- Start working on double-buffering on cairo widgets. The system
will SIGSEGV. I will fix this asap, in the meantime use the cmdline interface. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@810 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
6969d5b2c2
commit
5b577c5979
|
@ -24,6 +24,9 @@
|
||||||
#include "schedulables_widget.hh"
|
#include "schedulables_widget.hh"
|
||||||
#include "gui_builder.hh"
|
#include "gui_builder.hh"
|
||||||
|
|
||||||
|
#include "backend/history.hh"
|
||||||
|
#include "backend/simulation.hh"
|
||||||
|
|
||||||
#include <glibmm/ustring.h>
|
#include <glibmm/ustring.h>
|
||||||
#include <gtkmm/aboutdialog.h>
|
#include <gtkmm/aboutdialog.h>
|
||||||
#include <gtkmm/expander.h>
|
#include <gtkmm/expander.h>
|
||||||
|
@ -64,6 +67,10 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||||
scheds_expander->add(*scheds_widget);
|
scheds_expander->add(*scheds_widget);
|
||||||
// we have to remember to manually show custom added widgets:
|
// we have to remember to manually show custom added widgets:
|
||||||
scheds_widget->show();
|
scheds_widget->show();
|
||||||
|
|
||||||
|
// A test for widget display:
|
||||||
|
Simulation& sim = Simulation::get_instance();
|
||||||
|
sim.get_history().add_process("goofy", 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,45 +21,72 @@
|
||||||
#include "cairo_elements.hh"
|
#include "cairo_elements.hh"
|
||||||
#include "schedulables_widget.hh"
|
#include "schedulables_widget.hh"
|
||||||
|
|
||||||
#include <cmath>
|
#include "backend/history.hh"
|
||||||
|
#include "backend/simulation.hh"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
SchedulablesWidget::SchedulablesWidget()
|
SchedulablesWidget::SchedulablesWidget()
|
||||||
: Gtk::DrawingArea(), _ctx(NULL)
|
: Gtk::DrawingArea(), _h(1), _buf(NULL)
|
||||||
{
|
{
|
||||||
// Add other events we want to manage (as mouse clicks)
|
// Add other events we want to manage (as mouse clicks)
|
||||||
// when needed
|
// when needed
|
||||||
add_events(Gdk::EXPOSURE_MASK);
|
add_events(Gdk::EXPOSURE_MASK);
|
||||||
|
|
||||||
|
// Register this observer:
|
||||||
|
Simulation::get_instance().get_history().attach(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SchedulablesWidget::~SchedulablesWidget()
|
SchedulablesWidget::~SchedulablesWidget()
|
||||||
{
|
{
|
||||||
if(_ctx != NULL)
|
Simulation::get_instance().get_history().detach(*this);
|
||||||
cairo_destroy(_ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SchedulablesWidget::update(const History& history)
|
SchedulablesWidget::update(const History& history)
|
||||||
{
|
{
|
||||||
|
// Determine the final height before to start drawing
|
||||||
|
unsigned int w = get_allocation().get_width();
|
||||||
|
_h = calc_height(history);
|
||||||
|
|
||||||
// FIXME : write me using double buffering
|
// FIXME : write me using double buffering
|
||||||
// GdkPixmap* buffer = gdk_pixmap_new(...);
|
// PROBLEM : get_window() seems to return a null pointer!!!
|
||||||
// _ctx = gdk_cairo_create(buffer);
|
_buf = Gdk::Pixmap::create(get_window(), w, _h);
|
||||||
|
cairo_t* ctx = gdk_cairo_create(_buf->gobj());
|
||||||
|
|
||||||
// do the drawing...
|
// do the drawing...
|
||||||
|
draw_widget(ctx);
|
||||||
|
|
||||||
|
cairo_scale(ctx, w, _h);
|
||||||
|
|
||||||
|
// manually force an expose_event?
|
||||||
|
cairo_destroy(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SchedulablesWidget::draw_widget(cairo_t* ctx)
|
||||||
|
{
|
||||||
// NOTE: just to try
|
// NOTE: just to try
|
||||||
CairoElements ce(_ctx);
|
CairoElements ce(ctx);
|
||||||
Color red = { 1, 0, 0 };
|
Color red = { 1, 0, 0 };
|
||||||
Point center = { 25, 25 };
|
Point center = { 25, 25 };
|
||||||
|
|
||||||
ce.draw_3dsphere(center, 25, red);
|
ce.draw_3dsphere(center, 25, red);
|
||||||
|
}
|
||||||
|
|
||||||
// manually force an expose_event?
|
|
||||||
|
unsigned int
|
||||||
|
SchedulablesWidget::calc_height(const History& history) const
|
||||||
|
{
|
||||||
|
// FIXME: write me
|
||||||
|
return 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,52 +96,37 @@ SchedulablesWidget::on_size_request(Gtk::Requisition* requisition)
|
||||||
// FIXME: take correct measures, consider also using a viewport(?)
|
// FIXME: take correct measures, consider also using a viewport(?)
|
||||||
*requisition = Gtk::Requisition();
|
*requisition = Gtk::Requisition();
|
||||||
requisition->width = get_allocation().get_width();
|
requisition->width = get_allocation().get_width();
|
||||||
requisition->height = requisition->width;
|
requisition->height = _h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
|
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();
|
const Gtk::Allocation& allocation = get_allocation();
|
||||||
int width = allocation.get_width();
|
int width = allocation.get_width();
|
||||||
int height = allocation.get_height();
|
int height = allocation.get_height();
|
||||||
|
|
||||||
// Clip to redraw only the smallest possible area
|
// Clip to redraw only the smallest possible area
|
||||||
|
std::auto_ptr<Gdk::Rectangle> clip_area;
|
||||||
if(event)
|
if(event)
|
||||||
{
|
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(event->area.x, event->area.y,
|
||||||
cairo_rectangle(cr, event->area.x, event->area.y,
|
event->area.width, event->area.height));
|
||||||
event->area.width, event->area.height);
|
|
||||||
cairo_clip(cr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// should be calculated dinamically:
|
else
|
||||||
set_size_request(200,400);
|
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(0, 0, width, height));
|
||||||
|
|
||||||
// Copy from buffer to video
|
// Use double buffering or we're CPU-dead
|
||||||
// if(_ctx != NULL)
|
// Copy from the buffer to the screen
|
||||||
// gdk_draw_drawable(buffer, GC??, gdkDrawable, ...clip-region...);
|
if(_buf)
|
||||||
|
get_window()->draw_drawable(Gdk::GC::create(get_window()), _buf,
|
||||||
|
clip_area->get_x(), clip_area->get_y(),
|
||||||
|
clip_area->get_x(), clip_area->get_y(),
|
||||||
|
clip_area->get_width(), clip_area->get_height());
|
||||||
|
|
||||||
// Height should be calculated dynamically?
|
// calculated dinamically:
|
||||||
cairo_scale(cr, width, width);
|
set_size_request(width, _h);
|
||||||
|
|
||||||
cairo_destroy(cr);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
|
|
||||||
#include "backend/history_observer.hh"
|
#include "backend/history_observer.hh"
|
||||||
|
|
||||||
|
#include <cairo/cairo.h>
|
||||||
#include <gtkmm/drawingarea.h>
|
#include <gtkmm/drawingarea.h>
|
||||||
|
#include <gdkmm/pixmap.h>
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
|
@ -41,6 +43,12 @@ namespace sgpem
|
||||||
virtual void on_size_request(Gtk::Requisition* requisition);
|
virtual void on_size_request(Gtk::Requisition* requisition);
|
||||||
virtual bool on_expose_event(GdkEventExpose* event);
|
virtual bool on_expose_event(GdkEventExpose* event);
|
||||||
virtual bool on_button_press_event(GdkEventButton* event);
|
virtual bool on_button_press_event(GdkEventButton* event);
|
||||||
|
virtual void draw_widget(cairo_t* ctx);
|
||||||
|
virtual unsigned int calc_height(const History& history) const;
|
||||||
|
|
||||||
|
// The height the widget will assume, must be determined
|
||||||
|
// before starting drawing by calc_height().
|
||||||
|
unsigned int _h;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef Gdk::Rectangle area_t;
|
typedef Gdk::Rectangle area_t;
|
||||||
|
@ -48,7 +56,7 @@ namespace sgpem
|
||||||
typedef std::pair<area_t, method0_t> area_callback_t;
|
typedef std::pair<area_t, method0_t> area_callback_t;
|
||||||
typedef std::vector<area_callback_t> areas_vect_t;
|
typedef std::vector<area_callback_t> areas_vect_t;
|
||||||
|
|
||||||
cairo_t* _ctx;
|
Glib::RefPtr<Gdk::Pixmap> _buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //~ namespace sgpem
|
} //~ namespace sgpem
|
||||||
|
|
Loading…
Reference in New Issue