How to use drawText on FXCanvas in FXRuby?

365 Views Asked by At

I am trying to make text appear on a FXCanvas. when I use this code:

def score_box(event)
FXDCWindow.new(@canvas) do |dc|

    dc.drawText(640, 450, @score)
end     
end  

but it gives me an error saying I need to select a font, how do I do this? or could you provide anyway to make text on a canvas? Thanks

-bipolarpants

1

There are 1 best solutions below

2
On BEST ANSWER

You need to select an FXFont object into the device context (dc), e.g.

FXDCWindow.new(@canvas) do |dc|
  font = FXFont.new(...)
  font.create
  dc.font = font
  dc.drawText(640, 450, @score)
end