UI Hello World
This commit is contained in:
@ -35,5 +35,4 @@ std::shared_ptr<SceneItem> Scene::createSceneItem() {
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
std::cout << "What the dick" << std::endl;
|
||||
}
|
@ -71,6 +71,42 @@ namespace Dawn {
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a (direct) child of this component that has a matching component.
|
||||
*
|
||||
* @tparam T Component to find child of.
|
||||
* @return Pointer to the child, or nullptr if not found.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> findChild() {
|
||||
auto it = this->transform.children.begin();
|
||||
while(it != this->transform.children.end()) {
|
||||
auto child = (*it)->item.getComponent<T>();
|
||||
if(child != nullptr) return child;
|
||||
++it;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all (direct) children of this component that match the queried
|
||||
* component.
|
||||
*
|
||||
* @tparam T Component to find children for.
|
||||
* @return Array of pointers to matching children.
|
||||
*/
|
||||
template<class T>
|
||||
std::vector<std::shared_ptr<T>> findChildren() {
|
||||
auto it = this->transform.children.begin();
|
||||
std::vector<std::shared_ptr<T>> children;
|
||||
while(it != this->transform.children.end()) {
|
||||
auto child = (*it)->item.getComponent<T>();
|
||||
if(child != nullptr) children.push_back(child);
|
||||
++it;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this SceneItem.
|
||||
|
@ -4,4 +4,5 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(ui)
|
10
src/dawn/scene/components/ui/CMakeLists.txt
Normal file
10
src/dawn/scene/components/ui/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UICanvas.cpp
|
||||
)
|
32
src/dawn/scene/components/ui/UICanvas.cpp
Normal file
32
src/dawn/scene/components/ui/UICanvas.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UICanvas.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "ui/UIComponent.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::shared_ptr<UICanvas> UICanvas::createCanvas(std::shared_ptr<Scene> scene) {
|
||||
auto item = scene->createSceneItem();
|
||||
return item->addComponent<UICanvas>();
|
||||
}
|
||||
|
||||
UICanvas::UICanvas(SceneItem &item) : SceneItemComponent(item) {
|
||||
|
||||
}
|
||||
|
||||
float_t UICanvas::getWidth() {
|
||||
return this->getGame().renderManager.getBackBuffer().getWidth();
|
||||
}
|
||||
|
||||
float_t UICanvas::getHeight() {
|
||||
return this->getGame().renderManager.getBackBuffer().getHeight();
|
||||
}
|
||||
|
||||
void UICanvas::start() {
|
||||
|
||||
}
|
42
src/dawn/scene/components/ui/UICanvas.hpp
Normal file
42
src/dawn/scene/components/ui/UICanvas.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum UIDrawType {
|
||||
UI_DRAW_TYPE_WORLD_ABSOLUTE,
|
||||
UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE,
|
||||
UI_DRAW_TYPE_CAMERA_OVERLAY
|
||||
};
|
||||
|
||||
class UIComponent;
|
||||
|
||||
class UICanvas : public SceneItemComponent {
|
||||
public:
|
||||
static std::shared_ptr<UICanvas> createCanvas(
|
||||
std::shared_ptr<Scene> scene
|
||||
);
|
||||
|
||||
//
|
||||
std::vector<std::shared_ptr<UIComponent>> children;
|
||||
UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE;
|
||||
|
||||
UICanvas(SceneItem &item);
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> addElement() {
|
||||
auto item = std::make_shared<T>(*this);
|
||||
this->children.push_back(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
float_t getWidth();
|
||||
float_t getHeight();
|
||||
|
||||
void start() override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user