Fix ElevatorGUI's Gtk::Table
[cs356-p1-elevator.git] / elevatorgui.cpp
index 630a855..51c14cb 100644 (file)
@@ -13,7 +13,7 @@ ElevatorGUI::ElevatorGUI (int floors, int elevators)
        , timer_()
 
        /* GUI Elements */
-       , table_(floors+1, elevators+3)
+       , table_(floors+3, elevators+1)
        , button_playpause_(Gtk::Stock::MEDIA_PLAY)
        , button_stop_(Gtk::Stock::STOP)
        , button_quit_(Gtk::Stock::QUIT)
@@ -27,6 +27,11 @@ ElevatorGUI::ElevatorGUI (int floors, int elevators)
        int i, j, e, f, e_num, f_num, f_attach;
        std::ostringstream str;
 
+       /* Set Table Spacing / Window Border Size */
+       table_.set_col_spacings (8);
+       table_.set_row_spacings (8);
+       set_border_width (10);
+
        /* Fill in all of the ElevatorDoors and CallButtons */
        for (f_attach=0, f=floors-1; f>=0; --f, ++f_attach)
        {
@@ -51,6 +56,11 @@ ElevatorGUI::ElevatorGUI (int floors, int elevators)
                        call_buttons_.push_back (callbutton);
                        box->pack_start (*callbutton);
                }
+               else // we are on the top floor, create a dummy label
+               {
+                       Gtk::Label *label = new Gtk::Label ("");
+                       box->pack_start (*label);
+               }
 
                /* Only create the DOWN CallButton if we are not on the bottom floor */
                if (f != 0)
@@ -69,6 +79,11 @@ ElevatorGUI::ElevatorGUI (int floors, int elevators)
                        call_buttons_.push_back (callbutton);
                        box->pack_end (*callbutton);
                }
+               else // we are on the bottom floor, create a dummy label
+               {
+                       Gtk::Label *label = new Gtk::Label ("");
+                       box->pack_end (*label);
+               }
 
                for (e=0; e<elevators; ++e) // run left-to-right
                {
@@ -229,20 +244,14 @@ void ElevatorGUI::on_call_button_toggled (CallButton *button)
        }
 }
 
-void ElevatorGUI::gui_update_position_label (int elevator, float new_position)
+void ElevatorGUI::gui_update_position_label (int elevator, float new_position, Direction direction)
 {
-       std::ostringstream str;
-
-       // Generate the text
-       str << std::setiosflags (std::ios_base::showpoint | std::ios_base::fixed)
-               << std::setprecision(1) << new_position;
-
        // Find the correct label and set it
        PositionLabelVector::iterator it;
 
        for (it=position_labels_.begin(); it!=position_labels_.end(); it++)
                if ((*it)->getElevatorNumber() == elevator)
-                       (*it)->set_text (str.str());
+                       (*it)->update_position (new_position, direction);
 }
 
 void ElevatorGUI::gui_unpress_call_button (int floor, Direction direction)