- Create SimulationWidget

- Drop the old SchedulablesWidget in favor of a simple Gtk::TreeView
- Update the GuiBuilder consequentially
- FIXME: in cairo_widget.cc : have we to scale the context before or after
drawing on it?


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@845 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-12 15:49:37 +00:00
parent 51fdeea4d1
commit 59edb09c14
8 changed files with 60 additions and 61 deletions

View File

@ -295,7 +295,7 @@ sgpemv2_SOURCES = \
src/main.cc \ src/main.cc \
src/parse_opts.cc \ src/parse_opts.cc \
src/schedulables_tree_widget.cc \ src/schedulables_tree_widget.cc \
src/schedulables_widget.cc \ src/simulation_widget.cc \
src/text_simulation.cc src/text_simulation.cc
noinst_HEADERS += \ noinst_HEADERS += \
@ -305,7 +305,7 @@ noinst_HEADERS += \
src/main.hh \ src/main.hh \
src/parse_opts.hh \ src/parse_opts.hh \
src/schedulables_tree_widget.hh \ src/schedulables_tree_widget.hh \
src/schedulables_widget.hh \ src/simulation_widget.hh \
src/text_simulation.hh src/text_simulation.hh
# ---------- glade files ----------- # ---------- glade files -----------

View File

@ -2,7 +2,7 @@
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!-- Generated with glade3 <!-- Generated with glade3
Version: 2.91.3 Version: 2.91.3
Date: Fri Aug 4 21:13:04 2006 Date: Sat Aug 12 16:16:48 2006
User: matteo User: matteo
Host: tulip Host: tulip
--> -->
@ -226,9 +226,6 @@
</widget> </widget>
</child> </child>
</widget> </widget>
<packing>
<property name="resize">False</property>
</packing>
</child> </child>
<child> <child>
<widget class="GtkScrolledWindow" id="SimulationScrolledWindow"> <widget class="GtkScrolledWindow" id="SimulationScrolledWindow">

View File

@ -29,13 +29,12 @@
#include <cassert> #include <cassert>
#include <memory> #include <memory>
using namespace sgpem; using namespace sgpem;
CairoWidget::CairoWidget() CairoWidget::CairoWidget()
: Glib::ObjectBase("sgpem_CairoWidget"), : Glib::ObjectBase("sgpem_CairoWidget"),
Gtk::Widget(), _h(1), _buf(NULL) Gtk::Widget(), _w(1), _h(1), _buf(NULL)
{ {
set_flags(Gtk::NO_WINDOW); set_flags(Gtk::NO_WINDOW);
// Register this observer: // Register this observer:
@ -58,10 +57,9 @@ CairoWidget::update(const History& history)
return; // Nowhere to draw to. 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(); calc_size(history, _w, _h);
_h = calc_height(history);
_buf = Gdk::Pixmap::create(get_window(), w, _h); _buf = Gdk::Pixmap::create(get_window(), _w, _h);
// Draw the widget background as the first thing. // Draw the widget background as the first thing.
// I've seen this is how it's done in the very Gtk+ toolkit // I've seen this is how it's done in the very Gtk+ toolkit
@ -70,18 +68,16 @@ CairoWidget::update(const History& history)
gtk_paint_box(gStyle, _buf->gobj(), gtk_paint_box(gStyle, _buf->gobj(),
GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_IN, GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_IN,
NULL, this->gobj(), "through", NULL, this->gobj(), "through",
0, 0, w, _h); 0, 0, _w, _h);
cairo_t* ctx = gdk_cairo_create(_buf->gobj()); cairo_t* ctx = gdk_cairo_create(_buf->gobj());
// do the drawing... // do the drawing...
cairo_scale(ctx, _w, _h);
draw_widget(ctx); draw_widget(ctx);
cairo_scale(ctx, w, _h);
// manually force an expose_event?
cairo_destroy(ctx); cairo_destroy(ctx);
// Force redraw
queue_draw(); queue_draw();
} }
@ -125,15 +121,6 @@ CairoWidget::on_realize()
get_style()->set_background(window, Gtk::STATE_ACTIVE); get_style()->set_background(window, Gtk::STATE_ACTIVE);
} }
void
CairoWidget::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 = _h;
}
void void
CairoWidget::on_size_allocate(const Gtk::Allocation& allocation) CairoWidget::on_size_allocate(const Gtk::Allocation& allocation)
@ -152,9 +139,8 @@ CairoWidget::on_expose_event(GdkEventExpose* event)
if (event == NULL || event->count > 0) if (event == NULL || event->count > 0)
return false; return false;
// calculated dinamically: // calculated dinamically on update():
int w = get_allocation().get_width(); set_size_request(_w, _h);
set_size_request(w, _h);
// Clip to redraw only the smallest possible area // Clip to redraw only the smallest possible area
// Use double buffering or we're CPU-dead // Use double buffering or we're CPU-dead

View File

@ -40,13 +40,14 @@ namespace sgpem
void update(const History& history); void update(const History& history);
protected: protected:
typedef unsigned int size_t;
virtual void on_realize(); virtual void on_realize();
virtual void on_size_allocate(const Gtk::Allocation& allocation); virtual void on_size_allocate(const Gtk::Allocation& allocation);
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) = 0; virtual void draw_widget(cairo_t* ctx) = 0;
virtual unsigned int calc_height(const History& history) const = 0; virtual void calc_size(const History& history, size_t& width, size_t& height) const = 0;
typedef Gdk::Rectangle area_t; typedef Gdk::Rectangle area_t;
typedef sigc::mem_functor0<void, CairoWidget> method0_t; typedef sigc::mem_functor0<void, CairoWidget> method0_t;
@ -54,9 +55,10 @@ namespace sgpem
typedef std::vector<area_callback_t> areas_vect_t; typedef std::vector<area_callback_t> areas_vect_t;
private: private:
// The height the widget will assume, must be determined // The width and height the widget will assume, must be determined
// before starting drawing by calc_height() // before starting drawing by calc_size()
unsigned int _h; mutable size_t _w;
mutable size_t _h;
// The offscreen pixmap we use for double-buffering // The offscreen pixmap we use for double-buffering
Glib::RefPtr<Gdk::Pixmap> _buf; Glib::RefPtr<Gdk::Pixmap> _buf;

View File

@ -21,11 +21,8 @@
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"
#ifdef _SG_SCHEDULABLES_TREE_WIDGET #include "schedulables_tree_widget.hh"
#include "schedulables_tree_widget.hh" #include "simulation_widget.hh"
#else
#include "schedulables_widget.hh"
#endif
#include "gui_builder.hh" #include "gui_builder.hh"
@ -37,6 +34,7 @@
#include <gtkmm/expander.h> #include <gtkmm/expander.h>
#include <gtkmm/main.h> #include <gtkmm/main.h>
#include <gtkmm/menuitem.h> #include <gtkmm/menuitem.h>
#include <gtkmm/scrolledwindow.h>
#include <iostream> #include <iostream>
@ -78,14 +76,18 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
Expander* scheds_expander = NULL; Expander* scheds_expander = NULL;
_refXml->get_widget("SchedulablesExpander", scheds_expander); _refXml->get_widget("SchedulablesExpander", scheds_expander);
#ifdef _SG_SCHEDULABLES_TREE_WIDGET
SchedulablesTreeWidget* scheds_widget = manage(new SchedulablesTreeWidget()); SchedulablesTreeWidget* scheds_widget = manage(new SchedulablesTreeWidget());
#else
SchedulablesWidget* scheds_widget = manage(new SchedulablesWidget());
#endif
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();
// Main simulation widget
ScrolledWindow* simulation_window = NULL;
_refXml->get_widget("SimulationScrolledWindow", simulation_window);
SimulationWidget* simulation_widget = manage(new SimulationWidget());
simulation_window->add(*simulation_widget);
simulation_widget->show();
} }

View File

@ -1,4 +1,4 @@
// src/schedulables_widget.cc - Copyright 2005, 2006, University // src/simulation_widget.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied // of Padova, dept. of Pure and Applied
// Mathematics // Mathematics
// //
@ -18,26 +18,30 @@
// along with SGPEMv2; if not, write to the Free Software // along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "schedulables_widget.hh" #include "simulation_widget.hh"
#include "cairo_elements.hh" #include "cairo_elements.hh"
#include <cassert> #include <cassert>
#ifndef NDEBUG
#include <iostream>
#endif
using namespace sgpem; using namespace sgpem;
SchedulablesWidget::SchedulablesWidget() SimulationWidget::SimulationWidget()
: Glib::ObjectBase("sgpem_SchedulablesWidget"), CairoWidget() : Glib::ObjectBase("sgpem_SimulationWidget"), CairoWidget()
{} {}
SchedulablesWidget::~SchedulablesWidget() SimulationWidget::~SimulationWidget()
{} {}
void void
SchedulablesWidget::draw_widget(cairo_t* ctx) SimulationWidget::draw_widget(cairo_t* ctx)
{ {
// NOTE: just to try // NOTE: just to try
CairoElements ce(ctx); CairoElements ce(ctx);
@ -52,9 +56,17 @@ SchedulablesWidget::draw_widget(cairo_t* ctx)
} }
unsigned int void
SchedulablesWidget::calc_height(const History& history) const SimulationWidget::calc_size(const History& history, size_t& width, size_t& height) const
{ {
// FIXME: write me // FIXME: write me
return 400; width = get_allocation().get_width();
height = get_allocation().get_height();
#ifndef NDEBUG
using namespace std;
clog << " [DD] New allocation event on " << hex << this << ": "
<< dec << width << 'x' << height << endl;
#endif
} }

View File

@ -1,4 +1,4 @@
// src/schedulables_widget.hh - Copyright 2005, 2006, University // src/simulation_widget.hh - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied // of Padova, dept. of Pure and Applied
// Mathematics // Mathematics
// //
@ -18,8 +18,8 @@
// along with SGPEMv2; if not, write to the Free Software // along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef SCHEDULABLES_WIDGET_HH #ifndef SIMULATION_WIDGET_HH
#define SCHEDULABLES_WIDGET_HH 1 #define SIMULATION_WIDGET_HH 1
#include "config.h" #include "config.h"
@ -27,18 +27,18 @@
namespace sgpem namespace sgpem
{ {
class SchedulablesWidget : public CairoWidget class SimulationWidget : public CairoWidget
{ {
public: public:
SchedulablesWidget(); SimulationWidget();
virtual ~SchedulablesWidget(); virtual ~SimulationWidget();
protected: protected:
virtual void draw_widget(cairo_t* ctx); void draw_widget(cairo_t* ctx);
virtual unsigned int calc_height(const History& history) const; void calc_size(const History& history, size_t& width, size_t& height) const;
}; };
} //~ namespace sgpem } //~ namespace sgpem
#endif //~ SCHEDULABLES_WIDGET_HH #endif //~ SIMULATION_WIDGET_HH

View File

@ -1,4 +1,4 @@
set cpu-policy 1 set cpu-policy 2
add resource add resource
forchetta forchetta