From: Jean-Philippe Bruyère Date: Mon, 18 Jul 2022 20:38:45 +0000 (+0200) Subject: remove clear from prepare ui frame for cairo, solve flickering in mt X-Git-Tag: v1.2.0-beta~4 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=286b685aa9f21d73e22ce9d1941abf657e2d70b0;p=jp%2Fcrow.git remove clear from prepare ui frame for cairo, solve flickering in mt --- diff --git a/Backends/CairoBackend/src/ImageBackend.cs b/Backends/CairoBackend/src/ImageBackend.cs index a90d275a..97b61e24 100644 --- a/Backends/CairoBackend/src/ImageBackend.cs +++ b/Backends/CairoBackend/src/ImageBackend.cs @@ -65,15 +65,22 @@ namespace Crow.CairoBackend { IContext ctx = base.PrepareUIFrame (existingContext, clipping); - clear (ctx); + for (int i = 0; i < clipping.NumRectangles; i++) + ctx.Rectangle (clipping.GetRectangle (i)); + ctx.Clip (); + ctx.PushGroup (); return ctx; } public override void FlushUIFrame(IContext ctx) { + //clear (ctx); ctx.PopGroupToSource (); + //ctx.Save(); + //ctx.Operator = Operator.Source; ctx.Paint (); + //ctx.Restore(); surf.Flush (); diff --git a/Backends/CairoBackend/src/Surface.cs b/Backends/CairoBackend/src/Surface.cs index 1f44d3ab..413384f0 100644 --- a/Backends/CairoBackend/src/Surface.cs +++ b/Backends/CairoBackend/src/Surface.cs @@ -142,7 +142,7 @@ namespace Crow.CairoBackend { handle = IntPtr.Zero; } public virtual void Resize (int width, int height) { - + throw new NotImplementedException(); } public Status Finish () diff --git a/Crow/src/DebugUtils/DbgEvtType.cs b/Crow/src/DebugUtils/DbgEvtType.cs deleted file mode 100644 index ed6bfea2..00000000 --- a/Crow/src/DebugUtils/DbgEvtType.cs +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2013-2021 Jean-Philippe Bruyère -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; - -namespace Crow -{ - [Flags] - public enum DbgEvtType : Int32 { - None = 0, - IFace = 0x00000100, - Widget = 0x00000200, - - Warning = 0x00000400, - Error = 0x00000800, - - Binding = 0x00001000, - Lock = 0x00002000, - Layouting = 0x00004000, - Clipping = 0x00008000, - Drawing = 0x00010000, - - Focus = 0x00020000, - Override = 0x00040000, - TemplatedGroup = 0x00080000, - Dispose = 0x00100000, - Mouse = 0x00200000, - DragNDrop = 0x00400000, - - Update = IFace | 0x10000000, - ProcessLayouting = IFace | Update | Lock | Layouting, - ClippingRegistration = IFace | Update | Lock | Clipping, - ProcessDrawing = IFace | Update | Lock | Drawing, - IFaceLoad = IFace | 0x01, - IFaceInit = IFace | 0x02, - CreateITor = IFace | 0x03, - IFaceReloadTheme = IFace | 0x04, - - HoverWidget = Focus | Widget | 0x01, - FocusedWidget = Focus | Widget | 0x02, - ActiveWidget = Focus | Widget | 0x04, - UnfocusedWidget = Focus | Widget | 0x08, - - //10 nth bit set for graphic obj - GOClassCreation = Widget | 0x01, - GOInitialization = Widget | 0x02, - GORegisterForGraphicUpdate = Widget | 0x03, - GOEnqueueForRepaint = Widget | 0x04, - GONewDataSource = Widget | 0x05, - GONewParent = Widget | 0x06, - GONewLogicalParent = Widget | 0x07, - GOAddChild = Widget | 0x08, - - GOMeasure = Widget | 0x09, - GOSearchLargestChild = Widget | 0x0A, - GOSearchTallestChild = Widget | 0x0B, - GORegisterForRedraw = Widget | 0x0C, - GOComputeChildrenPositions = Widget | 0x0D, - GOOnChildLayoutChange = Widget | 0x0E, - GOAdjustStretchedGo = Widget | 0x0F, - GOSetProperty = Widget | 0x10, - - AlreadyDisposed = Widget | Dispose | Error | 0x01, - DisposedByGC = Widget | Dispose | Error | 0x02, - Disposing = Widget | Dispose | 0x01, - - GOClippingRegistration = Widget | Clipping | 0x01, - GORegisterClip = Widget | Clipping | 0x02, - GOResetClip = Widget | Clipping | 0x03, - GORegisterLayouting = Widget | Layouting | 0x01, - GOProcessLayouting = Widget | Layouting | 0x02, - GOProcessLayoutingWithNoParent = Widget | Layouting | Warning | 0x01, - GODraw = Widget | Drawing | 0x01, - GORecreateCache = Widget | Drawing | 0x02, - GOUpdateCache = Widget | Drawing | 0x03, - GOPaintCache = Widget | Drawing | 0x04, - GOPaint = Widget | Drawing | 0x05, - GOCreateSurface = Widget | Drawing | 0x06, - GOCreateContext = Widget | Drawing | 0x07, - - - GOLockUpdate = Widget | Lock | 0x01, - GOLockClipping = Widget | Lock | 0x02, - GOLockRender = Widget | Lock | 0x03, - GOLockLayouting = Widget | Lock | 0x04, - - TGLoadingThread = Widget | TemplatedGroup | 0x01, - TGCancelLoadingThread = Widget | TemplatedGroup | 0x02, - - MouseDown = IFace | Mouse | 0x01, - MouseUp = IFace | Mouse | 0x02, - MouseMove = IFace | Mouse | 0x03, - MouseEnter = Widget | Mouse | 0x01, - MouseLeave = Widget | Mouse | 0x02, - WidgetMouseMove = Widget | Mouse | 0x03, - WidgetMouseDown = Widget | Mouse | 0x04, - WidgetMouseUp = Widget | Mouse | 0x05, - WidgetMouseWheel = Widget | Mouse | 0x06, - WidgetMouseClick = Widget | Mouse | 0x07, - WidgetMouseDblClick = Widget | Mouse | 0x08, - Drag = Widget | DragNDrop | 0x01, - DragEnter = Widget | DragNDrop | 0x02, - DragLeave = Widget | DragNDrop | 0x03, - StartDrag = Widget | DragNDrop | 0x04, - EndDrag = Widget | DragNDrop | 0x05, - Drop = Widget | DragNDrop | 0x06, - - All = 0x7FFFFF00 - } -} \ No newline at end of file diff --git a/Crow/src/DebugUtils/DebugLogger.cs b/Crow/src/DebugUtils/DebugLogger.cs index d549e19d..c859fef9 100644 --- a/Crow/src/DebugUtils/DebugLogger.cs +++ b/Crow/src/DebugUtils/DebugLogger.cs @@ -15,9 +15,6 @@ namespace Crow { public static class DbgLogger { - /*public static DbgEvtType IncludeEvents = DbgEvtType.All; - public static DbgEvtType DiscardEvents = DbgEvtType.Focus;*/ - public static List IncludedEvents = new List (); public static bool ConsoleOutput = true; diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index 507bed69..ca45a243 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -1293,7 +1293,7 @@ namespace Crow [Conditional ("DEBUG_HIGHLIGHT_FOCUS")] internal void debugRegisterClip (Widget w) { - RegisterClip (w.ScreenCoordinates (w.Slot)); + RegisterChildClip (w.ScreenCoordinates (w.Slot)); } [Conditional ("DEBUG_HIGHLIGHT_FOCUS")] void debugHighlightFocus (IContext ctx) { @@ -1328,23 +1328,23 @@ namespace Crow if (FocusedWidget is IEditableTextWidget lab) { if (lab.DrawCursor (ctx, out Rectangle c)) { if (textCursor != null && c != textCursor.Value) - RegisterClip (textCursor.Value); + RegisterChildClip (textCursor.Value); textCursor = c; - MainSurface.Flush (); + //MainSurface.Flush (); } else if (textCursor != null) - RegisterClip (textCursor.Value); + RegisterChildClip (textCursor.Value); } blinkingCursor.Restart (); forceTextCursor = false; } else if (textCursor != null && blinkingCursor.ElapsedMilliseconds > TEXT_CURSOR_BLINK_FREQUENCY) { - RegisterClip (textCursor.Value); + RegisterChildClip (textCursor.Value); textCursor = null; blinkingCursor.Restart (); } else if (FocusedWidget is IEditableTextWidget lab) { if (blinkingCursor.ElapsedMilliseconds > TEXT_CURSOR_BLINK_FREQUENCY) { if (lab.DrawCursor (ctx, out Rectangle c)) { textCursor = c; - MainSurface.Flush (); + //MainSurface.Flush (); blinkingCursor.Restart (); } } @@ -1384,7 +1384,7 @@ namespace Crow public void DeleteWidget(Widget g) { lock (UpdateMutex) { - RegisterClip (g.ScreenCoordinates (g.LastPaintedSlot)); + RegisterChildClip (g.ScreenCoordinates (g.LastPaintedSlot)); GraphicTree.Remove (g); g.Parent = null; g.Dispose (); @@ -1400,7 +1400,7 @@ namespace Crow // } // } lock (UpdateMutex) { - RegisterClip (g.ScreenCoordinates (g.LastPaintedSlot)); + RegisterChildClip (g.ScreenCoordinates (g.LastPaintedSlot)); GraphicTree.Remove (g); g.Parent = null; } @@ -1413,7 +1413,7 @@ namespace Crow //TODO:parent is not reset to null because object will be added //to ObjectToRedraw list, and without parent, it fails Widget g = GraphicTree [0]; - RegisterClip (g.ScreenCoordinates (g.LastPaintedSlot)); + RegisterChildClip (g.ScreenCoordinates (g.LastPaintedSlot)); GraphicTree.RemoveAt (0); g.Dispose (); } @@ -1472,7 +1472,7 @@ namespace Crow } } - protected void registerRefreshClientRectangle () => RegisterClip (clientRectangle); + protected void registerRefreshClientRectangle () => RegisterChildClip (clientRectangle); #region Mouse and Keyboard Handling MouseCursor cursor = MouseCursor.top_left_arrow; @@ -2056,7 +2056,7 @@ namespace Crow #region ILayoutable implementation public virtual bool PointIsIn (ref Point m) => true; - public void RegisterClip (Rectangle r) + public void RegisterChildClip (Rectangle r) { clipping.UnionRectangle (r); } diff --git a/Crow/src/LayoutingQueueItem.cs b/Crow/src/LayoutingQueueItem.cs index 9ce5895b..f7606a6e 100644 --- a/Crow/src/LayoutingQueueItem.cs +++ b/Crow/src/LayoutingQueueItem.cs @@ -83,6 +83,16 @@ namespace Crow } try { + if (go.IsQueueForClipping) { + DbgLogger.AddEvent (DbgEvtType.GOProcessLayoutingWhileClipReg, this); +#if DEBUG_LOG + result = Result.Discarded; +#endif + LayoutingTries = 0; + DiscardCount++; + Layoutable.RegisteredLayoutings |= LayoutType; + go.IFace.DiscardQueue.Enqueue (this); + } if (go.Parent == null) {//TODO:improve this //cancel layouting for object without parent, maybe some were in queue when //removed from a listbox diff --git a/Crow/src/Widgets/ILayoutable.cs b/Crow/src/Widgets/ILayoutable.cs index 6007f023..0e71f056 100644 --- a/Crow/src/Widgets/ILayoutable.cs +++ b/Crow/src/Widgets/ILayoutable.cs @@ -25,7 +25,7 @@ namespace Crow LayoutingType RequiredLayoutings { get; set; } void ChildrenLayoutingConstraints(ILayoutable layoutable, ref LayoutingType layoutType); void RegisterForLayouting(LayoutingType layoutType); - void RegisterClip(Rectangle clip); + void RegisterChildClip(Rectangle clip); bool UpdateLayout(LayoutingType layoutType); bool PointIsIn(ref Point m); diff --git a/Crow/src/Widgets/ScrollBar.cs b/Crow/src/Widgets/ScrollBar.cs index efbf3fb1..99882590 100644 --- a/Crow/src/Widgets/ScrollBar.cs +++ b/Crow/src/Widgets/ScrollBar.cs @@ -27,7 +27,7 @@ namespace Crow set { if (cursorRatio == value) return; - if (double.IsFinite(value)) + if (double.IsFinite(value) && cursorRatio < 1.0) cursorRatio = value; else cursorRatio = -1; @@ -36,7 +36,7 @@ namespace Crow } void updateCursor () { - if (cursorRatio < 0 || !double.IsFinite(cursorRatio)) + if (cursorRatio < 0 || !double.IsFinite(cursorRatio) || cursorRatio > 1.0) return; ILayoutable l = cursor?.Parent; if (l == null) diff --git a/Crow/src/Widgets/Scroller.cs b/Crow/src/Widgets/Scroller.cs index db563cb0..a49420aa 100644 --- a/Crow/src/Widgets/Scroller.cs +++ b/Crow/src/Widgets/Scroller.cs @@ -174,9 +174,9 @@ namespace Crow m += new Point (ScrollX, ScrollY); return true; } - public override void RegisterClip (Rectangle clip) + public override void RegisterChildClip (Rectangle clip) { - base.RegisterClip (clip - new Point(ScrollX,ScrollY)); + base.RegisterChildClip (clip - new Point(ScrollX,ScrollY)); } public override void OnLayoutChanges (LayoutingType layoutType) { diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index c3f08fd4..1165bb7e 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -1527,8 +1527,8 @@ namespace Crow parentRWLock.EnterReadLock (); if (parent != null) { - parent.RegisterClip (LastPaintedSlot); - parent.RegisterClip (Slot); + parent.RegisterChildClip (LastPaintedSlot); + parent.RegisterChildClip (Slot); }else { DbgLogger.SetMsg (DbgEvtType.GOClippingRegistration, "clipping reg canceled (no parent)"); } @@ -1540,7 +1540,7 @@ namespace Crow /// Add clip rectangle to this.clipping and propagate up to root /// /// Clip rectangle - public virtual void RegisterClip(Rectangle clip){ + public virtual void RegisterChildClip(Rectangle clip){ if (disposed) { DbgLogger.AddEvent (DbgEvtType.AlreadyDisposed | DbgEvtType.GORegisterClip, this); return; @@ -1573,7 +1573,7 @@ namespace Crow Console.WriteLine ($"parent.regclip canceled p.Dirty:{p?.IsDirty} Cached:{p?.CacheEnabled}: {this.ToString()}"); return; }*/ - Parent.RegisterClip (r + Slot.Position); + Parent.RegisterChildClip (r + Slot.Position); } finally { DbgLogger.EndEvent (DbgEvtType.GORegisterClip); } @@ -2297,7 +2297,7 @@ namespace Crow try { if (parent != null) - parent.RegisterClip (ContextCoordinates(LastPaintedSlot)); + parent.RegisterChildClip (ContextCoordinates(LastPaintedSlot)); } catch (System.Exception e) { diff --git a/Crow/src/Widgets/Window.cs b/Crow/src/Widgets/Window.cs index 168fb101..cc7763c9 100644 --- a/Crow/src/Widgets/Window.cs +++ b/Crow/src/Widgets/Window.cs @@ -500,7 +500,7 @@ namespace Crow lock (IFace.UpdateMutex) { Widget p = Parent as Widget; if (p is Group g) { - RegisterClip (p.ScreenCoordinates (p.LastPaintedSlot)); + RegisterChildClip (p.ScreenCoordinates (p.LastPaintedSlot)); g.DeleteChild (this); //(Parent as Group).RegisterForRedraw (); } else if (Parent is Container c) diff --git a/Directory.Build.props b/Directory.Build.props index 37361807..d674fd6e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -15,7 +15,7 @@ - true + false false diff --git a/Drawing2D/src/DbgEvtType.cs b/Drawing2D/src/DbgEvtType.cs new file mode 100644 index 00000000..ff214ec8 --- /dev/null +++ b/Drawing2D/src/DbgEvtType.cs @@ -0,0 +1,112 @@ +// Copyright (c) 2013-2021 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + +using System; + +namespace Crow +{ + [Flags] + public enum DbgEvtType : Int32 { + None = 0, + IFace = 0x00000100, + Widget = 0x00000200, + + Warning = 0x00000400, + Error = 0x00000800, + + Binding = 0x00001000, + Lock = 0x00002000, + Layouting = 0x00004000, + Clipping = 0x00008000, + Drawing = 0x00010000, + + Focus = 0x00020000, + Override = 0x00040000, + TemplatedGroup = 0x00080000, + Dispose = 0x00100000, + Mouse = 0x00200000, + DragNDrop = 0x00400000, + + Update = IFace | 0x10000000, + ProcessLayouting = IFace | Update | Lock | Layouting, + ClippingRegistration = IFace | Update | Lock | Clipping, + ProcessDrawing = IFace | Update | Lock | Drawing, + IFaceLoad = IFace | 0x01, + IFaceInit = IFace | 0x02, + CreateITor = IFace | 0x03, + IFaceReloadTheme = IFace | 0x04, + + HoverWidget = Focus | Widget | 0x01, + FocusedWidget = Focus | Widget | 0x02, + ActiveWidget = Focus | Widget | 0x04, + UnfocusedWidget = Focus | Widget | 0x08, + + //10 nth bit set for graphic obj + GOClassCreation = Widget | 0x01, + GOInitialization = Widget | 0x02, + GORegisterForGraphicUpdate = Widget | 0x03, + GOEnqueueForRepaint = Widget | 0x04, + GONewDataSource = Widget | 0x05, + GONewParent = Widget | 0x06, + GONewLogicalParent = Widget | 0x07, + GOAddChild = Widget | 0x08, + + GOMeasure = Widget | 0x09, + GOSearchLargestChild = Widget | 0x0A, + GOSearchTallestChild = Widget | 0x0B, + GORegisterForRedraw = Widget | 0x0C, + GOComputeChildrenPositions = Widget | 0x0D, + GOOnChildLayoutChange = Widget | 0x0E, + GOAdjustStretchedGo = Widget | 0x0F, + GOSetProperty = Widget | 0x10, + + AlreadyDisposed = Widget | Dispose | Error | 0x01, + DisposedByGC = Widget | Dispose | Error | 0x02, + Disposing = Widget | Dispose | 0x01, + + GOClippingRegistration = Widget | Clipping | 0x01, + GORegisterClip = Widget | Clipping | 0x02, + GOResetClip = Widget | Clipping | 0x03, + GORegisterLayouting = Widget | Layouting | 0x01, + GOProcessLayouting = Widget | Layouting | 0x02, + GOProcessLayoutingWithNoParent = Widget | Layouting | Warning | 0x01, + GOProcessLayoutingWhileClipReg = Widget | Layouting | Warning | 0x02, + GODraw = Widget | Drawing | 0x01, + GORecreateCache = Widget | Drawing | 0x02, + GOUpdateCache = Widget | Drawing | 0x03, + GOPaintCache = Widget | Drawing | 0x04, + GOPaint = Widget | Drawing | 0x05, + GOCreateSurface = Widget | Drawing | 0x06, + GOCreateContext = Widget | Drawing | 0x07, + + + GOLockUpdate = Widget | Lock | 0x01, + GOLockClipping = Widget | Lock | 0x02, + GOLockRender = Widget | Lock | 0x03, + GOLockLayouting = Widget | Lock | 0x04, + + TGLoadingThread = Widget | TemplatedGroup | 0x01, + TGCancelLoadingThread = Widget | TemplatedGroup | 0x02, + + MouseDown = IFace | Mouse | 0x01, + MouseUp = IFace | Mouse | 0x02, + MouseMove = IFace | Mouse | 0x03, + MouseEnter = Widget | Mouse | 0x01, + MouseLeave = Widget | Mouse | 0x02, + WidgetMouseMove = Widget | Mouse | 0x03, + WidgetMouseDown = Widget | Mouse | 0x04, + WidgetMouseUp = Widget | Mouse | 0x05, + WidgetMouseWheel = Widget | Mouse | 0x06, + WidgetMouseClick = Widget | Mouse | 0x07, + WidgetMouseDblClick = Widget | Mouse | 0x08, + Drag = Widget | DragNDrop | 0x01, + DragEnter = Widget | DragNDrop | 0x02, + DragLeave = Widget | DragNDrop | 0x03, + StartDrag = Widget | DragNDrop | 0x04, + EndDrag = Widget | DragNDrop | 0x05, + Drop = Widget | DragNDrop | 0x06, + + All = 0x7FFFFF00 + } +} \ No newline at end of file diff --git a/Samples/common/src/SampleBase.cs b/Samples/common/src/SampleBase.cs index e469016c..2ae28cb5 100644 --- a/Samples/common/src/SampleBase.cs +++ b/Samples/common/src/SampleBase.cs @@ -19,7 +19,7 @@ namespace Samples public class SampleBase : Interface { public SampleBase(IntPtr hWin) : base(800, 600, hWin) { } - public SampleBase() : base (800, 600, true) { } + public SampleBase() : base (800, 600, false) { } public Version CrowVersion => Assembly.GetAssembly(typeof(Widget)).GetName().Version; diff --git a/Samples/common/ui/Interfaces/Experimental/randomProgress.crow b/Samples/common/ui/Interfaces/Experimental/randomProgress.crow index 9b63b81a..ae78a76a 100644 --- a/Samples/common/ui/Interfaces/Experimental/randomProgress.crow +++ b/Samples/common/ui/Interfaces/Experimental/randomProgress.crow @@ -2,10 +2,9 @@ -