headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / servers / app / painter / Painter.h
blobb8435b609f2f1f04794f66eaeb77ce524926165f
1 // Painter.h
3 #ifndef PAINTER_H
4 #define PAINTER_H
6 #include <Font.h>
7 #include <Rect.h>
8 #include <FontServer.h>
9 #include <ServerFont.h>
11 #include "defines.h"
12 #include "forwarding_pixfmt.h"
14 #include "RGBColor.h"
16 class AGGTextRenderer;
17 class BBitmap;
18 class BRegion;
19 class DrawData;
20 class PatternHandler;
21 class RenderingBuffer;
22 class ServerBitmap;
23 class ServerFont;
25 class Painter {
26 public:
27 Painter();
28 virtual ~Painter();
30 // frame buffer stuff
31 void AttachToBuffer(RenderingBuffer* buffer);
32 void DetachFromBuffer();
34 void ConstrainClipping(const BRegion& region);
35 void SetDrawData(const DrawData* data);
37 // object settings
38 void SetHighColor(const rgb_color& color);
39 inline void SetHighColor(uint8 r, uint8 g, uint8 b, uint8 a = 255);
40 inline void SetHighColor(const RGBColor& color)
41 { SetHighColor(color.GetColor32()); }
42 void SetLowColor(const rgb_color& color);
43 inline void SetLowColor(uint8 r, uint8 g, uint8 b, uint8 a = 255);
44 inline void SetLowColor(const RGBColor& color)
45 { SetLowColor(color.GetColor32()); }
47 void SetScale(float scale);
48 void SetPenSize(float size);
49 void SetOrigin(const BPoint& origin);
50 void SetDrawingMode(drawing_mode mode);
51 void SetBlendingMode(source_alpha alphaSrcMode,
52 alpha_function alphaFncMode);
53 void SetPenLocation(const BPoint& location);
54 void SetFont(const BFont& font);
55 void SetFont(const ServerFont& font);
57 // BView API compatibility (for easier testing)
58 void Sync() {}
59 inline void MovePenTo(const BPoint& location)
60 { SetPenLocation(location); }
61 inline void SetFont(const BFont* font)
62 { if (font) SetFont(*font); }
64 // painting functions
66 // lines
67 BRect StrokeLine( BPoint a,
68 BPoint b,
69 const pattern& p = B_SOLID_HIGH);
71 BRect StrokeLine( BPoint b,
72 const pattern& p = B_SOLID_HIGH);
74 // return true if the line was either vertical or horizontal
75 // draws a solid one pixel wide line of color c, no blending
76 bool StraightLine( BPoint a,
77 BPoint b,
78 const rgb_color& c) const;
80 // triangles
81 void StrokeTriangle( BPoint pt1,
82 BPoint pt2,
83 BPoint pt3,
84 const pattern& p = B_SOLID_HIGH) const;
86 void FillTriangle( BPoint pt1,
87 BPoint pt2,
88 BPoint pt3,
89 const pattern& p = B_SOLID_HIGH) const;
91 // polygons
92 void StrokePolygon( const BPoint* ptArray,
93 int32 numPts,
94 bool closed = true,
95 const pattern& p = B_SOLID_HIGH) const;
97 void FillPolygon( const BPoint* ptArray,
98 int32 numPts,
99 bool closed = true,
100 const pattern& p = B_SOLID_HIGH) const;
102 // bezier curves
103 void StrokeBezier( const BPoint* controlPoints,
104 const pattern& p = B_SOLID_HIGH) const;
106 void FillBezier( const BPoint* controlPoints,
107 const pattern& p = B_SOLID_HIGH) const;
109 // shapes
110 void StrokeShape( /*const */BShape* shape,
111 const pattern& p = B_SOLID_HIGH) const;
113 void FillShape( /*const */BShape* shape,
114 const pattern& p = B_SOLID_HIGH) const;
117 // rects
118 BRect StrokeRect( const BRect& r,
119 const pattern& p = B_SOLID_HIGH) const;
121 // strokes a one pixel wide solid rect, no blending
122 void StrokeRect( const BRect& r,
123 const rgb_color& c) const;
125 BRect FillRect( const BRect& r,
126 const pattern& p = B_SOLID_HIGH) const;
128 // fills a solid rect with color c, no blending
129 void FillRect( const BRect& r,
130 const rgb_color& c) const;
132 // round rects
133 void StrokeRoundRect(const BRect& r,
134 float xRadius,
135 float yRadius,
136 const pattern& p = B_SOLID_HIGH) const;
138 void FillRoundRect( const BRect& r,
139 float xRadius,
140 float yRadius,
141 const pattern& p = B_SOLID_HIGH) const;
143 // ellipses
144 void StrokeEllipse( BPoint center,
145 float xRadius,
146 float yRadius,
147 const pattern& p = B_SOLID_HIGH) const;
149 void FillEllipse( BPoint center,
150 float xRadius,
151 float yRadius,
152 const pattern& p = B_SOLID_HIGH) const;
154 // arcs
155 void StrokeArc( BPoint center,
156 float xRadius,
157 float yRadius,
158 float angle,
159 float span,
160 const pattern& p = B_SOLID_HIGH) const;
162 void FillArc( BPoint center,
163 float xRadius,
164 float yRadius,
165 float angle,
166 float span,
167 const pattern& p = B_SOLID_HIGH) const;
169 // strings
170 BRect DrawChar( char aChar);
172 BRect DrawChar( char aChar,
173 BPoint baseLine);
175 BRect DrawString( const char* utf8String,
176 uint32 length,
177 const escapement_delta* delta = NULL);
179 BRect DrawString( const char* utf8String,
180 uint32 length,
181 BPoint baseLine,
182 const escapement_delta* delta = NULL);
184 BRect DrawString( const char* utf8String,
185 const escapement_delta* delta = NULL);
187 BRect DrawString( const char* utf8String,
188 BPoint baseLine,
189 const escapement_delta* delta = NULL);
191 // bitmaps
192 void DrawBitmap( const BBitmap* bitmap,
193 BRect bitmapRect,
194 BRect viewRect) const;
196 void DrawBitmap( const ServerBitmap* bitmap,
197 BRect bitmapRect,
198 BRect viewRect) const;
200 // some convenience stuff
201 void FillRegion( const BRegion* region,
202 const pattern& p = B_SOLID_HIGH) const;
204 void InvertRect( const BRect& r) const;
206 BRect BoundingBox( const char* utf8String,
207 uint32 length,
208 const BPoint& baseLine) const;
210 inline BRect ClipRect(const BRect& rect) const
211 { return _Clipped(rect); }
213 private:
214 void _MakeEmpty();
216 void _Transform(BPoint* point,
217 bool centerOffset = true) const;
218 BPoint _Transform(const BPoint& point,
219 bool centerOffset = true) const;
220 void _Transform(float* width) const;
221 float _Transform(const float& width) const;
222 void _Transform(BRect* rect) const;
223 BRect _Transform(const BRect& rect) const;
224 BRect _Clipped(const BRect& rect) const;
226 void _RebuildClipping();
228 void _UpdateFont();
229 void _UpdateLineWidth();
231 // drawing functions stroke/fill
232 void _DrawTriangle( BPoint pt1,
233 BPoint pt2,
234 BPoint pt3,
235 const pattern& p,
236 bool fill) const;
237 void _DrawEllipse( BPoint center,
238 float xRadius,
239 float yRadius,
240 const pattern& p,
241 bool fill) const;
242 void _DrawShape( /*const */BShape* shape,
243 const pattern& p,
244 bool fill) const;
245 void _DrawPolygon( const BPoint* ptArray,
246 int32 numPts,
247 bool closed,
248 const pattern& p,
249 bool fill) const;
251 void _DrawBitmap( const agg::rendering_buffer& srcBuffer,
252 color_space format,
253 BRect actualBitmapRect,
254 BRect bitmapRect,
255 BRect viewRect) const;
256 void _DrawBitmap32( const agg::rendering_buffer& srcBuffer,
257 BRect actualBitmapRect,
258 BRect bitmapRect,
259 BRect viewRect) const;
261 void _InvertRect32(BRect r) const;
264 template<class VertexSource>
265 BRect _BoundingBox(VertexSource& path) const;
267 template<class VertexSource>
268 BRect _StrokePath(VertexSource& path,
269 const pattern& p) const;
270 template<class VertexSource>
271 BRect _FillPath(VertexSource& path,
273 const pattern& p) const;
275 void _SetPattern(const pattern& p) const;
276 void _SetRendererColor(const rgb_color& color) const;
278 agg::rendering_buffer* fBuffer;
280 // AGG rendering and rasterization classes
281 pixfmt* fPixelFormat;
282 renderer_base* fBaseRenderer;
284 outline_renderer_type* fOutlineRenderer;
285 outline_rasterizer_type* fOutlineRasterizer;
287 scanline_type* fScanline;
288 rasterizer_type* fRasterizer;
289 renderer_type* fRenderer;
291 font_renderer_solid_type* fFontRendererSolid;
292 font_renderer_bin_type* fFontRendererBin;
294 agg::line_profile_aa fLineProfile;
296 // for internal coordinate rounding/transformation,
297 // does not concern rendering
298 bool fSubpixelPrecise;
300 float fScale;
301 float fPenSize;
302 BPoint fOrigin;
303 BRegion* fClippingRegion; // NULL indicates no clipping at all
304 drawing_mode fDrawingMode;
305 source_alpha fAlphaSrcMode;
306 alpha_function fAlphaFncMode;
307 BPoint fPenLocation;
308 PatternHandler* fPatternHandler;
310 ServerFont fFont;
311 // a class handling rendering and caching of glyphs
312 // it is setup to load from a specific Freetype supported
313 // font file, it uses the FontManager to locate a file
314 // by Family and Style
315 AGGTextRenderer* fTextRenderer;
316 uint32 fLastFamilyAndStyle;
319 // SetHighColor
320 inline void
321 Painter::SetHighColor(uint8 r, uint8 g, uint8 b, uint8 a)
323 rgb_color color;
324 color.red = r;
325 color.green = g;
326 color.blue = b;
327 color.alpha = a;
328 SetHighColor(color);
331 // SetLowColor
332 inline void
333 Painter::SetLowColor(uint8 r, uint8 g, uint8 b, uint8 a)
335 rgb_color color;
336 color.red = r;
337 color.green = g;
338 color.blue = b;
339 color.alpha = a;
340 SetLowColor(color);
344 #endif // PAINTER_H