mirror of
https://github.com/gnustep/libs-back.git
synced 2025-02-24 04:11:28 +00:00
Add simple gradient implementation for the cairo backend.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@28873 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
fa0ec57ac5
commit
6653ef68cc
5 changed files with 160 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2009-10-23 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/gsc/GSContext.m,
|
||||||
|
* Headers/gsc/GSGStateOps.h,
|
||||||
|
* Source/gsc/GSGState.m: Empty definitions of gradient methods.
|
||||||
|
* Source/cairo/CairoGState.m: Simple cairo gradient implementation.
|
||||||
|
|
||||||
2009-10-20 Fred Kiefer <FredKiefer@gmx.de>
|
2009-10-20 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/winlib/WIN32GState.m: Small correction of last change.
|
* Source/winlib/WIN32GState.m: Small correction of last change.
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#ifndef _GSGStateOps_h_INCLUDE
|
#ifndef _GSGStateOps_h_INCLUDE
|
||||||
#define _GSGStateOps_h_INCLUDE
|
#define _GSGStateOps_h_INCLUDE
|
||||||
|
|
||||||
|
@class NSGradient;
|
||||||
|
|
||||||
@interface GSGState (Ops)
|
@interface GSGState (Ops)
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/* Color operations */
|
/* Color operations */
|
||||||
|
@ -166,4 +168,20 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface GSGState (NSGradient)
|
||||||
|
|
||||||
|
- (void) drawGradient: (NSGradient*)gradient
|
||||||
|
fromCenter: (NSPoint)startCenter
|
||||||
|
radius: (CGFloat)startRadius
|
||||||
|
toCenter: (NSPoint)endCenter
|
||||||
|
radius: (CGFloat)endRadius
|
||||||
|
options: (NSUInteger)options;
|
||||||
|
|
||||||
|
- (void) drawGradient: (NSGradient*)gradient
|
||||||
|
fromPoint: (NSPoint)startPoint
|
||||||
|
toPoint: (NSPoint)endPoint
|
||||||
|
options: (NSUInteger)options;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <AppKit/NSAffineTransform.h>
|
#include <AppKit/NSAffineTransform.h>
|
||||||
#include <AppKit/NSBezierPath.h>
|
#include <AppKit/NSBezierPath.h>
|
||||||
#include <AppKit/NSColor.h>
|
#include <AppKit/NSColor.h>
|
||||||
|
#include <AppKit/NSGradient.h>
|
||||||
#include <AppKit/NSGraphics.h>
|
#include <AppKit/NSGraphics.h>
|
||||||
#include "cairo/CairoGState.h"
|
#include "cairo/CairoGState.h"
|
||||||
#include "cairo/CairoFontInfo.h"
|
#include "cairo/CairoFontInfo.h"
|
||||||
|
@ -1413,3 +1414,86 @@ _set_op(cairo_t *ct, NSCompositingOperation op)
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation CairoGState (NSGradient)
|
||||||
|
|
||||||
|
- (void) drawGradient: (NSGradient*)gradient
|
||||||
|
fromCenter: (NSPoint)startCenter
|
||||||
|
radius: (CGFloat)startRadius
|
||||||
|
toCenter: (NSPoint)endCenter
|
||||||
|
radius: (CGFloat)endRadius
|
||||||
|
options: (NSUInteger)options
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int stops = [gradient numberOfColorStops];
|
||||||
|
NSPoint startP = [ctm transformPoint: startCenter];
|
||||||
|
NSPoint endP = [ctm transformPoint: endCenter];
|
||||||
|
cairo_pattern_t *cpattern = cairo_pattern_create_radial(startP.x, startP.y,
|
||||||
|
floatFromUserSpace(ctm, startRadius),
|
||||||
|
endP.x, endP.y,
|
||||||
|
floatFromUserSpace(ctm, endRadius));
|
||||||
|
for (i = 0; i < stops; i++)
|
||||||
|
{
|
||||||
|
NSColor *color;
|
||||||
|
CGFloat location;
|
||||||
|
double red;
|
||||||
|
double green;
|
||||||
|
double blue;
|
||||||
|
double alpha;
|
||||||
|
|
||||||
|
[gradient getColor: &color
|
||||||
|
location: &location
|
||||||
|
atIndex: i];
|
||||||
|
red = [color redComponent];
|
||||||
|
green = [color greenComponent];
|
||||||
|
blue = [color blueComponent];
|
||||||
|
alpha = [color alphaComponent];
|
||||||
|
cairo_pattern_add_color_stop_rgba(cpattern, location,
|
||||||
|
red, green, blue, alpha);
|
||||||
|
}
|
||||||
|
cairo_save(_ct);
|
||||||
|
cairo_set_source(_ct, cpattern);
|
||||||
|
cairo_pattern_destroy(cpattern);
|
||||||
|
cairo_paint(_ct);
|
||||||
|
cairo_restore(_ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) drawGradient: (NSGradient*)gradient
|
||||||
|
fromPoint: (NSPoint)startPoint
|
||||||
|
toPoint: (NSPoint)endPoint
|
||||||
|
options: (NSUInteger)options
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int stops = [gradient numberOfColorStops];
|
||||||
|
NSPoint startP = [ctm transformPoint: startPoint];
|
||||||
|
NSPoint endP = [ctm transformPoint: endPoint];
|
||||||
|
cairo_pattern_t *cpattern = cairo_pattern_create_linear(startP.x, startP.y,
|
||||||
|
endP.x, endP.y);
|
||||||
|
|
||||||
|
for (i = 0; i < stops; i++)
|
||||||
|
{
|
||||||
|
NSColor *color;
|
||||||
|
CGFloat location;
|
||||||
|
double red;
|
||||||
|
double green;
|
||||||
|
double blue;
|
||||||
|
double alpha;
|
||||||
|
|
||||||
|
[gradient getColor: &color
|
||||||
|
location: &location
|
||||||
|
atIndex: i];
|
||||||
|
red = [color redComponent];
|
||||||
|
green = [color greenComponent];
|
||||||
|
blue = [color blueComponent];
|
||||||
|
alpha = [color alphaComponent];
|
||||||
|
cairo_pattern_add_color_stop_rgba(cpattern, location,
|
||||||
|
red, green, blue, alpha);
|
||||||
|
}
|
||||||
|
cairo_save(_ct);
|
||||||
|
cairo_set_source(_ct, cpattern);
|
||||||
|
cairo_pattern_destroy(cpattern);
|
||||||
|
cairo_paint(_ct);
|
||||||
|
cairo_restore(_ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
|
@ -1001,3 +1001,32 @@ static NSMapTable *gtable;
|
||||||
ctxt_pop(obj, opstack, NSObject);
|
ctxt_pop(obj, opstack, NSObject);
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation GSContext (NSGradient)
|
||||||
|
- (void) drawGradient: (NSGradient*)gradient
|
||||||
|
fromCenter: (NSPoint)startCenter
|
||||||
|
radius: (CGFloat)startRadius
|
||||||
|
toCenter: (NSPoint)endCenter
|
||||||
|
radius: (CGFloat)endRadius
|
||||||
|
options: (NSUInteger)options
|
||||||
|
{
|
||||||
|
[gstate drawGradient: gradient
|
||||||
|
fromCenter: startCenter
|
||||||
|
radius: startRadius
|
||||||
|
toCenter: endCenter
|
||||||
|
radius: endRadius
|
||||||
|
options: options];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) drawGradient: (NSGradient*)gradient
|
||||||
|
fromPoint: (NSPoint)startPoint
|
||||||
|
toPoint: (NSPoint)endPoint
|
||||||
|
options: (NSUInteger)options
|
||||||
|
{
|
||||||
|
[gstate drawGradient: gradient
|
||||||
|
fromPoint: startPoint
|
||||||
|
toPoint: endPoint
|
||||||
|
options: options];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
|
@ -1304,3 +1304,25 @@ typedef enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation GSGState (NSGradient)
|
||||||
|
|
||||||
|
- (void) drawGradient: (NSGradient*)gradient
|
||||||
|
fromCenter: (NSPoint)startCenter
|
||||||
|
radius: (CGFloat)startRadius
|
||||||
|
toCenter: (NSPoint)endCenter
|
||||||
|
radius: (CGFloat)endRadius
|
||||||
|
options: (NSUInteger)options
|
||||||
|
{
|
||||||
|
[self subclassResponsibility: _cmd];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) drawGradient: (NSGradient*)gradient
|
||||||
|
fromPoint: (NSPoint)startPoint
|
||||||
|
toPoint: (NSPoint)endPoint
|
||||||
|
options: (NSUInteger)options
|
||||||
|
{
|
||||||
|
[self subclassResponsibility: _cmd];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
Loading…
Reference in a new issue