PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/accis/vecxg77.c

https://github.com/chaako/sceptic3D
C | 323 lines | 181 code | 20 blank | 122 comment | 13 complexity | 9556655742577defcefbb6cb94c86347 MD5 | raw file
  1. /* Xwindow driver for accis plotting */
  2. /* Fortran callable (f2c) routines */
  3. /* ********************************************************************** */
  4. /*
  5. Refreshing version.
  6. */
  7. #include <X11/StringDefs.h>
  8. #include <X11/Intrinsic.h>
  9. #include <X11/Core.h>
  10. /* Globals for these routines*/
  11. Widget accis_wshell;
  12. Widget accis_drawing;
  13. Display *accis_display;
  14. Drawable accis_window;
  15. Pixmap accis_pixmap;
  16. GC accis_gc;
  17. int accis_depth;
  18. Colormap accis_colormap;
  19. struct Screen_Size {
  20. Dimension width; /* unsigned short */
  21. Dimension height;
  22. };
  23. static struct Screen_Size s_s;
  24. #define a_maxPixels 16
  25. unsigned long accis_pixels[a_maxPixels];
  26. char *accis_colornames[a_maxPixels]=
  27. {
  28. "White",
  29. "MediumBlue",
  30. "SeaGreen",
  31. "MediumTurquoise",
  32. "Firebrick",
  33. "Orchid",
  34. "Brown",
  35. "LightGrey",
  36. "SlateGrey",
  37. "Blue",
  38. "Green",
  39. "Cyan",
  40. "Red",
  41. "Magenta",
  42. "Yellow",
  43. "Black"
  44. };
  45. /* Subroutine */
  46. int svga_(scrxpix, scrypix, vmode, ncolor)
  47. int *scrxpix, *scrypix, *vmode, *ncolor;
  48. {
  49. static int second=0;
  50. extern int f__xargc;
  51. extern char **f__xargv;
  52. int svga_argc=0;
  53. char *svga_argv[1];
  54. static int n;
  55. static Arg wargs[10];
  56. int theDepth;
  57. Colormap theColormap;
  58. extern void config_handler();
  59. extern void accis_refresh();
  60. if(second == 0){
  61. accis_wshell = XtInitialize("accis","Accis", NULL, 0,
  62. &f__xargc, f__xargv); /* This refers to the f2c command line args.
  63. It may only work with f2c, therefore. */
  64. /* &svga_argc, svga_argv); alternate */
  65. accis_drawing = XtCreateManagedWidget("drawing",coreWidgetClass,
  66. accis_wshell, NULL, 0);
  67. *vmode=88;
  68. *ncolor=15;
  69. /* Set up a default size of the drawing window widget.
  70. This is overruled by Accis*geometry resources setting wshell size.
  71. */
  72. n = 0;
  73. XtSetArg(wargs[n], XtNheight, 480); n++;
  74. XtSetArg(wargs[n], XtNwidth, 640); n++;
  75. XtSetValues(accis_drawing, wargs, n);
  76. XtRealizeWidget(accis_wshell);
  77. accis_display = XtDisplay(accis_drawing);
  78. accis_window = XtWindow(accis_drawing);
  79. accis_gc = XCreateGC(accis_display, accis_window, 0, NULL);
  80. accis_depth=DefaultDepth(accis_display,0);
  81. accis_colormap=DefaultColormap(accis_display,0);
  82. initDefaultColors();
  83. /* Leave setup for resizing. */
  84. n = 0;
  85. XtSetArg(wargs[n], XtNheight, &s_s.height); n++;
  86. XtSetArg(wargs[n], XtNwidth, &s_s.width); n++;
  87. /* Pixmap setup */
  88. XtGetValues(accis_wshell, wargs, n);
  89. accis_pixmap=XCreatePixmap(accis_display,accis_window,
  90. s_s.width,s_s.height,accis_depth);
  91. XtAddEventHandler(accis_drawing,ExposureMask,FALSE,
  92. accis_refresh,NULL);
  93. XSelectInput(accis_display,accis_window,
  94. KeyPressMask | ExposureMask | ButtonPress
  95. | FocusChangeMask | EnterWindowMask ); /* Tell events */
  96. second++;
  97. }else{
  98. /* Need to have this to make the get correct. */
  99. ManageEvents();
  100. }
  101. /* This doesn't need a configuration event handler to work correctly. */
  102. XtGetValues(accis_wshell, wargs, n);
  103. *scrxpix=s_s.width;
  104. *scrypix=s_s.height;
  105. XFlush(accis_display);
  106. XClearWindow(accis_display,accis_window);
  107. XSetForeground(accis_display,accis_gc,accis_pixels[0]);
  108. /* Clear the window to background color. VMS doesn't do correctly.
  109. But also this seems to fix the bad match error. */
  110. XFillRectangle(accis_display,accis_window,accis_gc,0,0,
  111. s_s.width,s_s.height);
  112. /* Clear the pixmap */
  113. XFillRectangle(accis_display,accis_pixmap,accis_gc,0,0,
  114. s_s.width,s_s.height);
  115. XSetForeground(accis_display,accis_gc,accis_pixels[15]);
  116. XSetInputFocus(accis_display, accis_window, RevertToPointerRoot,
  117. CurrentTime);
  118. return 0;
  119. }
  120. /* ******************************************************************** */
  121. initDefaultColors()
  122. {
  123. XColor theRGBColor,theHardColor;
  124. int status;
  125. int i;
  126. for(i=0;i<a_maxPixels;i++){
  127. status=XLookupColor(accis_display,accis_colormap,accis_colornames[i],
  128. &theRGBColor,&theHardColor);
  129. if(status !=0){
  130. status=XAllocColor(accis_display,accis_colormap,&theHardColor);
  131. if(status !=0){
  132. accis_pixels[i]=theHardColor.pixel;
  133. }else{
  134. accis_pixels[i]=BlackPixel(accis_display,0);
  135. }
  136. }else{
  137. accis_pixels[i]=BlackPixel(accis_display,0);
  138. }
  139. }
  140. }
  141. /* ******************************************************************** */
  142. /* End plotting and return to text editing. */
  143. /* Subroutine */
  144. /* #include <curses.h>*/
  145. int txtmode_()
  146. {
  147. XEvent event;
  148. XFlush(accis_display);
  149. do{
  150. /* printf("Executing XtNextEvent"); */
  151. XtNextEvent(&event);
  152. /* XNextEvent(accis_display,&event); is equivalent */
  153. XtDispatchEvent(&event);
  154. /* printf("The event type: %d\n",event); */
  155. }while(event.type != ButtonPress && event.type != KeyPress );
  156. /* Here we should give the focus back to parent, but I don't see how.
  157. XSetInputFocus(accis_display, ??, PointerRoot,
  158. CurrentTime); */
  159. }
  160. /* ********************************************************************* */
  161. /* Subroutine */ int scolor_(li)
  162. long *li;
  163. {
  164. /* *ncolor=*li; */
  165. if((*li < a_maxPixels) && (*li >= 0)){
  166. XSetForeground(accis_display,accis_gc,accis_pixels[(int) *li]);
  167. return 1;
  168. }else{
  169. return 0;
  170. }
  171. } /* scolor_ */
  172. /* ******************************************************************** */
  173. /* Subroutine */ int vec_(px, py, ud)
  174. long *px, *py, *ud;
  175. { /* Draw vector on screen, with pen up or down. */
  176. static int px1=0,py1=0,px2=0,py2=0;
  177. px1=px2;
  178. py1=py2;
  179. px2 = *px;
  180. py2 = *py;
  181. if (*ud == 0) {
  182. } else {
  183. XDrawLine(XtDisplay(accis_drawing),XtWindow(accis_drawing), accis_gc,
  184. px1,py1,px2,py2);
  185. XDrawLine(XtDisplay(accis_drawing),accis_pixmap, accis_gc,
  186. px1,py1,px2,py2);
  187. }
  188. /* XFlush(accis_display);
  189. Flush removed here. Now relies on txtmode to flush display. */
  190. return 0;
  191. } /* vec_ */
  192. /* ******************************************************************** */
  193. /* Not currently in use. */
  194. void config_handler(w,cs_s,event)
  195. Widget w;
  196. struct Screen_Size cs_s;
  197. XEvent *event;
  198. {
  199. cs_s.width=event->xconfigure.width;
  200. cs_s.height=event->xconfigure.height;
  201. printf("config_handler width= %d, height= %d\n",cs_s.width,cs_s.height);
  202. }
  203. /* ******************************************************************** */
  204. /* ******************************************************************** */
  205. void accis_refresh(w,data,event)
  206. Widget w;
  207. caddr_t data;
  208. XEvent *event;
  209. {
  210. XCopyArea(XtDisplay(w),accis_pixmap,accis_window,accis_gc,0,0,
  211. s_s.width,s_s.height,0,0);
  212. XFlush(accis_display);
  213. }
  214. /* ******************************************************************** */
  215. ManageEvents()
  216. {
  217. XEvent event;
  218. while(XtPending()){
  219. XtNextEvent(&event);
  220. XtDispatchEvent(&event);
  221. }
  222. }
  223. /* ******************************************************************** */
  224. /* Testing only */
  225. /*
  226. main()
  227. {
  228. long li=1;
  229. int x=200,y=150,pen=1;
  230. int a,b,c,d;
  231. int ch;
  232. while(ch != 'q'){
  233. printf("Calling svga\n");
  234. svga_(&a,&b,&c,&d);
  235. printf("Returned, x= %d, y= %d, mode= %d, ncolor= %d,\n",
  236. a,b,c,d);
  237. printf("Drawing stuff directly\n");
  238. draw_graphics(accis_drawing);
  239. printf("Drawing line using vec_\n");
  240. for(a=0;a<16;a++){
  241. li=a;
  242. scolor_(&li);
  243. for(b=0;b<10;b++){
  244. pen=0;x=200;y=150+10*a+b;
  245. vec_(&x,&y,&pen);
  246. pen=1;x=400;y=150+10*a+b;
  247. vec_(&x,&y,&pen);
  248. }
  249. }
  250. ch=getchar();
  251. }
  252. }
  253. draw_graphics(w)
  254. Widget w; {
  255. Display *display;
  256. Drawable window;
  257. GC gc;
  258. int store;
  259. XWindowAttributes attributes;
  260. XSetWindowAttributes sattributes;
  261. unsigned long valuemask;
  262. display = XtDisplay(w);
  263. window = XtWindow(w);
  264. store= DoesBackingStore(DefaultScreenOfDisplay(display));
  265. printf("DoesBackingstore return, %d of
  266. NotUseful,WhenMapped,Always %d,%d,%d\n",
  267. store,NotUseful,WhenMapped,Always);
  268. XGetWindowAttributes(display,window,&attributes);
  269. printf("Got attributes. backing_store,planes,pixel,%d %x %u\n"
  270. ,attributes.backing_store,attributes.backing_planes,
  271. attributes.backing_pixel);
  272. gc = XCreateGC(display, window, 0, NULL);
  273. XSetForeground(display, gc, 50);
  274. XSetBackground(display, gc, 0);
  275. XDrawLine(display, window, gc, 10, 10, 400, 400);
  276. XDrawRectangle(display, window, gc, 75, 110, 150, 100);
  277. XDrawArc(display, window, gc, 75, 110, 150, 100, 45*64, 120*64);
  278. XFreeGC(display, gc);
  279. }
  280. */
  281. /* ******************************************************************** */
  282. /* This broke with a complaint about pixmaps.
  283. valuemask=CWBackingStore || CWBackingPlanes || CWBackingPixel;
  284. sattributes.backing_store=2;
  285. sattributes.backing_planes=255;
  286. sattributes.backing_pixel=1;
  287. XChangeWindowAttributes(display, window, valuemask, &sattributes);
  288. XGetWindowAttributes(display,window,&attributes);
  289. printf("Got attributes. backing_store,planes,pixel,%d %x %u\n"
  290. ,attributes.backing_store,attributes.backing_planes,
  291. attributes.backing_pixel);
  292. */