Skip to content

Commit

Permalink
Use SFML 2.6.1 instead of latest dev changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDoom committed Mar 27, 2024
1 parent 12e1b77 commit 0954e11
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion dependencies/sfml
Submodule sfml updated 711 files
124 changes: 62 additions & 62 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,68 @@
#include "Renderer.h"
#include "Speaker.h"
#include "fstream"
//
//
// class TextButton {
// private:
// sf::RectangleShape button;
// sf::Text text;
// sf::Font font;
// sf::Color idleColor;
// sf::Color hoverColor;
// sf::Color activeColor;
// bool isPressed;
// bool isHovered;
//
// public:
// TextButton(float x, float y, float width, float height, std::string buttonText) {
// button.setSize(sf::Vector2f(width, height));
// button.setPosition(sf::Vector2f(x, y));
//
// font.loadFromFile("../assets/font.ttf"); // Load your font here
// text.setFont(font);
// text.setString(buttonText);
// text.setCharacterSize(24); // Set your text size
// text.setFillColor(sf::Color::Black);
// text.setPosition(x + width / 4, y + height / 4); // Adjust text position
//
// idleColor = sf::Color(192, 192, 192); // Grey
// hoverColor = sf::Color(128, 128, 128); // Dark Grey
// activeColor = sf::Color(64, 64, 64); // Darker Grey
//
// button.setFillColor(idleColor);
//
// isPressed = false;
// isHovered = false;
// }
//
// void updateSize(float width, float height) {
// button.setSize(sf::Vector2f(width, height));
// }
//
// void update(sf::RenderWindow& window) {
// isHovered = button.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);
//
// if (isHovered && sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
// isPressed = true;
// button.setFillColor(activeColor);
// } else if (isHovered) {
// button.setFillColor(hoverColor);
// } else {
// isPressed = false;
// button.setFillColor(idleColor);
// }
// }
//
// void draw(sf::RenderWindow& window) {
// window.draw(button);
// window.draw(text);
// }
//
// bool isClicked() {
// return isPressed;
// }
// };


class TextButton {
private:
sf::RectangleShape button;
sf::Text text;
sf::Font font;
sf::Color idleColor;
sf::Color hoverColor;
sf::Color activeColor;
bool isPressed;
bool isHovered;

public:
TextButton(float x, float y, float width, float height, std::string buttonText) {
button.setSize(sf::Vector2f(width, height));
button.setPosition(sf::Vector2f(x, y));

font.loadFromFile("../assets/font.ttf"); // Load your font here
text.setFont(font);
text.setString(buttonText);
text.setCharacterSize(24); // Set your text size
text.setFillColor(sf::Color::Black);
text.setPosition(x + width / 4, y + height / 4); // Adjust text position

idleColor = sf::Color(192, 192, 192); // Grey
hoverColor = sf::Color(128, 128, 128); // Dark Grey
activeColor = sf::Color(64, 64, 64); // Darker Grey

button.setFillColor(idleColor);

isPressed = false;
isHovered = false;
}

void updateSize(float width, float height) {
button.setSize(sf::Vector2f(width, height));
}

void update(sf::RenderWindow& window) {
isHovered = button.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);

if (isHovered && sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
isPressed = true;
button.setFillColor(activeColor);
} else if (isHovered) {
button.setFillColor(hoverColor);
} else {
isPressed = false;
button.setFillColor(idleColor);
}
}

void draw(sf::RenderWindow& window) {
window.draw(button);
window.draw(text);
}

bool isClicked() {
return isPressed;
}
};

int main(int argc, char** argv)
{
Expand Down

0 comments on commit 0954e11

Please sign in to comment.