Rapicorn - Experimental UI Toolkit - Source Code 10.08.1
cairocontext.hh
Go to the documentation of this file.
00001 /* Rapicorn
00002  * Copyright (C) 2006 Tim Janik
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * A copy of the GNU Lesser General Public License should ship along
00015  * with this library; if not, see http://www.gnu.org/copyleft/.
00016  */
00017 #ifndef __RAPICORN_CAIRO_CONTEXT_HH__
00018 #define __RAPICORN_CAIRO_CONTEXT_HH__
00019 
00020 #include <ui/painter.hh>
00021 #include <ui/primitives.hh>
00022 
00023 namespace Rapicorn {
00024 
00025 class CairoContext {
00026 #ifndef CAIRO_H
00027   typedef struct _cairo cairo_t;
00028 #endif
00029   void          set_cairo               (cairo_t *n_cr);
00030 protected:
00031   cairo_t      *cr;
00032   explicit      CairoContext            ();
00033 public:
00034   virtual      ~CairoContext            ();
00035   /* enums & constants */
00036   typedef enum {
00037     CAIRO_ANTIALIAS_NONE,
00038     CAIRO_ANTIALIAS_DEFAULT,
00039     CAIRO_ANTIALIAS_GRAY,
00040     CAIRO_ANTIALIAS_SUBPIXEL,
00041     NONE                        = CAIRO_ANTIALIAS_NONE,
00042     DEFAULT                     = CAIRO_ANTIALIAS_NONE,
00043     GRAY                        = CAIRO_ANTIALIAS_GRAY,
00044     SUBPIXEL                    = CAIRO_ANTIALIAS_SUBPIXEL,
00045   } Antialias;
00046   typedef enum {
00047     CAIRO_FILL_RULE_WINDING,
00048     CAIRO_FILL_RULE_EVEN_ODD,
00049     WINDING                     = CAIRO_FILL_RULE_WINDING,
00050     EVEN_ODD                    = CAIRO_FILL_RULE_EVEN_ODD,
00051   } FillRule;
00052   typedef enum {
00053     CAIRO_LINE_CAP_BUTT,
00054     CAIRO_LINE_CAP_ROUND,
00055     CAIRO_LINE_CAP_SQUARE,
00056     BUTT                        = CAIRO_LINE_CAP_BUTT,
00057     // ROUND                    = CAIRO_LINE_CAP_ROUND,
00058     SQUARE                      = CAIRO_LINE_CAP_SQUARE,
00059   } LineCap;
00060   typedef enum {
00061     CAIRO_LINE_JOIN_MITER,
00062     CAIRO_LINE_JOIN_ROUND,
00063     CAIRO_LINE_JOIN_BEVEL,
00064     MITER                       = CAIRO_LINE_JOIN_MITER,
00065     // ROUND                    = CAIRO_LINE_JOIN_ROUND,
00066     BEVEL                       = CAIRO_LINE_JOIN_BEVEL,
00067   } LineJoin;
00068   typedef enum { ROUND } _Round; /* conflicting enums */
00069   void          save                    ();
00070   void          restore                 ();
00071   void          set_tolerance           (double    tolerance);
00072   void          set_antialias           (Antialias antialias = CAIRO_ANTIALIAS_DEFAULT);
00073   void          set_fill_rule           (FillRule  fill_rule);
00074   void          set_line_width          (double    width);
00075   void          set_line_cap            (LineCap   line_cap);
00076   void          set_line_cap            (_Round    round)       { set_line_cap (CAIRO_LINE_CAP_ROUND); }
00077   void          set_line_join           (LineJoin  line_join);
00078   void          set_line_join           (_Round    round)       { set_line_join (CAIRO_LINE_JOIN_ROUND); }
00079   void          set_miter_limit         (double    limit);
00080   void          set_dash                (double   *dashes,
00081                                          int       num_dashes,
00082                                          double    offset);
00083   void          set_source_color        (Color     color);
00084   void          translate               (double x,  double y);
00085   void          new_path                ();
00086   void          move_to                 (double x,  double y);
00087   void          line_to                 (double x,  double y);
00088   void          rel_move_to             (double x,  double y);
00089   void          rel_line_to             (double x,  double y);
00090   void          rectangle               (double x, double y, double width, double height);
00091   void          curve_to                (double x1, double y1,
00092                                          double x2, double y2,
00093                                          double x3, double y3);
00094   void          arc                     (double xc, double yc, double radius,
00095                                          double angle1, double angle2);
00096   void          arc_negative            (double xc, double yc, double radius,
00097                                          double angle1, double angle2);
00098   void          close_path              ();
00099   void          paint                   ();
00100   void          stroke                  ();
00101   void          stroke_preserve         ();
00102   void          fill                    ();
00103   void          fill_preserve           ();
00104   static CairoContext*
00105   cairo_context_from_plane (Plane &plane);
00106 };
00107 
00108 class CairoPainter : virtual public Painter {
00109   CairoContext &cc;
00110 public:
00111   explicit      CairoPainter            (Plane &plane);
00112   virtual       ~CairoPainter           ();
00113   void          draw_arrow              (double x, double y, double width, double height, Color c, double angle);
00114   void          draw_dir_arrow          (double x, double y, double width, double height, Color c, DirType dir);
00115   void          draw_dot                (double x, double y, double width, double height, Color c1, Color c2, FrameType frame);
00116 };
00117 
00118 } // Rapicorn
00119 
00120 #endif  /* __RAPICORN_CAIRO_CONTEXT_HH__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines