Sample.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Copyright (c) 2008-2016 the Urho3D project.
  3. // Copyright (c) 2014-2016, THUNDERBEAST GAMES LLC All rights reserved
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include <Atomic/Core/Object.h>
  25. #include <Atomic/Core/StringUtils.h>
  26. #include <Atomic/Input/Input.h>
  27. #include <Atomic/UI/UIEditField.h>
  28. namespace Atomic
  29. {
  30. class Node;
  31. class Scene;
  32. class UIEditField;
  33. }
  34. using namespace Atomic;
  35. const float TOUCH_SENSITIVITY = 2.0f;
  36. /// Sample class, as framework for all samples.
  37. /// - Initialization of the Urho3D engine (in Application class)
  38. /// - Modify engine parameters for windowed mode and to show the class name as title
  39. /// - Create Urho3D logo at screen
  40. /// - Set custom window title and icon
  41. /// - Create Console and Debug HUD, and use F1 and F2 key to toggle them
  42. /// - Toggle rendering options from the keys 1-8
  43. /// - Take screenshot with key 9
  44. /// - Handle Esc key down to hide Console or exit application
  45. /// - Init touch input on mobile platform using screen joysticks (patched for each individual sample)
  46. class Sample : public Object
  47. {
  48. // Enable type information.
  49. ATOMIC_OBJECT(Sample, Object)
  50. public:
  51. /// Construct.
  52. Sample(Context* context);
  53. virtual void Start();
  54. virtual void Stop();
  55. protected:
  56. /// Initialize touch input on mobile platform.
  57. void InitTouchInput();
  58. /// Initialize mouse mode on non-web platform.
  59. void InitMouseMode(MouseMode mode);
  60. /// Control logo visibility.
  61. void SetLogoVisible(bool enable);
  62. void SimpleCreateInstructionsWithWasd(const String& extra = String::EMPTY);
  63. void SimpleCreateInstructions(const String& text = String::EMPTY);
  64. void SetInstructions(const String& text = String::EMPTY);
  65. void BackToSelector();
  66. /// Logo sprite.
  67. // SharedPtr<Sprite> logoSprite_;
  68. /// Scene.
  69. SharedPtr<Scene> scene_;
  70. /// Camera scene node.
  71. SharedPtr<Node> cameraNode_;
  72. /// Camera yaw angle.
  73. float yaw_;
  74. /// Camera pitch angle.
  75. float pitch_;
  76. /// Flag to indicate whether touch input has been enabled.
  77. bool touchEnabled_;
  78. /// Mouse mode option to use in the sample.
  79. MouseMode useMouseMode_;
  80. /// for making the instructions writable
  81. SharedPtr<UIEditField> label_;
  82. private:
  83. /// Create logo.
  84. void CreateLogo();
  85. /// Set custom window Title & Icon
  86. void SetWindowTitleAndIcon();
  87. /// Handle request for mouse mode on web platform.
  88. void HandleMouseModeRequest(StringHash eventType, VariantMap& eventData);
  89. /// Handle request for mouse mode change on web platform.
  90. void HandleMouseModeChange(StringHash eventType, VariantMap& eventData);
  91. /// Handle key down event to process key controls common to all samples.
  92. void HandleKeyDown(StringHash eventType, VariantMap& eventData);
  93. /// Handle key up event to process key controls common to all samples.
  94. void HandleKeyUp(StringHash eventType, VariantMap& eventData);
  95. /// Handle scene update event to control camera's pitch and yaw for all samples.
  96. void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
  97. /// Handle touch begin event to initialize touch input on desktop platform.
  98. void HandleTouchBegin(StringHash eventType, VariantMap& eventData);
  99. /// Screen joystick index for navigational controls (mobile platforms only).
  100. unsigned screenJoystickIndex_;
  101. /// Screen joystick index for settings (mobile platforms only).
  102. unsigned screenJoystickSettingsIndex_;
  103. /// Pause flag.
  104. bool paused_;
  105. };