private void DrawSeries(MySeries s, Brush brush, float moveY, float scale) { int begin, end; begin = s.begin < this._minX ? (int)this._minX : s.begin; float maxX = this._minX + (renderControl.ClientSize.Width - 40) / this._scale_times_X; end = maxX > s.end ? s.end : (int)Math.Ceiling(maxX); RawVector2 p_current, p_next; if (begin - s.begin < s.data.Length) { p_current = getPixelPoint(begin, s.data[begin - s.begin], moveY, scale); } else { return; } for (int i = begin + 1; i <= end; i++) { p_next = getPixelPoint(i, s.data[i - s.begin], moveY, scale); _renderTarget.DrawLine(p_current, p_next, brush, 0.6f); p_current = p_next; } }
public void Draw(Renderer renderer, RawRectangleF rect, int c, int textx, ref int texty) { D2D1.Brush brush = renderer.Brushes[Colors[c % Colors.Length]]; renderer.D2DContext.FillRectangle(rect, brush); renderer.Consolas14.TextAlignment = DWrite.TextAlignment.Leading; renderer.D2DContext.DrawText( Name + " (" + Stopwatch.Elapsed.TotalMilliseconds.ToString("F1") + "ms)", renderer.Consolas14, new RawRectangleF(textx, rect.Bottom + texty, textx + 100, rect.Bottom + texty + lineHeight), brush, D2D1.DrawTextOptions.None, D2D1.MeasuringMode.GdiNatural); int lineA = texty + 2; int lineC = c; texty += lineHeight; int x = 0; foreach (Profiler p in Children) { c++; //if (p.ParentTickOffset > 0) // x += (int)((p.ParentTickOffset / (double)Stopwatch.Elapsed.Ticks) * (rect.Right - rect.Left)); int w = (int)((p.Stopwatch.Elapsed.Ticks / (double)Stopwatch.Elapsed.Ticks) * (rect.Right - rect.Left)); p.Draw(renderer, new RawRectangleF(rect.Left + x, rect.Top, rect.Left + x + w, rect.Bottom), c, textx + 10, ref texty); x += w; } if (Children.Count > 0) { renderer.D2DContext.FillRectangle(new RawRectangleF(textx - 3, rect.Bottom + lineA, textx - 2, rect.Bottom + texty - 2), renderer.Brushes[Colors[lineC % Colors.Length]]); } }
/// <summary> /// Called when [render]. /// </summary> /// <param name="context">The context.</param> protected override void OnRender(RenderContext2D context) { if (background == null) { Background = new D2D.SolidColorBrush(context.DeviceContext, new Color4(0.8f, 0.8f, 0.8f, 0.6f)); } if (foreground == null) { Foreground = new D2D.SolidColorBrush(context.DeviceContext, Color.Blue); } var str = statistics.GetDetailString(); if (str != previousStr) { previousStr = str; RemoveAndDispose(ref textLayout); textLayout = Collect(new TextLayout(factory, str, format, float.MaxValue, float.MaxValue)); } var metrices = textLayout.Metrics; renderBound.Width = Math.Max(metrices.Width, renderBound.Width); renderBound.Height = metrices.Height; context.DeviceContext.Transform = Matrix3x2.Translation((float)context.ActualWidth - renderBound.Width, 0); context.DeviceContext.FillRectangle(renderBound, background); context.DeviceContext.DrawTextLayout(Vector2.Zero, textLayout, foreground); }
public void Create(Color color) { Control = new sd.SolidColorBrush( renderTarget: null, // BUGBUG: TODO color: color.ToWpf()); }
private void DrawArrow(Brush brush, Brush borderBrush, RawVector2 arrowTip, float rotAngle, float flowSize, bool moveForward, float borderWidth) { var transform = Surface.RenderTarget2D.Transform; var scaleVector = new Vector2(flowSize, flowSize); if (!moveForward) { rotAngle -= (float)Math.PI; } var translationVector = arrowTip + ((Matrix3x2)Surface.RenderTarget2D.Transform).TranslationVector; var scale = Matrix3x2.Scaling(scaleVector); var rotation = Matrix3x2.Rotation(rotAngle, Vector2.Zero); var translation = Matrix3x2.Translation(translationVector); Surface.RenderTarget2D.Transform = scale * rotation * translation; if (brush != null) { Surface.RenderTarget2D.FillGeometry(LineFlow, brush); } if (borderBrush != null) { Surface.RenderTarget2D.DrawGeometry(LineFlow, borderBrush, borderWidth); } Surface.RenderTarget2D.Transform = transform; }
public CustomColorRenderer(D2D1.RenderTarget renderTarget, D2D1.Brush fillBrush, D2D1.Brush strokeBrush, float strokeWidth) { this._renderTarget = renderTarget; _fillBrush = fillBrush; _strokeBrush = strokeBrush; _strokeWidth = strokeWidth; }
public D3D11Renderer(ObservableVideoTrack videoTrack, RendererOptions options) : base(videoTrack, options) { // _factoryDWrite = new DWrite.Factory(DWrite.FactoryType.Shared); var device2D = new D2D1.Device(DeviceDXGI, new D2D1.CreationProperties { DebugLevel = D2D1.DebugLevel.Warning, ThreadingMode = D2D1.ThreadingMode.MultiThreaded, Options = D2D1.DeviceContextOptions.None }); _context2D = new D2D1.DeviceContext(device2D, D2D1.DeviceContextOptions.None); // Load the background image using (var factoryWic = new WIC.ImagingFactory2()) using (var decoder = new WIC.JpegBitmapDecoder(factoryWic)) using (var inputStream = new WIC.WICStream(factoryWic, "background-small.jpg", NativeFileAccess.Read)) using (var formatConverter = new WIC.FormatConverter(factoryWic)) using (var bitmapScaler = new WIC.BitmapScaler(factoryWic)) { decoder.Initialize(inputStream, WIC.DecodeOptions.CacheOnLoad); formatConverter.Initialize(decoder.GetFrame(0), WIC.PixelFormat.Format32bppPBGRA); bitmapScaler.Initialize(formatConverter, VideoFrameWidth, VideoFrameHeight, WIC.BitmapInterpolationMode.Fant); _backgroundBitmap = D2D1.Bitmap1.FromWicBitmap(_context2D, bitmapScaler); } // Create render target _ballEllipse = new D2D1.Ellipse { RadiusX = VideoFrameWidth / 20f, RadiusY = VideoFrameWidth / 20f }; _ballBrush = new D2D1.SolidColorBrush(_context2D, new RawColor4(1f, 1f, 0f, 1f)); }
public void SetLineBreakBrush(D2D.Brush brush) { if (this.ShowLineBreak) { this.layout.SetDrawingEffect(brush.NativePointer, new DW.TextRange(lineBreakIndex, 1)); } }
public FpsDxLayer(D2D.RenderTarget renderTarget, DxLoadObject settings, OsuModel osuModel) : base(renderTarget, settings, osuModel) { _whiteBrush = new D2D.SolidColorBrush(RenderTarget, new Mathe.RawColor4(1, 1, 1, 1)); _textFormat = new DW.TextFormat(_factoryWrite, "Microsoft YaHei", 12); _bufferSw = new Stopwatch(); _bufferSw.Start(); }
protected override void Dispose(bool disposing) { if (disposing) { Brush.Dispose(); StrokeStyle?.Dispose(); } }
public void DrawText(string szText, int x, int y, SharpDX.Direct2D1.Brush foregroundBroush, SharpDX.DirectWrite.Factory fontFactory, SharpDX.DirectWrite.TextFormat font, WindowRenderTarget device) { var tempTextLayout = TextLayout(szText, fontFactory, font); device.DrawTextLayout(new RawVector2(x, y), tempTextLayout, foregroundBroush, DrawTextOptions.NoSnap); tempTextLayout.Dispose(); }
public void FillPolygon(Brush brush, params PointF[] polygon) { using (var path = GetPathFromPolygon(polygon, RenderTarget.Factory)) { RenderTarget.FillGeometry(path, brush); } //var path = GetPathFromPolygon(polygon, RenderTarget.Factory); //RenderTarget.FillGeometry(path, brush); }
public FpsLayer(D2D.RenderTarget renderTarget) : base(renderTarget) { _whiteBrush = new D2D.SolidColorBrush(RenderTarget, new Mathe.RawColor4(1, 1, 1, 1)); _blackBrush = new D2D.SolidColorBrush(RenderTarget, new Mathe.RawColor4(0, 0, 0, 1)); _textFormat = new DW.TextFormat(_factoryWrite, "Microsoft YaHei", 12); _bufferSw = new Stopwatch(); _bufferSw.Start(); }
public TextButton(UIElement parent, string name, RawRectangleF bounds, string text, DWrite.TextFormat textFormat, D2D1.Brush brush1, D2D1.Brush brush2, Action action) : base(parent, name, bounds) { Text = text; TextFormat = textFormat; Brush1 = brush1; Brush2 = brush2; Click = action; }
/// <inheritdoc /> /// <summary> /// Class constructor /// </summary> /// <param name="toolbar">Parent toolbar</param> public ToolbarPrimaryButton(Toolbar toolbar) : base(toolbar) { if (StyleHelper.GetAccentColor() is Color color) { this.backBrush = new SolidColorBrush(toolbar.ToolbarRenderTarget, new SharpDX.Color(color.R, color.G, color.B)); this.invert = color.ToYiq() > 0x7F; } }
/// <summary> /// Unloads all resources loaded on the given device. /// </summary> /// <param name="engineDevice">The device for which to unload the resource.</param> internal override void UnloadResources(EngineDevice engineDevice) { D2D.Brush brush = m_loadedBrushes[engineDevice.DeviceIndex]; if (brush != null) { GraphicsHelper.DisposeObject(brush); m_loadedBrushes[engineDevice.DeviceIndex] = null; } }
public static void DrawMultiPoint(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IMultiPoint points, D2D1.Brush brush, float size, Vector2 offset, Map map) { for (var i = 0; i < points.NumGeometries; i++) { var point = (IPoint)points[i]; DrawPoint(renderTarget, factory, point, brush, size, offset, map); } }
public override void OnRender(ChartControl chartControl, ChartScale chartScale, ChartBars chartBars) { Bars bars = chartBars.Bars; float lineWidth = (float)Math.Max(1, BarWidth); Vector2 point0 = new Vector2(); Vector2 point1 = new Vector2(); Vector2 point2 = new Vector2(); Vector2 point3 = new Vector2(); Vector2 point4 = new Vector2(); Vector2 point5 = new Vector2(); for (int idx = chartBars.FromIndex; idx <= chartBars.ToIndex; idx++) { SharpDX.Direct2D1.Brush overriddenBrush = chartControl.GetBarOverrideBrush(chartBars, idx); double closeValue = bars.GetClose(idx); float close = chartScale.GetYByValue(closeValue); float high = chartScale.GetYByValue(bars.GetHigh(idx)); float low = chartScale.GetYByValue(bars.GetLow(idx)); double openValue = bars.GetOpen(idx); float open = chartScale.GetYByValue(openValue); float x = chartControl.GetXByBarIndex(chartBars, idx); point0.X = point1.X = x; point0.Y = high - lineWidth * 0.5f; point1.Y = low + lineWidth * 0.5f; SharpDX.Direct2D1.Brush b = overriddenBrush ?? (closeValue >= openValue ? UpBrushDX : DownBrushDX); if (!(b is SharpDX.Direct2D1.SolidColorBrush)) { TransformBrush(b, new RectangleF(point0.X - lineWidth * 1.5f, point0.Y, lineWidth * 3, point1.Y - point0.Y)); } RenderTarget.DrawLine(point0, point1, b, lineWidth); if (!Equals(Mode, OhlcMode.HiLo)) { point2.X = x + lineWidth * 1.5f; point2.Y = close; point3.X = x; point3.Y = close; RenderTarget.DrawLine(point2, point3, b, lineWidth); if (Equals(Mode, OhlcMode.OHLC)) { point4.X = x - lineWidth * 1.5f; point4.Y = open; point5.X = x; point5.Y = open; RenderTarget.DrawLine(point4, point5, b, lineWidth); } } } }
public sd.Brush GetBrush(sd.RenderTarget target) { if (brush == null || !ReferenceEquals(brush.Tag, target)) { if (brush != null) brush.Dispose(); brush = new sd.SolidColorBrush(target, Color.ToDx()) { Tag = target }; } return brush; }
public sd.Brush Get(sd.RenderTarget target) { if (Brush == null || !ReferenceEquals(Brush.Tag, target)) { Brush = Create(target); Brush.Opacity = Alpha; Brush.Tag = target; OnCreated(); } return Brush; }
public sd.Brush Get(sd.RenderTarget target) { if (Brush == null || !ReferenceEquals(Brush.Tag, target)) { Brush = Create(target); Brush.Opacity = Alpha; Brush.Tag = target; OnCreated(); } return(Brush); }
public void Fill(Brush brush) { var context = RenderContext; var target = context.RenderTarget; using (var mesh = new Mesh(target, Triangles)) { // https://msdn.microsoft.com/en-us/library/dd371939.aspx target.AntialiasMode = AntialiasMode.Aliased; context.FillMesh(mesh, brush); target.AntialiasMode = AntialiasMode.PerPrimitive; } }
public void DrawText(string szText, int x, int y, SharpDX.Direct2D1.Brush textColor, SharpDX.DirectWrite.Factory fontFactory, SharpDX.DirectWrite.TextFormat font) { var tempTextLayout = TextLayout(szText, fontFactory, font); device.DrawTextLayout(new RawVector2(x + 1, y), tempTextLayout, new SolidColorBrush(device, RGB(0, 0, 0)), DrawTextOptions.NoSnap); device.DrawTextLayout(new RawVector2(x - 1, y), tempTextLayout, new SolidColorBrush(device, RGB(0, 0, 0)), DrawTextOptions.NoSnap); device.DrawTextLayout(new RawVector2(x, y + 1), tempTextLayout, new SolidColorBrush(device, RGB(0, 0, 0)), DrawTextOptions.NoSnap); device.DrawTextLayout(new RawVector2(x, y - 1), tempTextLayout, new SolidColorBrush(device, RGB(0, 0, 0)), DrawTextOptions.NoSnap); device.DrawTextLayout(new RawVector2(x, y), tempTextLayout, textColor, DrawTextOptions.NoSnap); tempTextLayout.Dispose(); }
private void DrawVertHBar(float X, float Y, float Height, float health, SharpDX.Direct2D1.Brush fillBrush) { float X2, Y2; float W = 2; float hbar = health / 100; hbar = hbar * Height; X2 = X + W; Y2 = Y + Height; Y = Y2 - hbar; device.FillRectangle(new RawRectangleF(X, Y, X2, Y2), fillBrush); }
public UIBrushes(WindowRenderTarget renderTarget) { White = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(1f, 1f, 1f, 1f)); Green = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(0f, 1f, 0f, 1f)); GreenYellow = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(0.6431373f, 1f, 0f, 1f)); Yellow = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(1f, 1f, 0f, 1f)); Orange = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(1f, 0.5f, 0f, 1f)); Red = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(1f, 0f, 0f, 1f)); DarkRed = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(0.75f, 0f, 0f, 1f)); Blue = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(0f, 0.5f, 1f, 1f)); Cyan = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(0f, 1f, 1f, 1f)); Gray = new D2D.SolidColorBrush(renderTarget, new SharpDX.Mathematics.Interop.RawColor4(0.6666667f, 0.6666667f, 0.6666667f, 1f)); }
private void DrawText(string text, float locX, float locY, D2D1.Brush fg, D2D1.Brush bg, string font = "", float size = 0) { using (TextFormat = new DW.TextFormat(DWFactory, font == "" ? Config.CooldownBarTextFont : font, size == 0 ? Config.CooldownBarTextFontSize : size)) { TextFormat.WordWrapping = DW.WordWrapping.NoWrap; using (DW.TextLayout TextLayout = new DW.TextLayout(DWFactory, text, TextFormat, 500, 500)) { using (TextBrush = new TextBrush(fg, bg)) { using (TextRenderer = new TextRenderer(Render, TextBrush)) { TextLayout.SetDrawingEffect(TextBrush, new DW.TextRange(10, 20)); TextLayout.Draw(TextRenderer, locX, locY); } } } } }
public Clock(Size clientSize) { ClientSize = clientSize; g_center = new PointF(ClientSize.Width / 2f, ClientSize.Height / 2f); // Create brushes blueBrush1 = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.3f, 0.4f, 0.9f, 1)); blueBrush2 = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.45f, 0.6f, 0.95f, 1)); blueBrush3 = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.6f, 0.8f, 1f, 1)); whiteBrush = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(1f, 1f, 1f, 0.5f)); redBrush = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.99f, 0.16f, 0.3f, 0.7f)); // Create ellipses ellipseCentre = new D2D.Ellipse(new Mathe.RawVector2(g_center.X, g_center.Y), 120, 120); // Create text formats textFormat = new DW.TextFormat(RenderForm.FactoryWrite, "Berlin Sans FB", 36); strokeProperties = new D2D.StrokeStyleProperties { StartCap = D2D.CapStyle.Round, EndCap = D2D.CapStyle.Triangle }; strokeStyle = new D2D.StrokeStyle(RenderForm.Factory, strokeProperties); strokeProperties2 = new D2D.StrokeStyleProperties { StartCap = D2D.CapStyle.Round, EndCap = D2D.CapStyle.Round, DashStyle = D2D.DashStyle.Dash }; strokeStyle2 = new D2D.StrokeStyle(RenderForm.Factory, strokeProperties2); int len = 110; for (int i = 0; i < 60; i++) { int r = i % 5 == 0 ? 10 : 5; float deg, rad; deg = (i / 60f * 360 - 90); rad = deg / 180 * (float)Math.PI; lim[i] = new PointF(g_center.X + (float)Math.Cos(rad) * (len - r), g_center.Y + (float)Math.Sin(rad) * (len - r)); lim2[i] = new PointF(g_center.X + (float)Math.Cos(rad) * (len), g_center.Y + (float)Math.Sin(rad) * (len)); } sw = new Stopwatch(); sw.Start(); }
public void Dispose() { if (brush != null) { brush.Dispose(); brush = null; } if (strokeStyle != null) { strokeStyle.Dispose(); strokeStyle = null; } }
private void DrawSeriesHalfLog(MySeries s, Brush brush, float moveY, float scale) { int begin, end; begin = s.begin < this._minX ? (int)this._minX : s.begin; float maxX = this._minX + (renderControl.ClientSize.Width - 40) / this._scale_times_X; end = maxX > s.end ? s.end : (int)Math.Ceiling(maxX); for (int i = begin + 1; i <= end && i - s.begin <= Setting.FrameLength / 2; i++) { _renderTarget.DrawLine(getPixelPoint(i - 1, (float)Math.Log10(s.data[i - s.begin - 1]), moveY, scale), getPixelPoint(i, (float)Math.Log10(s.data[i - s.begin]), moveY, scale), brush); } }
public sd.Brush GetBrush(sd.RenderTarget target) { if (brush == null || !ReferenceEquals(brush.Tag, target)) { if (brush != null) { brush.Dispose(); } brush = new sd.SolidColorBrush(target, Color.ToDx()) { Tag = target }; } return(brush); }
public override void Draw(Direct2D.DeviceContext renderTarget, Direct2D.Brush brush) { var lines = new[] { new [] { Points[0], Points[1] }, new [] { Points[1], Points[2] }, new [] { Points[2], Points[3] }, new [] { Points[3], Points[0] }, }; foreach (var line in lines) { renderTarget.DrawLine(line[0], line[1], brush, 2.0f); } }
public KarnaughGraphDraw(KarnaughGraphControl target) { this.width = target.Width; this.height = target.Height; var hwnd = new HwndRenderTargetProperties(); hwnd.Hwnd = target.Handle; hwnd.PixelSize = new Size2(this.width, this.height); this.fact = new SharpDX.Direct2D1.Factory(); render = new SharpDX.Direct2D1.WindowRenderTarget(this.fact, new RenderTargetProperties(), hwnd); this.target = target; //いろいろ設定 LineColor = new SharpDX.Direct2D1.SolidColorBrush(render, new RawColor4(1f, 1f, 1f, 1f)); background = new RawColor4(0.3f, 0.3f, 0.3f, 0f); }
public void Stroke( Point lineStart, Point lineEnd, Brush brush, StrokeStyle style, float strokeWidth) { Contract.Requires(brush != null); Contract.Requires(style != null); Contract.Requires(Check.IsPositive(strokeWidth)); Contract.Assert(_Target != null); DrawingPointF start = new DrawingPointF { X = lineStart.X, Y = lineStart.Y }; DrawingPointF end = new DrawingPointF { X = lineEnd.X, Y = lineEnd.Y }; _Target.DrawLine(start, end, brush, strokeWidth, style); }
/// <summary> /// Loads scene-specific content. /// </summary> private void LoadContent() { // reusable structure representing a text font with size and style _textFormat = _disposeCollector.Collect(new DW.TextFormat(_dwFactory, "Segoe UI", SharpDX.DirectWrite.FontWeight.SemiBold, SharpDX.DirectWrite.FontStyle.Italic, 16f)); // reusable brush structure _textBrush = _disposeCollector.Collect(new D2D.SolidColorBrush(_d2dDeviceContext, Color.Black)); // prebaked text - useful for constant labels as it greatly improves performance _textLayout = _disposeCollector.Collect(new DW.TextLayout(_dwFactory, "Demo DirectWrite text here.", _textFormat, 100f, 100f)); // another brush for ellipse outline _ellipseStrokeBrush = _disposeCollector.Collect(new D2D.SolidColorBrush(_d2dDeviceContext, Color.Blue)); // this is a structure so it is ok to recreate it every frame, but better to create only once, if possible _ellipse = new D2D.Ellipse(new Vector2(320, 240), 150, 100); // reusable structure describing a radial gradient properties var gradientProperties = new D2D.RadialGradientBrushProperties { Center = _ellipse.Point, RadiusX = _ellipse.RadiusX, RadiusY = _ellipse.RadiusY }; // gradient color description - here we'll draw a rainbow var gradientStops = _disposeCollector.Collect(new D2D.GradientStopCollection(_d2dDeviceContext, new[] { new D2D.GradientStop {Position = 0.00f, Color = Color.Red}, new D2D.GradientStop {Position = 0.16f, Color = Color.Orange}, new D2D.GradientStop {Position = 0.33f, Color = Color.Yellow}, new D2D.GradientStop {Position = 0.50f, Color = Color.Green}, new D2D.GradientStop {Position = 0.66f, Color = Color.LightBlue}, new D2D.GradientStop {Position = 0.83f, Color = Color.Blue}, new D2D.GradientStop {Position = 1.00f, Color = Color.Violet} })); // a radial gradient brush _ellipseFillBrush = _disposeCollector.Collect(new D2D.RadialGradientBrush(_d2dDeviceContext, ref gradientProperties, gradientStops)); }
public override void Initialize(Size size, RenderTarget renderTarget) { color = new SolidColorBrush(renderTarget, new Color4(new Color3(0.5f, 0.5f, 0.2f))); }
public void Fill(Rectangle rectangleRegion, Brush brush) { Contract.Requires(brush != null); Contract.Assert(_Target != null); RectangleF roundedRectangle = new RectangleF { Left = rectangleRegion.Left, Top = rectangleRegion.Top, Right = rectangleRegion.Right, Bottom = rectangleRegion.Bottom }; _Target.FillRectangle(roundedRectangle, brush); }
public void Stroke(Shape shape, Brush brush, StrokeStyle style, float strokeWidth) { Contract.Requires(shape != null); Contract.Requires(brush != null); Contract.Requires(style != null); Contract.Requires(Check.IsPositive(strokeWidth)); Contract.Assert(_Target != null); DxGeometry resolved = _GeometryCache.ResolveGeometry(shape); Contract.Assert(resolved != null); _Target.DrawGeometry(resolved, brush, strokeWidth, style); }
public void Fill(Rectangle rectangleRegion, Size roundedRectangleRadius, Brush brush) { Contract.Requires(Check.IsPositive(roundedRectangleRadius.Width)); Contract.Requires(Check.IsPositive(roundedRectangleRadius.Height)); Contract.Requires(brush != null); Contract.Assert(_Target != null); RectangleF rectangle = RectangleF.Empty; rectangle.Left = rectangleRegion.Left; rectangle.Top = rectangleRegion.Top; rectangle.Right = rectangleRegion.Right; rectangle.Bottom = rectangleRegion.Bottom; RoundedRectangle roundedRect = new RoundedRectangle { Rect = rectangle, RadiusX = roundedRectangleRadius.Width, RadiusY = roundedRectangleRadius.Height }; _Target.FillRoundedRectangle(roundedRect, brush); }
public void Fill(Shape shape, Brush brush) { Contract.Requires(shape != null); Contract.Requires(brush != null); Contract.Assert(_Target != null); DxGeometry resolved = _GeometryCache.ResolveGeometry(shape); Contract.Assert(resolved != null); _Target.FillGeometry(resolved, brush); }
public void Stroke( Rectangle rectangleRegion, Size roundedRectangleRadius, Brush brush, StrokeStyle style, float strokeWidth) { Contract.Requires(Check.IsPositive(roundedRectangleRadius.Width)); Contract.Requires(Check.IsPositive(roundedRectangleRadius.Height)); Contract.Requires(brush != null); Contract.Requires(style != null); Contract.Requires(Check.IsPositive(strokeWidth)); Contract.Assert(_Target != null); Rectangle newRegion; ToStrokeable(ref rectangleRegion, strokeWidth, strokeWidth, out newRegion); FitStroke(ref newRegion, strokeWidth, strokeWidth, out newRegion); RectangleF rectangle = RectangleF.Empty; rectangle.Left = newRegion.Left; rectangle.Top = newRegion.Top; rectangle.Right = newRegion.Right; rectangle.Bottom = newRegion.Bottom; RoundedRectangle roundedRectangle = new RoundedRectangle { Rect = rectangle, RadiusX = roundedRectangleRadius.Width, RadiusY = roundedRectangleRadius.Height }; _Target.DrawRoundedRectangle(roundedRectangle, brush, strokeWidth, style); }
private void Form1_Load(object sender, EventArgs e) { //Init Direct Draw //Set Rendering properties RenderTargetProperties renderProp = new RenderTargetProperties() { DpiX = 0, DpiY = 0, MinLevel = FeatureLevel.Level_10, PixelFormat = new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied), Type = RenderTargetType.Hardware, Usage = RenderTargetUsage.None }; //set hwnd target properties (permit to attach Direct2D to window) HwndRenderTargetProperties winProp = new HwndRenderTargetProperties() { Hwnd = this.Handle, PixelSize = new DrawingSize(this.ClientSize.Width, this.ClientSize.Height), PresentOptions = PresentOptions.Immediately }; //target creation target = new WindowRenderTarget(factory, renderProp, winProp); //create red and white brushes redBrush = new SharpDX.Direct2D1.SolidColorBrush(target, SharpDX.Color.Red); whiteBrush = new SharpDX.Direct2D1.SolidColorBrush(target, SharpDX.Color.White); //create a linear gradient brush var grad = new LinearGradientBrushProperties() { StartPoint = new DrawingPointF(ClientSize.Width / 2, ClientSize.Height / 2), EndPoint = new DrawingPointF(ClientSize.Width, ClientSize.Height) }; var stopCollection = new GradientStopCollection(target, new GradientStop[] { new GradientStop(){Color=SharpDX.Color.Azure ,Position=0F}, new GradientStop(){Color=SharpDX.Color.Yellow,Position=0.2F}, new GradientStop(){Color=SharpDX.Color.Green,Position=0.4F}, new GradientStop(){Color=SharpDX.Color.Red,Position=1F}, }, ExtendMode.Mirror); gradient = new SharpDX.Direct2D1.LinearGradientBrush(target, grad, stopCollection); //create textformat textFormat = new SharpDX.DirectWrite.TextFormat(factoryWrite, "Arial", 36); //avoid artifacts this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); }