protected override void OnDrag(UserAction action) { }
/// <summary> /// 复制事件 /// </summary> /// <param name="action"></param> /// <param name="FormSize"></param> public void CopyAction(UserAction action, Vector2 FormSize) { LastPosition = CanPosition; IsActive = true; MouseWheelDelta = action.MouseWheelDelta; if (MouseWheelDelta != 0) { IsMouseWheel = true; } else { IsMouseWheel = false; } IsLeftButtonDown = action.IsLeftButtonDown; IsRightButtonDown = action.IsRightButtonDown; IsMiddleButtonDown = action.IsMiddleButtonDown; IsLeftButtonUp = action.IsLeftButtonUp; IsRightButtonUp = action.IsRightButtonUp; IsMiddleButtonUp = action.IsMiddleButtonUp; isPressed = action.isPressed; IsRightPressed = action.IsRightPressed; IsMiddlePressed = action.IsMiddlePressed; if (IsLeftButtonDown | IsRightButtonDown | IsMiddleButtonDown) { EventTicks = Ticks; PressTime = 0; rawPosition = action.rawPosition; } else { PressTime += TimeSlice; } IsMoved = false; float x = action.Position.x; Motion.x = x - Position.x; if (Motion.x != 0) { IsMoved = true; } Position.x = x; float y = action.Position.y; Motion.y = y - Position.y; if (Motion.y != 0) { IsMoved = true; } Position.y = y; x = FormSize.x; x *= 0.5f; y = FormSize.y; y *= 0.5f; CanPosition.x = Position.x - x; CanPosition.y = Position.y - y; FramePos[Frame].x = Position.x; FramePos[Frame].y = Position.y; FramePos[Frame].z = TimeSlice; CalculVelocities(); Frame++; if (Frame >= 16) { Frame = 0; } }
protected override void OnMouseUp(UserAction action) { }
/// <summary> /// /// </summary> /// <param name="pipeLine">所有UI</param> /// <param name="index"></param> /// <param name="pos">父级位置</param> /// <param name="scale">父级大小</param> /// <param name="quate">父级旋转</param> /// <param name="action">用户操作指令</param> /// <returns></returns> static bool DispatchEvent(HGUIElement[] pipeLine, int index, Vector3 pos, Vector3 scale, Quaternion quate, UserAction action) { if (!pipeLine[index].active) { return(false); } Vector3 p = quate * pipeLine[index].localPosition; Vector3 o = Vector3.zero; o.x = p.x * scale.x; o.y = p.y * scale.y; o.z = p.z * scale.z; o += pos; Vector3 s = pipeLine[index].localScale; Quaternion q = quate * pipeLine[index].localRotation; s.x *= scale.x; s.y *= scale.y; var script = pipeLine[index].script; if (script != null) { var ue = script.userEvent; if (ue == null) { int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, o, s, q, action)) { return(true); } } } } else if (ue.forbid) { int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, o, s, q, action)) { return(true); } } } } else { ue.pgs = scale; ue.GlobalScale = s; ue.GlobalPosition = o; ue.GlobalRotation = q; bool inside = false; float w = (script.SizeDelta.x + ue.BoxAdjuvant.x) * s.x; float h = (script.SizeDelta.y + ue.BoxAdjuvant.y) * s.y; if (ue.IsCircular) { float x = action.CanPosition.x - o.x; float y = action.CanPosition.y - o.y; w *= 0.5f; if (x * x + y * y < w * w) { inside = true; } } else { float px = script.Pivot.x; float py = script.Pivot.y; float lx = -px * w; float rx = lx + w; float dy = -py * h; float ty = dy + h; var v = action.CanPosition; var Rectangular = ue.Rectangular; Rectangular[0] = q * new Vector3(lx, dy) + o; Rectangular[1] = q * new Vector3(lx, ty) + o; Rectangular[2] = q * new Vector3(rx, ty) + o; Rectangular[3] = q * new Vector3(rx, dy) + o; inside = huqiang.Physics2D.DotToPolygon(Rectangular, v); } if (inside) { action.CurrentEntry.Add(ue); int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, o, s, q, action)) { if (ue.ForceEvent) { if (!ue.forbid) { break; } } return(true); } } } if (action.IsLeftButtonDown | action.IsRightButtonDown | action.IsMiddleButtonDown) { ue.OnMouseDown(action); } else if (action.IsLeftButtonUp | action.IsRightButtonUp | action.IsMiddleButtonUp) { ue.OnMouseUp(action); } else { ue.OnMouseMove(action); } if (ue.Penetrate) { return(false); } return(true); } else if (!ue.CutRect) { int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, o, s, q, action)) { return(true); } } } } } } else { int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, o, s, q, action)) { return(true); } } } } return(false); }
/// <summary> /// 派发用户事件 /// </summary> /// <param name="pipeLine">所有UI</param> /// <param name="index"></param> /// <param name="pos">父级位置</param> /// <param name="scale">父级大小</param> /// <param name="quate">父级旋转</param> /// <param name="action">用户操作指令</param> /// <returns></returns> static bool DispatchEvent(HGUIElement[] pipeLine, int index, UserAction action) { if (!pipeLine[index].active) { return(false); } int pi = pipeLine[index].parentIndex; Vector3 o = pipeLine[index].Position; Vector3 scale = pipeLine[index].Scale; Quaternion q = pipeLine[index].Rotation; var script = pipeLine[index].script; if (script != null) { var ue = script.userEvent; if (ue == null) { int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, action)) { return(true); } } } } else if (ue.forbid) { int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, action)) { return(true); } } } } else { ue.pgs = pipeLine[pi].Scale; ue.GlobalScale = scale; ue.GlobalPosition = o; ue.GlobalRotation = q; bool inside = false; if (ue.collider != null) { inside = ue.collider.InThere(script, ue, action.CanPosition); } if (inside) { action.CurrentEntry.Add(ue); int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, action)) { if (ue.ForceEvent) { if (!ue.forbid) { break; } } return(true); } } } if (action.IsLeftButtonDown | action.IsRightButtonDown | action.IsMiddleButtonDown) { ue.OnMouseDown(action); } else if (action.IsLeftButtonUp | action.IsRightButtonUp | action.IsMiddleButtonUp) { ue.OnMouseUp(action); } else { ue.OnMouseMove(action); } if (ue.Penetrate) { return(false); } return(true); } else if (!ue.CutRect) { int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, action)) { return(true); } } } } } } else { int c = pipeLine[index].childCount; if (c > 0) { int os = pipeLine[index].childOffset + c; for (int i = 0; i < c; i++) { os--; if (DispatchEvent(pipeLine, os, action)) { return(true); } } } } return(false); }
internal override void OnClick(UserAction action) { base.OnClick(action); input.OnClick(action); }
internal override void OnLostFocus(UserAction action) { base.OnLostFocus(action); input.OnLostFocus(action); }
public static int GetPressIndex(TextInfo info, EventCallBack callBack, UserAction action, ref int dock) { dock = 0; if (info == null) { return(0); } if (info.text == "" | info.text == null) { return(0); } IList <UILineInfo> lines = info.filterLines; if (lines == null) { return(0); } IList <UIVertex> verts = info.filterVertex; float lx = verts[0].position.x; float ty = verts[0].position.y; float dy = verts[verts.Count - 1].position.y; var pos = callBack.GlobalPosition; var scale = callBack.GlobalScale; float mx = action.CanPosition.x - pos.x; mx *= scale.x; float my = action.CanPosition.y - pos.y; my *= scale.y; int r = 0;//行 if (my < ty) { if (my < dy) { r = lines.Count - 1; } else { for (int i = lines.Count - 1; i >= 0; i--) { if (my < lines[i].topY) { r = i; break; } } } } if (mx > lx) { int s = lines[r].startCharIdx; int index = s * 4; int end = verts.Count - index; float ox = verts[index].position.x; for (int i = 0; i < end; i += 4) { float tx = verts[index].position.x; if (tx <ox | tx> mx) { index -= 4; goto lable; } ox = tx; index += 4; } info.lineIndex = info.visibleCount - lines[lines.Count - 1].startCharIdx; return(info.visibleCount); lable :; float ax = verts[index].position.x; float bx = verts[index + 2].position.x; float cx = ax + (bx - ax) * 0.5f; index /= 4; if (mx > cx)//靠右 { index++; dock = 1; } info.lineIndex = index - lines[r].startCharIdx; return(index); } else { info.lineIndex = 0; return(lines[r].startCharIdx); } }
public override void OnMouseDown(UserAction action) { base.OnMouseDown(action); input.OnMouseDown(action); }
protected override void OnDrag(UserAction action) { if (Pressed) { if (TextCom != null) { if (action.Motion != Vector2.zero) { textInfo.CaretStyle = 2; int end = textInfo.endSelect; textInfo.endSelect = GetPressIndex(textInfo, this, action, ref textInfo.endDock) + textInfo.StartIndex; if (end != textInfo.endSelect) { Selected(); if (OnSelectChanged != null) { OnSelectChanged(this, action); } selectChanged = true; } } else if (!entry) { float oy = action.CanPosition.y - GlobalPosition.y; float py = GlobalScale.y * TextCom.model.data.sizeDelta.y * 0.5f; if (oy > 0) { oy -= py; } else { oy += py; } if (oy > overDistance) { oy = overDistance; } float per = 50000 / oy; if (per < 0) { per = -per; } overTime += UserAction.TimeSlice; if (overTime >= per) { overTime -= per; if (oy > 0) { textInfo.StartLine--; } else { textInfo.StartLine++; } int end = textInfo.endSelect; textInfo.endSelect = GetPressIndex(textInfo, this, action, ref textInfo.endDock) + textInfo.StartIndex; if (end != textInfo.endSelect) { Selected(); if (OnSelectChanged != null) { OnSelectChanged(this, action); } selectChanged = true; } lineChanged = true; if (LineChanged != null) { LineChanged(this); } } } } } base.OnDrag(action); }
public static bool DispatchEvent(ModelElement ui, Vector3 pos, Vector3 scale, Quaternion quate, UserAction action) { if (ui == null) { return(false); } if (!ui.activeSelf) { return(false); } Vector3 p = quate * ui.data.localPosition; Vector3 o = Vector3.zero; o.x = p.x * scale.x; o.y = p.y * scale.y; o.z = p.z * scale.z; o += pos; Vector3 s = ui.data.localScale; Quaternion q = ui.data.localRotation * quate; s.x *= scale.x; s.y *= scale.y; var callBack = ui.baseEvent; if (callBack == null) { var child = ui.child; for (int i = child.Count - 1; i >= 0; i--) { if (DispatchEvent(child[i], o, s, q, action)) { return(true); } } } else if (callBack.forbid) { var child = ui.child; for (int i = child.Count - 1; i >= 0; i--) { if (DispatchEvent(child[i], o, s, q, action)) { return(true); } } } else { callBack.pgs = scale; callBack.GlobalScale = s; callBack.GlobalPosition = o; callBack.GlobalRotation = q; bool inside = false; float w, h; if (callBack.UseAssignSize) { w = callBack.boxSize.x * s.x; h = callBack.boxSize.y * s.y; } else { w = ui.data.sizeDelta.x * s.x; h = ui.data.sizeDelta.y * s.y; } if (callBack.IsCircular) { float x = action.CanPosition.x - o.x; float y = action.CanPosition.y - o.y; w *= 0.5f; if (x * x + y * y < w * w) { inside = true; } } else { float x1 = 0.5f * w; float x0 = -x1; float y1 = 0.5f * h; float y0 = -y1; var v = action.CanPosition; var Rectangular = callBack.Rectangular; Rectangular[0] = q * new Vector3(x0, y0) + o; Rectangular[1] = q * new Vector3(x0, y1) + o; Rectangular[2] = q * new Vector3(x1, y1) + o; Rectangular[3] = q * new Vector3(x1, y0) + o; inside = Physics2D.DotToPolygon(Rectangular, v); } if (inside) { action.CurrentEntry.Add(callBack); var child = ui.child; for (int i = child.Count - 1; i >= 0; i--) { if (DispatchEvent(child[i], o, s, q, action)) { if (callBack.ForceEvent) { if (!callBack.forbid) { break; } } return(true); } } if (action.IsLeftButtonDown | action.IsRightButtonDown | action.IsMiddleButtonDown) { callBack.OnMouseDown(action); } else if (action.IsLeftButtonUp | action.IsRightButtonUp | action.IsMiddleButtonUp) { callBack.OnMouseUp(action); } else { callBack.OnMouseMove(action); } if (callBack.Penetrate) { return(false); } return(true); } else if (!callBack.CutRect) { var child = ui.child; for (int i = child.Count - 1; i >= 0; i--) { if (DispatchEvent(child[i], o, s, q, action)) { return(true); } } } } return(false); }
protected override void OnDrag(UserAction action) { if (Pressed) { if (TextCom != null) { Style = 2; if (action.Motion != Vector2.zero) { var p = GetPressIndex(action, action.CanPosition - RawPosition); if (p.Offset != EndPress.Offset | p.Row != EndPress.Row) { ShowChanged = true; } EndPress = p; } else if (!entry) { float oy = action.CanPosition.y - GlobalPosition.y; float py = GlobalScale.y * TextCom.SizeDelta.y * 0.5f; if (oy > 0) { oy -= py; } else { oy += py; } if (oy > overDistance) { oy = overDistance; } float per = 5000 / oy; if (per < 0) { per = -per; } overTime += UserAction.TimeSlice; if (overTime >= per) { overTime -= per; if (oy > 0) { MoveUp(); } else { MoveDown(); } var p = GetPressIndex(action, action.CanPosition - RawPosition); if (p.Offset != EndPress.Offset | p.Row != EndPress.Row) { ShowChanged = true; } EndPress = p; } } } } base.OnDrag(action); }
internal override void OnLostFocus(UserAction eventCall) { Style = 0; InputCaret.Hide(); Focus = false; }
internal override void OnClick(UserAction action) { Style = 0; InputCaret.Hide(); }