| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //
- // Copyright (c) 2008-2016 the Urho3D project.
- // Copyright (c) 2014-2016, THUNDERBEAST GAMES LLC All rights reserved
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #include <Atomic/Core/CoreEvents.h>
- #include <Atomic/Core/ProcessUtils.h>
- #include <Atomic/Input/Input.h>
- #include <Atomic/Graphics/Graphics.h>
- #include <Atomic/UI/UI.h>
- #include <Atomic/UI/UIFontDescription.h>
- #include <Atomic/UI/UIView.h>
- #include <Atomic/UI/UILayout.h>
- #include <Atomic/UI/UITextField.h>
- #include <Atomic/Resource/ResourceCache.h>
- #include <Atomic/Scene/Scene.h>
- #include "FeatureExamples.h"
- #include "HelloWorld.h"
- #include <Atomic/DebugNew.h>
- HelloWorld::HelloWorld(Context* context) :
- Sample(context)
- {
- }
- void HelloWorld::Start()
- {
- // Execute base class startup
- Sample::Start();
- // Create "Hello World" Text
- CreateText();
- SimpleCreateInstructions();
- // Finally subscribe to the update event. Note that by subscribing events at this point we have already missed some events
- // like the ScreenMode event sent by the Graphics subsystem when opening the application window. To catch those as well we
- // could subscribe in the constructor instead.
- SubscribeToEvents();
- // Set the mouse mode to use in the sample
- Sample::InitMouseMode(MM_FREE);
- }
- void HelloWorld::CreateText()
- {
- ResourceCache* cache = GetSubsystem<ResourceCache>();
- Graphics* graphics = GetSubsystem<Graphics>();
- // Say Hello
- UIView* view = FeatureExamples::GetUIView();
- UILayout* layout = new UILayout(context_);
- layout->SetRect(view->GetRect());
- layout->SetLayoutPosition(UI_LAYOUT_POSITION_CENTER);
- layout->SetLayoutDistributionPosition(UI_LAYOUT_DISTRIBUTION_POSITION_CENTER);
- SharedPtr<UIFontDescription> fontDesc(new UIFontDescription(context_));
- fontDesc->SetId("Vera");
- fontDesc->SetSize(24);
- UITextField* label = new UITextField(context_);
- label->SetFontDescription(fontDesc);
- label->SetText("Hello World, from the Atomic Game Engine");
- layout->AddChild(label);
- view->AddChild(layout);
- }
- void HelloWorld::SubscribeToEvents()
- {
- // Subscribe HandleUpdate() function for processing update events
- SubscribeToEvent(E_UPDATE, ATOMIC_HANDLER(HelloWorld, HandleUpdate));
- }
- void HelloWorld::HandleUpdate(StringHash eventType, VariantMap& eventData)
- {
- // Do nothing for now, could be extended to eg. animate the display
- }
|