]> O.S.I.I.S - jp/crow.git/commitdiff
out of client rectangle text cursor handling
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 2 Feb 2021 05:09:11 +0000 (06:09 +0100)
committerj-p <jp_bruyere@hotmail.com>
Sat, 6 Feb 2021 19:28:02 +0000 (20:28 +0100)
Crow/src/Interface.cs
Crow/src/Widgets/Label.cs

index 1e26824a964162be2ab6af5cbf3a004da8b3ae3b..12df8553d1fb22fce5baff02f29c7a6aa05278ae 100644 (file)
@@ -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 {
index e7fe430f5d90f57413bf798614a9fad03d57a7d4..8dbb48bac97df0ddd0a75c978e3d47171683ffd6 100644 (file)
@@ -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;
                }
 
        }