xoreos  0.0.5
console.cpp
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 #include <cassert>
26 #include <cstdarg>
27 #include <cstdio>
28 
29 #include <boost/bind.hpp>
30 
31 #include "src/common/util.h"
32 #include "src/common/strutil.h"
33 #include "src/common/filepath.h"
34 #include "src/common/readline.h"
35 #include "src/common/configman.h"
36 
37 #include "src/aurora/resman.h"
38 #include "src/aurora/talkman.h"
39 
40 #include "src/graphics/graphics.h"
41 #include "src/graphics/font.h"
42 #include "src/graphics/camera.h"
43 //#include "src/graphics/windowman.h"
44 
45 #include "src/sound/sound.h"
46 
47 #include "src/events/events.h"
48 
54 
55 #include "src/engines/engine.h"
56 
59 
60 
61 static const uint32 kDoubleClickTime = 500;
62 
63 static const char *kPrompt = "> ";
64 
65 static const size_t kCommandHistorySize = 100;
66 static const size_t kConsoleHistory = 500;
67 static const size_t kConsoleLines = 25;
68 
69 namespace Engines {
70 
71 ConsoleWindow::ConsoleWindow(const Common::UString &font, size_t lines, size_t history,
72  int fontHeight) :
73  Graphics::GUIElement(Graphics::GUIElement::kGUIElementConsole),
74  _font(FontMan.get(font, fontHeight)), _historySizeMax(history),
75  _historySizeCurrent(0), _historyStart(0), _cursorPosition(0),
76  _overwrite(false), _cursorBlinkState(false), _lastCursorBlink(0) {
77 
78  assert(lines >= 2);
79  assert(history >= lines);
80 
81  setTag("ConsoleWindow");
82  setClickable(true);
83 
85  _height = floorf(lines * _lineHeight);
86 
89 
90  _prompt->disableColorTokens(true);
91  _input->disableColorTokens(true);
92 
93  const float cursorHeight = _font.getFont().getHeight();
94  _cursor.reset(new Graphics::Aurora::GUIQuad(Graphics::GUIElement::kGUIElementConsole, "", 0.0f, 1.0f, 0.0f, cursorHeight));
95  _cursor->setXOR(true);
96 
98  _highlight->setColor(1.0f, 1.0f, 1.0f, 0.0f);
99  _highlight->setXOR(true);
100 
101  _lines.reserve(lines - 1);
102  for (size_t i = 0; i < (lines - 1); i++) {
104  _lines.back()->disableColorTokens(true);
105  }
106 
107  notifyResized(0, 0, WindowMan.getWindowWidth(), WindowMan.getWindowHeight());
108 
111 
112  clearHighlight();
113 
115 
116  openLogFile();
117 }
118 
120  _redirect.flush();
121  _redirect.close();
122 
123  for (std::vector<Graphics::Aurora::Text *>::iterator l = _lines.begin();
124  l != _lines.end(); ++l)
125  delete *l;
126 }
127 
129  GfxMan.lockFrame();
130 
131  for (std::vector<Graphics::Aurora::Text *>::iterator l = _lines.begin();
132  l != _lines.end(); ++l)
133  (*l)->show();
134 
135  _highlight->show();
136  _cursor->show();
137  _prompt->show();
138  _input->show();
139 
141 
142  GfxMan.unlockFrame();
143 }
144 
146  GfxMan.lockFrame();
147 
148  for (std::vector<Graphics::Aurora::Text *>::iterator l = _lines.begin();
149  l != _lines.end(); ++l)
150  (*l)->hide();
151 
152  _highlight->hide();
153  _cursor->hide();
154  _prompt->hide();
155  _input->hide();
156 
158 
159  GfxMan.unlockFrame();
160 }
161 
163  if (!isVisible())
164  return;
165 
166  GfxMan.lockFrame();
167 
168  _cursor->show();
169  _prompt->show();
170  _input->show();
171 
172  GfxMan.unlockFrame();
173 }
174 
176  if (!isVisible())
177  return;
178 
179  GfxMan.lockFrame();
180 
181  _cursor->hide();
182  _prompt->hide();
183  _input->hide();
184 
185  GfxMan.unlockFrame();
186 }
187 
188 bool ConsoleWindow::isIn(float x, float y) const {
189  if ((x < _x) || (x > (_x + _width)))
190  return false;
191  if ((y < _y) || (y > (_y + _height)))
192  return false;
193 
194  return true;
195 }
196 
197 bool ConsoleWindow::isIn(float x, float y, float UNUSED(z)) const {
198  return isIn(x, y);
199 }
200 
201 float ConsoleWindow::getWidth() const {
202  return _width;
203 }
204 
206  return _height;
207 }
208 
210  return _width - 15.0f;
211 }
212 
214  return _height - _lineHeight;
215 }
216 
217 size_t ConsoleWindow::getLines() const {
218  return _lines.size();
219 }
220 
222  return floorf(getContentWidth() / _font.getFont().getWidth('m'));
223 }
224 
226  GfxMan.lockFrame();
227 
228  _prompt->setText(prompt);
229 
230  _input->setPosition(_x + _prompt->getWidth(), _y, -1001.0f);
231  recalcCursor();
232 
233  GfxMan.unlockFrame();
234 }
235 
236 void ConsoleWindow::setInput(const Common::UString &input, size_t cursorPos,
237  bool overwrite) {
238 
239  GfxMan.lockFrame();
240 
241  _inputText = input;
242  _cursorPosition = cursorPos;
243  _overwrite = overwrite;
244 
245  _cursorBlinkState = false;
246  _lastCursorBlink = 0;
247 
248  _input->setText(input);
249  recalcCursor();
250 
251  GfxMan.unlockFrame();
252 }
253 
255  GfxMan.lockFrame();
256 
257  _history.clear();
259 
260  _historyStart = 0;
261 
264 
265  for (std::vector<Graphics::Aurora::Text *>::iterator l = _lines.begin();
266  l != _lines.end(); ++l)
267  (*l)->setText("");
268  GfxMan.unlockFrame();
269 }
270 
272  std::vector<Common::UString> lines;
273 
274  _font.getFont().split(line, lines, _width - 15.0f, 0.0f, false);
275  for (std::vector<Common::UString>::iterator l = lines.begin(); l != lines.end(); ++l)
276  printLine(*l);
277 }
278 
280  if (_redirect.isOpen()) {
281  _redirect.writeString(line);
282  _redirect.writeByte('\n');
283  return;
284  }
285 
286  if (_logFile.isOpen()) {
287  _logFile.writeString(line);
288  _logFile.writeByte('\n');
289  _logFile.flush();
290  }
291 
292  _history.push_back(line);
294  _history.pop_front();
295  else
297 
299  redrawLines();
300 }
301 
303  _redirect.flush();
304  _redirect.close();
305 
306  if (redirect.empty())
307  return true;
308 
309  redirect = Common::FilePath::getUserDataFile(redirect);
310  if (!_redirect.open(redirect)) {
312  Common::UString::format("Failed opening file \"%s\" for writing.", redirect.c_str());
313 
314  print(error);
315  return false;
316  }
317 
318  return true;
319 }
320 
322  /* Open the log file.
323  *
324  * NOTE: A log is opened by default, unless the consolelog config value
325  * is set to an empty string or noconsolelog is set to true.
326  */
327  Common::UString logFile = Common::FilePath::getUserDataDirectory() + "/console.log";
328  if (ConfigMan.hasKey("consolelog"))
329  logFile = ConfigMan.getString("consolelog");
330  if (ConfigMan.getBool("noconsolelog", false))
331  logFile.clear();
332 
333  if (logFile.empty())
334  return true;
335 
336  return openLogFile(logFile);
337 }
338 
340  closeLogFile();
341 
342  // Create the directories in the path, if necessary
344 
345  try {
347  } catch (...) {
348  return false;
349  }
350 
351  return _logFile.open(path);
352 }
353 
355  _logFile.close();
356 }
357 
359  if ((_highlightLength == 0) || (_highlightY >= kConsoleLines)) {
360  _highlight->setColor(1.0f, 1.0f, 1.0f, 0.0f);
361  return;
362  }
363 
364  const float charWidth = _font.getFont().getWidth(' ');
365 
366  const ptrdiff_t start = _highlightX;
367  const ptrdiff_t end = _highlightX + _highlightLength;
368 
369  const ptrdiff_t x = MIN(start, end);
370  const size_t length = ABS(start - end);
371 
372  _highlight->setWidth(length * charWidth);
373  _highlight->setPosition(_x + x * charWidth, _y + _highlightY * _lineHeight, -1002.0f);
374  _highlight->setColor(1.0f, 1.0f, 1.0f, 1.0f);
375 }
376 
377 bool ConsoleWindow::getPosition(int cursorX, int cursorY, float &x, float &y) {
378  float realX, realY;
379  CursorMan.toScreenCoordinates(cursorX, cursorY, realX, realY);
380 
381  x = (realX - _x) / _font.getFont().getWidth(' ');
382  y = (realY - _y) / _lineHeight;
383 
384  if ((x < 0.0f) || (x > _width))
385  return false;
386  if ((y < 0.0f) || (y > _height))
387  return false;
388 
389  return true;
390 }
391 
392 void ConsoleWindow::highlightClip(size_t &x, size_t &y) const {
393  y = CLIP<size_t>(y, 0, _lines.size());
394 
395  size_t minX, maxX;
396  if (y == 0) {
397  minX = _prompt->get().size();
398  maxX = _prompt->get().size() + _input->get().size();
399  } else {
400  minX = 0;
401  maxX = _lines[_lines.size() - y]->get().size();
402  }
403 
404  x = CLIP(x, minX, maxX);
405 }
406 
407 void ConsoleWindow::startHighlight(int x, int y) {
408  clearHighlight();
409 
410  float lineX, lineY;
411  if (!getPosition(x, y, lineX, lineY))
412  return;
413 
414  _highlightX = floor(lineX);
415  _highlightY = floor(lineY);
416 
418 
419  updateHighlight();
420 }
421 
422 void ConsoleWindow::stopHighlight(int x, int y) {
423  float lineX, lineY;
424  if (!getPosition(x, y, lineX, lineY))
425  return;
426 
427  size_t endX = floor(lineX);
428 
429  highlightClip(endX, _highlightY);
430 
431  _highlightLength = ((ptrdiff_t) endX) - ((ptrdiff_t) _highlightX);
432 
433  updateHighlight();
434 }
435 
436 void ConsoleWindow::highlightWord(int x, int y) {
437  clearHighlight();
438 
439  float lineX, lineY;
440  if (!getPosition(x, y, lineX, lineY))
441  return;
442 
443  size_t wX = floor(lineX);
444  size_t wY = floor(lineY);
445 
446  highlightClip(wX, wY);
447 
448  const Common::UString &line = (wY == 0) ? _input->get() :
449  _lines[_lines.size() - wY]->get();
450  const size_t pos = (wY == 0) ? (wX - _prompt->get().size()) : wX;
451 
452  size_t wordStart = findWordStart(line, pos);
453  size_t wordEnd = findWordEnd (line, pos);
454 
455  _highlightX = (wY == 0) ? (wordStart + _prompt->get().size()) : wordStart;
456  _highlightY = wY;
457  _highlightLength = wordEnd - wordStart;
458 
459  updateHighlight();
460 }
461 
462 void ConsoleWindow::highlightLine(int x, int y) {
463  clearHighlight();
464 
465  float lineX, lineY;
466  if (!getPosition(x, y, lineX, lineY))
467  return;
468 
469  _highlightX = 0;
470  _highlightY = floor(lineY);
471 
473 
474  const Common::UString &line = (_highlightY == 0) ?
475  _input->get() : _lines[_lines.size() - _highlightY]->get();
476  _highlightLength = line.size();
477 
478  updateHighlight();
479 }
480 
482  _highlightX = 0;
483  _highlightY = 0;
484  _highlightLength = 0;
485 
486  updateHighlight();
487 }
488 
490  if ((_highlightLength == 0) || (_highlightY >= kConsoleLines))
491  return "";
492 
493  ptrdiff_t start = _highlightX;
494  ptrdiff_t end = _highlightX + _highlightLength;
495 
496  if (start > end)
497  SWAP(start, end);
498 
499  Common::UString line;
500  if (_highlightY == 0) {
501  start = start - _prompt->get().size();
502  end = end - _prompt->get().size();
503  line = _input->get();
504  } else
505  line = _lines[_lines.size() - _highlightY]->get();
506 
507  start = MAX<ptrdiff_t>(0, start);
508  end = MAX<ptrdiff_t>(0, end );
509 
510  return line.substr(line.getPosition(start), line.getPosition(end));
511 }
512 
513 void ConsoleWindow::scrollUp(size_t n) {
514  if ((_historyStart + _lines.size()) >= _historySizeCurrent)
515  return;
516 
517  _historyStart += MIN<size_t>(n, _historySizeCurrent - _lines.size() - _historyStart);
518 
520  redrawLines();
521 }
522 
524  if (_historyStart == 0)
525  return;
526 
528 
530  redrawLines();
531 }
532 
534  if (_historySizeCurrent <= _lines.size())
535  return;
536 
537  const size_t bottom = _historySizeCurrent - _lines.size();
538  if (bottom == _historyStart)
539  return;
540 
541  _historyStart = bottom;
542 
544  redrawLines();
545 }
546 
548  if (_historyStart == 0)
549  return;
550 
551  _historyStart = 0;
552 
554  redrawLines();
555 }
556 
558  _distance = -1000.0f;
559 }
560 
563  return;
564 
565  uint32 now = EventMan.getTimestamp();
566  if ((now - _lastCursorBlink) > 500) {
568  _lastCursorBlink = now;
569 
570  _cursor->setColor(1.0f, 1.0f, 1.0f, _cursorBlinkState ? 1.0f : 0.0f);
571  }
572 
573  TextureMan.reset();
574  glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
575 
576 
577  // Backdrop
578  glBegin(GL_QUADS);
579  glVertex2f(_x , _y );
580  glVertex2f(_x + _width, _y );
581  glVertex2f(_x + _width, _y + _height);
582  glVertex2f(_x , _y + _height);
583  glEnd();
584 
585  // Bottom edge
586  glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
587  glBegin(GL_QUADS);
588  glVertex2f(_x , _y - 3.0f);
589  glVertex2f(_x + _width, _y - 3.0f);
590  glVertex2f(_x + _width, _y );
591  glVertex2f(_x , _y );
592  glEnd();
593 
594  // Scrollbar background
595  glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
596  glBegin(GL_QUADS);
597  glVertex2f(_x + _width - 12.0f, _y );
598  glVertex2f(_x + _width , _y );
599  glVertex2f(_x + _width , _y + _height);
600  glVertex2f(_x + _width - 12.0f, _y + _height);
601  glEnd();
602 
603  // Scrollbar
604  glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
605  glBegin(GL_QUADS);
606  glVertex2f(_x + _width - 10.0f, _y + 2.0f + _scrollbarPosition);
607  glVertex2f(_x + _width - 2.0f, _y + 2.0f + _scrollbarPosition);
608  glVertex2f(_x + _width - 2.0f, _y + 2.0f + _scrollbarPosition + _scrollbarLength);
609  glVertex2f(_x + _width - 10.0f, _y + 2.0f + _scrollbarPosition + _scrollbarLength);
610  glEnd();
611 
612  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
613 }
614 
615 void ConsoleWindow::notifyResized(int UNUSED(oldWidth), int UNUSED(oldHeight),
616  int newWidth, int newHeight) {
617 
618  _width = newWidth;
619 
620  _x = -(newWidth / 2.0f);
621  _y = (newHeight / 2.0f) - _height;
622 
623  float textY = (newHeight / 2.0f) - _lineHeight;
624  for (size_t i = 0; i < _lines.size(); i++, textY -= _lineHeight)
625  _lines[i]->setPosition(_x, textY, -1001.0f);
626 
627  _prompt->setPosition(_x , _y, -1001.0f);
628  _input ->setPosition(_x + _prompt->getWidth(), _y, -1001.0f);
629 
630  recalcCursor();
631 }
632 
633 size_t ConsoleWindow::findWordStart(const Common::UString &line, size_t pos) {
634  Common::UString::iterator it = line.getPosition(pos);
635  if ((it == line.end()) || (*it == ' '))
636  return 0;
637 
638  while ((it != line.begin()) && (*it != ' '))
639  --it;
640 
641  if (*it == ' ')
642  ++it;
643 
644  return line.getPosition(it);
645 }
646 
647 size_t ConsoleWindow::findWordEnd(const Common::UString &line, size_t pos) {
648  Common::UString::iterator it = line.getPosition(pos);
649  if ((it == line.end()) || (*it == ' '))
650  return 0;
651 
652  while ((it != line.end()) && (*it != ' '))
653  ++it;
654 
655  return line.getPosition(it);
656 }
657 
659  Common::UString input = _inputText;
660  input.truncate(_cursorPosition);
661 
662  const float cursorX = _x + _prompt->getWidth() + _font.getFont().getWidth(input) - 1.0f;
663  _cursor->setPosition(cursorX, _y, -1002.0f);
664 
665  const float cursorWidth = 1.0f + (_overwrite ? _font.getFont().getWidth(' ') : 0.0f);
666  _cursor->setWidth(cursorWidth);
667 }
668 
670  GfxMan.lockFrame();
671 
672  std::list<Common::UString>::reverse_iterator h = _history.rbegin();
673  for (size_t i = 0; (i < _historyStart) && (h != _history.rend()); i++, ++h);
674 
675  for (int i = _lines.size() - 1; (i >= 0) && (h != _history.rend()); i--, ++h)
676  _lines[i]->setText(*h);
677 
678  GfxMan.unlockFrame();
679 }
680 
682  float length = 1.0f;
683 
684  if (_historySizeCurrent > 0)
685  length = ((float) _lines.size()) / _historySizeCurrent;
686 
687  const float height = _height - 4.0f;
688  _scrollbarLength = floorf(CLIP(length * height, 8.0f, height));
689 }
690 
692  float position = 0.0f;
693 
694  int max = _historySizeCurrent - _lines.size();
695  if (max > 0)
696  position = ((float) _historyStart) / max;
697 
698  const float span = (_height - 4.0f) - _scrollbarLength;
699  _scrollbarPosition = floorf(CLIP(position * span, 0.0f, span));
700 }
701 
702 
703 Console::Console(Engine &engine, const Common::UString &font, int fontHeight) :
704  _engine(&engine), _neverShown(true), _visible(false), _tabCount(0),
705  _printedCompleteWarning(false), _lastClickCount(-1),
706  _lastClickButton(0), _lastClickTime(0), _lastClickX(0), _lastClickY(0),
707  _maxSizeVideos(0), _maxSizeSounds(0) {
708 
710  _console.reset(new ConsoleWindow(font, kConsoleLines, kConsoleHistory, fontHeight));
711 
712  _readLine->historyIgnoreDups(true);
713 
714  registerCommand("help" , boost::bind(&Console::cmdHelp , this, _1),
715  "Usage: help [<command>]\nPrint help text");
716  registerCommand("clear" , boost::bind(&Console::cmdClear , this, _1),
717  "Usage: clear\nClear the console window");
718  registerCommand("close" , boost::bind(&Console::cmdClose , this, _1),
719  "Usage: close\nClose the console window, returning to the game");
720  registerCommand("quit" , boost::bind(&Console::cmdQuit , this, _1),
721  "Usage: quit\nQuit xoreos entirely");
722  registerCommand("dumpreslist", boost::bind(&Console::cmdDumpResList, this, _1),
723  "Usage: dumpreslist <file>\nDump the current list of resources to file");
724  registerCommand("dumpres" , boost::bind(&Console::cmdDumpRes , this, _1),
725  "Usage: dumpres <resource>\nDump a resource to file");
726  registerCommand("dumptga" , boost::bind(&Console::cmdDumpTGA , this, _1),
727  "Usage: dumptga <resource>\nDump an image resource into a TGA");
728  registerCommand("dump2da" , boost::bind(&Console::cmdDump2DA , this, _1),
729  "Usage: dump2da <2da>\nDump a 2DA to file");
730  registerCommand("dumpall2da" , boost::bind(&Console::cmdDumpAll2DA , this, _1),
731  "Usage: dumpall2da\nDump all 2DA to file");
732  registerCommand("listvideos" , boost::bind(&Console::cmdListVideos , this, _1),
733  "Usage: listvideos\nList all available videos");
734  registerCommand("playvideo" , boost::bind(&Console::cmdPlayVideo , this, _1),
735  "Usage: playvideo <video>\nPlay the specified video");
736  registerCommand("listsounds" , boost::bind(&Console::cmdListSounds , this, _1),
737  "Usage: listsounds\nList all available sounds");
738  registerCommand("playsound" , boost::bind(&Console::cmdPlaySound , this, _1),
739  "Usage: playsound <sound>\nPlay the specified sound");
740  registerCommand("silence" , boost::bind(&Console::cmdSilence , this, _1),
741  "Usage: silence\nStop all playing sounds and music");
742  registerCommand("getoption" , boost::bind(&Console::cmdGetOption , this, _1),
743  "Usage: getoption <option>\nPrint the value of a config options");
744  registerCommand("setoption" , boost::bind(&Console::cmdSetOption , this, _1),
745  "Usage: setoption <option> <value>\nSet the value of a config option for this session");
746  registerCommand("showfps" , boost::bind(&Console::cmdShowFPS , this, _1),
747  "Usage: showfps <true/false>\nShow/Hide the frames-per-second display");
748  registerCommand("listlangs" , boost::bind(&Console::cmdListLangs , this, _1),
749  "Usage: listlangs\nLists all languages supported by this game version");
750  registerCommand("getlang" , boost::bind(&Console::cmdGetLang , this, _1),
751  "Usage: getlang\nPrint the current language settings");
752  registerCommand("setlang" , boost::bind(&Console::cmdSetLang , this, _1),
753  "Usage: setlang <language>\n setlang <language_text> <language_voice>\n"
754  "Change the game's current language");
755  registerCommand("getstring" , boost::bind(&Console::cmdGetString , this, _1),
756  "Usage: getstring <strref>\nGet a string from the talk manager and print it");
757  registerCommand("getcamera" , boost::bind(&Console::cmdGetCamera , this, _1),
758  "Usage: getcamera\nPrint the current camera position and orientation");
759  registerCommand("setcamera" , boost::bind(&Console::cmdSetCamera , this, _1),
760  "Usage: setcamera <posX> <posY> <posZ> [<orientX> <orientY> <orientZ>]\n"
761  "Set the camera position (and orientation)");
762 
763  _console->print("Console ready...");
764 }
765 
767  hide();
768 }
769 
771  if (_visible)
772  return;
773 
774  if (_neverShown)
775  _console->print("Type 'close' to return to the game. Type 'help' for a list of commands.");
776 
777  _console->show();
778  _visible = true;
779  _neverShown = false;
780 
781  updateCaches();
782  showCallback();
783 
784  EventMan.enableTextInput(true);
785 }
786 
788  if (!_visible)
789  return;
790 
791  _console->hide();
792  _visible = false;
793 
794  EventMan.enableTextInput(false);
795 }
796 
797 bool Console::isVisible() const {
798  return _visible;
799 }
800 
801 float Console::getWidth() const {
802  return _console->getContentWidth();
803 }
804 
805 float Console::getHeight() const {
806  return _console->getContentHeight();
807 }
808 
809 size_t Console::getLines() const {
810  return _console->getLines();
811 }
812 
813 size_t Console::getColumns() const {
814  return _console->getColumns();
815 }
816 
818  if (!isVisible())
819  return false;
820 
821  if (event.type == Events::kEventMouseDown) {
822 
823  const uint8 button = event.button.button;
824  const uint8 pasteMask1 = SDL_BUTTON_MMASK;
825  const uint8 pasteMask2 = SDL_BUTTON_LMASK | SDL_BUTTON_RMASK;
826 
827  // Pasting the current buffer with the middle (or left+right) mouse button
828  if (((button & pasteMask1) == pasteMask1) || ((button & pasteMask2) == pasteMask2)) {
829  _readLine->addInput(_console->getHighlight());
830  _console->setInput(_readLine->getCurrentLine(),
831  _readLine->getCursorPosition(), _readLine->getOverwrite());
832  return true;
833  }
834 
835  // Highlight while dragging the left mouse button
836  if (button & SDL_BUTTON_LMASK) {
837  _console->startHighlight(event.button.x, event.button.y);
838  return true;
839  }
840  }
841 
842  if (event.type == Events::kEventMouseMove) {
843 
844  // Highlight while dragging the left mouse button
845  if (event.motion.state & SDL_BUTTON_LMASK) {
846  _console->stopHighlight(event.button.x, event.button.y);
847  return true;
848  }
849  }
850 
851  if (event.type == Events::kEventMouseUp) {
852 
853  uint32 curTime = EventMan.getTimestamp();
854 
855  if (((curTime - _lastClickTime) < kDoubleClickTime) &&
856  (_lastClickButton == event.button.button) &&
857  (_lastClickX == event.button.x) && (_lastClickY == event.button.y))
858  _lastClickCount = (_lastClickCount + 1) % 3;
859  else
860  _lastClickCount = 0;
861 
862  _lastClickButton = event.button.button;
863  _lastClickTime = curTime;
864  _lastClickX = event.button.x;
865  _lastClickY = event.button.y;
866 
867  if (event.button.button & SDL_BUTTON_LMASK) {
868  if (_lastClickCount == 0)
869  // Stop highlighting when release the mouse
870  _console->stopHighlight(event.button.x, event.button.y);
871  else if (_lastClickCount == 1)
872  // Click twice to highlight a word
873  _console->highlightWord(event.button.x, event.button.y);
874  else if (_lastClickCount == 2)
875  // Click thrice to highlight the whole line
876  _console->highlightLine(event.button.x, event.button.y);
877 
878  return true;
879  }
880 
881  }
882 
883  if (event.type == Events::kEventKeyDown) {
884  _console->clearHighlight();
885 
886  // Autocomplete with tab
887  if (event.key.keysym.sym != SDLK_TAB) {
888  _tabCount = 0;
889  _printedCompleteWarning = false;
890  } else
891  _tabCount++;
892 
893  // Close the console with escape or Ctrl-D
894  if ((event.key.keysym.sym == SDLK_ESCAPE) ||
895  ((event.key.keysym.sym == SDLK_d) && (event.key.keysym.mod & KMOD_CTRL))) {
896  hide();
897  return true;
898  }
899 
900  // Ctrl-L clear the console
901  if ((event.key.keysym.sym == SDLK_l) && (event.key.keysym.mod & KMOD_CTRL)) {
902  clear();
903  return true;
904  }
905 
906  // Scroll up half a screen with Shift-PageUp
907  if ((event.key.keysym.sym == SDLK_PAGEUP) && (event.key.keysym.mod & KMOD_SHIFT)) {
908  _console->scrollUp(kConsoleLines / 2);
909  return true;
910  }
911 
912  // Scroll down half a screen with Shift-PageUp
913  if ((event.key.keysym.sym == SDLK_PAGEDOWN) && (event.key.keysym.mod & KMOD_SHIFT)) {
914  _console->scrollDown(kConsoleLines / 2);
915  return true;
916  }
917 
918  // Scroll up a line with PageUp
919  if (event.key.keysym.sym == SDLK_PAGEUP) {
920  _console->scrollUp();
921  return true;
922  }
923 
924  // Scroll down a line with PageUp
925  if (event.key.keysym.sym == SDLK_PAGEDOWN) {
926  _console->scrollDown();
927  return true;
928  }
929 
930  // Shift-Home scrolls to the top
931  if ((event.key.keysym.sym == SDLK_HOME) && (event.key.keysym.mod & KMOD_SHIFT)) {
932  _console->scrollTop();
933  return true;
934  }
935 
936  // Shift-Home scrolls to the bottom
937  if ((event.key.keysym.sym == SDLK_END) && (event.key.keysym.mod & KMOD_SHIFT)) {
938  _console->scrollBottom();
939  return true;
940  }
941 
942 
943  } else if (event.type == Events::kEventMouseWheel) {
944  // Scroll up / down using the mouse wheel
945 
946  if (event.wheel.y > 0) {
947  _console->scrollUp();
948  return true;
949  }
950 
951  if (event.wheel.y < 0) {
952  _console->scrollDown();
953  return true;
954  }
955  }
956 
957  Common::UString command;
958  if (!_readLine->processEvent(event, command))
959  return false;
960 
961  _console->setInput(_readLine->getCurrentLine(),
962  _readLine->getCursorPosition(), _readLine->getOverwrite());
963 
964  // Check whether we have tab-completion hints
965  if (printHints(command))
966  return true;
967 
968  execute(command);
969  return true;
970 }
971 
972 void Console::disableCommand(const Common::UString &cmd, const Common::UString &reason) {
973  CommandMap::iterator c = _commands.find(cmd);
974  if (c == _commands.end()) {
975  throw Common::Exception("No such command \"%s\"", cmd.c_str());
976  return;
977  }
978 
979  c->second.disabled = true;
980  c->second.disableReason = reason;
981 }
982 
984  CommandMap::iterator c = _commands.find(cmd);
985  if (c == _commands.end()) {
986  throw Common::Exception("No such command \"%s\"", cmd.c_str());
987  return;
988  }
989 
990  c->second.disabled = false;
991 }
992 
994  if (line.empty())
995  return;
996 
997  // Add the line to console
998  _console->print(Common::UString(kPrompt) + line);
999 
1000 
1001  // Split command from redirect target
1002 
1003  Common::UString command;
1004  Common::UString redirect;
1005  line.split(line.findFirst('>'), command, redirect, true);
1006 
1007  command.trim();
1008  redirect.trim();
1009 
1010 
1011  // Split command from arguments
1012 
1013  CommandLine cl;
1014 
1015  command.split(command.findFirst(' '), cl.cmd, cl.args, true);
1016 
1017  cl.cmd.trim();
1018  cl.args.trim();
1019 
1020 
1021  // Find the command
1022  CommandMap::iterator cmd = _commands.find(cl.cmd);
1023  if (cmd == _commands.end()) {
1024  printf("Unknown command \"%s\". Type 'help' for a list of available commands.",
1025  cl.cmd.c_str());
1026  return;
1027  }
1028 
1029  if (cmd->second.disabled) {
1030  if (cmd->second.disableReason.empty())
1031  printf("Command \"%s\" is currently disabled.", cl.cmd.c_str());
1032  else
1033  printf("Command \"%s\" is currently disabled: %s.", cl.cmd.c_str(),
1034  cmd->second.disableReason.c_str());
1035 
1036  return;
1037  }
1038 
1039  // Set redirect
1040  if (!_console->setRedirect(redirect))
1041  return;
1042 
1043  // Execute
1044  _console->hidePrompt();
1045  cmd->second.callback(cl);
1046  _console->showPrompt();
1047 
1048  // Reset redirect
1049  _console->setRedirect();
1050 }
1051 
1052 bool Console::printHints(const Common::UString &command) {
1053  if (_tabCount < 2)
1054  return false;
1055 
1056  size_t maxSize;
1057  const std::vector<Common::UString> &hints = _readLine->getCompleteHint(maxSize);
1058  if (hints.empty())
1059  return false;
1060 
1061  maxSize = MAX<size_t>(maxSize, 3) + 2;
1062  size_t lineSize = getColumns() / maxSize;
1063  size_t lines = hints.size() / lineSize;
1064 
1065  if (lines >= (kConsoleLines - 3)) {
1067  printf("%u completion candidates", (uint)hints.size());
1068 
1069  _printedCompleteWarning = true;
1070 
1071  if (_tabCount < 4)
1072  return true;
1073  }
1074 
1075  _console->scrollBottom();
1076  _console->print(Common::UString(kPrompt) + " " + command);
1077  printList(hints, maxSize);
1078 
1079  _tabCount = 0;
1080  _printedCompleteWarning = false;
1081 
1082  return true;
1083 }
1084 
1086  _console->clear();
1087 }
1088 
1089 void Console::print(const Common::UString &line) {
1090  _console->print(line);
1091 }
1092 
1093 void Console::printf(const char *s, ...) {
1094  char buf[STRINGBUFLEN];
1095  va_list va;
1096 
1097  va_start(va, s);
1098  vsnprintf(buf, STRINGBUFLEN, s, va);
1099  va_end(va);
1100 
1101  print(buf);
1102 }
1103 
1105  Common::Exception::Stack &stack = e.getStack();
1106 
1107  if (stack.empty()) {
1108  print("FATAL ERROR");
1109  return;
1110  }
1111 
1112  printf("%s%s", prefix.c_str(), stack.top().c_str());
1113 
1114  stack.pop();
1115 
1116  while (!stack.empty()) {
1117  printf("'- Because: %s", stack.top().c_str());
1118  stack.pop();
1119  }
1120 }
1121 
1123  updateVideos();
1124  updateSounds();
1125 }
1126 
1128  _videos.clear();
1129  _maxSizeVideos = 0;
1130 
1131  std::list<Aurora::ResourceManager::ResourceID> videos;
1132  ResMan.getAvailableResources(Aurora::kResourceVideo, videos);
1133 
1134  for (std::list<Aurora::ResourceManager::ResourceID>::const_iterator v = videos.begin();
1135  v != videos.end(); ++v) {
1136 
1137  _videos.push_back(v->name);
1138 
1139  _maxSizeVideos = MAX(_maxSizeVideos, _videos.back().size());
1140  }
1141 
1142  setArguments("playvideo", _videos);
1143 }
1144 
1146  _sounds.clear();
1147  _maxSizeSounds = 0;
1148 
1149  std::list<Aurora::ResourceManager::ResourceID> sounds;
1150  ResMan.getAvailableResources(Aurora::kFileTypeWAV, sounds);
1151 
1152  for (std::list<Aurora::ResourceManager::ResourceID>::const_iterator s = sounds.begin();
1153  s != sounds.end(); ++s) {
1154 
1155  _sounds.push_back(s->name);
1156 
1157  _maxSizeSounds = MAX(_maxSizeSounds, _sounds.back().size());
1158  }
1159 
1160  setArguments("playsound", _sounds);
1161 }
1162 
1163 void Console::cmdHelp(const CommandLine &cli) {
1164  if (cli.args.empty()) {
1165  printFullHelp();
1166  return;
1167  }
1168 
1169  printCommandHelp(cli.args);
1170 }
1171 
1173  clear();
1174 }
1175 
1177  hide();
1178 }
1179 
1181  print("Bye...");
1182  EventMan.requestQuit();
1183 }
1184 
1186  if (cl.args.empty()) {
1187  printCommandHelp(cl.cmd);
1188  return;
1189  }
1190 
1192 
1193  if (dumpResList(file))
1194  printf("Dumped list of resources to file \"%s\"", file.c_str());
1195  else
1196  printf("Failed dumping list of resources to file \"%s\"", file.c_str());
1197 }
1198 
1200  if (cl.args.empty()) {
1201  printCommandHelp(cl.cmd);
1202  return;
1203  }
1204 
1206 
1207  if (dumpResource(cl.args, file))
1208  printf("Dumped resource \"%s\" to \"%s\"", cl.args.c_str(), file.c_str());
1209  else
1210  printf("Failed dumping resource \"%s\"", cl.args.c_str());
1211 }
1212 
1214  if (cl.args.empty()) {
1215  printCommandHelp(cl.cmd);
1216  return;
1217  }
1218 
1220 
1221  if (dumpTGA(cl.args, file))
1222  printf("Dumped TGA \"%s\" to \"%s\"", cl.args.c_str(), file.c_str());
1223  else
1224  printf("Failed dumping TGA \"%s\"", cl.args.c_str());
1225 }
1226 
1228  if (cl.args.empty()) {
1229  printCommandHelp(cl.cmd);
1230  return;
1231  }
1232 
1234 
1235  if (dump2DA(cl.args, file))
1236  printf("Dumped 2DA \"%s\" to \"%s\"", cl.args.c_str(), file.c_str());
1237  else
1238  printf("Failed dumping 2DA \"%s\"", cl.args.c_str());
1239 }
1240 
1242  std::list<Aurora::ResourceManager::ResourceID> twoda;
1243  ResMan.getAvailableResources(Aurora::kFileType2DA, twoda);
1244 
1245  std::list<Aurora::ResourceManager::ResourceID>::const_iterator t;
1246  for (t = twoda.begin(); t != twoda.end(); ++t) {
1247  Common::UString file = Common::FilePath::getUserDataFile(t->name) + ".2da";
1248 
1249  if (dump2DA(t->name, file))
1250  printf("Dumped 2DA \"%s\" to \"%s\"", t->name.c_str(), file.c_str());
1251  else
1252  printf("Failed dumping 2DA \"%s\"", t->name.c_str());
1253  }
1254 }
1255 
1257  updateVideos();
1259 }
1260 
1262  if (cl.args.empty()) {
1263  printCommandHelp(cl.cmd);
1264  return;
1265  }
1266 
1267  playVideo(cl.args);
1268 }
1269 
1271  updateSounds();
1273 }
1274 
1276  if (cl.args.empty()) {
1277  printCommandHelp(cl.cmd);
1278  return;
1279  }
1280 
1282 }
1283 
1285  SoundMan.stopAll();
1286 }
1287 
1289  std::vector<Common::UString> args;
1290  splitArguments(cl.args, args);
1291 
1292  if (args.empty()) {
1293  printCommandHelp(cl.cmd);
1294  return;
1295  }
1296 
1297  printf("\"%s\" = \"%s\"", args[0].c_str(), ConfigMan.getString(args[0]).c_str());
1298 }
1299 
1301  std::vector<Common::UString> args;
1302  splitArguments(cl.args, args);
1303 
1304  if (args.size() < 2) {
1305  printCommandHelp(cl.cmd);
1306  return;
1307  }
1308 
1309  ConfigMan.setCommandlineKey(args[0], args[1]);
1310  _engine->showFPS();
1311 
1312  printf("\"%s\" = \"%s\"", args[0].c_str(), ConfigMan.getString(args[0]).c_str());
1313 }
1314 
1316  if (cl.args.empty()) {
1317  printCommandHelp(cl.cmd);
1318  return;
1319  }
1320 
1321  ConfigMan.setCommandlineKey("showfps", cl.args);
1322  _engine->showFPS();
1323 }
1324 
1326  std::vector<Aurora::Language> langs;
1327  if (_engine->detectLanguages(langs)) {
1328  if (!langs.empty()) {
1329  printf("Available languages:");
1330  for (std::vector<Aurora::Language>::iterator l = langs.begin(); l != langs.end(); ++l)
1331  printf("- %s", LangMan.getLanguageName(*l).c_str());
1332  }
1333  }
1334 
1335  std::vector<Aurora::Language> langsT, langsV;
1336  if (_engine->detectLanguages(langsT, langsV)) {
1337  if (!langsT.empty()) {
1338  printf("Available text languages:");
1339  for (std::vector<Aurora::Language>::iterator l = langsT.begin(); l != langsT.end(); ++l)
1340  printf("- %s", LangMan.getLanguageName(*l).c_str());
1341  }
1342 
1343  if (!langsV.empty()) {
1344  printf("Available voice languages:");
1345  for (std::vector<Aurora::Language>::iterator l = langsV.begin(); l != langsV.end(); ++l)
1346  printf("- %s", LangMan.getLanguageName(*l).c_str());
1347  }
1348  }
1349 }
1350 
1352  Aurora::Language lang;
1353  if (_engine->getLanguage(lang))
1354  printf("%s", LangMan.getLanguageName(lang).c_str());
1355 
1356  Aurora::Language langT, langV;
1357  if (_engine->getLanguage(langT, langV))
1358  printf("%s text + %s voices", LangMan.getLanguageName(langT).c_str(),
1359  LangMan.getLanguageName(langV).c_str());
1360 }
1361 
1363  std::vector<Common::UString> args;
1364  splitArguments(cl.args, args);
1365 
1366  if (args.size() == 1) {
1367  ConfigMan.setCommandlineKey("lang" , args[0]);
1368  ConfigMan.setCommandlineKey("langtext" , args[0]);
1369  ConfigMan.setCommandlineKey("langvoice", args[0]);
1370  } else if (args.size() == 2) {
1371  ConfigMan.setCommandlineKey("langtext" , args[0]);
1372  ConfigMan.setCommandlineKey("langvoice", args[1]);
1373  } else {
1374  printCommandHelp(cl.cmd);
1375  return;
1376  }
1377 
1378  if (_engine->changeLanguage()) {
1379  Aurora::Language lang;
1380  if (_engine->getLanguage(lang))
1381  printf("Changed language to %s", LangMan.getLanguageName(lang).c_str());
1382 
1383  Aurora::Language langT, langV;
1384  if (_engine->getLanguage(langT, langV))
1385  printf("Change language to %s text + %s voices", LangMan.getLanguageName(langT).c_str(),
1386  LangMan.getLanguageName(langV).c_str());
1387  } else
1388  printf("Failed to change the language");
1389 }
1390 
1392  CommandMap::const_iterator c = _commands.find(cmd);
1393  if (c == _commands.end()) {
1394  printFullHelp();
1395  return;
1396  }
1397 
1398  print(c->second.help);
1399 }
1400 
1402  if (cl.args.empty()) {
1403  printCommandHelp(cl.cmd);
1404  return;
1405  }
1406 
1407  uint32 strRef = 0xFFFFFFFF;
1408  try {
1409  Common::parseString(cl.args, strRef);
1410  } catch (...) {
1411  printCommandHelp(cl.cmd);
1412  return;
1413  }
1414 
1415  printf("\"%s\"", TalkMan.getString(strRef).c_str());
1416 }
1417 
1419  const float *pos = CameraMan.getPosition();
1420  const float *orient = CameraMan.getOrientation();
1421 
1422  printf("Position : % 9.3f, % 9.3f, % 9.3f", pos [0], pos [1], pos [2]);
1423  printf("Orientation: % 9.3f, % 9.3f, % 9.3f", orient[0], orient[1], orient[2]);
1424 }
1425 
1427  std::vector<Common::UString> args;
1428  splitArguments(cl.args, args);
1429 
1430  if ((args.size() != 3) && (args.size() != 6)) {
1431  printCommandHelp(cl.cmd);
1432  return;
1433  }
1434 
1435  float pos[3] = {0.0f, 0.0f, 0.0f}, orient[3] = {0.0f, 0.0f, 0.0f};
1436 
1437  try {
1438  for (size_t i = 0; i < 3; i++)
1439  Common::parseString(args[i], pos[i]);
1440  } catch (...) {
1441  printCommandHelp(cl.cmd);
1442  return;
1443  }
1444 
1445  if (args.size() > 3) {
1446  try {
1447  for (size_t i = 0; i < 3; i++)
1448  Common::parseString(args[3 + i], orient[i]);
1449  } catch (...) {
1450  printCommandHelp(cl.cmd);
1451  return;
1452  }
1453  }
1454 
1455  CameraMan.setPosition(pos[0], pos[1], pos[2]);
1456 
1457  if (args.size() > 3)
1458  CameraMan.setOrientation(orient[0], orient[1], orient[2]);
1459 
1460  CameraMan.update();
1461 }
1462 
1464  print("Available commands (help <command> for further help on each command):");
1465 
1466  size_t maxSize = 0;
1467  std::vector<Common::UString> commands;
1468  commands.reserve(_commands.size());
1469 
1470  for (CommandMap::const_iterator c = _commands.begin(); c != _commands.end(); ++c) {
1471  commands.push_back(c->second.cmd);
1472 
1473  maxSize = MAX(maxSize, commands.back().size());
1474  }
1475 
1476  printList(commands, maxSize);
1477 }
1478 
1479 void Console::printList(const std::vector<Common::UString> &list, size_t maxSize) {
1480  const size_t columns = getColumns();
1481 
1482  // If no max size is given, go through the whole list to find it ourselves
1483  if (maxSize == 0)
1484  for (std::vector<Common::UString>::const_iterator l = list.begin(); l != list.end(); ++l)
1485  maxSize = MAX<size_t>(maxSize, l->size());
1486 
1487  maxSize = MAX<size_t>(maxSize, 3);
1488 
1489  // Calculate the number of items per line
1490  size_t lineSize = 1;
1491  if (maxSize >= (columns - 2))
1492  maxSize = columns;
1493  else if (maxSize > 0)
1494  lineSize = columns / (maxSize + 2);
1495 
1496  // Calculate the number of number of lines that won't fit into the history
1497  size_t toPrint = MIN<size_t>((kConsoleHistory - 1) * lineSize, list.size());
1498  size_t linesCut = list.size() - toPrint;
1499 
1500  // Print a message when we cut items
1501  if (linesCut > 0) {
1502  Common::UString cutMsg =
1503  Common::UString::format("(%u items cut due to history overflow)", (uint)linesCut);
1504 
1505  print(cutMsg);
1506  }
1507 
1508  // Move past the items we're cutting
1509  std::vector<Common::UString>::const_iterator l = list.begin();
1510  std::advance(l, linesCut);
1511 
1512  // Print the lines
1513  while (l != list.end()) {
1514  Common::UString line;
1515 
1516  // Attach the items together that go onto one line
1517  for (size_t i = 0; (i < lineSize) && (l != list.end()); i++, ++l) {
1518  Common::UString item = *l;
1519 
1520  size_t itemSize = item.size();
1521 
1522  if (itemSize > maxSize) {
1523  item.truncate(maxSize - 3);
1524  item += "...";
1525  itemSize = maxSize;
1526  }
1527 
1528  size_t pad = (maxSize + 2) - itemSize;
1529  while (pad-- > 0)
1530  item += ' ';
1531 
1532  line += item;
1533  }
1534 
1535  print(line);
1536  }
1537 }
1538 
1539 void Console::splitArguments(Common::UString argLine, std::vector<Common::UString> &args) {
1540  bool inQuote = false;
1541 
1542  if (args.empty())
1543  args.push_back(Common::UString());
1544 
1545  for (Common::UString::iterator c = argLine.begin(); c != argLine.end(); ++c) {
1546  if (*c == '"') {
1547  inQuote = !inQuote;
1548  continue;
1549  }
1550 
1551  if (*c == ' ' && !inQuote) {
1552  if (!args.back().empty())
1553  args.push_back(Common::UString());
1554 
1555  continue;
1556  }
1557 
1558  args.back() += *c;
1559  }
1560 
1561  if (args.back().empty())
1562  args.pop_back();
1563 }
1564 
1565 void Console::setArguments(const Common::UString &cmd, const std::vector<Common::UString> &args) {
1566  _readLine->setArguments(cmd, args);
1567 }
1568 
1570  _readLine->setArguments(cmd);
1571 }
1572 
1574 }
1575 
1577  const Common::UString &help) {
1578 
1579 
1580  std::pair<CommandMap::iterator, bool> result;
1581 
1582  result = _commands.insert(std::make_pair(cmd, Command()));
1583  if (!result.second)
1584  return false;
1585 
1586  result.first->second.cmd = cmd;
1587  result.first->second.help = help;
1588 
1589  result.first->second.callback = callback;
1590 
1591  result.first->second.disabled = false;
1592 
1593  _readLine->addCommand(cmd);
1594 
1596 
1597  return true;
1598 }
1599 
1601  std::vector<Common::UString> commands;
1602  for (CommandMap::const_iterator c = _commands.begin(); c != _commands.end(); ++c)
1603  commands.push_back(c->second.cmd);
1604 
1605  _readLine->setArguments("help", commands);
1606 }
1607 
1608 } // End of namespace Engines
void printLine(const Common::UString &line)
Definition: console.cpp:279
virtual bool getLanguage(Aurora::Language &language) const
Return the game&#39;s current language.
Definition: engine.cpp:68
float getContentHeight() const
Definition: console.cpp:213
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Common::ScopedPtr< Graphics::Aurora::Text > _input
Definition: console.h:139
Table data, 2-dimensional text array.
Definition: types.h:86
static UString getUserDataDirectory()
Return the OS-specific path of the user data directory.
Definition: filepath.cpp:379
std::vector< Common::UString > _sounds
Definition: console.h:277
bool setRedirect(Common::UString redirect="")
Definition: console.cpp:302
T ABS(T x)
Definition: util.h:69
virtual void show()
Show the object.
Definition: renderable.cpp:114
Common::UString args
Definition: console.h:218
void playVideo(const Common::UString &video)
Play this video resource.
Definition: util.cpp:54
float getContentWidth() const
Definition: console.cpp:209
float getHeight() const
Definition: console.cpp:205
bool isVisible() const
Definition: console.cpp:797
The global graphics manager.
void highlightLine(int x, int y)
Definition: console.cpp:462
void updateHelpArguments()
Definition: console.cpp:1600
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
virtual ~Console()
Definition: console.cpp:766
virtual void hide()
Hide the object.
Definition: renderable.cpp:123
void cmdDumpTGA(const CommandLine &cl)
Definition: console.cpp:1213
void updateScrollbarLength()
Definition: console.cpp:681
Generic engine interface.
A class holding an UTF-8 string.
Definition: ustring.h:48
#define TextureMan
Shortcut for accessing the texture manager.
Definition: textureman.h:127
bool isIn(float x, float y) const
Is that point within the object?
Definition: console.cpp:188
uint8 _lastClickButton
Definition: console.h:269
void writeString(const UString &str)
Write the given string to the stream, encoded as UTF-8.
Definition: writestream.cpp:94
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
double _distance
The distance of the object from the viewer.
Definition: renderable.h:101
The global config manager.
bool dumpResList(const Common::UString &name)
Debug method to quickly dump the current list of resource to disk.
Definition: util.cpp:172
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
float getLineWidth(const Common::UString &text) const
Return the width of this string.
Definition: font.cpp:257
static const size_t kConsoleHistory
Definition: console.cpp:66
virtual float getLineSpacing() const
Return the size of space between lines.
Definition: font.cpp:39
The Aurora texture manager.
uint32 _lastClickTime
Definition: console.h:270
static size_t findWordStart(const Common::UString &line, size_t pos)
Definition: console.cpp:633
static const uint32 kDoubleClickTime
Definition: console.cpp:61
A text object.
Camera management.
static const size_t kConsoleLines
Definition: console.cpp:67
float split(const Common::UString &line, std::vector< Common::UString > &lines, float maxWidth=0.0f, float maxHeight=0.0f, bool trim=true) const
Definition: font.cpp:69
void truncate(const iterator &it)
Definition: ustring.cpp:343
iterator getPosition(size_t n) const
Convert a numerical position into an iterator.
Definition: ustring.cpp:501
size_t _tabCount
Definition: console.h:265
bool _printedCompleteWarning
Definition: console.h:266
iterator begin() const
Definition: ustring.cpp:253
bool dumpResource(const Common::UString &name, Aurora::FileType type, const Common::UString &file)
Debug method to quickly dump a resource to disk.
Definition: util.cpp:207
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
void execute(const Common::UString &line)
Definition: console.cpp:993
void cmdDumpAll2DA(const CommandLine &cl)
Definition: console.cpp:1241
Language
Definition: language.h:46
Stack & getStack()
Definition: error.cpp:84
iterator findFirst(uint32 c) const
Definition: ustring.cpp:261
void setPrompt(const Common::UString &prompt)
Definition: console.cpp:225
Utility templates and functions for working with strings and streams.
The Aurora font manager.
Mouse was moved.
Definition: types.h:48
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
static const size_t kCommandHistorySize
Definition: console.cpp:65
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
A class providing (limited) readline-like capabilities.
Mouse button was pressed.
Definition: types.h:49
Keyboard key was pressed.
Definition: types.h:46
void cmdDumpResList(const CommandLine &cl)
Definition: console.cpp:1185
Mouse button was released.
Definition: types.h:50
virtual void showCallback()
Definition: console.cpp:1573
std::stack< UString > Stack
Definition: error.h:38
void disableCommand(const Common::UString &cmd, const Common::UString &reason="")
Definition: console.cpp:972
UString substr(iterator from, iterator to) const
Definition: ustring.cpp:706
A text object.
Definition: text.h:42
void cmdListSounds(const CommandLine &cl)
Definition: console.cpp:1270
utf8::iterator< std::string::const_iterator > iterator
Definition: ustring.h:50
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
RenderPass
Definition: types.h:97
size_t getColumns() const
Definition: console.cpp:813
static UString getUserDataFile(UString file)
Return a path suitable for writing into.
Definition: filepath.cpp:383
void setClickable(bool clickable)
Set the object&#39;s clickable state.
Definition: renderable.cpp:94
bool open(const UString &fileName)
Try to open the file with the given fileName.
Definition: writefile.cpp:50
void cmdClose(const CommandLine &cl)
Definition: console.cpp:1176
Common::ScopedPtr< ConsoleWindow > _console
Definition: console.h:261
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
void cmdGetCamera(const CommandLine &cl)
Definition: console.cpp:1418
void cmdGetString(const CommandLine &cl)
Definition: console.cpp:1401
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
bool dumpTGA(const Common::UString &name, const Common::UString &file)
Debug method to quickly dump an image resource to disk.
Definition: util.cpp:221
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
The global events manager.
void cmdSetCamera(const CommandLine &cl)
Definition: console.cpp:1426
void printFullHelp()
Definition: console.cpp:1463
T MIN(T a, T b)
Definition: util.h:70
bool isOpen() const
Checks if the object opened a file successfully.
Definition: writefile.cpp:79
Common::ScopedPtr< Common::ReadLine > _readLine
Definition: console.h:260
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
static UString canonicalize(const UString &p, bool resolveSymLinks=true)
Return the canonical, absolutized and normalized path.
Definition: filepath.cpp:230
bool _neverShown
Definition: console.h:257
The global sound manager, handling all sound output.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
Generic Aurora engines (debug) console.
ConsoleWindow(const Common::UString &font, size_t lines, size_t history, int fontHeight=0)
Definition: console.cpp:71
#define SoundMan
Shortcut for accessing the sound manager.
Definition: sound.h:293
bool dump2DA(const Common::UString &name, const Common::UString &file)
Debug method to quickly dump a 2DA to disk.
Definition: util.cpp:232
StackException Exception
Definition: error.h:59
static UString getDirectory(const UString &p)
Return a path&#39;s directory.
Definition: filepath.cpp:107
void writeByte(byte value)
Definition: writestream.h:88
float getWidth() const
Definition: console.cpp:201
#define CursorMan
Shortcut for accessing the cursor manager.
Definition: cursorman.h:129
void cmdSetLang(const CommandLine &cl)
Definition: console.cpp:1362
void highlightWord(int x, int y)
Definition: console.cpp:436
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
void flush()
Commit any buffered data to the underlying channel or storage medium; unbuffered streams can use the ...
Definition: writefile.cpp:83
The Aurora cursor manager.
float getWidth() const
Definition: console.cpp:801
bool getPosition(int cursorX, int cursorY, float &x, float &y)
Definition: console.cpp:377
Sound::ChannelHandle playSound(const Common::UString &sound, Sound::SoundType soundType, bool loop, float volume, bool pitchVariance)
Play this sound resource.
Definition: util.cpp:81
CommandMap _commands
Definition: console.h:263
void printException(Common::Exception &e, const Common::UString &prefix="ERROR: ")
Definition: console.cpp:1104
void enableCommand(const Common::UString &cmd)
Definition: console.cpp:983
A video resource.
Definition: types.h:409
PointerType get() const
Returns the plain pointer value.
Definition: scopedptr.h:96
#define WindowMan
Shortcut for accessing the window manager.
Definition: windowman.h:137
size_t getLines() const
Definition: console.cpp:809
The base class for an engine within BioWare&#39;s Aurora family.
Definition: engine.h:49
virtual bool changeLanguage()
Change the game&#39;s current language.
Definition: engine.cpp:77
void close()
Close the file, if open.
Definition: writefile.cpp:69
int8 _lastClickCount
Definition: console.h:268
Common::WriteFile _redirect
Definition: console.h:165
#define STRINGBUFLEN
Definition: system.h:415
size_t size() const
Return the size of the string, in characters.
Definition: ustring.cpp:241
static const char * kPrompt
Definition: console.cpp:63
#define LangMan
Shortcut for accessing the language manager.
Definition: language.h:275
bool isVisible() const
Is the object visible?
Definition: renderable.cpp:106
void cmdShowFPS(const CommandLine &cl)
Definition: console.cpp:1315
void cmdDumpRes(const CommandLine &cl)
Definition: console.cpp:1199
static bool createDirectories(const UString &path)
Create all directories in this path.
Definition: filepath.cpp:342
static size_t findWordEnd(const Common::UString &line, size_t pos)
Definition: console.cpp:647
uint32_t uint32
Definition: types.h:204
void showFPS()
Evaluate the FPS display setting and show/hide the FPS display.
Definition: engine.cpp:91
The global talk manager for Aurora strings.
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
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
bool processEvent(const Events::Event &event)
Definition: console.cpp:817
void setTag(const Common::UString &tag)
Set the object&#39;s tag.
Definition: renderable.cpp:102
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
#define CameraMan
Shortcut for accessing the camera manager.
Definition: camera.h:83
Sound effect.
Definition: types.h:45
void cmdDump2DA(const CommandLine &cl)
Definition: console.cpp:1227
size_t _historySizeCurrent
Definition: console.h:133
Generic Aurora engines utility functions.
ptrdiff_t _highlightLength
Definition: console.h:162
Common::UString _inputText
Definition: console.h:142
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
void split(iterator splitPoint, UString &left, UString &right, bool remove=false) const
Definition: ustring.cpp:621
#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
iterator end() const
Definition: ustring.cpp:257
boost::function< void(const CommandLine &cl)> CommandCallback
Definition: console.h:221
size_t getColumns() const
Definition: console.cpp:221
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _highlight
Definition: console.h:130
void NORETURN_PRE error(const char *s,...)
Definition: util.cpp:86
T CLIP(T v, T amin, T amax)
Definition: util.h:72
virtual bool detectLanguages(Aurora::GameID game, const Common::UString &target, Aurora::Platform platform, std::vector< Aurora::Language > &languages) const
Detect which languages this game instance supports.
Definition: engine.cpp:45
A textured quad for a GUI element.
Common::WriteFile _logFile
Definition: console.h:164
T MAX(T a, T b)
Definition: util.h:71
void setArguments(const Common::UString &cmd, const std::vector< Common::UString > &args)
Definition: console.cpp:1565
virtual float getHeight() const =0
Return the height of a character.
void clear()
Clear the string&#39;s contents.
Definition: ustring.cpp:236
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
A font.
void parseString(const UString &str, T &value, bool allowEmpty)
Parse a string into any POD integer, float/double or bool type.
Definition: strutil.cpp:215
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
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
Audio, Waveform.
Definition: types.h:62
std::vector< Graphics::Aurora::Text * > _lines
Definition: console.h:138
virtual float getWidth(uint32 c) const =0
Return the width of a character.
The global resource manager for Aurora resources.
Utility class for manipulating file paths.
Only render opaque parts.
Definition: types.h:98
#define FontMan
Shortcut for accessing the font manager.
Definition: fontman.h:105
unsigned int uint
Definition: types.h:211
Engine * _engine
Definition: console.h:255
Mouse wheel was used.
Definition: types.h:51
void SWAP(T &a, T &b)
Template method which swaps the values of its two parameters.
Definition: util.h:78
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