aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2022-12-10 06:49:46 +0100
committerkdx <kikoodx@paranoici.org>2022-12-10 06:49:46 +0100
commit8644b576b5abaec9c668503f33038dee63d5fdb7 (patch)
tree27d685c9c6fe7b2766a517359612399a6fd561d7
parent2f42c47156cfc118a40a932e10f59f0d8fb1669d (diff)
downloadlzr-8644b576b5abaec9c668503f33038dee63d5fdb7.tar.gz
custom aspect ratio config
-rw-r--r--lzr.c30
-rw-r--r--lzr.h2
2 files changed, 18 insertions, 14 deletions
diff --git a/lzr.c b/lzr.c
index 23af5e5..2feec31 100644
--- a/lzr.c
+++ b/lzr.c
@@ -37,7 +37,6 @@ static SDL_Point *points = NULL;
static uint64_t tick = 0;
static Mix_Chunk *sounds[LZR_MAX_SOUNDS] = {0};
static Mix_Music *music = NULL;
-static SDL_BlendMode blend_mode = SDL_BLENDMODE_NONE;
static int off_x = 0;
static int off_y = 0;
static float scale = 1.0;
@@ -144,6 +143,13 @@ int LZR_Init(LZR_Config cfg)
}
if (config.tile_size == 0)
config.tile_size = 1;
+ if (config.ratio <= 0.0)
+ config.ratio = 1.0;
+ else {
+ const double ratio = (float)config.display_width /
+ (float)config.display_height;
+ config.ratio /= ratio;
+ }
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
dx_log_error("%s", SDL_GetError());
@@ -166,8 +172,9 @@ int LZR_Init(LZR_Config cfg)
dx_log_error("%s", SDL_GetError());
return -1;
}
+ const int dwidth = config.display_width * config.ratio;
window = SDL_CreateWindow(config.title, SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED, config.display_width,
+ SDL_WINDOWPOS_UNDEFINED, dwidth,
config.display_height, SDL_WINDOW_RESIZABLE);
if (window == NULL) {
dx_log_error("%s", SDL_GetError());
@@ -293,8 +300,7 @@ int LZR_ImageLoad(const char *path)
return -1;
}
images[i].tex = tex;
- blend_mode = config.blend_mode;
- if (SDL_SetTextureBlendMode(images[i].tex, blend_mode) < 0) {
+ if (SDL_SetTextureBlendMode(images[i].tex, SDL_BLENDMODE_BLEND) < 0) {
dx_log_error("%s", SDL_GetError());
return -1;
}
@@ -439,10 +445,8 @@ int LZR_DrawBegin(void)
dx_log_error("%s", SDL_GetError());
return -1;
}
- SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
- SDL_SetRenderDrawBlendMode(renderer, blend_mode);
return 0;
}
@@ -452,7 +456,6 @@ int LZR_DrawEnd(void)
dx_log_error("%s", SDL_GetError());
return -1;
}
- SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
LZR_DrawSetColor(0.0f, 0.0f, 0.0f);
if (LZR_DrawClear()) {
dx_log_error("LZY_DrawClear failed");
@@ -467,13 +470,14 @@ int LZR_DrawEnd(void)
}
int win_w, win_h;
SDL_GetWindowSize(window, &win_w, &win_h);
- const int ratio_w = win_w / config.display_width;
- const int ratio_h = win_h / config.display_height;
+ const int width = config.display_width * config.ratio;
+ const int height = config.display_height;
+ const int ratio_w = win_w / width;
+ const int ratio_h = win_h / height;
scale = (ratio_w <= ratio_h) ? ratio_w : ratio_h;
- off_x = (win_w - config.display_width * scale) / 2;
- off_y = (win_h - config.display_height * scale) / 2;
- const SDL_Rect dest = {off_x, off_y, config.display_width * scale,
- config.display_height * scale};
+ off_x = (win_w - width * scale) / 2;
+ off_y = (win_h - height * scale) / 2;
+ const SDL_Rect dest = {off_x, off_y, width * scale, height * scale};
if (SDL_RenderCopyEx(renderer, target, NULL, &dest, 0.0, NULL, 0) < 0) {
dx_log_error("%s", SDL_GetError());
return -1;
diff --git a/lzr.h b/lzr.h
index 82753c7..0e2ae10 100644
--- a/lzr.h
+++ b/lzr.h
@@ -14,8 +14,8 @@ typedef struct LZR_Config {
unsigned int target_fps;
unsigned int tile_size;
const char *title;
+ double ratio;
bool disable_bind_menu;
- unsigned int blend_mode;
} LZR_Config;
typedef enum LZR_EventType {