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