Remove Point2f, replace with Vector2f

This commit is contained in:
Bram Verhulst
2024-04-17 13:54:48 +02:00
parent 64e96ab209
commit db83ae5e13
42 changed files with 494 additions and 634 deletions

View File

@@ -5,10 +5,10 @@
#include "colors.h"
#include "utils.h"
Button::Button(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
Button::Button(const std::string& filePath, Vector2f pos, Vector2f 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())};
m_Size = Vector2f{float(m_Texture->GetWidth()), float(m_Texture->GetHeight())};
}
std::cout << "Button created" << '\n';
}
@@ -23,7 +23,7 @@ void Button::Draw() const {
}
}
void Button::Update(float elapsedSec) {
Point2f mousePos = utils::GetMousePos();
Vector2f mousePos = utils::GetMousePos();
Rectf buttonRect = Rectf(m_Position, m_Size);
this->m_IsHovered = utils::IsPointInRect(mousePos, buttonRect);

View File

@@ -9,7 +9,7 @@ class Button
{
public:
Button() = default;
Button(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager);
Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
~Button();
void Draw() const;
void Update(float elapsedSec);
@@ -20,8 +20,8 @@ public:
private:
Texture* m_Texture{ nullptr };
Point2f m_Position;
Point2f m_Size;
Vector2f m_Position;
Vector2f m_Size;
bool m_IsHovered{ false };
bool m_IsPressed{ false };

View File

@@ -1,7 +1,7 @@
#include "pch.h"
#include "Screen.h"
Screen::Screen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
Screen::Screen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
m_Background = manager->GetTexture(filePath);
}
Screen::~Screen() {

View File

@@ -10,7 +10,7 @@ class Screen
{
public:
Screen() = default;
Screen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager);
Screen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
virtual ~Screen();
@@ -19,8 +19,8 @@ public:
virtual void Update(float elapsedSecs);
virtual void Draw() const;
private:
Point2f m_Position;
Point2f m_Size;
Vector2f m_Position;
Vector2f m_Size;
Texture* m_Background{ nullptr };

View File

@@ -3,40 +3,40 @@
#include "ScreenManager.h"
#include "utils.h"
FuelScreen::FuelScreen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): Screen(filePath, pos, size, manager)
FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): Screen(filePath, pos, size, manager)
{
Point2f fuelScreenSize = Point2f { 492, 396 };
Point2f fuelScreenCenter = Point2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
const Vector2f fuelScreenSize = Vector2f { 492, 396 };
// Vector2f fuelScreenCenter = Vector2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
const Vector2f ScreenCenter = Vector2f { utils::GetViewport().x / 2, utils::GetViewport().y / 2 };
Point2f closeButtonOffset = Point2f { 460, 396 - 14 };
Point2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
const Vector2f fuelScreenCenter = ScreenCenter - fuelScreenSize / 2;
const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 };
Vector2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
closeButtonPos.y -= 18;
Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
closeFuelButton->SetOnClick([this]() { ScreenManager::GetInstance()->CloseScreen(); });
this->AddButton(closeFuelButton);
Point2f oneDollarButtonPos = Point2f { 451, 287 };
oneDollarButtonPos += fuelScreenCenter;
Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Point2f{0,0}, TextureManager::GetInstance() };
const Vector2f oneDollarButtonPos = Vector2f { 451, 287 };
Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(fiveDollarButton);
Point2f tenDollarButtonPos = oneDollarButtonPos + Point2f { 113, -1 };
tenDollarButtonPos += fuelScreenCenter;
Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
const Vector2f tenDollarButtonPos = oneDollarButtonPos + Vector2f { 113, -1 };
Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(tenDollarButton);
Point2f twentyFiveDollarButtonPos = oneDollarButtonPos + Point2f { 0, -89 };
twentyFiveDollarButtonPos += fuelScreenCenter;
Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
const Vector2f twentyFiveDollarButtonPos = oneDollarButtonPos + Vector2f { 0, -89 };
Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(twentyFiveDollarButton);
Point2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Point2f { 114, 0 };
Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
const Vector2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Vector2f { 114, 0 };
Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(fiftyDollarButton);
Point2f fillTankButtonPos = Point2f { 450, 108 };
fillTankButtonPos += fuelScreenCenter;
Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
const Vector2f fillTankButtonPos = Vector2f { 450, 108 };
Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(fillTankButton);
}

View File

@@ -5,7 +5,7 @@ class FuelScreen : public Screen
{
public:
FuelScreen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager);
FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
virtual void Draw() const override;
virtual void Update(float elapsedSecs) override;

View File

@@ -34,12 +34,12 @@ void ScreenManager::CloseScreen() {
}
void ScreenManager::InitializeScreens() {
Point2f fuelScreenSize = Point2f { 492, 396 };
Point2f fuelScreenCenter = Point2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
Fuel = new FuelScreen { "gui/fuel/background.png", fuelScreenCenter, Point2f { 0, 0 }, TextureManager::GetInstance() };
Vector2f fuelScreenSize = Vector2f { 492, 396 };
Vector2f fuelScreenCenter = Vector2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
Fuel = new FuelScreen { "gui/fuel/background.png", fuelScreenCenter, Vector2f { 0, 0 }, TextureManager::GetInstance() };
Point2f sellScreenSize = Point2f { 533, 398 };
Point2f sellScreenCenter = Point2f { utils::GetViewport().x / 2 - sellScreenSize.x / 2, utils::GetViewport().y / 2 - sellScreenSize.y / 2 };
Vector2f sellScreenSize = Vector2f { 533, 398 };
Vector2f sellScreenCenter = Vector2f { utils::GetViewport().x / 2 - sellScreenSize.x / 2, utils::GetViewport().y / 2 - sellScreenSize.y / 2 };
SellScreen = new Screen { "gui/sell/background.png", sellScreenCenter, sellScreenSize, TextureManager::GetInstance() };
//m_Button = Button { "gui/close.png", closeButtonPos, closeButtonSize, TextureManager::GetInstance() };