protected internal virtual void RenderRecursive(DrawingContext dc) { Debug.Assert(this.IsMeasureValid && this.IsArrangeValid); dc.Translate(_offsetX, _offsetY); dc.PushClippingRectangle(0, 0, _renderWidth, _renderHeight); try { Debug.Assert(this.Visibility == Visibility.Visible); if (!dc.EmptyClipRect) { OnRender(dc); UIElementCollection children = _logicalChildren; if (children != null) { int n = children.Count; for (int i = 0; i < n; i++) { UIElement child = children[i]; if (child.IsRenderable()) { child.RenderRecursive(dc); } } } } } finally { dc.PopClippingRectangle(); dc.Translate(-_offsetX, -_offsetY); //------------------------------------------------------------------------------- // Reset the render flags. _flags &= ~(Flags.IsSubtreeDirtyForRender | Flags.IsDirtyForRender); } }
/// <summary> /// This is the standard RenderMessageHandler callback, posted via PostRender() /// and Resize(). This wraps RenderMessageHandlerCore and emits an ETW events /// to trace its execution. /// </summary> internal object RenderMessageHandler(object arg) { try { _isRendering = true; //_screen.Clear(); if (_invokeOnRenderCallbacks != null) { int callbackLoopCount = 0; int count = _invokeOnRenderCallbacks.Count; while (count > 0) { callbackLoopCount++; if (callbackLoopCount > 153) { throw new InvalidOperationException("infinite loop"); } InvokeOnRenderCallback[] callbacks; lock (_invokeOnRenderCallbacks) { count = _invokeOnRenderCallbacks.Count; callbacks = new InvokeOnRenderCallback[count]; _invokeOnRenderCallbacks.CopyTo(callbacks); _invokeOnRenderCallbacks.Clear(); } for (int i = 0; i < count; i++) { callbacks[i].DoWork(); } count = _invokeOnRenderCallbacks.Count; } } DrawingContext dc = new DrawingContext(_screen); /* The dirty rectange MUST be read after the InvokeOnRender callbacks are * complete, as they can trigger layout changes or invalidate controls * which are expected to be redrawn. */ int x = _dirtyX0; int y = _dirtyY0; int w = _dirtyX1 - _dirtyX0; int h = _dirtyY1 - _dirtyY0; _dirtyX0 = _screenW; _dirtyY0 = _screenH; _dirtyX1 = _dirtyY1 = 0; try { if (w > 0 && h > 0) { // // This is the big Render! // // We've now updated layout and the updated scene will be // rendered. dc.PushClippingRectangle(x, y, w, h); _target.RenderRecursive(dc); dc.PopClippingRectangle(); } } finally { dc.Close(); if (w > 0 && h > 0) { _screen.Flush(x, y, w, h); } } } finally { _currentRenderOp = null; _isRendering = false; } return(null); }
/// <summary> /// This is the standard RenderMessageHandler callback, posted via PostRender() /// and Resize(). This wraps RenderMessageHandlerCore and emits an ETW events /// to trace its execution. /// </summary> internal object RenderMessageHandler(object arg) { try { _isRendering = true; //_screen.Clear(); if (_invokeOnRenderCallbacks != null) { int callbackLoopCount = 0; int count = _invokeOnRenderCallbacks.Count; while (count > 0) { callbackLoopCount++; if (callbackLoopCount > 153) { throw new InvalidOperationException("infinite loop"); } InvokeOnRenderCallback[] callbacks; lock (_invokeOnRenderCallbacks) { count = _invokeOnRenderCallbacks.Count; callbacks = new InvokeOnRenderCallback[count]; _invokeOnRenderCallbacks.CopyTo(callbacks); _invokeOnRenderCallbacks.Clear(); } for (int i = 0; i < count; i++) { callbacks[i].DoWork(); } count = _invokeOnRenderCallbacks.Count; } } DrawingContext dc = new DrawingContext(_screen); /* The dirty rectange MUST be read after the InvokeOnRender callbacks are * complete, as they can trigger layout changes or invalidate controls * which are expected to be redrawn. */ int x = _dirtyX0; int y = _dirtyY0; int w = _dirtyX1 - _dirtyX0; int h = _dirtyY1 - _dirtyY0; _dirtyX0 = _screenW; _dirtyY0 = _screenH; _dirtyX1 = _dirtyY1 = 0; try { if (w > 0 && h > 0) { // // This is the big Render! // // We've now updated layout and the updated scene will be // rendered. dc.PushClippingRectangle(x, y, w, h); _target.RenderRecursive(dc); dc.PopClippingRectangle(); } } finally { dc.Close(); if (w > 0 && h > 0) { _screen.Flush(x, y, w, h); } } } finally { _currentRenderOp = null; _isRendering = false; } return null; }
public override void OnRender(DrawingContext dc) { if (_pushClippingRectangle) { try { dc.PushClippingRectangle(x0, y0, xDimension, yDimension); } catch (ArgumentException ex) { Log.Comment("Caught " + ex.Message + " when Pushing a clipping rectangle at (" + x0 + ", " + y0 + ")" + " and Width = " + xDimension + " Height = " + yDimension); _argumentException = true; } } if (_popClippingRectangle) { dc.PopClippingRectangle(); } if (_getClippingRectangle) { dc.GetClippingRectangle(out x1, out y1, out wd, out ht); } if (_drawLine) { dc.DrawLine(_pen, x0, y0, x1, y1); } if (_drawRectangle) { try { dc.DrawRectangle(_brush, _pen, r, s, xDimension, yDimension); } catch (ArgumentException ex) { Log.Comment("Caught " + ex.Message + " when drawing a Rectangle at (" + r + ", " + s + ")" + " Width = " + xDimension + " Height = " + yDimension); _argumentException = true; } } if (_drawEllipse) { dc.DrawEllipse(_brush, _pen, r, s, xDimension, yDimension); } if (_drawPolygon) { dc.DrawPolygon(_brush, _pen, pts); } if (_clear) { dc.Clear(); } if (_setPixel) { dc.SetPixel(_color, r, s); } if (_drawImage) { try { dc.DrawImage(bmp1, r, s); } catch (NullReferenceException ex) { Log.Comment("Caught " + ex.Message + " when drawing a null Image"); _nullReferenceException = true; } } if (_drawCroppedImage) { try { dc.DrawImage(bmp1, r, s, x0, y0, xDimension, yDimension); } catch (ArgumentException ex) { Log.Comment("Caught " + ex.Message + " when drawing an Image at (" + r + ", " + s + ")" + "from a source Image at(" + x0 + ", " + y0 + ") Width = " + xDimension + " Height = " + yDimension); _argumentException = true; } catch (NullReferenceException ex) { Log.Comment("Caught " + ex.Message + " when drawing a null Image"); _nullReferenceException = true; } } if (_translate) { dc.Translate(r, s); } if (_blendImage) { dc.BlendImage(bmp2, x0, y0, x1, y1, xDimension, yDimension, _opacity); } if (_drawText) { _textFits = dc.DrawText(ref _str, _font, _color, r, s, xDimension, yDimension, _alignment, _trimming); } base.OnRender(dc); _pBitmap = dc.Bitmap; Master_Media.autoEvent.Set(); }