static Rboolean SWF_Open( pDevDesc deviceInfo ){ /* * Shortcut pointers to variables of interest. * It seems like there HAS to be a more elegent way of accesing * these... */ swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific; //Debug log if( swfInfo->debug == TRUE ){ if( !( swfInfo->logFile = fopen(R_ExpandFileName(swfInfo->logFileName), "w") ) ) return FALSE; fprintf(swfInfo->logFile, "SWF_Open: Begin swf output\n"); fprintf(swfInfo->logFile, "SWF_Open: Setting dimensions %6.1f by %6.1f\n", deviceInfo->right, deviceInfo->top); fprintf(swfInfo->logFile, "SWF_Open: Setting background %3d, %3d, %3d\n", R_RED(deviceInfo->startfill), R_GREEN(deviceInfo->startfill), R_BLUE(deviceInfo->startfill)); fflush(swfInfo->logFile); //Rprintf("%s",dashTo); } // Set the background color for the movie SWFMovie_setBackground(swfInfo->m, R_RED(deviceInfo->startfill), R_GREEN(deviceInfo->startfill), R_BLUE(deviceInfo->startfill)); SWFMovie_setDimension(swfInfo->m, deviceInfo->right, deviceInfo->top); // Set the frame rate for the movie SWFMovie_setRate(swfInfo->m, swfInfo->frameRate); // Set the total number of frames in the movie to 1 SWFMovie_setNumberOfFrames(swfInfo->m, 1); return TRUE; }
/* Initialize swf device specific data, for example swf movie object and initial fonts */ Rboolean swfSetupSWFInfo(pswfDesc swfInfo, const char *filename, double width, double height, const int *bg, float frameRate, SEXP env) { /* Filename */ strcpy(swfInfo->filename, filename); /* Movie object */ swfInfo->m = newSWFMovieWithVersion(8); /* Set swf background color */ SWFMovie_setBackground(swfInfo->m, bg[0], bg[1], bg[2]); /* Set movie frame rate */ SWFMovie_setRate(swfInfo->m, frameRate); /* Set movie dimension */ SWFMovie_setDimension(swfInfo->m, width * 72.0, height * 72.0); /* Set number of frames, only useful when you want to insert blank frames at the end of the movie. Otherwise it will be increased automatically every time you call SWFMovie_nextFrame() */ SWFMovie_setNumberOfFrames(swfInfo->m, 1); /* Pointer to the current frame (a MovieClip holding several shapes) */ swfInfo->currentFrame = NULL; /* Pointer to the clip layer, a SWFShape object */ swfInfo->currentClip = NULL; /* Initialize SWFArray, used to store SWFFillStyle objects and free them when movie is written to hard disk */ swfInfo->array = newSWFArray(100); /* An R environment in which the font list is stored. This serves as a "global" environment for plotting functions in C */ swfInfo->pkgEnv = env; /* Functions to draw font outline, used by swfTextUTF8() */ swfInfo->outlnFuns.move_to = outlineMoveTo; swfInfo->outlnFuns.line_to = outlineLineTo; swfInfo->outlnFuns.conic_to = outlineConicTo; swfInfo->outlnFuns.cubic_to = outlineCubicTo; swfInfo->outlnFuns.shift = 0; swfInfo->outlnFuns.delta = 0; return TRUE; }
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)); }
EXPORT BOOL WINAPI m_setFrames(int totalFrames, int p2, int p3, int p4) { lstrcpy(funcname, "m_setFrames"); SWFMovie_setNumberOfFrames(mhsp_movie, totalFrames); return 0; }