GUI-ize the Floor and Elevator entry
[cs356-p1-elevator.git] / main.cpp
1 #include "main.hpp"
2 #include "elevatorgui.hpp"
3
4 static ElevatorGUI *thegui = NULL;
5
6 int main (int argc, char *argv[])
7 {
8         int floors = 7;
9         int elevators = 3;
10
11         // Start GTK
12         Gtk::Main app(argc, argv);
13
14 //#define USE_STATIC_FLOORS
15 #ifndef USE_STATIC_FLOORS
16         do
17         {
18                 Gtk::Dialog d ("Floor Dialog", true, true);
19                 Gtk::Label  l ("Enter the number of floors to use [2-10]");
20                 Gtk::Entry  e;
21
22                 d.get_vbox()->pack_start (l);
23                 d.get_vbox()->pack_start (e);
24                 l.show();
25                 e.show();
26                 d.add_button ("gtk-ok", 7);
27
28                 int result = d.run ();
29                 floors = atoi (e.get_text().c_str());
30
31                 if (floors < 2 || floors > 10)
32                 {
33                         Gtk::MessageDialog bad_dialog ("The number of floors entered was not within"
34                                                                " the acceptable range");
35                         bad_dialog.run ();
36                 }
37                 else
38                 {
39                         // Good input, leave now
40                         break;
41                 }
42         } while (true);
43
44         do
45         {
46                 Gtk::Dialog d ("Elevator Dialog", true, true);
47                 Gtk::Label  l ("Enter the number of elevators to use [1-5]");
48                 Gtk::Entry  e;
49
50                 d.get_vbox()->pack_start (l);
51                 d.get_vbox()->pack_start (e);
52                 l.show();
53                 e.show();
54                 d.add_button ("gtk-ok", 7);
55
56                 int result = d.run ();
57                 elevators = atoi (e.get_text().c_str());
58
59                 if (elevators < 1 || elevators > 5)
60                 {
61                         Gtk::MessageDialog bad_dialog ("The number of elevators entered was not within"
62                                                                " the acceptable range");
63                         bad_dialog.run ();
64                 }
65                 else
66                 {
67                         // Good input, leave now
68                         break;
69                 }
70         } while (true);
71 #endif
72
73         // Start the GUI
74         ElevatorGUI eg(floors, elevators);
75         thegui = &eg;
76
77         // Show the GUI
78         eg.show ();
79
80         // Run it!
81         Gtk::Main::run (eg);
82
83         return 0;
84 }
85
86
87 void gui_update_position_label (int elevator, float new_position, Direction direction)
88 {
89         thegui->gui_update_position_label (elevator, new_position, direction);
90 }
91
92 void gui_unpress_call_button (int floor, Direction direction)
93 {
94         thegui->gui_unpress_call_button (floor, direction);
95 }
96
97 void gui_unpress_request_button (int elevator, int floor)
98 {
99         thegui->gui_unpress_request_button (elevator, floor);
100 }
101
102 void gui_open_door (int elevator, int floor)
103 {
104         thegui->gui_open_door (elevator, floor);
105 }
106
107 void gui_close_door (int elevator, int floor)
108 {
109         thegui->gui_close_door (elevator, floor);
110 }
111
112 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */