Forum: wxRuby How to put a background image on a panel

45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2009-03-23 03:12
(Received via mailing list)
Well I've made a lot of progress on my app, but I'm stuck on figuring
out how to add a bitmap. I have a notebook and a page panel. On this
panel I want to put a backdrop image and scale it to the size of the
panel. How do I do this? I looked at some of the samples related to
bitmaps and I could not see how to apply that to my situation.

Thanks,
T.
3396e4a3df8a840faec520af8555a400?d=identicon&s=25 Mario Steele (Guest)
on 2009-03-23 09:59
(Received via mailing list)
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2009-03-23 11:33
(Received via mailing list)
2009/3/23 Mario Steele <mario@ruby-im.net>:
> See: http://rubyforge.org/pipermail/wxruby-users/2009-J...

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.
3396e4a3df8a840faec520af8555a400?d=identicon&s=25 Mario Steele (Guest)
on 2009-03-23 15:41
(Received via mailing list)
Remove the set_size from the on_erase_background(), you shouldn't use
set_size() in on_erase_background().
This topic is locked and can not be replied to.