/
Rectangle.cs
executable file
·538 lines (493 loc) · 19.1 KB
/
Rectangle.cs
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/*
* Copyright(c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.ComponentModel;
using Tizen.NUI.Binding;
namespace Tizen.NUI
{
/// <summary>
/// The Rectangle class.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Binding.TypeConverter(typeof(RectangleTypeConverter))]
public class Rectangle : Disposable, ICloneable
{
/// <summary>
/// The constructor.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public Rectangle() : this(Interop.Rectangle.NewRectangle(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// The constructor.
/// </summary>
/// <param name="x">The x coordinate (or left).</param>
/// <param name="y">The y coordinate (or right).</param>
/// <param name="width">The width (or bottom).</param>
/// <param name="height">The height (or top).</param>
/// <since_tizen> 3 </since_tizen>
public Rectangle(int x, int y, int width, int height) : this(Interop.Rectangle.NewRectangle(x, y, width, height), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal Rectangle(Rectangle other) : this(other.x, other.y, other.width, other.height)
{
}
internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
{
}
internal Rectangle(RectangleChangedCallback cb, int x, int y, int width, int height) : this(Interop.Rectangle.NewRectangle(x, y, width, height), true)
{
callback = cb;
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal Rectangle(RectangleChangedCallback cb) : this()
{
callback = cb;
}
internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
{
}
/// <summary>
/// The type cast operator, int to Rectangle.
/// </summary>
/// <param name="value">A value of int type.</param>
/// <returns>return a Extents instance</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public static implicit operator Rectangle(int value)
{
return new Rectangle(value, value, value, value);
}
internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
private RectangleChangedCallback callback = null;
/// <summary>
/// The x position of the rectangle.
/// </summary>
/// <remarks>
/// The setter is deprecated in API8 and will be removed in API10. Use new Rectangle(...) constructor.
/// </remarks>
/// <code>
/// // DO NOT use like the followings!
/// Rectangle rectangle = new Rectangle();
/// rectangle.X = 1;
/// // USE like this
/// int x = 1, y = 2, width = 3, height = 4;
/// Rectangle rectangle = new Rectangle(x, y, width, height);
/// </code>
/// <since_tizen> 3 </since_tizen>
public int X
{
[Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Rectangle(...) constructor")]
set
{
x = (value);
callback?.Invoke(X, Y, Width, Height);
}
get
{
return x;
}
}
/// <summary>
/// The Y position of the rectangle.
/// </summary>
/// <remarks>
/// The setter is deprecated in API8 and will be removed in API10. Use new Rectangle(...) constructor.
/// </remarks>
/// <code>
/// // DO NOT use like the followings!
/// Rectangle rectangle = new Rectangle();
/// rectangle.Y = 2;
/// // USE like this
/// int x = 1, y = 2, width = 3, height = 4;
/// Rectangle rectangle = new Rectangle(x, y, width, height);
/// </code>
/// <since_tizen> 3 </since_tizen>
public int Y
{
[Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Rectangle(...) constructor")]
set
{
y = (value);
callback?.Invoke(X, Y, Width, Height);
}
get
{
return y;
}
}
/// <summary>
/// The width of the rectangle.
/// </summary>
/// <remarks>
/// The setter is deprecated in API8 and will be removed in API10. Use new Rectangle(...) constructor.
/// </remarks>
/// <code>
/// // DO NOT use like the followings!
/// Rectangle rectangle = new Rectangle();
/// rectangle.Width = 3;
/// // USE like this
/// int x = 1, y = 2, width = 3, height = 4;
/// Rectangle rectangle = new Rectangle(x, y, width, height);
/// </code>
/// <since_tizen> 3 </since_tizen>
public int Width
{
[Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Rectangle(...) constructor")]
set
{
width = (value);
callback?.Invoke(X, Y, Width, Height);
}
get
{
return width;
}
}
/// <summary>
/// The height of the rectangle.
/// </summary>
/// <remarks>
/// The setter is deprecated in API8 and will be removed in API10. Use new Rectangle(...) constructor.
/// </remarks>
/// <code>
/// // DO NOT use like the followings!
/// Rectangle rectangle = new Rectangle();
/// rectangle.Height = 4;
/// // USE like this
/// int x = 1, y = 2, width = 3, height = 4;
/// Rectangle rectangle = new Rectangle(x, y, width, height);
/// </code>
/// <since_tizen> 3 </since_tizen>
public int Height
{
[Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Rectangle(...) constructor")]
set
{
height = (value);
callback?.Invoke(X, Y, Width, Height);
}
get
{
return height;
}
}
private int x
{
set
{
Interop.Rectangle.XSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = Interop.Rectangle.XGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int left
{
set
{
Interop.Rectangle.LeftSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = Interop.Rectangle.LeftGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int y
{
set
{
Interop.Rectangle.YSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = Interop.Rectangle.YGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int right
{
set
{
Interop.Rectangle.RightSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = Interop.Rectangle.RightGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int width
{
set
{
Interop.Rectangle.WidthSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = Interop.Rectangle.WidthGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int bottom
{
set
{
Interop.Rectangle.BottomSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = Interop.Rectangle.BottomGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int height
{
set
{
Interop.Rectangle.HeightSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = Interop.Rectangle.HeightGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int top
{
set
{
Interop.Rectangle.TopSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = Interop.Rectangle.TopGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
/// <summary>
/// THe Equality operator.
/// </summary>
/// <param name="a">The first operand.</param>
/// <param name="b">The second operand.</param>
/// <returns>True if the boxes are exactly the same.</returns>
/// <since_tizen> 3 </since_tizen>
public static bool operator ==(Rectangle a, Rectangle b)
{
// If both are null, or both are same instance, return true.
if (System.Object.ReferenceEquals(a, b))
{
return true;
}
// If one is null, but not both, return false.
if (((object)a == null) || ((object)b == null))
{
return false;
}
// Return true if the fields match:
return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
}
/// <summary>
/// Inequality operator.
/// </summary>
/// <param name="a">The first rectangle.</param>
/// <param name="b">The second rectangle.</param>
/// <returns>True if the rectangles are not identical.</returns>
/// <since_tizen> 3 </since_tizen>
public static bool operator !=(Rectangle a, Rectangle b)
{
return !(a == b);
}
/// <summary>
/// Equality operator.
/// </summary>
/// <param name="o">The object to compare with the current object.</param>
/// <returns>True if boxes are exactly same.</returns>
/// <since_tizen> 4 </since_tizen>
public override bool Equals(object o)
{
if (o == null)
{
return false;
}
if (!(o is Rectangle))
{
return false;
}
Rectangle r = (Rectangle)o;
// Return true if the fields match:
return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
}
/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns>A hash code for the current object.</returns>
/// <since_tizen> 4 </since_tizen>
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// Assignment from individual values.
/// </summary>
/// <param name="newX">The x coordinate.</param>
/// <param name="newY">The y coordinate.</param>
/// <param name="newWidth">The width.</param>
/// <param name="newHeight">The height.</param>
/// <since_tizen> 3 </since_tizen>
public void Set(int newX, int newY, int newWidth, int newHeight)
{
Interop.Rectangle.Set(SwigCPtr, newX, newY, newWidth, newHeight);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// Determines whether or not this rectangle is empty.
/// </summary>
/// <returns>True if width or height are zero.</returns>
/// <since_tizen> 3 </since_tizen>
public bool IsEmpty()
{
bool ret = Interop.Rectangle.IsEmpty(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <summary>
/// Gets the left of the rectangle.
/// </summary>
/// <returns>The left edge of the rectangle.</returns>
/// <since_tizen> 3 </since_tizen>
public int Left()
{
int ret = Interop.Rectangle.Left(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <summary>
/// Gets the right of the rectangle.
/// </summary>
/// <returns>The right edge of the rectangle.</returns>
/// <since_tizen> 3 </since_tizen>
public int Right()
{
int ret = Interop.Rectangle.Right(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <summary>
/// Gets the top of the rectangle.
/// </summary>
/// <returns>The top of the rectangle.</returns>
/// <since_tizen> 3 </since_tizen>
public int Top()
{
int ret = Interop.Rectangle.Top(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <summary>
/// Gets the bottom of the rectangle.
/// </summary>
/// <returns>The bottom of the rectangle.</returns>
/// <since_tizen> 3 </since_tizen>
public int Bottom()
{
int ret = Interop.Rectangle.Bottom(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <summary>
/// Gets the area of the rectangle.
/// </summary>
/// <returns>The area of the rectangle.</returns>
/// <since_tizen> 3 </since_tizen>
public int Area()
{
int ret = Interop.Rectangle.Area(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <summary>
/// Determines whether or not this rectangle and the specified rectangle intersect.
/// </summary>
/// <param name="other">The other rectangle to test against this rectangle.</param>
/// <returns>True if the rectangles intersect.</returns>
/// <since_tizen> 3 </since_tizen>
public bool Intersects(Rectangle other)
{
bool ret = Interop.Rectangle.Intersects(SwigCPtr, Rectangle.getCPtr(other));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <summary>
/// Determines whether or not this rectangle contains the specified rectangle.
/// </summary>
/// <param name="other">The other rectangle to test against this rectangle.</param>
/// <returns>True if the specified rectangle is contained.</returns>
/// <since_tizen> 3 </since_tizen>
public bool Contains(Rectangle other)
{
bool ret = Interop.Rectangle.Contains(SwigCPtr, Rectangle.getCPtr(other));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
public object Clone() => new Rectangle(this);
/// This will not be public opened.
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
{
Interop.Rectangle.DeleteRectangle(swigCPtr);
}
/// <summary>
/// Determines whether the reference is null or the Rectangle has all 0 properties.
/// </summary>
internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));
/// <summary>
/// Get Rectangle from Intptr.<br/>
/// </summary>
/// <param name="cPtr">An object of IntPtr type.</param>
/// <returns>An object of the Rectangle type.</returns>
internal static Rectangle GetRectangleFromPtr(global::System.IntPtr cPtr)
{
Rectangle ret = new Rectangle(cPtr, false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
}