2
#include "Nux/VScrollBar.h"
3
#include "Nux/HLayout.h"
4
#include "Nux/VLayout.h"
5
#include "Nux/MenuPage.h"
6
#include "Nux/WindowCompositor.h"
7
#include "Nux/BaseWindow.h"
8
#include "Nux/MenuPage.h"
9
#include "NuxCore/Color.h"
11
#include "LauncherIcon.h"
14
#define DEFAULT_ICON "empathy"
16
LauncherIcon::LauncherIcon(Launcher* IconManager)
19
m_IconManager = IconManager;
20
m_TooltipText = "blank";
24
_background_color = nux::Color::White;
25
_mouse_inside = false;
26
_tooltip = new nux::Tooltip ();
27
_icon_type = LAUNCHER_ICON_TYPE_NONE;
30
MouseEnter.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseEnter));
31
MouseLeave.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseLeave));
34
LauncherIcon::~LauncherIcon()
38
nux::Color LauncherIcon::BackgroundColor ()
40
return _background_color;
43
nux::BaseTexture * LauncherIcon::TextureForSize (int size)
45
nux::BaseTexture * result = GetTextureForSize (size);
50
nux::Color LauncherIcon::ColorForIcon (GdkPixbuf *pixbuf)
52
unsigned int width = gdk_pixbuf_get_width (pixbuf);
53
unsigned int height = gdk_pixbuf_get_height (pixbuf);
54
unsigned int row_bytes = gdk_pixbuf_get_rowstride (pixbuf);
56
long int rtotal = 0, gtotal = 0, btotal = 0;
60
guchar *img = gdk_pixbuf_get_pixels (pixbuf);
62
for (unsigned int i = 0; i < width; i++)
64
for (unsigned int j = 0; j < height; j++)
66
guchar *pixels = img + ( j * row_bytes + i * 4);
67
guchar r = *(pixels + 0);
68
guchar g = *(pixels + 1);
69
guchar b = *(pixels + 2);
70
guchar a = *(pixels + 3);
72
float saturation = (MAX (r, MAX (g, b)) - MIN (r, MIN (g, b))) / 255.0f;
73
float relevance = .1 + .9 * (a / 255.0f) * saturation;
75
rtotal += (guchar) (r * relevance);
76
gtotal += (guchar) (g * relevance);
77
btotal += (guchar) (b * relevance);
79
total += relevance * 255;
83
float r, g, b, h, s, v;
88
nux::RGBtoHSV (r, g, b, h, s, v);
94
nux::HSVtoRGB (r, g, b, h, s, v);
96
return nux::Color (r, g, b);
99
nux::BaseTexture * LauncherIcon::TextureFromGtkTheme (const char *icon_name, int size)
104
nux::BaseTexture *result;
106
theme = gtk_icon_theme_get_default ();
109
icon_name = g_strdup (DEFAULT_ICON);
111
info = gtk_icon_theme_lookup_icon (theme,
114
(GtkIconLookupFlags) 0);
117
info = gtk_icon_theme_lookup_icon (theme,
120
(GtkIconLookupFlags) 0);
123
if (gtk_icon_info_get_filename (info) == NULL)
125
info = gtk_icon_theme_lookup_icon (theme,
128
(GtkIconLookupFlags) 0);
131
pbuf = gtk_icon_info_load_icon (info, NULL);
132
result = nux::CreateTextureFromPixbuf (pbuf);
134
_background_color = ColorForIcon (pbuf);
136
g_object_unref (pbuf);
141
void LauncherIcon::SetTooltipText(const TCHAR* text)
143
m_TooltipText = text;
144
_tooltip->SetText (m_TooltipText);
147
nux::NString LauncherIcon::GetTooltipText()
149
return m_TooltipText;
153
LauncherIcon::RecvMouseEnter ()
155
int icon_x = _xform_screen_coord[0].x;
156
int icon_y = _xform_screen_coord[0].y;
157
int icon_w = _xform_screen_coord[2].x - _xform_screen_coord[0].x;
158
int icon_h = _xform_screen_coord[2].y - _xform_screen_coord[0].y;
160
_tooltip->SetBaseX (icon_x + icon_w);
161
_tooltip->SetBaseY (icon_y +
162
24 + // TODO: HARCODED, replace m_IconManager->GetBaseY ()
164
(_tooltip->GetBaseHeight () / 2));
165
_tooltip->ShowWindow (true);
168
void LauncherIcon::RecvMouseLeave ()
170
_tooltip->ShowWindow (false);
173
void LauncherIcon::HideTooltip ()
175
_tooltip->ShowWindow (false);
179
LauncherIcon::SetVisible (bool visible)
181
if (visible == _visible)
193
LauncherIcon::SetActive (bool active)
195
if (active == _active)
199
needs_redraw.emit (this);
202
void LauncherIcon::SetRunning (bool running)
204
if (running == _running)
208
needs_redraw.emit (this);
212
LauncherIcon::SetIconType (LauncherIconType type)
218
LauncherIcon::SetSortPriority (int priority)
220
_sort_priority = priority;
224
LauncherIcon::SortPriority ()
226
return _sort_priority;
230
LauncherIcon::Type ()
236
LauncherIcon::Visible ()
242
LauncherIcon::Active ()
248
LauncherIcon::Running ()