00001
00002
00003
00004
00005
00006
00007
00008
00009 #if defined sgi && ! defined __STDC__
00010 #define __STDC__
00011 #endif
00012
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include <math.h>
00016 #include <sys/time.h>
00017
00018 #include <X11/Xlib.h>
00019 #include <X11/Xatom.h>
00020 #include <X11/Xutil.h>
00021 #include <X11/cursorfont.h>
00022 #include <X11/Intrinsic.h>
00023 #include <X11/StringDefs.h>
00024 #include <X11/Shell.h>
00025
00026 #ifndef _MSC_VER
00027 #include "machine.h"
00028 #include "version.h"
00029 #include "math_graphics.h"
00030 #endif
00031
00032 #include "sci_mem_alloc.h"
00033 #include "math.h"
00034 #include "periX11.h"
00035 #include "color.h"
00036 #include "bcg.h"
00037 #include "Events.h"
00038 #include "clipping.h"
00039 #include "WindowList.h"
00040 #include "sciprint.h"
00041 #include "GetProperty.h"
00042 #include "SetProperty.h"
00043
00044 #include "prompt.h"
00045
00046 #ifdef WITH_TK
00047 #include <tcl.h>
00048 #include <tk.h>
00049
00050 extern Tcl_Interp *TCLinterp;
00051 extern Tk_Window TKmainWindow;
00052 #endif
00053
00054 double t=0.;
00055 extern void AddMenu __PARAMS((integer *win_num, char *button_name, char **entries, integer *ne, integer *typ, char *fname, integer *ierr));
00056 extern int XRotDrawString(Display *dpy, XFontStruct *font, float angle, Drawable drawable, GC gc_, int x, int y, char *str);
00058 extern void ChangeBandF __PARAMS((int win_num,Pixel fg, Pixel bg));
00059
00060 void CreatePopupWindow __PARAMS((integer WinNum,Widget top,struct BCG *, Pixel *fg,Pixel *bg));
00061 extern void GViewportResize __PARAMS((struct BCG *ScilabXgc, int *width,int *height));
00062
00064 extern integer C2F(ismenu) __PARAMS((void));
00065 extern int C2F(getmen) __PARAMS((char *btn_cmd,integer *lb,integer *entry));
00066 extern integer C2F(sxevents)();
00067 extern void DisplayInit __PARAMS((char *string,Display **dpy,Widget *toplevel));
00068 extern void MenuFixCurrentWin __PARAMS(( int ivalue));
00069
00070 extern void GPopupResize __PARAMS((struct BCG *ScilabXgc,int *,int *));
00071 extern int IswmDeleteWindow __PARAMS((XEvent *));
00072 extern int IsCloseSGWindow __PARAMS((XEvent *));
00073 extern void SciViewportMove __PARAMS((struct BCG *,int,int));
00074 extern void SciViewportGet __PARAMS((struct BCG *,int *,int*));
00075 extern void SciViewportClipGetSize __PARAMS((struct BCG *,int *,int*));
00076 #ifdef WITH_TK
00077 extern void flushTKEvents(void);
00078 #endif
00079 extern void refreshMenus( struct BCG * ScilabGC ) ;
00080
00081
00082 #define MESSAGE4 "Can't allocate point vector"
00083 #define MESSAGE5 "Can't re-allocate point vector"
00084 #define Char2Int(x) ( x & 0x000000ff )
00085
00086 void C2F(DispStringAngle)(integer *x0, integer *yy0, char *string, double *angle);
00087 void C2F(MissileGCGetorSet)(char *str, integer flag, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dv1);
00088 void C2F(WriteGeneric1X11)(void);
00089 void C2F(xgetmarkX11)(void);
00090 void C2F(xsetmarkX11)(void);
00091 void C2F(xgetfontX11)(void);
00092 void C2F(xsetfontX11)(void);
00093 void C2F(setdashstyleX11)(void);
00094 void C2F(Write2VectX11)(void);
00095 void C2F(WriteGenericX11)(char *string, integer nobj, integer sizeobj, integer *vx, integer *vy, integer sizev, integer flag, integer *fvect);
00096 void C2F(InitScilabGCX11)(integer *v1, integer *v2, integer *v3, integer *v4);
00097 void C2F(setforegroundX11)(integer *num, integer *v2, integer *v3, integer *v4);
00098 void C2F(ScilabGCGetorSetX11)(char *str, integer flag, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dx1);
00099 void C2F(setbackgroundX11)(integer *num, integer *v2, integer *v3, integer *v4);
00100 void C2F(set_cX11)(integer i);
00101 void C2F(idfromnameX11) (char *name1, integer *num);
00102 void C2F(getdashX11)(integer *verbose, integer *value, integer *narg, double *dummy);
00103
00104 BOOL IsTKGraphicalMode(void);
00105 int XgcAllocColors(struct BCG *xgc, int m);
00106 void XgcFreeColors(struct BCG *xgc);
00107 int WithBackingStore(void);
00108 void sci_pixmap_resize(struct BCG *Xgc,int x,int y);
00109 void Setpopupname(char *string);
00110 int get_xclick_client_message_flag (void);
00111 void xset_alufunction(char *string);
00112 void C2F(CreatePatterns)(Pixel whitepixel, Pixel blackpixel);
00113 Pixel RGB2pixO(unsigned int r, unsigned int g, unsigned int b, long unsigned int r_mask, long unsigned int g_mask, long unsigned int b_mask);
00114 Pixel RGB2pix(unsigned int r, unsigned int g, unsigned int b, long unsigned int r_mask, long unsigned int g_mask, long unsigned int b_mask);
00115 void set_default_colormap(void);
00116 int IsPrivateCmap(void);
00117 void set_cmap(Window w);
00118 Pixmap get_pixmap(int i);
00119 void C2F(DispStringAngleold)(integer *x0, integer *yy0, char *string, double *angle);
00120 int GetEventWindow(XEvent* event);
00121 void SendScilab(Window local, integer winnum);
00122 Window Window_With_Name(Window top, char *name, int j, char *ResList0, char *ResList1, char *ResList2);
00123 int fontidscale(int fontsize);
00124 int CheckScilabXgc(void);
00125
00126
00127 BOOL IsTKGraphicalMode(void){
00128 return FALSE;
00129 }
00130
00133 static GC gc;
00134 static Cursor arrowcursor,normalcursor,crosscursor;
00135 static Window root=(Window) NULL;
00136 static Display *dpy = (Display *) NULL;
00137 static Pixel DefaultBackground, DefaultForeground;
00138 static double *vdouble = 0;
00139 static int depth;
00140 static unsigned long maxcol;
00141 Visual *visual;
00142 static int wpixel, bpixel;
00143
00144
00145
00146 unsigned short default_colors[] = {
00147 0, 0, 0,
00148 0, 0, 255,
00149 0, 255, 0,
00150 0, 255, 255,
00151 255, 0, 0,
00152 255, 0, 255,
00153 255, 255, 0,
00154 255, 255, 255,
00155 0, 0, 144,
00156 0, 0, 176,
00157 0, 0, 208,
00158 135, 206, 255,
00159 0, 144, 0,
00160 0, 176, 0,
00161 0, 208, 0,
00162 0, 144, 144,
00163 0, 176, 176,
00164 0, 208, 208,
00165 144, 0, 0,
00166 176, 0, 0,
00167 208, 0, 0,
00168 144, 0, 144,
00169 176, 0, 176,
00170 208, 0, 208,
00171 128, 48, 0,
00172 160, 64, 0,
00173 192, 96, 0,
00174 255, 128, 128,
00175 255, 160, 160,
00176 255, 192, 192,
00177 255, 224, 224,
00178 255, 215, 0
00179 };
00180
00181
00182 struct BCG *ScilabXgc = (struct BCG *) 0;
00183
00186 Window Find_X_Scilab __PARAMS((void));
00187 Window Find_BG_Window __PARAMS((int i));
00188 Window Find_ScilabGraphic_Window __PARAMS((int i));
00189 Window GetWindowNumber __PARAMS((int));
00190 Window GetBGWindowNumber __PARAMS((int));
00191
00192
00193 static void ResetScilabXgc __PARAMS((void));
00194 static XPoint *get_xpoints __PARAMS((void));
00195 static int ReallocVector __PARAMS((int));
00196 static void DrawMark(integer *x, integer *y),LoadFonts(void), LoadSymbFonts(void) ;
00197 static void C2F(loadfamily_n)(char *name, integer *j);
00198 static void PixmapClear __PARAMS((struct BCG *Xgc,int x,int y,int w,int h));
00199 static void xset_colormap __PARAMS((integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *a));
00200 static void xset_dashstyle __PARAMS((integer *v1,integer *v2,integer *v3));
00201
00202
00203 typedef void (xset_f) __PARAMS((integer * v1,integer * v2,integer * v3,integer * v4));
00204 static xset_f xset_windowpos,xset_windowdim,xset_popupdim,xset_viewport,xset_curwin,xset_clip;
00205 static xset_f xset_absourel,xset_alufunction1,xset_thickness,xset_pattern,xset_dash;
00206 static xset_f xset_pixmapOn,xset_wresize,xset_background,xset_foreground,xset_hidden3d;
00207 static xset_f xset_unclip,xset_font,xset_usecolor,xset_mark,xset_pixmapclear,xset_show,xset_dash_or_color;
00208 static xset_f xset_scilabxgc ;
00209 static void xset_scilabFigure(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure);
00210 static void xset_alufunction2(struct BCG *Xgc,integer *num, integer *v2, integer *v3, integer *v4);
00211
00212
00213 typedef void (xget_f) __PARAMS((integer *verbose, integer *x,integer *narg, double *dummy));
00214 static xget_f xget_windowpos,xget_windowdim,xget_popupdim,xget_viewport,xget_curwin ,xget_clip;
00215 static xget_f xget_absourel,xget_alufunction,xget_thickness,xget_pattern,xget_last,xget_dash;
00216 static xget_f xget_usecolor,xget_pixmapOn,xget_wresize,xget_colormap,xget_background,xget_foreground,xget_hidden3d;
00217 static xget_f xget_font,xget_mark,xget_dash_or_color;
00218 static xget_f xget_scilabxgc,xget_scilabFigure ;
00219 static xget_f xget_colormap_size;
00220
00221
00222 #define FONTNUMBER 11
00223 #define FONTMAXSIZE 6
00224 #define SYMBOLNUMBER 10
00225
00226
00227
00228
00229
00230
00231 static XFontStruct *FontsList_[FONTNUMBER][FONTMAXSIZE];
00232
00233
00234
00235 int XgcAllocColors(struct BCG *xgc, int m)
00236 {
00237 int mm;
00238
00239 mm = m + 2;
00240 if (!(xgc->Red = (float *) MALLOC(mm*sizeof(float)))) {
00241 sciprint("XgcAllocColors: unable to alloc\n");
00242 return 0;
00243 }
00244 if (!(xgc->Green = (float *) MALLOC(mm*sizeof(float)))) {
00245 sciprint("XgcAllocColors: unable to alloc\n");
00246 FREE(xgc->Red);
00247 return 0;
00248 }
00249 if (!(xgc->Blue = (float *) MALLOC(mm*sizeof(float)))) {
00250 sciprint("XgcAllocColors: unable to alloc\n");
00251 FREE(xgc->Red);
00252 FREE(xgc->Green);
00253 return 0;
00254 }
00255 if (!(xgc->Colors = (Pixel *) MALLOC(mm*sizeof(Pixel)))) {
00256 sciprint("XgcAllocColors: unable to alloc\n");
00257 FREE(xgc->Red);
00258 FREE(xgc->Green);
00259 FREE(xgc->Blue);
00260 return 0;
00261 }
00262 return 1;
00263 }
00264
00265 void XgcFreeColors(struct BCG *xgc)
00266 {
00267 FREE(xgc->Red); xgc->Red = (float *) 0;
00268 FREE(xgc->Green);xgc->Green = (float *) 0;
00269 FREE(xgc->Blue); xgc->Blue = (float *) 0;
00270 FREE(xgc->Colors); xgc->Colors = (Pixel *) 0;
00271 }
00272
00275 static void xset_pixmapclear(integer *v1, integer *v2, integer *v3, integer *v4)
00276 {
00277 XWindowAttributes war;
00279 XSetClipMask(dpy,gc,None);
00280 XGetWindowAttributes(dpy,ScilabXgc->CWindow,&war);
00281 PixmapClear(ScilabXgc,0,0,war.width,war.height);
00283 if ( ScilabXgc->ClipRegionSet == 1)
00284 {
00285 XRectangle rects[1];
00286 rects[0].x = ScilabXgc->CurClipRegion[0];
00287 rects[0].y = ScilabXgc->CurClipRegion[1];
00288 rects[0].width = ScilabXgc->CurClipRegion[2];
00289 rects[0].height = ScilabXgc->CurClipRegion[3];
00290 XSetClipRectangles(dpy,gc,0,0,rects,1,Unsorted);
00291 }
00292 }
00293
00294 int WithBackingStore(void)
00295
00296 {
00297 return (ScilabXgc->Cdrawable != (Drawable) 0) ;
00298 }
00299
00300 static void xset_show(integer *v1, integer *v2, integer *v3, integer *v4)
00301 {
00302
00303
00304 if (ScilabXgc->Cdrawable != (Drawable) 0) {
00305 XSetWindowBackgroundPixmap(dpy, ScilabXgc->CWindow, (Pixmap) ScilabXgc->Cdrawable);
00306 XClearWindow(dpy,ScilabXgc->CWindow);
00307 }
00308 XFlush(dpy);
00309 }
00310
00311
00312
00313
00314
00315
00316
00317 void sci_pixmap_resize(struct BCG *Xgc,int x,int y)
00318 {
00319
00320 if (Xgc->Cdrawable != (Drawable) 0)
00321 XFreePixmap(dpy,(Pixmap)Xgc->Cdrawable);
00322 Xgc->Cdrawable = (Drawable) XCreatePixmap(dpy, root,Max(x,400),Max(y,300),depth);
00323
00324 if ( Xgc->Cdrawable == (Drawable) 0)
00325 sciprint("Not enough memory to allocate pixmap\r\n");
00326 else
00327 {
00328 PixmapClear(Xgc,0,0,x,y);
00329 XSetWindowBackgroundPixmap(dpy, Xgc->CWindow,(Pixmap) Xgc->Cdrawable);
00330 }
00331
00332 }
00333
00334 void CPixmapResize(int x, int y)
00335 {
00336 sci_pixmap_resize(ScilabXgc,x,y);
00337 }
00338
00339
00340
00341
00342
00343
00344
00345 static void PixmapClear(struct BCG *Xgc,int x, int y, int w, int h)
00346 {
00347
00348 int cur_alu = Xgc->CurDrawFunction;
00349 int clear = GXclear;
00350 xset_alufunction2(Xgc,&clear,PI0,PI0,PI0);
00351 if (Xgc->Cdrawable != (Drawable) 0) XFillRectangle(dpy, Xgc->Cdrawable, gc, x,y,w,h);
00352
00353 xset_alufunction2(Xgc,&cur_alu,PI0,PI0,PI0);
00354 }
00355
00356
00357
00358
00359
00360
00361 void CPixmapResize1(void)
00362 {
00363 XWindowAttributes war;
00364 if (ScilabXgc->Cdrawable != (Drawable) 0 )
00365 {
00366 XGetWindowAttributes(dpy,ScilabXgc->CWindow,&war);
00367 CPixmapResize(war.width,war.height);
00368 }
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 void C2F(xselgraphic)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00381 {
00383 integer ierr;
00384 if (ScilabXgc == (struct BCG *)0 || ScilabXgc->CBGWindow == (Window ) NULL)
00385 C2F(initgraphic)("",PI0,&ierr,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00386 XMapWindow(dpy,ScilabXgc->CBGWindow);
00387 XRaiseWindow(dpy,ScilabXgc->CBGWindow);
00388 XFlush(dpy);
00389 }
00390
00393 void C2F(xendgraphic)(void)
00394 {
00395 }
00396
00397 void C2F(xend)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00398 {
00400 }
00401
00404 void C2F(clearwindow)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00405 {
00406 if (ScilabXgc->Cdrawable != (Drawable) 0 )
00407 xset_pixmapclear(PI0,PI0,PI0,PI0);
00408 XClearWindow(dpy, ScilabXgc->CWindow);
00409 XFlush(dpy);
00410 }
00411
00412
00413
00414
00415
00416 void Setpopupname(char *string)
00417 {
00418 int iargs = 0;
00419 static Arg args[2] ;
00420 if (ScilabXgc->popup != (Widget)0 ){
00421 XtSetArg(args[iargs],XtNtitle,string);iargs++;
00422 XtSetArg(args[iargs],XtNiconName,string);iargs++;
00423 XtSetValues(ScilabXgc->popup,args,iargs);
00424 }
00425 }
00426
00427
00428
00429 void C2F(setpopupname)(char *x0, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4, integer lx0)
00430 {
00431 Setpopupname(x0);
00432 }
00433
00434 static int client_message=0;
00435 static void set_client_message_on(void) { client_message=1;};
00436 static void set_client_message_off(void) { client_message=0;};
00437 int get_xclick_client_message_flag (void) { return client_message;}
00438
00439 extern void set_wait_click(int val);
00440 extern void set_event_select(int val);
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 void SciClick(integer *ibutton, integer *x1, integer *yy1, integer *iflag, int getmouse, int getrelease, int dyn_men, char *str, integer *lstr)
00463 {
00464 integer buttons = 0;
00465 integer win,ok,choice,motion,release;
00466 Window SCWindow;
00467 struct timeval delay;
00468
00469 choice=(dyn_men>1);
00470
00471 if ( ScilabXgc == (struct BCG *) 0 || ScilabXgc->CWindow == (Window) 0)
00472 {
00473 *x1 = -1;
00474 *yy1 = -1;
00475 *ibutton = -100; return;
00476 }
00477 win = ScilabXgc->CurWindow;
00478 SCWindow = ScilabXgc->CWindow;
00479
00480 if ( *iflag ==0 ) ClearClickQueue(ScilabXgc->CurWindow);
00481 XDefineCursor(dpy, ScilabXgc->CWindow ,crosscursor);
00482
00483
00484 set_wait_click(1);
00485 set_event_select(1+2*getmouse+4*getrelease);
00486
00487 while (buttons == 0)
00488 {
00490 if (choice) win=-1;
00491 ok=0;
00492 if (CheckClickQueue(&win,x1,yy1,ibutton,&motion,&release) == 1) {
00493 if ((release&&getrelease) || (motion&&getmouse) || ((motion==0)&&(release==0))){
00494 *iflag=win;
00495 ok=1;
00496 break;
00497 }
00498 if (choice) win=-1;
00499 }
00500 if(ok) break;
00501
00502 C2F(sxevents)();
00503
00505 if ( ScilabXgc == (struct BCG *) 0 || ScilabXgc->CWindow != SCWindow)
00506 {
00507 *x1 = -1;
00508 *yy1 = -1;
00509 *ibutton = -100;
00510 set_event_select(1+4);
00511 set_wait_click(0);
00512 return;
00513 }
00515 if ( (dyn_men == 1||dyn_men==3) && C2F(ismenu)()==1 ) {
00516 int entry;
00517 C2F(getmen)(str,lstr,&entry);
00518 *ibutton = -2;
00519 *x1=0;
00520 *yy1=0;
00521 break;
00522 }
00523
00524
00525 delay.tv_sec = 0; delay.tv_usec = 10;
00526 select(0, 0, 0, 0, &delay);
00527 }
00528 set_event_select(1+4);
00529 set_wait_click(0);
00530 if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->CWindow != (Window) 0)
00531 XDefineCursor(dpy, ScilabXgc->CWindow ,arrowcursor);
00532 XSync (dpy, 0);
00533 }
00534
00535
00536
00537
00538
00539
00540
00541
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 void C2F(xclick_any)(char *str, integer *ibutton, integer *x1, integer *yy1, integer *iwin, integer *iflag, integer *istr, double *dv1, double *dv2, double *dv3, double *dv4)
00560 {
00561 Window CW;
00562 int buttons = 0;
00563 integer i,win,ok;
00564 integer wincount;
00565 integer lstr ;
00566 int motion,release;
00567 struct timeval delay;
00568
00569 wincount = getWinsMaxId()+1;
00570 if (wincount == 0)
00571 {
00572 *x1=0;
00573 *yy1=0;
00574 *iwin=0;
00575 *ibutton = -100;
00576 *istr = 0;
00577 return;
00578 }
00579 for (i=0; i < wincount ; i++ )
00580 {
00581 if (( CW=GetWindowNumber(i)) != (Window ) NULL)
00582 XDefineCursor(dpy, CW ,crosscursor);
00583 }
00585 if ( *iflag ==0 ) ClearClickQueue(-1);
00586
00587
00588 set_client_message_on();
00589 set_wait_click(1);
00590 set_event_select(1+4);
00591 while (buttons == 0) {
00593 win=-1;
00594 ok=0;
00595 while (CheckClickQueue(&win,x1,yy1,ibutton,&motion,&release) == 1) {
00596 if ((motion==0) && (release==0)) {
00597 *iwin = win ;
00598 ok=1;
00599 break;
00600 }
00601
00602 win=-1;
00603 }
00604 if(ok) {*istr = 0;break;};
00605
00606
00607 C2F(sxevents)();
00608
00610 if ( *istr==1 && C2F(ismenu)()==1 ) {
00611 int entry;
00612 C2F(getmen)(str,&lstr,&entry);
00613 *ibutton = -2;
00614 *istr=lstr;
00615 *x1=0;
00616 *yy1=0;
00617 *iwin=-1;
00618 break;
00619 }
00620
00621 delay.tv_sec = 0; delay.tv_usec = 10;
00622 select(0, 0, 0, 0, &delay);
00623 }
00624 set_wait_click(0);
00625 set_client_message_off();
00626
00628 wincount = getWinsMaxId()+1;
00629 for (i=0;i < wincount;i++) {
00630 CW=GetWindowNumber(i);
00631 if (CW!=(Window ) NULL)
00632 XDefineCursor(dpy, CW ,arrowcursor);
00633 }
00634 XSync (dpy, 0);
00635 }
00636
00637
00638 void C2F(xclick)(char *str, integer *ibutton, integer *x1, integer *yy1, integer *iflag, integer *istr, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00639 {
00640 integer lstr ;
00641 SciClick(ibutton,x1, yy1,iflag,0,0,*istr,str,&lstr);
00642 if ( *istr == 1)
00643 {
00644 if (*ibutton == -2)
00645 {
00646
00647 *istr = lstr;
00648 }
00649 else
00650 *istr = 0;
00651 }
00652 }
00653
00654 void C2F(xgetmouse)(char *str, integer *ibutton, integer *x1, integer *yy1, integer *iflag, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00655 {
00656 SciClick(ibutton,x1, yy1,iflag,v6[0],v6[1],(v7==NULL)?0:*v7,(char *) 0,(integer *)0);
00657 }
00658
00659
00660
00661
00662
00663
00664 void C2F(cleararea)(char *str, integer *x, integer *y, integer *w, integer *h, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00665 {
00666 if (ScilabXgc->Cdrawable != (Drawable) 0 )
00667 PixmapClear(ScilabXgc,*x,*y,*w,*h);
00668 if (ScilabXgc->CurPixmapStatus != 1)
00669 XClearArea(dpy,ScilabXgc->CWindow,(int)*x,(int) *y,(unsigned) *w,
00670 (unsigned) *h,False);
00671 XFlush(dpy);
00672 }
00673
00674
00675
00676
00677
00680 static void xget_windowpos(integer *verbose, integer *x, integer *narg, double *dummy)
00681 {
00682 int xx[2];
00683 XWindowAttributes war;
00684 Window CHR;
00685 *narg = 2;
00686 XGetWindowAttributes(dpy,ScilabXgc->CBGWindow,&war);
00687 XTranslateCoordinates(dpy,ScilabXgc->CBGWindow,root,war.x,war.y,&(xx[0]),&(xx[1]),&CHR);
00688 x[0]=xx[0];x[1]=xx[1];
00689 if (*verbose == 1)
00690 sciprint("\n ScilabXgc->CWindow position :%d,%d\r\n",xx[0],xx[1]);
00691 }
00692
00693
00696 static void xset_windowpos(integer *x, integer *y, integer *v3, integer *v4)
00697 {
00699 integer ierr;
00700 if (ScilabXgc == (struct BCG *)0 || ScilabXgc->CBGWindow == (Window) NULL)
00701 C2F(initgraphic)("",PI0,&ierr,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00702 XMoveWindow(dpy,ScilabXgc->CBGWindow,(int) *x,(int) *y);
00703 }
00704
00707 void C2F(getwindowdim) (integer *verbose, integer *x, integer *narg, double *dummy)
00708 {
00709 xget_windowdim(verbose, x, narg,dummy);
00710 }
00711
00714 static void xget_windowdim(integer *verbose, integer *x, integer *narg, double *dummy)
00715 {
00716 *narg = 2;
00717 x[0]= ScilabXgc->CWindowWidth;
00718 x[1]= ScilabXgc->CWindowHeight;
00719 if (*verbose == 1)
00720 sciprint("\n ScilabXgc->CWindow dim :%d,%d\r\n",(int) x[0],(int) x[1]);
00721 }
00722
00725 static void xset_windowdim(integer *x, integer *y, integer *v3, integer *v4)
00726 {
00727 XWindowAttributes war;
00728 if (ScilabXgc == (struct BCG *) NULL || ScilabXgc->CBGWindow == (Window) NULL) return ;
00729 GViewportResize(ScilabXgc,x,y) ;
00730
00731 XGetWindowAttributes(dpy,ScilabXgc->CWindow,&war);
00732 ScilabXgc->CWindowWidth = war.width;
00733 ScilabXgc->CWindowHeight = war.height;
00734 XFlush(dpy);
00735 }
00736
00739 static void xget_popupdim(integer *verbose, integer *x, integer *narg, double *dummy)
00740 {
00741 Dimension clwidth,clheight;
00742 static Arg args[2] ;
00743 int iargs = 0;
00744 XtSetArg (args[iargs], XtNwidth, &clwidth ); iargs++;
00745 XtSetArg (args[iargs], XtNheight, &clheight); iargs++;
00746 XtGetValues (ScilabXgc->popup, args, iargs);
00747 x[0]= clwidth;
00748 x[1]= clheight;
00749 *narg = 2;
00750 if (*verbose == 1)
00751 sciprint("\n ScilabXgc->CWindow dim :%d,%d\r\n",(int) x[0],(int) x[1]);
00752 }
00753
00757 static void xset_popupdim(integer *x, integer *y, integer *v3, integer *v4)
00758 {
00759 GPopupResize(ScilabXgc,x,y);
00760 }
00761
00764 static void xget_viewport(integer *verbose, integer *x, integer *narg, double *dummy)
00765 {
00766 *narg = 2;
00767 sciGetViewport( ScilabXgc->mafigure, &x[0], &x[1] ) ;
00768 }
00769
00772 static void xset_viewport(integer *x, integer *y, integer *v3, integer *v4)
00773 {
00774 sciSetViewport( ScilabXgc->mafigure, *x, *y ) ;
00775 }
00776
00777
00778
00779
00780
00781
00782
00783
00784 void SwitchWindow(integer *intnum)
00785 {
00787 struct BCG *SXgc;
00788 integer ierr;
00789 SXgc = getWindowXgcNumber(*intnum);
00790 if ( SXgc != (struct BCG *) 0 )
00791 {
00793 ScilabXgc = SXgc ;
00794 ResetScilabXgc ();
00795 get_window_scale(*intnum,NULL);
00796 }
00797 else
00798 {
00800 C2F(initgraphic)("",intnum,&ierr,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00801 }
00802 }
00803
00804
00805
00806
00807
00808
00809
00810 static void xset_curwin(integer *intnum, integer *v2, integer *v3, integer *v4)
00811 {
00812 XWindowAttributes war;
00813 struct BCG *bcgk;
00814 integer ierr;
00815 bcgk = ScilabXgc ;
00817 if (v2 != (integer *) 0) MenuFixCurrentWin(*intnum);
00818 if ( ScilabXgc == (struct BCG *) 0 )
00819 {
00821 C2F(initgraphic)("",intnum,&ierr,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00822 }
00823 else
00824 {
00825 if ( ScilabXgc->CurWindow != *intnum )
00826 {
00827 SwitchWindow(intnum);
00828 }
00829 }
00830 if ( ScilabXgc == (struct BCG *) 0 && bcgk != (struct BCG *) 0)
00831 {
00833 ScilabXgc = bcgk ;
00834 if (v2 != (integer *) 0) MenuFixCurrentWin(bcgk->CurWindow);
00835 }
00836 else
00837 {
00838
00839 XGetWindowAttributes(dpy,ScilabXgc->CWindow,&war);
00840 ScilabXgc->CWindowWidth = war.width;
00841 ScilabXgc->CWindowHeight = war.height;
00842 }
00843 }
00844
00845 static void xset_scilabFigure(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure)
00846 {
00847 ScilabXgc->mafigure=(sciPointObj *)figure;
00848 }
00849
00850 static void xget_scilabFigure(integer *verbose, integer *x,integer *narg, double *figure)
00851 {
00852 *narg=1;
00853 figure=(double *)ScilabXgc->mafigure;
00854 }
00855
00856 static void xset_scilabxgc(v1, v2, v3, v4)
00857 integer *v1;
00858 integer *v2;
00859 integer *v3;
00860 integer *v4;
00861
00862 {
00863
00864 }
00865 static void xget_scilabxgc(verbose, x,narg, dummy)
00866 integer *verbose;
00867 integer *x;
00868 integer *narg;
00869 double *dummy;
00870 {
00871 double **XGC;
00872
00873 XGC=(double **)dummy;
00874 *XGC= (double *)ScilabXgc;
00875
00876 }
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887 static void xget_curwin(integer *verbose, integer *intnum, integer *narg, double *dummy)
00888 {
00889 *narg =1 ;
00890 *intnum = (ScilabXgc != (struct BCG *) 0) ? ScilabXgc->CurWindow : 0;
00891 if (*verbose == 1)
00892 sciprint("\nCurrent Graphic Window :%d\r\n",(int) *intnum);
00893
00894 }
00895
00898 static void xset_clip(integer *x, integer *y, integer *w, integer *h)
00899 {
00900 integer verbose=0,wd[2],narg;
00901 XRectangle rects[1];
00902 ScilabXgc->ClipRegionSet = 1;
00903 xget_windowdim(&verbose,wd,&narg,vdouble);
00904 rects[0].x= *x;
00905 rects[0].y= *y;
00906 rects[0].width= *w;
00907 rects[0].height= *h;
00908 ScilabXgc->CurClipRegion[0]= rects[0].x;
00909 ScilabXgc->CurClipRegion[1]= rects[0].y;
00910 ScilabXgc->CurClipRegion[2]= rects[0].width;
00911 ScilabXgc->CurClipRegion[3]= rects[0].height;
00912 XSetClipRectangles(dpy,gc,0,0,rects,1,Unsorted);
00913 }
00914
00917 static void xset_unclip(integer *v1, integer *v2, integer *v3, integer *v4)
00918 {
00919 ScilabXgc->ClipRegionSet = 0;
00920 XSetClipMask(dpy,gc,None);
00921 }
00922
00925 static void xget_clip(integer *verbose, integer *x, integer *narg, double *dummy)
00926 {
00927 x[0] = ScilabXgc->ClipRegionSet;
00928 if ( x[0] == 1)
00929 {
00930 *narg = 5;
00931 x[1] =ScilabXgc->CurClipRegion[0];
00932 x[2] =ScilabXgc->CurClipRegion[1];
00933 x[3] =ScilabXgc->CurClipRegion[2];
00934 x[4] =ScilabXgc->CurClipRegion[3];
00935 }
00936 else *narg = 1;
00937 if (*verbose == 1)
00938 {
00939 if (ScilabXgc->ClipRegionSet == 1)
00940 sciprint("\nThere's a Clip Region :x:%d,y:%d,w:%d,h:%d\r\n",
00941 ScilabXgc->CurClipRegion[0],
00942 ScilabXgc->CurClipRegion[1],
00943 ScilabXgc->CurClipRegion[2],
00944 ScilabXgc->CurClipRegion[3]);
00945 else
00946 sciprint("\nNo Clip Region");
00947 }
00948 }
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00961 static void xset_absourel(integer *num, integer *v2, integer *v3, integer *v4)
00962 {
00963 if (*num == CoordModeOrigin)
00964 ScilabXgc->CurVectorStyle = CoordModeOrigin;
00965 else
00966 ScilabXgc->CurVectorStyle = CoordModePrevious ;
00967 }
00968
00971 static void xget_absourel(integer *verbose, integer *num, integer *narg, double *dummy)
00972 {
00973 *narg = 1;
00974 *num = ScilabXgc->CurVectorStyle ;
00975 if (*verbose == 1)
00976 {
00977 if (ScilabXgc->CurVectorStyle == CoordModeOrigin)
00978 sciprint("\nTrace Absolu");
00979 else
00980 sciprint("\nTrace Relatif");
00981 }
00982 }
00983
00984 void set_c(integer col)
00985 {
00986 int i,bk;
00987
00988 i= Max(0,Min(col,ScilabXgc->Numcolors + 1));
00989 ScilabXgc->CurColor = i;
00990 bk= Max(0,Min(ScilabXgc->NumBackground,ScilabXgc->Numcolors + 1));
00991 if (ScilabXgc->Colors == NULL) return;
00992 switch ( ScilabXgc->CurDrawFunction )
00993 {
00994 case GXclear :
00995 break ;
00996 case GXxor :
00997 XSetForeground(dpy, gc,(unsigned long)
00998 ScilabXgc->Colors[i] ^ ScilabXgc->Colors[bk]);break;
00999 default :
01000 XSetForeground(dpy, gc,(unsigned long) ScilabXgc->Colors[i] );break;
01001 }
01002 }
01003
01004
01005
01006
01007
01008
01009
01010 static struct alinfo {
01011 char *name;
01012 char id;
01013 char *info;} AluStruc_[] =
01014 {
01015 {"GXclear" ,GXclear," 0 "},
01016 {"GXand" ,GXand," src AND dst "},
01017 {"GXandReverse" ,GXandReverse," src AND NOT dst "},
01018 {"GXcopy" ,GXcopy," src "},
01019 {"GXandInverted" ,GXandInverted," NOT src AND dst "},
01020 {"GXnoop" ,GXnoop," dst "},
01021 {"GXxor" ,GXxor," src XOR dst "},
01022 {"GXor" ,GXor," src OR dst "},
01023 {"GXnor" ,GXnor," NOT src AND NOT dst "},
01024 {"GXequiv" ,GXequiv," NOT src XOR dst "},
01025 {"GXinvert" ,GXinvert," NOT dst "},
01026 {"GXorReverse" ,GXorReverse," src OR NOT dst "},
01027 {"GXcopyInverted" ,GXcopyInverted," NOT src "},
01028 {"GXorInverted" ,GXorInverted," NOT src OR dst "},
01029 {"GXnand" ,GXnand," NOT src OR NOT dst "},
01030 {"GXset" ,GXset," 1 "}
01031 };
01032
01033
01034 static void idfromname(char *name1, integer *num)
01035 {int i;
01036 *num = -1;
01037 for ( i =0 ; i < 16;i++)
01038 if (strcmp(AluStruc_[i].name,name1)== 0)
01039 *num=AluStruc_[i].id;
01040 if (*num == -1 )
01041 {
01042 sciprint("\n Use the following keys (integer in scilab");
01043 for ( i=0 ; i < 16 ; i++)
01044 sciprint("\nkey %s -> %s\r\n",AluStruc_[i].name,
01045 AluStruc_[i].info);
01046 }
01047 }
01048
01049 void xset_alufunction(char *string)
01050 {
01051 integer value;
01052 XGCValues gcvalues;
01053 idfromname(string,&value);
01054 if ( value != -1)
01055 {
01056 ScilabXgc->CurDrawFunction = value;
01057 gcvalues.function = value;
01058 XChangeGC(dpy, gc, GCFunction, &gcvalues);
01059 }
01060 }
01061
01062
01063 static void xset_alufunction1(integer *num, integer *v2, integer *v3, integer *v4)
01064 {
01065 xset_alufunction2(ScilabXgc,num,v2,v3,v4);
01066 }
01067
01068
01069 static void xset_alufunction2(struct BCG *Xgc,integer *num, integer *v2, integer *v3, integer *v4)
01070 {
01071 integer value;
01072 XGCValues gcvalues;
01073 static Pixel pxb,pxf;
01074 pxb = (Xgc->Colors == NULL)? DefaultBackground
01075 : Xgc->Colors[Xgc->NumBackground];
01076 pxf = (Xgc->Colors == NULL)? DefaultForeground
01077 : Xgc->Colors[Xgc->NumForeground];
01078 value=AluStruc_[Min(15,Max(0,*num))].id;
01079 if ( value != -1)
01080 {
01081 Xgc->CurDrawFunction = value;
01082
01084 switch (value)
01085 {
01086 case GXclear :
01087 gcvalues.foreground = pxb;
01088 gcvalues.background = pxb;
01089 gcvalues.function = GXcopy;
01090 break;
01091 case GXxor :
01092 gcvalues.foreground = pxf ^ pxb ;
01093 gcvalues.background = pxb ;
01094 gcvalues.function = GXxor;
01095 break;
01096 default :
01097 gcvalues.foreground = pxf ;
01098 gcvalues.background = pxb;
01099 gcvalues.function = value;
01100 break;
01101 }
01102 XChangeGC(dpy,gc,(GCFunction|GCForeground|GCBackground), &gcvalues);
01103 if ( value == GXxor && Xgc->CurColorStatus == 1 )
01104 {
01107 set_c(Xgc->CurColor);
01108 }
01109 }
01110 }
01111
01112 static void xget_alufunction(integer *verbose, integer *value, integer *narg, double *dummy)
01113 {
01114 *narg =1 ;
01115 *value = ScilabXgc->CurDrawFunction ;
01116 if (*verbose ==1 )
01117 {
01118 sciprint("\nThe Alufunction is %s -> <%s>\r\n",
01119 AluStruc_[*value].name,
01120 AluStruc_[*value].info);
01121 }
01122 }
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132 #define MAXDASH 6
01133 #define DASH_TAB_SIZE 4
01134
01135
01136
01137
01138 static integer DashTab[MAXDASH][DASH_TAB_SIZE] = {
01139 {2,5,2,5}, {5,2,5,2}, {1,2,1,2}, {5,2,1,2},
01140 {9,2,1,2}, {9,2,5,2}} ;
01141
01142
01143
01144 static void setRealDashStyle( integer lineThickness, integer dashStyle, integer dashStyleSize )
01145 {
01146 integer xDash[4] ;
01147 integer xDash0 ;
01148 double gapFactor ;
01149 double dLineThickness ;
01150
01151
01152
01153
01154 if ( lineThickness == 0 )
01155 {
01156 dLineThickness = 0.8 ;
01157 gapFactor = 5.0 ;
01158 }
01159 else
01160 {
01161 dLineThickness = lineThickness ;
01162 gapFactor = dLineThickness + ( 4.0 / ( sqrt(dLineThickness) ) ) ;
01163 }
01164
01165
01166 xDash0 = DashTab[dashStyle][0] ;
01167
01168 xDash[0] = Max( (integer) ( DashTab[dashStyle][0] * dLineThickness ), 1 ) ;
01169 xDash[1] = (integer) ( DashTab[dashStyle][1] * gapFactor ) ;
01170 xDash[2] = Max( (integer) ( DashTab[dashStyle][2] * dLineThickness ), 1 ) ;
01171 xDash[3] = (integer) ( DashTab[dashStyle][3] * gapFactor ) ;
01172 xset_dashstyle( &dashStyle, xDash, &dashStyleSize ) ;
01173 }
01174
01175
01176
01177
01178
01179
01180
01181
01182 static void xset_thickness(integer *value, integer *v2, integer *v3, integer *v4)
01183 {
01184 integer l2 = DASH_TAB_SIZE ;
01185 XGCValues gcvalues;
01186
01187 ScilabXgc->CurLineWidth = Max(0, *value);
01188
01189 gcvalues.line_width = ScilabXgc->CurLineWidth ;
01190 XChangeGC(dpy, gc, GCLineWidth, &gcvalues);
01191
01192
01193
01194 setRealDashStyle( ScilabXgc->CurLineWidth, ScilabXgc->CurDashStyle, l2 ) ;
01195 }
01196
01199 static void xget_thickness(integer *verbose, integer *value, integer *narg, double *dummy)
01200 {
01201 *narg =1 ;
01202 *value = ScilabXgc->CurLineWidth ;
01203 if (*verbose ==1 )
01204 sciprint("\nLine Width:%d\r\n", ScilabXgc->CurLineWidth ) ;
01205 }
01206
01210 Pixmap Tabpix_[GREYNUMBER];
01211
01212 static char grey0[GREYNUMBER][8]={
01213 {(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00},
01214 {(char)0x00, (char)0x00, (char)0x44, (char)0x00, (char)0x00, (char)0x00, (char)0x44, (char)0x00},
01215 {(char)0x00, (char)0x44, (char)0x00, (char)0x22, (char)0x08, (char)0x40, (char)0x01, (char)0x20},
01216 {(char)0x00, (char)0x92, (char)0x00, (char)0x25, (char)0x00, (char)0x92, (char)0x00, (char)0xa4},
01217 {(char)0x55, (char)0x00, (char)0xaa, (char)0x00, (char)0x55, (char)0x00, (char)0xaa, (char)0x00},
01218 {(char)0xad, (char)0x00, (char)0x5b, (char)0x00, (char)0xda, (char)0x00, (char)0x6d, (char)0x00},
01219 {(char)0x6d, (char)0x02, (char)0xda, (char)0x08, (char)0x6b, (char)0x10, (char)0xb6, (char)0x20},
01220 {(char)0x6d, (char)0x22, (char)0xda, (char)0x0c, (char)0x6b, (char)0x18, (char)0xb6, (char)0x24},
01221 {(char)0x55, (char)0xaa, (char)0x55, (char)0xaa, (char)0x55, (char)0xaa, (char)0x55, (char)0xaa},
01222 {(char)0x92, (char)0xdd, (char)0x25, (char)0xf3, (char)0x94, (char)0xe7, (char)0x49, (char)0xdb},
01223 {(char)0x92, (char)0xfd, (char)0x25, (char)0xf7, (char)0x94, (char)0xef, (char)0x49, (char)0xdf},
01224 {(char)0x52, (char)0xff, (char)0xa4, (char)0xff, (char)0x25, (char)0xff, (char)0x92, (char)0xff},
01225 {(char)0xaa, (char)0xff, (char)0x55, (char)0xff, (char)0xaa, (char)0xff, (char)0x55, (char)0xff},
01226 {(char)0xff, (char)0x6d, (char)0xff, (char)0xda, (char)0xff, (char)0x6d, (char)0xff, (char)0x5b},
01227 {(char)0xff, (char)0xbb, (char)0xff, (char)0xdd, (char)0xf7, (char)0xbf, (char)0xfe, (char)0xdf},
01228 {(char)0xff, (char)0xff, (char)0xbb, (char)0xff, (char)0xff, (char)0xff, (char)0xbb, (char)0xff},
01229 {(char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff},
01230 };
01231
01232 void C2F(CreatePatterns)(Pixel whitepixel, Pixel blackpixel)
01233 { integer i ;
01234 for ( i=0 ; i < GREYNUMBER ; i++)
01235 Tabpix_[i] =XCreatePixmapFromBitmapData(dpy, root,grey0[i] ,8,8,whitepixel
01236 ,blackpixel,XDefaultDepth (dpy,DefaultScreen(dpy)));
01237 }
01238
01239 static void xset_pattern(integer *num, integer *v2, integer *v3, integer *v4)
01240 { integer i ;
01241
01242 if (ScilabXgc->CurColorStatus == 1)
01243 {
01244 set_c(*num-1);
01245 }
01246 else
01247 {
01248 i= Max(0,Min(*num - 1,GREYNUMBER - 1));
01249 ScilabXgc->CurPattern = i;
01250 XSetTile (dpy, gc, Tabpix_[i]);
01251 if (i ==0)
01252 XSetFillStyle(dpy,gc,FillSolid);
01253 else
01254 XSetFillStyle(dpy,gc,FillTiled);
01255 }
01256 }
01257
01260 static void xget_pattern(integer *verbose, integer *num, integer *narg, double *dummy)
01261 {
01262 *narg=1;
01263 if ( ScilabXgc->CurColorStatus == 1 )
01264 *num = ScilabXgc->CurColor + 1;
01265 else
01266 *num = ScilabXgc->CurPattern + 1;
01267 if (*verbose == 1)
01268 sciprint("\n Pattern : %d\r\n",ScilabXgc->CurPattern + 1);
01269 }
01270
01273 static void xget_last(integer *verbose, integer *num, integer *narg, double *dummy)
01274 {
01275 if ( ScilabXgc->CurColorStatus == 1 )
01276 {
01277 *num = ScilabXgc->IDLastPattern + 1;
01278 if (*verbose == 1)
01279 sciprint("\n Id of Last Color %d\r\n",(int)*num);
01280 }
01281
01282 else
01283 {
01284 *num = ScilabXgc->IDLastPattern + 1;
01285 if (*verbose == 1)
01286 sciprint("\n Id of Last Pattern %d\r\n",(int)*num);
01287 }
01288 *narg=1;
01289 }
01290
01291
01292 static void xset_dash(integer *value, integer *v2, integer *v3, integer *v4)
01293 {
01294 static integer l3 ;
01295 static integer l2 = DASH_TAB_SIZE ;
01296
01297 l3 = Max(0,Min(MAXDASH - 1,*value - 1));
01298
01299 ScilabXgc->CurDashStyle = l3 ;
01300
01301
01302
01303
01304 setRealDashStyle( ScilabXgc->CurLineWidth, ScilabXgc->CurDashStyle, l2 ) ;
01305
01306 }
01307
01308
01309
01310 static void xset_dash_or_color(integer *value, integer *v2, integer *v3, integer *v4)
01311 {
01312 if ( ScilabXgc->CurColorStatus == 1)
01313 {
01314 set_c(*value-1);
01315 }
01316 else
01317 xset_dash(value, v2, v3, v4);
01318 }
01319
01320 static void xset_dash_and_color(integer *value, integer *v2, integer *v3, integer *v4)
01321 {
01322 xset_dash(value, v2, v3, v4);
01323 xset_pattern(value+6, v2, v3, v4);
01324 }
01325
01326 static void xset_line_style(integer *value, integer *v2, integer *v3, integer *v4)
01327 {
01328 integer j;
01329 if (ScilabXgc->CurColorStatus == 0)
01330 xset_dash(value,PI0,PI0,PI0);
01331 else {
01332 j= ScilabXgc->CurDashStyle + 1;
01333 xset_dash(&j,PI0,PI0,PI0);
01334 xset_pattern(value,PI0,PI0,PI0);
01335 }
01336 }
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347 static void xset_dashstyle(integer *value, integer *xx, integer *n)
01348 {
01349 int dashok= LineOnOffDash ;
01350 if ( *value == 0)
01351 {
01352 dashok = LineSolid ;
01353 }
01354 else
01355 {
01356 integer i;
01357 char * buffdash = NULL ;
01358 if ( ( buffdash = MALLOC( *n * sizeof(char) ) ) == NULL )
01359 {
01360 return ;
01361 }
01362 for ( i = 0 ; i < *n ; i++ )
01363 {
01364
01365
01366
01367 buffdash[i] = INT_2_UCHAR( xx[i] ) ;
01368 }
01369 XSetDashes(dpy,gc,0,buffdash,(int)*n);
01370 FREE( buffdash ) ;
01371 }
01372 XSetLineAttributes(dpy,gc,(unsigned) ScilabXgc->CurLineWidth,dashok,
01373 CapButt,JoinMiter);
01374 }
01375
01376
01378
01379
01380 static void xget_dash_or_color(integer *verbose, integer *value, integer *narg, double *dummy)
01381 {
01382 if ( ScilabXgc->CurColorStatus ==1)
01383 {
01384 *narg =1 ;
01385 *value = ScilabXgc->CurColor + 1;
01386 if (*verbose == 1) sciprint("Color %d",(int)*value);
01387 return;
01388 }
01389 xget_dash(verbose, value, narg,dummy);
01390 }
01391
01392 static void xget_dash(integer *verbose, integer *value, integer *narg, double *dummy)
01393 {
01394 int i ;
01395 *narg =1 ;
01396 *value = ScilabXgc->CurDashStyle + 1;
01397 if (*value == 1)
01398 { if (*verbose == 1) sciprint("\nLine style = Line Solid");}
01399 else
01400 {
01401 value[1]=4;
01402 *narg = value[1]+2;
01403 for (i = 0 ; i < value[1]; i++) value[i+2]=DashTab[*value-2][i];
01404 if (*verbose ==1)
01405 {
01406 sciprint("\nDash Style %d:<",(int)*value - 1);
01407 for (i = 0 ; i < value[1]; i++)
01408 sciprint("%d ",(int)value[i+2]);
01409 sciprint(">\n");
01410 }
01411 }
01412 }
01413
01414 static void xget_dash_and_color(integer *verbose, integer *value, integer *narg, double *dummy)
01415 {
01416
01417 xget_dash(verbose, value, narg,dummy);
01418 xget_pattern(verbose, value+6, narg,dummy);
01419 *narg = 6;
01420 }
01421
01422
01423
01424
01425 static void xset_usecolor(integer *num, integer *v1, integer *v2, integer *v3)
01426 {
01427 integer i;
01428 i = Min(Max(*num,0),1);
01429 if ( ScilabXgc->CurColorStatus != (int) i)
01430 {
01431 if (ScilabXgc->CurColorStatus == 1)
01432 {
01433
01434 ScilabXgc->CurColorStatus = 1;
01435 xset_pattern((i=1,&i),PI0,PI0,PI0);
01436
01437 ScilabXgc->CurColorStatus = 0;
01438 i= ScilabXgc->CurPattern + 1;
01439 xset_pattern(&i,PI0,PI0,PI0);
01440 i= ScilabXgc->CurDashStyle + 1;
01441 xset_dash(&i,PI0,PI0,PI0);
01442
01443
01444 ScilabXgc->IDLastPattern = GREYNUMBER - 1;
01445 }
01446 else
01447 {
01448
01449
01450
01451 ScilabXgc->CurColorStatus = 0;
01452 xset_pattern((i=1,&i),PI0,PI0,PI0);
01453 xset_dash((i=1,&i),PI0,PI0,PI0);
01454
01455 ScilabXgc->CurColorStatus = 1;
01456 i= ScilabXgc->CurColor + 1;
01457 xset_pattern(&i,PI0,PI0,PI0);
01458 xset_pattern(&i,PI0,PI0,PI0);
01459 ScilabXgc->IDLastPattern = ScilabXgc->Numcolors - 1;
01460
01461 }
01462 }
01463 }
01464
01465 static void xget_usecolor(integer *verbose, integer *num, integer *narg, double *dummy)
01466 {
01467 *num = ScilabXgc->CurColorStatus;
01468 if (*verbose == 1)
01469 sciprint("\n Use color %d\r\n",(int)*num);
01470 *narg=1;
01471 }
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488 static void xset_pixmapOn(integer *num, integer *v2, integer *v3, integer *v4)
01489 {
01490 integer num1= Min(Max(*num,0),1);
01491 Pixel px;
01492
01493
01494
01495 if (ScilabXgc->Cdrawable == (Drawable) 0) {
01496 XWindowAttributes war;
01497 XGetWindowAttributes(dpy,ScilabXgc->CWindow,&war);
01498 ScilabXgc->Cdrawable = (Drawable) XCreatePixmap(dpy,root,war.width,war.height,depth);
01499 if (ScilabXgc->Cdrawable != (Drawable) 0) {
01500 PixmapClear(ScilabXgc,0,0,war.width,war.height);
01501 XSetWindowBackgroundPixmap(dpy, ScilabXgc->CWindow, (Pixmap) ScilabXgc->Cdrawable);
01502 }
01503 else {
01504 px = (ScilabXgc->Colors == NULL) ? DefaultBackground
01505 : ScilabXgc->Colors[ScilabXgc->NumBackground];
01506 XSetWindowBackground(dpy, ScilabXgc->CWindow,px);
01507 }
01508 }
01509
01510 if ( num1 == 0 ) {
01511 C2F(xinfo)(" ",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01512 ScilabXgc->CurPixmapStatus = 0;
01513 }
01514 else if ( num1 == 1 ) {
01515 if (ScilabXgc->Cdrawable != (Drawable) 0) {
01516 XWindowAttributes war;
01517 C2F(xinfo)("Animation mode is on,( xset('pixmap',0) to leave)",
01518 PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01519 XGetWindowAttributes(dpy,ScilabXgc->CWindow,&war);
01520
01521 ScilabXgc->CurPixmapStatus = 1;
01522 PixmapClear(ScilabXgc,0,0,war.width,war.height);
01523 }
01524 else
01525 ScilabXgc->CurPixmapStatus = 0;
01526
01527 }
01528
01529 }
01530
01531 static void xget_pixmapOn(integer *verbose, integer *value, integer *narg, double *dummy)
01532 {
01533 *value=ScilabXgc->CurPixmapStatus;
01534 *narg =1 ;
01535 if (*verbose == 1) sciprint("Pixmap status %d",(int)*value);
01536 }
01537
01538
01539
01540
01541
01542 static void xset_wresize(integer *num, integer *v2, integer *v3, integer *v4)
01543 {
01544 integer num1= Min(Max(*num,0),1);
01545 if ( num1 != ScilabXgc->CurResizeStatus && num1 == 1)
01546 {
01547
01548
01549 integer clwidth,clheight;
01550
01551 SciViewportMove(ScilabXgc,0,0);
01552
01553 SciViewportClipGetSize (ScilabXgc, &clwidth, &clheight);
01554
01555 ScilabXgc->CurResizeStatus = num1 ;
01556
01557 xset_windowdim(&clwidth,&clheight,NULL,NULL);
01558 return ;
01559 }
01560 ScilabXgc->CurResizeStatus = num1 ;
01561 }
01562
01563 static void xget_wresize(integer *verbose, integer *value, integer *narg, double *dummy)
01564 {
01565 *value=ScilabXgc->CurResizeStatus;
01566 *narg =1 ;
01567 if (*verbose == 1) sciprint("Resize status %d",(int)*value);
01568 }
01569
01570
01571
01572 static int set_default_colormap_flag = 1;
01573
01574 int C2F(sedeco)(int *flag)
01575 {
01576 set_default_colormap_flag = *flag;
01577 return(0);
01578 }
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588 Pixel RGB2pixO(unsigned int r, unsigned int g, unsigned int b, long unsigned int r_mask, long unsigned int g_mask, long unsigned int b_mask)
01589 {
01590 static int r_bits,g_bits,b_bits,first_entry=0;
01591 unsigned long p2;
01592 int i;
01593 Pixel pix;
01594
01595 if (first_entry == 0) {
01596 p2 = 1;
01597 for (i = 1; i <= depth; i++) {
01598 if (p2 << i == b_mask + 1) {
01599 b_bits = i;
01600 break;
01601 }
01602 }
01603 g_mask = g_mask >> b_bits;
01604 p2 = 1;
01605 for (i = 1; i <= depth - b_bits; i++) {
01606 if (p2 << i == g_mask + 1) {
01607 g_bits = i;
01608 break;
01609 }
01610 }
01611
01612 r_bits = depth - g_bits - b_bits;
01613 first_entry = 1;
01614 }
01615
01616 pix = ((r >> (8 - r_bits)) << (g_bits + b_bits))
01617 + ((g >> (8 - g_bits)) << b_bits)
01618 + (b >> (8 - b_bits));
01619 return pix;
01620 }
01621
01622
01623 static char *hex_string(int r, int g, int b);
01624
01625
01626
01627
01628
01629 static char hex_str[10];
01630
01631 static char *hex_string(int r, int g, int b)
01632 {
01633 char rlabel[10], glabel[10], blabel[10];
01634
01635
01636 (void) sprintf(rlabel,"00%x",r);
01637 (void) sprintf(glabel,"00%x",g);
01638 (void) sprintf(blabel,"00%x",b);
01639
01640
01641 (void) sprintf(hex_str,"#000000");
01642 hex_str[1] = rlabel[strlen(rlabel)-2];
01643 hex_str[2] = rlabel[strlen(rlabel)-1];
01644 hex_str[3] = glabel[strlen(glabel)-2];
01645 hex_str[4] = glabel[strlen(glabel)-1];
01646 hex_str[5] = blabel[strlen(blabel)-2];
01647 hex_str[6] = blabel[strlen(blabel)-1];
01648
01649 return(hex_str);
01650 }
01651
01652 Pixel RGB2pix(unsigned int r, unsigned int g, unsigned int b, long unsigned int r_mask, long unsigned int g_mask, long unsigned int b_mask)
01653 {
01654 Colormap cmap;
01655 XColor cdef;
01656 cdef.red = r *256 ;
01657 cdef.green = g *256 ;
01658 cdef.blue = b *256 ;
01659 cdef.flags = DoRed | DoGreen | DoBlue;
01660 cmap = XDefaultColormap(dpy,XDefaultScreen(dpy));
01661 if (XAllocColor(dpy,cmap,&cdef))
01662 return( cdef.pixel);
01663 else if (XParseColor(dpy,cmap,hex_string(r,g,b),&cdef) &&
01664 XAllocColor(dpy,cmap,&cdef)) {
01665 return( cdef.pixel);
01666 }
01667 return (Pixel) 0;
01668 }
01669
01670
01671
01672
01673
01674
01675 void set_default_colormap1(int m);
01676 void set_default_colormap2(int m);
01677 void set_default_colormap3(int m);
01678
01679 void set_default_colormap(void)
01680 {
01681 int m;
01682
01683
01684
01685
01686 if (set_default_colormap_flag == 0) return;
01687
01688 if (DEFAULTNUMCOLORS > maxcol) {
01689 sciprint("Not enough colors for default colormap. Maximum is %d\r\n",
01690 maxcol);
01691 return;
01692 }
01693 m = DEFAULTNUMCOLORS;
01694
01695 switch (visual->class) {
01696 case TrueColor:
01697 set_default_colormap1(m);
01698 break;
01699 case DirectColor:
01700 set_default_colormap2(m);
01701 break;
01702 default:
01703 set_default_colormap2(m);
01704 break;
01705 }
01706 }
01707
01708
01709
01710 void set_default_colormap1(int m)
01711 {
01712 int i;
01713 Colormap cmap;
01714 Pixel pix;
01715 unsigned int red, green, blue;
01716 Pixel *c = ScilabXgc->Colors;
01717 float *r = ScilabXgc->Red;
01718 float *g = ScilabXgc->Green;
01719 float *b = ScilabXgc->Blue;
01720
01721 if (!XgcAllocColors(ScilabXgc,m)) {
01722 ScilabXgc->Colors = c;
01723 ScilabXgc->Red = r;
01724 ScilabXgc->Green = g;
01725 ScilabXgc->Blue = b;
01726 return;
01727 }
01728
01729
01730 for (i = 0; i < m; i++) {
01731 ScilabXgc->Red[i] = (float)default_colors[3*i]/255.0;
01732 ScilabXgc->Green[i] = (float)default_colors[3*i+1]/255.0;
01733 ScilabXgc->Blue[i] = (float)default_colors[3*i+2]/255.0;
01734 }
01735
01736
01737 ScilabXgc->Red[m] = 0;
01738 ScilabXgc->Green[m] = 0;
01739 ScilabXgc->Blue[m] = 0;
01740
01741
01742 ScilabXgc->Red[m+1] = 1;
01743 ScilabXgc->Green[m+1] = 1;
01744 ScilabXgc->Blue[m+1] = 1;
01745
01746 cmap = XDefaultColormap(dpy,XDefaultScreen(dpy));
01747
01748 for (i = 0; i < m; i++) {
01749 red = (unsigned int)default_colors[3*i];
01750 green = (unsigned int)default_colors[3*i+1];
01751 blue = (unsigned int)default_colors[3*i+2];
01752 pix = RGB2pix(red,green,blue,visual->red_mask,visual->green_mask,
01753 visual->blue_mask);
01754 ScilabXgc->Colors[i] = pix;
01755 }
01756
01757 XSetWindowColormap(dpy,ScilabXgc->CBGWindow,cmap);
01758 ScilabXgc->Cmap = cmap;
01759 ScilabXgc->Numcolors = m;
01760 ScilabXgc->IDLastPattern = m - 1;
01761 ScilabXgc->CmapFlag = 1;
01762
01763 ScilabXgc->Colors[m] = ScilabXgc->Colors[DEFAULTBLACK];
01764 ScilabXgc->Colors[m+1] = ScilabXgc->Colors[DEFAULTWHITE];
01765 ScilabXgc->NumForeground = m;
01766 ScilabXgc->NumBackground = m + 1;
01767 XFlush(dpy);
01768 FREE(c); FREE(r); FREE(g); FREE(b);
01769 }
01770
01771
01772 void set_default_colormap2(int m)
01773 {
01774
01775 set_default_colormap3(m);
01776 }
01777
01778
01779 void set_default_colormap3(int m)
01780 {
01781 int i,j;
01782 int missing_col_mess=-1;
01783 Colormap cmap,dcmap,ocmap;
01784 XColor color;
01785 Pixel *pixels = (Pixel *) NULL;
01786 Pixel *c = ScilabXgc->Colors;
01787 float *r = ScilabXgc->Red;
01788 float *g = ScilabXgc->Green;
01789 float *b = ScilabXgc->Blue;
01790
01791 int bp1,wp1;
01792
01793 if (!XgcAllocColors(ScilabXgc,m)) {
01794 ScilabXgc->Colors = c;
01795 ScilabXgc->Red = r;
01796 ScilabXgc->Green = g;
01797 ScilabXgc->Blue = b;
01798 return;
01799 }
01800
01801 if (!(pixels = (Pixel *) MALLOC(m*sizeof(Pixel)))) {
01802 sciprint("set_default_colormap: unable to alloc\n");
01803 XgcFreeColors(ScilabXgc);
01804 ScilabXgc->Colors = c;
01805 ScilabXgc->Red = r;
01806 ScilabXgc->Green = g;
01807 ScilabXgc->Blue = b;
01808 return;
01809 }
01810
01811
01812 for (i = 0; i < m; i++) {
01813 ScilabXgc->Red[i] = (float)default_colors[3*i]/255.0;
01814 ScilabXgc->Green[i] = (float)default_colors[3*i+1]/255.0;
01815 ScilabXgc->Blue[i] = (float)default_colors[3*i+2]/255.0;
01816 }
01817
01818 ScilabXgc->Red[m] = 0;
01819 ScilabXgc->Green[m] = 0;
01820 ScilabXgc->Blue[m] = 0;
01821
01822
01823 ScilabXgc->Red[m+1] = 1;
01824 ScilabXgc->Green[m+1] = 1;
01825 ScilabXgc->Blue[m+1] = 1;
01826
01827 dcmap = XDefaultColormap(dpy,XDefaultScreen(dpy));
01828 ocmap = ScilabXgc->Cmap;
01829
01830
01831
01832 if (ScilabXgc->Numcolors != 0 && ocmap == dcmap) {
01833 XFreeColors(dpy,dcmap,c,ScilabXgc->Numcolors,0);
01834 }
01835
01836
01837 for (i = 0; i < m; i++) {
01838 color.red = default_colors[3*i]<<8;
01839 color.green = default_colors[3*i+1]<<8;
01840 color.blue = default_colors[3*i+2]<<8;
01841 color.flags = DoRed|DoGreen|DoBlue;
01842 if (!XAllocColor(dpy,dcmap,&color)) {
01843
01844 if (i != 0) XFreeColors(dpy,dcmap,pixels,i,0);
01845 break;
01846 }
01847 pixels[i] = color.pixel;
01848 ScilabXgc->Colors[i] = color.pixel;
01849 }
01850
01851 cmap = dcmap;
01852
01853 if (i < m - 1)
01854 {
01855
01856
01857 if (ocmap == 0 || ocmap == dcmap)
01858 {
01859
01860 missing_col_mess=i;
01861 if ((cmap=XCreateColormap(dpy,ScilabXgc->CBGWindow,visual,AllocNone)) == 0)
01862 {
01863 XgcFreeColors(ScilabXgc);
01864 FREE(pixels);
01865 ScilabXgc->Colors = c;
01866 ScilabXgc->Red = r;
01867 ScilabXgc->Green = g;
01868 ScilabXgc->Blue = b;
01869 sciprint("%d colors missing, switch to private colormap\r\n",m - i);
01870 sciprint("Cannot allocate new colormap\r\n");
01871 return;
01872 }
01873 }
01874 else
01875 {
01876
01877 cmap = ocmap;
01878
01879 if (ScilabXgc->CmapFlag)
01880 XFreeColors(dpy,cmap,c,ScilabXgc->Numcolors,0);
01881 else XFreeColors(dpy,cmap,c,ScilabXgc->Numcolors+2,0);
01882 }
01883
01884 for (i = 0; i < m; i++)
01885 {
01886 if (!XAllocColorCells(dpy,cmap,False,NULL,0,&pixels[i],1))
01887 {
01888 XgcFreeColors(ScilabXgc);
01889 FREE(pixels);
01890 ScilabXgc->Colors = c;
01891 ScilabXgc->Red = r;
01892 ScilabXgc->Green = g;
01893 ScilabXgc->Blue = b;
01894 sciprint("%d colors missing, unable to allocate colormap\r\n",m - i);
01895 return;
01896 }
01897 }
01898
01899 color.flags = DoRed|DoGreen|DoBlue;
01900
01901
01902
01903 color.red = default_colors[3*DEFAULTWHITE]<<8;
01904 color.green = default_colors[3*DEFAULTWHITE+1]<<8;
01905 color.blue = default_colors[3*DEFAULTWHITE+2]<<8;
01906 if (wpixel == 1) wp1 = wpixel;
01907 else if (wpixel == 0) wp1 = wpixel;
01908 else if (bpixel == 0) wp1 = 1;
01909 else if (bpixel == 1) wp1 = 0;
01910 else wp1 =0;
01911 color.pixel = ScilabXgc->Colors[DEFAULTWHITE] = pixels[wp1];
01912 XStoreColor(dpy,cmap,&color);
01913 color.red = default_colors[3*DEFAULTBLACK]<<8;
01914 color.green = default_colors[3*DEFAULTBLACK+1]<<8;
01915 color.blue = default_colors[3*DEFAULTBLACK+2]<<8;
01916 if (bpixel == 1) bp1 = bpixel;
01917 else if (bpixel == 0) bp1 = bpixel;
01918 else if (wpixel == 0) bp1 = 1;
01919 else if (wpixel == 1) bp1 = 0;
01920 else bp1 =1;
01921 color.pixel = ScilabXgc->Colors[DEFAULTBLACK] = pixels[bp1];
01922 XStoreColor(dpy,cmap,&color);
01923 j = 2;
01924 for (i = 0; i < m; i++) {
01925 if (i == DEFAULTBLACK || i == DEFAULTWHITE) continue;
01926 color.red = default_colors[3*i]<<8;
01927 color.green = default_colors[3*i+1]<<8;
01928 color.blue = default_colors[3*i+2]<<8;
01929 color.pixel = ScilabXgc->Colors[i] = pixels[j++];
01930 XStoreColor(dpy,cmap,&color);
01931 }
01932
01933 ChangeBandF(ScilabXgc->CurWindow,pixels[bp1],pixels[wp1]);
01934 }
01935
01936 if (ocmap != (Colormap)0 && ocmap != cmap && ocmap != dcmap)
01937 XFreeColormap(dpy,ocmap);
01938 XSetWindowColormap(dpy,ScilabXgc->CBGWindow,cmap);
01939 ScilabXgc->Cmap = cmap;
01940 ScilabXgc->Numcolors = m;
01941 ScilabXgc->IDLastPattern = m - 1;
01942 ScilabXgc->CmapFlag = 1;
01943
01944 ScilabXgc->Colors[m] = ScilabXgc->Colors[DEFAULTBLACK];
01945 ScilabXgc->Colors[m+1] = ScilabXgc->Colors[DEFAULTWHITE];
01946 ScilabXgc->NumForeground = m;
01947 ScilabXgc->NumBackground = m + 1;
01948 XFlush(dpy);
01949 FREE(c); FREE(r); FREE(g); FREE(b);
01950 FREE(pixels);
01955 if (missing_col_mess != -1 )
01956 sciprint("%d colors missing, switch to private colormap\r\n",m -
01957 missing_col_mess);
01958 }
01959 void setcolormapg(struct BCG *XGC,integer *v1,integer *v2, double *a, integer *v3);
01960 void setcolormap1(struct BCG *XGC,integer m, double *a, integer *v3);
01961 void setcolormap2(struct BCG *XGC,integer m, double *a, integer *v3);
01962 void setcolormap3(struct BCG *XGC,integer m, double *a, integer *v3);
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974 static void xset_colormap(v1,v2,v3,v4,v5,v6,a)
01975 integer *v1,*v2;
01976 integer *v3;
01977 integer *v4,*v5,*v6;
01978 double *a;
01979 {
01980 *v3 = 0;
01981
01982 setcolormapg(ScilabXgc,v1,v2,a,v3);
01983 }
01984 static void xset_gccolormap(v1,v2,a,XGC,v3)
01985 integer *v1,*v2;
01986 double *a;
01987 struct BCG *XGC;
01988 integer *v3;
01989 {
01990
01991 setcolormapg(XGC,v1,v2,a,v3);
01992 }
01993
01994
01995 extern void setcolormapg(struct BCG *XGC,integer *v1, integer *v2, double *a, integer *v3)
01996 {
01997 int m;
01998
01999 if (*v2 != 3 || *v1 < 0 || *v1 >(int) maxcol - 2) {
02000 sciprint("Colormap must be a m x 3 array with m <= %ld, previous one kept\r\n",maxcol-2);
02001 *v3 =1;
02002 return;
02003 }
02004 m = *v1;
02005 switch (visual->class) {
02006 case TrueColor:
02007 setcolormap1(XGC,m,a,v3);
02008 break;
02009 case DirectColor:
02010 setcolormap2(XGC,m,a,v3);
02011 break;
02012 default:
02013 setcolormap3(XGC,m,a,v3);
02014 break;
02015 }
02016 }
02017
02018
02019 void setcolormap1(struct BCG *Xgc,integer m, double *a, integer *v3)
02020 {
02021 int i;
02022 Colormap cmap;
02023 unsigned int red, green, blue;
02024 Pixel pix;
02025
02026 Pixel *c = Xgc->Colors;
02027 float *r = Xgc->Red;
02028 float *g = Xgc->Green;
02029 float *b = Xgc->Blue;
02030
02031 if (!XgcAllocColors(ScilabXgc,m)) {
02032 Xgc->Colors = c;
02033 Xgc->Red = r;
02034 Xgc->Green = g;
02035 Xgc->Blue = b;
02036 *v3 = 1;
02037 return;
02038 }
02039
02040
02041 for (i = 0; i < m; i++) {
02042 if (a[i] < 0 || a[i] > 1 || a[i+m] < 0 || a[i+m] > 1 ||
02043 a[i+2*m] < 0 || a[i+2*m]> 1) {
02044 sciprint("RGB values must be between 0 and 1\n");
02045 Xgc->Colors = c;
02046 Xgc->Red = r;
02047 Xgc->Green = g;
02048 Xgc->Blue = b;
02049 *v3 = 1;
02050 return;
02051 }
02052 Xgc->Red[i] = (float)a[i];
02053 Xgc->Green[i] = (float)a[i+m];
02054 Xgc->Blue[i] = (float)a[i+2*m];
02055 }
02056
02057 Xgc->Red[m] = 0;
02058 Xgc->Green[m] = 0;
02059 Xgc->Blue[m] = 0;
02060 Xgc->Colors[m] = RGB2pix(0,0,0,visual->red_mask,
02061 visual->green_mask,visual->blue_mask);
02062
02063
02064 Xgc->Red[m+1] = 1;
02065 Xgc->Green[m+1] = 1;
02066 Xgc->Blue[m+1] = 1;
02067 Xgc->Colors[m+1] = RGB2pix(255,255,255,visual->red_mask,
02068 visual->green_mask,visual->blue_mask);
02069
02070 for (i = 0; i < m; i++) {
02071 red = (unsigned short)(a[i]*255.0);
02072 green = (unsigned short)(a[i+m]*255.0);
02073 blue = (unsigned short)(a[i+2*m]*255.0);
02074 pix = RGB2pix(red,green,blue,visual->red_mask,visual->green_mask,
02075 visual->blue_mask);
02076 Xgc->Colors[i] = pix;
02077 }
02078
02079 cmap = XDefaultColormap(dpy,XDefaultScreen(dpy));
02080
02081 XSetWindowColormap(dpy,Xgc->CBGWindow,cmap);
02082 Xgc->Cmap = cmap;
02083 Xgc->Numcolors = m;
02084 Xgc->IDLastPattern = m - 1;
02085 Xgc->CmapFlag = 0;
02086 Xgc->NumForeground = m;
02087 Xgc->NumBackground = m + 1;
02088 xset_usecolor((i=1,&i) ,PI0,PI0,PI0);
02089 xset_alufunction1(&Xgc->CurDrawFunction,PI0,PI0,PI0);
02090 xset_pattern((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);
02091 xset_foreground((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);
02092 xset_background((i=Xgc->NumForeground+2,&i),PI0,PI0,PI0);
02093 XFlush(dpy);
02094 FREE(c); FREE(r); FREE(g); FREE(b);
02095 }
02096
02097
02098 void setcolormap2(struct BCG *Xgc,integer m, double *a, integer *v3)
02099 {
02100
02101 setcolormap3(Xgc,m,a,v3);
02102 }
02103
02104
02105 void setcolormap3(struct BCG *Xgc,integer m, double *a, integer *v3)
02106 {
02107 int missing_col_mess=-1;
02108 int i;
02109 Colormap cmap,dcmap,ocmap;
02110 XColor color;
02111 int bp1,wp1;
02112 Pixel *pixels = (Pixel *) NULL;
02113
02114 Pixel *c = Xgc->Colors;
02115 float *r = Xgc->Red;
02116 float *g = Xgc->Green;
02117 float *b = Xgc->Blue;
02118
02119 if (!XgcAllocColors(Xgc,m)) {
02120 Xgc->Colors = c;
02121 Xgc->Red = r;
02122 Xgc->Green = g;
02123 Xgc->Blue = b;
02124 *v3 = 1;
02125 return;
02126 }
02127
02128 if (!(pixels = (Pixel *) MALLOC((m+2)*sizeof(Pixel)))) {
02129 sciprint("setcolormap: unable to alloc\n");
02130 XgcFreeColors(Xgc);
02131 Xgc->Colors = c;
02132 Xgc->Red = r;
02133 Xgc->Green = g;
02134 Xgc->Blue = b;
02135 *v3 = 1;
02136 return;
02137 }
02138
02139
02140 for (i = 0; i < m; i++) {
02141 if (a[i] < 0 || a[i] > 1 || a[i+m] < 0 || a[i+m] > 1 ||
02142 a[i+2*m] < 0 || a[i+2*m]> 1) {
02143 sciprint("RGB values must be between 0 and 1\n");
02144 Xgc->Colors = c;
02145 Xgc->Red = r;
02146 Xgc->Green = g;
02147 Xgc->Blue = b;
02148 *v3 = 1;
02149 return;
02150 }
02151 Xgc->Red[i] = (float)a[i];
02152 Xgc->Green[i] = (float)a[i+m];
02153 Xgc->Blue[i] = (float)a[i+2*m];
02154 }
02155
02156 Xgc->Red[m] = 0;
02157 Xgc->Green[m] = 0;
02158 Xgc->Blue[m] = 0;
02159
02160
02161 Xgc->Red[m+1] = 1;
02162 Xgc->Green[m+1] = 1;
02163 Xgc->Blue[m+1] = 1;
02164
02165 dcmap = XDefaultColormap(dpy,XDefaultScreen(dpy));
02166 ocmap = Xgc->Cmap;
02167
02168
02169
02170 if (Xgc->Numcolors!= 0 && ocmap == dcmap) {
02171 XFreeColors(dpy,dcmap,c,Xgc->Numcolors,0);
02172 }
02173
02174 color.flags = DoRed|DoGreen|DoBlue;
02175
02176
02177
02178
02179 if (wpixel == 1) wp1 = wpixel;
02180 else if (wpixel == 0) wp1 = wpixel;
02181 else if (bpixel == 0) wp1 = 1;
02182 else if (bpixel == 1) wp1 = 0;
02183 else wp1 =0;
02184 color.red = default_colors[3*DEFAULTWHITE]<<8;
02185 color.green = default_colors[3*DEFAULTWHITE+1]<<8;
02186 color.blue = default_colors[3*DEFAULTWHITE+2]<<8;
02187 XAllocColor(dpy,dcmap,&color);
02188 Xgc->Colors[m+1] = pixels[wp1] = color.pixel;
02189
02190 if (bpixel == 1) bp1 = bpixel;
02191 else if (bpixel == 0) bp1 = bpixel;
02192 else if (wpixel == 0) bp1 = 1;
02193 else if (wpixel == 1) bp1 = 0;
02194 else bp1 =1;
02195 color.red = default_colors[3*DEFAULTBLACK]<<8;
02196 color.green = default_colors[3*DEFAULTBLACK+1]<<8;
02197 color.blue = default_colors[3*DEFAULTBLACK+2]<<8;
02198 XAllocColor(dpy,dcmap,&color);
02199 Xgc->Colors[m] = pixels[bp1] = color.pixel;
02200
02201 for (i = 2; i < m+2; i++) {
02202 color.red = (unsigned short)(a[i-2]*65535.0);
02203 color.green = (unsigned short)(a[i-2+m]*65535.0);
02204 color.blue = (unsigned short)(a[i-2+2*m]*65535.0);
02205 if (!XAllocColor(dpy,dcmap,&color)) {
02206
02207 if (i != 0) XFreeColors(dpy,dcmap,pixels,i,0);
02208 break;
02209 }
02210 Xgc->Colors[i-2] = pixels[i] = color.pixel;
02211 }
02212
02213 cmap = dcmap;
02214
02215 if (i < (m+2) - 1) {
02216
02217
02218 if (ocmap == 0 || ocmap == dcmap) {
02219
02220 missing_col_mess=i;
02221 if ((cmap = XCreateColormap(dpy,Xgc->CBGWindow,visual,AllocNone)) == 0) {
02222 XgcFreeColors(Xgc);
02223 FREE(pixels);
02224 Xgc->Colors = c;
02225 Xgc->Red = r;
02226 Xgc->Green = g;
02227 Xgc->Blue = b;
02228 sciprint("%d colors missing, switch to private colormap\r\n",m+2 - i);
02229 sciprint("Cannot allocate new colormap\n");
02230 return;
02231 }
02232 } else {
02233
02234 cmap = ocmap;
02235
02236 if (Xgc->CmapFlag)
02237 XFreeColors(dpy,cmap,c,Xgc->Numcolors,0);
02238 else XFreeColors(dpy,cmap,c,Xgc->Numcolors+2,0);
02239 }
02240
02241 for (i = 0; i < m+2; i++) {
02242 if (!XAllocColorCells(dpy,cmap,False,NULL,0,&pixels[i],1)) {
02243
02244 XgcFreeColors(Xgc);
02245 FREE(pixels);
02246 Xgc->Colors = c;
02247 Xgc->Red = r;
02248 Xgc->Green = g;
02249 Xgc->Blue = b;
02250 sciprint("%d colors missing, unable to allocate colormap\r\n",m+2 - i);
02251 return;
02252 }
02253 }
02254
02255 color.flags = DoRed|DoGreen|DoBlue;
02256
02257
02258 if (wpixel == 1) wp1 = wpixel;
02259 else if (wpixel == 0) wp1 = wpixel;
02260 else if (bpixel == 0) wp1 = 1;
02261 else if (bpixel == 1) wp1 = 0;
02262 else wp1 =0;
02263 color.red = 65535; color.green = 65535; color.blue = 65535;
02264 color.pixel = Xgc->Colors[m+1] = pixels[wp1];
02265 XStoreColor(dpy,cmap,&color);
02266 if (bpixel == 1) bp1 = bpixel;
02267 else if (bpixel == 0) bp1 = bpixel;
02268 else if (wpixel == 0) bp1 = 1;
02269 else if (wpixel == 1) bp1 = 0;
02270 else bp1 =1;
02271 color.red = 0; color.green = 0; color.blue = 0;
02272 color.pixel = Xgc->Colors[m] = pixels[bp1];
02273 XStoreColor(dpy,cmap,&color);
02274 for (i = 0; i < m; i++) {
02275 color.red = (unsigned short)(a[i]*65535.0);
02276 color.green = (unsigned short)(a[i+m]*65535.0);
02277 color.blue = (unsigned short)(a[i+2*m]*65535.0);
02278 color.pixel = Xgc->Colors[i] = pixels[i+2];
02279 XStoreColor(dpy,cmap,&color);
02280 }
02281
02282 ChangeBandF(Xgc->CurWindow,pixels[bp1],pixels[wp1]);
02283 }
02284
02285 if (ocmap != (Colormap)0 && ocmap != cmap && ocmap != dcmap)
02286 XFreeColormap(dpy,ocmap);
02287 XSetWindowColormap(dpy,Xgc->CBGWindow,cmap);
02288 Xgc->Cmap = cmap;
02289 Xgc->Numcolors = m;
02290 Xgc->IDLastPattern = m - 1;
02291 Xgc->CmapFlag = 0;
02292 Xgc->NumForeground = m;
02293 Xgc->NumBackground = m + 1;
02294 xset_usecolor((i=1,&i) ,PI0,PI0,PI0);
02295 xset_alufunction1(&Xgc->CurDrawFunction,PI0,PI0,PI0);
02296 xset_pattern((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);
02297 xset_foreground((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);
02298 xset_background((i=Xgc->NumForeground+2,&i),PI0,PI0,PI0);
02299 XFlush(dpy);
02300 FREE(c); FREE(r); FREE(g); FREE(b);
02301 FREE(pixels);
02302 if (missing_col_mess != -1)
02303 sciprint("%d colors missing, switch to private colormap\r\n",m+2 - missing_col_mess);
02304 }
02305
02306
02307
02308 static void xget_colormap_size(integer *verbose, integer *num, integer *narg, double *val)
02309 {
02310 if(ScilabXgc != NULL)
02311 *num = ScilabXgc->Numcolors;
02312 else
02313 {
02314 sciprint("No ScilabXgc allocated\n");
02315 *num = 0;
02316 return;
02317 }
02318 }
02319
02320
02321
02322 static void xget_colormap(integer *verbose, integer *num, integer *narg, double *val)
02323 {
02324 int m = ScilabXgc->Numcolors;
02325 int i;
02326 *narg = 1;
02327 *num = m;
02328 for (i = 0; i < m; i++) {
02329 val[i] = (double)ScilabXgc->Red[i];
02330 val[i+m] = (double)ScilabXgc->Green[i];
02331 val[i+2*m] = (double)ScilabXgc->Blue[i];
02332 }
02333 if (*verbose == 1) {
02334 sciprint("Size of colormap: %d colors\r\n",m);
02335 }
02336 }
02337
02340 int IsPrivateCmap(void)
02341 {
02342 int screen;
02343 if (dpy == (Display *) NULL) return(0);
02344 screen = XDefaultScreen(dpy);
02345 if (ScilabXgc == (struct BCG *)0 ) return(0);
02346 if ( ScilabXgc->Cmap == XDefaultColormap(dpy,screen)) return(0);
02347 else return(1);
02348 }
02349
02350
02353 static void xset_background(integer *num, integer *v2, integer *v3, integer *v4)
02354 {
02355 if (ScilabXgc->CurColorStatus == 1)
02356 {
02357
02358
02359
02360
02361 Pixel px;
02362 ScilabXgc->NumBackground = Max(0,Min(*num - 1,ScilabXgc->Numcolors + 1));
02363 xset_alufunction1(&ScilabXgc->CurDrawFunction,PI0,PI0,PI0);
02364 px = (ScilabXgc->Colors == NULL) ? DefaultBackground
02365 : ScilabXgc->Colors[ScilabXgc->NumBackground];
02366
02367 XSetWindowBackground(dpy, ScilabXgc->CWindow,px);
02368
02369
02370 }
02371 }
02372
02373 static void xget_background(integer *verbose, integer *num, integer *narg, double *dummy)
02374 {
02375 *narg=1;
02376 if ( ScilabXgc->CurColorStatus == 1 )
02377 {
02378 *num = ScilabXgc->NumBackground + 1;
02379 }
02380 else
02381 {
02382 *num = 1;
02383 }
02384 if (*verbose == 1)
02385 sciprint("\n Background : %d\r\n",*num);
02386 }
02387
02388
02389
02390 static void xset_foreground(integer *num, integer *v2, integer *v3, integer *v4)
02391 {
02392 if (ScilabXgc->CurColorStatus == 1)
02393 {
02394 Pixel px;
02395 ScilabXgc->NumForeground = Max(0,Min(*num - 1,ScilabXgc->Numcolors + 1));
02396 xset_alufunction1(&ScilabXgc->CurDrawFunction,PI0,PI0,PI0);
02397 px = (ScilabXgc->Colors == NULL) ? DefaultForeground
02398 : ScilabXgc->Colors[ScilabXgc->NumForeground];
02399
02401 }
02402 }
02403
02404 static void xget_foreground(integer *verbose, integer *num, integer *narg, double *dummy)
02405 {
02406 *narg=1;
02407 if ( ScilabXgc->CurColorStatus == 1 )
02408 {
02409 *num = ScilabXgc->NumForeground + 1;
02410 }
02411 else
02412 {
02413 *num = 1;
02414 }
02415 if (*verbose == 1)
02416 sciprint("\n Foreground : %d\r\n",*num);
02417 }
02418
02421 static void xset_hidden3d(integer *num, integer *v2, integer *v3, integer *v4)
02422 {
02423 if (ScilabXgc->CurColorStatus == 1)
02424 {
02425
02426
02427 ScilabXgc->NumHidden3d = Max(-2,Min(*num - 1,ScilabXgc->Numcolors + 1));
02428 }
02429 }
02430
02431 static void xget_hidden3d(integer *verbose, integer *num, integer *narg, double *dummy)
02432 {
02433 *narg=1;
02434 if ( ScilabXgc->CurColorStatus == 1 )
02435 {
02436 *num = ScilabXgc->NumHidden3d + 1;
02437 }
02438 else
02439 {
02440 *num = 1;
02441 }
02442 if (*verbose == 1)
02443 sciprint("\n Hidden3d : %d\r\n",*num);
02444 }
02445
02446
02447
02448
02449
02450
02451 void set_cmap(Window w)
02452 {
02453 if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->Cmap != (Colormap)0)
02454 XSetWindowColormap(dpy,w,ScilabXgc->Cmap);
02455 }
02456
02457 int get_pixel(int i)
02458 {
02459 if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->Cmap != (Colormap)0)
02460 return(ScilabXgc->Colors[Max(Min(i,ScilabXgc->Numcolors + 1),0)]);
02461 else
02462 return(0);
02463 }
02464
02465 Pixmap get_pixmap(int i)
02466 {
02467 return(Tabpix_[ Max(0,Min(i - 1,GREYNUMBER - 1))]);
02468 }
02469
02470
02471
02472
02473
02474
02475
02476
02477 int CheckColormap(int *m)
02478 {
02479 if ( ScilabXgc != (struct BCG *) 0 )
02480 {
02481 *m = ScilabXgc->Numcolors;
02482 if ( ScilabXgc->CmapFlag != 1)
02483 return 1;
02484 else
02485 return 0;
02486 }
02487 else
02488 {
02489 *m=0;
02490 return(0);
02491 }
02492 }
02493
02494 void get_r(int i, float *r)
02495 {
02496 *r = ScilabXgc->Red[i];
02497 }
02498 void get_g(int i, float *g)
02499 {
02500 *g = ScilabXgc->Green[i];
02501 }
02502 void get_b(int i, float *b)
02503 {
02504 *b = ScilabXgc->Blue[i];
02505 }
02506
02507
02508
02509
02510
02511
02512 static void InitMissileXgc(integer *v1, integer *v2, integer *v3, integer *v4);
02513
02514
02515 static void xset_empty(integer *verbose, integer *v2, integer *v3, integer *v4)
02516 {
02517 if ( *verbose ==1 ) sciprint("\n No operation ");
02518 }
02519
02520 static void xget_empty(integer *verbose, integer *v2, integer *v3, double *dummy)
02521 {
02522 if ( *verbose ==1 ) sciprint("\n No operation ");
02523 }
02524
02525 #define NUMSETFONC 32
02526
02529 static struct bgc { char *name ;
02530 void (*setfonc )() ;
02531 void (*getfonc )() ;}
02532
02533 MissileGCTab_[] = {
02534 {"alufunction",xset_alufunction1,xget_alufunction},
02535 {"background",xset_background,xget_background},
02536 {"clipoff",xset_unclip,xget_clip},
02537 {"clipping",xset_clip,xget_clip},
02538 {"cmap_size",xset_empty,xget_colormap_size},
02539 {"color",xset_pattern,xget_pattern},
02540 {"colormap",xset_colormap,xget_colormap},
02541 {"dashes",xset_dash_or_color,xget_dash_or_color},
02542 {"default",InitMissileXgc, xget_empty},
02543 {"figure",xset_scilabFigure,xget_scilabFigure},
02544 {"font",xset_font,xget_font},
02545 {"foreground",xset_foreground,xget_foreground},
02546 {"gc",xset_scilabxgc,xget_scilabxgc},
02547 {"gccolormap",xset_gccolormap,xget_colormap},
02548 {"hidden3d",xset_hidden3d,xget_hidden3d},
02549 {"lastpattern",xset_empty,xget_last},
02550 {"line mode",xset_absourel,xget_absourel},
02551 {"line style",xset_dash,xget_dash},
02552 {"mark",xset_mark,xget_mark},
02553 {"pattern",xset_pattern,xget_pattern},
02554 {"pixmap",xset_pixmapOn,xget_pixmapOn},
02555 {"thickness",xset_thickness,xget_thickness},
02556 {"use color",xset_usecolor,xget_usecolor},
02557 {"viewport",xset_viewport,xget_viewport},
02558 {"wdim",xset_windowdim,xget_windowdim},
02559 {"white",xset_empty,xget_last},
02560 {"window",xset_curwin,xget_curwin},
02561 {"wpdim",xset_popupdim,xget_popupdim},
02562 {"wpos",xset_windowpos,xget_windowpos},
02563 {"wresize",xset_wresize,xget_wresize},
02564 {"wshow",xset_show,xget_empty},
02565 {"wwpc",xset_pixmapclear,xget_empty}
02566 };
02567
02568 void C2F(MissileGCget)(char *str, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, double *dv1, double *dv2, double *dv3, double *dv4)
02569 {
02570 int x6=0;
02571 C2F(MissileGCGetorSet)(str,(integer)1L,verbose,x1,x2,x3,x4,x5,&x6,dv1);
02572 }
02573
02574 void C2F(MissileGCset)(char *str, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dv1, double *dv2, double *dv3, double *dv4)
02575 {
02576 integer verbose=0 ;
02577 C2F(MissileGCGetorSet)(str,(integer)0L,&verbose,x1,x2,x3,x4,x5,x6,dv1);
02578 }
02579
02580 void C2F(MissileGCGetorSet)(char *str, integer flag, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dv1)
02581 {
02582 integer i ;
02583 for (i=0; i < NUMSETFONC ; i++)
02584 {
02585 integer j;
02586 j = strcmp(str,MissileGCTab_[i].name);
02587 if ( j == 0 )
02588 {
02589
02590
02591 if (flag == 1)
02592 (MissileGCTab_[i].getfonc)(verbose,x1,x2,dv1);
02593 else
02594 (MissileGCTab_[i].setfonc)(x1,x2,x3,x4,x5,x6,dv1);
02595 return;}
02596 else
02597 { if ( j <= 0)
02598 {
02599 sciprint("\nUnknow X operator <%s>\r\n",str);
02600 if ( flag == 1)
02601 {
02604 *x1=1;*x2=0;
02605 }
02606 return;
02607 }
02608 }
02609 }
02610 sciprint("\n Unknow X operator <%s>\r\n",str);
02611 *x1=1;*x2=0;
02612 }
02613
02614
02615
02616
02617
02618
02619
02620
02621
02622
02623
02624
02625
02626
02627 void C2F(displaystring)(char *string, integer *x, integer *y, integer *v1, integer *flag, integer *v6, integer *v7, double *angle, double *dv2, double *dv3, double *dv4)
02628 {
02629 if ( Abs(*angle) <= 0.1)
02630 {
02631 int dir,asc,dsc,xpos;
02632 XCharStruct charret;
02633 if(strlen(string) !=0) {
02634 XQueryTextExtents(dpy,ScilabXgc->FontXID,
02635 string,strlen(string),&dir,&asc,&dsc,&charret);
02636 xpos= *x+ (charret.width)/(2.0*strlen(string));
02637 if(ScilabXgc->Cdrawable != (Drawable) 0 )
02638 XDrawString(dpy, ScilabXgc->Cdrawable,gc,(int) *x,(int) *y-charret.descent,
02639 string,strlen(string));
02640 if(ScilabXgc->CurPixmapStatus !=1)
02641 XDrawString(dpy, (Drawable) ScilabXgc->CWindow,gc,(int) *x,(int) *y-charret.descent,
02642 string,strlen(string));
02643
02644 if ( *flag == 1)
02645 {
02646 integer rect[4];
02647 rect[0]= *x ;
02648 rect[1]= *y-charret.ascent-charret.descent;
02649 rect[2]= charret.width;
02650 rect[3]= charret.ascent+charret.descent;
02651 C2F(drawrectangle)(string,rect,rect+1,rect+2,rect+3,
02652 PI0,PI0,PD0,PD0,PD0,PD0);
02653 }
02654 }
02655 }
02656 else
02657 C2F(DispStringAngle)(x,y,string,angle);
02658 XFlush(dpy);
02659 }
02660
02661 void C2F(DispStringAngle)(integer *x, integer *y, char *string, double *angle)
02662 {
02663 float ang;
02664 XFontStruct *font;
02665
02666 font=FontsList_[ScilabXgc->FontId][ScilabXgc->FontSize];
02667 ang= - *angle * M_PI/180.0;
02668
02669 if (ScilabXgc->Cdrawable != (Drawable) 0)
02670 XRotDrawString(dpy, font, ang, ScilabXgc->Cdrawable, gc, *x, *y, string);
02671 if (ScilabXgc->CurPixmapStatus != 1)
02672 XRotDrawString(dpy, font, ang, (Drawable) ScilabXgc->CWindow, gc, *x, *y, string);
02673 }
02674
02675 void C2F(DispStringAngleold)(integer *x0, integer *yy0, char *string, double *angle)
02676 {
02677 int i;
02678 integer x,y, rect[4];
02679 double sina ,cosa,l;
02680 char str1[2];
02681 str1[1]='\0';
02682 x= *x0;
02683 y= *yy0;
02684 sina= sin(*angle * M_PI/180.0);
02685 cosa= cos(*angle * M_PI/180.0);
02686 for ( i = 0 ; i < (int)strlen(string); i++)
02687 {
02688 str1[0]=string[i];
02689 if (ScilabXgc->Cdrawable != (Drawable) 0)
02690 XDrawString(dpy,ScilabXgc->Cdrawable,gc,(int) x,(int) y ,str1,1);
02691 if (ScilabXgc->CurPixmapStatus != 1)
02692 XDrawString(dpy,(Drawable) ScilabXgc->CWindow,gc,(int) x,(int) y ,str1,1);
02693
02694 C2F(boundingbox)(str1,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02696 if ( cosa <= 0.0 && i < (int)strlen(string)-1)
02697 { char str2[2];
02700 str2[1]='\0';str2[0]=string[i+1];
02701 C2F(boundingbox)(str2,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02702 }
02703 if ( Abs(cosa) >= 1.e-8 )
02704 {
02705 if ( Abs(sina/cosa) <= Abs(((double)rect[3])/((double)rect[2])))
02706 l = Abs(rect[2]/cosa);
02707 else
02708 l = Abs(rect[3]/sina);
02709 }
02710 else
02711 l = Abs(rect[3]/sina);
02712 x += cosa*l*1.1;
02713 y += sina*l*1.1;
02714 }
02715 }
02716
02719 void C2F(boundingbox)(char *string, integer *x, integer *y, integer *rect, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02720 {
02721 int dir,asc,dsc;
02722 XCharStruct charret;
02723 if (strlen(string) !=0) {
02724 XQueryTextExtents(dpy,ScilabXgc->FontXID,
02725 string,strlen(string),&dir,&asc,&dsc,&charret);
02726 rect[0]= *x ;
02727 rect[1]= *y-charret.ascent-charret.descent;
02728 rect[2]= charret.width;
02729 rect[3]= charret.ascent+charret.descent;
02730 }
02731 else {
02732 rect[0]= *x ;
02733 rect[1]= *y;
02734 rect[2]= 0;
02735 rect[3]= 0;
02736 }
02737 }
02738
02739
02740
02741
02742
02743 void C2F(drawline)(integer *x1, integer *yy1, integer *x2, integer *y2)
02744 {
02745 if (ScilabXgc->Cdrawable != (Drawable) 0)
02746 XDrawLine(dpy, ScilabXgc->Cdrawable, gc,(int) *x1,(int) *yy1,(int) *x2,(int) *y2);
02747 if (ScilabXgc->CurPixmapStatus != 1)
02748 XDrawLine(dpy,(Drawable) ScilabXgc->CWindow, gc,(int) *x1,(int) *yy1,(int) *x2,(int) *y2);
02749 XFlush(dpy);
02750 }
02751
02757 void C2F(drawsegments)(char *str, integer *vx, integer *vy, integer *n, integer *style, integer *iflag, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02758 {
02759 integer verbose=0,Dnarg,Dvalue[10],NDvalue;
02760 integer i;
02761 xget_dash_and_color(&verbose,Dvalue,&Dnarg,vdouble);
02762
02763 if ( (int) *iflag == 1) {
02764 for (i=0 ; i < *n/2 ; i++) {
02765 NDvalue = style[i];
02766 xset_line_style(&NDvalue,PI0,PI0,PI0);
02767 if (ScilabXgc->Cdrawable != (Drawable) 0)
02768 XDrawLine(dpy,ScilabXgc->Cdrawable,gc, (int) vx[2*i],
02769 (int) vy[2*i],(int) vx[2*i+1],(int) vy[2*i+1]) ;
02770 if (ScilabXgc->CurPixmapStatus != 1)
02771 XDrawLine(dpy,(Drawable) ScilabXgc->CWindow,gc, (int) vx[2*i],
02772 (int) vy[2*i],(int) vx[2*i+1],(int) vy[2*i+1]) ;
02773 XFlush(dpy);
02774 }
02775 }
02776 else {
02777 if (*style >= 1)
02778 xset_line_style(style,PI0,PI0,PI0);
02779
02780 for (i=0 ; i < *n/2 ; i++) {
02781 if (ScilabXgc->Cdrawable != (Drawable) 0)
02782 XDrawLine(dpy,ScilabXgc->Cdrawable,gc, (int) vx[2*i],
02783 (int) vy[2*i],(int) vx[2*i+1],(int) vy[2*i+1]) ;
02784 if (ScilabXgc->CurPixmapStatus != 1)
02785 XDrawLine(dpy,(Drawable) ScilabXgc->CWindow,gc, (int) vx[2*i],
02786 (int) vy[2*i],(int) vx[2*i+1],(int) vy[2*i+1]) ;
02787 XFlush(dpy);
02788 }
02789 }
02790
02791 xset_dash_and_color( Dvalue,PI0,PI0,PI0);
02792 }
02793
02794
02795
02796
02797
02798
02799
02800
02801 void C2F(drawarrows)(char *str, integer *vx, integer *vy, integer *n, integer *as, integer *style, integer *iflag, double *dv1, double *dv2, double *dv3, double *dv4)
02802 {
02803 integer verbose=0,Dnarg,Dvalue[10],NDvalue,i;
02804 double cos20=cos(20.0*M_PI/180.0);
02805 double sin20=sin(20.0*M_PI/180.0);
02806 integer polyx[4],polyy[4];
02807 xget_dash_and_color(&verbose,Dvalue,&Dnarg,vdouble);
02808 for (i=0 ; i < *n/2 ; i++)
02809 {
02810 double dx,dy,norm;
02811 NDvalue = ( (int) *iflag == 1) ? style[i] : ((*style >= 1) ? *style : Dvalue[0]);
02812 xset_line_style(&NDvalue,PI0,PI0,PI0);
02813 dx=( vx[2*i+1]-vx[2*i]);
02814 dy=( vy[2*i+1]-vy[2*i]);
02815 norm = sqrt(dx*dx+dy*dy);
02816 if ( Abs(norm) > SMDOUBLE )
02817 { integer nn=1,p=3;
02818 dx=(*as/10.0)*dx/norm;dy=(*as/10.0)*dy/norm;
02819 polyx[0]= polyx[3]=vx[2*i+1];
02820 polyx[1]= inint(polyx[0] - cos20*dx -sin20*dy );
02821 polyx[2]= inint(polyx[0] - cos20*dx + sin20*dy);
02822 polyy[0]= polyy[3]=vy[2*i+1];
02823 polyy[1]= inint(polyy[0] + sin20*dx -cos20*dy) ;
02824 polyy[2]= inint(polyy[0] - sin20*dx - cos20*dy) ;
02825 C2F(fillpolylines)("v",polyx,polyy,&NDvalue,&nn,&p,PI0,PD0,PD0,PD0,PD0);
02826 }
02827 if (ScilabXgc->Cdrawable != (Drawable) 0)
02828 XDrawLine(dpy,ScilabXgc->Cdrawable,gc,(int) vx[2*i],(int)vy[2*i],
02829 (int)(vx[2*i+1]-dx*cos20),(int)(vy[2*i+1]-dy*cos20));
02830 if (ScilabXgc->CurPixmapStatus != 1)
02831 XDrawLine(dpy,(Drawable) ScilabXgc->CWindow,gc,(int) vx[2*i],(int)vy[2*i],
02832 (int)(vx[2*i+1]-dx*cos20),(int)(vy[2*i+1]-dy*cos20));
02833
02834 }
02835 xset_dash_and_color( Dvalue,PI0,PI0,PI0);
02836 XFlush(dpy);
02837 }
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853 void C2F(drawrectangles)(char *str, integer *vects, integer *fillvect, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02854 {
02855 integer i,cpat,verbose=0,num,cd[10];
02856 xget_pattern(&verbose,&cpat,&num,vdouble);
02857 xget_dash_and_color(&verbose,cd,&num,vdouble);
02858 for (i = 0 ; i < *n ; i++)
02859 {
02860 if ( fillvect[i] < 0 )
02861 {
02862 int dash = - fillvect[i];
02863 xset_line_style(&dash,PI0,PI0,PI0);
02864 C2F(drawrectangle)(str,vects+4*i,vects+4*i+1,vects+4*i+2,vects+4*i+3
02865 ,PI0,PI0,PD0,PD0,PD0,PD0);
02866 }
02867 else if ( fillvect[i] == 0 )
02868 {
02869
02870 C2F(drawrectangle)(str,vects+4*i,vects+4*i+1,vects+4*i+2,vects+4*i+3
02871 ,PI0,PI0,PD0,PD0,PD0,PD0);
02872 }
02873 else
02874 {
02875 xset_pattern(&(fillvect[i]),PI0,PI0,PI0);
02876 C2F(fillrectangle)(str,vects+4*i,vects+4*i+1,vects+4*i+2,vects+4*i+3,PI0,PI0,PD0,PD0,PD0,PD0);
02877 }
02878 }
02879 xset_dash_and_color(cd,PI0,PI0,PI0);
02880 }
02881
02884 void C2F(drawrectangle)(char *str, integer *x, integer *y, integer *width, integer *height, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02885 {
02886 if (ScilabXgc->Cdrawable != (Drawable) 0)
02887 XDrawRectangle(dpy, ScilabXgc->Cdrawable, gc, *x, *y, (unsigned)*width,(unsigned)*height);
02888 if (ScilabXgc->CurPixmapStatus != 1)
02889 XDrawRectangle(dpy, (Drawable) ScilabXgc->CWindow, gc, *x, *y, (unsigned)*width,(unsigned)*height);
02890 XFlush(dpy); }
02891
02894 void C2F(fillrectangle)(char *str, integer *x, integer *y, integer *width, integer *height, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02895 {
02896 if (ScilabXgc->Cdrawable != (Drawable) 0)
02897 XFillRectangle(dpy, ScilabXgc->Cdrawable, gc,(int) *x,(int) *y,(unsigned) *width,(unsigned) *height);
02898 if (ScilabXgc->CurPixmapStatus != 1)
02899 XFillRectangle(dpy, (Drawable) ScilabXgc->CWindow, gc,(int) *x,(int) *y,(unsigned) *width,(unsigned) *height);
02900 XFlush(dpy);
02901 }
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911 void fill_grid_rectangles(integer *x, integer *y, double *z, integer n1, integer n2)
02912 {
02913 double zmoy,zmax,zmin,zmaxmin;
02914 integer i,j,verbose=0,whiteid,narg,fill[1],cpat,xz[2];
02915 zmin=Mini(z,(n1)*(n2));
02916 zmax=Maxi(z,(n1)*(n2));
02917 zmaxmin=zmax-zmin;
02918 if (zmaxmin <= SMDOUBLE) zmaxmin=SMDOUBLE;
02919
02920 xget_last(&verbose,&whiteid,&narg,vdouble);
02921 xget_pattern(&verbose,&cpat,&narg,vdouble);
02922 xget_windowdim(&verbose,xz,&narg,vdouble);
02923
02924 for (i = 0 ; i < (n1)-1 ; i++)
02925 for (j = 0 ; j < (n2)-1 ; j++)
02926 {
02927 integer w,h;
02928 zmoy=1/4.0*(z[i+n1*j]+z[i+n1*(j+1)]+z[i+1+n1*j]+z[i+1+n1*(j+1)]);
02929 fill[0]=1 + inint((whiteid-1)*(zmoy-zmin)/(zmaxmin));
02930
02931 xset_pattern(fill,PI0,PI0,PI0);
02932 w=Abs(x[i+1]-x[i]);h=Abs(y[j+1]-y[j]);
02933
02934 if ( w != 0 && h != 0 && x[i] < xz[0] && y[j+1] < xz[1] && x[i]+w > 0 && y[j+1]+h > 0 )
02935 if ( Abs(x[i]) < int16max && Abs(y[j+1]) < int16max && w < uns16max && h < uns16max) {
02936 if (ScilabXgc->Cdrawable != (Drawable) 0)
02937 XFillRectangle(dpy,ScilabXgc->Cdrawable,gc,x[i],y[j+1],w,h);
02938 if (ScilabXgc->CurPixmapStatus != 1)
02939 XFillRectangle(dpy,(Drawable) ScilabXgc->CWindow,gc,x[i],y[j+1],w,h);
02940 }
02941 }
02942 xset_pattern(&cpat,PI0,PI0,PI0);
02943 }
02944
02945
02946
02947
02948
02949
02950
02951
02952
02953
02954
02955 void fill_grid_rectangles1(integer *x, integer *y, double *z, integer n1, integer n2)
02956 {
02957 integer i,j,verbose=0,narg,fill[1],cpat,xz[2];
02958 xget_pattern(&verbose,&cpat,&narg,vdouble);
02959 xget_windowdim(&verbose,xz,&narg,vdouble);
02960 for (i = 0 ; i < (n1)-1 ; i++)
02961 for (j = 0 ; j < (n2)-1 ; j++)
02962 {
02963 integer w,h;
02964 fill[0]= z[i+(n1-1)*j];
02965 xset_pattern(fill,PI0,PI0,PI0);
02966 w=Abs(x[j+1]-x[j]);
02967 h=Abs(y[i+1]-y[i]);
02968
02969 if ( w != 0 && h != 0 && x[j] < xz[0] && y[i] < xz[1] && x[j]+w > 0 && y[i]+h > 0 )
02970 if ( Abs(x[j]) < int16max && Abs(y[i+1]) < int16max && w < uns16max && h < uns16max) {
02971 if (ScilabXgc->Cdrawable != (Drawable) 0)
02972 XFillRectangle(dpy,ScilabXgc->Cdrawable,gc,x[j],y[i],w,h);
02973 if (ScilabXgc->CurPixmapStatus != 1)
02974 XFillRectangle(dpy,(Drawable) ScilabXgc->CWindow,gc,x[j],y[i],w,h);
02975 }
02976 }
02977 xset_pattern(&cpat,PI0,PI0,PI0);
02978 }
02979
02980
02981
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992
02993
02994
02995
02996
02997
02998
02999 void C2F(fillarcs)(char *str, integer *vects, integer *fillvect, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03000 {
03001 integer i,cpat,verb,num;
03002 verb=0;
03003 xget_pattern(&verb,&cpat,&num,vdouble);
03004 for (i=0 ; i< *n ; i++)
03005 {
03006 if (fillvect[i] > ScilabXgc->IDLastPattern + 1)
03007 {
03008 xset_pattern(&(cpat),PI0,PI0,PI0);
03009 C2F(drawarc)(str,vects+6*i,vects+6*i+1,
03010 vects+6*i+2,vects+6*i+3,
03011 vects+6*i+4,vects+6*i+5,PD0,PD0,PD0,PD0);
03012 }
03013 else
03014 {
03015 xset_pattern(&(fillvect[i]),PI0,PI0,PI0);
03016 C2F(fillarc)(str,vects+6*i,vects+6*i+1,
03017 vects+6*i+2,vects+6*i+3,
03018 vects+6*i+4,vects+6*i+5,PD0,PD0,PD0,PD0);
03019 }
03020 }
03021 xset_pattern(&(cpat),PI0,PI0,PI0);
03022 }
03023
03024
03025
03026
03027
03028
03029
03030
03031
03032
03033
03034 void C2F(drawarcs)(char *str, integer *vects, integer *style, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03035 {
03036 integer verbose=0,Dnarg,Dvalue[10],NDvalue,i;
03037
03038 xget_dash_and_color(&verbose,Dvalue,&Dnarg,vdouble);
03039 for (i=0 ; i< *n ; i++)
03040 {
03041 NDvalue = style[i];
03042 xset_line_style(&NDvalue,PI0,PI0,PI0);
03043 C2F(drawarc)(str,vects+6*i,vects+6*i+1,
03044 vects+6*i+2,vects+6*i+3,
03045 vects+6*i+4,vects+6*i+5,PD0,PD0,PD0,PD0);
03046 }
03047 xset_dash_and_color( Dvalue,PI0,PI0,PI0);
03048 }
03049
03052 void C2F(drawarc)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dv1, double *dv2, double *dv3, double *dv4)
03053 {
03054 if (ScilabXgc->Cdrawable != (Drawable) 0)
03055 XDrawArc(dpy, ScilabXgc->Cdrawable, gc, *x, *y,(unsigned)*width,
03056 (unsigned)*height,*angle1, *angle2);
03057 if (ScilabXgc->CurPixmapStatus != 1)
03058 XDrawArc(dpy, (Drawable) ScilabXgc->CWindow, gc, *x, *y,(unsigned)*width,
03059 (unsigned)*height,*angle1, *angle2);
03060 XFlush(dpy); }
03061
03064 void C2F(fillarc)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dv1, double *dv2, double *dv3, double *dv4)
03065 {
03066 if (ScilabXgc->Cdrawable != (Drawable) 0)
03067 XFillArc(dpy, ScilabXgc->Cdrawable, gc, *x, *y, *width, *height, *angle1, *angle2);
03068 if (ScilabXgc->CurPixmapStatus != 1)
03069 XFillArc(dpy, (Drawable) ScilabXgc->CWindow, gc, *x, *y, *width, *height, *angle1, *angle2);
03070 XFlush(dpy);}
03071
03072
03073
03074
03075
03076
03077
03078
03079
03080
03081
03082
03083 void C2F(drawpolylines)(char *str, integer *vectsx, integer *vectsy, integer *drawvect, integer *n, integer *p, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03084 { integer verbose=0 ,symb[2],Mnarg,Dnarg,Dvalue[10],NDvalue,i,close;
03085
03086 xget_mark(&verbose,symb,&Mnarg,vdouble);
03087 xget_dash_and_color(&verbose,Dvalue,&Dnarg,vdouble);
03088 for (i=0 ; i< *n ; i++)
03089 {
03090 if (drawvect[i] <= 0)
03091 {
03092 NDvalue = - drawvect[i];
03093 xset_mark(&NDvalue,symb+1,PI0,PI0);
03094 xset_pattern(Dvalue+6,PI0,PI0,PI0);
03095
03096 C2F(drawpolymark)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
03097 }
03098 else
03099 {
03100 xset_line_style(drawvect+i,PI0,PI0,PI0);
03101 close = 0;
03102 C2F(drawClippedPolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,&close,
03103 PI0,PI0,PD0,PD0,PD0,PD0);
03104 }
03105 }
03107 xset_dash_and_color( Dvalue,PI0,PI0,PI0);
03108 xset_mark(symb,symb+1,PI0,PI0);
03109 }
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122 void C2F(fillpolylines)(char *str, integer *vectsx, integer *vectsy, integer *fillvect, integer *n, integer *p, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03123 {
03124 integer Dnarg,Dvalue[10];
03125 integer i,cpat,verbose=0,num,close=1,pattern;
03126 xget_pattern(&verbose,&cpat,&num,vdouble);
03127 xget_dash_and_color(&verbose,Dvalue,&Dnarg,vdouble);
03128 for (i = 0 ; i< *n ; i++)
03129 {
03130 if (fillvect[i] > 0 )
03131 {
03133 xset_pattern(&(fillvect[i]),PI0,PI0,PI0);
03134 C2F(fillpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=1,&close),
03135 PI0,PI0,PD0,PD0,PD0,PD0);
03136 xset_line_style(Dvalue,PI0,PI0,PI0);
03137 xset_pattern(&cpat,PI0,PI0,PI0);
03138 C2F(drawClippedPolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=1,&close)
03139 ,PI0,PI0,PD0,PD0,PD0,PD0);
03140 }
03141 else if (fillvect[i] == 0 )
03142 {
03144 xset_line_style(Dvalue,PI0,PI0,PI0);
03145 xset_pattern(&cpat,PI0,PI0,PI0);
03146 C2F(drawClippedPolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=1,&close)
03147 ,PI0,PI0,PD0,PD0,PD0,PD0);
03148 }
03149 else
03150 {
03152 pattern = -fillvect[i] ;
03153 xset_pattern(&pattern,PI0,PI0,PI0);
03154 C2F(fillpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=1,&close)
03155 ,PI0,PI0,PD0,PD0,PD0,PD0);
03156 xset_pattern(&(cpat),PI0,PI0,PI0);
03157 }
03158 }
03159 xset_dash_and_color(Dvalue,PI0,PI0,PI0);
03160 }
03161
03162 static void C2F(analyze_points)(integer n, integer *vx, integer *vy, integer onemore) ;
03163
03164
03165
03166
03167
03168
03169
03170 void C2F(drawClippedPolyline)(char *str, integer *n, integer *vx, integer *vy, integer *closeflag, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03171 {
03172 integer n1;
03173 if ( *closeflag )
03174 {
03175 n1 = *n+1 ;
03176 }
03177 else
03178 {
03179 n1= *n ;
03180 }
03181 if (n1 >= 2)
03182 {
03183 C2F(analyze_points)(*n, vx, vy,*closeflag);
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193
03194 }
03195 }
03196
03197
03198
03199
03200
03201
03202
03203
03204 void C2F(drawpolyline)(char *str, integer *n, integer *vx, integer *vy, integer *closeflag, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03205 {
03206 integer n1;
03207 if ( *closeflag )
03208 {
03209 n1 = *n+1 ;
03210 }
03211 else
03212 {
03213 n1= *n ;
03214 }
03215 if (n1 >= 2)
03216 {
03217
03218
03219 if (C2F(store_points)(*n, vx, vy,*closeflag))
03220 {
03221
03222 XDroutine( n1 ) ;
03223
03224 XFlush(dpy);
03225 }
03226
03227 }
03228 }
03229
03230
03231
03232
03233
03234
03235 void C2F(fillpolyline)(char *str, integer *n, integer *vx, integer *vy, integer *closeflag, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03236 {
03237 integer n1;
03238 if (*closeflag == 1) n1 = *n+1;else n1= *n;
03239 if (C2F(store_points)(*n, vx, vy,*closeflag)){
03240 if (ScilabXgc->Cdrawable != (Drawable) 0)
03241 XFillPolygon (dpy, ScilabXgc->Cdrawable, gc, get_xpoints(), n1,
03242 Complex, ScilabXgc->CurVectorStyle);
03243 if (ScilabXgc->CurPixmapStatus != 1)
03244 XFillPolygon (dpy, (Drawable) ScilabXgc->CWindow, gc, get_xpoints(), n1,
03245 Complex, ScilabXgc->CurVectorStyle);
03246 }
03247 XFlush(dpy);
03248 }
03249
03250
03251
03252
03253
03254
03255 void C2F(drawpolymark)(char *str, integer *n, integer *vx, integer *vy, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03256 {
03257 if ( ScilabXgc->CurHardSymb == 0 )
03258 {if (C2F(store_points)(*n, vx, vy,(integer)0L)){
03259 if (ScilabXgc->Cdrawable != (Drawable) 0)
03260 XDrawPoints (dpy, ScilabXgc->Cdrawable, gc, get_xpoints(), *n,CoordModeOrigin);
03261 if (ScilabXgc->CurPixmapStatus != 1)
03262 XDrawPoints (dpy, (Drawable) ScilabXgc->CWindow, gc, get_xpoints(), *n,CoordModeOrigin);
03263 }
03264 XFlush(dpy);
03265 }
03266 else
03267 {
03268 integer i,keepid,keepsize,hds;
03269 i=1;
03270 keepid = ScilabXgc->FontId;
03271 keepsize= ScilabXgc->FontSize;
03272 hds= ScilabXgc->CurHardSymbSize;
03273 xset_font(&i,&hds,PI0,PI0);
03274 for ( i=0; i< *n ;i++) DrawMark(vx+i,vy+i);
03275 xset_font(&keepid,&keepsize,PI0,PI0);
03276 }
03277 }
03278
03279
03280
03281
03282
03283
03284
03285
03286
03287
03288
03289 struct BCG *AddNewWindowToList(void) ;
03290
03291
03292 struct BCG *AddNewWindowToList(void)
03293 {
03294 struct BCG * newWin = addWindowItem() ;
03295
03296 if ( newWin == NULL ) { return NULL; }
03297
03298
03299 newWin->CWindow = (Window) NULL;
03300 newWin->CBGWindow = (Window) NULL;
03301 newWin->Cdrawable = (Drawable) NULL;
03302 newWin->CinfoW = (Widget) NULL ;
03303 newWin->Viewport = (Widget) NULL ;
03304 newWin->popup = (Widget)0;
03305 newWin->CurWindow = 0;
03306 newWin->Red = (float *) 0;
03307 newWin->Green = (float *) 0;
03308 newWin->Blue = (float *) 0;
03309 newWin->Colors = (Pixel *) 0;
03310 newWin->Cmap = (Colormap) 0 ;
03311 newWin->CmapFlag = 1;
03312 newWin->Cdrawable_flag = 0;
03313 newWin->EventHandler[0] = '\0';
03314
03315 return newWin ;
03316
03317 }
03318
03319
03320
03321
03322
03323
03324
03325
03326
03327
03328
03329
03330 void DeleteWindowToList(integer num)
03331 {
03332 Widget popup = NULL ;
03333 struct BCG * window = getWindowXgcNumber( num ) ;
03334
03335 if ( window == NULL ) { return ; }
03336
03337 popup = XtWindowToWidget(dpy,window->CBGWindow);
03338 XtDestroyWidget( popup ) ;
03339 XgcFreeColors( window ) ;
03340
03341 removeWindowItem( window ) ;
03342
03343 }
03344
03345
03346
03347
03348 void DeleteSGWin(integer intnum)
03349 {
03350 int curwin;
03351 if ( ScilabXgc == NULL ) { return ; }
03352
03353 curwin = ScilabXgc->CurWindow ;
03354 DeleteWindowToList(intnum);
03355
03356 del_window_scale(intnum);
03357 if ( curwin == intnum )
03358 {
03359 if ( isWindowListEmpty() )
03360 {
03362 ScilabXgc = NULL ;
03363 }
03364 else
03365 {
03367 ScilabXgc = getFirstWindow() ;
03368 ResetScilabXgc ();
03369 get_window_scale(ScilabXgc->CurWindow,NULL);
03370 }
03371 }
03372 }
03373
03374
03375
03376
03377
03378
03379 Window GetWindowNumber(int wincount)
03380 {
03381 struct BCG *bcg;
03382 bcg = getWindowXgcNumber(wincount);
03383 if ( bcg != (struct BCG *) 0)
03384 return( bcg->CWindow);
03385 else
03386 return( (Window) 0);
03387 }
03388
03389
03390
03391
03392
03393
03394 static struct BCG *GetWinXgc __PARAMS((WindowList *,integer));
03395
03396 static struct BCG *GetWinXgc(WindowList *listptr, integer i)
03397 {
03398 if (listptr == (WindowList *) NULL)
03399 {
03400 return NULL ;
03401 }
03402 else
03403 {
03404 if ((listptr->winxgc.CurWindow) == i)
03405 {
03406 return( &(listptr->winxgc));
03407 }
03408 else
03409 {
03410 return(GetWinXgc((WindowList *) listptr->next,i));
03411 }
03412 }
03413 }
03414
03415
03416
03417
03418
03419 Window GetBGWindowNumber(int wincount)
03420 {
03421 struct BCG *bcg;
03422 bcg = getWindowXgcNumber(wincount);
03423 if ( bcg != (struct BCG *) 0)
03424 return( bcg->CBGWindow);
03425 else
03426 return( (Window) 0);
03427 }
03428
03429 int GetEventWindow(XEvent* event)
03430 {
03431 WindowList *listptr = getScilabWindowList() ;
03432
03433 while ( listptr != (WindowList *) 0 ) {
03434 if (event->xbutton.window == listptr->winxgc.CWindow)
03435 return(listptr->winxgc.CurWindow);
03436 listptr = (WindowList *)listptr->next;
03437 }
03438 return(-1);
03439
03440 }
03441
03442
03443
03444
03445
03446 #define MAXERRMSGLEN 512
03447
03448 static int X_error_handler(Display *d, XErrorEvent *err_ev)
03449 {
03450 char err_msg[MAXERRMSGLEN];
03451
03452 XGetErrorText(dpy, (int) (err_ev->error_code), err_msg, MAXERRMSGLEN - 1);
03453 #ifndef NDEBUG
03454 printf("Scilab : X error trapped - error message follows:\r\n%s\r\n", err_msg);
03455 #endif
03456 return(0);
03457 }
03458
03459
03460
03461
03462
03463
03464
03465
03466 void C2F(initgraphic)(char *string, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03467 {
03468 XWindowAttributes war;
03469 struct BCG *NewXgc ;
03470 static integer EntryCounter = 0;
03471 integer WinNum;
03472
03473 #ifdef WITH_TK
03474 integer ne=11, menutyp=2, ierr;
03475 char *EditMenusE[]={"Select figure as current","Redraw figure","Erase figure","Copy object","Paste object","Move object","Delete object","Figure properties","Current axes properties","Start entity picker","Stop entity picker"};
03476
03477
03478 integer ni=6;
03479 char *InsertMenusE[]={"Line","Polyline","Arrow","Text","Rectangle","Circle"};
03480
03481 #else
03482 integer ne=3, menutyp=2, ierr;
03483 char *EditMenusE[]={"Select as current","Redraw figure","Erase figure"};
03484 #endif
03485
03486 GC XCreateGC(Display *, Drawable, long unsigned int, XGCValues *);
03487 static int screen;
03488 static XGCValues gcvalues;
03489 static Widget toplevel = (Widget) NULL;
03490 *v3=0;
03491 if ( v2 != (integer *) NULL && *v2 != -1 )
03492 WinNum= *v2;
03493 else
03494 WinNum= EntryCounter;
03495 if (EntryCounter == 0)
03496 {
03498 DisplayInit(string,&dpy,&toplevel);
03499 screen =DefaultScreen(dpy);
03500 root = XRootWindow (dpy,screen);
03501 depth = XDefaultDepth (dpy,screen);
03502 maxcol = 1 << depth;
03503 visual = XDefaultVisual(dpy,screen);
03504 wpixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
03505 bpixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
03506 LoadFonts();
03507 crosscursor = XCreateFontCursor(dpy, XC_crosshair);
03508 arrowcursor = XCreateFontCursor (dpy, (char)0x2e);
03509 normalcursor = XCreateFontCursor (dpy, XC_X_cursor);
03510 }
03511
03512 NewXgc = AddNewWindowToList();
03513 if ( NewXgc == (struct BCG *) 0)
03514 {
03515 sciprint("initgraphics: unable to alloc\n");
03516 return;
03517 }
03518 else
03519 {
03520 ScilabXgc= NewXgc;
03521 }
03522
03523 #ifdef WITH_TK
03524 if (IsTKGraphicalMode()) {
03525 Tk_Window win;
03526
03527
03528 if (TKmainWindow != (Tk_Window)0) {
03529 win = Tk_NameToWindow(TCLinterp, string, (Tk_Window) TKmainWindow);
03530 if (win != (Tk_Window)0) {
03531 ScilabXgc->CWindow=Tk_WindowId(win);
03532 ScilabXgc->CBGWindow=(Window)0;
03533 ScilabXgc->popup=(Widget)0;
03534
03535
03536
03537 }
03538 }
03539 }
03540 else
03541 #endif
03542 CreatePopupWindow(WinNum,toplevel,ScilabXgc,&DefaultForeground,&DefaultBackground) ;
03543
03544
03545
03546 if (EntryCounter == 0)
03547 {
03549 C2F(CreatePatterns)(DefaultBackground,DefaultForeground);
03550 }
03551 XGetWindowAttributes(dpy,ScilabXgc->CWindow,&war);
03552 ScilabXgc->CWindowWidth = war.width;
03553 ScilabXgc->CWindowHeight = war.height;
03554
03555
03556
03558 ScilabXgc->CurPixmapStatus = 0;
03559 ScilabXgc->CurResizeStatus = 1;
03560 ScilabXgc->CurWindow = WinNum;
03561 if (EntryCounter == 0)
03562 {
03563
03564 gcvalues.foreground = DefaultForeground;
03565 gcvalues.background = DefaultBackground;
03566 gcvalues.function = GXcopy ;
03567 gcvalues.line_width = 1;
03568 gc = XCreateGC(dpy, ScilabXgc->CWindow, GCFunction | GCForeground
03569 | GCBackground | GCLineWidth, &gcvalues);
03570 XSetWindowColormap(dpy,ScilabXgc->CBGWindow,
03571 XDefaultColormap(dpy,XDefaultScreen(dpy)));
03572 XSetErrorHandler(X_error_handler);
03573 XSetIOErrorHandler((XIOErrorHandler) X_error_handler);
03574 }
03575 InitMissileXgc(PI0,PI0,PI0,PI0);
03576
03577
03578 EntryCounter=Max(EntryCounter,WinNum);
03579 EntryCounter++;
03580 #ifdef WITH_TK
03581 if (!IsTKGraphicalMode())
03582 {
03583
03584 AddMenu(&WinNum,"Edit", EditMenusE, &ne, &menutyp, "ged", &ierr);
03585 AddMenu(&WinNum,"Insert", InsertMenusE, &ni, &menutyp, "ged_insert", &ierr);
03586
03587
03588 refreshMenus( ScilabXgc ) ;
03589 }
03590 #endif
03591 XSync(dpy,0);
03592
03593 }
03594
03595
03596
03597 void C2F(xinfo)(char *message, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
03598 {
03599 Arg args[1];
03600 if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->CinfoW != (Widget) NULL)
03601 {
03602 Cardinal n = 0;
03603 XtSetArg(args[n], XtNlabel, message);n++;
03604 XtSetValues(ScilabXgc->CinfoW, args, n);
03605 }
03606 }
03607
03608
03609
03610
03611
03612 #ifdef __STDC__
03613 #include <stdarg.h>
03614 #else
03615 #include <varargs.h>
03616 #endif
03617
03618 #define MAXPRINTF 512
03619
03620 #ifdef __STDC__
03621 void wininfo(char *format,...)
03622 #else
03623 void wininfo(va_alist) va_dcl
03624 #endif
03625 {
03626
03627 Arg args[1];
03628 va_list ap;
03629 char buf[MAXPRINTF];
03630 #ifdef __STDC__
03631 va_start(ap,format);
03632 #else
03633 char *format;
03634 va_start(ap);
03635 format = va_arg(ap, char *);
03636 #endif
03637 (void ) vsprintf(buf, format, ap );
03638 va_end(ap);
03639 if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->CinfoW != (Widget) NULL)
03640 {
03641 Cardinal n = 0;
03642 XtSetArg(args[n], XtNlabel,buf);n++;
03643 XtSetValues(ScilabXgc->CinfoW, args, n);
03644 }
03645 }
03646
03647
03648
03649
03650
03651
03652 Atom NewGraphWindowMessageAtom;
03653
03654 void SendScilab(Window local, integer winnum)
03655 {
03656 XClientMessageEvent ev;
03657 ev.type = ClientMessage;
03658 ev.window = local ;
03659 ev.message_type =NewGraphWindowMessageAtom;
03660 ev.format = 32;
03661 ev.data.l[0] = winnum;
03662 XSendEvent (dpy, local, False, (integer)0L, (XEvent *) &ev);
03663 XFlush(dpy);
03664 }
03665
03666
03667
03668
03669
03670 #define DbugInfo0(x)
03671 #define DbugInfo1(x,y)
03672 #define DbugInfo3(x,y,z,t)
03673 static int CheckWin(Window w);
03674
03675 Window Window_With_Name(Window top, char *name, int j, char *ResList0, char *ResList1, char *ResList2)
03676 {
03677 Status status;
03678 Window *children,root1,parent1,w=0;
03679 unsigned int nchildren=0;
03680 integer i;
03681 char *window_name;
03682 if ( CheckWin(top)==0) return((Window) 0);
03683 status=XQueryTree(dpy, top, &root1, &parent1, &children, &nchildren);
03684 DbugInfo1(" Status %d\n",status);
03685 if ( status == 0)
03686 {
03687 DbugInfo0("XQuery Tree failed \n");
03688 return((Window) 0);
03689 }
03690 if ( nchildren == 0 ) return((Window) 0);
03691 DbugInfo1("Number of children %d \n",nchildren);
03692 for (i= (int) nchildren-1; i >= 0 ; i--)
03693 {
03694 if ( CheckWin(children[i])!=0)
03695 {
03696 XFetchName(dpy, children[i], &window_name);
03697 DbugInfo3("Child [%d] %s %d\n",children[i],window_name,j);
03698 if ( window_name != 0 && strcmp(window_name, name)==0 )
03699 {
03700 w=children[i];
03701 DbugInfo1("Found %s \n",window_name);
03702 DbugInfo1("Level %d\n",j);
03703 XFree((char *) children);
03704 if (window_name) XFree(window_name);
03705 break;
03706 }
03707 else
03708 {
03709 w=Window_With_Name(children[i],name,j+1,
03710 ResList0,ResList1,ResList2);
03711 if ( w != 0 )
03712 {
03713 XFree((char *) children);
03714 DbugInfo1("father was %s\n",window_name);
03715 if (window_name) XFree(window_name);
03716 break;
03717 }
03718 }
03719 if (window_name) XFree(window_name);
03720 }
03721 }
03722 return((Window) w);
03723 }
03724
03725 static char *ResList[]={ SCI_VERSION_STRING,"BG","ScilabGraphic"};
03726
03727 Window Find_X_Scilab(void)
03728 {
03729 Window w;
03730 DbugInfo1("Searching %s\n",SCI_VERSION_STRING);
03731 w=Window_With_Name(RootWindow(dpy,DefaultScreen(dpy)),
03732 SCI_VERSION_STRING,0,ResList[0],ResList[0],ResList[0]);
03733 return(w);
03734 }
03735
03736 #define STR0 "ScilabGraphic%d"
03737
03738 Window Find_ScilabGraphic_Window(integer i)
03739 {
03740 Window w;
03741 char wname[sizeof(STR0)+4];
03742 sprintf(wname,STR0,(int) i);
03743 DbugInfo1("Searching %s\n",wname);
03744 w=Window_With_Name(RootWindow(dpy,DefaultScreen(dpy)),wname,0,
03745 ResList[2],ResList[2],ResList[2]);
03746 return(w);
03747 }
03748
03749 #define STR1 "BG%d"
03750
03751 Window Find_BG_Window(integer i)
03752 {
03753 char wname[sizeof(STR1)+4];
03754 Window w;
03755 sprintf(wname,STR1,(int) i);
03756 DbugInfo1("Searching %s\n",wname);
03757 w=Window_With_Name(RootWindow(dpy,DefaultScreen(dpy)),wname,0,
03758 ResList[1],ResList[2],ResList[2]);
03759 return(w);
03760 }
03761
03762
03763 #define STR2 "objfigure1"
03764
03765
03766
03767
03768
03769
03770
03771
03772
03773
03774
03775
03776
03777
03778
03779
03780
03781
03782
03783
03784
03785 #include <setjmp.h>
03786
03787 static jmp_buf my_env;
03788
03789 static void Ignore_Err(Display *d, XErrorEvent *err_ev)
03790 {
03791 DbugInfo0("Ignoring Error");
03792 longjmp(my_env,1);
03793 }
03794
03795 static int
03796 CheckWin(Window w)
03797 {
03798 Window root_ret;
03799 int x, y;
03800 unsigned width= -1, height= -1, bw, idepth;
03801 int (*curh)();
03802 curh=XSetErrorHandler((XErrorHandler) Ignore_Err);
03803 if ( setjmp(my_env))
03804 {
03806 XSetErrorHandler((XErrorHandler) curh);
03807 return(0);
03808 }
03809 else
03810 {
03811 XGetGeometry (dpy, w, &root_ret, &x, &y, &width, &height, &bw, &idepth);
03812 XSync (dpy, 0);
03813 XSetErrorHandler((XErrorHandler) curh);
03814 return(1);}
03815 }
03816
03817
03818
03819
03820
03821
03822 static void
03823 InitMissileXgc (integer *v1, integer *v2, integer *v3, integer *v4)
03824 {
03825 integer i,j;
03826 ScilabXgc->IDLastPattern = GREYNUMBER - 1;
03827 ScilabXgc->CurLineWidth = 0 ;
03828 ScilabXgc->CurDashStyle = 0 ;
03829 i=1;
03830 xset_thickness(&i,PI0,PI0,PI0);
03832 i=j= -1;
03833 xset_unclip(PI0,PI0,PI0,PI0);
03834 ScilabXgc->ClipRegionSet= 0;
03835 xset_font((i=2,&i),(j=1,&j),PI0,PI0);
03836 xset_mark((i=0,&i),(j=0,&j),PI0,PI0);
03837 ScilabXgc->CurResizeStatus = 1 ;
03839 i= CoordModeOrigin;
03840 xset_absourel(&i,PI0,PI0,PI0);
03841
03842 ScilabXgc->CurColorStatus = 0;
03843 xset_pattern((i=1,&i),PI0,PI0,PI0);
03844 xset_dash((i=1,&i),PI0,PI0,PI0);
03845 xset_hidden3d((i=1,&i),PI0,PI0,PI0);
03846
03847 ScilabXgc->CurColorStatus = 1;
03848 set_default_colormap();
03849 xset_alufunction1((i=3,&i),PI0,PI0,PI0);
03850 xset_pixmapOn((i=0,&i),PI0,PI0,PI0);
03851
03852 xset_pattern((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
03853
03854 xset_foreground((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
03855 xset_background((i=ScilabXgc->NumForeground+2,&i),PI0,PI0,PI0);
03856 xset_hidden3d((i=4,&i),PI0,PI0,PI0);
03857
03858 getcolordef(&i);
03862 ScilabXgc->mafigure = (sciPointObj *)NULL;
03863
03864 ScilabXgc->CurColorStatus = (i == 1) ? 0: 1;
03865 xset_usecolor(&i ,PI0,PI0,PI0);
03866 strcpy(ScilabXgc->CurNumberDispFormat,"%-5.2g");
03868 Cscale2default();
03869 }
03870
03871
03872
03873
03874
03875
03876
03877 static void ResetScilabXgc (void)
03878 {
03879 integer i,j, clip[4];
03880 i= ScilabXgc->FontId;
03881 j= ScilabXgc->FontSize;
03882 xset_font(&i,&j,PI0,PI0);
03883
03884 i= ScilabXgc->CurHardSymb;
03885 j= ScilabXgc->CurHardSymbSize;
03886 xset_mark(&i,&j,PI0,PI0);
03887
03888 i= ScilabXgc->CurLineWidth;
03889 xset_thickness(&i,PI0,PI0,PI0);
03890
03891 i= ScilabXgc->CurVectorStyle;
03892 xset_absourel(&i,PI0,PI0,PI0);
03893
03894 i= ScilabXgc->CurDrawFunction;
03895 xset_alufunction1(&i,PI0,PI0,PI0);
03896
03897 if (ScilabXgc->ClipRegionSet == 1)
03898 {
03899 for ( i= 0 ; i < 4; i++) clip[i]=ScilabXgc->CurClipRegion[i];
03900 xset_clip(clip,clip+1,clip+2,clip+3);
03901 }
03902 else
03903 xset_unclip(PI0,PI0,PI0,PI0);
03904
03905 if (ScilabXgc->CurColorStatus == 0)
03906 {
03907
03908 ScilabXgc->CurColorStatus = 1;
03909 xset_pattern((i=DefaultForeground,&i),PI0,PI0,PI0);
03910
03911 ScilabXgc->CurColorStatus = 0;
03912 i= ScilabXgc->CurPattern + 1;
03913 xset_pattern(&i,PI0,PI0,PI0);
03914 i= ScilabXgc->CurDashStyle + 1;
03915 xset_dash(&i,PI0,PI0,PI0);
03916 i= ScilabXgc->NumHidden3d+1;
03917 xset_hidden3d(&i,PI0,PI0,PI0);
03918 }
03919 else
03920 {
03921
03922
03923 ScilabXgc->CurColorStatus = 0;
03924 xset_pattern((i=1,&i),PI0,PI0,PI0);
03925 xset_dash((i=1,&i),PI0,PI0,PI0);
03926
03927 ScilabXgc->CurColorStatus = 1;
03928 i= ScilabXgc->CurColor + 1;
03929 xset_pattern(&i,PI0,PI0,PI0);
03930 i= ScilabXgc->NumBackground+1;
03931 xset_background(&i,PI0,PI0,PI0);
03932 i= ScilabXgc->NumForeground+1;
03933 xset_foreground(&i,PI0,PI0,PI0);
03934 i= ScilabXgc->NumHidden3d+1;
03935 xset_hidden3d(&i,PI0,PI0,PI0);
03936 }
03937 }
03938
03939
03940
03941
03942
03943
03944
03945
03946
03947
03948
03949
03950
03951
03952
03953
03954
03955
03956
03957
03958
03959
03960 void C2F(drawaxis)(char *str, integer *alpha, integer *nsteps, integer *v2, integer *initpoint, integer *v6, integer *v7, double *size, double *dx2, double *dx3, double *dx4)
03961 { integer i;
03962 double xi,yi,xf,yf;
03963 double cosal,sinal;
03964 cosal= cos( (double)M_PI * (*alpha)/180.0);
03965 sinal= sin( (double)M_PI * (*alpha)/180.0);
03966 for (i=0; i <= nsteps[0]*nsteps[1]; i++)
03967 {
03968 if (( i % nsteps[0]) != 0)
03969 {
03970 xi = initpoint[0]+i*size[0]*cosal;
03971 yi = initpoint[1]+i*size[0]*sinal;
03972 xf = xi - ( size[1]*sinal);
03973 yf = yi + ( size[1]*cosal);
03974 if (ScilabXgc->Cdrawable != (Drawable) 0)
03975 XDrawLine(dpy,ScilabXgc->Cdrawable,gc,inint(xi),inint(yi),inint(xf),inint(yf));
03976 if (ScilabXgc->CurPixmapStatus != 1)
03977 XDrawLine(dpy,(Drawable) ScilabXgc->CWindow,gc,inint(xi),inint(yi),inint(xf),inint(yf));
03978 }
03979 }
03980 for (i=0; i <= nsteps[1]; i++)
03981 { xi = initpoint[0]+i*nsteps[0]*size[0]*cosal;
03982 yi = initpoint[1]+i*nsteps[0]*size[0]*sinal;
03983 xf = xi - ( size[1]*size[2]*sinal);
03984 yf = yi + ( size[1]*size[2]*cosal);
03985 if (ScilabXgc->Cdrawable != (Drawable) 0)
03986 XDrawLine(dpy,ScilabXgc->Cdrawable,gc,inint(xi),inint(yi),inint(xf),inint(yf));
03987 if (ScilabXgc->CurPixmapStatus != 1)
03988 XDrawLine(dpy,(Drawable) ScilabXgc->CWindow,gc,inint(xi),inint(yi),inint(xf),inint(yf));
03989 }
03990
03991 XFlush(dpy);
03992 }
03993
03994
03998 void C2F(getFontMaxSize)(char *str, integer * sizeMin, integer *sizeMax, integer *v1, integer *v2, integer *v3, integer *v4, double *dx1, double *dx2, double *dx3, double *dx4)
03999 {
04000 *sizeMin = 0 ;
04001 *sizeMax = FONTMAXSIZE ;
04002 }
04003
04004
04005
04006
04007
04008
04009
04010
04011 void C2F(displaynumbers)(char *str, integer *x, integer *y, integer *v1, integer *v2, integer *n, integer *flag, double *z, double *alpha, double *dx3, double *dx4)
04012 { integer i ;
04013 char buf[20];
04014 for (i=0 ; i< *n ; i++)
04015 { sprintf(buf,ScilabXgc->CurNumberDispFormat,z[i]);
04016 C2F(displaystring)(buf,&(x[i]),&(y[i]),PI0,flag,PI0,PI0,&(alpha[i]),PD0,PD0,PD0) ;
04017 }
04018 XFlush(dpy);
04019 }
04020
04021 void C2F(bitmap)(char *string, integer w, integer h)
04022 {
04023 static XImage *setimage;
04024 setimage = XCreateImage (dpy, XDefaultVisual (dpy, DefaultScreen(dpy)),
04025 1, XYBitmap, 0, string,w,h, 8, 0);
04026 setimage->data = string;
04027 if (ScilabXgc->Cdrawable != (Drawable) 0)
04028 XPutImage (dpy, ScilabXgc->Cdrawable, gc, setimage, 0, 0, 10,10,w,h);
04029 if (ScilabXgc->CurPixmapStatus != 1)
04030 XPutImage (dpy, (Drawable) ScilabXgc->CWindow, gc, setimage, 0, 0, 10,10,w,h);
04031
04032 XDestroyImage(setimage);
04033 }
04034
04035
04036
04037
04038
04039
04040
04041
04042
04043
04044
04045
04046 struct FontInfo { integer ok;
04047 char fname[100];
04048 } FontInfoTab_[FONTNUMBER];
04049
04052 static char *size_[] = { "08" ,"10","12","14","18","24"};
04053 static int i_size_[] = { 8 ,10,12,14,18,24};
04054
04055
04056
04057
04058
04059
04060 typedef struct {
04061 char *alias;
04062 char *name;
04063 } FontAlias;
04064
04065
04066
04067 FontAlias fonttab[] ={
04068 {"CourR", "-adobe-courier-medium-r-normal--*-%s0-*-*-m-*-iso8859-1"},
04069 {"Symb", "-adobe-symbol-medium-r-normal--*-%s0-*-*-p-*-adobe-fontspecific"},
04070 {"TimR", "-adobe-times-medium-r-normal--*-%s0-*-*-p-*-iso8859-1"},
04071 {"TimI", "-adobe-times-medium-i-normal--*-%s0-*-*-p-*-iso8859-1"},
04072 {"TimB", "-adobe-times-bold-r-normal--*-%s0-*-*-p-*-iso8859-1"},
04073 {"TimBI", "-adobe-times-bold-i-normal--*-%s0-*-*-p-*-iso8859-1"},
04074 {"HelvR", "-adobe-helvetica-medium-r-normal--*-%s0-*-*-p-*-iso8859-1"},
04075 {"HelvO", "-adobe-helvetica-medium-o-normal--*-%s0-*-*-p-*-iso8859-1"},
04076 {"HelvB", "-adobe-helvetica-bold-r-normal--*-%s0-*-*-p-*-iso8859-1"},
04077 {"HelvBO", "-adobe-helvetica-bold-o-normal--*-%s0-*-*-p-*-iso8859-1"},
04078 {(char *) NULL,( char *) NULL}
04079 };
04080
04081 int fontidscale(int fontsize)
04082 {
04083 int Nsiz;
04084 int i;
04085 int isiz = i_size_[fontsize];
04086 double d = Min(ScilabXgc->CWindowHeight,ScilabXgc->CWindowWidth);
04087
04088 Nsiz = (ScilabXgc != NULL) ? inint((isiz*d/400.0)) : isiz;
04089 fprintf(stderr,"Scaling by -->%d %d \n",isiz,Nsiz);
04090 for ( i=0; i < FONTMAXSIZE ; i++)
04091 {
04092 if (i_size_[i] >= Nsiz ) return Max(i-1,0);
04093 }
04094 return FONTMAXSIZE -1;
04095 }
04096
04097 static void xset_font(integer *fontid, integer *fontsize, integer *v3, integer *v4)
04098 {
04099 integer i,fsiz,fsiz_sca;
04100 i = Min(FONTNUMBER-1,Max(*fontid,0));
04101 fsiz = Min(FONTMAXSIZE-1,Max(*fontsize,0));
04102 fsiz_sca = fsiz ;
04103 if ( FontInfoTab_[i].ok !=1 )
04104 {
04105 if (i != FONTNUMBER-1 )
04106 {
04107 C2F(loadfamily)(fonttab[i].alias,&i,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
04108 }
04109 else
04110 {
04111 sciprint(" The Font Id %d is not affected \r\n",(int)i);
04112 sciprint(" use xlfont to set it \n");
04113 return;
04114 }
04115 }
04116 ScilabXgc->FontId = i;
04117 ScilabXgc->FontSize = fsiz;
04118 ScilabXgc->FontXID=FontsList_[i][fsiz_sca]->fid;
04119 XSetFont(dpy,gc,FontsList_[i][fsiz_sca]->fid);
04120 XFlush(dpy);
04121 }
04122
04125 static void xget_font(integer *verbose, integer *font, integer *nargs, double *dummy)
04126 {
04127 *nargs=2;
04128 font[0]= ScilabXgc->FontId ;
04129 font[1] =ScilabXgc->FontSize ;
04130 if (*verbose == 1)
04131 {
04132 sciprint("\nFontId : %d ", ScilabXgc->FontId );
04133 sciprint("%s %s at size %s pts\r\n",SCIPROMPT,
04134 FontInfoTab_[ScilabXgc->FontId].fname,
04135 size_[ScilabXgc->FontSize]);
04136 }
04137 }
04138
04141 static void xset_mark(integer *number, integer *size, integer *v3, integer *v4)
04142 {
04143 ScilabXgc->CurHardSymb = Max(Min(SYMBOLNUMBER-1,*number),0);
04144 ScilabXgc->CurHardSymbSize = Max(Min(FONTMAXSIZE-1,*size),0);
04145 ;}
04146
04149 static void xget_mark(integer *verbose, integer *symb, integer *narg, double *dummy)
04150 {
04151 *narg =2 ;
04152 symb[0] = ScilabXgc->CurHardSymb ;
04153 symb[1] = ScilabXgc->CurHardSymbSize ;
04154 if (*verbose == 1)
04155 {
04156 sciprint("\nMark : %d ",ScilabXgc->CurHardSymb);
04157 sciprint("at size %s pts\r\n", size_[ScilabXgc->CurHardSymbSize]);
04158 }
04159 }
04160
04161
04162
04163
04164
04165
04166
04167
04168
04169
04170
04171
04172
04173 void C2F(loadfamily)(char *name, integer *j, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
04174 {
04175 integer i,flag=1 ;
04177 if ( strchr(name,'%') != (char *) NULL)
04178 {
04179 C2F(loadfamily_n)(name,j);
04180 return;
04181 }
04182 else
04183 {
04185 i=0;
04186 while ( fonttab[i].alias != (char *) NULL)
04187 {
04188 if (strcmp(fonttab[i].alias,name)==0)
04189 {
04190 C2F(loadfamily_n)(fonttab[i].name,j);
04191 return ;
04192 }
04193 i++;
04194 }
04196 for ( i = 0; i < FONTMAXSIZE ; i++)
04197 {
04198 char name1[200];
04199 sprintf(name1,"%s%s",name,size_[i]);
04200 FontsList_[*j][i]=XLoadQueryFont(dpy,name1);
04201 if (FontsList_[*j][i]== NULL)
04202 {
04203 flag=0;
04204 sciprint("\n Unknown font : %s",name1);
04205 sciprint("\n I'll use font: fixed ");
04206 FontsList_[*j][i]=XLoadQueryFont(dpy,"fixed");
04207 if (FontsList_[*j][i]== NULL)
04208 {
04209 sciprint("\n Unknown font : %s\r\n","fixed");
04210 sciprint("Please call an X Wizard !");
04211 }
04212 }
04213 }
04214 FontInfoTab_[*j].ok = 1;
04215 if (flag != 0)
04216 strcpy(FontInfoTab_[*j].fname,name);
04217 else
04218 strcpy(FontInfoTab_[*j].fname,"fixed");
04219 }
04220 }
04221
04222 static char *size_n_[] = { "8" ,"10","12","14","18","24"};
04223
04224 static void C2F(loadfamily_n)(char *name, integer *j)
04225 {
04226 char name1[200];
04227 integer i,flag=1 ;
04228 for ( i = 0; i < FONTMAXSIZE ; i++)
04229 {
04230 sprintf(name1,name,size_n_[i]);
04231 FontsList_[*j][i]=XLoadQueryFont(dpy,name1);
04232 if (FontsList_[*j][i]== NULL)
04233 {
04234 flag=0;
04235 sciprint("\n Unknown font : %s",name1);
04236 sciprint("\n I'll use font: fixed ");
04237 FontsList_[*j][i]=XLoadQueryFont(dpy,"fixed");
04238 if (FontsList_[*j][i]== NULL)
04239 {
04240 sciprint("\n Unknown font : %s\r\n","fixed");
04241 sciprint(" Please call an X Wizard !");
04242 }
04243 }
04244 }
04245 FontInfoTab_[*j].ok = 1;
04246 if (flag != 0)
04247 strcpy(FontInfoTab_[*j].fname,name);
04248 else
04249 strcpy(FontInfoTab_[*j].fname,"fixed");
04250 }
04251
04252 void C2F(queryfamily)(char *name, integer *j, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
04253 {
04254 integer i ;
04255 name[0]='\0';
04256 for (i=0;i<FONTNUMBER;i++) {
04257 v3[i]=strlen(FontInfoTab_[i].fname);
04258 if (v3[i] > 0)
04259 strcat(name,FontInfoTab_[i].fname);
04260 else
04261 if (i < FONTNUMBER-1) {
04262 v3[i]=strlen(fonttab[i].name);
04263 strcat(name,fonttab[i].name);
04264 }
04265 }
04266 *j=FONTNUMBER;
04267 }
04268
04269
04270
04271 static void LoadFonts(void)
04272 {
04273 integer fnum;
04274 C2F(loadfamily)("CourR",(fnum=0,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
04275 LoadSymbFonts();
04276 C2F(loadfamily)("TimR",(fnum=2,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
04277
04278
04279
04280
04281
04282 }
04283
04284
04285
04286
04287
04288
04289
04290 typedef struct { integer xoffset[SYMBOLNUMBER];
04291 integer yoffset[SYMBOLNUMBER];} Offset ;
04292
04293 static Offset ListOffset_[FONTMAXSIZE];
04294 static char Marks[] = {
04295
04296 (char)0x2e,(char)0x2b,(char)0xb4,(char)0xc5,(char)0xa8,
04297 (char)0xe0,(char)0x44,(char)0xd1,(char)0xa7,(char)0x4f};
04298
04299 static void
04300 LoadSymbFonts(void)
04301 {
04302 XCharStruct xcs;
04303 integer j,k ;
04304 integer i;
04306 C2F(loadfamily)("Symb",(i=1,&i),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
04307
04308
04309
04310
04311
04312
04313
04314
04315
04316
04318 if (strcmp(FontInfoTab_[1].fname,fonttab[1].name) != 0) return;
04319 for (i =0 ; i < FONTMAXSIZE ; i++)
04320 { if (FontsList_[1][i] != NULL)
04321 {
04322 k =FontsList_[1][i]->min_char_or_byte2;
04323 for (j=0 ; j < SYMBOLNUMBER ; j++)
04324 {
04325 xcs= FontsList_[1][i]->per_char[Char2Int(Marks[j])-k];
04326 (ListOffset_[i].xoffset)[j] = (xcs.rbearing+xcs.lbearing)/2;
04327 (ListOffset_[i].yoffset)[j] = (xcs.ascent+xcs.descent)/2;
04328 }
04329 }
04330 }
04331 }
04332
04333
04334
04335
04336
04337
04338 int C2F(CurSymbXOffset)(void)
04339 {
04340 return(-(ListOffset_[ScilabXgc->CurHardSymbSize].xoffset)
04341 [ScilabXgc->CurHardSymb]);
04342 }
04343
04344 int C2F(CurSymbYOffset)(void)
04345 {
04346 return((ListOffset_[ScilabXgc->CurHardSymbSize].yoffset)
04347 [ScilabXgc->CurHardSymb]);
04348 }
04349
04350 static void DrawMark(integer *x, integer *y)
04351 {
04352 char str[1];
04353 str[0]=Marks[ScilabXgc->CurHardSymb];
04354 if (ScilabXgc->Cdrawable != (Drawable) 0)
04355 XDrawString(dpy,ScilabXgc->Cdrawable,gc,(int) *x+C2F(CurSymbXOffset)(),
04356 (int)*y+C2F(CurSymbYOffset)(),str,1);
04357 if (ScilabXgc->CurPixmapStatus != 1)
04358 XDrawString(dpy,(Drawable) ScilabXgc->CWindow,gc,(int) *x+C2F(CurSymbXOffset)(),
04359 (int)*y+C2F(CurSymbYOffset)(),str,1);
04360 XFlush(dpy);
04361 }
04362
04363
04364
04365
04366
04367 static XPoint *points = NULL ;
04368 static XPoint *get_xpoints(void) { return(points); }
04369
04370 int C2F(store_points)(integer n, integer *vx, integer *vy, integer onemore)
04371 {
04372 integer i,n1 = ( onemore == 1) ? n+1 : n;
04373 if ( ReallocVector(n1) )
04374 {
04375 for ( i = 0; i < n; i++ )
04376 {
04377 points[i].x = INT_2_16B( vx[i] ) ;
04378
04379
04380
04381 points[i].y = INT_2_16B( vy[i] ) ;
04382
04383
04384 }
04385 if ( onemore ) {
04386 points[n].x = points[0].x;
04387 points[n].y = points[0].y;
04388 }
04389 return(1);
04390 }
04391 else return(0);
04392 }
04393
04394 static int ReallocVector(integer n)
04395 {
04396 if ( points == NULL )
04397 {
04398 points = MALLOC( n * sizeof(XPoint) ) ;
04399 }
04400 else
04401 {
04402 points = REALLOC( points, n * sizeof(XPoint) ) ;
04403 }
04404
04405 if ( points == NULL )
04406 {
04407 sciprint(MESSAGE5);
04408 return 0;
04409 }
04410
04411 return 1 ;
04412
04413 }
04414
04415 void deletePoints( void )
04416 {
04417 if ( points != NULL )
04418 {
04419 FREE( points ) ;
04420 points = NULL ;
04421 }
04422 }
04423
04424
04425
04426
04427
04428 void XDroutine(int npts)
04429 {
04430 if (ScilabXgc->Cdrawable != (Drawable) 0)
04431 XDrawLines (dpy, ScilabXgc->Cdrawable, gc, get_xpoints(),(int) npts,
04432 ScilabXgc->CurVectorStyle);
04433 if (ScilabXgc->CurPixmapStatus != 1)
04434 XDrawLines (dpy, (Drawable) ScilabXgc->CWindow, gc, get_xpoints(),(int) npts,
04435 ScilabXgc->CurVectorStyle);
04436 }
04437
04438 static int xleft, xright, ybot, ytop ;
04439
04440 static int clip_point(integer x, integer y)
04441 {
04442 integer ret_val = 0;
04443
04444 if (x < xleft) ret_val |= (char)0x01;
04445 else if (x > xright) ret_val |= (char)0x02;
04446 if (y < ybot) ret_val |= (char)0x04;
04447 else if (y > ytop) ret_val |= (char)0x08;
04448 return ret_val;
04449 }
04450
04451
04452
04453
04454
04455
04456
04457
04458
04459
04460
04461 void set_clip_box(integer xxleft, integer xxright, integer yybot, integer yytop)
04462 {
04463 xleft=xxleft;
04464 xright=xxright;
04465 ybot=yybot;
04466 ytop=yytop;
04467 }
04468
04469 void clip_line(integer x1, integer yy1, integer x2, integer y2, integer *x1n, integer *yy1n, integer *x2n, integer *y2n, integer *flag)
04470 {
04471 integer x_intr[2], y_intr[2];
04472
04473
04474 integer x, y, dx, dy, count, pos1, pos2;
04475
04476 *x1n=x1;*yy1n=yy1;*x2n=x2;*y2n=y2;*flag=4;
04477 pos1 = clip_point(x1, yy1);
04478 pos2 = clip_point(x2, y2);
04479 if (pos1 || pos2) {
04480 if (pos1 & pos2) { *flag=0;return;}
04481
04482
04483
04484
04485
04486
04487 count = 0;
04488 dx = x2 - x1;
04489 dy = y2 - yy1;
04490
04491
04492 if (dy != 0) {
04493 x = (int) (ybot - y2) * ((double) dx / (double) dy) + x2;
04494
04495 if (x >= xleft && x <= xright) {
04496 x_intr[count] = x;
04497 y_intr[count++] = ybot;
04498 }
04499 x = (ytop - y2) * ((double) dx / (double) dy) + x2;
04500
04501 if (x >= xleft && x <= xright) {
04502 x_intr[count] = x;
04503 y_intr[count++] = ytop;
04504 }
04505 }
04506 if ( count < 2 )
04507 {
04508
04509 if (dx != 0) {
04510 y = (xleft - x2) * ((double) dy / (double) dx) + y2;
04511
04512 if (y >= ybot && y <= ytop) {
04513 x_intr[count] = xleft;
04514 y_intr[count++] = y;
04515 }
04516 if ( count < 2 )
04517 {
04518 y = (xright - x2) * ((double) dy / (double) dx) + y2;
04519
04520 if (y >= ybot && y <= ytop) {
04521 x_intr[count] = xright;
04522 y_intr[count++] = y;
04523 }
04524 }
04525 }
04526 }
04527
04528 if (count == 2) {
04529 if (pos1 && pos2) {
04530 *x1n = x_intr[0];
04531 *yy1n = y_intr[0];
04532 *x2n = x_intr[1];
04533 *y2n = y_intr[1];
04534 *flag=3;return;
04535 }
04536 else if (pos1) {
04537 if (dx * (x2 - x_intr[0]) + dy * (y2 - y_intr[0]) >= 0) {
04538 *x1n = x_intr[0];
04539 *yy1n = y_intr[0];
04540 *flag=1;return;
04541 }
04542 else {
04543 *x1n = x_intr[1];
04544 *yy1n = y_intr[1];
04545 *flag=1;return;
04546 }
04547 }
04548 else {
04549 if (dx * (x_intr[0] - x1) + dy * (y_intr[0] - yy1) >= 0) {
04550 *x2n = x_intr[0];
04551 *y2n = y_intr[0];
04552 *flag=2;return;
04553 }
04554 else {
04555 *x2n = x_intr[1];
04556 *y2n = y_intr[1];
04557 *flag=2;return;
04558 }
04559 }
04560 }
04561 else
04562 {
04563
04564 *flag=0;return;
04565 }
04566 }
04567 }
04568
04569 integer first_in(integer n, integer ideb, integer *vx, integer *vy)
04570 {
04571 integer i;
04572 for (i=ideb ; i < n ; i++)
04573 {
04574 if (vx[i]>= xleft && vx[i] <= xright && vy[i] >= ybot && vy[i] <= ytop)
04575 {
04576 #ifdef DEBUG
04577 sciprint("first in %d->%d=(%d,%d)\r\n",ideb,i,vx[i],vy[i]);
04578 #endif
04579 return(i);
04580 }
04581 }
04582 return(-1);
04583 }
04584
04585
04586
04587
04588
04589
04590
04591 integer first_out(integer n, integer ideb, integer *vx, integer *vy)
04592 {
04593 integer i;
04594 for (i=ideb ; i < n ; i++)
04595 {
04596 if ( vx[i]< xleft || vx[i]> xright || vy[i] < ybot || vy[i] > ytop)
04597 {
04598 #ifdef DEBUG
04599 sciprint("first out %d->%d=(%d,%d)\r\n",ideb,i,vx[i],vy[i]);
04600 #endif
04601 return(i);
04602 }
04603 }
04604 return(-1);
04605 }
04606
04607 static void C2F(analyze_points)(integer n, integer *vx, integer *vy, integer onemore)
04608 {
04609 SClipRegion clipping ;
04610 integer windowSize[2] ;
04611 integer verbose = 0 ;
04612 integer narg ;
04613 xget_windowdim( &verbose, windowSize, &narg, vdouble ) ;
04614 clipping.leftX = 0 ;
04615 clipping.rightX = windowSize[0] ;
04616 clipping.bottomY = 0 ;
04617 clipping.topY = windowSize[1] ;
04618 C2F(clipPolyLine)( n, vx, vy, onemore, &clipping ) ;
04619 }
04620
04621 int CheckScilabXgc(void)
04622 {
04623 return( ScilabXgc != (struct BCG *) 0);
04624 }
04625
04626
04627 static int screencolor = 1 ;
04628
04629
04630
04631 void getcolordef( integer * screenc )
04632 {
04633 *screenc= screencolor;
04634 }
04635
04636 void setcolordef( int screenc )
04637 {
04638 screencolor = screenc;
04639 }
04640
04641 #undef MAXTAB
04642 #undef DASH_TAB_SIZE