xref: /haiku/src/servers/app/Canvas.h (revision 2db0fbd87ec3eeed8ab9b08ecfd1c41891c7e3a6)
1 /*
2  * Copyright (c) 2001-2015, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Adi Oanca <adioanca@gmail.com>
8  *		Axel Dörfler, axeld@pinc-software.de
9  *		Stephan Aßmus <superstippi@gmx.de>
10  *		Marcus Overhagen <marcus@overhagen.de>
11  *		Adrien Destugues <pulkomandy@pulkomandy.tk>
12  *		Julian Harnath <julian.harnath@rwth-aachen.de>
13  */
14 #ifndef CANVAS_H
15 #define CANVAS_H
16 
17 
18 #include <AutoDeleter.h>
19 #include <Point.h>
20 
21 #include "SimpleTransform.h"
22 
23 
24 class AlphaMask;
25 class BGradient;
26 class BRegion;
27 class DrawingEngine;
28 class DrawState;
29 class IntPoint;
30 class IntRect;
31 class Layer;
32 class ServerPicture;
33 class shape_data;
34 
35 
36 class Canvas {
37 public:
38 							Canvas();
39 							Canvas(const DrawState& state);
40 	virtual					~Canvas();
41 
42 			status_t		InitCheck() const;
43 
44 	virtual	void			PushState();
45 	virtual	void			PopState();
46 			DrawState*		CurrentState() const { return fDrawState.Get(); }
47 			void			SetDrawState(DrawState* newState);
48 			DrawState*		DetachDrawState() { return fDrawState.Detach(); }
49 
50 			void			SetDrawingOrigin(BPoint origin);
51 			BPoint			DrawingOrigin() const;
52 
53 			void			SetScale(float scale);
54 			float			Scale() const;
55 
56 			void			SetUserClipping(const BRegion* region);
57 				// region is expected in view coordinates
58 
59 			bool			ClipToRect(BRect rect, bool inverse);
60 			void			ClipToShape(shape_data* shape, bool inverse);
61 
62 			void			SetAlphaMask(AlphaMask* mask);
63 			AlphaMask*		GetAlphaMask() const;
64 
65 	virtual	IntRect			Bounds() const = 0;
66 
67 			SimpleTransform LocalToScreenTransform() const;
68 			SimpleTransform ScreenToLocalTransform() const;
69 			SimpleTransform PenToScreenTransform() const;
70 			SimpleTransform PenToLocalTransform() const;
71 			SimpleTransform ScreenToPenTransform() const;
72 
73 			void			BlendLayer(Layer* layer);
74 
75 	virtual	DrawingEngine*	GetDrawingEngine() const = 0;
76 	virtual ServerPicture*	GetPicture(int32 token) const = 0;
77 	virtual	void			RebuildClipping(bool deep) = 0;
78 	virtual void			ResyncDrawState() {};
79 	virtual void			UpdateCurrentDrawingRegion() {};
80 
81 protected:
82 	virtual	void			_LocalToScreenTransform(
83 								SimpleTransform& transform) const = 0;
84 	virtual	void			_ScreenToLocalTransform(
85 								SimpleTransform& transform) const = 0;
86 
87 protected:
88 			ObjectDeleter<DrawState>
89 							fDrawState;
90 };
91 
92 
93 class OffscreenCanvas : public Canvas {
94 public:
95 							OffscreenCanvas(DrawingEngine* engine,
96 								const DrawState& state, const IntRect& bounds);
97 	virtual					~OffscreenCanvas();
98 
99 	virtual DrawingEngine*	GetDrawingEngine() const { return fDrawingEngine; }
100 
101 	virtual void			RebuildClipping(bool deep) { /* TODO */ }
102 	virtual void			ResyncDrawState();
103 	virtual void			UpdateCurrentDrawingRegion();
104 	virtual ServerPicture*	GetPicture(int32 token) const
105 								{ /* TODO */ return NULL; }
106 	virtual	IntRect			Bounds() const;
107 
108 protected:
109 	virtual	void			_LocalToScreenTransform(SimpleTransform&) const {}
110 	virtual	void			_ScreenToLocalTransform(SimpleTransform&) const {}
111 
112 private:
113 			DrawingEngine*	fDrawingEngine;
114 			BRegion			fCurrentDrawingRegion;
115 			IntRect			fBounds;
116 };
117 
118 
119 #endif // CANVAS_H
120