internal static EventBase CreateEvent(Event systemEvent) { switch (systemEvent.type) { case EventType.MouseMove: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDrag: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDown: return(MouseDownEvent.GetPooled(systemEvent)); case EventType.MouseUp: return(MouseUpEvent.GetPooled(systemEvent)); case EventType.ScrollWheel: return(WheelEvent.GetPooled(systemEvent)); case EventType.KeyDown: return(KeyDownEvent.GetPooled(systemEvent)); case EventType.KeyUp: return(KeyUpEvent.GetPooled(systemEvent)); case EventType.MouseEnterWindow: return(MouseEnterWindowEvent.GetPooled(systemEvent)); case EventType.MouseLeaveWindow: return(MouseLeaveWindowEvent.GetPooled(systemEvent)); default: return(IMGUIEvent.GetPooled(systemEvent)); } }
public override void ExecuteDefaultActionAtTarget(EventBase evt) { base.ExecuteDefaultActionAtTarget(evt); if (evt.GetEventTypeId() == MouseDownEvent.TypeId()) { OnMouseDown(evt as MouseDownEvent); } else if (evt.GetEventTypeId() == MouseUpEvent.TypeId()) { OnMouseUp(evt as MouseUpEvent); } else if (evt.GetEventTypeId() == MouseMoveEvent.TypeId()) { OnMouseMove(evt as MouseMoveEvent); } else if (evt.GetEventTypeId() == KeyDownEvent.TypeId()) { OnKeyDown(evt as KeyDownEvent); } else if (evt.GetEventTypeId() == IMGUIEvent.TypeId()) { OnIMGUIEvent(evt as IMGUIEvent); } }
internal void Dispatch(EventBase evt, IPanel panel, DispatchMode dispatchMode) { evt.MarkReceivedByDispatcher(); if (evt.GetEventTypeId() == IMGUIEvent.TypeId()) { Event e = evt.imguiEvent; if (e.type == EventType.Repaint) { return; } } if (dispatchImmediately || (dispatchMode == DispatchMode.Immediate)) { ProcessEvent(evt, panel); } else { evt.Acquire(); m_Queue.Enqueue(new EventRecord { m_Event = evt, m_Panel = panel }); } }
// In order for tests to run without an EditorWindow but still be able to send // events, we sometimes need to force the event type. IMGUI::GetEventType() (native) will // return the event type as Ignore if the proper views haven't yet been // initialized. This (falsely) breaks tests that rely on the event type. So for tests, we // just ensure the event type is what we originally set it to when we sent it. internal static EventBase CreateEvent(Event systemEvent, EventType eventType) { switch (eventType) { case EventType.MouseMove: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDrag: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDown: return(MouseDownEvent.GetPooled(systemEvent)); case EventType.MouseUp: return(MouseUpEvent.GetPooled(systemEvent)); case EventType.ContextClick: return(ContextClickEvent.GetPooled(systemEvent)); case EventType.MouseEnterWindow: return(MouseEnterWindowEvent.GetPooled(systemEvent)); case EventType.MouseLeaveWindow: return(MouseLeaveWindowEvent.GetPooled(systemEvent)); case EventType.ScrollWheel: return(WheelEvent.GetPooled(systemEvent)); case EventType.KeyDown: return(KeyDownEvent.GetPooled(systemEvent)); case EventType.KeyUp: return(KeyUpEvent.GetPooled(systemEvent)); case EventType.DragUpdated: return(DragUpdatedEvent.GetPooled(systemEvent)); case EventType.DragPerform: return(DragPerformEvent.GetPooled(systemEvent)); case EventType.DragExited: return(DragExitedEvent.GetPooled(systemEvent)); case EventType.ValidateCommand: return(ValidateCommandEvent.GetPooled(systemEvent)); case EventType.ExecuteCommand: return(ExecuteCommandEvent.GetPooled(systemEvent)); default: // Layout, Ignore, Used return(IMGUIEvent.GetPooled(systemEvent)); } }
internal static EventBase CreateEvent(Event systemEvent) { EventBase pooled; switch (systemEvent.type) { case EventType.MouseDown: pooled = MouseEventBase <MouseDownEvent> .GetPooled(systemEvent); break; case EventType.MouseUp: pooled = MouseEventBase <MouseUpEvent> .GetPooled(systemEvent); break; case EventType.MouseMove: pooled = MouseEventBase <MouseMoveEvent> .GetPooled(systemEvent); break; case EventType.MouseDrag: pooled = MouseEventBase <MouseMoveEvent> .GetPooled(systemEvent); break; case EventType.KeyDown: pooled = KeyboardEventBase <KeyDownEvent> .GetPooled(systemEvent); break; case EventType.KeyUp: pooled = KeyboardEventBase <KeyUpEvent> .GetPooled(systemEvent); break; case EventType.ScrollWheel: pooled = WheelEvent.GetPooled(systemEvent); break; default: pooled = IMGUIEvent.GetPooled(systemEvent); break; } return(pooled); }
public void DispatchEvent(EventBase evt, IPanel panel) { if (evt.GetEventTypeId() == IMGUIEvent.TypeId()) { Event e = evt.imguiEvent; if (e.type == EventType.Repaint) { return; } } if (panel != null && panel.panelDebug != null && panel.panelDebug.enabled && panel.panelDebug.interceptEvents != null) { if (panel.panelDebug.interceptEvents(evt.imguiEvent)) { evt.StopPropagation(); return; } } IMouseEvent mouseEvent = evt as IMouseEvent; IMouseEventInternal mouseEventInternal = evt as IMouseEventInternal; if (mouseEvent != null && mouseEventInternal != null && mouseEventInternal.hasUnderlyingPhysicalEvent) { m_LastMousePosition = mouseEvent.mousePosition; } bool eventHandled = false; // Release mouse capture if capture element is not in a panel. VisualElement captureVE = MouseCaptureController.mouseCapture as VisualElement; if (evt.GetEventTypeId() != MouseCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { Event e = evt.imguiEvent; Debug.Log(String.Format("Capture has no panel, forcing removal (capture={0} eventType={1})", MouseCaptureController.mouseCapture, e != null ? e.type.ToString() : "null")); MouseCaptureController.ReleaseMouseCapture(); } // Send all IMGUI events (for backward compatibility) and MouseEvents with null target (because thats what we want to do in the new system) // to the capture, if there is one. Note that events coming from IMGUI have their target set to null. bool sendEventToMouseCapture = false; bool mouseEventWasCaptured = false; if (MouseCaptureController.mouseCapture != null) { if (evt.imguiEvent != null && evt.target == null) { // Non exclusive processing by capturing element. sendEventToMouseCapture = true; mouseEventWasCaptured = false; } if (mouseEvent != null && (evt.target == null || evt.target == MouseCaptureController.mouseCapture)) { // Exclusive processing by capturing element. sendEventToMouseCapture = true; mouseEventWasCaptured = true; } if (panel != null) { if (captureVE != null && captureVE.panel.contextType != panel.contextType) { // Capturing element is not in the right context. Ignore it. sendEventToMouseCapture = false; mouseEventWasCaptured = false; } } } evt.skipElement = null; if (sendEventToMouseCapture) { IEventHandler originalCaptureElement = MouseCaptureController.mouseCapture; eventHandled = true; evt.dispatch = true; evt.target = MouseCaptureController.mouseCapture; evt.currentTarget = MouseCaptureController.mouseCapture; evt.propagationPhase = PropagationPhase.AtTarget; MouseCaptureController.mouseCapture.HandleEvent(evt); // Do further processing with a target computed the usual way. // However, if mouseEventWasCaptured, the only thing remaining to do is ExecuteDefaultAction, // which whould be done with mouseCapture as the target. if (!mouseEventWasCaptured) { evt.target = null; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; // Do not call HandleEvent again for this element. evt.skipElement = originalCaptureElement; } if (!mouseEventWasCaptured && !evt.isPropagationStopped) { if (evt is IKeyboardEvent && panel != null) { eventHandled = true; if (panel.focusController.focusedElement != null) { IMGUIContainer imguiContainer = panel.focusController.focusedElement as IMGUIContainer; if (imguiContainer != null) { // THINK ABOUT THIS PF: shoudln't we allow for the capture dispatch phase? if (imguiContainer != evt.skipElement && imguiContainer.HandleIMGUIEvent(evt.imguiEvent)) { evt.StopPropagation(); evt.PreventDefault(); } } else { evt.target = panel.focusController.focusedElement; PropagateEvent(evt); } } else { evt.target = panel.visualTree; PropagateEvent(evt); if (!evt.isPropagationStopped) { PropagateToIMGUIContainer(panel.visualTree, evt); } } } else if (mouseEvent != null) { // FIXME: we should not change hover state when capture is true. // However, when doing drag and drop, drop target should be highlighted. // TODO when EditorWindow is docked MouseLeaveWindow is not always sent // this is a problem in itself but it could leave some elements as "hover" if (evt.GetEventTypeId() == MouseLeaveWindowEvent.TypeId()) { VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse; m_TopElementUnderMouse = null; DispatchMouseEnterMouseLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); DispatchMouseOverMouseOut(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } else if (evt.GetEventTypeId() == DragExitedEvent.TypeId()) { VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse; m_TopElementUnderMouse = null; DispatchDragEnterDragLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } // update element under mouse and fire necessary events else { VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse; if (evt.target == null && panel != null) { m_TopElementUnderMouse = panel.Pick(mouseEvent.mousePosition); evt.target = m_TopElementUnderMouse; } if (evt.target != null) { eventHandled = true; PropagateEvent(evt); } if (evt.GetEventTypeId() == MouseMoveEvent.TypeId() || evt.GetEventTypeId() == MouseDownEvent.TypeId() || evt.GetEventTypeId() == MouseUpEvent.TypeId() || evt.GetEventTypeId() == MouseEnterWindowEvent.TypeId() || evt.GetEventTypeId() == WheelEvent.TypeId()) { DispatchMouseEnterMouseLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); DispatchMouseOverMouseOut(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } else if (evt.GetEventTypeId() == DragUpdatedEvent.TypeId()) { DispatchDragEnterDragLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } } } else if (panel != null && evt is ICommandEvent) { IMGUIContainer imguiContainer = panel.focusController.focusedElement as IMGUIContainer; eventHandled = true; if (imguiContainer != null) { if (imguiContainer != evt.skipElement && imguiContainer.HandleIMGUIEvent(evt.imguiEvent)) { evt.StopPropagation(); evt.PreventDefault(); } } else if (panel.focusController.focusedElement != null) { evt.target = panel.focusController.focusedElement; PropagateEvent(evt); } else { PropagateToIMGUIContainer(panel.visualTree, evt); } } else if (evt is IPropagatableEvent || evt is IFocusEvent || evt is IChangeEvent || evt.GetEventTypeId() == InputEvent.TypeId() || evt.GetEventTypeId() == GeometryChangedEvent.TypeId()) { Debug.Assert(evt.target != null); eventHandled = true; PropagateEvent(evt); } } if (!mouseEventWasCaptured && !evt.isPropagationStopped && panel != null) { Event e = evt.imguiEvent; if (!eventHandled || (e != null && e.type == EventType.Used) || evt.GetEventTypeId() == MouseEnterWindowEvent.TypeId() || evt.GetEventTypeId() == MouseLeaveWindowEvent.TypeId()) { PropagateToIMGUIContainer(panel.visualTree, evt); } } if (evt.target == null && panel != null) { evt.target = panel.visualTree; } ExecuteDefaultAction(evt); }
private void OnIMGUIEvent(IMGUIEvent evt) { if (base.textInputField.hasFocus) { base.textInputField.SyncTextEngine(); this.m_Changed = false; EventType type = evt.imguiEvent.type; if (type != EventType.ValidateCommand) { if (type == EventType.ExecuteCommand) { bool flag = false; string text = base.editorEngine.text; if (!base.textInputField.hasFocus) { return; } string commandName = evt.imguiEvent.commandName; if (commandName != null) { if (commandName == "OnLostFocus") { evt.StopPropagation(); return; } if (!(commandName == "Cut")) { if (commandName == "Copy") { base.editorEngine.Copy(); evt.StopPropagation(); return; } if (!(commandName == "Paste")) { if (commandName == "SelectAll") { base.editorEngine.SelectAll(); evt.StopPropagation(); return; } if (commandName == "Delete") { if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX) { base.editorEngine.Delete(); } else { base.editorEngine.Cut(); } flag = true; } } else { base.editorEngine.Paste(); flag = true; } } else { base.editorEngine.Cut(); flag = true; } } if (flag) { if (text != base.editorEngine.text) { this.m_Changed = true; } evt.StopPropagation(); } } } else { string commandName2 = evt.imguiEvent.commandName; if (commandName2 != null) { if (!(commandName2 == "Cut") && !(commandName2 == "Copy")) { if (!(commandName2 == "Paste")) { if (!(commandName2 == "SelectAll") && !(commandName2 == "Delete")) { if (!(commandName2 == "UndoRedoPerformed")) { } } } else if (!base.editorEngine.CanPaste()) { return; } } else if (!base.editorEngine.hasSelection) { return; } } evt.StopPropagation(); } if (this.m_Changed) { base.editorEngine.text = base.textInputField.CullString(base.editorEngine.text); base.textInputField.UpdateText(base.editorEngine.text); evt.StopPropagation(); } base.editorEngine.UpdateScrollOffset(); } }
void OnIMGUIEvent(IMGUIEvent evt) { if (!textInputField.hasFocus) { return; } textInputField.SyncTextEngine(); m_Changed = false; switch (evt.imguiEvent.type) { case EventType.ValidateCommand: switch (evt.imguiEvent.commandName) { case EventCommandNames.Cut: case EventCommandNames.Copy: if (!editorEngine.hasSelection) { return; } break; case EventCommandNames.Paste: if (!editorEngine.CanPaste()) { return; } break; case EventCommandNames.SelectAll: case EventCommandNames.Delete: break; case EventCommandNames.UndoRedoPerformed: // TODO: ????? editor.text = text; --> see EditorGUI's DoTextField break; } evt.StopPropagation(); break; case EventType.ExecuteCommand: bool mayHaveChanged = false; string oldText = editorEngine.text; if (!textInputField.hasFocus) { return; } switch (evt.imguiEvent.commandName) { case EventCommandNames.OnLostFocus: evt.StopPropagation(); return; case EventCommandNames.Cut: editorEngine.Cut(); mayHaveChanged = true; break; case EventCommandNames.Copy: editorEngine.Copy(); evt.StopPropagation(); return; case EventCommandNames.Paste: editorEngine.Paste(); mayHaveChanged = true; break; case EventCommandNames.SelectAll: editorEngine.SelectAll(); evt.StopPropagation(); return; case EventCommandNames.Delete: // This "Delete" command stems from a Shift-Delete in the text // On Windows, Shift-Delete in text does a cut whereas on Mac, it does a delete. if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX) { editorEngine.Delete(); } else { editorEngine.Cut(); } mayHaveChanged = true; break; } if (mayHaveChanged) { if (oldText != editorEngine.text) { m_Changed = true; } evt.StopPropagation(); } break; } if (m_Changed) { editorEngine.text = textInputField.CullString(editorEngine.text); textInputField.UpdateText(editorEngine.text); evt.StopPropagation(); } // Scroll offset might need to be updated editorEngine.UpdateScrollOffset(); }
internal static EventBase CreateEvent(Event systemEvent) { EventType type = systemEvent.type; EventBase pooled; switch (type) { case EventType.MouseDown: pooled = MouseEventBase <MouseDownEvent> .GetPooled(systemEvent); break; case EventType.MouseUp: pooled = MouseEventBase <MouseUpEvent> .GetPooled(systemEvent); break; case EventType.MouseMove: pooled = MouseEventBase <MouseMoveEvent> .GetPooled(systemEvent); break; case EventType.MouseDrag: pooled = MouseEventBase <MouseMoveEvent> .GetPooled(systemEvent); break; case EventType.KeyDown: pooled = KeyboardEventBase <KeyDownEvent> .GetPooled(systemEvent); break; case EventType.KeyUp: pooled = KeyboardEventBase <KeyUpEvent> .GetPooled(systemEvent); break; case EventType.ScrollWheel: pooled = WheelEvent.GetPooled(systemEvent); break; default: if (type != EventType.MouseEnterWindow) { if (type != EventType.MouseLeaveWindow) { pooled = IMGUIEvent.GetPooled(systemEvent); } else { pooled = MouseEventBase <MouseLeaveWindowEvent> .GetPooled(systemEvent); } } else { pooled = MouseEventBase <MouseEnterWindowEvent> .GetPooled(systemEvent); } break; } return(pooled); }