mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-01 20:03:39 +02:00
TAChart: refactor zooming
git-svn-id: trunk@18818 -
This commit is contained in:
parent
aa768c5872
commit
c27d946f16
@ -44,6 +44,10 @@ type
|
|||||||
X, Y: Double;
|
X, Y: Double;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TDoubleRect = record
|
||||||
|
a, b: TDoublePoint;
|
||||||
|
end;
|
||||||
|
|
||||||
TPointDistFunc = function (const A, B: TPoint): Integer;
|
TPointDistFunc = function (const A, B: TPoint): Integer;
|
||||||
|
|
||||||
TAxisScale = (asIncreasing, asDecreasing, asLogIncreasing, asLogDecreasing);
|
TAxisScale = (asIncreasing, asDecreasing, asLogIncreasing, asLogDecreasing);
|
||||||
|
@ -244,11 +244,10 @@ type
|
|||||||
AxisColor: TColor; // Axis color
|
AxisColor: TColor; // Axis color
|
||||||
FScale, FOffset: TDoublePoint; // Coordinates transformation
|
FScale, FOffset: TDoublePoint; // Coordinates transformation
|
||||||
|
|
||||||
Down: Boolean;
|
FIsMouseDown: Boolean;
|
||||||
Zoom: Boolean;
|
FIsZoomed: Boolean;
|
||||||
Fixed: Boolean;
|
FSelectionRect: TRect;
|
||||||
XDown, YDown, XOld, YOld: Integer;
|
FCurrentExtent: TDoubleRect;
|
||||||
ZoomRect: TRect;
|
|
||||||
|
|
||||||
FShowReticule: Boolean;
|
FShowReticule: Boolean;
|
||||||
FShowVerticalReticule: Boolean;
|
FShowVerticalReticule: Boolean;
|
||||||
@ -736,11 +735,10 @@ begin
|
|||||||
FYGraphMax := 0;
|
FYGraphMax := 0;
|
||||||
FYGraphMin := 0;
|
FYGraphMin := 0;
|
||||||
|
|
||||||
MirrorX := False;
|
MirrorX := false;
|
||||||
Fixed := False;
|
FIsZoomed := false;
|
||||||
Zoom := False;
|
FShowReticule := false;
|
||||||
FShowReticule := False;
|
FShowVerticalReticule := false;
|
||||||
FShowVerticalReticule := False;
|
|
||||||
FBackColor := Color;
|
FBackColor := Color;
|
||||||
|
|
||||||
FGraphBrush := TBrush.Create;
|
FGraphBrush := TBrush.Create;
|
||||||
@ -1329,16 +1327,14 @@ var
|
|||||||
XMinSeries, XMaxSeries, YMinSeries, YMaxSeries: Double;
|
XMinSeries, XMaxSeries, YMinSeries, YMaxSeries: Double;
|
||||||
begin
|
begin
|
||||||
MaybeDrawReticules;
|
MaybeDrawReticules;
|
||||||
// Search # of points, min and max of all series
|
if FIsZoomed then begin
|
||||||
if Zoom then begin
|
FXGraphMin := FCurrentExtent.a.X;
|
||||||
Zoom := false;
|
FYGraphMin := FCurrentExtent.a.Y;
|
||||||
Fixed := true;
|
FXGraphMax := FCurrentExtent.b.X;
|
||||||
XImageToGraph(ZoomRect.Left, FXGraphMin);
|
FYGraphMax := FCurrentExtent.b.Y;
|
||||||
XImageToGraph(ZoomRect.Right, FXGraphMax);
|
|
||||||
YImageToGraph(ZoomRect.Bottom, FYGraphMin);
|
|
||||||
YImageToGraph(ZoomRect.Top, FYGraphMax);
|
|
||||||
end
|
end
|
||||||
else if not Fixed then begin
|
else begin
|
||||||
|
// Search # of points, min and max of all series
|
||||||
XMinSeries := MaxDouble;
|
XMinSeries := MaxDouble;
|
||||||
XMaxSeries := MinDouble;
|
XMaxSeries := MinDouble;
|
||||||
YMinSeries := MaxDouble;
|
YMinSeries := MaxDouble;
|
||||||
@ -1584,20 +1580,6 @@ begin
|
|||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TChart.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
|
||||||
begin
|
|
||||||
if
|
|
||||||
(X < XImageMax) and (X > XImageMin) and
|
|
||||||
(Y < YImageMin) and (Y > YImageMax) and FAllowZoom
|
|
||||||
then begin
|
|
||||||
Down := True;
|
|
||||||
XDown := X;
|
|
||||||
YDown := Y;
|
|
||||||
XOld := X;
|
|
||||||
YOld := Y;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChart.DrawReticule(ACanvas: TCanvas; const APos: TPoint);
|
procedure TChart.DrawReticule(ACanvas: TCanvas; const APos: TPoint);
|
||||||
begin
|
begin
|
||||||
PrepareXorPen;
|
PrepareXorPen;
|
||||||
@ -1614,6 +1596,17 @@ begin
|
|||||||
ACanvas.LineTo(AX, YImageMax);
|
ACanvas.LineTo(AX, YImageMax);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChart.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||||
|
begin
|
||||||
|
if
|
||||||
|
(X < XImageMax) and (X > XImageMin) and
|
||||||
|
(Y < YImageMin) and (Y > YImageMax) and FAllowZoom
|
||||||
|
then begin
|
||||||
|
FIsMouseDown := true;
|
||||||
|
FSelectionRect := Rect(X, Y, X, Y);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChart.MouseMove(Shift: TShiftState; X, Y: Integer);
|
procedure TChart.MouseMove(Shift: TShiftState; X, Y: Integer);
|
||||||
var
|
var
|
||||||
i, pointIndex: Integer;
|
i, pointIndex: Integer;
|
||||||
@ -1621,13 +1614,11 @@ var
|
|||||||
pt, newRetPos: TPoint;
|
pt, newRetPos: TPoint;
|
||||||
value: TDoublePoint;
|
value: TDoublePoint;
|
||||||
begin
|
begin
|
||||||
if Down then begin
|
if FIsMouseDown then begin
|
||||||
PrepareXorPen;
|
PrepareXorPen;
|
||||||
Canvas.Rectangle(XDown, YDown, XOld, YOld);
|
Canvas.Rectangle(FSelectionRect);
|
||||||
Canvas.Rectangle(XDown, YDown, X, Y);
|
FSelectionRect.BottomRight := Point(X, Y);
|
||||||
|
Canvas.Rectangle(FSelectionRect);
|
||||||
XOld := X;
|
|
||||||
YOld := Y;
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
r := Rect(XImageMin, YImageMin, XImageMax, YImageMax);
|
r := Rect(XImageMin, YImageMin, XImageMax, YImageMax);
|
||||||
@ -1664,34 +1655,20 @@ end;
|
|||||||
|
|
||||||
procedure TChart.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
procedure TChart.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||||
begin
|
begin
|
||||||
if not Down then exit;
|
if not FIsMouseDown then exit;
|
||||||
FReticulePos := Point(X, Y);
|
FReticulePos := Point(X, Y);
|
||||||
|
|
||||||
PrepareXorPen;
|
PrepareXorPen;
|
||||||
Canvas.Rectangle(XDown, YDown, XOld, YOld);
|
Canvas.Rectangle(FSelectionRect);
|
||||||
|
|
||||||
Down := false;
|
FIsMouseDown := false;
|
||||||
if (XDown < XOld) and (YDown < YOld) then
|
|
||||||
Zoom := true
|
with FSelectionRect do begin
|
||||||
else begin
|
FIsZoomed := (Left < Right) and (Top < Bottom);
|
||||||
Zoom := false;
|
if FIsZoomed then begin
|
||||||
Fixed := false;
|
ImageToGraph(Left, Bottom, FCurrentExtent.a.X, FCurrentExtent.a.Y);
|
||||||
end;
|
ImageToGraph(Right, Top, FCurrentExtent.b.X, FCurrentExtent.b.Y);
|
||||||
if XDown < XOld then begin
|
end;
|
||||||
ZoomRect.Left := XDown;
|
|
||||||
ZoomRect.Right := XOld;
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
ZoomRect.Left := XOld;
|
|
||||||
ZoomRect.Right := XDown;
|
|
||||||
end;
|
|
||||||
if YDown < YOld then begin
|
|
||||||
ZoomRect.Bottom := YOld;
|
|
||||||
ZoomRect.Top := YDown;
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
ZoomRect.Bottom := YDown;
|
|
||||||
ZoomRect.Top := YOld;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Invalidate;
|
Invalidate;
|
||||||
@ -1809,8 +1786,7 @@ end;
|
|||||||
|
|
||||||
procedure TChart.ZoomFull;
|
procedure TChart.ZoomFull;
|
||||||
begin
|
begin
|
||||||
Zoom := false;
|
FIsZoomed := false;
|
||||||
Fixed := false;
|
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user