UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ZBase.H
1 // ZBase.H
2 // $Id: ZBase.H,v 1.21 2005/06/14 12:31:03 vlad Exp $
3 
4 #if !defined __ZBase_H
5 
6 #define __ZBase_H
7 
8 #include <stdio.h>
9 #include <string.h>
10 #include <malloc.h>
11 
12 #include <X11/Xlib.h>
13 #include <X11/Xutil.h>
14 #ifndef NO_XTOOLKIT
15 #include <X11/Intrinsic.h>
16 #endif /* NO_XTOOLKIT */
17 
18 #include <mix/Exceptions.h>
19 #include <zm/ZTypes.h>
20 #include <zm/Zm.h>
21 
22 
23 /* Forward definitions */
24 class ZSize;
25 
26 
27 /*************************************************************
28  * Pixel point, place
29  *************************************************************/
30 class ZPoint
31 {
32 public:
33 
34  int x; /* x coord */
35  int y; /* y coord */
36 
37  ZPoint ();
38  ZPoint (int x_coord, int y_coord);
39  ZPoint (const ZPoint& zpoint);
40 
41  operator XPoint () const;
42 
43  void add_offset (const ZSize& zsize);
44  void sub_offset (const ZSize& zsize);
45 
46  void print (const char* szEnd = "\n") const;
47 
48  bool operator== (const ZPoint& zpoint) const;
49  bool operator!= (const ZPoint& zpoint) const;
50 
51 };
52 
53 
54 /*************************************************************
55  * Pixel size, box with undefined place. Conversion to
56  * XRectangle means: [0,0], [w-1,0], [w-1,h-1], [0,h-1].
57  *************************************************************/
58 class ZSize
59 {
60 public:
61 
62  int w; /* width */
63  int h; /* height */
64 
65  ZSize ();
66  ZSize (int width, int height);
67  ZSize (const ZSize& zsize);
68 
69  virtual Logic inside (const ZPoint& zpoint) const;
70  virtual operator XRectangle () const;
71 
72  void difference (const ZPoint& zpoint1, const ZPoint& zpoint2);
73 
74  void print (const char* szEnd = "\n") const;
75 
76  bool operator== (const ZSize& zsize) const;
77  bool operator!= (const ZSize& zsize) const;
78 
79 };
80 
81 
82 /*************************************************************
83  * Real box, rectangle. Corners has the next coords: [x,y],
84  * [x+w-1,y], [x+w-1,y+h-1], [x,y+h-1].
85  *************************************************************/
86 
87 class ZRect : public ZPoint, public ZSize
88 {
89 public:
90 
91  ZRect ();
92  ZRect (const ZPoint& zpoint1, const ZPoint& zpoint2);
93  ZRect (const ZPoint& zpoint, const ZSize& zsize,
94  ZCorner zcorner = zcLeftTop);
95  ZRect (const ZRect& zrect);
96 
97  /* Changes coords of rectangle to place zpoint, where
98  zpoint in zcorner of virtual box */
99  virtual void move (const ZPoint& zpoint,
100  ZCorner zcorner = zcLeftTop);
101 
102  /* Returns TRUE if zpoint is inside rectangle or on its border */
103  virtual Logic inside (const ZPoint& zpoint) const;
104 
105  virtual operator XRectangle () const;
106 
107  void print (const char* szEnd = "\n") const;
108 
109  bool operator== (const ZRect& zrect) const;
110  bool operator!= (const ZRect& zrect) const;
111 
112 };
113 
114 
115 /*************************************************************
116  * Link with X server
117  *************************************************************/
118 class ZConnect
119 {
120 public:
121 
122  Display *dpy; /* Display connection */
123  ScreenNo scr_no; /* Screen on display */
124 
125  ZConnect (Display* display);
126  ZConnect (const ZConnect& zconnect);
127 
128  void flush (); /* Performs XFlush(dpy) */
129 
130  /* X Errors handler and exeption generator */
131  void x_error (int code) const;
132 
133  /* Returns ZRect of drawable */
134  ZRect rect (Drawable drawable) const;
135 
136  /* Returns ZRect of root window */
137  virtual ZRect rect () const;
138 
139  /* Returns depth of pointed drawable */
140  int depth (Drawable drawable) const;
141 
142  /* Returns window id of root window */
143  Window root_wid () const;
144 
145  /* Color functions */
146  ColorPixel white () const;
147  ColorPixel black () const;
148  ColorPixel color (const char* szColorName) const;
149 
150 };
151 
152 
153 /*************************************************************
154  * X Graphics Environment: newly created GC.
155  *************************************************************/
156 class ZGEnv : virtual public ZConnect
157 {
158 private:
159 
160  char *font_name; /* name of current font */
161  char *fg_name; /* name of current foreground color */
162  char *bg_name; /* name of current background color */
163 
164 protected:
165 
166  // Draw text in some drawable attached to some point.
167  void draw_text (Drawable id, int x, int y, int attachment,
168  const char* szText) const;
169 
170  // Draw aligned text in pointed rectange.
171  void draw_text (Drawable id, const ZRect& box, int alignment,
172  const char* szText) const;
173 
174 public:
175 
176  GC gc; /* Graphics context */
177  XFontStruct *font; /* Font info for current font */
178 
179  ZGEnv (const ZConnect& zconnect);
180  ZGEnv (const ZGEnv& zgenv);
181  virtual ~ZGEnv ();
182 
183  virtual void expose ();
184 
185  /* GC operations */
186  void set_foreground (const char* szColorName);
187  void set_foreground (ColorPixel cp);
188  ColorPixel get_foreground () const;
189  const char* get_foreground_name () const;
190 
191  void set_background (const char* szColorName);
192  void set_background (ColorPixel cp);
193  ColorPixel get_background () const;
194  const char* get_background_name () const;
195 
196  void swap_ground (); /* swap foreground and background */
197  void assign (const ZGEnv& zgenv);
198 
199  void set_line_width (int new_width);
200  int get_line_width () const;
201 
202  void set_line_style (int new_style, int dash = 3, int hole = 3);
203  int get_line_style () const;
204 
205  void set_font (const char* szFontName);
206  void set_font_as (const ZGEnv& zgenv);
207  Font get_font () const;
208  const char* get_font_name () const;
209 
210  /* Text and font characteristics */
211  int text_width (const char* szText) const;
212  int text_width (int n) const;
213  int text_height () const; /* ascent + descent */
214  int text_ascent () const;
215  int text_descent () const;
216 
217  /* Get screen margin of text's rectangle */
218  ZRect text_rect (int x, int y, int attachment,
219  const char* szText) const;
220 
221  /* Method that is called when some changes of internal state
222  of object take place */
223  virtual void changed_state (int mask_of_changes);
224 
226  ZGEnv& operator= (const ZGEnv& zgenv);
227 
228 };
229 
230 
231 /*************************************************************
232  * Link with some window
233  *************************************************************/
234 class ZWindow : public ZGEnv
235 {
236 public:
237 
238  Window wid; /* Window identifier */
239 
240  ZWindow (const ZConnect& zconnect, Window window);
241  ZWindow (const ZWindow& zwindow);
242 
243  /* Returns ZRect of this window */
244  virtual ZRect rect () const;
245 
246  /* Draw attached text */
247  void draw_text (int x, int y, int attachment,
248  const char* szText) const;
249 
250  /* Draw aligned text */
251  void draw_text (const ZRect& box, int alignment,
252  const char* szText) const;
253 };
254 
255 
256 /*************************************************************
257  * Link with some drawable
258  *************************************************************/
259 class ZDrawable : public ZGEnv
260 {
261 public:
262 
263  Drawable did; /* Drawable identifier */
264 
265  ZDrawable (const ZConnect& zconnect, Drawable drawable);
266  ZDrawable (const ZDrawable& zdrawable);
267 
268  /* Returns ZRect of this drawable */
269  virtual ZRect rect () const;
270 
271  /* Draw attached text */
272  void draw_text (int x, int y, int attachment,
273  const char* szText) const;
274 
275  /* Draw aligned text */
276  void draw_text (const ZRect& box, int alignment,
277  const char* szText) const;
278 
280  void write_tiff (const char* path, ZmImageRemarks* remarks = NULL);
281 
283  void write_png (const char* path, ZmImageRemarks* remarks = NULL);
284 
285 };
286 
287 
288 /*************************************************************
289  * Newly created pixmap with default depth
290  *************************************************************/
291 class ZArea : public ZDrawable
292 {
293 public:
294 
295  ZArea (const ZConnect& zconnect, const ZSize& zsize);
296  ZArea (const ZArea& zarea);
297  virtual ~ZArea ();
298 
299  void resize (const ZSize& zsize);
300 };
301 
302 
303 /* Dynamic array of XSegments */
304 #define AnyType XSegment
305 #define AnyAr XSegmentAr
306 #define AnyFormatSpec "\n%d: (%d,%d)-(%d,%d)"
307 #define AnyPrintList i, item.x1, item.y1, item.x2, item.y2
308 #include <mix/AnyAr.H>
309 
310 
311 #ifndef NO_XTOOLKIT
312 
313 /*************************************************************
314  * Widget based object.
315  *************************************************************/
316 class ZWidget : virtual public ZConnect
317 {
318 public:/* methods */
319 
320  ZWidget (Widget w = NULL);
321  virtual ~ZWidget ();
322 
323  virtual Widget widget () const;
324 
325 protected:/* data */
326 
327  Widget wptr;
328 
329 };
330 
331 #endif /* NO_XTOOLKIT */
332 
333 /*************************************************************
334  * The function performs convertion of a segment into the one
335  * with ends inside rectangle area. Returns indication if part
336  * of segment inside area. Needed conditions: (wr>=0)&&(hr>=0)
337  * Input:
338  * (x1p,y1p)-(x2p,y2p) -- any source line;
339  * (xr,yr)-(xr+wr,yr+hr) -- bounds of rectangle;
340  * Output:
341  * (x1p,y1p)-(x2p,y2p) -- part of source line inside pointed
342  * rectangle;
343  * Return:
344  * TRUE if source line has a part inside pointed rectangle;
345  * FALSE if source line does not have even a point inside
346  * pointed rectangle.
347  *************************************************************/
348 extern "C" Logic RectMask (float* x1p, float* y1p,
349  float* x2p, float* y2p,
350  float xr, float yr, float wr, float hr);
351 
352 
353 /***********************************************************************
354  * Compute distance from given point (x,y) to line (x1,y1)-(x2,y2).
355  ***********************************************************************/
356 extern "C" float DistanceToLine (int x, int y,
357  int x1, int y1, int x2, int y2);
358 
359 
360 #ifndef NO_XTOOLKIT
361 #endif /* NO_XTOOLKIT */
362 //#define INLINE inline
363 //#include "ZBaseInline.H"
364 
365 
366 #endif // ZBase.H
Definition: ZBase.H:156
ZGEnv & operator=(const ZGEnv &zgenv)
Definition: ZBase.H:234
Definition: ZBase.H:87
Definition: ZBase.H:291
Definition: ZBase.H:316
Definition: ZBase.H:58
Definition: ZBase.H:118
void write_tiff(const char *path, ZmImageRemarks *remarks=NULL)
Definition: ZBase.H:30
Definition: ZBase.H:259
Definition: Zm.h:164
void write_png(const char *path, ZmImageRemarks *remarks=NULL)