aboutsummaryrefslogtreecommitdiff
path: root/lzr.c
diff options
context:
space:
mode:
Diffstat (limited to 'lzr.c')
-rw-r--r--lzr.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/lzr.c b/lzr.c
index ee4d1e4..89ef073 100644
--- a/lzr.c
+++ b/lzr.c
@@ -18,9 +18,10 @@
#include <string.h>
#include <unistd.h>
-#define UNPACKED_COLOR color[0], color[1], color[2]
-#define SCODE_BIND_MENU SDL_SCANCODE_F1
-#define SCODE_FULLSCREEN SDL_SCANCODE_F11
+#define UNPACKED_COLOR color[0], color[1], color[2]
+#define UNPACKED_COLOR_RGBA color[0], color[1], color[2], color[3]
+#define SCODE_BIND_MENU SDL_SCANCODE_F1
+#define SCODE_FULLSCREEN SDL_SCANCODE_F11
static LZR_Config config = {0};
static char *basepath = NULL;
@@ -36,7 +37,7 @@ static struct {
char *path;
long mtime;
} images[LZR_MAX_IMAGES] = {0};
-static unsigned int color[3] = {0};
+static unsigned int color[4] = {0};
static unsigned int map[LZR_BUTTON_COUNT] = {
SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP,
SDL_SCANCODE_DOWN, SDL_SCANCODE_X, SDL_SCANCODE_C};
@@ -263,6 +264,8 @@ int LZR_Init(LZR_Config cfg)
SDL_Log("%s", SDL_GetError());
return -1;
}
+ if (LZR_DrawSetColor(1.0f, 1.0f, 1.0f, 1.0f))
+ return -1;
return 0;
}
@@ -567,7 +570,7 @@ int LZR_DrawEnd(void)
SDL_Log("%s", SDL_GetError());
return -1;
}
- LZR_DrawSetColor(0.0f, 0.0f, 0.0f);
+ LZR_DrawSetColor(0.0f, 0.0f, 0.0f, 1.0f);
if (LZR_DrawClear()) {
SDL_Log("LZY_DrawClear failed");
return -1;
@@ -598,16 +601,17 @@ int LZR_DrawEnd(void)
return 0;
}
-int LZR_DrawSetColor(float r, float g, float b)
+int LZR_DrawSetColor(float r, float g, float b, float a)
{
const unsigned int ur = (unsigned int)(r * 255) & 255;
const unsigned int ug = (unsigned int)(g * 255) & 255;
const unsigned int ub = (unsigned int)(b * 255) & 255;
- if (SDL_SetRenderDrawColor(renderer, ur, ug, ub, 255) < 0) {
+ const unsigned int ua = (unsigned int)(a * 255) & 255;
+ if (SDL_SetRenderDrawColor(renderer, ur, ug, ub, ua) < 0) {
SDL_Log("%s", SDL_GetError());
return -1;
}
- color[0] = ur, color[1] = ug, color[2] = ub;
+ color[0] = ur, color[1] = ug, color[2] = ub, color[3] = ua;
return 0;
}
@@ -671,7 +675,7 @@ int LZR_DrawCircle(bool fill, int x, int y, int radius)
{
#ifdef LZR_ENABLE_GFX
if ((fill ? filledCircleRGBA : circleRGBA)(renderer, x, y, radius,
- UNPACKED_COLOR, 255) < 0) {
+ UNPACKED_COLOR_RGBA) < 0) {
SDL_Log("%s", SDL_GetError());
return -1;
}
@@ -694,7 +698,7 @@ int LZR_DrawPolygon(bool fill, int *vx, int *vy, int n)
for (int i = 0; i < n; i++)
x[i] = vx[i], y[i] = vy[i];
if ((fill ? filledPolygonRGBA : polygonRGBA)(renderer, x, y, n,
- UNPACKED_COLOR, 255) < 0) {
+ UNPACKED_COLOR_RGBA) < 0) {
SDL_Log("%s", SDL_GetError());
return -1;
}
@@ -720,6 +724,10 @@ int LZR_DrawImage(int id, int x, int y)
SDL_Log("%s", SDL_GetError());
return -1;
}
+ if (SDL_SetTextureAlphaMod(images[id].tex, color[3]) < 0) {
+ SDL_Log("%s", SDL_GetError());
+ return -1;
+ }
const SDL_Rect dest = {x, y, images[id].width, images[id].height};
if (SDL_RenderCopy(renderer, images[id].tex, NULL, &dest) < 0) {
SDL_Log("%s", SDL_GetError());
@@ -769,6 +777,10 @@ int LZR_DrawImageEx(int id, int x, int y, LZR_ImageDrawSettings stg)
SDL_Log("%s", SDL_GetError());
return -1;
}
+ if (SDL_SetTextureAlphaMod(images[id].tex, color[3]) < 0) {
+ SDL_Log("%s", SDL_GetError());
+ return -1;
+ }
const int flip = (stg.flip_v ? SDL_FLIP_VERTICAL : 0) |
(stg.flip_h ? SDL_FLIP_HORIZONTAL : 0);
if (SDL_RenderCopyEx(renderer, images[id].tex, &src, &dst,
@@ -803,6 +815,10 @@ int LZR_DrawTile(int id, int tile, int x, int y, double rot, int flip)
SDL_Log("%s", SDL_GetError());
return -1;
}
+ if (SDL_SetTextureAlphaMod(images[id].tex, color[3]) < 0) {
+ SDL_Log("%s", SDL_GetError());
+ return -1;
+ }
SDL_Rect src;
src.x = (tile % img_width) * config.tile_size;
src.y = (tile / img_width) * config.tile_size;