xref: /haiku/src/servers/app/DrawState.h (revision d2e1e872611179c9cfaa43ce11bd58b1e3554e4b)
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 <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 private:
36 							DrawState(DrawState* from);
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(const BPoint& origin);
53 		const BPoint&		Origin() const
54 								{ return fOrigin; }
55 		const 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 							// additional clipping as requested by client
65 		void				SetClippingRegion(const BRegion* region);
66 
67 		bool				HasClipping() const;
68 		bool				GetCombinedClippingRegion(BRegion* region) const;
69 
70 							// coordinate transformations
71 				void		Transform(float* x, float* y) const;
72 				void		InverseTransform(float* x, float* y) const;
73 
74 				void		Transform(BPoint* point) const;
75 				void		Transform(BRect* rect) const;
76 				void		Transform(BRegion* region) const;
77 
78 				void		InverseTransform(BPoint* point) const;
79 
80 							// color
81 		void				SetHighColor(const rgb_color& color);
82 		const rgb_color&	HighColor() const
83 								{ return fHighColor; }
84 
85 		void				SetLowColor(const rgb_color& color);
86 		const rgb_color&		LowColor() const
87 								{ return fLowColor; }
88 
89 		void				SetPattern(const Pattern& pattern);
90 		const Pattern&		GetPattern() const
91 								{ return fPattern; }
92 
93 							// drawing/blending mode
94 		void				SetDrawingMode(drawing_mode mode);
95 		drawing_mode		GetDrawingMode() const
96 								{ return fDrawingMode; }
97 
98 		void				SetBlendingMode(source_alpha srcMode,
99 								alpha_function fncMode);
100 		source_alpha		AlphaSrcMode() const
101 								{ return fAlphaSrcMode; }
102 		alpha_function		AlphaFncMode() const
103 								{ return fAlphaFncMode; }
104 
105 							// pen
106 		void				SetPenLocation(const BPoint& location);
107 		const BPoint&		PenLocation() const;
108 
109 		void				SetPenSize(float size);
110 		float				PenSize() const;
111 		float				UnscaledPenSize() const;
112 
113 							// font
114 		void				SetFont(const ServerFont& font,
115 								uint32 flags = B_FONT_ALL);
116 		const ServerFont&	Font() const
117 								{ return fFont; }
118 
119 		// overrides aliasing flag contained in SeverFont::Flags())
120 		void				SetForceFontAliasing(bool aliasing);
121 		bool				ForceFontAliasing() const
122 								{ return fFontAliasing; }
123 
124 							// postscript style settings
125 		void				SetLineCapMode(cap_mode mode);
126 		cap_mode			LineCapMode() const
127 								{ return fLineCapMode; }
128 
129 		void				SetLineJoinMode(join_mode mode);
130 		join_mode			LineJoinMode() const
131 								{ return fLineJoinMode; }
132 
133 		void				SetMiterLimit(float limit);
134 		float				MiterLimit() const
135 								{ return fMiterLimit; }
136 
137 							// convenience functions
138 		void				PrintToStream() const;
139 
140 		void				SetSubPixelPrecise(bool precise);
141 		bool				SubPixelPrecise() const
142 								{ return fSubPixelPrecise; }
143 
144 protected:
145 		BPoint				fOrigin;
146 		BPoint				fCombinedOrigin;
147 		float				fScale;
148 		float				fCombinedScale;
149 
150 		BRegion*			fClippingRegion;
151 
152 		rgb_color			fHighColor;
153 		rgb_color			fLowColor;
154 		Pattern				fPattern;
155 
156 		drawing_mode		fDrawingMode;
157 		source_alpha		fAlphaSrcMode;
158 		alpha_function		fAlphaFncMode;
159 
160 		BPoint				fPenLocation;
161 		float				fPenSize;
162 
163 		ServerFont			fFont;
164 		// overrides font aliasing flag
165 		bool				fFontAliasing;
166 
167 		// This is not part of the normal state stack.
168 		// The view will update it in PushState/PopState.
169 		// A BView can have a flag "B_SUBPIXEL_PRECISE",
170 		// I never knew what it does on R5, but I can use
171 		// it in Painter to actually draw stuff with
172 		// sub-pixel coordinates. It means
173 		// StrokeLine(BPoint(10, 5), BPoint(20, 9));
174 		// will look different from
175 		// StrokeLine(BPoint(10.3, 5.8), BPoint(20.6, 9.5));
176 		bool				fSubPixelPrecise;
177 
178 		cap_mode			fLineCapMode;
179 		join_mode			fLineJoinMode;
180 		float				fMiterLimit;
181 		// "internal", used to calculate the size
182 		// of the font (again) when the scale changes
183 		float				fUnscaledFontSize;
184 
185 		DrawState*			fPreviousState;
186 };
187 
188 #endif	// _DRAW_STATE_H_
189