OSDN Git Service

メトロ版でもカーソルを点滅できるようにしてみた&コードの整理
[fooeditengine/FooEditEngine.git] / Core / Direct2D / D2DRenderCommon.cs
index 2238410..bb850ae 100644 (file)
@@ -186,13 +186,15 @@ namespace FooEditEngine
         D2D.Factory D2DFactory;
 #endif
         DW.TextFormat format;
-        D2D.Bitmap bitmap;
+        protected D2D.Bitmap CachedBitmap;
         D2D.RenderTarget render;
         CustomTextRenderer textRender;
         int tabLength = 8;
-        bool hasCache, _ShowLineBreak;
-        Size renderSize = new Size();
+        bool _ShowLineBreak;
         Color4 _Comment, _Literal, _Keyword1, _Keyword2;
+        protected bool hasCache;
+
+        protected Size renderSize { get; private set; }
 
         public D2DRenderCommon()
         {
@@ -205,6 +207,7 @@ namespace FooEditEngine
             this.Strokes.Factory = this.D2DFactory;
             this.ChangedRenderResource += (s, e) => { };
             this.ChangedRightToLeft += (s, e) => { };
+            this.renderSize = new Size();
         }
 
         public event ChangedRenderResourceEventHandler ChangedRenderResource;
@@ -213,6 +216,13 @@ namespace FooEditEngine
 
         public const int MiniumeWidth = 40;    //これ以上ないと誤操作が起こる
 
+        public double GetScale()
+        {
+            float dpi;
+            this.GetDpi(out dpi, out dpi);
+            return dpi / 96.0;
+        }
+
         public void InitTextFormat(string fontName, float fontSize, DW.FontWeight fontWeigth = DW.FontWeight.Normal,DW.FontStyle fontStyle = DW.FontStyle.Normal)
         {
             if(this.format != null)
@@ -557,21 +567,12 @@ namespace FooEditEngine
             this.DestructDeviceResource();
             this.ConstructDeviceResource(width, height);
         }
-
         public virtual void DrawCachedBitmap(Rectangle rect)
         {
-            if (this.render == null || this.render.IsDisposed)
-                return;
-            render.DrawBitmap(this.bitmap, rect, 1.0f, D2D.BitmapInterpolationMode.Linear, rect);
         }
 
         public virtual void CacheContent()
         {
-            if (this.render == null || this.bitmap == null || this.bitmap.IsDisposed || this.render.IsDisposed)
-                return;
-            render.Flush();
-            this.bitmap.CopyFromRenderTarget(this.render, new SharpDX.Point(), new SharpDX.Rectangle(0, 0, (int)this.renderSize.Width, (int)this.renderSize.Height));
-            this.hasCache = true;
         }
 
         public virtual bool IsVaildCache()
@@ -855,7 +856,7 @@ namespace FooEditEngine
             this.GetDpi(out dpiX, out dpiY);
             D2D.RenderTargetProperties prop = new D2D.RenderTargetProperties(
                 D2D.RenderTargetType.Default,
-                new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Ignore),
+                new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied),
                 dpiX,
                 dpiY,
                 D2D.RenderTargetUsage.None,
@@ -868,16 +869,15 @@ namespace FooEditEngine
             D2D.BitmapProperties bmpProp = new D2D.BitmapProperties();
             bmpProp.DpiX = dpiX;
             bmpProp.DpiY = dpiY;
-            bmpProp.PixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Ignore);
-            this.bitmap = new D2D.Bitmap(this.render, new SharpDX.Size2((int)width, (int)height), bmpProp);
+            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.ConstrctedResource();
 
             this.textRender = new CustomTextRenderer(this.render, this.Brushes,this.Strokes, this.Foreground);
 
-            this.renderSize.Width = width;
-            this.renderSize.Height = height;
+            this.renderSize = new Size(width,height);
 
             this.TextAntialiasMode = this._TextAntialiasMode;
         }
@@ -915,8 +915,8 @@ namespace FooEditEngine
         public void DestructDeviceResource()
         {
             this.hasCache = false;
-            if (this.bitmap != null)
-                this.bitmap.Dispose();
+            if (this.CachedBitmap != null)
+                this.CachedBitmap.Dispose();
             this.Brushes.Clear();
             this.Strokes.Clear();
             this.Effects.Clear();