Button.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "Base.h"
  2. #include "Button.h"
  3. #include "Gamepad.h"
  4. namespace gameplay
  5. {
  6. Button::Button() : _dataBinding(0)
  7. {
  8. _canFocus = true;
  9. }
  10. Button::~Button()
  11. {
  12. }
  13. Button* Button::create(const char* id, Theme::Style* style)
  14. {
  15. Button* button = new Button();
  16. button->_id = id;
  17. button->_style = style;
  18. return button;
  19. }
  20. Control* Button::create(Theme::Style* style, Properties* properties)
  21. {
  22. Button* button = new Button();
  23. button->initialize(style, properties);
  24. // Different types of data bindings can be named differently in a button namespace.
  25. // Gamepad button mappings have the name "mapping" and correspond to Gamepad::ButtonMapping enums.
  26. const char* mapping = properties->getString("mapping");
  27. if (mapping)
  28. {
  29. button->_dataBinding = Gamepad::getButtonMappingFromString(mapping);
  30. }
  31. return button;
  32. }
  33. const char* Button::getType() const
  34. {
  35. return "button";
  36. }
  37. const unsigned int Button::getDataBinding() const
  38. {
  39. return _dataBinding;
  40. }
  41. void Button::setDataBinding(unsigned int dataBinding)
  42. {
  43. _dataBinding = dataBinding;
  44. }
  45. }