HelloWorld.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // Finally subscribe to the update event. Note that by subscribing events at this point we have already missed some events
  48. // like the ScreenMode event sent by the Graphics subsystem when opening the application window. To catch those as well we
  49. // could subscribe in the constructor instead.
  50. SubscribeToEvents();
  51. // Set the mouse mode to use in the sample
  52. Sample::InitMouseMode(MM_FREE);
  53. }
  54. void HelloWorld::CreateText()
  55. {
  56. ResourceCache* cache = GetSubsystem<ResourceCache>();
  57. Graphics* graphics = GetSubsystem<Graphics>();
  58. // Say Hello
  59. UIView* view = FeatureExamples::GetUIView();
  60. UILayout* layout = new UILayout(context_);
  61. layout->SetRect(view->GetRect());
  62. layout->SetLayoutPosition(UI_LAYOUT_POSITION_CENTER);
  63. layout->SetLayoutDistributionPosition(UI_LAYOUT_DISTRIBUTION_POSITION_CENTER);
  64. SharedPtr<UIFontDescription> fontDesc(new UIFontDescription(context_));
  65. fontDesc->SetId("Vera");
  66. fontDesc->SetSize(24);
  67. UITextField* label = new UITextField(context_);
  68. label->SetFontDescription(fontDesc);
  69. label->SetText("Hello World, from the Atomic Game Engine");
  70. layout->AddChild(label);
  71. view->AddChild(layout);
  72. }
  73. void HelloWorld::SubscribeToEvents()
  74. {
  75. // Subscribe HandleUpdate() function for processing update events
  76. SubscribeToEvent(E_UPDATE, ATOMIC_HANDLER(HelloWorld, HandleUpdate));
  77. }
  78. void HelloWorld::HandleUpdate(StringHash eventType, VariantMap& eventData)
  79. {
  80. // Do nothing for now, could be extended to eg. animate the display
  81. }