From 09268f7fd418131352eb21d3b93951b0bb0a84f5 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Wed, 12 Jul 2006 09:24:57 +0000 Subject: [PATCH] - 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 --- Makefile.am | 2 + src/gui_builder.cc | 10 +++ src/schedulables_widget.cc | 128 +++++++++++++++++++++++++++++++++++++ src/schedulables_widget.hh | 57 +++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 src/schedulables_widget.cc create mode 100644 src/schedulables_widget.hh diff --git a/Makefile.am b/Makefile.am index 2a4bc76..23d2a5b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -269,6 +269,7 @@ sgpemv2_SOURCES = \ src/main_window.cc \ src/observer.cc \ src/parse_opts.cc \ + src/schedulables_widget.cc \ src/simulation.cc \ src/standard_io.cc \ src/text_simulation.cc @@ -282,6 +283,7 @@ noinst_HEADERS += \ src/main_window.hh \ src/observer.hh \ src/parse_opts.hh \ + src/schedulables_widget.hh \ src/simulation.hh \ src/standard_io.hh \ src/text_simulation.hh diff --git a/src/gui_builder.cc b/src/gui_builder.cc index 57e0704..1461414 100644 --- a/src/gui_builder.cc +++ b/src/gui_builder.cc @@ -21,10 +21,12 @@ #include "config.h" #include "gettext.h" +#include "schedulables_widget.hh" #include "gui_builder.hh" #include #include +#include #include #include @@ -54,6 +56,14 @@ GuiBuilder::GuiBuilder(const std::string& gladefile) AboutDialog* about_dialog = NULL; _refXml->get_widget("AboutDialog", about_dialog); 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(); } diff --git a/src/schedulables_widget.cc b/src/schedulables_widget.cc new file mode 100644 index 0000000..636939c --- /dev/null +++ b/src/schedulables_widget.cc @@ -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 + +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 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; +} + diff --git a/src/schedulables_widget.hh b/src/schedulables_widget.hh new file mode 100644 index 0000000..71244db --- /dev/null +++ b/src/schedulables_widget.hh @@ -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 + +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 method0_t; + typedef std::pair area_callback_t; + typedef std::vector areas_vect_t; + + cairo_t* _ctx; + }; + +} //~ namespace sgpem + + +#endif //~ SCHEDULABLES_WIDGET_HH