Created
May 27, 2012 19:35
-
-
Save StonedXander/2815614 to your computer and use it in GitHub Desktop.
Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CameraHandler { | |
public: | |
CameraHandler(); | |
Handler<CameraHandler> *getArcballHandler(); | |
void handleKey(Handler<CameraHandler> *, int, int); | |
void handleMouseButton(Handler<CameraHandler> *, int, int); | |
void handleMousePosition(Handler<CameraHandler> *, int, int); | |
void handleMouseWheel(Handler<CameraHandler> *, int); | |
private: | |
Camera *camera; | |
FPSModifier *fpsModifier; | |
Arcball *arcball; | |
ArcballCameraModifier *arcModifier; | |
Handler<CameraHandler> *arcballHandler; | |
}; | |
void CameraHandler::handleKey(Handler<CameraHandler> *handler, int key, int action) { | |
if(handler == arcballHandler) { | |
// Modify 'arcball' using 'key' and 'action'. | |
arcModifier.Update(); | |
} | |
} | |
// Same with CameraHandler::handleMousePosition, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Game::handleKey(int key, int action, UserData *) { | |
Handler<CameraHandler> *handler = getCurrentHandler(); | |
handler->handleKey(key, action); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T> class Handler { | |
public: | |
Handler(); | |
void handleKey(int, int); | |
void handleMousePosition(int, int); | |
void handleMouseButton(int, int); | |
void handleMouseWheel(int); | |
private: | |
T *target; | |
}; | |
template <typename T, typename E> Handler<T, E>::Handler(T *t) : target(t) {} | |
template <typename T, typename E> void Handler<T, E>::handleKey(int a, int b) { | |
target->handleKey(this, a, b); | |
} | |
template <typename T, typename E> void Handler<T, E>::handleMousePosition(int a, int b) { | |
target->handleMousePosition(this, a, b); | |
} | |
template <typename T, typename E> void Handler<T, E>::handleMouseButton(int a, int b) { | |
target->handleMouseButton(this, a, b); | |
} | |
template <typename T, typename E> void Handler<T, E>::handleMouseWheel(int a) { | |
target->handleWheel(this, a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment