summaryrefslogtreecommitdiff
path: root/prototypes
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-19 08:21:39 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-19 08:21:39 +0000
commit629b20229075573823aec54c3250b668cec033fd (patch)
tree71aa606f0ae5a9f3d11024d6cd8478577c806fe1 /prototypes
parent374d4e73447331268d6eae681f2a530bc4d9ac86 (diff)
downloadfpGUI-629b20229075573823aec54c3250b668cec033fd.tar.xz
* Completed mockup implementation of a XP themed button
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/fpgui2/source/core/predefinedcolors.inc10
-rw-r--r--prototypes/fpgui2/source/core/x11/gfx_x11.pas7
-rw-r--r--prototypes/fpgui2/source/gui/gui_button.pas10
-rw-r--r--prototypes/fpgui2/tests/edittest.dpr143
4 files changed, 134 insertions, 36 deletions
diff --git a/prototypes/fpgui2/source/core/predefinedcolors.inc b/prototypes/fpgui2/source/core/predefinedcolors.inc
index 6d49e850..5162a58e 100644
--- a/prototypes/fpgui2/source/core/predefinedcolors.inc
+++ b/prototypes/fpgui2/source/core/predefinedcolors.inc
@@ -38,14 +38,14 @@
clWindowBackground = $80000001;
clBoxColor = $80000002;
clButtonFace = $80000003;
- clShadow1 = $80000004;
+ clShadow1 = $80000004; // nice for disabled text
clShadow2 = $80000005;
clHilite1 = $80000006;
clHilite2 = $80000007;
- clText1 = $80000008;
- clText2 = $80000009;
- clText3 = $8000000A;
- clText4 = $8000000B;
+ clText1 = $80000008; // normal text
+ clText2 = $80000009; // deep dark blue
+ clText3 = $8000000A; // red/brown
+ clText4 = $8000000B; // mud dark green
clSelection = $8000000C;
clSelectionText = $8000000D;
clInactiveSel = $8000000E;
diff --git a/prototypes/fpgui2/source/core/x11/gfx_x11.pas b/prototypes/fpgui2/source/core/x11/gfx_x11.pas
index 72103607..8554272e 100644
--- a/prototypes/fpgui2/source/core/x11/gfx_x11.pas
+++ b/prototypes/fpgui2/source/core/x11/gfx_x11.pas
@@ -1332,8 +1332,8 @@ begin
if Length(txt) < 1 then
Exit; //==>
- XftDrawStringUTF8(FXftDraw, FColorTextXft, FCurFontRes.Handle, x, y + FCurFontRes.GetAscent,
- PChar(txt), Length(txt));
+ XftDrawStringUTF8(FXftDraw, FColorTextXft, FCurFontRes.Handle, x,
+ y + FCurFontRes.GetAscent, PChar(txt), Length(txt));
end;
procedure TfpgCanvasImpl.DoGetWinRect(var r: TfpgRect);
@@ -1346,7 +1346,8 @@ var
begin
r.left := 0;
r.Top := 0;
- XGetGeometry(xapplication.display, FDrawWindow.FWinHandle, @rw, @x, @y, @(r.Width), @(r.Height), @bw, @d);
+ XGetGeometry(xapplication.display, FDrawWindow.FWinHandle, @rw, @x, @y,
+ @(r.Width), @(r.Height), @bw, @d);
end;
procedure TfpgCanvasImpl.DoFillRectangle(x, y, w, h: TfpgCoord);
diff --git a/prototypes/fpgui2/source/gui/gui_button.pas b/prototypes/fpgui2/source/gui/gui_button.pas
index 296818bc..719600c4 100644
--- a/prototypes/fpgui2/source/gui/gui_button.pas
+++ b/prototypes/fpgui2/source/gui/gui_button.pas
@@ -15,15 +15,10 @@ type
TfpgButton = class(TfpgWidget)
private
- FEmbedded: Boolean;
FImageName: string;
FClicked: Boolean;
- FImage: TfpgImage;
FShowImage: Boolean;
FClickOnPush: Boolean;
- FDown: Boolean;
- FImageMargin: integer;
- FImageSpacing: integer;
FGroupIndex: integer;
FAllowAllUp: boolean;
FModalResult: integer;
@@ -39,6 +34,11 @@ type
procedure SetAllowDown(const Value: Boolean);
procedure SetAllowAllUp(const Value: boolean);
protected
+ FImageMargin: integer;
+ FImageSpacing: integer;
+ FEmbedded: Boolean;
+ FDown: Boolean;
+ FImage: TfpgImage;
FText: string;
FFont: TfpgFont;
procedure SetShowImage(AValue: Boolean);
diff --git a/prototypes/fpgui2/tests/edittest.dpr b/prototypes/fpgui2/tests/edittest.dpr
index 03f7c8bb..be876a6a 100644
--- a/prototypes/fpgui2/tests/edittest.dpr
+++ b/prototypes/fpgui2/tests/edittest.dpr
@@ -30,7 +30,7 @@ type
// 1-hover
// 2-mouse down
// 3-disabled
- // 4-got focus
+ // 4-got focus & default button
image: TfpgImage;
protected
procedure HandlePaint; override;
@@ -62,7 +62,8 @@ type
listbox: TfpgListBox;
combo1: TfpgComboBox;
sbar: TfpgScrollBar;
- xp: TXPButton;
+ xp1: TXPButton;
+ xp2: TXPButton;
procedure AfterCreate; override;
end;
@@ -71,22 +72,31 @@ type
procedure TXPButton.HandlePaint;
var
x, i: integer;
+ r: TfpgRect;
+ iy, y: integer;
+ w: integer;
+ pofs: integer;
begin
Canvas.BeginDraw;
// inherited HandlePaint;
Canvas.ClearClipRect;
- Canvas.Clear(clGray);
+ Canvas.Clear(clButtonFace);
+
+ if State <> 1 then
+ begin
+ if Down then
+ State := 2
+ else if Focused then
+ State := 4
+ else if not Enabled then
+ State := 3
+ else
+ State := 0;
+ end;
- image := nil;
- image := LoadImage_BMP('button.bmp');
- image.CreateMaskFromSample(0, 0);
- image.UpdateImage;
- if not Assigned(image) then
- writeln('Image is nil');
- { left }
- Writeln(Left, ' ' , Top, ' ', State, ' ', image.Width);
x := 0;
+ { left }
Canvas.DrawImagePart(x, 0, image, state*32, 0, 3, 21);
{ body }
for i := (x+3) to (x+3+69) do
@@ -95,8 +105,76 @@ begin
Canvas.DrawImagePart(i, 0, image, (state*32)+29, 0, 3, 21);
- image.Free;
-// Canvas.DrawString(16, 242, 'OK');
+
+ if Focused and (not Embedded) then
+ begin
+ Canvas.SetColor(clText1);
+ Canvas.SetLineStyle(1, lsDot);
+ Canvas.DrawRectangle(3, 3, Width - 6, Height - 6);
+ end
+ else
+ begin
+ Canvas.SetTextColor(clText1);
+ Canvas.SetColor(clText1);
+ end;
+
+ if not Enabled then
+ Canvas.SetTextColor(clShadow1);
+
+ r.left := 2;
+ r.top := 2;
+ r.Width := Width - 4;
+ r.Height := Height - 4;
+ Canvas.SetClipRect(r);
+
+ Canvas.SetFont(Font);
+ y := Height div 2 - FFont.Height div 2;
+ if y < 3 then
+ y := 3;
+
+ // offset text and image
+ if Down then
+ pofs := 1
+ else
+ pofs := 0;
+
+ if (ShowImage) and (FImage <> nil) then
+ begin
+ iy := Height div 2 - FImage.Height div 2;
+ if ImageMargin = -1 then // centered
+ begin
+ w := FFont.TextWidth(FText) + FImage.Width;
+ if FImageSpacing > 0 then
+ Inc(w, FImageSpacing);
+ x := (Width div 2) - (w div 2);
+ if x < 3 then
+ x := 3;
+ end
+ else
+ begin
+ x := FImageMargin + 3;
+ end;
+
+ Canvas.DrawImage(x + pofs, iy + pofs, FImage);
+ Inc(x, FImage.Width);
+ if FImageSpacing > 0 then
+ Inc(x, FImageSpacing);
+
+ if (FImageSpacing = -1) and (FImageMargin >= 0) then
+ begin
+ w := (Width - 3 - x) div 2 - FFont.TextWidth(FText) div 2;
+ if w < 1 then
+ w := 1; // minimal spacing
+ x := x + w;
+ end;
+ end
+ else
+ x := (Width div 2) - (FFont.TextWidth(FText) div 2);
+
+ if x < 3 then
+ x := 3;
+
+ Canvas.DrawString(x + pofs, y + pofs, FText);
Canvas.EndDraw;
end;
@@ -117,18 +195,22 @@ end;
procedure TXPButton.HandleMouseExit;
begin
- writeln('exit');
inherited HandleMouseExit;
- State := 0;
- Repaint;
+ if Enabled then
+ begin
+ State := 0;
+ Repaint;
+ end;
end;
procedure TXPButton.HandleMouseEnter;
begin
- writeln('enter');
inherited HandleMouseEnter;
- State := 1;
- Repaint;
+ if Enabled then
+ begin
+ State := 1;
+ Repaint;
+ end;
end;
constructor TXPButton.Create(AOwner: TComponent);
@@ -138,6 +220,11 @@ begin
Height := 21;
State := 0;
+ image := LoadImage_BMP('button.bmp');
+ image.CreateMaskFromSample(0, 0);
+ image.UpdateImage;
+ if not Assigned(image) then
+ writeln('Image is nil');
end;
destructor TXPButton.Destroy;
@@ -225,6 +312,8 @@ end;
btn2 := CreateButton(self, 10, 100, 75, 'Normal', nil);
btn2.OnClick := @btnDisplayBMP;
+ btn2.Enabled := False;
+
btn3 := CreateButton(self, 100, 100, 75, 'Embedded', nil);
btn3.Embedded := True;
btn3.OnClick := @btn3Click;
@@ -259,10 +348,18 @@ end;
sbar.Height := 100;
sbar.Max := 15;
- xp := TXPButton.Create(self);
- xp.Left := 250;
- xp.Top := 200;
- xp.Width := 75;
+ xp1 := TXPButton.Create(self);
+ xp1.Left := 250;
+ xp1.Top := 200;
+ xp1.Width := 75;
+ xp1.Text := 'XP Button1';
+
+ xp2 := TXPButton.Create(self);
+ xp2.Left := 335;
+ xp2.Top := 200;
+ xp2.Width := 75;
+ xp2.Text := 'XP Button2';
+ xp2.Enabled := False;
end;