~mike82/netbook-remix-launcher/fixes

« back to all changes in this revision

Viewing changes to src/launcher-icon.c

  • Committer: Michael
  • Date: 2009-01-12 18:50:25 UTC
  • Revision ID: mike@rsy.com-20090112185025-dkh8mx1s7z03o3ep
Simplified and improved the selection/highlighting of icons in the icon view, using the new behaviour function.
The new code is much more robust: the effects look smoother, and it handles edge cases like when animations are interrupted by further mouse or keyboard movement.  There is no longer any jerking/snapping when animations are interrupted or replaced.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
#include "clutter-drag-server.h"
35
35
 
 
36
#include "launcher-behave.h"
36
37
#include "launcher-config.h"
37
38
#include "launcher-defines.h"
38
39
#include "launcher-iconview.h"
62
63
  ClutterTimeline       *time;
63
64
  ClutterEffectTemplate *temp;
64
65
 
65
 
  ClutterTimeline       *fast_time;
66
 
  ClutterEffectTemplate *fast_temp;
67
 
  ClutterTimeline       *current;
68
 
  
 
66
  ClutterTimeline       *hover_time;
 
67
  ClutterBehaviour      *colour_behave;
 
68
  ClutterBehaviour      *scale_behave;
 
69
 
69
70
  ClutterActor *label;
70
 
  ClutterActor *orange;
71
71
  ClutterActor *texture;
72
72
  ClutterActor *clone;
73
73
 
303
303
  g_return_val_if_fail (LAUNCHER_IS_ICON (icon), FALSE);
304
304
  priv = icon->priv;
305
305
 
306
 
  if (CLUTTER_IS_TIMELINE (priv->current) 
307
 
      && clutter_timeline_is_playing (priv->current))
 
306
  clutter_timeline_set_direction (priv->hover_time,
 
307
                                  CLUTTER_TIMELINE_FORWARD);
 
308
 
 
309
  if (!clutter_timeline_is_playing (priv->hover_time))
308
310
  {
309
 
    clutter_timeline_stop (priv->current);
310
 
    if (G_IS_OBJECT (priv->current)) 
311
 
      g_object_unref (priv->current);
312
 
  } 
313
 
 
314
 
  clutter_label_set_color (CLUTTER_LABEL (priv->label), &orange);
315
 
  priv->current = clutter_effect_scale (priv->fast_temp, priv->texture, 
316
 
                                        1.2, 1.2, NULL, NULL);
 
311
    clutter_timeline_rewind (priv->hover_time);
 
312
    clutter_timeline_start (priv->hover_time);
 
313
  }
317
314
 
318
315
  return TRUE;
319
316
}
329
326
  g_return_val_if_fail (LAUNCHER_IS_ICON (icon), FALSE);
330
327
  priv = icon->priv;
331
328
 
332
 
  if (CLUTTER_IS_TIMELINE (priv->current) 
333
 
      && clutter_timeline_is_playing (priv->current))
 
329
  clutter_timeline_set_direction (priv->hover_time,
 
330
                                  CLUTTER_TIMELINE_BACKWARD);
 
331
 
 
332
  if (!clutter_timeline_is_playing (priv->hover_time) &&
 
333
      clutter_actor_is_scaled (priv->texture))
334
334
  {
335
 
    clutter_timeline_stop (priv->current);
336
 
    if (G_IS_OBJECT (priv->current)) 
337
 
      g_object_unref (priv->current);
338
 
  } 
339
 
 
340
 
  clutter_label_set_color (CLUTTER_LABEL (priv->label), &white);
341
 
  priv->current = clutter_effect_scale (priv->fast_temp, priv->texture, 
342
 
                                        1.0, 1.0, NULL, NULL);
 
335
    clutter_timeline_rewind (priv->hover_time);
 
336
    clutter_timeline_start (priv->hover_time);
 
337
  }
343
338
 
344
339
  return TRUE;
345
340
}
404
399
  clutter_actor_set_anchor_point_from_gravity (texture, CLUTTER_GRAVITY_CENTER);
405
400
  clutter_actor_set_position (texture, width/2, padding/1.5 + CAH (texture)/2);
406
401
  clutter_container_add_actor (CLUTTER_CONTAINER (icon), texture);
 
402
  clutter_behaviour_apply (priv->scale_behave, texture);
407
403
  clutter_actor_show (texture);
408
404
 
409
405
  /* Text label */
423
419
                              (width/2)-(CAW (label)/2),
424
420
                              clutter_actor_get_y (texture) + CAH(texture)/1.5
425
421
                               );
 
422
  clutter_behaviour_apply (priv->colour_behave, label);
426
423
  clutter_actor_show (label);
427
424
 
428
425
  clip_label (CLUTTER_LABEL (label),
461
458
launcher_icon_set_focus (LauncherIcon *icon, gboolean has_focus)
462
459
{
463
460
  LauncherIconPrivate *priv;
 
461
  ClutterTimelineDirection dir;
464
462
    
465
463
  g_return_if_fail (LAUNCHER_IS_ICON (icon));
466
464
  priv = icon->priv;
467
465
 
468
 
  if (has_focus)
469
 
  {
470
 
    clutter_label_set_color (CLUTTER_LABEL (priv->label), &orange);
471
 
  }
472
 
  else
473
 
  {
474
 
    clutter_label_set_color (CLUTTER_LABEL (priv->label), &white);
 
466
  dir = has_focus ? CLUTTER_TIMELINE_FORWARD : CLUTTER_TIMELINE_BACKWARD;
 
467
 
 
468
  if (clutter_timeline_get_direction (priv->hover_time) != dir)
 
469
  {
 
470
    clutter_timeline_set_direction (priv->hover_time, dir);
 
471
 
 
472
    if (!clutter_timeline_is_playing (priv->hover_time))
 
473
    {
 
474
      clutter_timeline_rewind (priv->hover_time);
 
475
      clutter_timeline_start (priv->hover_time);
 
476
    }
475
477
  }
476
478
}
477
479
 
508
510
static void
509
511
launcher_icon_init (LauncherIcon *icon)
510
512
{
 
513
  static LauncherTextColourPair pair = { &white, &orange };
511
514
  LauncherIconPrivate *priv;
 
515
  ClutterAlpha *alpha;
512
516
  
513
517
  priv = icon->priv = LAUNCHER_ICON_GET_PRIVATE (icon);
514
518
 
529
533
  priv->temp = clutter_effect_template_new (priv->time, 
530
534
                                            clutter_sine_inc_func);
531
535
 
532
 
  priv->fast_time = clutter_timeline_new_for_duration (MID_TIME);
533
 
  priv->fast_temp = clutter_effect_template_new (priv->fast_time,
534
 
                                                 clutter_sine_inc_func);
 
536
  priv->hover_time = clutter_timeline_new_for_duration (MID_TIME);
 
537
  clutter_timeline_set_direction (priv->hover_time,
 
538
                                  CLUTTER_TIMELINE_BACKWARD);
 
539
  alpha = clutter_alpha_new_full (priv->hover_time,
 
540
                                  clutter_sine_inc_func,
 
541
                                  NULL, NULL);
 
542
  priv->colour_behave = launcher_behave_new (alpha,
 
543
                                             launcher_colour_behaviour,
 
544
                                             &pair);
 
545
  priv->scale_behave = clutter_behaviour_scale_new (alpha,
 
546
                                                    1, 1, 1.2, 1.2);
 
547
  g_object_unref (G_OBJECT (alpha));
535
548
}
536
549
 
537
550
ClutterActor *