Update Screen system

Added FuelScreen (Working buttons)
Added SellScreen (Nothing working)
This commit is contained in:
Bram Verhulst
2024-04-04 00:07:45 +02:00
parent df9e2f0b64
commit eb4c7b4d76
20 changed files with 759 additions and 45 deletions

View File

@@ -1 +1,37 @@
#include "Button.h"
#include <iostream>
#include "colors.h"
#include "utils.h"
Button::Button(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
m_Texture = manager->GetTexture(filePath);
if(size.x == 0 && size.y == 0) {
m_Size = Point2f{float(m_Texture->GetWidth()), float(m_Texture->GetHeight())};
}
std::cout << "Button created" << '\n';
}
Button::~Button() {
std::cout << "Button destroyed" << '\n';
}
void Button::Draw() const {
Rectf dest = Rectf(m_Position, m_Size);
Rectf src = Rectf(0, 0, m_Texture->GetWidth(), m_Texture->GetHeight());
if(m_IsHovered) {
m_Texture->Draw(dest, src, false);
}
}
void Button::Update(float elapsedSec) {
Point2f mousePos = utils::GetMousePos();
Rectf buttonRect = Rectf(m_Position, m_Size);
this->m_IsHovered = utils::IsPointInRect(mousePos, buttonRect);
m_IsPressed = m_IsHovered && utils::IsMouseButtonDown(SDL_BUTTON_LEFT);
if(m_IsPressed) {
m_OnClick();
}
}