/// <summary> /// /// </summary> /// <param name="rect"></param> /// <param name="targetSpace">null if to world space</param> /// <returns></returns> public Rectangle TransformRect(Rectangle rect, DisplayObject targetSpace) { if (targetSpace == null) { targetSpace = Stage.inst; } if (targetSpace == this) { return(rect); } if (targetSpace == parent && _rotation.Z == 0) // optimization { return(new Rectangle((this.x + rect.X) * _scale.X, (this.y + rect.Y) * _scale.Y, rect.Width * _scale.X, rect.Height * _scale.Y)); } else { ValidateMatrix(true); Matrix mat = Matrix.Invert(targetSpace.transformMatrix); ToolSet.TransformRect(ref rect, ref _localToWorldMatrix, ref mat); return(rect); } }
/// <summary> /// /// </summary> /// <param name="rect"></param> /// <param name="targetSpace">null if to world space</param> /// <returns></returns> public Rect TransformRect(Rect rect, DisplayObject targetSpace) { if (targetSpace == null) { targetSpace = Stage.inst; } if (targetSpace == this) { return(rect); } if (targetSpace == parent && _rotation.z == 0) // optimization { return(new Rect((this.x + rect.x) * _scale.x, (this.y + rect.y) * _scale.y, rect.Width * _scale.x, rect.Height * _scale.y)); } else { ValidateMatrix(true); Matrix4x4 mat = targetSpace.transformMatrix.GetInverted(); ToolSet.TransformRect(ref rect, ref _localToWorldMatrix, ref mat); return(rect); } }
override public void Draw(FairyBatch batch) { base.Draw(batch); if (_paintingMode != 0 && paintingGraphics.texture != null) { batch.PushRenderTarget(paintingGraphics.texture, Vector2.Transform(Vector2.Zero, _localToWorldMatrix) + new Vector2(_paintingMargin.left, _paintingMargin.top)); } if (_clipRect != null) { //在这里可以直接使用 _localToWorldMatrix, 因为已经更新 Rectangle clipRect = (Rectangle)_clipRect; Matrix mat = Matrix.Identity; ToolSet.TransformRect(ref clipRect, ref _localToWorldMatrix, ref mat); batch.EnterClipping(clipRect); } float savedAlpha = batch.alpha; batch.alpha *= this.alpha; bool savedGrayed = batch.grayed; batch.grayed = batch.grayed || this.grayed; int cnt = _children.Count; for (int i = 0; i < cnt; i++) { DisplayObject child = _children[i]; if (child.visible) { child.Draw(batch); } } if (_clipRect != null) { batch.LeaveClipping(); } if (_paintingMode != 0 && paintingGraphics.texture != null) { batch.PopRenderTarget(); batch.Draw(paintingGraphics, 1, false, _blendMode, ref _localToWorldMatrix, _filter); } batch.alpha = savedAlpha; batch.grayed = savedGrayed; }
override public void Update(UpdateContext context) { base.Update(context); if (_paintingMode != 0 && paintingGraphics.texture != null) { context.PushRenderTarget(paintingGraphics.texture, new Vector2(_renderRect.x, _renderRect.y)); } if (_clipRect != null) { //在这里可以直接使用 _localToWorldMatrix, 因为已经更新 Rect clipRect = (Rect)_clipRect; Matrix4x4 mat = Matrix4x4.Identity; ToolSet.TransformRect(ref clipRect, ref _localToWorldMatrix, ref mat); context.EnterClipping(this.id, clipRect); } float savedAlpha = context.alpha; context.alpha *= this.alpha; bool savedGrayed = context.grayed; context.grayed = context.grayed || this.grayed; int cnt = _children.Count; for (int i = 0; i < cnt; i++) { DisplayObject child = _children[i]; if (child.visible) { child.Update(context); } } if (_clipRect != null) { context.LeaveClipping(); } if (_paintingMode != 0 && paintingGraphics.texture != null) { context.PopRenderTarget(); paintingGraphics.Render(_renderRect, _renderScale, _renderRotation, 1, context); } context.alpha = savedAlpha; context.grayed = savedGrayed; }