Debian Codegraph @

debian/external_deps/fetk/sg/src/vgl/vgl.c

raw
1 /*
2 * ***************************************************************************
3 * SG = < Socket Graphics >
4 * Copyright (C) 1994-- Michael Holst
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * rcsid="$Id: vgl.c,v 1.52 2010/08/12 04:56:25 fetk Exp $"
21 * ***************************************************************************
22 */
23
24 /*
25 * ***************************************************************************
26 * File: vgl.c
27 *
28 * Purpose: Class Vgl: methods.
29 *
30 * Comments: A simple interface to the Ogl class, suitable for plotting
31 * simplical 2-dimensional triangular manifolds imbedded in R^3.
32 * The core Ogl routines are windowing system-independent; this
33 * module forms an interface to the core routines to connect them
34 * to the particular window system. The core routines are currently
35 * written in OpenGL, but could easily be replaced by any other
36 * high-level graphics language that is connectable to the window
37 * system.
38 *
39 * The X-based interface uses only the native Xlib, Xtoolkit, and
40 * the GLw widget set (not even the Athena widgets).
41 *
42 * The Win32-based interface uses only low-level Win32 API calls;
43 * no special libraries are used.
44 *
45 * Hooks are available for supporting a number of other
46 * window systems (OpenStep, OS/2, etc).
47 *
48 * Author: Michael Holst and Randy Bank
49 * ***************************************************************************
50 */
51
52 #include "vgl_p.h"
53
54 #if defined(HAVE_MOTIF)
55 # include "vglm_p.h"
56 #endif
57
58 VEMBED(rcsid="$Id: vgl.c,v 1.52 2010/08/12 04:56:25 fetk Exp $")
59
60 VPUBLIC Vgl *theeVgl;
61
62 /*
63 * ***************************************************************************
64 * Private routine prototypes
65 * ***************************************************************************
66 */
67
68 /*
69 * ***************************************************************************
70 * Class Vgl: Inlineable methods
71 * ***************************************************************************
72 */
73 #if !defined(VINLINE_VGL)
74 #endif /* if !defined(VINLINE_VGL) */
75
76 /*
77 * ***************************************************************************
78 * Class Vgl: Non-inlineable methods
79 * ***************************************************************************
80 */
81
82 VPUBLIC int Vgl_capability(void)
83 {
84 #if defined(HAVE_MOTIF)
85 return 1;
86 #else
87 return 0;
88 #endif
89 }
90
91 VPUBLIC Vgl* Vgl_ctor(int mode,
92 char *socktype, char *dataform, char *hostname, char *filename,
93 int xsize, int ysize, int xpos, int ypos,
94 int (*buildDisplayLists)(Vgl *thee))
95 {
96 int i;
97 Vgl *thee = VNULL;
98 Vglcore *vcore = VNULL;
99
100 #if defined(HAVE_X11)
101 char t_argv[80];
102 int t_argc;
103 String t_argv_string;
104 char *dpyName;
105 String fallback_resources[] = {
106 "*GLwDrawingArea.installColormap: true",
107 "*GLwDrawingArea.rgba: true",
108 "*GLwDrawingArea.doublebuffer: true",
109 "*GLwDrawingArea.depthSize: 1",
110 /* "*GLwDrawingArea.stencilSize: 1", */
111 "*GLwDrawingArea.alphaSize: 0",
112 VNULL
113 };
114 #elif defined(HAVE_WIN32)
115 #elif defined(HAVE_NEXT)
116 #endif
117
118 /* malloc the base structure areas */
119 thee = Vmem_malloc( VNULL, 1, sizeof(Vgl) );
120 thee->vcore = Vmem_malloc( VNULL, 1, sizeof(Vglcore) );
121 vcore = (Vglcore*)thee->vcore;
122 thee->mode = mode;
123 VASSERT( (0==thee->mode) || (1==thee->mode) );
124 theeVgl = thee;
125
126 /* create anchor block (applic context) and initialize (ONCE per exec) */
127 #if defined(HAVE_X11)
128 XtToolkitInitialize();
129 thee->appCon = VNULL;
130 thee->appCon = XtCreateApplicationContext();
131 VASSERT( thee->appCon != VNULL );
132 XtAppSetFallbackResources(thee->appCon, fallback_resources);
133 t_argc = 0;
134 strncpy(t_argv,"Vgl",80);
135 t_argv_string = (String)t_argv;
136 dpyName = getenv("DISPLAY");
137 vcore->dpy = XtOpenDisplay (thee->appCon, dpyName, t_argv_string,
138 t_argv_string, VNULL, 0, &t_argc, &t_argv_string);
139 VASSERT( vcore->dpy != VNULL );
140 #elif defined(HAVE_WIN32)
141 /* create the "anchor block" for this application */
142 thee->appCon = GetModuleHandle(VNULL);
143 #elif defined(HAVE_NEXT)
144 #endif
145
146 /* initialize the core variables */
147 thee->douBuf = VTRUE; /* NT only works WITH double Buffering */
148 thee->winInit = VFALSE;
149 thee->winUp = VFALSE;
150 thee->theScale = 50;
151 vcore->topLev = VNULL;
152 vcore->plot = VNULL;
153 vcore->glxCon = VNULL;
154
155 /* internal polygon XDR buffer */
156 thee->pbuf = VNULL;
157
158 /* display list routine and socket state strings */
159 thee->buildDisplayLists = buildDisplayLists;
160 strncpy(thee->socktype,socktype,80);
161 strncpy(thee->dataform,dataform,80);
162 strncpy(thee->hostname,hostname,80);
163 strncpy(thee->filename,filename,80);
164 thee->socket = -1;
165
166 /* it is useful for I/O to have the username */
167 VASSERT( Vnm_getuser(thee->username, sizeof(thee->username)) );
168
169 /* primary state variables */
170 thee->settings[VGL_LIGHT] = 1;
171 thee->settings[VGL_BALL] = 0;
172 thee->settings[VGL_BBOX] = 0;
173 if (0 == thee->mode) {
174 thee->settings[VGL_ORTHO] = 0;
175 thee->settings[VGL_FRAME] = 0;
176 } else {
177 thee->settings[VGL_ORTHO] = 1;
178 thee->settings[VGL_FRAME] = 1;
179 }
180 if ( !strncmp(thee->dataform,"ASC",80) ) {
181 thee->settings[VGL_XDR] = 0;
182 } else if ( !strncmp(thee->dataform,"XDR",80) ) {
183 thee->settings[VGL_XDR] = 1;
184 } else { VJMPERR1(0); }
185
186 /* display list settings */
187 for (i=0; i<10; i++) {
188 thee->list[i] = 1;
189 }
190
191 /* application title */
192 if ( !strncmp(thee->socktype,"NONE",80) ) {
193 sprintf(thee->id,"%s CLOSED",thee->dataform);
194 } else if ( !strncmp(thee->socktype,"FILE",80) ) {
195 sprintf(thee->id,"%s File=%s",thee->dataform,thee->filename);
196 } else if ( !strncmp(thee->socktype,"UNIX",80) ) {
197 sprintf(thee->id,"%s UNIX socket=/tmp/%s-%s",
198 thee->dataform,thee->filename,thee->username);
199 thee->socket = atoi(thee->filename);
200 } else if ( !strncmp(thee->socktype,"INET",80) ) {
201 sprintf(thee->id,"%s INET socket=%s+%d",
202 thee->dataform,thee->filename,VPORTNUMBER);
203 thee->socket = atoi(thee->filename);
204 } else { VJMPERR1(0); }
205
206 /* try to open the (initial) input [file/buff/unix/inet] device */
207 if ( !strncmp(thee->socktype,"NONE",80) ) {
208 thee->sock = VNULL;
209 } else {
210 thee->sock = Vio_ctor(thee->socktype,thee->dataform,
211 thee->hostname,thee->filename,"r");
212 VJMPERR1( VNULL != thee->sock );
213 }
214
215 /* realize widget hierarchy */
216 Vgl_open(thee, xsize, ysize, xpos, ypos);
217
218 /* setup the OpenGL device and start the event loop */
219 Vgl_makeCurrent(thee);
220 thee->ogl = Ogl_ctor(thee->settings[VGL_FRAME],thee->settings[VGL_ORTHO]);
221
222 /* finally enter the event loop */
223 Vgl_eventLoop(thee);
224
225 /* normal return */
226 return thee;
227
228 VERROR1:
229 /* error return */
230 fprintf(stderr,"Vgl_ctor: Problem opening file: %s\n", thee->filename);
231 return VNULL;
232 }
233
234 VPUBLIC void Vgl_dtor(Vgl **thee)
235 {
236 Vglcore *vcore = (Vglcore*)(*thee)->vcore;
237
238 if ((*thee) != VNULL) {
239
240 Ogl_dtor( (Ogl**)&((*thee)->ogl) );
241
242 #if defined(HAVE_X11)
243 # if 0
244 glXDestroyContext( vcore->dpy, vcore->glxCon );
245 XtDestroyWidget( vcore->topLev );
246 XtDestroyApplicationContext( thee->appCon );
247 # endif
248 if ( (*thee)->mode == 1 ) {
249 #if defined(HAVE_MOTIF)
250 XmFontListEntryFree( &(vcore->theFontEntry) );
251 #endif
252 }
253
254 #elif defined(HAVE_WIN32)
255 VASSERT( DestroyWindow( vcore->topLev) );
256 ExitProcess(0);
257 #elif defined(HAVE_NEXT)
258 [vcore->plot release];
259 [vcore->topLev flushWindow];
260 [vcore->theViu unlockFocus];
261 Vmem_free( VNULL, 1, (*thee)->plotWidth * (*thee)->plotHeight*4,
262 (void**)(vcore->buf) );
263 OSMesaDestroyContext( vcore->glxCon );
264 [NSApp run];
265 [NSApp release];
266 #endif
267
268 Vio_dtor( (Vio**)&((*thee)->sock) );
269 Vio_dtor( (Vio**)&((*thee)->pbuf) );
270
271 Vmem_free( VNULL, 1, sizeof(Vglcore), (void**)&((*thee)->vcore) );
272 Vmem_free( VNULL, 1, sizeof(Vgl), (void**)thee );
273 }
274 }
275
276 VPUBLIC void Vgl_unmakeWidgets(Vgl *thee)
277 {
278 #if defined(HAVE_X11)
279 Vglcore *vcore = thee->vcore;
280 int i;
281
282 if (1 == thee->mode) {
283 #if defined(HAVE_MOTIF)
284 XmFontListFree(vcore->theFont);
285 #endif
286 }
287
288 /* destroy ONLY mainForm (all children are recursively destroyed) */
289 if (vcore->mainForm != VNULL) {
290 XtDestroyWidget(vcore->mainForm);
291 }
292 vcore->mainForm = VNULL;
293 vcore->plot = VNULL;
294 vcore->psgenMenu = VNULL;
295 vcore->resetMenu = VNULL;
296 vcore->socketMenu = VNULL;
297 vcore->settingsMenu = VNULL;
298 vcore->listMenu = VNULL;
299 vcore->fileSelect = VNULL;
300 for (i=0; i<NUM_BUTTONS; i++) {
301 vcore->button[i] = VNULL;
302 }
303 #endif
304 }
305
306 VPUBLIC void Vgl_makeWidgets(Vgl *thee)
307 {
308 #if defined(HAVE_X11)
309 Vglcore *vcore = thee->vcore;
310 EventMask eventList0, eventList1, eventList2;
311
312 #if defined(HAVE_MOTIF)
313 int i, counter;
314 const String buttonLabel[NUM_BUTTONS] = {
315 "socket",
316 "settings",
317 "lists",
318 "gl->file",
319 "file->gl",
320 "reset",
321 "quit"
322 };
323 #endif
324
325 /* main event lists */
326 eventList0 = StructureNotifyMask;
327 eventList1 = ExposureMask | KeyPressMask
328 | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask;
329 eventList2 = ButtonPressMask;
330
331 #if defined(HAVE_MOTIF)
332 if (0 == thee->mode) {
333 #endif
334 /* Create the FORM for everything. */
335 vcore->mainForm = XtVaCreateManagedWidget("mainForm",
336 formWidgetClass, vcore->topLev,
337 XtNwidth, thee->mainFormWidth,
338 XtNheight, thee->mainFormHeight,
339 XtNborderWidth, thee->defaultBorder,
340 XtNdefaultDistance, thee->defaultSep,
341 XtNforeground, WhitePixelOfScreen(vcore->scr),
342 XtNbackground, vcore->backgrnd,
343 VNULL);
344 XtAddEventHandler(vcore->mainForm, eventList0, (int) 0,
345 (XtEventHandler) Vgl_handler, (VPTR) thee);
346
347 /* Create the plot BOX for graphics. */
348 vcore->plot = XtVaCreateManagedWidget("plot",
349 glwDrawingAreaWidgetClass, vcore->mainForm,
350 XtNwidth, thee->plotWidth,
351 XtNheight, thee->plotHeight,
352 XtNborderWidth, thee->defaultBorder,
353 XtNdefaultDistance, thee->defaultSep,
354 XtNforeground, BlackPixelOfScreen(vcore->scr),
355 XtNbackground, WhitePixelOfScreen(vcore->scr),
356 XtNborderColor, vcore->backgrnd,
357 VNULL);
358 XtAddEventHandler(vcore->plot, eventList1, (int) 0,
359 (XtEventHandler) Vgl_handler, (VPTR) thee);
360
361 #if defined(HAVE_MOTIF)
362 } else {
363 /* Create the FORM for everything. */
364 vcore->mainForm = XtVaCreateManagedWidget("mainForm",
365 xmFormWidgetClass, vcore->topLev,
366 XmNwidth, thee->mainFormWidth,
367 XmNheight, thee->mainFormHeight,
368 XmNborderWidth, thee->defaultBorder,
369 XmNforeground, WhitePixelOfScreen(vcore->scr),
370 XmNbackground, vcore->backgrnd,
371 XmNtraversalOn, False,
372 VNULL);
373 XtAddEventHandler(vcore->mainForm, eventList0, (int) 0,
374 (XtEventHandler) Vgl_handler, (VPTR) thee);
375
376 /* Create the plot BOX for graphics. */
377 vcore->plot = XtVaCreateManagedWidget("plot",
378 glwDrawingAreaWidgetClass, vcore->mainForm,
379 XmNwidth, thee->plotWidth,
380 XmNheight, thee->plotHeight,
381 XmNforeground, BlackPixelOfScreen(vcore->scr),
382 XmNbackground, WhitePixelOfScreen(vcore->scr),
383 XmNborderColor, vcore->backgrnd,
384 XmNtopAttachment, XmATTACH_FORM,
385 XmNtopOffset, thee->defaultSep,
386 XmNleftAttachment, XmATTACH_FORM,
387 XmNleftOffset, thee->defaultSep,
388 XmNrightAttachment, XmATTACH_FORM,
389 XmNrightOffset, thee->defaultSep,
390 XmNtraversalOn, False,
391 VNULL);
392 XtAddEventHandler(vcore->plot, eventList1, (int) 0,
393 (XtEventHandler) Vgl_handler, (VPTR) thee);
394
395 /* buttons */
396 counter = 0;
397 for (i=0; i<NUM_BUTTONS; i++) {
398
399 vcore->button[i] = XtVaCreateManagedWidget(
400 buttonLabel[i], (i < 6)
401 ? xmDrawnButtonWidgetClass : xmPushButtonWidgetClass,
402 vcore->mainForm,
403 XmNwidth,thee->ButtonWidth,
404 XmNheight,thee->ButtonHeight,
405 XmNfontList, vcore->theFont,
406 XmNtopAttachment, XmATTACH_WIDGET,
407 XmNtopWidget, vcore->plot,
408 XmNtopOffset, thee->ButtonVertSep,
409 XmNleftAttachment,
410 (counter==0) ? XmATTACH_FORM: XmATTACH_WIDGET,
411 XmNleftWidget,
412 (counter==0) ? vcore->mainForm : vcore->button[i-1],
413 XmNleftOffset, thee->ButtonHorizSep,
414 XmNtraversalOn, False,
415 XmNhighlightOnEnter, True,
416 XmNshadowType,XmSHADOW_OUT,
417 XmNlabelString,VNULL,
418 VNULL);
419 XmChangeColor(vcore->button[i], vcore->buttonBackgrnd);
420
421 if (i == VGL_LISTS) Vgl_buildListMenu(thee);
422 if (i == VGL_SOCKET) Vgl_buildSocketMenu(thee);
423 if (i == VGL_GL2FILE) Vgl_buildPsgenMenu(thee);
424 if (i == VGL_RESET) Vgl_buildResetMenu(thee);
425 if (i == VGL_SETTINGS) Vgl_buildSettingsMenu(thee);
426
427 XtManageChild(vcore->button[i]);
428 XtAddEventHandler(vcore->button[i], eventList2, (int) 0,
429 (XtEventHandler) Vgl_handler, (VPTR) thee);
430 counter++;
431 }
432
433 }
434 #endif
435 #endif
436 }
437
438 VPUBLIC void Vgl_object(Vgl *thee,
439 int itype, int np, float x[], float y[], float z[],
440 int icolor, float color[], float r, char text[])
441 {
442 int j;
443 float c[4], vx[100][3];
444
445 /* make sure have enough local storage to handle number of vertices */
446 VASSERT( np <= 100 );
447
448 /* grab and pack vertices */
449 for (j=0; j<np; j++) {
450 vx[j][0] = x[j];
451 vx[j][1] = y[j];
452 vx[j][2] = z[j];
453 }
454
455 /* map color integer to RGB values */
456 if (icolor < 0) {
457 c[0] = color[0];
458 c[1] = color[1];
459 c[2] = color[2];
460 c[3] = color[3];
461 } else {
462 c[0] = thee->red[ icolor ];
463 c[1] = thee->green[ icolor ];
464 c[2] = thee->blue[ icolor ];
465 c[3] = 0.0;
466 }
467
468 /* add the object to the display list */
469 Ogl_addListObject( thee->ogl, itype, np, vx, c, r, text);
470 }
471
472 VPUBLIC void Vgl_putl(Vgl *thee,
473 int ncolor, float red[], float green[], float blue[])
474 {
475 int i;
476
477 if (ncolor >= 0) {
478 VASSERT( ncolor <= 256 );
479 thee->ncolor = ncolor;
480 for (i=0; i<thee->ncolor; i++) {
481 thee->red[i] = red[i];
482 thee->green[i] = green[i];
483 thee->blue[i] = blue[i];
484 }
485 Ogl_initBegin(thee->ogl);
486 } else {
487 Ogl_initEnd(thee->ogl);
488 Vgl_redraw(thee);
489 }
490 }
491
492 VPUBLIC void Vgl_list(Vgl *thee, int dlist, int show)
493 {
494 if (dlist >= 0) {
495 Ogl_beginList(thee->ogl, dlist, show);
496 } else {
497 Ogl_endList(thee->ogl);
498 }
499 }
500
501 VPUBLIC void Vgl_line(Vgl *thee,
502 float x[], float y[], float z[], int np, int icolor, float color[])
503 {
504 int itype = 0;
505 Vgl_object(thee,itype,np,x,y,z,icolor,color,0.,VNULL);
506 }
507
508 VPUBLIC void Vgl_fill(Vgl *thee,
509 float x[], float y[], float z[], int np, int icolor, float color[])
510 {
511 int itype = 1;
512 Vgl_object(thee,itype,np,x,y,z,icolor,color,0.,VNULL);
513 }
514
515 VPUBLIC void Vgl_text(Vgl *thee,
516 float x[], float y[], float z[], char line[], int icolor, float color[])
517 {
518 int itype = 3;
519 int np = 1;
520 Vgl_object(thee,itype,np,x,y,z,icolor,color,0.,line);
521 }
522
523 VPUBLIC void Vgl_pont(Vgl *thee,
524 float x[], float y[], float z[], int np, int icolor, float color[],
525 int ptype, float radius)
526 {
527 int itype;
528 VASSERT( (0<=ptype) && (ptype<=2) );
529 if (ptype == 0) {
530 itype = 4;
531 } else if (ptype == 1) {
532 itype = 5;
533 } else if (ptype == 2) {
534 itype = 6;
535 } else { VASSERT(0); }
536 Vgl_object(thee,itype,np,x,y,z,icolor,color,radius,VNULL);
537 }
538
539 VPUBLIC void Vgl_quit(Vgl *thee)
540 {
541 thee->winUp = VFALSE;
542 }
543
544 VPUBLIC void Vgl_swapBuffers(Vgl *thee)
545 {
546 Vglcore *vcore = (Vglcore*)thee->vcore;
547
548 if (thee->douBuf) {
549 #if defined(HAVE_X11)
550 GLwDrawingAreaSwapBuffers(vcore->plot);
551 #elif defined(HAVE_WIN32)
552 SwapBuffers(vcore->plot);
553 #elif defined(HAVE_NEXT)
554 [vcore->plot draw];
555 #endif
556 } else {
557 #if defined(HAVE_X11)
558 #elif defined(HAVE_WIN32)
559 #elif defined(HAVE_NEXT)
560 [vcore->plot draw];
561 #endif
562 }
563 }
564
565 VPUBLIC void Vgl_makeCurrent(Vgl *thee)
566 {
567 Vglcore *vcore = (Vglcore*)thee->vcore;
568
569 #if defined(HAVE_X11)
570 GLwDrawingAreaMakeCurrent(vcore->plot, vcore->glxCon);
571 #elif defined(HAVE_WIN32)
572 VASSERT( wglMakeCurrent(vcore->plot, vcore->glxCon) );
573 #elif defined(HAVE_NEXT)
574 OSMesaMakeCurrent( vcore->glxCon, vcore->buf, GL_UNSIGNED_BYTE,
575 thee->plotWidth, thee->plotHeight );
576 #endif
577 }
578
579 VPUBLIC void Vgl_eventLoop(Vgl *thee)
580 {
581 unsigned long rc;
582
583 #if defined(HAVE_X11)
584 XEvent event;
585 #elif defined(HAVE_WIN32)
586 MSG Message;
587 Vglcore *vcore = (Vglcore*)thee->vcore;
588 #elif defined(HAVE_NEXT)
589 #endif
590
591 #if defined(HAVE_X11)
592 rc = XtAppAddTimeOut(thee->appCon,
593 1000, Vgl_getPolys, (VPTR)thee);
594 #elif defined(HAVE_WIN32)
595 rc = SetTimer(vcore->topLev, 1, 1000, VNULL);
596 #elif defined(HAVE_NEXT)
597 #endif
598 VASSERT(rc != 0);
599
600 while (thee->winUp) {
601 #if defined(HAVE_X11)
602 while (thee->winUp && XtAppPending(thee->appCon)) {
603 XtAppNextEvent(thee->appCon,&event);
604 XtDispatchEvent(&event);
605 }
606 #elif defined(HAVE_WIN32)
607 while (thee->winUp &&
608 PeekMessage(&Message, VNULL, 0, 0, PM_NOREMOVE)==TRUE) {
609 if (GetMessage(&Message, VNULL, 0, 0) ) {
610 TranslateMessage(&Message);
611 DispatchMessage(&Message);
612 }
613 }
614 #elif defined(HAVE_NEXT)
615 [NSApp run];
616 #endif
617 }
618 }
619
620 VPUBLIC void Vgl_spin(void *wId, unsigned long *tId)
621 {
622 Vgl *thee = (Vgl*)wId;
623 #if defined(HAVE_X11)
624 #elif defined(HAVE_WIN32)
625 Vglcore *vcore = (Vglcore*)thee->vcore;
626 #elif defined(HAVE_NEXT)
627 #endif
628
629 /* only spin if rotation was large enough */
630 if ( Ogl_spin( thee->ogl ) ) {
631
632 /* redraw the rotated picture and swap buffers */
633 Ogl_display( thee->ogl );
634 Vgl_swapBuffers( thee );
635
636 /* re-register us as a timeout */
637 #if defined(HAVE_X11)
638 thee->spinId = XtAppAddTimeOut(thee->appCon,
639 1, Vgl_spin, (VPTR)thee);
640 #elif defined(HAVE_WIN32)
641 thee->spinId = SetTimer(vcore->topLev, 2, 1, VNULL);
642 #elif defined(HAVE_NEXT)
643 #endif
644 } else {
645 /* de-register us as a timeout */
646 if (thee->spinId != 0) {
647 #if defined(HAVE_X11)
648 XtRemoveTimeOut(thee->spinId);
649 #elif defined(HAVE_WIN32)
650 KillTimer(vcore->topLev, thee->spinId);
651 #elif defined(HAVE_NEXT)
652 #endif
653 thee->spinId = 0;
654 }
655 thee->spinning = 0;
656 }
657 }
658
659 VPUBLIC void Vgl_getPolys(void *wId, unsigned long *tId)
660 {
661 Vgl *thee = (Vgl*)wId;
662 #if defined(HAVE_X11)
663 #elif defined(HAVE_WIN32)
664 Vglcore *vcore = (Vglcore*)thee->vcore;
665 #elif defined(HAVE_NEXT)
666 #endif
667
668 unsigned long rc;
669
670 /* get polygons and rebuild/render display lists if polys are waiting */
671 if ( thee->buildDisplayLists(thee) ) {
672 if (1 == thee->mode) {
673 Vgl_buildListMenu(thee);
674 }
675 }
676
677 /* always re-register us as a timeout */
678 #if defined(HAVE_X11)
679 rc = XtAppAddTimeOut(thee->appCon,
680 10, Vgl_getPolys, (VPTR)thee);
681 #elif defined(HAVE_WIN32)
682 rc = SetTimer(vcore->topLev, 1, 10, VNULL);
683 #elif defined(HAVE_NEXT)
684 #endif
685 VASSERT(rc != 0);
686 }
687
688 VPUBLIC void Vgl_redraw(Vgl *thee)
689 {
690 Ogl_reshape(thee->ogl,thee->plotWidth,thee->plotHeight);
691 Ogl_display(thee->ogl);
692 Vgl_swapBuffers(thee);
693 }
694
695 VPUBLIC VCBPROC Vgl_listCallback(VWIDGET w,
696 VPTR cli, VPTR cal)
697 {
698 int which = (int)cli;
699
700 theeVgl->list[which] = Ogl_listModeOnOff(theeVgl->ogl,which);
701 Vgl_redraw(theeVgl);
702 return 0;
703 }
704
705 VPUBLIC VCBPROC Vgl_settingsCallback(VWIDGET w,
706 VPTR cli, VPTR cal)
707 {
708 Vglcore *vcore = theeVgl->vcore;
709 int which = (int)cli;
710 char title[80];
711
712 if (which == VGL_LIGHT) {
713 theeVgl->settings[VGL_LIGHT] = Ogl_lightModeOnOff(theeVgl->ogl);
714 } else if (which == VGL_ORTHO) {
715 theeVgl->settings[VGL_ORTHO] = Ogl_orthoModeOnOff(theeVgl->ogl);
716 } else if (which == VGL_FRAME) {
717 #if defined(HAVE_X11)
718 theeVgl->settings[VGL_FRAME] = Ogl_frameModeOnOff(theeVgl->ogl);
719 theeVgl->mode = theeVgl->settings[VGL_FRAME];
720 Vgl_unmakeWidgets(theeVgl);
721 Vgl_makeGeom(theeVgl,0);
722 XtResizeWidget(vcore->topLev, theeVgl->mainFormWidth,
723 theeVgl->mainFormHeight, theeVgl->defaultBorder);
724 Vgl_makeWidgets(theeVgl);
725 Vgl_makeCurrent(theeVgl);
726 #endif
727 } else if (which == VGL_BALL) {
728 theeVgl->settings[VGL_BALL] = Ogl_ballModeOnOff(theeVgl->ogl);
729 } else if (which == VGL_BBOX) {
730 theeVgl->settings[VGL_BBOX] = Ogl_bboxModeOnOff(theeVgl->ogl);
731 } else if (which == VGL_XDR) {
732
733 /* toggle the dataform */
734 if ( !strncmp(theeVgl->dataform,"ASC",80) ) {
735 theeVgl->settings[VGL_XDR] = 1;
736 sprintf(theeVgl->dataform,"XDR");
737 } else if ( !strncmp(theeVgl->dataform,"XDR",80) ) {
738 theeVgl->settings[VGL_XDR] = 0;
739 sprintf(theeVgl->dataform,"ASC");
740 } else { VASSERT( 0 ); }
741
742 /* make a new window title */
743 if ( !strncmp(theeVgl->socktype,"NONE",80) ) {
744 sprintf(theeVgl->id,"%s CLOSED",theeVgl->dataform);
745 VASSERT( theeVgl->socket < 0 );
746 } else if ( !strncmp(theeVgl->socktype,"FILE",80) ) {
747 sprintf(theeVgl->id,"%s File=%s",
748 theeVgl->dataform,theeVgl->filename);
749 VASSERT( theeVgl->socket < 0 );
750 } else if ( !strncmp(theeVgl->socktype,"UNIX",80) ) {
751 sprintf(theeVgl->id,"%s UNIX socket=/tmp/%s-%s",
752 theeVgl->dataform,theeVgl->filename,theeVgl->username);
753 } else if ( !strncmp(theeVgl->socktype,"INET",80) ) {
754 sprintf(theeVgl->id,"%s INET socket=%s+%d",
755 theeVgl->dataform,theeVgl->filename,VPORTNUMBER);
756 } else { VASSERT( 0 ); }
757
758 /* close and re-open the socket */
759 if (theeVgl->socket >= 0) {
760 Vio_dtor( &(theeVgl->sock) );
761 if (VNULL==(theeVgl->sock=Vio_ctor(theeVgl->socktype,
762 theeVgl->dataform,theeVgl->hostname,theeVgl->filename,"r"))) {
763 fprintf(stderr,
764 "Vgl_fileReadCallback: Problem opening socket: %s\n",
765 theeVgl->filename);
766 }
767 }
768
769 /* update the window title information */
770 sprintf(title,"Socket Graphics <%s>",theeVgl->id);
771 #if defined(HAVE_X11)
772 XtVaSetValues(vcore->topLev,XtNtitle,title,VNULL);
773 #endif
774
775 } else { VASSERT( 0 ); }
776
777 Vgl_redraw(theeVgl);
778
779 return 0;
780 }
781
782 VPUBLIC VCBPROC Vgl_resetCallback(VWIDGET w,
783 VPTR cli, VPTR cal)
784 {
785 int which = (int)cli;
786
787 if (which == 0) {
788 fprintf(stderr,
789 "Vgl_resetCallback: resetting object orientation and position.\n");
790 Ogl_resetPos( theeVgl->ogl );
791 Vgl_redraw(theeVgl);
792 } else if (which == 1) {
793 fprintf(stderr,
794 "Vgl_resetCallback: releasing object and associated memory.\n");
795 Ogl_resetPos( theeVgl->ogl );
796 Ogl_initBegin(theeVgl->ogl);
797 Ogl_initEnd(theeVgl->ogl);
798 Vgl_buildListMenu(theeVgl);
799 Vgl_redraw(theeVgl);
800 } else { VASSERT( 0 ); }
801
802 return 0;
803 }
804
805 VPUBLIC VCBPROC Vgl_fileWriteCallback(VWIDGET w,
806 VPTR cli, VPTR cal)
807 {
808 int which = (int)cli;
809
810 /*
811 * Oglps options:
812 *
813 * outLine ==> 0=use filled triangles
814 * 1=use filled triangles and then outline them
815 *
816 * inColor ==> 0=grayscale
817 * 1=color
818 *
819 * doCulling ==> 0=don't cull (render everything)
820 * 1=cull (remove backface triangles before
821 * rendering)
822 */
823 int outline, inColor, doCulling;
824
825 if (which == 0) {
826 fprintf(stderr,
827 "Vgl_fileWriteCallback: PS generation started (no edges).\n");
828 Oglps_begin();
829 Ogl_reshape(theeVgl->ogl,theeVgl->plotWidth,theeVgl->plotHeight);
830 Ogl_display(theeVgl->ogl);
831 outline = 0;
832 inColor = 1;
833 doCulling = 0;
834 Oglps_end(outline,inColor,doCulling);
835 fprintf(stderr,
836 "Vgl_fileWriteCallback: PS generation ended (no edges).\n");
837 } else if (which == 1) {
838 fprintf(stderr,
839 "Vgl_fileWriteCallback: PS generation started (edges).\n");
840 Oglps_begin();
841 Ogl_reshape(theeVgl->ogl,theeVgl->plotWidth,theeVgl->plotHeight);
842 Ogl_display(theeVgl->ogl);
843 outline = 1;
844 inColor = 1;
845 doCulling = 0;
846 Oglps_end(outline,inColor,doCulling);
847 fprintf(stderr,
848 "Vgl_fileWriteCallback: PS generation ended (edges).\n");
849 } else if (which == 2) {
850 fprintf(stderr,
851 "Vgl_fileWriteCallback: XPM generation not yet implemented.\n");
852 } else if (which == 3) {
853 fprintf(stderr,
854 "Vgl_fileWriteCallback: BH generation not yet implemented.\n");
855 } else { VASSERT( 0 ); }
856
857 return 0;
858 }
859
860 VPUBLIC VCBPROC Vgl_socketCallBack(VWIDGET w,
861 VPTR cli, VPTR cal)
862 {
863 Vglcore *vcore = theeVgl->vcore;
864 int which = (int)cli;
865 char title[80];
866
867 /* closed socket */
868 if (which == 0) {
869 sprintf(theeVgl->socktype,"NONE");
870 theeVgl->socket = -1;
871 sprintf(theeVgl->filename,"%d",theeVgl->socket);
872 sprintf(theeVgl->id,"%s CLOSED", theeVgl->dataform);
873
874 /* UNIX Domain socket */
875 } else if ((1<=which) && (which<=4)) {
876 sprintf(theeVgl->socktype,"UNIX");
877 theeVgl->socket = which-1;
878 sprintf(theeVgl->filename,"%d",theeVgl->socket);
879 sprintf(theeVgl->id,"%s UNIX socket=/tmp/%s-%s",
880 theeVgl->dataform,theeVgl->filename,theeVgl->username);
881
882 /* INET TCP/IP socket */
883 } else if ((5<=which) && (which<=8)) {
884 sprintf(theeVgl->socktype,"INET");
885 theeVgl->socket = which-5;
886 sprintf(theeVgl->filename,"%d",theeVgl->socket);
887 sprintf(theeVgl->id,"%s INET socket=%s+%d",
888 theeVgl->dataform,theeVgl->filename,VPORTNUMBER);
889
890 } else { VASSERT( 0 ); }
891
892 /* actually open the socket */
893 Vio_dtor( &(theeVgl->sock) );
894 if (theeVgl->socket >= 0) {
895 if (VNULL==(theeVgl->sock=Vio_ctor(theeVgl->socktype,
896 theeVgl->dataform,theeVgl->hostname,theeVgl->filename,"r"))) {
897 fprintf(stderr,
898 "Vgl_fileReadCallback: Problem opening socket: %s\n",
899 theeVgl->filename);
900 }
901 }
902
903 /* update the window title information */
904 sprintf(title,"Socket Graphics <%s>",theeVgl->id);
905 #if defined(HAVE_X11)
906 XtVaSetValues(vcore->topLev,XtNtitle,title,VNULL);
907 #endif
908
909 return 0;
910 }
911
912 #if defined(HAVE_X11)
913 VPUBLIC VCBPROC Vgl_fileReadCallback(VWIDGET w,
914 VPTR cli, VPTR cal)
915 {
916 if (1 == theeVgl->mode) {
917 #if defined(HAVE_MOTIF)
918 return Vgl_M_fileReadCallback(w, cli, cal);
919 #else
920 return 0;
921 #endif
922 } else {
923 return 0;
924 }
925 }
926
927 /* ************************************************* */
928 /* Vgl_makeColors was yanked from Randy's <xgraph.c> */
929 /* ************************************************* */
930 VPUBLIC void Vgl_makeColors(Vgl *thee)
931 {
932 Vglcore *vcore = thee->vcore;
933 XColor color;
934 int Status1, Status2;
935 #if defined(HAVE_MOTIF)
936 Pixel topShadow, bottomShadow, selectit;
937 #endif
938
939 #if 1
940 String bgclr="grey80";
941 String btnbg="gray53";
942 #endif
943 #if 0
944 String bgclr="dodgerblue4";
945 String btnbg="dodgerblue4";
946 #endif
947
948 vcore->foregrnd = WhitePixelOfScreen(vcore->scr);
949 vcore->backgrnd = BlackPixelOfScreen(vcore->scr);
950
951 vcore->buttonBackgrnd = BlackPixelOfScreen(vcore->scr);
952 Status1 = XParseColor(vcore->dpy,
953 DefaultColormapOfScreen(vcore->scr), bgclr, &color);
954 if (Status1 != 0) {
955 Status2 = XAllocColor(vcore->dpy,
956 DefaultColormapOfScreen(vcore->scr),&color);
957 if (Status2 != 0) {
958 vcore->backgrnd = color.pixel;
959 }
960 }
961
962 Status1 = XParseColor(vcore->dpy,
963 DefaultColormapOfScreen(vcore->scr), btnbg, &color);
964 if (Status1 != 0) {
965 Status2 = XAllocColor(vcore->dpy,
966 DefaultColormapOfScreen(vcore->scr),&color);
967 if (Status2 != 0) {
968 vcore->buttonBackgrnd = color.pixel;
969 }
970 }
971 #if defined(HAVE_MOTIF)
972 XmGetColors (vcore->scr,
973 DefaultColormapOfScreen(vcore->scr),
974 vcore->backgrnd, &vcore->foregrnd,
975 &topShadow, &bottomShadow, &selectit);
976 XmGetColors (vcore->scr,
977 DefaultColormapOfScreen(vcore->scr),
978 vcore->buttonBackgrnd, &vcore->buttonForegrnd,
979 &topShadow, &bottomShadow, &selectit);
980 #endif
981 }
982
983 /* *********************************************** */
984 /* Vgl_makeGeom was yanked from Randy's <xgraph.c> */
985 /* *********************************************** */
986 VPUBLIC void Vgl_makeGeom(Vgl *thee, int key)
987 {
988 Vglcore *vcore = thee->vcore;
989 char newfont[100];
990 char *fontname;
991 Dimension winX, winY;
992
993 if (0 == thee->mode) {
994
995 if (key == 0) {
996 winX = XWidthOfScreen(vcore->scr);
997 winY = XHeightOfScreen(vcore->scr);
998 thee->minWidth = winX / 10;
999 thee->minHeight = winY / 10;
1000 thee->maxWidth = winX - 50;
1001 thee->maxHeight = winY - 50;
1002 /* assume [mainFormWidth,mainFormHeight] come in as set */
1003 } else {
1004 XtVaGetValues(vcore->topLev,
1005 XtNwidth, &winX, XtNheight, &winY, VNULL);
1006 thee->defaultBorder = 1;
1007 thee->defaultSep = 1;
1008 thee->mainFormWidth = winX - 4 * thee->defaultBorder;
1009 thee->mainFormHeight = winY - 4 * thee->defaultBorder;
1010 }
1011 if (thee->mainFormWidth < thee->minWidth) {
1012 thee->mainFormWidth = thee->minWidth;
1013 }
1014 if (thee->mainFormHeight < thee->minHeight) {
1015 thee->mainFormHeight = thee->minHeight;
1016 }
1017 if (thee->mainFormWidth > thee->maxWidth) {
1018 thee->mainFormWidth = thee->maxWidth;
1019 }
1020 if (thee->mainFormHeight > thee->maxHeight) {
1021 thee->mainFormHeight = thee->maxHeight;
1022 }
1023
1024 } else {
1025 if (key == 0) {
1026 winX = XWidthOfScreen(vcore->scr);
1027 winY = XHeightOfScreen(vcore->scr);
1028 if (15*winX < 21*winY) {
1029 thee->minWidth = winX * 1/ 10;
1030 thee->minHeight = (winX * 15) / 21;
1031 } else {
1032 thee->minHeight = winY * 1 / 10;
1033 thee->minWidth = (winY * 21) / 15;
1034 }
1035 winX = thee->mainFormWidth;
1036 winY = thee->mainFormHeight;
1037 } else {
1038 XtVaGetValues(vcore->topLev,
1039 XtNwidth, &winX, XtNheight, &winY, VNULL);
1040 }
1041 if (winX < thee->minWidth) winX = thee->minWidth;
1042 if (winY < thee->minHeight) winY = thee->minHeight;
1043 if (15*winX < 21*winY) {
1044 winY = (winX * 15) / 21;
1045 } else {
1046 winX = (winY * 21) / 15;
1047 }
1048 thee->mainFormWidth = winX;
1049 thee->mainFormHeight = winY;
1050 }
1051
1052 /* plot, border, and separator sizes */
1053 thee->defaultBorder = 1;
1054 thee->defaultSep = thee->mainFormWidth / 200;
1055 if (thee->defaultSep <= 0) {
1056 thee->defaultSep = 1;
1057 thee->defaultBorder = 1;
1058 }
1059 thee->plotWidth = thee->mainFormWidth
1060 - 2 * thee->defaultBorder
1061 - 2 * thee->defaultSep;
1062 if (0 == thee->mode) {
1063 thee->plotHeight = thee->mainFormHeight
1064 - 2 * thee->defaultBorder
1065 - 2 * thee->defaultSep;
1066 } else {
1067 thee->plotHeight = (2 * thee->plotWidth) / 3;
1068 }
1069
1070 /* button and button separator sizes */
1071 thee->ButtonWidth = thee->mainFormWidth / (NUM_BUTTONS + 1);
1072 thee->ButtonHeight = thee->ButtonWidth / 3;
1073 thee->ButtonVertSep = ( thee->mainFormHeight - thee->plotHeight
1074 - 4 * thee->defaultBorder
1075 - 1 * thee->ButtonHeight
1076 - 1 * thee->defaultSep ) / 2;
1077 if (thee->ButtonVertSep <= 0 ) {
1078 thee->ButtonVertSep = 1;
1079 }
1080 thee->ButtonHorizSep = (thee->mainFormWidth
1081 - NUM_BUTTONS * thee->ButtonWidth)
1082 / (NUM_BUTTONS + 1);
1083 if (thee->ButtonHorizSep <= 0 ) {
1084 thee->ButtonHorizSep = 1;
1085 }
1086
1087 /* try scalable font */
1088 vcore->fontHeight = (thee->ButtonHeight * 50) / 100;
1089 if (vcore->fontHeight > thee->ButtonHeight - 4)
1090 vcore->fontHeight = thee->ButtonHeight - 4;
1091 if (vcore->fontHeight < 5) vcore->fontHeight = 5;
1092 fontname = "-*-courier-medium-r-*-*-00-*-*-*-*-*-*-*";
1093 strcpy(newfont,fontname);
1094 newfont[24] = 48 + vcore->fontHeight / 10;
1095 newfont[25] = 48 + vcore->fontHeight - (vcore->fontHeight / 10) * 10;
1096 #if defined(HAVE_MOTIF)
1097 vcore->theFontEntry = XmFontListEntryLoad(vcore->dpy, newfont,
1098 XmFONT_IS_FONT, "myTag");
1099 vcore->theFont = XmFontListAppendEntry(VNULL, vcore->theFontEntry);
1100 #endif
1101
1102 }
1103 #endif /* if defined(HAVE_X11) */
1104
1105 VPUBLIC void Vgl_open(Vgl *thee, int xsize, int ysize, int xpos, int ypos)
1106 {
1107 Vglcore *vcore = (Vglcore*)thee->vcore;
1108
1109 #if defined(HAVE_X11)
1110 char title[80];
1111
1112 /* setup the application context if needed */
1113 if (!thee->winInit) {
1114 thee->winInit = VTRUE;
1115 }
1116
1117 /* if not done already, create the widget structure and realize */
1118 if (!thee->winUp) {
1119
1120 /* initial geometry */
1121 thee->mainFormWidth = xsize;
1122 thee->mainFormHeight = ysize;
1123 thee->left = xpos;
1124 thee->top = ypos;
1125
1126 /* Create the top level widget */
1127 sprintf(title,"Socket Graphics <%s>",thee->id);
1128 vcore->topLev = XtVaAppCreateShell(
1129 title, title, topLevelShellWidgetClass,
1130 vcore->dpy, XtNx, thee->left, XtNy, thee->top, VNULL);
1131
1132 /* store the screen away */
1133 vcore->scr = XtScreen(vcore->topLev);
1134 VASSERT( vcore->scr != VNULL );
1135
1136 /* make the colors */
1137 Vgl_makeColors(thee);
1138
1139 /* figure out the geometry */
1140 Vgl_makeGeom(thee, 0);
1141
1142 /* make the widgets */
1143 Vgl_makeWidgets(thee);
1144
1145 /* realize the Widget */
1146 XtRealizeWidget(vcore->topLev);
1147
1148 /* hack to fix screen blanking problem using kde window manager (7/1/03) */
1149
1150 Vgl_unmakeWidgets(thee);
1151 Vgl_makeGeom(thee, 1);
1152 Vgl_makeWidgets(thee);
1153
1154 /* hack to fix screen blanking problem using kde window manager (7/1/03) */
1155
1156 /* get X info and construct a Graphics ctx */
1157 XtVaGetValues(vcore->plot,
1158 GLwNrgba, &(vcore->rgbaVis),
1159 GLwNinstallColormap, &(vcore->cmapIns),
1160 GLwNvisualInfo, &(vcore->xVisInf),
1161 GLwNdoublebuffer, &(thee->douBuf),
1162 VNULL);
1163
1164 /* check some things */
1165 VASSERT( vcore->rgbaVis );
1166 VASSERT( vcore->cmapIns );
1167 VASSERT( thee->douBuf );
1168
1169 /* setup the graphics context */
1170 vcore->glxCon = glXCreateContext(vcore->dpy,vcore->xVisInf,0,VFALSE);
1171 VASSERT( vcore->glxCon != VNULL );
1172
1173 /* check out the visual */
1174 #if 0 /* defined(VDEBUG) */
1175 /* int xTmp; */
1176 glXGetConfig(vcore->dpy,vcore->xVisInf,GLX_DOUBLEBUFFER,&xTmp);
1177 fprintf(stderr,"Vgl_open: vi DOUBLEBUFFER flag = %d\n", xTmp);
1178 glXGetConfig(vcore->dpy,vcore->xVisInf,GLX_RGBA,&xTmp);
1179 fprintf(stderr,"Vgl_open: vi RGBA flag = %d\n", xTmp);
1180 xTmp = glXIsDirect(vcore->dpy, vcore->glxCon);
1181 fprintf(stderr,"Vgl_open: vi DIRECT flag = %d\n", xTmp);
1182 glXGetConfig(vcore->dpy,vcore->xVisInf,GLX_DEPTH_SIZE,&xTmp);
1183 fprintf(stderr,"Vgl_open: vi DEPTH size = %d\n", xTmp);
1184 glXGetConfig(vcore->dpy,vcore->xVisInf,GLX_STENCIL_SIZE,&xTmp);
1185 fprintf(stderr,"Vgl_open: vi STENCIL size = %d\n", xTmp);
1186 glXGetConfig(vcore->dpy,vcore->xVisInf,GLX_ALPHA_SIZE,&xTmp);
1187 fprintf(stderr,"Vgl_open: vi ALPHA size = %d\n", xTmp);
1188 glXGetConfig(vcore->dpy,vcore->xVisInf,GLX_ACCUM_RED_SIZE,&xTmp);
1189 fprintf(stderr,"Vgl_open: vi ACCUM_RED_SIZE = %d\n", xTmp);
1190 glXGetConfig(vcore->dpy,vcore->xVisInf,GLX_ACCUM_GREEN_SIZE,&xTmp);
1191 fprintf(stderr,"Vgl_open: vi ACCUM_GREEN_SIZE = %d\n", xTmp);
1192 glXGetConfig(vcore->dpy,vcore->xVisInf,GLX_ACCUM_BLUE_SIZE,&xTmp);
1193 fprintf(stderr,"Vgl_open: vi ACCUM_BLUE_SIZE = %d\n", xTmp);
1194 #endif
1195
1196 /* warp the pointer into the new window to get right colors */
1197 /*
1198 * XWarpPointer (XtDisplay(vcore->plot), None,
1199 * XtWindow(vcore->plot), 0, 0, 0, 0, 0, 0);
1200 */
1201
1202 /* okay, we are up! */
1203 thee->winUp = VTRUE;
1204 }
1205
1206 #elif defined(HAVE_WIN32)
1207 int xborder, yborder, ytitle, ygunk;
1208 WNDCLASS mglWndClass;
1209 RECT WinRect;
1210 int iPixelFormat;
1211 PIXELFORMATDESCRIPTOR pfd = {
1212 sizeof(PIXELFORMATDESCRIPTOR), /* size of this pfd */
1213 1, /* version number */
1214 PFD_DRAW_TO_WINDOW | /* support window */
1215 PFD_SUPPORT_OPENGL | /* support OpenGL */
1216 PFD_DOUBLEBUFFER, /* double buffered */
1217 PFD_TYPE_RGBA, /* RGBA type */
1218 24, /* 24-bit color depth */
1219 0, 0, 0, 0, 0, 0, /* color bits ignored */
1220 0, /* no alpha buffer */
1221 0, /* shift bit ignored */
1222 0, /* no accumulation buffer */
1223 0, 0, 0, 0, /* accum bits ignored */
1224 32, /* 32-bit z-buffer */
1225 0, /* no stencil buffer */
1226 0, /* no auxiliary buffer */
1227 PFD_MAIN_PLANE, /* main layer */
1228 0, /* reserved */
1229 0, 0, 0 /* layer masks ignored */
1230 };
1231
1232 void *iaddr;
1233 char theeAddr[32];
1234 char title[80];
1235
1236 /* turn "thee" address into a string */
1237 iaddr = (void*)thee;
1238 sprintf(theeAddr,"%p",iaddr);
1239
1240 /* setup the application context if needed */
1241 if (!thee->winInit) {
1242 thee->winInit = VTRUE;
1243
1244 /* register window classes and their handlers once per execution */
1245 mglWndClass.style = CS_HREDRAW | CS_VREDRAW;
1246 mglWndClass.lpfnWndProc = (WNDPROC)Vgl_handler;
1247 mglWndClass.cbClsExtra = 0;
1248 mglWndClass.cbWndExtra = 0;
1249 mglWndClass.hInstance = thee->appCon;
1250 mglWndClass.hIcon = LoadIcon(VNULL, IDI_APPLICATION);
1251 mglWndClass.hCursor = LoadCursor(VNULL, IDC_ARROW);
1252 mglWndClass.hbrBackground = GetStockObject(BLACK_BRUSH);
1253 mglWndClass.lpszMenuName = VNULL;
1254 mglWndClass.lpszClassName = (LPCSTR)theeAddr;
1255 VASSERT( RegisterClass(&mglWndClass) );
1256 }
1257
1258 /* if not done already, create the window structure and realize */
1259 if (!thee->winUp) {
1260 thee->winUp = VTRUE;
1261
1262 /* initial geometry */
1263 thee->plotWidth = xsize;
1264 thee->plotHeight = ysize;
1265 xborder = GetSystemMetrics(SM_CXFRAME);
1266 yborder = GetSystemMetrics(SM_CYFRAME);
1267 ytitle = GetSystemMetrics(SM_CYCAPTION);
1268 ygunk = GetSystemMetrics(SM_CYBORDER);
1269 thee->left = xpos + xborder;
1270 thee->top = ypos + yborder + ytitle - ygunk;
1271
1272 /* Make win large enough to hold client area */
1273 WinRect.left = thee->left;
1274 WinRect.right = thee->left + thee->plotWidth;
1275 WinRect.top = thee->top;
1276 WinRect.bottom = thee->top + thee->plotHeight;
1277 VASSERT( AdjustWindowRect(&WinRect, WS_OVERLAPPEDWINDOW, FALSE) );
1278
1279 /* Must use WS_CLIPCHILDREN and WS_CLIPSIBLINGS styles. */
1280 sprintf(title,"Socket Graphics <%s>",thee->id);
1281 vcore->topLev = CreateWindow( (LPCSTR)theeAddr, title,
1282 WS_VISIBLE | WS_OVERLAPPEDWINDOW |
1283 WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
1284 WinRect.left, WinRect.top,
1285 WinRect.right - WinRect.left, WinRect.bottom - WinRect.top,
1286 VNULL, VNULL, thee->appCon, VNULL );
1287 VASSERT( vcore->topLev != VNULL );
1288
1289 /* Get the hdc */
1290 vcore->plot = GetDC(vcore->topLev);
1291 VASSERT( vcore->plot != VNULL );
1292
1293 /* pixel stuff for WinNT.. */
1294 /* get the device context's best-available-match pixel format */
1295 iPixelFormat = ChoosePixelFormat(vcore->plot, &pfd);
1296
1297 /* make that the device context's current pixel format */
1298 VASSERT( SetPixelFormat(vcore->plot, iPixelFormat, &pfd) );
1299
1300 /* create the graphics context */
1301 vcore->glxCon = wglCreateContext(vcore->plot);
1302 VASSERT( vcore->glxCon != VNULL );
1303
1304 /* force the showing of the windows in the foreground */
1305 ShowWindow(vcore->topLev, SW_NORMAL);
1306 VASSERT( SetActiveWindow(vcore->topLev) );
1307 }
1308 #elif defined(HAVE_NEXT)
1309 NSRect GR;
1310 NSMenu *myMenu;
1311
1312 const char *title = "Vgl OpenGL Graphics";
1313
1314 /* setup the application context if needed */
1315 if (!thee->winInit) {
1316 thee->winInit = VTRUE;
1317 }
1318
1319 /* if not done already, create the widget structure and realize */
1320 if (!thee->winUp) {
1321 thee->winUp = VTRUE;
1322
1323 /* initial geometry */
1324 thee->plotWidth = xsize;
1325 thee->plotHeight = ysize;
1326 thee->left = xpos;
1327 thee->top = ypos;
1328
1329 [[NSAutoreleasePool alloc] init];
1330 NSApp=[NSApplication sharedApplication];
1331
1332 /* Allocate the image buffer */
1333 vcore->buf = Vmem_malloc( VNULL, 1, thee->plotWidth * thee->plotHeight * 4 );
1334
1335 vcore->plot = [[ NSBitmapImageRep alloc]
1336 initWithBitmapDataPlanes:&(vcore->buf)
1337 pixelsWide:thee->plotWidth
1338 pixelsHigh:thee->plotHeight
1339 bitsPerSample:8 samplesPerPixel:4
1340 hasAlpha:YES isPlanar:NO
1341 colorSpaceName:NSDeviceRGBColorSpace
1342 bytesPerRow:0 bitsPerPixel:0];
1343 GR = NSMakeRect(100, 100, thee->plotWidth, thee->plotHeight);
1344
1345
1346 vcore->topLev = [[ NSWindow alloc] initWithContentRect:GR
1347 styleMask:NSTitledWindowMask|
1348 NSMiniaturizableWindowMask
1349 backing:NSBackingStoreBuffered defer:NO];
1350
1351 vcore->theViu = [[ NSView alloc] initWithFrame:GR];
1352
1353 myMenu = [[ NSMenu alloc] initWithTitle:@"VGL"];
1354 [myMenu addItemWithTitle:@"Quit"
1355 action:@selector(terminate:)
1356 keyEquivalent:@"q"];
1357 [myMenu sizeToFit];
1358
1359 [vcore->topLev setTitle:[NSString stringWithCString:title]];
1360 [vcore->topLev display];
1361 [vcore->topLev setContentView:vcore->theViu];
1362 [vcore->topLev makeKeyAndOrderFront:nil];
1363
1364 [NSApp setMainMenu:myMenu];
1365
1366 [vcore->theViu lockFocus];
1367
1368 vcore->glxCon = OSMesaCreateContext( GL_RGBA, NULL );
1369 }
1370 #endif
1371 }
1372
1373 #if defined(HAVE_X11)
1374 VPUBLIC void Vgl_handler(Widget w,
1375 VPTR msg, XEvent* wParam, VPTR lParam)
1376 #elif defined(HAVE_WIN32)
1377 VPUBLIC WINAPI Vgl_handler(HWND w,
1378 UINT msg, DWORD wParam, LONG lParam)
1379 #elif defined(HAVE_NEXT)
1380 VPUBLIC void Vgl_handler(NSWindow *w,
1381 int msg, int wParam, int lParam)
1382 #endif
1383 {
1384 int ihandle = 0;
1385 static int mouseDown = 0;
1386 static int mouseMode = 0;
1387 static int resizeSwitch = 0;
1388 Vgl *thee;
1389 Vglcore *vcore;
1390
1391 #if defined(HAVE_X11)
1392 XComposeStatus compose;
1393 KeySym keysym;
1394 char thisKey,buffer[1];
1395 int x,y,bufsize = 1;
1396 double cpu = 0.0;
1397 unsigned long after;
1398 static unsigned long before;
1399 #elif defined(HAVE_WIN32)
1400 PAINTSTRUCT paint;
1401 MSG qmsg;
1402 HDC hdc;
1403 int x,y;
1404 long keysym,thisKey;
1405 unsigned long wTimerID;
1406 void *iaddr;
1407 char theeAddr[32];
1408 double cpu = 0.0;
1409 unsigned long after;
1410 static unsigned long before;
1411 #elif defined(HAVE_NEXT)
1412 static char lastKey = ' ';
1413 static char thisKey = ' ';
1414 int dummy;
1415 int keysym;
1416 #endif
1417
1418 /* decode the given object address */
1419 #if defined(HAVE_X11)
1420 thee = (Vgl*)msg;
1421 #elif defined(HAVE_WIN32)
1422 VASSERT( GetClassName(w,theeAddr,32) );
1423 sscanf(theeAddr,"%p",&iaddr);
1424 thee = (Vgl*)iaddr;
1425 #elif defined(HAVE_NEXT)
1426 #endif
1427
1428 vcore = (Vglcore*)thee->vcore;
1429
1430 #if defined(HAVE_X11)
1431 /* with X, this handler is called only if needed */
1432 if ( 0 == thee->mode ) {
1433 VASSERT( (w == vcore->plot) || (w == vcore->mainForm) );
1434 }
1435 ihandle = 1;
1436 #elif defined(HAVE_WIN32)
1437 /* with Win32, this handler is called other times also... */
1438 if (w == vcore->topLev) ihandle = 1;
1439 #elif defined(HAVE_NEXT)
1440 #endif
1441
1442 /* handle the single event */
1443 if (ihandle) {
1444
1445 #if defined(HAVE_X11)
1446 switch (wParam->type) {
1447 #elif defined(HAVE_WIN32)
1448 switch (msg) {
1449 #elif defined(HAVE_NEXT)
1450 switch (dummy) {
1451 #endif
1452
1453 /* Window resize */
1454 #if defined(HAVE_X11)
1455 case ConfigureNotify:
1456 if (resizeSwitch == 0) {
1457 resizeSwitch = 1;
1458 thee->plotWidth = wParam->xconfigure.width;
1459 thee->plotHeight = wParam->xconfigure.height;
1460 Vgl_unmakeWidgets(thee);
1461 Vgl_makeGeom(thee,1);
1462 XtResizeWidget(vcore->topLev, thee->mainFormWidth,
1463 thee->mainFormHeight, thee->defaultBorder);
1464 Vgl_makeWidgets(thee);
1465 Vgl_makeCurrent(thee);
1466 Vgl_redraw(thee);
1467 } else {
1468 /* HACK to avoid cascading <ConfigureNotify> forever */
1469 resizeSwitch = 0;
1470 }
1471 break;
1472 #elif defined(HAVE_WIN32)
1473 case WM_SIZE:
1474 thee->plotWidth = LOWORD(lParam);
1475 thee->plotHeight = HIWORD(lParam);
1476 Ogl_reshape( thee->ogl, thee->plotWidth, thee->plotHeight );
1477 if (!PeekMessage(&qmsg,w,WM_PAINT,WM_PAINT,PM_NOREMOVE))
1478 VASSERT( InvalidateRect( w, VNULL, FALSE ) );
1479 return 0;
1480 #elif defined(HAVE_NEXT)
1481 #endif
1482
1483 /* Window expose */
1484 #if defined(HAVE_X11)
1485 case Expose:
1486 Ogl_display( thee->ogl );
1487 Vgl_swapBuffers( thee );
1488 break;
1489 #elif defined(HAVE_WIN32)
1490 case WM_PAINT:
1491 hdc = BeginPaint(vcore->topLev, &paint);
1492 Ogl_display( thee->ogl );
1493 Vgl_swapBuffers( thee );
1494 EndPaint(vcore->topLev, &paint);
1495 return 0;
1496 #elif defined(HAVE_NEXT)
1497 #endif
1498
1499 /* Keyboard key press in window */
1500 #if defined(HAVE_X11)
1501 case KeyPress:
1502 XLookupString(&(wParam->xkey),buffer,bufsize,&keysym,&compose);
1503 #elif defined(HAVE_WIN32)
1504 case WM_CHAR:
1505 keysym = wParam;
1506 #elif defined(HAVE_NEXT)
1507 case 0:
1508 #endif
1509 thisKey = keysym;
1510
1511 if (thisKey == VKEY_Q) {
1512 Vgl_quit(thee);
1513 #if defined(HAVE_X11)
1514 return;
1515 #elif defined(HAVE_WIN32)
1516 return 0;
1517 #elif defined(HAVE_NEXT)
1518 #endif
1519
1520 } else if (thisKey == VKEY_QUE) {
1521 Vgl_prtStat( thee );
1522 } else if (thisKey == VKEY_w) {
1523 Vgl_resetCallback(VNULL, (VPTR) 0, VNULL);
1524 } else if (thisKey == VKEY_W) {
1525 Vgl_resetCallback(VNULL, (VPTR) 1, VNULL);
1526 } else if (thisKey == VKEY_0) {
1527 Vgl_listCallback(VNULL, (VPTR) 0, VNULL);
1528 Vgl_buildListMenu(thee);
1529 } else if (thisKey == VKEY_1) {
1530 Vgl_listCallback(VNULL, (VPTR) 1, VNULL);
1531 Vgl_buildListMenu(thee);
1532 } else if (thisKey == VKEY_2) {
1533 Vgl_listCallback(VNULL, (VPTR) 2, VNULL);
1534 Vgl_buildListMenu(thee);
1535 } else if (thisKey == VKEY_3) {
1536 Vgl_listCallback(VNULL, (VPTR) 3, VNULL);
1537 Vgl_buildListMenu(thee);
1538 } else if (thisKey == VKEY_4) {
1539 Vgl_listCallback(VNULL, (VPTR) 4, VNULL);
1540 Vgl_buildListMenu(thee);
1541 } else if (thisKey == VKEY_5) {
1542 Vgl_listCallback(VNULL, (VPTR) 5, VNULL);
1543 Vgl_buildListMenu(thee);
1544 } else if (thisKey == VKEY_6) {
1545 Vgl_listCallback(VNULL, (VPTR) 6, VNULL);
1546 Vgl_buildListMenu(thee);
1547 } else if (thisKey == VKEY_7) {
1548 Vgl_listCallback(VNULL, (VPTR) 7, VNULL);
1549 Vgl_buildListMenu(thee);
1550 } else if (thisKey == VKEY_8) {
1551 Vgl_listCallback(VNULL, (VPTR) 8, VNULL);
1552 Vgl_buildListMenu(thee);
1553 } else if (thisKey == VKEY_9) {
1554 Vgl_listCallback(VNULL, (VPTR) 9, VNULL);
1555 Vgl_buildListMenu(thee);
1556
1557 } else if (thisKey == VKEY_f) {
1558 Vgl_listCallback(VNULL, (VPTR) 7, VNULL);
1559 Vgl_buildListMenu(thee);
1560 } else if (thisKey == VKEY_e) {
1561 Vgl_listCallback(VNULL, (VPTR) 5, VNULL);
1562 Vgl_buildListMenu(thee);
1563
1564 } else if (thisKey == VKEY_l) {
1565 Vgl_settingsCallback(VNULL, (VPTR) VGL_LIGHT, VNULL);
1566 Vgl_buildSettingsMenu(thee);
1567 } else if (thisKey == VKEY_o) {
1568 Vgl_settingsCallback(VNULL, (VPTR) VGL_ORTHO, VNULL);
1569 Vgl_buildSettingsMenu(thee);
1570 } else if (thisKey == VKEY_v) {
1571 Vgl_settingsCallback(VNULL, (VPTR) VGL_BALL, VNULL);
1572 Vgl_buildSettingsMenu(thee);
1573 } else if (thisKey == VKEY_b) {
1574 Vgl_settingsCallback(VNULL, (VPTR) VGL_BBOX, VNULL);
1575 Vgl_buildSettingsMenu(thee);
1576 } else if (thisKey == VKEY_a) {
1577 Vgl_settingsCallback(VNULL, (VPTR) VGL_XDR, VNULL);
1578 Vgl_buildSettingsMenu(thee);
1579
1580 } else if (thisKey == VKEY_p) {
1581 Vgl_fileWriteCallback(VNULL, (VPTR) 0, VNULL);
1582 } else if (thisKey == VKEY_P) {
1583 Vgl_fileWriteCallback(VNULL, (VPTR) 1, VNULL);
1584 } else if (thisKey == VKEY_x) {
1585 Vgl_fileWriteCallback(VNULL, (VPTR) 2, VNULL);
1586 } else if (thisKey == VKEY_h) {
1587 Vgl_fileWriteCallback(VNULL, (VPTR) 3, VNULL);
1588
1589 } else if (thisKey == VKEY_m) {
1590 Vgl_settingsCallback(VNULL, (VPTR) VGL_FRAME, VNULL);
1591 Vgl_buildSettingsMenu(thee);
1592 }
1593 Vgl_redraw(thee);
1594
1595 #if defined(HAVE_X11)
1596 break;
1597 #elif defined(HAVE_WIN32)
1598 if (!PeekMessage(&qmsg,w,WM_PAINT,WM_PAINT,PM_NOREMOVE))
1599 VASSERT( InvalidateRect( w, VNULL, FALSE ) );
1600 return 0;
1601 #elif defined(HAVE_NEXT)
1602 #endif
1603
1604 /* Mouse button press */
1605 #if defined(HAVE_X11)
1606 case ButtonPress:
1607 /* Mouse button press in graphics window */
1608 if (w==vcore->plot) {
1609 if (!mouseDown) {
1610 if (wParam->xbutton.button == 1) {
1611 mouseMode = 0;
1612 Ogl_setMouseMode(thee->ogl,mouseMode);
1613 } else if (wParam->xbutton.button == 2) {
1614 mouseMode = 2;
1615 Ogl_setMouseMode(thee->ogl,mouseMode);
1616 } else if (wParam->xbutton.button == 3) {
1617 mouseMode = 1;
1618 Ogl_setMouseMode(thee->ogl,mouseMode);
1619 }
1620 mouseDown = 1;
1621 x = wParam->xbutton.x;
1622 y = wParam->xbutton.y;
1623 Ogl_mouseDown( thee->ogl, x, y );
1624 Ogl_display( thee->ogl );
1625 Vgl_swapBuffers( thee );
1626 before = clock();
1627 }
1628 /* Mouse button on one of the button widgets */
1629 } else {
1630 #if defined(HAVE_MOTIF)
1631 if ( 1 == thee->mode ) {
1632 if (w==vcore->button[VGL_SOCKET]) {
1633 XmMenuPosition(vcore->socketMenu,
1634 (XButtonPressedEvent*)(wParam));
1635 XtManageChild(vcore->socketMenu);
1636 } else if (w==vcore->button[VGL_SETTINGS]) {
1637 XmMenuPosition(vcore->settingsMenu,
1638 (XButtonPressedEvent*)(wParam));
1639 XtManageChild(vcore->settingsMenu);
1640 } else if (w==vcore->button[VGL_LISTS]) {
1641 XmMenuPosition(vcore->listMenu,
1642 (XButtonPressedEvent*)(wParam));
1643 XtManageChild(vcore->listMenu);
1644 } else if (w==vcore->button[VGL_GL2FILE]) {
1645 XmMenuPosition(vcore->psgenMenu,
1646 (XButtonPressedEvent*)(wParam));
1647 XtManageChild(vcore->psgenMenu);
1648 } else if (w==vcore->button[VGL_FILE2GL]) {
1649 Vgl_fileSelectHandle(thee);
1650 } else if (w==vcore->button[VGL_RESET]) {
1651 XmMenuPosition(vcore->resetMenu,
1652 (XButtonPressedEvent*)(wParam));
1653 XtManageChild(vcore->resetMenu);
1654 } else if (w==vcore->button[VGL_QUIT]) {
1655 Vgl_quit(thee);
1656 return;
1657 }
1658 Vgl_redraw(thee);
1659 }
1660 #endif
1661 }
1662 break;
1663 #elif defined(HAVE_WIN32)
1664 case WM_LBUTTONDOWN:
1665 if (!mouseDown) {
1666 mouseMode = 0;
1667 Ogl_setMouseMode(thee->ogl,mouseMode);
1668 mouseDown = 1;
1669 x = LOWORD(lParam);
1670 y = HIWORD(lParam);
1671 Ogl_mouseDown( thee->ogl, x, y );
1672 VASSERT( SetFocus(vcore->topLev) );
1673 VASSERT( SetActiveWindow(vcore->topLev) );
1674 SetCapture(vcore->topLev);
1675 before = clock();
1676 }
1677 return 0;
1678 case WM_MBUTTONDOWN:
1679 if (!mouseDown) {
1680 mouseMode = 2;
1681 Ogl_setMouseMode(thee->ogl,mouseMode);
1682 mouseDown = 1;
1683 x = LOWORD(lParam);
1684 y = HIWORD(lParam);
1685 Ogl_mouseDown( thee->ogl, x, y );
1686 VASSERT( SetFocus(vcore->topLev) );
1687 VASSERT( SetActiveWindow(vcore->topLev) );
1688 SetCapture(vcore->topLev);
1689 before = clock();
1690 }
1691 return 0;
1692 case WM_RBUTTONDOWN:
1693 if (!mouseDown) {
1694 mouseMode = 1;
1695 Ogl_setMouseMode(thee->ogl,mouseMode);
1696 mouseDown = 1;
1697 x = LOWORD(lParam);
1698 y = HIWORD(lParam);
1699 Ogl_mouseDown( thee->ogl, x, y );
1700 VASSERT( SetFocus(vcore->topLev) );
1701 VASSERT( SetActiveWindow(vcore->topLev) );
1702 SetCapture(vcore->topLev);
1703 before = clock();
1704 }
1705 return 0;
1706 #elif defined(HAVE_NEXT)
1707 #endif
1708
1709 /* Mouse button release (after press) */
1710 #if defined(HAVE_X11)
1711 case ButtonRelease:
1712 if (mouseDown) {
1713 mouseDown = 0;
1714 x = wParam->xbutton.x;
1715 y = wParam->xbutton.y;
1716 Ogl_mouseUp( thee->ogl, x, y );
1717 Ogl_display( thee->ogl );
1718 Vgl_swapBuffers( thee );
1719 after = clock();
1720 /* cpu = (double)(after - before) / (double)(CLK_TCK); */
1721 cpu = (double)(after - before) / (double)(CLOCKS_PER_SEC);
1722 if ( (thee->spinning == 0)
1723 && (mouseMode == 0)
1724 && (cpu < 4.0e-1) ) {
1725 thee->spinId = XtAppAddTimeOut(thee->appCon,
1726 1, Vgl_spin, (VPTR)thee);
1727 thee->spinning = 1;
1728 }
1729 }
1730 break;
1731 #elif defined(HAVE_WIN32)
1732 case WM_LBUTTONUP:
1733 if (mouseDown) {
1734 mouseDown = 0;
1735 x = LOWORD(lParam);
1736 y = HIWORD(lParam);
1737 Ogl_mouseUp( thee->ogl, x, y );
1738 VASSERT( ReleaseCapture() );
1739 after = clock();
1740 cpu = (double)(after - before) / (double)(CLOCKS_PER_SEC);
1741 if ( (thee->spinning == 0)
1742 && (mouseMode == 0)
1743 && (cpu < 4.0e-1) ) {
1744 thee->spinId = SetTimer(vcore->topLev, 2, 1, VNULL);
1745 thee->spinning = 1;
1746 }
1747 if (!PeekMessage(&qmsg,w,WM_PAINT,WM_PAINT,PM_NOREMOVE))
1748 VASSERT( InvalidateRect( w, VNULL, FALSE ) );
1749 }
1750 return 0;
1751 #elif defined(HAVE_NEXT)
1752 #endif
1753
1754 /* Mouse movement while button pressed */
1755 #if defined(HAVE_X11)
1756 case MotionNotify:
1757 if (mouseDown) {
1758 x = wParam->xbutton.x;
1759 y = wParam->xbutton.y;
1760 Ogl_mouseMotion( thee->ogl, x, y );
1761 Ogl_display( thee->ogl );
1762 Vgl_swapBuffers( thee );
1763 before = clock();
1764 }
1765 break;
1766 #elif defined(HAVE_WIN32)
1767 case WM_MOUSEMOVE:
1768 if (mouseDown) {
1769 x = LOWORD(lParam); /* horizontal position of cursor */
1770 y = HIWORD(lParam); /* vertical position of cursor */
1771 Ogl_mouseMotion( thee->ogl, x, y );
1772 if (!PeekMessage(&qmsg,w,WM_PAINT,WM_PAINT,PM_NOREMOVE))
1773 VASSERT( InvalidateRect( w, VNULL, FALSE ) );
1774 before = clock();
1775 }
1776 return 0;
1777 #elif defined(HAVE_NEXT)
1778 #endif
1779
1780 /* Win32-specific extra events */
1781 #if defined(HAVE_WIN32)
1782 case WM_TIMER:
1783 wTimerID = wParam;
1784 if (wTimerID == 1) {
1785 Vgl_getPolys(thee, &wTimerID);
1786 } else if (wTimerID == 2) {
1787 Vgl_spin(thee, &wTimerID);
1788 } else {
1789 VASSERT(0);
1790 }
1791 return 0;
1792 case WM_USER:
1793 return 0;
1794 case WM_MOVE:
1795 thee->left = LOWORD(lParam);
1796 thee->top = HIWORD(lParam);
1797 return 0;
1798 case WM_KEYDOWN:
1799 return 0;
1800 case WM_CLOSE:
1801 Vgl_quit(thee);
1802 return 0;
1803 case WM_DESTROY:
1804 return 0;
1805 #elif defined(HAVE_NEXT)
1806 #endif
1807
1808 default:
1809 break;
1810 }
1811 }
1812
1813 #if defined(HAVE_X11)
1814 #elif defined(HAVE_WIN32)
1815 return DefWindowProc(w, msg, wParam, lParam);
1816 #elif defined(HAVE_NEXT)
1817 #endif
1818 }
1819
1820 VPUBLIC void Vgl_buildSocketMenu(Vgl *thee)
1821 {
1822 if (1 == thee->mode) {
1823 #if defined(HAVE_MOTIF)
1824 Vgl_M_buildSocketMenu(thee);
1825 #else
1826 /* no-op */
1827 #endif
1828 } else {
1829 /* no-op */
1830 }
1831 }
1832
1833 VPUBLIC void Vgl_buildPsgenMenu(Vgl *thee)
1834 {
1835 if (1 == thee->mode) {
1836 #if defined(HAVE_MOTIF)
1837 Vgl_M_buildPsgenMenu(thee);
1838 #else
1839 /* no-op */
1840 #endif
1841 } else {
1842 /* no-op */
1843 }
1844 }
1845
1846 VPUBLIC void Vgl_buildResetMenu(Vgl *thee)
1847 {
1848 if (1 == thee->mode) {
1849 #if defined(HAVE_MOTIF)
1850 Vgl_M_buildResetMenu(thee);
1851 #else
1852 /* no-op */
1853 #endif
1854 } else {
1855 /* no-op */
1856 }
1857 }
1858
1859 VPUBLIC void Vgl_buildSettingsMenu(Vgl *thee)
1860 {
1861 if (1 == thee->mode) {
1862 #if defined(HAVE_MOTIF)
1863 Vgl_M_buildSettingsMenu(thee);
1864 #else
1865 /* no-op */
1866 #endif
1867 } else {
1868 /* no-op */
1869 }
1870 }
1871
1872 VPUBLIC void Vgl_buildListMenu(Vgl *thee)
1873 {
1874 if (1 == thee->mode) {
1875 #if defined(HAVE_MOTIF)
1876 Vgl_M_buildListMenu(thee);
1877 #else
1878 /* no-op */
1879 #endif
1880 } else {
1881 /* no-op */
1882 }
1883 }
1884
1885 VPUBLIC void Vgl_fileSelectHandle(Vgl *thee)
1886 {
1887 if (1 == thee->mode) {
1888 #if defined(HAVE_MOTIF)
1889 Vgl_M_fileSelectHandle(thee);
1890 #else
1891 /* no-op */
1892 #endif
1893 } else {
1894 /* no-op */
1895 }
1896 }
1897
1898 VPUBLIC void Vgl_prtStat(Vgl *thee)
1899 {
1900 int i;
1901 fprintf(stderr, "\n");
1902 fprintf(stderr, "------------------------[ status of Vgl display ]");
1903 fprintf(stderr, "-------------------------\n");
1904 fprintf(stderr, "| Key Mode Value Description"
1905 " |\n");
1906 fprintf(stderr, "| l lighting %5d lights on or off"
1907 " (0=no lights,1=lights) |\n", thee->settings[VGL_LIGHT]);
1908 fprintf(stderr, "| o ortho %5d projection"
1909 " (0=perspective,1=orthographic) |\n", thee->settings[VGL_ORTHO]);
1910 fprintf(stderr, "| m mode %5d operating mode"
1911 " (0=no frames,1=frames) |\n", thee->settings[VGL_FRAME]);
1912 fprintf(stderr, "| v visible ball %5d visible arcball"
1913 " (0=none,1=draw arcball) |\n", thee->settings[VGL_BALL]);
1914 fprintf(stderr, "| b visible box %5d visible bounding box"
1915 " (0=none,1=draw box) |\n", thee->settings[VGL_BBOX]);
1916 fprintf(stderr, "| a ASCII I/O %5d ASCII or XDR I/O"
1917 " (0=ASCII,1=XDR) |\n", thee->settings[VGL_XDR]);
1918 for (i=0; i<10; i++) {
1919 if ( Ogl_isList(thee->ogl, i) ) {
1920 if (i==5) {
1921 fprintf(stderr, "| %1d (e) listMode[%1d] %5d list mode"
1922 " (0=none,1=draw display list %d) |\n",
1923 i, i, Ogl_isListOn(thee->ogl,i), i);
1924 } else if (i==7) {
1925 fprintf(stderr, "| %1d (f) listMode[%1d] %5d list mode"
1926 " (0=none,1=draw display list %d) |\n",
1927 i, i, Ogl_isListOn(thee->ogl,i), i);
1928 } else {
1929 fprintf(stderr, "| %1d listMode[%1d] %5d list mode"
1930 " (0=none,1=draw display list %d) |\n",
1931 i, i, Ogl_isListOn(thee->ogl,i), i);
1932 }
1933 }
1934 }
1935 fprintf(stderr, "-------------------------------------------------");
1936 fprintf(stderr, "-------------------------\n");
1937 fprintf(stderr, "| ? printStat - "
1938 "print this display of context status |\n");
1939 fprintf(stderr, "| w reset - "
1940 "reset object to original position |\n");
1941 fprintf(stderr, "| W reset - "
1942 "free object and all associated malloc areas |\n");
1943 fprintf(stderr, "| Q quit - "
1944 "quit |\n");
1945 fprintf(stderr, "-------------------------------------------------");
1946 fprintf(stderr, "-------------------------\n");
1947 }
1948