Skip to content

Commit

Permalink
janitor duty
Browse files Browse the repository at this point in the history
  • Loading branch information
phynxinferno committed Apr 19, 2024
1 parent 22b42a9 commit 142d789
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 54 deletions.
90 changes: 41 additions & 49 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,50 @@ namespace ui {

// These are Useless and solely exist to satisfy linter & compiler warnings
// Please Note that UiElement should only be extended upon, and never used
UiElement::UiElement(void) { position = raylib::Vector2(400, 400); }
void UiElement::Render(void) { raylib::DrawText("ERROR", position.GetX(), position.GetY(), 30, raylib::Color::Red()); }
UiElement::UiElement() { position = raylib::Vector2(400, 400); }
void UiElement::Render() { raylib::DrawText("ERROR", position.GetX(), position.GetY(), 30, raylib::Color::Red()); }

/// @brief Get X value of Element position
/// @return float value of elements X position
float UiElement::X(void) { return position.GetX(); }
/// @brief Get x value of Element position
/// @return float value of elements x position
float UiElement::x() { return position.GetX(); }

/// @brief Get Y value of Element position
/// @return float value of elements Y position
float UiElement::Y(void) { return position.GetY(); }
/// @brief Get y value of Element position
/// @return float value of elements y position
float UiElement::y() { return position.GetY(); }

/// @brief Set X position Value of Element
/// @param X float value of new X position on Screen
void UiElement::X(float X) { position.SetX(X); }
/// @brief Set x position Value of Element
/// @param X float value of new x position on Screen
void UiElement::x(const float X) { position.SetX(X); }

/// @brief Set Y position Value of Element
/// @param Y float value of new Y position on Screen
void UiElement::Y(float Y) { position.SetY(Y); }
/// @brief Set y position Value of Element
/// @param Y float value of new y position on Screen
void UiElement::y(const float Y) { position.SetY(Y); }

// -- TextObject Ui Element -- //
TextObject::TextObject(void) {
TextObject::TextObject() {
position = raylib::Vector2(0, 0);
content = "null";
fontSize = 20;
colour = raylib::Color::Blue();
}

TextObject::TextObject(float X, float Y) {
position = raylib::Vector2(X, Y);
TextObject::TextObject(float x, float y) {
position = raylib::Vector2(x, y);
content = "null";
fontSize = 20;
colour = raylib::Color::White();
}

TextObject::TextObject(float X, float Y, std::string Content) {
position = raylib::Vector2(X, Y);
content = Content;
TextObject::TextObject(float x, float y, std::string Content) {
position = raylib::Vector2(x, y);
content = std::move(Content);
fontSize = 20;
colour = raylib::Color::Blue();
}

TextObject::TextObject(float X, float Y, std::string Content, raylib::Color Colour) {
position = raylib::Vector2(X, Y);
content = Content;
TextObject::TextObject(float X, float y, std::string Content, raylib::Color Colour) {
position = raylib::Vector2(X, y);
content = std::move(Content);
fontSize = 20;
colour = Colour;
}
Expand Down Expand Up @@ -81,39 +81,39 @@ namespace ui {

/// @brief Set string Content of textObject
/// @param Content c++ string value of new textObject content
void TextObject::Content(std::string Content) { content = Content; }
void TextObject::Content(std::string Content) { content = std::move(Content); }

// -- Button Ui Element -- //

/// @brief Default constructor. Leaves fields "empty"
Button::Button() = default;

/// @brief Constructor for Button Ui element. Initialises all fields aside from box height and width
/// @param X X coordinate for the button
/// @param Y Y coordinate for the button
/// @param x x coordinate for the button
/// @param y y coordinate for the button
/// @param Content Text on Button
/// @param Background Background Colour
/// @param Foreground Text and Outline Colour
Button::Button(float X, float Y, std::string Content, raylib::Color Background, raylib::Color Foreground) {
position = raylib::Vector2(X, Y);
Button::Button(float x, float y, std::string Content, raylib::Color Background, raylib::Color Foreground) {
position = raylib::Vector2(x, y);
box = raylib::Rectangle(position, raylib::Vector2(80, 40));
content = std::move(Content);
background = Background;
foreground = Foreground;
}

/// @brief Constructor for Button Ui element. Initialises all fields aside from box height and width
/// @param X X coordinate for the button
/// @param Y Y coordinate for the button
/// @param x x coordinate for the button
/// @param y y coordinate for the button
/// @param Height Box height of button
/// @param Width Box width of button
/// @param Content Text on Button
/// @param Background Background Colour
/// @param Foreground Text and Outline Colour
Button::Button(float X, float Y, float Height, float Width, std::string Content, raylib::Color Background, raylib::Color Foreground) {
position = raylib::Vector2(X, Y);
Button::Button(float x, float y, float Height, float Width, std::string Content, raylib::Color Background, raylib::Color Foreground) {
position = raylib::Vector2(x, y);
box = raylib::Rectangle(position, raylib::Vector2(Width, Height));
content = Content;
content = std::move(Content);
background = Background;
foreground = Foreground;
}
Expand All @@ -125,40 +125,32 @@ namespace ui {

/// @brief Checks if the button has been pressed
/// @return Returns true if mouse down inside of button area, else return false
bool Button::IsPressed(void) {
bool Button::IsPressed() {
// Check that mouse left button is down
if (raylib::Mouse::IsButtonDown(MOUSE_BUTTON_LEFT)) {
// Check if mouse pointer position is within bounds of Button box.
if (raylib::Mouse::GetPosition().GetX() >= position.GetX() && raylib::Mouse::GetPosition().GetX() <= position.GetX() + box.GetWidth()) {
if (raylib::Mouse::GetPosition().GetY() >= position.GetY() && raylib::Mouse::GetPosition().GetY() <= position.GetY() + box.GetHeight()) {
return true;
}
}
}
return false;
return ((raylib::Mouse::IsButtonDown(MOUSE_BUTTON_LEFT)) && (raylib::Mouse::GetPosition().GetX() >= position.GetX() && raylib::Mouse::GetPosition().GetX() <= position.GetX() + box.GetWidth()) && (raylib::Mouse::GetPosition().GetY() >= position.GetY() && raylib::Mouse::GetPosition().GetY() <= position.GetY() + box.GetHeight()));
}

/// @brief Renders Button to screen.
/// Updates Box position, then draws Button box and Button Content to current position
void Button::Render(void) {
void Button::Render() {
box.SetPosition(position);
box.Draw(background);
raylib::DrawText(content.c_str(), position.GetX() + 10, position.GetY() + 10, 25, foreground);
raylib::DrawText(content, position.GetX() + 10, position.GetY() + 10, 25, foreground);
}

// -- Button Getters -- //

/// @brief Get Length of button box
/// @return float value of buttons Length
float Button::Length(void) { return box.GetHeight(); }
float Button::Length() { return box.GetHeight(); }

/// @brief Get Width of button box
/// @return float value of buttons Width
float Button::Width(void) { return box.GetWidth(); }
float Button::Width() { return box.GetWidth(); }

/// @brief Get String Content of button
/// @return c++ string value of buttons content
std::string Button::Content(void) { return content; }
std::string Button::Content() { return content; }

// -- Button Setters -- //

Expand All @@ -172,6 +164,6 @@ namespace ui {

/// @brief Set string Content of Button
/// @param Content c++ string value of new Button content
void Button::Content(std::string Content) { content = Content; }
void Button::Content(std::string Content) { content = std::move(Content); }

}
10 changes: 5 additions & 5 deletions src/ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ namespace ui {
UiElement();
virtual void Render(void);
// -- Setters -- //
void X(float);
void Y(float);
void x(float);
void y(float);
// -- Getters -- //
float X(void);
float Y(void);
float x(void);
float y(void);
};

/// @brief A simple way to display text on screen
class TextObject : public UiElement {
private:
std::string content;
raylib::Color colour;
int fontSize;
unsigned int fontSize;

public:
// -- Constructors -- //
Expand Down

0 comments on commit 142d789

Please sign in to comment.