New drawing function and small patches on button cell.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@18593 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2004-02-13 18:27:34 +00:00
parent e447a55ea3
commit 38d9d84c34
4 changed files with 113 additions and 5 deletions

View file

@ -1,3 +1,13 @@
2004-02-11 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSButtonCel.m: (-setObjectValue:, -objectValue)
Implemented to set/return the state.
(-mouseEntered:, -mouseExited:, -drawWithFrame:inView:)
Partially added old showsBorderOnlyWhileMouseInside patch from
Michael Hanni (mhanni@yahoo.com).
* Headers/Additions/GNUstepGUI/GSDrawFunctions.h:
* Source/GSDrawFunctions.m: New gradient border drawing method.
2004-02-12 Adam Fedor <fedor@gnu.org> 2004-02-12 Adam Fedor <fedor@gnu.org>
* Documentation/GuiUser/KeyboardSetup.gsdoc: Update. * Documentation/GuiUser/KeyboardSetup.gsdoc: Update.

View file

@ -28,6 +28,8 @@
#define _GNUstep_H_GSDrawFunctions #define _GNUstep_H_GSDrawFunctions
#include <Foundation/NSGeometry.h> #include <Foundation/NSGeometry.h>
// For gradient types
#include "AppKit/NSButtonCell.h"
@class NSColor; @class NSColor;
@ -41,6 +43,10 @@
+ (void) drawGroove: (NSRect)border : (NSRect)clip; + (void) drawGroove: (NSRect)border : (NSRect)clip;
+ (void) drawFramePhoto: (NSRect)border : (NSRect)clip; + (void) drawFramePhoto: (NSRect)border : (NSRect)clip;
+ (NSRect) drawGradient: (NSGradientType)gradientType
inRect: (NSRect)border
withClip: (NSRect)clip;
@end @end
#endif /* _GNUstep_H_GSDrawFunctions */ #endif /* _GNUstep_H_GSDrawFunctions */

View file

@ -26,8 +26,8 @@
#include "GNUstepGUI/GSDrawFunctions.h" #include "GNUstepGUI/GSDrawFunctions.h"
#include "AppKit/NSColor.h" #include "AppKit/NSColor.h"
#include "AppKit/NSView.h"
#include "AppKit/NSGraphics.h" #include "AppKit/NSGraphics.h"
#include "AppKit/NSView.h"
#include "AppKit/PSOperators.h" #include "AppKit/PSOperators.h"
@ -237,4 +237,58 @@
} }
} }
/** Draw a gradient border. */
+ (NSRect) drawGradientBorder: (NSGradientType)gradientType
inRect: (NSRect)border
withClip: (NSRect)clip
{
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge,
NSMinXEdge, NSMaxYEdge};
NSRectEdge dn_sides[] = {NSMaxXEdge, NSMaxYEdge,
NSMinXEdge, NSMinYEdge};
NSColor *black = [NSColor controlDarkShadowColor];
NSColor *dark = [NSColor controlShadowColor];
NSColor *light = [NSColor controlColor];
NSColor **colors;
NSColor *concaveWeak[] = {dark, dark,
light, light};
NSColor *concaveStrong[] = {black, black,
light, light};
NSColor *convexWeak[] = {light, light,
dark, dark};
NSColor *convexStrong[] = {light, light,
black, black};
NSRect rect;
switch (gradientType)
{
case NSGradientConcaveWeak:
colors = concaveWeak;
break;
case NSGradientConcaveStrong:
colors = concaveStrong;
break;
case NSGradientConvexWeak:
colors = convexWeak;
break;
case NSGradientConvexStrong:
colors = convexStrong;
break;
case NSGradientNone:
default:
return border;
}
if ([[NSView focusView] isFlipped] == YES)
{
rect = NSDrawColorTiledRects(border, clip, dn_sides, colors, 4);
}
else
{
rect = NSDrawColorTiledRects(border, clip, up_sides, colors, 4);
}
return rect;
}
@end @end

View file

@ -36,6 +36,7 @@
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSDebug.h> #include <Foundation/NSDebug.h>
#include <Foundation/NSValue.h>
#include <GNUstepBase/GSCategories.h> #include <GNUstepBase/GSCategories.h>
#include "AppKit/AppKitExceptions.h" #include "AppKit/AppKitExceptions.h"
@ -446,8 +447,13 @@
- (void)setShowsBorderOnlyWhileMouseInside:(BOOL)show - (void)setShowsBorderOnlyWhileMouseInside:(BOOL)show
{ {
// FIXME: Switch mouse tracking on if (_shows_border_only_while_mouse_inside == show)
{
return;
}
_shows_border_only_while_mouse_inside = show; _shows_border_only_while_mouse_inside = show;
// FIXME Switch mouse tracking on
} }
- (NSGradientType)gradientType - (NSGradientType)gradientType
@ -584,8 +590,37 @@
return _cell.state; return _cell.state;
} }
// FIXME: The spec says that the stringValue and setStringValue methods should - (void) setObjectValue: (id)object
// also be redefined. But this does not fit to the way we uses this for the title. {
if (object == nil)
{
[self setState: NSOffState];
}
else if ([object respondsToSelector: @selector(intValue)])
{
[self setState: [object intValue]];
}
else
{
[self setState: NSOnState];
}
}
- (id) objectValue
{
if (_cell.state == NSOffState)
{
return [NSNumber numberWithBool: NO];
}
else if (_cell.state == NSOnState)
{
return [NSNumber numberWithBool: YES];
}
else // NSMixedState
{
return [NSNumber numberWithInt: -1];
}
}
/* /*
* Displaying * Displaying
@ -615,7 +650,8 @@
return; return;
// draw the border if needed // draw the border if needed
if (_cell.is_bordered) if ((_cell.is_bordered) &&
(!_shows_border_only_while_mouse_inside || _mouse_inside))
{ {
// FIXME Should check the bezel and gradient style // FIXME Should check the bezel and gradient style
if (_cell.is_highlighted && (_highlightsByMask & NSPushInCellMask)) if (_cell.is_highlighted && (_highlightsByMask & NSPushInCellMask))
@ -1057,11 +1093,13 @@
- (void) mouseEntered: (NSEvent *)event - (void) mouseEntered: (NSEvent *)event
{ {
_mouse_inside = YES; _mouse_inside = YES;
[(NSView *)[event userData] setNeedsDisplay: YES];
} }
- (void) mouseExited: (NSEvent *)event - (void) mouseExited: (NSEvent *)event
{ {
_mouse_inside = NO; _mouse_inside = NO;
[(NSView *)[event userData] setNeedsDisplay: YES];
} }
- (void) performClick: (id)sender - (void) performClick: (id)sender