summaryrefslogtreecommitdiff
path: root/prototypes/fpgui2/source
diff options
context:
space:
mode:
authordrewski207 <drewski207@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-15 16:41:05 +0000
committerdrewski207 <drewski207@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-15 16:41:05 +0000
commite2c678e978a64538b853b6585fda273ce8349ca7 (patch)
tree40e540c944c8e4b650af8087829e81d7406d042c /prototypes/fpgui2/source
parent9d17f385213027f6a6da2e3dd32d05de97847b5d (diff)
downloadfpGUI-e2c678e978a64538b853b6585fda273ce8349ca7.tar.xz
* Added a Timer to TfpgScrollBar to continue scrolling when the mouse button is held.
* Modified TfpgTimer so that when .Interval is changed inside OnTimer it is effective for the next time it is called * Added a ScrollStep property to TfpgScrollBar
Diffstat (limited to 'prototypes/fpgui2/source')
-rw-r--r--prototypes/fpgui2/source/core/fpgfx.pas11
-rw-r--r--prototypes/fpgui2/source/core/x11/fpGFX2.pas8
-rw-r--r--prototypes/fpgui2/source/gui/gui_memo.pas1
-rw-r--r--prototypes/fpgui2/source/gui/gui_scrollbar.pas77
4 files changed, 77 insertions, 20 deletions
diff --git a/prototypes/fpgui2/source/core/fpgfx.pas b/prototypes/fpgui2/source/core/fpgfx.pas
index f5b6d259..78198cb2 100644
--- a/prototypes/fpgui2/source/core/fpgfx.pas
+++ b/prototypes/fpgui2/source/core/fpgfx.pas
@@ -182,6 +182,8 @@ type
end;
+ { TfpgTimer }
+
TfpgTimer = class
private
FEnabled: boolean;
@@ -189,13 +191,14 @@ type
FInterval: integer;
FOnTimer: TNotifyEvent;
procedure SetEnabled(const AValue: boolean);
+ procedure SetInterval(const AValue: integer);
public
constructor Create(ainterval: integer);
destructor Destroy; override;
procedure CheckAlarm(ctime: TDateTime);
property Enabled: boolean read FEnabled write SetEnabled;
property NextAlarm: TDateTime read FNextAlarm;
- property Interval: integer read FInterval write FInterval;
+ property Interval: integer read FInterval write SetInterval;
property OnTimer: TNotifyEvent read FOnTimer write FOnTimer;
end;
@@ -333,6 +336,12 @@ begin
FEnabled := AValue;
end;
+procedure TfpgTimer.SetInterval(const AValue: integer);
+begin
+ FInterval := AValue;
+ FNextAlarm := now + FInterval * ONE_MILISEC;
+end;
+
constructor TfpgTimer.Create(ainterval: integer);
begin
FInterval := ainterval;
diff --git a/prototypes/fpgui2/source/core/x11/fpGFX2.pas b/prototypes/fpgui2/source/core/x11/fpGFX2.pas
index b48f0672..1cd62b83 100644
--- a/prototypes/fpgui2/source/core/x11/fpGFX2.pas
+++ b/prototypes/fpgui2/source/core/x11/fpGFX2.pas
@@ -7,10 +7,10 @@ unit fpGFX2;
interface
uses
- x11_xft, x11_keyconv, gfxbase, gfxbaseinterfaces, gfx_x11, fpgfx,
- gfx_stdimages, gfx_imgfmt_bmp, gfx_widget, gui_form, gui_label, gui_button,
- gui_edit, gui_combobox, gui_popupwindow, gui_scrollbar, gui_memo,
- gfx_UTF8utils, gui_dialogs, gui_listbox;
+ x11_xft, x11_keyconv, gfxbase, gfxbaseinterfaces, gfx_x11, fpgfx, gfx_stdimages,
+ gfx_imgfmt_bmp, gfx_widget, gui_form, gui_label, gui_button, gui_edit,
+ gui_combobox, gui_popupwindow, gui_scrollbar, gui_memo, gfx_UTF8utils,
+ gui_dialogs, gui_listbox;
implementation
diff --git a/prototypes/fpgui2/source/gui/gui_memo.pas b/prototypes/fpgui2/source/gui/gui_memo.pas
index 3b946105..23da587b 100644
--- a/prototypes/fpgui2/source/gui/gui_memo.pas
+++ b/prototypes/fpgui2/source/gui/gui_memo.pas
@@ -195,6 +195,7 @@ begin
FHScrollBar := TfpgScrollBar.Create(self);
FHScrollBar.Orientation := orHorizontal;
FHScrollBar.OnScroll := @HScrollBarMove;
+ FHScrollBar.ScrollStep := 5;
FWrapping := False;
end;
diff --git a/prototypes/fpgui2/source/gui/gui_scrollbar.pas b/prototypes/fpgui2/source/gui/gui_scrollbar.pas
index 407e4dc0..b76c103c 100644
--- a/prototypes/fpgui2/source/gui/gui_scrollbar.pas
+++ b/prototypes/fpgui2/source/gui/gui_scrollbar.pas
@@ -17,6 +17,8 @@ type
{ TfpgScrollBar }
TfpgScrollBar = class(TfpgWidget)
+ private
+ FScrollStep: integer;
protected
FSliderPos: TfpgCoord;
FSliderLength: TfpgCoord;
@@ -25,6 +27,10 @@ type
FEndBtnPressed: Boolean;
FSliderDragPos: TfpgCoord;
FSliderDragStart: TfpgCoord;
+ FScrollTimer: TfpgTimer;
+ FActiveButtonRect: TRect;
+ FMousePosition: TPoint;
+ procedure ScrollTimer(Sender: TObject);
procedure DrawButton(x, y, w, h: TfpgCoord; const imgname: string; Pressed: Boolean = False);
procedure DrawSlider(recalc: boolean);
procedure HandleLMouseDown(x, y: integer; shiftstate: word); override;
@@ -40,7 +46,9 @@ type
SliderSize: double; // 0-1
Position: integer;
constructor Create(AOwner: TComponent); override;
+ destructor Destroy; override;
procedure RepaintSlider;
+ property ScrollStep: integer read FScrollStep write FScrollStep default 1;
end;
@@ -51,6 +59,9 @@ implementation
constructor TfpgScrollBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
+ FScrollTimer := TfpgTimer.Create(500);
+ FScrollTimer.Enabled := False;
+ FScrollTimer.OnTimer := @ScrollTimer;
Orientation := orVertical;
Min := 0;
Max := 100;
@@ -60,6 +71,13 @@ begin
FSliderPos := 0;
FSliderDragging := False;
FSliderLength := 10;
+ FScrollStep := 1;
+end;
+
+destructor TfpgScrollBar.Destroy;
+begin
+ FScrollTimer.Free;
+ inherited Destroy;
end;
procedure TfpgScrollBar.HandlePaint;
@@ -88,6 +106,22 @@ begin
DrawSlider(True);
end;
+procedure TfpgScrollBar.ScrollTimer(Sender: TObject);
+begin
+ FScrollTimer.Interval := 25;
+ if (FMousePosition.X < FActiveButtonRect.Right)
+ and (FMousePosition.X > FActiveButtonRect.Left)
+ and (FMousePosition.Y < FActiveButtonRect.Bottom)
+ and (FMousePosition.Y > FActiveButtonRect.Top)
+ then begin
+ if FStartBtnPressed then PositionChange(-FScrollStep);
+ if FEndBtnPressed then PositionChange(FScrollStep);
+ end
+ else begin
+ FScrollTimer.Enabled := False;
+ end;
+end;
+
procedure TfpgScrollBar.DrawButton(x, y, w, h: TfpgCoord; const imgname: string; Pressed: Boolean = False);
var
img: TfpgImage;
@@ -163,12 +197,14 @@ begin
if Orientation = orVertical then
begin
if y <= Width then begin
- PositionChange(-1);
+ PositionChange(-FScrollStep);
FStartBtnPressed := True;
+ FActiveButtonRect := Rect(0, 0, Width, Width);
end
else if y >= Height - Width then begin
- PositionChange(1);
+ PositionChange(FScrollStep);
FEndBtnPressed := True;
+ FActiveButtonRect := Rect(0,Height-Width, Width, Height);
end
else if (y >= Width + FSliderPos) and (y <= Width + FSliderPos + FSliderLength) then
begin
@@ -176,26 +212,33 @@ begin
FSliderDragPos := y;
end;
end
- else if x <= Height then begin
- PositionChange(-1);
- FStartBtnPressed := True;
- end
- else if x >= Width - Height then begin
- PositionChange(1);
- FEndBtnPressed := True;
- end
- else if (x >= Height + FSliderPos) and (x <= Height + FSliderPos + FSliderLength) then
- begin
- FSliderDragging := True;
- FSliderDragPos := x;
+ else begin
+ if x <= Height then begin
+ PositionChange(-FScrollStep);
+ FStartBtnPressed := True;
+ FActiveButtonRect := Rect(0, 0, Height, Height);
+ end
+ else if x >= Width - Height then begin
+ PositionChange(FScrollStep);
+ FEndBtnPressed := True;
+ FActiveButtonRect := Rect(Width-Height, 0, Width, Height);
+ end
+ else if (x >= Height + FSliderPos) and (x <= Height + FSliderPos + FSliderLength) then
+ begin
+ FSliderDragging := True;
+ FSliderDragPos := x;
+ end;
end;
-
+
if FSliderDragging then
begin
FSliderDragStart := FSliderPos;
DrawSlider(False);
end
else if FStartBtnPressed or FEndBtnPressed then begin
+ FScrollTimer.Interval := 500;
+ FScrollTimer.Enabled := True;
+
HandlePaint;
end;
@@ -207,6 +250,7 @@ var
begin
inherited;
WasPressed := FStartBtnPressed or FEndBtnPressed;
+ FScrollTimer.Enabled := False;
FStartBtnPressed := False;
FEndBtnPressed := False;
FSliderDragging := False;
@@ -222,6 +266,9 @@ var
begin
inherited HandleMouseMove(x, y, btnstate, shiftstate);
+ FMousePosition.X := x;
+ FMousePosition.Y := y;
+
if (not FSliderDragging) or ((btnstate and MOUSE_LEFT) = 0) then
begin
FSliderDragging := False;