00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "gamepad-vgfx-element.h"
00036
00037 #include "datahash/datahash_util.h"
00038 #include "gamepad-vgfx/gamepad-vgfx.h"
00039
00040
00041 namespace gamepad {
00042
00043
00044 static const char * s_simpleElementName = "gamepadVgfxSimple";
00045
00046 static const char * s_null = "(null)";
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 class Simple : public dialog::Element {
00063 public:
00064
00065 ~Simple(void) throw() { }
00066
00067
00068 int getWidth(void) { return m_width; }
00069 int getHeight(void) { return m_height; }
00070 void draw(IN const dialog::point_t& offset);
00071 void cursor(IN const dialog::point_t& pos) { }
00072 const char * button(IN int button, IN int state,
00073 IN const dialog::point_t& pos)
00074 { return NULL; }
00075 void addData(IN crypto::DESKey * key, IO Datahash * data) { }
00076
00077
00078 static smart_ptr<dialog::Element> create(IN Type * type,
00079 IN const char * flash,
00080 IN const char * pulse,
00081 IN const char * direction,
00082 IN smart_ptr<vgfx::Drawer>& drawer);
00083
00084 private:
00085
00086 Simple(void) throw();
00087
00088
00089
00090
00091 void initialize(IN Type * type,
00092 IN const char * flash,
00093 IN const char * pulse,
00094 IN const char * direction,
00095 IN smart_ptr<vgfx::Drawer>& drawer);
00096
00097
00098 int m_width;
00099 int m_height;
00100 smart_ptr<TypeVgfxRenderer> m_renderer;
00101 Type * m_type;
00102 std::string m_flash;
00103 std::string m_pulse;
00104 eDpad m_direction;
00105 int m_counter;
00106 };
00107
00108
00109
00110 Simple::Simple
00111 (
00112 void
00113 )
00114 throw()
00115 {
00116 m_type = NULL;
00117
00118 m_width = 400;
00119 m_height = 300;
00120
00121 m_counter = 0;
00122
00123 m_direction = eDpad_Centered;
00124 }
00125
00126
00127
00128 smart_ptr<dialog::Element>
00129 Simple::create
00130 (
00131 IN Type * type,
00132 IN const char * flash,
00133 IN const char * pulse,
00134 IN const char * direction,
00135 IN smart_ptr<vgfx::Drawer>& drawer
00136 )
00137 {
00138 ASSERT(type, "null");
00139
00140
00141
00142 ASSERT(drawer, "null");
00143
00144 smart_ptr<Simple> local = new Simple;
00145 ASSERT(local, "out of memory");
00146
00147 local->initialize(type, flash, pulse, direction, drawer);
00148
00149 return local;
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 void
00161 Simple::draw
00162 (
00163 IN const dialog::point_t& offset
00164 )
00165 {
00166 ++m_counter;
00167
00168
00169 if (s_null != m_flash) {
00170 int on = (m_counter / 20) % 2;
00171 float val = (on) ? 1.0 : 0.0;
00172 m_renderer->setIntensity(m_flash.c_str(), val);
00173
00174 bool setPos = false;
00175 float x = 0.5;
00176 float y = 0.5;
00177 if (eDpad_Left & m_direction) {
00178 setPos = true;
00179 x = 0;
00180 }
00181 if (eDpad_Right & m_direction) {
00182 setPos = true;
00183 x = 1;
00184 }
00185 if (eDpad_Up & m_direction) {
00186 setPos = true;
00187 y = 0;
00188 }
00189 if (eDpad_Down & m_direction) {
00190 setPos = true;
00191 y = 1;
00192 }
00193
00194 if (setPos) {
00195 m_renderer->setPosition(m_flash.c_str(), x, y);
00196 }
00197 }
00198
00199 if (s_null != m_pulse) {
00200 int q = (m_counter % 200) - 100;
00201 if (q < 0) {
00202 q = -q;
00203 }
00204 m_renderer->setIntensity(m_pulse.c_str(), 0.01 * q);
00205 }
00206
00207
00208 m_renderer->draw(offset.x, offset.y, m_width, m_height);
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 void
00220 Simple::initialize
00221 (
00222 IN Type * type,
00223 IN const char * flash,
00224 IN const char * pulse,
00225 IN const char * direction,
00226 IN smart_ptr<vgfx::Drawer>& drawer
00227 )
00228 {
00229 ASSERT(type, "null");
00230
00231
00232
00233 ASSERT(drawer, "null");
00234 ASSERT(!m_type, "already have a type?");
00235
00236 m_type = type;
00237
00238 m_flash = (flash) ? flash : s_null;
00239 m_pulse = (pulse) ? pulse : s_null;
00240
00241 DPRINTF("flash = %s", m_flash.c_str());
00242 DPRINTF("pulse = %s", m_pulse.c_str());
00243
00244 if (direction) {
00245 if (!strcmp("up", direction)) {
00246 m_direction = eDpad_Up;
00247 } else if (!strcmp("down", direction)) {
00248 m_direction = eDpad_Down;
00249 } else if (!strcmp("left", direction)) {
00250 m_direction = eDpad_Left;
00251 } else if (!strcmp("right", direction)) {
00252 m_direction = eDpad_Right;
00253 } else {
00254 DPRINTF("Unknown direction, ignoring: %s", direction);
00255 }
00256 }
00257
00258 m_renderer = TypeVgfxRenderer::create(type, drawer);
00259 ASSERT(m_renderer, "null");
00260 }
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 class SimpleFactory : public dialog::Factory {
00272 public:
00273
00274 ~SimpleFactory(void) throw() { }
00275
00276
00277 smart_ptr<dialog::Element> createElement(IN const char * type,
00278 IN dialog::Manager * mgr,
00279 IN const Datahash * data);
00280
00281
00282 static smart_ptr<dialog::Factory> create(IN smart_ptr<Manager>& mgr,
00283 IN smart_ptr<vgfx::Drawer>& drawer) {
00284 ASSERT(mgr, "null");
00285 ASSERT(drawer, "null");
00286 smart_ptr<SimpleFactory> local = new SimpleFactory;
00287 ASSERT(local, "out of memory");
00288 local->m_mgr = mgr;
00289 local->m_drawer = drawer;
00290 return local;
00291 }
00292 private:
00293
00294 SimpleFactory(void) throw() { }
00295
00296
00297
00298 smart_ptr<Manager> m_mgr;
00299 smart_ptr<vgfx::Drawer> m_drawer;
00300 };
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 smart_ptr<dialog::Element>
00311 SimpleFactory::createElement
00312 (
00313 IN const char * type,
00314 IN dialog::Manager * mgr,
00315 IN const Datahash * data
00316 )
00317 {
00318 ASSERT(type, "null");
00319 ASSERT(mgr, "null");
00320 ASSERT(data, "null");
00321
00322 const char * typeId = getString(data, "typeId");
00323 ASSERT(typeId, "null");
00324 smart_ptr<Type> gpType = m_mgr->getType(typeId);
00325 ASSERT_THROW(gpType, "Failed to retrieve gamepad type: " << typeId);
00326
00327 const char * flash = getOptionalString(data, "flash", NULL);
00328 const char * pulse = getOptionalString(data, "pulse", NULL);
00329 const char * direction = getOptionalString(data, "direction", NULL);
00330
00331 return Simple::create(gpType, flash, pulse, direction, m_drawer);
00332 }
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 void
00344 registerVgfxSimpleFactory
00345 (
00346 IN smart_ptr<Manager>& gamepadMgr,
00347 IN dialog::Manager * dialogMgr,
00348 IN smart_ptr<vgfx::Drawer>& drawer
00349 )
00350 {
00351 ASSERT(gamepadMgr, "null");
00352 ASSERT(dialogMgr, "null");
00353 ASSERT(drawer, "null");
00354
00355 smart_ptr<dialog::Factory> factory =
00356 SimpleFactory::create(gamepadMgr, drawer);
00357 ASSERT(factory, "null");
00358
00359 dialogMgr->registerFactory(s_simpleElementName, factory);
00360 }
00361
00362
00363
00364 const char *
00365 getVgfxSimpleElementName
00366 (
00367 void
00368 )
00369 throw()
00370 {
00371 return s_simpleElementName;
00372 }
00373
00374
00375
00376 };
00377