X-Git-Url: https://www.irasnyder.com/gitweb/?a=blobdiff_plain;f=elevatorgui.cpp;h=f18a33480c5ab6e626873f22cf94d419e31bdb78;hb=eeaaa5863cbb876bd066f704c7ce600c1e363ed7;hp=f9d03a17a49a181e473b546c93b6b79c56089bad;hpb=c08c30e78fdbbde7e5823b26303b0dded3a4c1cf;p=cs356-p1-elevator.git diff --git a/elevatorgui.cpp b/elevatorgui.cpp index f9d03a1..f18a334 100644 --- a/elevatorgui.cpp +++ b/elevatorgui.cpp @@ -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) @@ -13,9 +13,8 @@ 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) /* Storage for GUI elements for later lookup */ @@ -27,11 +26,14 @@ 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) { - std::cout << "at floor: " << f << std::endl; - /* Create and attach the VBox */ Gtk::VBox *box = new Gtk::VBox (); table_.attach (*box, 0, 1, f_attach, f_attach+1); @@ -53,6 +55,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) @@ -71,10 +78,14 @@ 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; epack_start (button_playpause_); - box->pack_start (button_stop_); box->pack_start (button_quit_); /* Attach the box to the bottom of the GUI */ @@ -166,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; @@ -195,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; @@ -202,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 @@ -232,26 +233,24 @@ 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) { CallButtonVector::iterator it; + /* If there is still an elevator coming, don't turn it off! */ + if (ec_.oneElevatorWillStillStopAt (floor, direction)) + return; + for (it=call_buttons_.begin(); it!=call_buttons_.end(); it++) if ((*it)->getFloorNumber() == floor && (*it)->getDirection() == direction) (*it)->set_active (false);