Skip to content

Commit

Permalink
Merge remote-tracking branch 'group_3/main' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
FergusonAJ committed Dec 11, 2023
2 parents 7281711 + e84fa38 commit 9114750
Show file tree
Hide file tree
Showing 32 changed files with 888 additions and 694 deletions.
72 changes: 40 additions & 32 deletions source/Interfaces/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,64 @@

#include "Button.hpp"

/// Constructor
i_2D::Button::Button(const std::string &t, sf::Vector2f size, sf::Color bgColor,
sf::Color textColor, const sf::Font &font) {
text = std::make_unique<sf::Text>(font);
namespace i_2D {
/**
* Constructs the button
*
* @brief Construct the text with font. Then set text and shape properties with params.
* @param t the string to be displayed by button
* @param size the size of the rectangle shape
* @param bgColor the background color of the shape
* @param textColor the color of the text
* @param font the font style
*/
Button::Button(const std::string &t, sf::Vector2f size, sf::Color bgColor,
sf::Color textColor, const sf::Font &font) {
text = std::make_unique<sf::Text>(font);

text->setString(t);
text->setFillColor(textColor);
text->setString(t);
text->setFillColor(textColor);

button.setSize(size);
button.setFillColor(bgColor);
}
button.setSize(size);
button.setFillColor(bgColor);
}

/**
* @brief set the font of the button
*/
void i_2D::Button::setMFont(const sf::Font &font) {
text = std::make_unique<sf::Text>(font);
}
void Button::SetMFont(const sf::Font &font) {
text = std::make_unique<sf::Text>(font);
}

/**
* @brief set the position of the button
*
* @param pos position on the window
*/
void i_2D::Button::setPosition(sf::Vector2f pos) {
button.setPosition(pos);
float xPos = (pos.x + button.getGlobalBounds().width / 2) - (text->getLocalBounds().width/2);
float yPos = (pos.y + button.getGlobalBounds().height / 2) - (text->getLocalBounds().height/2);
text->setPosition({xPos, yPos});
}
void Button::SetPosition(sf::Vector2f pos) {
button.setPosition(pos);
float xPos = (pos.x + button.getGlobalBounds().width / 2) - (text->getLocalBounds().width / 2);
float yPos = (pos.y + button.getGlobalBounds().height / 2) - (text->getLocalBounds().height / 2);
text->setPosition({xPos, yPos});
}

/**
* @brief checks if mouse position is in a button
*
* @param window
*
* @return returns turn if mouse position is in the button
*/
bool i_2D::Button::isMouseOver(sf::RenderWindow &window) {
float mouseX = sf::Mouse::getPosition(window).x;
float mouseY = sf::Mouse::getPosition(window).y;
bool Button::IsMouseOver(sf::RenderWindow &window) {
float mouseX = sf::Mouse::getPosition(window).x;
float mouseY = sf::Mouse::getPosition(window).y;

float btnPosX = button.getPosition().x;
float btnPosY = button.getPosition().y;
float btnPosX = button.getPosition().x;
float btnPosY = button.getPosition().y;

float btnXPosWidth = button.getPosition().x + button.getLocalBounds().width;
float btnYPosHeight = button.getPosition().y + button.getLocalBounds().height;
float btnXPosWidth = button.getPosition().x + button.getLocalBounds().width;
float btnYPosHeight = button.getPosition().y + button.getLocalBounds().height;

if(mouseX < btnXPosWidth && mouseX > btnPosX && mouseY < btnYPosHeight && mouseY > btnPosY){
return true;
if (mouseX < btnXPosWidth && mouseX > btnPosX && mouseY < btnYPosHeight && mouseY > btnPosY) {
return true;
}
return false;
}
return false;
}
}
36 changes: 18 additions & 18 deletions source/Interfaces/Button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
* Button class creates a SF::Rectangle and SF::Text on top
*/

#ifndef CSE_491_BUTTON_HPP
#define CSE_491_BUTTON_HPP
#pragma once

#include <iostream>
#include <SFML/Graphics.hpp>
#include <memory>

namespace i_2D {
/***
* @class Button
*
* @brief Simple RectangleShape and a Text inside the shape
* Responsive rectangles on the Renderwindow that handles mouse's hover and click events
*/
class Button {
private:
/// The Rectangle that the button resides in
sf::RectangleShape button;
/// The String printed onto the button
std::unique_ptr<sf::Text> text;


Expand All @@ -24,65 +31,58 @@ namespace i_2D {

/**
* @brief set the string of the button
*
* @param s label of the button
*/
void setString(const std::string &s){
void SetString(const std::string &s){
text->setString(s);
}

void setMFont(const sf::Font &font);
void SetMFont(const sf::Font &font);

/**
* @brief set the font of the button
*
* @param font
*/
void setFont(const sf::Font &font) {
void SetFont(const sf::Font &font) {
text->setFont(font);
}

/**
* @brief set the button size
*
* @param size
*/
void setButtonSize(sf::Vector2f size){
void SetButtonSize(sf::Vector2f size){
button.setSize(size);
}

/**
* @brief set the background color of the button
*
* @param color
*/
void setBackColor(sf::Color color){
void SetBackColor(sf::Color color){
button.setFillColor(color);
}

/**
* @brief set the text color of the string
*
* @param color
*/
void setTextColor(sf::Color color){
void SetTextColor(sf::Color color){
text->setFillColor(color);
}

void setPosition(sf::Vector2f pos);
void SetPosition(sf::Vector2f pos);

/**
* @brief draws the button onto the window
*
* @param window
*/
void drawTo(sf::RenderWindow &window){
void DrawTo(sf::RenderWindow &window){
window.draw(button);
window.draw(*text);
}

bool isMouseOver(sf::RenderWindow &window);
bool IsMouseOver(sf::RenderWindow &window);
};
}

#endif //CSE_491_BUTTON_HPP
6 changes: 0 additions & 6 deletions source/Interfaces/Component.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions source/Interfaces/Component.hpp

This file was deleted.

88 changes: 0 additions & 88 deletions source/Interfaces/Container.cpp

This file was deleted.

32 changes: 0 additions & 32 deletions source/Interfaces/Container.hpp

This file was deleted.

Loading

0 comments on commit 9114750

Please sign in to comment.