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