Merge lp:~canonical-dx-team/unity/unity.quicklist-support into lp:unity

Proposed by Jay Taoko
Status: Merged
Merged at revision: 610
Proposed branch: lp:~canonical-dx-team/unity/unity.quicklist-support
Merge into: lp:unity
Diff against target: 2843 lines (+1510/-1015)
13 files modified
po/unity.pot (+1/-1)
src/BamfLauncherIcon.cpp (+3/-0)
src/Launcher.cpp (+21/-0)
src/Launcher.h (+45/-32)
src/LauncherIcon.cpp (+157/-10)
src/LauncherIcon.h (+21/-3)
src/QuicklistView.cpp (+1126/-883)
src/QuicklistView.h (+89/-74)
src/StaticCairoText.cpp (+2/-3)
src/StaticCairoText.h (+1/-0)
src/Tooltip.cpp (+39/-8)
src/Tooltip.h (+2/-0)
src/unity.cpp (+3/-1)
To merge this branch: bzr merge lp:~canonical-dx-team/unity/unity.quicklist-support
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+41125@code.launchpad.net

Description of the change

* Support for Quicklist

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Approved, with understanding that tests are coming today.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'po/unity.pot'
--- po/unity.pot 2010-11-12 09:42:09 +0000
+++ po/unity.pot 2010-11-18 14:03:47 +0000
@@ -8,7 +8,7 @@
8msgstr ""8msgstr ""
9"Project-Id-Version: PACKAGE VERSION\n"9"Project-Id-Version: PACKAGE VERSION\n"
10"Report-Msgid-Bugs-To: ayatana-dev@lists.launchpad.net\n"10"Report-Msgid-Bugs-To: ayatana-dev@lists.launchpad.net\n"
11"POT-Creation-Date: 2010-11-11 19:06+0000\n"11"POT-Creation-Date: 2010-11-15 11:43-0500\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"14"Language-Team: LANGUAGE <LL@li.org>\n"
1515
=== modified file 'src/BamfLauncherIcon.cpp'
--- src/BamfLauncherIcon.cpp 2010-11-17 14:40:39 +0000
+++ src/BamfLauncherIcon.cpp 2010-11-18 14:03:47 +0000
@@ -67,6 +67,9 @@
67void67void
68BamfLauncherIcon::OnMouseClick (int button)68BamfLauncherIcon::OnMouseClick (int button)
69{69{
70 if (button != 1)
71 return;
72
70 BamfView *view;73 BamfView *view;
71 GList *children, *l;74 GList *children, *l;
72 bool active, running;75 bool active, running;
7376
=== modified file 'src/Launcher.cpp'
--- src/Launcher.cpp 2010-11-17 18:02:14 +0000
+++ src/Launcher.cpp 2010-11-18 14:03:47 +0000
@@ -35,6 +35,7 @@
35#include "Launcher.h"35#include "Launcher.h"
36#include "LauncherIcon.h"36#include "LauncherIcon.h"
37#include "LauncherModel.h"37#include "LauncherModel.h"
38#include "QuicklistView.h"
3839
39#define ANIM_DURATION_SHORT 12540#define ANIM_DURATION_SHORT 125
40#define ANIM_DURATION 20041#define ANIM_DURATION 200
@@ -170,6 +171,8 @@
170, _model (0)171, _model (0)
171{172{
172 _parent = parent;173 _parent = parent;
174 _active_quicklist = 0;
175
173 m_Layout = new nux::HLayout(NUX_TRACKER_LOCATION);176 m_Layout = new nux::HLayout(NUX_TRACKER_LOCATION);
174177
175 OnMouseDown.connect(sigc::mem_fun(this, &Launcher::RecvMouseDown));178 OnMouseDown.connect(sigc::mem_fun(this, &Launcher::RecvMouseDown));
@@ -1891,3 +1894,21 @@
1891// }1894// }
1892// glEnd();1895// glEnd();
1893}1896}
1897
1898void Launcher::SetActiveQuicklist (QuicklistView *quicklist)
1899{
1900 // Assert: _active_quicklist should be 0
1901 _active_quicklist = quicklist;
1902}
1903
1904QuicklistView *Launcher::GetActiveQuicklist ()
1905{
1906 return _active_quicklist;
1907}
1908
1909void Launcher::CancelActiveQuicklist (QuicklistView *quicklist)
1910{
1911 if (_active_quicklist == quicklist)
1912 _active_quicklist = 0;
1913}
1914
18941915
=== modified file 'src/Launcher.h'
--- src/Launcher.h 2010-11-16 00:56:20 +0000
+++ src/Launcher.h 2010-11-18 14:03:47 +0000
@@ -29,42 +29,51 @@
29#include "Nux/TimerProc.h"29#include "Nux/TimerProc.h"
3030
31class LauncherModel;31class LauncherModel;
32class QuicklistView;
3233
33class Launcher : public nux::View34class Launcher : public nux::View
34{35{
35public:36public:
36 Launcher(nux::BaseWindow *parent, NUX_FILE_LINE_PROTO);37 Launcher(nux::BaseWindow *parent, NUX_FILE_LINE_PROTO);
37 ~Launcher();38 ~Launcher();
3839
39 virtual long ProcessEvent(nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo);40 virtual long ProcessEvent(nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
40 virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);41 virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
41 virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);42 virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
42 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);43 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
4344
44 LauncherIcon* GetActiveTooltipIcon() {return m_ActiveTooltipIcon;}45 LauncherIcon* GetActiveTooltipIcon() {return m_ActiveTooltipIcon;}
45 LauncherIcon* GetActiveMenuIcon() {return m_ActiveMenuIcon;}46 LauncherIcon* GetActiveMenuIcon() {return m_ActiveMenuIcon;}
4647
47 bool TooltipNotify(LauncherIcon* Icon);48 bool TooltipNotify(LauncherIcon* Icon);
48 bool MenuNotify(LauncherIcon* Icon);49 bool MenuNotify(LauncherIcon* Icon);
49 50
50 void SetIconSize(int tile_size, int icon_size);51 void SetIconSize(int tile_size, int icon_size);
51 void NotifyMenuTermination(LauncherIcon* Icon);52 void NotifyMenuTermination(LauncherIcon* Icon);
52 53
53 void SetModel (LauncherModel *model);54 void SetModel (LauncherModel *model);
54 55
55 void SetFloating (bool floating);56 void SetFloating (bool floating);
56 57
57 void SetAutohide (bool autohide, nux::View *show_trigger);58 void SetAutohide (bool autohide, nux::View *show_trigger);
58 bool AutohideEnabled ();59 bool AutohideEnabled ();
59 60
60 virtual void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);61 virtual void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
61 virtual void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);62 virtual void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
62 virtual void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);63 virtual void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
63 virtual void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);64 virtual void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
64 virtual void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);65 virtual void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
65 virtual void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);66 virtual void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
66 virtual void RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags);67 virtual void RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags);
6768
69
70 //! Called by LauncherIcon to signal that a Quicklist is becoming active.
71 void SetActiveQuicklist (QuicklistView *quicklist);
72 //! Get the active qicklist
73 QuicklistView *GetActiveQuicklist ();
74 //! Called by LauncherIcon to signal that a Quicklist is becoming unactive.
75 void CancelActiveQuicklist (QuicklistView *quicklist);
76
68private:77private:
69 typedef enum78 typedef enum
70 {79 {
@@ -140,6 +149,7 @@
140 virtual void PreLayoutManagement();149 virtual void PreLayoutManagement();
141 virtual long PostLayoutManagement(long LayoutResult);150 virtual long PostLayoutManagement(long LayoutResult);
142 virtual void PositionChildLayout(float offsetX, float offsetY);151 virtual void PositionChildLayout(float offsetX, float offsetY);
152
143153
144 nux::HLayout* m_Layout;154 nux::HLayout* m_Layout;
145 int m_ContentOffsetY;155 int m_ContentOffsetY;
@@ -147,6 +157,9 @@
147 LauncherIcon* m_ActiveTooltipIcon;157 LauncherIcon* m_ActiveTooltipIcon;
148 LauncherIcon* m_ActiveMenuIcon;158 LauncherIcon* m_ActiveMenuIcon;
149159
160
161 QuicklistView* _active_quicklist;
162
150 bool _hovered;163 bool _hovered;
151 bool _floating;164 bool _floating;
152 bool _autohide;165 bool _autohide;
153166
=== modified file 'src/LauncherIcon.cpp'
--- src/LauncherIcon.cpp 2010-11-14 03:08:14 +0000
+++ src/LauncherIcon.cpp 2010-11-18 14:03:47 +0000
@@ -33,10 +33,13 @@
3333
34#define DEFAULT_ICON "application-default-icon"34#define DEFAULT_ICON "application-default-icon"
3535
36LauncherIcon::LauncherIcon(Launcher* IconManager)36nux::Tooltip *LauncherIcon::_current_tooltip = 0;
37QuicklistView *LauncherIcon::_current_quicklist = 0;
38
39LauncherIcon::LauncherIcon(Launcher* launcher)
37{40{
38 _folding_angle = 0;41 _folding_angle = 0;
39 m_IconManager = IconManager;42 _launcher = launcher;
40 m_TooltipText = "blank";43 m_TooltipText = "blank";
4144
42 _show_time.tv_sec = 0;45 _show_time.tv_sec = 0;
@@ -67,8 +70,16 @@
67 _icon_type = LAUNCHER_ICON_TYPE_NONE;70 _icon_type = LAUNCHER_ICON_TYPE_NONE;
68 _sort_priority = 0;71 _sort_priority = 0;
6972
73 _quicklist = new QuicklistView ();
74 _quicklist->sigVisible.connect (sigc::mem_fun (this, &LauncherIcon::RecvShowQuicklist));
75 _quicklist->sigHidden.connect (sigc::mem_fun (this, &LauncherIcon::RecvHideQuicklist));
76 _quicklist_is_initialized = false;
77
70 MouseEnter.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseEnter));78 MouseEnter.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseEnter));
71 MouseLeave.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseLeave));79 MouseLeave.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseLeave));
80 MouseDown.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseDown));
81 MouseUp.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseUp));
82
72}83}
7384
74LauncherIcon::~LauncherIcon()85LauncherIcon::~LauncherIcon()
@@ -206,17 +217,47 @@
206void217void
207LauncherIcon::RecvMouseEnter ()218LauncherIcon::RecvMouseEnter ()
208{219{
209 int icon_x = _xform_screen_coord[0].x;220 if (_quicklist_is_initialized == false)
221 {
222 std::list<DbusmenuClient *> menus_list = Menus ();
223 std::list<DbusmenuClient *>::iterator it;
224 for (it = menus_list.begin (); it != menus_list.end (); it++)
225 {
226 g_signal_connect(G_OBJECT(*it), DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(&LauncherIcon::root_changed), _quicklist);
227 dbusmenu_client_add_type_handler (*it, DBUSMENU_CLIENT_TYPES_DEFAULT, (&LauncherIcon::label_handler));
228 dbusmenu_client_add_type_handler (*it, DBUSMENU_CLIENT_TYPES_SEPARATOR, (&LauncherIcon::separator_handler));
229 }
230
231 _quicklist_is_initialized = true;
232 }
233
234 if (_launcher->GetActiveQuicklist ())
235 {
236 // A quicklist is active
237 return;
238 }
239
240// int icon_x = _xform_screen_coord[0].x;
241// int icon_y = _xform_screen_coord[0].y;
242// int icon_w = _xform_screen_coord[2].x - _xform_screen_coord[0].x;
243// int icon_h = _xform_screen_coord[2].y - _xform_screen_coord[0].y;
244
245 //int icon_x = _xform_screen_coord[0].x;
210 int icon_y = _xform_screen_coord[0].y;246 int icon_y = _xform_screen_coord[0].y;
211 int icon_w = _xform_screen_coord[2].x - _xform_screen_coord[0].x;247 //int icon_w = _xform_screen_coord[2].x - _xform_screen_coord[0].x;
212 int icon_h = _xform_screen_coord[2].y - _xform_screen_coord[0].y;248 int icon_h = _xform_screen_coord[2].y - _xform_screen_coord[0].y;
213249
214 _tooltip->SetBaseX (icon_x + icon_w - 10);250 int tip_x = _launcher->GetBaseWidth () + 1; //icon_x + icon_w;
215 _tooltip->SetBaseY (icon_y +251 int tip_y = 24 + // The BaseWindow where the launcher resides is 24 pixels away from the top of the screen: find a better way to get that number.
216 23 + // TODO: HARCODED, replace m_IconManager->GetBaseY ()252 icon_y +
217 (icon_h / 2) -253 (icon_h / 2);
218 (_tooltip->GetBaseHeight () / 2));254
219 _tooltip->ShowWindow (true);255 _tooltip->ShowTooltipWithTipAt (tip_x, tip_y);
256
257 if (!_quicklist->IsVisible ())
258 {
259 _tooltip->ShowWindow (true);
260 }
220}261}
221262
222void LauncherIcon::RecvMouseLeave ()263void LauncherIcon::RecvMouseLeave ()
@@ -224,6 +265,112 @@
224 _tooltip->ShowWindow (false);265 _tooltip->ShowWindow (false);
225}266}
226267
268
269gboolean LauncherIcon::label_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
270{
271 //const gchar* s = dbusmenu_menuitem_property_get (newitem, DBUSMENU_MENUITEM_PROP_LABEL);
272 //printf ("label: %s\n", s);
273
274 return true;
275}
276
277gboolean LauncherIcon::separator_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
278{
279 //const gchar* s = dbusmenu_menuitem_property_get (newitem, DBUSMENU_MENUITEM_PROP_LABEL);
280 //printf ("separator: %s\n", s);
281
282 return true;
283}
284
285void LauncherIcon::child_realized (DbusmenuMenuitem *newitem, QuicklistView *quicklist)
286{
287 const gchar* label = dbusmenu_menuitem_property_get (newitem, DBUSMENU_MENUITEM_PROP_LABEL);
288 const gchar* type = dbusmenu_menuitem_property_get (newitem, DBUSMENU_MENUITEM_PROP_TYPE);
289
290 if (g_strcmp0 (type, DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0)
291 {
292 quicklist->AddMenuItem ("-----------------");
293 }
294 else
295 {
296 quicklist->AddMenuItem (label);
297 }
298
299}
300
301void LauncherIcon::root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, QuicklistView *quicklist)
302{
303 GList * child = NULL;
304 for (child = dbusmenu_menuitem_get_children(newroot); child != NULL; child = g_list_next(child))
305 {
306 g_signal_connect(G_OBJECT(child->data), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(child_realized), quicklist);
307 }
308}
309
310void LauncherIcon::RecvMouseDown (int button)
311{
312 if (button == 3)
313 {
314 if (_launcher->GetActiveQuicklist () == _quicklist)
315 {
316 // this quicklist is already active
317 return;
318 }
319
320 if (_launcher->GetActiveQuicklist ())
321 {
322 // Hide the active quicklist. This will prevent it from Ungrabing the pointer in
323 // QuicklistView::RecvMouseDownOutsideOfQuicklist or void QuicklistView::RecvMouseClick.
324 // So the new quicklist that is about to be set as active will keep the grab of the pointer.
325 // Also disable theinput window.
326 _launcher->GetActiveQuicklist ()->EnableInputWindow (false);
327 _launcher->GetActiveQuicklist ()->CaptureMouseDownAnyWhereElse (false);
328 // This call must be last, because after, _launcher->GetActiveQuicklist () will return Null.
329 // the launcher listen to the sigHidden signal emitted by the BaseWindow when it becomes invisible
330 // and it set the active window to Null.
331 _launcher->GetActiveQuicklist ()->ShowWindow (false);
332 }
333
334 _tooltip->ShowWindow (false);
335
336
337 //int icon_x = _xform_screen_coord[0].x;
338 int icon_y = _xform_screen_coord[0].y;
339 //int icon_w = _xform_screen_coord[2].x - _xform_screen_coord[0].x;
340 int icon_h = _xform_screen_coord[2].y - _xform_screen_coord[0].y;
341
342 int tip_x = _launcher->GetBaseWidth () + 1; //icon_x + icon_w;
343 int tip_y = 24 + // The BaseWindow where the launcher resides is 24 pixels away from the top of the screen: find a better way to get that number.
344 icon_y +
345 (icon_h / 2);
346
347 _quicklist->ShowQuicklistWithTipAt (tip_x, tip_y);
348 _quicklist->EnableInputWindow (true);
349 _quicklist->GrabPointer ();
350 nux::GetWindowCompositor ().SetAlwaysOnFrontWindow (_quicklist);
351 _quicklist->NeedRedraw ();
352 }
353}
354
355void LauncherIcon::RecvMouseUp (int button)
356{
357 if (button == 3)
358 {
359 if (_quicklist->IsVisible ())
360 _quicklist->CaptureMouseDownAnyWhereElse (true);
361 }
362}
363
364void LauncherIcon::RecvShowQuicklist (nux::BaseWindow *quicklist)
365{
366 _launcher->SetActiveQuicklist (_quicklist);
367}
368
369void LauncherIcon::RecvHideQuicklist (nux::BaseWindow *quicklist)
370{
371 _launcher->CancelActiveQuicklist (_quicklist);
372}
373
227void LauncherIcon::HideTooltip ()374void LauncherIcon::HideTooltip ()
228{375{
229 _tooltip->ShowWindow (false);376 _tooltip->ShowWindow (false);
230377
=== modified file 'src/LauncherIcon.h'
--- src/LauncherIcon.h 2010-11-14 06:23:18 +0000
+++ src/LauncherIcon.h 2010-11-18 14:03:47 +0000
@@ -33,8 +33,10 @@
33#include <libdbusmenu-glib/client.h>33#include <libdbusmenu-glib/client.h>
3434
35#include "Tooltip.h"35#include "Tooltip.h"
36#include "QuicklistView.h"
3637
37class Launcher;38class Launcher;
39class QuicklistView;
3840
39typedef enum41typedef enum
40{42{
@@ -51,7 +53,7 @@
51class LauncherIcon : public nux::InitiallyUnownedObject, public sigc::trackable53class LauncherIcon : public nux::InitiallyUnownedObject, public sigc::trackable
52{54{
53public:55public:
54 LauncherIcon(Launcher* IconManager);56 LauncherIcon(Launcher* launcher);
55 ~LauncherIcon();57 ~LauncherIcon();
5658
57 void SetTooltipText (const TCHAR* text);59 void SetTooltipText (const TCHAR* text);
@@ -66,6 +68,11 @@
6668
67 void RecvMouseEnter ();69 void RecvMouseEnter ();
68 void RecvMouseLeave ();70 void RecvMouseLeave ();
71 void RecvMouseDown (int button);
72 void RecvMouseUp (int button);
73
74 void RecvShowQuicklist (nux::BaseWindow *quicklist);
75 void RecvHideQuicklist (nux::BaseWindow *quicklist);
69 76
70 void HideTooltip ();77 void HideTooltip ();
71 78
@@ -121,20 +128,30 @@
121 nux::NString m_TooltipText;128 nux::NString m_TooltipText;
122 //! the window this icon belong too.129 //! the window this icon belong too.
123 nux::BaseWindow* m_Window;130 nux::BaseWindow* m_Window;
124 Launcher* m_IconManager;131 Launcher* _launcher;
125132
126 nux::Vector4 _xform_screen_coord [4];133 nux::Vector4 _xform_screen_coord [4];
127 nux::Vector4 _xform_icon_screen_coord [4];134 nux::Vector4 _xform_icon_screen_coord [4];
128 bool _mouse_inside;135 bool _mouse_inside;
129 float _folding_angle;136 float _folding_angle;
130137
131 nux::Tooltip* _tooltip;138 nux::Tooltip *_tooltip;
139 QuicklistView *_quicklist;
140
141 static nux::Tooltip *_current_tooltip;
142 static QuicklistView *_current_quicklist;
132143
133144
134 friend class Launcher;145 friend class Launcher;
135 friend class LauncherController;146 friend class LauncherController;
136147
137private:148private:
149
150 static gboolean label_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client);
151 static gboolean separator_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client);
152
153 static void child_realized (DbusmenuMenuitem *newitem, QuicklistView *quicklist);
154 static void root_changed (DbusmenuClient * client, DbusmenuMenuitem *newroot, QuicklistView *quicklist);
138 static gboolean OnPresentTimeout (gpointer data);155 static gboolean OnPresentTimeout (gpointer data);
139156
140 nux::Color ColorForIcon (GdkPixbuf *pixbuf);157 nux::Color ColorForIcon (GdkPixbuf *pixbuf);
@@ -148,6 +165,7 @@
148 int _sort_priority;165 int _sort_priority;
149 int _related_windows;166 int _related_windows;
150 guint _present_time_handle;167 guint _present_time_handle;
168 bool _quicklist_is_initialized;
151 169
152 LauncherIconType _icon_type;170 LauncherIconType _icon_type;
153 171
154172
=== modified file 'src/QuicklistView.cpp'
--- src/QuicklistView.cpp 2010-11-11 10:46:30 +0000
+++ src/QuicklistView.cpp 2010-11-18 14:03:47 +0000
@@ -1,21 +1,21 @@
1/*1/*
2 * Copyright (C) 2010 Canonical Ltd2* Copyright (C) 2010 Canonical Ltd
3 *3*
4 * This program is free software: you can redistribute it and/or modify4* 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 as5* it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.6* published by the Free Software Foundation.
7 *7*
8 * This program is distributed in the hope that it will be useful,8* This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.11* GNU General Public License for more details.
12 *12*
13 * You should have received a copy of the GNU General Public License13* 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/>.14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *15*
16 * Authored by: Jay Taoko <jay.taoko@canonical.com>16* Authored by: Jay Taoko <jay.taoko@canonical.com>
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com17* Authored by: Mirco Müller <mirco.mueller@canonical.com
18 */18*/
1919
20#include "Nux/Nux.h"20#include "Nux/Nux.h"
21#include "Nux/VLayout.h"21#include "Nux/VLayout.h"
@@ -30,480 +30,701 @@
3030
31#include "QuicklistView.h"31#include "QuicklistView.h"
3232
33namespace nux33
34{34NUX_IMPLEMENT_OBJECT_TYPE (QuicklistView);
35 NUX_IMPLEMENT_OBJECT_TYPE (QuicklistView);35
36 36QuicklistView::QuicklistView ()
37 QuicklistView::QuicklistView ()37{
38 {38 _texture_bg = 0;
39 _texture_bg = 0;39 _texture_mask = 0;
40 _texture_mask = 0;40 _texture_outline = 0;
41 _texture_outline = 0;41 _cairo_text_has_changed = true;
42 _cairo_text_has_changed = true;42
4343 _anchorX = 0;
44 _anchorX = 0;44 _anchorY = 0;
45 _anchorY = 0;45 _labelText = TEXT ("QuicklistView 1234567890");
46 _labelText = TEXT ("QuicklistView 1234567890");46
4747 _anchor_width = 10;
48 _anchor_width = 10;48 _anchor_height = 18;
49 _anchor_height = 18;49 _corner_radius = 4;
50 _corner_radius = 4;50 _padding = 13;
51 _padding = 10;51 _top_size = 4;
5252
53 _hlayout = new nux::HLayout (TEXT(""), NUX_TRACKER_LOCATION);53 _hlayout = new nux::HLayout (TEXT(""), NUX_TRACKER_LOCATION);
54 _vlayout = new nux::VLayout (TEXT(""), NUX_TRACKER_LOCATION);54 _vlayout = new nux::VLayout (TEXT(""), NUX_TRACKER_LOCATION);
5555 _item_layout = new nux::VLayout (TEXT(""), NUX_TRACKER_LOCATION);
56 _left_space = new nux::SpaceLayout (_padding + _anchor_width + _corner_radius, _padding + _anchor_width + _corner_radius, 1, 1000);56 _default_item_layout = new nux::VLayout (TEXT(""), NUX_TRACKER_LOCATION);
57 _right_space = new nux::SpaceLayout (_padding + _corner_radius, _padding + _corner_radius, 1, 1000);57
5858 _left_space = new nux::SpaceLayout (_padding + _anchor_width + _corner_radius, _padding + _anchor_width + _corner_radius, 1, 1000);
59 _top_space = new nux::SpaceLayout (1, 1000, _padding + _corner_radius, _padding + _corner_radius);59 _right_space = new nux::SpaceLayout (_padding + _corner_radius, _padding + _corner_radius, 1, 1000);
60 _bottom_space = new nux::SpaceLayout (1, 1000, _padding + _corner_radius, _padding + _corner_radius);60
6161 _top_space = new nux::SpaceLayout (1, 1000, _padding + _corner_radius, _padding + _corner_radius);
62 _vlayout->AddLayout(_top_space, 0);62 _bottom_space = new nux::SpaceLayout (1, 1000, _padding + _corner_radius, _padding + _corner_radius);
6363
64 for (int i = 0; i < 5; i++)64 _vlayout->AddLayout (_top_space, 0);
65 {65
66 nux::StaticCairoText* tooltip_text;66 _vlayout->AddLayout (_item_layout, 0);
67 if (i == 0)67
68 tooltip_text = new nux::StaticCairoText (TEXT ("1234567890"), NUX_TRACKER_LOCATION);68 _vlayout->AddLayout (_default_item_layout, 0);
69 else69
70 tooltip_text = new nux::StaticCairoText (TEXT ("QuicklistView 1234567890"), NUX_TRACKER_LOCATION);70 for (int i = 0; i < 2; i++)
7171 {
72 tooltip_text->sigTextChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextChanged));72 nux::StaticCairoText* item_text;
73 _vlayout->AddView(tooltip_text, 1, eCenter, eFull);73 item_text = new nux::StaticCairoText (TEXT ("Default Item"), NUX_TRACKER_LOCATION);
74 _item_list.push_back (tooltip_text);74
75 tooltip_text->Reference();75 item_text->sigTextChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextChanged));
76 }76 item_text->sigTextColorChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextColorChanged));
7777 _default_item_layout->AddView(item_text, 1, nux::eCenter, nux::eFull);
78 _vlayout->AddLayout(_bottom_space, 0);78 _default_item_list.push_back (item_text);
79 79 item_text->Reference();
80 _hlayout->AddLayout(_left_space, 0);80 }
81 _hlayout->AddLayout(_vlayout, 1, eCenter, eFull);81
82 _hlayout->AddLayout(_right_space, 0);82 _vlayout->AddLayout (_bottom_space, 0);
8383
84 SetWindowSizeMatchLayout (true);84 _hlayout->AddLayout (_left_space, 0);
85 SetLayout (_hlayout);85 _hlayout->AddLayout (_vlayout, 1, nux::eCenter, nux::eFull);
86 86 _hlayout->AddLayout (_right_space, 0);
87 }87
8888 SetWindowSizeMatchLayout (true);
89 QuicklistView::~QuicklistView ()89 SetLayout (_hlayout);
90 {90
91 if (_texture_bg)91 OnMouseDownOutsideArea.connect (sigc::mem_fun (this, &QuicklistView::RecvMouseDownOutsideOfQuicklist));
92 _texture_bg->UnReference ();92 OnMouseDown.connect (sigc::mem_fun (this, &QuicklistView::RecvMouseDown));
9393 OnMouseUp.connect (sigc::mem_fun (this, &QuicklistView::RecvMouseUp));
94 std::list<nux::StaticCairoText*>::iterator it;94 OnMouseClick.connect (sigc::mem_fun (this, &QuicklistView::RecvMouseClick));
95 for (it = _item_list.begin(); it != _item_list.end(); it++)95 OnMouseMove.connect (sigc::mem_fun (this, &QuicklistView::RecvMouseMove));
96 {96 OnMouseDrag.connect (sigc::mem_fun (this, &QuicklistView::RecvMouseDrag));
97 (*it)->UnReference();97
98 }98}
99 _item_list.clear ();99
100 }100QuicklistView::~QuicklistView ()
101101{
102 long QuicklistView::ProcessEvent (IEvent& ievent, long TraverseInfo, long ProcessEventInfo)102 if (_texture_bg)
103 {103 _texture_bg->UnReference ();
104 long ret = TraverseInfo;104
105 std::list<nux::StaticCairoText*>::iterator it;105 std::list<nux::StaticCairoText*>::iterator it;
106 for (it = _item_list.begin(); it != _item_list.end(); it++)106 for (it = _item_list.begin(); it != _item_list.end(); it++)
107 {107 {
108 ret = (*it)->ProcessEvent(ievent, ret, ProcessEventInfo);108 (*it)->UnReference();
109 }109 }
110 return ret;110 _item_list.clear ();
111 }111}
112112
113 void QuicklistView::Draw (GraphicsEngine& gfxContext, bool forceDraw)113void QuicklistView::ShowQuicklistWithTipAt (int anchor_tip_x, int anchor_tip_y)
114 {114{
115 Geometry base = GetGeometry();115 int window_width;
116116 int window_height;
117 // the elements position inside the window are referenced to top-left window117
118 // corner. So bring base to (0, 0).118 window_width = nux::GetWindow ().GetWindowWidth ();
119 base.SetX (0);119 window_height = nux::GetWindow ().GetWindowHeight ();
120 base.SetY (0);120
121 gfxContext.PushClippingRectangle (base);121 _anchorX = anchor_tip_x;
122122 _anchorY = anchor_tip_y;
123 GetGraphicsEngine().GetRenderStates().SetBlend (false, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);123
124124 int x = _anchorX - _padding;
125 TexCoordXForm texxform_bg;125 int y = anchor_tip_y - _anchor_height/2 - _top_size - _corner_radius - _padding;
126 texxform_bg.SetWrap(TEXWRAP_CLAMP, TEXWRAP_CLAMP);126
127 texxform_bg.SetTexCoordType (TexCoordXForm::OFFSET_COORD);127 SetBaseX (x);
128128 SetBaseY (y);
129 TexCoordXForm texxform_mask;129
130 texxform_mask.SetWrap(TEXWRAP_CLAMP, TEXWRAP_CLAMP);130 ShowWindow (true);
131 texxform_mask.SetTexCoordType (TexCoordXForm::OFFSET_COORD);131}
132132
133133void QuicklistView::ShowWindow (bool b, bool start_modal)
134 gfxContext.QRP_GLSL_2TexMod (base.x,134{
135 base.y,135 BaseWindow::ShowWindow (b, start_modal);
136 base.width,136
137 base.height,137 // Reset all colors to white
138 _texture_bg->GetDeviceTexture(),138 std::list<nux::StaticCairoText*>::iterator it;
139 texxform_bg,139 for (it = _item_list.begin(); it != _item_list.end(); it++)
140 Color(1.0f, 1.0f, 1.0f, 1.0f),140 {
141 _texture_mask->GetDeviceTexture(),141 (*it)->SetTextColor (nux::Color::White);
142 texxform_mask,142 }
143 Color(1.0f, 1.0f, 1.0f, 1.0f));143}
144144
145145long QuicklistView::ProcessEvent (nux::IEvent& ievent, long TraverseInfo, long ProcessEventInfo)
146 TexCoordXForm texxform;146{
147 texxform.SetWrap(TEXWRAP_CLAMP, TEXWRAP_CLAMP);147 long ret = TraverseInfo;
148 texxform.SetTexCoordType (TexCoordXForm::OFFSET_COORD);148 long ProcEvInfo = 0;
149149
150 GetGraphicsEngine().GetRenderStates().SetBlend (true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);150 nux::IEvent window_event = ievent;
151 gfxContext.QRP_GLSL_1Tex (base.x,151 nux::Geometry base = GetGeometry();
152 base.y,152 window_event.e_x_root = base.x;
153 base.width,153 window_event.e_y_root = base.y;
154 base.height,154
155 _texture_outline->GetDeviceTexture(),155 // The child layout get the Mouse down button only if the MouseDown happened inside the client view Area
156 texxform,156 nux::Geometry viewGeometry = GetGeometry();
157 Color(1.0f, 1.0f, 1.0f, 1.0f));157
158158 if (ievent.e_event == nux::NUX_MOUSE_PRESSED)
159 GetGraphicsEngine().GetRenderStates().SetBlend (false);159 {
160160 if (!viewGeometry.IsPointInside (ievent.e_x - ievent.e_x_root, ievent.e_y - ievent.e_y_root) )
161 std::list<nux::StaticCairoText*>::iterator it;161 {
162 for (it = _item_list.begin(); it != _item_list.end(); it++)162 ProcEvInfo = nux::eDoNotProcess;
163 {163 }
164 (*it)->ProcessDraw(gfxContext, forceDraw);164 }
165 }165
166166 // We choose to test the quicklist items ourselves instead of processing them as it is usual in nux.
167 gfxContext.PopClippingRectangle ();167 // This is meantto be easier since the quicklist has a atypical way of working.
168 }168 // if (m_layout)
169169 // ret = m_layout->ProcessEvent (window_event, ret, ProcEvInfo);
170 void QuicklistView::DrawContent (GraphicsEngine& GfxContext, bool force_draw)170
171 {171 // PostProcessEvent2 must always have its last parameter set to 0
172172 // because the m_BackgroundArea is the real physical limit of the window.
173 }173 // So the previous test about IsPointInside do not prevail over m_BackgroundArea
174174 // testing the event by itself.
175 void QuicklistView::PreLayoutManagement ()175 ret = PostProcessEvent2 (ievent, ret, 0);
176 {176 return ret;
177 int MaxItemWidth = 0;177}
178 int TotalItemHeight = 0;178
179 179void QuicklistView::Draw (nux::GraphicsEngine& gfxContext, bool forceDraw)
180 std::list<nux::StaticCairoText*>::iterator it;180{
181 for (it = _item_list.begin(); it != _item_list.end(); it++)181 nux::Geometry base = GetGeometry();
182 {182
183 int textWidth = 0;183 // the elements position inside the window are referenced to top-left window
184 int textHeight = 0;184 // corner. So bring base to (0, 0).
185 (*it)->GetTextExtents(textWidth, textHeight);185 base.SetX (0);
186 if (textWidth > MaxItemWidth)186 base.SetY (0);
187 MaxItemWidth = textWidth;187 gfxContext.PushClippingRectangle (base);
188 TotalItemHeight += textHeight;188
189 }189 nux::GetGraphicsEngine().GetRenderStates().SetBlend (false, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
190190
191 if(TotalItemHeight < _anchor_height)191 nux::TexCoordXForm texxform_bg;
192 {192 texxform_bg.SetWrap(nux::TEXWRAP_CLAMP, nux::TEXWRAP_CLAMP);
193 _top_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight)/2 +1 + _padding + _corner_radius);193 texxform_bg.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
194 _bottom_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight)/2 +1 + _padding + _corner_radius);194
195 }195 nux::TexCoordXForm texxform_mask;
196196 texxform_mask.SetWrap(nux::TEXWRAP_CLAMP, nux::TEXWRAP_CLAMP);
197 BaseWindow::PreLayoutManagement ();197 texxform_mask.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
198 }198
199199
200 long QuicklistView::PostLayoutManagement (long LayoutResult)200 gfxContext.QRP_GLSL_2TexMod (base.x,
201 {201 base.y,
202 long result = BaseWindow::PostLayoutManagement (LayoutResult);202 base.width,
203 UpdateTexture ();203 base.height,
204204 _texture_bg->GetDeviceTexture(),
205 int x = _padding + _anchor_width + _corner_radius;205 texxform_bg,
206 int y = _padding + _corner_radius;206 nux::Color(1.0f, 1.0f, 1.0f, 1.0f),
207207 _texture_mask->GetDeviceTexture(),
208 std::list<nux::StaticCairoText*>::iterator it;208 texxform_mask,
209 for (it = _item_list.begin(); it != _item_list.end(); it++)209 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
210 {210
211 (*it)->SetBaseX (x);211
212 (*it)->SetBaseY (y);212 nux::TexCoordXForm texxform;
213213 texxform.SetWrap(nux::TEXWRAP_CLAMP, nux::TEXWRAP_CLAMP);
214 y += (*it)->GetBaseHeight ();214 texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
215 }215
216216 nux::GetGraphicsEngine().GetRenderStates().SetBlend (true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
217 return result;217 gfxContext.QRP_GLSL_1Tex (base.x,
218 }218 base.y,
219219 base.width,
220 void QuicklistView::RecvCairoTextChanged (StaticCairoText& cairo_text)220 base.height,
221 {221 _texture_outline->GetDeviceTexture(),
222 _cairo_text_has_changed = true;222 texxform,
223 }223 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
224224
225/////////////////////////////////////////////////////////////////////////////////////////////////225 nux::GetGraphicsEngine().GetRenderStates().SetBlend (false);
226/////////////////////////////////////////////////////////////////////////////////////////////////226
227/////////////////////////////////////////////////////////////////////////////////////////////////227 std::list<nux::StaticCairoText*>::iterator it;
228228 for (it = _item_list.begin(); it != _item_list.end(); it++)
229 static inline void ql_blurinner (guchar* pixel,229 {
230 gint *zR,230 (*it)->ProcessDraw(gfxContext, forceDraw);
231 gint *zG,231 }
232 gint *zB,232
233 gint *zA,233 for (it = _default_item_list.begin(); it != _default_item_list.end(); it++)
234 gint alpha,234 {
235 gint aprec,235 (*it)->ProcessDraw(gfxContext, forceDraw);
236 gint zprec)236 }
237 {237
238 gint R;238
239 gint G;239 gfxContext.PopClippingRectangle ();
240 gint B;240}
241 guchar A;241
242242void QuicklistView::DrawContent (nux::GraphicsEngine& GfxContext, bool force_draw)
243 R = *pixel;243{
244 G = *(pixel + 1);244
245 B = *(pixel + 2);245}
246 A = *(pixel + 3);246
247247void QuicklistView::PreLayoutManagement ()
248 *zR += (alpha * ((R << zprec) - *zR)) >> aprec;248{
249 *zG += (alpha * ((G << zprec) - *zG)) >> aprec;249 int MaxItemWidth = 0;
250 *zB += (alpha * ((B << zprec) - *zB)) >> aprec;250 int TotalItemHeight = 0;
251 *zA += (alpha * ((A << zprec) - *zA)) >> aprec;251
252252 std::list<nux::StaticCairoText*>::iterator it;
253 *pixel = *zR >> zprec;253 for (it = _item_list.begin(); it != _item_list.end(); it++)
254 *(pixel + 1) = *zG >> zprec;254 {
255 *(pixel + 2) = *zB >> zprec;255 int textWidth = 0;
256 *(pixel + 3) = *zA >> zprec;256 int textHeight = 0;
257 }257 (*it)->GetTextExtents(textWidth, textHeight);
258258 if (textWidth > MaxItemWidth)
259 static inline void ql_blurrow (guchar* pixels,259 MaxItemWidth = textWidth;
260 gint width,260 TotalItemHeight += textHeight;
261 gint height,261 }
262 gint channels,262
263 gint line,263 for (it = _default_item_list.begin(); it != _default_item_list.end(); it++)
264 gint alpha,264 {
265 gint aprec,265 int textWidth = 0;
266 gint zprec)266 int textHeight = 0;
267 {267 (*it)->GetTextExtents(textWidth, textHeight);
268 gint zR;268 if (textWidth > MaxItemWidth)
269 gint zG;269 MaxItemWidth = textWidth;
270 gint zB;270 TotalItemHeight += textHeight;
271 gint zA;271 }
272 gint index;272
273 guchar* scanline;273 if(TotalItemHeight < _anchor_height)
274274 {
275 scanline = &(pixels[line * width * channels]);275 _top_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight)/2 +1 + _padding + _corner_radius);
276276 _bottom_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight)/2 +1 + _padding + _corner_radius);
277 zR = *scanline << zprec;277 }
278 zG = *(scanline + 1) << zprec;278
279 zB = *(scanline + 2) << zprec;279 BaseWindow::PreLayoutManagement ();
280 zA = *(scanline + 3) << zprec;280}
281281
282 for (index = 0; index < width; index ++)282long QuicklistView::PostLayoutManagement (long LayoutResult)
283 ql_blurinner (&scanline[index * channels], &zR, &zG, &zB, &zA, alpha, aprec,283{
284 zprec);284 long result = BaseWindow::PostLayoutManagement (LayoutResult);
285285 UpdateTexture ();
286 for (index = width - 2; index >= 0; index--)286
287 ql_blurinner (&scanline[index * channels], &zR, &zG, &zB, &zA, alpha, aprec,287 int x = _padding + _anchor_width + _corner_radius;
288 zprec);288 int y = _padding + _corner_radius;
289 }289
290290 std::list<nux::StaticCairoText*>::iterator it;
291 static inline void ql_blurcol (guchar* pixels,291 for (it = _item_list.begin(); it != _item_list.end(); it++)
292 gint width,292 {
293 gint height,293 (*it)->SetBaseX (x);
294 gint channels,294 (*it)->SetBaseY (y);
295 gint x,295
296 gint alpha,296 y += (*it)->GetBaseHeight ();
297 gint aprec,297 }
298 gint zprec)298
299 {299 for (it = _default_item_list.begin(); it != _default_item_list.end(); it++)
300 gint zR;300 {
301 gint zG;301 (*it)->SetBaseX (x);
302 gint zB;302 (*it)->SetBaseY (y);
303 gint zA;303
304 gint index;304 y += (*it)->GetBaseHeight ();
305 guchar* ptr;305 }
306306
307 ptr = pixels;307 return result;
308308}
309 ptr += x * channels;309
310310void QuicklistView::RecvCairoTextChanged (nux::StaticCairoText& cairo_text)
311 zR = *((guchar*) ptr ) << zprec;311{
312 zG = *((guchar*) ptr + 1) << zprec;312 _cairo_text_has_changed = true;
313 zB = *((guchar*) ptr + 2) << zprec;313}
314 zA = *((guchar*) ptr + 3) << zprec;314
315315void QuicklistView::RecvCairoTextColorChanged (nux::StaticCairoText& cairo_text)
316 for (index = width; index < (height - 1) * width; index += width)316{
317 ql_blurinner ((guchar*) &ptr[index * channels], &zR, &zG, &zB, &zA, alpha,317 NeedRedraw ();
318 aprec, zprec);318}
319319
320 for (index = (height - 2) * width; index >= 0; index -= width)320void QuicklistView::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
321 ql_blurinner ((guchar*) &ptr[index * channels], &zR, &zG, &zB, &zA, alpha,321{
322 aprec, zprec);322// if (IsVisible ())
323 }323// {
324324// CaptureMouseDownAnyWhereElse (false);
325 //325// ForceStopFocus (1, 1);
326 // pixels image-data326// UnGrabPointer ();
327 // width image-width327// EnableInputWindow (false);
328 // height image-height328// ShowWindow (false);
329 // channels image-channels329// }
330 //330}
331 // in-place blur of image 'img' with kernel of approximate radius 'radius'331
332 //332void QuicklistView::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
333 // blurs with two sided exponential impulse response333{
334 //334
335 // aprec = precision of alpha parameter in fixed-point format 0.aprec335}
336 //336
337 // zprec = precision of state parameters zR,zG,zB and zA in fp format 8.zprec337void QuicklistView::RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
338 //338{
339 void ql_expblur (guchar* pixels,339 if (IsVisible ())
340 gint width,340 {
341 gint height,341 CaptureMouseDownAnyWhereElse (false);
342 gint channels,342 ForceStopFocus (1, 1);
343 gint radius,343 UnGrabPointer ();
344 gint aprec,344 EnableInputWindow (false);
345 gint zprec)345 ShowWindow (false);
346 {346 }
347 gint alpha;347}
348 gint row = 0;348
349 gint col = 0;349void QuicklistView::RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
350350{
351 if (radius < 1)351 std::list<nux::StaticCairoText*>::iterator it;
352 return;352 for (it = _item_list.begin(); it != _item_list.end(); it++)
353353 {
354 // calculate the alpha such that 90% of 354 if ((*it)->GetGeometry ().IsPointInside (x, y))
355 // the kernel is within the radius.355 {
356 // (Kernel extends to infinity)356 (*it)->SetTextColor (nux::Color::DarkGray);
357 alpha = (gint) ((1 << aprec) * (1.0f - expf (-2.3f / (radius + 1.f))));357 }
358358 else
359 for (; row < height; row++)359 {
360 ql_blurrow (pixels, width, height, channels, row, alpha, aprec, zprec);360 (*it)->SetTextColor (nux::Color::White);
361361 }
362 for(; col < width; col++)362 }
363 ql_blurcol (pixels, width, height, channels, col, alpha, aprec, zprec);363
364364 for (it = _default_item_list.begin(); it != _default_item_list.end(); it++)
365 {
366 if ((*it)->GetGeometry ().IsPointInside (x, y))
367 {
368 (*it)->SetTextColor (nux::Color::DarkGray);
369 }
370 else
371 {
372 (*it)->SetTextColor (nux::Color::White);
373 }
374 }
375}
376
377void QuicklistView::RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
378{
379 std::list<nux::StaticCairoText*>::iterator it;
380 for (it = _item_list.begin(); it != _item_list.end(); it++)
381 {
382 if ((*it)->GetGeometry ().IsPointInside (x, y))
383 {
384 (*it)->SetTextColor (nux::Color::DarkGray);
385 }
386 else
387 {
388 (*it)->SetTextColor (nux::Color::White);
389 }
390 }
391
392 for (it = _default_item_list.begin(); it != _default_item_list.end(); it++)
393 {
394 if ((*it)->GetGeometry ().IsPointInside (x, y))
395 {
396 (*it)->SetTextColor (nux::Color::DarkGray);
397 }
398 else
399 {
400 (*it)->SetTextColor (nux::Color::White);
401 }
402 }
403}
404
405void QuicklistView::RecvMouseDownOutsideOfQuicklist (int x, int y, unsigned long button_flags, unsigned long key_flags)
406{
407 if (IsVisible ())
408 {
409 CaptureMouseDownAnyWhereElse (false);
410 ForceStopFocus (1, 1);
411 UnGrabPointer ();
412 EnableInputWindow (false);
413 ShowWindow (false);
414 }
415}
416
417void QuicklistView::RemoveAllMenuItem ()
418{
419 _item_list.clear ();
420 _item_layout->Clear ();
421 _cairo_text_has_changed = true;
422 nux::GetGraphicsThread ()->AddObjectToRefreshList (this);
423}
424
425void QuicklistView::AddMenuItem (nux::NString str)
426{
427 nux::StaticCairoText* item_text;
428 item_text = new nux::StaticCairoText (str.GetTCharPtr (), NUX_TRACKER_LOCATION);
429
430 item_text->sigTextChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextChanged));
431 item_text->sigTextColorChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextColorChanged));
432 _item_layout->AddView(item_text, 1, nux::eCenter, nux::eFull);
433 _item_list.push_back (item_text);
434 item_text->Reference();
435
436 _cairo_text_has_changed = true;
437 nux::GetGraphicsThread ()->AddObjectToRefreshList (this);
438 NeedRedraw ();
439}
440
441void QuicklistView::RenderQuicklistView ()
442{
443
444}
445
446/////////////////////////////////////////////////////////////////////////////////////////////////
447/////////////////////////////////////////////////////////////////////////////////////////////////
448/////////////////////////////////////////////////////////////////////////////////////////////////
449
450static inline void ql_blurinner (guchar* pixel,
451 gint *zR,
452 gint *zG,
453 gint *zB,
454 gint *zA,
455 gint alpha,
456 gint aprec,
457 gint zprec)
458{
459 gint R;
460 gint G;
461 gint B;
462 guchar A;
463
464 R = *pixel;
465 G = *(pixel + 1);
466 B = *(pixel + 2);
467 A = *(pixel + 3);
468
469 *zR += (alpha * ((R << zprec) - *zR)) >> aprec;
470 *zG += (alpha * ((G << zprec) - *zG)) >> aprec;
471 *zB += (alpha * ((B << zprec) - *zB)) >> aprec;
472 *zA += (alpha * ((A << zprec) - *zA)) >> aprec;
473
474 *pixel = *zR >> zprec;
475 *(pixel + 1) = *zG >> zprec;
476 *(pixel + 2) = *zB >> zprec;
477 *(pixel + 3) = *zA >> zprec;
478}
479
480static inline void ql_blurrow (guchar* pixels,
481 gint width,
482 gint height,
483 gint channels,
484 gint line,
485 gint alpha,
486 gint aprec,
487 gint zprec)
488{
489 gint zR;
490 gint zG;
491 gint zB;
492 gint zA;
493 gint index;
494 guchar* scanline;
495
496 scanline = &(pixels[line * width * channels]);
497
498 zR = *scanline << zprec;
499 zG = *(scanline + 1) << zprec;
500 zB = *(scanline + 2) << zprec;
501 zA = *(scanline + 3) << zprec;
502
503 for (index = 0; index < width; index ++)
504 ql_blurinner (&scanline[index * channels], &zR, &zG, &zB, &zA, alpha, aprec,
505 zprec);
506
507 for (index = width - 2; index >= 0; index--)
508 ql_blurinner (&scanline[index * channels], &zR, &zG, &zB, &zA, alpha, aprec,
509 zprec);
510}
511
512static inline void ql_blurcol (guchar* pixels,
513 gint width,
514 gint height,
515 gint channels,
516 gint x,
517 gint alpha,
518 gint aprec,
519 gint zprec)
520{
521 gint zR;
522 gint zG;
523 gint zB;
524 gint zA;
525 gint index;
526 guchar* ptr;
527
528 ptr = pixels;
529
530 ptr += x * channels;
531
532 zR = *((guchar*) ptr ) << zprec;
533 zG = *((guchar*) ptr + 1) << zprec;
534 zB = *((guchar*) ptr + 2) << zprec;
535 zA = *((guchar*) ptr + 3) << zprec;
536
537 for (index = width; index < (height - 1) * width; index += width)
538 ql_blurinner ((guchar*) &ptr[index * channels], &zR, &zG, &zB, &zA, alpha,
539 aprec, zprec);
540
541 for (index = (height - 2) * width; index >= 0; index -= width)
542 ql_blurinner ((guchar*) &ptr[index * channels], &zR, &zG, &zB, &zA, alpha,
543 aprec, zprec);
544}
545
546//
547// pixels image-data
548// width image-width
549// height image-height
550// channels image-channels
551//
552// in-place blur of image 'img' with kernel of approximate radius 'radius'
553//
554// blurs with two sided exponential impulse response
555//
556// aprec = precision of alpha parameter in fixed-point format 0.aprec
557//
558// zprec = precision of state parameters zR,zG,zB and zA in fp format 8.zprec
559//
560void ql_expblur (guchar* pixels,
561 gint width,
562 gint height,
563 gint channels,
564 gint radius,
565 gint aprec,
566 gint zprec)
567{
568 gint alpha;
569 gint row = 0;
570 gint col = 0;
571
572 if (radius < 1)
365 return;573 return;
366 }574
575 // calculate the alpha such that 90% of
576 // the kernel is within the radius.
577 // (Kernel extends to infinity)
578 alpha = (gint) ((1 << aprec) * (1.0f - expf (-2.3f / (radius + 1.f))));
579
580 for (; row < height; row++)
581 ql_blurrow (pixels, width, height, channels, row, alpha, aprec, zprec);
582
583 for(; col < width; col++)
584 ql_blurcol (pixels, width, height, channels, col, alpha, aprec, zprec);
585
586 return;
587}
367588
368/**589/**
369 * ctk_surface_blur:590* ctk_surface_blur:
370 * @surface: pointer to a cairo image-surface591* @surface: pointer to a cairo image-surface
371 * @radius: unsigned integer acting as the blur-radius to apply592* @radius: unsigned integer acting as the blur-radius to apply
372 *593*
373 * Applies an exponential blur on the passed surface executed on the CPU. Not as594* Applies an exponential blur on the passed surface executed on the CPU. Not as
374 * nice as a real gaussian blur, but much faster.595* nice as a real gaussian blur, but much faster.
375 **/596**/
376void ql_surface_blur (cairo_surface_t* surface,597void ql_surface_blur (cairo_surface_t* surface,
377 guint radius)598 guint radius)
378{599{
379 guchar* pixels;600guchar* pixels;
380 guint width;601guint width;
381 guint height;602guint height;
382 cairo_format_t format;603cairo_format_t format;
383604
384 // before we mess with the surface execute any pending drawing605// before we mess with the surface execute any pending drawing
385 cairo_surface_flush (surface);606cairo_surface_flush (surface);
386607
387 pixels = cairo_image_surface_get_data (surface);608pixels = cairo_image_surface_get_data (surface);
388 width = cairo_image_surface_get_width (surface);609width = cairo_image_surface_get_width (surface);
389 height = cairo_image_surface_get_height (surface);610height = cairo_image_surface_get_height (surface);
390 format = cairo_image_surface_get_format (surface);611format = cairo_image_surface_get_format (surface);
391612
392 switch (format)613switch (format)
393 {614{
394 case CAIRO_FORMAT_ARGB32:615 case CAIRO_FORMAT_ARGB32:
395 ql_expblur (pixels, width, height, 4, radius, 16, 7);616 ql_expblur (pixels, width, height, 4, radius, 16, 7);
396 break;617 break;
397618
398 case CAIRO_FORMAT_RGB24:619 case CAIRO_FORMAT_RGB24:
399 ql_expblur (pixels, width, height, 3, radius, 16, 7);620 ql_expblur (pixels, width, height, 3, radius, 16, 7);
400 break;621 break;
401622
402 case CAIRO_FORMAT_A8:623 case CAIRO_FORMAT_A8:
403 ql_expblur (pixels, width, height, 1, radius, 16, 7);624 ql_expblur (pixels, width, height, 1, radius, 16, 7);
404 break;625 break;
405626
406 default :627 default :
407 // do nothing628 // do nothing
408 break;629 break;
409 }630}
410631
411 // inform cairo we altered the surfaces contents632// inform cairo we altered the surfaces contents
412 cairo_surface_mark_dirty (surface); 633cairo_surface_mark_dirty (surface);
413}634}
414635
415 636
416 void ql_tint_dot_hl (cairo_t* cr,637void ql_tint_dot_hl (cairo_t* cr,
417 gint width,638 gint width,
418 gint height,639 gint height,
419 gfloat hl_x,640 gfloat hl_x,
420 gfloat hl_y,641 gfloat hl_y,
421 gfloat hl_size,642 gfloat hl_size,
422 gfloat* rgba_tint,643 gfloat* rgba_tint,
423 gfloat* rgba_hl,644 gfloat* rgba_hl,
424 gfloat* rgba_dot)645 gfloat* rgba_dot)
425 {646{
426 cairo_surface_t* dots_surf = NULL;647 cairo_surface_t* dots_surf = NULL;
427 cairo_t* dots_cr = NULL;648 cairo_t* dots_cr = NULL;
428 cairo_pattern_t* dots_pattern = NULL;649 cairo_pattern_t* dots_pattern = NULL;
429 cairo_pattern_t* hl_pattern = NULL;650 cairo_pattern_t* hl_pattern = NULL;
430651
431 // create context for dot-pattern652 // create context for dot-pattern
432 dots_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 4, 4);653 dots_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 4, 4);
433 dots_cr = cairo_create (dots_surf);654 dots_cr = cairo_create (dots_surf);
434655
435 // clear normal context656 // clear normal context
436 cairo_scale (cr, 1.0f, 1.0f);657 cairo_scale (cr, 1.0f, 1.0f);
437 cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);658 cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
438 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);659 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
439 cairo_paint (cr);660 cairo_paint (cr);
440661
441 // prepare drawing for normal context662 // prepare drawing for normal context
442 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);663 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
443664
444 // create path in normal context665 // create path in normal context
445 cairo_rectangle (cr, 0.0f, 0.0f, (gdouble) width, (gdouble) height); 666 cairo_rectangle (cr, 0.0f, 0.0f, (gdouble) width, (gdouble) height);
446667
447 // fill path of normal context with tint668 // fill path of normal context with tint
448 cairo_set_source_rgba (cr,669 cairo_set_source_rgba (cr,
449 rgba_tint[0],670 rgba_tint[0],
450 rgba_tint[1],671 rgba_tint[1],
451 rgba_tint[2],672 rgba_tint[2],
452 rgba_tint[3]);673 rgba_tint[3]);
453 cairo_fill_preserve (cr);674 cairo_fill_preserve (cr);
454675
455 // create pattern in dot-context676 // create pattern in dot-context
456 cairo_set_operator (dots_cr, CAIRO_OPERATOR_CLEAR);677 cairo_set_operator (dots_cr, CAIRO_OPERATOR_CLEAR);
457 cairo_paint (dots_cr);678 cairo_paint (dots_cr);
458 cairo_scale (dots_cr, 1.0f, 1.0f);679 cairo_scale (dots_cr, 1.0f, 1.0f);
459 cairo_set_operator (dots_cr, CAIRO_OPERATOR_OVER);680 cairo_set_operator (dots_cr, CAIRO_OPERATOR_OVER);
460 cairo_set_source_rgba (dots_cr,681 cairo_set_source_rgba (dots_cr,
461 rgba_dot[0],682 rgba_dot[0],
462 rgba_dot[1],683 rgba_dot[1],
463 rgba_dot[2],684 rgba_dot[2],
464 rgba_dot[3]);685 rgba_dot[3]);
465 cairo_rectangle (dots_cr, 0.0f, 0.0f, 1.0f, 1.0f);686 cairo_rectangle (dots_cr, 0.0f, 0.0f, 1.0f, 1.0f);
466 cairo_fill (dots_cr);687 cairo_fill (dots_cr);
467 cairo_rectangle (dots_cr, 2.0f, 2.0f, 1.0f, 1.0f);688 cairo_rectangle (dots_cr, 2.0f, 2.0f, 1.0f, 1.0f);
468 cairo_fill (dots_cr);689 cairo_fill (dots_cr);
469 dots_pattern = cairo_pattern_create_for_surface (dots_surf);690 dots_pattern = cairo_pattern_create_for_surface (dots_surf);
470691
471 // fill path of normal context with dot-pattern692 // fill path of normal context with dot-pattern
472 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);693 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
473 cairo_set_source (cr, dots_pattern);694 cairo_set_source (cr, dots_pattern);
474 cairo_pattern_set_extend (dots_pattern, CAIRO_EXTEND_REPEAT);695 cairo_pattern_set_extend (dots_pattern, CAIRO_EXTEND_REPEAT);
475 cairo_fill_preserve (cr);696 cairo_fill_preserve (cr);
476 cairo_pattern_destroy (dots_pattern);697 cairo_pattern_destroy (dots_pattern);
477 cairo_surface_destroy (dots_surf);698 cairo_surface_destroy (dots_surf);
478 cairo_destroy (dots_cr);699 cairo_destroy (dots_cr);
479700
480 // draw highlight701 // draw highlight
481 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);702 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
482 hl_pattern = cairo_pattern_create_radial (hl_x,703 hl_pattern = cairo_pattern_create_radial (hl_x,
483 hl_y,704 hl_y,
484 0.0f,705 0.0f,
485 hl_x,706 hl_x,
486 hl_y,707 hl_y,
487 hl_size);708 hl_size);
488 cairo_pattern_add_color_stop_rgba (hl_pattern,709 cairo_pattern_add_color_stop_rgba (hl_pattern,
489 0.0f,710 0.0f,
490 1.0f,711 1.0f,
491 1.0f,712 1.0f,
492 1.0f,713 1.0f,
493 0.65f);714 0.65f);
494 cairo_pattern_add_color_stop_rgba (hl_pattern, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f);715 cairo_pattern_add_color_stop_rgba (hl_pattern, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f);
495 cairo_set_source (cr, hl_pattern);716 cairo_set_source (cr, hl_pattern);
496 cairo_fill (cr);717 cairo_fill (cr);
497 cairo_pattern_destroy (hl_pattern);718 cairo_pattern_destroy (hl_pattern);
498 }719}
499720
500 void ql_setup (cairo_surface_t** surf,721void ql_setup (cairo_surface_t** surf,
501 cairo_t** cr,722 cairo_t** cr,
502 gboolean outline,723 gboolean outline,
503 gint width,724 gint width,
504 gint height,725 gint height,
505 gboolean negative)726 gboolean negative)
506 {727{
507// // create context728// // create context
508// if (outline)729// if (outline)
509// *surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);730// *surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
@@ -511,401 +732,423 @@
511// *surf = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);732// *surf = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
512// *cr = cairo_create (*surf);733// *cr = cairo_create (*surf);
513734
514 // clear context735 // clear context
515 cairo_scale (*cr, 1.0f, 1.0f);736 cairo_scale (*cr, 1.0f, 1.0f);
516 if (outline)737 if (outline)
517 {738 {
739 cairo_set_source_rgba (*cr, 0.0f, 0.0f, 0.0f, 0.0f);
740 cairo_set_operator (*cr, CAIRO_OPERATOR_CLEAR);
741 }
742 else
743 {
744 cairo_set_operator (*cr, CAIRO_OPERATOR_OVER);
745 if (negative)
518 cairo_set_source_rgba (*cr, 0.0f, 0.0f, 0.0f, 0.0f);746 cairo_set_source_rgba (*cr, 0.0f, 0.0f, 0.0f, 0.0f);
519 cairo_set_operator (*cr, CAIRO_OPERATOR_CLEAR);747 else
520 } 748 cairo_set_source_rgba (*cr, 1.0f, 1.0f, 1.0f, 1.0f);
521 else749 }
522 {750 cairo_paint (*cr);
523 cairo_set_operator (*cr, CAIRO_OPERATOR_OVER);751}
524 if (negative)752
525 cairo_set_source_rgba (*cr, 0.0f, 0.0f, 0.0f, 0.0f);753void ql_compute_full_mask_path (cairo_t* cr,
526 else754 gfloat anchor_width,
527 cairo_set_source_rgba (*cr, 1.0f, 1.0f, 1.0f, 1.0f);755 gfloat anchor_height,
528 }756 gint width,
529 cairo_paint (*cr);757 gint height,
530 }758 gint upper_size,
531759 gfloat radius,
532 void ql_compute_full_mask_path (cairo_t* cr,760 guint pad)
533 gfloat anchor_width,761{
534 gfloat anchor_height,762 // 0 1 2 3
535 gint width,763 // +--+--------+--+
536 gint height,764 // | |
537 gint upper_size,765 // + 14 + 4
538 gfloat radius,766 // | |
539 guint pad)767 // | |
540 {768 // | |
541 // 0 1 2 3769 // + 13 |
542 // +--+--------+--+770 // / |
543 // | |771 // / |
544 // + 14 + 4772 // + 12 |
545 // | |773 // \ |
546 // | |774 // \ |
547 // | |775 // 11 + |
548 // + 13 |776 // | |
549 // / |777 // | |
550 // / |778 // | |
551 // + 12 |779 // 10 + + 5
552 // \ |780 // | |
553 // \ |781 // +--+--------+--+ 6
554 // 11 + |782 // 9 8 7
555 // | |783
556 // | |784
557 // | |785 gfloat padding = pad;
558 // 10 + + 5786 int ZEROPOINT5 = 0.0f;
559 // | |787
560 // +--+--------+--+ 6788 gfloat HeightToAnchor = 0.0f;
561 // 9 8 7789 HeightToAnchor = ((gfloat) height - 2.0f * radius - anchor_height -2*padding) / 2.0f;
562790 if (HeightToAnchor < 0.0f)
563791 {
564 gfloat padding = pad;792 g_warning ("Anchor-height and corner-radius a higher than whole texture!");
565 int ZEROPOINT5 = 0.0f;793 return;
566794 }
567 gfloat HeightToAnchor = 0.0f;795
568 HeightToAnchor = ((gfloat) height - 2.0f * radius - anchor_height -2*padding) / 2.0f;796 //gint dynamic_size = height - 2*radius - 2*padding - anchor_height;
569 if (HeightToAnchor < 0.0f)797 //gint upper_dynamic_size = upper_size;
570 {798 //gint lower_dynamic_size = dynamic_size - upper_dynamic_size;
571 g_warning ("Anchor-height and corner-radius a higher than whole texture!");799
572 return;800 if(upper_size >= 0)
573 }801 {
574802 if(upper_size > height - 2.0f * radius - anchor_height -2 * padding)
575 //gint dynamic_size = height - 2*radius - 2*padding - anchor_height;803 {
576 //gint upper_dynamic_size = upper_size;804 //g_warning ("[_compute_full_mask_path] incorrect upper_size value");
577 //gint lower_dynamic_size = dynamic_size - upper_dynamic_size;805 HeightToAnchor = 0;
578806 }
579 if(upper_size >= 0)807 else
580 {808 {
581 if(upper_size > height - 2.0f * radius - anchor_height -2 * padding)809 HeightToAnchor = height - 2.0f * radius - anchor_height -2 * padding - upper_size;
582 {810 }
583 //g_warning ("[_compute_full_mask_path] incorrect upper_size value");811 }
584 HeightToAnchor = 0;812 else
585 }813 {
586 else814 HeightToAnchor = (height - 2.0f * radius - anchor_height -2*padding) / 2.0f;
587 {815 }
588 HeightToAnchor = height - 2.0f * radius - anchor_height -2 * padding - upper_size;816
589 }817 cairo_translate (cr, -0.5f, -0.5f);
590 }818
591 else819 // create path
592 {820 cairo_move_to (cr, padding + anchor_width + radius + ZEROPOINT5, padding + ZEROPOINT5); // Point 1
593 HeightToAnchor = (height - 2.0f * radius - anchor_height -2*padding) / 2.0f;821 cairo_line_to (cr, width - padding - radius, padding + ZEROPOINT5); // Point 2
594 }822 cairo_arc (cr,
595823 width - padding - radius + ZEROPOINT5,
596 cairo_translate (cr, -0.5f, -0.5f);824 padding + radius + ZEROPOINT5,
597825 radius,
598 // create path826 -90.0f * G_PI / 180.0f,
599 cairo_move_to (cr, padding + anchor_width + radius + ZEROPOINT5, padding + ZEROPOINT5); // Point 1827 0.0f * G_PI / 180.0f); // Point 4
600 cairo_line_to (cr, width - padding - radius, padding + ZEROPOINT5); // Point 2828 cairo_line_to (cr,
601 cairo_arc (cr,829 (gdouble) width - padding + ZEROPOINT5,
602 width - padding - radius + ZEROPOINT5,830 (gdouble) height - radius - padding + ZEROPOINT5); // Point 5
603 padding + radius + ZEROPOINT5,831 cairo_arc (cr,
604 radius,832 (gdouble) width - padding - radius + ZEROPOINT5,
605 -90.0f * G_PI / 180.0f,833 (gdouble) height - padding - radius + ZEROPOINT5,
606 0.0f * G_PI / 180.0f); // Point 4834 radius,
607 cairo_line_to (cr,835 0.0f * G_PI / 180.0f,
608 (gdouble) width - padding + ZEROPOINT5,836 90.0f * G_PI / 180.0f); // Point 7
609 (gdouble) height - radius - padding + ZEROPOINT5); // Point 5837 cairo_line_to (cr,
610 cairo_arc (cr,838 anchor_width + padding + radius + ZEROPOINT5,
611 (gdouble) width - padding - radius + ZEROPOINT5,839 (gdouble) height - padding + ZEROPOINT5); // Point 8
612 (gdouble) height - padding - radius + ZEROPOINT5,840
613 radius,841 cairo_arc (cr,
614 0.0f * G_PI / 180.0f,842 anchor_width + padding + radius + ZEROPOINT5,
615 90.0f * G_PI / 180.0f); // Point 7843 (gdouble) height - padding - radius,
616 cairo_line_to (cr,844 radius,
617 anchor_width + padding + radius + ZEROPOINT5,845 90.0f * G_PI / 180.0f,
618 (gdouble) height - padding + ZEROPOINT5); // Point 8846 180.0f * G_PI / 180.0f); // Point 10
619847
620 cairo_arc (cr,848 cairo_line_to (cr,
621 anchor_width + padding + radius + ZEROPOINT5,849 padding + anchor_width + ZEROPOINT5,
622 (gdouble) height - padding - radius,850 (gdouble) height - padding - radius - HeightToAnchor + ZEROPOINT5 ); // Point 11
623 radius,851 cairo_line_to (cr,
624 90.0f * G_PI / 180.0f,852 padding + ZEROPOINT5,
625 180.0f * G_PI / 180.0f); // Point 10853 (gdouble) height - padding - radius - HeightToAnchor - anchor_height / 2.0f + ZEROPOINT5); // Point 12
626854 cairo_line_to (cr,
627 cairo_line_to (cr,855 padding + anchor_width + ZEROPOINT5,
628 padding + anchor_width + ZEROPOINT5,856 (gdouble) height - padding - radius - HeightToAnchor - anchor_height + ZEROPOINT5); // Point 13
629 (gdouble) height - padding - radius - HeightToAnchor + ZEROPOINT5 ); // Point 11857
630 cairo_line_to (cr,858 cairo_line_to (cr, padding + anchor_width + ZEROPOINT5, padding + radius + ZEROPOINT5); // Point 14
631 padding + ZEROPOINT5,859 cairo_arc (cr,
632 (gdouble) height - padding - radius - HeightToAnchor - anchor_height / 2.0f + ZEROPOINT5); // Point 12860 padding + anchor_width + radius + ZEROPOINT5,
633 cairo_line_to (cr,861 padding + radius + ZEROPOINT5,
634 padding + anchor_width + ZEROPOINT5,862 radius,
635 (gdouble) height - padding - radius - HeightToAnchor - anchor_height + ZEROPOINT5); // Point 13863 180.0f * G_PI / 180.0f,
636864 270.0f * G_PI / 180.0f);
637 cairo_line_to (cr, padding + anchor_width + ZEROPOINT5, padding + radius + ZEROPOINT5); // Point 14865
638 cairo_arc (cr,866 cairo_close_path (cr);
639 padding + anchor_width + radius + ZEROPOINT5,867}
640 padding + radius + ZEROPOINT5,868
641 radius,869void ql_compute_mask (cairo_t* cr)
642 180.0f * G_PI / 180.0f,870{
643 270.0f * G_PI / 180.0f);871 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
644872 cairo_fill_preserve (cr);
645 cairo_close_path (cr);873}
646 }874
647875void ql_compute_outline (cairo_t* cr,
648 void ql_compute_mask (cairo_t* cr)876 gfloat line_width,
649 {877 gfloat* rgba_line)
650 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);878{
651 cairo_fill_preserve (cr);879 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
652 }880 cairo_set_source_rgba (cr,
653881 rgba_line[0],
654 void ql_compute_outline (cairo_t* cr,882 rgba_line[1],
655 gfloat line_width,883 rgba_line[2],
656 gfloat* rgba_line)884 rgba_line[3]);
657 {885 cairo_set_line_width (cr, line_width);
658 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);886 cairo_stroke (cr);
659 cairo_set_source_rgba (cr,887}
660 rgba_line[0],888
661 rgba_line[1],889void ql_draw (cairo_t* cr,
662 rgba_line[2],890 gboolean outline,
663 rgba_line[3]);891 gfloat line_width,
892 gfloat* rgba,
893 gboolean negative,
894 gboolean stroke)
895{
896 // prepare drawing
897 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
898
899 // actually draw the mask
900 if (outline)
901 {
664 cairo_set_line_width (cr, line_width);902 cairo_set_line_width (cr, line_width);
665 cairo_stroke (cr);903 cairo_set_source_rgba (cr, rgba[0], rgba[1], rgba[2], rgba[3]);
666 }904 }
667905 else
668 void ql_draw (cairo_t* cr,906 {
669 gboolean outline,907 if (negative)
670 gfloat line_width,908 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
671 gfloat* rgba,909 else
672 gboolean negative,910 cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
673 gboolean stroke)911 }
674 {912
675 // prepare drawing913 // stroke or fill?
676 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);914 if (stroke)
677915 cairo_stroke_preserve (cr);
678 // actually draw the mask916 else
679 if (outline)917 cairo_fill_preserve (cr);
680 {918}
681 cairo_set_line_width (cr, line_width);919
682 cairo_set_source_rgba (cr, rgba[0], rgba[1], rgba[2], rgba[3]);920void ql_finalize (cairo_t** cr,
683 }921 gboolean outline,
684 else922 gfloat line_width,
685 {923 gfloat* rgba,
686 if (negative)924 gboolean negative,
687 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);925 gboolean stroke)
688 else926{
689 cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);927 // prepare drawing
690 }928 cairo_set_operator (*cr, CAIRO_OPERATOR_SOURCE);
691929
692 // stroke or fill?930 // actually draw the mask
693 if (stroke)931 if (outline)
694 cairo_stroke_preserve (cr);932 {
695 else933 cairo_set_line_width (*cr, line_width);
696 cairo_fill_preserve (cr);934 cairo_set_source_rgba (*cr, rgba[0], rgba[1], rgba[2], rgba[3]);
697 }935 }
698936 else
699 void ql_finalize (cairo_t** cr,937 {
700 gboolean outline,938 if (negative)
701 gfloat line_width,939 cairo_set_source_rgba (*cr, 1.0f, 1.0f, 1.0f, 1.0f);
702 gfloat* rgba,940 else
703 gboolean negative,941 cairo_set_source_rgba (*cr, 0.0f, 0.0f, 0.0f, 0.0f);
704 gboolean stroke)942 }
705 {943
706 // prepare drawing944 // stroke or fill?
707 cairo_set_operator (*cr, CAIRO_OPERATOR_SOURCE);945 if (stroke)
708946 cairo_stroke (*cr);
709 // actually draw the mask947 else
710 if (outline)948 cairo_fill (*cr);
711 {949}
712 cairo_set_line_width (*cr, line_width);950
713 cairo_set_source_rgba (*cr, rgba[0], rgba[1], rgba[2], rgba[3]);951void
714 }952 ql_compute_full_outline_shadow (
715 else953 cairo_t* cr,
716 {954 cairo_surface_t* surf,
717 if (negative)955 gint width,
718 cairo_set_source_rgba (*cr, 1.0f, 1.0f, 1.0f, 1.0f);956 gint height,
719 else957 gfloat anchor_width,
720 cairo_set_source_rgba (*cr, 0.0f, 0.0f, 0.0f, 0.0f);958 gfloat anchor_height,
721 }959 gint upper_size,
722960 gfloat corner_radius,
723 // stroke or fill?961 guint blur_coeff,
724 if (stroke)962 gfloat* rgba_shadow,
725 cairo_stroke (*cr);963 gfloat line_width,
726 else964 gint padding_size,
727 cairo_fill (*cr);965 gfloat* rgba_line)
728 }966{
729967 ql_setup (&surf, &cr, TRUE, width, height, FALSE);
730 void968 ql_compute_full_mask_path (cr,
731 ql_compute_full_outline_shadow (969 anchor_width,
732 cairo_t* cr,970 anchor_height,
733 cairo_surface_t* surf,971 width,
734 gint width,972 height,
735 gint height,973 upper_size,
736 gfloat anchor_width,974 corner_radius,
737 gfloat anchor_height,975 padding_size);
738 gint upper_size,976
739 gfloat corner_radius,977 ql_draw (cr, TRUE, line_width, rgba_shadow, FALSE, FALSE);
740 guint blur_coeff,978 ql_surface_blur (surf, blur_coeff);
741 gfloat* rgba_shadow,979 ql_compute_mask (cr);
742 gfloat line_width,980 ql_compute_outline (cr, line_width, rgba_line);
743 gint padding_size,981}
744 gfloat* rgba_line)982
745 {983void ql_compute_full_mask (
746 ql_setup (&surf, &cr, TRUE, width, height, FALSE);984 cairo_t* cr,
747 ql_compute_full_mask_path (cr,985 cairo_surface_t* surf,
748 anchor_width,986 gint width,
749 anchor_height,987 gint height,
750 width,988 gfloat radius,
751 height,989 guint shadow_radius,
752 upper_size,990 gfloat anchor_width,
753 corner_radius,991 gfloat anchor_height,
754 padding_size);992 gint upper_size,
755993 gboolean negative,
756 ql_draw (cr, TRUE, line_width, rgba_shadow, FALSE, FALSE);994 gboolean outline,
757 ql_surface_blur (surf, blur_coeff);995 gfloat line_width,
758 ql_compute_mask (cr);996 gint padding_size,
759 ql_compute_outline (cr, line_width, rgba_line);997 gfloat* rgba)
760 }998{
761999 ql_setup (&surf, &cr, outline, width, height, negative);
762 void ql_compute_full_mask (1000 ql_compute_full_mask_path (cr,
763 cairo_t* cr,1001 anchor_width,
764 cairo_surface_t* surf,1002 anchor_height,
765 gint width,1003 width,
766 gint height,1004 height,
767 gfloat radius,1005 upper_size,
768 guint shadow_radius,1006 radius,
769 gfloat anchor_width,1007 padding_size);
770 gfloat anchor_height,1008 ql_finalize (&cr, outline, line_width, rgba, negative, outline);
771 gint upper_size,1009}
772 gboolean negative,1010
773 gboolean outline,1011void QuicklistView::UpdateTexture ()
774 gfloat line_width,1012{
775 gint padding_size,1013 if (_cairo_text_has_changed == false)
776 gfloat* rgba)1014 return;
777 {1015
778 ql_setup (&surf, &cr, outline, width, height, negative);1016 int size_above_anchor = -1; // equal to sise below
779 ql_compute_full_mask_path (cr,1017
780 anchor_width,1018 if ((_item_list.size () != 0) || (_default_item_list.size () != 0))
781 anchor_height,1019 {
782 width,1020 _top_size = 4;
783 height,1021 size_above_anchor = _top_size;
784 upper_size,1022 int x = _anchorX - _padding;
785 radius,1023 int y = _anchorY - _anchor_height/2 - _top_size - _corner_radius - _padding;
786 padding_size);1024
787 ql_finalize (&cr, outline, line_width, rgba, negative, outline);1025 SetBaseX (x);
788 }1026 SetBaseY (y);
7891027 }
790 void QuicklistView::UpdateTexture ()1028 else
791 {1029 {
792 if (_cairo_text_has_changed == false)1030 _top_size = 0;
793 return;1031 size_above_anchor = -1;
7941032 int x = _anchorX - _padding;
795 float blur_coef = 6.0f;1033 int y = _anchorY - _anchor_height/2 - _top_size - _corner_radius - _padding;
7961034
797 CairoGraphics* cairo_bg = new CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());1035 SetBaseX (x);
798 CairoGraphics* cairo_mask = new CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());1036 SetBaseY (y);
799 CairoGraphics* cairo_outline = new CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());1037 }
8001038
801 cairo_t *cr_bg = cairo_bg->GetContext ();1039 float blur_coef = 6.0f;
802 cairo_t *cr_mask = cairo_mask->GetContext ();1040
803 cairo_t *cr_outline = cairo_outline->GetContext ();1041 nux::CairoGraphics* cairo_bg = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());
8041042 nux::CairoGraphics* cairo_mask = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());
805 float tint_color[4] = {0.0f, 0.0f, 0.0f, 0.80f};1043 nux::CairoGraphics* cairo_outline = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());
806 float hl_color[4] = {1.0f, 1.0f, 1.0f, 0.15f};1044
807 float dot_color[4] = {1.0f, 1.0f, 1.0f, 0.20f};1045 cairo_t *cr_bg = cairo_bg->GetContext ();
808 float shadow_color[4] = {0.0f, 0.0f, 0.0f, 1.00f};1046 cairo_t *cr_mask = cairo_mask->GetContext ();
809 float outline_color[4] = {1.0f, 1.0f, 1.0f, 0.75f};1047 cairo_t *cr_outline = cairo_outline->GetContext ();
810 float mask_color[4] = {1.0f, 1.0f, 1.0f, 1.00f};1048
811 float anchor_width = 10;1049 float tint_color[4] = {0.0f, 0.0f, 0.0f, 0.80f};
812 float anchor_height = 18;1050 float hl_color[4] = {1.0f, 1.0f, 1.0f, 0.15f};
8131051 float dot_color[4] = {1.0f, 1.0f, 1.0f, 0.20f};
814 ql_tint_dot_hl (cr_bg,1052 float shadow_color[4] = {0.0f, 0.0f, 0.0f, 1.00f};
815 GetBaseWidth (),1053 float outline_color[4] = {1.0f, 1.0f, 1.0f, 0.75f};
816 GetBaseHeight (),1054 float mask_color[4] = {1.0f, 1.0f, 1.0f, 1.00f};
817 GetBaseWidth () / 2.0f,1055// float anchor_width = 10;
818 0,1056// float anchor_height = 18;
819 Max<float>(GetBaseWidth () / 1.3f, GetBaseHeight () / 1.3f),1057
820 tint_color,1058 ql_tint_dot_hl (cr_bg,
821 hl_color,1059 GetBaseWidth (),
822 dot_color);1060 GetBaseHeight (),
8231061 GetBaseWidth () / 2.0f,
824 ql_compute_full_outline_shadow1062 0,
825 (1063 nux::Max<float>(GetBaseWidth () / 1.3f, GetBaseHeight () / 1.3f),
826 cr_outline,1064 tint_color,
827 cairo_outline->GetSurface(),1065 hl_color,
828 GetBaseWidth (),1066 dot_color);
829 GetBaseHeight (),1067
830 anchor_width,1068 ql_compute_full_outline_shadow
831 anchor_height,1069 (
832 -1,1070 cr_outline,
833 _corner_radius,1071 cairo_outline->GetSurface(),
834 blur_coef,1072 GetBaseWidth (),
835 shadow_color,1073 GetBaseHeight (),
836 1.0f,1074 _anchor_width,
837 _padding,1075 _anchor_height,
838 outline_color);1076 size_above_anchor,
8391077 _corner_radius,
840 ql_compute_full_mask (1078 blur_coef,
841 cr_mask,1079 shadow_color,
842 cairo_mask->GetSurface(),1080 1.0f,
843 GetBaseWidth (),1081 _padding,
844 GetBaseHeight(),1082 outline_color);
845 _corner_radius, // radius,1083
846 16, // shadow_radius,1084 ql_compute_full_mask (
847 anchor_width, // anchor_width,1085 cr_mask,
848 anchor_height, // anchor_height,1086 cairo_mask->GetSurface(),
849 -1, // upper_size,1087 GetBaseWidth (),
850 true, // negative,1088 GetBaseHeight(),
851 false, // outline,1089 _corner_radius, // radius,
852 1.0, // line_width,1090 16, // shadow_radius,
853 _padding, // padding_size,1091 _anchor_width, // anchor_width,
854 mask_color);1092 _anchor_height, // anchor_height,
8551093 size_above_anchor, // upper_size,
856 cairo_destroy (cr_bg);1094 true, // negative,
857 cairo_destroy (cr_outline);1095 false, // outline,
858 cairo_destroy (cr_mask);1096 1.0, // line_width,
8591097 _padding, // padding_size,
860 NBitmapData* bitmap = cairo_bg->GetBitmap();1098 mask_color);
8611099
862 if (_texture_bg)1100 cairo_destroy (cr_bg);
863 _texture_bg->UnReference ();1101 cairo_destroy (cr_outline);
864 _texture_bg = GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();1102 cairo_destroy (cr_mask);
865 _texture_bg->Update(bitmap);1103
866 delete bitmap;1104 nux::NBitmapData* bitmap = cairo_bg->GetBitmap();
8671105
868 bitmap = cairo_mask->GetBitmap();1106 if (_texture_bg)
869 if (_texture_mask)1107 _texture_bg->UnReference ();
870 _texture_mask->UnReference ();1108 _texture_bg = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
871 _texture_mask = GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();1109 _texture_bg->Update(bitmap);
872 _texture_mask->Update(bitmap);1110 delete bitmap;
873 delete bitmap;1111
8741112 bitmap = cairo_mask->GetBitmap();
875 bitmap = cairo_outline->GetBitmap();1113 if (_texture_mask)
876 if (_texture_outline)1114 _texture_mask->UnReference ();
877 _texture_outline->UnReference ();1115 _texture_mask = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
878 _texture_outline = GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();1116 _texture_mask->Update(bitmap);
879 _texture_outline->Update(bitmap);1117 delete bitmap;
880 delete bitmap;1118
8811119 bitmap = cairo_outline->GetBitmap();
882 delete cairo_bg;1120 if (_texture_outline)
883 delete cairo_mask;1121 _texture_outline->UnReference ();
884 delete cairo_outline;1122 _texture_outline = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
885 _cairo_text_has_changed = false;1123 _texture_outline->Update(bitmap);
886 }1124 delete bitmap;
8871125
888 void QuicklistView::PositionChildLayout (float offsetX,1126 delete cairo_bg;
889 float offsetY)1127 delete cairo_mask;
890 {1128 delete cairo_outline;
891 }1129 _cairo_text_has_changed = false;
8921130
893 void QuicklistView::LayoutWindowElements ()1131 // Request a redraw, so this area will be added to Compiz list of dirty areas.
894 {1132 NeedRedraw ();
895 }1133}
8961134
897 void QuicklistView::NotifyConfigurationChange (int width,1135void QuicklistView::PositionChildLayout (float offsetX, float offsetY)
898 int height)1136{
899 {1137}
900 }1138
9011139void QuicklistView::LayoutWindowElements ()
902 void QuicklistView::SetText (NString text)1140{
903 {1141}
904 if (_labelText == text)1142
905 return;1143void QuicklistView::NotifyConfigurationChange (int width, int height)
9061144{
907 _labelText = text;1145}
908 UpdateTexture ();1146
909 }1147void QuicklistView::SetText (nux::NString text)
9101148{
911} // namespace nux1149 if (_labelText == text)
1150 return;
1151
1152 _labelText = text;
1153 UpdateTexture ();
1154}
9121155
=== modified file 'src/QuicklistView.h'
--- src/QuicklistView.h 2010-11-11 10:46:30 +0000
+++ src/QuicklistView.h 2010-11-18 14:03:47 +0000
@@ -17,8 +17,8 @@
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com17 * Authored by: Mirco Müller <mirco.mueller@canonical.com
18 */18 */
1919
20#ifndef TOOLTIP_H20#ifndef QUICKLISTVIEW_H
21#define TOOLTIP_H21#define QUICKLISTVIEW_H
2222
23#include "Nux/Nux.h"23#include "Nux/Nux.h"
24#include "Nux/BaseWindow.h"24#include "Nux/BaseWindow.h"
@@ -46,77 +46,92 @@
46#define V_MARGIN 446#define V_MARGIN 4
47#define FONT_FACE "Ubuntu 13"47#define FONT_FACE "Ubuntu 13"
4848
49namespace nux49
50class VLayout;
51class HLayout;
52class SpaceLayout;
53
54class QuicklistView : public nux::BaseWindow
50{55{
51 class VLayout;56 NUX_DECLARE_OBJECT_TYPE (QuicklistView, nux::BaseWindow);
52 class HLayout;57public:
53 class SpaceLayout;58 QuicklistView ();
5459
55 class QuicklistView : public BaseWindow60 ~QuicklistView ();
56 {61
57 NUX_DECLARE_OBJECT_TYPE (QuicklistView, BaseWindow);62 long ProcessEvent (nux::IEvent& iEvent,
58 public:63 long traverseInfo,
59 QuicklistView ();64 long processEventInfo);
6065
61 ~QuicklistView ();66 void Draw (nux::GraphicsEngine& gfxContext,
6267 bool forceDraw);
63 long ProcessEvent (IEvent& iEvent,68
64 long traverseInfo,69 void DrawContent (nux::GraphicsEngine& gfxContext,
65 long processEventInfo);70 bool forceDraw);
6671
67 void Draw (GraphicsEngine& gfxContext,72 void SetText (nux::NString text);
68 bool forceDraw);73
6974 void RemoveAllMenuItem ();
70 void DrawContent (GraphicsEngine& gfxContext,75 void AddMenuItem (nux::NString str);
71 bool forceDraw);76 void RenderQuicklistView ();
7277
73 void SetText (NString text);78 void ShowQuicklistWithTipAt (int anchor_tip_x, int anchor_tip_y);
7479 virtual void ShowWindow (bool b, bool StartModal = false);
75 private:80
76 void RecvCairoTextChanged (StaticCairoText& cairo_text);81private:
7782 void RecvCairoTextChanged (nux::StaticCairoText& cairo_text);
78 void PreLayoutManagement ();83 void RecvCairoTextColorChanged (nux::StaticCairoText& cairo_text);
7984
80 long PostLayoutManagement (long layoutResult);85 void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
8186 void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
82 void PositionChildLayout (float offsetX,87 void RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags);
83 float offsetY);88 void RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
8489 void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
85 void LayoutWindowElements ();90 void RecvMouseDownOutsideOfQuicklist (int x, int y, unsigned long button_flags, unsigned long key_flags);
8691
87 void NotifyConfigurationChange (int width,92 void PreLayoutManagement ();
88 int height);93
8994 long PostLayoutManagement (long layoutResult);
90 //nux::CairoGraphics* _cairo_graphics;95
91 int _anchorX;96 void PositionChildLayout (float offsetX, float offsetY);
92 int _anchorY;97
93 nux::NString _labelText;98 void LayoutWindowElements ();
94 int _dpiX;99
95 int _dpiY;100 void NotifyConfigurationChange (int width, int height);
96101
97 cairo_font_options_t* _fontOpts;102 //nux::CairoGraphics* _cairo_graphics;
98103 int _anchorX;
99 nux::StaticCairoText* _tooltip_text;104 int _anchorY;
100 nux::BaseTexture* _texture_bg;105 nux::NString _labelText;
101 nux::BaseTexture* _texture_mask;106 int _dpiX;
102 nux::BaseTexture* _texture_outline;107 int _dpiY;
103108 int _top_size; // size of the segment from point 13 to 14. See figure in ql_compute_full_mask_path.
104 float _anchor_width;109
105 float _anchor_height;110 cairo_font_options_t* _fontOpts;
106 float _corner_radius;111
107 float _padding;112 nux::StaticCairoText* _tooltip_text;
108 nux::HLayout *_hlayout;113 nux::BaseTexture* _texture_bg;
109 VLayout *_vlayout;114 nux::BaseTexture* _texture_mask;
110 nux::SpaceLayout *_left_space; //!< Space from the left of the widget to the left of the text.115 nux::BaseTexture* _texture_outline;
111 nux::SpaceLayout *_right_space; //!< Space from the right of the text to the right of the widget.116
112 nux::SpaceLayout *_top_space; //!< Space from the left of the widget to the left of the text.117 float _anchor_width;
113 nux::SpaceLayout *_bottom_space; //!< Space from the right of the text to the right of the widget.118 float _anchor_height;
114119 float _corner_radius;
115 bool _cairo_text_has_changed;120 float _padding;
116 void UpdateTexture ();121 nux::HLayout *_hlayout;
117 std::list<nux::StaticCairoText*> _item_list;122 nux::VLayout *_vlayout;
118 };123 nux::VLayout *_item_layout;
119}124 nux::VLayout *_default_item_layout;
120125 nux::SpaceLayout *_left_space; //!< Space from the left of the widget to the left of the text.
121#endif // TOOLTIP_H126 nux::SpaceLayout *_right_space; //!< Space from the right of the text to the right of the widget.
127 nux::SpaceLayout *_top_space; //!< Space from the left of the widget to the left of the text.
128 nux::SpaceLayout *_bottom_space; //!< Space from the right of the text to the right of the widget.
129
130 bool _cairo_text_has_changed;
131 void UpdateTexture ();
132 std::list<nux::StaticCairoText*> _item_list;
133 std::list<nux::StaticCairoText*> _default_item_list;
134};
135
136#endif // QUICKLISTVIEW_H
122137
123138
=== modified file 'src/StaticCairoText.cpp'
--- src/StaticCairoText.cpp 2010-11-10 15:45:18 +0000
+++ src/StaticCairoText.cpp 2010-11-18 14:03:47 +0000
@@ -170,7 +170,7 @@
170 base.height,170 base.height,
171 _texture2D->GetDeviceTexture(),171 _texture2D->GetDeviceTexture(),
172 texxform,172 texxform,
173 Color(1.0f, 1.0f, 1.0f, 1.0f));173 _textColor);
174174
175 gfxContext.GetRenderStates().SetBlend (false);175 gfxContext.GetRenderStates().SetBlend (false);
176176
@@ -252,8 +252,7 @@
252 if (_textColor != textColor)252 if (_textColor != textColor)
253 {253 {
254 _textColor = textColor;254 _textColor = textColor;
255 UpdateTexture ();255 sigTextColorChanged.emit (*this);
256 sigTextChanged.emit (*this);
257 }256 }
258}257}
259258
260259
=== modified file 'src/StaticCairoText.h'
--- src/StaticCairoText.h 2010-11-10 14:42:46 +0000
+++ src/StaticCairoText.h 2010-11-18 14:03:47 +0000
@@ -99,6 +99,7 @@
99 void GetTextExtents (int &width, int &height);99 void GetTextExtents (int &width, int &height);
100100
101 sigc::signal<void, StaticCairoText&> sigTextChanged;101 sigc::signal<void, StaticCairoText&> sigTextChanged;
102 sigc::signal<void, StaticCairoText&> sigTextColorChanged;
102103
103 protected:104 protected:
104 105
105106
=== modified file 'src/Tooltip.cpp'
--- src/Tooltip.cpp 2010-11-11 15:08:31 +0000
+++ src/Tooltip.cpp 2010-11-18 14:03:47 +0000
@@ -49,6 +49,7 @@
49 _anchor_height = 18;49 _anchor_height = 18;
50 _corner_radius = 4;50 _corner_radius = 4;
51 _padding = 15;51 _padding = 15;
52 _top_size = 4;
5253
53 _hlayout = new nux::HLayout (TEXT(""), NUX_TRACKER_LOCATION);54 _hlayout = new nux::HLayout (TEXT(""), NUX_TRACKER_LOCATION);
54 _vlayout = new nux::VLayout (TEXT(""), NUX_TRACKER_LOCATION);55 _vlayout = new nux::VLayout (TEXT(""), NUX_TRACKER_LOCATION);
@@ -94,6 +95,26 @@
94 95
95 return ret;96 return ret;
96 }97 }
98
99 void Tooltip::ShowTooltipWithTipAt (int anchor_tip_x, int anchor_tip_y)
100 {
101 int window_width;
102 int window_height;
103
104 window_width = nux::GetWindow ().GetWindowWidth ();
105 window_height = nux::GetWindow ().GetWindowHeight ();
106
107 _anchorX = anchor_tip_x;
108 _anchorY = anchor_tip_y;
109
110 int x = _anchorX - _padding;
111 int y = anchor_tip_y - _anchor_height/2 - _top_size - _corner_radius - _padding;
112
113 SetBaseX (x);
114 SetBaseY (y);
115
116 ShowWindow (true);
117 }
97118
98 void Tooltip::Draw (GraphicsEngine& gfxContext, bool forceDraw)119 void Tooltip::Draw (GraphicsEngine& gfxContext, bool forceDraw)
99 {120 {
@@ -766,6 +787,18 @@
766 if (_cairo_text_has_changed == false)787 if (_cairo_text_has_changed == false)
767 return;788 return;
768789
790 int width = GetBaseWidth ();
791 int height = GetBaseHeight ();
792 int size_above_anchor = -1; // equal to sise below
793
794 _top_size = 0;
795 size_above_anchor = -1;
796 int x = _anchorX - _padding;
797 int y = _anchorY - height/2;
798
799 SetBaseX (x);
800 SetBaseY (y);
801
769 float blur_coef = 6.0f;802 float blur_coef = 6.0f;
770803
771 CairoGraphics* cairo_bg = new CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());804 CairoGraphics* cairo_bg = new CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());
@@ -782,8 +815,6 @@
782 float shadow_color[4] = {0.0f, 0.0f, 0.0f, 1.00f};815 float shadow_color[4] = {0.0f, 0.0f, 0.0f, 1.00f};
783 float outline_color[4] = {1.0f, 1.0f, 1.0f, 0.75f};816 float outline_color[4] = {1.0f, 1.0f, 1.0f, 0.75f};
784 float mask_color[4] = {1.0f, 1.0f, 1.0f, 1.00f};817 float mask_color[4] = {1.0f, 1.0f, 1.0f, 1.00f};
785 float anchor_width = 10;
786 float anchor_height = 18;
787818
788 tint_dot_hl (cr_bg,819 tint_dot_hl (cr_bg,
789 GetBaseWidth (),820 GetBaseWidth (),
@@ -801,8 +832,8 @@
801 cairo_outline->GetSurface(),832 cairo_outline->GetSurface(),
802 GetBaseWidth (),833 GetBaseWidth (),
803 GetBaseHeight (),834 GetBaseHeight (),
804 anchor_width,835 _anchor_width,
805 anchor_height,836 _anchor_height,
806 -1,837 -1,
807 _corner_radius,838 _corner_radius,
808 blur_coef,839 blur_coef,
@@ -816,15 +847,15 @@
816 cairo_mask->GetSurface(),847 cairo_mask->GetSurface(),
817 GetBaseWidth (),848 GetBaseWidth (),
818 GetBaseHeight(),849 GetBaseHeight(),
819 _corner_radius, // radius,850 _corner_radius, // radius,
820 16, // shadow_radius,851 16, // shadow_radius,
821 anchor_width, // anchor_width,852 _anchor_width, // anchor_width,
822 anchor_height, // anchor_height,853 _anchor_height, // anchor_height,
823 -1, // upper_size,854 -1, // upper_size,
824 true, // negative,855 true, // negative,
825 false, // outline,856 false, // outline,
826 1.0, // line_width,857 1.0, // line_width,
827 _padding, // padding_size,858 _padding, // padding_size,
828 mask_color);859 mask_color);
829860
830 cairo_destroy (cr_bg);861 cairo_destroy (cr_bg);
831862
=== modified file 'src/Tooltip.h'
--- src/Tooltip.h 2010-11-11 10:46:30 +0000
+++ src/Tooltip.h 2010-11-18 14:03:47 +0000
@@ -73,6 +73,7 @@
7373
74 void SetText (NString text);74 void SetText (NString text);
7575
76 void ShowTooltipWithTipAt (int anchor_tip_x, int anchor_tip_y);
76 private:77 private:
77 void RecvCairoTextChanged (StaticCairoText& cairo_text);78 void RecvCairoTextChanged (StaticCairoText& cairo_text);
7879
@@ -94,6 +95,7 @@
94 nux::NString _labelText;95 nux::NString _labelText;
95 int _dpiX;96 int _dpiX;
96 int _dpiY;97 int _dpiY;
98 int _top_size; // size of the segment from point 13 to 14. See figure in _compute_full_mask_path.
9799
98 cairo_font_options_t* _fontOpts;100 cairo_font_options_t* _fontOpts;
99101
100102
=== modified file 'src/unity.cpp'
--- src/unity.cpp 2010-11-12 12:03:25 +0000
+++ src/unity.cpp 2010-11-18 14:03:47 +0000
@@ -188,9 +188,11 @@
188UnityScreen::handleEvent (XEvent *event)188UnityScreen::handleEvent (XEvent *event)
189{189{
190 screen->handleEvent (event);190 screen->handleEvent (event);
191 191
192 if (screen->otherGrabExist ("deco", "move", NULL))192 if (screen->otherGrabExist ("deco", "move", NULL))
193 {
193 wt->ProcessForeignEvent (event, NULL);194 wt->ProcessForeignEvent (event, NULL);
195 }
194}196}
195197
196bool198bool