|
|
@@ -21,17 +21,17 @@ |
|
|
#include <math.h> |
|
|
#include <locale.h> |
|
|
#include <algorithm> |
|
|
#include <SDL/SDL.h> |
|
|
#include <SDL2/SDL.h> |
|
|
#ifdef __APPLE__ |
|
|
#include <SDL_mixer/SDL_mixer.h> |
|
|
#include <SDL_gfx/SDL_gfxPrimitives.h> |
|
|
#include <SDL_gfx/SDL_rotozoom.h> |
|
|
#include <SDL2_mixer/SDL_mixer.h> |
|
|
#include <SDL2_gfx/SDL2_gfxPrimitives.h> |
|
|
#include <SDL2_gfx/SDL2_rotozoom.h> |
|
|
#else |
|
|
#include <SDL/SDL_mixer.h> |
|
|
#include <SDL/SDL_gfxPrimitives.h> |
|
|
#include <SDL/SDL_rotozoom.h> |
|
|
#include <SDL2/SDL_mixer.h> |
|
|
#include <SDL2/SDL2_gfxPrimitives.h> |
|
|
#include <SDL2/SDL2_rotozoom.h> |
|
|
#endif |
|
|
#include <SDL/SDL_syswm.h> |
|
|
#include <SDL2/SDL_syswm.h> |
|
|
#include <string> |
|
|
#include "Globals.h" |
|
|
#include "Functions.h" |
|
|
@@ -142,13 +142,15 @@ void applySurface(int x,int y,SDL_Surface* source,SDL_Surface* dest,SDL_Rect* cl |
|
|
|
|
|
void drawRect(int x,int y,int w,int h,SDL_Surface* dest,Uint32 color){ |
|
|
//NOTE: We let SDL_gfx render it. |
|
|
rectangleRGBA(dest,x,y,x+w,y+h,color >> 24,color >> 16,color >> 8,255); |
|
|
//FIXME - This needs to be fixed to work with SDL2 |
|
|
// rectangleRGBA(dest,x,y,x+w,y+h,color >> 24,color >> 16,color >> 8,255); |
|
|
} |
|
|
|
|
|
//Draw a box with anti-aliased borders using SDL_gfx. |
|
|
void drawGUIBox(int x,int y,int w,int h,SDL_Surface* dest,Uint32 color){ |
|
|
//Fill content's background color from function parameter |
|
|
boxRGBA(dest,x+1,y+1,x+w-2,y+h-2,color >> 24,color >> 16,color >> 8,color >> 0); |
|
|
//FIXME - ditto |
|
|
/* boxRGBA(dest,x+1,y+1,x+w-2,y+h-2,color >> 24,color >> 16,color >> 8,color >> 0); |
|
|
|
|
|
//Draw first black borders around content and leave 1 pixel in every corner |
|
|
lineRGBA(dest,x+1,y,x+w-2,y,0,0,0,255); |
|
|
@@ -169,12 +171,12 @@ void drawGUIBox(int x,int y,int w,int h,SDL_Surface* dest,Uint32 color){ |
|
|
pixelRGBA(dest,x+1,y+1,0,0,0,50); |
|
|
pixelRGBA(dest,x+1,y+h-2,0,0,0,50); |
|
|
pixelRGBA(dest,x+w-2,y+1,0,0,0,50); |
|
|
pixelRGBA(dest,x+w-2,y+h-2,0,0,0,50); |
|
|
pixelRGBA(dest,x+w-2,y+h-2,0,0,0,50);*/ |
|
|
} |
|
|
|
|
|
void drawLine(int x1,int y1,int x2,int y2,SDL_Surface* dest,Uint32 color){ |
|
|
//NOTE: We let SDL_gfx render it. |
|
|
lineRGBA(dest,x1,y1,x2,y2,color >> 24,color >> 16,color >> 8,255); |
|
|
// lineRGBA(dest,x1,y1,x2,y2,color >> 24,color >> 16,color >> 8,255); |
|
|
} |
|
|
|
|
|
void drawLineWithArrow(int x1,int y1,int x2,int y2,SDL_Surface* dest,Uint32 color,int spacing,int offset,int xsize,int ysize){ |
|
|
@@ -275,19 +277,31 @@ bool createScreen(){ |
|
|
#endif |
|
|
}else{ |
|
|
//Set the flags. |
|
|
Uint32 flags=SCREEN_FLAGS; |
|
|
#if !defined(ANDROID) |
|
|
flags |= SDL_DOUBLEBUF; |
|
|
#endif |
|
|
// Uint32 flags=SCREEN_FLAGS; |
|
|
Uint32 flags = 0; |
|
|
//#if !defined(ANDROID) |
|
|
// flags |= SDL_DOUBLEBUF; |
|
|
//#endif |
|
|
if(settings->getBoolValue("fullscreen")) |
|
|
flags|=SDL_FULLSCREEN; |
|
|
flags|=SDL_WINDOW_FULLSCREEN; //TODO with SDL2 we can also do SDL_WINDOW_FULLSCREEN_DESKTOP |
|
|
else if(settings->getBoolValue("resizable")) |
|
|
flags|=SDL_RESIZABLE; |
|
|
flags|=SDL_WINDOW_RESIZABLE; |
|
|
|
|
|
//Create the screen and check if there weren't any errors. |
|
|
screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,flags); |
|
|
if(screen==NULL){ |
|
|
fprintf(stderr,"FATAL ERROR: SDL_SetVideoMode failed\n"); |
|
|
//Create the window and renderer and check if there weren't any errors. |
|
|
// screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,flags); |
|
|
SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, flags, &sdlWindow, &sdlRenderer); |
|
|
if(!sdlWindow || !sdlRenderer){ |
|
|
fprintf(stderr,"FATAL ERROR: SDL_CreateWindowAndRenderer failed\n"); |
|
|
return false; |
|
|
} |
|
|
|
|
|
//Create the surface we are drawing to |
|
|
int width = 0; |
|
|
int height = 0; |
|
|
SDL_GetWindowSize(sdlWindow, &width, &height); |
|
|
screen = SDL_CreateRGBSurface(0, width, height, SCREEN_BPP, RMASK, GMASK, BMASK, AMASK); |
|
|
if(!screen) { |
|
|
fprintf(stderr,"FATAL ERROR: SDL_CreateRGBSurface failed\n"); |
|
|
return false; |
|
|
} |
|
|
} |
|
|
@@ -299,13 +313,19 @@ bool createScreen(){ |
|
|
//Create the temp surface, just a replica of the screen surface, free the previous one if any. |
|
|
if(tempSurface) |
|
|
SDL_FreeSurface(tempSurface); |
|
|
tempSurface=SDL_CreateRGBSurface(SCREEN_FLAGS|SDL_SRCALPHA, |
|
|
tempSurface=SDL_CreateRGBSurface(0, |
|
|
screen->w,screen->h,screen->format->BitsPerPixel, |
|
|
screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0); |
|
|
|
|
|
//TODO - do we need to test for pixel format here? |
|
|
screenTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ARGB8888, |
|
|
SDL_TEXTUREACCESS_STREAMING, screen->w, screen->h); |
|
|
|
|
|
//Set the the window caption. |
|
|
SDL_WM_SetCaption(("Me and My Shadow "+version).c_str(),NULL); |
|
|
SDL_EnableUNICODE(1); |
|
|
// SDL_WM_SetCaption(("Me and My Shadow "+version).c_str(),NULL); |
|
|
SDL_SetWindowTitle(sdlWindow, ("Me and My Shadow "+version).c_str()); |
|
|
//FIXME Seems to be obsolete |
|
|
// SDL_EnableUNICODE(1); |
|
|
|
|
|
//Nothing went wrong so return true. |
|
|
return true; |
|
|
@@ -351,9 +371,11 @@ vector<_res> getResolutionList(){ |
|
|
//NOTE: we enumerate fullscreen resolutions because |
|
|
// windowed resolutions always can be arbitrary |
|
|
if(resolutionList.empty()){ |
|
|
SDL_Rect **modes=SDL_ListModes(NULL,SDL_FULLSCREEN|SCREEN_FLAGS|SDL_ANYFORMAT); |
|
|
// SDL_Rect **modes=SDL_ListModes(NULL,SDL_FULLSCREEN|SCREEN_FLAGS|SDL_ANYFORMAT); |
|
|
//NOTe - currently only using the first display (0) |
|
|
int numDisplayModes = SDL_GetNumDisplayModes(0); |
|
|
|
|
|
if(modes==NULL || ((intptr_t)modes) == -1){ |
|
|
if(numDisplayModes < 1){ |
|
|
cerr<<"ERROR: Can't enumerate available screen resolutions." |
|
|
" Use predefined screen resolutions list instead."<<endl; |
|
|
|
|
|
@@ -385,10 +407,17 @@ vector<_res> getResolutionList(){ |
|
|
} |
|
|
}else{ |
|
|
//Fill the resolutionList. |
|
|
for(unsigned int i=0;modes[i]!=NULL;i++){ |
|
|
|
|
|
for(int i=0;i < numDisplayModes; ++i){ |
|
|
SDL_DisplayMode mode; |
|
|
int error = SDL_GetDisplayMode(0, i, &mode); |
|
|
if(error < 0) { |
|
|
//We failed to get a display mode. Should we crash here? |
|
|
std::cerr << "ERROR: Failed to get display mode " << i << " " << std::endl; |
|
|
} |
|
|
//Check if the resolution is higher than the minimum (800x600). |
|
|
if(modes[i]->w>=800 && modes[i]->h>=600){ |
|
|
_res res={modes[i]->w, modes[i]->h}; |
|
|
if(mode.w >= 800 && mode.h >= 600){ |
|
|
_res res={mode.w, mode.h}; |
|
|
resolutionList.push_back(res); |
|
|
} |
|
|
} |
|
|
@@ -472,11 +501,13 @@ void configureWindow(){ |
|
|
//Retrieve the WM info from SDL containing the window handle. |
|
|
struct SDL_SysWMinfo wmInfo; |
|
|
SDL_VERSION(&wmInfo.version); |
|
|
SDL_GetWMInfo(&wmInfo); |
|
|
SDL_GetWindowWMInfo(sdlWindow, &wmInfo); |
|
|
|
|
|
#ifdef __X11_INCLUDED__ |
|
|
//We assume that a linux system running meandmyshadow is also running an Xorg server. |
|
|
if(wmInfo.subsystem==SDL_SYSWM_X11){ |
|
|
//TODO: Lock func no longer exists in SDL2, is this still needed? |
|
|
/* |
|
|
//Create the size hints to give to the window. |
|
|
XSizeHints* sizeHints; |
|
|
if(!(sizeHints=XAllocSizeHints())){ |
|
|
@@ -496,6 +527,7 @@ void configureWindow(){ |
|
|
|
|
|
//Free size hint structure |
|
|
XFree(sizeHints); |
|
|
*/ |
|
|
}else{ |
|
|
//No X11 so an unsupported window manager. |
|
|
cerr<<"WARNING: Unsupported window manager."<<endl; |
|
|
@@ -512,25 +544,25 @@ void configureWindow(){ |
|
|
|
|
|
void onVideoResize(){ |
|
|
//Check if the resize event isn't malformed. |
|
|
if(event.resize.w<=0 || event.resize.h<=0) |
|
|
if(event.window.data1<=0 || event.window.data2<=0) |
|
|
return; |
|
|
|
|
|
//Check the size limit. |
|
|
if(event.resize.w<800) |
|
|
event.resize.w=800; |
|
|
if(event.resize.h<600) |
|
|
event.resize.h=600; |
|
|
if(event.window.data1<800) |
|
|
event.window.data1=800; |
|
|
if(event.window.data2<600) |
|
|
event.window.data2=600; |
|
|
|
|
|
//Check if it really resizes. |
|
|
if(SCREEN_WIDTH==event.resize.w && SCREEN_HEIGHT==event.resize.h) |
|
|
if(SCREEN_WIDTH==event.window.data1 && SCREEN_HEIGHT==event.window.data2) |
|
|
return; |
|
|
|
|
|
char s[32]; |
|
|
|
|
|
//Set the new width and height. |
|
|
sprintf(s,"%d",event.resize.w); |
|
|
sprintf(s,"%d",event.window.data1); |
|
|
getSettings()->setValue("width",s); |
|
|
sprintf(s,"%d",event.resize.h); |
|
|
sprintf(s,"%d",event.window.data2); |
|
|
getSettings()->setValue("height",s); |
|
|
|
|
|
//Do resizing. |
|
|
@@ -813,8 +845,12 @@ bool loadFiles(){ |
|
|
SDL_BlitSurface(surface,NULL,screen,&r); |
|
|
SDL_FreeSurface(surface); |
|
|
} |
|
|
SDL_UpdateTexture(screenTexture, NULL, screen->pixels, screen->w * sizeof(Uint32)); |
|
|
SDL_RenderClear(sdlRenderer); |
|
|
SDL_RenderCopy(sdlRenderer, screenTexture, NULL, NULL); |
|
|
SDL_RenderPresent(sdlRenderer); |
|
|
|
|
|
SDL_Flip(screen); |
|
|
// SDL_Flip(screen); |
|
|
} |
|
|
|
|
|
musicManager.destroy(); |
|
|
@@ -994,7 +1030,10 @@ void flipScreen(){ |
|
|
fprintf(stderr,"FATAL ERROR: Unable to draw to screen using OpenGL (compiled without).\n"); |
|
|
#endif |
|
|
}else{ |
|
|
SDL_Flip(screen); |
|
|
SDL_UpdateTexture(screenTexture, NULL, screen->pixels, screen->w * sizeof(Uint32)); |
|
|
SDL_RenderClear(sdlRenderer); |
|
|
SDL_RenderCopy(sdlRenderer, screenTexture, NULL, NULL); |
|
|
SDL_RenderPresent(sdlRenderer); |
|
|
} |
|
|
} |
|
|
|
|
|
@@ -1144,7 +1183,7 @@ void changeState(){ |
|
|
fade=0; |
|
|
|
|
|
SDL_FillRect(screen,NULL,0); |
|
|
SDL_SetAlpha(tempSurface, SDL_SRCALPHA, fade); |
|
|
SDL_SetSurfaceAlphaMod(tempSurface, fade); |
|
|
SDL_BlitSurface(tempSurface,NULL,screen,NULL); |
|
|
flipScreen(); |
|
|
SDL_Delay(25); |
|
|
|