// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ void HandleHotPoints(exHotPoint[] _hotPoints, bool _isMouse) { // ======================================================== // handle hover event // ======================================================== int hotPointCountForMouse = _isMouse ? 1 : _hotPoints.Length; for (int i = 0; i < hotPointCountForMouse; ++i) { exHotPoint hotPoint = _hotPoints[i]; if (hotPoint.active == false) { continue; } if (hotPoint.pressed != null && hotPoint.pressed.grabMouseOrTouch) { continue; } // get hot control exUIControl lastCtrl = hotPoint.hover; exUIControl curCtrl = PickControl(hotPoint.pos); hotPoint.hover = curCtrl; if (lastCtrl != curCtrl) { exUIPointInfo pointInfo = new exUIPointInfo(); pointInfo.id = hotPoint.id; pointInfo.pos = hotPoint.pos; pointInfo.delta = hotPoint.delta; pointInfo.worldPos = hotPoint.worldPos; pointInfo.worldDelta = hotPoint.worldDelta; exUIPointEvent pointEvent = new exUIPointEvent(); pointEvent.isMouse = hotPoint.isMouse; pointEvent.pointInfos = new exUIPointInfo [] { pointInfo }; // on hover out if (lastCtrl != null) { lastCtrl.OnHoverOut(pointEvent); } // on hover in if (curCtrl != null) { pointEvent.Reset(); curCtrl.OnHoverIn(pointEvent); if (hotPoint.isTouch) { hotPoint.pressDown = true; } } } } if (_isMouse) { for (int i = 1; i < _hotPoints.Length; ++i) { _hotPoints[i].hover = _hotPoints[0].hover; } // ======================================================== // send scroll wheel event // ======================================================== float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0.0f && _hotPoints[0].hover != null) { exUIWheelEvent wheelEvent = new exUIWheelEvent(); wheelEvent.delta = scroll; _hotPoints[0].hover.OnEXMouseWheel(wheelEvent); } } // ======================================================== // handle press down event // ======================================================== for (int i = 0; i < _hotPoints.Length; ++i) { exHotPoint hotPoint = _hotPoints[i]; if (hotPoint.active == false) { continue; } if (hotPoint.pressDown) { exUIControl curCtrl = hotPoint.hover; if (hotPoint.pressed != null && hotPoint.pressed.grabMouseOrTouch) { curCtrl = hotPoint.pressed; } // send press down event if (curCtrl != null) { exUIPointInfo pointInfo = new exUIPointInfo(); pointInfo.id = hotPoint.id; pointInfo.pos = hotPoint.pos; pointInfo.delta = hotPoint.delta; pointInfo.worldPos = hotPoint.worldPos; pointInfo.worldDelta = hotPoint.worldDelta; exUIPointEvent pointEvent = new exUIPointEvent(); pointEvent.isMouse = hotPoint.isMouse; pointEvent.pointInfos = new exUIPointInfo [] { pointInfo }; curCtrl.OnPressDown(pointEvent); } hotPoint.pressed = curCtrl; } } // ======================================================== // handle moving before press-up // ======================================================== Dictionary <exUIControl, List <exHotPoint> > moveEvents = new Dictionary <exUIControl, List <exHotPoint> >(); // collect press move event for (int i = 0; i < _hotPoints.Length; ++i) { exHotPoint hotPoint = _hotPoints[i]; if (hotPoint.active == false) { continue; } if (hotPoint.delta != Vector2.zero) { exUIControl curCtrl = hotPoint.hover; if (hotPoint.pressed != null && hotPoint.pressed.grabMouseOrTouch) { curCtrl = hotPoint.pressed; } if (curCtrl != null) { List <exHotPoint> hotPointList = null; if (moveEvents.ContainsKey(curCtrl)) { hotPointList = moveEvents[curCtrl]; } else { hotPointList = new List <exHotPoint>(); moveEvents.Add(curCtrl, hotPointList); } hotPointList.Add(hotPoint); } } } // send hot-point move event foreach (KeyValuePair <exUIControl, List <exHotPoint> > iter in moveEvents) { exUIPointEvent pointEvent = new exUIPointEvent(); pointEvent.pointInfos = new exUIPointInfo [iter.Value.Count]; for (int i = 0; i < iter.Value.Count; ++i) { exHotPoint hotPoint = iter.Value[i]; exUIPointInfo pointInfo = new exUIPointInfo(); pointInfo.id = hotPoint.id; pointInfo.pos = hotPoint.pos; pointInfo.delta = hotPoint.delta; pointInfo.worldPos = hotPoint.worldPos; pointInfo.worldDelta = hotPoint.worldDelta; pointEvent.pointInfos[i] = pointInfo; pointEvent.isMouse = hotPoint.isMouse; } iter.Key.OnHoverMove(pointEvent); } // ======================================================== // handle press up event // ======================================================== for (int i = 0; i < _hotPoints.Length; ++i) { exHotPoint hotPoint = _hotPoints[i]; if (hotPoint.active == false) { continue; } // if (hotPoint.pressUp) { exUIPointInfo pointInfo = new exUIPointInfo(); pointInfo.id = hotPoint.id; pointInfo.pos = hotPoint.pos; pointInfo.delta = hotPoint.delta; pointInfo.worldPos = hotPoint.worldPos; pointInfo.worldDelta = hotPoint.worldDelta; exUIPointEvent pointEvent = new exUIPointEvent(); pointEvent.isMouse = hotPoint.isMouse; pointEvent.pointInfos = new exUIPointInfo [] { pointInfo }; exUIControl curCtrl = hotPoint.hover; if (hotPoint.pressed != null && hotPoint.pressed.grabMouseOrTouch) { curCtrl = hotPoint.pressed; } // send press down event if (curCtrl != null) { curCtrl.OnPressUp(pointEvent); if (hotPoint.isTouch) { curCtrl.OnHoverOut(pointEvent); } } hotPoint.pressed = null; } } }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public void HoverOut(exUIControl _ctrl, int _id) { exHotPoint[] hotPoints = null; if (hasTouch || simulateMouseAsTouch) { hotPoints = touchPoints; } else { hotPoints = mousePoints; } // for (int i = 0; i < hotPoints.Length; ++i) { exHotPoint hotPoint = hotPoints[i]; if (hotPoint.active == false) { continue; } if (hotPoint.id != _id) { continue; } exUIPointInfo pointInfo = new exUIPointInfo(); pointInfo.id = hotPoint.id; pointInfo.pos = hotPoint.pos; pointInfo.delta = hotPoint.delta; pointInfo.worldPos = hotPoint.worldPos; pointInfo.worldDelta = hotPoint.worldDelta; exUIPointEvent pointEvent = new exUIPointEvent(); pointEvent.isMouse = hotPoint.isMouse; pointEvent.pointInfos = new exUIPointInfo [] { pointInfo }; // on hover out if (_ctrl != null) { _ctrl.OnHoverOut(pointEvent); } hotPoint.hover = null; // on hover in if (_ctrl.parent != null) { pointEvent.Reset(); hotPoint.hover = _ctrl.parent; _ctrl.parent.OnHoverIn(pointEvent); if (hotPoint.isTouch) { pointEvent.Reset(); hotPoint.pressed = _ctrl.parent; _ctrl.parent.OnPressDown(pointEvent); } } } }