diff options
author | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2006-11-23 16:39:15 +0000 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2006-11-23 16:39:15 +0000 |
commit | 7a9b7aa63ec89922242ce4fca8a558a0abbe8b02 (patch) | |
tree | d8d14646d87529df607acfed8f320365a616bc3e /prototypes/multihandle | |
parent | 88f2537400dfcc2dae03e79bba084dbde23fb948 (diff) | |
download | fpGUI-7a9b7aa63ec89922242ce4fca8a558a0abbe8b02.tar.xz |
Improved the painting. Added a TEdit component.
Diffstat (limited to 'prototypes/multihandle')
-rw-r--r-- | prototypes/multihandle/gui2Base.pas | 96 | ||||
-rw-r--r-- | prototypes/multihandle/test.lpr | 4 |
2 files changed, 97 insertions, 3 deletions
diff --git a/prototypes/multihandle/gui2Base.pas b/prototypes/multihandle/gui2Base.pas index bb7fae0b..e0b0812e 100644 --- a/prototypes/multihandle/gui2Base.pas +++ b/prototypes/multihandle/gui2Base.pas @@ -98,10 +98,71 @@ type constructor Create(AParent: TFCustomWindow; APosition: TPoint); overload; property Caption: string read FCaption write SetCaption; end; + + + { TCustomEdit } + + TCustomEdit = class(TWidget) + private + FText: string; + procedure SetText(const AValue: string); + protected + procedure Paint; override; + public + constructor Create(AParent: TFCustomWindow; APosition: TPoint); overload; + property Text: string read FText write SetText; + end; + + TEdit = class(TCustomEdit) + public + property Text; + end; implementation +const + clDkWhite: TGfxColor = (Red: $e000; Green: $e000; Blue: $e000; Alpha: 0); + cl3DShadow: TGfxColor = (Red: $8000; Green: $8000; Blue: $8000; Alpha: 0); + cl3DDkShadow: TGfxColor = (Red: $0000; Green: $0000; Blue: $0000; Alpha: 0); + cl3DHighlight: TGfxColor = (Red: $FF00; Green: $FF00; Blue: $FF00; Alpha: 0); + cl3DFace: TGfxColor = (Red: $c000; Green: $c000; Blue: $c000; Alpha: 0); + clWindow: TGfxColor = (Red: $FF00; Green: $FF00; Blue: $FF00; Alpha: 0); + cl3DLight: TGfxColor = (Red: $e000; Green: $e000; Blue: $e000; Alpha: 0); + + +// Helper functions, that will actually be in a style class. + +procedure Draw3DFrame(Canvas: TFCanvas; const ARect: TRect; Color1, Color2, Color3, Color4: TGfxColor); +begin + with ARect do + begin + Canvas.SetColor(Color1); + Canvas.DrawLine(Point(Left, Bottom - 2), TopLeft); + Canvas.DrawLine(TopLeft, Point(Right - 1, Top)); + + Canvas.SetColor(Color2); + Canvas.DrawLine(Point(Left + 1, Bottom - 3), Point(Left + 1, Top + 1)); + Canvas.DrawLine(Point(Left + 1, Top + 1), Point(Right - 2, Top + 1)); + + Canvas.SetColor(Color3); + Canvas.DrawLine(Point(Left, Bottom - 1), Point(Right - 1, Bottom - 1)); + Canvas.DrawLine(Point(Right - 1, Bottom - 1), Point(Right - 1, Top - 1)); + + Canvas.SetColor(Color4); + Canvas.DrawLine(Point(Left + 1, Bottom - 2), Point(Right - 2, Bottom - 2)); + Canvas.DrawLine(Point(Right - 2, Bottom - 2), Point(Right - 2, Top)); + end; +end; + +procedure DrawEditBox(Canvas: TFCanvas; const ARect: TRect); +begin + Draw3DFrame(Canvas, ARect, cl3DShadow, cl3DDkShadow, cl3DHighlight, cl3DFace); + Canvas.SetColor(clWindow); + with ARect do + Canvas.FillRect(Rect(Left + 2, Top + 2, Right - 2, Bottom - 2)); +end; + { TWidget } procedure TWidget.EvOnPaint(Sender: TObject; const Rect: TRect); @@ -223,11 +284,11 @@ var Pt: TPoint; begin inherited Paint; + Draw3DFrame(TFCanvas(Canvas), Rect(0, 0, Width, Height), cl3DHighlight, cl3DLight, cl3DDkShadow, cl3DShadow); + Canvas.SetColor(colBlack); - Canvas.DrawRect(Rect(0, 0, Width, Height)); - Pt.x := (Width - Canvas.TextWidth(FCaption)) div 2; - Pt.y := (Height - Canvas.FontCellHeight) div 2; + Pt.y := ((Height - Canvas.FontCellHeight) div 2) + 1; Canvas.TextOut(Pt, FCaption); end; @@ -299,5 +360,34 @@ begin Create(nil, [woWindow]); end; +{ TCustomEdit } + +procedure TCustomEdit.SetText(const AValue: string); +var + w: integer; +begin + if FText=AValue then exit; + FText:=AValue; + w := Canvas.TextWidth(FText) + 6; + SetClientSize(Size(w, Height)); + Paint; +end; + +procedure TCustomEdit.Paint; +begin + inherited Paint; + DrawEditBox(TFCanvas(Canvas), Rect(0, 0, Width, Height)); + Canvas.SetColor(colBlack); + if FText <> '' then + Canvas.TextOut(Point(2, 2), FText); +end; + +constructor TCustomEdit.Create(AParent: TFCustomWindow; APosition: TPoint); +begin + inherited Create(AParent); + SetPosition(APosition); + SetClientSize(Size(100, 25)); +end; + end. diff --git a/prototypes/multihandle/test.lpr b/prototypes/multihandle/test.lpr index 4da7f9e7..35651a5e 100644 --- a/prototypes/multihandle/test.lpr +++ b/prototypes/multihandle/test.lpr @@ -31,6 +31,7 @@ type btnCancel: TButton; btnPopup: TButton; lblWelcome: TLabel; + edEdit: TEdit; public constructor Create; override; destructor Destroy; override; @@ -95,6 +96,9 @@ begin lblWelcome := TLabel.Create(self, Point(10, 10)); lblWelcome.Caption := 'So what do you think?'; + + edEdit := TEdit.Create(self, Point(65, 110)); + edEdit.Text := 'Multi-Handle widgets'; end; destructor TMainWindow.Destroy; |