diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-04-29 13:22:06 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-04-29 13:22:06 -0400 |
| commit | a7284d1250b3605a471daddb9a214c2fa5978f82 (patch) | |
| tree | 3eee7c469dc50aa2409ba38e8d1b9a1da4187023 /widget.c | |
| parent | a9a75f182ad82cf54ca62a5c1e2d1cebc310c850 (diff) | |
| download | volute-a7284d1250b3605a471daddb9a214c2fa5978f82.zip | |
image widget
Diffstat (limited to 'widget.c')
| -rw-r--r-- | widget.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -6,15 +6,18 @@ #include <omp.h> #include "microui.h" +#include "renderer.h" #include "unit.h" #include "compressor.h" #include "widget.h" #include "util.h" +#include "eprintf.h" #define FORMAT "%.5g" static const mu_Color RED = {255, 0, 0, 255}; +static const mu_Color WHITE = {255, 255, 255, 255}; static const char *sc_selected_name(w_Select_Compressor *select); static int select_compressor_active(mu_Context *ctx, w_Select_Compressor *select); @@ -280,6 +283,49 @@ w_number(mu_Context *ctx, const w_Number num) { mu_label(ctx, num); } +void +w_init_image(w_Image *img) { + img->id = -1; +} + +void +w_free_image(w_Image *img) { + if (img->id >= 0) { + r_remove_icon(img->id); + img->id = -1; + } +} + +/* Load an image from a file. Returns non-zero on error. */ +int +w_set_image(w_Image *img, const char *path) { + int id; + + /* Remove old image. */ + w_free_image(img); + + /* Load new image. */ + id = r_add_icon(path); + if (id < 0) { + weprintf("failed to load image %s", path); + return 1; + } + img->id = id; + + return 0; +} + +void +w_image(mu_Context *ctx, w_Image *img) { + int id; + mu_Rect r; + + id = mu_get_id(ctx, &img, sizeof(img)); + r = mu_layout_next(ctx); + mu_update_control(ctx, id, r, 0); + mu_draw_icon(ctx, 0, r, WHITE); +} + /* Update the active/selected status of a widget. id is the microui ID of the widget. * *active is the active flag of the widget that will be toggled if anywhere in r is clicked. */ static void |