~canonical-dx-team/unity/unity.fix-ql-losing-focus

« back to all changes in this revision

Viewing changes to src/Launcher.cpp

  • Committer: Michael Terry
  • Date: 2010-12-17 14:07:11 UTC
  • mfrom: (724 unity)
  • mto: This revision was merged to the branch mainline in revision 743.
  • Revision ID: mike@mterry.name-20101217140711-qlij3bxdjuq1xoph
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
184
184
 
185
185
    m_Layout = new nux::HLayout(NUX_TRACKER_LOCATION);
186
186
 
187
 
    OnMouseDown.connect(sigc::mem_fun(this, &Launcher::RecvMouseDown));
188
 
    OnMouseUp.connect(sigc::mem_fun(this, &Launcher::RecvMouseUp));
189
 
    OnMouseDrag.connect(sigc::mem_fun(this, &Launcher::RecvMouseDrag));
190
 
    OnMouseEnter.connect(sigc::mem_fun(this, &Launcher::RecvMouseEnter));
191
 
    OnMouseLeave.connect(sigc::mem_fun(this, &Launcher::RecvMouseLeave));
192
 
    OnMouseMove.connect(sigc::mem_fun(this, &Launcher::RecvMouseMove));
193
 
    OnMouseWheel.connect(sigc::mem_fun(this, &Launcher::RecvMouseWheel));
 
187
    OnMouseDown.connect  (sigc::mem_fun (this, &Launcher::RecvMouseDown));
 
188
    OnMouseUp.connect    (sigc::mem_fun (this, &Launcher::RecvMouseUp));
 
189
    OnMouseDrag.connect  (sigc::mem_fun (this, &Launcher::RecvMouseDrag));
 
190
    OnMouseEnter.connect (sigc::mem_fun (this, &Launcher::RecvMouseEnter));
 
191
    OnMouseLeave.connect (sigc::mem_fun (this, &Launcher::RecvMouseLeave));
 
192
    OnMouseMove.connect  (sigc::mem_fun (this, &Launcher::RecvMouseMove));
 
193
    OnMouseWheel.connect (sigc::mem_fun (this, &Launcher::RecvMouseWheel));
194
194
 
195
195
    QuicklistManager::Default ()->quicklist_opened.connect (sigc::mem_fun(this, &Launcher::RecvQuicklistOpened));
196
196
    QuicklistManager::Default ()->quicklist_closed.connect (sigc::mem_fun(this, &Launcher::RecvQuicklistClosed));
 
197
    
 
198
    PluginAdapter::Default ()->window_maximized.connect   (sigc::mem_fun (this, &Launcher::OnWindowMaybeIntellihide));
 
199
    PluginAdapter::Default ()->window_restored.connect    (sigc::mem_fun (this, &Launcher::OnWindowMaybeIntellihide));
 
200
    PluginAdapter::Default ()->window_unminimized.connect (sigc::mem_fun (this, &Launcher::OnWindowMaybeIntellihide));
 
201
    PluginAdapter::Default ()->window_mapped.connect      (sigc::mem_fun (this, &Launcher::OnWindowMaybeIntellihide));
 
202
    PluginAdapter::Default ()->window_unmapped.connect    (sigc::mem_fun (this, &Launcher::OnWindowMaybeIntellihide));
 
203
    PluginAdapter::Default ()->window_shown.connect       (sigc::mem_fun (this, &Launcher::OnWindowMaybeIntellihide));
 
204
    PluginAdapter::Default ()->window_hidden.connect      (sigc::mem_fun (this, &Launcher::OnWindowMaybeIntellihide));
 
205
    PluginAdapter::Default ()->window_resized.connect     (sigc::mem_fun (this, &Launcher::OnWindowMaybeIntellihide));
 
206
    PluginAdapter::Default ()->window_moved.connect       (sigc::mem_fun (this, &Launcher::OnWindowMaybeIntellihide));
197
207
 
198
208
    m_ActiveTooltipIcon = NULL;
199
209
    m_ActiveMenuIcon = NULL;
236
246
    _icon_under_mouse       = NULL;
237
247
    _icon_mouse_down        = NULL;
238
248
    _drag_icon              = NULL;
239
 
    _drag_icon_under_mouse  = NULL;
240
249
    _icon_image_size        = 48;
241
250
    _icon_glow_size         = 62;
242
251
    _icon_image_size_delta  = 6;
246
255
    _icon_outline_texture   = nux::CreateTextureFromFile (PKGDATADIR"/round_outline_54x54.png");
247
256
    _icon_shine_texture     = nux::CreateTextureFromFile (PKGDATADIR"/round_shine_54x54.png");
248
257
    _icon_glow_texture      = nux::CreateTextureFromFile (PKGDATADIR"/round_glow_62x62.png");
249
 
    _icon_2indicator        = nux::CreateTextureFromFile (PKGDATADIR"/2indicate_54x54.png");
250
 
    _icon_3indicator        = nux::CreateTextureFromFile (PKGDATADIR"/3indicate_54x54.png");
251
 
    _icon_4indicator        = nux::CreateTextureFromFile (PKGDATADIR"/4indicate_54x54.png");
 
258
    _progress_bar_trough    = nux::CreateTextureFromFile (PKGDATADIR"/progress_bar_trough.png");
 
259
    _progress_bar_fill      = nux::CreateTextureFromFile (PKGDATADIR"/progress_bar_fill.png");
252
260
 
253
261
    _enter_y                = 0;
254
262
    _dnd_security           = 15;
255
263
    _launcher_drag_delta    = 0;
256
264
    _dnd_delta_y            = 0;
257
265
    _dnd_delta_x            = 0;
258
 
    _anim_handle            = 0;
259
266
    _autohide_handle        = 0;
260
267
    _floating               = false;
261
268
    _hovered                = false;
275
282
    _drag_end_time.tv_nsec = 0;
276
283
    _drag_start_time.tv_sec = 0;
277
284
    _drag_start_time.tv_nsec = 0;
 
285
    _drag_threshold_time.tv_sec = 0;
 
286
    _drag_threshold_time.tv_nsec = 0;
278
287
    _autohide_time.tv_sec = 0;
279
288
    _autohide_time.tv_nsec = 0;
280
289
    
281
290
    _drag_window = NULL;
282
 
    _offscreen_rt_texture = nux::GetThreadGLDeviceFactory()->CreateSystemCapableDeviceTexture (2, 2, 1, nux::BITFMT_R8G8B8A8);
 
291
    _offscreen_drag_texture = nux::GetThreadGLDeviceFactory()->CreateSystemCapableDeviceTexture (2, 2, 1, nux::BITFMT_R8G8B8A8);
 
292
    _offscreen_progress_texture = nux::GetThreadGLDeviceFactory()->CreateSystemCapableDeviceTexture (2, 2, 1, nux::BITFMT_R8G8B8A8);
283
293
}
284
294
 
285
295
Launcher::~Launcher()
313
323
  g_variant_builder_add (builder, "{sv}", "mouse-inside-launcher", g_variant_new_boolean (_mouse_inside_launcher));
314
324
}
315
325
 
 
326
void Launcher::SetMousePosition (int x, int y)
 
327
{
 
328
    bool beyond_drag_threshold = MouseBeyondDragThreshold ();
 
329
    _mouse_position = nux::Point2 (x, y);
 
330
    
 
331
    if (beyond_drag_threshold != MouseBeyondDragThreshold ())
 
332
      SetTimeStruct (&_drag_threshold_time, &_drag_threshold_time, ANIM_DURATION_SHORT);
 
333
}
 
334
 
 
335
bool Launcher::MouseBeyondDragThreshold ()
 
336
{
 
337
    if (_launcher_action_state != ACTION_DRAG_ICON)
 
338
      return false;
 
339
    return _mouse_position.x > GetGeometry ().width + _icon_size / 2;
 
340
}
 
341
 
316
342
/* Render Layout Logic */
317
 
 
318
343
float Launcher::GetHoverProgress (struct timespec const &current)
319
344
{
320
345
    if (_hovered)
344
369
        return 1.0f - CLAMP ((float) (TimeDelta (&current, &_autohide_time)) / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
345
370
}
346
371
 
 
372
float Launcher::DragThresholdProgress (struct timespec const &current)
 
373
{
 
374
  if (MouseBeyondDragThreshold ())
 
375
    return 1.0f - CLAMP ((float) (TimeDelta (&current, &_drag_threshold_time)) / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
 
376
  else
 
377
    return CLAMP ((float) (TimeDelta (&current, &_drag_threshold_time)) / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
 
378
}
 
379
 
347
380
gboolean Launcher::AnimationTimeout (gpointer data)
348
381
{
349
382
    Launcher *self = (Launcher*) data;
350
 
 
351
383
    self->NeedRedraw ();
352
 
 
353
 
    if (self->AnimationInProgress ())
354
 
      return true;
355
 
 
356
 
    // zero out handle so we know we are done
357
 
    self->_anim_handle = 0;
358
384
    return false;
359
385
}
360
386
 
361
387
void Launcher::EnsureAnimation ()
362
388
{
363
 
    if (_anim_handle)
364
 
      return;
365
 
 
366
389
    NeedRedraw ();
367
 
 
368
 
    if (AnimationInProgress ())
369
 
        _anim_handle = g_timeout_add (1000 / 60 - 1, &Launcher::AnimationTimeout, this);
370
390
}
371
391
 
372
392
bool Launcher::IconNeedsAnimation (LauncherIcon *icon, struct timespec const &current)
399
419
    if (TimeDelta (&current, &time) < ANIM_DURATION)
400
420
        return true;
401
421
 
 
422
    time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_PROGRESS);
 
423
    if (TimeDelta (&current, &time) < ANIM_DURATION)
 
424
        return true;
402
425
 
403
426
    return false;
404
427
}
430
453
 
431
454
    if (TimeDelta (&current, &_autohide_time) < ANIM_DURATION_SHORT)
432
455
        return true;
 
456
        
 
457
    if (TimeDelta (&current, &_drag_threshold_time) < ANIM_DURATION_SHORT)
 
458
        return true;
433
459
 
434
460
    // animations happening on specific icons
435
461
    LauncherModel::iterator it;
606
632
    return result;
607
633
}
608
634
 
 
635
float Launcher::IconProgressBias (LauncherIcon *icon, struct timespec const &current)
 
636
{
 
637
    struct timespec icon_progress_time = icon->GetQuirkTime (LAUNCHER_ICON_QUIRK_PROGRESS);
 
638
    int ms = TimeDelta (&current, &icon_progress_time);
 
639
    float result = CLAMP ((float) ms / (float) ANIM_DURATION, 0.0f, 1.0f);
 
640
 
 
641
    if (icon->GetQuirk (LAUNCHER_ICON_QUIRK_PROGRESS))
 
642
        return -1.0f + result;
 
643
    else
 
644
        return result;
 
645
}
 
646
 
609
647
void Launcher::SetupRenderArg (LauncherIcon *icon, struct timespec const &current, RenderArg &arg)
610
648
{
611
649
    arg.icon            = icon;
614
652
    arg.active_arrow    = icon->GetQuirk (LAUNCHER_ICON_QUIRK_ACTIVE);
615
653
    arg.running_colored = icon->GetQuirk (LAUNCHER_ICON_QUIRK_URGENT);
616
654
    arg.active_colored  = false;
617
 
    arg.folding_rads    = 0.0f;
 
655
    arg.x_rotation      = 0.0f;
 
656
    arg.y_rotation      = 0.0f;
 
657
    arg.z_rotation      = 0.0f;
618
658
    arg.skip            = false;
619
 
 
 
659
    arg.stick_thingy    = false;
 
660
    arg.progress_bias   = IconProgressBias (icon, current);
 
661
    arg.progress        = CLAMP (icon->GetProgress (), 0.0f, 1.0f);
620
662
 
621
663
    // we dont need to show strays
622
664
    if (!icon->GetQuirk (LAUNCHER_ICON_QUIRK_RUNNING))
659
701
        center.z = 300.0f * (1.0f - size_modifier);
660
702
    }
661
703
 
662
 
    if (size_modifier <= 0.0f || icon == _drag_icon)
 
704
    if (icon == _drag_icon)
 
705
    {
 
706
        if (MouseBeyondDragThreshold ())
 
707
          arg.stick_thingy = true;
 
708
        
 
709
        if (_launcher_action_state == ACTION_DRAG_ICON || (_drag_window && _drag_window->Animating ()))
 
710
          arg.skip = true;
 
711
        size_modifier *= DragThresholdProgress (current);
 
712
    }
 
713
    
 
714
    if (size_modifier <= 0.0f)
663
715
        arg.skip = true;
664
 
 
665
716
    
666
717
    // goes for 0.0f when fully unfolded, to 1.0f folded
667
718
    float folding_progress = CLAMP ((center.y + _icon_size - folding_threshold) / (float) _icon_size, 0.0f, 1.0f);
676
727
 
677
728
    // icon is crossing threshold, start folding
678
729
    center.z += folded_z_distance * folding_progress;
679
 
    arg.folding_rads = animation_neg_rads * folding_progress;
 
730
    arg.x_rotation = animation_neg_rads * folding_progress;
680
731
 
681
732
    float spacing_overlap = CLAMP ((float) (center.y + (2.0f * half_size * size_modifier) + (_space_between_icons * size_modifier) - folding_threshold) / (float) _icon_size, 0.0f, 1.0f);
682
733
    float spacing = (_space_between_icons * (1.0f - spacing_overlap) + folded_spacing * spacing_overlap) * size_modifier;
695
746
    
696
747
    icon->SetCenter (nux::Point3 (roundf (center.x), roundf (center.y), roundf (center.z)));
697
748
    
 
749
    if (icon == _drag_icon && _drag_window && _drag_window->Animating ())
 
750
      _drag_window->SetAnimationTarget ((int) center.x, (int) center.y + _parent->GetGeometry ().y);
 
751
    
698
752
    center.y += (half_size * size_modifier) + spacing;   // move to end
699
753
}
700
754
 
894
948
  {
895
949
    CompWindow *window = *it;
896
950
 
897
 
    if (window->type () != CompWindowTypeNormalMask || window->invisible ())
 
951
    if (window->type () != CompWindowTypeNormalMask || !window->isMapped () || !window->isViewable ())
898
952
      continue;
899
953
 
900
954
    if (CompRegion (window->inputRect ()).intersects (CompRect (geo.x, geo.y, geo.width, geo.height)))
910
964
}
911
965
 
912
966
void
913
 
Launcher::OnWindowMoved (CompWindow *window)
914
 
{
915
 
  if (_autohide)
916
 
    CheckWindowOverLauncher ();
917
 
}
918
 
 
919
 
void
920
 
Launcher::OnWindowResized (CompWindow *window)
921
 
{
922
 
  if (_autohide)
923
 
    CheckWindowOverLauncher ();
924
 
}
925
 
 
926
 
void
927
 
Launcher::OnWindowAppear (CompWindow *window)
928
 
{
929
 
  if (_autohide)
930
 
    CheckWindowOverLauncher ();
931
 
}
932
 
void
933
 
Launcher::OnWindowDisappear (CompWindow *window)
 
967
Launcher::OnWindowMaybeIntellihide (CompWindow *window)
934
968
{
935
969
  if (_autohide)
936
970
    CheckWindowOverLauncher ();
1004
1038
    EnsureAnimation ();
1005
1039
}
1006
1040
 
 
1041
void
 
1042
Launcher::EnsureHoverState ()
 
1043
{
 
1044
  if (_mouse_inside_launcher || QuicklistManager::Default ()->Current() || _launcher_action_state != ACTION_NONE)
 
1045
  {
 
1046
    SetHover ();
 
1047
  }
 
1048
  else
 
1049
  {
 
1050
    UnsetHover ();
 
1051
  }
 
1052
}
 
1053
 
1007
1054
void Launcher::SetHover ()
1008
1055
{
1009
1056
    if (_hovered)
1044
1091
    EnsureAnimation();
1045
1092
 
1046
1093
    // How to free these properly?
1047
 
    icon->_xform_coords["HitArea"] = new nux::Vector4[4];
1048
 
    icon->_xform_coords["Image"]   = new nux::Vector4[4];
1049
 
    icon->_xform_coords["Tile"]    = new nux::Vector4[4];
1050
 
    icon->_xform_coords["Glow"]    = new nux::Vector4[4];
 
1094
    icon->_xform_coords["HitArea"]      = new nux::Vector4[4];
 
1095
    icon->_xform_coords["Image"]        = new nux::Vector4[4];
 
1096
    icon->_xform_coords["Tile"]         = new nux::Vector4[4];
 
1097
    icon->_xform_coords["Glow"]         = new nux::Vector4[4];
1051
1098
 
1052
1099
    // needs to be disconnected
1053
1100
    icon->needs_redraw.connect (sigc::mem_fun(this, &Launcher::OnIconNeedsRedraw));
1169
1216
 
1170
1217
void Launcher::RenderIcon(nux::GraphicsEngine& GfxContext,
1171
1218
                          RenderArg const &arg,
1172
 
                          nux::BaseTexture *icon,
 
1219
                          nux::IntrusiveSP<nux::IOpenGLBaseTexture> icon,
1173
1220
                          nux::Color bkg_color,
1174
1221
                          float alpha,
1175
 
                          nux::Vector4 xform_coords[],
1176
 
                          nux::Geometry geo)
 
1222
                          nux::Vector4 xform_coords[])
1177
1223
{
1178
 
  if (icon == NULL || icon->IsNull ())
 
1224
  if (icon == NULL)
1179
1225
    return;
1180
1226
 
1181
1227
  nux::Matrix4 ObjectMatrix;
1183
1229
  nux::Matrix4 ProjectionMatrix;
1184
1230
  nux::Matrix4 ViewProjectionMatrix;
1185
1231
 
1186
 
  if(nux::Abs (arg.folding_rads) < 0.01f)
1187
 
    icon->GetDeviceTexture()->SetFiltering(GL_NEAREST, GL_NEAREST);
 
1232
  if(nux::Abs (arg.x_rotation) < 0.01f)
 
1233
    icon->SetFiltering(GL_NEAREST, GL_NEAREST);
1188
1234
  else
1189
 
    icon->GetDeviceTexture()->SetFiltering(GL_LINEAR, GL_LINEAR);
 
1235
    icon->SetFiltering(GL_LINEAR, GL_LINEAR);
1190
1236
 
1191
1237
  nux::Vector4 v0;
1192
1238
  nux::Vector4 v1;
1213
1259
  float s0, t0, s1, t1, s2, t2, s3, t3;
1214
1260
  nux::Color color = nux::Color::White;
1215
1261
 
1216
 
  if (icon->Type ().IsDerivedFromType(nux::TextureRectangle::StaticObjectType))
 
1262
  if (icon->GetResourceType () == nux::RTTEXTURERECTANGLE)
1217
1263
  {
1218
1264
    s0 = 0.0f;                                  t0 = 0.0f;
1219
1265
    s1 = 0.0f;                                  t1 = icon->GetHeight();
1335
1381
 
1336
1382
  GfxContext.GetRenderStates ().SetColorMask (true, true, true, true);
1337
1383
 
 
1384
  /* draw tile */
1338
1385
  if (arg.backlight_intensity < 1.0f)
1339
1386
  {
1340
1387
    RenderIcon(GfxContext,
1341
1388
               arg,
1342
 
               _icon_outline_texture,
 
1389
               _icon_outline_texture->GetDeviceTexture (),
1343
1390
               nux::Color(0xAAFFFFFF),
1344
1391
               1.0f - arg.backlight_intensity,
1345
 
               arg.icon->_xform_coords["Tile"],
1346
 
               geo);
 
1392
               arg.icon->_xform_coords["Tile"]);
1347
1393
  }
1348
1394
 
1349
1395
  if (arg.backlight_intensity > 0.0f)
1350
1396
  {
1351
1397
    RenderIcon(GfxContext,
1352
1398
               arg,
1353
 
               _icon_bkg_texture,
 
1399
               _icon_bkg_texture->GetDeviceTexture (),
1354
1400
               arg.icon->BackgroundColor (),
1355
1401
               arg.backlight_intensity,
1356
 
               arg.icon->_xform_coords["Tile"],
1357
 
               geo);
 
1402
               arg.icon->_xform_coords["Tile"]);
1358
1403
  }
 
1404
  /* end tile draw */
1359
1405
 
1360
1406
  GfxContext.GetRenderStates ().SetSeparateBlend (true,
1361
1407
                                                GL_SRC_ALPHA,
1364
1410
                                                GL_ONE);
1365
1411
  GfxContext.GetRenderStates ().SetColorMask (true, true, true, true);
1366
1412
 
 
1413
  /* draw icon */
1367
1414
  RenderIcon (GfxContext,
1368
1415
              arg,
1369
 
              arg.icon->TextureForSize (_icon_image_size),
 
1416
              arg.icon->TextureForSize (_icon_image_size)->GetDeviceTexture (),
1370
1417
              nux::Color::White,
1371
1418
              arg.alpha,
1372
 
              arg.icon->_xform_coords["Image"],
1373
 
              geo);
 
1419
              arg.icon->_xform_coords["Image"]);
1374
1420
 
 
1421
  /* draw overlay shine */
1375
1422
  if (arg.backlight_intensity > 0.0f)
1376
1423
  {
1377
1424
    RenderIcon(GfxContext,
1378
1425
               arg,
1379
 
               _icon_shine_texture,
 
1426
               _icon_shine_texture->GetDeviceTexture (),
1380
1427
               nux::Color::White,
1381
1428
               arg.backlight_intensity,
1382
 
               arg.icon->_xform_coords["Tile"],
1383
 
               geo);
1384
 
  }
1385
 
 
1386
 
  if (false)
1387
 
  {
1388
 
    switch (arg.window_indicators)
1389
 
    {
1390
 
      case 2:
1391
 
        RenderIcon(GfxContext,
1392
 
                   arg,
1393
 
                   _icon_2indicator,
1394
 
                   nux::Color::White,
1395
 
                   1.0f,
1396
 
                   arg.icon->_xform_coords["Tile"],
1397
 
                   geo);
1398
 
        break;
1399
 
      case 3:
1400
 
        RenderIcon(GfxContext,
1401
 
                    arg,
1402
 
                    _icon_3indicator,
1403
 
                    nux::Color::White,
1404
 
                    1.0f,
1405
 
                    arg.icon->_xform_coords["Tile"],
1406
 
                    geo);
1407
 
        break;
1408
 
      case 4:
1409
 
        RenderIcon(GfxContext,
1410
 
                   arg,
1411
 
                   _icon_4indicator,
1412
 
                   nux::Color::White,
1413
 
                   1.0f,
1414
 
                   arg.icon->_xform_coords["Tile"],
1415
 
                   geo);
1416
 
        break;
1417
 
    }
1418
 
  }
1419
 
 
 
1429
               arg.icon->_xform_coords["Tile"]);
 
1430
  }
 
1431
 
 
1432
  /* draw glow */
1420
1433
  if (arg.glow_intensity > 0.0f)
1421
1434
  {
1422
1435
    RenderIcon(GfxContext,
1423
1436
               arg,
1424
 
               _icon_glow_texture,
 
1437
               _icon_glow_texture->GetDeviceTexture (),
1425
1438
               arg.icon->GlowColor (),
1426
1439
               arg.glow_intensity,
1427
 
               arg.icon->_xform_coords["Glow"],
1428
 
               geo);
 
1440
               arg.icon->_xform_coords["Glow"]);
1429
1441
  }
1430
 
 
 
1442
  
 
1443
  /* draw shimmer */
1431
1444
  if (arg.shimmer_progress > 0.0f && arg.shimmer_progress < 1.0f)
1432
1445
  {
1433
1446
    nux::Geometry base = GetGeometry ();
1442
1455
 
1443
1456
    RenderIcon(GfxContext,
1444
1457
               arg,
1445
 
               _icon_glow_texture,
 
1458
               _icon_glow_texture->GetDeviceTexture (),
1446
1459
               arg.icon->GlowColor (),
1447
1460
               fade_out,
1448
 
               arg.icon->_xform_coords["Glow"],
1449
 
               geo);
 
1461
               arg.icon->_xform_coords["Glow"]);
1450
1462
 
1451
1463
    GfxContext.PopClippingRectangle();
1452
1464
  }
 
1465
  
 
1466
  /* draw progress bar */
 
1467
  if (arg.progress_bias > -1.0f && arg.progress_bias < 1.0f)
 
1468
  {
 
1469
    if (_offscreen_progress_texture->GetWidth () != _icon_size || _offscreen_progress_texture->GetHeight () != _icon_size)
 
1470
      _offscreen_progress_texture = nux::GetThreadGLDeviceFactory()->CreateSystemCapableDeviceTexture (_icon_size, _icon_size, 1, nux::BITFMT_R8G8B8A8);
 
1471
    RenderProgressToTexture (GfxContext, _offscreen_progress_texture, arg.progress, arg.progress_bias);
 
1472
    
 
1473
    RenderIcon(GfxContext,
 
1474
               arg,
 
1475
               _offscreen_progress_texture,
 
1476
               nux::Color::White,
 
1477
               1.0f,
 
1478
               arg.icon->_xform_coords["Tile"]);
 
1479
  }
1453
1480
 
 
1481
  /* draw indicators */
1454
1482
  RenderIndicators (GfxContext,
1455
1483
                    arg,
1456
1484
                    arg.running_arrow ? arg.window_indicators : 0,
1466
1494
    std::list<Launcher::RenderArg>::reverse_iterator rev_it;
1467
1495
    std::list<Launcher::RenderArg>::iterator it;
1468
1496
 
 
1497
    // rely on the compiz event loop to come back to us in a nice throttling
 
1498
    if (AnimationInProgress ())   
 
1499
      g_timeout_add (0, &Launcher::AnimationTimeout, this);
 
1500
 
1469
1501
    nux::ROPConfig ROP;
1470
1502
    ROP.Blend = false;
1471
1503
    ROP.SrcBlend = GL_SRC_ALPHA;
1475
1507
 
1476
1508
    if (_drag_icon && _render_drag_window)
1477
1509
    {
1478
 
      RenderArg arg;
1479
 
      struct timespec current;
1480
 
      clock_gettime (CLOCK_MONOTONIC, &current);
1481
 
      
1482
 
      SetupRenderArg (_drag_icon, current, arg);
1483
 
      arg.render_center = nux::Point3 (_icon_size / 2.0f, _icon_size / 2.0f, 0.0f);
1484
 
      arg.logical_center = arg.render_center;
1485
 
      arg.folding_rads = 0.0f;
1486
 
      arg.running_arrow = false;
1487
 
      arg.active_arrow = false;
1488
 
      arg.skip = false;
1489
 
      arg.window_indicators = 0;
1490
 
      arg.alpha = 1.0f;
1491
 
 
1492
 
      std::list<Launcher::RenderArg> drag_args;
1493
 
      drag_args.push_front (arg);
1494
 
      UpdateIconXForm (drag_args);
1495
 
      
1496
 
      SetOffscreenRenderTarget ();
1497
 
      DrawRenderArg (nux::GetGraphicsEngine (), arg, nux::Geometry (0, 0, _icon_size, _icon_size));
1498
 
      RestoreSystemRenderTarget ();
1499
 
      
 
1510
      RenderIconToTexture (GfxContext, _drag_icon, _offscreen_drag_texture);
1500
1511
      _drag_window->ShowWindow (true);
1501
1512
      nux::GetWindowCompositor ().SetAlwaysOnFrontWindow (_drag_window);
1502
1513
      
1524
1535
    /* draw launcher */
1525
1536
    for (rev_it = args.rbegin (); rev_it != args.rend (); rev_it++)
1526
1537
    {
1527
 
      if ((*rev_it).folding_rads >= 0.0f || (*rev_it).skip)
 
1538
      if ((*rev_it).stick_thingy)
 
1539
        gPainter.Paint2DQuadColor (GfxContext, 
 
1540
                                   nux::Geometry (bkg_box.x, (*rev_it).render_center.y - 3, bkg_box.width, 2), 
 
1541
                                   nux::Color(0xAAFFFFFF));
 
1542
      
 
1543
      if ((*rev_it).x_rotation >= 0.0f || (*rev_it).skip)
1528
1544
        continue;
1529
1545
 
1530
1546
      DrawRenderArg (GfxContext, *rev_it, bkg_box);
1532
1548
 
1533
1549
    for (it = args.begin(); it != args.end(); it++)
1534
1550
    {
1535
 
      if ((*it).folding_rads < 0.0f || (*it).skip)
 
1551
      if ((*it).stick_thingy)
 
1552
        gPainter.Paint2DQuadColor (GfxContext, 
 
1553
                                   nux::Geometry (bkg_box.x, (*it).render_center.y - 3, bkg_box.width, 2), 
 
1554
                                   nux::Color(0xAAFFFFFF));
 
1555
                                   
 
1556
      if ((*it).x_rotation < 0.0f || (*it).skip)
1536
1557
        continue;
1537
1558
 
1538
1559
      DrawRenderArg (GfxContext, *it, bkg_box);
1570
1591
{
1571
1592
  View::PostLayoutManagement(LayoutResult);
1572
1593
 
1573
 
  _mouse_position = nux::Point2 (0, 0);
 
1594
  SetMousePosition (0, 0);
1574
1595
 
1575
1596
  return nux::eCompliantHeight | nux::eCompliantWidth;
1576
1597
}
1579
1600
{
1580
1601
}
1581
1602
 
1582
 
bool Launcher::TooltipNotify(LauncherIcon* Icon)
1583
 
{
1584
 
    if(GetActiveMenuIcon())
1585
 
        return false;
1586
 
    return true;
1587
 
}
1588
 
 
1589
 
bool Launcher::MenuNotify(LauncherIcon* Icon)
1590
 
{
1591
 
 
1592
 
 
1593
 
    return true;
1594
 
}
1595
 
 
1596
 
void Launcher::NotifyMenuTermination(LauncherIcon* Icon)
1597
 
{
 
1603
void Launcher::OnDragWindowAnimCompleted ()
 
1604
{
 
1605
  if (_drag_window)
 
1606
    _drag_window->ShowWindow (false);
 
1607
  
 
1608
  EnsureAnimation ();
1598
1609
}
1599
1610
 
1600
1611
void Launcher::StartIconDrag (LauncherIcon *icon)
1611
1622
    _drag_window = NULL;
1612
1623
  }
1613
1624
  
1614
 
  _offscreen_rt_texture = nux::GetThreadGLDeviceFactory()->CreateSystemCapableDeviceTexture (_icon_size, _icon_size, 1, nux::BITFMT_R8G8B8A8);
1615
 
  _drag_window = new LauncherDragWindow (_offscreen_rt_texture);
 
1625
  _offscreen_drag_texture = nux::GetThreadGLDeviceFactory()->CreateSystemCapableDeviceTexture (_icon_size, _icon_size, 1, nux::BITFMT_R8G8B8A8);
 
1626
  _drag_window = new LauncherDragWindow (_offscreen_drag_texture);
1616
1627
  _drag_window->SinkReference ();
1617
1628
  
1618
1629
  _render_drag_window = true;
1622
1633
{
1623
1634
  if (_drag_window)
1624
1635
  {
1625
 
    _drag_window->ShowWindow (false);
1626
 
    _drag_window->UnReference ();
1627
 
    _drag_window = NULL;
 
1636
    _drag_window->SetAnimationTarget ((int) (_drag_icon->GetCenter ().x), (int) (_drag_icon->GetCenter ().y));
 
1637
    _drag_window->StartAnimation ();
 
1638
    _drag_window->anim_completed.connect (sigc::mem_fun (this, &Launcher::OnDragWindowAnimCompleted));
1628
1639
  }
1629
1640
  
1630
 
  _drag_icon_under_mouse = NULL;
1631
 
  _drag_icon = NULL;
 
1641
  if (MouseBeyondDragThreshold ())
 
1642
    SetTimeStruct (&_drag_threshold_time, &_drag_threshold_time, ANIM_DURATION_SHORT);
 
1643
  
1632
1644
  _render_drag_window = false;
1633
1645
}
1634
1646
 
1641
1653
    
1642
1654
    LauncherIcon *hovered_icon = MouseIconIntersection ((int) (GetGeometry ().x / 2.0f), y);
1643
1655
    
 
1656
    struct timespec current;
 
1657
    clock_gettime (CLOCK_MONOTONIC, &current);
1644
1658
    if (_drag_icon && hovered_icon && _drag_icon != hovered_icon)
1645
 
      request_reorder.emit (_drag_icon, hovered_icon);
 
1659
    {
 
1660
      float progress = DragThresholdProgress (current);
 
1661
      
 
1662
      if (progress >= 1.0f)
 
1663
        request_reorder_smart.emit (_drag_icon, hovered_icon, true);
 
1664
      else if (progress == 0.0f)
 
1665
        request_reorder_before.emit (_drag_icon, hovered_icon, false);
 
1666
    }
1646
1667
  }
1647
1668
}
1648
1669
 
1649
1670
void Launcher::RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags)
1650
1671
{
1651
 
  _mouse_position = nux::Point2 (x, y);
 
1672
  SetMousePosition (x, y);
1652
1673
 
1653
1674
  MouseDownLogic (x, y, button_flags, key_flags);
1654
1675
  EnsureAnimation ();
1656
1677
 
1657
1678
void Launcher::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags)
1658
1679
{
1659
 
  _mouse_position = nux::Point2 (x, y);
 
1680
  SetMousePosition (x, y);
1660
1681
  nux::Geometry geo = GetGeometry ();
1661
1682
 
1662
1683
  if (_launcher_action_state != ACTION_NONE && !geo.IsInside(nux::Point(x, y)))
1663
1684
  {
1664
1685
    // we are no longer hovered
1665
 
    UnsetHover ();
 
1686
    EnsureHoverState ();
1666
1687
  }
1667
1688
  
1668
1689
  MouseUpLogic (x, y, button_flags, key_flags);
1673
1694
  _launcher_action_state = ACTION_NONE;
1674
1695
  _dnd_delta_x = 0;
1675
1696
  _dnd_delta_y = 0;
 
1697
  EnsureHoverState ();
1676
1698
  EnsureAnimation ();
1677
1699
}
1678
1700
 
1679
1701
void Launcher::RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
1680
1702
{
1681
 
  _mouse_position = nux::Point2 (x, y);
 
1703
  SetMousePosition (x, y);
1682
1704
 
1683
1705
  _dnd_delta_y += dy;
1684
1706
  _dnd_delta_x += dx;
1731
1753
 
1732
1754
void Launcher::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags)
1733
1755
{
1734
 
  _mouse_position = nux::Point2 (x, y);
 
1756
  SetMousePosition (x, y);
1735
1757
  _mouse_inside_launcher = true;
1736
1758
 
1737
 
  SetHover ();
 
1759
  EnsureHoverState ();
1738
1760
 
1739
1761
  EventLogic ();
1740
1762
  EnsureAnimation ();
1742
1764
 
1743
1765
void Launcher::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags)
1744
1766
{
1745
 
  _mouse_position = nux::Point2 (x, y);
 
1767
  SetMousePosition (x, y);
1746
1768
  _mouse_inside_launcher = false;
1747
1769
 
1748
1770
  if (_launcher_action_state == ACTION_NONE)
1749
 
      UnsetHover ();
 
1771
      EnsureHoverState ();
1750
1772
 
1751
1773
  EventLogic ();
1752
1774
  EnsureAnimation ();
1754
1776
 
1755
1777
void Launcher::RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
1756
1778
{
1757
 
  _mouse_position = nux::Point2 (x, y);
 
1779
  SetMousePosition (x, y);
1758
1780
 
1759
1781
  // Every time the mouse moves, we check if it is inside an icon...
1760
1782
  EventLogic ();
1762
1784
 
1763
1785
void Launcher::RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags)
1764
1786
{
 
1787
  if (!_hovered)
 
1788
    return;
 
1789
  
 
1790
  if (wheel_delta < 0)
 
1791
  {
 
1792
    // scroll up
 
1793
    _launcher_drag_delta += 10;
 
1794
  }
 
1795
  else
 
1796
  {
 
1797
    // scroll down
 
1798
    _launcher_drag_delta -= 10;
 
1799
  }
 
1800
  
 
1801
  EnsureAnimation ();
1765
1802
}
1766
1803
 
1767
1804
void Launcher::RecvQuicklistOpened (QuicklistView *quicklist)
1768
1805
{
1769
1806
  EventLogic ();
 
1807
  EnsureHoverState ();
1770
1808
  EnsureAnimation ();
1771
1809
}
1772
1810
 
1775
1813
  SetupAutohideTimer ();
1776
1814
 
1777
1815
  EventLogic ();
 
1816
  EnsureHoverState ();
1778
1817
  EnsureAnimation ();
1779
1818
}
1780
1819
 
1952
1991
    LauncherIcon* launcher_icon = (*it).icon;
1953
1992
 
1954
1993
    // We to store the icon angle in the icons itself. Makes one thing easier afterward.
1955
 
    launcher_icon->_folding_angle = (*it).folding_rads;
 
1994
    launcher_icon->_folding_angle = (*it).x_rotation;
1956
1995
 
1957
1996
    float w = _icon_size;
1958
1997
    float h = _icon_size;
1969
2008
    }
1970
2009
    
1971
2010
    ObjectMatrix = nux::Matrix4::TRANSLATE(geo.width/2.0f, geo.height/2.0f, z) * // Translate the icon to the center of the viewport
1972
 
      nux::Matrix4::ROTATEX((*it).folding_rads) *              // rotate the icon
 
2011
      nux::Matrix4::ROTATEX((*it).x_rotation) *              // rotate the icon
 
2012
      nux::Matrix4::ROTATEY((*it).y_rotation) *
 
2013
      nux::Matrix4::ROTATEZ((*it).z_rotation) *
1973
2014
      nux::Matrix4::TRANSLATE(-x - w/2.0f, -y - h/2.0f, -z);    // Put the center the icon to (0, 0)
1974
2015
 
1975
2016
    ViewProjectionMatrix = ProjectionMatrix*ViewMatrix*ObjectMatrix;
2078
2119
 
2079
2120
  float AspectRatio = (float)ViewportWidth/(float)ViewportHeight;
2080
2121
  float CameraToScreenDistance = -1.0f;
2081
 
  float y_cs = -CameraToScreenDistance*tanf(0.5f*Fovy/* *3.1415926/180.0f*/);
 
2122
  float y_cs = -CameraToScreenDistance*tanf(0.5f*Fovy/* *M_PI/180.0f*/);
2082
2123
  float x_cs = y_cs*AspectRatio;
2083
 
  //float CameraToScreenDistance = -y_cs*1.0f/(tanf(0.5f*Fovy/* *3.1415926/180.0f*/));
2084
2124
 
2085
2125
  ViewMatrix = nux::Matrix4::TRANSLATE(-x_cs, y_cs, CameraToScreenDistance) *
2086
2126
    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*/ );
2087
2127
 
2088
2128
  PerspectiveMatrix.Perspective(Fovy, AspectRatio, NearClipPlane, FarClipPlane);
2089
 
 
2090
 
//   // Example usage with the matrices above:
2091
 
//   float W = 300;
2092
 
//   float H = 300;
2093
 
//   // centered quad
2094
 
//   float X = (ViewportWidth - W)/2.0;
2095
 
//   float Y = (ViewportHeight - H)/2.0;
2096
 
//   float Z = 0.0f;
2097
 
//
2098
 
//   {
2099
 
//     glPushMatrix();
2100
 
//     // Local Transformation of the object
2101
 
//     glTranslatef(0.0f, 0.0f, ObjectDistanceToCamera);
2102
 
//     glTranslatef(X  + W/2.0f, Y + H/2.0f, 0.0f);
2103
 
//     glRotatef(cameraAngleY, 1, 0, 0);
2104
 
//     glRotatef(cameraAngleX, 0, 1, 0);
2105
 
//     glTranslatef(-X - W/2.0f, -Y - H/2.0f, 0.0f);
2106
 
//
2107
 
//     glBegin(GL_QUADS);
2108
 
//     {
2109
 
//       glNormal3f(0.0f, 0.0f, 1.0f);
2110
 
//
2111
 
//       glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
2112
 
//       glVertex4f(X, Y, Z, 1.0f);
2113
 
//
2114
 
//       glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
2115
 
//       glVertex4f(X, Y+H, Z, 1.0f);
2116
 
//
2117
 
//       glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
2118
 
//       glVertex4f(X+W, Y+H, Z, 1.0f);
2119
 
//
2120
 
//       glColor4f(0.0f, 1.0f, 1.0f, 1.0f);
2121
 
//       glVertex4f(X+W, Y, Z, 1.0f);
2122
 
//     }
2123
 
//     glEnd();
2124
 
}
2125
 
 
2126
 
void Launcher::SetOffscreenRenderTarget ()
2127
 
{
2128
 
  int width = _offscreen_rt_texture->GetWidth ();
2129
 
  int height = _offscreen_rt_texture->GetHeight ();
 
2129
}
 
2130
 
 
2131
void
 
2132
Launcher::RenderIconToTexture (nux::GraphicsEngine& GfxContext, LauncherIcon *icon, nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture)
 
2133
{
 
2134
  RenderArg arg;
 
2135
  struct timespec current;
 
2136
  clock_gettime (CLOCK_MONOTONIC, &current);
 
2137
  
 
2138
  SetupRenderArg (icon, current, arg);
 
2139
  arg.render_center = nux::Point3 (_icon_size / 2.0f, _icon_size / 2.0f, 0.0f);
 
2140
  arg.logical_center = arg.render_center;
 
2141
  arg.x_rotation = 0.0f;
 
2142
  arg.running_arrow = false;
 
2143
  arg.active_arrow = false;
 
2144
  arg.skip = false;
 
2145
  arg.window_indicators = 0;
 
2146
  arg.alpha = 1.0f;
 
2147
 
 
2148
  std::list<Launcher::RenderArg> drag_args;
 
2149
  drag_args.push_front (arg);
 
2150
  UpdateIconXForm (drag_args);
 
2151
  
 
2152
  SetOffscreenRenderTarget (texture);
 
2153
  DrawRenderArg (nux::GetGraphicsEngine (), arg, nux::Geometry (0, 0, _icon_size, _icon_size));
 
2154
  RestoreSystemRenderTarget ();
 
2155
}
 
2156
 
 
2157
void
 
2158
Launcher::RenderProgressToTexture (nux::GraphicsEngine& GfxContext, nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture, float progress_fill, float bias)
 
2159
{
 
2160
  int width = texture->GetWidth ();
 
2161
  int height = texture->GetHeight ();
 
2162
  
 
2163
  int progress_width = _progress_bar_trough->GetWidth ();
 
2164
  int progress_height = _progress_bar_trough->GetHeight ();
 
2165
 
 
2166
  int fill_width = _progress_bar_fill->GetWidth ();
 
2167
  int fill_height = _progress_bar_fill->GetHeight ();
 
2168
  
 
2169
  int fill_offset = (progress_width - fill_width) / 2;
 
2170
 
 
2171
  /* We need to perform a barn doors effect to acheive the slide in and out */
 
2172
 
 
2173
  int left_edge = width / 2 - progress_width / 2;
 
2174
  int right_edge = width / 2 + progress_width / 2;
 
2175
  
 
2176
  if (bias < 0.0f)
 
2177
  {
 
2178
    // pulls the right edge in
 
2179
    right_edge -= (int) (-bias * (float) progress_width);
 
2180
  }
 
2181
  else if (bias > 0.0f)
 
2182
  {
 
2183
    // pulls the left edge in
 
2184
    left_edge += (int) (bias * progress_width);
 
2185
  }
 
2186
  
 
2187
  int fill_y = (height - fill_height) / 2;
 
2188
  int progress_y = (height - progress_height) / 2;
 
2189
  int half_size = (right_edge - left_edge) / 2;
 
2190
  
 
2191
  SetOffscreenRenderTarget (texture);
 
2192
  
 
2193
  // FIXME
 
2194
  glClear (GL_COLOR_BUFFER_BIT);
 
2195
  nux::TexCoordXForm texxform;
 
2196
  
 
2197
  fill_width *= progress_fill;
 
2198
 
 
2199
  // left door
 
2200
  GfxContext.PushClippingRectangle(nux::Geometry (left_edge, 0, half_size, height));
 
2201
  
 
2202
  GfxContext.QRP_GLSL_1Tex (left_edge, progress_y, progress_width, progress_height, 
 
2203
                            _progress_bar_trough->GetDeviceTexture (), texxform, nux::Color::White);
 
2204
                            
 
2205
  GfxContext.QRP_GLSL_1Tex (left_edge + fill_offset, fill_y, fill_width, fill_height, 
 
2206
                            _progress_bar_fill->GetDeviceTexture (), texxform, nux::Color::White);  
 
2207
 
 
2208
  GfxContext.PopClippingRectangle (); 
 
2209
 
 
2210
 
 
2211
  // right door
 
2212
  GfxContext.PushClippingRectangle(nux::Geometry (left_edge + half_size, 0, half_size, height));
 
2213
  
 
2214
  GfxContext.QRP_GLSL_1Tex (right_edge - progress_width, progress_y, progress_width, progress_height, 
 
2215
                            _progress_bar_trough->GetDeviceTexture (), texxform, nux::Color::White);
 
2216
  
 
2217
  GfxContext.QRP_GLSL_1Tex (right_edge - progress_width + fill_offset, fill_y, fill_width, fill_height, 
 
2218
                            _progress_bar_fill->GetDeviceTexture (), texxform, nux::Color::White);
 
2219
  
 
2220
  GfxContext.PopClippingRectangle (); 
 
2221
 
 
2222
  
 
2223
  RestoreSystemRenderTarget ();
 
2224
}
 
2225
 
 
2226
void 
 
2227
Launcher::SetOffscreenRenderTarget (nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture)
 
2228
{
 
2229
  int width = texture->GetWidth ();
 
2230
  int height = texture->GetHeight ();
2130
2231
  
2131
2232
  nux::GetThreadGLDeviceFactory ()->FormatFrameBufferObject (width, height, nux::BITFMT_R8G8B8A8);
2132
 
  nux::GetThreadGLDeviceFactory ()->SetColorRenderTargetSurface (0, _offscreen_rt_texture->GetSurfaceLevel (0));
 
2233
  nux::GetThreadGLDeviceFactory ()->SetColorRenderTargetSurface (0, texture->GetSurfaceLevel (0));
2133
2234
  nux::GetThreadGLDeviceFactory ()->ActivateFrameBuffer ();
2134
2235
 
2135
2236
  nux::GetThreadGraphicsContext ()->SetContext   (0, 0, width, height);
2138
2239
  nux::GetThreadGraphicsContext ()->EmptyClippingRegion();
2139
2240
}
2140
2241
 
2141
 
void Launcher::RestoreSystemRenderTarget ()
 
2242
void 
 
2243
Launcher::RestoreSystemRenderTarget ()
2142
2244
{
2143
2245
  nux::GetWindowCompositor ().RestoreRenderingSurface ();
2144
2246
}