2002-12-14 14:31:44 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2003-03-06 21:46:56 +00:00
|
|
|
* Copyright (C) 2002-2003 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $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
|
|
|
|
|
|
|
enum {
|
|
|
|
kBufferSize = 32768,
|
2002-12-14 18:57:15 +00:00
|
|
|
kLineBufferSize = 256,
|
2002-12-15 02:24:32 +00:00
|
|
|
kCharWidth = 8,
|
|
|
|
|
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:
|
|
|
|
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;
|
|
|
|
|
2002-12-14 21:37:40 +00:00
|
|
|
int _promptStartPos;
|
|
|
|
int _promptEndPos;
|
2002-12-14 18:57:15 +00:00
|
|
|
|
|
|
|
bool _caretVisible;
|
|
|
|
uint32 _caretTime;
|
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
|
|
|
|
//
|
|
|
|
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-09-20 01:08:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
float _widthPercent, _heightPercent;
|
|
|
|
|
|
|
|
void reflowLayout();
|
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();
|
2002-12-14 18:57:15 +00:00
|
|
|
void drawDialog();
|
|
|
|
|
|
|
|
void handleTickle();
|
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);
|
2002-12-15 00:36:34 +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:
|
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);
|
2002-12-14 14:31:44 +00:00
|
|
|
void nextLine();
|
2002-12-14 20:04:46 +00:00
|
|
|
void updateScrollBar();
|
2002-12-14 22:10:37 +00:00
|
|
|
void scrollToCurrent();
|
2002-12-14 21:37:40 +00:00
|
|
|
inline int getBufferPos() const { return _currentPos % kBufferSize; }
|
|
|
|
|
|
|
|
// Line editing
|
|
|
|
void specialKeys(int keycode);
|
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
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|