Internal class for 2-D coordinate transformations
| 379 | self._mouseCallback(Point(e.x, e.y)) |
| 380 | |
| 381 | class Transform: |
| 382 | |
| 383 | """Internal class for 2-D coordinate transformations""" |
| 384 | |
| 385 | def __init__(self, w, h, xlow, ylow, xhigh, yhigh): |
| 386 | # w, h are width and height of window |
| 387 | # (xlow,ylow) coordinates of lower-left [raw (0,h-1)] |
| 388 | # (xhigh,yhigh) coordinates of upper-right [raw (w-1,0)] |
| 389 | xspan = (xhigh-xlow) |
| 390 | yspan = (yhigh-ylow) |
| 391 | self.xbase = xlow |
| 392 | self.ybase = yhigh |
| 393 | self.xscale = xspan/float(w-1) |
| 394 | self.yscale = yspan/float(h-1) |
| 395 | |
| 396 | def screen(self,x,y): |
| 397 | # Returns x,y in screen (actually window) coordinates |
| 398 | xs = (x-self.xbase) / self.xscale |
| 399 | ys = (self.ybase-y) / self.yscale |
| 400 | return int(xs+0.5),int(ys+0.5) |
| 401 | |
| 402 | def world(self,xs,ys): |
| 403 | # Returns xs,ys in world coordinates |
| 404 | x = xs*self.xscale + self.xbase |
| 405 | y = self.ybase - ys*self.yscale |
| 406 | return x,y |
| 407 | |
| 408 | |
| 409 | # Default values for various item configuration options. Only a subset of |