The R Project SVN R

Rev

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