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
- def initialize main
- @main = main
- @textrender = textrender
- @textinput = textinput
- #@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
- setup
- end
- def setup
- @bgcolor = @main.bgcolor
- @fgcolor = @main.fgcolor
- @x = []
- @y = []
- @text = []
- @size = []
- @omit = false
- @textrender = TextRender.new(@main, self)
- @textinput = TextInput.new(self)
- 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
Add Comment
Please, Sign In to add comment