Method: MiniGL::TextHelper#write_breaking

Defined in:
lib/minigl/text.rb

#write_breaking(text, x, y, width, mode = :left, color = 0, alpha = 0xff, z_index = 0) ⇒ Object

Draws text, breaking lines when needed and when explicitly caused by the “n” character.

Parameters:

text

The text to be drawn. Line breaks are allowed.

x

The horizontal reference for drawing the text. Works like in write_line for the :left, :right and :center modes. For the :justified mode, works the same as for :left.

y

The vertical reference for drawing the text. All text will be drawn from this point down.

width

The maximum width for the lines of text. Line is broken when this width is exceeded.

mode

The alignment of the text. Valid values are :left, :right, :center and :justified.

color

The color of the text, in hexadecimal RRGGBB format.

alpha

The opacity of the text. Valid values vary from 0 (fully transparent) to 255 (fully opaque).

z_index

The z-order to draw the object. Objects with larger z-orders will be drawn on top of the ones with smaller z-orders.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/minigl/text.rb', line 110

def write_breaking(text, x, y, width, mode = :left, color = 0, alpha = 0xff, z_index = 0)
  color = (alpha << 24) | color
  text.split("\n").each do |p|
    if mode == :justified
      y = write_paragraph_justified p, x, y, width, color, z_index
    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, z_index
    end
  end
end