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