3
-- - Control-Alt-F toggles fullscreen
4
-- - Control-Alt-Q quits the app.
5
-- - Control-Alt-P deactivates the view.
6
-- - Control-Alt-S saves a screenshot to the app's directory --
7
-- see https://love2d.org/wiki/love.filesystem for where this is.
9
DebugShortcuts = DebugInstrument:extend
14
-- Property: modifiers
15
-- A table of modifier keys that must be held in order to activate
16
-- a debugging hotkey (set via <add()>). If you want hotkeys to
17
-- activate without having to hold any keys down, set this to nil.
18
modifiers = {'ctrl', 'alt'},
20
-- internal property: _shortcuts
21
-- A table with entries that have desc (long description), key
22
-- (triggering key) and func (function to run) properties.
25
-- internal property: _buttons
26
-- An ordered table of shortcut buttons.
29
onNew = function (self)
30
self.title.text = 'Shortcuts'
32
self:addShortcut('Fullscreen', 'f', function() the.app:toggleFullscreen() end)
34
self:addShortcut('Pause', 'p', function()
35
the.view.active = not the.view.active
36
if the.view.active then
39
the.view:tint(0, 0, 0, 200)
43
self:addShortcut('Quit', 'q', love.event.quit)
45
self:addShortcut('Reload Code', 'r', debugger.reload)
47
self:addShortcut('Save Screenshot', 's', function()
48
if debugger.console.visible then
49
debugger.hideConsole()
50
the.view.timer:after(0.05, bind(the.app, 'saveScreenshot', 'screenshot.png'))
51
the.view.timer:after(0.1, debugger.showConsole)
53
the.app:saveScreenshot('screenshot.png')
57
debugger.addListener(bind(self, 'listen'))
58
debugger.addShortcut = function (desc, key, func) self:addShortcut(desc, key, func) end
59
debugger.setShortcutModifiers = function (...) self.modifiers = {...} end
62
addShortcut = function (self, desc, key, func)
63
table.insert(self._shortcuts, { desc = desc, key = key, func = func })
68
label = label .. ' (' .. key .. ')'
71
local button = self:add(DebugInstrumentButton:new
77
button.label.font = 11
79
button.background.height = 24
81
table.insert(self._buttons, button)
83
self.contentHeight = #self._buttons * (DebugInstrumentButton.height + self.spacing) + 2 * self.spacing
88
listen = function (self)
89
local modifiers = (self.modifiers == nil)
94
for _, key in pairs(self.modifiers) do
95
if not the.keys:pressed(key) then
103
for _, shortcut in pairs(self._shortcuts) do
104
if the.keys:justPressed(shortcut.key) then
105
shortcut.func(shortcut.key)
111
onResize = function (self, x, y, width, height)
114
width = width - self.spacing * 2
116
for _, spr in pairs(self._buttons) do
119
spr.background.width = width
120
spr.label.width = width
122
y = y + DebugInstrumentButton.height + self.spacing