Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#Copyright (C) 2007 by Han Dao # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #You can contract the author at wikipediankiba@gmail.com #PROJECT: Rbgooey #DESCRIPTION: A GUI library for the rubygame library. #FUNCTION OF THIS PART: This class is responsible for parsing global setting. class ConfigParser attr_accessor :data , :name , :gui def initialize gui @gui = gui @main = gui.main @data = data @name = name end #Set up global setting for Dynpet def read data @data = data @data['conf'].each do |data| font(data['font']) screen(data['screen']) end end def font data data.each do |font| @main.font_set(font['content'],font['size'].to_i) end end def screen data data.each do |screen| bg = screen['bgcolor'].split(' ') @main.bgcolor = [bg[0].to_i,bg[1].to_i,bg[2].to_i] end end end #parent class of ConfigParser #Copyright (C) 2007 by Han Dao # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #You can contract the author at wikipediankiba@gmail.com #PROJECT: Rbgooey #DESCRIPTION: A GUI library for the rubygame library. #FUNCTION OF THIS PART: metaclass for file interface driven system. class Gui attr_accessor :text , :input , :main , :list , :target , :rect , :option , :widget , :data def initialize main @main = main @config = ConfigParser.new(self) @aim = Target.new() @text = text @text = TextMode.new(@main,@aim) @widget = widget @widget = Widget.new() @widget.setup(@main,@aim) @input = input @input = nil @option = option @textparser = TextParser.new(self) @inputparser = InputParser.new(self) @widgetparser = WidgetParser.new(self) @list = list @target = target @data = data @rect = rect puts @main.fgcolor puts @main.bgcolor end #load metadata def load name @data = XmlSimple.xml_in(name, {'KeyAttr' => 'name'}) @config.read(@data) end #read a file from the metadata def execute name , target @target = target @inputparser.data = @widgetparser.data = @textparser.data = XmlSimple.xml_in(@data['file'][name]['source'][0],{ 'KeyAttr' => 'name' }) end def mouse @rect = @widget.rect + @text.rect @option = @aim.option mqueue = MQueue.new mqueue.mouse.name("data/mouse/mouse.png") mqueue.queue(self,@target,@list) end def read name , list = nil @text.clear() @widget.clean() @list = list @textparser.read(name) @widgetparser.read(name) @text.render_text() @inputparser.read(name) return @input end end #data.xml <data> <file name ="begin"> <source>data/dyngui/menu.xml</source> </file> <file name ="optionmenu"> <source>data/sharegui/optionmenu.xml</source> </file> <file name ="file"> <source>data/dyngui/filemenu.xml</source> </file> <file name ="creation"> <source>data/dyngui/creation.xml</source> </file> <conf> <font size = "16">data/fonts/freesansbold.ttf</font> <screen bgcolor = "20 30 20" fgcolor = "200 200 200">800 600</screen> </conf> </data> #class where error occurs #Copyright (C) 2006-2007 by Han Dao # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #You can contract the author at wikipediankiba@gmail.com #PROJECT: Rbgooey #DESCRIPTION: A GUI library for the rubygame library. #FUNCTION OF THIS PART: Class TextRender handle the textrendering task. It is the result of TextMode's various arrays. class TextRender def initialize main , textmode @main = main @text = textmode end #This method render the text array element one by one. def render_text option = false y_value = 0 default = nil skip = @main.font.line_skip() @text.text.zip(@text.size,@text.x,@text.y,@text.report).each do |string , size , x , y , report| font = TTF.new("#{@main.fname}",size) if @text.omit == false render = font.render("#{[string]}",true,@text.fgcolor,@text.bgcolor) elsif @text.omit == true render = font.render("#{[string]}",true,@text.fgcolor) end render.blit(@main.screen,[x,y+=y_value]) if report == 1 @text.rect << Rect.new(x,y,*render.size) end y_value+= skip end end end #error message #/usr/lib/ruby/gems/1.8/gems/rbGooey-0.0.1/rbgooey/lib/textrender.rb:35: [BUG] #Segmentation fault #ruby 1.8.6 (2007-03-13) [i486-linux]
This paste will be private.
From the Design Piracy series on my blog: