Image dimming and gradient drawing added

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19721 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Sergii Stoian 2004-07-12 21:42:31 +00:00
parent 1abdf4ed3e
commit cf5f059c65

View file

@ -41,6 +41,7 @@
#include "AppKit/AppKitExceptions.h"
#include "AppKit/NSApplication.h"
#include "AppKit/NSBezierPath.h"
#include "AppKit/NSButtonCell.h"
#include "AppKit/NSButton.h"
#include "AppKit/NSColor.h"
@ -52,6 +53,8 @@
#include "AppKit/NSWindow.h"
#include "GNUstepGUI/GSDrawFunctions.h"
#include <math.h>
@implementation NSButtonCell
/*
@ -82,6 +85,8 @@
_keyEquivalentModifierMask = NSCommandKeyMask;
_keyEquivalent = @"";
_altContents = @"";
_gradient_type = NSGradientNone;
_image_dims_when_disabled = NO;
return self;
}
@ -416,22 +421,22 @@
return !_buttoncell_is_transparent && _cell.is_bordered;
}
- (NSBezelStyle)bezelStyle
- (NSBezelStyle) bezelStyle
{
return _bezel_style;
}
- (void)setBezelStyle:(NSBezelStyle)bezelStyle
- (void) setBezelStyle: (NSBezelStyle)bezelStyle
{
_bezel_style = bezelStyle;
}
- (BOOL)showsBorderOnlyWhileMouseInside
- (BOOL) showsBorderOnlyWhileMouseInside
{
return _shows_border_only_while_mouse_inside;
}
- (void)setShowsBorderOnlyWhileMouseInside:(BOOL)show
- (void) setShowsBorderOnlyWhileMouseInside: (BOOL)show
{
if (_shows_border_only_while_mouse_inside == show)
{
@ -442,22 +447,22 @@
// FIXME Switch mouse tracking on
}
- (NSGradientType)gradientType
- (NSGradientType) gradientType
{
return _gradient_type;
}
- (void)setGradientType:(NSGradientType)gradientType
- (void) setGradientType: (NSGradientType)gradientType
{
_gradient_type = gradientType;
}
- (BOOL)imageDimsWhenDisabled
- (BOOL) imageDimsWhenDisabled
{
return _image_dims_when_disabled;
}
- (void)setImageDimsWhenDisabled:(BOOL)flag
- (void) setImageDimsWhenDisabled:(BOOL)flag
{
_image_dims_when_disabled = flag;
}
@ -653,6 +658,105 @@
[self drawInteriorWithFrame: cellFrame inView: controlView];
}
- (void) drawGradientWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
float start_white = 0.0;
float end_white = 0.0;
float white = 0.0;
float white_step = 0.0;
float h, s, v, a;
NSColor *lightGray = nil;
NSColor *gray = nil;
NSColor *darkGray = nil;
NSPoint p1, p2;
lightGray = [NSColor colorWithDeviceRed:0.83 green:0.83 blue:0.83 alpha:1.0];
gray = [NSColor colorWithDeviceRed:0.50 green:0.50 blue:0.50 alpha:1.0];
darkGray = [NSColor colorWithDeviceRed:0.32 green:0.32 blue:0.32 alpha:1.0];
switch (_gradient_type)
{
case NSGradientNone:
return;
break;
case NSGradientConcaveWeak:
[gray getHue: &h saturation: &s brightness: &v alpha: &a];
start_white = [lightGray brightnessComponent];
end_white = [gray brightnessComponent];
break;
case NSGradientConvexWeak:
[darkGray getHue: &h saturation: &s brightness: &v alpha: &a];
start_white = [gray brightnessComponent];
end_white = [lightGray brightnessComponent];
break;
case NSGradientConcaveStrong:
[lightGray getHue: &h saturation: &s brightness: &v alpha: &a];
start_white = [lightGray brightnessComponent];
end_white = [darkGray brightnessComponent];
break;
case NSGradientConvexStrong:
[darkGray getHue: &h saturation: &s brightness: &v alpha: &a];
start_white = [darkGray brightnessComponent];
end_white = [lightGray brightnessComponent];
break;
default:
break;
}
white = start_white;
white_step = fabs(start_white - end_white)/
(cellFrame.size.width + cellFrame.size.height);
// Start from top left
p1 = NSMakePoint(cellFrame.origin.x,
cellFrame.size.height + cellFrame.origin.y);
p2 = NSMakePoint(cellFrame.origin.x,
cellFrame.size.height + cellFrame.origin.y);
// Move by Y
while (p1.y > cellFrame.origin.y)
{
[[NSColor
colorWithDeviceHue: h saturation: s brightness: white alpha: 1.0] set];
[NSBezierPath strokeLineFromPoint: p1 toPoint: p2];
if (start_white > end_white)
white -= white_step;
else
white += white_step;
p1.y -= 1.0;
if (p2.x < (cellFrame.size.width + cellFrame.origin.x))
p2.x += 1.0;
else
p2.y -= 1.0;
}
// Move by X
while (p1.x < (cellFrame.size.width + cellFrame.origin.x))
{
[[NSColor
colorWithDeviceHue: h saturation: s brightness: white alpha: 1.0] set];
[NSBezierPath strokeLineFromPoint: p1 toPoint: p2];
if (start_white > end_white)
white -= white_step;
else
white += white_step;
p1.x += 1.0;
if (p2.x >= (cellFrame.size.width + cellFrame.origin.x))
p2.y -= 1.0;
else
p2.x += 1.0;
}
}
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
unsigned mask;
@ -877,6 +981,14 @@
// TODO: Add distance from border if needed
break;
}
// Draw gradient
if (!_cell.is_highlighted && _gradient_type != NSGradientNone)
{
[self drawGradientWithFrame: cellFrame inView: controlView];
}
// Draw image
if (imageToDisplay != nil)
{
NSSize size;
@ -893,13 +1005,25 @@
{
position.y += size.height;
}
[imageToDisplay compositeToPoint: position operation: NSCompositeSourceOver];
if (_cell.is_disabled && _image_dims_when_disabled)
{
[imageToDisplay dissolveToPoint: position fraction: 0.5];
}
else
{
[imageToDisplay compositeToPoint: position
operation: NSCompositeSourceOver];
}
}
// Draw title
if (titleToDisplay != nil)
{
[self _drawAttributedText: titleToDisplay inFrame: titleRect];
}
// Draw first responder
if (_cell.shows_first_responder
&& [[controlView window] firstResponder] == controlView)
{