OSDN Git Service

render.Flushは遅いので使わないようにした
authorgdkhd812 <test@nnn.co.jp>
Sat, 19 Dec 2015 07:29:04 +0000 (12:59 +0530)
committergdkhd812 <test@nnn.co.jp>
Sat, 19 Dec 2015 07:29:04 +0000 (12:59 +0530)
Core/EditView.cs
Core/PrintableView.cs
Core/ViewBase.cs
WPF/FooEditEngine/Direct2D/D2DRender.cs
WPF/FooEditEngine/FooTextBox.cs
Windows/FooEditEngine/D2DTextRender.cs
Windows/FooEditEngine/FooTextBox.cs

index d1c5934..b892490 100644 (file)
@@ -204,11 +204,12 @@ namespace FooEditEngine
         /// Rectで指定された範囲にドキュメントを描く
         /// </summary>
         /// <param name="updateRect">描写する範囲</param>
-        /// <remarks>キャレットを点滅させる場合、定期的のこのメソッドを呼び出してください</remarks>
-        public override void Draw(Rectangle updateRect)
+        /// <returns>キャッシュしてはならない場合は真を返し、そうでない場合は偽を返します</returns>
+        /// <remarks>描写する範囲がPageBoundより小さい場合、キャッシュされた内容を使用することがあります。なお、レタリング後にrender.CacheContent()を呼び出さなかった場合は更新範囲にかかわらずキャッシュを使用しません</remarks>
+        public override bool Draw(Rectangle updateRect)
         {
             if (this.LayoutLines.Count == 0)
-                return;
+                return false;
 
             IEditorRender render = (IEditorRender)base.render;
 
@@ -300,13 +301,10 @@ namespace FooEditEngine
 
                 this.DrawInsertPoint();
 
-                render.CacheContent();
+                this.Document.SelectGrippers.BottomLeft.Draw(this.render);
+                this.Document.SelectGrippers.BottomRight.Draw(this.render);
             }
-
-            this.DrawCaret();
-
-            this.Document.SelectGrippers.BottomLeft.Draw(this.render);
-            this.Document.SelectGrippers.BottomRight.Draw(this.render);
+            return this.DrawCaret();    //キャレットを描いた場合はキャッシュしてはならない
         }
 
         void DrawUpdateArea(int row,double ypos)
@@ -400,16 +398,16 @@ namespace FooEditEngine
             }
         }
 
-        void DrawCaret()
+        bool DrawCaret()
         {
             if (this.HideCaret || !this.IsFocused)
-                return;
+                return false;
 
             long diff = DateTime.Now.Ticks - this.tickCount;
             long blinkTime = this.To100nsTime(this.CaretBlinkTime);
 
             if (this.CaretBlink && diff % blinkTime >= blinkTime / 2)
-                return;
+                return false;
 
             Rectangle CaretRect = new Rectangle();
 
@@ -432,6 +430,7 @@ namespace FooEditEngine
                 CaretRect.Location = new Point(this.CaretLocation.X, this.CaretLocation.Y + lineHeight - height);
                 render.FillRectangle(CaretRect, FillRectType.OverwriteCaret);
             }
+            return true;
         }
 
         long To100nsTime(int ms)
index 8c41b12..c84019a 100644 (file)
@@ -31,10 +31,10 @@ namespace FooEditEngine
             set;
         }
 
-        public override void Draw(Rectangle updateRect)
+        public override bool Draw(Rectangle updateRect)
         {
             if (this.LayoutLines.Count == 0)
-                return;
+                return false;
 
             if (this.Hilighter != null)
                 this.Hilighter.Reset();
@@ -77,6 +77,8 @@ namespace FooEditEngine
                 this.render.DrawString(this.Footer, pos.X, pos.Y, StringAlignment.Center,
                     new Size(render.TextArea.Width - this.GetRealtiveX(AreaType.TextArea), render.FooterHeight));
             }
+
+            return false;
         }
 
         public bool TryPageDown()
index c38c42c..4107e87 100644 (file)
@@ -281,8 +281,9 @@ namespace FooEditEngine
             set { this.Document.Src = value; }
         }
 
-        public virtual void Draw(Rectangle updateRect)
+        public virtual bool Draw(Rectangle updateRect)
         {
+            return false;
         }
 
         public virtual bool TryScroll(double x, int row)
index 4f31c7b..f8c57f0 100644 (file)
@@ -269,7 +269,7 @@ namespace FooEditEngine.WPF
         {
             if (this.render == null || this.cachedBitMap == null || this.cachedBitMap.IsDisposed || this.render.IsDisposed)
                 return;
-            render.Flush();
+            //render.Flush();
             this.cachedBitMap.CopyFromRenderTarget(this.render, new SharpDX.Point(), new SharpDX.Rectangle(0, 0, (int)this.renderSize.Width, (int)this.renderSize.Height));
             this.hasCache = true;
         }
index 5176871..2e47599 100644 (file)
@@ -443,11 +443,15 @@ namespace FooEditEngine.WPF
                 return;
 
             this.Render.BegineDraw();
+            bool useCache = false;
             if (this.IsEnabled)
-                this.View.Draw(updateRect);
+                useCache = this.View.Draw(updateRect);
             else
                 this.Render.FillBackground(updateRect);
             this.Render.EndDraw();
+            //キャッシュされた内容が使用されていない=キャレットが描かれてない
+            if(!useCache)
+                this.Render.CacheContent();
         }
 
         #region Commands
index f4b87bb..f1bc109 100644 (file)
@@ -95,7 +95,7 @@ namespace FooEditEngine.Windows
         {
             if (this.render == null || this.cachedBitMap == null || this.cachedBitMap.IsDisposed || this.render.IsDisposed)
                 return;
-            render.Flush();
+            //render.Flush();
             this.cachedBitMap.CopyFromRenderTarget(this.render, new SharpDX.Point(), new SharpDX.Rectangle(0, 0, (int)this.renderSize.Width, (int)this.renderSize.Height));
             this.hasCache = true;
         }
index ff10a88..a89af16 100644 (file)
@@ -1050,6 +1050,7 @@ namespace FooEditEngine.Windows
         {
             base.OnGotFocus(e);
             this.View.IsFocused = true;
+            this.Timer.Start();
             this.Refresh();
         }
 
@@ -1061,6 +1062,7 @@ namespace FooEditEngine.Windows
         {
             base.OnLostFocus(e);
             this.View.IsFocused = false;
+            this.Timer.Stop();
             this.Refresh();
         }
 
@@ -1208,8 +1210,10 @@ namespace FooEditEngine.Windows
                 brush.Dispose();
             }else if (this.Document.FireUpdateEvent){
                 this.render.BegineDraw();
-                this.View.Draw(e.ClipRectangle);
+                bool useCache = this.View.Draw(e.ClipRectangle);
                 this.render.EndDraw();
+                if (!useCache)
+                    this.render.CacheContent();
             }
             base.OnPaint(e);
         }
@@ -1500,21 +1504,11 @@ namespace FooEditEngine.Windows
             if (CaretBlinkTime == -1)
             {
                 this.View.CaretBlink = false;
-                if (this.IsHandleCreated)
-                    this.BeginInvoke(new Action(() =>
-                    {
-                    this.Timer.Stop();
-                    }));
             }
             else
             {
                 this.View.CaretBlink = true;
                 this.View.CaretBlinkTime = CaretBlinkTime * 2;
-                if(this.IsHandleCreated)
-                    this.BeginInvoke(new Action(() =>
-                    {
-                        this.Timer.Start();
-                    }));
             }
             this.View.CaretWidthOnInsertMode = SystemInformation.CaretWidth;
         }