- added gradients to holt_widget.cc

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1007 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
paolo 2006-09-04 17:01:50 +00:00
parent c9d9766092
commit 0dbb265126
1 changed files with 44 additions and 13 deletions

View File

@ -104,8 +104,10 @@ void HoltResource::draw(cairo_t *cr)
_pos.real() - _radius, _pos.imag() - _radius, _pos.real() - _radius, _pos.imag() - _radius,
2*_radius, 2*_radius); 2*_radius, 2*_radius);
// fill // fill
cairo_set_source_rgb (cr, 1, 0.5, 1); cairo_set_source_rgb (cr, 1, 1, 1);
cairo_fill_preserve (cr); cairo_fill_preserve (cr);
// outline // outline
cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_source_rgb (cr, 0, 0, 0);
@ -164,34 +166,61 @@ HoltSchedulable::~HoltSchedulable()
void HoltSchedulable::draw(cairo_t *cr) void HoltSchedulable::draw(cairo_t *cr)
{ {
cairo_save(cr); // save context state cairo_save(cr); // save context state
cairo_pattern_t* gradient;
gradient = cairo_pattern_create_radial( _pos.real(), _pos.imag(), 0.0, _pos.real(), _pos.imag(), _radius);
/*
_ready_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// yellow
cairo_pattern_add_color_stop_rgba(_ready_process_gradient, 0.00, 1.0, 1.0, 0.5, 0.7);
cairo_pattern_add_color_stop_rgba(_ready_process_gradient, 1.00, 1.0, 1.0, 0.0, 1.0);
_running_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// green
cairo_pattern_add_color_stop_rgba(_running_process_gradient, 0.00, 0.5, 1.0, 0.5, 0.7);
cairo_pattern_add_color_stop_rgba(_running_process_gradient, 1.00, 0.0, 1.0, 0.0, 1.0);
_blocked_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// blue
cairo_pattern_add_color_stop_rgba(_blocked_process_gradient, 0.00, 0.5, 0.5, 1.0, 0.7);
cairo_pattern_add_color_stop_rgba(_blocked_process_gradient, 1.00, 0.0, 0.0, 1.0, 1.0);
*/
// draw circle // draw circle
cairo_arc (cr, _pos.real(), _pos.imag(), _radius, 0, 2 * M_PI); cairo_arc (cr, _pos.real(), _pos.imag(), _radius, 0, 2 * M_PI);
// filling // filling
switch(_schedulable->get_state()) switch(_schedulable->get_state())
{ {
case Schedulable::state_running: case Schedulable::state_running:
//cairo_set_source_rgb (cr, 0.5, 1, 0.5); // cairo_set_source_rgb (cr, 0, 1, 0);
cairo_set_source_rgb (cr, 0, 1, 0); // green
cairo_pattern_add_color_stop_rgba(gradient, 0.00, 0.5, 1.0, 0.5, 0.7);
cairo_pattern_add_color_stop_rgba(gradient, 1.00, 0.0, 1.0, 0.0, 1.0);
cairo_set_source(cr, gradient);
break; break;
case Schedulable::state_ready: case Schedulable::state_ready:
// cairo_set_source_rgb (cr, 1, 1, 0.5); // cairo_set_source_rgb (cr, 1, 1, 0);
cairo_set_source_rgb (cr, 1, 1, 0); // yellow
cairo_pattern_add_color_stop_rgba(gradient, 0.00, 1.0, 1.0, 0.5, 0.7);
cairo_pattern_add_color_stop_rgba(gradient, 1.00, 1.0, 1.0, 0.0, 1.0);
cairo_set_source(cr, gradient);
break; break;
case Schedulable::state_blocked: case Schedulable::state_blocked:
// cairo_set_source_rgb (cr, 1, 0.5, 0.5); // cairo_set_source_rgb (cr, 1, 0, 0);
cairo_set_source_rgb (cr, 1, 0, 0); // blue
cairo_pattern_add_color_stop_rgba(gradient, 0.00, 0.5, 0.5, 1.0, 0.7);
cairo_pattern_add_color_stop_rgba(gradient, 1.00, 0.0, 0.0, 1.0, 1.0);
cairo_set_source(cr, gradient);
break; break;
case Schedulable::state_future: case Schedulable::state_future:
// cairo_set_source_rgb (cr, 0.5, 0.5, 1); //cairo_set_source_rgb (cr, 0.5, 0.5, 1);
cairo_set_source_rgb (cr, 0.5, 0.5, 1);
break; break;
case Schedulable::state_terminated: case Schedulable::state_terminated:
cairo_set_source_rgb (cr, 0.5, 0.5, 0.5); cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
break; break;
} }
cairo_fill_preserve (cr); cairo_fill_preserve (cr);
// outline // outline
cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_source_rgb (cr, 0, 0, 0);
@ -208,6 +237,7 @@ void HoltSchedulable::draw(cairo_t *cr)
// stroke all // stroke all
cairo_stroke (cr); cairo_stroke (cr);
cairo_restore(cr); // restore context state cairo_restore(cr); // restore context state
cairo_pattern_destroy(gradient);
} }
Vec2 HoltSchedulable::get_intersection_to(Vec2 pt) Vec2 HoltSchedulable::get_intersection_to(Vec2 pt)
@ -246,10 +276,12 @@ void HoltRequest::draw(cairo_t *cr)
switch(_state) switch(_state)
{ {
case Request::state_unallocable: case Request::state_unallocable:
cairo_set_source_rgb(cr, 1, 0, 0); // blue
cairo_set_source_rgb(cr, 0, 0, 1);
arrow(cr, schedulable, resource); arrow(cr, schedulable, resource);
break; break;
case Request::state_allocated: case Request::state_allocated:
// green
cairo_set_source_rgb(cr, 0, 1, 0); cairo_set_source_rgb(cr, 0, 1, 0);
arrow(cr, resource, schedulable); arrow(cr, resource, schedulable);
break; break;
@ -258,6 +290,7 @@ void HoltRequest::draw(cairo_t *cr)
case Request::state_exhausted: case Request::state_exhausted:
break; break;
case Request::state_allocable: case Request::state_allocable:
// yellow
cairo_set_source_rgb(cr, 1, 1, 0); cairo_set_source_rgb(cr, 1, 1, 0);
arrow(cr, schedulable, resource); arrow(cr, schedulable, resource);
break; break;
@ -656,8 +689,6 @@ HoltWidget::draw_widget(cairo_t* ctx)
piter++; piter++;
} }
cairo_set_line_width (ctx, 0.5 * cairo_get_line_width (ctx));
typedef HoltRequests::const_iterator holt_requ_iterator; typedef HoltRequests::const_iterator holt_requ_iterator;
holt_requ_iterator reqiter = _holt_requests.begin(); holt_requ_iterator reqiter = _holt_requests.begin();
while(reqiter!=_holt_requests.end()) while(reqiter!=_holt_requests.end())