Transparent line in Frame

Hi

Thanks for a great GUI toolkit!

I want to draw transparent lines in a Frame. I have the following setup
but my lines are not transparent.

My colour object is created using:
transparent_blue = Colour.new(0,0,255,100)

and I draw lines using a pen with this colour:
@pen = Pen.new(transparent_blue)

In evt_paint of frame I have:
dc.set_pen(@pen)
dc.draw_line(x1,y1,x2,y2)

The line is blue but there is no transparency.

I set the alpha level to 100 where 255 is supposed to be completely
opaque.

I’m on Windows XP SP2 and

C:>ruby --version
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

Please help!

Regards, Andreas

Andreas W. wrote:

I want to draw transparent lines in a Frame. I have the following setup
but my lines are not transparent.
The standard DC doesn’t support transparency (except on OS X I think).
But you can instead use wxGraphicsContext which fully supports
transparency, antialiasing and other advanced drawing tools like splines
and transforms. You create one from an ordinary DC like this:

paint.do | dc |
gdc = Wx::GraphicsContext.create(dc)
gdc.stroke_line(0, 0, 500, 500)

etc

end

Unfortunately the wxWidgets developers decided to make the API to
GraphicsContext different to DC, but the results are worth it for
graphical apps.

alex

Alex F. wrote:

The standard DC doesn’t support transparency (except on OS X I think).
But you can instead use wxGraphicsContext which fully supports
transparency, antialiasing and other advanced drawing tools like splines
and transforms. You create one from an ordinary DC like this:

paint.do | dc |
gdc = Wx::GraphicsContext.create(dc)
gdc.stroke_line(0, 0, 500, 500)

etc

end

Thanks! I’m having a bit of trouble, though. Here is a small example I
use:

require ‘wx’
include Wx

App.run do
frame = Frame.new(nil, :title => ‘GraphicsContext example’, :width =>
[300,400])

frame.evt_paint do
frame.paint do |dc|
gdc = GraphicsContext.create(dc)
siz = dc.size
h, w = siz.height, siz.width
#dc.draw_line(0,0,w,h)
gdc.stroke_line(0,0,w,h)
end
end

frame.show
end

It should draw / stroke a diagonal line in the frame. This works if I
use draw_line.

What am I missing? :slight_smile:

Andreas

Andreas W. wrote:

frame.evt_paint do
frame.paint do |dc|
gdc = GraphicsContext.create(dc)
siz = dc.size
h, w = siz.height, siz.width
#dc.draw_line(0,0,w,h)

  gdc.pen = Wx::Pen.new( Wx::Colour.new(255, 0, 0, 128), 20)

What am I missing? :slight_smile:
It seems with GraphicsContext, you need to set some sort of pen before
starting drawing - there is no default pen when it’s first created.

alex

Alex F. wrote:

Andreas W. wrote:

frame.evt_paint do
frame.paint do |dc|
gdc = GraphicsContext.create(dc)
siz = dc.size
h, w = siz.height, siz.width
#dc.draw_line(0,0,w,h)

  gdc.pen = Wx::Pen.new( Wx::Colour.new(255, 0, 0, 128), 20)

What am I missing? :slight_smile:
It seems with GraphicsContext, you need to set some sort of pen before
starting drawing - there is no default pen when it’s first created.

alex

Thanks!