| 1 |
<HTML> |
| 2 |
|
| 3 |
<HEAD> |
| 4 |
|
| 5 |
<TITLE> ACEDB source code documentation: the graph library </TITLE> |
| 6 |
|
| 7 |
<LINK rel=stylesheet type="text/css" |
| 8 |
href="./wdoc.css" |
| 9 |
title="Style sheet for wdoc developer documents"> |
| 10 |
|
| 11 |
</HEAD> |
| 12 |
|
| 13 |
<BODY> |
| 14 |
|
| 15 |
<H1>Application programmers' guide to the graph library</H1> |
| 16 |
|
| 17 |
<H3>Who should read this document</H3> |
| 18 |
This document is for application programmers who wish to |
| 19 |
use <B>Version 1</B> of the graph package to implement GUI's, it |
| 20 |
covers the public interface to the package, the internals of the graph package |
| 21 |
are not discussed in detail. |
| 22 |
<P> |
| 23 |
Although variants of the Version 1 package do exist for the Macintosh and for |
| 24 |
Windows, areas specific to these operating systems (e.g. how to build an |
| 25 |
application) are not covered in this document. This document covers the graph |
| 26 |
package in general and how to build applications in the unix environment only. |
| 27 |
<P> |
| 28 |
The document covers Version 1 of the graph package which will be frozen |
| 29 |
from ACEDB release 4 onwards. A new version of the graph package, Version 2, |
| 30 |
will be developed from ACEDB release 5, which will make use of the |
| 31 |
<A href="http://www.freiburg.linux.de/~wxxt/">wxWindows</A> |
| 32 |
package to implement better windows support for Unix, MS windows |
| 33 |
and the Macintosh. This package is C++ based and will require applications to |
| 34 |
compile their main functions with a C++ compiler and then use the C++ compiler |
| 35 |
to link the final application to ensure that the C++ environment is correctly |
| 36 |
set up. |
| 37 |
|
| 38 |
<H2>Introduction</H2> |
| 39 |
<P> |
| 40 |
The graph package provides a device independent ANSI-C library of |
| 41 |
subroutines for access to graphical user interfaces. It was |
| 42 |
developed by Richard Durbin and Jean Thierry-Mieg for the ACEDB |
| 43 |
genomic database program. Originally the graph program was intimately linked |
| 44 |
to ACEDB but in a recent development the ACEDB specific code has been moved |
| 45 |
from the graph package so that it has become a stand alone library (it is |
| 46 |
currently used like this in the Image gel slab analysis package). Applications |
| 47 |
needing to use both ACEDB and the graph package can use the |
| 48 |
<A href="http://www.sanger.ac.uk/Software/Acedb/Acedocs/sourcedocs/graphAcedbInterface.html"> |
| 49 |
ACEDB-graph interface package</A> |
| 50 |
to initialise the graph/acedb interface. |
| 51 |
|
| 52 |
<P> |
| 53 |
Currently there are three main versions of the graph package: |
| 54 |
<UL> |
| 55 |
<LI>The unix version which can be used to output to an X window, |
| 56 |
a Postscript file or to a gif file. |
| 57 |
<LI>The Macintosh version, this is in need of major work to bring it up |
| 58 |
to date. |
| 59 |
<LI>The Windows version, which is up to date but supports output only to an MS |
| 60 |
window currently. |
| 61 |
</UL> |
| 62 |
Only the unix version is dicussed in detail here. |
| 63 |
<P> |
| 64 |
There is an example program graphtest.c which shows how to use the graph |
| 65 |
package. |
| 66 |
|
| 67 |
|
| 68 |
<H2>Using the Graph library</H2> |
| 69 |
|
| 70 |
<H3>Initialisation & termination</H3> |
| 71 |
The graph library follows the initialisation protocol of X Windows |
| 72 |
and other graphical libraries in that |
| 73 |
the graph library <B>must be initialised</B> before use. This is |
| 74 |
done with a single call to the function <CODE>graphInit()</CODE>, |
| 75 |
<B>note</B> that further calls to graphInit will produce undefined |
| 76 |
results, i.e. <B>don't do it</B>. <CODE>graphInit()</CODE> sets up |
| 77 |
the connection to the display and this must only be done once. You |
| 78 |
should also note that calls to graph functions will produce undefined |
| 79 |
results if <CODE>graphInit()</CODE> has not been called. Currently it |
| 80 |
is not safe to have multiple sequences of <CODE>graphInit(), |
| 81 |
graphFinish()</CODE>: |
| 82 |
<PRE> |
| 83 |
{ |
| 84 |
some code |
| 85 |
|
| 86 |
<CODE> graphInit()</CODE> |
| 87 |
|
| 88 |
some code |
| 89 |
|
| 90 |
<CODE> graphFinish()</CODE> |
| 91 |
|
| 92 |
some code |
| 93 |
|
| 94 |
<CODE> graphInit()</CODE> |
| 95 |
|
| 96 |
some code |
| 97 |
|
| 98 |
<CODE> graphFinish()</CODE> |
| 99 |
} |
| 100 |
</PRE> |
| 101 |
This will fail, the graph package is not stateless and cannot |
| 102 |
be shut down and then reinitialised in the same application. |
| 103 |
<P> |
| 104 |
The graph package should be closed down by calling <CODE>graphFinish()</CODE>, |
| 105 |
this is particularly important if the application makes use of other |
| 106 |
facilities such as messubs to issue messages and needs to send messages to |
| 107 |
stdout after the connection to the display has been closed. |
| 108 |
<CODE>graphFinish()</CODE> will tidy up its links with these other packages so |
| 109 |
that they will continue to function as they did before graph initialisation. |
| 110 |
|
| 111 |
<H3>Basic concepts - handles and drawing</H3> |
| 112 |
<P> |
| 113 |
The basic concept is that each window has associated with it a Graph |
| 114 |
object. The window is made with graphCreate(), which returns the |
| 115 |
Graph handle. Items such as lines and text are drawn onto a drawing |
| 116 |
stack attached to the handle, which is then used to draw those parts |
| 117 |
of the graph that are currently visible. (Of course this changes |
| 118 |
when, e.g. an obscuring window is removed.) The stack can also be |
| 119 |
used to provide postscript or gif output. Note that because the drawing |
| 120 |
commands go to the stack, a call to graphRedraw() is necessary at |
| 121 |
the end of drawing to display material on the screen, the normal sequence will |
| 122 |
be something like: |
| 123 |
<PRE><CODE> |
| 124 |
graphBox(params) ; |
| 125 |
graphCircle(params) ; |
| 126 |
graphMenu(params) ; |
| 127 |
|
| 128 |
graphRedraw(params) ; |
| 129 |
|
| 130 |
</CODE></PRE> |
| 131 |
|
| 132 |
<H3>Basic concepts - the active graph</H3> |
| 133 |
At any one time there is one active graph. Almost all |
| 134 |
the functions in the package act on the active graph. The active |
| 135 |
graph can be changed explicitly using graphActivate(), but most |
| 136 |
changes are implicitly determined by user actions: when events |
| 137 |
occur, such as mouse clicks, keyboard typing, or menu selections, |
| 138 |
the window in which they took place is made active and a call is |
| 139 |
made to a callback function. Callback functions are registered with |
| 140 |
the graph package via graphRegister() when the graph is created. |
| 141 |
|
| 142 |
<H3>Basic concepts - user coordinates</H3> |
| 143 |
User coordinates: All drawing and communication with respect to |
| 144 |
position is in a user coordinate system, normally with units |
| 145 |
corresponding to single characters (TEXT_FIT and TEXT_SCROLL graph |
| 146 |
types - see graphCreate()). |
| 147 |
|
| 148 |
<H3>Basic concepts - text boxes</H3> |
| 149 |
The graph package provides a number of styles of text editting boxes which allow |
| 150 |
the application to get information in the form of strings from the user, this |
| 151 |
includes the usual cut/paste of text. There are two very important points to |
| 152 |
remember about using these text boxes: |
| 153 |
<OL> |
| 154 |
<LI>The application must allocate <B>and</B> hold on to the text buffer |
| 155 |
used by any graph text box until that graph text box is destroyed. |
| 156 |
<LI>The length supplied in the call to create the graph text box is the length |
| 157 |
(in bytes) of the whole buffer, this means that the user will be allowed to enter |
| 158 |
a maximum of (length - 1) characters into the text box, one byte must |
| 159 |
be reserved for the terminating null character of the string. |
| 160 |
</OL> |
| 161 |
|
| 162 |
|
| 163 |
<H3>Basic concepts - boxes</H3> |
| 164 |
A fundamental concept during drawing is that one or more |
| 165 |
drawing items can be bundled together into a box. This is done by |
| 166 |
surrounding the drawing calls with graphBoxStart() and graphBoxEnd() |
| 167 |
calls. Boxes can be nested. Each box has a unique identifier |
| 168 |
within its graph. These are consecutive integers, starting at 0: the |
| 169 |
whole drawing space is box 0. Each box keeps track of its limits, |
| 170 |
which are defined by the maximum extent of its contents. There are |
| 171 |
two main uses of boxes: (1) they can be independently redrawn with |
| 172 |
new background and foreground colours using graphBoxDraw(), (2) a |
| 173 |
PICK pseudoevent can be registered via graphRegister(), which causes |
| 174 |
the graph package to find which box a LEFT_MOUSE_DOWN event has |
| 175 |
occurred in, and pass this as a parameter to the registered. It is |
| 176 |
these two properties that allow selected items to be highlighted, |
| 177 |
and followed in a hypertext like fashion. |
| 178 |
|
| 179 |
<H3>Basic concepts - interrupting long operations</H3> |
| 180 |
The graph package provides two different interrupt handlers allowing the user to |
| 181 |
interrupt long operations: |
| 182 |
<DL> |
| 183 |
<DT>Signal based |
| 184 |
<DD>This interrupt uses the ANSI standard SIGINT signal to stop the program |
| 185 |
regardless of what it is doing. The signal is initiated by the user |
| 186 |
pressing the 'interrupt' key on their keyboard (BREAK or CTRL-C). The |
| 187 |
graph package will then give the user the chance to abort or continue |
| 188 |
where they left off. |
| 189 |
<DT>Key based |
| 190 |
<DD>This interrupt is based on the graph package detecting that the user |
| 191 |
has pressed the F4 key, this is done by monitoring the keys pressed |
| 192 |
and hence will not interrupt a program that is looping or busy processing |
| 193 |
some data. The precise action taken by the graph package will depend on |
| 194 |
which part of the application is being executed at the time. |
| 195 |
</DL> |
| 196 |
|
| 197 |
<H3>Basic concepts - the routines</H3> |
| 198 |
There are some 60 routines, which are listed alphabetically with |
| 199 |
notes at the end, but can be divided into several classes: |
| 200 |
<PRE> |
| 201 |
Initialisation/Cleanup: |
| 202 |
graphInit(), graphFinish(), - initialise/terminate graph package |
| 203 |
graphCleanUp() - kills all but one graph |
| 204 |
|
| 205 |
|
| 206 |
Event loop control: |
| 207 |
graphLoop() - start loop |
| 208 |
graphLoopReturn() - end loop |
| 209 |
graphProcessEvents() - process all pending X events |
| 210 |
|
| 211 |
Management of individual graphs: |
| 212 |
graphCreate(), graphDestroy() - creation/destruction |
| 213 |
graphActive(), graphActivate(), graphExists() |
| 214 |
- set/test the active graph |
| 215 |
graphRetitle() - change title of a graph |
| 216 |
graphPop() - deiconify and raise |
| 217 |
graphEvent() - create pseudo-event to go in loop |
| 218 |
graphRegister() - set up callback functions |
| 219 |
graphMenu(), graphFreeMenu() - add a menu (graphMenu preferred) |
| 220 |
|
| 221 |
Association of extra properties with the graph: |
| 222 |
graphAssociate(), graphAssFind(), graphAssRemove() |
| 223 |
|
| 224 |
Coordinate system management: |
| 225 |
graphTextBounds(), graphFitBounds(), graphPlainBounds() |
| 226 |
graphTextInfo(), graphScreenSize() |
| 227 |
graphGoto() |
| 228 |
|
| 229 |
Global drawing management: |
| 230 |
graphClear() |
| 231 |
graphRedraw() - draw stack on screen |
| 232 |
graphPS(), graphPrint() - postscript |
| 233 |
|
| 234 |
Basic drawing commands (go on stack): |
| 235 |
graphLine(), graphRectangle(), graphFillRectangle() |
| 236 |
graphCircle(), graphText(), graphTextPtr() |
| 237 |
graphPoint() - small square |
| 238 |
|
| 239 |
Drawing status control (go on stack): |
| 240 |
graphLinewidth(), graphPointsize(), |
| 241 |
graphTextHeight(), graphFontFormat(), - FontFormat is new |
| 242 |
graphColor() |
| 243 |
|
| 244 |
Box control: |
| 245 |
graphBoxStart(), graphBoxEnd() |
| 246 |
graphBoxDraw() |
| 247 |
graphBoxClear() |
| 248 |
graphBoxDim() - to get back box location/size |
| 249 |
graphBoxDrag(), graphBoxShift() |
| 250 |
graphBoxSetPick() - toggle pickability |
| 251 |
|
| 252 |
Complex prepackaged boxes: |
| 253 |
graphTextEntry(), graphTextScrollEntry, |
| 254 |
graphCompletionEntry(), graphCompletionScrollEntry(), |
| 255 |
graphEntryDisable() |
| 256 |
graphButton(), graphButtons(), graphColouredButton(), graphColouredButtons() |
| 257 |
|
| 258 |
XOR functions (not on stack): |
| 259 |
graphXorLine(), graphXorBox() |
| 260 |
|
| 261 |
Message windows: |
| 262 |
graphMessage(), graphUnMessage() - non-blocking message, use graphUnMessage |
| 263 |
to remove it |
| 264 |
graphOut() - blocking message with OK button |
| 265 |
graphError() - blocking message with OK button |
| 266 |
graphEnd() - blocking message with EXIT button |
| 267 |
graphQuery() - blocking yes/no query |
| 268 |
graphPrompt() - blocking request for data |
| 269 |
graphSelect() - blocking forced choice |
| 270 |
</PRE> |
| 271 |
|
| 272 |
<H3>Basic concepts - the source files</H3> |
| 273 |
Broadly speaking the various graph source files contain the following code: |
| 274 |
<PRE> |
| 275 |
graph.h public header file |
| 276 |
graphcon.c, graphsub.c display-method independent code |
| 277 |
graphps.c graphprint.c postscript creation/print code |
| 278 |
graphxt.c, graphxlib.c, xtsubs.c X-dependent code |
| 279 |
gifsubs.c, graphgd.c gif code |
| 280 |
filquery.c file query box implementation |
| 281 |
graphhelp.c, graphxwww.c, xnetscape_remote.c |
| 282 |
help display, browser control code |
| 283 |
chrono.c source code profiling code |
| 284 |
viewedit.c control display of various types of graph |
| 285 |
graphselect.c provides lists of items to be selected |
| 286 |
graphAcedbInterface.c acedb/graph interface code |
| 287 |
colcontrol.c controls layout of columns in fmap etc. |
| 288 |
graphramp.c control intensity of a greyscale image. |
| 289 |
</PRE> |
| 290 |
|
| 291 |
|
| 292 |
<H2>Building an application using the Graph library</H2> |
| 293 |
<P> |
| 294 |
Although the graph package can be built independently of ACEDB, it does |
| 295 |
require some of the packages also used by ACECB: |
| 296 |
<UL> |
| 297 |
<LI>the array package (arraysub.c, array.h) |
| 298 |
<LI>the utilities package (libfree.a) |
| 299 |
</UL> |
| 300 |
The <CODE>.h</CODE> files are required for compilation of the application and |
| 301 |
the module arraysubs.o and the library libfree.a are required for the final |
| 302 |
linking of the application. |
| 303 |
|
| 304 |
<P> |
| 305 |
Graph applications can either be built that write to an X window or |
| 306 |
to a gif file, it is not possible to do both from the same application |
| 307 |
(writing to a postscript file or printed is possible from either type of |
| 308 |
application). |
| 309 |
Building either application requires the basic graph library (libgraph.a), and |
| 310 |
this is combined with other object modules to give either the X windows or gif |
| 311 |
flavour of the final library. The makefile (<CODE>truemake</CODE>) distributed |
| 312 |
with acedb gives examples of how to build an X windows application (e.g. xace) |
| 313 |
or a gif application (e.g. giface). |
| 314 |
|
| 315 |
|
| 316 |
<H2>The Graph Interface</H2> |
| 317 |
|
| 318 |
<H3>Graph graphActive (void)</H3> |
| 319 |
Returns the handle for the currently active graph. This is |
| 320 |
normally used in a subsequent graphActivate() call. |
| 321 |
|
| 322 |
<H3>BOOL graphActivate (Graph g)</H3> |
| 323 |
If graphExists(g) then it makes g the active graph and returns |
| 324 |
TRUE, else returns FALSE. |
| 325 |
|
| 326 |
<H3>BOOL graphActivateChild (void)</H3> |
| 327 |
Attempts to make the child of the currently active graph the new active graph, |
| 328 |
returns TRUE if successful, FALSE otherwise. |
| 329 |
|
| 330 |
<H3>BOOL graphArc (float xcen, float yxen, float rad, |
| 331 |
float ang, float angDiff)</H3> |
| 332 |
Draws an arc of the specified length, note degrees are anticlockwise from 3 o'clock. |
| 333 |
|
| 334 |
<H3>BOOL graphAssociate (void* xin, void* xout)</H3> |
| 335 |
Uses the associator package (see the arraysubs utilities) to |
| 336 |
associate xin to xout for the active graph. It will return FALSE |
| 337 |
and do nothing if there is already an entry for xin (use |
| 338 |
graphAssRemove() first), otherwise it makes the association and |
| 339 |
returns TRUE. |
| 340 |
<P> |
| 341 |
This function can be used to attach an arbitrary number of new |
| 342 |
attributes to a graph, by giving each an identifier that is used as |
| 343 |
xin. |
| 344 |
<P> |
| 345 |
Implemented via a macro so that the compiler is not so fussy about |
| 346 |
the void* argument typing (well what can you say...sigh). |
| 347 |
|
| 348 |
<H3>BOOL graphAssFind (void* xin, void* *pxout)</H3> |
| 349 |
If xin has been associated with the active graph using |
| 350 |
graphAssociate(), then it sets *pxout and returns TRUE, else |
| 351 |
returns FALSE. |
| 352 |
|
| 353 |
<H3>BOOL graphAssRemove (void *in)</H3> |
| 354 |
If xin has been associated with the active graph using |
| 355 |
graphAssociate(), then it removes the entry and returns TRUE, else |
| 356 |
returns FALSE. |
| 357 |
|
| 358 |
<H3>void graphBoundsPrint (float uw, float uh, void (*draw)(void))</H3> |
| 359 |
Allow caller to set special page sizes for multipage prints. |
| 360 |
|
| 361 |
<H3>void graphBoxAt (float x, float y, float *rx, float *ry)</H3> |
| 362 |
Returns id of box at given graph coordinates. |
| 363 |
|
| 364 |
<H3>void graphBoxClear (int k)</H3> |
| 365 |
This is a toggle function. The first time it is called the box |
| 366 |
will be hidden, and the corresponding area of screen redrawn |
| 367 |
(possibly revealing material previously underneath). The next time |
| 368 |
the box will be restored and so on. Crashes if k is not a valid box id. |
| 369 |
|
| 370 |
<H3>void graphBoxDim (int k,float *x1, float *y1, |
| 371 |
float *x2, float *y2) </H3> |
| 372 |
This useful function returns in *x1, *x2, *y1, *y2 the bounds of |
| 373 |
box k in user coordinates. Crashes if k is not a valid box id. |
| 374 |
|
| 375 |
<H3>void graphBoxDrag (int k,void (*client)(float*,float*,BOOL)) </H3> |
| 376 |
Call this after a <CODE>LEFT_DOWN</CODE> or <CODE>MIDDLE_DOWN</CODE> button event that you |
| 377 |
want to use to allow the user to drag a box. The <CODE>LEFT</CODE> and <CODE>MIDDLE</CODE> |
| 378 |
<CODE>_DRAG</CODE> and <CODE>_UP</CODE> graphEvents are hijacked by this call (and restored at |
| 379 |
the end of the process). The box's outline will appear in XOR |
| 380 |
pixels until the drag process finishes (button <CODE>_UP</CODE>). An initial |
| 381 |
call is made to the client routine, with third arg <CODE>FALSE</CODE>, giving the |
| 382 |
current position of the top left corner of the box in user |
| 383 |
coordinates. For each <CODE>_DRAG</CODE> event a further call is made to the |
| 384 |
client routine, again with third argument <CODE>FALSE</CODE>. The client can |
| 385 |
change the values of <CODE>*x, *y</CODE>. e.g. keeping <CODE>*y</CODE> fixed forces dragging |
| 386 |
on a horizontal line. When the up button is reached the client will |
| 387 |
be called once more with the third argument set <CODE>TRUE</CODE>, to allow final |
| 388 |
processing to be performed. |
| 389 |
<P> |
| 390 |
NB If the user wants to move the contents of the box they must call |
| 391 |
graphBoxShift() explicitly during the final client invocation. |
| 392 |
<P> |
| 393 |
Crashes if k is not a valid box id. |
| 394 |
<P> |
| 395 |
Example: |
| 396 |
<PRE><CODE> |
| 397 |
static float cursorX ; |
| 398 |
|
| 399 |
void cursorDrag (float *x, float *y, BOOL isUp) |
| 400 |
{ |
| 401 |
*y = 2.0 ; /* horizontal dragging only */ |
| 402 |
if (isUp) |
| 403 |
{ cursorX = *x ; |
| 404 |
graphBoxShift (CURSOR_BOX, *x, *y) ; |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
void myPick (int k) |
| 409 |
{ |
| 410 |
switch (k) |
| 411 |
{ ... |
| 412 |
case CURSOR_BOX: |
| 413 |
graphBoxDrag (k, cursorDrag) ; |
| 414 |
break ; |
| 415 |
... |
| 416 |
} |
| 417 |
} |
| 418 |
</PRE></CODE> |
| 419 |
|
| 420 |
<H3>void graphBoxDraw (int k, int fcol, int bcol)</H3> |
| 421 |
A very fundamental routine. Box k is redrawn with the specified |
| 422 |
foreground and background colours. If fcol or bcol is negative the |
| 423 |
current value is used. This redraw is immediate (i.e. not placed on |
| 424 |
the event stack). It is used e.g. to highlight a box that has been |
| 425 |
picked. The colours fcol and bcol should be chosen from the list |
| 426 |
given in the graphColor() entry, with the addition that the |
| 427 |
pseudocolour TRANSPARENT can be used for the background. If the |
| 428 |
background is not TRANSPARENT it is painted solid bcol before |
| 429 |
drawing starts on the box. The foreground drawing colour can be |
| 430 |
reset within the box via graphColor(). Crashes if k is not a valid box id. |
| 431 |
|
| 432 |
<H3>void graphBoxEnd (void)</H3> |
| 433 |
Call during drawing to end the current box. Writes on the stack. |
| 434 |
|
| 435 |
<H3>void graphBoxMarkAsClear (int box)</H3> |
| 436 |
Marks a box for redrawing, actual redrawing is done when the current |
| 437 |
drawing commands are flushed. |
| 438 |
|
| 439 |
<H3>void graphBoxShift (int k, float xbase, float ybase)</H3> |
| 440 |
This translates the specified box so that its top left corner will |
| 441 |
go to (xbase, ybase) in user coordinates. Anything that was under |
| 442 |
the original box location will be redrawn. Subboxes will be moved with their parents. |
| 443 |
|
| 444 |
<H3>void graphBoxSetPick (int k, BOOL pick)</H3> |
| 445 |
If pick is FALSE this makes the box unpickable. i.e. a left mouse |
| 446 |
button down event inside it will not generate a call to the function |
| 447 |
registered with graphRegister(PICK,...). Calling with pick TRUE |
| 448 |
restores pickability. By default boxes are pickable. |
| 449 |
<P> |
| 450 |
Rather specialised, huh? |
| 451 |
|
| 452 |
<H3>int graphBoxStart (void)</H3> |
| 453 |
Call this during drawing to start a new box. All drawing commands |
| 454 |
between this call and the matching graphBoxEnd() will be assigned to |
| 455 |
the box. The return value is the id of the box (an integer starting |
| 456 |
at 1 - 0 is the background box). See the general introduction to |
| 457 |
boxes above. Writes on the stack. |
| 458 |
|
| 459 |
<H3>int graphButton (char* text, void (*f)(void),float x, float y)</H3> |
| 460 |
This creates a button containing the specified text with top left at |
| 461 |
location (x,y) in user coordinates. The button is a box (of |
| 462 |
course!). If it is picked the colour is inverted and your function |
| 463 |
f() is called. On return the colour is inverted back unless the |
| 464 |
window has been redrawn (there are sometimes minor bugs here, so |
| 465 |
that the button stays the wrong colour, but this is purely aesthetic |
| 466 |
- the function stays the same.) |
| 467 |
<P> |
| 468 |
To display several buttons in a row use graphButtons(). |
| 469 |
|
| 470 |
|
| 471 |
<H3>void graphButtons (MENUOPT *buttons,float x0, float y0, float xmax) </H3> |
| 472 |
Uses graphButton to display several buttons in a row, starting at |
| 473 |
(x0, y0). The line wraps if it extends beyond xmax. |
| 474 |
<P> |
| 475 |
The argument buttons is a null-terminated string of MENUOPT, which |
| 476 |
are (function, text) pairs (see graphMenu() for a lengthier |
| 477 |
definition of MENUOPT). |
| 478 |
|
| 479 |
<H3>void graphCircle (float xcen, float ycen, float rad)</H3> |
| 480 |
Draws a hollow circle in the current foreground colour. On the |
| 481 |
screen the perimeter has width 1 pixel, but in postscript it has |
| 482 |
width the current line width. |
| 483 |
<P> |
| 484 |
Writes on the stack. |
| 485 |
|
| 486 |
<H3>void graphCleanUp (void)</H3> |
| 487 |
Calls graphDestroy() for all graphs other than the current one. |
| 488 |
i.e. the "Clean Up" function from the ACEDB main menu. |
| 489 |
|
| 490 |
<H3>void graphClear (void)</H3> |
| 491 |
Empties the drawing stack and the box list for the active graph, |
| 492 |
clears the window on the screen, resets the drawing color to BLACK |
| 493 |
and the font to the standard font. |
| 494 |
|
| 495 |
<H3>STORE_HANDLE graphClearHandle (void)</H3> |
| 496 |
Returns the 'handle' by which the currently active graph is held. |
| 497 |
|
| 498 |
<H3>int graphColor (int color)</H3> |
| 499 |
This changes the current foreground drawing colour, with a scope of |
| 500 |
the current box. It is placed on the stack. The preferred way to |
| 501 |
control colour within boxes is using graphBoxDraw(), since anything |
| 502 |
following the graphColor() call will always be the specified colour, |
| 503 |
i.e. will not be changeable dynamically via graphBoxDraw(). |
| 504 |
graphColor() is normally used to draw features of different colours |
| 505 |
in the background that are non-pickable. |
| 506 |
<P> |
| 507 |
Allowed colours are from: |
| 508 |
<PRE><CODE> |
| 509 |
enum Colour {WHITE, BLACK, LIGHTGRAY, DARKGRAY, |
| 510 |
RED, GREEN, BLUE, |
| 511 |
YELLOW, CYAN, MAGENTA, |
| 512 |
LIGHTRED, LIGHTGREEN, LIGHTBLUE, |
| 513 |
DARKRED, DARKGREEN, DARKBLUE, |
| 514 |
} |
| 515 |
</PRE></CODE> |
| 516 |
|
| 517 |
<H3>int graphColouredButton(char* text, void (*f)(void *arg), void *arg, |
| 518 |
int fg, int bg, float x, float y)</H3> |
| 519 |
|
| 520 |
Like graphButton except that the foreground and background of the button |
| 521 |
are specified (by fg and bg) and the callback function receives an argument |
| 522 |
(specified by arg, this is a void *, so you can put a pointer to anything here, |
| 523 |
except a pointer to func.) |
| 524 |
|
| 525 |
<H3>void graphColouredButtons(COLOUROPT *buttons, float x0, float y0, float xmax)</H3> |
| 526 |
Like graphButtons but uses the COLOUROPT structure to specify |
| 527 |
button colours and callback arguments. |
| 528 |
<PRE><CODE> |
| 529 |
typedef struct colouropt |
| 530 |
{ void (*f)(void *arg); |
| 531 |
void *arg; |
| 532 |
int fg; |
| 533 |
int bg; |
| 534 |
char *text; |
| 535 |
struct colouropt *next; |
| 536 |
} COLOUROPT; |
| 537 |
</PRE></CODE> |
| 538 |
The arrangement and use of a COLOUROPT structure is somewhat idionsyncratic; |
| 539 |
this is because it is intended to represent both statically defined |
| 540 |
and dynamically built sets of buttons. |
| 541 |
|
| 542 |
The following rules interpret COLOUROPTS: |
| 543 |
1) To get to the next button; follow the next pointer, if the next pointer |
| 544 |
is zero, go to the next element in an array of COLOUROPTS. |
| 545 |
2) The last button is marked by having its next pointer equal to |
| 546 |
either the address originally passed to graphColouredButtons, |
| 547 |
or to the address of the last button's record, or having |
| 548 |
a NULL text field. |
| 549 |
3) Passing a NULL pointer to graphColouredButtons is legal, and |
| 550 |
denotes no buttons. |
| 551 |
|
| 552 |
This stucture is can be used with static arrays thus :- |
| 553 |
<PRE><CODE> |
| 554 |
static COLOUROPT buttons[] = { |
| 555 |
printf, "red", BLACK, LIGHTRED, "red button", 0, |
| 556 |
printf, "blue", BLACK, LIGHTBLUE, "blue button", 0, |
| 557 |
printf, "green", BLACK, GREEN, "green button", 0, |
| 558 |
printf, "yellow", BLACK, YELLOW, "yellow button", 0, |
| 559 |
printf, "cyan", BLACK, CYAN, "cyan button", 0, |
| 560 |
printf, "magenta", BLACK, MAGENTA, "magenta button", 0, |
| 561 |
printf, "gray", BLACK, LIGHTGRAY, "gray button", buttons |
| 562 |
}; |
| 563 |
</PRE></CODE> |
| 564 |
and to build linked lists thus :- |
| 565 |
<PRE><CODE> |
| 566 |
COLOUROPT *buttons = 0; |
| 567 |
COLOUROPT **p = &buttons; |
| 568 |
|
| 569 |
while (newbutton) { |
| 570 |
*p = malloc(sizeof(struct colouropt)); |
| 571 |
*p->next = *p; |
| 572 |
|
| 573 |
*p->text = ....... |
| 574 |
|
| 575 |
p = &(*p->next); |
| 576 |
|
| 577 |
} |
| 578 |
</PRE></CODE> |
| 579 |
|
| 580 |
<H3>int graphCompletionEntry (void (*gcf)(char*, int), |
| 581 |
char* cp, int len, float x, float y, void (*fn)(char*)) </H3> |
| 582 |
This creates a text entry box, using graphTextEntry(), with the |
| 583 |
addition that the TAB key will generate a call to the function gcf |
| 584 |
with arguments (cp, len). gcf should be used as a completion |
| 585 |
function - i.e. it will extend the text buffer cp if there is a |
| 586 |
unique extension in this context. We use it for completing names |
| 587 |
within a class -- see ksetClassComplete() and the examples in |
| 588 |
griddisp.c. |
| 589 |
|
| 590 |
<H3>int graphCompScrollEntry (GraphCompletionFunc f, char* text, |
| 591 |
int len, float x, float y, void (*fn)()) </H3> |
| 592 |
Similar to graphCompletionEntry() with changes in accordance to |
| 593 |
graphTextScrollEntry(). |
| 594 |
<P> |
| 595 |
See graphTextEntry(), graphCompletionEntry(), graphTextScrollEntry() |
| 596 |
|
| 597 |
|
| 598 |
<H3>BOOL graphContainedIn (Graph parent)</H3> |
| 599 |
Returns TRUE if the the currently active graph is a subgraph of the supplied graph. |
| 600 |
|
| 601 |
<H3>Graph graphCreate (int type, char *name, |
| 602 |
float x, float y, float w, float h)</H3> |
| 603 |
Creates a new window, which becomes the active window, and returns |
| 604 |
a handle for it. |
| 605 |
<P> |
| 606 |
name is used on the title bar. |
| 607 |
<P> |
| 608 |
x,y,w,h are the location on the screen in screen units. 1.0 = 900 |
| 609 |
pixels (typical height). Some window managers ignore x,y (e.g. |
| 610 |
twm). w and/or h may be negative, in which case the absolute value is |
| 611 |
taken to be the width or height in co-ordinate units, ie. size of |
| 612 |
default font for TEXT_* windows, and pixels for PIXEL_* windows. |
| 613 |
Note that this causes the pixel size of TEXT_* windows to change with |
| 614 |
changing font size. |
| 615 |
<P> |
| 616 |
type is from |
| 617 |
<PRE><CODE> |
| 618 |
enum GraphType { PLAIN, TEXT_SCROLL, TEXT_FIT, MAP_SCROLL, |
| 619 |
PIXEL_SCROLL, TEXT_FULL_SCROLL, PIXEL_FIT } ; |
| 620 |
</PRE></CODE> |
| 621 |
You are advised to use either TEXT_SCROLL or TEXT_FIT. Both these |
| 622 |
set the user coordinates to standard font character size. i.e. you |
| 623 |
give locations on the graph in character coords from top left = |
| 624 |
(0,0). graphTextInfo() will tell you the pixel dimensions of a |
| 625 |
character (and hence the aspect ratio). |
| 626 |
<P> |
| 627 |
TEXT_SCROLL gives a scroll bar, and lets you determine the height |
| 628 |
of the drawing area with graphTextBounds(). |
| 629 |
<P> |
| 630 |
A TEXT_FIT graph normally uses graphRegister(RESIZE,...) to |
| 631 |
register a RESIZE callback function, which then will call |
| 632 |
graphFitBounds() to find the current dimensions. |
| 633 |
<P> |
| 634 |
PLAIN lets you set the user bounds to anything you want using |
| 635 |
graphPlainBounds(). By default they are [0,1]x[0,1]. The user |
| 636 |
bounds fill the graph, however large on the screen. Resizing |
| 637 |
events are handled automatically, e.g. resizing the graph bigger |
| 638 |
will magnify its contents. It is essentially impossible to handle |
| 639 |
text well in a PLAIN graph, so they are limited to simple line |
| 640 |
drawings. |
| 641 |
<P> |
| 642 |
MAP_SCROLL was for a horizontally scrolling PLAIN type graph, but |
| 643 |
is now not used anywhere and should be treated as unsupported. |
| 644 |
<P> |
| 645 |
PIXEL_SCROLL is the type used for displaying background images using |
| 646 |
graphPixels() or graphPixelsRaw(). Using graphPixelBounds() you can |
| 647 |
set the drawing region which will activate scrollbars if this is |
| 648 |
bigger than the windowsize. graphWhere will tell you the coordinates |
| 649 |
of the currently visible section of the drawing field. You can't |
| 650 |
register a resize call with this graphType (use PIXEL_FIT) . |
| 651 |
<P> |
| 652 |
PIXEL_FIT is a graphType without scrollbars. It can be used |
| 653 |
for displaying images within fixed window dimensions. |
| 654 |
A resize register is possible for this type. |
| 655 |
|
| 656 |
<H3>void graphDestroy (void)</H3> |
| 657 |
Destroys the current active graph. If a DESTROY callback has been |
| 658 |
registered using graphRegister() that will be called from |
| 659 |
graphDestroy() while the graph is still active. |
| 660 |
|
| 661 |
<H3>void graphDisableBlock (void)</H3> |
| 662 |
Returns currently active graph to blockable state. |
| 663 |
|
| 664 |
<H3>void graphEnableBlock (void)</H3> |
| 665 |
Prevents currently active graph from being blocked by e.g. a blocking message. |
| 666 |
|
| 667 |
<H3>void graphEnd (char *text)</H3> |
| 668 |
Displays blocking message with button labelled "END", can be used for terminating |
| 669 |
an application gracefully (the application should call this routine from its own |
| 670 |
termination routine. |
| 671 |
|
| 672 |
<H3>void graphEntryDisable (void)</H3> |
| 673 |
Deactivates all text entry boxes. See graphTextEntry(). |
| 674 |
|
| 675 |
<H3>void graphError (char *text)</H3> |
| 676 |
Displays blocking message with button labelled "Continue", can be used for reporting |
| 677 |
non-fatal errors. |
| 678 |
|
| 679 |
<H3>void graphEvent (int action, float x, float y)</H3> |
| 680 |
This creates a false event that is placed on the event stack. The |
| 681 |
argument action may either be a GraphEvent value (see |
| 682 |
graphRegister()) or a printable character. In the latter case the |
| 683 |
event will be passed to the KEYBOARD callback routine, if one is |
| 684 |
registered via graphRegister(). (x, y) give the location in user |
| 685 |
coordinates of the pseudo-event. |
| 686 |
<P> |
| 687 |
Important: the event will not be processed immediately (i.e. before |
| 688 |
graphEvent() returns). It will be processed after control returns |
| 689 |
to the current event-handling loop, possibly after other itervening |
| 690 |
events. |
| 691 |
<P> |
| 692 |
NB graphEvent() may not work for all events for all implementations |
| 693 |
(the X version currently allows only mouse button up and down |
| 694 |
events and characters). |
| 695 |
|
| 696 |
<H3>BOOL graphExists (Graph g)</H3> |
| 697 |
Returns TRUE if g is a handle for an alive graph |
| 698 |
FALSE if g is not a handle, or has been destroyed. |
| 699 |
|
| 700 |
<H3>float graphFakeBounds (float ny)</H3> |
| 701 |
Sets the y size of a graph to be longer (perhaps for printing) and returns |
| 702 |
the old y size so application can reset to old size later. |
| 703 |
|
| 704 |
<H3>void graphFillArc (float xcen, float yxen, float rad, |
| 705 |
float ang, float angDiff)</H3> |
| 706 |
Draw a filled arc, note that angles are degrees anticlockwise from 3 o'clock. |
| 707 |
|
| 708 |
<H3>void graphFillRectangle (float x0, float y0, </H3> |
| 709 |
Draws a filled rectangle with opposite corners at (x0,y0), (x1,y1) |
| 710 |
in user coordinates, in the current foreground colour. |
| 711 |
<P> |
| 712 |
Writes on the stack. |
| 713 |
|
| 714 |
<H3>void graphFinish (void)</H3> |
| 715 |
Call at the end of the application to clean up the graphics |
| 716 |
properly. |
| 717 |
|
| 718 |
<H3>void graphFitBounds (int *nx, int *ny)</H3> |
| 719 |
For TEXT_FIT graph types only (see graphCreate()). Sets *nx, *ny, |
| 720 |
reporting on how many whole characters (= user units) fit in the |
| 721 |
active graph. Used in the drawing routine, particularly after |
| 722 |
RESIZE events. |
| 723 |
|
| 724 |
<H3>void graphFreeMenu (void (*f)(KEY), FREEOPT *options)</H3> |
| 725 |
Sets up the menu with a list of FREEOPT options. When one is picked |
| 726 |
f() is called with the corresponding KEY value as an argument. The |
| 727 |
FREEOPT structure is given in the notes for graphSelect(). |
| 728 |
<P> |
| 729 |
NB graphMenu() is the preferred way to establish a menu. |
| 730 |
|
| 731 |
<H3>void graphGoto (float x, float y)</H3> |
| 732 |
Tries to centre (x, y) in user coordinates in the middle of the |
| 733 |
displayed window. Only relevant for TEXT_SCROLL. |
| 734 |
|
| 735 |
<H3>STORE_HANDLE graphHandle (void)</H3> |
| 736 |
Returns the handle by which the currently active graph is held. |
| 737 |
|
| 738 |
<H3>char* graphHelp (char* item)</H3> |
| 739 |
This call registers the active graph with the help package, linking |
| 740 |
it to the help page specified by item. Subsequently a call to |
| 741 |
help() (e.g. from the menu) with this graph active will display the |
| 742 |
correct help page. |
| 743 |
The return value is the previous string registered with the help |
| 744 |
package, if any. |
| 745 |
<P> |
| 746 |
Note that in ACEDB the display manager allows the help page to be |
| 747 |
specified in wspec/displays.wrm. |
| 748 |
|
| 749 |
<H3>void graphInit (int *argcptr, char **argv)</H3> |
| 750 |
Call this in main() to initialise the graph package. |
| 751 |
<P> |
| 752 |
The arguments should be (&argc,argv), where (int argc, char **argv) |
| 753 |
were the arguments to main. graphInit() passes them on to the |
| 754 |
device dependent graphics initialiser. The X initialiser will act |
| 755 |
on, and strip out, the standard X arguments, changing *argcptr (= |
| 756 |
argc) and *argv (the argument list). Other graphics initialisers |
| 757 |
may not change argc, argv. |
| 758 |
|
| 759 |
<H3>int graphLastBox (void)</H3> |
| 760 |
Returns the last box in the active graph. |
| 761 |
|
| 762 |
<H3>void graphLine (float x1, float y1, float x2, float y2)</H3> |
| 763 |
Draws a line from (x1,y1) to (x2,y2) in user coordinates in the |
| 764 |
current foreground colour with the current line width. |
| 765 |
<P> |
| 766 |
Writes on the stack. |
| 767 |
|
| 768 |
<H3>float graphLinewidth (float x)</H3> |
| 769 |
Sets the width in user coordinates for graphLine(). Returns the old |
| 770 |
value. If x < 0 then just returns the old value. This may only |
| 771 |
work partially on graphics systems, but will be exact for postscript |
| 772 |
output. For postscript it also affects rectangle and circle line |
| 773 |
width. |
| 774 |
|
| 775 |
<H3>float graphLineSegs (Array pts) </H3> |
| 776 |
Draws a segmented line in the active graph. |
| 777 |
|
| 778 |
<H3>int graphLoop (BOOL isBlock)</H3> |
| 779 |
This starts a new event loop, processing all events until either the |
| 780 |
graph that was active when it was called is destroyed, or |
| 781 |
graphLoopReturn() is called during some event on that graph. In the |
| 782 |
former case graphLoop() returns 0. In the latter, after that event |
| 783 |
finishes graphLoop() returns with the value given as the argument to |
| 784 |
graphLoopReturn(). |
| 785 |
<P> |
| 786 |
If isBlock is TRUE then PICK, MENU and KEYBOARD events are only handled |
| 787 |
for the graph that graphLoop() was called on - used e.g. in the file |
| 788 |
chooser. |
| 789 |
<P> |
| 790 |
graphLoop() is now reentrant, so you can call it at any time. Recursive |
| 791 |
non-blocking calls could get complex. |
| 792 |
|
| 793 |
<H3>BOOL graphLoopReturn (int retval)</H3> |
| 794 |
see graphLoop(). Returns FALSE if it can't find an unterminated loop |
| 795 |
initiated using graphLoop() on the current graph. |
| 796 |
|
| 797 |
<H3>void graphMapBounds (float ux, float uy, float uw, float uh, float aspect)</H3> |
| 798 |
Set the size of the current graph. |
| 799 |
|
| 800 |
<H3>void graphMenu (MENUOPT *menu)</H3> |
| 801 |
Sets up the menu. menu must be a null terminated array of MENUOPT |
| 802 |
structures: |
| 803 |
<PRE><CODE> |
| 804 |
typedef struct menuopt |
| 805 |
{ void (*f)(void); |
| 806 |
char *text; |
| 807 |
} MENUOPT ; |
| 808 |
</PRE></CODE> |
| 809 |
When a particular text item is selected on the menu the |
| 810 |
corresponding function is called. There is a global empty function, |
| 811 |
menuSpacer() that can be used with a blank title "" to provide a |
| 812 |
blank line in the menu to separate sets of commands. |
| 813 |
|
| 814 |
<H3>void graphMessage (char *text)</H3> |
| 815 |
Puts up a little message window containing the message and a |
| 816 |
"Remove" button. The message window will be destroyed if (i) the |
| 817 |
parent dies, (ii) the button is pressed, (iii) graphUnMessage() is |
| 818 |
called. If graphRegister(MESSAGE_DESTROY,...) has been issued for |
| 819 |
the parent then the registered routine is called when the message |
| 820 |
window dies. Only one message at a time can be displayed for any |
| 821 |
graph -- additional calls are ignored. |
| 822 |
|
| 823 |
<H3>void graphOut (char *text)</H3> |
| 824 |
graphOut() pops up a little window containing the text and a |
| 825 |
"Continue" button that must be pressed to continue. i.e. it is |
| 826 |
blocking. |
| 827 |
|
| 828 |
<H3>Graph graphParent (void)</H3> |
| 829 |
Returns the graph id of the parent of the currently active graph. |
| 830 |
|
| 831 |
<H3>void graphPlainBounds (float ux, float uy, |
| 832 |
float uw, float uh, float aspect)</H3> |
| 833 |
For PLAIN graph types only (see graphCreate()). Sets the extent of |
| 834 |
the drawing area in user coordinates. This will automatically fill |
| 835 |
the available window space, resizing as the window is resized. |
| 836 |
The aspect ratio of the drawing is preserved, so if the window is |
| 837 |
made too narrow the drawing does not extend to the bottom, and if |
| 838 |
too wide then it does not extend to the right hand side. The |
| 839 |
effect of the aspect argument makes |
| 840 |
<PRE><CODE> |
| 841 |
graphPlainBounds (0,0,1,2,0.5) |
| 842 |
</PRE></CODE> |
| 843 |
define a square region on the screen. |
| 844 |
|
| 845 |
<H3>void graphPixels (char *pixels,</H3> |
| 846 |
int w, int h, int lineWidth, |
| 847 |
float x0, float y0, float x1, float y1)</H3> |
| 848 |
<P> |
| 849 |
Draw a pixel image expanded or shrunk in a box. |
| 850 |
<P> |
| 851 |
Can be used with PIXEL_SCROLL and PIXEL_FIT graphs. |
| 852 |
<P> |
| 853 |
pixels - is a data array which can be messfree'd after the call. |
| 854 |
<P> |
| 855 |
linewidth - is the length of a line in the array, the array |
| 856 |
has the form p(x,y) = pixels[y*linewidth+x]. |
| 857 |
<P> |
| 858 |
w, h - width and height of the raw pixel image. |
| 859 |
<P> |
| 860 |
x0, y0, x1, y1 - topleft and bottomright corner to positions of the |
| 861 |
box that the image will be fitted in to. |
| 862 |
|
| 863 |
<H3>void graphPixelBounds (int nx, int ny)</H3> |
| 864 |
Set the graph size in pixel coordinates. |
| 865 |
|
| 866 |
<H3>void graphPixelsRaw (char *pixels, |
| 867 |
int w, int h, int lineWidth, float x0, float y0)</H3> |
| 868 |
Can be used with PIXEL_SCROLL and PIXEL_FIT graphs. |
| 869 |
<P> |
| 870 |
pixels - is a data array which must be created with MALLOC and must |
| 871 |
NOT be free'd by the user. DON'T use messalloc !!! since it |
| 872 |
is freed by free() in XDestroyImage when graphDestroy is called. |
| 873 |
<P> |
| 874 |
linewidth - is the length of a line in the pixel array, the array |
| 875 |
has the form p(x,y) = pixels[y*linewidth+x] |
| 876 |
linewidth has to be a multiple of 4 !!! |
| 877 |
<P> |
| 878 |
w, h - width and height of image to display |
| 879 |
<P> |
| 880 |
x0, y0 - topleft corner to position image on the drawing field. |
| 881 |
|
| 882 |
|
| 883 |
<H3>void graphPoint (float x, float y)</H3> |
| 884 |
Draws a small square at the point (x,y) in the current foreground |
| 885 |
colour. The width of the square in user units can be set by |
| 886 |
graphPointsize(). |
| 887 |
<P> |
| 888 |
Writes on the stack. |
| 889 |
|
| 890 |
<H3>float graphPointsize (float x)</H3> |
| 891 |
Sets the size for graphPoint(). Returns the old value. If x < 0 |
| 892 |
then just returns the old value. |
| 893 |
|
| 894 |
<H3>void graphPolygon (Array pts)</H3> |
| 895 |
Draw a filled polygon. |
| 896 |
|
| 897 |
<H3>void graphPrint (void)</H3> |
| 898 |
Merely calls graphPS (graphHelp(0)). graphHelp(0) returns a name |
| 899 |
that was registered with the help package by the graph. The |
| 900 |
purpose of this is to allow graphPrint() to be placed directly in |
| 901 |
the menu for the graph (using graphMenu()), rather than having to |
| 902 |
write a tiny intermediate routine. |
| 903 |
|
| 904 |
<H3>void graphProcessEvents (void)</H3> |
| 905 |
Will process all pending events in the window system event queue, then |
| 906 |
return back to the user. This does not wait. For a waiting event |
| 907 |
loop use graphLoop(). |
| 908 |
|
| 909 |
<H3>BOOL graphPrompt (char *prompt, char *dfault, char *fmt)</H3> |
| 910 |
graphPrompt() puts up a blocking window with the text followed by a |
| 911 |
textEntry box that allows the user to enter the reply, and two |
| 912 |
buttons: OK and Cancel. The initial text in the textEntry box is |
| 913 |
given by dfault. If Cancel is pressed it returns FALSE. If the OK |
| 914 |
box is pressed, or the Return key, then freecheck() is called on the |
| 915 |
current text buffer to see if it satisfies the format fmt. If it |
| 916 |
does the buffer becomes the current buffer for freesubs, which |
| 917 |
allows reading of values using freeint(), freefloat(), freeword() |
| 918 |
etc, and graphPrompt() returns TRUE. If there is no match message |
| 919 |
and the |
| 920 |
<P> |
| 921 |
The format is a string containing the following chars: |
| 922 |
<PRE> |
| 923 |
i integer |
| 924 |
f float |
| 925 |
d double |
| 926 |
w single word (if it contains spaces or commas, must be in "") |
| 927 |
t text - all to the end of the line taken in next freeword() |
| 928 |
</PRE> |
| 929 |
If the format ends with 'z' then the match must be exact. |
| 930 |
<P> |
| 931 |
e.g. format "iiz" is matched by "23 -19", but not "13" or "13 16 ?", |
| 932 |
the latter of which does match "ii" and "iiwz". |
| 933 |
|
| 934 |
<H3>void graphPS (char *basename)</H3> |
| 935 |
Writes out the active graph as a PostScript file and prints it. |
| 936 |
<P> |
| 937 |
Uses basename to construct a file name by adding an integer (unique |
| 938 |
per process) and ".PS". It tries to open this in the subdirectory |
| 939 |
PS of the home directory, where the home directory is the result of |
| 940 |
filsetdir(0) (set to $ACEDB in main() for acedb). If this fails it |
| 941 |
prints out a message and returns. Otherwise the current drawing |
| 942 |
stack is written into the file as postscript. Following this an |
| 943 |
attempt is made to print the file. If the environment variable |
| 944 |
ACEDB_LPR is set, then the value of this is used as the print |
| 945 |
command, otherwise "lpr" will be used. If ACEDB_LPR is set and |
| 946 |
null then no printing is attempted. Printing is attempted using |
| 947 |
system("print_command file_name"). |
| 948 |
<P> |
| 949 |
NB Currently Helvetica is used as a font; this is not a fixed-width |
| 950 |
font. Ideally it should be. |
| 951 |
|
| 952 |
<H3>void graphPop (void)</H3> |
| 953 |
Uniconizes the active graph if iconized, and brings it to the top |
| 954 |
of the desktop. |
| 955 |
|
| 956 |
<H3>BOOL graphQuery (char *text)</H3> |
| 957 |
graphQuery() pops up a little window with the text and two buttons, |
| 958 |
"Yes" and "No". One of these must be pressed to continue, and |
| 959 |
graphQuery() returns TRUE is Yes and FALSE if No. |
| 960 |
|
| 961 |
<H3>void graphRectangle (float x0, float y0, float x1, float y1)</H3> |
| 962 |
Draws a hollow rectangle with opposite corners at (x0,y0), (x1,y1) |
| 963 |
in user coordinates, in the current foreground colour. On the screen |
| 964 |
the perimeter has width 1 pixel, but in postscript it has width the |
| 965 |
current line width. |
| 966 |
<P> |
| 967 |
Writes on the stack. |
| 968 |
|
| 969 |
<H3>void graphRedraw (void)</H3> |
| 970 |
Forces a complet redraw of the entire drawing stack for the active |
| 971 |
graph. To be called after finishing drawing. This is carried out |
| 972 |
by creating an X expose event, in contrast to graphBoxDraw(), which |
| 973 |
acts immediately. |
| 974 |
|
| 975 |
<H3>GraphFunc graphRegister (int event, void (*f)())</H3> |
| 976 |
This is the main routine to register callback functions for a graph. |
| 977 |
event must come from: |
| 978 |
<PRE><CODE> |
| 979 |
enum GraphEvent {LEFT_DOWN, LEFT_DRAG, LEFT_UP, |
| 980 |
MIDDLE_DOWN, MIDDLE_DRAG, MIDDLE_UP, |
| 981 |
PICK, KEYBOARD, RESIZE, |
| 982 |
MESSAGE_DESTROY, DESTROY |
| 983 |
} ; |
| 984 |
</PRE></CODE> |
| 985 |
f is function that will be called back. Before calling f the |
| 986 |
relevant graph is made active. |
| 987 |
<P> |
| 988 |
The return value is the previous function registered with this |
| 989 |
event, or 0 if there was none. |
| 990 |
<PRE> |
| 991 |
Details: |
| 992 |
Mouse buttons: the callback is f (double x, double y), where (x,y) |
| 993 |
gives the coordinates of the event in user units. Note that x, y |
| 994 |
must be double, since this is not type-checked by the compiler. |
| 995 |
The RIGHT mouse button events are reserved for the menu. |
| 996 |
PICK: if a pick function is registered then it takes precedence |
| 997 |
over LEFT_DOWN. It will call back f (int k, double x, double y) |
| 998 |
where k is the id of the innermost box that contains the cursor |
| 999 |
point, and (x,y) are user coordinates with respect to the top |
| 1000 |
left corner of the box (NB - RELATIVE COORDINATES). All picks |
| 1001 |
lie in some box, because the whole drawing area is box 0. Boxes |
| 1002 |
can refuse picks by calling graphBoxSetPick(). |
| 1003 |
KEYBOARD: The callback is f (int c), where c is normally the ascii |
| 1004 |
character that was pressed. For special keys the #define name |
| 1005 |
given in in key.h should be used, as follows: |
| 1006 |
<CODE> |
| 1007 |
#define SPACE_KEY 32 |
| 1008 |
#define ESCAPE_KEY 27 |
| 1009 |
#define RETURN_KEY 13 |
| 1010 |
#define BACKSPACE_KEY 8 |
| 1011 |
#define UP_KEY 257 |
| 1012 |
#define DOWN_KEY 258 |
| 1013 |
#define LEFT_KEY 259 |
| 1014 |
#define RIGHT_KEY 260 |
| 1015 |
#define HOME_KEY 261 |
| 1016 |
#define END_KEY 262 |
| 1017 |
#define PAGE_UP_KEY 263 |
| 1018 |
#define PAGE_DOWN_KEY 264 |
| 1019 |
#define INSERT_KEY 265 |
| 1020 |
#define DELETE_KEY 127 |
| 1021 |
</CODE> |
| 1022 |
RESIZE: The callback is f(). The application normally calls |
| 1023 |
graphFitBounds() to determine the new size of the window. |
| 1024 |
MESSAGE_DESTROY: The callback is f(). |
| 1025 |
DESTROY: The callback is f(). |
| 1026 |
</PRE> |
| 1027 |
|
| 1028 |
<H3>void graphRectangle (float x0, float y0, float x1, float y1)</H3> |
| 1029 |
Draw a rectangle in a graph. |
| 1030 |
|
| 1031 |
<H3>void graphRetitle (char *name)</H3> |
| 1032 |
Resets the title on the window for the active graph. |
| 1033 |
|
| 1034 |
<H3>void graphScreenSize (float *sx, float *sy, |
| 1035 |
float *fx, float *fy, int *px, int *py)</H3> |
| 1036 |
Return screen size in graphCreate units, TEXT units and pixels. |
| 1037 |
|
| 1038 |
<H3>BOOL graphSelect (KEY *kpt, FREEOPT *options)</H3> |
| 1039 |
Presents a forced choice from options. This is a blocking call that |
| 1040 |
requires a response. |
| 1041 |
<P> |
| 1042 |
Cancel returns FALSE. Selection of one of the legitimate options |
| 1043 |
returns TRUE and fills *kpt. |
| 1044 |
<P> |
| 1045 |
The FREEOPT structure is: |
| 1046 |
<PRE><CODE> |
| 1047 |
typedef struct freestruct |
| 1048 |
{ KEY key ; |
| 1049 |
char *text ; |
| 1050 |
} FREEOPT ; |
| 1051 |
</CODE></PRE> |
| 1052 |
options should be an array of FREEOPT. The length of the array is |
| 1053 |
given in the key field of the first item. The text field of the |
| 1054 |
first itme gives a title. |
| 1055 |
<P> |
| 1056 |
NB Use of this function is discouraged. It is hard to keep it |
| 1057 |
working in all the different environments. Use Buttons or Menu |
| 1058 |
instead if possible. |
| 1059 |
|
| 1060 |
<H3>BOOL graphSetSelectDisplayMode (GraphSelectDisplayMode mode)</H3> |
| 1061 |
Sets the mode for displaying selection lists, the mode is has the values: |
| 1062 |
<PRE><CODE> |
| 1063 |
typedef enum _GraphSelectDisplayMode |
| 1064 |
{GRAPH_SELECT_SCROLLED, |
| 1065 |
GRAPH_SELECT_PLAIN} GraphSelectDisplayMode ; |
| 1066 |
</CODE></PRE> |
| 1067 |
<CODE>GRAPH_SELECT_SCROLLED</CODE> (default) shows the selections in a scrolled window, |
| 1068 |
<CODE>GRAPH_SELECT_PLAIN</CODE> shows the selections in a plain window. |
| 1069 |
|
| 1070 |
<H3>Graph graphSubCreate (int type, float ux, float uy, float uw, float uh)</H3> |
| 1071 |
Creates a new window, which is a subwindow of the currently active graph and returns |
| 1072 |
a handle for it.. See graphCreate() |
| 1073 |
for a description of the parameters.becomes the active window, and returns |
| 1074 |
a handle for it. |
| 1075 |
|
| 1076 |
|
| 1077 |
<H3>Graph graphText (char *text, float x0, float y0)</H3> |
| 1078 |
Draws text in the currently active graph at the given coordinates. |
| 1079 |
|
| 1080 |
<H3>Graph graphTextBounds (int nx, int ny)</H3> |
| 1081 |
Set the size of a graph in text coordinates. |
| 1082 |
|
| 1083 |
<H3>int graphTextEntry (char* cp, int len, float x, float y, |
| 1084 |
void (*fn)(char*)) ;</H3> |
| 1085 |
This creates a box that the user can type into of length len at |
| 1086 |
coords (x,y). The text buffer is cp, which must be of length at |
| 1087 |
least (len+1). cp can be initialised by the user before calling. |
| 1088 |
graphTextEntry() grabs the KEYBOARD event input, and processes |
| 1089 |
keystrokes by inserting printable characters into the buffer at the |
| 1090 |
current cursor position and responding to arrow keys, delete keys |
| 1091 |
and emacs control keys as appropriate to move the cursor. When the |
| 1092 |
return key is pressed the registered function, fn, is called with |
| 1093 |
current contents of its buffer as an argument. |
| 1094 |
<P> |
| 1095 |
The return value of graphTextEntry() is the id of the box containing |
| 1096 |
the text. The user can change the contents of the cp buffer in the |
| 1097 |
code and redraw this box (e.g. graphBoxDraw (entryBox, -1, -1) ;). |
| 1098 |
<P> |
| 1099 |
There can be several text entry boxes in one graph. At any one time |
| 1100 |
at most one is active (grabbing keyboard input). This has a yellow |
| 1101 |
background, while the inactive ones have a green background. The |
| 1102 |
active one is the last for which graphTextEntry (cp,...) has been |
| 1103 |
called. i.e. if you recall graphTextEntry() with the a cp buffer |
| 1104 |
that has already been used it will activate the existing box, not |
| 1105 |
create a new one. This is often done in response to PICK'ing the |
| 1106 |
dormant box. graphEntryDisable() can be used to disable all text |
| 1107 |
entry boxes, and restore the original KEYBOARD callback function. |
| 1108 |
<P> |
| 1109 |
NB two boxes are actually made by each call to graphTextEntry: the |
| 1110 |
main one and one to hold the cursor that is a subbox. |
| 1111 |
<P> |
| 1112 |
See also graphCompletionEntry(). |
| 1113 |
|
| 1114 |
<H3>int graphTextInfo (int *dx, int *dy, float *cw, float *ch) </H3> |
| 1115 |
Get the size of text in the active graph. |
| 1116 |
|
| 1117 |
<H3>int graphTextScrollEntry (char* text, int len, int wlen, </H3> |
| 1118 |
float x, float y, void (*fn)())</H3> |
| 1119 |
Similar to graphTextEntry with following differences: |
| 1120 |
<P> |
| 1121 |
This creates a box that the user can type into of length 'wlen' at |
| 1122 |
coords (x,y). The text buffer is 'text', which must be of length at |
| 1123 |
least ('len'+1). 'text' can be initialised by the user before calling. |
| 1124 |
<P> |
| 1125 |
Because the buffer length may now be greater than the window length |
| 1126 |
(no truncation of input) we now allow for scrolling of text. Text |
| 1127 |
is only partially displayed up to as many characters as the size of |
| 1128 |
the box allows. Left and right keys will scroll if the cursor is at the |
| 1129 |
margins of the box and more text exists in the buffer to the "left" |
| 1130 |
and "right" of the current cursor position. |
| 1131 |
<P> |
| 1132 |
Control-L will center the text buffer in the window (show the middle) and |
| 1133 |
center the cursor position. |
| 1134 |
<P> |
| 1135 |
See also graphTextEntry(), graphCompletionEntry(), graphCompScrollEntry() |
| 1136 |
|
| 1137 |
<H3>void graphText (char *text, float x0, float y0)</H3> |
| 1138 |
Writes the given string with top left at the given location. Line |
| 1139 |
breaking must be done by the user code (possibly using the uLines |
| 1140 |
package from arraysubs). See also graphTextPtr(). |
| 1141 |
<P> |
| 1142 |
Writes on the stack. |
| 1143 |
|
| 1144 |
<H3>void graphTextBounds (int nx, int ny)</H3> |
| 1145 |
For TEXT_SCROLL graph types only (see graphCreate()). Sets the |
| 1146 |
drawing area in character coords (columns, rows). Top left is |
| 1147 |
always (0,0). |
| 1148 |
The ny argument is used to set up scrolling if necessary. nx is |
| 1149 |
only used when writing PostScript files with graphPS(); normally |
| 1150 |
the user must extend the window rightwards to see more. |
| 1151 |
graphTextbounds() can be called after drawing (i.e. once you know |
| 1152 |
how big the drawing is), which is useful. |
| 1153 |
|
| 1154 |
<H3>int graphTextFormat (int format)</H3> |
| 1155 |
Sets the format to one of |
| 1156 |
<PRE><CODE> |
| 1157 |
enum TextFormat { PLAIN_FORMAT, BOLD, ITALIC } |
| 1158 |
</PRE></CODE> |
| 1159 |
Returns the old value. If format < 0 then just returns the old value. |
| 1160 |
|
| 1161 |
<H3>float graphTextHeight (float x)</H3> |
| 1162 |
Sets the height in user coordinates for text. Returns the old |
| 1163 |
value. If x < 0 then just returns the old value. Except for |
| 1164 |
postscript the actual height achieved will be only approximately |
| 1165 |
that requested. |
| 1166 |
<P> |
| 1167 |
Setting height = 0 gives the default font. |
| 1168 |
|
| 1169 |
<H3>void graphTextInfo (int *dx, int *dy, float *cw, float *ch)</H3> |
| 1170 |
Can be called on any graph. Fills *dx, *dy, *cw, *ch. Gives the |
| 1171 |
size of the current font in pixels (*dx, *dy) and in user units |
| 1172 |
(*cw, *ch). |
| 1173 |
|
| 1174 |
<H3>void graphScreenSize (float *sx, float *sy, |
| 1175 |
float *fx, float *fy, int *px, int *py)</H3> |
| 1176 |
|
| 1177 |
Can be called before graphCreate(). (But must be after graphInit of |
| 1178 |
course.) This function provides sizes of the screen, font and pixels |
| 1179 |
in graphCreate units. Fills *sx, *sy, *fx, *fy, *px and *py only if |
| 1180 |
they are non-zero. |
| 1181 |
<PRE><CODE> |
| 1182 |
*sx - Width of entire screen in graphCreate units. |
| 1183 |
*sy - Height of entire screen in graphCreate units. |
| 1184 |
|
| 1185 |
*fx - Number of text columns over entire width of screen. |
| 1186 |
*fy - Number of text rows over entire height of screen. |
| 1187 |
|
| 1188 |
*px - Number of pixels over entire width of screen. |
| 1189 |
*py - Number of pixels over entire height of screen. |
| 1190 |
</PRE></CODE> |
| 1191 |
By dividing sx with fx or px, the width of a character or pixel can be |
| 1192 |
calculated in graphCreate units. Dividing px with fx gives the width |
| 1193 |
of a character in pixels. Apologies that this is such an indirect and |
| 1194 |
complicated function, but a more intuitive version was vetoed. |
| 1195 |
|
| 1196 |
Examples: |
| 1197 |
<PRE> |
| 1198 |
Create a graph which uses half the screen: |
| 1199 |
<CODE> |
| 1200 |
{ |
| 1201 |
float sx, sy ; |
| 1202 |
graphScreenSize (&sx, &sy, 0, 0, 0, 0) ; |
| 1203 |
graphCreate (TEXT_SCROLL, "Half", 0, 0, sx, 0.5*sy) ; |
| 1204 |
} |
| 1205 |
</CODE> |
| 1206 |
Create a graph with 80 columns and 25 rows: |
| 1207 |
<CODE> |
| 1208 |
{ |
| 1209 |
float sx, sy, fx, fy ; |
| 1210 |
graphScreenSize (&sx, &sy, &fx, &fy, 0, 0) ; |
| 1211 |
graphCreate (TEXT_SCROLL, "80x25", 0, 0, 80*sx/fx, 25*sy/fy) ; |
| 1212 |
} |
| 1213 |
</CODE> |
| 1214 |
</PRE> |
| 1215 |
Note: unfortunately graphCreate does not make extra space for |
| 1216 |
scrollbars, so you have to do that yourself. |
| 1217 |
|
| 1218 |
<H3>void graphTextPtr (char *text, float x0, float y0, |
| 1219 |
int length)</H3> |
| 1220 |
Similar to graphText() except that a pointer to the text is kept on |
| 1221 |
the stack, rather than the text itself. This allows the text to be |
| 1222 |
changed without redrawing the whole graph. The maximum expected |
| 1223 |
length of the text must be given to determine the box extent. |
| 1224 |
<P> |
| 1225 |
Writes on the stack. |
| 1226 |
|
| 1227 |
<H3>void graphTextPtrPtr (char *text, float x0, float y0, </H3> |
| 1228 |
As for <CODE>graphTextPtr()</CODE> except that a pointer to a pointer to text is stored |
| 1229 |
on the stack. |
| 1230 |
|
| 1231 |
<H3>Graph graphTextUp (char *text, float x0, float y0)</H3> |
| 1232 |
Draw updatable text into current graph, length is length to extend the box. |
| 1233 |
|
| 1234 |
<H3>void graphUnMessage (void)</H3> |
| 1235 |
See graphMessage(). |
| 1236 |
|
| 1237 |
<H3>void graphWaitCursor (BOOL)</H3> |
| 1238 |
Set a wait cursor (usually watch or egg-timer shaped) for the active graph. |
| 1239 |
|
| 1240 |
<H3>void graphWaitCursorAll (BOOL)</H3> |
| 1241 |
Set a wait cursor (usually watch or egg-timer shaped) for all graphs. |
| 1242 |
|
| 1243 |
<H3>void graphWhere (float *x1, float *y1, float *x2, float *y2)</H3> |
| 1244 |
Return coordinates of the active graph. |
| 1245 |
|
| 1246 |
<H3>void graphWindowSize (float *xp, float *yp, float *wp, float *hp)</H3> |
| 1247 |
Returns the size of the active graphs window (in user coordinates, not pixels). |
| 1248 |
|
| 1249 |
<H3>void graphXorBox (int kbox, float x, float y)</H3> |
| 1250 |
Draws a rectangle in XOR mode of the same dimensions as box kbox, |
| 1251 |
with top left at (x,y). This does not affect the drawing stack - |
| 1252 |
e.g. it is not seen in the postscript output. |
| 1253 |
<P> |
| 1254 |
Low level: used by graphBoxDrag(), which should normally be used by |
| 1255 |
the user. |
| 1256 |
|
| 1257 |
<H3>void graphXorLine (float x0, float y0, float x1, float y1)</H3> |
| 1258 |
Draws a line in XOR mode on the screen. This does not affect the |
| 1259 |
drawing stack - it is purely for temporary cursor type operations. |
| 1260 |
Calling a second time on the same line removes it. |
| 1261 |
|
| 1262 |
|
| 1263 |
</BODY> |
| 1264 |
</HTML> |
| 1265 |
|