// src/cairo_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 CAIRO_WIDGET_HH #define CAIRO_WIDGET_HH 1 #include "config.h" #include #include #include namespace sgpem { class CairoWidget : public Gtk::Widget { public: enum scaling_mode { scaling_none = 0, // without any scaling scaling_to_w = 1 << 0, // uses width to calculate scale factor scaling_to_h = 1 << 1, // uses height to calculate scale factor scaling_min = 1 << 2, // uses minimum scale factor from width, height scaling_max = 1 << 3, // uses maximum scale factor from width, height scaling_all = 1 << 4 // scale to stretch into client area }; CairoWidget(); virtual ~CairoWidget(); scaling_mode set_scaling_mode(scaling_mode scaling_mode); scaling_mode get_scaling_mode(); void change_scaling_mode(); protected: typedef unsigned int size_t; virtual void on_realize(); virtual void on_size_allocate(const Gtk::Allocation& allocation); virtual void on_size_request(Gtk::Requisition* request); virtual bool on_expose_event(GdkEventExpose* event); virtual bool on_button_press_event(GdkEventButton* event); // in this method the implemented widget must "do the things" virtual void draw_widget(cairo_t* ctx) = 0; // with this method CairoWidget the needed drawing dimensions virtual void calc_size(size_t& width, size_t& height) const = 0; void redraw(); typedef Gdk::Rectangle area_t; typedef sigc::mem_functor0 method0_t; typedef std::pair area_callback_t; typedef std::vector areas_vect_t; private: // The width and height the widget will assume, must be determined // before starting drawing by calc_size() mutable size_t _draw_w; mutable size_t _draw_h; mutable size_t _client_w; mutable size_t _client_h; mutable size_t _pixmap_w; mutable size_t _pixmap_h; mutable bool _need_redraw; scaling_mode _scaling_mode; // The offscreen pixmap we use for double-buffering Glib::RefPtr _buf; }; } //~ namespace sgpem #endif //~ CAIRO_WIDGET_HH