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23RGW3BAKTAE7P73ASBYNKOHMQMH5AC 3QNOKBFMKBGXBVJIRHR2444JRRMBTABHE4674NR3DT67RRM2X6GAC IZGZEWFGSMVXXFGMBITHUZUSFAJGWZNBE7LR7PCZ52P2JEO5HAUQC 4HAEKSJVXYUDFYJVYI5BYANWLOMFL74W4Y4YEUCZVEVBXOUFDYNQC name_width = State.font:getWidth('m')name_width = State.font:getWidth(p.name)endelse
function draw_help_without_mouse_pressed(State, drawing_index)local drawing = State.lines[drawing_index]local line_cache = State.line_cache[drawing_index]App.color(Help_color)local y = line_cache.starty+10love.graphics.print("Things you can do:", State.left+30,y)y = y + State.line_heightlove.graphics.print("* Press the mouse button to start drawing a "..current_shape(State), State.left+30,y)y = y + State.line_heightlove.graphics.print("* Hover on a point and press 'ctrl+u' to pick it up and start moving it,", State.left+30,y)y = y + State.line_heightlove.graphics.print("then press the mouse button to drop it", State.left+30+State.font:getWidth('* '),y)y = y + State.line_heightlove.graphics.print("* Hover on a point and press 'ctrl+n', type a name, then press 'enter'", State.left+30,y)y = y + State.line_heightlove.graphics.print("* Hover on a point or shape and press 'ctrl+d' to delete it", State.left+30,y)y = y + State.line_heightif State.current_drawing_mode ~= 'freehand' thenlove.graphics.print("* Press 'ctrl+p' to switch to drawing freehand strokes", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'line' thenlove.graphics.print("* Press 'ctrl+l' to switch to drawing lines", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'manhattan' thenlove.graphics.print("* Press 'ctrl+m' to switch to drawing horizontal/vertical lines", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'circle' thenlove.graphics.print("* Press 'ctrl+o' to switch to drawing circles/arcs", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'polygon' thenlove.graphics.print("* Press 'ctrl+g' to switch to drawing polygons", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'rectangle' thenlove.graphics.print("* Press 'ctrl+r' to switch to drawing rectangles", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'square' thenlove.graphics.print("* Press 'ctrl+s' to switch to drawing squares", State.left+30,y)y = y + State.line_heightendlove.graphics.print("* Press 'ctrl+=' or 'ctrl+-' to zoom in or out, ctrl+0 to reset zoom", State.left+30,y)y = y + State.line_heightlove.graphics.print("Press 'esc' now to hide this message", State.left+30,y)y = y + State.line_heightApp.color(Help_background_color)love.graphics.rectangle('fill', State.left,line_cache.starty, State.width, math.max(Drawing.pixels(drawing.h, State.width),y-line_cache.starty))endfunction draw_help_with_mouse_pressed(State, drawing_index)local drawing = State.lines[drawing_index]local line_cache = State.line_cache[drawing_index]App.color(Help_color)local y = line_cache.starty+10love.graphics.print("You're currently drawing a "..current_shape(State, drawing.pending), State.left+30,y)y = y + State.line_heightlove.graphics.print('Things you can do now:', State.left+30,y)y = y + State.line_heightif State.current_drawing_mode == 'freehand' thenlove.graphics.print('* Release the mouse button to finish drawing the stroke', State.left+30,y)y = y + State.line_heightelseif State.current_drawing_mode == 'line' or State.current_drawing_mode == 'manhattan' thenlove.graphics.print('* Release the mouse button to finish drawing the line', State.left+30,y)y = y + State.line_heightelseif State.current_drawing_mode == 'circle' thenif drawing.pending.mode == 'circle' thenlove.graphics.print('* Release the mouse button to finish drawing the circle', State.left+30,y)y = y + State.line_heightlove.graphics.print("* Press 'a' to draw just an arc of a circle", State.left+30,y)elselove.graphics.print('* Release the mouse button to finish drawing the arc', State.left+30,y)endy = y + State.line_heightelseif State.current_drawing_mode == 'polygon' thenlove.graphics.print('* Release the mouse button to finish drawing the polygon', State.left+30,y)y = y + State.line_heightlove.graphics.print("* Press 'p' to add a vertex to the polygon", State.left+30,y)y = y + State.line_heightelseif State.current_drawing_mode == 'rectangle' thenif #drawing.pending.vertices < 2 thenlove.graphics.print("* Press 'p' to add a vertex to the rectangle", State.left+30,y)y = y + State.line_heightelselove.graphics.print('* Release the mouse button to finish drawing the rectangle', State.left+30,y)y = y + State.line_heightlove.graphics.print("* Press 'p' to replace the second vertex of the rectangle", State.left+30,y)y = y + State.line_heightendelseif State.current_drawing_mode == 'square' thenif #drawing.pending.vertices < 2 thenlove.graphics.print("* Press 'p' to add a vertex to the square", State.left+30,y)y = y + State.line_heightelselove.graphics.print('* Release the mouse button to finish drawing the square', State.left+30,y)y = y + State.line_heightlove.graphics.print("* Press 'p' to replace the second vertex of the square", State.left+30,y)y = y + State.line_heightendendlove.graphics.print("* Press 'esc' then release the mouse button to cancel the current shape", State.left+30,y)y = y + State.line_heighty = y + State.line_heightif State.current_drawing_mode ~= 'line' thenlove.graphics.print("* Press 'l' to switch to drawing lines", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'manhattan' thenlove.graphics.print("* Press 'm' to switch to drawing horizontal/vertical lines", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'circle' thenlove.graphics.print("* Press 'o' to switch to drawing circles/arcs", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'polygon' thenlove.graphics.print("* Press 'g' to switch to drawing polygons", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'rectangle' thenlove.graphics.print("* Press 'r' to switch to drawing rectangles", State.left+30,y)y = y + State.line_heightendif State.current_drawing_mode ~= 'square' thenlove.graphics.print("* Press 's' to switch to drawing squares", State.left+30,y)y = y + State.line_heightendApp.color(Help_background_color)love.graphics.rectangle('fill', State.left,line_cache.starty, State.width, math.max(Drawing.pixels(drawing.h, State.width),y-line_cache.starty))endfunction current_shape(State, shape)if State.current_drawing_mode == 'freehand' thenreturn 'freehand stroke'elseif State.current_drawing_mode == 'line' thenreturn 'straight line'elseif State.current_drawing_mode == 'manhattan' thenreturn 'horizontal/vertical line'elseif State.current_drawing_mode == 'circle' and shape and shape.start_angle thenreturn 'arc'elsereturn State.current_drawing_modeendend
lo_px = State.font:getWidth(before)love.graphics.rectangle('fill', x+lo_px,y, State.font:getWidth(s),State.line_height)App.color(Text_color)return lo_pxendendend
love.graphics.print(line_index, State.left-Line_number_width*State.font:getWidth('m')+10,y)local lo, hi = Text.clip_wikiword_with_screen_line(State.font, line, line_cache, i, s, e)Text.draw_cursor(State, State.left+Text.x(State.font, screen_line, State.cursor1.pos-pos+1), y)Text.draw_cursor(State, State.left+Text.x(State.font, screen_line, State.cursor1.pos-pos+1), y)x = x+State.font:getWidth(frag)local frag_width = State.font:getWidth(frag)local bpos = Text.nearest_pos_less_than(State.font, frag, State.width - x)frag_width = State.font:getWidth(frag)function Text.clip_wikiword_with_screen_line(font, line, line_cache, i, s, e)return font:getWidth(line.data:sub(soff, loff-1)), font:getWidth(line.data:sub(soff, hoff))State.cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, State.cursor_x, State.left) - 1State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, State.cursor_x, State.left) - 1pos = Text.nearest_cursor_pos(State.font, State.lines[new_cursor_line].data, State.cursor_x, State.left),State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, State.cursor_x, State.left) - 1--? print('return', mx, Text.nearest_cursor_pos(State.font, s, mx, State.left), '=>', screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, mx, State.left) - 1)return screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, mx, State.left) - 1return State.font:getWidth(screen_line)function Text.nearest_cursor_pos(font, line, x, left)local max_x = left+Text.x(font, line, len+1)local currxmin = left+Text.x(font, line, curr)local currxmax = left+Text.x(font, line, curr+1)function Text.nearest_pos_less_than(font, line, x)local max_x = Text.x_after(font, line, len)local currxmin = Text.x_after(font, line, curr+1)local currxmax = Text.x_after(font, line, curr+2)function Text.x_after(font, s, pos)return font:getWidth(s_before)function Text.x(font, s, pos)return font:getWidth(s_before)endfunction Text.to2(State, loc1)local offset = Text.offset(s, pos)local s_before = s:sub(1, offset-1)endlocal len = utf8.len(s)local offset = Text.offset(s, math.min(pos+1, len+1))--? print('', x, left, right, curr, currxmin, currxmax)if currxmin <= x and x < currxmax thenreturn currendif left >= right-1 thenreturn leftendif currxmin > x thenright = currelseleft = currendendif x > max_x thenreturn len+1endlocal left, right = 0, len+1while true dolocal curr = math.floor((left+right)/2)--? print('', '-- nearest_pos_less_than', line, x)local len = utf8.len(line)--? print('nearest', x, leftpos, rightpos, curr, currxmin, currxmax)if currxmin <= x and x < currxmax thenif x-currxmin < currxmax-x thenreturn currelsereturn curr+1endendif leftpos >= rightpos-1 thenreturn rightposendif currxmin > x thenrightpos = currelseleftpos = currendendif x > max_x thenreturn len+1endlocal leftpos, rightpos = 1, len+1--? print('-- nearest', x)while true do--? print('nearest', x, '^'..line..'$', leftpos, rightpos)if leftpos == rightpos thenreturn leftposendlocal curr = math.floor((leftpos+rightpos)/2)if x < left thenreturn 1endlocal len = utf8.len(line)endendy = nextyend--? print('cursor pos is now', State.cursor1.line, State.cursor1.pos)if scroll_down then--? print('scroll up preserving cursor')Text.snap_cursor_to_bottom_of_screen(State)--? print('screen top after:', State.screen_top1.line, State.screen_top1.pos)end}--? print(State.cursor1.pos)breakend--? print('cursor pos is now '..tostring(State.cursor1.pos))endif Text.lt1(State.cursor1, State.screen_top1) thenbreakendendlocal spos = line_cache.screen_line_starting_pos[i]local soff = Text.offset(line.data, spos)if e < soff thenreturnendlocal eoffif i < #line_cache.screen_line_starting_pos thenlocal epos = line_cache.screen_line_starting_pos[i+1]eoff = Text.offset(line.data, epos)if s > eoff thenreturnend--? print('screen line:', pos)if x == 0 and bpos == 0 thenassert(false, ("Infinite loop while line-wrapping. Editor is %dpx wide; window is %dpx wide"):format(State.width, App.screen.width))end--? print('-- frag:', frag, pos, x, frag_width, State.width)while x + frag_width > State.width do--? print('frag:', frag, pos, x, frag_width, State.width)if x < 0.8 * State.width then-- long word; chop it at some letter-- We're not going to reimplement TeX here.endendendendelseif pos + frag_len == State.cursor1.pos then-- Show cursor at end of line.-- This place also catches end of wrapping screen lines. That doesn't seem worth distinguishing.-- It seems useful to see a cursor whether your eye is on the left or right margin.if lo thenend
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*font:getWidth('m'), right, font, settings.font_height, math.floor(settings.font_height*1.3))Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*font:getWidth('m'), App.screen.width-Margin_right, font, font_height, math.floor(font_height*1.3))Editor_state.filename = 'run.lua'Editor_state.filename = settings.filename
love.graphics.line(xleft+50+State.font:getWidth(line.section_name)+2,sectiony, xright,sectiony)love.graphics.line(xleft+50+State.font:getWidth(line.section_name)+2,sectiony, xright,sectiony)love.graphics.print(line.section_stack[i].name, x+State.font_height+5, App.screen.height-State.font:getWidth(line.section_stack[i].name)-5, --[[vertically]] math.pi/2)love.graphics.print(line.section_stack[i].name, x, App.screen.height-State.font:getWidth(line.section_stack[i].name)-5, --[[vertically]] math.pi/2)endendreturn log_browser.right_margin(State, line)endfunction should_show(line)-- Show a line if every single section it's in is expanded.for i=1,#line.section_stack dolocal section = line.section_stack[i]if not section.expanded thenreturn falseendendreturn trueendfunction log_browser.left_margin(State, line)return State.left + #line.section_stack*Section_border_padding_horizontalendfunction log_browser.right_margin(State, line)return State.right - #line.section_stack*Section_border_padding_horizontalendfunction log_browser.update(State, dt)endfunction log_browser.quit(State)endendendreturn log_browser.left_margin(State, line)endfunction render_stack_right_margin(State, line_index, line, y)App.color(Section_border_color)for i=1,#line.section_stack dolocal x = State.right - (i-1)*Section_border_padding_horizontallove.graphics.line(x,y, x,y+log_browser.height(State, line_index))if y < 30 thenlove.graphics.print(line.section_stack[i].name, x, y+5, --[[vertically]] math.pi/2)endif y > App.screen.height-log_browser.height(State, line_index) thenendelseif type(line.data) == 'string' thenlocal old_left, old_right = State.left,State.rightState.left,State.right = xleft,xrightelse assert(line.section_end, "log line has a section name, but it's neither the start nor end of a section")
if Disable_all_quit_handlers then return endendfunction warning_message()assert(type(Current_app) == 'table')return Current_app.message