//
//  GSGradientKnob.h
//  GlyphsCore
//
//  Created by Florian Pircher on 28.05.22.
//  Copyright © 2022 schriftgestaltung.de. All rights reserved.
//

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

@class GSGradient;
@class GSColorStop;

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(uint8_t, GSGradientKnobType) {
	GSGradientKnobTypeLinear = 0,
	GSGradientKnobTypeRadialCenter = 1,
	GSGradientKnobTypeRadialHandle = 2,
	GSGradientKnobTypeConicCenter = 3,
	GSGradientKnobTypeConicHandle = 4,
};

@interface GSGradientKnob : NSObject <GSSelectableElementProtocol>

@property (weak, nullable) GSContainer *parent;
@property (assign) GSGradientKnobType type;
@property (strong) GSGradient *gradient;
/// `-1` if the knob is not about a color stop
@property (assign) NSInteger colorStopIndex;
/// All related knobs, including the knob itself. The order is not consistent; consult `colorStopIndex` of the members to get a knob for a specific color stop. `nil` if the knob is not about a color stop or the knob is not selected.
@property (strong, nullable) NSArray<GSGradientKnob *> *knobLine;
@property (strong) GSGradient *shadowGradient;

@property (nonatomic, readonly) BOOL isStart;
@property (nonatomic, readonly) BOOL isEnd;
/// Union of the bounds of all paths of the gradients of the color stops. (A ‘slice’ is an element of a draw stack.)
@property (nonatomic, readonly) NSRect sliceBounds;
@property (assign, nonatomic, getter=isSnappingToAlignment) BOOL snappingToAlignment;

+ (GSGradientKnob *)knobAt:(NSPoint)position parent:(id)parent type:(GSGradientKnobType)type forGradient:(GSGradient *)gradient colorStopIndex:(NSInteger)colorStopIndex;
+ (GSGradientKnob *)knobAt:(NSPoint)position parent:(id)parent type:(GSGradientKnobType)type forGradient:(GSGradient *)gradient;

- (void)performColorStopModificationWithBlock:(void (^)(GSColorStop *))block;
- (void)performGradientModificationWithBlock:(void (^)(id))block;

@end

NS_ASSUME_NONNULL_END
