Button.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ? id : "";
  17. button->initialize("Button", style, NULL);
  18. return button;
  19. }
  20. Control* Button::create(Theme::Style* style, Properties* properties)
  21. {
  22. Button* button = new Button();
  23. button->initialize("Button", style, properties);
  24. return button;
  25. }
  26. void Button::initialize(const char* typeName, Theme::Style* style, Properties* properties)
  27. {
  28. Label::initialize(typeName, style, properties);
  29. if (properties)
  30. {
  31. // Different types of data bindings can be named differently in a button namespace.
  32. // Gamepad button mappings have the name "mapping" and correspond to Gamepad::ButtonMapping enums.
  33. const char* mapping = properties->getString("mapping");
  34. if (mapping)
  35. {
  36. _dataBinding = Gamepad::getButtonMappingFromString(mapping);
  37. }
  38. }
  39. }
  40. const char* Button::getType() const
  41. {
  42. return "button";
  43. }
  44. const unsigned int Button::getDataBinding() const
  45. {
  46. return _dataBinding;
  47. }
  48. void Button::setDataBinding(unsigned int dataBinding)
  49. {
  50. _dataBinding = dataBinding;
  51. }
  52. }