I have a need to create non-standard zoom increments with 8 zoom levels as well as ZoomAt:
Left Button Zoom In: ImageEnView1.ZoomAt(MousePos.X, MousePos.Y,
ImageEnView1.Zoom * 1.333333333);
Right Button Zoom Out: ImageEnView1.ZoomAt(MousePos.X, MousePos.Y, ImageEnView1.Zoom * 0.75);
The following code works the way we want it to with the mousewheel:
procedure TForm1.ImageEnView1MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
{ This procedure handles all the zooming. }
begin
if ImageEnView1.Focused then
begin
if (WheelDelta > 0) and (ZoomLevel < 9) then
begin
ZoomLevel := ZoomLevel + 1;
ImageEnView1.ZoomAt(MousePos.X, MousePos.Y,
ImageEnView1.Zoom * 1.333333333);
end;
if (WheelDelta < 0) and (ZoomLevel > 1) then
begin
ZoomLevel := ZoomLevel - 1;
ImageEnView1.ZoomAt(MousePos.X, MousePos.Y, ImageEnView1.Zoom * 0.75);
end;
Handled := True;
end
else
Handled := False;
end;
I need to duplicate zooming with the left and right mouse buttons and to set the scrolling mouse cursor when scrolling.
I have tried using the OnMouseDown event to duplicate this and it works, but the cursor does not change to the scroll cursor when scrolling (Left button is down and MouseInteract is [miScroll].
procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
iPoint: TPoint;
begin
{ Handle mouse button zooming with 8 levels of zoom with zooming at the mouse
cursor position }
iPoint := Mouse.CursorPos;
if (Button = mbLeft) and (ZoomLevel < 9) and
(ImageEnView1.MouseInteract = []) then
begin
{ Change the mouse cursor to zoom in }
ImageEnView1.Cursor := 1779;
{ Set the zoom level }
ZoomLevel := ZoomLevel + 1;
ImageEnView1.ZoomAt(iPoint.X, iPoint.Y, ImageEnView1.Zoom * 1.333333333);
end;
if (Button = mbRight) and (ZoomLevel > 1) and
(ImageEnView1.MouseInteract = []) then
begin
{ Change the mouse cursor to zoom out }
ImageEnView1.Cursor := 1778;
{ Set the zoom level }
ZoomLevel := ZoomLevel - 1;
ImageEnView1.ZoomAt(iPoint.X, iPoint.Y, ImageEnView1.Zoom * 0.75);
end;
{ If the left button is held down and ZoomLevel > 1 then scroll the image and
change the mousecursor to scroll }
if (Button = mbLeft) and (ImageEnView1.MouseCapture) and (ZoomLevel > 1) and
(ImageEnView1.MouseInteract = [miScroll]) then
{ Change the mouse cursor to scroll }
ImageEnView1.Cursor := 1782;
end;
procedure TForm1.ImageEnView1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
{ Toggle mouseinteract between scrolling and zooming }
if (ssLeft in Shift) and (ImageEnView1.MouseCapture) and (ZoomLevel > 1) then
begin
ImageEnView1.MouseInteract := [miScroll];
end
else
begin
ImageEnView1.MouseInteract := [];
end;
end;
In essence there are a maximum of 8 zoom levels and the zoom is at the mouse position at the specified zoom increments. Holding the left mouse button down and dragging the cursor sets the MouseInteract to miScroll.
Does anyone have some suggestions on how to change the mouse cursor to the scroll cursor (1782) when scrolling?
Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development