mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Added dependance on cyberarm_engine, removed duplicate code which is in cyberarm_engine
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
class MultiLineText
|
||||
attr_accessor :options, :x, :y, :width, :height
|
||||
|
||||
def initialize(text, options={})
|
||||
@texts = []
|
||||
text.split("\n").each_with_index do |line, i|
|
||||
_options = options
|
||||
@texts << Text.new(line, _options)
|
||||
end
|
||||
@options = options
|
||||
@x = @texts.first ? @texts.first.x : 0
|
||||
@y = @texts.first ? @texts.first.y : 0
|
||||
@width = 0
|
||||
@height = 0
|
||||
calculate_boundry
|
||||
end
|
||||
|
||||
def draw
|
||||
@texts.each(&:draw)
|
||||
end
|
||||
|
||||
def text
|
||||
string = ""
|
||||
@texts.each {|t| string << t.text}
|
||||
return string
|
||||
end
|
||||
|
||||
def text=(text)
|
||||
text.split("\n").each_with_index do |line, i|
|
||||
if @texts[i]
|
||||
@texts[i].text = line
|
||||
else
|
||||
@texts << Text.new(line, @options)
|
||||
end
|
||||
end
|
||||
|
||||
calculate_stack
|
||||
calculate_boundry
|
||||
end
|
||||
|
||||
def x=(int)
|
||||
@x = int
|
||||
@texts.each {|t| t.x = int}
|
||||
end
|
||||
|
||||
def y=(int)
|
||||
@y = int
|
||||
@texts.each_with_index {|t, i| t.y=int+(i*t.size)}
|
||||
end
|
||||
|
||||
def calculate_stack
|
||||
@texts.each_with_index do |text, index|
|
||||
text.y = (text.size*index)+@options[:y]
|
||||
end
|
||||
end
|
||||
|
||||
def calculate_boundry
|
||||
@width = 0
|
||||
@height= 0
|
||||
@texts.each {|t| @width = t.width if t.width > @width}
|
||||
@texts.each {|t| @height+=t.height}
|
||||
end
|
||||
end
|
||||
@@ -1,96 +0,0 @@
|
||||
class Text
|
||||
include IMICFPS::CommonMethods
|
||||
CACHE = {}
|
||||
|
||||
attr_accessor :text, :x, :y, :z, :size, :factor_x, :factor_y, :color, :shadow, :shadow_size, :options
|
||||
attr_reader :textobject
|
||||
|
||||
def initialize(text, options={})
|
||||
@text = text || ""
|
||||
@options = options
|
||||
@size = options[:size] || 18
|
||||
@font = options[:font] || "Consolas"
|
||||
|
||||
@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
|
||||
@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] ? options[:shadow_size] : 1
|
||||
@shadow_alpha= options[:shadow_alpha] ? options[:shadow_alpha] : 30
|
||||
@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
|
||||
|
||||
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, bold: true)
|
||||
CACHE[@size] = {} unless CACHE[@size].is_a?(Hash)
|
||||
CACHE[@size][@font] = font
|
||||
end
|
||||
|
||||
return font
|
||||
end
|
||||
|
||||
def width
|
||||
textobject.text_width(@text)
|
||||
end
|
||||
|
||||
def height
|
||||
textobject.height
|
||||
end
|
||||
|
||||
def draw
|
||||
if @shadow && !ARGV.join.include?("--no-shadow")
|
||||
# _color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha) if @shadow_alpha <= @color.alpha
|
||||
# _color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, @color.alpha) unless @shadow_alpha <= @color.alpha
|
||||
_color = Gosu::Color::BLACK
|
||||
@textobject.draw_text(@text, @x-@shadow_size, @y, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_text(@text, @x-@shadow_size, @y-@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
|
||||
@textobject.draw_text(@text, @x, @y-@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_text(@text, @x+@shadow_size, @y-@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
|
||||
@textobject.draw_text(@text, @x, @y+@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_text(@text, @x-@shadow_size, @y+@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
|
||||
@textobject.draw_text(@text, @x+@shadow_size, @y, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_text(@text, @x+@shadow_size, @y+@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
end
|
||||
|
||||
@textobject.draw_markup(@text, @x, @y, @z, @factor_x, @factor_y, @color)
|
||||
end
|
||||
|
||||
def update; end
|
||||
end
|
||||
Reference in New Issue
Block a user