Ticket #8711: backends-lib.v5.5

File backends-lib.v5.5, 16.5 KB (added by SF/sbatyuk, 13 years ago)

drag and drop and VK stub patch

Line 
1Index: backends/events/default/default-events.cpp
2===================================================================
3--- backends/events/default/default-events.cpp (revision 28773)
4+++ backends/events/default/default-events.cpp (working copy)
5@@ -32,7 +32,9 @@
6
7 #include "engines/engine.h"
8 #include "gui/message.h"
9+#include "gui/VirtualKeyboardDialog.h"
10
11+
12 DefaultEventManager::DefaultEventManager(OSystem *boss) :
13 _boss(boss),
14 _buttonState(0),
15@@ -65,6 +67,12 @@
16 _currentKeyDown.flags = event.kbd.flags;
17 _keyRepeatTime = time + kKeyRepeatInitialDelay;
18 #endif
19+ // TODO remove; for testing purposes only
20+ if (event.kbd.keycode == Common::KEYCODE_k) {
21+ GUI::VirtualKeyboardDialog *vkdlg = new GUI::VirtualKeyboardDialog("keyboard", "D:\\keyboard.bmp");
22+ vkdlg->runModal();
23+ return false;
24+ }
25 break;
26 case Common::EVENT_KEYUP:
27 _modifierState = event.kbd.flags;
28Index: backends/platform/sdl/sdl.cpp
29===================================================================
30--- backends/platform/sdl/sdl.cpp (revision 28773)
31+++ backends/platform/sdl/sdl.cpp (working copy)
32@@ -473,3 +473,13 @@
33 _cdEndTime = SDL_GetTicks() + _cdrom->track[_cdTrack].length * 1000 / CD_FPS;
34 }
35 }
36+
37+Common::String OSystem_SDL::getExtraThemeConfig() {
38+ Common::String myConfigINI(
39+ "[XxY]\n"
40+ "keyboard=0 0 580 160\n"
41+ "keyboard_image=0 0 580 160\n"
42+ "keyboard_draganddrop=2 0 580 12\n"
43+ );
44+ return myConfigINI;
45+}
46\ No newline at end of file
47Index: backends/platform/sdl/sdl.h
48===================================================================
49--- backends/platform/sdl/sdl.h (revision 28773)
50+++ backends/platform/sdl/sdl.h (working copy)
51@@ -410,6 +410,12 @@
52 virtual bool remapKey(SDL_Event &ev, Common::Event &event);
53
54 void handleScalerHotkeys(const SDL_KeyboardEvent &key);
55+
56+ // backend lib methods
57+
58+public:
59+
60+ virtual Common::String getExtraThemeConfig();
61 };
62
63 #endif
64Index: common/system.h
65===================================================================
66--- common/system.h (revision 28773)
67+++ common/system.h (working copy)
68@@ -885,6 +885,19 @@
69 */
70 virtual Common::SaveFileManager *getSavefileManager() = 0;
71
72+ // backend lib methods
73+
74+ // disabling launcher dialog GUI elements method
75+
76+ /**
77+ * Returns the additional backend specific theme config
78+ * that may be optionally processed by each theme after it has loaded its main config
79+ */
80+ // currently it's intented to be used by backends to disable specific GUI elements on launcher dialog
81+ virtual Common::String getExtraThemeConfig() {
82+ return "";
83+ }
84+
85 //@}
86 };
87
88 Index: gui/dialog_image.h
89===================================================================
90--- gui/dialog_image.h (revision 0)
91+++ gui/dialog_image.h (revision 0)
92@@ -0,0 +1,51 @@
93+/* ScummVM - Graphic Adventure Engine
94+ *
95+ * ScummVM is the legal property of its developers, whose names
96+ * are too numerous to list here. Please refer to the COPYRIGHT
97+ * file distributed with this source distribution.
98+ *
99+ * This program is free software; you can redistribute it and/or
100+ * modify it under the terms of the GNU General Public License
101+ * as published by the Free Software Foundation; either version 2
102+ * of the License, or (at your option) any later version.
103+ *
104+ * This program is distributed in the hope that it will be useful,
105+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
106+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
107+ * GNU General Public License for more details.
108+ *
109+ * You should have received a copy of the GNU General Public License
110+ * along with this program; if not, write to the Free Software
111+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
112+ */
113+#ifndef DIALOG_WITH_BACKGROUND_IMAGE_H
114+#define DIALOG_WITH_BACKGROUND_IMAGE_H
115+
116+#include "common/stdafx.h"
117+#include "gui/dialog.h"
118+#include "gui/widget.h"
119+
120+namespace GUI {
121+
122+class DialogWithBackgroundImage : public Dialog {
123+public:
124+ DialogWithBackgroundImage(const Common::String &name, bool dimsInactive = true)
125+ :Dialog(name, dimsInactive), _image(NULL) {}
126+
127+ DialogWithBackgroundImage(const Common::String &name, const Common::String &imagePath, bool dimsInactive = true)
128+ :Dialog(name, dimsInactive), _image(NULL) {
129+
130+ setImage(imagePath);
131+ }
132+
133+ ~DialogWithBackgroundImage();
134+
135+ void setImage(const Common::String &imagePath);
136+
137+private:
138+ GUI::GraphicsWidget *_image;
139+};
140+
141+}
142+
143+#endif
144Index: gui/ThemeModern.cpp
145===================================================================
146--- gui/ThemeModern.cpp (revision 28773)
147+++ gui/ThemeModern.cpp (working copy)
148@@ -135,7 +135,7 @@
149
150 if (isThemeLoadingRequired()) {
151 loadTheme(_defaultConfig);
152- loadTheme(_configFile, false); // Don't reset
153+ loadTheme(_configFile, false, true); // Don't reset
154
155 processExtraValues();
156 }
157Index: gui/theme.h
158===================================================================
159--- gui/theme.h (revision 28773)
160+++ gui/theme.h (working copy)
161@@ -211,7 +211,7 @@
162 bool isThemeLoadingRequired();
163 bool sectionIsSkipped(Common::ConfigFile &config, const char *name, int w, int h);
164 void loadTheme(Common::ConfigFile &config, bool reset = true);
165-
166+ void loadTheme(Common::ConfigFile &config, bool reset, bool doBackendSpecificPostProcessing);
167 Eval *_evaluator;
168
169 static bool themeConfigUseable(const Common::String &file, const Common::String &style="", Common::String *cStyle=0, Common::ConfigFile *cfg=0);
170Index: gui/object.h
171===================================================================
172--- gui/object.h (revision 28773)
173+++ gui/object.h (working copy)
174@@ -59,6 +59,8 @@
175
176 class GuiObject : public CommandReceiver {
177 friend class Widget;
178+ friend class DragAndDropWidget;
179+
180 protected:
181 int16 _x, _y;
182 uint16 _w, _h;
183Index: gui/widget.h
184===================================================================
185--- gui/widget.h (revision 28773)
186+++ gui/widget.h (working copy)
187@@ -63,7 +63,8 @@
188 kPopUpWidget = 'POPU',
189 kTabWidget = 'TABW',
190 kGraphicsWidget = 'GFXW',
191- kContainerWidget = 'CTNR'
192+ kContainerWidget = 'CTNR',
193+ kDragAndDropWidget = 'DNDW'
194 };
195
196 enum {
197@@ -148,7 +149,7 @@
198 int getHints() const { return _hints; }
199
200 void setEnabled(bool e) { if (e) setFlags(WIDGET_ENABLED); else clearFlags(WIDGET_ENABLED); }
201- bool isEnabled() const { return _flags & WIDGET_ENABLED; }
202+ bool isEnabled() const;
203 bool isVisible() const;
204
205 protected:
206@@ -293,6 +294,23 @@
207 void drawWidget(bool hilite);
208 };
209
210+/* ContainerWidget */
211+class DragAndDropWidget : public Widget {
212+public:
213+ DragAndDropWidget(GuiObject *boss, const Common::String &name);
214+
215+ virtual void handleMouseDown(int x, int y, int button, int clickCount);
216+ virtual void handleMouseUp(int x, int y, int button, int clickCount);
217+ virtual void handleMouseMoved(int x, int y, int button);
218+
219+protected:
220+ void drawWidget(bool hilite);
221+
222+private:
223+ bool _drag;
224+ int _mouseX, _mouseY;
225+};
226+
227 } // End of namespace GUI
228
229 #endif
230Index: gui/VirtualKeyboardDialog.h
231===================================================================
232--- gui/VirtualKeyboardDialog.h (revision 0)
233+++ gui/VirtualKeyboardDialog.h (revision 0)
234@@ -0,0 +1,83 @@
235+/* ScummVM - Graphic Adventure Engine
236+ *
237+ * ScummVM is the legal property of its developers, whose names
238+ * are too numerous to list here. Please refer to the COPYRIGHT
239+ * file distributed with this source distribution.
240+ *
241+ * This program is free software; you can redistribute it and/or
242+ * modify it under the terms of the GNU General Public License
243+ * as published by the Free Software Foundation; either version 2
244+ * of the License, or (at your option) any later version.
245+ *
246+ * This program is distributed in the hope that it will be useful,
247+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
248+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
249+ * GNU General Public License for more details.
250+ *
251+ * You should have received a copy of the GNU General Public License
252+ * along with this program; if not, write to the Free Software
253+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
254+ */
255+#ifndef VIRTUAL_KEYBOARD_DIALOG_H
256+#define VIRTUAL_KEYBOARD_DIALOG_H
257+
258+#include "gui/dialog_image.h"
259+#include "gui/widget.h"
260+
261+#include "common/singleton.h"
262+
263+namespace GUI {
264+
265+enum ScreenResolution {
266+ SCREEN_RESOLUTION_320x240 = 0,
267+ SCREEN_RESOLUTION_640x480 = 1
268+};
269+
270+enum KeyboardState {
271+ KEYBOARD_STATE_DEFAULT = 0,
272+ KEYBOARD_STATE_SHIFT = 1,
273+ KEYBOARD_STATE_CAPS_LOCK = 2
274+};
275+
276+enum Img {
277+ IMG_PATH = 0,
278+ IMG_PRESSED_BUTTONS_PATH = 1,
279+ IMG_MAP = 2
280+};
281+
282+struct ButtonIcon {
283+ int x1, y1, x2, y2;
284+ bool clicked(int x, int y) {
285+ return (x1 < x) && (x < x2) && (y1 < y) && (y < y2);
286+ }
287+};
288+
289+class VirtualKeyboardDialog : public DialogWithBackgroundImage {
290+public:
291+
292+ class VKConfigManager : public Common::Singleton<VKConfigManager> {
293+ public:
294+ VKConfigManager();
295+ ~VKConfigManager();
296+
297+ Common::String getImagePath(ScreenResolution sr, KeyboardState ks);
298+ Common::String getPressedButtonsImagePath(ScreenResolution sr, KeyboardState ks);
299+ ButtonIcon *getButtonIcon(ScreenResolution sr, KeyboardState ks, int i);
300+
301+ private:
302+ Common::String config[2][3][3];
303+ void load();
304+ };
305+
306+ VirtualKeyboardDialog(const Common::String &name, const Common::String &imagePath);
307+ virtual ~VirtualKeyboardDialog();
308+
309+ virtual void handleMouseDown(int x, int y, int button, int clickCount);
310+
311+private:
312+ GUI::DragAndDropWidget *dnd;
313+};
314+
315+}
316+
317+#endif
318Index: gui/dialog_image.cpp
319===================================================================
320--- gui/dialog_image.cpp (revision 0)
321+++ gui/dialog_image.cpp (revision 0)
322@@ -0,0 +1,43 @@
323+/* ScummVM - Graphic Adventure Engine
324+ *
325+ * ScummVM is the legal property of its developers, whose names
326+ * are too numerous to list here. Please refer to the COPYRIGHT
327+ * file distributed with this source distribution.
328+ *
329+ * This program is free software; you can redistribute it and/or
330+ * modify it under the terms of the GNU General Public License
331+ * as published by the Free Software Foundation; either version 2
332+ * of the License, or (at your option) any later version.
333+ *
334+ * This program is distributed in the hope that it will be useful,
335+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
336+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
337+ * GNU General Public License for more details.
338+ *
339+ * You should have received a copy of the GNU General Public License
340+ * along with this program; if not, write to the Free Software
341+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
342+ */
343+
344+#include "gui/dialog_image.h"
345+#include "graphics/surface.h"
346+#include "graphics/imagedec.h"
347+
348+void GUI::DialogWithBackgroundImage::setImage(const Common::String &imagePath) {
349+ if (imagePath.empty()) {
350+ return;
351+ }
352+
353+ Graphics::Surface *surface = Graphics::ImageDecoder::loadFile(imagePath);
354+ // image lazy initialization
355+ if (!_image) {
356+ _image = new GUI::GraphicsWidget(this, this->_name + "_image");
357+ }
358+ _image->setGfx(surface);
359+}
360+
361+GUI::DialogWithBackgroundImage::~DialogWithBackgroundImage() {
362+ if (_image) {
363+ delete _image;
364+ }
365+}
366\ No newline at end of file
367Index: gui/ThemeClassic.cpp
368===================================================================
369--- gui/ThemeClassic.cpp (revision 28773)
370+++ gui/ThemeClassic.cpp (working copy)
371@@ -70,7 +70,7 @@
372
373 if (isThemeLoadingRequired()) {
374 loadTheme(_defaultConfig);
375- loadTheme(_configFile, false);
376+ loadTheme(_configFile, false, true);
377
378 setupConfig();
379 }
380Index: gui/theme-config.cpp
381===================================================================
382--- gui/theme-config.cpp (revision 28773)
383+++ gui/theme-config.cpp (working copy)
384@@ -766,4 +766,16 @@
385 debug(3, "Number of variables: %d", _evaluator->getNumVars());
386 }
387
388+void Theme::loadTheme(Common::ConfigFile &config, bool reset, bool doBackendSpecificPostProcessing) {
389+ loadTheme(config, reset);
390+
391+ if (doBackendSpecificPostProcessing && !g_system->getExtraThemeConfig().empty()) {
392+ Common::ConfigFile myConfig;
393+ Common::String myConfigINI = g_system->getExtraThemeConfig();
394+ Common::MemoryReadStream s((const byte *)myConfigINI.c_str(), strlen(myConfigINI.c_str()));
395+ myConfig.loadFromStream(s);
396+ loadTheme(myConfig, false);
397+ }
398+}
399+
400 } // End of namespace GUI
401Index: gui/widget.cpp
402===================================================================
403--- gui/widget.cpp (revision 28773)
404+++ gui/widget.cpp (working copy)
405@@ -135,6 +135,12 @@
406 return 0;
407 }
408
409+bool Widget::isEnabled() const {
410+ if (g_gui.evaluator()->getVar(_name + ".enabled") == 0)
411+ return false;
412+ return _flags & WIDGET_ENABLED;
413+}
414+
415 bool Widget::isVisible() const {
416 if (g_gui.evaluator()->getVar(_name + ".visible") == 0)
417 return false;
418@@ -389,4 +395,35 @@
419 g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), _hints, Theme::kWidgetBackgroundBorder);
420 }
421
422+#pragma mark -
423+
424+DragAndDropWidget::DragAndDropWidget(GuiObject *boss, const Common::String &name) : Widget(boss, name), _drag(false) {
425+ _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_TRACK_MOUSE;
426+ _type = kDragAndDropWidget;
427+}
428+
429+void DragAndDropWidget::handleMouseDown(int x, int y, int button, int clickCount) {
430+ if (button == 1 && clickCount == 1) {
431+ _drag = true;
432+ _mouseX = x;
433+ _mouseY = y;
434+ }
435+}
436+
437+void DragAndDropWidget::handleMouseUp(int x, int y, int button, int clickCount) {
438+ _drag = false;
439+}
440+
441+void DragAndDropWidget::handleMouseMoved(int x, int y, int button) {
442+ if (_drag) {
443+ _boss->_x += x - _mouseX;
444+ _boss->_y += y - _mouseY;
445+ _boss->draw();
446+ }
447+}
448+
449+void DragAndDropWidget::drawWidget(bool hilite) {
450+ g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), _hints, Theme::kWidgetBackgroundBorder);
451+}
452+
453 } // End of namespace GUI
454Index: gui/VirtualKeyboardDialog.cpp
455===================================================================
456--- gui/VirtualKeyboardDialog.cpp (revision 0)
457+++ gui/VirtualKeyboardDialog.cpp (revision 0)
458@@ -0,0 +1,62 @@
459+/* ScummVM - Graphic Adventure Engine
460+ *
461+ * ScummVM is the legal property of its developers, whose names
462+ * are too numerous to list here. Please refer to the COPYRIGHT
463+ * file distributed with this source distribution.
464+ *
465+ * This program is free software; you can redistribute it and/or
466+ * modify it under the terms of the GNU General Public License
467+ * as published by the Free Software Foundation; either version 2
468+ * of the License, or (at your option) any later version.
469+
470+ * This program is distributed in the hope that it will be useful,
471+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
472+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
473+ * GNU General Public License for more details.
474+
475+ * You should have received a copy of the GNU General Public License
476+ * along with this program; if not, write to the Free Software
477+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
478+ */
479+
480+#include "gui/VirtualKeyboardDialog.h"
481+#include "common/config-manager.h"
482+
483+GUI::VirtualKeyboardDialog::VirtualKeyboardDialog(const Common::String &name, const Common::String &imagePath)
484+ :DialogWithBackgroundImage(name, imagePath) {
485+
486+ dnd = new GUI::DragAndDropWidget(this, this->_name + "_draganddrop");
487+}
488+
489+GUI::VirtualKeyboardDialog::~VirtualKeyboardDialog() {
490+ delete dnd;
491+}
492+
493+void GUI::VirtualKeyboardDialog::handleMouseDown(int x, int y, int button, int clickCount) {
494+ int x123;
495+ x123 = 0;
496+ Dialog::handleMouseDown(x, y, button, clickCount);
497+}
498+
499+GUI::VirtualKeyboardDialog::VKConfigManager::VKConfigManager() {
500+}
501+
502+GUI::VirtualKeyboardDialog::VKConfigManager::~VKConfigManager() {
503+}
504+
505+Common::String GUI::VirtualKeyboardDialog::VKConfigManager::getImagePath(ScreenResolution sr, KeyboardState ks) {
506+ return "";
507+}
508+
509+Common::String GUI::VirtualKeyboardDialog::VKConfigManager::getPressedButtonsImagePath(ScreenResolution sr, KeyboardState ks) {
510+ return "";
511+}
512+
513+GUI::ButtonIcon *GUI::VirtualKeyboardDialog::VKConfigManager::getButtonIcon(ScreenResolution sr, KeyboardState ks, int i) {
514+ return NULL;
515+}
516+
517+void GUI::VirtualKeyboardDialog::VKConfigManager::load() {
518+ Common::String path = ConfMan.get("vk_config_file_path");
519+
520+}
521\ No newline at end of file
522