@ -79,10 +79,11 @@ 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 ;
bool stop_clicked = stop_button . getGlobalBounds ( ) . contains ( btn . x , btn . y ) ;
if ( stop_button . getGlobalBounds ( ) . contains ( btn . x , btn . y ) ) {
bool start_clicked = start_button . getGlobalBounds ( ) . contains ( btn . x , btn . y ) ;
buttons = Button : : STOP ;
} else if ( start_button . getGlobalBounds ( ) . contains ( btn . x , btn . y ) ) {
fmt : : println ( " BUTTON: start={}, stop={} " , start_clicked , stop_clicked ) ;
buttons = Button : : START ;
}
break ;
break ;
}
}
default :
default :
@ -148,9 +149,17 @@ void SFMLBackend::update_entities() {
game . streak , game . deaths ) ;
game . streak , game . deaths ) ;
write_text ( X_ROWS / 4 + 5 , 2 , status ) ;
write_text ( X_ROWS / 4 + 5 , 2 , status ) ;
std : : chrono : : time_point < std : : chrono : : system_clock > now = std : : chrono : : system_clock : : now ( ) ;
if ( buttons = = Button : : START ) {
string time = fmt : : format ( " {:%r} " , now ) ;
// better thing here please
write_text ( 2 , 14 , time , 2.0f ) ;
} else if ( buttons = = Button : : STOP ) {
clock_start = std : : chrono : : system_clock : : now ( ) ;
}
auto elapsed_time = std : : chrono : : system_clock : : now ( ) - clock_start ;
string time = format ( " {:%H:%M:%OS} " , elapsed_time ) ;
write_text ( 7 , 14 , time , 2.0f ) ;
stop_button . setPosition ( translate ( 27 , 15 ) ) ;
stop_button . setPosition ( translate ( 27 , 15 ) ) ;
window . draw ( start_button ) ;
window . draw ( start_button ) ;