mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
working, but skins suck
This commit is contained in:
parent
1ba7314243
commit
0b1d48f3c5
7
main.lua
7
main.lua
@ -1,8 +1,9 @@
|
|||||||
local pop = require "pop"
|
local pop = require "pop"
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
--pop.box() -- returns the box element
|
pop.setSkin("blackonwhite")
|
||||||
-- or pop.create("box") (this is what is actually called when you call pop.box())
|
local align = pop.box():align("center", "center"):setSize(100, 100):setSkin("blackonwhite")
|
||||||
|
--print(align.skin)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
@ -11,6 +12,8 @@ end
|
|||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
pop.draw()
|
pop.draw()
|
||||||
|
love.graphics.setColor(255, 255, 255, 255)
|
||||||
|
--love.graphics.rectangle("fill", 0, 0, 100, 100)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.textinput(text)
|
function love.textinput(text)
|
||||||
|
@ -11,9 +11,14 @@ function box:initialize(pop, parent, skin)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function box:draw() --TODO these ifs are probably wrong
|
function box:draw() --TODO these ifs are probably wrong
|
||||||
|
print("box drawn!")
|
||||||
|
|
||||||
|
if self.skin.background then
|
||||||
if type(self.skin.background) == "table" then
|
if type(self.skin.background) == "table" then
|
||||||
lg.setColor(self.skin.background)
|
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)
|
lg.rectangle("fill", self.x, self.y, self.w, self.h)
|
||||||
|
print("rect")
|
||||||
else
|
else
|
||||||
lg.setColor(255, 255, 255, 255)
|
lg.setColor(255, 255, 255, 255)
|
||||||
local w, h = self.skin.background:getDimensions()
|
local w, h = self.skin.background:getDimensions()
|
||||||
@ -22,7 +27,9 @@ function box:draw() --TODO these ifs are probably wrong
|
|||||||
h = self.h/h
|
h = self.h/h
|
||||||
lg.draw(self.skin.background, self.x, self.y, 0, w, h)
|
lg.draw(self.skin.background, self.x, self.y, 0, w, h)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.skin.foreground then
|
||||||
if type(self.skin.foreground) == "table" then
|
if type(self.skin.foreground) == "table" then
|
||||||
lg.setColor(self.skin.foreground)
|
lg.setColor(self.skin.foreground)
|
||||||
lg.rectangle("fill", self.x, self.y, self.w, self.h)
|
lg.rectangle("fill", self.x, self.y, self.w, self.h)
|
||||||
@ -34,6 +41,9 @@ function box:draw() --TODO these ifs are probably wrong
|
|||||||
h = self.h/h
|
h = self.h/h
|
||||||
lg.draw(self.skin.foreground, self.x, self.y, 0, w, h)
|
lg.draw(self.skin.foreground, self.x, self.y, 0, w, h)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
return box
|
return box
|
||||||
|
@ -4,6 +4,7 @@ local class = require(path .. "/lib/middleclass")
|
|||||||
local element = class("pop.element")
|
local element = class("pop.element")
|
||||||
|
|
||||||
function element:initialize(pop, parent, skin)
|
function element:initialize(pop, parent, skin)
|
||||||
|
self.pop = pop --I hate this -.-
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.child = {}
|
self.child = {}
|
||||||
|
|
||||||
@ -12,7 +13,11 @@ function element:initialize(pop, parent, skin)
|
|||||||
self.w = 10
|
self.w = 10
|
||||||
self.h = 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.horizontal = "left"
|
||||||
self.vertical = "top"
|
self.vertical = "top"
|
||||||
@ -27,6 +32,8 @@ function element:move(x, y)
|
|||||||
element.child[i]:move(x - oldX, y - oldY)
|
element.child[i]:move(x - oldX, y - oldY)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:setPosition(x, y)
|
function element:setPosition(x, y)
|
||||||
@ -54,6 +61,8 @@ function element:setPosition(x, y)
|
|||||||
element.child[i]:move(x - oldX, y - oldY)
|
element.child[i]:move(x - oldX, y - oldY)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:getPosition()
|
function element:getPosition()
|
||||||
@ -90,6 +99,8 @@ function element:setSize(w, h)
|
|||||||
|
|
||||||
self.w = w
|
self.w = w
|
||||||
self.h = h
|
self.h = h
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:getSize()
|
function element:getSize()
|
||||||
@ -113,6 +124,8 @@ function element:align(horizontal, vertical)
|
|||||||
elseif self.vertical == "bottom" then
|
elseif self.vertical == "bottom" then
|
||||||
self.y = self.y + (self.parent.h - self.h)
|
self.y = self.y + (self.parent.h - self.h)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:alignTo(element, horizontal, vertical)
|
function element:alignTo(element, horizontal, vertical)
|
||||||
@ -122,6 +135,8 @@ function element:alignTo(element, horizontal, vertical)
|
|||||||
self:align(alignment)
|
self:align(alignment)
|
||||||
|
|
||||||
self.parent = realParent
|
self.parent = realParent
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:setAlignment(horizontal, vertical)
|
function element:setAlignment(horizontal, vertical)
|
||||||
@ -131,14 +146,18 @@ function element:setAlignment(horizontal, vertical)
|
|||||||
if vertical then
|
if vertical then
|
||||||
self.vertical = vertical
|
self.vertical = vertical
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:setSkin(skin)
|
function element:setSkin(skin)
|
||||||
if type(skin) == "string" then
|
if type(skin) == "string" then
|
||||||
self.skin = pop.skins[skin]
|
self.skin = self.pop.skins[skin]
|
||||||
else
|
else
|
||||||
self.skin = skin
|
self.skin = skin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
return element
|
return element
|
||||||
|
16
pop/init.lua
16
pop/init.lua
@ -5,7 +5,7 @@ local path = ...
|
|||||||
local pop = {}
|
local pop = {}
|
||||||
pop.elementClasses = {}
|
pop.elementClasses = {}
|
||||||
--pop.elements = {}
|
--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.skins = {}
|
||||||
pop.currentSkin = "clear"
|
pop.currentSkin = "clear"
|
||||||
--TODO we need a "focused" element for textinput or whatever
|
--TODO we need a "focused" element for textinput or whatever
|
||||||
@ -17,10 +17,12 @@ function pop.load()
|
|||||||
for i=1, #elementList do
|
for i=1, #elementList do
|
||||||
local name = elementList[i]:sub(1, -5)
|
local name = elementList[i]:sub(1, -5)
|
||||||
pop.elementClasses[name] = require(path .. "/elements/" .. name)
|
pop.elementClasses[name] = require(path .. "/elements/" .. name)
|
||||||
|
print("loaded \"" .. name .. "\" element")
|
||||||
|
|
||||||
-- wrapper to be able to call pop.element() to create elements
|
-- wrapper to be able to call pop.element() to create elements
|
||||||
if not pop[name] then
|
if not pop[name] then
|
||||||
pop[name] = function(...) return pop.create(name, ...) end
|
pop[name] = function(...) return pop.create(name, ...) end
|
||||||
|
print("pop." .. name .. "() created")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -31,10 +33,12 @@ function pop.load()
|
|||||||
local name = skinList[i]:sub(1, -5)
|
local name = skinList[i]:sub(1, -5)
|
||||||
pop.skins[name] = require(path .. "/skins/" .. name)
|
pop.skins[name] = require(path .. "/skins/" .. name)
|
||||||
pop.skins[name].name = name
|
pop.skins[name].name = name
|
||||||
|
print("loaded \"" .. name .. "\" skin")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set top element
|
-- set top element
|
||||||
pop.window = pop.create("element"):setSize(lg.getWidth(), lg.getHeight())
|
pop.window = pop.create("element"):setSize(lg.getWidth(), lg.getHeight())
|
||||||
|
print("created pop.window")
|
||||||
end
|
end
|
||||||
|
|
||||||
function pop.create(elementType, parent, ...)
|
function pop.create(elementType, parent, ...)
|
||||||
@ -43,7 +47,7 @@ function pop.create(elementType, parent, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local newElement = pop.elementClasses[elementType](pop, parent, ...)
|
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
|
return newElement
|
||||||
end
|
end
|
||||||
@ -96,6 +100,14 @@ function pop.keyreleased(key)
|
|||||||
--TODO no idea what to do with this
|
--TODO no idea what to do with this
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function pop.setSkin(skin)
|
||||||
|
if type(skin) == "string" then
|
||||||
|
pop.currentSkin = pop.skins[skin]
|
||||||
|
else
|
||||||
|
pop.currentSkin = skin
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
pop.load()
|
pop.load()
|
||||||
|
|
||||||
return pop
|
return pop
|
||||||
|
11
pop/skinclass.lua
Normal file
11
pop/skinclass.lua
Normal 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
|
6
pop/skins/blackonwhite.lua
Normal file
6
pop/skins/blackonwhite.lua
Normal 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
|
@ -1,6 +1,6 @@
|
|||||||
local skin = {}
|
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
|
skin.foreground = {255, 255, 255, 255} -- Drawable, color table, or false
|
||||||
|
|
||||||
return skin
|
return skin
|
||||||
|
2
run here.bat
Normal file
2
run here.bat
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
@ECHO OFF
|
||||||
|
"C:\Program Files\LOVE\love.exe" "%cd%"
|
Loading…
Reference in New Issue
Block a user