-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathControl.cs
3058 lines (2679 loc) · 115 KB
/
Control.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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/////////////////////////////////////////////////////////////////
// //
// Neoforce Controls //
// //
////////////////////////////////////////////////////////////////
// //
// File: Control.cs //
// //
// Version: 0.7 //
// //
// Date: 11/09/2010 //
// //
// Author: Tom Shane //
// //
////////////////////////////////////////////////////////////////
// //
// Copyright (c) by Tom Shane //
// //
////////////////////////////////////////////////////////////////
#region //// Using /////////////
////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#if (!XBOX && !XBOX_FAKE)
using System.Media;
using System.Collections;
using System.ComponentModel;
#endif
////////////////////////////////////////////////////////////////////////////
#endregion
namespace TomShane.Neoforce.Controls
{
#region //// Classes ///////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Defines the gamepad actions mapping.
/// </summary>
public class GamePadActions
{
public GamePadButton Click = GamePadButton.A;
public GamePadButton Press = GamePadButton.Y;
public GamePadButton Left = GamePadButton.LeftStickLeft;
public GamePadButton Right = GamePadButton.LeftStickRight;
public GamePadButton Up = GamePadButton.LeftStickUp;
public GamePadButton Down = GamePadButton.LeftStickDown;
public GamePadButton NextControl = GamePadButton.RightShoulder;
public GamePadButton PrevControl = GamePadButton.LeftShoulder;
public GamePadButton ContextMenu = GamePadButton.X;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Defines type used as a controls collection.
/// </summary>
public class ControlsList : EventedList<Control>
{
public ControlsList() : base() { }
public ControlsList(int capacity) : base(capacity) { }
public ControlsList(IEnumerable<Control> collection) : base(collection) { }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Defines the base class for all controls.
/// </summary>
public class Control : Component
{
#region //// Consts/////////////
////////////////////////////////////////////////////////////////////////////
public static readonly Color UndefinedColor = new Color(255, 255, 255, 0);
////////////////////////////////////////////////////////////////////////////
#endregion
#region //// Fields ////////////
////////////////////////////////////////////////////////////////////////////
internal static ControlsList Stack = new ControlsList();
////////////////////////////////////////////////////////////////////////////
#if (!XBOX && !XBOX_FAKE)
////////////////////////////////////////////////////////////////////////////
private Cursor cursor = null;
////////////////////////////////////////////////////////////////////////////
#endif
////////////////////////////////////////////////////////////////////////////
private Color color = UndefinedColor;
private Color textColor = UndefinedColor;
private Color backColor = Color.Transparent;
private byte alpha = 255;
private Anchors anchor = Anchors.Left | Anchors.Top;
private Anchors resizeEdge = Anchors.All;
private string text = "Control";
private bool visible = true;
private bool enabled = true;
private SkinControl skin = null;
private Control parent = null;
private Control root = null;
private int left = 0;
private int top = 0;
private int width = 64;
private int height = 64;
private bool suspended = false;
private ContextMenu contextMenu = null;
private long tooltipTimer = 0;
private long doubleClickTimer = 0;
private MouseButton doubleClickButton = MouseButton.None;
private Type toolTipType = typeof(ToolTip);
private ToolTip toolTip = null;
private bool doubleClicks = true;
private bool outlineResizing = false;
private bool outlineMoving = false;
private string name = "Control";
private object tag = null;
private GamePadActions gamePadActions = new GamePadActions();
private bool designMode = false;
private bool partialOutline = true;
private Rectangle drawingRect = Rectangle.Empty;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
private ControlsList controls = new ControlsList();
private Rectangle movableArea = Rectangle.Empty;
private bool passive = false;
private bool detached = false;
private bool movable = false;
private bool resizable = false;
private bool invalidated = true;
private bool canFocus = true;
private int resizerSize = 4;
private int minimumWidth = 0;
private int maximumWidth = 4096;
private int minimumHeight = 0;
private int maximumHeight = 4096;
private int topModifier = 0;
private int leftModifier = 0;
private int virtualHeight = 64;
private int virtualWidth = 64;
private bool stayOnBack = false;
private bool stayOnTop = false;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
private RenderTarget2D target;
private Point pressSpot = Point.Zero;
private int[] pressDiff = new int[4];
private Alignment resizeArea = Alignment.None;
private bool hovered = false;
private bool inside = false;
private bool[] pressed = new bool[32];
private bool isMoving = false;
private bool isResizing = false;
private Margins margins = new Margins(4, 4, 4, 4);
private Margins anchorMargins = new Margins();
private Margins clientMargins = new Margins();
private Rectangle outlineRect = Rectangle.Empty;
/// <summary>
/// Tracks the position of the mouse scroll wheel
/// </summary>
private int scrollWheel = 0;
////////////////////////////////////////////////////////////////////////////
#endregion
#region //// Properties ////////
#if (!XBOX && !XBOX_FAKE)
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the cursor displaying over the control.
/// </summary>
public Cursor Cursor
{
get { return cursor; }
set { cursor = value; }
}
////////////////////////////////////////////////////////////////////////////
#endif
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets a list of all child controls.
/// </summary>
public virtual IEnumerable<Control> Controls { get { return controls; } }
/// <summary>
/// Gets or sets a rectangular area that reacts on moving the control with the mouse.
/// </summary>
public virtual Rectangle MovableArea { get { return movableArea; } set { movableArea = value; } }
/// <summary>
/// Gets a value indicating whether this control is a child control.
/// </summary>
public virtual bool IsChild { get { return (parent != null); } }
/// <summary>
/// Gets a value indicating whether this control is a parent control.
/// </summary>
public virtual bool IsParent { get { return (controls != null && controls.Count > 0); } }
/// <summary>
/// Gets a value indicating whether this control is a root control.
/// </summary>
public virtual bool IsRoot { get { return (root == this); } }
/// <summary>
/// Gets or sets a value indicating whether this control can receive focus.
/// </summary>
public virtual bool CanFocus { get { return canFocus; } set { canFocus = value; } }
/// <summary>
/// Gets or sets a value indicating whether this control is rendered off the parents texture.
/// </summary>
public virtual bool Detached { get { return detached; } set { detached = value; } }
/// <summary>
/// Gets or sets a value indicating whether this controls can receive user input events.
/// </summary>
public virtual bool Passive { get { return passive; } set { passive = value; } }
/// <summary>
/// Gets or sets a value indicating whether this control can be moved by the mouse.
/// </summary>
public virtual bool Movable { get { return movable; } set { movable = value; } }
/// <summary>
/// Gets or sets a value indicating whether this control can be resized by the mouse.
/// </summary>
public virtual bool Resizable { get { return resizable; } set { resizable = value; } }
/// <summary>
/// Gets or sets the size of the rectangular borders around the control used for resizing by the mouse.
/// </summary>
public virtual int ResizerSize { get { return resizerSize; } set { resizerSize = value; } }
/// <summary>
/// Gets or sets the ContextMenu associated with this control.
/// </summary>
public virtual ContextMenu ContextMenu { get { return contextMenu; } set { contextMenu = value; } }
/// <summary>
/// Gets or sets a value indicating whether this control should process mouse double-clicks.
/// </summary>
public virtual bool DoubleClicks { get { return doubleClicks; } set { doubleClicks = value; } }
/// <summary>
/// Gets or sets a value indicating whether this control should use ouline resizing.
/// </summary>
public virtual bool OutlineResizing { get { return outlineResizing; } set { outlineResizing = value; } }
/// <summary>
/// Gets or sets a value indicating whether this control should use outline moving.
/// </summary>
public virtual bool OutlineMoving { get { return outlineMoving; } set { outlineMoving = value; } }
/// <summary>
/// Gets or sets the object that contains data about the control.
/// </summary>
public virtual object Tag { get { return tag; } set { tag = value; } }
/// <summary>
/// Gets or sets the value indicating the distance from another control. Usable with StackPanel control.
/// </summary>
public virtual Margins Margins { get { return margins; } set { margins = value; } }
/// <summary>
/// Gets or sets the value indicating wheter control is in design mode.
/// </summary>
public virtual bool DesignMode { get { return designMode; } set { designMode = value; } }
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets gamepad actions for the control.
/// </summary>
public virtual GamePadActions GamePadActions
{
get { return gamePadActions; }
set { gamePadActions = value; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the value indicating whether the control outline is displayed only for certain edges.
/// </summary>
public virtual bool PartialOutline
{
get { return partialOutline; }
set { partialOutline = value; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the value indicating whether the control is allowed to be brought in the front.
/// </summary>
public virtual bool StayOnBack
{
get { return stayOnBack; }
set
{
if (value && stayOnTop) stayOnTop = false;
stayOnBack = value;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the value indicating that the control should stay on top of other controls.
/// </summary>
public virtual bool StayOnTop
{
get { return stayOnTop; }
set
{
if (value && stayOnBack) stayOnBack = false;
stayOnTop = value;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets a name of the control.
/// </summary>
public virtual string Name
{
get { return name; }
set { name = value; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets a value indicating whether this control has input focus.
/// </summary>
public virtual bool Focused
{
get
{
return (Manager.FocusedControl == this);
}
set
{
this.Invalidate();
if (value)
{
bool f = Focused;
Manager.FocusedControl = this;
if (!Suspended && value && !f) OnFocusGained(new EventArgs());
if (Focused && Root != null && Root is Container)
{
(Root as Container).ScrollTo(this);
}
}
else
{
bool f = Focused;
if (Manager.FocusedControl == this) Manager.FocusedControl = null;
if (!Suspended && !value && f) OnFocusLost(new EventArgs());
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets a value indicating current state of the control.
/// </summary>
public virtual ControlState ControlState
{
get
{
if (DesignMode) return ControlState.Enabled;
else if (Suspended) return ControlState.Disabled;
else
{
if (!enabled) return ControlState.Disabled;
if ((IsPressed && inside) || (Focused && IsPressed)) return ControlState.Pressed;
else if (hovered && !IsPressed) return ControlState.Hovered;
else if ((Focused && !inside) || (hovered && IsPressed && !inside) || (Focused && !hovered && inside)) return ControlState.Focused;
else return ControlState.Enabled;
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
public virtual Type ToolTipType
{
get { return toolTipType; }
set
{
toolTipType = value;
if (toolTip != null)
{
toolTip.Dispose();
toolTip = null;
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
public virtual ToolTip ToolTip
{
get
{
if (toolTip == null)
{
Type[] t = new Type[1] { typeof(Manager) };
object[] p = new object[1] { Manager };
toolTip = (ToolTip)toolTipType.GetConstructor(t).Invoke(p);
toolTip.Init();
toolTip.Visible = false;
}
return toolTip;
}
set
{
toolTip = value;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
internal protected virtual bool IsPressed
{
get
{
for (int i = 0; i < pressed.Length - 1; i++)
{
if (pressed[i]) return true;
}
return false;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
internal virtual int TopModifier
{
get { return topModifier; }
set { topModifier = value; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
internal virtual int LeftModifier
{
get { return leftModifier; }
set { leftModifier = value; }
}
////////////////////////////////////////////////////////////////////////////
internal virtual int VirtualHeight
{
get { return GetVirtualHeight(); }
//set { virtualHeight = value; }
}
////////////////////////////////////////////////////////////////////////////
internal virtual int VirtualWidth
{
get { return GetVirtualWidth(); }
//set { virtualWidth = value; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets an area where is the control supposed to be drawn.
/// </summary>
public Rectangle DrawingRect
{
get { return drawingRect; }
private set { drawingRect = value; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets a value indicating whether this control should receive any events.
/// </summary>
public virtual bool Suspended
{
get { return suspended; }
set { suspended = value; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
internal protected virtual bool Hovered
{
get { return hovered; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
internal protected virtual bool Inside
{
get { return inside; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
internal protected virtual bool[] Pressed
{
get { return pressed; }
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets a value indicating whether this controls is currently being moved.
/// </summary>
protected virtual bool IsMoving
{
get
{
return isMoving;
}
set
{
isMoving = value;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets a value indicating whether this controls is currently being resized.
/// </summary>
protected virtual bool IsResizing
{
get
{
return isResizing;
}
set
{
isResizing = value;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the edges of the container to which a control is bound and determines how a control is resized with its parent.
/// </summary>
public virtual Anchors Anchor
{
get
{
return anchor;
}
set
{
anchor = value;
SetAnchorMargins();
if (!Suspended) OnAnchorChanged(new EventArgs());
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the edges of the contol which are allowed for resizing.
/// </summary>
public virtual Anchors ResizeEdge
{
get
{
return resizeEdge;
}
set
{
resizeEdge = value;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the skin used for rendering the control.
/// </summary>
public virtual SkinControl Skin
{
get
{
return skin;
}
set
{
skin = value;
ClientMargins = skin.ClientMargins;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the text associated with this control.
/// </summary>
public virtual string Text
{
get { return text; }
set
{
text = value;
Invalidate();
if (!Suspended) OnTextChanged(new EventArgs());
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the alpha value for this control.
/// </summary>
public virtual byte Alpha
{
get
{
return alpha;
}
set
{
alpha = value;
if (!Suspended) OnAlphaChanged(new EventArgs());
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the background color for the control.
/// </summary>
public virtual Color BackColor
{
get
{
return backColor;
}
set
{
backColor = value;
Invalidate();
if (!Suspended) OnBackColorChanged(new EventArgs());
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the color for the control.
/// </summary>
public virtual Color Color
{
get
{
return color;
}
set
{
if (value != color)
{
color = value;
Invalidate();
if (!Suspended) OnColorChanged(new EventArgs());
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the text color for the control.
/// </summary>
public virtual Color TextColor
{
get
{
return textColor;
}
set
{
if (value != textColor)
{
textColor = value;
Invalidate();
if (!Suspended) OnTextColorChanged(new EventArgs());
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets a value indicating whether the control can respond to user interaction.
/// </summary>
public virtual bool Enabled
{
get
{
return enabled;
}
set
{
if (Root != null && Root != this && !Root.Enabled && value) return;
enabled = value;
Invalidate();
foreach (Control c in controls)
{
c.Enabled = value;
}
if (!Suspended) OnEnabledChanged(new EventArgs());
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets a value that indicates whether the control is rendered.
/// </summary>
public virtual bool Visible
{
get
{
return (visible && (parent == null || parent.Visible));
}
set
{
visible = value;
Invalidate();
if (!Suspended) OnVisibleChanged(new EventArgs());
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the parent for the control.
/// </summary>
public virtual Control Parent
{
get
{
return parent;
}
set
{
if (parent != value)
{
if (value != null) value.Add(this);
else Manager.Add(this);
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the root for the control.
/// </summary>
public virtual Control Root
{
get
{
return root;
}
private set
{
if (root != value)
{
root = value;
foreach (Control c in controls)
{
c.Root = root;
}
if (!Suspended) OnRootChanged(new EventArgs());
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the distance, in pixels, between the left edge of the control and the left edge of its parent.
/// </summary>
public virtual int Left
{
get
{
return left;
}
set
{
if (left != value)
{
int old = left;
left = value;
SetAnchorMargins();
if (!Suspended) OnMove(new MoveEventArgs(left, top, old, top));
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the distance, in pixels, between the top edge of the control and the top edge of its parent.
/// </summary>
public virtual int Top
{
get
{
return top;
}
set
{
if (top != value)
{
int old = top;
top = value;
SetAnchorMargins();
if (!Suspended) OnMove(new MoveEventArgs(left, top, left, old));
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the width of the control.
/// </summary>
public virtual int Width
{
get
{
return width;
}
set
{
if (value < 0 && Parent != null && value > int.MinValue)
{
var mult = value / -100f;
value = (int)(parent.Width * mult);
}
if (width != value)
{
int old = width;
width = value;
if (skin != null)
{
if (width + skin.OriginMargins.Horizontal > MaximumWidth) width = MaximumWidth - skin.OriginMargins.Horizontal;
}
else
{
if (width > MaximumWidth) width = MaximumWidth;
}
if (width < MinimumWidth) width = MinimumWidth;
if (width > 0) SetAnchorMargins();
if (!Suspended) OnResize(new ResizeEventArgs(width, height, old, height));
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the height of the control.
/// </summary>
public virtual int Height
{
get
{
return height;
}
set
{
if (value < 0 && Parent != null && value > int.MinValue)
{
var mult = value / -100f;
value = (int)(parent.Height * mult);
}
if (height != value)
{
int old = height;
height = value;
if (skin != null)
{
if (height + skin.OriginMargins.Vertical > MaximumHeight)
height = MaximumHeight - skin.OriginMargins.Vertical;
}
else
{
if (height > MaximumHeight) height = MaximumHeight;
}
if (height < MinimumHeight) height = MinimumHeight;
if (height > 0) SetAnchorMargins();
if (!Suspended) OnResize(new ResizeEventArgs(width, height, width, old));
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gets or sets the minimum width in pixels the control can be sized to.
/// </summary>
public virtual int MinimumWidth
{
get
{
return minimumWidth;
}
set
{
minimumWidth = value;
if (minimumWidth < 0) minimumWidth = 0;
if (minimumWidth > maximumWidth) minimumWidth = maximumWidth;
if (width < MinimumWidth) Width = MinimumWidth;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// /// Gets or sets the minimum height in pixels the control can be sized to.
/// </summary>
public virtual int MinimumHeight
{
get
{
return minimumHeight;
}
set
{
minimumHeight = value;
if (minimumHeight < 0) minimumHeight = 0;
if (minimumHeight > maximumHeight) minimumHeight = maximumHeight;
if (height < MinimumHeight) Height = MinimumHeight;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// /// Gets or sets the maximum width in pixels the control can be sized to.
/// </summary>
public virtual int MaximumWidth
{
get
{
int max = maximumWidth;
if (max > Manager.TargetWidth) max = Manager.TargetWidth;
return max;
}
set
{