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