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 #define IMGUI_DEFINE_MATH_OPERATORS
26 
27 #include "graphics/surface.h"
28 
29 #include "backends/imgui/imgui.h"
30 #include "backends/imgui/imgui_fonts.h"
31 
32 #include "director/debugger/imgui_memory_editor.h"
33 
34 #include "director/types.h"
35 #include "director/lingo/lingo.h"
36 #include "director/lingo/lingodec/ast.h"
37 #include "director/lingo/lingodec/handler.h"
38 
39 namespace Director {
40 
41 namespace DT {
42 
43 class ImGuiLogger;
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 
67  bool isMethod = false;
68  bool isGenericEvent = false;
69  Common::StringArray argumentNames;
70  Common::StringArray propertyNames;
71  Common::StringArray globalNames;
74  Common::Array<uint> startOffsets;
76 
77  bool operator==(const ImGuiScript &c) const {
78  return moviePath == c.moviePath && score == c.score && id == c.id && handlerId == c.handlerId;
79  }
80  bool operator!=(const ImGuiScript &c) const {
81  return !(*this == c);
82  }
83 } ImGuiScript;
84 
85 typedef struct ImGuiWindows {
86  bool controlPanel = true;
87  bool callStack = false;
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 } ImGuiWindows;
99 
100 typedef struct ImGuiState {
101  struct {
103  bool _listView = true;
104  int _thumbnailSize = 64;
105  ImGuiTextFilter _nameFilter;
106  int _typeFilter = 0x7FFF;
107  } _cast;
108  struct {
110  uint _current = 0;
111  ImGuiTextFilter _nameFilter;
112  bool _showByteCode = false;
113  bool _showScript = false;
114  } _functions;
115  struct {
116  uint _lastLinePC = 0;
117  uint _callstackSize = 0;
118  bool _isScriptDirty = false; // indicates whether or not we have to display the script corresponding to the current stackframe
119  } _dbg;
120 
121  struct {
122  ImVec4 _bp_color_disabled = ImVec4(0.9f, 0.08f, 0.0f, 0.0f);
123  ImVec4 _bp_color_enabled = ImVec4(0.9f, 0.08f, 0.0f, 1.0f);
124  ImVec4 _bp_color_hover = ImVec4(0.42f, 0.17f, 0.13f, 1.0f);
125 
126  ImVec4 _current_statement = ImColor(IM_COL32(0xFF, 0xFF, 0x00, 0xFF));
127  ImVec4 _line_color = ImVec4(0.44f, 0.44f, 0.44f, 1.0f);
128  ImVec4 _call_color = ImColor(IM_COL32(0xFF, 0xC5, 0x5C, 0xFF));
129  ImVec4 _builtin_color = ImColor(IM_COL32(0x60, 0x7C, 0xFF, 0xFF));
130  ImVec4 _var_color = ImColor(IM_COL32(0x4B, 0xCD, 0x5E, 0xFF));
131  ImVec4 _literal_color = ImColor(IM_COL32(0xFF, 0x9F, 0xDA, 0x9E));
132  ImVec4 _comment_color = ImColor(IM_COL32(0xFF, 0xA5, 0x9D, 0x95));
133  ImVec4 _type_color = ImColor(IM_COL32(0x13, 0xC5, 0xF9, 0xFF));
134  ImVec4 _keyword_color = ImColor(IM_COL32(0xC1, 0xC1, 0xC1, 0xFF));
135  ImVec4 _the_color = ImColor(IM_COL32(0xFF, 0x49, 0xEF, 0xFF));
136 
137  ImVec4 _script_ref = ImColor(IM_COL32(0x7f, 0x7f, 0xff, 0xfff));
138  ImVec4 _var_ref = ImColor(IM_COL32(0xe6, 0xe6, 0x00, 0xff));
139  ImVec4 _var_ref_changed = ImColor(IM_COL32(0xFF, 0x00, 0x00, 0xFF));
140 
141  ImVec4 _logger_error_b = ImVec4(1.f, 0.f, 0.f, 1.f);
142  ImVec4 _logger_warning_b = ImVec4(1.f, 1.f, 0.f, 1.f);
143  ImVec4 _logger_info_b = ImVec4(1.f, 1.f, 1.f, 1.f);
144  ImVec4 _logger_debug_b = ImVec4(0.8f, 0.8f, 0.8f, 1.f);
145 
146  ImVec4 _logger_error = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
147  ImVec4 _logger_warning = ImVec4(1.0f, 1.0f, 0.4f, 1.0f);
148  ImVec4 _logger_info = ImVec4(1.0f, 0.8f, 0.6f, 1.0f);
149  ImVec4 _logger_debug = ImVec4(0.8f, 0.8f, 0.8f, 1.0f);
150  } _colors;
151 
152  struct {
153  DatumHash _locals;
154  DatumHash _globals;
155 
156  DatumHash _prevLocals;
157  DatumHash _prevGlobals;
158 
159  uint32 _lastTimeRefreshed = 0;
160  } _vars;
161 
162  ImGuiWindows _w;
163  ImGuiWindows _savedW;
164  bool _wasHidden = false;
165 
166  Common::List<CastMemberID> _scriptCasts;
168  int _prevFrame = -1;
169  struct {
170  int frame = -1;
171  int channel = -1;
172  } _selectedScoreCast;
173 
174  int _scoreMode = 0;
175  int _scoreFrameOffset = 1;
176 
177  ImFont *_tinyFont = nullptr;
178 
179  struct {
180  Common::Path path;
181  uint32 resType = 0;
182  uint32 resId = 0;
183 
184  byte *data = nullptr;
185  uint32 dataSize = 0;
186 
187  MemoryEditor memEdit;
188  } _archive;
189 
190  ImGuiLogger *_logger = nullptr;
191 } ImGuiState;
192 
193 // dt-logger.cpp
194 class ImGuiLogger {
195  char _inputBuf[256];
196  ImVector<char *> _items;
197  ImVector<char *> _history;
198  int _historyPos; // -1: new line, 0.._history.Size-1 browsing history.
199  ImGuiTextFilter _filter;
200  bool _autoScroll;
201  bool _scrollToBottom;
202  bool _showError = true;
203  bool _showWarn = true;
204  bool _showInfo = true;
205  bool _showdebug = true;
206 
207 public:
208  ImGuiLogger();
209  ~ImGuiLogger();
210  void clear();
211  void addLog(const char *fmt, ...) IM_FMTARGS(2);
212  void draw(const char *title, bool *p_open);
213 };
214 
215 // debugtools.cpp
216 bool toggleButton(const char *label, bool *p_value, bool inverse = false);
217 ImGuiScript toImGuiScript(ScriptType scriptType, CastMemberID id, const Common::String &handlerId);
218 void setScriptToDisplay(const ImGuiScript &script);
219 Director::Breakpoint *getBreakpoint(const Common::String &handlerName, uint16 scriptId, uint pc);
220 void displayScriptRef(CastMemberID &scriptId);
221 ImGuiImage getImageID(CastMember *castMember);
222 Common::String getDisplayName(CastMember *castMember);
223 void showImage(const ImGuiImage &image, const char *name, float thumbnailSize);
224 ImVec4 convertColor(uint32 color);
225 void displayVariable(const Common::String &name, bool changed);
226 
227 void showCast(); // dt-cast.cpp
228 void showControlPanel(); // dt-controlpanel.cpp
229 
230 // dt-lists.cpp
231 void showCallStack();
232 void showVars();
233 void showWatchedVars();
234 void showBreakpointList();
235 void showArchive();
236 
237 // dt-score.cpp
238 void showScore();
239 void showChannels();
240 
241 void renderOldScriptAST(ImGuiScript &script, bool showByteCode); // dt-script-d2.cpp
242 void renderScriptAST(ImGuiScript &script, bool showByteCode); // dt-script-d4.cpp
243 
244 // dt-scripts.cpp
245 void showFuncList();
246 void showScriptCasts();
247 void showScripts();
248 
249 extern ImGuiState *_state;
250 
251 }
252 
253 }
254 
255 #endif
Definition: str.h:59
Definition: dt-internal.h:53
Definition: dt-internal.h:47
Definition: imgui.h:294
Definition: list.h:44
Definition: path.h:52
Definition: archive.h:35
Definition: imgui.h:3250
Definition: dt-internal.h:85
Definition: imgui_memory_editor.h:69
Definition: hashmap.h:85
Definition: imgui.h:2047
Definition: dt-internal.h:194
Definition: imgui.h:2733
Definition: imgui.h:2531
Definition: dt-internal.h:100
Definition: debugger.h:45
Definition: dt-internal.h:58
Definition: castmember.h:45
Definition: types.h:413