From a9bf07a2d599bc1fb2e1a8764ed2e6ce17f8dfc4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Tue, 2 Feb 2021 06:09:11 +0100 Subject: [PATCH] out of client rectangle text cursor handling --- Crow/src/Interface.cs | 33 +++++++++++++-------------------- Crow/src/Widgets/Label.cs | 16 +++++++++++----- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index 1e26824a..12df8553 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -870,12 +870,14 @@ namespace Crow } if (forceTextCursor) { - if (FocusedWidget is Label lab && lab.SelectionIsEmpty) { - Rectangle c = lab.DrawCursor (ctx); - if (textCursor != null && c != textCursor.Value) - RegisterClip (textCursor.Value); - textCursor = c; - surf.Flush (); + if (FocusedWidget is Label lab && lab.SelectionIsEmpty) { + if (lab.DrawCursor (ctx, out Rectangle c)) { + if (textCursor != null && c != textCursor.Value) + RegisterClip (textCursor.Value); + textCursor = c; + surf.Flush (); + } else if (textCursor != null) + RegisterClip (textCursor.Value); } blinkingCursor.Restart (); forceTextCursor = false; @@ -885,9 +887,11 @@ namespace Crow blinkingCursor.Restart (); } else if (FocusedWidget is Label lab && lab.SelectionIsEmpty) { if (blinkingCursor.ElapsedMilliseconds > TEXT_CURSOR_BLINK_FREQUENCY) { - textCursor = lab.DrawCursor (ctx); - surf.Flush (); - blinkingCursor.Restart (); + if (lab.DrawCursor (ctx, out Rectangle c)) { + textCursor = c; + surf.Flush (); + blinkingCursor.Restart (); + } } } @@ -1125,17 +1129,6 @@ namespace Crow public Point MousePosition { get; set; } = default; public bool IsDown (MouseButton button) => Glfw3.GetMouseButton (hWin, button) != InputAction.Release; - Cursor createCursor (MouseCursor mc) - { - const int minimumSize = 24; - if (!XCursor.Cursors.ContainsKey (mc)) { - XCursor.Cursors[mc] = XCursorFile.Load (this, $"#Crow.Cursors.{mc}").Cursors.First (cu => cu.Width >= minimumSize); - } - XCursor c = XCursor.Cursors [mc]; - return new CustomCursor (c.Width, c.Height, c.data, c.Xhot, c.Yhot); - } - - public MouseCursor MouseCursor { get => cursor; set { diff --git a/Crow/src/Widgets/Label.cs b/Crow/src/Widgets/Label.cs index e7fe430f..8dbb48ba 100644 --- a/Crow/src/Widgets/Label.cs +++ b/Crow/src/Widgets/Label.cs @@ -729,7 +729,7 @@ namespace Crow } RectangleD? textCursor = null; - internal Rectangle DrawCursor (Context ctx) { + internal bool DrawCursor (Context ctx, out Rectangle rect) { if (!currentLoc.Value.HasVisualX) { ctx.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); ctx.SetFontSize (Font.Size); @@ -739,11 +739,16 @@ namespace Crow updateLocation (ctx, ClientRectangle.Width, ref currentLoc); textCursor = null; } + //if (textCursor == null) { Rectangle cb = ClientRectangle; - int lineHeight = (int)(fe.Ascent + fe.Descent); - textCursor = new RectangleD (currentLoc.Value.VisualCharXPosition + cb.X + Slot.X, - cb.Y + Slot.Y + currentLoc.Value.Line * lineHeight, 1.0, lineHeight); + if (currentLoc.Value.VisualCharXPosition > cb.Width) { + rect = default; + return false; + } + int lineHeight = (int)(fe.Ascent + fe.Descent); + textCursor = new RectangleD (currentLoc.Value.VisualCharXPosition + cb.X + Slot.X, + cb.Y + Slot.Y + currentLoc.Value.Line * lineHeight, 1.0, lineHeight); //} Rectangle c = ScreenCoordinates (textCursor.Value); ctx.ResetClip (); @@ -752,7 +757,8 @@ namespace Crow ctx.MoveTo (0.5 + c.X, c.Y); ctx.LineTo (0.5 + c.X, c.Bottom); ctx.Stroke (); - return c; + rect = c; + return true; } } -- 2.47.3