Hello3DUI.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // Copyright (c) 2008-2017 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. #pragma once
  23. #include "Sample.h"
  24. namespace Urho3D
  25. {
  26. class Window;
  27. }
  28. /// A 3D UI demonstration based on the HelloGUI sample. Renders UI alternatively
  29. /// either to a 3D scene object using UIComponent, or directly to the backbuffer.
  30. class Hello3DUI : public Sample
  31. {
  32. URHO3D_OBJECT(Hello3DUI, Sample);
  33. public:
  34. /// Construct.
  35. Hello3DUI(Context* context);
  36. /// Setup after engine initialization and before running the main loop.
  37. virtual void Start() override;
  38. protected:
  39. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  40. virtual String GetScreenJoystickPatchString() const override { return
  41. "<patch>"
  42. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Hat0']]\">"
  43. " <attribute name=\"Is Visible\" value=\"false\" />"
  44. " </add>"
  45. "</patch>";
  46. }
  47. private:
  48. /// Create and initialize a Scene.
  49. void InitScene();
  50. /// Create and initialize a Window control.
  51. void InitWindow();
  52. /// Create and add various common controls for demonstration purposes.
  53. void InitControls();
  54. /// Create a draggable fish button.
  55. void CreateDraggableFish();
  56. /// Handle drag begin for the fish button.
  57. void HandleDragBegin(StringHash eventType, VariantMap& eventData);
  58. /// Handle drag move for the fish button.
  59. void HandleDragMove(StringHash eventType, VariantMap& eventData);
  60. /// Handle drag end for the fish button.
  61. void HandleDragEnd(StringHash eventType, VariantMap& eventData);
  62. /// Handle any UI control being clicked.
  63. void HandleControlClicked(StringHash eventType, VariantMap& eventData);
  64. /// Handle close button pressed and released.
  65. void HandleClosePressed(StringHash eventType, VariantMap& eventData);
  66. /// Animate cube.
  67. void HandleUpdate(StringHash, VariantMap& eventData);
  68. /// Create 3D UI.
  69. void Init3DUI();
  70. /// The Scene.
  71. SharedPtr<Scene> scene_;
  72. /// The Window.
  73. SharedPtr<Window> window_;
  74. /// The UI's root UIElement.
  75. SharedPtr<UIElement> uiRoot_;
  76. /// Remembered drag begin position.
  77. IntVector2 dragBeginPosition_;
  78. /// Root UI element of texture.
  79. SharedPtr<UIElement> textureRoot_;
  80. /// UI element with instructions.
  81. SharedPtr<Text> instructions_;
  82. /// Enable or disable cube rotation.
  83. bool animateCube_;
  84. /// Enable or disable rendering to texture.
  85. bool renderOnCube_;
  86. /// Draw debug information of last clicked element.
  87. bool drawDebug_;
  88. /// Last clicked UI element.
  89. WeakPtr<UIElement> current_;
  90. };