diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/console.cpp | 25 | ||||
-rw-r--r-- | gui/console.h | 18 |
2 files changed, 36 insertions, 7 deletions
diff --git a/gui/console.cpp b/gui/console.cpp index a416d57192..9318e73d9a 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -48,7 +48,7 @@ This code is not finished, so please don't complain :-) * - a *lot* of others things, this code is in no way complete and heavily under progress */ ConsoleDialog::ConsoleDialog(NewGui *gui) - : Dialog(gui, 0, 0, 320, 6*kLineHeight+2) + : Dialog(gui, 0, 0, 320, 12*kLineHeight+2) { _lineWidth = (_w - kScrollBarWidth - 2) / kCharWidth; _linesPerPage = (_h - 2) / kLineHeight; @@ -70,8 +70,19 @@ ConsoleDialog::ConsoleDialog(NewGui *gui) print("ScummVM "SCUMMVM_VERSION" (" SCUMMVM_CVS ")\n"); print("Console is ready\n"); - print(PROMPT); - _promptStartPos = _promptEndPos = _currentPos; + _promptStartPos = _promptEndPos = -1; + + _callbackProc = 0; + _callbackRefCon = 0; +} + +void ConsoleDialog::open() +{ + Dialog::open(); + if (_promptStartPos == -1) { + print(PROMPT); + _promptStartPos = _promptEndPos = _currentPos; + } } void ConsoleDialog::drawDialog() @@ -138,12 +149,18 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) for (i = 0; i < len; i++) str[i] = _buffer[(_promptStartPos + i) % kBufferSize]; str[len] = 0; - printf("You entered '%s'\n", str); + + bool keepRunning = true; + if (_callbackProc) + keepRunning = (*_callbackProc)(this, str, _callbackRefCon); + //printf("You entered '%s'\n", str); print(PROMPT); _promptStartPos = _promptEndPos = _currentPos; draw(); + if (!keepRunning) + close(); break; } case 27: // escape diff --git a/gui/console.h b/gui/console.h index fd0042e9df..a3b91223a6 100644 --- a/gui/console.h +++ b/gui/console.h @@ -23,8 +23,6 @@ #include "dialog.h" #include "newgui.h" -#include "common/str.h" -#include "common/list.h" #include <stdarg.h> @@ -37,7 +35,9 @@ enum { class ScrollBarWidget; class ConsoleDialog : public Dialog { - typedef ScummVM::String String; +public: + typedef bool (*InputCallbackProc)(ConsoleDialog *console, const char *input, void *refCon); + protected: char _buffer[kBufferSize]; int _linesInBuffer; @@ -55,10 +55,16 @@ protected: uint32 _caretTime; ScrollBarWidget *_scrollBar; + + // The _callbackProc is called whenver a data line is entered + // + InputCallbackProc _callbackProc; + void *_callbackRefCon; public: ConsoleDialog(NewGui *gui); + void open(); void drawDialog(); void handleTickle(); @@ -70,6 +76,12 @@ public: int vprintf(const char *format, va_list argptr); #undef putchar void putchar(int c); + + void setInputeCallback(InputCallbackProc proc, void *refCon) + { + _callbackProc = proc; + _callbackRefCon = refCon; + } protected: void drawCaret(bool erase); |