D3D11.Device device;
D3D9.Device device9;
D3D9.Surface surface9;
- new D2D.RenderTarget render;
double fontSize;
FontFamily fontFamily;
FontWeight fontWeigth;
FontStyle fontStyle;
D3DImage imageSource;
- public D2DRender(FooTextBox textbox, double width, double height,Image image)
+ public D2DRender(FooTextBox textbox, double width, double height, Image image)
{
this.fontFamily = textbox.FontFamily;
this.fontSize = textbox.FontSize;
this.LineMarker = ToColor4(textbox.LineMarker);
this.UpdateArea = ToColor4(textbox.UpdateArea);
this.LineNumber = ToColor4(textbox.LineNumber);
+ this.HilightForeground = ToColor4(textbox.HilightForeground);
this.store = textbox.TextStore;
this.CreateDevice();
- this.ConstructDeviceResource(width, height);
+ this.ConstructRenderAndResource(width, height);
this.InitTextFormat(this.fontFamily.Source, (float)this.fontSize, this.GetDWFontWeigth(this.fontWeigth), this.GetDWFontStyle(this.fontStyle));
this.imageSource = new D3DImage();
set
{
this.fontWeigth = value;
- this.InitTextFormat(this.fontFamily.Source, (float)this.fontSize, this.GetDWFontWeigth(value),this.GetDWFontStyle(this.fontStyle));
+ this.InitTextFormat(this.fontFamily.Source, (float)this.fontSize, this.GetDWFontWeigth(value), this.GetDWFontStyle(this.fontStyle));
}
}
{
if (Math.Floor(width) != Math.Floor(this.imageSource.Width) || Math.Floor(height) != Math.Floor(this.imageSource.Height))
{
- this.ReConstructDeviceResource(width, height);
+ this.ReConstructRenderAndResource(width, height);
this.imageSource.Lock();
this.imageSource.SetBackBuffer(D3DResourceType.IDirect3DSurface9, this.surface9.NativePointer);
this.imageSource.Unlock();
return false;
}
- public void DrawContent(EditView view,bool IsEnabled,Rectangle updateRect)
+ public void ReConstructRenderAndResource(double width, double height)
+ {
+ this.DestructRenderAndResource();
+ this.ConstructRenderAndResource(width, height);
+ }
+
+ public void DrawContent(EditView view, bool IsEnabled, Rectangle updateRect)
{
if (this.imageSource.IsFrontBufferAvailable)
{
base.EndDraw();
this.device.ImmediateContext.Flush();
- this.imageSource.AddDirtyRect(new Int32Rect(0, 0, (int)this.imageSource.Width, (int)this.imageSource.Height));
+ this.imageSource.AddDirtyRect(new Int32Rect(0, 0, (int)this.imageSource.PixelWidth, (int)this.imageSource.PixelHeight));
this.imageSource.Unlock();
}
}
- public void DrawOneLine(LineToIndexTable lti, int row, double x, double y, IEnumerable<Selection> SelectRanges)
+ public void DrawOneLine(Document doc, LineToIndexTable lti, int row, double x, double y)
{
PreDrawOneLineHandler PreDrawOneLine = null;
if (InputMethod.Current.ImeState == InputMethodState.On)
PreDrawOneLine = this.DrawImeConversionLine;
- base.DrawOneLine(lti,
+ base.DrawOneLine(doc,
+ lti,
row,
x,
y,
- SelectRanges,
- PreDrawOneLine);
+ PreDrawOneLine
+ );
}
- private void DrawImeConversionLine(MyTextLayout layout,LineToIndexTable lti,int row,double x,double y)
+ private void DrawImeConversionLine(MyTextLayout layout, LineToIndexTable lti, int row, double x, double y)
{
using (Unlocker locker = this.store.LockDocument(false))
{
private Color4? GetColor4(TF_DA_COLOR cr)
{
COLORREF colorref;
- switch(cr.type)
+ switch (cr.type)
{
case TF_DA_COLORTYPE.TF_CT_SYSCOLOR:
colorref = new COLORREF(NativeMethods.GetSysColor((int)cr.indexOrColorRef));
return new Color4(colorref.R / 255.0f, colorref.G / 255.0f, colorref.B / 255.0f, 1);
}
- public override void Dispose()
- {
- base.Dispose();
- this.DestructDevice();
- }
-
DW.FontStyle GetDWFontStyle(FontStyle style)
{
return (DW.FontStyle)Enum.Parse(typeof(DW.FontStyle), style.ToString());
public override void DrawCachedBitmap(Rectangle rect)
{
- if (this.render == null || this.render.IsDisposed)
+ if (this.render == null || this.render.IsDisposed || this.cachedBitMap == null || this.cachedBitMap.IsDisposed)
return;
render.DrawBitmap(this.cachedBitMap, rect, 1.0f, D2D.BitmapInterpolationMode.Linear, rect);
}
}
}
- protected override void ReCreateTarget()
+ public void ConstructRenderAndResource(double width, double height)
{
- System.Diagnostics.Debug.WriteLine("ReCreatedDevice");
- this.DestructDevice();
- this.CreateDevice();
- this.ReConstructDeviceResource();
- }
+ float dpiX, dpiY;
+ this.GetDpi(out dpiX, out dpiY);
+ D2D.RenderTargetProperties prop = new D2D.RenderTargetProperties(
+ D2D.RenderTargetType.Default,
+ new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied),
+ dpiX,
+ dpiY,
+ D2D.RenderTargetUsage.None,
+ D2D.FeatureLevel.Level_DEFAULT);
- protected override D2D.RenderTarget ConstructRender(D2D.Factory factory, D2D.RenderTargetProperties prop, double width, double height)
- {
D3D11.Texture2DDescription desc = new D3D11.Texture2DDescription();
desc.Width = (int)width;
desc.Height = (int)height;
resource.Dispose();
texture.Dispose();
- this.render = new D2D.RenderTarget(factory, this.surface, prop);
- return this.render;
- }
+ this.render = new D2D.RenderTarget(D2DRenderShared.D2DFactory, this.surface, prop);
- protected override void ConstrctedResource()
- {
+ D2D.BitmapProperties bmpProp = new D2D.BitmapProperties();
+ bmpProp.DpiX = dpiX;
+ bmpProp.DpiY = dpiY;
+ bmpProp.PixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied);
+ this.cachedBitMap = new D2D.Bitmap(this.render, new SharpDX.Size2((int)width, (int)height), bmpProp);
+ this.hasCache = false;
+
+ this.textRender = new CustomTextRenderer(this.Brushes, this.Strokes, this.Foreground);
+
+ this.renderSize = new Size(width, height);
}
- public double GetScale()
+ public void DestructRenderAndResource()
{
- float dpi;
- this.GetDpi(out dpi, out dpi);
- return dpi / 96.0;
+ this.hasCache = false;
+ if (this.cachedBitMap != null)
+ this.cachedBitMap.Dispose();
+ this.Brushes.Clear();
+ this.Strokes.Clear();
+ if (this.textRender != null)
+ this.textRender.Dispose();
+ if (this.texture != null)
+ this.texture.Dispose();
+ if (this.surface != null)
+ this.surface.Dispose();
+ if (this.surface9 != null)
+ this.surface9.Dispose();
+ if (this.render != null)
+ this.render.Dispose();
}
public override void GetDpi(out float dpix, out float dpiy)
dpiy = (int)dpiYProperty.GetValue(null, null);
}
- protected override void DestructRender()
+ protected override void Dispose(bool dispose)
{
- if (this.texture != null)
- this.texture.Dispose();
- if (this.surface != null)
- this.surface.Dispose();
- if (this.surface9 != null)
- this.surface9.Dispose();
- if (this.render != null)
- this.render.Dispose();
+ base.Dispose(dispose);
+ this.DestructRenderAndResource();
+ this.DestructDevice();
}
+
}
}