File indexing completed on 2024-04-28 05:32:10

0001 #ifndef oxygencairoutils_h
0002 #define oxygencairoutils_h
0003 /*
0004 * this file is part of the oxygen gtk engine
0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 *
0007 * SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #include "oxygencairopattern.h"
0011 #include "oxygenflags.h"
0012 #include "oxygengeometry.h"
0013 #include "oxygenrgba.h"
0014 
0015 #include <cairo.h>
0016 #include <gdk/gdk.h>
0017 #include <vector>
0018 
0019 namespace Oxygen
0020 {
0021 
0022     //! draw arc with the parameters similar to those of QPainter::drawArc() (but using diameter instead of width&height). Also, angles are specified in degrees, not in 16ths of degrees
0023     void cairo_arc_qt( cairo_t*, double, double, double, double, double );
0024 
0025     //! convenience class for cairo pattern color stops
0026     class ColorStop
0027     {
0028         public:
0029 
0030         //! empty constructor
0031         ColorStop( double x = 0, ColorUtils::Rgba color = ColorUtils::Rgba() ):
0032             _x( x ),
0033             _color( color )
0034         {}
0035 
0036         //! offset
0037         double _x;
0038 
0039         //! color
0040         ColorUtils::Rgba _color;
0041 
0042         typedef std::vector<ColorStop> List;
0043 
0044     };
0045 
0046     //!@name color handling
0047     //@{
0048 
0049     //! add color to pattern
0050     void cairo_pattern_add_color_stop( cairo_pattern_t*, double, const ColorUtils::Rgba& );
0051 
0052     //! add color to pattern
0053     inline void cairo_pattern_add_color_stop( cairo_pattern_t* pattern, const ColorStop& colorStop )
0054     { Oxygen::cairo_pattern_add_color_stop( pattern, colorStop._x, colorStop._color ); }
0055 
0056     //! get color stops
0057     ColorStop::List cairo_pattern_get_color_stops( cairo_pattern_t* );
0058 
0059     //! set source from pattern
0060     inline void cairo_set_source( cairo_t* context, const Cairo::Pattern& pattern )
0061     { ::cairo_set_source( context, (cairo_pattern_t*)( pattern ) ); }
0062 
0063     //! set source from color
0064     void cairo_set_source( cairo_t*, const ColorUtils::Rgba& );
0065 
0066     //@}
0067 
0068     //!@name patterns
0069     //@{
0070 
0071     inline cairo_pattern_t* cairo_pattern_create_radial( double x, double y, double r )
0072     { return ::cairo_pattern_create_radial( x, y, 0, x, y, r ); }
0073 
0074     //@}
0075 
0076     //!@name path
0077     //@{
0078 
0079     enum Corner
0080     {
0081         CornersNone = 0,
0082         CornersTopLeft = 1<<0,
0083         CornersTopRight = 1<<1,
0084         CornersBottomLeft = 1<<2,
0085         CornersBottomRight = 1<<3,
0086         CornersTop = CornersTopLeft|CornersTopRight,
0087         CornersBottom = CornersBottomLeft|CornersBottomRight,
0088         CornersLeft = CornersTopLeft|CornersBottomLeft,
0089         CornersRight = CornersTopRight|CornersBottomRight,
0090         CornersAll = CornersTop|CornersBottom
0091     };
0092 
0093     OX_DECLARE_FLAGS( Corners, Corner );
0094     OX_DECLARE_OPERATORS_FOR_FLAGS( Corners );
0095 
0096     //! rounded rectangle
0097     void cairo_rounded_rectangle( cairo_t*, double x, double y, double width, double height, double radius, Corners corners = CornersAll );
0098 
0099     //! rounded rectangle
0100     void cairo_rounded_rectangle_negative( cairo_t*, double x, double y, double width, double height, double radius, Corners corners = CornersAll );
0101 
0102     //! negative rectangle
0103     void cairo_rectangle_negative( cairo_t*, double x, double y, double width, double height );
0104 
0105     //! ellipse
0106     void cairo_ellipse( cairo_t*, double x, double y, double width, double height );
0107 
0108     //! ellipse
0109     void cairo_ellipse_negative( cairo_t*, double x, double y, double width, double height );
0110 
0111     //! polygon
0112     void cairo_polygon( cairo_t*, const Polygon& );
0113 
0114     //@}
0115 
0116     //!@name gdk path
0117     //@{
0118     //! rounded rectangle
0119     inline void gdk_cairo_rounded_rectangle( cairo_t* context, GdkRectangle* rect, double radius, Corners corners = CornersAll )
0120     { cairo_rounded_rectangle( context, rect->x, rect->y, rect->width, rect->height, radius, corners ); }
0121 
0122     //! rounded rectangle
0123     inline void gdk_cairo_rounded_rectangle_negative( cairo_t* context, GdkRectangle* rect, double radius, Corners corners = CornersAll )
0124     { cairo_rounded_rectangle_negative( context, rect->x, rect->y, rect->width, rect->height, radius, corners ); }
0125 
0126     //! ellipse
0127     inline void gdk_cairo_ellipse( cairo_t* context, GdkRectangle* rect )
0128     { cairo_ellipse( context, rect->x, rect->y, rect->width, rect->height ); }
0129 
0130     //! ellipse
0131     inline void gdk_cairo_ellipse_negative( cairo_t* context, GdkRectangle* rect )
0132     { cairo_ellipse_negative( context, rect->x, rect->y, rect->width, rect->height ); }
0133 
0134     //@}
0135 
0136     //!@name surfaces
0137     //@{
0138 
0139     //! get width for surface
0140     int cairo_surface_get_width( cairo_surface_t* );
0141 
0142     //! get height for surface
0143     int cairo_surface_get_height( cairo_surface_t* );
0144 
0145     //! get size for surface
0146     void cairo_surface_get_size( cairo_surface_t*, int& width, int& height );
0147 
0148     //! deep copy
0149     cairo_surface_t* cairo_surface_copy( cairo_surface_t* );
0150 
0151     //! alpha channel
0152     void cairo_surface_add_alpha( cairo_surface_t*, double );
0153 
0154     //! saturation
0155     /*! Inspired from gdk-pixbuf-util.c
0156     Copyright (C) 1999 The Free Software Foundation
0157     Authors: Federico Mena-Quintero <federico@gimp.org>
0158              Cody Russell  <bratsche@gnome.org>
0159     */
0160     void cairo_image_surface_saturate( cairo_surface_t*, double );
0161 
0162     //@}
0163 
0164 }
0165 
0166 #endif