draw a line to cursor

Alex,

Thanks for the help, I added your code but it is not working properly.
I can see that it somewhat erases the lines but many are still drawn
just opaquely. Does that make sense? I pretty much just added your
code.

Cole Harris
Enterasys Networks
Phone: 978-684-1652
Email: coharris@enterasys.com
www. http://www.enterasys.com

···

-----Original Message-----
From: Alex Tweedly [mailto:alex@tweedly.net]
Sent: Thursday, September 01, 2005 2:44 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] draw a line to cursor

Harris, Cole wrote:

Hi all,

I am trying to do a relatively easy task... Draw a line from a static
spot on the canvas to my cursor and have it follow the cursor wherever
it goes. I was able to do this by using the wxDC function DrawLine()
and a redraw it everytime the event OnMotion is called. The problem
arises when I draw it I must Refresh() everytime in order to eliminate
the old line from the canvas. This causes a very sluggish motion and
redrawing. Is there any faster way to do this or possibly a built in
wrapper that I am not aware of?
Thanks

-Cole

Draw it using a "reversible" function, then undraw it before drawing the

next one.

e.g. wxDC.SetLogicalFunction (wxINVERT)
Then when you "undraw" it (i.e. draw it the second time) you reverse the

original effect.
.

--
Alex Tweedly http://www.tweedly.net

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.18/86 - Release Date:
31/08/2005

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Harris, Cole wrote:

Alex,

Thanks for the help, I added your code but it is not working properly.
I can see that it somewhat erases the lines but many are still drawn
just opaquely. Does that make sense? I pretty much just added your
code.

Doesn't really make sense to me. It sounds like maybe you're not undrawing it properly; you need to be sure that on each movement, if you have a previously drawn line, that you "undraw" it with the old co-ords, then draw (and remember) the new line to the new mouse coords.

Here's some sample code (unfortunately, in PythonCard rather than raw wxPython - it would take me a while to convert it to raw wxPython, but hopefully it is clear enough ...)

class MyBackground(model.Background):

    def on_initialize(self, event):
        self.rootX, self.rootY = None, None
        dc = wx.ClientDC(self.components.BitmapCanvas1)
        dc.SetPen(wx.Pen('black', 1, wx.DOT))
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        dc.SetLogicalFunction(wx.INVERT)
        self.dc = dc
        self.banding = False

    def on_BitmapCanvas1_mouseUp(self, event):
        print event.x, event.y
        self.rootX, self.rootY = event.x, event.y
        self.lastX, self.lastY = self.rootX, self.rootY
        self.banding = True
       def on_BitmapCanvas1_mouseMove(self, event):
        if self.banding:
            if self.lastX <> self.rootX or self.lastY <> self.rootY:
                # undraw last one
                self.dc.DrawLine(self.rootX, self.rootY, self.lastX, self.lastY)
                       self.lastX, self.lastY = event.x, event.y
            self.dc.DrawLine(self.rootX, self.rootY, self.lastX, self.lastY)

···

--
Alex Tweedly http://www.tweedly.net

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.18/86 - Release Date: 31/08/2005