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_line_numbers thenApp.color(Line_number_color)love.graphics.print(line_index, State.left-Line_number_width*App.width('m')+10,y)endinitialize_color()local line = State.lines[line_index]local line_cache = State.line_cache[line_index]line_cache.starty = yline_cache.startpos = startpos
Line_number_color = {r=0.6, g=0.6, b=0.6}left = math.floor(left), -- left margin for text; line numbers go to the left of thisedit.put_cursor_on_next_text_line(State)function edit.put_cursor_on_next_text_line(State)while true doif State.cursor1.line >= #State.lines thenbreakendif State.lines[State.cursor1.line].mode == 'text' thenbreakendState.cursor1.line = State.cursor1.line+1State.cursor1.pos = 1function edit.draw(State, hide_cursor, show_line_numbers)local buttonx = State.left-Margin_left+4if show_line_numbers thenbuttonx = 4 -- HACK: position draw buttons at a fixed x on screenendbutton(State, 'draw', {x=buttonx, y=y+4, w=12,h=12, color={1,1,0},y, screen_bottom1.pos = Text.draw(State, line_index, y, startpos, hide_cursor, show_line_numbers)edit.put_cursor_on_next_text_line(State)edit.put_cursor_on_next_text_line(State)for i=1,math.floor(-dy) doText.down(State)endfor i=1,math.floor(dy) doText.up(State)endelseif dy < 0 thenState.cursor1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos}--? print('=> y', y)elseif line.mode == 'drawing' theny = y+Drawing_padding_topDrawing.draw(State, line_index, y)y = y + Drawing.pixels(line.h, State.width) + Drawing_padding_bottomelseprint(line.mode)assert(false)icon = icon.insert_drawing,onpress1 = function()Drawing.before = snapshot(State, line_index-1, line_index)table.insert(State.lines, line_index, {mode='drawing', y=y, h=256/2, points={}, shapes={}, pending={}})table.insert(State.line_cache, line_index, {})if State.cursor1.line >= line_index thenState.cursor1.line = State.cursor1.line+1endschedule_save(State)record_undo_event(State, {before=Drawing.before, after=snapshot(State, line_index-1, line_index+1)})end,})State.button_handlers = {}App.color(Text_color)endendendendfunction edit.invalid1(State, loc1)right = math.floor(right),Icon_color = {r=0.7, g=0.7, b=0.7} -- color of current mode icon in drawingsHelp_color = {r=0, g=0.5, b=0}Help_background_color = {r=0, g=0.5, b=0, a=0.1}
Line_number_width = 3 -- in emslove.window.setTitle('text.love - source - '..Editor_state.filename)Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), right, settings.font_height, math.floor(settings.font_height*1.3))Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), App.screen.width-Margin_right)edit.draw(Editor_state, --[[hide cursor?]] Show_file_navigator, --[[show line numbers]] true)if Show_log_browser_side then-- dividerApp.color(Divider_color)love.graphics.rectangle('fill', App.screen.width/2-1,Menu_status_bar_height, 3,App.screen.height)--Editor_state.filename = 'run.lua'Editor_state.filename = settings.filename-- called both in tests and real runfunction source.initialize_globals()-- tests currently mostly clear their own stateShow_log_browser_side = falseFocus = 'edit'Show_file_navigator = falseFile_navigation = {
local r = round(geom.dist(center.x, center.y, mx, my))love.graphics.circle('line', cx,cy, Drawing.pixels(r, width))if line_cache.starty == nil then-- some event cleared starty just this frame-- draw in this frame will soon set starty-- just skip this framereturnendfunction Drawing.mouse_release(State, x,y, mouse_button)assert(drawing.mode == 'drawing')local pmx, pmy = App.mouse_x(), App.mouse_y()local mx = Drawing.coord(pmx-State.left, State.width)local my = Drawing.coord(pmy-line_cache.starty, State.width)if App.mouse_down(1) thenif Drawing.in_drawing(drawing, line_cache, pmx,pmy, State.left,State.right) thenif drawing.pending.mode == 'freehand' thentable.insert(drawing.pending.points, {x=mx, y=my})elseif drawing.pending.mode == 'move' thendrawing.pending.target_point.x = mxdrawing.pending.target_point.y = myDrawing.relax_constraints(drawing, drawing.pending.target_point_index)endendelseif State.current_drawing_mode == 'move' thenif Drawing.in_drawing(drawing, line_cache, pmx, pmy, State.left,State.right) thendrawing.pending.target_point.x = mxdrawing.pending.target_point.y = myDrawing.relax_constraints(drawing, drawing.pending.target_point_index)endelse-- do nothingendendfunction Drawing.relax_constraints(drawing, p)for _,shape in ipairs(drawing.shapes) doif shape.mode == 'manhattan' thenif shape.p1 == p thenshape.mode = 'line'elseif shape.p2 == p thenshape.mode = 'line'endelseif shape.mode == 'rectangle' or shape.mode == 'square' thenfor _,v in ipairs(shape.vertices) doif v == p thenshape.mode = 'polygon'endendendendendfunction Drawing.mouse_press(State, drawing_index, x,y, mouse_button)elseif shape.mode == 'arc' thenlocal center = drawing.points[shape.center]if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h thenreturnendshape.end_angle = geom.angle_with_hint(center.x,center.y, mx,my, shape.end_angle)local cx,cy = px(center.x), py(center.y)love.graphics.arc('line', 'open', cx,cy, Drawing.pixels(shape.radius, width), shape.start_angle, shape.end_angle, 360)elseif shape.mode == 'move' then-- nothing pending; changes are immediately committedelseif shape.mode == 'name' then-- nothing pending; changes are immediately committedelseprint(shape.mode)assert(false)endendfunction Drawing.in_drawing(drawing, line_cache, x,y, left,right)if line_cache.starty == nil then return false end -- outside current pagelocal width = right-leftreturn y >= line_cache.starty and y < line_cache.starty + Drawing.pixels(drawing.h, width) and x >= left and x < rightendlocal cx,cy = px(center.x), py(center.y)
source.switch_to_file(s..'.lua')love.window.setTitle('lines.love - source - '..Editor_state.filename)reset_file_navigator()endfunction move_candidate_to_front(s)local index = array.find(File_navigation.all_candidates, s)assert(index)table.remove(File_navigation.all_candidates, index)table.insert(File_navigation.all_candidates, 1, s)endfunction reset_file_navigator()Show_file_navigator = falseFile_navigation.index = 1File_navigation.filter = ''File_navigation.candidates = File_navigation.all_candidatesend