1 /* 2 * Copyright 2006-2007, 2023, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 * Zardshard 8 */ 9 #ifndef PERSPECTIVE_BOX_H 10 #define PERSPECTIVE_BOX_H 11 12 #include <List.h> 13 #include <Point.h> 14 #include <Referenceable.h> 15 16 #include "Manipulator.h" 17 18 19 namespace PerspectiveBoxStates { 20 class DragState; 21 } 22 23 class CanvasView; 24 class Command; 25 class PerspectiveCommand; 26 class PerspectiveBox; 27 class PerspectiveTransformer; 28 29 30 class PerspectiveBoxListener { 31 public: 32 PerspectiveBoxListener() {} 33 virtual ~PerspectiveBoxListener() {} 34 35 virtual void PerspectiveBoxDeleted( 36 const PerspectiveBox* box) = 0; 37 }; 38 39 40 class PerspectiveBox : public Manipulator { 41 public: 42 PerspectiveBox(CanvasView* view, 43 PerspectiveTransformer* parent); 44 virtual ~PerspectiveBox(); 45 46 // Manipulator interface 47 virtual void Draw(BView* into, BRect updateRect); 48 49 virtual bool MouseDown(BPoint where); 50 virtual void MouseMoved(BPoint where); 51 virtual Command* MouseUp(); 52 virtual bool MouseOver(BPoint where); 53 54 virtual BRect Bounds(); 55 virtual BRect TrackingBounds(BView* withinView); 56 57 virtual void ModifiersChanged(uint32 modifiers); 58 59 virtual bool UpdateCursor(); 60 61 virtual void AttachedToView(BView* view); 62 virtual void DetachedFromView(BView* view); 63 64 // Observer interface 65 virtual void ObjectChanged(const Observable* object); 66 67 // PerspectiveTransformBox 68 void TransformTo(BPoint leftTop, BPoint rightTop, 69 BPoint leftBottom, BPoint rightBottom); 70 71 virtual void Update(bool deep = true); 72 73 Command* FinishTransaction(); 74 75 // Listener support 76 bool AddListener(PerspectiveBoxListener* listener); 77 bool RemoveListener(PerspectiveBoxListener* listener); 78 79 private: 80 void _NotifyDeleted() const; 81 PerspectiveBoxStates::DragState* _DragStateFor( 82 BPoint canvasWhere, float canvasZoom); 83 void _StrokeBWLine(BView* into, 84 BPoint from, BPoint to) const; 85 void _StrokeBWPoint(BView* into, 86 BPoint point, double angle) const; 87 88 private: 89 BPoint fLeftTop; 90 BPoint fRightTop; 91 BPoint fLeftBottom; 92 BPoint fRightBottom; 93 94 PerspectiveCommand* fCurrentCommand; 95 PerspectiveBoxStates::DragState* fCurrentState; 96 97 bool fDragging; 98 BPoint fMousePos; 99 uint32 fModifiers; 100 101 BList fListeners; 102 103 BRect fPreviousBox; 104 105 // "static" state objects 106 CanvasView* fCanvasView; 107 BReference<PerspectiveTransformer> fPerspective; 108 109 PerspectiveBoxStates::DragState* fDragLTState; 110 PerspectiveBoxStates::DragState* fDragRTState; 111 PerspectiveBoxStates::DragState* fDragLBState; 112 PerspectiveBoxStates::DragState* fDragRBState; 113 }; 114 115 #endif // PERSPECTIVE_BOX_H 116