source: tags/ms_r16q3/WINDOW/aw_device.hxx

Last change on this file was 15340, checked in by westram, 8 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.9 KB
Line 
1#ifndef AW_DEVICE_HXX
2#define AW_DEVICE_HXX
3
4#ifndef AW_POSITION_HXX
5#include <aw_position.hxx>
6#endif
7#ifndef AW_FONT_LIMITS_HXX
8#include <aw_font_limits.hxx>
9#endif
10#ifndef ATTRIBUTES_H
11#include <attributes.h>
12#endif
13#ifndef ARBTOOLS_H
14#include <arbtools.h>
15#endif
16
17#if defined(DEBUG) && defined(DEBUG_GRAPHICS)
18// if you want flush() to be called after every motif command :
19#define AUTO_FLUSH(device) (device)->flush()
20#else
21#define AUTO_FLUSH(device)
22#endif
23
24#define AW_INT(x) ((int)(((x)>=0.0) ? ((float)(x)+.5) : ((float)(x)-.5)))
25
26// #define AW_PIXELS_PER_MM 1.0001 // stupid and wrong
27
28#define DPI_SCREEN  80   // fixed
29#define DPI_PRINTER 1200 // default resolution of xfig 3.2
30
31const AW_bitset AW_SCREEN        = 1;
32const AW_bitset AW_CLICK         = 2;
33const AW_bitset AW_CLICK_DROP    = 4;
34const AW_bitset AW_SIZE          = 8;
35const AW_bitset AW_SIZE_UNSCALED = 16;  // for text and text-size dependant parts
36const AW_bitset AW_PRINTER       = 32;  // print/xfig-export
37const AW_bitset AW_PRINTER_EXT   = 64;  // (+Handles) use combined with AW_PRINTER only
38const AW_bitset AW_PRINTER_CLIP  = 128; // print screen only
39const AW_bitset AW_TRACK         = 256; // species tracking
40
41const AW_bitset AW_ALL_DEVICES          = (AW_bitset)-1; // @@@ allowed to used this ?
42const AW_bitset AW_ALL_DEVICES_SCALED   = (AW_ALL_DEVICES & ~AW_SIZE_UNSCALED);
43const AW_bitset AW_ALL_DEVICES_UNSCALED = (AW_ALL_DEVICES & ~AW_SIZE);
44
45enum AW_DEVICE_TYPE {
46    AW_DEVICE_SCREEN  = AW_SCREEN,
47    AW_DEVICE_CLICK   = AW_CLICK,
48    AW_DEVICE_SIZE    = AW_SIZE,
49    AW_DEVICE_PRINTER = AW_PRINTER,
50};
51
52enum {
53    AW_FIXED             = -1,
54    AW_TIMES             = 0,
55    AW_TIMES_ITALIC      = 1,
56    AW_TIMES_BOLD        = 2,
57    AW_TIMES_BOLD_ITALIC = 3,
58
59    AW_COURIER              = 12,
60    AW_COURIER_OBLIQUE      = 13,
61    AW_COURIER_BOLD         = 14,
62    AW_COURIER_BOLD_OBLIQUE = 15,
63
64    AW_HELVETICA                     = 16,
65    AW_HELVETICA_OBLIQUE             = 17,
66    AW_HELVETICA_BOLD                = 18,
67    AW_HELVETICA_BOLD_OBLIQUE        = 19,
68    AW_HELVETICA_NARROW              = 20,
69    AW_HELVETICA_NARROW_OBLIQUE      = 21,
70    AW_HELVETICA_NARROW_BOLD         = 22,
71    AW_HELVETICA_NARROW_BOLD_OBLIQUE = 23,
72
73    AW_LUCIDA_SANS                 = 35,
74    AW_LUCIDA_SANS_OBLIQUE         = 36,
75    AW_LUCIDA_SANS_BOLD            = 37,
76    AW_LUCIDA_SANS_BOLD_OBLIQUE    = 38,
77    AW_LUCIDA_SANS_TYPEWRITER      = 39,
78    AW_LUCIDA_SANS_TYPEWRITER_BOLD = 40,
79    AW_SCREEN_MEDIUM               = 41,
80    AW_SCREEN_BOLD                 = 42,
81    AW_CLEAN_MEDIUM                = 43,
82    AW_CLEAN_BOLD                  = 44,
83    AW_TERMINAL_MEDIUM             = 45,
84    AW_TERMINAL_BOLD               = 46,
85
86    AW_NUM_FONTS      = 68,
87    AW_NUM_FONTS_XFIG = 35, // immutable
88
89    AW_DEFAULT_NORMAL_FONT = AW_LUCIDA_SANS,
90    AW_DEFAULT_BOLD_FONT   = AW_LUCIDA_SANS_BOLD,
91    AW_DEFAULT_FIXED_FONT  = AW_LUCIDA_SANS_TYPEWRITER,
92};
93
94enum AW_cursor_type {
95    AW_cursor_insert,
96    AW_cursor_overwrite
97};
98
99// --------------------------------------------------
100// general note on world- vs. pixel-positions:(WORLD_vs_PIXEL)
101//
102// A position is interpreted as the center of the corresponding pixel
103// (pixel refers to screen; printer pixel are 15 times smaller!)
104//
105// Hence, when scaling factor is 1.0, then
106// - any position inside [-0.5, 0.5[ will fall into the pixel 0, any inside [0.5, 1.5[ into pixel 1.
107// - a line from 0.0 to 2.0 will paint THREE pixels (0, 1 and 2). A line from -0.5 to 2.499 will to the same
108// - clipping to area [0, 100] should in fact clip to [-0.5, 100.5[ (@@@ check this)
109
110class AW_zoomable {
111    AW::Vector offset;
112    AW_pos     scale;
113    AW_pos     unscale;         // = 1.0/scale
114
115public:
116    AW_zoomable() { this->reset(); };
117    virtual ~AW_zoomable() {}
118
119    void zoom(AW_pos scale);
120
121    AW_pos get_scale() const { return scale; };
122    AW_pos get_unscale() const { return unscale; };
123    AW::Vector get_offset() const { return offset; }
124
125    void rotate(AW_pos angle);
126
127    void set_offset(const AW::Vector& off) { offset = off*scale; }
128    void shift(const AW::Vector& doff) { offset += doff*scale; }
129
130    void reset();
131
132    double transform_size(const double& size) const { return size*scale; }
133    double rtransform_size(const double& size) const { return size*unscale; }
134
135    double rtransform_pixelsize(int pixelsize) const {
136        // return world-size needed to draw line/box with length/size == 'pixelsize'
137        return (pixelsize-1)*unscale;
138    }
139
140    // transforming a Vector only scales the vector (a Vector has no position!)
141    AW::Vector transform (const AW::Vector& vec) const { return vec*scale; }
142    AW::Vector rtransform(const AW::Vector& vec) const { return vec*unscale; }
143
144    // transform a Position
145    AW::Position transform (const AW::Position& pos) const { return transform(AW::Vector(pos+offset)).endpoint(); }
146    AW::Position rtransform(const AW::Position& pos) const { return rtransform(AW::Vector(pos)).endpoint()-offset; }
147#if defined(WARN_TODO) && 0
148#warning fix transformations
149    // @@@ I think this calculation is wrong, cause offset is already scaled
150    //     (same applies to old-style transform/rtransform below)
151#endif
152
153    AW::LineVector transform (const AW::LineVector& lvec) const { return AW::LineVector(transform(lvec.start()), transform(lvec.line_vector())); }
154    AW::LineVector rtransform(const AW::LineVector& lvec) const { return AW::LineVector(rtransform(lvec.start()), rtransform(lvec.line_vector())); }
155
156    AW::Rectangle transform (const AW::Rectangle& rect) const { return AW::Rectangle(transform(static_cast<const AW::LineVector&>(rect))); }
157    AW::Rectangle rtransform(const AW::Rectangle& rect) const { return AW::Rectangle(rtransform(static_cast<const AW::LineVector&>(rect))); }
158
159    // old style functions, not preferred:
160    void transform(AW_pos x, AW_pos y, AW_pos& xout, AW_pos& yout) const {
161        xout = (x+offset.x())*scale;
162        yout = (y+offset.y())*scale;
163    }
164    void rtransform(AW_pos x, AW_pos y, AW_pos& xout, AW_pos& yout) const {
165        xout = x*unscale - offset.x();
166        yout = y*unscale - offset.y();
167    }
168};
169
170struct AW_font_overlap { bool top, bottom, left, right; };
171
172class AW_clipable {
173    const AW_screen_area& common_screen;
174    const AW_screen_area& get_screen() const { return common_screen; }
175
176    AW_screen_area  clip_rect;    // holds the clipping rectangle coordinates
177    AW_font_overlap font_overlap;
178
179    void set_cliprect_oversize(const AW_screen_area& rect, bool allow_oversize);
180
181    bool need_extra_clip_position(const AW::Position& p1, const AW::Position& p2, AW::Position& extra);
182
183protected:
184    int compoutcode(AW_pos xx, AW_pos yy) const {
185        // calculate outcode for clipping the current line
186        // order - top,bottom,right,left
187        int code = 0;
188        if (clip_rect.b - yy < 0)       code = 4;
189        else if (yy - clip_rect.t < 0)  code = 8;
190        if (clip_rect.r - xx < 0)       code |= 2;
191        else if (xx - clip_rect.l < 0)  code |= 1;
192        return (code);
193    };
194
195    void set_cliprect(const AW_screen_area& rect) { clip_rect = rect; }
196
197public:
198
199    AW_clipable(const AW_screen_area& screen)
200        : common_screen(screen)
201    {
202        clip_rect.clear();
203        set_font_overlap(false);
204    }
205    virtual ~AW_clipable() {}
206
207    bool is_below_clip(double ypos) const { return ypos > clip_rect.b; }
208    bool is_above_clip(double ypos) const { return ypos < clip_rect.t; }
209    bool is_leftof_clip(double xpos) const { return xpos < clip_rect.l; }
210    bool is_rightof_clip(double xpos) const { return xpos > clip_rect.r; }
211
212    bool is_outside_clip(AW::Position pos) const {
213        return
214            is_below_clip(pos.ypos()) || is_above_clip(pos.ypos()) ||
215            is_leftof_clip(pos.xpos()) || is_rightof_clip(pos.xpos());
216    }
217    bool is_outside_clip(AW::Rectangle rect) const {
218        return !rect.overlaps_with(AW::Rectangle(get_cliprect(), AW::INCLUSIVE_OUTLINE));
219    }
220
221    bool 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);
222    bool clip(const AW::LineVector& line, AW::LineVector& clippedLine);
223
224    bool 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);
225    bool box_clip(const AW::Rectangle& rect, AW::Rectangle& clippedRect);
226    bool box_clip(int npos, const AW::Position *pos, int& nclippedPos, AW::Position*& clippedPos);
227    bool force_into_clipbox(const AW::Position& pos, AW::Position& forcedPos);
228
229    void set_top_clip_border(int top, bool allow_oversize = false);
230    void set_bottom_clip_border(int bottom, bool allow_oversize = false); // absolute
231    void set_bottom_clip_margin(int bottom, bool allow_oversize = false); // relative
232    void set_left_clip_border(int left, bool allow_oversize = false);
233    void set_right_clip_border(int right, bool allow_oversize = false);
234    const AW_screen_area& get_cliprect() const { return clip_rect; }
235
236    void set_clipall() {
237        // clip all -> nothing drawn afterwards
238        AW_screen_area rect = { 0, -1, 0, -1};
239        set_cliprect_oversize(rect, false);
240    }
241
242    bool completely_clipped() const { return clip_rect.l>clip_rect.r || clip_rect.t>clip_rect.b; }
243
244    bool allow_top_font_overlap() const { return font_overlap.top; }
245    bool allow_bottom_font_overlap() const { return font_overlap.bottom; }
246    bool allow_left_font_overlap() const { return font_overlap.left; }
247    bool allow_right_font_overlap() const { return font_overlap.right; }
248    const AW_font_overlap& get_font_overlap() const { return font_overlap; }
249
250    void set_top_font_overlap(bool allow) { font_overlap.top = allow; }
251    void set_bottom_font_overlap(bool allow) { font_overlap.bottom = allow; }
252    void set_left_font_overlap(bool allow) { font_overlap.left = allow; }
253    void set_right_font_overlap(bool allow) { font_overlap.right = allow; }
254
255    void set_vertical_font_overlap(bool allow) { font_overlap.top = font_overlap.bottom = allow; }
256    void set_horizontal_font_overlap(bool allow) { font_overlap.left = font_overlap.right = allow; }
257    void set_font_overlap(bool allow) { set_vertical_font_overlap(allow); set_horizontal_font_overlap(allow); }
258    void set_font_overlap(const AW_font_overlap& fo) { font_overlap = fo; }
259
260    // like set_xxx_clip_border but make window only smaller:
261
262    void reduce_top_clip_border(int top);
263    void reduce_bottom_clip_border(int bottom);
264    void reduce_left_clip_border(int left);
265    void reduce_right_clip_border(int right);
266
267    int reduceClipBorders(int top, int bottom, int left, int right);
268};
269
270// -----------------------------------------------
271//      Graphic context (linestyle, width ...)
272
273enum AW_linestyle {
274    AW_SOLID,
275    AW_DASHED,
276    AW_DOTTED,
277};
278
279
280enum AW_function {
281    AW_COPY,
282    AW_XOR
283};
284
285class AW_common;
286
287class AW_stylable : virtual Noncopyable {
288    AW_common *common;
289public:
290    AW_stylable(AW_common *common_) : common(common_) {}
291    virtual ~AW_stylable() {};
292
293    AW_common *get_common() const { return common; }
294
295    void new_gc(int gc);
296
297    void          set_grey_level(int gc, AW_grey_level grey_level);
298    AW_grey_level get_grey_level(int gc);
299
300    void set_font(int gc, AW_font fontnr, int size, int *found_size);
301    void set_line_attributes(int gc, short width, AW_linestyle style);
302    void set_function(int gc, AW_function function);
303    void establish_default(int gc);
304    void set_foreground_color(int gc, AW_color_idx color);                 // lines ....
305    int  get_string_size(int gc, const  char *string, long textlen) const; // get the size of the string
306
307    const AW_font_limits& get_font_limits(int gc, char c) const; // for one characters (c == 0 -> for all characters)
308
309    int get_available_fontsizes(int gc, AW_font font_nr, int *available_sizes);
310
311    void reset_style();
312};
313
314class  AW_clip_scale_stack;
315struct AW_world;
316class  AW_device;
317
318class AW_click_cd : virtual Noncopyable {
319    AW_CL              cd1;
320    AW_CL              cd2;
321    AW_device         *my_device;
322    const AW_click_cd *previous;
323
324    void link();
325
326public:
327    AW_click_cd(AW_device *device, AW_CL CD1, AW_CL CD2)
328        : cd1(CD1),
329          cd2(CD2),
330          my_device(device)
331    { link(); }
332    AW_click_cd(AW_device *device, AW_CL CD1)
333        : cd1(CD1),
334          cd2(0),
335          my_device(device)
336    { link(); }
337    ~AW_click_cd();
338
339    void disable();
340    void enable();
341
342    AW_CL get_cd1() const { return cd1; }
343    AW_CL get_cd2() const { return cd2; }
344
345    void set_cd1(AW_CL cd) { cd1 = cd; }
346    void set_cd2(AW_CL cd) { cd2 = cd; }
347};
348
349typedef bool (*TextOverlayCallback)(AW_device *device, int gc, const char *opt_string, size_t opt_string_len, size_t start, size_t size, AW_pos x, AW_pos y, AW_pos opt_ascent, AW_pos opt_descent, AW_CL cduser);
350
351class AW_device : public AW_zoomable, public AW_stylable, public AW_clipable {
352    AW_device(const AW_device& other);
353    AW_device& operator=(const AW_device& other);
354
355protected:
356    AW_clip_scale_stack *clip_scale_stack;
357
358    const AW_click_cd *click_cd;
359    friend class       AW_click_cd;
360
361    AW_bitset filter;
362
363    static const AW_screen_area& get_common_screen(const AW_common *common_);
364
365public:
366    AW_device(class AW_common *common_)
367        : AW_stylable(common_),
368          AW_clipable(get_common_screen(common_)),
369          clip_scale_stack(NULL),
370          click_cd(NULL),
371          filter(AW_ALL_DEVICES)
372    {}
373    virtual ~AW_device() {}
374
375    const AW_click_cd *get_click_cd() const { return click_cd; }
376    AW_bitset get_filter() const { return filter; }
377
378    void reset(); // pops all clip_scales
379
380    const AW_screen_area& get_area_size() const;
381    AW::Rectangle get_rtransformed_cliprect() const { return rtransform(AW::Rectangle(get_cliprect(), AW::INCLUSIVE_OUTLINE)); }
382
383    void set_filter(AW_bitset filteri);   // set the main filter mask
384
385    void push_clip_scale();     // push clipping area and scale
386    void pop_clip_scale();     // pop them
387
388    virtual AW_DEVICE_TYPE type() = 0;
389
390    bool ready_to_draw(int gc); // unused atm
391
392private:
393    // * functions below return 1 if any pixel is drawn, 0 otherwise
394    // * primary functions (always virtual; pure virtual in all devices used as baseclass)
395
396    virtual bool line_impl(int gc, const AW::LineVector& Line, AW_bitset filteri)                                                  = 0;
397    virtual bool text_impl(int gc, const char *str, const AW::Position& pos, AW_pos alignment, AW_bitset filteri, long opt_strlen) = 0;
398    virtual bool box_impl(int gc, AW::FillStyle filled, const AW::Rectangle& rect, AW_bitset filteri)                                       = 0;
399    virtual bool polygon_impl(int gc, AW::FillStyle filled, int npos, const AW::Position *pos, AW_bitset filteri)                           = 0;
400
401    virtual bool circle_impl(int gc, AW::FillStyle filled, const AW::Position& center, const AW::Vector& radius, AW_bitset filteri)                                  = 0;
402    virtual bool arc_impl(int gc, AW::FillStyle filled, const AW::Position& center, const AW::Vector& radius, int start_degrees, int arc_degrees, AW_bitset filteri) = 0;
403
404    virtual bool invisible_impl(const AW::Position& pos, AW_bitset filteri) = 0;
405
406    virtual void specific_reset() = 0;
407
408protected:
409
410    // * second level functions
411    // generic implementations which may be used by primary functions of derived classes
412
413    bool generic_box(int gc, const AW::Rectangle& rect, AW_bitset filteri);
414    bool generic_circle(int gc, const AW::Position& center, const AW::Vector& radius, AW_bitset filteri) {
415        return generic_box(gc, AW::Rectangle(center-radius, center+radius), filteri);
416    }
417    bool generic_polygon(int gc, int npos, const AW::Position *pos, AW_bitset filteri);
418    bool generic_invisible(const AW::Position& pos, AW_bitset filteri);
419
420public:
421    // * third level functions (never virtual/overloaded by derived classes)
422
423    bool line(int gc, const AW::LineVector& Line, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
424        return line_impl(gc, Line, filteri);
425    }
426    bool line(int gc, const AW::Position& pos1, const AW::Position& pos2, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
427        return line_impl(gc, AW::LineVector(pos1, pos2), filteri);
428    }
429    bool line(int gc, AW_pos x0, AW_pos y0, AW_pos x1, AW_pos y1, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
430        return line_impl(gc, AW::LineVector(x0, y0, x1, y1), filteri);
431    }
432
433    bool text(int         gc,
434              const char *string,
435              AW_pos      x,
436              AW_pos      y,
437              AW_pos      alignment  = 0.0, // 0.0 alignment left 0.5 centered 1.0 right justified
438              AW_bitset   filteri    = AW_ALL_DEVICES_UNSCALED,
439              long        opt_strlen = 0) {
440        return text_impl(gc, string, AW::Position(x, y), alignment, filteri, opt_strlen);
441    }
442    bool text(int                  gc,
443              const char          *string,
444              const AW::Position&  pos,
445              AW_pos               alignment  = 0.0, // 0.0 alignment left 0.5 centered 1.0 right justified
446              AW_bitset            filteri    = AW_ALL_DEVICES_UNSCALED,
447              long                 opt_strlen = 0) {
448        return text_impl(gc, string, pos, alignment, filteri, opt_strlen);
449    }
450
451    bool invisible(const AW::Position& pos, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
452        return invisible_impl(pos, filteri);
453    }
454
455    bool box(int gc, AW::FillStyle filled, const AW::Rectangle& rect, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
456        return box_impl(gc, filled, rect, filteri);
457    }
458    bool box(int gc, AW::FillStyle filled, const AW::Position& pos, const AW::Vector& size, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
459        return box_impl(gc, filled, AW::Rectangle(pos, size), filteri);
460    }
461    bool box(int gc, AW::FillStyle filled, AW_pos x0, AW_pos y0, AW_pos width, AW_pos height, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
462        return box_impl(gc, filled, AW::Rectangle(AW::Position(x0, y0), AW::Vector(width, height)), filteri);
463    }
464
465    bool circle(int gc, AW::FillStyle filled, const AW::Position& center, const AW::Vector& radius, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
466        return circle_impl(gc, filled, center, radius, filteri);
467    }
468    bool circle(int gc, AW::FillStyle filled, AW_pos x0, AW_pos y0, AW_pos xradius, AW_pos yradius, AW_bitset filteri = AW_ALL_DEVICES_SCALED)  {
469        return circle_impl(gc, filled, AW::Position(x0, y0), AW::Vector(xradius, yradius), filteri);
470    }
471    bool circle(int gc, AW::FillStyle filled, const AW::Rectangle& rect, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
472        // draw ellipse into Rectangle
473        return circle_impl(gc, filled, rect.centroid(), AW::Vector(rect.width()/2, rect.height()/2), filteri);
474    }
475
476    // draw arcs (Note: passed degrees are nagative compared to unit circle!)
477    bool arc(int gc, AW::FillStyle filled, AW_pos x0, AW_pos y0, AW_pos xradius, AW_pos yradius, int start_degrees, int arc_degrees, AW_bitset filteri = AW_ALL_DEVICES_SCALED)  {
478        return arc_impl(gc, filled, AW::Position(x0, y0), AW::Vector(xradius, yradius), start_degrees, arc_degrees, filteri);
479    }
480    bool arc(int gc, AW::FillStyle filled, const AW::Position& pos, const AW::Vector& radius, int start_degrees, int arc_degrees, AW_bitset filteri = AW_ALL_DEVICES_SCALED) {
481        return arc_impl(gc, filled, pos, radius, start_degrees, arc_degrees, filteri);
482    }
483
484    bool polygon(int gc, AW::FillStyle filled, int npoints, const AW_pos *points, AW_bitset filteri = AW_ALL_DEVICES_SCALED)  {
485        AW::Position *pos = new AW::Position[npoints];
486        for (int n = 0; n<npoints; ++n) {
487            pos[n].setx(points[n*2]);
488            pos[n].sety(points[n*2+1]);
489        }
490        bool result = polygon_impl(gc, filled, npoints, pos, filteri);
491        delete [] pos;
492        return result;
493    }
494    bool polygon(int gc, AW::FillStyle filled, int npos, const AW::Position *pos, AW_bitset filteri = AW_ALL_DEVICES_SCALED)  {
495        return polygon_impl(gc, filled, npos, pos, filteri);
496    }
497
498    // reduces any string (or virtual string) to its actual drawn size and calls the function f with the result
499    bool text_overlay(int gc, const char *opt_string, long opt_strlen,   // either string or strlen != 0
500                      const AW::Position& pos, AW_pos alignment, AW_bitset filteri, AW_CL cduser,
501                      AW_pos opt_ascent, AW_pos opt_descent,  // optional height (if == 0 take font height)
502                      TextOverlayCallback toc);
503
504
505    // ********* X11 Device only ********
506    virtual void clear(AW_bitset filteri);
507    virtual void clear_part(const AW::Rectangle& rect, AW_bitset filteri);
508
509    void clear_part(AW_pos x, AW_pos y, AW_pos width, AW_pos height, AW_bitset filteri) {
510        clear_part(AW::Rectangle(AW::Position(x, y), AW::Vector(width, height)), filteri);
511    }
512
513    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);
514    virtual void    fast();                                         // e.g. zoom linewidth off
515    virtual void    slow();
516    virtual void    flush();                                        // empty X11 buffers
517};
518
519
520inline void AW_click_cd::link() {
521    previous            = my_device->click_cd;
522    my_device->click_cd = this;
523}
524inline AW_click_cd::~AW_click_cd() { my_device->click_cd = previous; }
525inline void AW_click_cd::disable() { my_device->click_cd = NULL; }
526inline void AW_click_cd::enable() { my_device->click_cd = this; }
527
528class AW_device_print : public AW_device { // derived from a Noncopyable
529    FILE *out;
530    bool  color_mode;
531
532    bool line_impl(int gc, const AW::LineVector& Line, AW_bitset filteri) OVERRIDE;
533    bool text_impl(int gc, const char *str, const AW::Position& pos, AW_pos alignment, AW_bitset filteri, long opt_strlen) OVERRIDE;
534    bool box_impl(int gc, AW::FillStyle filled, const AW::Rectangle& rect, AW_bitset filteri) OVERRIDE;
535    bool circle_impl(int gc, AW::FillStyle filled, const AW::Position& center, const AW::Vector& radius, AW_bitset filteri) OVERRIDE;
536    bool arc_impl(int gc, AW::FillStyle filled, const AW::Position& center, const AW::Vector& radius, int start_degrees, int arc_degrees, AW_bitset filteri) OVERRIDE;
537    bool polygon_impl(int gc, AW::FillStyle filled, int npos, const AW::Position *pos, AW_bitset filteri) OVERRIDE;
538    bool invisible_impl(const AW::Position& pos, AW_bitset filteri) OVERRIDE;
539
540    void specific_reset() {}
541
542public:
543    AW_device_print(AW_common *common_)
544        : AW_device(common_),
545          out(0),
546          color_mode(false)
547    {}
548
549    GB_ERROR open(const char *path) __ATTR__USERESULT;
550    void close();
551
552    FILE *get_FILE() { return out; }
553
554    // AW_device interface:
555    AW_DEVICE_TYPE type();
556
557    int find_color_idx(AW_rgb color);
558    void set_color_mode(bool mode);
559
560};
561
562class AW_simple_device : public AW_device {
563    bool box_impl(int gc, AW::FillStyle /*filled*/, const AW::Rectangle& rect, AW_bitset filteri) OVERRIDE {
564        return generic_box(gc, rect, filteri);
565    }
566    bool polygon_impl(int gc, AW::FillStyle /*filled*/, int npos, const AW::Position *pos, AW_bitset filteri) OVERRIDE {
567        return generic_polygon(gc, npos, pos, filteri);
568    }
569    bool circle_impl(int gc, AW::FillStyle /*filled*/, const AW::Position& center, const AW::Vector& radius, AW_bitset filteri) OVERRIDE {
570        return generic_circle(gc, center, radius, filteri);
571    }
572    bool arc_impl(int gc, AW::FillStyle /*filled*/, const AW::Position& center, const AW::Vector& radius, int /*start_degrees*/, int /*arc_degrees*/, AW_bitset filteri) OVERRIDE {
573        return generic_circle(gc, center, radius, filteri);
574    }
575public:
576    AW_simple_device(AW_common *common_) : AW_device(common_) {}
577};
578
579class AW_size_tracker {
580    bool     drawn;
581    AW_world size;
582
583    void extend(AW_pos& low, AW_pos val, AW_pos& high) {
584        low = std::min(low, val);
585        high = std::max(high, val);
586    }
587public:
588    AW_size_tracker() { restart(); }
589
590    void restart() { drawn = false; size.clear(); }
591    void track(const AW::Position& pos) {
592        if (drawn) {
593            extend(size.l, pos.xpos(), size.r);
594            extend(size.t, pos.ypos(), size.b);
595        }
596        else {
597            size.l = size.r = pos.xpos();
598            size.t = size.b = pos.ypos();
599            drawn  = true;
600        }
601    }
602
603    bool was_drawn() const { return drawn; }
604    const AW_world& get_size() const { return size; }
605    AW::Rectangle get_size_as_Rectangle() const {
606        return AW::Rectangle(AW::Position(size.l, size.t), AW::Position(size.r, size.b));
607    }
608};
609
610class AW_device_size : public AW_simple_device {
611    AW_size_tracker scaled;   // all zoomable parts (e.g. tree skeleton)
612    AW_size_tracker unscaled; // all unzoomable parts (e.g. text at tree-tips or group-brackets)
613
614    void dot_transformed(const AW::Position& pos, AW_bitset filteri);
615    void dot_transformed(AW_pos X, AW_pos Y, AW_bitset filteri) { dot_transformed(AW::Position(X, Y), filteri); }
616
617    void dot(const AW::Position& p, AW_bitset filteri) { dot_transformed(transform(p), filteri); }
618    void dot(AW_pos x, AW_pos y, AW_bitset filteri) { dot(AW::Position(x, y), filteri); }
619
620    bool line_impl(int gc, const AW::LineVector& Line, AW_bitset filteri) OVERRIDE;
621    bool text_impl(int gc, const char *str, const AW::Position& pos, AW_pos alignment, AW_bitset filteri, long opt_strlen) OVERRIDE;
622    bool invisible_impl(const AW::Position& pos, AW_bitset filteri) OVERRIDE;
623
624    void specific_reset();
625
626public:
627    AW_device_size(AW_common *common_) : AW_simple_device(common_) {}
628
629    void restart_tracking();
630
631    AW_DEVICE_TYPE type();
632
633    // all get_size_information...() return screen coordinates
634
635    void get_size_information(AW_world *ptr) const __ATTR__DEPRECATED_TODO("whole AW_world is deprecated") {
636        *ptr = scaled.get_size();
637    }
638    AW::Rectangle get_size_information() const { return scaled.get_size_as_Rectangle(); }
639    AW::Rectangle get_size_information_unscaled() const { return unscaled.get_size_as_Rectangle(); }
640    AW::Rectangle get_size_information_inclusive_text() const {
641        return get_size_information().bounding_box(get_size_information_unscaled());
642    }
643
644    AW_borders get_unscaleable_overlap() const;
645};
646
647#else
648#error aw_device.hxx included twice
649#endif
Note: See TracBrowser for help on using the repository browser.