split mouse_pressed events between Text and Drawing

[?]
May 18, 2022, 5:53 AM
HYEAFRZ2UEKDYTAE2GDQLHEJBPQASP2NDLMXB7F6MTVK2BKOXKEAC

Dependencies

  • [2] BULPIBEG beginnings of a module for the text editor
  • [3] EX3GRC2K bugfix typo
  • [4] VHQCNMAR several more modules
  • [5] V5TP27FP ctrl-+ and ctrl-- to adjust font size
  • [6] MGOQ5XAV start uppercasing globals
  • [7] XNFTJHC4 split keyboard handling between Text and Drawing
  • [8] AVQ5MC5D finish uppercasing all globals
  • [9] 2INHXC3K position cursor by clicking on text
  • [10] 7IKRRESB longer names for indices in long loops
  • [11] ZUOL7X6V move
  • [*] OTIBCAUJ love2d scaffold
  • [*] BLWAYPKV extract a module

Change contents

  • edit in text.lua at line 144
    [2.464]
    [2.464]
    end
    function Text.in_line(line, x,y)
    return x >= 16 and y >= line.y and y < line.y+15*Zoom
    end
    function Text.move_cursor(line_index, line, x, hint)
    Cursor_line = line_index
    Cursor_pos = Text.nearest_cursor_pos(line.data, x)
  • replacement in text.lua at line 163
    [2.643][2.643:739]()
    local currx = Text.cursor_x(line, hint)
    if currx > x-2 and currx < x+2 then
    return hint
    [2.643]
    [2.739]
    if hint then
    local currx = Text.cursor_x(line, hint)
    if currx > x-2 and currx < x+2 then
    return hint
    end
  • replacement in text.lua at line 170
    [2.778][2.778:838]()
    if currx > x then
    right = hint
    else
    left = hint
    [2.778]
    [2.838]
    if hint then
    if currx > x then
    right = hint
    else
    left = hint
    end
  • replacement in main.lua at line 161
    [5.208][5.208:229](),[5.229][3.74:135](),[3.135][5.347:380](),[5.1934][5.347:380](),[5.380][2.1578:1640]()
    -- move cursor
    if x >= 16 and y >= line.y and y < line.y+15*Zoom then
    Cursor_line = line_index
    Cursor_pos = Text.nearest_cursor_pos(line.data, x, 1)
    [5.208]
    [5.361]
    if Text.in_line(line, x,y) then
    Text.move_cursor(line_index, line, x)
  • replacement in main.lua at line 165
    [5.410][5.410:437](),[5.437][5.76:132](),[5.76][5.76:132](),[5.132][4.726:1722](),[4.1722][5.955:967](),[5.2601][5.955:967](),[5.955][5.955:967](),[5.967][5.537:569]()
    local drawing = line
    local x, y = love.mouse.getX(), love.mouse.getY()
    if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
    if Current_drawing_mode == 'freehand' then
    drawing.pending = {mode=Current_drawing_mode, points={{x=Drawing.coord(x-16), y=Drawing.coord(y-drawing.y)}}}
    elseif Current_drawing_mode == 'line' or Current_drawing_mode == 'manhattan' then
    local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))
    drawing.pending = {mode=Current_drawing_mode, p1=j}
    elseif Current_drawing_mode == 'polygon' then
    local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))
    drawing.pending = {mode=Current_drawing_mode, vertices={j}}
    elseif Current_drawing_mode == 'circle' then
    local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))
    drawing.pending = {mode=Current_drawing_mode, center=j}
    end
    Lines.current = drawing
    [5.410]
    [5.999]
    if Drawing.in_drawing(line, x, y) then
    Drawing.mouse_pressed(line, x,y, button)
  • edit in drawing.lua at line 50
    [4.19072]
    [4.19072]
    end
    function Drawing.in_drawing(drawing, x,y)
    return y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width
    end
    function Drawing.mouse_pressed(drawing, x,y, button)
    if Current_drawing_mode == 'freehand' then
    drawing.pending = {mode=Current_drawing_mode, points={{x=Drawing.coord(x-16), y=Drawing.coord(y-drawing.y)}}}
    elseif Current_drawing_mode == 'line' or Current_drawing_mode == 'manhattan' then
    local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))
    drawing.pending = {mode=Current_drawing_mode, p1=j}
    elseif Current_drawing_mode == 'polygon' then
    local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))
    drawing.pending = {mode=Current_drawing_mode, vertices={j}}
    elseif Current_drawing_mode == 'circle' then
    local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))
    drawing.pending = {mode=Current_drawing_mode, center=j}
    end
    Lines.current = drawing