/** * clip this view so that outside of the visible bounds can be hidden. */ private void BeforeDraw() { if (m_bClippingToBounds) { m_bScissorRestored = false; CCRect frame = GetViewRect(); if (CCDrawManager.ScissorRectEnabled) { m_bScissorRestored = true; m_tParentScissorRect = CCDrawManager.ScissorRect; //set the intersection of m_tParentScissorRect and frame as the new scissor rect if (frame.IntersectsRect(m_tParentScissorRect)) { float x = Math.Max(frame.Origin.X, m_tParentScissorRect.Origin.X); float y = Math.Max(frame.Origin.Y, m_tParentScissorRect.Origin.Y); float xx = Math.Min(frame.Origin.X + frame.Size.Width, m_tParentScissorRect.Origin.X + m_tParentScissorRect.Size.Width); float yy = Math.Min(frame.Origin.Y + frame.Size.Height, m_tParentScissorRect.Origin.Y + m_tParentScissorRect.Size.Height); CCDrawManager.SetScissorInPoints(x, y, xx - x, yy - y); } } else { CCDrawManager.ScissorRectEnabled = true; CCDrawManager.SetScissorInPoints(frame.Origin.X, frame.Origin.Y, frame.Size.Width, frame.Size.Height); } } }
/** * retract what's done in beforeDraw so that there's no side effect to * other nodes. */ private void AfterDraw() { if (m_childClippingMode != CCClipMode.None) { if (m_childClippingMode == CCClipMode.BoundsWithRenderTarget) { m_pRenderTexture.End(); CCDrawManager.PopMatrix(); } if (m_bRestoreScissor) { CCDrawManager.SetScissorInPoints( m_tSaveScissorRect.Origin.X, m_tSaveScissorRect.Origin.Y, m_tSaveScissorRect.Size.Width, m_tSaveScissorRect.Size.Height); CCDrawManager.ScissorRectEnabled = true; m_bRestoreScissor = false; } else { CCDrawManager.ScissorRectEnabled = false; } if (m_childClippingMode == CCClipMode.BoundsWithRenderTarget) { m_pRenderTexture.Sprite.Visit(); } } }
private void BeforeDraw() { m_bNoDrawChildren = false; if (m_childClippingMode == CCClipMode.Bounds) { // We always clip to the bounding box var rect = new CCRect(0, 0, m_obContentSize.Width, m_obContentSize.Height); var bounds = CCAffineTransform.Transform(rect, NodeToWorldTransform()); var winSize = CCDirector.SharedDirector.WinSize; CCRect prevScissorRect; if (CCDrawManager.ScissorRectEnabled) { prevScissorRect = CCDrawManager.ScissorRect; } else { prevScissorRect = new CCRect(0, 0, winSize.Width, winSize.Height); } if (!bounds.IntersectsRect(prevScissorRect)) { m_bNoDrawChildren = true; return; } float minX = Math.Max(bounds.MinX, prevScissorRect.MinX); float minY = Math.Max(bounds.MinY, prevScissorRect.MinY); float maxX = Math.Min(bounds.MaxX, prevScissorRect.MaxX); float maxY = Math.Min(bounds.MaxY, prevScissorRect.MaxY); if (CCDrawManager.ScissorRectEnabled) { m_bRestoreScissor = true; } else { CCDrawManager.ScissorRectEnabled = true; } m_tSaveScissorRect = prevScissorRect; CCDrawManager.SetScissorInPoints(minX, minY, maxX - minX, maxY - minY); } else if (m_childClippingMode == CCClipMode.BoundsWithRenderTarget) { m_tSaveScissorRect = CCDrawManager.ScissorRect; m_bRestoreScissor = CCDrawManager.ScissorRectEnabled; CCDrawManager.ScissorRectEnabled = false; CCDrawManager.PushMatrix(); CCDrawManager.SetIdentityMatrix(); m_pRenderTexture.BeginWithClear(0, 0, 0, 0); } }
/** * retract what's done in beforeDraw so that there's no side effect to * other nodes. */ private void AfterDraw() { if (m_bClippingToBounds) { if (m_bScissorRestored) { CCDrawManager.SetScissorInPoints(m_tParentScissorRect.Origin.X, m_tParentScissorRect.Origin.Y, m_tParentScissorRect.Size.Width, m_tParentScissorRect.Size.Height); } else { CCDrawManager.ScissorRectEnabled = false; } } }
private void BeforeDraw() { CCDirector director = CCDirector.SharedDirector; // TODO: Add the RenderTarget support here CCPoint screenPos = Parent.ConvertToWorldSpace(Position); if (screenPos.X < 0f || screenPos.X > director.WinSize.Width || screenPos.Y < 0f || screenPos.Y > director.WinSize.Height) { // ScissorRect can not be applied outside of the viewport. return; } float s = Scale; s *= director.ContentScaleFactor; CCSize winSize = CCDirector.SharedDirector.WinSize; CCRect m_tViewSize = BoundingBox; // We always clip to the bounding box float x = screenPos.X; float y = winSize.Height - (screenPos.Y + m_tViewSize.Size.Height * s); float scissorW = m_tViewSize.Size.Width * s; float scissorH = m_tViewSize.Size.Height * s; if (x < 0) { x = 0f; } if (y < 0) { y = 0f; } if (x + scissorW > winSize.Width) { scissorW = winSize.Width - x; } if (y + scissorH > winSize.Height) { scissorH = winSize.Height - y; } if (scissorW < 0f || scissorH < 0f) { return; } if (x < 0 || y < 0 || (x + scissorW) > winSize.Width || (y + scissorH) > winSize.Height) { } CCDrawManager.ScissorRectEnabled = true; CCDrawManager.SetScissorInPoints(x, y, scissorW, scissorH); }
/** * clip this view so that outside of the visible bounds can be hidden. */ private void BeforeDraw() { if (m_bClippingToBounds) { CCPoint screenPos = Parent.ConvertToWorldSpace(Position); float s = Scale; CCDirector director = CCDirector.SharedDirector; s *= director.ContentScaleFactor; CCSize winSize = CCDirector.SharedDirector.WinSize; CCDrawManager.ScissorRectEnabled = true; CCDrawManager.SetScissorInPoints(screenPos.X, winSize.Height - (screenPos.Y + m_tViewSize.Height * s), m_tViewSize.Width * s, m_tViewSize.Height * s); } }