|
|
#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: This is the main class that handle various screen objects, along with fonts, colors, and other basic info.
class Main
attr_accessor :screen , :font , :bgcolor , :fgcolor , :size , :fname , :background , :x , :y
def initialize
@screen = screen
@background = background
@font = font
@bgcolor = bgcolor
@fgcolor = fgcolor
@size = size
@fname = fname
@x = x
@y = y
end
#setup screen
def screen_set width , height , cursor = true
@x = width
@y = height
@screen = Rubygame::Screen.set_mode([width,height],0, [Rubygame::HWSURFACE, Rubygame::DOUBLEBUF])
@screen.show_cursor = cursor
@background = Rubygame::Surface.new(@screen.size)
end
def widtheight x , y
@x = x
@y = y
@screen = Rubygame::Screen.set_mode([x,y],0, [Rubygame::HWSURFACE, Rubygame::DOUBLEBUF])
@background = Rubygame::Surface.new(@screen.size)
end
def fullscreen
@screen = Rubygame::Screen.set_mode([@x,@y],0, [Rubygame::HWSURFACE, Rubygame::DOUBLEBUF, Rubygame::FULLSCREEN])
end
def font_set location , size
@size = size
@fname = location
#Load a TTF file and set the size of the TFF file provided
@font = TTF.new("#{location}",@size)
end
def screen_clear
@background.blit(@screen, [0,0])
end
def background_cleanup
@background.draw_filled_box([0,0], [@x,@y] , [0,0,0] )
end
end
require"rubygems"
require"rubygame"
string = []
string += Dir.glob('rbgooey/lib/*.rb')
string.each do |data|
require(data)
end
include Rubygame
context "A new Main object" do
setup do
@main = Main.new
end
specify "should have all of their instance variables empty" do
@main.screen.should == nil
@main.background.should == nil
@main.font.should == nil
@main.bgcolor.should == nil
@main.fgcolor.should == nil
@main.size.should == nil
@main.y.should == nil
end
specify "should have variable @screen.size return 800 , 600 when 'set_new(800,600)' is called" do
@main.set_new(800,600)
@main.screen.size.should == [800,600]
end
end
|