views:

76

answers:

1

hello
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 advance

def 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()
      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
+2  A: 

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.

Anurag Uniyal
btw, you don't need begin/end drawing - they do nothing. (whoops, that should be for Moayyad)
Steven Sproat
Actually, the drawing is ok (he's copying the wx demo code) - the EVT_PAINT simply blits the bitmap buffer that is being drawn to in the motion events. This is the code in my drawing program's paint event: wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)
Steven Sproat
but still .. that does not answer my question , the drawing is fine but not when you use dc.SetUserScale(). did you try it ? or do anyone have another way to zoom image
Moayyad Yaghi