Sample.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #pragma once
  23. #include <Urho3D/Engine/Application.h>
  24. namespace Urho3D
  25. {
  26. class Node;
  27. class Scene;
  28. class Sprite;
  29. }
  30. // All Urho3D classes reside in namespace Urho3D
  31. using namespace Urho3D;
  32. const float TOUCH_SENSITIVITY = 2.0f;
  33. /// Sample class, as framework for all samples.
  34. /// - Initialization of the Urho3D engine (in Application class)
  35. /// - Modify engine parameters for windowed mode and to show the class name as title
  36. /// - Create Urho3D logo at screen
  37. /// - Set custom window title and icon
  38. /// - Create Console and Debug HUD, and use F1 and F2 key to toggle them
  39. /// - Toggle rendering options from the keys 1-8
  40. /// - Take screenshot with key 9
  41. /// - Handle Esc key down to hide Console or exit application
  42. /// - Init touch input on mobile platform using screen joysticks (patched for each individual sample)
  43. class Sample : public Application
  44. {
  45. // Enable type information.
  46. OBJECT(Sample);
  47. public:
  48. /// Construct.
  49. Sample(Context* context);
  50. /// Setup before engine initialization. Modifies the engine parameters.
  51. virtual void Setup();
  52. /// Setup after engine initialization. Creates the logo, console & debug HUD.
  53. virtual void Start();
  54. /// Cleanup after the main loop. Called by Application.
  55. virtual void Stop();
  56. protected:
  57. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  58. virtual String GetScreenJoystickPatchString() const { return String::EMPTY; }
  59. /// Initialize touch input on mobile platform.
  60. void InitTouchInput();
  61. /// Control logo visibility.
  62. void SetLogoVisible(bool enable);
  63. /// Logo sprite.
  64. SharedPtr<Sprite> logoSprite_;
  65. /// Scene.
  66. SharedPtr<Scene> scene_;
  67. /// Camera scene node.
  68. SharedPtr<Node> cameraNode_;
  69. /// Camera yaw angle.
  70. float yaw_;
  71. /// Camera pitch angle.
  72. float pitch_;
  73. /// Flag to indicate whether touch input has been enabled.
  74. bool touchEnabled_;
  75. private:
  76. /// Create logo.
  77. void CreateLogo();
  78. /// Set custom window Title & Icon
  79. void SetWindowTitleAndIcon();
  80. /// Create console and debug HUD.
  81. void CreateConsoleAndDebugHud();
  82. /// Handle key down event to process key controls common to all samples.
  83. void HandleKeyDown(StringHash eventType, VariantMap& eventData);
  84. /// Handle scene update event to control camera's pitch and yaw for all samples.
  85. void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
  86. /// Handle touch begin event to initialize touch input on desktop platform.
  87. void HandleTouchBegin(StringHash eventType, VariantMap& eventData);
  88. /// Screen joystick index for navigational controls (mobile platforms only).
  89. unsigned screenJoystickIndex_;
  90. /// Screen joystick index for settings (mobile platforms only).
  91. unsigned screenJoystickSettingsIndex_;
  92. /// Pause flag.
  93. bool paused_;
  94. };
  95. #include "Sample.inl"