class CyberarmEngine::Text
Constants
- CACHE
Attributes
color[R]
factor_x[R]
factor_y[R]
options[RW]
shadow[R]
shadow_alpha[R]
shadow_color[R]
shadow_size[R]
size[RW]
text[R]
textobject[R]
x[RW]
y[RW]
z[RW]
Public Class Methods
new(text, options = {})
click to toggle source
# File lib/cyberarm_engine/text.rb, line 8 def initialize(text, options = {}) @text = text.to_s || "" @options = options @size = options[:size] || 18 @font = options[:font] || Gosu.default_font_name @x = options[:x] || 0 @y = options[:y] || 0 @z = options[:z] || 1025 @factor_x = options[:factor_x] || 1 @factor_y = options[:factor_y] || 1 @color = options[:color] || Gosu::Color::WHITE @mode = options[:mode] || :default @alignment = options[:alignment] || nil @shadow = true if options[:shadow] == true @shadow = false if options[:shadow] == false @shadow = true if options[:shadow].nil? @shadow_size = options[:shadow_size] || 1 @shadow_alpha = options[:shadow_alpha] || 30 @shadow_alpha = options[:shadow_alpha] || 30 @shadow_color = options[: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 self end
Public Instance Methods
alpha()
click to toggle source
# File lib/cyberarm_engine/text.rb, line 163 def alpha @color.alpha end
alpha=(n)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 159 def alpha=(n) @color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, n) end
check_cache(size, font_name)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 44 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 font end
color=(color)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 92 def color=(color) @rendered_shadow = nil @color = color end
draw(method = :draw_markup)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 129 def draw(method = :draw_markup) if @shadow && !ARGV.join.include?("--no-shadow") shadow_alpha = @color.alpha <= 30 ? @color.alpha : @shadow_alpha shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, shadow_alpha) white = Gosu::Color::WHITE _x = @shadow_size _y = @shadow_size @rendered_shadow ||= Gosu.render((width + (shadow_size * 2)).ceil, (height + (@shadow_size * 2)).ceil) do @textobject.send(method, @text, _x - @shadow_size, _y, @z, @factor_x, @factor_y, white, :add) @textobject.send(method, @text, _x - @shadow_size, _y - @shadow_size, @z, @factor_x, @factor_y, white, :add) @textobject.send(method, @text, _x, _y - @shadow_size, @z, @factor_x, @factor_y, white, :add) @textobject.send(method, @text, _x + @shadow_size, _y - @shadow_size, @z, @factor_x, @factor_y, white, :add) @textobject.send(method, @text, _x, _y + @shadow_size, @z, @factor_x, @factor_y, white, :add) @textobject.send(method, @text, _x - @shadow_size, _y + @shadow_size, @z, @factor_x, @factor_y, white, :add) @textobject.send(method, @text, _x + @shadow_size, _y, @z, @factor_x, @factor_y, white, :add) @textobject.send(method, @text, _x + @shadow_size, _y + @shadow_size, @z, @factor_x, @factor_y, white, :add) end @rendered_shadow.draw(@x - @shadow_size, @y - @shadow_size, @z, @factor_x, @factor_y, shadow_color) end @textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode) end
factor_x=(n)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 82 def factor_x=(n) @rendered_shadow = nil @factor_x = n end
factor_y=(n)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 87 def factor_y=(n) @rendered_shadow = nil @factor_y = n end
height(text = @text)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 125 def height(text = @text) text.lines.count > 0 ? text.lines.count * textobject.height : @textobject.height end
markup_width(text = @text)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 121 def markup_width(text = @text) textobject.markup_width(text) end
shadow=(boolean)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 97 def shadow=(boolean) @rendered_shadow = nil @shadow = boolean end
shadow_alpha=(n)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 107 def shadow_alpha=(n) @rendered_shadow = nil @shadow_alpha = n end
shadow_color=(n)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 112 def shadow_color=(n) @rendered_shadow = nil @shadow_color = n end
shadow_size=(n)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 102 def shadow_size=(n) @rendered_shadow = nil @shadow_size = n end
swap_font(size, font_name = @font)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 68 def swap_font(size, font_name = @font) if @size != size || @font != font_name @size = size @font = font_name @textobject = check_cache(size, font_name) end end
text=(string)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 77 def text=(string) @rendered_shadow = nil @text = string end
update()
click to toggle source
# File lib/cyberarm_engine/text.rb, line 167 def update end
width(text = @text)
click to toggle source
# File lib/cyberarm_engine/text.rb, line 117 def width(text = @text) textobject.text_width(text) end