How can I use draw line in wxruby?

I use

dc = DC.new()
dc.draw_line(50, 50, 100, 100)

but it can’t be compiled
I don’t know how to declare DC variable??
in http://wxruby.rubyforge.org/doc/dc.html
it don’t tell me how to declare now variable
plese tell me :’(

Hello Bass Guitar,

Unfortunately, you cannot instantiate the DC (Device Context) directly
from
the DC Class. You need to utilize Window#draw or Window#paint to create
a
DC. The difference between these two methods, is that when you are in a
paint event (EG: evt_paint), you utilize the Window#paint method to
acquire
a Device Context. When your outside of the paint event, you utilize
Window#draw to acquire the Device Context.

An Example of inside an paint event would be this:

evt_paint() do
self.paint do |dc|
dc.draw_line(50, 50, 100, 100)
end
end

And an example of how to draw outside of a paint event:

def run_draw()
self.draw do |dc|
dc.draw_line(50, 50, 100, 100)
end
end

Once you implement this, it will work.

L8ers,

Mario S.

Mario S. wrote:

Unfortunately, you cannot instantiate the DC (Device Context) directly
from the DC Class. You need to utilize Window#draw or Window#paint to
create a DC. The difference between these two methods, is that when
you are in a paint event (EG: evt_paint), you utilize the Window#paint
method to acquire a Device Context. When your outside of the paint
event, you utilize Window#draw to acquire the Device Context.
Just a quick follow-up; Mario’s quite right that you use the
Window#paint method to acquire a DeviceContext to do drawing. It is
recommended that this is within an evt_paint handler which means that
drawing will only be done when necessary. The sample image/images.rb is
probably the simplest example to look at.

However, there isn’t a “draw” method as far as I know. “paint” is used
in all circumstances, but the exact type of DC will be different
dependent on the, um, context. But there will be no functional
difference

hth
alex

thank you :smiley:

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