From 459ba9c48cb5db19642efffd45d1d7d8626c90fc Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Thu, 16 Dec 2021 15:16:33 +0000 Subject: [PATCH] Integrate the canvas example with the demos --- demo/allegro5/main.c | 53 ++++++++++++++++++---- demo/canvas.c | 84 +++++++++++++++++++++++++++++++++++ demo/d3d11/main.c | 8 ++++ demo/d3d9/main.c | 8 ++++ demo/gdi/main.c | 8 ++++ demo/gdip/main.c | 8 ++++ demo/glfw_opengl2/main.c | 8 ++++ demo/glfw_opengl3/main.c | 8 ++++ demo/glfw_opengl4/main.c | 8 ++++ demo/sdl2surface_rawfb/main.c | 53 ++++++++++++++++++++++ demo/sdl_opengl2/main.c | 8 ++++ demo/sdl_opengl3/main.c | 8 ++++ demo/sdl_opengles2/main.c | 52 ++++++++++++++++++---- demo/sfml_opengl2/main.cpp | 8 ++++ demo/sfml_opengl3/main.cpp | 8 ++++ demo/wayland_rawfb/main.c | 63 +++++++++++++++++++++----- demo/x11/main.c | 8 ++++ demo/x11_opengl2/main.c | 8 ++++ demo/x11_opengl3/main.c | 8 ++++ demo/x11_rawfb/main.c | 8 ++++ demo/x11_xft/main.c | 8 ++++ 21 files changed, 404 insertions(+), 29 deletions(-) create mode 100644 demo/canvas.c diff --git a/demo/allegro5/main.c b/demo/allegro5/main.c index 2755f0d..0d748bf 100644 --- a/demo/allegro5/main.c +++ b/demo/allegro5/main.c @@ -29,18 +29,44 @@ #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_CANVAS */ +#define INCLUDE_OVERVIEW +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -139,9 +165,18 @@ int main(void) nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - overview(ctx); - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif + #ifdef INCLUDE_OVERVIEW + overview(ctx); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(ctx); + #endif /* ----------------------------------------- */ /* Draw */ diff --git a/demo/canvas.c b/demo/canvas.c new file mode 100644 index 0000000..30b76da --- /dev/null +++ b/demo/canvas.c @@ -0,0 +1,84 @@ +/* nuklear - v1.05 - public domain */ +struct nk_canvas { + struct nk_command_buffer *painter; + struct nk_vec2 item_spacing; + struct nk_vec2 panel_padding; + struct nk_style_item window_background; +}; + +static nk_bool +canvas_begin(struct nk_context *ctx, struct nk_canvas *canvas, nk_flags flags, + int x, int y, int width, int height, struct nk_color background_color) +{ + /* save style properties which will be overwritten */ + canvas->panel_padding = ctx->style.window.padding; + canvas->item_spacing = ctx->style.window.spacing; + canvas->window_background = ctx->style.window.fixed_background; + + /* use the complete window space and set background */ + ctx->style.window.spacing = nk_vec2(0,0); + ctx->style.window.padding = nk_vec2(0,0); + ctx->style.window.fixed_background = nk_style_item_color(background_color); + + /* create/update window and set position + size */ + if (!nk_begin(ctx, "Canvas", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR|flags)) + return nk_false; + + /* allocate the complete window space for drawing */ + { + struct nk_rect total_space; + total_space = nk_window_get_content_region(ctx); + nk_layout_row_dynamic(ctx, total_space.h, 1); + nk_widget(&total_space, ctx); + canvas->painter = nk_window_get_canvas(ctx); + } + + return nk_true; +} + +static void +canvas_end(struct nk_context *ctx, struct nk_canvas *canvas) +{ + nk_end(ctx); + ctx->style.window.spacing = canvas->panel_padding; + ctx->style.window.padding = canvas->item_spacing; + ctx->style.window.fixed_background = canvas->window_background; +} + +static void +canvas(struct nk_context *ctx) +{ + struct nk_canvas canvas; + if (canvas_begin(ctx, &canvas, NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| + NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE, 10, 10, 500, 550, nk_rgb(250,250,250))) + { + float x = canvas.painter->clip.x, y = canvas.painter->clip.y; + + nk_fill_rect(canvas.painter, nk_rect(x + 15, y + 15, 210, 210), 5, nk_rgb(247, 230, 154)); + nk_fill_rect(canvas.painter, nk_rect(x + 20, y + 20, 200, 200), 5, nk_rgb(188, 174, 118)); + /* nk_draw_text(canvas.painter, nk_rect(x + 30, y + 30, 150, 20), "Text to draw", 12, &font->handle, nk_rgb(188,174,118), nk_rgb(0,0,0)); */ + nk_fill_rect(canvas.painter, nk_rect(x + 250, y + 20, 100, 100), 0, nk_rgb(0,0,255)); + nk_fill_circle(canvas.painter, nk_rect(x + 20, y + 250, 100, 100), nk_rgb(255,0,0)); + nk_fill_triangle(canvas.painter, x + 250, y + 250, x + 350, y + 250, x + 300, y + 350, nk_rgb(0,255,0)); + nk_fill_arc(canvas.painter, x + 300, y + 180, 50, 0, 3.141592654f * 3.0f / 4.0f, nk_rgb(255,255,0)); + + { + float points[12]; + points[0] = x + 200; points[1] = y + 250; + points[2] = x + 250; points[3] = y + 350; + points[4] = x + 225; points[5] = y + 350; + points[6] = x + 200; points[7] = y + 300; + points[8] = x + 175; points[9] = y + 350; + points[10] = x + 150; points[11] = y + 350; + nk_fill_polygon(canvas.painter, points, 6, nk_rgb(0,0,0)); + } + + nk_stroke_line(canvas.painter, x + 15, y + 10, x + 200, y + 10, 2.0f, nk_rgb(189,45,75)); + nk_stroke_rect(canvas.painter, nk_rect(x + 370, y + 20, 100, 100), 10, 3, nk_rgb(0,0,255)); + nk_stroke_curve(canvas.painter, x + 380, y + 200, x + 405, y + 270, x + 455, y + 120, x + 480, y + 200, 2, nk_rgb(0,150,220)); + nk_stroke_circle(canvas.painter, nk_rect(x + 20, y + 370, 100, 100), 5, nk_rgb(0,255,120)); + nk_stroke_triangle(canvas.painter, x + 370, y + 250, x + 470, y + 250, x + 420, y + 350, 6, nk_rgb(255,0,143)); + } + canvas_end(ctx, &canvas); +} + diff --git a/demo/d3d11/main.c b/demo/d3d11/main.c index 14d0d1c..c10d36a 100644 --- a/demo/d3d11/main.c +++ b/demo/d3d11/main.c @@ -36,12 +36,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -52,6 +54,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -264,6 +269,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/d3d9/main.c b/demo/d3d9/main.c index 76c8f81..d43bcc0 100644 --- a/demo/d3d9/main.c +++ b/demo/d3d9/main.c @@ -33,12 +33,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -49,6 +51,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -269,6 +274,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/gdi/main.c b/demo/gdi/main.c index 1755b9c..01dd5ce 100644 --- a/demo/gdi/main.c +++ b/demo/gdi/main.c @@ -28,12 +28,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -44,6 +46,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -164,6 +169,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/gdip/main.c b/demo/gdip/main.c index a90a0cf..1fdabe4 100644 --- a/demo/gdip/main.c +++ b/demo/gdip/main.c @@ -28,12 +28,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -44,6 +46,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -159,6 +164,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/glfw_opengl2/main.c b/demo/glfw_opengl2/main.c index f3d3d9d..0301eee 100644 --- a/demo/glfw_opengl2/main.c +++ b/demo/glfw_opengl2/main.c @@ -37,12 +37,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ #define INCLUDE_OVERVIEW /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -53,6 +55,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -155,6 +160,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/glfw_opengl3/main.c b/demo/glfw_opengl3/main.c index b9b09d7..af02f68 100644 --- a/demo/glfw_opengl3/main.c +++ b/demo/glfw_opengl3/main.c @@ -41,12 +41,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ #define INCLUDE_OVERVIEW /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -57,6 +59,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -173,6 +178,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/glfw_opengl4/main.c b/demo/glfw_opengl4/main.c index 5385fb3..dd78a40 100644 --- a/demo/glfw_opengl4/main.c +++ b/demo/glfw_opengl4/main.c @@ -41,12 +41,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ #define INCLUDE_OVERVIEW /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -57,6 +59,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -194,6 +199,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/sdl2surface_rawfb/main.c b/demo/sdl2surface_rawfb/main.c index f383cbc..a52e71b 100644 --- a/demo/sdl2surface_rawfb/main.c +++ b/demo/sdl2surface_rawfb/main.c @@ -22,6 +22,44 @@ #define NK_SDLSURFACE_IMPLEMENTATION #include "sdl2surface_rawfb.h" +/* =============================================================== + * + * 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 defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif + static int translate_sdl_key(struct SDL_Keysym const *k) { /*keyboard handling left as an exercise for the reader */ @@ -187,6 +225,21 @@ int main(int argc, char **argv) /* grid_demo(&(context->ctx)); */ + /* -------------- EXAMPLES ---------------- */ + #ifdef INCLUDE_CALCULATOR + calculator(&(context->ctx)); + #endif + #ifdef INCLUDE_CANVAS + canvas(&(context->ctx)); + #endif + #ifdef INCLUDE_OVERVIEW + overview(&(context->ctx)); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(&(context->ctx)); + #endif + /* ----------------------------------------- */ + nk_sdlsurface_render(context, clear, 1); diff --git a/demo/sdl_opengl2/main.c b/demo/sdl_opengl2/main.c index 309351c..157cfab 100644 --- a/demo/sdl_opengl2/main.c +++ b/demo/sdl_opengl2/main.c @@ -37,12 +37,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -53,6 +55,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -168,6 +173,9 @@ main(int argc, char *argv[]) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/sdl_opengl3/main.c b/demo/sdl_opengl3/main.c index 09eb89e..2aa1588 100644 --- a/demo/sdl_opengl3/main.c +++ b/demo/sdl_opengl3/main.c @@ -41,12 +41,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -57,6 +59,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -178,6 +183,9 @@ int main(int argc, char *argv[]) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/sdl_opengles2/main.c b/demo/sdl_opengles2/main.c index e137aee..02a0964 100644 --- a/demo/sdl_opengles2/main.c +++ b/demo/sdl_opengles2/main.c @@ -38,12 +38,37 @@ * * ===============================================================*/ /* 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_CANVAS */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif /* =============================================================== * @@ -112,9 +137,18 @@ MainLoop(void* loopArg){ nk_end(ctx); /* -------------- EXAMPLES ---------------- */ - /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + #ifdef INCLUDE_CALCULATOR + calculator(ctx); + #endif + #ifdef INCLUDE_CANVAS + canvas(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 db0bb29..a815d09 100644 --- a/demo/sfml_opengl2/main.cpp +++ b/demo/sfml_opengl2/main.cpp @@ -37,12 +37,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -53,6 +55,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -154,6 +159,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/sfml_opengl3/main.cpp b/demo/sfml_opengl3/main.cpp index 8bd669a..45afb6c 100644 --- a/demo/sfml_opengl3/main.cpp +++ b/demo/sfml_opengl3/main.cpp @@ -39,12 +39,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -55,6 +57,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -161,6 +166,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/wayland_rawfb/main.c b/demo/wayland_rawfb/main.c index 0db432c..98f2c10 100644 --- a/demo/wayland_rawfb/main.c +++ b/demo/wayland_rawfb/main.c @@ -28,6 +28,44 @@ #define DTIME 20 +/* =============================================================== + * + * 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 defines */ +/*#define INCLUDE_ALL */ +/*#define INCLUDE_STYLE */ +/*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ +/*#define INCLUDE_OVERVIEW */ +/*#define INCLUDE_NODE_EDITOR */ + +#ifdef INCLUDE_ALL + #define INCLUDE_STYLE + #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS + #define INCLUDE_OVERVIEW + #define INCLUDE_NODE_EDITOR +#endif + +#ifdef INCLUDE_STYLE + #include "../style.c" +#endif +#ifdef INCLUDE_CALCULATOR + #include "../calculator.c" +#endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif +#ifdef INCLUDE_OVERVIEW + #include "../overview.c" +#endif +#ifdef INCLUDE_NODE_EDITOR + #include "../node_editor.c" +#endif + //WAYLAND OUTPUT INTERFACE static void nk_wayland_output_cb_geometry(void *data, struct wl_output *wl_output, int x, int y, int w, int h, int subpixel, const char *make, const char *model, int transform) @@ -504,17 +542,20 @@ int main () if (nk_window_is_closed(&(nk_wayland_ctx.ctx), "Demo")) break; - // -------------- EXAMPLES ---------------- - //#ifdef INCLUDE_CALCULATOR - // calculator(&rawfb->ctx); - //#endif - // #ifdef INCLUDE_OVERVIEW - // overview(&rawfb->ctx); - // #endif - // #ifdef INCLUDE_NODE_EDITOR - // node_editor(&rawfb->ctx); - //#endif - // ----------------------------------------- + /* -------------- EXAMPLES ---------------- */ + #ifdef INCLUDE_CALCULATOR + calculator(&(nk_wayland_ctx.ctx)); + #endif + #ifdef INCLUDE_CANVAS + canvas(&(nk_wayland_ctx.ctx)); + #endif + #ifdef INCLUDE_OVERVIEW + overview(&(nk_wayland_ctx.ctx)); + #endif + #ifdef INCLUDE_NODE_EDITOR + node_editor(&(nk_wayland_ctx.ctx)); + #endif + /* ----------------------------------------- */ // Draw framebuffer nk_wayland_render(&nk_wayland_ctx, nk_rgb(30,30,30), 1); diff --git a/demo/x11/main.c b/demo/x11/main.c index 791653d..6ae35e5 100644 --- a/demo/x11/main.c +++ b/demo/x11/main.c @@ -79,12 +79,14 @@ sleep_for(long t) /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -95,6 +97,9 @@ sleep_for(long t) #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -193,6 +198,9 @@ main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/x11_opengl2/main.c b/demo/x11_opengl2/main.c index d906929..ec91a6f 100644 --- a/demo/x11_opengl2/main.c +++ b/demo/x11_opengl2/main.c @@ -40,12 +40,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -56,6 +58,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -309,6 +314,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/x11_opengl3/main.c b/demo/x11_opengl3/main.c index 5eab66f..8dafad3 100644 --- a/demo/x11_opengl3/main.c +++ b/demo/x11_opengl3/main.c @@ -38,12 +38,14 @@ /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -54,6 +56,9 @@ #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -306,6 +311,9 @@ int main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif diff --git a/demo/x11_rawfb/main.c b/demo/x11_rawfb/main.c index d722864..4ff4669 100644 --- a/demo/x11_rawfb/main.c +++ b/demo/x11_rawfb/main.c @@ -113,12 +113,14 @@ sleep_for(long t) /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -129,6 +131,9 @@ sleep_for(long t) #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -230,6 +235,9 @@ main(void) #ifdef INCLUDE_CALCULATOR calculator(&rawfb->ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(&rawfb->ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(&rawfb->ctx); #endif diff --git a/demo/x11_xft/main.c b/demo/x11_xft/main.c index 3a7917e..20957c1 100644 --- a/demo/x11_xft/main.c +++ b/demo/x11_xft/main.c @@ -79,12 +79,14 @@ sleep_for(long t) /*#define INCLUDE_ALL */ /*#define INCLUDE_STYLE */ /*#define INCLUDE_CALCULATOR */ +/*#define INCLUDE_CANVAS */ /*#define INCLUDE_OVERVIEW */ /*#define INCLUDE_NODE_EDITOR */ #ifdef INCLUDE_ALL #define INCLUDE_STYLE #define INCLUDE_CALCULATOR + #define INCLUDE_CANVAS #define INCLUDE_OVERVIEW #define INCLUDE_NODE_EDITOR #endif @@ -95,6 +97,9 @@ sleep_for(long t) #ifdef INCLUDE_CALCULATOR #include "../calculator.c" #endif +#ifdef INCLUDE_CANVAS + #include "../canvas.c" +#endif #ifdef INCLUDE_OVERVIEW #include "../overview.c" #endif @@ -197,6 +202,9 @@ main(void) #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif + #ifdef INCLUDE_CANVAS + canvas(ctx); + #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif