[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH]: NSDraw functions with system colors
From: |
Adam Fedor |
Subject: |
[PATCH]: NSDraw functions with system colors |
Date: |
Sun, 04 May 2003 19:28:45 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.1) Gecko/20020905 |
Following up on Nicolas' Camaelon package, this patch removes the rect
fill and draws (some functions) with system colors. Both the OpenStep
and MacOSX docs on this are terse and ambiguous (The usage of the
functions conflicts with other documentation e.g. NSCell. MacOSX
suggests that these aren't even used any more in their AppKit). In order
to make these functions more useful, I've changed the functions to use
system colors where appropriate, etc. I'll commit in a day or so if
there are no objections.
2003-05-04 Adam Fedor <fedor@gnu.org>
* Source/Functions.m (NSDrawButton, NSDrawGroove, NSDrawFramePhoto):
Don't fill rect. Use system colors
(NSDrawGrayBezel, NSDrawWhiteBezel): Don't fill rect.
(NSDrawDarkBezel): Implement like NSDrawGrayBezel with system colors.
(NSDrawLightBezel): Idem like NSDrawWhiteBezel.
Index: Source/Functions.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/Functions.m,v
retrieving revision 1.27
diff -u -p -r1.27 Functions.m
--- Source/Functions.m 22 May 2002 12:04:47 -0000 1.27
+++ Source/Functions.m 5 May 2003 01:19:05 -0000
@@ -540,6 +540,22 @@ NSDrawColorTiledRects(NSRect boundsRect,
return remainder;
}
+static int filled_color_list = 0;
+static NSColor *white = nil;
+static NSColor *light = nil;
+static NSColor *dark = nil;
+static NSColor *black = nil;
+
+static void
+fill_color_list()
+{
+ filled_color_list = 1;
+ white = [NSColor controlLightHighlightColor];
+ light = [NSColor controlHighlightColor];
+ dark = [NSColor controlShadowColor];
+ black = [NSColor controlDarkShadowColor];
+}
+
void
NSDrawButton(const NSRect aRect, const NSRect clipRect)
{
@@ -549,26 +565,22 @@ NSDrawButton(const NSRect aRect, const N
NSRectEdge down_sides[] = {NSMaxXEdge, NSMaxYEdge,
NSMinXEdge, NSMinYEdge,
NSMaxXEdge, NSMaxYEdge};
- float grays[] = {NSBlack, NSBlack,
- NSWhite, NSWhite,
- NSDarkGray, NSDarkGray};
- NSRect rect;
- NSGraphicsContext *ctxt = GSCurrentContext();
+ NSColor *colors[6];
+ if (filled_color_list == 0)
+ fill_color_list();
+ colors[0]=black; colors[1]=black; colors[2]=white; colors[3]=white;
+ colors[4]=dark; colors[5]=dark;
- if (GSWViewIsFlipped(ctxt) == YES)
+ if (GSWViewIsFlipped(GSCurrentContext()) == YES)
{
- rect = NSDrawTiledRects(aRect, clipRect,
- down_sides, grays, 6);
+ NSDrawColorTiledRects(aRect, clipRect,
+ down_sides, colors, 6);
}
else
{
- rect = NSDrawTiledRects(aRect, clipRect,
- up_sides, grays, 6);
+ NSDrawColorTiledRects(aRect, clipRect,
+ up_sides, colors, 6);
}
-
- DPSsetgray(ctxt, NSLightGray);
- DPSrectfill(ctxt, NSMinX(rect), NSMinY(rect),
- NSWidth(rect), NSHeight(rect));
}
void
@@ -580,13 +592,12 @@ NSDrawGrayBezel(const NSRect aRect, cons
NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge};
float grays[] = {NSWhite, NSWhite, NSDarkGray, NSDarkGray,
NSLightGray, NSLightGray, NSBlack, NSBlack};
- NSRect rect;
NSGraphicsContext *ctxt = GSCurrentContext();
if (GSWViewIsFlipped(ctxt) == YES)
{
- rect = NSDrawTiledRects(aRect, clipRect,
- down_sides, grays, 8);
+ NSDrawTiledRects(aRect, clipRect,
+ down_sides, grays, 8);
// to give a really clean look we add 2 dark gray points
DPSsetgray(ctxt, NSDarkGray);
DPSrectfill(ctxt, NSMinX(aRect) + 1., NSMaxY(aRect) - 2., 1., 1.);
@@ -594,17 +605,13 @@ NSDrawGrayBezel(const NSRect aRect, cons
}
else
{
- rect = NSDrawTiledRects(aRect, clipRect,
- up_sides, grays, 8);
+ NSDrawTiledRects(aRect, clipRect,
+ up_sides, grays, 8);
// to give a really clean look we add 2 dark gray points
DPSsetgray(ctxt, NSDarkGray);
DPSrectfill(ctxt, NSMinX(aRect) + 1., NSMinY(aRect) + 1., 1., 1.);
DPSrectfill(ctxt, NSMaxX(aRect) - 2., NSMaxY(aRect) - 2., 1., 1.);
}
-
- DPSsetgray(ctxt, NSLightGray);
- DPSrectfill(ctxt, NSMinX(rect), NSMinY(rect),
- NSWidth(rect), NSHeight(rect));
}
void
@@ -614,25 +621,22 @@ NSDrawGroove(const NSRect aRect, const N
NSMaxXEdge, NSMinYEdge, NSMaxXEdge, NSMinYEdge};
NSRectEdge down_sides[] = {NSMinXEdge, NSMinYEdge, NSMinXEdge, NSMinYEdge,
NSMaxXEdge, NSMaxYEdge, NSMaxXEdge, NSMaxYEdge};
- float grays[] = {NSDarkGray, NSDarkGray, NSWhite, NSWhite,
- NSWhite, NSWhite, NSDarkGray, NSDarkGray};
- NSRect rect;
- NSGraphicsContext *ctxt = GSCurrentContext();
+ NSColor *colors[8];
+ if (filled_color_list == 0)
+ fill_color_list();
+ colors[0]=dark; colors[1]=dark; colors[2]=white; colors[3]=white;
+ colors[4]=white; colors[5]=white; colors[6]=dark; colors[7]=dark;
- if (GSWViewIsFlipped(ctxt) == YES)
+ if (GSWViewIsFlipped(GSCurrentContext()) == YES)
{
- rect = NSDrawTiledRects(aRect, clipRect,
- down_sides, grays, 8);
+ NSDrawColorTiledRects(aRect, clipRect,
+ down_sides, colors, 8);
}
else
{
- rect = NSDrawTiledRects(aRect, clipRect,
- up_sides, grays, 8);
+ NSDrawColorTiledRects(aRect, clipRect,
+ up_sides, colors, 8);
}
-
- DPSsetgray(ctxt, NSLightGray);
- DPSrectfill(ctxt, NSMinX(rect), NSMinY(rect),
- NSWidth(rect), NSHeight(rect));
}
void
@@ -644,33 +648,77 @@ NSDrawWhiteBezel(const NSRect aRect, co
NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge};
float grays[] = {NSWhite, NSWhite, NSDarkGray, NSDarkGray,
NSLightGray, NSLightGray, NSDarkGray, NSDarkGray};
- NSRect rect;
- NSGraphicsContext *ctxt = GSCurrentContext();
- if (GSWViewIsFlipped(ctxt) == YES)
+ if (GSWViewIsFlipped(GSCurrentContext()) == YES)
{
- rect = NSDrawTiledRects(aRect, clipRect,
- down_sides, grays, 8);
+ NSDrawTiledRects(aRect, clipRect,
+ down_sides, grays, 8);
}
else
{
- rect = NSDrawTiledRects(aRect, clipRect,
- up_sides, grays, 8);
+ NSDrawTiledRects(aRect, clipRect,
+ up_sides, grays, 8);
}
-
- DPSsetgray(ctxt, NSWhite);
- DPSrectfill(ctxt, NSMinX(rect), NSMinY(rect),
- NSWidth(rect), NSHeight(rect));
}
void
NSDrawDarkBezel(NSRect aRect, NSRect clipRect)
{
+ NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge,
+ NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge};
+ NSRectEdge down_sides[] = {NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge,
+ NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge};
+ NSGraphicsContext *ctxt = GSCurrentContext();
+ NSColor *colors[8];
+ if (filled_color_list == 0)
+ fill_color_list();
+ colors[0]=white; colors[1]=white; colors[2]=dark; colors[3]=dark;
+ colors[4]=light; colors[5]=light; colors[6]=black; colors[7]=black;
+
+ if (GSWViewIsFlipped(ctxt) == YES)
+ {
+ NSDrawColorTiledRects(aRect, clipRect,
+ down_sides, colors, 8);
+ // to give a really clean look we add 2 dark gray points
+ [dark set];
+ DPSrectfill(ctxt, NSMinX(aRect) + 1., NSMaxY(aRect) - 2., 1., 1.);
+ DPSrectfill(ctxt, NSMaxX(aRect) - 2., NSMinY(aRect) + 1., 1., 1.);
+ }
+ else
+ {
+ NSDrawColorTiledRects(aRect, clipRect,
+ up_sides, colors, 8);
+ // to give a really clean look we add 2 dark gray points
+ [dark set];
+ DPSrectfill(ctxt, NSMinX(aRect) + 1., NSMinY(aRect) + 1., 1., 1.);
+ DPSrectfill(ctxt, NSMaxX(aRect) - 2., NSMaxY(aRect) - 2., 1., 1.);
+ }
}
void
NSDrawLightBezel(NSRect aRect, NSRect clipRect)
{
+ NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge,
+ NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge};
+ NSRectEdge down_sides[] = {NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge,
+ NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge};
+ NSGraphicsContext *ctxt = GSCurrentContext();
+ NSColor *colors[8];
+ if (filled_color_list == 0)
+ fill_color_list();
+ colors[0]=white; colors[1]=white; colors[2]=dark; colors[3]=dark;
+ colors[4]=light; colors[5]=light; colors[6]=dark; colors[7]=dark;
+
+ if (GSWViewIsFlipped(ctxt) == YES)
+ {
+ NSDrawColorTiledRects(aRect, clipRect,
+ down_sides, colors, 8);
+ }
+ else
+ {
+ NSDrawColorTiledRects(aRect, clipRect,
+ up_sides, colors, 8);
+ }
}
void
@@ -682,27 +730,22 @@ NSDrawFramePhoto(const NSRect aRect, con
NSRectEdge down_sides[] = {NSMaxXEdge, NSMaxYEdge,
NSMinXEdge, NSMinYEdge,
NSMaxXEdge, NSMaxYEdge};
- float grays[] = {NSDarkGray, NSDarkGray,
- NSDarkGray, NSDarkGray,
- NSBlack, NSBlack};
+ NSColor *colors[6];
+ if (filled_color_list == 0)
+ fill_color_list();
+ colors[0]=dark; colors[1]=dark; colors[2]=dark; colors[3]=dark;
+ colors[4]=black; colors[5]=black;
- NSRect rect;
- NSGraphicsContext *ctxt = GSCurrentContext();
-
- if (GSWViewIsFlipped(ctxt) == YES)
+ if (GSWViewIsFlipped(GSCurrentContext()) == YES)
{
- rect = NSDrawTiledRects(aRect, clipRect,
- down_sides, grays, 6);
+ NSDrawColorTiledRects(aRect, clipRect,
+ down_sides, colors, 6);
}
else
{
- rect = NSDrawTiledRects(aRect, clipRect,
- up_sides, grays, 6);
+ NSDrawColorTiledRects(aRect, clipRect,
+ up_sides, colors, 6);
}
-
- DPSsetgray(ctxt, NSLightGray);
- DPSrectfill(ctxt, NSMinX(rect), NSMinY(rect),
- NSWidth(rect), NSHeight(rect));
}
void
- [PATCH]: NSDraw functions with system colors,
Adam Fedor <=