-Make PositionLabels inherit from Gtk::Table and have them display an arrow
-with their direction, as well as just an integer version of their position.
-
Move the PositionLabels to the top of the screen.
Make the input of floors and elevators GUI based (dialog boxes)
position_ += ELEVATOR_STEP;
// TODO: Call into the GUI to update the position
- gui_update_position_label (number_, (float)position_);
+ gui_update_position_label (number_, (float)position_, direction_);
std::cout << "Updating the GUI with our position: " << position_ << std::endl;
}
position_ -= ELEVATOR_STEP;
// TODO: Call into the GUI to update the position
- gui_update_position_label (number_, (float)position_);
+ gui_update_position_label (number_, (float)position_, direction_);
std::cout << "Updating the GUI with our position: " << position_ << std::endl;
}
void Elevator::transition_move_idle ()
{
direction_ = IDLE;
+ // TODO: Call into the GUI to update the position
+ gui_update_position_label (number_, (float)position_, direction_);
// do not change position while IDLE
}
}
}
-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)
ElevatorGUI (int floors, int elevators);
/* Functions to be called from Elevator to change GUI status */
- void gui_update_position_label (int elevator, float new_position);
+ void gui_update_position_label (int elevator, float new_position, Direction direction);
void gui_unpress_call_button (int floor, Direction direction);
void gui_unpress_request_button (int elevator, int floor);
void gui_open_door (int elevator, int floor);
int floors = 7;
int elevators = 3;
-#define USE_STATIC_FLOORS 1
+//#define USE_STATIC_FLOORS 1
#ifndef USE_STATIC_FLOORS
do
{
}
-void gui_update_position_label (int elevator, float new_position)
+void gui_update_position_label (int elevator, float new_position, Direction direction)
{
- thegui->gui_update_position_label (elevator, new_position);
+ thegui->gui_update_position_label (elevator, new_position, direction);
}
void gui_unpress_call_button (int floor, Direction direction)
#include <iostream>
#include <gtkmm/main.h>
-void gui_update_position_label (int elevator, float new_position);
+void gui_update_position_label (int elevator, float new_position, Direction direction);
void gui_unpress_call_button (int floor, Direction direction);
void gui_unpress_request_button (int elevator, int floor);
void gui_open_door (int elevator, int floor);
#include "positionlabel.hpp"
PositionLabel::PositionLabel (int elevator, const std::string text)
- : Gtk::Label (text)
+ : Gtk::Table (1, 2)
+ , label_(text)
+ , direction_img_(Gtk::Stock::YES, Gtk::ICON_SIZE_BUTTON)
, elevator_(elevator)
{
- // Intentionally Left Empty
+ attach (label_, 0, 1, 0, 1);
+ attach (direction_img_, 1, 2, 0, 1);
+ show ();
}
int PositionLabel::getElevatorNumber () const
return elevator_;
}
+void PositionLabel::update_position (float floor, Direction direction)
+{
+ switch (direction)
+ {
+ case UP:
+ direction_img_.set(Gtk::Stock::GO_UP, Gtk::ICON_SIZE_BUTTON);
+ break;
+ case DOWN:
+ direction_img_.set(Gtk::Stock::GO_DOWN, Gtk::ICON_SIZE_BUTTON);
+ break;
+ case IDLE:
+ direction_img_.set(Gtk::Stock::YES, Gtk::ICON_SIZE_BUTTON);
+ break;
+ default:
+ std::cout << "Bad direction in PositionLabel->update_position(" << floor
+ << ", " << direction << ")" << std::endl;
+ break;
+ }
+
+ std::ostringstream str;
+
+ // Generate the text
+ str << std::setiosflags (std::ios_base::showpoint | std::ios_base::fixed)
+ << std::setprecision(1) << floor;
+
+ label_.set_text (str.str());
+}
+
+
/* vim: set ts=4 sts=4 sw=4 noet tw=112: */
#ifndef POSITIONLABEL_HPP
#define POSITIONLABEL_HPP
+#include "direction.hpp"
#include <gtkmm.h>
#include <string>
+#include <sstream>
+#include <iostream>
+#include <iomanip>
-class PositionLabel : public Gtk::Label
+class PositionLabel : public Gtk::Table
{
public:
PositionLabel (int elevator, const std::string text="0.0");
int getElevatorNumber() const;
+ void update_position (float floor, Direction direction);
private:
+ Gtk::Label label_;
+ Gtk::Image direction_img_;
int elevator_;
};