Back to index

unity  6.0.0
HudIcon.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010-2012 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: Gord Allott <gord.allott@canonical.com>
00017  *              Marco Trevisan (TreviƱo) <3v1n0@ubuntu.com>
00018  */
00019 
00020 
00021 #include "HudIcon.h"
00022 #include "NuxCore/Logger.h"
00023 #include "config.h"
00024 
00025 namespace
00026 {
00027   nux::logging::Logger logger("unity.hud.icon");
00028   const unsigned int vertical_padding = 4;
00029 }
00030 
00031 namespace unity
00032 {
00033 namespace hud
00034 {
00035 
00036 Icon::Icon()
00037   : IconTexture("", 0, true)
00038 {
00039   background_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_back_54.png", -1, true));
00040   gloss_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_shine_54.png", -1, true));
00041   edge_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_edge_54.png", -1,  true));
00042 
00043   texture_updated.connect([&] (nux::BaseTexture* texture)
00044   {
00045     icon_texture_source_ = new HudIconTextureSource(nux::ObjectPtr<nux::BaseTexture>(texture));
00046     icon_texture_source_->ColorForIcon(_pixbuf_cached);
00047     QueueDraw();
00048     LOG_DEBUG(logger) << "got our texture";
00049   });
00050 }
00051 
00052 void Icon::SetIcon(std::string const& icon_name, unsigned int icon_size, unsigned int tile_size)
00053 {
00054   IconTexture::SetByIconName(icon_name, icon_size);
00055   icon_renderer_.SetTargetSize(tile_size, icon_size, 0);
00056   SetMinimumWidth(tile_size);
00057   SetMinimumHeight(tile_size + vertical_padding * 2);
00058 }
00059 
00060 void Icon::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
00061 {
00062   if (texture() == nullptr)
00063     return;
00064 
00065   unity::ui::RenderArg arg;
00066   arg.icon = icon_texture_source_.GetPointer();
00067   arg.colorify            = nux::color::White;
00068   arg.running_arrow       = true;
00069   arg.running_on_viewport = true;
00070   arg.render_center       = nux::Point3(GetMinimumWidth() / 2.0f, GetMinimumHeight() / 2.0f, 0.0f);
00071   arg.logical_center      = arg.render_center;
00072   arg.window_indicators   = true;
00073   arg.backlight_intensity = 1.0f;
00074   arg.alpha               = 1.0f;
00075 
00076   std::list<unity::ui::RenderArg> args;
00077   args.push_front(arg);
00078 
00079 
00080   auto toplevel = GetToplevel();
00081   icon_renderer_.PreprocessIcons(args, toplevel->GetGeometry());
00082   icon_renderer_.RenderIcon(GfxContext, arg, toplevel->GetGeometry(), toplevel->GetGeometry());
00083 }
00084 
00085 std::string Icon::GetName() const
00086 {
00087   return "HudEmbeddedIcon";
00088 }
00089 
00090 }
00091 }