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"
|
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
#include "backend/history.hh"
|
|
|
|
#include "backend/simulation.hh"
|
|
|
|
|
2006-08-03 13:16:16 +02:00
|
|
|
#include <gdkmm/window.h>
|
|
|
|
|
2006-08-03 17:43:21 +02:00
|
|
|
#include <cassert>
|
2006-08-02 15:48:26 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
2006-07-12 11:24:57 +02:00
|
|
|
|
2006-08-03 17:43:21 +02:00
|
|
|
|
2006-07-12 11:24:57 +02:00
|
|
|
using namespace sgpem;
|
|
|
|
|
|
|
|
|
|
|
|
SchedulablesWidget::SchedulablesWidget()
|
2006-08-03 17:43:21 +02:00
|
|
|
: Glib::ObjectBase("sgpem_CairoWidget"),
|
2006-08-03 13:16:16 +02:00
|
|
|
Gtk::Widget(), _h(1), _buf(NULL)
|
2006-07-12 11:24:57 +02:00
|
|
|
{
|
2006-08-03 17:43:21 +02:00
|
|
|
set_flags(Gtk::NO_WINDOW);
|
2006-08-02 15:48:26 +02:00
|
|
|
// Register this observer:
|
|
|
|
Simulation::get_instance().get_history().attach(*this);
|
2006-07-12 11:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SchedulablesWidget::~SchedulablesWidget()
|
|
|
|
{
|
2006-08-02 15:48:26 +02:00
|
|
|
Simulation::get_instance().get_history().detach(*this);
|
2006-07-12 11:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesWidget::update(const History& history)
|
|
|
|
{
|
2006-08-04 21:12:17 +02:00
|
|
|
// get_window() returns a null pointer
|
|
|
|
// if the widget has not been realized
|
2006-08-03 13:16:16 +02:00
|
|
|
if(!is_realized())
|
2006-08-03 17:43:21 +02:00
|
|
|
return; // Nowhere to draw to.
|
2006-08-03 13:16:16 +02:00
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
// Determine the final height before to start drawing
|
|
|
|
unsigned int w = get_allocation().get_width();
|
|
|
|
_h = calc_height(history);
|
2006-08-03 17:43:21 +02:00
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
_buf = Gdk::Pixmap::create(get_window(), w, _h);
|
2006-08-03 17:43:21 +02:00
|
|
|
|
2006-08-04 21:12:17 +02:00
|
|
|
// Draw the widget background as the first thing.
|
|
|
|
// I've seen this is how it's done in the very Gtk+ toolkit
|
|
|
|
// for the GtkProgressBar widget.
|
|
|
|
GtkStyle* gStyle = get_style()->gobj();
|
|
|
|
gtk_paint_box(gStyle, _buf->gobj(),
|
|
|
|
GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_IN,
|
|
|
|
NULL, this->gobj(), "through",
|
|
|
|
0, 0, w, _h);
|
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
cairo_t* ctx = gdk_cairo_create(_buf->gobj());
|
2006-07-28 17:24:56 +02:00
|
|
|
|
|
|
|
// do the drawing...
|
2006-08-02 15:48:26 +02:00
|
|
|
draw_widget(ctx);
|
2006-08-03 17:43:21 +02:00
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
cairo_scale(ctx, w, _h);
|
2006-07-28 17:24:56 +02:00
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
// manually force an expose_event?
|
|
|
|
cairo_destroy(ctx);
|
2006-08-03 17:43:21 +02:00
|
|
|
|
|
|
|
queue_draw();
|
2006-08-02 15:48:26 +02:00
|
|
|
}
|
2006-07-28 17:24:56 +02:00
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesWidget::draw_widget(cairo_t* ctx)
|
|
|
|
{
|
2006-07-28 17:24:56 +02:00
|
|
|
// NOTE: just to try
|
2006-08-02 15:48:26 +02:00
|
|
|
CairoElements ce(ctx);
|
2006-07-28 17:24:56 +02:00
|
|
|
Color red = { 1, 0, 0 };
|
|
|
|
Point center = { 25, 25 };
|
2006-08-02 15:48:26 +02:00
|
|
|
|
2006-07-28 17:24:56 +02:00
|
|
|
ce.draw_3dsphere(center, 25, red);
|
2006-08-02 15:48:26 +02:00
|
|
|
}
|
|
|
|
|
2006-07-28 17:24:56 +02:00
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
unsigned int
|
|
|
|
SchedulablesWidget::calc_height(const History& history) const
|
|
|
|
{
|
|
|
|
// FIXME: write me
|
|
|
|
return 400;
|
2006-07-12 11:24:57 +02:00
|
|
|
}
|
|
|
|
|
2006-08-03 13:16:16 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesWidget::on_realize()
|
|
|
|
{
|
2006-08-03 17:43:21 +02:00
|
|
|
if(is_realized()) return;
|
2006-08-03 13:16:16 +02:00
|
|
|
|
2006-08-03 17:43:21 +02:00
|
|
|
Gtk::Widget::on_realize();
|
|
|
|
ensure_style();
|
|
|
|
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
memset(&attributes, 0, sizeof(attributes));
|
2006-08-03 13:16:16 +02:00
|
|
|
|
|
|
|
Gtk::Allocation alloc = get_allocation();
|
|
|
|
|
|
|
|
attributes.x = alloc.get_x();
|
|
|
|
attributes.y = alloc.get_y();
|
|
|
|
attributes.width = alloc.get_width();
|
|
|
|
attributes.height = alloc.get_height();
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
2006-08-03 17:43:21 +02:00
|
|
|
attributes.event_mask = get_events() | GDK_EXPOSURE_MASK;
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
2006-08-04 21:12:17 +02:00
|
|
|
attributes.visual = get_visual()->gobj();
|
|
|
|
attributes.colormap = get_colormap()->gobj();
|
|
|
|
|
|
|
|
static const gint attributes_mask = Gdk::WA_X | Gdk::WA_Y | Gdk::WA_WMCLASS
|
|
|
|
| Gdk::WA_VISUAL | Gdk::WA_COLORMAP;
|
2006-08-03 17:43:21 +02:00
|
|
|
|
2006-08-03 13:16:16 +02:00
|
|
|
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
|
|
|
|
&attributes,
|
2006-08-04 21:12:17 +02:00
|
|
|
attributes_mask);
|
2006-08-03 17:43:21 +02:00
|
|
|
|
2006-08-04 21:12:17 +02:00
|
|
|
unset_flags(Gtk::NO_WINDOW);
|
2006-08-03 13:16:16 +02:00
|
|
|
set_window(window);
|
|
|
|
window->set_user_data(gobj());
|
2006-08-04 21:12:17 +02:00
|
|
|
|
|
|
|
// Not sure if the following line is needed:
|
|
|
|
gtk_style_attach(get_style()->gobj(), window->gobj());
|
2006-08-03 13:16:16 +02:00
|
|
|
get_style()->set_background(window, Gtk::STATE_ACTIVE);
|
|
|
|
}
|
2006-08-03 17:43:21 +02:00
|
|
|
|
|
|
|
void
|
2006-07-12 11:24:57 +02:00
|
|
|
SchedulablesWidget::on_size_request(Gtk::Requisition* requisition)
|
|
|
|
{
|
|
|
|
// FIXME: take correct measures, consider also using a viewport(?)
|
|
|
|
*requisition = Gtk::Requisition();
|
2006-08-03 13:16:16 +02:00
|
|
|
requisition->width = get_allocation().get_width();
|
|
|
|
requisition->height = _h;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesWidget::on_size_allocate(const Gtk::Allocation& allocation)
|
|
|
|
{
|
|
|
|
set_allocation(allocation);
|
|
|
|
|
|
|
|
if(is_realized())
|
|
|
|
get_window()->move_resize(allocation.get_x(), allocation.get_y(),
|
|
|
|
allocation.get_width(), allocation.get_height());
|
2006-07-12 11:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
|
|
|
|
{
|
2006-08-04 21:12:17 +02:00
|
|
|
if(event == NULL || event->count > 0)
|
|
|
|
return false;
|
|
|
|
|
2006-08-03 13:16:16 +02:00
|
|
|
// calculated dinamically:
|
2006-08-03 17:43:21 +02:00
|
|
|
int w = get_allocation().get_width();
|
|
|
|
set_size_request(w, _h);
|
2006-07-12 11:24:57 +02:00
|
|
|
|
2006-07-28 17:24:56 +02:00
|
|
|
// Clip to redraw only the smallest possible area
|
2006-08-02 15:48:26 +02:00
|
|
|
// Use double buffering or we're CPU-dead
|
|
|
|
// Copy from the buffer to the screen
|
|
|
|
if(_buf)
|
2006-08-04 21:12:17 +02:00
|
|
|
get_window()->draw_drawable(get_style()->get_black_gc(), _buf,
|
|
|
|
event->area.x, event->area.y,
|
|
|
|
event->area.x, event->area.y,
|
|
|
|
event->area.width, event->area.height);
|
|
|
|
|
2006-08-03 17:43:21 +02:00
|
|
|
return true;
|
2006-07-12 11:24:57 +02:00
|
|
|
}
|
2006-08-03 17:43:21 +02:00
|
|
|
|
2006-07-12 11:24:57 +02:00
|
|
|
|
|
|
|
bool
|
|
|
|
SchedulablesWidget::on_button_press_event(GdkEventButton* event)
|
|
|
|
{
|
|
|
|
// Not here. Yet.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|