- Add stubs to implement custom widget to show schedulables entities.
Paint a red clown nose just to show the humour of the thing, and that it works(?). git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@755 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
db34232e72
commit
09268f7fd4
|
@ -269,6 +269,7 @@ sgpemv2_SOURCES = \
|
||||||
src/main_window.cc \
|
src/main_window.cc \
|
||||||
src/observer.cc \
|
src/observer.cc \
|
||||||
src/parse_opts.cc \
|
src/parse_opts.cc \
|
||||||
|
src/schedulables_widget.cc \
|
||||||
src/simulation.cc \
|
src/simulation.cc \
|
||||||
src/standard_io.cc \
|
src/standard_io.cc \
|
||||||
src/text_simulation.cc
|
src/text_simulation.cc
|
||||||
|
@ -282,6 +283,7 @@ noinst_HEADERS += \
|
||||||
src/main_window.hh \
|
src/main_window.hh \
|
||||||
src/observer.hh \
|
src/observer.hh \
|
||||||
src/parse_opts.hh \
|
src/parse_opts.hh \
|
||||||
|
src/schedulables_widget.hh \
|
||||||
src/simulation.hh \
|
src/simulation.hh \
|
||||||
src/standard_io.hh \
|
src/standard_io.hh \
|
||||||
src/text_simulation.hh
|
src/text_simulation.hh
|
||||||
|
|
|
@ -21,10 +21,12 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
|
|
||||||
|
#include "schedulables_widget.hh"
|
||||||
#include "gui_builder.hh"
|
#include "gui_builder.hh"
|
||||||
|
|
||||||
#include <glibmm/ustring.h>
|
#include <glibmm/ustring.h>
|
||||||
#include <gtkmm/aboutdialog.h>
|
#include <gtkmm/aboutdialog.h>
|
||||||
|
#include <gtkmm/expander.h>
|
||||||
#include <gtkmm/main.h>
|
#include <gtkmm/main.h>
|
||||||
#include <gtkmm/menuitem.h>
|
#include <gtkmm/menuitem.h>
|
||||||
|
|
||||||
|
@ -54,6 +56,14 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||||
AboutDialog* about_dialog = NULL;
|
AboutDialog* about_dialog = NULL;
|
||||||
_refXml->get_widget("AboutDialog", about_dialog);
|
_refXml->get_widget("AboutDialog", about_dialog);
|
||||||
help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
|
help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
|
||||||
|
|
||||||
|
// Temporary code to test the Schedulables custom widget
|
||||||
|
Expander* scheds_expander = NULL;
|
||||||
|
_refXml->get_widget("SchedulablesExpander", scheds_expander);
|
||||||
|
SchedulablesWidget* scheds_widget = manage(new SchedulablesWidget());
|
||||||
|
scheds_expander->add(*scheds_widget);
|
||||||
|
// we have to remember to manually show custom added widgets:
|
||||||
|
scheds_widget->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
// 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 "schedulables_widget.hh"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
|
SchedulablesWidget::SchedulablesWidget()
|
||||||
|
: _ctx(NULL)
|
||||||
|
{
|
||||||
|
// Add other events we want to manage (as mouse clicks)
|
||||||
|
// when needed
|
||||||
|
add_events(Gdk::EXPOSURE_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SchedulablesWidget::~SchedulablesWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SchedulablesWidget::update(const History& history)
|
||||||
|
{
|
||||||
|
// FIXME : write me
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
cairo_t*& cr = _ctx;
|
||||||
|
cr = gdk_cairo_create(gdkDrawable);
|
||||||
|
|
||||||
|
const Gtk::Allocation& allocation = get_allocation();
|
||||||
|
int width = allocation.get_width();
|
||||||
|
int height = allocation.get_height();
|
||||||
|
|
||||||
|
// Already clip, so that paint hasn't to care about it:
|
||||||
|
if(event)
|
||||||
|
{
|
||||||
|
cairo_rectangle(cr, event->area.x, event->area.y,
|
||||||
|
event->area.width, event->area.height);
|
||||||
|
cairo_clip(cr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: just to try:
|
||||||
|
|
||||||
|
// should be calculated dinamically:
|
||||||
|
set_size_request(200,400);
|
||||||
|
|
||||||
|
// Height should be calculated dynamically?
|
||||||
|
cairo_scale(cr, width, width);
|
||||||
|
cairo_set_line_width(cr, 0.02);
|
||||||
|
cairo_set_source_rgba(cr, 0, 0, 0, 1);
|
||||||
|
|
||||||
|
// Draw initial sphere perimeter
|
||||||
|
float r = 1.f, g = 0.f, b = 0.f;
|
||||||
|
double x = .5, y = .5, radius = .5;
|
||||||
|
cairo_save(cr);
|
||||||
|
cairo_new_path(cr);
|
||||||
|
cairo_arc(cr, x, y, radius, 0, 2*M_PI);
|
||||||
|
cairo_pattern_t* grad = cairo_pattern_create_radial(x, y, radius, x, y, radius - .15);
|
||||||
|
cairo_pattern_add_color_stop_rgba(grad, 0, r - .2, g - .2, b - .2, 1);
|
||||||
|
cairo_pattern_add_color_stop_rgba(grad, 1, r, g, b, 1);
|
||||||
|
cairo_set_source(cr, grad);
|
||||||
|
cairo_fill_preserve(cr);
|
||||||
|
cairo_pattern_destroy(grad);
|
||||||
|
cairo_set_source_rgba(cr, 0, 0, 0, 1);
|
||||||
|
cairo_set_line_width(cr, radius * .01);
|
||||||
|
cairo_stroke(cr);
|
||||||
|
cairo_restore(cr);
|
||||||
|
|
||||||
|
cairo_destroy(cr);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
SchedulablesWidget::on_button_press_event(GdkEventButton* event)
|
||||||
|
{
|
||||||
|
// Not here. Yet.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
// src/schedulables_widget.hh - 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
|
||||||
|
|
||||||
|
#ifndef SCHEDULABLES_WIDGET_HH
|
||||||
|
#define SCHEDULABLES_WIDGET_HH 1
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "backend/history_observer.hh"
|
||||||
|
|
||||||
|
#include <gtkmm/drawingarea.h>
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
class SchedulablesWidget : public Gtk::DrawingArea, public HistoryObserver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SchedulablesWidget();
|
||||||
|
virtual ~SchedulablesWidget();
|
||||||
|
|
||||||
|
void update(const History& history);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void on_size_request(Gtk::Requisition* requisition);
|
||||||
|
virtual bool on_expose_event(GdkEventExpose* event);
|
||||||
|
virtual bool on_button_press_event(GdkEventButton* event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef Gdk::Rectangle area_t;
|
||||||
|
typedef sigc::mem_functor0<void, SchedulablesWidget> method0_t;
|
||||||
|
typedef std::pair<area_t, method0_t> area_callback_t;
|
||||||
|
typedef std::vector<area_callback_t> areas_vect_t;
|
||||||
|
|
||||||
|
cairo_t* _ctx;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //~ namespace sgpem
|
||||||
|
|
||||||
|
|
||||||
|
#endif //~ SCHEDULABLES_WIDGET_HH
|
Loading…
Reference in New Issue