~and471/+junk/do-with-docky

« back to all changes in this revision

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

  • Committer: rugby471 at gmail
  • Date: 2010-10-15 16:08:38 UTC
  • Revision ID: rugby471@gmail.com-20101015160838-z9m3utbf7bxzb5ty
reverted to before docky removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// LayoutUtils.cs
 
2
// 
 
3
// Copyright (C) 2008 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 Cairo;
 
24
using Gdk;
 
25
 
 
26
using Docky.Utilities;
 
27
 
 
28
namespace Docky.Interface
 
29
{
 
30
        public enum RelativeMove
 
31
        {
 
32
                Inward = 0,
 
33
                Outward,
 
34
                RelativeLeft,
 
35
                RelativeRight,
 
36
                RelativeUp,
 
37
                RelativeDown,
 
38
                RealLeft,
 
39
                RealRight,
 
40
                RealUp,
 
41
                RealDown,
 
42
        }
 
43
        
 
44
        public static class LayoutUtils
 
45
        {
 
46
                static Gdk.Rectangle monitor_geo = Gdk.Screen.Default.GetMonitorGeometry (DockPreferences.Monitor);
 
47
 
 
48
                static LayoutUtils ()
 
49
                {
 
50
                        Gdk.Screen.Default.SizeChanged += HandleSizeChanged;
 
51
                }
 
52
 
 
53
                static void HandleSizeChanged (object sender, EventArgs args)
 
54
                {
 
55
                        Recalculate ();
 
56
                }
 
57
 
 
58
                public static void Recalculate ()
 
59
                {
 
60
                        monitor_geo = Gdk.Screen.Default.GetMonitorGeometry (DockPreferences.Monitor);
 
61
                }
 
62
                
 
63
                public static Gdk.Rectangle MonitorGeometry ()
 
64
                {
 
65
                        return monitor_geo;
 
66
                }
 
67
                
 
68
                public static Gdk.Rectangle RelativeRectangleToRootPoint (this Gdk.Rectangle relativePoint, Gtk.Window window)
 
69
                {
 
70
                        Gdk.Rectangle main;
 
71
                        if (window is DockWindow)
 
72
                                (window as DockWindow).GetBufferedPosition (out main.X, out main.Y);
 
73
                        else
 
74
                                window.GetPosition (out main.X, out main.Y);
 
75
                        return new Gdk.Rectangle (main.X + relativePoint.X, main.Y + relativePoint.Y, relativePoint.Width, relativePoint.Height);
 
76
                }
 
77
 
 
78
                public static Gdk.Point RelativePointToRootPoint (this Gdk.Point relativePoint, Gtk.Window window)
 
79
                {
 
80
                        Gdk.Rectangle main;
 
81
                        if (window is DockWindow)
 
82
                                (window as DockWindow).GetBufferedPosition (out main.X, out main.Y);
 
83
                        else
 
84
                                window.GetPosition (out main.X, out main.Y);
 
85
                        return new Gdk.Point (main.X + relativePoint.X, main.Y + relativePoint.Y);
 
86
                }
 
87
 
 
88
                public static Gdk.Point RelativeMovePoint (this Gdk.Point startingLocation, int delta, RelativeMove direction)
 
89
                {
 
90
                        int[] vector = null;
 
91
                        switch (direction) {
 
92
                        case RelativeMove.RealDown:
 
93
                                return new Gdk.Point (startingLocation.X, startingLocation.Y + delta);
 
94
                                
 
95
                        case RelativeMove.RealLeft:
 
96
                                return new Gdk.Point (startingLocation.X - delta, startingLocation.Y);
 
97
                                
 
98
                        case RelativeMove.RealRight:
 
99
                                return new Gdk.Point (startingLocation.X + delta, startingLocation.Y);
 
100
                                
 
101
                        case RelativeMove.RealUp:
 
102
                                return new Gdk.Point (startingLocation.X, startingLocation.Y - delta);
 
103
 
 
104
                        case RelativeMove.Inward:
 
105
                        case RelativeMove.RelativeUp:
 
106
                                vector = new [] {0, 0 - delta};
 
107
                                break;
 
108
                                
 
109
                        case RelativeMove.Outward:
 
110
                        case RelativeMove.RelativeDown:
 
111
                                vector = new [] {0, delta};
 
112
                                break;
 
113
                                
 
114
                        case RelativeMove.RelativeLeft:
 
115
                                vector = new [] {0 - delta, 0};
 
116
                                break;
 
117
                                
 
118
                        case RelativeMove.RelativeRight:
 
119
                                vector = new [] {delta, 0};
 
120
                                break;
 
121
                        }
 
122
 
 
123
                        switch (DockPreferences.Orientation) {
 
124
                        case DockOrientation.Bottom:
 
125
                                // do nothing
 
126
                                break;
 
127
                        case DockOrientation.Top:
 
128
                                vector = new [] {vector [0], 0 - vector [1]};
 
129
                                break;
 
130
                        }
 
131
 
 
132
                        return new Gdk.Point (startingLocation.X + vector [0], startingLocation.Y + vector [1]);
 
133
                }
 
134
 
 
135
                public static PointD RelativeMovePoint (this PointD startingLocation, double delta, RelativeMove direction)
 
136
                {
 
137
                        double[] vector = null;
 
138
                        switch (direction) {
 
139
                        case RelativeMove.RealDown:
 
140
                                return new PointD (startingLocation.X, startingLocation.Y + delta);
 
141
                                
 
142
                        case RelativeMove.RealLeft:
 
143
                                return new PointD (startingLocation.X - delta, startingLocation.Y);
 
144
                                
 
145
                        case RelativeMove.RealRight:
 
146
                                return new PointD (startingLocation.X + delta, startingLocation.Y);
 
147
                                
 
148
                        case RelativeMove.RealUp:
 
149
                                return new PointD (startingLocation.X, startingLocation.Y - delta);
 
150
 
 
151
                        case RelativeMove.Inward:
 
152
                        case RelativeMove.RelativeUp:
 
153
                                vector = new [] {0, 0 - delta};
 
154
                                break;
 
155
                                
 
156
                        case RelativeMove.Outward:
 
157
                        case RelativeMove.RelativeDown:
 
158
                                vector = new [] {0, delta};
 
159
                                break;
 
160
                                
 
161
                        case RelativeMove.RelativeLeft:
 
162
                                vector = new [] {0 - delta, 0};
 
163
                                break;
 
164
                                
 
165
                        case RelativeMove.RelativeRight:
 
166
                                vector = new [] {delta, 0};
 
167
                                break;
 
168
                        }
 
169
 
 
170
                        switch (DockPreferences.Orientation) {
 
171
                        case DockOrientation.Bottom:
 
172
                                // do nothing
 
173
                                break;
 
174
                        case DockOrientation.Top:
 
175
                                vector = new [] {vector [0], 0 - vector [1]};
 
176
                                break;
 
177
                        }
 
178
 
 
179
                        return new PointD (startingLocation.X + vector [0], startingLocation.Y + vector [1]);
 
180
                }
 
181
        }
 
182
}