From b1b5f33417cb9269aac8bf762ee1b699e034523d Mon Sep 17 00:00:00 2001 From: beaglejoe Date: Tue, 9 Jun 2015 23:31:12 +0000 Subject: [PATCH] Correct display order of Screen resolutions for SDL 2 git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6023 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 7f62f3b2704a751dc1ff6651871a3767290c3486 Former-commit-id: d1ff509e6d082494259a331854c038714b9975d0 --- src/libs/tgfclient/guiscreen.cpp | 37 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/libs/tgfclient/guiscreen.cpp b/src/libs/tgfclient/guiscreen.cpp index e35ab6b53..81d0c0e37 100644 --- a/src/libs/tgfclient/guiscreen.cpp +++ b/src/libs/tgfclient/guiscreen.cpp @@ -141,6 +141,7 @@ tScreenSize* GfScrGetSupportedSizes(int nColorDepth, bool bFullScreen, int* pnSi Uint32 format; SDL_Rect bounds; tScreenSize* aSuppSizes; + tScreenSize* tmpSuppSizes; tScreenSize last; last.width = 0; @@ -163,17 +164,17 @@ tScreenSize* GfScrGetSupportedSizes(int nColorDepth, bool bFullScreen, int* pnSi if (avail) { /* Overzealous malloc */ - aSuppSizes = (tScreenSize*)malloc((avail+1) * sizeof(tScreenSize)); + tmpSuppSizes = (tScreenSize*)malloc((avail+1) * sizeof(tScreenSize)); while (avail) { if (bFullScreen == 0) { /* list any size <= desktop size */ if (ADefScreenSizes[avail-1].width <= bounds.w && ADefScreenSizes[avail-1].height <= bounds.h) { - aSuppSizes[*pnSizes].width = ADefScreenSizes[avail-1].width; - aSuppSizes[*pnSizes].height = ADefScreenSizes[avail-1].height; + tmpSuppSizes[*pnSizes].width = ADefScreenSizes[avail-1].width; + tmpSuppSizes[*pnSizes].height = ADefScreenSizes[avail-1].height; - GfLogInfo(" %dx%d,", aSuppSizes[*pnSizes].width, aSuppSizes[*pnSizes].height); + GfLogInfo(" %dx%d,", tmpSuppSizes[*pnSizes].width, tmpSuppSizes[*pnSizes].height); (*pnSizes)++; } } @@ -183,10 +184,10 @@ tScreenSize* GfScrGetSupportedSizes(int nColorDepth, bool bFullScreen, int* pnSi && (last.width != mode.w || last.height != mode.h) #endif ) { - aSuppSizes[*pnSizes].width = mode.w; - aSuppSizes[*pnSizes].height = mode.h; + tmpSuppSizes[*pnSizes].width = mode.w; + tmpSuppSizes[*pnSizes].height = mode.h; - GfLogInfo(" %dx%d,", aSuppSizes[*pnSizes].width, aSuppSizes[*pnSizes].height); + GfLogInfo(" %dx%d,", tmpSuppSizes[*pnSizes].width, tmpSuppSizes[*pnSizes].height); (*pnSizes)++; last.width = mode.w; @@ -198,18 +199,32 @@ tScreenSize* GfScrGetSupportedSizes(int nColorDepth, bool bFullScreen, int* pnSi /* work around SDL2 bug, add desktop bounds as option */ if (bFullScreen && (bounds.w != last.width || bounds.h != last.height)) { - aSuppSizes[*pnSizes].width = bounds.w; - aSuppSizes[*pnSizes].height = bounds.h; + tmpSuppSizes[*pnSizes].width = bounds.w; + tmpSuppSizes[*pnSizes].height = bounds.h; - GfLogInfo(" %dx%d,", aSuppSizes[*pnSizes].width, aSuppSizes[*pnSizes].height); + GfLogInfo(" %dx%d,", tmpSuppSizes[*pnSizes].width, tmpSuppSizes[*pnSizes].height); (*pnSizes)++; } } else { GfLogInfo(" None."); - aSuppSizes = (tScreenSize*) NULL; + tmpSuppSizes = (tScreenSize*) NULL; } GfLogInfo("\nModes selected %d\n", *pnSizes); + + // reverse the array so they appear in correct order in GUI... + if(*pnSizes > 0) { + aSuppSizes = (tScreenSize*)malloc((*pnSizes) * sizeof(tScreenSize)); + int maxindex = *pnSizes - 1; + for(int i = maxindex; i >= 0; i--) { + aSuppSizes[i] = tmpSuppSizes[maxindex - i]; + } + // ...and free the temporary array + free(tmpSuppSizes); + } + else { + aSuppSizes = NULL; + } #else // Query system video capabilities. const SDL_VideoInfo* sdlVideoInfo = SDL_GetVideoInfo();