From 51b57f100e50eb56b87641efb7b0cb29f8340407 Mon Sep 17 00:00:00 2001 From: graemeg Date: Sun, 2 Dec 2007 13:26:52 +0000 Subject: * Implemented ButtonBevel and FocusRect style based drawing. Currently only active in the prototypes directory, but will later be moved to src/gui --- prototypes/fpgui2/tests/themetest.lpi | 3 +- prototypes/fpgui2/tests/themetest.lpr | 77 ++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 3 deletions(-) (limited to 'prototypes') diff --git a/prototypes/fpgui2/tests/themetest.lpi b/prototypes/fpgui2/tests/themetest.lpi index ccc40a37..b0826d88 100644 --- a/prototypes/fpgui2/tests/themetest.lpi +++ b/prototypes/fpgui2/tests/themetest.lpi @@ -46,8 +46,7 @@ - + diff --git a/prototypes/fpgui2/tests/themetest.lpr b/prototypes/fpgui2/tests/themetest.lpr index 97da4e05..33e0b64f 100644 --- a/prototypes/fpgui2/tests/themetest.lpr +++ b/prototypes/fpgui2/tests/themetest.lpr @@ -16,7 +16,8 @@ gui_label, gfx_imgfmt_bmp, gfx_extinterpolation, - gui_trackbar; + gui_trackbar, + gui_style; type { Note: @@ -74,6 +75,19 @@ TThemeScrollbar = class(TfpgScrollBar) { this property is only for demo purposes! } property ThemeImage: TfpgImage read image write SetThemeImage; end; + + + { TStyledButton } + + TStyledButton = class(TfpgButton) + private + FStyle: TfpgBaseStyle; + protected + procedure HandlePaint; override; + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + end; TMainForm = class(TfpgForm) @@ -83,6 +97,7 @@ TMainForm = class(TfpgForm) lblSilver: TfpgLabel; xpluna: TThemeButton; xpsilver: TThemeButton; + styledbutton: TStyledButton; sbluna: TThemeScrollbar; sbsilver: TThemeScrollbar; sblunaHor: TThemeScrollbar; @@ -100,6 +115,61 @@ TMainForm = class(TfpgForm) constructor Create(AOwner: TComponent); override; end; +{ TStyledButton } + +procedure TStyledButton.HandlePaint; +var + buttonoptions: TfpgButtonStyleOption; +begin + Canvas.BeginDraw; + + Canvas.Clear(clButtonFace); + Canvas.ClearClipRect; + + // Setup all button options that we need + buttonoptions := TfpgButtonStyleOption.Create; + buttonoptions.Rect.SetRect(0, 0, Width, Height); + buttonoptions.StyleOption := soButton; + buttonoptions.State := []; + buttonoptions.ButtonFeatures := []; + + if Enabled then + Include(buttonoptions.State, stEnabled); + + if FDown then + Include(buttonoptions.State, stLowered) + else + Include(buttonoptions.State, stRaised); + + if FFocused then + Include(buttonoptions.State, stHasFocus); + + if FEmbedded then + Include(buttonoptions.ButtonFeatures, bfEmbedded); + + if FDefault then + Include(buttonoptions.ButtonFeatures, bfDefault); + + // Now let the Style do ALL the drawing. Nothing must be done here! + FStyle.DrawControl(cePushButtonBevel, buttonoptions, Canvas, self); + FStyle.DrawPrimitive(peFocusRectangle, buttonoptions, Canvas, self); + + buttonoptions.Free; + Canvas.EndDraw; +end; + +constructor TStyledButton.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FStyle := TfpgWin2000Style.Create; +end; + +destructor TStyledButton.Destroy; +begin + FStyle.Free; + inherited Destroy; +end; + procedure PaintPartScaledImage(Image: TfpgImage; Canvas: TfpgCanvas; x, y: TfpgCoord; OrigWidth, OrigHeight: TfpgCoord; NewWidth, NewHeight: TfpgCoord; Border: TfpgCoord; ImgIndex: integer); @@ -525,6 +595,11 @@ procedure TMainForm.CreateButtons; bmp.CreateMaskFromSample(0, 0); bmp.UpdateImage; xpsilver.ThemeImage := bmp; + + styledbutton := TStyledButton.Create(self); + styledbutton.SetPosition(btnClose.Left-20, btnClose.Top-80, 75, 24); +// styledbutton.Default := True; + styledbutton.Text := 'Styled'; end; procedure TMainForm.CreateScrollbars; -- cgit v1.2.3-54-g00ecf