working, but skins suck

This commit is contained in:
Fox 2016-01-21 15:01:15 -08:00
parent 1ba7314243
commit 0b1d48f3c5
9 changed files with 94 additions and 28 deletions

3
conf.lua Normal file
View File

@ -0,0 +1,3 @@
function love.conf(t)
t.console = true
end

View File

@ -1,8 +1,9 @@
local pop = require "pop"
function love.load()
--pop.box() -- returns the box element
-- or pop.create("box") (this is what is actually called when you call pop.box())
pop.setSkin("blackonwhite")
local align = pop.box():align("center", "center"):setSize(100, 100):setSkin("blackonwhite")
--print(align.skin)
end
function love.update(dt)
@ -11,6 +12,8 @@ end
function love.draw()
pop.draw()
love.graphics.setColor(255, 255, 255, 255)
--love.graphics.rectangle("fill", 0, 0, 100, 100)
end
function love.textinput(text)

View File

@ -11,9 +11,14 @@ function box:initialize(pop, parent, skin)
end
function box:draw() --TODO these ifs are probably wrong
print("box drawn!")
if self.skin.background then
if type(self.skin.background) == "table" then
lg.setColor(self.skin.background)
print(self.skin.background[4], self.x, self.y, self.w, self.h)
lg.rectangle("fill", self.x, self.y, self.w, self.h)
print("rect")
else
lg.setColor(255, 255, 255, 255)
local w, h = self.skin.background:getDimensions()
@ -22,7 +27,9 @@ function box:draw() --TODO these ifs are probably wrong
h = self.h/h
lg.draw(self.skin.background, self.x, self.y, 0, w, h)
end
end
if self.skin.foreground then
if type(self.skin.foreground) == "table" then
lg.setColor(self.skin.foreground)
lg.rectangle("fill", self.x, self.y, self.w, self.h)
@ -36,4 +43,7 @@ function box:draw() --TODO these ifs are probably wrong
end
end
return self
end
return box

View File

@ -4,6 +4,7 @@ local class = require(path .. "/lib/middleclass")
local element = class("pop.element")
function element:initialize(pop, parent, skin)
self.pop = pop --I hate this -.-
self.parent = parent
self.child = {}
@ -12,7 +13,11 @@ function element:initialize(pop, parent, skin)
self.w = 10
self.h = 10
self.skin = pop.skins[skin] or pop.skins[pop.currentSkin]
if skin then
self.skin = pop.skins[skin]
else
self.skin = pop.skins[pop.currentSkin]
end
self.horizontal = "left"
self.vertical = "top"
@ -27,6 +32,8 @@ function element:move(x, y)
element.child[i]:move(x - oldX, y - oldY)
end
end
return self
end
function element:setPosition(x, y)
@ -54,6 +61,8 @@ function element:setPosition(x, y)
element.child[i]:move(x - oldX, y - oldY)
end
end
return self
end
function element:getPosition()
@ -90,6 +99,8 @@ function element:setSize(w, h)
self.w = w
self.h = h
return self
end
function element:getSize()
@ -113,6 +124,8 @@ function element:align(horizontal, vertical)
elseif self.vertical == "bottom" then
self.y = self.y + (self.parent.h - self.h)
end
return self
end
function element:alignTo(element, horizontal, vertical)
@ -122,6 +135,8 @@ function element:alignTo(element, horizontal, vertical)
self:align(alignment)
self.parent = realParent
return self
end
function element:setAlignment(horizontal, vertical)
@ -131,14 +146,18 @@ function element:setAlignment(horizontal, vertical)
if vertical then
self.vertical = vertical
end
return self
end
function element:setSkin(skin)
if type(skin) == "string" then
self.skin = pop.skins[skin]
self.skin = self.pop.skins[skin]
else
self.skin = skin
end
return self
end
return element

View File

@ -5,7 +5,7 @@ local path = ...
local pop = {}
pop.elementClasses = {}
--pop.elements = {}
pop.window = false --top level element, defined in pop.load()
pop.window = {child = {}} --top level element, defined in pop.load()
pop.skins = {}
pop.currentSkin = "clear"
--TODO we need a "focused" element for textinput or whatever
@ -17,10 +17,12 @@ function pop.load()
for i=1, #elementList do
local name = elementList[i]:sub(1, -5)
pop.elementClasses[name] = require(path .. "/elements/" .. name)
print("loaded \"" .. name .. "\" element")
-- wrapper to be able to call pop.element() to create elements
if not pop[name] then
pop[name] = function(...) return pop.create(name, ...) end
print("pop." .. name .. "() created")
end
end
@ -31,10 +33,12 @@ function pop.load()
local name = skinList[i]:sub(1, -5)
pop.skins[name] = require(path .. "/skins/" .. name)
pop.skins[name].name = name
print("loaded \"" .. name .. "\" skin")
end
-- set top element
pop.window = pop.create("element"):setSize(lg.getWidth(), lg.getHeight())
print("created pop.window")
end
function pop.create(elementType, parent, ...)
@ -43,7 +47,7 @@ function pop.create(elementType, parent, ...)
end
local newElement = pop.elementClasses[elementType](pop, parent, ...)
table.insert(parent.child, newElement) --NOTE pop.window is its own parent!
table.insert(parent.child, newElement) --NOTE pop.window is its own parent?
return newElement
end
@ -96,6 +100,14 @@ function pop.keyreleased(key)
--TODO no idea what to do with this
end
function pop.setSkin(skin)
if type(skin) == "string" then
pop.currentSkin = pop.skins[skin]
else
pop.currentSkin = skin
end
end
pop.load()
return pop

11
pop/skinclass.lua Normal file
View File

@ -0,0 +1,11 @@
--TODO make skins inherit this, and allow duplication and modification of skins on the fly
local path = string.sub(..., 1, string.len(...) - string.len("/skinclass"))
local class = require(path .. "/lib/middleclass")
local skinclass = class("pop.skinclass")
function skinclass:initialize()
--
end
return skinclass

View File

@ -0,0 +1,6 @@
local skin = {}
skin.background = {255, 255, 255, 255} -- Drawable, color table, or false
skin.foreground = {0, 0, 0, 255} -- Drawable, color table, or false
return skin

View File

@ -1,6 +1,6 @@
local skin = {}
skin.background = false, -- Drawable, color table, or false
skin.background = false -- Drawable, color table, or false
skin.foreground = {255, 255, 255, 255} -- Drawable, color table, or false
return skin

2
run here.bat Normal file
View File

@ -0,0 +1,2 @@
@ECHO OFF
"C:\Program Files\LOVE\love.exe" "%cd%"