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:in
on_init’
…
What am I doing wrong? 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…
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