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 
35 #include "director/debugger/imgui_memory_editor.h"
36 
37 #include "director/types.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 funcList = false;
92  bool score = false;
93  bool bpList = false;
94  bool settings = false;
95  bool logger = false;
96  bool archive = false;
97  bool watchedVars = false;
98  bool executionContext = false;
99 } ImGuiWindows;
100 
101 typedef struct ScriptData {
103  uint _current = 0;
104  bool _showByteCode = false;
105  bool _showScript = false;
106 } ScriptData;
107 
108 typedef struct WindowFlag {
109  const char *name;
110  bool *flag;
111 } WindowFlag;
112 
113 typedef struct ImGuiState {
114  struct {
116  bool _listView = true;
117  int _thumbnailSize = 64;
118  ImGuiTextFilter _nameFilter;
119  int _typeFilter = 0x7FFF;
120  } _cast;
121  struct {
122  ImGuiTextFilter _nameFilter;
123  bool _showScriptContexts = true;
124  Common::HashMap<Window *, ScriptData> _windowScriptData;
125  } _functions;
126 
127  struct {
128  bool _isScriptDirty = false; // indicates whether or not we have to display the script corresponding to the current stackframe
129  bool _goToDefinition = false;
130  bool _scrollToPC = false;
131  uint _lastLinePC = 0;
132  uint _callstackSize = 0;
133  } _dbg;
134 
135  struct {
136  ImVec4 _bp_color_disabled = ImVec4(0.9f, 0.08f, 0.0f, 0.0f);
137  ImVec4 _bp_color_enabled = ImVec4(0.9f, 0.08f, 0.0f, 1.0f);
138  ImVec4 _bp_color_hover = ImVec4(0.42f, 0.17f, 0.13f, 1.0f);
139 
140  ImVec4 _channel_toggle = ImColor(IM_COL32(0x30, 0x30, 0xFF, 0xFF));
141 
142  ImVec4 _current_statement = ImColor(IM_COL32(0xFF, 0xFF, 0x00, 0xFF));
143  ImVec4 _line_color = ImVec4(0.44f, 0.44f, 0.44f, 1.0f);
144  ImVec4 _call_color = ImColor(IM_COL32(0xFF, 0xC5, 0x5C, 0xFF));
145  ImVec4 _builtin_color = ImColor(IM_COL32(0x60, 0x7C, 0xFF, 0xFF));
146  ImVec4 _var_color = ImColor(IM_COL32(0x4B, 0xCD, 0x5E, 0xFF));
147  ImVec4 _literal_color = ImColor(IM_COL32(0xFF, 0x9F, 0xDA, 0x9E));
148  ImVec4 _comment_color = ImColor(IM_COL32(0xFF, 0xA5, 0x9D, 0x95));
149  ImVec4 _type_color = ImColor(IM_COL32(0x13, 0xC5, 0xF9, 0xFF));
150  ImVec4 _keyword_color = ImColor(IM_COL32(0xC1, 0xC1, 0xC1, 0xFF));
151  ImVec4 _the_color = ImColor(IM_COL32(0xFF, 0x49, 0xEF, 0xFF));
152 
153  ImVec4 _script_ref = ImColor(IM_COL32(0x7f, 0x7f, 0xff, 0xfff));
154  ImVec4 _var_ref = ImColor(IM_COL32(0xe6, 0xe6, 0x00, 0xff));
155  ImVec4 _var_ref_changed = ImColor(IM_COL32(0xFF, 0x00, 0x00, 0xFF));
156  ImVec4 _var_ref_out_of_scope = ImColor(IM_COL32(0xFF, 0x00, 0xFF, 0xFF));
157 
158  // Colors to show continuation data
159  // They come from the Authoring tool
160  ImColor _contColors[6] = {
161  ImColor(IM_COL32(0xce, 0xce, 0xff, 0x80)), // 0xceceff,
162  ImColor(IM_COL32(0xff, 0xff, 0xce, 0x80)), // 0xffffce,
163  ImColor(IM_COL32(0xce, 0xff, 0xce, 0x80)), // 0xceffce,
164  ImColor(IM_COL32(0xce, 0xff, 0xff, 0x80)), // 0xceffff,
165  ImColor(IM_COL32(0xff, 0xce, 0xff, 0x80)), // 0xffceff,
166  ImColor(IM_COL32(0xff, 0xce, 0x9c, 0x80)), // 0xffce9c,
167  };
168 
169  ImColor _channel_selected_col = ImColor(IM_COL32(0x94, 0x00, 0xD3, 0xFF));
170  ImColor _channel_hovered_col = ImColor(IM_COL32(0xFF, 0xFF, 0, 0x3C));
171  int _contColorIndex = 0;
172  } _colors;
173 
174 
175  struct {
176  DatumHash _locals;
177  DatumHash _globals;
178 
179  DatumHash _prevLocals;
180  DatumHash _prevGlobals;
181 
182  uint32 _lastTimeRefreshed = 0;
183  } _vars;
184 
185  ImGuiWindows _w;
186  ImGuiWindows _savedW;
187  bool _wasHidden = false;
188 
189  Common::List<CastMemberID> _scriptCasts;
190  Common::HashMap<int, ImGuiScript> _openHandlers;
191  bool _showCompleteScript = true;
192 
194  int _prevFrame = -1;
195  struct {
196  int frame = -1;
197  int channel = -1;
198  } _selectedScoreCast;
199 
200  struct {
201  int frame = -1;
202  int channel = -1;
203  } _hoveredScoreCast;
204 
206  Common::String _loadedContinuationData;
207 
208  Common::String _scoreWindow;
209  Common::String _channelsWindow;
210  Common::String _castWindow;
211  int _scoreMode = 0;
212  int _scoreFrameOffset = 1;
213  int _scorePageSlider = 0;
214 
215  int _selectedChannel = -1;
216 
217  ImFont *_tinyFont = nullptr;
218 
219  struct {
220  Common::Path path;
221  uint32 resType = 0;
222  uint32 resId = 0;
223 
224  byte *data = nullptr;
225  uint32 dataSize = 0;
226 
227  MemoryEditor memEdit;
228  } _archive;
229 
230  ImGuiEx::ImGuiLogger *_logger = nullptr;
231 } ImGuiState;
232 
233 // debugtools.cpp
234 ImGuiScript toImGuiScript(ScriptType scriptType, CastMemberID id, const Common::String &handlerId);
235 ScriptContext *getScriptContext(CastMemberID id);
236 ScriptContext *getScriptContext(uint32 nameIndex, CastMemberID castId, Common::String handler);
237 void setScriptToDisplay(const ImGuiScript &script);
238 Director::Breakpoint *getBreakpoint(const Common::String &handlerName, uint16 scriptId, uint pc);
239 void displayScriptRef(CastMemberID &scriptId);
240 ImGuiImage getImageID(CastMember *castMember);
241 ImGuiImage getShapeID(CastMember *castMember);
242 ImGuiImage getTextID(CastMember *castMember);
243 Common::String getDisplayName(CastMember *castMember);
244 void showImage(const ImGuiImage &image, const char *name, float thumbnailSize);
245 ImVec4 convertColor(uint32 color);
246 void displayVariable(const Common::String &name, bool changed, bool outOfScope = false);
247 ImColor brightenColor(const ImColor &color, float factor);
248 Window *windowListCombo(Common::String *target);
249 Common::String formatHandlerName(int scriptId, int castId, Common::String handlerName, ScriptType scriptType, bool childScript);
250 
251 void showCast(); // dt-cast.cpp
252 void showControlPanel(); // dt-controlpanel.cpp
253 
254 // dt-lists.cpp
255 void showVars();
256 void showWatchedVars();
257 void showBreakpointList();
258 void showArchive();
259 
260 // dt-score.cpp
261 void showScore();
262 void showChannels();
263 
264 void renderOldScriptAST(ImGuiScript &script, bool showByteCode, bool scrollTo); // dt-script-d2.cpp
265 void renderScriptAST(ImGuiScript &script, bool showByteCode, bool scrollTo); // dt-script-d4.cpp
266 
267 // dt-scripts.cpp
268 void showFuncList();
269 void showScriptCasts();
270 void showExecutionContext();
271 void showHandlers();
272 
273 // dt-save-state.cpp
274 void saveCurrentState();
275 void loadSavedState();
276 Common::Array<WindowFlag> getWindowFlags();
277 
278 extern ImGuiState *_state;
279 
280 } // End of namespace DT
281 
282 } // End of namespace Director
283 
284 #endif
Definition: str.h:59
Definition: dt-internal.h:53
Definition: dt-internal.h:47
Definition: imgui.h:307
Definition: list.h:44
Definition: path.h:52
Definition: window.h:106
Definition: archive.h:36
Definition: dt-internal.h:108
Definition: imgui.h:3896
Definition: dt-internal.h:86
Definition: imgui_memory_editor.h:67
Definition: dt-internal.h:101
Definition: hashmap.h:85
Definition: imgui_logger.h:33
Definition: imgui.h:3012
Definition: imgui.h:2790
Definition: dt-internal.h:113
Definition: debugger.h:45
Definition: dt-internal.h:58
Definition: castmember.h:48
Definition: types.h:419
Definition: lingo-object.h:213