diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/IMGUI/GUIButton.cpp |
Diffstat (limited to 'Runtime/IMGUI/GUIButton.cpp')
-rw-r--r-- | Runtime/IMGUI/GUIButton.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Runtime/IMGUI/GUIButton.cpp b/Runtime/IMGUI/GUIButton.cpp new file mode 100644 index 0000000..d83462b --- /dev/null +++ b/Runtime/IMGUI/GUIButton.cpp @@ -0,0 +1,77 @@ +#include "UnityPrefix.h" +#include "Runtime/IMGUI/GUIButton.h" +#include "Runtime/IMGUI/GUIStyle.h" +#include "Runtime/IMGUI/GUIState.h" +#include "Runtime/IMGUI/IMGUIUtils.h" + +static const int kGUIButtonHash = 2001146706; + +namespace IMGUI +{ + +bool GUIButton (GUIState &state, const Rectf &position, 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::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 true; + } + } + break; + case InputEvent::kKeyDown: + if (evt.character == 32 && state.m_MultiFrameGUIState.m_KeyboardControl == id) + { + evt.Use (); + state.m_OnGUIState.m_Changed = true; + return true; + } + break; + case InputEvent::kMouseDrag: + if (HasMouseControl (state, id)) + evt.Use (); + break; + + case InputEvent::kRepaint: + style.Draw (state, position, content, id, false); + break; + } + return false; +} + +bool GUIButton (GUIState &state, const Rectf &position, GUIContent &content, GUIStyle &style) +{ + int id = GetControlID (state, kGUIButtonHash, kNative, position); + return GUIButton (state, position, content, style, id); +} + + +} |