|
|
# rbGooey. -- Game GUI library to be used with rubygame
# Copyright (C) 2006 Han 'kiba' Dao
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#Class TextRender handle the TextRender tasks. It also formed the foundation for entire text library for the RbGooey. This include the TextInput class.
class TextMode
#Set up the class by using the Main class
attr_accessor :main , :bgcolor , :fgcolor , :x , :y , :text , :size , :textrender
def initialize main
@main = main
@textrender = textrender
#@omit variable is used in render_text, which serve to determine wheather to omit the bgcolor or not from the font render agurement.
@bgcolor = bgcolor
@fgcolor = fgcolor
@omit = false
#@x contain the x position of text
@x = x
#@y contain the y position of text
@y = y
#@text contain strings of text
@text = text
#@size contain the size of the text
@size = size
setup
end
def omit omit
@omit = omit
end
def setup
@textrender = TextRender.new(@main, self.class)
@bgcolor = @main.bgcolor
@fgcolor = @main.fgcolor
@x = []
@y = []
@text = []
@size = []
end
def array_push
#This method exist for the purpose of DRY or don't repeat yourself
@x.push 0
@y.push 0
@size.push @main.size
end
def add text
#Use this method to add new lines to the text array
@text << text
#This default to zero to prevent font size changing.
#To activiate this setting for a particular index in the text array, please use method set_size after the particular index you wanted.
array_push
end
def set_size size
#Set the font size for a part of the @text array. It only apply for a particular index you apply to.
@size[-1] = size
end
def set_pos x , y = 0
#Set position
@x[-1] = x
@y[-1] = y
end
def length length
#Set the length of how much text array element will follow the text's x position. For y, it will skip.
length.times do
@y << @y[-1]
@x << @x[-1]
end
end
def set_mutiple time
#It is used in dir_nosub and dir. It make sure that all array objects are added for each
time.times do
array_push
end
end
def clear
#Use this to clear arrays which are @text, @size, and @x and @y
@textrender.screen_clear
@text = []
@size = []
@x = []
@y = []
end
def dir location , enable = false
#Use this to add directory items. Usage: Dir(location) => a string that should contain the location of the directory
#change the enable variable to the value true. This if you want only the filename or the "basename".
if enable == true
@text += Dir.glob(location).map {|f| File.basename(f)}
else
@text += Dir.glob(location)
end
set_mutiple(Dir[location].size)
end
end
|