gui: Store pointers to play and pause buttons

We use these every half-second, so let's not waste time looking them up
every call.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-09-11 08:28:01 -04:00
parent a2987c2952
commit bc5e53a423
1 changed files with 12 additions and 11 deletions

View File

@ -7,6 +7,8 @@
#include <gui/ocarina.h>
static Gtk::Label *o_position;
static Gtk::Button *o_play_button;
static Gtk::Button *o_pause_button;
static Glib::RefPtr<Gtk::Adjustment> o_pos_bar;
static inline bool audio_playing()
@ -14,19 +16,15 @@ static inline bool audio_playing()
return driver :: get_driver()->is_playing();
}
static void hide_show_buttons(const std::string &hide, const std::string &show)
{
lib :: get_widget<Gtk::Button>(hide)->hide();
lib :: get_widget<Gtk::Button>(show)->show();
}
void o_fix_buttons()
{
if (audio_playing())
hide_show_buttons("o_play", "o_pause");
else
hide_show_buttons("o_pause", "o_play");
if (audio_playing()) {
o_play_button->hide();
o_pause_button->show();
} else {
o_play_button->show();
o_pause_button->hide();
}
}
/*
@ -84,6 +82,9 @@ void controls_init()
o_position = lib :: get_widget<Gtk::Label>("o_cur_position");
o_pos_bar = lib :: get_object<Gtk::Adjustment>("o_progress");
o_play_button = lib :: get_widget<Gtk::Button>("o_play");
o_pause_button = lib :: get_widget<Gtk::Button>("o_pause");
pos_scale->signal_change_value().connect(sigc::ptr_fun(o_seek));
connect_button("o_play", o_play);
connect_button("o_pause", o_pause);