mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:50:48 +00:00
Draw round and circular bezel borders for button cells. Code by Nikolaus
Schaller <hns@computer.org>. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24415 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5e83b8ca0c
commit
971ec8d86d
3 changed files with 137 additions and 46 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
2007-01-25 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/NSButtonCell.m (-encodeWithCoder:, -initWithCoder:):
|
||||||
|
Corrected coding and decoding of bezel style.
|
||||||
|
* Source/GSTheme.m (-drawCircularBezel:withColor:,
|
||||||
|
-drawRoundBezel:withColor:) New methods to draw bezel.
|
||||||
|
Code by Nikolaus Schaller <hns@computer.org>.
|
||||||
|
* Source/GSTheme.m (-buttonBorderForStyle:state:,
|
||||||
|
-drawButton:view:style:state:): Handle some of the bezel styles.
|
||||||
|
|
||||||
2007-01-24 Richard Frith-Macdoanld <rfm@gnu.org>
|
2007-01-24 Richard Frith-Macdoanld <rfm@gnu.org>
|
||||||
|
|
||||||
* Headers/AppKit/NSButtonCell.h: Fix documentation error.
|
* Headers/AppKit/NSButtonCell.h: Fix documentation error.
|
||||||
|
|
136
Source/GSTheme.m
136
Source/GSTheme.m
|
@ -163,6 +163,10 @@ typedef enum {
|
||||||
* Returns nil on failure.
|
* Returns nil on failure.
|
||||||
*/
|
*/
|
||||||
+ (GSTheme*) loadThemeNamed: (NSString*)aName;
|
+ (GSTheme*) loadThemeNamed: (NSString*)aName;
|
||||||
|
|
||||||
|
// These two drawing method may be made public later on
|
||||||
|
- (void) drawCircularBezel: (NSRect)cellFrame withColor: (NSColor*)backgroundColor;
|
||||||
|
- (void) drawRoundBezel: (NSRect)cellFrame withColor: (NSColor*)backgroundColor;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -718,16 +722,57 @@ static NSNull *null = nil;
|
||||||
|
|
||||||
if (tiles == nil)
|
if (tiles == nil)
|
||||||
{
|
{
|
||||||
[color set];
|
switch (style)
|
||||||
NSRectFill(frame);
|
{
|
||||||
|
case NSRoundRectBezelStyle:
|
||||||
|
case NSTexturedRoundBezelStyle:
|
||||||
|
case NSRoundedBezelStyle:
|
||||||
|
[self drawRoundBezel: frame withColor: color];
|
||||||
|
break;
|
||||||
|
case NSTexturedSquareBezelStyle:
|
||||||
|
frame = NSInsetRect(frame, 0, 1);
|
||||||
|
case NSSmallSquareBezelStyle:
|
||||||
|
case NSRegularSquareBezelStyle:
|
||||||
|
case NSShadowlessSquareBezelStyle:
|
||||||
|
[color set];
|
||||||
|
NSRectFill(frame);
|
||||||
|
[[NSColor controlShadowColor] set];
|
||||||
|
NSFrameRectWithWidth(frame, 1);
|
||||||
|
break;
|
||||||
|
case NSThickSquareBezelStyle:
|
||||||
|
[color set];
|
||||||
|
NSRectFill(frame);
|
||||||
|
[[NSColor controlShadowColor] set];
|
||||||
|
NSFrameRectWithWidth(frame, 1.5);
|
||||||
|
break;
|
||||||
|
case NSThickerSquareBezelStyle:
|
||||||
|
[color set];
|
||||||
|
NSRectFill(frame);
|
||||||
|
[[NSColor controlShadowColor] set];
|
||||||
|
NSFrameRectWithWidth(frame, 2);
|
||||||
|
break;
|
||||||
|
case NSCircularBezelStyle:
|
||||||
|
frame = NSInsetRect(frame, 3, 3);
|
||||||
|
case NSHelpButtonBezelStyle:
|
||||||
|
[self drawCircularBezel: frame withColor: color];
|
||||||
|
break;
|
||||||
|
case NSDisclosureBezelStyle:
|
||||||
|
case NSRoundedDisclosureBezelStyle:
|
||||||
|
case NSRecessedBezelStyle:
|
||||||
|
// FIXME
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
[color set];
|
||||||
|
NSRectFill(frame);
|
||||||
|
|
||||||
if (state == GSThemeNormalState || state == GSThemeHighlightedState)
|
if (state == GSThemeNormalState || state == GSThemeHighlightedState)
|
||||||
{
|
{
|
||||||
[self drawButton: frame withClip: NSZeroRect];
|
[self drawButton: frame withClip: NSZeroRect];
|
||||||
}
|
}
|
||||||
else if (state == GSThemeSelectedState)
|
else if (state == GSThemeSelectedState)
|
||||||
{
|
{
|
||||||
[self drawGrayBezel: frame withClip: NSZeroRect];
|
[self drawGrayBezel: frame withClip: NSZeroRect];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -761,8 +806,34 @@ static NSNull *null = nil;
|
||||||
|
|
||||||
if (tiles == nil)
|
if (tiles == nil)
|
||||||
{
|
{
|
||||||
// FIXME: Should take style into account
|
switch (style)
|
||||||
return NSMakeSize(3, 3);
|
{
|
||||||
|
case NSRoundRectBezelStyle:
|
||||||
|
case NSTexturedRoundBezelStyle:
|
||||||
|
case NSRoundedBezelStyle:
|
||||||
|
return NSMakeSize(5, 5);
|
||||||
|
case NSTexturedSquareBezelStyle:
|
||||||
|
return NSMakeSize(3, 3);
|
||||||
|
case NSSmallSquareBezelStyle:
|
||||||
|
case NSRegularSquareBezelStyle:
|
||||||
|
case NSShadowlessSquareBezelStyle:
|
||||||
|
return NSMakeSize(2, 2);
|
||||||
|
case NSThickSquareBezelStyle:
|
||||||
|
return NSMakeSize(3, 3);
|
||||||
|
case NSThickerSquareBezelStyle:
|
||||||
|
return NSMakeSize(4, 4);
|
||||||
|
case NSCircularBezelStyle:
|
||||||
|
return NSMakeSize(5, 5);
|
||||||
|
case NSHelpButtonBezelStyle:
|
||||||
|
return NSMakeSize(2, 2);
|
||||||
|
case NSDisclosureBezelStyle:
|
||||||
|
case NSRoundedDisclosureBezelStyle:
|
||||||
|
case NSRecessedBezelStyle:
|
||||||
|
// FIXME
|
||||||
|
return NSMakeSize(0, 0);
|
||||||
|
default:
|
||||||
|
return NSMakeSize(3, 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1045,6 +1116,49 @@ static NSNull *null = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) drawRoundBezel: (NSRect)cellFrame withColor: (NSColor*)backgroundColor
|
||||||
|
{
|
||||||
|
NSBezierPath *p = [NSBezierPath bezierPath];
|
||||||
|
NSPoint point;
|
||||||
|
float radius;
|
||||||
|
|
||||||
|
// make smaller than enclosing frame
|
||||||
|
cellFrame = NSInsetRect(cellFrame, 4, floor(cellFrame.size.height * 0.1875));
|
||||||
|
radius = cellFrame.size.height / 2.0;
|
||||||
|
point = cellFrame.origin;
|
||||||
|
point.x += radius;
|
||||||
|
point.y += radius;
|
||||||
|
// left half-circle
|
||||||
|
[p appendBezierPathWithArcWithCenter: point radius: radius startAngle: 90.0 endAngle: 270.0];
|
||||||
|
|
||||||
|
// line to first point and right halfcircle
|
||||||
|
point.x += cellFrame.size.width - cellFrame.size.height;
|
||||||
|
[p appendBezierPathWithArcWithCenter: point radius: radius startAngle: 270.0 endAngle: 90.0];
|
||||||
|
[p closePath];
|
||||||
|
|
||||||
|
// fill with background color
|
||||||
|
[backgroundColor set];
|
||||||
|
[p fill];
|
||||||
|
|
||||||
|
// and stroke rounded button
|
||||||
|
[[NSColor shadowColor] set];
|
||||||
|
[p stroke];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) drawCircularBezel: (NSRect)cellFrame withColor: (NSColor*)backgroundColor
|
||||||
|
{
|
||||||
|
// make smaller so that it does not touch frame
|
||||||
|
NSBezierPath *oval = [NSBezierPath bezierPathWithOvalInRect: NSInsetRect(cellFrame, 1, 1)];
|
||||||
|
|
||||||
|
// fill oval with background color
|
||||||
|
[backgroundColor set];
|
||||||
|
[oval fill];
|
||||||
|
|
||||||
|
// and stroke rounded button
|
||||||
|
[[NSColor shadowColor] set];
|
||||||
|
[oval stroke];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1592,7 +1592,7 @@ typedef struct _GSButtonCellFlags
|
||||||
|
|
||||||
// style and border.
|
// style and border.
|
||||||
bFlags2 != [self showsBorderOnlyWhileMouseInside] ? 0x8 : 0;
|
bFlags2 != [self showsBorderOnlyWhileMouseInside] ? 0x8 : 0;
|
||||||
bFlags2 |= [self bezelStyle];
|
bFlags2 |= (([self bezelStyle] & 0x7) | (([self bezelStyle] & 0x18) << 2));
|
||||||
[aCoder encodeInt: bFlags2 forKey: @"NSButtonFlags2"];
|
[aCoder encodeInt: bFlags2 forKey: @"NSButtonFlags2"];
|
||||||
|
|
||||||
// alternate image encoding...
|
// alternate image encoding...
|
||||||
|
@ -1714,40 +1714,7 @@ typedef struct _GSButtonCellFlags
|
||||||
|
|
||||||
bFlags2 = [aDecoder decodeIntForKey: @"NSButtonFlags2"];
|
bFlags2 = [aDecoder decodeIntForKey: @"NSButtonFlags2"];
|
||||||
[self setShowsBorderOnlyWhileMouseInside: (bFlags2 & 0x8)];
|
[self setShowsBorderOnlyWhileMouseInside: (bFlags2 & 0x8)];
|
||||||
|
[self setBezelStyle: (bFlags2 & 0x7) | ((bFlags2 & 0x20) >> 2)];
|
||||||
// FIXME
|
|
||||||
switch (bFlags2 & 0x27)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
[self setBezelStyle: NSRoundedBezelStyle];
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
[self setBezelStyle: NSRegularSquareBezelStyle];
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
[self setBezelStyle: NSThickSquareBezelStyle];
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
[self setBezelStyle: NSThickerSquareBezelStyle];
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
[self setBezelStyle: NSDisclosureBezelStyle];
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
[self setBezelStyle: NSShadowlessSquareBezelStyle];
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
[self setBezelStyle: NSCircularBezelStyle];
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
[self setBezelStyle: NSTexturedSquareBezelStyle];
|
|
||||||
break;
|
|
||||||
case 33:
|
|
||||||
[self setBezelStyle: NSHelpButtonBezelStyle];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ([aDecoder containsValueForKey: @"NSAlternateImage"])
|
if ([aDecoder containsValueForKey: @"NSAlternateImage"])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue