mirror of https://github.com/kepler155c/opus
transitions
This commit is contained in:
parent
e25f4f9319
commit
427b871e2a
|
@ -15,7 +15,7 @@ local version = "Version 1.1.6"
|
||||||
-- Modified to integrate with opus os
|
-- Modified to integrate with opus os
|
||||||
|
|
||||||
local calls, recTerm, oldTerm, arg, showInput, skipLast, lastDelay, curInput, callCount, callListCount = {{["delay"] = 0}}, {}, Util.shallowCopy(multishell.term), {...}, false, false, 2, "", 1, 2
|
local calls, recTerm, oldTerm, arg, showInput, skipLast, lastDelay, curInput, callCount, callListCount = {{["delay"] = 0}}, {}, Util.shallowCopy(multishell.term), {...}, false, false, 2, "", 1, 2
|
||||||
local curBlink, oldBlink, curCalls, tTerm, buffer, colourNum, xPos, yPos, oldXPos, oldYPos, tCol, bCol, xSize, ySize = false, false, calls[1], {}, {}, {}, 1, 1, 1, 1, colours.white, colours.black, term.getSize()
|
local curBlink, oldBlink, curCalls, tTerm, buffer, colourNum, xPos, yPos, oldXPos, oldYPos, tCol, bCol, xSize, ySize = false, false, calls[1], {}, {}, {}, 1, 1, 1, 1, colours.white, colours.black, oldTerm.getSize()
|
||||||
local greys, buttons = {["0"] = true, ["7"] = true, ["8"] = true, ["f"] = true}, {"l", "r", "m"}
|
local greys, buttons = {["0"] = true, ["7"] = true, ["8"] = true, ["f"] = true}, {"l", "r", "m"}
|
||||||
local charW, charH, chars, resp
|
local charW, charH, chars, resp
|
||||||
local filename
|
local filename
|
||||||
|
|
103
sys/apis/ui.lua
103
sys/apis/ui.lua
|
@ -91,11 +91,26 @@ end
|
||||||
|
|
||||||
--[[-- Top Level Manager --]]--
|
--[[-- Top Level Manager --]]--
|
||||||
local Manager = class()
|
local Manager = class()
|
||||||
|
Manager.effect = {
|
||||||
|
slideLeft = {
|
||||||
|
type = 'slideLeft',
|
||||||
|
ticks = 12,
|
||||||
|
easing = 'outBounce',
|
||||||
|
},
|
||||||
|
slideRight = {
|
||||||
|
type = 'slideRight',
|
||||||
|
ticks = 12,
|
||||||
|
easing = 'outBounce',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
function Manager:init(args)
|
function Manager:init(args)
|
||||||
local control = false
|
local control = false
|
||||||
local shift = false
|
local shift = false
|
||||||
local pages = { }
|
local pages = { }
|
||||||
|
|
||||||
|
self.effectsEnabled = true
|
||||||
|
|
||||||
Event.addHandler('term_resize', function(h, side)
|
Event.addHandler('term_resize', function(h, side)
|
||||||
if self.currentPage then
|
if self.currentPage then
|
||||||
-- the parent doesn't have any children set...
|
-- the parent doesn't have any children set...
|
||||||
|
@ -198,7 +213,6 @@ function Manager:configure(appName, ...)
|
||||||
textScale = { arg = 't', type = 'number',
|
textScale = { arg = 't', type = 'number',
|
||||||
desc = 'Text scale' },
|
desc = 'Text scale' },
|
||||||
}
|
}
|
||||||
|
|
||||||
local defaults = Util.loadTable('/config/' .. appName) or { }
|
local defaults = Util.loadTable('/config/' .. appName) or { }
|
||||||
if not defaults.device then
|
if not defaults.device then
|
||||||
defaults.device = { }
|
defaults.device = { }
|
||||||
|
@ -241,10 +255,14 @@ function Manager:configure(appName, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Manager:disableEffects()
|
||||||
|
self.effectsEnabled = false
|
||||||
|
end
|
||||||
|
|
||||||
function Manager:loadTheme(filename)
|
function Manager:loadTheme(filename)
|
||||||
local theme, err = Util.loadTable(filename)
|
local theme, err = Util.loadTable(filename)
|
||||||
if not theme then
|
if not theme then
|
||||||
error(theme)
|
error(err)
|
||||||
end
|
end
|
||||||
for k,v in pairs(theme) do
|
for k,v in pairs(theme) do
|
||||||
if self[k] and self[k].defaults then
|
if self[k] and self[k].defaults then
|
||||||
|
@ -835,7 +853,6 @@ UI.Device.defaults = {
|
||||||
textColor = colors.white,
|
textColor = colors.white,
|
||||||
textScale = 1,
|
textScale = 1,
|
||||||
lines = { },
|
lines = { },
|
||||||
transitionsEnabled = true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function UI.Device:init(args)
|
function UI.Device:init(args)
|
||||||
|
@ -903,8 +920,13 @@ function UI.Device:setTransition(effect, y, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Device:runTransition(transition)
|
function UI.Device:runTransition(effect)
|
||||||
if transition == 'left' or transition == 'right' then
|
|
||||||
|
if not self.Tween then
|
||||||
|
self.Tween = require('tween')
|
||||||
|
end
|
||||||
|
|
||||||
|
if effect.type == 'slideLeft' or effect.type == 'slideRight' then
|
||||||
for y, line in ipairs(self.lines) do
|
for y, line in ipairs(self.lines) do
|
||||||
if not line.transition then
|
if not line.transition then
|
||||||
self.device.setCursorPos(1, y)
|
self.device.setCursorPos(1, y)
|
||||||
|
@ -912,36 +934,37 @@ function UI.Device:runTransition(transition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local c = os.clock()
|
local pos = { x = 1 }
|
||||||
local steps = math.floor(self.width * .34) -- 150 ms
|
local tween = self.Tween.new(effect.ticks, pos, { x = self.width }, effect.easing)
|
||||||
|
|
||||||
for i = 1, self.width do
|
local lastx = 0
|
||||||
for y, line in pairs(self.lines) do
|
repeat
|
||||||
if line.transition then
|
tween:update(1)
|
||||||
if transition == 'left' then
|
local x = math.floor(pos.x)
|
||||||
local text = self.lastScreen[y].text .. line.text
|
if x ~= lastx then
|
||||||
local bg = self.lastScreen[y].bg .. line.bg
|
lastx = x
|
||||||
local fg = self.lastScreen[y].fg .. line.fg
|
for y, line in pairs(self.lines) do
|
||||||
self.device.setCursorPos(1 - i, y)
|
if line.transition then
|
||||||
self.device.blit(text, fg, bg)
|
if effect.type == 'slideLeft' then
|
||||||
else
|
local text = self.lastScreen[y].text .. line.text
|
||||||
local text = line.text .. self.lastScreen[y].text
|
local bg = self.lastScreen[y].bg .. line.bg
|
||||||
local bg = line.bg .. self.lastScreen[y].bg
|
local fg = self.lastScreen[y].fg .. line.fg
|
||||||
local fg = line.fg .. self.lastScreen[y].fg
|
self.device.setCursorPos(1 - x, y)
|
||||||
self.device.setCursorPos(-self.width + i + 1, y)
|
self.device.blit(text, fg, bg)
|
||||||
self.device.blit(text, fg, bg)
|
else
|
||||||
|
local text = line.text .. self.lastScreen[y].text
|
||||||
|
local bg = line.bg .. self.lastScreen[y].bg
|
||||||
|
local fg = line.fg .. self.lastScreen[y].fg
|
||||||
|
self.device.setCursorPos(-self.width + x + 1, y)
|
||||||
|
self.device.blit(text, fg, bg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (i + math.floor(steps / 2)) % steps == 0 then
|
os.sleep()
|
||||||
if c == os.clock() then
|
until pos.x == self.width
|
||||||
os.sleep(0)
|
|
||||||
c = os.clock()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif transition == 'explode' then
|
elseif effect.type == 'explode' then
|
||||||
local half = math.floor(self.width / 2)
|
local half = math.floor(self.width / 2)
|
||||||
local c = os.clock()
|
local c = os.clock()
|
||||||
local steps = math.floor(self.width * .5)
|
local steps = math.floor(self.width * .5)
|
||||||
|
@ -973,7 +996,7 @@ end
|
||||||
function UI.Device:sync()
|
function UI.Device:sync()
|
||||||
|
|
||||||
local transition
|
local transition
|
||||||
if self.transition then
|
if self.transition and UI.effectsEnabled then
|
||||||
for y, line in pairs(self.lines) do
|
for y, line in pairs(self.lines) do
|
||||||
if line.dirty then
|
if line.dirty then
|
||||||
transition = self.transition
|
transition = self.transition
|
||||||
|
@ -983,7 +1006,7 @@ function UI.Device:sync()
|
||||||
self.transition = nil
|
self.transition = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if transition and self.transitionsEnabled then
|
if transition then
|
||||||
self:runTransition(transition)
|
self:runTransition(transition)
|
||||||
else
|
else
|
||||||
for y, line in pairs(self.lines) do
|
for y, line in pairs(self.lines) do
|
||||||
|
@ -2070,9 +2093,9 @@ function UI.Tabs:eventHandler(event)
|
||||||
for _,tab in ipairs(self.children) do
|
for _,tab in ipairs(self.children) do
|
||||||
if tab ~= self.tabBar then
|
if tab ~= self.tabBar then
|
||||||
if event.current > event.last then
|
if event.current > event.last then
|
||||||
tab:setTransition('left')
|
tab:setTransition(UI.effect.slideLeft)
|
||||||
else
|
else
|
||||||
tab:setTransition('right')
|
tab:setTransition(UI.effect.slideRight)
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -2102,7 +2125,7 @@ function UI.WindowScroller:nextChild()
|
||||||
for i = 1, #self.children do
|
for i = 1, #self.children do
|
||||||
if self.children[i].enabled then
|
if self.children[i].enabled then
|
||||||
if i < #self.children then
|
if i < #self.children then
|
||||||
self:setTransition('left')
|
self:setTransition(UI.effect.slideLeft)
|
||||||
self.children[i]:disable()
|
self.children[i]:disable()
|
||||||
self.children[i + 1]:enable()
|
self.children[i + 1]:enable()
|
||||||
end
|
end
|
||||||
|
@ -2115,7 +2138,7 @@ function UI.WindowScroller:prevChild()
|
||||||
for i = 1, #self.children do
|
for i = 1, #self.children do
|
||||||
if self.children[i].enabled then
|
if self.children[i].enabled then
|
||||||
if i - 1 > 0 then
|
if i - 1 > 0 then
|
||||||
self:setTransition('right')
|
self:setTransition(UI.effect.slideRight)
|
||||||
self.children[i]:disable()
|
self.children[i]:disable()
|
||||||
self.children[i - 1]:enable()
|
self.children[i - 1]:enable()
|
||||||
end
|
end
|
||||||
|
@ -2924,7 +2947,7 @@ function UI.Image:setParent()
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Image:draw()
|
function UI.Image:draw()
|
||||||
self:clear(bg)
|
self:clear()
|
||||||
if self.image then
|
if self.image then
|
||||||
for y = 1, #self.image do
|
for y = 1, #self.image do
|
||||||
local line = self.image[y]
|
local line = self.image[y]
|
||||||
|
@ -2968,7 +2991,7 @@ function UI.NftImage:setParent()
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.NftImage:draw()
|
function UI.NftImage:draw()
|
||||||
-- self:clear(bg)
|
-- self:clear()
|
||||||
if self.image then
|
if self.image then
|
||||||
for y = 1, self.image.height do
|
for y = 1, self.image.height do
|
||||||
for x = 1, #self.image.text[y] do
|
for x = 1, #self.image.text[y] do
|
||||||
|
@ -2984,10 +3007,10 @@ function UI.NftImage:setImage(image)
|
||||||
self.image = image
|
self.image = image
|
||||||
end
|
end
|
||||||
|
|
||||||
UI:setDefaultDevice(UI.Device({ device = term.current() }))
|
|
||||||
|
|
||||||
if fs.exists('/config/ui.theme') then
|
if fs.exists('/config/ui.theme') then
|
||||||
UI:loadTheme('/config/ui.theme')
|
UI:loadTheme('/config/ui.theme')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
UI:setDefaultDevice(UI.Device({ device = term.current() }))
|
||||||
|
|
||||||
return UI
|
return UI
|
||||||
|
|
Loading…
Reference in New Issue