Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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 TextMode handle texts setting and data and handle all classes of Text so everything a programmer need to do with one of the text class can access it here.
- class TextMode
- #Set up the class by using the Main class
- attr_accessor :main , :bgcolor , :fgcolor , :x , :y , :text , :size , :textrender , :omit , :textinput , :textsprite , :report
- def initialize main
- @main = main
- @textrender = textrender
- @textinput = textinput
- @textsprite = textsprite
- #@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 = omit
- #@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
- @report = report
- setup
- end
- def setup
- @bgcolor = @main.bgcolor
- @fgcolor = @main.fgcolor
- @x = []
- @y = []
- @text = []
- @size = []
- @report = []
- @omit = false
- @textrender = TextRender.new(@main, self)
- @textinput = TextInput.new(self)
- @textsprite = TextSprite.new(self)
- end
- #This method exist for the purpose of DRY or don't repeat yourself. It is mean to be used internally.
- def array_push
- @x.push(0)
- @y.push(0)
- @size.push(@main.size)
- @report.push(false)
- 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 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
- #Tag the particular text that been added last using the add method of this TextMode class.
- def active
- @report[-1] = 1
- end
- #Method clear is for the purpose of clearing every infomation accumulated during the usage of this class that are the screen, class Textsprite's rect, and instance variable such as @text, @size, @x, and @y. Useful for starting with a clean state.
- def clear
- @textrender.screen_clear()
- @textsprite.setup()
- @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
Add Comment
Please, Sign In to add comment