Class: AGL::TextHelper
- Inherits:
-
Object
- Object
- AGL::TextHelper
- Defined in:
- lib/minigl/text.rb
Instance Method Summary collapse
-
#initialize(font, line_spacing = 0) ⇒ TextHelper
constructor
A new instance of TextHelper.
- #write_breaking(text, x, y, width, mode = :left, color = 0, alpha = 0xff) ⇒ Object
- #write_line(text, x, y, mode = :left, color = 0, alpha = 0xff) ⇒ Object
Constructor Details
#initialize(font, line_spacing = 0) ⇒ TextHelper
Returns a new instance of TextHelper.
3 4 5 6 |
# File 'lib/minigl/text.rb', line 3 def initialize font, line_spacing = 0 @font = font @line_spacing = line_spacing end |
Instance Method Details
#write_breaking(text, x, y, width, mode = :left, color = 0, alpha = 0xff) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/minigl/text.rb', line 20 def write_breaking text, x, y, width, mode = :left, color = 0, alpha = 0xff color = (alpha << 24) | color text.split("\n").each do |p| if mode == :justified y = write_paragraph_justified p, x, y, width, color else rel = case mode when :left then 0 when :center then 0.5 when :right then 1 else 0 end y = write_paragraph p, x, y, width, rel, color end end end |
#write_line(text, x, y, mode = :left, color = 0, alpha = 0xff) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/minigl/text.rb', line 8 def write_line text, x, y, mode = :left, color = 0, alpha = 0xff color = (alpha << 24) | color rel = case mode when :left then 0 when :center then 0.5 when :right then 1 else 0 end @font.draw_rel text, x, y, 0, rel, 0, 1, 1, color end |