Created
March 15, 2010 09:03
-
-
Save hansent/332641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymt import * | |
class ScaleManipulation(MTWidget): | |
def init(self): | |
self.register_event_type('on_scale') | |
self.touches = [] | |
self.distance = 0 | |
def on_scale(self, scale): | |
self.parent.width *= scale | |
self.parent.height *= scale | |
def on_touch_down(self, touch): | |
if len(self.touches) < 2: | |
touch.grab(self) | |
self.touches.append(touch) | |
if len(self.touches) == 2: | |
self.distance = self.touches[0].distance(self.touches[1]) | |
def on_touch_move(self, touch): | |
if len(self.touches) > 1: | |
old_distance = self.distance | |
self.distance = self.touches[0].distance(self.touches[1]) | |
self.dispatch_event('on_scale', self.distance/old_distance) | |
def on_touch_up(self, touch): | |
if touch in self.touches: | |
self.touches.remove(touch) | |
rect = MTRectangularWidget() | |
rect.add_widget(ScaleManipulation()) | |
runTouchApp(rect) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment