mostly done re-implementing things I think

This commit is contained in:
Paul Liverman 2016-02-22 22:10:13 -08:00
parent 2442730ded
commit a100f0f50c
5 changed files with 175 additions and 0 deletions

7
demo/conf.lua Normal file
View File

@ -0,0 +1,7 @@
function love.conf(t)
t.title = "Pop.Box Demo / Tests"
t.console = true
t.window.width = 960
t.window.height = 540
end

74
demo/main.lua Normal file
View File

@ -0,0 +1,74 @@
local pop = require "pop"
local lg = love.graphics
local visualTestsShown = false
local testsRun = false
local debugDrawEnabled = false
function love.load()
pop.text(nil, "Press \"s\" to show objects for visual testing/demo.\nPress \"t\" to run tests.\nPress \"d\" to toggle debug draw."):move(2, 2)
--TODO correct the fact that the size is wrong here! (height doesn't take into account \n)
--NOTE width? Is width calculated correctly when \n's exist? TEST THIS (also test tabs)
pop.text(nil, "This is a test\ncollection of strings to see how width is determined.\nLooks like it takes width of widest line!"):move(30, 120)
pop.element():align("right", "bottom"):setSize(25, 25):move(-5, -5)
end
function love.update(dt)
pop.update(dt)
end
function love.draw()
pop.draw()
if debugDrawEnabled then
pop.debugDraw()
end
end
function love.textinput(text)
--pop.textinput(text)
end
function love.mousepressed(button, x, y)
--pop.mousepressed(button, x, y)
end
function love.mousereleased(button, x, y)
--pop.mousereleased(button, x, y)
end
function love.keypressed(key)
if key == "escape" then
love.event.quit()
else
if (key == "s") and (not visualTestsShown) then
-- old visual tests
local align = pop.box():align("center", "center"):setSize(200, 200)
pop.box(align):align("left", "top"):setSize(75, 10):setColor(255, 0, 255, 255)
pop.box(align):align("center", "top"):setColor(100, 100, 100)
pop.box(align, {0, 255, 0, 255}):setSize(20, 5):align("right", "top")
pop.box(align):align("left", "center"):setColor(0, 0, 255)
pop.box(align):align("center", "center"):setSize(90, 90):setColor(255, 255, 255)
pop.box(align):align("right", "center"):setColor(255, 0, 0)
pop.box(align):align("left", "bottom"):setColor(0, 255, 0):setSize(nil, 40)
pop.box(align):align("center", "bottom"):setColor(255, 255, 0)
pop.box(align):align("right", "bottom"):setColor(0, 255, 255):setSize(40, 40)
--pop.box(nil, {255, 0, 0, 255}):align("left", "top"):setSize(50, 50) --TODO adjust z-height of elements
pop.text(nil, "Hello World!"):align("center"):setText("Hey, I've been modified!")--:move(0, 18)
pop.text(nil, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+[]{}\\|:;\"',./<>?`~"):align("center", "bottom")
visualTestsShown = true
elseif (key == "t") and (not testsRun) then
require "test"
elseif key == "d" then
debugDrawEnabled = not debugDrawEnabled
end
--pop.keypressed(key)
end
end
function love.keyreleased(key)
--pop.keyreleased(key)
end

View File

@ -0,0 +1,75 @@
import graphics from love
import sub, len from string
path = sub ..., 1, len(...) - len "/text"
element = require "#{path}/element"
class text extends element
new: (pop, parent, text="", color={255,255,255,255}) =>
super pop, parent
@font = graphics.newFont 14
@setText text
@color = color
draw: =>
graphics.setColor @color
graphics.setFont @font
graphics.print @text, @x, @y
return @
debugDraw: =>
graphics.setLineWidth 0.5
graphics.setColor 0, 0, 0, 100
graphics.rectangle "fill", @x, @y, @w, @h
graphics.setColor 200, 0, 0, 200
graphics.rectangle "line", @x, @y, @w, @h
graphics.setColor 255, 200, 200, 255
graphics.print "t", @x, @y
return @
setSize: =>
w = @font\getWidth @text
h = @font\getHeight * (select(2, @text:gsub("\n", "\n")) + 1) --hack to get height of multiple lines of text
switch @horizontal
when "center"
@x -= (w - @w)/2
when "right"
@x -= w - @w
switch @vertical
when "center"
@y -= (h - @h)/2
when "right"
@y -= h - @h
@w = w
@h = h
return @
setText: (text="") =>
@text = text
@setSize!
return @
getText: =>
return @text
setFont: (font) =>
@font = font
@setSize!
return @
getFont: =>
return @font
setColor: (r, g, b, a=255) =>
@color = {r, g, b, a}
return @
getColor: =>
return unpack @color

7
src/pop/skins/clear.moon Normal file
View File

@ -0,0 +1,7 @@
import graphics from love
return {
color: {255, 255, 255, 255}
background: false
font: graphics.newFont(13)
}

12
todo.txt Normal file
View File

@ -0,0 +1,12 @@
COPY README AND DOCS FROM MAIN BRANCH, BUT FIGURE OUT WHAT HAS CHANGED OR WHATEVER...
local pop = require "pop"
--[[ TODO
Test using different Drawables: Canvas, Image, Video
- Test without scaling, test with scaling up, test with scaling down.
- Test wtih scaling unevenly (more x / more y, one test for each!).
- Look at what can be done to them, and test doing other things.
- Test using various color tables.
- Test using false.
]]