Fixed warnings and UB in demo code

This commit is contained in:
vurtun 2017-11-27 20:44:13 +01:00
parent 1d8aae2bba
commit 054136075c
5 changed files with 17 additions and 16 deletions

View File

@ -223,7 +223,7 @@ nk_glfw3_mouse_button_callback(GLFWwindow* window, int button, int action, int m
double dt = glfwGetTime() - glfw.last_button_click;
if (dt > NK_GLFW_DOUBLE_CLICK_LO && dt < NK_GLFW_DOUBLE_CLICK_HI) {
glfw.is_double_click_down = nk_true;
glfw.double_click_pos = nk_vec2(x, y);
glfw.double_click_pos = nk_vec2((float)x, (float)y);
}
glfw.last_button_click = glfwGetTime();
} else glfw.is_double_click_down = nk_false;
@ -352,7 +352,7 @@ nk_glfw3_new_frame(void)
glfwGetCursorPos(win, &x, &y);
nk_input_motion(ctx, (int)x, (int)y);
if (ctx->input.mouse.grabbed) {
glfwSetCursorPos(glfw.win, ctx->input.mouse.prev.x, ctx->input.mouse.prev.y);
glfwSetCursorPos(glfw.win, (double)ctx->input.mouse.prev.x, (double)ctx->input.mouse.prev.y);
ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
}
@ -360,7 +360,7 @@ nk_glfw3_new_frame(void)
nk_input_button(ctx, NK_BUTTON_LEFT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
nk_input_button(ctx, NK_BUTTON_MIDDLE, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS);
nk_input_button(ctx, NK_BUTTON_RIGHT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
nk_input_button(ctx, NK_BUTTON_DOUBLE, glfw.double_click_pos.x, glfw.double_click_pos.y, glfw.is_double_click_down);
nk_input_button(ctx, NK_BUTTON_DOUBLE, (int)glfw.double_click_pos.x, (int)glfw.double_click_pos.y, glfw.is_double_click_down);
nk_input_scroll(ctx, glfw.scroll);
nk_input_end(&glfw.ctx);
glfw.text_len = 0;

View File

@ -332,7 +332,7 @@ nk_glfw3_mouse_button_callback(GLFWwindow* window, int button, int action, int m
double dt = glfwGetTime() - glfw.last_button_click;
if (dt > NK_GLFW_DOUBLE_CLICK_LO && dt < NK_GLFW_DOUBLE_CLICK_HI) {
glfw.is_double_click_down = nk_true;
glfw.double_click_pos = nk_vec2(x, y);
glfw.double_click_pos = nk_vec2((float)x, (float)y);
}
glfw.last_button_click = glfwGetTime();
} else glfw.is_double_click_down = nk_false;
@ -418,7 +418,7 @@ nk_glfw3_new_frame(void)
for (i = 0; i < glfw.text_len; ++i)
nk_input_unicode(ctx, glfw.text[i]);
#if NK_GLFW_GL3_MOUSE_GRABBING
#ifdef NK_GLFW_GL3_MOUSE_GRABBING
/* optional grabbing behavior */
if (ctx->input.mouse.grab)
glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
@ -463,7 +463,7 @@ nk_glfw3_new_frame(void)
glfwGetCursorPos(win, &x, &y);
nk_input_motion(ctx, (int)x, (int)y);
#if NK_GLFW_GL3_MOUSE_GRABBING
#ifdef NK_GLFW_GL3_MOUSE_GRABBING
if (ctx->input.mouse.grabbed) {
glfwSetCursorPos(glfw.win, ctx->input.mouse.prev.x, ctx->input.mouse.prev.y);
ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
@ -473,7 +473,7 @@ nk_glfw3_new_frame(void)
nk_input_button(ctx, NK_BUTTON_LEFT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
nk_input_button(ctx, NK_BUTTON_MIDDLE, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS);
nk_input_button(ctx, NK_BUTTON_RIGHT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
nk_input_button(ctx, NK_BUTTON_DOUBLE, glfw.double_click_pos.x, glfw.double_click_pos.y, glfw.is_double_click_down);
nk_input_button(ctx, NK_BUTTON_DOUBLE, (int)glfw.double_click_pos.x, (int)glfw.double_click_pos.y, glfw.is_double_click_down);
nk_input_scroll(ctx, glfw.scroll);
nk_input_end(&glfw.ctx);
glfw.text_len = 0;

View File

@ -221,6 +221,7 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
const struct nk_draw_command *cmd;
void *vertices, *elements;
const nk_draw_index *offset = NULL;
struct nk_buffer vbuf, ebuf;
/* allocate vertex and element buffer */
glBindVertexArray(dev->vao);
@ -255,10 +256,9 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
config.line_AA = AA;
/* setup buffers to load vertices and elements */
{struct nk_buffer vbuf, ebuf;
nk_buffer_init_fixed(&vbuf, vertices, (nk_size)max_vertex_buffer);
nk_buffer_init_fixed(&ebuf, elements, (nk_size)max_element_buffer);
nk_convert(&sdl.ctx, &dev->cmds, &vbuf, &ebuf, &config);}
nk_convert(&sdl.ctx, &dev->cmds, &vbuf, &ebuf, &config);
}
glUnmapBuffer(GL_ARRAY_BUFFER);
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);

View File

@ -510,6 +510,7 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
const struct nk_draw_command *cmd;
void *vertices, *elements;
const nk_draw_index *offset = NULL;
struct nk_buffer vbuf, ebuf;
/* allocate vertex and element buffer */
glBindVertexArray(dev->vao);
@ -544,10 +545,9 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
config.line_AA = AA;
/* setup buffers to load vertices and elements */
{struct nk_buffer vbuf, ebuf;
nk_buffer_init_fixed(&vbuf, vertices, (size_t)max_vertex_buffer);
nk_buffer_init_fixed(&ebuf, elements, (size_t)max_element_buffer);
nk_convert(&x11.ctx, &dev->cmds, &vbuf, &ebuf, &config);}
nk_convert(&x11.ctx, &dev->cmds, &vbuf, &ebuf, &config);
}
glUnmapBuffer(GL_ARRAY_BUFFER);
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);

View File

@ -8616,22 +8616,23 @@ nk_draw_list_path_arc_to(struct nk_draw_list *list, struct nk_vec2 center,
[1] https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Angle_sum_and_difference_identities
*/
const float d_angle = (a_max - a_min) / (float)segments;
{const float d_angle = (a_max - a_min) / (float)segments;
const float sin_d = (float)NK_SIN(d_angle);
const float cos_d = (float)NK_COS(d_angle);
float cx = (float)NK_COS(a_min) * radius;
float cy = (float)NK_SIN(a_min) * radius;
for(i = 0; i <= segments; ++i) {
float new_cx, new_cy;
const float x = center.x + cx;
const float y = center.y + cy;
nk_draw_list_path_line_to(list, nk_vec2(x, y));
const float new_cx = cx * cos_d - cy * sin_d;
const float new_cy = cy * cos_d + cx * sin_d;
new_cx = cx * cos_d - cy * sin_d;
new_cy = cy * cos_d + cx * sin_d;
cx = new_cx;
cy = new_cy;
}
}}
}
NK_API void
@ -21342,7 +21343,7 @@ nk_edit_buffer(struct nk_context *ctx, nk_flags flags,
}
if (flags & NK_EDIT_CLIPBOARD)
edit->clip = ctx->clip;
edit->active = win->edit.active;
edit->active = (unsigned char)win->edit.active;
} else edit->active = nk_false;
edit->mode = win->edit.mode;