aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-02-02 06:09:11 +0100
committerj-p <jp_bruyere@hotmail.com>2021-02-06 20:28:02 +0100
commita9bf07a2d599bc1fb2e1a8764ed2e6ce17f8dfc4 (patch)
treef425b681bc50a00293d0526c9af1e18c9a222b86
parenta91da272cb525a0dda1baa2aad2c8da2560405fe (diff)
out of client rectangle text cursor handling
-rw-r--r--Crow/src/Interface.cs33
-rw-r--r--Crow/src/Widgets/Label.cs16
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;
}
}