Back to index

unity  6.0.0
QuicklistMenuItemSeparator.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 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: Mirco Müller <mirco.mueller@canonical.com>
00018  */
00019 
00020 #include <Nux/Nux.h>
00021 
00022 #include "unity-shared/CairoTexture.h"
00023 #include "QuicklistMenuItemSeparator.h"
00024 
00025 namespace unity
00026 {
00027 
00028 QuicklistMenuItemSeparator::QuicklistMenuItemSeparator(DbusmenuMenuitem* item,
00029                                                        NUX_FILE_LINE_DECL) :
00030   QuicklistMenuItem(item,
00031                     NUX_FILE_LINE_PARAM)
00032 {
00033   _name = "QuicklistMenuItemSeparator";
00034   SetMinimumHeight(7);
00035   SetBaseSize(64, 7);
00036 
00037   _color      = nux::Color(1.0f, 1.0f, 1.0f, 0.5f);
00038   _premultiplied_color = nux::Color(0.5f, 0.5f, 0.5f, 0.5f);
00039   _item_type  = MENUITEM_TYPE_SEPARATOR;
00040 }
00041 
00042 QuicklistMenuItemSeparator::QuicklistMenuItemSeparator(DbusmenuMenuitem* item,
00043                                                        bool              debug,
00044                                                        NUX_FILE_LINE_DECL) :
00045   QuicklistMenuItem(item,
00046                     debug,
00047                     NUX_FILE_LINE_PARAM)
00048 {
00049   _name = "QuicklistMenuItemSeparator";
00050   SetMinimumHeight(7);
00051   SetBaseSize(64, 7);
00052   //_normalTexture = NULL;
00053   _color      = nux::Color(1.0f, 1.0f, 1.0f, 0.5f);
00054   _premultiplied_color = nux::Color(0.5f, 0.5f, 0.5f, 0.5f);
00055   _item_type  = MENUITEM_TYPE_SEPARATOR;
00056 }
00057 
00058 QuicklistMenuItemSeparator::~QuicklistMenuItemSeparator()
00059 {
00060 }
00061 
00062 bool
00063 QuicklistMenuItemSeparator::GetSelectable()
00064 {
00065   return false;
00066 }
00067 
00068 void
00069 QuicklistMenuItemSeparator::PreLayoutManagement()
00070 {
00071   _pre_layout_width = GetBaseWidth();
00072   _pre_layout_height = GetBaseHeight();
00073 
00074   if ((_normalTexture[0] == 0))
00075   {
00076     UpdateTexture();
00077   }
00078 
00079   QuicklistMenuItem::PreLayoutManagement();
00080 }
00081 
00082 long
00083 QuicklistMenuItemSeparator::PostLayoutManagement(long layoutResult)
00084 {
00085   int w = GetBaseWidth();
00086   int h = GetBaseHeight();
00087 
00088   long result = 0;
00089 
00090   if (_pre_layout_width < w)
00091     result |= nux::eLargerWidth;
00092   else if (_pre_layout_width > w)
00093     result |= nux::eSmallerWidth;
00094   else
00095     result |= nux::eCompliantWidth;
00096 
00097   if (_pre_layout_height < h)
00098     result |= nux::eLargerHeight;
00099   else if (_pre_layout_height > h)
00100     result |= nux::eSmallerHeight;
00101   else
00102     result |= nux::eCompliantHeight;
00103 
00104   return result;
00105 }
00106 
00107 void
00108 QuicklistMenuItemSeparator::Draw(nux::GraphicsEngine& gfxContext,
00109                                  bool                 forceDraw)
00110 {
00111   // Check if the texture have been computed. If they haven't, exit the function.
00112   if (_normalTexture[0] == 0)
00113     return;
00114 
00115   nux::Geometry base = GetGeometry();
00116 
00117   gfxContext.PushClippingRectangle(base);
00118 
00119   nux::TexCoordXForm texxform;
00120   texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
00121   texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
00122 
00123   gfxContext.GetRenderStates().SetBlend(true);
00124   gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
00125 
00126   gfxContext.QRP_1Tex(base.x,
00127                       base.y,
00128                       base.width,
00129                       base.height,
00130                       _normalTexture[0]->GetDeviceTexture(),
00131                       texxform,
00132                       _premultiplied_color);
00133 
00134   gfxContext.GetRenderStates().SetBlend(false);
00135 
00136   gfxContext.PopClippingRectangle();
00137 }
00138 
00139 void
00140 QuicklistMenuItemSeparator::DrawContent(nux::GraphicsEngine& gfxContext,
00141                                         bool                 forceDraw)
00142 {
00143 }
00144 
00145 void
00146 QuicklistMenuItemSeparator::PostDraw(nux::GraphicsEngine& gfxContext,
00147                                      bool                 forceDraw)
00148 {
00149 }
00150 
00151 void
00152 QuicklistMenuItemSeparator::UpdateTexture()
00153 {
00154   int width  = GetBaseWidth();
00155   int height  = GetBaseHeight();
00156 
00157   _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
00158   cairo_t* cr = _cairoGraphics->GetContext();
00159 
00160   cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
00161   cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
00162   cairo_paint(cr);
00163   cairo_set_source_rgba(cr, _color.red, _color.green, _color.blue, _color.alpha);
00164   cairo_set_line_width(cr, 1.0f);
00165   cairo_move_to(cr, 0.0f, 3.5f);
00166   cairo_line_to(cr, width, 3.5f);
00167   cairo_stroke(cr);
00168 
00169   if (_normalTexture[0])
00170     _normalTexture[0]->UnReference();
00171 
00172   _normalTexture[0] = texture_from_cairo_graphics(*_cairoGraphics);
00173 
00174   cairo_destroy(cr);
00175   delete _cairoGraphics;
00176 }
00177 
00178 int QuicklistMenuItemSeparator::CairoSurfaceWidth()
00179 {
00180   if (_normalTexture[0])
00181     return _normalTexture[0]->GetWidth();
00182 
00183   return 0;
00184 }
00185 
00186 }