class Castaway::Element::Text
Public Class Methods
new(production, scene, string)
click to toggle source
Calls superclass method
Castaway::Element::Base::new
# File lib/castaway/element/text.rb, line 7 def initialize(production, scene, string) super(production, scene) @string = string @gravity = 'Center' @font = 'TimesNewRoman' @font_size = 24 @background = 'transparent' @kerning = 0 @fill = @stroke = nil attribute(:font_size, 1) { |memo, value| memo * value } attribute(:kerning, -> { @kerning }) { |memo, value| memo + value } end
Public Instance Methods
_prepare_canvas(t, canvas)
click to toggle source
# File lib/castaway/element/text.rb, line 57 def _prepare_canvas(t, canvas) canvas.xc @background font_size = @font_size * attributes[:font_size] kerning = attributes[:kerning] canvas.pointsize font_size commands = [ "gravity #{@gravity}", "font '#{@font}'" ] commands << "fill #{@fill}" if @fill commands << "stroke #{@stroke}" if @stroke commands << format('kerning %.1f', kerning) if kerning commands << "text 0,0 '#{@string}'" canvas.draw commands.join(' ') end
background(color)
click to toggle source
# File lib/castaway/element/text.rb, line 32 def background(color) @background = color self end
fill(color)
click to toggle source
# File lib/castaway/element/text.rb, line 22 def fill(color) @fill = color self end
font(font)
click to toggle source
# File lib/castaway/element/text.rb, line 47 def font(font) @font = font self end
font_size(size)
click to toggle source
# File lib/castaway/element/text.rb, line 52 def font_size(size) @font_size = size self end
gravity(gravity)
click to toggle source
# File lib/castaway/element/text.rb, line 42 def gravity(gravity) @gravity = gravity self end
kerning(kerning)
click to toggle source
# File lib/castaway/element/text.rb, line 37 def kerning(kerning) @kerning = kerning self end
stroke(color)
click to toggle source
# File lib/castaway/element/text.rb, line 27 def stroke(color) @stroke = color self end