diff --git a/demo/d3d11/main.c b/demo/d3d11/main.c index 6e97263..ecc002e 100644 --- a/demo/d3d11/main.c +++ b/demo/d3d11/main.c @@ -32,17 +32,32 @@ * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ - #define UNUSED(a) (void)a - #define MIN(a,b) ((a) < (b) ? (a) : (b)) - #define MAX(a,b) ((a) < (b) ? (b) : (a)) - #define LEN(a) (sizeof(a)/sizeof(a)[0]) + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -189,10 +204,12 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle)*/;} /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif background = nk_rgb(28,48,62); while (running) @@ -244,9 +261,15 @@ int main(void) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ {/* Draw */ diff --git a/demo/d3d9/main.c b/demo/d3d9/main.c index 516426c..09b52f6 100644 --- a/demo/d3d9/main.c +++ b/demo/d3d9/main.c @@ -29,17 +29,32 @@ * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ - #define UNUSED(a) (void)a - #define MIN(a,b) ((a) < (b) ? (a) : (b)) - #define MAX(a,b) ((a) < (b) ? (b) : (a)) - #define LEN(a) (sizeof(a)/sizeof(a)[0]) + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -194,10 +209,12 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle)*/;} /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif background = nk_rgb(28,48,62); while (running) @@ -248,9 +265,15 @@ int main(void) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/gdi/main.c b/demo/gdi/main.c index c91ebb4..1755b9c 100644 --- a/demo/gdi/main.c +++ b/demo/gdi/main.c @@ -24,17 +24,32 @@ * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -94,10 +109,12 @@ int main(void) ctx = nk_gdi_init(font, dc, WINDOW_WIDTH, WINDOW_HEIGHT); /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif while (running) { @@ -144,9 +161,15 @@ int main(void) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/gdip/main.c b/demo/gdip/main.c index dfc28ca..a90a0cf 100644 --- a/demo/gdip/main.c +++ b/demo/gdip/main.c @@ -23,18 +23,33 @@ * EXAMPLE * * ===============================================================*/ -/* These are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ - #define UNUSED(a) (void)a - #define MIN(a,b) ((a) < (b) ? (a) : (b)) - #define MAX(a,b) ((a) < (b) ? (b) : (a)) - #define LEN(a) (sizeof(a)/sizeof(a)[0]) +/* This are some code examples to provide a small overview of what can be + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -90,10 +105,12 @@ int main(void) nk_gdip_set_font(font); /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif while (running) { @@ -139,9 +156,15 @@ int main(void) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/glfw_opengl2/main.c b/demo/glfw_opengl2/main.c index 2f6abde..941dffa 100644 --- a/demo/glfw_opengl2/main.c +++ b/demo/glfw_opengl2/main.c @@ -27,23 +27,38 @@ #define WINDOW_WIDTH 1200 #define WINDOW_HEIGHT 800 -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) - /* =============================================================== * * EXAMPLE * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -87,11 +102,12 @@ int main(void) /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_set_font(ctx, &droid->handle);*/} - /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif background = nk_rgb(28,48,62); while (!glfwWindowShouldClose(win)) @@ -136,9 +152,15 @@ int main(void) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/glfw_opengl3/main.c b/demo/glfw_opengl3/main.c index c6f5077..e650628 100644 --- a/demo/glfw_opengl3/main.c +++ b/demo/glfw_opengl3/main.c @@ -31,23 +31,38 @@ #define MAX_VERTEX_BUFFER 512 * 1024 #define MAX_ELEMENT_BUFFER 128 * 1024 -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) - /* =============================================================== * * EXAMPLE * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -104,11 +119,12 @@ int main(void) /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_set_font(ctx, &droid->handle);*/} - /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif background = nk_rgb(28,48,62); while (!glfwWindowShouldClose(win)) @@ -153,9 +169,15 @@ int main(void) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/node_editor.c b/demo/node_editor.c index 6949f59..d4f34c3 100644 --- a/demo/node_editor.c +++ b/demo/node_editor.c @@ -104,7 +104,7 @@ node_editor_add(struct node_editor *editor, const char *name, struct nk_rect bou { static int IDs = 0; struct node *node; - assert((nk_size)editor->node_count < LEN(editor->node_buf)); + NK_ASSERT((nk_size)editor->node_count < NK_LEN(editor->node_buf)); node = &editor->node_buf[editor->node_count++]; node->ID = IDs++; node->value = 0; @@ -122,7 +122,7 @@ node_editor_link(struct node_editor *editor, int in_id, int in_slot, int out_id, int out_slot) { struct node_link *link; - assert((nk_size)editor->link_count < LEN(editor->links)); + NK_ASSERT((nk_size)editor->link_count < NK_LEN(editor->links)); link = &editor->links[editor->link_count++]; link->input_id = in_id; link->input_slot = in_slot; @@ -169,6 +169,7 @@ node_editor(struct nk_context *ctx) { struct node *it = nodedit->begin; struct nk_rect size = nk_layout_space_bounds(ctx); + struct nk_panel *node = 0; if (nodedit->show_grid) { /* display grid */ @@ -182,7 +183,6 @@ node_editor(struct nk_context *ctx) } /* execute each node as a movable group */ - struct nk_panel *node; while (it) { /* calculate scrolled node window position and size */ nk_layout_space_push(ctx, nk_rect(it->bounds.x - nodedit->scrolling.x, diff --git a/demo/overview.c b/demo/overview.c index b4c2fa9..60357f9 100644 --- a/demo/overview.c +++ b/demo/overview.c @@ -228,7 +228,7 @@ overview(struct nk_context *ctx) nk_label(ctx, "Slider float", NK_TEXT_LEFT); nk_slider_float(ctx, 0, &float_slider, 5.0, 0.5f); - nk_labelf(ctx, NK_TEXT_LEFT, "Progressbar" , prog_value); + nk_labelf(ctx, NK_TEXT_LEFT, "Progressbar: %zu" , prog_value); nk_progress(ctx, &prog_value, 100, NK_MODIFIABLE); nk_layout_row(ctx, NK_STATIC, 25, 2, ratio); @@ -924,6 +924,7 @@ overview(struct nk_context *ctx) { nk_style_pop_vec2(ctx); switch (current_tab) { + default: break; case CHART_LINE: nk_layout_row_dynamic(ctx, 100, 1); bounds = nk_widget_bounds(ctx); diff --git a/demo/sdl_opengl2/main.c b/demo/sdl_opengl2/main.c index 04f7866..4e07db6 100644 --- a/demo/sdl_opengl2/main.c +++ b/demo/sdl_opengl2/main.c @@ -28,23 +28,38 @@ #define WINDOW_WIDTH 1200 #define WINDOW_HEIGHT 800 -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) - /* =============================================================== * * EXAMPLE * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -52,7 +67,7 @@ * * ===============================================================*/ int -main(int argc, char* argv[]) +main(void) { /* Platform */ SDL_Window *win; @@ -94,11 +109,12 @@ main(int argc, char* argv[]) /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_set_font(ctx, &roboto->handle)*/;} - /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif background = nk_rgb(28,48,62); while (running) @@ -147,9 +163,15 @@ main(int argc, char* argv[]) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/sdl_opengl3/main.c b/demo/sdl_opengl3/main.c index 5c31fa3..7f4a54c 100644 --- a/demo/sdl_opengl3/main.c +++ b/demo/sdl_opengl3/main.c @@ -26,36 +26,51 @@ #include "../../nuklear.h" #include "nuklear_sdl_gl3.h" -#define WINDOW_WIDTH 800 -#define WINDOW_HEIGHT 600 +#define WINDOW_WIDTH 1200 +#define WINDOW_HEIGHT 800 #define MAX_VERTEX_MEMORY 512 * 1024 #define MAX_ELEMENT_MEMORY 128 * 1024 -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) - /* =============================================================== * * EXAMPLE * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * * DEMO * * ===============================================================*/ -int main(int argc, char* argv[]) +int main(void) { /* Platform */ SDL_Window *win; @@ -105,10 +120,12 @@ int main(int argc, char* argv[]) /*nk_style_set_font(ctx, &roboto->handle);*/} /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif background = nk_rgb(28,48,62); while (running) @@ -142,9 +159,15 @@ int main(int argc, char* argv[]) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/sfml_opengl2/main.cpp b/demo/sfml_opengl2/main.cpp index 065282a..955502b 100644 --- a/demo/sfml_opengl2/main.cpp +++ b/demo/sfml_opengl2/main.cpp @@ -28,23 +28,38 @@ #define WINDOW_WIDTH 1200 #define WINDOW_HEIGHT 800 -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) - /* =============================================================== * * EXAMPLE * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -78,10 +93,12 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/ /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif struct nk_color background; background = nk_rgb(28,48,62); @@ -135,9 +152,15 @@ int main(void) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/sfml_opengl3/main.cpp b/demo/sfml_opengl3/main.cpp index b2cae73..538967d 100644 --- a/demo/sfml_opengl3/main.cpp +++ b/demo/sfml_opengl3/main.cpp @@ -30,23 +30,38 @@ #define MAX_VERTEX_BUFFER 512 * 1024 #define MAX_ELEMENT_BUFFER 128 * 1024 -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) - /* =============================================================== * * EXAMPLE * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -84,10 +99,12 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/ /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif struct nk_color background; background = nk_rgb(28,48,62); @@ -142,9 +159,15 @@ int main(void) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/style.c b/demo/style.c index 8cea152..17c48fe 100644 --- a/demo/style.c +++ b/demo/style.c @@ -1,6 +1,6 @@ enum theme {THEME_BLACK, THEME_WHITE, THEME_RED, THEME_BLUE, THEME_DARK}; -void +static void set_style(struct nk_context *ctx, enum theme theme) { struct nk_color table[NK_COLOR_COUNT]; diff --git a/demo/x11/main.c b/demo/x11/main.c index a6785a4..791653d 100644 --- a/demo/x11/main.c +++ b/demo/x11/main.c @@ -23,11 +23,6 @@ #define WINDOW_WIDTH 800 #define WINDOW_HEIGHT 600 -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) - typedef struct XWindow XWindow; struct XWindow { Display *dpy; @@ -55,14 +50,6 @@ die(const char *fmt, ...) exit(EXIT_FAILURE); } -static void* -xcalloc(size_t siz, size_t n) -{ - void *ptr = calloc(siz, n); - if (!ptr) die("Out of memory\n"); - return ptr; -} - static long timestamp(void) { @@ -87,13 +74,33 @@ sleep_for(long t) * EXAMPLE * * ===============================================================*/ -/* These are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ +/* This are some code examples to provide a small overview of what can be + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -140,11 +147,12 @@ main(void) xw.font = nk_xfont_create(xw.dpy, "fixed"); ctx = nk_xlib_init(xw.font, xw.dpy, xw.screen, xw.win, xw.width, xw.height); - /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif while (running) { @@ -182,9 +190,15 @@ main(void) if (nk_window_is_hidden(ctx, "Demo")) break; /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/x11_opengl2/main.c b/demo/x11_opengl2/main.c index 47d700d..49df99e 100644 --- a/demo/x11_opengl2/main.c +++ b/demo/x11_opengl2/main.c @@ -31,23 +31,38 @@ #define MAX_VERTEX_BUFFER 512 * 1024 #define MAX_ELEMENT_BUFFER 128 * 1024 -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) - /* =============================================================== * * EXAMPLE * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -67,7 +82,7 @@ struct XWindow { }; static int gl_err = nk_false; static int gl_error_handler(Display *dpy, XErrorEvent *ev) -{UNUSED((dpy, ev)); gl_err = nk_true; return 0;} +{NK_UNUSED(dpy); NK_UNUSED(ev); gl_err = nk_true; return 0;} static void die(const char *fmt, ...) @@ -101,7 +116,7 @@ has_extension(const char *string, const char *ext) return nk_false; } -int main(int argc, char **argv) +int main(void) { /* Platform */ int running = 1; @@ -152,7 +167,7 @@ int main(int argc, char **argv) glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLE_BUFFERS, &sample_buffer); glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLES, &samples); if ((fb_best < 0) || (sample_buffer && samples > best_num_samples)) - fb_best = i; best_num_samples = samples; + fb_best = i, best_num_samples = samples; } } win.fbc = fbc[fb_best]; @@ -236,11 +251,12 @@ int main(int argc, char **argv) /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_set_font(ctx, &droid->handle);*/} - /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif background = nk_rgb(28,48,62); while (running) @@ -291,9 +307,15 @@ int main(int argc, char **argv) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/x11_opengl3/main.c b/demo/x11_opengl3/main.c index fcdee57..362a8e9 100644 --- a/demo/x11_opengl3/main.c +++ b/demo/x11_opengl3/main.c @@ -29,23 +29,38 @@ #define MAX_VERTEX_BUFFER 512 * 1024 #define MAX_ELEMENT_BUFFER 128 * 1024 -#define UNUSED(a) (void)a -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a)/sizeof(a)[0]) - /* =============================================================== * * EXAMPLE * * ===============================================================*/ /* This are some code examples to provide a small overview of what can be - * done with this library. To try out an example uncomment the include - * and the corresponding function. */ -/*#include "../style.c"*/ -/*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ + * done with this library. To try out an example uncomment the defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -65,7 +80,7 @@ struct XWindow { }; static int gl_err = nk_false; static int gl_error_handler(Display *dpy, XErrorEvent *ev) -{UNUSED((dpy, ev)); gl_err = nk_true;return 0;} +{NK_UNUSED(dpy); NK_UNUSED(ev); gl_err = nk_true;return 0;} static void die(const char *fmt, ...) @@ -99,7 +114,7 @@ has_extension(const char *string, const char *ext) return nk_false; } -int main(int argc, char **argv) +int main(void) { /* Platform */ int running = 1; @@ -150,7 +165,7 @@ int main(int argc, char **argv) glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLE_BUFFERS, &sample_buffer); glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLES, &samples); if ((fb_best < 0) || (sample_buffer && samples > best_num_samples)) - fb_best = i; best_num_samples = samples; + fb_best = i, best_num_samples = samples; } } win.fbc = fbc[fb_best]; @@ -233,11 +248,12 @@ int main(int argc, char **argv) /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_set_font(ctx, &droid->handle);*/} - /* style.c */ + #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ + #endif background = nk_rgb(28,48,62); while (running) @@ -288,9 +304,15 @@ int main(int argc, char **argv) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */