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