sgpemv2/src/schedulable_state_widget.cc

96 lines
2.4 KiB
C++
Raw Normal View History

// 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);
}