+ Reply to Thread
Results 1 to 4 of 4

Thread: Help with Zooming in and out on an image please?

  1. #1
    Champion
    Join Date
    Feb 2011
    Posts
    586

    Default Help with Zooming in and out on an image please?

    I'm trying to recreate a map utility that I can zoom in and out on, but am having some difficulty implementing the 'zoom' so that it mimics the default map zoom in/out.

    What I've got so far is the ability to use the WheelForward and WheelBack to resize my image and redraw the image with bigger/small dimensions, but it's always redrawing from the (0,0) position on my frame... so it always expands/contracts from the (0,0) location and then I have to move the image with my mouse accordingly to compensate for the image shift to the right and down or to the left and up.

    So my question is: Does anyone know of an example I can look at that implements zooming in and out of an image that functions like the default map zooming feature does... where the image 'expands' from the point where the mouse is hovered over?

    Thanks for any insight into this.

  2. #2
    Plane Walker Kreiri's Avatar
    Join Date
    Feb 2011
    Posts
    402

    Default

    M-m...

    From SetPoint documentation:

    This function can take many different forms. In general, it looks like this: SetPoint(point_on_this_frame, target_frame, point_on_target_frame [, x_offset, y_offset]).

    The first part is the point on this frame that will be attached. Usually, these are string identifiers. "TOPLEFT", "TOPCENTER", "TOPRIGHT", "CENTERLEFT", "CENTER", "CENTERRIGHT", "BOTTOMLEFT", "BOTTOMCENTER", "BOTTOMRIGHT". You may also use a string identifier that refers to a single axis - "TOP", "BOTTOM", "LEFT", "RIGHT", "CENTERX", "CENTERY". If you want more direct numeric control you can use number pairs. 0,0 is equivalent to "TOPLEFT", 1,1 is equivalent to "BOTTOMRIGHT", 0.5,nil is equivalent to "CENTERX".
    How about:

    1) get mouse position and calculate mouse position relative to image frame and to mask frame
    2) clear image points and set new anchor point on image

    local mouseImageX, mouseImageY = -- mouse position relative to top left corner of image frame
    local mouseMaskX, mouseMaskY = -- mouse position relative to top left corner of mask frame

    local imageW, imageH, maskW, maskH = -- widths and heights of image and mask frames

    local pointImageX = mouseImageX / imageW
    local pointImageY = mouseImageY / imageH

    local pointIMaskX = mouseMaskX / maskW
    local pointIMaskY = mouseMaskY / maskH

    -- ClearAll or ClearPoint (never used either, so I'm not sure which is better) on your image and SetPoint from it to mask frame using pair pointImageX, pointImageY on image frame and pointIMaskX, pointIMaskY on mask frame. I never used " more direct numeric control", though, so I'm not sure on syntax of a "pair". Perhaps, a table {pointImageX, pointImageY} ?

    3) Resize image frame.
    Last edited by Kreiri; 02-24-2012 at 11:25 AM.
    Feminism is the radical notion that women are people.

  3. #3
    Plane Walker Kreiri's Avatar
    Join Date
    Feb 2011
    Posts
    402

    Default

    Or maybe like this:

    Calculate where center point (or topleft, or whatever) of image should be (relative to mask) after zooming, then clear this point, set it to new point and resize image.
    Last edited by Kreiri; 02-24-2012 at 11:30 AM.
    Feminism is the radical notion that women are people.

  4. #4
    Champion
    Join Date
    Feb 2011
    Posts
    586

    Default

    Kreiri...

    Thanks for the reply. I've acutally been working on adjusting the SetPoint but your help with the mouse positions and mask are very helpful.

    I was hoping to have someone show me an example addon that already implemented this that I could muddle through, but your info might acutally get me through the areas I'm not familiar with.

    Thanks again.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts