support for naming points
There's still an absence of affordance showing when you're in naming mode.
This commit is contained in:
parent
96df187488
commit
bb9e23a638
|
@ -16,6 +16,9 @@ Known issues:
|
||||||
So far this app isn't really designed for drawing-heavy files. For now I'm
|
So far this app isn't really designed for drawing-heavy files. For now I'm
|
||||||
targeting mostly-text files with a few drawings mixed in.
|
targeting mostly-text files with a few drawings mixed in.
|
||||||
|
|
||||||
|
* No clipping yet for drawings. In particular, circles and point labels can
|
||||||
|
overflow a drawing.
|
||||||
|
|
||||||
* Insufficient handling of constraints when moving points. For example, if you
|
* Insufficient handling of constraints when moving points. For example, if you
|
||||||
draw a manhattan line and then move one of the points, you may not be able
|
draw a manhattan line and then move one of the points, you may not be able
|
||||||
to hover on it anymore.
|
to hover on it anymore.
|
||||||
|
|
16
drawing.lua
16
drawing.lua
|
@ -46,6 +46,10 @@ function Drawing.draw(line)
|
||||||
love.graphics.setColor(0,0,0)
|
love.graphics.setColor(0,0,0)
|
||||||
love.graphics.circle('fill', Drawing.pixels(p.x)+16,Drawing.pixels(p.y)+line.y, 2)
|
love.graphics.circle('fill', Drawing.pixels(p.x)+16,Drawing.pixels(p.y)+line.y, 2)
|
||||||
end
|
end
|
||||||
|
if p.name then
|
||||||
|
-- todo: clip
|
||||||
|
love.graphics.print(p.name, Drawing.pixels(p.x)+16+5,Drawing.pixels(p.y)+line.y+5, 0, Zoom)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
love.graphics.setColor(0.75,0.75,0.75)
|
love.graphics.setColor(0.75,0.75,0.75)
|
||||||
|
@ -78,6 +82,7 @@ function Drawing.draw_shape(left,top, drawing, shape)
|
||||||
local curr = drawing.points[shape.vertices[1]]
|
local curr = drawing.points[shape.vertices[1]]
|
||||||
love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, Drawing.pixels(curr.x)+left,Drawing.pixels(curr.y)+top)
|
love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, Drawing.pixels(curr.x)+left,Drawing.pixels(curr.y)+top)
|
||||||
elseif shape.mode == 'circle' then
|
elseif shape.mode == 'circle' then
|
||||||
|
-- todo: clip
|
||||||
local center = drawing.points[shape.center]
|
local center = drawing.points[shape.center]
|
||||||
love.graphics.circle('line', Drawing.pixels(center.x)+left,Drawing.pixels(center.y)+top, Drawing.pixels(shape.radius))
|
love.graphics.circle('line', Drawing.pixels(center.x)+left,Drawing.pixels(center.y)+top, Drawing.pixels(shape.radius))
|
||||||
elseif shape.mode == 'arc' then
|
elseif shape.mode == 'arc' then
|
||||||
|
@ -173,6 +178,8 @@ function Drawing.draw_pending_shape(left,top, drawing)
|
||||||
love.graphics.arc('line', 'open', cx,cy, Drawing.pixels(shape.radius), shape.start_angle, shape.end_angle, 360)
|
love.graphics.arc('line', 'open', cx,cy, Drawing.pixels(shape.radius), shape.start_angle, shape.end_angle, 360)
|
||||||
elseif shape.mode == 'move' then
|
elseif shape.mode == 'move' then
|
||||||
-- nothing pending; changes are immediately committed
|
-- nothing pending; changes are immediately committed
|
||||||
|
elseif shape.mode == 'name' then
|
||||||
|
-- nothing pending; changes are immediately committed
|
||||||
else
|
else
|
||||||
print(shape.mode)
|
print(shape.mode)
|
||||||
assert(false)
|
assert(false)
|
||||||
|
@ -468,6 +475,15 @@ function Drawing.keychord_pressed(chord)
|
||||||
drawing.pending = {mode=Current_drawing_mode, target_point=p}
|
drawing.pending = {mode=Current_drawing_mode, target_point=p}
|
||||||
Lines.current = drawing
|
Lines.current = drawing
|
||||||
end
|
end
|
||||||
|
elseif chord == 'C-n' and not love.mouse.isDown('1') then
|
||||||
|
local drawing,point_index,p = Drawing.select_point_at_mouse()
|
||||||
|
if drawing then
|
||||||
|
Previous_drawing_mode = Current_drawing_mode
|
||||||
|
Current_drawing_mode = 'name'
|
||||||
|
p.name = ''
|
||||||
|
drawing.pending = {mode=Current_drawing_mode, target_point=point_index}
|
||||||
|
Lines.current = drawing
|
||||||
|
end
|
||||||
elseif chord == 'C-d' and not love.mouse.isDown('1') then
|
elseif chord == 'C-d' and not love.mouse.isDown('1') then
|
||||||
local drawing,i,p = Drawing.select_point_at_mouse()
|
local drawing,i,p = Drawing.select_point_at_mouse()
|
||||||
if drawing then
|
if drawing then
|
||||||
|
|
12
file.lua
12
file.lua
|
@ -48,15 +48,25 @@ function load_drawing(infile_next_line)
|
||||||
assert(line)
|
assert(line)
|
||||||
if line == '```' then break end
|
if line == '```' then break end
|
||||||
local shape = json.decode(line)
|
local shape = json.decode(line)
|
||||||
if shape.mode == 'line' or shape.mode == 'manhattan' then
|
if shape.mode == 'freehand' then
|
||||||
|
-- no changes needed
|
||||||
|
elseif shape.mode == 'line' or shape.mode == 'manhattan' then
|
||||||
|
local name = shape.p1.name
|
||||||
shape.p1 = Drawing.insert_point(drawing.points, shape.p1.x, shape.p1.y)
|
shape.p1 = Drawing.insert_point(drawing.points, shape.p1.x, shape.p1.y)
|
||||||
|
drawing.points[shape.p1].name = name
|
||||||
|
name = shape.p2.name
|
||||||
shape.p2 = Drawing.insert_point(drawing.points, shape.p2.x, shape.p2.y)
|
shape.p2 = Drawing.insert_point(drawing.points, shape.p2.x, shape.p2.y)
|
||||||
|
drawing.points[shape.p2].name = name
|
||||||
elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
|
elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
|
||||||
for i,p in ipairs(shape.vertices) do
|
for i,p in ipairs(shape.vertices) do
|
||||||
|
local name = p.name
|
||||||
shape.vertices[i] = Drawing.insert_point(drawing.points, p.x,p.y)
|
shape.vertices[i] = Drawing.insert_point(drawing.points, p.x,p.y)
|
||||||
|
drawing.points[shape.vertices[i]].name = name
|
||||||
end
|
end
|
||||||
elseif shape.mode == 'circle' or shape.mode == 'arc' then
|
elseif shape.mode == 'circle' or shape.mode == 'arc' then
|
||||||
|
local name = shape.center.name
|
||||||
shape.center = Drawing.insert_point(drawing.points, shape.center.x,shape.center.y)
|
shape.center = Drawing.insert_point(drawing.points, shape.center.x,shape.center.y)
|
||||||
|
drawing.point[shape.center].name = name
|
||||||
else
|
else
|
||||||
print(shape.mode)
|
print(shape.mode)
|
||||||
assert(false)
|
assert(false)
|
||||||
|
|
2
help.lua
2
help.lua
|
@ -7,6 +7,8 @@ function draw_help_without_mouse_pressed(drawing)
|
||||||
y = y + math.floor(15*Zoom)
|
y = y + math.floor(15*Zoom)
|
||||||
love.graphics.print("* Hover on a point and press 'ctrl+v' to start moving it,", 16+30,y, 0, Zoom)
|
love.graphics.print("* Hover on a point and press 'ctrl+v' to start moving it,", 16+30,y, 0, Zoom)
|
||||||
y = y + math.floor(15*Zoom)
|
y = y + math.floor(15*Zoom)
|
||||||
|
love.graphics.print("* Hover on a point and press 'ctrl+n' to name it,", 16+30,y, 0, Zoom)
|
||||||
|
y = y + math.floor(15*Zoom)
|
||||||
love.graphics.print("then press the mouse button to finish", 16+30+bullet_indent(),y, 0, Zoom)
|
love.graphics.print("then press the mouse button to finish", 16+30+bullet_indent(),y, 0, Zoom)
|
||||||
y = y + math.floor(15*Zoom)
|
y = y + math.floor(15*Zoom)
|
||||||
love.graphics.print("* Hover on a point or shape and press 'ctrl+d' to delete it", 16+30,y, 0, Zoom)
|
love.graphics.print("* Hover on a point or shape and press 'ctrl+d' to delete it", 16+30,y, 0, Zoom)
|
||||||
|
|
27
main.lua
27
main.lua
|
@ -167,6 +167,17 @@ function love.mousereleased(x,y, button)
|
||||||
Drawing.mouse_released(x,y, button)
|
Drawing.mouse_released(x,y, button)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function love.textinput(t)
|
||||||
|
if Current_drawing_mode == 'name' then
|
||||||
|
local drawing = Lines.current
|
||||||
|
local p = drawing.points[drawing.pending.target_point]
|
||||||
|
p.name = p.name..t
|
||||||
|
else
|
||||||
|
Text.textinput(t)
|
||||||
|
end
|
||||||
|
save_to_disk(Lines, Filename)
|
||||||
|
end
|
||||||
|
|
||||||
function keychord_pressed(chord)
|
function keychord_pressed(chord)
|
||||||
if love.mouse.isDown('1') or chord:sub(1,2) == 'C-' then
|
if love.mouse.isDown('1') or chord:sub(1,2) == 'C-' then
|
||||||
Drawing.keychord_pressed(chord)
|
Drawing.keychord_pressed(chord)
|
||||||
|
@ -175,6 +186,22 @@ function keychord_pressed(chord)
|
||||||
if drawing then
|
if drawing then
|
||||||
drawing.pending = {}
|
drawing.pending = {}
|
||||||
end
|
end
|
||||||
|
elseif Current_drawing_mode == 'name' then
|
||||||
|
if chord == 'return' then
|
||||||
|
Current_drawing_mode = Previous_drawing_mode
|
||||||
|
Previous_drawing_mode = nil
|
||||||
|
else
|
||||||
|
local drawing = Lines.current
|
||||||
|
local p = drawing.points[drawing.pending.target_point]
|
||||||
|
if chord == 'escape' then
|
||||||
|
p.name = nil
|
||||||
|
elseif chord == 'backspace' then
|
||||||
|
local len = utf8.len(p.name)
|
||||||
|
local byte_offset = utf8.offset(p.name, len-1)
|
||||||
|
p.name = string.sub(p.name, 1, byte_offset)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
save_to_disk(Lines, Filename)
|
||||||
elseif chord == 'pagedown' then
|
elseif chord == 'pagedown' then
|
||||||
Screen_top_line = Screen_bottom_line
|
Screen_top_line = Screen_bottom_line
|
||||||
Cursor_line = Screen_top_line
|
Cursor_line = Screen_top_line
|
||||||
|
|
|
@ -15,6 +15,7 @@ backspace
|
||||||
drawing
|
drawing
|
||||||
draw a line, circle, rectangle, square, polygon
|
draw a line, circle, rectangle, square, polygon
|
||||||
select a point and move it
|
select a point and move it
|
||||||
|
select a point and name it
|
||||||
|
|
||||||
enter
|
enter
|
||||||
cursor_pos == 0 -> insert empty line above current line
|
cursor_pos == 0 -> insert empty line above current line
|
||||||
|
@ -33,3 +34,4 @@ scrolling:
|
||||||
|
|
||||||
persistence:
|
persistence:
|
||||||
draw a line, circle, rectangle, square, polygon, quit, restart. All the shapes you drew should still be visible.
|
draw a line, circle, rectangle, square, polygon, quit, restart. All the shapes you drew should still be visible.
|
||||||
|
select a point and name it, quit, restart. Name is still visible.
|
||||||
|
|
4
text.lua
4
text.lua
|
@ -102,11 +102,9 @@ function Text.compute_fragments(line, line_width)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.textinput(t)
|
function Text.textinput(t)
|
||||||
if love.mouse.isDown('1') then return end
|
if love.mouse.isDown('1') then return end
|
||||||
if Lines[Cursor_line].mode == 'drawing' then return end
|
|
||||||
Text.insert_at_cursor(t)
|
Text.insert_at_cursor(t)
|
||||||
save_to_disk(Lines, Filename)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.insert_at_cursor(t)
|
function Text.insert_at_cursor(t)
|
||||||
|
|
Loading…
Reference in New Issue