From 78624a6d9896604433bcaf820ab141fbf0b59304 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 9 Sep 2014 08:27:41 -0400 Subject: [PATCH] gui: Fix up how the gui pauses I make it look more like o_play(). Signed-off-by: Anna Schumaker --- gui/controls.cpp | 37 ++++++++++++++++++++++++++++++------- gui/gui.cpp | 20 ++++---------------- include/gui/controls.h | 4 ++++ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/gui/controls.cpp b/gui/controls.cpp index ef72d5fd..a6d15a95 100644 --- a/gui/controls.cpp +++ b/gui/controls.cpp @@ -12,6 +12,20 @@ static inline bool audio_playing() } +static void hide_show_buttons(const std::string &hide, const std::string &show) +{ + lib :: get_widget(hide)->hide(); + lib :: get_widget(show)->show(); +} + +void o_fix_buttons() +{ + if (audio_playing()) + hide_show_buttons("o_play", "o_pause"); + else + hide_show_buttons("o_pause", "o_play"); +} + /* * Timeout function is called every half-second. */ @@ -24,6 +38,7 @@ static bool on_timeout() bar->set_upper(audio :: duration()); bar->set_value(audio :: position()); + o_fix_buttons(); return audio_playing(); } @@ -33,15 +48,23 @@ static void enable_timeout() } -static void hide_show_buttons(const std::string &hide, const std::string &show) -{ - lib :: get_widget(hide)->hide(); - lib :: get_widget(show)->show(); -} - void o_play() { audio :: play(); - hide_show_buttons("o_play", "o_pause"); + o_fix_buttons(); enable_timeout(); } + +void o_pause() +{ + audio :: pause(); + o_fix_buttons(); +} + +void o_toggle() +{ + if (audio_playing()) + o_pause(); + else + o_play(); +} diff --git a/gui/gui.cpp b/gui/gui.cpp index e3e8d4d1..415ead0d 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -15,7 +15,6 @@ #include #include -static bool audio_playing = false; static sigc::connection fav_connection; static sigc::connection ban_connection; @@ -32,13 +31,6 @@ static void on_config_pause() audio :: pause_after(enabled->get_active(), count->get_value()); } -static void on_pause() -{ - lib :: get_widget("o_play")->show(); - lib :: get_widget("o_pause")->hide(); - audio_playing = false; -} - static void on_next() { audio :: next(); @@ -162,12 +154,9 @@ static bool on_window_key_released(GdkEventKey *event) { std::string key = gdk_keyval_name(event->keyval); - if (key == "space") { - if (driver :: get_driver()->is_playing()) - audio :: pause(); - else - o_play(); - } else + if (key == "space") + o_toggle(); + else return false; return true; } @@ -217,12 +206,11 @@ Gtk::Window *setup_gui() Gtk::CheckButton *enabled = lib :: get_widget("o_pause_enabled"); Gtk::Scale *position = lib :: get_widget("o_position_scale"); - cb->on_pause = on_pause; cb->on_track_loaded = on_track_loaded; cb->on_pause_count_changed = on_pause_count_changed; connect_button("o_play", o_play); - connect_button("o_pause", audio::pause); + connect_button("o_pause", o_pause); connect_button("o_stop", audio::stop); connect_button("o_prev", audio::prev); connect_button("o_next", on_next); diff --git a/include/gui/controls.h b/include/gui/controls.h index 1565f679..83d7f9b3 100644 --- a/include/gui/controls.h +++ b/include/gui/controls.h @@ -4,6 +4,10 @@ #ifndef OCARINA_GUI_CONTROLS_H #define OCARINA_GUI_CONTROLS_H +void o_fix_buttons(); + void o_play(); +void o_pause(); +void o_toggle(); #endif /* OCARINA_GUI_CONTROLS_H */