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, 84 uint32 nameIndex) = 0; 85 86 bool IsRotating() const 87 { return fCurrentState == fRotateState; } 88 virtual double ViewSpaceRotation() const; 89 90 // Listener support 91 bool AddListener(TransformBoxListener* listener); 92 bool RemoveListener(TransformBoxListener* listener); 93 94 private: 95 DragState* _DragStateFor(BPoint canvasWhere, 96 float canvasZoom); 97 void _StrokeBWLine(BView* into, 98 BPoint from, BPoint to) const; 99 void _StrokeBWPoint(BView* into, 100 BPoint point, 101 double angle) const; 102 103 BRect fOriginalBox; 104 105 BPoint fLeftTop; 106 BPoint fRightTop; 107 BPoint fLeftBottom; 108 BPoint fRightBottom; 109 110 BPoint fPivot; 111 BPoint fPivotOffset; 112 113 TransformCommand* fCurrentCommand; 114 DragState* fCurrentState; 115 116 bool fDragging; 117 BPoint fMousePos; 118 uint32 fModifiers; 119 120 bool fNudging; 121 122 BList fListeners; 123 124 protected: 125 void _NotifyDeleted() const; 126 127 // "static" state objects 128 StateView* fView; 129 130 DragState* fDragLTState; 131 DragState* fDragRTState; 132 DragState* fDragLBState; 133 DragState* fDragRBState; 134 135 DragState* fDragLState; 136 DragState* fDragRState; 137 DragState* fDragTState; 138 DragState* fDragBState; 139 140 DragState* fRotateState; 141 DragState* fTranslateState; 142 DragState* fOffsetCenterState; 143 }; 144 145 #endif // TRANSFORM_BOX_H 146