v1.0.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 
123 
129  void unset() const {
130  _SYS_setGameMenuLabel(0);
131  _SYS_setVector(_SYS_BASE_GAME_MENU, 0, 0);
132  }
133 
145  template <typename tContext>
146  void set(void (*handler)(tContext), tContext context, const char *label=0) const {
147  if (label)
148  _SYS_setGameMenuLabel(label);
149  _SYS_setVector(_SYS_BASE_GAME_MENU, (void*) handler, reinterpret_cast<void*>(context));
150  }
151 
163  void set(void (*handler)(void*), const char *label=0) const {
164  if (label)
165  _SYS_setGameMenuLabel(label);
166  _SYS_setVector(_SYS_BASE_GAME_MENU, (void*) handler, 0);
167  }
168 
176  template <typename tClass>
177  void set(void (tClass::*handler)(), tClass *cls, const char *label=0) const {
178  union {
179  void *pVoid;
180  void (tClass::*pMethod)();
181  } u;
182  u.pMethod = handler;
183  if (label)
184  _SYS_setGameMenuLabel(label);
185  _SYS_setVector(_SYS_BASE_GAME_MENU, u.pVoid, (void*) cls);
186  }
187 
191  void *handler() const {
192  return _SYS_getVectorHandler(_SYS_BASE_GAME_MENU);
193  }
194 
198  void *context() const {
199  return _SYS_getVectorContext(_SYS_BASE_GAME_MENU);
200  }
201 
213  void setLabel(const char *label)
214  {
215  ASSERT(label && label[0]);
216  _SYS_setGameMenuLabel(label);
217  }
218 };
219 
220 
228 template <_SYSVectorID tID>
231 
239  void unset() const {
240  _SYS_setVector(tID, 0, 0);
241  }
242 
255  template <typename tContext>
256  void set(void (*handler)(tContext, unsigned, unsigned, unsigned, unsigned), tContext context) const {
257  _SYS_setVector(tID, (void*) handler, reinterpret_cast<void*>(context));
258  }
259 
272  void set(void (*handler)(void*, unsigned, unsigned, unsigned, unsigned)) const {
273  _SYS_setVector(tID, (void*) handler, 0);
274  }
275 
280  template <typename tClass>
281  void set(void (tClass::*handler)(unsigned, unsigned, unsigned, unsigned), tClass *cls) const {
282  union {
283  void *pVoid;
284  void (tClass::*pMethod)(unsigned, unsigned, unsigned, unsigned);
285  } u;
286  u.pMethod = handler;
287  _SYS_setVector(tID, u.pVoid, (void*) cls);
288  }
289 
293  void *handler() const {
294  return _SYS_getVectorHandler(tID);
295  }
296 
300  void *context() const {
301  return _SYS_getVectorContext(tID);
302  }
303 };
304 
305 
324 namespace Events {
325 
326  /*
327  * Neighboring events
328  */
329 
332 
335 
336  /*
337  * Cube events
338  */
339 
349 
363 
366 
369 
372 
375 
389 
390  /*
391  * Base events
392  */
393 
396 
399 
402 
405 
406 }; // namespace Events
407 
412 }; // namespace Sifteo