Image as a background to a form

Just curious,
if the background image is a repeated motif of a small
bitmap, where should be the complete background build?

- Create a background image greater than the (resiable) frame
in the __init?
- Create the background image in "OnPaint"

Jean-Michel Fauth, Switzerland

Jean-Michel Fauth wrote:

Just curious, if the background image is a repeated motif of a small
bitmap, where should be the complete background build?

- Create a background image greater than the (resiable) frame
in the __init?
- Create the background image in "OnPaint"

Just draw the tiles individually in a EVT_ERASE_BACKGROUND handler.

     def OnEraseBackground(self, evt):
         dc = evt.GetDC()

         if not dc:
             dc = wx.ClientDC(self)
             rect = self.GetUpdateRegion().GetBox()
             dc.SetClippingRect(rect)

         self.TileBackground(dc)

     def TileBackground(self, dc):
         sz = self.GetClientSize()
         w = self.bg_bmp.GetWidth()
         h = self.bg_bmp.GetHeight()

         # adjust for scrolled position
         spx, spy = self.GetScrollPixelsPerUnit()
         vsx, vsy = self.GetViewStart()
         dx, dy = (spx * vsx) % w, (spy * vsy) % h

         x = -dx

         while x < sz.width:
             y = -dy
             while y < sz.height:
                 dc.DrawBitmap(self.bg_bmp, x, y)
                 y = y + h

             x = x + w

···

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

Robin Dunn wrote:

Just draw the tiles individually in a EVT_ERASE_BACKGROUND handler.

or do it in EVT_SIZE, and store the full bitmap, and then just do a blit in EVT_ERASE_BACKGROUND. I suppose this only makes sense if it really takes much time to do the tiling.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Just FYI, I recently tried both approaches in the app I'm working on and
only saw a noticable difference in performance when the image was
extremely small (customer provided a 2x8 image to tile a 800x600 window
=). I settled on a middle-ground approach: create a reasonably sized
bitmap in the constructor (like 200x200) and then tile that in the draw
routine.

Regards,
Cliff

···

On Wed, 2004-09-08 at 12:12, Chris Barker wrote:

Robin Dunn wrote:
> Just draw the tiles individually in a EVT_ERASE_BACKGROUND handler.

or do it in EVT_SIZE, and store the full bitmap, and then just do a blit
  in EVT_ERASE_BACKGROUND. I suppose this only makes sense if it really
takes much time to do the tiling.

--
Cliff Wells <clifford.wells@comcast.net>