Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

flash.cc

Go to the documentation of this file.
00001 
00002 // Flash Plugin and Player
00003 // Copyright (C) 1998,1999 Olivier Debon
00004 // 
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 // 
00020 //  Author : Olivier Debon  <odebon@club-internet.fr>
00021 //  
00022 
00023 #include "swf.h"
00024 #include "graphic16.h"
00025 #include "graphic24.h"
00026 #include "graphic32.h"
00027 
00028 #ifdef RCSID
00029 static char *rcsid = "$Id: flash.cc,v 1.1.1.1 2002/01/25 22:14:58 kergoth Exp $";
00030 #endif
00031 
00032 // Interface with standard C
00033 extern "C" {
00034 
00035 FlashHandle
00036 FlashNew()
00037 {
00038         FlashMovie *fh;
00039 
00040         fh = new FlashMovie;
00041 
00042         fh->main = new CInputScript;
00043 
00044         return (FlashHandle)fh;
00045 }
00046 
00047 int
00048 FlashParse(FlashHandle flashHandle, int level, char *data, long size)
00049 {
00050         FlashMovie *fh;
00051         CInputScript *script;
00052         int status = FLASH_PARSE_ERROR;
00053 
00054         fh = (FlashMovie *)flashHandle;
00055 
00056         for(script = fh->main; script != NULL; script = script->next) {
00057                 if (script->level == level) {
00058                         status = script->ParseData(fh, data, size);
00059 
00060                         if (status & FLASH_PARSE_START) {
00061                                 fh->msPerFrame = 1000/fh->main->frameRate;
00062                                 script->program->rewindMovie();
00063                         }
00064                         break;
00065                 }
00066         }
00067 
00068         return status;
00069 }
00070 
00071 void
00072 FlashGetInfo(FlashHandle flashHandle, struct FlashInfo *fi)
00073 {
00074         FlashMovie *fh;
00075 
00076         fh = (FlashMovie *)flashHandle;
00077 
00078         fi->version = fh->main->m_fileVersion;
00079         fi->frameRate = fh->main->frameRate;
00080         fi->frameCount = fh->main->frameCount;
00081         fi->frameWidth = fh->main->frameRect.xmax - fh->main->frameRect.xmin;
00082         fi->frameHeight = fh->main->frameRect.ymax - fh->main->frameRect.ymin;
00083 }
00084 
00085 long FlashGraphicInit(FlashHandle flashHandle, FlashDisplay *fd)
00086 {
00087         FlashMovie *fh;
00088 
00089         fh = (FlashMovie *)flashHandle;
00090 
00091         switch (fd->bpp) {
00092                 case 4:
00093                         fh->gd = new GraphicDevice32(fd);
00094                         break;
00095                 case 3:
00096                         fh->gd = new GraphicDevice24(fd);
00097                         break;
00098                 case 2:
00099                         fh->gd = new GraphicDevice16(fd);
00100                         break;
00101                 default:
00102                         fprintf(stderr, "Unsupported depth\n");
00103         }
00104 
00105         fh->gd->setMovieDimension(fh->main->frameRect.xmax - fh->main->frameRect.xmin,
00106                                   fh->main->frameRect.ymax - fh->main->frameRect.ymin);
00107 
00108         return 1;       // Ok
00109 }
00110 
00111 void
00112 FlashSoundInit(FlashHandle flashHandle, char *device)
00113 {
00114         FlashMovie *fh;
00115 
00116         fh = (FlashMovie *)flashHandle;
00117 
00118         fh->sm = new SoundMixer(device);
00119 }
00120 
00121 void
00122 FlashZoom(FlashHandle flashHandle, int zoom)
00123 {
00124         FlashMovie *fh;
00125 
00126         fh = (FlashMovie *)flashHandle;
00127 
00128         fh->gd->setMovieZoom(zoom);
00129 }
00130 
00131 void
00132 FlashOffset(FlashHandle flashHandle, int x, int y)
00133 {
00134         FlashMovie *fh;
00135 
00136         fh = (FlashMovie *)flashHandle;
00137 
00138         fh->gd->setMovieOffset(x,y);
00139 }
00140 
00141 long
00142 FlashExec(FlashHandle flashHandle, long flag, 
00143           FlashEvent *fe, struct timeval *wakeDate)
00144 {
00145         FlashMovie *fh;
00146         long wakeUp = 0;
00147 
00148         fh = (FlashMovie *)flashHandle;
00149 
00150         if (fh->main == NULL) return 0; // Not ready
00151         if (fh->main->program == NULL) return 0; // Not ready
00152         if (fh->main->program->nbFrames == 0) return 0; // Still not ready
00153         if (fh->gd == 0) return 0;
00154 
00155         switch (flag & FLASH_CMD_MASK) {
00156                 case FLASH_STOP:
00157                         fh->main->program->pauseMovie();
00158                         wakeUp = 0;
00159                         break;
00160                 case FLASH_CONT:
00161                         fh->main->program->continueMovie();
00162                         wakeUp = FLASH_STATUS_WAKEUP;
00163                         break;
00164                 case FLASH_REWIND:
00165                         fh->main->program->rewindMovie();
00166                         wakeUp = 0;
00167                         break;
00168                 case FLASH_STEP:
00169                         fh->main->program->nextStepMovie();
00170                         wakeUp = 0;
00171                         break;
00172         }
00173 
00174         if (flag & FLASH_WAKEUP) {
00175                 // Compute next wakeup time
00176                 gettimeofday(wakeDate,0);
00177                 wakeDate->tv_usec += fh->msPerFrame*1000;
00178                 if (wakeDate->tv_usec > 1000000) {
00179                         wakeDate->tv_usec -= 1000000;
00180                         wakeDate->tv_sec++;
00181                 }
00182                 
00183                 // Play frame
00184                 wakeUp = fh->processMovie(fh->gd, fh->sm);
00185         }
00186 
00187         if (checkFlashTimer(&fh->scheduledTime)) {
00188             if (fh->handleEvent(fh->gd, fh->sm, &fh->scheduledEvent)) {
00189                 wakeUp = 1;
00190             }
00191             
00192             setFlashTimer(&fh->scheduledTime, -1);
00193         }
00194 
00195         if (flag & FLASH_EVENT) {
00196             wakeUp = fh->handleEvent(fh->gd, fh->sm, fe);
00197             if (wakeUp) {
00198                 /* Wake up at once, except for mouse move (40 ms after) */
00199                 gettimeofday(wakeDate,0);
00200                 if (fe->type == FeMouseMove) {
00201                     wakeDate->tv_usec += 40*1000;
00202                     if (wakeDate->tv_usec > 1000000) {
00203                         wakeDate->tv_usec -= 1000000;
00204                         wakeDate->tv_sec++;
00205                     }
00206                 }
00207             }
00208         }
00209 
00210         return wakeUp || (fh->scheduledTime.tv_sec != -1);
00211 }
00212 
00213 void FlashSetGetSwfMethod(FlashHandle flashHandle, void (*getSwf)(char *url, int level, void *clientData), void *clientData)
00214 {
00215         FlashMovie *fh;
00216 
00217         fh = (FlashMovie *)flashHandle;
00218 
00219         fh->getSwf = getSwf;
00220         fh->getSwfClientData = clientData;
00221 }
00222 
00223 
00224 void
00225 FlashSetCursorOnOffMethod(FlashHandle flashHandle, void (*cursorOnOff)(int , void *), void *clientData)
00226 {
00227         FlashMovie *fh;
00228 
00229         fh = (FlashMovie *)flashHandle;
00230 
00231         fh->cursorOnOff = cursorOnOff;
00232         fh->cursorOnOffClientData = clientData;
00233 }
00234 
00235 void
00236 FlashSetGetUrlMethod(FlashHandle flashHandle, void (*getUrl)(char *, char *, void *), void *clientData)
00237 {
00238         FlashMovie *fh;
00239 
00240         fh = (FlashMovie *)flashHandle;
00241 
00242         fh->getUrl = getUrl;
00243         fh->getUrlClientData = clientData;
00244 }
00245 
00246 void
00247 FlashClose(FlashHandle flashHandle)
00248 {
00249         FlashMovie *fh;
00250 
00251         fh = (FlashMovie *)flashHandle;
00252 
00253         delete fh;
00254 }
00255 
00256 void
00257 FlashSettings(FlashHandle flashHandle, long settings)
00258 {
00259         FlashMovie *fh;
00260 
00261         fh = (FlashMovie *)flashHandle;
00262 
00263         fh->main->program->modifySettings( settings );
00264 }
00265 
00266 int shape_size,shape_nb,shaperecord_size,shaperecord_nb,style_size,style_nb;
00267 
00268 void flash_dump(void)
00269 {
00270     printf("flash: shape_size=%d (nb=%d)\n",shape_size,shape_nb);
00271     printf("flash: shaperecord_size=%d (nb=%d)\n",shaperecord_size,shaperecord_nb);
00272     printf("flash: style_size=%d (nb=%d)\n",style_size,style_nb);
00273 }
00274 
00275 }; /* end of extern C */

Generated on Sat Nov 5 16:15:35 2005 for OPIE by  doxygen 1.4.2