Allow selection of screen resolution.
This commit is contained in:
parent
20d1548f42
commit
d2bc37eebf
|
@ -25,6 +25,8 @@ static void logic(void);
|
|||
static void draw(void);
|
||||
static void soundVolume(void);
|
||||
static void musicVolume(void);
|
||||
static void fullscreen(void);
|
||||
static void windowSize(void);
|
||||
static void bloodGore(void);
|
||||
static void trophyScreenshot(void);
|
||||
static void trophyAlert(void);
|
||||
|
@ -32,11 +34,14 @@ static void inventory(void);
|
|||
static void controls(void);
|
||||
static void back(void);
|
||||
static void setGeneralOptions(void);
|
||||
static void setWindowSizeOption(void);
|
||||
static void setControlOptions(void);
|
||||
static int section;
|
||||
|
||||
static Widget *soundVolumeWidget;
|
||||
static Widget *musicVolumeWidget;
|
||||
static Widget *windowSizeWidget;
|
||||
static Widget *fullscreenWidget;
|
||||
static Widget *bloodGoreWidget;
|
||||
static Widget *trophyScreenshotWidget;
|
||||
static Widget *trophyAlertWidget;
|
||||
|
@ -78,6 +83,14 @@ static void setGeneralOptions(void)
|
|||
musicVolumeWidget = getWidget("musicVolume", "options");
|
||||
musicVolumeWidget->action = musicVolume;
|
||||
musicVolumeWidget->value[0] = app.config.musicVolume;
|
||||
|
||||
fullscreenWidget = getWidget("fullscreen", "options");
|
||||
fullscreenWidget->action = fullscreen;
|
||||
fullscreenWidget->value[0] = app.config.fullscreen;
|
||||
|
||||
windowSizeWidget = getWidget("windowSize", "options");
|
||||
windowSizeWidget->action = windowSize;
|
||||
setWindowSizeOption();
|
||||
|
||||
bloodGoreWidget = getWidget("bloodGore", "options");
|
||||
bloodGoreWidget->action = bloodGore;
|
||||
|
@ -102,6 +115,23 @@ static void setGeneralOptions(void)
|
|||
getWidget("back", "controls")->action = back;
|
||||
}
|
||||
|
||||
static void setWindowSizeOption(void)
|
||||
{
|
||||
int i;
|
||||
char winSize[16];
|
||||
|
||||
sprintf(winSize, "%d x %d", app.config.winWidth, app.config.winHeight);
|
||||
|
||||
for (i = 0 ; i < windowSizeWidget->numOptions ; i++)
|
||||
{
|
||||
if (strcmp(windowSizeWidget->options[i], winSize) == 0)
|
||||
{
|
||||
windowSizeWidget->value[0] = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void setControlOptions(void)
|
||||
{
|
||||
getWidget("left", "controls")->value[0] = app.config.keyControls[CONTROL_LEFT];
|
||||
|
@ -157,6 +187,20 @@ static void musicVolume(void)
|
|||
Mix_VolumeMusic(app.config.musicVolume);
|
||||
}
|
||||
|
||||
static void fullscreen(void)
|
||||
{
|
||||
app.config.fullscreen = fullscreenWidget->value[0];
|
||||
}
|
||||
|
||||
static void windowSize(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = windowSizeWidget->value[0];
|
||||
|
||||
sscanf(windowSizeWidget->options[i], "%d x %d", &app.config.winWidth, &app.config.winHeight);
|
||||
}
|
||||
|
||||
static void bloodGore(void)
|
||||
{
|
||||
app.config.blood = bloodGoreWidget->value[0];
|
||||
|
|
|
@ -129,7 +129,7 @@ void initHub(void)
|
|||
|
||||
cursor.x = SCREEN_WIDTH / 2;
|
||||
cursor.y = SCREEN_HEIGHT / 2;
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x, cursor.y);
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x * app.scaleX, cursor.y * app.scaleY);
|
||||
|
||||
for (t = game.missionStatusHead.next ; t != NULL ; t = t->next)
|
||||
{
|
||||
|
@ -269,32 +269,32 @@ static void doCursor(void)
|
|||
{
|
||||
if (app.mouse.dx != 0 || app.mouse.dy != 0)
|
||||
{
|
||||
cursor.x = app.mouse.x;
|
||||
cursor.y = app.mouse.y;
|
||||
cursor.x = app.mouse.x * app.scaleX;
|
||||
cursor.y = app.mouse.y * app.scaleY;
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_UP) || app.keyboard[SDL_SCANCODE_UP])
|
||||
{
|
||||
cursor.y -= CURSOR_SPEED;
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x, cursor.y);
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x / app.scaleX, cursor.y / app.scaleY);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_DOWN) || app.keyboard[SDL_SCANCODE_DOWN])
|
||||
{
|
||||
cursor.y += CURSOR_SPEED;
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x, cursor.y);
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x / app.scaleX, cursor.y / app.scaleY);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_LEFT) || app.keyboard[SDL_SCANCODE_LEFT])
|
||||
{
|
||||
cursor.x -= CURSOR_SPEED;
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x, cursor.y);
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x / app.scaleX, cursor.y / app.scaleY);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_RIGHT) || app.keyboard[SDL_SCANCODE_RIGHT])
|
||||
{
|
||||
cursor.x += CURSOR_SPEED;
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x, cursor.y);
|
||||
SDL_WarpMouseInWindow(app.window, cursor.x / app.scaleX, cursor.y / app.scaleY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -326,6 +326,8 @@ typedef struct {
|
|||
} Mouse;
|
||||
|
||||
typedef struct {
|
||||
int winWidth;
|
||||
int winHeight;
|
||||
int fullscreen;
|
||||
int soundVolume;
|
||||
int musicVolume;
|
||||
|
@ -339,8 +341,6 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char saveDir[MAX_FILENAME_LENGTH];
|
||||
int winWidth;
|
||||
int winHeight;
|
||||
float scaleX;
|
||||
float scaleY;
|
||||
Mouse mouse;
|
||||
|
|
|
@ -54,6 +54,11 @@ void initGraphics(void)
|
|||
initColor(&colors.darkGrey, 128, 128, 128);
|
||||
|
||||
app.backBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
app.scaleX = SCREEN_WIDTH;
|
||||
app.scaleX /= app.config.winWidth;
|
||||
app.scaleY = SCREEN_HEIGHT;
|
||||
app.scaleY /= app.config.winHeight;
|
||||
}
|
||||
|
||||
void prepareScene(void)
|
||||
|
|
|
@ -58,9 +58,6 @@ void initSDL(void)
|
|||
createSaveFolder();
|
||||
|
||||
loadConfig();
|
||||
|
||||
app.winWidth = SCREEN_WIDTH;
|
||||
app.winHeight = SCREEN_HEIGHT;
|
||||
|
||||
rendererFlags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
|
||||
|
||||
|
@ -88,7 +85,7 @@ void initSDL(void)
|
|||
Mix_Volume(-1, app.config.soundVolume);
|
||||
Mix_VolumeMusic(app.config.musicVolume);
|
||||
|
||||
app.window = SDL_CreateWindow("Blob Wars : Attrition", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, app.winWidth, app.winHeight, windowFlags);
|
||||
app.window = SDL_CreateWindow("Blob Wars : Attrition", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, app.config.winWidth, app.config.winHeight, windowFlags);
|
||||
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
|
||||
|
||||
|
@ -191,6 +188,9 @@ static void showLoadingStep(float step, float maxSteps)
|
|||
static void initDefaultConfig(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
app.config.winWidth = SCREEN_WIDTH;
|
||||
app.config.winHeight = SCREEN_HEIGHT;
|
||||
|
||||
app.config.inventory = 1;
|
||||
app.config.blood = 1;
|
||||
|
@ -238,6 +238,9 @@ static void loadConfig(void)
|
|||
root = cJSON_Parse(text);
|
||||
|
||||
app.config.fullscreen = cJSON_GetObjectItem(root, "fullscreen")->valueint;
|
||||
app.config.winWidth = cJSON_GetObjectItem(root, "winWidth")->valueint;
|
||||
app.config.winHeight = cJSON_GetObjectItem(root, "winHeight")->valueint;
|
||||
|
||||
app.config.musicVolume = cJSON_GetObjectItem(root, "musicVolume")->valueint;
|
||||
app.config.soundVolume = cJSON_GetObjectItem(root, "soundVolume")->valueint;
|
||||
|
||||
|
@ -288,6 +291,9 @@ void saveConfig(void)
|
|||
root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddNumberToObject(root, "fullscreen", app.config.fullscreen);
|
||||
cJSON_AddNumberToObject(root, "winWidth", app.config.winWidth);
|
||||
cJSON_AddNumberToObject(root, "winHeight", app.config.winHeight);
|
||||
|
||||
cJSON_AddNumberToObject(root, "musicVolume", app.config.musicVolume);
|
||||
cJSON_AddNumberToObject(root, "soundVolume", app.config.soundVolume);
|
||||
|
||||
|
|
Loading…
Reference in New Issue