Allow per-context transformations (#9)

This commit is contained in:
Kevin Harrison 2016-12-29 23:17:13 -05:00
parent 8b5482e74f
commit 26f05c82e4
6 changed files with 377 additions and 95 deletions

View file

@ -1,3 +1,5 @@
-- Demonstrate a number of custom drawing functions.
local img = love.graphics.newImage 'skin/button.png'
return function (ui)

View file

@ -7,52 +7,61 @@ local draw = require 'draw'
local overview = require 'overview'
local style = require 'style'
local skin = require 'skin'
local transform = require 'transform'
local ui
local ui1, ui2
function love.load()
ui = nuklear.init()
ui1, ui2 = nuklear.newUI(), nuklear.newUI()
end
function love.update(dt)
ui:frameBegin()
calculator(ui)
style(ui)
overview(ui)
draw(ui)
skin(ui)
ui:frameEnd()
ui1:frameBegin()
calculator(ui1)
style(ui1)
overview(ui1)
draw(ui1)
skin(ui1)
ui1:frameEnd()
ui2:frameBegin()
transform(ui2)
ui2:frameEnd()
end
function love.draw()
ui:draw()
ui1:draw()
ui2:draw()
love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 10, 10)
end
local function input(name, ...)
return ui2[name](ui2, ...) or ui1[name](ui1, ...)
end
function love.keypressed(key, scancode, isrepeat)
ui:keypressed(key, scancode, isrepeat)
input('keypressed', key, scancode, isrepeat)
end
function love.keyreleased(key, scancode)
ui:keyreleased(key, scancode)
input('keyreleased', key, scancode)
end
function love.mousepressed(x, y, button, istouch)
ui:mousepressed(x, y, button, istouch)
input('mousepressed', x, y, button, istouch)
end
function love.mousereleased(x, y, button, istouch)
ui:mousereleased(x, y, button, istouch)
input('mousereleased', x, y, button, istouch)
end
function love.mousemoved(x, y, dx, dy, istouch)
ui:mousemoved(x, y, dx, dy, istouch)
input('mousemoved', x, y, dx, dy, istouch)
end
function love.textinput(text)
ui:textinput(text)
input('textinput', text)
end
function love.wheelmoved(x, y)
ui:wheelmoved(x, y)
input('wheelmoved', x, y)
end

View file

@ -24,7 +24,7 @@ return function (ui)
ui:menuEnd()
end
ui:menubarEnd()
ui:layoutRow('dynamic', 400, 3)
ui:layoutRow('dynamic', 375, 3)
if ui:groupBegin('Group 1', 'border') then
ui:layoutRow('dynamic', 30, 1)
ui:label('Left label')

View file

@ -1,3 +1,5 @@
-- Basic skinning example.
local windowHeader = love.graphics.newImage 'skin/window_header.png'
local checkboxSkin = love.graphics.newImage 'skin/checkbox_false.png'
local checkboxCheck = love.graphics.newImage 'skin/checkbox_true.png'

14
example/transform.lua Normal file
View file

@ -0,0 +1,14 @@
-- Apply transformations to a basic UI.
return function(ui)
local t = love.timer.getTime()
ui:translate(350 + 100 * math.cos(t / 4), 350 + 100 * math.sin(t / 4))
ui:rotate(t / 8)
ui:scale(1 + math.sin(t / 4) / 2, 1 + math.cos(t / 4) / 2)
ui:shear(math.cos(t / 8) / 4, math.sin(t / 8) / 4)
if ui:windowBegin('Transform', 0, 0, 200, 200, 'border', 'title') then
ui:layoutRow('dynamic', 150, 1)
ui:label('You can apply transformations to the UI using ui:rotate, ui:scale, ui:shear, and ui:translate.', 'wrap')
end
ui:windowEnd()
end