Back to shtanton's homepage
summaryrefslogtreecommitdiff
path: root/src/all.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/all.c')
-rw-r--r--src/all.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/src/all.c b/src/all.c
index 7ed292e..87b9b56 100644
--- a/src/all.c
+++ b/src/all.c
@@ -101,6 +101,7 @@ static const Button buttons[N_BUTTONS] = {
[BUTTON_CONTINUE] = {.x = BUTTON_SPACING, .y = BUTTON_SPACER(BUTTON_CONTINUE), .w = BUTTON_SIZE, .h = BUTTON_SIZE},
};
+// This returns a positive color index or a negated image index
static int getPlaceAction(int currentColor, int cellx, int celly, float cellWidth, float cellHeight) {
int hoverColor = EMPTY;
@@ -134,35 +135,16 @@ static DrawList *render(State *state, UI *ui, Arena *a) {
for (int x = 0; x < GRIDWIDTH; x++) {
for (int y = 0; y < GRIDHEIGHT; y++) {
- int image;
- switch (state->grid[x + GRIDWIDTH * y]) {
- case RED:
- image = IMAGE_NELSON;
- break;
- case RED_LEFT:
- image = IMAGE_NELSON_LEFT;
- break;
- case RED_UP:
- image = IMAGE_NELSON_UP;
- break;
- case RED_RIGHT:
- image = IMAGE_NELSON_RIGHT;
- break;
- case RED_DOWN:
- image = IMAGE_NELSON_DOWN;
- break;
- default:
- image = 0;
- break;
- }
-
- if (image) {
+ if (colorImages[state->grid[x + GRIDWIDTH * y]]) {
drawList->els[drawList->len++] = (DrawElement) {
.x = cellWidth * x + GRID_OFFSET_X,
.y = cellHeight * y,
.w = cellWidth,
.h = cellHeight,
- .image = image,
+ .image = (ImageRef) {
+ .index = colorImages[state->grid[x + GRIDWIDTH * y]],
+ .opacity = 255,
+ },
};
} else {
for (int subx = 0; subx < 2; subx++) {
@@ -228,7 +210,18 @@ static DrawList *render(State *state, UI *ui, Arena *a) {
cellHeight
);
- if (hoverColor != EMPTY) {
+ if (colorImages[hoverColor]) {
+ drawList->els[drawList->len++] = (DrawElement) {
+ .x = cellWidth * hoverx + GRID_OFFSET_X,
+ .y = cellHeight * hovery,
+ .w = cellWidth,
+ .h = cellHeight,
+ .image = {
+ .index = colorImages[hoverColor],
+ .opacity = 127,
+ },
+ };
+ } else if (hoverColor != EMPTY) {
int subCellWidth = cellWidth / 2;
int subCellHeight = cellHeight / 2;
for (int subx = 0; subx < 2; subx++) {
@@ -291,7 +284,10 @@ static DrawList *render(State *state, UI *ui, Arena *a) {
.y = ui->height - buttons[i].y,
.w = buttons[i].w,
.h = buttons[i].h,
- .image = image,
+ .image = (ImageRef) {
+ .index = image,
+ .opacity = 255,
+ },
};
}
@@ -566,8 +562,9 @@ int main(int argc, char **argv) {
);
SDL_RenderRect(r, &rect);
- if (drawList->els[i].image != 0) {
- SDL_RenderTexture(r, textures[drawList->els[i].image], NULL, &rect);
+ if (drawList->els[i].image.index != 0) {
+ SDL_SetTextureAlphaMod(textures[(int) drawList->els[i].image.index], drawList->els[i].image.opacity);
+ SDL_RenderTexture(r, textures[(int) drawList->els[i].image.index], NULL, &rect);
}
}