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
|
#include "UnityPrefix.h"
#include "Runtime/IMGUI/GUIToggle.h"
#include "Runtime/IMGUI/GUIStyle.h"
#include "Runtime/IMGUI/GUIState.h"
#include "Runtime/IMGUI/IMGUIUtils.h"
namespace IMGUI
{
static const int kGUIToggleHash = -1784436876;
bool GUIToggle (GUIState &state, const Rectf &position, bool value, GUIContent &content, GUIStyle &style, int id)
{
InputEvent &evt (*state.m_CurrentEvent);
switch (GetEventTypeForControl (state, evt, id))
{
case InputEvent::kMouseDown:
// If the mouse is inside the button, we say that we're the hot control
#if ENABLE_NEW_EVENT_SYSTEM
if (position.Contains (evt.touch.pos))
#else
if (position.Contains (evt.mousePosition))
#endif
{
GrabMouseControl (state, id);
evt.Use ();
}
break;
case InputEvent::kKeyDown:
if (evt.character == 32 && state.m_MultiFrameGUIState.m_KeyboardControl == id)
{
evt.Use ();
state.m_OnGUIState.m_Changed = true;
return !value;
}
break;
case InputEvent::kMouseUp:
if (HasMouseControl (state, id))
{
ReleaseMouseControl (state);
// If we got the mousedown, the mouseup is ours as well
// (no matter if the click was in the button or not)
evt.Use ();
// toggle the passed-in value if the mouse was over the button & return true
#if ENABLE_NEW_EVENT_SYSTEM
if (position.Contains (evt.touch.pos))
#else
if (position.Contains (evt.mousePosition))
#endif
{
state.m_OnGUIState.m_Changed = true;
return !value;
}
}
break;
case InputEvent::kMouseDrag:
if (HasMouseControl (state, id))
evt.Use ();
break;
case InputEvent::kRepaint:
style.Draw (state, position, content, id, value);
break;
}
return value;
}
bool GUIToggle (GUIState &state, const Rectf &position, bool value, GUIContent &content, GUIStyle &style)
{
int id = GetControlID (state, kGUIToggleHash, kNative, position);
return GUIToggle (state, position, value, content, style, id);
}
}
|