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