2006-07-12 11:24:57 +02:00
|
|
|
// 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
|
|
|
|
|
2006-07-28 17:24:56 +02:00
|
|
|
#include "cairo_elements.hh"
|
2006-07-12 11:24:57 +02:00
|
|
|
#include "schedulables_widget.hh"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
using namespace sgpem;
|
|
|
|
|
|
|
|
|
|
|
|
SchedulablesWidget::SchedulablesWidget()
|
2006-07-28 17:24:56 +02:00
|
|
|
: Gtk::DrawingArea(), _ctx(NULL)
|
2006-07-12 11:24:57 +02:00
|
|
|
{
|
|
|
|
// Add other events we want to manage (as mouse clicks)
|
|
|
|
// when needed
|
2006-07-28 17:24:56 +02:00
|
|
|
add_events(Gdk::EXPOSURE_MASK);
|
2006-07-12 11:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SchedulablesWidget::~SchedulablesWidget()
|
|
|
|
{
|
2006-07-28 17:24:56 +02:00
|
|
|
if(_ctx != NULL)
|
|
|
|
cairo_destroy(_ctx);
|
2006-07-12 11:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesWidget::update(const History& history)
|
|
|
|
{
|
2006-07-28 17:24:56 +02:00
|
|
|
// FIXME : write me using double buffering
|
|
|
|
// GdkPixmap* buffer = gdk_pixmap_new(...);
|
|
|
|
// _ctx = gdk_cairo_create(buffer);
|
|
|
|
|
|
|
|
// do the drawing...
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: just to try
|
|
|
|
CairoElements ce(_ctx);
|
|
|
|
Color red = { 1, 0, 0 };
|
|
|
|
Point center = { 25, 25 };
|
|
|
|
|
|
|
|
ce.draw_3dsphere(center, 25, red);
|
|
|
|
|
|
|
|
// manually force an expose_event?
|
2006-07-12 11:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
2006-07-28 17:24:56 +02:00
|
|
|
if(_ctx == NULL)
|
|
|
|
_ctx = gdk_cairo_create(gdkDrawable);
|
2006-07-12 11:24:57 +02:00
|
|
|
|
2006-07-28 17:24:56 +02:00
|
|
|
cairo_t* cr = gdk_cairo_create(gdkDrawable);
|
|
|
|
|
2006-07-12 11:24:57 +02:00
|
|
|
const Gtk::Allocation& allocation = get_allocation();
|
|
|
|
int width = allocation.get_width();
|
|
|
|
int height = allocation.get_height();
|
|
|
|
|
2006-07-28 17:24:56 +02:00
|
|
|
// Clip to redraw only the smallest possible area
|
2006-07-12 11:24:57 +02:00
|
|
|
if(event)
|
|
|
|
{
|
|
|
|
cairo_rectangle(cr, event->area.x, event->area.y,
|
|
|
|
event->area.width, event->area.height);
|
|
|
|
cairo_clip(cr);
|
|
|
|
}
|
2006-07-28 17:24:56 +02:00
|
|
|
|
2006-07-12 11:24:57 +02:00
|
|
|
// should be calculated dinamically:
|
|
|
|
set_size_request(200,400);
|
|
|
|
|
2006-07-28 17:24:56 +02:00
|
|
|
// Copy from buffer to video
|
|
|
|
// if(_ctx != NULL)
|
|
|
|
// gdk_draw_drawable(buffer, GC??, gdkDrawable, ...clip-region...);
|
|
|
|
|
2006-07-12 11:24:57 +02:00
|
|
|
// Height should be calculated dynamically?
|
|
|
|
cairo_scale(cr, width, width);
|
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
SchedulablesWidget::on_button_press_event(GdkEventButton* event)
|
|
|
|
{
|
|
|
|
// Not here. Yet.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|