Changed scene item components to smart pointers

This commit is contained in:
2023-11-10 23:21:59 -06:00
parent bed6e3e1f4
commit 3ab98bf2ea
33 changed files with 84 additions and 97 deletions

View File

@ -9,7 +9,7 @@
using namespace Dawn;
UICanvas * UICanvas::create(Scene *scene) {
std::shared_ptr<UICanvas> UICanvas::create(Scene *scene) {
auto item = scene->createSceneItem();
return item->addComponent<UICanvas>();
}

View File

@ -83,10 +83,10 @@ namespace Dawn {
* @param scene Scene to create the UI Canvas for.
* @return Created UI Canvas.
*/
static UICanvas * create(Scene *scene);
static std::shared_ptr<UICanvas> create(Scene *scene);
//======================================================================//
StateProperty<Camera*> camera;
StateProperty<std::shared_ptr<Camera>> camera;
enum UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE;
/**

View File

@ -21,7 +21,7 @@ UIComponent::UIComponent(SceneItem *item) :
}
UIComponentDimensional * UIComponent::getParentDimensional() {
std::shared_ptr<UIComponentDimensional> UIComponent::getParentDimensional() {
auto parent = this->transform->getParent();
if(parent == nullptr) return nullptr;
auto dimensional = parent->item->getComponent<UIComponentDimensional>();
@ -238,7 +238,7 @@ void UIComponent::calculateDimensions(
}
}
UICanvas * UIComponent::getCanvas() {
std::shared_ptr<UICanvas> UIComponent::getCanvas() {
// TODO: Cache this on first hit.
auto parent = this->transform->getParent();
while(parent != nullptr) {

View File

@ -38,7 +38,7 @@ namespace Dawn {
*
* @return Pointer to the parent dimensional.
*/
UIComponentDimensional * getParentDimensional();
std::shared_ptr<UIComponentDimensional> getParentDimensional();
/**
* Internal method to update the alignment of this item.
@ -130,7 +130,7 @@ namespace Dawn {
*
* @return Pointer to the UI Canvas this component is a child of.
*/
virtual UICanvas * getCanvas();
virtual std::shared_ptr<UICanvas> getCanvas();
float_t getWidth() override;
float_t getHeight() override;

View File

@ -14,7 +14,7 @@ UISimpleMenu::UISimpleMenu(SceneItem *item) :
}
std::vector<SceneItemComponent*> UISimpleMenu::getDependencies() {
std::vector<std::shared_ptr<SceneItemComponent>> UISimpleMenu::getDependencies() {
return {
(this->menu = this->item->getComponent<UIMenuController>()),
(this->canvas == nullptr ? (this->canvas = this->item->getComponent<UICanvas>()) : nullptr)

View File

@ -10,14 +10,14 @@
namespace Dawn {
class UISimpleMenu : public SceneItemComponent {
protected:
UIMenuController *menu = nullptr;
UICanvas *canvas = nullptr;
UISimpleMenuItem *currentlySelected = nullptr;
std::vector<UISimpleMenuItem*> menuItems;
std::shared_ptr<UIMenuController> menu;
std::shared_ptr<UICanvas> canvas;
std::shared_ptr<UISimpleMenuItem> currentlySelected;
std::vector<std::shared_ptr<UISimpleMenuItem>> menuItems;
public:
UISimpleMenu(SceneItem *item);
std::vector<SceneItemComponent*> getDependencies() override;
std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
void onStart() override;
};
}

View File

@ -11,7 +11,7 @@ UISimpleMenuItem::UISimpleMenuItem(SceneItem *item) : SceneItemComponent(item) {
}
UIComponent * UISimpleMenuItem::getComponentForHighlighting() {
std::shared_ptr<UIComponent> UISimpleMenuItem::getComponentForHighlighting() {
if(uiComponent == nullptr) uiComponent = item->getComponent<UIComponent>();
return uiComponent;
}

View File

@ -15,7 +15,7 @@ namespace Dawn {
// May make these into either state events or make a new event.
int32_t menuX = 0;
int32_t menuY = 0;
UIComponent *uiComponent = nullptr;
std::shared_ptr<UIComponent> uiComponent = nullptr;
UISimpleMenuItem(SceneItem *item);
@ -25,6 +25,6 @@ namespace Dawn {
*
* @return UI Component to use for highlighting / hovering.
*/
virtual UIComponent * getComponentForHighlighting();
virtual std::shared_ptr<UIComponent> getComponentForHighlighting();
};
}