- Add untested code to SchedulableWidget, manually inheriting from a raw Gtk::Widget
and doing things by hand git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@819 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
82289edc14
commit
b76756c2a8
|
@ -26,7 +26,7 @@
|
||||||
#include "backend/thread.hh"
|
#include "backend/thread.hh"
|
||||||
#include "backend/process.hh"
|
#include "backend/process.hh"
|
||||||
|
|
||||||
#include <cairo/cairo.h>
|
#include <cairo.h>
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "backend/history.hh"
|
#include "backend/history.hh"
|
||||||
#include "backend/simulation.hh"
|
#include "backend/simulation.hh"
|
||||||
|
|
||||||
|
#include <gdkmm/window.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
@ -31,12 +33,9 @@ using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
SchedulablesWidget::SchedulablesWidget()
|
SchedulablesWidget::SchedulablesWidget()
|
||||||
: Gtk::DrawingArea(), _h(1), _buf(NULL)
|
: Glib::ObjectBase("sgpem_CairoWidget"),
|
||||||
|
Gtk::Widget(), _h(1), _buf(NULL)
|
||||||
{
|
{
|
||||||
// Add other events we want to manage (as mouse clicks)
|
|
||||||
// when needed
|
|
||||||
add_events(Gdk::EXPOSURE_MASK);
|
|
||||||
|
|
||||||
// Register this observer:
|
// Register this observer:
|
||||||
Simulation::get_instance().get_history().attach(*this);
|
Simulation::get_instance().get_history().attach(*this);
|
||||||
}
|
}
|
||||||
|
@ -51,17 +50,14 @@ SchedulablesWidget::~SchedulablesWidget()
|
||||||
void
|
void
|
||||||
SchedulablesWidget::update(const History& history)
|
SchedulablesWidget::update(const History& history)
|
||||||
{
|
{
|
||||||
|
if(!is_realized())
|
||||||
|
return; // Nowhere to draw to.
|
||||||
|
|
||||||
// Determine the final height before to start drawing
|
// Determine the final height before to start drawing
|
||||||
unsigned int w = get_allocation().get_width();
|
unsigned int w = get_allocation().get_width();
|
||||||
_h = calc_height(history);
|
_h = calc_height(history);
|
||||||
|
|
||||||
// FIXME TO THE EXPERT: this assertion fails.
|
// get_window() returns a null pointer
|
||||||
// is this important???
|
|
||||||
assert(is_drawable());
|
|
||||||
|
|
||||||
// FIXME : write me using double buffering
|
|
||||||
// PROBLEM : get_window() seems to return a null pointer!!!
|
|
||||||
// I read on the web that get_window() returns a null pointer
|
|
||||||
// if the widget has not been realized
|
// if the widget has not been realized
|
||||||
_buf = Gdk::Pixmap::create(get_window(), w, _h);
|
_buf = Gdk::Pixmap::create(get_window(), w, _h);
|
||||||
cairo_t* ctx = gdk_cairo_create(_buf->gobj());
|
cairo_t* ctx = gdk_cairo_create(_buf->gobj());
|
||||||
|
@ -96,31 +92,71 @@ SchedulablesWidget::calc_height(const History& history) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SchedulablesWidget::on_realize()
|
||||||
|
{
|
||||||
|
set_flags(Gtk::REALIZED);
|
||||||
|
|
||||||
|
// Add other events we want to manage (as mouse clicks)
|
||||||
|
// when needed
|
||||||
|
add_events(Gdk::EXPOSURE_MASK);
|
||||||
|
|
||||||
|
GdkWindowAttr attributes;
|
||||||
|
|
||||||
|
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;
|
||||||
|
attributes.visual = get_visual()->gobj();
|
||||||
|
attributes.colormap = get_colormap()->gobj();
|
||||||
|
|
||||||
|
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
|
||||||
|
&attributes,
|
||||||
|
GDK_WA_X | GDK_WA_Y | GDK_WA_COLORMAP |
|
||||||
|
GDK_WA_VISUAL | GDK_WA_WMCLASS);
|
||||||
|
set_window(window);
|
||||||
|
// get_style()->attach(window);
|
||||||
|
window->set_user_data(gobj());
|
||||||
|
get_style()->set_background(window, Gtk::STATE_ACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SchedulablesWidget::on_size_request(Gtk::Requisition* requisition)
|
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 = _h;
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
|
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
|
||||||
{
|
{
|
||||||
const Gtk::Allocation& allocation = get_allocation();
|
if(!event || event->count > 0)
|
||||||
int width = allocation.get_width();
|
return false;
|
||||||
int height = allocation.get_height();
|
|
||||||
|
// calculated dinamically:
|
||||||
|
set_size_request(get_allocation().get_width(), _h);
|
||||||
|
|
||||||
// Clip to redraw only the smallest possible area
|
// Clip to redraw only the smallest possible area
|
||||||
std::auto_ptr<Gdk::Rectangle> clip_area;
|
std::auto_ptr<Gdk::Rectangle> clip_area;
|
||||||
if(event)
|
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(event->area.x, event->area.y,
|
||||||
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(event->area.x, event->area.y,
|
event->area.width, event->area.height));
|
||||||
event->area.width, event->area.height));
|
|
||||||
|
|
||||||
else
|
|
||||||
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(0, 0, width, height));
|
|
||||||
|
|
||||||
// Use double buffering or we're CPU-dead
|
// Use double buffering or we're CPU-dead
|
||||||
// Copy from the buffer to the screen
|
// Copy from the buffer to the screen
|
||||||
|
@ -130,9 +166,6 @@ SchedulablesWidget::on_expose_event(GdkEventExpose* event)
|
||||||
clip_area->get_x(), clip_area->get_y(),
|
clip_area->get_x(), clip_area->get_y(),
|
||||||
clip_area->get_width(), clip_area->get_height());
|
clip_area->get_width(), clip_area->get_height());
|
||||||
|
|
||||||
// calculated dinamically:
|
|
||||||
set_size_request(width, _h);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
|
|
||||||
#include "backend/history_observer.hh"
|
#include "backend/history_observer.hh"
|
||||||
|
|
||||||
#include <cairo/cairo.h>
|
#include <cairo.h>
|
||||||
#include <gtkmm/drawingarea.h>
|
#include <gtkmm/widget.h>
|
||||||
#include <gdkmm/pixmap.h>
|
#include <gdkmm/pixmap.h>
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
class SchedulablesWidget : public Gtk::DrawingArea, public HistoryObserver
|
class SchedulablesWidget : public Gtk::Widget, public HistoryObserver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SchedulablesWidget();
|
SchedulablesWidget();
|
||||||
|
@ -40,6 +40,8 @@ namespace sgpem
|
||||||
void update(const History& history);
|
void update(const History& history);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void on_realize();
|
||||||
|
virtual void on_size_allocate(const Gtk::Allocation& allocation);
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue