sgpemv2/src/schedulables_widget.cc

129 lines
3.3 KiB
C++
Raw Normal View History

// 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 "cairo_elements.hh"
#include "schedulables_widget.hh"
#include <cmath>
using namespace sgpem;
SchedulablesWidget::SchedulablesWidget()
: Gtk::DrawingArea(), _ctx(NULL)
{
// Add other events we want to manage (as mouse clicks)
// when needed
add_events(Gdk::EXPOSURE_MASK);
}
SchedulablesWidget::~SchedulablesWidget()
{
if(_ctx != NULL)
cairo_destroy(_ctx);
}
void
SchedulablesWidget::update(const History& history)
{
// 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?
}
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.
if(_ctx == NULL)
_ctx = gdk_cairo_create(gdkDrawable);
cairo_t* cr = gdk_cairo_create(gdkDrawable);
const Gtk::Allocation& allocation = get_allocation();
int width = allocation.get_width();
int height = allocation.get_height();
// Clip to redraw only the smallest possible area
if(event)
{
cairo_rectangle(cr, event->area.x, event->area.y,
event->area.width, event->area.height);
cairo_clip(cr);
}
// should be calculated dinamically:
set_size_request(200,400);
// Copy from buffer to video
// if(_ctx != NULL)
// gdk_draw_drawable(buffer, GC??, gdkDrawable, ...clip-region...);
// 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;
}