//
//  LCCanvasRootLayer.h
//  LogoistCore
//
//  Created by Mendel Kucharzeck on 15.12.11.
//  Copyright 2011 AvisNocturna Software. All rights reserved.
//

@class LCObjectsContainer;
@class LCCanvasContentLayer;
@class LCCanvasBaseLayer;
@class LCCanvasDemoLayer;
@class LCBaseObjectHandle;
@class LCCanvasSnappingGuideContainerLayer;
@class LCCanvasSelectionRectLayer;
@class LCBaseObjectTool;
@class LCCanvasRulerLayer;
@class LCObjectsContainerRulerGuide;

@protocol LCCanvasRootLayerProtocol;
#import <LogoistCore/LCObjectsContainerDelegate.h>
#import <LogoistCore/LCCanvasProtocol.h>

@interface LCCanvasRootLayer : CALayer <LCObjectsContainerDelegate,LCCanvasProtocol>
{
    LCObjectsContainer *objectsContainer;
    
    LCCanvasContentLayer *contentLayer;
    LCCanvasSnappingGuideContainerLayer *snappingGuideContainerLayer;
    CALayer *gridContainerLayer;
    CALayer *backgroundShadowLayer;
    CALayer *handlesContainerLayer;
    CALayer *rulerGuideContainerLayer;
    BOOL didShowBackgroundShadowLayerAnim;

    LCCanvasDemoLayer *demoLayer;
    
    NSMutableArray *delegates;
    
    NSMutableArray *selectedObjects;
    NSMutableArray *currentHandles;
    NSMutableArray *selectedHandles;
    NSMutableArray *dragHandles;
    
    NSMutableSet *layers;
    
    float zoomFactor;
    BOOL isZooming;
    
    float renderQualityDivisor;
    
    BOOL showHandles;
    
    //Snapping
    NSMutableArray *snappingGuideLayers;
    
    //Grid
    NSMutableArray *horizontalGridLayers;
    NSMutableArray *verticalGridLayers;
    
    //Events
    CGPoint mouseDownPoint;
    CGPoint lastDragPoint;
    CGPoint lastCursorPosition;
    LCCanvasBaseLayer *mouseDownLayer;
    LCCanvasBaseLayer *realMouseDownLayer;
    BOOL mouseDraggedAfterDown;
    BOOL mouseDownCalled;
    BOOL didCallDragStart;
    BOOL beginUndoGroupingCalledForRotateEvent;
    BOOL toolHandledMouseDown;
    
    //Selection Rect
    LCCanvasSelectionRectLayer *selectionRectLayer;
    
    //Tools
    LCBaseObjectTool *currentTool;

    //Rulers
    LCCanvasRulerLayer *horizontalRulerLayer;
    LCCanvasRulerLayer *verticalRulerLayer;
    
    //Ruler Guides
    NSMutableArray *rulerGuideLayers;
    LCObjectsContainerRulerGuide *addedAndCurrentlyDraggedRulerGuide;
}

@property (retain) LCObjectsContainer *objectsContainer;

- (void) addDelegate:(id <LCCanvasRootLayerProtocol>)d;
- (void) removeDelegate:(id <LCCanvasRootLayerProtocol>)d;

- (void) addObjectsToSelectedObjects:(NSArray*)objects;
- (void) removeObjectsFromSelectedObjects:(NSSet*)objects;
- (void) selectObjectsInRect:(CGRect)rect;
@property (copy) NSArray *selectedObjects;

@property (readonly) CGSize minimumSize;

- (void) setShowDemoLayer:(BOOL)show;

- (void) beginZooming;
@property (assign) float zoomFactor;
@property (readonly) BOOL isZooming;
- (void) endZooming;

@property (assign) float renderQualityDivisor;  //Zoom factor will be devided by this value, 1 means full quality, 2 means half quality

@end
