get rid of animation and editor movement
Editors also have some padding within their borders.
This commit is contained in:
parent
55be59d110
commit
3917fa9d94
|
@ -1,9 +1,4 @@
|
|||
on.mouse_press = function(x,y, mouse_button)
|
||||
if Animating then return end
|
||||
if Zoomed_out then
|
||||
zoom_in(x,y)
|
||||
return
|
||||
end
|
||||
if Cursor_node then
|
||||
Cursor_node.show_cursor = nil
|
||||
Cursor_node = nil
|
||||
|
@ -18,12 +13,6 @@ on.mouse_press = function(x,y, mouse_button)
|
|||
edit.mouse_press(node.editor, x,y, mouse_button)
|
||||
return
|
||||
end
|
||||
local node = on_handle(x,y)
|
||||
if node then
|
||||
-- move node
|
||||
Move = {xoff=App.mouse_x()-vx(node.x), yoff=App.mouse_y()-vy(node.y), node=node}
|
||||
return
|
||||
end
|
||||
-- pan surface
|
||||
Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom}
|
||||
end
|
||||
end
|
|
@ -1,8 +1,4 @@
|
|||
on.initialize = function()
|
||||
if table_and_array_both_empty(Definitions) then
|
||||
new_definition()
|
||||
A()
|
||||
else
|
||||
survey_animation() -- calls A internally
|
||||
end
|
||||
new_definition()
|
||||
A()
|
||||
end
|
|
@ -1,5 +1,4 @@
|
|||
on.mouse_release = function(x,y, mouse_button)
|
||||
if Animating then return end
|
||||
if Pan then
|
||||
Pan = nil
|
||||
A()
|
||||
|
@ -10,4 +9,4 @@ on.mouse_release = function(x,y, mouse_button)
|
|||
Cursor_node.show_cursor = true
|
||||
edit.mouse_release(Cursor_node.editor, x,y, mouse_button)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +1,6 @@
|
|||
on.update = function(dt)
|
||||
if Animating then
|
||||
animate_next(dt)
|
||||
return
|
||||
end
|
||||
if Pan then
|
||||
set_mouse_cursor('hand')
|
||||
elseif Move or on_handle(App.mouse_x(), App.mouse_y()) then
|
||||
set_mouse_cursor('crosshair')
|
||||
else
|
||||
set_mouse_cursor('arrow')
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cur
|
|||
-- render background if necessary
|
||||
local node_to_render
|
||||
if node.bg then
|
||||
node_to_render = {type='rectangle', drawmode='line', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y, key=node.key}
|
||||
node_to_render = {type='rectangle', drawmode='line', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x-5, y=node.y-5, key=node.key}
|
||||
table.insert(nodes_to_render, node_to_render)
|
||||
end
|
||||
-- render contents
|
||||
|
@ -29,8 +29,8 @@ compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cur
|
|||
node.h = box_height(node)
|
||||
table.insert(nodes_to_render, node)
|
||||
if node_to_render then
|
||||
node_to_render.w = node.w
|
||||
node_to_render.h = node.h
|
||||
node_to_render.w = node.w+10
|
||||
node_to_render.h = node.h+10
|
||||
end
|
||||
elseif node.type == 'rows' then
|
||||
node.x = x
|
||||
|
|
|
@ -4,14 +4,10 @@ on.text_input = function(t)
|
|||
text_input_on_manifest_navigator(t)
|
||||
elseif Cursor_node then
|
||||
local old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}
|
||||
local old_definition_name = live.get_cmd_from_buffer(Cursor_node.editor.lines[1].data)
|
||||
edit.text_input(Cursor_node.editor, t)
|
||||
if not eq(Cursor_node.editor.screen_top1, old_top) then
|
||||
Viewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)
|
||||
end
|
||||
local definition_name = live.get_cmd_from_buffer(Cursor_node.editor.lines[1].data)
|
||||
maybe_update_key_in_definitions(old_definition_name, definition_name, Cursor_node)
|
||||
Cursor_node.bg = definition_background_color(definition_name)
|
||||
B(--[[preserve screen_top of cursor node]] true)
|
||||
end
|
||||
end
|
|
@ -1,10 +1,5 @@
|
|||
on.keychord_press = function(chord, key)
|
||||
print('key', chord)
|
||||
if Animating then return end
|
||||
if Move then return end
|
||||
if Manifest_navigator.reload then
|
||||
load_manifest()
|
||||
end
|
||||
if chord == 'C-=' then
|
||||
-- zoom in
|
||||
Viewport.zoom = Viewport.zoom+0.1
|
||||
|
@ -19,37 +14,16 @@ on.keychord_press = function(chord, key)
|
|||
-- reset zoom
|
||||
Viewport.zoom = 1.0
|
||||
B()
|
||||
elseif chord == 'C-g' then
|
||||
-- special Expose-like 'global zoom' mode
|
||||
if Zoomed_out == nil then
|
||||
zoom_out()
|
||||
else
|
||||
undo_zoom_out()
|
||||
end
|
||||
elseif chord == 'C-q' then
|
||||
live.send_to_app('QUIT')
|
||||
elseif Manifest_navigator.show then
|
||||
keychord_press_on_manifest_navigator(chord, key)
|
||||
elseif chord == 'C-n' then
|
||||
new_definition()
|
||||
A()
|
||||
elseif chord == 'C-l' then
|
||||
Manifest_navigator.show = true
|
||||
Manifest_navigator.for_delete = false
|
||||
initialize_manifest_navigator()
|
||||
elseif chord == 'C-d' then
|
||||
Manifest_navigator.show = true
|
||||
Manifest_navigator.for_delete = true
|
||||
initialize_manifest_navigator()
|
||||
elseif Cursor_node then
|
||||
local old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}
|
||||
local old_definition_name = live.get_cmd_from_buffer(Cursor_node.editor.lines[1].data)
|
||||
edit.keychord_press(Cursor_node.editor, chord, key)
|
||||
if not eq(Cursor_node.editor.screen_top1, old_top) then
|
||||
Viewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)
|
||||
end
|
||||
local definition_name = live.get_cmd_from_buffer(Cursor_node.editor.lines[1].data)
|
||||
maybe_update_key_in_definitions(old_definition_name, definition_name, Cursor_node)
|
||||
if chord == 'return' then
|
||||
A(--[[preserve screen_top of cursor node]] true)
|
||||
else
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
on.draw = function()
|
||||
if Animating then
|
||||
local q = love.graphics.newQuad((Viewport.x-Global_viewport.x)*Viewport.zoom,(Viewport.y-Global_viewport.y)*Viewport.zoom, App.screen.width, App.screen.height, Global_viewport.w*Viewport.zoom, Global_viewport.h*Viewport.zoom)
|
||||
App.color{r=1,g=1,b=1}
|
||||
love.graphics.draw(Canvas, q, 0,0)
|
||||
return
|
||||
end
|
||||
for _,obj in ipairs(Surface) do
|
||||
love.graphics.setColor(obj.r or 0, obj.g or 0, obj.b or 0)
|
||||
if obj.type == 'rectangle' then
|
||||
love.graphics.rectangle(obj.drawmode or 'fill', vx(obj.x),vy(obj.y), scale(obj.w),scale(obj.h), scale(obj.rx or 2), scale(obj.ry or 2))
|
||||
love.graphics.rectangle(obj.drawmode or 'fill', vx(obj.x),vy(obj.y), scale(obj.w),scale(obj.h), scale(obj.rx or 5), scale(obj.ry or 5))
|
||||
elseif obj.type == 'line' then
|
||||
love.graphics.line(unpack(obj.zdata))
|
||||
elseif obj.type == 'circle' then
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
maybe_update_key_in_definitions = function(old_definition_name, definition_name, Cursor_node)
|
||||
--print(old_definition_name, definition_name)
|
||||
if old_definition_name ~= definition_name then
|
||||
if old_definition_name == nil or Definitions[old_definition_name] ~= Cursor_node then
|
||||
local pos = array.find(Definitions, Cursor_node)
|
||||
--print('found at index', pos)
|
||||
assert(pos)
|
||||
table.remove(Definitions, pos)
|
||||
elseif Definitions[old_definition_name] == Cursor_node then
|
||||
--print('found at key', old_definition_name)
|
||||
Definitions[old_definition_name] = nil
|
||||
end
|
||||
if definition_name and Definitions[definition_name] == nil then
|
||||
--print('moving to key', definition_name)
|
||||
Definitions[definition_name] = Cursor_node
|
||||
elseif definition_name == nil or Definitions[definition_name] then
|
||||
-- temporary collision; try again later
|
||||
-- deleting and reinserting is inefficient, but hopefully rare
|
||||
--print('moving to index', #Definitions+1)
|
||||
table.insert(Definitions, Cursor_node)
|
||||
end
|
||||
--print('-- definition keys')
|
||||
--for k in pairs(Definitions) do
|
||||
--print(k)
|
||||
--end
|
||||
end
|
||||
end
|
|
@ -1,11 +0,0 @@
|
|||
on_handle = function(x,y)
|
||||
for _,node in ipairs(Surface) do
|
||||
if node.type == 'text' then
|
||||
if x >= vx(node.x) and node.w and x < vx(node.x + node.w/2-5) then
|
||||
if y >= vy(node.y-30) and node.h and y < vy(node.y-10) then
|
||||
return node
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
draw_manifest_navigator = function()
|
||||
App.color(Menu_command_color)
|
||||
local filter_text = to_hud_text(Manifest_navigator.filter)
|
||||
App.screen.draw(filter_text, 5, 5)
|
||||
draw_cursor(5 + filter_text:getWidth(), 5)
|
||||
App.color(Menu_background_color)
|
||||
love.graphics.rectangle('fill', 0,Menu_bar_height, App.screen.width, Manifest_navigator.num_lines * (HUD_line_height + --[[highlight padding]]5))
|
||||
local x,y = 5, Menu_bar_height
|
||||
for i,definition in ipairs(Manifest_navigator.candidates) do
|
||||
x,y = add_def_to_menu(x,y, definition, i == Manifest_navigator.index)
|
||||
if Menu_cursor >= App.screen.width - 5 then
|
||||
break
|
||||
end
|
||||
end
|
||||
Manifest_navigator.bottom_y = y + HUD_line_height + --[[highlight padding]] 5
|
||||
end
|
|
@ -1,6 +0,0 @@
|
|||
table_and_array_both_empty = function(x)
|
||||
for _,_ in pairs(x) do
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
|
@ -1,4 +1,2 @@
|
|||
on.key_release = function(key)
|
||||
if Animating then return end
|
||||
if Move then return end
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
Num_animation_frames = 20
|
|
@ -1,4 +0,0 @@
|
|||
Animating = nil -- set this to enable animation
|
||||
-- When enabled, animation should consist of a series of viewport states that we animate into.
|
||||
-- Each viewport state will be attained in Num_animation_frames frames, each of 0.01 ms or 1 Love frame.
|
||||
-- Each state will specify the final state of various viewport keys. Keys not mentioned will remain unchanged.
|
|
@ -1,5 +0,0 @@
|
|||
interpolate_viewport = function(initial, final, step)
|
||||
for k,v in pairs(initial) do
|
||||
Viewport[k] = (initial[k]*(Num_animation_frames - step) + final[k]*step) / Num_animation_frames
|
||||
end
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
Test_definition_background_color = {r=0.7,g=0.9,b=0.7}
|
|
@ -6,21 +6,9 @@ draw_menu_bar = function()
|
|||
love.graphics.rectangle('line', 0,0, App.screen.width, Menu_bar_height)
|
||||
App.color(Menu_command_color)
|
||||
Menu_cursor = 5
|
||||
if Manifest_navigator.show then
|
||||
draw_manifest_navigator()
|
||||
return
|
||||
end
|
||||
if Zoomed_out == nil then
|
||||
add_hotkey_to_menu('ctrl+g: zoom out')
|
||||
else
|
||||
add_hotkey_to_menu('ctrl+g: undo zoom out')
|
||||
end
|
||||
add_hotkey_to_menu('ctrl+l: load definition')
|
||||
add_hotkey_to_menu('ctrl+n: new definition')
|
||||
add_hotkey_to_menu('ctrl+d: delete definition')
|
||||
add_hotkey_to_menu('ctrl+f: find')
|
||||
add_hotkey_to_menu('ctrl+left ctrl+right: prev/next word')
|
||||
add_hotkey_to_menu('ctrl+z ctrl+y: undo/redo')
|
||||
add_hotkey_to_menu('ctrl+x ctrl+c ctrl+v: cut/copy/paste')
|
||||
add_hotkey_to_menu('ctrl+= ctrl+- ctrl+0: zoom')
|
||||
end
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
Zoomed_out = nil -- special mode when set
|
|
@ -1,9 +0,0 @@
|
|||
zoom_out = function()
|
||||
Save_viewport = copy_viewport(Viewport)
|
||||
initialize_global_viewport()
|
||||
snapshot_canvas()
|
||||
Animating = {
|
||||
copy_viewport(Global_viewport),
|
||||
}
|
||||
Zoomed_out = true
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
snapshot_canvas = function()
|
||||
-- Render the canvas at pixel perfect resolution.
|
||||
local winw,winh = App.screen.width, App.screen.height
|
||||
App.screen.width,App.screen.height = Global_viewport.w, Global_viewport.h
|
||||
local saved_viewport = Viewport
|
||||
Viewport = copy_viewport(Global_viewport)
|
||||
Viewport.zoom = 1.0
|
||||
A()
|
||||
Canvas = love.graphics.newCanvas(Global_viewport.w, Global_viewport.h)
|
||||
love.graphics.setCanvas(Canvas)
|
||||
App.fake_key_press = true -- Hack; disable drawing the menu and ticks
|
||||
on.draw()
|
||||
App.fake_key_press = nil
|
||||
love.graphics.setCanvas()
|
||||
Viewport = saved_viewport
|
||||
App.screen.width,App.screen.height = winw,winh
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
animate_next = function(dt)
|
||||
if Animating[1].step and Animating[1].step >= Num_animation_frames then
|
||||
table.remove(Animating, 1)
|
||||
if #Animating == 0 then
|
||||
Animating = nil
|
||||
Canvas = nil
|
||||
A()
|
||||
return
|
||||
end
|
||||
end
|
||||
animate_next_frame(Animating[1], dt)
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
animate_next_frame = function(state, dt)
|
||||
if state.initial == nil then
|
||||
state.initial = from_viewport(state)
|
||||
-- once we've checked keys, pollute the keyspace
|
||||
state.step = 0
|
||||
state.frame_time = 0
|
||||
return
|
||||
end
|
||||
state.frame_time = state.frame_time + dt
|
||||
if state.frame_time > 0.01 then
|
||||
state.frame_time = state.frame_time - 0.01
|
||||
state.step = state.step+1
|
||||
interpolate_viewport(state.initial, state, state.step)
|
||||
B()
|
||||
end
|
||||
end
|
18
0089-zoom_in
18
0089-zoom_in
|
@ -1,18 +0,0 @@
|
|||
zoom_in = function(x,y)
|
||||
-- precondition: Zoomed_out
|
||||
-- precondition: Viewport == Global_viewport
|
||||
-- precondition: Save_viewport exists
|
||||
-- center Viewport on x,y at zoom level Saved_viewport.zoom
|
||||
snapshot_canvas()
|
||||
Animating = {
|
||||
{
|
||||
x=sx(x)-App.screen.width/Save_viewport.zoom/2,
|
||||
y=sy(y)-App.screen.height/Save_viewport.zoom/2,
|
||||
w=App.screen.width/Save_viewport.zoom,
|
||||
h=App.screen.height/Save_viewport.zoom,
|
||||
zoom=Save_viewport.zoom,
|
||||
},
|
||||
}
|
||||
Zoomed_out = nil
|
||||
Save_viewport = nil
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
undo_zoom_out = function()
|
||||
snapshot_canvas()
|
||||
Animating = {
|
||||
Save_viewport,
|
||||
}
|
||||
Save_viewport = nil
|
||||
Zoomed_out = nil
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
Failing_test_definition_background_color = {r=1,g=0.7,b=0.7}
|
|
@ -1,19 +0,0 @@
|
|||
on.code_submit = function(editor)
|
||||
if not editor.load_time_error then
|
||||
Manifest_navigator.reload = true
|
||||
end
|
||||
-- update definition backgrounds of failing tests
|
||||
for name,node in pairs(Definitions) do
|
||||
-- ignore temporary definitions with numeric indices; they haven't been saved yet
|
||||
if type(name) == 'string' and starts_with(name, 'test_') then
|
||||
if Client_app_test_failures[name] then
|
||||
node.bg = Failing_test_definition_background_color
|
||||
node.editor.load_time_error = Client_app_test_failures[name]
|
||||
else
|
||||
node.bg = Test_definition_background_color
|
||||
node.editor.load_time_error = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
A()
|
||||
end
|
|
@ -1,32 +0,0 @@
|
|||
survey_animation = function()
|
||||
---[[ '--' at start to disable animation, '---' to enable
|
||||
local minx, miny, maxx, maxy = surface_bounds(Definitions)
|
||||
-- ensure 1px of white background all around
|
||||
-- just in case the viewport ever goes
|
||||
-- outside canvas bounds while animating
|
||||
minx,miny, maxx,maxy = minx-1,miny-1, maxx+2,maxy+1
|
||||
local zoomx = App.screen.width/(maxx-minx)
|
||||
local zoomy = App.screen.height/(maxy-miny)
|
||||
local zoom, cw, ch
|
||||
if zoomx < zoomy then
|
||||
zoom = zoomx
|
||||
cw = maxx-minx
|
||||
ch = cw*App.screen.height/App.screen.width
|
||||
else
|
||||
zoom = zoomy
|
||||
ch = maxy-miny
|
||||
cw = ch*App.screen.width/App.screen.height
|
||||
end
|
||||
Global_viewport = {x=minx, y=miny, w=cw, h=ch, zoom=zoom}
|
||||
snapshot_canvas()
|
||||
-- initialize animation
|
||||
Animating = {
|
||||
copy_viewport(Global_viewport),
|
||||
copy_viewport(Viewport),
|
||||
}
|
||||
Viewport.x = -App.screen.width/2
|
||||
Viewport.y = -App.screen.height/2
|
||||
Viewport.w = App.screen.width
|
||||
Viewport.h = App.screen.height
|
||||
Viewport.zoom = 1.0 --]]
|
||||
end
|
|
@ -1,7 +1,4 @@
|
|||
definition_background_color = function(name)
|
||||
if name and starts_with(name, 'test_') then
|
||||
return Test_definition_background_color
|
||||
else
|
||||
return Definition_background_color
|
||||
end
|
||||
-- TODO: get rid of this function
|
||||
return Border_color
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
Global_viewport = nil
|
|
@ -1,20 +0,0 @@
|
|||
initialize_global_viewport = function()
|
||||
local minx, miny, maxx, maxy = surface_bounds(Definitions)
|
||||
-- ensure 1px of white background all around
|
||||
-- just in case the viewport ever goes
|
||||
-- outside canvas bounds while animating
|
||||
minx,miny, maxx,maxy = minx-1,miny-1, maxx+2,maxy+1
|
||||
local zoomx = App.screen.width/(maxx-minx)
|
||||
local zoomy = App.screen.height/(maxy-miny)
|
||||
local zoom, cw, ch
|
||||
if zoomx < zoomy then
|
||||
zoom = zoomx
|
||||
cw = maxx-minx
|
||||
ch = cw*App.screen.height/App.screen.width
|
||||
else
|
||||
zoom = zoomy
|
||||
ch = maxy-miny
|
||||
cw = ch*App.screen.width/App.screen.height
|
||||
end
|
||||
Global_viewport = {x=minx, y=miny, w=cw, h=ch, zoom=zoom}
|
||||
end
|
Loading…
Reference in New Issue