Back to index

unity  6.0.0
UnityWindowView.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2012 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program 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
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Jason Smith <jason.smith@canonical.com>
00018  */
00019 
00020 #include <UnityCore/Variant.h>
00021 
00022 #include "UnityWindowView.h"
00023 
00024 namespace unity {
00025 namespace ui {
00026 
00027 NUX_IMPLEMENT_OBJECT_TYPE(UnityWindowView);
00028 
00029 UnityWindowView::UnityWindowView(NUX_FILE_LINE_DECL) : View(NUX_FILE_LINE_PARAM)
00030 {
00031   style = UnityWindowStyle::Ptr(new UnityWindowStyle());
00032   bg_helper_.owner = this;
00033 }
00034 
00035 UnityWindowView::~UnityWindowView()
00036 {
00037 
00038 }
00039 
00040 void
00041 UnityWindowView::SetupBackground(bool enabled)
00042 {
00043   bg_helper_.enabled = enabled;
00044 }
00045 
00046 void UnityWindowView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
00047 {
00048   // fixme???
00049 }
00050 
00051 void UnityWindowView::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
00052 {
00053   PreDraw(GfxContext, force_draw);
00054 
00055   nux::Geometry base = GetGeometry();
00056   GfxContext.PushClippingRectangle(base);
00057 
00058   // clear region
00059   gPainter.PaintBackground(GfxContext, base);
00060 
00061   nux::Geometry background_geo(GetBackgroundGeometry());
00062   int internal_offset = style()->GetInternalOffset();
00063 
00064   nux::Geometry internal_clip(background_geo.x + internal_offset,
00065                               background_geo.y + internal_offset,
00066                               background_geo.width - internal_offset * 2,
00067                               background_geo.height - internal_offset * 2);
00068   GfxContext.PushClippingRectangle(internal_clip);
00069 
00070   nux::Geometry const& geo_absolute = GetAbsoluteGeometry();
00071   nux::Geometry blur_geo(geo_absolute.x, geo_absolute.y, base.width, base.height);
00072 
00073   if (BackgroundEffectHelper::blur_type != BLUR_NONE)
00074   {
00075     bg_texture_ = bg_helper_.GetBlurRegion(blur_geo);
00076   }
00077   else
00078   {
00079     bg_texture_ = bg_helper_.GetRegion(blur_geo);
00080   }
00081 
00082   if (bg_texture_.IsValid())
00083   {
00084     nux::TexCoordXForm texxform_blur_bg;
00085     texxform_blur_bg.flip_v_coord = true;
00086     texxform_blur_bg.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
00087     texxform_blur_bg.uoffset = ((float) base.x) / geo_absolute.width;
00088     texxform_blur_bg.voffset = ((float) base.y) / geo_absolute.height;
00089 
00090     nux::ROPConfig rop;
00091     rop.Blend = false;
00092     rop.SrcBlend = GL_ONE;
00093     rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
00094 
00095 #ifndef NUX_OPENGLES_20
00096     if (GfxContext.UsingGLSLCodePath())
00097       gPainter.PushDrawCompositionLayer(GfxContext, base,
00098                                         bg_texture_,
00099                                         texxform_blur_bg,
00100                                         nux::color::White,
00101                                         background_color, nux::LAYER_BLEND_MODE_OVERLAY,
00102                                         true, rop);
00103     else
00104       gPainter.PushDrawTextureLayer(GfxContext, base,
00105                                     bg_texture_,
00106                                     texxform_blur_bg,
00107                                     nux::color::White,
00108                                     true,
00109                                     rop);
00110 #else
00111       gPainter.PushDrawCompositionLayer(GfxContext, base,
00112                                         bg_texture_,
00113                                         texxform_blur_bg,
00114                                         nux::color::White,
00115                                         background_color, nux::LAYER_BLEND_MODE_OVERLAY,
00116                                         true, rop);
00117 #endif
00118   }
00119 
00120   nux::ROPConfig rop;
00121   rop.Blend = true;
00122 
00123 #ifndef NUX_OPENGLES_20
00124   if (GfxContext.UsingGLSLCodePath() == false)
00125   {
00126     rop.SrcBlend = GL_ONE;
00127     rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
00128     gPainter.PushDrawColorLayer (GfxContext, internal_clip, background_color, false, rop);
00129   }
00130 #endif
00131 
00132   // Make round corners
00133   rop.Blend = true;
00134   rop.SrcBlend = GL_ZERO;
00135   rop.DstBlend = GL_SRC_ALPHA;
00136   gPainter.PaintShapeCornerROP(GfxContext,
00137                                internal_clip,
00138                                nux::color::White,
00139                                nux::eSHAPE_CORNER_ROUND5,
00140                                nux::eCornerTopLeft | nux::eCornerTopRight |
00141                                nux::eCornerBottomLeft | nux::eCornerBottomRight,
00142                                true,
00143                                rop);
00144 
00145   DrawOverlay(GfxContext, force_draw, internal_clip);
00146 
00147   GfxContext.PopClippingRectangle();
00148   GfxContext.PopClippingRectangle();
00149 
00150   DrawBackground(GfxContext, background_geo);
00151 
00152   PostDraw(GfxContext, force_draw);
00153 }
00154 
00155 void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo)
00156 {
00157   int border = style()->GetBorderSize();
00158 
00159   GfxContext.GetRenderStates().SetBlend (TRUE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
00160 
00161   nux::TexCoordXForm texxform;
00162   texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
00163   texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
00164 
00165   // Draw TOP-LEFT CORNER
00166   texxform.u0 = 0;
00167   texxform.v0 = 0;
00168   texxform.u1 = border;
00169   texxform.v1 = border;
00170   GfxContext.QRP_1Tex (geo.x, geo.y,
00171                        border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
00172 
00173   // Draw TOP-RIGHT CORNER
00174   texxform.u0 = 0;
00175   texxform.v0 = 0;
00176   texxform.u1 = border;
00177   texxform.v1 = border;
00178   texxform.flip_u_coord = true;
00179   texxform.flip_v_coord = false;
00180   GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y,
00181                        border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
00182 
00183   // Draw BOTTOM-LEFT CORNER
00184   texxform.u0 = 0;
00185   texxform.v0 = 0;
00186   texxform.u1 = border;
00187   texxform.v1 = border;
00188   texxform.flip_u_coord = false;
00189   texxform.flip_v_coord = true;
00190   GfxContext.QRP_1Tex (geo.x, geo.y + geo.height - border,
00191                        border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
00192 
00193   // Draw BOTTOM-RIGHT CORNER
00194   texxform.u0 = 0;
00195   texxform.v0 = 0;
00196   texxform.u1 = border;
00197   texxform.v1 = border;
00198   texxform.flip_u_coord = true;
00199   texxform.flip_v_coord = true;
00200   GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + geo.height - border,
00201                        border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
00202 
00203   int top_width = style()->GetBackgroundTop()->GetWidth();
00204   int top_height = style()->GetBackgroundTop()->GetHeight();
00205 
00206   // Draw TOP BORDER
00207   texxform.u0 = 0;
00208   texxform.v0 = 0;
00209   texxform.u1 = top_width;
00210   texxform.v1 = top_height;
00211   texxform.flip_u_coord = false;
00212   texxform.flip_v_coord = false;
00213   GfxContext.QRP_1Tex (geo.x + border, geo.y, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White);
00214 
00215   // Draw BOTTOM BORDER
00216   texxform.u0 = 0;
00217   texxform.v0 = 0;
00218   texxform.u1 = top_width;
00219   texxform.v1 = top_height;
00220   texxform.flip_u_coord = false;
00221   texxform.flip_v_coord = true;
00222   GfxContext.QRP_1Tex (geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White);
00223 
00224 
00225   int left_width = style()->GetBackgroundLeft()->GetWidth();
00226   int left_height = style()->GetBackgroundLeft()->GetHeight();
00227 
00228   // Draw LEFT BORDER
00229   texxform.u0 = 0;
00230   texxform.v0 = 0;
00231   texxform.u1 = left_width;
00232   texxform.v1 = left_height;
00233   texxform.flip_u_coord = false;
00234   texxform.flip_v_coord = false;
00235   GfxContext.QRP_1Tex (geo.x, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White);
00236 
00237   // Draw RIGHT BORDER
00238   texxform.u0 = 0;
00239   texxform.v0 = 0;
00240   texxform.u1 = left_width;
00241   texxform.v1 = left_height;
00242   texxform.flip_u_coord = true;
00243   texxform.flip_v_coord = false;
00244   GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White);
00245 
00246   GfxContext.GetRenderStates().SetBlend (FALSE);
00247 }
00248 
00249 // Introspectable methods
00250 std::string UnityWindowView::GetName() const
00251 {
00252   return "UnityWindowView";
00253 }
00254 
00255 void UnityWindowView::AddProperties(GVariantBuilder* builder)
00256 {
00257   unity::variant::BuilderWrapper(builder)
00258     .add("bg-texture-is-valid", bg_texture_.IsValid());
00259 }
00260 
00261 
00262 }
00263 }