source: tags/ms_r16q2/WINDOW/aw_device.hxx

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