Annotation of OpenXM_contrib2/asir2000/plot/ox_plot_xevent.c, Revision 1.17
1.2 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.17 ! takayama 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/ox_plot_xevent.c,v 1.16 2002/07/11 12:35:03 takayama Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include "ox.h"
53: #include "ifplot.h"
54: #include "cursor.h"
1.8 takayama 55: #include <X11/Xaw/MenuButton.h>
56: #include <X11/Xaw/Paned.h>
1.14 noro 57:
58: /* XXX : these lines are in plotg.c, but ld says they are not defined */
59: #if __DARWIN__
60: int stream;
61:
62: DISPLAY *display;
63: CURSOR normalcur,runningcur,errorcur;
64:
65: #if defined(VISUAL)
66: POINT start_point, end_point;
67: SIZE cansize;
68: #else
69: Window rootwin;
70: GC drawGC,dashGC,hlGC,scaleGC,clearGC,xorGC,colorGC,cdrawGC;
71: XFontStruct *sffs;
72: #endif
73:
74: struct canvas *canvas[MAXCANVAS];
75: struct canvas *current_can;
76: #endif /* __DARWIN__ */
1.1 noro 77:
78: #ifdef ABS
79: #undef ABS
80: #define ABS(a) ((a)>0?(a):-(a))
81: #endif
82:
83: static char *dname;
84: static int remotes;
85: static int depth,scrn;
86:
1.13 noro 87: extern JMP_BUF ox_env;
1.1 noro 88: static Widget toplevel;
89: static XtAppContext app_con;
90:
91: static int busy;
92:
93: static struct PlotResources {
94: Pixel ForePixel,BackPixel,DashPixel;
95: char *ForeName,*BackName,*DashName;
96: Boolean Reverse;
97: } PlotResources;
98:
99: #define forePixel PlotResources.ForePixel
100: #define backPixel PlotResources.BackPixel
101: #define dashPixel PlotResources.DashPixel
102: #define foreName PlotResources.ForeName
103: #define backName PlotResources.BackName
104: #define dashName PlotResources.DashName
105: #define reverse PlotResources.Reverse
106:
107: Cursor create_cursor();
108:
109: #define blackPixel BlackPixel(display,scrn)
110: #define whitePixel WhitePixel(display,scrn)
111:
112: #define LABELWIDTH 150
113:
114: process_xevent() {
115: XEvent ev;
116:
117: while ( XPending(display) ) {
118: XtAppNextEvent(app_con,&ev);
119: XtDispatchEvent(&ev);
120: }
121: }
122:
123: /* event handlers */
124:
125: static POINT spos,cpos;
126:
127: void press(w,can,ev)
128: Widget w;
129: struct canvas *can;
130: XButtonEvent *ev;
131: {
132: POINT p;
133:
134: switch ( ev->button ) {
135: case Button1:
136: XC(spos) = ev->x; YC(spos) = ev->y; cpos = spos; break;
137: case Button3:
138: XC(p) = ev->x; YC(p) = ev->y; draw_coord(can,&p); break;
139: default:
140: break;
141: }
142: }
143:
144: void motion(w,can,ev)
145: Widget w;
146: struct canvas *can;
147: XMotionEvent *ev;
148: {
149:
150: POINT o,p;
151:
152: if ( ev->state & Button1Mask ) {
153: o = cpos; XC(cpos) = ev->x; YC(cpos) = ev->y;
154: draw_frame(can->window,spos,o,cpos);
155: } else if ( ev->state & Button3Mask ) {
156: XC(p) = ev->x; YC(p) = ev->y;
157: draw_coord(can,p);
158: }
159: }
160:
161: void release(w,can,ev)
162: Widget w;
163: struct canvas *can;
164: XButtonEvent *ev;
165: {
166: POINT e;
167:
168: switch ( ev->button ) {
169: case Button1:
170: e.x = ev->x; e.y = ev->y;
171: draw_frame0(can->window,spos,e);
1.10 noro 172: if ( !busy && can->mode != MODE_INTERACTIVE ) {
1.1 noro 173: if ( can->mode == MODE_PLOT )
174: plot_resize(can,spos,e);
175: else
176: ifplot_resize(can,spos,e);
177: }
178: break;
179: default:
180: break;
181: }
182: }
183:
184: void structure(w,can,ev)
185: Widget w;
186: struct canvas *can;
187: XEvent *ev;
188: {
189: switch ( ev->xany.type ) {
190: case Expose:
191: if ( !ev->xexpose.count )
192: redraw_canvas(can);
193: break;
194: case ConfigureNotify:
195: redraw_canvas(can); break;
196: default:
197: break;
198: }
199: }
200:
201: static int lindex;
202:
203: void lpress(w,can,ev)
204: Widget w;
205: struct canvas *can;
206: XButtonEvent *ev;
207: {
208: lindex = (can->height-ev->y)/(can->height/can->nzstep);
209: draw_level(can,lindex,hlGC);
210: }
211:
212: void jumpproc(w,can,percent)
213: Widget w;
214: struct canvas *can;
215: float *percent;
216: {
217: int index;
218:
219: index = can->nzstep * (1.0-*percent);
220: if ( index == lindex )
221: return;
222: if ( lindex >= 0 )
223: draw_level(can,lindex,drawGC);
224: lindex = index;
225: draw_level(can,lindex,hlGC);
226: }
227:
228: void jumpproc_m(w,can,percent)
229: Widget w;
230: struct canvas *can;
231: float *percent;
232: {
233: int index;
234:
235: index = can->nzstep * (1.0-*percent);
236: if ( index != lindex ) {
237: draw_level(can,lindex,drawGC);
238: draw_level(can,lindex,hlGC);
239: }
240: }
241:
242: void lrelease(w,can,ev)
243: Widget w;
244: struct canvas *can;
245: XButtonEvent *ev;
246: {
247: draw_level(can,lindex,drawGC); lindex = -1;
248: }
249:
250: void lrelease_m(w,can,ev)
251: Widget w;
252: struct canvas *can;
253: XButtonEvent *ev;
254: {
255: lindex = -1;
256: }
257:
258: draw_level(can,index,gc)
259: struct canvas *can;
260: int index;
261: GC gc;
262: {
263: Pixmap pix;
264: struct pa *pa;
265: int i,len;
266: POINT *p;
267: Arg arg[2];
268: char buf[BUFSIZ];
269:
270: if ( busy || can->wide || index < 0 || index > can->nzstep )
271: return;
272: pix = can->pix; pa = &can->pa[index]; len = pa->length; p = pa->pos;
273: for ( i = 0; i < len; i++ )
274: XDrawPoint(display,pix,gc,p[i].x,p[i].y);
275: sprintf(buf,"level:%g",can->zmin+(can->zmax-can->zmin)*index/can->nzstep);
276: XtSetArg(arg[0],XtNlabel,buf); XtSetArg(arg[1],XtNwidth,LABELWIDTH);
277: XtSetValues(can->level,arg,2);
278: copy_to_canvas(can);
279: }
280:
281: draw_frame(window,spos,opos,epos)
282: Window window;
283: POINT spos,opos,epos;
284: {
285: if ( XC(opos) != XC(epos) || YC(opos) != YC(epos) )
286: draw_frame0(window,spos,opos);
287: draw_frame0(window,spos,epos);
288: }
289:
290: draw_frame0(window,spos,epos)
291: Window window;
292: POINT spos,epos;
293: {
294: int ulx,uly,w,h;
295:
296: ulx = MIN(XC(spos),XC(epos)); uly = MIN(YC(spos),YC(epos));
297: w = ABS(XC(spos)-XC(epos)); h = ABS(YC(spos)-YC(epos));
298: if ( !w || !h )
299: return;
300: XDrawRectangle(display,window,xorGC,ulx,uly,w,h);
301: XFlush(display);
302: }
303:
304: draw_coord(can,pos)
305: struct canvas *can;
306: POINT pos;
307: {
308: char buf[BUFSIZ];
309: Arg arg[2];
310: double x,y,xmin,ymax,dx,dy;
311:
312: if ( can->wide ) {
313: dx = 10*(can->xmax-can->xmin); dy = 10*(can->ymax-can->ymin);
314: xmin = (can->xmax+can->xmin-dx)/2;
315: ymax = (can->ymax+can->ymin+dy)/2;
316: } else {
317: dx = can->xmax-can->xmin; dy = can->ymax-can->ymin;
318: xmin = can->xmin; ymax = can->ymax;
319: }
320: x = xmin+XC(pos)*dx/can->width;
321: y = ymax-YC(pos)*dy/can->height;
322: sprintf(buf,"%s:%g",can->vx?can->vx->name:"horiz",x);
323: XtSetArg(arg[0],XtNlabel,buf); XtSetArg(arg[1],XtNwidth,LABELWIDTH);
324: XtSetValues(can->xcoord,arg,2);
325: sprintf(buf,"%s:%g",can->vy?can->vy->name:"vert",y);
326: XtSetArg(arg[0],XtNlabel,buf); XtSetArg(arg[1],XtNwidth,LABELWIDTH);
327: XtSetValues(can->ycoord,arg,2);
328: }
329:
330: redraw_canvas(can)
331: struct canvas *can;
332: {
333: if ( can->wide )
334: draw_wideframe(can);
335: else
336: copy_to_canvas(can);
337: }
338:
339: search_canvas()
340: {
341: int i;
342:
343: for ( i = 0; i < MAXCANVAS; i++ )
344: if ( !canvas[i] ) {
345: canvas[i] = (struct canvas *)MALLOC(sizeof(struct canvas));
346: canvas[i]->index = i; return i;
347: }
348: }
349:
350: search_active_canvas()
351: {
352: int i;
353:
354: for ( i = 0; i < MAXCANVAS; i++ )
355: if ( canvas[i] )
356: return i;
357: return -1;
358: }
359:
1.4 takayama 360:
361:
1.1 noro 362: void destroy_canvas(w,can,calldata)
363: Widget w;
364: struct canvas *can;
365: XtPointer calldata;
366: {
367: XtPopdown(can->shell);
368: XtDestroyWidget(can->shell);
369: XFlush(display);
370: if ( can == current_can ) {
371: reset_busy(can); current_can = 0;
372: }
373: canvas[can->index] = 0;
374: }
375:
376: void precise_canvas(w,can,calldata)
377: Widget w;
378: struct canvas *can;
379: XtPointer calldata;
380: {
381: if ( can->precise )
382: can->precise = 0;
383: else
384: can->precise = 1;
385: }
386:
387: void wide_canvas(w,can,calldata)
388: Widget w;
389: struct canvas *can;
390: XtPointer calldata;
391: {
392: if ( can->wide ) {
393: can->wide = 0; copy_to_canvas(can);
394: } else {
395: can->wide = 1; draw_wideframe(can);
396: }
397: }
398:
399: void noaxis_canvas(w,can,calldata)
400: Widget w;
401: struct canvas *can;
402: XtPointer calldata;
403: {
404: if ( can->noaxis )
405: can->noaxis = 0;
406: else
407: can->noaxis = 1;
408: if ( can->wide )
409: draw_wideframe(can);
410: else
411: copy_to_canvas(can);
412: }
413:
414: toggle_button(w,flag)
415: Widget w;
416: int flag;
417: {
418: Arg arg[2];
419:
420: if ( flag ) {
421: XtSetArg(arg[0],XtNforeground,backPixel);
422: XtSetArg(arg[1],XtNbackground,forePixel);
423: } else {
424: XtSetArg(arg[0],XtNforeground,forePixel);
425: XtSetArg(arg[1],XtNbackground,backPixel);
426: }
427: XtSetValues(w,arg,2); XFlush(display);
428: }
429:
430: draw_wideframe(can)
431: struct canvas *can;
432: {
433: struct canvas fakecan;
434: double xmin,xmax,ymin,ymax,xmid,ymid,dx,dy;
435: POINT s,e;
436:
437: fakecan = *can;
438: dx = 10*(can->xmax-can->xmin); dy = 10*(can->ymax-can->ymin);
439: xmid = (can->xmax+can->xmin)/2; ymid = (can->ymax+can->ymin)/2;
440:
441: fakecan.xmin = xmid-dx/2; fakecan.xmax = xmid+dx/2;
442: fakecan.ymin = ymid-dy/2; fakecan.ymax = ymid+dy/2;
443:
444: XFillRectangle(display,can->window,clearGC,
445: 0,0,can->width,can->height);
446: pline(display,&fakecan,can->window);
447: XC(s) = can->width*9/20; YC(s) = can->height*9/20;
448: XC(e) = can->width*11/20; YC(e) = can->height*11/20;
449: draw_frame0(can->window,s,e);
450: }
451:
452: create_popup(parent,name,str,shell,dialog)
453: Widget parent;
454: char *name,*str;
455: Widget *shell,*dialog;
456: {
457: Arg arg[3];
458: Position x,y;
459:
460: XtTranslateCoords(parent,0,0,&x,&y);
461: XtSetArg(arg[0],XtNx,x); XtSetArg(arg[1],XtNy,y);
462: *shell = XtCreatePopupShell(name,transientShellWidgetClass,parent,arg,2);
463: XtSetArg(arg[0],XtNlabel,str);
464: *dialog = XtCreateManagedWidget("dialog",dialogWidgetClass,*shell,arg,1);
465: }
466:
467: warning(can,s)
468: struct canvas *can;
469: char *s;
470: {
471: void popdown_warning();
472: Widget warnshell,warndialog;
473: Position x,y;
474: Arg arg[3];
475:
476: if ( !can->shell )
477: return;
478: create_popup(can->shell,"warning",s,&warnshell,&warndialog);
479: XawDialogAddButton(warndialog,"dismiss",popdown_warning,warnshell);
480: XtPopup(warnshell,XtGrabNone);
481: }
482:
483: void popdown_warning(w,client,call)
484: Widget w;
485: XtPointer client,call;
486: {
487: XtPopdown(client); XtDestroyWidget(client);
488: }
489:
490: void show_formula(w,can,calldata)
491: Widget w;
492: struct canvas *can;
493: XtPointer calldata;
494: {
495: void popdown_formula();
496: Widget fshell,fdialog;
497: char buf[BUFSIZ];
498:
499: soutput_init(buf); sprintexpr(CO,(Obj)can->formula);
500: create_popup(can->shell,"formula",buf,&fshell,&fdialog);
501: XawDialogAddButton(fdialog,"dismiss",popdown_formula,w);
502: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
503: }
504:
505: void popdown_formula(w,fbutton,call)
506: Widget w,fbutton;
507: XtPointer call;
508: {
509: Widget shell = XtParent(XtParent(w));
510: XtPopdown(shell); XtDestroyWidget(shell);
511: XtSetSensitive(fbutton,True);
512: }
513:
514: #define NormalSelection ButtonPressMask|ButtonReleaseMask|Button1MotionMask|Button3MotionMask|StructureNotifyMask| ExposureMask
515:
516: create_canvas(can)
517: struct canvas *can;
518: {
519: XEvent event;
520: Widget box,frame,commands,
1.4 takayama 521: coords,quit,print,wide,precise,canvas,formula;
1.1 noro 522: Window window;
523: Pixmap pix;
524: int i,width,height;
525: Arg arg[6];
526: char buf[BUFSIZ];
1.8 takayama 527: static void print_canvas();
1.1 noro 528:
529: width = can->width; height = can->height;
530:
531: sprintf(buf,"%s : %d/%d", can->wname?can->wname:"Plot",
532: remotes,can->index);
533: XtSetArg(arg[0],XtNiconName,buf);
534: can->shell =
535: XtCreatePopupShell("shell",topLevelShellWidgetClass,toplevel,arg,1);
536:
537: XtSetArg(arg[0],XtNhSpace,0);
538: XtSetArg(arg[1],XtNvSpace,0);
539: XtSetArg(arg[2],XtNborderWidth,0);
540: box = XtCreateManagedWidget("box",boxWidgetClass,can->shell,arg,3);
541:
542: frame = XtCreateManagedWidget("form",formWidgetClass,box,NULL,0);
543:
544: XtSetArg(arg[0],XtNorientation,XtorientHorizontal);
545: XtSetArg(arg[1],XtNborderWidth,0);
546: commands = XtCreateManagedWidget("commands",boxWidgetClass,frame,arg,2);
547:
548: quit = XtCreateManagedWidget("quit",commandWidgetClass,commands,NULL,0);
549: XtAddCallback(quit,XtNcallback,destroy_canvas,can);
1.4 takayama 550: print = XtCreateManagedWidget("print",commandWidgetClass,commands,NULL,0);
551: XtAddCallback(print,XtNcallback,print_canvas,can);
1.1 noro 552: can->wideb = wide =
553: XtCreateManagedWidget("wide",toggleWidgetClass,commands,NULL,0);
554: XtAddCallback(wide,XtNcallback,wide_canvas,can);
555: can->preciseb = precise =
556: XtCreateManagedWidget("precise",toggleWidgetClass,commands,NULL,0);
557: XtAddCallback(precise,XtNcallback,precise_canvas,can);
558: formula =
559: XtCreateManagedWidget("formula",commandWidgetClass,commands,NULL,0);
560: XtAddCallback(formula,XtNcallback,show_formula,can);
561: can->noaxisb =
562: XtCreateManagedWidget("noaxis",toggleWidgetClass,commands,NULL,0);
563: XtAddCallback(can->noaxisb,XtNcallback,noaxis_canvas,can);
564:
565: XtSetArg(arg[0],XtNfromVert,commands);
566: XtSetArg(arg[1],XtNwidth,width);
567: XtSetArg(arg[2],XtNheight,height);
568: canvas = XtCreateManagedWidget("canvas",simpleWidgetClass,frame,arg,3);
569:
570: XtSetArg(arg[0],XtNfromVert,canvas);
571: XtSetArg(arg[1],XtNheight,5);
572: XtSetArg(arg[2],XtNwidth,width);
573: XtSetArg(arg[3],XtNorientation,XtorientHorizontal);
574: XtSetArg(arg[4],XtNsensitive,False);
575: can->xdone =
576: XtCreateManagedWidget("xdone",scrollbarWidgetClass,frame,arg,5);
577:
578: XtSetArg(arg[0],XtNfromHoriz,canvas);
579: XtSetArg(arg[1],XtNfromVert,commands);
580: XtSetArg(arg[2],XtNwidth,5);
581: XtSetArg(arg[3],XtNheight,height);
582: XtSetArg(arg[4],XtNorientation,XtorientVertical);
583: XtSetArg(arg[5],XtNsensitive,False);
584: can->ydone =
585: XtCreateManagedWidget("ydone",scrollbarWidgetClass,frame,arg,6);
586:
587: XtSetArg(arg[0],XtNfromVert,can->xdone);
588: XtSetArg(arg[1],XtNorientation,XtorientHorizontal);
589: XtSetArg(arg[2],XtNborderWidth,0);
590: coords = XtCreateManagedWidget("coords",boxWidgetClass,frame,arg,3);
591:
592: XtSetArg(arg[0],XtNwidth,LABELWIDTH);
593: can->xcoord = XtCreateManagedWidget("xcoord",labelWidgetClass,coords,arg,1);
594: XtSetArg(arg[0],XtNwidth,LABELWIDTH);
595: can->ycoord = XtCreateManagedWidget("ycoord",labelWidgetClass,coords,arg,1);
596:
597: XtAddEventHandler(canvas,ButtonPressMask,False,press,can);
598: XtAddEventHandler(canvas,ButtonReleaseMask,False,release,can);
599: XtAddEventHandler(canvas,Button1MotionMask,False,motion,can);
600: XtAddEventHandler(canvas,Button3MotionMask,False,motion,can);
601: XtAddEventHandler(canvas,StructureNotifyMask,False,structure,can);
602: XtAddEventHandler(canvas,ExposureMask,False,structure,can);
603:
604: if ( can->mode == MODE_CONPLOT ) {
605: Widget scale;
606:
607: XtSetArg(arg[0],XtNwidth,LABELWIDTH);
608: can->level = XtCreateManagedWidget("level",labelWidgetClass,
609: commands,arg,1);
610:
611: XtSetArg(arg[0],XtNsensitive,True);
612: XtSetValues(can->ydone,arg,1);
613: if ( depth >= 2 ) {
614: XtAddCallback(can->ydone,XtNjumpProc,jumpproc,can);
615: XtAddEventHandler(can->ydone,ButtonReleaseMask,False,lrelease,can);
616: } else {
617: XtAddCallback(can->ydone,XtNjumpProc,jumpproc_m,can);
618: XtAddEventHandler(can->ydone,ButtonReleaseMask,False,lrelease_m,can);
619: }
620: }
621: if ( can->mode != MODE_IFPLOT || !qpcheck((Obj)can->formula) )
622: XtSetSensitive(precise,False);
623: XtPopup(can->shell,XtGrabNone);
624:
625: window = can->window = XtWindow(canvas);
626: pix = can->pix = XCreatePixmap(display,window,width,height,depth);
627: XFillRectangle(display,pix,clearGC,0,0,width,height);
628: XDefineCursor(display,window,normalcur);
629: XFlush(display);
630: current_can = can;
631: }
632:
633: alloc_pixmap(can)
634: struct canvas *can;
635: {
636: can->pix = XCreatePixmap(display,can->window,
637: can->width,can->height,depth);
638: XFillRectangle(display,can->pix,clearGC,0,0,can->width,can->height);
639: }
640:
641: static XrmOptionDescRec options[] = {
642: {"-reverse","*reverse",XrmoptionNoArg,"on"},
643: {"-fg","*foreground",XrmoptionSepArg,NULL},
644: {"-bg","*background",XrmoptionSepArg,NULL},
645: };
646:
647: #define offset(name) XtOffset(struct PlotResources *,name)
648:
649: static XtResource resources[] = {
650: {"reverse","Reverse",XtRBoolean,sizeof(Boolean),
651: offset(Reverse),XtRBoolean,&reverse},
652: {"foreground","Foreground",XtRString,sizeof(char *),
653: offset(ForeName),XtRString,NULL},
654: {"foreground","Foreground",XtRPixel,sizeof(Pixel),
655: offset(ForePixel),XtRPixel,(XtPointer)&forePixel},
656: {"background","Background",XtRString,sizeof(char *),
657: offset(BackName),XtRString,NULL},
658: {"background","Background",XtRPixel,sizeof(Pixel),
659: offset(BackPixel),XtRPixel,(XtPointer)&backPixel},
660: {"dash","Dash",XtRString,sizeof(char *),
661: offset(DashName),XtRString,NULL},
662: {"dash","Dash",XtRPixel,sizeof(Pixel),
663: offset(DashPixel),XtRPixel,(XtPointer)&dashPixel},
664: };
665:
1.12 noro 666: int init_plot_display(argc,argv)
1.1 noro 667: int argc;
668: char **argv;
669: {
670: int ac;
671: char **av;
672: unsigned int tmp;
673:
674: for ( ac = argc, av = argv; ac; ac--, av++ )
1.12 noro 675: if ( !strcmp(*av,"nox") )
676: return 0;
677: else if ( index(*av,':') )
1.1 noro 678: dname = *av;
679: XtToolkitInitialize();
680: app_con = XtCreateApplicationContext();
681: display = XtOpenDisplay(app_con,dname,"plot","Plot",
682: options,XtNumber(options),&argc,argv);
683: if ( !display ) {
684: fprintf(stderr,"Can't open display\n");
1.12 noro 685: return 0;
1.1 noro 686: }
687: toplevel = XtAppCreateShell(0,"Plot",applicationShellWidgetClass,
688: display,0,0);
689:
690: forePixel = blackPixel; backPixel = whitePixel;
691: dashPixel = blackPixel;
692: XtGetApplicationResources(toplevel,&PlotResources,
693: resources,XtNumber(resources),NULL,0);
694: display = XtDisplay(toplevel);
695: scrn = DefaultScreen(display);
696: depth = DefaultDepth(display,scrn);
697: rootwin = RootWindow(display,scrn);
698:
699: if ( reverse ) {
700: tmp = forePixel; forePixel = backPixel; backPixel = tmp;
701: }
702:
703: create_gc();
704: create_font();
705: create_cursors();
1.12 noro 706: return 1;
1.1 noro 707: }
708:
709: static char *scalefont = "*-8-80-*";
710:
711: create_font() {
712: Font sfid;
713:
714: sfid = XLoadFont(display,scalefont);
715: sffs = XQueryFont(display,sfid);
716: XSetFont(display,scaleGC,sfid);
717: }
718:
719: create_gc() {
720: static XColor color = {0,0x0,0x0,0x0,DoRed|DoGreen|DoBlue,0};
721: int i,b,step;
722:
723: drawGC = XCreateGC(display,rootwin,0,NULL);
724: dashGC = XCreateGC(display,rootwin,0,NULL);
725: hlGC = XCreateGC(display,rootwin,0,NULL);
726: clearGC = XCreateGC(display,rootwin,0,NULL);
727: scaleGC = XCreateGC(display,rootwin,0,NULL);
728: xorGC = XCreateGC(display,rootwin,0,NULL);
729: colorGC = XCreateGC(display,rootwin,0,NULL);
1.11 noro 730: cdrawGC = XCreateGC(display,rootwin,0,NULL);
1.1 noro 731: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,drawGC);
732: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,dashGC);
733: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,clearGC);
734: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,scaleGC);
735: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,xorGC);
736: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,colorGC);
1.11 noro 737: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,cdrawGC);
1.1 noro 738: XSetForeground(display,drawGC,forePixel);
739: XSetForeground(display,scaleGC,forePixel);
740: XSetForeground(display,clearGC,backPixel);
741: XSetForeground(display,xorGC,forePixel^backPixel);
742: XSetFunction(display,xorGC,GXxor);
743: XSetForeground(display,dashGC,dashPixel);
744: XSetLineAttributes(display,dashGC,1,LineOnOffDash,CapButt,JoinRound);
745:
746: color.red = color.green = color.blue = 0xffff/2;
747: XAllocColor(display,DefaultColormap(display,scrn),&color);
748: XSetForeground(display,hlGC,color.pixel);
749: color.red = 0xffff; color.green = color.blue = 0;
750: XAllocColor(display,DefaultColormap(display,scrn),&color);
751: XSetForeground(display,colorGC,color.pixel);
1.11 noro 752: }
753:
754: set_drawcolor(c)
755: unsigned int c;
756: {
757: XColor color = {0,0x0,0x0,0x0,DoRed|DoGreen|DoBlue,0};
758:
759: color.red = (c&0xff0000)>>8;
760: color.green = (c&0xff00);
761: color.blue = (c&0xff)<<8;
762: XAllocColor(display,DefaultColormap(display,scrn),&color);
763: XSetForeground(display,cdrawGC,color.pixel);
1.1 noro 764: }
765:
766: create_cursors() {
767: static XColor fg = {0, 0x0, 0x0, 0x0,DoRed|DoGreen|DoBlue,0};
768: static XColor bg = {0, 0xffff, 0xffff, 0xffff,DoRed|DoGreen|DoBlue,0};
769:
770: XAllocColor(display,DefaultColormap(display,scrn),&fg);
771: XAllocColor(display,DefaultColormap(display,scrn),&bg);
772: normalcur = create_cursor(h_bits,h_m_bits,h_width,h_height,
773: h_x_hot,h_y_hot,&fg,&bg);
774: runningcur = create_cursor(ht_bits,ht_m_bits,ht_width,ht_height,
775: ht_width/2,ht_height/2,&fg,&bg);
776: errorcur = create_cursor(m_bits,m_m_bits,m_width,m_height,
777: m_width/2,m_height/2,&fg,&bg);
778: }
779:
780: Cursor create_cursor(image,mask,width,height,xhot,yhot,fg,bg)
781: char *image,*mask;
782: int width,height,xhot,yhot;
783: XColor *fg,*bg;
784: {
785: Pixmap ipix,mpix;
786:
787: ipix = XCreateBitmapFromData(display,rootwin,image,width,height);
788: mpix = XCreateBitmapFromData(display,rootwin,mask,width,height);
789: return XCreatePixmapCursor(display,ipix,mpix,fg,bg,xhot,yhot);
790: }
791:
792: copy_to_canvas(can)
793: struct canvas *can;
794: {
795: if ( display ) {
796: XCopyArea(display,can->pix,can->window,
797: drawGC,0,0,can->width,can->height,0,0);
798: pline(display,can,can->window);
799: XFlush(display);
800: }
801: }
802:
803: copy_subimage(subcan,can,pos)
804: struct canvas *subcan,*can;
805: XPoint pos;
806: {
807: if ( display ) {
808: XCopyArea(display,subcan->pix,can->pix,
809: drawGC,0,0,subcan->width,subcan->height,pos.x,pos.y);
810: XFlush(display);
811: }
812: }
813:
814: #include <signal.h>
815: #include <fcntl.h>
816:
817: set_selection() {
818: if ( current_can ) {
819: XSelectInput(display,current_can->window,0);
820: XFlush(display);
821: }
822: }
823:
824: reset_selection() {
825: if ( current_can ) {
826: XSelectInput(display,current_can->window,NormalSelection);
827: XFlush(display);
828: }
829: }
830:
831: set_busy(can)
832: struct canvas *can;
833: {
834: busy = 1;
835: XtSetSensitive(can->wideb,False);
836: XtSetSensitive(can->preciseb,False);
837: XtSetSensitive(can->noaxisb,False);
838: XFlush(display);
839: }
840:
841: reset_busy(can)
842: struct canvas *can;
843: {
844: busy = 0;
845: if ( can->window ) {
846: XtSetSensitive(can->wideb,True);
847: XtSetSensitive(can->noaxisb,True);
848: if ( can->mode == MODE_IFPLOT && qpcheck((Obj)can->formula) )
849: XtSetSensitive(can->preciseb,True);
850: XFlush(display);
851: }
852: }
853:
854: reset_current_computation()
855: {
856: if ( current_can ) {
857: reset_selection(); reset_busy(current_can);
858: define_cursor(current_can->window,normalcur);
859: }
1.8 takayama 860: }
861:
862: static struct canvas *Can;
863: /* void print_canvas(Widget w,struct canvas *can, XtPointer calldata); */
864: static void output_to_file(Widget , XtPointer, XtPointer );
865: static void output_to_ps_printer(Widget , XtPointer, XtPointer );
866: static void cancel_output_to_file(Widget , XtPointer,XtPointer);
867: static void generate_psfile(struct canvas *can, FILE *fp);
868: static void set_printing_method(Widget,XtPointer,XtPointer);
869: static void method_is_not_available();
870: static Widget PrintDialog;
871: static Widget PrintDialog_lp;
872: static Widget W;
873: static char *Fname = NULL;
874: static char *PrinterName = NULL;
875: #define PRINTING_METHOD_BITMAP 0
876: #define PRINTING_METHOD_VECTOR 1
877: static int PrintingMethod = PRINTING_METHOD_BITMAP;
878: static String Printing_methods[]={
879: "bitMap","vector",
880: };
881: static int N_printing_methods = 2;
882:
883: /*
884: static Widget create_printing_method_bar(Widget parent) {
885: Widget panel, button;
886: int i,n;
887: Arg wargs[1];
888: panel = XtCreateManagedWidget("printing methods",panedWidgetClass,
889: parent,NULL,0);
890: for (i=0; i<N_printing_methods; i++) {
891: button = XtCreateManagedWidget(Printing_methods[i],menuButtonWidgetClass,
892: panel,NULL,0);
893: fprintf(stderr,"button=%x\n",(int) button);
894: XtAddCallback(button,XtNcallback,set_printing_method,(XtPointer) i);
895: }
896: return(panel);
897: }
898: */
899:
900:
901: static void print_canvas(w,can,calldata)
902: Widget w;
903: struct canvas *can;
904: XtPointer calldata;
905: {
906: Widget fshell,fdialog;
907: extern struct canvas *Can;
908: extern Widget W;
909: Widget entry;
910: int i;
911: Arg arg[1];
912: static void output_to_printer();
913: static void print_canvas_to_file();
914: static void printing_method();
915:
916: W = w;
917: Can = can;
918: create_popup(can->shell,"Print/Output PS file","",&fshell,&fdialog);
919: XawDialogAddButton(fdialog,"print",output_to_printer,w);
920: XawDialogAddButton(fdialog,"output PS file",print_canvas_to_file,w);
921: XawDialogAddButton(fdialog,"method",printing_method,w);
922: XawDialogAddButton(fdialog,"dismiss",cancel_output_to_file,w);
923: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
924: }
925:
926: static void set_printing_method(Widget w,XtPointer number,XtPointer call_data) {
927: Widget shell;
928: extern int PrintingMethod;
929: PrintingMethod = (int) number;
930: fprintf(stderr,"PrintingMethod=%d\n",number);
931: shell = XtParent(XtParent(w));
932: XtPopdown(shell); XtDestroyWidget(shell);
933: }
934:
935: static void printing_method(w,can,calldata)
936: Widget w;
937: struct canvas *can;
938: XtPointer calldata;
939: {
940: Arg arg[10];
941: int i,n;
942: Widget fshell,fdialog;
943: extern struct canvas *Can;
944: extern int PrintingMethod;
945:
946: w = W;
947: can = Can;
948: create_popup(can->shell,"Printing method",Printing_methods[PrintingMethod],
949: &fshell,&fdialog);
950: n = 0;
951: XtSetArg(arg[n], XtNlabel, "Method: "); n++;
952: XtSetArg(arg[n], XtNvalue, Printing_methods[PrintingMethod]); n++;
953: XtSetValues(fdialog,arg,n);
954: for (i=0; i<N_printing_methods; i++) {
955: XawDialogAddButton(fdialog,Printing_methods[i],set_printing_method,(XtPointer) i);
956: }
957: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
958: }
959: static void print_canvas_to_file(w,can,calldata)
960: Widget w;
961: struct canvas *can;
962: XtPointer calldata;
963: {
964: FILE *fp;
965: Arg arg[10];
966: int n;
967: static char *psfile = NULL;
968: Widget fshell,fdialog;
969: extern struct canvas *Can;
970: extern Widget PrintDialog;
971: extern char *Fname;
972:
973: w = W;
974: can = Can;
975: if (psfile == NULL || Fname == NULL) psfile = "ox_plot.eps";
976: else psfile = Fname;
977: create_popup(can->shell,"Output as PS file",psfile,&fshell,&fdialog);
978: n = 0;
979: XtSetArg(arg[n], XtNlabel, "File : "); n++;
980: XtSetArg(arg[n], XtNvalue, psfile); n++;
981: XtSetValues(fdialog,arg,n);
982: XawDialogAddButton(fdialog,"output to file",output_to_file,w);
983: XawDialogAddButton(fdialog,"cancel",cancel_output_to_file,w);
984: PrintDialog = fdialog;
985: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
986: }
987: static void output_to_printer(w,can,calldata)
988: Widget w;
989: struct canvas *can;
990: XtPointer calldata;
991: {
992: FILE *fp;
993: Arg arg[10];
994: int n;
995: static char *psfile = NULL;
996: Widget fshell,fdialog;
997: extern struct canvas *Can;
998: extern Widget PrintDialog_lp;
999: extern char *PrinterName;
1000:
1001: w = W;
1002: can = Can;
1003: if (psfile == NULL || PrinterName == NULL) psfile = "lp";
1004: else psfile = PrinterName;
1005: create_popup(can->shell,"Output PS file to printer",psfile,&fshell,&fdialog);
1006: n = 0;
1007: XtSetArg(arg[n], XtNlabel, "PS Printer Name : "); n++;
1008: XtSetArg(arg[n], XtNvalue, psfile); n++;
1009: XtSetValues(fdialog,arg,n);
1010: XawDialogAddButton(fdialog,"output to PS printer",output_to_ps_printer,w);
1011: XawDialogAddButton(fdialog,"cancel",cancel_output_to_file,w);
1012: PrintDialog_lp = fdialog;
1013: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
1014: }
1015:
1016: static void cancel_output_to_file(w,fbutton,call)
1017: Widget w;
1018: XtPointer fbutton, call;
1019: {
1020: Widget shell = XtParent(XtParent(w));
1021: XtPopdown(shell); XtDestroyWidget(shell);
1022: XtSetSensitive(fbutton,True);
1023: }
1024:
1025: static void output_to_file(w,fbutton,call)
1026: Widget w;
1027: XtPointer fbutton, call;
1028: {
1029: char *fname;
1030: FILE *fp;
1031: int i;
1032: char *m;
1033: extern struct canvas *Can;
1034: extern Widget PrintDialog;
1035: extern int PrintingMethod;
1036: Widget shell = XtParent(XtParent(w));
1037:
1038: if (PrintingMethod == PRINTING_METHOD_BITMAP) {
1039: }else{
1040: method_is_not_available();
1041: XtPopdown(shell); XtDestroyWidget(shell);
1042: XtSetSensitive(fbutton,True);
1043: return;
1044: }
1045:
1046: fname = XawDialogGetValueString(PrintDialog);
1047: Fname = (char *)malloc(sizeof(char)*strlen(fname)+1);
1048: strcpy(Fname,fname);
1049: for (i=0; i<strlen(Fname); i++) {
1050: if (Fname[i] == 0xd || Fname[i] == 0xa) {
1051: Fname[i] = 0; break;
1052: }
1053: }
1054: fprintf(stderr,"fname=%s\n",Fname); fflush(NULL);
1055: fp = fopen(Fname,"w");
1056: if (fp == NULL) {
1057: warning(Can,"Could not open the output file.");
1058: }else{
1059: generate_psfile(Can,fp);
1060: fclose(fp);
1061: }
1062:
1063: XtPopdown(shell); XtDestroyWidget(shell);
1064: XtSetSensitive(fbutton,True);
1065: }
1066:
1067: static void output_to_ps_printer(w,fbutton,call)
1068: Widget w;
1069: XtPointer fbutton, call;
1070: {
1071: char *printerName;
1072: FILE *fp;
1073: extern struct canvas *Can;
1074: extern Widget PrintDialog_lp;
1075: char fname[256];
1076: char cmd[512];
1077: static int id = 0;
1078: int i;
1079: Widget shell = XtParent(XtParent(w));
1080:
1081: if (PrintingMethod == PRINTING_METHOD_BITMAP) {
1082: }else{
1083: method_is_not_available();
1084: XtPopdown(shell); XtDestroyWidget(shell);
1085: XtSetSensitive(fbutton,True);
1086: return;
1087: }
1088:
1089: sprintf(fname,"/tmp/ox_plot_%d.eps",(int) getpid(),id++);
1090:
1091: printerName = XawDialogGetValueString(PrintDialog_lp);
1092: PrinterName = (char *)malloc(sizeof(char)*strlen(printerName)+1);
1093: strcpy(PrinterName,printerName);
1094: for (i=0; i<strlen(PrinterName); i++) {
1095: if (PrinterName[i] == 0xd || PrinterName[i] == 0xa) {
1096: PrinterName[i] = 0; break;
1097: }
1098: }
1099: fprintf(stderr,"printerName=%s\n",PrinterName); fflush(NULL);
1100: fp = fopen(fname,"w");
1101: if (fp == NULL) {
1102: warning(Can,"Could not open the output file.");
1103: }else{
1104: generate_psfile(Can,fp);
1105: fclose(fp);
1106: }
1107:
1108: sprintf(cmd,"lpr -P%s %s",PrinterName,fname);
1109: if (system(cmd)) {
1110: warning(Can,"Unknown printer?");
1111: }
1112: sprintf(cmd,"rm -f %s",fname);
1113: system(cmd);
1114: XtPopdown(shell); XtDestroyWidget(shell);
1115: XtSetSensitive(fbutton,True);
1116: }
1117:
1118:
1119: /* test sequence
1120: ox_launch(0,"ox_plot");
1121: ifplot(x^2-y^3);
1122: drawcircle(0,0,100,0,0);
1123: */
1.15 takayama 1124: static int getColorSizeOfImageForPS(int xsize,int ysize,XImage *image,
1125: struct xcolorForPS **tableOfxcolorForPS);
1126:
1.8 takayama 1127: static void generate_psfile(can,fp)
1128: struct canvas *can;
1129: FILE *fp;
1130: {
1131: int x,y;
1132: XImage *image;
1133: int color[1];
1134: int colorSize = 1;
1135: char *m;
1.15 takayama 1136: struct xcolorForPS *tableOfxcolorForPS;
1.8 takayama 1137: extern int PrintingMethod;
1138: fprintf(stderr,"generate_psfile\n");
1139: if (PrintingMethod == PRINTING_METHOD_BITMAP) {
1140: if ( display ) {
1141: fprintf(stderr,"generate_psfile: output to a file.\n");
1142: image = XGetImage(display,can->pix,
1143: 0,0,can->width,can->height,-1,ZPixmap);
1.15 takayama 1144: colorSize =
1145: getColorSizeOfImageForPS(can->width,can->height,image,&tableOfxcolorForPS);
1146: color[0] = 0; /* black line */
1147: generatePS_from_image(fp,image,can->width,can->height,color,colorSize,can,tableOfxcolorForPS);
1.8 takayama 1148: }else{
1149: fprintf(stderr,"Cannot print on this system\n");
1150: }
1151: }else{
1152: method_is_not_available();
1153: }
1154: fflush(NULL);
1155: }
1156:
1157: static void method_is_not_available() {
1158: char *m;
1159: #define MSG1 "Printing method \""
1160: #define MSG2 "\" is not available for this picture."
1161: m = (char *)malloc(strlen(MSG1)+strlen(MSG2)+strlen(Printing_methods[PrintingMethod])+1);
1162: strcpy(m,MSG1);
1163: strcat(m,Printing_methods[PrintingMethod]);
1164: strcat(m,MSG2);
1165: warning(Can,m);
1.9 noro 1166: }
1167:
1168: clear_pixmap(can)
1169: struct canvas *can;
1170: {
1171: XFillRectangle(display,can->pix,clearGC,0,0,can->width,can->height);
1172: XFlush(display);
1.1 noro 1173: }
1.15 takayama 1174:
1175: /*
1176: The following functions are used to generate color postscript file.
1177: */
1178: /* In order to count colorSize, binary tree (sm_btree) is used. */
1179: static struct sm_btree *sm_newNode(unsigned long v);
1180: static int sm_insert(struct sm_btree *node,unsigned long v);
1181: static int sm_count(struct sm_btree *rootp);
1.17 ! takayama 1182:
1.15 takayama 1183: struct sm_btree {
1184: unsigned long p;
1185: struct sm_btree * left;
1186: struct sm_btree * right;
1187: };
1188: static struct sm_btree *sm_newNode(unsigned long v) {
1189: struct sm_btree * n;
1190: n = (struct sm_btree *)MALLOC(sizeof(struct sm_btree));
1191: if (n == NULL) { fprintf(stderr,"No more memory.\n"); exit(10); }
1192: n->p = v;
1193: n->left = NULL;
1194: n->right = NULL;
1195: return n;
1196: }
1197: static int sm_insert(struct sm_btree *node,unsigned long v)
1198: {
1199: if (node->p == v) return;
1200: if (node->p > v) {
1201: if (node->left == NULL) {
1202: node->left = sm_newNode(v);
1203: return;
1204: }
1205: sm_insert(node->left,v);
1206: }
1207: if (node->p < v) {
1208: if (node->right == NULL) {
1209: node->right = sm_newNode(v);
1210: return;
1211: }
1212: sm_insert(node->right,v);
1213: }
1214: }
1215: static int sm_count(struct sm_btree *rootp)
1216: {
1217: if (rootp == NULL) return 0;
1218: return (1+sm_count(rootp->left)+sm_count(rootp->right));
1219: }
1220:
1.16 takayama 1221: static int setTableOfxcolorForPS(struct sm_btree *rootp,
1222: struct xcolorForPS *table,int k,int size)
1223: {
1224: int m;
1225: m = k;
1226: if (rootp == NULL) return;
1227: if (k >= size) {
1228: warning(Can,"internal error of setTableOfxcolorForPS");
1229: }
1230: if (rootp->left != NULL) {
1231: m = setTableOfxcolorForPS(rootp->left,table,k,size);
1232: }
1233:
1234: (table[m]).pixel = rootp->p;
1235: m++;
1236: if (rootp->right != NULL) {
1237: m = setTableOfxcolorForPS(rootp->right,table,m,size);
1238: }
1239: return m;
1240: }
1241:
1242:
1.15 takayama 1243: static int getColorSizeOfImageForPS(int xsize,int ysize,XImage *image,
1244: struct xcolorForPS **tableOfxcolorForPS)
1245: {
1246: int x,y;
1247: int size;
1248: struct sm_btree root;
1249: struct xcolorForPS *table;
1.16 takayama 1250: XStandardColormap scm;
1251: Colormap cm;
1252: XColor color;
1253: XColor white;
1254: int screen,i;
1255:
1.15 takayama 1256: root.p = 0;
1257: root.left = NULL; root.right=NULL;
1258: /* get color size */
1259: for (x=0; x<xsize; x++) {
1260: for (y=0; y<ysize; y++) {
1261: sm_insert(&root,XGetPixel(image,x,y));
1262: }
1263: }
1264: size=sm_count(&root);
1265:
1266: table = (struct xcolorForPS *)MALLOC((size+1)*sizeof(struct xcolorForPS));
1267: if (table == NULL) {
1268: fprintf(stderr,"No more memory in getColorSizeOfImageForPS.\n");
1269: return 0;
1270: }
1271: /* Set rgb values standing for the pixel values.
1272: */
1.16 takayama 1273: if (setTableOfxcolorForPS(&root,table,0,size) != size) {
1274: warning(Can,"internal error.");
1275: return ;
1276: }
1277:
1278: screen = DefaultScreen(display);
1279: cm = DefaultColormap(display,screen);
1280: /* BUG: it does not work.
1281: if (!XGetStandardColormap(display,RootWindow(display,DefaultScreen(display)),&scm,XA_RGB_DEFAULT_MAP)) {
1282: warning(Can,"failed to open the X Standard Colormap.");
1283: scm.red_max = 0xffff;
1284: scm.green_max = 0xffff;
1285: scm.blue_max = 0xffff;
1286: }
1287: */
1288: /* Set by hand. */
1289: scm.red_max = 0xffff;
1290: scm.green_max = 0xffff;
1291: scm.blue_max = 0xffff;
1292: XParseColor(display,cm,"White",&white);
1293: for (i=0; i<size; i++) {
1294: color.pixel=(table[i]).pixel;
1295: /*
1296: {
1297: char s[254];
1298: sprintf(s,"%ld",color.pixel);
1299: warning(Can,s);
1300: }
1301: */
1302: XQueryColor(display,cm,&color);
1303: (table[i]).r = ((double) color.red)/((double) scm.red_max);
1304: (table[i]).g = ((double) color.green)/((double) scm.green_max);
1305: (table[i]).b = ((double) color.blue)/((double) scm.blue_max);
1306: if ((table[i]).r > 1.0) (table[i]).r = 1.0;
1307: if ((table[i]).g > 1.0) (table[i]).g = 1.0;
1308: if ((table[i]).b > 1.0) (table[i]).b = 1.0;
1309: if (color.red == white.red && color.green == white.green
1310: && color.blue == white.blue) {
1311: (table[i]).print = 0;
1312: }else{
1313: (table[i]).print = 1;
1314: }
1315: }
1.15 takayama 1316:
1317: *tableOfxcolorForPS = table;
1318: return size;
1319: }
1320:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>