Class: Fox::Canvas::TextShape

Inherits:
Shape
  • Object
show all
Defined in:
lib/fox16/canvas.rb

Instance Attribute Summary collapse

Attributes inherited from Shape

#foreground, #selector, #target, #x, #y

Instance Method Summary collapse

Methods inherited from Shape

#apply_dc, #bounds, #deselect, #disable, #draggable=, #draggable?, #drawOutline, #enable, #enabled?, #hide, #hit?, #makeControlPoints, #move, #position, #resize, #select, #selected?, #show, #visible?

Constructor Details

#initialize(x, y, w, h, text = nil) ⇒ TextShape

Returns a new instance of TextShape.



249
250
251
252
253
254
255
# File 'lib/fox16/canvas.rb', line 249

def initialize(x, y, w, h, text=nil)
  super(x, y)
  @width = w
  @height = h
  @text = text
  @font = FXApp.instance.normalFont
end

Instance Attribute Details

#fontObject (readonly)

Returns the value of attribute font.



246
247
248
# File 'lib/fox16/canvas.rb', line 246

def font
  @font
end

#heightObject

Returns the value of attribute height.



247
248
249
# File 'lib/fox16/canvas.rb', line 247

def height
  @height
end

#textObject (readonly)

Returns the value of attribute text.



246
247
248
# File 'lib/fox16/canvas.rb', line 246

def text
  @text
end

#widthObject

Returns the value of attribute width.



247
248
249
# File 'lib/fox16/canvas.rb', line 247

def width
  @width
end

Instance Method Details

#draw(dc) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/fox16/canvas.rb', line 257

def draw(dc)
  old_foreground = dc.foreground
  apply_dc(dc) do
    if selected?
      dc.lineWidth = 5
      dc.drawRectangle(x - 3, y - 3, width + 6, height + 6)
    end

    old_background = dc.background
    dc.background = old_foreground
    oldTextFont = dc.font
    dc.font = @font
    dc.drawImageText(x, y + height, text)
    dc.font = oldTextFont if oldTextFont
    dc.background = old_foreground
  end
end