[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/ns/refactor 2ee451b 10/10: Fix NS inset rectangle corners
From: |
Alan Third |
Subject: |
scratch/ns/refactor 2ee451b 10/10: Fix NS inset rectangle corners |
Date: |
Sat, 17 Jul 2021 08:23:43 -0400 (EDT) |
branch: scratch/ns/refactor
commit 2ee451b109fe68d3beb14e89cfeecd0041b8132a
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>
Fix NS inset rectangle corners
* src/nsterm.m (ns_draw_relief): Use a path to draw the mitered
corners instead of rectangles.
---
src/nsterm.m | 65 ++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 24 deletions(-)
diff --git a/src/nsterm.m b/src/nsterm.m
index f888961..bb18959 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -3493,7 +3493,7 @@ ns_draw_box (NSRect r, CGFloat hthickness, CGFloat
vthickness,
static void
-ns_draw_relief (NSRect r, int hthickness, int vthickness, char raised_p,
+ns_draw_relief (NSRect outer, int hthickness, int vthickness, char raised_p,
char top_p, char bottom_p, char left_p, char right_p,
struct glyph_string *s)
/* --------------------------------------------------------------------------
@@ -3504,7 +3504,7 @@ ns_draw_relief (NSRect r, int hthickness, int vthickness,
char raised_p,
{
static NSColor *baseCol = nil, *lightCol = nil, *darkCol = nil;
NSColor *newBaseCol = nil;
- NSRect sr = r;
+ NSRect inner;
NSTRACE ("ns_draw_relief");
@@ -3538,33 +3538,50 @@ ns_draw_relief (NSRect r, int hthickness, int
vthickness, char raised_p,
darkCol = [[baseCol shadowWithLevel: 0.3] retain];
}
- [(raised_p ? lightCol : darkCol) set];
-
- /* TODO: mitering. Using NSBezierPath doesn't work because of color switch.
*/
+ /* Calculate the inner rectangle. */
+ inner = NSInsetRect (outer, hthickness, vthickness);
- /* top */
- sr.size.height = hthickness;
- if (top_p) NSRectFill (sr);
+ [(raised_p ? lightCol : darkCol) set];
- /* left */
- sr.size.height = r.size.height;
- sr.size.width = vthickness;
- if (left_p) NSRectFill (sr);
+ if (top_p || left_p)
+ {
+ NSBezierPath *p = [NSBezierPath bezierPath];
+ [p moveToPoint:NSMakePoint (NSMinX (outer), NSMinY (outer))];
+ if (top_p)
+ {
+ [p lineToPoint:NSMakePoint (NSMaxX (outer), NSMinY (outer))];
+ [p lineToPoint:NSMakePoint (NSMaxX (inner), NSMinY (inner))];
+ }
+ [p lineToPoint:NSMakePoint (NSMinX (inner), NSMinY (inner))];
+ if (left_p)
+ {
+ [p lineToPoint:NSMakePoint (NSMinX (inner), NSMaxY (inner))];
+ [p lineToPoint:NSMakePoint (NSMinX (outer), NSMaxY (outer))];
+ }
+ [p closePath];
+ [p fill];
+ }
[(raised_p ? darkCol : lightCol) set];
- /* bottom */
- sr.size.width = r.size.width;
- sr.size.height = hthickness;
- sr.origin.y += r.size.height - hthickness;
- if (bottom_p) NSRectFill (sr);
-
- /* right */
- sr.size.height = r.size.height;
- sr.origin.y = r.origin.y;
- sr.size.width = vthickness;
- sr.origin.x += r.size.width - vthickness;
- if (right_p) NSRectFill (sr);
+ if (bottom_p || right_p)
+ {
+ NSBezierPath *p = [NSBezierPath bezierPath];
+ [p moveToPoint:NSMakePoint (NSMaxX (outer), NSMaxY (outer))];
+ if (right_p)
+ {
+ [p lineToPoint:NSMakePoint (NSMaxX (outer), NSMinY (outer))];
+ [p lineToPoint:NSMakePoint (NSMaxX (inner), NSMinY (inner))];
+ }
+ [p lineToPoint:NSMakePoint (NSMaxX (inner), NSMaxY (inner))];
+ if (bottom_p)
+ {
+ [p lineToPoint:NSMakePoint (NSMinX (inner), NSMaxY (inner))];
+ [p lineToPoint:NSMakePoint (NSMinX (outer), NSMaxY (outer))];
+ }
+ [p closePath];
+ [p fill];
+ }
}
- branch scratch/ns/refactor created (now 2ee451b), Alan Third, 2021/07/17
- scratch/ns/refactor 40d30ea 03/10: Change NS port resize detection, Alan Third, 2021/07/17
- scratch/ns/refactor 4c10229 05/10: Move NS port toolbar handling to the window, Alan Third, 2021/07/17
- scratch/ns/refactor 87aae7e 09/10: Simplify NS sizing and positioning code, Alan Third, 2021/07/17
- scratch/ns/refactor a159bd0 01/10: Simplify macOS drawing code, Alan Third, 2021/07/17
- scratch/ns/refactor c319def 02/10: Tidy up NS port OS window handling, Alan Third, 2021/07/17
- scratch/ns/refactor 91b1715 04/10: Fix macOS live resize drawing, Alan Third, 2021/07/17
- scratch/ns/refactor ae88acc 06/10: Move parent frame setting code into EmacsWindow, Alan Third, 2021/07/17
- scratch/ns/refactor d58e217 07/10: Fix some macOS problems, Alan Third, 2021/07/17
- scratch/ns/refactor 2fcd93d 08/10: * src/nsterm.m (ns_set_frame_alpha): Enable alpha on GNUstep., Alan Third, 2021/07/17
- scratch/ns/refactor 2ee451b 10/10: Fix NS inset rectangle corners,
Alan Third <=