#==============================================================================
# ** Module
#-----------------------------------------------------------------------------
# Superclass of the Class class
#==============================================================================
class Module
#-------------------------------------------------------------------------
# * Name: Class Attribute
# Info: Calls class_reader/writer for a symbol
# Author: Yeyinde
# Call Info: symbol, writable
# symbol: A Symbol
# writable: Boolean telling is symbol is writable
#-------------------------------------------------------------------------
private
def class_attr(symbol, writable = false)
raise(TypeError, "#{symbol} must be a Symbol.") unless symbol.is_a?(Symbol)
class_reader(symbol)
class_writer(symbol) if writable
return nil
end
#-------------------------------------------------------------------------
# * Name: Class Accessor
# Info: Creates reader and writer methods for one or more class variables
# Author: Yeyinde
# Call Info: One or more Symbols
#-------------------------------------------------------------------------
private
def class_accessor(*symbols)
class_writer(*symbols)
class_reader(*symbols)
end
#-------------------------------------------------------------------------
# * Name: Class Writer
# Info: Creates writer method for one or more class variables
# Author: Yeyinde
# Call Info: One or more Symbols
#-------------------------------------------------------------------------
private
def class_writer(*symbols)
symbols.each do |symbol|
raise(TypeError, "#{symbol} must be a Symbol.") unless symbol.is_a?(Symbol)
method = symbol.id2name
eval("def self.#{method}=(var); @@#{method} = var; end")
end
return nil
end
#-------------------------------------------------------------------------
# * Name: Class Reader
# Info: Creates reader method for one or more class variables
# Author: Yeyinde
# Call Info: One or more Symbols
#-------------------------------------------------------------------------
private
def class_reader(*symbols)
symbols.each do |symbol|
raise(TypeError, "#{symbol} must be a Symbol.") unless symbol.is_a?(Symbol)
method = symbol.id2name
eval("def self.#{method}; return @@#{method}; end")
end
return nil
end
end
#==============================================================================
# ** Font
#-----------------------------------------------------------------------------
# The Font class
#==============================================================================
class Font
#--------------------------------------------------------------------------
# * Class Variable Declarations
#--------------------------------------------------------------------------
@@default_underline = false
@@default_underline_full = false
@@default_strikethrough = false
@@default_strikethrough_full = false
@@default_shadow = false
@@default_shadow_color = Color.new(0, 0, 0, 100)
@@default_outline = true
@@default_outline_color = Color.new(0, 0, 0)
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :underline, :underline_full
attr_accessor :strikethrough, :strikethrough_full
attr_accessor :shadow_color, :outline_color
attr_reader :shadow, :outline
#--------------------------------------------------------------------------
# * Class Variables
#--------------------------------------------------------------------------
class_accessor :default_underline, :default_underline_full
class_accessor :default_strikethrough, :default_strickthrough_full
class_accessor :default_shadow, :default_shadow_color
class_accessor :default_outline, :default_outline_color
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
if @yeyinde_font_alias.nil?
alias_method :yeyinde_font_addons_initialize, :initialize
@yeyinde_font_alias = true
end
#-------------------------------------------------------------------------
# * Name: Object Initialization
# Info: Sets New Properties of Font
# Author: Yeyinde
# Call Info: Zero - Two Arguments
# String name - name of the font
# Integer size - size of the font
#-------------------------------------------------------------------------
def initialize(*args)
yeyinde_font_addons_initialize(*args)
# Set Properties
@underline = @@default_underline
@underline_full = @@default_underline_full
@strikethrough = @@default_strikethrough
@strikethrough_full = @@default_strikethrough_full
@shadow = @@default_shadow
@shadow_color = @@default_shadow_color
@outline = @@default_outline
@outline_color = @@default_outline_color
end
#-------------------------------------------------------------------------
# * Name: Set Shadow
# Info: Sets Shadow Flag
# Author: Yeyinde
# Call Info: One Argument Boolean bool flag
#-------------------------------------------------------------------------
def shadow=(bool)
@outline = false unless bool == false
@shadow = bool
end
#-------------------------------------------------------------------------
# * Name: Set Outline
# Info: Sets Outline Flag
# Author: Yeyinde
# Call Info: One Argument Boolean bool flag
#-------------------------------------------------------------------------
def outline=(bool)
@shadow = false unless bool == false
@outline = bool
end
#-------------------------------------------------------------------------
# Name: == (Comparision Equals)
# Info: Compares two Fonts
# Author: Trickster
# Call Info: One Argument Font other, Font to Check
# Returns: True if all attributes are equal
#-------------------------------------------------------------------------
def ==(other)
attr = %w( name size color bold italic underline underline_full strikethrough
strikethrough_full shadow_color outline_color shadow outline )
attr.each {|var| return false if eval("self.#{var} != other.#{var}")}
return true
end
end
class Bitmap
#--------------------------------------------------------------------------
# * Object Aliasing
#--------------------------------------------------------------------------
if @yeyinde_us_alias.nil?
alias yeyinde_us_draw_text draw_text
@yeyinde_us_alias = true
end
#-------------------------------------------------------------------------
# * Name: Draw Text (Underline and Strike Through)
# Info: Draws Text (Underline and Strike Through)
# Author: Yeyinde
# Call Info: Two,Three,Five or Siz Arguments
# Two Arguments: rect, str
# Rect rect for the text to be drawn
# String str text to be drawn
# Three Arguments: rect, str, align
# Rect rect for the text to be drawn
# String str text to be drawn
# Integer align 0: left 1: center 2:right
# Five Arguments: x,y,width,height,str
# Integer X and Y, Defines Position
# Width and Height, Defines Width and Hieght of the text drawn
# String str text to be drawn
# Six Arguments: x,y,width,height,str,align
# Integer X and Y, Defines Position
# Width and Height, Defines Width and Hieght of the text drawn
# String str text to be drawn
# Integer align 0: left 1: center 2:right
#-------------------------------------------------------------------------
def draw_text(*args)
yeyinde_us_draw_text(*args)
if self.font.underline
u_color = self.font.color.dup
if args[0].is_a?(Rect)
u_x = args[0].x
u_y = args[0].y + args[0].height / 2 + self.font.size / 3
if self.font.underline_full
u_width = args[0].width
else
u_width = self.text_size(args[1]).width
case args[2]
when 1
u_x += args[0].width / 2 - u_width / 2
when 2
u_x += args[0].width - u_width
end
end
else
u_x = args[0]
u_y = args[1] + args[3] / 2 + self.font.size / 3
if self.font.underline_full
u_width = args[2]
else
u_width = self.text_size(args[4]).width
case args[5]
when 1
u_x += args[2] / 2 - u_width / 2
when 2
u_x += args[2] - u_width
end
end
end
self.fill_rect(u_x, u_y, u_width, 1, u_color)
end
if self.font.strikethrough
s_color = self.font.color.dup
if args[0].is_a?(Rect)
s_x = args[0].x
s_y = args[0].y + args[0].height / 2
if self.font.strikethrough_full
s_width = args[0].width
else
s_width = self.text_size(args[1]).width
case args[2]
when 1
s_x += args[0].width / 2 - s_width / 2
when 2
s_x += args[0].width - s_width
end
end
else
s_x = args[0]
s_y = args[1] + args[3] / 2
if self.font.strikethrough_full
s_width = args[0].width
else
s_width = self.text_size(args[4]).width
case args[5]
when 1
s_x += args[2] / 2 - s_width / 2
when 2
s_x += args[2] - s_width
end
end
end
self.fill_rect(s_x, s_y, s_width, 1, s_color)
end
end
#--------------------------------------------------------------------------
# * Object Aliasing
#--------------------------------------------------------------------------
if @yeyinde_so_alias.nil?
alias yeyinde_so_draw_text draw_text
@yeyinde_so_alias = true
end
#-------------------------------------------------------------------------
# * Name: Draw Text (Shadow and Outline)
# Info: Draws Text (Shadow and Outline)
# Author: Yeyinde
# Call Info: Two,Three,Five or Siz Arguments
# Two Arguments: rect, str
# Rect rect for the text to be drawn
# String str text to be drawn
# Three Arguments: rect, str, align
# Rect rect for the text to be drawn
# String str text to be drawn
# Integer align 0: left 1: center 2:right
# Five Arguments: x,y,width,height,str
# Integer X and Y, Defines Position
# Width and Height, Defines Width and Hieght of the text drawn
# String str text to be drawn
# Six Arguments: x,y,width,height,str,align
# Integer X and Y, Defines Position
# Width and Height, Defines Width and Hieght of the text drawn
# String str text to be drawn
# Integer align 0: left 1: center 2:right
#-------------------------------------------------------------------------
def draw_text(*args)
if self.font.shadow
orig_color = self.font.color.dup
self.font.color = self.font.shadow_color
if args[0].is_a?(Rect)
s_x = args[0].x + 2
s_y = args[0].y + 2
s_w = args[0].width
s_h = args[0].height
s_t = args[1]
s_a = args[2]
else
s_x = args[0] + 2
s_y = args[1] + 2
s_w = args[2]
s_h = args[3]
s_t = args[4]
s_a = args[5]
end
s_a = 0 if s_a.nil?
self.yeyinde_so_draw_text(s_x, s_y, s_w, s_h, s_t, s_a)
self.font.color = orig_color
end
if self.font.outline
orig_color = self.font.color.dup
self.font.color = self.font.outline_color
if args[0].is_a?(Rect)
o_x = args[0].x
o_y = args[0].y
o_w = args[0].width
o_h = args[0].height
o_t = args[1]
o_a = args[2]
else
o_x = args[0]
o_y = args[1]
o_w = args[2]
o_h = args[3]
o_t = args[4]
o_a = args[5]
end
o_a = 0 if o_a.nil?
self.yeyinde_so_draw_text(o_x + 1, o_y, o_w, o_h, o_t, o_a)
self.yeyinde_so_draw_text(o_x - 1, o_y, o_w, o_h, o_t, o_a)
self.yeyinde_so_draw_text(o_x, o_y + 1, o_w, o_h, o_t, o_a)
self.yeyinde_so_draw_text(o_x, o_y - 1, o_w, o_h, o_t, o_a)
self.yeyinde_so_draw_text(o_x + 1, o_y + 1, o_w, o_h, o_t, o_a)
self.yeyinde_so_draw_text(o_x + 1, o_y - 1, o_w, o_h, o_t, o_a)
self.yeyinde_so_draw_text(o_x - 1, o_y - 1, o_w, o_h, o_t, o_a)
self.yeyinde_so_draw_text(o_x - 1, o_y + 1, o_w, o_h, o_t, o_a)
self.font.color = orig_color
end
self.yeyinde_so_draw_text(*args)
end
end