Nuklear+
 All Classes Files Functions Enumerations Enumerator Macros Groups Pages
nuklear_cross.h
Go to the documentation of this file.
1 
33 #ifndef NUKLEAR_CROSS_H
34 #define NUKLEAR_CROSS_H
35 
36 #define NKC_SDL 1
37 #define NKC_GLFW 2
38 #define NKC_XLIB 3
39 #define NKC_GDIP 4
40 
41 #define NGL_ES2 20
42 
43 
44 
45 
46 #define NK_INCLUDE_FIXED_TYPES
47 #define NK_INCLUDE_DEFAULT_ALLOCATOR
48 #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
49 #define NK_INCLUDE_FONT_BAKING
50 #define NK_INCLUDE_STANDARD_IO
51 #if !defined(NKC_DISABLE_DEFAULT_FONT)
52  #define NK_INCLUDE_DEFAULT_FONT
53 #endif
54 
55 #if defined(NKC_IMPLEMENTATION) && !defined(NK_IMPLEMENTATION)
56  #define NK_IMPLEMENTATION
57 #endif
58 
59 #include "nuklear.h"
60 
61 
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
73 struct nkc;
74 
81  NKC_WIN_FIXED = 'x',
85 };
86 #define NKC_INITED 1234
89 #define MAX_VERTEX_MEMORY 512 * 1024
90 #define MAX_ELEMENT_MEMORY 128 * 1024
93 #if defined(__EMSCRIPTEN__)
94  /* GL ES systems */
95  #undef NKC_OPENGL_VERSION
96  #define NKC_OPENGL_VERSION NGL_ES2
97 #else
98  #if defined(NKC_USE_OPENGL)
99  #define NKC_OPENGL_VERSION NKC_USE_OPENGL
100  #else
101  #define NKC_OPENGL_VERSION 2
102  #endif
103 #endif
104 
105 #include <stdio.h>
106 #include <string.h>
107 
108 /* Events system */
114 };
115 
117  enum nkc_event_type type;
118  int param;
119 };
120 
122  enum nkc_event_type type;
123  int code;
124  int mod;
125 };
126 union nkc_event {
127  enum nkc_event_type type;
128  struct nkc_window_event window;
129  struct nkc_key_event key;
130 };
131 /* end Events */
132 
133 #if defined(NKCD)
134  #if NKCD==NKC_GDIP
135  #include "nkc_frontend/nkc_gdip.h"
136  #elif NKCD==NKC_SDL
137  #include "nkc_frontend/nkc_sdl.h"
138  #elif NKCD==NKC_GLFW
139  #include "nkc_frontend/nkc_glfw.h"
140  #elif NKCD==NKC_XLIB
141  #include "nkc_frontend/nkc_xlib.h"
142  #endif
143 #else
144  /* if no value defined. Try to choose */
145  #if defined(WIN32) && !defined(__EMSCRIPTEN__)
146  #include "nkc_frontend/nkc_gdip.h"
147  #else
148  /* SDL if not windows */
149  #include "nkc_frontend/nkc_sdl.h"
150  #endif
151 #endif /* Frontend choose */
152 
153 
154 
155 
156 
167 NK_API void* nkc_rdie(const char *fmt, ...);
168 
179 NK_API struct nk_context *nkc_init(struct nkc* nkcHandle, const char* title,
180  int width, int height, enum nkc_window_mode windowMode);
181 
187 NK_API union nkc_event nkc_poll_events(struct nkc* nkcHandle);
188 
190 NK_API struct nk_context* nkc_get_ctx(struct nkc* nkcHandle);
191 
193 NK_API void nkc_shutdown(struct nkc* nkcHandle);
194  /* end of init group */
196 
197 
198 
203 NK_API void nkc_render_bg(struct nkc* nkcHandle, struct nk_color bgColor);
204 NK_API void nkc_render_gui(struct nkc* nkcHandle);
205 
207 NK_API void nkc_render(struct nkc* nkcHandle, struct nk_color bgColor); /* end of render group */
209 
210 
211 
212 
219 NK_API void nkc_style_set_font(struct nkc* nkcHandle, const struct nk_user_font* font);
220 
227 NK_API struct nk_user_font* nkc_load_font_file(struct nkc* nkcHandle, const char* filename, float size,
228  const nk_rune *symbolsRange);
229 NK_API struct nk_user_font* nkc_load_font_memory(struct nkc* nkcHandle, const void* membuf, int membufSize,
230  float size, const nk_rune *symbolsRange);
231 
236 NK_API char nkc_get_key_char(int code); /* end of font group */
238 
239 
240 
241 
246 #if !defined(NKC_DISABLE_IMAGES)
247 NK_API struct nk_image nkc_load_image_file(struct nkc* nkcHandle, const char* filename);
248 NK_API struct nk_image nkc_load_image_memory(struct nkc* nkcHandle, const void* membuf, int membufSize);
249 NK_API void nkc_image_free(struct nk_image* img);
250 #endif /* NKC_DISABLE_IMAGES */
251 
258 NK_API int nkc_get_desktop_size(struct nkc* nkcHandle, int* width, int* height); /* end of image group */
260 
261 
262 
273 NK_API void nkc_set_main_loop(struct nkc* nkcHandle,
274  void (*mainLoopFunc)(void* loopArg), void* loopArg);
276 NK_API void nkc_stop_main_loop(struct nkc* nkcHandle); /* end of mainloop group */
278 
279 
280 
281 
282 
287 #include "nkc_frontend/helpers/nkc_file.h"
288 
290 int nkc_file_exists(const char* filename);
291 
293 size_t nkc_file_size(const char* filename);
294 
300 size_t nkc_stdfile_size(FILE* f);
301 
302 
307 void nkc_mount_write(const char* folder);
308 
310 void nkc_file_pre_read();
311 
313 void nkc_file_post_write();
314  /* end of file group */
316 
317 
318 
319 #if defined(NKC_IMPLEMENTATION)
320 NK_API void nkc_render(struct nkc* nkcHandle, struct nk_color bgColor){
321  nkc_render_bg(nkcHandle, bgColor);
322  nkc_render_gui(nkcHandle);
323 }
324 
325 NK_API struct nk_context* nkc_get_ctx(struct nkc* nkcHandle){
326  return nkcHandle->ctx;
327 }
328 
329 NK_API void nkc_style_set_font(struct nkc* nkcHandle, const struct nk_user_font* font){
330  if(font) nk_style_set_font(nkcHandle->ctx, font);
331 }
332 
333 #if !defined(__EMSCRIPTEN__)
334 NK_API void nkc_set_main_loop(struct nkc* nkcHandle,
335  void (*mainLoopFunc)(void* loopArg), void* loopArg)
336 {
337  nkcHandle->keepRunning = nk_true;
338  while (nkcHandle->keepRunning)
339  mainLoopFunc(loopArg);
340 }
341 
342 NK_API void nkc_stop_main_loop(struct nkc* nkcHandle){
343  nkcHandle->keepRunning = nk_false;
344 }
345 #endif /* __EMSCRIPTEN__ */
346 
347 #endif /* NKC_IMPLEMENTATION */
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 
353 #endif /* NUKLEAR_CROSS_H */
size_t nkc_stdfile_size(FILE *f)
Returns file size in bytes.
Definition: nuklear_cross.h:126
NK_API char nkc_get_key_char(int code)
Converts keyboard code to it's latin character (if have)
Definition: nuklear_cross.h:112
Definition: nuklear_cross.h:82
Definition: nuklear_cross.h:80
size_t nkc_file_size(const char *filename)
nkc_window_mode
Window mode constants, passed to initialization.
Definition: nuklear_cross.h:78
NK_API void nkc_shutdown(struct nkc *nkcHandle)
Finalizing.
NK_API void nkc_style_set_font(struct nkc *nkcHandle, const struct nk_user_font *font)
void nkc_file_pre_read()
NK_API struct nk_context * nkc_get_ctx(struct nkc *nkcHandle)
NK_API void nkc_set_main_loop(struct nkc *nkcHandle, void(*mainLoopFunc)(void *loopArg), void *loopArg)
Starts the 'infinite' main loop. Required for Emscipten only.
nkc_event_type
Definition: nuklear_cross.h:109
Definition: nuklear_cross.h:111
NK_API int nkc_get_desktop_size(struct nkc *nkcHandle, int *width, int *height)
Gets the desktop size in pixels. In browsers - draw area.
NK_API void nkc_stop_main_loop(struct nkc *nkcHandle)
Definition: nuklear_cross.h:83
Definition: nuklear_cross.h:121
Definition: nuklear_cross.h:79
void nkc_file_post_write()
int nkc_file_exists(const char *filename)
NK_API union nkc_event nkc_poll_events(struct nkc *nkcHandle)
Poll window's events in a loop.
void nkc_mount_write(const char *folder)
Mounts local storage folder for writing. Useful for Emscripten only.
NK_API void * nkc_rdie(const char *fmt,...)
Fatal error. Application exit. Die with message. Printf-like.
NK_API struct nk_user_font * nkc_load_font_file(struct nkc *nkcHandle, const char *filename, float size, const nk_rune *symbolsRange)
Load font from TTF-file from disk.
NK_API void nkc_render(struct nkc *nkcHandle, struct nk_color bgColor)
Definition: nuklear_cross.h:110
NK_API struct nk_context * nkc_init(struct nkc *nkcHandle, const char *title, int width, int height, enum nkc_window_mode windowMode)
Initialize the library, create the operation system window.
Definition: nuklear_cross.h:81
Definition: nuklear_cross.h:113
Definition: nuklear_cross.h:116