Get the Play/Pause and Quit buttons working nicely
authorIra W. Snyder <devel@irasnyder.com>
Tue, 9 Oct 2007 21:15:04 +0000 (14:15 -0700)
committerIra W. Snyder <devel@irasnyder.com>
Tue, 9 Oct 2007 21:15:04 +0000 (14:15 -0700)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
TODO
elevatorgui.cpp
elevatorgui.hpp

diff --git a/TODO b/TODO
index d7cfff2..5981086 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,3 @@
 Move the PositionLabels to the top of the screen.
 
 Make the input of floors and elevators GUI based (dialog boxes)
-
-Four buttons: Start, Pause, Resume, Quit
index 51c14cb..8e7ae2a 100644 (file)
@@ -4,7 +4,7 @@ ElevatorGUI::ElevatorGUI (int floors, int elevators)
        : Gtk::Window()
        , number_of_floors_(floors)
        , number_of_elevators_(elevators)
-       , simulation_status_(STOPPED)
+       , simulation_status_(PAUSED)
 
        /* The ElevatorController */
        , ec_(floors, elevators)
@@ -15,7 +15,6 @@ ElevatorGUI::ElevatorGUI (int floors, int elevators)
        /* GUI Elements */
        , table_(floors+3, elevators+1)
        , button_playpause_(Gtk::Stock::MEDIA_PLAY)
-       , button_stop_(Gtk::Stock::STOP)
        , button_quit_(Gtk::Stock::QUIT)
 
        /* Storage for GUI elements for later lookup */
@@ -149,15 +148,16 @@ ElevatorGUI::ElevatorGUI (int floors, int elevators)
        /* Fill in the control buttons */
        Gtk::HBox *box = new Gtk::HBox ();
 
+       /* Tell the Play/Pause button to use the StockID so we can change it's image */
+       button_playpause_.set_use_stock (true);
+
+       /* Signals for control buttons */
        button_quit_.signal_clicked().connect (
                        sigc::mem_fun (*this, &ElevatorGUI::on_quit_button_clicked));
-       button_stop_.signal_clicked().connect (
-                       sigc::mem_fun (*this, &ElevatorGUI::on_stop_button_clicked));
        button_playpause_.signal_clicked().connect (
                        sigc::mem_fun (*this, &ElevatorGUI::on_playpause_button_clicked));
 
        box->pack_start (button_playpause_);
-       box->pack_start (button_stop_);
        box->pack_start (button_quit_);
 
        /* Attach the box to the bottom of the GUI */
@@ -178,26 +178,20 @@ void ElevatorGUI::on_quit_button_clicked ()
 
 void ElevatorGUI::on_playpause_button_clicked ()
 {
-       std::string names[] = { "STOPPED", "RUNNING", "PAUSED" };
+       std::string names[] = { "RUNNING", "PAUSED" };
        std::cout << "Play/Pause pressed with status=" << names[simulation_status_] << std::endl;
 
        switch (simulation_status_)
        {
-               case STOPPED:
-                       simulation_status_ = RUNNING;
-
-                       // add and start timer
-                       timer_ = Glib::signal_timeout().connect (
-                                               sigc::mem_fun (*this, &ElevatorGUI::on_timer_tick),
-                                               timer_tick_ms_);
-
-                       break;
                case RUNNING:
                        simulation_status_= PAUSED;
 
                        // stop and remove timer
                        timer_.disconnect ();
 
+                       // Set the StockID of the button
+                       button_playpause_.set_label ("gtk-media-play");
+
                        break;
                case PAUSED:
                        simulation_status_ = RUNNING;
@@ -207,6 +201,9 @@ void ElevatorGUI::on_playpause_button_clicked ()
                                                sigc::mem_fun (*this, &ElevatorGUI::on_timer_tick),
                                                timer_tick_ms_);
 
+                       // Set the StockID of the button
+                       button_playpause_.set_label ("gtk-media-pause");
+
                        break;
                default:
                        std::cout << "Bad Simulation Status in Play/Pause" << std::endl;
@@ -214,14 +211,6 @@ void ElevatorGUI::on_playpause_button_clicked ()
        }
 }
 
-void ElevatorGUI::on_stop_button_clicked ()
-{
-       // FIXME: implement this
-       std::cout << "STOP Button Clicked" << std::endl;
-
-       simulation_status_ = STOPPED;
-}
-
 void ElevatorGUI::on_request_button_toggled (RequestButton *button)
 {
        // Only send an elevator if we are toggled to on
index 3a4b1f3..6dd2206 100644 (file)
@@ -38,7 +38,6 @@ class ElevatorGUI : public Gtk::Window
                void on_call_button_toggled (CallButton *button);
                void on_request_button_toggled (RequestButton *button);
                void on_playpause_button_clicked ();
-               void on_stop_button_clicked ();
                void on_quit_button_clicked ();
 
                /* Timer Function */
@@ -49,7 +48,7 @@ class ElevatorGUI : public Gtk::Window
                int number_of_floors_;
                int number_of_elevators_;
 
-               enum { STOPPED, RUNNING, PAUSED } simulation_status_;
+               enum { RUNNING, PAUSED } simulation_status_;
                
                ElevatorController ec_;
 
@@ -65,8 +64,8 @@ class ElevatorGUI : public Gtk::Window
                // holds custom ElevatorDoor which knows it's elevator# and floor#
                ElevatorDoorVector elevator_doors_;
 
-               // Holds the Play / Pause button, Stop button, and Quit button
-               Gtk::Button button_playpause_, button_stop_, button_quit_;
+               // Holds the Play / Pause button and Quit button
+               Gtk::Button button_playpause_, button_quit_;
 
                // Holds the Table which holds everything
                Gtk::Table table_;