Class: Chingu::Text

Inherits:
GameObject show all
Defined in:
lib/chingu/text.rb

Overview

Text is a class to give the use of Gosu::Font more rubyish feel and fit it better into Chingu. Pure Gosu:

@font = Gosu::Font.new($window, "verdana", 30)
@font.draw("A Text", 200, 50, 55, 2.0)

Chingu

@text = Chingu::Text.new(:text => "A Text", :x => 200, :y => 50, :zorder => 55, :factor_x => 2.0)
@text.draw  # usually not needed as Text is a GameObject and therefore autodrawn

Constant Summary collapse

@@size =
nil
@@font =
nil

Instance Attribute Summary collapse

Attributes inherited from GameObject

#angle, #center, #center_x, #center_y, #color, #factor, #factor_x, #factor_y, #image, #mode, #x, #y, #zorder

Attributes inherited from BasicGameObject

#options, #parent, #paused, #visible

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GameObject

#distance_to, #inside_window?, #outside_window?

Methods included from Helpers::RotationCenter

#rotation_center

Methods included from Helpers::InputClient

#input, #input=

Methods inherited from BasicGameObject

all, create, #destroy, destroy_all, destroy_if, #draw_trait, has_trait, has_traits, #hide!, #pause!, #setup_trait, #show!, #unpause!, #update, #update_trait

Constructor Details

#initialize(options) ⇒ Text

Takes the standard GameObject-hash-arguments but also:

  • :text - a string of text

  • :font_name|:font - name of a systemfont (default: “verdana”)

  • :height|size - how many pixels high should the text be



34
35
36
37
38
39
40
41
# File 'lib/chingu/text.rb', line 34

def initialize(options)
  super(options)
  @text = options[:text] || "-No text specified-"
  @font =  options[:font] || @@font || default_font_name()
  @height = options[:height] || options[:size] || @@size || 15
  
  @gosu_font = Gosu::Font.new($window, @font, @height)
end

Instance Attribute Details

#gosu_fontObject (readonly)

Returns the value of attribute gosu_font.



16
17
18
# File 'lib/chingu/text.rb', line 16

def gosu_font
  @gosu_font
end

#heightObject (readonly)

Returns the value of attribute height.



16
17
18
# File 'lib/chingu/text.rb', line 16

def height
  @height
end

#textObject

Returns the value of attribute text.



15
16
17
# File 'lib/chingu/text.rb', line 15

def text
  @text
end

Class Method Details

.fontObject



20
# File 'lib/chingu/text.rb', line 20

def self.font; @@font; end

.font=(value) ⇒ Object



21
# File 'lib/chingu/text.rb', line 21

def self.font=(value); @@font = value; end

.heightObject



25
# File 'lib/chingu/text.rb', line 25

def self.height; @@size; end

.height=(value) ⇒ Object



26
# File 'lib/chingu/text.rb', line 26

def self.height=(value); @@size = value; end

.sizeObject



23
# File 'lib/chingu/text.rb', line 23

def self.size; @@size; end

.size=(value) ⇒ Object



24
# File 'lib/chingu/text.rb', line 24

def self.size=(value); @@size = value; end

Instance Method Details

#drawObject



43
44
45
# File 'lib/chingu/text.rb', line 43

def draw
  @gosu_font.draw_rot(@text, @x.to_i, @y.to_i, @zorder, @angle, @factor_x, @factor_y, @color, @mode)
end

#widthObject

Returns the width, in pixels, the given text would occupy if drawn.



50
51
52
# File 'lib/chingu/text.rb', line 50

def width
  @gosu_font.text_width(@text, @factor_x)
end