UIRoot.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "Context.h"
  24. #include "Graphics.h"
  25. #include "GraphicsEvents.h"
  26. #include "InputEvents.h"
  27. #include "Log.h"
  28. #include "Node.h"
  29. #include "UIRoot.h"
  30. #include "DebugNew.h"
  31. namespace Urho3D
  32. {
  33. extern URHO3D_API const float PIXEL_SIZE;
  34. UIRoot::UIRoot(Context* context) :
  35. UIRect(context)
  36. {
  37. SubscribeToEvent(E_SCREENMODE, HANDLER(UIRoot, HandleScreenMode));
  38. SubscribeToEvent(E_MOUSEBUTTONDOWN, HANDLER(UIRoot, HandleMouseButtonDown));
  39. SubscribeToEvent(E_MOUSEBUTTONUP, HANDLER(UIRoot, HandleMouseButtonUp));
  40. SubscribeToEvent(E_MOUSEMOVE, HANDLER(UIRoot, HandleMouseMove));
  41. // SubscribeToEvent(E_MOUSEWHEEL, HANDLER(UIRoot, HandleMouseWheel));
  42. // SubscribeToEvent(E_TOUCHBEGIN, HANDLER(UIRoot, HandleTouchBegin));
  43. // SubscribeToEvent(E_TOUCHEND, HANDLER(UIRoot, HandleTouchEnd));
  44. // SubscribeToEvent(E_TOUCHMOVE, HANDLER(UIRoot, HandleTouchMove));
  45. // SubscribeToEvent(E_KEYDOWN, HANDLER(UIRoot, HandleKeyDown));
  46. // SubscribeToEvent(E_TEXTINPUT, HANDLER(UIRoot, HandleTextInput));
  47. // SubscribeToEvent(E_DROPFILE, HANDLER(UIRoot, HandleDropFile));
  48. }
  49. UIRoot::~UIRoot()
  50. {
  51. }
  52. void UIRoot::RegisterObject(Context* context)
  53. {
  54. context->RegisterFactory<UIRoot>();
  55. }
  56. void UIRoot::OnNodeSet(Node* node)
  57. {
  58. Graphics* graphics = GetSubsystem<Graphics>();
  59. float width = (float)(graphics->GetWidth()) * PIXEL_SIZE;
  60. float height = (float)(graphics->GetHeight()) * PIXEL_SIZE;
  61. SetSize(Vector2(width, height));
  62. }
  63. void UIRoot::HandleScreenMode(StringHash eventType, VariantMap& eventData)
  64. {
  65. using namespace ScreenMode;
  66. float width = ((float)eventData[P_WIDTH].GetInt()) * PIXEL_SIZE;
  67. float height = ((float)eventData[P_HEIGHT].GetInt()) * PIXEL_SIZE;
  68. SetSize(Vector2(width, height));
  69. }
  70. void UIRoot::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
  71. {
  72. using namespace MouseButtonDown;
  73. // TODO:
  74. }
  75. void UIRoot::HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
  76. {
  77. using namespace MouseButtonUp;
  78. // TODO:
  79. }
  80. void UIRoot::HandleMouseMove(StringHash eventType, VariantMap& eventData)
  81. {
  82. using namespace MouseMove;
  83. // TODO:
  84. }
  85. }