1 /* 2 * Copyright 2006-2007, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #ifndef TRANSFORM_BOX_H 10 #define TRANSFORM_BOX_H 11 12 #include <List.h> 13 14 #include "ChannelTransform.h" 15 #include "Manipulator.h" 16 17 class Command; 18 class StateView; 19 class DragState; 20 class TransformBox; 21 class TransformCommand; 22 23 class TransformBoxListener { 24 public: 25 TransformBoxListener(); 26 virtual ~TransformBoxListener(); 27 28 virtual void TransformBoxDeleted( 29 const TransformBox* box) = 0; 30 }; 31 32 class TransformBox : public ChannelTransform, 33 public Manipulator { 34 public: 35 TransformBox(StateView* view, 36 BRect box); 37 virtual ~TransformBox(); 38 39 // Manipulator interface 40 virtual void Draw(BView* into, BRect updateRect); 41 42 virtual bool MouseDown(BPoint where); 43 virtual void MouseMoved(BPoint where); 44 virtual Command* MouseUp(); 45 virtual bool MouseOver(BPoint where); 46 virtual bool DoubleClicked(BPoint where); 47 48 virtual BRect Bounds(); 49 virtual BRect TrackingBounds(BView* withinView); 50 51 virtual void ModifiersChanged(uint32 modifiers); 52 virtual bool HandleKeyDown(uint32 key, uint32 modifiers, 53 Command** _command); 54 virtual bool HandleKeyUp(uint32 key, uint32 modifiers, 55 Command** _command); 56 57 virtual bool UpdateCursor(); 58 59 virtual void AttachedToView(BView* view); 60 virtual void DetachedFromView(BView* view); 61 62 // TransformBox 63 virtual void Update(bool deep = true); 64 65 void OffsetCenter(BPoint offset); 66 BPoint Center() const; 67 void SetBox(BRect box); 68 BRect Box() const 69 { return fOriginalBox; } 70 71 Command* FinishTransaction(); 72 73 void NudgeBy(BPoint offset); 74 bool IsNudging() const 75 { return fNudging; } 76 Command* FinishNudging(); 77 78 virtual void TransformFromCanvas(BPoint& point) const; 79 virtual void TransformToCanvas(BPoint& point) const; 80 virtual float ZoomLevel() const; 81 82 83 virtual TransformCommand* MakeCommand(const char* actionName) = 0; 84 85 bool IsRotating() const 86 { return fCurrentState == fRotateState; } 87 virtual double ViewSpaceRotation() const; 88 89 // Listener support 90 bool AddListener(TransformBoxListener* listener); 91 bool RemoveListener(TransformBoxListener* listener); 92 93 private: 94 DragState* _DragStateFor(BPoint canvasWhere, 95 float canvasZoom); 96 void _StrokeBWLine(BView* into, 97 BPoint from, BPoint to) const; 98 void _StrokeBWPoint(BView* into, 99 BPoint point, 100 double angle) const; 101 102 BRect fOriginalBox; 103 104 BPoint fLeftTop; 105 BPoint fRightTop; 106 BPoint fLeftBottom; 107 BPoint fRightBottom; 108 109 BPoint fPivot; 110 BPoint fPivotOffset; 111 112 TransformCommand* fCurrentCommand; 113 DragState* fCurrentState; 114 115 bool fDragging; 116 BPoint fMousePos; 117 uint32 fModifiers; 118 119 bool fNudging; 120 121 BList fListeners; 122 123 protected: 124 void _NotifyDeleted() const; 125 126 // "static" state objects 127 StateView* fView; 128 129 DragState* fDragLTState; 130 DragState* fDragRTState; 131 DragState* fDragLBState; 132 DragState* fDragRBState; 133 134 DragState* fDragLState; 135 DragState* fDragRState; 136 DragState* fDragTState; 137 DragState* fDragBState; 138 139 DragState* fRotateState; 140 DragState* fTranslateState; 141 DragState* fOffsetCenterState; 142 }; 143 144 #endif // TRANSFORM_BOX_H 145