xref: /haiku/src/apps/icon-o-matic/CanvasView.h (revision 4fac07a0887406d944d78403f8a3b01a4e6154be)
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				FilterMouse(BPoint* where) const;
40 
41 	// Scrollable interface
42  protected:
43 	virtual	void				ScrollOffsetChanged(BPoint oldOffset,
44 													BPoint newOffset);
45 	virtual	void				VisibleSizeChanged(float oldWidth,
46 												   float oldHeight,
47 												   float newWidth,
48 												   float newHeight);
49 	// IconListener interface
50  public:
51 	virtual	void				AreaInvalidated(const BRect& area);
52 
53 	// CanvasView
54 			void				SetIcon(Icon* icon);
55 
56 	inline	float				ZoomLevel() const
57 									{ return fZoomLevel; }
58 
59 			void				SetMouseFilterMode(uint32 mode);
60 			bool				MouseFilterMode() const
61 									{ return fMouseFilterMode; }
62 
63 			void				ConvertFromCanvas(BPoint* point) const;
64 			void				ConvertToCanvas(BPoint* point) const;
65 
66 			void				ConvertFromCanvas(BRect* rect) const;
67 			void				ConvertToCanvas(BRect* rect) const;
68 
69  protected:
70 	// StateView interface
71 	virtual	bool				_HandleKeyDown(uint32 key, uint32 modifiers);
72 
73 	// CanvasView
74 			BRect				_CanvasRect() const;
75 
76 			void				_AllocBackBitmap(float width,
77 												 float height);
78 			void				_FreeBackBitmap();
79 			void				_DrawInto(BView* view,
80 										  BRect updateRect);
81 
82 			void				_MakeBackground();
83 
84  private:
85 			double				_NextZoomInLevel(double zoom) const;
86 			double				_NextZoomOutLevel(double zoom) const;
87 			void				_SetZoom(double zoomLevel);
88 			BRect				_LayoutCanvas();
89 
90 			BBitmap*			fBitmap;
91 			BBitmap*			fBackground;
92 
93 			Icon*				fIcon;
94 			IconRenderer*		fRenderer;
95 			BRect				fDirtyIconArea;
96 
97 			BPoint				fCanvasOrigin;
98 			double				fZoomLevel;
99 
100 			uint32				fMouseFilterMode;
101 
102 			BBitmap*			fOffsreenBitmap;
103 			BView*				fOffsreenView;
104 };
105 
106 #endif // CANVAS_VIEW_H
107