wxruby - painting in device context

H

Haris Bogdanoviæ

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.
 
M

Marvin Gülker

Haris said:
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
 
M

Marvin Gülker

Haris said:
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
 
M

Michael Brooks

From: "Haris Bogdanoviæ said:
Newsgroups: comp.lang.ruby
Sent: Friday, September 25, 2009 7:13 PM
Subject: 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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top