mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-15 20:52:35 +00:00
Renamed Text's shadow to border and added proper text shadow effect
This commit is contained in:
@@ -3,7 +3,9 @@ module CyberarmEngine
|
|||||||
CACHE = {}
|
CACHE = {}
|
||||||
|
|
||||||
attr_accessor :x, :y, :z, :size, :options
|
attr_accessor :x, :y, :z, :size, :options
|
||||||
attr_reader :text, :textobject, :factor_x, :factor_y, :color, :shadow, :shadow_size, :shadow_alpha, :shadow_color
|
attr_reader :text, :textobject, :factor_x, :factor_y, :color,
|
||||||
|
:border, :border_size, :border_alpha, :border_color,
|
||||||
|
:shadow, :shadow_size, :shadow_alpha, :shadow_color
|
||||||
|
|
||||||
def initialize(text, options = {})
|
def initialize(text, options = {})
|
||||||
@text = text.to_s || ""
|
@text = text.to_s || ""
|
||||||
@@ -15,15 +17,25 @@ module CyberarmEngine
|
|||||||
@z = options[:z] || 1025
|
@z = options[:z] || 1025
|
||||||
@factor_x = options[:factor_x] || 1
|
@factor_x = options[:factor_x] || 1
|
||||||
@factor_y = options[:factor_y] || 1
|
@factor_y = options[:factor_y] || 1
|
||||||
@color = options[:color] || Gosu::Color::WHITE
|
if options[:color]
|
||||||
|
@color = options[:color].is_a?(Gosu::Color) ? options[:color] : Gosu::Color.new(options[:color])
|
||||||
|
else
|
||||||
|
@color = Gosu::Color::WHITE
|
||||||
|
end
|
||||||
@mode = options[:mode] || :default
|
@mode = options[:mode] || :default
|
||||||
@alignment = options[:alignment] || nil
|
@alignment = options[:alignment] || nil
|
||||||
@shadow = true if options[:shadow] == true
|
|
||||||
@shadow = false if options[:shadow] == false
|
@border = options[:border]
|
||||||
@shadow = true if options[:shadow].nil?
|
@border = true if options[:border].nil?
|
||||||
@shadow_size = options[:shadow_size] || 1
|
@border_size = options[:border_size] || 1
|
||||||
|
@border_alpha = options[:border_alpha] || 30
|
||||||
|
@border_color = options[:border_color]
|
||||||
|
|
||||||
|
@shadow = options[:shadow]
|
||||||
|
@shadow_size = options[:shadow_size] || 2
|
||||||
@shadow_alpha = options[:shadow_alpha] || 30
|
@shadow_alpha = options[:shadow_alpha] || 30
|
||||||
@shadow_color = options[:shadow_color]
|
@shadow_color = options[:shadow_color]
|
||||||
|
|
||||||
@textobject = check_cache(@size, @font)
|
@textobject = check_cache(@size, @font)
|
||||||
|
|
||||||
if @alignment
|
if @alignment
|
||||||
@@ -36,8 +48,6 @@ module CyberarmEngine
|
|||||||
@x = $window.width - BUTTON_PADDING - @textobject.text_width(@text)
|
@x = $window.width - BUTTON_PADDING - @textobject.text_width(@text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_cache(size, font_name)
|
def check_cache(size, font_name)
|
||||||
@@ -74,43 +84,47 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def text=(string)
|
def text=(string)
|
||||||
@rendered_shadow = nil
|
@rendered_border = nil
|
||||||
@text = string
|
@text = string
|
||||||
end
|
end
|
||||||
|
|
||||||
def factor_x=(n)
|
def factor_x=(n)
|
||||||
@rendered_shadow = nil
|
@rendered_border = nil
|
||||||
@factor_x = n
|
@factor_x = n
|
||||||
end
|
end
|
||||||
|
|
||||||
def factor_y=(n)
|
def factor_y=(n)
|
||||||
@rendered_shadow = nil
|
@rendered_border = nil
|
||||||
@factor_y = n
|
@factor_y = n
|
||||||
end
|
end
|
||||||
|
|
||||||
def color=(color)
|
def color=(color)
|
||||||
@rendered_shadow = nil
|
@rendered_border = nil
|
||||||
@color = color
|
if color
|
||||||
|
@color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
|
||||||
|
else
|
||||||
|
raise "color cannot be nil"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def shadow=(boolean)
|
def border=(boolean)
|
||||||
@rendered_shadow = nil
|
@rendered_border = nil
|
||||||
@shadow = boolean
|
@border = boolean
|
||||||
end
|
end
|
||||||
|
|
||||||
def shadow_size=(n)
|
def border_size=(n)
|
||||||
@rendered_shadow = nil
|
@rendered_border = nil
|
||||||
@shadow_size = n
|
@border_size = n
|
||||||
end
|
end
|
||||||
|
|
||||||
def shadow_alpha=(n)
|
def border_alpha=(n)
|
||||||
@rendered_shadow = nil
|
@rendered_border = nil
|
||||||
@shadow_alpha = n
|
@border_alpha = n
|
||||||
end
|
end
|
||||||
|
|
||||||
def shadow_color=(n)
|
def border_color=(n)
|
||||||
@rendered_shadow = nil
|
@rendered_border = nil
|
||||||
@shadow_color = n
|
@border_color = n
|
||||||
end
|
end
|
||||||
|
|
||||||
def width(text = @text)
|
def width(text = @text)
|
||||||
@@ -126,30 +140,35 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw(method = :draw_markup)
|
def draw(method = :draw_markup)
|
||||||
if @shadow && !ARGV.join.include?("--no-shadow")
|
if @border && !ARGV.join.include?("--no-border")
|
||||||
shadow_alpha = @color.alpha <= 30 ? @color.alpha : @shadow_alpha
|
border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
|
||||||
shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
|
border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
|
||||||
shadow_alpha)
|
border_alpha)
|
||||||
white = Gosu::Color::WHITE
|
white = Gosu::Color::WHITE
|
||||||
|
|
||||||
_x = @shadow_size
|
_x = @border_size
|
||||||
_y = @shadow_size
|
_y = @border_size
|
||||||
|
|
||||||
@rendered_shadow ||= Gosu.render((width + (shadow_size * 2)).ceil, (height + (@shadow_size * 2)).ceil) do
|
@rendered_border ||= Gosu.render((width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
||||||
@textobject.send(method, @text, _x - @shadow_size, _y, @z, @factor_x, @factor_y, white, :add)
|
@textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
||||||
@textobject.send(method, @text, _x - @shadow_size, _y - @shadow_size, @z, @factor_x, @factor_y, white, :add)
|
@textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||||
|
|
||||||
@textobject.send(method, @text, _x, _y - @shadow_size, @z, @factor_x, @factor_y, white, :add)
|
@textobject.send(method, @text, _x, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||||
@textobject.send(method, @text, _x + @shadow_size, _y - @shadow_size, @z, @factor_x, @factor_y, white, :add)
|
@textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||||
|
|
||||||
@textobject.send(method, @text, _x, _y + @shadow_size, @z, @factor_x, @factor_y, white, :add)
|
@textobject.send(method, @text, _x, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||||
@textobject.send(method, @text, _x - @shadow_size, _y + @shadow_size, @z, @factor_x, @factor_y, white, :add)
|
@textobject.send(method, @text, _x - @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||||
|
|
||||||
@textobject.send(method, @text, _x + @shadow_size, _y, @z, @factor_x, @factor_y, white, :add)
|
@textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
||||||
@textobject.send(method, @text, _x + @shadow_size, _y + @shadow_size, @z, @factor_x, @factor_y, white, :add)
|
@textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
@rendered_shadow.draw(@x - @shadow_size, @y - @shadow_size, @z, @factor_x, @factor_y, shadow_color)
|
@rendered_border.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
|
||||||
|
end
|
||||||
|
|
||||||
|
if @shadow
|
||||||
|
shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
|
||||||
|
@textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
@textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
@textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ module CyberarmEngine
|
|||||||
text, font: @options[:font], z: @z, color: @options[:color],
|
text, font: @options[:font], z: @z, color: @options[:color],
|
||||||
size: @options[:text_size], shadow: @options[:text_shadow],
|
size: @options[:text_size], shadow: @options[:text_shadow],
|
||||||
shadow_size: @options[:text_shadow_size],
|
shadow_size: @options[:text_shadow_size],
|
||||||
shadow_color: @options[:text_shadow_color]
|
shadow_color: @options[:text_shadow_color],
|
||||||
|
border: @options[:text_border],
|
||||||
|
border_size: @options[:text_border_size],
|
||||||
|
border_color: @options[:text_border_color]
|
||||||
)
|
)
|
||||||
|
|
||||||
@raw_text = text
|
@raw_text = text
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ module CyberarmEngine
|
|||||||
text_size: 28,
|
text_size: 28,
|
||||||
text_wrap: :word_wrap, # :word_wrap, :break_word, :none
|
text_wrap: :word_wrap, # :word_wrap, :break_word, :none
|
||||||
text_shadow: false,
|
text_shadow: false,
|
||||||
|
text_border: false,
|
||||||
text_align: :left,
|
text_align: :left,
|
||||||
font: "Arial",
|
font: "Arial",
|
||||||
margin: 0,
|
margin: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user