ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Changing the Zoom Value and Max Levels
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

w2m

USA
1990 Posts

Posted - Jan 29 2015 :  13:51:23  Show Profile  Reply
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

xequte

39052 Posts

Posted - Feb 02 2015 :  15:04:38  Show Profile  Reply
Hi Bill

Sorry for the delay. So essentially:
- Wheel zooms in and out
- Clicking zooms in and out
- Click and drag causes scroll

Is that correct?

P.S. don't forget that you can set MouseWheelParams.ZoomPosition := iemwMouse to cause the wheel to zoom at the current mouse position.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 02 2015 :  18:40:35  Show Profile  Reply
Thanks for the reply. The answer to your 3 questions are yes. As I stated I have it working with the mouse wheel as well as with the buttons, but I can not set the cursor to 1782 so show the scroll cursor when the left button is down and dragging. Any suggestions.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

39052 Posts

Posted - Feb 04 2015 :  17:09:10  Show Profile  Reply
Hi Bill

If you set ImageEnView1.MouseInteract to [miZoom, miScroll];

And ImageEnView1.Cursor := 1779;

Then ImageEn should automatically provide the functionality you need (click to zoom with zoom cursor, drag to scroll with scroll cursor).

Apologies if I have missed the point. You may also want to check the OnSetCursor event.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: