annotate tools/x11coord.h @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
rev   line source
tomwalters@0 1 /*
tomwalters@0 2 Still to consider:
tomwalters@0 3
tomwalters@0 4 A structure for a box-object, containing a complete set of internal
tomwalters@0 5 variables for one box. A routine could allocate a structure, call the
tomwalters@0 6 routines set_box_parameters() and set_data_parameters(), and return a ptr
tomwalters@0 7 to the structure. Now a set of #defines could take a structure pointer
tomwalters@0 8 (just as they currently often take a window ptr), and could call the
tomwalters@0 9 appropriate sub-routines using the internal variables for that box.
tomwalters@0 10 (The window could be a member of the structute too).
tomwalters@0 11
tomwalters@0 12 With this, you could easily maintain a set of boxes, and plot anything
tomwalters@0 13 in any of them. But if you need ore than one window, then you'll need a
tomwalters@0 14 window structure too, (to hold window parameters for each window).
tomwalters@0 15 For example:
tomwalters@0 16
tomwalters@0 17 struct st_window {
tomwalters@0 18 Window w;
tomwalters@0 19 int x,y; window origin wrt display
tomwalters@0 20 unsigned int width,height; window size
tomwalters@0 21 GC gc;
tomwalters@0 22 };
tomwalters@0 23
tomwalters@0 24 struct st_box {
tomwalters@0 25 struct st_window * pt; parent window
tomwalters@0 26 char *fname; file name for data
tomwalters@0 27 int n, s; num points and start point in file
tomwalters@0 28 ...all system variables...
tomwalters@0 29 };
tomwalters@0 30
tomwalters@0 31 */
tomwalters@0 32
tomwalters@0 33
tomwalters@0 34 /****************************************************************************
tomwalters@0 35
tomwalters@0 36 x11coord.h A file for inclusion into X11 plotting programs.
tomwalters@0 37 ---------- (See x11test.c for example).
tomwalters@0 38
tomwalters@0 39 ****************************************************************************
tomwalters@0 40
tomwalters@0 41 User parameters:
tomwalters@0 42 ================
tomwalters@0 43 1. Window parameters - Set size and position of a window on the display.
tomwalters@0 44 set_window_parameters(xorg,yorg, width,height)
tomwalters@0 45 int xorg,yorg Window origin (pixel coords of top-left wrt Display).
tomwalters@0 46 int width,height Window size (pixels).
tomwalters@0 47
tomwalters@0 48 2. Box parameters - Set size and position of a box in a preset window.
tomwalters@0 49 a) set_box_parameters(xorg,yorg, width,height)
tomwalters@0 50 int xorg,yorg Box origin (pixel coords of bottom-left wrt window).
tomwalters@0 51 int width,height Box size (pixels).
tomwalters@0 52 b) set_bordered_box(bpc)
tomwalters@0 53 int bpc Box border (constant width) as %age of window size.
tomwalters@0 54
tomwalters@0 55 3. Data parameters - Set area and location of data space to appear in box.
tomwalters@0 56 set_data_parameters(xp0,yp0, xd0,yd0, xrange,yrange)
tomwalters@0 57 int xp0,yp0 Plot origin (as a %age of box size from box origin).
tomwalters@0 58 float xd0,yd0 Data origin (data coords to appear under plot origin).
tomwalters@0 59 float xrange,yrange Data ranges (area of data space to appear under plot).
tomwalters@0 60
tomwalters@0 61 Notes:
tomwalters@0 62 1. Pixel coordinates and sizes are ints. Data coordinates and sizes are floats.
tomwalters@0 63 2. Pixel coords refer to the X11 coord system which has origin (0,0) in the
tomwalters@0 64 top-left of each window. Data coords refer to the user coord system which
tomwalters@0 65 has its origin (0,0) in the bottom-left of each box.
tomwalters@0 66 3. The parameter initialization routines must be called in order, (window,
tomwalters@0 67 box, data), and must be done first, otherwise macros which use the system
tomwalters@0 68 variables will not work. As a minimum, you MUST do set_window_parameters(),
tomwalters@0 69 and this will give you a box the same size as the window, with origin in
tomwalters@0 70 the bottom-left, with data origin at the box origin, and data ranges the
tomwalters@0 71 same as pixels.
tomwalters@0 72 4. Although its true that set_window_parameters only sets window pixel sizes,
tomwalters@0 73 set_box_parameters only sets box pixel sizes, and set_data_parameters only
tomwalters@0 74 sets data sizes, the data sizes are somewhat dependent upon the pixel
tomwalters@0 75 sizes, and so if you change the window or box parameters during a program,
tomwalters@0 76 (eg, to resize a box), then you must re-initialize set_data_parameters at
tomwalters@0 77 the same time. (Call it again with the same initial arguments; it will
tomwalters@0 78 re-initialize internal parameters).
tomwalters@0 79
tomwalters@0 80 User routines and macros:
tomwalters@0 81 =========================
tomwalters@0 82 Set system private parameters.
tomwalters@0 83 -----------------------------
tomwalters@0 84 set_window_parameters(xorg,yorg, width,height)
tomwalters@0 85 set_box_parameters(xorg,yorg, width,height)
tomwalters@0 86 set_bordered_box(bpc)
tomwalters@0 87 set_data_parameters(xp0,yp0, xd0,yd0, xrange,yrange)
tomwalters@0 88 Open connection and create window.
tomwalters@0 89 ---------------------------------
tomwalters@0 90 xopen()
tomwalters@0 91 Window xcreate(name, event_mask)
tomwalters@0 92 Convert coordinates.
tomwalters@0 93 -------------------
tomwalters@0 94 int px(x)
tomwalters@0 95 int py(y)
tomwalters@0 96 float xp(p)
tomwalters@0 97 float yp(p)
tomwalters@0 98 float xpc(pc)
tomwalters@0 99 float ypc(pc)
tomwalters@0 100 Return pixel coordinates.
tomwalters@0 101 -----------------------
tomwalters@0 102 int pleft()
tomwalters@0 103 int pright()
tomwalters@0 104 int pbottom()
tomwalters@0 105 int ptop()
tomwalters@0 106 int pwidth()
tomwalters@0 107 int pheight()
tomwalters@0 108 Return data coordinates.
tomwalters@0 109 -----------------------
tomwalters@0 110 float xleft()
tomwalters@0 111 float xright()
tomwalters@0 112 float ybottom()
tomwalters@0 113 float ytop()
tomwalters@0 114 float xwidth()
tomwalters@0 115 float yheight()
tomwalters@0 116 float xcentre()
tomwalters@0 117 float ycentre()
tomwalters@0 118 float Xjitter(x,p)
tomwalters@0 119 float Yjitter(y,p)
tomwalters@0 120 Test data coordinates.
tomwalters@0 121 ---------------------
tomwalters@0 122 bool Xinbox(x)
tomwalters@0 123 bool Yinbox(y)
tomwalters@0 124 bool inbox(x,y)
tomwalters@0 125 Draw and calibrate boxes and axes.
tomwalters@0 126 ---------------------------------
tomwalters@0 127 draw_Xaxis(w,yval)
tomwalters@0 128 calibrate_Xaxis(w,yval)
tomwalters@0 129 draw_Yaxis(w,xval)
tomwalters@0 130 calibrate_Yaxis(w,xval)
tomwalters@0 131 draw_box(w)
tomwalters@0 132 calibrate_box(w)
tomwalters@0 133 draw_calibrated_box(w)
tomwalters@0 134 Draw points, lines, and strings, etc..
tomwalters@0 135 -------------------------------------
tomwalters@0 136 setLinewidth(width)
tomwalters@0 137 Point(w,x,y)
tomwalters@0 138 xPoint(w,x,y)
tomwalters@0 139 Line(w,x1,y1,x2,y2)
tomwalters@0 140 xLine(w,x1,y1,x2,y2)
tomwalters@0 141 String(w,x,y,string)
tomwalters@0 142 xString(w,x,y,string)
tomwalters@0 143 Cross(w,x,y)
tomwalters@0 144 xCross(w,x,y)
tomwalters@0 145 Dot(w,x,y,dotsize)
tomwalters@0 146 xDot(w,x,y,dotsize)
tomwalters@0 147 Text string parameters.
tomwalters@0 148 -----------------------
tomwalters@0 149 setFont("fontname")
tomwalters@0 150 int nlines()
tomwalters@0 151 int ncols()
tomwalters@0 152 Return pixel sizes based on current "theFont".
tomwalters@0 153 ----------------------------------------------
tomwalters@0 154 int max_charwidth()
tomwalters@0 155 int max_charheight()
tomwalters@0 156 int stringwidth(string)
tomwalters@0 157 int stringheight(string)
tomwalters@0 158 int linespacing() white space between lines.
tomwalters@0 159 int lineheight() total line (y-value) increment.
tomwalters@0 160 int colwidth() total character (x-value) increment.
tomwalters@0 161 int margin() white space at sides of page.
tomwalters@0 162 int headroom() white space at head and foot of page.
tomwalters@0 163 Return pixel coordinates.
tomwalters@0 164 -------------------------
tomwalters@0 165 int leftmargin()
tomwalters@0 166 int rightmargin()
tomwalters@0 167 int topmargin()
tomwalters@0 168 int bottommargin()
tomwalters@0 169 int line(i)
tomwalters@0 170 int col(j)
tomwalters@0 171 Draw text strings.
tomwalters@0 172 ------------------
tomwalters@0 173 topline(w,string)
tomwalters@0 174 bottomline(w,string)
tomwalters@0 175 lineString(w,string,i,j)
tomwalters@0 176 leftString(w,string,i)
tomwalters@0 177 rightString(w,string,i)
tomwalters@0 178 centreString(w,string,i)
tomwalters@0 179 supertopline(w,string)
tomwalters@0 180
tomwalters@0 181
tomwalters@0 182 Notes:
tomwalters@0 183 1. The user routines conventionally take data coordinate arguments.
tomwalters@0 184 To convert pixel coordinates to data, use the xp,yp macros.
tomwalters@0 185
tomwalters@0 186 Development of coord system scaling transformations:
tomwalters@0 187 ====================================================
tomwalters@0 188 Internal variables (initialized by the `set' routines and used by the `px'
tomwalters@0 189 macros) are pixel coords and sizes, and refer to the X11 coord system:
tomwalters@0 190
tomwalters@0 191 | _Xp0 |
tomwalters@0 192 +---------------+
tomwalters@0 193 | |
tomwalters@0 194
tomwalters@0 195 | _Xp1 |
tomwalters@0 196 +---------------------------+
tomwalters@0 197 | |
tomwalters@0 198 (0,0)
tomwalters@0 199 -+- -+- +-------------------------------------------+
tomwalters@0 200 | | |Window |
tomwalters@0 201 | _Yp1| | |
tomwalters@0 202 | | | _Wb |
tomwalters@0 203 _Yp0| -+- | (_Xp0,_Yp1) +-----------+ (_Xp1,_Yp1) |
tomwalters@0 204 | | |Box | |
tomwalters@0 205 | | | |_Hb |
tomwalters@0 206 | | | | |
tomwalters@0 207 -+- | (_Xp0,_Yp0) +-----------+ (_Xp1,_Yp0) |
tomwalters@0 208 | |
tomwalters@0 209 | |
tomwalters@0 210 | |
tomwalters@0 211 +-------------------------------------------+
tomwalters@0 212
tomwalters@0 213 Consider a box of width Wb pixels (on horizontal axis) and height Hb pixels
tomwalters@0 214 (on vertical axis). Let this box size represent data ranges xrange and yrange,
tomwalters@0 215 (corresponding to Wb and Hb respectively). Let the pixel origin and the data
tomwalters@0 216 origin be superimposed at (0,0) in the bottom-left corner. Then a data coord
tomwalters@0 217 (x,y) is transformed into a pixel coord by the scaling:
tomwalters@0 218 px(x) = x * Wb/xrange
tomwalters@0 219 py(y) = y * Hb/yrange
tomwalters@0 220
tomwalters@0 221 If the data coordinate which we wish to appear at the plot origin is actually
tomwalters@0 222 (xd0,yd0), then the data origin must be shifted off the pixel origin, so that
tomwalters@0 223 the data coord (xd0,yd0) is represented by pixel coord (0,0). Hence:
tomwalters@0 224 px(x) = (x-xd0) * Wb/xrange
tomwalters@0 225 py(y) = (y-yd0) * Hb/yrange
tomwalters@0 226
tomwalters@0 227 It is necessary to invert the y-axis so that pixel coords are consistent with
tomwalters@0 228 the X11 coord system, (with pixel origin in the top-left of a window and pixel
tomwalters@0 229 y-values which increase down the window). Let the box be positioned in the
tomwalters@0 230 top-left corner of its parent window, so that the X11 origin corresponds with
tomwalters@0 231 the top-left corner of the box. Then the y-axis is inverted by:
tomwalters@0 232 px(x) = (x-xd0) * Wb/xrange
tomwalters@0 233 py(y) = Hb - (y-yd0) * Hb/yrange
tomwalters@0 234
tomwalters@0 235 In general, the box will be positioned within its parent window as in the
tomwalters@0 236 diagram above. The box is shifted into the window by an x-value Xp0 and a
tomwalters@0 237 y-value Yp1, and these must be added to any pixel coordinate:
tomwalters@0 238 px(x) = Xp0 + (x-xd0) * Wb/xrange
tomwalters@0 239 py(y) = Yp1 + Hb - (y-yd0) * Hb/yrange
tomwalters@0 240
tomwalters@0 241 Although Yp0 is the y-value at the bottom of the box, at its default origin,
tomwalters@0 242 note that Yp0>Yp1, since y-values increase down the window in the X11 pixel
tomwalters@0 243 coordinate system.
tomwalters@0 244 Finally, we may want the user origin of the box to be somewhere other than the
tomwalters@0 245 bottom-left corner, (Eg, scatter plots often have the user origin in the
tomwalters@0 246 centre of the plot; time-waveform plot often have the origin half-way up the
tomwalters@0 247 left side of the plot). To place the user origin at a pixel coordinate of
tomwalters@0 248 (xshift,yshift), we add xshift and subtract yshift from the transformed pixel
tomwalters@0 249 coordinates. (We subtract yshift since the transformed pixel coord is in the
tomwalters@0 250 X11 coord system). So we have:
tomwalters@0 251 px(x) = Xp0 + xshift + (x-xd0) * Wb/xrange
tomwalters@0 252 py(y) = Yp1 + Hb - yshift - (y-yd0) * Hb/yrange
tomwalters@0 253
tomwalters@0 254 Grouping terms we have:
tomwalters@0 255 px(x) = Xp0 + xshift - xd0*Wb/xrange + x*Wb/xrange
tomwalters@0 256 py(y) = Yp1 + Hb - yshift + yd0*Hb/yrange - y*Hb/yrange
tomwalters@0 257
tomwalters@0 258 Now substituting:
tomwalters@0 259 xoffset = Xp0 + xshift - xd0*Wb/xrange ; xscale = Wb/xrange
tomwalters@0 260 yoffset = Yp1 + Hb - yshift + yd0*Hb/yrange ; yscale = Hb/yrange
tomwalters@0 261 We have:
tomwalters@0 262 px(x) = xoffset + x * xscale
tomwalters@0 263 py(y) = yoffset - y * yscale
tomwalters@0 264
tomwalters@0 265 The inverse transformations xp(p) and yp(p) are just the inverse of these.
tomwalters@0 266
tomwalters@0 267 A typical program might be as follows:
tomwalters@0 268 -------------------------------------
tomwalters@0 269 ------------------------------------------------------------------
tomwalters@0 270 |#include <stdio.h> |
tomwalters@0 271 |#include <math.h> |
tomwalters@0 272 | |
tomwalters@0 273 |#include "x11coord.h" |
tomwalters@0 274 | |
tomwalters@0 275 | |
tomwalters@0 276 |main() |
tomwalters@0 277 |{ |
tomwalters@0 278 | Window w; |
tomwalters@0 279 | ..... |
tomwalters@0 280 | |
tomwalters@0 281 | set_window_parameters(100,85, 775,775); |
tomwalters@0 282 | set_bordered_box(10); |
tomwalters@0 283 | set_data_parameters(50,50, 0,0, 2.0,2.0); |
tomwalters@0 284 | |
tomwalters@0 285 | xopen(); |
tomwalters@0 286 | w = xcreate("test", ButtonPressMask | ExposureMask); |
tomwalters@0 287 | xevent_monitor(w); |
tomwalters@0 288 |} |
tomwalters@0 289 | |
tomwalters@0 290 | |
tomwalters@0 291 |xevent_monitor(w) |
tomwalters@0 292 |Window w; |
tomwalters@0 293 |{ |
tomwalters@0 294 | XEvent event; |
tomwalters@0 295 | |
tomwalters@0 296 | for ( ; ; ) { |
tomwalters@0 297 | XNextEvent(theDisplay,&event); |
tomwalters@0 298 | switch (event.type) { |
tomwalters@0 299 | .... |
tomwalters@0 300 | case ButtonPress: |
tomwalters@0 301 | switch(event.xbutton.button) { |
tomwalters@0 302 | case Button1: |
tomwalters@0 303 | XDestroyWindow(theDisplay,w); |
tomwalters@0 304 | return; |
tomwalters@0 305 | case Button2: |
tomwalters@0 306 | .... |
tomwalters@0 307 | } |
tomwalters@0 308 | break; |
tomwalters@0 309 | case Expose: |
tomwalters@0 310 | if (event.xexpose.count == 0) { |
tomwalters@0 311 | draw_calibrated_box(w); |
tomwalters@0 312 | plot(w); |
tomwalters@0 313 | } |
tomwalters@0 314 | break; |
tomwalters@0 315 | .... |
tomwalters@0 316 | } |
tomwalters@0 317 | } |
tomwalters@0 318 |} |
tomwalters@0 319 | |
tomwalters@0 320 ------------------------------------------------------------------
tomwalters@0 321 The purpose of the xevent_monitor is to loop endlessly and keep the program
tomwalters@0 322 running while the window is displayed. The window vanishes when the monitor
tomwalters@0 323 is quit using (in this example) the left mouse button.
tomwalters@0 324 Note that you let all plotting routines be called when an expose-event has
tomwalters@0 325 been caught. This is not just so that the screen re-draws itself when exposed,
tomwalters@0 326 but also to avoid data at the start of the plot going missing.
tomwalters@0 327 If you don't set up for expose-events, but try to plot data as soon as the
tomwalters@0 328 window is created, then it turns out that you tend to lose the first few bytes
tomwalters@0 329 of plot data. The correct way is to plot data when the window is exposed.
tomwalters@0 330 The window-creation and mapping process generates an expose event
tomwalters@0 331 automatically and, when caught by the event monitor, this causes the window to
tomwalters@0 332 be first plotted.
tomwalters@0 333
tomwalters@0 334
tomwalters@0 335 *****************************************************************************/
tomwalters@0 336 #include <X11/X.h> /* /usr/include/X11/X.h */
tomwalters@0 337 #include <X11/Xlib.h> /* /usr/include/X11/Xlib.h */
tomwalters@0 338
tomwalters@0 339
tomwalters@0 340 static char defFontString[] = "fixed" , *theFontString = defFontString ;
tomwalters@0 341
tomwalters@0 342
tomwalters@0 343 /****************************************************************************
tomwalters@0 344 * Defaults for some standard window sizes
tomwalters@0 345 ****************************************************************************/
tomwalters@0 346 #define FULLXORG 5 /* Full screen size */
tomwalters@0 347 #define FULLYORG 90
tomwalters@0 348 #define FULLWIDTH 1000
tomwalters@0 349 #define FULLHEIGHT 750
tomwalters@0 350
tomwalters@0 351 #define A4XORG 190 /* A4 size */
tomwalters@0 352 #define A4YORG 85
tomwalters@0 353 #define A4WIDTH 620
tomwalters@0 354 #define A4HEIGHT 760
tomwalters@0 355
tomwalters@0 356 #define PLOTXORG 100 /* Rectangular plotting area */
tomwalters@0 357 #define PLOTYORG 155
tomwalters@0 358 #define PLOTWIDTH 800
tomwalters@0 359 #define PLOTHEIGHT 600
tomwalters@0 360
tomwalters@0 361 #define BOXXORG 100 /* Square box */
tomwalters@0 362 #define BOXYORG 85
tomwalters@0 363 #define BOXWIDTH 775
tomwalters@0 364 #define BOXHEIGHT 775
tomwalters@0 365
tomwalters@0 366 /****************************************************************************
tomwalters@0 367 * Macros for pixel-data transformation
tomwalters@0 368 ****************************************************************************/
tomwalters@0 369 /* pixel coord from data coord */
tomwalters@0 370 #define px(x) ( (int)(_xoffset + (x) * _xscale) )
tomwalters@0 371 #define py(y) ( (int)(_yoffset - (y) * _yscale) )
tomwalters@0 372 /* data coord from pixel coord */
tomwalters@0 373 #define xp(p) ( (float)(((p) - _xoffset) / _xscale) )
tomwalters@0 374 #define yp(p) ( (float)((_yoffset - (p)) / _yscale) )
tomwalters@0 375 /* data coord from a %age of data range */
tomwalters@0 376 #define xpc(pc) ( ((xleft()+xright())*pc) / 100 )
tomwalters@0 377 #define ypc(pc) ( ((ybottom()+ytop())*pc) / 100 )
tomwalters@0 378 /* data coord of box centre */
tomwalters@0 379 #define xcentre() xpc(50)
tomwalters@0 380 #define ycentre() ypc(50)
tomwalters@0 381 /* pixel limits of box (note that ptop() < pbottom() ). */
tomwalters@0 382 #define pleft() (_Xp0)
tomwalters@0 383 #define pright() (_Xp1)
tomwalters@0 384 #define pbottom() (_Yp0)
tomwalters@0 385 #define ptop() (_Yp1)
tomwalters@0 386 #define pwidth() (_Wb)
tomwalters@0 387 #define pheight() (_Hb)
tomwalters@0 388 /* data limits of box */
tomwalters@0 389 #define xleft() xp(_Xp0)
tomwalters@0 390 #define xright() xp(_Xp1)
tomwalters@0 391 #define ybottom() yp(_Yp0)
tomwalters@0 392 #define ytop() yp(_Yp1)
tomwalters@0 393 #define xwidth() xp(_Wb)
tomwalters@0 394 #define yheight() yp(_Hb)
tomwalters@0 395 /* test if data argument is in box */
tomwalters@0 396 #define Xinbox(x) ( (xleft()<=x && x<=xright()) ? 1 : 0 )
tomwalters@0 397 #define Yinbox(y) ( (ybottom()<=y && y<=ytop()) ? 1 : 0 )
tomwalters@0 398 #define inbox(x,y) ( (Xinbox(x) && Yinbox(y)) ? 1 : 0 )
tomwalters@0 399 /* jitter data value (ie move by a given pixel distance) */
tomwalters@0 400 #define Xjitter(x,p) ( xp(px(x)+(p)) )
tomwalters@0 401 #define Yjitter(y,p) ( yp(py(y)+(p)) )
tomwalters@0 402
tomwalters@0 403 /****************************************************************************
tomwalters@0 404 * Macros for routines (using preset system parameters)
tomwalters@0 405 ****************************************************************************/
tomwalters@0 406 /* Xaxes: yval is a data value at which to place a horizontal axis. */
tomwalters@0 407 /* For example: 0 (zero line), ybottom() (box-bottom), ytop() (box-top). */
tomwalters@0 408 #define draw_Xaxis(w,yval) if (Yinbox(yval)) axis(w, _Xp0,_Xp1, py(yval),'x')
tomwalters@0 409 #define calibrate_Xaxis(w,yval) calibrate_Axis(w, _Xp0,_Xp1, _Xd0,_Xd1, py(yval),'x')
tomwalters@0 410
tomwalters@0 411 /* Yaxes: xval is a data value at which to place a vertical axis. */
tomwalters@0 412 /* For example: 0 (zero line), xleft() (box-left), xright() (box-right). */
tomwalters@0 413 #define draw_Yaxis(w,xval) if (Xinbox(xval)) axis(w, _Yp0,_Yp1, px(xval),'y')
tomwalters@0 414 #define calibrate_Yaxis(w,xval) calibrate_Axis(w, _Yp0,_Yp1, _Yd0,_Yd1, px(xval),'y')
tomwalters@0 415
tomwalters@0 416 #define draw_box(w) box(w, _Xp0,_Yp0, _Xp1,_Yp1)
tomwalters@0 417 #define calibrate_box(w) calibrate_Box(w, _Xp0,_Yp0, _Xp1,_Yp1, _Xd0,_Yd0, _Xd1,_Yd1)
tomwalters@0 418 #define draw_calibrated_box(w) draw_box(w); calibrate_box(w)
tomwalters@0 419
tomwalters@0 420 #define xcreate(name,mask) xCreate(name,mask, _xorg,_yorg, _width,_height)
tomwalters@0 421
tomwalters@0 422 /****************************************************************************
tomwalters@0 423 * Macros for standard X11 commands
tomwalters@0 424 ****************************************************************************/
tomwalters@0 425 #define Point(w,x,y) XDrawPoint(theDisplay,w,theGC,px(x),py(y))
tomwalters@0 426 #define Line(w,x1,y1,x2,y2) XDrawLine(theDisplay,w,theGC,px(x1),py(y1),px(x2),py(y2))
tomwalters@0 427 #define String(w,x,y,string) XDrawString(theDisplay, w, theGC, px(x),py(y), string, strlen(string))
tomwalters@0 428
tomwalters@0 429 #define Cross(w,x,y) XDrawLine(theDisplay,w,theGC,px(x)-10,py(y),px(x)+10,py(y)); XDrawLine(theDisplay,w,theGC,px(x),py(y)-10,px(x),py(y)+10)
tomwalters@0 430
tomwalters@0 431 #define xPoint(w,x,y) if (inbox(x,y)) Point(w,x,y)
tomwalters@0 432 #define xLine(w,x1,y1,x2,y2) if (inbox(x1,y1) && inbox(x2,y2)) Line(w,x1,y1,x2,y2)
tomwalters@0 433 #define xString(w,x,y,string) if (inbox(x,y)) String(w,x,y,string)
tomwalters@0 434
tomwalters@0 435 #define xCross(w,x,y) if (inbox(x,y)) Cross(w,x,y)
tomwalters@0 436 #define xDot(w,x,y,dotsize) if (inbox(x,y)) Dot(w,x,y,dotsize)
tomwalters@0 437
tomwalters@0 438 /* Max width and height (pixels) of chars in current font, (ref 6-17, 6-19) */
tomwalters@0 439 #define max_charwidth() ( theFont->max_bounds.rbearing - theFont->min_bounds.lbearing )
tomwalters@0 440 #define max_charheight() ( theFont->max_bounds.ascent + theFont->max_bounds.descent )
tomwalters@0 441 /* Number of lines and cols (chars) of current font which fit into box */
tomwalters@0 442 #define linespacing() ( (theFont->max_bounds.descent)>>1 )
tomwalters@0 443 #define lineheight() ( max_charheight()+linespacing() )
tomwalters@0 444 #define colwidth() ( max_charwidth() )
tomwalters@0 445 #define nlines() ( pheight() / lineheight() )
tomwalters@0 446 #define ncols() ( pwidth() / colwidth() )
tomwalters@0 447 #define topline(w,string) lineString(w,string,1,1)
tomwalters@0 448 #define bottomline(w,string) lineString(w,string,nlines(),1)
tomwalters@0 449 #define margin() ( theFont->max_bounds.lbearing + theFont->max_bounds.rbearing )
tomwalters@0 450 #define headroom() ( theFont->max_bounds.ascent )
tomwalters@0 451 #define leftmargin() ( pleft() + margin() )
tomwalters@0 452 #define rightmargin() ( pright() - margin() )
tomwalters@0 453 #define topmargin() ( ptop() + headroom() )
tomwalters@0 454 #define bottommargin() ( pbottom() - headroom() )
tomwalters@0 455 #define line(i) ( topmargin() + (i-1)*lineheight() )
tomwalters@0 456 #define col(j) ( leftmargin() + (j-1)*colwidth() )
tomwalters@0 457 #define lineString(w,string,i,j) ( XDrawString(theDisplay,w,theGC,col(j),line(i),string,strlen(string)) )
tomwalters@0 458 #define leftString(w,string,i) ( XDrawString(theDisplay,w,theGC,leftmargin(),line(i),string,strlen(string)) )
tomwalters@0 459 #define rightString(w,string,i) ( XDrawString(theDisplay,w,theGC,rightmargin()-stringwidth(string),line(i),string,strlen(string)) )
tomwalters@0 460 #define centreString(w,string,i) ( XDrawString(theDisplay,w,theGC,(pwidth()-stringwidth(string))>>1,line(i),string,strlen(string)) )
tomwalters@0 461 #define supertopline(w,string) ( XDrawString(theDisplay,w,theGC,col(1),ptop()-max_charheight()-headroom(),string,strlen(string)) )
tomwalters@0 462
tomwalters@0 463
tomwalters@0 464 /****************************************************************************
tomwalters@0 465 * Window parameters (X11-specific).
tomwalters@0 466 ****************************************************************************/
tomwalters@0 467 Display *theDisplay;
tomwalters@0 468 int theScreen; /* screen_number */
tomwalters@0 469 int theWidth; /* horizontal size, in pixels */
tomwalters@0 470 int theHeight; /* vertical size, in pixels */
tomwalters@0 471 unsigned long theForeground; /* lines, text, and border pixel value */
tomwalters@0 472 unsigned long theBackground; /* background pixel value */
tomwalters@0 473 GC theGC; /* graphics context */
tomwalters@0 474 XFontStruct *theFont; /* current font used to print text */
tomwalters@0 475 unsigned long theBlack; /* pixel value for black */
tomwalters@0 476 unsigned long theWhite; /* pixel value for white */
tomwalters@0 477
tomwalters@0 478 /****************************************************************************
tomwalters@0 479 * System (global) variables
tomwalters@0 480 *****************************************************************************/
tomwalters@0 481 int _xorg, _yorg; /* Window origin (pixel coords top-left wrt Display)*/
tomwalters@0 482 int _width, _height;/* Window size (pixels). */
tomwalters@0 483
tomwalters@0 484 int _Xp0, _Yp0; /* Box origin (pixel coords at bottom-left) */
tomwalters@0 485 int _Xp1, _Yp1; /* Box limits (pixel coords at top-right) */
tomwalters@0 486 int _Wb, _Hb; /* Box size (pixels). */
tomwalters@0 487
tomwalters@0 488 float _Xd0, _Yd0; /* Box origin (data coords at bottom-left) */
tomwalters@0 489 float _Xd1, _Yd1; /* Box limits (data coords at top-right) */
tomwalters@0 490 float _xrange,_yrange;/* Box size (data ranges). */
tomwalters@0 491
tomwalters@0 492 int _xshift,_yshift;/* Plot origin (pixel coords from box origin) */
tomwalters@0 493 float _xd0, _yd0; /* Data coords fixed at plot origin */
tomwalters@0 494
tomwalters@0 495 float _xoffset,_yoffset;
tomwalters@0 496 float _xscale, _yscale;
tomwalters@0 497
tomwalters@0 498 /****************************************************************************
tomwalters@0 499 * Functions (in x11coord.c)
tomwalters@0 500 *****************************************************************************/
tomwalters@0 501 extern set_window_parameters();
tomwalters@0 502 extern set_box_parameters();
tomwalters@0 503 extern set_bordered_box();
tomwalters@0 504 extern set_data_parameters();
tomwalters@0 505 extern xopen();
tomwalters@0 506 extern GC initGC();
tomwalters@0 507 extern setLinewidth();
tomwalters@0 508 extern setFont();
tomwalters@0 509 extern Window xCreate();
tomwalters@0 510 extern axis();
tomwalters@0 511 extern box();
tomwalters@0 512 extern calibrate_Axis();
tomwalters@0 513 extern calibrate_Box();
tomwalters@0 514 extern plotX();
tomwalters@0 515 extern plotY();
tomwalters@0 516 extern int stringwidth();
tomwalters@0 517 extern int stringheight();
tomwalters@0 518 extern calibrate();
tomwalters@0 519 extern Dot();
tomwalters@0 520