diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-08-19 16:08:08 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-08-19 16:08:08 +0200 |
commit | ed0126691c5f76aa0b26a3c8f0927d3cbb87eb46 (patch) | |
tree | 91f89218268eec7fd17a36208707e27162cd5437 | |
parent | f376241d831ae3863d367ca2414f7fc445d08fe0 (diff) | |
download | fpGUI-ed0126691c5f76aa0b26a3c8f0927d3cbb87eb46.tar.xz |
Scrollbars now have disabled arrow button state at Min or Max values.
Thanks to Jean-Marc Levecque for the idea.
-rw-r--r-- | src/gui/fpg_scrollbar.pas | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/gui/fpg_scrollbar.pas b/src/gui/fpg_scrollbar.pas index 55db9f59..ed12d0d2 100644 --- a/src/gui/fpg_scrollbar.pas +++ b/src/gui/fpg_scrollbar.pas @@ -43,7 +43,6 @@ type TfpgScrollBarPart = (sbpNone, sbpUpBack, sbpPageUpBack, sbpSlider, sbpDownForward, sbpPageDownForward); - { TfpgScrollBar } TfpgScrollBar = class(TfpgWidget) private @@ -72,7 +71,7 @@ type FMousePosition: TPoint; FOnScroll: TScrollNotifyEvent; procedure ScrollTimer(Sender: TObject); - procedure DrawButton(x, y, w, h: TfpgCoord; const imgname: string; Pressed: Boolean = False); virtual; + procedure DrawButton(x, y, w, h: TfpgCoord; const imgname: string; Pressed: Boolean = False; const ButtonEnabled: Boolean= True); virtual; procedure DrawSlider(recalc: boolean); virtual; procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override; @@ -139,13 +138,13 @@ begin Canvas.BeginDraw; // Do not remove - Scrollbars do painting outside HandlePaint as well! if Orientation = orVertical then begin - DrawButton(0, 0, Width, Width, 'sys.sb.up', FScrollbarDownPart = sbpUpBack); - DrawButton(0, Height-Width, Width, Width, 'sys.sb.down', FScrollbarDownPart = sbpDownForward); + DrawButton(0, 0, Width, Width, 'sys.sb.up', (FScrollbarDownPart = sbpUpBack) and (FPosition <> FMin), FPosition <> FMin); + DrawButton(0, Height-Width, Width, Width, 'sys.sb.down', (FScrollbarDownPart = sbpDownForward) and (FPosition <> FMax), FPosition <> FMax); end else begin - DrawButton(0, 0, Height, Height, 'sys.sb.left', FScrollbarDownPart = sbpUpBack); - DrawButton(Width-Height, 0, Height, Height, 'sys.sb.right', FScrollbarDownPart = sbpDownForward); + DrawButton(0, 0, Height, Height, 'sys.sb.left', (FScrollbarDownPart = sbpUpBack) and (FPosition <> FMin), FPosition <> FMin); + DrawButton(Width-Height, 0, Height, Height, 'sys.sb.right', (FScrollbarDownPart = sbpDownForward) and (FPosition <> FMax), FPosition <> FMax); end; DrawSlider(FRecalc); @@ -323,9 +322,9 @@ begin end; // only called from inside HandlePaint so no need for BeginDraw..EndDraw calls -procedure TfpgScrollBar.DrawButton(x, y, w, h: TfpgCoord; const imgname: string; Pressed: Boolean = False); +procedure TfpgScrollBar.DrawButton(x, y, w, h: TfpgCoord; const imgname: string; Pressed: Boolean = False; const ButtonEnabled: Boolean= True); var - img: TfpgImage; + img, imgdisabled: TfpgImage; dx: integer; dy: integer; begin @@ -344,7 +343,16 @@ begin Canvas.SetColor(clText1); img := fpgImages.GetImage(imgname); if img <> nil then - Canvas.DrawImage(x + w div 2 - (img.Width div 2) + dx, y + h div 2 - (img.Height div 2) + dy, img); + begin + if ButtonEnabled then + Canvas.DrawImage(x + w div 2 - (img.Width div 2) + dx, y + h div 2 - (img.Height div 2) + dy, img) + else + begin + imgdisabled := img.CreateDisabledImage; + Canvas.DrawImage(x + w div 2 - (img.Width div 2) + dx, y + h div 2 - (img.Height div 2) + dy, imgdisabled); + imgdisabled.Free; + end; + end; end; // only called from inside HandlePaint so no need for BeginDraw..EndDraw calls @@ -516,14 +524,13 @@ begin if FScrollbarDownPart = sbpSlider then begin FSliderDragStart := FSliderPos; - Invalidate; //DrawSlider(False); + Invalidate; end else if not (FScrollbarDownPart in [sbpNone, sbpSlider]) then begin FScrollTimer.Interval := 300; FScrollTimer.Enabled := True; - - Invalidate; //HandlePaint; + Invalidate; end; end; @@ -540,7 +547,7 @@ begin FScrollbarDownPart := sbpNone; if WasPressed then - Invalidate; //HandlePaint; + Invalidate; end; procedure TfpgScrollBar.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); |