1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or( at your option ) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 * MA 02110-1301, USA. 19 */ 20 21 #include "oxygencairocontext.h" 22 #include <gdk/gdk.h> 23 namespace Oxygen 24 { 25 26 //_________________________________________- Context(GdkWindow * window,GdkRectangle * clipRect)27 Cairo::Context::Context( GdkWindow* window, GdkRectangle* clipRect): 28 _cr( 0L ) 29 { 30 31 if( !GDK_IS_DRAWABLE(window) ) return; 32 _cr= static_cast<cairo_t*>( gdk_cairo_create(window) ); 33 setClipping( clipRect ); 34 35 } 36 37 //_________________________________________- Context(cairo_surface_t * surface,GdkRectangle * clipRect)38 Cairo::Context::Context( cairo_surface_t* surface, GdkRectangle* clipRect): 39 _cr( 0L ) 40 { 41 42 _cr= static_cast<cairo_t*>( cairo_create(surface) ); 43 setClipping( clipRect ); 44 45 } 46 47 //_________________________________________________ free(void)48 void Cairo::Context::free( void ) 49 { 50 if( _cr ) { 51 52 cairo_destroy( _cr ); 53 _cr = 0L; 54 55 } 56 } 57 58 //_________________________________________________ setClipping(GdkRectangle * clipRect) const59 void Cairo::Context::setClipping( GdkRectangle* clipRect ) const 60 { 61 if( !clipRect ) return; 62 cairo_rectangle( _cr, clipRect->x, clipRect->y, clipRect->width, clipRect->height ); 63 cairo_clip( _cr ); 64 } 65 66 } 67