0x47 stub
[scummvm-innocent.git] / gui / console.h
blob52c3394184398c9e4b508e39e2fd3fb81c9254d1
1 /* ScummVM - Graphic Adventure Engine
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $URL$
22 * $Id$
25 #ifndef CONSOLE_DIALOG_H
26 #define CONSOLE_DIALOG_H
28 #include "gui/dialog.h"
29 #include "gui/GuiManager.h"
31 namespace GUI {
33 class ScrollBarWidget;
36 FIXME #1: The console dialog code has some fundamental problems.
37 First of, note the conflict between the (constant) value kCharsPerLine, and the
38 (variable) value _pageWidth. Look a bit at the code get familiar with them,
39 then return...
40 Now, why don't we just drop kCharsPerLine? Because of the problem of resizing!
41 When the user changes the scaler, the console will get resized. If the dialog
42 becomes smaller because of this, we may have to rewrap text. If the resolution
43 is then increased again, we'd end up with garbled content.
45 One can now either ignore this problem (and modify our code accordingly to
46 implement this simple rewrapping -- we currently don't do that at all!).
48 Or, one can go and implement a more complete console, by replacing the
49 _buffer by a real line buffer -- an array of char* pointers.
50 This will allow one to implement resizing perfectly, but has the drawback
51 of making things like scrolling, drawing etc. more complicated.
53 Either way, the current situation is bad, and we should resolve it one way
54 or the other (and if you can think of a thirds, feel free to suggest it).
58 FIXME #2: Another problem is that apparently _pageWidth isn't computed quite
59 correctly. The current line ends well before reaching the right side of the
60 console dialog. That's irritating and should be fixed.
63 FIXME #3: The scroll bar is not shown initially, but the area it would
64 occupy is not used for anything else. As a result, the gap described above
65 becomes even wider and thus even more irritating.
67 class ConsoleDialog : public Dialog {
68 public:
69 typedef bool (*InputCallbackProc)(ConsoleDialog *console, const char *input, void *refCon);
70 typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, Common::String &completion, void *refCon);
72 protected:
73 enum {
74 kBufferSize = 32768,
75 kCharsPerLine = 128,
76 kLineBufferSize = 256,
78 kHistorySize = 20
81 const Graphics::Font *_font;
83 char _buffer[kBufferSize];
84 int _linesInBuffer;
86 int _pageWidth;
87 int _linesPerPage;
89 int _currentPos;
90 int _scrollLine;
91 int _firstLineInBuffer;
93 int _promptStartPos;
94 int _promptEndPos;
96 bool _caretVisible;
97 uint32 _caretTime;
99 enum SlideMode {
100 kNoSlideMode,
101 kUpSlideMode,
102 kDownSlideMode
105 SlideMode _slideMode;
106 uint32 _slideTime;
108 ScrollBarWidget *_scrollBar;
110 // The _callbackProc is called whenver a data line is entered
112 InputCallbackProc _callbackProc;
113 void *_callbackRefCon;
115 // _completionCallbackProc is called when tab is pressed
116 CompletionCallbackProc _completionCallbackProc;
117 void *_completionCallbackRefCon;
119 char _history[kHistorySize][kLineBufferSize];
120 int _historySize;
121 int _historyIndex;
122 int _historyLine;
124 float _widthPercent, _heightPercent;
126 int _leftPadding;
127 int _rightPadding;
128 int _topPadding;
129 int _bottomPadding;
131 void slideUpAndClose();
133 public:
134 ConsoleDialog(float widthPercent, float heightPercent);
136 void open();
137 void close();
138 void drawDialog();
140 void handleTickle();
141 void reflowLayout();
142 void handleMouseWheel(int x, int y, int direction);
143 void handleKeyDown(Common::KeyState state);
144 void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
146 int printf(const char *format, ...) GCC_PRINTF(2, 3);
147 int vprintf(const char *format, va_list argptr);
148 #undef putchar
149 void putchar(int c);
151 void setInputCallback(InputCallbackProc proc, void *refCon) {
152 _callbackProc = proc;
153 _callbackRefCon = refCon;
155 void setCompletionCallback(CompletionCallbackProc proc, void *refCon) {
156 _completionCallbackProc = proc;
157 _completionCallbackRefCon = refCon;
160 int getCharsPerLine() {
161 return _pageWidth;
164 protected:
165 inline char &buffer(int idx) {
166 return _buffer[idx % kBufferSize];
169 void init();
171 int pos2line(int pos) { return (pos - (_scrollLine - _linesPerPage + 1) * kCharsPerLine) / kCharsPerLine; }
173 void drawLine(int line, bool restoreBg = true);
174 void drawCaret(bool erase);
175 void putcharIntern(int c);
176 void insertIntoPrompt(const char *str);
177 void print(const char *str);
178 void updateScrollBuffer();
179 void scrollToCurrent();
181 // Line editing
182 void specialKeys(int keycode);
183 void nextLine();
184 void killChar();
185 void killLine();
186 void killLastWord();
188 // History
189 void addToHistory(const char *str);
190 void historyScroll(int direction);
193 } // End of namespace GUI
195 #endif