2002-12-14 14:31:44 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2002-2006 The ScummVM project
|
2002-12-14 14:31:44 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-12-14 14:31:44 +00:00
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONSOLE_DIALOG_H
|
|
|
|
#define CONSOLE_DIALOG_H
|
|
|
|
|
2003-11-02 02:18:16 +00:00
|
|
|
#include "gui/dialog.h"
|
|
|
|
#include "gui/newgui.h"
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2002-12-14 15:45:45 +00:00
|
|
|
#include <stdarg.h>
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2002-12-14 14:31:44 +00:00
|
|
|
enum {
|
|
|
|
kBufferSize = 32768,
|
2002-12-14 18:57:15 +00:00
|
|
|
kLineBufferSize = 256,
|
2002-12-15 02:24:32 +00:00
|
|
|
|
2002-12-25 00:38:53 +00:00
|
|
|
kHistorySize = 20
|
2002-12-14 14:31:44 +00:00
|
|
|
};
|
|
|
|
|
2002-12-14 20:04:46 +00:00
|
|
|
class ScrollBarWidget;
|
|
|
|
|
2002-12-14 14:31:44 +00:00
|
|
|
class ConsoleDialog : public Dialog {
|
2002-12-15 00:36:34 +00:00
|
|
|
public:
|
|
|
|
typedef bool (*InputCallbackProc)(ConsoleDialog *console, const char *input, void *refCon);
|
2003-05-03 21:49:19 +00:00
|
|
|
typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, char*& completion, void *refCon);
|
2002-12-15 00:36:34 +00:00
|
|
|
|
2002-12-14 14:31:44 +00:00
|
|
|
protected:
|
2005-10-08 19:40:47 +00:00
|
|
|
const Graphics::Font *_font;
|
|
|
|
|
2002-12-14 14:31:44 +00:00
|
|
|
char _buffer[kBufferSize];
|
|
|
|
int _linesInBuffer;
|
|
|
|
|
|
|
|
int _lineWidth;
|
|
|
|
int _linesPerPage;
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-12-14 21:37:40 +00:00
|
|
|
int _currentPos;
|
2002-12-14 14:31:44 +00:00
|
|
|
int _scrollLine;
|
2004-05-23 14:06:52 +00:00
|
|
|
int _firstLineInBuffer;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-12-14 21:37:40 +00:00
|
|
|
int _promptStartPos;
|
|
|
|
int _promptEndPos;
|
2002-12-14 18:57:15 +00:00
|
|
|
|
|
|
|
bool _caretVisible;
|
|
|
|
uint32 _caretTime;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-12 21:23:21 +00:00
|
|
|
enum SlideMode {
|
|
|
|
kNoSlideMode,
|
|
|
|
kUpSlideMode,
|
|
|
|
kDownSlideMode
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-12 21:23:21 +00:00
|
|
|
SlideMode _slideMode;
|
2004-11-27 01:25:25 +00:00
|
|
|
uint32 _slideTime;
|
2003-03-06 19:52:54 +00:00
|
|
|
|
|
|
|
ScrollBarWidget *_scrollBar;
|
|
|
|
|
2002-12-15 00:36:34 +00:00
|
|
|
// The _callbackProc is called whenver a data line is entered
|
2005-07-30 21:11:48 +00:00
|
|
|
//
|
2002-12-15 00:36:34 +00:00
|
|
|
InputCallbackProc _callbackProc;
|
2003-03-06 19:52:54 +00:00
|
|
|
void *_callbackRefCon;
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2003-05-03 21:49:19 +00:00
|
|
|
// _completionCallbackProc is called when tab is pressed
|
|
|
|
CompletionCallbackProc _completionCallbackProc;
|
|
|
|
void *_completionCallbackRefCon;
|
|
|
|
|
2002-12-15 02:24:32 +00:00
|
|
|
char _history[kHistorySize][kLineBufferSize];
|
|
|
|
int _historySize;
|
|
|
|
int _historyIndex;
|
|
|
|
int _historyLine;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2003-09-20 01:08:48 +00:00
|
|
|
float _widthPercent, _heightPercent;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2004-11-27 01:25:25 +00:00
|
|
|
void slideUpAndClose();
|
2002-12-15 02:24:32 +00:00
|
|
|
|
2002-12-14 14:31:44 +00:00
|
|
|
public:
|
2003-11-02 02:18:16 +00:00
|
|
|
ConsoleDialog(float widthPercent, float heightPercent);
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2002-12-15 00:36:34 +00:00
|
|
|
void open();
|
2005-07-13 14:38:26 +00:00
|
|
|
void close();
|
2002-12-14 18:57:15 +00:00
|
|
|
void drawDialog();
|
|
|
|
|
|
|
|
void handleTickle();
|
2005-07-13 14:38:26 +00:00
|
|
|
void handleScreenChanged();
|
2002-12-14 20:04:46 +00:00
|
|
|
void handleMouseWheel(int x, int y, int direction);
|
2002-12-14 18:57:15 +00:00
|
|
|
void handleKeyDown(uint16 ascii, int keycode, int modifiers);
|
2002-12-14 20:04:46 +00:00
|
|
|
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2002-12-14 15:45:45 +00:00
|
|
|
int printf(const char *format, ...);
|
|
|
|
int vprintf(const char *format, va_list argptr);
|
|
|
|
#undef putchar
|
|
|
|
void putchar(int c);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-10-26 19:16:59 +00:00
|
|
|
void setInputCallback(InputCallbackProc proc, void *refCon) {
|
2002-12-15 00:36:34 +00:00
|
|
|
_callbackProc = proc;
|
|
|
|
_callbackRefCon = refCon;
|
|
|
|
}
|
2003-05-03 21:49:19 +00:00
|
|
|
void setCompletionCallback(CompletionCallbackProc proc, void *refCon) {
|
|
|
|
_completionCallbackProc = proc;
|
|
|
|
_completionCallbackRefCon = refCon;
|
|
|
|
}
|
2002-12-14 14:31:44 +00:00
|
|
|
|
|
|
|
protected:
|
2004-05-05 23:06:44 +00:00
|
|
|
inline char &buffer(int idx) {
|
|
|
|
return _buffer[idx % kBufferSize];
|
|
|
|
}
|
|
|
|
|
2002-12-14 18:57:15 +00:00
|
|
|
void drawCaret(bool erase);
|
2002-12-14 21:57:30 +00:00
|
|
|
void putcharIntern(int c);
|
2003-05-03 21:49:19 +00:00
|
|
|
void insertIntoPrompt(const char *str);
|
2002-12-14 15:45:45 +00:00
|
|
|
void print(const char *str);
|
2004-05-23 14:06:52 +00:00
|
|
|
void updateScrollBuffer();
|
2002-12-14 22:10:37 +00:00
|
|
|
void scrollToCurrent();
|
2002-12-14 21:37:40 +00:00
|
|
|
|
|
|
|
// Line editing
|
|
|
|
void specialKeys(int keycode);
|
2003-11-28 22:08:52 +00:00
|
|
|
void nextLine();
|
2002-12-14 22:25:09 +00:00
|
|
|
void killChar();
|
2002-12-14 21:37:40 +00:00
|
|
|
void killLine();
|
|
|
|
void killLastWord();
|
2002-12-15 02:24:32 +00:00
|
|
|
|
|
|
|
// History
|
|
|
|
void addToHistory(const char *str);
|
|
|
|
void historyScroll(int direction);
|
2002-12-14 14:31:44 +00:00
|
|
|
};
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|
|
|
|
|
2002-12-14 14:31:44 +00:00
|
|
|
#endif
|