//
//  GSGradient.h
//  GlyphsCore
//
//  Created by Georg Seifert on 26.08.19.
//  Copyright © 2019 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GSElement.h>
#import <GlyphsCore/GSDrawEnvironment.h>

@class GSColorLine;

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(int8_t, GSGradientType) {
	GSGradientTypeLinear = 0,
	GSGradientTypeRadial = 1,
	/// A.k.a. angular or sweep
	GSGradientTypeConic = 2,
};

typedef NS_ENUM(int8_t, GSGradientExtendMode) {
	GSGradientExtendModePad = 0,
	GSGradientExtendModeRepeat = 1,
	GSGradientExtendModeReflect = 2,
};

@interface GSGradient : GSElement

@property (nonatomic, readonly) GSGradientType type;
@property (nonatomic, strong) GSColorLine *colorLine;
@property (nonatomic) GSGradientExtendMode extendMode;
/// A transform that is applied to the gradient independently from the region that is filled with the gradient.
@property (assign) CGAffineTransform transform;

- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithPropertyListValue:(NSDictionary *)dict format:(GSFormatVersion)formatVersion;

+ (GSGradient *)gradientWithType:(GSGradientType)type bounds:(NSRect)bounds baseColor:(nullable NSColor *)baseColor;

/// Converts the gradient to the given type while trying to match the UI of the gradient as closely as possible.
- (GSGradient *)convertedToType:(GSGradientType)type;

/// Returns the bounds of the draw stack slice of which the path of the gradient is a part.
///
/// If the gradient has no parent, returns `CGRectNull`.
- (NSRect)drawBounds;

/// Draws the gradient in the current graphics context, transforming the gradient control points based on the given reference rectangle.
- (void)drawWithReferenceRect:(NSRect)referenceRect environment:(GSDrawEnvironment *)environment;

@end

NS_ASSUME_NONNULL_END
