starting to experiment with animated pane transitions
This commit is contained in:
parent
20f95bc766
commit
47d38eabf2
11
0005-animate
11
0005-animate
|
@ -1,8 +1,5 @@
|
|||
-- A debugging aid to help animate intermediate results within f.
|
||||
-- Pause animation in the current frame using loiter().
|
||||
-- Try to only have one such call in your program.
|
||||
-- You can have multiple, but things might get confusing if one of them indirectly calls the other,
|
||||
-- or more generally if a single function ever loiters sometimes under the call tree of one and sometimes under the other.
|
||||
-- Animate 'f' by smearing its work across multiple frames.
|
||||
-- Pause animation in the current frame using end_frame().
|
||||
animate = function(f, ...)
|
||||
local args = {...}
|
||||
Error_with_callstack = nil
|
||||
|
@ -17,5 +14,5 @@ animate = function(f, ...)
|
|||
if Error_with_callstack then
|
||||
error(Error_with_callstack)
|
||||
end
|
||||
table.insert(Debug_animations_in_progress, {co=co, next_run=Current_time+0.3})
|
||||
end
|
||||
table.insert(Animations_in_progress, {co=co})
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
-- A debugging aid to animate intermediate results in computations.
|
||||
-- Can only be called from functions invoked using `animate()`.
|
||||
-- Can only be called from functions invoked using `enable_loiter()`.
|
||||
loiter = function()
|
||||
coroutine.yield()
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
-- Internal helper for animate()
|
||||
-- Internal helper for animations.
|
||||
-- Records the stack of function calls that led to any error within a debug animation coroutine.
|
||||
-- Lua normally prints out errors with callstacks, but coroutines interrupt the stack unless we do some additional work.
|
||||
save_callstack = function(err)
|
||||
local callstack = debug.traceback('', --[[stack frame]]2)
|
||||
Error_with_callstack = 'Error: ' .. cleaned_up_frame(tostring(err))..'\n'..cleaned_up_callstack(callstack)
|
||||
end
|
||||
end
|
|
@ -10,4 +10,5 @@ on.draw = function()
|
|||
edit.draw(Current_pane.output_editor_state, Normal_color, --[[hide cursor]] true)
|
||||
draw_scrollbar(Current_pane.output_editor_state)
|
||||
draw_menu()
|
||||
draw_next_frames_of_animations()
|
||||
end
|
|
@ -25,6 +25,7 @@ draw_menu = function()
|
|||
onpress1 = function()
|
||||
Current_pane_index = Current_pane_index-1
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
animate(slide_canvas(Current_pane_index+1, 'right'))
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
@ -39,6 +40,7 @@ draw_menu = function()
|
|||
table.insert(Panes, new_pane())
|
||||
Current_pane_index = Current_pane_index+1
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
animate(slide_canvas(Current_pane_index-1, 'left'))
|
||||
end,
|
||||
})
|
||||
else
|
||||
|
@ -50,6 +52,7 @@ draw_menu = function()
|
|||
onpress1 = function()
|
||||
Current_pane_index = Current_pane_index+1
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
animate(slide_canvas(Current_pane_index-1, 'left'))
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
-- A debugging aid to help animate intermediate results within f.
|
||||
-- Pause animation in the current frame using loiter().
|
||||
-- Try to only have one such call in your program.
|
||||
-- You can have multiple, but things might get confusing if one of them indirectly calls the other,
|
||||
-- or more generally if a single function ever loiters sometimes under the call tree of one and sometimes under the other.
|
||||
enable_loiter = function(f, ...)
|
||||
local args = {...}
|
||||
Error_with_callstack = nil
|
||||
local co = coroutine.create(
|
||||
function()
|
||||
xpcall(function()
|
||||
f(unpack(args))
|
||||
end,
|
||||
save_callstack)
|
||||
end)
|
||||
coroutine.resume(co, ...)
|
||||
if Error_with_callstack then
|
||||
error(Error_with_callstack)
|
||||
end
|
||||
table.insert(Debug_animations_in_progress, {co=co, next_run=Current_time+0.3})
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
-- Intermediate state during animations.
|
||||
Animations_in_progress = {}
|
|
@ -0,0 +1,4 @@
|
|||
-- Pause a drawing called by animate().
|
||||
end_frame = function()
|
||||
coroutine.yield()
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
-- update any in-progress animations
|
||||
-- return whether any work remains
|
||||
draw_next_frames_of_animations = function()
|
||||
local a = Animations_in_progress
|
||||
for i=#a,1,-1 do
|
||||
if coroutine.status(a[i].co) == 'dead' then
|
||||
table.remove(a, i)
|
||||
else
|
||||
local status, err = coroutine.resume(a[i].co)
|
||||
if status == false then error(err) end
|
||||
end
|
||||
end
|
||||
return #a > 0
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
slide_canvas = function(pane_index, dir)
|
||||
return function()
|
||||
end_frame()
|
||||
if dir == 'right' then
|
||||
for i=1,40 do
|
||||
print(Current_time, i)
|
||||
love.graphics.rectangle('fill', i*10,0, 30, App.screen.height)
|
||||
end_frame()
|
||||
end
|
||||
elseif dir == 'left' then
|
||||
for i=20,1,-1 do
|
||||
print(i)
|
||||
love.graphics.line(i*50,0, i*50, App.screen.height)
|
||||
end_frame()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue