HelloWorld.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include <Atomic/Core/CoreEvents.h>
  24. #include <Atomic/Core/ProcessUtils.h>
  25. #include <Atomic/Input/Input.h>
  26. #include <Atomic/Graphics/Graphics.h>
  27. #include <Atomic/UI/UI.h>
  28. #include <Atomic/UI/UIFontDescription.h>
  29. #include <Atomic/UI/UIView.h>
  30. #include <Atomic/UI/UILayout.h>
  31. #include <Atomic/UI/UITextField.h>
  32. #include <Atomic/Resource/ResourceCache.h>
  33. #include <Atomic/Scene/Scene.h>
  34. #include "FeatureExamples.h"
  35. #include "HelloWorld.h"
  36. #include <Atomic/DebugNew.h>
  37. HelloWorld::HelloWorld(Context* context) :
  38. Sample(context)
  39. {
  40. }
  41. void HelloWorld::Start()
  42. {
  43. // Execute base class startup
  44. Sample::Start();
  45. // Create "Hello World" Text
  46. CreateText();
  47. SimpleCreateInstructions();
  48. // Finally subscribe to the update event. Note that by subscribing events at this point we have already missed some events
  49. // like the ScreenMode event sent by the Graphics subsystem when opening the application window. To catch those as well we
  50. // could subscribe in the constructor instead.
  51. SubscribeToEvents();
  52. // Set the mouse mode to use in the sample
  53. Sample::InitMouseMode(MM_FREE);
  54. }
  55. void HelloWorld::CreateText()
  56. {
  57. ResourceCache* cache = GetSubsystem<ResourceCache>();
  58. Graphics* graphics = GetSubsystem<Graphics>();
  59. // Say Hello
  60. UIView* view = FeatureExamples::GetUIView();
  61. UILayout* layout = new UILayout(context_);
  62. layout->SetRect(view->GetRect());
  63. layout->SetLayoutPosition(UI_LAYOUT_POSITION_CENTER);
  64. layout->SetLayoutDistributionPosition(UI_LAYOUT_DISTRIBUTION_POSITION_CENTER);
  65. SharedPtr<UIFontDescription> fontDesc(new UIFontDescription(context_));
  66. fontDesc->SetId("Vera");
  67. fontDesc->SetSize(24);
  68. UITextField* label = new UITextField(context_);
  69. label->SetFontDescription(fontDesc);
  70. label->SetText("Hello World, from the Atomic Game Engine");
  71. layout->AddChild(label);
  72. view->AddChild(layout);
  73. }
  74. void HelloWorld::SubscribeToEvents()
  75. {
  76. // Subscribe HandleUpdate() function for processing update events
  77. SubscribeToEvent(E_UPDATE, ATOMIC_HANDLER(HelloWorld, HandleUpdate));
  78. }
  79. void HelloWorld::HandleUpdate(StringHash eventType, VariantMap& eventData)
  80. {
  81. // Do nothing for now, could be extended to eg. animate the display
  82. }