~ubuntu-branches/ubuntu/precise/gnome-do/precise-backports

« back to all changes in this revision

Viewing changes to Do.Interface.Linux.Docky/src/Docky.Interface/ItemPositionProvider.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers, Christopher James Halse Rogers, Iain Lane
  • Date: 2009-02-04 15:30:25 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090204153025-dhb2pm7dgbtmoib6
Tags: 0.8.0-1~ubuntu1
[ Christopher James Halse Rogers ]
* New upstream release.  (LP: #323048)
  + Fixes text input problems (LP: #288517)
  + No longer grabs plugins from internet repositories (LP: #294808)
  + Preferences dialog is resizable (LP: #305419)
* Build against gtk, gnome mono packages from Experimental. (Closes: #510836)
* debian/control:
  + Bump versioned dep on libgtk2.0-cil to ensure
    Gdk.Screen.IsComposited exists (Closes: #510973)
  + Add libwnck2.20-cil build-dep
  + gnome-sharp2 transition.
* debian/patches/04_fix_locale_dir
* debian/patches/05_fix_localised_theme_setting
* debian/patches/06_expand_homedir_in_open
  + Drop; fixed in new upstream  
* debian/patches/02_use_cli_for_wrapper
  + Update for new upstream
  + Add dpatch comments
* debian/gnome-do.1
  + Fix broken formatting (LP: #291654).  Thank you to Frédéric Grosshans
    for spotting it, and the patch.
  + Update for new version.

[ Iain Lane ]
* Tag pkg-cli-apps SVN revision into Jaunty, to get in before Feature
  Freeze. Should be a sync after the next Debian upload.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ItemPositionProvider.cs
 
2
// 
 
3
// Copyright (C) 2009 GNOME Do
 
4
//
 
5
// This program is free software: you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation, either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
//
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
//
 
18
 
 
19
using System;
 
20
using System.Collections.Generic;
 
21
using System.Linq;
 
22
 
 
23
using Gdk;
 
24
 
 
25
using Docky.Utilities;
 
26
 
 
27
namespace Docky.Interface
 
28
{
 
29
        
 
30
        
 
31
        public class ItemPositionProvider : IDisposable
 
32
        {
 
33
                const int HorizontalBuffer = 7;
 
34
                
 
35
                DockItemProvider item_provider;
 
36
                Rectangle clip_area;
 
37
                
 
38
                List<BaseDockItem> DockItems {
 
39
                        get { return item_provider.DockItems; }
 
40
                }
 
41
                
 
42
                /// <value>
 
43
                /// The width of the visible dock
 
44
                /// </value>
 
45
                public int DockWidth {
 
46
                        get {
 
47
                                int val = 2 * HorizontalBuffer;
 
48
                                foreach (BaseDockItem di in DockItems)
 
49
                                        val += 2 * DockPreferences.IconBorderWidth + di.Width;
 
50
                                return val;
 
51
                        }
 
52
                }
 
53
                
 
54
                public int VerticalBuffer {
 
55
                        get { return 5; }
 
56
                }
 
57
                
 
58
                int IconSize {
 
59
                        get { return DockPreferences.IconSize; }
 
60
                }
 
61
                
 
62
                int Width {
 
63
                        get { return clip_area.Width; }
 
64
                }
 
65
                
 
66
                int Height {
 
67
                        get { return clip_area.Height; }
 
68
                }
 
69
                
 
70
                int ZoomSize {
 
71
                        get { return DockPreferences.ZoomSize; }
 
72
                }
 
73
                
 
74
                public Rectangle MinimumDockArea { 
 
75
                        get {
 
76
                                int x_offset = (Width - DockWidth) / 2;
 
77
                                return new Gdk.Rectangle (x_offset, Height - IconSize - 2 * VerticalBuffer, DockWidth, IconSize + 2 * VerticalBuffer);
 
78
                        }
 
79
                }
 
80
                
 
81
                public ItemPositionProvider(DockItemProvider itemProvider, Gdk.Rectangle clipArea)
 
82
                {
 
83
                        item_provider = itemProvider;
 
84
                        clip_area = clipArea;
 
85
                }
 
86
                
 
87
                public Rectangle DockArea (double zoomByEntryTime, Gdk.Point cursor)
 
88
                {
 
89
                        int start_x, end_x;
 
90
                        double start_zoom, end_zoom;
 
91
                        IconZoomedPosition (0, zoomByEntryTime, cursor, out start_x, out start_zoom);
 
92
                        IconZoomedPosition (DockItems.Count - 1, zoomByEntryTime, cursor, out end_x, out end_zoom);
 
93
                        
 
94
                        double x = start_x - start_zoom * (IconSize / 2) - (start_zoom * HorizontalBuffer) - DockPreferences.IconBorderWidth;
 
95
                        double end = end_x + end_zoom * (IconSize / 2) + (end_zoom * HorizontalBuffer) + DockPreferences.IconBorderWidth;
 
96
                        
 
97
                        return new Gdk.Rectangle ((int) x, Height - IconSize - 2 * VerticalBuffer, (int) (end - x), IconSize + 2 * VerticalBuffer);
 
98
                }
 
99
                
 
100
                public int IconUnzoomedPosition (int icon)
 
101
                {
 
102
                        // the first icons center is at dock X + border + IconBorder + half its width
 
103
                        // it is subtle, but it *is* a mistake to add the half width until the end.  adding
 
104
                        // premature will add the wrong width.  It hurts the brain.
 
105
                        if (!DockItems.Any ())
 
106
                                return 0;
 
107
                        int startX = MinimumDockArea.X + HorizontalBuffer + DockPreferences.IconBorderWidth;
 
108
                        for (int i = 0; i < icon; i++)
 
109
                                startX += DockItems [i].Width + 2 * DockPreferences.IconBorderWidth;
 
110
                        
 
111
                        return startX + DockItems [icon].Width / 2;
 
112
                }
 
113
                
 
114
                public void IconZoomedPosition (int icon, double zoomByEntryTime, Gdk.Point cursor, out int position, out double zoom)
 
115
                {
 
116
                        // get our actual center
 
117
                        int center = IconUnzoomedPosition (icon);
 
118
                        
 
119
                        // ZoomPercent is a number greater than 1.  It should never be less than one.
 
120
                        // ZoomIn is a range of 0 to 1. we need a number that is 1 when ZoomIn is 0, 
 
121
                        // and ZoomPercent when ZoomIn is 1.  Then we treat this as 
 
122
                        // if it were the ZoomPercent for the rest of the calculation
 
123
                        double zoomInPercent = 1 + (DockPreferences.ZoomPercent - 1) * zoomByEntryTime;
 
124
                        
 
125
                        // offset from the center of the true position, ranged between 0 and half of the zoom range
 
126
                        int offset = Math.Min (Math.Abs (cursor.X - center), ZoomSize / 2);
 
127
                        
 
128
                        if (ZoomSize / 2.0 == 0) {
 
129
                                zoom = 1;
 
130
                        } else {
 
131
                                // zoom is calculated as 1 through target_zoom (default 2).  
 
132
                                // The larger your offset, the smaller your zoom
 
133
                                zoom = 0 - Math.Pow (offset / (ZoomSize / 2.0), 2) + 2;
 
134
                                zoom = 1 + (zoom - 1) * (zoomInPercent - 1);
 
135
                                
 
136
                                offset = (int) (offset * (zoomInPercent - 1) - (zoomInPercent - zoom) * (IconSize * .9));
 
137
                        }
 
138
                        
 
139
                        if (cursor.X > center) {
 
140
                                center -= offset;
 
141
                        } else {
 
142
                                center += offset;
 
143
                        }
 
144
                        position = center;
 
145
                }
 
146
                
 
147
                public int IndexAtPosition (int position)
 
148
                {
 
149
                        int startX = MinimumDockArea.X + HorizontalBuffer;
 
150
                        int width;
 
151
                        for (int i = 0; i < DockItems.Count; i++) {
 
152
                                width = DockItems [i].Width + 2 * DockPreferences.IconBorderWidth;
 
153
                                if (position >= startX && position <= startX + width)
 
154
                                        return i;
 
155
                                startX += width;
 
156
                        }
 
157
                        return -1;
 
158
                }
 
159
 
 
160
                #region IDisposable implementation 
 
161
                
 
162
                public void Dispose ()
 
163
                {
 
164
                        item_provider = null;
 
165
                }
 
166
                
 
167
                #endregion 
 
168
                
 
169
        }
 
170
}