protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1)); this._yellowGreenBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(0x9ACD32, 1)); GradientStop[] stops = new GradientStop[] { new GradientStop(0, Color.FromKnown(Colors.Yellow, 1)), new GradientStop(1, Color.FromKnown(Colors.ForestGreen, 1)) }; using (GradientStopCollection collection = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp)) { this._linearGradientBrush = renderTarget.CreateLinearGradientBrush( new LinearGradientBrushProperties(new PointF(0, 0), new PointF(150, 150)), BrushProperties.Default, collection); this._radialGradientBrush = renderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties(new PointF(75, 75), new PointF(0, 0), 75, 75), BrushProperties.Default, collection); } using (Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "fern.jpg")) { this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.Linear), BrushProperties.Default); } this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromRGB(0.93f, 0.94f, 0.96f)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._outlineBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.DarkSlateBlue, 1), 1); this._shapeFillBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.CornflowerBlue, 1), 0.5f); this._textFillBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1), 1); this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); _blackBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1)); _customRenderer = new CustomTextRendererWithEffects(Direct2DFactory, renderTarget, _blackBrush); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); // Create an array of gradient stops to put in the gradient stop // collection that will be used in the gradient brush. GradientStop[] stops = new GradientStop[] { new GradientStop(0, Color.FromKnown(Colors.Gold, 1)), new GradientStop(0.85f, Color.FromKnown(Colors.Orange, 1)), new GradientStop(1, Color.FromKnown(Colors.OrangeRed, 1)) }; using (GradientStopCollection gradiendStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp)) { // The center of the gradient is in the center of the box. // The gradient origin offset was set to zero(0, 0) or center in this case. this._radialGradientBrush = renderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties( new PointF(330, 330), new PointF(140, 140), 140, 140), BrushProperties.Default, gradiendStops); } this._sceneBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1)); this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromRGB(0.93f, 0.94f, 0.96f)); }
protected override void OnRender(WindowRenderTarget renderTarget) { if (_task != null) { _task.Wait(); _task.Dispose(); } List <Tuple <Geometry, Color> > copy = _geometries; _task = CreateGeometries(_time); if (_time == 0.1f) { renderTarget.Clear(Color.FromKnown(Colors.Black, 1f)); } renderTarget.FillRect(_brush, new RectF(0, 0, ClientSize.Width, ClientSize.Height)); for (int index = 0; index < copy.Count; ++index) { Tuple <Geometry, Color> tuple = copy[index]; using (Geometry geometry = tuple.Item1) { using (SolidColorBrush brush = renderTarget.CreateSolidColorBrush(tuple.Item2.AdjustContrast(1.5f))) { renderTarget.DrawGeometry(brush, 0.1f, geometry); } } } copy.Clear(); _time += 0.002f; }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); float width = ClientSize.Width / _dpiScaleX; float height = ClientSize.Height / _dpiScaleY; this._textLayout = DirectWriteFactory.CreateTextLayout( _text, this._textFormat, width, height); using (Typography typography = DirectWriteFactory.CreateTypography()) { typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1); this._textLayout.SetTypography(typography, new TextRange(0, _text.Length)); } Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "heart.png"); this._bitmapInlineObject = new BitmapInlineObject(RenderTarget, bitmap); this._textLayout.SetInlineObject(this._bitmapInlineObject, new TextRange(2, 1)); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1)); }
private void MainWindow_Load(object sender, EventArgs e) { DirectWriteFactory f = DirectWriteFactory.Create(DirectWriteFactoryType.Shared); _textFormat = f.CreateTextFormat("Verdana", 110, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal); _textFormat.ParagraphAlignment = ParagraphAlignment.Far; _textFormat.TextAlignment = TextAlignment.Center; ClientSize = new System.Drawing.Size(600, 600); _factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None, FactoryVersion.Auto); _renderTarget = _factory.CreateWindowRenderTarget(this, PresentOptions.None, RenderTargetProperties.Default); AntialiasMode amode = _renderTarget.AntialiasMode; TextAntialiasMode tamode = _renderTarget.TextAntialiasMode; _strokeBrush = _renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Cyan, 1)); try { _strokeStyle = _factory.CreateStrokeStyle(new StrokeStyleProperties1(LineCapStyle.Flat, LineCapStyle.Flat, LineCapStyle.Round, LineJoin.Miter, 10, DashStyle.Dot, 0, StrokeTransformType.Normal), null); } catch (NotSupportedException) { _strokeStyle = _factory.CreateStrokeStyle(new StrokeStyleProperties(LineCapStyle.Flat, LineCapStyle.Flat, LineCapStyle.Round, LineJoin.Miter, 10, DashStyle.Dot, 0), null); } Resize += new EventHandler(MainWindow_Resize); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); foreach (MyText text in parent.texts) { text.brush = renderTarget.CreateSolidColorBrush(text.color); } }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._bitmap = renderTarget.CreateBitmap(this.GetType(), "fern.jpg"); this._brush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Orange, 1)); this._brush.Opacity = 0.75f; this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f)); }
protected override void OnRender(WindowRenderTarget renderTarget) { using (SolidColorBrush b = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 0.75f))) { renderTarget.FillRect(b, new RectF(0, 0, ClientSize.Width, ClientSize.Height)); } this._universe.Render(renderTarget); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1)); using (Bitmap bitmap = renderTarget.CreateBitmap(this.GetType(), "flowers.jpg")) { this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.NearestNeighbor), BrushProperties.Default); } _customRenderer = new CustomTextRenderer(this.Direct2DFactory, renderTarget, this._blackBrush, this._bitmapBrush); }
public void DrawGlyphRun(float baselineOriginX, float baselineOriginY, Graphics.Direct2D.MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ClientDrawingEffect clientDrawingEffect) { using (PathGeometry pathGeometry = _factory.CreatePathGeometry()) { using (GeometrySink sink = pathGeometry.Open()) { glyphRun.FontFace.GetGlyphRunOutline( glyphRun.EmSize, glyphRun.GlyphIndices, glyphRun.GlyphAdvances, glyphRun.GlyphOffsets, glyphRun.IsSideways, glyphRun.BidiLevel != 0, sink); sink.Close(); } CustomGeometrySink customSink = new CustomGeometrySink(); pathGeometry.Stream(customSink); customSink.Close(); System.Diagnostics.Debug.WriteLine(customSink.ToString()); SolidColorBrush brush = null; if (clientDrawingEffect != null) { ColorDrawingEffect drawingEffect = clientDrawingEffect as ColorDrawingEffect; if (drawingEffect != null) { brush = _renderTarget.CreateSolidColorBrush(drawingEffect.Color); } } Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY); using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(pathGeometry, matrix)) { _renderTarget.FillGeometry(brush == null ? _defaultBrush : brush, transformedGeometry); } if (brush != null) { brush.Dispose(); } } }
protected override void OnRender(WindowRenderTarget renderTarget) { renderTarget.Clear(Color.FromKnown(Colors.Black, 1)); using (EllipseGeometry geometry = Direct2DFactory.CreateEllipseGeometry(new Graphics.Direct2D.Ellipse(ClientSize.Width / 2, ClientSize.Height / 2, ClientSize.Width / 2 - 25, ClientSize.Height / 2 - 25))) { using (SolidColorBrush brush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Red, 1))) { renderTarget.DrawGeometry(brush, 50, geometry); } } }
private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; Random rand = new Random(); _renderTarget.BeginDraw(); for (int index = 0; index < 20; ++index) { Color color = Color.FromRGB((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()); using (SolidColorBrush brush = _renderTarget.CreateSolidColorBrush(color)) { float strokeWidth = rand.Next(1, 5); float patch = strokeWidth / 2 - (int)(strokeWidth / 2); _renderTarget.DrawRect(brush, strokeWidth, _strokeStyle, new RectF( new PointF(rand.Next(0, ClientSize.Width) + patch, rand.Next(0, ClientSize.Height) + patch), new PointF(rand.Next(0, ClientSize.Width) + patch, rand.Next(0, ClientSize.Height) + patch))); } } _cache = _renderTarget.CreateBitmap(new SizeU((uint)ClientSize.Width, (uint)ClientSize.Height), IntPtr.Zero, 0, new BitmapProperties(new PixelFormat(DxgiFormat.B8G8R8A8_UNORM, AlphaMode.Ignore), 96, 96)); _cache.CopyFromRenderTarget(new PointU(0, 0), _renderTarget, new RectU(0, 0, (uint)ClientSize.Width, (uint)ClientSize.Height)); _renderTarget.EndDraw(); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._brush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Brown, 1)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); // Create an array of gradient stops to put in the gradient stop // collection that will be used in the gradient brush. GradientStop[] stops = new GradientStop[] { new GradientStop(0, Color.FromARGB(Colors.Gold, 1)), new GradientStop(0.85f, Color.FromARGB(Colors.Orange, 1)), new GradientStop(1, Color.FromARGB(Colors.OrangeRed, 1)) }; using (GradientStopCollection gradiendStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp)) { // The center of the gradient is in the center of the box. // The gradient origin offset was set to zero(0, 0) or center in this case. this._radialGradientBrush = renderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties( new PointF(330, 330), new PointF(140, 140), 140, 140), BrushProperties.Default, gradiendStops); } this._sceneBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1)); this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1)); this._customRenderer = new CustomTextRendererWithEffects(this.Direct2DFactory, renderTarget, this._blackBrush); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1)); this._yellowGreenBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(0x9ACD32, 1)); GradientStop[] stops = new GradientStop[] { new GradientStop(0, Color.FromARGB(Colors.Yellow, 1)), new GradientStop(1, Color.FromARGB(Colors.ForestGreen, 1)) }; using (GradientStopCollection collection = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp)) { this._linearGradientBrush = renderTarget.CreateLinearGradientBrush( new LinearGradientBrushProperties(new PointF(0, 0), new PointF(150, 150)), BrushProperties.Default, collection); this._radialGradientBrush = renderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties(new PointF(75, 75), new PointF(0, 0), 75, 75), BrushProperties.Default, collection); } using (Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "fern.jpg")) { this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.Linear), BrushProperties.Default); } this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); _brush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.LimeGreen, 1)); _semiTransparentBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 0.25f)); }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1)); using (Bitmap bitmap = renderTarget.CreateBitmap(this.GetType(), "flowers.jpg")) { this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.NearestNeighbor), BrushProperties.Default); } _customRenderer = new CustomTextRenderer(this.Direct2DFactory, renderTarget, this._blackBrush, this._bitmapBrush); }