BsGUIDropDownHitBox.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "BsGUIDropDownHitBox.h"
  2. #include "BsGUICommandEvent.h"
  3. #include "BsGUIMouseEvent.h"
  4. #include "BsGUIWidget.h"
  5. #include "BsGUISkin.h"
  6. namespace BansheeEngine
  7. {
  8. const String& GUIDropDownHitBox::getGUITypeName()
  9. {
  10. static String name = "DropDownHitBox";
  11. return name;
  12. }
  13. GUIDropDownHitBox* GUIDropDownHitBox::create(bool captureMouse)
  14. {
  15. return new (bs_alloc<GUIDropDownHitBox, PoolAlloc>()) GUIDropDownHitBox(captureMouse, GUILayoutOptions::create());
  16. }
  17. GUIDropDownHitBox* GUIDropDownHitBox::create(bool captureMouse, const GUIOptions& layoutOptions)
  18. {
  19. return new (bs_alloc<GUIDropDownHitBox, PoolAlloc>()) GUIDropDownHitBox(captureMouse, GUILayoutOptions::create(layoutOptions));
  20. }
  21. GUIDropDownHitBox::GUIDropDownHitBox(bool captureMouse, const GUILayoutOptions& layoutOptions)
  22. :GUIElementContainer(layoutOptions), mCaptureMouse(captureMouse)
  23. {
  24. }
  25. bool GUIDropDownHitBox::commandEvent(const GUICommandEvent& ev)
  26. {
  27. bool processed = GUIElementContainer::commandEvent(ev);
  28. if(ev.getType() == GUICommandEventType::FocusGained)
  29. {
  30. if(!onFocusGained.empty())
  31. onFocusGained();
  32. return true;
  33. }
  34. else if(ev.getType() == GUICommandEventType::FocusLost)
  35. {
  36. if(!onFocusLost.empty())
  37. onFocusLost();
  38. return true;
  39. }
  40. return processed;
  41. }
  42. bool GUIDropDownHitBox::mouseEvent(const GUIMouseEvent& ev)
  43. {
  44. bool processed = GUIElementContainer::mouseEvent(ev);
  45. if(mCaptureMouse)
  46. {
  47. if(ev.getType() == GUIMouseEventType::MouseUp)
  48. {
  49. return true;
  50. }
  51. else if(ev.getType() == GUIMouseEventType::MouseDown)
  52. {
  53. return true;
  54. }
  55. }
  56. return processed;
  57. }
  58. bool GUIDropDownHitBox::_isInBounds(const Vector2I position) const
  59. {
  60. for(auto& bound : mBounds)
  61. {
  62. if(bound.contains(position))
  63. return true;
  64. }
  65. return false;
  66. }
  67. };