wxRuby: MemoryDC problems

I’m trying to put together a quick test of buffered animation with
WxRuby, but I’m encountering a fair amount of trouble… I’m drawing
to a Wx::Bitmap first, then using Wx::DC#draw_bitmap to copy it to a
Wx::Window. But I get the following error:

C:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.1-i386-mswin32/lib/wx/
classes/bitmap.rb:18:in draw': uninitialized constant Wxruby2::Bitmap::MemoryDC (NameError) from dc_draw_line.rb:30:inon_init’

Is MemoryDC not implemented yet in WxRuby 1.9.1? It’s in the
documentation, but I know large chunks of that are auto-generated, so
I don’t totally trust it. Maybe I’m doing something wrong, though?

My code is below. Any advice would be most appreciated!

-Jay

gems_loaded = false
begin
require ‘wx’
rescue LoadError
if gems_loaded == false
require ‘rubygems’
gems_loaded = true
retry
else
raise
end
end

class MyApp < Wx::App
def on_init
#Create the top window.
frame = Wx::Frame.new(nil, :size => [300, 300])
#Create a panel within it.
view = Wx::Window.new(frame)

    buffer = Wx::Bitmap.new(300, 300)

    @x = 0

#Set up a handler for paint events.
view.evt_paint do |event|
  #Wx::Window#paint takes a block.
  #This will later be called with a device context to paint on.
  view.paint do |dc|
    buffer.draw do |buffer_dc|
      buffer_dc.clear
      buffer_dc.pen = Wx::Pen.new(Wx::Colour.new(128, 128, 128), 5)
      buffer_dc.draw_line(@x, 0, @x + 100, 100)
    end
    dc.draw_bitmap(buffer, 0, 0, false)
  end
  @x += 1
end
#Show the window.
frame.show
return true

end
end

app = MyApp.new

app.main_loop

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs