Back to index

nux  3.0.0
Painter.cpp
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 #include "Nux.h"
00024 #include "InputArea.h"
00025 #include "Painter.h"
00026 
00027 #include "NuxGraphics/GLTextureResourceManager.h"
00028 
00029 namespace nux
00030 {
00031 
00032   const unsigned int  STENCIL_TEST_REF = 0xFF;
00033   const unsigned int  STENCIL_TEST_MASK = 0xFFFFFFFF;
00034   const unsigned int  STENCIL_CLEAR = 0x0;
00035   const float         ALPHA_TEST_REF = 0.0f;
00036 
00037   GeometryPositioning::GeometryPositioning()
00038   {
00039     m_stretch_horizontal = true;
00040     m_stretch_vertical = true;
00041 
00042     m_vertical_aligment = eVACenter;
00043     m_horizontal_aligment = eHACenter;
00044 
00045     m_horizontal_margin = 0;
00046     m_vertical_margin = 0;
00047   }
00048 
00049   GeometryPositioning::GeometryPositioning(
00050     HorizontalAlignment horizontal_aligment,
00051     VerticalAlignment vertical_aligment,
00052     bool stretch_horizontal,
00053     bool stretch_vertical,
00054     int horizontal_margin,
00055     int vertical_margin)
00056   {
00057     m_stretch_horizontal = stretch_horizontal;
00058     m_stretch_vertical = stretch_vertical;
00059 
00060     m_vertical_aligment = eVACenter;
00061     m_horizontal_aligment = eHACenter;
00062 
00063     m_horizontal_margin = horizontal_margin;
00064     m_vertical_margin = vertical_margin;
00065   }
00066 
00067   GeometryPositioning::~GeometryPositioning()
00068   {
00069 
00070   }
00071 
00072   Geometry ComputeGeometryPositioning(const Geometry &container_geo, const Geometry &content_geo, GeometryPositioning gctx)
00073   {
00074     int x_pos, y_pos;
00075     int w, h;
00076 
00077     if (gctx.m_stretch_horizontal)
00078     {
00079       w = container_geo.GetWidth() - 2 * gctx.m_horizontal_margin;
00080     }
00081     else
00082     {
00083       w = content_geo.GetWidth();
00084     }
00085 
00086     if (gctx.m_stretch_horizontal)
00087     {
00088       h = container_geo.GetHeight() - 2 * gctx.m_vertical_margin;
00089     }
00090     else
00091     {
00092       h = content_geo.GetHeight();
00093     }
00094 
00095     if (gctx.m_horizontal_aligment == eHACenter)
00096     {
00097       int offset = (container_geo.GetWidth() - w) / 2.0f;
00098       //offset = (offset < 0) ? 0 : offset;
00099       x_pos = container_geo.x + offset;
00100     }
00101     else if (gctx.m_horizontal_aligment == eHALeft)
00102     {
00103       x_pos = container_geo.x + gctx.m_horizontal_margin;
00104 
00105       if (x_pos > container_geo.x + container_geo.GetWidth())
00106         x_pos = container_geo.x;
00107     }
00108     else if (gctx.m_horizontal_aligment == eHARight)
00109     {
00110       x_pos = container_geo.x + container_geo.GetWidth() - w - gctx.m_horizontal_margin;
00111 
00112       if (x_pos < container_geo.x)
00113         x_pos = container_geo.x;
00114     }
00115     else
00116     {
00117       x_pos = container_geo.x + gctx.m_horizontal_margin;
00118     }
00119 
00120     if (gctx.m_vertical_aligment == eVACenter)
00121     {
00122       int offset = (container_geo.GetHeight() - h) / 2.0f;
00123       //offset = (offset < 0) ? 0 : offset;
00124       y_pos = container_geo.y + offset;
00125     }
00126     else if (gctx.m_vertical_aligment == eVATop)
00127     {
00128       y_pos = container_geo.y + gctx.m_vertical_margin;
00129 
00130       if (y_pos > container_geo.y + container_geo.GetHeight())
00131         y_pos = container_geo.y;
00132     }
00133     else if (gctx.m_vertical_aligment == eVABottom)
00134     {
00135       y_pos = container_geo.y + container_geo.GetHeight() - h - gctx.m_vertical_margin;
00136 
00137       if (y_pos < container_geo.y)
00138         y_pos = container_geo.y;
00139     }
00140     else
00141     {
00142       y_pos = container_geo.y + gctx.m_vertical_margin;
00143     }
00144 
00145     return Geometry(x_pos, y_pos, w, h);
00146   }
00147 
00148   InteractState::InteractState()
00149   {
00150     is_on = false;
00151     is_focus = false;
00152     is_prelight = false;
00153     is_disable = false;
00154   }
00155 
00156   InteractState::InteractState(bool on, bool focus, bool prelight, bool disable)
00157   {
00158     is_on = on;
00159     is_focus = focus;
00160     is_prelight = prelight;
00161     is_disable = disable;
00162   }
00163 
00164   InteractState::~InteractState()
00165   {
00166 
00167   }
00168 
00169   BasePainter::BasePainter(WindowThread *window_thread)
00170   : window_thread_(window_thread)
00171   {
00172   }
00173 
00174   BasePainter::~BasePainter()
00175   {
00176     EmptyBackgroundStack();
00177   }
00178 
00179   int BasePainter::PaintColorTextLineEdit(GraphicsEngine &graphics_engine, const Geometry &g, const NString &Str,
00180       Color TextColor,
00181       bool WriteAlphaChannel,
00182       Color SelectedTextColor,
00183       Color SelectedTextBackgroundColor,
00184       Color TextBlinkColor,
00185       Color CursorColor,
00186       bool ShowCursor, unsigned int CursorPosition,
00187       int offset,
00188       int selection_start, int selection_end) const
00189   {
00190     PageBBox page;
00191     page.xmin = g.x;
00192     page.xmax = g.x + g.GetWidth();
00193     page.ymin = g.y;
00194     page.ymax = g.y + g.GetHeight();
00195     page.x_margin = DEFAULT_TEXT_X_MARGIN;
00196     page.y_margin = DEFAULT_TEXT_Y_MARGIN;
00197     return graphics_engine.RenderColorTextLineEdit(GetSysFont(), page, Str,
00198            TextColor,
00199            WriteAlphaChannel,
00200            SelectedTextColor,
00201            SelectedTextBackgroundColor,
00202            TextBlinkColor,
00203            CursorColor,
00204            ShowCursor, CursorPosition, offset, selection_start, selection_end);
00205   }
00206 
00207   int BasePainter::PaintTextLineStatic(GraphicsEngine &graphics_engine,
00208                                         ObjectPtr<FontTexture> Font,
00209                                         const Geometry &g,
00210                                         const NString &Str,
00211                                         const Color &color,
00212                                         bool WriteAlphaChannel,
00213                                         TextAlignment alignment) const
00214   {
00215     PageBBox page;
00216     page.xmin = g.x;
00217     page.xmax = g.x + g.GetWidth();
00218     page.ymin = g.y;
00219     page.ymax = g.y + g.GetHeight();
00220     page.x_margin = DEFAULT_TEXT_X_MARGIN;
00221     page.y_margin = DEFAULT_TEXT_Y_MARGIN;
00222     return graphics_engine.RenderColorTextLineStatic(Font, page, Str, color, WriteAlphaChannel, alignment);
00223   }
00224 
00225   void BasePainter::Draw2DTexture(GraphicsEngine &graphics_engine, BaseTexture *texture, int x, int y) const
00226   {
00227     float tex_w, tex_h;
00228     tex_w = (float) texture->GetWidth();
00229     tex_h = (float) texture->GetHeight();
00230 
00231     TexCoordXForm texxform;
00232     graphics_engine.QRP_1Tex(x, y, tex_w, tex_h, texture->GetDeviceTexture(), texxform, color::White);
00233   }
00234 
00235   void BasePainter::Draw2DTextureAligned(GraphicsEngine &graphics_engine, BaseTexture *texture, const Geometry &g, TextureAlignmentStyle tex_align) const
00236   {
00237     int x_pos, y_pos;
00238     int tex_w, tex_h;
00239     tex_w = (float) texture->GetWidth();
00240     tex_h = (float) texture->GetHeight();
00241 
00242     if (tex_align.horz_alignment == eTACenter)
00243     {
00244       int offset = (g.GetWidth() - tex_w) / 2.0f;
00245       offset = (offset < 0) ? 0 : offset;
00246       x_pos = g.x + offset;
00247     }
00248     else if (tex_align.horz_alignment == eTALeft)
00249     {
00250       x_pos = g.x + tex_align.horizontal_margin;
00251     }
00252     else if (tex_align.horz_alignment == eTARight)
00253     {
00254       x_pos = g.x + g.GetWidth() - tex_w - tex_align.horizontal_margin;
00255     }
00256     else
00257     {
00258       x_pos = g.x + tex_align.horizontal_margin;
00259     }
00260 
00261     if (tex_align.vert_alignment == eTACenter)
00262     {
00263       int offset = (g.GetHeight() - tex_h) / 2.0f;
00264       offset = (offset < 0) ? 0 : offset;
00265       y_pos = g.y + offset;
00266     }
00267     else if (tex_align.vert_alignment == eTATop)
00268     {
00269       y_pos = g.y + tex_align.vertical_margin;
00270     }
00271     else if (tex_align.vert_alignment == eTABottom)
00272     {
00273       y_pos = g.y + g.GetHeight() - tex_h - tex_align.vertical_margin;
00274     }
00275     else
00276     {
00277       y_pos = g.y + tex_align.vertical_margin;
00278     }
00279 
00280     PaintTextureShape(graphics_engine, Geometry(x_pos, y_pos, tex_w, tex_h), texture, 0, 0, 0, 0, 0);
00281   }
00282 
00284 // Draw QUADS    //
00286 
00287   void BasePainter::Paint2DQuadColor(GraphicsEngine &graphics_engine, const Geometry &g, const Color &c0) const
00288   {
00289     graphics_engine.QRP_Color(g.x, g.y, g.GetWidth(), g.GetHeight(), c0);
00290   }
00291 
00292   void BasePainter::Paint2DQuadColor(GraphicsEngine &graphics_engine, const Geometry &g, const Color &c0_top_left, const Color &c1_bottom_left, const Color &c2_bottom_right, const Color &c3_top_right) const
00293   {
00294     graphics_engine.QRP_Color(g.x, g.y, g.GetWidth(), g.GetHeight(), c0_top_left, c1_bottom_left, c2_bottom_right, c3_top_right);
00295   }
00296 
00297   void BasePainter::Paint2DQuadColor(GraphicsEngine &graphics_engine, int x, int y, int width, int height, const Color &c0) const
00298   {
00299     graphics_engine.QRP_Color(x, y, width, height, c0);
00300   }
00301 
00302 
00303   void BasePainter::Paint2DQuadColor(GraphicsEngine &graphics_engine, int x, int y, int width, int height, const Color &c0_top_left, const Color &c1_bottom_left, const Color &c2_bottom_right, const Color &c3_top_right) const
00304   {
00305     graphics_engine.QRP_Color(x, y, width, height, c0_top_left, c1_bottom_left, c2_bottom_right, c3_top_right);
00306   }
00307 
00308   void BasePainter::Paint2DQuadVGradient(GraphicsEngine &graphics_engine, const Geometry &g, Color TopColor, Color BottomColor) const
00309   {
00310     Paint2DQuadColor(graphics_engine, g, TopColor, BottomColor, BottomColor, TopColor);
00311   }
00312 
00313   void BasePainter::Paint2DQuadHGradient(GraphicsEngine &graphics_engine, const Geometry &g, Color LeftColor, Color RightColor) const
00314   {
00315     Paint2DQuadColor(graphics_engine, g, LeftColor, LeftColor, RightColor, LeftColor);
00316   }
00317 
00318 
00320 // Draw QUADS WIREFRAME    //
00322   void BasePainter::Paint2DQuadWireframe(GraphicsEngine &graphics_engine, const Geometry &g, Color c0) const
00323   {
00324     graphics_engine.QRP_QuadWireframe(g.x, g.y, g.GetWidth(), g.GetHeight(), c0, c0, c0, c0);
00325   }
00326 
00327 // void BasePainter::Paint2DQuadWireframe(GraphicsEngine& graphics_engine, const Geometry &g, Color c0_left, Color c1_right) const
00328 // {
00329 //     graphics_engine.QRP_QuadWireframe(g.x, g.y, g.GetWidth(), g.GetHeight(), c0_left, c0_left, c1_right, c1_right);
00330 // }
00331 
00332   void BasePainter::Paint2DQuadWireframe(GraphicsEngine &graphics_engine, const Geometry &g, Color c_top_left, Color c_bottom_left, Color c_bottom_right, Color c_top_right) const
00333   {
00334     graphics_engine.QRP_QuadWireframe(g.x, g.y, g.GetWidth(), g.GetHeight(), c_top_left, c_bottom_left, c_bottom_right, c_top_right);
00335   }
00336 
00337   void BasePainter::Paint2DQuadWireframe(GraphicsEngine &graphics_engine, int x, int y, int width, int height, Color c0) const
00338   {
00339     graphics_engine.QRP_QuadWireframe(x, y, width, height, c0, c0, c0, c0);
00340   }
00341 
00342 // void BasePainter::Paint2DQuadWireframe(GraphicsEngine& graphics_engine, int x, int y, int width, int height, Color c0_left, Color c1_right) const
00343 // {
00344 //     graphics_engine.QRP_QuadWireframe(x, y, width, height, c0_left, c0_left, c1_right, c1_right);
00345 // }
00346 
00347   void BasePainter::Paint2DQuadWireframe(GraphicsEngine &graphics_engine, 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
00348   {
00349     graphics_engine.QRP_QuadWireframe(x, y, width, height, c_top_left, c_bottom_left, c_bottom_right, c_top_right);
00350   }
00351 
00353 // Draw TRIANGLES   //
00355   void BasePainter::Draw2DTriangleColor(GraphicsEngine &graphics_engine, int x0, int y0,
00356                                          int x1, int y1,
00357                                          int x2, int y2,
00358                                          Color c0)
00359   {
00360     graphics_engine.QRP_Triangle(x0, y0, x1, y1, x2, y2, c0);
00361   }
00362 
00363   void BasePainter::Draw2DTriangleColor(GraphicsEngine &graphics_engine, int x0, int y0,
00364                                          int x1, int y1,
00365                                          int x2, int y2,
00366                                          Color c0, Color c1, Color c2)
00367   {
00368     graphics_engine.QRP_Triangle(x0, y0, x1, y1, x2, y2, c0, c1, c2);
00369   }
00370 
00372 // DRAW LINES       //
00374   void BasePainter::Draw2DLine(GraphicsEngine &graphics_engine, int x0, int y0,
00375                                 int x1, int y1, Color c0) const
00376   {
00377     graphics_engine.QRP_Line(x0, y0, x1, y1, c0);
00378   }
00379   void BasePainter::Draw2DLine(GraphicsEngine &graphics_engine, int x0, int y0,
00380                                 int x1, int y1, Color c0, Color c1) const
00381   {
00382     graphics_engine.QRP_Line(x0, y0, x1, y1, c0, c1);
00383   }
00384 
00386 // Themes         //
00388 
00389 
00390   void BasePainter::PaintShape(GraphicsEngine &graphics_engine,
00391                                const Geometry &geo,
00392                                const Color &c0,
00393                                UXStyleImageRef style,
00394                                bool WriteAlpha) const
00395   {
00396     ROPConfig ROP;
00397     ROP.Blend = true;
00398     ROP.SrcBlend = GL_SRC_ALPHA;
00399     ROP.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
00400     PaintShapeCornerROP(graphics_engine, geo, c0, style, eCornerTopLeft | eCornerTopRight | eCornerBottomLeft | eCornerBottomRight, WriteAlpha, ROP);
00401   }
00402 
00403   void BasePainter::PaintShapeCorner(GraphicsEngine &graphics_engine,
00404                                      const Geometry &geo,
00405                                      const Color &c0,
00406                                      UXStyleImageRef style,
00407                                      long corners,
00408                                      bool WriteAlpha) const
00409   {
00410     ROPConfig ROP;
00411     ROP.Blend = true;
00412     ROP.SrcBlend = GL_SRC_ALPHA;
00413     ROP.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
00414     PaintShapeCornerROP(graphics_engine, geo, c0, style, corners, WriteAlpha, ROP);
00415   }
00416 
00417   void BasePainter::PaintShapeROP(GraphicsEngine &graphics_engine,
00418                                   const Geometry &geo,
00419                                   const Color &c0,
00420                                   UXStyleImageRef style,
00421                                   bool WriteAlpha, const ROPConfig &ROP) const
00422   {
00423     PaintShapeCornerROP(graphics_engine, geo, c0, style, eCornerTopLeft | eCornerTopRight | eCornerBottomLeft | eCornerBottomRight, WriteAlpha, ROP);
00424   }
00425 
00426   void BasePainter::PaintShapeCornerROP(GraphicsEngine &graphics_engine,
00427                                         const Geometry &geo,
00428                                         const Color &c0,
00429                                         UXStyleImageRef style,
00430                                         long corners,
00431                                         bool WriteAlpha,
00432                                         const ROPConfig &ROP) const
00433   {
00434     const PainterImage *pimage = GetTheme().GetImage(style);
00435 
00436     if (pimage == 0)
00437       return;
00438 
00439     BaseTexture *texture = pimage->texture;
00440 
00441     int border_left = pimage->border_left;
00442     int border_right = pimage->border_right;
00443     int border_top = pimage->border_top;
00444     int border_bottom = pimage->border_bottom;
00445     bool draw_borders_only = pimage->draw_borders_only;
00446     unsigned int current_alpha_blend;
00447     unsigned int current_src_blend_factor;
00448     unsigned int current_dest_blend_factor;
00449     unsigned int current_red_mask;
00450     unsigned int current_green_mask;
00451     unsigned int current_blue_mask;
00452     unsigned int current_alpha_mask;
00453 
00454     // Get the current color mask and blend states. They will be restored later.
00455     graphics_engine.GetRenderStates().GetColorMask(current_red_mask, current_green_mask, current_blue_mask, current_alpha_mask);
00456     graphics_engine.GetRenderStates().GetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
00457 
00458 
00459     graphics_engine.GetRenderStates().SetColorMask(GL_TRUE, GL_TRUE, GL_TRUE, WriteAlpha ? GL_TRUE : GL_FALSE);
00460     graphics_engine.GetRenderStates().SetBlend(ROP.Blend, ROP.SrcBlend, ROP.DstBlend);
00461 
00462     int tex_w = texture->GetWidth();
00463     int tex_h = texture->GetHeight();
00464 
00465     int r_x = geo.x;
00466     int r_y = geo.y;
00467     int r_w = geo.GetWidth();
00468     int r_h = geo.GetHeight();
00469 
00470     TexCoordXForm texxform;
00471     texxform.SetTexCoordType(TexCoordXForm::UNNORMALIZED_COORD);
00472 
00473     if (r_w < border_left + border_right)
00474     {
00475       // Do not apply this correction: just show the drawing as it is;
00476       //border_left = border_right = 0;
00477     }
00478 
00479     if (r_h < border_top + border_bottom)
00480     {
00481       // Do not apply this correction: just show the drawing as it is;
00482       //border_top = border_bottom = 0;
00483     }
00484 
00485     // Draw TOP-LEFT CORNER
00486     if (corners & eCornerTopLeft)
00487     {
00488       texxform.u0 = 0;
00489       texxform.v0 = 0;
00490       texxform.u1 = border_left;
00491       texxform.v1 = border_top;
00492       graphics_engine.QRP_ColorModTexAlpha(r_x, r_y, border_left, border_top, texture->GetDeviceTexture(), texxform, c0);
00493     }
00494     else
00495     {
00496       graphics_engine.QRP_Color(r_x, r_y, border_left, border_top, c0);
00497     }
00498 
00499     // Draw TOP-RIGHT CORNER
00500     if (corners & eCornerTopRight)
00501     {
00502       texxform.u0 = tex_w - border_right;
00503       texxform.v0 = 0;
00504       texxform.u1 = tex_w;
00505       texxform.v1 = border_top;
00506       graphics_engine.QRP_ColorModTexAlpha(r_x + r_w - border_right, r_y, border_right, border_top, texture->GetDeviceTexture(), texxform, c0);
00507     }
00508     else
00509     {
00510       graphics_engine.QRP_Color(r_x + r_w - border_right, r_y, border_right, border_top, c0);
00511     }
00512 
00513     // Draw BOTTOM-LEFT CORNER
00514     if (corners & eCornerBottomLeft)
00515     {
00516       texxform.u0 = 0;
00517       texxform.v0 = tex_h - border_bottom;
00518       texxform.u1 = border_left;
00519       texxform.v1 = tex_h;
00520       graphics_engine.QRP_ColorModTexAlpha(r_x, r_y + r_h - border_bottom, border_left, border_bottom, texture->GetDeviceTexture(), texxform, c0);
00521     }
00522     else
00523     {
00524       graphics_engine.QRP_Color(r_x, r_y + r_h - border_bottom, border_left, border_bottom, c0);
00525     }
00526 
00527     // Draw BOTTOM-RIGHT CORNER
00528     if (corners & eCornerBottomRight)
00529     {
00530       texxform.u0 = tex_w - border_right;
00531       texxform.v0 = tex_h - border_bottom;
00532       texxform.u1 = tex_w;
00533       texxform.v1 = tex_h;
00534       graphics_engine.QRP_ColorModTexAlpha(r_x + r_w - border_right, r_y + r_h - border_bottom, border_right, border_bottom, texture->GetDeviceTexture(), texxform, c0);
00535     }
00536     else
00537     {
00538       graphics_engine.QRP_Color(r_x + r_w - border_right, r_y + r_h - border_bottom, border_right, border_bottom, c0);
00539     }
00540 
00541     texxform.u0 = border_left;
00542     texxform.v0 = 0;
00543     texxform.u1 = tex_w - border_right;
00544     texxform.v1 = border_top;
00545     graphics_engine.QRP_ColorModTexAlpha(r_x + border_left, r_y, r_w - border_left - border_right, border_top, texture->GetDeviceTexture(), texxform, c0);
00546     // Draw BOTTOM BORDER
00547     texxform.u0 = border_left;
00548     texxform.v0 = tex_h - border_bottom;
00549     texxform.u1 = tex_w - border_right;
00550     texxform.v1 = tex_h;
00551     graphics_engine.QRP_ColorModTexAlpha(r_x + border_left, r_y + r_h - border_bottom, r_w - border_left - border_right, border_bottom, texture->GetDeviceTexture(), texxform, c0);
00552     // Draw LEFT BORDER
00553     texxform.u0 = 0;
00554     texxform.v0 = border_top;
00555     texxform.u1 = border_left;
00556     texxform.v1 = tex_h - border_bottom;
00557     graphics_engine.QRP_ColorModTexAlpha(r_x, r_y + border_top, border_left, r_h - border_top - border_bottom, texture->GetDeviceTexture(), texxform, c0);
00558     // Draw RIGHT BORDER
00559     texxform.u0 = tex_w - border_right;
00560     texxform.v0 = border_top;
00561     texxform.u1 = tex_w;
00562     texxform.v1 = tex_h - border_bottom;
00563     graphics_engine.QRP_ColorModTexAlpha(r_x + r_w - border_right, r_y + border_top, border_right, r_h - border_top - border_bottom, texture->GetDeviceTexture(), texxform, c0);
00564 
00565     // Draw CENTER
00566     if (draw_borders_only == false)
00567     {
00568       texxform.u0 = border_left;
00569       texxform.v0 = border_top;
00570       texxform.u1 = tex_w - border_right;
00571       texxform.v1 = tex_h - border_bottom;
00572       graphics_engine.QRP_ColorModTexAlpha(r_x + border_left, r_y + border_top, r_w - border_left - border_right, r_h - border_top - border_bottom, texture->GetDeviceTexture(), texxform, c0);
00573     }
00574 
00575     // Restore Color mask and blend states.
00576     graphics_engine.GetRenderStates().SetColorMask(current_red_mask, current_green_mask, current_blue_mask, current_alpha_mask);
00577     graphics_engine.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
00578   }
00579 
00580   void BasePainter::PaintTextureShape(GraphicsEngine &graphics_engine, const Geometry &geo, UXStyleImageRef style) const
00581   {
00582     const PainterImage *pimage = GetTheme().GetImage(style);
00583 
00584     if (pimage == 0)
00585       return;
00586 
00587     BaseTexture *texture = pimage->texture;
00588 
00589 
00590     int border_left = pimage->border_left;
00591     int border_right = pimage->border_right;
00592     int border_top = pimage->border_top;
00593     int border_bottom = pimage->border_bottom;
00594     bool draw_borders_only = pimage->draw_borders_only;
00595 
00596     PaintTextureShape(graphics_engine, geo, texture,
00597                        border_left, border_right, border_top, border_bottom, draw_borders_only);
00598   }
00599 
00600   void BasePainter::PaintTextureShape(GraphicsEngine &graphics_engine, const Geometry &geo, BaseTexture *texture,
00601                                        int border_left, int border_right, int border_top, int border_bottom,
00602                                        bool draw_borders_only, bool premultiply) const
00603   {
00604     int tex_w = texture->GetWidth();
00605     int tex_h = texture->GetHeight();
00606 
00607     int r_x = geo.x;
00608     int r_y = geo.y;
00609     int r_w = geo.GetWidth();
00610     int r_h = geo.GetHeight();
00611 
00612     if (r_w < border_left + border_right)
00613     {
00614       border_left = border_right = 0;
00615     }
00616 
00617     if (r_h < border_top + border_bottom)
00618     {
00619       border_top = border_bottom = 0;
00620     }
00621 
00622     if (premultiply)
00623       graphics_engine.GetRenderStates().SetBlend(TRUE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
00624     else
00625       graphics_engine.GetRenderStates().SetBlend(TRUE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00626 
00627     TexCoordXForm texxform;
00628     texxform.SetTexCoordType(TexCoordXForm::UNNORMALIZED_COORD);
00629 
00630     // Draw TOP-LEFT CORNER
00631     texxform.u0 = 0;
00632     texxform.v0 = 0;
00633     texxform.u1 = border_left;
00634     texxform.v1 = border_top;
00635     graphics_engine.QRP_1Tex(r_x, r_y, border_left, border_top, texture->GetDeviceTexture(), texxform, color::White);
00636     // Draw TOP-RIGHT CORNER
00637     texxform.u0 = tex_w - border_right;
00638     texxform.v0 = 0;
00639     texxform.u1 = tex_w;
00640     texxform.v1 = border_top;
00641     graphics_engine.QRP_1Tex(r_x + r_w - border_right, r_y, border_right, border_top, texture->GetDeviceTexture(), texxform, color::White);
00642     // Draw BOTTOM-LEFT CORNER
00643     texxform.u0 = 0;
00644     texxform.v0 = tex_h - border_bottom;
00645     texxform.u1 = border_left;
00646     texxform.v1 = tex_h;
00647     graphics_engine.QRP_1Tex(r_x, r_y + r_h - border_bottom, border_left, border_bottom, texture->GetDeviceTexture(), texxform, color::White);
00648     // Draw BOTTOM-RIGHT CORNER
00649     texxform.u0 = tex_w - border_right;
00650     texxform.v0 = tex_h - border_bottom;
00651     texxform.u1 = tex_w;
00652     texxform.v1 = tex_h;
00653     graphics_engine.QRP_1Tex(r_x + r_w - border_right, r_y + r_h - border_bottom, border_right, border_bottom, texture->GetDeviceTexture(), texxform, color::White);
00654     // Draw TOP BORDER
00655     texxform.u0 = border_left;
00656     texxform.v0 = 0;
00657     texxform.u1 = tex_w - border_right;
00658     texxform.v1 = border_top;
00659     graphics_engine.QRP_1Tex(r_x + border_left, r_y, r_w - border_left - border_right, border_top, texture->GetDeviceTexture(), texxform, color::White);
00660     // Draw BOTTOM BORDER
00661     texxform.u0 = border_left;
00662     texxform.v0 = tex_h - border_bottom;
00663     texxform.u1 = tex_w - border_right;
00664     texxform.v1 = tex_h;
00665     graphics_engine.QRP_1Tex(r_x + border_left, r_y + r_h - border_bottom, r_w - border_left - border_right, border_bottom, texture->GetDeviceTexture(), texxform, color::White);
00666     // Draw LEFT BORDER
00667     texxform.u0 = 0;
00668     texxform.v0 = border_top;
00669     texxform.u1 = border_left;
00670     texxform.v1 = tex_h - border_bottom;
00671     graphics_engine.QRP_1Tex(r_x, r_y + border_top, border_left, r_h - border_top - border_bottom, texture->GetDeviceTexture(), texxform, color::White);
00672     // Draw RIGHT BORDER
00673     texxform.u0 = tex_w - border_right;
00674     texxform.v0 = border_top;
00675     texxform.u1 = tex_w;
00676     texxform.v1 = tex_h - border_bottom;
00677     graphics_engine.QRP_1Tex(r_x + r_w - border_right, r_y + border_top, border_right, r_h - border_top - border_bottom, texture->GetDeviceTexture(), texxform, color::White);
00678 
00679     // Draw CENTER
00680     if (draw_borders_only == false)
00681     {
00682       texxform.u0 = border_left;
00683       texxform.v0 = border_top;
00684       texxform.u1 = tex_w - border_right;
00685       texxform.v1 = tex_h - border_bottom;
00686       graphics_engine.QRP_1Tex(r_x + border_left, r_y + border_top, r_w - border_left - border_right, r_h - border_top - border_bottom, texture->GetDeviceTexture(), texxform, color::White);
00687     }
00688 
00689     graphics_engine.GetRenderStates().SetBlend(FALSE);
00690   }
00691 
00692   void BasePainter::PaintHorizontalGradientQuad(GraphicsEngine &graphics_engine, const Geometry &geo, int array_size, float *percentage_array, Color *color_array)
00693   {
00694     for (int i = 0; i < array_size - 1; i++)
00695     {
00696       float p0 = percentage_array[i] / 100.0f;
00697       float p1 = percentage_array[i+1] / 100.0f;
00698 
00699       Paint2DQuadColor(graphics_engine, geo.x, geo.y + geo.GetHeight() * p0, geo.GetWidth(), geo.GetHeight() * p1 - geo.GetHeight() * p0,
00700                         color_array[i], color_array[i],
00701                         color_array[i+1], color_array[i+1]);
00702     }
00703   }
00704 
00705   void BasePainter::PaintCheckBox(GraphicsEngine &graphics_engine, const Geometry &geo, const InteractState &interaction_state,
00706                                    Color check_mark_color, Color check_box_color)
00707   {
00708 
00709     GeometryPositioning pctx(eHACenter, eVACenter);
00710     pctx.m_stretch_horizontal = false;
00711     pctx.m_stretch_vertical = false;
00712 
00713     const PainterImage *pimage = GetTheme().GetImage(eCHECKBOX_NORMAL_ON);
00714 
00715     if (pimage == 0)
00716       return;
00717 
00718     BaseTexture *texture = pimage->texture;
00719     Geometry content_geo(0, 0, texture->GetWidth(), texture->GetHeight()) ;
00720     content_geo = ComputeGeometryPositioning(geo, content_geo, pctx);
00721 
00722     graphics_engine.GetRenderStates().SetBlend(true, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00723 
00724     if (interaction_state.is_focus && interaction_state.is_on)
00725     {
00726       Draw2DTexture(graphics_engine, GetTheme().GetImage(eCHECKBOX_FOCUS_ON)->texture, content_geo.x, content_geo.y);
00727     }
00728     else if (interaction_state.is_focus && !interaction_state.is_on)
00729     {
00730       Draw2DTexture(graphics_engine, GetTheme().GetImage(eCHECKBOX_FOCUS_OFF)->texture, content_geo.x, content_geo.y);
00731     }
00732     else if (interaction_state.is_prelight && interaction_state.is_on)
00733     {
00734       Draw2DTexture(graphics_engine, GetTheme().GetImage(eCHECKBOX_PRELIGHT_ON)->texture, content_geo.x, content_geo.y);
00735     }
00736     else if (interaction_state.is_prelight && !interaction_state.is_on)
00737     {
00738       Draw2DTexture(graphics_engine, GetTheme().GetImage(eCHECKBOX_PRELIGHT_OFF)->texture, content_geo.x, content_geo.y);
00739     }
00740     else if (interaction_state.is_on)
00741     {
00742       Draw2DTexture(graphics_engine, GetTheme().GetImage(eCHECKBOX_NORMAL_ON)->texture, content_geo.x, content_geo.y);
00743     }
00744     else
00745     {
00746       Draw2DTexture(graphics_engine, GetTheme().GetImage(eCHECKBOX_NORMAL_OFF)->texture, content_geo.x, content_geo.y);
00747     }
00748 
00749     graphics_engine.GetRenderStates().SetBlend(false);
00750   }
00751 
00752   void BasePainter::PaintRadioButton(GraphicsEngine &graphics_engine, const Geometry &geo, const InteractState &interaction_state,
00753                                       Color check_mark_color, Color check_box_color)
00754   {
00755     PaintBackground(graphics_engine, geo);
00756     GeometryPositioning pctx(eHACenter, eVACenter);
00757     pctx.m_stretch_horizontal = false;
00758     pctx.m_stretch_vertical = false;
00759 
00760     const PainterImage *pimage = GetTheme().GetImage(eRADIO_NORMAL_ON);
00761 
00762     if (pimage == 0)
00763       return;
00764 
00765     BaseTexture *texture = pimage->texture;
00766 
00767     Geometry content_geo(0, 0, texture->GetWidth(), texture->GetHeight()) ;
00768     content_geo = ComputeGeometryPositioning(geo, content_geo, pctx);
00769 
00770     graphics_engine.GetRenderStates().SetBlend(true, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00771 
00772     if (interaction_state.is_focus && interaction_state.is_on)
00773     {
00774       Draw2DTexture(graphics_engine, GetTheme().GetImage(eRADIO_FOCUS_ON)->texture, content_geo.x, content_geo.y);
00775     }
00776     else if (interaction_state.is_focus && !interaction_state.is_on)
00777     {
00778       Draw2DTexture(graphics_engine, GetTheme().GetImage(eRADIO_FOCUS_OFF)->texture, content_geo.x, content_geo.y);
00779     }
00780     else if (interaction_state.is_prelight && interaction_state.is_on)
00781     {
00782       Draw2DTexture(graphics_engine, GetTheme().GetImage(eRADIO_PRELIGHT_ON)->texture, content_geo.x, content_geo.y);
00783     }
00784     else if (interaction_state.is_prelight && !interaction_state.is_on)
00785     {
00786       Draw2DTexture(graphics_engine, GetTheme().GetImage(eRADIO_PRELIGHT_OFF)->texture, content_geo.x, content_geo.y);
00787     }
00788     else if (interaction_state.is_on)
00789     {
00790       Draw2DTexture(graphics_engine, GetTheme().GetImage(eRADIO_NORMAL_ON)->texture, content_geo.x, content_geo.y);
00791     }
00792     else
00793     {
00794       Draw2DTexture(graphics_engine, GetTheme().GetImage(eRADIO_NORMAL_OFF)->texture, content_geo.x, content_geo.y);
00795     }
00796 
00797     graphics_engine.GetRenderStates().SetBlend(false);
00798   }
00799 
00800   void BasePainter::PaintBackground(GraphicsEngine &graphics_engine, const Geometry &geo)
00801   {
00802     if (active_paint_layer_stack_.empty())
00803     {
00804       return;
00805     }
00806 
00807     std::list<AbstractPaintLayer *>::const_reverse_iterator rev_it;
00808 
00809     bool first = true;
00810 
00811     for (rev_it = active_paint_layer_stack_.rbegin(); rev_it != active_paint_layer_stack_.rend(); rev_it++)
00812     {
00813       AbstractPaintLayer *layer = (*rev_it);
00814       Geometry layer_geo = layer->GetGeometry();
00815       Geometry xform_geo = graphics_engine.ModelViewXFormRect(geo);
00816 
00817       graphics_engine.PushClippingRectangle(geo);
00818       graphics_engine.SetModelViewMatrix(layer->GetModelViewMatrix());
00819 
00820       if (first)
00821       {
00822         Paint2DQuadColor(graphics_engine, layer_geo, Color(0x0));
00823         first = false;
00824       }
00825 
00826       RenderSinglePaintLayer(graphics_engine, layer_geo, layer);
00827 
00828       // restore the model view matrix stack and the clipping rectangle stack.
00829       graphics_engine.ApplyModelViewMatrix();
00830       graphics_engine.PopClippingRectangle();
00831     }
00832   }
00833 
00834   void BasePainter::RenderSinglePaintLayer(GraphicsEngine &graphics_engine, Geometry geo, AbstractPaintLayer *paint_layer)
00835   {
00836     paint_layer->Renderlayer(graphics_engine);
00837   }
00838 
00839   void BasePainter::PushLayer(GraphicsEngine &graphics_engine, const Geometry &geo, AbstractPaintLayer *layer)
00840   {
00841     AbstractPaintLayer *l = layer->Clone();
00842     l->SetModelViewMatrix(window_thread_->GetGraphicsEngine().GetModelViewMatrix());
00843     l->SetGeometry(geo);
00844     active_paint_layer_stack_.push_front(l);
00845   }
00846 
00847   void BasePainter::PushDrawLayer(GraphicsEngine &graphics_engine, const Geometry &geo, AbstractPaintLayer *layer)
00848   {
00849     PushLayer(graphics_engine, geo, layer);
00850     PaintBackground(graphics_engine, geo);
00851   }
00852 
00853   void BasePainter::PushColorLayer(GraphicsEngine &graphics_engine, const Geometry &geo,
00854                                     Color color,
00855                                     bool WriteAlpha,
00856                                     const ROPConfig &ROP)
00857   {
00858     ColorLayer *cl = new ColorLayer(color, WriteAlpha, ROP);
00859     cl->SetModelViewMatrix(window_thread_->GetGraphicsEngine().GetModelViewMatrix());
00860     cl->SetGeometry(geo);
00861     active_paint_layer_stack_.push_front(cl);
00862   }
00863 
00864   void BasePainter::PushDrawColorLayer(GraphicsEngine &graphics_engine, const Geometry &geo,
00865                                         Color color,
00866                                         bool WriteAlpha,
00867                                         const ROPConfig &ROP)
00868   {
00869     PushColorLayer(graphics_engine, geo, color, WriteAlpha, ROP);
00870     PaintBackground(graphics_engine, geo);
00871   }
00872 
00873   void BasePainter::PushShapeLayer(GraphicsEngine &graphics_engine, Geometry geo,
00874                                     UXStyleImageRef imageStyle,
00875                                     const Color &color,
00876                                     unsigned long Corners,
00877                                     bool WriteAlpha,
00878                                     const ROPConfig &ROP)
00879   {
00880     ShapeLayer *sl = new ShapeLayer(imageStyle, color, Corners, WriteAlpha, ROP);
00881     sl->SetModelViewMatrix(window_thread_->GetGraphicsEngine().GetModelViewMatrix());
00882     sl->SetGeometry(geo);
00883     active_paint_layer_stack_.push_front(sl);
00884   }
00885 
00886   void BasePainter::PushDrawShapeLayer(GraphicsEngine &graphics_engine, Geometry geo,
00887                                         UXStyleImageRef imageStyle,
00888                                         const Color &color,
00889                                         unsigned long Corners,
00890                                         bool WriteAlpha,
00891                                         const ROPConfig &ROP)
00892   {
00893     PushShapeLayer(graphics_engine, geo, imageStyle, color, Corners, WriteAlpha, ROP);
00894     PaintBackground(graphics_engine, geo);
00895   }
00896 
00897   void BasePainter::PushSliceScaledTextureLayer(GraphicsEngine &graphics_engine, Geometry geo,
00898       UXStyleImageRef imageStyle,
00899       const Color &color,
00900       unsigned long Corners,
00901       bool WriteAlpha,
00902       const ROPConfig &ROP)
00903   {
00904     SliceScaledTextureLayer *sl = new SliceScaledTextureLayer(imageStyle, color, Corners, WriteAlpha, ROP);
00905     sl->SetModelViewMatrix(window_thread_->GetGraphicsEngine().GetModelViewMatrix());
00906     sl->SetGeometry(geo);
00907     active_paint_layer_stack_.push_front(sl);
00908   }
00909 
00910   void BasePainter::PushDrawSliceScaledTextureLayer(GraphicsEngine &graphics_engine, Geometry geo,
00911       UXStyleImageRef imageStyle,
00912       const Color &color,
00913       unsigned long Corners,
00914       bool WriteAlpha,
00915       const ROPConfig &ROP)
00916   {
00917     PushSliceScaledTextureLayer(graphics_engine, geo, imageStyle, color, Corners, WriteAlpha, ROP);
00918     PaintBackground(graphics_engine, geo);
00919   }
00920 
00921   void BasePainter::PushTextureLayer(GraphicsEngine &graphics_engine, Geometry geo,
00922                                       ObjectPtr<IOpenGLBaseTexture> DeviceTexture,
00923                                       TexCoordXForm texxform,
00924                                       const Color &color,
00925                                       bool WriteAlpha,
00926                                       const ROPConfig &ROP)
00927   {
00928     TextureLayer *tl = new TextureLayer(DeviceTexture, texxform, color, WriteAlpha, ROP);
00929     tl->SetModelViewMatrix(window_thread_->GetGraphicsEngine().GetModelViewMatrix());
00930     tl->SetGeometry(geo);
00931     active_paint_layer_stack_.push_front(tl);
00932   }
00933   
00934   void BasePainter::PushCompositionLayer (GraphicsEngine &graphics_engine,
00935                                      Geometry geo,
00936                                      ObjectPtr <IOpenGLBaseTexture> texture0,
00937                                      TexCoordXForm texxform0,
00938                                      const Color &color0,
00939                                      ObjectPtr <IOpenGLBaseTexture> texture1,
00940                                      TexCoordXForm texxform1,
00941                                      const Color &color1, 
00942                                      LayerBlendMode layer_blend_mode,
00943                                      bool WriteAlpha,
00944                                      const ROPConfig &ROP)
00945   {
00946     CompositionLayer *cl = new CompositionLayer (texture0, texxform0, color0,
00947                                            texture1, texxform1, color1,
00948                                            layer_blend_mode, WriteAlpha, ROP);
00949     cl->SetModelViewMatrix(window_thread_->GetGraphicsEngine().GetModelViewMatrix());
00950     cl->SetGeometry(geo);
00951     
00952     active_paint_layer_stack_.push_front(cl);
00953   }
00954 
00955   void BasePainter::PushCompositionLayer (GraphicsEngine &graphics_engine,
00956                                      Geometry geo,
00957                                      ObjectPtr <IOpenGLBaseTexture> texture0,
00958                                      TexCoordXForm texxform0,
00959                                      const Color& color0,
00960                                      const Color& blend_color,
00961                                      LayerBlendMode layer_blend_mode,
00962                                      bool WriteAlpha,
00963                                      const ROPConfig &ROP)
00964   {
00965     CompositionLayer *cl = new CompositionLayer (texture0, texxform0, color0, blend_color,
00966                                            layer_blend_mode, WriteAlpha, ROP);
00967     cl->SetModelViewMatrix(window_thread_->GetGraphicsEngine().GetModelViewMatrix());
00968     cl->SetGeometry(geo);
00969 
00970     active_paint_layer_stack_.push_front(cl);
00971   }
00972 
00973   void BasePainter::PushCompositionLayer (GraphicsEngine &graphics_engine,
00974                                      Geometry geo,
00975                                      const Color& base_color,
00976                                      ObjectPtr <IOpenGLBaseTexture> texture0,
00977                                      TexCoordXForm texxform0,
00978                                      const Color& color0,
00979                                      LayerBlendMode layer_blend_mode,
00980                                      bool WriteAlpha,
00981                                      const ROPConfig &ROP)
00982   {
00983     CompositionLayer *cl = new CompositionLayer (base_color, texture0, texxform0,
00984                                            color0, layer_blend_mode,
00985                                            WriteAlpha, ROP);
00986 
00987     cl->SetModelViewMatrix(window_thread_->GetGraphicsEngine().GetModelViewMatrix());
00988     cl->SetGeometry(geo);
00989 
00990     active_paint_layer_stack_.push_front(cl);
00991   }
00992 
00993     
00994   void BasePainter::PushDrawCompositionLayer (GraphicsEngine &graphics_engine,
00995                                          Geometry geo,
00996                                          ObjectPtr <IOpenGLBaseTexture> texture0,
00997                                          TexCoordXForm texxform0,
00998                                          const Color &color0,
00999                                          const Color& blend_color,
01000                                          LayerBlendMode layer_blend_mode,
01001                                          bool WriteAlpha,
01002                                          const ROPConfig &ROP)
01003   {
01004     PushCompositionLayer(graphics_engine, geo, texture0, texxform0,
01005                       color0, blend_color, layer_blend_mode, WriteAlpha, ROP);
01006     PaintBackground(graphics_engine, geo);
01007   }
01008   
01009   void BasePainter::PushDrawCompositionLayer (GraphicsEngine &graphics_engine,
01010                                          Geometry geo,
01011                                          ObjectPtr <IOpenGLBaseTexture> texture0,
01012                                          TexCoordXForm texxform0,
01013                                          const Color &color0,
01014                                          ObjectPtr <IOpenGLBaseTexture> texture1,
01015                                          TexCoordXForm texxform1,
01016                                          const Color &color1, 
01017                                          LayerBlendMode layer_blend_mode,
01018                                          bool WriteAlpha,
01019                                          const ROPConfig &ROP)
01020   {
01021     PushCompositionLayer(graphics_engine, geo, texture0, texxform0,
01022                       color0, texture1, texxform1, color1, layer_blend_mode,
01023                       WriteAlpha, ROP);
01024     PaintBackground(graphics_engine, geo);
01025   }
01026     
01027   void BasePainter::PushDrawCompositionLayer (GraphicsEngine &graphics_engine,
01028                                          Geometry geo,
01029                                          const Color& base_color,
01030                                          ObjectPtr <IOpenGLBaseTexture> texture0,
01031                                          TexCoordXForm texxform0,
01032                                          const Color &color0,
01033                                          LayerBlendMode layer_blend_mode,
01034                                          bool WriteAlpha,
01035                                          const ROPConfig &ROP)
01036   {
01037     PushCompositionLayer(graphics_engine, geo, base_color, texture0,
01038                       texxform0, color0, layer_blend_mode, WriteAlpha, ROP);
01039   }
01040 
01041   void BasePainter::PushColorizeTextureLayer(GraphicsEngine &graphics_engine, Geometry geo,
01042                                         ObjectPtr<IOpenGLBaseTexture> DeviceTexture,
01043                                         TexCoordXForm texxform,
01044                                         const Color &color,
01045                                         bool WriteAlpha,
01046                                         const ROPConfig &ROP,
01047                                         const Color &blend_color,
01048                                         LayerBlendMode layer_blend_mode)
01049   {
01050     TextureLayer *tl = new TextureLayer(DeviceTexture, texxform, color, WriteAlpha, ROP, blend_color, layer_blend_mode);
01051     tl->SetModelViewMatrix(window_thread_->GetGraphicsEngine().GetModelViewMatrix());
01052     tl->SetGeometry(geo);
01053     active_paint_layer_stack_.push_front(tl);
01054   }
01055 
01056   void BasePainter::PushDrawTextureLayer(GraphicsEngine &graphics_engine, Geometry geo,
01057                                           ObjectPtr<IOpenGLBaseTexture> DeviceTexture,
01058                                           TexCoordXForm texxform,
01059                                           const Color &color,
01060                                           bool WriteAlpha,
01061                                           const ROPConfig &ROP)
01062   {
01063     PushTextureLayer(graphics_engine, geo, DeviceTexture, texxform, color, WriteAlpha, ROP);
01064     PaintBackground(graphics_engine, geo);
01065   }
01066 
01067   void BasePainter::PushDrawColorizeTextureLayer(GraphicsEngine &graphics_engine, Geometry geo,
01068                                            ObjectPtr<IOpenGLBaseTexture> DeviceTexture,
01069                                            TexCoordXForm texxform,
01070                                            const Color &color,
01071                                            bool WriteAlpha,
01072                                            const ROPConfig &ROP,
01073                                            const Color &blend_color,
01074                                            LayerBlendMode layer_blend_mode)
01075   {
01076     PushColorizeTextureLayer(graphics_engine, geo, DeviceTexture, texxform, color, WriteAlpha, ROP, blend_color, layer_blend_mode);
01077     PaintBackground(graphics_engine, geo);
01078   }
01079 
01080   void BasePainter::PopBackground(int level)
01081   {
01082     PopPaintLayer(level);
01083   }
01084 
01085   void BasePainter::PopPaintLayer(int level)
01086   {
01087     nuxAssert(level >= 0);
01088 
01089     while ((level >= 1) && (active_paint_layer_stack_.size() > 0))
01090     {
01091       AbstractPaintLayer *paint_layer = (*active_paint_layer_stack_.begin());
01092       delete paint_layer;
01093       active_paint_layer_stack_.pop_front();
01094       level--;
01095     }
01096   }
01097 
01098   void BasePainter::EmptyBackgroundStack()
01099   {
01100     EmptyActivePaintLayerStack();
01101   }
01102 
01103   void BasePainter::EmptyActivePaintLayerStack()
01104   {
01105     std::list<AbstractPaintLayer*>::iterator background_layer_it;
01106     for (background_layer_it = active_paint_layer_stack_.begin(); background_layer_it != active_paint_layer_stack_.end(); ++background_layer_it)
01107     {
01108       delete(*background_layer_it);
01109     }
01110     active_paint_layer_stack_.clear();
01111   }
01112 
01113   void BasePainter::EmptyPushedPaintLayerStack()
01114   {
01115     std::list<std::list<AbstractPaintLayer*> >::iterator pushed_paint_layer_it;
01116     for (pushed_paint_layer_it = pushed_paint_layer_stack_.begin(); pushed_paint_layer_it != pushed_paint_layer_stack_.end(); ++pushed_paint_layer_it)
01117     {
01118       std::list<AbstractPaintLayer*> paint_layer_stack = *pushed_paint_layer_it;
01119       {
01120         std::list<AbstractPaintLayer*>::iterator paint_layer_it;
01121         for (paint_layer_it = paint_layer_stack.begin(); paint_layer_it != paint_layer_stack.end(); ++paint_layer_it)
01122         {
01123           delete(*paint_layer_it);
01124         }
01125         paint_layer_stack.clear();
01126       }
01127     }
01128     active_paint_layer_stack_.clear();
01129   }
01130 
01131   void BasePainter::PushBackgroundStack()
01132   {
01133     PushPaintLayerStack();
01134   }
01135 
01136   void BasePainter::PushPaintLayerStack()
01137   {
01138     pushed_paint_layer_stack_.push_back(active_paint_layer_stack_);
01139     active_paint_layer_stack_.clear();
01140   }
01141 
01142   void BasePainter::PopBackgroundStack()
01143   {
01144     PopPaintLayerStack();
01145   }
01146 
01147   void BasePainter::PopPaintLayerStack()
01148   {
01149     // clear and delete
01150     EmptyActivePaintLayerStack();
01151 
01152     active_paint_layer_stack_ = pushed_paint_layer_stack_.back();
01153     pushed_paint_layer_stack_.pop_back();
01154   }
01155 }