-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWindow.cs
912 lines (762 loc) · 30.3 KB
/
Window.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
// <copyright file="Window.cs" company="Pixel Precision LLC">
// Copyright (c) 2020 All Rights Reserved
// </copyright>
// <author>William Leu</author>
// <date>04/12/2020</date>
// <summary>
// A window, managing a RectTransform, that in turn is meant to
// be managed by a UIDock.Root.
// </summary>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PxPre.UIDock
{
public class Window :
UnityEngine.UI.Image,
UnityEngine.EventSystems.IBeginDragHandler,
UnityEngine.EventSystems.IEndDragHandler,
UnityEngine.EventSystems.IDragHandler,
UnityEngine.EventSystems.IPointerDownHandler,
UnityEngine.EventSystems.IPointerUpHandler,
UnityEngine.EventSystems.IPointerClickHandler
{
/// <summary>
/// The different style flags used to defined
/// properties for a window.
/// </summary>
[System.Flags]
public enum Flag
{
/// <summary>
/// If set, the window has a close button.
/// </summary>
HasClose = 1 << 0,
/// <summary>
/// If set, the window has a pin button
/// </summary>
HasPin = 1 << 1,
/// <summary>
/// If set, the window can be made floatable.
/// </summary>
Floatable = 1 << 2,
/// <summary>
/// If set, the window can be resized.
/// </summary>
Resizeable = 1 << 3,
/// <summary>
/// The window is forced to be borderless and cannot
/// be removed from docking. There should only ever be
/// 1 of these at most in a dock system.
/// </summary>
LockedFrame = 1 << 4
}
/// <summary>
/// An enum used to describe what kind of dragging
/// operations is being done to the variable
/// this.dragWindow.
/// </summary>
/// <remarks>The siz of </remarks>
[System.Flags]
public enum FrameDrag
{
/// <summary>
/// A frame is not being
/// </summary>
None = 0,
/// <summary>
/// The top is being dragged.
/// </summary>
Top = 1 << 0,
/// <summary>
/// The left is being dragged.
/// </summary>
Left = 1 << 1,
/// <summary>
/// The bottom is being dragged.
/// </summary>
Bottom = 1 << 2,
/// <summary>
/// The right is being dragged.
/// </summary>
Right = 1 << 3,
/// <summary>
/// The position is being moved from dragging the
/// titlebar.
/// </summary>
Position = 1 << 4
}
/// <summary>
/// The part of the frame on this.dragWindow being draged.
/// </summary>
static FrameDrag drag = FrameDrag.None;
/// <summary>
/// The window being dragged by the mouse.
/// </summary>
static Window dragWindow = null;
/// <summary>
/// The location where the mouse drag was started.
/// </summary>
static Vector2 localDragStart;
/// <summary>
/// A collection of variables for the titlebar buttons.
/// </summary>
public struct ButtonInfo
{
/// <summary>
/// The button.
/// </summary>
public UnityEngine.UI.Button btn;
/// <summary>
/// The outer button container.
/// </summary>
public UnityEngine.UI.Image plate;
/// <summary>
/// The inside button icon.
/// </summary>
public UnityEngine.UI.Image icon;
}
/// <summary>
/// The default flags for a standard window.
/// </summary>
public const Flag DefaultFlags =
Flag.HasClose | Flag.HasPin | Flag.Floatable | Flag.HasPin;
/// <summary>
/// A cached copy of the window's style flags.
/// </summary>
private DockProps.WinType style =
DockProps.WinType.Float;
/// <summary>
/// The Root managing the window.
/// </summary>
public Root system = null;
/// <summary>
/// The shadow sprite shown underneath when the window is floating.
/// </summary>
public UnityEngine.UI.Image shadow = null;
/// <summary>
/// The close titlebar button.
/// </summary>
ButtonInfo btnClose;
/// <summary>
/// The pin titlebar button.
/// </summary>
ButtonInfo btnPin;
/// <summary>
/// The restore/maximize titlebar button.
/// </summary>
ButtonInfo btnRestMax;
/// <summary>
/// The UI element being managed.
/// </summary>
private RectTransform win = null;
/// <summary>
/// read-only access to the window.
/// </summary>
public RectTransform Win {get{return this.win; } }
/// <summary>
/// The titlebar text.
/// </summary>
UnityEngine.UI.Text titlebar;
/// <summary>
/// The cached value of the flags that built the window.
/// </summary>
Flag flags = 0;
/// <summary>
/// Timer used to tracking the distance of clicks.
/// Used with lastClickWin to detect double clicks.
/// </summary>
static float lastClickTime = -999.0f;
/// <summary>
/// The last window clicked, used with lastClickTime
/// to track double clicks.
/// </summary>
static Window lastClickWin = null;
public bool Locked { get => (this.flags & Flag.LockedFrame) != 0; }
public bool Closable {get => (this.flags & Flag.HasClose) != 0; }
/// <summary>
/// Reset the double clicks tracking variables.
/// </summary>
static void ResetDoubleClick()
{
lastClickTime = -999.0f;
lastClickWin = null;
}
/// <summary>
/// Initialize the window.
/// </summary>
/// <param name="parent">The Root that the window will be managed by.</param>
/// <param name="rt">The UI being managed.</param>
/// <param name="titlebar">The titlebar text.</param>
/// <param name="flags">The style flags.</param>
public void Initialize(
Root parent,
RectTransform rt,
string titlebar,
Flag buildFlags = DefaultFlags)
{
this.system = parent;
DockProps props = system.props;
props.floatWin.spriteFrame.ApplySliced(this);
this.transform.SetParent(parent.rectTransform);
PrepareChild(this.rectTransform);
this.win = rt;
rt.SetParent(this.rectTransform);
PrepareChild(rt);
GameObject goShadow = new GameObject("Shadow_" + rt.gameObject.name);
goShadow.transform.SetParent(parent.rectTransform);
this.shadow = goShadow.AddComponent<UnityEngine.UI.Image>();
this.shadow.color = props.shadowColor;
props.shadow.ApplySliced(this.shadow);
PrepareChild(this.shadow.rectTransform);
GameObject goTitleTest = new GameObject("Text_" + rt.gameObject.name);
goTitleTest.transform.SetParent(this.transform);
UnityEngine.UI.Text title = goTitleTest.AddComponent<UnityEngine.UI.Text>();
PrepareChild(title.rectTransform);
title.font = props.titleFont;
title.fontSize = props.titleFontSize;
title.color = props.titleLabelColor;
this.titlebar = title;
this.rectTransform.sizeDelta =
CalculateSizeFromInnerRect();
if((buildFlags & Flag.LockedFrame) == 0)
{
if ((buildFlags & Flag.HasClose) != 0)
{
this.btnClose = this.AddButton(props.spriteBtnClose.sprite);
this.btnClose.btn.onClick.AddListener(()=>{ this.OnTitlebarButton_Close(); });
}
if((buildFlags & Flag.HasPin) != 0)
{
this.btnPin = this.AddButton(props.spriteBtnPin.sprite);
this.btnPin.btn.onClick.AddListener(()=>{ this.OnTitlebarButton_Pin(); });
}
if((buildFlags & Flag.Floatable) != 0)
{
this.btnRestMax = this.AddButton(props.spriteBtnMax.sprite);
this.btnRestMax.btn.onClick.AddListener(()=>{ this.OnTitlebarButton_RestMax(); });
}
}
this.flags = buildFlags;
this.TitlebarText = titlebar;
this.PlaceContentWin();
}
/// <summary>
/// Callback for the close window.
/// </summary>
void OnTitlebarButton_Close()
{
this.CloseWindow();
}
/// <summary>
/// Callback for the restore/maximize window.
/// </summary>
void OnTitlebarButton_RestMax()
{
this.MaximizeWindow();
}
void OnTitlebarButton_Pin()
{
this.PinWindow();
}
/// <summary>
/// Access to the titlebar text.
/// </summary>
public string TitlebarText
{
get => this.titlebar.text;
set
{
this.titlebar.text = value;
}
}
/// <summary>
/// Calcuate how window should be to properly managed the ui content without
/// changing the ui content's size.
/// </summary>
/// <returns></returns>
Vector2 CalculateSizeFromInnerRect()
{
DockProps props = system.props;
Vector2 dimRt = this.win.rect.size;
Vector2 size =
new Vector2(
dimRt.x + props.winPadding * 2.0f,
dimRt.y + props.winPadding + props.floatWin.titlebarHeight);
return size;
}
/// <summary>
/// Calculate how big the managed content should be to maintain the window's
/// current size while still properly containing the ui content.
/// </summary>
/// <returns></returns>
Vector2 CalculateInnerRectFromSize()
{
DockProps props = system.props;
Vector2 dimRt = this.rectTransform.rect.size;
Vector2 size =
new Vector2(
dimRt.x - props.winPadding * 2.0f,
dimRt.y - (props.winPadding + props.floatWin.titlebarHeight));
return size;
}
/// <summary>
/// Create button assets in the window.
/// </summary>
/// <param name="iconSprite">The icon.</param>
/// <returns>The button information.</returns>
ButtonInfo AddButton(Sprite iconSprite)
{
GameObject goPlate = new GameObject("Button");
goPlate.transform.SetParent( this.transform );
UnityEngine.UI.Image plate = goPlate.AddComponent<UnityEngine.UI.Image>();
PrepareChild(plate.rectTransform);
UnityEngine.UI.Button btn = goPlate.AddComponent<UnityEngine.UI.Button>();
btn.targetGraphic = plate;
ButtonInfo ret = new ButtonInfo();
ret.btn = btn;
ret.plate = plate;
if(iconSprite != null)
{
GameObject goIcon = new GameObject("Icon");
goIcon.transform.SetParent(goPlate.transform);
UnityEngine.UI.Image icon = goIcon.AddComponent<UnityEngine.UI.Image>();
icon.sprite = iconSprite;
icon.rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
icon.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
icon.rectTransform.pivot = new Vector2(0.5f, 0.5f);
Vector2 halfDim = iconSprite.rect.size / 2.0f;
icon.rectTransform.offsetMin = new Vector2(-halfDim.x, -halfDim.y);
icon.rectTransform.offsetMax = new Vector2(halfDim.x, halfDim.y);
ret.icon = icon;
}
return ret;
}
IEnumerable<ButtonInfo> EnuerateButtons()
{
if (this.btnClose.plate != null)
yield return this.btnClose;
if (this.btnRestMax.plate != null)
yield return this.btnRestMax;
if (this.btnPin.plate != null)
yield return this.btnPin;
}
/// <summary>
/// Match the client content to take up the full windowed area. Used
/// for docked content to hide the border.
/// </summary>
void PlaceContentBorderless()
{
this.win.anchorMin = Vector2.zero;
this.win.anchorMax = Vector2.one;
this.win.offsetMin = Vector2.zero;
this.win.offsetMax = Vector2.zero;
foreach (ButtonInfo bi in this.EnuerateButtons())
bi.plate.gameObject.SetActive(false);
}
/// <summary>
/// Move the inner content around in the window to be placed. This
/// does not only account for the managed ui, but for all the other
/// things (titlebar buttons, titlebar text, etc).
/// </summary>
void PlaceContentWin()
{
DockProps props = system.props;
DockProps.WindowSetting winset = this.GetWindowSetting();
Vector2 clientDim = this.CalculateInnerRectFromSize();
this.win.anchorMin = Vector2.zero;
this.win.anchorMax = Vector2.one;
this.win.offsetMin = new Vector2(props.winPadding, props.winPadding);
this.win.offsetMax = new Vector2(-props.winPadding, -winset.titlebarHeight);
float ffromR = props.winPadding;
float buttonY = (props.floatWin.titlebarHeight - props.floatWin.btnHeight) * 0.5f;
foreach(ButtonInfo bi in this.EnuerateButtons())
{
bi.plate.gameObject.SetActive(true);
bi.plate.rectTransform.sizeDelta =
new Vector2(
props.floatWin.btnWidth,
props.floatWin.btnHeight);
ffromR += props.floatWin.btnWidth;
bi.plate.rectTransform.anchorMin = new Vector2(1.0f, 1.0f);
bi.plate.rectTransform.anchorMax = new Vector2(1.0f, 1.0f);
bi.plate.rectTransform.anchoredPosition =
new Vector2(-ffromR, -buttonY);
}
float fend = this.rectTransform.rect.width - ffromR;
TextGenerationSettings tgs =
this.titlebar.GetGenerationSettings(
new Vector2(
float.PositiveInfinity,
float.PositiveInfinity));
TextGenerator tg = this.titlebar.cachedTextGenerator;
Vector2 titlebarTextSz =
new Vector2(
tg.GetPreferredWidth(this.titlebar.text, tgs),
tg.GetPreferredHeight(this.titlebar.text, tgs));
this.titlebar.alignment = TextAnchor.MiddleLeft;
RectTransform rtTitle = this.titlebar.rectTransform;
rtTitle.pivot = new Vector2(0.5f, 0.5f);
rtTitle.anchorMin = new Vector2(0.0f, 1.0f);
rtTitle.anchorMax = new Vector2(1.0f, 1.0f);
rtTitle.offsetMin = new Vector2(props.winPadding, -winset.titlebarHeight);
rtTitle.offsetMax = new Vector2(0.0f, 0.0f);
this.UpdateShadow();
}
/// <summary>
/// Update the shadow. This includes size, position and z-ordering.
/// </summary>
public void UpdateShadow()
{
if(this.shadow.gameObject.activeSelf == false)
return;
DockProps props = system.props;
this.shadow.rectTransform.sizeDelta = this.rectTransform.sizeDelta;
this.shadow.rectTransform.anchoredPosition = this.rectTransform.anchoredPosition + props.shadowOffset;
int thisSibIdx = this.rectTransform.GetSiblingIndex();
if(thisSibIdx == 0)
this.shadow.rectTransform.SetAsFirstSibling();
else
this.shadow.rectTransform.SetSiblingIndex(thisSibIdx - 1);
}
/// <summary>
/// Apply standard UI setup work to a RectTransform.
///
/// It's assumed the input RectTransform is already
/// parented correctly.
/// </summary>
/// <param name="rt"></param>
public static void PrepareChild(RectTransform rt)
{
rt.localScale = Vector3.one;
rt.localRotation = Quaternion.identity;
rt.pivot = new Vector2(0.0f, 1.0f);
rt.anchorMin = new Vector2(0.0f, 1.0f);
rt.anchorMax = new Vector2(0.0f, 1.0f);
}
/// <summary>
/// Toggle the window's shadow.
/// </summary>
/// <param name="shadow">
/// If true, the shadow is turned on;
/// if false, the shadow is turned off.</param>
public void EnableShadow(bool shadow = true)
{
if(this.shadow != null)
this.shadow.gameObject.SetActive(shadow);
}
/// <summary>
/// Turn off the window's shadow.
/// </summary>
public void DisableShadow()
{
this.EnableShadow(false);
}
/// <summary>
/// Maximize the window.
/// </summary>
private void MaximizeWindow()
{
if(this.system.IsMaximized(this) == true)
this.system.RestoreWindow(this);
else
this.system.MaximizeWindow(this);
}
/// <summary>
///
/// </summary>
private void RestoreWindow()
{
this.system.RestoreWindow(this);
}
/// <summary>
/// Close and destroy the window.
/// </summary>
private void CloseWindow()
{
this.system.CloseWindow(this);
}
/// <summary>
/// Undock the window.
/// </summary>
private void PinWindow()
{
this.system.UndockWindow(this);
}
/// <summary>
/// Get the window settings, based on the visual style of the window.
/// </summary>
/// <returns>The window settings.</returns>
/// <remarks>The visual style should not be confused with the style flags.</remarks>
DockProps.WindowSetting GetWindowSetting()
{
return this.system.props.GetWindowSetting(this.style);
}
internal static void _StartOutsideDrag(FrameDrag frame, Window dragWin, Vector2 offset)
{
drag = frame;
dragWindow = dragWin;
localDragStart = offset;
}
/// <summary>
/// Unity interface method for starting a UI drag.
/// </summary>
void UnityEngine.EventSystems.IBeginDragHandler.OnBeginDrag(UnityEngine.EventSystems.PointerEventData eventData)
{
if( this.Locked == true)
{
eventData.pointerDrag = null;
return;
}
if (dragWindow == this && drag == FrameDrag.Position)
this.system.StartWindowDrag(this, eventData);
}
/// <summary>
/// Unity interface method for ending a UI drag.
/// </summary>
void UnityEngine.EventSystems.IEndDragHandler.OnEndDrag(UnityEngine.EventSystems.PointerEventData eventData)
{
this.system.EndWindowDrag(this, drag, eventData);
dragWindow = null;
drag = FrameDrag.None;
}
/// <summary>
/// Unity interface method for dragging.
/// </summary>
void UnityEngine.EventSystems.IDragHandler.OnDrag(UnityEngine.EventSystems.PointerEventData eventData)
{
if(dragWindow != this)
return;
if(drag == FrameDrag.None)
return;
if(this.system.IsMaximized(this) == true)
{
if(drag != FrameDrag.Position)
return;
this.RestoreWindow();
}
DockProps props = this.system.props;
if(drag == FrameDrag.Position)
{
this.rectTransform.anchoredPosition += eventData.delta;
this.system.HandleWindowDrag(this, eventData);
}
else
{
// TODO: Min size enforcement
Vector2 rtpos = this.rectTransform.anchoredPosition;
Vector2 rtsize = this.rectTransform.sizeDelta;
if((drag & FrameDrag.Top) != 0)
{
float dy = eventData.delta.y;
float newSz = Mathf.Max(rtsize.y + dy, props.minsizeWindow.y);
dy = newSz - rtsize.y;
rtpos.y += dy;
rtsize.y += dy;
}
else if((drag & FrameDrag.Bottom) != 0)
{
float dy = eventData.delta.y;
float newSz = Mathf.Max(rtsize.y - dy, props.minsizeWindow.y);
dy = newSz - rtsize.y;
rtsize.y += dy;
}
if((drag & FrameDrag.Left) != 0)
{
float dx = eventData.delta.x;
float newSz = Mathf.Max(rtsize.x - dx, props.minsizeWindow.x);
dx = rtsize.x - newSz;
rtpos.x += dx;
rtsize.x -= dx;
}
else if((drag & FrameDrag.Right) != 0)
{
float dx = eventData.delta.x;
float newSz = Mathf.Max(rtsize.x + dx, props.minsizeWindow.x);
dx = newSz - rtsize.x;
rtsize.x += dx;
}
this.rectTransform.anchoredPosition = rtpos;
this.rectTransform.sizeDelta = rtsize;
this.PlaceContentWin();
}
this.UpdateShadow();
}
/// <summary>
/// Unity interface method for clicking the mouse down.
/// </summary>
void UnityEngine.EventSystems.IPointerDownHandler.OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData)
{
dragWindow = this;
localDragStart = this.transform.worldToLocalMatrix.MultiplyPoint(eventData.position);
DockProps props = system.props;
DockProps.WindowSetting winSetting = this.GetWindowSetting();
Vector2 sz = this.rectTransform.rect.size;
drag = FrameDrag.None;
this.system.HandleWindowMouseDown(this, eventData);
if (this.style == DockProps.WinType.Float)
{
if (localDragStart.y >= -props.winPadding)
drag |= FrameDrag.Top;
else if(localDragStart.y <= -sz.y + props.winPadding)
drag |= FrameDrag.Bottom;
if(localDragStart.x <= props.winPadding)
drag |= FrameDrag.Left;
else if(localDragStart.x >= sz.x - props.winPadding)
drag |= FrameDrag.Right;
}
if(
drag == FrameDrag.None &&
localDragStart.y >= -winSetting.titlebarHeight)
{
drag = FrameDrag.Position;
}
}
/// <summary>
/// Unity interface method for release the mouse click.
/// </summary>
void UnityEngine.EventSystems.IPointerUpHandler.OnPointerUp(UnityEngine.EventSystems.PointerEventData eventData)
{
if(eventData.dragging == false)
{
drag = FrameDrag.None;
dragWindow = null;
}
}
/// <summary>
/// Unity interface method for clicking.
/// </summary>
void UnityEngine.EventSystems.IPointerClickHandler.OnPointerClick(UnityEngine.EventSystems.PointerEventData eventData)
{
if(this.Locked == true)
return;
if(this.style == DockProps.WinType.Borderless || this.style == DockProps.WinType.BorderlessTabChild)
return;
// The only thing we check here ATM is double clicking
// in the titlebar area.
float dCR = this.system.props.doubleClickRate;
DockProps.WindowSetting winSetting = this.GetWindowSetting();
if (localDragStart.y >= -winSetting.titlebarHeight)
{
if(lastClickWin != this)
{
lastClickWin = this;
lastClickTime = Time.time;
}
else if(Time.time > lastClickTime + dCR)
ResetDoubleClick();
else
{
if(this.system.IsMaximized(this) == true)
this.system.RestoreWindow(this);
else
this.system.MaximizeWindow(this);
ResetDoubleClick();
}
}
else
ResetDoubleClick();
}
/// <summary>
/// Called on the window when changed to be maximized.
/// </summary>
public void NotifyMaximized()
{
this.ChangeStyle(DockProps.WinType.Maximized);
if(this.btnPin.plate != null)
this.btnPin.plate.gameObject.SetActive(false);
this._SetRestoreButton();
}
/// <summary>
/// Called on the window when changed to be floating.
/// </summary>
public void NotifyFloating(bool forceStyle = false)
{
this.ChangeStyle(DockProps.WinType.Float, true, forceStyle);
if (this.btnPin.plate != null)
this.btnPin.plate.gameObject.SetActive(false);
this._SetMaximizeButton();
}
/// <summary>
/// Called on the window when changed to be docked.
/// </summary>
public void NotifyDocked()
{
if (this.btnPin.plate != null)
this.btnPin.plate.gameObject.SetActive(true);
this._SetMaximizeButton();
if((this.flags & Flag.LockedFrame) != 0)
this.ChangeStyle(DockProps.WinType.Borderless);
else
this.ChangeStyle(DockProps.WinType.Docked);
}
/// <summary>
/// Change the visual style of the window.
/// </summary>
/// <param name="winType">The window style to change to.</param>
/// <param name="placeContent">If true, PlaceContent() will be called afterwards.</param>
/// <param name="forceStyle">If true, setting the style is forced, even if it's detected to be redundant.</param>
public void ChangeStyle(DockProps.WinType winType, bool placeContent = true, bool forceStyle = false)
{
if(this.style == winType && forceStyle == false)
return;
this.style = winType;
if( winType == DockProps.WinType.BorderlessTabChild ||
winType == DockProps.WinType.Borderless)
{
this.titlebar.gameObject.SetActive(false);
this.PlaceContentBorderless();
}
else
{
DockProps.WindowSetting ws = this.GetWindowSetting();
this.sprite = ws.spriteFrame.sprite;
this.color = ws.spriteFrame.color;
if(this.btnClose.plate != null)
ws.spriteBtnPlate.ApplySliced(this.btnClose.plate);
if(this.btnPin.plate != null)
ws.spriteBtnPlate.ApplySliced(this.btnPin.plate);
if(this.btnRestMax.plate != null)
ws.spriteBtnPlate.ApplySliced(this.btnRestMax.plate);
this.titlebar.gameObject.SetActive(true);
if (placeContent == true)
this.PlaceContentWin();
}
}
/// <summary>
/// Set the maximize/restore button have to have maximize icon.
/// </summary>
void _SetMaximizeButton()
{
if(this.btnRestMax.icon != null)
{
this.system.props.spriteBtnMax.ApplySimple(this.btnRestMax.icon);
}
}
/// <summary>
/// Set the maximize/restore button to have the restore icon.
/// </summary>
void _SetRestoreButton()
{
if(this.btnRestMax.icon != null)
{
this.system.props.spriteBtnRestore.ApplySimple(this.btnRestMax.icon);
}
}
public void ToggleGameObject(bool state)
{
if(state == false)
{
this.gameObject.SetActive(false);
if(this.shadow != null)
this.shadow.gameObject.SetActive(false);
}
else
{
this.gameObject.SetActive(true);
if (this.shadow != null && this.style == DockProps.WinType.Float)
this.shadow.gameObject.SetActive(true);
}
}
}
}