~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to routines/graphics/periWin.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*------------------------------------------------------------------------
 
2
 *    Graphic library
 
3
 *    Copyright (C) 1998-2000 Enpc/Jean-Philippe Chancelier
 
4
 *    jpc@cereve.enpc.fr 
 
5
 --------------------------------------------------------------------------*/
 
6
 
 
7
/***************************************************************** 
 
8
 *  Windows driver 
 
9
 *****************************************************************/
 
10
 
 
11
#ifndef STRICT 
 
12
#define STRICT
 
13
#endif 
 
14
#include <windows.h>
 
15
#include <windowsx.h>
 
16
#ifndef __GNUC__
 
17
#include <commctrl.h>
 
18
#endif
 
19
#include <stdio.h>
 
20
#include <string.h>
 
21
#include <math.h>
 
22
#include <stdlib.h>
 
23
#include <stdarg.h>
 
24
 
 
25
#include "../wsci/wgnuplib.h"
 
26
#include "../wsci/wresource.h"
 
27
#include "../wsci/wcommon.h"
 
28
 
 
29
#include "periWin.h" 
 
30
#include "version.h"
 
31
#include "color.h" 
 
32
#include "Graphics.h"
 
33
#include "scigraphic.h"
 
34
 
 
35
#define M_PI    3.14159265358979323846
 
36
#define CoordModePrevious 1
 
37
#define CoordModeOrigin 0
 
38
 
 
39
/** 
 
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 
 
42
 
 
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.
 
51
  **/
 
52
 
 
53
LRESULT CALLBACK WndGraphProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
 
54
LRESULT CALLBACK WndParentGraphProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
 
55
 
 
56
/* Initialization values - Guess Now Scale later */
 
57
 
 
58
#define WIN_XMAX (2400)
 
59
#define WIN_YMAX (1800)
 
60
#define WIN_HCHAR (WIN_XMAX/75) 
 
61
#define WIN_VCHAR (WIN_YMAX/25)
 
62
 
 
63
/* relative or absolute mode for drawing */
 
64
 
 
65
#define MESSAGE4 "Can't allocate point vector"
 
66
#define MESSAGE5 "Can't re-allocate point vector" 
 
67
#define Char2Int(x)   ( x & 0x000000ff )
 
68
 
 
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
 
72
 */
 
73
 
 
74
unsigned short default_colors[] = {
 
75
   0,   0,   0, /* Black: DEFAULTBLACK */
 
76
   0,   0, 255, /* Blue */
 
77
   0, 255,   0, /* Green */
 
78
   0, 255, 255, /* Cyan */
 
79
 255,   0,   0, /* Red */
 
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 */
 
93
 144,   0,   0, /* Red4 */
 
94
 176,   0,   0, /* Red3 */
 
95
 208,   0,   0, /* Red2 */
 
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 */
 
107
};
 
108
 
 
109
 
 
110
#define GXxor 6
 
111
 
 
112
#define MAXDASH 5
 
113
static integer DashTab[MAXDASH] = { PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT};
 
114
 
 
115
 
 
116
/** 
 
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 
 
121
  **/
 
122
 
 
123
extern GW graphwin; /** keeps information for the current graphic window **/
 
124
extern TW textwin; /** keeps information for the current graphic window **/
 
125
 
 
126
/** XXX a mettre ailleurs **/
 
127
 
 
128
static  POINT *C2F(ReturnPoints)();
 
129
static HFONT getcurfont();
 
130
int XorString(integer x,integer y, char *string,int fWidth,int fHeight);
 
131
 
 
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);
 
135
 
 
136
#define COLORREF COLORREF
 
137
 
 
138
/** Structure to keep the graphic state  **/
 
139
 
 
140
struct BCG MissileXgc ;
 
141
 
 
142
/* structure for Window List  */
 
143
 
 
144
typedef  struct 
 
145
{
 
146
  struct BCG winxgc;
 
147
  struct WindowList *next;
 
148
} WindowList  ;
 
149
 
 
150
static WindowList *The_List  = (WindowList *) NULL;
 
151
static integer deleted_win = -1;
 
152
struct BCG *ScilabXgc = (struct BCG *) 0;
 
153
 
 
154
/** functions **/
 
155
 
 
156
Window GetWindowNumber();
 
157
struct BCG *GetWinXgc();
 
158
struct BCG *GetWindowXgcNumber();
 
159
struct BCG *AddNewWindow();
 
160
struct BCG *AddNewWindowToList();
 
161
 
 
162
int SwitchWindow(integer *intnum);
 
163
 
 
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) ;
 
172
 
 
173
 
 
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
 *************************************************/
 
184
 
 
185
static HDC  hdc = (HDC) 0 ; 
 
186
static HDC  hdc1 = (HDC) 0 ; 
 
187
 
 
188
 
 
189
int sciGetScrollInfo(struct BCG *Scilabgc, int sb_ctl, SCROLLINFO *si)
 
190
{
 
191
        SCROLLINFO totosi;
 
192
        
 
193
        switch (sb_ctl) {
 
194
        case SB_VERT:
 
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;
 
202
                break;
 
203
        case SB_HORZ:
 
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;
 
211
                break;
 
212
        default:
 
213
                break;
 
214
        }
 
215
        /* force le rafraichissement de l'affichage des SB !!! */
 
216
        GetScrollInfo(Scilabgc->CWindow, sb_ctl, &totosi);
 
217
        return 0;
 
218
}
 
219
 
 
220
 
 
221
int sciSetScrollInfo(struct BCG *Scilabgc, int sb_ctl, SCROLLINFO *si, boolean bRedraw)
 
222
{
 
223
        int inttmp = si->nMax;
 
224
        SCROLLINFO totosi;
 
225
 
 
226
 
 
227
        switch (sb_ctl) {
 
228
        case SB_VERT:
 
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) {
 
236
                        //inttmp = si->nMax;
 
237
                        si->nMax = 0; /* on effectue un swapp pour ne pas changer la val (pointeur !!) */
 
238
                                      /* 0 permet de faire disparaitre les scrollbars */
 
239
                }
 
240
                Scilabgc->vertsi.nPos   = si->nPos;     
 
241
                break;
 
242
        case SB_HORZ:
 
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) {
 
250
                        //inttmp = si->nMax;
 
251
                        si->nMax = 0;
 
252
                }
 
253
                Scilabgc->horzsi.nPos   = si->nPos;
 
254
                break;
 
255
        default:
 
256
                break;
 
257
        }
 
258
        /* reset clip region after a scroll */
 
259
        set_clip_after_scroll() ;
 
260
        /* ? */  
 
261
        SetScrollInfo(Scilabgc->CWindow, sb_ctl, si, bRedraw);
 
262
        if (sciGetwresize() == 1)
 
263
          si->nMax = inttmp;
 
264
        /* force le rafraichissement de l'affichage des SB !!! */
 
265
        sciGetScrollInfo(Scilabgc, sb_ctl, &totosi);
 
266
        return 0;
 
267
}
 
268
 
 
269
 
 
270
 
 
271
 
 
272
int sciInitScrollBar(struct BCG *Scilabgc)
 
273
{
 
274
  SCROLLINFO si;
 
275
 
 
276
  /* definition des scroll bars verticalles a la creationS*/
 
277
  si.cbSize = sizeof(SCROLLINFO);
 
278
  si.fMask  = SIF_RANGE | SIF_PAGE | SIF_POS;
 
279
  si.nMin   = 0;
 
280
  si.nMax   = Scilabgc->CWindowHeight;
 
281
  si.nPage  = Scilabgc->CWindowHeightView;
 
282
  si.nPos   = 0;
 
283
  sciSetScrollInfo(ScilabXgc,SB_VERT, &si, TRUE);
 
284
 
 
285
  /* definition des scroll bars horizontalles */
 
286
  si.cbSize = sizeof(SCROLLINFO);
 
287
  si.fMask  = SIF_RANGE | SIF_PAGE | SIF_POS;
 
288
  si.nMin   = 0;
 
289
  si.nMax   = Scilabgc->CWindowWidth;
 
290
  si.nPage  = Scilabgc->CWindowWidthView;
 
291
  si.nPos   = 0;
 
292
  sciSetScrollInfo(ScilabXgc,SB_HORZ, &si, TRUE);
 
293
  return 0;
 
294
}
 
295
 
 
296
 
 
297
void  SetWinhdc()
 
298
{
 
299
  if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->CWindow != (Window) 0)
 
300
    {
 
301
      if ( sciGetPixmapStatus() == 1) 
 
302
        hdc = ScilabXgc->hdcCompat;
 
303
      else
 
304
        hdc=GetDC(ScilabXgc->CWindow);
 
305
    }
 
306
}
 
307
 
 
308
int MaybeSetWinhdc()
 
309
{
 
310
  /** a clarifier XXXX faut-il aussi un test **/
 
311
  if ( hdc == (HDC) 0)  
 
312
    {
 
313
      if ( sciGetPixmapStatus() == 1) 
 
314
        hdc = ScilabXgc->hdcCompat;
 
315
      else
 
316
        hdc=GetDC(ScilabXgc->CWindow);
 
317
      return(1);
 
318
    }
 
319
  else 
 
320
    return(0);
 
321
}
 
322
 
 
323
void  ReleaseWinHdc()
 
324
{
 
325
  if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->CWindow != (Window) 0)
 
326
    {
 
327
      if ( sciGetPixmapStatus() != 1) 
 
328
        ReleaseDC(ScilabXgc->CWindow,hdc);
 
329
      hdc = (HDC) 0;
 
330
    }
 
331
}
 
332
 
 
333
/****************************
 
334
 * used when replaying with 
 
335
 * printers or memory hdc 
 
336
 ***************************/
 
337
 
 
338
void SetGHdc(lhdc,width,height)
 
339
     HDC lhdc;
 
340
     int width,height;
 
341
{
 
342
  if ( lhdc != (HDC) 0)
 
343
    {
 
344
      hdc1= hdc ;
 
345
      if ( hdc != (HDC) 0) ReleaseWinHdc();
 
346
      hdc = lhdc;
 
347
      ScilabXgc->CWindowWidth  = width;
 
348
      ScilabXgc->CWindowHeight = height;
 
349
    }
 
350
  else
 
351
    {
 
352
      if ( hdc1 != (HDC) 0 && ScilabXgc != (struct BCG *) 0 
 
353
           && ScilabXgc->CWindow != (Window) 0 )
 
354
        {
 
355
          RECT rect;
 
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;
 
361
        }
 
362
    }
 
363
}
 
364
 
 
365
/** Allocating colors in BCG struct */
 
366
 
 
367
int XgcAllocColors(xgc,m)
 
368
struct BCG *xgc;
 
369
int m;
 
370
{
 
371
  int mm;
 
372
  /* don't forget black and white */
 
373
  mm = m + 2;
 
374
  if (!(xgc->Red = (float *) MALLOC(mm*sizeof(float)))) {
 
375
    Scistring("XgcAllocColors: unable to alloc\n");
 
376
    return 0;
 
377
  }
 
378
  if (!(xgc->Green = (float *) MALLOC(mm*sizeof(float)))) {
 
379
    Scistring("XgcAllocColors: unable to alloc\n");
 
380
    FREE(xgc->Red);
 
381
    return 0;
 
382
  }
 
383
  if (!(xgc->Blue = (float *) MALLOC(mm*sizeof(float)))) {
 
384
    Scistring("XgcAllocColors: unable to alloc\n");
 
385
    FREE(xgc->Red);
 
386
    FREE(xgc->Green);
 
387
    return 0;
 
388
  }
 
389
  if (!(xgc->Colors = (COLORREF *) MALLOC(mm*sizeof(COLORREF)))) {
 
390
    Scistring("XgcAllocColors: unable to alloc\n");
 
391
    FREE(xgc->Red);
 
392
    FREE(xgc->Green);
 
393
    FREE(xgc->Blue);
 
394
    return 0;
 
395
  }
 
396
  return 1;
 
397
}
 
398
 
 
399
int XgcFreeColors(xgc)
 
400
     struct BCG *xgc;
 
401
{
 
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;
 
406
        return(0);
 
407
}
 
408
 
 
409
 
 
410
 
 
411
/** Pixmap routines **/
 
412
 
 
413
void C2F(pixmapclear)(v1, v2, v3, v4)
 
414
     integer *v1;
 
415
     integer *v2;
 
416
     integer *v3;
 
417
     integer *v4;
 
418
{
 
419
  RECT rect;
 
420
  static COLORREF px;
 
421
  HBRUSH hBrush;
 
422
  px = (ScilabXgc->Colors == NULL)? DefaultBackground 
 
423
    :  ScilabXgc->Colors[ScilabXgc->NumBackground];
 
424
  if ( ScilabXgc->hdcCompat)
 
425
    {
 
426
      SetBkColor( ScilabXgc->hdcCompat, px );
 
427
      /*
 
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
 
431
       * GPopupResize()
 
432
       */
 
433
      /* GetClientRect(ScilabXgc->CWindow, &rect); */
 
434
      rect.top    = 0;
 
435
      rect.bottom = ScilabXgc->CWindowHeight;
 
436
      rect.left   = 0;
 
437
      rect.right  = ScilabXgc->CWindowWidth;
 
438
      hBrush = CreateSolidBrush(px);
 
439
      FillRect( ScilabXgc->hdcCompat, &rect,hBrush );
 
440
      DeleteObject(hBrush);
 
441
    }
 
442
}
 
443
 
 
444
void C2F(show)(v1, v2, v3, v4)
 
445
     integer *v1;
 
446
     integer *v2;
 
447
     integer *v3;
 
448
     integer *v4;
 
449
{
 
450
  if ( ScilabXgc->hdcCompat)
 
451
    {
 
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);
 
456
    }
 
457
}
 
458
 
 
459
 
 
460
/** 
 
461
 *  ResiZe the pixmap associated to CWindow and store it 
 
462
 *  back in the window List 
 
463
 **/
 
464
 
 
465
void CPixmapResize(x, y)
 
466
     int x;
 
467
     int y;
 
468
{
 
469
  HDC hdc1;
 
470
  HBITMAP hbmTemp;
 
471
  hdc1=GetDC(ScilabXgc->CWindow);
 
472
  hbmTemp = CreateCompatibleBitmap (hdc1,x,y);
 
473
  ReleaseDC(ScilabXgc->CWindow,hdc1);
 
474
  if (!hbmTemp)
 
475
    {
 
476
      sciprint("Can't resize pixmap\r\n");
 
477
      return;
 
478
    }
 
479
  else
 
480
    {
 
481
      HBITMAP  hbmSave;
 
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);
 
488
    }
 
489
}
 
490
 
 
491
/* 
 
492
   Resize the Pixmap according to window size change 
 
493
   But only if there's a pixmap 
 
494
   */
 
495
 
 
496
void CPixmapResize1()
 
497
{
 
498
  if ( sciGetPixmapStatus() == 1 )
 
499
    {
 
500
      CPixmapResize(ScilabXgc->CWindowWidth,ScilabXgc->CWindowHeight);
 
501
    }
 
502
}
 
503
 
 
504
 
 
505
/*-----------------------------------------------------
 
506
\encadre{General routines}
 
507
-----------------------------------------------------*/
 
508
 
 
509
/** To select (raise on the screen )the current graphic Window  **/
 
510
/** If there's no graphic window then select creates one **/
 
511
 
 
512
void C2F(xselgraphic)(v1, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
 
513
     char *v1;
 
514
     integer *v2;
 
515
     integer *v3;
 
516
     integer *v4;
 
517
     integer *v5;
 
518
     integer *v6;
 
519
     integer *v7;
 
520
     double *dv1;
 
521
     double *dv2;
 
522
     double *dv3;
 
523
     double *dv4;
 
524
 
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);
 
530
}
 
531
 
 
532
/** End of graphic (do nothing)  **/
 
533
 
 
534
void C2F(xendgraphic)()
 
535
{
 
536
 
537
 
 
538
void C2F(xend)(v1, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
 
539
     char *v1;
 
540
     integer *v2;
 
541
     integer *v3;
 
542
     integer *v4;
 
543
     integer *v5;
 
544
     integer *v6;
 
545
     integer *v7;
 
546
     double *dv1;
 
547
     double *dv2;
 
548
     double *dv3;
 
549
     double *dv4;
 
550
{
 
551
  /** Nothing in Windows **/
 
552
}
 
553
 
 
554
/** Clear the current graphic window     **/
 
555
 
 
556
void C2F(clearwindow)(v1, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
 
557
     char *v1;
 
558
     integer *v2,*v3,*v4,*v5,*v6,*v7;
 
559
     double *dv1,*dv2,*dv3,*dv4;
 
560
{
 
561
  RECT rect;
 
562
  static COLORREF px;
 
563
  HBRUSH hBrush;
 
564
  if ( ScilabXgc->ClipRegionSet == 1) 
 
565
     SelectClipRgn(hdc,NULL);
 
566
  if ( sciGetPixmapStatus() == 1) 
 
567
    {
 
568
      C2F(pixmapclear)(PI0,PI0,PI0,PI0);
 
569
      C2F(show)(PI0,PI0,PI0,PI0);      
 
570
    }
 
571
  else
 
572
    {
 
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 */
 
580
          rect.top    = 0;
 
581
          rect.left   = 0;
 
582
          rect.right  = ScilabXgc->CWindowWidth;
 
583
          rect.bottom = ScilabXgc->CWindowHeight;
 
584
      FillRect(hdc, &rect,hBrush );
 
585
      DeleteObject(hBrush);
 
586
    }
 
587
  /* reset the clip region using current data */
 
588
  set_current_clip ();
 
589
}
 
590
 
 
591
 
 
592
/*-----------------------------------------------------------
 
593
 \encadre{To generate a pause, in seconds}
 
594
------------------------------------------------------------*/
 
595
 
 
596
void C2F(xpause)(str, sec_time, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
 
597
     char *str;
 
598
     integer *sec_time;
 
599
     integer *v3;
 
600
     integer *v4;
 
601
     integer *v5;
 
602
     integer *v6;
 
603
     integer *v7;
 
604
     double *dv1;
 
605
     double *dv2;
 
606
     double *dv3;
 
607
     double *dv4;
 
608
 
609
  int ms = (*sec_time)/1000; /** time is specified in microseconds in scilab**/
 
610
  if (ms != 0) Sleep(ms); /* Number of milliseconds to sleep. */
 
611
}
 
612
 
 
613
 
 
614
 
 
615
/*************************************************************
 
616
 * Changes the popupname 
 
617
 *************************************************************/
 
618
 
 
619
void Setpopupname(string)
 
620
     char *string;
 
621
 
622
  /* set the window title if exists */
 
623
  SetWindowText(ScilabXgc->hWndParent, string);
 
624
}
 
625
 
 
626
 
 
627
void C2F(setpopupname)(x0, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
 
628
     char *x0;
 
629
     integer *v2,*v3,*v4,*v5,*v6,*v7;
 
630
     double *dv1,*dv2,*dv3,*dv4;
 
631
{
 
632
  Setpopupname(x0);
 
633
}
 
634
 
 
635
 
 
636
extern void sciSendMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
 
637
extern int  sciPeekMessage(MSG *msg);
 
638
 
 
639
 
 
640
 
 
641
/****************************************************************
 
642
 Wait for mouse click in graphic window 
 
643
   send back mouse location  (x1,y1)  and button number  
 
644
   0,1,2}
 
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
****************************************************************/
 
648
 
 
649
void C2F(xclick_any)(str, ibutton, x1, yy1, iwin, iflag, istr, dv1, dv2, dv3, dv4)
 
650
     char *str;
 
651
     integer *ibutton,*x1,*yy1,*iwin,*iflag,*istr;
 
652
     double *dv1;
 
653
     double *dv2;
 
654
     double *dv3;
 
655
     double *dv4;
 
656
{
 
657
  
 
658
  WindowList *listptr = The_List;
 
659
  /* 
 
660
   * listptr_tmp est utilise pour recuperer les 
 
661
   * events clavier WM_CHAR 
 
662
   */
 
663
  WindowList *listptr_tmp;
 
664
  POINT Point;
 
665
  HWND hwnd_window_pointed;
 
666
  RECT lpRect;
 
667
  Window CW;
 
668
  MSG msg;
 
669
  int buttons = 0,win = 0;
 
670
  integer iwin_tmp = -1;
 
671
  integer lstr ;
 
672
  win = -1;
 
673
  if ( *iflag ==1 && CheckClickQueue(&win,x1,yy1,ibutton) == 1) 
 
674
  {
 
675
      *iwin = win ;
 
676
      return;
 
677
  }
 
678
  if ( *iflag ==0 )  
 
679
                ClearClickQueue(-1);
 
680
 
 
681
  
 
682
  while (buttons == 0) 
 
683
  {
 
684
        int ok =0;
 
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) 
 
689
        {
 
690
                *iwin       = deleted_win;/* utile dans le cas ou une fenetre a ete killee */
 
691
                deleted_win = -1;
 
692
                *x1         = 0;
 
693
                *yy1        = 0;
 
694
                *ibutton    = -100;
 
695
                buttons++;
 
696
                break;
 
697
        }
 
698
    if ( CtrlCHit(&textwin) == 1) 
 
699
    {
 
700
                *x1= 0 ;  *yy1= 0;  *ibutton=0; return ;
 
701
    }
 
702
    /** a loop on all the graphics windows **/
 
703
    listptr = The_List;
 
704
    /** special case the list is empty **/
 
705
    if ( listptr == (WindowList *) 0) 
 
706
    {
 
707
                *x1=0;*yy1=0;*ibutton = -100; return ;
 
708
    }
 
709
    while ( (buttons == 0) && ( listptr != (WindowList  *) 0 ) )
 
710
    {
 
711
                CW = listptr->winxgc.CWindow;
 
712
                *iwin = listptr->winxgc.CurWindow;
 
713
                //listptr =  (WindowList *)listptr->next; relegue a la fin
 
714
                if ( msg.hwnd == CW ) 
 
715
                {
 
716
                    ok = 1;
 
717
                    if (  msg.message == WM_CHAR)
 
718
                        {
 
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)
 
725
                                {
 
726
                                        iwin_tmp = -1;
 
727
                                        listptr_tmp = The_List;
 
728
                                        /* si la liste de fenetre est non vide */
 
729
                                        while (listptr_tmp != (WindowList  *) 0 )
 
730
                                        {
 
731
                                                /* si la fenetre pointee est la fenetre courante liste*/
 
732
                                                if (hwnd_window_pointed == listptr_tmp->winxgc.CWindow)
 
733
                                                {
 
734
                                                        iwin_tmp = listptr_tmp->winxgc.CurWindow;
 
735
                                                        break;
 
736
                                                }
 
737
                                                /* on regarde la fenetre scilab suivante */
 
738
                                                listptr_tmp =  (WindowList *)listptr_tmp->next;
 
739
                                        } /* fin while */
 
740
                                        /* si la fenetre pointee est une fenetre scilab */
 
741
                                        if ( iwin_tmp != -1 )
 
742
                                        {
 
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;
 
748
                                                *iwin = iwin_tmp;
 
749
                                                *ibutton = msg.wParam;
 
750
                                                buttons++;
 
751
                                        //      break;
 
752
                                        } /* fi */
 
753
                                } /* fi (hwnd_window_pointed != NULL)*/
 
754
                                //else                                  
 
755
                                //*ibutton = msg.wParam;
 
756
                                //buttons++;
 
757
                                //break;
 
758
                        } /* fi WM_CHAR */
 
759
                        else if (msg.message == WM_CLOSE)
 
760
                        {
 
761
                                *x1  = 0;
 
762
                                *yy1 = 0;
 
763
                                *ibutton = -100;
 
764
                                buttons++;
 
765
                                //break;
 
766
                        }
 
767
                    else if (msg.message == WM_DESTROY)
 
768
                    {
 
769
                                *x1  = 0;
 
770
                                *yy1 = 0;
 
771
                                *ibutton = -100;
 
772
                                buttons++;
 
773
                                //break;
 
774
                        }
 
775
                    else if (  msg.message == WM_LBUTTONDOWN )
 
776
                        {
 
777
                                *x1 = LOWORD(msg.lParam) + listptr->winxgc.horzsi.nPos;
 
778
                                *yy1= HIWORD(msg.lParam) + listptr->winxgc.vertsi.nPos;
 
779
                                *ibutton = 0;
 
780
                                buttons++;
 
781
                                //break;
 
782
                        }
 
783
                    else if (  msg.message == WM_MBUTTONDOWN )
 
784
                    {
 
785
                                *x1 = LOWORD(msg.lParam) + listptr->winxgc.horzsi.nPos;
 
786
                                *yy1= HIWORD(msg.lParam) + listptr->winxgc.vertsi.nPos;
 
787
                                *ibutton=1;
 
788
                                buttons++;
 
789
                                //break;
 
790
                    }
 
791
                    else if (  msg.message == WM_RBUTTONDOWN )
 
792
                    {
 
793
                                *x1 = LOWORD(msg.lParam) + listptr->winxgc.horzsi.nPos;
 
794
                                *yy1= HIWORD(msg.lParam) + listptr->winxgc.vertsi.nPos;
 
795
                                *ibutton=2; 
 
796
                                buttons++;
 
797
                                //break;
 
798
                        }
 
799
                    else
 
800
                    {
 
801
                                TranslateMessage(&msg);
 
802
                                DispatchMessage(&msg);
 
803
                        }
 
804
                    if ( *istr==1 && C2F(ismenu)()==1 ) 
 
805
                    {
 
806
                                int entry;
 
807
                                C2F(getmen)(str,&lstr,&entry);
 
808
                                *ibutton = -2;
 
809
                                *istr=lstr;
 
810
                                *x1=0;
 
811
                                *yy1=0;
 
812
                                /*iwin=-1;*/
 
813
                                buttons++;
 
814
                                //break;
 
815
                        }
 
816
                } /* if ( msg.hwnd == CW ) */
 
817
                if (buttons == 0)
 
818
                        listptr =  (WindowList *)listptr->next;
 
819
    }/* while ( (buttons == 0) && ( listptr != (WindowList  *) 0 ) ) */
 
820
    if ( ok != 1) 
 
821
    {
 
822
                TranslateMessage(&msg);
 
823
                DispatchMessage(&msg);
 
824
        }
 
825
    } else sciprint("erreur peek\n"); /* fin de PeekMessage */
 
826
 
 
827
  }/* fin de while (buttons == 0) */
 
828
 
 
829
 
 
830
  /* SetCursor(LoadCursor(NULL,IDC_ARROW));  */
 
831
}
 
832
 
 
833
 
 
834
 
 
835
void C2F(xclick)(str, ibutton, x1, yy1, iflag,istr, v7, dv1, dv2, dv3, dv4)
 
836
     char *str;
 
837
     integer *ibutton,*x1,*yy1,*iflag,*istr,*v7;
 
838
     double *dv1;
 
839
     double *dv2;
 
840
     double *dv3;
 
841
     double *dv4;
 
842
{
 
843
  integer lstr ;
 
844
  SciClick(ibutton,x1, yy1,iflag,0,0,*istr,str,&lstr);
 
845
  if ( *istr == 1) 
 
846
    {
 
847
      if (*ibutton == -2) 
 
848
        {
 
849
          /*sciprint("Menu activated %s %d",str,lstr);*/
 
850
          *istr = lstr;
 
851
        }
 
852
      else
 
853
        *istr = 0;
 
854
    }
 
855
}
 
856
 
 
857
void C2F(xgetmouse)(str, ibutton, x1, yy1,iflag, v6, v7, dv1, dv2, dv3, dv4)
 
858
     char *str;
 
859
     integer *ibutton,*x1,*yy1,*iflag,*v6,*v7;
 
860
     double *dv1;
 
861
     double *dv2;
 
862
     double *dv3;
 
863
     double *dv4;
 
864
{
 
865
  SciClick(ibutton,x1, yy1,iflag,1,0,0,(char *) 0,(integer *)0);
 
866
}
 
867
 
 
868
void SciMouseCapture()
 
869
{
 
870
  SetCapture(ScilabXgc->CWindow);
 
871
}
 
872
 
 
873
void SciMouseRelease()
 
874
{
 
875
  ReleaseCapture();
 
876
}
 
877
 
 
878
 
 
879
 
 
880
/*****************************************
 
881
 * general function for mouse click or 
 
882
 * dynamic menu activation 
 
883
 * 
 
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
 *****************************************/
 
890
 
 
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;
 
894
     char *str;
 
895
{
 
896
  int win;
 
897
  MSG msg;
 
898
  /** BOOL flag1= TRUE; **/
 
899
  integer buttons = 0;
 
900
  if ( ScilabXgc == (struct BCG *) 0 || ScilabXgc->CWindow == (Window) 0)
 
901
    {
 
902
      *ibutton = -100;     return;
 
903
    }
 
904
  win = ScilabXgc->CurWindow;
 
905
  if ( *iflag ==1 && CheckClickQueue(&win,x1, yy1,ibutton) == 1)
 
906
  {
 
907
    /* this is performed in CheckClickQueue 
 
908
     * *x1  = *x1  + ScilabXgc->horzsi.nPos;
 
909
     * *yy1 = *yy1 + ScilabXgc->vertsi.nPos;
 
910
     */
 
911
     return;
 
912
  }
 
913
  if ( *iflag ==0 )  ClearClickQueue(ScilabXgc->CurWindow);
 
914
 
 
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);
 
919
  /** 
 
920
    remove the previous click events on the queue 
 
921
    not useful anymore 
 
922
    while (flag1) 
 
923
    flag1= PeekMessage(&msg,ScilabXgc->CWindow,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE);
 
924
    **/
 
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)
 
932
        {
 
933
          *ibutton = -100;     return;
 
934
        }
 
935
      if ( CtrlCHit(&textwin) == 1) 
 
936
        {
 
937
          *x1= 0 ;  *yy1= 0;  *ibutton=0; return;
 
938
        }
 
939
      if ( msg.hwnd == ScilabXgc->CWindow ) 
 
940
        {
 
941
                if (  msg.message == WM_LBUTTONDOWN )
 
942
            {
 
943
              *x1=LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
 
944
              *yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
 
945
              *ibutton=0; 
 
946
              buttons++;
 
947
              break;
 
948
            }
 
949
          else if (  msg.message == WM_MBUTTONDOWN )
 
950
            {
 
951
              *x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
 
952
              *yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
 
953
              *ibutton=1; 
 
954
              buttons++;
 
955
              break;
 
956
            }
 
957
          else if (  msg.message == WM_RBUTTONDOWN )
 
958
            {
 
959
              *x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
 
960
              *yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
 
961
              *ibutton=2; 
 
962
              buttons++;
 
963
              break;
 
964
            }
 
965
          else if ( getmouse == 1 && msg.message == WM_MOUSEMOVE )
 
966
            {
 
967
              *x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
 
968
              *yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
 
969
              *ibutton=-1; /** 0 for left button **/
 
970
              buttons++;
 
971
              break;
 
972
            }
 
973
          else if ( getrelease == 1 &&  msg.message == WM_LBUTTONUP )
 
974
            {
 
975
              *x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
 
976
              *yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
 
977
              *ibutton= -5 ; 
 
978
              buttons++;
 
979
              break;
 
980
            }
 
981
          else if (getrelease == 1 &&  msg.message == WM_MBUTTONUP )
 
982
            {
 
983
              *x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
 
984
              *yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
 
985
              *ibutton= -4 ;
 
986
              buttons++;
 
987
              break;
 
988
            }
 
989
          else if ( getrelease == 1 && msg.message == WM_RBUTTONUP )
 
990
            {
 
991
              *x1 = LOWORD(msg.lParam) + ScilabXgc->horzsi.nPos;
 
992
              *yy1= HIWORD(msg.lParam) + ScilabXgc->vertsi.nPos;
 
993
              *ibutton= -3;
 
994
              buttons++;
 
995
              break;
 
996
            }
 
997
          else
 
998
            {
 
999
              TranslateMessage(&msg);
 
1000
              DispatchMessage(&msg);
 
1001
            }
 
1002
        }
 
1003
      else 
 
1004
        {
 
1005
          TranslateMessage(&msg);
 
1006
          DispatchMessage(&msg);
 
1007
        }
 
1008
      if ( dyn_men == 1 &&  C2F(ismenu)()==1 ) 
 
1009
        {
 
1010
          int entry;
 
1011
          C2F(getmen)(str,lstr,&entry);
 
1012
          *ibutton = -2;
 
1013
          break;
 
1014
        }
 
1015
  }
 
1016
  /** SetCursor(LoadCursor(NULL,IDC_ARROW)); **/
 
1017
}
 
1018
 
 
1019
 
 
1020
 
 
1021
/*------------------------------------------------
 
1022
  \encadre{Clear a rectangle }
 
1023
-------------------------------------------------*/
 
1024
 
 
1025
void C2F(cleararea)(str, x, y, w, h, v6, v7, dv1, dv2, dv3, dv4)
 
1026
     char *str;
 
1027
     integer *x;
 
1028
     integer *y;
 
1029
     integer *w;
 
1030
     integer *h;
 
1031
     integer *v6;
 
1032
     integer *v7;
 
1033
     double *dv1;
 
1034
     double *dv2;
 
1035
     double *dv3;
 
1036
     double *dv4;
 
1037
{
 
1038
  HBRUSH hBrush;
 
1039
  RECT rect;
 
1040
  static COLORREF px;
 
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 **/
 
1050
}
 
1051
 
 
1052
/*---------------------------------------------------------------------
 
1053
\section{Function for graphic context modification}
 
1054
------------------------------------------------------------------------*/
 
1055
 
 
1056
/** to get the window upper-left point coordinates on the screen  **/
 
1057
 
 
1058
void C2F(getwindowpos)(verbose, x, narg,dummy)
 
1059
     integer *verbose;
 
1060
     integer *x;
 
1061
     integer *narg;
 
1062
     double *dummy;
 
1063
{
 
1064
  RECT rect;
 
1065
  GetWindowRect(ScilabXgc->hWndParent,&rect);
 
1066
  *narg = 2;
 
1067
  x[0]=rect.left; x[1] = rect.top;
 
1068
  if (*verbose == 1) 
 
1069
    sciprint("\n ScilabXgc->CWindow position :%d,%d\r\n",x[0],x[1]);
 
1070
}
 
1071
 
 
1072
/** to set the window upper-left point position on the screen **/
 
1073
 
 
1074
void C2F(setwindowpos)(x, y, v3, v4)
 
1075
     integer *x;
 
1076
     integer *y;
 
1077
     integer *v3;
 
1078
     integer *v4;
 
1079
{
 
1080
  SetWindowPos(ScilabXgc->hWndParent,HWND_TOP,*x,*y,0,0,
 
1081
               SWP_NOSIZE | SWP_NOZORDER );
 
1082
}
 
1083
 
 
1084
/** To get the window size **/
 
1085
 
 
1086
void C2F(getwindowdim)(verbose, x, narg,dummy)
 
1087
     integer *verbose;
 
1088
     integer *x;
 
1089
     integer *narg;
 
1090
     double *dummy;
 
1091
{     
 
1092
  *narg = 2;
 
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;
 
1097
  if (*verbose == 1) 
 
1098
    sciprint("\n CWindow dim :%d,%d\r\n",(int) x[0],(int) x[1]);
 
1099
 
1100
 
 
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
 
1105
 *@see: GPopupResize
 
1106
 */
 
1107
void C2F(setwindowdim)(x, y, v3, v4)
 
1108
     integer *x;
 
1109
     integer *y;
 
1110
     integer *v3;
 
1111
     integer *v4;
 
1112
{
 
1113
  RECT rect,rect1;
 
1114
  int xof,yof;
 
1115
  SCROLLINFO vertsi;
 
1116
  SCROLLINFO horzsi;
 
1117
  if (ScilabXgc->CWindow != (Window) NULL) 
 
1118
  {
 
1119
          /* initialisation des variables SCROLLINFO*/
 
1120
          sciGetScrollInfo(ScilabXgc, SB_VERT, &vertsi);
 
1121
          sciGetScrollInfo(ScilabXgc, SB_HORZ, &horzsi);
 
1122
 
 
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;
 
1128
                  vertsi.nPos   = 0;
 
1129
                  horzsi.nPos   = 0;
 
1130
          }
 
1131
 
 
1132
      if (ScilabXgc->CWindowWidthView > ScilabXgc->CWindowWidth)
 
1133
        ScilabXgc->CWindowWidthView = ScilabXgc->CWindowWidth;
 
1134
 
 
1135
      if (ScilabXgc->CWindowHeightView > ScilabXgc->CWindowHeight)
 
1136
        ScilabXgc->CWindowHeightView = ScilabXgc->CWindowHeight;
 
1137
 
 
1138
      if ( sciGetPixmapStatus() == 1 )
 
1139
          {
 
1140
            CPixmapResize(ScilabXgc->CWindowWidth,ScilabXgc->CWindowHeight);
 
1141
          }
 
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)
 
1147
        {
 
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);
 
1154
        }
 
1155
      else
 
1156
        {
 
1157
      SetWindowPos(ScilabXgc->hWndParent,HWND_TOP,0,0,
 
1158
                   ScilabXgc->CWindowWidthView  + xof,
 
1159
                   ScilabXgc->CWindowHeightView + yof,
 
1160
                   SWP_NOMOVE | SWP_NOZORDER );
 
1161
          }
 
1162
      vertsi.nMax   = ScilabXgc->CWindowHeight;
 
1163
      vertsi.nPage  = ScilabXgc->CWindowHeightView;
 
1164
          //vertsi.nPos   = 0;
 
1165
      horzsi.nMax   = ScilabXgc->CWindowWidth;
 
1166
      horzsi.nPage  = ScilabXgc->CWindowWidthView;  
 
1167
          //horzsi.nPos   = 0;
 
1168
          sciSetScrollInfo(ScilabXgc,SB_VERT, &(vertsi), TRUE);
 
1169
      sciSetScrollInfo(ScilabXgc,SB_HORZ, &(horzsi), TRUE);
 
1170
  }
 
1171
}
 
1172
 
 
1173
/** To get the popup  window size **/
 
1174
 
 
1175
void C2F(getpopupdim)(verbose, x, narg,dummy)
 
1176
     integer *verbose;
 
1177
     integer *x;
 
1178
     integer *narg;
 
1179
     double *dummy;
 
1180
{
 
1181
        x[0]= ScilabXgc->CWindowWidthView; 
 
1182
        x[1]= ScilabXgc->CWindowHeightView;
 
1183
        *narg = 2;
 
1184
        if (*verbose == 1) 
 
1185
    sciprint("\n ScilabXgc->CWindow dim :%d,%d\r\n",(int) x[0],(int) x[1]);
 
1186
}
 
1187
 
 
1188
 
 
1189
/**C2F(setpopupdim)
 
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
 
1192
 **/
 
1193
void C2F(setpopupdim)(x, y, v3, v4)
 
1194
     integer *x;
 
1195
     integer *y;
 
1196
     integer *v3;
 
1197
     integer *v4;
 
1198
{
 
1199
  int x1= Min((int) *x, ScilabXgc->CWindowWidth);
 
1200
  int x2= Min((int) *y, ScilabXgc->CWindowHeight);
 
1201
  GPopupResize(ScilabXgc,&x1,&x2);
 
1202
}
 
1203
 
 
1204
 
 
1205
 
 
1206
/** To change the window view  **/
 
1207
void C2F(setviewport)(x, y, v3, v4)
 
1208
     integer *x;
 
1209
     integer *y;
 
1210
     integer *v3;
 
1211
     integer *v4;
 
1212
{
 
1213
  if ( sciGetwresize() == 0) 
 
1214
    SciViewportMove(ScilabXgc,*x,*y);
 
1215
}
 
1216
 
 
1217
 
 
1218
/**C2F(getviewport)
 
1219
 *@description: To get the viewport Upper/Left point Position 
 
1220
 **/
 
1221
void C2F(getviewport)(verbose, x, narg,dummy)
 
1222
     integer *verbose;
 
1223
     integer *x;
 
1224
     integer *narg;
 
1225
     double *dummy;
 
1226
{     
 
1227
  *narg = 2;
 
1228
  if ( sciGetwresize() == 0) 
 
1229
    {   
 
1230
      SciViewportGet(ScilabXgc,x,x+1);
 
1231
    }
 
1232
  else 
 
1233
    { 
 
1234
      x[0]=0;
 
1235
      x[1]=0;
 
1236
    }
 
1237
  if (*verbose == 1) 
 
1238
    sciprint("\n Viewport position:%d,%d\r\n",(int) x[0],(int) x[1]);
 
1239
 
1240
 
 
1241
/********************************************
 
1242
 * select window intnum as the current window 
 
1243
 * window is created if necessary 
 
1244
 ********************************************/
 
1245
void C2F(setcurwin)(intnum, v2, v3, v4)
 
1246
     integer *intnum;
 
1247
     integer *v2;
 
1248
     integer *v3;
 
1249
     integer *v4;
 
1250
 
1251
  struct BCG *bcgk;
 
1252
  bcgk =  ScilabXgc ;
 
1253
  /** send info to menu **/
 
1254
  MenuFixCurrentWin(*intnum);
 
1255
  if ( ScilabXgc == (struct BCG *) 0 ) 
 
1256
    {
 
1257
      /** First entry or no more graphic window **/
 
1258
      C2F(initgraphic)("",intnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
 
1259
    }
 
1260
  else 
 
1261
    {
 
1262
      if ( ScilabXgc->CurWindow != *intnum )
 
1263
        {
 
1264
          SwitchWindow(intnum);
 
1265
        }
 
1266
    }
 
1267
  if ( ScilabXgc == (struct BCG *) 0 && bcgk != (struct BCG *) 0)
 
1268
    {
 
1269
      /** back to previous value **/
 
1270
      ScilabXgc = bcgk ;
 
1271
      MenuFixCurrentWin(bcgk->CurWindow);
 
1272
    }
 
1273
  else 
 
1274
    {
 
1275
      /* update the dimensions   */
 
1276
      RECT rect;
 
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;
 
1283
    }
 
1284
}
 
1285
 
 
1286
 
 
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 
 
1291
*/
 
1292
int SwitchWindow(integer *intnum)
 
1293
{
 
1294
  /** trying to get window *intnum **/
 
1295
  struct BCG *SXgc;
 
1296
  SXgc = GetWindowXgcNumber(*intnum);
 
1297
  if ( SXgc != (struct BCG *) 0 ) 
 
1298
    {
 
1299
      /** releasing previous hdc **/
 
1300
      /** wininfo("quit window %d with alu %d\r\n",
 
1301
               ScilabXgc->CurWindow,
 
1302
               ScilabXgc->CurDrawFunction); 
 
1303
               **/
 
1304
      ReleaseWinHdc();
 
1305
      ScilabXgc = SXgc;
 
1306
      SetWinhdc();
 
1307
      ResetScilabXgc ();
 
1308
      /** wininfo("switching to window %d with alu %d\r\n",*intnum,
 
1309
               ScilabXgc->CurDrawFunction); **/
 
1310
      get_window_scale(*intnum,NULL);
 
1311
    }
 
1312
  else 
 
1313
    {
 
1314
      /** Create window **/
 
1315
      C2F(initgraphic)("",intnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
 
1316
    }
 
1317
        return(0);
 
1318
}
 
1319
 
 
1320
/** Get the id number of the Current Graphic Window **/
 
1321
 
 
1322
 
 
1323
/**
 
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 
 
1328
  **/
 
1329
void C2F(getcurwin)(verbose, intnum, narg,dummy)
 
1330
     integer *verbose;
 
1331
     integer *intnum;
 
1332
     integer *narg;
 
1333
     double *dummy;
 
1334
{
 
1335
  *narg =1 ;
 
1336
  *intnum = (ScilabXgc != (struct BCG *) 0) ? ScilabXgc->CurWindow : 0;
 
1337
  if (*verbose == 1) 
 
1338
    sciprint("\nCurrent Graphic Window :%d\r\n",(int) *intnum);
 
1339
}
 
1340
 
 
1341
/** Set a clip zone (rectangle ) **/
 
1342
 
 
1343
void C2F(setclip)(x, y, w, h)
 
1344
     integer *x;
 
1345
     integer *y;
 
1346
     integer *w;
 
1347
     integer *h;
 
1348
{
 
1349
  ScilabXgc->ClipRegionSet = 1;
 
1350
  ScilabXgc->CurClipRegion[0]= *x;
 
1351
  ScilabXgc->CurClipRegion[1]= *y;
 
1352
  ScilabXgc->CurClipRegion[2]= *w;
 
1353
  ScilabXgc->CurClipRegion[3]= *h;
 
1354
}
 
1355
 
 
1356
 
 
1357
static void set_current_clip()
 
1358
{
 
1359
  HRGN hRgn;
 
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]);    
 
1368
  }
 
1369
  else {
 
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]);    
 
1376
  }
 
1377
  SelectClipRgn(hdc, hRgn);
 
1378
  DeleteObject(hRgn);
 
1379
}
 
1380
 
 
1381
static void set_clip_after_scroll() 
 
1382
{  
 
1383
  HRGN hRgn;
 
1384
  if (ScilabXgc->ClipRegionSet == 1 && sciGetwresize() == 0) 
 
1385
    {
 
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);
 
1393
      DeleteObject(hRgn);
 
1394
    }
 
1395
}
 
1396
 
 
1397
/** unset clip zone **/
 
1398
void C2F(unsetclip)(v1, v2, v3, v4)
 
1399
     integer *v1;
 
1400
     integer *v2;
 
1401
     integer *v3;
 
1402
     integer *v4;
 
1403
{
 
1404
  ScilabXgc->ClipRegionSet = 0;
 
1405
  SelectClipRgn(hdc,NULL);
 
1406
}
 
1407
 
 
1408
/** Get the boundaries of the current clip zone **/
 
1409
void C2F(getclip)(verbose, x, narg,dummy)
 
1410
     integer *verbose;
 
1411
     integer *x;
 
1412
     integer *narg;
 
1413
     double *dummy;
 
1414
{
 
1415
  x[0] = ScilabXgc->ClipRegionSet;
 
1416
  if ( x[0] == 1)
 
1417
    {
 
1418
      *narg = 5;
 
1419
      x[1] =ScilabXgc->CurClipRegion[0];
 
1420
      x[2] =ScilabXgc->CurClipRegion[1];
 
1421
      x[3] =ScilabXgc->CurClipRegion[2];
 
1422
      x[4] =ScilabXgc->CurClipRegion[3];
 
1423
    }
 
1424
  else *narg = 1;
 
1425
  if (*verbose == 1)
 
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]);
 
1432
    else 
 
1433
      Scistring("\nNo Clip Region");
 
1434
}
 
1435
 
 
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)
 
1444
     integer *num;
 
1445
     integer *v2;
 
1446
     integer *v3;
 
1447
     integer *v4;
 
1448
{
 
1449
  if (*num == 0 )
 
1450
    ScilabXgc->CurVectorStyle =  CoordModeOrigin;
 
1451
  else 
 
1452
    ScilabXgc->CurVectorStyle =  CoordModePrevious ;
 
1453
}
 
1454
 
 
1455
/** to get information on absolute or relative mode **/
 
1456
void C2F(getabsourel)(verbose, num, narg,dummy)
 
1457
     integer *verbose;
 
1458
     integer *num;
 
1459
     integer *narg;
 
1460
     double *dummy;
 
1461
{
 
1462
  *narg = 1;
 
1463
  *num = ScilabXgc->CurVectorStyle  ;
 
1464
  if (*verbose == 1) 
 
1465
    if (ScilabXgc->CurVectorStyle == CoordModeOrigin)
 
1466
      Scistring("\nTrace Absolu");
 
1467
    else 
 
1468
      Scistring("\nTrace Relatif");
 
1469
}
 
1470
 
 
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 { 
 
1475
  char *name;
 
1476
  int id;
 
1477
  char *info;} AluStruc_[] =
 
1478
 
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 "}
 
1495
};
 
1496
 
 
1497
 
 
1498
static void idfromname(name1, num)
 
1499
     char *name1;
 
1500
     integer *num;
 
1501
{int i;
 
1502
 *num = -1;
 
1503
 for ( i =0 ; i < 16;i++)
 
1504
   if (strcmp(AluStruc_[i].name,name1)== 0) 
 
1505
     *num=AluStruc_[i].id;
 
1506
 if (*num == -1 ) 
 
1507
   {
 
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,
 
1511
               AluStruc_[i].info);
 
1512
   }
 
1513
}
 
1514
 
 
1515
void C2F(setalufunction)(string)
 
1516
     char *string;
 
1517
{     
 
1518
  integer value;
 
1519
  idfromname(string,&value);
 
1520
  if ( value != -1)
 
1521
    {
 
1522
      SetROP2(hdc,(int) value);
 
1523
      ScilabXgc->CurDrawFunction = value;
 
1524
      set_c(ScilabXgc->CurColor);
 
1525
    }
 
1526
}
 
1527
 
 
1528
void C2F(setalufunction1)(num, v2, v3, v4)
 
1529
     integer *num;
 
1530
     integer *v2;
 
1531
     integer *v3;
 
1532
     integer *v4;
 
1533
{     
 
1534
  int value;
 
1535
  ScilabXgc->CurDrawFunction = Min(15,Max(0,*num));
 
1536
  value=AluStruc_[ScilabXgc->CurDrawFunction].id;
 
1537
  SetROP2(hdc,(int) value);
 
1538
  if ( ScilabXgc->CurColorStatus == 1 )
 
1539
    {
 
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);
 
1544
    }
 
1545
}
 
1546
 
 
1547
void C2F(getalufunction)(verbose, value, narg,dummy)
 
1548
     integer *verbose;
 
1549
     integer *value;
 
1550
     integer *narg;
 
1551
     double *dummy;
 
1552
 
1553
  *narg =1 ;
 
1554
  *value = ScilabXgc->CurDrawFunction ;
 
1555
  if (*verbose ==1 ) 
 
1556
    { 
 
1557
      sciprint("\nThe Alufunction is %s -> <%s>\r\n",
 
1558
              AluStruc_[*value].name,
 
1559
              AluStruc_[*value].info);}
 
1560
}
 
1561
 
 
1562
 
 
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)
 
1568
     integer *value;
 
1569
     integer *v2;
 
1570
     integer *v3;
 
1571
     integer *v4;
 
1572
 
1573
  HPEN hpen ;
 
1574
  ScilabXgc->CurLineWidth =Max(0, *value);
 
1575
  if ( ScilabXgc->CurColorStatus == 1 ) 
 
1576
    {
 
1577
      COLORREF px = DefaultForeground ;
 
1578
      if (ScilabXgc->Colors != NULL) 
 
1579
        {
 
1580
          if ( ScilabXgc->CurDrawFunction !=  GXxor )
 
1581
            px= ScilabXgc->Colors[ScilabXgc->CurColor];
 
1582
          else 
 
1583
            px = ScilabXgc->Colors[ScilabXgc->CurColor] 
 
1584
              ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
 
1585
        }
 
1586
      hpen = CreatePen(PS_SOLID,ScilabXgc->CurLineWidth,px);
 
1587
    }
 
1588
  else 
 
1589
    {
 
1590
      int width;
 
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));
 
1595
    }
 
1596
  SelectObject(hdc,hpen);
 
1597
  if ( ScilabXgc->hPen != (HPEN) 0 ) DeleteObject(ScilabXgc->hPen);
 
1598
  ScilabXgc->hPen = hpen;
 
1599
}
 
1600
 
 
1601
/** to get the thickness value **/
 
1602
 
 
1603
void C2F(getthickness)(verbose, value, narg,dummy)
 
1604
     integer *verbose;
 
1605
     integer *value;
 
1606
     integer *narg;
 
1607
     double *dummy;
 
1608
{
 
1609
  *narg =1 ;
 
1610
  *value = ScilabXgc->CurLineWidth ;
 
1611
  if (*verbose ==1 ) 
 
1612
    sciprint("\nLine Width:%d\r\n", ScilabXgc->CurLineWidth ) ;
 
1613
}
 
1614
 
 
1615
/** To set grey level for filing areas **/
 
1616
/** from black (*num =0 ) to white     **/
 
1617
 
 
1618
#define GREYNUMBER 17
 
1619
/** maybe not so useful ???? XXXX **/
 
1620
 
 
1621
HBRUSH Tabpix_[GREYNUMBER];
 
1622
 
 
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},
 
1641
};
 
1642
 
 
1643
 
 
1644
void C2F(CreatePatterns)()
 
1645
 
1646
  integer i ;
 
1647
  for ( i=0 ; i < GREYNUMBER ; i++)
 
1648
    {
 
1649
      HBITMAP hBitmap;
 
1650
      hBitmap = CreateBitmap(8,8,1,1,grey0[i]);
 
1651
      Tabpix_[i] =CreatePatternBrush(hBitmap);
 
1652
      DeleteObject(hBitmap);
 
1653
    }
 
1654
}
 
1655
 
 
1656
void C2F(setpattern)(num, v2, v3, v4)
 
1657
     integer *num;
 
1658
     integer *v2;
 
1659
     integer *v3;
 
1660
     integer *v4;
 
1661
{ integer i ; 
 
1662
  if ( ScilabXgc->CurColorStatus == 1 ) 
 
1663
    {
 
1664
      set_c(*num-1);
 
1665
    }
 
1666
  else 
 
1667
    {
 
1668
      i= Max(0,Min(*num-1,GREYNUMBER-1));
 
1669
      ScilabXgc->CurPattern = i;
 
1670
      SelectObject(hdc,Tabpix_[i]);
 
1671
    }
 
1672
}
 
1673
 
 
1674
/** To get the id of the current pattern  **/
 
1675
void C2F(getpattern)(verbose, num, narg,dummy)
 
1676
     integer *verbose;
 
1677
     integer *num;
 
1678
     integer *narg;
 
1679
     double *dummy;
 
1680
 
1681
  *narg=1;
 
1682
  if ( ScilabXgc->CurColorStatus == 1 ) 
 
1683
    *num = ScilabXgc->CurColor +1 ;
 
1684
  else 
 
1685
    *num = ScilabXgc->CurPattern +1 ;
 
1686
  if (*verbose == 1) 
 
1687
    sciprint("\n Pattern : %d\r\n",ScilabXgc->CurPattern+1);
 
1688
}
 
1689
 
 
1690
/** To get the id of the last pattern **/
 
1691
void C2F(getlast)(verbose, num, narg,dummy)
 
1692
     integer *verbose;
 
1693
     integer *num;
 
1694
     integer *narg;
 
1695
     double *dummy;
 
1696
{
 
1697
  if ( ScilabXgc->CurColorStatus == 1 ) 
 
1698
    {
 
1699
      *num = ScilabXgc->IDLastPattern + 1;
 
1700
      if (*verbose == 1) 
 
1701
        sciprint("\n Id of Last Color %d\r\n",(int)*num);
 
1702
    }
 
1703
  else 
 
1704
    {
 
1705
      *num = ScilabXgc->IDLastPattern + 1;
 
1706
      if (*verbose == 1) 
 
1707
        sciprint("\n Id of Last Pattern %d\r\n",(int)*num);
 
1708
    }
 
1709
  *narg=1;
 
1710
}
 
1711
 
 
1712
/*--------------------------------------
 
1713
\encadre{Line style }
 
1714
---------------------------------------*/
 
1715
 
 
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 **/
 
1721
 
 
1722
/* old version of setdash retained for compatibility */
 
1723
void C2F(set_dash_or_color)(value, v2, v3, v4)
 
1724
     integer *value;
 
1725
     integer *v2;
 
1726
     integer *v3;
 
1727
     integer *v4;
 
1728
{
 
1729
  if ( ScilabXgc->CurColorStatus == 1) 
 
1730
    {
 
1731
      set_c(*value-1);
 
1732
    }
 
1733
  else
 
1734
    C2F(setdash)(value, v2, v3, v4);
 
1735
}
 
1736
 
 
1737
void C2F(setdash)(value, v2, v3, v4)
 
1738
     integer *value;
 
1739
     integer *v2;
 
1740
     integer *v3;
 
1741
     integer *v4;
 
1742
{
 
1743
  static integer l3 ;
 
1744
  COLORREF col ;
 
1745
  HPEN hpen;
 
1746
  int id,width;
 
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];
 
1754
    else 
 
1755
      col = ScilabXgc->Colors[id] ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
 
1756
  }
 
1757
  else
 
1758
    col=RGB(0,0,0);
 
1759
 
 
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;
 
1765
}
 
1766
 
 
1767
static void C2F(set_dash_and_color)(value, v2, v3, v4)
 
1768
     integer *value;
 
1769
     integer *v2;
 
1770
     integer *v3;
 
1771
     integer *v4;
 
1772
{
 
1773
  C2F(setdash)(value, v2, v3, v4);
 
1774
  C2F(setpattern)(value+6, v2, v3, v4);
 
1775
}
 
1776
 
 
1777
static void C2F(set_line_style)(value, v2, v3, v4)
 
1778
     integer *value;
 
1779
     integer *v2;
 
1780
     integer *v3;
 
1781
     integer *v4;
 
1782
{
 
1783
  integer j;
 
1784
  if (ScilabXgc->CurColorStatus == 0) 
 
1785
    C2F(setdash)(value,PI0,PI0,PI0);
 
1786
  else {
 
1787
    j= ScilabXgc->CurDashStyle + 1;
 
1788
    C2F(setdash)(&j,PI0,PI0,PI0);
 
1789
    C2F(setpattern)(value,PI0,PI0,PI0);
 
1790
  }
 
1791
}
 
1792
 
 
1793
 
 
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)
 
1797
     integer *verbose;
 
1798
     integer *value;
 
1799
     integer *narg;
 
1800
     double *dummy; 
 
1801
{
 
1802
 
 
1803
 if ( ScilabXgc->CurColorStatus == 1) 
 
1804
   {
 
1805
     *narg =1 ;
 
1806
     *value =ScilabXgc->CurColor+1;
 
1807
     if (*verbose == 1) sciprint("Color %d",(int)*value);
 
1808
     return;
 
1809
   }
 
1810
 C2F(getdash)(verbose, value, narg,dummy);
 
1811
}
 
1812
 
 
1813
void C2F(getdash)(verbose, value, narg,dummy)
 
1814
     integer *verbose;
 
1815
     integer *value;
 
1816
     integer *narg;
 
1817
     double *dummy; 
 
1818
{
 
1819
 *narg =1 ;
 
1820
 *value =ScilabXgc->CurDashStyle+1;
 
1821
 if ( *verbose == 1) 
 
1822
   {
 
1823
     switch ( *value )
 
1824
       {
 
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 ;
 
1830
       }
 
1831
   }
 
1832
}
 
1833
static void C2F(get_dash_and_color)(verbose, value, narg,dummy)
 
1834
     integer *verbose;
 
1835
     integer *value;
 
1836
     integer *narg;
 
1837
     double *dummy;
 
1838
{
 
1839
/*may be improved replacing 6 by narg */
 
1840
  C2F(getdash)(verbose, value, narg,dummy);
 
1841
  C2F(getpattern)(verbose, value+6, narg,dummy);
 
1842
  *narg = 6;
 
1843
}
 
1844
 
 
1845
/* basculement eventuel de couleur a n&b */
 
1846
void C2F(usecolor)(num, v1, v2, v3)
 
1847
     integer *num;
 
1848
     integer *v1;
 
1849
     integer *v2;
 
1850
     integer *v3;
 
1851
{
 
1852
  integer i;
 
1853
  i =  Min(Max(*num,0),1);
 
1854
  if ( ScilabXgc->CurColorStatus != (int) i) 
 
1855
    {
 
1856
      if (ScilabXgc->CurColorStatus == 1) 
 
1857
        {
 
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;
 
1869
        }
 
1870
      else 
 
1871
        {
 
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;
 
1883
        }
 
1884
    }
 
1885
}
 
1886
 
 
1887
void C2F(getusecolor)(verbose, num, narg,dummy)
 
1888
     integer *verbose;
 
1889
     integer *num;
 
1890
     integer *narg;
 
1891
     double *dummy;
 
1892
{
 
1893
  *num = ScilabXgc->CurColorStatus;
 
1894
  if (*verbose == 1) 
 
1895
    sciprint("\n Use color %d\r\n",(int)*num);
 
1896
  *narg=1;
 
1897
}
 
1898
 
 
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)
 
1902
     integer *num;
 
1903
     integer *v2;
 
1904
     integer *v3;
 
1905
     integer *v4;
 
1906
{
 
1907
  integer num1= Min(Max(*num,0),1);
 
1908
  if ( sciGetPixmapStatus() == num1 ) return;
 
1909
  if ( num1 == 1 )
 
1910
    {
 
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)
 
1915
        {
 
1916
          sciprint("Seeting pixmap on is impossible \r\n");
 
1917
          return;
 
1918
        }
 
1919
      else
 
1920
        {
 
1921
          HBITMAP hbmTemp ;
 
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);
 
1928
          /* ajout */
 
1929
          if (!hbmTemp)
 
1930
            {
 
1931
              sciprint("Seeting pixmap on is impossible \r\n");
 
1932
              return;
 
1933
            }
 
1934
          else
 
1935
            {
 
1936
              HBITMAP  hbmSave;
 
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);
 
1946
              ResetScilabXgc ();
 
1947
              SetGHdc((HDC)0,ScilabXgc->CWindowWidth,
 
1948
                       ScilabXgc->CWindowHeight);
 
1949
                  /* ajout */
 
1950
              C2F(show)(PI0,PI0,PI0,PI0);
 
1951
            }
 
1952
        }
 
1953
    }
 
1954
  if ( num1 == 0 )
 
1955
    {
 
1956
      /** I remove the Background Pixmap to the window **/
 
1957
      ScilabXgc->CurPixmapStatus = 0;
 
1958
      /** XXXX **/
 
1959
      if ( ScilabXgc->hdcCompat)
 
1960
        SelectObject (ScilabXgc->hdcCompat, NULL) ;
 
1961
      if ( ScilabXgc->hbmCompat)
 
1962
        DeleteObject (ScilabXgc->hbmCompat);
 
1963
      if ( ScilabXgc->hdcCompat)
 
1964
        {
 
1965
          if ( hdc == ScilabXgc->hdcCompat)
 
1966
            hdc=GetDC(ScilabXgc->CWindow);
 
1967
          DeleteDC(ScilabXgc->hdcCompat);
 
1968
        }
 
1969
      ScilabXgc->hbmCompat = (HBITMAP) 0;
 
1970
      ScilabXgc->hdcCompat = (HDC) 0;
 
1971
    }
 
1972
}
 
1973
 
 
1974
void C2F(getpixmapOn)(verbose, value, narg,dummy)
 
1975
     integer *verbose;
 
1976
     integer *value;
 
1977
     integer *narg;
 
1978
     double *dummy;
 
1979
{
 
1980
 
 
1981
  *value=sciGetPixmapStatus();
 
1982
  *narg =1 ;
 
1983
  if (*verbose == 1) sciprint("Color %d",(int)*value);
 
1984
}
 
1985
 
 
1986
 
 
1987
integer sciGetPixmapStatus()
 
1988
{
 
1989
        return ScilabXgc->CurPixmapStatus;
 
1990
}
 
1991
 
 
1992
/** Change the status of a Graphic Window **/
 
1993
/** follow or dont follow the viewport resize  **/
 
1994
 
 
1995
void C2F(setwresize)(num, v2, v3, v4)
 
1996
     integer *num;
 
1997
     integer *v2;
 
1998
     integer *v3;
 
1999
     integer *v4;
 
2000
{
 
2001
  integer num1= Min(Max(*num,0),1);
 
2002
  integer xtmp=0;
 
2003
  integer ytmp=0;
 
2004
 
 
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);
 
2011
}
 
2012
 
 
2013
void C2F(getwresize)(verbose, value, narg,dummy)
 
2014
     integer *verbose;
 
2015
     integer *value;
 
2016
     integer *narg;
 
2017
     double *dummy;
 
2018
{
 
2019
  *value = sciGetwresize();
 
2020
  *narg =1 ;
 
2021
  if (*verbose == 1) sciprint("Resize status %d",(int)*value);
 
2022
}
 
2023
 
 
2024
 
 
2025
 
 
2026
/*
 
2027
 * Cette fonction renvoie le status wresize
 
2028
 */
 
2029
integer sciGetwresize()
 
2030
{
 
2031
         return ScilabXgc->CurResizeStatus;
 
2032
}
 
2033
 
 
2034
 
 
2035
 
 
2036
 
 
2037
static int set_default_colormap_flag = 1;
 
2038
 
 
2039
int C2F(sedeco)(flag) 
 
2040
     int *flag;
 
2041
{
 
2042
  set_default_colormap_flag = *flag;
 
2043
  return(0);
 
2044
}
 
2045
 
 
2046
 
 
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',...) */
 
2050
 
 
2051
void set_default_colormap()
 
2052
{
 
2053
  int i,m;
 
2054
  unsigned long maxcol;
 
2055
  COLORREF *c;
 
2056
  float *r, *g, *b;
 
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);
 
2065
 
 
2066
  /* we don't want to set the default colormap at window creation 
 
2067
     if the scilab command was xset("colormap"); */
 
2068
 
 
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",
 
2072
             maxcol);
 
2073
    return;
 
2074
  }
 
2075
  m = DEFAULTNUMCOLORS;
 
2076
 
 
2077
  /* Save old color vectors */
 
2078
  c = ScilabXgc->Colors;
 
2079
  r = ScilabXgc->Red;
 
2080
  g = ScilabXgc->Green;
 
2081
  b = ScilabXgc->Blue;
 
2082
 
 
2083
  if (!XgcAllocColors(ScilabXgc,m)) {
 
2084
    ScilabXgc->Colors = c;
 
2085
    ScilabXgc->Red = r;
 
2086
    ScilabXgc->Green = g;
 
2087
    ScilabXgc->Blue = b;
 
2088
    return;
 
2089
  }
 
2090
 
 
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]);
 
2099
  }
 
2100
  /* Black */
 
2101
  ScilabXgc->Red[m] = ScilabXgc->Green[m] =   ScilabXgc->Blue[m] =(float) 0;
 
2102
  ScilabXgc->Colors[m]= RGB(0,0,0);
 
2103
 
 
2104
  /* White */
 
2105
  ScilabXgc->Red[m+1] =   ScilabXgc->Green[m+1] =   ScilabXgc->Blue[m+1] = (float)1;
 
2106
  ScilabXgc->Colors[m+1]= RGB(255,255,255);
 
2107
 
 
2108
  ScilabXgc->Numcolors = m;
 
2109
  ScilabXgc->IDLastPattern = m - 1;
 
2110
  ScilabXgc->CmapFlag = 1;
 
2111
  /* Black and white pixels */
 
2112
 
 
2113
  ScilabXgc->NumForeground = m;
 
2114
  ScilabXgc->NumBackground = m + 1;
 
2115
  FREE(c); FREE(r); FREE(g); FREE(b);
 
2116
}
 
2117
 
 
2118
/* Setting the colormap 
 
2119
   a must be a m x 3 double RGB matrix: 
 
2120
     a[i] = RED
 
2121
     a[i+m] = GREEN
 
2122
     a[i+2*m] = BLUE
 
2123
     *v2 gives the value of m and *v3 must be equal to 3 */
 
2124
 
 
2125
void C2F(setcolormap)(v1,v2,v3,v4,v5,v6,a)
 
2126
     integer *v1,*v2;
 
2127
     integer *v3;
 
2128
     integer *v4,*v5,*v6;
 
2129
     double *a;
 
2130
{
 
2131
  int i,palstatus ,m;
 
2132
  unsigned long maxcol;
 
2133
  COLORREF  *c;
 
2134
  float *r, *g, *b;
 
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); **/
 
2144
 
 
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);
 
2147
    return;
 
2148
  }
 
2149
  m = *v1;
 
2150
 
 
2151
  /* Save old color vectors */
 
2152
  c = ScilabXgc->Colors;
 
2153
  r = ScilabXgc->Red;
 
2154
  g = ScilabXgc->Green;
 
2155
  b = ScilabXgc->Blue;
 
2156
 
 
2157
  if (!XgcAllocColors(ScilabXgc,m)) {
 
2158
    ScilabXgc->Colors = c;
 
2159
    ScilabXgc->Red = r;
 
2160
    ScilabXgc->Green = g;
 
2161
    ScilabXgc->Blue = b;
 
2162
    return;
 
2163
  }
 
2164
 
 
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;
 
2171
      ScilabXgc->Red = r;
 
2172
      ScilabXgc->Green = g;
 
2173
      ScilabXgc->Blue = b;
 
2174
      return;
 
2175
    }
 
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]));
 
2182
  }
 
2183
  /* Black */
 
2184
  ScilabXgc->Red[m] = ScilabXgc->Green[m] =  ScilabXgc->Blue[m] = (float) 0;
 
2185
  ScilabXgc->Colors[m]= RGB(0,0,0);
 
2186
 
 
2187
  /* White */
 
2188
  ScilabXgc->Red[m+1] =  ScilabXgc->Green[m+1] =  ScilabXgc->Blue[m+1] = (float) 0;
 
2189
  ScilabXgc->Colors[m+1]= RGB(255,255,255);
 
2190
 
 
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);
 
2203
}
 
2204
 
 
2205
/*** unfinished : a version with palettes **/
 
2206
 
 
2207
void C2F(pal_setcolormap)(v1,v2,v3,v4,v5,v6,a)
 
2208
     integer *v1,*v2;
 
2209
     integer *v3;
 
2210
     integer *v4,*v5,*v6;
 
2211
     double *a;
 
2212
{
 
2213
  int i,m,maxcol;
 
2214
  COLORREF  *c;
 
2215
  float *r, *g, *b;
 
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);
 
2222
 
 
2223
  if (*v2 != 3 || *v1 > maxcol || *v1 < 0) {
 
2224
    sciprint("Colormap must be a m x 3 array with m <= %d\r\n",maxcol);
 
2225
    return;
 
2226
  }
 
2227
  m = *v1;
 
2228
 
 
2229
  /* Save old color vectors */
 
2230
  c = ScilabXgc->Colors;
 
2231
  r = ScilabXgc->Red;
 
2232
  g = ScilabXgc->Green;
 
2233
  b = ScilabXgc->Blue;
 
2234
 
 
2235
  if (!XgcAllocColors(ScilabXgc,m)) {
 
2236
    ScilabXgc->Colors = c;
 
2237
    ScilabXgc->Red = r;
 
2238
    ScilabXgc->Green = g;
 
2239
    ScilabXgc->Blue = b;
 
2240
    return;
 
2241
  }
 
2242
 
 
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;
 
2249
      ScilabXgc->Red = r;
 
2250
      ScilabXgc->Green = g;
 
2251
      ScilabXgc->Blue = b;
 
2252
      return;
 
2253
    }
 
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]));
 
2260
  }
 
2261
  /* Black */
 
2262
  ScilabXgc->Red[m] = ScilabXgc->Green[m] =  ScilabXgc->Blue[m] = (float) 0;
 
2263
  ScilabXgc->Colors[m]= RGB(0,0,0);
 
2264
 
 
2265
  /* White */
 
2266
  ScilabXgc->Red[m+1] =  ScilabXgc->Green[m+1] =  ScilabXgc->Blue[m+1] = (float) 0;
 
2267
  ScilabXgc->Colors[m+1]= RGB(255,255,255);
 
2268
 
 
2269
  if ((GetDeviceCaps(hdc, RASTERCAPS)) & RC_PALETTE )
 
2270
    {
 
2271
      if ( SciPalette(m) == FALSE )
 
2272
          {
 
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]));
 
2277
            }
 
2278
            ScilabXgc->Colors[m]= RGB(0,0,0);
 
2279
            ScilabXgc->Colors[m+1]= RGB(255,255,255);
 
2280
          }
 
2281
    }
 
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);
 
2295
}
 
2296
 
 
2297
 
 
2298
static BOOL SciPalette(int iNumClr)
 
2299
{
 
2300
  static HPALETTE hPal=NULL;
 
2301
  LOGPALETTE    *plogPal;
 
2302
  UINT          uiSizPal;
 
2303
  INT           i;
 
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");
 
2307
      hPal = NULL;
 
2308
      return FALSE;
 
2309
  }
 
2310
  plogPal->palVersion = 0x300;
 
2311
  plogPal->palNumEntries = (WORD) iNumClr;
 
2312
 
 
2313
  for (i=0; i<iNumClr; i++) 
 
2314
    {
 
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);
 
2322
    }
 
2323
 
 
2324
  if ( hPal != (HPALETTE) NULL) DeleteObject(hPal);
 
2325
  hPal = CreatePalette((LPLOGPALETTE)plogPal);
 
2326
  if ((hPal) == NULL) {
 
2327
      sciprint("Fail in creating palette!\r\n");
 
2328
      return FALSE;
 
2329
  }
 
2330
  SelectPalette(hdc, hPal, FALSE);
 
2331
  RealizePalette(hdc);
 
2332
  /** UpdateColors(hdc) **/
 
2333
  GlobalFree(plogPal);
 
2334
  return TRUE;
 
2335
}
 
2336
 
 
2337
 
 
2338
/* getting the colormap */
 
2339
 
 
2340
void C2F(getcolormap)(verbose,num,narg,val)
 
2341
     integer *verbose;
 
2342
     integer *num;
 
2343
     integer *narg;
 
2344
     double *val;
 
2345
{
 
2346
  int m = ScilabXgc->Numcolors;
 
2347
  int i;
 
2348
  *narg = 1;
 
2349
  *num = m;
 
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];
 
2354
  }
 
2355
  if (*verbose == 1) {
 
2356
    sciprint("Size of colormap: %d colors\r\n",m);
 
2357
  }
 
2358
}
 
2359
 
 
2360
 
 
2361
/** set and get the number of the background or foreground */
 
2362
 
 
2363
void C2F(setbackground)(num, v2, v3, v4)
 
2364
     integer *num;
 
2365
     integer *v2;
 
2366
     integer *v3;
 
2367
     integer *v4;
 
2368
{
 
2369
  if (ScilabXgc->CurColorStatus == 1)
 
2370
    {
 
2371
      COLORREF px;
 
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];
 
2376
      /** A finir XXXX 
 
2377
              if (ScilabXgc->Cdrawable != (Drawable) ScilabXgc->CWindow ) 
 
2378
        {
 
2379
          XSetWindowBackground(dpy, ScilabXgc->CWindow,px);
 
2380
        }
 
2381
        **/
 
2382
    }
 
2383
}
 
2384
void C2F(getbackground)(verbose, num, narg,dummy)
 
2385
     integer *verbose;
 
2386
     integer *num;
 
2387
     integer *narg;
 
2388
     double *dummy;
 
2389
{
 
2390
  *narg=1;
 
2391
  if ( ScilabXgc->CurColorStatus == 1 )
 
2392
    {
 
2393
      *num = ScilabXgc->NumBackground + 1;
 
2394
    }
 
2395
  else
 
2396
    {
 
2397
      *num = 1;
 
2398
    }
 
2399
  if (*verbose == 1)
 
2400
    sciprint("\n Background : %d\r\n",*num);
 
2401
}
 
2402
 
 
2403
 
 
2404
/** set and get the number of the background or foreground */
 
2405
 
 
2406
void C2F(setforeground)(num, v2, v3, v4)
 
2407
     integer *num;
 
2408
     integer *v2;
 
2409
     integer *v3;
 
2410
     integer *v4;
 
2411
{
 
2412
  if (ScilabXgc->CurColorStatus == 1)
 
2413
    {
 
2414
      COLORREF px;
 
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];
 
2419
      /** XX inutile **/
 
2420
    }
 
2421
}
 
2422
 
 
2423
 
 
2424
void C2F(getforeground)(verbose, num, narg,dummy)
 
2425
     integer *verbose;
 
2426
     integer *num;
 
2427
     integer *narg;
 
2428
     double *dummy;
 
2429
{
 
2430
  *narg=1;
 
2431
  if ( ScilabXgc->CurColorStatus == 1 )
 
2432
    {
 
2433
      *num = ScilabXgc->NumForeground + 1;
 
2434
    }
 
2435
  else
 
2436
    {
 
2437
      *num =  1; /** the foreground is a solid line style in b&w */
 
2438
    }
 
2439
  if (*verbose == 1)
 
2440
    sciprint("\n Foreground : %d\r\n",*num);
 
2441
}
 
2442
 
 
2443
/** set and get the number of the hidden3d color */
 
2444
 
 
2445
void C2F(sethidden3d)(num, v2, v3, v4)
 
2446
     integer *num;
 
2447
     integer *v2;
 
2448
     integer *v3;
 
2449
     integer *v4;
 
2450
{
 
2451
  if (ScilabXgc->CurColorStatus == 1)
 
2452
    {
 
2453
      ScilabXgc->NumHidden3d = Max(0,Min(*num - 1,ScilabXgc->Numcolors + 1));
 
2454
    }
 
2455
}
 
2456
 
 
2457
void C2F(gethidden3d)(verbose, num, narg,dummy)
 
2458
     integer *verbose;
 
2459
     integer *num;
 
2460
     integer *narg;
 
2461
     double *dummy;
 
2462
{
 
2463
  *narg=1;
 
2464
  if ( ScilabXgc->CurColorStatus == 1 )
 
2465
    {
 
2466
      *num = ScilabXgc->NumHidden3d + 1;
 
2467
    }
 
2468
  else
 
2469
    {
 
2470
      *num = 1; /** the hidden3d is a solid line style in b&w */
 
2471
    }
 
2472
  if (*verbose == 1)
 
2473
    sciprint("\n Hidden3d : %d\r\n",*num);
 
2474
}
 
2475
 
 
2476
 
 
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
 
2481
 * else return 0 
 
2482
 *****************************************************/
 
2483
 
 
2484
 
 
2485
int CheckColormap(m)
 
2486
     int *m;
 
2487
{
 
2488
  if (  ScilabXgc != (struct BCG *) 0 )
 
2489
    {
 
2490
      *m =  ScilabXgc->Numcolors;
 
2491
      if ( ScilabXgc->CmapFlag  != 1) 
 
2492
        return 1;
 
2493
      else 
 
2494
        return 0;
 
2495
    }
 
2496
  else {
 
2497
    *m=0;
 
2498
    return(0);}
 
2499
}
 
2500
 
 
2501
void get_r(i,r) 
 
2502
     int i;
 
2503
     float *r;
 
2504
{
 
2505
  *r = ScilabXgc->Red[i];
 
2506
}
 
2507
 
 
2508
void get_g(i,g) 
 
2509
     int i;
 
2510
     float *g;
 
2511
{
 
2512
  *g = ScilabXgc->Green[i];
 
2513
}
 
2514
void get_b(i,b) 
 
2515
     float *b;
 
2516
     int i;
 
2517
{
 
2518
  *b = ScilabXgc->Blue[i];
 
2519
}
 
2520
 
 
2521
 
 
2522
/*-----------------------------------------------------------
 
2523
  \encadre{general routines accessing the  set<> or get<>
 
2524
  routines } 
 
2525
-------------------------------------------------------------*/
 
2526
 
 
2527
static void InitMissileXgc();
 
2528
 
 
2529
 
 
2530
void C2F(sempty)(verbose, v2, v3, v4)
 
2531
     integer *verbose;
 
2532
     integer *v2;
 
2533
     integer *v3;
 
2534
     integer *v4;
 
2535
{
 
2536
  if ( *verbose ==1 ) Scistring("\n No operation ");
 
2537
}
 
2538
 
 
2539
void C2F(gempty)(verbose, v2, v3,dummy)
 
2540
     integer *verbose;
 
2541
     integer *v2;
 
2542
     integer *v3;
 
2543
         double *dummy;
 
2544
{
 
2545
  if ( *verbose ==1 ) Scistring("\n No operation ");
 
2546
}
 
2547
 
 
2548
#define NUMSETFONC 28
 
2549
 
 
2550
/** Table in lexicographic order **/
 
2551
 
 
2552
static struct bgc { char *name ;
 
2553
             void  (*setfonc )() ;
 
2554
             void  (*getfonc )() ;}
 
2555
 
 
2556
MissileGCTab_[] = {
 
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)}
 
2585
  };
 
2586
 
 
2587
#ifdef lint 
 
2588
 
 
2589
/* pour forcer lint a verifier ca */
 
2590
 
 
2591
static 
 
2592
test(str,flag,verbose,x1,x2,x3,x4,x5)
 
2593
     char str[];
 
2594
     integer flag ;
 
2595
     integer  *verbose,*x1,*x2,*x3,*x4,*x5;
 
2596
 
2597
double *dv;
 
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);
 
2616
}
 
2617
 
 
2618
#endif 
 
2619
 
 
2620
void C2F(MissileGCget)(str, verbose, x1, x2, x3, x4, x5,dv1, dv2, dv3, dv4)
 
2621
     char *str; 
 
2622
     integer *verbose;
 
2623
     integer *x1; integer *x2; integer *x3; integer *x4;
 
2624
     integer *x5; double *dv1; double *dv2; double *dv3; double *dv4;
 
2625
 
2626
  int x6=0;
 
2627
  C2F(MissileGCGetorSet)(str,1L,verbose,x1,x2,x3,x4,x5,&x6,dv1);
 
2628
}
 
2629
 
 
2630
void C2F(MissileGCset)(str, x1, x2, x3, x4, x5, x6, dv1, dv2, dv3, dv4)
 
2631
     char *str;
 
2632
     integer *x1;
 
2633
     integer *x2;
 
2634
     integer *x3;
 
2635
     integer *x4;
 
2636
     integer *x5;
 
2637
     integer *x6;
 
2638
     double *dv1;
 
2639
     double *dv2; 
 
2640
     double *dv3;
 
2641
     double *dv4;
 
2642
{
 
2643
  integer verbose=0 ;
 
2644
  C2F(MissileGCGetorSet)(str,0L,&verbose,x1,x2,x3,x4,x5,x6,dv1);
 
2645
}
 
2646
 
 
2647
void C2F(MissileGCGetorSet)(str, flag, verbose, x1, x2, x3, x4, x5,x6,dv1)
 
2648
     char *str;
 
2649
     integer flag;
 
2650
     integer *verbose;
 
2651
     integer *x1;
 
2652
     integer *x2;
 
2653
     integer *x3;
 
2654
     integer *x4;
 
2655
     integer *x5;
 
2656
     integer *x6;
 
2657
     double  *dv1;
 
2658
{ integer i ;
 
2659
  for (i=0; i < NUMSETFONC ; i++)
 
2660
    {
 
2661
      integer j;
 
2662
      j = strcmp(str,MissileGCTab_[i].name);
 
2663
      if ( j == 0 ) 
 
2664
        { if (*verbose == 1)
 
2665
            sciprint("\nGettting Info on %s\r\n",str);
 
2666
          if (flag == 1)
 
2667
            (MissileGCTab_[i].getfonc)(verbose,x1,x2,dv1);
 
2668
          else 
 
2669
            (MissileGCTab_[i].setfonc)(x1,x2,x3,x4,x5,x6,dv1);
 
2670
          return;}
 
2671
      else 
 
2672
        { if ( j <= 0)
 
2673
            {
 
2674
              sciprint("\nUnknow X operator <%s>\r\n",str);
 
2675
              return;
 
2676
            }
 
2677
        }
 
2678
    }
 
2679
  sciprint("\n Unknow X operator <%s>\r\n",str);
 
2680
}
 
2681
 
 
2682
 
 
2683
/*-------------------------------------------------------
 
2684
\section{Functions for drawing}
 
2685
---------------------------------------------------------*/
 
2686
 
 
2687
/*----------------------------------------------------
 
2688
\subsection{String display}
 
2689
 
 
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 
 
2694
  around the string}.
 
2695
-----------------------------------------------------*/
 
2696
 
 
2697
void C2F(displaystring)(string, x, y, v1, flag, v6, v7, angle, dv2, dv3, dv4)
 
2698
     char *string;
 
2699
     integer *x,*y,*v1,*flag,*v6,*v7;
 
2700
     double *angle,*dv2,*dv3,*dv4;
 
2701
 
2702
  if ( Abs(*angle) <= 0.1) 
 
2703
    {
 
2704
      if ( ScilabXgc->CurDrawFunction ==  GXxor )
 
2705
        {
 
2706
          SIZE size ;
 
2707
          GetTextExtentPoint32(hdc,string,strlen(string),&size);
 
2708
          XorString(*x,*y,string,size.cx,size.cy);
 
2709
        }
 
2710
      else
 
2711
        {
 
2712
          TextOut(hdc,(int) *x,(int) *y,string,strlen(string));
 
2713
        }
 
2714
      if ( *flag == 1) 
 
2715
        {
 
2716
          integer rect[4];
 
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);
 
2719
        }
 
2720
    }
 
2721
  else 
 
2722
    {
 
2723
      C2F(DispStringAngle)(x,y,string,angle);
 
2724
    }
 
2725
}
 
2726
 
 
2727
void C2F(DispStringAngle)(x0, yy0, string, angle)
 
2728
     integer *x0;
 
2729
     integer *yy0;
 
2730
     char *string;
 
2731
     double *angle;
 
2732
{
 
2733
  int i;
 
2734
  integer x,y, rect[4];
 
2735
  double sina ,cosa,l;
 
2736
  char str1[2];
 
2737
  str1[1]='\0';
 
2738
  x= *x0;
 
2739
  y= *yy0;
 
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++)
 
2743
    { 
 
2744
      str1[0]=string[i];
 
2745
      if ( ScilabXgc->CurDrawFunction ==  GXxor )
 
2746
        {
 
2747
          SIZE size ;
 
2748
          GetTextExtentPoint32(hdc,str1,1,&size);
 
2749
          XorString(x,y,str1,size.cx,size.cy);
 
2750
        }
 
2751
      else
 
2752
        {
 
2753
          TextOut(hdc,(int) x,(int) y,str1,1);
 
2754
        }
 
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)
 
2758
        { char str2[2];
 
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);
 
2763
        }
 
2764
      if ( Abs(cosa) >= 1.e-8 )
 
2765
        {
 
2766
          if ( Abs(sina/cosa) <= Abs(((double)rect[3])/((double)rect[2])))
 
2767
            l = Abs(rect[2]/cosa);
 
2768
          else 
 
2769
            l = Abs(rect[3]/sina);
 
2770
        }
 
2771
      else 
 
2772
        l = Abs(rect[3]/sina);
 
2773
      x +=  inint(cosa*l*1.1);
 
2774
      y +=  inint(sina*l*1.1);
 
2775
    }
 
2776
}
 
2777
 
 
2778
int XorString(x,y,string,fWidth,fHeight)
 
2779
     integer x,y;
 
2780
     char *string;
 
2781
     int fWidth,fHeight;
 
2782
{
 
2783
  COLORREF col ;
 
2784
  /** HPEN hpenOld;
 
2785
  HBRUSH hbrushOld; **/
 
2786
  HFONT hfont,hfontOld;
 
2787
  HDC hdcMem;
 
2788
  HBITMAP hbitmap, hbitmapOld;
 
2789
  hfont=getcurfont();
 
2790
  hdcMem = CreateCompatibleDC (hdc);
 
2791
  if (hdcMem) {
 
2792
    hbitmap = CreateCompatibleBitmap (hdc,fWidth,fHeight);
 
2793
    if (hbitmap) {
 
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);
 
2799
      /** unused : 
 
2800
        hpenOld=SelectObject(hdcMem,ScilabXgc->hPen);
 
2801
        hbrushOld=SelectObject(hdcMem,ScilabXgc->hBrush); 
 
2802
        **/
 
2803
      hfontOld=SelectObject(hdcMem,hfont);
 
2804
      if (ScilabXgc->Colors != NULL) 
 
2805
        {
 
2806
          /** see set_c **/
 
2807
          col = ScilabXgc->Colors[ScilabXgc->CurColor];
 
2808
          if ( ScilabXgc->CurDrawFunction !=  GXxor )
 
2809
            col = col ^ ScilabXgc->Colors[ScilabXgc->NumBackground];
 
2810
          SetTextColor(hdcMem,col); 
 
2811
        }
 
2812
      if (TextOut (hdcMem,0,fHeight,string,strlen(string)))
 
2813
        {
 
2814
          /** see raster ops in VC++ **/
 
2815
          BitBlt(hdc, x,y-fHeight,fWidth,fHeight,hdcMem,0,0,0x990066);
 
2816
        } else {
 
2817
          MessageBox (GetFocus(),
 
2818
                      "Unable to perform TextOut", "DisplayGlyph", MB_OK);
 
2819
        }
 
2820
      SelectObject (hdcMem, hbitmapOld);
 
2821
      /** SelectObject (hdcMem, hpenOld);
 
2822
        SelectObject (hdcMem, hbrushOld); **/
 
2823
      SelectObject (hdcMem, hfontOld);
 
2824
      DeleteObject (hbitmap);
 
2825
    } else {
 
2826
      MessageBox (GetFocus(), "Unable To create Bitmap", "DisplayGlyph", MB_OK);
 
2827
    }
 
2828
    DeleteDC (hdcMem);
 
2829
  } else {
 
2830
    MessageBox (GetFocus(), "Unable to create DC", "DisplayGlyph", MB_OK);
 
2831
  }
 
2832
  return 0;
 
2833
}
 
2834
 
 
2835
 
 
2836
/** To get the bounding rectangle of a string **/
 
2837
 
 
2838
void C2F(boundingbox)(string, x, y, rect, v5, v6, v7, dv1, dv2, dv3, dv4)
 
2839
     char *string;
 
2840
     integer *x,*y,*rect,*v5,*v6,*v7;
 
2841
     double *dv1,*dv2,*dv3,*dv4;
 
2842
 
2843
  SIZE size ;
 
2844
  /** text mode is supposed to be bottom  **/
 
2845
  GetTextExtentPoint32(hdc,string,strlen(string),&size);
 
2846
  rect[0]= *x ;
 
2847
  rect[1]= *y - size.cy ;
 
2848
  rect[2]= size.cx;
 
2849
  rect[3]= size.cy;
 
2850
}
 
2851
 
 
2852
/*------------------------------------------------
 
2853
subsection{ Segments and Arrows }
 
2854
-------------------------------------------------*/
 
2855
 
 
2856
void C2F(drawline)(x1, yy1, x2, y2)
 
2857
     integer *x1;
 
2858
     integer *yy1;
 
2859
     integer *x2;
 
2860
     integer *y2;
 
2861
{
 
2862
   
 
2863
  MoveToEx(hdc,(int) *x1,(int) *yy1,NULL);
 
2864
  LineTo(hdc,(int) *x2,(int) *y2);
 
2865
  
 
2866
}
 
2867
 
 
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 **/
 
2872
 
 
2873
void C2F(drawsegments)(str, vx, vy, n, style, iflag, v7, dv1, dv2, dv3, dv4)
 
2874
     char *str;
 
2875
     integer *vx;
 
2876
     integer *vy;
 
2877
     integer *n;
 
2878
     integer *style;
 
2879
     integer *iflag;
 
2880
     integer *v7;
 
2881
     double *dv1;
 
2882
     double *dv2;
 
2883
     double *dv3;
 
2884
     double *dv4;
 
2885
{
 
2886
  integer verbose=0,Dnarg,Dvalue[10],NDvalue;
 
2887
  integer i ;
 
2888
 
 
2889
  C2F(get_dash_and_color)(&verbose,Dvalue,&Dnarg,vdouble);
 
2890
 
 
2891
 
 
2892
  if ( (int) *iflag == 1) { /* one style per segment */
 
2893
    for (i=0 ; i < *n/2 ; i++) {
 
2894
      NDvalue = style[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]);
 
2898
    }
 
2899
  }
 
2900
  else {
 
2901
    if (*style >= 1) /* set color */
 
2902
      C2F(set_line_style)(style,PI0,PI0,PI0);
 
2903
 
 
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]);
 
2907
    }
 
2908
  }
 
2909
  C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
 
2910
}
 
2911
 
 
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 **/
 
2917
 
 
2918
void C2F(drawarrows)(str, vx, vy, n, as, style, iflag, dv1, dv2, dv3, dv4)
 
2919
     char *str;
 
2920
     integer *vx;
 
2921
     integer *vy;
 
2922
     integer *n;
 
2923
     integer *as;
 
2924
     integer *style;
 
2925
     integer *iflag;
 
2926
     double *dv1;
 
2927
     double *dv2;
 
2928
     double *dv3;
 
2929
     double *dv4;
 
2930
 
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++)
 
2937
    { 
 
2938
      double dx,dy,norm;
 
2939
      if ( (int) *iflag == 1) 
 
2940
        NDvalue = style[i];
 
2941
      else 
 
2942
        NDvalue=(*style < 1) ?  Dvalue[0] : *style;
 
2943
      C2F(set_line_style)(&NDvalue,PI0,PI0,PI0);
 
2944
      
 
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]);
 
2947
      
 
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 ) 
 
2952
        { integer nn=1,p=3;
 
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);
 
2961
          }
 
2962
    }
 
2963
  C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
 
2964
}
 
2965
 
 
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] **/
 
2976
 
 
2977
void C2F(drawrectangles)(str, vects, fillvect, n, v5, v6, v7, dv1, dv2, dv3, dv4)
 
2978
     char *str;
 
2979
     integer *vects;
 
2980
     integer *fillvect;
 
2981
     integer *n;
 
2982
     integer *v5;
 
2983
     integer *v6;
 
2984
     integer *v7;
 
2985
     double *dv1;
 
2986
     double *dv2;
 
2987
     double *dv3;
 
2988
     double *dv4;
 
2989
{
 
2990
  integer i,cpat,verbose=0,num,cd[10];
 
2991
  C2F(getpattern)(&verbose,&cpat,&num,vdouble);
 
2992
 
 
2993
  C2F(get_dash_and_color)(&verbose,cd,&num,vdouble);
 
2994
  for (i=0 ; i< *n ; i++)
 
2995
    {
 
2996
      if (fillvect[i] < 0)
 
2997
        {
 
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);
 
3002
        }
 
3003
      else if (fillvect[i] == 0)
 
3004
        {
 
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);
 
3008
        }
 
3009
      else
 
3010
        {
 
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);
 
3013
        }
 
3014
    }
 
3015
  C2F(set_dash_and_color)(&(cd),PI0,PI0,PI0);
 
3016
}
 
3017
 
 
3018
/** Draw one rectangle with current line style **/
 
3019
 
 
3020
void C2F(drawrectangle)(str, x, y, width, height, v6, v7, dv1, dv2, dv3, dv4)
 
3021
     char *str;
 
3022
     integer *x;
 
3023
     integer *y;
 
3024
     integer *width;
 
3025
     integer *height;
 
3026
     integer *v6;
 
3027
     integer *v7;
 
3028
     double *dv1;
 
3029
     double *dv2;
 
3030
     double *dv3;
 
3031
     double *dv4;
 
3032
 
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);
 
3038
}
 
3039
 
 
3040
/** fill one rectangle, with current pattern **/
 
3041
 
 
3042
void C2F(fillrectangle)(str, x, y, width, height, v6, v7, dv1, dv2, dv3, dv4)
 
3043
     char *str;
 
3044
     integer *x;
 
3045
     integer *y;
 
3046
     integer *width;
 
3047
     integer *height;
 
3048
     integer *v6;
 
3049
     integer *v7;
 
3050
     double *dv1;
 
3051
     double *dv2;
 
3052
     double *dv3;
 
3053
     double *dv4;
 
3054
 
3055
  /** Rectangle with current pen and brush **/
 
3056
  Rectangle(hdc,(int) *x,(int) *y,(int) *width + *x+1 ,(int) *height + *y+1 );
 
3057
}
 
3058
 
 
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
 *----------------------------------------------------------------------------------*/
 
3066
 
 
3067
void fill_grid_rectangles(x, y, z, n1, n2)
 
3068
     integer x[],y[];
 
3069
     double *z;
 
3070
     integer n1,n2;
 
3071
{
 
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));
 
3076
  zmaxmin=zmax-zmin;
 
3077
  if (zmaxmin <= SMDOUBLE) zmaxmin=SMDOUBLE;
 
3078
  
 
3079
  C2F(getlast)(&verbose,&whiteid,&narg,vdouble);
 
3080
  C2F(getpattern)(&verbose,&cpat,&narg,vdouble);
 
3081
  C2F(getwindowdim)(&verbose,xz,&narg,vdouble);
 
3082
 
 
3083
  for (i = 0 ; i < (n1)-1 ; i++)
 
3084
    for (j = 0 ; j < (n2)-1 ; j++)
 
3085
      {
 
3086
        integer w,h;
 
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 );
 
3094
      }
 
3095
  C2F(setpattern)(&cpat,PI0,PI0,PI0);
 
3096
}
 
3097
 
 
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
 *----------------------------------------------------------------------------------*/
 
3107
 
 
3108
void fill_grid_rectangles1(x, y, z, n1, n2)
 
3109
     integer *x;
 
3110
     integer *y;
 
3111
     double *z;
 
3112
     integer n1;
 
3113
     integer n2;
 
3114
{
 
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++)
 
3120
      {
 
3121
        integer w,h;
 
3122
        fill[0]= z[i+(n1-1)*j];
 
3123
        C2F(setpattern)(fill,PI0,PI0,PI0);
 
3124
        w=Abs(x[j+1]-x[j]);
 
3125
        h=Abs(y[i+1]-y[i]);
 
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 );
 
3129
      }
 
3130
  C2F(setpattern)(&cpat,PI0,PI0,PI0);
 
3131
}
 
3132
 
 
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 **/
 
3146
 
 
3147
void C2F(fillarcs)(str, vects, fillvect, n, v5, v6, v7, dv1, dv2, dv3, dv4)
 
3148
     char *str;
 
3149
     integer *vects;
 
3150
     integer *fillvect;
 
3151
     integer *n;
 
3152
     integer *v5;
 
3153
     integer *v6;
 
3154
     integer *v7;
 
3155
     double *dv1;
 
3156
     double *dv2;
 
3157
     double *dv3;
 
3158
     double *dv4;
 
3159
{
 
3160
  integer i,cpat,verb,num;
 
3161
  verb=0;
 
3162
  C2F(getpattern)(&verb,&cpat,&num,vdouble);
 
3163
  for (i=0 ; i< *n ; i++)
 
3164
    {
 
3165
      if (fillvect[i] > ScilabXgc->IDLastPattern + 1)
 
3166
        {
 
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);
 
3171
        }
 
3172
      else
 
3173
        {
 
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);
 
3178
        }
 
3179
    }
 
3180
  C2F(setpattern)(&(cpat),PI0,PI0,PI0);
 
3181
}
 
3182
 
 
3183
 
 
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          **/
 
3190
 
 
3191
void C2F(drawarcs)(str, vects, style, n, v5, v6, v7, dv1, dv2, dv3, dv4)
 
3192
     char *str;
 
3193
     integer *vects;
 
3194
     integer *style;
 
3195
     integer *n;
 
3196
     integer *v5;
 
3197
     integer *v6;
 
3198
     integer *v7;
 
3199
     double *dv1;
 
3200
     double *dv2;
 
3201
     double *dv3;
 
3202
     double *dv4;
 
3203
{
 
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++)
 
3208
    {
 
3209
      NDvalue = style[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);
 
3214
    }
 
3215
  C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
 
3216
}
 
3217
 
 
3218
/** Draw a single ellipsis or part of it **/
 
3219
 
 
3220
void C2F(drawarc)(str, x, y, width, height, angle1, angle2, dv1, dv2, dv3, dv4)
 
3221
     char *str;
 
3222
     integer *x, *y, *width,*height, *angle1, *angle2;
 
3223
     double *dv1,*dv2,*dv3,*dv4;
 
3224
 
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);
 
3236
}
 
3237
 
 
3238
/** Fill a single elipsis or part of it with current pattern **/
 
3239
 
 
3240
void C2F(fillarc)(str, x, y, width, height, angle1, angle2, dv1, dv2, dv3, dv4)
 
3241
     char *str;
 
3242
     integer *x, *y, *width,*height, *angle1, *angle2;
 
3243
     double *dv1,*dv2,*dv3,*dv4;
 
3244
{
 
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 **/
 
3254
}
 
3255
 
 
3256
/*--------------------------------------------------------------
 
3257
\encadre{Filling or Drawing Polylines and Polygons}
 
3258
---------------------------------------------------------------*/
 
3259
 
 
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 **/
 
3264
 
 
3265
void C2F(drawpolylines)(str, vectsx, vectsy, drawvect, n, p, v7, dv1, dv2, dv3, dv4)
 
3266
     char *str;
 
3267
     integer *vectsx;
 
3268
     integer *vectsy;
 
3269
     integer *drawvect;
 
3270
     integer *n;
 
3271
     integer *p;
 
3272
     integer *v7;
 
3273
     double *dv1;
 
3274
     double *dv2;
 
3275
     double *dv3;
 
3276
     double *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++)
 
3282
    {
 
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);
 
3289
        }
 
3290
      else
 
3291
        {/** we use the line-style number abs(drawvect[i])  **/
 
3292
          C2F(set_line_style)(drawvect+i,PI0,PI0,PI0);
 
3293
          close = 0;
 
3294
          C2F(drawpolyline)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,&close,
 
3295
                        PI0,PI0,PD0,PD0,PD0,PD0);
 
3296
        }
 
3297
    }
 
3298
  /** back to default values **/
 
3299
  C2F(set_dash_and_color)( Dvalue,PI0,PI0,PI0);
 
3300
  C2F(xsetmark)(symb,symb+1,PI0,PI0);
 
3301
}
 
3302
 
 
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 
 
3306
 fillvect[*n] :         
 
3307
 fillvect[*n] :         
 
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]
 
3312
**/
 
3313
 
 
3314
void C2F(fillpolylines)(str, vectsx, vectsy, fillvect, n, p, v7, dv1, dv2, dv3, dv4)
 
3315
     char *str;
 
3316
     integer *vectsx;
 
3317
     integer *vectsy;
 
3318
     integer *fillvect;
 
3319
     integer *n;
 
3320
     integer *p;
 
3321
     integer *v7;
 
3322
     double *dv1;
 
3323
     double *dv2;
 
3324
     double *dv3;
 
3325
     double *dv4;
 
3326
{
 
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++)
 
3332
    {
 
3333
      if (fillvect[i] > 0) 
 
3334
        { 
 
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);
 
3343
        }
 
3344
      else  if (fillvect[i] == 0 )
 
3345
        {
 
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);
 
3350
        }
 
3351
      else 
 
3352
        {
 
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);
 
3357
        }
 
3358
    }
 
3359
  C2F(set_dash_and_color)(Dvalue,PI0,PI0,PI0); 
 
3360
}
 
3361
 
 
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 */
 
3365
 
 
3366
void C2F(drawpolyline)(str, n, vx, vy, closeflag, v6, v7, dv1, dv2, dv3, dv4)
 
3367
     char *str;
 
3368
     integer *n;
 
3369
     integer *vx;
 
3370
     integer *vy;
 
3371
     integer *closeflag;
 
3372
     integer *v6;
 
3373
     integer *v7;
 
3374
     double *dv1;
 
3375
     double *dv2;
 
3376
     double *dv3;
 
3377
     double *dv4;
 
3378
 
3379
  integer n1;
 
3380
  if (*closeflag == 1) n1 = *n+1;else n1= *n;
 
3381
  if (n1 >= 2) 
 
3382
    {
 
3383
      if (C2F(store_points)(*n, vx, vy,*closeflag))
 
3384
        {
 
3385
          Polyline(hdc,C2F(ReturnPoints)(),(int) n1);
 
3386
        } 
 
3387
    }
 
3388
}
 
3389
 
 
3390
/** Fill the polygon or polyline **/
 
3391
/** according to *closeflag : the given vector is a polyline or a polygon **/
 
3392
 
 
3393
void C2F(fillpolyline)(str, n, vx, vy, closeflag, v6, v7, dv1, dv2, dv3, dv4)
 
3394
     char *str;
 
3395
     integer *n;
 
3396
     integer *vx;
 
3397
     integer *vy;
 
3398
     integer *closeflag;
 
3399
     integer *v6;
 
3400
     integer *v7;
 
3401
     double *dv1;
 
3402
     double *dv2;
 
3403
     double *dv3;
 
3404
     double *dv4;
 
3405
{
 
3406
  integer n1;
 
3407
  if (*closeflag == 1) n1 = *n+1;else n1= *n;
 
3408
  if (C2F(store_points)(*n, vx, vy,*closeflag))
 
3409
    {
 
3410
      Polygon(hdc,C2F(ReturnPoints)(), n1);
 
3411
    }
 
3412
}
 
3413
 
 
3414
/** Draw the current mark centred at points defined **/
 
3415
/** by vx and vy (vx[i],vy[i]) **/
 
3416
 
 
3417
void C2F(drawpolymark)(str, n, vx, vy, v5, v6, v7, dv1, dv2, dv3, dv4)
 
3418
     char *str;
 
3419
     integer *n;
 
3420
     integer *vx;
 
3421
     integer *vy;
 
3422
     integer *v5;
 
3423
     integer *v6;
 
3424
     integer *v7;
 
3425
     double *dv1;
 
3426
     double *dv2;
 
3427
     double *dv3;
 
3428
     double *dv4;
 
3429
{
 
3430
  if ( ScilabXgc->CurHardSymb == 0 )
 
3431
    {
 
3432
      if (C2F(store_points)(*n, vx, vy,0L))             
 
3433
        {
 
3434
          XDrawPoints (hdc,C2F(ReturnPoints)(), *n);
 
3435
        }
 
3436
    }
 
3437
  else 
 
3438
    { 
 
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);
 
3447
    }
 
3448
}
 
3449
 
 
3450
static void XDrawPoints(lhdc, points, Npoints)
 
3451
        HDC lhdc;
 
3452
        POINT *points;
 
3453
        integer Npoints;
 
3454
{
 
3455
  int i ;
 
3456
  for ( i=0; i < Npoints;i++) 
 
3457
    {
 
3458
      /** XXX SetPixel plutot **/
 
3459
      MoveToEx(hdc,points[i].x,points[i].y,NULL);
 
3460
      LineTo(hdc,points[i].x+1,points[i].y);
 
3461
    }
 
3462
}
 
3463
 
 
3464
/*-----------------------------------------
 
3465
 \encadre{List of Window id}
 
3466
-----------------------------------------*/
 
3467
 
 
3468
 
 
3469
/*
 
3470
 * Adds a new entry at the end of the Window List
 
3471
 * and returns a pointer to that entry
 
3472
 */
 
3473
 
 
3474
struct BCG *AddNewWindowToList()
 
3475
{
 
3476
  return( AddNewWindow(&The_List));
 
3477
}
 
3478
struct BCG *AddNewWindow(listptr)
 
3479
     WindowList **listptr;
 
3480
{
 
3481
  if ( *listptr == (WindowList *) NULL)
 
3482
    {
 
3483
      *listptr = (WindowList *) MALLOC (sizeof(WindowList));
 
3484
      if ( listptr == 0)
 
3485
        {
 
3486
          Scistring("AddNewWindow No More Place ");
 
3487
          return((struct BCG *) 0);
 
3488
        }
 
3489
     else
 
3490
       {
 
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));
 
3505
       }
 
3506
    }
 
3507
  else
 
3508
    {
 
3509
      return( AddNewWindow((WindowList **) &((*listptr)->next)));
 
3510
    }
 
3511
}
 
3512
 
 
3513
/** destruction d'une fenetre **/
 
3514
 
 
3515
void DeleteSGWin(intnum)
 
3516
     integer intnum;
 
3517
{
 
3518
  int curwin;
 
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 )
 
3525
    {
 
3526
      if ( The_List == (WindowList *) NULL)
 
3527
        {
 
3528
          /** No more graphic window ; **/
 
3529
          ScilabXgc = (struct BCG *) 0;
 
3530
        }
 
3531
      else
 
3532
        {
 
3533
          /** fix the new current graphic window **/
 
3534
          ScilabXgc = &(The_List->winxgc);
 
3535
          ResetScilabXgc ();
 
3536
          get_window_scale(ScilabXgc->CurWindow,NULL);
 
3537
        }
 
3538
    }
 
3539
}
 
3540
 
 
3541
/** detruit la fenetre num dans la liste des fenetres */
 
3542
 
 
3543
void DeleteWindowToList(num)
 
3544
     integer num;
 
3545
{
 
3546
  WindowList *L1,*L2;
 
3547
  L1 = The_List;
 
3548
  L2 = The_List;
 
3549
  while ( L1 != (WindowList *) NULL)
 
3550
    {
 
3551
      if ( L1->winxgc.CurWindow == num )
 
3552
        {
 
3553
          /** destroying windows **/
 
3554
          /** XXXX : if there's a pixmap we must free it **/
 
3555
          deleted_win = num;
 
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) 
 
3562
            {
 
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)
 
3569
                {
 
3570
                  DeleteDC(L1->winxgc.hdcCompat);
 
3571
                }
 
3572
            }
 
3573
          /** The window was found **/
 
3574
          if ( L1 != L2 )
 
3575
            {
 
3576
              /** Ce n'est pas la premiere fenetre de la liste **/
 
3577
              L2->next= L1->next ;
 
3578
              FREE(L1);
 
3579
              return ;
 
3580
            }
 
3581
          else 
 
3582
            {
 
3583
              /** C'est la premiere fenetre de la liste **/
 
3584
              The_List = (WindowList *) L1->next ;
 
3585
              FREE(L1);
 
3586
              return;
 
3587
            }
 
3588
        }
 
3589
      else 
 
3590
        {
 
3591
          L2 = L1;
 
3592
          L1 = (WindowList *) L1->next;
 
3593
        }
 
3594
    }
 
3595
}
 
3596
 
 
3597
/********************************************
 
3598
 * Get Window number wincount ( or 0 )
 
3599
 ********************************************/
 
3600
 
 
3601
Window GetWindowNumber(wincount)
 
3602
     int wincount;
 
3603
{
 
3604
  struct BCG *bcg;
 
3605
  bcg = GetWindowXgcNumber(wincount);
 
3606
  if ( bcg != (struct BCG *) 0)
 
3607
    return( bcg->CWindow);
 
3608
  else
 
3609
    return( (Window) 0);
 
3610
}
 
3611
 
 
3612
/********************************************
 
3613
 * returns the graphic context of window i
 
3614
 * or 0 if this window does not exists
 
3615
 ********************************************/
 
3616
 
 
3617
struct BCG *GetWindowXgcNumber(i)
 
3618
     integer i;
 
3619
{
 
3620
  return( GetWinXgc(The_List,Max(0,i)));
 
3621
}
 
3622
 
 
3623
struct BCG *GetWinXgc(listptr, i)
 
3624
     WindowList *listptr;
 
3625
     integer i;
 
3626
{
 
3627
  if (listptr == (WindowList  *) NULL)
 
3628
    {
 
3629
      return((struct BCG *) 0);
 
3630
    }
 
3631
  else
 
3632
    {
 
3633
      if ((listptr->winxgc.CurWindow) == i)
 
3634
        {
 
3635
          return( &(listptr->winxgc));
 
3636
         }
 
3637
      else
 
3638
        {
 
3639
         return(GetWinXgc((WindowList *) listptr->next,i));
 
3640
        }
 
3641
    }
 
3642
}
 
3643
 
 
3644
 
 
3645
/***************************
 
3646
 * get ids of scilab windows
 
3647
 * in array Ids,
 
3648
 * Num gives the number of windows
 
3649
 * flag == 1 ==> get the Ids 
 
3650
 * flag == 0 ==> just get the Number Num 
 
3651
 ***************************/
 
3652
 
 
3653
void C2F(getwins)(Num,Ids,flag)
 
3654
     integer *Num,Ids[],*flag;
 
3655
{
 
3656
  WindowList *listptr = The_List;
 
3657
  *Num = 0;
 
3658
  if ( *flag == 0 )
 
3659
    {
 
3660
      while ( listptr != (WindowList  *) 0 ) 
 
3661
        {
 
3662
          (*Num)++;
 
3663
          listptr = (WindowList *) listptr->next;
 
3664
        }
 
3665
    }
 
3666
  else 
 
3667
    {
 
3668
      while ( listptr != (WindowList  *) 0 ) 
 
3669
        {
 
3670
          Ids[*Num] = listptr->winxgc.CurWindow;
 
3671
          listptr =  (WindowList *)listptr->next;
 
3672
          (*Num)++;
 
3673
        }
 
3674
    }
 
3675
}
 
3676
 
 
3677
/*--------------------------------------------------------------
 
3678
  \encadre{Routine for initialisation : string is a display name }
 
3679
--------------------------------------------------------------*/
 
3680
 
 
3681
void set_c(coli)
 
3682
     integer coli;
 
3683
{
 
3684
  int i,id, width;
 
3685
  COLORREF col ;
 
3686
  HBRUSH hBrush;
 
3687
  HPEN hpen;
 
3688
 
 
3689
  if (ScilabXgc->Colors == NULL) 
 
3690
    return;
 
3691
  i= Max(0,Min(coli,ScilabXgc->Numcolors + 1));
 
3692
  ScilabXgc->CurColor = i ;
 
3693
  if ( ScilabXgc->CurDrawFunction !=  GXxor )
 
3694
    col = ScilabXgc->Colors[i];
 
3695
  else 
 
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); 
 
3702
  else {
 
3703
    width = ( DashTab[id] != PS_SOLID) ?  0 : ScilabXgc->CurLineWidth ;
 
3704
    hpen = CreatePen(DashTab[id],width,col);
 
3705
  }
 
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;
 
3712
}
 
3713
 
 
3714
 
 
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 **/
 
3718
 
 
3719
void C2F(initgraphic)(string, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
 
3720
     char *string;
 
3721
     integer *v2;
 
3722
     integer *v3;
 
3723
     integer *v4;
 
3724
     integer *v5;
 
3725
     integer *v6;
 
3726
     integer *v7;
 
3727
     double *dv1;
 
3728
     double *dv2;
 
3729
     double *dv3;
 
3730
     double *dv4;
 
3731
 
3732
  static char popupname[sizeof("ScilabGraphic")+4];
 
3733
  static char winname[sizeof("BG")+4];
 
3734
  struct BCG *NewXgc ;
 
3735
  RECT rect,rect1;
 
3736
  static integer EntryCounter = 0;
 
3737
  integer WinNum;
 
3738
  static HMENU sysmenu;
 
3739
  SCROLLINFO vertsi;
 
3740
  SCROLLINFO horzsi;
 
3741
 
 
3742
 
 
3743
  
 
3744
  if ( v2 != (integer *) NULL && *v2 != -1 )
 
3745
    WinNum= *v2;
 
3746
  else
 
3747
    WinNum= EntryCounter;
 
3748
  if (EntryCounter == 0)
 
3749
    {
 
3750
      /** XXXXXX : pour l'instant couleur par defaut */
 
3751
      screencolor = 1;
 
3752
      if (C2F(AllocVectorStorage)()==0) return;
 
3753
      graphwin.xmax = WIN_XMAX;
 
3754
      graphwin.ymax = WIN_YMAX;
 
3755
      if (! graphwin.hPrevInstance) /** XXX : utiliser EntryCounter ??? **/
 
3756
        {
 
3757
          CreateGraphClass();
 
3758
        }
 
3759
      /** Read or use default values **/
 
3760
    }
 
3761
  if (( NewXgc = AddNewWindowToList()) == (struct BCG *) 0)
 
3762
    {
 
3763
      Scistring("initgraphics: unable to alloc\n");
 
3764
      return;
 
3765
    }
 
3766
  else
 
3767
    {
 
3768
      ScilabXgc= NewXgc;
 
3769
    }
 
3770
  /** ReadGraphIni takes care of graphwin.Origin and  graphwin.Size **/
 
3771
  /** ScilabXgc is send to CreateWindow and this information is used 
 
3772
    in WndGraphProc **/
 
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, 
 
3782
                                       NewXgc);
 
3783
  if (ScilabXgc->hWndParent == (HWND)NULL) {
 
3784
    MessageBox((HWND)NULL,"Couldn't open parent graph window",
 
3785
               (LPSTR)NULL, MB_ICONHAND | MB_SYSTEMMODAL);
 
3786
    return;
 
3787
  }
 
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,
 
3805
                                    NewXgc);
 
3806
 
 
3807
  ScilabXgc->CurResizeStatus = 1;
 
3808
  ScilabXgc->CWindowWidthView  = ScilabXgc->CWindowWidth;
 
3809
  ScilabXgc->CWindowHeightView = ScilabXgc->CWindowHeight;
 
3810
 
 
3811
        /* definition des scroll bars verticalles */
 
3812
  vertsi.cbSize = sizeof(SCROLLINFO);
 
3813
  vertsi.fMask  = SIF_RANGE | SIF_PAGE | SIF_POS;
 
3814
  vertsi.nMin   = 0;
 
3815
  vertsi.nMax   = ScilabXgc->CWindowHeight;
 
3816
  vertsi.nPage  = ScilabXgc->CWindowHeightView;
 
3817
  vertsi.nPos   = 0;
 
3818
  sciSetScrollInfo(ScilabXgc,SB_VERT, &(vertsi), TRUE);
 
3819
  sciGetScrollInfo(ScilabXgc,SB_VERT, &vertsi);
 
3820
 
 
3821
        /* definition des scroll bars horizontalle */
 
3822
  horzsi.cbSize = sizeof(SCROLLINFO);
 
3823
  horzsi.fMask  = SIF_RANGE | SIF_PAGE | SIF_POS;
 
3824
  horzsi.nMin   = 0;
 
3825
  horzsi.nMax   = ScilabXgc->CWindowWidth;
 
3826
  horzsi.nPage  = ScilabXgc->CWindowWidthView;
 
3827
  horzsi.nPos   = 0;
 
3828
  sciSetScrollInfo(ScilabXgc,SB_HORZ, &horzsi, TRUE);     
 
3829
  sciGetScrollInfo(ScilabXgc,SB_HORZ, &horzsi);
 
3830
 
 
3831
  //sciInitScrollBar(ScilabXgc);
 
3832
 
 
3833
  if (ScilabXgc->CWindow == (HWND)NULL) 
 
3834
    {
 
3835
      MessageBox((HWND)NULL,"Couldn't open graphic window",
 
3836
                 (LPSTR)NULL, MB_ICONHAND | MB_SYSTEMMODAL);
 
3837
      return;
 
3838
    }
 
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 */
 
3853
  SetWinhdc();
 
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);
 
3860
 
 
3861
  if (EntryCounter == 0)
 
3862
    {
 
3863
      C2F(CreatePatterns)();
 
3864
      LoadFonts();
 
3865
    } 
 
3866
  InitMissileXgc(PI0,PI0,PI0,PI0);/* a laisser ici */
 
3867
  EntryCounter=Max(EntryCounter,WinNum);
 
3868
  EntryCounter++;
 
3869
  ScilabXgc->Inside_init=0;
 
3870
}
 
3871
 
 
3872
static void CreateGraphClass()
 
3873
{
 
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;
 
3894
  if (textwin.hIcon)
 
3895
    wndclass.hIcon = textwin.hIcon;
 
3896
  else
 
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);
 
3903
}
 
3904
 
 
3905
/* Writes a message in the Label info part of the Graphicwindow  */
 
3906
 
 
3907
void C2F(xinfo)(message, v2, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
 
3908
     char *message;
 
3909
     integer *v2,*v3,*v4,*v5,*v6,*v7;
 
3910
     double *dv1,*dv2,*dv3,*dv4;
 
3911
{
 
3912
  if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->Statusbar != (Window) 0)
 
3913
    {
 
3914
      (BOOL)SendMessage(ScilabXgc->Statusbar, SB_SETTEXT, (WPARAM) 0, 
 
3915
                        (LPARAM) (LPSTR) message );
 
3916
    }
 
3917
}
 
3918
 
 
3919
/* Extended call for C calling */
 
3920
#define MAXPRINTF 512
 
3921
 
 
3922
void wininfo(char *fmt,...)
 
3923
{
 
3924
  int count;
 
3925
  char buf[MAXPRINTF];
 
3926
  va_list args;
 
3927
  va_start(args,fmt);
 
3928
  count = vsprintf(buf,fmt,args);
 
3929
  if ( ScilabXgc != (struct BCG *) 0 && ScilabXgc->Statusbar != (Window) 0)
 
3930
    {
 
3931
      (BOOL)SendMessage(ScilabXgc->Statusbar, SB_SETTEXT, (WPARAM) 0, 
 
3932
                        (LPARAM) (LPSTR) buf);
 
3933
    }
 
3934
}
 
3935
 
 
3936
/*************************************************
 
3937
 * Initialize the graphic context. Used also 
 
3938
 * to come back to the default graphic state
 
3939
 *************************************************/
 
3940
 
 
3941
static void InitMissileXgc (integer *v1,integer *v2,integer *v3,integer *v4)
 
3942
 
3943
  integer i,j;
 
3944
  ScilabXgc->IDLastPattern = GREYNUMBER - 1;
 
3945
  ScilabXgc->CurLineWidth=0 ;
 
3946
 
 
3947
  C2F(setalufunction1)((i=3,&i),PI0,PI0,PI0);
 
3948
  /** retirer le clipping **/
 
3949
  i=j= -1;
 
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;
 
3971
 
 
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) */
 
3982
  getcolordef(&i);
 
3983
  /** we force CurColorStatus to the opposite value of col
 
3984
    to force usecolorPos to perform initialisations
 
3985
    **/
 
3986
  ScilabXgc->CurColorStatus = (i == 1) ? 0: 1;
 
3987
  C2F(usecolor)(&i ,PI0,PI0,PI0);
 
3988
  strcpy(ScilabXgc->CurNumberDispFormat,"%-5.2g");
 
3989
  /** default scales **/
 
3990
  Cscale2default();
 
3991
}
 
3992
 
 
3993
 
 
3994
/* returns the current color status */
 
3995
 
 
3996
void getcolordef(screenc)
 
3997
     integer *screenc;
 
3998
{
 
3999
  *screenc= screencolor;
 
4000
}
 
4001
 
 
4002
void setcolordef(screenc)
 
4003
        integer screenc;
 
4004
{
 
4005
        screencolor = screenc;
 
4006
}
 
4007
 
 
4008
/* Utilise le ScilabXgc courant pour reinitialiser le gc XWindow */
 
4009
/* cela est utilis'e quand on change de fenetre graphique        */
 
4010
 
 
4011
void
 
4012
ResetScilabXgc ()
 
4013
 
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);
 
4022
  
 
4023
  i= ScilabXgc->CurLineWidth;
 
4024
  C2F(setthickness)(&i,PI0,PI0,PI0);
 
4025
  
 
4026
  i= ScilabXgc->CurVectorStyle;
 
4027
  C2F(setabsourel)(&i,PI0,PI0,PI0);
 
4028
  
 
4029
  i= ScilabXgc->CurDrawFunction;
 
4030
  C2F(setalufunction1)(&i,PI0,PI0,PI0);
 
4031
  
 
4032
  if (ScilabXgc->ClipRegionSet == 1) 
 
4033
    {
 
4034
      for ( i= 0 ; i < 4; i++) clip[i]=ScilabXgc->CurClipRegion[i];
 
4035
      C2F(setclip)(clip,clip+1,clip+2,clip+3);
 
4036
    }
 
4037
  else
 
4038
    C2F(unsetclip)(PI0,PI0,PI0,PI0);
 
4039
 
 
4040
  if (ScilabXgc->CurColorStatus == 0) 
 
4041
    {
 
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);
 
4053
    }
 
4054
  else 
 
4055
    {
 
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);
 
4071
    }
 
4072
}
 
4073
 
 
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 
 
4077
  following way :
 
4078
  \begin{itemize}
 
4079
  \item   $n=<n1,n2>$,
 
4080
  \begin{verbatim}
 
4081
  |            |           |
 
4082
  |----|---|---|---|---|---|
 
4083
  <-----n1---->                 
 
4084
  <-------------n2-------->
 
4085
  \end{verbatim}
 
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>$. 
 
4091
  \end{itemize}
 
4092
  
 
4093
-------------------------------------------------------------*/
 
4094
 
 
4095
void C2F(drawaxis)(str, alpha, nsteps, v2, initpoint, v6, v7, size, dx2, dx3, dx4)
 
4096
     char *str;
 
4097
     integer *alpha;
 
4098
     integer *nsteps;
 
4099
     integer *v2;
 
4100
     integer *initpoint;
 
4101
     integer *v6;
 
4102
     integer *v7;
 
4103
     double *size;
 
4104
     double *dx2;
 
4105
     double *dx3;
 
4106
     double *dx4;
 
4107
{ integer i;
 
4108
  double xi,yi,xf,yf;
 
4109
  double cosal,sinal;
 
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++)
 
4113
    {
 
4114
      if ( ( i % nsteps[0]) != 0) 
 
4115
        {
 
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));
 
4122
        }
 
4123
    }
 
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));
 
4131
    }
 
4132
  /**
 
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));
 
4138
  **/
 
4139
}
 
4140
 
 
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
-----------------------------------------------------*/
 
4146
 
 
4147
void C2F(displaynumbers)(str, x, y, v1, v2, n, flag, z, alpha, dx3, dx4)
 
4148
     char *str;
 
4149
     integer *x;
 
4150
     integer *y;
 
4151
     integer *v1;
 
4152
     integer *v2;
 
4153
     integer *n;
 
4154
     integer *flag;
 
4155
     double *z;
 
4156
     double *alpha;
 
4157
     double *dx3;
 
4158
     double *dx4;
 
4159
 
4160
  char buf[20];
 
4161
  integer i ;
 
4162
  for (i=0 ; i< *n ; i++)
 
4163
    {
 
4164
      sprintf(buf,ScilabXgc->CurNumberDispFormat,z[i]);
 
4165
      C2F(displaystring)(buf,&(x[i]),&(y[i]),PI0,flag,PI0,PI0,&(alpha[i]),PD0,PD0,PD0) ;
 
4166
    }
 
4167
}
 
4168
 
 
4169
void C2F(bitmap)(string, w, h)
 
4170
     char *string;
 
4171
     integer w;
 
4172
     integer h;
 
4173
{
 
4174
  /** 
 
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);
 
4181
  **/
 
4182
}
 
4183
 
 
4184
/***********************************
 
4185
 * Fonts for the graphic windows 
 
4186
 ***********************************/
 
4187
 
 
4188
#define FONTNUMBER 7 
 
4189
#define FONTMAXSIZE 6
 
4190
#define SYMBOLNUMBER 10
 
4191
 
 
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]
 
4199
*/
 
4200
 
 
4201
typedef struct tagFontInfo { 
 
4202
  integer ok;
 
4203
  char fname[100];
 
4204
  HFONT hf[FONTMAXSIZE];
 
4205
} FontInfoT[FONTNUMBER];
 
4206
 
 
4207
static int scale_font_size = 1;
 
4208
static FontInfoT FontInfoTab;           /** for screen **/ 
 
4209
static FontInfoT FontInfoTabPrinter;    /** for printer **/ 
 
4210
 
 
4211
static FontInfoT *FontTab = &FontInfoTab;
 
4212
 
 
4213
static char *size_[] = { "08" ,"10","12","14","18","24"};
 
4214
static int size_n_[] = {8,10,12,14,18,24};
 
4215
 
 
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 **/
 
4218
 
 
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;
 
4224
 
 
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,};
 
4229
 
 
4230
 
 
4231
/** To set the current font id  and size **/
 
4232
/** load the fonts into X11 if necessary **/
 
4233
 
 
4234
typedef  struct  {
 
4235
  char *alias;  char *name;  char *Winname;
 
4236
}  FontAlias;
 
4237
 
 
4238
/** ce qui suit marche sur 75dpi ou 100dpi **/
 
4239
 
 
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}
 
4248
};
 
4249
 
 
4250
/***********************************
 
4251
 * set current font to font fontid at size 
 
4252
 * fontsize ( <<load>> the font if necessary )
 
4253
 ***********************************/
 
4254
 
 
4255
void C2F(xsetfont)(fontid, fontsize, v3, v4)
 
4256
     integer *fontid;
 
4257
     integer *fontsize;
 
4258
     integer *v3;
 
4259
     integer *v4;
 
4260
 
4261
  integer i,fsiz;
 
4262
  i = Min(FONTNUMBER-1,Max(*fontid,0));
 
4263
  fsiz = Min(FONTMAXSIZE-1,Max(*fontsize,0));
 
4264
  if ( (*FontTab)[i].ok !=1 )
 
4265
    { 
 
4266
      if (i != 6 )
 
4267
        {
 
4268
          C2F(loadfamily)(fonttab[i].alias,&i,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
 
4269
        }
 
4270
      else 
 
4271
        {
 
4272
          sciprint(" The Font Id %d is not affected \r\n",(int)i);
 
4273
          Scistring(" use xlfont to set it \n");
 
4274
          return;
 
4275
        }
 
4276
    }
 
4277
  ScilabXgc->FontId = i;
 
4278
  ScilabXgc->FontSize = fsiz;
 
4279
  SelectFont(hdc, (*FontTab)[i].hf[fsiz]);
 
4280
}
 
4281
 
 
4282
static HFONT getcurfont()
 
4283
{
 
4284
  return( (*FontTab)[ScilabXgc->FontId].hf[ScilabXgc->FontSize]);
 
4285
}
 
4286
 
 
4287
/*********************************************
 
4288
 * To get the  id and size of the current font 
 
4289
 **********************************************/
 
4290
 
 
4291
void  C2F(xgetfont)(verbose, font, nargs,dummy)
 
4292
     integer *verbose;
 
4293
     integer *font;
 
4294
     integer *nargs;
 
4295
         double *dummy;
 
4296
{
 
4297
  *nargs=2;
 
4298
  font[0]= ScilabXgc->FontId ;
 
4299
  font[1] =ScilabXgc->FontSize ;
 
4300
  if (*verbose == 1) 
 
4301
    {
 
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]);
 
4306
    }
 
4307
}
 
4308
 
 
4309
/*********************************************
 
4310
 * To set the current mark ( a symbol in font symbol)
 
4311
 **********************************************/
 
4312
 
 
4313
void C2F(xsetmark)(number, size, v3, v4)
 
4314
     integer *number;
 
4315
     integer *size;
 
4316
     integer *v3;
 
4317
     integer *v4;
 
4318
 
4319
  ScilabXgc->CurHardSymb = Max(Min(SYMBOLNUMBER-1,*number),0);
 
4320
  ScilabXgc->CurHardSymbSize = Max(Min(FONTMAXSIZE-1,*size),0);
 
4321
}
 
4322
 
 
4323
 
 
4324
/*********************************************
 
4325
 * To get the current mark id 
 
4326
 **********************************************/
 
4327
 
 
4328
void C2F(xgetmark)(verbose, symb, narg,dummy)
 
4329
     integer *verbose;
 
4330
     integer *symb;
 
4331
     integer *narg;
 
4332
     double *dummy;
 
4333
{
 
4334
  *narg =2 ;
 
4335
  symb[0] = ScilabXgc->CurHardSymb ;
 
4336
  symb[1] = ScilabXgc->CurHardSymbSize ;
 
4337
  if (*verbose == 1) 
 
4338
    {
 
4339
      sciprint("\nMark : %d ",ScilabXgc->CurHardSymb);
 
4340
      sciprint("at size %s pts\r\n", size_[ScilabXgc->CurHardSymbSize]);
 
4341
    }
 
4342
}
 
4343
 
 
4344
/**************************************************
 
4345
 * loadfamily Loads a font at size  08 10 12 14 18 24 
 
4346
 * for example TimR08 TimR10 TimR12 TimR14 TimR18 TimR24 
 
4347
 * name is a string 
 
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
 **************************************************/
 
4354
 
 
4355
void C2F(loadfamily)(name, j, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
 
4356
     char *name;
 
4357
     integer *j,*v3,*v4,*v5,*v6,*v7;
 
4358
     double *dv1, *dv2,*dv3,*dv4;
 
4359
 
4360
  integer i;
 
4361
  /** our table of alias **/
 
4362
  i=0;
 
4363
  while ( fonttab[i].alias != (char *) NULL)
 
4364
    {
 
4365
      if (strcmp(fonttab[i].alias,name)==0)
 
4366
        {
 
4367
          C2F(loadfamily_n)(fonttab[i].Winname,j);
 
4368
          return ;
 
4369
        }
 
4370
      i++;
 
4371
    }
 
4372
  C2F(loadfamily_n)(name,j);
 
4373
}
 
4374
 
 
4375
void C2F(queryfamily)(name, j, v3, v4, v5, v6, v7, dv1, dv2, dv3, dv4)
 
4376
     char *name;
 
4377
     integer *j;
 
4378
     integer *v3;
 
4379
     integer *v4;
 
4380
     integer *v5;
 
4381
     integer *v6;
 
4382
     integer *v7;
 
4383
     double *dv1;
 
4384
     double *dv2;
 
4385
     double *dv3;
 
4386
     double *dv4;
 
4387
 
4388
  integer i ;
 
4389
  name[0]='\0';
 
4390
  for (i=0;i<FONTNUMBER;i++) {
 
4391
    v3[i]=strlen((*FontTab)[i].fname);
 
4392
    if (v3[i] > 0)
 
4393
      strcat(name,(*FontTab)[i].fname);
 
4394
    else {
 
4395
      v3[i]=strlen(fonttab[i].Winname);
 
4396
       strcat(name,fonttab[i].Winname);
 
4397
    }
 
4398
  }
 
4399
  *j=FONTNUMBER;
 
4400
}
 
4401
 
 
4402
/** creates a font **/
 
4403
 
 
4404
void SciMakeFont(name,size,hfont)
 
4405
     char *name;
 
4406
     int size;
 
4407
     HFONT *hfont;
 
4408
{
 
4409
  LOGFONT lf;
 
4410
  char *p;
 
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';
 
4418
    lf.lfItalic = TRUE;
 
4419
  }
 
4420
  if ( (p = strstr(name," Bold")) != (LPSTR)NULL ) {
 
4421
    lf.lfFaceName[ (unsigned int)(p- name) ] = '\0';
 
4422
    lf.lfWeight = FW_BOLD;
 
4423
  }
 
4424
  *hfont = CreateFontIndirect((LOGFONT FAR *)&lf);
 
4425
}
 
4426
 
 
4427
static void C2F(loadfamily_n)(name, j)
 
4428
     char *name;
 
4429
     integer *j;
 
4430
 
4431
  integer i,flag=1 ;
 
4432
  for ( i = 0; i < FONTMAXSIZE ; i++)
 
4433
    {
 
4434
      SciMakeFont(name,size_n_[i], &((*FontTab)[*j].hf[i]));
 
4435
      if  (  (*FontTab)[*j].hf[i] == (HFONT) 0 )
 
4436
        { 
 
4437
          flag=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)
 
4442
            {
 
4443
              sciprint("Unknown font : %s\r\n","Courier New");
 
4444
              Scistring("  Please send a bug report !\r\n");
 
4445
            }
 
4446
        }
 
4447
    }
 
4448
  (*FontTab)[*j].ok = 1;
 
4449
  if (flag != 0) 
 
4450
    strcpy((*FontTab)[*j].fname,name);
 
4451
  else
 
4452
    strcpy((*FontTab)[*j].fname,"Courier New");
 
4453
}
 
4454
 
 
4455
/********************************************
 
4456
 * switch to printer font 
 
4457
 ********************************************/
 
4458
 
 
4459
void SciG_Font_Printer(int scale)
 
4460
{
 
4461
  static int last_scale= -1;
 
4462
  FontTab = &FontInfoTabPrinter;
 
4463
  SymbOffset = &ListOffsetPrint;
 
4464
  if ( last_scale != -1 && last_scale != scale ) 
 
4465
    CleanFonts();
 
4466
  scale_font_size = last_scale = scale;
 
4467
  LoadFonts();
 
4468
}
 
4469
 
 
4470
void SciG_Font(void) 
 
4471
{
 
4472
  FontTab = &FontInfoTab;
 
4473
  SymbOffset = &ListOffset;
 
4474
  scale_font_size = 1; 
 
4475
}
 
4476
 
 
4477
void CleanFonts()
 
4478
{
 
4479
  int i,j;
 
4480
  for ( j= 0 ; j < FONTNUMBER  ; j++ )
 
4481
    {
 
4482
      if ( (*FontTab)[j].ok == 1) 
 
4483
        {
 
4484
          (*FontTab)[j].ok = 0;
 
4485
          for ( i = 0; i < FONTMAXSIZE ; i++)
 
4486
            {
 
4487
              DeleteObject( (*FontTab)[j].hf[i]) ;
 
4488
              (*FontTab)[j].hf[i] = (HFONT) 0;
 
4489
            }
 
4490
        }
 
4491
    }
 
4492
}
 
4493
 
 
4494
/********************************************
 
4495
 * Initial set of font loaded at startup 
 
4496
 ********************************************/
 
4497
 
 
4498
static void LoadFonts()
 
4499
{
 
4500
  integer fnum;
 
4501
  C2F(loadfamily)("CourR",(fnum=0,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
 
4502
  LoadSymbFonts();
 
4503
  C2F(loadfamily)("TimR",(fnum=2,&fnum),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
 
4504
  /*  
 
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); 
 
4509
      See xsetfont
 
4510
      */
 
4511
}
 
4512
 
 
4513
 
 
4514
static void
 
4515
LoadSymbFonts()
 
4516
{
 
4517
  /** XCharStruct xcs;**/
 
4518
  integer j,fid;
 
4519
  integer i;
 
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++)
 
4526
    {
 
4527
      if ( (*FontTab)[1].hf[i] != NULL)
 
4528
        {
 
4529
          SelectFont(hdc, (*FontTab)[fid].hf[i]);
 
4530
          for (j=0 ; j < SYMBOLNUMBER ; j++)
 
4531
            {
 
4532
              SIZE size;
 
4533
              char str[1];
 
4534
              str[0]=Marks[j];
 
4535
              GetTextExtentPoint32(hdc,str,1,&size);
 
4536
              SymbOffset->xoffset[i][j] = size.cx /2;
 
4537
              SymbOffset->yoffset[i][j] = size.cy /2;
 
4538
            }
 
4539
        }
 
4540
    }
 
4541
}
 
4542
 
 
4543
/** The two next functions send the x and y offsets to center the current **/
 
4544
/** symbol at point (x,y) **/
 
4545
 
 
4546
int C2F(CurSymbXOffset)()
 
4547
{
 
4548
  return(- SymbOffset->xoffset[ScilabXgc->CurHardSymbSize]
 
4549
         [ScilabXgc->CurHardSymb]);
 
4550
}
 
4551
int C2F(CurSymbYOffset)()
 
4552
{
 
4553
  return( SymbOffset->yoffset[ScilabXgc->CurHardSymbSize]
 
4554
          [ScilabXgc->CurHardSymb]);
 
4555
}
 
4556
 
 
4557
/********************************************
 
4558
 * Draws the current mark centred at position 
 
4559
 * x,y
 
4560
 ********************************************/
 
4561
 
 
4562
static void DrawMark(lhdc,x, y)
 
4563
     HDC lhdc;
 
4564
     integer *x;
 
4565
     integer *y;
 
4566
{
 
4567
  char str[2];
 
4568
#ifdef DEBUG 
 
4569
  SIZE size ;
 
4570
#endif 
 
4571
  str[0]=Marks[ScilabXgc->CurHardSymb];
 
4572
  str[1]='\0';
 
4573
  if ( ScilabXgc->CurDrawFunction ==  GXxor )
 
4574
    {
 
4575
      SIZE size ;
 
4576
      GetTextExtentPoint32(hdc,str,1,&size);
 
4577
      XorString(*x+C2F(CurSymbXOffset)(),*y+C2F(CurSymbYOffset)(),
 
4578
                str,size.cx,size.cy);
 
4579
    }
 
4580
  else
 
4581
    {
 
4582
      TextOut(hdc,*x+C2F(CurSymbXOffset)(),*y+C2F(CurSymbYOffset)(),str,1); 
 
4583
    }
 
4584
#ifdef DEBUG
 
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 ,
 
4590
            (int) *y);
 
4591
#endif
 
4592
}
 
4593
 
 
4594
/*-------------------------------------------------------------------
 
4595
\subsection{Allocation and storing function for vectors of X11-points}
 
4596
------------------------------------------------------------------------*/
 
4597
 
 
4598
static POINT *points;
 
4599
static unsigned nbpoints;
 
4600
#define NBPOINTS 256 
 
4601
 
 
4602
int C2F(store_points)(n, vx, vy, onemore)
 
4603
     integer n;
 
4604
     integer *vx;
 
4605
     integer *vy;
 
4606
     integer onemore;
 
4607
 
4608
  integer i,n1;
 
4609
  if ( onemore == 1) n1=n+1;
 
4610
  else n1=n;
 
4611
  if (ReallocVector(n1) == 1)
 
4612
    {
 
4613
      for (i = 0; i < n; i++){
 
4614
#ifdef DEBUG
 
4615
        if ( Abs(vx[i]) > int16max )
 
4616
          {
 
4617
            fprintf(stderr,"Warning store_point oustide of 16bits x=%d\n",
 
4618
                    (int) vx[i]);
 
4619
          }
 
4620
        if ( Abs(vy[i]) > int16max )
 
4621
          {
 
4622
            fprintf(stderr,"Warning store_point oustide of 16bits x=%d\n",
 
4623
                    (int) vy[i]);
 
4624
          }
 
4625
#endif
 
4626
        points[i].x =(short) vx[i];
 
4627
        points[i].y =(short) vy[i];
 
4628
      }
 
4629
      if (onemore == 1) {
 
4630
        points[n].x=(short) points[0].x;
 
4631
        points[n].y=(short) points[0].y;
 
4632
      }
 
4633
      return(1);
 
4634
    }
 
4635
  else return(0);
 
4636
}
 
4637
 
 
4638
static int ReallocVector(n)
 
4639
     integer n;
 
4640
{
 
4641
  while ( (unsigned) n > nbpoints){
 
4642
    nbpoints = 2 * nbpoints ;
 
4643
    points = (POINT *) REALLOC(points,(unsigned)
 
4644
                                 nbpoints * sizeof (POINT));
 
4645
    if (points == 0) 
 
4646
      { 
 
4647
        sciprint(MESSAGE5);
 
4648
        return (0);
 
4649
      }
 
4650
  }
 
4651
  return(1);
 
4652
}
 
4653
 
 
4654
int C2F(AllocVectorStorage)()
 
4655
{
 
4656
  nbpoints = NBPOINTS;
 
4657
  points = (POINT *) MALLOC( nbpoints * sizeof (POINT)); 
 
4658
  if ( points == 0) { sciprint(MESSAGE4);return(0);}
 
4659
  else return(1);
 
4660
}
 
4661
 
 
4662
static POINT *C2F(ReturnPoints)() { return(points); }
 
4663
 
 
4664
/**  Clipping functions **/
 
4665
/** XXXX a isoler des p'eripheriques car c'est utilis'e dans plot3d **/
 
4666
 
 
4667
/* My own clipping routines  
 
4668
  XDrawlines with clipping on the current graphic window 
 
4669
  to ovoid trouble on some X servers **/
 
4670
 
 
4671
static integer xleft,xright,ybot,ytop;
 
4672
 
 
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.
 
4680
 */
 
4681
 
 
4682
static int clip_point(x, y)
 
4683
integer x, y;
 
4684
{
 
4685
    integer ret_val = 0;
 
4686
 
 
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;
 
4691
    return ret_val;
 
4692
}
 
4693
 
 
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 
 
4698
        1  : (x1,y1) changed 
 
4699
        2  : (x2,y2) changed 
 
4700
        3  : (x1,y1) and (x2,y2) changed 
 
4701
        4  : segment in 
 
4702
 */
 
4703
 
 
4704
 
 
4705
void set_clip_box(xxleft,xxright,yybot,yytop)
 
4706
     integer xxleft,xxright,yybot,yytop;
 
4707
{
 
4708
  xleft=xxleft;
 
4709
  xright=xxright;
 
4710
  ybot=yybot;
 
4711
  ytop=yytop;
 
4712
}
 
4713
 
 
4714
void
 
4715
clip_line(x1, yy1, x2, y2, x1n, yy1n, x2n, y2n, flag)
 
4716
     integer x1, yy1, x2, y2, *flag, *x1n, *yy1n, *x2n, *y2n;
 
4717
{
 
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);
 
4722
    if (pos1 || pos2) {
 
4723
        if (pos1 & pos2) { *flag=0;return;}       
 
4724
        /* segment is totally out. */
 
4725
 
 
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.
 
4729
         */
 
4730
        count = 0;
 
4731
        dx = x2 - x1;
 
4732
        dy = y2 - yy1;
 
4733
 
 
4734
        /* Find intersections with the x parallel bbox lines: */
 
4735
        if (dy != 0) {
 
4736
            x = (int) ((ybot - y2)  * ((double) dx / (double) dy) + x2);
 
4737
            /* Test for ybot boundary. */
 
4738
            if (x >= xleft && x <= xright) {
 
4739
                x_intr[count] = x;
 
4740
                y_intr[count++] = ybot;
 
4741
            }
 
4742
            x = (int) ((ytop - y2) * ((double) dx / (double) dy) + x2); 
 
4743
            /* Test for ytop boundary. */
 
4744
            if (x >= xleft && x <= xright) {
 
4745
                x_intr[count] = x;
 
4746
                y_intr[count++] = ytop;
 
4747
            }
 
4748
        }
 
4749
 
 
4750
        /* Find intersections with the y parallel bbox lines: */
 
4751
        if (dx != 0) {
 
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;
 
4757
            }
 
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;
 
4763
            }
 
4764
        }
 
4765
 
 
4766
        if (count == 2) {
 
4767
            if (pos1 && pos2) {    /* Both were out - update both */
 
4768
                *x1n = x_intr[0];
 
4769
                *yy1n = y_intr[0];
 
4770
                *x2n = x_intr[1];
 
4771
                *y2n = y_intr[1];
 
4772
                *flag=3;return;
 
4773
              }
 
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) {
 
4776
                    *x1n = x_intr[0];
 
4777
                    *yy1n = y_intr[0];
 
4778
                    *flag=1;return;
 
4779
                }
 
4780
                else {
 
4781
                    *x1n = x_intr[1];
 
4782
                    *yy1n = y_intr[1];
 
4783
                    *flag=1;return;
 
4784
                }
 
4785
            }
 
4786
            else {               /* Only x2/y2 was out - update only it */
 
4787
                if (dx * (x_intr[0] - x1) + dy * (y_intr[0] - yy1) >= 0) {
 
4788
                    *x2n = x_intr[0];
 
4789
                    *y2n = y_intr[0];
 
4790
                    *flag=2;return;
 
4791
                }
 
4792
                else {
 
4793
                    *x2n = x_intr[1];
 
4794
                    *y2n = y_intr[1];
 
4795
                    *flag=2;return;
 
4796
                }
 
4797
              }
 
4798
          }
 
4799
        else 
 
4800
          {
 
4801
            /* count != 0 */
 
4802
            *flag=0;return;
 
4803
          }
 
4804
      }
 
4805
  }
 
4806
 
 
4807
 
 
4808
 
 
4809
 
 
4810
/* 
 
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 
 
4814
 */
 
4815
 
 
4816
integer first_in(n, ideb, vx, vy)
 
4817
     integer n;
 
4818
     integer ideb;
 
4819
     integer *vx;
 
4820
     integer *vy;
 
4821
{
 
4822
  integer i;
 
4823
  for (i=ideb  ; i < n ; i++)
 
4824
    {
 
4825
      if (vx[i]>= xleft && vx[i] <= xright  && vy[i] >= ybot && vy[i] <= ytop)
 
4826
        {
 
4827
#ifdef DEBUG
 
4828
          sciprint("first in %d->%d=(%d,%d)\r\n",ideb,i,vx[i],vy[i]);
 
4829
#endif
 
4830
          return(i);
 
4831
        }
 
4832
    }
 
4833
  return(-1);
 
4834
}
 
4835
 
 
4836
/* 
 
4837
 *  returns the first (vx[.],vy[.]) point outside
 
4838
 *  xleft,xright,ybot,ytop bbox.
 
4839
 *  or zero if the whole polyline is out 
 
4840
 */
 
4841
 
 
4842
integer first_out(n, ideb, vx, vy)
 
4843
     integer n;
 
4844
     integer ideb;
 
4845
     integer *vx;
 
4846
     integer *vy;
 
4847
{
 
4848
  integer i;
 
4849
  for (i=ideb  ; i < n ; i++)
 
4850
    {
 
4851
      if ( vx[i]< xleft || vx[i]> xright  || vy[i] < ybot || vy[i] > ytop) 
 
4852
        {
 
4853
#ifdef DEBUG
 
4854
          sciprint("first out %d->%d=(%d,%d)\r\n",ideb,i,vx[i],vy[i]);
 
4855
#endif
 
4856
          return(i);
 
4857
        }
 
4858
    }
 
4859
  return(-1);
 
4860
}
 
4861
int CheckScilabXgc()
 
4862
{
 
4863
  return( ScilabXgc != (struct BCG *) 0);
 
4864
}