1 | #ifndef aw_device_hxx_included |
---|
2 | #define aw_device_hxx_included |
---|
3 | |
---|
4 | #ifndef NDEBUG |
---|
5 | #define aw_assert(bed) do { if (!(bed)) *(int *)0=0; } while (0) |
---|
6 | #else |
---|
7 | #define aw_assert(bed) |
---|
8 | #endif |
---|
9 | |
---|
10 | #define _AW_DEVICE_INCLUDED |
---|
11 | |
---|
12 | #ifndef _AW_COMMON_INCLUDED |
---|
13 | class AW_common { void *dummy;}; |
---|
14 | #endif |
---|
15 | |
---|
16 | |
---|
17 | #define AW_PIXELS_PER_MM 1.0001 |
---|
18 | |
---|
19 | const AW_bitset AW_SCREEN = 1; |
---|
20 | const AW_bitset AW_CLICK = 2; |
---|
21 | const AW_bitset AW_CLICK_DRAG = 4; |
---|
22 | const AW_bitset AW_SIZE = 8; |
---|
23 | const AW_bitset AW_PRINTER = 16; |
---|
24 | const AW_bitset AW_PRINTER_EXT = 32; // Handles ... |
---|
25 | |
---|
26 | typedef enum { |
---|
27 | AW_DEVICE_SCREEN = 1, |
---|
28 | AW_DEVICE_CLICK = 2, |
---|
29 | AW_DEVICE_SIZE = 8, |
---|
30 | AW_DEVICE_PRINTER = 16 |
---|
31 | } AW_DEVICE_TYPE; |
---|
32 | |
---|
33 | typedef enum { |
---|
34 | AW_INFO_AREA, |
---|
35 | AW_MIDDLE_AREA, |
---|
36 | AW_BOTTOM_AREA, |
---|
37 | AW_MAX_AREA |
---|
38 | } AW_area; |
---|
39 | |
---|
40 | enum { |
---|
41 | AW_FIXED = -1, |
---|
42 | AW_TIMES = 0, |
---|
43 | AW_TIMES_ITALIC = 1, |
---|
44 | AW_TIMES_BOLD = 2, |
---|
45 | AW_TIMES_BOLD_ITALIC = 3, |
---|
46 | |
---|
47 | AW_COURIER = 12, |
---|
48 | AW_COURIER_OBLIQUE = 13, |
---|
49 | AW_COURIER_BOLD = 14, |
---|
50 | AW_COURIER_BOLD_OBLIQUE = 15, |
---|
51 | |
---|
52 | AW_HELVETICA =16, |
---|
53 | AW_HELVETICA_OBLIQUE =17, |
---|
54 | AW_HELVETICA_BOLD =18, |
---|
55 | AW_HELVETICA_BOLD_OBLIQUE =19, |
---|
56 | AW_HELVETICA_NARROW =20, |
---|
57 | AW_HELVETICA_NARROW_OBLIQUE =21, |
---|
58 | AW_HELVETICA_NARROW_BOLD =22, |
---|
59 | AW_HELVETICA_NARROW_BOLD_OBLIQUE =23, |
---|
60 | |
---|
61 | AW_LUCIDA_SANS =35, |
---|
62 | AW_LUCIDA_SANS_OBLIQUE =36, |
---|
63 | AW_LUCIDA_SANS_BOLD =37, |
---|
64 | AW_LUCIDA_SANS_BOLD_OBLIQUE =38, |
---|
65 | AW_LUCIDA_SANS_TYPEWRITER =39, |
---|
66 | AW_LUCIDA_SANS_TYPEWRITER_BOLD =40, |
---|
67 | AW_NUM_FONTS =41 |
---|
68 | |
---|
69 | }; // AW_font |
---|
70 | |
---|
71 | typedef enum { |
---|
72 | AW_WINDOW_BG, |
---|
73 | AW_WINDOW_FG, |
---|
74 | AW_WINDOW_C1, |
---|
75 | AW_WINDOW_C2, |
---|
76 | AW_WINDOW_C3, |
---|
77 | AW_WINDOW_DRAG, |
---|
78 | AW_DATA_BG, |
---|
79 | AW_COLOR_MAX |
---|
80 | } AW_color; |
---|
81 | |
---|
82 | typedef enum { |
---|
83 | AW_cursor_insert, |
---|
84 | AW_cursor_overwrite |
---|
85 | } AW_cursor_type; |
---|
86 | |
---|
87 | class AW_clicked_line { |
---|
88 | public: |
---|
89 | AW_pos x0,y0,x1,y1; |
---|
90 | AW_pos height; |
---|
91 | AW_pos length; |
---|
92 | AW_CL client_data1; |
---|
93 | AW_CL client_data2; |
---|
94 | AW_BOOL exists; |
---|
95 | }; |
---|
96 | |
---|
97 | class AW_clicked_text { |
---|
98 | public: |
---|
99 | AW_pos x0, y0; // start of text |
---|
100 | AW_pos alignment; |
---|
101 | AW_pos rotation; |
---|
102 | AW_pos distance; // Entfernung zum Text, <0 => oberhalb, >0 => unterhalb |
---|
103 | int cursor; // which letter was selected, from 0 to strlen-1 |
---|
104 | AW_CL client_data1; |
---|
105 | AW_CL client_data2; |
---|
106 | AW_BOOL exists; // AW_TRUE if a text was clicked, else AW_FALSE |
---|
107 | }; |
---|
108 | |
---|
109 | class AW_matrix { |
---|
110 | friend class AW_device; |
---|
111 | AW_pos xoffset,yoffset; |
---|
112 | AW_pos scale; |
---|
113 | public: |
---|
114 | AW_matrix(void) { this->reset();}; |
---|
115 | void zoom(AW_pos scale); |
---|
116 | AW_pos get_scale() { return scale; }; |
---|
117 | void rotate(AW_pos angle); |
---|
118 | void shift_x(AW_pos xoff); |
---|
119 | void shift_y(AW_pos yoff); |
---|
120 | void shift_dx(AW_pos xoff); |
---|
121 | void shift_dy(AW_pos yoff); |
---|
122 | void reset(void); |
---|
123 | |
---|
124 | void transform(int x,int y,int& xout,int& yout) {xout = int((x+ xoffset)*scale); yout = int((y + yoffset)*scale);}; |
---|
125 | void transform(AW_pos x,AW_pos y,AW_pos& xout,AW_pos& yout) {xout = (x+ xoffset)*scale; yout = (y + yoffset)*scale;}; |
---|
126 | void rtransform(int x,int y,int& xout,int& yout) {xout = int(x/scale - xoffset); yout = int(y/scale - yoffset);}; |
---|
127 | void rtransform(AW_pos x,AW_pos y,AW_pos& xout,AW_pos& yout) {xout = x/scale - xoffset; yout = y/scale - yoffset;}; |
---|
128 | }; |
---|
129 | |
---|
130 | class AW_common; |
---|
131 | |
---|
132 | class AW_clip { |
---|
133 | friend class AW_device; |
---|
134 | protected: |
---|
135 | int compoutcode(AW_pos xx, AW_pos yy) { |
---|
136 | /* calculate outcode for clipping the current line */ |
---|
137 | /* order - top,bottom,right,left */ |
---|
138 | register int code = 0; |
---|
139 | if (clip_rect.b - yy < 0) code = 4; |
---|
140 | else if (yy - clip_rect.t < 0) code = 8; |
---|
141 | if (clip_rect.r - xx < 0) code |= 2; |
---|
142 | else if (xx - clip_rect.l < 0) code |= 1; |
---|
143 | return(code); |
---|
144 | }; |
---|
145 | public: |
---|
146 | class AW_common *common; |
---|
147 | |
---|
148 | // ****** read only section |
---|
149 | AW_rectangle clip_rect; //holds the clipping rectangle coordinates |
---|
150 | int top_font_overlap; |
---|
151 | int bottom_font_overlap; |
---|
152 | int left_font_overlap; |
---|
153 | int right_font_overlap; |
---|
154 | |
---|
155 | // ****** real public |
---|
156 | int clip(AW_pos x0, AW_pos y0, AW_pos x1, AW_pos y1, AW_pos& x0out, AW_pos& y0out, AW_pos& x1out, AW_pos& y1out); |
---|
157 | int box_clip(AW_pos x0, AW_pos y0, AW_pos x1, AW_pos y1, AW_pos& x0out, AW_pos& y0out, AW_pos& x1out, AW_pos& y1out); |
---|
158 | |
---|
159 | |
---|
160 | void set_top_clip_border(int top, AW_BOOL allow_oversize = AW_FALSE); |
---|
161 | void set_bottom_clip_border(int bottom, AW_BOOL allow_oversize = AW_FALSE); // absolut |
---|
162 | void set_bottom_clip_margin(int bottom, AW_BOOL allow_oversize = AW_FALSE); // relativ |
---|
163 | void set_left_clip_border(int left, AW_BOOL allow_oversize = AW_FALSE); |
---|
164 | void set_right_clip_border(int right, AW_BOOL allow_oversize = AW_FALSE); |
---|
165 | void set_cliprect(AW_rectangle *rect, AW_BOOL allow_oversize = AW_FALSE); |
---|
166 | |
---|
167 | void set_top_font_overlap(int val=1); |
---|
168 | void set_bottom_font_overlap(int val=1); |
---|
169 | void set_left_font_overlap(int val=1); |
---|
170 | void set_right_font_overlap(int val=1); |
---|
171 | |
---|
172 | // like set_xxx_clip_border but make window only smaller: |
---|
173 | |
---|
174 | void reduce_top_clip_border(int top); |
---|
175 | void reduce_bottom_clip_border(int bottom); |
---|
176 | void reduce_left_clip_border(int left); |
---|
177 | void reduce_right_clip_border(int right); |
---|
178 | |
---|
179 | void reduceClipBorders(int top, int bottom, int left, int right); |
---|
180 | |
---|
181 | AW_clip(); |
---|
182 | }; |
---|
183 | |
---|
184 | class AW_clip_scale_stack { |
---|
185 | friend class AW_device; |
---|
186 | AW_rectangle clip_rect; |
---|
187 | int top_font_overlap; |
---|
188 | int bottom_font_overlap; |
---|
189 | int left_font_overlap; |
---|
190 | int right_font_overlap; |
---|
191 | AW_pos xoffset,yoffset; |
---|
192 | AW_pos scale; |
---|
193 | class AW_clip_scale_stack *next; |
---|
194 | }; |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | class AW_font_information { |
---|
200 | public: |
---|
201 | short max_letter_ascent; |
---|
202 | short max_letter_descent; |
---|
203 | short max_letter_height; |
---|
204 | short max_letter_width; |
---|
205 | short this_letter_ascent; |
---|
206 | short this_letter_descent; |
---|
207 | short this_letter_height; |
---|
208 | short this_letter_width; |
---|
209 | }; |
---|
210 | |
---|
211 | |
---|
212 | /*************************************************************************************************** |
---|
213 | *********** Graphic Context (Linestyle, width ... ************ |
---|
214 | ***************************************************************************************************/ |
---|
215 | typedef enum { |
---|
216 | AW_SOLID, |
---|
217 | AW_DOTTED |
---|
218 | } AW_linestyle; |
---|
219 | |
---|
220 | |
---|
221 | typedef enum { |
---|
222 | AW_COPY, |
---|
223 | AW_XOR |
---|
224 | } AW_function; |
---|
225 | |
---|
226 | class AW_gc: public AW_clip { |
---|
227 | public: |
---|
228 | void new_gc(int gc); |
---|
229 | int new_gc(void); |
---|
230 | void set_fill(int gc,AW_grey_level grey_level); // <0 dont fill 0.0 white 1.0 black |
---|
231 | void set_font(int gc,AW_font fontnr, int size); // |
---|
232 | void set_line_attributes(int gc,AW_pos width,AW_linestyle style); |
---|
233 | void set_function(int gc,AW_function function); |
---|
234 | void set_foreground_color(int gc,AW_color color); // lines .... |
---|
235 | void set_background_color(int gc,AW_color color); // for box |
---|
236 | AW_font_information *get_font_information(int gc,char c); |
---|
237 | int get_string_size(int gc,const char *string,long textlen); // get the size of the string |
---|
238 | AW_gc(); |
---|
239 | }; |
---|
240 | |
---|
241 | /*************************************************************************************************** |
---|
242 | *********** The abstract class AW_device ... ************ |
---|
243 | ***************************************************************************************************/ |
---|
244 | |
---|
245 | class AW_device: public AW_matrix, public AW_gc { |
---|
246 | friend class AW_window; |
---|
247 | protected: |
---|
248 | AW_clip_scale_stack *clip_scale_stack; |
---|
249 | virtual void _privat_reset(void); |
---|
250 | |
---|
251 | public: |
---|
252 | AW_device(class AW_common *common); // get the device from the AW_window class |
---|
253 | // by device = get_device(area); |
---|
254 | /***************** The Read Only Section ******************/ |
---|
255 | AW_bitset filter; |
---|
256 | /***************** The real Public Section ******************/ |
---|
257 | |
---|
258 | void reset(void); |
---|
259 | void get_area_size(AW_rectangle *rect); //read the frame size |
---|
260 | void get_area_size(AW_world *rect); //read the frame size |
---|
261 | void set_filter( AW_bitset filteri ); //set the main filter mask |
---|
262 | // ******all functions return 1 if any pixel is drawn |
---|
263 | // 0 else |
---|
264 | void push_clip_scale(void); // push clipping area and scale |
---|
265 | void pop_clip_scale(void); // pop them |
---|
266 | |
---|
267 | virtual AW_DEVICE_TYPE type(void) =0 ; |
---|
268 | // * primary functions (always virtual) |
---|
269 | virtual int line(int gc, AW_pos x0,AW_pos y0, AW_pos x1,AW_pos y1, |
---|
270 | AW_bitset filteri = (AW_bitset)-1, AW_CL cd1 = 0, AW_CL cd2 = 0) = 0; // used by click device |
---|
271 | virtual int text(int gc, const char *string,AW_pos x,AW_pos y, |
---|
272 | AW_pos alignment = 0.0, // 0.0 alignment left 0.5 centered 1.0 right justified |
---|
273 | AW_bitset filteri = (AW_bitset)-1, AW_CL cd1 = 0, AW_CL cd2 = 0, // used by click device |
---|
274 | long opt_strlen = 0) = 0; |
---|
275 | |
---|
276 | // * second level functions (maybe non virtual) |
---|
277 | virtual int invisible(int gc, AW_pos x, AW_pos y, AW_bitset filteri, AW_CL cd1, AW_CL cd2); |
---|
278 | // returns 1 when invisible would be on sreen |
---|
279 | virtual int cursor(int gc, AW_pos x0,AW_pos y0, AW_cursor_type type, AW_bitset filteri, AW_CL cd1, AW_CL cd2); |
---|
280 | virtual int zoomtext(int gc, const char *string, AW_pos x,AW_pos y, AW_pos height, |
---|
281 | AW_pos alignment,AW_pos rotation,AW_bitset filteri,AW_CL cd1,AW_CL cd2); |
---|
282 | virtual int zoomtext1(int gc, const char *string, AW_pos x,AW_pos y, AW_pos scale, |
---|
283 | AW_pos alignment,AW_pos rotation, AW_bitset filteri,AW_CL cd1,AW_CL cd2); |
---|
284 | virtual int zoomtext4line(int gc, const char *string, AW_pos height, AW_pos lx0, AW_pos ly0, AW_pos lx1, AW_pos ly1, |
---|
285 | AW_pos alignmentx, AW_pos alignmenty, AW_bitset filteri,AW_CL cd1,AW_CL cd2); |
---|
286 | |
---|
287 | |
---|
288 | virtual int box(int gc, AW_pos x0,AW_pos y0,AW_pos width,AW_pos heigth, AW_bitset filteri, AW_CL cd1, AW_CL cd2); |
---|
289 | virtual int circle(int gc, AW_pos x0,AW_pos y0,AW_pos width,AW_pos heigth, AW_bitset filteri, AW_CL cd1, AW_CL cd2); |
---|
290 | virtual int filled_area(int gc, int npoints, AW_pos *points, AW_bitset filteri, AW_CL cd1, AW_CL cd2); |
---|
291 | |
---|
292 | // * third level functions (never virtual) |
---|
293 | |
---|
294 | // reduces any string (or virtual string) to its actual drawn size |
---|
295 | // and calls the function f with the result |
---|
296 | int text_overlay( int gc, const char *opt_string, long opt_strlen, // either string or strlen != 0 |
---|
297 | AW_pos x,AW_pos y, AW_pos alignment, AW_bitset filteri, AW_CL cduser, AW_CL cd1, AW_CL cd2, |
---|
298 | AW_pos opt_ascent,AW_pos opt_descent, // optional height (if == 0 take font height) |
---|
299 | int (*f)(AW_device *device, int gc, const char *opt_string, size_t opt_string_len, size_t start, size_t size, |
---|
300 | AW_pos x,AW_pos y, AW_pos opt_ascent,AW_pos opt_descent, |
---|
301 | AW_CL cduser, AW_CL cd1, AW_CL cd2)); |
---|
302 | |
---|
303 | |
---|
304 | // ********* X11 Device only ******** |
---|
305 | virtual void clear(void); |
---|
306 | virtual void clear_part(AW_pos x, AW_pos y, AW_pos width, AW_pos height); |
---|
307 | virtual void clear_text(int gc, const char *string, AW_pos x, AW_pos y, AW_pos alignment, AW_bitset filteri, AW_CL cd1, AW_CL cd2); |
---|
308 | virtual void move_region( AW_pos src_x, AW_pos src_y, AW_pos width, AW_pos height, AW_pos dest_x, AW_pos dest_y ); |
---|
309 | virtual void fast(void); // e.g. zoom linewidth off |
---|
310 | virtual void slow(void); |
---|
311 | virtual void flush(void); // empty X11 buffers |
---|
312 | // ********* click device only ******** |
---|
313 | virtual void get_clicked_line(AW_clicked_line *ptr); |
---|
314 | virtual void get_clicked_text(AW_clicked_text *ptr); |
---|
315 | // ********* size device only ******** |
---|
316 | virtual void get_size_information(AW_world *ptr); |
---|
317 | // ********* print device only (xfig compatible) ******** |
---|
318 | virtual const char *open(const char *path); |
---|
319 | virtual void close(void); |
---|
320 | }; |
---|
321 | |
---|
322 | |
---|
323 | |
---|
324 | #endif |
---|