diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-12-08 16:31:24 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-12-08 17:00:23 +0100 |
| commit | 4da7a3e44d2bbd7b21ae05c7b6604748e7227227 (patch) | |
| tree | cbb81eed24dd2bed75998e4f8ffb803dd479a6df /src/gui | |
| parent | de3532bd6b685c66015202a48d53e1b8fa4900f5 (diff) | |
| download | jancity-4da7a3e44d2bbd7b21ae05c7b6604748e7227227.tar.gz | |
wip2
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/gui/inc/gui/combo_box.h | 29 | ||||
| -rw-r--r-- | src/gui/src/button.c | 6 | ||||
| -rw-r--r-- | src/gui/src/button_sprite.c | 31 | ||||
| -rw-r--r-- | src/gui/src/combo_box.c | 43 |
5 files changed, 107 insertions, 3 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index bd5b004..5fa625f 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1,6 +1,7 @@ add_library(gui "src/bar.c" "src/button.c" + "src/button_sprite.c" "src/button_type1.c" "src/checkbox.c" "src/container.c" diff --git a/src/gui/inc/gui/combo_box.h b/src/gui/inc/gui/combo_box.h new file mode 100644 index 0000000..dd2fdea --- /dev/null +++ b/src/gui/inc/gui/combo_box.h @@ -0,0 +1,29 @@ +#ifndef GUI_COMBO_BOX_H +#define GUI_COMBO_BOX_H + +#include <gui.h> +#include <gui/button.h> +#include <util.h> +#include <stddef.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct gui_combo_box +{ + struct gui_common common; + struct gui_button b; +}; + +UTIL_STATIC_ASSERT(!offsetof(struct gui_combo_box, common), + "unexpected offset for struct gui_combo_box"); + +void gui_combo_box_init(struct gui_combo_box *c, enum gui_button_type t); + +#ifdef __cplusplus +} +#endif + +#endif /* GUI_COMBO_BOX_H */ diff --git a/src/gui/src/button.c b/src/gui/src/button.c index cf49679..8f00ff2 100644 --- a/src/gui/src/button.c +++ b/src/gui/src/button.c @@ -14,7 +14,7 @@ static int render(const struct gui_common *const g) static int (*const f[])(const struct gui_button *) = { [GUI_BUTTON_TYPE_1] = gui_button_render_type1, - /* [GUI_BUTTON_TYPE_SPRITE] = gui_button_render_sprite */ + [GUI_BUTTON_TYPE_SPRITE] = gui_button_render_sprite }; const struct gui_button *const b = (const struct gui_button *)g; @@ -28,7 +28,7 @@ static void get_dim(const struct gui_common *const g, static void (*const f[])(const struct gui_button *, short *, short *) = { [GUI_BUTTON_TYPE_1] = gui_button_get_dim_type1, - /* [GUI_BUTTON_TYPE_SPRITE] = gui_button_get_dim_sprite */ + [GUI_BUTTON_TYPE_SPRITE] = gui_button_get_dim_sprite }; const struct gui_button *const b = (const struct gui_button *)g; @@ -81,7 +81,7 @@ void gui_button_init(struct gui_button *const b, const enum gui_button_type t) static void (*const f[])(struct gui_button *) = { [GUI_BUTTON_TYPE_1] = gui_button_init_type1, - /* [GUI_BUTTON_TYPE_SPRITE] = gui_button_get_dim_sprite */ + [GUI_BUTTON_TYPE_SPRITE] = gui_button_get_dim_sprite }; f[b->type](b); diff --git a/src/gui/src/button_sprite.c b/src/gui/src/button_sprite.c new file mode 100644 index 0000000..5bdc1b0 --- /dev/null +++ b/src/gui/src/button_sprite.c @@ -0,0 +1,31 @@ +#include <gui.h> +#include <gui/button.h> +#include <gui_private.h> +#include <gui_button_private.h> +#include <gfx.h> +#include <stdio.h> + +int gui_button_render_sprite(const struct gui_button *const b) +{ + sprite_get_or_ret(s, -1); + + if (sprite_clone(b->u.sprite.s, s)) + return -1; + + gui_coords(&b->common, &s->x, &s->y); + sprite_sort(s); + return 0; +} + +void gui_button_get_dim_sprite(const struct gui_button *const b, + short *const w, short *const h) +{ + const struct sprite *const s = b->u.sprite.s; + + *w = s->w; + *h = s->h; +} + +void gui_button_init_sprite(struct gui_button *const b) +{ +} diff --git a/src/gui/src/combo_box.c b/src/gui/src/combo_box.c new file mode 100644 index 0000000..746b4d0 --- /dev/null +++ b/src/gui/src/combo_box.c @@ -0,0 +1,43 @@ +#include <gui/combo_box.h> +#include <gui.h> +#include <input.h> +#include <peripheral.h> +#include <camera.h> + +static int update(struct gui_common *const g, + const union peripheral *const p, const struct camera *const cam, + struct input *const in) +{ + return -1; +} + +static int render(const struct gui_common *const g) +{ + return -1; +} + +static void on_pressed(void *const arg) +{ +} + +void gui_combo_box_init(struct gui_combo_box *const c, + const enum gui_button_type t) +{ + static const struct gui_common_cb cb = + { + .update = update, + .render = render + }; + + *c = (const struct gui_combo_box) + { + .common = + { + .cb = &cb + } + }; + + gui_button_init(&c->b, t); + c->b.on_pressed = on_pressed; + gui_add_child(&c->common, &c->b.common); +} |
