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