Class: CyberarmEngine::Text
- Inherits:
-
Object
- Object
- CyberarmEngine::Text
- Defined in:
- lib/cyberarm_engine/text.rb
Constant Summary collapse
- CACHE =
{}
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#factor_x ⇒ Object
Returns the value of attribute factor_x.
-
#factor_y ⇒ Object
Returns the value of attribute factor_y.
-
#options ⇒ Object
Returns the value of attribute options.
-
#shadow ⇒ Object
Returns the value of attribute shadow.
-
#shadow_alpha ⇒ Object
Returns the value of attribute shadow_alpha.
-
#shadow_color ⇒ Object
Returns the value of attribute shadow_color.
-
#shadow_size ⇒ Object
Returns the value of attribute shadow_size.
-
#size ⇒ Object
Returns the value of attribute size.
-
#text ⇒ Object
Returns the value of attribute text.
-
#textobject ⇒ Object
readonly
Returns the value of attribute textobject.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
- #alpha ⇒ Object
- #alpha=(n) ⇒ Object
- #check_cache(size, font_name) ⇒ Object
- #draw ⇒ Object
- #height ⇒ Object
-
#initialize(text, options = {}) ⇒ Text
constructor
A new instance of Text.
- #update ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(text, options = {}) ⇒ Text
Returns a new instance of Text.
8 9 10 11 12 13 14 15 16 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/cyberarm_engine/text.rb', line 8 def initialize(text, ={}) @text = text.to_s || "" @options = @size = [:size] || 18 @font = [:font] || "sans-serif"#Gosu.default_font_name @x = [:x] || 0 @y = [:y] || 0 @z = [:z] || 1025 @factor_x = [:factor_x] || 1 @factor_y = [:factor_y] || 1 @color = [:color] || Gosu::Color::WHITE @alignment= [:alignment] || nil @shadow = true if [:shadow] == true @shadow = false if [:shadow] == false @shadow = true if [:shadow] == nil @shadow_size = [:shadow_size] ? [:shadow_size] : 1 @shadow_alpha= [:shadow_alpha] ? [:shadow_alpha] : 30 @shadow_alpha= [:shadow_alpha] ? [:shadow_alpha] : 30 @shadow_color= [:shadow_color] @textobject = check_cache(@size, @font) if @alignment case @alignment when :left @x = 0+BUTTON_PADDING when :center @x = ($window.width/2)-(@textobject.text_width(@text)/2) when :right @x = $window.width-BUTTON_PADDING-@textobject.text_width(@text) end end return self end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
6 7 8 |
# File 'lib/cyberarm_engine/text.rb', line 6 def color @color end |
#factor_x ⇒ Object
Returns the value of attribute factor_x.
6 7 8 |
# File 'lib/cyberarm_engine/text.rb', line 6 def factor_x @factor_x end |
#factor_y ⇒ Object
Returns the value of attribute factor_y.
6 7 8 |
# File 'lib/cyberarm_engine/text.rb', line 6 def factor_y @factor_y end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/cyberarm_engine/text.rb', line 5 def @options end |
#shadow ⇒ Object
Returns the value of attribute shadow.
6 7 8 |
# File 'lib/cyberarm_engine/text.rb', line 6 def shadow @shadow end |
#shadow_alpha ⇒ Object
Returns the value of attribute shadow_alpha.
6 7 8 |
# File 'lib/cyberarm_engine/text.rb', line 6 def shadow_alpha @shadow_alpha end |
#shadow_color ⇒ Object
Returns the value of attribute shadow_color.
6 7 8 |
# File 'lib/cyberarm_engine/text.rb', line 6 def shadow_color @shadow_color end |
#shadow_size ⇒ Object
Returns the value of attribute shadow_size.
6 7 8 |
# File 'lib/cyberarm_engine/text.rb', line 6 def shadow_size @shadow_size end |
#size ⇒ Object
Returns the value of attribute size.
5 6 7 |
# File 'lib/cyberarm_engine/text.rb', line 5 def size @size end |
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/cyberarm_engine/text.rb', line 6 def text @text end |
#textobject ⇒ Object (readonly)
Returns the value of attribute textobject.
6 7 8 |
# File 'lib/cyberarm_engine/text.rb', line 6 def textobject @textobject end |
#x ⇒ Object
Returns the value of attribute x.
5 6 7 |
# File 'lib/cyberarm_engine/text.rb', line 5 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/cyberarm_engine/text.rb', line 5 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
5 6 7 |
# File 'lib/cyberarm_engine/text.rb', line 5 def z @z end |
Instance Method Details
#alpha ⇒ Object
140 141 142 |
# File 'lib/cyberarm_engine/text.rb', line 140 def alpha @color.alpha end |
#alpha=(n) ⇒ Object
136 137 138 |
# File 'lib/cyberarm_engine/text.rb', line 136 def alpha=(n) @color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, n) end |
#check_cache(size, font_name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cyberarm_engine/text.rb', line 43 def check_cache(size, font_name) available = false font = nil if CACHE[size] if CACHE[size][font_name] font = CACHE[size][font_name] available = true else available = false end else available = false end unless available font = Gosu::Font.new(@size, name: @font) CACHE[@size] = {} unless CACHE[@size].is_a?(Hash) CACHE[@size][@font] = font end return font end |
#draw ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cyberarm_engine/text.rb', line 109 def draw if @shadow && !ARGV.join.include?("--no-shadow") shadow_alpha = @color.alpha <= 30 ? @color.alpha : @shadow_alpha shadow_color = @shadow_color ? @shadow_color : Gosu::Color.rgba(@color.red, @color.green, @color.blue, shadow_alpha) _x = @shadow_size _y = @shadow_size @rendered_shadow ||= Gosu.render((self.width+(shadow_size*2)).ceil, (self.height+(@shadow_size*2)).ceil) do @textobject.draw_markup(@text, _x-@shadow_size, _y, @z) @textobject.draw_markup(@text, _x-@shadow_size, _y-@shadow_size, @z) @textobject.draw_markup(@text, _x, _y-@shadow_size, @z, @factor_x) @textobject.draw_markup(@text, _x+@shadow_size, _y-@shadow_size, @z) @textobject.draw_markup(@text, _x, _y+@shadow_size, @z) @textobject.draw_markup(@text, _x-@shadow_size, _y+@shadow_size, @z) @textobject.draw_markup(@text, _x+@shadow_size, _y, @z) @textobject.draw_markup(@text, _x+@shadow_size, _y+@shadow_size, @z) end @rendered_shadow.draw(@x-@shadow_size, @y-@shadow_size, @z, @factor_x, @factor_y, shadow_color) end @textobject.draw_markup(@text, @x, @y, @z, @factor_x, @factor_y, @color) end |
#height ⇒ Object
105 106 107 |
# File 'lib/cyberarm_engine/text.rb', line 105 def height @text.lines.count > 0 ? (@text.lines.count) * textobject.height : @textobject.height end |
#update ⇒ Object
144 |
# File 'lib/cyberarm_engine/text.rb', line 144 def update; end |
#width ⇒ Object
101 102 103 |
# File 'lib/cyberarm_engine/text.rb', line 101 def width textobject.text_width(@text) end |