public TextShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, DWriteFactory dwriteFactory) : base(initialRenderTarget, random, d2DFactory, bitmap) { this.dwriteFactory = dwriteFactory; layoutRect = RandomRect(CanvasWidth, CanvasHeight); NiceGabriola = Random.NextDouble() < 0.25 && dwriteFactory.SystemFontFamilyCollection.Contains("Gabriola"); TextFormat = dwriteFactory.CreateTextFormat( RandomFontFamily(), RandomFontSize(), RandomFontWeight(), RandomFontStyle(), RandomFontStretch(), System.Globalization.CultureInfo.CurrentUICulture); if (CoinFlip) { TextFormat.LineSpacing = RandomLineSpacing(TextFormat.FontSize); } Text = RandomString(Random.Next(1000, 1000)); FillBrush = RandomBrush(); RenderingParams = RandomRenderingParams(); if (CoinFlip) { Options = DrawTextOptions.None; if (CoinFlip) { Options |= DrawTextOptions.Clip; } if (CoinFlip) { Options |= DrawTextOptions.NoSnap; } } }
protected virtual void DisposeDirectXResources() { DwFactory?.Dispose(); RenderTarget?.Dispose(); D2DFactory?.Dispose(); D3DDevice?.Dispose(); }
public MeshShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { FillBrush = RandomBrush(); mesh = CoinFlip ? MeshFromRandomGeometry() : MeshFromRandomTriangles(); }
public GeometryShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { coolStrokes = CoinFlip; double which = Random.NextDouble(); if (which < 0.67 || coolStrokes) { PenBrush = RandomBrush(); } if (!coolStrokes && which > 0.33) { FillBrush = RandomBrush(); } if (coolStrokes || CoinFlip) { StrokeStyle = RandomStrokeStyle(); } if (CoinFlip) { worldTransform = RandomMatrix3x2(); } StrokeWidth = RandomStrokeWidth(); geometry = RandomGeometry(); if (coolStrokes || Random.NextDouble() < 0.3) { ModifyGeometry(); } if (coolStrokes && CoinFlip) { ModifyGeometry(); } }
/// <summary> /// アンマネージ リソースの解放およびリセットに関連付けられているアプリケーション定義のタスクを実行します。 /// </summary> public void Dispose() { foreach (var screenContext in screenContexts) { screenContext.Value.Dispose(); } if (CullingRasterizerState != null && !CullingRasterizerState.Disposed) { CullingRasterizerState.Dispose(); } if (NonCullingRasterizerState != null && !NonCullingRasterizerState.Disposed) { NonCullingRasterizerState.Dispose(); } foreach (var disposable in Disposables) { disposable.Dispose(); } if (D2DFactory != null && !D2DFactory.Disposed) { D2DFactory.Dispose(); } if (DWFactory != null && !DWFactory.Disposed) { DWFactory.Dispose(); } if (disposeDeviceManager) { DeviceManager.Dispose(); } }
public MeshShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { FillBrush = RandomBrush(); mesh = CoinFlip ? MeshFromRandomGeometry() : MeshFromRandomTriangles(); }
protected CoordinateTargetView(Target target, RenderTarget canvas, D2DFactory factory, CoordinateSystem coordinateSystem) : base(target) { if (target == null) { return; } this.canvas = canvas; this.factory = factory; CoordinateSystem = coordinateSystem; position = coordinateSystem.CoordinateToPoint(target.CurrentCoordinate); //计算显示坐标 activeRect = new Rect { Left = (int)position.X - activeRectRadius, Top = (int)position.Y - activeRectRadius, Right = (int)position.X + activeRectRadius, Bottom = (int)position.Y + activeRectRadius }; targetController = TargetManagerFactory.CreateTargetManagerController(); targetViewBrush = canvas.CreateSolidColorBrush(Tools.GetColorFFromRgb(255, 128, 0)); //橘黄 }
public TextShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, DWriteFactory dwriteFactory) : base(initialRenderTarget, random, d2DFactory, bitmap) { this.dwriteFactory = dwriteFactory; layoutRect = RandomRect(CanvasWidth, CanvasHeight); NiceGabriola = Random.NextDouble() < 0.25 && dwriteFactory.SystemFontFamilyCollection.Contains("Gabriola"); TextFormat = dwriteFactory.CreateTextFormat( RandomFontFamily(), RandomFontSize(), RandomFontWeight(), RandomFontStyle(), RandomFontStretch(), System.Globalization.CultureInfo.CurrentUICulture); if (CoinFlip) TextFormat.LineSpacing = RandomLineSpacing(TextFormat.FontSize); Text = RandomString(Random.Next(1000, 1000)); FillBrush = RandomBrush(); RenderingParams = RandomRenderingParams(); if (CoinFlip) { Options = DrawTextOptions.None; if (CoinFlip) Options |= DrawTextOptions.Clip; if (CoinFlip) Options |= DrawTextOptions.NoSnap; } }
protected DrawingShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) { renderTarget = initialRenderTarget; Random = random; this.d2DFactory = d2DFactory; this.bitmap = bitmap; shapeID = ++shapesCreated; }
protected void InitializeDirect2D(Panel holder) //用控件初始化Direct2D变量 { Factory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); //创建工厂 var rtps = new RenderTargetProperties(); var hrtp = new HwndRenderTargetProperties(holder.Handle, new SizeU((uint)holder.Width, (uint)holder.Height), PresentOptions.None); Canvas = Factory.CreateHwndRenderTarget(rtps, hrtp); }
protected DrawingShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) { renderTarget = initialRenderTarget; Random = random; this.d2DFactory = d2DFactory; this.bitmap = bitmap; shapeID = ++shapesCreated; }
public LineShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { point0 = RandomPoint(); point1 = RandomPoint(); PenBrush = RandomBrush(); StrokeWidth = RandomStrokeWidth(); if (CoinFlip) StrokeStyle = RandomStrokeStyle(); }
protected virtual void DisposeDirectXResources() { DwFactory.Dispose(); RenderTarget.Dispose(); RenderTargetView.Dispose(); D2DFactory.Dispose(); SwapChain.Dispose(); D3DDeviceContext.Dispose(); D3DDevice.Dispose(); }
public BitmapShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { DestRect = RandomRect(CanvasWidth, CanvasHeight); opacity = RandomOpacity(); DrawSection = Random.NextDouble() < 0.25; if (drawSection) SourceRect = RandomRect( Bitmap.PixelSize.Width, Bitmap.PixelSize.Height); }
public void Initialize() { d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.MultiThreaded); dwriteFactory = DWriteFactory.CreateFactory(); InitializeRenderTarget(); FillFontFamilies(); if (FixedItemHeight) DropDownHeight = (int)maxHeight * 10; DrawMode = DrawMode.OwnerDrawVariable; MeasureItem += FontEnumComboBox_MeasureItem; DrawItem += FontEnumComboBox_DrawItem; }
private void InitializeDisplayerState() { var rtps = new RenderTargetProperties(); var hrtp = new HwndRenderTargetProperties(Panel.Handle, new SizeU((uint)Panel.Width, (uint)Panel.Height), PresentOptions.None); Factory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); //创建工厂 rt = Factory.CreateHwndRenderTarget(rtps, hrtp); rt.AntiAliasMode = AntiAliasMode.Aliased; rt.TextAntiAliasMode = TextAntiAliasMode.Aliased; (rt as HwndRenderTarget).Resize(new SizeU((uint)Panel.Width, (uint)Panel.Height)); rt.Transform = Matrix3x2F.Scale(rt.Size.Width / Panel.Width, rt.Size.Height / Panel.Height); }
public LineShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { point0 = RandomPoint(); point1 = RandomPoint(); PenBrush = RandomBrush(); StrokeWidth = RandomStrokeWidth(); if (CoinFlip) { StrokeStyle = RandomStrokeStyle(); } }
void host_Loaded(object sender, RoutedEventArgs e) { // Create the D2D Factory d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); // Create the DWrite Factory dwriteFactory = DWriteFactory.CreateFactory(); // Start rendering now! host.Render = Render; host.InvalidateVisual(); }
protected D2DFactory Factory; //用于计算pathGeometry protected CoordinateSystem(Rect drawArea, double range, D2DFactory factory) //drawArea为的目标区域和坐标刻度区域的和 { // ReSharper disable once VirtualMemberCallInConstructor _coordinateArea = FindCoordinateArea(drawArea); //绘制坐标系的范围 OriginalRect = _coordinateArea; VisibleArea = drawArea; VisibleCenter = Tools.FindCenterPosition(VisibleArea); // ReSharper disable once VirtualMemberCallInConstructor OriginalPoint = FindOriginalPoint(_coordinateArea); //原点位置 Range = range; Factory = factory; }
void host_Loaded(object sender, RoutedEventArgs e) { // Create the D2D Factory d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); // Create the DWrite Factory dwriteFactory = DWriteFactory.CreateFactory(); // Start rendering now! host.Render = Render; host.InvalidateVisual(); }
protected override void Dispose(bool disposing) { if (Disposing) { DisposeRenderObjects(); if (D2DFactory != null) { D2DFactory.Dispose(); D2DFactory = null; } } base.Dispose(disposing); }
public GDIEllipsesShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, int count) : base(initialRenderTarget, random, d2DFactory, bitmap) { for(int i = 0; i < count; i++) { ellipses.Add(RandomGdiEllipse()); } if (RenderTargetSupportsGDI(RenderTarget)) { gdiRenderTarget = RenderTarget.GetGdiInteropRenderTarget(); } }
public RoundRectangleShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { rect = RandomRoundedRect(); double which = Random.NextDouble(); if (which < 0.67) PenBrush = RandomBrush(); if (which > 0.33) FillBrush = RandomBrush(); if (CoinFlip) StrokeStyle = RandomStrokeStyle(); StrokeWidth = RandomStrokeWidth(); }
public GDIEllipsesShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, int count) : base(initialRenderTarget, random, d2DFactory, bitmap) { for (int i = 0; i < count; i++) { ellipses.Add(RandomGdiEllipse()); } if (RenderTargetSupportsGDI(RenderTarget)) { gdiRenderTarget = RenderTarget.GdiInteropRenderTarget; } }
public BitmapShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { DestRect = RandomRect(CanvasWidth, CanvasHeight); opacity = RandomOpacity(); DrawSection = Random.NextDouble() < 0.25; if (drawSection) { SourceRect = RandomRect( Bitmap.PixelSize.Width, Bitmap.PixelSize.Height); } }
public void Initialize() { d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); dwriteFactory = DWriteFactory.CreateFactory(); InitializeRenderTarget(); FillFontFamilies(); if (FixedItemHeight) { DropDownHeight = (int)maxHeight * 10; } DrawMode = DrawMode.OwnerDrawVariable; MeasureItem += FontEnumComboBox_MeasureItem; DrawItem += FontEnumComboBox_DrawItem; }
void CreateDeviceIndependentResources() { // Create a Direct2D factory. d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); // Create a DirectWrite factory. dWriteFactory = DWriteFactory.CreateFactory(); // Create a DirectWrite text format object. textFormat = dWriteFactory.CreateTextFormat("Calibri", 50, DWrite.FontWeight.Bold, DWrite.FontStyle.Normal, DWrite.FontStretch.Normal); // Center the text both horizontally and vertically. textFormat.TextAlignment = DWrite.TextAlignment.Leading; textFormat.ParagraphAlignment = ParagraphAlignment.Near; }
public CoordinateTargetDotView(Target target, RenderTarget rt, D2DFactory factory, CoordinateSystem cs) : base(target, rt, factory, cs) { if (!((TargetDot)target).IsClotDot) { targetViewRadius = 2; float redColorValue = CalRedColorValue(target.AmValue); float blueColorValue = CalBlueColorValue(target.AmValue); targetViewBrush = canvas.CreateSolidColorBrush(new ColorF(redColorValue, 0.184f, blueColorValue)); } else { targetViewBrush = canvas.CreateSolidColorBrush(Tools.GetColorFFromRgb((int)(((TargetDot)target).DotWidth * 3.5f), 150, 150)); //绿色 targetViewRadius = 6; } }
public CoordinateTargetTrackView(Target target, RenderTarget rt, D2DFactory factory, CoordinateSystem cs) : base(target, rt, factory, cs) { drawer = CreateDrawer(); PreLocations = new List <Ellipse>(); TargetTrack t = (TargetTrack)target; foreach (PolarCoordinate c in t.Locations) { Point2F p; p = CoordinateSystem.CoordinateToPoint(c); Ellipse e = new Ellipse(p, preLocationRadius, preLocationRadius); PreLocations.Add(e); } targetViewRadius = 4; }
private void CreateFactories() { //reuse factories except for random cases if (random.NextDouble() < 0.5) { lock (sharedSyncObject) { if (sharedD2DFactory == null) { // Create the D2D Factory sharedD2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); // Create the DWrite Factory sharedDwriteFactory = DWriteFactory.CreateFactory(); // Create the WIC Factory sharedWicFactory = ImagingFactory.Create(); Debug.Assert(sharedD2DFactory.NativeInterface != IntPtr.Zero); Debug.Assert(sharedDwriteFactory.NativeInterface != IntPtr.Zero); Debug.Assert(sharedWicFactory.NativeInterface != IntPtr.Zero); } sharedRefCount++; } d2DFactory = sharedD2DFactory; dwriteFactory = sharedDwriteFactory; wicFactory = sharedWicFactory; Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero); Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero); Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero); } else { // Create the D2D Factory d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); // Create the DWrite Factory dwriteFactory = DWriteFactory.CreateFactory(); // Create the WIC Factory wicFactory = ImagingFactory.Create(); Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero); Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero); Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero); } }
public SideViewDisplayerBackground(RenderTarget canvas, D2DFactory factory, CoordinateSystem csp) : base(canvas, factory, csp) { axisBrush = canvas.CreateSolidColorBrush(new ColorF(0, 255, 0)); //绿色 dashLineBrush = canvas.CreateSolidColorBrush(new ColorF(128, 138, 135)); //冷灰 DWriteFactory dw = DWriteFactory.CreateFactory(); xTextFromation = dw.CreateTextFormat("Berlin Sans FB Demi", 15); yTextFromation = dw.CreateTextFormat("Berlin Sans FB Demi", 15); yTextFromation.TextAlignment = TextAlignment.Trailing; textBrush = canvas.CreateSolidColorBrush(new ColorF(new ColorI(128, 138, 135))); angleLines = new float[] { 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330 }; angleNumbers = new float[] { 0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360 }; distanceNumbers = new[] { 0, Distance / 6, Distance / 3, Distance / 2, Distance * 2 / 3, Distance * 5 / 6, Distance }; dw.Dispose(); }
public EllipseShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { ellipse = RandomEllipse(); double which = Random.NextDouble(); if (which < 0.67) { PenBrush = RandomBrush(); } if (which > 0.33) { FillBrush = RandomBrush(); } if (CoinFlip) { StrokeStyle = RandomStrokeStyle(); } StrokeWidth = RandomStrokeWidth(); }
public Direct2DRenderer(IntPtr pWindowHandle) { Control control = Control.FromHandle(pWindowHandle); var renderProps = new RenderTargetProperties { PixelFormat = new PixelFormat( Microsoft.WindowsAPICodePack.DirectX.DXGI.Format.B8G8R8A8_UNORM, AlphaMode.Ignore), Usage = RenderTargetUsage.None, Type = RenderTargetType.Default // Software type is required to allow resource // sharing between hardware (HwndRenderTarget) // and software (WIC Bitmap render Target). }; _renderer = D2DFactory.CreateHwndRenderTarget( renderProps, new HwndRenderTargetProperties(pWindowHandle, new SizeU(Convert.ToUInt32(control.ClientSize.Width), Convert.ToUInt32(control.ClientSize.Height)), PresentOptions.Immediately)); }
public RectangleShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { rect = RandomRect(CanvasWidth, CanvasHeight); double which = Random.NextDouble(); if (which < 0.67) { PenBrush = RandomBrush(); } if (which > 0.33) { FillBrush = RandomBrush(); } if (CoinFlip) { StrokeStyle = RandomStrokeStyle(); } StrokeWidth = RandomStrokeWidth(); }
public GeometryShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { coolStrokes = CoinFlip; double which = Random.NextDouble(); if (which < 0.67 || coolStrokes) PenBrush = RandomBrush(); if (!coolStrokes && which > 0.33) FillBrush = RandomBrush(); if (coolStrokes || CoinFlip) StrokeStyle = RandomStrokeStyle(); if (CoinFlip) worldTransform = RandomMatrix3x2(); StrokeWidth = RandomStrokeWidth(); geometry = RandomGeometry(); if (coolStrokes || Random.NextDouble() < 0.3) ModifyGeometry(); if (coolStrokes && CoinFlip) { ModifyGeometry(); } }
public LayerShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, int count) : base(initialRenderTarget, random, d2DFactory, bitmap) { Parameters = new LayerParameters(); parameters.ContentBounds = CoinFlip ? RandomRect(CanvasWidth, CanvasHeight) : new RectF(0, 0, CanvasWidth, CanvasHeight); if (CoinFlip) { GeometricMaskShape = new GeometryShape(initialRenderTarget, random, d2DFactory, Bitmap); parameters.GeometricMask = GeometricMaskShape.Geometry; } parameters.MaskAntialiasMode = CoinFlip ? AntialiasMode.Aliased : AntialiasMode.PerPrimitive; parameters.MaskTransform = RandomMatrix3x2(); parameters.Opacity = RandomOpacity(); if (CoinFlip) parameters.OpacityBrush = RandomOpacityBrush(); parameters.Options = CoinFlip ? LayerOptions.InitializeForClearType : LayerOptions.None; for(int i = 0; i < count; i++) { shapes.Add(RandomShape()); } }
protected override void Dispose(bool disposing) { if (disposing) { //dispose of all layouts while (layouts.Keys.Count > 0) { foreach (string key in layouts.Keys) { layouts[key].Dispose(); layouts.Remove(key); break; } } if (brush != null) { brush.Dispose(); } brush = null; if (dcRenderTarget != null) { dcRenderTarget.Dispose(); } dcRenderTarget = null; if (dwriteFactory != null) { dwriteFactory.Dispose(); } dwriteFactory = null; if (d2DFactory != null) { d2DFactory.Dispose(); } d2DFactory = null; } base.Dispose(disposing); }
private void LoadDeviceIndependentResource() { // Create the D2D Factory // This really needs to be set to type MultiThreaded if rendering is to be performed by multiple threads, // such as if used in a control similar to DirectControl sample control where rendering is done by a dedicated render thread, // especially if multiple such controls are used in one application, but also when multiple applications use D2D Factories. // // In this sample - SingleThreaded type is used because rendering is only done by the main/UI thread and only when required // (when the surface gets invalidated) making the risk of synchronization problems - quite low. d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); // Create the DWrite Factory dwriteFactory = DWriteFactory.CreateFactory(); // Create the WIC Factory wicFactory = ImagingFactory.Create(); TextBoxStroke = d2dFactory.CreateStrokeStyle( new StrokeStyleProperties( CapStyle.Flat, CapStyle.Flat, CapStyle.Round, LineJoin.Miter, 5.0f, DashStyle.Dash, 3f), null); }
private void CreateDeviceIndependentResources() { // Create the D2D Factory d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); // Create the DWrite Factory dwriteFactory = DWriteFactory.CreateFactory(); wicFactory = ImagingFactory.Create(); string text = "Inline Object * Sample"; textFormat = dwriteFactory.CreateTextFormat("Gabriola", 72); textFormat.TextAlignment = DWrite.TextAlignment.Center; textFormat.ParagraphAlignment = DWrite.ParagraphAlignment.Center; textLayout = dwriteFactory.CreateTextLayout( text, textFormat, (float)host.ActualWidth, (float)host.ActualHeight); }
private void CreateDeviceIndependentResources() { // Create the D2D Factory d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); // Create the DWrite Factory dwriteFactory = DWriteFactory.CreateFactory(); wicFactory = new ImagingFactory(); string text = "Inline Object * Sample"; textFormat = dwriteFactory.CreateTextFormat("Gabriola", 72); textFormat.TextAlignment = DWrite.TextAlignment.Center; textFormat.ParagraphAlignment = DWrite.ParagraphAlignment.Center; textLayout = dwriteFactory.CreateTextLayout( text, textFormat, (float) host.ActualWidth, (float) host.ActualHeight); }
public void Dispose() { foreach (KeyValuePair <string, D2D1.Brush> p in Brushes) { p.Value.Dispose(); } DashStyle.Dispose(); D2DTarget.Dispose(); D2DDevice.Dispose(); D2DContext.Dispose(); D2DFactory.Dispose(); BlackTextureView.Dispose(); WhiteTextureView.Dispose(); AnisotropicSampler.Dispose(); blendStateOpaque.Dispose(); blendStateTransparent.Dispose(); rasterizerStateSolidCullBack.Dispose(); rasterizerStateWireframeCullBack.Dispose(); rasterizerStateSolidNoCull.Dispose(); rasterizerStateWireframeNoCull.Dispose(); depthStencilStateDefault.Dispose(); depthStencilStateNoDepth.Dispose(); foreach (Camera c in Cameras) { c.Dispose(); } constantBuffer.Dispose(); swapChain.Dispose(); Device.Dispose(); Context.Dispose(); }
private void Situation_Load(object sender, EventArgs e) { Console.WriteLine("load!!"); // create factory (un-managed resource) d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); dwriteFactory = DWriteFactory.CreateFactory(); // target RenderTargetProperties renderTargetProperties = new RenderTargetProperties { PixelFormat = new PixelFormat(), Usage = RenderTargetUsages.None, RenderTargetType = RenderTargetType.Default }; // handle HwndRenderTargetProperties hwndRenderTargetProperties1 = new HwndRenderTargetProperties { WindowHandle = this.pictureBox1.Handle, PixelSize = new SizeU((uint)this.pictureBox1.Width, (uint)this.pictureBox1.Height), PresentOptions = PresentOptions.Immediately }; renderTarget = d2DFactory.CreateHwndRenderTarget(renderTargetProperties, hwndRenderTargetProperties1); // create blushes blackBlush = renderTarget.CreateSolidColorBrush(new ColorF(0.0f, 0.0f, 0.0f)); redBlush = renderTarget.CreateSolidColorBrush(new ColorF(1.0f, 0.0f, 0.0f)); greenBlush = renderTarget.CreateSolidColorBrush(new ColorF(0.0f, 1.0f, 0.0f)); blueBlush = renderTarget.CreateSolidColorBrush(new ColorF(0.0f, 0.0f, 1.0f)); // define and start onPaintTimer onPaintTimer = new Timer(); onPaintTimer.Interval = 500; onPaintTimer.Tick += Render; onPaintTimer.Start(); }
private void LoadDeviceIndependentResource() { // Create the D2D Factory // This really needs to be set to type MultiThreaded if rendering is to be performed by multiple threads, // such as if used in a control similar to DirectControl sample control where rendering is done by a dedicated render thread, // especially if multiple such controls are used in one application, but also when multiple applications use D2D Factories. // // In this sample - SingleThreaded type is used because rendering is only done by the main/UI thread and only when required // (when the surface gets invalidated) making the risk of synchronization problems - quite low. d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); // Create the DWrite Factory dwriteFactory = DWriteFactory.CreateFactory(); // Create the WIC Factory wicFactory = ImagingFactory.Create(); TextBoxStroke = d2dFactory.CreateStrokeStyle( new StrokeStyleProperties( CapStyle.Flat, CapStyle.Flat, CapStyle.Round, LineJoin.Miter, 5.0f, DashStyle.Dash, 3f), null); }
private void CreateFactories() { // Create the D2D Factory d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.MultiThreaded); // Create the DWrite Factory dwriteFactory = DWriteFactory.CreateFactory(); // Create the WIC Factory wicFactory = new ImagingFactory(); Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero); Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero); Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero); }
/// <summary> /// Dispose of resources (IDisposable implementation) /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (disposing && !disposed) { lock (renderSyncObject) { render = null; lock (sharedSyncObject) { if (sharedD2DFactory != null && d2DFactory == sharedD2DFactory) sharedRefCount--; if (d2DFactory != null && d2DFactory != sharedD2DFactory) d2DFactory.Dispose(); d2DFactory = null; if (dwriteFactory != null && dwriteFactory != sharedDwriteFactory) dwriteFactory.Dispose(); dwriteFactory = null; if (wicFactory != null && wicFactory != sharedWicFactory) wicFactory.Dispose(); wicFactory = null; if (sharedRefCount == 0) { if (sharedD2DFactory != null) sharedD2DFactory.Dispose(); sharedD2DFactory = null; if (sharedDwriteFactory != null) sharedDwriteFactory.Dispose(); sharedDwriteFactory = null; if (sharedWicFactory != null) sharedWicFactory.Dispose(); sharedWicFactory = null; } } foreach (DrawingShape shape in drawingShapes) { shape.Dispose(); } if (bitmap != null) bitmap.Dispose(); bitmap = null; if (dcRenderTarget != null) dcRenderTarget.Dispose(); dcRenderTarget = null; if (bitmapRenderTarget != null) bitmapRenderTarget.Dispose(); bitmapRenderTarget = null; if (hwndRenderTarget != null) hwndRenderTarget.Dispose(); hwndRenderTarget = null; disposed = true; } } base.Dispose(disposing); }
private void CreateFactories() { //reuse factories except for random cases if (random.NextDouble() < 0.5) { lock (sharedSyncObject) { if (sharedD2DFactory == null) { // Create the D2D Factory sharedD2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); // Create the DWrite Factory sharedDwriteFactory = DWriteFactory.CreateFactory(); // Create the WIC Factory sharedWicFactory = ImagingFactory.Create(); Debug.Assert(sharedD2DFactory.NativeInterface != IntPtr.Zero); Debug.Assert(sharedDwriteFactory.NativeInterface != IntPtr.Zero); Debug.Assert(sharedWicFactory.NativeInterface != IntPtr.Zero); } sharedRefCount++; } d2DFactory = sharedD2DFactory; dwriteFactory = sharedDwriteFactory; wicFactory = sharedWicFactory; Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero); Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero); Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero); } else { // Create the D2D Factory d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); // Create the DWrite Factory dwriteFactory = DWriteFactory.CreateFactory(); // Create the WIC Factory wicFactory = ImagingFactory.Create(); Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero); Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero); Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero); } }
public TextLayoutShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, DWriteFactory dwriteFactory) : base(initialRenderTarget, random, d2DFactory, bitmap, dwriteFactory) { RandomizeTextLayout(); Point0 = RandomPoint(); }
void CreateDeviceIndependentResources() { string msc_fontName = "Verdana"; float msc_fontSize = 50; string fps_fontName = "Courier New"; float fps_fontSize = 12; GeometrySink spSink; // Create D2D factory d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); // Create WIC factory imagingFactory = ImagingFactory.Create(); // Create DWrite factory dWriteFactory = DWriteFactory.CreateFactory(); // Create DWrite text format object textFormat = dWriteFactory.CreateTextFormat( msc_fontName, msc_fontSize); textFormat.TextAlignment = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.TextAlignment.Center; textFormat.ParagraphAlignment = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.ParagraphAlignment.Center; // Create DWrite text format object textFormatFps = dWriteFactory.CreateTextFormat( fps_fontName, fps_fontSize); textFormatFps.TextAlignment = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.TextAlignment.Leading; textFormatFps.ParagraphAlignment = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.ParagraphAlignment.Near; // Create the path geometry. pathGeometry = d2DFactory.CreatePathGeometry(); // Write to the path geometry using the geometry sink. We are going to create an // hour glass. spSink = pathGeometry.Open(); spSink.SetFillMode(Microsoft.WindowsAPICodePack.DirectX.Direct2D1.FillMode.Alternate); spSink.BeginFigure( new Point2F(0, 0), FigureBegin.Filled ); spSink.AddLine(new Point2F(200, 0)); spSink.AddBezier( new BezierSegment( new Point2F(150, 50), new Point2F(150, 150), new Point2F(200, 200) )); spSink.AddLine( new Point2F(0, 200) ); spSink.AddBezier( new BezierSegment( new Point2F(50, 150), new Point2F(50, 50), new Point2F(0, 0) )); spSink.EndFigure( FigureEnd.Closed ); spSink.Close( ); }
protected override void Dispose(bool disposing) { if (disposing) { //dispose of all layouts while (layouts.Keys.Count > 0) foreach (string key in layouts.Keys) { layouts[key].Dispose(); layouts.Remove(key); break; } if (brush != null) brush.Dispose(); brush = null; if (dcRenderTarget != null) dcRenderTarget.Dispose(); dcRenderTarget = null; if (dwriteFactory != null) dwriteFactory.Dispose(); dwriteFactory = null; if (d2DFactory != null) d2DFactory.Dispose(); d2DFactory = null; } base.Dispose(disposing); }
void CreateDeviceIndependentResources() { // Create a Direct2D factory. d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded); // Create a DirectWrite factory. dWriteFactory = DWriteFactory.CreateFactory(); // Create a DirectWrite text format object. textFormat = dWriteFactory.CreateTextFormat("Calibri", 50, DWrite.FontWeight.Bold, DWrite.FontStyle.Normal, DWrite.FontStretch.Normal); // Center the text both horizontally and vertically. textFormat.TextAlignment = DWrite.TextAlignment.Leading; textFormat.ParagraphAlignment = ParagraphAlignment.Near; }