Lots of UI Component Updates

This commit is contained in:
2022-10-27 08:16:55 -07:00
parent 57b3354d4c
commit 942de96e16
25 changed files with 387 additions and 56 deletions

View File

@ -65,7 +65,7 @@ float_t Camera::getAspect() {
return target.getWidth() / target.getHeight();
}
void Camera::start() {
void Camera::onStart() {
this->updateProjection();
}

View File

@ -73,7 +73,7 @@ namespace Dawn {
/**
* Event triggered by the scene item when the item is added to the scene.
*/
void start() override;
void onStart() override;
/**
* Disposes a previously initialized camera.

View File

@ -65,7 +65,4 @@ std::shared_ptr<Shader> Material::getShader() {
void Material::setShader(std::shared_ptr<Shader> shader) {
this->shader = shader;
this->updateShaderParameters();
}
void Material::start() {
}

View File

@ -58,10 +58,5 @@ namespace Dawn {
* This method assumes that the shader has already been bound.
*/
void setShaderParameters();
/**
* Overrides the default SceneItemComponent start method.
*/
void start() override;
};
}

View File

@ -11,8 +11,4 @@ MeshRenderer::MeshRenderer(SceneItem &item) :
SceneItemComponent(item)
{
}
void MeshRenderer::start() {
}

View File

@ -18,10 +18,5 @@ namespace Dawn {
* @param item Scene Item this mesh renderer belongs to.
*/
MeshRenderer(SceneItem &item);
/**
* Overrides the default SceneItemComponent start method.
*/
void start() override;
};
}

View File

@ -16,7 +16,6 @@ std::shared_ptr<UICanvas> UICanvas::createCanvas(std::shared_ptr<Scene> scene) {
}
UICanvas::UICanvas(SceneItem &item) : SceneItemComponent(item) {
}
float_t UICanvas::getWidth() {
@ -27,6 +26,27 @@ float_t UICanvas::getHeight() {
return this->getGame().renderManager.getBackBuffer().getHeight();
}
void UICanvas::start() {
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)
;
}

View File

@ -5,6 +5,7 @@
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "display/RenderTarget.hpp"
namespace Dawn {
enum UIDrawType {
@ -16,6 +17,13 @@ namespace Dawn {
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
@ -37,6 +45,8 @@ namespace Dawn {
float_t getWidth();
float_t getHeight();
void start() override;
void onStart() override;
~UICanvas();
};
}