1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include "MouseManager.h"
- MouseManager::MouseManager()
- {
- for(int i = 0; i < NUMBER_OF_BUTTONS; i++)
- {
- mappingArray[i] = 0;
- }
- }
- bool MouseManager::isDown(int mapping)
- {
- return isInRange(mapping) && mouseArray[mappingArray[mapping]].down;
- }
- bool MouseManager::isReleased(int mapping)
- {
- return isInRange(mapping) && mouseArray[mappingArray[mapping]].shouldRelease;
- }
- unsigned int MouseManager::getDownTime(int mapping)
- {
- bool m = isInRange(mapping);
- return m * mouseArray[mappingArray[mapping * m]].downTime;
- }
- void MouseManager::resetDownTime(int mapping)
- {
- mouseArray[mappingArray[mapping * isInRange(mapping)]].downTime = 0;
- }
- bool MouseManager::map(int mapping, int mouse)
- {
- bool b = isInRange(mapping) && isInRange(mouse);
- mappingArray[mapping * b] = b * mouse;
- }
- bool MouseManager::isInRange(int i)
- {
- return i >= 0 && i < NUMBER_OF_BUTTONS;
- }
- void MouseManager::tick()
- {
- for(int i = 0; i < NUMBER_OF_BUTTONS; i++)
- {
- mouseArray[i].downTime += mouseArray[i].down;
-
- mouseArray[i].down = mouseArray[i].down && !mouseArray[i].shouldRelease;
- mouseArray[i].downTime *= !mouseArray[i].shouldRelease;
- mouseArray[i].shouldRelease = false;
- }
- }
- bool MouseManager::press(int mouse)
- {
- int index = isInRange(mouse) * mouse;
- mouseArray[index].down = true;
- mouseArray[index].shouldRelease = false;
- }
- bool MouseManager::release(int mouse)
- {
- int index = isInRange(mouse) * mouse;
- mouseArray[index].shouldRelease = true;
- }
|