simplified icon handling
This commit is contained in:
parent
b1011f457f
commit
6888141745
@ -56,23 +56,23 @@
|
|||||||
#include "../../zahnrad.h"
|
#include "../../zahnrad.h"
|
||||||
|
|
||||||
struct icons {
|
struct icons {
|
||||||
struct zr_image unchecked;
|
int unchecked;
|
||||||
struct zr_image checked;
|
int checked;
|
||||||
struct zr_image rocket;
|
int rocket;
|
||||||
struct zr_image cloud;
|
int cloud;
|
||||||
struct zr_image pen;
|
int pen;
|
||||||
struct zr_image play;
|
int play;
|
||||||
struct zr_image pause;
|
int pause;
|
||||||
struct zr_image stop;
|
int stop;
|
||||||
struct zr_image prev;
|
int prev;
|
||||||
struct zr_image next;
|
int next;
|
||||||
struct zr_image tools;
|
int tools;
|
||||||
struct zr_image directory;
|
int directory;
|
||||||
struct zr_image copy;
|
int copy;
|
||||||
struct zr_image convert;
|
int convert;
|
||||||
struct zr_image delete;
|
int delete;
|
||||||
struct zr_image edit;
|
int edit;
|
||||||
struct zr_image images[9];
|
int images[9];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gui {
|
struct gui {
|
||||||
@ -148,25 +148,25 @@ button_demo(struct zr_window *window, struct zr_style *config, struct icons *img
|
|||||||
{
|
{
|
||||||
/* toolbar */
|
/* toolbar */
|
||||||
zr_layout_row_static(&layout, 40, 40, 4);
|
zr_layout_row_static(&layout, 40, 40, 4);
|
||||||
zr_menu_icon_begin(&layout, &menu, img->play, 120, &music_active);
|
zr_menu_icon_begin(&layout, &menu, zr_image_id(img->play), 120, &music_active);
|
||||||
{
|
{
|
||||||
/* settings */
|
/* settings */
|
||||||
zr_layout_row_dynamic(&menu, 25, 1);
|
zr_layout_row_dynamic(&menu, 25, 1);
|
||||||
if (zr_menu_item_icon(&menu, img->play, "Play", ZR_TEXT_RIGHT))
|
if (zr_menu_item_icon(&menu, zr_image_id(img->play), "Play", ZR_TEXT_RIGHT))
|
||||||
zr_menu_close(&menu, &music_active);
|
zr_menu_close(&menu, &music_active);
|
||||||
if (zr_menu_item_icon(&menu, img->stop, "Stop", ZR_TEXT_RIGHT))
|
if (zr_menu_item_icon(&menu, zr_image_id(img->stop), "Stop", ZR_TEXT_RIGHT))
|
||||||
zr_menu_close(&menu, &music_active);
|
zr_menu_close(&menu, &music_active);
|
||||||
if (zr_menu_item_icon(&menu, img->pause, "Pause", ZR_TEXT_RIGHT))
|
if (zr_menu_item_icon(&menu, zr_image_id(img->pause), "Pause", ZR_TEXT_RIGHT))
|
||||||
zr_menu_close(&menu, &music_active);
|
zr_menu_close(&menu, &music_active);
|
||||||
if (zr_menu_item_icon(&menu, img->next, "Next", ZR_TEXT_RIGHT))
|
if (zr_menu_item_icon(&menu, zr_image_id(img->next), "Next", ZR_TEXT_RIGHT))
|
||||||
zr_menu_close(&menu, &music_active);
|
zr_menu_close(&menu, &music_active);
|
||||||
if (zr_menu_item_icon(&menu, img->next, "Prev", ZR_TEXT_RIGHT))
|
if (zr_menu_item_icon(&menu, zr_image_id(img->prev), "Prev", ZR_TEXT_RIGHT))
|
||||||
zr_menu_close(&menu, &music_active);
|
zr_menu_close(&menu, &music_active);
|
||||||
}
|
}
|
||||||
zr_menu_end(&layout, &menu);
|
zr_menu_end(&layout, &menu);
|
||||||
zr_button_image(&layout, img->tools, ZR_BUTTON_DEFAULT);
|
zr_button_image(&layout, zr_image_id(img->tools), ZR_BUTTON_DEFAULT);
|
||||||
zr_button_image(&layout, img->cloud, ZR_BUTTON_DEFAULT);
|
zr_button_image(&layout, zr_image_id(img->cloud), ZR_BUTTON_DEFAULT);
|
||||||
zr_button_image(&layout, img->pen, ZR_BUTTON_DEFAULT);
|
zr_button_image(&layout, zr_image_id(img->pen), ZR_BUTTON_DEFAULT);
|
||||||
}
|
}
|
||||||
zr_menubar_end(&layout);
|
zr_menubar_end(&layout);
|
||||||
|
|
||||||
@ -177,9 +177,8 @@ button_demo(struct zr_window *window, struct zr_style *config, struct icons *img
|
|||||||
ui_widget(&layout, config, 35, 22);
|
ui_widget(&layout, config, 35, 22);
|
||||||
if (zr_button_text(&layout, "Push me", ZR_BUTTON_DEFAULT))
|
if (zr_button_text(&layout, "Push me", ZR_BUTTON_DEFAULT))
|
||||||
fprintf(stdout, "pushed!\n");
|
fprintf(stdout, "pushed!\n");
|
||||||
|
|
||||||
ui_widget(&layout, config, 35, 22);
|
ui_widget(&layout, config, 35, 22);
|
||||||
if (zr_button_text_image(&layout, img->rocket,
|
if (zr_button_text_image(&layout, zr_image_id(img->rocket),
|
||||||
"Styled", ZR_TEXT_CENTERED, ZR_BUTTON_DEFAULT))
|
"Styled", ZR_TEXT_CENTERED, ZR_BUTTON_DEFAULT))
|
||||||
fprintf(stdout, "rocket!\n");
|
fprintf(stdout, "rocket!\n");
|
||||||
|
|
||||||
@ -196,16 +195,19 @@ button_demo(struct zr_window *window, struct zr_style *config, struct icons *img
|
|||||||
*------------------------------------------------*/
|
*------------------------------------------------*/
|
||||||
ui_header(&layout, config, "Toggle buttons");
|
ui_header(&layout, config, "Toggle buttons");
|
||||||
ui_widget(&layout, config, 35, 22);
|
ui_widget(&layout, config, 35, 22);
|
||||||
if (zr_button_text_image(&layout, (toggle0) ? img->checked: img->unchecked,
|
if (zr_button_text_image(&layout, (toggle0) ? zr_image_id(img->checked):
|
||||||
"Toggle", ZR_TEXT_LEFT, ZR_BUTTON_DEFAULT)) toggle0 = !toggle0;
|
zr_image_id(img->unchecked), "Toggle", ZR_TEXT_LEFT, ZR_BUTTON_DEFAULT))
|
||||||
|
toggle0 = !toggle0;
|
||||||
|
|
||||||
ui_widget(&layout, config, 35, 22);
|
ui_widget(&layout, config, 35, 22);
|
||||||
if (zr_button_text_image(&layout, (toggle1) ? img->checked: img->unchecked,
|
if (zr_button_text_image(&layout, (toggle1) ? zr_image_id(img->checked):
|
||||||
"Toggle", ZR_TEXT_LEFT, ZR_BUTTON_DEFAULT)) toggle1 = !toggle1;
|
zr_image_id(img->unchecked), "Toggle", ZR_TEXT_LEFT, ZR_BUTTON_DEFAULT))
|
||||||
|
toggle1 = !toggle1;
|
||||||
|
|
||||||
ui_widget(&layout, config, 35, 22);
|
ui_widget(&layout, config, 35, 22);
|
||||||
if (zr_button_text_image(&layout, (toggle2) ? img->checked: img->unchecked,
|
if (zr_button_text_image(&layout, (toggle2) ? zr_image_id(img->checked):
|
||||||
"Toggle", ZR_TEXT_LEFT, ZR_BUTTON_DEFAULT)) toggle2 = !toggle2;
|
zr_image_id(img->unchecked), "Toggle", ZR_TEXT_LEFT, ZR_BUTTON_DEFAULT))
|
||||||
|
toggle2 = !toggle2;
|
||||||
|
|
||||||
/*------------------------------------------------
|
/*------------------------------------------------
|
||||||
* RADIO
|
* RADIO
|
||||||
@ -233,13 +235,13 @@ button_demo(struct zr_window *window, struct zr_style *config, struct icons *img
|
|||||||
config->font.height = 18;
|
config->font.height = 18;
|
||||||
zr_contextual_begin(&layout, &menu, ZR_WINDOW_NO_SCROLLBAR, &contextual_active, contextual_bounds);
|
zr_contextual_begin(&layout, &menu, ZR_WINDOW_NO_SCROLLBAR, &contextual_active, contextual_bounds);
|
||||||
zr_layout_row_dynamic(&menu, 25, 1);
|
zr_layout_row_dynamic(&menu, 25, 1);
|
||||||
if (zr_contextual_item_icon(&menu, img->copy, "Clone", ZR_TEXT_RIGHT))
|
if (zr_contextual_item_icon(&menu, zr_image_id(img->copy), "Clone", ZR_TEXT_RIGHT))
|
||||||
fprintf(stdout, "pressed clone!\n");
|
fprintf(stdout, "pressed clone!\n");
|
||||||
if (zr_contextual_item_icon(&menu, img->delete, "Delete", ZR_TEXT_RIGHT))
|
if (zr_contextual_item_icon(&menu, zr_image_id(img->delete), "Delete", ZR_TEXT_RIGHT))
|
||||||
fprintf(stdout, "pressed delete!\n");
|
fprintf(stdout, "pressed delete!\n");
|
||||||
if (zr_contextual_item_icon(&menu, img->convert, "Convert", ZR_TEXT_RIGHT))
|
if (zr_contextual_item_icon(&menu, zr_image_id(img->convert), "Convert", ZR_TEXT_RIGHT))
|
||||||
fprintf(stdout, "pressed convert!\n");
|
fprintf(stdout, "pressed convert!\n");
|
||||||
if (zr_contextual_item_icon(&menu, img->edit, "Edit", ZR_TEXT_RIGHT))
|
if (zr_contextual_item_icon(&menu, zr_image_id(img->edit), "Edit", ZR_TEXT_RIGHT))
|
||||||
fprintf(stdout, "pressed edit!\n");
|
fprintf(stdout, "pressed edit!\n");
|
||||||
zr_contextual_end(&layout, &menu, &contextual_active);
|
zr_contextual_end(&layout, &menu, &contextual_active);
|
||||||
}
|
}
|
||||||
@ -270,7 +272,7 @@ basic_demo(struct zr_window *window, struct zr_style *config, struct icons *img)
|
|||||||
*------------------------------------------------*/
|
*------------------------------------------------*/
|
||||||
ui_header(&layout, config, "Popup & Scrollbar & Images");
|
ui_header(&layout, config, "Popup & Scrollbar & Images");
|
||||||
ui_widget(&layout, config, 35, 22);
|
ui_widget(&layout, config, 35, 22);
|
||||||
if (zr_button_text_image(&layout, img->directory,
|
if (zr_button_text_image(&layout, zr_image_id(img->directory),
|
||||||
"Images", ZR_TEXT_CENTERED, ZR_BUTTON_DEFAULT))
|
"Images", ZR_TEXT_CENTERED, ZR_BUTTON_DEFAULT))
|
||||||
image_active = !image_active;
|
image_active = !image_active;
|
||||||
|
|
||||||
@ -279,7 +281,7 @@ basic_demo(struct zr_window *window, struct zr_style *config, struct icons *img)
|
|||||||
*------------------------------------------------*/
|
*------------------------------------------------*/
|
||||||
ui_header(&layout, config, "Selected Image");
|
ui_header(&layout, config, "Selected Image");
|
||||||
ui_widget_centered(&layout, config, 100, 22);
|
ui_widget_centered(&layout, config, 100, 22);
|
||||||
zr_image(&layout, img->images[selected_image]);
|
zr_image(&layout, zr_image_id(img->images[selected_image]));
|
||||||
|
|
||||||
/*------------------------------------------------
|
/*------------------------------------------------
|
||||||
* IMAGE POPUP
|
* IMAGE POPUP
|
||||||
@ -288,10 +290,10 @@ basic_demo(struct zr_window *window, struct zr_style *config, struct icons *img)
|
|||||||
struct zr_context popup;
|
struct zr_context popup;
|
||||||
static struct zr_vec2 scrollbar;
|
static struct zr_vec2 scrollbar;
|
||||||
zr_popup_begin(&layout, &popup, ZR_POPUP_STATIC, 0, 0,
|
zr_popup_begin(&layout, &popup, ZR_POPUP_STATIC, 0, 0,
|
||||||
zr_rect(265, 0, 300, 200), scrollbar);
|
zr_rect(265, 0, 300, 220), scrollbar);
|
||||||
zr_layout_row_static(&popup, 82, 82, 3);
|
zr_layout_row_static(&popup, 82, 82, 3);
|
||||||
for (i = 0; i < 9; ++i) {
|
for (i = 0; i < 9; ++i) {
|
||||||
if (zr_button_image(&popup, img->images[i], ZR_BUTTON_DEFAULT)) {
|
if (zr_button_image(&popup, zr_image_id(img->images[i]), ZR_BUTTON_DEFAULT)) {
|
||||||
selected_image = i;
|
selected_image = i;
|
||||||
image_active = 0;
|
image_active = 0;
|
||||||
zr_popup_close(&popup);
|
zr_popup_close(&popup);
|
||||||
@ -563,23 +565,6 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* images */
|
/* images */
|
||||||
struct icons icons;
|
struct icons icons;
|
||||||
int unchecked;
|
|
||||||
int checked;
|
|
||||||
int rocket;
|
|
||||||
int cloud;
|
|
||||||
int pen;
|
|
||||||
int play;
|
|
||||||
int stop;
|
|
||||||
int pause;
|
|
||||||
int next;
|
|
||||||
int prev;
|
|
||||||
int tools;
|
|
||||||
int directory;
|
|
||||||
int images[9];
|
|
||||||
int copy;
|
|
||||||
int convert;
|
|
||||||
int delete;
|
|
||||||
int edit;
|
|
||||||
|
|
||||||
/* GUI */
|
/* GUI */
|
||||||
struct gui gui;
|
struct gui gui;
|
||||||
@ -616,49 +601,29 @@ main(int argc, char *argv[])
|
|||||||
nvgFontSize(vg, font_height);
|
nvgFontSize(vg, font_height);
|
||||||
nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
|
nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
|
||||||
|
|
||||||
/* images */
|
/* icons */
|
||||||
unchecked = nvgCreateImage(vg, "../icon/unchecked.png", 0);
|
icons.unchecked = nvgCreateImage(vg, "../icon/unchecked.png", 0);
|
||||||
checked = nvgCreateImage(vg, "../icon/checked.png", 0);
|
icons.checked = nvgCreateImage(vg, "../icon/checked.png", 0);
|
||||||
rocket = nvgCreateImage(vg, "../icon/rocket.png", 0);
|
icons.rocket = nvgCreateImage(vg, "../icon/rocket.png", 0);
|
||||||
cloud = nvgCreateImage(vg, "../icon/cloud.png", 0);
|
icons.cloud = nvgCreateImage(vg, "../icon/cloud.png", 0);
|
||||||
pen = nvgCreateImage(vg, "../icon/pen.png", 0);
|
icons.pen = nvgCreateImage(vg, "../icon/pen.png", 0);
|
||||||
play = nvgCreateImage(vg, "../icon/play.png", 0);
|
icons.play = nvgCreateImage(vg, "../icon/play.png", 0);
|
||||||
pause = nvgCreateImage(vg, "../icon/pause.png", 0);
|
icons.pause = nvgCreateImage(vg, "../icon/pause.png", 0);
|
||||||
stop = nvgCreateImage(vg, "../icon/stop.png", 0);
|
icons.stop = nvgCreateImage(vg, "../icon/stop.png", 0);
|
||||||
next = nvgCreateImage(vg, "../icon/next.png", 0);
|
icons.next = nvgCreateImage(vg, "../icon/next.png", 0);
|
||||||
prev = nvgCreateImage(vg, "../icon/prev.png", 0);
|
icons.prev = nvgCreateImage(vg, "../icon/prev.png", 0);
|
||||||
tools = nvgCreateImage(vg, "../icon/tools.png", 0);
|
icons.tools = nvgCreateImage(vg, "../icon/tools.png", 0);
|
||||||
directory = nvgCreateImage(vg, "../icon/directory.png", 0);
|
icons.directory = nvgCreateImage(vg, "../icon/directory.png", 0);
|
||||||
copy = nvgCreateImage(vg, "../icon/copy.png", 0);
|
icons.copy = nvgCreateImage(vg, "../icon/copy.png", 0);
|
||||||
convert = nvgCreateImage(vg, "../icon/export.png", 0);
|
icons.convert = nvgCreateImage(vg, "../icon/export.png", 0);
|
||||||
delete = nvgCreateImage(vg, "../icon/delete.png", 0);
|
icons.delete = nvgCreateImage(vg, "../icon/delete.png", 0);
|
||||||
edit = nvgCreateImage(vg, "../icon/edit.png", 0);
|
icons.edit = nvgCreateImage(vg, "../icon/edit.png", 0);
|
||||||
for (i = 0; i < 9; ++i) {
|
for (i = 0; i < 9; ++i) {
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
sprintf(buffer, "../images/image%d.jpg", (i+1));
|
sprintf(buffer, "../images/image%d.jpg", (i+1));
|
||||||
images[i] = nvgCreateImage(vg, buffer, 0);
|
icons.images[i] = nvgCreateImage(vg, buffer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* icons */
|
|
||||||
icons.unchecked = zr_image_id(unchecked);
|
|
||||||
icons.checked = zr_image_id(checked);
|
|
||||||
icons.rocket = zr_image_id(rocket);
|
|
||||||
icons.cloud = zr_image_id(cloud);
|
|
||||||
icons.pen = zr_image_id(pen);
|
|
||||||
icons.play = zr_image_id(play);
|
|
||||||
icons.tools = zr_image_id(tools);
|
|
||||||
icons.directory = zr_image_id(directory);
|
|
||||||
icons.pause = zr_image_id(pause);
|
|
||||||
icons.stop = zr_image_id(stop);
|
|
||||||
icons.prev = zr_image_id(prev);
|
|
||||||
icons.next = zr_image_id(next);
|
|
||||||
icons.copy = zr_image_id(copy);
|
|
||||||
icons.convert = zr_image_id(convert);
|
|
||||||
icons.delete = zr_image_id(delete);
|
|
||||||
icons.edit = zr_image_id(edit);
|
|
||||||
for (i = 0; i < 9; ++i)
|
|
||||||
icons.images[i] = zr_image_id(images[i]);
|
|
||||||
|
|
||||||
/* GUI */
|
/* GUI */
|
||||||
memset(&gui, 0, sizeof gui);
|
memset(&gui, 0, sizeof gui);
|
||||||
gui.memory = malloc(MAX_MEMORY);
|
gui.memory = malloc(MAX_MEMORY);
|
||||||
@ -721,18 +686,18 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
nvgDeleteImage(vg, unchecked);
|
nvgDeleteImage(vg, icons.unchecked);
|
||||||
nvgDeleteImage(vg, checked);
|
nvgDeleteImage(vg, icons.checked);
|
||||||
nvgDeleteImage(vg, rocket);
|
nvgDeleteImage(vg, icons.rocket);
|
||||||
nvgDeleteImage(vg, cloud);
|
nvgDeleteImage(vg, icons.cloud);
|
||||||
nvgDeleteImage(vg, pen);
|
nvgDeleteImage(vg, icons.pen);
|
||||||
nvgDeleteImage(vg, play);
|
nvgDeleteImage(vg, icons.play);
|
||||||
nvgDeleteImage(vg, pause);
|
nvgDeleteImage(vg, icons.pause);
|
||||||
nvgDeleteImage(vg, stop);
|
nvgDeleteImage(vg, icons.stop);
|
||||||
nvgDeleteImage(vg, next);
|
nvgDeleteImage(vg, icons.next);
|
||||||
nvgDeleteImage(vg, prev);
|
nvgDeleteImage(vg, icons.prev);
|
||||||
nvgDeleteImage(vg, tools);
|
nvgDeleteImage(vg, icons.tools);
|
||||||
nvgDeleteImage(vg, directory);
|
nvgDeleteImage(vg, icons.directory);
|
||||||
|
|
||||||
free(gui.memory);
|
free(gui.memory);
|
||||||
nvgDeleteGLES2(vg);
|
nvgDeleteGLES2(vg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user