Part one - removed references and smart pointers

This commit is contained in:
2022-11-11 19:08:46 -08:00
parent e892224900
commit e6d475d170
76 changed files with 3899 additions and 3707 deletions

View File

@ -1,52 +1,51 @@
// 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::onStart() {
std::cout << "Canvas event" << std::endl;
this->getGame().renderManager.getBackBuffer()
.eventRenderTargetResized.addListener(this, &UICanvas::onBackBufferResize)
;
}
void UICanvas::onBackBufferResize(
RenderTarget &target,
float_t width,
float_t height
) {
auto it = this->children.begin();
while(it != this->children.end()) {
(*it)->updatePositions();
++it;
}
}
UICanvas::~UICanvas() {
this->getGame().renderManager.getBackBuffer()
.eventRenderTargetResized.removeListener(this, &UICanvas::onBackBufferResize)
;
// 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;
UICanvas * UICanvas::createCanvas(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::onStart() {
this->getGame()->renderManager.getBackBuffer()->eventRenderTargetResized
.addListener(this, &UICanvas::onBackBufferResize)
;
}
void UICanvas::onBackBufferResize(
RenderTarget *target,
float_t width,
float_t height
) {
auto it = this->children.begin();
while(it != this->children.end()) {
(*it)->updatePositions();
++it;
}
}
UICanvas::~UICanvas() {
this->getGame()->renderManager.getBackBuffer()->eventRenderTargetResized
.removeListener(this, &UICanvas::onBackBufferResize)
;
}

View File

@ -1,52 +1,80 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "display/RenderTarget.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 {
protected:
void onBackBufferResize(
RenderTarget &target,
float_t width,
float_t height
);
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 onStart() override;
~UICanvas();
};
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "display/RenderTarget.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 {
protected:
void onBackBufferResize(
RenderTarget *target,
float_t width,
float_t height
);
public:
/**
* Creates a UI Canvas Scene Item Element, and attaches it to the provided
* scene.
*
* @param scene Scene to create the UI Canvas for.
* @return Created UI Canvas.
*/
static UICanvas * createCanvas(Scene *scene);
//
std::vector<UIComponent*> children;
UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE;
/**
* Constructs the UI Canvas Scene Item Component.
*
* @param item Item that this canvas item belongs to.
*/
UICanvas(SceneItem *item);
/**
* Construct and append a UI item to this UI Canvas.
*
* @tparam Type of the UI Item.
* @return Pointer to the created UI Item.
*/
template<class T>
T * addElement() {
auto item = new T(this);
this->children.push_back(item);
return item;
}
/**
* Returns the width of the root UI Canvas size. In future I may allow
* this to be dynamic, right now it uses the render canvas however.
*
* @return Width of the UI Canvas.
*/
float_t getWidth();
/**
* Returns the height of this UI Canvas element.
*
* @return Height of the UI Canvas.
*/
float_t getHeight();
void onStart() override;
~UICanvas();
};
}