|
|
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:
19: //#define ALLOW_SCREEN_GRABS /* FIXME */
20:
1.1.1.2 ! root 21: extern SDL_Surface *sdlscrn;
! 22:
! 23: int nScreenShots=0; /* Number of screen shots saved */
! 24: BOOL bRecordingAnimation=FALSE; /* Recording animation? */
1.1 root 25: BOOL bGrabWhenChange;
26: int GrabFrameCounter,GrabFrameLatch;
27:
1.1.1.2 ! root 28: /*-----------------------------------------------------------------------*/
1.1 root 29: /*
1.1.1.2 ! root 30: Scan working directory to get the screenshot number
! 31: */
! 32: void ScreenSnapShot_GetNum(void){
! 33: char dummy[5];
! 34: int i, num;
! 35: DIR *workingdir = opendir(szWorkingDir);
! 36: struct dirent *file;
! 37:
! 38: nScreenShots = 0;
! 39: if(workingdir == NULL)return;
! 40:
! 41: file = readdir(workingdir);
! 42: while(file != NULL){
! 43: /* copy first 4 letters */
! 44: for(i=0;i<4;i++)
! 45: if(file->d_name[i])
! 46: dummy[i] = file->d_name[i];
! 47: dummy[i] = '\0'; /* null terminate */
! 48: if(strcmp("grab", dummy) == 0){
! 49: /* copy next 4 numbers */
! 50: for(i=0;i<4;i++)
! 51: if(file->d_name[4+i] >= '0' && file->d_name[4+i] <= '9')
! 52: dummy[i] = file->d_name[4+i];
! 53: else break;
! 54:
! 55: dummy[i] = '\0'; /* null terminate */
! 56: sscanf(dummy,"%i", &num);
! 57: if(num > nScreenShots)nScreenShots = num;
! 58: }
! 59: /* next file.. */
! 60: file = readdir(workingdir);
! 61: }
! 62: }
! 63:
! 64:
! 65: /*-----------------------------------------------------------------------*/
! 66: /* REDUNDANT.
1.1 root 67: Check if we have pressed PrintScreen
68: */
69: void ScreenSnapShot_CheckPrintKey(void)
70: {
71: #ifdef ALLOW_SCREEN_GRABS
1.1.1.2 ! root 72: /* Did press Print Screen key? */
! 73: if (GetAsyncKeyState(VK_SNAPSHOT)&0x0001) { /* Print Key pressed(not held) */
! 74: /* Save our screen */
1.1 root 75: ScreenSnapShot_SaveScreen();
76: }
1.1.1.2 ! root 77: #endif /*ALLOW_SCREEN_GRABS*/
1.1 root 78: }
79:
1.1.1.2 ! root 80: /*-----------------------------------------------------------------------*/
1.1 root 81: /*
1.1.1.2 ! root 82: Save screen shot out .BMP file with filename 'grab0000.bmp','grab0001.bmp'....
1.1 root 83: */
84: void ScreenSnapShot_SaveScreen(void)
85: {
86: char szFileName[MAX_FILENAME_LENGTH];
1.1.1.2 ! root 87:
! 88: ScreenSnapShot_GetNum();
! 89: /* Only do when NOT in full screen and NOT VDI resolution */
1.1 root 90: if (!bInFullScreen && !bUseVDIRes) {
1.1.1.2 ! root 91: /* Create our filename */
1.1 root 92: nScreenShots++;
1.1.1.2 ! root 93: sprintf(szFileName,"%s/grab%4.4d.bmp",szWorkingDir,nScreenShots);
! 94: if(SDL_SaveBMP(sdlscrn, szFileName))
! 95: fprintf(stderr, "Screen dump failed!\n");
! 96: else
! 97: fprintf(stderr, "Screen dump saved to: %s\n", szFileName);
1.1 root 98: }
99: }
100:
1.1.1.2 ! root 101: /*-----------------------------------------------------------------------*/
1.1 root 102: /*
103: Are we recording an animation?
104: */
105: BOOL ScreenSnapShot_AreWeRecording(void)
106: {
107: return(bRecordingAnimation);
108: }
109:
110: /*-----------------------------------------------------------------------*/
111: /*
112: Start recording animation
113: */
114: void ScreenSnapShot_BeginRecording(BOOL bCaptureChange, int nFramesPerSecond)
115: {
116: /* Set in globals */
117: bGrabWhenChange = bCaptureChange;
118: /* Set animation timer rate */
119: GrabFrameCounter = 0;
120: GrabFrameLatch = (int)(50.0f/(float)nFramesPerSecond);
121: /* Start animation */
122: bRecordingAnimation = TRUE;
123: /* Set status bar */
124: StatusBar_SetIcon(STATUS_ICON_SCREEN,ICONSTATE_ON);
125: /* And inform user */
126: Main_Message("Screen-Shot recording started.",PROG_NAME /*,MB_OK|MB_ICONINFORMATION*/);
127: }
128:
129: /*-----------------------------------------------------------------------*/
130: /*
131: Stop recording animation
132: */
133: void ScreenSnapShot_EndRecording()
134: {
135: /* Were we recording? */
136: if (bRecordingAnimation) {
137: /* Stop animation */
138: bRecordingAnimation = FALSE;
139: /* Turn off icon */
140: StatusBar_SetIcon(STATUS_ICON_SCREEN,ICONSTATE_OFF);
141: /* And inform user */
142: Main_Message("Screen-Shot recording stopped.",PROG_NAME /*,MB_OK|MB_ICONINFORMATION*/);
143: }
144: }
145:
1.1.1.2 ! root 146: /*-----------------------------------------------------------------------*/
1.1 root 147: /*
148: Recording animation frame
149: */
150: void ScreenSnapShot_RecordFrame(BOOL bFrameChanged)
151: {
1.1.1.2 ! root 152: /* As we recording? And running in a Window */
1.1 root 153: if (bRecordingAnimation && !bInFullScreen) {
1.1.1.2 ! root 154: /* Yes, but on a change basis or a timer? */
1.1 root 155: if (bGrabWhenChange) {
1.1.1.2 ! root 156: /* On change, so did change this frame? */
1.1 root 157: if (bFrameChanged)
158: ScreenSnapShot_SaveScreen();
159: }
160: else {
1.1.1.2 ! root 161: /* On timer, check for latch and save */
1.1 root 162: GrabFrameCounter++;
163: if (GrabFrameCounter>=GrabFrameLatch) {
164: ScreenSnapShot_SaveScreen();
165: GrabFrameCounter = 0;
166: }
167: }
168: }
169: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.