Files
prog2/Game/Gui/Screen.cpp
Bram Verhulst 5f1dcd5788 Add Alot
2024-06-09 22:03:29 +02:00

40 lines
950 B
C++

#include "pch.h"
#include "Screen.h"
#include "colors.h"
#include "utils.h"
Screen::Screen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
if (!filePath.empty()) {
m_Background = manager->GetTexture(filePath);
}
else {
m_Background = nullptr;
}
}
Screen::~Screen() {
for (GuiElement* b : m_Elements) {
delete b;
}
}
void Screen::AddElement(GuiElement* element) {
m_Elements.push_back(element);
}
void Screen::Update(float elapsedSecs) {
for (GuiElement* b : m_Elements) {
b->Update(elapsedSecs);
}
}
void Screen::Draw() const {
utils::SetColor(Colors::WHITE);
if (m_Background != nullptr) { //Incase there is no background
Rectf dest = Rectf(m_Position, m_Size);
Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight());
m_Background->Draw(dest, src, false);
}
for (GuiElement* GuiElement : m_Elements) {
GuiElement->Draw();
}
}