home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume20 / pexdraw / part13 < prev    next >
Encoding:
Text File  |  1993-06-07  |  59.8 KB  |  2,299 lines

  1. Newsgroups: comp.sources.x
  2. From: jch@okimicro.oki.com (Jan Hardenbergh)
  3. Subject: v20i023:  pexdraw - A PEX drawing program, Part13/14
  4. Message-ID: <1993Jun8.150259.19474@sparky.imd.sterling.com>
  5. X-Md4-Signature: 931f5d9c1b785c3fdce94db924b7d7d3
  6. Sender: chris@sparky.imd.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Tue, 8 Jun 1993 15:02:59 GMT
  9. Approved: chris@sparky.imd.sterling.com
  10.  
  11. Submitted-by: jch@okimicro.oki.com (Jan Hardenbergh)
  12. Posting-number: Volume 20, Issue 23
  13. Archive-name: pexdraw/part13
  14. Environment: X11R5, PEX
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  init.c pexdraw.h pexdrawc.3 ui_x.c util/pexutcmaphp.c
  21. # Wrapped by chris@sparky on Tue Jun  8 09:46:36 1993
  22. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  23. echo If this archive is complete, you will see the following message:
  24. echo '          "shar: End of archive 13 (of 14)."'
  25. if test -f 'init.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'init.c'\"
  27. else
  28.   echo shar: Extracting \"'init.c'\" \(13341 characters\)
  29.   sed "s/^X//" >'init.c' <<'END_OF_FILE'
  30. X#ifdef SCCS
  31. Xstatic char sccsid[]="@(#)init.c    1.1 Oki Electric Industry Co., Ltd. 93/05/11";
  32. X#endif
  33. X/*
  34. X *            Copyright (c) 1992 by
  35. X *            Oki Electric Industry Co., Ltd.
  36. X *            All Rights Reserved
  37. X *
  38. X * Permission to use, copy, modify, and distribute this software and its
  39. X * documentation for any purpose and without fee is hereby granted,
  40. X * provided that the above copyright notice appear in all copies and that
  41. X * both that copyright notice and this permission notice appear in
  42. X * supporting documentation, and that the name of Oki not be
  43. X * used in advertising or publicity pertaining to distribution of the
  44. X * software without specific, written prior permission. Oki
  45. X * makes no representations about the suitability of this software for any
  46. X * purpose.  It is provided "as is" without express or implied warranty.
  47. X *
  48. X *************************************************************************
  49. X *
  50. X * init.c containes the initialization routines for pexdraw.
  51. X *
  52. X *************************************************************************/
  53. X
  54. X#include <stdio.h>
  55. X
  56. X#include <math.h>
  57. X
  58. X#include <X11/Xlib.h>
  59. X#include <X11/Xutil.h>
  60. X#include <X11/Xatom.h>
  61. X
  62. X#include <X11/PEX5/PEXlib.h>
  63. X
  64. X#include "pexdraw.h"
  65. X
  66. X/* for PEXUtFindVisual */
  67. X#include "util/pexutcmap.h"
  68. X
  69. Xextern renderProcs wksProcs, rdrProcs;
  70. X
  71. Xextern PEXLookupTable theLightLUT;
  72. X
  73. Xextern int theDBFlag;
  74. Xextern int theHPFlag;
  75. X
  76. X/*************************************************************************
  77. X * M A I N
  78. X */
  79. Xmain(argc,argv)
  80. Xint    argc;
  81. Xchar    *argv[];
  82. X{   
  83. X    InitUserInterface(argc, argv);
  84. X
  85. X    InitPEX();
  86. X
  87. X    MainLoop();
  88. X}
  89. X /*************************************************************************
  90. X * InitPEX
  91. X *
  92. X * Open PEX using popen_xphigs
  93. X */
  94. Xvoid
  95. XInitPEX()
  96. X{
  97. X  PEXExtensionInfo *info;
  98. X  PEXStructure struxid;
  99. X  PEXCoord p[6], *pp;
  100. X  PEXLookupTable        depthCueLUT, colorLUT, 
  101. X                colorApproxLUT;
  102. X  XWindowAttributes winAttrs;
  103. X  XVisualInfo betterVisualInfo, *visInfo;
  104. X  int i, j, count;
  105. X
  106. X  int error;
  107. X  char charString[81];
  108. X
  109. X  unsigned long setWinMask;
  110. X  XSetWindowAttributes setWinAttrs;
  111. X
  112. X  if (error = PEXInitialize(theDisplay, &info, 80, charString)) {
  113. X    charString[80] = (char)0;
  114. X    (void) fprintf(stderr,"%s\n", charString);
  115. X    (void) fprintf(stderr,"PEX not initialized error = %d\n", error);
  116. X    exit(-1);
  117. X  }
  118. X
  119. X  /*
  120. X   * O.K. We would like to used mixed mode if possible 
  121. X   *                    (cause it will always work in 6.0)
  122. X   * but we have some constraints:
  123. X   *  - if we are 5.0 only, we need to use the workstation to get picking done.
  124. X   *  - if we are workstation subset
  125. X   * Otherwise, we can use the 5.1 Renderer picking, etc.  
  126. X   */
  127. X  if (info->major_version != 5) {printf("5.X NOT!!\n"); exit(-5);}
  128. X  if (info->minor_version == 0) {
  129. X    theRenderProcs = wksProcs;
  130. X    the51Flag = 0;
  131. X  } else {
  132. X    the51Flag = 1;
  133. X    if (info->subset_info == PEXWorkstationOnly ) {
  134. X      theRenderProcs = wksProcs;
  135. X    } else if (info->subset_info == PEXImmediateMode ) {
  136. X      printf("OT!!\n"); exit(-5);
  137. X    }    
  138. X    theRenderProcs = rdrProcs;
  139. X
  140. X    /* for testing */
  141. X    if (theForceWKSFlag) theRenderProcs = wksProcs;
  142. X  }
  143. X  /* need this for fetches */
  144. X  theFF = PEXGetProtocolFloatFormat(theDisplay);
  145. X
  146. X/*
  147. X * Determine which visual to use
  148. X *
  149. X * did user specify a visual?
  150. X *
  151. X * First, check to see if the window we have is satisfactory.
  152. X *  - might check to see if it is PEX worthy & DB worthy.
  153. X *    if so, get std colormap.
  154. X *
  155. X * If not, if max Cmaps == 1, then use default
  156. X *    Get STD_CMAP_ grab visual.
  157. X *
  158. X * else find best.
  159. X *
  160. X *
  161. X */
  162. X  XGetWindowAttributes(theDisplay,theWindow,&winAttrs);
  163. X  theScreen = XScreenNumberOfScreen(winAttrs.screen);
  164. X
  165. X  if ((winAttrs.depth < 24) &&
  166. X      (MaxCmapsOfScreen(winAttrs.screen) > 1) &&  /* prevent flashing */
  167. X      (FindBetterPEXVisual( theDisplay, theWindow, PEXWindowDrawable,
  168. X                    winAttrs.visual, &betterVisualInfo ))) {
  169. X    /* found one */
  170. X    theWimpyWindow = theWindow;
  171. X    theWindow = MakeBetterPEXWindow( theDisplay, theWindow,
  172. X                    &winAttrs, &betterVisualInfo );
  173. X    visInfo = &betterVisualInfo;
  174. X  } else { 
  175. X    /* not worth looking for anything better, or there is nothing. get
  176. X     * what we need to make do with what we have.
  177. X     */
  178. X    theWimpyWindow = 0;
  179. X
  180. X    betterVisualInfo.visualid = XVisualIDFromVisual(winAttrs.visual);
  181. X    visInfo = XGetVisualInfo(theDisplay, VisualIDMask, &betterVisualInfo, &i);
  182. X  }
  183. X/*
  184. X * O.K. We are all set, set up color approximation, hide this it is ugly
  185. X */
  186. X  colorApproxLUT = MakeColorApprox( theDisplay, theWindow, visInfo );
  187. X
  188. X  theWinHeight =  winAttrs.height;
  189. X
  190. X/*
  191. X *  Init Render Object
  192. X *
  193. X * Set up all of the LUTs we want (colorApprox, color, light & depthCue )
  194. X * Then call the Render Proc to init ( see above )
  195. X */
  196. X  colorLUT =    InitColorLUT( theDisplay,theWindow);
  197. X  theLightLUT = PEXCreateLookupTable( theDisplay,theWindow, PEXLUTLight);
  198. X  depthCueLUT = PEXCreateLookupTable( theDisplay,theWindow, PEXLUTDepthCue);
  199. X  theFontLUT = PEXCreateLookupTable( theDisplay, theWindow, PEXLUTTextFont);
  200. X
  201. X  theRenderObj = theRenderProcs.Init( theDisplay, theWindow,
  202. X                     colorLUT, theLightLUT, theFontLUT,
  203. X                     depthCueLUT, 
  204. X                     colorApproxLUT);
  205. X
  206. X/*
  207. X * Just turn some lights on for the heck of it.
  208. X */
  209. X  InitLights();
  210. X
  211. X  struxid = PEXCreateStructure(theDisplay);
  212. X
  213. X  PEXSetEditingMode(theDisplay, struxid, PEXStructureInsert);
  214. X
  215. X  PEXSetViewIndex(theDisplay, struxid, PEXOCStore, 1);
  216. X
  217. X  pp = (PEXCoord *)p;
  218. X  pp->x = 0.5; pp->y = 0.0; pp->z = 0.0; pp++;
  219. X  pp->x = 1.0; pp->y = 1.0; pp->z = 0.0; pp++;
  220. X  pp->x = 0.5; pp->y = 0.0; pp->z = 1.0; pp++;
  221. X  pp->x = 0.5; pp->y = 0.0; pp->z = -1.0; pp++;
  222. X  pp->x = 0.5; pp->y = 1.0; pp->z = -1.0; pp++;
  223. X  pp->x = 1.0; pp->y = 0.0; pp->z = 0.0;
  224. X  PEXPolyline(theDisplay, struxid, PEXOCStore, 6, p);
  225. X
  226. X  theRenderProcs.Post( struxid );
  227. X
  228. X  applyViewSet(1);
  229. X
  230. X  theRenderProcs.ReDraw();
  231. X
  232. X  theSpinList.count = 0;
  233. X  PEXRotate(PEXXAxis, 0.0, theMCMatrix.matrix ); /* init MC matrix */
  234. X
  235. X  theDynGC = CreateDynGC(); /* for dynamics using X */
  236. X}
  237. X
  238. X/*************************************************************************
  239. X * FindBestPEXVisual - just do it.
  240. X *
  241. X * type is for MatchRenderingTargets 
  242. X */
  243. Xint 
  244. XFindBetterPEXVisual(dpy, w, type, visIn, visBest )
  245. X     Display *dpy;
  246. X     Window w;
  247. X     int type;
  248. X     Visual *visIn;
  249. X     XVisualInfo *visBest;
  250. X{
  251. X  int i;
  252. X  PEXRenderingTarget *targets;
  253. X  unsigned long lcount;
  254. X  XVisualInfo visTemplate;  
  255. X  XVisualInfo visMatch;
  256. X  XVisualInfo *visInfo;
  257. X  XWindowAttributes winAttrs;
  258. X  int            screen;
  259. X  Window         winWin;
  260. X  int   notDone = 1, triedTrue = 0, triedDirect = 0;
  261. X        PEXUtVisualCriteria             criteria;
  262. X              XStandardColormap         cmap_info_return;
  263. X             PEXColorApproxEntry    capx_info_return;
  264. X      unsigned int                  unmet;
  265. X    Atom                            std_prop_atom_return;
  266. X                          int found;                                                   
  267. X
  268. X  if (w) {
  269. X    screen = theScreen;
  270. X    winWin = w;
  271. X  } else {
  272. X    screen = DefaultScreen(dpy);
  273. X    winWin = RootWindow(dpy, screen);
  274. X  }
  275. X  
  276. X  criteria.visual_class = TrueColor;
  277. X  criteria.depth = 24;
  278. X  criteria.sharable_colormap = 1;
  279. X  criteria.double_buffering_capability = 1;
  280. X  
  281. X  criteria.hard_criteria_mask = PEXUtVisualClass;
  282. X  criteria.soft_criteria_mask = PEXUtDepth |  PEXUtSharableColormap;
  283. X  
  284. X  if (theDBFlag) {
  285. X    criteria.soft_criteria_mask |= PEXUtDoubleBufferingCapability;
  286. X    }
  287. X
  288. X  found = PEXUtFindVisual( dpy, screen, &criteria, visBest,  &cmap_info_return, 
  289. X             &capx_info_return, &unmet, &std_prop_atom_return);
  290. X
  291. X  if ((found == PEXUtQualifiedSuccess) || (found == PEXUtSuccess))
  292. X    return (1); 
  293. X  else {
  294. X
  295. X    criteria.hard_criteria_mask = 0;
  296. X    
  297. X    found = PEXUtFindVisual( dpy, screen, &criteria, visBest,  &cmap_info_return, 
  298. X             &capx_info_return, &unmet, &std_prop_atom_return);
  299. X
  300. X    if ((found == PEXUtQualifiedSuccess)||(found == PEXUtSuccess)) return (1); 
  301. X            
  302. X  }
  303. X  return (0);
  304. X}
  305. X
  306. X/*************************************************************************
  307. X *  GetStandardColormap - 
  308. Xint GetStandardColormap(Display *dpy, XVisualInfo *visInfo, 
  309. X            XStandardColormap *cmap )
  310. X *
  311. X */
  312. Xint GetStandardColormap( dpy, visInfo, cmap )
  313. X     Display *dpy;
  314. X     XVisualInfo *visInfo;
  315. X     XStandardColormap *cmap;
  316. X{
  317. X  XStandardColormap  *scm, *s;
  318. X  Atom property;
  319. X  int i, count;
  320. X
  321. X  switch (visInfo->class) {
  322. X  case TrueColor:
  323. X  case StaticColor:
  324. X    property = XA_RGB_BEST_MAP;
  325. X    break;
  326. X
  327. X  default:
  328. X    property = XA_RGB_DEFAULT_MAP;
  329. X    break;
  330. X  }
  331. X
  332. X  if ( XmuLookupStandardColormap( dpy, visInfo->screen, visInfo->visualid,
  333. X                 visInfo->depth, property, False, True )) {
  334. X
  335. X    if (XGetRGBColormaps(theDisplay, RootWindow(theDisplay, visInfo->screen),
  336. X               &scm, &count, property )) {
  337. X      for (i = 0, s = scm; i < count; i++, scm++ ) {
  338. X    if ( scm->visualid == visInfo->visualid ) {
  339. X      *cmap = *scm;
  340. X      XFree((char *)s);
  341. X      return (1);
  342. X    }
  343. X      }
  344. X    }
  345. X  }
  346. X  return (0);
  347. X}
  348. X
  349. X/*************************************************************************
  350. X * InitColorLUT(dpy, win)
  351. X */
  352. XPEXLookupTable
  353. XInitColorLUT(dpy, win)
  354. X     Display *dpy;
  355. X     Window win;
  356. X{
  357. X  PEXLookupTable clt;
  358. X  PEXColorEntry  entries[8];
  359. X
  360. X  clt = PEXCreateLookupTable( dpy, win, PEXLUTColor);
  361. X
  362. X  entries[0].type = PEXColorTypeRGB;
  363. X  entries[0].value.rgb.red   =  0.0;
  364. X  entries[0].value.rgb.green =  0.0;
  365. X  entries[0].value.rgb.blue  =  0.0;
  366. X
  367. X  entries[1].type = PEXColorTypeRGB;
  368. X  entries[1].value.rgb.red   =  1.0;
  369. X  entries[1].value.rgb.green =  1.0;
  370. X  entries[1].value.rgb.blue  =  1.0;
  371. X
  372. X  entries[2].type = PEXColorTypeRGB;
  373. X  entries[2].value.rgb.red   =  1.0;
  374. X  entries[2].value.rgb.green =  0.0;
  375. X  entries[2].value.rgb.blue  =  0.0;
  376. X
  377. X  entries[3].type = PEXColorTypeRGB;
  378. X  entries[3].value.rgb.red   =  0.0;
  379. X  entries[3].value.rgb.green =  1.0;
  380. X  entries[3].value.rgb.blue  =  0.0;
  381. X
  382. X  entries[4].type = PEXColorTypeRGB;
  383. X  entries[4].value.rgb.red   =  0.0;
  384. X  entries[4].value.rgb.green =  0.0;
  385. X  entries[4].value.rgb.blue  =  1.0;
  386. X
  387. X  entries[5].type = PEXColorTypeRGB;
  388. X  entries[5].value.rgb.red   =  0.0;
  389. X  entries[5].value.rgb.green =  1.0;
  390. X  entries[5].value.rgb.blue  =  1.0;
  391. X
  392. X  entries[6].type = PEXColorTypeRGB;
  393. X  entries[6].value.rgb.red   =  1.0;
  394. X  entries[6].value.rgb.green =  0.0;
  395. X  entries[6].value.rgb.blue  =  1.0;
  396. X
  397. X  entries[7].type = PEXColorTypeRGB;
  398. X  entries[7].value.rgb.red   =  1.0;
  399. X  entries[7].value.rgb.green =  1.0;
  400. X  entries[7].value.rgb.blue  =  0.0;
  401. X
  402. X  PEXSetTableEntries(theDisplay,clt,0,8,PEXLUTColor,(char *)&entries);
  403. X
  404. X  return (clt);
  405. X}
  406. X/*************************************************************************
  407. X * MakeBetterPEXWindow(dpy, w, winAttrs, visBest )
  408. X */
  409. XWindow
  410. XMakeBetterPEXWindow(dpy, w, winAttrs, visBest )
  411. X     Display *dpy;
  412. X     Window w;
  413. X     XWindowAttributes *winAttrs;
  414. X     XVisualInfo *visBest;
  415. X{
  416. X  XStandardColormap  cmap;
  417. X
  418. X  int i, j, count;
  419. X
  420. X  int error;
  421. X  char charString[81];
  422. X
  423. X  unsigned long setWinMask;
  424. X  XSetWindowAttributes setWinAttrs;
  425. X  Window newWin;
  426. X
  427. X
  428. X
  429. X    setWinMask = CWBorderPixel|CWBackPixel;
  430. X    setWinAttrs.border_pixmap = None;
  431. X    setWinAttrs.background_pixmap = None;
  432. X    setWinAttrs.border_pixel = -1;
  433. X    setWinAttrs.background_pixel = 0;
  434. X    if (GetStandardColormap(theDisplay, visBest, &cmap )) {
  435. X
  436. X      if (cmap.colormap == 0) {
  437. X
  438. X        theHPFlag = 1;
  439. X               cmap.colormap = XCreateColormap(theDisplay, w,
  440. X                            visBest->visual, AllocNone );
  441. X    printf("special  HP colormap id = %x visid %x\n", cmap.colormap,
  442. X          visBest->visual );
  443. X      }    
  444. X      setWinAttrs.border_pixel = 0;
  445. X      setWinAttrs.background_pixel = 0;
  446. X      setWinMask |= CWColormap;
  447. X      setWinAttrs.colormap = cmap.colormap;
  448. X    } else {
  449. X        printf("could not get standard colormap\n");
  450. X    }
  451. X    newWin = XCreateWindow(theDisplay, w, 
  452. X                  0,0, winAttrs->width, winAttrs->height, 0,
  453. X                  visBest->depth, InputOutput,
  454. X                  visBest->visual,
  455. X                  setWinMask, &setWinAttrs);
  456. X    /*
  457. X     * do this so Window Manager knows to install this colormap, too.
  458. X     */                  
  459. X    if (winAttrs->colormap != cmap.colormap)
  460. X      XSetWMColormapWindows( theDisplay, theTopWindow, &newWin, 1);
  461. X                  
  462. X    XMapWindow(theDisplay,newWin);
  463. X    XGetWindowAttributes(theDisplay,newWin,winAttrs);
  464. X    
  465. X   return (newWin);
  466. X}
  467. X
  468. X/*************************************************************************
  469. X * MakeColorApprox( dpy, w, visInfo )
  470. X */
  471. XPEXLookupTable
  472. XMakeColorApprox( dpy, w, visInfo )
  473. X     Display *dpy;
  474. X     Window w;
  475. X     XVisualInfo *visInfo;
  476. X{
  477. X  PEXLookupTable capx;
  478. X  PEXColorApproxEntry colorApprox;
  479. X  XStandardColormap  cmap;
  480. X      
  481. X  capx = PEXCreateLookupTable( dpy, w, PEXLUTColorApprox );
  482. X  if (theHPFlag == 0) {                    
  483. X
  484. X   if (GetStandardColormap(theDisplay, visInfo, &cmap )) {
  485. X
  486. X    colorApprox.type = PEXColorSpace;
  487. X    colorApprox.model = PEXColorApproxRGB;
  488. X    colorApprox.max1 = cmap.red_max;
  489. X    colorApprox.max2 = cmap.green_max;
  490. X    colorApprox.max3 = cmap.blue_max;
  491. X    colorApprox.mult1 = cmap.red_mult;
  492. X    colorApprox.mult2 = cmap.green_mult;
  493. X    colorApprox.mult3 = cmap.blue_mult;
  494. X    colorApprox.base_pixel = cmap.base_pixel;
  495. X
  496. X    if ((CheckImpDepInteger(PEXIDDitheringSupported)) && !(theNoDitherFlag))
  497. X      colorApprox.dither = 1;
  498. X    else colorApprox.dither = 0;
  499. X
  500. X    PEXSetTableEntries(theDisplay,capx,0,1,PEXLUTColorApprox,
  501. X               (char *)&colorApprox);
  502. X   } else {
  503. X    printf("no color approx???\n");
  504. X   }
  505. X  }
  506. X  return (capx);
  507. X}
  508. X
  509. END_OF_FILE
  510.   if test 13341 -ne `wc -c <'init.c'`; then
  511.     echo shar: \"'init.c'\" unpacked with wrong size!
  512.   fi
  513.   # end of 'init.c'
  514. fi
  515. if test -f 'pexdraw.h' -a "${1}" != "-c" ; then 
  516.   echo shar: Will not clobber existing file \"'pexdraw.h'\"
  517. else
  518.   echo shar: Extracting \"'pexdraw.h'\" \(12694 characters\)
  519.   sed "s/^X//" >'pexdraw.h' <<'END_OF_FILE'
  520. X#ifdef SCCS
  521. Xstatic char sccsid[]="@(#)pexdraw.h    1.18 Oki Electric Industry Co., Ltd. 93/05/24";
  522. X#endif
  523. X/*
  524. X    This file is under sccs control at Stardent in:
  525. X    /nfs/sole/root/sccs1.p/X11R5/mit/demos/pexdraw/s.pexdraw.h
  526. X*/
  527. X/*
  528. X *            Copyright (c) 1992 by
  529. X *            Oki Electric Industry Co., Ltd.
  530. X *            All Rights Reserved
  531. X *
  532. X * Permission to use, copy, modify, and distribute this software and its
  533. X * documentation for any purpose and without fee is hereby granted,
  534. X * provided that the above copyright notice appear in all copies and that
  535. X * both that copyright notice and this permission notice appear in
  536. X * supporting documentation, and that the name of Oki not be
  537. X * used in advertising or publicity pertaining to distribution of the
  538. X * software without specific, written prior permission. Oki
  539. X * makes no representations about the suitability of this software for any
  540. X * purpose.  It is provided "as is" without express or implied warranty.
  541. X *
  542. X * This supercedes the Stardent copyright granting the same rights that
  543. X * appeared in the pdraw predecessor to pexdraw.
  544. X *
  545. X *************************************************************************
  546. X *
  547. X *                         P E X D R A W
  548. X *
  549. X *  A PEX drawing program based on PDRAW,
  550. X *
  551. X *   This is the header file.
  552. X *
  553. X *************************************************************************/
  554. X
  555. X/*************************************************************************
  556. X * typedefs.
  557. X */
  558. Xtypedef struct _si {
  559. X  PEXCoord point;
  560. X  PEXVector  offset;
  561. X  PEXVector  scale;
  562. X  float  x_ang;
  563. X  float  y_ang;
  564. X  float  z_ang;
  565. X  float  delta_x;
  566. X  float  delta_y;
  567. X  float  delta_z;
  568. X  int    strux;
  569. X  int    wk_id;
  570. X  Display *dpy;
  571. X  int     stop;
  572. X  struct _si *next;
  573. X} SpinInfo;
  574. X
  575. Xtypedef struct {
  576. X  int count;
  577. X  SpinInfo *listHead;
  578. X} SpinList;
  579. X/*
  580. X * other business
  581. X */
  582. X#if defined(SVR4_0) || defined(SVR4) || defined(hpux)
  583. X#include <string.h>
  584. X#define bcopy(b1,b2,len) memmove(b2, b1, len)
  585. X#define bzero(b,len) memset(b, 0, len)
  586. X#define bcmp(b1,b2,len) memcmp(b1, b2, len)
  587. X#endif
  588. X
  589. X#ifndef MAXFLOAT
  590. X#define MAXFLOAT 10000000.0
  591. X#endif
  592. X
  593. X#ifndef M_PI
  594. X#define M_PI            3.14159265358979323846
  595. X#endif
  596. X
  597. X /*************************************************************************
  598. X *
  599. X *    F U N C T I O N    P R O T O T Y P E S
  600. X *
  601. X * I know that this is a pain for some people with lesser compilers, but 
  602. X * these save time and energy.
  603. X *
  604. X */
  605. Xint applyViewSet(
  606. X#if NeedFunctionPrototypes
  607. X         int  /* viewNumber */
  608. X#endif
  609. X);
  610. X
  611. Xint getNumberWidgetValue(
  612. X#if NeedFunctionPrototypes
  613. X             int  /* id */,
  614. X             float * /* value */
  615. X#endif
  616. X);
  617. X
  618. Xint setNumberWidgetValue(
  619. X#if NeedFunctionPrototypes
  620. X             int  /* id */,
  621. X             double  /* value */
  622. X#endif
  623. X);
  624. X
  625. Xvoid InsertLineCmd(
  626. X#if NeedFunctionPrototypes
  627. X           int  /* nCoords */,
  628. X           PEXCoord * /* points */,
  629. X           int  /* select */ 
  630. X#endif
  631. X);
  632. X
  633. Xvoid InsertMClipCmd(
  634. X#if NeedFunctionPrototypes
  635. X           PEXCoord * /* points */,
  636. X           int  /* select */ 
  637. X#endif
  638. X);
  639. X
  640. Xvoid ResizeWindow(
  641. X#if NeedFunctionPrototypes
  642. X          Window  /* w */,
  643. X          int  /* width */,
  644. X          int  /* height */
  645. X#endif
  646. X);
  647. X
  648. Xvoid SelectSomething(
  649. X#if NeedFunctionPrototypes
  650. X             long  /* strux */,
  651. X             long  /* element */ 
  652. X#endif
  653. X);
  654. X
  655. Xvoid ClearSelection();
  656. X
  657. Xvoid DumpStrux(
  658. X#if NeedFunctionPrototypes
  659. X           long  /* strux */,
  660. X           long  /* element */, 
  661. X           int  /* pretty */ 
  662. X#endif
  663. X);
  664. X
  665. Xvoid PrintElement(
  666. X#if NeedFunctionPrototypes
  667. X          long  /* struxID */,
  668. X          long  /* element */, 
  669. X          long  /* ocType */,
  670. X          long  /* eSize */,
  671. X          char * /* elem_data */ 
  672. X#endif
  673. X);
  674. X
  675. XPEXStructure InitStrux();
  676. X
  677. XPEXLookupTable InitColorLUT(
  678. X#if NeedFunctionPrototypes
  679. X     Display * /* dpy */,
  680. X     Window    /* win */
  681. X#endif
  682. X);
  683. X
  684. Xvoid TranslateSelected(
  685. X#if NeedFunctionPrototypes
  686. X               PEXCoord * /* points */ 
  687. X#endif
  688. X);
  689. X
  690. Xvoid DeleteSelected();
  691. X
  692. Xint DeleteStrux(
  693. X#if NeedFunctionPrototypes
  694. X        PEXStructure /* strux */
  695. X#endif
  696. X);
  697. X
  698. Xint ExecStrux(
  699. X#if NeedFunctionPrototypes
  700. X        PEXStructure /* strux */
  701. X#endif
  702. X);
  703. X
  704. Xvoid InsertTriStripCmd(
  705. X#if NeedFunctionPrototypes
  706. X               int  /* nCoords */,
  707. X               PEXCoord * /* points */, 
  708. X               int  /* select */
  709. X#endif
  710. X);
  711. X
  712. Xint StartSpinning(
  713. X#if NeedFunctionPrototypes
  714. X        PEXStructure /* sidToStart */
  715. X#endif
  716. X);
  717. X
  718. X
  719. Xint ApplySpin(
  720. X#if NeedFunctionPrototypes
  721. X        SpinInfo */* si */
  722. X#endif
  723. X);
  724. X
  725. Xint LoadSpinWidget(
  726. X#if NeedFunctionPrototypes
  727. X        SpinInfo */* si */
  728. X#endif
  729. X);
  730. X
  731. XSpinInfo *GetSpinInfo(
  732. X#if NeedFunctionPrototypes
  733. X        PEXStructure /* sidToStart */
  734. X#endif
  735. X);
  736. X
  737. Xint manageSpin(
  738. X#if NeedFunctionPrototypes
  739. X        char * /* client_data */
  740. X#endif
  741. X);
  742. X
  743. Xint oneSpin(
  744. X#if NeedFunctionPrototypes
  745. X        char * /* client_data */
  746. X#endif
  747. X);
  748. X
  749. Xint StopSpinning(
  750. X#if NeedFunctionPrototypes
  751. X        PEXStructure /* sidToStop */
  752. X#endif
  753. X);
  754. X
  755. Xint LoadColorWidget(
  756. X#if NeedFunctionPrototypes
  757. X            PEXStructure /* sidToStart */,
  758. X            long  /* element */,
  759. X            PEXColorRGB * /* rgb */
  760. X#endif
  761. X);
  762. X
  763. X
  764. Xint ApplyColor(
  765. X#if NeedFunctionPrototypes
  766. X            PEXStructure /* sidToStart */,
  767. X            long  /* element */
  768. X#endif
  769. X);
  770. X
  771. Xint GetColorAttribute(
  772. X#if NeedFunctionPrototypes
  773. X            PEXStructure /* sidToStart */,
  774. X            long  /* element */,
  775. X            PEXColorRGB * /* rgb */
  776. X#endif
  777. X);
  778. X
  779. Xint SetColorAttribute(
  780. X#if NeedFunctionPrototypes
  781. X            PEXStructure /* sidToStart */,
  782. X            long  /* element */,
  783. X            PEXColorRGB * /* rgb */
  784. X#endif
  785. X);
  786. X
  787. XGC CreateDynGC();
  788. X
  789. Xint GetXPointsFromSelected(
  790. X#if NeedFunctionPrototypes
  791. X               int * /* count */,
  792. X               XPoint ** /* points */
  793. X#endif
  794. X);
  795. X
  796. Xvoid DumpStruxCmd(
  797. X#if NeedFunctionPrototypes
  798. X          int  /* pretty */
  799. X#endif
  800. X);
  801. X
  802. Xint InteriorStyleCmd(
  803. X#if NeedFunctionPrototypes
  804. X             int  /* style */
  805. X#endif
  806. X);
  807. X
  808. Xint SurfaceInterpCmd(
  809. X#if NeedFunctionPrototypes
  810. X             int  /* method */
  811. X#endif
  812. X);
  813. X
  814. Xint FacetCullingCmd(
  815. X#if NeedFunctionPrototypes
  816. X            int  /* mode */
  817. X#endif
  818. X);
  819. X
  820. Xint ReflectionAttributesCmd(
  821. X#if NeedFunctionPrototypes
  822. X                PEXReflectionAttributes * /* reflAttrs */
  823. X#endif
  824. X);
  825. X
  826. Xvoid AddWorkProc(
  827. X#if NeedFunctionPrototypes
  828. X         int (*)()/* worker */,
  829. X         char * /* info */
  830. X#endif
  831. X);
  832. X
  833. Xvoid InitUserInterface(
  834. X#if NeedFunctionPrototypes
  835. X               int  /* argc */,
  836. X               char ** /* argv */
  837. X#endif
  838. X);
  839. X
  840. Xvoid InitPEX();
  841. Xvoid MainLoop();
  842. Xvoid ApplySurfaceAttrs();
  843. X
  844. Xlong Cubeoctahedron(
  845. X#if NeedFunctionPrototypes
  846. X            PEXCoord * /* offset */,
  847. X            double  /* radius */
  848. X#endif
  849. X);
  850. X
  851. Xint FindBetterPEXVisual(
  852. X#if NeedFunctionPrototypes
  853. X            Display * /* dpy */, 
  854. X            Window  /* w */, 
  855. X            int  /* type */, 
  856. X            Visual * /* visIn */,
  857. X            XVisualInfo * /* visBest */ 
  858. X#endif
  859. X);
  860. X
  861. XWindow
  862. XMakeBetterPEXWindow(
  863. X#if NeedFunctionPrototypes
  864. X            Display * /* dpy */, 
  865. X            Window  /* w */, 
  866. X                XWindowAttributes * /* winAttrs */,
  867. X            XVisualInfo * /* visBest */ 
  868. X#endif
  869. X);
  870. X
  871. XPEXLookupTable
  872. XMakeColorApprox(
  873. X#if NeedFunctionPrototypes
  874. X            Display * /* dpy */, 
  875. X            Window  /* w */, 
  876. X            XVisualInfo * /* visBest */ 
  877. X#endif
  878. X);
  879. X
  880. Xint GetStandardColormap(
  881. X#if NeedFunctionPrototypes
  882. X            Display * /* dpy */,
  883. X            XVisualInfo * /* visInfo */, 
  884. X            XStandardColormap * /* cmap */ 
  885. X#endif
  886. X);
  887. X
  888. Xint GetTextRect(
  889. X#if NeedFunctionPrototypes
  890. X        PEXOCData * /* OCData */,
  891. X        XID  /* strux */, 
  892. X        int  /* offset */, 
  893. X        PEXCoord ** /* rect */ 
  894. X#endif
  895. X);
  896. X
  897. Xint CheckImpDepInteger(
  898. X#if NeedFunctionPrototypes
  899. X     int /* impDepConst; */
  900. X#endif
  901. X);
  902. X
  903. Xint CheckEnumType(
  904. X#if NeedFunctionPrototypes
  905. X     int     /* eType; */,
  906. X     int         /* eValue; */
  907. X#endif
  908. X);
  909. X
  910. X/* static void MyPHIGSErrorHandler( Pint errnum, Pint funcnum, char *fname); */
  911. X
  912. Xvoid set_tool_pointer();
  913. Xvoid set_tool_line();
  914. Xvoid set_tool_view();
  915. Xvoid set_tool_tristrip();
  916. Xvoid set_tool_zoom();
  917. Xvoid set_tool_mclip();
  918. X
  919. X#define RADIAN(x) ((x)*(3.1415927 / 180.0))
  920. X
  921. Xtypedef struct {
  922. X  long strux;
  923. X  long seqNo;
  924. X  PEXMatrix matrix;
  925. X} MCMatrix;
  926. X
  927. X/*************************************************************************
  928. X *
  929. X *    G L O B A L    V A R I A B L E S
  930. X *
  931. X */
  932. X
  933. X#ifdef DECL_GLOBALS
  934. X#define GLOBAL 
  935. X#define INIT(_a) =_a
  936. X#else
  937. X#define GLOBAL extern
  938. X#define INIT(_a)
  939. X#endif
  940. X
  941. X/*************************************************************************
  942. X * theRenderProcs -
  943. X *
  944. X * This global allows the pexdraw application to talk to either a Renderer
  945. X * Resource or a PHIGS Workstation object.
  946. X *
  947. X * The procedures defined are:
  948. X *  Init
  949. X *  ReDraw
  950. X *  MapXToMC
  951. X *  MapMCToX
  952. X *  SetView
  953. X *  SetNPCToDC
  954. X *  Post
  955. X *  DeleteAll
  956. X *  PickOne
  957. X *  PickAll
  958. X *  MapXToNPC
  959. X *  ReconfigureWindow
  960. X *  GetColorFromIndex
  961. X *
  962. X * The two sets of procedures are defines in wks.c & rdr.c
  963. X */
  964. Xtypedef struct {
  965. X XID (*Init)(
  966. X#if NeedNestedPrototypes
  967. X         Display * /* dpy */, 
  968. X         Window  /* w */,
  969. X         PEXLookupTable  /* colorLUT */,
  970. X         PEXLookupTable  /* lightLUT */,
  971. X         PEXLookupTable  /* textLUT */,
  972. X         PEXLookupTable  /* depthCueLUT */,
  973. X         PEXLookupTable  /* colorApproxLUT */ 
  974. X#endif
  975. X);
  976. X
  977. X void (*ReDraw)();
  978. X
  979. X int  (*MapXToMC)(
  980. X#if NeedNestedPrototypes
  981. X          MCMatrix * /* mc */,
  982. X          int  /* inCount */,
  983. X          XPoint * /* xPoints */,
  984. X          PEXCoord ** /* mcPoints */ 
  985. X#endif
  986. X);
  987. X
  988. X int  (*MapMCToX)(
  989. X#if NeedNestedPrototypes
  990. X          MCMatrix * /* mc */,
  991. X          int  /* inCount */,
  992. X          PEXCoord * /* mcPoints */,
  993. X          XPoint ** /* xPoints */ 
  994. X#endif
  995. X);
  996. X
  997. X void (*SetView)(
  998. X#if NeedNestedPrototypes
  999. X          int  /*  viewNumber */,
  1000. X                  PEXViewEntry * /* view; */
  1001. X#endif
  1002. X );
  1003. X
  1004. X void (*SetNPCToDC)(
  1005. X#if NeedNestedPrototypes
  1006. X            PEXNPCSubVolume * /* volume */,
  1007. X            PEXViewport * /* viewport */ 
  1008. X#endif
  1009. X);
  1010. X
  1011. X void (*Post)(
  1012. X#if NeedNestedPrototypes
  1013. X          long  /* struxid */
  1014. X#endif
  1015. X);
  1016. X
  1017. X void (*DeleteAll)();
  1018. X
  1019. X void (*PickOne)(
  1020. X#if NeedNestedPrototypes
  1021. X         short  /* x */,
  1022. X         short  /* y */,
  1023. X         long * /* strux */,
  1024. X         int * /* element */ 
  1025. X#endif
  1026. X);
  1027. X
  1028. X void (*PickAll)(
  1029. X#if NeedNestedPrototypes
  1030. X         short  /* x */,
  1031. X         short  /* y */,
  1032. X         short  /* x2 */,
  1033. X         short  /* y2 */, 
  1034. X         int * /* nFound */,
  1035. X         long ** /* struxArray */,
  1036. X         int ** /* elemArray */ 
  1037. X#endif
  1038. X);
  1039. X
  1040. X int  (*MapXToNPC)(
  1041. X#if NeedNestedPrototypes
  1042. X           int  /* inCount */,
  1043. X           PEXCoord * /* points */ 
  1044. X#endif
  1045. X);
  1046. X
  1047. X int  (*ReconfigureWindow)(
  1048. X#if NeedNestedPrototypes
  1049. X               long  /* w */,
  1050. X               int  /* width */,
  1051. X               int  /* height */
  1052. X#endif
  1053. X);
  1054. X
  1055. X int  (*GetColorFromIndex)(
  1056. X#if NeedFunctionPrototypes
  1057. X     int           /* cIndex; */,
  1058. X     PEXColorRGB * /* rgb */
  1059. X#endif
  1060. X);
  1061. X
  1062. X void (*Unpost)(
  1063. X#if NeedNestedPrototypes
  1064. X          long  /* struxid */
  1065. X#endif
  1066. X);
  1067. X
  1068. X } renderProcs;
  1069. X
  1070. XGLOBAL renderProcs theRenderProcs;
  1071. XGLOBAL int the51Flag;
  1072. X
  1073. XGLOBAL XID theRenderObj INIT( 1);
  1074. XGLOBAL MCMatrix theMCMatrix;
  1075. X
  1076. XGLOBAL float theDepth INIT( 0.5);
  1077. XGLOBAL PEXMatrix theMatOri, theMatMap;
  1078. X
  1079. XGLOBAL SpinList theSpinList;
  1080. XGLOBAL Display *theDisplay;
  1081. XGLOBAL Window   theWindow;
  1082. XGLOBAL int theWinHeight;
  1083. X
  1084. XGLOBAL GC theDynGC INIT( NULL);
  1085. XGLOBAL XID theFontLUT;
  1086. XGLOBAL int theFontInitFlag INIT(0);
  1087. X/*
  1088. X * if theSelectedElement == -1 then nothing is slected. These are
  1089. X * needed in fb.c
  1090. X *
  1091. X * index is only used for stretch, so far.
  1092. X */
  1093. XGLOBAL long theSelectedStrux INIT(0);
  1094. XGLOBAL long theSelectedElement INIT( -1);
  1095. XGLOBAL long theSelectedIndex; /* which point in list */
  1096. XGLOBAL long theNewStrux INIT(0);
  1097. X
  1098. XGLOBAL int thedebug;
  1099. XGLOBAL Window theWimpyWindow;
  1100. X
  1101. X#define TOOL_POINTER 1
  1102. X#define TOOL_LINE 2
  1103. X#define TOOL_VIEW 3
  1104. X#define TOOL_TRISTRIP 4
  1105. X#define TOOL_ZOOM 5
  1106. X#define TOOL_NURBC 6
  1107. X#define TOOL_TEXT 7
  1108. X#define TOOL_PGON 8
  1109. X#define TOOL_CIRCLE 9
  1110. X#define TOOL_MCLIP 9
  1111. X
  1112. XGLOBAL int theCurrentTool;
  1113. X
  1114. XGLOBAL int thePMDBFlag INIT(0);
  1115. XGLOBAL int theForceWKSFlag INIT(0);
  1116. X
  1117. XGLOBAL int theNoDitherFlag INIT(0);
  1118. XGLOBAL int theSetEchoColorFlag INIT(0);
  1119. XGLOBAL int theFF;
  1120. X
  1121. X/* these are in NPC space to allow zooming */
  1122. XGLOBAL float theWindowCenterX INIT(0.5);
  1123. XGLOBAL float theWindowCenterY INIT(0.5);
  1124. XGLOBAL float theWindowSize INIT(0.5);
  1125. X
  1126. XGLOBAL int theScreen;
  1127. X
  1128. Xtypedef int (*pexFileCmd)();
  1129. Xint ReadArchiveFile(
  1130. X#if NeedFunctionPrototypes
  1131. X    char * /*filename */
  1132. X#endif
  1133. X    );
  1134. X
  1135. Xint WriteArchiveFile(
  1136. X#if NeedFunctionPrototypes
  1137. X    char * /*filename */
  1138. X#endif
  1139. X    );
  1140. X
  1141. XGLOBAL pexFileCmd theFileCmd INIT(ReadArchiveFile);
  1142. X
  1143. X/*************************************************************************
  1144. X * input dispatch tables
  1145. X */
  1146. Xtypedef void (*pexdrawHandler)();
  1147. XpexdrawHandler thePressHandlerTable[3];
  1148. XpexdrawHandler theMotionHandlerTable[3];
  1149. XpexdrawHandler theReleaseHandlerTable[3];
  1150. X
  1151. X/*************************************************************************
  1152. X * markers start at 70
  1153. X * 0 if marker
  1154. X * 1
  1155. X */
  1156. X#define OCPRIMTAB_BASE 79
  1157. X#define OCPRIMTAB_MAX  98
  1158. X
  1159. X#define OCPRIM_MARKER 1
  1160. X#define OCPRIM_LINE   2
  1161. X#define OCPRIM_PGON   3
  1162. X#define OCPRIM_TEXT   5
  1163. X
  1164. X
  1165. X#ifdef DECL_GLOBALS
  1166. Xint myOCPrimType[] = {1,1,3,3,3,3,2,2,2,2,/* 89 */3,3,3,3,3,3,3,3,3,3};
  1167. X#else
  1168. Xextern int myOCPrimType[];
  1169. X#endif
  1170. X
  1171. Xtypedef struct {
  1172. X  unsigned int index;
  1173. X  int path;
  1174. X  double expansion;
  1175. X  double spacing;
  1176. X  double height;
  1177. X  int halign;
  1178. X  int valign;
  1179. X} TextAttributes;
  1180. X
  1181. XGLOBAL TextAttributes scratchTextAttrs;
  1182. XGLOBAL PEXCoord textRect[4];
  1183. X
  1184. XGLOBAL Window theTopWindow;
  1185. END_OF_FILE
  1186.   if test 12694 -ne `wc -c <'pexdraw.h'`; then
  1187.     echo shar: \"'pexdraw.h'\" unpacked with wrong size!
  1188.   fi
  1189.   # end of 'pexdraw.h'
  1190. fi
  1191. if test -f 'pexdrawc.3' -a "${1}" != "-c" ; then 
  1192.   echo shar: Will not clobber existing file \"'pexdrawc.3'\"
  1193. else
  1194.   echo shar: Extracting \"'pexdrawc.3'\" \(6070 characters\)
  1195.   sed "s/^X//" >'pexdrawc.3' <<'END_OF_FILE'
  1196. X    pp4->z = pp3->z * w;
  1197. X    pp4->w = w;
  1198. X      }
  1199. X    p4[11].w = 0.1;
  1200. X    parr.point_4d = p4;
  1201. X  } else {
  1202. X    parr.point = p3;
  1203. X  }
  1204. X
  1205. X  PEXSetSurfaceApprox(theDisplay, struxid, PEXOCStore, 
  1206. X              PEXApproxConstantBetweenKnots, 2.0, 2.0 );
  1207. X  PEXSetSurfaceColorIndex( theDisplay, struxid, PEXOCStore, 5 );
  1208. X  PEXNURBSurface(dpy,struxid,PEXOCStore, rational, 3, 4,
  1209. X         uKnots, vKnots, 
  1210. X         3, 4, parr, 0, 0 );
  1211. X}
  1212. X/*************************************************************************
  1213. X *
  1214. X */
  1215. X
  1216. Xint CheckImpDepInteger(impDepConst)
  1217. X  int impDepConst;
  1218. X{
  1219. X  PEXImpDepConstant *impDeps;
  1220. X  unsigned short id[1];         /* it get's promoted if a paramter, sigh */
  1221. X  int value;
  1222. X/*
  1223. X */
  1224. X  id[0] = (unsigned short)impDepConst;
  1225. X
  1226. X  if(PEXGetImpDepConstants( theDisplay, theWindow,
  1227. X               1, id, &impDeps )) {
  1228. X    value = impDeps[0].integer;
  1229. X    XFree((char *)impDeps);
  1230. X  } else { printf("CheckImpDep failed on %d\n",impDepConst); value = 0; }
  1231. X  return (value);
  1232. X}    
  1233. X
  1234. X/*************************************************************************
  1235. X *
  1236. X */
  1237. X
  1238. Xint CheckEnumType( eType, eValue )
  1239. X     int eType;
  1240. X     int eValue;
  1241. X{
  1242. X  PEXEnumTypeDesc *enums;
  1243. X  unsigned long *enumCounts;
  1244. X  int found = 0;
  1245. X  int j;
  1246. X
  1247. X  if (PEXGetEnumTypeInfo( theDisplay, theWindow, 1, &eType,
  1248. X                    PEXETIndex, &enumCounts, &enums )) {
  1249. X    for (j = 0; j < enumCounts[0]; j++ ) {
  1250. X      /* we have a list of the supported enums for the type eType */
  1251. X      /* See if the one we wnat is in here */
  1252. X      if (enums[j].index == (PEXEnumTypeIndex)eValue) found = 1;
  1253. X      }
  1254. X    PEXFreeEnumInfo(1, enumCounts, enums );
  1255. X  }
  1256. X  return (found);
  1257. X}
  1258. X
  1259. X/*************************************************************************
  1260. X *  GetColorAttribute get the color of the given element.
  1261. X *
  1262. X *  Function return 1 if O.K.
  1263. X *
  1264. X *  Get the element 2 before it, if color, assume it is right type go to FC
  1265. X *   if not color, fetch element, decide type, increment elem[hmmm...]
  1266. X *     [hmm... violation of global selected vs. what we got, but it's exception
  1267. X *   Insert Noop to be color.
  1268. X *  FC - Fetch Color
  1269. X *   if indexed, get color table from renderer, get color from color table
  1270. X *  fill in
  1271. X */
  1272. Xint GetColorAttribute(strux, elem, rgb)
  1273. X     PEXStructure strux;
  1274. X     long  elem;
  1275. X     PEXColorRGB *rgb;
  1276. X{
  1277. X  int i;
  1278. X  int error;
  1279. X  char *eData;
  1280. X  unsigned long count, length;
  1281. X  PEXOCData *OCData;
  1282. X  long  e;
  1283. X
  1284. X  if (elem == -1) {
  1285. X    rgb->red = 1.0;
  1286. X    rgb->green = 1.0;
  1287. X    rgb->blue = 1.0;
  1288. X    return (0);
  1289. X  }
  1290. X
  1291. X  e = elem-1; /* get to the color element */
  1292. X
  1293. X  if (!(PEXFetchElements( theDisplay, strux,
  1294. X               PEXBeginning, e, PEXBeginning, e, theFF,
  1295. X               &count, &length, &eData ))) { return; }
  1296. X
  1297. X  OCData = PEXDecodeOCs( theFF, count, length, eData );
  1298. X  XFree((char *)eData);
  1299. X
  1300. X  /* no edge or backface color test */
  1301. X  if ((OCData->oc_type  == PEXOCLineColor) ||
  1302. X      (OCData->oc_type  == PEXOCTextColor) ||
  1303. X      (OCData->oc_type  == PEXOCMarkerColor) ||
  1304. X      (OCData->oc_type  == PEXOCSurfaceColor)) { 
  1305. X    if (OCData->data.SetLineColor.color_type != PEXColorTypeRGB)printf("RGB\n");
  1306. X    *rgb = OCData->data.SetLineColor.color.rgb;
  1307. X  } else if ((OCData->oc_type  == PEXOCLineColorIndex) ||
  1308. X      (OCData->oc_type  == PEXOCTextColorIndex) ||
  1309. X      (OCData->oc_type  == PEXOCMarkerColorIndex) ||
  1310. X      (OCData->oc_type  == PEXOCSurfaceColorIndex)) { 
  1311. X    theRenderProcs.GetColorFromIndex(OCData->data.SetLineColorIndex.index, rgb);
  1312. X  } else {
  1313. X    /*
  1314. X     * not a color element, insert a Noop after elem and call color group
  1315. X     */
  1316. X    long struxArray[1];
  1317. X    int elemArray[1];
  1318. X
  1319. X    PEXSetElementPtr( theDisplay, strux, PEXBeginning, e );
  1320. X    PEXNoop(theDisplay,strux,PEXOCStore); /* ColorGroup will replace */
  1321. X    
  1322. X    struxArray[0] = strux;
  1323. X    if ((strux == theSelectedStrux) && (elem >= theSelectedElement)) {
  1324. X      theSelectedElement++;
  1325. X      elemArray[0] = elem+1;
  1326. X    } else {
  1327. X      elemArray[0] = elem;
  1328. X    }
  1329. X    ColorGroup(1,struxArray,elemArray);
  1330. X     
  1331. X    theRenderProcs.GetColorFromIndex(theRandomColorIndex, rgb);
  1332. X  }
  1333. X  return (1);
  1334. X}
  1335. X
  1336. Xint SetColorAttribute(strux, elem, rgb)
  1337. X     PEXStructure strux;
  1338. X     long  elem;
  1339. X     PEXColorRGB *rgb;
  1340. X{
  1341. X  unsigned long length;
  1342. X  PEXElementInfo *eInfo;
  1343. X  unsigned long eCount;
  1344. X  long pe, del;
  1345. X
  1346. X  if ((strux == theSelectedStrux) && (elem == theSelectedElement)) {
  1347. X    pe = elem+1;  /* primitive is behind select color strux */
  1348. X    del = elem;   /* neuter the select color */
  1349. X  } else {
  1350. X    pe = elem;
  1351. X    del = elem-1;
  1352. X  }
  1353. X  
  1354. X
  1355. X  if(PEXGetElementInfo(theDisplay, strux, 
  1356. X                PEXBeginning, pe,
  1357. X                PEXBeginning, pe,
  1358. X                theFF, &eCount, &eInfo )){
  1359. X    if ((eCount == 1) &&
  1360. X    ((eInfo->type >= OCPRIMTAB_BASE) && (eInfo->type <= OCPRIMTAB_MAX))) {
  1361. X
  1362. X      PEXDeleteElements( theDisplay, strux,
  1363. X            PEXBeginning, elem-1,
  1364. X            PEXBeginning, del );
  1365. X
  1366. X      switch (myOCPrimType[eInfo->type-OCPRIMTAB_BASE]) {
  1367. X      case OCPRIM_MARKER:
  1368. X    PEXSetMarkerColor( theDisplay, strux, PEXOCStore,
  1369. X              PEXColorTypeRGB, (PEXColor *)rgb);
  1370. X    break;
  1371. X      case OCPRIM_LINE:
  1372. X    PEXSetLineColor( theDisplay, strux, PEXOCStore,
  1373. X            PEXColorTypeRGB, (PEXColor *)rgb);
  1374. X    break;
  1375. X      case OCPRIM_PGON:
  1376. X    PEXSetSurfaceColor( theDisplay, strux, PEXOCStore, 
  1377. X               PEXColorTypeRGB, (PEXColor *)rgb);
  1378. X    break;
  1379. X      case OCPRIM_TEXT:
  1380. X    PEXSetTextColor( theDisplay, strux, PEXOCStore,
  1381. X            PEXColorTypeRGB, (PEXColor *)rgb);
  1382. X    break;
  1383. X      default:
  1384. X    break;
  1385. X      }
  1386. X      if ((strux == theSelectedStrux) && (elem == theSelectedElement)) {
  1387. X    PEXNoop(theDisplay, strux, PEXOCStore);
  1388. X      }
  1389. X    } else { printf("SetColorAttribute, %d not prim\n",eInfo->type);}
  1390. X  } else { printf("PEXGetStructureInfo failed\n");}
  1391. X}
  1392. X
  1393. XDeleteStrux(strux)
  1394. X     PEXStructure strux;
  1395. X{
  1396. X  PEXDestroyStructures(theDisplay, 1, (PEXStructure *)&strux);
  1397. X  if ((strux == theSelectedStrux) && (theSelectedElement != -1)) {
  1398. X    theSelectedElement = -1;
  1399. X  }
  1400. X}
  1401. X
  1402. XExecStrux(strux)
  1403. X     PEXStructure strux;
  1404. X{
  1405. X  if ((strux == theSelectedStrux) && (theSelectedElement != -1)) {
  1406. X    printf("a structure cannot execute itself\n");
  1407. X    return;
  1408. X  }
  1409. X
  1410. X  PEXSetElementPtr( theDisplay, theSelectedStrux, PEXEnd,  0 );
  1411. X  PEXExecuteStructure(theDisplay, theSelectedStrux, PEXOCStore, strux );
  1412. X}
  1413. X
  1414. END_OF_FILE
  1415.   if test 6070 -ne `wc -c <'pexdrawc.3'`; then
  1416.     echo shar: \"'pexdrawc.3'\" unpacked with wrong size!
  1417.   fi
  1418.   # end of 'pexdrawc.3'
  1419. fi
  1420. if test -f 'ui_x.c' -a "${1}" != "-c" ; then 
  1421.   echo shar: Will not clobber existing file \"'ui_x.c'\"
  1422. else
  1423.   echo shar: Extracting \"'ui_x.c'\" \(11454 characters\)
  1424.   sed "s/^X//" >'ui_x.c' <<'END_OF_FILE'
  1425. X#ifdef SCCS
  1426. Xstatic char sccsid[]="@(#)ui_x.c    1.10 Oki Electric Industry Co., Ltd. 93/05/24";
  1427. X#endif
  1428. X/*
  1429. X    This file is under sccs control at Stardent in:
  1430. X    /nfs/sole/root/sccs1.p/X11R5/mit/demos/pexdraw/s.ui_x.c
  1431. X*/
  1432. X/*
  1433. X *            Copyright (c) 1992 by
  1434. X *            Oki Electric Industry Co., Ltd.
  1435. X *            All Rights Reserved
  1436. X *
  1437. X * Permission to use, copy, modify, and distribute this software and its
  1438. X * documentation for any purpose and without fee is hereby granted,
  1439. X * provided that the above copyright notice appear in all copies and that
  1440. X * both that copyright notice and this permission notice appear in
  1441. X * supporting documentation, and that the name of Oki not be
  1442. X * used in advertising or publicity pertaining to distribution of the
  1443. X * software without specific, written prior permission. Oki
  1444. X * makes no representations about the suitability of this software for any
  1445. X * purpose.  It is provided "as is" without express or implied warranty.
  1446. X *
  1447. X * This supercedes the Stardent copyright granting the same rights that
  1448. X * appeared in the pdraw predecessor to pexdraw.
  1449. X *
  1450. X *************************************************************************
  1451. X *
  1452. X *                         P E X D R A W
  1453. X *
  1454. X *  A PEX drawing program based on PDRAW,
  1455. X *
  1456. X *   This is the NO_MOTIF version of the "user interface".
  1457. X *
  1458. X *  This implements the following routines: InitUserInterface(),
  1459. X *    MainLoop() and AddWorkProc();
  1460. X *
  1461. X *************************************************************************/
  1462. X
  1463. X#include <stdio.h>
  1464. X
  1465. X#include <math.h>
  1466. X
  1467. X#include <X11/Xlib.h>
  1468. X#include <X11/keysym.h>
  1469. X#include <X11/Xutil.h>
  1470. X#include <X11/Xatom.h>
  1471. X
  1472. X#include <X11/PEX5/PEXlib.h>
  1473. X#include "pexdraw.h"
  1474. X
  1475. X
  1476. Xstatic int (*theWorker)();
  1477. Xstatic char *theInfo;
  1478. X
  1479. XPEXVector  theVPN = { 0.0, 0.0, 1.0 };
  1480. XPEXVector  theVUP = { 0.0, 1.0, 1.0 };
  1481. Xint theDBFlag = 1;
  1482. X
  1483. Xint activate(
  1484. X#if NeedFunctionPrototypes
  1485. X         KeySym  /* k */
  1486. X#endif
  1487. X);
  1488. X
  1489. X/*************************************************************************
  1490. X *
  1491. X */
  1492. Xvoid
  1493. XInitUserInterface( argc, argv )
  1494. X     int argc;
  1495. X     char *argv[];
  1496. X{
  1497. X    XVisualInfo     template;
  1498. X    XVisualInfo     *visinfo;
  1499. X    Visual           *visual; 
  1500. X    int            nitems;
  1501. X    XSizeHints        sizehints;
  1502. X    int    i;
  1503. X
  1504. X    char *displayString = (char *)0;
  1505. X    int direct = 0;
  1506. X    char *winstr;
  1507. X    int vis = -1;
  1508. X    int wind_x, wind_y, wind_w = 500, wind_h = 500;
  1509. X
  1510. X    for ( i = 1; i<argc; i++ ) {
  1511. X      if ((strncmp(argv[i],"-geometry",strlen(argv[i]))) == 0) {
  1512. X    printf("found -geom\n");
  1513. X      } else if ((strncmp(argv[i],"-display",strlen(argv[i]))) == 0) {
  1514. X    if (++i > argc) { printf("not enough args"); exit(1); }
  1515. X    displayString = argv[i];
  1516. X      } else if ((strncmp(argv[i],"-pmdb",strlen(argv[i]))) == 0) {
  1517. X    thePMDBFlag = 1; 
  1518. X      } else if ((strncmp(argv[i],"-wks",strlen(argv[i]))) == 0) {
  1519. X    theForceWKSFlag = 1; 
  1520. X      } else if ((strncmp(argv[i],"-direct",strlen(argv[i]))) == 0) {
  1521. X    vis = 1;
  1522. X    direct = 1;
  1523. X      } else if ((strncmp(argv[i],"-true",strlen(argv[i]))) == 0) {
  1524. X    vis = 1;
  1525. X    direct = 0;
  1526. X      }
  1527. X    }
  1528. X
  1529. X  theDisplay = XOpenDisplay(displayString);
  1530. X  if (!theDisplay) { printf(" cannot open display %s\n",displayString); exit(1);}
  1531. X
  1532. X    wind_x = (1280-wind_w)/2;
  1533. X    wind_y = (1024-wind_h)/2;
  1534. X
  1535. X  if ( vis = -1 ) {
  1536. X    theWindow = XCreateSimpleWindow( theDisplay, DefaultRootWindow(theDisplay), 
  1537. X                 wind_x,wind_y,
  1538. X                 wind_w,wind_h,
  1539. X                 2,
  1540. X                 BlackPixel(theDisplay,DefaultScreen(theDisplay)),
  1541. X                 WhitePixel(theDisplay,DefaultScreen(theDisplay)));
  1542. X/*    thePixelDepth = DefaultDepth(theDisplay, DefaultScreen(theDisplay)); */
  1543. X  } else {
  1544. X
  1545. X    /* Get the visual info for a visual of the type we want */
  1546. X    if (direct) {
  1547. X      template.class = DirectColor;
  1548. X      winstr = "DirectColor";
  1549. X    } else {
  1550. X      template.class = TrueColor;
  1551. X      winstr = "TrueColor";
  1552. X    }
  1553. X    visinfo = XGetVisualInfo(theDisplay, VisualClassMask, &template, &nitems);
  1554. X    if (visinfo == NULL) 
  1555. X    {   fprintf(stderr,"Can't create %s window",winstr);
  1556. X    exit(-1);
  1557. X    }
  1558. X    /* This is the visual that we will use */
  1559. X    visual = visinfo->visual;
  1560. X    theWindow = XCreateWindow(theDisplay,
  1561. X               DefaultRootWindow(theDisplay),
  1562. X               wind_x,wind_y,
  1563. X               wind_w,wind_h,
  1564. X               2,
  1565. X               visinfo->depth,
  1566. X               InputOutput,    
  1567. X               visual,
  1568. X               0,0);
  1569. X/*    thePixelDepth = visinfo->depth; */
  1570. X  }
  1571. X    sizehints.x = wind_x;
  1572. X    sizehints.y = wind_y;
  1573. X    sizehints.width = sizehints.max_width = wind_w;
  1574. X    sizehints.height = sizehints.max_height = wind_h;
  1575. X    sizehints.flags = USSize | USPosition;
  1576. X    XSetNormalHints(theDisplay,theWindow,&sizehints);
  1577. X
  1578. X    XMapWindow(theDisplay,theWindow);
  1579. X
  1580. X    XSelectInput(theDisplay,theWindow,
  1581. X         ButtonMotionMask|ButtonPressMask|ButtonReleaseMask|
  1582. X         KeyPressMask|
  1583. X         ExposureMask|StructureNotifyMask);
  1584. X    XFlush(theDisplay);
  1585. X
  1586. X  /* iquire what the default too is and ... */
  1587. X  set_tool_line();
  1588. X
  1589. X  theDynGC = CreateDynGC();
  1590. X
  1591. X  theWorker = 0;
  1592. X}
  1593. X
  1594. Xvoid
  1595. XMainLoop()
  1596. X{
  1597. X  XEvent event;
  1598. X  int done = 0;
  1599. X  int button, length;
  1600. X  KeySym keysym;
  1601. X  char buf[42]; /* why ask why? */
  1602. X  XComposeStatus cs;
  1603. X  XWindowAttributes winAttrs;
  1604. X
  1605. X  while (!done) {
  1606. X    if (!XPending(theDisplay)) {
  1607. X      if (theWorker) if (theWorker(theInfo)) theWorker = 0;
  1608. X    } else {
  1609. X      XNextEvent(theDisplay,&event);
  1610. X      switch (event.type) {
  1611. X    
  1612. X      case Expose:
  1613. X    theRenderProcs.ReDraw();
  1614. X    break;
  1615. X    
  1616. X      case ConfigureNotify:
  1617. X    theWinHeight = event.xconfigure.height;
  1618. X    ResizeWindow( theWindow, event.xconfigure.width, event.xconfigure.height );
  1619. X    theRenderProcs.ReDraw();
  1620. X    break;
  1621. X    
  1622. X      case ButtonPress:
  1623. X    if (event.xbutton.button < 1 || event.xbutton.button > 3) break;
  1624. X    thePressHandlerTable[event.xbutton.button-1](&event);
  1625. X    break;
  1626. X    
  1627. X      case  ButtonRelease:
  1628. X    if (event.xbutton.button < 1 || event.xbutton.button > 3) break;
  1629. X    theReleaseHandlerTable[event.xbutton.button-1](&event);
  1630. X    break;
  1631. X    
  1632. X      case MotionNotify:
  1633. X    if ( event.xmotion.state == Button1MotionMask ) {
  1634. X      button = 0;
  1635. X    } else if ( event.xmotion.state == Button2MotionMask ) {
  1636. X      button = 1;
  1637. X    } else if ( event.xmotion.state == Button3MotionMask ) {
  1638. X      button = 2;
  1639. X    } else {
  1640. X      return;
  1641. X    }
  1642. X    
  1643. X    theMotionHandlerTable[button](&event);
  1644. X    break;
  1645. X    
  1646. X      case KeyPress:
  1647. X    length = XLookupString(&event.xkey, buf, 42, &keysym, &cs );
  1648. X    done = activate(keysym);
  1649. X    break;
  1650. X    
  1651. X      default:
  1652. X    printf("got weird event!!! type = %x\n", event.type);
  1653. X      }
  1654. X    }
  1655. X  }
  1656. X
  1657. X}
  1658. X
  1659. Xint activate(k)
  1660. X     KeySym k;
  1661. X{
  1662. X  switch (k) {
  1663. X
  1664. X  case XK_question:
  1665. X  case XK_h:
  1666. X  case XK_H: /*  k_tool_pointer */
  1667. X    printf("You are in NO_MOTIF mode!, h & ? get this message\n");
  1668. X    printf(" tool selection l - line, p - pointer, t - triangle, v -view\n");
  1669. X    printf(" d - dump strux, k - kill element, a - delete all \n");
  1670. X    printf(" s - spin, i - interior style solid, r - refresh\n");
  1671. X    break;
  1672. X
  1673. X  case XK_p:
  1674. X  case XK_P: /*  k_tool_pointer */
  1675. X    set_tool_pointer();
  1676. X    break;
  1677. X
  1678. X  case XK_l:
  1679. X  case XK_L: /*  k_tool_line */
  1680. X    set_tool_line();
  1681. X    break;
  1682. X
  1683. X  case XK_v:
  1684. X  case XK_V: /*  k_tool_view */
  1685. X    set_tool_view();
  1686. X    break;
  1687. X
  1688. X  case XK_t:
  1689. X  case XK_T: /*  k_tool_tristrip */
  1690. X    set_tool_tristrip();
  1691. X    break;
  1692. X
  1693. X  case XK_d:
  1694. X  case XK_D: /*  k_dump_strux */
  1695. X    DumpStruxCmd(1);
  1696. X    break;
  1697. X
  1698. X  case XK_r:
  1699. X  case XK_R: /*  k_refresh */
  1700. X    theRenderProcs.ReDraw();
  1701. X    break;
  1702. X
  1703. X  case XK_k:
  1704. X  case XK_K: /*  k_delete */
  1705. X    DeleteSelected();
  1706. X    break;
  1707. X
  1708. X  case XK_i:
  1709. X  case XK_I: /*  k_make_solid */
  1710. X    InteriorStyleCmd(PEXInteriorStyleSolid);
  1711. X    break;
  1712. X
  1713. X  case XK_s:
  1714. X  case XK_S: /*  k_spin_slowly */ {
  1715. X    PEXStructure sid;
  1716. X    
  1717. X    if ( theSelectedElement != -1 ) {
  1718. X      sid = theSelectedStrux;
  1719. X    } else if (theNewStrux != 0) {
  1720. X      sid = theNewStrux;
  1721. X    } else break;
  1722. X
  1723. X    if (!StartSpinning(sid)) { /* could not start, must be spinning */
  1724. X      StopSpinning(sid);
  1725. X    }}
  1726. X
  1727. X  case XK_a:
  1728. X  case XK_A: /*  k_delete_all */
  1729. X    StopSpinning((PEXStructure)-1);
  1730. X    PEXRotate(PEXXAxis, 0.0, theMCMatrix.matrix );
  1731. X    theMCMatrix.seqNo = 0;
  1732. X    theRenderProcs.DeleteAll();
  1733. X    break;
  1734. X
  1735. X  case XK_q:
  1736. X  case XK_Q: /*  k_delete_all */
  1737. X    return (1);
  1738. X    break;
  1739. X
  1740. X  default:
  1741. X    break;
  1742. X  }
  1743. X  return (0);
  1744. X}
  1745. X
  1746. Xvoid
  1747. XAddWorkProc(worker,info)
  1748. X     int (*worker)();
  1749. X     char *info;
  1750. X{
  1751. X  theWorker = worker;
  1752. X  theInfo = info;
  1753. X}
  1754. X
  1755. Xint
  1756. XapplyViewSet( viewNumber)
  1757. X     int viewNumber;
  1758. X{
  1759. X  PEXCoord  vrp;  /* view reference point */
  1760. X  PEXVector  vpn;  /* view plane normal    */
  1761. X  PEXVector  vup;  /* view up vector       */
  1762. X  
  1763. X  PEXViewRep vrep;                           /*  view structure */
  1764. X
  1765. X  PEXCoord2D          frame[2];
  1766. X  PEXNPCSubVolume     viewport;
  1767. X  int                 perspective;
  1768. X  PEXCoord            prp;
  1769. X  float               view_plane, back_plane, front_plane;
  1770. X  int err;
  1771. X
  1772. X  int persp;
  1773. X
  1774. X
  1775. X  persp = 0;
  1776. X
  1777. X  vrp.x = 0;
  1778. X  vrp.y = 0;
  1779. X  vrp.z = 0;
  1780. X  
  1781. X  err = PEXViewOrientationMatrix( &vrp, &theVPN, &theVUP,
  1782. X                 vrep.view.orientation);
  1783. X  if (err != 0) {
  1784. X    printf( "view orientation error %d\n",err); return (1);
  1785. X  }
  1786. X
  1787. X
  1788. Xframe[0].x = -3;
  1789. Xframe[1].x = 3;
  1790. Xframe[0].y = -3;
  1791. Xframe[1].y = 3;
  1792. Xviewport.min.x = 0;
  1793. Xviewport.max.x = 1;
  1794. Xviewport.min.y = 0;
  1795. Xviewport.max.y = 1;
  1796. Xviewport.min.z = 0;
  1797. Xviewport.max.z = 1;
  1798. Xprp.x = 0;
  1799. Xprp.y = 0;
  1800. Xprp.z = 10;
  1801. Xview_plane = 0;
  1802. Xback_plane = -5;
  1803. Xfront_plane = 5;
  1804. X
  1805. X  err = PEXViewMappingMatrix( frame, &viewport, persp, &prp,
  1806. X               view_plane, back_plane, front_plane,
  1807. X               vrep.view.mapping);
  1808. X  
  1809. X  if (err != 0) { printf( "view mapping error %d\n",err); return (1); }
  1810. X  
  1811. X  vrep.view.clip_limits.min.x = viewport.min.x;
  1812. X  vrep.view.clip_limits.min.y = viewport.min.y;
  1813. X  vrep.view.clip_limits.min.z = viewport.min.z;
  1814. X  vrep.view.clip_limits.max.x = viewport.max.x;
  1815. X  vrep.view.clip_limits.max.y = viewport.max.y;
  1816. X  vrep.view.clip_limits.max.z = viewport.max.z;
  1817. X  vrep.view.clip_flags = PEXClipXY | PEXClipBack | PEXClipFront;
  1818. X  vrep.index = viewNumber;
  1819. X
  1820. X  theRenderProcs.SetView( 1, &vrep.view );
  1821. X
  1822. X  bcopy((char *)&vrep.view.orientation, (char *)&theMatOri,sizeof(PEXMatrix));
  1823. X  bcopy((char *)&vrep.view.mapping, (char *)&theMatMap, sizeof(PEXMatrix));
  1824. X
  1825. X  theRenderProcs.ReDraw();
  1826. X
  1827. X  return (0);
  1828. X}
  1829. X
  1830. X/*************************************************************************
  1831. X * CreateDynGC - create an X GC Resource for Dynamics.
  1832. X *
  1833. X * Got the rubberbanding methodology from contrib/clients/xfig/w_drawPrim.c
  1834. X * But just the idea, no code was copied, hence no copyright.
  1835. X *
  1836. X * The idea is to xor ( exclusive or ) the foreground and the background
  1837. X * together. When it is xor'd with the background it produces the foreground.
  1838. X */
  1839. XGC CreateDynGC()
  1840. X{
  1841. X  XGCValues values;
  1842. X  unsigned long fg, bg;
  1843. X  GC tGC;
  1844. X
  1845. X  if (theWimpyWindow) {
  1846. X    values.foreground = -1;
  1847. X    values.background = 0;
  1848. X  } else {
  1849. X  bg = BlackPixel(theDisplay,DefaultScreen(theDisplay));
  1850. X  fg = WhitePixel(theDisplay,DefaultScreen(theDisplay));
  1851. X
  1852. X  values.foreground = fg ^ bg;
  1853. X  values.background = bg;
  1854. X  }
  1855. X  values.function = GXxor;
  1856. X  tGC = XCreateGC(theDisplay, theWindow,
  1857. X          GCFunction | GCForeground | GCBackground, &values );
  1858. X  return (tGC);
  1859. X}
  1860. X
  1861. Xvoid GetVPN( viewNumber, vpn )
  1862. X     int viewNumber;
  1863. X     PEXVector  *vpn;
  1864. X{
  1865. X  *vpn = theVPN;
  1866. X}
  1867. X
  1868. Xvoid SetVPN( viewNumber, vpn )
  1869. X     int viewNumber;
  1870. X     PEXVector  *vpn;
  1871. X{
  1872. X  theVPN = *vpn;
  1873. X}
  1874. X
  1875. X
  1876. Xvoid GetVUP( viewNumber, vup )
  1877. X     int viewNumber;
  1878. X     PEXVector  *vup;
  1879. X{
  1880. X  *vup = theVUP;
  1881. X}
  1882. X
  1883. Xvoid SetVUP( viewNumber, vup )
  1884. X     int viewNumber;
  1885. X     PEXVector  *vup;
  1886. X{
  1887. X  theVUP = *vup;
  1888. X}
  1889. X
  1890. XGetSomeTextFromUI( x, y, length, charStr, flags )
  1891. X     int x;
  1892. X     int y;
  1893. X     int *length;
  1894. X     char **charStr;
  1895. X     int *flags;
  1896. X{
  1897. X  *length = strlen("hello world");
  1898. X  *charStr = malloc(*length+1);
  1899. X  strcpy(*charStr, "hello world");
  1900. X  *flags = 0;
  1901. X}
  1902. X
  1903. END_OF_FILE
  1904.   if test 11454 -ne `wc -c <'ui_x.c'`; then
  1905.     echo shar: \"'ui_x.c'\" unpacked with wrong size!
  1906.   fi
  1907.   # end of 'ui_x.c'
  1908. fi
  1909. if test -f 'util/pexutcmaphp.c' -a "${1}" != "-c" ; then 
  1910.   echo shar: Will not clobber existing file \"'util/pexutcmaphp.c'\"
  1911. else
  1912.   echo shar: Extracting \"'util/pexutcmaphp.c'\" \(11684 characters\)
  1913.   sed "s/^X//" >'util/pexutcmaphp.c' <<'END_OF_FILE'
  1914. X/******************************************************************************/
  1915. X/*                                                                            */
  1916. X/*  (c) Copyright Hewlett-Packard Company, 1992, Fort Collins, Colorado       */
  1917. X/*                                                                            */
  1918. X/*                            All Rights Reserved                             */
  1919. X/*                                                                            */
  1920. X/*  Permission to use, copy, modify, and distribute this software and its     */
  1921. X/*  documentation for any purpose and without fee is hereby granted,          */
  1922. X/*  provided that the above copyright notices appear in all copies and that   */
  1923. X/*  both the copyright notices and this permission notice appear in           */
  1924. X/*  supporting documentation, and that the name of Hewlett-Packard not be     */
  1925. X/*  used in advertising or publicity pertaining to distribution of the        */
  1926. X/*  software without specific, written prior permission.                      */
  1927. X/*                                                                            */
  1928. X/*  HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS         */
  1929. X/*  SOFTWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
  1930. X/*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  Hewlett-Packard    */
  1931. X/*  shall not be liable for errors contained herein or direct, indirect,      */
  1932. X/*  special, incidental or consequential damages in connection with the       */
  1933. X/*  furnishing, performance or use of this software.                          */
  1934. X/*                                                                            */
  1935. X/******************************************************************************/
  1936. X
  1937. X/******************************************************************************/
  1938. X/*                                                                            */
  1939. X/* $Source: /BE700/9.0/gtd/R903/wbuild/PEX5/src/test/RCS/pexutcmaphp.c,v $                          */
  1940. X/* $Date: 93/03/17 13:50:37 $                                                 */
  1941. X/* $Revision: 500.1.200.1 $                                                   */
  1942. X/*                                                                            */
  1943. X/* Description:                                                               */
  1944. X/*   Implementation file of Hewlett-Packard-specific routines                 */
  1945. X/*   for PEXUt colormap/visual utilities.                                     */
  1946. X/*                                                                            */
  1947. X/* Notes:                                                                     */
  1948. X/*                                                                            */
  1949. X/******************************************************************************/
  1950. X
  1951. X
  1952. X#include <math.h>
  1953. X#include <stdio.h>
  1954. X#include <stdlib.h>
  1955. X
  1956. X#include <X11/Xlib.h>
  1957. X#include <X11/Xutil.h>
  1958. X#include <X11/Xatom.h>
  1959. X#include <X11/PEX5/PEXlib.h>
  1960. X
  1961. X#include "pexutcmap.h"
  1962. X#include "pexutcmapint.h"
  1963. X#include "pexutcmaphp.h"
  1964. X
  1965. X
  1966. Xstatic short hp_crx_666_dithertable[256] = {
  1967. X/*   0: */   0,   1,   2,   3,   4,   5,   6,   7,
  1968. X/*   8: */   8,   9,  10,  11,  12,  13,  14,  15,
  1969. X/*  16: */  16,  17,  18,  19,  20,  21,  22,  23,
  1970. X/*  24: */  24,  25,  26,  27,  28,  29,  30,  31,
  1971. X/*  32: */  32,  33,  34,  35,  36,  37,  38,  39,
  1972. X/*  40: */ 255, 251, 191, 187, 127, 123, 253, 249,
  1973. X/*  48: */ 189, 185, 125, 121, 239, 235, 175, 171,
  1974. X/*  56: */ 111, 107, 237, 233, 173, 169, 109, 105,
  1975. X/*  64: */ 223, 219, 159, 155,  95,  91, 221, 217,
  1976. X/*  72: */ 157, 153,  93,  89, 254, 250, 190, 186,
  1977. X/*  80: */ 126, 122, 252, 248, 188, 184, 124, 120,
  1978. X/*  88: */ 238, 234, 174, 170, 110, 106, 236, 232,
  1979. X/*  96: */ 172, 168, 108, 104, 222, 218, 158, 154,
  1980. X/* 104: */  94,  90, 220, 216, 156, 152,  92,  88,
  1981. X/* 112: */ 247, 243, 183, 179, 119, 115, 245, 241,
  1982. X/* 120: */ 181, 177, 117, 113, 231, 227, 167, 163,
  1983. X/* 128: */ 103,  99, 229, 225, 165, 161, 101,  97,
  1984. X/* 136: */ 215, 211, 151, 147,  87,  83, 213, 209,
  1985. X/* 144: */ 149, 145,  85,  81, 246, 242, 182, 178,
  1986. X/* 152: */ 118, 114, 244, 240, 180, 176, 116, 112,
  1987. X/* 160: */ 230, 226, 166, 162, 102,  98, 228, 224,
  1988. X/* 168: */ 164, 160, 100,  96, 214, 210, 150, 146,
  1989. X/* 176: */  86,  82, 212, 208, 148, 144,  84,  80,
  1990. X/* 184: */ 207, 203, 143, 139,  79,  75, 205, 201,
  1991. X/* 192: */ 141, 137,  77,  73, 199, 195, 135, 131,
  1992. X/* 200: */  71,  67, 197, 193, 133, 129,  69,  65,
  1993. X/* 208: */  63,  59,  55,  51,  47,  43,  61,  57,
  1994. X/* 216: */  53,  49,  45,  41, 206, 202, 142, 138,
  1995. X/* 224: */  78,  74, 204, 200, 140, 136,  76,  72,
  1996. X/* 232: */ 198, 194, 134, 130,  70,  66, 196, 192,
  1997. X/* 240: */ 132, 128,  68,  64,  62,  58,  54,  50,
  1998. X/* 248: */  46,  42,  60,  56,  52,  48,  44,  40,
  1999. X};
  2000. X
  2001. Xstatic short hp_crx_884_dithertable[256] = {
  2002. X/*   0: */ 255, 251, 223, 219, 253, 249, 221, 217,
  2003. X/*   8: */ 239, 235, 207, 203, 237, 233, 205, 201,
  2004. X/*  16: */ 127, 123,  95,  91, 125, 121,  93,  89,
  2005. X/*  24: */ 111, 107,  79,  75, 109, 105,  77,  73,
  2006. X/*  32: */ 254, 250, 222, 218, 252, 248, 220, 216,
  2007. X/*  40: */ 238, 234, 206, 202, 236, 232, 204, 200,
  2008. X/*  48: */ 126, 122,  94,  90, 124, 120,  92,  88,
  2009. X/*  56: */ 110, 106,  78,  74, 108, 104,  76,  72,
  2010. X/*  64: */ 247, 243, 215, 211, 245, 241, 213, 209,
  2011. X/*  72: */ 231, 227, 199, 195, 229, 225, 197, 193,
  2012. X/*  80: */ 119, 115,  87,  83, 117, 113,  85,  81,
  2013. X/*  88: */ 103,  99,  71,  67, 101,  97,  69,  65,
  2014. X/*  96: */ 246, 242, 214, 210, 244, 240, 212, 208,
  2015. X/* 104: */ 230, 226, 198, 194, 228, 224, 196, 192,
  2016. X/* 112: */ 118, 114,  86,  82, 116, 112,  84,  80,
  2017. X/* 120: */ 102,  98,  70,  66, 100,  96,  68,  64,
  2018. X/* 128: */ 191, 187, 159, 155, 189, 185, 157, 153,
  2019. X/* 136: */ 175, 171, 143, 139, 173, 169, 141, 137,
  2020. X/* 144: */  63,  59,  31,  27,  61,  57,  29,  25,
  2021. X/* 152: */  47,  43,  15,  11,  45,  41,  13,   9,
  2022. X/* 160: */ 190, 186, 158, 154, 188, 184, 156, 152,
  2023. X/* 168: */ 174, 170, 142, 138, 172, 168, 140, 136,
  2024. X/* 176: */  62,  58,  30,  26,  60,  56,  28,  24,
  2025. X/* 184: */  46,  42,  14,  10,  44,  40,  12,   8,
  2026. X/* 192: */ 183, 179, 151, 147, 181, 177, 149, 145,
  2027. X/* 200: */ 167, 163, 135, 131, 165, 161, 133, 129,
  2028. X/* 208: */  55,  51,  23,  19,  53,  49,  21,  17,
  2029. X/* 216: */  39,  35,   7,   3,  37,  33,   5,   1,
  2030. X/* 224: */ 182, 178, 150, 146, 180, 176, 148, 144,
  2031. X/* 232: */ 166, 162, 134, 130, 164, 160, 132, 128,
  2032. X/* 240: */  54,  50,  22,  18,  52,  48,  20,  16,
  2033. X/* 248: */  38,  34,   6,   2,  36,  32,   4,   0,
  2034. X};
  2035. X
  2036. X
  2037. X/* 
  2038. X    This is the value type for the _HP_RGB_SHADING_MAP property.
  2039. X    There may be one entry per Visual.
  2040. X*/
  2041. X
  2042. Xtypedef struct {
  2043. X    VisualID    visualid;
  2044. X    int        interpolation_ramp;
  2045. X} hp_rgb_shading_map_type;
  2046. X
  2047. X/*
  2048. X    Interesting values for the interpolation_ramp field.
  2049. X*/
  2050. X
  2051. X#define HPPEX_INTERP_RAMP_884_CRX     0x011 
  2052. X#define HPPEX_INTERP_RAMP_666_CRX     0x012
  2053. X
  2054. X
  2055. Xint pexut_modify_colormap_for_HP_dependencies (
  2056. X        display,
  2057. X        colormap_id,
  2058. X        vis_info,
  2059. X        capx_info
  2060. X        )
  2061. X
  2062. X        Display                *display;
  2063. X        Colormap            colormap_id;
  2064. X        XVisualInfo            *vis_info;
  2065. X        PEXColorApproxEntry        *capx_info;
  2066. X{
  2067. X    int                num_colors;
  2068. X    unsigned long            pixel_value;
  2069. X    XColor                *new_colors, *source_colors, *p_color;
  2070. X    short                *translation_table;
  2071. X    int                base_pixel;
  2072. X
  2073. X    int                ramp_index;
  2074. X    hp_rgb_shading_map_type        *shading_map_data;
  2075. X    int                shading_map_count;
  2076. X    int                i;
  2077. X
  2078. X    Atom                property_atom;
  2079. X    Atom                    actual_type;
  2080. X    int                actual_format;
  2081. X    unsigned long           item_count;
  2082. X    unsigned long           item_count_return, bytes_unread;
  2083. X    int                result;
  2084. X
  2085. X
  2086. X    /*
  2087. X        If using X protocol, the remote server's rendering behavior
  2088. X        does not affect the local rendering, so ignore the property.
  2089. X        Otherwise, try to fetch it.
  2090. X    */
  2091. X
  2092. X    if (!strcmp("X",getenv("HPPEX_CLIENT_PROTOCOL")))
  2093. X        return PEXUtUnmodifiedResource;
  2094. X
  2095. X
  2096. X    /*
  2097. X        Currently nothing to do on any HP platform for PEXColorRange.
  2098. X    */
  2099. X    
  2100. X    if (capx_info->type != PEXColorSpace)
  2101. X        return PEXUtUnmodifiedResource;
  2102. X
  2103. X
  2104. X    /*
  2105. X        Determine if the _HP_RGB_SHADING_MAP property is defined on
  2106. X        the server, and if so get its value.
  2107. X    */
  2108. X
  2109. X    ramp_index = 0;
  2110. X
  2111. X
  2112. X    /*
  2113. X        Get the atom from the X server.  If it doesn't exist,
  2114. X        neither does the property.  In this case, succeed silently.
  2115. X    */
  2116. X
  2117. X    property_atom = XInternAtom(display, "_HP_RGB_SHADING_MAP", True);
  2118. X    if (property_atom == None) {
  2119. X        return PEXUtUnmodifiedResource;
  2120. X    }
  2121. X
  2122. X
  2123. X    /* 
  2124. X        Property atom exists - fetch the property.
  2125. X    */
  2126. X
  2127. X    bytes_unread = 0;
  2128. X    item_count = sizeof(hp_rgb_shading_map_type)/4;
  2129. X    do {
  2130. X        item_count += (bytes_unread+3)/4;
  2131. X        result = XGetWindowProperty (display, 
  2132. X                    RootWindow(display, vis_info->screen),
  2133. X                    property_atom,
  2134. X                    0, item_count, False, 
  2135. X                    property_atom,
  2136. X                    &actual_type, &actual_format, 
  2137. X                    &item_count_return, &bytes_unread,
  2138. X                    (unsigned char **) &shading_map_data);
  2139. X
  2140. X    } while ((result == Success) && (bytes_unread > 0));
  2141. X
  2142. X    if (result != Success)
  2143. X        return PEXUtUnmodifiedResource;
  2144. X
  2145. X    /*
  2146. X        Search for an entry for the specified visual in the returned data.
  2147. X    */
  2148. X
  2149. X    ramp_index = 0;
  2150. X    shading_map_count = item_count_return/(sizeof(hp_rgb_shading_map_type)/4);
  2151. X    for (i=0; i<shading_map_count; i++) {
  2152. X
  2153. X        if (vis_info->visualid == shading_map_data[i].visualid) {
  2154. X
  2155. X        ramp_index = shading_map_data[i].interpolation_ramp;
  2156. X        break;
  2157. X        }
  2158. X    }
  2159. X
  2160. X    if (item_count_return > 0)
  2161. X        XFree (shading_map_data);
  2162. X    if (ramp_index == 0) 
  2163. X        return PEXUtUnmodifiedResource;
  2164. X
  2165. X
  2166. X    /*
  2167. X        See if this is one of the interesting values for 
  2168. X        the interpolation ramp, if not interesting quit now.
  2169. X    */
  2170. X
  2171. X    if ((ramp_index == HPPEX_INTERP_RAMP_884_CRX) &&
  2172. X        (capx_info->max1 == 7) && (capx_info->mult1 == 32) &&
  2173. X        (capx_info->max2 == 7) && (capx_info->mult2 == 4) &&
  2174. X        (capx_info->max3 == 3) && (capx_info->mult3 == 1) &&
  2175. X        (capx_info->base_pixel == 0))
  2176. X    {
  2177. X
  2178. X        translation_table = hp_crx_884_dithertable;
  2179. X        base_pixel = 0;
  2180. X        num_colors = 256;
  2181. X    }
  2182. X    else if ((ramp_index == HPPEX_INTERP_RAMP_666_CRX) && 
  2183. X        (capx_info->max1 == 5) && (capx_info->mult1 == 36) &&
  2184. X        (capx_info->max2 == 5) && (capx_info->mult2 == 6) &&
  2185. X        (capx_info->max3 == 5) && (capx_info->mult3 == 1) &&
  2186. X        (capx_info->base_pixel == 40))
  2187. X    {
  2188. X        translation_table = hp_crx_666_dithertable;
  2189. X        base_pixel = 40;
  2190. X        num_colors = 216;
  2191. X    }
  2192. X    else
  2193. X        return PEXUtUnmodifiedResource;
  2194. X
  2195. X
  2196. X    /*
  2197. X        Allocate storage and fetch the current colormap contents.
  2198. X    */
  2199. X
  2200. X    if ((source_colors = (XColor *) 
  2201. X            malloc (num_colors * sizeof(XColor))) == NULL) {
  2202. X
  2203. X        return PEXUtAllocFailure;
  2204. X    }
  2205. X
  2206. X    for (pixel_value = base_pixel, p_color = source_colors; 
  2207. X        pixel_value < base_pixel + num_colors; 
  2208. X        pixel_value++, p_color++) {
  2209. X
  2210. X        p_color->pixel = pixel_value;
  2211. X    }
  2212. X    XQueryColors (display, colormap_id, source_colors, num_colors);
  2213. X
  2214. X
  2215. X    /*
  2216. X        Allocate storage for a new set of colors for the ramp.
  2217. X    */
  2218. X
  2219. X    if ((new_colors = (XColor *) 
  2220. X            malloc (num_colors * sizeof(XColor))) == NULL) {
  2221. X
  2222. X        free (source_colors);
  2223. X        return PEXUtAllocFailure;
  2224. X    }
  2225. X
  2226. X    
  2227. X    /*
  2228. X        Copy colors from the original ramp, but in the shuffled order.
  2229. X    */
  2230. X
  2231. X    p_color = new_colors;
  2232. X    for (pixel_value = base_pixel; 
  2233. X        pixel_value < base_pixel + num_colors; 
  2234. X        pixel_value++) {
  2235. X
  2236. X        p_color->flags = DoRed | DoGreen | DoBlue;
  2237. X        p_color->pixel = translation_table[pixel_value];
  2238. X        p_color->red = source_colors[pixel_value - base_pixel].red;
  2239. X        p_color->green = source_colors[pixel_value - base_pixel].green;
  2240. X        p_color->blue = source_colors[pixel_value - base_pixel].blue;
  2241. X        p_color++;
  2242. X    }
  2243. X
  2244. X
  2245. X    /*
  2246. X        Load the color map.
  2247. X    */
  2248. X
  2249. X    XStoreColors (display, colormap_id, new_colors, num_colors);
  2250. X
  2251. X
  2252. X    /*
  2253. X        Free the temporary storage.
  2254. X    */
  2255. X
  2256. X    free (new_colors);
  2257. X    free (source_colors);
  2258. X
  2259. X    return PEXUtModifiedResource;
  2260. X
  2261. X} /* pexut_modify_colormap_for_HP_dependencies */
  2262. END_OF_FILE
  2263.   if test 11684 -ne `wc -c <'util/pexutcmaphp.c'`; then
  2264.     echo shar: \"'util/pexutcmaphp.c'\" unpacked with wrong size!
  2265.   fi
  2266.   # end of 'util/pexutcmaphp.c'
  2267. fi
  2268. echo shar: End of archive 13 \(of 14\).
  2269. cp /dev/null ark13isdone
  2270. MISSING=""
  2271. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
  2272.     if test ! -f ark${I}isdone ; then
  2273.     MISSING="${MISSING} ${I}"
  2274.     fi
  2275. done
  2276. if test "${MISSING}" = "" ; then
  2277.     echo You have unpacked all 14 archives.
  2278.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2279.     echo "concatentating pexdraw.c ..."
  2280.     cat pexdrawc.? > pexdraw.c
  2281.     rm pexdrawc.?
  2282.     echo "concatentating pexdraw.uil ..."
  2283.     cat pexdrawu.? > pexdraw.uil
  2284.     rm pexdrawu.?
  2285.     echo "concatentating teapot.c ..."
  2286.     rm teapotc.?
  2287. else
  2288.     echo You still must unpack the following archives:
  2289.     echo "        " ${MISSING}
  2290. fi
  2291. exit 0
  2292. exit 0 # Just in case...
  2293. -- 
  2294.   // chris@IMD.Sterling.COM       | Send comp.sources.x submissions to:
  2295. \X/  Amiga - The only way to fly! |    sources-x@imd.sterling.com
  2296.  "It's intuitively obvious to the |
  2297.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  2298.