~azzar1/unity/proper-reboot

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/HudIcon.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Gord Allott <gord.allott@canonical.com>
 
17
 */
 
18
 
 
19
 
 
20
#include "HudIcon.h"
 
21
#include "NuxCore/Logger.h"
 
22
namespace
 
23
{
 
24
  nux::logging::Logger logger("unity.hud.icon");
 
25
}
 
26
  
 
27
namespace unity
 
28
{
 
29
namespace hud
 
30
{
 
31
 
 
32
Icon::Icon(nux::BaseTexture* texture, guint width, guint height)
 
33
  : unity::IconTexture(texture, width, height)
 
34
{
 
35
  Init();
 
36
  icon_renderer_.SetTargetSize(54, 46, 0);
 
37
}
 
38
 
 
39
Icon::Icon(const char* icon_name, unsigned int size, bool defer_icon_loading)
 
40
  : unity::IconTexture(icon_name, size, defer_icon_loading)
 
41
{
 
42
  Init();
 
43
}
 
44
 
 
45
Icon::~Icon()
 
46
{
 
47
}
 
48
 
 
49
void Icon::Init()
 
50
{
 
51
  SetMinimumWidth(66);
 
52
  SetMinimumHeight(66);
 
53
  background_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_back_54.png", -1, true));
 
54
  gloss_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_shine_54.png", -1, true));
 
55
  edge_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_edge_54.png", -1,  true));
 
56
  
 
57
  texture_updated.connect([&] (nux::BaseTexture* texture) 
 
58
  {
 
59
    icon_texture_source_ = new HudIconTextureSource(nux::ObjectPtr<nux::BaseTexture>(texture));
 
60
    icon_texture_source_->ColorForIcon(_pixbuf_cached);
 
61
    QueueDraw();
 
62
    LOG_DEBUG(logger) << "got our texture";
 
63
  });
 
64
}
 
65
 
 
66
void Icon::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
 
67
{
 
68
  if (texture() == nullptr)
 
69
    return;
 
70
 
 
71
  unity::ui::RenderArg arg;
 
72
  arg.icon = icon_texture_source_.GetPointer();
 
73
  arg.colorify            = nux::color::White;
 
74
  arg.running_arrow       = true;
 
75
  arg.running_on_viewport = true;
 
76
  arg.render_center       = nux::Point3(32, 32, 0);
 
77
  arg.logical_center      = nux::Point3(52, 50, 0);
 
78
  arg.window_indicators   = true;
 
79
  arg.backlight_intensity = 1.0f;
 
80
  arg.alpha               = 1.0f;
 
81
  
 
82
  std::list<unity::ui::RenderArg> args;
 
83
  args.push_front(arg);
 
84
 
 
85
  
 
86
  auto toplevel = GetToplevel(); 
 
87
  icon_renderer_.SetTargetSize(54, 46, 0);
 
88
  icon_renderer_.PreprocessIcons(args, toplevel->GetGeometry());
 
89
  icon_renderer_.RenderIcon(GfxContext, arg, toplevel->GetGeometry(), toplevel->GetGeometry());
 
90
}
 
91
 
 
92
 
 
93
}
 
94
}
 
95