/* gtkmm example Copyright (C) 2011 gtkmm development team * * This program 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. * * This program 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 this program; if not, see . */ #include "myarea.h" #include #include #include // set_source_pixbuf() #include #include MyArea::MyArea() { try { // The fractal image has been created by the XaoS program. // http://xaos.sourceforge.net m_image = Gdk::Pixbuf::create_from_resource("/image/fractal_image.png"); } catch(const Gio::ResourceError& ex) { std::cerr << "ResourceError: " << ex.what() << std::endl; } catch(const Gdk::PixbufError& ex) { std::cerr << "PixbufError: " << ex.what() << std::endl; } // Show at least a quarter of the image. if (m_image) { set_content_width(m_image->get_width()/2); set_content_height(m_image->get_height()/2); } // Set the draw function. set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw)); } MyArea::~MyArea() { } void MyArea::on_draw(const Cairo::RefPtr& cr, int width, int height) { if (!m_image) return; // Draw the image in the middle of the drawing area, or (if the image is // larger than the drawing area) draw the middle part of the image. Gdk::Cairo::set_source_pixbuf(cr, m_image, (width - m_image->get_width())/2, (height - m_image->get_height())/2); cr->paint(); }