Annotation of hatari/src/screenSnapShot.c, revision 1.1.1.3

1.1       root        1: /*
                      2:   Hatari
                      3: 
                      4:   Screen Snapshot
                      5: */
                      6: 
1.1.1.2   root        7: #include <SDL.h>
                      8: #include <dirent.h>
                      9: #include <string.h>
                     10: 
1.1       root       11: #include "main.h"
                     12: #include "misc.h"
                     13: #include "screen.h"
                     14: #include "screenSnapShot.h"
                     15: #include "statusBar.h"
                     16: #include "video.h"
                     17: #include "vdi.h"
                     18: 
1.1.1.2   root       19: 
                     20: int nScreenShots=0;                  /* Number of screen shots saved */
                     21: BOOL bRecordingAnimation=FALSE;      /* Recording animation? */
1.1       root       22: BOOL bGrabWhenChange;
                     23: int GrabFrameCounter,GrabFrameLatch;
                     24: 
1.1.1.2   root       25: /*-----------------------------------------------------------------------*/
1.1       root       26: /*
1.1.1.2   root       27:   Scan working directory to get the screenshot number
                     28: */
                     29: void ScreenSnapShot_GetNum(void){
                     30:   char dummy[5];
                     31:   int i, num;
                     32:   DIR *workingdir = opendir(szWorkingDir);
                     33:   struct dirent *file;
                     34: 
                     35:   nScreenShots = 0;
                     36:   if(workingdir == NULL)return;
                     37: 
                     38:   file = readdir(workingdir);
                     39:   while(file != NULL){
                     40:     /* copy first 4 letters */
                     41:     for(i=0;i<4;i++)
                     42:       if(file->d_name[i])
                     43:         dummy[i] = file->d_name[i]; 
                     44:     dummy[i] = '\0'; /* null terminate */
                     45:     if(strcmp("grab", dummy) == 0){
                     46:       /* copy next 4 numbers */
                     47:       for(i=0;i<4;i++)
                     48:         if(file->d_name[4+i] >= '0' && file->d_name[4+i] <= '9')
                     49:           dummy[i] = file->d_name[4+i]; 
                     50:         else break;
                     51: 
                     52:       dummy[i] = '\0'; /* null terminate */
                     53:       sscanf(dummy,"%i", &num);
                     54:       if(num > nScreenShots)nScreenShots = num;
                     55:     }
                     56:     /* next file.. */
                     57:   file = readdir(workingdir);
                     58:   } 
                     59: }
                     60: 
                     61: /*-----------------------------------------------------------------------*/
1.1       root       62: /*
1.1.1.2   root       63:   Save screen shot out .BMP file with filename 'grab0000.bmp','grab0001.bmp'....
1.1       root       64: */
                     65: void ScreenSnapShot_SaveScreen(void)
                     66: {
                     67:   char szFileName[MAX_FILENAME_LENGTH];
1.1.1.2   root       68:   
                     69:   ScreenSnapShot_GetNum();
1.1.1.3 ! root       70:   /* Create our filename */
        !            71:   nScreenShots++;
        !            72:   sprintf(szFileName,"%s/grab%4.4d.bmp",szWorkingDir,nScreenShots);
        !            73:   if(SDL_SaveBMP(sdlscrn, szFileName))
        !            74:     fprintf(stderr, "Screen dump failed!\n");
        !            75:   else 
        !            76:     fprintf(stderr, "Screen dump saved to: %s\n", szFileName);    
1.1       root       77: }
                     78: 
1.1.1.2   root       79: /*-----------------------------------------------------------------------*/
1.1       root       80: /*
                     81:   Are we recording an animation?
                     82: */
                     83: BOOL ScreenSnapShot_AreWeRecording(void)
                     84: {
                     85:   return(bRecordingAnimation);
                     86: }
                     87: 
                     88: /*-----------------------------------------------------------------------*/
                     89: /*
                     90:   Start recording animation
                     91: */
                     92: void ScreenSnapShot_BeginRecording(BOOL bCaptureChange, int nFramesPerSecond)
                     93: {
                     94:   /* Set in globals */
                     95:   bGrabWhenChange = bCaptureChange;
                     96:   /* Set animation timer rate */
                     97:   GrabFrameCounter = 0;
                     98:   GrabFrameLatch = (int)(50.0f/(float)nFramesPerSecond);
                     99:   /* Start animation */
                    100:   bRecordingAnimation = TRUE;
                    101:   /* Set status bar */
                    102:   StatusBar_SetIcon(STATUS_ICON_SCREEN,ICONSTATE_ON);
                    103:   /* And inform user */
                    104:   Main_Message("Screen-Shot recording started.",PROG_NAME /*,MB_OK|MB_ICONINFORMATION*/);
                    105: }
                    106: 
                    107: /*-----------------------------------------------------------------------*/
                    108: /*
                    109:   Stop recording animation
                    110: */
                    111: void ScreenSnapShot_EndRecording()
                    112: {
                    113:   /* Were we recording? */
                    114:   if (bRecordingAnimation) {
                    115:     /* Stop animation */
                    116:     bRecordingAnimation = FALSE;
                    117:     /* Turn off icon */
                    118:     StatusBar_SetIcon(STATUS_ICON_SCREEN,ICONSTATE_OFF);
                    119:     /* And inform user */
                    120:     Main_Message("Screen-Shot recording stopped.",PROG_NAME /*,MB_OK|MB_ICONINFORMATION*/);
                    121:   }
                    122: }
                    123: 
1.1.1.2   root      124: /*-----------------------------------------------------------------------*/
1.1       root      125: /*
                    126:   Recording animation frame
                    127: */
                    128: void ScreenSnapShot_RecordFrame(BOOL bFrameChanged)
                    129: {
1.1.1.3 ! root      130:   /* As we recording? */
        !           131:   if (bRecordingAnimation) {
1.1.1.2   root      132:     /* Yes, but on a change basis or a timer? */
1.1       root      133:     if (bGrabWhenChange) {
1.1.1.2   root      134:       /* On change, so did change this frame? */
1.1       root      135:       if (bFrameChanged)
                    136:         ScreenSnapShot_SaveScreen();
                    137:     }
                    138:     else {
1.1.1.2   root      139:       /* On timer, check for latch and save */
1.1       root      140:       GrabFrameCounter++;
                    141:       if (GrabFrameCounter>=GrabFrameLatch) {
                    142:         ScreenSnapShot_SaveScreen();
                    143:         GrabFrameCounter = 0;
                    144:       }
                    145:     }
                    146:   }
                    147: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.