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hide_cursor, show_line_numbers)
if show_line_numbers then
App.color(Line_number_color)
love.graphics.print(line_index, State.left-Line_number_width*App.width('m')+10,y)
end
initialize_color()
local line = State.lines[line_index]
local line_cache = State.line_cache[line_index]
line_cache.starty = y
line_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 this
edit.put_cursor_on_next_text_line(State)
function edit.put_cursor_on_next_text_line(State)
while true do
if State.cursor1.line >= #State.lines then
break
end
if State.lines[State.cursor1.line].mode == 'text' then
break
end
State.cursor1.line = State.cursor1.line+1
State.cursor1.pos = 1
function edit.draw(State, hide_cursor, show_line_numbers)
local buttonx = State.left-Margin_left+4
if show_line_numbers then
buttonx = 4 -- HACK: position draw buttons at a fixed x on screen
end
button(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) do
Text.down(State)
end
for i=1,math.floor(dy) do
Text.up(State)
end
elseif dy < 0 then
State.cursor1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos}
--? print('=> y', y)
elseif line.mode == 'drawing' then
y = y+Drawing_padding_top
Drawing.draw(State, line_index, y)
y = y + Drawing.pixels(line.h, State.width) + Drawing_padding_bottom
else
print(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 then
State.cursor1.line = State.cursor1.line+1
end
schedule_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)
end
end
end
end
function 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 drawings
Help_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 ems
love.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
-- divider
App.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 run
function source.initialize_globals()
-- tests currently mostly clear their own state
Show_log_browser_side = false
Focus = 'edit'
Show_file_navigator = false
File_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 frame
return
end
function 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) then
if Drawing.in_drawing(drawing, line_cache, pmx,pmy, State.left,State.right) then
if drawing.pending.mode == 'freehand' then
table.insert(drawing.pending.points, {x=mx, y=my})
elseif drawing.pending.mode == 'move' then
drawing.pending.target_point.x = mx
drawing.pending.target_point.y = my
Drawing.relax_constraints(drawing, drawing.pending.target_point_index)
end
end
elseif State.current_drawing_mode == 'move' then
if Drawing.in_drawing(drawing, line_cache, pmx, pmy, State.left,State.right) then
drawing.pending.target_point.x = mx
drawing.pending.target_point.y = my
Drawing.relax_constraints(drawing, drawing.pending.target_point_index)
end
else
-- do nothing
end
end
function Drawing.relax_constraints(drawing, p)
for _,shape in ipairs(drawing.shapes) do
if shape.mode == 'manhattan' then
if shape.p1 == p then
shape.mode = 'line'
elseif shape.p2 == p then
shape.mode = 'line'
end
elseif shape.mode == 'rectangle' or shape.mode == 'square' then
for _,v in ipairs(shape.vertices) do
if v == p then
shape.mode = 'polygon'
end
end
end
end
end
function Drawing.mouse_press(State, drawing_index, x,y, mouse_button)
elseif shape.mode == 'arc' then
local center = drawing.points[shape.center]
if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
return
end
shape.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 committed
elseif shape.mode == 'name' then
-- nothing pending; changes are immediately committed
else
print(shape.mode)
assert(false)
end
end
function Drawing.in_drawing(drawing, line_cache, x,y, left,right)
if line_cache.starty == nil then return false end -- outside current page
local width = right-left
return y >= line_cache.starty and y < line_cache.starty + Drawing.pixels(drawing.h, width) and x >= left and x < right
end
local 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()
end
function 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)
end
function reset_file_navigator()
Show_file_navigator = false
File_navigation.index = 1
File_navigation.filter = ''
File_navigation.candidates = File_navigation.all_candidates
end