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 <SFML/Window.hpp>
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_SFML_GL3_IMPLEMENTATION
24 #include "../../nuklear.h"
25 #include "nuklear_sfml_gl3.h"
26
27 #define WINDOW_WIDTH 1200
28 #define WINDOW_HEIGHT 800
29
30 #define MAX_VERTEX_BUFFER 512 * 1024
31 #define MAX_ELEMENT_BUFFER 128 * 1024
32
33 /* ===============================================================
34 *
35 * EXAMPLE
36 *
37 * ===============================================================*/
38 /* This are some code examples to provide a small overview of what can be
39 * done with this library. To try out an example uncomment the defines */
40 /*#define INCLUDE_ALL */
41 /*#define INCLUDE_STYLE */
42 /*#define INCLUDE_CALCULATOR */
43 /*#define INCLUDE_OVERVIEW */
44 /*#define INCLUDE_NODE_EDITOR */
45
46 #ifdef INCLUDE_ALL
47 #define INCLUDE_STYLE
48 #define INCLUDE_CALCULATOR
49 #define INCLUDE_OVERVIEW
50 #define INCLUDE_NODE_EDITOR
51 #endif
52
53 #ifdef INCLUDE_STYLE
54 #include "../style.c"
55 #endif
56 #ifdef INCLUDE_CALCULATOR
57 #include "../calculator.c"
58 #endif
59 #ifdef INCLUDE_OVERVIEW
60 #include "../overview.c"
61 #endif
62 #ifdef INCLUDE_NODE_EDITOR
63 #include "../node_editor.c"
64 #endif
65
66 /* ===============================================================
67 *
68 * DEMO
69 *
70 * ===============================================================*/
main(void)71 int main(void)
72 {
73 /* Platform */
74 sf::ContextSettings settings(24, 8, 4, 3, 3);
75 sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
76 win.setVerticalSyncEnabled(true);
77 win.setActive(true);
78 if(!gladLoadGL()) { /* Load OpenGL extensions */
79 printf("Failed to load OpenGL extensions!\n");
80 return -1;
81 }
82 glViewport(0, 0, win.getSize().x, win.getSize().y);
83
84 /* GUI */
85 struct nk_context *ctx;
86 ctx = nk_sfml_init(&win);
87 /* Load Fonts: if none of these are loaded a default font will be used */
88 /* Load Cursor: if you uncomment cursor loading please hide the cursor */
89 struct nk_font_atlas *atlas;
90 nk_sfml_font_stash_begin(&atlas);
91 /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/
92 /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/
93 /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/
94 /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/
95 /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/
96 /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/
97 nk_sfml_font_stash_end();
98 /*nk_style_load_all_cursors(ctx, atlas->cursors);*/
99 /*nk_style_set_font(ctx, &droid->handle);*/
100
101 /* style.c */
102 #ifdef INCLUDE_STYLE
103 /*set_style(ctx, THEME_WHITE);*/
104 /*set_style(ctx, THEME_RED);*/
105 /*set_style(ctx, THEME_BLUE);*/
106 /*set_style(ctx, THEME_DARK);*/
107 #endif
108
109 struct nk_colorf bg;
110 bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
111 while (win.isOpen())
112 {
113 /* Input */
114 sf::Event evt;
115 nk_input_begin(ctx);
116 while(win.pollEvent(evt)) {
117 if(evt.type == sf::Event::Closed)
118 win.close();
119 else if(evt.type == sf::Event::Resized)
120 glViewport(0, 0, evt.size.width, evt.size.height);
121
122 nk_sfml_handle_event(&evt);
123 }
124 nk_input_end(ctx);
125
126 /* GUI */
127 if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
128 NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
129 NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
130 {
131 enum {EASY, HARD};
132 static int op = EASY;
133 static int property = 20;
134 nk_layout_row_static(ctx, 30, 80, 1);
135 if (nk_button_label(ctx, "button"))
136 fprintf(stdout, "button pressed\n");
137
138 nk_layout_row_dynamic(ctx, 30, 2);
139 if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
140 if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
141
142 nk_layout_row_dynamic(ctx, 25, 1);
143 nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
144
145 nk_layout_row_dynamic(ctx, 20, 1);
146 nk_label(ctx, "background:", NK_TEXT_LEFT);
147 nk_layout_row_dynamic(ctx, 25, 1);
148 if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) {
149 nk_layout_row_dynamic(ctx, 120, 1);
150 bg = nk_color_picker(ctx, bg, NK_RGBA);
151 nk_layout_row_dynamic(ctx, 25, 1);
152 bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
153 bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
154 bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
155 bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
156 nk_combo_end(ctx);
157 }
158 }
159 nk_end(ctx);
160
161 /* -------------- EXAMPLES ---------------- */
162 #ifdef INCLUDE_CALCULATOR
163 calculator(ctx);
164 #endif
165 #ifdef INCLUDE_OVERVIEW
166 overview(ctx);
167 #endif
168 #ifdef INCLUDE_NODE_EDITOR
169 node_editor(ctx);
170 #endif
171 /* ----------------------------------------- */
172
173 /* Draw */
174 float bg[4];
175 win.setActive(true);
176 nk_color_fv(bg, background);
177 glClear(GL_COLOR_BUFFER_BIT);
178 glClearColor(bg.r, bg.g, bg.b, bg.a);
179 /* IMPORTANT: `nk_sfml_render` modifies some global OpenGL state
180 * with blending, scissor, face culling and depth test and defaults everything
181 * back into a default state. Make sure to either save and restore or
182 * reset your own state after drawing rendering the UI. */
183 nk_sfml_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
184 win.display();
185 }
186 nk_sfml_shutdown();
187 return 0;
188 }
189
190