OdraEncoded

pin

May 16th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. def get_absolute_point(self, widget_point):
  2.     ''' Returns a point with the view transformations of a point in the
  3.         widget reverted '''
  4.     x, y = self.offset
  5.    
  6.     px, py = widget_point
  7.     px /= self.get_allocated_width()
  8.     py /= self.get_allocated_height()
  9.    
  10.     magw = self.get_magnified_width()
  11.     magh = self.get_magnified_height()
  12.    
  13.     x, y = x + px * magw, y + py * magh
  14.    
  15.     rotation = self.get_rotation()
  16.     if rotation:
  17.         x, y = spin_point(x, y, rotation / 180 * math.pi * -1)
  18.    
  19.     hflip, vflip = self.get_flip()
  20.     if hflip:
  21.         x *= -1
  22.     if vflip:
  23.         y *= -1
  24.        
  25.     return (x, y)
  26.  
  27. def get_pin(self, widget_point=None):
  28.     ''' Gets a pin for readjusting the view to a point in the widget
  29.         after any transformations '''
  30.     w, h = self.get_allocated_width(), self.get_allocated_height()
  31.     if not widget_point:
  32.         widget_point = w / 2, h / 2
  33.                        
  34.     absolute_point = self.get_absolute_point(widget_point)
  35.    
  36.     px, py = widget_point
  37.     px /= w; py /= h
  38.     scalar_point = px, py
  39.    
  40.     return absolute_point, scalar_point
  41.    
  42. def adjust_to_pin(self, pin):
  43.     ''' Adjusts the view so that the same widget point in the pin can be
  44.         converted to the same absolute point in the pin '''
  45.     (x, y), (px, py) = pin
  46.    
  47.     hflip, vflip = self.get_flip()
  48.     if hflip:
  49.         x *= -1
  50.     if vflip:
  51.         y *= -1
  52.    
  53.     rotation = self.get_rotation()
  54.     if rotation:
  55.         x, y = spin_point(x, y, rotation / 180 * math.pi)
  56.    
  57.     magw = self.get_magnified_width()
  58.     magh = self.get_magnified_height()
  59.    
  60.     x -= px * magw
  61.     y -= py * magh
  62.    
  63.     self.adjust_to(x, y)
Advertisement
Add Comment
Please, Sign In to add comment