summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-01 10:42:14 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-01 10:42:14 +0000
commitd77c30bf2891857f9336b46b95a8739801bcb0e3 (patch)
treea27696d360cf02d695a74875fa7ccb23eed93fc4
parentea4a9faddc8c3a5322d43d2484df9d6cc1a04041 (diff)
downloadfpGUI-d77c30bf2891857f9336b46b95a8739801bcb0e3.tar.xz
* TfpgButton now contains a new property called Flat which gives it a flat look. As the mouse hovers over the button, it gets the normal look. This property overrides the Default property look.
* UI Designer now has support for the Button.Flat property, but the flat behaviour has been disabled in the designer form to make buttons more visible compared to labels.
-rw-r--r--examples/apps/uidesigner/vfdwidgets.pas1
-rw-r--r--src/corelib/fpgfx.pas11
-rw-r--r--src/gui/gui_button.pas48
3 files changed, 56 insertions, 4 deletions
diff --git a/examples/apps/uidesigner/vfdwidgets.pas b/examples/apps/uidesigner/vfdwidgets.pas
index 730dbb89..43004722 100644
--- a/examples/apps/uidesigner/vfdwidgets.pas
+++ b/examples/apps/uidesigner/vfdwidgets.pas
@@ -258,6 +258,7 @@ begin
wc.AddProperty('Text', TPropertyString, 'Initial text');
wc.AddProperty('AllowAllUp', TPropertyBoolean, '');
wc.AddProperty('Embedded', TPropertyBoolean, 'No focus rectangle will be drawn. eg: Toolbar buttons');
+ wc.AddProperty('Flat', TPropertyBoolean, 'Only draw button borders when mouse hovers over button');
wc.AddProperty('FontDesc', TPropertyFontDesc, 'The font used for displaying the text');
wc.AddProperty('GroupIndex', TPropertyInteger, '');
wc.AddProperty('ImageMargin', TPropertyInteger, '');
diff --git a/src/corelib/fpgfx.pas b/src/corelib/fpgfx.pas
index 13ed1eaa..59054a59 100644
--- a/src/corelib/fpgfx.pas
+++ b/src/corelib/fpgfx.pas
@@ -30,7 +30,7 @@ type
TAnchors = set of TAnchor;
TFButtonFlags = set of (btfIsEmbedded, btfIsDefault, btfIsPressed,
- btfIsSelected, btfHasFocus, btfHasParentColor);
+ btfIsSelected, btfHasFocus, btfHasParentColor, btfFlat, btfHover);
TFTextFlags = set of (txtLeft, txtHCenter, txtRight, txtTop, txtVCenter, txtBottom, txtWrap, txtEnabled,
txtAutoSize);
@@ -1474,8 +1474,11 @@ end;
procedure TfpgStyle.DrawButtonFace(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord; AFlags: TFButtonFlags);
var
r: TfpgRect;
+ lDoDraw: Boolean;
begin
r.SetRect(x, y, w, h);
+ lDoDraw := False;
+
if btfIsDefault in AFlags then
begin
ACanvas.SetColor(clBlack);
@@ -1491,6 +1494,9 @@ begin
ACanvas.SetLineStyle(1, lsSolid);
ACanvas.FillRectangle(x, y, w, h);
+ if (btfFlat in AFlags) and not (btfIsPressed in AFlags) then
+ Exit; // no need to go further
+
// Left and Top (outer)
if (btfIsPressed in AFlags) then
begin
@@ -1501,6 +1507,7 @@ begin
end
else
ACanvas.SetColor(clHilite2);
+
ACanvas.DrawLine(r.Left, r.Bottom, r.Left, r.Top); // left
ACanvas.DrawLine(r.Left, r.Top, r.Right, r.Top); // top
@@ -1522,6 +1529,7 @@ begin
end
else
ACanvas.SetColor(clShadow2);
+
ACanvas.DrawLine(r.Right, r.Top, r.Right, r.Bottom); // right
ACanvas.DrawLine(r.Right, r.Bottom, r.Left-1, r.Bottom); // bottom
@@ -1535,6 +1543,7 @@ begin
end
else
ACanvas.SetColor(clShadow1);
+
ACanvas.DrawLine(r.Right-1, r.Top+1, r.Right-1, r.Bottom-1); // right
ACanvas.DrawLine(r.Right-1, r.Bottom-1, r.Left, r.Bottom-1); // bottom
end;
diff --git a/src/gui/gui_button.pas b/src/gui/gui_button.pas
index 91b97a29..a04a6375 100644
--- a/src/gui/gui_button.pas
+++ b/src/gui/gui_button.pas
@@ -34,6 +34,7 @@ type
TfpgBaseButton = class(TfpgWidget, ICommandHolder)
private
FCommand: ICommand;
+ FFlat: Boolean;
FImageName: string;
FClicked: Boolean;
FShowImage: Boolean;
@@ -44,6 +45,7 @@ type
function GetFontDesc: string;
procedure SetDefault(const AValue: boolean);
procedure SetEmbedded(const AValue: Boolean);
+ procedure SetFlat(const AValue: Boolean);
procedure SetFontDesc(const AValue: string);
procedure SetImageName(const AValue: string);
procedure SetText(const AValue: string);
@@ -64,6 +66,7 @@ type
FText: string;
FFont: TfpgFont;
FDefault: boolean;
+ FState: integer; // 0 - normal // 1 - hover
procedure SetShowImage(AValue: Boolean);
procedure HandlePaint; override;
procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override;
@@ -82,6 +85,7 @@ type
{ The button will not show focus. It might also have a different down state (look).
This is similar to Focusable = False, but the appearance of the down state might differ. }
property Embedded: Boolean read FEmbedded write SetEmbedded default False;
+ property Flat: Boolean read FFlat write SetFlat default False;
property FontDesc: string read GetFontDesc write SetFontDesc;
{ Used in combination with AllowDown and AllowAllUp. Allows buttons in the same
group to work together. }
@@ -110,6 +114,7 @@ type
property Default;
property Down;
property Embedded;
+ property Flat;
property FontDesc;
property GroupIndex;
property ImageMargin;
@@ -219,6 +224,15 @@ begin
FEmbedded := AValue;
end;
+procedure TfpgBaseButton.SetFlat(const AValue: Boolean);
+begin
+ if FFlat = AValue then
+ Exit; //==>
+ FFlat := AValue;
+ if FFlat then
+ FDefault := False; // you can't have it all!
+end;
+
procedure TfpgBaseButton.SetFontDesc(const AValue: string);
begin
FFont.Free;
@@ -251,6 +265,7 @@ begin
FEmbedded := False;
FDefault := False;
FAllowAllUp := False;
+ FState := 0;
end;
destructor TfpgBaseButton.Destroy;
@@ -286,7 +301,16 @@ begin
if FEmbedded then
Include(lBtnFlags, btfIsEmbedded);
- if FDefault then
+ // In the UI Designer we want the button more visible
+ if not (csDesigning in ComponentState) then
+ begin
+ if FFlat and (FState = 1) then // mouse over
+ Include(lBtnFlags, btfHover)
+ else if FFlat then
+ Include(lBtnFlags, btfFlat);
+ end;
+
+ if not FFlat and FDefault then
Include(lBtnFlags, btfIsDefault);
if FBackgroundColor <> clButtonFace then
@@ -460,20 +484,38 @@ end;
procedure TfpgBaseButton.HandleMouseExit;
begin
inherited HandleMouseExit;
+ if (csDesigning in ComponentState) then
+ Exit;
+ if Enabled then
+ FState := 0;
if FDown and (not AllowDown) then
begin
FDown := False;
- RePaint;
+ Repaint;
+ end
+ else if FFlat then
+ begin
+ if Enabled then
+ Repaint;
end;
end;
procedure TfpgBaseButton.HandleMouseEnter;
begin
inherited HandleMouseEnter;
+ if (csDesigning in ComponentState) then
+ Exit;
+ if Enabled then
+ FState := 1;
if FClicked and (not AllowDown) then
begin
FDown := True;
- RePaint;
+ Repaint;
+ end
+ else if FFlat then
+ begin
+ if Enabled then
+ Repaint;
end;
end;