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  uint _lastLinePC = 0;
131  uint _callstackSize = 0;
132  } _dbg;
133 
134  struct {
135  ImVec4 _bp_color_disabled = ImVec4(0.9f, 0.08f, 0.0f, 0.0f);
136  ImVec4 _bp_color_enabled = ImVec4(0.9f, 0.08f, 0.0f, 1.0f);
137  ImVec4 _bp_color_hover = ImVec4(0.42f, 0.17f, 0.13f, 1.0f);
138 
139  ImVec4 _current_statement = ImColor(IM_COL32(0xFF, 0xFF, 0x00, 0xFF));
140  ImVec4 _line_color = ImVec4(0.44f, 0.44f, 0.44f, 1.0f);
141  ImVec4 _call_color = ImColor(IM_COL32(0xFF, 0xC5, 0x5C, 0xFF));
142  ImVec4 _builtin_color = ImColor(IM_COL32(0x60, 0x7C, 0xFF, 0xFF));
143  ImVec4 _var_color = ImColor(IM_COL32(0x4B, 0xCD, 0x5E, 0xFF));
144  ImVec4 _literal_color = ImColor(IM_COL32(0xFF, 0x9F, 0xDA, 0x9E));
145  ImVec4 _comment_color = ImColor(IM_COL32(0xFF, 0xA5, 0x9D, 0x95));
146  ImVec4 _type_color = ImColor(IM_COL32(0x13, 0xC5, 0xF9, 0xFF));
147  ImVec4 _keyword_color = ImColor(IM_COL32(0xC1, 0xC1, 0xC1, 0xFF));
148  ImVec4 _the_color = ImColor(IM_COL32(0xFF, 0x49, 0xEF, 0xFF));
149 
150  ImVec4 _script_ref = ImColor(IM_COL32(0x7f, 0x7f, 0xff, 0xfff));
151  ImVec4 _var_ref = ImColor(IM_COL32(0xe6, 0xe6, 0x00, 0xff));
152  ImVec4 _var_ref_changed = ImColor(IM_COL32(0xFF, 0x00, 0x00, 0xFF));
153  ImVec4 _var_ref_out_of_scope = ImColor(IM_COL32(0xFF, 0x00, 0xFF, 0xFF));
154  } _colors;
155 
156  struct {
157  DatumHash _locals;
158  DatumHash _globals;
159 
160  DatumHash _prevLocals;
161  DatumHash _prevGlobals;
162 
163  uint32 _lastTimeRefreshed = 0;
164  } _vars;
165 
166  ImGuiWindows _w;
167  ImGuiWindows _savedW;
168  bool _wasHidden = false;
169 
170  Common::List<CastMemberID> _scriptCasts;
171  Common::List<ImGuiScript> _openHandlers;
172  bool _showCompleteScript = true;
173 
175  int _prevFrame = -1;
176  struct {
177  int frame = -1;
178  int channel = -1;
179  } _selectedScoreCast;
180 
181  int _scoreMode = 0;
182  int _scoreFrameOffset = 1;
183 
184  int _selectedChannel = -1;
185 
186  ImFont *_tinyFont = nullptr;
187 
188  struct {
189  Common::Path path;
190  uint32 resType = 0;
191  uint32 resId = 0;
192 
193  byte *data = nullptr;
194  uint32 dataSize = 0;
195 
196  MemoryEditor memEdit;
197  } _archive;
198 
199  ImGuiEx::ImGuiLogger *_logger = nullptr;
200 } ImGuiState;
201 
202 // debugtools.cpp
203 ImGuiScript toImGuiScript(ScriptType scriptType, CastMemberID id, const Common::String &handlerId);
204 ScriptContext *getScriptContext(CastMemberID id);
205 ScriptContext *getScriptContext(uint32 nameIndex, CastMemberID castId, Common::String handler);
206 void setScriptToDisplay(const ImGuiScript &script);
207 Director::Breakpoint *getBreakpoint(const Common::String &handlerName, uint16 scriptId, uint pc);
208 void displayScriptRef(CastMemberID &scriptId);
209 ImGuiImage getImageID(CastMember *castMember);
210 ImGuiImage getShapeID(CastMember *castMember);
211 ImGuiImage getTextID(CastMember *castMember);
212 Common::String getDisplayName(CastMember *castMember);
213 void showImage(const ImGuiImage &image, const char *name, float thumbnailSize);
214 ImVec4 convertColor(uint32 color);
215 void displayVariable(const Common::String &name, bool changed, bool outOfScope = false);
216 
217 void showCast(); // dt-cast.cpp
218 void showControlPanel(); // dt-controlpanel.cpp
219 
220 // dt-lists.cpp
221 void showVars();
222 void showWatchedVars();
223 void showBreakpointList();
224 void showArchive();
225 
226 // dt-score.cpp
227 void showScore();
228 void showChannels();
229 
230 void renderOldScriptAST(ImGuiScript &script, bool showByteCode, bool scrollTo); // dt-script-d2.cpp
231 void renderScriptAST(ImGuiScript &script, bool showByteCode, bool scrollTo); // dt-script-d4.cpp
232 
233 // dt-scripts.cpp
234 void showFuncList();
235 void showScriptCasts();
236 void showExecutionContext();
237 void showHandlers();
238 
239 // dt-save-state.cpp
240 void saveCurrentState();
241 void loadSavedState();
242 Common::Array<WindowFlag> getWindowFlags();
243 
244 extern ImGuiState *_state;
245 
246 } // End of namespace DT
247 
248 } // End of namespace Director
249 
250 #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: 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:411
Definition: lingo-object.h:213