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