xoreos  0.0.5
console.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef ENGINES_AURORA_CONSOLE_H
26 #define ENGINES_AURORA_CONSOLE_H
27 
28 #include <vector>
29 #include <list>
30 #include <map>
31 
32 #include <boost/noncopyable.hpp>
33 #include <boost/function.hpp>
34 
35 #include "src/common/types.h"
36 #include "src/common/scopedptr.h"
37 #include "src/common/error.h"
38 #include "src/common/ustring.h"
39 #include "src/common/writefile.h"
40 
41 #include "src/events/types.h"
42 #include "src/events/notifyable.h"
43 
44 #include "src/graphics/types.h"
46 
49 
50 namespace Common {
51  class ReadLine;
52 }
53 
54 namespace Engines {
55 
56 class Engine;
57 
59 public:
60  ConsoleWindow(const Common::UString &font, size_t lines, size_t history,
61  int fontHeight = 0);
63 
64 
65  void show();
66  void hide();
67 
68  void showPrompt();
69  void hidePrompt();
70 
71  bool isIn(float x, float y) const;
72  bool isIn(float x, float y, float z) const;
73 
74 
75  // Dimensions
76 
77  float getWidth () const;
78  float getHeight() const;
79  float getContentWidth () const;
80  float getContentHeight() const;
81 
82  size_t getLines () const;
83  size_t getColumns() const;
84 
85 
86  // Input
87 
88  void setPrompt(const Common::UString &prompt);
89  void setInput(const Common::UString &input, size_t cursorPos, bool overwrite);
90 
91 
92  // Output
93 
94  void clear();
95  void print(const Common::UString &line);
96  bool setRedirect(Common::UString redirect = "");
97 
98 
99  // Highlight
100 
101  void clearHighlight();
102 
103  void startHighlight(int x, int y);
104  void stopHighlight(int x, int y);
105 
106  void highlightWord(int x, int y);
107  void highlightLine(int x, int y);
108 
110 
111 
112  // Scrolling
113 
114  void scrollUp(size_t n = 1);
115  void scrollDown(size_t n = 1);
116  void scrollTop();
117  void scrollBottom();
118 
119 
120  // Renderable
121  void calculateDistance();
123 
124 
125 private:
127 
131 
134  std::list<Common::UString> _history;
135 
137 
138  std::vector<Graphics::Aurora::Text *> _lines;
140 
141 
145 
146 
147  float _lineHeight;
148 
149  float _x;
150  float _y;
151  float _width;
152  float _height;
153 
156 
159 
160  size_t _highlightX;
161  size_t _highlightY;
162  ptrdiff_t _highlightLength;
163 
166 
167 
168  void recalcCursor();
169  void redrawLines();
170 
171  void printLine(const Common::UString &line);
172 
173  bool openLogFile();
174  bool openLogFile(const Common::UString &file);
175  void closeLogFile();
176 
177  void updateHighlight();
178  bool getPosition(int cursorX, int cursorY, float &x, float &y);
179  void highlightClip(size_t &x, size_t &y) const;
180 
181  void updateScrollbarLength();
183 
184  void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight);
185 
186  static size_t findWordStart(const Common::UString &line, size_t pos);
187  static size_t findWordEnd (const Common::UString &line, size_t pos);
188 };
189 
190 class Console : boost::noncopyable {
191 public:
192  Console(Engine &engine, const Common::UString &font, int fontHeight = 0);
193  virtual ~Console();
194 
195  void show();
196  void hide();
197 
198  bool isVisible() const;
199 
200  float getWidth () const;
201  float getHeight () const;
202  size_t getLines () const;
203  size_t getColumns() const;
204 
205  bool processEvent(const Events::Event &event);
206 
207  void disableCommand(const Common::UString &cmd, const Common::UString &reason = "");
208  void enableCommand (const Common::UString &cmd);
209 
210  void clear();
211  void print(const Common::UString &line);
212  void printf(const char *s, ...) GCC_PRINTF(2, 3);
213 
214 
215 protected:
216  struct CommandLine {
219  };
220 
221  typedef boost::function<void (const CommandLine &cl)> CommandCallback;
222 
223 
224  void printException(Common::Exception &e, const Common::UString &prefix = "ERROR: ");
225 
226  bool registerCommand(const Common::UString &cmd, const CommandCallback &callback,
227  const Common::UString &help);
228 
229  void printCommandHelp(const Common::UString &cmd);
230  void printList(const std::vector<Common::UString> &list, size_t maxSize = 0);
231 
232  void setArguments(const Common::UString &cmd, const std::vector<Common::UString> &args);
233  void setArguments(const Common::UString &cmd);
234 
235  virtual void updateCaches();
236  virtual void showCallback();
237 
238  static void splitArguments(Common::UString argLine, std::vector<Common::UString> &args);
239 
240 
241 private:
242  struct Command {
245 
247 
248  bool disabled;
250  };
251 
252  typedef std::map<Common::UString, Command, Common::UString::iless> CommandMap;
253 
254 
256 
258  bool _visible;
259 
262 
264 
265  size_t _tabCount;
267 
271 
272  ptrdiff_t _lastClickX;
273  ptrdiff_t _lastClickY;
274 
275 
276  std::vector<Common::UString> _videos;
277  std::vector<Common::UString> _sounds;
278 
281 
282 
283  void updateVideos();
284  void updateSounds();
285 
286  void cmdHelp (const CommandLine &cl);
287  void cmdClear (const CommandLine &cl);
288  void cmdClose (const CommandLine &cl);
289  void cmdQuit (const CommandLine &cl);
290  void cmdDumpResList(const CommandLine &cl);
291  void cmdDumpRes (const CommandLine &cl);
292  void cmdDumpTGA (const CommandLine &cl);
293  void cmdDump2DA (const CommandLine &cl);
294  void cmdDumpAll2DA (const CommandLine &cl);
295  void cmdListVideos (const CommandLine &cl);
296  void cmdPlayVideo (const CommandLine &cl);
297  void cmdListSounds (const CommandLine &cl);
298  void cmdPlaySound (const CommandLine &cl);
299  void cmdSilence (const CommandLine &cl);
300  void cmdGetOption (const CommandLine &cl);
301  void cmdSetOption (const CommandLine &cl);
302  void cmdShowFPS (const CommandLine &cl);
303  void cmdListLangs (const CommandLine &cl);
304  void cmdGetLang (const CommandLine &cl);
305  void cmdSetLang (const CommandLine &cl);
306  void cmdGetString (const CommandLine &cl);
307  void cmdGetCamera (const CommandLine &cl);
308  void cmdSetCamera (const CommandLine &cl);
309 
310  void updateHelpArguments();
311 
312  void printFullHelp();
313  bool printHints(const Common::UString &command);
314 
315  void execute(const Common::UString &line);
316 };
317 
318 } // End of namespace Engines
319 
320 #endif // ENGINES_AURORA_CONSOLE_H
void printLine(const Common::UString &line)
Definition: console.cpp:279
float getContentHeight() const
Definition: console.cpp:213
Basic event types.
Common::ScopedPtr< Graphics::Aurora::Text > _input
Definition: console.h:139
std::vector< Common::UString > _sounds
Definition: console.h:277
bool setRedirect(Common::UString redirect="")
Definition: console.cpp:302
Common::UString args
Definition: console.h:218
float getContentWidth() const
Definition: console.cpp:209
float getHeight() const
Definition: console.cpp:205
bool isVisible() const
Definition: console.cpp:797
Common::UString disableReason
Definition: console.h:249
void highlightLine(int x, int y)
Definition: console.cpp:462
void updateHelpArguments()
Definition: console.cpp:1600
virtual ~Console()
Definition: console.cpp:766
Definition: 2dafile.h:39
void cmdDumpTGA(const CommandLine &cl)
Definition: console.cpp:1213
void updateScrollbarLength()
Definition: console.cpp:681
A class holding an UTF-8 string.
Definition: ustring.h:48
bool isIn(float x, float y) const
Is that point within the object?
Definition: console.cpp:188
uint8 _lastClickButton
Definition: console.h:269
void updateScrollbarPosition()
Definition: console.cpp:691
static void splitArguments(Common::UString argLine, std::vector< Common::UString > &args)
Definition: console.cpp:1539
float getHeight() const
Definition: console.cpp:805
uint8_t uint8
Definition: types.h:200
Graphics::Aurora::FontHandle _font
Definition: console.h:126
uint32 _lastClickTime
Definition: console.h:270
A handle to a font.
Definition: fonthandle.h:52
static size_t findWordStart(const Common::UString &line, size_t pos)
Definition: console.cpp:633
size_t _tabCount
Definition: console.h:265
bool _printedCompleteWarning
Definition: console.h:266
void cmdListLangs(const CommandLine &cl)
Definition: console.cpp:1325
bool printHints(const Common::UString &command)
Definition: console.cpp:1052
void stopHighlight(int x, int y)
Definition: console.cpp:422
void highlightClip(size_t &x, size_t &y) const
Definition: console.cpp:392
std::vector< Common::UString > _videos
Definition: console.h:276
Basic graphics types.
void execute(const Common::UString &line)
Definition: console.cpp:993
void cmdDumpAll2DA(const CommandLine &cl)
Definition: console.cpp:1241
void setPrompt(const Common::UString &prompt)
Definition: console.cpp:225
void calculateDistance()
Calculate the object&#39;s distance.
Definition: console.cpp:557
Exception that provides a stack of explanations.
Definition: error.h:36
Common::UString getHighlight() const
Definition: console.cpp:489
A simple scoped smart pointer template.
Common::ScopedPtr< Graphics::Aurora::Text > _prompt
Definition: console.h:128
SDL_Event Event
Definition: types.h:42
void cmdSetOption(const CommandLine &cl)
Definition: console.cpp:1300
void cmdDumpResList(const CommandLine &cl)
Definition: console.cpp:1185
A GUI element.
virtual void showCallback()
Definition: console.cpp:1573
Basic exceptions to throw.
void disableCommand(const Common::UString &cmd, const Common::UString &reason="")
Definition: console.cpp:972
void cmdListSounds(const CommandLine &cl)
Definition: console.cpp:1270
RenderPass
Definition: types.h:97
size_t getColumns() const
Definition: console.cpp:813
void cmdClose(const CommandLine &cl)
Definition: console.cpp:1176
Common::ScopedPtr< ConsoleWindow > _console
Definition: console.h:261
std::map< Common::UString, Command, Common::UString::iless > CommandMap
Definition: console.h:252
void cmdGetCamera(const CommandLine &cl)
Definition: console.cpp:1418
void cmdGetString(const CommandLine &cl)
Definition: console.cpp:1401
Basic Aurora graphics types.
void cmdSilence(const CommandLine &cl)
Definition: console.cpp:1284
void updateVideos()
Definition: console.cpp:1127
ptrdiff_t _lastClickX
Definition: console.h:272
void cmdPlayVideo(const CommandLine &cl)
Definition: console.cpp:1261
void cmdGetLang(const CommandLine &cl)
Definition: console.cpp:1351
void print(const Common::UString &line)
Definition: console.cpp:271
void cmdSetCamera(const CommandLine &cl)
Definition: console.cpp:1426
void printFullHelp()
Definition: console.cpp:1463
Common::ScopedPtr< Common::ReadLine > _readLine
Definition: console.h:260
A handle to an Aurora font.
void updateSounds()
Definition: console.cpp:1145
void setInput(const Common::UString &input, size_t cursorPos, bool overwrite)
Definition: console.cpp:236
void printList(const std::vector< Common::UString > &list, size_t maxSize=0)
Definition: console.cpp:1479
bool _neverShown
Definition: console.h:257
Low-level type definitions to handle fixed width types portably.
ConsoleWindow(const Common::UString &font, size_t lines, size_t history, int fontHeight=0)
Definition: console.cpp:71
A class that can be notified by the NotificationManager.
float getWidth() const
Definition: console.cpp:201
void cmdSetLang(const CommandLine &cl)
Definition: console.cpp:1362
void highlightWord(int x, int y)
Definition: console.cpp:436
float getWidth() const
Definition: console.cpp:801
bool getPosition(int cursorX, int cursorY, float &x, float &y)
Definition: console.cpp:377
CommandMap _commands
Definition: console.h:263
Unicode string handling.
void printException(Common::Exception &e, const Common::UString &prefix="ERROR: ")
Definition: console.cpp:1104
void enableCommand(const Common::UString &cmd)
Definition: console.cpp:983
size_t getLines() const
Definition: console.cpp:809
The base class for an engine within BioWare&#39;s Aurora family.
Definition: engine.h:49
An element of the GUI.
Definition: guielement.h:33
int8 _lastClickCount
Definition: console.h:268
Common::WriteFile _redirect
Definition: console.h:165
int8_t int8
Definition: types.h:199
void cmdShowFPS(const CommandLine &cl)
Definition: console.cpp:1315
void cmdDumpRes(const CommandLine &cl)
Definition: console.cpp:1199
static size_t findWordEnd(const Common::UString &line, size_t pos)
Definition: console.cpp:647
uint32_t uint32
Definition: types.h:204
void show()
Show the object.
Definition: console.cpp:128
void cmdListVideos(const CommandLine &cl)
Definition: console.cpp:1256
Console(Engine &engine, const Common::UString &font, int fontHeight=0)
Definition: console.cpp:703
std::list< Common::UString > _history
Definition: console.h:134
Common::UString help
Definition: console.h:244
void scrollDown(size_t n=1)
Definition: console.cpp:523
void render(Graphics::RenderPass pass)
Render the object.
Definition: console.cpp:561
void cmdGetOption(const CommandLine &cl)
Definition: console.cpp:1288
void printf(const char *s,...) GCC_PRINTF(2
Definition: console.cpp:1093
Implementing the stream writing interfaces for files.
bool processEvent(const Events::Event &event)
Definition: console.cpp:817
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _cursor
Definition: console.h:129
void cmdPlaySound(const CommandLine &cl)
Definition: console.cpp:1275
void print(const Common::UString &line)
Definition: console.cpp:1089
void cmdDump2DA(const CommandLine &cl)
Definition: console.cpp:1227
size_t _historySizeCurrent
Definition: console.h:133
ptrdiff_t _highlightLength
Definition: console.h:162
Common::UString _inputText
Definition: console.h:142
Common::UString cmd
Definition: console.h:243
void cmdClear(const CommandLine &cl)
Definition: console.cpp:1172
virtual void updateCaches()
Definition: console.cpp:1122
void printCommandHelp(const Common::UString &cmd)
Definition: console.cpp:1391
#define pass
Definition: fft.cpp:257
size_t _maxSizeVideos
Definition: console.h:279
void startHighlight(int x, int y)
Definition: console.cpp:407
void cmdHelp(const CommandLine &cl)
Definition: console.cpp:1163
#define GCC_PRINTF(x, y)
Definition: system.h:161
boost::function< void(const CommandLine &cl)> CommandCallback
Definition: console.h:221
CommandCallback callback
Definition: console.h:246
size_t getColumns() const
Definition: console.cpp:221
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _highlight
Definition: console.h:130
A simple streaming file writing class.
Definition: writefile.h:40
Common::WriteFile _logFile
Definition: console.h:164
void setArguments(const Common::UString &cmd, const std::vector< Common::UString > &args)
Definition: console.cpp:1565
size_t _maxSizeSounds
Definition: console.h:280
size_t getLines() const
Definition: console.cpp:217
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
Definition: console.cpp:615
bool registerCommand(const Common::UString &cmd, const CommandCallback &callback, const Common::UString &help)
Definition: console.cpp:1576
void cmdQuit(const CommandLine &cl)
Definition: console.cpp:1180
std::vector< Graphics::Aurora::Text * > _lines
Definition: console.h:138
Engine * _engine
Definition: console.h:255
void hide()
Hide the object.
Definition: console.cpp:145
void scrollUp(size_t n=1)
Definition: console.cpp:513
ptrdiff_t _lastClickY
Definition: console.h:273