split mouse_pressed events between Text and Drawing
[?]
May 18, 2022, 5:53 AM
HYEAFRZ2UEKDYTAE2GDQLHEJBPQASP2NDLMXB7F6MTVK2BKOXKEACDependencies
- [2]
BULPIBEGbeginnings of a module for the text editor - [3]
EX3GRC2Kbugfix typo - [4]
VHQCNMARseveral more modules - [5]
V5TP27FPctrl-+ and ctrl-- to adjust font size - [6]
MGOQ5XAVstart uppercasing globals - [7]
XNFTJHC4split keyboard handling between Text and Drawing - [8]
AVQ5MC5Dfinish uppercasing all globals - [9]
2INHXC3Kposition cursor by clicking on text - [10]
7IKRRESBlonger names for indices in long loops - [11]
ZUOL7X6Vmove - [*]
OTIBCAUJlove2d scaffold - [*]
BLWAYPKVextract a module
Change contents
- edit in text.lua at line 144
endfunction Text.in_line(line, x,y)return x >= 16 and y >= line.y and y < line.y+15*Zoomendfunction Text.move_cursor(line_index, line, x, hint)Cursor_line = line_indexCursor_pos = Text.nearest_cursor_pos(line.data, x) - replacement in text.lua at line 163
local currx = Text.cursor_x(line, hint)if currx > x-2 and currx < x+2 thenreturn hintif hint thenlocal currx = Text.cursor_x(line, hint)if currx > x-2 and currx < x+2 thenreturn hintend - replacement in text.lua at line 170
if currx > x thenright = hintelseleft = hintif hint thenif currx > x thenright = hintelseleft = hintend - 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 cursorif x >= 16 and y >= line.y and y < line.y+15*Zoom thenCursor_line = line_indexCursor_pos = Text.nearest_cursor_pos(line.data, x, 1)if Text.in_line(line, x,y) thenText.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 = linelocal 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 thenif Current_drawing_mode == 'freehand' thendrawing.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' thenlocal 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' thenlocal 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' thenlocal j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))drawing.pending = {mode=Current_drawing_mode, center=j}endLines.current = drawingif Drawing.in_drawing(line, x, y) thenDrawing.mouse_pressed(line, x,y, button) - edit in drawing.lua at line 50
endfunction 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_widthendfunction Drawing.mouse_pressed(drawing, x,y, button)if Current_drawing_mode == 'freehand' thendrawing.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' thenlocal 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' thenlocal 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' thenlocal j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))drawing.pending = {mode=Current_drawing_mode, center=j}endLines.current = drawing