3
// Copyright (C) 2008 GNOME Do
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.
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.
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/>.
20
using System.Collections.Generic;
26
using Docky.Utilities;
28
namespace Docky.Interface
30
public enum RelativeMove
44
public static class LayoutUtils
46
static Gdk.Rectangle monitor_geo = Gdk.Screen.Default.GetMonitorGeometry (DockPreferences.Monitor);
50
Gdk.Screen.Default.SizeChanged += HandleSizeChanged;
53
static void HandleSizeChanged (object sender, EventArgs args)
58
public static void Recalculate ()
60
monitor_geo = Gdk.Screen.Default.GetMonitorGeometry (DockPreferences.Monitor);
63
public static Gdk.Rectangle MonitorGeometry ()
68
public static Gdk.Rectangle RelativeRectangleToRootPoint (this Gdk.Rectangle relativePoint, Gtk.Window window)
71
if (window is DockWindow)
72
(window as DockWindow).GetBufferedPosition (out main.X, out main.Y);
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);
78
public static Gdk.Point RelativePointToRootPoint (this Gdk.Point relativePoint, Gtk.Window window)
81
if (window is DockWindow)
82
(window as DockWindow).GetBufferedPosition (out main.X, out main.Y);
84
window.GetPosition (out main.X, out main.Y);
85
return new Gdk.Point (main.X + relativePoint.X, main.Y + relativePoint.Y);
88
public static Gdk.Point RelativeMovePoint (this Gdk.Point startingLocation, int delta, RelativeMove direction)
92
case RelativeMove.RealDown:
93
return new Gdk.Point (startingLocation.X, startingLocation.Y + delta);
95
case RelativeMove.RealLeft:
96
return new Gdk.Point (startingLocation.X - delta, startingLocation.Y);
98
case RelativeMove.RealRight:
99
return new Gdk.Point (startingLocation.X + delta, startingLocation.Y);
101
case RelativeMove.RealUp:
102
return new Gdk.Point (startingLocation.X, startingLocation.Y - delta);
104
case RelativeMove.Inward:
105
case RelativeMove.RelativeUp:
106
vector = new [] {0, 0 - delta};
109
case RelativeMove.Outward:
110
case RelativeMove.RelativeDown:
111
vector = new [] {0, delta};
114
case RelativeMove.RelativeLeft:
115
vector = new [] {0 - delta, 0};
118
case RelativeMove.RelativeRight:
119
vector = new [] {delta, 0};
123
switch (DockPreferences.Orientation) {
124
case DockOrientation.Bottom:
127
case DockOrientation.Top:
128
vector = new [] {vector [0], 0 - vector [1]};
132
return new Gdk.Point (startingLocation.X + vector [0], startingLocation.Y + vector [1]);
135
public static PointD RelativeMovePoint (this PointD startingLocation, double delta, RelativeMove direction)
137
double[] vector = null;
139
case RelativeMove.RealDown:
140
return new PointD (startingLocation.X, startingLocation.Y + delta);
142
case RelativeMove.RealLeft:
143
return new PointD (startingLocation.X - delta, startingLocation.Y);
145
case RelativeMove.RealRight:
146
return new PointD (startingLocation.X + delta, startingLocation.Y);
148
case RelativeMove.RealUp:
149
return new PointD (startingLocation.X, startingLocation.Y - delta);
151
case RelativeMove.Inward:
152
case RelativeMove.RelativeUp:
153
vector = new [] {0, 0 - delta};
156
case RelativeMove.Outward:
157
case RelativeMove.RelativeDown:
158
vector = new [] {0, delta};
161
case RelativeMove.RelativeLeft:
162
vector = new [] {0 - delta, 0};
165
case RelativeMove.RelativeRight:
166
vector = new [] {delta, 0};
170
switch (DockPreferences.Orientation) {
171
case DockOrientation.Bottom:
174
case DockOrientation.Top:
175
vector = new [] {vector [0], 0 - vector [1]};
179
return new PointD (startingLocation.X + vector [0], startingLocation.Y + vector [1]);