diff options
-rw-r--r-- | gui/console.cpp | 121 | ||||
-rw-r--r-- | gui/console.h | 67 | ||||
-rw-r--r-- | gui/module.mk | 1 | ||||
-rw-r--r-- | scumm/dialogs.cpp | 46 | ||||
-rw-r--r-- | scumm/dialogs.h | 11 | ||||
-rw-r--r-- | scumm/scummvm.cpp | 5 |
6 files changed, 192 insertions, 59 deletions
diff --git a/gui/console.cpp b/gui/console.cpp new file mode 100644 index 0000000000..872496f269 --- /dev/null +++ b/gui/console.cpp @@ -0,0 +1,121 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2002 The ScummVM project + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Header$ + */ + +#include "stdafx.h" +#include "console.h" +#include "newgui.h" + +#include "common/engine.h" + +/* + + _ _ _ _ _ _ +| | | |_ __ __| | ___ _ __ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_(_) ___ _ __ +| | | | '_ \ / _` |/ _ \ '__| / __/ _ \| '_ \/ __| __| '__| | | |/ __| __| |/ _ \| '_ \ +| |_| | | | | (_| | __/ | | (_| (_) | | | \__ \ |_| | | |_| | (__| |_| | (_) | | | | + \___/|_| |_|\__,_|\___|_| \___\___/|_| |_|___/\__|_| \__,_|\___|\__|_|\___/|_| |_| + +This code is not finished, so please don't complain :-) + +*/ + +/* TODO: + * - it is very inefficient to redraw the full thingy when just one char is added/removed. + * Instead, we could just copy the GFX of the blank console (i.e. after the transparent + * background is drawn, before any text is drawn). Then using that, it becomes trivial + * to erase a single character, do scrolling etc. + * - add a scrollbar widget to allow scrolling in the history + * - a *lot* of others things, this code is in no way complete and heavily under progress + */ +ConsoleDialog::ConsoleDialog(NewGui *gui) + : Dialog(gui, 5, 0, 320-2*5, 5*kLineHeight+2) +{ + _lineWidth = (_w - 2) / kCharWidth; + _linesPerPage = (_h - 2) / kLineHeight; + + memset(_buffer, ' ', kBufferSize); + _linesInBuffer = kBufferSize / _lineWidth; + + _currentColumn = 0; + _currentLine = 0; + _scrollLine = 0; +} + +void ConsoleDialog::drawDialog() +{ + _gui->blendRect(_x, _y, _w, _h, _gui->_bgcolor); + + // Draw a border (might want to use different colors :-) + _gui->vline(_x, _y, _y+_h-1, _gui->_textcolorhi); + _gui->hline(_x, _y+_h-1, _x+_w-1, _gui->_textcolor); + _gui->vline(_x+_w-1, _y, _y+_h-1, _gui->_textcolor); + + // Draw text + int start = _scrollLine - _linesPerPage + 1; + int y = _y + 1; + for (int line = 0; line < _linesPerPage; line++) { + int x = _x + 1; + for (int column = 0; column < _lineWidth; column++) { + int l = (start+line+_linesInBuffer) % _linesInBuffer; + byte c = _buffer[l * _lineWidth + column]; + _gui->drawChar(c, x, y, _gui->_textcolor); + x += kCharWidth; + } + y += kLineHeight; + } + + _gui->addDirtyRect(_x, _y, _w, _h); +} + +void ConsoleDialog::nextLine() +{ + _currentColumn = 0; + if (_currentLine == _scrollLine) + _scrollLine = (_scrollLine + 1) % _linesInBuffer; + _currentLine = (_currentLine + 1) % _linesInBuffer; +} + +void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) { + if (ascii == '~' || (keycode == 27) || ascii == '#') { // Total abort on tilde or escape + close(); + } else if (ascii == '\r' || ascii == '\n') { // Run command on enter/newline + nextLine(); + draw(); + } else if (keycode == 8) { // Backspace + if (_currentColumn == 0) { + _currentColumn = _lineWidth - 1; + _currentLine--; + if (_currentLine < 0) + _currentLine = _linesInBuffer - 1; + } else + _currentColumn--; + _buffer[_currentLine * _lineWidth + _currentColumn] = ' '; + draw(); // FIXME - not nice to redraw the full console just for one char! + } else if ((ascii >= 31) && (ascii <= 122)) { // Printable ASCII, add to string + _buffer[_currentLine * _lineWidth + _currentColumn] = (char)ascii; + _currentColumn++; + if (_currentColumn >= _lineWidth) { + nextLine(); + } + draw(); // FIXME - not nice to redraw the full console just for one char! + } else { + debug(2, "Unhandled keycode from ConsoleDialog: %d\n", keycode); + } +} diff --git a/gui/console.h b/gui/console.h new file mode 100644 index 0000000000..1d06284dd8 --- /dev/null +++ b/gui/console.h @@ -0,0 +1,67 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2002 The ScummVM project + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Header$ + */ + +#ifndef CONSOLE_DIALOG_H +#define CONSOLE_DIALOG_H + +#include "dialog.h" +#include "common/str.h" +#include "common/list.h" + + +enum { + kBufferSize = 32768, + kCharWidth = 8 +}; + +class ConsoleDialog : public Dialog { + typedef ScummVM::String String; +protected: + char _buffer[kBufferSize]; + int _linesInBuffer; + + int _lineWidth; + int _linesPerPage; + + int _currentColumn; + int _currentLine; + int _scrollLine; + + +public: + ConsoleDialog(NewGui *gui); + +// void open(); +// void close(); + + virtual void drawDialog(); + virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers); +// void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); + + //printf(const char *format, ...) + //vprintf( +// void printString(const String &str); +// const String &readString(); + +protected: + void nextLine(); +}; + +#endif diff --git a/gui/module.mk b/gui/module.mk index 8a090e83d1..b31d0e7e31 100644 --- a/gui/module.mk +++ b/gui/module.mk @@ -3,6 +3,7 @@ MODULE := gui MODULE_OBJS = \ gui/browser.o \ gui/chooser.o \ + gui/console.o \ gui/dialog.o \ gui/EditTextWidget.o \ gui/launcher.o \ diff --git a/scumm/dialogs.cpp b/scumm/dialogs.cpp index 16b8cc21ba..c115295ca1 100644 --- a/scumm/dialogs.cpp +++ b/scumm/dialogs.cpp @@ -670,52 +670,6 @@ PauseDialog::PauseDialog(NewGui *gui, Scumm *scumm) { } -#pragma mark - - -DebuggerDialog::DebuggerDialog(NewGui *gui, Scumm *scumm, int width, int height) - : ScummDialog(gui, scumm, 0, 0, width, height) -{ - draw(); -} - -void DebuggerDialog::drawDialog() -{ - //int history_len = cmd_history.size(); - - // Draw box and border - _gui->blendRect(_x, _y, _w, _h, _gui->_bgcolor); - /*_gui->line(_x, _y, _x, _h, _gui->_color); - _gui->line(_w, _y, _w, _y, _gui->_color); - _gui->line(_x, _h, _w, _h, _gui->_shadowcolor);*/ - - _gui->addDirtyRect(_x, _y, _w, _h); - - // Draw items - // ... history_len - ((_h / kLineHeight) * _page) -} - -void DebuggerDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) { - if ((ascii == '~') || (keycode == 27)) { // Total abort on tilde or escape - close(); - return; - } else if (ascii == '\r' || ascii == '\n') { // Run command on enter/newline - // TODO: Add some kind of pop() method to StringList, - // so we can remove old obsolete entries and not waste memory - cmd_history.push_back(cmd_current); - // _scumm.debugger.parseCommand(cmd_current, (void*)this.printCallback); - cmd_current.clear(); - draw(); - } else if (keycode == 8) { // Backspace - cmd_current.deleteLastChar(); - draw(); - } else if ((keycode >= 31) && (keycode <= 122)) { // Printable ASCII, add to string - cmd_current+=(char)ascii; - draw(); - } else { - debug(2, "Unhandled keycode from DebuggerDialog: %d\n", keycode); - } -} - #ifdef _WIN32_WCE #pragma mark - diff --git a/scumm/dialogs.h b/scumm/dialogs.h index 4a0f27b22b..abe21082d2 100644 --- a/scumm/dialogs.h +++ b/scumm/dialogs.h @@ -134,17 +134,6 @@ public: PauseDialog(NewGui *gui, Scumm *scumm); }; -class DebuggerDialog : public ScummDialog { -protected: - ScummVM::StringList cmd_history; - String cmd_current; - -public: - DebuggerDialog(NewGui *gui, Scumm *scumm, int width, int height); - virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers); - virtual void drawDialog(); -}; - #ifdef _WIN32_WCE class KeysDialog : public ScummDialog { diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp index 7b77c9a176..b9d7e19e66 100644 --- a/scumm/scummvm.cpp +++ b/scumm/scummvm.cpp @@ -34,6 +34,7 @@ #include "verbs.h" #include "common/gameDetector.h" #include "common/config-file.h" +#include "gui/console.h" #include "gui/newgui.h" #include "gui/message.h" #include "sound/mixer.h" @@ -1003,7 +1004,7 @@ void Scumm::saveloadDialog() void Scumm::debuggerDialog() { if (!_debuggerDialog) - _debuggerDialog = new DebuggerDialog(_newgui, this, _realWidth, _realHeight / 5); + _debuggerDialog = new ConsoleDialog(_newgui); runDialog(_debuggerDialog); } @@ -1135,7 +1136,7 @@ void Scumm::processKbd() _defaultTalkDelay = 5; _vars[VAR_CHARINC] = _defaultTalkDelay / 20; - } else if (_lastKeyHit == '~') { // Debug console + } else if (_lastKeyHit == '~' || _lastKeyHit == '#') { // Debug console debuggerDialog(); } |