public override void TouchMoved(CCTouch touch, CCEvent pEvent) { if (!Visible) { return; } if (m_pTouches.Contains(touch)) { if (m_pTouches.Count == 1 && m_bDragging) { // scrolling m_bTouchMoved = true; CCPoint frameOriginal = Parent.ConvertToWorldSpace(Position); var frame = new CCRect(frameOriginal.X, frameOriginal.Y, m_tViewSize.Width, m_tViewSize.Height); CCPoint newPoint = ConvertTouchToNodeSpace(m_pTouches[0]); CCPoint moveDistance = newPoint - m_tTouchPoint; m_tTouchPoint = newPoint; if (frame.ContainsPoint(ConvertToWorldSpace(newPoint))) { switch (m_eDirection) { case CCScrollViewDirection.Vertical: moveDistance = new CCPoint(0.0f, moveDistance.Y); break; case CCScrollViewDirection.Horizontal: moveDistance = new CCPoint(moveDistance.X, 0.0f); break; } m_pContainer.Position = m_pContainer.Position + moveDistance; CCPoint maxInset = m_fMaxInset; CCPoint minInset = m_fMinInset; //check to see if offset lies within the inset bounds float newX = Math.Min(m_pContainer.Position.X, maxInset.X); newX = Math.Max(newX, minInset.X); float newY = Math.Min(m_pContainer.Position.Y, maxInset.Y); newY = Math.Max(newY, minInset.Y); m_tScrollDistance = moveDistance - new CCPoint(newX - m_pContainer.Position.X, newY - m_pContainer.Position.Y); SetContentOffset(new CCPoint(newX, newY), false); } } else if (m_pTouches.Count == 2 && !m_bDragging) { float len = CCPoint.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]), m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1])); ZoomScale = ZoomScale * len / m_fTouchLength; } } }
/** override functions */ // optional public override bool TouchBegan(CCTouch pTouch, CCEvent pEvent) { if (!Visible) { return(false); } CCPoint frameOriginal = Parent.ConvertToWorldSpace(Position); var frame = new CCRect(frameOriginal.X, frameOriginal.Y, m_tViewSize.Width, m_tViewSize.Height); //dispatcher does not know about clipping. reject touches outside visible bounds. if (m_pTouches.Count > 2 || m_bTouchMoved || !frame.ContainsPoint(m_pContainer.ConvertToWorldSpace(m_pContainer.ConvertTouchToNodeSpace(pTouch)))) { return(false); } if (!m_pTouches.Contains(pTouch)) { m_pTouches.Add(pTouch); } if (m_pTouches.Count == 1) { // scrolling m_tTouchPoint = ConvertTouchToNodeSpace(pTouch); m_bTouchMoved = false; m_bDragging = true; //dragging started m_tScrollDistance = new CCPoint(0.0f, 0.0f); m_fTouchLength = 0.0f; } else if (m_pTouches.Count == 2) { m_tTouchPoint = CCPoint.Midpoint(ConvertTouchToNodeSpace(m_pTouches[0]), ConvertTouchToNodeSpace(m_pTouches[1])); m_fTouchLength = CCPoint.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]), m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1])); m_bDragging = false; } return(true); }
/** override functions */ // optional public override bool TouchBegan(CCTouch pTouch) { if (!Visible) { return(false); } CCRect frame = GetViewRect(); //dispatcher does not know about clipping. reject touches outside visible bounds. if (m_pTouches.Count > 2 || m_bTouchMoved || !frame.ContainsPoint(m_pContainer.ConvertToWorldSpace(m_pContainer.ConvertTouchToNodeSpace(pTouch)))) { return(false); } if (!m_pTouches.Contains(pTouch)) { m_pTouches.Add(pTouch); } if (m_pTouches.Count == 1) { // scrolling m_tTouchPoint = ConvertTouchToNodeSpace(pTouch); m_bTouchMoved = false; m_bDragging = true; //dragging started m_tScrollDistance = CCPoint.Zero; m_fTouchLength = 0.0f; } else if (m_pTouches.Count == 2) { m_tTouchPoint = CCPoint.Midpoint(ConvertTouchToNodeSpace(m_pTouches[0]), ConvertTouchToNodeSpace(m_pTouches[1])); m_fTouchLength = CCPoint.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]), m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1])); m_bDragging = false; } return(true); }
// Returns the point where the bolt is at a given fraction of the way through the bolt. Passing // zero will return the start of the bolt, and passing 1 will return the end. private CCPoint GetPoint(BoltStatus b, float position) { var start = b.Bolt.Start; float length = CCPoint.Distance(start, b.Bolt.End); CCPoint dir = (b.Bolt.End - start) / length; position *= length; for (int i = 0; i < b.Segments.Count; i += 2) { if (CCPoint.Dot(b.Segments[i] - start, dir) >= position) { float lineStartPos = CCPoint.Dot(b.Segments[i] - start, dir); float lineEndPos = CCPoint.Dot(b.Segments[i + 1] - start, dir); float linePos = (position - lineStartPos) / (lineEndPos - lineStartPos); return(CCPoint.Lerp(b.Segments[i], b.Segments[i + 1], linePos)); } } return(CCPoint.Zero); }
public override void TouchMoved(CCTouch touch) { if (!Visible) { return; } if (m_pTouches.Contains(touch)) { if (m_pTouches.Count == 1 && m_bDragging) { // scrolling CCPoint moveDistance, newPoint; //, maxInset, minInset; CCRect frame; float newX, newY; frame = GetViewRect(); newPoint = ConvertTouchToNodeSpace(m_pTouches[0]); moveDistance = newPoint - m_tTouchPoint; float dis = 0.0f; if (m_eDirection == CCScrollViewDirection.Vertical) { dis = moveDistance.Y; } else if (m_eDirection == CCScrollViewDirection.Horizontal) { dis = moveDistance.X; } else { dis = (float)Math.Sqrt(moveDistance.X * moveDistance.X + moveDistance.Y * moveDistance.Y); } if (!m_bTouchMoved && Math.Abs(ConvertDistanceFromPointToInch(dis)) < MOVE_INCH) { //CCLOG("Invalid movement, distance = [%f, %f], disInch = %f", moveDistance.x, moveDistance.y); return; } if (!m_bTouchMoved) { moveDistance = CCPoint.Zero; } m_tTouchPoint = newPoint; m_bTouchMoved = true; if (frame.ContainsPoint(ConvertToWorldSpace(newPoint))) { switch (m_eDirection) { case CCScrollViewDirection.Vertical: moveDistance = new CCPoint(0.0f, moveDistance.Y); break; case CCScrollViewDirection.Horizontal: moveDistance = new CCPoint(moveDistance.X, 0.0f); break; default: break; } //maxInset = m_fMaxInset; //minInset = m_fMinInset; newX = m_pContainer.Position.X + moveDistance.X; newY = m_pContainer.Position.Y + moveDistance.Y; m_tScrollDistance = moveDistance; SetContentOffset(new CCPoint(newX, newY)); } } else if (m_pTouches.Count == 2 && !m_bDragging) { float len = CCPoint.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]), m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1])); ZoomScale = ZoomScale * len / m_fTouchLength; } } }