Build all demos as C89

This commit is contained in:
Cameron Cawley 2019-02-27 14:02:44 +00:00
parent 230231355d
commit 9af0103cac
26 changed files with 190 additions and 118 deletions

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -55,6 +55,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");
@ -85,9 +87,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);
@ -99,11 +99,12 @@ int main(void)
while(1)
{
bool get_event;
ALLEGRO_EVENT ev;
ALLEGRO_TIMEOUT timeout;
al_init_timeout(&timeout, 0.06);
bool get_event = al_wait_for_event_until(event_queue, &ev, &timeout);
get_event = al_wait_for_event_until(event_queue, &ev, &timeout);
if (get_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
break;

View File

@ -70,18 +70,20 @@ static struct nk_allegro5 {
NK_API struct nk_image* nk_allegro5_create_image(const char* file_name)
{
ALLEGRO_BITMAP *bitmap;
struct nk_image *image;
if (!al_init_image_addon()) {
fprintf(stdout, "Unable to initialize required allegro5 image addon\n");
exit(1);
}
ALLEGRO_BITMAP* bitmap = al_load_bitmap(file_name);
bitmap = al_load_bitmap(file_name);
if (bitmap == NULL) {
fprintf(stdout, "Unable to load image file: %s\n", file_name);
return NULL;
}
struct nk_image *image = (struct nk_image*)calloc(1, sizeof(struct nk_image));
image = (struct nk_image*)calloc(1, sizeof(struct nk_image));
image->handle.ptr = bitmap;
image->w = al_get_bitmap_width(bitmap);
image->h = al_get_bitmap_height(bitmap);
@ -98,8 +100,10 @@ NK_API void nk_allegro5_del_image(struct nk_image* image)
static float
nk_allegro5_font_get_text_width(nk_handle handle, float height, const char *text, int len)
{
NK_UNUSED(height);
float width;
char *strcpy;
NkAllegro5Font *font = (NkAllegro5Font*)handle.ptr;
NK_UNUSED(height);
if (!font || !text) {
return 0;
}
@ -107,16 +111,19 @@ 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;
}
/* Flags are identical to al_load_font() flags argument */
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);
@ -129,7 +136,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) {
@ -201,18 +208,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,
@ -231,10 +238,11 @@ nk_allegro5_render()
(float)t->b.y, (float)t->c.x, (float)t->c.y, color);
} break;
case NK_COMMAND_POLYGON: {
const struct nk_command_polygon *p = (const struct nk_command_polygon*)cmd;
color = nk_color_to_allegro_color(p->color);
int i;
float vertices[p->point_count * 2];
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);
for (i = 0; i < p->point_count; i++) {
vertices[i*2] = p->points[i].x;
vertices[(i*2) + 1] = p->points[i].y;
@ -242,23 +250,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: {
const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled *)cmd;
color = nk_color_to_allegro_color(p->color);
int i;
float vertices[p->point_count * 2];
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);
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: {
const struct nk_command_polyline *p = (const struct nk_command_polyline *)cmd;
color = nk_color_to_allegro_color(p->color);
int i;
float vertices[p->point_count * 2];
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);
for (i = 0; i < p->point_count; i++) {
vertices[i*2] = p->points[i].x;
vertices[(i*2) + 1] = p->points[i].y;
@ -266,19 +278,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;
@ -466,12 +480,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;
allegro5.dsp = dsp;
allegro5.width = width;

View File

@ -179,11 +179,15 @@ nk_d3d11_get_projection_matrix(int width, int height, float *result)
const float B = (float)height;
float matrix[4][4] =
{
{ 2.0f / (R - L), 0.0f, 0.0f, 0.0f },
{ 0.0f, 2.0f / (T - B), 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.5f, 0.0f },
{ (R + L) / (L - R), (T + B) / (B - T), 0.5f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.5f, 0.0f },
{ 0.0f, 0.0f, 0.5f, 1.0f },
};
matrix[0][0] = 2.0f / (R - L);
matrix[1][1] = 2.0f / (T - B);
matrix[3][0] = (R + L) / (L - R);
matrix[3][1] = (T + B) / (B - T);
memcpy(result, matrix, sizeof(matrix));
}

View File

@ -82,10 +82,11 @@ WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
if (width != 0 && height != 0 &&
(width != present.BackBufferWidth || height != present.BackBufferHeight))
{
HRESULT hr;
nk_d3d9_release();
present.BackBufferWidth = width;
present.BackBufferHeight = height;
HRESULT hr = IDirect3DDevice9_Reset(device, &present);
hr = IDirect3DDevice9_Reset(device, &present);
NK_ASSERT(SUCCEEDED(hr));
nk_d3d9_resize(width, height);
}

View File

@ -204,11 +204,15 @@ nk_d3d9_get_projection_matrix(int width, int height, float *result)
const float T = 0.5f;
const float B = (float)height + 0.5f;
float matrix[4][4] = {
{ 2.0f / (R - L), 0.0f, 0.0f, 0.0f },
{ 0.0f, 2.0f / (T - B), 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ (R + L) / (L - R), (T + B) / (B - T), 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f },
};
matrix[0][0] = 2.0f / (R - L);
matrix[1][1] = 2.0f / (T - B);
matrix[3][0] = (R + L) / (L - R);
matrix[3][1] = (T + B) / (B - T);
memcpy(result, matrix, sizeof(matrix));
}
@ -426,30 +430,35 @@ nk_d3d9_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
static void
nk_d3d9_clipboard_paste(nk_handle usr, struct nk_text_edit *edit)
{
HGLOBAL mem;
SIZE_T size;
LPCWSTR wstr;
int utf8size;
(void)usr;
if (!IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL)) {
return;
}
HGLOBAL mem = GetClipboardData(CF_UNICODETEXT);
mem = GetClipboardData(CF_UNICODETEXT);
if (!mem) {
CloseClipboard();
return;
}
SIZE_T size = GlobalSize(mem) - 1;
size = GlobalSize(mem) - 1;
if (!size) {
CloseClipboard();
return;
}
LPCWSTR wstr = (LPCWSTR)GlobalLock(mem);
wstr = (LPCWSTR)GlobalLock(mem);
if (!wstr) {
CloseClipboard();
return;
}
int utf8size = WideCharToMultiByte(CP_UTF8, 0, wstr, (int)size / sizeof(wchar_t), NULL, 0, NULL, NULL);
utf8size = WideCharToMultiByte(CP_UTF8, 0, wstr, (int)size / sizeof(wchar_t), NULL, 0, NULL, NULL);
if (utf8size) {
char *utf8 = (char *)malloc(utf8size);
if (utf8) {
@ -466,12 +475,14 @@ nk_d3d9_clipboard_paste(nk_handle usr, struct nk_text_edit *edit)
static void
nk_d3d9_clipboard_copy(nk_handle usr, const char *text, int len)
{
int wsize;
(void)usr;
if (!OpenClipboard(NULL)) {
return;
}
int wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0);
wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0);
if (wsize) {
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (wsize + 1) * sizeof(wchar_t));
if (mem) {

View File

@ -62,6 +62,13 @@ nk_create_image(struct nk_image * image, const char * frame_buffer, const int wi
{
if (image && frame_buffer && (width > 0) && (height > 0))
{
const unsigned char * src = (const unsigned char *)frame_buffer;
INT row = ((width * 3 + 3) & ~3);
LPBYTE lpBuf, pb = NULL;
BITMAPINFO bi = { 0 };
HBITMAP hbm;
int v, i;
image->w = width;
image->h = height;
image->region[0] = 0;
@ -69,8 +76,6 @@ nk_create_image(struct nk_image * image, const char * frame_buffer, const int wi
image->region[2] = width;
image->region[3] = height;
INT row = ((width * 3 + 3) & ~3);
BITMAPINFO bi = { 0 };
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = width;
bi.bmiHeader.biHeight = height;
@ -79,15 +84,13 @@ nk_create_image(struct nk_image * image, const char * frame_buffer, const int wi
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = row * height;
LPBYTE lpBuf, pb = NULL;
HBITMAP hbm = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**)&lpBuf, NULL, 0);
hbm = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**)&lpBuf, NULL, 0);
pb = lpBuf + row * height;
unsigned char * src = (unsigned char *)frame_buffer;
for (int v = 0; v<height; v++)
for (v = 0; v < height; v++)
{
pb -= row;
for (int i = 0; i < row; i += 3)
for (i = 0; i < row; i += 3)
{
pb[i + 0] = src[0];
pb[i + 1] = src[1];
@ -170,8 +173,9 @@ nk_gdi_stroke_rect(HDC dc, short x, short y, unsigned short w,
unsigned short h, unsigned short r, unsigned short line_thickness, struct nk_color col)
{
COLORREF color = convert_color(col);
HGDIOBJ br;
HPEN pen = NULL;
if (line_thickness == 1) {
SetDCPenColor(dc, color);
} else {
@ -179,7 +183,7 @@ nk_gdi_stroke_rect(HDC dc, short x, short y, unsigned short w,
SelectObject(dc, pen);
}
HGDIOBJ br = SelectObject(dc, GetStockObject(NULL_BRUSH));
br = SelectObject(dc, GetStockObject(NULL_BRUSH));
if (r == 0) {
Rectangle(dc, x, y, x + w, y + h);
} else {
@ -200,7 +204,8 @@ nk_gdi_fill_rect(HDC dc, short x, short y, unsigned short w,
COLORREF color = convert_color(col);
if (r == 0) {
RECT rect = { x, y, x + w, y + h };
RECT rect;
SetRect(&rect, x, y, x + w, y + h);
SetBkColor(dc, color);
ExtTextOutW(dc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
} else {
@ -262,16 +267,26 @@ nk_gdi_rect_multi_color(HDC dc, short x, short y, unsigned short w,
}
static BOOL
SetPoint(POINT *p, LONG x, LONG y)
{
if (!p)
return FALSE;
p->x = x;
p->y = y;
return TRUE;
}
static void
nk_gdi_fill_triangle(HDC dc, short x0, short y0, short x1,
short y1, short x2, short y2, struct nk_color col)
{
COLORREF color = convert_color(col);
POINT points[] = {
{ x0, y0 },
{ x1, y1 },
{ x2, y2 },
};
POINT points[3];
SetPoint(&points[0], x0, y0);
SetPoint(&points[1], x1, y1);
SetPoint(&points[2], x2, y2);
SetDCPenColor(dc, color);
SetDCBrushColor(dc, color);
@ -283,14 +298,14 @@ nk_gdi_stroke_triangle(HDC dc, short x0, short y0, short x1,
short y1, short x2, short y2, unsigned short line_thickness, struct nk_color col)
{
COLORREF color = convert_color(col);
POINT points[] = {
{ x0, y0 },
{ x1, y1 },
{ x2, y2 },
{ x0, y0 },
};
POINT points[4];
HPEN pen = NULL;
SetPoint(&points[0], x0, y0);
SetPoint(&points[1], x1, y1);
SetPoint(&points[2], x2, y2);
SetPoint(&points[3], x0, y0);
if (line_thickness == 1) {
SetDCPenColor(dc, color);
} else {
@ -414,14 +429,14 @@ nk_gdi_stroke_curve(HDC dc, struct nk_vec2i p1,
unsigned short line_thickness, struct nk_color col)
{
COLORREF color = convert_color(col);
POINT p[] = {
{ p1.x, p1.y },
{ p2.x, p2.y },
{ p3.x, p3.y },
{ p4.x, p4.y },
};
POINT p[4];
HPEN pen = NULL;
SetPoint(&p[0], p1.x, p1.y);
SetPoint(&p[1], p2.x, p2.y);
SetPoint(&p[2], p3.x, p3.y);
SetPoint(&p[3], p4.x, p4.y);
if (line_thickness == 1) {
SetDCPenColor(dc, color);
} else {
@ -462,7 +477,8 @@ static void
nk_gdi_clear(HDC dc, struct nk_color col)
{
COLORREF color = convert_color(col);
RECT rect = { 0, 0, gdi.width, gdi.height };
RECT rect;
SetRect(&rect, 0, 0, gdi.width, gdi.height);
SetBkColor(dc, color);
ExtTextOutW(dc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);

View File

@ -471,15 +471,25 @@ nk_gdip_fill_rect(short x, short y, unsigned short w,
}
}
static BOOL
SetPoint(POINT *p, LONG x, LONG y)
{
if (!p)
return FALSE;
p->x = x;
p->y = y;
return TRUE;
}
static void
nk_gdip_fill_triangle(short x0, short y0, short x1,
short y1, short x2, short y2, struct nk_color col)
{
POINT points[] = {
{ x0, y0 },
{ x1, y1 },
{ x2, y2 },
};
POINT points[3];
SetPoint(&points[0], x0, y0);
SetPoint(&points[1], x1, y1);
SetPoint(&points[2], x2, y2);
GdipSetSolidFillColor(gdip.brush, convert_color(col));
GdipFillPolygonI(gdip.memory, gdip.brush, points, 3, FillModeAlternate);
@ -489,12 +499,13 @@ static void
nk_gdip_stroke_triangle(short x0, short y0, short x1,
short y1, short x2, short y2, unsigned short line_thickness, struct nk_color col)
{
POINT points[] = {
{ x0, y0 },
{ x1, y1 },
{ x2, y2 },
{ x0, y0 },
};
POINT points[4];
SetPoint(&points[0], x0, y0);
SetPoint(&points[1], x1, y1);
SetPoint(&points[2], x2, y2);
SetPoint(&points[3], x0, y0);
GdipSetPenWidth(gdip.pen, (REAL)line_thickness);
GdipSetPenColor(gdip.pen, convert_color(col));
GdipDrawPolygonI(gdip.memory, gdip.pen, points, 4);
@ -575,7 +586,12 @@ nk_gdip_draw_text(short x, short y, unsigned short w, unsigned short h,
{
int wsize;
WCHAR* wstr;
RectF layout = { (FLOAT)x, (FLOAT)y, (FLOAT)w, (FLOAT)h };
RectF layout;
layout.X = x;
layout.Y = y;
layout.Width = w;
layout.Height = h;
if(!text || !font || !len) return;

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -328,9 +328,9 @@ nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff)
NK_API void
nk_glfw3_mouse_button_callback(GLFWwindow* win, int button, int action, int mods)
{
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
double x, y;
if (button != GLFW_MOUSE_BUTTON_LEFT) return;
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
glfwGetCursorPos(win, &x, &y);
if (action == GLFW_PRESS) {
double dt = glfwGetTime() - glfw->last_button_click;
@ -354,13 +354,13 @@ nk_glfw3_clipboard_paste(nk_handle usr, struct nk_text_edit *edit)
NK_INTERN void
nk_glfw3_clipboard_copy(nk_handle usr, const char *text, int len)
{
struct nk_glfw* glfw = usr.ptr;
char *str = 0;
if (!len) return;
str = (char*)malloc((size_t)len+1);
if (!str) return;
memcpy(str, text, (size_t)len);
str[len] = '\0';
struct nk_glfw* glfw = usr.ptr;
glfwSetClipboardString(glfw->win, str);
free(str);
}

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -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 = (char*)calloc((size_t)len, sizeof(char));

View File

@ -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);

View File

@ -1,4 +1,4 @@
CFLAGS=`sdl2-config --cflags --libs` -std=c11 -Wall -O0 -g -fvisibility=hidden -Wno-unused `pkg-config SDL2_ttf --cflags --libs`
CFLAGS=`sdl2-config --cflags --libs` -std=c89 -Wall -O0 -g -fvisibility=hidden -Wno-unused `pkg-config SDL2_ttf --cflags --libs`
.PHONY: clean

View File

@ -36,7 +36,7 @@ static int sdl_button_to_nk(int button)
switch(button)
{
default:
//ft
/* ft */
case SDL_BUTTON_LEFT:
return NK_BUTTON_LEFT;
break;
@ -177,7 +177,7 @@ int main(int argc, char **argv)
}
nk_end(&(context->ctx));
// grid_demo(&(context->ctx));
/* grid_demo(&(context->ctx)); */
nk_sdlsurface_render(context, clear, 1);

View File

@ -845,7 +845,8 @@ nk_sdlsurface_init(SDL_Surface *fb, float fontSize)
{
SDL_assert(sdlsurface->font_tex->pitch == sdlsurface->font_tex->w * 4);
uint32_t *fontPixels = (uint32_t *)sdlsurface->font_tex->pixels;
for (int i = 0; i < sdlsurface->font_tex->w * sdlsurface->font_tex->h; i++)
int i;
for (i = 0; i < sdlsurface->font_tex->w * sdlsurface->font_tex->h; i++)
{
uint32_t col = fontPixels[i];
fontPixels[i] &= 0xFFFF00;
@ -961,8 +962,8 @@ nk_sdlsurface_draw_text(const struct sdlsurface_context *sdlsurface,
dst_rect.x = x + g.offset.x + rect.x;
dst_rect.y = g.offset.y + rect.y;
dst_rect.w = ceilf(g.width);
dst_rect.h = ceilf(g.height);
dst_rect.w = ceil(g.width);
dst_rect.h = ceil(g.height);
/* Use software rescaling to blit glyph from font_text to framebuffer */
nk_sdlsurface_stretch_image(sdlsurface->fb, sdlsurface->font_tex, &dst_rect, &src_rect, &sdlsurface->scissors, &fg);

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c99 -pedantic -O2
CFLAGS += -std=c89 -pedantic -O2
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -95,17 +95,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);

View File

@ -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)

View File

@ -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)

View File

@ -35,7 +35,7 @@ struct rawfb_context;
typedef enum rawfb_pixel_layout {
PIXEL_LAYOUT_XRGB_8888,
PIXEL_LAYOUT_RGBX_8888,
PIXEL_LAYOUT_RGBX_8888
}
rawfb_pl;

View File

@ -254,10 +254,10 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt, struct r
} else if (evt->type == Expose || evt->type == ConfigureNotify) {
/* Window resize handler */
void *fb;
rawfb_pl pl;
unsigned int width, height;
XWindowAttributes attr;
XGetWindowAttributes(dpy, win, &attr);
rawfb_pl pl;
width = (unsigned int)attr.width;
height = (unsigned int)attr.height;

View File

@ -420,6 +420,10 @@ NK_INTERN void
nk_xsurf_draw_text(XSurface *surf, short x, short y, unsigned short w, unsigned short h,
const char *text, int len, XFont *font, struct nk_color cbg, struct nk_color cfg)
{
#ifdef NK_XLIB_USE_XFT
XRenderColor xrc;
XftColor color;
#endif
int tx, ty;
unsigned long bg = nk_color_from_byte(&cbg.r);
unsigned long fg = nk_color_from_byte(&cfg.r);
@ -431,8 +435,6 @@ nk_xsurf_draw_text(XSurface *surf, short x, short y, unsigned short w, unsigned
tx = (int)x;
ty = (int)y + font->ascent;
#ifdef NK_XLIB_USE_XFT
XRenderColor xrc;
XftColor color;
xrc.red = cfg.r * 257;
xrc.green = cfg.g * 257;
xrc.blue = cfg.b * 257;
@ -640,17 +642,20 @@ nk_xfont_get_text_width(nk_handle handle, float height, const char *text, int le
{
XFont *font = (XFont*)handle.ptr;
if(!font || !text)
return 0;
#ifdef NK_XLIB_USE_XFT
XGlyphInfo g;
if(!font || !text)
return 0;
XftTextExtentsUtf8(xlib.dpy, font->ft, (FcChar8*)text, len, &g);
return g.xOff;
#else
XRectangle r;
if(!font || !text)
return 0;
if(font->set) {
XmbTextExtents(font->set, (const char*)text, len, NULL, &r);
return (float)r.width;