Hello3DUI.h 2.6 KB

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