/* convenience wrapper */ void GEaddDevice2(pGEDevDesc gdd, const char *name) { gsetVar(R_DeviceSymbol, mkString(name), R_BaseEnv); GEaddDevice(gdd); GEinitDisplayList(gdd); }
SEXP MingSWFNew(SEXP file, SEXP height, SEXP width, SEXP scale, SEXP version, SEXP bg, SEXP fonts, SEXP initAS, SEXP labelMethod){ int bgcolor = RGBpar(bg,0); /* R Graphics Device: in GraphicsDevice.h */ pDevDesc RGD; /* R Graphics Engine: in GraphicsEngine.h */ pGEDevDesc RGE; /* Ming Graphics Device */ MingSWFDesc *MGD; if (!(RGD = (pDevDesc)calloc(1, sizeof(NewDevDesc)))) return R_NilValue; if (!(MGD = (MingSWFDesc *)calloc(1, sizeof(MingSWFDesc)))){ free(RGD); error("unable to start device mingswf"); return R_NilValue; } MGD->version = asInteger(version); Ming_setScale(asInteger(scale));/* default for library is 20 */ MGD->movie = newSWFMovieWithVersion(MGD->version); MGD->file=(char *)CHAR(STRING_ELT(file,0)); /* Initialize SWF file */ SWFMovie_setDimension(MGD->movie,asReal(width),asReal(height)); SWFMovie_setBackground(MGD->movie, REDC(bgcolor), GREENC(bgcolor), BLUEC(bgcolor)); SWFMovie_setRate(MGD->movie, 1.0); SWFMovie_setNumberOfFrames(MGD->movie, 1); SWFMovie_add(MGD->movie,newSWFInitAction(newSWFAction( "_root.createEmptyMovieClip('popup',65534);" "_root.popup._visible = false;" "_root.popup.createTextField('Label',65535,0,0,0,0);" "_root.popup.Label.multiline = true;" "_root.popup.Label.html = true;" "_root.movePopUp = function (){" " if (_root._xmouse <= _root.popup.Label._width+20){" " _root.popup._x = _root._xmouse+20;" " } else {" " _root.popup._x = _root._xmouse-_root.popup.Label._width-10;" " }" " if (_root._ymouse <= _root.popup.Label._height+20){" " _root.popup._y = _root._ymouse+15;" " } else {" " _root.popup._y = _root._ymouse-_root.popup.Label._height-10;" " }" " updateAfterEvent();" "};" "_root.showPopUp = function(obj){" " _root.popup.Label.htmlText = obj.Label;" " obj.oldAlpha = obj._alpha;" " obj._alpha = 50;" " _root.popup.Label.autoSize = true;" " _root.popup.lineStyle(20,0xc2c2c2);" " _root.popup.beginFill(0xc2c2c2);" " _root.popup.moveTo(0,0);" " _root.popup.lineTo(_root.popup.Label._width-5,0);" " _root.popup.lineTo(_root.popup.Label._width-5,_root.popup.Label._height-5);" " _root.popup.lineTo(0,_root.popup.Label._height-5);" " _root.popup.lineTo(0,0);" " _root.popup._visible = true;" " obj.onMouseMove = _root.movePopUp;" " _root.movePopUp();" "};" "_root.hidePopUp = function(obj){" " obj._alpha = obj.oldAlpha;" " delete obj.onMouseMove;" " _root.popup.clear();" " _root.popup._visible = false;" "};" ))); RGD->deviceSpecific = (void *) MGD; /* Callbacks */ RGD->close = MingSWFClose; RGD->activate = MingSWFActivate; RGD->deactivate = MingSWFDeactivate; RGD->size = MingSWFSize; RGD->newPage = MingSWFNewPage; RGD->clip = MingSWFClip; RGD->strWidth = MingSWFStrWidth; RGD->text = MingSWFText; RGD->rect = MingSWFRect; RGD->circle = MingSWFCircle; RGD->line = MingSWFLine; RGD->polyline = MingSWFPolyline; RGD->polygon = MingSWFPolygon; RGD->locator = MingSWFLocator; RGD->mode = MingSWFMode; RGD->metricInfo = MingSWFMetricInfo; RGD->hasTextUTF8 = TRUE; RGD->strWidthUTF8 = MingSWFStrWidth; RGD->textUTF8 = MingSWFText; RGD->wantSymbolUTF8 = TRUE; /* Initialise RGD */ RGD->left = RGD->clipLeft = 0; RGD->top = RGD->clipTop = 0; RGD->right = RGD->clipRight = asReal(width); RGD->bottom = RGD->clipBottom = asReal(height); RGD->xCharOffset = 0.4900; RGD->yCharOffset = 0.3333; RGD->yLineBias = 0.1; RGD->ipr[0] = 1.0/72.0; RGD->ipr[1] = 1.0/72.0; RGD->cra[0] = 0.9 * 12; RGD->cra[1] = 1.2 * 12; RGD->gamma = 1.0; RGD->canClip = FALSE; RGD->canChangeGamma = FALSE; RGD->canHAdj = 2; RGD->startps = 12.0; RGD->startcol = R_RGB(0,0,0); RGD->startfill = 0xffffffff; RGD->startlty = LTY_SOLID; RGD->startfont = 1; RGD->startgamma = RGD->gamma; RGD->displayListOn = TRUE; /* Add to the device list */ RGE = GEcreateDevDesc(RGD); MGD->RGE = RGE; GEaddDevice(RGE); GEinitDisplayList(RGE); return ScalarInteger(1 + GEdeviceNumber(RGE)); }
SEXP canvas_new_device(SEXP args) { /* R Graphics Device: in GraphicsDevice.h */ pDevDesc RGD; /* R Graphics Engine: in GraphicsEngine.h */ pGEDevDesc RGE; /* canvas Graphics Device */ canvasDesc *cGD; FILE *fp = NULL; int width, height, bgcolor; SEXP v; args=CDR(args); v=CAR(args); args=CDR(args); if (isString(v)){ PROTECT(v); fp = fopen(CHAR(STRING_ELT(v,0)),"w"); UNPROTECT(1); if (fp == NULL) error("could not open file"); } else { error("file must be a filename"); } v=CAR(args); args=CDR(args); if (!isNumeric(v)) {fclose(fp); error("`width' must be a number");} width=asInteger(v); v=CAR(args); args=CDR(args); if (!isNumeric(v)) {fclose(fp); error("`height' must be a number");} height=asInteger(v); v=CAR(args); args=CDR(args); if (!isString(v) && !isInteger(v) && !isLogical(v) && !isReal(v)) error("invalid color specification for `bg'"); bgcolor = RGBpar(v, 0); #ifdef CANVASDEBUG Rprintf("canvas_new_device(width=%d,height=%d,fd=%x)\n", width, height, fp); #endif R_CheckDeviceAvailable(); if (!(RGD = (pDevDesc)calloc(1, sizeof(NewDevDesc)))){ fclose(fp); error("calloc failed for canvas device"); } if (!(cGD = (canvasDesc *)calloc(1, sizeof(canvasDesc)))){ free(RGD); fclose(fp); error("calloc failed for canvas device"); } cGD->fp = fp; RGD->deviceSpecific = (void *) cGD; /* Callbacks */ RGD->close = canvasClose; RGD->activate = canvasActivate; RGD->deactivate = canvasDeactivate; RGD->size = canvasSize; RGD->newPage = canvasNewPage; RGD->clip = canvasClip; RGD->strWidth = canvasStrWidth; RGD->text = canvasText; RGD->rect = canvasRect; RGD->circle = canvasCircle; RGD->line = canvasLine; RGD->polyline = canvasPolyline; RGD->polygon = canvasPolygon; RGD->locator = canvasLocator; RGD->mode = canvasMode; RGD->metricInfo = canvasMetricInfo; RGD->hasTextUTF8 = TRUE; RGD->strWidthUTF8 = canvasStrWidth; RGD->textUTF8 = canvasText; RGD->wantSymbolUTF8 = TRUE; /* Initialise RGD */ RGD->left = RGD->clipLeft = 0; RGD->top = RGD->clipTop = 0; RGD->right = RGD->clipRight = width; RGD->bottom = RGD->clipBottom = height; RGD->xCharOffset = 0.4900; RGD->yCharOffset = 0.3333; RGD->yLineBias = 0.1; RGD->ipr[0] = 1.0/72.0; RGD->ipr[1] = 1.0/72.0; RGD->cra[0] = 0.9 * 10; RGD->cra[1] = 1.2 * 10; RGD->gamma = 1.0; RGD->canClip = FALSE; RGD->canChangeGamma = FALSE; RGD->canHAdj = 2; RGD->startps = 10.0; RGD->startcol = R_RGB(0,0,0); RGD->startfill = bgcolor; RGD->startlty = LTY_SOLID; RGD->startfont = 1; RGD->startgamma = RGD->gamma; RGD->displayListOn = FALSE; /* Add to the device list */ RGE = GEcreateDevDesc(RGD); cGD->RGE = RGE; GEaddDevice(RGE); GEinitDisplayList(RGE); /*return ScalarInteger(1 + GEdeviceNumber(RGE));*/ return R_NilValue; }