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