public static bool CCRectContainsPoint(CCRect rect, CCPoint point) { bool flag = false; if (rect != null) { if (float.IsNaN(point.x)) { point.x = 0f; } if (float.IsNaN(point.y)) { point.y = 0f; } CCRect.CCRectGetMinX(rect); CCRect.CCRectGetMaxX(rect); CCRect.CCRectGetMinY(rect); CCRect.CCRectGetMaxY(rect); if (point.x >= CCRect.CCRectGetMinX(rect) && point.x <= CCRect.CCRectGetMaxX(rect) && point.y >= CCRect.CCRectGetMinY(rect) && point.y <= CCRect.CCRectGetMaxY(rect)) { flag = true; } } return(flag); }
public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform) { float single = CCRect.CCRectGetMinY(rect); float single1 = CCRect.CCRectGetMinX(rect); float single2 = CCRect.CCRectGetMaxX(rect); float single3 = CCRect.CCRectGetMaxY(rect); CCPoint cCPoint = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(single1, single), anAffineTransform); CCPoint cCPoint1 = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(single2, single), anAffineTransform); CCPoint cCPoint2 = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(single1, single3), anAffineTransform); CCPoint cCPoint3 = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(single2, single3), anAffineTransform); float single4 = Math.Min(Math.Min(cCPoint.x, cCPoint1.x), Math.Min(cCPoint2.x, cCPoint3.x)); float single5 = Math.Max(Math.Max(cCPoint.x, cCPoint1.x), Math.Max(cCPoint2.x, cCPoint3.x)); float single6 = Math.Min(Math.Min(cCPoint.y, cCPoint1.y), Math.Min(cCPoint2.y, cCPoint3.y)); float single7 = Math.Max(Math.Max(cCPoint.y, cCPoint1.y), Math.Max(cCPoint2.y, cCPoint3.y)); return(new CCRect(single4, single6, single5 - single4, single7 - single6)); }
public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform) { float top = CCRect.CCRectGetMinY(rect); float left = CCRect.CCRectGetMinX(rect); float right = CCRect.CCRectGetMaxX(rect); float bottom = CCRect.CCRectGetMaxY(rect); CCPoint topLeft = CCPointApplyAffineTransform(new CCPoint(left, top), anAffineTransform); CCPoint topRight = CCPointApplyAffineTransform(new CCPoint(right, top), anAffineTransform); CCPoint bottomLeft = CCPointApplyAffineTransform(new CCPoint(left, bottom), anAffineTransform); CCPoint bottomRight = CCPointApplyAffineTransform(new CCPoint(right, bottom), anAffineTransform); float minX = Math.Min(Math.Min(topLeft.x, topRight.x), Math.Min(bottomLeft.x, bottomRight.x)); float maxX = Math.Max(Math.Max(topLeft.x, topRight.x), Math.Max(bottomLeft.x, bottomRight.x)); float minY = Math.Min(Math.Min(topLeft.y, topRight.y), Math.Min(bottomLeft.y, bottomRight.y)); float maxY = Math.Max(Math.Max(topLeft.y, topRight.y), Math.Max(bottomLeft.y, bottomRight.y)); return(new CCRect(minX, minY, (maxX - minX), (maxY - minY))); }
public virtual void keyboardWillShow(CCIMEKeyboardNotificationInfo info) { Debug.WriteLine("TextInputTest:keyboardWillShowAt(origin:%f,%f, size:%f,%f)", info.end.origin.x, info.end.origin.y, info.end.size.width, info.end.size.height); if (m_pTrackNode != null) { return; } CCRect rectTracked = TextInputTestScene.getRect(m_pTrackNode); Debug.WriteLine("TextInputTest:trackingNodeAt(origin:%f,%f, size:%f,%f)", rectTracked.origin.x, rectTracked.origin.y, rectTracked.size.width, rectTracked.size.height); // if the keyboard area doesn't intersect with the tracking node area, nothing need to do. if (!CCRect.CCRectIntersetsRect(rectTracked, info.end)) { return; } // assume keyboard at the bottom of screen, calculate the vertical adjustment. float adjustVert = CCRect.CCRectGetMaxY(info.end) - CCRect.CCRectGetMinY(rectTracked); Debug.WriteLine("TextInputTest:needAdjustVerticalPosition(%f)", adjustVert); // move all the children node of KeyboardNotificationLayer CCNode ccnoed = new CCNode(); List <CCNode> children = ccnoed.children; CCNode node; int count = children.Count; CCPoint pos; for (int i = 0; i < count; ++i) { node = (CCNode)children[i]; pos = node.position; pos.y += adjustVert; node.position = pos; } }
public static bool CCRectIntersetsRect(CCRect rectA, CCRect rectB) { bool flag = false; if (rectA != null && rectB != null) { flag = (CCRect.CCRectGetMaxX(rectA) < CCRect.CCRectGetMinX(rectB) || CCRect.CCRectGetMaxX(rectB) < CCRect.CCRectGetMinX(rectA) || CCRect.CCRectGetMaxY(rectA) < CCRect.CCRectGetMinY(rectB) ? false : CCRect.CCRectGetMaxY(rectB) >= CCRect.CCRectGetMinY(rectA)); } return(flag); }