2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-12-14 14:31:44 +00:00
|
|
|
*
|
2021-12-26 17:47:58 +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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2002-12-14 14:31:44 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2002-12-14 14:31:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONSOLE_DIALOG_H
|
|
|
|
#define CONSOLE_DIALOG_H
|
|
|
|
|
2003-11-02 02:18:16 +00:00
|
|
|
#include "gui/dialog.h"
|
2013-10-27 20:04:18 +00:00
|
|
|
#include "common/str.h"
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2002-12-14 20:04:46 +00:00
|
|
|
class ScrollBarWidget;
|
|
|
|
|
2006-09-16 17:29:43 +00:00
|
|
|
/*
|
2008-01-27 19:47:41 +00:00
|
|
|
FIXME #1: The console dialog code has some fundamental problems.
|
2006-09-16 17:29:43 +00:00
|
|
|
First of, note the conflict between the (constant) value kCharsPerLine, and the
|
2011-06-03 11:43:10 +00:00
|
|
|
(variable) value _pageWidth. Look a bit at the code to get familiar with them,
|
2006-09-16 17:29:43 +00:00
|
|
|
then return...
|
|
|
|
Now, why don't we just drop kCharsPerLine? Because of the problem of resizing!
|
|
|
|
When the user changes the scaler, the console will get resized. If the dialog
|
|
|
|
becomes smaller because of this, we may have to rewrap text. If the resolution
|
|
|
|
is then increased again, we'd end up with garbled content.
|
2008-01-27 19:47:41 +00:00
|
|
|
|
|
|
|
One can now either ignore this problem (and modify our code accordingly to
|
2006-09-16 17:29:43 +00:00
|
|
|
implement this simple rewrapping -- we currently don't do that at all!).
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-09-16 17:29:43 +00:00
|
|
|
Or, one can go and implement a more complete console, by replacing the
|
2009-05-11 18:02:27 +00:00
|
|
|
_buffer by a real line buffer -- an array of char* pointers.
|
2006-09-16 17:29:43 +00:00
|
|
|
This will allow one to implement resizing perfectly, but has the drawback
|
|
|
|
of making things like scrolling, drawing etc. more complicated.
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-09-16 17:29:43 +00:00
|
|
|
Either way, the current situation is bad, and we should resolve it one way
|
2011-06-03 11:43:10 +00:00
|
|
|
or the other (and if you can think of a third, feel free to suggest it).
|
2008-01-27 19:47:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 17:29:43 +00:00
|
|
|
FIXME #2: Another problem is that apparently _pageWidth isn't computed quite
|
|
|
|
correctly. The current line ends well before reaching the right side of the
|
|
|
|
console dialog. That's irritating and should be fixed.
|
2008-01-27 19:47:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
FIXME #3: The scroll bar is not shown initially, but the area it would
|
2006-09-16 17:29:43 +00:00
|
|
|
occupy is not used for anything else. As a result, the gap described above
|
|
|
|
becomes even wider and thus even more irritating.
|
|
|
|
*/
|
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);
|
2009-05-11 18:02:27 +00:00
|
|
|
typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, Common::String &completion, void *refCon);
|
2002-12-15 00:36:34 +00:00
|
|
|
|
2006-09-16 17:29:43 +00:00
|
|
|
protected:
|
2006-09-16 15:19:23 +00:00
|
|
|
enum {
|
2018-05-02 10:10:32 +00:00
|
|
|
kBufferSize = 32768,
|
2006-09-16 15:19:23 +00:00
|
|
|
kCharsPerLine = 128,
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2018-05-02 10:10:32 +00:00
|
|
|
kHistorySize = 20
|
2006-09-16 15:19:23 +00:00
|
|
|
};
|
|
|
|
|
2005-10-08 19:40:47 +00:00
|
|
|
const Graphics::Font *_font;
|
|
|
|
|
2018-05-02 10:10:32 +00:00
|
|
|
char _buffer[kBufferSize];
|
|
|
|
int _linesInBuffer;
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2018-05-02 10:10:32 +00:00
|
|
|
int _pageWidth;
|
|
|
|
int _linesPerPage;
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2018-05-02 10:10:32 +00:00
|
|
|
int _currentPos;
|
|
|
|
int _scrollLine;
|
|
|
|
int _firstLineInBuffer;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2018-05-02 10:10:32 +00:00
|
|
|
int _promptStartPos;
|
|
|
|
int _promptEndPos;
|
2002-12-14 18:57:15 +00:00
|
|
|
|
2018-05-02 10:10:32 +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
|
|
|
|
2018-05-02 10:10:32 +00:00
|
|
|
SlideMode _slideMode;
|
|
|
|
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;
|
|
|
|
|
2013-10-27 20:04:18 +00:00
|
|
|
Common::String _history[kHistorySize];
|
2002-12-15 02:24:32 +00:00
|
|
|
int _historySize;
|
|
|
|
int _historyIndex;
|
|
|
|
int _historyLine;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2021-08-31 17:04:27 +00:00
|
|
|
void loadHistory();
|
|
|
|
void saveHistory();
|
|
|
|
|
2003-09-20 01:08:48 +00:00
|
|
|
float _widthPercent, _heightPercent;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2018-05-02 10:10:32 +00:00
|
|
|
int _leftPadding;
|
|
|
|
int _rightPadding;
|
|
|
|
int _topPadding;
|
|
|
|
int _bottomPadding;
|
2006-05-27 05:46:04 +00:00
|
|
|
|
2004-11-27 01:25:25 +00:00
|
|
|
void slideUpAndClose();
|
2002-12-15 02:24:32 +00:00
|
|
|
|
2023-02-04 13:58:54 +00:00
|
|
|
Common::String _prompt;
|
|
|
|
|
2002-12-14 14:31:44 +00:00
|
|
|
public:
|
2003-11-02 02:18:16 +00:00
|
|
|
ConsoleDialog(float widthPercent, float heightPercent);
|
2021-08-31 17:04:27 +00:00
|
|
|
virtual ~ConsoleDialog();
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2018-03-28 10:47:23 +00:00
|
|
|
void open() override;
|
|
|
|
void close() override;
|
2018-01-07 09:39:22 +00:00
|
|
|
void drawDialog(DrawLayer layerToDraw) override;
|
2002-12-14 18:57:15 +00:00
|
|
|
|
2018-03-28 10:47:23 +00:00
|
|
|
void handleTickle() override;
|
|
|
|
void reflowLayout() override;
|
|
|
|
void handleMouseWheel(int x, int y, int direction) override;
|
|
|
|
void handleKeyDown(Common::KeyState state) override;
|
|
|
|
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2022-11-25 16:54:44 +00:00
|
|
|
int printFormat(int dummy, MSVC_PRINTF const char *format, ...) GCC_PRINTF(3, 4);
|
2010-11-01 16:03:02 +00:00
|
|
|
int vprintFormat(int dummy, const char *format, va_list argptr);
|
|
|
|
|
|
|
|
void printChar(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;
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-09-16 17:29:43 +00:00
|
|
|
int getCharsPerLine() {
|
|
|
|
return _pageWidth;
|
|
|
|
}
|
2002-12-14 14:31:44 +00:00
|
|
|
|
2023-02-04 13:58:54 +00:00
|
|
|
void setPrompt(Common::String prompt);
|
|
|
|
void resetPrompt();
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2006-05-26 00:17:55 +00:00
|
|
|
void init();
|
|
|
|
|
2006-09-16 15:19:23 +00:00
|
|
|
int pos2line(int pos) { return (pos - (_scrollLine - _linesPerPage + 1) * kCharsPerLine) / kCharsPerLine; }
|
2006-05-27 05:46:04 +00:00
|
|
|
|
2019-04-27 06:00:37 +00:00
|
|
|
void drawLine(int line);
|
2002-12-14 18:57:15 +00:00
|
|
|
void drawCaret(bool erase);
|
2010-11-01 16:03:02 +00:00
|
|
|
void printCharIntern(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();
|
2018-04-21 14:01:58 +00:00
|
|
|
Common::String getUserInput();
|
2002-12-14 21:37:40 +00:00
|
|
|
|
2010-02-21 04:04:13 +00:00
|
|
|
void defaultKeyDownHandler(Common::KeyState &state);
|
|
|
|
|
2002-12-14 21:37:40 +00:00
|
|
|
// Line editing
|
2018-04-21 14:01:58 +00:00
|
|
|
void specialKeys(Common::KeyCode 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
|
2013-10-27 20:04:18 +00:00
|
|
|
void addToHistory(const Common::String &str);
|
2002-12-15 02:24:32 +00:00
|
|
|
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
|