v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
event.h
1 /* -*- mode: C; c-basic-offset: 4; intent-tabs-mode: nil -*-
2  *
3  * This file is part of the public interface to the Sifteo SDK.
4  * Copyright <c> 2012 Sifteo, Inc. All rights reserved.
5  */
6 
7 #pragma once
8 #ifdef NOT_USERSPACE
9 # error This is a userspace-only header, not allowed by the current build.
10 #endif
11 
12 #include <sifteo/abi.h>
13 
14 namespace Sifteo {
15 
16 
36 template <_SYSVectorID tID>
37 struct EventVector {
38  EventVector() {}
39 
47  void unset() const {
48  _SYS_setVector(tID, 0, 0);
49  }
50 
63  template <typename tContext>
64  void set(void (*handler)(tContext, unsigned), tContext context) const {
65  _SYS_setVector(tID, (void*) handler, reinterpret_cast<void*>(context));
66  }
67 
80  void set(void (*handler)(void*, unsigned)) const {
81  _SYS_setVector(tID, (void*) handler, 0);
82  }
83 
88  template <typename tClass>
89  void set(void (tClass::*handler)(unsigned), tClass *cls) const {
90  union {
91  void *pVoid;
92  void (tClass::*pMethod)(unsigned);
93  } u;
94  u.pMethod = handler;
95  _SYS_setVector(tID, u.pVoid, (void*) cls);
96  }
97 
101  void *handler() const {
102  return _SYS_getVectorHandler(tID);
103  }
104 
108  void *context() const {
109  return _SYS_getVectorContext(tID);
110  }
111 };
112 
113 
125 template <_SYSVectorID tID>
127  NullaryEventVector() {}
128 
136  void unset() const {
137  _SYS_setVector(tID, 0, 0);
138  }
139 
148  template <typename tContext>
149  void set(void (*handler)(tContext), tContext context) const {
150  _SYS_setVector(tID, (void*) handler, reinterpret_cast<void*>(context));
151  }
152 
160  void set(void (*handler)()) const {
161  _SYS_setVector(tID, (void*) handler, 0);
162  }
163 
168  template <typename tClass>
169  void set(void (tClass::*handler)(), tClass *cls) const {
170  union {
171  void *pVoid;
172  void (tClass::*pMethod)();
173  } u;
174  u.pMethod = handler;
175  _SYS_setVector(tID, u.pVoid, (void*) cls);
176  }
177 
181  void *handler() const {
182  return _SYS_getVectorHandler(tID);
183  }
184 
188  void *context() const {
189  return _SYS_getVectorContext(tID);
190  }
191 };
192 
193 
203 
209  void unset() const {
210  _SYS_setGameMenuLabel(0);
211  _SYS_setVector(_SYS_BASE_GAME_MENU, 0, 0);
212  }
213 
225  template <typename tContext>
226  void set(void (*handler)(tContext), tContext context, const char *label=0) const {
227  if (label)
228  _SYS_setGameMenuLabel(label);
229  _SYS_setVector(_SYS_BASE_GAME_MENU, (void*) handler, reinterpret_cast<void*>(context));
230  }
231 
243  void set(void (*handler)(void*), const char *label=0) const {
244  if (label)
245  _SYS_setGameMenuLabel(label);
246  _SYS_setVector(_SYS_BASE_GAME_MENU, (void*) handler, 0);
247  }
248 
256  template <typename tClass>
257  void set(void (tClass::*handler)(), tClass *cls, const char *label=0) const {
258  union {
259  void *pVoid;
260  void (tClass::*pMethod)();
261  } u;
262  u.pMethod = handler;
263  if (label)
264  _SYS_setGameMenuLabel(label);
265  _SYS_setVector(_SYS_BASE_GAME_MENU, u.pVoid, (void*) cls);
266  }
267 
271  void *handler() const {
272  return _SYS_getVectorHandler(_SYS_BASE_GAME_MENU);
273  }
274 
278  void *context() const {
279  return _SYS_getVectorContext(_SYS_BASE_GAME_MENU);
280  }
281 
293  void setLabel(const char *label) const {
294  ASSERT(label && label[0]);
295  _SYS_setGameMenuLabel(label);
296  }
297 
303  void setResumeEnabled(bool enabled) const {
304  _SYS_setPauseMenuResumeEnabled(enabled);
305  }
306 };
307 
308 
316 template <_SYSVectorID tID>
319 
327  void unset() const {
328  _SYS_setVector(tID, 0, 0);
329  }
330 
343  template <typename tContext>
344  void set(void (*handler)(tContext, unsigned, unsigned, unsigned, unsigned), tContext context) const {
345  _SYS_setVector(tID, (void*) handler, reinterpret_cast<void*>(context));
346  }
347 
360  void set(void (*handler)(void*, unsigned, unsigned, unsigned, unsigned)) const {
361  _SYS_setVector(tID, (void*) handler, 0);
362  }
363 
368  template <typename tClass>
369  void set(void (tClass::*handler)(unsigned, unsigned, unsigned, unsigned), tClass *cls) const {
370  union {
371  void *pVoid;
372  void (tClass::*pMethod)(unsigned, unsigned, unsigned, unsigned);
373  } u;
374  u.pMethod = handler;
375  _SYS_setVector(tID, u.pVoid, (void*) cls);
376  }
377 
381  void *handler() const {
382  return _SYS_getVectorHandler(tID);
383  }
384 
388  void *context() const {
389  return _SYS_getVectorContext(tID);
390  }
391 };
392 
393 
412 namespace Events {
413 
414  /*
415  * Neighboring events
416  */
417 
420 
423 
424  /*
425  * Cube events
426  */
427 
437 
451 
454 
457 
460 
463 
477 
478  /*
479  * Base events
480  */
481 
484 
487 
490 
493 
494  /*
495  * Bluetooth events
496  */
497 
500 
503 
506 
509 
510  /*
511  * USB events
512  */
513 
516 
519 
522 
525 
526 }; // namespace Events
527 
532 }; // namespace Sifteo