Back to index

unity  6.0.0
LensBarIcon.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 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: Neil Jagdish Patel <neil.patel@canonical.com>
00017  */
00018 
00019 #include <UnityCore/Variant.h>
00020 
00021 #include "unity-shared/DashStyle.h"
00022 #include "LensBarIcon.h"
00023 
00024 #include "config.h"
00025 
00026 namespace unity
00027 {
00028 namespace dash
00029 {
00030 namespace
00031 {
00032 
00033 const int FOCUS_OVERLAY_HEIGHT = 44;
00034 const int FOCUS_OVERLAY_WIDTH = 60;
00035 
00036 }
00037 
00038 NUX_IMPLEMENT_OBJECT_TYPE(LensBarIcon);
00039 
00040 LensBarIcon::LensBarIcon(std::string id_, std::string icon_hint)
00041   : IconTexture(icon_hint, 24)
00042   , id(id_)
00043   , active(false)
00044   , inactive_opacity_(0.4f)
00045 {
00046   SetMinimumWidth(FOCUS_OVERLAY_WIDTH);
00047   SetMaximumWidth(FOCUS_OVERLAY_WIDTH);
00048   SetMinimumHeight(FOCUS_OVERLAY_HEIGHT);
00049   SetMaximumHeight(FOCUS_OVERLAY_HEIGHT);
00050 
00051   focus_layer_.reset(Style::Instance().FocusOverlay(FOCUS_OVERLAY_WIDTH, FOCUS_OVERLAY_HEIGHT));
00052   
00053   SetOpacity(inactive_opacity_);
00054 
00055   SetAcceptKeyNavFocus(true);
00056   SetAcceptKeyNavFocusOnMouseDown(false);
00057   SetAcceptKeyNavFocusOnMouseEnter(true);
00058 
00059   active.changed.connect(sigc::mem_fun(this, &LensBarIcon::OnActiveChanged));
00060   key_nav_focus_change.connect([&](nux::Area*, bool, nux::KeyNavDirection){ QueueDraw(); });
00061 }
00062 
00063 LensBarIcon::~LensBarIcon()
00064 {}
00065 
00066 void LensBarIcon::Draw(nux::GraphicsEngine& gfx_context, bool force_draw)
00067 {
00068   nux::Geometry const& geo = GetGeometry();
00069 
00070   gfx_context.PushClippingRectangle(geo);
00071   nux::GetPainter().PaintBackground(gfx_context, geo);
00072 
00073   if (!texture())
00074   {
00075     gfx_context.PopClippingRectangle();
00076     return;
00077   }
00078 
00079   if (HasKeyFocus() && focus_layer_)
00080   {
00081     nux::Geometry geo(GetGeometry());
00082     nux::AbstractPaintLayer* layer = focus_layer_.get();
00083 
00084     layer->SetGeometry(geo);
00085     layer->Renderlayer(gfx_context);
00086   }
00087 
00088   float opacity = active ? 1.0f : inactive_opacity_;
00089   int width = 0, height = 0;
00090   GetTextureSize(&width, &height);
00091 
00092   nux::Color col(1.0f * opacity, 1.0f * opacity, 1.0f * opacity, opacity);
00093   nux::TexCoordXForm texxform;
00094   texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
00095   texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER);
00096 
00097   gfx_context.QRP_1Tex(geo.x + ((geo.width - width) / 2),
00098                        geo.y + ((geo.height - height) / 2),
00099                        width,
00100                        height,
00101                        texture()->GetDeviceTexture(),
00102                        texxform,
00103                        col);
00104 
00105   gfx_context.PopClippingRectangle();
00106 }
00107 
00108 void LensBarIcon::OnActiveChanged(bool is_active)
00109 {
00110   QueueDraw();
00111 }
00112 
00113 // Introspectable
00114 std::string LensBarIcon::GetName() const
00115 {
00116   return "LensBarIcon";
00117 }
00118 
00119 void LensBarIcon::AddProperties(GVariantBuilder* builder)
00120 {
00121   unity::variant::BuilderWrapper wrapper(builder);
00122 
00123   wrapper.add(GetAbsoluteGeometry());
00124   wrapper.add("name", id);
00125 }
00126 
00127 }
00128 }