00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef STRICT
00014 #define STRICT
00015 #endif
00016
00017 #include <Windows.h>
00018 #include <commctrl.h>
00019
00020 #include <stdio.h>
00021 #include <string.h>
00022 #include <math.h>
00023 #include <stdlib.h>
00024 #include <stdarg.h>
00025
00026 #include "../../gui/src/c/wsci/wresource.h"
00027 #include "../../gui/src/c/wsci/resource.h"
00028 #include "../../gui/src/c/wsci/wcommon.h"
00029 #include "../../gui/src/c/wsci/wgraph.h"
00030 #include "../../gui/src/c/wsci/wtext.h"
00031 #include "Events.h"
00032
00033 #include "bcg.h"
00034 #include "periWin.h"
00035 #include "color.h"
00036 #include "scigraphic.h"
00037 #include "machine.h"
00038 #include "clipping.h"
00039 #include "SetProperty.h"
00040
00041 #include "math_graphics.h"
00042
00043 #include "MALLOC.h"
00044
00045 #include "WindowList.h"
00046
00047
00048 #define CoordModePrevious 1
00049 #define CoordModeOrigin 0
00050
00051
00052 #define GXxor 6
00053
00054
00069 LRESULT CALLBACK WndGraphProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
00070 LRESULT CALLBACK WndParentGraphProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
00071 void setcolormapg(struct BCG *Xgc,integer *v1, integer *v2, double *a, integer *v3);
00072 static void C2F(setscilabFigure)(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure);
00073 static void C2F(getscilabFigure)(integer *verbose, integer *x,integer *narg, double *figure);
00074 static void C2F(setscilabVersion)(integer *vers, integer *v2, integer *v3, integer *v4);
00075 static void C2F(getscilabVersion)(integer *verbose, integer *vers, integer *narg, double *dummy);
00076 static void C2F(setscilabxgc)(integer *v1, integer *v2, integer *v3, integer *v4);
00077 static void C2F(getscilabxgc)(integer *verbose, integer *x,integer *narg, double *dummy);
00078 static void C2F(getcolormapsize)(integer *verbose, integer *num, integer *narg, double *val);
00079
00080
00081
00082 #define WIN_XMAX (2400)
00083 #define WIN_YMAX (1800)
00084 #define WIN_HCHAR (WIN_XMAX/75)
00085 #define WIN_VCHAR (WIN_YMAX/25)
00086
00087
00088
00089 #define MESSAGE4 "Can't allocate point vector"
00090 #define MESSAGE5 "Can't re-allocate point vector"
00091 #define Char2Int(x) ( x & 0x000000ff )
00092
00093 static double *vdouble = 0;
00094
00095
00096
00097
00098 unsigned short default_colors[] = {
00099 0, 0, 0,
00100 0, 0, 255,
00101 0, 255, 0,
00102 0, 255, 255,
00103 255, 0, 0,
00104 255, 0, 255,
00105 255, 0, 0,
00106 255, 255, 255,
00107 0, 0, 144,
00108 0, 0, 176,
00109 0, 0, 208,
00110 135, 206, 255,
00111 0, 144, 0,
00112 0, 176, 0,
00113 0, 208, 0,
00114 0, 144, 144,
00115 0, 176, 176,
00116 0, 208, 208,
00117 144, 0, 0,
00118 176, 0, 0,
00119 208, 0, 0,
00120 144, 0, 144,
00121 176, 0, 176,
00122 208, 0, 208,
00123 128, 48, 0,
00124 160, 64, 0,
00125 192, 96, 0,
00126 255, 128, 128,
00127 255, 160, 160,
00128 255, 192, 192,
00129 255, 224, 224,
00130 255, 215, 0
00131 };
00132
00133 LPSTR szGraphClass = "wscilab_graph";
00134 LPSTR szParentGraphClass = "wscilab_parent_graph";
00135
00136
00137 #define MAXDASH 5
00138 static integer DashTab[MAXDASH] = { PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT};
00139
00140
00148 extern GW graphwin;
00149 extern TW textwin;
00153 static POINT *C2F(ReturnPoints)();
00154 static HFONT getcurfont();
00155 int XorString(integer x,integer y, char *string,int fWidth,int fHeight);
00156
00157 static int screencolor = 1 ;
00158 static COLORREF DefaultBackground = RGB(255,255,255);
00159 static COLORREF DefaultForeground = RGB(0,0,0);
00160
00161 #define COLORREF COLORREF
00162
00165 struct BCG MissileXgc ;
00166
00167
00168 static integer deleted_win = -1;
00169 struct BCG *ScilabXgc = (struct BCG *) 0;
00170
00173 HWND GetWindowNumber();
00174 struct BCG *AddNewWindowToList();
00175
00176 int SwitchWindow(integer *intnum);
00177
00178 static int ReallocVector();
00179 static void DrawMark(),LoadFonts(), LoadSymbFonts();
00180 static void C2F(loadfamily_n)();
00181 static void CreateGraphClass();
00182 static BOOL RegisterParentWindowGraphClass (void);
00183 static BOOL RegisterWindowGraphClass (void);
00184 static void XDrawPoints();
00185 static BOOL SciPalette(int iNumClr);
00186 static void set_current_clip (void);
00187 static void set_clip_after_scroll (void) ;
00188
00189
00190 extern void UpdateFileGraphNameMenu(struct BCG *ScilabGC);
00191 extern void CreateGraphToolBar(struct BCG * ScilabGC);
00192 extern void CreateGedMenus(struct BCG * ScilabGC);
00193 extern void SetIsASingleClickToFalse(void);
00194 extern BOOL IsASingleClickToFalse(void);
00195 extern BOOL IsWindowInterface(void);
00196 extern void RefreshGraphToolBar(struct BCG * ScilabGC) ;
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 static HDC hdc = (HDC) 0 ;
00209 static HDC hdc1 = (HDC) 0 ;
00210
00211 integer sciGetwresize(void);
00212
00213
00214 int sciGetScrollInfo(struct BCG *Scilabgc, int sb_ctl, SCROLLINFO *si)
00215 {
00216 SCROLLINFO totosi;
00217 switch (sb_ctl)
00218 {
00219 case SB_VERT:
00220
00221 si->cbSize = Scilabgc->vertsi.cbSize;
00222 si->fMask = Scilabgc->vertsi.fMask;
00223 si->nMin = Scilabgc->vertsi.nMin;
00224 si->nMax = Scilabgc->vertsi.nMax;
00225 si->nPage = Scilabgc->vertsi.nPage;
00226 si->nPos = Scilabgc->vertsi.nPos;
00227 break;
00228 case SB_HORZ:
00229
00230 si->cbSize = Scilabgc->horzsi.cbSize;
00231 si->fMask = Scilabgc->horzsi.fMask;
00232 si->nMin = Scilabgc->horzsi.nMin;
00233 si->nMax = Scilabgc->horzsi.nMax;
00234 si->nPage = Scilabgc->horzsi.nPage;
00235 si->nPos = Scilabgc->horzsi.nPos;
00236 break;
00237 default:
00238 break;
00239 }
00240
00241 GetScrollInfo(Scilabgc->CWindow, sb_ctl, &totosi);
00242 return 0;
00243 }
00244
00245 int sciSetScrollInfo(struct BCG *Scilabgc, int sb_ctl, SCROLLINFO *si, BOOLEAN bRedraw)
00246 {
00247 int inttmp = si->nMax;
00248 SCROLLINFO totosi;
00249
00250 switch (sb_ctl) {
00251 case SB_VERT:
00252
00253 Scilabgc->vertsi.cbSize = si->cbSize;
00254 Scilabgc->vertsi.fMask = si->fMask;
00255 Scilabgc->vertsi.nMin = si->nMin;
00256 Scilabgc->vertsi.nMax = si->nMax;
00257 Scilabgc->vertsi.nPage = si->nPage;
00258 if ( Scilabgc->CurResizeStatus == 1)
00259 {
00260 si->nMax = 0;
00261
00262 }
00263 Scilabgc->vertsi.nPos = si->nPos;
00264 break;
00265 case SB_HORZ:
00266
00267 Scilabgc->horzsi.cbSize = si->cbSize;
00268 Scilabgc->horzsi.fMask = si->fMask;
00269 Scilabgc->horzsi.nMin = si->nMin;
00270 Scilabgc->horzsi.nMax = si->nMax;
00271 Scilabgc->horzsi.nPage = si->nPage;
00272 if ( Scilabgc->CurResizeStatus == 1 ) { si->nMax = 0;}
00273 Scilabgc->horzsi.nPos = si->nPos;
00274 break;
00275 default:
00276 break;
00277 }
00278
00279
00280
00281 SetScrollInfo(Scilabgc->CWindow, sb_ctl, si, bRedraw);
00282 if ( Scilabgc->CurResizeStatus == 1)
00283 si->nMax = inttmp;
00284
00285 sciGetScrollInfo(Scilabgc, sb_ctl, &totosi);
00286 return 0;
00287 }
00288
00289 int sciInitScrollBar(struct BCG *Scilabgc)
00290 {
00291 SCROLLINFO si;
00292
00293
00294 si.cbSize = sizeof(SCROLLINFO);
00295 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
00296 si.nMin = 0;
00297 si.nMax = Scilabgc->CWindowHeight;
00298 si.nPage = Scilabgc->CWindowHeightView;
00299 si.nPos = 0;
00300 sciSetScrollInfo(ScilabXgc,SB_VERT, &si, TRUE);
00301
00302
00303 si.cbSize = sizeof(SCROLLINFO);
00304 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
00305 si.nMin = 0;
00306 si.nMax = Scilabgc->CWindowWidth;
00307 si.nPage = Scilabgc->CWindowWidthView;
00308 si.nPos = 0;
00309 sciSetScrollInfo(ScilabXgc,SB_HORZ, &si, TRUE);
00310 return 0;
00311 }
00312
00313 void SetWinhdc( void )
00314 {
00315 if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->CWindow != (HWND) 0)
00316 {
00317 if ( sciGetPixmapStatus() == 1)
00318 hdc = ScilabXgc->hdcCompat;
00319 else
00320 hdc=TryToGetDC(ScilabXgc->CWindow);
00321 }
00322 }
00323
00324 int MaybeSetWinhdc()
00325 {
00326 int DiD = GetDriverId();
00327 if( DiD != 0)
00328 return 0;
00329
00331 if ( hdc == (HDC) 0)
00332 {
00333 if ( sciGetPixmapStatus() == 1)
00334 {
00335 hdc = ScilabXgc->hdcCompat;
00336
00337
00338
00339
00340
00341
00342 return(1);
00343 }
00344 else
00345 {
00346 hdc=TryToGetDC(ScilabXgc->CWindow);
00347 return(1);
00348 }
00349 }
00350 else
00351 {
00352 return(0);
00353 }
00354 }
00355
00356 void ReleaseWinHdc()
00357 {
00358 int DiD = GetDriverId();
00359 if( DiD != 0)
00360 {
00361 }
00362 else
00363 {
00364 if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->CWindow != (HWND) 0)
00365 {
00366 if ( sciGetPixmapStatus() != 1)
00367 ReleaseDC(ScilabXgc->CWindow,hdc);
00368 hdc = (HDC) 0;
00369 }
00370 }
00371 }
00372
00373
00374
00375
00376
00377
00378 void SetGHdc(HDC lhdc,int width,int height)
00379 {
00380 if ( lhdc != (HDC) 0)
00381 {
00382 hdc1= hdc ;
00383 if ( hdc != (HDC) 0) ReleaseWinHdc();
00384 hdc = lhdc;
00385 ScilabXgc->CWindowWidth = width;
00386 ScilabXgc->CWindowHeight = height;
00387 }
00388 else
00389 {
00390 if ( hdc1 != (HDC) 0 && ScilabXgc != (struct BCG *) 0
00391 && ScilabXgc->CWindow != (HWND) 0 )
00392 {
00393 RECT rect;
00394 hdc=TryToGetDC(ScilabXgc->CWindow);
00395
00396 GetClientRect(ScilabXgc->CWindow,&rect);
00397 ScilabXgc->CWindowWidthView = rect.right-rect.left;
00398 ScilabXgc->CWindowHeightView = rect.bottom-rect.top;
00399 }
00400 }
00401 }
00402
00405 int XgcAllocColors(xgc,m)
00406 struct BCG *xgc;
00407 int m;
00408 {
00409 int mm;
00410
00411 mm = m + 2;
00412 if (!(xgc->Red = (float *) MALLOC(mm*sizeof(float)))) {
00413 Scistring("XgcAllocColors: unable to alloc\n");
00414 return 0;
00415 }
00416 if (!(xgc->Green = (float *) MALLOC(mm*sizeof(float)))) {
00417 Scistring("XgcAllocColors: unable to alloc\n");
00418 FREE(xgc->Red);
00419 return 0;
00420 }
00421 if (!(xgc->Blue = (float *) MALLOC(mm*sizeof(float)))) {
00422 Scistring("XgcAllocColors: unable to alloc\n");
00423 FREE(xgc->Red);
00424 FREE(xgc->Green);
00425 return 0;
00426 }
00427 if (!(xgc->Colors = (COLORREF *) MALLOC(mm*sizeof(COLORREF)))) {
00428 Scistring("XgcAllocColors: unable to alloc\n");
00429 FREE(xgc->Red);
00430 FREE(xgc->Green);
00431 FREE(xgc->Blue);
00432 return 0;
00433 }
00434 return 1;
00435 }
00436
00437 int XgcFreeColors(xgc)
00438 struct BCG *xgc;
00439 {
00440 FREE(xgc->Red); xgc->Red = (float *) 0;
00441 FREE(xgc->Green);xgc->Green = (float *) 0;
00442 FREE(xgc->Blue); xgc->Blue = (float *) 0;
00443 FREE(xgc->Colors); xgc->Colors = (COLORREF *) 0;
00444 return(0);
00445 }
00446
00449 void sci_pixmapclear_rect(HDC hdc_c, struct BCG *ScilabGC,int ww,int hh)
00450 {
00451 RECT rect;
00452 COLORREF px;
00453 HBRUSH hBrush;
00454 if ( hdc_c == NULL) return ;
00455 px = (ScilabGC->Colors == NULL)? DefaultBackground
00456 : ScilabGC->Colors[ScilabGC->NumBackground];
00457 SetBkColor( hdc_c , px );
00458 rect.top = 0;
00459 rect.bottom = ww ;
00460 rect.left = 0;
00461 rect.right = hh ;
00462 hBrush = CreateSolidBrush(px);
00463 FillRect( hdc_c , &rect,hBrush );
00464 DeleteObject(hBrush);
00465 }
00466
00467 void sci_pixmapclear(HDC hdc_c, struct BCG *ScilabGC )
00468 {
00469 sci_pixmapclear_rect(hdc_c,ScilabGC,
00470 ScilabGC->CWindowHeight,ScilabGC->CWindowWidth);
00471 }
00472
00473 void C2F(pixmapclear)( integer *v1, integer *v2, integer *v3, integer *v4)
00474 {
00475 sci_pixmapclear(ScilabXgc->hdcCompat, ScilabXgc);
00476 }
00477
00478 void C2F(show)( integer *v1, integer *v2, integer *v3, integer *v4)
00479 {
00480 if ( ScilabXgc->hdcCompat)
00481 {
00482 HDC hdc1=TryToGetDC(ScilabXgc->CWindow);
00483 BitBlt (hdc1,0,0,ScilabXgc->CWindowWidth,ScilabXgc->CWindowHeight,
00484 ScilabXgc->hdcCompat,0,0,SRCCOPY);
00485
00486 ReleaseDC(ScilabXgc->CWindow,hdc1);
00487 RefreshGraphToolBar(ScilabXgc);
00488 }
00489
00490 }
00491
00492
00498 void sci_pixmap_resize(struct BCG * ScilabGC, int x, int y)
00499 {
00500 HDC hdc1;
00501 HBITMAP hbmTemp;
00502 hdc1=TryToGetDC(ScilabGC->CWindow);
00503 hbmTemp = CreateCompatibleBitmap (hdc1,x,y);
00504 ReleaseDC(ScilabGC->CWindow,hdc1);
00505 if (!hbmTemp)
00506 {
00507 sciprint("Can't resize pixmap\r\n");
00508 return;
00509 }
00510 else
00511 {
00512 HBITMAP hbmSave;
00513 hbmSave = SelectObject ( ScilabGC->hdcCompat, hbmTemp);
00514 if ( ScilabGC->hbmCompat != NULL)
00515 DeleteObject (ScilabGC->hbmCompat);
00516 ScilabGC->hbmCompat = hbmTemp;
00517 sci_pixmapclear(ScilabGC->hdcCompat, ScilabGC);
00518
00519 }
00520 }
00521
00522 void CPixmapResize(int x,int y)
00523 {
00524 void sci_pixmap_resize(ScilabXgc, x, y) ;
00525 }
00526
00527
00528
00529
00530
00531 void CPixmapResize1( void )
00532 {
00533 if ( sciGetPixmapStatus() == 1 )
00534 sci_pixmap_resize(ScilabXgc,ScilabXgc->CWindowWidth,ScilabXgc->CWindowHeight);
00535 }
00536
00537
00538
00539
00540
00541
00545 void C2F(xselgraphic)(v1, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
00546 char *v1;
00547 integer *v2;
00548 integer *v3;
00549 integer *v4;
00550 integer *v5;
00551 integer *v6;
00552 integer *v7;
00553 double *dv1;
00554 double *dv2;
00555 double *dv3;
00556 double *dv4;
00557 {
00558 integer ierr;
00559 if (ScilabXgc == (struct BCG *)0 || ScilabXgc->CWindow == (HWND) NULL)
00560 C2F(initgraphic)("",PI0,&ierr,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00561 if (IsIconic(ScilabXgc->hWndParent))
00562 ShowWindow(ScilabXgc->hWndParent, SW_SHOWNORMAL);
00563 BringWindowToTop(ScilabXgc->hWndParent);
00564 }
00565
00567 void C2F(xendgraphic)()
00568 {
00569 }
00570
00571 void C2F(xend)(v1, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
00572 char *v1;
00573 integer *v2;
00574 integer *v3;
00575 integer *v4;
00576 integer *v5;
00577 integer *v6;
00578 integer *v7;
00579 double *dv1;
00580 double *dv2;
00581 double *dv3;
00582 double *dv4;
00583 {
00585 }
00586
00589 void C2F(clearwindow)(v1, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
00590 char *v1;
00591 integer *v2,*v3,*v4,*v5,*v6,*v7;
00592 double *dv1,*dv2,*dv3,*dv4;
00593 {
00594 RECT rect;
00595 static COLORREF px;
00596 HBRUSH hBrush;
00597 if ( ScilabXgc->ClipRegionSet == 1)
00598 SelectClipRgn(hdc,NULL);
00599 if ( sciGetPixmapStatus() == 1)
00600 {
00601 C2F(pixmapclear)(PI0,PI0,PI0,PI0);
00602 C2F(show)(PI0,PI0,PI0,PI0);
00603 }
00604 else
00605 {
00606 px = (ScilabXgc->Colors == NULL)? DefaultBackground
00607 : ScilabXgc->Colors[ScilabXgc->NumBackground];
00608 SetBkColor(hdc, px );
00609 GetClientRect(ScilabXgc->CWindow, &rect);
00611 hBrush = CreateSolidBrush(px);
00612
00613 rect.top = 0;
00614 rect.left = 0;
00615 rect.right = ScilabXgc->CWindowWidth;
00616 rect.bottom = ScilabXgc->CWindowHeight;
00617 FillRect(hdc, &rect,hBrush );
00618 DeleteObject(hBrush);
00619 }
00620
00621 set_current_clip ();
00622
00623 RefreshGraphToolBar(ScilabXgc);
00624
00625 }
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635 void Setpopupname(string)
00636 char *string;
00637 {
00638
00639 SetWindowText(ScilabXgc->hWndParent, string);
00640 }
00641
00642
00643 void C2F(setpopupname)(x0, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
00644 char *x0;
00645 integer *v2,*v3,*v4,*v5,*v6,*v7;
00646 double *dv1,*dv2,*dv3,*dv4;
00647 {
00648 Setpopupname(x0);
00649 }
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659 static int check_mouse(MSG *msg,integer *ibutton,integer *x1,integer *yy1,
00660 int xofset,int yofset,
00661 int getmouse,int getrelease);
00662
00663 int check_pointer_win(int *x1,int *yy1,int *win)
00664 {
00665 RECT lpRect;
00666 HWND hwnd_window_pointed;
00667 WindowList * listptr = NULL ;
00668 POINT Point;
00669 integer iwin = -1;
00670
00671 GetCursorPos(&Point);
00672
00673 hwnd_window_pointed = WindowFromPoint(Point);
00674
00675 if (hwnd_window_pointed != NULL)
00676 {
00677 iwin = -1;
00678 listptr = getScilabWindowList() ;
00679 while ( listptr != NULL )
00680 {
00681 if (hwnd_window_pointed == listptr->winxgc.CWindow
00682 || hwnd_window_pointed == listptr->winxgc.hWndParent)
00683 {
00684 iwin = listptr->winxgc.CurWindow;
00685 break;
00686 }
00687 listptr = listptr->next;
00688 }
00689
00690 if ( iwin != -1 )
00691 {
00692
00693 GetWindowRect(listptr->winxgc.CWindow , &lpRect);
00694
00695 *x1 = Point.x - lpRect.left + listptr->winxgc.horzsi.nPos;
00696 *yy1 = Point.y - lpRect.top + listptr->winxgc.vertsi.nPos;
00697 *win = iwin;
00698 return 1;
00699 }
00700 }
00701 return 0;
00702 }
00703
00704
00705 extern void set_wait_click(int val);
00706 extern void set_event_select(int val);
00707
00708 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)
00709 {
00710 integer win;
00711 integer wincount;
00712 integer lstr ;
00713 int motion,release,ok;
00714
00715
00716
00717
00718
00719
00720 deleted_win = -1;
00721
00722 wincount = getWinsMaxId() + 1 ;
00723 if (wincount == 0)
00724 {
00725 *x1=0;
00726 *yy1=0;
00727 *iwin=0;
00728 *ibutton = -100;
00729 *istr = 0;
00730 return;
00731 }
00732
00733
00734 if ( *iflag ==0 ) ClearClickQueue(-1);
00735
00737 set_wait_click(1);
00738 set_event_select(1+4);
00739 while (1)
00740 {
00741 win=-1;
00742 ok=0;
00743 while (CheckClickQueue(&win,x1,yy1,ibutton,&motion,&release) == 1) {
00744 if ((motion==0) && (release==0)) {
00745 *iwin = win ;
00746 ok=1;
00747 break;
00748 }
00749
00750 win=-1;
00751 }
00752 if(ok) {*istr = 0;break;};
00753
00754 C2F(sxevents)();
00755 Sleep(1);
00756
00757 if ( deleted_win != -1 )
00758 {
00759
00760 *iwin = deleted_win;
00761 deleted_win = -1;
00762 *x1= 0;
00763 *yy1 = 0;
00764 *ibutton = -100;
00765 set_wait_click(0);
00766 return ;
00767 }
00768
00770 if ( *istr==1 && C2F(ismenu)()==1 )
00771 {
00772 int entry;
00773 C2F(getmen)(str,&lstr,&entry);
00774 *ibutton = -2;
00775 *istr=lstr;
00776 *x1=0;
00777 *yy1=0;
00778 *iwin=-1;
00779 break;
00780 }
00781
00782 }
00783 set_wait_click(0);
00784 }
00785
00786 void SciClick(integer *ibutton, integer *x1, integer *yy1, integer *iflag, int getmouse, int getrelease, int dyn_men, char *str, integer *lstr)
00787 {
00788 integer ok,choice,motion,release;
00789 int win;
00790
00791 choice=(dyn_men>1);
00792 if ( ScilabXgc == (struct BCG *) 0 || ScilabXgc->CWindow == (HWND) 0)
00793 {
00794 *x1 = -1;
00795 *yy1 = -1;
00796 *ibutton = -100;
00797 return;
00798 }
00799
00800 win = ScilabXgc->CurWindow;
00801
00802 if ( *iflag ==0 ) ClearClickQueue(ScilabXgc->CurWindow);
00803
00805 if (IsIconic(ScilabXgc->hWndParent)) ShowWindow(ScilabXgc->hWndParent, SW_SHOWNORMAL);
00806 BringWindowToTop(ScilabXgc->hWndParent);
00807
00808 set_wait_click(1);
00809 set_event_select(1+2*getmouse+4*getrelease);
00810
00811 while ( 1 )
00812 {
00814 if (choice) win=-1;
00815 ok=0;
00816 if (CheckClickQueue(&win,x1,yy1,ibutton,&motion,&release) == 1) {
00817 if ((release&&getrelease) || (motion&&getmouse) || ((motion==0)&&(release==0))){
00818 *iflag=win;
00819 ok=1;
00820 break;
00821 }
00822 if (choice) win=-1;
00823 }
00824 if(ok) break;
00825
00826
00827 C2F(sxevents)();
00828 Sleep(1);
00829
00830 if ( ScilabXgc == (struct BCG *) 0 || ScilabXgc->CWindow == (HWND) 0)
00831 {
00832
00833 *x1= 0 ;
00834 *yy1= 0;
00835 *ibutton=-100;
00836 set_event_select(1+4);
00837 set_wait_click(0);
00838 return;
00839 }
00840
00841 if ( dyn_men == 1 && C2F(ismenu)()==1 )
00842 {
00843 int entry;
00844 C2F(getmen)(str,lstr,&entry);
00845 *ibutton = -2;
00846 *x1=0;
00847 *yy1=0;
00848 set_event_select(1+4);
00849 set_wait_click(0);
00850 return ;
00851 }
00852
00853 if ( CtrlCHit(&textwin) == 1)
00854 {
00855 *x1= 0 ;
00856 *yy1= 0;
00857 *ibutton=0;
00858 break ;
00859 }
00860 }
00861 set_event_select(1+4);
00862 set_wait_click(0);
00863 }
00864
00865 void C2F(xclick)(str, ibutton, x1, yy1, iflag,istr, v7, dv1, dv2, dv3, dv4)
00866 char *str;
00867 integer *ibutton,*x1,*yy1,*iflag,*istr,*v7;
00868 double *dv1;
00869 double *dv2;
00870 double *dv3;
00871 double *dv4;
00872 {
00873 integer lstr ;
00874 SciClick(ibutton,x1, yy1,iflag,0,0,*istr,str,&lstr);
00875 if ( *istr == 1)
00876 {
00877 if (*ibutton == -2)
00878 {
00879
00880 *istr = lstr;
00881 }
00882 else
00883 *istr = 0;
00884 }
00885 }
00886
00887 void C2F(xgetmouse)(str, ibutton, x1, yy1,iflag, v6, v7, dv1, dv2, dv3, dv4)
00888 char *str;
00889 integer *ibutton,*x1,*yy1,*iflag,*v6,*v7;
00890 double *dv1;
00891 double *dv2;
00892 double *dv3;
00893 double *dv4;
00894 {
00895 SciClick(ibutton,x1, yy1,iflag,v6[0],v6[1],0,(char *) 0,(integer *)0);
00896 }
00897
00898 void SciMouseCapture( void )
00899 {
00900 SetCapture(ScilabXgc->CWindow);
00901 }
00902
00903 void SciMouseRelease( void )
00904 {
00905 ReleaseCapture();
00906 }
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920 static int check_mouse(MSG *msg,integer *ibutton,integer *x1,integer *yy1,
00921 int xofset,int yofset,
00922 int getmouse,int getrelease)
00923 {
00924 if ( msg->message == WM_LBUTTONDOWN )
00925 {
00926 *x1=LOWORD(msg->lParam) + xofset;
00927 *yy1= HIWORD(msg->lParam) + yofset;
00928 *ibutton=0;
00929 }
00930 else if ( msg->message == WM_MBUTTONDOWN )
00931 {
00932 *x1 = LOWORD(msg->lParam) + xofset;
00933 *yy1= HIWORD(msg->lParam) + yofset;
00934 *ibutton=1;
00935 }
00936 else if ( msg->message == WM_RBUTTONDOWN )
00937 {
00938 *x1 = LOWORD(msg->lParam) + xofset;
00939 *yy1= HIWORD(msg->lParam) + yofset;
00940 *ibutton=2;
00941 }
00942 else if ( getmouse == 1 && msg->message == WM_MOUSEMOVE )
00943 {
00944 *x1 = LOWORD(msg->lParam) + xofset;
00945 *yy1= HIWORD(msg->lParam) + yofset;
00946 *ibutton=-1;
00947 }
00948 else if ( getrelease == 1 && msg->message == WM_LBUTTONUP )
00949 {
00950 *x1 = LOWORD(msg->lParam) + xofset;
00951 *yy1= HIWORD(msg->lParam) + yofset;
00952 *ibutton= -5 ;
00953 }
00954 else if (getrelease == 1 && msg->message == WM_MBUTTONUP )
00955 {
00956 *x1 = LOWORD(msg->lParam) + xofset;
00957 *yy1= HIWORD(msg->lParam) + yofset;
00958 *ibutton= -4 ;
00959 }
00960 else if ( getrelease == 1 && msg->message == WM_RBUTTONUP )
00961 {
00962 *x1 = LOWORD(msg->lParam) + xofset;
00963 *yy1= HIWORD(msg->lParam) + yofset;
00964 *ibutton= -3;
00965 }
00966 else
00967 {
00968 return 0;
00969 }
00970 return 1;
00971 }
00972
00973
00974
00975
00976
00977 void C2F(cleararea)(str, x, y, w, h, v6, v7, dv1, dv2, dv3, dv4)
00978 char *str;
00979 integer *x;
00980 integer *y;
00981 integer *w;
00982 integer *h;
00983 integer *v6;
00984 integer *v7;
00985 double *dv1;
00986 double *dv2;
00987 double *dv3;
00988 double *dv4;
00989 {
00990 HBRUSH hBrush;
00991 RECT rect;
00992 static COLORREF px;
00993 px = (ScilabXgc->Colors == NULL)? DefaultBackground
00994 : ScilabXgc->Colors[ScilabXgc->NumBackground];
00995 SetRect(&rect,(int) *x,(int) *y,(int) *x+*w,(int) *y+*h);
00997 hBrush = CreateSolidBrush(px);
00998 FillRect(hdc, &rect,hBrush );
00999 DeleteObject(hBrush);
01002 }
01003
01004
01005
01006
01007
01008
01011 void C2F(getwindowpos)(verbose, x, narg,dummy)
01012 integer *verbose;
01013 integer *x;
01014 integer *narg;
01015 double *dummy;
01016 {
01017 RECT rect;
01018 GetWindowRect(ScilabXgc->hWndParent,&rect);
01019 *narg = 2;
01020 x[0]=rect.left; x[1] = rect.top;
01021 if (*verbose == 1)
01022 sciprint("\n ScilabXgc->CWindow position :%d,%d\r\n",x[0],x[1]);
01023 }
01024
01026 void C2F(setwindowpos)(x, y, v3, v4)
01027 integer *x;
01028 integer *y;
01029 integer *v3;
01030 integer *v4;
01031 {
01032 SetWindowPos(ScilabXgc->hWndParent,HWND_TOP,*x,*y,0,0,
01033 SWP_NOSIZE | SWP_NOZORDER );
01034 }
01035
01037 void C2F(getwindowdim)( integer * verbose, integer * x, integer * narg, double * dummy )
01038 {
01039 *narg = 2;
01040
01041
01042 x[0]= ScilabXgc->CWindowWidth;
01043 x[1]= ScilabXgc->CWindowHeight;
01044 if (*verbose == 1)
01045 sciprint("\n CWindow dim :%d,%d\r\n",(int) x[0],(int) x[1]);
01046 }
01047
01048
01049
01050
01051
01052
01053
01054 void C2F(setwindowdim)(x, y, v3, v4)
01055 integer *x;
01056 integer *y;
01057 integer *v3;
01058 integer *v4;
01059 {
01060 RECT rect,rect1;
01061 int xof,yof;
01062 SCROLLINFO vertsi;
01063 SCROLLINFO horzsi;
01064 if (ScilabXgc->CWindow != (HWND) NULL)
01065 {
01066
01067 sciGetScrollInfo(ScilabXgc, SB_VERT, &vertsi);
01068 sciGetScrollInfo(ScilabXgc, SB_HORZ, &horzsi);
01069
01070 ScilabXgc->CWindowWidth = Max((int) *x,50);
01071 ScilabXgc->CWindowHeight =Max((int) *y,50);
01072 if ( sciGetwresize() == 1 ) {
01073 ScilabXgc->CWindowWidthView = ScilabXgc->CWindowWidth;
01074 ScilabXgc->CWindowHeightView = ScilabXgc->CWindowHeight;
01075 vertsi.nPos = 0;
01076 horzsi.nPos = 0;
01077 }
01078
01079 if ( ScilabXgc->CWindowWidthView > ScilabXgc->CWindowWidth)
01080 ScilabXgc->CWindowWidthView = ScilabXgc->CWindowWidth;
01081
01082 if (ScilabXgc->CWindowHeightView > ScilabXgc->CWindowHeight)
01083 ScilabXgc->CWindowHeightView = ScilabXgc->CWindowHeight;
01084 CPixmapResize1();
01085
01086 GetWindowRect (ScilabXgc->hWndParent, &rect) ;
01087 GetWindowRect (ScilabXgc->CWindow, &rect1) ;
01088 xof = (rect.right-rect.left)- (rect1.right - rect1.left);
01089 yof = (rect.bottom-rect.top)- (rect1.bottom -rect1.top );
01090 if (sciGetwresize () == 0)
01091 {
01092 SetWindowPos (ScilabXgc->hWndParent, HWND_TOP, 0, 0,
01093 ScilabXgc->CWindowWidthView + xof +
01094 GetSystemMetrics (SM_CXVSCROLL),
01095 ScilabXgc->CWindowHeightView + yof +
01096 GetSystemMetrics (SM_CYHSCROLL),
01097 SWP_NOMOVE | SWP_NOZORDER);
01098 }
01099 else
01100 {
01101 SetWindowPos(ScilabXgc->hWndParent,HWND_TOP,0,0,
01102 ScilabXgc->CWindowWidthView + xof,
01103 ScilabXgc->CWindowHeightView + yof,
01104 SWP_NOMOVE | SWP_NOZORDER );
01105 }
01106 vertsi.nMax = ScilabXgc->CWindowHeight;
01107 vertsi.nPage = ScilabXgc->CWindowHeightView;
01108 horzsi.nMax = ScilabXgc->CWindowWidth;
01109 horzsi.nPage = ScilabXgc->CWindowWidthView;
01110 sciSetScrollInfo(ScilabXgc,SB_VERT, &(vertsi), TRUE);
01111 sciSetScrollInfo(ScilabXgc,SB_HORZ, &(horzsi), TRUE);
01112 if ( sciGetwresize() == 0 )
01113 {
01114
01115 if ( ScilabXgc->horzsi.nPos + ScilabXgc->CWindowWidthView <
01116 ScilabXgc->CWindowWidth
01117 && ScilabXgc->vertsi.nPos + ScilabXgc->CWindowHeightView <
01118 ScilabXgc->CWindowHeight)
01119 InvalidateRect(ScilabXgc->CWindow,NULL,FALSE);
01120 }
01121 }
01122 }
01123
01125 void C2F(getpopupdim)(verbose, x, narg,dummy)
01126 integer *verbose;
01127 integer *x;
01128 integer *narg;
01129 double *dummy;
01130 {
01131 x[0]= ScilabXgc->CWindowWidthView;
01132 x[1]= ScilabXgc->CWindowHeightView;
01133 *narg = 2;
01134 if (*verbose == 1)
01135 sciprint("\n ScilabXgc->CWindow dim :%d,%d\r\n",(int) x[0],(int) x[1]);
01136 }
01137
01138
01143 void C2F(setpopupdim)(x, y, v3, v4)
01144 integer *x;
01145 integer *y;
01146 integer *v3;
01147 integer *v4;
01148 {
01149
01150
01151
01152
01153
01154 GPopupResize(ScilabXgc,x,y);
01155 }
01156
01158 void C2F(setviewport)( integer * x, integer * y, integer * v3, integer * v4)
01159 {
01160 sciSetViewport( ScilabXgc->mafigure, *x, *y ) ;
01161 }
01162
01166 void C2F(getviewport)( integer * verbose, integer * x, integer * narg, double * dummy)
01167 {
01168 *narg = 2;
01169 sciGetViewport( ScilabXgc->mafigure, &x[0], &x[1] ) ;
01170 }
01171
01172
01173
01174
01175
01176 void C2F(setcurwin)(intnum, v2, v3, v4)
01177 integer *intnum;
01178 integer *v2;
01179 integer *v3;
01180 integer *v4;
01181 {
01182 struct BCG *bcgk;
01183 integer ierr;
01184 bcgk = ScilabXgc ;
01186 if (v2 != (integer *) 0) MenuFixCurrentWin(*intnum);
01187 if ( ScilabXgc == (struct BCG *) 0 )
01188 {
01190 C2F(initgraphic)("",intnum,&ierr,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01191 }
01192 else
01193 {
01194 if ( ScilabXgc->CurWindow != *intnum )
01195 {
01196 SwitchWindow(intnum);
01197 }
01198 }
01199 if ( ScilabXgc == (struct BCG *) 0 && bcgk != (struct BCG *) 0)
01200 {
01202 ScilabXgc = bcgk ;
01203 if (v2 != (integer *) 0) MenuFixCurrentWin(bcgk->CurWindow);
01204 }
01205 else
01206 {
01207
01208 RECT rect;
01209 GetClientRect(ScilabXgc->CWindow,&rect);
01210 ScilabXgc->CWindowWidthView = rect.right-rect.left;
01211 ScilabXgc->CWindowHeightView = rect.bottom-rect.top;
01212
01213 ScilabXgc->CWindowWidth = ScilabXgc->CWindowWidth;
01214 ScilabXgc->CWindowHeight = ScilabXgc->CWindowHeight;
01215 }
01216 }
01217
01218
01219
01220
01221
01222
01223 int SwitchWindow(integer *intnum)
01224 {
01226 struct BCG *SXgc;
01227 integer ierr;
01228 SXgc = getWindowXgcNumber(*intnum);
01229 if ( SXgc != (struct BCG *) 0 )
01230 {
01236 ReleaseWinHdc();
01237 ScilabXgc = SXgc;
01238 SetWinhdc();
01239 ResetScilabXgc ();
01242 get_window_scale(*intnum,NULL);
01243 }
01244 else
01245 {
01247 C2F(initgraphic)("",intnum,&ierr,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01248 }
01249 return(0);
01250 }
01251
01259 void C2F(getcurwin)(verbose, intnum, narg,dummy)
01260 integer *verbose;
01261 integer *intnum;
01262 integer *narg;
01263 double *dummy;
01264 {
01265 *narg =1 ;
01266 *intnum = (ScilabXgc != (struct BCG *) 0) ? ScilabXgc->CurWindow : 0;
01267 if (*verbose == 1)
01268 sciprint("\nCurrent Graphic Window :%d\r\n",(int) *intnum);
01269 }
01270
01272 void C2F(setclip)(x, y, w, h)
01273 integer *x;
01274 integer *y;
01275 integer *w;
01276 integer *h;
01277 {
01278 ScilabXgc->ClipRegionSet = 1;
01279 ScilabXgc->CurClipRegion[0]= *x;
01280 ScilabXgc->CurClipRegion[1]= *y;
01281 ScilabXgc->CurClipRegion[2]= *w;
01282 ScilabXgc->CurClipRegion[3]= *h;
01283 set_current_clip();
01284 }
01285
01286 static void set_current_clip()
01287 {
01288 HRGN hRgn;
01289 if (ScilabXgc->ClipRegionSet == 0) return;
01290 if (sciGetwresize() == 1) {
01291 hRgn = CreateRectRgn(ScilabXgc->CurClipRegion[0],
01292 ScilabXgc->CurClipRegion[1],
01293 ScilabXgc->CurClipRegion[2]
01294 + ScilabXgc->CurClipRegion[0],
01295 ScilabXgc->CurClipRegion[3]
01296 + ScilabXgc->CurClipRegion[1]);
01297 }
01298 else {
01299 hRgn = CreateRectRgn(ScilabXgc->CurClipRegion[0] - GetScrollPos(ScilabXgc->CWindow,SB_HORZ),
01300 ScilabXgc->CurClipRegion[1] - GetScrollPos(ScilabXgc->CWindow,SB_VERT),
01301 ScilabXgc->CurClipRegion[2]
01302 + ScilabXgc->CurClipRegion[0],
01303 ScilabXgc->CurClipRegion[3]
01304 + ScilabXgc->CurClipRegion[1]);
01305 }
01306 SelectClipRgn(hdc, hRgn);
01307 DeleteObject(hRgn);
01308 }
01309
01310 static void set_clip_after_scroll()
01311 {
01312 HRGN hRgn;
01313 if (ScilabXgc->ClipRegionSet == 1 && sciGetwresize() == 0)
01314 {
01315 hRgn = CreateRectRgn(ScilabXgc->CurClipRegion[0] - GetScrollPos(ScilabXgc->CWindow,SB_HORZ),
01316 ScilabXgc->CurClipRegion[1] - GetScrollPos(ScilabXgc->CWindow,SB_VERT),
01317 ScilabXgc->CurClipRegion[2]
01318 + ScilabXgc->CurClipRegion[0],
01319 ScilabXgc->CurClipRegion[3]
01320 + ScilabXgc->CurClipRegion[1]);
01321 SelectClipRgn(hdc, hRgn);
01322 DeleteObject(hRgn);
01323 }
01324 }
01325
01327 void C2F(unsetclip)(v1, v2, v3, v4)
01328 integer *v1;
01329 integer *v2;
01330 integer *v3;
01331 integer *v4;
01332 {
01333 ScilabXgc->ClipRegionSet = 0;
01334 SelectClipRgn(hdc,NULL);
01335 }
01336
01338 void C2F(getclip)(verbose, x, narg,dummy)
01339 integer *verbose;
01340 integer *x;
01341 integer *narg;
01342 double *dummy;
01343 {
01344 x[0] = ScilabXgc->ClipRegionSet;
01345 if ( x[0] == 1)
01346 {
01347 *narg = 5;
01348 x[1] =ScilabXgc->CurClipRegion[0];
01349 x[2] =ScilabXgc->CurClipRegion[1];
01350 x[3] =ScilabXgc->CurClipRegion[2];
01351 x[4] =ScilabXgc->CurClipRegion[3];
01352 }
01353 else *narg = 1;
01354 if (*verbose == 1) {
01355 if (ScilabXgc->ClipRegionSet == 1)
01356 sciprint("\nThere's a Clip Region :x:%d,y:%d,w:%d,h:%d\r\n",
01357 ScilabXgc->CurClipRegion[0],
01358 ScilabXgc->CurClipRegion[1],
01359 ScilabXgc->CurClipRegion[2],
01360 ScilabXgc->CurClipRegion[3]);
01361 else
01362 Scistring("\nNo Clip Region");
01363 }
01364 }
01365
01366
01367
01368
01369
01370
01371
01373 void C2F(setabsourel)(num, v2, v3, v4)
01374 integer *num;
01375 integer *v2;
01376 integer *v3;
01377 integer *v4;
01378 {
01379 if (*num == CoordModeOrigin )
01380 ScilabXgc->CurVectorStyle = CoordModeOrigin;
01381 else
01382 ScilabXgc->CurVectorStyle = CoordModePrevious ;
01383 }
01384
01386 void C2F(getabsourel)(verbose, num, narg,dummy)
01387 integer *verbose;
01388 integer *num;
01389 integer *narg;
01390 double *dummy;
01391 {
01392 *narg = 1;
01393 *num = ScilabXgc->CurVectorStyle ;
01394 if (*verbose == 1) {
01395 if (ScilabXgc->CurVectorStyle == CoordModeOrigin)
01396 Scistring("\nTrace Absolu");
01397 else
01398 Scistring("\nTrace Relatif");
01399 }
01400 }
01401
01405 static struct alinfo {
01406 char *name;
01407 int id;
01408 char *info;} AluStruc_[] =
01409 {
01410 {"GXclear" ,R2_WHITE," 0 "},
01411 {"GXand" ,R2_MASKPEN," src AND dst "},
01412 {"GXandReverse" ,R2_MASKPENNOT," src AND NOT dst "},
01413 {"GXcopy" ,R2_COPYPEN," src "},
01414 {"GXandInverted" ,R2_MASKNOTPEN," NOT src AND dst "},
01415 {"GXnoop" ,R2_NOP," dst "},
01416 {"GXxor" ,R2_XORPEN," src XOR dst "},
01417 {"GXor" ,R2_MERGEPEN," src OR dst "},
01418 {"GXnor" ,R2_NOTMERGEPEN," NOT src AND NOT dst "},
01419 {"GXequiv" ,R2_NOTXORPEN," NOT src XOR dst "},
01420 {"GXinvert" ,R2_NOT," NOT dst "},
01421 {"GXorReverse" ,R2_MERGEPENNOT," src OR NOT dst "},
01422 {"GXcopyInverted" ,R2_NOTCOPYPEN," NOT src "},
01423 {"GXorInverted" ,R2_MERGENOTPEN," NOT src OR dst "},
01424 {"GXnand" ,R2_NOTMASKPEN," NOT src OR NOT dst "},
01425 {"GXset" ,R2_BLACK," 1 "}
01426 };
01427
01428 static void idfromname(name1, num)
01429 char *name1;
01430 integer *num;
01431 {int i;
01432 *num = -1;
01433 for ( i =0 ; i < 16;i++)
01434 if (strcmp(AluStruc_[i].name,name1)== 0)
01435 *num=AluStruc_[i].id;
01436 if (*num == -1 )
01437 {
01438 Scistring("\n Use the following keys (integer in scilab");
01439 for ( i=0 ; i < 16 ; i++)
01440 sciprint("\nkey %s -> %s\r\n",AluStruc_[i].name,
01441 AluStruc_[i].info);
01442 }
01443 }
01444
01445
01446
01447
01448 void set_c(integer coli)
01449 {
01450 int i=0,id=0, width=0;
01451 COLORREF col=RGB(0,0,0);
01452 HBRUSH hBrush=NULL;
01453 HBRUSH hBrushOld=NULL;
01454 HPEN hpen=NULL;
01455 HPEN hpenOld=NULL;
01456 int style=0;
01457
01458 if (ScilabXgc->Colors == NULL) return;
01459
01460 i= Max(0,Min(coli,ScilabXgc->Numcolors + 1));
01461 ScilabXgc->CurColor = i ;
01462
01463 if ( ScilabXgc->CurDrawFunction != GXxor ) col = ScilabXgc->Colors[i];
01464 else col = ScilabXgc->Colors[i] ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
01465
01466 hBrush=CreateSolidBrush(col);
01467 hBrushOld=SelectObject(hdc,hBrush);
01468 if ( hBrushOld ) DeleteObject(hBrushOld);
01469 ScilabXgc->hBrush = hBrush;
01470
01471 id = ScilabXgc->CurDashStyle;
01472 style=DashTab[id];
01473
01474 width = ScilabXgc->CurLineWidth;
01475
01476 if ( (style == PS_SOLID) || (width<=1) )
01477 {
01478 hpen = CreatePen(style,ScilabXgc->CurLineWidth,col);
01479 }
01480 else
01481 {
01482 LOGBRUSH logbrush;
01483 logbrush.lbStyle = BS_SOLID;
01484 logbrush.lbColor = col;
01485 logbrush.lbHatch = 0;
01486 hpen = ExtCreatePen(PS_GEOMETRIC|PS_ENDCAP_FLAT|style,width,&logbrush,0,NULL);
01487 }
01488
01489 hpenOld=SelectObject(hdc,hpen);
01490 if (hpenOld) DeleteObject(hpenOld);
01491 ScilabXgc->hPen = hpen;
01492
01493 SetTextColor(hdc,col);
01494 }
01495
01496
01497
01498 void C2F(setalufunction)(string)
01499 char *string;
01500 {
01501 integer value;
01502 idfromname(string,&value);
01503 if ( value != -1)
01504 {
01505 SetROP2(hdc,(int) value);
01506 ScilabXgc->CurDrawFunction = value;
01507 set_c(ScilabXgc->CurColor);
01508 }
01509 }
01510
01511 void C2F(setalufunction1)(num, v2, v3, v4)
01512 integer *num;
01513 integer *v2;
01514 integer *v3;
01515 integer *v4;
01516 {
01517 int value;
01518 ScilabXgc->CurDrawFunction = Min(15,Max(0,*num));
01519 value=AluStruc_[ScilabXgc->CurDrawFunction].id;
01520 SetROP2(hdc,(int) value);
01521 if ( ScilabXgc->CurColorStatus == 1 )
01522 {
01526 set_c(ScilabXgc->CurColor);
01527 }
01528 }
01529
01530 void C2F(getalufunction)(verbose, value, narg,dummy)
01531 integer *verbose;
01532 integer *value;
01533 integer *narg;
01534 double *dummy;
01535 {
01536 *narg =1 ;
01537 *value = ScilabXgc->CurDrawFunction ;
01538 if (*verbose ==1 )
01539 {
01540 sciprint("\nThe Alufunction is %s -> <%s>\r\n",
01541 AluStruc_[*value].name,
01542 AluStruc_[*value].info);}
01543 }
01544
01549 void C2F(setthickness)(integer *value,integer *v2,integer *v3,integer *v4)
01550 {
01551 HPEN hpen=NULL ;
01552 HPEN hpenOld=NULL ;
01553
01554 int width =Max(0, *value);
01555 int style = DashTab[ScilabXgc->CurDashStyle];
01556
01557 ScilabXgc->CurLineWidth = width ;
01558
01559 if ( ScilabXgc->CurColorStatus == 1 )
01560 {
01561 COLORREF px = DefaultForeground ;
01562 if (ScilabXgc->Colors != NULL)
01563 {
01564 if ( ScilabXgc->CurDrawFunction != GXxor ) px= ScilabXgc->Colors[ScilabXgc->CurColor];
01565 else px = ScilabXgc->Colors[ScilabXgc->CurColor] ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
01566 }
01567
01568 if ( (style == PS_SOLID) || (width<=1) )
01569 {
01570 hpen = CreatePen(style,ScilabXgc->CurLineWidth,px);
01571 }
01572 else
01573 {
01574 LOGBRUSH logbrush;
01575 logbrush.lbStyle = BS_SOLID;
01576 logbrush.lbColor = px;
01577 logbrush.lbHatch = 0;
01578 hpen = ExtCreatePen(PS_GEOMETRIC|PS_ENDCAP_FLAT|style,width,&logbrush,0,NULL);
01579 }
01580 }
01581 else
01582 {
01583 if ( (style == PS_SOLID) || (width<=1) )
01584 {
01585 hpen = CreatePen(style,width,RGB(0,0,0));
01586 }
01587 else
01588 {
01589 LOGBRUSH logbrush;
01590 logbrush.lbStyle = BS_SOLID;
01591 logbrush.lbColor = RGB(0,0,0);
01592 logbrush.lbHatch = 0;
01593 hpen = ExtCreatePen(PS_GEOMETRIC|PS_ENDCAP_FLAT|style,width,&logbrush,0,NULL);
01594 }
01595 }
01596 hpenOld=SelectObject(hdc,hpen);
01597 if ( hpenOld ) DeleteObject(hpenOld);
01598 ScilabXgc->hPen = hpen;
01599 }
01600
01602 void C2F(getthickness)(integer *verbose,integer *value,integer *narg,double *dummy)
01603 {
01604 *narg =1 ;
01605 *value = ScilabXgc->CurLineWidth ;
01606 if (*verbose ==1 ) sciprint("\nLine Width:%d\r\n", ScilabXgc->CurLineWidth ) ;
01607 }
01608
01612 #define GREYNUMBER 17
01613
01615 HBRUSH Tabpix_[GREYNUMBER];
01616
01617 static WORD grey0[GREYNUMBER][8]={
01618 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
01619 {0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00},
01620 {0x00, 0x44, 0x00, 0x22, 0x08, 0x40, 0x01, 0x20},
01621 {0x00, 0x92, 0x00, 0x25, 0x00, 0x92, 0x00, 0xa4},
01622 {0x55, 0x00, 0xaa, 0x00, 0x55, 0x00, 0xaa, 0x00},
01623 {0xad, 0x00, 0x5b, 0x00, 0xda, 0x00, 0x6d, 0x00},
01624 {0x6d, 0x02, 0xda, 0x08, 0x6b, 0x10, 0xb6, 0x20},
01625 {0x6d, 0x22, 0xda, 0x0c, 0x6b, 0x18, 0xb6, 0x24},
01626 {0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa},
01627 {0x92, 0xdd, 0x25, 0xf3, 0x94, 0xe7, 0x49, 0xdb},
01628 {0x92, 0xfd, 0x25, 0xf7, 0x94, 0xef, 0x49, 0xdf},
01629 {0x52, 0xff, 0xa4, 0xff, 0x25, 0xff, 0x92, 0xff},
01630 {0xaa, 0xff, 0x55, 0xff, 0xaa, 0xff, 0x55, 0xff},
01631 {0xff, 0x6d, 0xff, 0xda, 0xff, 0x6d, 0xff, 0x5b},
01632 {0xff, 0xbb, 0xff, 0xdd, 0xf7, 0xbf, 0xfe, 0xdf},
01633 {0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff},
01634 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
01635 };
01636
01637 void C2F(CreatePatterns)()
01638 {
01639 integer i ;
01640 for ( i=0 ; i < GREYNUMBER ; i++)
01641 {
01642 HBITMAP hBitmap;
01643 hBitmap = CreateBitmap(8,8,1,1,grey0[i]);
01644 Tabpix_[i] =CreatePatternBrush(hBitmap);
01645 DeleteObject(hBitmap);
01646 }
01647 }
01648
01649 void C2F(setpattern)(num, v2, v3, v4)
01650 integer *num;
01651 integer *v2;
01652 integer *v3;
01653 integer *v4;
01654 { integer i ;
01655 if ( ScilabXgc->CurColorStatus == 1 )
01656 {
01657 set_c(*num-1);
01658 }
01659 else
01660 {
01661 i= Max(0,Min(*num-1,GREYNUMBER-1));
01662 ScilabXgc->CurPattern = i;
01663 SelectObject(hdc,Tabpix_[i]);
01664 }
01665 }
01666
01668 void C2F(getpattern)(verbose, num, narg,dummy)
01669 integer *verbose;
01670 integer *num;
01671 integer *narg;
01672 double *dummy;
01673 {
01674 *narg=1;
01675 if ( ScilabXgc->CurColorStatus == 1 )
01676 *num = ScilabXgc->CurColor +1 ;
01677 else
01678 *num = ScilabXgc->CurPattern +1 ;
01679 if (*verbose == 1) sciprint("\n Pattern : %d\r\n",ScilabXgc->CurPattern+1);
01680 }
01681
01683 void C2F(getlast)(verbose, num, narg,dummy)
01684 integer *verbose;
01685 integer *num;
01686 integer *narg;
01687 double *dummy;
01688 {
01689 if ( ScilabXgc->CurColorStatus == 1 )
01690 {
01691 *num = ScilabXgc->IDLastPattern + 1;
01692 if (*verbose == 1)
01693 sciprint("\n Id of Last Color %d\r\n",(int)*num);
01694 }
01695 else
01696 {
01697 *num = ScilabXgc->IDLastPattern + 1;
01698 if (*verbose == 1)
01699 sciprint("\n Id of Last Pattern %d\r\n",(int)*num);
01700 }
01701 *narg=1;
01702 }
01703
01704 void C2F(setdash)(integer *value,integer *v2,integer *v3,integer *v4)
01705 {
01706 static integer l3 ;
01707 COLORREF col=RGB(0,0,0) ;
01708 HPEN hpen=NULL;
01709 HPEN hpenOld=NULL;
01710 int id=0,width=0;
01711
01712 l3 = Max(0,Min(MAXDASH - 1,*value - 1));
01713
01714 width = ScilabXgc->CurLineWidth ;
01715
01716 if ( ScilabXgc->CurColorStatus == 1)
01717 {
01718 id = ScilabXgc->CurColor;
01719 if ( ScilabXgc->CurDrawFunction != GXxor ) col = ScilabXgc->Colors[id];
01720 else col = ScilabXgc->Colors[id] ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
01721 }
01722 else col=RGB(0,0,0);
01723
01724 {
01725 int style = DashTab[l3];
01726 if ( (style == PS_SOLID) || (width<=1) )
01727 {
01728 hpen = CreatePen(style,width,col);
01729 }
01730 else
01731 {
01732 LOGBRUSH logbrush;
01733 logbrush.lbStyle = BS_SOLID;
01734 logbrush.lbColor = col;
01735 logbrush.lbHatch = 0;
01736 hpen = ExtCreatePen(PS_GEOMETRIC|PS_ENDCAP_FLAT|style,width,&logbrush,0,NULL);
01737 }
01738 }
01739
01740
01741 hpenOld=SelectObject(hdc,hpen);
01742 if ( hpenOld ) DeleteObject(hpenOld);
01743 ScilabXgc->hPen = hpen;
01744 ScilabXgc->CurDashStyle = l3;
01745 }
01746
01747
01748
01749
01750
01757
01758 void C2F(set_dash_or_color)(value, v2, v3, v4)
01759 integer *value;
01760 integer *v2;
01761 integer *v3;
01762 integer *v4;
01763 {
01764 if ( ScilabXgc->CurColorStatus == 1) set_c(*value-1);
01765 else C2F(setdash)(value, v2, v3, v4);
01766 }
01767
01768 static void C2F(set_dash_and_color)(value, v2, v3, v4)
01769 integer *value;
01770 integer *v2;
01771 integer *v3;
01772 integer *v4;
01773 {
01774 C2F(setdash)(value, v2, v3, v4);
01775 C2F(setpattern)(value+6, v2, v3, v4);
01776 }
01777
01778 static void C2F(set_line_style)(value, v2, v3, v4)
01779 integer *value;
01780 integer *v2;
01781 integer *v3;
01782 integer *v4;
01783 {
01784 integer j;
01785 if (ScilabXgc->CurColorStatus == 0)
01786 C2F(setdash)(value,PI0,PI0,PI0);
01787 else {
01788 j= ScilabXgc->CurDashStyle + 1;
01789 C2F(setdash)(&j,PI0,PI0,PI0);
01790 C2F(setpattern)(value,PI0,PI0,PI0);
01791 }
01792 }
01793
01794 void C2F(getdash)( integer * verbose, integer * value, integer * narg, double * dummy)
01795 {
01796 *narg =1 ;
01797 *value =ScilabXgc->CurDashStyle+1;
01798 if ( *verbose == 1)
01799 {
01800 switch ( *value )
01801 {
01802 case 0: Scistring("\nLine style = Line Solid\n"); break ;
01803 case 1: Scistring("\nLine style = DASH\n"); break ;
01804 case 2: Scistring("\nLine style = DOT\n"); break ;
01805 case 3: Scistring("\nLine style = DASHDOT\n"); break ;
01806 case 4: Scistring("\nLine style = DASHDOTDOT\n"); break ;
01807 }
01808 }
01809 }
01810
01812
01813 void C2F(get_dash_or_color)(verbose, value, narg,dummy)
01814 integer *verbose;
01815 integer *value;
01816 integer *narg;
01817 double *dummy;
01818 {
01819
01820 if ( ScilabXgc->CurColorStatus == 1)
01821 {
01822 *narg =1 ;
01823 *value =ScilabXgc->CurColor+1;
01824 if (*verbose == 1) sciprint("Color %d",(int)*value);
01825 return;
01826 }
01827 C2F(getdash)(verbose, value, narg,dummy);
01828 }
01829
01830 static void C2F(get_dash_and_color)(verbose, value, narg,dummy)
01831 integer *verbose;
01832 integer *value;
01833 integer *narg;
01834 double *dummy;
01835 {
01836
01837 C2F(getdash)(verbose, value, narg,dummy);
01838 C2F(getpattern)(verbose, value+6, narg,dummy);
01839 *narg = 6;
01840 }
01841
01842
01843 void C2F(usecolor)(num, v1, v2, v3)
01844 integer *num;
01845 integer *v1;
01846 integer *v2;
01847 integer *v3;
01848 {
01849 integer i;
01850 i = Min(Max(*num,0),1);
01851 if ( ScilabXgc->CurColorStatus != (int) i)
01852 {
01853 if (ScilabXgc->CurColorStatus == 1)
01854 {
01855
01856
01857 ScilabXgc->CurColorStatus = 1;
01858 C2F(setpattern)((i=1,&i),PI0,PI0,PI0);
01859
01860 ScilabXgc->CurColorStatus = 0;
01861 i= ScilabXgc->CurPattern + 1;
01862 C2F(setpattern)(&i,PI0,PI0,PI0);
01863 i= ScilabXgc->CurDashStyle + 1;
01864 C2F(setdash)(&i,PI0,PI0,PI0);
01865 ScilabXgc->IDLastPattern = GREYNUMBER - 1;
01866 }
01867 else
01868 {
01869
01870
01871
01872 ScilabXgc->CurColorStatus = 0;
01873 C2F(setpattern)((i=1,&i),PI0,PI0,PI0);
01874 C2F(setdash)((i=1,&i),PI0,PI0,PI0);
01875
01876 ScilabXgc->CurColorStatus = 1;
01877 i= ScilabXgc->CurColor + 1;
01878 C2F(setpattern)(&i,PI0,PI0,PI0);
01879 ScilabXgc->IDLastPattern = ScilabXgc->Numcolors - 1;
01880 }
01881 }
01882 }
01883
01884 void C2F(getusecolor)(verbose, num, narg,dummy)
01885 integer *verbose;
01886 integer *num;
01887 integer *narg;
01888 double *dummy;
01889 {
01890 *num = ScilabXgc->CurColorStatus;
01891 if (*verbose == 1)
01892 sciprint("\n Use color %d\r\n",(int)*num);
01893 *narg=1;
01894 }
01895
01898 void C2F(setpixmapOn)(num, v2, v3, v4)
01899 integer *num;
01900 integer *v2;
01901 integer *v3;
01902 integer *v4;
01903 {
01904 integer num1= Min(Max(*num,0),1);
01905 if ( sciGetPixmapStatus() == num1 ) return;
01906 if ( num1 == 1 )
01907 {
01909 C2F(xinfo)("Animation mode is on,( xset('pixmap',0) to leave)",
01910 PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01911 if (( ScilabXgc->hdcCompat = CreateCompatibleDC (hdc)) == NULL)
01912 {
01913 sciprint("Setting pixmap on is impossible \r\n");
01914 return;
01915 }
01916 else
01917 {
01918 HBITMAP hbmTemp ;
01919 SetMapMode(ScilabXgc->hdcCompat, MM_TEXT);
01920 SetBkMode(ScilabXgc->hdcCompat,TRANSPARENT);
01921 SetTextAlign(ScilabXgc->hdcCompat, TA_LEFT|TA_BOTTOM);
01922 hbmTemp =CreateCompatibleBitmap (hdc,
01923 ScilabXgc->CWindowWidth,
01924 ScilabXgc->CWindowHeight);
01925
01926 if (!hbmTemp)
01927 {
01928 sciprint("Setting pixmap on is impossible \r\n");
01929 return;
01930 }
01931 else
01932 {
01933 HBITMAP hbmSave;
01934 hbmSave = SelectObject ( ScilabXgc->hdcCompat, hbmTemp);
01935 if ( ScilabXgc->hbmCompat != NULL)
01936 DeleteObject (ScilabXgc->hbmCompat);
01937 ScilabXgc->hbmCompat = hbmTemp;
01938 ScilabXgc->CurPixmapStatus = 1;
01939 C2F(pixmapclear)(PI0,PI0,PI0,PI0);
01941 SetGHdc(ScilabXgc->hdcCompat,ScilabXgc->CWindowWidth,
01942 ScilabXgc->CWindowHeight);
01943 ResetScilabXgc ();
01944 SetGHdc((HDC)0,ScilabXgc->CWindowWidth,
01945 ScilabXgc->CWindowHeight);
01946
01947 C2F(show)(PI0,PI0,PI0,PI0);
01948 }
01949 }
01950 }
01951 if ( num1 == 0 )
01952 {
01954 ScilabXgc->CurPixmapStatus = 0;
01956 if ( ScilabXgc->hdcCompat)
01957 SelectObject (ScilabXgc->hdcCompat, NULL) ;
01958 if ( ScilabXgc->hbmCompat)
01959 DeleteObject (ScilabXgc->hbmCompat);
01960 if ( ScilabXgc->hdcCompat)
01961 {
01962 if ( hdc == ScilabXgc->hdcCompat)
01963 hdc=TryToGetDC(ScilabXgc->CWindow);
01964 DeleteDC(ScilabXgc->hdcCompat);
01965 }
01966 ScilabXgc->hbmCompat = (HBITMAP) 0;
01967 ScilabXgc->hdcCompat = (HDC) 0;
01968 }
01969 }
01970
01971 void C2F(getpixmapOn)(integer *verbose, integer *value, integer *narg, double *dummy)
01972 {
01973 *value=sciGetPixmapStatus();
01974 *narg =1 ;
01975 if (*verbose == 1) sciprint("Color %d",(int)*value);
01976 }
01977
01978 integer sciGetPixmapStatus()
01979 {
01980 return ScilabXgc->CurPixmapStatus;
01981 }
01982
01985 void C2F(setwresize)( integer *num, integer *v2, integer *v3, integer *v4)
01986 {
01987 integer num1= Min(Max(*num,0),1);
01988 integer xtmp=0;
01989 integer ytmp=0;
01990 if ( ScilabXgc->CurResizeStatus == num1 )
01991 {
01992 static int count=0;
01993 wininfo(" ");
01994 return;
01995 }
01996 ScilabXgc->CurResizeStatus = num1;
01997 C2F(setwindowdim)((xtmp = ScilabXgc->CWindowWidthView, &xtmp),
01998 (ytmp=ScilabXgc->CWindowHeightView,&ytmp), PI0, PI0);
01999 SetViewportOrgEx(hdc,-ScilabXgc->horzsi.nPos,-ScilabXgc->vertsi.nPos,NULL);
02000 InvalidateRect(ScilabXgc->CWindow,NULL,FALSE);
02001 }
02002
02003 void C2F(getwresize)(verbose, value, narg,dummy)
02004 integer *verbose;
02005 integer *value;
02006 integer *narg;
02007 double *dummy;
02008 {
02009 *value = sciGetwresize();
02010 *narg =1 ;
02011 if (*verbose == 1) sciprint("Resize status %d",(int)*value);
02012 }
02013
02014
02015
02016
02017 integer sciGetwresize()
02018 {
02019 return ScilabXgc->CurResizeStatus;
02020 }
02021
02022 static int set_default_colormap_flag = 1;
02023
02024 int C2F(sedeco)( int * flag )
02025 {
02026 set_default_colormap_flag = *flag;
02027 return(0);
02028 }
02029
02030
02031
02032
02033
02034 void set_default_colormap()
02035 {
02036 int i,m;
02037 unsigned long maxcol;
02038 COLORREF *c = (COLORREF *) NULL;
02039 float *r = (float *) NULL;
02040 float *g = (float *) NULL;
02041 float *b = (float *) NULL;
02043 int iPlanes = GetDeviceCaps(hdc,PLANES);
02044 int iBitsPixel = GetDeviceCaps(hdc,BITSPIXEL);
02045
02048 if ( iBitsPixel > 24 ) iBitsPixel = 24;
02049 maxcol = 1 << ( iPlanes*iBitsPixel);
02050
02051
02052
02053
02054 if (set_default_colormap_flag == 0) return;
02055 if ( DEFAULTNUMCOLORS > maxcol) {
02056 sciprint("No enough colors for default colormap. Maximum is %d\r\n",
02057 maxcol);
02058 return;
02059 }
02060 m = DEFAULTNUMCOLORS;
02061
02062
02063 if(ScilabXgc->Colors != (COLORREF *) NULL)
02064 c = ScilabXgc->Colors;
02065
02066 if(ScilabXgc->Red != (float *) NULL)
02067 r = ScilabXgc->Red;
02068
02069 if(ScilabXgc->Green != (float *) NULL)
02070 g = ScilabXgc->Green;
02071
02072 if(ScilabXgc->Blue != (float *) NULL)
02073 b = ScilabXgc->Blue;
02074
02075 if (!XgcAllocColors(ScilabXgc,m)) {
02076 ScilabXgc->Colors = c;
02077 ScilabXgc->Red = r;
02078 ScilabXgc->Green = g;
02079 ScilabXgc->Blue = b;
02080 return;
02081 }
02082
02083
02084 for (i = 0; i < m; i++) {
02085 ScilabXgc->Red[i] = ((float)default_colors[3*i])/(float)255.0;
02086 ScilabXgc->Green[i] = (float)default_colors[3*i+1]/(float)255.0;
02087 ScilabXgc->Blue[i] = (float)default_colors[3*i+2]/(float)255.0;
02088 ScilabXgc->Colors[i] = RGB(default_colors[3*i],
02089 default_colors[3*i+1],
02090 default_colors[3*i+2]);
02091 }
02092
02093 ScilabXgc->Red[m] = ScilabXgc->Green[m] = ScilabXgc->Blue[m] =(float) 0;
02094 ScilabXgc->Colors[m]= RGB(0,0,0);
02095
02096
02097 ScilabXgc->Red[m+1] = ScilabXgc->Green[m+1] = ScilabXgc->Blue[m+1] = (float)1;
02098 ScilabXgc->Colors[m+1]= RGB(255,255,255);
02099
02100 ScilabXgc->Numcolors = m;
02101 ScilabXgc->IDLastPattern = m - 1;
02102 ScilabXgc->CmapFlag = 1;
02103
02104
02105 ScilabXgc->NumForeground = m;
02106 ScilabXgc->NumBackground = m + 1;
02107 FREE(c); FREE(r); FREE(g); FREE(b);
02108 }
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120 void C2F(setcolormap)(v1,v2,v3,v4,v5,v6,a)
02121 integer *v1,*v2;
02122 integer *v3;
02123 integer *v4,*v5,*v6;
02124 double *a;
02125 {
02126 unsigned long maxcol;
02127 int iPlanes = GetDeviceCaps(hdc,PLANES);
02128 int iBitsPixel = GetDeviceCaps(hdc,BITSPIXEL);
02129
02130 *v3 = 0;
02131
02133 if ( iBitsPixel > 24 ) iBitsPixel = 24;
02134 maxcol = 1 << ( iPlanes*iBitsPixel);
02135
02137 if (*v2 != 3 || (unsigned long) *v1 > maxcol || *v1 < 0) {
02138 sciprint("Colormap must be a m x 3 array with m <= %d\r\n",maxcol);
02139 *v3 = 1;
02140 return;
02141 }
02142 setcolormapg(ScilabXgc,v1,v2,a,v3);
02143 }
02144
02145 void C2F(setgccolormap)(v1,v2,a,XGC,v3)
02146 integer *v1,*v2;
02147 double *a;
02148 struct BCG *XGC;
02149 integer *v3;
02150 {
02151
02152 setcolormapg(XGC,v1,v2,a,v3);
02153 }
02154
02155 void setcolormapg(struct BCG *Xgc,integer *v1, integer *v2, double *a, integer *v3)
02156 {
02157 int i,palstatus ,m;
02158 unsigned long maxcol;
02159 COLORREF *c = (COLORREF *) NULL;
02160 float *r = (float *) NULL;
02161 float *g = (float *) NULL;
02162 float *b = (float *) NULL;
02164 int iPlanes = GetDeviceCaps(hdc,PLANES);
02165 int iBitsPixel = GetDeviceCaps(hdc,BITSPIXEL);
02166
02167 if ( ScilabXgc->CurPixmapStatus == 1)
02168 hdc = Xgc->hdcCompat;
02169 else
02170 hdc=TryToGetDC(Xgc->CWindow);
02171
02173 if ( iBitsPixel > 24 ) iBitsPixel = 24;
02174 maxcol = 1 << ( iPlanes*iBitsPixel);
02175 palstatus= (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE);
02176
02177
02178 m = *v1;
02179
02180
02181 if(Xgc->Colors != (COLORREF *) NULL)
02182 c = Xgc->Colors;
02183
02184 if(Xgc->Red != (float *) NULL)
02185 r = Xgc->Red;
02186
02187 if(Xgc->Green != (float *) NULL)
02188 g = Xgc->Green;
02189
02190 if(Xgc->Blue != (float *) NULL)
02191 b = Xgc->Blue;
02192
02193 if (!XgcAllocColors(Xgc,m)) {
02194 Xgc->Colors = c;
02195 Xgc->Red = r;
02196 Xgc->Green = g;
02197 Xgc->Blue = b;
02198 *v3 = 1;
02199 return;
02200 }
02201
02202
02203 for (i = 0; i < m; i++) {
02204 if (a[i] < 0 || a[i] > 1 || a[i+m] < 0 || a[i+m] > 1 ||
02205 a[i+2*m] < 0 || a[i+2*m]> 1) {
02206 Scistring("RGB values must be between 0 and 1\n");
02207 Xgc->Colors = c;
02208 Xgc->Red = r;
02209 Xgc->Green = g;
02210 Xgc->Blue = b;
02211 *v3 = 1;
02212 return;
02213 }
02214 Xgc->Red[i] = (float)a[i];
02215 Xgc->Green[i] = (float)a[i+m];
02216 Xgc->Blue[i] = (float)a[i+2*m];
02217 Xgc->Colors[i] = RGB((unsigned short) (255.0*a[i]),
02218 (unsigned short) (255.0*a[i+m]),
02219 (unsigned short) (255.0*a[i+2*m]));
02220 }
02221
02222 Xgc->Red[m] = Xgc->Green[m] = Xgc->Blue[m] = (float) 0;
02223 Xgc->Colors[m]= RGB(0,0,0);
02224
02225
02226 Xgc->Red[m+1] = Xgc->Green[m+1] = Xgc->Blue[m+1] = (float) 0;
02227 Xgc->Colors[m+1]= RGB(255,255,255);
02228
02229 Xgc->Numcolors = m;
02230 Xgc->IDLastPattern = m - 1;
02231 Xgc->CmapFlag = 0;
02232 Xgc->NumForeground = m;
02233 Xgc->NumBackground = m + 1;
02234 C2F(usecolor)((i=1,&i) ,PI0,PI0,PI0);
02236 C2F(setpattern)((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);
02237 C2F(setalufunction1)(&Xgc->CurDrawFunction,PI0,PI0,PI0);
02238 C2F(setforeground)((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);
02239 C2F(setbackground)((i=Xgc->NumForeground+2,&i),PI0,PI0,PI0);
02240 FREE(c); FREE(r); FREE(g); FREE(b);
02241 }
02242
02243
02244 void C2F(pal_setcolormap)(v1,v2,v3,v4,v5,v6,a)
02245 integer *v1,*v2;
02246 integer *v3;
02247 integer *v4,*v5,*v6;
02248 double *a;
02249 {
02250 int i,m,maxcol;
02251 COLORREF *c = (COLORREF *) NULL;
02252 float *r = (float *) NULL;
02253 float *g = (float *) NULL;
02254 float *b = (float *) NULL;
02255 int iPlanes = GetDeviceCaps(hdc,PLANES);
02256 int iBitsPixel = GetDeviceCaps(hdc,BITSPIXEL);
02257
02258 *v3 = 0;
02259
02262 if ( iBitsPixel > 24 ) iBitsPixel = 24;
02263 maxcol = 1 << ( iPlanes*iBitsPixel);
02264
02265 if (*v2 != 3 || *v1 > maxcol || *v1 < 0) {
02266 sciprint("Colormap must be a m x 3 array with m <= %d\r\n",maxcol);
02267 *v3 = 1;
02268 return;
02269 }
02270 m = *v1;
02271
02272
02273 if(ScilabXgc->Colors != (COLORREF *) NULL)
02274 c = ScilabXgc->Colors;
02275
02276 if(ScilabXgc->Red != (float *) NULL)
02277 r = ScilabXgc->Red;
02278
02279 if(ScilabXgc->Green != (float *) NULL)
02280 g = ScilabXgc->Green;
02281
02282 if(ScilabXgc->Blue != (float *) NULL)
02283 b = ScilabXgc->Blue;
02284
02285 if (!XgcAllocColors(ScilabXgc,m)) {
02286 ScilabXgc->Colors = c;
02287 ScilabXgc->Red = r;
02288 ScilabXgc->Green = g;
02289 ScilabXgc->Blue = b;
02290 *v3 = 1;
02291 return;
02292 }
02293
02294
02295 for (i = 0; i < m; i++) {
02296 if (a[i] < 0 || a[i] > 1 || a[i+m] < 0 || a[i+m] > 1 ||
02297 a[i+2*m] < 0 || a[i+2*m]> 1) {
02298 Scistring("RGB values must be between 0 and 1\n");
02299 ScilabXgc->Colors = c;
02300 ScilabXgc->Red = r;
02301 ScilabXgc->Green = g;
02302 ScilabXgc->Blue = b;
02303 *v3 = 1;
02304 return;
02305 }
02306 ScilabXgc->Red[i] = (float)a[i];
02307 ScilabXgc->Green[i] = (float)a[i+m];
02308 ScilabXgc->Blue[i] = (float)a[i+2*m];
02309 ScilabXgc->Colors[i] = RGB((unsigned short) (255.0*a[i]),
02310 (unsigned short) (255.0*a[i+m]),
02311 (unsigned short) (255.0*a[i+2*m]));
02312 }
02313
02314 ScilabXgc->Red[m] = ScilabXgc->Green[m] = ScilabXgc->Blue[m] = (float) 0;
02315 ScilabXgc->Colors[m]= RGB(0,0,0);
02316
02317
02318 ScilabXgc->Red[m+1] = ScilabXgc->Green[m+1] = ScilabXgc->Blue[m+1] = (float) 0;
02319 ScilabXgc->Colors[m+1]= RGB(255,255,255);
02320
02321 if ((GetDeviceCaps(hdc, RASTERCAPS)) & RC_PALETTE )
02322 {
02323 if ( SciPalette(m) == FALSE )
02324 {
02325 for (i = 0; i < m; i++) {
02326 ScilabXgc->Colors[i] = RGB((unsigned short) (255.0*a[i]),
02327 (unsigned short) (255.0*a[i+m]),
02328 (unsigned short) (255.0*a[i+2*m]));
02329 }
02330 ScilabXgc->Colors[m]= RGB(0,0,0);
02331 ScilabXgc->Colors[m+1]= RGB(255,255,255);
02332 }
02333 }
02334 ScilabXgc->Numcolors = m;
02335 ScilabXgc->IDLastPattern = m - 1;
02336 ScilabXgc->CmapFlag = 0;
02337 ScilabXgc->NumForeground = m;
02338 ScilabXgc->NumBackground = m + 1;
02339 C2F(usecolor)((i=1,&i) ,PI0,PI0,PI0);
02341 C2F(setpattern)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
02342 C2F(setalufunction1)(&ScilabXgc->CurDrawFunction,PI0,PI0,PI0);
02343 C2F(setpattern)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
02344 C2F(setforeground)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
02345 C2F(setbackground)((i=ScilabXgc->NumForeground+2,&i),PI0,PI0,PI0);
02346 FREE(c); FREE(r); FREE(g); FREE(b);
02347 }
02348
02349 static BOOL SciPalette(int iNumClr)
02350 {
02351 static HPALETTE hPal=NULL;
02352 LOGPALETTE *plogPal;
02353 UINT uiSizPal;
02354 INT i;
02355 uiSizPal = sizeof(WORD)*2 + sizeof(PALETTEENTRY)*iNumClr;
02356 if ((plogPal = (LOGPALETTE *) LocalAlloc(LMEM_FIXED,uiSizPal)) == NULL) {
02357 sciprint("Fail in Allocating palette!\r\n");
02358 hPal = NULL;
02359 return FALSE;
02360 }
02361 plogPal->palVersion = 0x300;
02362 plogPal->palNumEntries = (WORD) iNumClr;
02363
02364 for (i=0; i<iNumClr; i++)
02365 {
02366 plogPal->palPalEntry[i].peRed =(unsigned char) (255.0* ScilabXgc->Red[i]);
02367 plogPal->palPalEntry[i].peGreen =(unsigned char) (255.0* ScilabXgc->Green[i]);
02368 plogPal->palPalEntry[i].peBlue =(unsigned char) (255.0* ScilabXgc->Blue[i]);
02369 plogPal->palPalEntry[i].peFlags = PC_RESERVED;
02370 ScilabXgc->Colors[i]=PALETTERGB(plogPal->palPalEntry[i].peRed,
02371 plogPal->palPalEntry[i].peGreen,
02372 plogPal->palPalEntry[i].peBlue);
02373 }
02374
02375 if ( hPal != (HPALETTE) NULL) DeleteObject(hPal);
02376 hPal = CreatePalette((LPLOGPALETTE)plogPal);
02377 if ((hPal) == NULL) {
02378 sciprint("Fail in creating palette!\r\n");
02379 return FALSE;
02380 }
02381 SelectPalette(hdc, hPal, FALSE);
02382 RealizePalette(hdc);
02384 GlobalFree(plogPal);
02385 return TRUE;
02386 }
02387
02388
02389 void C2F(getcolormapsize)(integer *verbose, integer *num, integer *narg, double *val)
02390 {
02391 if(ScilabXgc != NULL)
02392 *num = ScilabXgc->Numcolors;
02393 else
02394 {
02395 sciprint("No ScilabXgc allocated\n");
02396 *num = 0;
02397 return;
02398 }
02399 }
02400
02401
02402
02403 void C2F(getcolormap)(verbose,num,narg,val)
02404 integer *verbose;
02405 integer *num;
02406 integer *narg;
02407 double *val;
02408 {
02409 int m = ScilabXgc->Numcolors;
02410 int i;
02411 *narg = 1;
02412 *num = m;
02413 for (i = 0; i < m; i++) {
02414 val[i] = (double)ScilabXgc->Red[i];
02415 val[i+m] = (double)ScilabXgc->Green[i];
02416 val[i+2*m] = (double)ScilabXgc->Blue[i];
02417 }
02418 if (*verbose == 1) {
02419 sciprint("Size of colormap: %d colors\r\n",m);
02420 }
02421 }
02422
02424 void C2F(setbackground)( integer * num, integer * v2, integer * v3, integer * v4)
02425 {
02426 if (ScilabXgc->CurColorStatus == 1)
02427 {
02428 COLORREF px;
02429 ScilabXgc->NumBackground = Max(0,Min(*num - 1,ScilabXgc->Numcolors + 1));
02430 C2F(setalufunction1)(&ScilabXgc->CurDrawFunction,PI0,PI0,PI0);
02431 px = (ScilabXgc->Colors == NULL) ? DefaultBackground : ScilabXgc->Colors[ScilabXgc->NumBackground];
02432
02439 }
02440 }
02441
02442 void C2F(getbackground)(verbose, num, narg,dummy)
02443 integer *verbose;
02444 integer *num;
02445 integer *narg;
02446 double *dummy;
02447 {
02448 *narg=1;
02449 if ( ScilabXgc->CurColorStatus == 1 )
02450 {
02451 *num = ScilabXgc->NumBackground + 1;
02452 }
02453 else
02454 {
02455 *num = 1;
02456 }
02457 if (*verbose == 1)
02458 sciprint("\n Background : %d\r\n",*num);
02459 }
02460
02462 void C2F(setforeground)( integer * num, integer * v2, integer * v3, integer * v4)
02463 {
02464 if (ScilabXgc->CurColorStatus == 1)
02465 {
02466 COLORREF px;
02467 ScilabXgc->NumForeground = Max(0,Min(*num - 1,ScilabXgc->Numcolors + 1));
02468 C2F(setalufunction1)(&ScilabXgc->CurDrawFunction,PI0,PI0,PI0);
02469 px = (ScilabXgc->Colors == NULL) ? DefaultForeground
02470 : ScilabXgc->Colors[ScilabXgc->NumForeground];
02472 }
02473 }
02474
02475 void C2F(getforeground)(verbose, num, narg,dummy)
02476 integer *verbose;
02477 integer *num;
02478 integer *narg;
02479 double *dummy;
02480 {
02481 *narg=1;
02482 if ( ScilabXgc->CurColorStatus == 1 )
02483 {
02484 *num = ScilabXgc->NumForeground + 1;
02485 }
02486 else
02487 {
02488 *num = 1;
02489 }
02490 if (*verbose == 1)
02491 sciprint("\n Foreground : %d\r\n",*num);
02492 }
02493
02495 void C2F(sethidden3d)(num, v2, v3, v4)
02496 integer *num;
02497 integer *v2;
02498 integer *v3;
02499 integer *v4;
02500 {
02501 if (ScilabXgc->CurColorStatus == 1)
02502 {
02503
02504 ScilabXgc->NumHidden3d = Max(-2,Min(*num - 1,ScilabXgc->Numcolors + 1));
02505 }
02506 }
02507
02508 void C2F(gethidden3d)(verbose, num, narg,dummy)
02509 integer *verbose;
02510 integer *num;
02511 integer *narg;
02512 double *dummy;
02513 {
02514 *narg=1;
02515 if ( ScilabXgc->CurColorStatus == 1 )
02516 {
02517 *num = ScilabXgc->NumHidden3d + 1;
02518 }
02519 else
02520 {
02521 *num = 1;
02522 }
02523 if (*verbose == 1) sciprint("\n Hidden3d : %d\r\n",*num);
02524 }
02525
02526
02527
02528
02529
02530
02531
02532 int CheckColormap(m)
02533 int *m;
02534 {
02535 if ( ScilabXgc != (struct BCG *) 0 )
02536 {
02537 *m = ScilabXgc->Numcolors;
02538 if ( ScilabXgc->CmapFlag != 1)
02539 return 1;
02540 else
02541 return 0;
02542 }
02543 else {
02544 *m=0;
02545 return(0);}
02546 }
02547
02548 void get_r(i,r)
02549 int i;
02550 float *r;
02551 {
02552 *r = ScilabXgc->Red[i];
02553 }
02554
02555 void get_g(i,g)
02556 int i;
02557 float *g;
02558 {
02559 *g = ScilabXgc->Green[i];
02560 }
02561
02562 void get_b(i,b)
02563 float *b;
02564 int i;
02565 {
02566 *b = ScilabXgc->Blue[i];
02567 }
02568
02569
02570
02571
02572
02573
02574
02575 static void InitMissileXgc();
02576
02577
02578 void C2F(sempty)(verbose, v2, v3, v4)
02579 integer *verbose;
02580 integer *v2;
02581 integer *v3;
02582 integer *v4;
02583 {
02584 if ( *verbose ==1 ) Scistring("\n No operation ");
02585 }
02586
02587 void C2F(gempty)(verbose, v2, v3,dummy)
02588 integer *verbose;
02589 integer *v2;
02590 integer *v3;
02591 double *dummy;
02592 {
02593 if ( *verbose ==1 ) Scistring("\n No operation ");
02594 }
02595
02596 #define NUMSETFONC 32
02597
02600 static struct bgc { char *name ;
02601 void (*setfonc )() ;
02602 void (*getfonc )() ;}
02603
02604 MissileGCTab_[] = {
02605 {"alufunction",C2F(setalufunction1),C2F(getalufunction)},
02606 {"background",C2F(setbackground),C2F(getbackground)},
02607 {"clipoff",C2F(unsetclip),C2F(getclip)},
02608 {"clipping",C2F(setclip),C2F(getclip)},
02609 {"cmap_size",C2F(sempty),C2F(getcolormapsize)},
02610 {"color",C2F(setpattern),C2F(getpattern)},
02611 {"colormap",C2F(setcolormap),C2F(getcolormap)},
02612 {"dashes",C2F(set_dash_or_color),C2F(get_dash_or_color)},
02613 {"default",InitMissileXgc, C2F(gempty)},
02614 {"figure",C2F(setscilabFigure),C2F(getscilabFigure)},
02615 {"font",C2F(xsetfont),C2F(xgetfont)},
02616 {"foreground",C2F(setforeground),C2F(getforeground)},
02617 {"gc",C2F(setscilabxgc),C2F(getscilabxgc)},
02618 {"gccolormap",C2F(setgccolormap),C2F(getcolormap)},
02619 {"hidden3d",C2F(sethidden3d),C2F(gethidden3d)},
02620 {"lastpattern",C2F(sempty),C2F(getlast)},
02621 {"line mode",C2F(setabsourel),C2F(getabsourel)},
02622 {"line style",C2F(setdash),C2F(getdash)},
02623 {"mark",C2F(xsetmark),C2F(xgetmark)},
02624 {"pattern",C2F(setpattern),C2F(getpattern)},
02625 {"pixmap",C2F(setpixmapOn),C2F(getpixmapOn)},
02626 {"thickness",C2F(setthickness),C2F(getthickness)},
02627 {"use color",C2F(usecolor),C2F(getusecolor)},
02628 {"viewport", C2F(setviewport), C2F(getviewport)},
02629 {"wdim",C2F(setwindowdim),C2F(getwindowdim)},
02630 {"white",C2F(sempty),C2F(getlast)},
02631 {"window",C2F(setcurwin),C2F(getcurwin)},
02632 {"wpdim",C2F(setpopupdim),C2F(getpopupdim)},
02633 {"wpos",C2F(setwindowpos),C2F(getwindowpos)},
02634 {"wresize",C2F(setwresize),C2F(getwresize)},
02635 {"wshow",C2F(show),C2F(gempty)},
02636 {"wwpc",C2F(pixmapclear),C2F(gempty)}
02637 };
02638
02639 #ifdef lint
02640
02641
02642
02643 static
02644 test(str,flag,verbose,x1,x2,x3,x4,x5)
02645 char str[];
02646 integer flag ;
02647 integer *verbose,*x1,*x2,*x3,*x4,*x5;
02648 {
02649 double *dv;
02650 C2F(setalufunction1)(x1,x2,x3,x4);C2F(getalufunction)(verbose,x1,x2,dv);
02651 C2F(setclip)(x1,x2,x3,x4);C2F(getclip)(verbose,x1,x2,dv);
02652 C2F(unsetclip)(x1,x2,x3,x4);C2F(getclip)(verbose,x1,x2,dv);
02653 C2F(setdash)(x1,x2,x3,x4);C2F(getdash)(verbose,x1,x2,dv);
02654 InitMissileXgc(x1,x2,x3,x4); C2F(gempty)(verbose,x1,x2,dv);
02655 C2F(xsetfont)(x1,x2,x3,x4);C2F(xgetfont)(verbose,x1,x2,dv);
02656 C2F(setabsourel)(x1,x2,x3,x4);C2F(getabsourel)(verbose,x1,x2,dv);
02657 C2F(xsetmark)(x1,x2,x3,x4);C2F(xgetmark)(verbose,x1,x2,dv);
02658 C2F(setpattern)(x1,x2,x3,x4);C2F(getpattern)(verbose,x1,x2,dv);
02659 C2F(setpixmapOn)(x1,x2,x3,x4);C2F(getpixmapOn)(verbose,x1,x2,dv);
02660 C2F(setthickness)(x1,x2,x3,x4);C2F(getthickness)(verbose,x1,x2,dv);
02661 C2F(usecolor)(x1,x2,x3,x4);C2F(gempty)(verbose,x1,x2,dv);
02662 C2F(setwindowdim)(x1,x2,x3,x4);C2F(getwindowdim)(verbose,x1,x2,dv);
02663 C2F(sempty)(x1,x2,x3,x4);C2F(getwhite)(verbose,x1,x2,dv);
02664 C2F(setcurwin)(x1,x2,x3,x4);C2F(getcurwin)(verbose,x1,x2,dv);
02665 C2F(setwindowpos)(x1,x2,x3,x4);C2F(getwindowpos)(verbose,x1,x2,dv);
02666 C2F(show)(x1,x2,x3,x4);C2F(gempty)(verbose,x1,x2,dv);
02667 C2F(pixmapclear)(x1,x2,x3,x4);gempty(verbose,x1,x2,dv);
02668 }
02669
02670 #endif
02671
02672 void C2F(MissileGCGetorSet)(char *str,integer flag,integer *verbose,integer *x1,integer *x2,integer *x3,integer *x4,integer *x5,integer *x6,double *dv1)
02673 {
02674 integer i ;
02675 for (i=0; i < NUMSETFONC ; i++)
02676 {
02677 integer j;
02678 j = strcmp(str,MissileGCTab_[i].name);
02679 if ( j == 0 )
02680 {
02681 #ifdef _DEBUG
02682 if (*verbose == 1) sciprint("\nGetting Info on %s\r\n",str);
02683 #endif
02684 if (flag == 1) (MissileGCTab_[i].getfonc)(verbose,x1,x2,dv1);
02685 else (MissileGCTab_[i].setfonc)(x1,x2,x3,x4,x5,x6,dv1);
02686 return;
02687 }
02688 else
02689 {
02690 if ( j <= 0)
02691 {
02692 sciprint("\nUnknow X operator <%s>\r\n",str);
02693 *x1=1;*x2=0;
02694 return;
02695 }
02696 }
02697 }
02698 sciprint("\n Unknow X operator <%s>\r\n",str);
02699 *x1=1;
02700 *x2=0;
02701 }
02702
02703 void C2F(MissileGCget)(str, verbose, x1, x2, x3, x4, x5,dv1, dv2, dv3, dv4)
02704 char *str;
02705 integer *verbose;
02706 integer *x1; integer *x2; integer *x3; integer *x4;
02707 integer *x5; double *dv1; double *dv2; double *dv3; double *dv4;
02708 {
02709 int x6=0;
02710 C2F(MissileGCGetorSet)(str,1L,verbose,x1,x2,x3,x4,x5,&x6,dv1);
02711 }
02712
02713 void C2F(MissileGCset)(str, x1, x2, x3, x4, x5, x6, dv1, dv2, dv3, dv4)
02714 char *str;
02715 integer *x1;
02716 integer *x2;
02717 integer *x3;
02718 integer *x4;
02719 integer *x5;
02720 integer *x6;
02721 double *dv1;
02722 double *dv2;
02723 double *dv3;
02724 double *dv4;
02725 {
02726 integer verbose=0 ;
02727 C2F(MissileGCGetorSet)(str,0L,&verbose,x1,x2,x3,x4,x5,x6,dv1);
02728 }
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744 void C2F(displaystring)(string, x, y, v1, flag, v6, v7, angle, dv2, dv3, dv4)
02745 char *string;
02746 integer *x,*y,*v1,*flag,*v6,*v7;
02747 double *angle,*dv2,*dv3,*dv4;
02748 {
02749 if ( Abs(*angle) <= 0.1)
02750 {
02751 if ( ScilabXgc->CurDrawFunction == GXxor )
02752 {
02753 SIZE size ;
02754 GetTextExtentPoint32(hdc,string,strlen(string),&size);
02755 XorString(*x,*y,string,size.cx,size.cy);
02756 }
02757 else
02758 {
02759 SetBkMode(hdc, TRANSPARENT);
02760 TextOut(hdc,(int) *x,(int) *y,string,strlen(string));
02761 SetBkMode(hdc, OPAQUE);
02762 }
02763 if ( *flag == 1)
02764 {
02765 integer rect[4];
02766 C2F(boundingbox)(string,x,y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02767 C2F(drawrectangle)(string,rect,rect+1,rect+2,rect+3,PI0,PI0,PD0,PD0,PD0,PD0);
02768 }
02769 }
02770 else
02771 {
02772 C2F(DispStringAngle)(x,y,string,angle);
02773 }
02774 }
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784 #define FONTNUMBER 10 // F.Leray FONTNUMBER set to 10 pb not solved: font Id 9 has always the same size
02785
02786 #define FONTMAXSIZE 6
02787 #define SYMBOLNUMBER 10
02788
02789
02790
02791
02792
02793
02794
02795
02796
02797
02798 typedef struct tagFontInfo {
02799 integer ok;
02800 char fname[100];
02801 HFONT hf[FONTMAXSIZE];
02802 } FontInfoT[FONTNUMBER];
02803
02804 static int scale_font_size = 1;
02805 static FontInfoT FontInfoTab;
02806 static FontInfoT FontInfoTabPrinter;
02808 static FontInfoT *FontTab = &FontInfoTab;
02809
02810 static char *size_[] = { "08" ,"10","12","14","18","24"};
02811 static int size_n_[] = {8,10,12,14,18,24};
02812
02816 typedef struct { integer xoffset[FONTMAXSIZE][SYMBOLNUMBER];
02817 integer yoffset[FONTMAXSIZE][SYMBOLNUMBER];} Offset ;
02818 static Offset ListOffset;
02819 static Offset ListOffsetPrint;
02820 static Offset *SymbOffset = &ListOffset;
02821
02822 static char Marks[] = {
02823
02824 (char)46,(char)43,(char)180,(char)42, (char)168,(char)224,
02825 (char)196,(char)209,(char)167,(char)176,};
02826
02830 typedef struct {
02831 char *alias; char *name; char *Winname;
02832 } FontAlias;
02833
02836 FontAlias fonttab[] ={
02837 {"CourR", "-adobe-courier-medium-r-normal--*-%s0-*-*-m-*-iso8859-1","Courier New"},
02838 {"Symb", "-adobe-symbol-medium-r-normal--*-%s0-*-*-p-*-adobe-fontspecific","Symbol"},
02839 {"TimR", "-adobe-times-medium-r-normal--*-%s0-*-*-p-*-iso8859-1","Times New Roman"},
02840 {"TimI", "-adobe-times-medium-i-normal--*-%s0-*-*-p-*-iso8859-1","Times New Roman Italic"},
02841 {"TimB", "-adobe-times-bold-r-normal--*-%s0-*-*-p-*-iso8859-1","Times New Roman Bold"},
02842 {"TimBI", "-adobe-times-bold-i-normal--*-%s0-*-*-p-*-iso8859-1","Times New Roman Bold Italic"},
02843 {"HelvR", "-adobe-helvetica-medium-r-normal--*-%s0-*-*-p-*-iso8859-1","Arial"},
02844 {"HelvO", "-adobe-helvetica-medium-o-normal--*-%s0-*-*-p-*-iso8859-1","Arial Italic"},
02845 {"HelvB", "-adobe-helvetica-bold-r-normal--*-%s0-*-*-p-*-iso8859-1", "Arial Bold"},
02846 {"HelvBO","-adobe-helvetica-bold-o-normal--*-%s0-*-*-p-*-iso8859-1", "Arial Bold Italic"},
02847 {(char *) NULL,( char *) NULL}
02848 };
02849
02850
02851
02852
02853 void C2F(DispStringAngle)( integer * x0, integer * yy0, char * string, double * angle)
02854 {
02855
02856 HFONT hfnt, hfntPrev;
02857 size_t pcch;
02858 LOGFONT lf;
02859 char *p;
02860
02861 memset(&lf, 0, sizeof(LOGFONT));
02862 strncpy(lf.lfFaceName,(*FontTab)[ScilabXgc->FontId].fname,LF_FACESIZE);
02863
02864 lf.lfHeight = - size_n_[ScilabXgc->FontSize]*scale_font_size;
02865 lf.lfCharSet = DEFAULT_CHARSET;
02866 if ( (p = strstr((*FontTab)[ScilabXgc->FontId].fname," Italic")) != (LPSTR)NULL ) {
02867 lf.lfFaceName[ (unsigned int)(p- (*FontTab)[ScilabXgc->FontId].fname) ] = '\0';
02868 lf.lfItalic = TRUE;
02869 }
02870 if ( (p = strstr((*FontTab)[ScilabXgc->FontId].fname," Bold")) != (LPSTR)NULL ) {
02871 lf.lfFaceName[ (unsigned int)(p- (*FontTab)[ScilabXgc->FontId].fname) ] = '\0';
02872 lf.lfWeight = FW_BOLD;
02873 }
02874
02875 SetBkMode(hdc, TRANSPARENT);
02876
02877
02878
02879 lf.lfEscapement = (int) (-(*angle)*10);
02880
02881 hfnt = CreateFontIndirect((LOGFONT FAR *)&lf);
02882 hfntPrev = SelectObject(hdc, hfnt);
02883
02884 pcch = strlen(string);
02885
02886 TextOut(hdc, *x0, *yy0, string, pcch);
02887 SelectObject(hdc, hfntPrev);
02888
02889 DeleteObject(hfnt);
02890
02891
02892
02893 SetBkMode(hdc, OPAQUE);
02894
02895 }
02896
02897 int XorString(x,y,string,fWidth,fHeight)
02898 integer x,y;
02899 char *string;
02900 int fWidth,fHeight;
02901 {
02902 COLORREF col ;
02905 HFONT hfont,hfontOld;
02906 HDC hdcMem;
02907 HBITMAP hbitmap, hbitmapOld;
02908 hfont=getcurfont();
02909 hdcMem = CreateCompatibleDC (hdc);
02910 if (hdcMem) {
02911 hbitmap = CreateCompatibleBitmap (hdc,fWidth,fHeight);
02912 if (hbitmap) {
02913 SetMapMode(hdcMem, MM_TEXT);
02914 SetBkMode(hdcMem,TRANSPARENT);
02915 SetTextAlign(hdcMem, TA_LEFT|TA_BOTTOM);
02916 hbitmapOld = SelectObject (hdcMem, hbitmap);
02917 BitBlt (hdcMem, 0, 0,fWidth,fHeight, NULL, 0, 0, WHITENESS);
02922 hfontOld=SelectObject(hdcMem,hfont);
02923 if (ScilabXgc->Colors != NULL)
02924 {
02926 col = ScilabXgc->Colors[ScilabXgc->CurColor];
02927 if ( ScilabXgc->CurDrawFunction != GXxor )
02928 col = col ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
02929 SetTextColor(hdcMem,col);
02930 }
02931 if (TextOut (hdcMem,0,fHeight,string,strlen(string)))
02932 {
02934 BitBlt(hdc, x,y-fHeight,fWidth,fHeight,hdcMem,0,0,0x990066);
02935 } else {
02936 MessageBox (GetFocus(),
02937 "Unable to perform TextOut", "DisplayGlyph", MB_OK);
02938 }
02939 SelectObject (hdcMem, hbitmapOld);
02942 SelectObject (hdcMem, hfontOld);
02943 DeleteObject (hbitmap);
02944 } else {
02945 MessageBox (GetFocus(), "Unable To create Bitmap", "DisplayGlyph", MB_OK);
02946 }
02947 DeleteDC (hdcMem);
02948 } else {
02949 MessageBox (GetFocus(), "Unable to create DC", "DisplayGlyph", MB_OK);
02950 }
02951 return 0;
02952 }
02953
02954
02957 void C2F(boundingbox)(string, x, y, rect, v5, v6, v7, dv1, dv2, dv3, dv4)
02958 char *string;
02959 integer *x,*y,*rect,*v5,*v6,*v7;
02960 double *dv1,*dv2,*dv3,*dv4;
02961 {
02962 SIZE size ;
02964 GetTextExtentPoint32(hdc,(LPCTSTR)string,(int)strlen(string),&size);
02965 rect[0]= *x ;
02966 rect[1]= *y - size.cy ;
02967 rect[2]= size.cx;
02968 rect[3]= size.cy;
02969 }
02970
02971
02972
02973
02974
02975 void C2F(drawline)(x1, yy1, x2, y2)
02976 integer *x1;
02977 integer *yy1;
02978 integer *x2;
02979 integer *y2;
02980 {
02981
02982 MoveToEx(hdc,(int) *x1,(int) *yy1,NULL);
02983 LineTo(hdc,(int) *x2,(int) *y2);
02984
02985 }
02986
02992 void C2F(drawsegments)(str, vx, vy, n, style, iflag, v7, dv1, dv2, dv3, dv4)
02993 char *str;
02994 integer *vx;
02995 integer *vy;
02996 integer *n;
02997 integer *style;
02998 integer *iflag;
02999 integer *v7;
03000 double *dv1;
03001 double *dv2;
03002 double *dv3;
03003 double *dv4;
03004 {
03005 integer verbose=0,Dnarg,Dvalue[10],NDvalue;
03006 integer i ;
03007
03008 C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
03009
03010
03011 if ( (int) *iflag == 1) {
03012 for (i=0 ; i < *n/2 ; i++) {
03013 NDvalue = style[i];
03014 C2F(set_line_style)(&NDvalue,PI0,PI0,PI0);
03015 MoveToEx(hdc,(int) vx[2*i],(int) vy[2*i],NULL);
03016 LineTo(hdc,(int) vx[2*i+1],(int) vy[2*i+1]);
03017 }
03018 }
03019 else {
03020 if (*style >= 1)
03021 C2F(set_line_style)(style,PI0,PI0,PI0);
03022
03023 for (i=0 ; i < *n/2 ; i++) {
03024 MoveToEx(hdc,(int) vx[2*i],(int) vy[2*i],NULL);
03025 LineTo(hdc,(int) vx[2*i+1],(int) vy[2*i+1]);
03026 }
03027 }
03028 C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
03029 }
03030
03037 void C2F(drawarrows)(str, vx, vy, n, as, style, iflag, dv1, dv2, dv3, dv4)
03038 char *str;
03039 integer *vx;
03040 integer *vy;
03041 integer *n;
03042 integer *as;
03043 integer *style;
03044 integer *iflag;
03045 double *dv1;
03046 double *dv2;
03047 double *dv3;
03048 double *dv4;
03049 {
03050 integer verbose=0,Dnarg,Dvalue[10],NDvalue,i;
03051 double cos20=cos(20.0*M_PI/180.0);
03052 double sin20=sin(20.0*M_PI/180.0);
03053 integer polyx[4],polyy[4];
03054 C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
03055 for (i=0 ; i < *n/2 ; i++)
03056 {
03057 double dx,dy,norm;
03058 if ( (int) *iflag == 1)
03059 NDvalue = style[i];
03060 else
03061 NDvalue=(*style < 1) ? Dvalue[0] : *style;
03062 C2F(set_line_style)(&NDvalue,PI0,PI0,PI0);
03063
03064 dx=( vx[2*i+1]-vx[2*i]);
03065 dy=( vy[2*i+1]-vy[2*i]);
03066 norm = sqrt(dx*dx+dy*dy);
03067 if ( Abs(norm) > SMDOUBLE )
03068 { integer nn=1,p=3;
03069 dx=(*as/10.0)*dx/norm;dy=(*as/10.0)*dy/norm;
03070 polyx[0]= polyx[3]=vx[2*i+1];
03071 polyx[1]= inint(polyx[0] - cos20*dx -sin20*dy );
03072 polyx[2]= inint(polyx[0] - cos20*dx + sin20*dy);
03073 polyy[0]= polyy[3]=vy[2*i+1];
03074 polyy[1]= inint(polyy[0] + sin20*dx -cos20*dy) ;
03075 polyy[2]= inint(polyy[0] - sin20*dx - cos20*dy) ;
03076 C2F(fillpolylines)("v",polyx,polyy,&NDvalue, &nn,&p,PI0,PD0,PD0,PD0,PD0);
03077 }
03078 MoveToEx(hdc,(int) vx[2*i],(int) vy[2*i],NULL);
03079 LineTo(hdc,(int) (vx[2*i+1]-dx*cos20),(int) (vy[2*i+1]-dy*cos20));
03080
03081
03082 }
03083 C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
03084 }
03085
03097 void C2F(drawrectangles)(str, vects, fillvect, n, v5, v6, v7, dv1, dv2, dv3, dv4)
03098 char *str;
03099 integer *vects;
03100 integer *fillvect;
03101 integer *n;
03102 integer *v5;
03103 integer *v6;
03104 integer *v7;
03105 double *dv1;
03106 double *dv2;
03107 double *dv3;
03108 double *dv4;
03109 {
03110 integer i,cpat,verbose=0,num,cd[10];
03111 C2F(getpattern)(&verbose,&cpat,&num,vdouble);
03112
03113 C2F(get_dash_and_color)(&verbose,cd,&num,vdouble);
03114 for (i=0 ; i< *n ; i++)
03115 {
03116 if (fillvect[i] < 0)
03117 {
03118 int dash = - fillvect[i];
03119 C2F(set_line_style)(&dash,PI0,PI0,PI0);
03120 C2F(drawrectangle)(str,vects+4*i,vects+4*i+1,vects+4*i+2,vects+4*i+3
03121 ,PI0,PI0,PD0,PD0,PD0,PD0);
03122 }
03123 else if (fillvect[i] == 0)
03124 {
03125
03126 C2F(drawrectangle)(str,vects+4*i,vects+4*i+1,vects+4*i+2,vects+4*i+3
03127 ,PI0,PI0,PD0,PD0,PD0,PD0);
03128 }
03129 else
03130 {
03131 C2F(setpattern)(&(fillvect[i]),PI0,PI0,PI0);
03132 C2F(fillrectangle)(str,vects+4*i,vects+4*i+1,vects+4*i+2,vects+4*i+3,PI0,PI0,PD0,PD0,PD0,PD0);
03133 }
03134 }
03135 C2F(set_dash_and_color)(&(cd[0]),PI0,PI0,PI0);
03136 }
03137
03140 void C2F(drawrectangle)(str, x, y, width, height, v6, v7, dv1, dv2, dv3, dv4)
03141 char *str;
03142 integer *x;
03143 integer *y;
03144 integer *width;
03145 integer *height;
03146 integer *v6;
03147 integer *v7;
03148 double *dv1;
03149 double *dv2;
03150 double *dv3;
03151 double *dv4;
03152 {
03153 SelectObject(hdc,GetStockObject(NULL_BRUSH));
03154
03155 Rectangle(hdc,(int) *x,(int) *y,(int) *width+*x+1 ,(int) *height+*y+1);
03156 if ( ScilabXgc->hBrush != (HBRUSH) 0)
03157 SelectObject(hdc,ScilabXgc->hBrush);
03158 }
03159
03162 void C2F(fillrectangle)(str, x, y, width, height, v6, v7, dv1, dv2, dv3, dv4)
03163 char *str;
03164 integer *x;
03165 integer *y;
03166 integer *width;
03167 integer *height;
03168 integer *v6;
03169 integer *v7;
03170 double *dv1;
03171 double *dv2;
03172 double *dv3;
03173 double *dv4;
03174 {
03176 Rectangle(hdc,(int) *x,(int) *y,(int) *width + *x+1 ,(int) *height + *y+1 );
03177 }
03178
03179
03180
03181
03182
03183
03184
03185
03186
03187 void fill_grid_rectangles(x, y, z, n1, n2)
03188 integer x[],y[];
03189 double *z;
03190 integer n1,n2;
03191 {
03192 double zmoy,zmax,zmin,zmaxmin;
03193 integer i,j,verbose=0,whiteid,narg,fill[1],cpat,xz[2];
03194 int flag;
03195
03196 zmin=Mini(z,(n1)*(n2));
03197 zmax=Maxi(z,(n1)*(n2));
03198 zmaxmin=zmax-zmin;
03199 if (zmaxmin <= SMDOUBLE) zmaxmin=SMDOUBLE;
03200
03201
03202
03203
03204
03205 flag=MaybeSetWinhdc();
03206 C2F(getlast)(&verbose,&whiteid,&narg,vdouble);
03207 C2F(getpattern)(&verbose,&cpat,&narg,vdouble);
03208 C2F(getwindowdim)(&verbose,xz,&narg,vdouble);
03209
03210 for (i = 0 ; i < (n1)-1 ; i++)
03211 for (j = 0 ; j < (n2)-1 ; j++)
03212 {
03213 integer w,h;
03214 zmoy=1/4.0*(z[i+n1*j]+z[i+n1*(j+1)]+z[i+1+n1*j]+z[i+1+n1*(j+1)]);
03215 fill[0]=1 + inint((whiteid-1)*(zmoy-zmin)/(zmaxmin));
03216 C2F(setpattern)(fill,PI0,PI0,PI0);
03217 w=Abs(x[i+1]-x[i]);h=Abs(y[j+1]-y[j]);
03218
03219 if ( w != 0 && h != 0 && x[i] < xz[0] && y[j+1] < xz[1] && x[i]+w > 0 && y[j+1]+h > 0 )
03220 Rectangle(hdc,(int) x[i],(int) y[j+1],(int) w + x[i]+1 ,(int) h + y[j+1]+1 );
03221 }
03222 C2F(setpattern)(&cpat,PI0,PI0,PI0);
03223 if ( flag == 1) ReleaseWinHdc();
03224 }
03225
03226
03227
03228
03229
03230
03231
03232
03233
03234
03235
03236 void fill_grid_rectangles1(x, y, z, n1, n2)
03237 integer *x;
03238 integer *y;
03239 double *z;
03240 integer n1;
03241 integer n2;
03242 {
03243 integer i,j,verbose=0,narg,fill[1],cpat,xz[2];
03244 int flag;
03245
03246
03247
03248
03249
03250
03251 flag=MaybeSetWinhdc();
03252 C2F(getpattern)(&verbose,&cpat,&narg,vdouble);
03253 C2F(getwindowdim)(&verbose,xz,&narg,vdouble);
03254 for (i = 0 ; i < (n1)-1 ; i++)
03255 for (j = 0 ; j < (n2)-1 ; j++)
03256 {
03257 integer w,h;
03258 fill[0]= (int) z[i+(n1-1)*j];
03259 C2F(setpattern)(fill,PI0,PI0,PI0);
03260 w=Abs(x[j+1]-x[j]);
03261 h=Abs(y[i+1]-y[i]);
03262
03263 if ( w != 0 && h != 0 && x[j] < xz[0] && y[i] < xz[1] && x[j]+w > 0 && y[i]+h > 0 )
03264 Rectangle(hdc,(int) x[j],(int) y[i],(int) w + x[j]+1 ,(int) h + y[i]+1 );
03265 }
03266 C2F(setpattern)(&cpat,PI0,PI0,PI0);
03267 if ( flag == 1) ReleaseWinHdc();
03268 }
03269
03270
03271
03272
03284 void C2F(fillarcs)(str, vects, fillvect, n, v5, v6, v7, dv1, dv2, dv3, dv4)
03285 char *str;
03286 integer *vects;
03287 integer *fillvect;
03288 integer *n;
03289 integer *v5;
03290 integer *v6;
03291 integer *v7;
03292 double *dv1;
03293 double *dv2;
03294 double *dv3;
03295 double *dv4;
03296 {
03297 integer i,cpat,verb,num;
03298 verb=0;
03299 C2F(getpattern)(&verb,&cpat,&num,vdouble);
03300 for (i=0 ; i< *n ; i++)
03301 {
03302 if (fillvect[i] > ScilabXgc->IDLastPattern + 1)
03303 {
03304 C2F(setpattern)(&(cpat),PI0,PI0,PI0);
03305 C2F(drawarc)(str,vects+6*i,vects+6*i+1,
03306 vects+6*i+2,vects+6*i+3,
03307 vects+6*i+4,vects+6*i+5,PD0,PD0,PD0,PD0);
03308 }
03309 else
03310 {
03311 C2F(setpattern)(&(fillvect[i]),PI0,PI0,PI0);
03312 C2F(fillarc)(str,vects+6*i,vects+6*i+1,
03313 vects+6*i+2,vects+6*i+3,
03314 vects+6*i+4,vects+6*i+5,PD0,PD0,PD0,PD0);
03315 }
03316 }
03317 C2F(setpattern)(&(cpat),PI0,PI0,PI0);
03318 }
03319
03320
03328 void C2F(drawarcs)(str, vects, style, n, v5, v6, v7, dv1, dv2, dv3, dv4)
03329 char *str;
03330 integer *vects;
03331 integer *style;
03332 integer *n;
03333 integer *v5;
03334 integer *v6;
03335 integer *v7;
03336 double *dv1;
03337 double *dv2;
03338 double *dv3;
03339 double *dv4;
03340 {
03341 integer verbose=0,Dnarg,Dvalue[10],NDvalue,i;
03342
03343 C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
03344 for (i=0 ; i< *n ; i++)
03345 {
03346 NDvalue = style[i];
03347 C2F(set_line_style)(&NDvalue,PI0,PI0,PI0);
03348 C2F(drawarc)(str,vects+6*i,vects+6*i+1,
03349 vects+6*i+2,vects+6*i+3,
03350 vects+6*i+4,vects+6*i+5,PD0,PD0,PD0,PD0);
03351 }
03352 C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
03353 }
03354
03357 void C2F(drawarc)(str, x, y, width, height, angle1, angle2, dv1, dv2, dv3, dv4)
03358 char *str;
03359 integer *x, *y, *width,*height, *angle1, *angle2;
03360 double *dv1,*dv2,*dv3,*dv4;
03361 {
03362 int xmid= *x + *width/2;
03363 int ymid= *y + *height/2;
03364 int lg= Max(*width,*height);
03365 SelectObject(hdc,GetStockObject(NULL_BRUSH));
03367 Arc(hdc,(int) *x,(int) *y,(int) *width + *x ,(int) *height + *y,
03368 xmid + (int) (lg*cos(*angle1*M_PI/11520.00)),
03369 ymid - (int) (lg*sin(*angle1*M_PI/11520.00)),
03370 xmid + (int) (lg*cos((*angle1+*angle2)*M_PI/11520.00)),
03371 ymid - (int)(lg*sin((*angle1+*angle2)*M_PI/11520.00)));
03372 if ( ScilabXgc->hBrush != (HBRUSH) 0) SelectObject(hdc,ScilabXgc->hBrush);
03373 }
03374
03376 void C2F(fillarc)(str, x, y, width, height, angle1, angle2, dv1, dv2, dv3, dv4)
03377 char *str;
03378 integer *x, *y, *width,*height, *angle1, *angle2;
03379 double *dv1,*dv2,*dv3,*dv4;
03380 {
03381 int xmid= *x + *width/2;
03382 int ymid= *y + *height/2;
03383 int lg= Max(*width,*height);
03385 Pie(hdc,(int) *x,(int) *y,(int) *width + *x ,(int) *height + *y,
03386 xmid +(int) (lg*cos(*angle1*M_PI/11520.00)),
03387 ymid - (int) (lg*sin(*angle1*M_PI/11520.00)),
03388 xmid+(int) (lg*cos((*angle1+*angle2)*M_PI/11520.00)),
03389 ymid - (int) (lg*sin((*angle1+*angle2)*M_PI/11520.00)));
03390 }
03391
03392
03393
03394
03395
03401 void C2F(drawpolylines)(str, vectsx, vectsy, drawvect, n, p, v7, dv1, dv2, dv3, dv4)
03402 char *str;
03403 integer *vectsx;
03404 integer *vectsy;
03405 integer *drawvect;
03406 integer *n;
03407 integer *p;
03408 integer *v7;
03409 double *dv1;
03410 double *dv2;
03411 double *dv3;
03412 double *dv4;
03413 { integer verbose=0 ,symb[2],Mnarg,Dnarg,Dvalue[10],NDvalue,i,close;
03414
03415 C2F(xgetmark)(&verbose,symb,&Mnarg,vdouble);
03416 C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
03417 for (i=0 ; i< *n ; i++)
03418 {
03419 if (drawvect[i] <= 0)
03420 {
03421 NDvalue = - drawvect[i] ;
03422 C2F(xsetmark)(&NDvalue,symb+1,PI0,PI0);
03423 C2F(setpattern)(Dvalue+6,PI0,PI0,PI0);
03424
03425 C2F(drawpolymark)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
03426 }
03427 else
03428 {
03429 C2F(set_line_style)(drawvect+i,PI0,PI0,PI0);
03430 close = 0;
03431 C2F(drawpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,&close,
03432 PI0,PI0,PD0,PD0,PD0,PD0);
03433 }
03434 }
03436 C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
03437 C2F(xsetmark)(symb,symb+1,PI0,PI0);
03438 }
03439
03451 void C2F(fillpolylines)(str, vectsx, vectsy, fillvect, n, p, v7, dv1, dv2, dv3, dv4)
03452 char *str;
03453 integer *vectsx;
03454 integer *vectsy;
03455 integer *fillvect;
03456 integer *n;
03457 integer *p;
03458 integer *v7;
03459 double *dv1;
03460 double *dv2;
03461 double *dv3;
03462 double *dv4;
03463 {
03464 integer Dnarg,Dvalue[10];
03465 integer i,cpat,verbose=0,num,close=1,pattern;
03466 C2F(getpattern)(&verbose,&cpat,&num,vdouble);
03467 C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
03468 for (i=0 ; i< *n ; i++)
03469 {
03470 if (fillvect[i] > 0)
03471 {
03473 C2F(setpattern)(&fillvect[i],PI0,PI0,PI0);
03474 C2F(fillpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=1,&close),
03475 PI0,PI0,PD0,PD0,PD0,PD0);
03476 C2F(set_line_style)(Dvalue,PI0,PI0,PI0);
03477 C2F(setpattern)(&(cpat),PI0,PI0,PI0);
03478 C2F(drawpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=1,&close)
03479 ,PI0,PI0,PD0,PD0,PD0,PD0);
03480 }
03481 else if (fillvect[i] == 0 )
03482 {
03483 C2F(set_line_style)(Dvalue,PI0,PI0,PI0);
03484 C2F(setpattern)(&cpat,PI0,PI0,PI0);
03485 C2F(drawpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=0,&close)
03486 ,PI0,PI0,PD0,PD0,PD0,PD0);
03487 }
03488 else
03489 {
03490 pattern = -fillvect[i] ;
03491 C2F(setpattern)(&pattern,PI0,PI0,PI0);
03492 C2F(fillpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=0,&close)
03493 ,PI0,PI0,PD0,PD0,PD0,PD0);
03494 }
03495 }
03496 C2F(set_dash_and_color)(Dvalue,PI0,PI0,PI0);
03497 }
03498
03499
03500 static void C2F(analyze_points)(integer n, integer *vx, integer *vy, integer onemore) ;
03501
03506 void C2F(drawClippedPolyline)(str, n, vx, vy, closeflag, v6, v7, dv1, dv2, dv3, dv4)
03507 char *str;
03508 integer *n;
03509 integer *vx;
03510 integer *vy;
03511 integer *closeflag;
03512 integer *v6;
03513 integer *v7;
03514 double *dv1;
03515 double *dv2;
03516 double *dv3;
03517 double *dv4;
03518 {
03519 integer n1;
03520 if (*closeflag == 1) n1 = *n+1;else n1= *n;
03521 if (n1 >= 2)
03522 {
03523 C2F(analyze_points)( *n, vx, vy, *closeflag );
03524 }
03525 }
03526
03531 void C2F(drawpolyline)(str, n, vx, vy, closeflag, v6, v7, dv1, dv2, dv3, dv4)
03532 char *str;
03533 integer *n;
03534 integer *vx;
03535 integer *vy;
03536 integer *closeflag;
03537 integer *v6;
03538 integer *v7;
03539 double *dv1;
03540 double *dv2;
03541 double *dv3;
03542 double *dv4;
03543 {
03544 integer n1;
03545 if (*closeflag == 1) n1 = *n+1;else n1= *n;
03546 if (n1 >= 2)
03547 {
03548 if (C2F(store_points)(*n, vx, vy,*closeflag))
03549 {
03550 Polyline(hdc,C2F(ReturnPoints)(),(int) n1);
03551 }
03552 }
03553 }
03554
03557 void C2F(fillpolyline)(str, n, vx, vy, closeflag, v6, v7, dv1, dv2, dv3, dv4)
03558 char *str;
03559 integer *n;
03560 integer *vx;
03561 integer *vy;
03562 integer *closeflag;
03563 integer *v6;
03564 integer *v7;
03565 double *dv1;
03566 double *dv2;
03567 double *dv3;
03568 double *dv4;
03569 {
03570 integer n1;
03571 if (*closeflag == 1) n1 = *n+1;else n1= *n;
03572 if (C2F(store_points)(*n, vx, vy,*closeflag))
03573 {
03574 Polygon(hdc,C2F(ReturnPoints)(), n1);
03575 }
03576 }
03577
03580 void C2F(drawpolymark)(str, n, vx, vy, v5, v6, v7, dv1, dv2, dv3, dv4)
03581 char *str;
03582 integer *n;
03583 integer *vx;
03584 integer *vy;
03585 integer *v5;
03586 integer *v6;
03587 integer *v7;
03588 double *dv1;
03589 double *dv2;
03590 double *dv3;
03591 double *dv4;
03592 {
03593 if ( ScilabXgc->CurHardSymb == 0 )
03594 {
03595 if (C2F(store_points)(*n, vx, vy,0L))
03596 {
03597 XDrawPoints (hdc,C2F(ReturnPoints)(), *n);
03598 }
03599 }
03600 else
03601 {
03602 integer i,keepid,keepsize,hds;
03603 i=1;
03604 keepid = ScilabXgc->FontId;
03605 keepsize= ScilabXgc->FontSize;
03606 hds= ScilabXgc->CurHardSymbSize;
03607 C2F(xsetfont)(&i,&hds,PI0,PI0);
03608 for ( i=0; i< *n ;i++) DrawMark(hdc,vx+i,vy+i);
03609 C2F(xsetfont)(&keepid,&keepsize,PI0,PI0);
03610 }
03611 }
03612
03613 static void XDrawPoints(lhdc, points, Npoints)
03614 HDC lhdc;
03615 POINT *points;
03616 integer Npoints;
03617 {
03618 int i ;
03619 for ( i=0; i < Npoints;i++)
03620 {
03622 MoveToEx(hdc,points[i].x,points[i].y,NULL);
03623 LineTo(hdc,points[i].x+1,points[i].y);
03624 }
03625 }
03626
03627
03628
03629
03630
03631
03632
03633
03634
03635 struct BCG *AddNewWindowToList()
03636 {
03637 struct BCG * newWin = addWindowItem() ;
03638
03639 if ( newWin == NULL ) { return NULL ; }
03640
03641
03642 newWin->CWindow = (HWND) NULL;
03643 newWin->CurWindow = 0;
03644 newWin->in_sizemove = 0;
03645 newWin->Red = (float *) 0;
03646 newWin->Green = (float *) 0;
03647 newWin->Blue = (float *) 0;
03648 newWin->Colors = (COLORREF *) 0;
03649 newWin->CmapFlag = 1;
03650 newWin->EventHandler[0]='\0';
03651 newWin->lpgw = &graphwin;
03652 newWin->hPen = (HPEN) 0;
03653 newWin->hBrush = (HBRUSH) 0;
03654 newWin->hbmCompat = (HBITMAP) 0;
03655 newWin->hdcCompat = (HDC) 0;
03656 newWin->CurColor = 32;
03657 newWin->IDM_Count=0;
03658 newWin->hMenuRoot=NULL;
03659
03660 return newWin ;
03661 }
03662
03664 void DeleteWindowToList( integer num )
03665 {
03666 struct BCG * window = getWindowXgcNumber( num ) ;
03667
03668 if ( window == NULL ) { return ; }
03669
03670 deleted_win = num;
03671 DestroyWindow(window->hWndParent);
03672 DestroyWindow(window->CWindow);
03673 DestroyWindow(window->Statusbar);
03674 CloseGraphMacros( window ) ;
03675 XgcFreeColors( window );
03676
03677
03678 if ( window->lpgw->szMenuName != NULL )
03679 {
03680 FREE(window->lpgw->szMenuName) ;
03681 window->lpgw->szMenuName = NULL ;
03682 }
03683
03684 if ( window->CurPixmapStatus == 1)
03685 {
03687 if ( window->hdcCompat)
03688 {
03689 SelectObject( window->hdcCompat, NULL ) ;
03690 }
03691 if ( window->hbmCompat)
03692 {
03693 DeleteObject( window->hbmCompat ) ;
03694 }
03695 if ( window->hdcCompat)
03696 {
03697 DeleteDC( window->hdcCompat ) ;
03698 }
03699
03700 }
03701 removeWindowItem( window ) ;
03702 }
03703
03705 void DeleteSGWin( integer intnum )
03706 {
03707 int curwin;
03708 if ( ScilabXgc == NULL ) { return ; }
03709 curwin = ScilabXgc->CurWindow ;
03710 DeleteWindowToList( intnum ) ;
03711
03712 del_window_scale(intnum);
03713 if ( curwin == intnum )
03714 {
03715 if ( isWindowListEmpty() )
03716 {
03718 ScilabXgc = NULL ;
03719 }
03720 else
03721 {
03723 ScilabXgc = getFirstWindow() ;
03724 ResetScilabXgc() ;
03725 get_window_scale(ScilabXgc->CurWindow,NULL);
03726 }
03727 }
03728 }
03729
03730
03731
03732
03733
03734 HWND GetWindowNumber(wincount)
03735 int wincount;
03736 {
03737 struct BCG *bcg;
03738 bcg = getWindowXgcNumber(wincount);
03739 if ( bcg != (struct BCG *) 0)
03740 return( bcg->CWindow);
03741 else
03742 return( (HWND) 0);
03743 }
03744
03749 void C2F(initgraphic)(string, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
03750 char *string;
03751 integer *v2;
03752 integer *v3;
03753 integer *v4;
03754 integer *v5;
03755 integer *v6;
03756 integer *v7;
03757 double *dv1;
03758 double *dv2;
03759 double *dv3;
03760 double *dv4;
03761 {
03762 static char popupname[sizeof("ScilabGraphic")+4];
03763 static char winname[sizeof("BG")+4];
03764 struct BCG *NewXgc ;
03765 RECT rect,rect1;
03766 static integer EntryCounter = 0;
03767 integer WinNum;
03768 static HMENU sysmenu;
03769 SCROLLINFO vertsi;
03770 SCROLLINFO horzsi;
03771
03772 if ( v2 != (integer *) NULL && *v2 != -1 )
03773 {
03774 WinNum= *v2;
03775 }
03776 else
03777 {
03778 WinNum= EntryCounter;
03779 }
03780
03781 if (EntryCounter == 0)
03782 {
03784 screencolor = 1;
03785 if (C2F(AllocVectorStorage)()==0) return;
03786 graphwin.xmax = WIN_XMAX;
03787 graphwin.ymax = WIN_YMAX;
03788 if (! graphwin.hPrevInstance)
03789 {
03790 CreateGraphClass();
03791 }
03793 }
03794
03795 if (( NewXgc = AddNewWindowToList()) == (struct BCG *) 0)
03796 {
03797 Scistring("initgraphics: unable to alloc\n");
03798 return;
03799 }
03800 else
03801 {
03802 ScilabXgc= NewXgc;
03803 }
03808
03809
03810 ScilabXgc->lpgw = &graphwin;
03811
03812 sprintf(popupname,"ScilabGraphic%d", (int)WinNum);
03813 if (EntryCounter == 0)
03814 {
03815 ReadRegistryGraph(ScilabXgc);
03816 }
03817 ScilabXgc->Inside_init=1;
03819 ScilabXgc->hWndParent = CreateWindow(szParentGraphClass, popupname,
03820 WS_OVERLAPPEDWINDOW,
03821 graphwin.Origin.x, graphwin.Origin.y,
03822 graphwin.Size.x, graphwin.Size.y,
03823 NULL, NULL, graphwin.hInstance,
03824 NewXgc);
03825
03826 if (ScilabXgc->hWndParent == (HWND)NULL)
03827 {
03828 MessageBox((HWND)NULL,"Couldn't open parent graph window",(LPSTR)NULL, MB_ICONHAND | MB_SYSTEMMODAL);
03829 return;
03830 }
03831 ShowWindow(ScilabXgc->hWndParent, SW_SHOWNORMAL);
03832 ScilabXgc->Statusbar = InitStatusBar (ScilabXgc->hWndParent);
03833 ShowWindow(ScilabXgc->Statusbar, SW_SHOWNORMAL);
03834 GetWindowRect (ScilabXgc->Statusbar, &rect1) ;
03835 GetClientRect(ScilabXgc->hWndParent, &rect);
03836
03837 MoveWindow(ScilabXgc->Statusbar, 0, rect.bottom -( rect1.bottom - rect1.top),
03838 rect.right, ( rect1.bottom - rect1.top), TRUE) ;
03839
03840 sprintf((char *)winname,"BG%d", (int)WinNum);
03841
03842 ScilabXgc->CWindowWidth = rect.right;
03843 ScilabXgc->CWindowHeight = rect.bottom - ( rect1.bottom - rect1.top);
03844
03845 ScilabXgc->CWindow = CreateWindow(szGraphClass, winname,
03846 WS_CHILD | WS_VSCROLL | WS_HSCROLL,
03847 0, graphwin.ButtonHeight,
03848 ScilabXgc->CWindowWidth,
03849 ScilabXgc->CWindowHeight,
03850 ScilabXgc->hWndParent,
03851 NULL, graphwin.hInstance,
03852 NewXgc);
03853
03854 ScilabXgc->CurResizeStatus = 1;
03855 ScilabXgc->CWindowWidthView = ScilabXgc->CWindowWidth;
03856 ScilabXgc->CWindowHeightView = ScilabXgc->CWindowHeight;
03857
03858
03859 vertsi.cbSize = sizeof(SCROLLINFO);
03860 vertsi.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
03861 vertsi.nMin = 0;
03862 vertsi.nMax = ScilabXgc->CWindowHeight;
03863 vertsi.nPage = ScilabXgc->CWindowHeightView;
03864 vertsi.nPos = 0;
03865 sciSetScrollInfo(ScilabXgc,SB_VERT, &(vertsi), TRUE);
03866 sciGetScrollInfo(ScilabXgc,SB_VERT, &vertsi);
03867
03868
03869 horzsi.cbSize = sizeof(SCROLLINFO);
03870 horzsi.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
03871 horzsi.nMin = 0;
03872 horzsi.nMax = ScilabXgc->CWindowWidth;
03873 horzsi.nPage = ScilabXgc->CWindowWidthView;
03874 horzsi.nPos = 0;
03875 sciSetScrollInfo(ScilabXgc,SB_HORZ, &horzsi, TRUE);
03876 sciGetScrollInfo(ScilabXgc,SB_HORZ, &horzsi);
03877
03878 if (ScilabXgc->CWindow == (HWND)NULL)
03879 {
03880 MessageBox((HWND)NULL,"Couldn't open graphic window",(LPSTR)NULL, MB_ICONHAND | MB_SYSTEMMODAL);
03881 return;
03882 }
03883
03884 ShowWindow(ScilabXgc->CWindow, SW_SHOWNORMAL);
03885 ShowWindow(ScilabXgc->hWndParent, SW_SHOWNORMAL);
03886 graphwin.resized = FALSE;
03887
03888
03890 ScilabXgc->CurPixmapStatus = 0;
03891 ScilabXgc->CurResizeStatus = 1;
03892 ScilabXgc->CurWindow = WinNum;
03893
03894
03895 SetWinhdc();
03896 SetMapMode(hdc, MM_TEXT);
03897 SetBkMode(hdc,TRANSPARENT);
03898 GetClientRect(ScilabXgc->CWindow, &rect);
03899 SetViewportExtEx(hdc, rect.right, rect.bottom,NULL);
03900 SetTextAlign(hdc, TA_LEFT|TA_BOTTOM);
03901 SetFocus( ScilabXgc->CWindow);
03902 if (EntryCounter == 0)
03903 {
03904 C2F(CreatePatterns)();
03905 LoadFonts();
03906 }
03907 InitMissileXgc(PI0,PI0,PI0,PI0);
03908
03909
03910 EntryCounter=Max(EntryCounter,WinNum);
03911 EntryCounter++;
03912
03913
03914 CreateGedMenus(ScilabXgc);
03915 CreateGraphToolBar(ScilabXgc);
03916
03917 ScilabXgc->Inside_init=0;
03918 }
03919
03920 static void CreateGraphClass()
03921 {
03922 RegisterParentWindowGraphClass();
03923 RegisterWindowGraphClass();
03924 }
03925
03926 static BOOL RegisterParentWindowGraphClass (void)
03927 {
03929 BOOL bOK=FALSE;
03930 static WNDCLASS ParentGraphwndclass;
03931
03932 ParentGraphwndclass.style = CS_HREDRAW | CS_VREDRAW;
03933 ParentGraphwndclass.lpfnWndProc = WndParentGraphProc;
03934 ParentGraphwndclass.cbClsExtra = 0;
03935 ParentGraphwndclass.cbWndExtra = 4 * sizeof(void *);
03936 ParentGraphwndclass.hInstance = graphwin.hInstance;
03937 ParentGraphwndclass.hIcon = LoadIcon (graphwin.hInstance,(LPCSTR)TEXT(IDI_PUFFIN));
03938 ParentGraphwndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
03939 ParentGraphwndclass.hbrBackground = NULL;
03940 ParentGraphwndclass.lpszMenuName = NULL;
03941 ParentGraphwndclass.lpszClassName = szParentGraphClass;
03942
03943 if (!RegisterClass(&ParentGraphwndclass))
03944 {
03945 DWORD dwLastError = GetLastError();
03946 char buff1[1000], buff2[1000];
03947
03948 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError, 0, buff1, sizeof (buff1), NULL);
03949 sprintf(buff2, "ParentGraphwndclass Win32 error %ld occured", dwLastError);
03950
03951 MessageBox(NULL, buff1, buff2, MB_ICONERROR);
03952 bOK=FALSE;
03953 }
03954 else bOK=TRUE;
03955
03956 return bOK;
03957 }
03958
03959 static BOOL RegisterWindowGraphClass (void)
03960 {
03961 BOOL bOK=FALSE;
03962 static WNDCLASS Graphwndclass;
03964 Graphwndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC |CS_DBLCLKS ;
03965 Graphwndclass.lpfnWndProc = WndGraphProc;
03966 Graphwndclass.cbClsExtra = 0;
03967 Graphwndclass.cbWndExtra = 4 * sizeof(void *);
03968 Graphwndclass.hInstance = graphwin.hInstance;
03969 Graphwndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
03970 Graphwndclass.hCursor = LoadCursor(NULL, IDC_CROSS);
03971 Graphwndclass.hbrBackground = NULL;
03972 Graphwndclass.lpszMenuName = NULL;
03973 Graphwndclass.lpszClassName = szGraphClass;
03974
03975 if (!RegisterClass(&Graphwndclass))
03976 {
03977 DWORD dwLastError = GetLastError();
03978 char buff1[1000], buff2[1000];
03979
03980 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError, 0, buff1, sizeof (buff1), NULL);
03981 sprintf(buff2, "ParentGraphwndclass Win32 error %ld occured", dwLastError);
03982
03983 MessageBox(NULL, buff1, buff2, MB_ICONERROR);
03984 bOK=FALSE;
03985 }
03986 else bOK=TRUE;
03987
03988 return bOK;
03989 }
03990
03991
03992
03993 void C2F(xinfo)(message, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
03994 char *message;
03995 integer *v2,*v3,*v4,*v5,*v6,*v7;
03996 double *dv1,*dv2,*dv3,*dv4;
03997 {
03998 if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->Statusbar != (HWND) 0)
03999 {
04000 (BOOL)SendMessage(ScilabXgc->Statusbar, SB_SETTEXT, (WPARAM) 0,
04001 (LPARAM) (LPSTR) message );
04002 }
04003 }
04004
04005
04006 #define MAXPRINTF 512
04007
04008 void wininfo(char *fmt,...)
04009 {
04010 int count;
04011 char buf[MAXPRINTF];
04012 va_list args;
04013 va_start(args,fmt);
04014 count = vsprintf(buf,fmt,args);
04015 if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->Statusbar != (HWND) 0)
04016 {
04017 (BOOL)SendMessage(ScilabXgc->Statusbar, SB_SETTEXT, (WPARAM) 0,
04018 (LPARAM) (LPSTR) buf);
04019 }
04020 }
04021
04022
04023
04024
04025
04026
04027 static void InitMissileXgc (integer *v1,integer *v2,integer *v3,integer *v4)
04028 {
04029 integer i,j;
04030 ScilabXgc->IDLastPattern = GREYNUMBER - 1;
04031 ScilabXgc->CurLineWidth=0 ;
04032 C2F(setalufunction1)((i=3,&i),PI0,PI0,PI0);
04034 i=j= -1;
04035 C2F(unsetclip)(PI0,PI0,PI0,PI0);
04036 ScilabXgc->ClipRegionSet= 0;
04037 C2F(xsetfont)((i=2,&i),(j=1,&j),PI0,PI0);
04038 C2F(xsetmark)((i=0,&i),(j=0,&j),PI0,PI0);
04040 i= CoordModeOrigin ;
04041 C2F(setabsourel)(&i,PI0,PI0,PI0);
04042
04043 ScilabXgc->CurColorStatus =0;
04044 C2F(setpattern)((i=1,&i),PI0,PI0,PI0);
04045 C2F(setdash)((i=1,&i),PI0,PI0,PI0);
04046 C2F(sethidden3d)((i=1,&i),PI0,PI0,PI0);
04048 C2F(setthickness)((i=0,&i),PI0,PI0,PI0);
04049
04050 ScilabXgc->CurColorStatus = 1;
04051 set_default_colormap();
04052 C2F(setalufunction1)((i=3,&i),PI0,PI0,PI0);
04053 C2F(setpattern)((i=DefaultForeground,&i),PI0,PI0,PI0);
04054 C2F(setpattern)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
04055 C2F(setthickness)((i=1,&i),PI0,PI0,PI0);
04056
04057 C2F(setforeground)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
04058 C2F(setbackground)((i=ScilabXgc->NumForeground+2,&i),PI0,PI0,PI0);
04059 C2F(sethidden3d)((i=4,&i),PI0,PI0,PI0);
04060
04061 getcolordef(&i);
04065 ScilabXgc->mafigure = (sciPointObj *)NULL;
04066 ScilabXgc->CurColorStatus = (i == 1) ? 0: 1;
04067 C2F(usecolor)(&i ,PI0,PI0,PI0);
04068 strcpy(ScilabXgc->CurNumberDispFormat,"%-5.2g");
04069
04071 Cscale2default();
04072
04073
04074
04075
04076
04077
04078
04079
04080
04081
04082
04083 C2F(setpixmapOn)((i = 0,&i),PI0,PI0,PI0);
04084 }
04085
04086
04087
04088
04089
04090 void getcolordef( integer * screenc )
04091 {
04092 *screenc= screencolor;
04093 }
04094
04095 void setcolordef( integer screenc )
04096 {
04097 screencolor = screenc;
04098 }
04099
04100
04101
04102
04103 void ResetScilabXgc( void )
04104 {
04105 integer i,j, clip[4];
04106 i= ScilabXgc->FontId;
04107 j= ScilabXgc->FontSize;
04108 C2F(xsetfont)(&i,&j,PI0,PI0);
04110 i= ScilabXgc->CurHardSymb;
04111 j= ScilabXgc->CurHardSymbSize;
04112 C2F(xsetmark)(&i,&j,PI0,PI0);
04113
04114 i= ScilabXgc->CurLineWidth;
04115 C2F(setthickness)(&i,PI0,PI0,PI0);
04116
04117 i= ScilabXgc->CurVectorStyle;
04118 C2F(setabsourel)(&i,PI0,PI0,PI0);
04119
04120 i= ScilabXgc->CurDrawFunction;
04121 C2F(setalufunction1)(&i,PI0,PI0,PI0);
04122
04123 if (ScilabXgc->ClipRegionSet == 1)
04124 {
04125 for ( i= 0 ; i < 4; i++) clip[i]=ScilabXgc->CurClipRegion[i];
04126 C2F(setclip)(clip,clip+1,clip+2,clip+3);
04127 }
04128 else
04129 C2F(unsetclip)(PI0,PI0,PI0,PI0);
04130
04131 if (ScilabXgc->CurColorStatus == 0)
04132 {
04133
04134 ScilabXgc->CurColorStatus = 1;
04135 C2F(setpattern)((i=DefaultForeground,&i),PI0,PI0,PI0);
04136
04137 ScilabXgc->CurColorStatus = 0;
04138 i= ScilabXgc->CurPattern + 1;
04139 C2F(setpattern)(&i,PI0,PI0,PI0);
04140 i= ScilabXgc->CurDashStyle + 1;
04141 C2F(setdash)(&i,PI0,PI0,PI0);
04142 i= ScilabXgc->NumHidden3d+1;
04143 C2F(sethidden3d)(&i,PI0,PI0,PI0);
04144 }
04145 else
04146 {
04147
04148
04149 ScilabXgc->CurColorStatus = 0;
04150 C2F(setpattern)((i=1,&i),PI0,PI0,PI0);
04151 C2F(setdash)((i=1,&i),PI0,PI0,PI0);
04152
04153 ScilabXgc->CurColorStatus = 1;
04154 i= ScilabXgc->CurColor + 1;
04155 C2F(setpattern)(&i,PI0,PI0,PI0);
04156 i= ScilabXgc->NumBackground+1;
04157 C2F(setbackground)(&i,PI0,PI0,PI0);
04158 i= ScilabXgc->NumForeground+1;
04159 C2F(setforeground)(&i,PI0,PI0,PI0);
04160 i= ScilabXgc->NumHidden3d+1;
04161 C2F(sethidden3d)(&i,PI0,PI0,PI0);
04162 }
04163 }
04164
04165
04166
04167
04168
04169
04170
04171
04172
04173
04174
04175
04176
04177
04178
04179
04180
04181
04182
04183
04184
04185
04186 void C2F(drawaxis)(str, alpha, nsteps, v2, initpoint, v6, v7, size, dx2, dx3, dx4)
04187 char *str;
04188 integer *alpha;
04189 integer *nsteps;
04190 integer *v2;
04191 integer *initpoint;
04192 integer *v6;
04193 integer *v7;
04194 double *size;
04195 double *dx2;
04196 double *dx3;
04197 double *dx4;
04198 { integer i;
04199 double xi,yi,xf,yf;
04200 double cosal,sinal;
04201 cosal= cos( (double)M_PI * (*alpha)/180.0);
04202 sinal= sin( (double)M_PI * (*alpha)/180.0);
04203 for (i=0; i <= nsteps[0]*nsteps[1]; i++)
04204 {
04205 if ( ( i % nsteps[0]) != 0)
04206 {
04207 xi = initpoint[0]+i*size[0]*cosal;
04208 yi = initpoint[1]+i*size[0]*sinal;
04209 xf = xi - ( size[1]*sinal);
04210 yf = yi + ( size[1]*cosal);
04211 MoveToEx(hdc,inint(xi),inint(yi),NULL);
04212 LineTo(hdc,inint(xf),inint(yf));
04213 }
04214 }
04215 for (i=0; i <= nsteps[1]; i++)
04216 { xi = initpoint[0]+i*nsteps[0]*size[0]*cosal;
04217 yi = initpoint[1]+i*nsteps[0]*size[0]*sinal;
04218 xf = xi - ( size[1]*size[2]*sinal);
04219 yf = yi + ( size[1]*size[2]*cosal);
04220 MoveToEx(hdc,inint(xi),inint(yi),NULL);
04221 LineTo(hdc,inint(xf),inint(yf));
04222 }
04230 }
04231
04235 void C2F(getFontMaxSize)( char * str, integer * sizeMin, integer * sizeMax,
04236 integer * v1, integer * v2, integer * v3, integer * v4,
04237 double * dx1, double * dx2, double * dx3, double * dx4 )
04238 {
04239 *sizeMin = 0 ;
04240 *sizeMax = FONTMAXSIZE ;
04241 }
04242
04243
04244
04245
04246
04247
04248
04249 void C2F(displaynumbers)(str, x, y, v1, v2, n, flag, z, alpha, dx3, dx4)
04250 char *str;
04251 integer *x;
04252 integer *y;
04253 integer *v1;
04254 integer *v2;
04255 integer *n;
04256 integer *flag;
04257 double *z;
04258 double *alpha;
04259 double *dx3;
04260 double *dx4;
04261 {
04262 char buf[20];
04263 integer i ;
04264 for (i=0 ; i< *n ; i++)
04265 {
04266 sprintf(buf,ScilabXgc->CurNumberDispFormat,z[i]);
04267 C2F(displaystring)(buf,&(x[i]),&(y[i]),PI0,flag,PI0,PI0,&(alpha[i]),PD0,PD0,PD0) ;
04268 }
04269 }
04270
04271 void C2F(bitmap)(string, w, h)
04272 char *string;
04273 integer w;
04274 integer h;
04275 {
04284 }
04285
04286
04287
04288
04289
04290
04291
04292 void C2F(xsetfont)( integer * fontid, integer * fontsize, integer * v3, integer * v4 )
04293 {
04294 integer i,fsiz;
04295 i = Min(FONTNUMBER-1,Max(*fontid,0));
04296 fsiz = Min(FONTMAXSIZE-1,Max(*fontsize,0));
04297 if ( (*FontTab)[i].ok !=1 )
04298 {
04299
04300 if (i != FONTNUMBER )
04301 {
04302 C2F(loadfamily)(fonttab[i].alias,&i,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
04303 }
04304 else
04305 {
04306 sciprint(" The Font Id %d is not affected \r\n",(int)i);
04307 Scistring(" use xlfont to set it \n");
04308 return;
04309 }
04310 }
04311 ScilabXgc->FontId = i;
04312 ScilabXgc->FontSize = fsiz;
04313 SelectFont(hdc, (*FontTab)[i].hf[fsiz]);
04314 }
04315
04316 static HFONT getcurfont()
04317 {
04318 return( (*FontTab)[ScilabXgc->FontId].hf[ScilabXgc->FontSize]);
04319 }
04320
04321
04322
04323
04324
04325 void C2F(xgetfont)( integer * verbose, integer * font, integer * nargs, double * dummy)
04326 {
04327 *nargs=2;
04328 font[0]= ScilabXgc->FontId ;
04329 font[1] =ScilabXgc->FontSize ;
04330 if (*verbose == 1)
04331 {
04332 sciprint("\r\nFontId : %d ", ScilabXgc->FontId );
04333 sciprint("--> %s at size %s pts\r\n",
04334 (*FontTab)[ScilabXgc->FontId].fname,
04335 size_[ScilabXgc->FontSize]);
04336 }
04337 }
04338
04339
04340
04341
04342
04343 void C2F(xsetmark)( integer * number, integer * size, integer * v3, integer * v4)
04344 {
04345 ScilabXgc->CurHardSymb = Max(Min(SYMBOLNUMBER-1,*number),0);
04346 ScilabXgc->CurHardSymbSize = Max(Min(FONTMAXSIZE-1,*size),0);
04347 }
04348
04349
04350
04351
04352
04353
04354 void C2F(xgetmark)( integer * verbose, integer *symb, integer * narg, double * dummy)
04355 {
04356 *narg =2 ;
04357 symb[0] = ScilabXgc->CurHardSymb ;
04358 symb[1] = ScilabXgc->CurHardSymbSize ;
04359 if (*verbose == 1)
04360 {
04361 sciprint("\nMark : %d ",ScilabXgc->CurHardSymb);
04362 sciprint("at size %s pts\r\n", size_[ScilabXgc->CurHardSymbSize]);
04363 }
04364 }
04365
04366
04367
04368
04369
04370
04371
04372
04373
04374
04375
04376
04377 void C2F(loadfamily)(name, j, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
04378 char *name;
04379 integer *j,*v3,*v4,*v5,*v6,*v7;
04380 double *dv1, *dv2,*dv3,*dv4;
04381 {
04382 integer i;
04384 i=0;
04385 while ( fonttab[i].alias != (char *) NULL)
04386 {
04387 if (strcmp(fonttab[i].alias,name)==0)
04388 {
04389 C2F(loadfamily_n)(fonttab[i].Winname,j);
04390 return ;
04391 }
04392 i++;
04393 }
04394 C2F(loadfamily_n)(name,j);
04395 }
04396
04397 void C2F(queryfamily)(name, j, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
04398 char *name;
04399 integer *j;
04400 integer *v3;
04401 integer *v4;
04402 integer *v5;
04403 integer *v6;
04404 integer *v7;
04405 double *dv1;
04406 double *dv2;
04407 double *dv3;
04408 double *dv4;
04409 {
04410 integer i ;
04411 name[0]='\0';
04412
04413
04414
04415
04416 for (i=0;i<FONTNUMBER;i++) {
04417 v3[i]=strlen((*FontTab)[i].fname);
04418 if (v3[i] > 0)
04419 strcat(name,(*FontTab)[i].fname);
04420 else {
04421 v3[i]=strlen(fonttab[i].Winname);
04422 strcat(name,fonttab[i].Winname);
04423 }
04424 }
04425 *j=FONTNUMBER;
04426 }
04427
04429 void SciMakeFont(name,size,hfont)
04430 char *name;
04431 int size;
04432 HFONT *hfont;
04433 {
04434 LOGFONT lf;
04435 char *p;
04436 memset(&lf, 0, sizeof(LOGFONT));
04437 strncpy(lf.lfFaceName,name,LF_FACESIZE);
04439 lf.lfHeight = - size*scale_font_size;
04440 lf.lfCharSet = DEFAULT_CHARSET;
04441 if ( (p = strstr(name," Italic")) != (LPSTR)NULL ) {
04442 lf.lfFaceName[ (unsigned int)(p- name) ] = '\0';
04443 lf.lfItalic = TRUE;
04444 }
04445 if ( (p = strstr(name," Bold")) != (LPSTR)NULL ) {
04446 lf.lfFaceName[ (unsigned int)(p- name) ] = '\0';
04447 lf.lfWeight = FW_BOLD;
04448 }
04449 *hfont = CreateFontIndirect((LOGFONT FAR *)&lf);
04450 }
04451
04452 static void C2F(loadfamily_n)(name, j)
04453 char *name;
04454 integer *j;
04455 {
04456 integer i,flag=1 ;
04457 for ( i = 0; i < FONTMAXSIZE ; i++)
04458 {
04459 SciMakeFont(name,size_n_[i], &((*FontTab)[*j].hf[i]));
04460 if ( (*FontTab)[*j].hf[i] == (HFONT) 0 )
04461 {
04462 flag=0;
04463 sciprint("Unknown font : %s\r\n",name);
04464 Scistring("I'll use font: Courier New\r\n");
04465 SciMakeFont("Courier New",size_n_[i], &((*FontTab)[*j].hf[i]));
04466 if ( (*FontTab)[*j].hf[i] == (HFONT) 0)
04467 {
04468 sciprint("Unknown font : %s\r\n","Courier New");
04469 Scistring(" Please send a bug report !\r\n");
04470 }
04471 }
04472 }
04473 (*FontTab)[*j].ok = 1;
04474 if (flag != 0)
04475 strcpy((*FontTab)[*j].fname,name);
04476 else
04477 strcpy((*FontTab)[*j].fname,"Courier New");
04478 }
04479
04480 void CleanFonts()
04481 {
04482 int i,j;
04483 for ( j= 0 ; j < FONTNUMBER ; j++ )
04484 {
04485 if ( (*FontTab)[j].ok == 1)
04486 {
04487 (*FontTab)[j].ok = 0;
04488 for ( i = 0; i < FONTMAXSIZE ; i++)
04489 {
04490 DeleteObject( (*FontTab)[j].hf[i]) ;
04491 (*FontTab)[j].hf[i] = (HFONT) 0;
04492 }
04493 }
04494 }
04495 }
04496
04497
04498
04499
04500
04501 void SciG_Font_Printer(int scale)
04502 {
04503 static int last_scale= -1;
04504 FontTab = &FontInfoTabPrinter;
04505 SymbOffset = &ListOffsetPrint;
04506 if ( last_scale != -1 && last_scale != scale )
04507 CleanFonts();
04508 scale_font_size = last_scale = scale;
04509 LoadFonts();
04510 }
04511
04512 void SciG_Font(void)
04513 {
04514 FontTab = &FontInfoTab;
04515 SymbOffset = &ListOffset;
04516 scale_font_size = 1;
04517 }
04518
04519
04520
04521
04522
04523 static void LoadFonts()
04524 {
04525 integer fnum;
04526 C2F(loadfamily)("CourR",(fnum=0,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
04527 LoadSymbFonts();
04528 C2F(loadfamily)("TimR",(fnum=2,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
04529
04530
04531
04532
04533
04534
04535
04536 }
04537
04538
04539 static void LoadSymbFonts()
04540 {
04542 integer j,fid;
04543 integer i;
04545 C2F(loadfamily)("Symb",(i=1,&i),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
04546
04548 fid=1;
04549 for (i =0 ; i < FONTMAXSIZE ; i++)
04550 {
04551 if ( (*FontTab)[1].hf[i] != NULL)
04552 {
04553 SelectFont(hdc, (*FontTab)[fid].hf[i]);
04554 for (j=0 ; j < SYMBOLNUMBER ; j++)
04555 {
04556 SIZE size;
04557 char str[1];
04558 str[0]=Marks[j];
04559 GetTextExtentPoint32(hdc,str,1,&size);
04560 SymbOffset->xoffset[i][j] = size.cx /2;
04561 SymbOffset->yoffset[i][j] = size.cy /2;
04562 }
04563 }
04564 }
04565 }
04566
04569 int C2F(CurSymbXOffset)()
04570 {
04571 return(- SymbOffset->xoffset[ScilabXgc->CurHardSymbSize]
04572 [ScilabXgc->CurHardSymb]);
04573 }
04574
04575 int C2F(CurSymbYOffset)()
04576 {
04577 return( SymbOffset->yoffset[ScilabXgc->CurHardSymbSize]
04578 [ScilabXgc->CurHardSymb]);
04579 }
04580
04581
04582
04583
04584
04585 static void DrawMark(lhdc,x, y)
04586 HDC lhdc;
04587 integer *x;
04588 integer *y;
04589 {
04590 char str[2];
04591
04592 str[0]=Marks[ScilabXgc->CurHardSymb];
04593 str[1]='\0';
04594 if ( ScilabXgc->CurDrawFunction == GXxor )
04595 {
04596 SIZE size ;
04597 GetTextExtentPoint32(hdc,str,1,&size);
04598 XorString(*x+C2F(CurSymbXOffset)(),*y+C2F(CurSymbYOffset)(),
04599 str,size.cx,size.cy);
04600 }
04601 else
04602 {
04603 TextOut(hdc,*x+C2F(CurSymbXOffset)(),*y+C2F(CurSymbYOffset)(),str,1);
04604 }
04605
04606 }
04607
04608
04609
04610
04611
04612 static POINT *points;
04613 static unsigned nbpoints;
04614 #define NBPOINTS 256
04615
04616 int C2F(store_points)( integer n, integer * vx, integer * vy, integer onemore)
04617 {
04618 integer i,n1;
04619 if ( onemore == 1) n1=n+1;
04620 else n1=n;
04621 if (ReallocVector(n1) == 1)
04622 {
04623 for (i = 0; i < n; i++){
04624 points[i].x = INT_2_16B( vx[i] ) ;
04625 points[i].y = INT_2_16B( vy[i] ) ;
04626 }
04627 if (onemore == 1) {
04628 points[n].x=(short) points[0].x;
04629 points[n].y=(short) points[0].y;
04630 }
04631 return(1);
04632 }
04633 else return(0);
04634 }
04635
04636 static int ReallocVector(n)
04637 integer n;
04638 {
04639 while ( (unsigned) n > nbpoints){
04640 nbpoints = 2 * nbpoints ;
04641
04642 points = (POINT *) REALLOC(points,(unsigned)
04643 nbpoints * sizeof (POINT));
04644 if (points == 0)
04645 {
04646 sciprint(MESSAGE5);
04647 return (0);
04648 }
04649 }
04650 return(1);
04651 }
04652
04653 void deletePoints( void )
04654 {
04655 if( points != NULL )
04656 {
04657 FREE( points ) ;
04658 points = NULL ;
04659 }
04660 }
04661
04662 int C2F(AllocVectorStorage)( void )
04663 {
04664 nbpoints = NBPOINTS;
04665 points = (POINT *) MALLOC( nbpoints * sizeof (POINT));
04666 if ( points == 0) { sciprint(MESSAGE4);return(0);}
04667 else return(1);
04668 }
04669
04670 static POINT *C2F(ReturnPoints)() { return(points); }
04671
04675
04676
04677
04678
04679 static integer xleft,xright,ybot,ytop;
04680
04681
04682
04683
04684
04685
04686
04687
04688
04689
04690 static int clip_point( integer x,integer y)
04691 {
04692 integer ret_val = 0;
04693 if (x < xleft) ret_val |= (char)0x01;
04694 else if (x > xright) ret_val |= (char)0x02;
04695 if (y < ybot) ret_val |= (char)0x04;
04696 else if (y > ytop) ret_val |= (char)0x08;
04697 return ret_val;
04698 }
04699
04700
04701
04702
04703
04704
04705
04706
04707
04708
04709
04710
04711 void set_clip_box( integer xxleft ,
04712 integer xxright,
04713 integer yybot ,
04714 integer yytop )
04715 {
04716 xleft=xxleft;
04717 xright=xxright;
04718 ybot=yybot;
04719 ytop=yytop;
04720 }
04721
04722
04723
04724
04725
04726
04727 void
04728 clip_line( integer x1 ,
04729 integer yy1 ,
04730 integer x2 ,
04731 integer y2 ,
04732 integer * x1n ,
04733 integer * yy1n,
04734 integer * x2n ,
04735 integer * y2n ,
04736 integer * flag )
04737 {
04738 integer x, y, dx, dy, x_intr[2], y_intr[2], count, pos1, pos2;
04739
04740 *x1n=x1; *yy1n=yy1; *x2n=x2; *y2n=y2; *flag=4;
04741 pos1 = clip_point(x1, yy1);
04742 pos2 = clip_point(x2, y2);
04743 if (pos1 || pos2) {
04744 if (pos1 & pos2) { *flag=0;return;}
04745
04746
04747
04748
04749
04750
04751 count = 0;
04752 dx = x2 - x1;
04753 dy = y2 - yy1;
04754
04755
04756 if (dy != 0) {
04757 x = (int) ((ybot - y2) * ((double) dx / (double) dy) + x2);
04758
04759 if (x >= xleft && x <= xright) {
04760 x_intr[count] = x;
04761 y_intr[count++] = ybot;
04762 }
04763 x = (int) ((ytop - y2) * ((double) dx / (double) dy) + x2);
04764
04765 if (x >= xleft && x <= xright) {
04766 x_intr[count] = x;
04767 y_intr[count++] = ytop;
04768 }
04769 }
04770 if ( count < 2 )
04771 {
04772
04773 if (dx != 0) {
04774 y = (int) ((xleft - x2) * ((double) dy / (double) dx) + y2);
04775
04776 if (y >= ybot && y <= ytop) {
04777 x_intr[count] = xleft;
04778 y_intr[count++] = y;
04779 }
04780 if ( count < 2 )
04781 {
04782 y = (int) ((xright - x2) * ((double) dy / (double) dx) + y2);
04783
04784 if (y >= ybot && y <= ytop) {
04785 x_intr[count] = xright;
04786 y_intr[count++] = y;
04787 }
04788 }
04789 }
04790 }
04791
04792 if (count == 2) {
04793 if (pos1 && pos2) {
04794 *x1n = x_intr[0];
04795 *yy1n = y_intr[0];
04796 *x2n = x_intr[1];
04797 *y2n = y_intr[1];
04798 *flag=3;return;
04799 }
04800 else if (pos1) {
04801 if (dx * (x2 - x_intr[0]) + dy * (y2 - y_intr[0]) >= 0) {
04802 *x1n = x_intr[0];
04803 *yy1n = y_intr[0];
04804 *flag=1;return;
04805 }
04806 else {
04807 *x1n = x_intr[1];
04808 *yy1n = y_intr[1];
04809 *flag=1;return;
04810 }
04811 }
04812 else {
04813 if (dx * (x_intr[0] - x1) + dy * (y_intr[0] - yy1) >= 0) {
04814 *x2n = x_intr[0];
04815 *y2n = y_intr[0];
04816 *flag=2;return;
04817 }
04818 else {
04819 *x2n = x_intr[1];
04820 *y2n = y_intr[1];
04821 *flag=2;return;
04822 }
04823 }
04824 }
04825 else
04826 {
04827
04828 *flag=0;return;
04829 }
04830 }
04831 }
04832
04833
04834
04835
04836
04837
04838
04839
04840
04841
04842 integer first_in(n, ideb, vx, vy)
04843 integer n;
04844 integer ideb;
04845 integer *vx;
04846 integer *vy;
04847 {
04848 integer i;
04849 for (i=ideb ; i < n ; i++)
04850 {
04851 if (vx[i]>= xleft && vx[i] <= xright && vy[i] >= ybot && vy[i] <= ytop)
04852 {
04853 return(i);
04854 }
04855 }
04856 return(-1);
04857 }
04858
04859
04860
04861
04862
04863
04864
04865 integer first_out(n, ideb, vx, vy)
04866 integer n;
04867 integer ideb;
04868 integer *vx;
04869 integer *vy;
04870 {
04871 integer i;
04872 for (i=ideb ; i < n ; i++)
04873 {
04874 if ( vx[i]< xleft || vx[i]> xright || vy[i] < ybot || vy[i] > ytop) return(i);
04875 }
04876 return(-1);
04877 }
04878
04879 static void C2F(analyze_points)(integer n, integer *vx, integer *vy, integer onemore)
04880 {
04881 SClipRegion clipping ;
04882 integer windowSize[2] ;
04883 integer verbose = 0 ;
04884 integer narg ;
04885 C2F(getwindowdim)( &verbose, windowSize, &narg, vdouble ) ;
04886 clipping.leftX = 0 ;
04887 clipping.rightX = windowSize[0] ;
04888 clipping.bottomY = 0 ;
04889 clipping.topY = windowSize[1] ;
04890 C2F(clipPolyLine)( n, vx, vy, onemore, &clipping ) ;
04891 }
04892
04893
04894 int CheckScilabXgc()
04895 {
04896 return( ScilabXgc != (struct BCG *) 0);
04897 }
04898
04899
04900 static void C2F(setscilabFigure)(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure)
04901 {
04902 figure=(double *)ScilabXgc->mafigure;
04903 }
04904
04905 static void C2F(getscilabFigure)(integer *verbose, integer *x,integer *narg, double *figure)
04906 {
04907 figure=(double *)ScilabXgc->mafigure;
04908 }
04909
04910 static void C2F(setscilabVersion)(integer *vers, integer *v2, integer *v3, integer *v4)
04911 {
04912
04913 }
04914
04915 static void C2F(getscilabVersion)(integer *verbose, integer *vers, integer *narg, double *dummy)
04916 {
04917 *vers = 0 ;
04918 }
04919
04920 static void C2F(setscilabxgc)(integer *v1, integer *v2, integer *v3, integer *v4)
04921 {
04922
04923 }
04924
04925 static void C2F(getscilabxgc)(integer *verbose, integer *x,integer *narg, double *dummy)
04926 {
04927 double **XGC;
04928 XGC=(double **)dummy;
04929 *XGC= (double *)ScilabXgc;
04930 }
04931