ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

gui/console.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef CONSOLE_DIALOG_H
00024 #define CONSOLE_DIALOG_H
00025 
00026 #include "gui/dialog.h"
00027 #include "common/str.h"
00028 
00029 namespace GUI {
00030 
00031 class ScrollBarWidget;
00032 
00033 /*
00034  FIXME #1: The console dialog code has some fundamental problems.
00035  First of, note the conflict between the (constant) value kCharsPerLine, and the
00036  (variable) value _pageWidth. Look a bit at the code to get familiar with them,
00037  then return...
00038  Now, why don't we just drop kCharsPerLine? Because of the problem of resizing!
00039  When the user changes the scaler, the console will get resized. If the dialog
00040  becomes smaller because of this, we may have to rewrap text. If the resolution
00041  is then increased again, we'd end up with garbled content.
00042 
00043  One can now either ignore this problem (and modify our code accordingly to
00044  implement this simple rewrapping -- we currently don't do that at all!).
00045 
00046  Or, one can go and implement a more complete console, by replacing the
00047  _buffer by a real line buffer -- an array of char* pointers.
00048  This will allow one to implement resizing perfectly, but has the drawback
00049  of making things like scrolling, drawing etc. more complicated.
00050 
00051  Either way, the current situation is bad, and we should resolve it one way
00052  or the other (and if you can think of a third, feel free to suggest it).
00053 
00054 
00055 
00056  FIXME #2: Another problem is that apparently _pageWidth isn't computed quite
00057  correctly. The current line ends well before reaching the right side of the
00058  console dialog. That's irritating and should be fixed.
00059 
00060 
00061  FIXME #3: The scroll bar is not shown initially, but the area it would
00062  occupy is not used for anything else. As a result, the gap described above
00063  becomes even wider and thus even more irritating.
00064 */
00065 class ConsoleDialog : public Dialog {
00066 public:
00067     typedef bool (*InputCallbackProc)(ConsoleDialog *console, const char *input, void *refCon);
00068     typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, Common::String &completion, void *refCon);
00069 
00070 protected:
00071     enum {
00072         kBufferSize   = 32768,
00073         kCharsPerLine = 128,
00074 
00075         kHistorySize  = 20
00076     };
00077 
00078     const Graphics::Font *_font;
00079 
00080     char _buffer[kBufferSize];
00081     int  _linesInBuffer;
00082 
00083     int _pageWidth;
00084     int _linesPerPage;
00085 
00086     int _currentPos;
00087     int _scrollLine;
00088     int _firstLineInBuffer;
00089 
00090     int _promptStartPos;
00091     int _promptEndPos;
00092 
00093     bool   _caretVisible;
00094     uint32 _caretTime;
00095 
00096     enum SlideMode {
00097         kNoSlideMode,
00098         kUpSlideMode,
00099         kDownSlideMode
00100     };
00101 
00102     SlideMode _slideMode;
00103     uint32    _slideTime;
00104 
00105     ScrollBarWidget *_scrollBar;
00106 
00107     // The _callbackProc is called whenver a data line is entered
00108     //
00109     InputCallbackProc _callbackProc;
00110     void *_callbackRefCon;
00111 
00112     // _completionCallbackProc is called when tab is pressed
00113     CompletionCallbackProc _completionCallbackProc;
00114     void *_completionCallbackRefCon;
00115 
00116     Common::String _history[kHistorySize];
00117     int _historySize;
00118     int _historyIndex;
00119     int _historyLine;
00120 
00121     float _widthPercent, _heightPercent;
00122 
00123     int _leftPadding;
00124     int _rightPadding;
00125     int _topPadding;
00126     int _bottomPadding;
00127 
00128     void slideUpAndClose();
00129 
00130 public:
00131     ConsoleDialog(float widthPercent, float heightPercent);
00132 
00133     void open() override;
00134     void close() override;
00135     void drawDialog(DrawLayer layerToDraw) override;
00136 
00137     void handleTickle() override;
00138     void reflowLayout() override;
00139     void handleMouseWheel(int x, int y, int direction) override;
00140     void handleKeyDown(Common::KeyState state) override;
00141     void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
00142 
00143     int printFormat(int dummy, const char *format, ...) GCC_PRINTF(3, 4);
00144     int vprintFormat(int dummy, const char *format, va_list argptr);
00145 
00146     void printChar(int c);
00147 
00148     void setInputCallback(InputCallbackProc proc, void *refCon) {
00149         _callbackProc = proc;
00150         _callbackRefCon = refCon;
00151     }
00152     void setCompletionCallback(CompletionCallbackProc proc, void *refCon) {
00153         _completionCallbackProc = proc;
00154         _completionCallbackRefCon = refCon;
00155     }
00156 
00157     int getCharsPerLine() {
00158         return _pageWidth;
00159     }
00160 
00161 protected:
00162     inline char &buffer(int idx) {
00163         return _buffer[idx % kBufferSize];
00164     }
00165 
00166     void init();
00167 
00168     int pos2line(int pos) { return (pos - (_scrollLine - _linesPerPage + 1) * kCharsPerLine) / kCharsPerLine; }
00169 
00170     void drawLine(int line, bool restoreBg = true);
00171     void drawCaret(bool erase);
00172     void printCharIntern(int c);
00173     void insertIntoPrompt(const char *str);
00174     void print(const char *str);
00175     void updateScrollBuffer();
00176     void scrollToCurrent();
00177     Common::String getUserInput();
00178 
00179     void defaultKeyDownHandler(Common::KeyState &state);
00180 
00181     // Line editing
00182     void specialKeys(Common::KeyCode keycode);
00183     void nextLine();
00184     void killChar();
00185     void killLine();
00186     void killLastWord();
00187 
00188     // History
00189     void addToHistory(const Common::String &str);
00190     void historyScroll(int direction);
00191 };
00192 
00193 } // End of namespace GUI
00194 
00195 #endif


Generated on Sat Apr 20 2019 05:02:13 for ResidualVM by doxygen 1.7.1
curved edge   curved edge