|
@@ -43,7 +43,7 @@ type
|
|
|
constructor Create(AOwner: TComponent); override; overload;
|
|
|
procedure Draw(Renderer: TFresnelRenderer); virtual;
|
|
|
procedure DrawCorner(Renderer: TFresnelRenderer; const r: TFresnelRect); virtual;
|
|
|
- function GetHit(const X, Y: TFresnelLength; out aPosition: TFresnelLength): THit; override;
|
|
|
+ function GetHit(const X, Y: TFresnelLength; Nearest: boolean; out aPosition: TFresnelLength): THit; override;
|
|
|
end;
|
|
|
|
|
|
{ TFresnelRenderer }
|
|
@@ -392,9 +392,23 @@ end;
|
|
|
{ TRendererScrollBar }
|
|
|
|
|
|
procedure TRendererScrollBar.MouseHandler(Event: TAbstractEvent);
|
|
|
+
|
|
|
+ procedure SetScrollPos(NewPos: TFresnelLength);
|
|
|
+ begin
|
|
|
+ if Horizontal then
|
|
|
+ begin
|
|
|
+ if Parent.ComputedDirection=CSSRegistry.kwRTL then
|
|
|
+ NewPos:=NewPos-Size+Page;
|
|
|
+ Parent.ScrollLeft:=NewPos;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ Parent.ScrollTop:=NewPos;
|
|
|
+ end;
|
|
|
+
|
|
|
var
|
|
|
MouseEvt: TFresnelMouseEvent absolute Event;
|
|
|
- X, Y, NewPos: TFresnelLength;
|
|
|
+ X, Y, p, NewPos: TFresnelLength;
|
|
|
+ Hit: THit;
|
|
|
begin
|
|
|
// the mouse event has the coord of the Parent's clientbox
|
|
|
// -> translate to GrandParent's child box
|
|
@@ -409,15 +423,17 @@ begin
|
|
|
evtMouseDown:
|
|
|
if MouseEvt.Button=mbLeft then
|
|
|
begin
|
|
|
- MouseDownHit:=GetHit(X,Y,MouseDownPos);
|
|
|
+ MouseDownHit:=GetHit(X,Y,false,MouseDownGrabPos);
|
|
|
+ MouseDownPosition:=Position;
|
|
|
{$IFDEF VerboseFresnelScrolling}
|
|
|
- writeln('TRendererScrollBar.MouseHandler Mouse Down ',Parent.Name,' Horz=',Horizontal,' Hit=',MouseDownHit,' p=',FloatToCSSStr(MouseDownPos));
|
|
|
+ writeln('TRendererScrollBar.MouseHandler Mouse Down ',Parent.Name,' Horz=',Horizontal,' Hit=',MouseDownHit,' p=',FloatToCSSStr(MouseDownGrabPos));
|
|
|
{$ENDIF}
|
|
|
case MouseDownHit of
|
|
|
THit.hButtonLT: ;
|
|
|
THit.hButtonRB: ;
|
|
|
THit.hThumb:
|
|
|
begin
|
|
|
+ SetPointerCapture((MouseEvt as TFresnelMouseDownEvent).PointerId);
|
|
|
exit;
|
|
|
end;
|
|
|
THit.hTrackLT:
|
|
@@ -429,25 +445,33 @@ begin
|
|
|
else exit;
|
|
|
end;
|
|
|
NewPos:=Max(0,Min(NewPos,Size-Page));
|
|
|
- if Horizontal then
|
|
|
- begin
|
|
|
- if Parent.ComputedDirection=CSSRegistry.kwRTL then
|
|
|
- NewPos:=NewPos-Size+Page;
|
|
|
- Parent.ScrollLeft:=NewPos;
|
|
|
- end
|
|
|
- else
|
|
|
- Parent.ScrollTop:=NewPos;
|
|
|
+ SetScrollPos(NewPos);
|
|
|
end;
|
|
|
evtMouseMove:
|
|
|
- if MouseDownHit>THit.hNone then begin
|
|
|
- //Hit:=GetHit(X,Y,p);
|
|
|
- //writeln('TRendererScrollBar.MouseHandler Mouse Move ',Element.Name,' Hit=',Hit,' p=',FloatToCSSStr(p));
|
|
|
+ if (MouseEvt.Button=mbLeft) then
|
|
|
+ begin
|
|
|
+ Hit:=GetHit(X,Y,true,p);
|
|
|
+ {$IFDEF VerboseFresnelScrolling}
|
|
|
+ writeln('TRendererScrollBar.MouseHandler Mouse Move ',Parent.Name,' Horz=',Horizontal,' Hit=',Hit,' p=',FloatToCSSStr(p),' GrabPos=',FloatToCSSStr(MouseDownGrabPos));
|
|
|
+ {$ENDIF}
|
|
|
+ if MouseDownHit=THit.hThumb then
|
|
|
+ begin
|
|
|
+ // move thumb
|
|
|
+ NewPos:=MouseDownPosition+(p-MouseDownGrabPos);
|
|
|
+ NewPos:=Max(0,Min(NewPos,Size-Page));
|
|
|
+ SetScrollPos(NewPos);
|
|
|
+ end;
|
|
|
end;
|
|
|
evtMouseUp:
|
|
|
- if (MouseEvt.Button=mbLeft) and (MouseDownHit>THit.hNone) then
|
|
|
+ if (MouseEvt.Button=mbLeft) then
|
|
|
begin
|
|
|
- //Hit:=GetHit(X,Y,p);
|
|
|
- //writeln('TRendererScrollBar.MouseHandler Mouse Up ',Element.Name,' Hit=',Hit,' p=',FloatToCSSStr(p));
|
|
|
+ Hit:=GetHit(X,Y,true,p);
|
|
|
+ {$IFDEF VerboseFresnelScrolling}
|
|
|
+ writeln('TRendererScrollBar.MouseHandler Mouse Up ',Parent.Name,' Horz=',Horizontal,' Hit=',Hit,' p=',FloatToCSSStr(p));
|
|
|
+ {$ENDIF}
|
|
|
+ MouseDownGrabPos:=0;
|
|
|
+ MouseDownHit:=THit.hNone;
|
|
|
+ ReleasePointerCapture((MouseEvt as TFresnelMouseUpEvent).PointerId);
|
|
|
end;
|
|
|
end;
|
|
|
end;
|
|
@@ -531,7 +555,8 @@ begin
|
|
|
Renderer.FillRect(TrackColor,r);
|
|
|
end;
|
|
|
|
|
|
-function TRendererScrollBar.GetHit(const X, Y: TFresnelLength; out aPosition: TFresnelLength): THit;
|
|
|
+function TRendererScrollBar.GetHit(const X, Y: TFresnelLength; Nearest: boolean; out
|
|
|
+ aPosition: TFresnelLength): THit;
|
|
|
var
|
|
|
LT, RB: TFresnelLength;
|
|
|
begin
|
|
@@ -539,14 +564,14 @@ begin
|
|
|
aPosition:=0;
|
|
|
if Horizontal then
|
|
|
begin
|
|
|
- if (X<Box.Left) or (X>Box.Right) then
|
|
|
+ if (not Nearest) and ((X<Box.Left) or (X>Box.Right)) then
|
|
|
exit;
|
|
|
LT:=Box.Left+Border;
|
|
|
RB:=Box.Right-Border;
|
|
|
if LT>RB-1 then exit;
|
|
|
aPosition:=(X-LT) / (RB-LT);
|
|
|
end else begin
|
|
|
- if (Y<Box.Top) or (Y>Box.Bottom) then
|
|
|
+ if (not Nearest) and ((Y<Box.Top) or (Y>Box.Bottom)) then
|
|
|
exit;
|
|
|
LT:=Box.Top+Border;
|
|
|
RB:=Box.Bottom-Border;
|