[wxruby-users] How to put a background image on a panel

Trans transfire at gmail.com
Mon Mar 23 06:19:55 EDT 2009


2009/3/23 Mario Steele <mario at ruby-im.net>:
> See: http://rubyforge.org/pipermail/wxruby-users/2009-January/004448.html

Thanks. Though that only got me so far. I added:

  class Backdrop < Wx::Window
    def initialize(parent, image)
      @parent = parent
      @image  = Wx::Image.new(image)
      super(parent)
      evt_erase_background :on_erase_background
    end

    def on_erase_background(evt)
      size = @parent.get_client_size
      set_size(size)
      @image.scale(size.get_width, size.get_height)
      evt.dc.draw_bitmap(@image.to_bitmap, 0, 0, false)
    end
  end

And then added an instance of it to my panel's boxsizer:

      file  = (DIR + '/images/cover.jpg')
      image = Backdrop.new(cover_panel, file)
      cover_sizer.add(image)

It draws the image initially but it isn't scaled for some reason and
then when I resize the window it shrinks to a small square.

T.


More information about the wxruby-users mailing list