1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : AW_Xm.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include <aw_Xm.hxx> |
---|
12 | |
---|
13 | #if defined(WARN_TODO) |
---|
14 | #warning change implementation of draw functions (read more) |
---|
15 | // * filter has to be checked early (in AW_device) |
---|
16 | // * functions shall use Position/LineVector/Rectangle only |
---|
17 | #endif |
---|
18 | |
---|
19 | using namespace AW; |
---|
20 | |
---|
21 | // --------------------- |
---|
22 | // AW_device_Xm |
---|
23 | |
---|
24 | AW_DEVICE_TYPE AW_device_Xm::type() { return AW_DEVICE_SCREEN; } |
---|
25 | |
---|
26 | #define XDRAW_PARAM2(common) (common)->get_display(), (common)->get_window_id() |
---|
27 | #define XDRAW_PARAM3(common,gc) XDRAW_PARAM2(common), (common)->get_GC(gc) |
---|
28 | |
---|
29 | bool AW_device_Xm::line_impl(int gc, const LineVector& Line, AW_bitset filteri) { |
---|
30 | bool drawflag = false; |
---|
31 | if (filteri & filter) { |
---|
32 | LineVector transLine = transform(Line); |
---|
33 | LineVector clippedLine; |
---|
34 | drawflag = clip(transLine, clippedLine); |
---|
35 | if (drawflag) { |
---|
36 | XDrawLine(XDRAW_PARAM3(get_common(), gc), |
---|
37 | AW_INT(clippedLine.start().xpos()), AW_INT(clippedLine.start().ypos()), |
---|
38 | AW_INT(clippedLine.head().xpos()), AW_INT(clippedLine.head().ypos())); |
---|
39 | AUTO_FLUSH(this); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | return drawflag; |
---|
44 | } |
---|
45 | |
---|
46 | static bool AW_draw_string_on_screen(AW_device *device, int gc, const char *str, size_t /* opt_str_len */, size_t start, size_t size, |
---|
47 | AW_pos x, AW_pos y, AW_pos /*opt_ascent*/, AW_pos /*opt_descent*/, AW_CL /*cduser*/) |
---|
48 | { |
---|
49 | AW_pos X, Y; |
---|
50 | device->transform(x, y, X, Y); |
---|
51 | aw_assert(size <= strlen(str)); |
---|
52 | AW_device_Xm *device_xm = DOWNCAST(AW_device_Xm*, device); |
---|
53 | XDrawString(XDRAW_PARAM3(device_xm->get_common(), gc), AW_INT(X), AW_INT(Y), str + start, (int)size); |
---|
54 | AUTO_FLUSH(device); |
---|
55 | return true; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | bool AW_device_Xm::text_impl(int gc, const char *str, const Position& pos, AW_pos alignment, AW_bitset filteri, long opt_strlen) { |
---|
60 | return text_overlay(gc, str, opt_strlen, pos, alignment, filteri, (AW_CL)this, 0.0, 0.0, AW_draw_string_on_screen); |
---|
61 | } |
---|
62 | |
---|
63 | bool AW_device_Xm::box_impl(int gc, bool filled, const Rectangle& rect, AW_bitset filteri) { |
---|
64 | bool drawflag = false; |
---|
65 | if (filteri & filter) { |
---|
66 | if (filled) { |
---|
67 | Rectangle transRect = transform(rect); |
---|
68 | Rectangle clippedRect; |
---|
69 | drawflag = box_clip(transRect, clippedRect); |
---|
70 | if (drawflag) { |
---|
71 | XFillRectangle(XDRAW_PARAM3(get_common(), gc), |
---|
72 | AW_INT(clippedRect.left()), |
---|
73 | AW_INT(clippedRect.top()), |
---|
74 | AW_INT(clippedRect.width())+1, // see aw_device.hxx@WORLD_vs_PIXEL |
---|
75 | AW_INT(clippedRect.height())+1); |
---|
76 | AUTO_FLUSH(this); |
---|
77 | } |
---|
78 | } |
---|
79 | else { |
---|
80 | drawflag = generic_box(gc, false, rect, filteri); |
---|
81 | } |
---|
82 | } |
---|
83 | return drawflag; |
---|
84 | } |
---|
85 | |
---|
86 | bool AW_device_Xm::circle_impl(int gc, bool filled, const AW::Position& center, const AW::Vector& radius, AW_bitset filteri) { |
---|
87 | aw_assert(radius.x()>0 && radius.y()>0); |
---|
88 | return arc_impl(gc, filled, center, radius, 0, 360, filteri); |
---|
89 | } |
---|
90 | |
---|
91 | bool AW_device_Xm::arc_impl(int gc, bool filled, const AW::Position& center, const AW::Vector& radius, int start_degrees, int arc_degrees, AW_bitset filteri) { |
---|
92 | // degrees start at east side of unit circle, |
---|
93 | // but orientation is clockwise (because ARBs y-coordinate grows downwards) |
---|
94 | |
---|
95 | bool drawflag = false; |
---|
96 | if (filteri & filter) { |
---|
97 | Rectangle Box(center-radius, center+radius); |
---|
98 | Rectangle screen_box = transform(Box); |
---|
99 | |
---|
100 | drawflag = !is_outside_clip(screen_box); |
---|
101 | if (drawflag) { |
---|
102 | int width = AW_INT(screen_box.width()); |
---|
103 | int height = AW_INT(screen_box.height()); |
---|
104 | const Position& ulc = screen_box.upper_left_corner(); |
---|
105 | int xl = AW_INT(ulc.xpos()); |
---|
106 | int yl = AW_INT(ulc.ypos()); |
---|
107 | |
---|
108 | aw_assert(arc_degrees >= -360 && arc_degrees <= 360); |
---|
109 | |
---|
110 | // ARB -> X |
---|
111 | start_degrees = -start_degrees; |
---|
112 | arc_degrees = -arc_degrees; |
---|
113 | |
---|
114 | while (start_degrees<0) start_degrees += 360; |
---|
115 | |
---|
116 | if (!filled) { |
---|
117 | XDrawArc(XDRAW_PARAM3(get_common(), gc), xl, yl, width, height, 64*start_degrees, 64*arc_degrees); |
---|
118 | } |
---|
119 | else { |
---|
120 | XFillArc(XDRAW_PARAM3(get_common(), gc), xl, yl, width, height, 64*start_degrees, 64*arc_degrees); |
---|
121 | } |
---|
122 | AUTO_FLUSH(this); |
---|
123 | } |
---|
124 | } |
---|
125 | return drawflag; |
---|
126 | } |
---|
127 | |
---|
128 | void AW_device_Xm::clear(AW_bitset filteri) { |
---|
129 | if (filteri & filter) { |
---|
130 | XClearWindow(XDRAW_PARAM2(get_common())); |
---|
131 | AUTO_FLUSH(this); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | void AW_device_Xm::clear_part(const Rectangle& rect, AW_bitset filteri) { |
---|
136 | if (filteri & filter) { |
---|
137 | Rectangle transRect = transform(rect); |
---|
138 | Rectangle clippedRect; |
---|
139 | bool drawflag = box_clip(transRect, clippedRect); |
---|
140 | if (drawflag) { |
---|
141 | XClearArea(XDRAW_PARAM2(get_common()), |
---|
142 | AW_INT(clippedRect.left()), |
---|
143 | AW_INT(clippedRect.top()), |
---|
144 | AW_INT(clippedRect.width())+1, // see aw_device.hxx@WORLD_vs_PIXEL |
---|
145 | AW_INT(clippedRect.height())+1, |
---|
146 | False); |
---|
147 | AUTO_FLUSH(this); |
---|
148 | } |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | void AW_device_Xm::flush() { |
---|
153 | XFlush(get_common()->get_display()); |
---|
154 | } |
---|
155 | |
---|
156 | void AW_device_Xm::move_region(AW_pos src_x, AW_pos src_y, AW_pos width, AW_pos height, AW_pos dest_x, AW_pos dest_y) { |
---|
157 | int gc = 0; |
---|
158 | XCopyArea(get_common()->get_display(), get_common()->get_window_id(), get_common()->get_window_id(), get_common()->get_GC(gc), |
---|
159 | AW_INT(src_x), AW_INT(src_y), AW_INT(width), AW_INT(height), |
---|
160 | AW_INT(dest_x), AW_INT(dest_y)); |
---|
161 | AUTO_FLUSH(this); |
---|
162 | } |
---|