ScummVM API documentation
dt-internal.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef DIRECTOR_DEBUGER_DT_INTERNAL_H
23 #define DIRECTOR_DEBUGER_DT_INTERNAL_H
24 
25 #ifndef IMGUI_DEFINE_MATH_OPERATORS
26 #define IMGUI_DEFINE_MATH_OPERATORS
27 #endif
28 
29 #include "graphics/surface.h"
30 
31 #include "backends/imgui/imgui.h"
32 #include "backends/imgui/imgui_fonts.h"
33 #include "backends/imgui/components/imgui_logger.h"
34 #include "backends/imgui/components/imgui_memory_editor.h"
35 
36 #include "director/types.h"
37 #include "director/window.h"
38 #include "director/lingo/lingo.h"
39 #include "director/lingo/lingodec/ast.h"
40 #include "director/lingo/lingodec/handler.h"
41 
42 namespace Director {
43 namespace DT {
44 
45 #define kMaxColumnsInTable 512
46 
47 typedef struct ImGuiImage {
48  ImTextureID id;
49  int16 width;
50  int16 height;
51 } ImGuiImage;
52 
53 typedef struct ImGuiScriptCodeLine {
54  uint32 pc;
55  Common::String codeLine;
57 
58 typedef struct ImGuiScript {
59  bool score = false;
60  CastMemberID id;
61  ScriptType type;
62  Common::String handlerId;
63  Common::String handlerName;
64  Common::String moviePath;
65  Common::Array<uint32> byteOffsets;
66  uint pc = 0;
67 
68  bool isMethod = false;
69  bool isGenericEvent = false;
70  Common::StringArray argumentNames;
71  Common::StringArray propertyNames;
72  Common::StringArray globalNames;
75  Common::Array<uint> startOffsets;
77 
78  bool operator==(const ImGuiScript &c) const {
79  return moviePath == c.moviePath && score == c.score && id == c.id && handlerId == c.handlerId;
80  }
81  bool operator!=(const ImGuiScript &c) const {
82  return !(*this == c);
83  }
84 } ImGuiScript;
85 
86 typedef struct ImGuiWindows {
87  bool controlPanel = true;
88  bool vars = false;
89  bool channels = false;
90  bool cast = false;
91  bool castDetails = false;
92  bool funcList = false;
93  bool score = false;
94  bool bpList = false;
95  bool settings = false;
96  bool logger = false;
97  bool archive = false;
98  bool watchedVars = false;
99  bool executionContext = false;
100  bool search = false;
101  bool imageViewer = false;
102 } ImGuiWindows;
103 
104 
105 enum SearchMode {
106  kSearchAll = 0,
107  kSearchHandlerNames,
108  kSearchScriptBody,
109 };
110 
111 typedef struct ScriptData {
113  uint _current = 0;
114  bool _showByteCode = false;
115  bool _showScript = false;
116 } ScriptData;
117 
118 typedef struct WindowFlag {
119  const char *name;
120  bool *flag;
121 } WindowFlag;
122 
123 enum ThemeID {
124  kThemeDark = 0,
125  kThemeLight,
126  kThemeCount
127 };
128 
130  ImU32 tableLightColor;
131  ImU32 tableDarkColor;
132  ImU32 borderColor;
133  ImU32 sidebarTextColor;
134  ImU32 gridTextColor;
135  ImU32 playhead_color;
136  ImU32 current_statement_bg;
137  ImU32 channel_toggle;
138  ImU32 channel_hide_bg;
139  ImU32 channelSelectedCol;
140  ImU32 channelHoveredCol;
141  ImU32 contColors[6];
142 
143  // Breakpoints
144  ImVec4 bp_color_disabled;
145  ImVec4 bp_color_enabled;
146  ImVec4 bp_color_hover;
147 
148  // Syntax Highlighting
149  ImVec4 current_statement;
150  ImVec4 line_color;
151  ImVec4 call_color;
152  ImVec4 builtin_color;
153  ImVec4 var_color;
154  ImVec4 literal_color;
155  ImVec4 comment_color;
156  ImVec4 type_color;
157  ImVec4 keyword_color;
158  ImVec4 the_color;
159 
160  // Variable / Script References
161  ImVec4 script_ref;
162  ImVec4 var_ref;
163  ImVec4 var_ref_changed;
164  ImVec4 var_ref_out_of_scope;
165 
166  // Control Panel
167  ImVec4 cp_color;
168  ImVec4 cp_color_red;
169  ImVec4 cp_active_color;
170  ImVec4 cp_bgcolor;
171  ImVec4 cp_playing_color;
172  ImVec4 cp_path_color;
173 
174  // Logger
175  ImVec4 logger_error_b;
176  ImVec4 logger_warning_b;
177  ImVec4 logger_info_b;
178  ImVec4 logger_debug_b;
179  ImVec4 logger_error;
180  ImVec4 logger_warning;
181  ImVec4 logger_info;
182  ImVec4 logger_debug;
183 };
184 
185 typedef struct ImGuiState {
186 
187  struct WatchLogEntry {
188  Common::String varName;
189  Common::String value;
190  Common::String scriptRef;
191  };
192 
193  struct ScoreConfig {
194  float _sidebarWidth = 60.0f;
195  float _cellWidth = 14.0f;
196  float _cellHeight = 22.0f;
197  int _visibleFrames = 60;
198  int _visibleChannels = 20;
199  float _tableWidth = _cellWidth * _visibleFrames;
200  float _tableHeight = _cellHeight * _visibleChannels;
201  float _rulerHeight = 30.0f;
202  float _rulerWidth = _cellWidth * _visibleFrames;
203  float _sidebar1Height = _cellHeight * 6;
204  float _labelBarHeight = _cellHeight;
205  float _cellHeightExtended = 5 * _cellHeight;
206  } _scoreCfg;
207 
208  struct ScoreState {
209  int xSliderValue = 1; // first visible frame, 1 indexed
210  int channelScrollOffset = 1; // first visible channel, 1 indexed
211  } _scoreState;
212 
213  struct {
215  bool _listView = true;
216  int _thumbnailSize = 64;
217  ImGuiTextFilter _nameFilter;
218  int _typeFilter = 0x7FFF;
219  } _cast;
220 
221  struct {
222  ImGuiTextFilter _nameFilter;
223  bool _showScriptContexts = true;
224  Common::HashMap<Window *, ScriptData> _windowScriptData;
225  } _functions;
226  struct {
227  CastMember *_castMember;
228  Common::HashMap<CastMember *, int> _filmLoopCurrentFrame;
229  } _castDetails;
230 
231  struct {
232  bool _isScriptDirty = false; // indicates whether or not we have to display the script corresponding to the current stackframe
233  bool _goToDefinition = false;
234  bool _scrollToPC = false;
235  uint _lastLinePC = 0;
236  uint _callstackSize = 0;
237  Common::String _highlightQuery; // lowercased, empty disables highlight
238  bool _suppressHighlight = false; // used to disable highlighting in Execution Context
239  } _dbg;
240 
241  struct {
242  char input[256] = {};
243  bool dirty = false;
244  int mode = kSearchAll;
246  } _search;
247 
248  struct {
249  DatumHash _locals;
250  DatumHash _globals;
251 
252  DatumHash _prevLocals;
253  DatumHash _prevGlobals;
254 
255  uint32 _lastTimeRefreshed = 0;
256  } _vars;
257 
258  struct {
259  ImGuiImage image;
260  Common::String text; // empty = no text panel
261  Common::String title; // optional title
262 
263  // cached normalized text
264  Common::String cachedRaw;
265  Common::String cachedNormalized;
266 
267  // reusable buffer
268  char *buffer = nullptr;
269  size_t bufferSize = 0;
270 
271  } _imageViewerState;
272 
273  ImGuiWindows _w;
274  ImGuiWindows _savedW;
275  bool _wasHidden = false;
276 
277  Common::List<CastMemberID> _scriptCasts;
278  Common::HashMap<int, ImGuiScript> _openHandlers;
279  bool _showCompleteScript = true;
280 
282  int _prevFrame = -1;
283  struct {
284  int frame = -1;
285  int channel = -1;
286  bool isMainChannel = false;
287  } _selectedScoreCast;
288 
289  struct {
290  int frame = -1;
291  int channel = -1;
292  } _hoveredScoreCast;
293 
295  Common::String _loadedContinuationData;
296 
298 
299  Common::String _scoreWindow;
300  Common::String _channelsWindow;
301  Common::String _castWindow;
302  int _scoreMode = 0;
303  int _scoreFrameOffset = 1;
304  int _scorePageSlider = 0;
305  int _selectedChannel = -1;
306  bool _scrollToChannel = false;
307 
308  ImFont *_tinyFont = nullptr;
309 
310  int _activeThemeID = kThemeLight;
311  const DebuggerTheme *theme = nullptr;
312 
313  struct {
314  Common::Path path;
315  uint32 resType = 0;
316  uint32 resId = 0;
317 
318  byte *data = nullptr;
319  uint32 dataSize = 0;
320 
321  MemoryEditor memEdit;
322  } _archive;
323 
324  ImGuiEx::ImGuiLogger *_logger = nullptr;
325  bool _ignoreMouse = false;
326  bool _enableMultiViewport = true;
327 
328  Window *_windowToRedraw = nullptr;
329 } ImGuiState;
330 
331 // debugtools.cpp
332 ImGuiScript toImGuiScript(ScriptType scriptType, CastMemberID id, const Common::String &handlerId);
333 ScriptContext *getScriptContext(CastMemberID id);
334 ScriptContext *getScriptContext(uint32 nameIndex, CastMemberID castId, Common::String handler);
335 ScriptContext *resolveHandlerContext(int32 nameIndex, const CastMemberID &refId, const Common::String &handlerName);
336 ImGuiScript buildImGuiHandlerScript(ScriptContext *ctx, int castLibID, const Common::String &handlerName, const Common::String &moviePath);
337 void maybeHighlightLastItem(const Common::String &text);
338 void addToOpenHandlers(ImGuiScript handler);
339 void setScriptToDisplay(const ImGuiScript &script);
340 Director::Breakpoint *getBreakpoint(const Common::String &handlerName, uint16 scriptId, uint pc);
341 void displayScriptRef(CastMemberID &scriptId);
342 ImGuiImage getImageID(CastMember *castMember);
343 ImGuiImage getShapeID(CastMember *castMember);
344 ImGuiImage getTextID(CastMember *castMember);
345 Common::String getDisplayName(CastMember *castMember);
346 void showImage(const ImGuiImage &image, const char *name, float thumbnailSize);
347 void showImageWrappedBorder(const ImGuiImage &image, const char *name, float size);
348 ImVec4 convertColor(uint32 color);
349 void displayVariable(const Common::String &name, bool changed, bool outOfScope = false);
350 ImColor brightenColor(const ImColor &color, float factor);
351 Window *windowListCombo(Common::String *target);
352 Common::String formatHandlerName(int scriptId, int castId, Common::String handlerName, ScriptType scriptType, bool childScript);
353 void setTheme(int themeIndex);
354 void openImageViewer(ImGuiImage image, const Common::String &text = "", const Common::String &title = "");
355 
356 // helper to draw thin rectangles for table grid
357 inline void addThinRect(ImDrawList *dl, ImVec2 min, ImVec2 max, ImU32 col, float thickness = 0.1f) {
358  dl->AddLine(ImVec2(min.x, min.y), ImVec2(max.x, min.y), col, thickness); // top
359  dl->AddLine(ImVec2(max.x, min.y), ImVec2(max.x, max.y), col, thickness); // right
360  dl->AddLine(ImVec2(max.x, max.y), ImVec2(min.x, max.y), col, thickness); // bottom
361  dl->AddLine(ImVec2(min.x, max.y), ImVec2(min.x, min.y), col, thickness); // left
362 }
363 
364 void showCast(); // dt-cast.cpp
365 void showImageViewer(); // dt-castdetails.cpp
366 void showCastDetails(); // dt-castdetails.cpp
367 void showControlPanel();// dt-controlpanel.cpp
368 
369 // dt-lists.cpp
370 void showVars();
371 void showWatchedVars();
372 void showBreakpointList();
373 void showArchive();
374 
375 // dt-score.cpp
376 void showScore();
377 void showChannels();
378 
379 void renderOldScriptAST(ImGuiScript &script, bool showByteCode, bool scrollTo); // dt-script-d2.cpp
380 void renderScriptAST(ImGuiScript &script, bool showByteCode, bool scrollTo); // dt-script-d4.cpp
381 
382 // dt-scripts.cpp
383 void showFuncList();
384 void showScriptCasts();
385 void showExecutionContext();
386 void showHandlers();
387 
388 // dt-save-state.cpp
389 void saveCurrentState();
390 void loadSavedState();
391 Common::Array<WindowFlag> getWindowFlags();
392 
393 // dt-search.cpp
394 void showSearchBar();
395 
396 extern ImGuiState *_state;
397 
398 } // End of namespace DT
399 
400 } // End of namespace Director
401 
402 #endif
Definition: str.h:59
Definition: dt-internal.h:53
Definition: dt-internal.h:47
Definition: imgui.h:315
Definition: list.h:44
Definition: path.h:52
Definition: window.h:106
Definition: archive.h:36
Definition: dt-internal.h:129
Definition: dt-internal.h:118
Definition: imgui.h:3398
Definition: imgui.h:302
Definition: imgui.h:3982
Definition: dt-internal.h:86
Definition: imgui_memory_editor.h:83
Definition: dt-internal.h:193
Definition: dt-internal.h:111
Definition: hashmap.h:85
Definition: dt-internal.h:187
Definition: imgui_logger.h:33
Definition: dt-internal.h:208
Definition: imgui.h:3086
Definition: imgui.h:2856
Definition: dt-internal.h:185
Definition: debugger.h:45
Definition: dt-internal.h:58
Definition: castmember.h:48
Definition: types.h:423
Definition: lingo-object.h:213