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 #ifndef CANVAS_VIEW_H 9 #define CANVAS_VIEW_H 10 11 12 #include "Icon.h" 13 #include "Scrollable.h" 14 #include "StateView.h" 15 16 17 class BBitmap; 18 19 namespace BPrivate { 20 namespace Icon { 21 class IconRenderer; 22 } 23 } 24 using namespace BPrivate::Icon; 25 26 enum { 27 SNAPPING_OFF = 0, 28 SNAPPING_64, 29 SNAPPING_32, 30 SNAPPING_16, 31 }; 32 33 class CanvasView : public StateView, 34 public Scrollable, 35 public IconListener { 36 public: 37 CanvasView(BRect frame); 38 virtual ~CanvasView(); 39 40 // StateView interface 41 virtual void AttachedToWindow(); 42 virtual void FrameResized(float width, float height); 43 virtual void Draw(BRect updateRect); 44 45 virtual void MouseDown(BPoint where); 46 virtual void MouseUp(BPoint where); 47 virtual void MouseMoved(BPoint where, uint32 transit, 48 const BMessage* dragMessage); 49 virtual void FilterMouse(BPoint* where) const; 50 51 virtual bool MouseWheelChanged(BPoint where, 52 float x, float y); 53 54 // Scrollable interface 55 protected: 56 virtual void ScrollOffsetChanged(BPoint oldOffset, 57 BPoint newOffset); 58 virtual void VisibleSizeChanged(float oldWidth, 59 float oldHeight, 60 float newWidth, 61 float newHeight); 62 // IconListener interface 63 public: 64 virtual void AreaInvalidated(const BRect& area); 65 66 // CanvasView 67 void SetIcon(Icon* icon); 68 69 inline float ZoomLevel() const 70 { return fZoomLevel; } 71 72 void SetMouseFilterMode(uint32 mode); 73 bool MouseFilterMode() const 74 { return fMouseFilterMode; } 75 76 void ConvertFromCanvas(BPoint* point) const; 77 void ConvertToCanvas(BPoint* point) const; 78 79 void ConvertFromCanvas(BRect* rect) const; 80 void ConvertToCanvas(BRect* rect) const; 81 82 protected: 83 // StateView interface 84 virtual bool _HandleKeyDown(uint32 key, uint32 modifiers); 85 virtual bool _HandleKeyUp(uint32 key, uint32 modifiers); 86 87 // CanvasView 88 BRect _CanvasRect() const; 89 90 void _AllocBackBitmap(float width, 91 float height); 92 void _FreeBackBitmap(); 93 void _DrawInto(BView* view, 94 BRect updateRect); 95 96 void _MakeBackground(); 97 98 void _UpdateToolCursor(); 99 100 private: 101 double _NextZoomInLevel(double zoom) const; 102 double _NextZoomOutLevel(double zoom) const; 103 void _SetZoom(double zoomLevel, 104 bool mouseIsAnchor = true); 105 BRect _LayoutCanvas(); 106 107 BBitmap* fBitmap; 108 BBitmap* fBackground; 109 110 Icon* fIcon; 111 IconRenderer* fRenderer; 112 BRect fDirtyIconArea; 113 114 BPoint fCanvasOrigin; 115 double fZoomLevel; 116 117 bool fSpaceHeldDown; 118 bool fScrollTracking; 119 BPoint fScrollTrackingStart; 120 BPoint fScrollOffsetStart; 121 122 uint32 fMouseFilterMode; 123 124 BBitmap* fOffsreenBitmap; 125 BView* fOffsreenView; 126 }; 127 128 #endif // CANVAS_VIEW_H 129