Author: esr
Date: Sun Oct 12 22:41:00 2008
New Revision: 30101

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30101&view=rev
Log:
trackplacer: draw icons at proper size.

Modified:
    trunk/data/tools/trackplacer

Modified: trunk/data/tools/trackplacer
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/trackplacer?rev=30101&r1=30100&r2=30101&view=diff
==============================================================================
--- trunk/data/tools/trackplacer (original)
+++ trunk/data/tools/trackplacer Sun Oct 12 22:41:00 2008
@@ -23,9 +23,8 @@
 """
 
 # TODO:
-# 1. Fix clipping of flag icon.
-# 2. Test reading and writing of track files
-# 3. Write track-to-macro tool.
+# 1. Test reading and writing of track files
+# 2. Write track-to-macro tool.
 
 import sys, os, exceptions, getopt
 
@@ -50,11 +49,11 @@
 
 # Size of the rectangle around the mouse pointer within which the code
 # will seek tracking dots. Should be about (N-1)/2 where N is the
-# pixel radius of the journey dot.  For this and other reasons, it's
+# pixel radius of the largest icon.  For this and other reasons, it's
 # helpful if the tracking dot and other icons all have a square
 # aspect ratio and an odd number of pixels on the sise, so each has
 # a well-defined center pixel.
-vision_distance = 5
+vision_distance = 12
 
 class ReadException(exceptions.Exception):
     "Exception thrown while reading a track file."
@@ -326,17 +325,21 @@
             ys = self.map_height - y
         self.pixmap.draw_drawable(self.default_gc, self.map, x, y, x, y, xs, 
ys)
 
-    def draw_feature(self, x, y, icon):
+    def draw_feature(self, widget, x, y, action, erase=False):
         "Draw specified icon on the map."
-        self.log("Drawing action=%s, dest_x=%d dest_y=%d width=%d height=%d" % 
\
-              (icon.action,
-               x-icon.icon_width/2, y-icon.icon_height/2,
-               icon.icon_width, icon.icon_height))
-        self.pixmap.draw_pixbuf(self.default_gc,
-                                icon.icon,
-                                0, 0,
-                                x-icon.icon_width/2, y-icon.icon_height/2,
-                                icon.icon_width, icon.icon_height)
+        icon = self.action_dictionary[action]
+        if erase:
+            # The +1 is a slop factor allowing for even-sized icons
+            rect = (x-icon.icon_width/2, y-icon.icon_height/2,
+                    icon.icon_width+1, icon.icon_height+1)
+            self.log("Erasing action=%s, dest=%s" % (icon.action, rect))
+            self.refresh_map(*rect)
+        else:
+            rect = (x-icon.icon_width/2, y-icon.icon_height/2,
+                    icon.icon_width, icon.icon_height)
+            self.log("Drawing action=%s, dest=%s" % (icon.action, rect))
+            self.pixmap.draw_pixbuf(self.default_gc, icon.icon, 0, 0, *rect)
+        widget.queue_draw_area(*rect)
         
     def configure_event(self, widget, event):
         "Create a new backing pixmap of the appropriate size."
@@ -357,30 +360,29 @@
         "Return a feature-containing rangle around a pixel."
         return (int(p[0]-d), int(p[1]-d), d*2, d*2)
 
-    def draw_icon(self, widget, x, y):
-        "Draw or erase a track dot."
-        feature = self.journey.snap_to(x, y)
-        # Skip the redraw in half the cases
-        self.log("Action %s at (%d, %d): feature = %s" % (self.action, x, y, 
feature))
-        if (feature == None) and (self.action == "DELETE"):
-            return
-        if (feature != None) and (self.action != "DELETE"):
-            return
-        # Actual drawing and mutation of the journey track happens here
-        if not feature and self.action != "DELETE":
-            rect = self.bounding_box((x, y))
-            self.draw_feature(x, y, self.action_dictionary[self.action])
-            self.journey.track.append((self.action, int(x), int(y)))
-        elif feature and self.action == "DELETE":
-            rect = self.bounding_box(feature)
-            self.refresh_map(*rect)
-            self.journey.remove(feature[0], feature[1])
-        widget.queue_draw_area(rect[0], rect[1], rect[2], rect[3])
-        self.log("Track is %s" % self.journey)
-
     def button_press_event(self, widget, event):
         if event.button == 1 and self.pixmap != None:
-            self.draw_icon(widget, event.x, event.y)
+            x = int(event.x)
+            y = int(event.y)
+            feature = self.journey.snap_to(x, y)
+            # Skip the redraw in half the cases
+            self.log("Action %s at (%d, %d): feature = %s" % (self.action, x, 
y, feature))
+            if (feature == None) and (self.action == "DELETE"):
+                return
+            if (feature != None) and (self.action != "DELETE"):
+                return
+            # Actual drawing and mutation of the journey track happens here
+            if not feature and self.action != "DELETE":
+                self.draw_feature(widget, x, y, self.action)
+                self.journey.track.append((self.action, x, y))
+            elif feature and self.action == "DELETE":
+                candidates = self.journey.find(x, y)
+                if len(candidates) == 1:
+                    # Prefer to delete the most recent candidate
+                    action = self.journey.track[candidates[-1]][0]
+                    self.draw_feature(widget, x, y, action, erase=True)
+                    self.journey.remove(feature[0], feature[1])
+            self.log("Track is %s" % self.journey)
         return True
 
     def motion_notify_event(self, widget, event):
@@ -394,7 +396,7 @@
 
         # Lets you draw pixels by dragging, not the effect we want.
         #if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:
-        #    self.draw_icon(widget, x, y)
+        #    self.button_left_click(widget, x, y)
 
         return True
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to