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.
Mario Steele
2009-Mar-23 08:12 UTC
[wxruby-users] How to put a background image on a panel
See: http://rubyforge.org/pipermail/wxruby-users/2009-January/004448.html On Sun, Mar 22, 2009 at 9:03 PM, Trans <transfire at gmail.com> wrote:> 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. > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20090323/567aac77/attachment.html>
2009/3/23 Mario Steele <mario at ruby-im.net>:> See: http://rubyforge.org/pipermail/wxruby-users/2009-January/004448.htmlThanks. 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.
Mario Steele
2009-Mar-23 13:20 UTC
[wxruby-users] How to put a background image on a panel
Remove the set_size from the on_erase_background(), you shouldn''t use set_size() in on_erase_background(). On Mon, Mar 23, 2009 at 5:19 AM, Trans <transfire at gmail.com> wrote:> 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. > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20090323/d3416cdf/attachment-0001.html>