X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=main.cpp;h=a86059c601d3e75874ed541cdeea8543582ba05f;hb=f95be7131a6221491745f0a001f45589aa6acca3;hp=9b2d2e0b6e83cf2c15c6111394c789413db5eed8;hpb=0f2350d5ad9a6bc431bbcce84e8b61a784328bea;p=cs356-p1-elevator.git diff --git a/main.cpp b/main.cpp index 9b2d2e0..a86059c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,24 +1,40 @@ #include "main.hpp" +#include "elevatorgui.hpp" -ElevatorGUI *thegui = NULL; +static ElevatorGUI *thegui = NULL; int main (int argc, char *argv[]) { int floors = 7; int elevators = 3; -#define USE_STATIC_FLOORS 1 + // Start GTK + Gtk::Main app(argc, argv); + +//#define USE_STATIC_FLOORS #ifndef USE_STATIC_FLOORS do { - std::cout << "Enter the number of floors to use [2-10]: "; - std::cin >> floors; + Gtk::Dialog d ("Floor Dialog", true, true); + Gtk::Label l ("Enter the number of floors to use [2-10]"); + Gtk::Entry e; + + d.get_vbox()->pack_start (l); + d.get_vbox()->pack_start (e); + l.show(); + e.show(); + d.add_button ("gtk-ok", Gtk::RESPONSE_OK); + e.set_activates_default (true); + d.set_default_response (Gtk::RESPONSE_OK); + + int result = d.run (); + floors = atoi (e.get_text().c_str()); if (floors < 2 || floors > 10) { - std::cout << "You entered: " << floors - << " which is outside the acceptable range." << std::endl; - std::cout << "Please try again..." << std::endl << std::endl; + Gtk::MessageDialog bad_dialog ("The number of floors entered was not within" + " the acceptable range"); + bad_dialog.run (); } else { @@ -29,14 +45,26 @@ int main (int argc, char *argv[]) do { - std::cout << "Enter the number of elevators to use [1-5]: "; - std::cin >> elevators; + Gtk::Dialog d ("Elevator Dialog", true, true); + Gtk::Label l ("Enter the number of elevators to use [1-5]"); + Gtk::Entry e; + + d.get_vbox()->pack_start (l); + d.get_vbox()->pack_start (e); + l.show(); + e.show(); + d.add_button ("gtk-ok", Gtk::RESPONSE_OK); + e.set_activates_default (true); + d.set_default_response (Gtk::RESPONSE_OK); + + int result = d.run (); + elevators = atoi (e.get_text().c_str()); if (elevators < 1 || elevators > 5) { - std::cout << "You entered: " << elevators - << " which is outside the acceptable range." << std::endl; - std::cout << "Please try again..." << std::endl << std::endl; + Gtk::MessageDialog bad_dialog ("The number of elevators entered was not within" + " the acceptable range"); + bad_dialog.run (); } else { @@ -46,9 +74,6 @@ int main (int argc, char *argv[]) } while (true); #endif - // Start GTK - Gtk::Main app(argc, argv); - // Start the GUI ElevatorGUI eg(floors, elevators); thegui = ⪚ @@ -62,4 +87,30 @@ int main (int argc, char *argv[]) return 0; } + +void gui_update_position_label (int elevator, float new_position, Direction direction) +{ + thegui->gui_update_position_label (elevator, new_position, direction); +} + +void gui_unpress_call_button (int floor, Direction direction) +{ + thegui->gui_unpress_call_button (floor, direction); +} + +void gui_unpress_request_button (int elevator, int floor) +{ + thegui->gui_unpress_request_button (elevator, floor); +} + +void gui_open_door (int elevator, int floor) +{ + thegui->gui_open_door (elevator, floor); +} + +void gui_close_door (int elevator, int floor) +{ + thegui->gui_close_door (elevator, floor); +} + /* vim: set ts=4 sts=4 sw=4 noet tw=112: */