+class ImageWindow(wx.Window):
+ def __init__(self, parent, model, zoom):
+ wx.Window.__init__(self, parent)
+ self.model = model
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+ self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
+ self.SetSize((model.width, model.height))
+ self.zoom = zoom
+ self.x = 0
+ self.y = 0
+ self.lastx = 0
+ self.lasty = 0
+ self.firstclick = None
+ self.model.drawModeListeners += [self.reset]
+
+ def reset(self):
+ self.firstclick = None
+
+ def OnMouseClick(self, event):
+ x = min(max(event.X, 0), self.model.width-1)
+ y = min(max(event.Y, 0), self.model.height-1)
+ if self.model.drawmode == PixelColorCheck:
+ check = self.model.find(x,y)
+ if check:
+ self.model.delete(check)
+ else:
+ p = slef.model.GetPixel(x,y)
+ color = p[0]<<16|p[1]<<8|p[2]
+ self.model.append(PixelColorCheck(x,y,color))
+ else:
+ if not self.firstclick:
+ self.firstclick = (x,y)
+ else:
+ x1,y1 = self.firstclick
+ self.model.append(self.model.drawmode(x1,y1,x,y))
+ self.firstclick = None
+
+ self.Refresh()
+
+ def OnMouse(self, event):
+ if event.LeftIsDown():
+ return self.OnMouseClick(event)
+ lastx = self.x
+ lasty = self.y
+ self.x = min(max(event.X, 0), self.model.width-1)
+ self.y = min(max(event.Y, 0), self.model.height-1)
+ if lastx!=self.x or lasty!=self.y:
+ self.zoom.setpos(self.x,self.y)
+ self.Refresh()
+
+ def OnPaint(self, event):
+ dc = wx.PaintDC(self)
+ self.Draw(dc)
+
+ def Draw(self,dc=None):
+ if not dc:
+ dc = wx.ClientDC(self)
+
+ dc.SetBackground(wx.Brush((0,0,0)))
+ dc.DrawBitmap(self.model.bitmap, 0, 0, False)
+
+ red = wx.Pen((192,0,0),2)
+
+ if self.firstclick:
+ x,y = self.firstclick
+ if AreaCheck in self.model.drawmode.__bases__:
+ dc.SetBrush(wx.TRANSPARENT_BRUSH)
+ dc.DrawRectangle(x,y,self.x-x,self.y-y)
+ dc.SetBrush(wx.WHITE_BRUSH)
+ elif TwoPixelCheck in self.model.drawmode.__bases__:
+ x,y = self.firstclick
+ dc.DrawLine(x,y,self.x,self.y)
+
+ for check in self.model.checks:
+ if TESTMODE and not check.verifies(model):
+ dc.SetPen(red)
+ else:
+ dc.SetPen(wx.BLACK_PEN)
+ if AreaCheck in check.__class__.__bases__:
+ dc.SetBrush(wx.TRANSPARENT_BRUSH)
+ dc.DrawRectangle(check.x,check.y,check.x2-check.x,check.y2-check.y)
+ dc.SetBrush(wx.WHITE_BRUSH)
+ else:
+ x = check.x
+ y = check.y
+ l = 0
+ for r in range(10):
+ r = (r+1)*3.141526/5
+ dc.DrawLine(x+10*math.sin(l), y+10*math.cos(l), x+10*math.sin(r), y+10*math.cos(r))
+ l = r
+ dc.DrawLine(x,y,x+1,y)
+ if TwoPixelCheck in check.__class__.__bases__:
+ dc.DrawLine(x,y,check.x2,check.y2)
+ dc.SetPen(wx.BLACK_PEN)
+