Just reporting back.

Turns out I didn't RTFM, and I didn't see Actor.transform_stage_point(x,y).
So for my final zoomable-scroll area, the code looks like this:



# Get relative position of event location
(X,Y) = self.group.transform_stage_point(event.x, event.y)

# Get the current scaled size of the group
(oldscalesizex, oldscalesizey) = self.group.get_transformed_size()

#Initiate the scale animation
self.group.set_scale(scale, scale)

# Get the new scaled size of the group
(newscalesizex, newscalesizey) = self.group.get_transformed_size()

# Get the pixel difference between the old scale and the new scale
pdifx = newscalesizex - oldscalesizex
pdify = newscalesizey - oldscalesizey

# Get the current position and size of the group
(posx, posy) = self.group.get_position()
(sizex, sizey) = self.group.get_size()

# Calculate the final offset for the position of group
# multiply pixel difference in scale by the ratio of relative event
position vs size
offsetx = (pdifx * (X / sizex))
offsety = (pdify * (Y / sizey))

# apply offset
posx -= offsetx
posy -= offsety

# Move position of group so the event position appears to be the zoom center
self.group.set_position(posx, posy)



Perhaps this code could be included as a method for Actor?
set_scale_relative(scale_x, scale_y, center_x, center_y) or similar ?
It's quite useful for times where you don't want the anchor to move, but
still want scaling from a relative position.

Anyway hope it helps someone in a similar position.




On Wed, May 23, 2012 at 9:50 AM, Mark Boorer <markbo...@gmail.com> wrote:

> Hi all,
>
> Not sure if this has been answered before, and I couldn't find anything in
> my searches.
>
> I'm using python-clutter, and I'm implementing a zoomable-scroll area
> using nested Group containers.
>
> Like this:
>
> viewArea = clutter.Group()
> container = clutter.Group()
> viewArea.add(container)
>
> I'm nesting them, so that the top level group doesn't move, and receives
> all the mouse events, and it moves / scales the "container" inside.
>
> I've hit a slight problem though. When scaling the "container", I want the
> user to have the area the mouse is under remain in the center of the zoom.
> I can use set_scale_full() and calculate the center coordinates relative to
> "viewArea" but these values don't work it the container is already scaled.
>
> Is there a way to get the relative position of an actor when it's already
> scaled?
>
> Thanks,
> Mark
>
_______________________________________________
clutter-app-devel-list mailing list
clutter-app-devel-list@clutter-project.org
http://lists.clutter-project.org/listinfo/clutter-app-devel-list

Reply via email to