13 #ifndef NK_GLFW_GL2_H_ 14 #define NK_GLFW_GL2_H_ 42 #ifdef NK_GLFW_GL2_IMPLEMENTATION 44 #ifndef NK_GLFW_TEXT_MAX 45 #define NK_GLFW_TEXT_MAX 256 47 #ifndef NK_GLFW_DOUBLE_CLICK_LO 48 #define NK_GLFW_DOUBLE_CLICK_LO 0.02 50 #ifndef NK_GLFW_DOUBLE_CLICK_HI 51 #define NK_GLFW_DOUBLE_CLICK_HI 0.2 54 struct nk_glfw_device {
60 struct nk_glfw_vertex {
66 static struct nk_glfw {
69 int display_width, display_height;
70 struct nk_glfw_device ogl;
72 struct nk_font_atlas atlas;
74 unsigned int text[NK_GLFW_TEXT_MAX];
77 double last_button_click;
78 int is_double_click_down;
79 struct nk_vec2 double_click_pos;
85 struct nk_glfw_device *
dev = &glfw.ogl;
98 struct nk_glfw_device *dev = &glfw.ogl;
112 glOrtho(0.0
f, glfw.width, glfw.height, 0.0f, -1.0f, 1.0f);
121 GLsizei vs =
sizeof(
struct nk_glfw_vertex);
122 size_t vp =
offsetof(
struct nk_glfw_vertex, position);
123 size_t vt =
offsetof(
struct nk_glfw_vertex, uv);
127 const struct nk_draw_command *
cmd;
133 static const struct nk_draw_vertex_layout_element vertex_layout[] = {
134 {NK_VERTEX_POSITION, NK_FORMAT_FLOAT,
NK_OFFSETOF(
struct nk_glfw_vertex, position)},
135 {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT,
NK_OFFSETOF(
struct nk_glfw_vertex, uv)},
136 {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8,
NK_OFFSETOF(
struct nk_glfw_vertex,
col)},
137 {NK_VERTEX_LAYOUT_END}
140 config.vertex_layout = vertex_layout;
141 config.vertex_size =
sizeof(
struct nk_glfw_vertex);
144 config.circle_segment_count = 22;
145 config.curve_segment_count = 22;
146 config.arc_segment_count = 22;
147 config.global_alpha = 1.0f;
152 nk_buffer_init_default(&vbuf);
153 nk_buffer_init_default(&ebuf);
154 nk_convert(&glfw.ctx, &dev->cmds, &vbuf, &ebuf, &
config);
164 nk_draw_foreach(cmd, &glfw.ctx, &dev->cmds)
166 if (!cmd->elem_count)
continue;
169 (
GLint)(cmd->clip_rect.x * glfw.fb_scale.x),
170 (
GLint)((glfw.height - (
GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * glfw.fb_scale.y),
171 (
GLint)(cmd->clip_rect.w * glfw.fb_scale.x),
172 (
GLint)(cmd->clip_rect.h * glfw.fb_scale.y));
174 offset += cmd->elem_count;
204 if (glfw.text_len < NK_GLFW_TEXT_MAX)
205 glfw.text[glfw.text_len++] = codepoint;
212 glfw.scroll.x += (float)xoff;
213 glfw.scroll.y += (float)yoff;
224 if (dt > NK_GLFW_DOUBLE_CLICK_LO && dt < NK_GLFW_DOUBLE_CLICK_HI) {
225 glfw.is_double_click_down =
nk_true;
226 glfw.double_click_pos =
nk_vec2((
float)x, (
float)y);
229 }
else glfw.is_double_click_down =
nk_false;
241 nk_glfw3_clipbard_copy(
nk_handle usr,
const char *text,
int len)
246 str = (
char*)malloc((
size_t)len+1);
248 NK_MEMCPY(str, text, (
size_t)len);
263 nk_init_default(&glfw.ctx, 0);
264 glfw.ctx.clip.copy = nk_glfw3_clipbard_copy;
265 glfw.ctx.clip.paste = nk_glfw3_clipbard_paste;
267 nk_buffer_init_default(&glfw.ogl.cmds);
269 glfw.is_double_click_down =
nk_false;
270 glfw.double_click_pos =
nk_vec2(0, 0);
278 nk_font_atlas_init_default(&glfw.atlas);
279 nk_font_atlas_begin(&glfw.atlas);
280 *atlas = &glfw.atlas;
287 image = nk_font_atlas_bake(&glfw.atlas, &w, &h, NK_FONT_ATLAS_RGBA32);
288 nk_glfw3_device_upload_atlas(image, w, h);
289 nk_font_atlas_end(&glfw.atlas,
nk_handle_id((
int)glfw.ogl.font_tex), &glfw.ogl.null);
290 if (glfw.atlas.default_font)
304 glfw.fb_scale.x = (float)glfw.display_width/(
float)glfw.width;
305 glfw.fb_scale.y = (float)glfw.display_height/(
float)glfw.height;
308 for (i = 0; i < glfw.text_len; ++
i)
373 struct nk_glfw_device *dev = &glfw.ogl;
374 nk_font_atlas_clear(&glfw.atlas);
378 NK_MEMSET(&glfw, 0,
sizeof(glfw));
#define glDisableClientState
#define GL_TEXTURE_MAG_FILTER
#define glEnableClientState
#define GLFW_KEY_RIGHT_CONTROL
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
The header of the GLFW 3 API.
NK_API void nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff)
NK_API void nk_glfw3_shutdown(void)
#define GLFW_KEY_LEFT_SHIFT
#define GLFW_KEY_PAGE_DOWN
GLdouble GLdouble GLdouble w
GLfloat GLfloat GLfloat GLfloat h
NK_API void nk_input_scroll(struct nk_context *, struct nk_vec2 val)
NK_API void nk_free(struct nk_context *)
NK_API void nk_glfw3_render(enum nk_anti_aliasing)
#define GLFW_KEY_BACKSPACE
GLenum GLenum GLsizei void * image
NK_API struct nk_vec2 nk_vec2(float x, float y)
NK_API int nk_strlen(const char *str)
#define glTexCoordPointer
#define GL_COLOR_BUFFER_BIT
NK_API void nk_glfw3_new_frame(void)
#define GLFW_CURSOR_NORMAL
NK_API const void * nk_buffer_memory_const(const struct nk_buffer *)
NK_API struct nk_context * nk_glfw3_init(GLFWwindow *win, enum nk_glfw_init_state)
NK_API void nk_input_begin(struct nk_context *)
GLint GLsizei GLsizei height
static const textual_icon edit
#define GL_UNSIGNED_SHORT
#define GL_TEXTURE_MIN_FILTER
NK_API nk_handle nk_handle_id(int)
NK_API void nk_input_motion(struct nk_context *, int x, int y)
NK_API int nk_textedit_paste(struct nk_text_edit *, char const *, int len)
#define GL_ONE_MINUS_SRC_ALPHA
NK_API void nk_input_button(struct nk_context *, enum nk_buttons, int x, int y, int down)
NK_API void nk_input_key(struct nk_context *, enum nk_keys, int down)
NK_API nk_handle nk_handle_ptr(void *)
#define GLFW_CURSOR_HIDDEN
static const struct @18 vertices[3]
NK_API void nk_buffer_free(struct nk_buffer *)
GLFWAPI void glfwGetFramebufferSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the framebuffer of the specified window.
#define GLFW_KEY_LEFT_CONTROL
NK_API void nk_clear(struct nk_context *)
NK_API void nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint)
NK_API void nk_glfw3_font_stash_end(void)
NK_API void nk_input_end(struct nk_context *)
NK_API void nk_glfw3_font_stash_begin(struct nk_font_atlas **atlas)
#define offsetof(STRUCTURE, FIELD)
NK_API void nk_style_set_font(struct nk_context *, const struct nk_user_font *)
#define GLFW_KEY_RIGHT_SHIFT
#define GL_TEXTURE_COORD_ARRAY
NK_API void nk_input_unicode(struct nk_context *, nk_rune)
struct GLFWwindow GLFWwindow
#define NK_OFFSETOF(st, m)