1
/*------------------------------------------------------------------------
3
* Copyright (C) 1998-2000 Enpc/Jean-Philippe Chancelier
5
--------------------------------------------------------------------------*/
7
/*****************************************************************
9
*****************************************************************/
25
#include "../wsci/wgnuplib.h"
26
#include "../wsci/wresource.h"
27
#include "../wsci/wcommon.h"
33
#include "scigraphic.h"
35
#define M_PI 3.14159265358979323846
36
#define CoordModePrevious 1
37
#define CoordModeOrigin 0
40
Warning : the following code won't work if the win.a library is
41
replaced by a dll. The way to find WndGraphProc should be changed
43
Warning : Potential loop
44
It's dangerous to use sciprint in the following code
45
if the argument string to sciprint contains a \n
46
because this will call the TextMessage function (
47
which will enter a message loop).
48
One can enter an infinite loop if TexMessage is activated
49
while inside WndGraphProc and all the following function
50
can be called while inside WndGraphProc.
53
LRESULT CALLBACK WndGraphProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
54
LRESULT CALLBACK WndParentGraphProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
56
/* Initialization values - Guess Now Scale later */
58
#define WIN_XMAX (2400)
59
#define WIN_YMAX (1800)
60
#define WIN_HCHAR (WIN_XMAX/75)
61
#define WIN_VCHAR (WIN_YMAX/25)
63
/* relative or absolute mode for drawing */
65
#define MESSAGE4 "Can't allocate point vector"
66
#define MESSAGE5 "Can't re-allocate point vector"
67
#define Char2Int(x) ( x & 0x000000ff )
69
static double *vdouble = 0; /* used when a double argument is needed */
70
/* These DEFAULTNUMCOLORS colors come from Xfig
71
used in periPos.c and periFig.c
74
unsigned short default_colors[] = {
75
0, 0, 0, /* Black: DEFAULTBLACK */
77
0, 255, 0, /* Green */
78
0, 255, 255, /* Cyan */
80
255, 0, 255, /* Magenta */
81
255, 0, 0, /* Yellow */
82
255, 255, 255, /* White: DEFAULTWHITE */
83
0, 0, 144, /* Blue4 */
84
0, 0, 176, /* Blue3 */
85
0, 0, 208, /* Blue2 */
86
135, 206, 255, /* LtBlue */
87
0, 144, 0, /* Green4 */
88
0, 176, 0, /* Green3 */
89
0, 208, 0, /* Green2 */
90
0, 144, 144, /* Cyan4 */
91
0, 176, 176, /* Cyan3 */
92
0, 208, 208, /* Cyan2 */
96
144, 0, 144, /* Magenta4 */
97
176, 0, 176, /* Magenta3 */
98
208, 0, 208, /* Magenta2 */
99
128, 48, 0, /* Brown4 */
100
160, 64, 0, /* Brown3 */
101
192, 96, 0, /* Brown2 */
102
255, 128, 128, /* Pink4 */
103
255, 160, 160, /* Pink3 */
104
255, 192, 192, /* Pink2 */
105
255, 224, 224, /* Pink */
106
255, 215, 0 /* Gold */
113
static integer DashTab[MAXDASH] = { PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT};
117
We need to provide a hdc for each graphic operation
118
but hdc can be changed to be set to a window a printer a metafile etc...
119
Thus hdc is kept as a global variable
120
which will be set to what we need : see Xcall.c
123
extern GW graphwin; /** keeps information for the current graphic window **/
124
extern TW textwin; /** keeps information for the current graphic window **/
126
/** XXX a mettre ailleurs **/
128
static POINT *C2F(ReturnPoints)();
129
static HFONT getcurfont();
130
int XorString(integer x,integer y, char *string,int fWidth,int fHeight);
132
static int screencolor = 1 ; /* default screen color or not :initgraphic_*/
133
static COLORREF DefaultBackground = RGB(255,255,255);
134
static COLORREF DefaultForeground = RGB(0,0,0);
136
#define COLORREF COLORREF
138
/** Structure to keep the graphic state **/
140
struct BCG MissileXgc ;
142
/* structure for Window List */
147
struct WindowList *next;
150
static WindowList *The_List = (WindowList *) NULL;
151
static integer deleted_win = -1;
152
struct BCG *ScilabXgc = (struct BCG *) 0;
156
Window GetWindowNumber();
157
struct BCG *GetWinXgc();
158
struct BCG *GetWindowXgcNumber();
159
struct BCG *AddNewWindow();
160
struct BCG *AddNewWindowToList();
162
int SwitchWindow(integer *intnum);
164
static int ReallocVector();
165
static void DrawMark(),LoadFonts(), LoadSymbFonts();
166
static void C2F(loadfamily_n)();
167
static void CreateGraphClass();
168
static void XDrawPoints();
169
static BOOL SciPalette(int iNumClr);
170
static void set_current_clip (void);
171
static void set_clip_after_scroll (void) ;
174
/************************************************
175
* dealing with hdc : when using the Rec driver
176
* each command in xcall is ``encadree'' with
177
* SetWinhdc and ReleaseWinHdc
178
* when replaying SetGHdc and are used to provide
179
* the proper hdc for replaying ( see Rec)
180
* XXXX : voir xbasr ??
181
* XXXX bien verifier ds les fonction qui suivent si
182
* ScilabXgc peut etre un pointeur nul
183
*************************************************/
185
static HDC hdc = (HDC) 0 ;
186
static HDC hdc1 = (HDC) 0 ;
189
int sciGetScrollInfo(struct BCG *Scilabgc, int sb_ctl, SCROLLINFO *si)
195
/* definition des scroll bars verticalles */
196
si->cbSize = Scilabgc->vertsi.cbSize;
197
si->fMask = Scilabgc->vertsi.fMask;
198
si->nMin = Scilabgc->vertsi.nMin;
199
si->nMax = Scilabgc->vertsi.nMax;
200
si->nPage = Scilabgc->vertsi.nPage;
201
si->nPos = Scilabgc->vertsi.nPos;
204
/* definition des scroll bars horizontalles */
205
si->cbSize = Scilabgc->horzsi.cbSize;
206
si->fMask = Scilabgc->horzsi.fMask;
207
si->nMin = Scilabgc->horzsi.nMin;
208
si->nMax = Scilabgc->horzsi.nMax;
209
si->nPage = Scilabgc->horzsi.nPage;
210
si->nPos = Scilabgc->horzsi.nPos;
215
/* force le rafraichissement de l'affichage des SB !!! */
216
GetScrollInfo(Scilabgc->CWindow, sb_ctl, &totosi);
221
int sciSetScrollInfo(struct BCG *Scilabgc, int sb_ctl, SCROLLINFO *si, boolean bRedraw)
223
int inttmp = si->nMax;
229
/* definition des scroll bars verticalles */
230
Scilabgc->vertsi.cbSize = si->cbSize;
231
Scilabgc->vertsi.fMask = si->fMask;
232
Scilabgc->vertsi.nMin = si->nMin;
233
Scilabgc->vertsi.nMax = si->nMax;
234
Scilabgc->vertsi.nPage = si->nPage;
235
if (sciGetwresize() == 1) {
237
si->nMax = 0; /* on effectue un swapp pour ne pas changer la val (pointeur !!) */
238
/* 0 permet de faire disparaitre les scrollbars */
240
Scilabgc->vertsi.nPos = si->nPos;
243
/* definition des scroll bars horizontalles */
244
Scilabgc->horzsi.cbSize = si->cbSize;
245
Scilabgc->horzsi.fMask = si->fMask;
246
Scilabgc->horzsi.nMin = si->nMin;
247
Scilabgc->horzsi.nMax = si->nMax;
248
Scilabgc->horzsi.nPage = si->nPage;
249
if (sciGetwresize() == 1) {
253
Scilabgc->horzsi.nPos = si->nPos;
258
/* reset clip region after a scroll */
259
set_clip_after_scroll() ;
261
SetScrollInfo(Scilabgc->CWindow, sb_ctl, si, bRedraw);
262
if (sciGetwresize() == 1)
264
/* force le rafraichissement de l'affichage des SB !!! */
265
sciGetScrollInfo(Scilabgc, sb_ctl, &totosi);
272
int sciInitScrollBar(struct BCG *Scilabgc)
276
/* definition des scroll bars verticalles a la creationS*/
277
si.cbSize = sizeof(SCROLLINFO);
278
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
280
si.nMax = Scilabgc->CWindowHeight;
281
si.nPage = Scilabgc->CWindowHeightView;
283
sciSetScrollInfo(ScilabXgc,SB_VERT, &si, TRUE);
285
/* definition des scroll bars horizontalles */
286
si.cbSize = sizeof(SCROLLINFO);
287
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
289
si.nMax = Scilabgc->CWindowWidth;
290
si.nPage = Scilabgc->CWindowWidthView;
292
sciSetScrollInfo(ScilabXgc,SB_HORZ, &si, TRUE);
299
if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->CWindow != (Window) 0)
301
if ( sciGetPixmapStatus() == 1)
302
hdc = ScilabXgc->hdcCompat;
304
hdc=GetDC(ScilabXgc->CWindow);
310
/** a clarifier XXXX faut-il aussi un test **/
313
if ( sciGetPixmapStatus() == 1)
314
hdc = ScilabXgc->hdcCompat;
316
hdc=GetDC(ScilabXgc->CWindow);
325
if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->CWindow != (Window) 0)
327
if ( sciGetPixmapStatus() != 1)
328
ReleaseDC(ScilabXgc->CWindow,hdc);
333
/****************************
334
* used when replaying with
335
* printers or memory hdc
336
***************************/
338
void SetGHdc(lhdc,width,height)
342
if ( lhdc != (HDC) 0)
345
if ( hdc != (HDC) 0) ReleaseWinHdc();
347
ScilabXgc->CWindowWidth = width;
348
ScilabXgc->CWindowHeight = height;
352
if ( hdc1 != (HDC) 0 && ScilabXgc != (struct BCG *) 0
353
&& ScilabXgc->CWindow != (Window) 0 )
356
hdc=GetDC(ScilabXgc->CWindow);
357
/* get back the dimensions */
358
GetClientRect(ScilabXgc->CWindow,&rect);
359
ScilabXgc->CWindowWidthView = rect.right-rect.left;
360
ScilabXgc->CWindowHeightView = rect.bottom-rect.top;
365
/** Allocating colors in BCG struct */
367
int XgcAllocColors(xgc,m)
372
/* don't forget black and white */
374
if (!(xgc->Red = (float *) MALLOC(mm*sizeof(float)))) {
375
Scistring("XgcAllocColors: unable to alloc\n");
378
if (!(xgc->Green = (float *) MALLOC(mm*sizeof(float)))) {
379
Scistring("XgcAllocColors: unable to alloc\n");
383
if (!(xgc->Blue = (float *) MALLOC(mm*sizeof(float)))) {
384
Scistring("XgcAllocColors: unable to alloc\n");
389
if (!(xgc->Colors = (COLORREF *) MALLOC(mm*sizeof(COLORREF)))) {
390
Scistring("XgcAllocColors: unable to alloc\n");
399
int XgcFreeColors(xgc)
402
FREE(xgc->Red); xgc->Red = (float *) 0;
403
FREE(xgc->Green);xgc->Green = (float *) 0;
404
FREE(xgc->Blue); xgc->Blue = (float *) 0;
405
FREE(xgc->Colors); xgc->Colors = (COLORREF *) 0;
411
/** Pixmap routines **/
413
void C2F(pixmapclear)(v1, v2, v3, v4)
422
px = (ScilabXgc->Colors == NULL)? DefaultBackground
423
: ScilabXgc->Colors[ScilabXgc->NumBackground];
424
if ( ScilabXgc->hdcCompat)
426
SetBkColor( ScilabXgc->hdcCompat, px );
428
* modified by Matthieu Philippe Saphir Control 19 October 2000
429
* GetClientRect is replaced by the internal Scilab graphique Context Structure
430
* calculates in file wgraph.c function WndGraphProc() at WM_SIZE event and
433
/* GetClientRect(ScilabXgc->CWindow, &rect); */
435
rect.bottom = ScilabXgc->CWindowHeight;
437
rect.right = ScilabXgc->CWindowWidth;
438
hBrush = CreateSolidBrush(px);
439
FillRect( ScilabXgc->hdcCompat, &rect,hBrush );
440
DeleteObject(hBrush);
444
void C2F(show)(v1, v2, v3, v4)
450
if ( ScilabXgc->hdcCompat)
452
HDC hdc1=GetDC(ScilabXgc->CWindow);
453
BitBlt (hdc1,0,0,ScilabXgc->CWindowWidth,ScilabXgc->CWindowHeight,
454
ScilabXgc->hdcCompat,ScilabXgc->horzsi.nPos,ScilabXgc->vertsi.nPos,SRCCOPY);
455
ReleaseDC(ScilabXgc->CWindow,hdc1);
461
* ResiZe the pixmap associated to CWindow and store it
462
* back in the window List
465
void CPixmapResize(x, y)
471
hdc1=GetDC(ScilabXgc->CWindow);
472
hbmTemp = CreateCompatibleBitmap (hdc1,x,y);
473
ReleaseDC(ScilabXgc->CWindow,hdc1);
476
sciprint("Can't resize pixmap\r\n");
482
hbmSave = SelectObject ( ScilabXgc->hdcCompat, hbmTemp);
483
if ( ScilabXgc->hbmCompat != NULL)
484
DeleteObject (ScilabXgc->hbmCompat);
485
ScilabXgc->hbmCompat = hbmTemp;
486
C2F(pixmapclear)(PI0,PI0,PI0,PI0);
487
C2F(show)(PI0,PI0,PI0,PI0);
492
Resize the Pixmap according to window size change
493
But only if there's a pixmap
496
void CPixmapResize1()
498
if ( sciGetPixmapStatus() == 1 )
500
CPixmapResize(ScilabXgc->CWindowWidth,ScilabXgc->CWindowHeight);
505
/*-----------------------------------------------------
506
\encadre{General routines}
507
-----------------------------------------------------*/
509
/** To select (raise on the screen )the current graphic Window **/
510
/** If there's no graphic window then select creates one **/
512
void C2F(xselgraphic)(v1, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
525
if (ScilabXgc == (struct BCG *)0 || ScilabXgc->CWindow == (Window ) NULL)
526
C2F(initgraphic)("",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
527
if (IsIconic(ScilabXgc->hWndParent))
528
ShowWindow(ScilabXgc->hWndParent, SW_SHOWNORMAL);
529
BringWindowToTop(ScilabXgc->hWndParent);
532
/** End of graphic (do nothing) **/
534
void C2F(xendgraphic)()
538
void C2F(xend)(v1, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
551
/** Nothing in Windows **/
554
/** Clear the current graphic window **/
556
void C2F(clearwindow)(v1, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
558
integer *v2,*v3,*v4,*v5,*v6,*v7;
559
double *dv1,*dv2,*dv3,*dv4;
564
if ( ScilabXgc->ClipRegionSet == 1)
565
SelectClipRgn(hdc,NULL);
566
if ( sciGetPixmapStatus() == 1)
568
C2F(pixmapclear)(PI0,PI0,PI0,PI0);
569
C2F(show)(PI0,PI0,PI0,PI0);
573
px = (ScilabXgc->Colors == NULL)? DefaultBackground
574
: ScilabXgc->Colors[ScilabXgc->NumBackground];
575
SetBkColor(hdc, px );
576
GetClientRect(ScilabXgc->CWindow, &rect);
577
/** verifier ce qui se passe si on est en Xor ? XXXXXXXX **/
578
hBrush = CreateSolidBrush(px);
579
/* on met a jour la couleur de fond */
582
rect.right = ScilabXgc->CWindowWidth;
583
rect.bottom = ScilabXgc->CWindowHeight;
584
FillRect(hdc, &rect,hBrush );
585
DeleteObject(hBrush);
587
/* reset the clip region using current data */
592
/*-----------------------------------------------------------
593
\encadre{To generate a pause, in seconds}
594
------------------------------------------------------------*/
596
void C2F(xpause)(str, sec_time, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
609
int ms = (*sec_time)/1000; /** time is specified in microseconds in scilab**/
610
if (ms != 0) Sleep(ms); /* Number of milliseconds to sleep. */
615
/*************************************************************
616
* Changes the popupname
617
*************************************************************/
619
void Setpopupname(string)
622
/* set the window title if exists */
623
SetWindowText(ScilabXgc->hWndParent, string);
627
void C2F(setpopupname)(x0, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
629
integer *v2,*v3,*v4,*v5,*v6,*v7;
630
double *dv1,*dv2,*dv3,*dv4;
636
extern void sciSendMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
637
extern int sciPeekMessage(MSG *msg);
641
/****************************************************************
642
Wait for mouse click in graphic window
643
send back mouse location (x1,y1) and button number
645
There's just a pb if the window is iconified when we try to click
646
in this case we return i= -1
647
****************************************************************/
649
void C2F(xclick_any)(str, ibutton, x1, yy1, iwin, iflag, istr, dv1, dv2, dv3, dv4)
651
integer *ibutton,*x1,*yy1,*iwin,*iflag,*istr;
658
WindowList *listptr = The_List;
660
* listptr_tmp est utilise pour recuperer les
661
* events clavier WM_CHAR
663
WindowList *listptr_tmp;
665
HWND hwnd_window_pointed;
669
int buttons = 0,win = 0;
670
integer iwin_tmp = -1;
673
if ( *iflag ==1 && CheckClickQueue(&win,x1,yy1,ibutton) == 1)
685
if (PeekMessage(&msg, 0, 0, 0,PM_REMOVE) != -1) {
686
/* Attention il faut peut etre prendre PeekMessage mais il y a bug */
687
//if (sciPeekMessage(&msg) != 0) {
688
if (msg.message == WM_QUIT)
690
*iwin = deleted_win;/* utile dans le cas ou une fenetre a ete killee */
698
if ( CtrlCHit(&textwin) == 1)
700
*x1= 0 ; *yy1= 0; *ibutton=0; return ;
702
/** a loop on all the graphics windows **/
704
/** special case the list is empty **/
705
if ( listptr == (WindowList *) 0)
707
*x1=0;*yy1=0;*ibutton = -100; return ;
709
while ( (buttons == 0) && ( listptr != (WindowList *) 0 ) )
711
CW = listptr->winxgc.CWindow;
712
*iwin = listptr->winxgc.CurWindow;
713
//listptr = (WindowList *)listptr->next; relegue a la fin
714
if ( msg.hwnd == CW )
717
if ( msg.message == WM_CHAR)
719
/* ou est le curseur ? */
720
GetCursorPos(&Point);
721
/* sur quelle fenetre */
722
hwnd_window_pointed = WindowFromPoint(Point);
723
/* le curseur est bien sur une fenetre */
724
if (hwnd_window_pointed != NULL)
727
listptr_tmp = The_List;
728
/* si la liste de fenetre est non vide */
729
while (listptr_tmp != (WindowList *) 0 )
731
/* si la fenetre pointee est la fenetre courante liste*/
732
if (hwnd_window_pointed == listptr_tmp->winxgc.CWindow)
734
iwin_tmp = listptr_tmp->winxgc.CurWindow;
737
/* on regarde la fenetre scilab suivante */
738
listptr_tmp = (WindowList *)listptr_tmp->next;
740
/* si la fenetre pointee est une fenetre scilab */
741
if ( iwin_tmp != -1 )
743
/* quelle est la dimension de la fenetre */
744
GetWindowRect(hwnd_window_pointed, &lpRect);
745
/* on calcule la position relative du click */
746
*x1 = Point.x - lpRect.left + listptr_tmp->winxgc.horzsi.nPos;
747
*yy1 = Point.y - lpRect.top + listptr_tmp->winxgc.vertsi.nPos;
749
*ibutton = msg.wParam;
753
} /* fi (hwnd_window_pointed != NULL)*/
755
//*ibutton = msg.wParam;
759
else if (msg.message == WM_CLOSE)
767
else if (msg.message == WM_DESTROY)
775
else if ( msg.message == WM_LBUTTONDOWN )
777
*x1 = LOWORD(msg.lParam) + listptr->winxgc.horzsi.nPos;
778
*yy1= HIWORD(msg.lParam) + listptr->winxgc.vertsi.nPos;
783
else if ( msg.message == WM_MBUTTONDOWN )
785
*x1 = LOWORD(msg.lParam) + listptr->winxgc.horzsi.nPos;
786
*yy1= HIWORD(msg.lParam) + listptr->winxgc.vertsi.nPos;
791
else if ( msg.message == WM_RBUTTONDOWN )
793
*x1 = LOWORD(msg.lParam) + listptr->winxgc.horzsi.nPos;
794
*yy1= HIWORD(msg.lParam) + listptr->winxgc.vertsi.nPos;
801
TranslateMessage(&msg);
802
DispatchMessage(&msg);
804
if ( *istr==1 && C2F(ismenu)()==1 )
807
C2F(getmen)(str,&lstr,&entry);
816
} /* if ( msg.hwnd == CW ) */
818
listptr = (WindowList *)listptr->next;
819
}/* while ( (buttons == 0) && ( listptr != (WindowList *) 0 ) ) */
822
TranslateMessage(&msg);
823
DispatchMessage(&msg);
825
} else sciprint("erreur peek\n"); /* fin de PeekMessage */
827
}/* fin de while (buttons == 0) */
830
/* SetCursor(LoadCursor(NULL,IDC_ARROW)); */
835
void C2F(xclick)(str, ibutton, x1, yy1, iflag,istr, v7, dv1, dv2, dv3, dv4)
837
integer *ibutton,*x1,*yy1,*iflag,*istr,*v7;
844
SciClick(ibutton,x1, yy1,iflag,0,0,*istr,str,&lstr);
849
/*sciprint("Menu activated %s %d",str,lstr);*/
857
void C2F(xgetmouse)(str, ibutton, x1, yy1,iflag, v6, v7, dv1, dv2, dv3, dv4)
859
integer *ibutton,*x1,*yy1,*iflag,*v6,*v7;
865
SciClick(ibutton,x1, yy1,iflag,1,0,0,(char *) 0,(integer *)0);
868
void SciMouseCapture()
870
SetCapture(ScilabXgc->CWindow);
873
void SciMouseRelease()
880
/*****************************************
881
* general function for mouse click or
882
* dynamic menu activation
884
* if iflag = 0 : clear previous mouse click
885
* if iflag = 1 : don't
886
* if getmouse = 1 : check also mouse move
887
* if dyn_men = 1 ; check also dynamic menus
888
* ( return the buton code in str )
889
*****************************************/
891
void SciClick(ibutton,x1,yy1,iflag,getmouse,getrelease,dyn_men,str,lstr)
892
integer *ibutton,*x1,*yy1, *iflag,*lstr;
893
int getmouse,dyn_men,getrelease;
898
/** BOOL flag1= TRUE; **/
900
if ( ScilabXgc == (struct BCG *) 0 || ScilabXgc->CWindow == (Window) 0)
902
*ibutton = -100; return;
904
win = ScilabXgc->CurWindow;
905
if ( *iflag ==1 && CheckClickQueue(&win,x1, yy1,ibutton) == 1)
907
/* this is performed in CheckClickQueue
908
* *x1 = *x1 + ScilabXgc->horzsi.nPos;
909
* *yy1 = *yy1 + ScilabXgc->vertsi.nPos;
913
if ( *iflag ==0 ) ClearClickQueue(ScilabXgc->CurWindow);
915
/** Pas necessaire en fait voir si c'est mieux ou moins bien **/
916
if (IsIconic(ScilabXgc->hWndParent))
917
ShowWindow(ScilabXgc->hWndParent, SW_SHOWNORMAL);
918
BringWindowToTop(ScilabXgc->hWndParent);
920
remove the previous click events on the queue
923
flag1= PeekMessage(&msg,ScilabXgc->CWindow,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE);
925
SetCursor(LoadCursor(NULL,IDC_CROSS));
926
/* track a mouse click */
927
while (buttons == 0) {
928
/* PeekMessage(&msg, ScilabXgc->CWindow, 0, 0, PM_REMOVE); jpc may 2000 */
929
PeekMessage(&msg, 0, 0, 0, PM_REMOVE);
930
/** maybe someone decided to destroy scilab Graphic window **/
931
if ( ScilabXgc == (struct BCG *) 0 || ScilabXgc->CWindow == (Window) 0)
933
*ibutton = -100; return;
935
if ( CtrlCHit(&textwin) == 1)
937
*x1= 0 ; *yy1= 0; *ibutton=0; return;
939
if ( msg.hwnd == ScilabXgc->CWindow )
941
if ( msg.message == WM_LBUTTONDOWN )
943
*x1=LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
944
*yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
949
else if ( msg.message == WM_MBUTTONDOWN )
951
*x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
952
*yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
957
else if ( msg.message == WM_RBUTTONDOWN )
959
*x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
960
*yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
965
else if ( getmouse == 1 && msg.message == WM_MOUSEMOVE )
967
*x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
968
*yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
969
*ibutton=-1; /** 0 for left button **/
973
else if ( getrelease == 1 && msg.message == WM_LBUTTONUP )
975
*x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
976
*yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
981
else if (getrelease == 1 && msg.message == WM_MBUTTONUP )
983
*x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
984
*yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
989
else if ( getrelease == 1 && msg.message == WM_RBUTTONUP )
991
*x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
992
*yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
999
TranslateMessage(&msg);
1000
DispatchMessage(&msg);
1005
TranslateMessage(&msg);
1006
DispatchMessage(&msg);
1008
if ( dyn_men == 1 && C2F(ismenu)()==1 )
1011
C2F(getmen)(str,lstr,&entry);
1016
/** SetCursor(LoadCursor(NULL,IDC_ARROW)); **/
1021
/*------------------------------------------------
1022
\encadre{Clear a rectangle }
1023
-------------------------------------------------*/
1025
void C2F(cleararea)(str, x, y, w, h, v6, v7, dv1, dv2, dv3, dv4)
1041
px = (ScilabXgc->Colors == NULL)? DefaultBackground
1042
: ScilabXgc->Colors[ScilabXgc->NumBackground];
1043
SetRect(&rect,(int) *x,(int) *y,(int) *x+*w,(int) *y+*h);
1044
/** XXXXXX : verifier en Xor **/
1045
hBrush = CreateSolidBrush(px);
1046
FillRect(hdc, &rect,hBrush );
1047
DeleteObject(hBrush);
1048
/** XXXX : mettre la background brush ds ScilabXgc pour ne pas
1049
la cr'eer a chaque fois **/
1052
/*---------------------------------------------------------------------
1053
\section{Function for graphic context modification}
1054
------------------------------------------------------------------------*/
1056
/** to get the window upper-left point coordinates on the screen **/
1058
void C2F(getwindowpos)(verbose, x, narg,dummy)
1065
GetWindowRect(ScilabXgc->hWndParent,&rect);
1067
x[0]=rect.left; x[1] = rect.top;
1069
sciprint("\n ScilabXgc->CWindow position :%d,%d\r\n",x[0],x[1]);
1072
/** to set the window upper-left point position on the screen **/
1074
void C2F(setwindowpos)(x, y, v3, v4)
1080
SetWindowPos(ScilabXgc->hWndParent,HWND_TOP,*x,*y,0,0,
1081
SWP_NOSIZE | SWP_NOZORDER );
1084
/** To get the window size **/
1086
void C2F(getwindowdim)(verbose, x, narg,dummy)
1093
/* on renvoie la taille de la fenetre virtuelle */
1094
/* windows devrait s'occupper de tout afficher correctement */
1095
x[0]= ScilabXgc->CWindowWidth;
1096
x[1]= ScilabXgc->CWindowHeight;
1098
sciprint("\n CWindow dim :%d,%d\r\n",(int) x[0],(int) x[1]);
1101
/** To change the window size
1102
* on redimensionne la dimension virtuelle
1103
* si le resizing et off, la vue (View) et la virtuelle sont egales
1104
* voire dans le resize de wgraph.c
1107
void C2F(setwindowdim)(x, y, v3, v4)
1117
if (ScilabXgc->CWindow != (Window) NULL)
1119
/* initialisation des variables SCROLLINFO*/
1120
sciGetScrollInfo(ScilabXgc, SB_VERT, &vertsi);
1121
sciGetScrollInfo(ScilabXgc, SB_HORZ, &horzsi);
1123
ScilabXgc->CWindowWidth = Max((int) *x,50);
1124
ScilabXgc->CWindowHeight =Max((int) *y,50);
1125
if ( sciGetwresize() ) {
1126
ScilabXgc->CWindowWidthView = ScilabXgc->CWindowWidth;
1127
ScilabXgc->CWindowHeightView = ScilabXgc->CWindowHeight;
1132
if (ScilabXgc->CWindowWidthView > ScilabXgc->CWindowWidth)
1133
ScilabXgc->CWindowWidthView = ScilabXgc->CWindowWidth;
1135
if (ScilabXgc->CWindowHeightView > ScilabXgc->CWindowHeight)
1136
ScilabXgc->CWindowHeightView = ScilabXgc->CWindowHeight;
1138
if ( sciGetPixmapStatus() == 1 )
1140
CPixmapResize(ScilabXgc->CWindowWidth,ScilabXgc->CWindowHeight);
1142
GetWindowRect (ScilabXgc->hWndParent, &rect) ;
1143
GetWindowRect (ScilabXgc->CWindow, &rect1) ;
1144
xof = (rect.right-rect.left)- (rect1.right - rect1.left);
1145
yof = (rect.bottom-rect.top)- (rect1.bottom -rect1.top );
1146
if (sciGetwresize () == 0)
1148
SetWindowPos (ScilabXgc->hWndParent, HWND_TOP, 0, 0,
1149
ScilabXgc->CWindowWidthView + xof +
1150
GetSystemMetrics (SM_CXVSCROLL),
1151
ScilabXgc->CWindowHeightView + yof +
1152
GetSystemMetrics (SM_CYHSCROLL),
1153
SWP_NOMOVE | SWP_NOZORDER);
1157
SetWindowPos(ScilabXgc->hWndParent,HWND_TOP,0,0,
1158
ScilabXgc->CWindowWidthView + xof,
1159
ScilabXgc->CWindowHeightView + yof,
1160
SWP_NOMOVE | SWP_NOZORDER );
1162
vertsi.nMax = ScilabXgc->CWindowHeight;
1163
vertsi.nPage = ScilabXgc->CWindowHeightView;
1165
horzsi.nMax = ScilabXgc->CWindowWidth;
1166
horzsi.nPage = ScilabXgc->CWindowWidthView;
1168
sciSetScrollInfo(ScilabXgc,SB_VERT, &(vertsi), TRUE);
1169
sciSetScrollInfo(ScilabXgc,SB_HORZ, &(horzsi), TRUE);
1173
/** To get the popup window size **/
1175
void C2F(getpopupdim)(verbose, x, narg,dummy)
1181
x[0]= ScilabXgc->CWindowWidthView;
1182
x[1]= ScilabXgc->CWindowHeightView;
1185
sciprint("\n ScilabXgc->CWindow dim :%d,%d\r\n",(int) x[0],(int) x[1]);
1190
*@description: To change the popup window size (visible borders)
1191
* it's used by xget('wpdim') and xset('wpdim',x,y) in Scilab langage
1193
void C2F(setpopupdim)(x, y, v3, v4)
1199
int x1= Min((int) *x, ScilabXgc->CWindowWidth);
1200
int x2= Min((int) *y, ScilabXgc->CWindowHeight);
1201
GPopupResize(ScilabXgc,&x1,&x2);
1206
/** To change the window view **/
1207
void C2F(setviewport)(x, y, v3, v4)
1213
if ( sciGetwresize() == 0)
1214
SciViewportMove(ScilabXgc,*x,*y);
1219
*@description: To get the viewport Upper/Left point Position
1221
void C2F(getviewport)(verbose, x, narg,dummy)
1228
if ( sciGetwresize() == 0)
1230
SciViewportGet(ScilabXgc,x,x+1);
1238
sciprint("\n Viewport position:%d,%d\r\n",(int) x[0],(int) x[1]);
1241
/********************************************
1242
* select window intnum as the current window
1243
* window is created if necessary
1244
********************************************/
1245
void C2F(setcurwin)(intnum, v2, v3, v4)
1253
/** send info to menu **/
1254
MenuFixCurrentWin(*intnum);
1255
if ( ScilabXgc == (struct BCG *) 0 )
1257
/** First entry or no more graphic window **/
1258
C2F(initgraphic)("",intnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
1262
if ( ScilabXgc->CurWindow != *intnum )
1264
SwitchWindow(intnum);
1267
if ( ScilabXgc == (struct BCG *) 0 && bcgk != (struct BCG *) 0)
1269
/** back to previous value **/
1271
MenuFixCurrentWin(bcgk->CurWindow);
1275
/* update the dimensions */
1277
GetClientRect(ScilabXgc->CWindow,&rect);
1278
ScilabXgc->CWindowWidthView = rect.right-rect.left;
1279
ScilabXgc->CWindowHeightView = rect.bottom-rect.top;
1280
/* ajout pour compatibilite */
1281
ScilabXgc->CWindowWidth = ScilabXgc->CWindowWidth;
1282
ScilabXgc->CWindowHeight = ScilabXgc->CWindowHeight;
1287
/* used in the previous function to set back the graphic scales
1288
when changing form one window to an other
1289
Also used in scig_tops : to force a reset of scilab graphic scales
1290
after a print in Postscript or Xfig
1292
int SwitchWindow(integer *intnum)
1294
/** trying to get window *intnum **/
1296
SXgc = GetWindowXgcNumber(*intnum);
1297
if ( SXgc != (struct BCG *) 0 )
1299
/** releasing previous hdc **/
1300
/** wininfo("quit window %d with alu %d\r\n",
1301
ScilabXgc->CurWindow,
1302
ScilabXgc->CurDrawFunction);
1308
/** wininfo("switching to window %d with alu %d\r\n",*intnum,
1309
ScilabXgc->CurDrawFunction); **/
1310
get_window_scale(*intnum,NULL);
1314
/** Create window **/
1315
C2F(initgraphic)("",intnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
1320
/** Get the id number of the Current Graphic Window **/
1324
Get the id number of the Current Graphic Window
1325
In all the other functions we are sure that ScilabXgc exists
1326
when we call them ( see sciwin in matdes.f )
1327
exept for this function which is called in sciwin and the previous one
1329
void C2F(getcurwin)(verbose, intnum, narg,dummy)
1336
*intnum = (ScilabXgc != (struct BCG *) 0) ? ScilabXgc->CurWindow : 0;
1338
sciprint("\nCurrent Graphic Window :%d\r\n",(int) *intnum);
1341
/** Set a clip zone (rectangle ) **/
1343
void C2F(setclip)(x, y, w, h)
1349
ScilabXgc->ClipRegionSet = 1;
1350
ScilabXgc->CurClipRegion[0]= *x;
1351
ScilabXgc->CurClipRegion[1]= *y;
1352
ScilabXgc->CurClipRegion[2]= *w;
1353
ScilabXgc->CurClipRegion[3]= *h;
1357
static void set_current_clip()
1360
if (ScilabXgc->ClipRegionSet == 0) return;
1361
if (sciGetwresize() == 1) {
1362
hRgn = CreateRectRgn(ScilabXgc->CurClipRegion[0],
1363
ScilabXgc->CurClipRegion[1],
1364
ScilabXgc->CurClipRegion[2]
1365
+ ScilabXgc->CurClipRegion[0],
1366
ScilabXgc->CurClipRegion[3]
1367
+ ScilabXgc->CurClipRegion[1]);
1370
hRgn = CreateRectRgn(ScilabXgc->CurClipRegion[0] - GetScrollPos(ScilabXgc->CWindow,SB_HORZ),
1371
ScilabXgc->CurClipRegion[1] - GetScrollPos(ScilabXgc->CWindow,SB_VERT),
1372
ScilabXgc->CurClipRegion[2]
1373
+ ScilabXgc->CurClipRegion[0],
1374
ScilabXgc->CurClipRegion[3]
1375
+ ScilabXgc->CurClipRegion[1]);
1377
SelectClipRgn(hdc, hRgn);
1381
static void set_clip_after_scroll()
1384
if (ScilabXgc->ClipRegionSet == 1 && sciGetwresize() == 0)
1386
hRgn = CreateRectRgn(ScilabXgc->CurClipRegion[0] - GetScrollPos(ScilabXgc->CWindow,SB_HORZ),
1387
ScilabXgc->CurClipRegion[1] - GetScrollPos(ScilabXgc->CWindow,SB_VERT),
1388
ScilabXgc->CurClipRegion[2]
1389
+ ScilabXgc->CurClipRegion[0],
1390
ScilabXgc->CurClipRegion[3]
1391
+ ScilabXgc->CurClipRegion[1]);
1392
SelectClipRgn(hdc, hRgn);
1397
/** unset clip zone **/
1398
void C2F(unsetclip)(v1, v2, v3, v4)
1404
ScilabXgc->ClipRegionSet = 0;
1405
SelectClipRgn(hdc,NULL);
1408
/** Get the boundaries of the current clip zone **/
1409
void C2F(getclip)(verbose, x, narg,dummy)
1415
x[0] = ScilabXgc->ClipRegionSet;
1419
x[1] =ScilabXgc->CurClipRegion[0];
1420
x[2] =ScilabXgc->CurClipRegion[1];
1421
x[3] =ScilabXgc->CurClipRegion[2];
1422
x[4] =ScilabXgc->CurClipRegion[3];
1426
if (ScilabXgc->ClipRegionSet == 1)
1427
sciprint("\nThere's a Clip Region :x:%d,y:%d,w:%d,h:%d\r\n",
1428
ScilabXgc->CurClipRegion[0],
1429
ScilabXgc->CurClipRegion[1],
1430
ScilabXgc->CurClipRegion[2],
1431
ScilabXgc->CurClipRegion[3]);
1433
Scistring("\nNo Clip Region");
1436
/*----------------------------------------------------------
1437
\encadre{For the drawing functions dealing with vectors of
1438
points, the following routine is used to select the mode
1439
absolute or relative }
1440
Absolute mode if *num==0, relative mode if *num != 0
1441
------------------------------------------------------------*/
1442
/** to set absolute or relative mode **/
1443
void C2F(setabsourel)(num, v2, v3, v4)
1450
ScilabXgc->CurVectorStyle = CoordModeOrigin;
1452
ScilabXgc->CurVectorStyle = CoordModePrevious ;
1455
/** to get information on absolute or relative mode **/
1456
void C2F(getabsourel)(verbose, num, narg,dummy)
1463
*num = ScilabXgc->CurVectorStyle ;
1465
if (ScilabXgc->CurVectorStyle == CoordModeOrigin)
1466
Scistring("\nTrace Absolu");
1468
Scistring("\nTrace Relatif");
1471
/** The alu function for drawing : Works only with X11 **/
1472
/** Not in Postscript **/
1473
/** All the possibilities : Read The X11 manual to get more informations **/
1474
static struct alinfo {
1477
char *info;} AluStruc_[] =
1479
{"GXclear" ,R2_WHITE," 0 "},
1480
{"GXand" ,R2_MASKPEN," src AND dst "},
1481
{"GXandReverse" ,R2_MASKPENNOT," src AND NOT dst "},
1482
{"GXcopy" ,R2_COPYPEN," src "},
1483
{"GXandInverted" ,R2_MASKNOTPEN," NOT src AND dst "},
1484
{"GXnoop" ,R2_NOP," dst "},
1485
{"GXxor" ,R2_XORPEN," src XOR dst "},
1486
{"GXor" ,R2_MERGEPEN," src OR dst "},
1487
{"GXnor" ,R2_NOTMERGEPEN," NOT src AND NOT dst "},
1488
{"GXequiv" ,R2_NOTXORPEN," NOT src XOR dst "},
1489
{"GXinvert" ,R2_NOT," NOT dst "},
1490
{"GXorReverse" ,R2_MERGEPENNOT," src OR NOT dst "},
1491
{"GXcopyInverted" ,R2_NOTCOPYPEN," NOT src "},
1492
{"GXorInverted" ,R2_MERGENOTPEN," NOT src OR dst "},
1493
{"GXnand" ,R2_NOTMASKPEN," NOT src OR NOT dst "},
1494
{"GXset" ,R2_BLACK," 1 "}
1498
static void idfromname(name1, num)
1503
for ( i =0 ; i < 16;i++)
1504
if (strcmp(AluStruc_[i].name,name1)== 0)
1505
*num=AluStruc_[i].id;
1508
Scistring("\n Use the following keys (integer in scilab");
1509
for ( i=0 ; i < 16 ; i++)
1510
sciprint("\nkey %s -> %s\r\n",AluStruc_[i].name,
1515
void C2F(setalufunction)(string)
1519
idfromname(string,&value);
1522
SetROP2(hdc,(int) value);
1523
ScilabXgc->CurDrawFunction = value;
1524
set_c(ScilabXgc->CurColor);
1528
void C2F(setalufunction1)(num, v2, v3, v4)
1535
ScilabXgc->CurDrawFunction = Min(15,Max(0,*num));
1536
value=AluStruc_[ScilabXgc->CurDrawFunction].id;
1537
SetROP2(hdc,(int) value);
1538
if ( ScilabXgc->CurColorStatus == 1 )
1540
/** we force here the computation of current color **/
1541
/** since the way color are computed changes according **/
1542
/** to alufunction mode **/
1543
set_c(ScilabXgc->CurColor);
1547
void C2F(getalufunction)(verbose, value, narg,dummy)
1554
*value = ScilabXgc->CurDrawFunction ;
1557
sciprint("\nThe Alufunction is %s -> <%s>\r\n",
1558
AluStruc_[*value].name,
1559
AluStruc_[*value].info);}
1563
/** to set the thickness of lines : 0 is a possible value **/
1564
/** give the thinest line (0 and 1 the same for X11 but **/
1565
/** with diferent algorithms ) **/
1566
/** defaut value is 1 **/
1567
void C2F(setthickness)(value, v2, v3, v4)
1574
ScilabXgc->CurLineWidth =Max(0, *value);
1575
if ( ScilabXgc->CurColorStatus == 1 )
1577
COLORREF px = DefaultForeground ;
1578
if (ScilabXgc->Colors != NULL)
1580
if ( ScilabXgc->CurDrawFunction != GXxor )
1581
px= ScilabXgc->Colors[ScilabXgc->CurColor];
1583
px = ScilabXgc->Colors[ScilabXgc->CurColor]
1584
^ ScilabXgc->Colors[ScilabXgc->NumBackground];
1586
hpen = CreatePen(PS_SOLID,ScilabXgc->CurLineWidth,px);
1591
int style = DashTab[ScilabXgc->CurDashStyle];
1592
/** warning win95 only uses dot or dash with linewidth <= 1 **/
1593
width = ( style != PS_SOLID) ? 0 : ScilabXgc->CurLineWidth ;
1594
hpen = CreatePen(style,width,RGB(0,0,0));
1596
SelectObject(hdc,hpen);
1597
if ( ScilabXgc->hPen != (HPEN) 0 ) DeleteObject(ScilabXgc->hPen);
1598
ScilabXgc->hPen = hpen;
1601
/** to get the thickness value **/
1603
void C2F(getthickness)(verbose, value, narg,dummy)
1610
*value = ScilabXgc->CurLineWidth ;
1612
sciprint("\nLine Width:%d\r\n", ScilabXgc->CurLineWidth ) ;
1615
/** To set grey level for filing areas **/
1616
/** from black (*num =0 ) to white **/
1618
#define GREYNUMBER 17
1619
/** maybe not so useful ???? XXXX **/
1621
HBRUSH Tabpix_[GREYNUMBER];
1623
static WORD grey0[GREYNUMBER][8]={
1624
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1625
{0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00},
1626
{0x00, 0x44, 0x00, 0x22, 0x08, 0x40, 0x01, 0x20},
1627
{0x00, 0x92, 0x00, 0x25, 0x00, 0x92, 0x00, 0xa4},
1628
{0x55, 0x00, 0xaa, 0x00, 0x55, 0x00, 0xaa, 0x00},
1629
{0xad, 0x00, 0x5b, 0x00, 0xda, 0x00, 0x6d, 0x00},
1630
{0x6d, 0x02, 0xda, 0x08, 0x6b, 0x10, 0xb6, 0x20},
1631
{0x6d, 0x22, 0xda, 0x0c, 0x6b, 0x18, 0xb6, 0x24},
1632
{0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa},
1633
{0x92, 0xdd, 0x25, 0xf3, 0x94, 0xe7, 0x49, 0xdb},
1634
{0x92, 0xfd, 0x25, 0xf7, 0x94, 0xef, 0x49, 0xdf},
1635
{0x52, 0xff, 0xa4, 0xff, 0x25, 0xff, 0x92, 0xff},
1636
{0xaa, 0xff, 0x55, 0xff, 0xaa, 0xff, 0x55, 0xff},
1637
{0xff, 0x6d, 0xff, 0xda, 0xff, 0x6d, 0xff, 0x5b},
1638
{0xff, 0xbb, 0xff, 0xdd, 0xf7, 0xbf, 0xfe, 0xdf},
1639
{0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff},
1640
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1644
void C2F(CreatePatterns)()
1647
for ( i=0 ; i < GREYNUMBER ; i++)
1650
hBitmap = CreateBitmap(8,8,1,1,grey0[i]);
1651
Tabpix_[i] =CreatePatternBrush(hBitmap);
1652
DeleteObject(hBitmap);
1656
void C2F(setpattern)(num, v2, v3, v4)
1662
if ( ScilabXgc->CurColorStatus == 1 )
1668
i= Max(0,Min(*num-1,GREYNUMBER-1));
1669
ScilabXgc->CurPattern = i;
1670
SelectObject(hdc,Tabpix_[i]);
1674
/** To get the id of the current pattern **/
1675
void C2F(getpattern)(verbose, num, narg,dummy)
1682
if ( ScilabXgc->CurColorStatus == 1 )
1683
*num = ScilabXgc->CurColor +1 ;
1685
*num = ScilabXgc->CurPattern +1 ;
1687
sciprint("\n Pattern : %d\r\n",ScilabXgc->CurPattern+1);
1690
/** To get the id of the last pattern **/
1691
void C2F(getlast)(verbose, num, narg,dummy)
1697
if ( ScilabXgc->CurColorStatus == 1 )
1699
*num = ScilabXgc->IDLastPattern + 1;
1701
sciprint("\n Id of Last Color %d\r\n",(int)*num);
1705
*num = ScilabXgc->IDLastPattern + 1;
1707
sciprint("\n Id of Last Pattern %d\r\n",(int)*num);
1712
/*--------------------------------------
1713
\encadre{Line style }
1714
---------------------------------------*/
1716
/** use a table of dashes and set default X11-dash style to **/
1717
/** one of the possible value. value points **/
1718
/** to a strictly positive integer **/
1719
/** if *value == 0 -> Solid line **/
1720
/** else Dashed Line **/
1722
/* old version of setdash retained for compatibility */
1723
void C2F(set_dash_or_color)(value, v2, v3, v4)
1729
if ( ScilabXgc->CurColorStatus == 1)
1734
C2F(setdash)(value, v2, v3, v4);
1737
void C2F(setdash)(value, v2, v3, v4)
1747
l3 = Max(0,Min(MAXDASH - 1,*value - 1));
1748
/** warning win95 only uses dot or dash with linewidth <= 1 **/
1749
width = ( DashTab[l3] != PS_SOLID) ? 0 : ScilabXgc->CurLineWidth ;
1750
if ( ScilabXgc->CurColorStatus == 1) {
1751
id = ScilabXgc->CurColor;
1752
if ( ScilabXgc->CurDrawFunction != GXxor )
1753
col = ScilabXgc->Colors[id];
1755
col = ScilabXgc->Colors[id] ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
1760
hpen = CreatePen(DashTab[l3],width,col);
1761
SelectObject(hdc,hpen);
1762
if ( ScilabXgc->hPen != (HPEN) 0 ) DeleteObject(ScilabXgc->hPen);
1763
ScilabXgc->hPen = hpen;
1764
ScilabXgc->CurDashStyle = l3;
1767
static void C2F(set_dash_and_color)(value, v2, v3, v4)
1773
C2F(setdash)(value, v2, v3, v4);
1774
C2F(setpattern)(value+6, v2, v3, v4);
1777
static void C2F(set_line_style)(value, v2, v3, v4)
1784
if (ScilabXgc->CurColorStatus == 0)
1785
C2F(setdash)(value,PI0,PI0,PI0);
1787
j= ScilabXgc->CurDashStyle + 1;
1788
C2F(setdash)(&j,PI0,PI0,PI0);
1789
C2F(setpattern)(value,PI0,PI0,PI0);
1794
/** to get the current dash-style **/
1795
/* old version of getdash retained for compatibility */
1796
void C2F(get_dash_or_color)(verbose, value, narg,dummy)
1803
if ( ScilabXgc->CurColorStatus == 1)
1806
*value =ScilabXgc->CurColor+1;
1807
if (*verbose == 1) sciprint("Color %d",(int)*value);
1810
C2F(getdash)(verbose, value, narg,dummy);
1813
void C2F(getdash)(verbose, value, narg,dummy)
1820
*value =ScilabXgc->CurDashStyle+1;
1825
case 0: Scistring("\nLine style = Line Solid\n"); break ;
1826
case 1: Scistring("\nLine style = DASH\n"); break ;
1827
case 2: Scistring("\nLine style = DOT\n"); break ;
1828
case 3: Scistring("\nLine style = DASHDOT\n"); break ;
1829
case 4: Scistring("\nLine style = DASHDOTDOT\n"); break ;
1833
static void C2F(get_dash_and_color)(verbose, value, narg,dummy)
1839
/*may be improved replacing 6 by narg */
1840
C2F(getdash)(verbose, value, narg,dummy);
1841
C2F(getpattern)(verbose, value+6, narg,dummy);
1845
/* basculement eventuel de couleur a n&b */
1846
void C2F(usecolor)(num, v1, v2, v3)
1853
i = Min(Max(*num,0),1);
1854
if ( ScilabXgc->CurColorStatus != (int) i)
1856
if (ScilabXgc->CurColorStatus == 1)
1858
/* je passe de Couleur a n&b */
1859
/* remise des couleurs a vide */
1860
ScilabXgc->CurColorStatus = 1;
1861
C2F(setpattern)((i=1,&i),PI0,PI0,PI0);
1862
/* passage en n&b */
1863
ScilabXgc->CurColorStatus = 0;
1864
i= ScilabXgc->CurPattern + 1;
1865
C2F(setpattern)(&i,PI0,PI0,PI0);
1866
i= ScilabXgc->CurDashStyle + 1;
1867
C2F(setdash)(&i,PI0,PI0,PI0);
1868
ScilabXgc->IDLastPattern = GREYNUMBER - 1;
1872
/* je passe en couleur */
1873
/* remise a zero des patterns et dash */
1874
/* remise des couleurs a vide */
1875
ScilabXgc->CurColorStatus = 0;
1876
C2F(setpattern)((i=1,&i),PI0,PI0,PI0);
1877
C2F(setdash)((i=1,&i),PI0,PI0,PI0);
1878
/* passage en couleur */
1879
ScilabXgc->CurColorStatus = 1;
1880
i= ScilabXgc->CurColor + 1;
1881
C2F(setpattern)(&i,PI0,PI0,PI0);
1882
ScilabXgc->IDLastPattern = ScilabXgc->Numcolors - 1;
1887
void C2F(getusecolor)(verbose, num, narg,dummy)
1893
*num = ScilabXgc->CurColorStatus;
1895
sciprint("\n Use color %d\r\n",(int)*num);
1899
/** Change the status of a Graphic Window **/
1900
/** adding or removing a Background Pixmap to it **/
1901
void C2F(setpixmapOn)(num, v2, v3, v4)
1907
integer num1= Min(Max(*num,0),1);
1908
if ( sciGetPixmapStatus() == num1 ) return;
1911
/** I add a Background Pixmap to the window **/
1912
C2F(xinfo)("Animation mode is on,( xset('pixmap',0) to leave)",
1913
PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
1914
if (( ScilabXgc->hdcCompat = CreateCompatibleDC (hdc)) == NULL)
1916
sciprint("Seeting pixmap on is impossible \r\n");
1922
SetMapMode(ScilabXgc->hdcCompat, MM_TEXT);
1923
SetBkMode(ScilabXgc->hdcCompat,TRANSPARENT);
1924
SetTextAlign(ScilabXgc->hdcCompat, TA_LEFT|TA_BOTTOM);
1925
hbmTemp =CreateCompatibleBitmap (hdc,
1926
ScilabXgc->CWindowWidth,
1927
ScilabXgc->CWindowHeight);
1931
sciprint("Seeting pixmap on is impossible \r\n");
1937
hbmSave = SelectObject ( ScilabXgc->hdcCompat, hbmTemp);
1938
if ( ScilabXgc->hbmCompat != NULL)
1939
DeleteObject (ScilabXgc->hbmCompat);
1940
ScilabXgc->hbmCompat = hbmTemp;
1941
ScilabXgc->CurPixmapStatus = 1;
1942
C2F(pixmapclear)(PI0,PI0,PI0,PI0); /* background color */
1943
/** the create default font/brush etc... in hdc */
1944
SetGHdc(ScilabXgc->hdcCompat,ScilabXgc->CWindowWidth,
1945
ScilabXgc->CWindowHeight);
1947
SetGHdc((HDC)0,ScilabXgc->CWindowWidth,
1948
ScilabXgc->CWindowHeight);
1950
C2F(show)(PI0,PI0,PI0,PI0);
1956
/** I remove the Background Pixmap to the window **/
1957
ScilabXgc->CurPixmapStatus = 0;
1959
if ( ScilabXgc->hdcCompat)
1960
SelectObject (ScilabXgc->hdcCompat, NULL) ;
1961
if ( ScilabXgc->hbmCompat)
1962
DeleteObject (ScilabXgc->hbmCompat);
1963
if ( ScilabXgc->hdcCompat)
1965
if ( hdc == ScilabXgc->hdcCompat)
1966
hdc=GetDC(ScilabXgc->CWindow);
1967
DeleteDC(ScilabXgc->hdcCompat);
1969
ScilabXgc->hbmCompat = (HBITMAP) 0;
1970
ScilabXgc->hdcCompat = (HDC) 0;
1974
void C2F(getpixmapOn)(verbose, value, narg,dummy)
1981
*value=sciGetPixmapStatus();
1983
if (*verbose == 1) sciprint("Color %d",(int)*value);
1987
integer sciGetPixmapStatus()
1989
return ScilabXgc->CurPixmapStatus;
1992
/** Change the status of a Graphic Window **/
1993
/** follow or dont follow the viewport resize **/
1995
void C2F(setwresize)(num, v2, v3, v4)
2001
integer num1= Min(Max(*num,0),1);
2005
ScilabXgc->CurResizeStatus = num1; /* a faire avant setwindowdim */
2006
C2F(setwindowdim)((xtmp = ScilabXgc->CWindowWidthView, &xtmp),
2007
(ytmp=ScilabXgc->CWindowHeightView,&ytmp), PI0, PI0);
2008
SetViewportOrgEx(hdc,-ScilabXgc->horzsi.nPos,-ScilabXgc->vertsi.nPos,NULL);
2009
UpdateWindow(ScilabXgc->CWindow);
2010
InvalidateRect(ScilabXgc->CWindow,NULL,TRUE);
2013
void C2F(getwresize)(verbose, value, narg,dummy)
2019
*value = sciGetwresize();
2021
if (*verbose == 1) sciprint("Resize status %d",(int)*value);
2027
* Cette fonction renvoie le status wresize
2029
integer sciGetwresize()
2031
return ScilabXgc->CurResizeStatus;
2037
static int set_default_colormap_flag = 1;
2039
int C2F(sedeco)(flag)
2042
set_default_colormap_flag = *flag;
2047
/* set_default_colormap is called when raising a window for the first
2048
timeby xset('window',...) or by getting back to default by
2049
xset('default',...) */
2051
void set_default_colormap()
2054
unsigned long maxcol;
2057
/** XXXXX Trouver une doc sur les pallettes **/
2058
int iPlanes = GetDeviceCaps(hdc,PLANES);
2059
int iBitsPixel = GetDeviceCaps(hdc,BITSPIXEL);
2060
/* int numcolors = GetDeviceCaps(hdc,NUMCOLORS);*/
2061
/** to avoid overflow in maxcol **/
2062
/** must be improved for 32bit color display **/
2063
if ( iBitsPixel > 24 ) iBitsPixel = 24;
2064
maxcol = 1 << ( iPlanes*iBitsPixel);
2066
/* we don't want to set the default colormap at window creation
2067
if the scilab command was xset("colormap"); */
2069
if (set_default_colormap_flag == 0) return;
2070
if ( DEFAULTNUMCOLORS > maxcol) {
2071
sciprint("No enough colors for default colormap. Maximum is %d\r\n",
2075
m = DEFAULTNUMCOLORS;
2077
/* Save old color vectors */
2078
c = ScilabXgc->Colors;
2080
g = ScilabXgc->Green;
2081
b = ScilabXgc->Blue;
2083
if (!XgcAllocColors(ScilabXgc,m)) {
2084
ScilabXgc->Colors = c;
2086
ScilabXgc->Green = g;
2087
ScilabXgc->Blue = b;
2091
/* Getting RGB values */
2092
for (i = 0; i < m; i++) {
2093
ScilabXgc->Red[i] = ((float)default_colors[3*i])/(float)255.0;
2094
ScilabXgc->Green[i] = (float)default_colors[3*i+1]/(float)255.0;
2095
ScilabXgc->Blue[i] = (float)default_colors[3*i+2]/(float)255.0;
2096
ScilabXgc->Colors[i] = RGB(default_colors[3*i],
2097
default_colors[3*i+1],
2098
default_colors[3*i+2]);
2101
ScilabXgc->Red[m] = ScilabXgc->Green[m] = ScilabXgc->Blue[m] =(float) 0;
2102
ScilabXgc->Colors[m]= RGB(0,0,0);
2105
ScilabXgc->Red[m+1] = ScilabXgc->Green[m+1] = ScilabXgc->Blue[m+1] = (float)1;
2106
ScilabXgc->Colors[m+1]= RGB(255,255,255);
2108
ScilabXgc->Numcolors = m;
2109
ScilabXgc->IDLastPattern = m - 1;
2110
ScilabXgc->CmapFlag = 1;
2111
/* Black and white pixels */
2113
ScilabXgc->NumForeground = m;
2114
ScilabXgc->NumBackground = m + 1;
2115
FREE(c); FREE(r); FREE(g); FREE(b);
2118
/* Setting the colormap
2119
a must be a m x 3 double RGB matrix:
2123
*v2 gives the value of m and *v3 must be equal to 3 */
2125
void C2F(setcolormap)(v1,v2,v3,v4,v5,v6,a)
2128
integer *v4,*v5,*v6;
2132
unsigned long maxcol;
2135
/** XXXXX Trouver une doc sur les pallettes **/
2136
int iPlanes = GetDeviceCaps(hdc,PLANES);
2137
int iBitsPixel = GetDeviceCaps(hdc,BITSPIXEL);
2138
/** to avoid overflow in maxcol **/
2139
/** must be improved for 32bit color display **/
2140
if ( iBitsPixel > 24 ) iBitsPixel = 24;
2141
maxcol = 1 << ( iPlanes*iBitsPixel);
2142
palstatus= (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE);
2143
/** sciprint(" couleurs %d et palette %d\r\n",maxcol,palstatus); **/
2145
if (*v2 != 3 || (unsigned long) *v1 > maxcol || *v1 < 0) {
2146
sciprint("Colormap must be a m x 3 array with m <= %d\r\n",maxcol);
2151
/* Save old color vectors */
2152
c = ScilabXgc->Colors;
2154
g = ScilabXgc->Green;
2155
b = ScilabXgc->Blue;
2157
if (!XgcAllocColors(ScilabXgc,m)) {
2158
ScilabXgc->Colors = c;
2160
ScilabXgc->Green = g;
2161
ScilabXgc->Blue = b;
2165
/* Checking RGB values */
2166
for (i = 0; i < m; i++) {
2167
if (a[i] < 0 || a[i] > 1 || a[i+m] < 0 || a[i+m] > 1 ||
2168
a[i+2*m] < 0 || a[i+2*m]> 1) {
2169
Scistring("RGB values must be between 0 and 1\n");
2170
ScilabXgc->Colors = c;
2172
ScilabXgc->Green = g;
2173
ScilabXgc->Blue = b;
2176
ScilabXgc->Red[i] = (float)a[i];
2177
ScilabXgc->Green[i] = (float)a[i+m];
2178
ScilabXgc->Blue[i] = (float)a[i+2*m];
2179
ScilabXgc->Colors[i] = RGB((unsigned short) (255.0*a[i]),
2180
(unsigned short) (255.0*a[i+m]),
2181
(unsigned short) (255.0*a[i+2*m]));
2184
ScilabXgc->Red[m] = ScilabXgc->Green[m] = ScilabXgc->Blue[m] = (float) 0;
2185
ScilabXgc->Colors[m]= RGB(0,0,0);
2188
ScilabXgc->Red[m+1] = ScilabXgc->Green[m+1] = ScilabXgc->Blue[m+1] = (float) 0;
2189
ScilabXgc->Colors[m+1]= RGB(255,255,255);
2191
ScilabXgc->Numcolors = m;
2192
ScilabXgc->IDLastPattern = m - 1;
2193
ScilabXgc->CmapFlag = 0;
2194
ScilabXgc->NumForeground = m;
2195
ScilabXgc->NumBackground = m + 1;
2196
C2F(usecolor)((i=1,&i) ,PI0,PI0,PI0);
2197
/** we must change the current pattern before the alufunction **/
2198
C2F(setpattern)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
2199
C2F(setalufunction1)(&ScilabXgc->CurDrawFunction,PI0,PI0,PI0);
2200
C2F(setforeground)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
2201
C2F(setbackground)((i=ScilabXgc->NumForeground+2,&i),PI0,PI0,PI0);
2202
FREE(c); FREE(r); FREE(g); FREE(b);
2205
/*** unfinished : a version with palettes **/
2207
void C2F(pal_setcolormap)(v1,v2,v3,v4,v5,v6,a)
2210
integer *v4,*v5,*v6;
2216
int iPlanes = GetDeviceCaps(hdc,PLANES);
2217
int iBitsPixel = GetDeviceCaps(hdc,BITSPIXEL);
2218
/** to avoid overflow in maxcol **/
2219
/** must be improved for 32bit color display **/
2220
if ( iBitsPixel > 24 ) iBitsPixel = 24;
2221
maxcol = 1 << ( iPlanes*iBitsPixel);
2223
if (*v2 != 3 || *v1 > maxcol || *v1 < 0) {
2224
sciprint("Colormap must be a m x 3 array with m <= %d\r\n",maxcol);
2229
/* Save old color vectors */
2230
c = ScilabXgc->Colors;
2232
g = ScilabXgc->Green;
2233
b = ScilabXgc->Blue;
2235
if (!XgcAllocColors(ScilabXgc,m)) {
2236
ScilabXgc->Colors = c;
2238
ScilabXgc->Green = g;
2239
ScilabXgc->Blue = b;
2243
/* Checking RGB values */
2244
for (i = 0; i < m; i++) {
2245
if (a[i] < 0 || a[i] > 1 || a[i+m] < 0 || a[i+m] > 1 ||
2246
a[i+2*m] < 0 || a[i+2*m]> 1) {
2247
Scistring("RGB values must be between 0 and 1\n");
2248
ScilabXgc->Colors = c;
2250
ScilabXgc->Green = g;
2251
ScilabXgc->Blue = b;
2254
ScilabXgc->Red[i] = (float)a[i];
2255
ScilabXgc->Green[i] = (float)a[i+m];
2256
ScilabXgc->Blue[i] = (float)a[i+2*m];
2257
ScilabXgc->Colors[i] = RGB((unsigned short) (255.0*a[i]),
2258
(unsigned short) (255.0*a[i+m]),
2259
(unsigned short) (255.0*a[i+2*m]));
2262
ScilabXgc->Red[m] = ScilabXgc->Green[m] = ScilabXgc->Blue[m] = (float) 0;
2263
ScilabXgc->Colors[m]= RGB(0,0,0);
2266
ScilabXgc->Red[m+1] = ScilabXgc->Green[m+1] = ScilabXgc->Blue[m+1] = (float) 0;
2267
ScilabXgc->Colors[m+1]= RGB(255,255,255);
2269
if ((GetDeviceCaps(hdc, RASTERCAPS)) & RC_PALETTE )
2271
if ( SciPalette(m) == FALSE )
2273
for (i = 0; i < m; i++) {
2274
ScilabXgc->Colors[i] = RGB((unsigned short) (255.0*a[i]),
2275
(unsigned short) (255.0*a[i+m]),
2276
(unsigned short) (255.0*a[i+2*m]));
2278
ScilabXgc->Colors[m]= RGB(0,0,0);
2279
ScilabXgc->Colors[m+1]= RGB(255,255,255);
2282
ScilabXgc->Numcolors = m;
2283
ScilabXgc->IDLastPattern = m - 1;
2284
ScilabXgc->CmapFlag = 0;
2285
ScilabXgc->NumForeground = m;
2286
ScilabXgc->NumBackground = m + 1;
2287
C2F(usecolor)((i=1,&i) ,PI0,PI0,PI0);
2288
/** we must change the current pattern before the alufunction **/
2289
C2F(setpattern)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
2290
C2F(setalufunction1)(&ScilabXgc->CurDrawFunction,PI0,PI0,PI0);
2291
C2F(setpattern)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
2292
C2F(setforeground)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
2293
C2F(setbackground)((i=ScilabXgc->NumForeground+2,&i),PI0,PI0,PI0);
2294
FREE(c); FREE(r); FREE(g); FREE(b);
2298
static BOOL SciPalette(int iNumClr)
2300
static HPALETTE hPal=NULL;
2301
LOGPALETTE *plogPal;
2304
uiSizPal = sizeof(WORD)*2 + sizeof(PALETTEENTRY)*iNumClr;
2305
if ((plogPal = (LOGPALETTE *) LocalAlloc(LMEM_FIXED,uiSizPal)) == NULL) {
2306
sciprint("Fail in Allocating palette!\r\n");
2310
plogPal->palVersion = 0x300;
2311
plogPal->palNumEntries = (WORD) iNumClr;
2313
for (i=0; i<iNumClr; i++)
2315
plogPal->palPalEntry[i].peRed =(unsigned char) (255.0* ScilabXgc->Red[i]);
2316
plogPal->palPalEntry[i].peGreen =(unsigned char) (255.0* ScilabXgc->Green[i]);
2317
plogPal->palPalEntry[i].peBlue =(unsigned char) (255.0* ScilabXgc->Blue[i]);
2318
plogPal->palPalEntry[i].peFlags = PC_RESERVED;
2319
ScilabXgc->Colors[i]=PALETTERGB(plogPal->palPalEntry[i].peRed,
2320
plogPal->palPalEntry[i].peGreen,
2321
plogPal->palPalEntry[i].peBlue);
2324
if ( hPal != (HPALETTE) NULL) DeleteObject(hPal);
2325
hPal = CreatePalette((LPLOGPALETTE)plogPal);
2326
if ((hPal) == NULL) {
2327
sciprint("Fail in creating palette!\r\n");
2330
SelectPalette(hdc, hPal, FALSE);
2331
RealizePalette(hdc);
2332
/** UpdateColors(hdc) **/
2333
GlobalFree(plogPal);
2338
/* getting the colormap */
2340
void C2F(getcolormap)(verbose,num,narg,val)
2346
int m = ScilabXgc->Numcolors;
2350
for (i = 0; i < m; i++) {
2351
val[i] = (double)ScilabXgc->Red[i];
2352
val[i+m] = (double)ScilabXgc->Green[i];
2353
val[i+2*m] = (double)ScilabXgc->Blue[i];
2355
if (*verbose == 1) {
2356
sciprint("Size of colormap: %d colors\r\n",m);
2361
/** set and get the number of the background or foreground */
2363
void C2F(setbackground)(num, v2, v3, v4)
2369
if (ScilabXgc->CurColorStatus == 1)
2372
ScilabXgc->NumBackground = Max(0,Min(*num - 1,ScilabXgc->Numcolors + 1));
2373
C2F(setalufunction1)(&ScilabXgc->CurDrawFunction,PI0,PI0,PI0);
2374
px = (ScilabXgc->Colors == NULL) ? DefaultBackground
2375
: ScilabXgc->Colors[ScilabXgc->NumBackground];
2377
if (ScilabXgc->Cdrawable != (Drawable) ScilabXgc->CWindow )
2379
XSetWindowBackground(dpy, ScilabXgc->CWindow,px);
2384
void C2F(getbackground)(verbose, num, narg,dummy)
2391
if ( ScilabXgc->CurColorStatus == 1 )
2393
*num = ScilabXgc->NumBackground + 1;
2400
sciprint("\n Background : %d\r\n",*num);
2404
/** set and get the number of the background or foreground */
2406
void C2F(setforeground)(num, v2, v3, v4)
2412
if (ScilabXgc->CurColorStatus == 1)
2415
ScilabXgc->NumForeground = Max(0,Min(*num - 1,ScilabXgc->Numcolors + 1));
2416
C2F(setalufunction1)(&ScilabXgc->CurDrawFunction,PI0,PI0,PI0);
2417
px = (ScilabXgc->Colors == NULL) ? DefaultForeground
2418
: ScilabXgc->Colors[ScilabXgc->NumForeground];
2424
void C2F(getforeground)(verbose, num, narg,dummy)
2431
if ( ScilabXgc->CurColorStatus == 1 )
2433
*num = ScilabXgc->NumForeground + 1;
2437
*num = 1; /** the foreground is a solid line style in b&w */
2440
sciprint("\n Foreground : %d\r\n",*num);
2443
/** set and get the number of the hidden3d color */
2445
void C2F(sethidden3d)(num, v2, v3, v4)
2451
if (ScilabXgc->CurColorStatus == 1)
2453
ScilabXgc->NumHidden3d = Max(0,Min(*num - 1,ScilabXgc->Numcolors + 1));
2457
void C2F(gethidden3d)(verbose, num, narg,dummy)
2464
if ( ScilabXgc->CurColorStatus == 1 )
2466
*num = ScilabXgc->NumHidden3d + 1;
2470
*num = 1; /** the hidden3d is a solid line style in b&w */
2473
sciprint("\n Hidden3d : %d\r\n",*num);
2477
/*****************************************************
2478
* return 1 : if the current window exists
2479
* and its colormap is not the default
2480
* colormap (the number of colors is returned in m
2482
*****************************************************/
2485
int CheckColormap(m)
2488
if ( ScilabXgc != (struct BCG *) 0 )
2490
*m = ScilabXgc->Numcolors;
2491
if ( ScilabXgc->CmapFlag != 1)
2505
*r = ScilabXgc->Red[i];
2512
*g = ScilabXgc->Green[i];
2518
*b = ScilabXgc->Blue[i];
2522
/*-----------------------------------------------------------
2523
\encadre{general routines accessing the set<> or get<>
2525
-------------------------------------------------------------*/
2527
static void InitMissileXgc();
2530
void C2F(sempty)(verbose, v2, v3, v4)
2536
if ( *verbose ==1 ) Scistring("\n No operation ");
2539
void C2F(gempty)(verbose, v2, v3,dummy)
2545
if ( *verbose ==1 ) Scistring("\n No operation ");
2548
#define NUMSETFONC 28
2550
/** Table in lexicographic order **/
2552
static struct bgc { char *name ;
2553
void (*setfonc )() ;
2554
void (*getfonc )() ;}
2557
{"alufunction",C2F(setalufunction1),C2F(getalufunction)},
2558
{"background",C2F(setbackground),C2F(getbackground)},
2559
{"clipoff",C2F(unsetclip),C2F(getclip)},
2560
{"clipping",C2F(setclip),C2F(getclip)},
2561
{"color",C2F(setpattern),C2F(getpattern)},
2562
{"colormap",C2F(setcolormap),C2F(getcolormap)},
2563
{"dashes",C2F(set_dash_or_color),C2F(get_dash_or_color)}, /* obsolet */
2564
{"default",InitMissileXgc, C2F(gempty)},
2565
{"font",C2F(xsetfont),C2F(xgetfont)},
2566
{"foreground",C2F(setforeground),C2F(getforeground)},
2567
{"hidden3d",C2F(sethidden3d),C2F(gethidden3d)},
2568
{"lastpattern",C2F(sempty),C2F(getlast)},
2569
{"line mode",C2F(setabsourel),C2F(getabsourel)},
2570
{"line style",C2F(setdash),C2F(getdash)},
2571
{"mark",C2F(xsetmark),C2F(xgetmark)},
2572
{"pattern",C2F(setpattern),C2F(getpattern)},
2573
{"pixmap",C2F(setpixmapOn),C2F(getpixmapOn)},
2574
{"thickness",C2F(setthickness),C2F(getthickness)},
2575
{"use color",C2F(usecolor),C2F(getusecolor)},
2576
{"viewport", C2F(setviewport), C2F(getviewport)},
2577
{"wdim",C2F(setwindowdim),C2F(getwindowdim)},
2578
{"white",C2F(sempty),C2F(getlast)},
2579
{"window",C2F(setcurwin),C2F(getcurwin)},
2580
{"wpdim",C2F(setpopupdim),C2F(getpopupdim)},
2581
{"wpos",C2F(setwindowpos),C2F(getwindowpos)},
2582
{"wresize",C2F(setwresize),C2F(getwresize)},
2583
{"wshow",C2F(show),C2F(gempty)},
2584
{"wwpc",C2F(pixmapclear),C2F(gempty)}
2589
/* pour forcer lint a verifier ca */
2592
test(str,flag,verbose,x1,x2,x3,x4,x5)
2595
integer *verbose,*x1,*x2,*x3,*x4,*x5;
2598
C2F(setalufunction1)(x1,x2,x3,x4);C2F(getalufunction)(verbose,x1,x2,dv);
2599
C2F(setclip)(x1,x2,x3,x4);C2F(getclip)(verbose,x1,x2,dv);
2600
C2F(unsetclip)(x1,x2,x3,x4);C2F(getclip)(verbose,x1,x2,dv);
2601
C2F(setdash)(x1,x2,x3,x4);C2F(getdash)(verbose,x1,x2,dv);
2602
InitMissileXgc(x1,x2,x3,x4); C2F(gempty)(verbose,x1,x2,dv);
2603
C2F(xsetfont)(x1,x2,x3,x4);C2F(xgetfont)(verbose,x1,x2,dv);
2604
C2F(setabsourel)(x1,x2,x3,x4);C2F(getabsourel)(verbose,x1,x2,dv);
2605
C2F(xsetmark)(x1,x2,x3,x4);C2F(xgetmark)(verbose,x1,x2,dv);
2606
C2F(setpattern)(x1,x2,x3,x4);C2F(getpattern)(verbose,x1,x2,dv);
2607
C2F(setpixmapOn)(x1,x2,x3,x4);C2F(getpixmapOn)(verbose,x1,x2,dv);
2608
C2F(setthickness)(x1,x2,x3,x4);C2F(getthickness)(verbose,x1,x2,dv);
2609
C2F(usecolor)(x1,x2,x3,x4);C2F(gempty)(verbose,x1,x2,dv);
2610
C2F(setwindowdim)(x1,x2,x3,x4);C2F(getwindowdim)(verbose,x1,x2,dv);
2611
C2F(sempty)(x1,x2,x3,x4);C2F(getwhite)(verbose,x1,x2,dv);
2612
C2F(setcurwin)(x1,x2,x3,x4);C2F(getcurwin)(verbose,x1,x2,dv);
2613
C2F(setwindowpos)(x1,x2,x3,x4);C2F(getwindowpos)(verbose,x1,x2,dv);
2614
C2F(show)(x1,x2,x3,x4);C2F(gempty)(verbose,x1,x2,dv);
2615
C2F(pixmapclear)(x1,x2,x3,x4);gempty(verbose,x1,x2,dv);
2620
void C2F(MissileGCget)(str, verbose, x1, x2, x3, x4, x5,dv1, dv2, dv3, dv4)
2623
integer *x1; integer *x2; integer *x3; integer *x4;
2624
integer *x5; double *dv1; double *dv2; double *dv3; double *dv4;
2627
C2F(MissileGCGetorSet)(str,1L,verbose,x1,x2,x3,x4,x5,&x6,dv1);
2630
void C2F(MissileGCset)(str, x1, x2, x3, x4, x5, x6, dv1, dv2, dv3, dv4)
2644
C2F(MissileGCGetorSet)(str,0L,&verbose,x1,x2,x3,x4,x5,x6,dv1);
2647
void C2F(MissileGCGetorSet)(str, flag, verbose, x1, x2, x3, x4, x5,x6,dv1)
2659
for (i=0; i < NUMSETFONC ; i++)
2662
j = strcmp(str,MissileGCTab_[i].name);
2664
{ if (*verbose == 1)
2665
sciprint("\nGettting Info on %s\r\n",str);
2667
(MissileGCTab_[i].getfonc)(verbose,x1,x2,dv1);
2669
(MissileGCTab_[i].setfonc)(x1,x2,x3,x4,x5,x6,dv1);
2674
sciprint("\nUnknow X operator <%s>\r\n",str);
2679
sciprint("\n Unknow X operator <%s>\r\n",str);
2683
/*-------------------------------------------------------
2684
\section{Functions for drawing}
2685
---------------------------------------------------------*/
2687
/*----------------------------------------------------
2688
\subsection{String display}
2690
\encadre{display of a string
2691
at (x,y) position whith slope angle alpha in degree .
2692
Angle are given clockwise.
2693
If *flag ==1 and angle is z\'ero a framed box is added
2695
-----------------------------------------------------*/
2697
void C2F(displaystring)(string, x, y, v1, flag, v6, v7, angle, dv2, dv3, dv4)
2699
integer *x,*y,*v1,*flag,*v6,*v7;
2700
double *angle,*dv2,*dv3,*dv4;
2702
if ( Abs(*angle) <= 0.1)
2704
if ( ScilabXgc->CurDrawFunction == GXxor )
2707
GetTextExtentPoint32(hdc,string,strlen(string),&size);
2708
XorString(*x,*y,string,size.cx,size.cy);
2712
TextOut(hdc,(int) *x,(int) *y,string,strlen(string));
2717
C2F(boundingbox)(string,x,y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
2718
C2F(drawrectangle)(string,rect,rect+1,rect+2,rect+3,PI0,PI0,PD0,PD0,PD0,PD0);
2723
C2F(DispStringAngle)(x,y,string,angle);
2727
void C2F(DispStringAngle)(x0, yy0, string, angle)
2734
integer x,y, rect[4];
2735
double sina ,cosa,l;
2740
sina= sin(*angle * M_PI/180.0);
2741
cosa= cos(*angle * M_PI/180.0);
2742
for ( i = 0 ; i < (int)strlen(string); i++)
2745
if ( ScilabXgc->CurDrawFunction == GXxor )
2748
GetTextExtentPoint32(hdc,str1,1,&size);
2749
XorString(x,y,str1,size.cx,size.cy);
2753
TextOut(hdc,(int) x,(int) y,str1,1);
2755
C2F(boundingbox)(str1,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
2756
/** C2F(drawrectangle)(string,rect,rect+1,rect+2,rect+3); **/
2757
if ( cosa <= 0.0 && i < (int)strlen(string)-1)
2759
/** si le cosinus est negatif le deplacement est a calculer **/
2760
/** sur la boite du caractere suivant **/
2761
str2[1]='\0';str2[0]=string[i+1];
2762
C2F(boundingbox)(str2,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
2764
if ( Abs(cosa) >= 1.e-8 )
2766
if ( Abs(sina/cosa) <= Abs(((double)rect[3])/((double)rect[2])))
2767
l = Abs(rect[2]/cosa);
2769
l = Abs(rect[3]/sina);
2772
l = Abs(rect[3]/sina);
2773
x += inint(cosa*l*1.1);
2774
y += inint(sina*l*1.1);
2778
int XorString(x,y,string,fWidth,fHeight)
2785
HBRUSH hbrushOld; **/
2786
HFONT hfont,hfontOld;
2788
HBITMAP hbitmap, hbitmapOld;
2790
hdcMem = CreateCompatibleDC (hdc);
2792
hbitmap = CreateCompatibleBitmap (hdc,fWidth,fHeight);
2794
SetMapMode(hdcMem, MM_TEXT);
2795
SetBkMode(hdcMem,TRANSPARENT);
2796
SetTextAlign(hdcMem, TA_LEFT|TA_BOTTOM);
2797
hbitmapOld = SelectObject (hdcMem, hbitmap);
2798
BitBlt (hdcMem, 0, 0,fWidth,fHeight, NULL, 0, 0, WHITENESS);
2800
hpenOld=SelectObject(hdcMem,ScilabXgc->hPen);
2801
hbrushOld=SelectObject(hdcMem,ScilabXgc->hBrush);
2803
hfontOld=SelectObject(hdcMem,hfont);
2804
if (ScilabXgc->Colors != NULL)
2807
col = ScilabXgc->Colors[ScilabXgc->CurColor];
2808
if ( ScilabXgc->CurDrawFunction != GXxor )
2809
col = col ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
2810
SetTextColor(hdcMem,col);
2812
if (TextOut (hdcMem,0,fHeight,string,strlen(string)))
2814
/** see raster ops in VC++ **/
2815
BitBlt(hdc, x,y-fHeight,fWidth,fHeight,hdcMem,0,0,0x990066);
2817
MessageBox (GetFocus(),
2818
"Unable to perform TextOut", "DisplayGlyph", MB_OK);
2820
SelectObject (hdcMem, hbitmapOld);
2821
/** SelectObject (hdcMem, hpenOld);
2822
SelectObject (hdcMem, hbrushOld); **/
2823
SelectObject (hdcMem, hfontOld);
2824
DeleteObject (hbitmap);
2826
MessageBox (GetFocus(), "Unable To create Bitmap", "DisplayGlyph", MB_OK);
2830
MessageBox (GetFocus(), "Unable to create DC", "DisplayGlyph", MB_OK);
2836
/** To get the bounding rectangle of a string **/
2838
void C2F(boundingbox)(string, x, y, rect, v5, v6, v7, dv1, dv2, dv3, dv4)
2840
integer *x,*y,*rect,*v5,*v6,*v7;
2841
double *dv1,*dv2,*dv3,*dv4;
2844
/** text mode is supposed to be bottom **/
2845
GetTextExtentPoint32(hdc,string,strlen(string),&size);
2847
rect[1]= *y - size.cy ;
2852
/*------------------------------------------------
2853
subsection{ Segments and Arrows }
2854
-------------------------------------------------*/
2856
void C2F(drawline)(x1, yy1, x2, y2)
2863
MoveToEx(hdc,(int) *x1,(int) *yy1,NULL);
2864
LineTo(hdc,(int) *x2,(int) *y2);
2868
/** Draw a set of segments **/
2869
/** segments are defined by (vx[i],vy[i])->(vx[i+1],vy[i+1]) **/
2870
/** for i=0 step 2 **/
2871
/** n is the size of vx and vy **/
2873
void C2F(drawsegments)(str, vx, vy, n, style, iflag, v7, dv1, dv2, dv3, dv4)
2886
integer verbose=0,Dnarg,Dvalue[10],NDvalue;
2889
C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
2892
if ( (int) *iflag == 1) { /* one style per segment */
2893
for (i=0 ; i < *n/2 ; i++) {
2895
C2F(set_line_style)(&NDvalue,PI0,PI0,PI0);
2896
MoveToEx(hdc,(int) vx[2*i],(int) vy[2*i],NULL);
2897
LineTo(hdc,(int) vx[2*i+1],(int) vy[2*i+1]);
2901
if (*style >= 1) /* set color */
2902
C2F(set_line_style)(style,PI0,PI0,PI0);
2904
for (i=0 ; i < *n/2 ; i++) {
2905
MoveToEx(hdc,(int) vx[2*i],(int) vy[2*i],NULL);
2906
LineTo(hdc,(int) vx[2*i+1],(int) vy[2*i+1]);
2909
C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
2912
/** Draw a set of arrows **/
2913
/** arrows are defined by (vx[i],vy[i])->(vx[i+1],vy[i+1]) **/
2914
/** for i=0 step 2 **/
2915
/** n is the size of vx and vy **/
2916
/** as is 10*arsize (arsize) the size of the arrow head in pixels **/
2918
void C2F(drawarrows)(str, vx, vy, n, as, style, iflag, dv1, dv2, dv3, dv4)
2931
integer verbose=0,Dnarg,Dvalue[10],NDvalue,i;
2932
double cos20=cos(20.0*M_PI/180.0);
2933
double sin20=sin(20.0*M_PI/180.0);
2934
integer polyx[4],polyy[4];
2935
C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
2936
for (i=0 ; i < *n/2 ; i++)
2939
if ( (int) *iflag == 1)
2942
NDvalue=(*style < 1) ? Dvalue[0] : *style;
2943
C2F(set_line_style)(&NDvalue,PI0,PI0,PI0);
2945
MoveToEx(hdc,(int) vx[2*i],(int) vy[2*i],NULL);
2946
LineTo(hdc,(int) vx[2*i+1],(int) vy[2*i+1]);
2948
dx=( vx[2*i+1]-vx[2*i]);
2949
dy=( vy[2*i+1]-vy[2*i]);
2950
norm = sqrt(dx*dx+dy*dy);
2951
if ( Abs(norm) > SMDOUBLE )
2953
dx=(*as/10.0)*dx/norm;dy=(*as/10.0)*dy/norm;
2954
polyx[0]= polyx[3]=inint(vx[2*i+1]+dx*cos20);
2955
polyx[1]= inint(polyx[0] - cos20*dx -sin20*dy );
2956
polyx[2]= inint(polyx[0] - cos20*dx + sin20*dy);
2957
polyy[0]= polyy[3]=inint(vy[2*i+1]+dy*cos20);
2958
polyy[1]= inint(polyy[0] + sin20*dx -cos20*dy) ;
2959
polyy[2]= inint(polyy[0] - sin20*dx - cos20*dy) ;
2960
C2F(fillpolylines)("v",polyx,polyy,&NDvalue, &nn,&p,PI0,PD0,PD0,PD0,PD0);
2963
C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
2966
/** Draw or fill a set of rectangle **/
2967
/** rectangle i is specified by (vect[i],vect[i+1],vect[i+2],vect[i+3]) **/
2968
/** for x,y,width,height **/
2969
/** for i=0 step 4 **/
2970
/** (*n) : number of rectangles **/
2971
/** fillvect[*n] : specify the action **/
2972
/** if fillvect[i] is > 0 then fill the rectangle i **/
2973
/** if fillvect[i] is == 0 then only draw the rectangle i **/
2974
/** with the current drawing style **/
2975
/** if fillvect[i] is < 0 then draw the rectangle with -fillvect[i] **/
2977
void C2F(drawrectangles)(str, vects, fillvect, n, v5, v6, v7, dv1, dv2, dv3, dv4)
2990
integer i,cpat,verbose=0,num,cd[10];
2991
C2F(getpattern)(&verbose,&cpat,&num,vdouble);
2993
C2F(get_dash_and_color)(&verbose,cd,&num,vdouble);
2994
for (i=0 ; i< *n ; i++)
2996
if (fillvect[i] < 0)
2998
int dash = - fillvect[i];
2999
C2F(set_line_style)(&dash,PI0,PI0,PI0);
3000
C2F(drawrectangle)(str,vects+4*i,vects+4*i+1,vects+4*i+2,vects+4*i+3
3001
,PI0,PI0,PD0,PD0,PD0,PD0);
3003
else if (fillvect[i] == 0)
3005
/* C2F(set_line_style)(&cd,PI0,PI0,PI0);*/
3006
C2F(drawrectangle)(str,vects+4*i,vects+4*i+1,vects+4*i+2,vects+4*i+3
3007
,PI0,PI0,PD0,PD0,PD0,PD0);
3011
C2F(setpattern)(&(fillvect[i]),PI0,PI0,PI0);
3012
C2F(fillrectangle)(str,vects+4*i,vects+4*i+1,vects+4*i+2,vects+4*i+3,PI0,PI0,PD0,PD0,PD0,PD0);
3015
C2F(set_dash_and_color)(&(cd),PI0,PI0,PI0);
3018
/** Draw one rectangle with current line style **/
3020
void C2F(drawrectangle)(str, x, y, width, height, v6, v7, dv1, dv2, dv3, dv4)
3033
SelectObject(hdc,GetStockObject(NULL_BRUSH));
3034
/* +1 added for correct 2d axis necessary !! **/
3035
Rectangle(hdc,(int) *x,(int) *y,(int) *width+*x+1 ,(int) *height+*y+1);
3036
if ( ScilabXgc->hBrush != (HBRUSH) 0)
3037
SelectObject(hdc,ScilabXgc->hBrush);
3040
/** fill one rectangle, with current pattern **/
3042
void C2F(fillrectangle)(str, x, y, width, height, v6, v7, dv1, dv2, dv3, dv4)
3055
/** Rectangle with current pen and brush **/
3056
Rectangle(hdc,(int) *x,(int) *y,(int) *width + *x+1 ,(int) *height + *y+1 );
3059
/*----------------------------------------------------------------------------------
3060
* draw a set of rectangles, provided here to accelerate GraySquare for X11 device
3061
* x : of size n1 gives the x-values of the grid
3062
* y : of size n2 gives the y-values of the grid
3063
* z : is the value of a function on the grid defined by x,y
3064
* on each rectangle the average value of z is computed
3065
*----------------------------------------------------------------------------------*/
3067
void fill_grid_rectangles(x, y, z, n1, n2)
3072
double zmoy,zmax,zmin,zmaxmin;
3073
integer i,j,verbose=0,whiteid,narg,fill[1],cpat,xz[2];
3074
zmin=Mini(z,(n1)*(n2));
3075
zmax=Maxi(z,(n1)*(n2));
3077
if (zmaxmin <= SMDOUBLE) zmaxmin=SMDOUBLE;
3079
C2F(getlast)(&verbose,&whiteid,&narg,vdouble);
3080
C2F(getpattern)(&verbose,&cpat,&narg,vdouble);
3081
C2F(getwindowdim)(&verbose,xz,&narg,vdouble);
3083
for (i = 0 ; i < (n1)-1 ; i++)
3084
for (j = 0 ; j < (n2)-1 ; j++)
3087
zmoy=1/4.0*(z[i+n1*j]+z[i+n1*(j+1)]+z[i+1+n1*j]+z[i+1+n1*(j+1)]);
3088
fill[0]=1 + inint((whiteid-1)*(zmoy-zmin)/(zmaxmin));
3089
C2F(setpattern)(fill,PI0,PI0,PI0);
3090
w=Abs(x[i+1]-x[i]);h=Abs(y[j+1]-y[j]);
3091
/* We don't trace rectangle which are totally out **/
3092
if ( w != 0 && h != 0 && x[i] < xz[0] && y[j+1] < xz[1] && x[i]+w > 0 && y[j+1]+h > 0 )
3093
Rectangle(hdc,(int) x[i],(int) y[j+1],(int) w + x[i]+1 ,(int) h + y[j+1]+1 );
3095
C2F(setpattern)(&cpat,PI0,PI0,PI0);
3098
/*----------------------------------------------------------------------------------
3099
* draw a set of rectangles, provided here to accelerate GraySquare1 for X11 device
3100
* x : of size n1 gives the x-values of the grid
3101
* y : of size n2 gives the y-values of the grid
3102
* z : of size (n1-1)*(n2-1) gives the f-values on the middle
3103
* of each rectangle.
3104
* z[i,j] is the value on the middle of rectangle
3105
* P1= x[i],y[j] x[i+1],y[j+1]
3106
*----------------------------------------------------------------------------------*/
3108
void fill_grid_rectangles1(x, y, z, n1, n2)
3115
integer i,j,verbose=0,narg,fill[1],cpat,xz[2];
3116
C2F(getpattern)(&verbose,&cpat,&narg,vdouble);
3117
C2F(getwindowdim)(&verbose,xz,&narg,vdouble);
3118
for (i = 0 ; i < (n1)-1 ; i++)
3119
for (j = 0 ; j < (n2)-1 ; j++)
3122
fill[0]= z[i+(n1-1)*j];
3123
C2F(setpattern)(fill,PI0,PI0,PI0);
3126
/* We don't trace rectangle which are totally out **/
3127
if ( w != 0 && h != 0 && x[j] < xz[0] && y[i] < xz[1] && x[j]+w > 0 && y[i]+h > 0 )
3128
Rectangle(hdc,(int) x[j],(int) y[i],(int) w + x[j]+1 ,(int) h + y[i]+1 );
3130
C2F(setpattern)(&cpat,PI0,PI0,PI0);
3133
/*----------------------
3134
\subsection{Circles and Ellipsis }
3135
------------------------*/
3136
/** Draw or fill a set of ellipsis or part of ellipsis **/
3137
/** Each is defined by 6-parameters, **/
3138
/** ellipsis i is specified by $vect[6*i+k]_{k=0,5}= x,y,width,height,angle1,angle2$ **/
3139
/** <x,y,width,height> is the bounding box **/
3140
/** angle1,angle2 specifies the portion of the ellipsis **/
3141
/** caution : angle=degreangle*64 **/
3142
/** if fillvect[i] is in [0,whitepattern] then fill the ellipsis i **/
3143
/** with pattern fillvect[i] **/
3144
/** if fillvect[i] is > whitepattern then only draw the ellipsis i **/
3145
/** The drawing style is the current drawing **/
3147
void C2F(fillarcs)(str, vects, fillvect, n, v5, v6, v7, dv1, dv2, dv3, dv4)
3160
integer i,cpat,verb,num;
3162
C2F(getpattern)(&verb,&cpat,&num,vdouble);
3163
for (i=0 ; i< *n ; i++)
3165
if (fillvect[i] > ScilabXgc->IDLastPattern + 1)
3167
C2F(setpattern)(&(cpat),PI0,PI0,PI0);
3168
C2F(drawarc)(str,vects+6*i,vects+6*i+1,
3169
vects+6*i+2,vects+6*i+3,
3170
vects+6*i+4,vects+6*i+5,PD0,PD0,PD0,PD0);
3174
C2F(setpattern)(&(fillvect[i]),PI0,PI0,PI0);
3175
C2F(fillarc)(str,vects+6*i,vects+6*i+1,
3176
vects+6*i+2,vects+6*i+3,
3177
vects+6*i+4,vects+6*i+5,PD0,PD0,PD0,PD0);
3180
C2F(setpattern)(&(cpat),PI0,PI0,PI0);
3184
/** Draw a set of ellipsis or part of ellipsis **/
3185
/** Each is defined by 6-parameters, **/
3186
/** ellipsis i is specified by $vect[6*i+k]_{k=0,5}= x,y,width,height,angle1,angle2$ **/
3187
/** <x,y,width,height> is the bounding box **/
3188
/** angle1,angle2 specifies the portion of the ellipsis **/
3189
/** caution : angle=degreangle*64 **/
3191
void C2F(drawarcs)(str, vects, style, n, v5, v6, v7, dv1, dv2, dv3, dv4)
3204
integer verbose=0,Dnarg,Dvalue[10],NDvalue,i;
3205
/* store the current values */
3206
C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
3207
for (i=0 ; i< *n ; i++)
3210
C2F(set_line_style)(&NDvalue,PI0,PI0,PI0);
3211
C2F(drawarc)(str,vects+6*i,vects+6*i+1,
3212
vects+6*i+2,vects+6*i+3,
3213
vects+6*i+4,vects+6*i+5,PD0,PD0,PD0,PD0);
3215
C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
3218
/** Draw a single ellipsis or part of it **/
3220
void C2F(drawarc)(str, x, y, width, height, angle1, angle2, dv1, dv2, dv3, dv4)
3222
integer *x, *y, *width,*height, *angle1, *angle2;
3223
double *dv1,*dv2,*dv3,*dv4;
3225
int xmid= *x + *width/2;
3226
int ymid= *y + *height/2;
3227
int lg= Max(*width,*height);
3228
SelectObject(hdc,GetStockObject(NULL_BRUSH));
3229
/** Ellipse(hdc,(int) *x,(int) *y,(int) *width + *x ,(int) *height + *y ); **/
3230
Arc(hdc,(int) *x,(int) *y,(int) *width + *x ,(int) *height + *y,
3231
xmid + (int) (lg*cos(*angle1*M_PI/11520.00)),
3232
ymid - (int) (lg*sin(*angle1*M_PI/11520.00)),
3233
xmid + (int) (lg*cos((*angle1+*angle2)*M_PI/11520.00)),
3234
ymid - (int)(lg*sin((*angle1+*angle2)*M_PI/11520.00))); /** 180*64 **/
3235
if ( ScilabXgc->hBrush != (HBRUSH) 0) SelectObject(hdc,ScilabXgc->hBrush);
3238
/** Fill a single elipsis or part of it with current pattern **/
3240
void C2F(fillarc)(str, x, y, width, height, angle1, angle2, dv1, dv2, dv3, dv4)
3242
integer *x, *y, *width,*height, *angle1, *angle2;
3243
double *dv1,*dv2,*dv3,*dv4;
3245
int xmid= *x + *width/2;
3246
int ymid= *y + *height/2;
3247
int lg= Max(*width,*height);
3248
/**Ellipse(hdc,(int) *x,(int) *y,(int)*width+*x ,(int)*height+*y ); **/
3249
Pie(hdc,(int) *x,(int) *y,(int) *width + *x ,(int) *height + *y,
3250
xmid +(int) (lg*cos(*angle1*M_PI/11520.00)),
3251
ymid - (int) (lg*sin(*angle1*M_PI/11520.00)),
3252
xmid+(int) (lg*cos((*angle1+*angle2)*M_PI/11520.00)),
3253
ymid - (int) (lg*sin((*angle1+*angle2)*M_PI/11520.00))); /** 180*64 **/
3256
/*--------------------------------------------------------------
3257
\encadre{Filling or Drawing Polylines and Polygons}
3258
---------------------------------------------------------------*/
3260
/** Draw a set of (*n) polylines (each of which have (*p) points) **/
3261
/** with lines or marks **/
3262
/** drawvect[i] >= 0 use a mark for polyline i **/
3263
/** drawvect[i] < 0 use a line style for i **/
3265
void C2F(drawpolylines)(str, vectsx, vectsy, drawvect, n, p, v7, dv1, dv2, dv3, dv4)
3277
{ integer verbose=0 ,symb[2],Mnarg,Dnarg,Dvalue[10],NDvalue,i,close;
3278
/* store the current values */
3279
C2F(xgetmark)(&verbose,symb,&Mnarg,vdouble);
3280
C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
3281
for (i=0 ; i< *n ; i++)
3283
if (drawvect[i] <= 0)
3284
{ /** we use the markid : drawvect[i] **/
3285
NDvalue = - drawvect[i] ;
3286
C2F(xsetmark)(&NDvalue,symb+1,PI0,PI0);
3287
C2F(setpattern)(Dvalue+6,PI0,PI0,PI0);
3288
C2F(drawpolymark)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
3291
{/** we use the line-style number abs(drawvect[i]) **/
3292
C2F(set_line_style)(drawvect+i,PI0,PI0,PI0);
3294
C2F(drawpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,&close,
3295
PI0,PI0,PD0,PD0,PD0,PD0);
3298
/** back to default values **/
3299
C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
3300
C2F(xsetmark)(symb,symb+1,PI0,PI0);
3303
/** fill a set of polygons each of which is defined by
3304
(*p) points (*n) is the number of polygons
3305
the polygon is closed by the routine
3308
if fillvect[i] == 0 draw the boundaries with current color
3309
if fillvect[i] > 0 draw the boundaries with current color
3310
then fill with pattern fillvect[i]
3311
if fillvect[i] < 0 fill with pattern - fillvect[i]
3314
void C2F(fillpolylines)(str, vectsx, vectsy, fillvect, n, p, v7, dv1, dv2, dv3, dv4)
3327
integer Dnarg,Dvalue[10];
3328
integer i,cpat,verbose=0,num,close=1,pattern;
3329
C2F(getpattern)(&verbose,&cpat,&num,vdouble);
3330
C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
3331
for (i=0 ; i< *n ; i++)
3333
if (fillvect[i] > 0)
3335
/** on peint puis on fait un contour ferme **/
3336
C2F(setpattern)(&fillvect[i],PI0,PI0,PI0);
3337
C2F(fillpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=1,&close),
3338
PI0,PI0,PD0,PD0,PD0,PD0);
3339
C2F(set_line_style)(Dvalue,PI0,PI0,PI0);
3340
C2F(setpattern)(&(cpat),PI0,PI0,PI0);
3341
C2F(drawpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=1,&close)
3342
,PI0,PI0,PD0,PD0,PD0,PD0);
3344
else if (fillvect[i] == 0 )
3346
C2F(set_line_style)(Dvalue,PI0,PI0,PI0);
3347
C2F(setpattern)(&cpat,PI0,PI0,PI0);
3348
C2F(drawpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=0,&close)
3349
,PI0,PI0,PD0,PD0,PD0,PD0);
3353
pattern = -fillvect[i] ;
3354
C2F(setpattern)(&pattern,PI0,PI0,PI0);
3355
C2F(fillpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,(close=0,&close)
3356
,PI0,PI0,PD0,PD0,PD0,PD0);
3359
C2F(set_dash_and_color)(Dvalue,PI0,PI0,PI0);
3362
/** Only draw one polygon with current line style **/
3363
/** according to *closeflag : it's a polyline or a polygon **/
3364
/** n is the number of points of the polyline */
3366
void C2F(drawpolyline)(str, n, vx, vy, closeflag, v6, v7, dv1, dv2, dv3, dv4)
3380
if (*closeflag == 1) n1 = *n+1;else n1= *n;
3383
if (C2F(store_points)(*n, vx, vy,*closeflag))
3385
Polyline(hdc,C2F(ReturnPoints)(),(int) n1);
3390
/** Fill the polygon or polyline **/
3391
/** according to *closeflag : the given vector is a polyline or a polygon **/
3393
void C2F(fillpolyline)(str, n, vx, vy, closeflag, v6, v7, dv1, dv2, dv3, dv4)
3407
if (*closeflag == 1) n1 = *n+1;else n1= *n;
3408
if (C2F(store_points)(*n, vx, vy,*closeflag))
3410
Polygon(hdc,C2F(ReturnPoints)(), n1);
3414
/** Draw the current mark centred at points defined **/
3415
/** by vx and vy (vx[i],vy[i]) **/
3417
void C2F(drawpolymark)(str, n, vx, vy, v5, v6, v7, dv1, dv2, dv3, dv4)
3430
if ( ScilabXgc->CurHardSymb == 0 )
3432
if (C2F(store_points)(*n, vx, vy,0L))
3434
XDrawPoints (hdc,C2F(ReturnPoints)(), *n);
3439
integer i,keepid,keepsize,hds;
3440
i=1; /** the symbol font **/
3441
keepid = ScilabXgc->FontId;
3442
keepsize= ScilabXgc->FontSize;
3443
hds= ScilabXgc->CurHardSymbSize;
3444
C2F(xsetfont)(&i,&hds,PI0,PI0);
3445
for ( i=0; i< *n ;i++) DrawMark(hdc,vx+i,vy+i);
3446
C2F(xsetfont)(&keepid,&keepsize,PI0,PI0);
3450
static void XDrawPoints(lhdc, points, Npoints)
3456
for ( i=0; i < Npoints;i++)
3458
/** XXX SetPixel plutot **/
3459
MoveToEx(hdc,points[i].x,points[i].y,NULL);
3460
LineTo(hdc,points[i].x+1,points[i].y);
3464
/*-----------------------------------------
3465
\encadre{List of Window id}
3466
-----------------------------------------*/
3470
* Adds a new entry at the end of the Window List
3471
* and returns a pointer to that entry
3474
struct BCG *AddNewWindowToList()
3476
return( AddNewWindow(&The_List));
3478
struct BCG *AddNewWindow(listptr)
3479
WindowList **listptr;
3481
if ( *listptr == (WindowList *) NULL)
3483
*listptr = (WindowList *) MALLOC (sizeof(WindowList));
3486
Scistring("AddNewWindow No More Place ");
3487
return((struct BCG *) 0);
3491
(*listptr)->winxgc.CWindow = (Window) NULL;
3492
(*listptr)->winxgc.CurWindow = 0;
3493
(*listptr)->winxgc.Red = (float *) 0;
3494
(*listptr)->winxgc.Green = (float *) 0;
3495
(*listptr)->winxgc.Blue = (float *) 0;
3496
(*listptr)->winxgc.Colors = (COLORREF *) 0;
3497
(*listptr)->winxgc.CmapFlag = 1;
3498
(*listptr)->winxgc.lpgw = &graphwin;
3499
(*listptr)->winxgc.hPen = (HPEN) 0;
3500
(*listptr)->winxgc.hBrush = (HBRUSH) 0;
3501
(*listptr)->winxgc.hbmCompat = (HBITMAP) 0;
3502
(*listptr)->winxgc.hdcCompat = (HDC) 0;
3503
(*listptr)->next = (struct WindowList *) NULL ;
3504
return(&((*listptr)->winxgc));
3509
return( AddNewWindow((WindowList **) &((*listptr)->next)));
3513
/** destruction d'une fenetre **/
3515
void DeleteSGWin(intnum)
3519
if ( ScilabXgc == (struct BCG *) 0) return;
3520
curwin = ScilabXgc->CurWindow ;
3521
DeleteWindowToList(intnum);
3522
/*XXXX: jpc 2000: I also delete the scale list associated to that window */
3523
del_window_scale(intnum);
3524
if ( curwin == intnum )
3526
if ( The_List == (WindowList *) NULL)
3528
/** No more graphic window ; **/
3529
ScilabXgc = (struct BCG *) 0;
3533
/** fix the new current graphic window **/
3534
ScilabXgc = &(The_List->winxgc);
3536
get_window_scale(ScilabXgc->CurWindow,NULL);
3541
/** detruit la fenetre num dans la liste des fenetres */
3543
void DeleteWindowToList(num)
3549
while ( L1 != (WindowList *) NULL)
3551
if ( L1->winxgc.CurWindow == num )
3553
/** destroying windows **/
3554
/** XXXX : if there's a pixmap we must free it **/
3556
DestroyWindow(L1->winxgc.hWndParent);
3557
DestroyWindow(L1->winxgc.CWindow);
3558
DestroyWindow(L1->winxgc.Statusbar);
3559
CloseGraphMacros(&(L1->winxgc));
3560
XgcFreeColors(&(L1->winxgc));
3561
if ( L1->winxgc.CurPixmapStatus == 1)
3563
/** Freeing bitmaps **/
3564
if ( L1->winxgc.hdcCompat)
3565
SelectObject (L1->winxgc.hdcCompat, NULL) ;
3566
if ( L1->winxgc.hbmCompat)
3567
DeleteObject (L1->winxgc.hbmCompat);
3568
if ( L1->winxgc.hdcCompat)
3570
DeleteDC(L1->winxgc.hdcCompat);
3573
/** The window was found **/
3576
/** Ce n'est pas la premiere fenetre de la liste **/
3577
L2->next= L1->next ;
3583
/** C'est la premiere fenetre de la liste **/
3584
The_List = (WindowList *) L1->next ;
3592
L1 = (WindowList *) L1->next;
3597
/********************************************
3598
* Get Window number wincount ( or 0 )
3599
********************************************/
3601
Window GetWindowNumber(wincount)
3605
bcg = GetWindowXgcNumber(wincount);
3606
if ( bcg != (struct BCG *) 0)
3607
return( bcg->CWindow);
3609
return( (Window) 0);
3612
/********************************************
3613
* returns the graphic context of window i
3614
* or 0 if this window does not exists
3615
********************************************/
3617
struct BCG *GetWindowXgcNumber(i)
3620
return( GetWinXgc(The_List,Max(0,i)));
3623
struct BCG *GetWinXgc(listptr, i)
3624
WindowList *listptr;
3627
if (listptr == (WindowList *) NULL)
3629
return((struct BCG *) 0);
3633
if ((listptr->winxgc.CurWindow) == i)
3635
return( &(listptr->winxgc));
3639
return(GetWinXgc((WindowList *) listptr->next,i));
3645
/***************************
3646
* get ids of scilab windows
3648
* Num gives the number of windows
3649
* flag == 1 ==> get the Ids
3650
* flag == 0 ==> just get the Number Num
3651
***************************/
3653
void C2F(getwins)(Num,Ids,flag)
3654
integer *Num,Ids[],*flag;
3656
WindowList *listptr = The_List;
3660
while ( listptr != (WindowList *) 0 )
3663
listptr = (WindowList *) listptr->next;
3668
while ( listptr != (WindowList *) 0 )
3670
Ids[*Num] = listptr->winxgc.CurWindow;
3671
listptr = (WindowList *)listptr->next;
3677
/*--------------------------------------------------------------
3678
\encadre{Routine for initialisation : string is a display name }
3679
--------------------------------------------------------------*/
3689
if (ScilabXgc->Colors == NULL)
3691
i= Max(0,Min(coli,ScilabXgc->Numcolors + 1));
3692
ScilabXgc->CurColor = i ;
3693
if ( ScilabXgc->CurDrawFunction != GXxor )
3694
col = ScilabXgc->Colors[i];
3696
col = ScilabXgc->Colors[i] ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
3697
hBrush=CreateSolidBrush(col);
3698
SelectObject(hdc,hBrush);
3699
id = ScilabXgc->CurDashStyle;
3700
if (DashTab[id] == PS_SOLID)
3701
hpen = CreatePen(PS_SOLID,ScilabXgc->CurLineWidth,col);
3703
width = ( DashTab[id] != PS_SOLID) ? 0 : ScilabXgc->CurLineWidth ;
3704
hpen = CreatePen(DashTab[id],width,col);
3706
SelectObject(hdc,hpen);
3707
SetTextColor(hdc,col);
3708
if ( ScilabXgc->hPen != (HPEN) 0 ) DeleteObject(ScilabXgc->hPen);
3709
ScilabXgc->hPen = hpen;
3710
if ( ScilabXgc->hBrush != (HBRUSH) 0 ) DeleteObject(ScilabXgc->hBrush);
3711
ScilabXgc->hBrush = hBrush;
3715
/** Initialyze the dpy connection and creates graphic windows **/
3716
/** If v2 is not a nul pointer *v2 is the window number to create **/
3717
/** EntryCounter is used to check for first Entry + to now an available number **/
3719
void C2F(initgraphic)(string, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
3732
static char popupname[sizeof("ScilabGraphic")+4];
3733
static char winname[sizeof("BG")+4];
3734
struct BCG *NewXgc ;
3736
static integer EntryCounter = 0;
3738
static HMENU sysmenu;
3744
if ( v2 != (integer *) NULL && *v2 != -1 )
3747
WinNum= EntryCounter;
3748
if (EntryCounter == 0)
3750
/** XXXXXX : pour l'instant couleur par defaut */
3752
if (C2F(AllocVectorStorage)()==0) return;
3753
graphwin.xmax = WIN_XMAX;
3754
graphwin.ymax = WIN_YMAX;
3755
if (! graphwin.hPrevInstance) /** XXX : utiliser EntryCounter ??? **/
3759
/** Read or use default values **/
3761
if (( NewXgc = AddNewWindowToList()) == (struct BCG *) 0)
3763
Scistring("initgraphics: unable to alloc\n");
3770
/** ReadGraphIni takes care of graphwin.Origin and graphwin.Size **/
3771
/** ScilabXgc is send to CreateWindow and this information is used
3773
ScilabXgc->lpgw = &graphwin;
3774
if (EntryCounter == 0) { ReadGraphIni(ScilabXgc);};
3775
sprintf(popupname,"ScilabGraphic%d", (int)WinNum);
3776
ScilabXgc->Inside_init=1; /** to know that we are inside init code **/
3777
ScilabXgc->hWndParent = CreateWindow(szParentGraphClass, popupname,
3778
WS_OVERLAPPEDWINDOW,
3779
graphwin.Origin.x, graphwin.Origin.y,
3780
graphwin.Size.x, graphwin.Size.y,
3781
NULL, NULL, graphwin.hInstance,
3783
if (ScilabXgc->hWndParent == (HWND)NULL) {
3784
MessageBox((HWND)NULL,"Couldn't open parent graph window",
3785
(LPSTR)NULL, MB_ICONHAND | MB_SYSTEMMODAL);
3788
ShowWindow(ScilabXgc->hWndParent, SW_SHOWNORMAL);
3789
ScilabXgc->Statusbar = InitStatusBar (ScilabXgc->hWndParent);
3790
ShowWindow(ScilabXgc->Statusbar, SW_SHOWNORMAL);
3791
GetWindowRect (ScilabXgc->Statusbar, &rect1) ;
3792
GetClientRect(ScilabXgc->hWndParent, &rect);
3793
MoveWindow(ScilabXgc->Statusbar, 0, rect.bottom -( rect1.bottom - rect1.top),
3794
rect.right, ( rect1.bottom - rect1.top), TRUE) ;
3795
sprintf((char *)winname,"BG%d", (int)WinNum);
3796
ScilabXgc->CWindowWidth = rect.right;
3797
ScilabXgc->CWindowHeight = rect.bottom - ( rect1.bottom - rect1.top);
3798
ScilabXgc->CWindow = CreateWindow(szGraphClass, winname,
3799
WS_CHILD | WS_VSCROLL | WS_HSCROLL,
3800
0, graphwin.ButtonHeight,
3801
ScilabXgc->CWindowWidth,
3802
ScilabXgc->CWindowHeight,
3803
ScilabXgc->hWndParent,
3804
NULL, graphwin.hInstance,
3807
ScilabXgc->CurResizeStatus = 1;
3808
ScilabXgc->CWindowWidthView = ScilabXgc->CWindowWidth;
3809
ScilabXgc->CWindowHeightView = ScilabXgc->CWindowHeight;
3811
/* definition des scroll bars verticalles */
3812
vertsi.cbSize = sizeof(SCROLLINFO);
3813
vertsi.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
3815
vertsi.nMax = ScilabXgc->CWindowHeight;
3816
vertsi.nPage = ScilabXgc->CWindowHeightView;
3818
sciSetScrollInfo(ScilabXgc,SB_VERT, &(vertsi), TRUE);
3819
sciGetScrollInfo(ScilabXgc,SB_VERT, &vertsi);
3821
/* definition des scroll bars horizontalle */
3822
horzsi.cbSize = sizeof(SCROLLINFO);
3823
horzsi.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
3825
horzsi.nMax = ScilabXgc->CWindowWidth;
3826
horzsi.nPage = ScilabXgc->CWindowWidthView;
3828
sciSetScrollInfo(ScilabXgc,SB_HORZ, &horzsi, TRUE);
3829
sciGetScrollInfo(ScilabXgc,SB_HORZ, &horzsi);
3831
//sciInitScrollBar(ScilabXgc);
3833
if (ScilabXgc->CWindow == (HWND)NULL)
3835
MessageBox((HWND)NULL,"Couldn't open graphic window",
3836
(LPSTR)NULL, MB_ICONHAND | MB_SYSTEMMODAL);
3839
/* modify the system menu to have the new items we want */
3840
sysmenu = GetSystemMenu(ScilabXgc->hWndParent,0);
3841
AppendMenu(sysmenu, MF_SEPARATOR, 0, NULL);
3842
AppendMenu(sysmenu, MF_STRING, M_ABOUT, "&About");
3843
ShowWindow(ScilabXgc->CWindow, SW_SHOWNORMAL);
3844
ShowWindow(ScilabXgc->hWndParent, SW_SHOWNORMAL);
3845
graphwin.resized = FALSE;
3846
LoadGraphMacros( ScilabXgc);
3847
/** Default value is without Pixmap **/
3848
ScilabXgc->CurPixmapStatus = 0;
3849
ScilabXgc->CurResizeStatus = 1;
3850
ScilabXgc->CurWindow = WinNum;
3851
/* on fait un SetWinhdc car on vient de creer la fenetre */
3852
/* le release est fait par Xcall.c */
3854
SetMapMode(hdc, MM_TEXT);
3855
SetBkMode(hdc,TRANSPARENT);
3856
GetClientRect(ScilabXgc->CWindow, &rect);
3857
SetViewportExtEx(hdc, rect.right, rect.bottom,NULL);
3858
SetTextAlign(hdc, TA_LEFT|TA_BOTTOM);
3859
SetFocus( ScilabXgc->CWindow);
3861
if (EntryCounter == 0)
3863
C2F(CreatePatterns)();
3866
InitMissileXgc(PI0,PI0,PI0,PI0);/* a laisser ici */
3867
EntryCounter=Max(EntryCounter,WinNum);
3869
ScilabXgc->Inside_init=0;
3872
static void CreateGraphClass()
3874
static WNDCLASS wndclass;
3875
/** each Graphic window owns is DC : CS_OWNDC **/
3876
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
3877
wndclass.lpfnWndProc = WndGraphProc;
3878
wndclass.cbClsExtra = 0;
3879
wndclass.cbWndExtra = 4 * sizeof(void *);
3880
wndclass.hInstance = graphwin.hInstance;
3881
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
3882
/** should be changed : cursor must be changed when inside xclick **/
3883
wndclass.hCursor = LoadCursor(NULL, IDC_CROSS);
3884
wndclass.hbrBackground = GetStockBrush(WHITE_BRUSH);
3885
wndclass.lpszMenuName = NULL;
3886
wndclass.lpszClassName = szGraphClass;
3887
RegisterClass(&wndclass);
3888
/** The parent window **/
3889
wndclass.style = CS_HREDRAW | CS_VREDRAW;
3890
wndclass.lpfnWndProc = WndParentGraphProc;
3891
wndclass.cbClsExtra = 0;
3892
wndclass.cbWndExtra = 4 * sizeof(void *);
3893
wndclass.hInstance = graphwin.hInstance;
3895
wndclass.hIcon = textwin.hIcon;
3897
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
3898
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
3899
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
3900
wndclass.lpszMenuName = NULL;
3901
wndclass.lpszClassName = szParentGraphClass;
3902
RegisterClass(&wndclass);
3905
/* Writes a message in the Label info part of the Graphicwindow */
3907
void C2F(xinfo)(message, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
3909
integer *v2,*v3,*v4,*v5,*v6,*v7;
3910
double *dv1,*dv2,*dv3,*dv4;
3912
if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->Statusbar != (Window) 0)
3914
(BOOL)SendMessage(ScilabXgc->Statusbar, SB_SETTEXT, (WPARAM) 0,
3915
(LPARAM) (LPSTR) message );
3919
/* Extended call for C calling */
3920
#define MAXPRINTF 512
3922
void wininfo(char *fmt,...)
3925
char buf[MAXPRINTF];
3928
count = vsprintf(buf,fmt,args);
3929
if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->Statusbar != (Window) 0)
3931
(BOOL)SendMessage(ScilabXgc->Statusbar, SB_SETTEXT, (WPARAM) 0,
3932
(LPARAM) (LPSTR) buf);
3936
/*************************************************
3937
* Initialize the graphic context. Used also
3938
* to come back to the default graphic state
3939
*************************************************/
3941
static void InitMissileXgc (integer *v1,integer *v2,integer *v3,integer *v4)
3944
ScilabXgc->IDLastPattern = GREYNUMBER - 1;
3945
ScilabXgc->CurLineWidth=0 ;
3947
C2F(setalufunction1)((i=3,&i),PI0,PI0,PI0);
3948
/** retirer le clipping **/
3950
C2F(unsetclip)(PI0,PI0,PI0,PI0);
3951
ScilabXgc->ClipRegionSet= 0;
3952
C2F(xsetfont)((i=2,&i),(j=1,&j),PI0,PI0);
3953
C2F(xsetmark)((i=0,&i),(j=0,&j),PI0,PI0);
3954
/* ScilabXgc->CurPixmapStatus =0 ; */
3955
C2F(setpixmapOn)((i = 0,&i),PI0,PI0,PI0);
3956
/* ScilabXgc->CurResizeStatus =1 ; */
3957
C2F(setwresize)((i = sciGetwresize(), &i), PI0,PI0,PI0);
3958
C2F(setpixmapOn)((i = 0,&i),PI0,PI0,PI0);
3959
/** trac\'e absolu **/
3960
i= CoordModeOrigin ;
3961
C2F(setabsourel)(&i,PI0,PI0,PI0);
3962
/* initialisation des pattern dash par defaut en n&b */
3963
ScilabXgc->CurColorStatus =0;
3964
C2F(setpattern)((i=1,&i),PI0,PI0,PI0);
3965
C2F(setdash)((i=1,&i),PI0,PI0,PI0);
3966
C2F(sethidden3d)((i=1,&i),PI0,PI0,PI0);
3967
/** attention setthickness : depend de la couleur en Win95 **/
3968
C2F(setthickness)((i=0,&i),PI0,PI0,PI0);
3969
/* initialisation de la couleur par defaut */
3970
ScilabXgc->CurColorStatus = 1;
3972
set_default_colormap();
3973
C2F(setalufunction1)((i=3,&i),PI0,PI0,PI0);
3974
C2F(setpattern)((i=DefaultForeground,&i),PI0,PI0,PI0);
3975
C2F(setpattern)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
3976
C2F(setthickness)((i=1,&i),PI0,PI0,PI0);
3977
/*** XXXXX a faire aussi pour le n&b plus haut ***/
3978
C2F(setforeground)((i=ScilabXgc->NumForeground+1,&i),PI0,PI0,PI0);
3979
C2F(setbackground)((i=ScilabXgc->NumForeground+2,&i),PI0,PI0,PI0);
3980
C2F(sethidden3d)((i=4,&i),PI0,PI0,PI0);
3981
/* Choix du mode par defaut (decide dans initgraphic) */
3983
/** we force CurColorStatus to the opposite value of col
3984
to force usecolorPos to perform initialisations
3986
ScilabXgc->CurColorStatus = (i == 1) ? 0: 1;
3987
C2F(usecolor)(&i ,PI0,PI0,PI0);
3988
strcpy(ScilabXgc->CurNumberDispFormat,"%-5.2g");
3989
/** default scales **/
3994
/* returns the current color status */
3996
void getcolordef(screenc)
3999
*screenc= screencolor;
4002
void setcolordef(screenc)
4005
screencolor = screenc;
4008
/* Utilise le ScilabXgc courant pour reinitialiser le gc XWindow */
4009
/* cela est utilis'e quand on change de fenetre graphique */
4014
integer i,j, clip[4];
4015
i= ScilabXgc->FontId;
4016
j= ScilabXgc->FontSize;
4017
C2F(xsetfont)(&i,&j,PI0,PI0);
4018
/** wininfo("Reset Scilab Xgc avec %d %d\r\n",i,j); **/
4019
i= ScilabXgc->CurHardSymb;
4020
j= ScilabXgc->CurHardSymbSize;
4021
C2F(xsetmark)(&i,&j,PI0,PI0);
4023
i= ScilabXgc->CurLineWidth;
4024
C2F(setthickness)(&i,PI0,PI0,PI0);
4026
i= ScilabXgc->CurVectorStyle;
4027
C2F(setabsourel)(&i,PI0,PI0,PI0);
4029
i= ScilabXgc->CurDrawFunction;
4030
C2F(setalufunction1)(&i,PI0,PI0,PI0);
4032
if (ScilabXgc->ClipRegionSet == 1)
4034
for ( i= 0 ; i < 4; i++) clip[i]=ScilabXgc->CurClipRegion[i];
4035
C2F(setclip)(clip,clip+1,clip+2,clip+3);
4038
C2F(unsetclip)(PI0,PI0,PI0,PI0);
4040
if (ScilabXgc->CurColorStatus == 0)
4042
/* remise des couleurs a vide */
4043
ScilabXgc->CurColorStatus = 1;
4044
C2F(setpattern)((i=DefaultForeground,&i),PI0,PI0,PI0);
4045
/* passage en n&b */
4046
ScilabXgc->CurColorStatus = 0;
4047
i= ScilabXgc->CurPattern + 1;
4048
C2F(setpattern)(&i,PI0,PI0,PI0);
4049
i= ScilabXgc->CurDashStyle + 1;
4050
C2F(setdash)(&i,PI0,PI0,PI0);
4051
i= ScilabXgc->NumHidden3d+1;
4052
C2F(sethidden3d)(&i,PI0,PI0,PI0);
4056
/* remise a zero des patterns et dash */
4057
/* remise des couleurs a vide */
4058
ScilabXgc->CurColorStatus = 0;
4059
C2F(setpattern)((i=1,&i),PI0,PI0,PI0);
4060
C2F(setdash)((i=1,&i),PI0,PI0,PI0);
4061
/* passage en couleur */
4062
ScilabXgc->CurColorStatus = 1;
4063
i= ScilabXgc->CurColor + 1;
4064
C2F(setpattern)(&i,PI0,PI0,PI0);
4065
i= ScilabXgc->NumBackground+1;
4066
C2F(setbackground)(&i,PI0,PI0,PI0);
4067
i= ScilabXgc->NumForeground+1;
4068
C2F(setforeground)(&i,PI0,PI0,PI0);
4069
i= ScilabXgc->NumHidden3d+1;
4070
C2F(sethidden3d)(&i,PI0,PI0,PI0);
4074
/*------------------------------------------------------
4075
Draw an axis whith a slope of alpha degree (clockwise)
4076
. Along the axis marks are set in the direction ( alpha + pi/2), in the
4082
|----|---|---|---|---|---|
4084
<-------------n2-------->
4086
$n1$and $n2$ are integer numbers for interval numbers.
4087
\item $size=<dl,r,coeff>$. $dl$ distance in points between
4088
two marks, $r$ size in points of small mark, $r*coeff$
4089
size in points of big marks. (they are doubleing points numbers)
4090
\item $init$. Initial point $<x,y>$.
4093
-------------------------------------------------------------*/
4095
void C2F(drawaxis)(str, alpha, nsteps, v2, initpoint, v6, v7, size, dx2, dx3, dx4)
4110
cosal= cos( (double)M_PI * (*alpha)/180.0);
4111
sinal= sin( (double)M_PI * (*alpha)/180.0);
4112
for (i=0; i <= nsteps[0]*nsteps[1]; i++)
4114
if ( ( i % nsteps[0]) != 0)
4116
xi = initpoint[0]+i*size[0]*cosal;
4117
yi = initpoint[1]+i*size[0]*sinal;
4118
xf = xi - ( size[1]*sinal);
4119
yf = yi + ( size[1]*cosal);
4120
MoveToEx(hdc,inint(xi),inint(yi),NULL);
4121
LineTo(hdc,inint(xf),inint(yf));
4124
for (i=0; i <= nsteps[1]; i++)
4125
{ xi = initpoint[0]+i*nsteps[0]*size[0]*cosal;
4126
yi = initpoint[1]+i*nsteps[0]*size[0]*sinal;
4127
xf = xi - ( size[1]*size[2]*sinal);
4128
yf = yi + ( size[1]*size[2]*cosal);
4129
MoveToEx(hdc,inint(xi),inint(yi),NULL);
4130
LineTo(hdc,inint(xf),inint(yf));
4133
xi = initpoint[0]; yi= initpoint[1];
4134
xf = initpoint[0]+ nsteps[0]*nsteps[1]*size[0]*cosal;
4135
yf = initpoint[1]+ nsteps[0]*nsteps[1]*size[0]*sinal;
4136
MoveToEx(hdc,inint(xi),inint(yi),NULL);
4137
LineTo(hdc,inint(xf),inint(yf));
4141
/*-----------------------------------------------------
4142
\encadre{Display numbers z[i] at location (x[i],y[i])
4143
with a slope alpha[i] (see displaystring), if flag==1
4144
add a box around the string, only if slope =0}
4145
-----------------------------------------------------*/
4147
void C2F(displaynumbers)(str, x, y, v1, v2, n, flag, z, alpha, dx3, dx4)
4162
for (i=0 ; i< *n ; i++)
4164
sprintf(buf,ScilabXgc->CurNumberDispFormat,z[i]);
4165
C2F(displaystring)(buf,&(x[i]),&(y[i]),PI0,flag,PI0,PI0,&(alpha[i]),PD0,PD0,PD0) ;
4169
void C2F(bitmap)(string, w, h)
4175
static XImage *setimage;
4176
setimage = XCreateImage (dpy, XDefaultVisual (dpy, DefaultScreen(dpy)),
4177
1, XYBitmap, 0, string,w,h, 8, 0);
4178
setimage->data = string;
4179
XPutImage (dpy, Cdrawable, gc, setimage, 0, 0, 10,10,w,h);
4180
XDestroyImage(setimage);
4184
/***********************************
4185
* Fonts for the graphic windows
4186
***********************************/
4188
#define FONTNUMBER 7
4189
#define FONTMAXSIZE 6
4190
#define SYMBOLNUMBER 10
4192
/* structure to keep track of fonts
4193
Dans FontInfoTab : on se garde des information sur les
4194
fonts la fonts i a pour nom fname et ok vaut 1 si
4195
elle a ete chargee ds le serveur
4196
c'est loadfamily qui se charge de charger une font a diverses
4197
taille ds le serveur.
4198
The font i at size fsiz is stored at position FontInfoTab[i].hf[fsiz]
4201
typedef struct tagFontInfo {
4204
HFONT hf[FONTMAXSIZE];
4205
} FontInfoT[FONTNUMBER];
4207
static int scale_font_size = 1;
4208
static FontInfoT FontInfoTab; /** for screen **/
4209
static FontInfoT FontInfoTabPrinter; /** for printer **/
4211
static FontInfoT *FontTab = &FontInfoTab;
4213
static char *size_[] = { "08" ,"10","12","14","18","24"};
4214
static int size_n_[] = {8,10,12,14,18,24};
4216
/** We use the Symbol font for mark plotting **/
4217
/** so we want to be able to center a Symbol character at a specified point **/
4219
typedef struct { integer xoffset[FONTMAXSIZE][SYMBOLNUMBER];
4220
integer yoffset[FONTMAXSIZE][SYMBOLNUMBER];} Offset ;
4221
static Offset ListOffset;
4222
static Offset ListOffsetPrint;
4223
static Offset *SymbOffset = &ListOffset;
4225
static char Marks[] = {
4226
/*., +,X,*,diamond(filled),diamond,triangle up,triangle down,trefle,circle*/
4227
(char)46,(char)43,(char)180,(char)42, (char)168,(char)224,
4228
(char)196,(char)209,(char)167,(char)176,};
4231
/** To set the current font id and size **/
4232
/** load the fonts into X11 if necessary **/
4235
char *alias; char *name; char *Winname;
4238
/** ce qui suit marche sur 75dpi ou 100dpi **/
4240
FontAlias fonttab[] ={
4241
{"CourR", "-adobe-courier-medium-r-normal--*-%s0-*-*-m-*-iso8859-1","Courier New"},
4242
{"Symb", "-adobe-symbol-medium-r-normal--*-%s0-*-*-p-*-adobe-fontspecific","Symbol"},
4243
{"TimR", "-adobe-times-medium-r-normal--*-%s0-*-*-p-*-iso8859-1","Times New Roman"},
4244
{"TimI", "-adobe-times-medium-i-normal--*-%s0-*-*-p-*-iso8859-1","Times New Roman Italic"},
4245
{"TimB", "-adobe-times-bold-r-normal--*-%s0-*-*-p-*-iso8859-1","Times New Roman Bold"},
4246
{"TimBI", "-adobe-times-bold-i-normal--*-%s0-*-*-p-*-iso8859-1","Times New Roman Bold Italic"},
4247
{(char *) NULL,( char *) NULL}
4250
/***********************************
4251
* set current font to font fontid at size
4252
* fontsize ( <<load>> the font if necessary )
4253
***********************************/
4255
void C2F(xsetfont)(fontid, fontsize, v3, v4)
4262
i = Min(FONTNUMBER-1,Max(*fontid,0));
4263
fsiz = Min(FONTMAXSIZE-1,Max(*fontsize,0));
4264
if ( (*FontTab)[i].ok !=1 )
4268
C2F(loadfamily)(fonttab[i].alias,&i,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
4272
sciprint(" The Font Id %d is not affected \r\n",(int)i);
4273
Scistring(" use xlfont to set it \n");
4277
ScilabXgc->FontId = i;
4278
ScilabXgc->FontSize = fsiz;
4279
SelectFont(hdc, (*FontTab)[i].hf[fsiz]);
4282
static HFONT getcurfont()
4284
return( (*FontTab)[ScilabXgc->FontId].hf[ScilabXgc->FontSize]);
4287
/*********************************************
4288
* To get the id and size of the current font
4289
**********************************************/
4291
void C2F(xgetfont)(verbose, font, nargs,dummy)
4298
font[0]= ScilabXgc->FontId ;
4299
font[1] =ScilabXgc->FontSize ;
4302
sciprint("\r\nFontId : %d ", ScilabXgc->FontId );
4303
sciprint("--> %s at size %s pts\r\n",
4304
(*FontTab)[ScilabXgc->FontId].fname,
4305
size_[ScilabXgc->FontSize]);
4309
/*********************************************
4310
* To set the current mark ( a symbol in font symbol)
4311
**********************************************/
4313
void C2F(xsetmark)(number, size, v3, v4)
4319
ScilabXgc->CurHardSymb = Max(Min(SYMBOLNUMBER-1,*number),0);
4320
ScilabXgc->CurHardSymbSize = Max(Min(FONTMAXSIZE-1,*size),0);
4324
/*********************************************
4325
* To get the current mark id
4326
**********************************************/
4328
void C2F(xgetmark)(verbose, symb, narg,dummy)
4335
symb[0] = ScilabXgc->CurHardSymb ;
4336
symb[1] = ScilabXgc->CurHardSymbSize ;
4339
sciprint("\nMark : %d ",ScilabXgc->CurHardSymb);
4340
sciprint("at size %s pts\r\n", size_[ScilabXgc->CurHardSymbSize]);
4344
/**************************************************
4345
* loadfamily Loads a font at size 08 10 12 14 18 24
4346
* for example TimR08 TimR10 TimR12 TimR14 TimR18 TimR24
4348
* ( X11 only : if it's a string containing the char %
4349
* it's suposed to be a format for a generic font in X11 string style
4350
* "-adobe-times-bold-i-normal--%s-*-75-75-p-*-iso8859-1" )
4351
* it's supposed to be an alias for a font name
4352
* Ex : TimR and we shall try to load TimR08 TimR10 TimR12 TimR14 TimR18 TimR24
4353
**************************************************/
4355
void C2F(loadfamily)(name, j, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
4357
integer *j,*v3,*v4,*v5,*v6,*v7;
4358
double *dv1, *dv2,*dv3,*dv4;
4361
/** our table of alias **/
4363
while ( fonttab[i].alias != (char *) NULL)
4365
if (strcmp(fonttab[i].alias,name)==0)
4367
C2F(loadfamily_n)(fonttab[i].Winname,j);
4372
C2F(loadfamily_n)(name,j);
4375
void C2F(queryfamily)(name, j, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
4390
for (i=0;i<FONTNUMBER;i++) {
4391
v3[i]=strlen((*FontTab)[i].fname);
4393
strcat(name,(*FontTab)[i].fname);
4395
v3[i]=strlen(fonttab[i].Winname);
4396
strcat(name,fonttab[i].Winname);
4402
/** creates a font **/
4404
void SciMakeFont(name,size,hfont)
4411
memset(&lf, 0, sizeof(LOGFONT));
4412
strncpy(lf.lfFaceName,name,LF_FACESIZE);
4413
/** lf.lfHeight = - MulDiv( size, GetDeviceCaps(hdc, LOGPIXELSY), 72); **/
4414
lf.lfHeight = - size*scale_font_size;
4415
lf.lfCharSet = DEFAULT_CHARSET;
4416
if ( (p = strstr(name," Italic")) != (LPSTR)NULL ) {
4417
lf.lfFaceName[ (unsigned int)(p- name) ] = '\0';
4420
if ( (p = strstr(name," Bold")) != (LPSTR)NULL ) {
4421
lf.lfFaceName[ (unsigned int)(p- name) ] = '\0';
4422
lf.lfWeight = FW_BOLD;
4424
*hfont = CreateFontIndirect((LOGFONT FAR *)&lf);
4427
static void C2F(loadfamily_n)(name, j)
4432
for ( i = 0; i < FONTMAXSIZE ; i++)
4434
SciMakeFont(name,size_n_[i], &((*FontTab)[*j].hf[i]));
4435
if ( (*FontTab)[*j].hf[i] == (HFONT) 0 )
4438
sciprint("Unknown font : %s\r\n",name);
4439
Scistring("I'll use font: Courier New\r\n");
4440
SciMakeFont("Courier New",size_n_[i], &((*FontTab)[*j].hf[i]));
4441
if ( (*FontTab)[*j].hf[i] == (HFONT) 0)
4443
sciprint("Unknown font : %s\r\n","Courier New");
4444
Scistring(" Please send a bug report !\r\n");
4448
(*FontTab)[*j].ok = 1;
4450
strcpy((*FontTab)[*j].fname,name);
4452
strcpy((*FontTab)[*j].fname,"Courier New");
4455
/********************************************
4456
* switch to printer font
4457
********************************************/
4459
void SciG_Font_Printer(int scale)
4461
static int last_scale= -1;
4462
FontTab = &FontInfoTabPrinter;
4463
SymbOffset = &ListOffsetPrint;
4464
if ( last_scale != -1 && last_scale != scale )
4466
scale_font_size = last_scale = scale;
4470
void SciG_Font(void)
4472
FontTab = &FontInfoTab;
4473
SymbOffset = &ListOffset;
4474
scale_font_size = 1;
4480
for ( j= 0 ; j < FONTNUMBER ; j++ )
4482
if ( (*FontTab)[j].ok == 1)
4484
(*FontTab)[j].ok = 0;
4485
for ( i = 0; i < FONTMAXSIZE ; i++)
4487
DeleteObject( (*FontTab)[j].hf[i]) ;
4488
(*FontTab)[j].hf[i] = (HFONT) 0;
4494
/********************************************
4495
* Initial set of font loaded at startup
4496
********************************************/
4498
static void LoadFonts()
4501
C2F(loadfamily)("CourR",(fnum=0,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
4503
C2F(loadfamily)("TimR",(fnum=2,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
4505
XXX : we load fonts when we need see xsetfonts
4506
C2F(loadfamily)("TimI",(fnum=3,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
4507
C2F(loadfamily)("TimB",(fnum=4,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
4508
C2F(loadfamily)("TimBI",(fnum=5,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
4517
/** XCharStruct xcs;**/
4520
/** Symbol Font is loaded under Id : 1 **/
4521
C2F(loadfamily)("Symb",(i=1,&i),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
4522
/* We compute the char offset for several chars of the symbol font */
4523
/** if symbol font was not found me must stop **/
4524
fid=1; /** the symbol font **/
4525
for (i =0 ; i < FONTMAXSIZE ; i++)
4527
if ( (*FontTab)[1].hf[i] != NULL)
4529
SelectFont(hdc, (*FontTab)[fid].hf[i]);
4530
for (j=0 ; j < SYMBOLNUMBER ; j++)
4535
GetTextExtentPoint32(hdc,str,1,&size);
4536
SymbOffset->xoffset[i][j] = size.cx /2;
4537
SymbOffset->yoffset[i][j] = size.cy /2;
4543
/** The two next functions send the x and y offsets to center the current **/
4544
/** symbol at point (x,y) **/
4546
int C2F(CurSymbXOffset)()
4548
return(- SymbOffset->xoffset[ScilabXgc->CurHardSymbSize]
4549
[ScilabXgc->CurHardSymb]);
4551
int C2F(CurSymbYOffset)()
4553
return( SymbOffset->yoffset[ScilabXgc->CurHardSymbSize]
4554
[ScilabXgc->CurHardSymb]);
4557
/********************************************
4558
* Draws the current mark centred at position
4560
********************************************/
4562
static void DrawMark(lhdc,x, y)
4571
str[0]=Marks[ScilabXgc->CurHardSymb];
4573
if ( ScilabXgc->CurDrawFunction == GXxor )
4576
GetTextExtentPoint32(hdc,str,1,&size);
4577
XorString(*x+C2F(CurSymbXOffset)(),*y+C2F(CurSymbYOffset)(),
4578
str,size.cx,size.cy);
4582
TextOut(hdc,*x+C2F(CurSymbXOffset)(),*y+C2F(CurSymbYOffset)(),str,1);
4585
GetTextExtentPoint32(hdc,str,1,&size);
4586
sciprint("valeurs %d %d %d %d\r\n",size.cx,size.cy,C2F(CurSymbXOffset)(),
4587
C2F(CurSymbYOffset)());
4588
TextOut(hdc,*x,*y,str,1);
4589
Rectangle(hdc,(int) *x+30,(int) *y - size.cy,(int) *x+size.cx+30 ,
4594
/*-------------------------------------------------------------------
4595
\subsection{Allocation and storing function for vectors of X11-points}
4596
------------------------------------------------------------------------*/
4598
static POINT *points;
4599
static unsigned nbpoints;
4600
#define NBPOINTS 256
4602
int C2F(store_points)(n, vx, vy, onemore)
4609
if ( onemore == 1) n1=n+1;
4611
if (ReallocVector(n1) == 1)
4613
for (i = 0; i < n; i++){
4615
if ( Abs(vx[i]) > int16max )
4617
fprintf(stderr,"Warning store_point oustide of 16bits x=%d\n",
4620
if ( Abs(vy[i]) > int16max )
4622
fprintf(stderr,"Warning store_point oustide of 16bits x=%d\n",
4626
points[i].x =(short) vx[i];
4627
points[i].y =(short) vy[i];
4630
points[n].x=(short) points[0].x;
4631
points[n].y=(short) points[0].y;
4638
static int ReallocVector(n)
4641
while ( (unsigned) n > nbpoints){
4642
nbpoints = 2 * nbpoints ;
4643
points = (POINT *) REALLOC(points,(unsigned)
4644
nbpoints * sizeof (POINT));
4654
int C2F(AllocVectorStorage)()
4656
nbpoints = NBPOINTS;
4657
points = (POINT *) MALLOC( nbpoints * sizeof (POINT));
4658
if ( points == 0) { sciprint(MESSAGE4);return(0);}
4662
static POINT *C2F(ReturnPoints)() { return(points); }
4664
/** Clipping functions **/
4665
/** XXXX a isoler des p'eripheriques car c'est utilis'e dans plot3d **/
4667
/* My own clipping routines
4668
XDrawlines with clipping on the current graphic window
4669
to ovoid trouble on some X servers **/
4671
static integer xleft,xright,ybot,ytop;
4673
/* Test a single point to be within the xleft,xright,ybot,ytop bbox.
4674
* Sets the returned integers 4 l.s.b. as follows:
4675
* bit 0 if to the left of xleft.
4676
* bit 1 if to the right of xright.
4677
* bit 2 if below of ybot.
4678
* bit 3 if above of ytop.
4679
* 0 is returned if inside.
4682
static int clip_point(x, y)
4685
integer ret_val = 0;
4687
if (x < xleft) ret_val |= (char)0x01;
4688
else if (x > xright) ret_val |= (char)0x02;
4689
if (y < ybot) ret_val |= (char)0x04;
4690
else if (y > ytop) ret_val |= (char)0x08;
4694
/* Clip the given line to drawing coords defined as xleft,xright,ybot,ytop.
4695
* This routine uses the cohen & sutherland bit mapping for fast clipping -
4696
* see "Principles of Interactive Computer Graphics" Newman & Sproull page 65.
4697
return 0 : segment out
4700
3 : (x1,y1) and (x2,y2) changed
4705
void set_clip_box(xxleft,xxright,yybot,yytop)
4706
integer xxleft,xxright,yybot,yytop;
4715
clip_line(x1, yy1, x2, y2, x1n, yy1n, x2n, y2n, flag)
4716
integer x1, yy1, x2, y2, *flag, *x1n, *yy1n, *x2n, *y2n;
4718
integer x, y, dx, dy, x_intr[2], y_intr[2], count, pos1, pos2;
4719
*x1n=x1;*yy1n=yy1;*x2n=x2;*y2n=y2;*flag=4;
4720
pos1 = clip_point(x1, yy1);
4721
pos2 = clip_point(x2, y2);
4723
if (pos1 & pos2) { *flag=0;return;}
4724
/* segment is totally out. */
4726
/* Here part of the segment MAy be inside. test the intersection
4727
* of this segment with the 4 boundaries for hopefully 2 intersections
4728
* in. If non found segment is totaly out.
4734
/* Find intersections with the x parallel bbox lines: */
4736
x = (int) ((ybot - y2) * ((double) dx / (double) dy) + x2);
4737
/* Test for ybot boundary. */
4738
if (x >= xleft && x <= xright) {
4740
y_intr[count++] = ybot;
4742
x = (int) ((ytop - y2) * ((double) dx / (double) dy) + x2);
4743
/* Test for ytop boundary. */
4744
if (x >= xleft && x <= xright) {
4746
y_intr[count++] = ytop;
4750
/* Find intersections with the y parallel bbox lines: */
4752
y = (int) ((xleft - x2) * ((double) dy / (double) dx) + y2);
4753
/* Test for xleft boundary. */
4754
if (y >= ybot && y <= ytop) {
4755
x_intr[count] = xleft;
4756
y_intr[count++] = y;
4758
y = (int) ((xright - x2) * ((double) dy / (double) dx) + y2);
4759
/* Test for xright boundary. */
4760
if (y >= ybot && y <= ytop) {
4761
x_intr[count] = xright;
4762
y_intr[count++] = y;
4767
if (pos1 && pos2) { /* Both were out - update both */
4774
else if (pos1) { /* Only x1/yy1 was out - update only it */
4775
if (dx * (x2 - x_intr[0]) + dy * (y2 - y_intr[0]) >= 0) {
4786
else { /* Only x2/y2 was out - update only it */
4787
if (dx * (x_intr[0] - x1) + dy * (y_intr[0] - yy1) >= 0) {
4811
* returns the first (vx[.],vy[.]) point inside
4812
* xleft,xright,ybot,ytop bbox. begining at index ideb
4813
* or zero if the whole polyline is out
4816
integer first_in(n, ideb, vx, vy)
4823
for (i=ideb ; i < n ; i++)
4825
if (vx[i]>= xleft && vx[i] <= xright && vy[i] >= ybot && vy[i] <= ytop)
4828
sciprint("first in %d->%d=(%d,%d)\r\n",ideb,i,vx[i],vy[i]);
4837
* returns the first (vx[.],vy[.]) point outside
4838
* xleft,xright,ybot,ytop bbox.
4839
* or zero if the whole polyline is out
4842
integer first_out(n, ideb, vx, vy)
4849
for (i=ideb ; i < n ; i++)
4851
if ( vx[i]< xleft || vx[i]> xright || vy[i] < ybot || vy[i] > ytop)
4854
sciprint("first out %d->%d=(%d,%d)\r\n",ideb,i,vx[i],vy[i]);
4861
int CheckScilabXgc()
4863
return( ScilabXgc != (struct BCG *) 0);