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

  1. Newsgroups: comp.sources.x
  2. From: jch@okimicro.oki.com (Jan Hardenbergh)
  3. Subject: v20i015:  pexdraw - A PEX drawing program, Part05/14
  4. Message-ID: <1993Jun8.150120.18870@sparky.imd.sterling.com>
  5. X-Md4-Signature: a85436da20844dcda299c0a0fd767a00
  6. Sender: chris@sparky.imd.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Tue, 8 Jun 1993 15:01:20 GMT
  9. Approved: chris@sparky.imd.sterling.com
  10.  
  11. Submitted-by: jch@okimicro.oki.com (Jan Hardenbergh)
  12. Posting-number: Volume 20, Issue 15
  13. Archive-name: pexdraw/part05
  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:  plogo.c ui.c
  21. # Wrapped by chris@sparky on Tue Jun  8 09:46:32 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 5 (of 14)."'
  25. if test -f 'plogo.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'plogo.c'\"
  27. else
  28.   echo shar: Extracting \"'plogo.c'\" \(13664 characters\)
  29.   sed "s/^X//" >'plogo.c' <<'END_OF_FILE'
  30. X#ifdef SCCS
  31. Xstatic char sccsid[]="@(#)plcube.c    1.1 Oki 93/05/18";
  32. X#endif
  33. X/*
  34. X * plogo.c - PEXlib logo
  35. X   cc -o plcube plcube.c -lPEX5 -lm -lX11                    -lnsl
  36. X   
  37. X            Copyright (c) 1992, 1993 by 
  38. X            Oki Electric Industry Co., Ltd.
  39. X            All Rights Reserved
  40. X    
  41. X * Permission to use, copy, modify, and distribute this software and its
  42. X * documentation for any purpose and without fee is hereby granted,
  43. X * provided that the above copyright notice appear in all copies and that
  44. X * both that copyright notice and this permission notice appear in
  45. X * supporting documentation, and that the name of Oki not be
  46. X * used in advertising or publicity pertaining to distribution of the
  47. X * software without specific, written prior permission. Oki
  48. X * makes no representations about the suitability of this software for any
  49. X * purpose.  It is provided "as is" without express or implied warranty.
  50. X*/
  51. X
  52. X#define NeedFunctionPrototypes 1
  53. X
  54. X#include <X11/Xlib.h>
  55. X#include <X11/PEX5/PEXlib.h>
  56. X
  57. X#define SET_POINT(p,a,b,c) {(p)->x=(a);(p)->y=(b);(p)->z=(c);}
  58. X
  59. X#define RADIAN(x) ((x)*(3.1415927 / 180.0))
  60. X
  61. X
  62. XPEXColorRGB red     = {1,0,0};
  63. XPEXColorRGB green   = {0,1,0};
  64. XPEXColorRGB blue    = {0,0,1};
  65. XPEXColorRGB cyan    = {0,1,1};
  66. XPEXColorRGB magenta = {1,0,1};
  67. XPEXColorRGB yellow  = {1,1,0};
  68. X
  69. XPEXColorRGB purple  = {1,0,0.8};
  70. X
  71. XDisplay        *theDisplay;
  72. XPEXStructure     theStrux;
  73. X
  74. Xmain (argc, argv)
  75. X     int argc;
  76. X     char  *argv[];
  77. X{
  78. X  char            *displayString = (char *)0;
  79. X  PEXExtensionInfo    *info_return;
  80. X  char            err_msg[PEXErrorStringLength];
  81. X  int                   i;
  82. X  PEXCoord p[2];
  83. X  PEXCoord verts[30], *pts;
  84. X  PEXVector normals[30], *ns;
  85. X  PEXArrayOfFacetData fData;
  86. X  PEXArrayOfVertex vData;
  87. X
  88. X  PEXVector shift, scale;
  89. X  PEXMatrix bldmat, scaleMatrix;
  90. X  PEXCoord  pt;
  91. X  double x_ang, y_ang, z_ang;
  92. X
  93. X  for ( i = 1; i<argc; i++ ) {
  94. X    if ((strncmp(argv[i],"-display",strlen(argv[i]))) == 0) {
  95. X      if (++i > argc) { printf("not enough args"); exit(1); }
  96. X      displayString = argv[i];
  97. X    } else if ((strncmp(argv[i],"-strux",strlen(argv[i]))) == 0) {
  98. X      if (++i > argc) { printf("not enough args"); exit(1); }
  99. X      theStrux = atoi(argv[i]);
  100. X    }
  101. X  }
  102. X
  103. X  /*
  104. X   * Open the display and initialize the PEX extension.
  105. X   */
  106. X  
  107. X  if (!(theDisplay = XOpenDisplay(displayString)))
  108. X    {
  109. X      printf ( "Could not open display %s\n",displayString);
  110. X      exit (1);
  111. X    }
  112. X  
  113. X  if (PEXInitialize(theDisplay, &info_return, PEXErrorStringLength, err_msg))
  114. X    {
  115. X      printf ("%s\n", err_msg);
  116. X      exit (1);        
  117. X    }
  118. X
  119. X  PEXSetLineColorIndex( theDisplay, theStrux, PEXOCStore, 2);
  120. X  p[0].x = -3; p[0].y = -2; p[0].z = 0;
  121. X  p[1].x = 3; p[1].y = -2; p[1].z = 0;
  122. X  PEXPolyline(theDisplay, theStrux, PEXOCStore, 2, p );
  123. X
  124. X  scale.x = 0.7; scale.y = -0.7; scale.z = 0.7;
  125. X  PEXScale(&scale,scaleMatrix);
  126. X  shift.x = -3; shift.y = 0; shift.z = 0;
  127. X  PEXTranslate(&shift,bldmat);
  128. X  PEXMatrixMult( scaleMatrix, bldmat, bldmat );
  129. X
  130. X  PEXSetLocalTransform( theDisplay, theStrux, PEXOCStore,
  131. X                      PEXPreConcatenate, bldmat);
  132. X  PutPEXlib();
  133. X  
  134. X  XSync(theDisplay,0); /* must sync before we exit, we care about the strux */
  135. X}
  136. X
  137. X
  138. XPutPEXlib()
  139. X{
  140. X  PEXCoord points[30], *pts;
  141. X  PEXListOfCoord lop[2];
  142. X  
  143. X  pts = points;
  144. X  
  145. X  pts->x = 0.1434; pts->y = 1.625; pts->z = -0.1; pts++;
  146. X  pts->x = 0.1434; pts->y = 0.92486; pts->z = -0.1; pts++;
  147. X  pts->x = 0.39947; pts->y = 0.92486; pts->z = -0.1; pts++;
  148. X  pts->x = 0.39947; pts->y = 1.625; pts->z = -0.1; pts++;
  149. X  
  150. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  151. X             PEXColorTypeRGB, (PEXColor *)&red );
  152. X  
  153. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  154. X          PEXShapeComplex, True, 4, points );
  155. X  
  156. X  pts = points;
  157. X  
  158. X  pts->x = 0.1434; pts->y = 0.87487; pts->z = -0.1; pts++;
  159. X  pts->x = 0.1434; pts->y = 0.77489; pts->z = -0.1; pts++;
  160. X  pts->x = 0.61286; pts->y = 0.77489; pts->z = -0.1; pts++;
  161. X  pts->x = 0.7409; pts->y = 0.7249; pts->z = -0.1; pts++;
  162. X  pts->x = 0.82625; pts->y = 0.67491; pts->z = -0.1; pts++;
  163. X  pts->x = 0.86893; pts->y = 0.57492; pts->z = -0.1; pts++;
  164. X  pts->x = 0.86893; pts->y = 0.42495; pts->z = -0.1; pts++;
  165. X  pts->x = 0.82625; pts->y = 0.32497; pts->z = -0.1; pts++;
  166. X  pts->x = 0.7409; pts->y = 0.27498; pts->z = -0.1; pts++;
  167. X  pts->x = 0.61286; pts->y = 0.22499; pts->z = -0.1; pts++;
  168. X  pts->x = 0.39947; pts->y = 0.22499; pts->z = -0.1; pts++;
  169. X  pts->x = 0.39947; pts->y = 0.7249; pts->z = -0.1; pts++;
  170. X  pts->x = 0.1434; pts->y = 0.7249; pts->z = -0.1; pts++;
  171. X  pts->x = 0.1434; pts->y = 0.125; pts->z = -0.1; pts++;
  172. X  pts->x = 0.7409; pts->y = 0.125; pts->z = -0.1; pts++;
  173. X  pts->x = 0.91161; pts->y = 0.17499; pts->z = -0.1; pts++;
  174. X  pts->x = 0.99697; pts->y = 0.22499; pts->z = -0.1; pts++;
  175. X  pts->x = 1.08232; pts->y = 0.32497; pts->z = -0.1; pts++;
  176. X  pts->x = 1.125; pts->y = 0.42495; pts->z = -0.1; pts++;
  177. X  pts->x = 1.125; pts->y = 0.57492; pts->z = -0.1; pts++;
  178. X  pts->x = 1.08232; pts->y = 0.67491; pts->z = -0.1; pts++;
  179. X  pts->x = 0.99697; pts->y = 0.77489; pts->z = -0.1; pts++;
  180. X  pts->x = 0.91161; pts->y = 0.82488; pts->z = -0.1; pts++;
  181. X  pts->x = 0.7409; pts->y = 0.87487; pts->z = -0.1; pts++;
  182. X  
  183. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  184. X             PEXColorTypeRGB, (PEXColor *)&red );
  185. X  
  186. X  
  187. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  188. X          PEXShapeComplex, True, 24, points );
  189. X  
  190. X  pts = points;
  191. X  
  192. X  pts->x = 1.25; pts->y = 1.625; pts->z = -0.1; pts++;
  193. X  pts->x = 1.25; pts->y = 0.92512; pts->z = -0.1; pts++;
  194. X  pts->x = 1.50608; pts->y = 0.92512; pts->z = -0.1; pts++;
  195. X  pts->x = 1.50608; pts->y = 1.52499; pts->z = -0.1; pts++;
  196. X  pts->x = 2.14625; pts->y = 1.52499; pts->z = -0.1; pts++;
  197. X  pts->x = 2.14625; pts->y = 1.625; pts->z = -0.1; pts++;
  198. X  
  199. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  200. X             PEXColorTypeRGB, (PEXColor *)&green );
  201. X  
  202. X  
  203. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  204. X          PEXShapeComplex, True, 6, points );
  205. X  
  206. X  pts = points;
  207. X  
  208. X  pts->x = 1.25; pts->y = 0.87513; pts->z = -0.1; pts++;
  209. X  pts->x = 1.25; pts->y = 0.77514; pts->z = -0.1; pts++;
  210. X  pts->x = 2.14625; pts->y = 0.77514; pts->z = -0.1; pts++;
  211. X  pts->x = 2.14625; pts->y = 0.87513; pts->z = -0.1; pts++;
  212. X  
  213. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  214. X             PEXColorTypeRGB, (PEXColor *)&green );
  215. X  
  216. X  
  217. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  218. X          PEXShapeComplex, True, 4, points );
  219. X  
  220. X  pts = points;
  221. X  
  222. X  pts->x = 1.25; pts->y = 0.72376; pts->z = -0.1; pts++;
  223. X  pts->x = 1.25; pts->y = 0.12386; pts->z = -0.1; pts++;
  224. X  pts->x = 2.14625; pts->y = 0.12386; pts->z = -0.1; pts++;
  225. X  pts->x = 2.14625; pts->y = 0.22385; pts->z = -0.1; pts++;
  226. X  pts->x = 1.50608; pts->y = 0.22385; pts->z = -0.1; pts++;
  227. X  pts->x = 1.50608; pts->y = 0.72376; pts->z = -0.1; pts++;
  228. X  
  229. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  230. X             PEXColorTypeRGB, (PEXColor *)&green );
  231. X  
  232. X  
  233. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  234. X          PEXShapeComplex, True, 6, points );
  235. X  
  236. X  pts = points;
  237. X  
  238. X  pts->x = 2.40232; pts->y = 1.62386; pts->z = -0.1; pts++;
  239. X  pts->x = 2.82911; pts->y = 0.87373; pts->z = -0.1; pts++;
  240. X  pts->x = 2.40232; pts->y = 0.12386; pts->z = -0.1; pts++;
  241. X  pts->x = 2.65839; pts->y = 0.12386; pts->z = -0.1; pts++;
  242. X  pts->x = 2.99982; pts->y = 0.72376; pts->z = -0.1; pts++;
  243. X  pts->x = 2.48768; pts->y = 1.62386; pts->z = -0.1; pts++;
  244. X  
  245. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  246. X             PEXColorTypeRGB, (PEXColor *)&blue );
  247. X  
  248. X  
  249. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  250. X          PEXShapeComplex, True, 6, points );
  251. X  
  252. X  pts = points;
  253. X  
  254. X  pts->x = 3.25589; pts->y = 1.62386; pts->z = -0.1; pts++;
  255. X  pts->x = 2.91447; pts->y = 1.02371; pts->z = -0.1; pts++;
  256. X  pts->x = 3.42661; pts->y = 0.12386; pts->z = -0.1; pts++;
  257. X  pts->x = 3.51233; pts->y = 0.12386; pts->z = -0.1; pts++;
  258. X  pts->x = 3.08518; pts->y = 0.87373; pts->z = -0.1; pts++;
  259. X  pts->x = 3.51233; pts->y = 1.62386; pts->z = -0.1; pts++;
  260. X  pts->x = 3.25589; pts->y = 1.62386; pts->z = -0.1; pts++;
  261. X  
  262. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  263. X             PEXColorTypeRGB, (PEXColor *)&blue );
  264. X  
  265. X  
  266. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  267. X          PEXShapeComplex, True, 7, points );
  268. X  
  269. X  pts = points;
  270. X  
  271. X  pts->x = 3.75; pts->y = 0.375; pts->z = -0.1; pts++;
  272. X  pts->x = 3.875; pts->y = 0.25; pts->z = -0.1; pts++;
  273. X  pts->x = 4.02367; pts->y = 0.14236; pts->z = -0.1; pts++;
  274. X  pts->x = 4.125; pts->y = 0.125; pts->z = -0.1; pts++;
  275. X  pts->x = 4.21117; pts->y = 0.15972; pts->z = -0.1; pts++;
  276. X  pts->x = 4.25; pts->y = 0.25; pts->z = -0.1; pts++;
  277. X  pts->x = 4.0; pts->y = 1.375; pts->z = -0.1; pts++;
  278. X  pts->x = 4.04798; pts->y = 1.48264; pts->z = -0.1; pts++;
  279. X  pts->x = 4.22506; pts->y = 1.45139; pts->z = -0.1; pts++;
  280. X  pts->x = 4.375; pts->y = 1.375; pts->z = -0.1; pts++;
  281. X  pts->x = 4.25; pts->y = 1.5; pts->z = -0.1; pts++;
  282. X  pts->x = 4.10354; pts->y = 1.60417; pts->z = -0.1; pts++;
  283. X  pts->x = 4.0; pts->y = 1.625; pts->z = -0.1; pts++;
  284. X  pts->x = 3.91951; pts->y = 1.58333; pts->z = -0.1; pts++;
  285. X  pts->x = 3.875; pts->y = 1.5; pts->z = -0.1; pts++;
  286. X  pts->x = 4.125; pts->y = 0.375; pts->z = -0.1; pts++;
  287. X  pts->x = 4.08617; pts->y = 0.26042; pts->z = -0.1; pts++;
  288. X  pts->x = 3.90562; pts->y = 0.29861; pts->z = -0.1; pts++;
  289. X  pts->x = 3.75; pts->y = 0.375; pts->z = -0.1; pts++;
  290. X  
  291. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  292. X             PEXColorTypeRGB, (PEXColor *)&cyan );
  293. X  
  294. X  
  295. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  296. X          PEXShapeComplex, True, 19, points );
  297. X  
  298. X  pts = points;
  299. X  
  300. X  pts->x = 4.54104; pts->y = 0.84028; pts->z = -0.1; pts++;
  301. X  pts->x = 4.69034; pts->y = 0.69792; pts->z = -0.1; pts++;
  302. X  pts->x = 4.77715; pts->y = 0.64583; pts->z = -0.1; pts++;
  303. X  pts->x = 4.87437; pts->y = 0.64236; pts->z = -0.1; pts++;
  304. X  pts->x = 4.9334; pts->y = 0.71875; pts->z = -0.1; pts++;
  305. X  pts->x = 4.93687; pts->y = 0.85069; pts->z = -0.1; pts++;
  306. X  pts->x = 4.81944; pts->y = 1.36806; pts->z = -0.1; pts++;
  307. X  pts->x = 4.86742; pts->y = 1.47569; pts->z = -0.1; pts++;
  308. X  pts->x = 5.04451; pts->y = 1.44444; pts->z = -0.1; pts++;
  309. X  pts->x = 5.19444; pts->y = 1.36806; pts->z = -0.1; pts++;
  310. X  pts->x = 5.06944; pts->y = 1.49306; pts->z = -0.1; pts++;
  311. X  pts->x = 4.92298; pts->y = 1.59722; pts->z = -0.1; pts++;
  312. X  pts->x = 4.81944; pts->y = 1.61806; pts->z = -0.1; pts++;
  313. X  pts->x = 4.73895; pts->y = 1.57639; pts->z = -0.1; pts++;
  314. X  pts->x = 4.69444; pts->y = 1.49306; pts->z = -0.1; pts++;
  315. X  pts->x = 4.8327; pts->y = 0.86458; pts->z = -0.1; pts++;
  316. X  pts->x = 4.8084; pts->y = 0.75694; pts->z = -0.1; pts++;
  317. X  pts->x = 4.72854; pts->y = 0.75694; pts->z = -0.1; pts++;
  318. X  pts->x = 4.54104; pts->y = 0.84028; pts->z = -0.1; pts++;
  319. X  
  320. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  321. X             PEXColorTypeRGB, (PEXColor *)&magenta );
  322. X  
  323. X  
  324. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  325. X          PEXShapeComplex, True, 19, points );
  326. X  
  327. X  pts = points;
  328. X  
  329. X  pts->x = 4.84312; pts->y = 0.30208; pts->z = -0.1; pts++;
  330. X  pts->x = 4.95423; pts->y = 0.30208; pts->z = -0.1; pts++;
  331. X  pts->x = 5.02367; pts->y = 0.37153; pts->z = -0.1; pts++;
  332. X  pts->x = 5.02367; pts->y = 0.48611; pts->z = -0.1; pts++;
  333. X  pts->x = 4.9577; pts->y = 0.54514; pts->z = -0.1; pts++;
  334. X  pts->x = 4.85354; pts->y = 0.54514; pts->z = -0.1; pts++;
  335. X  pts->x = 4.78409; pts->y = 0.48611; pts->z = -0.1; pts++;
  336. X  pts->x = 4.78756; pts->y = 0.36458; pts->z = -0.1; pts++;
  337. X  
  338. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  339. X             PEXColorTypeRGB, (PEXColor *)&magenta );
  340. X  
  341. X  
  342. X  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
  343. X          PEXShapeComplex, True, 8, points );
  344. X  
  345. X  pts = points;
  346. X  
  347. X  pts->x = 5.38889; pts->y = 0.375; pts->z = -0.1; pts++;
  348. X  pts->x = 5.51389; pts->y = 0.25; pts->z = -0.1; pts++;
  349. X  pts->x = 5.66256; pts->y = 0.14236; pts->z = -0.1; pts++;
  350. X  pts->x = 5.76389; pts->y = 0.125; pts->z = -0.1; pts++;
  351. X  pts->x = 5.85006; pts->y = 0.15972; pts->z = -0.1; pts++;
  352. X  pts->x = 5.88889; pts->y = 0.25; pts->z = -0.1; pts++;
  353. X  pts->x = 5.72159; pts->y = 0.99306; pts->z = -0.1; pts++;
  354. X  pts->x = 5.81534; pts->y = 0.89236; pts->z = -0.1; pts++;
  355. X  pts->x = 5.92992; pts->y = 0.82986; pts->z = -0.1; pts++;
  356. X  pts->x = 6.10006; pts->y = 0.82986; pts->z = -0.1; pts++;
  357. X  pts->x = 6.22159; pts->y = 0.95833; pts->z = -0.1; pts++;
  358. X  pts->x = 6.14173; pts->y = 1.34375; pts->z = -0.1; pts++;
  359. X  pts->x = 6.1; pts->y = 1.42; pts->z = -0.1; pts++;
  360. X  pts->x = 6.01389; pts->y = 1.51736; pts->z = -0.1; pts++;
  361. X  pts->x = 5.81534; pts->y = 1.59375; pts->z = -0.1; pts++;
  362. X  pts->x = 5.63889; pts->y = 1.625; pts->z = -0.1; pts++;
  363. X  pts->x = 5.5584; pts->y = 1.58333; pts->z = -0.1; pts++;
  364. X  pts->x = 5.51389; pts->y = 1.5; pts->z = -0.1; pts++;
  365. X  pts->x = 5.76389; pts->y = 0.375; pts->z = -0.1; pts++;
  366. X  pts->x = 5.72506; pts->y = 0.26042; pts->z = -0.1; pts++;
  367. X  pts->x = 5.54451; pts->y = 0.29861; pts->z = -0.1; pts++;
  368. X  pts->x = 5.38889; pts->y = 0.375; pts->z = -0.1; pts++;
  369. X  
  370. X  /* start inside of b */
  371. X  
  372. X  pts->x = 5.70423; pts->y = 1.10417; pts->z = -0.1; pts++;
  373. X  pts->x = 5.63826; pts->y = 1.41667; pts->z = -0.1; pts++;
  374. X  pts->x = 5.72506; pts->y = 1.50694; pts->z = -0.1; pts++;
  375. X  pts->x = 5.87437; pts->y = 1.46528; pts->z = -0.1; pts++;
  376. X  pts->x = 6.01326; pts->y = 1.34028; pts->z = -0.1; pts++;
  377. X  pts->x = 6.08965; pts->y = 1.0; pts->z = -0.1; pts++;
  378. X  pts->x = 6.01673; pts->y = 0.93403; pts->z = -0.1; pts++;
  379. X  pts->x = 5.82229; pts->y = 0.98958; pts->z = -0.1; pts++;
  380. X  
  381. X  lop[0].count = 22;
  382. X  lop[0].points = &points[0];
  383. X  lop[1].count = 8;
  384. X  lop[1].points = &points[22];
  385. X  
  386. X  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
  387. X             PEXColorTypeRGB, (PEXColor *)&yellow );
  388. X  
  389. X  
  390. X  PEXFillAreaSet(  theDisplay, theStrux, PEXOCStore,
  391. X         PEXShapeComplex, True, PEXContourNested, 2, lop );
  392. X}
  393. END_OF_FILE
  394.   if test 13664 -ne `wc -c <'plogo.c'`; then
  395.     echo shar: \"'plogo.c'\" unpacked with wrong size!
  396.   fi
  397.   # end of 'plogo.c'
  398. fi
  399. if test -f 'ui.c' -a "${1}" != "-c" ; then 
  400.   echo shar: Will not clobber existing file \"'ui.c'\"
  401. else
  402.   echo shar: Extracting \"'ui.c'\" \(43663 characters\)
  403.   sed "s/^X//" >'ui.c' <<'END_OF_FILE'
  404. X#ifdef SCCS
  405. Xstatic char sccsid[]="@(#)ui.c    1.19 Oki Electric Industry Co., Ltd. 93/05/24";
  406. X#endif
  407. X/*
  408. X    This file is under sccs control at Stardent in:
  409. X    /nfs/sole/root/sccs1.p/X11R5/mit/demos/pexdraw/s.ui.c
  410. X*/
  411. X/*
  412. X *            Copyright (c) 1992 by
  413. X *            Oki Electric Industry Co., Ltd.
  414. X *            All Rights Reserved
  415. X *
  416. X * Permission to use, copy, modify, and distribute this software and its
  417. X * documentation for any purpose and without fee is hereby granted,
  418. X * provided that the above copyright notice appear in all copies and that
  419. X * both that copyright notice and this permission notice appear in
  420. X * supporting documentation, and that the name of Oki not be
  421. X * used in advertising or publicity pertaining to distribution of the
  422. X * software without specific, written prior permission. Oki
  423. X * makes no representations about the suitability of this software for any
  424. X * purpose.  It is provided "as is" without express or implied warranty.
  425. X *
  426. X * This supercedes the Stardent copyright granting the same rights that
  427. X * appeared in the pdraw predecessor to pexdraw.
  428. X *
  429. X *************************************************************************
  430. X *
  431. X *             User Interface for   P E X D R A W
  432. X *
  433. X *        The Motif Version.
  434. X *   
  435. X *  void InitUserInterface(argc, argv)
  436. X *  void MainLoop()
  437. X *  int  applyViewSet(int viewNumber)
  438. X *  void GetVPN( int viewNumber,   PEXVector  *vpn )
  439. X *  void SetVPN( int viewNumber,   PEXVector  *vpn )
  440. X *  void GetVUP( int viewNumber,   PEXVector  *vup )
  441. X *  void SetVUP( int viewNumber,   PEXVector  *vup )
  442. X *  void AddWorkProc(int (*worker)(), char *info)
  443. X *  void ApplySurfaceAttrs()
  444. X *  GC CreateDynGC()
  445. X *  GetSomeTextFromUI(int x, int y, int *length, char **charStr, int *flags )
  446. X *  void FinishExec(XButtonReleasedEvent *event );
  447. X *  
  448. X * What about WM_COLORMAP_WINDOWS???
  449. X *************************************************************************/
  450. X
  451. X#include <stdlib.h>         /* for strtod() */
  452. X#include <stdio.h>
  453. X#include <Xm/Xm.h>          /* Motif Toolkit */
  454. X#include <Mrm/MrmPublic.h>   /* Mrm */
  455. X#include <Xm/ToggleB.h>     /* for XmToggleButtonGetState() */
  456. X
  457. X#include <math.h>
  458. X
  459. X#include <X11/PEX5/PEXlib.h>
  460. X
  461. X#include "pexdraw.h"
  462. X
  463. Xstatic MrmHierarchy theMrmHierarchy;     /* MRM database hierarchy ID */
  464. X
  465. XXtAppContext    theAppContext;
  466. Xint theDBFlag = 1;
  467. X
  468. Xstatic Widget theDrawingArea = NULL, /* the PEX area */
  469. X              theViewForm = NULL,    /* the View Paramter Form */
  470. X              theLightForm = NULL,   /* the Light Form */
  471. X          theSurfaceForm = NULL, /* the surface form */
  472. X              theTopLevel = NULL,    /* global parent */
  473. X            theFileForm = NULL,    /* archive file handler */
  474. X            theSpinForm = NULL,    /* spin options */
  475. X            theColorForm = NULL;   /* spin options */
  476. X
  477. X/* Widget array declared after constants */
  478. X
  479. X       /* forward declaration of interface procedures */
  480. Xstatic void proc_pexdraw_create();
  481. Xstatic void proc_pexdraw_expose();
  482. Xstatic void proc_pexdraw_resize();
  483. Xstatic void proc_pexdraw_input();
  484. Xstatic void proc_pexdraw_exit();
  485. Xstatic void proc_pexdraw_activate();
  486. Xstatic void proc_pexdraw_file();
  487. X
  488. X#if NeedFunctionPrototypes
  489. Xstatic void FinishExec(XButtonReleasedEvent * /* event */ );
  490. X#else
  491. Xstatic void FinishExec();
  492. X#endif
  493. X
  494. X
  495. X       /* binding of uil procedure names with C functions */
  496. Xstatic MRMRegisterArg    regvec[] = {
  497. X    {"proc_pexdraw_exit",(caddr_t)proc_pexdraw_exit},
  498. X    {"proc_pexdraw_create",(caddr_t)proc_pexdraw_create},
  499. X    {"proc_pexdraw_expose",(caddr_t)proc_pexdraw_expose},
  500. X    {"proc_pexdraw_resize",(caddr_t)proc_pexdraw_resize},
  501. X    {"proc_pexdraw_input",(caddr_t)proc_pexdraw_input},
  502. X    {"proc_pexdraw_activate",(caddr_t)proc_pexdraw_activate},
  503. X    {"proc_pexdraw_file",(caddr_t)proc_pexdraw_file}
  504. X    };
  505. Xstatic MrmCount regnum = sizeof(regvec) / sizeof(MRMRegisterArg);
  506. X
  507. X /*************************************************************************
  508. X *
  509. X *   C O N S T A N T S   U S E D   B Y   U I L
  510. X *
  511. X *
  512. X * why the &^%&^% these are not generated by UIL!.
  513. X * 
  514. X */
  515. X#define    k_drawing_area 0
  516. X#define    k_view_set 1
  517. X#define    k_apply_vs 2
  518. X#define    k_reset_vs 3
  519. X#define    k_dismiss_vs 4
  520. X#define    k_view_ref_pt_x 5
  521. X#define    k_view_ref_pt_y 6
  522. X#define    k_view_ref_pt_z 7
  523. X#define    k_view_pl_norm_x 8
  524. X#define    k_view_pl_norm_y 9
  525. X#define    k_view_pl_norm_z 10
  526. X#define    k_view_up_vect_x 11
  527. X#define    k_view_up_vect_y 12
  528. X#define    k_view_up_vect_z 13
  529. X#define    k_proj_ref_pt_x 14
  530. X#define    k_proj_ref_pt_y 15
  531. X#define    k_proj_ref_pt_z 16
  532. X#define    k_view_window_minx 17
  533. X#define    k_view_window_maxx 18
  534. X#define    k_view_window_miny 19
  535. X#define    k_view_window_maxy 20
  536. X#define    k_view_plane_dist 21
  537. X#define    k_view_plane_back 22
  538. X#define    k_view_plane_front 23
  539. X#define    k_proj_vp_minx 24
  540. X#define    k_proj_vp_maxx 25
  541. X#define    k_proj_vp_miny 26
  542. X#define    k_proj_vp_maxy 27
  543. X#define    k_proj_vp_minz 28
  544. X#define    k_proj_vp_maxz 29
  545. X#define    k_proj_type_para 30
  546. X#define    k_proj_type_persp 31
  547. X#define    k_dump_strux 32
  548. X#define    k_refresh 33
  549. X#define    k_tool_pointer 34
  550. X#define    k_tool_line 35
  551. X#define    k_tool_view 36
  552. X#define    k_tool_tristrip 37
  553. X#define    k_delete 38
  554. X#define    k_light 39
  555. X#define    k_light_on1 40
  556. X#define    k_light_on2 41
  557. X#define    k_light_on3 42
  558. X#define    k_light_on4 43
  559. X#define    k_light_on5 44
  560. X#define    k_light_on6 45
  561. X#define    k_light_on7 46
  562. X#define    k_light_on8 47
  563. X#define    k_light_edit1 48
  564. X#define    k_light_edit2 49
  565. X#define    k_light_edit3 50
  566. X#define    k_light_edit4 51
  567. X#define    k_light_edit5 52
  568. X#define    k_light_edit6 53
  569. X#define    k_light_edit7 54
  570. X#define    k_light_edit8 55
  571. X#define    k_light_type_ambient 56
  572. X#define    k_light_type_directional 57
  573. X#define    k_light_type_positional 58
  574. X#define    k_light_type_spot 59
  575. X#define    k_light_pos_x 60
  576. X#define    k_light_pos_y 61
  577. X#define    k_light_pos_z 62
  578. X#define    k_light_color_red 63
  579. X#define    k_light_color_green 64
  580. X#define    k_light_color_blue 65
  581. X#define    k_light_direction_x 66
  582. X#define    k_light_direction_y 67
  583. X#define    k_light_direction_z 68
  584. X#define    k_light_coeff_const 69
  585. X#define    k_light_coeff_dist 70
  586. X#define    k_light_conc_exp 71
  587. X#define    k_light_spread_angle 72
  588. X#define    k_apply_light 73
  589. X#define    k_reset_light 74
  590. X#define    k_dismiss_light 75
  591. X#define    k_surface 76
  592. X#define    k_tool_mclip 77
  593. X#define    k_reset_model  78
  594. X#define    k_spin_slowly  79
  595. X#define    k_save 80
  596. X#define    k_read 81
  597. X#define    k_file 82
  598. X#define    k_undo 83
  599. X#define    k_file_help 84
  600. X#define    k_delete_all 85
  601. X#define    k_face_cull 86
  602. X#define    k_sphere 87
  603. X#define    k_dismiss_surface 88
  604. X#define    k_reset_surface 89
  605. X#define    k_apply_surface 90
  606. X#define    k_surface_refl_transparency 91
  607. X#define    k_surface_refl_specexp 92
  608. X#define    k_surface_refl_specular 93
  609. X#define    k_surface_refl_diffuse 94
  610. X#define    k_surface_refl_ambient 95
  611. X#define    k_sstyle_empty 96
  612. X#define    k_sstyle_solid 97
  613. X#define    k_sstyle_hollow 98
  614. X#define    k_sshade_flat 99
  615. X#define    k_sshade_gouraud 100
  616. X#define    k_sshade_dot 101
  617. X#define    k_sshade_phong 102
  618. X#define    k_cull_none 103
  619. X#define    k_cull_back 104
  620. X#define    k_cull_front 105
  621. X#define    k_tool_zoom 106
  622. X#define    k_tool_nurbc 107
  623. X#define    k_tool_text 108
  624. X#define    k_tool_pgon 109
  625. X#define    k_tool_circle 110
  626. X#define    k_spin_form 111
  627. X#define    k_spinf_strux 112
  628. X#define    k_spinf_px 113
  629. X#define    k_spinf_py 114
  630. X#define    k_spinf_pz 115
  631. X#define    k_spinf_ox 116
  632. X#define    k_spinf_oy 117
  633. X#define    k_spinf_oz 118
  634. X#define    k_spinf_xang 119
  635. X#define    k_spinf_yang 120
  636. X#define    k_spinf_zang 121
  637. X#define    k_spinf_dx 122
  638. X#define    k_spinf_dy 123
  639. X#define    k_spinf_dz 124
  640. X#define    k_spinf_stop 125
  641. X#define    k_spinf_scale 126
  642. X#define    k_apply_spin 127
  643. X#define    k_dismiss_spin 128
  644. X#define    k_reset_spin 129
  645. X#define    k_color_form 130
  646. X#define    k_color_red 131
  647. X#define    k_color_green 132
  648. X#define    k_color_blue 133
  649. X#define    k_apply_color 134
  650. X#define    k_dismiss_color 135
  651. X#define    k_reset_color 136
  652. X#define    k_color_strux 137
  653. X#define    k_color_elem 138
  654. X#define    k_delete_strux 139
  655. X#define    k_exec_strux 140
  656. X#define    k_unpost_strux 141
  657. X
  658. X#define MAX_WIDGET 140
  659. Xstatic Widget widgetArray[MAX_WIDGET]; /* just the widgets with constants +1 */
  660. X
  661. X/*
  662. X * number strings
  663. X */
  664. Xstatic char *numberStrings[] = {
  665. X  "",                /* k_drawing_area 0 */
  666. X  "",                /* k_view_set 1 */
  667. X  "",                /* k_apply_vs 2 */
  668. X  "",                /* k_reset_vs 3 */
  669. X  "",                /* k_dismiss_vs 4 */
  670. X  "view_ref_pt_x",        /* k_view_ref_pt_x 5 */
  671. X  "view_ref_pt_y",        /* k_view_ref_pt_y 6 */
  672. X  "view_ref_pt_z",        /* k_view_ref_pt_z 7 */
  673. X  "view_pl_norm_x",        /* k_view_pl_norm_x 8 */
  674. X  "view_pl_norm_y",        /* k_view_pl_norm_y 9 */
  675. X  "view_pl_norm_z",        /* k_view_pl_norm_z 10 */
  676. X  "view_up_vect_x",        /* k_view_up_vect_x 11 */
  677. X  "view_up_vect_y",        /* k_view_up_vect_y 12 */
  678. X  "view_up_vect_z",        /* k_view_up_vect_z 13 */
  679. X  "view_window_minx",        /* k_view_window_minx 17 */
  680. X  "view_window_maxx",        /* k_view_window_maxx 18 */
  681. X  "view_window_miny",        /* k_view_window_miny 19 */
  682. X  "view_window_maxy",        /* k_view_window_maxy 20 */
  683. X  "view_plane_dist",        /* k_view_plane_dist 21 */
  684. X  "view_plane_back",        /* k_view_plane_back 22 */
  685. X  "view_plane_front",        /* k_view_plane_front 23 */
  686. X  "proj_vp_minx",        /* k_proj_vp_minx 24 */
  687. X  "proj_vp_maxx",        /* k_proj_vp_maxx 25 */
  688. X  "proj_vp_miny",        /* k_proj_vp_miny 26 */
  689. X  "proj_vp_maxy",        /* k_proj_vp_maxy 27 */
  690. X  "proj_vp_minz",        /* k_proj_vp_minz 28 */
  691. X  "proj_vp_maxz",        /* k_proj_vp_maxz 29 */
  692. X  "proj_type_para",        /* k_proj_type_para 30 */
  693. X  "proj_type_persp",        /* k_proj_type_persp 31 */
  694. X    "dump_strux",        /* k_dump_strux 32 */
  695. X    "refresh",        /* k_refresh 33 */
  696. X    "tool_pointer",        /* k_tool_pointer 34 */
  697. X    "tool_line",        /* k_tool_line 35 */
  698. X    "tool_view",        /* k_tool_view 36 */
  699. X    "tool_tristrip",        /* k_tool_tristrip 37 */
  700. X    "delete",        /* k_delete 38 */
  701. X    "light",        /* k_light 39 */
  702. X    "light_on1",        /* k_light_on1 40 */
  703. X    "light_on2",        /* k_light_on2 41 */
  704. X    "light_on3",        /* k_light_on3 42 */
  705. X    "light_on4",        /* k_light_on4 43 */
  706. X    "light_on5",        /* k_light_on5 44 */
  707. X    "light_on6",        /* k_light_on6 45 */
  708. X    "light_on7",        /* k_light_on7 46 */
  709. X    "light_on8",        /* k_light_on8 47 */
  710. X    "light_edit1",        /* k_light_edit1 48 */
  711. X    "light_edit2",        /* k_light_edit2 49 */
  712. X    "light_edit3",        /* k_light_edit3 50 */
  713. X    "light_edit4",        /* k_light_edit4 51 */
  714. X    "light_edit5",        /* k_light_edit5 52 */
  715. X    "light_edit6",        /* k_light_edit6 53 */
  716. X    "light_edit7",        /* k_light_edit7 54 */
  717. X    "light_edit8",        /* k_light_edit8 55 */
  718. X    "light_type_ambient",        /* k_light_type_ambient 56 */
  719. X    "light_type_directional",        /* k_light_type_directional 57 */
  720. X    "light_type_positional",        /* k_light_type_positional 58 */
  721. X    "light_type_spot",        /* k_light_type_spot 59 */
  722. X    "light_pos_x",        /* k_light_pos_x 60 */
  723. X    "light_pos_y",        /* k_light_pos_y 61 */
  724. X    "light_pos_z",        /* k_light_pos_z 62 */
  725. X    "light_color_red",        /* k_light_color_red 63 */
  726. X    "light_color_green",        /* k_light_color_green 64 */
  727. X    "light_color_blue",        /* k_light_color_blue 65 */
  728. X    "light_direction_x",        /* k_light_direction_x 66 */
  729. X    "light_direction_y",        /* k_light_direction_y 67 */
  730. X    "light_direction_z",        /* k_light_direction_z 68 */
  731. X    "light_coeff_const",        /* k_light_coeff_const 69 */
  732. X    "light_coeff_dist",        /* k_light_coeff_dist 70 */
  733. X    "light_conc_exp",        /* k_light_conc_exp 71 */
  734. X    "light_spread_angle",        /* k_light_spread_angle 72 */
  735. X    "apply_light",        /* k_apply_light 73 */
  736. X    "reset_light",        /* k_reset_light 74 */
  737. X    "dismiss_light",        /* k_dismiss_light 75 */
  738. X    "surface",        /* k_surface 76 */
  739. X    "FREE",        /* k_FREE 77 */
  740. X    "reset_model",        /* k_spin_strux  78 */
  741. X    "spin_slowly",        /* k_spin_slowly  79 */
  742. X    "save",        /* k_save 80 */
  743. X    "read",        /* k_read 81 */
  744. X    "file",        /* k_file 82 */
  745. X    "undo",        /* k_undo 83 */
  746. X    "file_help",        /* k_file_help 84 */
  747. X    "delete_all",        /* k_delete_all 85 */
  748. X    "face_cull",        /* k_face_cull 86 */
  749. X    "sphere",        /* k_sphere 87 */
  750. X    "dismiss_surface",        /* k_dismiss_surface 88 */
  751. X    "reset_surface",        /* k_reset_surface 89 */
  752. X    "apply_surface",        /* k_apply_surface 90 */
  753. X    "surface_refl_transparency",        /* k_surface_refl_transparency 91 */
  754. X    "surface_refl_specexp",        /* k_surface_refl_specexp 92 */
  755. X    "surface_refl_specular",        /* k_surface_refl_specular 93 */
  756. X    "surface_refl_diffuse",        /* k_surface_refl_diffuse 94 */
  757. X    "surface_refl_ambient",        /* k_surface_refl_ambient 95 */
  758. X    "sstyle_empty",        /* k_sstyle_empty 96 */
  759. X    "sstyle_solid",        /* k_sstyle_solid 97 */
  760. X    "sstyle_hollow",        /* k_sstyle_hollow 98 */
  761. X    "sshade_flat",        /* k_sshade_flat 99 */
  762. X    "sshade_gouraud",        /* k_sshade_gouraud 100 */
  763. X    "sshade_dot",        /* k_sshade_dot 101 */
  764. X    "sshade_phong",        /* k_sshade_phong 102 */
  765. X    "cull_none",        /* k_cull_none 103 */
  766. X    "cull_back",        /* k_cull_back 104 */
  767. X    "cull_front",        /* k_cull_front 105 */
  768. X  "",             /* k_tool_zoom : 106; */
  769. X      "",             /* k_tool_nurbc : 107; */
  770. X      "",             /* k_tool_text : 108; */
  771. X      "",             /* k_tool_pgon : 109; */
  772. X      "",             /* k_tool_circle : 110; */
  773. X      "",             /* k_spin_form : 111; */
  774. X      "strux_id",             /* k_spinf_strux : 112; */
  775. X      "spinf_pnt_x",             /* k_spinf_px : 113; */
  776. X      "spinf_pnt_y",             /* k_spinf_py : 114; */
  777. X      "spinf_pnt_z",             /* k_spinf_pz : 115; */
  778. X      "spinf_offset_x",             /* k_spinf_ox : 116; */
  779. X  "spinf_offset_y",             /* k_spinf_oy : 117; */
  780. X  "spinf_offset_z",             /* k_spinf_oz : 118; */
  781. X  "spinf_ang_x",             /* k_spinf_xang : 119; */
  782. X  "spinf_ang_y",             /* k_spinf_yang : 120; */
  783. X  "spinf_ang_z",             /* k_spinf_zang : 121; */
  784. X  "spinf_delta_x",             /* k_spinf_dx : 122; */
  785. X  "spinf_delta_y",             /* k_spinf_dy : 123; */
  786. X  "spinf_delta_z",             /* k_spinf_dz : 124; */
  787. X  "",             /* k_spinf_stop : 125; */
  788. X  "spinf_scale",             /* k_spinf_scale : 126; */
  789. X  "",             /* k_apply_spin : 127; */
  790. X  "",             /* k_dismiss_spin : 128; */
  791. X  "",             /* k_reset_spin : 129; */
  792. X  "",            /* k_color_form : 130; */
  793. X  "color_red",            /* k_color_red : 131; */
  794. X  "color_green",            /* k_color_green : 132; */
  795. X  "color_blue",            /* k_color_blue : 133; */
  796. X  "",            /* k_apply_color : 134; */
  797. X  "",            /* k_dismiss_color : 135; */
  798. X  "",            /* k_reset_color : 136; */
  799. X  "",            /* k_color_strux : 137; */
  800. X  ""            /* k_color_elem : 138; */
  801. X};
  802. Xstatic int numberStringCount = sizeof(numberStrings) / sizeof(char *);
  803. X
  804. X/*
  805. X * event handler
  806. X */
  807. Xstatic XtEventHandler motionHandler(
  808. X#if NeedFunctionPrototypes
  809. X                    Widget  /* widget */,
  810. X                    XtPointer  /* unused */,
  811. X                    XMotionEvent * /* event */, 
  812. X                    Boolean * /* continue_to_dispatch */
  813. X#endif
  814. X);
  815. X
  816. Xstatic theSpecialExecMode = 0;
  817. X
  818. X /******************************************************************
  819. X *
  820. X *     M A I N
  821. X */
  822. Xvoid
  823. XInitUserInterface(argc, argv)
  824. Xint argc;
  825. Xchar **argv;
  826. X{
  827. X  Widget pexdrawmain = NULL;
  828. X  Arg arglist[1];
  829. X  int n, i;
  830. X  MrmCode class;
  831. X  char *files[1];
  832. X
  833. X  for ( i = 1; i<argc; i++ ) {
  834. X    if ((strncmp(argv[i],"-pmdb",strlen(argv[i]))) == 0) {
  835. X      thePMDBFlag = 1; 
  836. X    } else if ((strncmp(argv[i],"-nodb",strlen(argv[i]))) == 0) {
  837. X      theDBFlag = 0; 
  838. X    } else if ((strncmp(argv[i],"-wks",strlen(argv[i]))) == 0) {
  839. X      theForceWKSFlag = 1; 
  840. X    } else if ((strncmp(argv[i],"-nodither",strlen(argv[i]))) == 0) {
  841. X      theNoDitherFlag = 1; 
  842. X    }
  843. X  }
  844. X
  845. X  MrmInitialize ();
  846. X
  847. X  theTopLevel = XtAppInitialize(&theAppContext, "pexdraw", 
  848. X                (XrmOptionDescList)NULL , 0,
  849. X                    &argc, (String*)argv, 
  850. X                (String*)NULL, (ArgList)NULL, 0);
  851. X
  852. X  /*
  853. X   *  Open the User Interface Description file. 
  854. X   *    pexdraw.uil is compiled into pexdraw.uid
  855. X   */ 
  856. X  files[0] = "pexdraw.uid";
  857. X  if (MrmOpenHierarchy( 1, files, NULL, &theMrmHierarchy) != MrmSUCCESS) {
  858. X    printf ("can't open pexdraw.uid\n");
  859. X    exit(0);
  860. X  }
  861. X
  862. X  if (MrmRegisterNames (regvec, regnum) != MrmSUCCESS) {
  863. X    printf("can't register names\n");
  864. X    exit(0) ;
  865. X  }
  866. X
  867. X  if (MrmFetchWidget (theMrmHierarchy, "pexdraw_obj_main",
  868. X              theTopLevel, &pexdrawmain, &class)
  869. X      != MrmSUCCESS) {
  870. X    printf("can't fetch interface\n");
  871. X    exit(0);
  872. X  }
  873. X
  874. X  XtManageChild(pexdrawmain);
  875. X    
  876. X  XtRealizeWidget(theTopLevel);
  877. X
  878. X  /* iquire what the default too is and ... */
  879. X  set_tool_line();
  880. X
  881. X  theTopWindow = XtWindow(theTopLevel);
  882. X  theDisplay = XtDisplay(theDrawingArea);
  883. X  theWindow = XtWindow(theDrawingArea);
  884. X}
  885. X
  886. Xvoid
  887. XMainLoop()
  888. X{
  889. X  XtAppMainLoop(theAppContext);  /* Hand over control to the UI & User */
  890. X}
  891. X
  892. X /*************************************************************************
  893. X *
  894. X *    U S E R    I N T E R F A C E    C A L L B A C K S
  895. X *
  896. X *  All UI callbacks are also defined in pexdraw.uil and begin proc_pexdraw_??
  897. X *
  898. X */
  899. X
  900. Xstatic void proc_pexdraw_create( widget, tag, cbData )
  901. X    Widget    widget;
  902. X    int    *tag;
  903. X    XmAnyCallbackStruct *cbData;
  904. X{
  905. X    Arg arg ;
  906. X    int which = *(int *)tag;
  907. X
  908. X    switch (which) {
  909. X    case k_drawing_area:
  910. X    theDrawingArea = widget;
  911. X    XtAddEventHandler( theDrawingArea, ButtonMotionMask, FALSE, 
  912. X              (XtEventHandler)motionHandler, NULL );
  913. X
  914. X    break;
  915. X
  916. X      case k_view_set:
  917. X    theViewForm = widget;
  918. X    break;
  919. X    
  920. X      case k_light:
  921. X    theLightForm = widget;
  922. X    break;
  923. X
  924. X      case k_file:
  925. X    theFileForm = widget;
  926. X    break;
  927. X
  928. X      case k_spin_form:
  929. X    theSpinForm = widget;
  930. X    break;
  931. X
  932. X      case k_color_form:
  933. X    theColorForm = widget;
  934. X    break;
  935. X
  936. X      default: 
  937. X    if (which > MAX_WIDGET) {
  938. X      printf(" got widget #%d, MAX is still %d\n",which,MAX_WIDGET);
  939. X      return;
  940. X    }
  941. X    widgetArray[which] = widget;
  942. X    break;
  943. X    }
  944. X}
  945. X
  946. Xstatic void proc_pexdraw_expose( widget, tag, cbData )
  947. X    Widget    widget;
  948. X    int    *tag;
  949. X    XmAnyCallbackStruct *cbData;
  950. X{
  951. X  theRenderProcs.ReDraw();
  952. X}
  953. X
  954. X
  955. Xstatic void proc_pexdraw_resize( widget, tag, cbData )
  956. X    Widget    widget;
  957. X    int    *tag;
  958. X    XmAnyCallbackStruct *cbData;
  959. X{
  960. X  XWindowAttributes winAttrs;
  961. X
  962. X  /*
  963. X   * I'm positive this is a terrible hack in violation of all of Xt
  964. X   * rules and regulations, but event was not comming back in call_back data.
  965. X   */
  966. X  XGetWindowAttributes(XtDisplay(theDrawingArea), XtWindow(theDrawingArea),
  967. X               &winAttrs );
  968. X
  969. X  theWinHeight =  winAttrs.height;
  970. X
  971. X  ResizeWindow( XtWindow(theDrawingArea), winAttrs.width, winAttrs.height );
  972. X  theRenderProcs.ReDraw();
  973. X}
  974. X
  975. X/*
  976. X * Handle button presses. See fb.c for the actual handler routines.
  977. X */
  978. Xstatic void proc_pexdraw_input( widget, tag, cbData )
  979. X    Widget    widget;
  980. X    int    *tag;
  981. X    XmAnyCallbackStruct *cbData;
  982. X{
  983. X  XEvent *event = cbData->event;
  984. X
  985. X  if (event->xbutton.button < 1 || event->xbutton.button > 3) return;
  986. X
  987. X  if (theSpecialExecMode) {
  988. X    if (event->type !=  ButtonRelease) return;
  989. X    FinishExec((XButtonReleasedEvent *)event);
  990. X    theSpecialExecMode = 0;
  991. X  }
  992. X
  993. X  if (event->type ==  ButtonPress) {
  994. X    thePressHandlerTable[event->xbutton.button-1](event);
  995. X  } else if (event->type ==  ButtonRelease) {
  996. X    theReleaseHandlerTable[event->xbutton.button-1](event);
  997. X  }
  998. X}
  999. X
  1000. X/* good-bye */
  1001. Xstatic void proc_pexdraw_exit( widget, tag, cbData )
  1002. X    Widget    widget;
  1003. X    char    *tag;
  1004. X    XmAnyCallbackStruct *cbData;
  1005. X{
  1006. X    exit(0);
  1007. X}
  1008. X
  1009. X/*************************************************************************
  1010. X *
  1011. X *   P R O C _ P D R A W _ A C T I V A T E
  1012. X */
  1013. Xstatic void proc_pexdraw_activate( widget, tag, cbData )
  1014. X    Widget    widget;
  1015. X    char    *tag;
  1016. X    XmAnyCallbackStruct *cbData;
  1017. X{
  1018. X  int which = *(int *)tag;
  1019. X  MrmCode class;
  1020. X  PEXCoord offset;
  1021. X
  1022. X  switch (which) {
  1023. X  case k_view_set:
  1024. X    if (theViewForm == NULL) {     /* The first time, fetch order box. */
  1025. X      if (MrmFetchWidget(theMrmHierarchy, "view_set_dialog", theTopLevel,
  1026. X             &theViewForm, &class) != MrmSUCCESS) {
  1027. X    printf("can't fetch view_set_dialog");
  1028. X    return;
  1029. X      }
  1030. X    }
  1031. X
  1032. X    if (XtIsManaged(theViewForm))
  1033. X      XtUnmanageChild(theViewForm);
  1034. X    else
  1035. X      XtManageChild(theViewForm);
  1036. X    break;
  1037. X
  1038. X  case k_apply_vs:
  1039. X    applyViewSet(1);
  1040. X    break;
  1041. X
  1042. X  case k_reset_vs:
  1043. X    break;
  1044. X
  1045. X  case k_dismiss_vs:
  1046. X    XtUnmanageChild(theViewForm);
  1047. X    break;
  1048. X
  1049. X  case k_dump_strux:
  1050. X    DumpStruxCmd(1);
  1051. X    break;
  1052. X
  1053. X  case k_refresh:
  1054. X    theRenderProcs.ReDraw();
  1055. X    break;
  1056. X
  1057. X  case k_tool_pointer:
  1058. X    set_tool_pointer();
  1059. X    break;
  1060. X
  1061. X  case k_tool_line:
  1062. X    set_tool_line();
  1063. X    break;
  1064. X
  1065. X  case k_tool_view:
  1066. X    set_tool_view();
  1067. X    break;
  1068. X
  1069. X  case k_tool_tristrip:
  1070. X    set_tool_tristrip();
  1071. X    break;
  1072. X
  1073. X  case k_tool_nurbc:
  1074. X    set_tool_nurbc();
  1075. X    break;
  1076. X
  1077. X  case k_tool_text:
  1078. X    set_tool_text();
  1079. X    break;
  1080. X
  1081. X  case k_tool_zoom:
  1082. X    set_tool_zoom();
  1083. X    break;
  1084. X
  1085. X  case k_tool_pgon:
  1086. X    set_tool_pgon();
  1087. X    break;
  1088. X
  1089. X  case k_tool_mclip:
  1090. X    set_tool_mclip();
  1091. X    break;
  1092. X
  1093. X  case k_tool_circle:
  1094. X    set_tool_circle();
  1095. X    break;
  1096. X
  1097. X  case k_delete:
  1098. X    DeleteSelected();
  1099. X    theRenderProcs.ReDraw();
  1100. X    break;
  1101. X
  1102. X  case k_light:
  1103. X    if (theLightForm == NULL) {     /* The first time, fetch order box. */
  1104. X      if (MrmFetchWidget(theMrmHierarchy, "light_dialog", theTopLevel,
  1105. X             &theLightForm, &class) != MrmSUCCESS) {
  1106. X    printf("can't fetch light form widget");
  1107. X    return;
  1108. X      }
  1109. X    }
  1110. X
  1111. X    if (XtIsManaged(theLightForm))
  1112. X      XtUnmanageChild(theLightForm);
  1113. X    else
  1114. X      XtManageChild(theLightForm);
  1115. X    break;
  1116. X
  1117. X  case k_apply_light:
  1118. X    break;
  1119. X
  1120. X  case k_reset_light:
  1121. X    break;
  1122. X
  1123. X  case k_dismiss_light:
  1124. X    XtUnmanageChild(theLightForm);
  1125. X    break;
  1126. X
  1127. X
  1128. X  case k_surface:
  1129. X    if (theSurfaceForm == NULL) {     /* The first time, fetch order box. */
  1130. X      if (MrmFetchWidget(theMrmHierarchy, "surface_dialog", theTopLevel,
  1131. X             &theSurfaceForm, &class) != MrmSUCCESS) {
  1132. X    printf("can't fetch surface form widget");
  1133. X    return;
  1134. X      }
  1135. X    }
  1136. X
  1137. X    if (XtIsManaged(theSurfaceForm))
  1138. X      XtUnmanageChild(theSurfaceForm);
  1139. X    else
  1140. X      XtManageChild(theSurfaceForm);
  1141. X    break;
  1142. X
  1143. X  case k_apply_surface:
  1144. X    ApplySurfaceAttrs();
  1145. X    theRenderProcs.ReDraw();
  1146. X    break;
  1147. X
  1148. X  case k_reset_surface:
  1149. X    break;
  1150. X
  1151. X  case k_dismiss_surface:
  1152. X    XtUnmanageChild(theSurfaceForm);
  1153. X    break;
  1154. X
  1155. X  case k_reset_model:
  1156. X    break;
  1157. X
  1158. X  case k_spin_slowly: {
  1159. X    PEXStructure sid;
  1160. X    
  1161. X    if ( theSelectedElement != -1 ) {
  1162. X      sid = theSelectedStrux;
  1163. X    } else if (theNewStrux != 0) {
  1164. X      sid = theNewStrux;
  1165. X    } else break;
  1166. X
  1167. X    if (!StartSpinning(sid)) { /* could not start, must be spinning */
  1168. X      StopSpinning(sid);
  1169. X    }}
  1170. X    break;
  1171. X
  1172. X  case k_spin_form:
  1173. X    if (theSpinForm == NULL) {     /* The first time, fetch order box. */
  1174. X      if (MrmFetchWidget(theMrmHierarchy, "spin_dialog", theTopLevel,
  1175. X             &theSpinForm, &class) != MrmSUCCESS) {
  1176. X    printf("can't fetch Spin form widget");
  1177. X    return;
  1178. X      }
  1179. X    }
  1180. X
  1181. X    {
  1182. X      PEXStructure sid;
  1183. X      SpinInfo *si;
  1184. X
  1185. X      if ( theSelectedElement != -1 ) {
  1186. X    sid = theSelectedStrux;
  1187. X      } else if (theNewStrux != 0) {
  1188. X    sid = theNewStrux;
  1189. X      } else { return; }
  1190. X      si = GetSpinInfo(sid);
  1191. X      if (!si) return;
  1192. X      LoadSpinWidget(si);
  1193. X    }
  1194. X
  1195. X    if (XtIsManaged(theSpinForm))
  1196. X      XtUnmanageChild(theSpinForm);
  1197. X    else
  1198. X      XtManageChild(theSpinForm);
  1199. X    break;
  1200. X
  1201. X  case k_apply_spin: /* must clean this up !!! */
  1202. X    {
  1203. X      PEXStructure sid;
  1204. X      SpinInfo *si;
  1205. X
  1206. X      if ( theSelectedElement != -1 ) {
  1207. X    sid = theSelectedStrux;
  1208. X      } else if (theNewStrux != 0) {
  1209. X    sid = theNewStrux;
  1210. X      } else { return; }
  1211. X      si = GetSpinInfo(sid);
  1212. X      if (!si) return;
  1213. X      ApplySpin(si);
  1214. X    }
  1215. X    break;
  1216. X
  1217. X  case k_reset_spin:
  1218. X    {
  1219. X      PEXStructure sid;
  1220. X      SpinInfo *si;
  1221. X
  1222. X      if ( theSelectedElement != -1 ) {
  1223. X    sid = theSelectedStrux;
  1224. X      } else if (theNewStrux != 0) {
  1225. X    sid = theNewStrux;
  1226. X      } else { return; }
  1227. X      si = GetSpinInfo(sid);
  1228. X      if (!si) return;
  1229. X      LoadSpinWidget(si);
  1230. X    }
  1231. X    break;
  1232. X
  1233. X  case k_dismiss_spin:
  1234. X    XtUnmanageChild(theSpinForm);
  1235. X    break;
  1236. X
  1237. X  case k_color_form:
  1238. X    if (theColorForm == NULL) {     /* The first time, fetch order box. */
  1239. X      if (MrmFetchWidget(theMrmHierarchy, "color_dialog", theTopLevel,
  1240. X             &theColorForm, &class) != MrmSUCCESS) {
  1241. X    printf("can't fetch Color form widget");
  1242. X    return;
  1243. X      }
  1244. X    }
  1245. X
  1246. X    { PEXColorRGB rgb;
  1247. X      GetColorAttribute(theSelectedStrux, theSelectedElement, &rgb);
  1248. X      LoadColorWidget(theSelectedStrux, theSelectedElement, &rgb); }
  1249. X
  1250. X    if (XtIsManaged(theColorForm))
  1251. X      XtUnmanageChild(theColorForm);
  1252. X    else
  1253. X      XtManageChild(theColorForm);
  1254. X    break;
  1255. X
  1256. X  case k_apply_color: /* must clean this up !!! */
  1257. X    ApplyColor(theSelectedStrux, theSelectedElement);
  1258. X    theRenderProcs.ReDraw();
  1259. X    break;
  1260. X
  1261. X  case k_reset_color:
  1262. X    { PEXColorRGB rgb;
  1263. X      GetColorAttribute(theSelectedStrux, theSelectedElement, &rgb);
  1264. X      LoadColorWidget(theSelectedStrux, theSelectedElement, &rgb); }
  1265. X    break;
  1266. X
  1267. X  case k_dismiss_color:
  1268. X    XtUnmanageChild(theColorForm);
  1269. X    break;
  1270. X
  1271. X  case k_read:
  1272. X  case k_save:
  1273. X    if (theFileForm == NULL) {     /* The first time, fetch order box. */
  1274. X      if (MrmFetchWidget(theMrmHierarchy, "file_dialog", theTopLevel,
  1275. X             &theFileForm, &class) != MrmSUCCESS) {
  1276. X    printf("can't fetch order box widget");
  1277. X    return;
  1278. X      }
  1279. X    }
  1280. X
  1281. X
  1282. X    theFileCmd = (which == k_read)?ReadArchiveFile:WriteArchiveFile;
  1283. X
  1284. X    if (XtIsManaged(theFileForm))
  1285. X      XtUnmanageChild(theFileForm);
  1286. X    else
  1287. X      XtManageChild(theFileForm);
  1288. X    break;
  1289. X
  1290. X  case k_undo:
  1291. X    break;
  1292. X
  1293. X  case k_file_help:
  1294. X    break;
  1295. X
  1296. X  case k_delete_all:
  1297. X    StopSpinning((PEXStructure)-1);
  1298. X    PEXRotate(PEXXAxis, 0.0, theMCMatrix.matrix );
  1299. X    theMCMatrix.seqNo = 0;
  1300. X    theRenderProcs.DeleteAll();
  1301. X    break;
  1302. X
  1303. X  case k_sphere:
  1304. X    offset.x = 1.0;
  1305. X    offset.y = 1.0;
  1306. X    offset.z = 1.0;
  1307. X    Cubeoctahedron(&offset, 0.9);
  1308. X    theRenderProcs.ReDraw();
  1309. X    break;
  1310. X
  1311. X  case k_delete_strux:
  1312. X    if ( theSelectedElement != -1 ) {
  1313. X      theRenderProcs.Unpost(theSelectedStrux);
  1314. X      DeleteStrux(theSelectedStrux);
  1315. X      StopSpinning(theSelectedStrux); /* just in case */
  1316. X      theRenderProcs.ReDraw();
  1317. X    }
  1318. X    break;
  1319. X
  1320. X  case k_exec_strux:
  1321. X    if ( theSelectedElement != -1 ) {
  1322. X      theSpecialExecMode = 1;          /* see FinishExec */
  1323. X    }
  1324. X    break;
  1325. X
  1326. X  case k_unpost_strux:
  1327. X    if ( theSelectedElement != -1 ) {
  1328. X      theRenderProcs.Unpost(theSelectedStrux);
  1329. X      theRenderProcs.ReDraw();
  1330. X    }
  1331. X    break;
  1332. X
  1333. X  default:
  1334. X    break;
  1335. X  }
  1336. X    
  1337. X}
  1338. X
  1339. X /*************************************************************************
  1340. X * proc_pexdraw_file
  1341. X *
  1342. X * handle callback fron file selection mechanism.
  1343. X */
  1344. Xstatic void proc_pexdraw_file( widget, tag, cbData )
  1345. X    Widget    widget;
  1346. X    char    *tag;
  1347. X    XmFileSelectionBoxCallbackStruct *cbData;
  1348. X{
  1349. X  char *filename;
  1350. X  int status;
  1351. X
  1352. X  switch (cbData->reason) {
  1353. X  case XmCR_OK:
  1354. X  case XmCR_APPLY:
  1355. X    if (!XmStringGetLtoR(cbData->value, XmSTRING_DEFAULT_CHARSET, 
  1356. X             &filename )) {
  1357. X      printf("imagine a popup...\n");
  1358. X    } else {
  1359. X      status = theFileCmd(filename);
  1360. X    }
  1361. X    if (cbData->reason == XmCR_OK) XtUnmanageChild(theFileForm);
  1362. X    break;
  1363. X
  1364. X  case XmCR_CANCEL:
  1365. X    XtUnmanageChild(theFileForm);
  1366. X    break;
  1367. X
  1368. X  case XmCR_HELP:
  1369. X    break;
  1370. X
  1371. X  default:
  1372. X    break;
  1373. X  }
  1374. X}
  1375. X
  1376. X
  1377. X
  1378. X/*************************************************************************
  1379. X * applyViewSet - get values from widget and set the view representation
  1380. X */
  1381. Xint
  1382. XapplyViewSet(viewNumber)
  1383. X  int viewNumber;
  1384. X{
  1385. X  PEXCoord  vrp;  /* view reference point */
  1386. X  PEXVector  vpn;  /* view plane normal    */
  1387. X  PEXVector  vup;  /* view up vector       */
  1388. X
  1389. X/* clean this up, why use a view struct? use view entry */
  1390. X  
  1391. X  PEXViewRep vrep;                           /*  view structure */
  1392. X
  1393. X  PEXCoord2D          frame[2];
  1394. X  PEXNPCSubVolume     viewport;
  1395. X  int                 perspective;
  1396. X  PEXCoord            prp;
  1397. X  float               view_plane, back_plane, front_plane;
  1398. X  int err;
  1399. X
  1400. X  int persp;
  1401. X  MrmCode class;
  1402. X
  1403. X  if (theViewForm == NULL) {     /* The first time, fetch order box. */
  1404. X    if (MrmFetchWidget(theMrmHierarchy, "view_set_dialog", theTopLevel,
  1405. X               &theViewForm, &class) != MrmSUCCESS) {
  1406. X      printf("can't fetch view set dialog");
  1407. X      return;
  1408. X    }
  1409. X  }
  1410. X
  1411. X#define FetchValue(_a,_b)  {if (getNumberWidgetValue((_a), (_b))) return(1);}
  1412. X
  1413. X  /* View Reference Point */
  1414. X  FetchValue(k_view_ref_pt_x, &vrp.x);
  1415. X  FetchValue(k_view_ref_pt_y, &vrp.y);
  1416. X  FetchValue(k_view_ref_pt_z, &vrp.z);
  1417. X
  1418. X  /* view plane normal */
  1419. X  FetchValue(k_view_pl_norm_x, &vpn.x);
  1420. X  FetchValue(k_view_pl_norm_y, &vpn.y);
  1421. X  FetchValue(k_view_pl_norm_z, &vpn.z);
  1422. X
  1423. X  /*  view up vector */
  1424. X  FetchValue(k_view_up_vect_x, &vup.x);
  1425. X  FetchValue(k_view_up_vect_y, &vup.y);
  1426. X  FetchValue(k_view_up_vect_z, &vup.z);
  1427. X  
  1428. X  err = PEXViewOrientationMatrix( &vrp, &vpn, &vup, vrep.view.orientation);
  1429. X  if (err != 0) {
  1430. X    printf( "view orientation error %d\n",err); return (1);
  1431. X  }
  1432. X
  1433. X  FetchValue(k_proj_ref_pt_x, &prp.x);
  1434. X  FetchValue(k_proj_ref_pt_y, &prp.y);
  1435. X  FetchValue(k_proj_ref_pt_z, &prp.z);
  1436. X
  1437. X  FetchValue(k_view_window_minx, &frame[0].x);
  1438. X  FetchValue(k_view_window_maxx, &frame[1].x);
  1439. X  FetchValue(k_view_window_miny, &frame[0].y);
  1440. X  FetchValue(k_view_window_maxy, &frame[1].y);
  1441. X
  1442. X  FetchValue(k_view_plane_dist, &view_plane);
  1443. X  FetchValue(k_view_plane_back, &back_plane);
  1444. X  FetchValue(k_view_plane_front, &front_plane);
  1445. X
  1446. X  FetchValue(k_proj_vp_minx, &viewport.min.x);
  1447. X  FetchValue(k_proj_vp_maxx, &viewport.max.x);
  1448. X  FetchValue(k_proj_vp_miny, &viewport.min.y);
  1449. X  FetchValue(k_proj_vp_maxy, &viewport.max.y);
  1450. X  FetchValue(k_proj_vp_minz, &viewport.min.z);
  1451. X  FetchValue(k_proj_vp_maxz, &viewport.max.z);
  1452. X
  1453. X  if (widgetArray[k_proj_type_persp] == NULL) {
  1454. X      /* The first time, fetch order box. */
  1455. X      if (MrmFetchWidget(theMrmHierarchy, numberStrings[k_proj_type_persp],
  1456. X                         theTopLevel, &widgetArray[k_proj_type_persp],
  1457. X             &class) != MrmSUCCESS) {
  1458. X    printf("can't fetch number perspective\n");
  1459. X    return (1);
  1460. X      }
  1461. X    }
  1462. X  /* View Reference Point */
  1463. X  persp = XmToggleButtonGetState(widgetArray[k_proj_type_persp]);
  1464. X
  1465. X  err = PEXViewMappingMatrix( frame, &viewport, persp, &prp,
  1466. X               view_plane, back_plane, front_plane,
  1467. X               vrep.view.mapping);
  1468. X  
  1469. X  if (err != 0) { printf( "view mapping error %d\n",err); return (1); }
  1470. X  
  1471. X  vrep.view.clip_limits.min.x = viewport.min.x;
  1472. X  vrep.view.clip_limits.min.y = viewport.min.y;
  1473. X  vrep.view.clip_limits.min.z = viewport.min.z;
  1474. X  vrep.view.clip_limits.max.x = viewport.max.x;
  1475. X  vrep.view.clip_limits.max.y = viewport.max.y;
  1476. X  vrep.view.clip_limits.max.z = viewport.max.z;
  1477. X  vrep.view.clip_flags = PEXClipXY | PEXClipBack | PEXClipFront;
  1478. X  vrep.index = viewNumber;
  1479. X
  1480. X  theRenderProcs.SetView( 1, &vrep.view );
  1481. X
  1482. X  bcopy((char *)&vrep.view.orientation, (char *)&theMatOri,sizeof(PEXMatrix));
  1483. X  bcopy((char *)&vrep.view.mapping, (char *)&theMatMap, sizeof(PEXMatrix));
  1484. X
  1485. X  theRenderProcs.ReDraw();
  1486. X
  1487. X  return (0);
  1488. X}
  1489. X
  1490. X/*************************************************************************
  1491. X * getNumberWidgetValue - get a number from a string widget.
  1492. Xint getNumberWidgetValue(int id, float *value)
  1493. X */
  1494. Xint getNumberWidgetValue(id, value)
  1495. X     int id; 
  1496. X     float *value;
  1497. X{
  1498. X  double number;
  1499. X  char *text, *notText;
  1500. X  MrmCode class;
  1501. X
  1502. X  if (id > numberStringCount) return (1);
  1503. X
  1504. X  if (widgetArray[id] == NULL) {     /* The first time, fetch order box. */
  1505. X      if (MrmFetchWidget(theMrmHierarchy, numberStrings[id], theTopLevel,
  1506. X             &widgetArray[id], &class) != MrmSUCCESS) {
  1507. X    printf("can't fetch number %d\n",id);
  1508. X    return (1);
  1509. X      }
  1510. X    }
  1511. X  /* View Reference Point */
  1512. X  XtVaGetValues(widgetArray[id], XmNvalue, &text, NULL);
  1513. X
  1514. X  number = strtod(text,¬Text);
  1515. X  if (number == 0.0 && text == notText) {
  1516. X    printf(" could get a number %s, %s\n",numberStrings[id],text);
  1517. X    return (1);
  1518. X  }
  1519. X
  1520. X  *value = (float) number;
  1521. X  return (0);
  1522. X}
  1523. X
  1524. X/*************************************************************************
  1525. X * setNumberWidgetValue - set a number into a string widget.
  1526. Xint setNumberWidgetValue(int id, float value)
  1527. X */
  1528. Xint setNumberWidgetValue( id, value)
  1529. Xint id; 
  1530. Xfloat value;
  1531. X{
  1532. X  double number;
  1533. X  char text[80];
  1534. X  MrmCode class;
  1535. X  Arg al[1];
  1536. X    
  1537. X  if (id > numberStringCount) return (1);
  1538. X
  1539. X  if (widgetArray[id] == NULL) {     /* The first time, fetch order box. */
  1540. X      if (MrmFetchWidget(theMrmHierarchy, numberStrings[id], theTopLevel,
  1541. X             &widgetArray[id], &class) != MrmSUCCESS) {
  1542. X    printf("can't fetch number %d\n",id);
  1543. X    return (1);
  1544. X      }
  1545. X    }
  1546. X
  1547. X  sprintf(text, "%1.6f", value);
  1548. X
  1549. X  XtSetArg(al[0],  XmNvalue, text );
  1550. X  XtSetValues(widgetArray[id], al, 1);
  1551. X
  1552. X  return (0);
  1553. X}
  1554. X
  1555. X/*************************************************************************
  1556. X * getWidgetValue - get a floating point number from an integer 
  1557. Xstatic int getWidgetValue(int id, float *value)
  1558. X */
  1559. Xstatic int getWidgetValue( id, value)
  1560. Xint id;
  1561. X float *value;
  1562. X{
  1563. X  double number;
  1564. X  char *text, *notText;
  1565. X  MrmCode class;
  1566. X  int intVal, i;
  1567. X  short decVal;
  1568. X  
  1569. X
  1570. X  if (id > numberStringCount) return (1);
  1571. X
  1572. X  if (widgetArray[id] == NULL) {     /* The first time, fetch order box. */
  1573. X      if (MrmFetchWidget(theMrmHierarchy, numberStrings[id], theTopLevel,
  1574. X             &widgetArray[id], &class) != MrmSUCCESS) {
  1575. X    printf("can't fetch number %d\n",id);
  1576. X    return (1);
  1577. X      }
  1578. X    }
  1579. X  /* View Reference Point */
  1580. X  XtVaGetValues(widgetArray[id],
  1581. X        XmNvalue, &intVal, 
  1582. X        XmNdecimalPoints, &decVal,
  1583. X        NULL);
  1584. X
  1585. X  number = (double)intVal;
  1586. X
  1587. X  for (i = 0; i < (int)decVal; i++ ) number = number / 10.0;
  1588. X
  1589. X/*  printf ("getWidgetValue %d, %d, %d, %g\n", id, intVal, decVal, number); */
  1590. X
  1591. X  *value = (float) number;
  1592. X  return (0);
  1593. X}
  1594. X
  1595. X/*************************************************************************
  1596. X * setWidgetValue - get a floating point number from an integer 
  1597. X * static int getWidgetValue(int id, float *value)
  1598. X */
  1599. Xstatic int setWidgetValue( id, value)
  1600. X     int id;
  1601. X     float *value;
  1602. X{
  1603. X  double number;
  1604. X  MrmCode class;
  1605. X  int intVal, i;
  1606. X  short decVal;
  1607. X  
  1608. X  if (id > numberStringCount) return (1);
  1609. X
  1610. X  if (widgetArray[id] == NULL) {     /* The first time, fetch order box. */
  1611. X      if (MrmFetchWidget(theMrmHierarchy, numberStrings[id], theTopLevel,
  1612. X             &widgetArray[id], &class) != MrmSUCCESS) {
  1613. X    printf("can't fetch number %d\n",id);
  1614. X    return (1);
  1615. X      }
  1616. X    }
  1617. X
  1618. X  XtVaGetValues(widgetArray[id],
  1619. X        XmNvalue, &intVal, 
  1620. X        XmNdecimalPoints, &decVal,
  1621. X        NULL);
  1622. X
  1623. X  number = (double)*value;
  1624. X
  1625. X  for (i = 0; i < (int)decVal; i++ ) number = number * 10.0;
  1626. X
  1627. X  intVal = (int)number;
  1628. X  XtVaSetValues(widgetArray[id],
  1629. X        XmNvalue, &intVal, 
  1630. X        NULL);
  1631. X
  1632. X  return (0);
  1633. X}
  1634. X
  1635. X/*************************************************************************
  1636. X * AddWorkProc - give us something to do when not busy
  1637. Xvoid AddWorkProc(int (*worker)(), char *info)
  1638. X */
  1639. Xvoid AddWorkProc(worker, info)
  1640. Xint (*worker)();
  1641. Xchar *info;
  1642. X{
  1643. X  XtAppAddWorkProc(theAppContext,(XtWorkProc)worker,(XtPointer)info);
  1644. X}
  1645. X
  1646. X
  1647. X/*************************************************************************
  1648. X * motionHandler
  1649. X *
  1650. X * Registered for button motion, meaning when the mouse moves while the
  1651. X * button is down, this routine gets called. 
  1652. X XtEventHandler motionHandler( Widget widget,  XtPointer unused,
  1653. X              XMotionEvent *event,  Boolean *continue_to_dispatch )
  1654. X */
  1655. X
  1656. Xstatic XtEventHandler motionHandler( widget, unused,event,continue_to_dispatch)
  1657. X     Widget widget;
  1658. X     XtPointer unused;
  1659. X     XMotionEvent *event;
  1660. X     Boolean *continue_to_dispatch;
  1661. X{
  1662. X  int button;
  1663. X
  1664. X  if ( event->state == Button1MotionMask ) {
  1665. X    button = 0;
  1666. X  } else if ( event->state == Button2MotionMask ) {
  1667. X    button = 1;
  1668. X  } else if ( event->state == Button3MotionMask ) {
  1669. X    button = 2;
  1670. X  } else {
  1671. X    return;
  1672. X  }
  1673. X
  1674. X  theMotionHandlerTable[button](event);
  1675. X  
  1676. X  *continue_to_dispatch = 1;  /* tells whether to call other dispatchers */
  1677. X}
  1678. X
  1679. X/*************************************************************************
  1680. X * CreateDynGC - create an X GC Resource for Dynamics.
  1681. X *
  1682. X * Got the rubberbanding methodology from contrib/clients/xfig/w_drawPrim.c
  1683. X * But just the idea, no code was copied, hence no copyright.
  1684. X *
  1685. X * The idea is to xor ( exclusive or ) the foreground and the background
  1686. X * together. When it is xor'd with the background it produces the foreground.
  1687. X * 
  1688. X * must be called after the window is set up.
  1689. X */
  1690. XGC CreateDynGC()
  1691. X{
  1692. X  XGCValues values;
  1693. X  unsigned long fg, bg;
  1694. X  GC tGC;
  1695. X
  1696. X  if (theWimpyWindow) {
  1697. X    values.foreground = -1;
  1698. X    values.background = 0;
  1699. X  } else {
  1700. X    XtVaGetValues(theDrawingArea, XmNforeground, &fg, XmNbackground, &bg, NULL);
  1701. X    values.foreground = fg ^ bg;
  1702. X    values.background = bg;
  1703. X  }
  1704. X  values.function = GXxor;
  1705. X  tGC = XCreateGC(XtDisplay(theDrawingArea), theWindow,
  1706. X          GCFunction | GCForeground | GCBackground, &values );
  1707. X  return (tGC);
  1708. X}
  1709. X
  1710. X#define GetNumValue(_a,_b)  {if (getNumberWidgetValue((_a), (_b))) return;}
  1711. X
  1712. X/*
  1713. Xvoid GetVPN( int viewNumber,   PEXVector  *vpn )
  1714. X*/
  1715. Xvoid GetVPN( viewNumber, vpn )
  1716. X     int viewNumber;
  1717. X     PEXVector  *vpn;
  1718. X{
  1719. X  /* view plane normal */
  1720. X  GetNumValue(k_view_pl_norm_x, &vpn->x);
  1721. X  GetNumValue(k_view_pl_norm_y, &vpn->y);
  1722. X  GetNumValue(k_view_pl_norm_z, &vpn->z);
  1723. X}
  1724. X
  1725. Xvoid SetVPN( viewNumber, vpn )
  1726. X     int viewNumber;
  1727. X     PEXVector  *vpn;
  1728. X{
  1729. X  setNumberWidgetValue(k_view_pl_norm_x, vpn->x);
  1730. X  setNumberWidgetValue(k_view_pl_norm_y, vpn->y);
  1731. X  setNumberWidgetValue(k_view_pl_norm_z, vpn->z);
  1732. X}
  1733. X
  1734. X
  1735. Xvoid GetVUP( viewNumber, vup )
  1736. X     int viewNumber;
  1737. X     PEXVector  *vup;
  1738. X{
  1739. X  /* view plane normal */
  1740. X  GetNumValue(k_view_pl_norm_x, &vup->x);
  1741. X  GetNumValue(k_view_pl_norm_y, &vup->y);
  1742. X  GetNumValue(k_view_pl_norm_z, &vup->z);
  1743. X}
  1744. X
  1745. Xvoid SetVUP( viewNumber, vup )
  1746. X     int viewNumber;
  1747. X     PEXVector  *vup;
  1748. X{
  1749. X  setNumberWidgetValue(k_view_pl_norm_x, vup->x);
  1750. X  setNumberWidgetValue(k_view_pl_norm_y, vup->y);
  1751. X  setNumberWidgetValue(k_view_pl_norm_z, vup->z);
  1752. X}
  1753. X
  1754. X/*************************************************************************
  1755. X * ApplySurfaceAttrs
  1756. X */
  1757. Xvoid
  1758. XApplySurfaceAttrs()
  1759. X{
  1760. X  int error, ptr;
  1761. X  int style;
  1762. X  int shade;
  1763. X  int cull;
  1764. X  float value;
  1765. X  PEXReflectionAttributes reflAttrs;
  1766. X
  1767. X  MrmCode class;
  1768. X
  1769. X  if (theSurfaceForm == NULL) {     /* The first time, fetch order box. */
  1770. X    if (MrmFetchWidget(theMrmHierarchy, "surface_dialog", theTopLevel,
  1771. X               &theSurfaceForm, &class) != MrmSUCCESS) {
  1772. X      printf("can't fetch Surface set dialog");
  1773. X      return;
  1774. X    }
  1775. X  }
  1776. X
  1777. X  if (XmToggleButtonGetState(widgetArray[k_sstyle_hollow]))
  1778. X    style = PEXInteriorStyleHollow;
  1779. X  else if (XmToggleButtonGetState(widgetArray[k_sstyle_solid]))
  1780. X    style = PEXInteriorStyleSolid;
  1781. X  else if (XmToggleButtonGetState(widgetArray[k_sstyle_empty]))
  1782. X    style = PEXInteriorStyleEmpty;
  1783. X  else {
  1784. X    printf("bad style\n");
  1785. X    style = PEXInteriorStyleHollow;
  1786. X  }
  1787. X
  1788. X  InteriorStyleCmd(style);
  1789. X
  1790. X  if (XmToggleButtonGetState(widgetArray[k_sshade_flat]))
  1791. X    shade = PEXSurfaceInterpNone;
  1792. X  else if (XmToggleButtonGetState(widgetArray[k_sshade_gouraud]))
  1793. X    shade = PEXSurfaceInterpColor;
  1794. X  else if (XmToggleButtonGetState(widgetArray[k_sshade_dot]))
  1795. X    shade = PEXSurfaceInterpDotProduct;
  1796. X  else if (XmToggleButtonGetState(widgetArray[k_sshade_phong]))
  1797. X    shade = PEXSurfaceInterpNormal;
  1798. X  else {
  1799. X    printf("bad shade\n");
  1800. X    shade = PEXSurfaceInterpNone;
  1801. X  }
  1802. X
  1803. X  SurfaceInterpCmd(shade); /* let this be done in pexdraw */
  1804. X
  1805. X  if (XmToggleButtonGetState(widgetArray[k_cull_none]))
  1806. X    cull = PEXNone;
  1807. X  else if (XmToggleButtonGetState(widgetArray[k_cull_back]))
  1808. X    cull = PEXBackFaces;
  1809. X  else if (XmToggleButtonGetState(widgetArray[k_cull_front]))
  1810. X    cull = PEXFrontFaces;
  1811. X  else {
  1812. X    printf("bad cull\n");
  1813. X    cull = PEXNone;
  1814. X  }
  1815. X
  1816. X  FacetCullingCmd(cull);
  1817. X
  1818. X#ifndef NO_TRANS
  1819. X  if (getWidgetValue(k_surface_refl_transparency, &value)) return;
  1820. X  if (value > /* arbitrary threshold for transparency */0.00001 ) {
  1821. X    reflAttrs.transmission = value;
  1822. X  } else reflAttrs.transmission = 0.0;
  1823. X#endif
  1824. X    
  1825. X  if (getWidgetValue(k_surface_refl_ambient, &value)) return;
  1826. X  reflAttrs.ambient = value;    /* ambient coefficient */
  1827. X  if (getWidgetValue(k_surface_refl_diffuse, &value)) return;
  1828. X  reflAttrs.diffuse = value;    /* diffuse coefficient */
  1829. X  if (getWidgetValue(k_surface_refl_specular, &value)) return;
  1830. X  reflAttrs.specular = value;    /* specular coefficient */
  1831. X  /* set specular color to white */
  1832. X  if (getWidgetValue(k_surface_refl_specexp, &value)) return;
  1833. X  reflAttrs.specular_conc = value;    /* specular exponent */
  1834. X  reflAttrs.specular_color.type = PEXColorTypeRGB;
  1835. X  reflAttrs.specular_color.value.rgb.red   = 1.0;
  1836. X  reflAttrs.specular_color.value.rgb.green = 1.0;
  1837. X  reflAttrs.specular_color.value.rgb.blue  = 1.0;
  1838. X
  1839. X  ReflectionAttributesCmd(&reflAttrs);
  1840. X
  1841. X}
  1842. X
  1843. X/*
  1844. XGetSomeTextFromUI(int x, int y, int *length, char **charStr, int *flags )
  1845. X*/
  1846. XGetSomeTextFromUI( x, y, length, charStr, flags )
  1847. X     int x;
  1848. X     int y;
  1849. X     int *length;
  1850. X     char **charStr;
  1851. X     int *flags;
  1852. X{
  1853. X  *length = strlen("hello world");
  1854. X  *charStr = malloc(*length+1);
  1855. X  strcpy(*charStr, "hello world");
  1856. X  *flags = 0;
  1857. X}
  1858. X
  1859. X/*************************************************************************
  1860. X * ApplySpin
  1861. X */
  1862. Xint
  1863. XApplySpin(si)
  1864. X     SpinInfo *si;
  1865. X{
  1866. X  int error, okToSet;
  1867. X  float value;
  1868. X
  1869. X  MrmCode class;
  1870. X
  1871. X  if (theSpinForm == NULL) {     /* The first time, fetch order box. */
  1872. X    if (MrmFetchWidget(theMrmHierarchy, "spin_dialog", theTopLevel,
  1873. X               &theSpinForm, &class) != MrmSUCCESS) {
  1874. X      printf("can't fetch Spin set dialog");
  1875. X      return;
  1876. X    }
  1877. X  }
  1878. X    
  1879. X  FetchValue(k_spinf_px, &si->point.x);
  1880. X  FetchValue(k_spinf_py, &si->point.y);
  1881. X  FetchValue(k_spinf_pz, &si->point.z);
  1882. X
  1883. X  FetchValue(k_spinf_ox, &si->offset.x);
  1884. X  FetchValue(k_spinf_oy, &si->offset.y);
  1885. X  FetchValue(k_spinf_oz, &si->offset.z);
  1886. X
  1887. X  okToSet = XmToggleButtonGetState(widgetArray[k_spinf_stop]);
  1888. X
  1889. X  if (okToSet) {
  1890. X    FetchValue(k_spinf_xang, &si->x_ang);
  1891. X    FetchValue(k_spinf_yang, &si->y_ang);
  1892. X    FetchValue(k_spinf_zang, &si->z_ang);
  1893. X  }
  1894. X
  1895. X  FetchValue(k_spinf_dx, &si->delta_x);
  1896. X  FetchValue(k_spinf_dy, &si->delta_y);
  1897. X  FetchValue(k_spinf_dz, &si->delta_z);
  1898. X
  1899. X  FetchValue(k_spinf_scale, &value);
  1900. X
  1901. X  si->scale.x = value;
  1902. X  si->scale.y = value;
  1903. X  si->scale.z = value;
  1904. X
  1905. X}
  1906. X
  1907. Xint
  1908. XLoadSpinWidget(si)
  1909. X     SpinInfo *si;
  1910. X{
  1911. X  char text[80];
  1912. X  Arg al[1];
  1913. X
  1914. X  setNumberWidgetValue(k_spinf_px, si->point.x);
  1915. X  setNumberWidgetValue(k_spinf_py, si->point.y);
  1916. X  setNumberWidgetValue(k_spinf_pz, si->point.z);
  1917. X
  1918. X  setNumberWidgetValue(k_spinf_ox, si->offset.x);
  1919. X  setNumberWidgetValue(k_spinf_oy, si->offset.y);
  1920. X  setNumberWidgetValue(k_spinf_oz, si->offset.z);
  1921. X
  1922. X  setNumberWidgetValue(k_spinf_xang, si->x_ang);
  1923. X  setNumberWidgetValue(k_spinf_yang, si->y_ang);
  1924. X  setNumberWidgetValue(k_spinf_zang, si->z_ang);
  1925. X
  1926. X  setNumberWidgetValue(k_spinf_dx, si->delta_x);
  1927. X  setNumberWidgetValue(k_spinf_dy, si->delta_y);
  1928. X  setNumberWidgetValue(k_spinf_dz, si->delta_z);
  1929. X
  1930. X  setNumberWidgetValue(k_spinf_scale, si->scale.x);
  1931. X
  1932. X  XmToggleButtonSetState(widgetArray[k_spinf_stop],False,False);
  1933. X
  1934. X  sprintf(text, "%x", si->strux);
  1935. X
  1936. X  XtSetArg(al[0],  XmNvalue, text );
  1937. X  XtSetValues(widgetArray[k_spinf_strux], al, 1);
  1938. X
  1939. X}
  1940. X/*************************************************************************
  1941. X * LoadColorWidget - actually, that is all widget in form
  1942. X */
  1943. Xint
  1944. XLoadColorWidget(strux, elem, rgb)
  1945. X     PEXStructure strux;
  1946. X     long  elem;
  1947. X     PEXColorRGB *rgb;
  1948. X{
  1949. X  char text[80];
  1950. X  Arg al[1];
  1951. X
  1952. X  setWidgetValue(k_color_red, &rgb->red);
  1953. X  setWidgetValue(k_color_green, &rgb->green);
  1954. X  setWidgetValue(k_color_blue, &rgb->blue);
  1955. X
  1956. X  sprintf(text, "%x", strux);
  1957. X  XtSetArg(al[0],  XmNvalue, text );
  1958. X  XtSetValues(widgetArray[k_color_strux], al, 1);
  1959. X
  1960. X  sprintf(text, "%d", elem);
  1961. X  XtSetArg(al[0],  XmNvalue, text );
  1962. X  XtSetValues(widgetArray[k_color_elem], al, 1);
  1963. X
  1964. X}
  1965. X
  1966. X/*************************************************************************
  1967. X * ApplyColor, get the color, call SetColorAttribute
  1968. X */
  1969. Xint
  1970. XApplyColor(strux, elem)
  1971. X     PEXStructure strux;
  1972. X     long  elem;
  1973. X{
  1974. X  PEXColorRGB rgb;
  1975. X
  1976. X  if (elem == -1 ) {printf("nothing selected, can't change colour\n"); return;}
  1977. X
  1978. X  getWidgetValue(k_color_red, &rgb.red);
  1979. X  getWidgetValue(k_color_green, &rgb.green);
  1980. X  getWidgetValue(k_color_blue, &rgb.blue);
  1981. X
  1982. X  SetColorAttribute( strux, elem, &rgb);
  1983. X}
  1984. X
  1985. X
  1986. X/***********************************************************************
  1987. X * FinishExec - last minute hacking for the sake of a cheap example
  1988. X */
  1989. Xstatic void
  1990. XFinishExec(event)
  1991. X XButtonReleasedEvent *event;
  1992. X{
  1993. X  long s;
  1994. X  int e;
  1995. X
  1996. X  if ( theSelectedElement != -1 ) {
  1997. X    theRenderProcs.PickOne( event->x, event->y, &s, &e);
  1998. X    if ( e != -1 )
  1999. X      ExecStrux(s);
  2000. X    theRenderProcs.ReDraw();
  2001. X  }
  2002. X}
  2003. END_OF_FILE
  2004.   if test 43663 -ne `wc -c <'ui.c'`; then
  2005.     echo shar: \"'ui.c'\" unpacked with wrong size!
  2006.   fi
  2007.   # end of 'ui.c'
  2008. fi
  2009. echo shar: End of archive 5 \(of 14\).
  2010. cp /dev/null ark5isdone
  2011. MISSING=""
  2012. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
  2013.     if test ! -f ark${I}isdone ; then
  2014.     MISSING="${MISSING} ${I}"
  2015.     fi
  2016. done
  2017. if test "${MISSING}" = "" ; then
  2018.     echo You have unpacked all 14 archives.
  2019.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2020.     echo "concatentating pexdraw.c ..."
  2021.     cat pexdrawc.? > pexdraw.c
  2022.     rm pexdrawc.?
  2023.     echo "concatentating pexdraw.uil ..."
  2024.     cat pexdrawu.? > pexdraw.uil
  2025.     rm pexdrawu.?
  2026.     echo "concatentating teapot.c ..."
  2027.     rm teapotc.?
  2028. else
  2029.     echo You still must unpack the following archives:
  2030.     echo "        " ${MISSING}
  2031. fi
  2032. exit 0
  2033. exit 0 # Just in case...
  2034. -- 
  2035.   // chris@IMD.Sterling.COM       | Send comp.sources.x submissions to:
  2036. \X/  Amiga - The only way to fly! |    sources-x@imd.sterling.com
  2037.  "It's intuitively obvious to the |
  2038.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  2039.