~zeitgeist/plank/zeitgeist

« back to all changes in this revision

Viewing changes to lib/PositionManager.vala

  • Committer: Rico Tzschichholz
  • Date: 2013-09-30 22:02:11 UTC
  • Revision ID: ricotz@ubuntu.com-20130930220211-77d050nwi70blazx
Cache item's "draw-values" and handle item-position changes more specific

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
         */
32
32
        public class PositionManager : GLib.Object
33
33
        {
 
34
                public struct DockItemDrawValue
 
35
                {
 
36
                        public Gdk.Rectangle hover_region;
 
37
                        public Gdk.Rectangle draw_region;
 
38
                        public Gdk.Rectangle background_region;
 
39
                        
 
40
                        public DockItemDrawValue move_in (PositionType position, double damount)
 
41
                        {
 
42
                                var result = this;
 
43
                                var amount = (int) damount;
 
44
                                
 
45
                                switch (position) {
 
46
                                default:
 
47
                                case PositionType.BOTTOM:
 
48
                                        result.hover_region.y -= amount;
 
49
                                        result.draw_region.y -= amount;
 
50
                                        result.background_region.y -= amount;
 
51
                                        break;
 
52
                                case PositionType.TOP:
 
53
                                        result.hover_region.y += amount;
 
54
                                        result.draw_region.y += amount;
 
55
                                        result.background_region.y += amount;
 
56
                                        break;
 
57
                                case PositionType.LEFT:
 
58
                                        result.hover_region.x += amount;
 
59
                                        result.draw_region.x += amount;
 
60
                                        result.background_region.x += amount;
 
61
                                        break;
 
62
                                case PositionType.RIGHT:
 
63
                                        result.hover_region.x -= amount;
 
64
                                        result.draw_region.x -= amount;
 
65
                                        result.background_region.x -= amount;
 
66
                                        break;
 
67
                                }
 
68
                                
 
69
                                return result;
 
70
                        }
 
71
                        
 
72
                        public DockItemDrawValue move_right (PositionType position, double damount)
 
73
                        {
 
74
                                var result = this;
 
75
                                var amount = (int) damount;
 
76
                                
 
77
                                switch (position) {
 
78
                                default:
 
79
                                case PositionType.BOTTOM:
 
80
                                        result.hover_region.x -= amount;
 
81
                                        result.draw_region.x -= amount;
 
82
                                        result.background_region.x -= amount;
 
83
                                        break;
 
84
                                case PositionType.TOP:
 
85
                                        result.hover_region.x += amount;
 
86
                                        result.draw_region.x += amount;
 
87
                                        result.background_region.x += amount;
 
88
                                        break;
 
89
                                case PositionType.LEFT:
 
90
                                        result.hover_region.y += amount;
 
91
                                        result.draw_region.y += amount;
 
92
                                        result.background_region.y += amount;
 
93
                                        break;
 
94
                                case PositionType.RIGHT:
 
95
                                        result.hover_region.y -= amount;
 
96
                                        result.draw_region.y -= amount;
 
97
                                        result.background_region.y -= amount;
 
98
                                        break;
 
99
                                }
 
100
                                
 
101
                                return result;
 
102
                        }
 
103
                }
 
104
                
34
105
                public DockController controller { private get; construct; }
35
106
                
36
107
                Gdk.Rectangle static_dock_region;
 
108
                HashMap<DockItem, DockItemDrawValue?> draw_values;
37
109
                
38
110
                Gdk.Rectangle monitor_geo;
39
111
                
52
124
                construct
53
125
                {
54
126
                        static_dock_region = Gdk.Rectangle ();
 
127
                        draw_values = new HashMap<DockItem, DockItemDrawValue?> ();                     
55
128
                        
56
129
                        controller.prefs.notify["Monitor"].connect (update_monitor_geo);
57
130
                }
80
153
                        screen.monitors_changed.disconnect (update_monitor_geo);
81
154
                        screen.size_changed.disconnect (update_monitor_geo);
82
155
                        controller.prefs.notify["Monitor"].disconnect (update_monitor_geo);
 
156
                        
 
157
                        draw_values.clear ();
83
158
                }
84
159
                
85
160
                void update_monitor_geo ()
203
278
                        update_dock_position ();
204
279
                }
205
280
                
 
281
                /**
 
282
                 * Resets all internal caches for the given item.
 
283
                 *
 
284
                 * @param item the dock item
 
285
                 */
 
286
                public void reset_item_caches (DockItem item)
 
287
                {
 
288
                        draw_values.unset (item);
 
289
                }
 
290
                
206
291
                void update_caches (DockTheme theme)
207
292
                {
208
293
                        IconSize = int.min (MaxIconSize, controller.prefs.IconSize);
236
321
                                HorizPadding = int.max (0, HorizPadding);
237
322
                                TopPadding = int.max (0, TopPadding);
238
323
                        }
 
324
                        
 
325
                        draw_values.clear ();
239
326
                }
240
327
                
241
328
                /**
459
546
                                break;
460
547
                        }
461
548
                        
 
549
                        // FIXME Maybe no need to purge all cached values?
 
550
                        draw_values.clear ();
 
551
                        
462
552
                        if (old_region.x != static_dock_region.x
463
553
                                || old_region.y != static_dock_region.y
464
554
                                || old_region.width != static_dock_region.width
475
565
                }
476
566
                
477
567
                /**
 
568
                 * The draw-value for a dock item.
 
569
                 *
 
570
                 * @param item the dock item to find the drawvalue for
 
571
                 * @return the region for the dock item
 
572
                 */
 
573
                public DockItemDrawValue get_draw_value_for_item (DockItem item)
 
574
                {
 
575
                        DockItemDrawValue? draw_value;
 
576
                        
 
577
                        if ((draw_value = draw_values.get (item)) == null) {
 
578
                                var hover_rect = internal_item_hover_region (item);
 
579
                                var draw_rect = item_draw_region (hover_rect);
 
580
                                var background_rect = item_background_region (hover_rect);
 
581
                        
 
582
                                draw_value = { hover_rect, draw_rect, background_rect };
 
583
                                draw_values.set (item, draw_value);
 
584
                        }
 
585
                        
 
586
                        return draw_value;
 
587
                }
 
588
                
 
589
                /**
478
590
                 * The region for drawing a dock item.
479
591
                 *
480
592
                 * @param hover_rect the item's hover region
481
593
                 * @return the region for the dock item
482
594
                 */
483
 
                public Gdk.Rectangle item_draw_region (Gdk.Rectangle hover_rect)
 
595
                Gdk.Rectangle item_draw_region (Gdk.Rectangle hover_rect)
484
596
                {
485
597
                        var item_padding = ItemPadding;
486
598
                        var top_padding = top_offset + TopPadding;
526
638
                 * @param rect the item's hover region
527
639
                 * @return the region for the dock item
528
640
                 */
529
 
                public Gdk.Rectangle item_background_region (Gdk.Rectangle rect)
 
641
                Gdk.Rectangle item_background_region (Gdk.Rectangle rect)
530
642
                {
531
643
                        var top_padding = top_offset + TopPadding;
532
644
                        top_padding = (top_padding > 0 ? 0 : top_padding);
582
694
                 */
583
695
                public Gdk.Rectangle item_hover_region (DockItem item)
584
696
                {
 
697
                        return get_draw_value_for_item (item).hover_region;
 
698
                }
 
699
                        
 
700
                Gdk.Rectangle internal_item_hover_region (DockItem item)
 
701
                {
585
702
                        unowned DockPreferences prefs = controller.prefs;
586
703
                        
587
704
                        var rect = Gdk.Rectangle ();