xref: /haiku/headers/private/interface/PictureDataWriter.h (revision 2cad94c1c30b6223ad8c08710b26e071d32e9979)
1 /*
2  * Copyright 2006-2015 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stefano Ceccherini, burton666@libero.it
7  *		Julian Harnath, <julian.harnath@rwth-achen.de>
8  */
9 #ifndef _PICTURE_DATA_WRITER_H
10 #define _PICTURE_DATA_WRITER_H
11 
12 
13 #include <AffineTransform.h>
14 #include <InterfaceDefs.h>
15 #include <Font.h>
16 #include <OS.h>
17 
18 #include <stack>
19 
20 
21 class Layer;
22 class BPositionIO;
23 class BRegion;
24 
25 class PictureDataWriter {
26 public:
27 								PictureDataWriter();
28 								PictureDataWriter(BPositionIO* data);
29 	virtual						~PictureDataWriter();
30 
31 			status_t			SetTo(BPositionIO* data);
32 
33 			status_t			WriteSetHighColor(const rgb_color& color);
34 			status_t			WriteSetLowColor(const rgb_color& color);
35 			status_t			WriteSetOrigin(const BPoint& point);
36 			status_t			WriteSetDrawingMode(const drawing_mode& mode);
37 			status_t			WriteSetPenLocation(const BPoint& point);
38 			status_t			WriteSetPenSize(const float& penSize);
39 			status_t			WriteSetLineMode(const cap_mode& cap,
40 									const join_mode& join,
41 									const float& miterLimit);
42 			status_t			WriteSetScale(const float& scale);
43 			status_t			WriteSetTransform(BAffineTransform transform);
44 			status_t			WriteTranslateBy(double x, double y);
45 			status_t			WriteScaleBy(double x, double y);
46 			status_t			WriteRotateBy(double angleRadians);
47 			status_t			WriteSetPattern(const ::pattern& pattern);
48 			status_t			WriteClipToPicture(int32 pictureToken,
49 									const BPoint& origin, bool inverse);
50 			status_t			WriteSetClipping(const BRegion& region);
51 			status_t			WriteClearClipping();
52 
53 			status_t			WritePushState();
54 			status_t			WritePopState();
55 
56 			status_t			WriteSetFontFamily(const font_family family);
57 			status_t			WriteSetFontStyle(const font_style style);
58 			status_t			WriteSetFontSpacing(const int32& spacing);
59 			status_t			WriteSetFontSize(const float& size);
60 			status_t			WriteSetFontRotation(const float& rotation);
61 			status_t			WriteSetFontEncoding(const int32& encoding);
62 			status_t			WriteSetFontFlags(const int32& flags);
63 			status_t			WriteSetFontShear(const float& shear);
64 			status_t			WriteSetFontFace(const int32& face);
65 
66 			status_t			WriteStrokeLine(const BPoint& start,
67 									const BPoint& end);
68 			status_t			WriteInvertRect(const BRect& rect);
69 			status_t			WriteDrawRect(const BRect& rect,
70 									const bool& fill);
71 			status_t			WriteDrawRoundRect(const BRect& rect,
72 									const BPoint& radius, const bool& fill);
73 			status_t			WriteDrawEllipse(const BRect& rect,
74 									const bool& fill);
75 			status_t			WriteDrawArc(const BPoint& center,
76 									const BPoint& radius,
77 									const float& startTheta,
78 									const float& arcTheta, const bool& fill);
79 			status_t			WriteDrawPolygon(const int32& numPoints,
80 									BPoint* points, const bool& isClosed,
81 									const bool& fill);
82 			status_t			WriteDrawBezier(const BPoint points[4],
83 									const bool& fill);
84 			status_t			WriteDrawString(const BPoint& where,
85 									const char* string, const int32& length,
86 									const escapement_delta& delta);
87 			status_t			WriteDrawShape(const int32& opCount,
88 									const void* opList, const int32& ptCount,
89 									const void* ptList, const bool& fill);
90 			status_t			WriteDrawBitmap(const BRect& srcRect,
91 									const BRect& dstRect, const int32& width,
92 									const int32& height,
93 									const int32& bytesPerRow,
94 									const int32& colorSpace,
95 									const int32& flags,
96 									const void* data, const int32& length);
97 
98 			status_t			WriteDrawPicture(const BPoint& where,
99 									const int32& token);
100 
101 			status_t			WriteBlendLayer(Layer* layer);
102 			status_t			WriteClipToRect(const BRect& rect,
103 									bool inverse);
104 			status_t			WriteClipToShape(int32 opCount,
105 									const void* opList, int32 ptCount,
106 									const void* ptList, bool inverse);
107 
108 protected:
109 	// throw a status_t on error
110 			void				BeginOp(const int16& op);
111 			void				EndOp();
112 			void				WriteData(const void* data, size_t size);
113 	template <typename T> void	Write(const T& data)
114 									{ WriteData(&data, sizeof(data)); }
115 
116 private:
117 			BPositionIO*		fData;
118 			std::stack<off_t>	fStack;
119 };
120 
121 
122 #endif // _PICTURE_DATA_WRITER_H
123