xref: /haiku/src/servers/app/DrawState.h (revision d9cebac2b77547b7064f22497514eecd2d047160)
1 /*
2  * Copyright 2001-2005, 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 <GraphicsDefs.h>
16 #include <InterfaceDefs.h>
17 #include <Point.h>
18 #include <View.h> // for B_FONT_ALL
19 
20 #include "FontManager.h"
21 #include "ServerFont.h"
22 #include "PatternHandler.h"
23 
24 class BRegion;
25 
26 namespace BPrivate {
27 	class LinkReceiver;
28 	class LinkSender;
29 };
30 
31 
32 class DrawState {
33 	public:
34 							DrawState();
35 							DrawState(const DrawState& from);
36 		virtual				~DrawState();
37 
38 		DrawState&			operator=(const DrawState& from);
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(const BPoint& origin);
53 		void				OffsetOrigin(const BPoint& offset);
54 		const BPoint&		Origin() const
55 								{ return fOrigin; }
56 
57 		void				SetScale(float scale);
58 		float				Scale() const
59 								{ return fScale; }
60 
61 							// coordinate transformations
62 				void		Transform(float* x, float* y) const;
63 				void		InverseTransform(float* x, float* y) const;
64 
65 				void		Transform(BPoint* point) const;
66 				void		Transform(BRect* rect) const;
67 				void		Transform(BRegion* region) const;
68 
69 				void		InverseTransform(BPoint* point) const;
70 
71 							// additional clipping as requested by client
72 		void				SetClippingRegion(const BRegion* region);
73 		const BRegion*		ClippingRegion() const
74 								{ return fClippingRegion; }
75 /*	inline	int32				CountClippingRects() const
76 									{ return fClippingRegion ? fClippingRegion.CountRects() : 0; }
77 	inline	BRect				ClippingRectAt(int32 index) const;*/
78 
79 							// color
80 		void				SetHighColor(const rgb_color& color);
81 		const rgb_color&	HighColor() const
82 								{ return fHighColor; }
83 
84 		void				SetLowColor(const rgb_color& color);
85 		const rgb_color&		LowColor() const
86 								{ return fLowColor; }
87 
88 		void				SetPattern(const Pattern& pattern);
89 		const Pattern&		GetPattern() const
90 								{ return fPattern; }
91 
92 							// drawing/blending mode
93 		void				SetDrawingMode(drawing_mode mode);
94 		drawing_mode		GetDrawingMode() const
95 								{ return fDrawingMode; }
96 
97 		void				SetBlendingMode(source_alpha srcMode,
98 								alpha_function fncMode);
99 		source_alpha		AlphaSrcMode() const
100 								{ return fAlphaSrcMode; }
101 		alpha_function		AlphaFncMode() const
102 								{ return fAlphaFncMode; }
103 
104 							// pen
105 		void				SetPenLocation(const BPoint& location);
106 		const BPoint&		PenLocation() const;
107 
108 		void				SetPenSize(float size);
109 		float				PenSize() const;
110 		float				UnscaledPenSize() const;
111 
112 							// font
113 		void				SetFont(const ServerFont& font,
114 								uint32 flags = B_FONT_ALL);
115 		const ServerFont&	Font() const
116 								{ return fFont; }
117 
118 		// overrides aliasing flag contained in SeverFont::Flags())
119 		void				SetForceFontAliasing(bool aliasing);
120 		bool				ForceFontAliasing() const
121 								{ return fFontAliasing; }
122 
123 							// postscript style settings
124 		void				SetLineCapMode(cap_mode mode);
125 		cap_mode			LineCapMode() const
126 								{ return fLineCapMode; }
127 
128 		void				SetLineJoinMode(join_mode mode);
129 		join_mode			LineJoinMode() const
130 								{ return fLineJoinMode; }
131 
132 		void				SetMiterLimit(float limit);
133 		float				MiterLimit() const
134 								{ return fMiterLimit; }
135 
136 							// convenience functions
137 		void				PrintToStream() const;
138 
139 		void				SetSubPixelPrecise(bool precise);
140 		bool				SubPixelPrecise() const
141 								{ return fSubPixelPrecise; }
142 
143 	protected:
144 		BPoint				fOrigin;
145 		float				fScale;
146 
147 		BRegion*			fClippingRegion;
148 
149 		rgb_color			fHighColor;
150 		rgb_color			fLowColor;
151 		Pattern				fPattern;
152 
153 		drawing_mode		fDrawingMode;
154 		source_alpha		fAlphaSrcMode;
155 		alpha_function		fAlphaFncMode;
156 
157 		BPoint				fPenLocation;
158 		float				fPenSize;
159 
160 		ServerFont			fFont;
161 		// overrides font aliasing flag
162 		bool				fFontAliasing;
163 
164 		// This is not part of the normal state stack.
165 		// Layer will update it in PushState/PopState.
166 		// A BView can have a flag "B_SUBPIXEL_PRECISE",
167 		// I never knew what it does on R5, but I can use
168 		// it in Painter to actually draw stuff with
169 		// sub-pixel coordinates. It means
170 		// StrokeLine(BPoint(10, 5), BPoint(20, 9));
171 		// will look different from
172 		// StrokeLine(BPoint(10.3, 5.8), BPoint(20.6, 9.5));
173 		bool				fSubPixelPrecise;
174 
175 		cap_mode			fLineCapMode;
176 		join_mode			fLineJoinMode;
177 		float				fMiterLimit;
178 		// "internal", used to calculate the size
179 		// of the font (again) when the scale changes
180 		float				fUnscaledFontSize;
181 
182 		DrawState*			fPreviousState;
183 };
184 
185 
186 // inline implementations
187 
188 /*
189 // ClippingRectAt
190 BRect
191 DrawState::ClippingRectAt(int32 index) const
192 {
193 	BRect r;
194 	if (fClippingRegion) {
195 		r = fClippingRegion.RectAt(index);
196 	}
197 	return r;
198 }*/
199 
200 #endif	/* _DRAW_STATE_H_ */
201