diff --git a/demo/allegro5/Makefile b/demo/allegro5/Makefile index 090a126a..48e0b7aa 100644 --- a/demo/allegro5/Makefile +++ b/demo/allegro5/Makefile @@ -2,7 +2,7 @@ BIN = demo # Flags -CFLAGS += -std=c99 -pedantic -O2 +CFLAGS += -std=c89 -pedantic -O2 SRC = main.c OBJ = $(SRC:.c=.o) diff --git a/demo/allegro5/main.c b/demo/allegro5/main.c index 624e7c98..0c822fcc 100644 --- a/demo/allegro5/main.c +++ b/demo/allegro5/main.c @@ -56,6 +56,8 @@ int main(void) /* Platform */ ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; + NkAllegro5Font *font; + struct nk_context *ctx; if (!al_init()) { fprintf(stdout, "failed to initialize allegro5!\n"); @@ -86,9 +88,7 @@ int main(void) al_register_event_source(event_queue, al_get_mouse_event_source()); al_register_event_source(event_queue, al_get_keyboard_event_source()); - NkAllegro5Font *font; font = nk_allegro5_font_create_from_file("../../../extra_font/Roboto-Regular.ttf", 12, 0); - struct nk_context *ctx; ctx = nk_allegro5_init(font, display, WINDOW_WIDTH, WINDOW_HEIGHT); diff --git a/demo/allegro5/nuklear_allegro5.h b/demo/allegro5/nuklear_allegro5.h index f3966005..2f155f43 100644 --- a/demo/allegro5/nuklear_allegro5.h +++ b/demo/allegro5/nuklear_allegro5.h @@ -68,6 +68,7 @@ static struct nk_allegro5 { NK_API NkAllegro5Font* nk_allegro5_font_create_from_file(const char *file_name, int font_size, int flags) { + NkAllegro5Font *font; if (!al_init_image_addon()) { fprintf(stdout, "Unable to initialize required allegro5 image addon\n"); exit(1); @@ -80,7 +81,7 @@ nk_allegro5_font_create_from_file(const char *file_name, int font_size, int flag fprintf(stdout, "Unable to initialize required allegro5 TTF font addon\n"); exit(1); } - NkAllegro5Font *font = (NkAllegro5Font*)calloc(1, sizeof(NkAllegro5Font)); + font = (NkAllegro5Font*)calloc(1, sizeof(NkAllegro5Font)); font->font = al_load_font(file_name, font_size, flags); if (font->font == NULL) { @@ -94,6 +95,8 @@ nk_allegro5_font_create_from_file(const char *file_name, int font_size, int flag static float nk_allegro5_font_get_text_width(nk_handle handle, float height, const char *text, int len) { + float width; + char *strcpy; NkAllegro5Font *font = (NkAllegro5Font*)handle.ptr; if (!font || !text) { return 0; @@ -102,10 +105,12 @@ nk_allegro5_font_get_text_width(nk_handle handle, float height, const char *text as nuklear uses variable size buffers and al_get_text_width doesn't accept a length, it infers length from null-termination (which is unsafe API design by allegro devs!) */ - char strcpy[len+1]; - strncpy((char*)&strcpy, text, len); + strcpy = malloc(len + 1); + strncpy(strcpy, text, len); strcpy[len] = '\0'; - return al_get_text_width(font->font, strcpy); + width = al_get_text_width(font->font, strcpy); + free(strcpy); + return width; } NK_API void @@ -170,18 +175,18 @@ nk_allegro5_render() (float)r->rounding, color); } break; case NK_COMMAND_CIRCLE: { + float xr, yr; const struct nk_command_circle *c = (const struct nk_command_circle *)cmd; color = nk_color_to_allegro_color(c->color); - float xr, yr; xr = (float)c->w/2; yr = (float)c->h/2; al_draw_ellipse(((float)(c->x)) + xr, ((float)c->y) + yr, xr, yr, color, (float)c->line_thickness); } break; case NK_COMMAND_CIRCLE_FILLED: { + float xr, yr; const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd; color = nk_color_to_allegro_color(c->color); - float xr, yr; xr = (float)c->w/2; yr = (float)c->h/2; al_draw_filled_ellipse(((float)(c->x)) + xr, ((float)c->y) + yr, @@ -200,10 +205,11 @@ nk_allegro5_render() (float)t->b.y, (float)t->c.x, (float)t->c.y, color); } break; case NK_COMMAND_POLYGON: { + int i; + float *vertices; const struct nk_command_polygon *p = (const struct nk_command_polygon*)cmd; + vertices = calloc(p->point_count * 2, sizeof(float)); color = nk_color_to_allegro_color(p->color); - int i; - float vertices[p->point_count * 2]; for (i = 0; i < p->point_count; i++) { vertices[i*2] = p->points[i].x; vertices[(i*2) + 1] = p->points[i].y; @@ -211,23 +217,27 @@ nk_allegro5_render() al_draw_polyline((const float*)&vertices, (2 * sizeof(float)), (int)p->point_count, ALLEGRO_LINE_JOIN_ROUND, ALLEGRO_LINE_CAP_CLOSED, color, (float)p->line_thickness, 0.0); + free(vertices); } break; case NK_COMMAND_POLYGON_FILLED: { + int i; + float *vertices; const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled *)cmd; + vertices = calloc(p->point_count * 2, sizeof(float)); color = nk_color_to_allegro_color(p->color); - int i; - float vertices[p->point_count * 2]; for (i = 0; i < p->point_count; i++) { vertices[i*2] = p->points[i].x; vertices[(i*2) + 1] = p->points[i].y; } al_draw_filled_polygon((const float*)&vertices, (int)p->point_count, color); + free(vertices); } break; case NK_COMMAND_POLYLINE: { + int i; + float *vertices; const struct nk_command_polyline *p = (const struct nk_command_polyline *)cmd; + vertices = calloc(p->point_count * 2, sizeof(float)); color = nk_color_to_allegro_color(p->color); - int i; - float vertices[p->point_count * 2]; for (i = 0; i < p->point_count; i++) { vertices[i*2] = p->points[i].x; vertices[(i*2) + 1] = p->points[i].y; @@ -235,19 +245,21 @@ nk_allegro5_render() al_draw_polyline((const float*)&vertices, (2 * sizeof(float)), (int)p->point_count, ALLEGRO_LINE_JOIN_ROUND, ALLEGRO_LINE_CAP_ROUND, color, (float)p->line_thickness, 0.0); + free(vertices); } break; case NK_COMMAND_TEXT: { + NkAllegro5Font *font; const struct nk_command_text *t = (const struct nk_command_text*)cmd; color = nk_color_to_allegro_color(t->foreground); - NkAllegro5Font *font = (NkAllegro5Font*)t->font->userdata.ptr; + font = (NkAllegro5Font*)t->font->userdata.ptr; al_draw_text(font->font, color, (float)t->x, (float)t->y, 0, (const char*)t->string); } break; case NK_COMMAND_CURVE: { + float points[8]; const struct nk_command_curve *q = (const struct nk_command_curve *)cmd; color = nk_color_to_allegro_color(q->color); - float points[8]; points[0] = (float)q->begin.x; points[1] = (float)q->begin.y; points[2] = (float)q->ctrl[0].x; @@ -425,12 +437,13 @@ NK_API struct nk_context* nk_allegro5_init(NkAllegro5Font *allegro5font, ALLEGRO_DISPLAY *dsp, unsigned int width, unsigned int height) { + struct nk_user_font *font; if (!al_init_primitives_addon()) { fprintf(stdout, "Unable to initialize required allegro5 primitives addon\n"); exit(1); } - struct nk_user_font *font = &allegro5font->nk; + font = &allegro5font->nk; font->userdata = nk_handle_ptr(allegro5font); font->height = (float)allegro5font->height; font->width = nk_allegro5_font_get_text_width; diff --git a/demo/glfw_opengl2/Makefile b/demo/glfw_opengl2/Makefile index c08d65f9..ec8bcf39 100644 --- a/demo/glfw_opengl2/Makefile +++ b/demo/glfw_opengl2/Makefile @@ -2,7 +2,7 @@ BIN = demo # Flags -CFLAGS += -std=c99 -pedantic -O2 +CFLAGS += -std=c89 -pedantic -O2 SRC = main.c OBJ = $(SRC:.c=.o) diff --git a/demo/glfw_opengl3/Makefile b/demo/glfw_opengl3/Makefile index da952617..57e09361 100644 --- a/demo/glfw_opengl3/Makefile +++ b/demo/glfw_opengl3/Makefile @@ -2,7 +2,7 @@ BIN = demo # Flags -CFLAGS += -std=c99 -pedantic -O2 +CFLAGS += -std=c89 -pedantic -O2 SRC = main.c OBJ = $(SRC:.c=.o) diff --git a/demo/glfw_opengl4/Makefile b/demo/glfw_opengl4/Makefile index da952617..57e09361 100644 --- a/demo/glfw_opengl4/Makefile +++ b/demo/glfw_opengl4/Makefile @@ -2,7 +2,7 @@ BIN = demo # Flags -CFLAGS += -std=c99 -pedantic -O2 +CFLAGS += -std=c89 -pedantic -O2 SRC = main.c OBJ = $(SRC:.c=.o) diff --git a/demo/glfw_opengl4/nuklear_glfw_gl4.h b/demo/glfw_opengl4/nuklear_glfw_gl4.h index 34b61ac4..67174630 100644 --- a/demo/glfw_opengl4/nuklear_glfw_gl4.h +++ b/demo/glfw_opengl4/nuklear_glfw_gl4.h @@ -116,6 +116,7 @@ NK_API void nk_glfw3_device_create() { GLint status; + GLint len = 0; static const GLchar *vertex_shader = NK_SHADER_VERSION NK_SHADER_BINDLESS @@ -156,7 +157,6 @@ nk_glfw3_device_create() glCompileShader(dev->frag_shdr); glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status); - GLint len = 0; glGetShaderiv(dev->vert_shdr, GL_INFO_LOG_LENGTH, &len); if (len > 1) { char *log = calloc((size_t)len, sizeof(char)); diff --git a/demo/overview.c b/demo/overview.c index d83f682d..d9b6ec4c 100644 --- a/demo/overview.c +++ b/demo/overview.c @@ -199,7 +199,7 @@ overview(struct nk_context *ctx) /* Basic widgets */ static int int_slider = 5; static float float_slider = 2.5f; - static size_t prog_value = 40; + static nk_size prog_value = 40; static float property_float = 2; static int property_int = 10; static int property_neg = 10; @@ -226,7 +226,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: %zu" , prog_value); + nk_labelf(ctx, NK_TEXT_LEFT, "Progressbar: %u" , (int)prog_value); nk_progress(ctx, &prog_value, 100, NK_MODIFIABLE); nk_layout_row(ctx, NK_STATIC, 25, 2, ratio); diff --git a/demo/sdl_opengl2/Makefile b/demo/sdl_opengl2/Makefile index b73174ab..967e3f6a 100644 --- a/demo/sdl_opengl2/Makefile +++ b/demo/sdl_opengl2/Makefile @@ -2,7 +2,7 @@ BIN = demo # Flags -CFLAGS += -std=c99 -pedantic -O2 +CFLAGS += -std=c89 -pedantic -O2 SRC = main.c OBJ = $(SRC:.c=.o) diff --git a/demo/sdl_opengl3/Makefile b/demo/sdl_opengl3/Makefile index c6fcb451..1c919955 100644 --- a/demo/sdl_opengl3/Makefile +++ b/demo/sdl_opengl3/Makefile @@ -2,7 +2,7 @@ BIN = demo # Flags -CFLAGS += -std=c99 -pedantic -O2 +CFLAGS += -std=c89 -pedantic -O2 SRC = main.c OBJ = $(SRC:.c=.o) diff --git a/demo/sdl_opengles2/Makefile b/demo/sdl_opengles2/Makefile index e1820d73..9c85d89a 100644 --- a/demo/sdl_opengles2/Makefile +++ b/demo/sdl_opengles2/Makefile @@ -2,7 +2,7 @@ BIN = demo # Flags -CFLAGS += -std=c99 -pedantic -O2 +CFLAGS += -std=c89 -pedantic -O2 SRC = main.c OBJ = $(SRC:.c=.o) diff --git a/demo/sdl_opengles2/main.c b/demo/sdl_opengles2/main.c index 16a271ad..99047b1f 100644 --- a/demo/sdl_opengles2/main.c +++ b/demo/sdl_opengles2/main.c @@ -96,17 +96,19 @@ MainLoop(void* loopArg){ nk_layout_row_end(ctx); nk_menubar_end(ctx); - enum {EASY, HARD}; - static int op = EASY; - static int property = 20; - nk_layout_row_static(ctx, 30, 80, 1); - if (nk_button_label(ctx, "button")) - fprintf(stdout, "button pressed\n"); - nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; - nk_layout_row_dynamic(ctx, 25, 1); - nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); + { + enum {EASY, HARD}; + static int op = EASY; + static int property = 20; + nk_layout_row_static(ctx, 30, 80, 1); + if (nk_button_label(ctx, "button")) + fprintf(stdout, "button pressed\n"); + nk_layout_row_dynamic(ctx, 30, 2); + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + nk_layout_row_dynamic(ctx, 25, 1); + nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); + } } nk_end(ctx); diff --git a/demo/x11_opengl2/Makefile b/demo/x11_opengl2/Makefile index a3d6d323..824bc977 100644 --- a/demo/x11_opengl2/Makefile +++ b/demo/x11_opengl2/Makefile @@ -6,7 +6,7 @@ CC = clang DCC = gcc # Flags -CFLAGS += -std=c99 -pedantic -O2 +CFLAGS += -std=c89 -pedantic -O2 SRC = main.c OBJ = $(SRC:.c=.o) diff --git a/demo/x11_opengl3/Makefile b/demo/x11_opengl3/Makefile index a3d6d323..824bc977 100644 --- a/demo/x11_opengl3/Makefile +++ b/demo/x11_opengl3/Makefile @@ -6,7 +6,7 @@ CC = clang DCC = gcc # Flags -CFLAGS += -std=c99 -pedantic -O2 +CFLAGS += -std=c89 -pedantic -O2 SRC = main.c OBJ = $(SRC:.c=.o)