I need to draw over image (to comment over it) in a scrolled panel. I'm having troubles with it since it doesn't behave right when I zoom it in or out. it stops drawing , and then it shows it after a while in a wrong place. right in the upper left corner of the window. and doesn't draw lines correctly .
below is the code for the (onLeftDown
) function (the button that should draw). the right button event (zoom in). hope it is clear enough.
do you guys have any idea what is going on, and how do I solve it?
thanks in advancedef OnLeftButtonEvent(self, event):
self.curLine = []
self.x, self.y = event.GetPositionTuple()
self.CaptureMouse()
def OnMotion(self, event):
if self.HasCapture() and event.Dragging():
dc = wx.BufferedDC(None,self.buffer)
dc.SetUserScale(self.scale,self.scale)
# to zoom in and out ( increases whenever someone presses the right mouse button
dc.BeginDrawing()开发者_StackOverflow社区
dc.SetPen(wx.Pen(wx.BLUE, 3))
coords = (self.x, self.y) + event.GetPositionTuple()
self.curLine.append(coords)
dc.DrawLine(*coords)
self.x, self.y = event.GetPositionTuple()
self.SetXY(event)
dc.EndDrawing()
def OnRightDown(self,event):
print self.scale
self.scale=self.scale*2.0
self.initDrawing()
self.maxHeight=self.maxHeight*2
self.maxWidth=self.maxWidth*2
You need to scale mouse co-ordinates so that it is in sync with scaling of drawing, so if you are using userScale=2, mouse at x=10 will end up at 20 . so you need to do this
sx, sy = x/cur_scale, y/cur_scale
You also need to be do drawing in EVT_PAINT
event not on onmotion, on motion you just need to refresh window and paint event should take care of what you want to draw.
精彩评论