sync w/ screenshot code from snes9x-gx

This commit is contained in:
dborth 2012-01-11 18:45:07 +00:00
parent 4066768fd2
commit 9c933cf7df
3 changed files with 39 additions and 57 deletions

View File

@ -46,8 +46,8 @@ static GuiTrigger * trigA = NULL;
static GuiTrigger * trig2 = NULL; static GuiTrigger * trig2 = NULL;
static GuiButton * btnLogo = NULL; static GuiButton * btnLogo = NULL;
static GuiImageData * gameScreen = NULL;
static GuiImage * gameScreenImg = NULL; static GuiImage * gameScreenImg = NULL;
static GuiImage * bgImg = NULL;
static GuiImage * bgTopImg = NULL; static GuiImage * bgTopImg = NULL;
static GuiImage * bgBottomImg = NULL; static GuiImage * bgBottomImg = NULL;
static GuiSound * bgMusic = NULL; static GuiSound * bgMusic = NULL;
@ -816,11 +816,7 @@ static void WindowCredits(void * ptr)
{ {
UpdatePads(); UpdatePads();
if(gameScreenImg) gameScreenImg->Draw();
gameScreenImg->Draw();
else
bgImg->Draw();
bgBottomImg->Draw(); bgBottomImg->Draw();
bgTopImg->Draw(); bgTopImg->Draw();
creditsWindow.Draw(); creditsWindow.Draw();
@ -1380,19 +1376,17 @@ static int MenuGame()
{ {
if (WindowPrompt("Quit Game", "Quit this game? Any unsaved progress will be lost.", "OK", "Cancel")) if (WindowPrompt("Quit Game", "Quit this game? Any unsaved progress will be lost.", "OK", "Cancel"))
{ {
if(gameScreenImg) HaltGui();
{ mainWindow->Remove(gameScreenImg);
mainWindow->Remove(gameScreenImg); delete gameScreenImg;
delete gameScreenImg; delete gameScreen;
gameScreenImg = NULL; gameScreen = NULL;
} free(gameScreenPng);
if(gameScreenTex) gameScreenPng = NULL;
{ gameScreenImg = new GuiImage(screenwidth, screenheight, (GXColor){236, 226, 238, 255});
free(gameScreenTex); gameScreenImg->ColorStripe(10);
gameScreenTex = NULL; mainWindow->Insert(gameScreenImg, 0);
gameScreenPngSize = 0; ResumeGui();
}
bgImg->SetVisible(true);
#ifndef NO_SOUND #ifndef NO_SOUND
bgMusic->Play(); // startup music bgMusic->Play(); // startup music
#endif #endif
@ -4230,29 +4224,23 @@ MainMenu (int menu)
mainWindow = new GuiWindow(screenwidth, screenheight); mainWindow = new GuiWindow(screenwidth, screenheight);
bgImg = new GuiImage(screenwidth, screenheight, (GXColor){236, 226, 238, 255}); if(menu == MENU_GAME)
bgImg->ColorStripe(10);
mainWindow->Append(bgImg);
if(gameScreenTex)
{ {
IMGCTX pngContext = PNGU_SelectImageFromBuffer(gameScreenPng); gameScreen = new GuiImageData(gameScreenPng);
gameScreenImg = new GuiImage(gameScreen);
if (pngContext != NULL)
{
gameScreenPngSize = PNGU_EncodeFromGXTexture(pngContext, vmode->fbWidth, vmode->efbHeight, gameScreenTex, 0);
PNGU_ReleaseImageContext(pngContext);
DCFlushRange(gameScreenPng, 512*1024);
}
gameScreenImg = new GuiImage(gameScreenTex, vmode->fbWidth, vmode->efbHeight);
gameScreenImg->SetAlpha(192); gameScreenImg->SetAlpha(192);
gameScreenImg->ColorStripe(30); gameScreenImg->ColorStripe(30);
gameScreenImg->SetScaleX(screenwidth/(float)vmode->fbWidth); gameScreenImg->SetScaleX(screenwidth/(float)vmode->fbWidth);
gameScreenImg->SetScaleY(screenheight/(float)vmode->efbHeight); gameScreenImg->SetScaleY(screenheight/(float)vmode->efbHeight);
mainWindow->Append(gameScreenImg);
bgImg->SetVisible(false);
} }
else
{
gameScreenImg = new GuiImage(screenwidth, screenheight, (GXColor){236, 226, 238, 255});
gameScreenImg->ColorStripe(10);
}
mainWindow->Append(gameScreenImg);
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM); GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
GuiSound btnSoundClick(button_click_pcm, button_click_pcm_size, SOUND_PCM); GuiSound btnSoundClick(button_click_pcm, button_click_pcm_size, SOUND_PCM);
@ -4394,23 +4382,20 @@ MainMenu (int menu)
#endif #endif
delete btnLogo; delete btnLogo;
delete bgImg; delete gameScreenImg;
delete bgTopImg; delete bgTopImg;
delete bgBottomImg; delete bgBottomImg;
delete mainWindow; delete mainWindow;
mainWindow = NULL; mainWindow = NULL;
if(gameScreenImg) if(gameScreen)
delete gameScreen;
if(gameScreenPng)
{ {
delete gameScreenImg; free(gameScreenPng);
gameScreenImg = NULL; gameScreenPng = NULL;
}
if(gameScreenTex)
{
free(gameScreenTex);
gameScreenTex = NULL;
gameScreenPngSize = 0;
} }
// wait for keys to be depressed // wait for keys to be depressed

View File

@ -354,7 +354,6 @@ bool SaveBatteryOrState(char * filepath, int action, bool silent)
if(!FindDevice(filepath, &device)) if(!FindDevice(filepath, &device))
return 0; return 0;
// save screenshot - I would prefer to do this from gameScreenTex
if(action == FILE_SNAPSHOT && gameScreenPngSize > 0) if(action == FILE_SNAPSHOT && gameScreenPngSize > 0)
{ {
char screenpath[1024]; char screenpath[1024];

View File

@ -35,7 +35,6 @@ int whichfb = 0; // Frame buffer toggle
static Mtx GXmodelView2D; static Mtx GXmodelView2D;
u8 * gameScreenTex = NULL; // a GX texture screen capture of the game
u8 * gameScreenPng = NULL; u8 * gameScreenPng = NULL;
int gameScreenPngSize = 0; int gameScreenPngSize = 0;
@ -674,16 +673,15 @@ void GX_Render(int width, int height, u8 * buffer, int pitch)
***************************************************************************/ ***************************************************************************/
void TakeScreenshot() void TakeScreenshot()
{ {
int texSize = vmode->fbWidth * vmode->efbHeight * 4; IMGCTX pngContext = PNGU_SelectImageFromBuffer(savebuffer);
if(gameScreenTex) free(gameScreenTex); if (pngContext != NULL)
gameScreenTex = (u8 *)memalign(32, texSize); {
if(gameScreenTex == NULL) return; gameScreenPngSize = PNGU_EncodeFromEFB(pngContext, vmode->fbWidth, vmode->efbHeight);
GX_SetTexCopySrc(0, 0, vmode->fbWidth, vmode->efbHeight); PNGU_ReleaseImageContext(pngContext);
GX_SetTexCopyDst(vmode->fbWidth, vmode->efbHeight, GX_TF_RGBA8, GX_FALSE); gameScreenPng = (u8 *)malloc(gameScreenPngSize);
GX_CopyTex(gameScreenTex, GX_FALSE); memcpy(gameScreenPng, savebuffer, gameScreenPngSize);
GX_PixModeSync(); }
DCFlushRange(gameScreenTex, texSize);
} }
/**************************************************************************** /****************************************************************************