]> git.neil.brown.name Git - scribble.git/commitdiff
Fix detection of position of glyph on screen.
authorNeil Brown <neilb@notabene.brown>
Wed, 27 Aug 2008 20:30:50 +0000 (06:30 +1000)
committerNeil Brown <neilb@notabene.brown>
Wed, 27 Aug 2008 20:30:50 +0000 (06:30 +1000)
Using BBox.relpos to find position of glyph on screen didn't work
so well as it is too easy to miss the 'middle' which should be the
easiest to hit.  So modify bbox so that above/below midline are easy
to detect.

scribble.py

index 01b912ae65d8b2a5c23085e0e41570b7dd98d479..d448006ad2ae045789145bf3d5619a2fd395e7c0 100755 (executable)
@@ -411,10 +411,12 @@ class BBox:
             self.maxy = p.y
         if p.y < self.miny:
             self.miny = p.y
-    def finish(self):
+    def finish(self, div = 3):
         # if aspect ratio is bad, we adjust max/min accordingly
         # before setting [xy][12].  We don't change self.min/max
         # as they are used to place stroke in bigger bbox.
+        # Normally divisions are at 1/3 and 2/3. They can be moved
+        # by setting div e.g. 2 = 1/2 and 1/2
         (minx,miny,maxx,maxy) = (self.minx,self.miny,self.maxx,self.maxy)
         if (maxx - minx) * 3 < (maxy - miny) * 2:
             # too narrow
@@ -429,10 +431,11 @@ class BBox:
             miny = mid - halfheight
             maxy = mid + halfheight
 
-        self.x1 = int((2*minx + maxx)/3)
-        self.x2 = int((minx + 2*maxx)/3)
-        self.y1 = int((2*miny + maxy)/3)
-        self.y2 = int((miny + 2*maxy)/3)
+        div1 = div - 1
+        self.x1 = int((div1*minx + maxx)/div)
+        self.x2 = int((minx + div1*maxx)/div)
+        self.y1 = int((div1*miny + maxy)/div)
+        self.y2 = int((miny + div1*maxy)/div)
 
     def row(self, p):
         # 0, 1, 2 - top to bottom
@@ -874,7 +877,7 @@ class ScribblePad:
         alloc = self.page.get_allocation()
         pagebb = BBox(Point(0,0))
         pagebb.add(Point(alloc.width, alloc.height))
-        pagebb.finish()
+        pagebb.finish(div = 2)
 
         p = PPath(self.line[1][0], self.line[1][1])
         for pp in self.line[1:]: