The R Project SVN R

Rev

Rev 26207 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13365 ripley 1
/*
2
 *  RProxy: Connector implementation between application and R language
3
 *  Copyright (C) 2000--2001 Thomas Baier
4
 *
5
 *  This library is free software; you can redistribute it and/or
6
 *  modify it under the terms of the GNU Library General Public
7
 *  License as published by the Free Software Foundation; either
8
 *  version 2 of the License, or (at your option) any later version.
26207 murdoch 9
 *
13365 ripley 10
 *  This library is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 *  Library General Public License for more details.
26207 murdoch 14
 *
13365 ripley 15
 *  You should have received a copy of the GNU Library General Public
16
 *  License along with this library; if not, write to the Free
17
 *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18
 *  MA 02111-1307, USA
19
 *
27236 murrell 20
 *  $Id: rproxy_dev.c,v 1.7 2003/11/26 20:50:15 murrell Exp $
13365 ripley 21
 */
22
 
26207 murdoch 23
/* virtual device size */
13365 ripley 24
#define DEV_X 500
25
#define DEV_Y 500
26
 
27
#ifdef HAVE_CONFIG_H
28
#include <Rconfig.h>
29
#endif
30
 
31
#include "Defn.h"
32
#include "Graphics.h"
33
#include <stdio.h>
34
#include <windows.h>
35
 
36
#include "SC_proxy.h"
37
 
38
extern SC_GraphicsDevice* __graphics_device;
39
 
17227 murrell 40
static void R_Proxy_Graphics_Activate (NewDevDesc* pDD)
13365 ripley 41
{
42
  if (__graphics_device)
43
    {
44
      __graphics_device->vtbl->activate (__graphics_device);
45
      return;
46
    }
47
}
48
 
49
#ifdef MessageBox
50
#undef MessageBox
51
#endif
52
#define MessageBox(a,b,c,d)
53
 
17227 murrell 54
static void R_Proxy_Graphics_Activate(NewDevDesc *dd);
55
static void R_Proxy_Graphics_Circle(double x, double y, double r,
27236 murrell 56
				    R_GE_gcontext *gc,
57
				    NewDevDesc *dd);
26207 murdoch 58
static void R_Proxy_Graphics_Clip(double x0, double x1, double y0, double y1,
17227 murrell 59
		     NewDevDesc *dd);
60
static void R_Proxy_Graphics_Close(NewDevDesc *dd);
61
static void R_Proxy_Graphics_Deactivate(NewDevDesc *dd);
62
static void R_Proxy_Graphics_Hold(NewDevDesc *dd);
63
static Rboolean R_Proxy_Graphics_Locator(double *x, double *y, NewDevDesc *dd);
64
static void R_Proxy_Graphics_Line(double x1, double y1, double x2, double y2,
27236 murrell 65
				  R_GE_gcontext *gc,
66
				  NewDevDesc *dd);
67
static void R_Proxy_Graphics_MetricInfo(int c, 
68
					R_GE_gcontext *gc,
69
					double* ascent, double* descent,
70
					double* width, NewDevDesc *dd);
17227 murrell 71
static void R_Proxy_Graphics_Mode(int mode, NewDevDesc *dd);
27236 murrell 72
static void R_Proxy_Graphics_NewPage(R_GE_gcontext *gc,
73
				     NewDevDesc *dd);
26207 murdoch 74
static void R_Proxy_Graphics_Polygon(int n, double *x, double *y,
27236 murrell 75
				     R_GE_gcontext *gc,
76
				     NewDevDesc *dd);
26207 murdoch 77
static void R_Proxy_Graphics_Polyline(int n, double *x, double *y,
27236 murrell 78
				      R_GE_gcontext *gc,
79
				      NewDevDesc *dd);
17227 murrell 80
static void R_Proxy_Graphics_Rect(double x0, double y0, double x1, double y1,
27236 murrell 81
				  R_GE_gcontext *gc,
82
				  NewDevDesc *dd);
17227 murrell 83
static void R_Proxy_Graphics_Size(double *left, double *right,
27236 murrell 84
				  double *bottom, double *top,
85
				  NewDevDesc *dd);
17511 ripley 86
#ifdef UNUSED
17227 murrell 87
static void R_Proxy_Graphics_Resize(NewDevDesc *dd);
17511 ripley 88
#endif
27236 murrell 89
static double R_Proxy_Graphics_StrWidth(char *str, 
90
					R_GE_gcontext *gc,
91
					NewDevDesc *dd);
26207 murdoch 92
static void R_Proxy_Graphics_Text(double x, double y, char *str,
27236 murrell 93
				  double rot, double hadj,
94
				  R_GE_gcontext *gc,
95
				  NewDevDesc *dd);
17227 murrell 96
static Rboolean R_Proxy_Graphics_Open (NewDevDesc* pDD,
97
				       void* pAXD,
98
				       char* pDisplay,
99
				       double pWidth,
100
				       double pHeight,
101
				       Rboolean pRecording,
102
				       int pResize);
103
 
26207 murdoch 104
/* 00-06-22 | baier | added line type and width */
13365 ripley 105
static void R_Proxy_Graphics_Circle (double pX,
106
				     double pY,
107
				     double pRad,
27236 murrell 108
				     R_GE_gcontext *gc,
17227 murrell 109
				     NewDevDesc* pDD)
13365 ripley 110
{
111
  if (__graphics_device)
112
    {
113
      __graphics_device->vtbl->circle (__graphics_device,
114
				       pX,
115
				       pY,
116
				       pRad,
27236 murrell 117
				       gc->fill,
118
				       gc->col,
119
				       gc->lty,
120
				       gc->lwd);
13365 ripley 121
      return;
122
    }
123
 
124
  MessageBox (GetDesktopWindow (),"Circle()","R_Proxy_Graphics",MB_OK);
125
}
126
static void R_Proxy_Graphics_Clip (double pX0,
127
				   double pX1,
128
				   double pY0,
129
				   double pY1,
17227 murrell 130
				   NewDevDesc* pDD)
13365 ripley 131
{
132
  if (__graphics_device)
133
    {
134
      __graphics_device->vtbl->clip (__graphics_device,
135
				     pX0,pX1,pY0,pY1);
136
      return;
137
    }
138
 
139
  MessageBox (GetDesktopWindow (),"Clip()","R_Proxy_Graphics",MB_OK);
140
}
17227 murrell 141
static void R_Proxy_Graphics_Close (NewDevDesc* pDD)
13365 ripley 142
{
143
  if (__graphics_device)
144
    {
145
      __graphics_device->vtbl->close (__graphics_device);
146
      return;
147
    }
148
 
149
  MessageBox (GetDesktopWindow (),"Close()","R_Proxy_Graphics",MB_OK);
150
}
17227 murrell 151
static void R_Proxy_Graphics_Deactivate (NewDevDesc* pDD)
13365 ripley 152
{
153
  if (__graphics_device)
154
    {
155
      __graphics_device->vtbl->deactivate (__graphics_device);
156
      return;
157
    }
158
 
159
  MessageBox (GetDesktopWindow (),"Deactivate()","R_Proxy_Graphics",MB_OK);
160
}
17227 murrell 161
static void R_Proxy_Graphics_Hold (NewDevDesc* pDD)
13365 ripley 162
{
163
  if (__graphics_device)
164
    {
165
      __graphics_device->vtbl->hold (__graphics_device);
166
      return;
167
    }
168
 
169
  MessageBox (GetDesktopWindow (),"Hold()","R_Proxy_Graphics",MB_OK);
170
}
26207 murdoch 171
/* 00-06-22 | baier | added color, line type and width */
13365 ripley 172
static void R_Proxy_Graphics_Line (double pX0,
173
				   double pY0,
174
				   double pX1,
175
				   double pY1,
27236 murrell 176
				   R_GE_gcontext *gc,
17227 murrell 177
				   NewDevDesc* pDD)
13365 ripley 178
{
179
  if (__graphics_device)
180
    {
181
 
182
      __graphics_device->vtbl->line (__graphics_device,
27236 murrell 183
				     pX0,pY0,pX1,pY1,gc->col,
184
				     gc->lty,gc->lwd);
13365 ripley 185
      return;
186
    }
187
 
188
  MessageBox (GetDesktopWindow (),"Line()","R_Proxy_Graphics",MB_OK);
189
}
26207 murdoch 190
/* 01-01-25 | changed return type */
13365 ripley 191
static Rboolean R_Proxy_Graphics_Locator (double* pX,
192
					  double* pY,
17227 murrell 193
					  NewDevDesc* pDD)
13365 ripley 194
{
195
  if (__graphics_device)
196
    {
197
      return __graphics_device->vtbl->locator (__graphics_device,pX,pY);
198
    }
199
 
200
  MessageBox (GetDesktopWindow (),"Locator()","R_Proxy_Graphics",MB_OK);
201
  return 0;
202
}
17227 murrell 203
static void R_Proxy_Graphics_Mode (int pMode, NewDevDesc *dd)
13365 ripley 204
{
205
  if (__graphics_device)
206
    {
207
      __graphics_device->vtbl->mode (__graphics_device,pMode);
208
      return;
209
    }
210
 
211
  MessageBox (GetDesktopWindow (),"Mode()","R_Proxy_Graphics",MB_OK);
212
}
27236 murrell 213
static void R_Proxy_Graphics_NewPage (R_GE_gcontext *gc,
17227 murrell 214
				      NewDevDesc* pDD)
13365 ripley 215
{
216
  if (__graphics_device)
217
    {
218
      __graphics_device->vtbl->newpage (__graphics_device);
219
      return;
220
    }
221
 
222
  MessageBox (GetDesktopWindow (),"NewPage()","R_Proxy_Graphics",MB_OK);
223
}
26207 murdoch 224
/* 01-01-25 | baier | added new parameters "recording", "resize" */
17227 murrell 225
static Rboolean R_Proxy_Graphics_Open (NewDevDesc* pDD,
13365 ripley 226
				       void* pAXD,
227
				       char* pDisplay,
228
				       double pWidth,
229
				       double pHeight,
230
				       Rboolean pRecording,
231
				       int pResize)
232
{
233
  if (__graphics_device)
234
    {
235
      return __graphics_device->vtbl->open (__graphics_device,
236
					    pDisplay,pWidth,pHeight,0.0,0,0);
237
    }
238
 
239
  MessageBox (GetDesktopWindow (),"Open()","R_Proxy_Graphics",MB_OK);
240
  return 1;
241
}
17227 murrell 242
 
13365 ripley 243
static void R_Proxy_Graphics_Polygon (int pCount,
244
				      double* pX,
245
				      double* pY,
27236 murrell 246
				      R_GE_gcontext *gc,
17227 murrell 247
				      NewDevDesc* pDD)
13365 ripley 248
{
249
  if (__graphics_device)
250
    {
26207 murdoch 251
      /* convert coordinates here: don't use alloca() -> overflow? */
13365 ripley 252
      double* lX = (double*) malloc (pCount * sizeof (double));
253
      double* lY = (double*) malloc (pCount * sizeof (double));
254
      int i = 0;
255
 
26207 murdoch 256
      /* could use memcpy() for speed */
13365 ripley 257
      for (i = 0;i < pCount;i++)
258
	{
259
	  lX[i] = pX[i];
260
	  lY[i] = pY[i];
261
 
262
	}
263
 
27236 murrell 264
      /*      sprintf (x,"device::Polygon: bg is %08x, fg is %08x\n",fill,col); */
26207 murdoch 265
      /*      OutputDebugString (x); */
13365 ripley 266
      __graphics_device->vtbl->polygon (__graphics_device,
27236 murrell 267
					pCount,lX,lY,gc->fill,gc->col);
13365 ripley 268
 
269
      free (lX);
270
      free (lY);
271
 
272
      return;
273
    }
274
 
275
  MessageBox (GetDesktopWindow (),"Polygon()","R_Proxy_Graphics",MB_OK);
276
}
26207 murdoch 277
/* 01-01-23 | baier | added "col" parameter */
13365 ripley 278
static void R_Proxy_Graphics_Polyline (int pCount,
279
				       double* pX,
280
				       double* pY,
27236 murrell 281
				       R_GE_gcontext *gc,
17227 murrell 282
				       NewDevDesc* pDD)
13365 ripley 283
{
284
  if (__graphics_device)
285
    {
26207 murdoch 286
      /* convert coordinates here: don't use alloca() -> overflow? */
13365 ripley 287
      double* lX = (double*) malloc (pCount * sizeof (double));
288
      double* lY = (double*) malloc (pCount * sizeof (double));
289
      int i = 0;
290
 
26207 murdoch 291
      /* could use memcpy() for speed */
13365 ripley 292
      for (i = 0;i < pCount;i++)
293
	{
294
	  char x[1000];
295
	  lX[i] = pX[i];
296
	  lY[i] = pY[i];
297
 
298
	  sprintf (x,"Polyline: coord %d is %f/%f (was %f/%f)\n",
299
		   i,lX[i],lY[i],pX[i],pY[i]);
26207 murdoch 300
	  /*	  OutputDebugString (x); */
13365 ripley 301
 
302
	}
303
 
304
      __graphics_device->vtbl->polyline (__graphics_device,
27236 murrell 305
					 pCount,lX,lY,gc->col);
13365 ripley 306
 
307
      free (lX);
308
      free (lY);
309
 
310
      return;
311
    }
312
 
313
  MessageBox (GetDesktopWindow (),"Polyline()","R_Proxy_Graphics",MB_OK);
314
}
26207 murdoch 315
/* 00-06-22 | baier | added line type and width */
13365 ripley 316
static void R_Proxy_Graphics_Rect (double pX0,
317
				   double pY0,
318
				   double pX1,
319
				   double pY1,
27236 murrell 320
				   R_GE_gcontext *gc,
17227 murrell 321
				   NewDevDesc* pDD)
13365 ripley 322
{
323
  if (__graphics_device)
324
    {
325
 
326
      __graphics_device->vtbl->rect (__graphics_device,
27236 murrell 327
				     pX0,pY0,pX1,pY1,gc->fill,gc->col,
328
				     gc->lty,gc->lwd);
13365 ripley 329
      return;
330
    }
331
 
332
  MessageBox (GetDesktopWindow (),"Rect()","R_Proxy_Graphics",MB_OK);
333
}
17227 murrell 334
static void R_Proxy_Graphics_Size(double *left, double *right,
335
				  double *bottom, double *top,
336
				  NewDevDesc *pDD)
13365 ripley 337
{
17227 murrell 338
    *left = pDD->left;
339
    *right = pDD->right;
340
    *bottom = pDD->bottom;
341
    *top = pDD->top;
342
}
17511 ripley 343
 
344
#ifdef UNUSED
17227 murrell 345
static void R_Proxy_Graphics_Resize (NewDevDesc* pDD)
346
{
13365 ripley 347
  if (__graphics_device)
348
    {
349
      __graphics_device->vtbl->resize (__graphics_device);
350
      return;
351
    }
352
 
353
  MessageBox (GetDesktopWindow (),"Resize()","R_Proxy_Graphics",MB_OK);
354
}
17511 ripley 355
#endif
356
 
26207 murdoch 357
/* 00-06-22 | baier | added font and size parameters */
17227 murrell 358
static double R_Proxy_Graphics_StrWidth (char* pString,
27236 murrell 359
					 R_GE_gcontext *gc,
17227 murrell 360
					 NewDevDesc* pDD)
13365 ripley 361
{
362
  if (__graphics_device)
363
    {
27236 murrell 364
      int lSize = gc->cex * gc->ps + 0.5;
13365 ripley 365
      return __graphics_device->vtbl->strwidth (__graphics_device,
366
						pString,
27236 murrell 367
						gc->fontface,
13365 ripley 368
						lSize);
369
    }
370
 
371
  MessageBox (GetDesktopWindow (),"StrWidth()","R_Proxy_Graphics",MB_OK);
372
  return 0.0;
373
}
374
 
26207 murdoch 375
/* 00-06-22 | baier | added color, font and size */
13365 ripley 376
static void R_Proxy_Graphics_Text (double pX,
377
				   double pY,
378
				   char* pString,
379
				   double pRot,
380
				   double pHadj,
27236 murrell 381
				   R_GE_gcontext *gc,
17227 murrell 382
				   NewDevDesc* pDD)
13365 ripley 383
{
384
  if (__graphics_device)
385
    {
27236 murrell 386
      int lSize = gc->cex * gc->ps + 0.5;
13365 ripley 387
 
388
      __graphics_device->vtbl->text (__graphics_device,
389
				     pX,pY,pString,pRot,pHadj,
27236 murrell 390
				     gc->col,gc->fontface,lSize);
13365 ripley 391
      return;
392
    }
393
 
394
  MessageBox (GetDesktopWindow (),"Text()","R_Proxy_Graphics",MB_OK);
395
}
396
 
26207 murdoch 397
/* 00-06-22 | baier | added font and size parameters */
27236 murrell 398
static void R_Proxy_Graphics_MetricInfo(int c, 
399
					R_GE_gcontext *gc,
400
					double* ascent, double* descent,
401
					double* width, NewDevDesc *dd);
13365 ripley 402
static void R_Proxy_Graphics_MetricInfo (int pC,
27236 murrell 403
					 R_GE_gcontext *gc,
13365 ripley 404
					 double* pAscent,
405
					 double* pDescent,
406
					 double* pWidth,
17227 murrell 407
					 NewDevDesc* pDD)
13365 ripley 408
{
409
  if (__graphics_device)
410
    {
27236 murrell 411
      int lSize = gc->cex * gc->ps + 0.5;
13365 ripley 412
      __graphics_device->vtbl->metricinfo (__graphics_device,
413
					   pC,
414
					   pAscent,
415
					   pDescent,
416
					   pWidth,
27236 murrell 417
					   gc->fontface,
13365 ripley 418
					   lSize);
419
      return;
420
    }
421
 
422
  MessageBox (GetDesktopWindow (),"MetricInfo()","R_Proxy_Graphics",MB_OK);
423
}
424
 
26207 murdoch 425
/* 01-01-25 | baier | new paramters */
17227 murrell 426
int R_Proxy_Graphics_Driver (NewDevDesc* pDD,
13365 ripley 427
			     char* pDisplay,
428
			     double pWidth,
429
			     double pHeight,
430
			     double pPointSize,
431
			     Rboolean pRecording,
432
			     int pResize,
433
			     struct _SC_GraphicsDevice* pDevice)
434
{
17227 murrell 435
  pDD->startfont = 1;
436
  pDD->startps = pPointSize;
437
  pDD->startcol = 0;
438
  pDD->startfill = NA_INTEGER;
439
  pDD->startlty = LTY_SOLID;
440
  pDD->startgamma = 1;
13365 ripley 441
 
442
  /* init the device-specific functionality here */
443
  pDD->deviceSpecific = (void *) NULL;
444
 
445
  /* Start the Device Driver and Hardcopy.  */
446
  if (!R_Proxy_Graphics_Open (pDD,
447
			      NULL,
448
			      pDisplay,
449
			      pWidth,
450
			      pHeight,
451
			      pRecording,
452
			      pResize)) {
453
    return 0;
454
  }
455
  /* Set up Data Structures  */
456
 
17227 murrell 457
  pDD->newDevStruct = 1;
13365 ripley 458
 
17227 murrell 459
  pDD->open = R_Proxy_Graphics_Open;
460
  pDD->close = R_Proxy_Graphics_Close;
461
  pDD->activate = R_Proxy_Graphics_Activate;
462
  pDD->deactivate = R_Proxy_Graphics_Deactivate;
463
  pDD->size = R_Proxy_Graphics_Size;
464
  pDD->newPage = R_Proxy_Graphics_NewPage;
465
  pDD->clip = R_Proxy_Graphics_Clip;
466
  pDD->strWidth = R_Proxy_Graphics_StrWidth;
467
  pDD->text = R_Proxy_Graphics_Text;
468
  pDD->rect = R_Proxy_Graphics_Rect;
469
  pDD->circle = R_Proxy_Graphics_Circle;
470
  pDD->line = R_Proxy_Graphics_Line;
471
  pDD->polyline = R_Proxy_Graphics_Polyline;
472
  pDD->polygon = R_Proxy_Graphics_Polygon;
473
  pDD->locator = R_Proxy_Graphics_Locator;
474
  pDD->mode = R_Proxy_Graphics_Mode;
475
  pDD->hold = R_Proxy_Graphics_Hold;
476
  pDD->metricInfo = R_Proxy_Graphics_MetricInfo;
477
 
13365 ripley 478
    /* set graphics parameters that must be set by device driver */
479
    /* Window Dimensions in Pixels */
17227 murrell 480
  pDD->left = 0;	/* left */
481
  pDD->right = DEV_X;	/* right */
482
  pDD->top = 0;	/* top */
483
  pDD->bottom = DEV_Y;	/* bottom */
13365 ripley 484
 
485
 
486
  /* Nominal Character Sizes in Pixels */
17227 murrell 487
  pDD->cra[0] = 10;
488
  pDD->cra[1] = 10;
13365 ripley 489
  /* Character Addressing Offsets */
490
  /* These are used to plot a single plotting character */
491
  /* so that it is exactly over the plotting point */
492
 
17227 murrell 493
  pDD->xCharOffset = 0.50;
494
  pDD->yCharOffset = 0.40;
495
  pDD->yLineBias = 0.1;
13365 ripley 496
 
497
  /* Inches per raster unit */
498
 
17227 murrell 499
  pDD->ipr[0] = 1.0 / 72.0;
500
  pDD->ipr[1] = 1.0 / 72.0;
13365 ripley 501
 
502
    /* Device capabilities */
503
    /* Clipping is problematic for X11 */
504
    /* Graphics is clipped, text is not */
505
 
17227 murrell 506
  pDD->canResizePlot = 1;
507
  pDD->canChangeFont = 0;
508
  pDD->canRotateText = 1;
509
  pDD->canResizeText = 1;
510
  pDD->canClip = 1;
13365 ripley 511
 
512
  /* initialise x11 device description (most of the work */
513
  /* has been done in X11_Open) */
514
 
515
  pDD->displayListOn = 1;
516
  return 1;
517
}