From 1fe3c4ddf74137590f5d58665fba3732e59be2ab Mon Sep 17 00:00:00 2001 From: tchernobog Date: Sun, 20 Aug 2006 19:20:05 +0000 Subject: [PATCH] git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@916 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/schedulable_state_widget.cc | 95 +++++++++++++++++++++++++++++++++ src/schedulable_state_widget.hh | 58 ++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/schedulable_state_widget.cc create mode 100644 src/schedulable_state_widget.hh diff --git a/src/schedulable_state_widget.cc b/src/schedulable_state_widget.cc new file mode 100644 index 0000000..7daf8ca --- /dev/null +++ b/src/schedulable_state_widget.cc @@ -0,0 +1,95 @@ +// src/schedulable_state_widget.cc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#include "schedulable_state_widget.hh" + +using namespace sgpem; + + +Gtk::Tooltips +SchedulableStateWidget::_ttips; + + +SchedulableStateWidget::SchedulableStateWidget(Schedulable::state st) + : _color(1, 1, 1) +{ + set_scaling_mode(scaling_to_w); + set_state(st); +} + + +void +SchedulableStateWidget::set_state(Schedulable::state new_state) +{ + switch(new_state) + { + case Schedulable::state_future: + _color = Color(1, 1, 1); // White + _ttips.set_tip(*this, "Future"); + break; + case Schedulable::state_ready: + _color = Color(1, 1, 0); // Yellow + _ttips.set_tip(*this, "Ready"); + break; + case Schedulable::state_running: + _color = Color(0, 1, 0); // Green + _ttips.set_tip(*this, "Running"); + break; + case Schedulable::state_blocked: + _color = Color(0, 0, 1); // Blue + _ttips.set_tip(*this, "Blocked"); + break; + case Schedulable::state_terminated: + _color = Color(0, 0, 0); // Black + _ttips.set_tip(*this, "Terminated"); + break; + } + + queue_draw(); +} + +void +SchedulableStateWidget::draw_widget(cairo_t* ctx) +{ + CairoElements ce(ctx); + static const Point center(.5f, .5f); + ce.draw_3dsphere(center, .49f, _color); +} + + +void +SchedulableStateWidget::calc_drawing_size(size_t& width, size_t& height) const +{ + width = 1; + height = 1; +} + + +void +SchedulableStateWidget::calc_widget_size(size_t& width, size_t& height) const +{ + static const size_t min_size = 15; // px + + if(width != height) + if(width < min_size || height < min_size) + width = height = min_size; + else + width = height = std::min(width, height); +} diff --git a/src/schedulable_state_widget.hh b/src/schedulable_state_widget.hh new file mode 100644 index 0000000..672c34d --- /dev/null +++ b/src/schedulable_state_widget.hh @@ -0,0 +1,58 @@ +// src/schedulable_state_widget.hh - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef SCHEDULABLE_STATE_WIDGET_HH +#define SCHEDULABLE_STATE_WIDGET_HH 1 + +#include "config.h" + +#include "backend/schedulable.hh" +#include "cairo_elements.hh" +#include "cairo_widget.hh" + +#include "gtkmm/tooltips.h" + +namespace sgpem +{ + class SchedulableStateWidget : public CairoWidget + { + public: + SchedulableStateWidget(Schedulable::state st); + + void set_state(Schedulable::state new_state); + + protected: + virtual void draw_widget(cairo_t* ctx) = 0; + + // with this method CairoWidget tells the needed drawing dimensions + virtual void calc_drawing_size(size_t& width, size_t& height) const; + + // with this method CairoWidget tells the needed widget dimensions + virtual void calc_widget_size(size_t& width, size_t& height) const; + + private: + Color _color; + static Gtk::Tooltips _ttips; + }; + +} //~ namespace sgpem + + +#endif //~ SCHEDULABLE_STATE_WIDGET_HH