Back to index

unity  6.0.0
LineSeparator.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00017  *
00018  */
00019 
00020 #include "LineSeparator.h"
00021 
00022 #include "Nux/Nux.h"
00023 
00024 namespace unity
00025 {
00026 
00027 HSeparator::HSeparator()
00028 {
00029   SetMinimumHeight(1);
00030   SetMaximumHeight(1);
00031 }
00032 
00033 HSeparator::HSeparator(nux::Color const& color, float alpha0, float alpha1, int border)
00034   : AbstractSeparator(color, alpha0, alpha1, border)
00035 {
00036   SetMinimumHeight(1);
00037   SetMaximumHeight(1);
00038 }
00039 
00040 HSeparator::~HSeparator()
00041 {
00042 }
00043 
00044 void HSeparator::Draw(nux::GraphicsEngine &GfxContext, bool force_draw)
00045 {
00046   nux::Geometry const& base = GetGeometry();
00047   int y0 = base.y + base.GetHeight() / 2;
00048 
00049   unsigned int alpha = 0, src = 0, dest = 0;
00050   GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
00051   nux::GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
00052 
00053   if (base.GetWidth() - 2 * border_size_ > 0)
00054   {
00055     nux::Color color0 = color_ * alpha0_;
00056     nux::Color color1 = color_ * alpha1_;
00057     nux::GetPainter().Draw2DLine(GfxContext, base.x, y0, base.x + border_size_, y0, color0, color1);
00058     nux::GetPainter().Draw2DLine(GfxContext, base.x + border_size_, y0, base.x + base.GetWidth() - border_size_, y0, color1, color1);
00059     nux::GetPainter().Draw2DLine(GfxContext, base.x + base.GetWidth() - border_size_, y0, base.x + base.GetWidth(), y0, color1, color0);
00060   }
00061   else
00062   {
00063     nux::Color color1 = color_ *  alpha1_;
00064     nux::GetPainter().Draw2DLine(GfxContext, base.x, y0, base.x + base.GetWidth(), y0, color1, color1);
00065   }
00066 
00067   GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
00068 }
00069 
00070 } // namespace unity