1 /* 2 * Copyright 2006, 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_STATES_H 10 #define TRANSFORM_BOX_STATES_H 11 12 #include <Point.h> 13 14 #include <agg_trans_affine.h> 15 16 class BView; 17 class TransformBox; 18 19 // TODO: remove and replace with translation string indices once multiple 20 // languages are supported 21 #define TRANSFORMATION 0 22 #define ROTATE 0 23 #define MOVE 0 24 #define SCALE 0 25 #define MOVE_PIVOT 0 26 // 27 28 // base class 29 class DragState { 30 public: 31 DragState(TransformBox* parent); 32 virtual ~DragState() {} 33 34 virtual void SetOrigin(BPoint origin); 35 virtual void DragTo(BPoint current, uint32 modifiers) = 0; 36 virtual void UpdateViewCursor(BView* view, BPoint current) const = 0; 37 38 virtual const char* ActionName() const; 39 virtual uint32 ActionNameIndex() const; 40 41 protected: 42 void _SetViewCursor(BView* view, 43 const uchar* cursorData) const; 44 45 BPoint fOrigin; 46 TransformBox* fParent; 47 }; 48 49 // scaling states 50 class DragCornerState : public DragState { 51 public: 52 enum { 53 LEFT_TOP_CORNER, 54 RIGHT_TOP_CORNER, 55 LEFT_BOTTOM_CORNER, 56 RIGHT_BOTTOM_CORNER, 57 }; 58 DragCornerState(TransformBox* parent, 59 uint32 corner); 60 virtual ~DragCornerState() {} 61 62 virtual void SetOrigin(BPoint origin); 63 virtual void DragTo(BPoint current, uint32 modifiers); 64 virtual void UpdateViewCursor(BView* view, BPoint current) const; 65 66 virtual const char* ActionName() const; 67 virtual uint32 ActionNameIndex() const; 68 69 private: 70 uint32 fCorner; 71 72 float fXOffsetFromCorner; 73 float fYOffsetFromCorner; 74 double fOldXScale; 75 double fOldYScale; 76 double fOldWidth; 77 double fOldHeight; 78 agg::trans_affine fMatrix; 79 BPoint fOldOffset; 80 }; 81 82 class DragSideState : public DragState { 83 public: 84 enum { 85 LEFT_SIDE, 86 TOP_SIDE, 87 RIGHT_SIDE, 88 BOTTOM_SIDE, 89 }; 90 DragSideState(TransformBox* parent, 91 uint32 side); 92 virtual ~DragSideState() {} 93 94 virtual void SetOrigin(BPoint origin); 95 virtual void DragTo(BPoint current, uint32 modifiers); 96 virtual void UpdateViewCursor(BView* view, BPoint current) const; 97 98 virtual const char* ActionName() const; 99 virtual uint32 ActionNameIndex() const; 100 101 private: 102 uint32 fSide; 103 104 float fOffsetFromSide; 105 double fOldXScale; 106 double fOldYScale; 107 double fOldSideDist; 108 agg::trans_affine fMatrix; 109 BPoint fOldOffset; 110 }; 111 112 // translate state 113 class DragBoxState : public DragState { 114 public: 115 DragBoxState(TransformBox* parent) 116 : DragState(parent) {} 117 virtual ~DragBoxState() {} 118 119 virtual void SetOrigin(BPoint origin); 120 virtual void DragTo(BPoint current, uint32 modifiers); 121 virtual void UpdateViewCursor(BView* view, BPoint current) const; 122 123 virtual const char* ActionName() const; 124 virtual uint32 ActionNameIndex() const; 125 126 private: 127 BPoint fOldTranslation; 128 }; 129 130 // rotate state 131 class RotateBoxState : public DragState { 132 public: 133 RotateBoxState(TransformBox* parent); 134 virtual ~RotateBoxState() {} 135 136 virtual void SetOrigin(BPoint origin); 137 virtual void DragTo(BPoint current, uint32 modifiers); 138 virtual void UpdateViewCursor(BView* view, BPoint current) const; 139 140 virtual const char* ActionName() const; 141 virtual uint32 ActionNameIndex() const; 142 143 private: 144 double fOldAngle; 145 }; 146 147 // offset center state 148 class OffsetCenterState : public DragState { 149 public: 150 OffsetCenterState(TransformBox* parent) 151 : DragState(parent) {} 152 virtual ~OffsetCenterState() {} 153 154 virtual void SetOrigin(BPoint origin); 155 virtual void DragTo(BPoint current, uint32 modifiers); 156 virtual void UpdateViewCursor(BView* view, BPoint current) const; 157 158 virtual const char* ActionName() const; 159 virtual uint32 ActionNameIndex() const; 160 161 }; 162 163 #endif // TRANSFORM_BOX_STATES_H 164