Merge lp:~canonical-dx-team/unity/unity.jason-fixes into lp:unity

Proposed by Jason Smith
Status: Merged
Merged at revision: 653
Proposed branch: lp:~canonical-dx-team/unity/unity.jason-fixes
Merge into: lp:unity
Diff against target: 2858 lines (+2469/-289) (has conflicts)
5 files modified
src/BamfLauncherIcon.cpp (+80/-42)
src/BamfLauncherIcon.h (+6/-0)
src/Launcher.cpp (+1884/-0)
src/Launcher.h (+494/-245)
src/LauncherController.cpp (+5/-2)
Text conflict in src/Launcher.cpp
Text conflict in src/Launcher.h
To merge this branch: bzr merge lp:~canonical-dx-team/unity/unity.jason-fixes
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+42393@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Looks good, but please send a GError into g_app_info_launch and g_warning the contents if it's set (and don't forget to free it too), We should be always settings GErrors and reporting them so we get the best info if Unity is breaking for someone.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/BamfLauncherIcon.cpp'
--- src/BamfLauncherIcon.cpp 2010-11-30 04:56:10 +0000
+++ src/BamfLauncherIcon.cpp 2010-12-02 15:23:26 +0000
@@ -102,6 +102,18 @@
102}102}
103103
104void104void
105BamfLauncherIcon::OpenInstance ()
106{
107 GDesktopAppInfo *appInfo;
108
109 appInfo = g_desktop_app_info_new_from_filename (bamf_application_get_desktop_file (BAMF_APPLICATION (m_App)));
110 g_app_info_launch (G_APP_INFO (appInfo), NULL, NULL, NULL);
111 g_object_unref (appInfo);
112
113 UpdateQuirkTime (LAUNCHER_ICON_QUIRK_STARTING);
114}
115
116void
105BamfLauncherIcon::OnMouseClick (int button)117BamfLauncherIcon::OnMouseClick (int button)
106{118{
107 if (button != 1)119 if (button != 1)
@@ -110,7 +122,6 @@
110 BamfView *view;122 BamfView *view;
111 GList *children, *l;123 GList *children, *l;
112 bool active, running;124 bool active, running;
113 GDesktopAppInfo *appInfo;
114 125
115 children = bamf_view_get_children (BAMF_VIEW (m_App));126 children = bamf_view_get_children (BAMF_VIEW (m_App));
116 active = bamf_view_is_active (BAMF_VIEW (m_App));127 active = bamf_view_is_active (BAMF_VIEW (m_App));
@@ -118,12 +129,7 @@
118 129
119 if (!running)130 if (!running)
120 {131 {
121 appInfo = g_desktop_app_info_new_from_filename (bamf_application_get_desktop_file (BAMF_APPLICATION (m_App)));132 OpenInstance ();
122 g_app_info_launch (G_APP_INFO (appInfo), NULL, NULL, NULL);
123 g_object_unref (appInfo);
124
125 UpdateQuirkTime (LAUNCHER_ICON_QUIRK_STARTING);
126
127 return;133 return;
128 }134 }
129 135
@@ -269,6 +275,12 @@
269}275}
270276
271void277void
278BamfLauncherIcon::OnLaunch (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self)
279{
280 self->OpenInstance ();
281}
282
283void
272BamfLauncherIcon::OnQuit (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self)284BamfLauncherIcon::OnQuit (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self)
273{285{
274 GList *children, *l;286 GList *children, *l;
@@ -315,12 +327,67 @@
315 }327 }
316}328}
317329
330void
331BamfLauncherIcon::EnsureMenuItemsReady ()
332{
333 DbusmenuMenuitem *menu_item;
334
335 /* Launch */
336 if (_menu_items.find ("Launch") == _menu_items.end ())
337 {
338 menu_item = dbusmenu_menuitem_new ();
339 g_object_ref (menu_item);
340
341 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, "Open New Window");
342 dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
343
344 g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnLaunch, this);
345
346 _menu_items["Launch"] = menu_item;
347 }
348
349 /* Pin */
350 if (_menu_items.find ("Pin") == _menu_items.end ())
351 {
352 menu_item = dbusmenu_menuitem_new ();
353 g_object_ref (menu_item);
354
355 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK);
356 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, "Keep In Launcher");
357 dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
358
359 g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnTogglePin, this);
360
361 _menu_items["Pin"] = menu_item;
362 }
363 int checked = !bamf_view_is_sticky (BAMF_VIEW (m_App)) ?
364 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED;
365
366 dbusmenu_menuitem_property_set_int (_menu_items["Pin"],
367 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
368 checked);
369
370
371 /* Quit */
372 if (_menu_items.find ("Quit") == _menu_items.end ())
373 {
374 menu_item = dbusmenu_menuitem_new ();
375 g_object_ref (menu_item);
376
377 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, "Quit");
378 dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
379
380 g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnQuit, this);
381
382 _menu_items["Quit"] = menu_item;
383 }
384}
385
318std::list<DbusmenuMenuitem *>386std::list<DbusmenuMenuitem *>
319BamfLauncherIcon::GetMenus ()387BamfLauncherIcon::GetMenus ()
320{388{
321 std::map<std::string, DbusmenuClient *>::iterator it;389 std::map<std::string, DbusmenuClient *>::iterator it;
322 std::list<DbusmenuMenuitem *> result;390 std::list<DbusmenuMenuitem *> result;
323 DbusmenuMenuitem *menu_item;
324 391
325 for (it = _menu_clients.begin (); it != _menu_clients.end (); it++)392 for (it = _menu_clients.begin (); it != _menu_clients.end (); it++)
326 {393 {
@@ -339,42 +406,13 @@
339 }406 }
340 }407 }
341 408
342 if (_menu_items.find ("Pin") == _menu_items.end ())409 EnsureMenuItemsReady ();
343 {410
344 menu_item = dbusmenu_menuitem_new ();411 result.push_back (_menu_items["Launch"]);
345 g_object_ref (menu_item);
346
347 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK);
348 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, "Pin To Launcher");
349 dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
350
351 g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnTogglePin, this);
352
353 _menu_items["Pin"] = menu_item;
354 }
355
356 int checked = !bamf_view_is_sticky (BAMF_VIEW (m_App)) ?
357 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED;
358
359 dbusmenu_menuitem_property_set_int (_menu_items["Pin"],
360 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
361 checked);
362 result.push_back (_menu_items["Pin"]);412 result.push_back (_menu_items["Pin"]);
363 413
364 if (_menu_items.find ("Quit") == _menu_items.end ())414 if (bamf_view_is_running (BAMF_VIEW (m_App)))
365 {415 result.push_back (_menu_items["Quit"]);
366 menu_item = dbusmenu_menuitem_new ();
367 g_object_ref (menu_item);
368
369 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, "Quit");
370 dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
371
372 g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnQuit, this);
373
374 _menu_items["Quit"] = menu_item;
375 }
376
377 result.push_back (_menu_items["Quit"]);
378 416
379 return result;417 return result;
380}418}
381419
=== modified file 'src/BamfLauncherIcon.h'
--- src/BamfLauncherIcon.h 2010-11-30 03:19:56 +0000
+++ src/BamfLauncherIcon.h 2010-12-02 15:23:26 +0000
@@ -55,8 +55,13 @@
55 std::map<std::string, DbusmenuMenuitem *> _menu_items;55 std::map<std::string, DbusmenuMenuitem *> _menu_items;
56 56
57 void EnsureWindowState ();57 void EnsureWindowState ();
58
58 void UpdateMenus ();59 void UpdateMenus ();
59 60
61 void OpenInstance ();
62
63 void EnsureMenuItemsReady ();
64
60 static void OnClosed (BamfView *view, gpointer data);65 static void OnClosed (BamfView *view, gpointer data);
61 static void OnUserVisibleChanged (BamfView *view, gboolean visible, gpointer data);66 static void OnUserVisibleChanged (BamfView *view, gboolean visible, gpointer data);
62 static void OnActiveChanged (BamfView *view, gboolean active, gpointer data);67 static void OnActiveChanged (BamfView *view, gboolean active, gpointer data);
@@ -65,6 +70,7 @@
65 static void OnChildAdded (BamfView *view, BamfView *child, gpointer data);70 static void OnChildAdded (BamfView *view, BamfView *child, gpointer data);
66 static void OnChildRemoved (BamfView *view, BamfView *child, gpointer data);71 static void OnChildRemoved (BamfView *view, BamfView *child, gpointer data);
67 72
73 static void OnLaunch (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self);
68 static void OnQuit (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self);74 static void OnQuit (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self);
69 static void OnTogglePin (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self);75 static void OnTogglePin (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self);
70};76};
7177
=== modified file 'src/Launcher.cpp'
--- src/Launcher.cpp 2010-12-01 22:28:50 +0000
+++ src/Launcher.cpp 2010-12-02 15:23:26 +0000
@@ -1,3 +1,4 @@
1<<<<<<< TREE
1/*2/*
2 * Copyright (C) 2010 Canonical Ltd3 * Copyright (C) 2010 Canonical Ltd
3 *4 *
@@ -1865,3 +1866,1886 @@
1865 _active_quicklist = 0;1866 _active_quicklist = 0;
1866}1867}
18671868
1869=======
1870/*
1871 * Copyright (C) 2010 Canonical Ltd
1872 *
1873 * This program is free software: you can redistribute it and/or modify
1874 * it under the terms of the GNU General Public License version 3 as
1875 * published by the Free Software Foundation.
1876 *
1877 * This program is distributed in the hope that it will be useful,
1878 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1879 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1880 * GNU General Public License for more details.
1881 *
1882 * You should have received a copy of the GNU General Public License
1883 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1884 *
1885 * Authored by: Jason Smith <jason.smith@canonical.com>
1886 * Authored by: Jay Taoko <jay.taoko@canonical.com>
1887 */
1888
1889#include <math.h>
1890
1891#include "Nux/Nux.h"
1892#include "Nux/VScrollBar.h"
1893#include "Nux/HLayout.h"
1894#include "Nux/VLayout.h"
1895#include "Nux/MenuPage.h"
1896
1897#include "NuxGraphics/NuxGraphics.h"
1898#include "NuxGraphics/GpuDevice.h"
1899#include "NuxGraphics/GLTextureResourceManager.h"
1900
1901#include "Nux/BaseWindow.h"
1902#include "Nux/WindowCompositor.h"
1903
1904#include "Launcher.h"
1905#include "LauncherIcon.h"
1906#include "LauncherModel.h"
1907#include "QuicklistView.h"
1908
1909#define ANIM_DURATION_SHORT 125
1910#define ANIM_DURATION 200
1911#define ANIM_DURATION_LONG 350
1912
1913#define URGENT_BLINKS 3
1914
1915#define MAX_STARTING_BLINKS 5
1916#define STARTING_BLINK_LAMBDA 3
1917
1918#define BACKLIGHT_STRENGTH 0.9f
1919
1920int
1921TimeDelta (struct timespec *x, struct timespec *y)
1922{
1923 return ((x->tv_sec - y->tv_sec) * 1000) + ((x->tv_nsec - y->tv_nsec) / 1000000);
1924}
1925
1926static bool USE_ARB_SHADERS = true;
1927/*
1928 Use this shader to pass vertices in screen coordinates in the C++ code and compute use
1929 the fragment shader to perform the texture perspective correct division.
1930 This shader assume the following:
1931 - the projection matrix is orthogonal: glOrtho(0, ScreenWidth, ScreenWidth, 0, Near, Far)
1932 - vertices x and y are in screen coordinates: Vertex(x_screen, y_screen, 0, 1.0)
1933 - the vertices w coordinates has been computed 'manually'
1934 - vertices uv textture coordinates are passed to the shader as: (u/w, v/w, 0, 1/w)
1935
1936 The texture coordinates s=u/w, t=v/w and q=1w are interpolated linearly in screen coordinates.
1937 In the fragment shader we get the texture coordinates used for the sampling by dividing
1938 s and t resulting from the interpolation by q.
1939
1940 */
1941
1942nux::NString gPerspectiveCorrectShader = TEXT (
1943"[Vertex Shader] \n\
1944#version 120 \n\
1945uniform mat4 ViewProjectionMatrix; \n\
1946 \n\
1947attribute vec4 iColor; \n\
1948attribute vec4 iTexCoord0; \n\
1949attribute vec4 iVertex; \n\
1950 \n\
1951varying vec4 varyTexCoord0; \n\
1952varying vec4 varyVertexColor; \n\
1953 \n\
1954void main() \n\
1955{ \n\
1956 varyTexCoord0 = iTexCoord0; \n\
1957 varyVertexColor = iColor; \n\
1958 gl_Position = ViewProjectionMatrix * iVertex; \n\
1959} \n\
1960 \n\
1961[Fragment Shader] \n\
1962#version 120 \n\
1963#extension GL_ARB_texture_rectangle : enable \n\
1964 \n\
1965varying vec4 varyTexCoord0; \n\
1966varying vec4 varyVertexColor; \n\
1967 \n\
1968uniform sampler2D TextureObject0; \n\
1969uniform vec4 color0; \n\
1970vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord) \n\
1971{ \n\
1972 return texture2D(TexObject, TexCoord.st); \n\
1973} \n\
1974 \n\
1975void main() \n\
1976{ \n\
1977 vec4 tex = varyTexCoord0; \n\
1978 tex.s = tex.s/varyTexCoord0.w; \n\
1979 tex.t = tex.t/varyTexCoord0.w; \n\
1980 \n\
1981 vec4 texel = SampleTexture(TextureObject0, tex); \n\
1982 gl_FragColor = texel*varyVertexColor; \n\
1983} \n\
1984");
1985
1986nux::NString PerspectiveCorrectVtx = TEXT (
1987 "!!ARBvp1.0 \n\
1988 ATTRIB iPos = vertex.position; \n\
1989 ATTRIB iColor = vertex.attrib[3]; \n\
1990 PARAM mvp[4] = {state.matrix.mvp}; \n\
1991 OUTPUT oPos = result.position; \n\
1992 OUTPUT oColor = result.color; \n\
1993 OUTPUT oTexCoord0 = result.texcoord[0]; \n\
1994 # Transform the vertex to clip coordinates. \n\
1995 DP4 oPos.x, mvp[0], iPos; \n\
1996 DP4 oPos.y, mvp[1], iPos; \n\
1997 DP4 oPos.z, mvp[2], iPos; \n\
1998 DP4 oPos.w, mvp[3], iPos; \n\
1999 MOV oColor, iColor; \n\
2000 MOV oTexCoord0, vertex.attrib[8]; \n\
2001 END");
2002
2003
2004
2005nux::NString PerspectiveCorrectTexFrg = TEXT (
2006 "!!ARBfp1.0 \n\
2007 PARAM color0 = program.local[0]; \n\
2008 TEMP temp; \n\
2009 TEMP pcoord; \n\
2010 TEMP tex0; \n\
2011 TEMP temp1; \n\
2012 TEMP recip; \n\
2013 MOV pcoord, fragment.texcoord[0].w; \n\
2014 RCP temp, fragment.texcoord[0].w; \n\
2015 MUL pcoord.xy, fragment.texcoord[0], temp; \n\
2016 TEX tex0, pcoord, texture[0], 2D; \n\
2017 MUL result.color, color0, tex0; \n\
2018 END");
2019
2020nux::NString PerspectiveCorrectTexRectFrg = TEXT (
2021 "!!ARBfp1.0 \n\
2022 PARAM color0 = program.local[0]; \n\
2023 TEMP temp; \n\
2024 TEMP pcoord; \n\
2025 TEMP tex0; \n\
2026 MOV pcoord, fragment.texcoord[0].w; \n\
2027 RCP temp, fragment.texcoord[0].w; \n\
2028 MUL pcoord.xy, fragment.texcoord[0], temp; \n\
2029 TEX tex0, pcoord, texture[0], RECT; \n\
2030 MUL result.color, color0, tex0; \n\
2031 END");
2032
2033static void GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, nux::Matrix4& PerspectiveMatrix,
2034 int ViewportWidth,
2035 int ViewportHeight,
2036 float NearClipPlane,
2037 float FarClipPlane,
2038 float Fovy);
2039
2040Launcher::Launcher(nux::BaseWindow *parent, NUX_FILE_LINE_DECL)
2041: View(NUX_FILE_LINE_PARAM)
2042, m_ContentOffsetY(0)
2043, m_RunningIndicator(0)
2044, m_ActiveIndicator(0)
2045, m_BackgroundLayer(0)
2046, _model (0)
2047{
2048 _parent = parent;
2049 _active_quicklist = 0;
2050
2051 m_Layout = new nux::HLayout(NUX_TRACKER_LOCATION);
2052
2053 OnMouseDown.connect(sigc::mem_fun(this, &Launcher::RecvMouseDown));
2054 OnMouseUp.connect(sigc::mem_fun(this, &Launcher::RecvMouseUp));
2055 OnMouseDrag.connect(sigc::mem_fun(this, &Launcher::RecvMouseDrag));
2056 OnMouseEnter.connect(sigc::mem_fun(this, &Launcher::RecvMouseEnter));
2057 OnMouseLeave.connect(sigc::mem_fun(this, &Launcher::RecvMouseLeave));
2058 OnMouseMove.connect(sigc::mem_fun(this, &Launcher::RecvMouseMove));
2059 OnMouseWheel.connect(sigc::mem_fun(this, &Launcher::RecvMouseWheel));
2060
2061 m_ActiveTooltipIcon = NULL;
2062 m_ActiveMenuIcon = NULL;
2063
2064 SetCompositionLayout(m_Layout);
2065
2066 if(!USE_ARB_SHADERS)
2067 {
2068 _shader_program_uv_persp_correction = nux::GetThreadGLDeviceFactory()->CreateShaderProgram();
2069 _shader_program_uv_persp_correction->LoadIShader(gPerspectiveCorrectShader.GetTCharPtr());
2070 _shader_program_uv_persp_correction->Link();
2071 }
2072 else
2073 {
2074 _AsmShaderProg = nux::GetThreadGLDeviceFactory()->CreateAsmShaderProgram();
2075 _AsmShaderProg->LoadVertexShader (TCHAR_TO_ANSI (*PerspectiveCorrectVtx) );
2076
2077 if ((nux::GetThreadGLDeviceFactory()->SUPPORT_GL_ARB_TEXTURE_NON_POWER_OF_TWO() == false) &&
2078 (nux::GetThreadGLDeviceFactory()->SUPPORT_GL_EXT_TEXTURE_RECTANGLE () || nux::GetThreadGLDeviceFactory()->SUPPORT_GL_ARB_TEXTURE_RECTANGLE ()))
2079 {
2080 // No support for non power of two textures but support for rectangle textures
2081 _AsmShaderProg->LoadPixelShader (TCHAR_TO_ANSI (*PerspectiveCorrectTexRectFrg) );
2082 }
2083 else
2084 {
2085 _AsmShaderProg->LoadPixelShader (TCHAR_TO_ANSI (*PerspectiveCorrectTexFrg) );
2086 }
2087
2088 _AsmShaderProg->Link();
2089 }
2090
2091 _folded_angle = 1.0f;
2092 _neg_folded_angle = -1.0f;
2093 _space_between_icons = 5;
2094 _launcher_top_y = 0;
2095 _launcher_bottom_y = 0;
2096 _folded_z_distance = 10.0f;
2097 _launcher_state = LAUNCHER_FOLDED;
2098 _launcher_action_state = ACTION_NONE;
2099 _icon_under_mouse = NULL;
2100 _icon_mouse_down = NULL;
2101 _icon_image_size = 48;
2102 _icon_glow_size = 62;
2103 _icon_image_size_delta = 6;
2104 _icon_size = _icon_image_size + _icon_image_size_delta;
2105
2106 _icon_bkg_texture = nux::CreateTextureFromFile (PKGDATADIR"/round_corner_54x54.png");
2107 _icon_outline_texture = nux::CreateTextureFromFile (PKGDATADIR"/round_outline_54x54.png");
2108 _icon_shine_texture = nux::CreateTextureFromFile (PKGDATADIR"/round_shine_54x54.png");
2109 _icon_glow_texture = nux::CreateTextureFromFile (PKGDATADIR"/round_glow_62x62.png");
2110 _icon_2indicator = nux::CreateTextureFromFile (PKGDATADIR"/2indicate_54x54.png");
2111 _icon_3indicator = nux::CreateTextureFromFile (PKGDATADIR"/3indicate_54x54.png");
2112 _icon_4indicator = nux::CreateTextureFromFile (PKGDATADIR"/4indicate_54x54.png");
2113
2114 _enter_y = 0;
2115 _dnd_security = 15;
2116 _dnd_delta = 0;
2117 _anim_handle = 0;
2118 _autohide_handle = 0;
2119 _floating = false;
2120 _hovered = false;
2121 _autohide = false;
2122 _hidden = false;
2123 _mouse_inside_launcher = false;
2124
2125 // 0 out timers to avoid wonky startups
2126 _enter_time.tv_sec = 0;
2127 _enter_time.tv_nsec = 0;
2128 _exit_time.tv_sec = 0;
2129 _exit_time.tv_nsec = 0;
2130 _drag_end_time.tv_sec = 0;
2131 _drag_end_time.tv_nsec = 0;
2132 _autohide_time.tv_sec = 0;
2133 _autohide_time.tv_nsec = 0;
2134}
2135
2136Launcher::~Launcher()
2137{
2138
2139}
2140
2141/* Render Layout Logic */
2142
2143float Launcher::GetHoverProgress ()
2144{
2145 struct timespec current;
2146 clock_gettime (CLOCK_MONOTONIC, &current);
2147
2148 if (_hovered)
2149 return CLAMP ((float) (TimeDelta (&current, &_enter_time)) / (float) ANIM_DURATION, 0.0f, 1.0f);
2150 else
2151 return 1.0f - CLAMP ((float) (TimeDelta (&current, &_exit_time)) / (float) ANIM_DURATION, 0.0f, 1.0f);
2152}
2153
2154float Launcher::DnDExitProgress ()
2155{
2156 struct timespec current;
2157 clock_gettime (CLOCK_MONOTONIC, &current);
2158
2159 return 1.0f - CLAMP ((float) (TimeDelta (&current, &_drag_end_time)) / (float) ANIM_DURATION_LONG, 0.0f, 1.0f);
2160}
2161
2162float Launcher::AutohideProgress ()
2163{
2164 if (!_autohide)
2165 return 0.0f;
2166
2167 struct timespec current;
2168 clock_gettime (CLOCK_MONOTONIC, &current);
2169
2170 if (_hidden)
2171 return CLAMP ((float) (TimeDelta (&current, &_autohide_time)) / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
2172 else
2173 return 1.0f - CLAMP ((float) (TimeDelta (&current, &_autohide_time)) / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
2174}
2175
2176gboolean Launcher::AnimationTimeout (gpointer data)
2177{
2178 Launcher *self = (Launcher*) data;
2179
2180 self->NeedRedraw ();
2181
2182 if (self->AnimationInProgress ())
2183 return true;
2184
2185 // zero out handle so we know we are done
2186 self->_anim_handle = 0;
2187 return false;
2188}
2189
2190void Launcher::EnsureAnimation ()
2191{
2192 if (_anim_handle)
2193 return;
2194
2195 NeedRedraw ();
2196
2197 if (AnimationInProgress ())
2198 _anim_handle = g_timeout_add (1000 / 60 - 1, &Launcher::AnimationTimeout, this);
2199}
2200
2201bool Launcher::IconNeedsAnimation (LauncherIcon *icon, struct timespec current)
2202{
2203 struct timespec time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_VISIBLE);
2204 if (TimeDelta (&current, &time) < ANIM_DURATION_SHORT)
2205 return true;
2206
2207 time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_RUNNING);
2208 if (TimeDelta (&current, &time) < ANIM_DURATION_SHORT)
2209 return true;
2210
2211 time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_STARTING);
2212 if (TimeDelta (&current, &time) < (ANIM_DURATION_LONG * MAX_STARTING_BLINKS * STARTING_BLINK_LAMBDA * 2))
2213 return true;
2214
2215 time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_URGENT);
2216 if (TimeDelta (&current, &time) < (ANIM_DURATION_LONG * URGENT_BLINKS * 2))
2217 return true;
2218
2219 time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_PRESENTED);
2220 if (TimeDelta (&current, &time) < ANIM_DURATION)
2221 return true;
2222
2223 time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_SHIMMER);
2224 if (TimeDelta (&current, &time) < ANIM_DURATION_LONG)
2225 return true;
2226
2227 return false;
2228}
2229
2230bool Launcher::AnimationInProgress ()
2231{
2232 // performance here can be improved by caching the longer remaining animation found and short circuiting to that each time
2233 // this way extra checks may be avoided
2234
2235 // short circuit to avoid unneeded calculations
2236 struct timespec current;
2237 clock_gettime (CLOCK_MONOTONIC, &current);
2238
2239 // hover in animation
2240 if (TimeDelta (&current, &_enter_time) < ANIM_DURATION)
2241 return true;
2242
2243 // hover out animation
2244 if (TimeDelta (&current, &_exit_time) < ANIM_DURATION)
2245 return true;
2246
2247 // drag end animation
2248 if (TimeDelta (&current, &_drag_end_time) < ANIM_DURATION_LONG)
2249 return true;
2250
2251 if (TimeDelta (&current, &_autohide_time) < ANIM_DURATION_SHORT)
2252 return true;
2253
2254 // animations happening on specific icons
2255 LauncherModel::iterator it;
2256 for (it = _model->begin (); it != _model->end (); it++)
2257 if (IconNeedsAnimation (*it, current))
2258 return true;
2259
2260 return false;
2261}
2262
2263void Launcher::SetTimeStruct (struct timespec *timer, struct timespec *sister, int sister_relation)
2264{
2265 struct timespec current;
2266 clock_gettime (CLOCK_MONOTONIC, &current);
2267
2268 if (sister)
2269 {
2270 int diff = TimeDelta (&current, sister);
2271
2272 if (diff < sister_relation)
2273 {
2274 int remove = sister_relation - diff;
2275 current.tv_sec -= remove / 1000;
2276 remove = remove % 1000;
2277
2278 if (remove > current.tv_nsec / 1000000)
2279 {
2280 current.tv_sec--;
2281 current.tv_nsec += 1000000000;
2282 }
2283 current.tv_nsec -= remove * 1000000;
2284 }
2285 }
2286
2287 timer->tv_sec = current.tv_sec;
2288 timer->tv_nsec = current.tv_nsec;
2289}
2290
2291float IconVisibleProgress (LauncherIcon *icon, struct timespec current)
2292{
2293 if (icon->GetQuirk (LAUNCHER_ICON_QUIRK_VISIBLE))
2294 {
2295 struct timespec icon_visible_time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_VISIBLE);
2296 int enter_ms = TimeDelta (&current, &icon_visible_time);
2297 return CLAMP ((float) enter_ms / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
2298 }
2299 else
2300 {
2301 struct timespec icon_hide_time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_VISIBLE);
2302 int hide_ms = TimeDelta (&current, &icon_hide_time);
2303 return 1.0f - CLAMP ((float) hide_ms / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
2304 }
2305}
2306
2307void Launcher::SetDndDelta (float x, float y, nux::Geometry geo, struct timespec current)
2308{
2309 LauncherIcon *anchor = 0;
2310 LauncherModel::iterator it;
2311 anchor = MouseIconIntersection (x, _enter_y);
2312
2313 if (anchor)
2314 {
2315 float position = y;
2316 for (it = _model->begin (); it != _model->end (); it++)
2317 {
2318 if (*it == anchor)
2319 {
2320 position += _icon_size / 2;
2321 _dnd_delta = _enter_y - position;
2322
2323 if (position + _icon_size / 2 + _dnd_delta > geo.height)
2324 _dnd_delta -= (position + _icon_size / 2 + _dnd_delta) - geo.height;
2325
2326 break;
2327 }
2328 position += (_icon_size + _space_between_icons) * IconVisibleProgress (*it, current);
2329 }
2330 }
2331}
2332
2333float Launcher::IconPresentProgress (LauncherIcon *icon, struct timespec current)
2334{
2335 struct timespec icon_present_time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_PRESENTED);
2336 int ms = TimeDelta (&current, &icon_present_time);
2337 float result = CLAMP ((float) ms / (float) ANIM_DURATION, 0.0f, 1.0f);
2338
2339 if (icon->GetQuirk (LAUNCHER_ICON_QUIRK_PRESENTED))
2340 return result;
2341 else
2342 return 1.0f - result;
2343}
2344
2345float Launcher::IconUrgentProgress (LauncherIcon *icon, struct timespec current)
2346{
2347 struct timespec urgent_time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_URGENT);
2348 int urgent_ms = TimeDelta (&current, &urgent_time);
2349 float result = CLAMP ((float) urgent_ms / (float) (ANIM_DURATION_LONG * URGENT_BLINKS * 2), 0.0f, 1.0f);
2350
2351 if (icon->GetQuirk (LAUNCHER_ICON_QUIRK_URGENT))
2352 return result;
2353 else
2354 return 1.0f - result;
2355}
2356
2357float Launcher::IconShimmerProgress (LauncherIcon *icon, struct timespec current)
2358{
2359 struct timespec shimmer_time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_SHIMMER);
2360 int shimmer_ms = TimeDelta (&current, &shimmer_time);
2361 return CLAMP ((float) shimmer_ms / (float) ANIM_DURATION_LONG, 0.0f, 1.0f);
2362}
2363
2364float Launcher::IconUrgentPulseValue (LauncherIcon *icon, struct timespec current)
2365{
2366 if (!icon->GetQuirk (LAUNCHER_ICON_QUIRK_URGENT))
2367 return 1.0f; // we are full on in a normal condition
2368
2369 double urgent_progress = (double) IconUrgentProgress (icon, current);
2370 return 0.5f + (float) (std::cos (M_PI * (float) (URGENT_BLINKS * 2) * urgent_progress)) * 0.5f;
2371}
2372
2373float Launcher::IconStartingPulseValue (LauncherIcon *icon, struct timespec current)
2374{
2375 struct timespec starting_time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_STARTING);
2376 int starting_ms = TimeDelta (&current, &starting_time);
2377 double starting_progress = (double) CLAMP ((float) starting_ms / (float) (ANIM_DURATION_LONG * MAX_STARTING_BLINKS * STARTING_BLINK_LAMBDA * 2), 0.0f, 1.0f);
2378
2379 return 1.0f - (0.5f + (float) (std::cos (M_PI * (float) (MAX_STARTING_BLINKS * 2) * starting_progress)) * 0.5f);
2380}
2381
2382float Launcher::IconBackgroundIntensity (LauncherIcon *icon, struct timespec current)
2383{
2384 float result = 0.0f;
2385 struct timespec running_time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_RUNNING);
2386 int running_ms = TimeDelta (&current, &running_time);
2387 float running_progress = CLAMP ((float) running_ms / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
2388
2389 // After we finish a fade in from running, we can reset the quirk
2390 if (icon->GetQuirk (LAUNCHER_ICON_QUIRK_RUNNING) && running_progress == 1.0f)
2391 icon->ResetQuirkTime (LAUNCHER_ICON_QUIRK_STARTING);
2392
2393 result = IconStartingPulseValue (icon, current) * BACKLIGHT_STRENGTH;
2394
2395 if (icon->GetQuirk (LAUNCHER_ICON_QUIRK_RUNNING))
2396 {
2397 // running progress fades in whatever the pulsing did not fill in already
2398 result += running_progress * (BACKLIGHT_STRENGTH - result);
2399
2400 // urgent serves to bring the total down only
2401 if (icon->GetQuirk (LAUNCHER_ICON_QUIRK_URGENT))
2402 result *= 0.2f + 0.8f * IconUrgentPulseValue (icon, current);
2403 }
2404 else
2405 {
2406 // modestly evil
2407 result += BACKLIGHT_STRENGTH - running_progress * BACKLIGHT_STRENGTH;
2408 }
2409
2410 return result;
2411}
2412
2413void Launcher::SetupRenderArg (LauncherIcon *icon, struct timespec current, RenderArg &arg)
2414{
2415 arg.icon = icon;
2416 arg.alpha = 1.0f;
2417 arg.running_arrow = false;
2418 arg.active_arrow = icon->GetQuirk (LAUNCHER_ICON_QUIRK_ACTIVE);
2419 arg.folding_rads = 0.0f;
2420 arg.skip = false;
2421
2422 arg.window_indicators = MIN (4, icon->RelatedWindows ());
2423
2424 // we dont need to show strays
2425 if (arg.window_indicators == 1 || !icon->GetQuirk (LAUNCHER_ICON_QUIRK_RUNNING))
2426 arg.window_indicators = 0;
2427
2428 arg.backlight_intensity = IconBackgroundIntensity (icon, current);
2429 arg.shimmer_progress = IconShimmerProgress (icon, current);
2430
2431 float urgent_progress = IconUrgentProgress (icon, current);
2432 urgent_progress = CLAMP (urgent_progress * 3, 0.0f, 1.0f); // we want to go 3x faster than the urgent normal cycle
2433 arg.glow_intensity = urgent_progress;
2434}
2435
2436int Launcher::DragLimiter (int x)
2437{
2438 int result = (int) ((1 - std::pow (159.0 / 160, std::abs (x))) * 160);
2439
2440 if (x >= 0)
2441 return result;
2442 return -result;
2443}
2444
2445void Launcher::RenderArgs (std::list<Launcher::RenderArg> &launcher_args,
2446 std::list<Launcher::RenderArg> &shelf_args,
2447 nux::Geometry &box_geo, nux::Geometry &shelf_geo)
2448{
2449 nux::Geometry geo = GetGeometry ();
2450 LauncherModel::iterator it;
2451 nux::Point3 center;
2452 float hover_progress = GetHoverProgress ();
2453 float folded_z_distance = _folded_z_distance * (1.0f - hover_progress);
2454 float animation_neg_rads = _neg_folded_angle * (1.0f - hover_progress);
2455 int vertical_offset = _parent->GetGeometry ().y;
2456 struct timespec current;
2457 clock_gettime (CLOCK_MONOTONIC, &current);
2458
2459 float folding_constant = 0.25f;
2460 float folding_not_constant = folding_constant + ((1.0f - folding_constant) * hover_progress);
2461
2462 int folded_size = (int) (_icon_size * folding_not_constant);
2463 int folded_spacing = (int) (_space_between_icons * folding_not_constant);
2464
2465 center.x = geo.width / 2;
2466 center.y = _space_between_icons;
2467 center.z = 0;
2468
2469 // compute required height of shelf
2470 float shelf_sum = 0.0f;
2471 for (it = _model->shelf_begin (); it != _model->shelf_end (); it++)
2472 {
2473 float height = (_icon_size + _space_between_icons) * IconVisibleProgress (*it, current);
2474 shelf_sum += height;
2475 }
2476
2477 // add bottom padding
2478 if (shelf_sum > 0.0f)
2479 shelf_sum += _space_between_icons;
2480
2481 int launcher_height = geo.height - shelf_sum;
2482
2483 // compute required height of launcher AND folding threshold
2484 float sum = 0.0f + center.y;
2485 int folding_threshold = launcher_height - _icon_size / 2.5f;
2486 for (it = _model->begin (); it != _model->end (); it++)
2487 {
2488 float height = (_icon_size + _space_between_icons) * IconVisibleProgress (*it, current);
2489 sum += height;
2490
2491 // magic constant must some day be explained, for now suffice to say this constant prevents the bottom from "marching";
2492 float magic_constant = 1.2f;
2493
2494 float present_progress = IconPresentProgress (*it, current);
2495 folding_threshold -= CLAMP (sum - launcher_height, 0.0f, height * magic_constant) * (folding_constant + (1.0f - folding_constant) * present_progress);
2496 }
2497
2498 // this happens on hover, basically its a flag and a value in one, we translate this into a dnd offset
2499 if (_enter_y != 0 && _enter_y + _icon_size / 2 > folding_threshold)
2500 SetDndDelta (center.x, center.y, nux::Geometry (geo.x, geo.y, geo.width, geo.height - shelf_sum), current);
2501
2502 _enter_y = 0;
2503
2504 if (hover_progress > 0.0f && _dnd_delta != 0)
2505 {
2506 int delta_y = _dnd_delta;
2507
2508 // logically dnd exit only restores to the clamped ranges
2509 // hover_progress restores to 0
2510 float max = 0.0f;
2511 float min = MIN (0.0f, launcher_height - sum);
2512
2513 if (_dnd_delta > max)
2514 delta_y = max + DragLimiter (delta_y - max);
2515 else if (_dnd_delta < min)
2516 delta_y = min + DragLimiter (delta_y - min);
2517
2518 if (_launcher_action_state != ACTION_DRAG_LAUNCHER)
2519 {
2520 float dnd_progress = DnDExitProgress ();
2521
2522 if (_dnd_delta > max)
2523 delta_y = max + (delta_y - max) * dnd_progress;
2524 else if (_dnd_delta < min)
2525 delta_y = min + (delta_y - min) * dnd_progress;
2526
2527 if (dnd_progress == 0.0f)
2528 _dnd_delta = (int) delta_y;
2529 }
2530
2531 delta_y *= hover_progress;
2532 center.y += delta_y;
2533 }
2534 else
2535 {
2536 _dnd_delta = 0;
2537 }
2538
2539 float autohide_progress = AutohideProgress ();
2540 float autohide_offset = 0.0f;
2541 if (_autohide && autohide_progress > 0.0f)
2542 {
2543 autohide_offset -= geo.width * autohide_progress;
2544 }
2545
2546 // Inform the painter where to paint the box
2547 box_geo = geo;
2548
2549 if (_floating)
2550 box_geo.height = sum + shelf_sum + _space_between_icons;
2551
2552 if (_autohide)
2553 box_geo.x += autohide_offset;
2554
2555 shelf_geo = nux::Geometry (box_geo.x, box_geo.height - shelf_sum, box_geo.width, shelf_sum);
2556
2557 // The functional position we wish to represent for these icons is not smooth. Rather than introducing
2558 // special casing to represent this, we use MIN/MAX functions. This helps ensure that even though our
2559 // function is not smooth it is continuous, which is more important for our visual representation (icons
2560 // wont start jumping around). As a general rule ANY if () statements that modify center.y should be seen
2561 // as bugs.
2562 for (it = _model->begin (); it != _model->end (); it++)
2563 {
2564 RenderArg arg;
2565 LauncherIcon *icon = *it;
2566
2567 SetupRenderArg (icon, current, arg);
2568
2569 // reset z
2570 center.z = 0;
2571
2572 float size_modifier = IconVisibleProgress (icon, current);
2573 if (size_modifier < 1.0f)
2574 {
2575 arg.alpha = size_modifier;
2576 center.z = 300.0f * (1.0f - size_modifier);
2577 }
2578
2579 if (size_modifier <= 0.0f)
2580 {
2581 arg.skip = true;
2582 continue;
2583 }
2584
2585 // goes for 0.0f when fully unfolded, to 1.0f folded
2586 float folding_progress = CLAMP ((center.y + _icon_size - folding_threshold) / (float) _icon_size, 0.0f, 1.0f);
2587 float present_progress = IconPresentProgress (icon, current);
2588
2589 folding_progress *= 1.0f - present_progress;
2590
2591 float half_size = (folded_size / 2.0f) + (_icon_size / 2.0f - folded_size / 2.0f) * (1.0f - folding_progress);
2592
2593 float icon_hide_offset = autohide_offset;
2594
2595 if (icon->PresentUrgency () == 1)
2596 icon_hide_offset *= 0.5f + 0.5f * (1.0f - present_progress);
2597 else if (icon->PresentUrgency () >= 2)
2598 icon_hide_offset *= 1.0f - present_progress;
2599
2600 // icon is crossing threshold, start folding
2601 center.z += folded_z_distance * folding_progress;
2602 arg.folding_rads = animation_neg_rads * folding_progress;
2603
2604 center.y += half_size * size_modifier; // move to center
2605 arg.center = nux::Point3 (center.x + icon_hide_offset, center.y, center.z); // copy center
2606 icon->SetCenter (nux::Point3 (center.x, center.y + vertical_offset, center.z));
2607 center.y += half_size * size_modifier; // move to end
2608
2609 float spacing_overlap = CLAMP ((float) (center.y + (_space_between_icons * size_modifier) - folding_threshold) / (float) _icon_size, 0.0f, 1.0f);
2610 //add spacing
2611 center.y += (_space_between_icons * (1.0f - spacing_overlap) + folded_spacing * spacing_overlap) * size_modifier;
2612
2613 launcher_args.push_back (arg);
2614 }
2615
2616 center.y = (box_geo.y + box_geo.height) - shelf_sum + _space_between_icons;
2617
2618 // Place shelf icons
2619 for (it = _model->shelf_begin (); it != _model->shelf_end (); it++)
2620 {
2621 RenderArg arg;
2622 LauncherIcon *icon = *it;
2623
2624 SetupRenderArg (icon, current, arg);
2625
2626 // reset z
2627 center.z = 0;
2628
2629 float size_modifier = IconVisibleProgress (icon, current);
2630 if (size_modifier < 1.0f)
2631 {
2632 arg.alpha = size_modifier;
2633 center.z = 300.0f * (1.0f - size_modifier);
2634 }
2635
2636 if (size_modifier <= 0.0f)
2637 {
2638 arg.skip = true;
2639 continue;
2640 }
2641
2642 float half_size = _icon_size / 2.0f;
2643
2644 center.y += half_size * size_modifier; // move to center
2645 arg.center = nux::Point3 (center.x + autohide_offset, center.y, center.z); // copy center
2646 icon->SetCenter (nux::Point3 (center.x, center.y + vertical_offset, center.z));
2647 center.y += half_size * size_modifier; // move to end
2648 center.y += _space_between_icons * size_modifier;
2649
2650 shelf_args.push_back (arg);
2651 }
2652}
2653
2654/* End Render Layout Logic */
2655
2656void Launcher::SetHidden (bool hidden)
2657{
2658 if (hidden == _hidden)
2659 return;
2660
2661 _hidden = hidden;
2662 SetTimeStruct (&_autohide_time, &_autohide_time, ANIM_DURATION);
2663
2664 _parent->EnableInputWindow(!hidden);
2665
2666 EnsureAnimation ();
2667}
2668
2669gboolean Launcher::OnAutohideTimeout (gpointer data)
2670{
2671 Launcher *self = (Launcher*) data;
2672
2673 if (self->_hovered || self->_hidden)
2674 return false;
2675
2676 self->SetHidden (true);
2677
2678 self->_autohide_handle = 0;
2679 return false;
2680}
2681
2682void Launcher::OnTriggerMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
2683{
2684 if (!_autohide || !_hidden)
2685 return;
2686
2687 SetHidden (false);
2688}
2689
2690void Launcher::SetupAutohideTimer ()
2691{
2692 if (_autohide)
2693 {
2694 if (_autohide_handle > 0)
2695 g_source_remove (_autohide_handle);
2696 _autohide_handle = g_timeout_add (1000, &Launcher::OnAutohideTimeout, this);
2697 }
2698}
2699
2700void Launcher::OnTriggerMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
2701{
2702 SetupAutohideTimer ();
2703}
2704
2705bool Launcher::AutohideEnabled ()
2706{
2707 return _autohide;
2708}
2709
2710gboolean Launcher::StrutHack (gpointer data)
2711{
2712 Launcher *self = (Launcher *) data;
2713 self->_parent->InputWindowEnableStruts(false);
2714 self->_parent->InputWindowEnableStruts(true);
2715
2716 return false;
2717}
2718
2719void Launcher::SetAutohide (bool autohide, nux::View *trigger)
2720{
2721 if (_autohide == autohide)
2722 return;
2723
2724 if (autohide)
2725 {
2726 _parent->InputWindowEnableStruts(false);
2727 _autohide_trigger = trigger;
2728 _autohide_trigger->OnMouseEnter.connect (sigc::mem_fun(this, &Launcher::OnTriggerMouseEnter));
2729 _autohide_trigger->OnMouseLeave.connect (sigc::mem_fun(this, &Launcher::OnTriggerMouseLeave));
2730 }
2731 else
2732 {
2733 _parent->EnableInputWindow(true);
2734 g_timeout_add (1000, &Launcher::StrutHack, this);
2735 _parent->InputWindowEnableStruts(true);
2736 }
2737
2738 _autohide = autohide;
2739 EnsureAnimation ();
2740}
2741
2742void Launcher::SetFloating (bool floating)
2743{
2744 if (_floating == floating)
2745 return;
2746
2747 _floating = floating;
2748 EnsureAnimation ();
2749}
2750
2751void Launcher::SetHover ()
2752{
2753 if (_hovered)
2754 return;
2755
2756 _enter_y = (int) _mouse_position.y;
2757
2758 if (_last_shelf_area.y - _enter_y < 5 && _last_shelf_area.y - _enter_y >= 0)
2759 _enter_y = _last_shelf_area.y - 5;
2760
2761 _hovered = true;
2762 SetTimeStruct (&_enter_time, &_exit_time, ANIM_DURATION);
2763}
2764
2765void Launcher::UnsetHover ()
2766{
2767 if (!_hovered)
2768 return;
2769
2770 _hovered = false;
2771 SetTimeStruct (&_exit_time, &_enter_time, ANIM_DURATION);
2772 SetupAutohideTimer ();
2773}
2774
2775void Launcher::SetIconSize(int tile_size, int icon_size)
2776{
2777 nux::Geometry geo = _parent->GetGeometry ();
2778
2779 _icon_size = tile_size;
2780 _icon_image_size = icon_size;
2781 _icon_image_size_delta = tile_size - icon_size;
2782
2783 // recreate tile textures
2784
2785 _parent->SetGeometry (nux::Geometry (geo.x, geo.y, tile_size + 12, geo.height));
2786}
2787
2788void Launcher::OnIconAdded (void *icon_pointer)
2789{
2790 LauncherIcon *icon = (LauncherIcon *) icon_pointer;
2791 icon->Reference ();
2792 EnsureAnimation();
2793
2794 // How to free these properly?
2795 icon->_xform_coords["HitArea"] = new nux::Vector4[4];
2796 icon->_xform_coords["Image"] = new nux::Vector4[4];
2797 icon->_xform_coords["Tile"] = new nux::Vector4[4];
2798 icon->_xform_coords["Glow"] = new nux::Vector4[4];
2799
2800 // needs to be disconnected
2801 icon->needs_redraw.connect (sigc::mem_fun(this, &Launcher::OnIconNeedsRedraw));
2802}
2803
2804void Launcher::OnIconRemoved (void *icon_pointer)
2805{
2806 LauncherIcon *icon = (LauncherIcon *) icon_pointer;
2807 icon->UnReference ();
2808
2809 EnsureAnimation();
2810}
2811
2812void Launcher::OnOrderChanged ()
2813{
2814
2815}
2816
2817void Launcher::SetModel (LauncherModel *model)
2818{
2819 _model = model;
2820 _model->icon_added.connect (sigc::mem_fun (this, &Launcher::OnIconAdded));
2821 _model->icon_removed.connect (sigc::mem_fun (this, &Launcher::OnIconRemoved));
2822 _model->order_changed.connect (sigc::mem_fun (this, &Launcher::OnOrderChanged));
2823}
2824
2825void Launcher::OnIconNeedsRedraw (void *icon)
2826{
2827 EnsureAnimation();
2828}
2829
2830long Launcher::ProcessEvent(nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
2831{
2832 long ret = TraverseInfo;
2833 ret = PostProcessEvent2(ievent, ret, ProcessEventInfo);
2834 return ret;
2835}
2836
2837void Launcher::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
2838{
2839
2840}
2841
2842void Launcher::RenderIcon(nux::GraphicsEngine& GfxContext,
2843 RenderArg arg,
2844 nux::BaseTexture *icon,
2845 nux::Color bkg_color,
2846 float alpha,
2847 nux::Vector4 xform_coords[],
2848 nux::Geometry geo,
2849 bool render_indicators)
2850{
2851 nux::Matrix4 ObjectMatrix;
2852 nux::Matrix4 ViewMatrix;
2853 nux::Matrix4 ProjectionMatrix;
2854 nux::Matrix4 ViewProjectionMatrix;
2855
2856 if(nux::Abs (arg.folding_rads) < 0.01f)
2857 icon->GetDeviceTexture()->SetFiltering(GL_NEAREST, GL_NEAREST);
2858 else
2859 icon->GetDeviceTexture()->SetFiltering(GL_LINEAR, GL_LINEAR);
2860
2861 nux::Vector4 v0;
2862 nux::Vector4 v1;
2863 nux::Vector4 v2;
2864 nux::Vector4 v3;
2865
2866 v0.x = xform_coords[0].x ;
2867 v0.y = xform_coords[0].y ;
2868 v0.z = xform_coords[0].z ;
2869 v0.w = xform_coords[0].w ;
2870 v1.x = xform_coords[1].x ;
2871 v1.y = xform_coords[1].y ;
2872 v1.z = xform_coords[1].z ;
2873 v1.w = xform_coords[1].w ;
2874 v2.x = xform_coords[2].x ;
2875 v2.y = xform_coords[2].y ;
2876 v2.z = xform_coords[2].z ;
2877 v2.w = xform_coords[2].w ;
2878 v3.x = xform_coords[3].x ;
2879 v3.y = xform_coords[3].y ;
2880 v3.z = xform_coords[3].z ;
2881 v3.w = xform_coords[3].w ;
2882
2883 float s0, t0, s1, t1, s2, t2, s3, t3;
2884 nux::Color color = nux::Color::White;
2885
2886 if (icon->Type ().IsDerivedFromType(nux::TextureRectangle::StaticObjectType))
2887 {
2888 s0 = 0.0f; t0 = 0.0f;
2889 s1 = 0.0f; t1 = icon->GetHeight();
2890 s2 = icon->GetWidth(); t2 = icon->GetHeight();
2891 s3 = icon->GetWidth(); t3 = 0.0f;
2892 }
2893 else
2894 {
2895 s0 = 0.0f; t0 = 0.0f;
2896 s1 = 0.0f; t1 = 1.0f;
2897 s2 = 1.0f; t2 = 1.0f;
2898 s3 = 1.0f; t3 = 0.0f;
2899 }
2900
2901 float VtxBuffer[] =
2902 {// Perspective correct
2903 v0.x, v0.y, 0.0f, 1.0f, s0/v0.w, t0/v0.w, 0.0f, 1.0f/v0.w, color.R(), color.G(), color.B(), color.A(),
2904 v1.x, v1.y, 0.0f, 1.0f, s1/v1.w, t1/v1.w, 0.0f, 1.0f/v1.w, color.R(), color.G(), color.B(), color.A(),
2905 v2.x, v2.y, 0.0f, 1.0f, s2/v2.w, t2/v2.w, 0.0f, 1.0f/v2.w, color.R(), color.G(), color.B(), color.A(),
2906 v3.x, v3.y, 0.0f, 1.0f, s3/v3.w, t3/v3.w, 0.0f, 1.0f/v3.w, color.R(), color.G(), color.B(), color.A(),
2907 };
2908
2909 CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
2910 CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
2911
2912 int TextureObjectLocation;
2913 int VertexLocation;
2914 int TextureCoord0Location;
2915 int VertexColorLocation;
2916 int FragmentColor;
2917
2918 if(!USE_ARB_SHADERS)
2919 {
2920 _shader_program_uv_persp_correction->Begin();
2921
2922 TextureObjectLocation = _shader_program_uv_persp_correction->GetUniformLocationARB("TextureObject0");
2923 VertexLocation = _shader_program_uv_persp_correction->GetAttributeLocation("iVertex");
2924 TextureCoord0Location = _shader_program_uv_persp_correction->GetAttributeLocation("iTexCoord0");
2925 VertexColorLocation = _shader_program_uv_persp_correction->GetAttributeLocation("iColor");
2926 FragmentColor = _shader_program_uv_persp_correction->GetUniformLocationARB ("color");
2927
2928 nux::GetGraphicsEngine ().SetTexture(GL_TEXTURE0, icon);
2929
2930 if(TextureObjectLocation != -1)
2931 CHECKGL( glUniform1iARB (TextureObjectLocation, 0) );
2932
2933 int VPMatrixLocation = _shader_program_uv_persp_correction->GetUniformLocationARB("ViewProjectionMatrix");
2934 if(VPMatrixLocation != -1)
2935 {
2936 nux::Matrix4 mat = nux::GetGraphicsEngine ().GetModelViewProjectionMatrix ();
2937 _shader_program_uv_persp_correction->SetUniformLocMatrix4fv ((GLint)VPMatrixLocation, 1, false, (GLfloat*)&(mat.m));
2938 }
2939 }
2940 else
2941 {
2942 _AsmShaderProg->Begin();
2943
2944 VertexLocation = nux::VTXATTRIB_POSITION;
2945 TextureCoord0Location = nux::VTXATTRIB_TEXCOORD0;
2946 VertexColorLocation = nux::VTXATTRIB_COLOR;
2947
2948 nux::GetGraphicsEngine().SetTexture(GL_TEXTURE0, icon);
2949 }
2950
2951 CHECKGL( glEnableVertexAttribArrayARB(VertexLocation) );
2952 CHECKGL( glVertexAttribPointerARB((GLuint)VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
2953
2954 if(TextureCoord0Location != -1)
2955 {
2956 CHECKGL( glEnableVertexAttribArrayARB(TextureCoord0Location) );
2957 CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
2958 }
2959
2960 if(VertexColorLocation != -1)
2961 {
2962 CHECKGL( glEnableVertexAttribArrayARB(VertexColorLocation) );
2963 CHECKGL( glVertexAttribPointerARB((GLuint)VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
2964 }
2965
2966 bkg_color.SetAlpha (bkg_color.A () * alpha);
2967
2968 if(!USE_ARB_SHADERS)
2969 {
2970 CHECKGL ( glUniform4fARB (FragmentColor, bkg_color.R(), bkg_color.G(), bkg_color.B(), bkg_color.A() ) );
2971 nux::GetGraphicsEngine ().SetTexture(GL_TEXTURE0, icon);
2972 CHECKGL( glDrawArrays(GL_QUADS, 0, 4) );
2973 }
2974 else
2975 {
2976 CHECKGL ( glProgramLocalParameter4fARB (GL_FRAGMENT_PROGRAM_ARB, 0, bkg_color.R(), bkg_color.G(), bkg_color.B(), bkg_color.A() ) );
2977 nux::GetGraphicsEngine ().SetTexture(GL_TEXTURE0, icon);
2978 CHECKGL( glDrawArrays(GL_QUADS, 0, 4) );
2979 }
2980
2981 if(VertexLocation != -1)
2982 CHECKGL( glDisableVertexAttribArrayARB(VertexLocation) );
2983 if(TextureCoord0Location != -1)
2984 CHECKGL( glDisableVertexAttribArrayARB(TextureCoord0Location) );
2985 if(VertexColorLocation != -1)
2986 CHECKGL( glDisableVertexAttribArrayARB(VertexColorLocation) );
2987
2988 if(!USE_ARB_SHADERS)
2989 {
2990 _shader_program_uv_persp_correction->End();
2991 }
2992 else
2993 {
2994 _AsmShaderProg->End();
2995 }
2996
2997 int markerCenter = (v1.y + v0.y) / 2;
2998
2999 if (arg.running_arrow && render_indicators)
3000 {
3001 if (!m_RunningIndicator)
3002 {
3003 GdkPixbuf *pbuf = gdk_pixbuf_new_from_file (PKGDATADIR"/running_indicator.png", NULL);
3004 m_RunningIndicator = nux::CreateTextureFromPixbuf (pbuf);
3005 g_object_unref (pbuf);
3006 }
3007 gPainter.Draw2DTexture (GfxContext, m_RunningIndicator, geo.x, markerCenter - (m_ActiveIndicator->GetHeight () / 2));
3008 }
3009
3010 if (arg.active_arrow && render_indicators)
3011 {
3012 if (!m_ActiveIndicator)
3013 {
3014 GdkPixbuf *pbuf = gdk_pixbuf_new_from_file (PKGDATADIR"/focused_indicator.png", NULL);
3015 m_ActiveIndicator = nux::CreateTextureFromPixbuf (pbuf);
3016 g_object_unref (pbuf);
3017 }
3018 gPainter.Draw2DTexture (GfxContext, m_ActiveIndicator, (geo.x + geo.width) - m_ActiveIndicator->GetWidth (), markerCenter - (m_ActiveIndicator->GetHeight () / 2));
3019 }
3020}
3021
3022void Launcher::DrawRenderArg (nux::GraphicsEngine& GfxContext, RenderArg arg, nux::Geometry geo)
3023{
3024 GfxContext.GetRenderStates ().SetSeparateBlend (true,
3025 GL_SRC_ALPHA,
3026 GL_ONE_MINUS_SRC_ALPHA,
3027 GL_ONE_MINUS_DST_ALPHA,
3028 GL_ONE);
3029
3030 GfxContext.GetRenderStates ().SetColorMask (true, true, true, true);
3031
3032 if (arg.backlight_intensity < 1.0f)
3033 {
3034 RenderIcon(GfxContext,
3035 arg,
3036 _icon_outline_texture,
3037 nux::Color(0xFF6D6D6D),
3038 1.0f - arg.backlight_intensity,
3039 arg.icon->_xform_coords["Tile"],
3040 geo,
3041 false);
3042 }
3043
3044 if (arg.backlight_intensity > 0.0f)
3045 {
3046 RenderIcon(GfxContext,
3047 arg,
3048 _icon_bkg_texture,
3049 arg.icon->BackgroundColor (),
3050 arg.backlight_intensity,
3051 arg.icon->_xform_coords["Tile"],
3052 geo,
3053 false);
3054 }
3055
3056 GfxContext.GetRenderStates ().SetSeparateBlend (true,
3057 GL_SRC_ALPHA,
3058 GL_ONE_MINUS_SRC_ALPHA,
3059 GL_ONE_MINUS_DST_ALPHA,
3060 GL_ONE);
3061 GfxContext.GetRenderStates ().SetColorMask (true, true, true, true);
3062
3063 RenderIcon (GfxContext,
3064 arg,
3065 arg.icon->TextureForSize (_icon_image_size),
3066 nux::Color::White,
3067 arg.alpha,
3068 arg.icon->_xform_coords["Image"],
3069 geo,
3070 true);
3071
3072 if (arg.backlight_intensity > 0.0f)
3073 {
3074 RenderIcon(GfxContext,
3075 arg,
3076 _icon_shine_texture,
3077 nux::Color::White,
3078 arg.backlight_intensity,
3079 arg.icon->_xform_coords["Tile"],
3080 geo,
3081 false);
3082 }
3083
3084 switch (arg.window_indicators)
3085 {
3086 case 2:
3087 RenderIcon(GfxContext,
3088 arg,
3089 _icon_2indicator,
3090 nux::Color::White,
3091 1.0f,
3092 arg.icon->_xform_coords["Tile"],
3093 geo,
3094 false);
3095 break;
3096 case 3:
3097 RenderIcon(GfxContext,
3098 arg,
3099 _icon_3indicator,
3100 nux::Color::White,
3101 1.0f,
3102 arg.icon->_xform_coords["Tile"],
3103 geo,
3104 false);
3105 break;
3106 case 4:
3107 RenderIcon(GfxContext,
3108 arg,
3109 _icon_4indicator,
3110 nux::Color::White,
3111 1.0f,
3112 arg.icon->_xform_coords["Tile"],
3113 geo,
3114 false);
3115 break;
3116 }
3117
3118 if (arg.glow_intensity > 0.0f)
3119 {
3120 RenderIcon(GfxContext,
3121 arg,
3122 _icon_glow_texture,
3123 arg.icon->GlowColor (),
3124 arg.glow_intensity,
3125 arg.icon->_xform_coords["Glow"],
3126 geo,
3127 false);
3128 }
3129
3130 if (arg.shimmer_progress > 0.0f && arg.shimmer_progress < 1.0f)
3131 {
3132 nux::Geometry base = GetGeometry ();
3133 int x1 = base.x + base.width;
3134 int x2 = base.x + base.width;
3135 float shimmer_constant = 1.9f;
3136
3137 x1 -= geo.width * arg.shimmer_progress * shimmer_constant;
3138 GfxContext.PushClippingRectangle(nux::Geometry (x1, geo.y, x2 - x1, geo.height));
3139
3140 float fade_out = 1.0f - CLAMP (((x2 - x1) - geo.width) / (geo.width * (shimmer_constant - 1.0f)), 0.0f, 1.0f);
3141
3142 RenderIcon(GfxContext,
3143 arg,
3144 _icon_glow_texture,
3145 arg.icon->GlowColor (),
3146 fade_out,
3147 arg.icon->_xform_coords["Glow"],
3148 geo,
3149 false);
3150
3151 GfxContext.PopClippingRectangle();
3152 }
3153}
3154
3155void Launcher::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
3156{
3157 nux::Geometry base = GetGeometry();
3158 GfxContext.PushClippingRectangle(base);
3159 nux::Geometry bkg_box;
3160 nux::Geometry shelf_box;
3161 std::list<Launcher::RenderArg> args;
3162 std::list<Launcher::RenderArg> shelf_args;
3163
3164 nux::ROPConfig ROP;
3165 ROP.Blend = false;
3166 ROP.SrcBlend = GL_SRC_ALPHA;
3167 ROP.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
3168
3169 RenderArgs (args, shelf_args, bkg_box, shelf_box);
3170 _last_shelf_area = shelf_box;
3171
3172 // clear region
3173 gPainter.PushDrawColorLayer(GfxContext, base, nux::Color(0x00000000), true, ROP);
3174
3175 // clip vertically but not horizontally
3176 GfxContext.PushClippingRectangle(nux::Geometry (base.x, bkg_box.y, base.width, bkg_box.height));
3177 GfxContext.GetRenderStates ().SetSeparateBlend (true,
3178 GL_SRC_ALPHA,
3179 GL_ONE_MINUS_SRC_ALPHA,
3180 GL_ONE_MINUS_DST_ALPHA,
3181 GL_ONE);
3182
3183 gPainter.Paint2DQuadColor (GfxContext, bkg_box, nux::Color(0xAA000000));
3184
3185 UpdateIconXForm (args);
3186 UpdateIconXForm (shelf_args);
3187 EventLogic ();
3188
3189 /* drag launcher */
3190 std::list<Launcher::RenderArg>::reverse_iterator rev_it;
3191 for (rev_it = args.rbegin (); rev_it != args.rend (); rev_it++)
3192 {
3193 if ((*rev_it).folding_rads >= 0.0f || (*rev_it).skip)
3194 continue;
3195
3196 DrawRenderArg (GfxContext, *rev_it, bkg_box);
3197 }
3198
3199 std::list<Launcher::RenderArg>::iterator it;
3200 for (it = args.begin(); it != args.end(); it++)
3201 {
3202 if ((*it).folding_rads < 0.0f || (*it).skip)
3203 continue;
3204
3205 DrawRenderArg (GfxContext, *it, bkg_box);
3206 }
3207
3208 /* draw shelf */
3209
3210 nux::Color shelf_color = nux::Color (0xCC000000);
3211 nux::Color shelf_zero = nux::Color (0x00000000);
3212 int shelf_shadow_height = 35;
3213
3214 nux::Geometry shelf_shadow = nux::Geometry (shelf_box.x, shelf_box.y - shelf_shadow_height, shelf_box.width, shelf_shadow_height);
3215 gPainter.Paint2DQuadColor (GfxContext, shelf_shadow, shelf_zero, shelf_color, shelf_color, shelf_zero);
3216 gPainter.Paint2DQuadColor (GfxContext, shelf_box, shelf_color);
3217
3218 for (it = shelf_args.begin(); it != shelf_args.end(); it++)
3219 {
3220 if ((*it).skip)
3221 continue;
3222
3223 DrawRenderArg (GfxContext, *it, bkg_box);
3224 }
3225
3226 gPainter.Paint2DQuadColor (GfxContext, nux::Geometry (bkg_box.x + bkg_box.width - 1, bkg_box.y, 1, bkg_box.height), nux::Color(0x60FFFFFF));
3227
3228 GfxContext.GetRenderStates().SetColorMask (true, true, true, true);
3229 GfxContext.GetRenderStates ().SetSeparateBlend (false,
3230 GL_SRC_ALPHA,
3231 GL_ONE_MINUS_SRC_ALPHA,
3232 GL_SRC_ALPHA,
3233 GL_ONE_MINUS_SRC_ALPHA);
3234
3235 gPainter.PopBackground();
3236 GfxContext.PopClippingRectangle();
3237 GfxContext.PopClippingRectangle();
3238}
3239
3240void Launcher::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw)
3241{
3242}
3243
3244void Launcher::PreLayoutManagement()
3245{
3246 View::PreLayoutManagement();
3247 if(m_CompositionLayout)
3248 {
3249 m_CompositionLayout->SetGeometry(GetGeometry());
3250 }
3251}
3252
3253long Launcher::PostLayoutManagement(long LayoutResult)
3254{
3255 View::PostLayoutManagement(LayoutResult);
3256
3257 _mouse_position = nux::Point2 (0, 0);
3258
3259 return nux::eCompliantHeight | nux::eCompliantWidth;
3260}
3261
3262void Launcher::PositionChildLayout(float offsetX, float offsetY)
3263{
3264}
3265
3266bool Launcher::TooltipNotify(LauncherIcon* Icon)
3267{
3268 if(GetActiveMenuIcon())
3269 return false;
3270 return true;
3271}
3272
3273bool Launcher::MenuNotify(LauncherIcon* Icon)
3274{
3275
3276
3277 return true;
3278}
3279
3280void Launcher::NotifyMenuTermination(LauncherIcon* Icon)
3281{
3282}
3283
3284void Launcher::RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags)
3285{
3286 _mouse_position = nux::Point2 (x, y);
3287
3288 MouseDownLogic (x, y, button_flags, key_flags);
3289 EnsureAnimation ();
3290}
3291
3292void Launcher::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags)
3293{
3294 _mouse_position = nux::Point2 (x, y);
3295 nux::Geometry geo = GetGeometry ();
3296
3297 if (_launcher_action_state == ACTION_DRAG_LAUNCHER && !geo.IsInside(nux::Point(x, y)))
3298 {
3299 // we are no longer hovered
3300 UnsetHover ();
3301 }
3302
3303 MouseUpLogic (x, y, button_flags, key_flags);
3304 _launcher_action_state = ACTION_NONE;
3305 EnsureAnimation ();
3306}
3307
3308void Launcher::RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
3309{
3310 _mouse_position = nux::Point2 (x, y);
3311
3312 _dnd_delta += dy;
3313
3314 if (nux::Abs (_dnd_delta) < 15 && _launcher_action_state != ACTION_DRAG_LAUNCHER)
3315 return;
3316
3317 if (_icon_under_mouse)
3318 {
3319 _icon_under_mouse->MouseLeave.emit ();
3320 _icon_under_mouse->_mouse_inside = false;
3321 _icon_under_mouse = 0;
3322 }
3323
3324 _launcher_action_state = ACTION_DRAG_LAUNCHER;
3325 EnsureAnimation ();
3326}
3327
3328void Launcher::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags)
3329{
3330 _mouse_position = nux::Point2 (x, y);
3331 _mouse_inside_launcher = true;
3332
3333 if (!_last_shelf_area.IsInside (nux::Point (x, y)))
3334 SetHover ();
3335
3336 EventLogic ();
3337 EnsureAnimation ();
3338}
3339
3340void Launcher::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags)
3341{
3342 _mouse_position = nux::Point2 (x, y);
3343 _mouse_inside_launcher = false;
3344
3345 if (_launcher_action_state != ACTION_DRAG_LAUNCHER)
3346 UnsetHover ();
3347
3348 EventLogic ();
3349 EnsureAnimation ();
3350}
3351
3352void Launcher::RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
3353{
3354 _mouse_position = nux::Point2 (x, y);
3355
3356 if (!_last_shelf_area.IsInside (nux::Point (x, y)))
3357 {
3358 SetHover ();
3359 EnsureAnimation ();
3360 }
3361 // Every time the mouse moves, we check if it is inside an icon...
3362
3363 EventLogic ();
3364}
3365
3366void Launcher::RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags)
3367{
3368}
3369
3370const gchar* Launcher::GetName ()
3371{
3372 return "Launcher";
3373}
3374
3375void Launcher::AddProperties (GVariantBuilder *builder)
3376{
3377}
3378
3379void Launcher::EventLogic ()
3380{
3381 if (_launcher_action_state == ACTION_DRAG_LAUNCHER)
3382 return;
3383
3384 LauncherIcon* launcher_icon = 0;
3385
3386 if (_mouse_inside_launcher)
3387 launcher_icon = MouseIconIntersection (_mouse_position.x, _mouse_position.y);
3388
3389 if (_icon_under_mouse && (_icon_under_mouse != launcher_icon))
3390 {
3391 _icon_under_mouse->MouseLeave.emit ();
3392 _icon_under_mouse->_mouse_inside = false;
3393 _icon_under_mouse = 0;
3394 }
3395
3396 if (launcher_icon && (_icon_under_mouse != launcher_icon))
3397 {
3398 launcher_icon->MouseEnter.emit ();
3399 launcher_icon->_mouse_inside = true;
3400 _icon_under_mouse = launcher_icon;
3401 }
3402}
3403
3404void Launcher::MouseDownLogic (int x, int y, unsigned long button_flags, unsigned long key_flags)
3405{
3406 LauncherIcon* launcher_icon = 0;
3407 launcher_icon = MouseIconIntersection (_mouse_position.x, _mouse_position.y);
3408
3409 if (launcher_icon)
3410 {
3411 _icon_mouse_down = launcher_icon;
3412 launcher_icon->MouseDown.emit (nux::GetEventButton (button_flags));
3413 }
3414}
3415
3416void Launcher::MouseUpLogic (int x, int y, unsigned long button_flags, unsigned long key_flags)
3417{
3418 LauncherIcon* launcher_icon = 0;
3419 launcher_icon = MouseIconIntersection (_mouse_position.x, _mouse_position.y);
3420
3421 if (_icon_mouse_down && (_icon_mouse_down == launcher_icon))
3422 {
3423 _icon_mouse_down->MouseUp.emit (nux::GetEventButton (button_flags));
3424
3425 if (_launcher_action_state != ACTION_DRAG_LAUNCHER)
3426 _icon_mouse_down->MouseClick.emit (nux::GetEventButton (button_flags));
3427 }
3428
3429 if (launcher_icon && (_icon_mouse_down != launcher_icon))
3430 {
3431 launcher_icon->MouseUp.emit (nux::GetEventButton (button_flags));
3432 }
3433
3434 if (_launcher_action_state == ACTION_DRAG_LAUNCHER)
3435 {
3436 SetTimeStruct (&_drag_end_time);
3437 }
3438
3439 _icon_mouse_down = 0;
3440}
3441
3442LauncherIcon* Launcher::MouseIconIntersection (int x, int y)
3443{
3444 LauncherModel::iterator it;
3445 LauncherModel::reverse_iterator rev_it;
3446 // We are looking for the icon at screen coordinates x, y;
3447 nux::Point2 mouse_position(x, y);
3448 int inside = 0;
3449
3450 for (it = _model->shelf_begin(); it != _model->shelf_end (); it++)
3451 {
3452 if (!(*it)->GetQuirk (LAUNCHER_ICON_QUIRK_VISIBLE))
3453 continue;
3454
3455 nux::Point2 screen_coord [4];
3456 for (int i = 0; i < 4; i++)
3457 {
3458 screen_coord [i].x = (*it)->_xform_coords["HitArea"] [i].x;
3459 screen_coord [i].y = (*it)->_xform_coords["HitArea"] [i].y;
3460 }
3461 inside = PointInside2DPolygon (screen_coord, 4, mouse_position, 1);
3462 if (inside)
3463 return (*it);
3464 }
3465
3466 // Because of the way icons fold and stack on one another, we must proceed in 2 steps.
3467 for (rev_it = _model->rbegin (); rev_it != _model->rend (); rev_it++)
3468 {
3469 if ((*rev_it)->_folding_angle < 0.0f || !(*rev_it)->GetQuirk (LAUNCHER_ICON_QUIRK_VISIBLE))
3470 continue;
3471
3472 nux::Point2 screen_coord [4];
3473 for (int i = 0; i < 4; i++)
3474 {
3475 screen_coord [i].x = (*rev_it)->_xform_coords["HitArea"] [i].x;
3476 screen_coord [i].y = (*rev_it)->_xform_coords["HitArea"] [i].y;
3477 }
3478 inside = PointInside2DPolygon (screen_coord, 4, mouse_position, 1);
3479 if (inside)
3480 return (*rev_it);
3481 }
3482
3483 for (it = _model->begin(); it != _model->end (); it++)
3484 {
3485 if ((*it)->_folding_angle >= 0.0f || !(*it)->GetQuirk (LAUNCHER_ICON_QUIRK_VISIBLE))
3486 continue;
3487
3488 nux::Point2 screen_coord [4];
3489 for (int i = 0; i < 4; i++)
3490 {
3491 screen_coord [i].x = (*it)->_xform_coords["HitArea"] [i].x;
3492 screen_coord [i].y = (*it)->_xform_coords["HitArea"] [i].y;
3493 }
3494 inside = PointInside2DPolygon (screen_coord, 4, mouse_position, 1);
3495 if (inside)
3496 return (*it);
3497 }
3498
3499 return 0;
3500}
3501
3502void Launcher::SetIconXForm (LauncherIcon *icon, nux::Matrix4 ViewProjectionMatrix, nux::Geometry geo,
3503 float x, float y, float w, float h, float z, std::string name)
3504{
3505 nux::Vector4 v0 = nux::Vector4(x, y, z, 1.0f);
3506 nux::Vector4 v1 = nux::Vector4(x, y+h, z, 1.0f);
3507 nux::Vector4 v2 = nux::Vector4(x+w, y+h, z, 1.0f);
3508 nux::Vector4 v3 = nux::Vector4(x+w, y, z, 1.0f);
3509
3510 v0 = ViewProjectionMatrix * v0;
3511 v1 = ViewProjectionMatrix * v1;
3512 v2 = ViewProjectionMatrix * v2;
3513 v3 = ViewProjectionMatrix * v3;
3514
3515 v0.divide_xyz_by_w();
3516 v1.divide_xyz_by_w();
3517 v2.divide_xyz_by_w();
3518 v3.divide_xyz_by_w();
3519
3520 // normalize to the viewport coordinates and translate to the correct location
3521 v0.x = geo.width *(v0.x + 1.0f)/2.0f - geo.width/2.0f + x + w/2.0f;
3522 v0.y = -geo.height*(v0.y - 1.0f)/2.0f - geo.height/2.0f + y + h/2.0f;
3523 v1.x = geo.width *(v1.x + 1.0f)/2.0f - geo.width/2.0f + x + w/2.0f;;
3524 v1.y = -geo.height*(v1.y - 1.0f)/2.0f - geo.height/2.0f + y + h/2.0f;
3525 v2.x = geo.width *(v2.x + 1.0f)/2.0f - geo.width/2.0f + x + w/2.0f;
3526 v2.y = -geo.height*(v2.y - 1.0f)/2.0f - geo.height/2.0f + y + h/2.0f;
3527 v3.x = geo.width *(v3.x + 1.0f)/2.0f - geo.width/2.0f + x + w/2.0f;
3528 v3.y = -geo.height*(v3.y - 1.0f)/2.0f - geo.height/2.0f + y + h/2.0f;
3529
3530
3531 nux::Vector4* vectors = icon->_xform_coords[name];
3532
3533 vectors[0].x = v0.x;
3534 vectors[0].y = v0.y;
3535 vectors[0].z = v0.z;
3536 vectors[0].w = v0.w;
3537 vectors[1].x = v1.x;
3538 vectors[1].y = v1.y;
3539 vectors[1].z = v1.z;
3540 vectors[1].w = v1.w;
3541 vectors[2].x = v2.x;
3542 vectors[2].y = v2.y;
3543 vectors[2].z = v2.z;
3544 vectors[2].w = v2.w;
3545 vectors[3].x = v3.x;
3546 vectors[3].y = v3.y;
3547 vectors[3].z = v3.z;
3548 vectors[3].w = v3.w;
3549}
3550
3551void Launcher::UpdateIconXForm (std::list<Launcher::RenderArg> args)
3552{
3553 nux::Geometry geo = GetGeometry ();
3554 nux::Matrix4 ObjectMatrix;
3555 nux::Matrix4 ViewMatrix;
3556 nux::Matrix4 ProjectionMatrix;
3557 nux::Matrix4 ViewProjectionMatrix;
3558
3559 GetInverseScreenPerspectiveMatrix(ViewMatrix, ProjectionMatrix, geo.width, geo.height, 0.1f, 1000.0f, DEGTORAD(90));
3560
3561 //LauncherModel::iterator it;
3562 std::list<Launcher::RenderArg>::iterator it;
3563 for(it = args.begin(); it != args.end(); it++)
3564 {
3565 if ((*it).skip)
3566 continue;
3567
3568 LauncherIcon* launcher_icon = (*it).icon;
3569
3570 // We to store the icon angle in the icons itself. Makes one thing easier afterward.
3571 launcher_icon->_folding_angle = (*it).folding_rads;
3572
3573 float w = _icon_size;
3574 float h = _icon_size;
3575 float x = (*it).center.x - w/2.0f; // x: top left corner
3576 float y = (*it).center.y - h/2.0f; // y: top left corner
3577 float z = (*it).center.z;
3578
3579 ObjectMatrix = nux::Matrix4::TRANSLATE(geo.width/2.0f, geo.height/2.0f, z) * // Translate the icon to the center of the viewport
3580 nux::Matrix4::ROTATEX((*it).folding_rads) * // rotate the icon
3581 nux::Matrix4::TRANSLATE(-x - w/2.0f, -y - h/2.0f, -z); // Put the center the icon to (0, 0)
3582
3583 ViewProjectionMatrix = ProjectionMatrix*ViewMatrix*ObjectMatrix;
3584
3585 SetIconXForm (launcher_icon, ViewProjectionMatrix, geo, x, y, w, h, z, "Tile");
3586
3587 w = _icon_image_size;
3588 h = _icon_image_size;
3589 x = (*it).center.x - _icon_size/2.0f + _icon_image_size_delta/2.0f;
3590 y = (*it).center.y - _icon_size/2.0f + _icon_image_size_delta/2.0f;
3591 z = (*it).center.z;
3592
3593 SetIconXForm (launcher_icon, ViewProjectionMatrix, geo, x, y, w, h, z, "Image");
3594
3595 w = _icon_glow_size;
3596 h = _icon_glow_size;
3597 x = (*it).center.x - _icon_glow_size/2.0f;
3598 y = (*it).center.y - _icon_glow_size/2.0f;
3599 z = (*it).center.z;
3600
3601 SetIconXForm (launcher_icon, ViewProjectionMatrix, geo, x, y, w, h, z, "Glow");
3602
3603 w = geo.width + 2;
3604 h = _icon_size + _space_between_icons;
3605 x = (*it).center.x - w/2.0f;
3606 y = (*it).center.y - h/2.0f;
3607 z = (*it).center.z;
3608
3609 SetIconXForm (launcher_icon, ViewProjectionMatrix, geo, x, y, w, h, z, "HitArea");
3610 }
3611}
3612
3613void GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, nux::Matrix4& PerspectiveMatrix,
3614 int ViewportWidth,
3615 int ViewportHeight,
3616 float NearClipPlane,
3617 float FarClipPlane,
3618 float Fovy)
3619{
3620/*
3621 Objective:
3622 Given a perspective matrix defined by (Fovy, AspectRatio, NearPlane, FarPlane), we want to compute
3623 the ModelView matrix that transform a quad defined by its top-left coord (0, 0) and its
3624 bottom-right coord (WindowWidth, WindowHeight) into a full screen quad that covers the entire viewport (one to one).
3625 Any quad that is facing the camera and whose 4 points are on the 4 guiding line of the view frustum (pyramid)
3626 will always cover the entire viewport one to one (when projected on the screen).
3627 So all we have to do is to define a quad with x:[-x_cs, x_cs] and y:[-y_cs, y_cs] and find the z distance in eye space (z_cs) so that
3628 the quad touches the 4 guiding lines of the view frustum.
3629 We consider a well centered projection view (no skewing, no oblique clipping plane, ...) and derive the following equations:
3630 x_cs = AspectRatio*y_cs
3631 y_cs/z_cs = tanf(Fovy/2) ==> z_cs = y_cs*1/tanf(Fovy/2) (this is the absolute value the quad depth value will be -z_cs since we are using OpenGL right hand coord system).
3632
3633 The quad (in camera space) facing the camera and centered around the camera view axis is defined by the points (-x_cs, y_cs) (top-left)
3634 and the point (x_cs, -y_cs) (bottom-right). If we move that quad along the camera view axis and place it at a distance z_cs of the camera,
3635 then its 4 corners are each on the 4 lines of the view frustum.
3636
3637 (-x_cs, y_cs) Camera Space
3638 ^
3639 __________|__________
3640 | | |
3641 | | |
3642 | |(0, 0) |
3643 |----------|----------|->
3644 | | |
3645 | | |
3646 |__________|__________|
3647 (x_cs, -y_cs)
3648
3649 The full-screen quad (in screen space) is defined by the point (0, 0) (top-left) and (WindowWidth, WindowHeight) (bottom-right).
3650 We can choose and arbitrary value y_cs and compute the z_cs position in camera space that will produce a quad in camera space that projects into
3651 the full-screen space.
3652
3653 (0, 0) Screen Space
3654 _____________________->
3655 | | |
3656 | | |
3657 | | |
3658 |----------|----------|
3659 | | |
3660 | | |
3661 |__________|__________|
3662 v (WindowWidth, WindowHeight)
3663
3664 The model view matrix is the succession of transformation that convert the quad (0, 0, WindowWidth, WindowHeight) into
3665 the quad (-x_cs, y_cs, x_cs, -y_cs)
3666
3667 Screen Space Camera Space
3668 x ----> x_ = x*2*x_cs/WindowWidth - x_cs
3669 y ----> y_ = -y*2*y_cs/WindowHeight + y_cs
3670 z ----> z_ = A*z -y_cs*1/tanf(Fovy/2)
3671 where A is a coefficient that can attenuate the rate of change in depth when the quad moves along the camera axis
3672
3673 If the following is the projection matrix:
3674
3675 (a, 0, 0, 0) a = 1/(AspectRatio*tan(Fovy/2))
3676 (0, b, 0, 0) b = 1/tan(Fovy/2)
3677 (0, 0, c, d)
3678 (0, 0, -1, 0)
3679
3680 and the camera space vertex is (x_cs, y_cs, z_cs, w_cs) projects to the top left corner of the view port on the screen ((-1, 1) in clip space), then
3681 x_cs*a/(-z_cs) = -1; | z_cs = x_cs*a x_cs*a = -y_cs*b ==> x_cs = y_cs*AspectRatio
3682 | ==> ==>
3683 y_cs*b/(-z_cs) = +1; | z_cs = -y_cs*b z_cs = -y_cs*1/tanf(Fovy/2)
3684*/
3685
3686
3687 float AspectRatio = (float)ViewportWidth/(float)ViewportHeight;
3688 float CameraToScreenDistance = -1.0f;
3689 float y_cs = -CameraToScreenDistance*tanf(0.5f*Fovy/* *3.1415926/180.0f*/);
3690 float x_cs = y_cs*AspectRatio;
3691 //float CameraToScreenDistance = -y_cs*1.0f/(tanf(0.5f*Fovy/* *3.1415926/180.0f*/));
3692
3693 ViewMatrix = nux::Matrix4::TRANSLATE(-x_cs, y_cs, CameraToScreenDistance) *
3694 nux::Matrix4::SCALE(2.0f*x_cs/ViewportWidth, -2.0f*y_cs/ViewportHeight, -2.0f * 3 * y_cs/ViewportHeight /* or -2.0f * x_cs/ViewportWidth*/ );
3695
3696 PerspectiveMatrix.Perspective(Fovy, AspectRatio, NearClipPlane, FarClipPlane);
3697
3698// // Example usage with the matrices above:
3699// float W = 300;
3700// float H = 300;
3701// // centered quad
3702// float X = (ViewportWidth - W)/2.0;
3703// float Y = (ViewportHeight - H)/2.0;
3704// float Z = 0.0f;
3705//
3706// {
3707// glPushMatrix();
3708// // Local Transformation of the object
3709// glTranslatef(0.0f, 0.0f, ObjectDistanceToCamera);
3710// glTranslatef(X + W/2.0f, Y + H/2.0f, 0.0f);
3711// glRotatef(cameraAngleY, 1, 0, 0);
3712// glRotatef(cameraAngleX, 0, 1, 0);
3713// glTranslatef(-X - W/2.0f, -Y - H/2.0f, 0.0f);
3714//
3715// glBegin(GL_QUADS);
3716// {
3717// glNormal3f(0.0f, 0.0f, 1.0f);
3718//
3719// glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
3720// glVertex4f(X, Y, Z, 1.0f);
3721//
3722// glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
3723// glVertex4f(X, Y+H, Z, 1.0f);
3724//
3725// glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
3726// glVertex4f(X+W, Y+H, Z, 1.0f);
3727//
3728// glColor4f(0.0f, 1.0f, 1.0f, 1.0f);
3729// glVertex4f(X+W, Y, Z, 1.0f);
3730// }
3731// glEnd();
3732}
3733
3734void Launcher::SetActiveQuicklist (QuicklistView *quicklist)
3735{
3736 // Assert: _active_quicklist should be 0
3737 _active_quicklist = quicklist;
3738}
3739
3740QuicklistView *Launcher::GetActiveQuicklist ()
3741{
3742 return _active_quicklist;
3743}
3744
3745void Launcher::CancelActiveQuicklist (QuicklistView *quicklist)
3746{
3747 if (_active_quicklist == quicklist)
3748 _active_quicklist = 0;
3749}
3750
3751>>>>>>> MERGE-SOURCE
18683752
=== modified file 'src/Launcher.h'
--- src/Launcher.h 2010-12-01 22:28:50 +0000
+++ src/Launcher.h 2010-12-02 15:23:26 +0000
@@ -1,245 +1,494 @@
1/*1<<<<<<< TREE
2 * Copyright (C) 2010 Canonical Ltd2/*
3 *3 * Copyright (C) 2010 Canonical Ltd
4 * This program is free software: you can redistribute it and/or modify4 *
5 * it under the terms of the GNU General Public License version 3 as5 * This program is free software: you can redistribute it and/or modify
6 * published by the Free Software Foundation.6 * it under the terms of the GNU General Public License version 3 as
7 *7 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,8 *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of9 * This program is distributed in the hope that it will be useful,
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * GNU General Public License for more details.11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 *12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License13 *
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * You should have received a copy of the GNU General Public License
15 *15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Authored by: Jason Smith <jason.smith@canonical.com>16 *
17 * Authored by: Jay Taoko <jay.taoko@canonical.com>17 * Authored by: Jason Smith <jason.smith@canonical.com>
18 */18 * Authored by: Jay Taoko <jay.taoko@canonical.com>
1919 */
20#ifndef LAUNCHER_H20
21#define LAUNCHER_H21#ifndef LAUNCHER_H
2222#define LAUNCHER_H
23#include <sys/time.h>23
2424#include <sys/time.h>
25#include <Nux/View.h>25
26#include <Nux/BaseWindow.h>26#include <Nux/View.h>
27#include "Introspectable.h"27#include <Nux/BaseWindow.h>
28#include "LauncherIcon.h"28#include "Introspectable.h"
29#include "NuxGraphics/IOpenGLAsmShader.h"29#include "LauncherIcon.h"
30#include "Nux/TimerProc.h"30#include "NuxGraphics/IOpenGLAsmShader.h"
3131#include "Nux/TimerProc.h"
32class LauncherModel;32
33class QuicklistView;33class LauncherModel;
3434class QuicklistView;
35class Launcher : public Introspectable, public nux::View35
36{36class Launcher : public Introspectable, public nux::View
37public:37{
38 Launcher(nux::BaseWindow *parent, NUX_FILE_LINE_PROTO);38public:
39 ~Launcher();39 Launcher(nux::BaseWindow *parent, NUX_FILE_LINE_PROTO);
4040 ~Launcher();
41 virtual long ProcessEvent(nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo);41
42 virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);42 virtual long ProcessEvent(nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
43 virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);43 virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
44 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);44 virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
4545 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
46 LauncherIcon* GetActiveTooltipIcon() {return m_ActiveTooltipIcon;}46
47 LauncherIcon* GetActiveMenuIcon() {return m_ActiveMenuIcon;}47 LauncherIcon* GetActiveTooltipIcon() {return m_ActiveTooltipIcon;}
4848 LauncherIcon* GetActiveMenuIcon() {return m_ActiveMenuIcon;}
49 bool TooltipNotify(LauncherIcon* Icon);49
50 bool MenuNotify(LauncherIcon* Icon);50 bool TooltipNotify(LauncherIcon* Icon);
51 51 bool MenuNotify(LauncherIcon* Icon);
52 void SetIconSize(int tile_size, int icon_size);52
53 void NotifyMenuTermination(LauncherIcon* Icon);53 void SetIconSize(int tile_size, int icon_size);
54 54 void NotifyMenuTermination(LauncherIcon* Icon);
55 void SetModel (LauncherModel *model);55
56 56 void SetModel (LauncherModel *model);
57 void SetFloating (bool floating);57
58 58 void SetFloating (bool floating);
59 void SetAutohide (bool autohide, nux::View *show_trigger);59
60 bool AutohideEnabled ();60 void SetAutohide (bool autohide, nux::View *show_trigger);
61 61 bool AutohideEnabled ();
62 virtual void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);62
63 virtual void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);63 virtual void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
64 virtual void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);64 virtual void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
65 virtual void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);65 virtual void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
66 virtual void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);66 virtual void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
67 virtual void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);67 virtual void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
68 virtual void RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags);68 virtual void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
6969 virtual void RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags);
70 //! Called by LauncherIcon to signal that a Quicklist is becoming active.70
71 void SetActiveQuicklist (QuicklistView *quicklist);71 //! Called by LauncherIcon to signal that a Quicklist is becoming active.
72 //! Get the active qicklist72 void SetActiveQuicklist (QuicklistView *quicklist);
73 QuicklistView *GetActiveQuicklist ();73 //! Get the active qicklist
74 //! Called by LauncherIcon to signal that a Quicklist is becoming unactive.74 QuicklistView *GetActiveQuicklist ();
75 void CancelActiveQuicklist (QuicklistView *quicklist);75 //! Called by LauncherIcon to signal that a Quicklist is becoming unactive.
7676 void CancelActiveQuicklist (QuicklistView *quicklist);
77protected: 77
78 // Introspectable methods78protected:
79 const gchar* GetName ();79 // Introspectable methods
80 void AddProperties (GVariantBuilder *builder);80 const gchar* GetName ();
8181 void AddProperties (GVariantBuilder *builder);
82private:82
83 typedef enum83private:
84 {84 typedef enum
85 LAUNCHER_FOLDED,85 {
86 LAUNCHER_UNFOLDED86 LAUNCHER_FOLDED,
87 } LauncherState;87 LAUNCHER_UNFOLDED
8888 } LauncherState;
89 typedef enum89
90 {90 typedef enum
91 ACTION_NONE,91 {
92 ACTION_DRAG_LAUNCHER,92 ACTION_NONE,
93 ACTION_DRAG_ICON,93 ACTION_DRAG_LAUNCHER,
94 } LauncherActionState;94 ACTION_DRAG_ICON,
95 95 } LauncherActionState;
96 typedef struct96
97 {97 typedef struct
98 LauncherIcon *icon;98 {
99 nux::Point3 center;99 LauncherIcon *icon;
100 float folding_rads;100 nux::Point3 center;
101 float alpha;101 float folding_rads;
102 float backlight_intensity;102 float alpha;
103 float glow_intensity;103 float backlight_intensity;
104 float shimmer_progress;104 float glow_intensity;
105 bool running_arrow;105 float shimmer_progress;
106 bool active_arrow;106 bool running_arrow;
107 bool skip;107 bool active_arrow;
108 int window_indicators;108 bool skip;
109 } RenderArg;109 int window_indicators;
110 110 } RenderArg;
111 static gboolean AnimationTimeout (gpointer data);111
112 static gboolean OnAutohideTimeout (gpointer data);112 static gboolean AnimationTimeout (gpointer data);
113 static gboolean StrutHack (gpointer data);113 static gboolean OnAutohideTimeout (gpointer data);
114 114 static gboolean StrutHack (gpointer data);
115 void OnTriggerMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags);115
116 void OnTriggerMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags);116 void OnTriggerMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags);
117 117 void OnTriggerMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags);
118 bool IconNeedsAnimation (LauncherIcon *icon, struct timespec current);118
119 bool AnimationInProgress ();119 bool IconNeedsAnimation (LauncherIcon *icon, struct timespec current);
120 void SetTimeStruct (struct timespec *timer, struct timespec *sister = 0, int sister_relation = 0);120 bool AnimationInProgress ();
121 121 void SetTimeStruct (struct timespec *timer, struct timespec *sister = 0, int sister_relation = 0);
122 void EnsureAnimation ();122
123 void SetupAutohideTimer ();123 void EnsureAnimation ();
124 124 void SetupAutohideTimer ();
125 float DnDExitProgress ();125
126 float GetHoverProgress ();126 float DnDExitProgress ();
127 float AutohideProgress ();127 float GetHoverProgress ();
128 float IconPresentProgress (LauncherIcon *icon, struct timespec current);128 float AutohideProgress ();
129 float IconUrgentProgress (LauncherIcon *icon, struct timespec current);129 float IconPresentProgress (LauncherIcon *icon, struct timespec current);
130 float IconShimmerProgress (LauncherIcon *icon, struct timespec current);130 float IconUrgentProgress (LauncherIcon *icon, struct timespec current);
131 float IconUrgentPulseValue (LauncherIcon *icon, struct timespec current);131 float IconShimmerProgress (LauncherIcon *icon, struct timespec current);
132 float IconStartingPulseValue (LauncherIcon *icon, struct timespec current);132 float IconUrgentPulseValue (LauncherIcon *icon, struct timespec current);
133 float IconBackgroundIntensity (LauncherIcon *icon, struct timespec current);133 float IconStartingPulseValue (LauncherIcon *icon, struct timespec current);
134134 float IconBackgroundIntensity (LauncherIcon *icon, struct timespec current);
135 void SetHover ();135
136 void UnsetHover ();136 void SetHover ();
137 void SetHidden (bool hidden);137 void UnsetHover ();
138 138 void SetHidden (bool hidden);
139 void SetDndDelta (float x, float y, nux::Geometry geo, struct timespec current);139
140 140 void SetDndDelta (float x, float y, nux::Geometry geo, struct timespec current);
141 void SetupRenderArg (LauncherIcon *icon, struct timespec current, RenderArg &arg);141
142 void RenderArgs (std::list<Launcher::RenderArg> &launcher_args, 142 void SetupRenderArg (LauncherIcon *icon, struct timespec current, RenderArg &arg);
143 std::list<Launcher::RenderArg> &shelf_args, 143 void RenderArgs (std::list<Launcher::RenderArg> &launcher_args,
144 nux::Geometry &box_geo, nux::Geometry &shelf_geo);144 std::list<Launcher::RenderArg> &shelf_args,
145145 nux::Geometry &box_geo, nux::Geometry &shelf_geo);
146 void DrawRenderArg (nux::GraphicsEngine& GfxContext, RenderArg arg, nux::Geometry geo);146
147147 void DrawRenderArg (nux::GraphicsEngine& GfxContext, RenderArg arg, nux::Geometry geo);
148 void OnIconAdded (void *icon_pointer);148
149 void OnIconRemoved (void *icon_pointer);149 void OnIconAdded (void *icon_pointer);
150 void OnOrderChanged ();150 void OnIconRemoved (void *icon_pointer);
151151 void OnOrderChanged ();
152 void OnIconNeedsRedraw (void *icon);152
153153 void OnIconNeedsRedraw (void *icon);
154 void RenderIcon (nux::GraphicsEngine& GfxContext, 154
155 RenderArg arg, 155 void RenderIcon (nux::GraphicsEngine& GfxContext,
156 nux::BaseTexture *icon, 156 RenderArg arg,
157 nux::Color bkg_color, 157 nux::BaseTexture *icon,
158 float alpha, 158 nux::Color bkg_color,
159 nux::Vector4 xform_coords[], 159 float alpha,
160 nux::Geometry geo,160 nux::Vector4 xform_coords[],
161 bool render_indicators);161 nux::Geometry geo,
162 162 bool render_indicators);
163 void SetIconXForm (LauncherIcon *icon, nux::Matrix4 ViewProjectionMatrix, nux::Geometry geo, 163
164 float x, float y, float w, float h, float z, std::string name); 164 void SetIconXForm (LauncherIcon *icon, nux::Matrix4 ViewProjectionMatrix, nux::Geometry geo,
165 void UpdateIconXForm (std::list<Launcher::RenderArg> args);165 float x, float y, float w, float h, float z, std::string name);
166 166 void UpdateIconXForm (std::list<Launcher::RenderArg> args);
167 LauncherIcon* MouseIconIntersection (int x, int y);167
168 void EventLogic ();168 LauncherIcon* MouseIconIntersection (int x, int y);
169 void MouseDownLogic (int x, int y, unsigned long button_flags, unsigned long key_flags);169 void EventLogic ();
170 void MouseUpLogic (int x, int y, unsigned long button_flags, unsigned long key_flags);170 void MouseDownLogic (int x, int y, unsigned long button_flags, unsigned long key_flags);
171171 void MouseUpLogic (int x, int y, unsigned long button_flags, unsigned long key_flags);
172 virtual void PreLayoutManagement();172
173 virtual long PostLayoutManagement(long LayoutResult);173 virtual void PreLayoutManagement();
174 virtual void PositionChildLayout(float offsetX, float offsetY);174 virtual long PostLayoutManagement(long LayoutResult);
175 175 virtual void PositionChildLayout(float offsetX, float offsetY);
176176
177 nux::HLayout* m_Layout;177
178 int m_ContentOffsetY;178 nux::HLayout* m_Layout;
179179 int m_ContentOffsetY;
180 LauncherIcon* m_ActiveTooltipIcon;180
181 LauncherIcon* m_ActiveMenuIcon;181 LauncherIcon* m_ActiveTooltipIcon;
182182 LauncherIcon* m_ActiveMenuIcon;
183 183
184 QuicklistView* _active_quicklist;184
185 185 QuicklistView* _active_quicklist;
186 bool _hovered;186
187 bool _floating;187 bool _hovered;
188 bool _autohide;188 bool _floating;
189 bool _hidden;189 bool _autohide;
190 bool _mouse_inside_launcher;190 bool _hidden;
191191 bool _mouse_inside_launcher;
192 float _folded_angle;192
193 float _neg_folded_angle;193 float _folded_angle;
194 float _folded_z_distance;194 float _neg_folded_angle;
195 float _launcher_top_y;195 float _folded_z_distance;
196 float _launcher_bottom_y;196 float _launcher_top_y;
197197 float _launcher_bottom_y;
198 LauncherState _launcher_state;198
199 LauncherActionState _launcher_action_state;199 LauncherState _launcher_state;
200 LauncherIcon* _icon_under_mouse;200 LauncherActionState _launcher_action_state;
201 LauncherIcon* _icon_mouse_down;201 LauncherIcon* _icon_under_mouse;
202202 LauncherIcon* _icon_mouse_down;
203 int _space_between_icons;203
204 int _icon_size;204 int _space_between_icons;
205 int _icon_image_size;205 int _icon_size;
206 int _icon_image_size_delta;206 int _icon_image_size;
207 int _icon_glow_size;207 int _icon_image_size_delta;
208 int _dnd_delta;208 int _icon_glow_size;
209 int _dnd_security;209 int _dnd_delta;
210 int _enter_y;210 int _dnd_security;
211211 int _enter_y;
212 nux::BaseTexture* _icon_bkg_texture;212
213 nux::BaseTexture* _icon_shine_texture;213 nux::BaseTexture* _icon_bkg_texture;
214 nux::BaseTexture* _icon_outline_texture;214 nux::BaseTexture* _icon_shine_texture;
215 nux::BaseTexture* _icon_glow_texture;215 nux::BaseTexture* _icon_outline_texture;
216 nux::BaseTexture* _icon_2indicator;216 nux::BaseTexture* _icon_glow_texture;
217 nux::BaseTexture* _icon_3indicator;217 nux::BaseTexture* _icon_2indicator;
218 nux::BaseTexture* _icon_4indicator;218 nux::BaseTexture* _icon_3indicator;
219219 nux::BaseTexture* _icon_4indicator;
220 guint _anim_handle;220
221 guint _autohide_handle;221 guint _anim_handle;
222222 guint _autohide_handle;
223 nux::Matrix4 _view_matrix;223
224 nux::Matrix4 _projection_matrix;224 nux::Matrix4 _view_matrix;
225 nux::Point2 _mouse_position;225 nux::Matrix4 _projection_matrix;
226 nux::IntrusiveSP<nux::IOpenGLShaderProgram> _shader_program_uv_persp_correction;226 nux::Point2 _mouse_position;
227 nux::IntrusiveSP<nux::IOpenGLAsmShaderProgram> _AsmShaderProg;227 nux::IntrusiveSP<nux::IOpenGLShaderProgram> _shader_program_uv_persp_correction;
228 nux::BaseTexture* m_RunningIndicator;228 nux::IntrusiveSP<nux::IOpenGLAsmShaderProgram> _AsmShaderProg;
229 nux::BaseTexture* m_ActiveIndicator;229 nux::BaseTexture* m_RunningIndicator;
230 nux::AbstractPaintLayer* m_BackgroundLayer;230 nux::BaseTexture* m_ActiveIndicator;
231 nux::BaseWindow* _parent;231 nux::AbstractPaintLayer* m_BackgroundLayer;
232 nux::View* _autohide_trigger;232 nux::BaseWindow* _parent;
233 nux::Geometry _last_shelf_area;233 nux::View* _autohide_trigger;
234 LauncherModel* _model;234 nux::Geometry _last_shelf_area;
235 235 LauncherModel* _model;
236 /* event times */236
237 struct timespec _enter_time;237 /* event times */
238 struct timespec _exit_time;238 struct timespec _enter_time;
239 struct timespec _drag_end_time;239 struct timespec _exit_time;
240 struct timespec _autohide_time;240 struct timespec _drag_end_time;
241};241 struct timespec _autohide_time;
242242};
243#endif // LAUNCHER_H243
244244#endif // LAUNCHER_H
245245
246
247=======
248/*
249 * Copyright (C) 2010 Canonical Ltd
250 *
251 * This program is free software: you can redistribute it and/or modify
252 * it under the terms of the GNU General Public License version 3 as
253 * published by the Free Software Foundation.
254 *
255 * This program is distributed in the hope that it will be useful,
256 * but WITHOUT ANY WARRANTY; without even the implied warranty of
257 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
258 * GNU General Public License for more details.
259 *
260 * You should have received a copy of the GNU General Public License
261 * along with this program. If not, see <http://www.gnu.org/licenses/>.
262 *
263 * Authored by: Jason Smith <jason.smith@canonical.com>
264 * Authored by: Jay Taoko <jay.taoko@canonical.com>
265 */
266
267#ifndef LAUNCHER_H
268#define LAUNCHER_H
269
270#include <sys/time.h>
271
272#include <Nux/View.h>
273#include <Nux/BaseWindow.h>
274#include "Introspectable.h"
275#include "LauncherIcon.h"
276#include "NuxGraphics/IOpenGLAsmShader.h"
277#include "Nux/TimerProc.h"
278
279class LauncherModel;
280class QuicklistView;
281
282class Launcher : public Introspectable, public nux::View
283{
284public:
285 Launcher(nux::BaseWindow *parent, NUX_FILE_LINE_PROTO);
286 ~Launcher();
287
288 virtual long ProcessEvent(nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
289 virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
290 virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
291 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
292
293 LauncherIcon* GetActiveTooltipIcon() {return m_ActiveTooltipIcon;}
294 LauncherIcon* GetActiveMenuIcon() {return m_ActiveMenuIcon;}
295
296 bool TooltipNotify(LauncherIcon* Icon);
297 bool MenuNotify(LauncherIcon* Icon);
298
299 void SetIconSize(int tile_size, int icon_size);
300 void NotifyMenuTermination(LauncherIcon* Icon);
301
302 void SetModel (LauncherModel *model);
303
304 void SetFloating (bool floating);
305
306 void SetAutohide (bool autohide, nux::View *show_trigger);
307 bool AutohideEnabled ();
308
309 virtual void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
310 virtual void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
311 virtual void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
312 virtual void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
313 virtual void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
314 virtual void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
315 virtual void RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags);
316
317 //! Called by LauncherIcon to signal that a Quicklist is becoming active.
318 void SetActiveQuicklist (QuicklistView *quicklist);
319 //! Get the active qicklist
320 QuicklistView *GetActiveQuicklist ();
321 //! Called by LauncherIcon to signal that a Quicklist is becoming unactive.
322 void CancelActiveQuicklist (QuicklistView *quicklist);
323
324protected:
325 // Introspectable methods
326 const gchar* GetName ();
327 void AddProperties (GVariantBuilder *builder);
328
329private:
330 typedef enum
331 {
332 LAUNCHER_FOLDED,
333 LAUNCHER_UNFOLDED
334 } LauncherState;
335
336 typedef enum
337 {
338 ACTION_NONE,
339 ACTION_DRAG_LAUNCHER,
340 ACTION_DRAG_ICON,
341 } LauncherActionState;
342
343 typedef struct
344 {
345 LauncherIcon *icon;
346 nux::Point3 center;
347 float folding_rads;
348 float alpha;
349 float backlight_intensity;
350 float glow_intensity;
351 float shimmer_progress;
352 bool running_arrow;
353 bool active_arrow;
354 bool skip;
355 int window_indicators;
356 } RenderArg;
357
358 static gboolean AnimationTimeout (gpointer data);
359 static gboolean OnAutohideTimeout (gpointer data);
360 static gboolean StrutHack (gpointer data);
361
362 void OnTriggerMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags);
363 void OnTriggerMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags);
364
365 bool IconNeedsAnimation (LauncherIcon *icon, struct timespec current);
366 bool AnimationInProgress ();
367 void SetTimeStruct (struct timespec *timer, struct timespec *sister = 0, int sister_relation = 0);
368
369 void EnsureAnimation ();
370 void SetupAutohideTimer ();
371
372 float DnDExitProgress ();
373 float GetHoverProgress ();
374 float AutohideProgress ();
375 float IconPresentProgress (LauncherIcon *icon, struct timespec current);
376 float IconUrgentProgress (LauncherIcon *icon, struct timespec current);
377 float IconShimmerProgress (LauncherIcon *icon, struct timespec current);
378 float IconUrgentPulseValue (LauncherIcon *icon, struct timespec current);
379 float IconStartingPulseValue (LauncherIcon *icon, struct timespec current);
380 float IconBackgroundIntensity (LauncherIcon *icon, struct timespec current);
381
382 void SetHover ();
383 void UnsetHover ();
384 void SetHidden (bool hidden);
385
386 void SetDndDelta (float x, float y, nux::Geometry geo, struct timespec current);
387 int DragLimiter (int x);
388
389 void SetupRenderArg (LauncherIcon *icon, struct timespec current, RenderArg &arg);
390 void RenderArgs (std::list<Launcher::RenderArg> &launcher_args,
391 std::list<Launcher::RenderArg> &shelf_args,
392 nux::Geometry &box_geo, nux::Geometry &shelf_geo);
393
394 void DrawRenderArg (nux::GraphicsEngine& GfxContext, RenderArg arg, nux::Geometry geo);
395
396 void OnIconAdded (void *icon_pointer);
397 void OnIconRemoved (void *icon_pointer);
398 void OnOrderChanged ();
399
400 void OnIconNeedsRedraw (void *icon);
401
402 void RenderIcon (nux::GraphicsEngine& GfxContext,
403 RenderArg arg,
404 nux::BaseTexture *icon,
405 nux::Color bkg_color,
406 float alpha,
407 nux::Vector4 xform_coords[],
408 nux::Geometry geo,
409 bool render_indicators);
410
411 void SetIconXForm (LauncherIcon *icon, nux::Matrix4 ViewProjectionMatrix, nux::Geometry geo,
412 float x, float y, float w, float h, float z, std::string name);
413 void UpdateIconXForm (std::list<Launcher::RenderArg> args);
414
415 LauncherIcon* MouseIconIntersection (int x, int y);
416 void EventLogic ();
417 void MouseDownLogic (int x, int y, unsigned long button_flags, unsigned long key_flags);
418 void MouseUpLogic (int x, int y, unsigned long button_flags, unsigned long key_flags);
419
420 virtual void PreLayoutManagement();
421 virtual long PostLayoutManagement(long LayoutResult);
422 virtual void PositionChildLayout(float offsetX, float offsetY);
423
424
425 nux::HLayout* m_Layout;
426 int m_ContentOffsetY;
427
428 LauncherIcon* m_ActiveTooltipIcon;
429 LauncherIcon* m_ActiveMenuIcon;
430
431
432 QuicklistView* _active_quicklist;
433
434 bool _hovered;
435 bool _floating;
436 bool _autohide;
437 bool _hidden;
438 bool _mouse_inside_launcher;
439
440 float _folded_angle;
441 float _neg_folded_angle;
442 float _folded_z_distance;
443 float _launcher_top_y;
444 float _launcher_bottom_y;
445
446 LauncherState _launcher_state;
447 LauncherActionState _launcher_action_state;
448 LauncherIcon* _icon_under_mouse;
449 LauncherIcon* _icon_mouse_down;
450
451 int _space_between_icons;
452 int _icon_size;
453 int _icon_image_size;
454 int _icon_image_size_delta;
455 int _icon_glow_size;
456 int _dnd_delta;
457 int _dnd_security;
458 int _enter_y;
459
460 nux::BaseTexture* _icon_bkg_texture;
461 nux::BaseTexture* _icon_shine_texture;
462 nux::BaseTexture* _icon_outline_texture;
463 nux::BaseTexture* _icon_glow_texture;
464 nux::BaseTexture* _icon_2indicator;
465 nux::BaseTexture* _icon_3indicator;
466 nux::BaseTexture* _icon_4indicator;
467
468 guint _anim_handle;
469 guint _autohide_handle;
470
471 nux::Matrix4 _view_matrix;
472 nux::Matrix4 _projection_matrix;
473 nux::Point2 _mouse_position;
474 nux::IntrusiveSP<nux::IOpenGLShaderProgram> _shader_program_uv_persp_correction;
475 nux::IntrusiveSP<nux::IOpenGLAsmShaderProgram> _AsmShaderProg;
476 nux::BaseTexture* m_RunningIndicator;
477 nux::BaseTexture* m_ActiveIndicator;
478 nux::AbstractPaintLayer* m_BackgroundLayer;
479 nux::BaseWindow* _parent;
480 nux::View* _autohide_trigger;
481 nux::Geometry _last_shelf_area;
482 LauncherModel* _model;
483
484 /* event times */
485 struct timespec _enter_time;
486 struct timespec _exit_time;
487 struct timespec _drag_end_time;
488 struct timespec _autohide_time;
489};
490
491#endif // LAUNCHER_H
492
493
494>>>>>>> MERGE-SOURCE
246495
=== modified file 'src/LauncherController.cpp'
--- src/LauncherController.cpp 2010-11-30 04:42:47 +0000
+++ src/LauncherController.cpp 2010-12-02 15:23:26 +0000
@@ -72,8 +72,11 @@
72 }72 }
73 }73 }
74 74
75 owner->Present (2, 600);75 if (owner)
76 owner->UpdateQuirkTimeDelayed (300, LAUNCHER_ICON_QUIRK_SHIMMER);76 {
77 owner->Present (2, 600);
78 owner->UpdateQuirkTimeDelayed (300, LAUNCHER_ICON_QUIRK_SHIMMER);
79 }
77}80}
7881
79void82void