I now have a start/stop button for the pomodoro timer.

master
Zed A. Shaw 2 weeks ago
parent e1c667d816
commit 47c9cb719e
  1. 0
      assets/build_success.mp3
  2. BIN
      assets/start_button.png
  3. BIN
      assets/stop_button.png
  4. 20
      sfmlbackend.cpp
  5. 4
      sfmlbackend.hpp

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

@ -79,7 +79,10 @@ void SFMLBackend::handle_events() {
case sf::Event::MouseButtonPressed: { case sf::Event::MouseButtonPressed: {
// rect::contains(x,y) for if mouse is in the button rect // rect::contains(x,y) for if mouse is in the button rect
sf::Event::MouseButtonEvent btn = event.mouseButton; sf::Event::MouseButtonEvent btn = event.mouseButton;
fmt::println("BUTTON: X={}, Y={}", btn.x, btn.y); bool stop_clicked = stop_button.getGlobalBounds().contains(btn.x, btn.y);
bool start_clicked = start_button.getGlobalBounds().contains(btn.x, btn.y);
fmt::println("BUTTON: start={}, stop={}", start_clicked, stop_clicked);
break; break;
} }
default: default:
@ -149,11 +152,10 @@ void SFMLBackend::update_entities() {
string time = fmt::format("{:%r}", now); string time = fmt::format("{:%r}", now);
write_text(2, 14, time, 2.0f); write_text(2, 14, time, 2.0f);
sf::RectangleShape start_btn = box(27, 16, 8, 3, Value::DARK_MID); stop_button.setPosition(translate(27, 15));
write_text(29, 16, "START", 1.0f); window.draw(start_button);
start_button.setPosition(translate(37, 15));
sf::RectangleShape done_btn = box(37, 16, 8, 3, Value::DARK_MID); window.draw(stop_button);
write_text(39, 16, "DONE", 1.0f);
Window_update(); Window_update();
} }
@ -171,6 +173,12 @@ void SFMLBackend::change_face(const string name) {
SFMLBackend::SFMLBackend(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g) SFMLBackend::SFMLBackend(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g)
{ {
change_face("building"); change_face("building");
stop_texture.loadFromFile("./assets/stop_button.png");
stop_button.setTexture(stop_texture);
start_texture.loadFromFile("./assets/start_button.png");
start_button.setTexture(start_texture);
} }

@ -47,6 +47,10 @@ class SFMLBackend {
sf::RenderWindow window; sf::RenderWindow window;
sf::Sprite face_sprite; sf::Sprite face_sprite;
sf::Texture face_texture; sf::Texture face_texture;
sf::Sprite stop_button;
sf::Texture stop_texture;
sf::Sprite start_button;
sf::Texture start_texture;
int hit_points = 50; int hit_points = 50;
sf::Font font; sf::Font font;
GameEngine &game; GameEngine &game;

Loading…
Cancel
Save