HelloGUI.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 simple 'HelloWorld' GUI created purely from code.
  10. /// This sample demonstrates:
  11. /// - Creation of controls and building a UI hierarchy
  12. /// - Loading UI style from XML and applying it to controls
  13. /// - Handling of global and per-control events
  14. /// For more advanced users (beginners can skip this section):
  15. /// - Dragging UIElements
  16. /// - Displaying tooltips
  17. /// - Accessing available Events data (eventData)
  18. class HelloGUI : public Sample
  19. {
  20. URHO3D_OBJECT(HelloGUI, Sample);
  21. public:
  22. /// Construct.
  23. explicit HelloGUI(Context* context);
  24. /// Setup after engine initialization and before running the main loop.
  25. void Start() override;
  26. protected:
  27. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  28. String GetScreenJoystickPatchString() const override { return
  29. "<patch>"
  30. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Hat0']]\">"
  31. " <attribute name=\"Is Visible\" value=\"false\" />"
  32. " </add>"
  33. "</patch>";
  34. }
  35. private:
  36. /// Create and initialize a Window control.
  37. void InitWindow();
  38. /// Create and add various common controls for demonstration purposes.
  39. void InitControls();
  40. /// Create a draggable fish button.
  41. void CreateDraggableFish();
  42. /// Handle drag begin for the fish button.
  43. void HandleDragBegin(StringHash eventType, VariantMap& eventData);
  44. /// Handle drag move for the fish button.
  45. void HandleDragMove(StringHash eventType, VariantMap& eventData);
  46. /// Handle drag end for the fish button.
  47. void HandleDragEnd(StringHash eventType, VariantMap& eventData);
  48. /// Handle any UI control being clicked.
  49. void HandleControlClicked(StringHash eventType, VariantMap& eventData);
  50. /// Handle close button pressed and released.
  51. void HandleClosePressed(StringHash eventType, VariantMap& eventData);
  52. /// The Window.
  53. SharedPtr<Window> window_;
  54. /// The UI's root UIElement.
  55. SharedPtr<UIElement> uiRoot_;
  56. /// Remembered drag begin position.
  57. IntVector2 dragBeginPosition_;
  58. };