2015-05-09 15:26:44 +03:00
|
|
|
#define MAX_BUFFER 64
|
2015-08-10 21:34:47 +03:00
|
|
|
#define MAX_MEMORY (64 * 1024)
|
2015-05-21 23:10:07 +03:00
|
|
|
#define WINDOW_WIDTH 800
|
|
|
|
#define WINDOW_HEIGHT 600
|
2015-05-09 15:26:44 +03:00
|
|
|
|
2015-07-30 23:19:06 +03:00
|
|
|
struct tree_node {
|
|
|
|
gui_tree_node_state state;
|
|
|
|
const char *name;
|
|
|
|
struct tree_node *parent;
|
|
|
|
struct tree_node *children[8];
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct test_tree {
|
|
|
|
struct tree_node root;
|
|
|
|
struct tree_node *clipboard[16];
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct state {
|
2015-05-13 15:47:11 +03:00
|
|
|
/* input buffer */
|
|
|
|
gui_char input_buffer[MAX_BUFFER];
|
2015-07-12 17:36:55 +03:00
|
|
|
struct gui_edit_box input;
|
2015-07-30 23:19:06 +03:00
|
|
|
gui_char in_buf[MAX_BUFFER];
|
|
|
|
gui_size in_len;
|
|
|
|
gui_bool in_active;
|
2015-07-12 17:36:55 +03:00
|
|
|
|
2015-05-13 15:47:11 +03:00
|
|
|
/* widgets state */
|
2015-07-30 23:19:06 +03:00
|
|
|
gui_size menu_item;
|
2015-07-29 23:19:17 +03:00
|
|
|
gui_bool scaleable;
|
2015-05-13 15:47:11 +03:00
|
|
|
gui_bool checkbox;
|
2015-05-09 15:26:44 +03:00
|
|
|
gui_float slider;
|
2015-05-13 15:47:11 +03:00
|
|
|
gui_size progressbar;
|
2015-08-07 17:53:52 +03:00
|
|
|
gui_int spinner;
|
2015-05-13 15:47:11 +03:00
|
|
|
gui_bool spinner_active;
|
|
|
|
gui_size item_current;
|
|
|
|
gui_size shelf_selection;
|
2015-05-12 18:01:02 +03:00
|
|
|
gui_bool toggle;
|
|
|
|
gui_int option;
|
2015-07-30 23:19:06 +03:00
|
|
|
|
2015-08-06 17:36:28 +03:00
|
|
|
gui_int op;
|
|
|
|
gui_size cur;
|
2015-08-10 21:34:47 +03:00
|
|
|
gui_bool popup;
|
|
|
|
gui_bool combo;
|
|
|
|
gui_size sel;
|
2015-08-06 17:36:28 +03:00
|
|
|
|
2015-07-30 23:19:06 +03:00
|
|
|
/* tree */
|
|
|
|
struct test_tree tree;
|
|
|
|
struct tree_node nodes[8];
|
|
|
|
|
2015-05-12 18:01:02 +03:00
|
|
|
/* tabs */
|
2015-07-30 23:19:06 +03:00
|
|
|
enum gui_node_state config_tab;
|
|
|
|
enum gui_node_state widget_tab;
|
|
|
|
enum gui_node_state style_tab;
|
|
|
|
enum gui_node_state round_tab;
|
|
|
|
enum gui_node_state color_tab;
|
|
|
|
enum gui_node_state flag_tab;
|
|
|
|
|
2015-05-12 18:01:02 +03:00
|
|
|
/* scrollbars */
|
2015-08-02 14:49:51 +03:00
|
|
|
struct gui_vec2 shelf_scrollbar;
|
|
|
|
struct gui_vec2 table_scrollbar;
|
|
|
|
struct gui_vec2 tree_scrollbar;
|
2015-05-09 15:26:44 +03:00
|
|
|
|
2015-05-12 18:01:02 +03:00
|
|
|
/* color picker */
|
2015-05-13 15:47:11 +03:00
|
|
|
gui_bool picker_active;
|
|
|
|
gui_bool spinner_r_active;
|
|
|
|
gui_bool spinner_g_active;
|
|
|
|
gui_bool spinner_b_active;
|
|
|
|
gui_bool spinner_a_active;
|
|
|
|
gui_size current_color;
|
2015-05-09 15:26:44 +03:00
|
|
|
struct gui_color color;
|
2015-07-30 23:19:06 +03:00
|
|
|
|
2015-05-09 15:26:44 +03:00
|
|
|
};
|
|
|
|
|
2015-05-13 15:47:11 +03:00
|
|
|
struct demo_gui {
|
2015-05-19 19:49:24 +03:00
|
|
|
gui_bool running;
|
2015-05-29 15:18:23 +03:00
|
|
|
void *memory;
|
2015-08-10 21:34:47 +03:00
|
|
|
const struct gui_input *input;
|
2015-08-06 17:36:28 +03:00
|
|
|
struct gui_command_queue queue;
|
2015-05-13 15:47:11 +03:00
|
|
|
struct gui_config config;
|
|
|
|
struct gui_font font;
|
2015-07-30 23:19:06 +03:00
|
|
|
struct gui_panel panel;
|
2015-08-06 17:36:28 +03:00
|
|
|
struct gui_panel sub;
|
2015-07-30 23:19:06 +03:00
|
|
|
struct state state;
|
2015-08-07 17:53:52 +03:00
|
|
|
gui_size w, h;
|
2015-05-13 15:47:11 +03:00
|
|
|
};
|
2015-05-09 15:26:44 +03:00
|
|
|
|
|
|
|
static void
|
2015-07-30 23:19:06 +03:00
|
|
|
tree_remove_node(struct tree_node *parent, struct tree_node *child)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
child->parent = NULL;
|
|
|
|
if (!parent->count) return;
|
|
|
|
if (parent->count == 1) {
|
|
|
|
parent->count = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < parent->count; ++i) {
|
|
|
|
if (parent->children[i] == child)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == parent->count) return;
|
|
|
|
if (i == parent->count - 1) {
|
|
|
|
parent->count--;
|
|
|
|
return;
|
|
|
|
} else{
|
|
|
|
parent->children[i] = parent->children[parent->count-1];
|
|
|
|
parent->count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tree_add_node(struct tree_node *parent, struct tree_node *child)
|
|
|
|
{
|
|
|
|
assert(parent->count < 8);
|
|
|
|
child->parent = parent;
|
|
|
|
parent->children[parent->count++] = child;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tree_push_node(struct test_tree *tree, struct tree_node *node)
|
|
|
|
{
|
|
|
|
assert(tree->count < 16);
|
|
|
|
tree->clipboard[tree->count++] = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct tree_node*
|
|
|
|
tree_pop_node(struct test_tree *tree)
|
|
|
|
{
|
|
|
|
assert(tree->count > 0);
|
|
|
|
return tree->clipboard[--tree->count];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
upload_tree(struct test_tree *base, struct gui_tree *tree, struct tree_node *node)
|
|
|
|
{
|
|
|
|
int i = 0, n = 0;
|
|
|
|
enum gui_tree_node_operation op;
|
|
|
|
if (node->count) {
|
|
|
|
i = 0;
|
|
|
|
op = gui_panel_tree_begin_node(tree, node->name, &node->state);
|
|
|
|
while (i < node->count)
|
|
|
|
i += upload_tree(base, tree, node->children[i]);
|
|
|
|
gui_panel_tree_end_node(tree);
|
|
|
|
}
|
|
|
|
else op = gui_panel_tree_leaf(tree, node->name, &node->state);
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case GUI_NODE_NOP: break;
|
|
|
|
case GUI_NODE_CUT:
|
|
|
|
tree_remove_node(node->parent, node);
|
|
|
|
tree_push_node(base, node);
|
|
|
|
return 0;
|
|
|
|
case GUI_NODE_DELETE:
|
|
|
|
tree_remove_node(node->parent, node); break;
|
|
|
|
return 0;
|
|
|
|
case GUI_NODE_PASTE:
|
|
|
|
i = 0; n = base->count;
|
|
|
|
while (i < n) {
|
|
|
|
tree_add_node(node, tree_pop_node(base));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
case GUI_NODE_CLONE:
|
|
|
|
default:break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
widget_panel(struct gui_panel_layout *panel, struct state *demo)
|
2015-05-09 15:26:44 +03:00
|
|
|
{
|
|
|
|
const char *items[] = {"Fist", "Pistol", "Shotgun", "Railgun", "BFG"};
|
2015-07-27 20:56:19 +03:00
|
|
|
|
|
|
|
/* Labels */
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(panel, 30, 1);
|
2015-07-29 23:19:17 +03:00
|
|
|
demo->scaleable = gui_panel_check(panel, "Scaleable Layout", demo->scaleable);
|
2015-08-05 13:48:01 +03:00
|
|
|
|
2015-07-29 23:19:17 +03:00
|
|
|
if (!demo->scaleable)
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_static(panel, 30, 150, 1);
|
2015-05-13 15:47:11 +03:00
|
|
|
gui_panel_label(panel, "text left", GUI_TEXT_LEFT);
|
|
|
|
gui_panel_label(panel, "text center", GUI_TEXT_CENTERED);
|
|
|
|
gui_panel_label(panel, "text right", GUI_TEXT_RIGHT);
|
2015-07-27 20:56:19 +03:00
|
|
|
|
|
|
|
/* Buttons */
|
2015-05-13 15:47:11 +03:00
|
|
|
if (gui_panel_button_text(panel, "button", GUI_BUTTON_DEFAULT))
|
2015-08-10 21:34:47 +03:00
|
|
|
demo->popup = gui_true;
|
2015-06-09 18:05:05 +03:00
|
|
|
if (gui_panel_button_text_triangle(panel, GUI_RIGHT, "next", GUI_TEXT_LEFT, GUI_BUTTON_DEFAULT))
|
2015-06-06 21:13:28 +03:00
|
|
|
fprintf(stdout, "right triangle button pressed!\n");
|
2015-06-10 12:25:35 +03:00
|
|
|
if (gui_panel_button_text_triangle(panel,GUI_LEFT,"previous",GUI_TEXT_RIGHT,GUI_BUTTON_DEFAULT))
|
2015-06-06 21:13:28 +03:00
|
|
|
fprintf(stdout, "left triangle button pressed!\n");
|
2015-07-16 02:35:21 +03:00
|
|
|
|
2015-05-13 15:47:11 +03:00
|
|
|
demo->toggle = gui_panel_button_toggle(panel, "toggle", demo->toggle);
|
|
|
|
demo->checkbox = gui_panel_check(panel, "checkbox", demo->checkbox);
|
2015-07-29 23:19:17 +03:00
|
|
|
|
|
|
|
if (!demo->scaleable)
|
2015-08-10 21:34:47 +03:00
|
|
|
gui_panel_row_static(panel, 30, 75, 2);
|
2015-08-05 13:48:01 +03:00
|
|
|
else gui_panel_row_dynamic(panel, 30, 2);
|
2015-07-29 23:19:17 +03:00
|
|
|
|
2015-05-13 15:47:11 +03:00
|
|
|
if (gui_panel_option(panel, "option 0", demo->option == 0)) demo->option = 0;
|
|
|
|
if (gui_panel_option(panel, "option 1", demo->option == 1)) demo->option = 1;
|
2015-07-18 04:37:42 +03:00
|
|
|
|
2015-06-09 18:05:05 +03:00
|
|
|
{
|
2015-07-18 04:37:42 +03:00
|
|
|
/* templated row layout */
|
2015-06-09 18:05:05 +03:00
|
|
|
char buffer[MAX_BUFFER];
|
2015-07-29 23:19:17 +03:00
|
|
|
if (demo->scaleable) {
|
|
|
|
const gui_float ratio[] = {0.8f, 0.2f};
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row(panel, GUI_DYNAMIC, 30, 2, ratio);
|
2015-07-29 23:19:17 +03:00
|
|
|
demo->slider = gui_panel_slider(panel, 0, demo->slider, 10, 1.0f);
|
|
|
|
sprintf(buffer, "%.2f", demo->slider);
|
|
|
|
gui_panel_label(panel, buffer, GUI_TEXT_LEFT);
|
|
|
|
demo->progressbar = gui_panel_progress(panel, demo->progressbar, 100, gui_true);
|
|
|
|
sprintf(buffer, "%lu", demo->progressbar);
|
|
|
|
gui_panel_label(panel, buffer, GUI_TEXT_LEFT);
|
|
|
|
} else {
|
|
|
|
const gui_float ratio[] = {150.0f, 30.0f};
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row(panel, GUI_STATIC, 30, 2, ratio);
|
2015-07-29 23:19:17 +03:00
|
|
|
demo->slider = gui_panel_slider(panel, 0, demo->slider, 10, 1.0f);
|
|
|
|
sprintf(buffer, "%.2f", demo->slider);
|
|
|
|
gui_panel_label(panel, buffer, GUI_TEXT_LEFT);
|
|
|
|
demo->progressbar = gui_panel_progress(panel, demo->progressbar, 100, gui_true);
|
|
|
|
sprintf(buffer, "%lu", demo->progressbar);
|
|
|
|
gui_panel_label(panel, buffer, GUI_TEXT_LEFT);
|
|
|
|
}
|
2015-06-09 18:05:05 +03:00
|
|
|
}
|
2015-05-13 15:47:11 +03:00
|
|
|
|
2015-07-29 23:19:17 +03:00
|
|
|
if (!demo->scaleable)
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_static(panel, 30, 150, 1);
|
|
|
|
else gui_panel_row_dynamic(panel, 30, 1);
|
2015-07-29 23:19:17 +03:00
|
|
|
|
2015-05-13 15:47:11 +03:00
|
|
|
demo->item_current = gui_panel_selector(panel, items, LEN(items), demo->item_current);
|
2015-08-07 17:53:52 +03:00
|
|
|
demo->spinner= gui_panel_spinner(panel, 0, demo->spinner, 250, 10, &demo->spinner_active);
|
2015-07-30 23:19:06 +03:00
|
|
|
demo->in_len = gui_panel_edit(panel, demo->in_buf, demo->in_len, MAX_BUFFER,
|
2015-08-06 17:36:28 +03:00
|
|
|
&demo->in_active, NULL, GUI_INPUT_DEFAULT);
|
2015-06-09 18:05:05 +03:00
|
|
|
|
2015-07-29 23:19:17 +03:00
|
|
|
if (demo->scaleable) {
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_begin(panel, GUI_DYNAMIC, 30, 2);
|
2015-07-29 23:19:17 +03:00
|
|
|
{
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_push(panel, 0.7f);
|
2015-07-29 23:19:17 +03:00
|
|
|
gui_panel_editbox(panel, &demo->input);
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_push(panel, 0.3f);
|
2015-07-29 23:19:17 +03:00
|
|
|
if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) {
|
2015-08-06 17:36:28 +03:00
|
|
|
gui_edit_box_clear(&demo->input);
|
2015-07-29 23:19:17 +03:00
|
|
|
fprintf(stdout, "command executed!\n");
|
|
|
|
}
|
2015-07-18 04:37:42 +03:00
|
|
|
}
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_end(panel);
|
2015-07-29 23:19:17 +03:00
|
|
|
} else {
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_begin(panel, GUI_STATIC, 30, 2);
|
2015-07-29 23:19:17 +03:00
|
|
|
{
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_push(panel, 100);
|
2015-07-29 23:19:17 +03:00
|
|
|
gui_panel_editbox(panel, &demo->input);
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_push(panel, 80);
|
2015-07-29 23:19:17 +03:00
|
|
|
if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) {
|
2015-08-06 17:36:28 +03:00
|
|
|
gui_edit_box_clear(&demo->input);
|
2015-07-29 23:19:17 +03:00
|
|
|
fprintf(stdout, "command executed!\n");
|
|
|
|
}
|
|
|
|
}
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_end(panel);
|
2015-06-09 18:05:05 +03:00
|
|
|
}
|
2015-05-13 15:47:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
graph_panel(struct gui_panel_layout *panel, gui_size current)
|
|
|
|
{
|
2015-05-21 18:09:22 +03:00
|
|
|
enum {COL, PLOT};
|
2015-06-03 01:58:57 +03:00
|
|
|
static const gui_float values[]={8.0f,15.0f,20.0f,12.0f,30.0f,12.0f,35.0f,40.0f,20.0f};
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(panel, 100, 1);
|
2015-05-21 18:09:22 +03:00
|
|
|
if (current == COL) {
|
2015-05-29 15:18:23 +03:00
|
|
|
gui_panel_graph(panel, GUI_GRAPH_COLUMN, values, LEN(values), 0);
|
2015-05-13 15:47:11 +03:00
|
|
|
} else {
|
2015-05-29 15:18:23 +03:00
|
|
|
gui_panel_graph(panel, GUI_GRAPH_LINES, values, LEN(values), 0);
|
2015-05-13 15:47:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
table_panel(struct gui_panel_layout *panel)
|
|
|
|
{
|
2015-06-10 12:25:35 +03:00
|
|
|
gui_size i = 0;
|
|
|
|
const char *table[] = {"Move forward", "w", "Move back", "s", "Move left", "a",
|
|
|
|
"Move right", "d", "Jump", "SPACE", "Duck", "CTRL"};
|
2015-05-13 15:47:11 +03:00
|
|
|
gui_panel_table_begin(panel, GUI_TABLE_HHEADER, 30, 2);
|
2015-06-04 23:17:54 +03:00
|
|
|
gui_panel_label_colored(panel, "MOVEMENT", GUI_TEXT_CENTERED, gui_rgba(178, 122, 1, 255));
|
|
|
|
gui_panel_label_colored(panel, "KEY/BUTTON", GUI_TEXT_CENTERED, gui_rgba(178, 122, 1, 255));
|
2015-06-10 12:25:35 +03:00
|
|
|
for (i = 0; i < LEN(table); i += 2) {
|
|
|
|
gui_panel_table_row(panel);
|
|
|
|
gui_panel_label(panel, table[i], GUI_TEXT_LEFT);
|
|
|
|
gui_panel_label(panel, table[i+1], GUI_TEXT_CENTERED);
|
|
|
|
}
|
2015-05-13 15:47:11 +03:00
|
|
|
gui_panel_table_end(panel);
|
|
|
|
}
|
|
|
|
|
2015-07-20 18:36:58 +03:00
|
|
|
static void
|
2015-07-30 23:19:06 +03:00
|
|
|
update_flags(struct gui_panel_layout *panel)
|
2015-05-09 15:26:44 +03:00
|
|
|
{
|
|
|
|
gui_size n = 0;
|
|
|
|
gui_flags res = 0;
|
2015-05-29 15:18:23 +03:00
|
|
|
gui_flags i = 0x01;
|
2015-08-10 21:34:47 +03:00
|
|
|
const char *options[]={"Hidden","Border","Header Border", "Moveable","Scaleable", "Minimized", "ROM"};
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(panel, 30, 2);
|
2015-05-09 15:26:44 +03:00
|
|
|
do {
|
2015-07-30 23:19:06 +03:00
|
|
|
if (gui_panel_check(panel,options[n++],(panel->flags & i)?gui_true:gui_false))
|
2015-05-12 18:01:02 +03:00
|
|
|
res |= i;
|
2015-05-09 15:26:44 +03:00
|
|
|
i = i << 1;
|
2015-08-10 21:34:47 +03:00
|
|
|
} while (i <= GUI_PANEL_ROM);
|
2015-07-30 23:19:06 +03:00
|
|
|
panel->flags = res;
|
2015-05-09 15:26:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-06-03 01:58:57 +03:00
|
|
|
properties_tab(struct gui_panel_layout *panel, struct gui_config *config)
|
2015-05-09 15:26:44 +03:00
|
|
|
{
|
2015-06-03 01:58:57 +03:00
|
|
|
int i = 0;
|
2015-06-10 18:35:46 +03:00
|
|
|
const char *properties[] = {"item spacing:", "item padding:", "panel padding:",
|
|
|
|
"scaler size:", "scrollbar:"};
|
2015-05-09 15:26:44 +03:00
|
|
|
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(panel, 30, 3);
|
2015-08-02 14:49:51 +03:00
|
|
|
for (i = 0; i <= GUI_PROPERTY_SCROLLBAR_SIZE; ++i) {
|
2015-06-03 01:58:57 +03:00
|
|
|
gui_int tx, ty;
|
|
|
|
gui_panel_label(panel, properties[i], GUI_TEXT_LEFT);
|
2015-08-07 17:53:52 +03:00
|
|
|
tx = gui_panel_spinner(panel,0,(gui_int)config->properties[i].x, 20, 1, NULL);
|
|
|
|
ty = gui_panel_spinner(panel,0,(gui_int)config->properties[i].y, 20, 1, NULL);
|
2015-06-03 01:58:57 +03:00
|
|
|
config->properties[i].x = (float)tx;
|
|
|
|
config->properties[i].y = (float)ty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
round_tab(struct gui_panel_layout *panel, struct gui_config *config)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
const char *rounding[] = {"panel:", "button:", "checkbox:", "progress:", "input: ",
|
|
|
|
"graph:", "scrollbar:"};
|
|
|
|
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(panel, 30, 2);
|
2015-06-03 01:58:57 +03:00
|
|
|
for (i = 0; i < GUI_ROUNDING_MAX; ++i) {
|
|
|
|
gui_int t;
|
|
|
|
gui_panel_label(panel, rounding[i], GUI_TEXT_LEFT);
|
2015-08-07 17:53:52 +03:00
|
|
|
t = gui_panel_spinner(panel,0,(gui_int)config->rounding[i], 20, 1, NULL);
|
2015-06-03 01:58:57 +03:00
|
|
|
config->rounding[i] = (float)t;
|
|
|
|
}
|
2015-05-09 15:26:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct gui_color
|
2015-07-30 23:19:06 +03:00
|
|
|
color_picker(struct gui_panel_layout *panel, struct state *control,
|
2015-05-09 21:26:23 +03:00
|
|
|
const char *name, struct gui_color color)
|
2015-05-09 15:26:44 +03:00
|
|
|
{
|
2015-06-03 01:58:57 +03:00
|
|
|
int i;
|
|
|
|
gui_byte *iter;
|
|
|
|
gui_bool *active[4];
|
2015-06-08 11:55:35 +03:00
|
|
|
|
2015-06-03 01:58:57 +03:00
|
|
|
active[0] = &control->spinner_r_active;
|
|
|
|
active[1] = &control->spinner_g_active;
|
|
|
|
active[2] = &control->spinner_b_active;
|
|
|
|
active[3] = &control->spinner_a_active;
|
|
|
|
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(panel, 30, 2);
|
2015-05-09 21:26:23 +03:00
|
|
|
gui_panel_label(panel, name, GUI_TEXT_LEFT);
|
|
|
|
gui_panel_button_color(panel, color, GUI_BUTTON_DEFAULT);
|
2015-05-13 15:47:11 +03:00
|
|
|
|
2015-06-03 01:58:57 +03:00
|
|
|
iter = &color.r;
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(panel, 30, 2);
|
2015-06-03 01:58:57 +03:00
|
|
|
for (i = 0; i < 4; ++i, iter++) {
|
|
|
|
gui_float t = *iter;
|
|
|
|
t = gui_panel_slider(panel, 0, t, 255, 10);
|
|
|
|
*iter = (gui_byte)t;
|
2015-08-07 17:53:52 +03:00
|
|
|
*iter = (gui_byte)gui_panel_spinner(panel, 0, *iter, 255, 1, active[i]);
|
2015-06-03 01:58:57 +03:00
|
|
|
}
|
2015-05-09 15:26:44 +03:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-07-30 23:19:06 +03:00
|
|
|
color_tab(struct gui_panel_layout *panel, struct state *control, struct gui_config *config)
|
2015-05-09 15:26:44 +03:00
|
|
|
{
|
|
|
|
gui_size i = 0;
|
2015-05-12 16:48:12 +03:00
|
|
|
static const char *labels[] = {"Text:", "Panel:", "Header:", "Border:", "Button:",
|
|
|
|
"Button Border:", "Button Hovering:", "Button Toggle:", "Button Hovering Text:",
|
|
|
|
"Check:", "Check BG:", "Check Active:", "Option:", "Option BG:", "Option Active:",
|
2015-05-23 01:11:58 +03:00
|
|
|
"Slider:", "Slider bar:", "Slider boder:","Slider cursor:", "Progress:", "Progress Cursor:",
|
2015-06-03 01:58:57 +03:00
|
|
|
"Editbox:", "Editbox cursor:", "Editbox Border:", "Editbox Text:",
|
|
|
|
"Spinner:", "Spinner Border:", "Spinner Triangle:", "Spinner Text:",
|
|
|
|
"Selector:", "Selector Border:", "Selector Triangle:", "Selector Text:",
|
|
|
|
"Histo:", "Histo Bars:", "Histo Negative:", "Histo Hovering:", "Plot:", "Plot Lines:",
|
|
|
|
"Plot Hightlight:", "Scrollbar:", "Scrollbar Cursor:", "Scrollbar Border:",
|
2015-07-30 23:19:06 +03:00
|
|
|
"Table lines:", "Tab header", "Tab border",
|
|
|
|
"Shelf:", "Shelf Text:", "Shelf Active:", "Shelf Active Text:", "Scaler:",
|
2015-06-23 20:23:25 +03:00
|
|
|
"Tiled Scaler"
|
2015-05-09 15:26:44 +03:00
|
|
|
};
|
2015-05-16 13:26:39 +03:00
|
|
|
|
2015-05-13 15:47:11 +03:00
|
|
|
if (control->picker_active) {
|
2015-05-16 13:26:39 +03:00
|
|
|
control->color = color_picker(panel,control,labels[control->current_color], control->color);
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(panel, 30, 3);
|
2015-05-29 15:18:23 +03:00
|
|
|
gui_panel_spacing(panel, 1);
|
2015-05-13 15:47:11 +03:00
|
|
|
if (gui_panel_button_text(panel, "ok", GUI_BUTTON_DEFAULT)) {
|
|
|
|
config->colors[control->current_color] = control->color;
|
|
|
|
control->picker_active = gui_false;
|
2015-05-09 15:26:44 +03:00
|
|
|
}
|
2015-05-13 15:47:11 +03:00
|
|
|
if (gui_panel_button_text(panel, "cancel", GUI_BUTTON_DEFAULT))
|
|
|
|
control->picker_active = gui_false;
|
2015-05-09 15:26:44 +03:00
|
|
|
} else {
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(panel, 30, 2);
|
2015-05-09 15:26:44 +03:00
|
|
|
for (i = 0; i < GUI_COLOR_COUNT; ++i) {
|
2015-06-04 23:17:54 +03:00
|
|
|
struct gui_color c = config->colors[i];
|
2015-05-13 15:47:11 +03:00
|
|
|
gui_panel_label(panel, labels[i], GUI_TEXT_LEFT);
|
2015-06-04 23:17:54 +03:00
|
|
|
if (gui_panel_button_color(panel, c, GUI_BUTTON_DEFAULT)) {
|
2015-05-13 15:47:11 +03:00
|
|
|
if (!control->picker_active) {
|
|
|
|
control->picker_active = gui_true;
|
2015-05-09 15:26:44 +03:00
|
|
|
control->color = config->colors[i];
|
2015-05-13 15:47:11 +03:00
|
|
|
control->current_color = i;
|
2015-05-09 15:26:44 +03:00
|
|
|
} else continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-13 15:47:11 +03:00
|
|
|
}
|
|
|
|
|
2015-08-02 14:49:51 +03:00
|
|
|
static void
|
|
|
|
copy(gui_handle handle, const char *text, gui_size size)
|
|
|
|
{
|
|
|
|
gui_char buffer[1024];
|
|
|
|
UNUSED(handle);
|
|
|
|
if (size >= 1023) return;
|
|
|
|
memcpy(buffer, text, size);
|
|
|
|
buffer[size] = '\0';
|
|
|
|
clipboard_set(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
paste(gui_handle handle, struct gui_edit_box *box)
|
|
|
|
{
|
|
|
|
gui_size len;
|
|
|
|
const char *text;
|
|
|
|
UNUSED(handle);
|
|
|
|
if (!clipboard_is_filled()) return;
|
|
|
|
text = clipboard_get();
|
|
|
|
len = strlen(text);
|
|
|
|
gui_edit_box_add(box, text, len);
|
|
|
|
}
|
|
|
|
|
2015-05-13 15:47:11 +03:00
|
|
|
static void
|
2015-07-30 23:19:06 +03:00
|
|
|
init_demo(struct demo_gui *gui, struct gui_font *font)
|
2015-05-09 15:26:44 +03:00
|
|
|
{
|
2015-07-30 23:19:06 +03:00
|
|
|
struct gui_config *config = &gui->config;
|
|
|
|
struct state *win = &gui->state;
|
2015-08-02 14:49:51 +03:00
|
|
|
struct gui_clipboard clip;
|
2015-07-30 23:19:06 +03:00
|
|
|
gui->font = *font;
|
|
|
|
gui->running = gui_true;
|
2015-05-13 15:47:11 +03:00
|
|
|
|
2015-08-06 17:36:28 +03:00
|
|
|
gui_command_queue_init_fixed(&gui->queue, gui->memory, MAX_MEMORY);
|
2015-07-30 23:19:06 +03:00
|
|
|
gui_config_default(config, GUI_DEFAULT_ALL, font);
|
2015-08-07 17:53:52 +03:00
|
|
|
|
|
|
|
/* panel */
|
2015-07-30 23:19:06 +03:00
|
|
|
gui_panel_init(&gui->panel, 30, 30, 280, 530,
|
2015-08-10 21:34:47 +03:00
|
|
|
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|GUI_PANEL_SCALEABLE,
|
|
|
|
&gui->queue, config, gui->input);
|
2015-08-07 17:53:52 +03:00
|
|
|
gui_panel_init(&gui->sub, 400, 50, 220, 180,
|
2015-08-06 17:36:28 +03:00
|
|
|
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|GUI_PANEL_SCALEABLE,
|
2015-08-10 21:34:47 +03:00
|
|
|
&gui->queue, config, gui->input);
|
2015-06-03 01:58:57 +03:00
|
|
|
|
2015-08-06 17:36:28 +03:00
|
|
|
/* widget state */
|
2015-08-10 21:34:47 +03:00
|
|
|
clip.userdata.ptr = NULL,
|
|
|
|
clip.copy = copy;
|
|
|
|
clip.paste = paste;
|
2015-08-02 14:49:51 +03:00
|
|
|
gui_edit_box_init_fixed(&win->input, win->input_buffer, MAX_BUFFER, &clip, NULL);
|
2015-08-10 21:34:47 +03:00
|
|
|
|
2015-07-30 23:19:06 +03:00
|
|
|
win->config_tab = GUI_MINIMIZED;
|
|
|
|
win->widget_tab = GUI_MINIMIZED;
|
|
|
|
win->style_tab = GUI_MINIMIZED;
|
|
|
|
win->round_tab = GUI_MINIMIZED;
|
|
|
|
win->color_tab = GUI_MINIMIZED;
|
|
|
|
win->flag_tab = GUI_MINIMIZED;
|
|
|
|
win->scaleable = gui_true;
|
|
|
|
win->slider = 2.0f;
|
|
|
|
win->progressbar = 50;
|
2015-08-07 17:53:52 +03:00
|
|
|
win->spinner = 100;
|
2015-05-13 15:47:11 +03:00
|
|
|
|
2015-07-30 23:19:06 +03:00
|
|
|
{
|
2015-08-06 17:36:28 +03:00
|
|
|
/* test tree data */
|
2015-07-30 23:19:06 +03:00
|
|
|
struct test_tree *tree = &win->tree;
|
|
|
|
tree->root.state = GUI_NODE_ACTIVE;
|
|
|
|
tree->root.name = "Primitives";
|
|
|
|
tree->root.parent = NULL;
|
|
|
|
tree->root.count = 2;
|
|
|
|
tree->root.children[0] = &win->nodes[0];
|
|
|
|
tree->root.children[1] = &win->nodes[4];
|
|
|
|
|
|
|
|
win->nodes[0].state = 0;
|
|
|
|
win->nodes[0].name = "Boxes";
|
|
|
|
win->nodes[0].parent = &tree->root;
|
|
|
|
win->nodes[0].count = 2;
|
|
|
|
win->nodes[0].children[0] = &win->nodes[1];
|
|
|
|
win->nodes[0].children[1] = &win->nodes[2];
|
|
|
|
|
|
|
|
win->nodes[1].state = 0;
|
|
|
|
win->nodes[1].name = "Box0";
|
|
|
|
win->nodes[1].parent = &win->nodes[0];
|
|
|
|
win->nodes[1].count = 0;
|
|
|
|
|
|
|
|
win->nodes[2].state = 0;
|
|
|
|
win->nodes[2].name = "Box1";
|
|
|
|
win->nodes[2].parent = &win->nodes[0];
|
|
|
|
win->nodes[2].count = 0;
|
|
|
|
|
|
|
|
win->nodes[4].state = GUI_NODE_ACTIVE;
|
|
|
|
win->nodes[4].name = "Cylinders";
|
|
|
|
win->nodes[4].parent = &tree->root;
|
|
|
|
win->nodes[4].count = 2;
|
|
|
|
win->nodes[4].children[0] = &win->nodes[5];
|
|
|
|
win->nodes[4].children[1] = &win->nodes[6];
|
|
|
|
|
|
|
|
win->nodes[5].state = 0;
|
|
|
|
win->nodes[5].name = "Cylinder0";
|
|
|
|
win->nodes[5].parent = &win->nodes[4];
|
|
|
|
win->nodes[5].count = 0;
|
|
|
|
|
|
|
|
win->nodes[6].state = 0;
|
|
|
|
win->nodes[6].name = "Cylinder1";
|
|
|
|
win->nodes[6].parent = &win->nodes[4];
|
|
|
|
win->nodes[6].count = 0;
|
2015-07-18 04:37:42 +03:00
|
|
|
}
|
2015-05-09 15:26:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-10 21:34:47 +03:00
|
|
|
run_demo(struct demo_gui *gui)
|
2015-05-09 15:26:44 +03:00
|
|
|
{
|
2015-07-30 23:19:06 +03:00
|
|
|
struct gui_panel_layout layout;
|
|
|
|
struct state *state = &gui->state;
|
|
|
|
struct gui_panel_layout tab;
|
2015-05-13 15:47:11 +03:00
|
|
|
struct gui_config *config = &gui->config;
|
2015-07-30 23:19:06 +03:00
|
|
|
static const char *shelfs[] = {"Histogram", "Lines"};
|
2015-08-06 17:36:28 +03:00
|
|
|
enum {EASY, HARD};
|
2015-06-08 11:55:35 +03:00
|
|
|
|
2015-08-10 21:34:47 +03:00
|
|
|
gui_panel_begin(&layout, &gui->panel);
|
2015-07-30 23:19:06 +03:00
|
|
|
{
|
2015-08-10 21:34:47 +03:00
|
|
|
/* Header */
|
2015-07-30 23:19:06 +03:00
|
|
|
gui->running = !gui_panel_header(&layout, "Demo",
|
|
|
|
GUI_CLOSEABLE|GUI_MINIMIZABLE, GUI_CLOSEABLE, GUI_HEADER_RIGHT);
|
2015-05-17 14:38:37 +03:00
|
|
|
|
2015-07-30 23:19:06 +03:00
|
|
|
/* Panel style configuration */
|
|
|
|
if (gui_panel_layout_push(&layout, GUI_LAYOUT_TAB, "Style", &state->config_tab))
|
|
|
|
{
|
|
|
|
if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Options", &state->flag_tab)) {
|
|
|
|
update_flags(&layout);
|
|
|
|
gui_panel_layout_pop(&layout);
|
|
|
|
}
|
|
|
|
if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Properties", &state->style_tab)) {
|
|
|
|
properties_tab(&layout, config);
|
|
|
|
gui_panel_layout_pop(&layout);
|
|
|
|
}
|
|
|
|
if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Rounding", &state->round_tab)) {
|
|
|
|
round_tab(&layout, config);
|
|
|
|
gui_panel_layout_pop(&layout);
|
|
|
|
}
|
|
|
|
if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Color", &state->color_tab)) {
|
|
|
|
color_tab(&layout, state, config);
|
|
|
|
gui_panel_layout_pop(&layout);
|
|
|
|
}
|
|
|
|
gui_panel_layout_pop(&layout);
|
|
|
|
}
|
2015-05-17 14:38:37 +03:00
|
|
|
|
2015-07-30 23:19:06 +03:00
|
|
|
/* Widgets examples */
|
|
|
|
if (gui_panel_layout_push(&layout, GUI_LAYOUT_TAB, "Widgets", &state->widget_tab)) {
|
|
|
|
widget_panel(&layout, state);
|
|
|
|
gui_panel_layout_pop(&layout);
|
|
|
|
}
|
|
|
|
|
2015-08-10 21:34:47 +03:00
|
|
|
/* popup panel */
|
|
|
|
if (state->popup) {
|
|
|
|
gui_panel_popup_begin(&layout, &tab, gui_rect(20, 10, 220, 150), gui_vec2(0,0));
|
|
|
|
{
|
|
|
|
if (gui_panel_header(&tab, "Popup", GUI_CLOSEABLE, GUI_CLOSEABLE, GUI_HEADER_LEFT)) {
|
|
|
|
gui_panel_popup_close(&tab);
|
|
|
|
state->popup = gui_false;
|
|
|
|
}
|
|
|
|
gui_panel_row_dynamic(&tab, 30, 1);
|
|
|
|
gui_panel_label(&tab, "Are you sure you want to exit?", GUI_TEXT_LEFT);
|
|
|
|
gui_panel_row_dynamic(&tab, 30, 4);
|
|
|
|
gui_panel_spacing(&tab, 1);
|
|
|
|
if (gui_panel_button_text(&tab, "Yes", GUI_BUTTON_DEFAULT)) {
|
|
|
|
gui_panel_popup_close(&tab);
|
|
|
|
state->popup = gui_false;
|
|
|
|
}
|
|
|
|
if (gui_panel_button_text(&tab, "No", GUI_BUTTON_DEFAULT)) {
|
|
|
|
gui_panel_popup_close(&tab);
|
|
|
|
state->popup = gui_false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gui_panel_popup_end(&layout, &tab);
|
|
|
|
}
|
|
|
|
|
2015-07-30 23:19:06 +03:00
|
|
|
/* Shelf + Graphes */
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(&layout, 180, 1);
|
2015-07-30 23:19:06 +03:00
|
|
|
state->shelf_selection = gui_panel_shelf_begin(&layout, &tab, shelfs,
|
|
|
|
LEN(shelfs), state->shelf_selection, state->shelf_scrollbar);
|
|
|
|
graph_panel(&tab, state->shelf_selection);
|
|
|
|
state->shelf_scrollbar = gui_panel_shelf_end(&layout, &tab);
|
|
|
|
|
|
|
|
/* Tables */
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(&layout, 180, 1);
|
2015-07-30 23:19:06 +03:00
|
|
|
gui_panel_group_begin(&layout, &tab, "Table", state->table_scrollbar);
|
|
|
|
table_panel(&tab);
|
|
|
|
state->table_scrollbar = gui_panel_group_end(&layout, &tab);
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Tree */
|
|
|
|
struct gui_tree tree;
|
2015-08-05 13:48:01 +03:00
|
|
|
gui_panel_row_dynamic(&layout, 250, 1);
|
2015-08-02 14:49:51 +03:00
|
|
|
gui_panel_tree_begin(&layout, &tree, "Tree", 20, state->tree_scrollbar);
|
2015-07-30 23:19:06 +03:00
|
|
|
upload_tree(&state->tree, &tree, &state->tree.root);
|
2015-08-02 14:49:51 +03:00
|
|
|
state->tree_scrollbar = gui_panel_tree_end(&layout, &tree);
|
2015-07-30 23:19:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
gui_panel_end(&layout, &gui->panel);
|
2015-08-06 17:36:28 +03:00
|
|
|
|
2015-08-10 21:34:47 +03:00
|
|
|
gui_panel_begin(&layout, &gui->sub);
|
2015-08-06 17:36:28 +03:00
|
|
|
{
|
|
|
|
const char *items[] = {"Fist", "Pistol", "Railgun", "BFG"};
|
|
|
|
gui_panel_header(&layout, "Demo", GUI_CLOSEABLE, 0, GUI_HEADER_LEFT);
|
2015-08-07 18:09:23 +03:00
|
|
|
gui_panel_row_static(&layout, 30, 80, 1);
|
2015-08-06 17:36:28 +03:00
|
|
|
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT)) {
|
|
|
|
/* event handling */
|
|
|
|
}
|
|
|
|
gui_panel_row_dynamic(&layout, 30, 2);
|
|
|
|
if (gui_panel_option(&layout, "easy", state->op == EASY)) state->op = EASY;
|
|
|
|
if (gui_panel_option(&layout, "hard", state->op == HARD)) state->op = HARD;
|
|
|
|
gui_panel_label(&layout, "Weapon:", GUI_TEXT_LEFT);
|
|
|
|
state->cur = gui_panel_selector(&layout, items, LEN(items), state->cur);
|
|
|
|
}
|
|
|
|
gui_panel_end(&layout, &gui->sub);
|
2015-05-09 15:26:44 +03:00
|
|
|
}
|
|
|
|
|