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

virtual-keyboard.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 COMMON_VIRTUAL_KEYBOARD_H
00024 #define COMMON_VIRTUAL_KEYBOARD_H
00025 
00026 #include "common/scummsys.h"
00027 
00028 #ifdef ENABLE_VKEYBD
00029 
00030 class OSystem;
00031 
00032 #include "common/events.h"
00033 #include "common/hashmap.h"
00034 #include "common/hash-str.h"
00035 #include "common/keyboard.h"
00036 #include "common/list.h"
00037 #include "common/str.h"
00038 #include "common/fs.h"
00039 
00040 #include "backends/vkeybd/image-map.h"
00041 #include "graphics/surface.h"
00042 
00043 
00044 namespace Common {
00045 
00046 class Archive;
00047 
00048 class VirtualKeyboardGUI;
00049 class VirtualKeyboardParser;
00050 
00057 class VirtualKeyboard {
00058 protected:
00059 
00064     enum VKEventType {
00066         kVKEventKey,
00068         kVKEventModifier,
00070         kVKEventSwitchMode,
00072         kVKEventSubmit,
00074         kVKEventCancel,
00076         kVKEventClear,
00078         kVKEventMoveLeft,
00080         kVKEventMoveRight,
00082         kVKEventDelete
00083     };
00084 
00086     struct VKEvent {
00087         String name;
00088         VKEventType type;
00096         void *data;
00097 
00098         VKEvent() : data(0) {}
00099         ~VKEvent() {
00100             if (data)
00101                 free(data);
00102         }
00103     };
00104 
00105     typedef HashMap<String, VKEvent *> VKEventMap;
00106 
00110     struct Mode {
00111         String              name;
00112         String              resolution;
00113         String              bitmapName;
00114         Graphics::Surface   *image;
00115         uint32              transparentColor;
00116         ImageMap            imageMap;
00117         VKEventMap          events;
00118         Rect                displayArea;
00119         uint32              displayFontColor;
00120 
00121         Mode() : image(0) {}
00122         ~Mode() {
00123             if (image) {
00124                 image->free();
00125                 delete image;
00126                 image = 0;
00127             }
00128         }
00129     };
00130 
00131     typedef HashMap<String, Mode, IgnoreCase_Hash, IgnoreCase_EqualTo> ModeMap;
00132 
00133     enum HorizontalAlignment {
00134         kAlignLeft,
00135         kAlignCenter,
00136         kAlignRight
00137     };
00138 
00139     enum VerticalAlignment {
00140         kAlignTop,
00141         kAlignMiddle,
00142         kAlignBottom
00143     };
00144 
00145     struct VirtualKeyPress {
00146         KeyState key;
00148         uint strLen;
00149     };
00150 
00155     class KeyPressQueue {
00156     public:
00157         KeyPressQueue();
00158         void toggleFlags(byte fl);
00159         void clearFlags();
00160         void insertKey(KeyState key);
00161         void deleteKey();
00162         void moveLeft();
00163         void moveRight();
00164         KeyState pop();
00165         void clear();
00166         bool empty();
00167         String getString();
00168         uint getInsertIndex();
00169         bool hasStringChanged();
00170 
00171     private:
00172         byte _flags;
00173         String _flagsStr;
00174 
00175         typedef List<VirtualKeyPress> KeyPressList;
00176         KeyPressList _keys;
00177         String _keysStr;
00178 
00179         bool _strChanged;
00180 
00181         KeyPressList::iterator _keyPos;
00182         uint _strPos;
00183     };
00184 
00185 public:
00186 
00187     VirtualKeyboard();
00188 
00189     virtual ~VirtualKeyboard();
00190 
00198     bool loadKeyboardPack(const String &packName);
00199 
00205     void show();
00206 
00212     void close(bool submit);
00213 
00217     bool isDisplaying();
00218 
00222     bool isLoaded() {
00223         return _loaded;
00224     }
00225 
00226 protected:
00227 
00228     OSystem *_system;
00229     DisposablePtr<Archive> _fileArchive;
00230 
00231     friend class VirtualKeyboardGUI;
00232     VirtualKeyboardGUI *_kbdGUI;
00233 
00234     KeyPressQueue _keyQueue;
00235 
00236     friend class VirtualKeyboardParser;
00237     VirtualKeyboardParser *_parser;
00238 
00239     void reset();
00240     bool openPack(const String &packName, Archive *searchPath, DisposeAfterUse::Flag disposeSearchPath);
00241     void deleteEvents();
00242     bool checkModeResolutions();
00243     void switchMode(Mode *newMode);
00244     void switchMode(const String &newMode);
00245     void handleMouseDown(int16 x, int16 y);
00246     void handleMouseUp(int16 x, int16 y);
00247     String findArea(int16 x, int16 y);
00248     void processAreaClick(const String &area);
00249 
00250     bool _loaded;
00251 
00252     ModeMap _modes;
00253     Mode *_initialMode;
00254     Mode *_currentMode;
00255 
00256     HorizontalAlignment  _hAlignment;
00257     VerticalAlignment    _vAlignment;
00258 
00259     String _areaDown;
00260 
00261     bool _submitKeys;
00262 
00263 };
00264 
00265 } // End of namespace Common
00266 
00267 #endif // #ifdef ENABLE_VKEYBD
00268 
00269 #endif // #ifndef COMMON_VIRTUAL_KEYBOARD_H


Generated on Sat May 18 2019 05:01:29 for ResidualVM by doxygen 1.7.1
curved edge   curved edge