/
Metallist64
/
rbfx
Обзор
Документация
Войти
/
Metallist64
/
rbfx
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Source/Samples/01_HelloWorld/HelloWorld.cpp
86 строк
3 KB
gleblebedev
Game screen abstraction (#392)
02 май 2022, 22:14
Не верифицирован
02 май 2022, 22:14
4c6e1c2
Код
Авторство
О чём код?
// // Copyright (c) 2008-2022 the Urho3D project. // // 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 <Urho3D/Core/CoreEvents.h> #include <Urho3D/Core/ProcessUtils.h> #include <Urho3D/Input/Input.h> #include <Urho3D/UI/Font.h> #include <Urho3D/UI/Text.h> #include <Urho3D/UI/UI.h> #include "HelloWorld.h" #include <Urho3D/DebugNew.h> HelloWorld::HelloWorld(Context* context) : Sample(context) { // Set the mouse mode to use in the sample SetMouseMode(MM_FREE); SetMouseVisible(true); } void HelloWorld::Start() { // Execute base class startup Sample::Start(); // Create "Hello World" Text CreateText(); // 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(); } void HelloWorld::CreateText() { auto* cache = GetSubsystem<ResourceCache>(); // Construct new Text object SharedPtr<Text> helloText(new Text(context_)); // Set String to display helloText->SetText("Hello World from Urho3D!"); // Set font and text color helloText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 30); helloText->SetColor(Color(0.0f, 1.0f, 0.0f)); // Align Text center-screen helloText->SetHorizontalAlignment(HA_CENTER); helloText->SetVerticalAlignment(VA_CENTER); // Add Text instance to the UI root element GetUIRoot()->AddChild(helloText); } void HelloWorld::SubscribeToEvents() { } void HelloWorld::Update(float timeStep) { // Do nothing for now, could be extended to eg. animate the display }