2022-09-03 21:13:22 +00:00
|
|
|
Menu_background_color = {r=0.6, g=0.8, b=0.6}
|
|
|
|
Menu_border_color = {r=0.6, g=0.7, b=0.6}
|
|
|
|
Menu_command_color = {r=0.2, g=0.2, b=0.2}
|
|
|
|
Menu_highlight_color = {r=0.5, g=0.7, b=0.3}
|
|
|
|
|
|
|
|
function source.draw_menu_bar()
|
|
|
|
if App.run_tests then return end -- disable in tests
|
|
|
|
App.color(Menu_background_color)
|
|
|
|
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_status_bar_height)
|
|
|
|
App.color(Menu_border_color)
|
|
|
|
love.graphics.rectangle('line', 0,0, App.screen.width, Menu_status_bar_height)
|
|
|
|
App.color(Menu_command_color)
|
|
|
|
Menu_cursor = 5
|
|
|
|
if Show_file_navigator then
|
|
|
|
source.draw_file_navigator()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
add_hotkey_to_menu('ctrl+e: run')
|
|
|
|
if Focus == 'edit' then
|
|
|
|
add_hotkey_to_menu('ctrl+g: switch file')
|
|
|
|
if Show_log_browser_side then
|
|
|
|
add_hotkey_to_menu('ctrl+l: hide log browser')
|
|
|
|
else
|
|
|
|
add_hotkey_to_menu('ctrl+l: show log browser')
|
|
|
|
end
|
|
|
|
if Editor_state.expanded then
|
2022-09-07 01:39:46 +00:00
|
|
|
add_hotkey_to_menu('alt+b: collapse debug prints')
|
2022-09-03 21:13:22 +00:00
|
|
|
else
|
2022-09-07 01:39:46 +00:00
|
|
|
add_hotkey_to_menu('alt+b: expand debug prints')
|
2022-09-03 21:13:22 +00:00
|
|
|
end
|
2022-09-07 01:39:46 +00:00
|
|
|
add_hotkey_to_menu('alt+d: create/edit debug print')
|
2022-09-03 21:13:22 +00:00
|
|
|
add_hotkey_to_menu('ctrl+f: find in file')
|
|
|
|
add_hotkey_to_menu('alt+left alt+right: prev/next word')
|
|
|
|
elseif Focus == 'log_browser' then
|
|
|
|
-- nothing yet
|
|
|
|
else
|
|
|
|
assert(false, 'unknown focus "'..Focus..'"')
|
|
|
|
end
|
|
|
|
add_hotkey_to_menu('ctrl+z ctrl+y: undo/redo')
|
|
|
|
add_hotkey_to_menu('ctrl+x ctrl+c ctrl+v: cut/copy/paste')
|
|
|
|
add_hotkey_to_menu('ctrl+= ctrl+- ctrl+0: zoom')
|
|
|
|
end
|
|
|
|
|
|
|
|
function add_hotkey_to_menu(s)
|
2022-09-18 06:01:40 +00:00
|
|
|
local s_text = to_text(s)
|
|
|
|
local width = App.width(s_text)
|
2022-09-03 21:13:22 +00:00
|
|
|
if Menu_cursor + width > App.screen.width - 5 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
App.color(Menu_command_color)
|
2022-09-18 06:01:40 +00:00
|
|
|
App.screen.draw(s_text, Menu_cursor,5)
|
2022-09-03 21:13:22 +00:00
|
|
|
Menu_cursor = Menu_cursor + width + 30
|
|
|
|
end
|
|
|
|
|
|
|
|
function source.draw_file_navigator()
|
2022-09-18 06:53:57 +00:00
|
|
|
if File_navigation.num_lines == nil then
|
|
|
|
File_navigation.num_lines = source.num_lines_for_file_navigator()
|
|
|
|
end
|
|
|
|
App.color(Menu_background_color)
|
|
|
|
love.graphics.rectangle('fill', 0,Menu_status_bar_height, App.screen.width, File_navigation.num_lines * Editor_state.line_height)
|
|
|
|
local x,y = 5, Menu_status_bar_height
|
2022-09-18 06:43:14 +00:00
|
|
|
for i,filename in ipairs(File_navigation.candidates) do
|
|
|
|
if filename == 'source' then
|
2022-09-03 21:13:22 +00:00
|
|
|
App.color(Menu_border_color)
|
|
|
|
love.graphics.line(Menu_cursor-10,2, Menu_cursor-10,Menu_status_bar_height-2)
|
|
|
|
end
|
2022-09-18 06:53:57 +00:00
|
|
|
x,y = add_file_to_menu(x,y, filename, i == File_navigation.index)
|
2022-09-18 06:05:08 +00:00
|
|
|
if Menu_cursor >= App.screen.width - 5 then
|
|
|
|
break
|
|
|
|
end
|
2022-09-03 21:13:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-18 06:53:57 +00:00
|
|
|
function source.num_lines_for_file_navigator()
|
|
|
|
local result = 1
|
|
|
|
local x = 5
|
|
|
|
for i,filename in ipairs(File_navigation.candidates) do
|
|
|
|
local width = App.width(to_text(filename))
|
|
|
|
if x + width > App.screen.width - 5 then
|
|
|
|
result = result+1
|
|
|
|
x = 5 + width
|
|
|
|
else
|
|
|
|
x = x + width + 30
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
|
|
|
function add_file_to_menu(x,y, s, cursor_highlight)
|
2022-09-18 06:01:40 +00:00
|
|
|
local s_text = to_text(s)
|
|
|
|
local width = App.width(s_text)
|
2022-09-18 06:53:57 +00:00
|
|
|
if x + width > App.screen.width - 5 then
|
|
|
|
y = y + Editor_state.line_height
|
|
|
|
x = 5
|
|
|
|
end
|
2022-09-03 21:13:22 +00:00
|
|
|
if cursor_highlight then
|
|
|
|
App.color(Menu_highlight_color)
|
2022-09-18 06:53:57 +00:00
|
|
|
love.graphics.rectangle('fill', x-5,y-2, width+5*2,Editor_state.line_height+2*2)
|
2022-09-03 21:13:22 +00:00
|
|
|
end
|
|
|
|
App.color(Menu_command_color)
|
2022-09-18 06:53:57 +00:00
|
|
|
App.screen.draw(s_text, x,y)
|
|
|
|
x = x + width + 30
|
|
|
|
return x,y
|
2022-09-03 21:13:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function keychord_pressed_on_file_navigator(chord, key)
|
|
|
|
if chord == 'escape' then
|
|
|
|
Show_file_navigator = false
|
|
|
|
elseif chord == 'return' then
|
|
|
|
local candidate = guess_source(File_navigation.candidates[File_navigation.index]..'.lua')
|
|
|
|
source.switch_to_file(candidate)
|
|
|
|
Show_file_navigator = false
|
|
|
|
elseif chord == 'left' then
|
|
|
|
if File_navigation.index > 1 then
|
|
|
|
File_navigation.index = File_navigation.index-1
|
|
|
|
end
|
|
|
|
elseif chord == 'right' then
|
|
|
|
if File_navigation.index < #File_navigation.candidates then
|
|
|
|
File_navigation.index = File_navigation.index+1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|