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