diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-04-28 23:09:28 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-04-28 23:09:28 -0400 |
| commit | 8ce4990f69b6ce1f85a3a29774f7b07d68030e55 (patch) | |
| tree | aae53e3c9ed5d07ed2998e7fa0ffc04f9ca1c023 | |
| parent | 9b8a1454f11de3728b2e0dc87d5778bce9761459 (diff) | |
| download | volute-8ce4990f69b6ce1f85a3a29774f7b07d68030e55.zip | |
load compressor image
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | main.c | 2 | ||||
| -rw-r--r-- | ui.c | 23 | ||||
| -rw-r--r-- | ui.h | 2 |
4 files changed, 28 insertions, 1 deletions
@@ -1,5 +1,5 @@ CFLAGS = -std=c99 -I ./ -fopenmp -Wall -Wextra -pedantic -Wno-deprecated-declarations -D_XOPEN_SOURCE=700L -LDFLAGS = -lSDL2 -lSDL2_ttf -lm -fopenmp +LDFLAGS = -lSDL2 -lSDL2_ttf -lSDL2_image -lm -fopenmp SRC = main.c microui.c renderer.c widget.c ui.c unit.c engine.c compressor.c eprintf.c cwalk.c toml.c util.c OBJ = ${SRC:.c=.o} @@ -4,6 +4,8 @@ #include <stdio.h> #include <stdlib.h> +#include <SDL2/SDL.h> + #include "microui.h" #include "renderer.h" #include "unit.h" @@ -4,6 +4,9 @@ #include <stdlib.h> #include <string.h> +#include <SDL2/SDL.h> +#include <SDL2/SDL_image.h> + #include "microui.h" #include "unit.h" #include "compressor.h" @@ -40,6 +43,7 @@ static void init_volume_flow_rate(UI *ui); static void init_mass_flow_rate(UI *ui); static void init_mass_flow_rate_corrected(UI *ui); static int init_comps(UI *ui); +static int init_comp_img(UI *ui); static void compute_pressure_ratio(UI *ui, int idx); static void compute_comp_outlet_temperature(UI *ui, int idx); static void compute_manifold_temperature(UI *ui, int idx); @@ -76,6 +80,11 @@ init_ui(UI *ui) { return 1; } + if (init_comp_img(ui) != 0) { + free_ui(ui); + return 1; + } + compute(ui, 0); return 0; @@ -85,6 +94,7 @@ void free_ui(UI *ui) { w_free_select_compressor(&ui->comp_select); free(ui->comps); + SDL_FreeSurface(ui->comp_img); } static void @@ -244,6 +254,19 @@ init_comps(UI *ui) { return 0; } +static int +init_comp_img(UI *ui) { + const Compressor *comp; + + comp = &ui->comps[ui->comp_select.idx]; + ui->comp_img = IMG_Load(comp->imgfile); + if (ui->comp_img == NULL) { + weprintf("failed to load %s", comp->imgfile); + return 1; + } + return 0; +} + void set_displacement(UI *ui) { int idx, i; @@ -47,6 +47,8 @@ typedef struct { Compressor *comps; int ncomps; w_Select_Compressor comp_select; + + SDL_Surface *comp_img; /* image of compressor map. */ } UI; int init_ui(UI *ui); |