forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopupWindowWithoutFocus.cs
More file actions
90 lines (75 loc) · 2.63 KB
/
Copy pathPopupWindowWithoutFocus.cs
File metadata and controls
90 lines (75 loc) · 2.63 KB
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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
namespace UnityEditor
{
class PopupWindowWithoutFocus : PopupWindow
{
static PopupWindowWithoutFocus s_PopupWindowWithoutFocus;
public new static void Show(Rect activatorRect, PopupWindowContent windowContent)
{
Show(activatorRect, windowContent, null);
}
internal new static void Show(Rect activatorRect, PopupWindowContent windowContent, PopupLocation[] locationPriorityOrder)
{
if (windowContent == null)
throw new System.ArgumentNullException(nameof(windowContent));
if (s_PopupWindowWithoutFocus != null)
{
s_PopupWindowWithoutFocus.CloseContent();
}
if (ShouldShowWindow(activatorRect))
{
if (s_PopupWindowWithoutFocus == null)
s_PopupWindowWithoutFocus = CreateInstance<PopupWindowWithoutFocus>();
s_PopupWindowWithoutFocus.Init(activatorRect, windowContent, locationPriorityOrder, ShowMode.PopupMenu, false);
}
else
{
windowContent.OnClose();
}
}
public static bool IsVisible()
{
return s_PopupWindowWithoutFocus != null;
}
public static void Hide()
{
if (s_PopupWindowWithoutFocus != null)
s_PopupWindowWithoutFocus.Close();
}
protected override void OnEnable()
{
base.OnEnable();
hideFlags = HideFlags.DontSave;
s_PopupWindowWithoutFocus = this;
}
protected override void OnDisable()
{
base.OnDisable();
s_PopupWindowWithoutFocus = null;
}
// Invoked from C++
static bool OnGlobalMouseOrKeyEvent(EventType type, KeyCode keyCode, Vector2 mousePosition)
{
if (s_PopupWindowWithoutFocus == null)
return false;
if (type == EventType.MouseDown && !s_PopupWindowWithoutFocus.position.Contains(mousePosition))
{
s_PopupWindowWithoutFocus.Close();
return false;
}
if (type == EventType.KeyDown && keyCode == KeyCode.Escape)
{
s_PopupWindowWithoutFocus.Close();
return true;
}
return false;
}
}
}