view dstep/appkit/NSGradient.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents
children b9de51448c6b
line wrap: on
line source

/**
 * Copyright: Copyright (c) 2009 Jacob Carlborg.
 * Authors: Jacob Carlborg
 * Version: Initial created: Sep 24, 2009 
 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
 */
module dstep.appkit.NSGradient;

import dstep.appkit.NSBezierPath;
import dstep.appkit.NSColor;
import dstep.appkit.NSColorSpace;
import dstep.applicationservices.coregraphics.CGBase;
import dstep.foundation.NSArray;
import dstep.foundation.NSCoder;
import dstep.foundation.NSGeometry;
import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSObject;
import dstep.foundation.NSZone;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;

typedef NSUInteger NSGradientDrawingOptions;

enum
{
	NSGradientDrawsBeforeStartingLocation = (1 << 0),
	NSGradientDrawsAfterEndingLocation = (1 << 1)
}

class NSGradient : NSObject, INSCopying, INSCoding
{
	mixin (ObjcWrap);
	
	this (NSCoder aDecoder)
	{
		super(typeof(this).alloc.initWithCoder(aDecoder).objcObject);
	}
	
	void encodeWithCoder (NSCoder aCoder)
	{
		return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
	}
	
	typeof(this) initWithCoder (NSCoder aDecoder)
	{
		return invokeObjcSelf!(typeof(this), "initWithCoder:", NSCoder)(aDecoder);
	}
	
	typeof(this) copyWithZone (NSZone* zone)
	{
		return invokeObjcSelf!(typeof(this), "copyWithZone:", NSZone*)(zone);
	}

	NSGradient initWithStartingColor (NSColor startingColor, NSColor endingColor)
	{
		id result = invokeObjcSelf!(id, "initWithStartingColor:endingColor:", NSColor, NSColor)(startingColor, endingColor);
		return result is this.objcObject ? this : (result !is null ? new NSGradient(result) : null);
	}

	this (NSColor startingColor, NSColor endingColor)
	{
		super(NSGradient.alloc.initWithStartingColor(startingColor, endingColor).objcObject);
	}

	NSGradient initWithColors (NSArray colorArray)
	{
		id result = invokeObjcSelf!(id, "initWithColors:", NSArray)(colorArray);
		return result is this.objcObject ? this : (result !is null ? new NSGradient(result) : null);
	}

	this (NSArray colorArray)
	{
		super(NSGradient.alloc.initWithColors(colorArray).objcObject);
	}

	NSGradient initWithColorsAndLocations (NSColor initWithColorsAndLocations, ...)
	{
		id result = invokeObjcSelf!(id, "initWithColorsAndLocations:", NSColor)(initWithColorsAndLocations);
		return result is this.objcObject ? this : (result !is null ? new NSGradient(result) : null);
	}

	this (NSColor initWithColorsAndLocations, ...)
	{
		super(NSGradient.alloc.initWithColorsAndLocations(initWithColorsAndLocations).objcObject);
	}

	NSGradient initWithColors (NSArray colorArray, CGFloat* locations, NSColorSpace colorSpace)
	{
		id result = invokeObjcSelf!(id, "initWithColors:atLocations:colorSpace:", NSArray, CGFloat*, NSColorSpace)(colorArray, locations, colorSpace);
		return result is this.objcObject ? this : (result !is null ? new NSGradient(result) : null);
	}

	this (NSArray colorArray, CGFloat* locations, NSColorSpace colorSpace)
	{
		super(NSGradient.alloc.initWithColors(colorArray, locations, colorSpace).objcObject);
	}

	void drawFromPoint (NSPoint startingPoint, NSPoint endingPoint, uint options)
	{
		return invokeObjcSelf!(void, "drawFromPoint:toPoint:options:", NSPoint, NSPoint, uint)(startingPoint, endingPoint, options);
	}

	void drawInRect (NSRect rect, CGFloat angle)
	{
		return invokeObjcSelf!(void, "drawInRect:angle:", NSRect, CGFloat)(rect, angle);
	}

	void drawInBezierPath (NSBezierPath path, CGFloat angle)
	{
		return invokeObjcSelf!(void, "drawInBezierPath:angle:", NSBezierPath, CGFloat)(path, angle);
	}

	void drawFromCenter (NSPoint startCenter, CGFloat startRadius, NSPoint endCenter, CGFloat endRadius, uint options)
	{
		return invokeObjcSelf!(void, "drawFromCenter:radius:toCenter:radius:options:", NSPoint, CGFloat, NSPoint, CGFloat, uint)(startCenter, startRadius, endCenter, endRadius, options);
	}

	void drawInRect (NSRect rect, NSPoint relativeCenterPosition)
	{
		return invokeObjcSelf!(void, "drawInRect:relativeCenterPosition:", NSRect, NSPoint)(rect, relativeCenterPosition);
	}

	void drawInBezierPath (NSBezierPath path, NSPoint relativeCenterPosition)
	{
		return invokeObjcSelf!(void, "drawInBezierPath:relativeCenterPosition:", NSBezierPath, NSPoint)(path, relativeCenterPosition);
	}

	NSColorSpace colorSpace ()
	{
		return invokeObjcSelf!(NSColorSpace, "colorSpace");
	}

	NSInteger numberOfColorStops ()
	{
		return invokeObjcSelf!(NSInteger, "numberOfColorStops");
	}

	void getColor (ref NSColor color, CGFloat* location, NSInteger index)
	{
		id c;
		
		if (color)
			c = color.objcObject;
		
		invokeObjcSelf!(void, "getColor:location:atIndex:", id*, CGFloat*, NSInteger)(&c, location, index);
		
		if (c)
			color = new NSColor(c);
	}

	NSColor interpolatedColorAtLocation (CGFloat location)
	{
		return invokeObjcSelf!(NSColor, "interpolatedColorAtLocation:", CGFloat)(location);
	}

}