OSDN Git Service

fix layer picking to take rotation/zoom into account
authorMartin Renold <martinxyz@gmx.ch>
Sun, 30 Nov 2008 19:09:05 +0000 (19:09 +0000)
committerMartin Renold <martinxyz@gmx.ch>
Sun, 30 Nov 2008 19:09:05 +0000 (19:09 +0000)
svn://svn.gna.org/svn/mypaint/trunk@160

gui/drawwindow.py
gui/tileddrawwidget.py

index a21112e..aecd489 100644 (file)
@@ -542,16 +542,12 @@ class Window(gtk.Window):
         self.doc.select_layer(idx)
 
     def pick_layer_cb(self, action):
-        #idx = self.doc.get_layer_at()
-        x, y, modifiers = self.window.get_pointer()
-        print 'pick layer at', x, y
-        best = None
+        x, y = self.tdw.get_cursor_in_model_coordinates()
         for idx, layer in reversed(list(enumerate(self.doc.layers))):
             alpha = layer.surface.get_alpha (x, y, 5)
             if alpha > 0.1:
                 self.doc.select_layer(idx)
                 return
-        print '(almost) no layer found'
         self.doc.select_layer(0)
 
     def new_layer_cb(self, action):
index fdb04e2..b7a2f9f 100644 (file)
@@ -173,6 +173,11 @@ class TiledDrawWidget(gtk.DrawingArea):
         # looks like we always get nearest-neighbour downsampling
         return cr
 
+    def get_cursor_in_model_coordinates(self):
+        x, y, modifiers = self.window.get_pointer()
+        cr = self.get_model_coordinates_cairo_context()
+        return cr.device_to_user(x, y)
+
     def repaint(self, device_bbox=None, model_bbox=None):
         # FIXME: ...we do not fill tile-free background white in this function...