1 /* nuklear - v1.32.0 - 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 <math.h>
10 #include <limits.h>
11 #include <time.h>
12
13 #include <GLFW/glfw3.h>
14
15 #define NK_INCLUDE_FIXED_TYPES
16 #define NK_INCLUDE_STANDARD_IO
17 #define NK_INCLUDE_STANDARD_VARARGS
18 #define NK_INCLUDE_DEFAULT_ALLOCATOR
19 #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
20 #define NK_INCLUDE_FONT_BAKING
21 #define NK_INCLUDE_DEFAULT_FONT
22 #define NK_IMPLEMENTATION
23 #define NK_GLFW_GL2_IMPLEMENTATION
24 #include "../../nuklear.h"
25 #include "nuklear_glfw_gl2.h"
26
27 #define WINDOW_WIDTH 1200
28 #define WINDOW_HEIGHT 800
29
30 /* ===============================================================
31 *
32 * EXAMPLE
33 *
34 * ===============================================================*/
35 /* This are some code examples to provide a small overview of what can be
36 * done with this library. To try out an example uncomment the defines */
37 /*#define INCLUDE_ALL */
38 /*#define INCLUDE_STYLE */
39 /*#define INCLUDE_CALCULATOR */
40 /*#define INCLUDE_OVERVIEW */
41 /*#define INCLUDE_NODE_EDITOR */
42
43 #ifdef INCLUDE_ALL
44 #define INCLUDE_STYLE
45 #define INCLUDE_CALCULATOR
46 #define INCLUDE_OVERVIEW
47 #define INCLUDE_NODE_EDITOR
48 #endif
49
50 #ifdef INCLUDE_STYLE
51 #include "../style.c"
52 #endif
53 #ifdef INCLUDE_CALCULATOR
54 #include "../calculator.c"
55 #endif
56 #ifdef INCLUDE_OVERVIEW
57 #include "../overview.c"
58 #endif
59 #ifdef INCLUDE_NODE_EDITOR
60 #include "../node_editor.c"
61 #endif
62
63 /* ===============================================================
64 *
65 * DEMO
66 *
67 * ===============================================================*/
error_callback(int e,const char * d)68 static void error_callback(int e, const char *d)
69 {printf("Error %d: %s\n", e, d);}
70
main(void)71 int main(void)
72 {
73 /* Platform */
74 static GLFWwindow *win;
75 int width = 0, height = 0;
76 struct nk_context *ctx;
77 struct nk_colorf bg;
78
79 /* GLFW */
80 glfwSetErrorCallback(error_callback);
81 if (!glfwInit()) {
82 fprintf(stdout, "[GFLW] failed to init!\n");
83 exit(1);
84 }
85 win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL);
86 glfwMakeContextCurrent(win);
87 glfwGetWindowSize(win, &width, &height);
88
89 /* GUI */
90 ctx = nk_glfw3_init(win, NK_GLFW3_INSTALL_CALLBACKS);
91 /* Load Fonts: if none of these are loaded a default font will be used */
92 /* Load Cursor: if you uncomment cursor loading please hide the cursor */
93 {struct nk_font_atlas *atlas;
94 nk_glfw3_font_stash_begin(&atlas);
95 /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/
96 /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/
97 /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/
98 /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/
99 /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/
100 /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/
101 nk_glfw3_font_stash_end();
102 /*nk_style_load_all_cursors(ctx, atlas->cursors);*/
103 /*nk_style_set_font(ctx, &droid->handle);*/}
104
105 #ifdef INCLUDE_STYLE
106 /*set_style(ctx, THEME_WHITE);*/
107 /*set_style(ctx, THEME_RED);*/
108 /*set_style(ctx, THEME_BLUE);*/
109 /*set_style(ctx, THEME_DARK);*/
110 #endif
111
112 bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
113 while (!glfwWindowShouldClose(win))
114 {
115 /* Input */
116 glfwPollEvents();
117 nk_glfw3_new_frame();
118
119 /* GUI */
120 if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
121 NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
122 NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
123 {
124 enum {EASY, HARD};
125 static int op = EASY;
126 static int property = 20;
127 nk_layout_row_static(ctx, 30, 80, 1);
128 if (nk_button_label(ctx, "button"))
129 fprintf(stdout, "button pressed\n");
130
131 nk_layout_row_dynamic(ctx, 30, 2);
132 if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
133 if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
134
135 nk_layout_row_dynamic(ctx, 25, 1);
136 nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
137
138 nk_layout_row_dynamic(ctx, 20, 1);
139 nk_label(ctx, "background:", NK_TEXT_LEFT);
140 nk_layout_row_dynamic(ctx, 25, 1);
141 if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) {
142 nk_layout_row_dynamic(ctx, 120, 1);
143 bg = nk_color_picker(ctx, bg, NK_RGBA);
144 nk_layout_row_dynamic(ctx, 25, 1);
145 bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
146 bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
147 bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
148 bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
149 nk_combo_end(ctx);
150 }
151 }
152 nk_end(ctx);
153
154 /* -------------- EXAMPLES ---------------- */
155 #ifdef INCLUDE_CALCULATOR
156 calculator(ctx);
157 #endif
158 #ifdef INCLUDE_OVERVIEW
159 overview(ctx);
160 #endif
161 #ifdef INCLUDE_NODE_EDITOR
162 node_editor(ctx);
163 #endif
164 /* ----------------------------------------- */
165
166 /* Draw */
167 glfwGetWindowSize(win, &width, &height);
168 glViewport(0, 0, width, height);
169 glClear(GL_COLOR_BUFFER_BIT);
170 glClearColor(bg.r, bg.g, bg.b, bg.a);
171 /* IMPORTANT: `nk_glfw_render` modifies some global OpenGL state
172 * with blending, scissor, face culling and depth test and defaults everything
173 * back into a default state. Make sure to either save and restore or
174 * reset your own state after drawing rendering the UI. */
175 nk_glfw3_render(NK_ANTI_ALIASING_ON);
176 glfwSwapBuffers(win);
177 }
178 nk_glfw3_shutdown();
179 glfwTerminate();
180 return 0;
181 }
182
183