Search code examples
rubyfxruby

How to use drawText on FXCanvas in FXRuby?


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


Solution

  • 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