nux-1.16.0
|
00001 /* 00002 * Copyright 2010, 2011 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 class CairoFontOptions 00035 { 00036 public: 00037 CairoFontOptions() 00038 : font_options_(::cairo_font_options_create()) 00039 {} 00040 00041 ~CairoFontOptions() 00042 { 00043 ::cairo_font_options_destroy(font_options_); 00044 } 00045 00046 operator cairo_font_options_t*() 00047 { 00048 return font_options_; 00049 } 00050 00051 private: 00052 cairo_font_options_t* font_options_; 00053 }; 00054 00055 00057 00060 class CairoGraphics 00061 { 00062 public: 00063 CairoGraphics (cairo_format_t format, int width, int height); 00064 ~CairoGraphics(); 00065 00067 00071 cairo_t *GetContext (); 00072 00074 00078 cairo_t *GetInternalContext (); 00079 00080 cairo_surface_t* GetSurface (); 00082 00086 NBitmapData *GetBitmap(); 00087 00088 int GetWidth () const; 00089 int GetHeight () const; 00090 00091 bool PushState (); 00092 bool PopState (); 00093 00094 bool ClearCanvas(); 00095 00096 bool ClearRect(double x, double y, double w, double h); 00097 00098 bool DrawLine(double x0, double y0, double x1, double y1, double width, const Color &c); 00099 00100 bool DrawFilledRect(double x, double y, double w, double h, const Color &c); 00101 00102 bool DrawCanvas(double x, double y, CairoGraphics *cg); 00103 00104 bool DrawRoundedRectangle (cairo_t* cr, 00105 double aspect, 00106 double x, 00107 double y, 00108 double cornerRadius, 00109 double width, 00110 double height, 00111 bool align = false); 00112 00113 bool BlurSurface (unsigned int radius, cairo_surface_t* surf = NULL); 00114 00115 bool IntersectRectClipRegion(double x, double y, double w, double h); 00116 00117 bool IntersectGeneralClipRegion(std::list<Rect> ®ion); 00118 00122 enum Alignment { 00123 ALIGN_LEFT, 00124 ALIGN_CENTER, 00125 ALIGN_RIGHT, 00126 ALIGN_JUSTIFY 00127 }; 00128 00132 enum VAlignment { 00133 VALIGN_TOP, 00134 VALIGN_MIDDLE, 00135 VALIGN_BOTTOM 00136 }; 00137 00141 enum Trimming { 00142 TRIMMING_NONE, 00143 TRIMMING_CHARACTER, 00144 TRIMMING_WORD, 00145 TRIMMING_CHARACTER_ELLIPSIS, 00146 TRIMMING_WORD_ELLIPSIS, 00147 TRIMMING_PATH_ELLIPSIS 00148 }; 00149 00153 enum TextFlag { 00154 TEXT_FLAGS_NONE = 0, 00155 TEXT_FLAGS_UNDERLINE = 1, 00156 TEXT_FLAGS_STRIKEOUT = 2, 00157 TEXT_FLAGS_WORDWRAP = 4 00158 }; 00159 00160 private: 00162 cairo_format_t m_surface_format; 00164 cairo_surface_t *_cairo_surface; 00165 00166 cairo_t * _cr; 00167 int _width; 00168 int _height; 00169 00170 double _zoom; 00171 float _opacity; 00172 std::stack<float> _opacity_stack; 00173 }; 00174 00175 } 00176 00177 #endif // CAIROGRAPHICS_H 00178