Method: Ray::Text#initialize

Defined in:
lib/ray/text.rb

#initialize(string, opts = {}) ⇒ Text

Returns a new instance of Text.

Parameters:

  • string (String)

    The content of the text

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :encoding (Object) — default: "utf-8"

    The encoding for the text. Unneeded in 1.9.

  • :size (Object) — default: 12

    The character size.

  • :style (Object) — default: Font::STYLE_NORMAL

    Style of the text.

  • :at (Object) — default: (0, 0)

    Position of the text.

  • :scale (Object) — default: (1, 1)

    Scale applied to the text.

  • :zoom (Object)

    Same as :scale

  • :angle (Object) — default: 0

    Rotation applied to the text.

  • :color (Object) — default: Ray::Color.white

    The color used to draw the text

  • :font (Ray::Font, String) — default: Ray::Font.default

    Font used to draw

  • :shader (Ray::Shader) — default: nil

    Shader



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ray/text.rb', line 17

def initialize(string, opts = {})
  opts = {
    :encoding => string.respond_to?(:encoding) ? string.encoding : "utf-8",
    :size     => 12,
    :style    => Normal,
    :at       => [0, 0],
    :angle    => 0,
    :color    => Ray::Color.white
  }.merge(opts)

  @encoding = opts[:encoding].to_s

  self.string = string
  self.size   = opts[:size]
  self.style  = opts[:style]
  self.pos    = opts[:at]
  self.scale  = opts[:scale] || opts[:zoom] || [1, 1]
  self.angle  = opts[:angle]
  self.color  = opts[:color]
  self.shader = opts[:shader]

  if font = opts[:font]
    self.font = font.is_a?(String) ? Ray::FontSet[font] : font
  end
end