//
//  CODAttachedWindow.h
//
//  Created by Shlok Datye on 31.07.2014.
//  Copyright (c) 2014 Coding Turtle. All rights reserved.
//
//  Based on Matt Gemmell’s MAAttachedWindow.
//

#import <Cocoa/Cocoa.h>


typedef NS_ENUM(NSUInteger, CODAttachedWindowArrowLocation) {
  CODAttachedWindowArrowLocationTop,
  CODAttachedWindowArrowLocationBottom
};


//Note: This class only represents the window itself--its shape and size.
//This class does not care about how or when we actually show the window.
//Neither does this class really care about the window’s frame, in a sense; to change the frame, the outside world can modify the “point” property.
//In particular, it is up to the outside world to, e.g., dynamically change the window’s shape (including its arrowLocation) and position (using the “point” property) after some “parent” view or window moves.

@interface CODAttachedWindow : NSWindow

//After initializing (using -init), configure the window further using the following properties.
//If any are skipped, “sensible” default values are used.
//Usually, most of these properties will be set up before the window is shown.
//However, they can all be safely changed even when the window is already shown; things will be adjusted accordingly.
//When changing more than one attribute at once while the window is visible and things get choppy, try wrapping these changes within NSDisableScreenUpdates() and NSEnableScreenUpdates().

@property(nonatomic) NSView *view; //“nonatomic” to suppress compiler warning (“Writable atomic property 'view' cannot pair a synthesized getter with a user defined setter”).

@property CODAttachedWindowArrowLocation arrowLocation;
@property NSPoint point; //the tip of the window’s arrow--in screen coordinates.

@property CGFloat distance; //distance between point and window
@property NSColor *borderColor;
@property CGFloat borderWidth; //see note 1 below
@property CGFloat viewMargin;
@property CGFloat arrowBaseWidth;
@property CGFloat arrowHeight;
@property BOOL hasArrow;
@property CGFloat cornerRadius;
@property NSImage *backgroundImage;
@property NSColor *windowBackgroundColor; //see note 2 below

//Notes regarding properties.
//1. The border is drawn inside the viewMargin area, expanding inwards; it does not
//   increase the width/height of the window. You can use the borderWidth and
//   viewMargin properties together to achieve the exact look/geometry you want.
//   (viewMargin is the distance between the edge of the view and the window edge.)
//2. Note that to retrieve the background color of the window, you should use the
//   “windowBackgroundColor” property, instead of -backgroundColor. This is because
//   we draw the entire background of the window (rounded path, arrow, etc.) in an
//   NSColor pattern image, and set it as the backgroundColor of the window.

@end
