unit SchemeVisual;

  TClipRectChangeType = (vcZoomIn,vcZoomOut,vcHorz,vcVert);

  TSchemeVisualClipRectChangeEvent =
    procedure(Sender:TObject; ANewVisibleRect,AOldClipRect:TRect;
      AType:TClipRectChangeType) of object;

  TSchemeVisualShowHintEvent =
    procedure(Sender:TObject;
      AObject: TAbstractPaintObject;
      APoint: TPoint;
      var HintString:string;
      var CanVisible:boolean) of object;

  TSchemeVisual = class(TCustomControl)
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    property  Canvas:TCanvas read GetCanvas;
    function  FindPaintObject(AIdLayer,AIdObject:integer):TAbstractPaintObject;
    procedure FindPaintObjectDirect(AObject:TAbstractPaintObject);
    procedure SetCenterToPoint(Value:TPoint);
    function  GetCenterPoint:TPoint;
    procedure TransformZoomAndOriginXY(var X,Y:integer); 
    procedure TransformZoomAndOriginXYExt(var X,Y:extended);
    property  ScrollPosX:cardinal read FScrollPosX;
    property  ScrollPosY:cardinal read FScrollPosY;
    function  OwnerInFocus:boolean; virtual;
    procedure RepaintOnlySchemeData;
  published
    property Align;
    property DragKind;
    property DragMode;
    property Color: TColor read GetColor write SetColor;
    property Grid:  TSchemeGridType read FGrid write SetGrid;
    property GridPen: TPen read FGridPen write SetGridPen;
    property HintWidth:integer read FHintWidth write FHintWidth;
    property HintHeight:integer read FHintHeight write FHintHeight;
    property HintColor: TColor read FHintColor write FHintColor;
    property HintPause: Integer read FHintPause write FHintPause;
    property HintHidePause: Integer read FHintHidePause write FHintHidePause;
    property ShowHint:boolean read FHintShow write FHintShow;
    property SchemeData: TSchemeData read FSchemeData write SetSchemeData;
    property Picture: TPicture read FPicture write SetPicture;
    property PopupMenu;
    property TabOrder;
    property TabStop;
    property Visible;
    property Param: integer read FParam write SetParam;
    property Zoom: extended read FZoom write SetZoom;
    property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
    property OnClipRectChange: TSchemeVisualClipRectChangeEvent
      read FOnClipRectChange write FOnClipRectChange;
    property OnShowHint: TSchemeVisualShowHintEvent read FOnShowHint
      write FOnShowHint;
    property OnHideHint: TNotifyEvent read FOnHideHint write FOnHideHint;
    property OnClick;
    property OnDblClick;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnDragDrop;
    property OnDragOver;
  end;


  TSchemeVisualEditor = class(TSchemeVisual)
  public
    constructor Create(AOwner: TComponent); override;
    procedure CancelObjectMoving(ARepaint:boolean); virtual;
    property ObjectDragging:boolean read bDragging;
  published
    property  DragCursor:TCursor read FDragCursor write SetDragCursor;
    property MinZoomForResize:extended read FMinZoomForResize write FMinZoomForResize;
    property EditEnabled:boolean read FEditEnabled write FEditEnabled;
  end;


  TSchemeDataMouseDown =
    procedure(Sender,VisualSender:TObject; Button:TMouseButton;
      Shift: TShiftState; AObject: TAbstractPaintObject) of object;

  TSchemeDataObjectStatusChangeEvent =
    procedure(Sender:TObject;
      AIdLayer,AIdObject: Integer;
      AOldState:integer;
      var ANewState:integer;
      var CanChange:boolean) of object;

  TSchemeDataObjectPaint =
    procedure(Sender,VisualSender:TObject;
      AObject: TAbstractPaintObject;
      AZoom:extended;ACanvas:TCanvas;AParam:integer=0) of object;

  TSchemeData = class(TComponent)
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    procedure PaintDirectInWindow(VisualSender:TObject);
    procedure PaintDirectInCanvas(ACanvas:TCanvas; //paint direct in Canvas
      AOffsetX,AOffsetY,AZoom:extended;AParam:integer);
    procedure RepaintAllVisualControls(AOnlyData:boolean=false);
    procedure BeginUpdate;
    procedure EndUpdate;
    function  LayerAddDirect(Value:TSchemeLayer):TSchemeLayer;
    function  LayerAdd(AIdLayer:integer):TSchemeLayer;
    procedure LayerDelete(AIdLayer:integer);
    procedure LayerClear;
    property  Layer[AIdLayer:integer]:TSchemeLayer read GetLayer write SetLayer;
    property  LayerIndex[AIndex:integer]:TSchemeLayer read GetLayerIndex write SetLayerIndex;
    function  LayerCount:integer;
    function  LayerExist(AIdLayer:integer):boolean;
    procedure LayerPaintDirectInWindow(Value:TSchemeLayer;VisualSender:TObject);
    procedure LayerPaintDirect(Value:TSchemeLayer);  
    procedure LayerPaint(AIdLayer:integer);
    procedure LayerRepaintDirect(Value:TSchemeLayer);
    procedure LayerRepaint(AIdLayer:integer);
    property  LayerStateColor[AIdLayer:integer;AIdState:integer]:TColor read GetStateColor write SetStateColor;
    procedure LayerSetAllStateColors(AIdLayer:integer;Value:array of TColor); 
    procedure LayerSelectAllObjects(AIdLayer:integer;Value:boolean); //select/deselect all objects in layer
    procedure LayerExchange(AIdLayer1,AIdLayer2:integer);
    function  ObjectAddDirect(AIdLayer:integer;
      Value:TAbstractPaintObject):TAbstractPaintObject;
    function  ObjectAddShape(AIdLayer,AIdObject:integer;ARect:TRect;AState:integer;AShape:TShapeType):TPaintObjectShape;
    function  ObjectAddShapeExt(AIdLayer,AIdObject:integer;
      AX,AY,AW,AH:extended;AState:integer;AShape:TShapeType):TPaintObjectShape;
    function  ObjectAddZone(AIdLayer,AIdObject:integer;
      APoints:array of TPoint;
      AState:integer; ABrushStyle:TBrushStyle;
      const AString:string;
      AStringPoint:TPoint):TPaintObjectZone;
    function  ObjectAddZoneAmount(AIdLayer,AIdObject:integer;
      APoints:array of TPoint;
      AAmount:integer;
      AState:integer; ABrushStyle:TBrushStyle;
      const AString:string;
      AStringPoint:TPoint):TPaintObjectZone;
    function  ObjectAddZoneFromBuffer(AIdLayer,AIdObject:integer;
      APoints:Pointer; APointsCount:integer;
      AState:integer; ABrushStyle:TBrushStyle;
      const AString:string;
      AStringPointNumber:integer):TPaintObjectZone;
    procedure ObjectDelete(AIdLayer,AIdObject:integer);
    procedure ObjectDeleteDirect(Value:TAbstractPaintObject);
    procedure ObjectPaintDirectInWindow(Value:TAbstractPaintObject;VisualSender:TObject);
    procedure ObjectPaint(AIdLayer,AIdObject:integer);
    procedure ObjectPaintDirect(Value:TAbstractPaintObject);
    procedure ObjectRepaint(AIdLayer,AIdObject:integer);
    procedure ObjectRepaintDirect(Value:TAbstractPaintObject);
    procedure ObjectRepaintDirectInWindow(Value:TAbstractPaintObject;VisualSender:TObject);
    property  ObjectState[AIdLayer:integer;AIdObject:integer]:integer read GetObjectState write SetObjectState;
    property  ObjectStateDirect[Value:TAbstractPaintObject]:integer read GetObjectStateDirect write SetObjectStateDirect;
    property  ObjectSelected[AIdLayer:integer;AIdObject:integer]:boolean read GetObjectSelected write SetObjectSelected;
    property  ObjectSelectedDirect[Value:TAbstractPaintObject]:boolean read GetObjectSelectedDirect write SetObjectSelectedDirect;
    property  ObjectVisible[AIdLayer:integer;AIdObject:integer]:boolean read GetObjectVisible write SetObjectVisible;
    property  ObjectVisibleDirect[Value:TAbstractPaintObject]:boolean read GetObjectVisibleDirect write SetObjectVisibleDirect;
    function  ObjectForPoint(AX,AY:extended;AParam:integer):TAbstractPaintObject;
    function  ObjectForPointWithCheckEnabled(AX,AY:extended;
      ACheckEnabled:boolean;AParam:integer):TAbstractPaintObject; //protected
    function  ObjectFind(AIdLayer,AIdObject:integer):TAbstractPaintObject;
    procedure ObjectFindDirect(Value:TAbstractPaintObject);
    procedure ObjectExchangeUp(AIdLayer,AIdObject:integer);
    procedure ObjectExchangeDown(AIdLayer,AIdObject:integer);
    procedure ObjectExchangeUpDirect(Value:TAbstractPaintObject);
    procedure ObjectExchangeDownDirect(Value:TAbstractPaintObject);
    procedure LoadFromFile(const FileName: string); virtual;
    procedure SaveToFile(const FileName: string); virtual;
  published
    property  DefaultDrawing:boolean read FDefaultDrawing write SetDefaultDrawing;
    property  TimerInterval:integer read FTimerInterval write SetTimerInterval;
    property  OnMouseDown: TSchemeDataMouseDown read FOnMouseDown write FOnMouseDown;
    property  OnObjectStatusChange: TSchemeDataObjectStatusChangeEvent read FOnObjectStatusChange write FOnObjectStatusChange;
    property  OnObjectPaint: TSchemeDataObjectPaint read FOnObjectPaint write FOnObjectPaint;
  end;

  TSchemeDataEditor = class(TSchemeData)
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    procedure ObjectDeleteResizedPointDirect(Value:TAbstractPaintObject);
    procedure ObjectAddResizedPointDirect(Value:TAbstractPaintObject);
    procedure AlignPointToGrid(var X,Y:extended);
  published
    property  AlignToGrid:  TSchemeGridType read FGrid write SetGrid;
    property  FullMovedDrawing:boolean read FFullMovedDrawing write FFullMovedDrawing;
  end;


procedure Register;
