nux-0.9.46

NuxImage/CairoGraphics.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef CAIROGRAPHICS_H
00024 #define CAIROGRAPHICS_H
00025 
00026 #include "cairo/cairo.h"
00027 #include "BitmapFormats.h"
00028 #include "ImageSurface.h"
00029 
00030 #include <stack>
00031 
00032 namespace nux
00033 {
00034 
00035 
00037 
00040   class CairoGraphics
00041   {
00042   public:
00043     CairoGraphics (cairo_format_t format, int width, int height);
00044     ~CairoGraphics();
00045 
00047 
00051     cairo_t *GetContext ();
00052 
00054 
00058     cairo_t *GetInternalContext ();
00059 
00060     cairo_surface_t* GetSurface ();
00062 
00066     NBitmapData *GetBitmap();
00067 
00068     int GetWidth () const;
00069     int GetHeight () const;
00070 
00071     bool PushState ();
00072     bool PopState ();
00073 
00074     bool ClearCanvas();
00075 
00076     bool ClearRect(double x, double y, double w, double h);
00077 
00078     bool DrawLine(double x0, double y0, double x1, double y1, double width, const Color &c);
00079 
00080     bool DrawFilledRect(double x, double y, double w, double h, const Color &c);
00081 
00082     bool DrawCanvas(double x, double y, CairoGraphics *cg);
00083 
00084     bool DrawRoundedRectangle (cairo_t* cr,
00085                                double   aspect,
00086                                double   x,
00087                                double   y,
00088                                double   cornerRadius,
00089                                double   width,
00090                                double   height,
00091                                bool     align = false);
00092 
00093     bool BlurSurface (unsigned int radius, cairo_surface_t* surf = NULL);
00094 
00095     bool IntersectRectClipRegion(double x, double y, double w, double h);
00096 
00097     bool IntersectGeneralClipRegion(std::list<Rect> &region);
00098 
00102   enum Alignment {
00103     ALIGN_LEFT,
00104     ALIGN_CENTER,
00105     ALIGN_RIGHT,
00106     ALIGN_JUSTIFY
00107   };
00108 
00112   enum VAlignment {
00113     VALIGN_TOP,
00114     VALIGN_MIDDLE,
00115     VALIGN_BOTTOM
00116   };
00117 
00121   enum Trimming {
00122     TRIMMING_NONE,
00123     TRIMMING_CHARACTER,
00124     TRIMMING_WORD,
00125     TRIMMING_CHARACTER_ELLIPSIS,
00126     TRIMMING_WORD_ELLIPSIS,
00127     TRIMMING_PATH_ELLIPSIS
00128   };
00129 
00133   enum TextFlag {
00134     TEXT_FLAGS_NONE = 0,
00135     TEXT_FLAGS_UNDERLINE = 1,
00136     TEXT_FLAGS_STRIKEOUT = 2,
00137     TEXT_FLAGS_WORDWRAP = 4
00138   };
00139 
00140   private:
00142     cairo_format_t m_surface_format;
00144     cairo_surface_t *_cairo_surface;
00145 
00146     cairo_t * _cr;
00147     int _width; 
00148     int _height; 
00149 
00150     double _zoom;
00151     float _opacity;
00152     std::stack<float> _opacity_stack;
00153   };
00154 
00155 }
00156 
00157 #endif // CAIROGRAPHICS_H
00158