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