nux-1.14.0
|
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 PAINTER_H 00024 #define PAINTER_H 00025 00026 #include <string> 00027 #include <iostream> 00028 #include <list> 00029 00030 #include "Utils.h" 00031 #include "NuxGraphics/GraphicsEngine.h" 00032 #include "PaintLayer.h" 00033 00034 namespace nux 00035 { 00036 00037 class TextLineRenderer; 00038 class BaseTexture; 00039 00040 class GeometryPositioning 00041 { 00042 public: 00043 GeometryPositioning(); 00044 GeometryPositioning ( 00045 HorizontalAlignment horizontal_aligment, 00046 VerticalAlignment vertical_aligment, 00047 bool stretch_horizontal = FALSE, 00048 bool stretch_vertical = FALSE, 00049 int horizontal_margin = 0, 00050 int vertical_margin = 0); 00051 ~GeometryPositioning(); 00052 00053 bool m_stretch_horizontal; // if TRUE, the content width will be stretched over the width of the container. 00054 bool m_stretch_vertical; // if TRUE, the content height will be stretched over the height of the container. 00055 00056 void SetAlignment (HorizontalAlignment ha, VerticalAlignment va) 00057 { 00058 m_vertical_aligment = va; 00059 m_horizontal_aligment = ha; 00060 } 00061 00062 VerticalAlignment m_vertical_aligment; 00063 HorizontalAlignment m_horizontal_aligment; 00064 00065 int m_horizontal_margin; // Add a margin to the horizontal alignment 00066 int m_vertical_margin; // Add a margin to the vertical alignment 00067 }; 00068 00070 00078 Geometry ComputeGeometryPositioning (const Geometry &container_geo, const Geometry &content_geo, GeometryPositioning gctx); 00079 00081 /* 00082 Class storing the states of User interface controls such button, radio, checkbox, combobox. 00083 */ 00084 class InteractState 00085 { 00086 public: 00087 00088 /* 00089 Default constructor. All states are set to false. 00090 */ 00091 InteractState(); 00092 InteractState (bool on, bool focus, bool prelight, bool disable); 00093 ~InteractState(); 00094 00095 bool is_on; 00096 bool is_focus; 00097 bool is_prelight; 00098 bool is_disable; 00099 }; 00100 00101 00102 00103 00104 // enum PainterBackgroundType 00105 // { 00106 // eColorBackground = 0, 00107 // eShapeBackground, 00108 // eShapeCornerBackground, 00109 // eTextureBackground, 00110 // }; 00111 00112 class TextureAlignmentStyle 00113 { 00114 public: 00115 TextureAlignmentStyle() 00116 { 00117 horz_alignment = eTACenter; 00118 vert_alignment = eTACenter; 00119 horizontal_margin = 0; 00120 vertical_margin = 0; 00121 }; 00122 TextureAlignmentStyle (TextureAlignment horz_align, TextureAlignment vert_align) 00123 { 00124 horz_alignment = horz_align; 00125 vert_alignment = vert_align; 00126 horizontal_margin = 0; 00127 vertical_margin = 0; 00128 }; 00129 00130 ~TextureAlignmentStyle() {}; 00131 00132 enum TextureAlignment horz_alignment; 00133 enum TextureAlignment vert_alignment; 00134 int horizontal_margin; 00135 int vertical_margin; 00136 }; 00137 00138 class BasePainter 00139 { 00140 public: 00141 BasePainter(); 00142 virtual ~BasePainter(); 00143 int intTest; 00144 00146 virtual void Draw2DTexture (GraphicsEngine &GfxContext, BaseTexture *Texture, int x, int y) const; 00147 virtual void Draw2DTextureAligned (GraphicsEngine &GfxContext, BaseTexture *Texture, const Geometry &g, TextureAlignmentStyle tex_align) const; 00148 00150 00152 // TEXT PAINTING // 00154 virtual int PaintColorTextLineEdit (GraphicsEngine &GfxContext, const Geometry &g, const NString &Str, 00155 Color TextColor, 00156 bool WriteAlphaChannel, 00157 Color SelectedTextColor, 00158 Color SelectedTextBackgroundColor, 00159 Color TextBlinkColor, 00160 Color CursorColor, 00161 bool ShowCursor, unsigned int CursorPosition, 00162 int offset = 0, 00163 int selection_start = 0, int selection_end = 0) const; 00164 00165 virtual int PaintTextLineStatic (GraphicsEngine &GfxContext, ObjectPtr<FontTexture> Font, const Geometry &g, 00166 const NString &Str, 00167 const Color &color = Color (0.0f, 0.0f, 0.0f, 1.0f), 00168 bool WriteAlphaChannel = true, 00169 TextAlignment alignment = eAlignTextLeft) const; 00170 00171 void Paint2DQuadColor (GraphicsEngine &GfxContext, const Geometry &g, Color c0) const; 00172 void Paint2DQuadColor (GraphicsEngine &GfxContext, const Geometry &g, Color c0_top_left, Color c1_bottom_left, Color c2_bottom_right, Color c3_top_right) const; 00173 00174 void Paint2DQuadColor (GraphicsEngine &GfxContext, int x, int y, int width, int height, Color c0) const; 00175 void Paint2DQuadColor (GraphicsEngine &GfxContext, int x, int y, int width, int height, Color c0_top_left, Color c1_bottom_left, Color c2_bottom_right, Color c3_top_right) const; 00176 00178 00183 void Paint2DQuadVGradient (GraphicsEngine &GfxContext, const Geometry &g, Color TopColor, Color BottomColor) const; 00185 00190 void Paint2DQuadHGradient (GraphicsEngine &GfxContext, const Geometry &g, Color LeftColor, Color RightColor) const; 00191 00192 void Paint2DQuadWireframe (GraphicsEngine &GfxContext, const Geometry &g, Color c0) const; 00193 void Paint2DQuadWireframe (GraphicsEngine &GfxContext, const Geometry &g, Color c_top_left, Color c_bottom_left, Color c_bottom_right, Color c_top_right) const; 00194 00195 void Paint2DQuadWireframe (GraphicsEngine &GfxContext, int x, int y, int width, int height, Color c0) const; 00196 void Paint2DQuadWireframe (GraphicsEngine &GfxContext, int x, int y, int width, int height, Color c_top_left, Color c_bottom_left, Color c_bottom_right, Color c_top_right) const; 00197 00198 void Draw2DTriangleColor (GraphicsEngine &GfxContext, int x0, int y0, 00199 int x1, int y1, 00200 int x2, int y2, 00201 Color c0); 00202 void Draw2DTriangleColor (GraphicsEngine &GfxContext, int x0, int y0, 00203 int x1, int y1, 00204 int x2, int y2, 00205 Color c0, Color c1, Color c2); 00206 00208 // DRAW LINES // 00210 void Draw2DLine (GraphicsEngine &GfxContext, int x0, int y0, 00211 int x1, int y1, Color c0) const; 00212 void Draw2DLine (GraphicsEngine &GfxContext, int x0, int y0, 00213 int x1, int y1, Color c0, Color c1) const; 00214 00216 // Themes // 00218 void PaintShape (GraphicsEngine &GfxContext, const Geometry &geo, Color c0, UXStyleImageRef style, bool WriteAlpha = true) const; 00219 void PaintShapeCorner (GraphicsEngine &GfxContext, const Geometry &geo, Color c0, UXStyleImageRef style, long corners, bool WriteAlpha = true) const; 00220 void PaintShapeROP (GraphicsEngine &GfxContext, const Geometry &geo, Color c0, UXStyleImageRef style, bool WriteAlpha = true, 00221 const ROPConfig &ROP = ROPConfig::Default) const; 00222 void PaintShapeCornerROP (GraphicsEngine &GfxContext, const Geometry &geo, Color c0, UXStyleImageRef style, long corners, bool WriteAlpha = true, 00223 const ROPConfig &ROP = ROPConfig::Default) const; 00224 00225 void PaintTextureShape (GraphicsEngine &GfxContext, const Geometry &geo, UXStyleImageRef style) const; 00226 void PaintTextureShape (GraphicsEngine &GfxContext, const Geometry &geo, BaseTexture *Texture, 00227 int border_left, int border_right, int border_top, int border_bottom, bool draw_borders_only, bool premultiply = true) const; 00228 00230 00234 void PaintCheckBox (GraphicsEngine &GfxContext, const Geometry &geo, const InteractState &interaction_state, 00235 Color check_mark_color = Color (0x0), Color check_box_color = Color (0x0) ); 00236 00237 void PaintRadioButton (GraphicsEngine &GfxContext, const Geometry &geo, const InteractState &interaction_state, 00238 Color check_mark_color = Color (0x0), Color check_box_color = Color (0x0) ); 00239 00240 void PaintHorizontalGradientQuad (GraphicsEngine &GfxContext, const Geometry &geo, int num_color, float *percentage_array, Color *color_array); 00241 00242 public: 00243 void PushColorLayer (GraphicsEngine &GfxContext, const Geometry &geo, 00244 Color color, 00245 bool WriteAlpha = false, 00246 const ROPConfig &ROP = ROPConfig::Default); 00247 00248 void PushShapeLayer (GraphicsEngine &GfxContext, Geometry geo, 00249 UXStyleImageRef imageStyle, 00250 const Color &color, 00251 unsigned long Corners = eAllCorners, 00252 bool WriteAlpha = false, 00253 const ROPConfig &ROP = ROPConfig::Default); 00254 00255 void PushSliceScaledTextureLayer (GraphicsEngine &GfxContext, Geometry geo, 00256 UXStyleImageRef imageStyle, 00257 const Color &color, 00258 unsigned long Corners = eAllCorners, 00259 bool WriteAlpha = false, 00260 const ROPConfig &ROP = ROPConfig::Default); 00261 00262 void PushTextureLayer (GraphicsEngine &GfxContext, Geometry geo, 00263 ObjectPtr<IOpenGLBaseTexture> DeviceTexture, 00264 TexCoordXForm texxform, 00265 const Color &color, 00266 bool WriteAlpha = false, 00267 const ROPConfig &ROP = ROPConfig::Default); 00268 00269 void PushDrawColorLayer (GraphicsEngine &GfxContext, const Geometry &geo, 00270 Color color, 00271 bool WriteAlpha = false, 00272 const ROPConfig &ROP = ROPConfig::Default); 00273 00274 void PushDrawShapeLayer (GraphicsEngine &GfxContext, Geometry geo, 00275 UXStyleImageRef imageStyle, 00276 const Color &color, 00277 unsigned long Corners = eAllCorners, 00278 bool WriteAlpha = false, 00279 const ROPConfig &ROP = ROPConfig::Default); 00280 00281 void PushDrawSliceScaledTextureLayer (GraphicsEngine &GfxContext, Geometry geo, 00282 UXStyleImageRef imageStyle, 00283 const Color &color, 00284 unsigned long Corners = eAllCorners, 00285 bool WriteAlpha = false, 00286 const ROPConfig &ROP = ROPConfig::Default); 00287 00288 void PushDrawTextureLayer (GraphicsEngine &GfxContext, Geometry geo, 00289 ObjectPtr<IOpenGLBaseTexture> DeviceTexture, 00290 TexCoordXForm texxform, 00291 const Color &color, 00292 bool WriteAlpha = false, 00293 const ROPConfig &ROP = ROPConfig::Default); 00294 00295 void PushLayer (GraphicsEngine &GfxContext, const Geometry &geo, AbstractPaintLayer *layer); 00296 void PushDrawLayer (GraphicsEngine &GfxContext, const Geometry &geo, AbstractPaintLayer *layer); 00297 00299 00302 void RenderSinglePaintLayer (GraphicsEngine &GfxContext, Geometry geo, AbstractPaintLayer *paint_layer); 00303 00305 00308 void PopBackground (int level = 1); 00309 void EmptyBackgroundStack(); 00310 void PaintBackground (GraphicsEngine &GfxContext, const Geometry &geo); 00311 00312 void PushBackgroundStack(); 00313 void PopBackgroundStack(); 00314 00315 private: 00316 00317 std::list<AbstractPaintLayer*> m_BackgroundStack; 00318 00319 }; 00320 00321 00322 class PushBackgroundScope 00323 { 00324 public: 00325 PushBackgroundScope (BasePainter &painter, GraphicsEngine &GfxContext, const Geometry &geo, UXStyleImageRef image_style, bool PushAndDraw = false) 00326 : m_painter (painter) 00327 { 00328 if (PushAndDraw) 00329 m_painter.PushDrawShapeLayer (GfxContext, geo, image_style, color::White, eAllCorners); 00330 else 00331 m_painter.PushShapeLayer (GfxContext, geo, image_style, color::White, eAllCorners); 00332 } 00333 00334 ~PushBackgroundScope() 00335 { 00336 //m_painter.PopBackground(); 00337 } 00338 00339 private: 00340 BasePainter &m_painter; 00341 }; 00342 00343 class PushShapeBackgroundScope 00344 { 00345 public: 00346 PushShapeBackgroundScope (BasePainter &painter, GraphicsEngine &GfxContext, const Geometry &geo, UXStyleImageRef image_style, const Color &color, bool PushAndDraw = false, bool WriteAlpha = false, const ROPConfig &ROP = ROPConfig::Default) 00347 : m_painter (painter) 00348 { 00349 if (PushAndDraw) 00350 m_painter.PushDrawShapeLayer (GfxContext, geo, image_style, color, eAllCorners, WriteAlpha, ROP); 00351 else 00352 m_painter.PushShapeLayer (GfxContext, geo, image_style, color, eAllCorners, WriteAlpha, ROP); 00353 } 00354 ~PushShapeBackgroundScope() 00355 { 00356 m_painter.PopBackground(); 00357 } 00358 private: 00359 BasePainter &m_painter; 00360 }; 00361 00362 class PushShapeCornerBackgroundScope 00363 { 00364 public: 00365 PushShapeCornerBackgroundScope (BasePainter &painter, GraphicsEngine &GfxContext, const Geometry &geo, UXStyleImageRef image_style, const Color &color, long corners, bool PushAndDraw = false, bool WriteAlpha = false, const ROPConfig &ROP = ROPConfig::Default) 00366 : m_painter (painter) 00367 { 00368 if (PushAndDraw) 00369 m_painter.PushDrawShapeLayer (GfxContext, geo, image_style, color, corners, WriteAlpha, ROP); 00370 else 00371 m_painter.PushShapeLayer (GfxContext, geo, image_style, color, corners, WriteAlpha, ROP); 00372 } 00373 ~PushShapeCornerBackgroundScope() 00374 { 00375 m_painter.PopBackground(); 00376 } 00377 private: 00378 BasePainter &m_painter; 00379 }; 00380 00381 class PushColorBackgroundScope 00382 { 00383 public: 00384 PushColorBackgroundScope (BasePainter &painter, GraphicsEngine &GfxContext, const Geometry &geo, const Color &color, bool PushAndDraw = false, bool WriteAlpha = false, const ROPConfig &ROP = ROPConfig::Default) 00385 : m_painter (painter) 00386 { 00387 if (PushAndDraw) 00388 m_painter.PushDrawColorLayer (GfxContext, geo, color, WriteAlpha, ROP); 00389 else 00390 m_painter.PushColorLayer (GfxContext, geo, color, WriteAlpha, ROP); 00391 } 00392 00393 ~PushColorBackgroundScope() 00394 { 00395 m_painter.PopBackground(); 00396 } 00397 private: 00398 BasePainter &m_painter; 00399 }; 00400 00401 00402 } 00403 00404 #endif // PAINTER_H