From: Ira W. Snyder Date: Thu, 11 Oct 2007 00:15:13 +0000 (-0700) Subject: GUI-ize the Floor and Elevator entry X-Git-Url: https://www.irasnyder.com/gitweb/?a=commitdiff_plain;h=637a3859106f650f9acfff7209efef3a73a3980a;p=cs356-p1-elevator.git GUI-ize the Floor and Elevator entry Signed-off-by: Ira W. Snyder --- diff --git a/TODO b/TODO deleted file mode 100644 index 5981086..0000000 --- a/TODO +++ /dev/null @@ -1,3 +0,0 @@ -Move the PositionLabels to the top of the screen. - -Make the input of floors and elevators GUI based (dialog boxes) diff --git a/main.cpp b/main.cpp index 5ac3fe9..ab3a1b4 100644 --- a/main.cpp +++ b/main.cpp @@ -8,18 +8,31 @@ 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", 7); + + 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 { @@ -30,14 +43,24 @@ 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", 7); + + 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 { @@ -47,9 +70,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 = ⪚