xref: /haiku/src/servers/app/DrawState.h (revision 850f2d1e58cc443f77353c7fc0ce0c158c1fd328)
1 /*
2  * Copyright 2001-2008, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Adi Oanca <adioanca@mymail.ro>
8  *		Stephan Aßmus <superstippi@gmx.de>
9  *		Axel Dörfler, axeld@pinc-software.de
10  */
11 #ifndef _DRAW_STATE_H_
12 #define _DRAW_STATE_H_
13 
14 
15 #include <AffineTransform.h>
16 #include <GraphicsDefs.h>
17 #include <InterfaceDefs.h>
18 #include <Point.h>
19 #include <View.h>
20 
21 #include "ServerFont.h"
22 #include "PatternHandler.h"
23 
24 class AlphaMask;
25 class BRegion;
26 
27 namespace BPrivate {
28 	class LinkReceiver;
29 	class LinkSender;
30 };
31 
32 
33 class DrawState {
34 public:
35 							DrawState();
36 							DrawState(const DrawState& other);
37 public:
38 		virtual				~DrawState();
39 
40 		DrawState*			PushState();
41 		DrawState*			PopState();
42 		DrawState*			PreviousState() const { return fPreviousState; }
43 
44 		void				ReadFontFromLink(BPrivate::LinkReceiver& link);
45 								// NOTE: ReadFromLink() does not read Font state!!
46 								// It was separate in ServerWindow, and I didn't
47 								// want to change it without knowing implications.
48 		void				ReadFromLink(BPrivate::LinkReceiver& link);
49 		void				WriteToLink(BPrivate::LinkSender& link) const;
50 
51 							// coordinate transformation
52 		void				SetOrigin(BPoint origin);
53 		BPoint				Origin() const
54 								{ return fOrigin; }
55 		BPoint				CombinedOrigin() const
56 								{ return fCombinedOrigin; }
57 
58 		void				SetScale(float scale);
59 		float				Scale() const
60 								{ return fScale; }
61 		float				CombinedScale() const
62 								{ return fCombinedScale; }
63 
64 		void				SetTransform(BAffineTransform transform);
65 		BAffineTransform	Transform() const
66 								{ return fTransform; }
67 		BAffineTransform	CombinedTransform() const
68 								{ return fCombinedTransform; }
69 
70 							// additional clipping as requested by client
71 		void				SetClippingRegion(const BRegion* region);
72 
73 		bool				HasClipping() const;
74 		bool				HasAdditionalClipping() const;
75 		bool				GetCombinedClippingRegion(BRegion* region) const;
76 
77 			void			SetAlphaMask(AlphaMask* mask);
78 			AlphaMask*		GetAlphaMask() const;
79 
80 							// coordinate transformations
81 				void		Transform(float* x, float* y) const;
82 				void		InverseTransform(float* x, float* y) const;
83 
84 				void		Transform(BPoint* point) const;
85 				void		Transform(BRect* rect) const;
86 				void		Transform(BRegion* region) const;
87 
88 				void		InverseTransform(BPoint* point) const;
89 
90 							// color
91 		void				SetHighColor(rgb_color color);
92 		rgb_color			HighColor() const
93 								{ return fHighColor; }
94 
95 		void				SetLowColor(rgb_color color);
96 		rgb_color			LowColor() const
97 								{ return fLowColor; }
98 
99 		void				SetPattern(const Pattern& pattern);
100 		const Pattern&		GetPattern() const
101 								{ return fPattern; }
102 
103 							// drawing/blending mode
104 		void				SetDrawingMode(drawing_mode mode);
105 		drawing_mode		GetDrawingMode() const
106 								{ return fDrawingMode; }
107 
108 		void				SetBlendingMode(source_alpha srcMode,
109 								alpha_function fncMode);
110 		source_alpha		AlphaSrcMode() const
111 								{ return fAlphaSrcMode; }
112 		alpha_function		AlphaFncMode() const
113 								{ return fAlphaFncMode; }
114 
115 							// pen
116 		void				SetPenLocation(BPoint location);
117 		BPoint				PenLocation() const;
118 
119 		void				SetPenSize(float size);
120 		float				PenSize() const;
121 		float				UnscaledPenSize() const;
122 
123 							// font
124 		void				SetFont(const ServerFont& font,
125 								uint32 flags = B_FONT_ALL);
126 		const ServerFont&	Font() const
127 								{ return fFont; }
128 
129 		// overrides aliasing flag contained in SeverFont::Flags())
130 		void				SetForceFontAliasing(bool aliasing);
131 		bool				ForceFontAliasing() const
132 								{ return fFontAliasing; }
133 
134 							// postscript style settings
135 		void				SetLineCapMode(cap_mode mode);
136 		cap_mode			LineCapMode() const
137 								{ return fLineCapMode; }
138 
139 		void				SetLineJoinMode(join_mode mode);
140 		join_mode			LineJoinMode() const
141 								{ return fLineJoinMode; }
142 
143 		void				SetMiterLimit(float limit);
144 		float				MiterLimit() const
145 								{ return fMiterLimit; }
146 
147 		void				SetFillRule(int32 fillRule);
148 		int32				FillRule() const
149 								{ return fFillRule; }
150 
151 							// convenience functions
152 		void				PrintToStream() const;
153 
154 		void				SetSubPixelPrecise(bool precise);
155 		bool				SubPixelPrecise() const
156 								{ return fSubPixelPrecise; }
157 
158 protected:
159 		BPoint				fOrigin;
160 		BPoint				fCombinedOrigin;
161 		float				fScale;
162 		float				fCombinedScale;
163 		BAffineTransform	fTransform;
164 		BAffineTransform	fCombinedTransform;
165 
166 		BRegion*			fClippingRegion;
167 
168 		AlphaMask*			fAlphaMask;
169 
170 		rgb_color			fHighColor;
171 		rgb_color			fLowColor;
172 		Pattern				fPattern;
173 
174 		drawing_mode		fDrawingMode;
175 		source_alpha		fAlphaSrcMode;
176 		alpha_function		fAlphaFncMode;
177 
178 		BPoint				fPenLocation;
179 		float				fPenSize;
180 
181 		ServerFont			fFont;
182 		// overrides font aliasing flag
183 		bool				fFontAliasing;
184 
185 		// This is not part of the normal state stack.
186 		// The view will update it in PushState/PopState.
187 		// A BView can have a flag "B_SUBPIXEL_PRECISE",
188 		// I never knew what it does on R5, but I can use
189 		// it in Painter to actually draw stuff with
190 		// sub-pixel coordinates. It means
191 		// StrokeLine(BPoint(10, 5), BPoint(20, 9));
192 		// will look different from
193 		// StrokeLine(BPoint(10.3, 5.8), BPoint(20.6, 9.5));
194 		bool				fSubPixelPrecise;
195 
196 		cap_mode			fLineCapMode;
197 		join_mode			fLineJoinMode;
198 		float				fMiterLimit;
199 		int32				fFillRule;
200 		// "internal", used to calculate the size
201 		// of the font (again) when the scale changes
202 		float				fUnscaledFontSize;
203 
204 		DrawState*			fPreviousState;
205 };
206 
207 #endif	// _DRAW_STATE_H_
208