Skip to content

Commit f9ac94d

Browse files
author
Leviscus Tempris
committed
Resolve button int to float conversion possible loss of data.
1 parent ba609e4 commit f9ac94d

6 files changed

+9
-9
lines changed

src/Button.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ void Button::setPosition(float x, float y) {
7373
text.setPosition(x + button.getSize().x * 0.5f, y + button.getSize().y * 0.5f);
7474
}
7575

76-
void Button::center(float windowWidth, float windowHeight, float yOffset) {
77-
setPosition((windowWidth - getWidth()) * 0.5f, (windowHeight - getHeight()) * 0.5f + yOffset);
76+
void Button::center(sf::RenderWindow& window, float yOffset) {
77+
setPosition((window.getSize().x - getWidth()) * 0.5f, (window.getSize().y - getHeight()) * 0.5f + yOffset);
7878
}

src/Button.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Button : public IButton {
1515
float getWidth() const;
1616
float getHeight() const;
1717
void setPosition(float x, float y) override;
18-
void center(float windowWidth, float windowHeight, float yOffset) override;
18+
void center(sf::RenderWindow& window, float yOffset) override;
1919

2020
private:
2121
sf::RectangleShape button;

src/IButton.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class IButton {
1111
virtual void draw(sf::RenderWindow& window) = 0;
1212
virtual bool isReleased() = 0;
1313
virtual void setPosition(float x, float y) = 0;
14-
virtual void center(float windowWidth, float windowHeight, float yOffset) = 0;
14+
virtual void center(sf::RenderWindow& window, float yOffset) = 0;
1515
};
1616

1717
#endif // IBUTTON_H

src/UI.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ UI::UI(sf::RenderWindow& window, sf::Font& font)
1515

1616
void UI::initializeElements() {
1717
try {
18-
startButton->center(window.getSize().x, window.getSize().y, 25);
19-
startClassicButton->center(window.getSize().x, window.getSize().y, 100);
20-
quitButton->center(window.getSize().x, window.getSize().y, 175);
21-
resumeButton->center(window.getSize().x, window.getSize().y, -50);
22-
mainMenuButton->center(window.getSize().x, window.getSize().y, 125);
18+
startButton->center(window, 25);
19+
startClassicButton->center(window, 100);
20+
quitButton->center(window, 175);
21+
resumeButton->center(window, -50);
22+
mainMenuButton->center(window, 125);
2323
}
2424
catch (const std::exception& e) {
2525
std::cerr << "Failed to initialize UI elements: " << e.what() << std::endl;
30.5 KB
Binary file not shown.
352 KB
Binary file not shown.

0 commit comments

Comments
 (0)