129 lines
3.5 KiB
C++
129 lines
3.5 KiB
C++
|
// src/schedulables_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 "schedulables_widget.hh"
|
||
|
|
||
|
#include <cmath>
|
||
|
|
||
|
using namespace sgpem;
|
||
|
|
||
|
|
||
|
SchedulablesWidget::SchedulablesWidget()
|
||
|
: _ctx(NULL)
|
||
|
{
|
||
|
// Add other events we want to manage (as mouse clicks)
|
||
|
// when needed
|
||
|
add_events(Gdk::EXPOSURE_MASK);
|
||
|
}
|
||
|
|
||
|
|
||
|
SchedulablesWidget::~SchedulablesWidget()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
void
|
||
|
SchedulablesWidget::update(const History& history)
|
||
|
{
|
||
|
// FIXME : write me
|
||
|
}
|
||
|
|
||
|
|
||
|
void
|
||
|
SchedulablesWidget::on_size_request(Gtk::Requisition* requisition)
|
||
|
{
|
||
|
// FIXME: take correct measures, consider also using a viewport(?)
|
||
|
*requisition = Gtk::Requisition();
|
||
|
requisition->width = get_allocation().get_width();
|
||
|
requisition->height = requisition->width;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool
|
||
|
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
|
||
|
{
|
||
|
// Use double buffering or we're CPU-dead
|
||
|
|
||
|
Glib::RefPtr<Gdk::Window> window = get_window();
|
||
|
GdkWindow* gdkWindow = window->gobj();
|
||
|
GdkDrawable* gdkDrawable;
|
||
|
gint xOffset, yOffset;
|
||
|
gdk_window_get_internal_paint_info(gdkWindow, &gdkDrawable, &xOffset, &yOffset);
|
||
|
|
||
|
// Copy new ctx from old one (the buffer); from distant memories,
|
||
|
// we should use something like create_similar to instantiate a
|
||
|
// compatible surface and then copy the buffer to fg
|
||
|
// So the following two lines WILL HAVE TO CHANGE.
|
||
|
cairo_t*& cr = _ctx;
|
||
|
cr = gdk_cairo_create(gdkDrawable);
|
||
|
|
||
|
const Gtk::Allocation& allocation = get_allocation();
|
||
|
int width = allocation.get_width();
|
||
|
int height = allocation.get_height();
|
||
|
|
||
|
// Already clip, so that paint hasn't to care about it:
|
||
|
if(event)
|
||
|
{
|
||
|
cairo_rectangle(cr, event->area.x, event->area.y,
|
||
|
event->area.width, event->area.height);
|
||
|
cairo_clip(cr);
|
||
|
}
|
||
|
|
||
|
// NOTE: just to try:
|
||
|
|
||
|
// should be calculated dinamically:
|
||
|
set_size_request(200,400);
|
||
|
|
||
|
// Height should be calculated dynamically?
|
||
|
cairo_scale(cr, width, width);
|
||
|
cairo_set_line_width(cr, 0.02);
|
||
|
cairo_set_source_rgba(cr, 0, 0, 0, 1);
|
||
|
|
||
|
// Draw initial sphere perimeter
|
||
|
float r = 1.f, g = 0.f, b = 0.f;
|
||
|
double x = .5, y = .5, radius = .5;
|
||
|
cairo_save(cr);
|
||
|
cairo_new_path(cr);
|
||
|
cairo_arc(cr, x, y, radius, 0, 2*M_PI);
|
||
|
cairo_pattern_t* grad = cairo_pattern_create_radial(x, y, radius, x, y, radius - .15);
|
||
|
cairo_pattern_add_color_stop_rgba(grad, 0, r - .2, g - .2, b - .2, 1);
|
||
|
cairo_pattern_add_color_stop_rgba(grad, 1, r, g, b, 1);
|
||
|
cairo_set_source(cr, grad);
|
||
|
cairo_fill_preserve(cr);
|
||
|
cairo_pattern_destroy(grad);
|
||
|
cairo_set_source_rgba(cr, 0, 0, 0, 1);
|
||
|
cairo_set_line_width(cr, radius * .01);
|
||
|
cairo_stroke(cr);
|
||
|
cairo_restore(cr);
|
||
|
|
||
|
cairo_destroy(cr);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool
|
||
|
SchedulablesWidget::on_button_press_event(GdkEventButton* event)
|
||
|
{
|
||
|
// Not here. Yet.
|
||
|
return false;
|
||
|
}
|
||
|
|