Gamepad::Gamepad(const char* formPath) : _handle((GamepadHandle)INT_MAX), _buttonCount(0), _joystickCount(0), _triggerCount(0), _form(NULL), _buttons(0) { GP_ASSERT(formPath); _form = Form::create(formPath); GP_ASSERT(_form); _form->setConsumeInputEvents(false); _name = "Virtual"; for (int i = 0; i < 2; ++i) { _uiJoysticks[i] = NULL; _triggers[i] = 0.0f; } for (int i = 0; i < 20; ++i) { _uiButtons[i] = NULL; } bindGamepadControls(_form); _joysticks[ 0 ] = Vector2::zero( ); _joysticks[ 1 ] = Vector2::zero( ); }
void Gamepad::bindGamepadControls(Container* container) { std::vector<Control*> controls = container->getControls(); std::vector<Control*>::iterator itr = controls.begin(); for (; itr != controls.end(); itr++) { Control* control = *itr; GP_ASSERT(control); if (control->isContainer()) { bindGamepadControls((Container*) control); } else if (std::strcmp("JoystickControl", control->getTypeName()) == 0) { JoystickControl* joystick = (JoystickControl*)control; joystick->setConsumeInputEvents(true); _uiJoysticks[joystick->getIndex()] = joystick; _joystickCount++; } else if (std::strcmp("Button", control->getTypeName()) == 0) { Button* button = (Button*)control; button->setConsumeInputEvents(true); button->setCanFocus(false); _uiButtons[button->getDataBinding()] = button; _buttonCount++; } } }
void Gamepad::bindGamepadControls(Container* container) { std::vector<Control*> controls = container->getControls(); std::vector<Control*>::iterator itr = controls.begin(); for (; itr != controls.end(); itr++) { Control* control = *itr; GP_ASSERT(control); if (control->isContainer()) { bindGamepadControls((Container*) control); } else if (std::strcmp("joystick", control->getType()) == 0) { control->addRef(); if (!_uiJoysticks) _uiJoysticks = new std::vector<Joystick*>; _uiJoysticks->push_back((Joystick*) control); _joystickCount++; } else if (std::strcmp("button", control->getType()) == 0) { control->addRef(); if (!_uiButtons) _uiButtons = new std::vector<Button*>; _uiButtons->push_back((Button*) control); _buttonCount++; } } }
Gamepad::Gamepad(unsigned int handle, const char* formPath) : _id(""), _handle(handle), _buttonCount(0), _joystickCount(0), _triggerCount(0), _gamepadForm(NULL), _uiJoysticks(NULL), _uiButtons(NULL) { GP_ASSERT(formPath); _gamepadForm = Form::create(formPath); GP_ASSERT(_gamepadForm); _gamepadForm->setConsumeInputEvents(false); _id = _gamepadForm->getId(); bindGamepadControls(_gamepadForm); }
Gamepad::Gamepad(const char* formPath) : _handle((GamepadHandle)INT_MAX), _buttonCount(0), _joystickCount(0), _triggerCount(0), _vendorId(0), _productId(0), _form(NULL), _buttons(0) { GP_ASSERT(formPath); _form = Form::create(formPath); GP_ASSERT(_form); _form->setConsumeInputEvents(false); _vendorString = "None"; _productString = "Virtual"; for (int i = 0; i < 2; ++i) { _uiJoysticks[i] = NULL; } for (int i = 0; i < 20; ++i) { _uiButtons[i] = NULL; } bindGamepadControls(_form); }