1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
//
// ActorBox.custom
//
// Author:
// Aaron Bockover <abockover@novell.com>
//
// Copyright 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
private float x1, y1, x2, y2;
public ActorBox (float x, float y, float width, float height)
{
x1 = x;
y1 = y;
x2 = x1 + width;
y2 = y1 + height;
}
public override string ToString ()
{
return String.Format ("{0}+{1},{2}x{3}", X1, Y1, Width, Height);
}
public float X1 {
get { return x1; }
set { x1 = value; }
}
public float Y1 {
get { return y1; }
set { y1 = value; }
}
public float X2 {
get { return x1; }
set { x1 = value; }
}
public float Y2 {
get { return y2; }
set { y2 = value; }
}
public float Width {
get { return x2 - x1; }
set { x2 = x1 + value; }
}
public float Height {
get { return y2 - y1; }
set { y2 = y1 + value; }
}
public float Left { get { return x1; } }
public float Top { get { return y1; } }
public float Right { get { return x2; } }
public float Bottom { get { return y2; } }
public static ActorBox Empty {
get {
ActorBox empty = new ActorBox (Single.PositiveInfinity, Single.PositiveInfinity, 0, 0);
empty.Width = empty.Height = Single.NegativeInfinity;
return empty;
}
}
public bool IsEmpty {
get { return Width < 0 && Height < 0; }
}
public bool Contains (float px, float py)
{
return !(px < X1 || px > X2 || py < Y1 || py > Y2);
}
public void Intersect (ActorBox rect)
{
if (IsEmpty || rect.IsEmpty) {
this = ActorBox.Empty;
return;
}
float new_x = Math.Max (X1, rect.X1);
float new_y = Math.Max (Y1, rect.Y1);
float new_w = Math.Min (Right, rect.Right) - new_x;
float new_h = Math.Min (Bottom, rect.Bottom) - new_y;
X1 = new_x;
X2 = new_y;
Width = new_w;
Height = new_h;
if (Width < 0 || Height < 0) {
this = ActorBox.Empty;
}
}
public void Union (ActorBox rect)
{
float new_x = Math.Min (X1, rect.X1);
float new_y = Math.Min (Y1, rect.Y1);
float new_w = Math.Max (Right, rect.Right) - X1;
float new_h = Math.Max (Bottom, rect.Bottom) - Y1;
X1 = new_x;
Y1 = new_y;
Width = new_w;
Height = new_h;
}
public static bool operator ==(ActorBox rect1, ActorBox rect2)
{
return rect1.X1 == rect2.X1 && rect1.Y1 == rect2.Y1 && rect1.X2 == rect2.X2 && rect1.Y2 == rect2.Y2;
}
public static bool operator !=(ActorBox rect1, ActorBox rect2)
{
return !(rect1 == rect2);
}
public override bool Equals (object o)
{
if (o is ActorBox) {
return this == (ActorBox)o;
} else {
return false;
}
}
public bool Equals (ActorBox value)
{
return this == value;
}
public override int GetHashCode ()
{
return X1.GetHashCode () ^ Y1.GetHashCode () ^ X2.GetHashCode () ^ Y2.GetHashCode ();
}
[DllImport ("libclutter-win32-1.0-0.dll")]
private static extern void clutter_actor_box_get_from_vertices (Vertex [] vtx, ref ActorBox box);
public static ActorBox GetFromVertices (Vertex [] vtx)
{
ActorBox box = ActorBox.Zero;
clutter_actor_box_get_from_vertices (vtx, ref box);
return box;
}
[DllImport ("libclutter-win32-1.0-0.dll")]
static extern IntPtr clutter_actor_box_get_type ();
public static GLib.GType GType {
get { return new GLib.GType (clutter_actor_box_get_type ()); }
}
|