Wxruby - painting in device context

Hi.
I’m trying to paint in DC context:

---------------------------------------------------

frame = Frame.new(nil, -1, “”)

frame.paint { |dc|

dc.draw_line(50, 50, 100, 100)                                #  for

this I don’t see the line

dc.draw_bitmap(Bitmap.new('c:\img.bmp'),0,0)        # and for this

program crashes

}

-----------------------------------------------------------

Does anyone know why is this happening ?

Thanks.

Haris Bogdanovi� wrote:

Hi.
I’m trying to paint in DC context:

---------------------------------------------------

frame = Frame.new(nil, -1, “”)

frame.paint { |dc|

dc.draw_line(50, 50, 100, 100)                                #  for

this I don’t see the line

dc.draw_bitmap(Bitmap.new('c:\img.bmp'),0,0)        # and for this

program crashes

}

-----------------------------------------------------------

Does anyone know why is this happening ?

Thanks.

It appears to me that you cannot draw on a DC before the window is
created. The following shows nothing with Ruby 1.9 on my Ubuntu Jaunty
machine:

=======================================
#!/usr/bin/env ruby
#Encoding: UTF-8
require “wx”

class GUI < Wx::App
include Wx

def on_init
@mainwindow = Frame.new(nil, -1, “Test”, DEFAULT_POSITION,
Size.new(400, 400))

@mainwindow.paint{|dc| dc.draw_line(0, 0, 100, 100)}

@mainwindow.show

end

end

x = GUI.new
x.main_loop

But if you use the #paint method after the window has been created,
everything works fine:

=======================================
#!/usr/bin/env ruby
#Encoding: UTF-8
require “wx”

class GUI < Wx::App
include Wx

def on_init
@mainwindow = Frame.new(nil, -1, “Test”, DEFAULT_POSITION,
Size.new(400, 400))

Timer.after(2000){@mainwindow.paint{|dc| dc.draw_line(0, 0, 100, 

100)}}

@mainwindow.show

end

end

x = GUI.new
x.main_loop

Marvin

Haris Bogdanovi� wrote:

dc.draw_bitmap(Bitmap.new('c:\img.bmp'),0,0)        # and for this

program crashes
You may want to use a forward slash / instead of the backslash, even on
Windows. An alternative is to escape the backslash by duplicating it:
“C:/img.bmp” or “C:\img.bmp”

Marvin

frame.paint { |dc|

Hello Haris:

I haven’t been able to get a line drawn either but I know it’s possible.
The WxRuby samples directory contains a files called bitmap.rb and
graphics_drawing.rb that draws bitmaps, text and rectangles.

Michael