]> O.S.I.I.S - jp/crow.git/commitdiff
test clipping and text cursor blinking redraw in drawing loop
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 22 Sep 2021 06:19:43 +0000 (06:19 +0000)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 22 Sep 2021 06:19:43 +0000 (06:19 +0000)
Crow/src/2d/Measure.cs
Crow/src/Interface.cs
Crow/src/Widgets/Widget.cs

index b5f475f5d8d1c05225741096cf2ff1d6b9638cf5..4b66a97594c90b41423d6a9814582c0a09e67579 100644 (file)
@@ -53,8 +53,8 @@ namespace Crow
                public bool IsRelativeToParent { get { return Value >= 0 && Units == Unit.Percent; }}
                #region Operators
                public static implicit operator int(Measure m) => m.Value;
-               public static implicit operator Measure(int i) => new Measure(i);               
-               public static implicit operator string(Measure m) => m.ToString();              
+               public static implicit operator Measure(int i) => new Measure(i);
+               public static implicit operator string(Measure m) => m.ToString();
                public static implicit operator Measure(string s) => Measure.Parse(s);
 
                public static bool operator ==(Measure m1, Measure m2) => m1.Equals (m2);
@@ -87,7 +87,7 @@ namespace Crow
                        else if (string.Equals ("Fit", st, StringComparison.Ordinal))
                                return Measure.Fit;
                        else if (string.Equals ("Stretched", s, StringComparison.Ordinal))
-                               return Measure.Stretched;                       
+                               return Measure.Stretched;
                        else {
                                if (st.EndsWith ("%", StringComparison.Ordinal)) {
                                        if (int.TryParse (s.Substring(0, st.Length - 1), out tmp))
index 250d2fb107cc29221386c86860a11bb018b5cd8e..c177cd1bd50d697d122074013ca73de07eee9f3e 100644 (file)
@@ -1073,9 +1073,6 @@ namespace Crow
                                }
 
                                _hoverWidget = value;
-                               if (_hoverWidget.ToString() == "HelloWorld.Program.vs2.Border12")
-                                       Debugger.Break();
-
 
                                NotifyValueChanged ("HoverWidget", _hoverWidget);
                                DbgLogger.AddEvent (DbgEvtType.HoverWidget, _hoverWidget);
@@ -1176,7 +1173,7 @@ namespace Crow
                                                clipping.UnionRectangle(lastDragImageBounds);
                                }
 
-                               if (!clipping.IsEmpty) {
+                               if (!clipping.IsEmpty || shouldDrawTextCursor) {
                                        if (ctx == null) {
                                                using (ctx = new Context (surf))
                                                        processDrawing (ctx);
@@ -1190,7 +1187,6 @@ namespace Crow
                                                ProcessResize (new Rectangle (0,0,(int)vkCtx.width, (int)vkCtx.height));
                                }
 #endif
-
                        } finally {
 
                                PerformanceMeasure.End (PerformanceMeasure.Kind.Update);
@@ -1285,67 +1281,68 @@ namespace Crow
                        DbgLogger.StartEvent (DbgEvtType.ProcessDrawing);
 
                        PerformanceMeasure.Begin (PerformanceMeasure.Kind.Drawing);
-
+                       if (!clipping.IsEmpty) {
 #if VKVG
-                       clear (ctx);
+                               clear (ctx);
 #else
-                       ctx.PushGroup ();
+                               ctx.PushGroup ();
 
-                       if (SolidBackground)
-                               clear (ctx);
+                               if (SolidBackground)
+                                       clear (ctx);
 #endif
 
-                       for (int i = GraphicTree.Count -1; i >= 0 ; i--){
-                               Widget p = GraphicTree[i];
-                               if (!p.IsVisible)
-                                       continue;
-                               if (clipping.OverlapOut (p.Slot))
-                                       continue;
+                               for (int i = GraphicTree.Count -1; i >= 0 ; i--){
+                                       Widget p = GraphicTree[i];
+                                       if (!p.IsVisible)
+                                               continue;
+                                       if (clipping.OverlapOut (p.Slot))
+                                               continue;
 
-                               ctx.Save ();
-                               p.Paint (ctx);
-                               ctx.Restore ();
-                       }
+                                       ctx.Save ();
+                                       p.Paint (ctx);
+                                       ctx.Restore ();
+                               }
 
 
-                       if (lastDragImageBounds != DragImageBounds) {
-                               DirtyRect += lastDragImageBounds;
-                               ctx.Save ();
-                               ctx.ResetClip ();
-                               ctx.SetSource (DragImage, DragImageBounds.X, DragImageBounds.Y);
-                               ctx.PaintWithAlpha (0.8);
-                               ctx.Restore ();
-                               DirtyRect += DragImageBounds;
-                               IsDirty = true;
-                       }
+                               if (lastDragImageBounds != DragImageBounds) {
+                                       DirtyRect += lastDragImageBounds;
+                                       ctx.Save ();
+                                       ctx.ResetClip ();
+                                       ctx.SetSource (DragImage, DragImageBounds.X, DragImageBounds.Y);
+                                       ctx.PaintWithAlpha (0.8);
+                                       ctx.Restore ();
+                                       DirtyRect += DragImageBounds;
+                                       IsDirty = true;
+                               }
 
 
 #if DEBUG_CLIP_RECTANGLE
-                       ctx.LineWidth = 1;
-                       ctx.SetSource(1,1,0,0.5);
-                       for (int i = 0; i < clipping.NumRectangles; i++)
-                               ctx.Rectangle(clipping.GetRectangle(i));
-                       ctx.Stroke ();
+                               ctx.LineWidth = 1;
+                               ctx.SetSource(1,1,0,0.5);
+                               for (int i = 0; i < clipping.NumRectangles; i++)
+                                       ctx.Rectangle(clipping.GetRectangle(i));
+                               ctx.Stroke ();
 
 #endif
 
 #if VKVG
-                       ctx.Flush();
+                               ctx.Flush();
 #else
-                       ctx.PopGroupToSource ();
+                               ctx.PopGroupToSource ();
 
-                       if (!SolidBackground)
-                               clear (ctx);
+                               if (!SolidBackground)
+                                       clear (ctx);
 
-                       ctx.Paint ();
+                               ctx.Paint ();
 
-                       surf.Flush ();
+                               surf.Flush ();
 #endif
 
-                       clipping.Reset ();
+                               clipping.Reset ();
 
-                       PerformanceMeasure.End (PerformanceMeasure.Kind.Drawing);
-                       IsDirty = true;
+                               PerformanceMeasure.End (PerformanceMeasure.Kind.Drawing);
+                               IsDirty = true;
+                       }
 
 #if !VKVG
                        drawTextCursor (ctx);
@@ -1417,6 +1414,8 @@ namespace Crow
                        }
                }
                #endregion
+               bool shouldDrawTextCursor => forceTextCursor || (blinkingCursor.ElapsedMilliseconds > TEXT_CURSOR_BLINK_FREQUENCY &&
+                       (FocusedWidget is IEditableTextWidget || textCursor != null));
 
                #region GraphicTree handling
                /// <summary>Add widget to the Graphic tree of this interface and register it for layouting</summary>
@@ -2113,8 +2112,10 @@ namespace Crow
                        ctxMenuContainer.Top = MousePosition.Y - 5;
 
                        //OnMouseMove (MousePosition.X, MousePosition.Y);
-                       HoverWidget = ctxMenuContainer;
+                       //
+                       //
                        ctxMenuContainer.onMouseEnter (ctxMenuContainer, new MouseMoveEventArgs (MousePosition.X, MousePosition.Y, 0, 0));
+                       HoverWidget = ctxMenuContainer;
                }
                #endregion
 
index da4d7c357d652a970fc75ff98e86804c1a9c9376..a7f50e78fc1c245d66fa4d0aa2a96e7c448efadb 100644 (file)
@@ -1823,9 +1823,9 @@ namespace Crow
                                if (isVisible) {
                                        if (Width.IsFixed)
                                                Slot.Width = Width;
-                                       else if (Width == Measure.Fit) {
+                                       else if (Width == Measure.Fit)
                                                Slot.Width = measureRawSize (LayoutingType.Width);
-                                       else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
+                                       else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
                                                return false;
                                        else if (Width == Measure.Stretched)
                                                Slot.Width = Parent.GetClientRectangleForChild(this).Width;