Ticket #8711: backends-lib.v5.1

File backends-lib.v5.1, 7.1 KB (added by SF/sbatyuk, 17 years ago)

port specific tabs and disabling GUI elements patch

Line 
1Index: backends/platform/sdl/sdl.cpp
2===================================================================
3--- backends/platform/sdl/sdl.cpp (revision 28684)
4+++ backends/platform/sdl/sdl.cpp (working copy)
5@@ -473,3 +473,30 @@
6 _cdEndTime = SDL_GetTicks() + _cdrom->track[_cdTrack].length * 1000 / CD_FPS;
7 }
8 }
9+
10+enum {
11+ kCmdTestBtn = 'TEST'
12+};
13+
14+GUI::StaticTextWidget *_stw;
15+
16+void OSystem_SDL::genereteBackendTab (GUI::GuiObject *boss) {
17+ new GUI::ButtonWidget(boss, "gameoptions_extrapath", "Click!", kCmdTestBtn, 'Q');
18+ _stw = new GUI::StaticTextWidget(boss, "gameoptions_id", "test");
19+}
20+
21+bool OSystem_SDL::handleBackendTabCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
22+ switch(cmd) {
23+ case kCmdTestBtn:
24+ _stw->setEnabled(!_stw->isEnabled());
25+ _stw->draw();
26+ return true;
27+ default:
28+ return false;
29+ }
30+}
31+
32+Common::String OSystem_SDL::getExtraThemeConfig() {
33+ Common::String myConfigINI("[XxY]\ngameoptions_gamepath.enabled=false\n");
34+ return myConfigINI;
35+}
36\ No newline at end of file
37Index: backends/platform/sdl/sdl.h
38===================================================================
39--- backends/platform/sdl/sdl.h (revision 28684)
40+++ backends/platform/sdl/sdl.h (working copy)
41@@ -34,7 +34,10 @@
42 #include "graphics/scaler.h"
43 #include "backends/intern.h"
44
45+#include "gui/object.h"
46+#include "gui/widget.h"
47
48+
49 namespace Audio {
50 class Mixer;
51 }
52@@ -410,6 +413,20 @@
53 virtual bool remapKey(SDL_Event &ev, Common::Event &event);
54
55 void handleScalerHotkeys(const SDL_KeyboardEvent &key);
56+
57+ // backend lib methods
58+
59+public:
60+
61+ virtual Common::String getBackendTabName () {
62+ return "test";
63+ }
64+
65+ virtual void genereteBackendTab (GUI::GuiObject *boss);
66+
67+ virtual bool handleBackendTabCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
68+
69+ virtual Common::String getExtraThemeConfig();
70 };
71
72 #endif
73Index: common/system.h
74===================================================================
75--- common/system.h (revision 28684)
76+++ common/system.h (working copy)
77@@ -31,6 +31,8 @@
78 #include "common/noncopyable.h"
79 #include "common/rect.h"
80
81+#include "gui/object.h"
82+
83 namespace Audio {
84 class Mixer;
85 }
86@@ -885,6 +887,41 @@
87 */
88 virtual Common::SaveFileManager *getSavefileManager() = 0;
89
90+ // backend lib methods
91+
92+ // backend specific game options tab methods
93+
94+ /**
95+ * Returns the name of the backend specific tab in game edit dialog
96+ */
97+ virtual Common::String getBackendTabName() {
98+ return "";
99+ }
100+
101+ /**
102+ * Hook method to allow the backends generate their own specific tab in game edit dialog
103+ */
104+ virtual void genereteBackendTab(GUI::GuiObject *boss) {}
105+
106+ /**
107+ * Hook method to allow the backends process the events from their
108+ * own specific tab in game edit dialog
109+ */
110+ virtual bool handleBackendTabCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
111+ return false;
112+ }
113+
114+ // disabling launcher dialog GUI elements method
115+
116+ /**
117+ * Returns the additional backend specific theme config
118+ * that may be optionally processed by each theme after it has loaded its main config
119+ */
120+ // currently it's intented to be used by backends to disable specific GUI elements on launcher dialog
121+ virtual Common::String getExtraThemeConfig() {
122+ return "";
123+ }
124+
125 //@}
126 };
127
128 Index: gui/ThemeModern.cpp
129===================================================================
130--- gui/ThemeModern.cpp (revision 28684)
131+++ gui/ThemeModern.cpp (working copy)
132@@ -135,7 +135,7 @@
133
134 if (isThemeLoadingRequired()) {
135 loadTheme(_defaultConfig);
136- loadTheme(_configFile, false); // Don't reset
137+ loadTheme(_configFile, false, true); // Don't reset
138
139 processExtraValues();
140 }
141Index: gui/theme.h
142===================================================================
143--- gui/theme.h (revision 28684)
144+++ gui/theme.h (working copy)
145@@ -211,7 +211,7 @@
146 bool isThemeLoadingRequired();
147 bool sectionIsSkipped(Common::ConfigFile &config, const char *name, int w, int h);
148 void loadTheme(Common::ConfigFile &config, bool reset = true);
149-
150+ void loadTheme(Common::ConfigFile &config, bool reset, bool doBackendSpecificPostProcessing);
151 Eval *_evaluator;
152
153 static bool themeConfigUseable(const Common::String &file, const Common::String &style="", Common::String *cStyle=0, Common::ConfigFile *cfg=0);
154Index: gui/widget.h
155===================================================================
156--- gui/widget.h (revision 28684)
157+++ gui/widget.h (working copy)
158@@ -148,7 +148,7 @@
159 int getHints() const { return _hints; }
160
161 void setEnabled(bool e) { if (e) setFlags(WIDGET_ENABLED); else clearFlags(WIDGET_ENABLED); }
162- bool isEnabled() const { return _flags & WIDGET_ENABLED; }
163+ bool isEnabled() const;
164 bool isVisible() const;
165
166 protected:
167Index: gui/launcher.cpp
168===================================================================
169--- gui/launcher.cpp (revision 28684)
170+++ gui/launcher.cpp (working copy)
171@@ -259,6 +259,14 @@
172 _savePathWidget->setLabel("Default");
173 }
174
175+ //
176+ // 8) Backend tab
177+ //
178+ if (!g_system->getBackendTabName().empty()){
179+ tab->addTab(g_system->getBackendTabName());
180+ g_system->genereteBackendTab(tab);
181+ }
182+
183 // Activate the first tab
184 tab->setActiveTab(0);
185
186@@ -464,7 +472,9 @@
187 }
188 // FALL THROUGH to default case
189 default:
190- OptionsDialog::handleCommand(sender, cmd, data);
191+ if(!g_system->handleBackendTabCommand(sender, cmd, data)) {
192+ OptionsDialog::handleCommand(sender, cmd, data);
193+ }
194 }
195 }
196
197Index: gui/ThemeClassic.cpp
198===================================================================
199--- gui/ThemeClassic.cpp (revision 28684)
200+++ gui/ThemeClassic.cpp (working copy)
201@@ -70,7 +70,7 @@
202
203 if (isThemeLoadingRequired()) {
204 loadTheme(_defaultConfig);
205- loadTheme(_configFile, false);
206+ loadTheme(_configFile, false, true);
207
208 setupConfig();
209 }
210Index: gui/theme-config.cpp
211===================================================================
212--- gui/theme-config.cpp (revision 28684)
213+++ gui/theme-config.cpp (working copy)
214@@ -766,4 +766,16 @@
215 debug(3, "Number of variables: %d", _evaluator->getNumVars());
216 }
217
218+void Theme::loadTheme(Common::ConfigFile &config, bool reset, bool doBackendSpecificPostProcessing) {
219+ loadTheme(config, reset);
220+
221+ if (doBackendSpecificPostProcessing && !g_system->getExtraThemeConfig().empty()) {
222+ Common::ConfigFile myConfig;
223+ Common::String myConfigINI = g_system->getExtraThemeConfig();
224+ Common::MemoryReadStream s((const byte *)myConfigINI.c_str(), strlen(myConfigINI.c_str()));
225+ myConfig.loadFromStream(s);
226+ loadTheme(myConfig, false);
227+ }
228+}
229+
230 } // End of namespace GUI
231Index: gui/widget.cpp
232===================================================================
233--- gui/widget.cpp (revision 28684)
234+++ gui/widget.cpp (working copy)
235@@ -135,6 +135,12 @@
236 return 0;
237 }
238
239+bool Widget::isEnabled() const {
240+ if (g_gui.evaluator()->getVar(_name + ".enabled") == 0)
241+ return false;
242+ return _flags & WIDGET_ENABLED;
243+}
244+
245 bool Widget::isVisible() const {
246 if (g_gui.evaluator()->getVar(_name + ".visible") == 0)
247 return false;
248