keep drawings within the line width slider as well

This commit is contained in:
Kartik K. Agaram 2022-06-22 21:08:17 -07:00
parent 39913ddbb8
commit 515dad95f9
3 changed files with 30 additions and 29 deletions

View File

@ -8,13 +8,13 @@ require 'drawing_tests'
-- into 256 parts.
function Drawing.draw(line)
local pmx,pmy = App.mouse_x(), App.mouse_y()
if pmx < Margin_left+Line_width and pmy > line.y and pmy < line.y+Drawing.pixels(line.h) then
if pmx < Line_width and pmy > line.y and pmy < line.y+Drawing.pixels(line.h) then
love.graphics.setColor(0.75,0.75,0.75)
love.graphics.rectangle('line', Margin_left,line.y, Line_width,Drawing.pixels(line.h))
love.graphics.rectangle('line', Margin_left,line.y, Line_width-Margin_left,Drawing.pixels(line.h))
if icon[Current_drawing_mode] then
icon[Current_drawing_mode](Margin_left+Line_width-22, line.y+4)
icon[Current_drawing_mode](Line_width-22, line.y+4)
else
icon[Previous_drawing_mode](Margin_left+Line_width-22, line.y+4)
icon[Previous_drawing_mode](Line_width-22, line.y+4)
end
if App.mouse_down(1) and love.keyboard.isDown('h') then
@ -204,7 +204,7 @@ end
function Drawing.in_drawing(drawing, x,y)
if drawing.y == nil then return false end -- outside current page
return y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= Margin_left and x < Margin_left+Line_width
return y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= Margin_left and x < Line_width
end
function Drawing.mouse_pressed(drawing, x,y, button)
@ -685,10 +685,10 @@ function Drawing.near(point, x,y)
end
function Drawing.pixels(n) -- parts to pixels
return math.floor(n*Line_width/256)
return math.floor(n*(Line_width-Margin_left)/256)
end
function Drawing.coord(n) -- pixels to parts
return math.floor(n*256/Line_width)
return math.floor(n*256/(Line_width-Margin_left))
end
function table.find(h, x)

View File

@ -26,7 +26,7 @@ function test_draw_line()
Filename = 'foo'
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
check_eq(#Lines, 2, 'F - test_draw_line/baseline/#lines')
@ -70,7 +70,7 @@ function test_draw_horizontal_line()
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'manhattan'
App.draw()
check_eq(#Lines, 2, 'F - test_draw_horizontal_line/baseline/#lines')
@ -98,7 +98,7 @@ function test_draw_circle()
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
check_eq(#Lines, 2, 'F - test_draw_circle/baseline/#lines')
@ -126,7 +126,7 @@ function test_keys_do_not_affect_shape_when_mouse_up()
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
-- hover over drawing and press 'o' without holding mouse
@ -142,7 +142,7 @@ function test_draw_circle_mid_stroke()
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
check_eq(#Lines, 2, 'F - test_draw_circle_mid_stroke/baseline/#lines')
@ -170,7 +170,7 @@ function test_draw_arc()
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'circle'
App.draw()
check_eq(#Lines, 2, 'F - test_draw_arc/baseline/#lines')
@ -201,7 +201,7 @@ function test_draw_polygon()
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
App.draw()
check_eq(Current_drawing_mode, 'line', 'F - test_draw_polygon/baseline/drawing_mode')
check_eq(#Lines, 2, 'F - test_draw_polygon/baseline/#lines')
@ -239,7 +239,7 @@ function test_draw_rectangle()
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
App.draw()
check_eq(Current_drawing_mode, 'line', 'F - test_draw_rectangle/baseline/drawing_mode')
check_eq(#Lines, 2, 'F - test_draw_rectangle/baseline/#lines')
@ -283,7 +283,7 @@ function test_draw_rectangle_intermediate()
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
App.draw()
check_eq(Current_drawing_mode, 'line', 'F - test_draw_rectangle_intermediate/baseline/drawing_mode')
check_eq(#Lines, 2, 'F - test_draw_rectangle_intermediate/baseline/#lines')
@ -319,7 +319,7 @@ function test_draw_square()
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
App.draw()
check_eq(Current_drawing_mode, 'line', 'F - test_draw_square/baseline/drawing_mode')
check_eq(#Lines, 2, 'F - test_draw_square/baseline/#lines')
@ -363,7 +363,7 @@ function test_name_point()
Filename = 'foo'
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
-- draw a line
@ -406,7 +406,7 @@ function test_move_point()
Filename = 'foo'
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
@ -463,7 +463,7 @@ function test_move_point_on_manhattan_line()
Filename = 'foo'
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'manhattan'
App.draw()
App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
@ -489,7 +489,7 @@ function test_delete_lines_at_point()
Filename = 'foo'
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
@ -518,7 +518,7 @@ function test_delete_line_under_mouse_pointer()
-- create a drawing with two lines connected at a point
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
@ -542,7 +542,7 @@ function test_delete_point_from_polygon()
-- create a drawing with two lines connected at a point
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
-- first point
@ -573,7 +573,7 @@ function test_delete_point_from_polygon()
-- create a drawing with two lines connected at a point
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
-- first point
@ -601,7 +601,7 @@ function test_undo_name_point()
Filename = 'foo'
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
-- draw a line
@ -647,7 +647,7 @@ function test_undo_move_point()
Filename = 'foo'
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
@ -697,7 +697,7 @@ function test_undo_delete_point()
Filename = 'foo'
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Line_width = Margin_left+256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)

View File

@ -530,7 +530,8 @@ end
function test_pagedown_skips_drawings()
io.write('\ntest_pagedown_skips_drawings')
-- some lines of text with a drawing intermixed
App.screen.init{width=50, height=80}
local drawing_width = 50
App.screen.init{width=Margin_left+drawing_width, height=80}
Lines = load_array{'abc', -- height 15
'```lines', '```', -- height 25
'def', -- height 15
@ -540,7 +541,7 @@ function test_pagedown_skips_drawings()
Cursor1 = {line=1, pos=1}
Screen_top1 = {line=1, pos=1}
Screen_bottom1 = {}
local drawing_height = Drawing_padding_height + App.screen.width / 2 -- default
local drawing_height = Drawing_padding_height + drawing_width/2 -- default
-- initially the screen displays the first line and the drawing
-- 15px margin + 15px line1 + 10px margin + 25px drawing + 10px margin = 75px < screen height 80px
App.draw()