Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fresh start on goo. Aims to be much leaner.
Signed-off-by: Luke Perkin <lukeperkin@gmail.com>
- Loading branch information
Luke Perkin
committed
Jan 20, 2011
1 parent
d75a327
commit d0cefad
Showing
54 changed files
with
1,743 additions
and
692 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- Filename: roundrect.lua | ||
-- Author: Luke Perkin | ||
-- Date: 2010-02-25 | ||
-- Desc: Draws a round rectangle | ||
-- Thanks to Robin for the draw code. | ||
|
||
local function roundrect(mode, x, y, width, height, xround, yround) | ||
local points = {} | ||
local precision = (xround + yround) * .1 | ||
local tI, hP = table.insert, .5*math.pi | ||
if xround > width*.5 then xround = width*.5 end | ||
if yround > height*.5 then yround = height*.5 end | ||
local X1, Y1, X2, Y2 = x + xround, y + yround, x + width - xround, y + height - yround | ||
local sin, cos = math.sin, math.cos | ||
for i = 0, precision do | ||
local a = (i/precision-1)*hP | ||
tI(points, X2 + xround*cos(a)) | ||
tI(points, Y1 + yround*sin(a)) | ||
end | ||
for i = 0, precision do | ||
local a = (i/precision)*hP | ||
tI(points, X2 + xround*cos(a)) | ||
tI(points, Y2 + yround*sin(a)) | ||
end | ||
for i = 0, precision do | ||
local a = (i/precision+1)*hP | ||
tI(points, X1 + xround*cos(a)) | ||
tI(points, Y2 + yround*sin(a)) | ||
end | ||
for i = 0, precision do | ||
local a = (i/precision+2)*hP | ||
tI(points, X1 + xround*cos(a)) | ||
tI(points, Y1 + yround*sin(a)) | ||
end | ||
love.graphics.polygon(mode, unpack(points)) | ||
end | ||
|
||
return roundrect |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
-- BUTTON | ||
goo.button = class('goo button', goo.object) | ||
function goo.button:initialize( parent ) | ||
super.initialize(self,parent) | ||
self.text = "button" | ||
self.borderStyle = 'line' | ||
self.backgroundColor = {0,0,0,255} | ||
self.borderColor = {255,255,255,255} | ||
self.textColor = {255,255,255,255} | ||
self.spacing = 5 | ||
self.border = true | ||
self.background = true | ||
end | ||
function goo.button:draw() | ||
if self.background then | ||
self:setColor( self.backgroundColor ) | ||
love.graphics.rectangle( 'fill', 0, 0, self.w , self.h ) | ||
end | ||
if self.border then | ||
love.graphics.setLine( 1, 'rough' ) | ||
self:setColor( self.borderColor ) | ||
love.graphics.rectangle( 'line', 0, 0, self.w+2, self.h ) | ||
end | ||
|
||
self:setColor( self.textColor ) | ||
love.graphics.setFont( self.style.textFont ) | ||
local fontW,fontH = self.style.textFont:getWidth(self.text or ''), self.style.textFont:getHeight() | ||
local ypos = ((self.h - fontH)/2)+(fontH*0.8) | ||
local xpos = ((self.w - fontW)/2) | ||
love.graphics.print( self.text, xpos, ypos ) | ||
end | ||
function goo.button:enterHover() | ||
self.backgroundColor = self.style.backgroundColorHover | ||
self.borderColor = self.style.borderColorHover | ||
self.textColor = self.style.textColorHover | ||
end | ||
function goo.button:exitHover() | ||
self.backgroundColor = self.style.backgroundColor | ||
self.borderColor = self.style.borderColor | ||
self.textColor = self.style.textColor | ||
end | ||
function goo.button:mousepressed(x,y,button) | ||
if self.onClick then self:onClick(button) end | ||
self:updateBounds( 'children', self.updateBounds ) | ||
end | ||
function goo.button:setText( text ) | ||
self.text = text or '' | ||
end | ||
function goo.button:sizeToText( padding ) | ||
local padding = padding or 5 | ||
local _font = self.style.textFont or love.graphics.getFont() | ||
self.w = _font:getWidth(self.text or '') + (padding*2) | ||
self.h = _font:getHeight() + (padding*2) | ||
self:updateBounds() | ||
end | ||
goo.button:getterSetter('border') | ||
goo.button:getterSetter('background') | ||
|
||
return goo.button |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
-- Filename: goo.lua | ||
-- Author: Luke Perkin | ||
-- Date: 2010-02-26 | ||
-- Desc: | ||
|
||
local style = {} | ||
local fonts = {} | ||
fonts.default24 = love.graphics.newFont(24) | ||
fonts.oldsans12 = love.graphics.newFont('oldsansblack.ttf') | ||
fonts.oldsans24 = love.graphics.newFont('oldsansblack.ttf',24) | ||
fonts.oldsans32 = love.graphics.newFont('oldsansblack.ttf',32) | ||
|
||
style['goo big button'] = { | ||
buttonColor = {255,255,255,255}, | ||
buttonColorHover = {200,150,255,255}, | ||
textColor = {0,0,0,255}, | ||
textColorHover = {0,0,0,255}, | ||
font = {'oldsansblack.ttf', 12} | ||
} | ||
|
||
style['goo text input'] = { | ||
borderColor = {0,0,0}, | ||
backgroundColor = {255,255,255}, | ||
textColor = {0,0,0}, | ||
cursorColor = {0,0,0}, | ||
cursorWidth = 2, | ||
borderWidth = 2, | ||
textFont = fonts.oldsans12, | ||
blinkRate = 0.5, | ||
leading = 35 | ||
} | ||
|
||
style['goo progressbar'] = { | ||
backgroundColor = {255,255,255}, | ||
fillMode = 'fill' | ||
} | ||
|
||
style['goo image'] = { | ||
imageTint = {255,255,255} | ||
} | ||
|
||
style['goo debug'] = { | ||
backgroundColor = {0,0,0,170}, | ||
textColor = {255,255,255,255}, | ||
textFont = fonts.oldsans12 | ||
} | ||
|
||
style['goo close button'] = { | ||
color = {255,255,255}, | ||
colorHover = {255,0,0} | ||
} | ||
|
||
style['goo button'] = { | ||
backgroundColor = {255,255,255}, | ||
backgroundColorHover = {203,131,21}, | ||
borderColor = {0,0,0,255}, | ||
borderColorHover = {0,0,0}, | ||
textColor = {0,0,0}, | ||
textColorHover = {0,0,0}, | ||
textFont = fonts.oldsans12 | ||
} | ||
|
||
style['goo panel'] = { | ||
backgroundColor = {0,0,0}, | ||
borderColor = {255,255,255}, | ||
titleColor = {255,255,255}, | ||
titleFont = fonts.oldsans12, | ||
seperatorColor = {100,100,100} | ||
} | ||
|
||
return style, fonts | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
-- Filename: goo.lua | ||
-- Author: Luke Perkin | ||
-- Date: 2010-02-26 | ||
-- Returns Style, Fonts. | ||
|
||
-- How to use: | ||
-- Each table reperesent a style sheet for a gui object. | ||
-- Think of it like CSS. Colors are reperesented by RGBA tables. | ||
-- If you specify an alpha value that property will not inherit its | ||
-- parent's opacity. | ||
-- use goo.skin to point to the current skin directory. | ||
|
||
local style = {} | ||
local fonts = {} | ||
fonts.default24 = love.graphics.newFont(24) | ||
fonts.oldsans12 = love.graphics.newFont(GOO_SKINPATH .. 'oldsansblack.ttf') | ||
fonts.oldsans24 = love.graphics.newFont(GOO_SKINPATH .. 'oldsansblack.ttf', 24) | ||
fonts.oldsans32 = love.graphics.newFont(GOO_SKINPATH .. 'oldsansblack.ttf', 32) | ||
|
||
style['goo panel'] = { | ||
backgroundColor = {255,255,255}, | ||
borderColor = {255,255,255}, | ||
titleColor = {130,130,130}, | ||
titleFont = fonts.oldsans12, | ||
seperatorColor = {100,100,100} | ||
} | ||
|
||
style['goo close button'] = { | ||
color = {255,255,255}, | ||
colorHover = {255,0,0} | ||
} | ||
|
||
style['goo button'] = { | ||
backgroundColor = {100,100,100}, | ||
backgroundColorHover = {131,203,21}, | ||
borderColor = {0,0,0,255}, | ||
borderColorHover = {0,0,0}, | ||
textColor = {255,255,255}, | ||
textColorHover = {255,255,255}, | ||
textFont = fonts.oldsans12 | ||
} | ||
|
||
style['goo big button'] = { | ||
buttonColor = {255,255,255,255}, | ||
buttonColorHover = {200,150,255,255}, | ||
textColor = {0,0,0,255}, | ||
textColorHover = {0,0,0,255}, | ||
font = {'oldsansblack.ttf', 12} | ||
} | ||
|
||
style['goo text input'] = { | ||
borderColor = {0,0,0}, | ||
backgroundColor = {255,255,255}, | ||
textColor = {0,0,0}, | ||
cursorColor = {0,0,0}, | ||
cursorWidth = 2, | ||
borderWidth = 2, | ||
textFont = fonts.oldsans12, | ||
blinkRate = 0.5, | ||
leading = 35 | ||
} | ||
|
||
style['goo progressbar'] = { | ||
backgroundColor = {255,255,255}, | ||
fillMode = 'fill' | ||
} | ||
|
||
style['goo image'] = { | ||
imageTint = {255,255,255} | ||
} | ||
|
||
style['goo debug'] = { | ||
backgroundColor = {0,0,0,170}, | ||
textColor = {255,255,255,255}, | ||
textFont = fonts.oldsans12 | ||
} | ||
|
||
return style, fonts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
local base = {} | ||
|
||
function base:new( parent ) | ||
local instance = {} | ||
setmetatable( instance, self.meta ) | ||
instance:setparent( parent ) | ||
instance.visible = true | ||
instance.children = {} | ||
instance.AABB = {0,0,0,0} | ||
instance.x = 0 | ||
instance.y = 0 | ||
instance.w = 0 | ||
instance.h = 0 | ||
instance.hoverstate = 'off' | ||
goo.newinstance( instance, parent ) | ||
instance:init( parent ) | ||
return instance | ||
end | ||
|
||
function base:setparent( parent ) | ||
if not parent then return end | ||
if self.parent then self.parent:removechild( self ) end | ||
self.parent = parent | ||
self.parent:addchild( self ) | ||
end | ||
|
||
function base:addchild( child ) | ||
table.insert( self.children, child ) | ||
end | ||
|
||
function base:removechild( child ) | ||
for k, existing_child in ipairs( self.children ) do | ||
if existing_child == child then table.remove( self.children, k ) end | ||
end | ||
end | ||
|
||
function base:init() | ||
end | ||
|
||
function base:update(dt) | ||
self:updatebounds() | ||
local mx, my = love.mouse.getPosition() | ||
local m_left = love.mouse.isDown('l') | ||
if self:inbounds( mx, my ) then | ||
if self.hoverstate ~= 'click' then | ||
self.hoverstate = 'over' | ||
end | ||
else | ||
self.hoverstate = 'off' | ||
end | ||
end | ||
|
||
function base:draw() end | ||
function base:drawall() | ||
self:draw() | ||
for k, child in ipairs( self.children ) do | ||
child:drawall() | ||
end | ||
end | ||
|
||
function base:mousepressed() self.hoverstate = 'click' end | ||
function base:mousereleased() self.hoverstate = 'off' end | ||
function base:keypressed() end | ||
function base:keyreleased() end | ||
|
||
function base:inbounds( x, y ) | ||
local ax, ay = self.AABB[1], self.AABB[2] | ||
local bx, by = self.AABB[3], self.AABB[4] | ||
if x > ax and x < bx and y > ay and y < by then | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
function base:setbounds( ax, ay, bx, by ) | ||
self.AABB = {ax,ay,bx,by} | ||
self.x = ax | ||
self.y = ay | ||
self.w = bx-ax | ||
self.h = by-ay | ||
end | ||
|
||
function base:updatebounds() | ||
local ax, ay = self.x, self.y | ||
local bx, by = self.x + self.w, self.y + self.h | ||
self.AABB = {ax,ay,bx,by} | ||
end | ||
|
||
function base:setpos( x, y ) | ||
self.x = x | ||
self.y = y | ||
end | ||
|
||
function base:setsize( w, h ) | ||
self.w = w | ||
self.h = h | ||
end | ||
|
||
function base:setcolor( colorname ) | ||
love.graphics.setColor( unpack( goo.skin[ self.name ][ colorname ] ) ) | ||
end | ||
|
||
function base:getskinvar( varname ) | ||
return goo.skin[ self.name ][ varname ] | ||
end | ||
|
||
return base |
Oops, something went wrong.