skinning.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /* nuklear - v1.05 - public domain */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <stdarg.h>
  6. #include <string.h>
  7. #include <math.h>
  8. #include <assert.h>
  9. #include <time.h>
  10. #include <limits.h>
  11. #include <GL/glew.h>
  12. #include <GLFW/glfw3.h>
  13. #define NK_INCLUDE_FIXED_TYPES
  14. #define NK_INCLUDE_STANDARD_IO
  15. #define NK_INCLUDE_DEFAULT_ALLOCATOR
  16. #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
  17. #define NK_INCLUDE_FONT_BAKING
  18. #define NK_INCLUDE_DEFAULT_FONT
  19. #define NK_IMPLEMENTATION
  20. #include "../nuklear.h"
  21. #define STB_IMAGE_IMPLEMENTATION
  22. #include "stb_image.h"
  23. /* macros */
  24. #define WINDOW_WIDTH 1200
  25. #define WINDOW_HEIGHT 800
  26. #define MAX_VERTEX_MEMORY 512 * 1024
  27. #define MAX_ELEMENT_MEMORY 128 * 1024
  28. #define UNUSED(a) (void)a
  29. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  30. #define MAX(a,b) ((a) < (b) ? (b) : (a))
  31. #define LEN(a) (sizeof(a)/sizeof(a)[0])
  32. #ifdef __APPLE__
  33. #define NK_SHADER_VERSION "#version 150\n"
  34. #else
  35. #define NK_SHADER_VERSION "#version 300 es\n"
  36. #endif
  37. struct media {
  38. GLint skin;
  39. struct nk_image menu;
  40. struct nk_image check;
  41. struct nk_image check_cursor;
  42. struct nk_image option;
  43. struct nk_image option_cursor;
  44. struct nk_image header;
  45. struct nk_image window;
  46. struct nk_image scrollbar_inc_button;
  47. struct nk_image scrollbar_inc_button_hover;
  48. struct nk_image scrollbar_dec_button;
  49. struct nk_image scrollbar_dec_button_hover;
  50. struct nk_image button;
  51. struct nk_image button_hover;
  52. struct nk_image button_active;
  53. struct nk_image tab_minimize;
  54. struct nk_image tab_maximize;
  55. struct nk_image slider;
  56. struct nk_image slider_hover;
  57. struct nk_image slider_active;
  58. };
  59. /* ===============================================================
  60. *
  61. * DEVICE
  62. *
  63. * ===============================================================*/
  64. struct nk_glfw_vertex {
  65. float position[2];
  66. float uv[2];
  67. nk_byte col[4];
  68. };
  69. struct device {
  70. struct nk_buffer cmds;
  71. struct nk_draw_null_texture tex_null;
  72. GLuint vbo, vao, ebo;
  73. GLuint prog;
  74. GLuint vert_shdr;
  75. GLuint frag_shdr;
  76. GLint attrib_pos;
  77. GLint attrib_uv;
  78. GLint attrib_col;
  79. GLint uniform_tex;
  80. GLint uniform_proj;
  81. GLuint font_tex;
  82. };
  83. static void
  84. die(const char *fmt, ...)
  85. {
  86. va_list ap;
  87. va_start(ap, fmt);
  88. vfprintf(stderr, fmt, ap);
  89. va_end(ap);
  90. fputs("\n", stderr);
  91. exit(EXIT_FAILURE);
  92. }
  93. static GLuint
  94. image_load(const char *filename)
  95. {
  96. int x,y,n;
  97. GLuint tex;
  98. unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
  99. if (!data) die("failed to load image: %s", filename);
  100. glGenTextures(1, &tex);
  101. glBindTexture(GL_TEXTURE_2D, tex);
  102. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  103. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  104. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  105. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  106. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
  107. glGenerateMipmap(GL_TEXTURE_2D);
  108. stbi_image_free(data);
  109. return tex;
  110. }
  111. static void
  112. device_init(struct device *dev)
  113. {
  114. GLint status;
  115. static const GLchar *vertex_shader =
  116. NK_SHADER_VERSION
  117. "uniform mat4 ProjMtx;\n"
  118. "in vec2 Position;\n"
  119. "in vec2 TexCoord;\n"
  120. "in vec4 Color;\n"
  121. "out vec2 Frag_UV;\n"
  122. "out vec4 Frag_Color;\n"
  123. "void main() {\n"
  124. " Frag_UV = TexCoord;\n"
  125. " Frag_Color = Color;\n"
  126. " gl_Position = ProjMtx * vec4(Position.xy, 0, 1);\n"
  127. "}\n";
  128. static const GLchar *fragment_shader =
  129. NK_SHADER_VERSION
  130. "precision mediump float;\n"
  131. "uniform sampler2D Texture;\n"
  132. "in vec2 Frag_UV;\n"
  133. "in vec4 Frag_Color;\n"
  134. "out vec4 Out_Color;\n"
  135. "void main(){\n"
  136. " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
  137. "}\n";
  138. nk_buffer_init_default(&dev->cmds);
  139. dev->prog = glCreateProgram();
  140. dev->vert_shdr = glCreateShader(GL_VERTEX_SHADER);
  141. dev->frag_shdr = glCreateShader(GL_FRAGMENT_SHADER);
  142. glShaderSource(dev->vert_shdr, 1, &vertex_shader, 0);
  143. glShaderSource(dev->frag_shdr, 1, &fragment_shader, 0);
  144. glCompileShader(dev->vert_shdr);
  145. glCompileShader(dev->frag_shdr);
  146. glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status);
  147. assert(status == GL_TRUE);
  148. glGetShaderiv(dev->frag_shdr, GL_COMPILE_STATUS, &status);
  149. assert(status == GL_TRUE);
  150. glAttachShader(dev->prog, dev->vert_shdr);
  151. glAttachShader(dev->prog, dev->frag_shdr);
  152. glLinkProgram(dev->prog);
  153. glGetProgramiv(dev->prog, GL_LINK_STATUS, &status);
  154. assert(status == GL_TRUE);
  155. dev->uniform_tex = glGetUniformLocation(dev->prog, "Texture");
  156. dev->uniform_proj = glGetUniformLocation(dev->prog, "ProjMtx");
  157. dev->attrib_pos = glGetAttribLocation(dev->prog, "Position");
  158. dev->attrib_uv = glGetAttribLocation(dev->prog, "TexCoord");
  159. dev->attrib_col = glGetAttribLocation(dev->prog, "Color");
  160. {
  161. /* buffer setup */
  162. GLsizei vs = sizeof(struct nk_glfw_vertex);
  163. size_t vp = offsetof(struct nk_glfw_vertex, position);
  164. size_t vt = offsetof(struct nk_glfw_vertex, uv);
  165. size_t vc = offsetof(struct nk_glfw_vertex, col);
  166. glGenBuffers(1, &dev->vbo);
  167. glGenBuffers(1, &dev->ebo);
  168. glGenVertexArrays(1, &dev->vao);
  169. glBindVertexArray(dev->vao);
  170. glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
  171. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
  172. glEnableVertexAttribArray((GLuint)dev->attrib_pos);
  173. glEnableVertexAttribArray((GLuint)dev->attrib_uv);
  174. glEnableVertexAttribArray((GLuint)dev->attrib_col);
  175. glVertexAttribPointer((GLuint)dev->attrib_pos, 2, GL_FLOAT, GL_FALSE, vs, (void*)vp);
  176. glVertexAttribPointer((GLuint)dev->attrib_uv, 2, GL_FLOAT, GL_FALSE, vs, (void*)vt);
  177. glVertexAttribPointer((GLuint)dev->attrib_col, 4, GL_UNSIGNED_BYTE, GL_TRUE, vs, (void*)vc);
  178. }
  179. glBindTexture(GL_TEXTURE_2D, 0);
  180. glBindBuffer(GL_ARRAY_BUFFER, 0);
  181. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  182. glBindVertexArray(0);
  183. }
  184. static void
  185. device_upload_atlas(struct device *dev, const void *image, int width, int height)
  186. {
  187. glGenTextures(1, &dev->font_tex);
  188. glBindTexture(GL_TEXTURE_2D, dev->font_tex);
  189. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  190. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  191. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0,
  192. GL_RGBA, GL_UNSIGNED_BYTE, image);
  193. }
  194. static void
  195. device_shutdown(struct device *dev)
  196. {
  197. glDetachShader(dev->prog, dev->vert_shdr);
  198. glDetachShader(dev->prog, dev->frag_shdr);
  199. glDeleteShader(dev->vert_shdr);
  200. glDeleteShader(dev->frag_shdr);
  201. glDeleteProgram(dev->prog);
  202. glDeleteTextures(1, &dev->font_tex);
  203. glDeleteBuffers(1, &dev->vbo);
  204. glDeleteBuffers(1, &dev->ebo);
  205. nk_buffer_free(&dev->cmds);
  206. }
  207. static void
  208. device_draw(struct device *dev, struct nk_context *ctx, int width, int height,
  209. struct nk_vec2 scale, enum nk_anti_aliasing AA)
  210. {
  211. GLfloat ortho[4][4] = {
  212. {2.0f, 0.0f, 0.0f, 0.0f},
  213. {0.0f,-2.0f, 0.0f, 0.0f},
  214. {0.0f, 0.0f,-1.0f, 0.0f},
  215. {-1.0f,1.0f, 0.0f, 1.0f},
  216. };
  217. ortho[0][0] /= (GLfloat)width;
  218. ortho[1][1] /= (GLfloat)height;
  219. /* setup global state */
  220. glEnable(GL_BLEND);
  221. glBlendEquation(GL_FUNC_ADD);
  222. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  223. glDisable(GL_CULL_FACE);
  224. glDisable(GL_DEPTH_TEST);
  225. glEnable(GL_SCISSOR_TEST);
  226. glActiveTexture(GL_TEXTURE0);
  227. /* setup program */
  228. glUseProgram(dev->prog);
  229. glUniform1i(dev->uniform_tex, 0);
  230. glUniformMatrix4fv(dev->uniform_proj, 1, GL_FALSE, &ortho[0][0]);
  231. {
  232. /* convert from command queue into draw list and draw to screen */
  233. const struct nk_draw_command *cmd;
  234. void *vertices, *elements;
  235. const nk_draw_index *offset = NULL;
  236. /* allocate vertex and element buffer */
  237. glBindVertexArray(dev->vao);
  238. glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
  239. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
  240. glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_MEMORY, NULL, GL_STREAM_DRAW);
  241. glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_ELEMENT_MEMORY, NULL, GL_STREAM_DRAW);
  242. /* load draw vertices & elements directly into vertex + element buffer */
  243. vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
  244. elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
  245. {
  246. /* fill convert configuration */
  247. struct nk_convert_config config;
  248. static const struct nk_draw_vertex_layout_element vertex_layout[] = {
  249. {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, position)},
  250. {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, uv)},
  251. {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_glfw_vertex, col)},
  252. {NK_VERTEX_LAYOUT_END}
  253. };
  254. NK_MEMSET(&config, 0, sizeof(config));
  255. config.vertex_layout = vertex_layout;
  256. config.vertex_size = sizeof(struct nk_glfw_vertex);
  257. config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
  258. config.tex_null = dev->tex_null;
  259. config.circle_segment_count = 22;
  260. config.curve_segment_count = 22;
  261. config.arc_segment_count = 22;
  262. config.global_alpha = 1.0f;
  263. config.shape_AA = AA;
  264. config.line_AA = AA;
  265. /* setup buffers to load vertices and elements */
  266. {struct nk_buffer vbuf, ebuf;
  267. nk_buffer_init_fixed(&vbuf, vertices, MAX_VERTEX_MEMORY);
  268. nk_buffer_init_fixed(&ebuf, elements, MAX_ELEMENT_MEMORY);
  269. nk_convert(ctx, &dev->cmds, &vbuf, &ebuf, &config);}
  270. }
  271. glUnmapBuffer(GL_ARRAY_BUFFER);
  272. glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
  273. /* iterate over and execute each draw command */
  274. nk_draw_foreach(cmd, ctx, &dev->cmds)
  275. {
  276. if (!cmd->elem_count) continue;
  277. glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
  278. glScissor(
  279. (GLint)(cmd->clip_rect.x * scale.x),
  280. (GLint)((height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * scale.y),
  281. (GLint)(cmd->clip_rect.w * scale.x),
  282. (GLint)(cmd->clip_rect.h * scale.y));
  283. glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
  284. offset += cmd->elem_count;
  285. }
  286. nk_clear(ctx);
  287. nk_buffer_clear(&dev->cmds);
  288. }
  289. /* default OpenGL state */
  290. glUseProgram(0);
  291. glBindBuffer(GL_ARRAY_BUFFER, 0);
  292. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  293. glBindVertexArray(0);
  294. glDisable(GL_BLEND);
  295. glDisable(GL_SCISSOR_TEST);
  296. }
  297. /* glfw callbacks (I don't know if there is a easier way to access text and scroll )*/
  298. static void error_callback(int e, const char *d){printf("Error %d: %s\n", e, d);}
  299. static void text_input(GLFWwindow *win, unsigned int codepoint)
  300. {nk_input_unicode((struct nk_context*)glfwGetWindowUserPointer(win), codepoint);}
  301. static void scroll_input(GLFWwindow *win, double _, double yoff)
  302. {UNUSED(_);nk_input_scroll((struct nk_context*)glfwGetWindowUserPointer(win), nk_vec2(0, (float)yoff));}
  303. int main(int argc, char *argv[])
  304. {
  305. /* Platform */
  306. static GLFWwindow *win;
  307. int width = 0, height = 0;
  308. int display_width=0, display_height=0;
  309. /* GUI */
  310. struct device device;
  311. struct nk_font_atlas atlas;
  312. struct media media;
  313. struct nk_context ctx;
  314. struct nk_font *font;
  315. /* GLFW */
  316. glfwSetErrorCallback(error_callback);
  317. if (!glfwInit()) {
  318. fprintf(stdout, "[GFLW] failed to init!\n");
  319. exit(1);
  320. }
  321. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  322. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  323. glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  324. #ifdef __APPLE__
  325. glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  326. #endif
  327. win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL);
  328. glfwMakeContextCurrent(win);
  329. glfwSetWindowUserPointer(win, &ctx);
  330. glfwSetCharCallback(win, text_input);
  331. glfwSetScrollCallback(win, scroll_input);
  332. glfwGetWindowSize(win, &width, &height);
  333. glfwGetFramebufferSize(win, &display_width, &display_height);
  334. /* OpenGL */
  335. glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
  336. glewExperimental = 1;
  337. if (glewInit() != GLEW_OK) {
  338. fprintf(stderr, "Failed to setup GLEW\n");
  339. exit(1);
  340. }
  341. /* GUI */
  342. {device_init(&device);
  343. {const void *image; int w, h;
  344. const char *font_path = (argc > 1) ? argv[1]: 0;
  345. nk_font_atlas_init_default(&atlas);
  346. nk_font_atlas_begin(&atlas);
  347. if (font_path) font = nk_font_atlas_add_from_file(&atlas, font_path, 13.0f, NULL);
  348. else font = nk_font_atlas_add_default(&atlas, 13.0f, NULL);
  349. image = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32);
  350. device_upload_atlas(&device, image, w, h);
  351. nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.tex_null);}
  352. nk_init_default(&ctx, &font->handle);}
  353. { /* skin */
  354. glEnable(GL_TEXTURE_2D);
  355. media.skin = image_load("../skins/gwen.png");
  356. media.check = nk_subimage_id(media.skin, 512,512, nk_rect(464,32,15,15));
  357. media.check_cursor = nk_subimage_id(media.skin, 512,512, nk_rect(450,34,11,11));
  358. media.option = nk_subimage_id(media.skin, 512,512, nk_rect(464,64,15,15));
  359. media.option_cursor = nk_subimage_id(media.skin, 512,512, nk_rect(451,67,9,9));
  360. media.header = nk_subimage_id(media.skin, 512,512, nk_rect(128,0,127,24));
  361. media.window = nk_subimage_id(media.skin, 512,512, nk_rect(128,23,127,104));
  362. media.scrollbar_inc_button = nk_subimage_id(media.skin, 512,512, nk_rect(464,256,15,15));
  363. media.scrollbar_inc_button_hover = nk_subimage_id(media.skin, 512,512, nk_rect(464,320,15,15));
  364. media.scrollbar_dec_button = nk_subimage_id(media.skin, 512,512, nk_rect(464,224,15,15));
  365. media.scrollbar_dec_button_hover = nk_subimage_id(media.skin, 512,512, nk_rect(464,288,15,15));
  366. media.button = nk_subimage_id(media.skin, 512,512, nk_rect(384,336,127,31));
  367. media.button_hover = nk_subimage_id(media.skin, 512,512, nk_rect(384,368,127,31));
  368. media.button_active = nk_subimage_id(media.skin, 512,512, nk_rect(384,400,127,31));
  369. media.tab_minimize = nk_subimage_id(media.skin, 512,512, nk_rect(451, 99, 9, 9));
  370. media.tab_maximize = nk_subimage_id(media.skin, 512,512, nk_rect(467,99,9,9));
  371. media.slider = nk_subimage_id(media.skin, 512,512, nk_rect(418,33,11,14));
  372. media.slider_hover = nk_subimage_id(media.skin, 512,512, nk_rect(418,49,11,14));
  373. media.slider_active = nk_subimage_id(media.skin, 512,512, nk_rect(418,64,11,14));
  374. /* window */
  375. ctx.style.window.background = nk_rgb(204,204,204);
  376. ctx.style.window.fixed_background = nk_style_item_image(media.window);
  377. ctx.style.window.border_color = nk_rgb(67,67,67);
  378. ctx.style.window.combo_border_color = nk_rgb(67,67,67);
  379. ctx.style.window.contextual_border_color = nk_rgb(67,67,67);
  380. ctx.style.window.menu_border_color = nk_rgb(67,67,67);
  381. ctx.style.window.group_border_color = nk_rgb(67,67,67);
  382. ctx.style.window.tooltip_border_color = nk_rgb(67,67,67);
  383. ctx.style.window.scrollbar_size = nk_vec2(16,16);
  384. ctx.style.window.border_color = nk_rgba(0,0,0,0);
  385. ctx.style.window.padding = nk_vec2(8,4);
  386. ctx.style.window.border = 3;
  387. /* window header */
  388. ctx.style.window.header.normal = nk_style_item_image(media.header);
  389. ctx.style.window.header.hover = nk_style_item_image(media.header);
  390. ctx.style.window.header.active = nk_style_item_image(media.header);
  391. ctx.style.window.header.label_normal = nk_rgb(95,95,95);
  392. ctx.style.window.header.label_hover = nk_rgb(95,95,95);
  393. ctx.style.window.header.label_active = nk_rgb(95,95,95);
  394. /* scrollbar */
  395. ctx.style.scrollv.normal = nk_style_item_color(nk_rgb(184,184,184));
  396. ctx.style.scrollv.hover = nk_style_item_color(nk_rgb(184,184,184));
  397. ctx.style.scrollv.active = nk_style_item_color(nk_rgb(184,184,184));
  398. ctx.style.scrollv.cursor_normal = nk_style_item_color(nk_rgb(220,220,220));
  399. ctx.style.scrollv.cursor_hover = nk_style_item_color(nk_rgb(235,235,235));
  400. ctx.style.scrollv.cursor_active = nk_style_item_color(nk_rgb(99,202,255));
  401. ctx.style.scrollv.dec_symbol = NK_SYMBOL_NONE;
  402. ctx.style.scrollv.inc_symbol = NK_SYMBOL_NONE;
  403. ctx.style.scrollv.show_buttons = nk_true;
  404. ctx.style.scrollv.border_color = nk_rgb(81,81,81);
  405. ctx.style.scrollv.cursor_border_color = nk_rgb(81,81,81);
  406. ctx.style.scrollv.border = 1;
  407. ctx.style.scrollv.rounding = 0;
  408. ctx.style.scrollv.border_cursor = 1;
  409. ctx.style.scrollv.rounding_cursor = 2;
  410. /* scrollbar buttons */
  411. ctx.style.scrollv.inc_button.normal = nk_style_item_image(media.scrollbar_inc_button);
  412. ctx.style.scrollv.inc_button.hover = nk_style_item_image(media.scrollbar_inc_button_hover);
  413. ctx.style.scrollv.inc_button.active = nk_style_item_image(media.scrollbar_inc_button_hover);
  414. ctx.style.scrollv.inc_button.border_color = nk_rgba(0,0,0,0);
  415. ctx.style.scrollv.inc_button.text_background = nk_rgba(0,0,0,0);
  416. ctx.style.scrollv.inc_button.text_normal = nk_rgba(0,0,0,0);
  417. ctx.style.scrollv.inc_button.text_hover = nk_rgba(0,0,0,0);
  418. ctx.style.scrollv.inc_button.text_active = nk_rgba(0,0,0,0);
  419. ctx.style.scrollv.inc_button.border = 0.0f;
  420. ctx.style.scrollv.dec_button.normal = nk_style_item_image(media.scrollbar_dec_button);
  421. ctx.style.scrollv.dec_button.hover = nk_style_item_image(media.scrollbar_dec_button_hover);
  422. ctx.style.scrollv.dec_button.active = nk_style_item_image(media.scrollbar_dec_button_hover);
  423. ctx.style.scrollv.dec_button.border_color = nk_rgba(0,0,0,0);
  424. ctx.style.scrollv.dec_button.text_background = nk_rgba(0,0,0,0);
  425. ctx.style.scrollv.dec_button.text_normal = nk_rgba(0,0,0,0);
  426. ctx.style.scrollv.dec_button.text_hover = nk_rgba(0,0,0,0);
  427. ctx.style.scrollv.dec_button.text_active = nk_rgba(0,0,0,0);
  428. ctx.style.scrollv.dec_button.border = 0.0f;
  429. /* checkbox toggle */
  430. {struct nk_style_toggle *toggle;
  431. toggle = &ctx.style.checkbox;
  432. toggle->normal = nk_style_item_image(media.check);
  433. toggle->hover = nk_style_item_image(media.check);
  434. toggle->active = nk_style_item_image(media.check);
  435. toggle->cursor_normal = nk_style_item_image(media.check_cursor);
  436. toggle->cursor_hover = nk_style_item_image(media.check_cursor);
  437. toggle->text_normal = nk_rgb(95,95,95);
  438. toggle->text_hover = nk_rgb(95,95,95);
  439. toggle->text_active = nk_rgb(95,95,95);}
  440. /* option toggle */
  441. {struct nk_style_toggle *toggle;
  442. toggle = &ctx.style.option;
  443. toggle->normal = nk_style_item_image(media.option);
  444. toggle->hover = nk_style_item_image(media.option);
  445. toggle->active = nk_style_item_image(media.option);
  446. toggle->cursor_normal = nk_style_item_image(media.option_cursor);
  447. toggle->cursor_hover = nk_style_item_image(media.option_cursor);
  448. toggle->text_normal = nk_rgb(95,95,95);
  449. toggle->text_hover = nk_rgb(95,95,95);
  450. toggle->text_active = nk_rgb(95,95,95);}
  451. /* default button */
  452. ctx.style.button.normal = nk_style_item_image(media.button);
  453. ctx.style.button.hover = nk_style_item_image(media.button_hover);
  454. ctx.style.button.active = nk_style_item_image(media.button_active);
  455. ctx.style.button.border_color = nk_rgba(0,0,0,0);
  456. ctx.style.button.text_background = nk_rgba(0,0,0,0);
  457. ctx.style.button.text_normal = nk_rgb(95,95,95);
  458. ctx.style.button.text_hover = nk_rgb(95,95,95);
  459. ctx.style.button.text_active = nk_rgb(95,95,95);
  460. /* default text */
  461. ctx.style.text.color = nk_rgb(95,95,95);
  462. /* contextual button */
  463. ctx.style.contextual_button.normal = nk_style_item_color(nk_rgb(206,206,206));
  464. ctx.style.contextual_button.hover = nk_style_item_color(nk_rgb(229,229,229));
  465. ctx.style.contextual_button.active = nk_style_item_color(nk_rgb(99,202,255));
  466. ctx.style.contextual_button.border_color = nk_rgba(0,0,0,0);
  467. ctx.style.contextual_button.text_background = nk_rgba(0,0,0,0);
  468. ctx.style.contextual_button.text_normal = nk_rgb(95,95,95);
  469. ctx.style.contextual_button.text_hover = nk_rgb(95,95,95);
  470. ctx.style.contextual_button.text_active = nk_rgb(95,95,95);
  471. /* menu button */
  472. ctx.style.menu_button.normal = nk_style_item_color(nk_rgb(206,206,206));
  473. ctx.style.menu_button.hover = nk_style_item_color(nk_rgb(229,229,229));
  474. ctx.style.menu_button.active = nk_style_item_color(nk_rgb(99,202,255));
  475. ctx.style.menu_button.border_color = nk_rgba(0,0,0,0);
  476. ctx.style.menu_button.text_background = nk_rgba(0,0,0,0);
  477. ctx.style.menu_button.text_normal = nk_rgb(95,95,95);
  478. ctx.style.menu_button.text_hover = nk_rgb(95,95,95);
  479. ctx.style.menu_button.text_active = nk_rgb(95,95,95);
  480. /* tree */
  481. ctx.style.tab.text = nk_rgb(95,95,95);
  482. ctx.style.tab.tab_minimize_button.normal = nk_style_item_image(media.tab_minimize);
  483. ctx.style.tab.tab_minimize_button.hover = nk_style_item_image(media.tab_minimize);
  484. ctx.style.tab.tab_minimize_button.active = nk_style_item_image(media.tab_minimize);
  485. ctx.style.tab.tab_minimize_button.text_background = nk_rgba(0,0,0,0);
  486. ctx.style.tab.tab_minimize_button.text_normal = nk_rgba(0,0,0,0);
  487. ctx.style.tab.tab_minimize_button.text_hover = nk_rgba(0,0,0,0);
  488. ctx.style.tab.tab_minimize_button.text_active = nk_rgba(0,0,0,0);
  489. ctx.style.tab.tab_maximize_button.normal = nk_style_item_image(media.tab_maximize);
  490. ctx.style.tab.tab_maximize_button.hover = nk_style_item_image(media.tab_maximize);
  491. ctx.style.tab.tab_maximize_button.active = nk_style_item_image(media.tab_maximize);
  492. ctx.style.tab.tab_maximize_button.text_background = nk_rgba(0,0,0,0);
  493. ctx.style.tab.tab_maximize_button.text_normal = nk_rgba(0,0,0,0);
  494. ctx.style.tab.tab_maximize_button.text_hover = nk_rgba(0,0,0,0);
  495. ctx.style.tab.tab_maximize_button.text_active = nk_rgba(0,0,0,0);
  496. ctx.style.tab.node_minimize_button.normal = nk_style_item_image(media.tab_minimize);
  497. ctx.style.tab.node_minimize_button.hover = nk_style_item_image(media.tab_minimize);
  498. ctx.style.tab.node_minimize_button.active = nk_style_item_image(media.tab_minimize);
  499. ctx.style.tab.node_minimize_button.text_background = nk_rgba(0,0,0,0);
  500. ctx.style.tab.node_minimize_button.text_normal = nk_rgba(0,0,0,0);
  501. ctx.style.tab.node_minimize_button.text_hover = nk_rgba(0,0,0,0);
  502. ctx.style.tab.node_minimize_button.text_active = nk_rgba(0,0,0,0);
  503. ctx.style.tab.node_maximize_button.normal = nk_style_item_image(media.tab_maximize);
  504. ctx.style.tab.node_maximize_button.hover = nk_style_item_image(media.tab_maximize);
  505. ctx.style.tab.node_maximize_button.active = nk_style_item_image(media.tab_maximize);
  506. ctx.style.tab.node_maximize_button.text_background = nk_rgba(0,0,0,0);
  507. ctx.style.tab.node_maximize_button.text_normal = nk_rgba(0,0,0,0);
  508. ctx.style.tab.node_maximize_button.text_hover = nk_rgba(0,0,0,0);
  509. ctx.style.tab.node_maximize_button.text_active = nk_rgba(0,0,0,0);
  510. /* selectable */
  511. ctx.style.selectable.normal = nk_style_item_color(nk_rgb(206,206,206));
  512. ctx.style.selectable.hover = nk_style_item_color(nk_rgb(206,206,206));
  513. ctx.style.selectable.pressed = nk_style_item_color(nk_rgb(206,206,206));
  514. ctx.style.selectable.normal_active = nk_style_item_color(nk_rgb(185,205,248));
  515. ctx.style.selectable.hover_active = nk_style_item_color(nk_rgb(185,205,248));
  516. ctx.style.selectable.pressed_active = nk_style_item_color(nk_rgb(185,205,248));
  517. ctx.style.selectable.text_normal = nk_rgb(95,95,95);
  518. ctx.style.selectable.text_hover = nk_rgb(95,95,95);
  519. ctx.style.selectable.text_pressed = nk_rgb(95,95,95);
  520. ctx.style.selectable.text_normal_active = nk_rgb(95,95,95);
  521. ctx.style.selectable.text_hover_active = nk_rgb(95,95,95);
  522. ctx.style.selectable.text_pressed_active = nk_rgb(95,95,95);
  523. /* slider */
  524. ctx.style.slider.normal = nk_style_item_hide();
  525. ctx.style.slider.hover = nk_style_item_hide();
  526. ctx.style.slider.active = nk_style_item_hide();
  527. ctx.style.slider.bar_normal = nk_rgb(156,156,156);
  528. ctx.style.slider.bar_hover = nk_rgb(156,156,156);
  529. ctx.style.slider.bar_active = nk_rgb(156,156,156);
  530. ctx.style.slider.bar_filled = nk_rgb(156,156,156);
  531. ctx.style.slider.cursor_normal = nk_style_item_image(media.slider);
  532. ctx.style.slider.cursor_hover = nk_style_item_image(media.slider_hover);
  533. ctx.style.slider.cursor_active = nk_style_item_image(media.slider_active);
  534. ctx.style.slider.cursor_size = nk_vec2(16.5f,21);
  535. ctx.style.slider.bar_height = 1;
  536. /* progressbar */
  537. ctx.style.progress.normal = nk_style_item_color(nk_rgb(231,231,231));
  538. ctx.style.progress.hover = nk_style_item_color(nk_rgb(231,231,231));
  539. ctx.style.progress.active = nk_style_item_color(nk_rgb(231,231,231));
  540. ctx.style.progress.cursor_normal = nk_style_item_color(nk_rgb(63,242,93));
  541. ctx.style.progress.cursor_hover = nk_style_item_color(nk_rgb(63,242,93));
  542. ctx.style.progress.cursor_active = nk_style_item_color(nk_rgb(63,242,93));
  543. ctx.style.progress.border_color = nk_rgb(114,116,115);
  544. ctx.style.progress.padding = nk_vec2(0,0);
  545. ctx.style.progress.border = 2;
  546. ctx.style.progress.rounding = 1;
  547. /* combo */
  548. ctx.style.combo.normal = nk_style_item_color(nk_rgb(216,216,216));
  549. ctx.style.combo.hover = nk_style_item_color(nk_rgb(216,216,216));
  550. ctx.style.combo.active = nk_style_item_color(nk_rgb(216,216,216));
  551. ctx.style.combo.border_color = nk_rgb(95,95,95);
  552. ctx.style.combo.label_normal = nk_rgb(95,95,95);
  553. ctx.style.combo.label_hover = nk_rgb(95,95,95);
  554. ctx.style.combo.label_active = nk_rgb(95,95,95);
  555. ctx.style.combo.border = 1;
  556. ctx.style.combo.rounding = 1;
  557. /* combo button */
  558. ctx.style.combo.button.normal = nk_style_item_color(nk_rgb(216,216,216));
  559. ctx.style.combo.button.hover = nk_style_item_color(nk_rgb(216,216,216));
  560. ctx.style.combo.button.active = nk_style_item_color(nk_rgb(216,216,216));
  561. ctx.style.combo.button.text_background = nk_rgb(216,216,216);
  562. ctx.style.combo.button.text_normal = nk_rgb(95,95,95);
  563. ctx.style.combo.button.text_hover = nk_rgb(95,95,95);
  564. ctx.style.combo.button.text_active = nk_rgb(95,95,95);
  565. /* property */
  566. ctx.style.property.normal = nk_style_item_color(nk_rgb(216,216,216));
  567. ctx.style.property.hover = nk_style_item_color(nk_rgb(216,216,216));
  568. ctx.style.property.active = nk_style_item_color(nk_rgb(216,216,216));
  569. ctx.style.property.border_color = nk_rgb(81,81,81);
  570. ctx.style.property.label_normal = nk_rgb(95,95,95);
  571. ctx.style.property.label_hover = nk_rgb(95,95,95);
  572. ctx.style.property.label_active = nk_rgb(95,95,95);
  573. ctx.style.property.sym_left = NK_SYMBOL_TRIANGLE_LEFT;
  574. ctx.style.property.sym_right = NK_SYMBOL_TRIANGLE_RIGHT;
  575. ctx.style.property.rounding = 10;
  576. ctx.style.property.border = 1;
  577. /* edit */
  578. ctx.style.edit.normal = nk_style_item_color(nk_rgb(240,240,240));
  579. ctx.style.edit.hover = nk_style_item_color(nk_rgb(240,240,240));
  580. ctx.style.edit.active = nk_style_item_color(nk_rgb(240,240,240));
  581. ctx.style.edit.border_color = nk_rgb(62,62,62);
  582. ctx.style.edit.cursor_normal = nk_rgb(99,202,255);
  583. ctx.style.edit.cursor_hover = nk_rgb(99,202,255);
  584. ctx.style.edit.cursor_text_normal = nk_rgb(95,95,95);
  585. ctx.style.edit.cursor_text_hover = nk_rgb(95,95,95);
  586. ctx.style.edit.text_normal = nk_rgb(95,95,95);
  587. ctx.style.edit.text_hover = nk_rgb(95,95,95);
  588. ctx.style.edit.text_active = nk_rgb(95,95,95);
  589. ctx.style.edit.selected_normal = nk_rgb(99,202,255);
  590. ctx.style.edit.selected_hover = nk_rgb(99,202,255);
  591. ctx.style.edit.selected_text_normal = nk_rgb(95,95,95);
  592. ctx.style.edit.selected_text_hover = nk_rgb(95,95,95);
  593. ctx.style.edit.border = 1;
  594. ctx.style.edit.rounding = 2;
  595. /* property buttons */
  596. ctx.style.property.dec_button.normal = nk_style_item_color(nk_rgb(216,216,216));
  597. ctx.style.property.dec_button.hover = nk_style_item_color(nk_rgb(216,216,216));
  598. ctx.style.property.dec_button.active = nk_style_item_color(nk_rgb(216,216,216));
  599. ctx.style.property.dec_button.text_background = nk_rgba(0,0,0,0);
  600. ctx.style.property.dec_button.text_normal = nk_rgb(95,95,95);
  601. ctx.style.property.dec_button.text_hover = nk_rgb(95,95,95);
  602. ctx.style.property.dec_button.text_active = nk_rgb(95,95,95);
  603. ctx.style.property.inc_button = ctx.style.property.dec_button;
  604. /* property edit */
  605. ctx.style.property.edit.normal = nk_style_item_color(nk_rgb(216,216,216));
  606. ctx.style.property.edit.hover = nk_style_item_color(nk_rgb(216,216,216));
  607. ctx.style.property.edit.active = nk_style_item_color(nk_rgb(216,216,216));
  608. ctx.style.property.edit.border_color = nk_rgba(0,0,0,0);
  609. ctx.style.property.edit.cursor_normal = nk_rgb(95,95,95);
  610. ctx.style.property.edit.cursor_hover = nk_rgb(95,95,95);
  611. ctx.style.property.edit.cursor_text_normal = nk_rgb(216,216,216);
  612. ctx.style.property.edit.cursor_text_hover = nk_rgb(216,216,216);
  613. ctx.style.property.edit.text_normal = nk_rgb(95,95,95);
  614. ctx.style.property.edit.text_hover = nk_rgb(95,95,95);
  615. ctx.style.property.edit.text_active = nk_rgb(95,95,95);
  616. ctx.style.property.edit.selected_normal = nk_rgb(95,95,95);
  617. ctx.style.property.edit.selected_hover = nk_rgb(95,95,95);
  618. ctx.style.property.edit.selected_text_normal = nk_rgb(216,216,216);
  619. ctx.style.property.edit.selected_text_hover = nk_rgb(216,216,216);
  620. /* chart */
  621. ctx.style.chart.background = nk_style_item_color(nk_rgb(216,216,216));
  622. ctx.style.chart.border_color = nk_rgb(81,81,81);
  623. ctx.style.chart.color = nk_rgb(95,95,95);
  624. ctx.style.chart.selected_color = nk_rgb(255,0,0);
  625. ctx.style.chart.border = 1;
  626. }
  627. while (!glfwWindowShouldClose(win))
  628. {
  629. /* High DPI displays */
  630. struct nk_vec2 scale;
  631. glfwGetWindowSize(win, &width, &height);
  632. glfwGetFramebufferSize(win, &display_width, &display_height);
  633. scale.x = (float)display_width/(float)width;
  634. scale.y = (float)display_height/(float)height;
  635. /* Input */
  636. {double x, y;
  637. nk_input_begin(&ctx);
  638. glfwPollEvents();
  639. nk_input_key(&ctx, NK_KEY_DEL, glfwGetKey(win, GLFW_KEY_DELETE) == GLFW_PRESS);
  640. nk_input_key(&ctx, NK_KEY_ENTER, glfwGetKey(win, GLFW_KEY_ENTER) == GLFW_PRESS);
  641. nk_input_key(&ctx, NK_KEY_TAB, glfwGetKey(win, GLFW_KEY_TAB) == GLFW_PRESS);
  642. nk_input_key(&ctx, NK_KEY_BACKSPACE, glfwGetKey(win, GLFW_KEY_BACKSPACE) == GLFW_PRESS);
  643. nk_input_key(&ctx, NK_KEY_LEFT, glfwGetKey(win, GLFW_KEY_LEFT) == GLFW_PRESS);
  644. nk_input_key(&ctx, NK_KEY_RIGHT, glfwGetKey(win, GLFW_KEY_RIGHT) == GLFW_PRESS);
  645. nk_input_key(&ctx, NK_KEY_UP, glfwGetKey(win, GLFW_KEY_UP) == GLFW_PRESS);
  646. nk_input_key(&ctx, NK_KEY_DOWN, glfwGetKey(win, GLFW_KEY_DOWN) == GLFW_PRESS);
  647. if (glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
  648. glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS) {
  649. nk_input_key(&ctx, NK_KEY_COPY, glfwGetKey(win, GLFW_KEY_C) == GLFW_PRESS);
  650. nk_input_key(&ctx, NK_KEY_PASTE, glfwGetKey(win, GLFW_KEY_P) == GLFW_PRESS);
  651. nk_input_key(&ctx, NK_KEY_CUT, glfwGetKey(win, GLFW_KEY_X) == GLFW_PRESS);
  652. nk_input_key(&ctx, NK_KEY_CUT, glfwGetKey(win, GLFW_KEY_E) == GLFW_PRESS);
  653. nk_input_key(&ctx, NK_KEY_SHIFT, 1);
  654. } else {
  655. nk_input_key(&ctx, NK_KEY_COPY, 0);
  656. nk_input_key(&ctx, NK_KEY_PASTE, 0);
  657. nk_input_key(&ctx, NK_KEY_CUT, 0);
  658. nk_input_key(&ctx, NK_KEY_SHIFT, 0);
  659. }
  660. glfwGetCursorPos(win, &x, &y);
  661. nk_input_motion(&ctx, (int)x, (int)y);
  662. nk_input_button(&ctx, NK_BUTTON_LEFT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
  663. nk_input_button(&ctx, NK_BUTTON_MIDDLE, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS);
  664. nk_input_button(&ctx, NK_BUTTON_RIGHT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
  665. nk_input_end(&ctx);}
  666. /* GUI */
  667. if (nk_begin(&ctx, "Demo", nk_rect(50, 50, 300, 400),
  668. NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE))
  669. {
  670. int i;
  671. float id;
  672. static int slider = 10;
  673. static int field_len;
  674. static nk_size prog_value = 60;
  675. static int current_weapon = 0;
  676. static char field_buffer[64];
  677. static float pos;
  678. static const char *weapons[] = {"Fist","Pistol","Shotgun","Plasma","BFG"};
  679. const float step = (2*3.141592654f) / 32;
  680. nk_layout_row_static(&ctx, 30, 120, 1);
  681. if (nk_button_label(&ctx, "button"))
  682. fprintf(stdout, "button pressed\n");
  683. nk_layout_row_dynamic(&ctx, 20, 1);
  684. nk_label(&ctx, "Label", NK_TEXT_LEFT);
  685. nk_layout_row_dynamic(&ctx, 30, 2);
  686. nk_check_label(&ctx, "inactive", 0);
  687. nk_check_label(&ctx, "active", 1);
  688. nk_option_label(&ctx, "active", 1);
  689. nk_option_label(&ctx, "inactive", 0);
  690. nk_layout_row_dynamic(&ctx, 30, 1);
  691. nk_slider_int(&ctx, 0, &slider, 16, 1);
  692. nk_layout_row_dynamic(&ctx, 20, 1);
  693. nk_progress(&ctx, &prog_value, 100, NK_MODIFIABLE);
  694. nk_layout_row_dynamic(&ctx, 25, 1);
  695. nk_edit_string(&ctx, NK_EDIT_FIELD, field_buffer, &field_len, 64, nk_filter_default);
  696. nk_property_float(&ctx, "#X:", -1024.0f, &pos, 1024.0f, 1, 1);
  697. current_weapon = nk_combo(&ctx, weapons, LEN(weapons), current_weapon, 25, nk_vec2(nk_widget_width(&ctx),200));
  698. nk_layout_row_dynamic(&ctx, 100, 1);
  699. if (nk_chart_begin_colored(&ctx, NK_CHART_LINES, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) {
  700. nk_chart_add_slot_colored(&ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f);
  701. nk_chart_add_slot_colored(&ctx, NK_CHART_LINES, nk_rgb(0,255,0), nk_rgb(0,150,0), 32, -1.0f, 1.0f);
  702. for (id = 0, i = 0; i < 32; ++i) {
  703. nk_chart_push_slot(&ctx, (float)fabs(sin(id)), 0);
  704. nk_chart_push_slot(&ctx, (float)cos(id), 1);
  705. nk_chart_push_slot(&ctx, (float)sin(id), 2);
  706. id += step;
  707. }
  708. }
  709. nk_chart_end(&ctx);
  710. nk_layout_row_dynamic(&ctx, 250, 1);
  711. if (nk_group_begin(&ctx, "Standard", NK_WINDOW_BORDER|NK_WINDOW_BORDER))
  712. {
  713. if (nk_tree_push(&ctx, NK_TREE_NODE, "Window", NK_MAXIMIZED)) {
  714. static int selected[8];
  715. if (nk_tree_push(&ctx, NK_TREE_NODE, "Next", NK_MAXIMIZED)) {
  716. nk_layout_row_dynamic(&ctx, 20, 1);
  717. for (i = 0; i < 4; ++i)
  718. nk_selectable_label(&ctx, (selected[i]) ? "Selected": "Unselected", NK_TEXT_LEFT, &selected[i]);
  719. nk_tree_pop(&ctx);
  720. }
  721. if (nk_tree_push(&ctx, NK_TREE_NODE, "Previous", NK_MAXIMIZED)) {
  722. nk_layout_row_dynamic(&ctx, 20, 1);
  723. for (i = 4; i < 8; ++i)
  724. nk_selectable_label(&ctx, (selected[i]) ? "Selected": "Unselected", NK_TEXT_LEFT, &selected[i]);
  725. nk_tree_pop(&ctx);
  726. }
  727. nk_tree_pop(&ctx);
  728. }
  729. nk_group_end(&ctx);
  730. }
  731. }
  732. nk_end(&ctx);
  733. /* Draw */
  734. glViewport(0, 0, display_width, display_height);
  735. glClear(GL_COLOR_BUFFER_BIT);
  736. glClearColor(0.5882, 0.6666, 0.6666, 1.0f);
  737. device_draw(&device, &ctx, width, height, scale, NK_ANTI_ALIASING_ON);
  738. glfwSwapBuffers(win);
  739. }
  740. glDeleteTextures(1,(const GLuint*)&media.skin);
  741. nk_font_atlas_clear(&atlas);
  742. nk_free(&ctx);
  743. device_shutdown(&device);
  744. glfwTerminate();
  745. return 0;
  746. }