12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277 |
- #include "main.h"
- SDL_Surface *gpScreen = NULL;
- SDL_Surface *gpScreenBak = NULL;
- #if SDL_VERSION_ATLEAST(2,0,0)
- SDL_Window *gpWindow = NULL;
- static SDL_Renderer *gpRenderer = NULL;
- static SDL_Texture *gpTexture = NULL;
- static SDL_Texture *gpTouchOverlay = NULL;
- #ifdef __WINPHONE__
- static SDL_Texture *gpBackKeyMessage = NULL;
- #endif
- #endif
- static SDL_Surface *gpScreenReal = NULL;
- volatile BOOL g_bRenderPaused = FALSE;
- #if (defined (__SYMBIAN32__) && !defined (__S60_5X__)) || defined (PSP) || defined (GEKKO)
- static BOOL bScaleScreen = FALSE;
- #else
- static BOOL bScaleScreen = TRUE;
- #endif
- static WORD g_wInitialWidth = 640;
- static WORD g_wInitialHeight = 400;
- static WORD g_wShakeTime = 0;
- static WORD g_wShakeLevel = 0;
- #if SDL_VERSION_ATLEAST(2, 0, 0)
- #define SDL_SoftStretch SDL_UpperBlit
- #endif
- INT
- #ifdef GEKKO
- VIDEO_Init_GEKKO(
- #else
- VIDEO_Init(
- #endif
- WORD wScreenWidth,
- WORD wScreenHeight,
- BOOL fFullScreen
- )
- {
- #if SDL_VERSION_ATLEAST(2,0,0)
- SDL_Surface *overlay;
- #endif
- g_wInitialWidth = wScreenWidth;
- g_wInitialHeight = wScreenHeight;
- #if SDL_VERSION_ATLEAST(2,0,0)
-
-
-
- #if defined (__IOS__) || defined (__ANDROID__) || defined (__WINPHONE__)
- gpWindow = SDL_CreateWindow("Pal",
- SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, wScreenWidth, wScreenHeight,
- SDL_WINDOW_SHOWN);
- #else
- gpWindow = SDL_CreateWindow("Pal",
- SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, wScreenWidth, wScreenHeight,
- SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
- #endif
- if (gpWindow == NULL)
- {
- return -1;
- }
- gpRenderer = SDL_CreateRenderer(gpWindow, -1, SDL_RENDERER_ACCELERATED);
- if (gpRenderer == NULL)
- {
- return -1;
- }
- #if defined (__IOS__)
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
- SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
- #endif
-
-
-
- gpScreen = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 8, 0, 0, 0, 0);
- gpScreenBak = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 8, 0, 0, 0, 0);
- gpScreenReal = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 32,
- 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
-
-
-
- gpTexture = SDL_CreateTexture(gpRenderer, SDL_PIXELFORMAT_ARGB8888,
- SDL_TEXTUREACCESS_STREAMING, 320, 200);
-
-
-
- if (gpScreen == NULL || gpScreenBak == NULL || gpScreenReal == NULL || gpTexture == NULL)
- {
- if (gpScreen != NULL)
- {
- SDL_FreeSurface(gpScreen);
- gpScreen = NULL;
- }
- if (gpScreenBak != NULL)
- {
- SDL_FreeSurface(gpScreenBak);
- gpScreenBak = NULL;
- }
- if (gpScreenReal != NULL)
- {
- SDL_FreeSurface(gpScreenReal);
- gpScreenReal = NULL;
- }
- if (gpTexture != NULL)
- {
- SDL_DestroyTexture(gpTexture);
- gpTexture = NULL;
- }
- SDL_DestroyRenderer(gpRenderer);
- gpRenderer = NULL;
- SDL_DestroyWindow(gpWindow);
- gpWindow = NULL;
- return -2;
- }
-
-
-
- overlay = SDL_LoadBMP(va("%s%s", PAL_PREFIX, "overlay.bmp"));
- if (overlay != NULL)
- {
- SDL_SetColorKey(overlay, SDL_RLEACCEL, SDL_MapRGB(overlay->format, 255, 0, 255));
- gpTouchOverlay = SDL_CreateTextureFromSurface(gpRenderer, overlay);
- SDL_SetTextureAlphaMod(gpTouchOverlay, 120);
- SDL_FreeSurface(overlay);
- }
- #ifdef __WINPHONE__
- {
-
-
-
-
- #if defined(PAL_WIN95) && !defined(PAL_UNICODE)
- extern BOOL fIsBig5;
- #endif
- SDL_Color palette[256] = { 0 };
- SDL_Surface *p;
- #if defined(PAL_WIN95) && !defined(PAL_UNICODE)
- fIsBig5 = TRUE;
- #endif
- palette[0].r = palette[0].g = palette[0].b = palette[0].a = 0;
- palette[1].r = palette[1].g = palette[1].b = palette[1].a = 255;
- SDL_FillRect(gpScreenBak, NULL, 0);
- VIDEO_SetPalette(palette);
- p = gpScreen;
- gpScreen = gpScreenBak;
- # ifdef PAL_UNICODE
- switch(gpGlobals->iCodePage)
- {
- case CP_BIG5:
- PAL_DrawText(L"\x518D\x6B21\x6309 Back \x7D50\x675F", PAL_XY(30, 30), 1, FALSE, FALSE);
- break;
- case CP_GBK:
- PAL_DrawText(L"\x518D\x6B21\x6309 Back \x7ED3\x675F", PAL_XY(30, 30), 1, FALSE, FALSE);
- break;
- case CP_SHIFTJIS:
- PAL_DrawText(L"Press Back again to end", PAL_XY(30, 30), 1, FALSE, FALSE);
- break;
- }
- # else
- PAL_DrawText("\xA6\x41\xA6\xB8\xAB\xF6 Back \xB5\xB2\xA7\xF4", PAL_XY(30, 30), 1, FALSE, FALSE);
- # endif
- gpScreen = p;
- gpBackKeyMessage = SDL_CreateTextureFromSurface(gpRenderer, gpScreenBak);
- SDL_FillRect(gpScreenBak, NULL, 0);
- #if defined(PAL_WIN95) && !defined(PAL_UNICODE)
- fIsBig5 = FALSE;
- #endif
- }
- #endif
- #else
-
-
-
- #if defined (NDS)
- gpScreenReal = SDL_SetVideoMode(293, 196, 8, SDL_SWSURFACE | SDL_FULLSCREEN);
- #elif defined (__SYMBIAN32__)
- #ifdef __S60_5X__
- gpScreenReal = SDL_SetVideoMode(640, 360, 8,
- SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
- #else
- gpScreenReal = SDL_SetVideoMode(320, 240, 8,
- SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
- #endif
- #elif defined (GEKKO)
- gpScreenReal = SDL_SetVideoMode(640, 480, 8,
- SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
- #elif defined (PSP)
- gpScreenReal = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE | SDL_FULLSCREEN);
- #else
- gpScreenReal = SDL_SetVideoMode(wScreenWidth, wScreenHeight, 8,
- SDL_HWSURFACE | SDL_RESIZABLE | (fFullScreen ? SDL_FULLSCREEN : 0));
- #endif
- if (gpScreenReal == NULL)
- {
-
-
-
- gpScreenReal = SDL_SetVideoMode(640, 480, 8,
- SDL_SWSURFACE | (fFullScreen ? SDL_FULLSCREEN : 0));
- }
-
-
-
- if (gpScreenReal == NULL)
- {
- return -1;
- }
-
-
-
- gpScreen = SDL_CreateRGBSurface(gpScreenReal->flags & ~SDL_HWSURFACE, 320, 200, 8,
- gpScreenReal->format->Rmask, gpScreenReal->format->Gmask,
- gpScreenReal->format->Bmask, gpScreenReal->format->Amask);
- gpScreenBak = SDL_CreateRGBSurface(gpScreenReal->flags & ~SDL_HWSURFACE, 320, 200, 8,
- gpScreenReal->format->Rmask, gpScreenReal->format->Gmask,
- gpScreenReal->format->Bmask, gpScreenReal->format->Amask);
-
-
-
- if (gpScreen == NULL || gpScreenBak == NULL)
- {
- if (gpScreen != NULL)
- {
- SDL_FreeSurface(gpScreen);
- gpScreen = NULL;
- }
- if (gpScreenBak != NULL)
- {
- SDL_FreeSurface(gpScreenBak);
- gpScreenBak = NULL;
- }
- SDL_FreeSurface(gpScreenReal);
- gpScreenReal = NULL;
- return -2;
- }
- #endif
- if (fFullScreen)
- {
- SDL_ShowCursor(FALSE);
- }
- return 0;
- }
- VOID
- VIDEO_Shutdown(
- VOID
- )
- {
- if (gpScreen != NULL)
- {
- SDL_FreeSurface(gpScreen);
- }
- gpScreen = NULL;
- if (gpScreenBak != NULL)
- {
- SDL_FreeSurface(gpScreenBak);
- }
- gpScreenBak = NULL;
- #if SDL_VERSION_ATLEAST(2,0,0)
- if (gpTouchOverlay)
- {
- SDL_DestroyTexture(gpTouchOverlay);
- }
- gpTouchOverlay = NULL;
- #ifdef __WINPHONE__
- if (gpBackKeyMessage)
- {
- SDL_DestroyTexture(gpBackKeyMessage);
- }
- gpBackKeyMessage = NULL;
- #endif
- if (gpTexture)
- {
- SDL_DestroyTexture(gpTexture);
- }
- gpTexture = NULL;
- if (gpRenderer)
- {
- SDL_DestroyRenderer(gpRenderer);
- }
- gpRenderer = NULL;
- if (gpWindow)
- {
- SDL_DestroyWindow(gpWindow);
- }
- gpWindow = NULL;
- #endif
- if (gpScreenReal != NULL)
- {
- SDL_FreeSurface(gpScreenReal);
- }
- gpScreenReal = NULL;
- }
- VOID
- VIDEO_UpdateScreen(
- const SDL_Rect *lpRect
- )
- {
- SDL_Rect srcrect, dstrect;
- short offset = 240 - 200;
- short screenRealHeight = gpScreenReal->h;
- short screenRealY = 0;
- #if SDL_VERSION_ATLEAST(2,0,0)
- if (g_bRenderPaused)
- {
- return;
- }
- #endif
-
-
-
- if (SDL_MUSTLOCK(gpScreenReal))
- {
- if (SDL_LockSurface(gpScreenReal) < 0)
- return;
- }
- if (!bScaleScreen)
- {
- screenRealHeight -= offset;
- screenRealY = offset / 2;
- }
- if (lpRect != NULL)
- {
- dstrect.x = (SHORT)((INT)(lpRect->x) * gpScreenReal->w / gpScreen->w);
- dstrect.y = (SHORT)((INT)(screenRealY + lpRect->y) * screenRealHeight / gpScreen->h);
- dstrect.w = (WORD)((DWORD)(lpRect->w) * gpScreenReal->w / gpScreen->w);
- dstrect.h = (WORD)((DWORD)(lpRect->h) * screenRealHeight / gpScreen->h);
- SDL_SoftStretch(gpScreen, (SDL_Rect *)lpRect, gpScreenReal, &dstrect);
- if (SDL_MUSTLOCK(gpScreenReal))
- {
- SDL_UnlockSurface(gpScreenReal);
- }
- #if SDL_VERSION_ATLEAST(2,0,0)
- SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
- SDL_RenderCopy(gpRenderer, gpTexture, NULL, NULL);
- if (gpTouchOverlay)
- {
- SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
- }
- #ifdef __WINPHONE__
- if (gpBackKeyMessage)
- {
- extern unsigned int g_uiLastBackKeyTime;
- if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
- {
- SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
- }
- }
- #endif
- SDL_RenderPresent(gpRenderer);
- #else
- SDL_UpdateRect(gpScreenReal, dstrect.x, dstrect.y, dstrect.w, dstrect.h);
- #endif
- }
- else if (g_wShakeTime != 0)
- {
-
-
-
- srcrect.x = 0;
- srcrect.y = 0;
- srcrect.w = 320;
- srcrect.h = 200 - g_wShakeLevel;
- dstrect.x = 0;
- dstrect.y = screenRealY;
- dstrect.w = 320 * gpScreenReal->w / gpScreen->w;
- dstrect.h = (200 - g_wShakeLevel) * screenRealHeight / gpScreen->h;
- if (g_wShakeTime & 1)
- {
- srcrect.y = g_wShakeLevel;
- }
- else
- {
- dstrect.y = (screenRealY + g_wShakeLevel) * screenRealHeight / gpScreen->h;
- }
- SDL_SoftStretch(gpScreen, &srcrect, gpScreenReal, &dstrect);
- if (g_wShakeTime & 1)
- {
- dstrect.y = (screenRealY + screenRealHeight - g_wShakeLevel) * screenRealHeight / gpScreen->h;
- }
- else
- {
- dstrect.y = screenRealY;
- }
- dstrect.h = g_wShakeLevel * screenRealHeight / gpScreen->h;
- SDL_FillRect(gpScreenReal, &dstrect, 0);
- if (SDL_MUSTLOCK(gpScreenReal))
- {
- SDL_UnlockSurface(gpScreenReal);
- }
- #if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
- SDL_RenderCopy(gpRenderer, gpTexture, NULL, NULL);
- if (gpTouchOverlay)
- {
- SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
- }
- #ifdef __WINPHONE__
- if (gpBackKeyMessage)
- {
- extern unsigned int g_uiLastBackKeyTime;
- if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
- {
- SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
- }
- }
- #endif
- SDL_RenderPresent(gpRenderer);
- #else
- SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
- #endif
- g_wShakeTime--;
- }
- else
- {
- dstrect.x = 0;
- dstrect.y = screenRealY;
- dstrect.w = gpScreenReal->w;
- dstrect.h = screenRealHeight;
- SDL_SoftStretch(gpScreen, NULL, gpScreenReal, &dstrect);
- if (SDL_MUSTLOCK(gpScreenReal))
- {
- SDL_UnlockSurface(gpScreenReal);
- }
- #if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
- SDL_RenderCopy(gpRenderer, gpTexture, NULL, NULL);
- if (gpTouchOverlay)
- {
- SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
- }
- #ifdef __WINPHONE__
- if (gpBackKeyMessage)
- {
- extern unsigned int g_uiLastBackKeyTime;
- if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
- {
- SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
- }
- }
- #endif
- SDL_RenderPresent(gpRenderer);
- #else
- SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
- #endif
- }
- }
- VOID
- VIDEO_SetPalette(
- SDL_Color rgPalette[256]
- )
- {
- #if SDL_VERSION_ATLEAST(2,0,0)
- SDL_Palette *palette = SDL_AllocPalette(256);
- if (palette == NULL)
- {
- return;
- }
- SDL_SetPaletteColors(palette, rgPalette, 0, 256);
- SDL_SetSurfacePalette(gpScreen, palette);
- SDL_SetSurfacePalette(gpScreenBak, palette);
-
-
-
-
- SDL_SetSurfaceColorMod(gpScreen, 0, 0, 0);
- SDL_SetSurfaceColorMod(gpScreen, 0xFF, 0xFF, 0xFF);
- SDL_SetSurfaceColorMod(gpScreenBak, 0, 0, 0);
- SDL_SetSurfaceColorMod(gpScreenBak, 0xFF, 0xFF, 0xFF);
- VIDEO_UpdateScreen(NULL);
-
- SDL_FreePalette(palette);
- #else
- SDL_SetPalette(gpScreen, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
- SDL_SetPalette(gpScreenBak, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
- SDL_SetPalette(gpScreenReal, SDL_LOGPAL | SDL_PHYSPAL, rgPalette, 0, 256);
- #if (defined (__SYMBIAN32__))
- {
- static UINT32 time = 0;
- if (SDL_GetTicks() - time > 50)
- {
- SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
- time = SDL_GetTicks();
- }
- }
- #endif
- #endif
- }
- VOID
- VIDEO_Resize(
- INT w,
- INT h
- )
- {
- #if SDL_VERSION_ATLEAST(2,0,0)
-
- #else
- DWORD flags;
- PAL_LARGE SDL_Color palette[256];
- int i;
-
-
-
- for (i = 0; i < gpScreenReal->format->palette->ncolors; i++)
- {
- palette[i] = gpScreenReal->format->palette->colors[i];
- }
-
-
-
- flags = gpScreenReal->flags;
- SDL_FreeSurface(gpScreenReal);
- gpScreenReal = SDL_SetVideoMode(w, h, 8, flags);
- if (gpScreenReal == NULL)
- {
- #ifdef __SYMBIAN32__
- #ifdef __S60_5X__
- gpScreenReal = SDL_SetVideoMode(640, 360, 8, SDL_SWSURFACE);
- #else
- gpScreenReal = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE);
- #endif
- #else
-
-
-
- gpScreenReal = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
- #endif
- }
- SDL_SetPalette(gpScreenReal, SDL_PHYSPAL | SDL_LOGPAL, palette, 0, i);
- VIDEO_UpdateScreen(NULL);
- #endif
- }
- SDL_Color *
- VIDEO_GetPalette(
- VOID
- )
- {
- #if SDL_VERSION_ATLEAST(2,0,0)
- return gpScreen->format->palette->colors;
- #else
- return gpScreenReal->format->palette->colors;
- #endif
- }
- VOID
- VIDEO_ToggleScaleScreen(
- VOID
- )
- {
- #ifdef __SYMBIAN32__
- bScaleScreen = !bScaleScreen;
- VIDEO_Resize(320, 240);
- VIDEO_UpdateScreen(NULL);
- #endif
- }
- VOID
- VIDEO_ToggleFullscreen(
- VOID
- )
- {
- #if SDL_VERSION_ATLEAST(2,0,0)
-
- #else
- DWORD flags;
- PAL_LARGE SDL_Color palette[256];
- int i;
-
-
-
- for (i = 0; i < gpScreenReal->format->palette->ncolors; i++)
- {
- palette[i] = gpScreenReal->format->palette->colors[i];
- }
-
-
-
- flags = gpScreenReal->flags;
- if (flags & SDL_FULLSCREEN)
- {
-
-
-
- flags &= ~SDL_FULLSCREEN;
- flags |= SDL_RESIZABLE;
- SDL_ShowCursor(TRUE);
- }
- else
- {
-
-
-
- flags |= SDL_FULLSCREEN;
- SDL_ShowCursor(FALSE);
- }
-
-
-
- SDL_FreeSurface(gpScreenReal);
-
-
-
- if (g_wInitialWidth == 640 && g_wInitialHeight == 400 && (flags & SDL_FULLSCREEN))
- {
- gpScreenReal = SDL_SetVideoMode(640, 480, 8, flags);
- }
- else if (g_wInitialWidth == 640 && g_wInitialHeight == 480 && !(flags & SDL_FULLSCREEN))
- {
- gpScreenReal = SDL_SetVideoMode(640, 400, 8, flags);
- }
- else
- {
- gpScreenReal = SDL_SetVideoMode(g_wInitialWidth, g_wInitialHeight, 8, flags);
- }
- VIDEO_SetPalette(palette);
-
-
-
- VIDEO_UpdateScreen(NULL);
- #endif
- }
- VOID
- VIDEO_SaveScreenshot(
- VOID
- )
- {
- int iNumBMP = 0;
- FILE *fp;
-
-
-
- for (iNumBMP = 0; iNumBMP <= 9999; iNumBMP++)
- {
- fp = fopen(va("%sscrn%.4d.bmp", PAL_PREFIX, iNumBMP), "rb");
- if (fp == NULL)
- {
- break;
- }
- fclose(fp);
- }
- if (iNumBMP > 9999)
- {
- return;
- }
-
-
-
- #if SDL_VERSION_ATLEAST(2,0,0)
- SDL_SaveBMP(gpScreen, va("%sscrn%.4d.bmp", PAL_PREFIX, iNumBMP));
- #else
- SDL_SaveBMP(gpScreenReal, va("%sscrn%.4d.bmp", PAL_PREFIX, iNumBMP));
- #endif
- }
- VOID
- VIDEO_BackupScreen(
- VOID
- )
- {
- SDL_BlitSurface(gpScreen, NULL, gpScreenBak, NULL);
- }
- VOID
- VIDEO_RestoreScreen(
- VOID
- )
- {
- SDL_BlitSurface(gpScreenBak, NULL, gpScreen, NULL);
- }
- VOID
- VIDEO_ShakeScreen(
- WORD wShakeTime,
- WORD wShakeLevel
- )
- {
- g_wShakeTime = wShakeTime;
- g_wShakeLevel = wShakeLevel;
- }
- VOID
- VIDEO_SwitchScreen(
- WORD wSpeed
- )
- {
- int i, j;
- const int rgIndex[6] = {0, 3, 1, 5, 2, 4};
- SDL_Rect dstrect;
- short offset = 240 - 200;
- short screenRealHeight = gpScreenReal->h;
- short screenRealY = 0;
- if (!bScaleScreen)
- {
- screenRealHeight -= offset;
- screenRealY = offset / 2;
- }
- wSpeed++;
- wSpeed *= 10;
- for (i = 0; i < 6; i++)
- {
- for (j = rgIndex[i]; j < gpScreen->pitch * gpScreen->h; j += 6)
- {
- ((LPBYTE)(gpScreenBak->pixels))[j] = ((LPBYTE)(gpScreen->pixels))[j];
- }
-
-
-
- dstrect.x = 0;
- dstrect.y = screenRealY;
- dstrect.w = gpScreenReal->w;
- dstrect.h = screenRealHeight;
- SDL_SoftStretch(gpScreenBak, NULL, gpScreenReal, &dstrect);
- #if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
- SDL_RenderCopy(gpRenderer, gpTexture, NULL, NULL);
- if (gpTouchOverlay)
- {
- SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
- }
- #ifdef __WINPHONE__
- if (gpBackKeyMessage)
- {
- extern unsigned int g_uiLastBackKeyTime;
- if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
- {
- SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
- }
- }
- #endif
- SDL_RenderPresent(gpRenderer);
- #else
- SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
- #endif
- UTIL_Delay(wSpeed);
- }
- }
- VOID
- VIDEO_FadeScreen(
- WORD wSpeed
- )
- {
- int i, j, k;
- DWORD time;
- BYTE a, b;
- const int rgIndex[6] = {0, 3, 1, 5, 2, 4};
- SDL_Rect dstrect;
- short offset = 240 - 200;
- short screenRealHeight = gpScreenReal->h;
- short screenRealY = 0;
-
-
-
- if (SDL_MUSTLOCK(gpScreenReal))
- {
- if (SDL_LockSurface(gpScreenReal) < 0)
- return;
- }
- if (!bScaleScreen)
- {
- screenRealHeight -= offset;
- screenRealY = offset / 2;
- }
- time = SDL_GetTicks();
- wSpeed++;
- wSpeed *= 10;
- for (i = 0; i < 12; i++)
- {
- for (j = 0; j < 6; j++)
- {
- PAL_ProcessEvent();
- while (SDL_GetTicks() <= time)
- {
- PAL_ProcessEvent();
- SDL_Delay(5);
- }
- time = SDL_GetTicks() + wSpeed;
-
-
-
-
- for (k = rgIndex[j]; k < gpScreen->pitch * gpScreen->h; k += 6)
- {
- a = ((LPBYTE)(gpScreen->pixels))[k];
- b = ((LPBYTE)(gpScreenBak->pixels))[k];
- if (i > 0)
- {
- if ((a & 0x0F) > (b & 0x0F))
- {
- b++;
- }
- else if ((a & 0x0F) < (b & 0x0F))
- {
- b--;
- }
- }
- ((LPBYTE)(gpScreenBak->pixels))[k] = ((a & 0xF0) | (b & 0x0F));
- }
-
-
-
- if (g_wShakeTime != 0)
- {
-
-
-
- SDL_Rect srcrect, dstrect;
- srcrect.x = 0;
- srcrect.y = 0;
- srcrect.w = 320;
- srcrect.h = 200 - g_wShakeLevel;
- dstrect.x = 0;
- dstrect.y = screenRealY;
- dstrect.w = 320 * gpScreenReal->w / gpScreen->w;
- dstrect.h = (200 - g_wShakeLevel) * screenRealHeight / gpScreen->h;
- if (g_wShakeTime & 1)
- {
- srcrect.y = g_wShakeLevel;
- }
- else
- {
- dstrect.y = (screenRealY + g_wShakeLevel) * screenRealHeight / gpScreen->h;
- }
- SDL_SoftStretch(gpScreenBak, &srcrect, gpScreenReal, &dstrect);
- if (g_wShakeTime & 1)
- {
- dstrect.y = (screenRealY + screenRealHeight - g_wShakeLevel) * screenRealHeight / gpScreen->h;
- }
- else
- {
- dstrect.y = screenRealY;
- }
- dstrect.h = g_wShakeLevel * screenRealHeight / gpScreen->h;
- SDL_FillRect(gpScreenReal, &dstrect, 0);
- #if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
- SDL_RenderCopy(gpRenderer, gpTexture, NULL, NULL);
- if (gpTouchOverlay)
- {
- SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
- }
- #ifdef __WINPHONE__
- if (gpBackKeyMessage)
- {
- extern unsigned int g_uiLastBackKeyTime;
- if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
- {
- SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
- }
- }
- #endif
- SDL_RenderPresent(gpRenderer);
- #else
- SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
- #endif
- g_wShakeTime--;
- }
- else
- {
- dstrect.x = 0;
- dstrect.y = screenRealY;
- dstrect.w = gpScreenReal->w;
- dstrect.h = screenRealHeight;
- SDL_SoftStretch(gpScreenBak, NULL, gpScreenReal, &dstrect);
- #if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_UpdateTexture(gpTexture, NULL, gpScreenReal->pixels, gpScreenReal->pitch);
- SDL_RenderCopy(gpRenderer, gpTexture, NULL, NULL);
- if (gpTouchOverlay)
- {
- SDL_RenderCopy(gpRenderer, gpTouchOverlay, NULL, NULL);
- }
- #ifdef __WINPHONE__
- if (gpBackKeyMessage)
- {
- extern unsigned int g_uiLastBackKeyTime;
- if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
- {
- SDL_RenderCopy(gpRenderer, gpBackKeyMessage, NULL, NULL);
- }
- }
- #endif
- SDL_RenderPresent(gpRenderer);
- #else
- SDL_UpdateRect(gpScreenReal, 0, 0, gpScreenReal->w, gpScreenReal->h);
- #endif
- }
- }
- }
- if (SDL_MUSTLOCK(gpScreenReal))
- {
- SDL_UnlockSurface(gpScreenReal);
- }
-
-
-
- VIDEO_UpdateScreen(NULL);
- }
- #if SDL_VERSION_ATLEAST(2,0,0)
- VOID
- SDL_WM_SetCaption(
- LPCSTR lpszCaption,
- LPVOID lpReserved
- )
- {
- if (gpWindow != NULL)
- {
- SDL_SetWindowTitle(gpWindow, lpszCaption);
- }
- }
- #endif
|