public void Start(WidgetGroup widgetGroup) { Point2d newMousePosition = GetMousePosition(); m_rootWidgetGroup = widgetGroup; m_mousePosition.Set(newMousePosition.x, newMousePosition.y); m_mouseOverIWidget = m_rootWidgetGroup.FindChildIWidgetContainingPoint(m_mousePosition); m_mouseIsDragging = false; m_mouseWasDown = Input.GetMouseButton((int)eMouseButton.left); if (Debug.isDebugBuild) { DebugRegistry.SetToggle("ui.event.log", false); } }
private void OnMouseMove(float newMouseX, float newMouseY) { float mouseDeltaX = newMouseX - m_mousePosition.x; float mouseDeltaY = newMouseY - m_mousePosition.y; //Debug.Log("Mouse: " + newMouseX.ToString() + ", " + newMouseY.ToString()); m_mousePosition.Set(newMouseX, newMouseY); // Notify the widget of a drag event if (m_mouseOverIWidget != null) { if (m_mouseIsDragging) { if (LogEnabled) { Debug.Log("[MouseDrag] on Widget " + m_mouseOverIWidget.GetType().Name); } (m_mouseOverIWidget as IWidgetEventListener).OnWidgetEvent( new WidgetEvent( WidgetEvent.eEventType.mouseDrag, m_mouseOverIWidget, new WidgetEvent.MouseDragEventParameters { deltaX = mouseDeltaX, deltaY = mouseDeltaY })); } else { if (LogEnabled) { Debug.Log("[MouseMove] on Widget " + m_mouseOverIWidget.GetType().Name); } (m_mouseOverIWidget as IWidgetEventListener).OnWidgetEvent( new WidgetEvent( WidgetEvent.eEventType.mouseMove, m_mouseOverIWidget, new WidgetEvent.MouseMoveEventParameters { deltaX = mouseDeltaX, deltaY = mouseDeltaY })); } } { IWidget newMouseOverWidget = m_rootWidgetGroup.FindChildIWidgetContainingPoint(m_mousePosition); // See if we have moved over a new widget if (newMouseOverWidget != m_mouseOverIWidget) { // Notify the old widget the cursor left if (m_mouseOverIWidget != null) { if (LogEnabled) { Debug.Log("[MouseOut] on Widget " + m_mouseOverIWidget.GetType().Name); } (m_mouseOverIWidget as IWidgetEventListener).OnWidgetEvent( new WidgetEvent( WidgetEvent.eEventType.mouseOut, m_mouseOverIWidget, null)); } // Notify the new mouse over widget we entered if (newMouseOverWidget != null) { if (LogEnabled) { Debug.Log("[MouseOver] on Widget " + newMouseOverWidget.GetType().Name); } (newMouseOverWidget as IWidgetEventListener).OnWidgetEvent( new WidgetEvent( WidgetEvent.eEventType.mouseOver, newMouseOverWidget, null)); } // Remember the new mouse over widget m_mouseOverIWidget = newMouseOverWidget; } } }