BUGFIX: Elevators did not handle Requests in the correct order
[cs356-p1-elevator.git] / positionlabel.cpp
1 #include "positionlabel.hpp"
2
3 PositionLabel::PositionLabel (int elevator, const std::string text)
4         : Gtk::Table (1, 2)
5         , label_(text)
6         , direction_img_(Gtk::Stock::YES, Gtk::ICON_SIZE_BUTTON)
7         , elevator_(elevator)
8 {
9         attach (label_, 0, 1, 0, 1);
10         attach (direction_img_, 1, 2, 0, 1);
11         show ();
12 }
13
14 int PositionLabel::getElevatorNumber () const
15 {
16         return elevator_;
17 }
18
19 void PositionLabel::update_position (float floor, Direction direction)
20 {
21         switch (direction)
22         {
23                 case UP:
24                         direction_img_.set(Gtk::Stock::GO_UP, Gtk::ICON_SIZE_BUTTON);
25                         break;
26                 case DOWN:
27                         direction_img_.set(Gtk::Stock::GO_DOWN, Gtk::ICON_SIZE_BUTTON);
28                         break;
29                 case IDLE:
30                         direction_img_.set(Gtk::Stock::YES, Gtk::ICON_SIZE_BUTTON);
31                         break;
32                 default:
33                         std::cout << "Bad direction in PositionLabel->update_position(" << floor
34                                           << ", " << direction << ")" << std::endl;
35                         break;
36         }
37
38         std::ostringstream str;
39
40         // Generate the text
41         str << std::setiosflags (std::ios_base::showpoint | std::ios_base::fixed)
42                 << std::setprecision(1) << floor;
43
44         label_.set_text (str.str());
45 }
46
47
48 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */