Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Build all demos as C89 #814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/allegro5/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BIN = demo

# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2

SRC = main.c
OBJ = $(SRC:.c=.o)
Expand Down
4 changes: 2 additions & 2 deletions demo/allegro5/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
43 changes: 28 additions & 15 deletions demo/allegro5/nuklear_allegro5.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -200,54 +205,61 @@ 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;
}
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;
}
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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion demo/glfw_opengl2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BIN = demo

# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2

SRC = main.c
OBJ = $(SRC:.c=.o)
Expand Down
2 changes: 1 addition & 1 deletion demo/glfw_opengl3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BIN = demo

# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2

SRC = main.c
OBJ = $(SRC:.c=.o)
Expand Down
2 changes: 1 addition & 1 deletion demo/glfw_opengl4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BIN = demo

# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2

SRC = main.c
OBJ = $(SRC:.c=.o)
Expand Down
2 changes: 1 addition & 1 deletion demo/glfw_opengl4/nuklear_glfw_gl4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions demo/overview.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion demo/sdl_opengl2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BIN = demo

# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2

SRC = main.c
OBJ = $(SRC:.c=.o)
Expand Down
2 changes: 1 addition & 1 deletion demo/sdl_opengl3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BIN = demo

# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2

SRC = main.c
OBJ = $(SRC:.c=.o)
Expand Down
2 changes: 1 addition & 1 deletion demo/sdl_opengles2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BIN = demo

# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2

SRC = main.c
OBJ = $(SRC:.c=.o)
Expand Down
24 changes: 13 additions & 11 deletions demo/sdl_opengles2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion demo/x11_opengl2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion demo/x11_opengl3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down