ScrolledWindow and creating an overlay

Hi all, this is my first post & I am quite new to wxPython.
What I want to try to do is have a ScrolledWindow with a bitmap attached to it, so I can scroll around the image. At the same time I want to overlay some lines, these lines are fixed with respect to the viewing panel - in other words these lines will need to move around the scrolled window to conter the scroll.
Perhaps an example, in a side scrolling game the background will scroll but the player will remain fixed.

Anyhow, I can load & display & scroll the image, but the lines don't draw properly overtop of it, they get blurred & shreded.
Here is the OnPaint event, hopefully you should see what I am trying to do.

def OnPaint(self, event):
       dc = wx.PaintDC( self.panel_1 )
       if self.image is not None:
        mem = wx.MemoryDC()
        mem.SelectObject(self.bmp)
        mem.SetPen(wx.Pen(wx.RED, 14))
        x,y = self.panel_1.CalcUnscrolledPosition(0,0)
        #mem.DrawLine(x,y,x+50,y+50) # this line should draw a screen fixed line, but doesn't
        mem.DrawLine(0,0,50,50) # this line draws an image relative line
        self.panel_1.PrepareDC(dc)
        #dc.Clear()
        #dc.DrawBitmap(self.image.Scale(x,y).ConvertToBitmap(),0,0,1)
        #dc.DrawBitmap(self.bmp,0,0,1)
        a,b = mem.GetSize()
        dc.Blit(0,0,a,b,mem,0,0)

Any thoughts?

Cheers
Brad

Brad Beveridge wrote:

Hi all, this is my first post & I am quite new to wxPython.
What I want to try to do is have a ScrolledWindow with a bitmap attached to it, so I can scroll around the image. At the same time I want to overlay some lines, these lines are fixed with respect to the viewing panel - in other words these lines will need to move around the scrolled window to conter the scroll.
Perhaps an example, in a side scrolling game the background will scroll but the player will remain fixed.

Anyhow, I can load & display & scroll the image, but the lines don't draw properly overtop of it, they get blurred & shreded.
Here is the OnPaint event, hopefully you should see what I am trying to do.

IIUC, it appears that you are drawing your lines onto your background bitmap via the MemoryDC. This updates the bitmap too so the next time you paint it will draw the lines in a different spot, but the old ones are still there and so are still displayed.

You probably want to create a new buffer bitmap for the MemoryDC, draw your background bitmap onto that, then your lines and then blit that bitmap to the real DC.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks for the pointers. The same still happens with the following draw code
        self.panel_1.PrepareDC(dc)
        a,b = self.image.GetWidth(),self.image.GetHeight()
        mem = wx.MemoryDC()
        mem.SelectObject(wx.EmptyBitmap(a,b))
        mem.SetPen(wx.Pen(wx.RED, 14))
        x,y = self.panel_1.CalcUnscrolledPosition(0,0)
        mem.DrawLine(x,y,x+150,y+150) dc.Blit(0,0,a,b,mem,0,0)

It is like the drawline isn't getting done until too late. If I put the code (approx 100 lines) up on a website somewhere, would somebody be willing to take a look at it?

Cheers
Brad

Robin Dunn wrote:

···

Brad Beveridge wrote:

Hi all, this is my first post & I am quite new to wxPython.
What I want to try to do is have a ScrolledWindow with a bitmap attached to it, so I can scroll around the image. At the same time I want to overlay some lines, these lines are fixed with respect to the viewing panel - in other words these lines will need to move around the scrolled window to conter the scroll.
Perhaps an example, in a side scrolling game the background will scroll but the player will remain fixed.

Anyhow, I can load & display & scroll the image, but the lines don't draw properly overtop of it, they get blurred & shreded.
Here is the OnPaint event, hopefully you should see what I am trying to do.

IIUC, it appears that you are drawing your lines onto your background bitmap via the MemoryDC. This updates the bitmap too so the next time you paint it will draw the lines in a different spot, but the old ones are still there and so are still displayed.

You probably want to create a new buffer bitmap for the MemoryDC, draw your background bitmap onto that, then your lines and then blit that bitmap to the real DC.

Well, I've fixed it in a very hacky way by doing 2 refreshes instead of one, so this is in my OnPaint method
        if self.repaintHack is True:
            self.Refresh()
            self.repaintHack = False
        else:
            self.repaintHack = True

Very nasty. Oh well.

Cheers
Brad

Brad Beveridge wrote:

···

Thanks for the pointers. The same still happens with the following draw code
       self.panel_1.PrepareDC(dc)
       a,b = self.image.GetWidth(),self.image.GetHeight()
       mem = wx.MemoryDC()
       mem.SelectObject(wx.EmptyBitmap(a,b))
       mem.SetPen(wx.Pen(wx.RED, 14))
       x,y = self.panel_1.CalcUnscrolledPosition(0,0)
       mem.DrawLine(x,y,x+150,y+150) dc.Blit(0,0,a,b,mem,0,0)

It is like the drawline isn't getting done until too late. If I put the code (approx 100 lines) up on a website somewhere, would somebody be willing to take a look at it?

Cheers
Brad

Robin Dunn wrote:

Brad Beveridge wrote:

Hi all, this is my first post & I am quite new to wxPython.
What I want to try to do is have a ScrolledWindow with a bitmap attached to it, so I can scroll around the image. At the same time I want to overlay some lines, these lines are fixed with respect to the viewing panel - in other words these lines will need to move around the scrolled window to conter the scroll.
Perhaps an example, in a side scrolling game the background will scroll but the player will remain fixed.

Anyhow, I can load & display & scroll the image, but the lines don't draw properly overtop of it, they get blurred & shreded.
Here is the OnPaint event, hopefully you should see what I am trying to do.

IIUC, it appears that you are drawing your lines onto your background bitmap via the MemoryDC. This updates the bitmap too so the next time you paint it will draw the lines in a different spot, but the old ones are still there and so are still displayed.

You probably want to create a new buffer bitmap for the MemoryDC, draw your background bitmap onto that, then your lines and then blit that bitmap to the real DC.

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

Brad Beveridge wrote:

Thanks for the pointers. The same still happens with the following draw code
       self.panel_1.PrepareDC(dc)
       a,b = self.image.GetWidth(),self.image.GetHeight()
       mem = wx.MemoryDC()
       mem.SelectObject(wx.EmptyBitmap(a,b))
       mem.SetPen(wx.Pen(wx.RED, 14))
       x,y = self.panel_1.CalcUnscrolledPosition(0,0)
       mem.DrawLine(x,y,x+150,y+150) dc.Blit(0,0,a,b,mem,0,0)

Whose paint event is it? self's or panel_1's?

It is like the drawline isn't getting done until too late. If I put the code (approx 100 lines) up on a website somewhere, would somebody be willing to take a look at it?

If you can reduce the app to the point of showing just this problem then go ahead and send it to the list.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!