mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 07:20:58 +00:00
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:
parent
fa830b1182
commit
b804b93692
1 changed files with 148 additions and 24 deletions
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
#include "AppKit/AppKitExceptions.h"
|
#include "AppKit/AppKitExceptions.h"
|
||||||
#include "AppKit/NSApplication.h"
|
#include "AppKit/NSApplication.h"
|
||||||
|
#include "AppKit/NSBezierPath.h"
|
||||||
#include "AppKit/NSButtonCell.h"
|
#include "AppKit/NSButtonCell.h"
|
||||||
#include "AppKit/NSButton.h"
|
#include "AppKit/NSButton.h"
|
||||||
#include "AppKit/NSColor.h"
|
#include "AppKit/NSColor.h"
|
||||||
|
@ -52,6 +53,8 @@
|
||||||
#include "AppKit/NSWindow.h"
|
#include "AppKit/NSWindow.h"
|
||||||
#include "GNUstepGUI/GSDrawFunctions.h"
|
#include "GNUstepGUI/GSDrawFunctions.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
@implementation NSButtonCell
|
@implementation NSButtonCell
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -82,6 +85,8 @@
|
||||||
_keyEquivalentModifierMask = NSCommandKeyMask;
|
_keyEquivalentModifierMask = NSCommandKeyMask;
|
||||||
_keyEquivalent = @"";
|
_keyEquivalent = @"";
|
||||||
_altContents = @"";
|
_altContents = @"";
|
||||||
|
_gradient_type = NSGradientNone;
|
||||||
|
_image_dims_when_disabled = NO;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -653,6 +658,105 @@
|
||||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
[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
|
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
{
|
{
|
||||||
unsigned mask;
|
unsigned mask;
|
||||||
|
@ -877,6 +981,14 @@
|
||||||
// TODO: Add distance from border if needed
|
// TODO: Add distance from border if needed
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw gradient
|
||||||
|
if (!_cell.is_highlighted && _gradient_type != NSGradientNone)
|
||||||
|
{
|
||||||
|
[self drawGradientWithFrame: cellFrame inView: controlView];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw image
|
||||||
if (imageToDisplay != nil)
|
if (imageToDisplay != nil)
|
||||||
{
|
{
|
||||||
NSSize size;
|
NSSize size;
|
||||||
|
@ -893,13 +1005,25 @@
|
||||||
{
|
{
|
||||||
position.y += size.height;
|
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)
|
if (titleToDisplay != nil)
|
||||||
{
|
{
|
||||||
[self _drawAttributedText: titleToDisplay inFrame: titleRect];
|
[self _drawAttributedText: titleToDisplay inFrame: titleRect];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw first responder
|
||||||
if (_cell.shows_first_responder
|
if (_cell.shows_first_responder
|
||||||
&& [[controlView window] firstResponder] == controlView)
|
&& [[controlView window] firstResponder] == controlView)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue