diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-19 15:10:15 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-19 15:10:15 +0000 |
commit | 5eaf11ad28e1f178adad58c6d922e23b26951583 (patch) | |
tree | a6baaaf6eb205e3d115223107e3630ccf631807b /prototypes | |
parent | 9d3fbcf9640f261958463c3457900d66d892cfb1 (diff) | |
download | fpGUI-5eaf11ad28e1f178adad58c6d922e23b26951583.tar.xz |
* Added PtInRect to fpgbase
* Started with scrollbar themeing
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/fpgui2/source/core/gfxbase.pas | 11 | ||||
-rw-r--r-- | prototypes/fpgui2/tests/themetest.lpr | 218 |
2 files changed, 223 insertions, 6 deletions
diff --git a/prototypes/fpgui2/source/core/gfxbase.pas b/prototypes/fpgui2/source/core/gfxbase.pas index 5f76ee14..19918c60 100644 --- a/prototypes/fpgui2/source/core/gfxbase.pas +++ b/prototypes/fpgui2/source/core/gfxbase.pas @@ -359,6 +359,9 @@ function fpgGetGreen(const AColor: TfpgColor): word; function fpgGetBlue(const AColor: TfpgColor): word; function fpgGetAlpha(const AColor: TfpgColor): word; +{ Points } +function PtInRect(const ARect: TfpgRect; const APoint: TPoint): Boolean; + implementation uses @@ -553,6 +556,14 @@ begin Result := Word((AColor shr 32) and $FF); end; +function PtInRect(const ARect: TfpgRect; const APoint: TPoint): Boolean; +begin + Result := (APoint.x >= ARect.Left) and + (APoint.y >= ARect.Top) and + (APoint.x < ARect.Right) and + (APoint.y < ARect.Bottom); +end; + { TfpgRect } procedure TfpgRect.SetRect(aleft, atop, awidth, aheight: TfpgCoord); diff --git a/prototypes/fpgui2/tests/themetest.lpr b/prototypes/fpgui2/tests/themetest.lpr index adb26616..9fd396cd 100644 --- a/prototypes/fpgui2/tests/themetest.lpr +++ b/prototypes/fpgui2/tests/themetest.lpr @@ -17,6 +17,10 @@ uses gfx_imgfmt_bmp; type + { Note: + I am only creating new classes to test my drawing routines in HandlePaint. + The final themeing will be done inside the TfpgXXXX classes. } + { Concept theme button } TThemeButton = class(TfpgButton) private @@ -43,17 +47,145 @@ type TThemeScrollbar = class(TfpgScrollBar) + private + TopRect: TfpgRect; + BottomRect: TfpgRect; + ThumbRect: TfpgRect; + State: integer; + // 0 - normal + // 1 - hover + // 2 - mouse down + // 3 - disabled + // 4 - got focus or default + image: TfpgImage; + procedure SetThemeImage(const AValue: TfpgImage); + protected + procedure HandlePaint; override; + procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + { this property is only for demo purposes! } + property ThemeImage: TfpgImage read image write SetThemeImage; end; TMainForm = class(TfpgForm) private + btnClose: TfpgButton; lblLuna: TfpgLabel; lblSilver: TfpgLabel; + xpluna: TThemeButton; + xpsilver: TThemeButton; + sbluna: TThemeScrollbar; + sbsilver: TThemeScrollbar; + sblunaHor: TThemeScrollbar; + sbsilverHor: TThemeScrollbar; + private + procedure btnCloseClick(Sender: TObject); + procedure CreateButtons; + procedure CreateScrollbars; public constructor Create(AOwner: TComponent); override; end; +{ TThemeScrollbar } + +procedure TThemeScrollbar.SetThemeImage(const AValue: TfpgImage); +begin + if Assigned(image) then + image.Free; + image := AValue; + Repaint; +end; + +procedure TThemeScrollbar.HandlePaint; +var + imgwidth: integer; + x: integer; +begin + Canvas.BeginDraw; +// inherited HandlePaint; + Canvas.ClearClipRect; + Canvas.Clear(clWindowBackground); + + imgwidth := image.Width div 34; + + //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; + + + if Orientation = orVertical then + begin +// DrawButton(0, 0, Width, Width, 'sys.sb.up' ,FStartBtnPressed); + { top button } +// if Pressed then +// Canvas.DrawButtonFace(x, y, w, h, [btnIsEmbedded, btnIsPressed]) + Canvas.DrawImagePart(0, 0, image, state*imgwidth, 0, imgwidth, 21); +// else +// Canvas.DrawButtonFace(x, y, w, h, [btnIsEmbedded]); + + { bottom button } + DrawButton(0, Height - Width, Width, Width, 'sys.sb.down', FEndBtnPressed); + end + else + begin + DrawButton(0, 0, Height, Height, 'sys.sb.left', FStartBtnPressed); + DrawButton(Width - Height, 0, Height, Height, 'sys.sb.right', FEndBtnPressed); + end; + + DrawSlider(True); + + Canvas.EndDraw; +end; + +procedure TThemeScrollbar.HandleMouseMove(x, y: integer; btnstate: word; + shiftstate: TShiftState); +var + Pt: TPoint; + NewState: Integer; +begin + inherited HandleMouseMove(x, y, btnstate, shiftstate); + + Pt := Point(X, Y); + NewState := 0; + if PtInRect(TopRect, Pt) then + NewState := 1 + else if PtInRect(ThumbRect, Pt) then + NewState := 2 + else if PtInRect(BottomRect, Pt) then + NewState := 3; + + if NewState <> State then + begin + State := NewState; + Repaint; + end; +end; + +constructor TThemeScrollbar.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + State := 0; + image := LoadImage_BMP(SetDirSeparators('../images/themes/luna/scrollbar.bmp')); + image.UpdateImage; +end; + +destructor TThemeScrollbar.Destroy; +begin + image.Free; + inherited Destroy; +end; + { TXPButton } @@ -230,6 +362,77 @@ end; { TMainForm } +procedure TMainForm.btnCloseClick(Sender: TObject); +begin + Close; +end; + +procedure TMainForm.CreateButtons; +var + bmp: TfpgImage; +begin + btnClose := TfpgButton.Create(self); + btnClose.Width := 75; + btnClose.Left := Width - btnClose.Width - 6; + btnClose.Top := Height - btnClose.Height - 6; + btnClose.Text := 'Quit'; + btnClose.ImageName := 'stdimg.Quit'; + btnClose.ShowImage := True; + btnClose.OnClick := @btnCloseClick; + + xpluna := TThemeButton.Create(self); + xpluna.Left := 80; + xpluna.Top := 45; + xpluna.Width := 75; + xpluna.Text := 'XP Luna'; + + xpsilver := TThemeButton.Create(self); + xpsilver.Left := 230; + xpsilver.Top := 45; + xpsilver.Width := 75; + xpsilver.Text := 'XP Silver'; + bmp := LoadImage_BMP(SetDirSeparators('../images/themes/silver/button.bmp')); + bmp.CreateMaskFromSample(0, 0); + bmp.UpdateImage; + xpsilver.ThemeImage := bmp; +end; + +procedure TMainForm.CreateScrollbars; +var + bmp: TfpgImage; +begin + bmp := LoadImage_BMP(SetDirSeparators('../images/themes/silver/scrollbar.bmp')); + bmp.UpdateImage; + + sbluna := TThemeScrollBar.Create(self); + sbluna.Top := 80; + sbluna.Left := 130; + sbluna.Height := 100; + sbluna.Max := 15; + + sbsilver := TThemeScrollBar.Create(self); + sbsilver.Top := 80; + sbsilver.Left := 310; + sbsilver.Height := 100; + sbsilver.Max := 15; + sbsilver.ThemeImage := bmp; + + sblunaHor := TThemeScrollBar.Create(self); + sblunaHor.Top := 100; + sblunaHor.Left := 20; + sblunaHor.Width := 100; + sblunaHor.Max := 15; + sblunaHor.Orientation := orHorizontal; + + sbsilverHor := TThemeScrollBar.Create(self); + sbsilverHor.Top := 110; + sbsilverHor.Left := 200; + sbsilverHor.Width := 100; + sbsilverHor.Max := 15; + sbsilverHor.Orientation := orHorizontal; + sbsilverHor.ThemeImage := bmp; +end; + constructor TMainForm.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -237,14 +440,17 @@ begin SetPosition(100, 100, 400, 300); lblLuna := CreateLabel(self, 100, 5, 'Luna'); - lblLuna.FontDesc := 'Sans-12:bold:underline'; - lblLuna.Height := lblLuna.Font.Height; - lblLuna.Width := lblLuna.Font.TextWidth(lblLuna.Text); + lblLuna.FontDesc := 'Sans-12:bold:underline'; + lblLuna.Height := lblLuna.Font.Height; + lblLuna.Width := lblLuna.Font.TextWidth(lblLuna.Text); lblSilver := CreateLabel(self, 250, 5, 'Silver'); - lblSilver.FontDesc := 'Sans-12:bold:underline'; - lblSilver.Height := lblSilver.Font.Height; - lblSilver.Width := lblSilver.Font.TextWidth(lblSilver.Text); + lblSilver.FontDesc := 'Sans-12:bold:underline'; + lblSilver.Height := lblSilver.Font.Height; + lblSilver.Width := lblSilver.Font.TextWidth(lblSilver.Text); + + CreateButtons; + CreateScrollbars; end; |