summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-12-02 13:26:52 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-12-02 13:26:52 +0000
commit51b57f100e50eb56b87641efb7b0cb29f8340407 (patch)
tree3afe1d5224ebca9dafdde4e64c8cf5abfb8e8099
parentb657b3cffbd21178bac28505e7d70dee61e17b4a (diff)
downloadfpGUI-51b57f100e50eb56b87641efb7b0cb29f8340407.tar.xz
* Implemented ButtonBevel and FocusRect style based drawing. Currently only active in the prototypes directory, but will later be moved to src/gui
-rw-r--r--prototypes/fpgui2/tests/themetest.lpi3
-rw-r--r--prototypes/fpgui2/tests/themetest.lpr77
-rw-r--r--src/gui/gui_style.pas100
3 files changed, 166 insertions, 14 deletions
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 @@
<Generate Value="Faster"/>
</CodeGeneration>
<Other>
- <CustomOptions Value="-FUunits
-"/>
+ <CustomOptions Value="-FUunits"/>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
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 @@ uses
gui_label,
gfx_imgfmt_bmp,
gfx_extinterpolation,
- gui_trackbar;
+ gui_trackbar,
+ gui_style;
type
{ Note:
@@ -74,6 +75,19 @@ type
{ 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 @@ type
lblSilver: TfpgLabel;
xpluna: TThemeButton;
xpsilver: TThemeButton;
+ styledbutton: TStyledButton;
sbluna: TThemeScrollbar;
sbsilver: TThemeScrollbar;
sblunaHor: TThemeScrollbar;
@@ -100,6 +115,61 @@ type
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 @@ begin
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;
diff --git a/src/gui/gui_style.pas b/src/gui/gui_style.pas
index 4fa62f25..03a44b2d 100644
--- a/src/gui/gui_style.pas
+++ b/src/gui/gui_style.pas
@@ -21,6 +21,8 @@ unit gui_style;
{$mode objfpc}{$H+}
+{$Define DEBUG}
+
interface
uses
@@ -114,7 +116,7 @@ type
end;
- TfpgButtonFeatures = set of (bfNone, bfFlat, bfDefault);
+ TfpgButtonFeatures = set of (bfNone, bfFlat, bfDefault, bfEmbedded);
// Button specific options
TfpgButtonStyleOption = class(TfpgStyleOption)
@@ -156,7 +158,7 @@ type
// This class provides a widgte style similar to the classic BlueCurve theme
// originally created by Red Hat.
- TfpgBluecurveStyle = class(TfpgCommonStyle)
+ TfpgBlueCurveStyle = class(TfpgCommonStyle)
end;
@@ -179,13 +181,77 @@ implementation
{ TfpgCommonStyle }
procedure TfpgCommonStyle.DrawControl(element: TfpgControlElement;
- const option: TfpgStyleOption; canvas: TfpgCanvas; widget: TfpgWidget);
+ const option: TfpgStyleOption; canvas: TfpgCanvas; widget: TfpgWidget);
+var
+ r: TfpgRect;
begin
// Do common things here
+ case element of
+ cePushButtonBevel:
+ begin
+ {$IFDEF DEBUG}
+ writeln('TfpgCommonStyle.DrawControl: cePushButtonBevel');
+ {$ENDIF}
+ r.SetRect(option.Rect.Left, option.Rect.Top, option.Rect.Width, option.Rect.Height);
+
+ if bfDefault in TfpgButtonStyleOption(option).ButtonFeatures then
+ begin
+ Canvas.SetColor(clBlack);
+ Canvas.SetLineStyle(1, lsSolid);
+ Canvas.DrawRectangle(r);
+ InflateRect(r, -1, -1);
+ end;
+
+ Canvas.SetColor(clButtonFace);
+ Canvas.SetLineStyle(1, lsSolid);
+ Canvas.FillRectangle(r.Left, r.Top, r.Width, r.Height);
+
+ // Left and Top (outer)
+ if stLowered in option.State then
+ begin
+ if bfEmbedded in TfpgButtonStyleOption(option).ButtonFeatures then
+ Canvas.SetColor(clHilite1)
+ else
+ Canvas.SetColor(clShadow2);
+ end
+ else
+ Canvas.SetColor(clHilite1);
+ Canvas.DrawLine(r.Left, r.Bottom, r.Left, r.Top); // left
+ Canvas.DrawLine(r.Left, r.Top, r.Right, r.Top); // top
+
+ // Right and Bottom (outer)
+ if stLowered in option.State then
+ begin
+ if bfEmbedded in TfpgButtonStyleOption(option).ButtonFeatures then
+ Canvas.SetColor(clHilite1)
+ else
+ Canvas.SetColor(clShadow2);
+ end
+ else
+ Canvas.SetColor(clShadow2);
+ Canvas.DrawLine(r.Right, r.Top, r.Right, r.Bottom); // right
+ Canvas.DrawLine(r.Right, r.Bottom, r.Left-1, r.Bottom); // bottom
+
+ // Right and Bottom (inner)
+ if stLowered in option.State then
+ begin
+ if bfEmbedded in TfpgButtonStyleOption(option).ButtonFeatures then
+ Canvas.SetColor(clButtonFace)
+ else
+ Canvas.SetColor(clHilite1);
+ end
+ else
+ Canvas.SetColor(clShadow1);
+ Canvas.DrawLine(r.Right-1, r.Top+1, r.Right-1, r.Bottom-1); // right
+ Canvas.DrawLine(r.Right-1, r.Bottom-1, r.Left, r.Bottom-1); // bottom
+ end { cePushButtonBevel }
+ end;
end;
procedure TfpgCommonStyle.DrawPrimitive(element: TfpgPrimitiveElement;
- const option: TfpgStyleOption; canvas: TfpgCanvas; widget: TfpgWidget);
+ const option: TfpgStyleOption; canvas: TfpgCanvas; widget: TfpgWidget);
+var
+ r: TfpgRect;
begin
// Do common things here. It's going to be a huge case statement. This design
// allows us to add new controls or elements without having to instantly
@@ -193,15 +259,27 @@ begin
case element of
peFocusRectangle:
begin
- canvas.DrawFocusRect(option.Rect);
- end;
+ {$IFDEF DEBUG}
+ writeln('TfpgCommonStyle.DrawPrimitive: peFocusRectangle');
+ {$ENDIF}
+ if stHasFocus in option.State then
+ begin
+ r.SetRect(option.Rect.Left, option.Rect.Top, option.Rect.Width, option.Rect.Height);
+ InflateRect(r, -3, -3);
+ Canvas.DrawFocusRect(r);
+ end;
+ end; { peFocusRectangle }
+
peIndicatorRadioButton:
begin // just an example!!!!!!!!
- canvas.SetColor(clShadow1);
- canvas.DrawArc(option.Rect.Left, option.Rect.Top, option.Rect.Width, option.Rect.Height, 0, 180);
- canvas.SetColor(clHilite1);
- canvas.DrawArc(option.Rect.Left, option.Rect.Top, option.Rect.Width, option.Rect.Height, 180, 0);
- end;
+ {$IFDEF DEBUG}
+ writeln('TfpgCommonStyle.DrawPrimitive: peIndicatorRadioButton');
+ {$ENDIF}
+ Canvas.SetColor(clShadow1);
+ Canvas.DrawArc(option.Rect.Left, option.Rect.Top, option.Rect.Width, option.Rect.Height, 0, 180);
+ Canvas.SetColor(clHilite1);
+ Canvas.DrawArc(option.Rect.Left, option.Rect.Top, option.Rect.Width, option.Rect.Height, 180, 0);
+ end; { peIndicatorRadioButton }
end;
end;