diff --git a/.gitignore b/.gitignore index 87ff5b2caa..1a100e9fea 100644 --- a/.gitignore +++ b/.gitignore @@ -110,3 +110,5 @@ obj-unix/ /pkg/msvc/msvc-2010/Release Cg/*.obj /pkg/msvc/msvc-2010/Release Cg/*.res /pkg/msvc/msvc-2010/Release Cg/*.pdb + +retroarch.cfg diff --git a/CHANGES.md b/CHANGES.md index 6dc6f06dec..0810405f82 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ - GUI: (XMB) Skip drawing the fading list when it is already transparent. Optimization. - GUI: (XMB) Comment out visible item calculation in xmb_draw_items(). - GUI: (RGUI) Prevent crashes when using a non-English language reliant on UTF8. +- GUI: Add option for OSD background color. - INPUT: Always show the controls menu even if descriptors are not set - INPUT: Fix input descriptors not being set on cores that don't implement the controllers interface - INPUT: Apply descriptors only for the amount of cores the core supports @@ -111,7 +112,7 @@ Skipped this one. - VITA: Add cheevos support - VITA: Add support for external USB if mounted - WAYLAND: Fix menu mouse input -- WII: Add support for single-port 'PS1/PS2 to USB controller adapter' +- WII: Add support for single-port 'PS1/PS2 to USB controller adapter # 1.6.0 - ANDROID: Allow remotes to retain OK/Cancel position when menu_swap_ok_cancel is enabled diff --git a/Makefile.common b/Makefile.common index 8f907f4f83..218a6e89f5 100644 --- a/Makefile.common +++ b/Makefile.common @@ -729,10 +729,7 @@ endif ifeq ($(HAVE_NUKLEAR), 1) OBJ += menu/drivers/nuklear/nk_common.o OBJ += menu/drivers/nuklear/nk_menu.o - OBJ += menu/drivers/nuklear/nk_wnd_main.o - OBJ += menu/drivers/nuklear/nk_wnd_file_picker.o - OBJ += menu/drivers/nuklear/nk_wnd_shader_parameters.o - OBJ += menu/drivers/nuklear/nk_wnd_settings.o + OBJ += menu/drivers/nuklear/nk_wnd_debug.o OBJ += menu/drivers/nuklear.o DEFINES += -DHAVE_NUKLEAR endif diff --git a/config.def.h b/config.def.h index 0054870b1f..7826870ffb 100644 --- a/config.def.h +++ b/config.def.h @@ -375,6 +375,12 @@ static const float message_pos_offset_y = 0.05; * RGB hex value. */ static const uint32_t message_color = 0xffff00; +static const bool message_bgcolor_enable = false; +static const uint32_t message_bgcolor_red = 0; +static const uint32_t message_bgcolor_green = 0; +static const uint32_t message_bgcolor_blue = 0; +static const float message_bgcolor_opacity = 1.0f; + /* Record post-filtered (CPU filter) video, * rather than raw game output. */ static const bool post_filter_record = false; diff --git a/configuration.c b/configuration.c index d1717dfa82..96dad980ba 100644 --- a/configuration.c +++ b/configuration.c @@ -1295,6 +1295,8 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings, SETTING_BOOL("systemfiles_in_content_dir", &settings->bools.systemfiles_in_content_dir, true, default_systemfiles_in_content_dir, false); SETTING_BOOL("screenshots_in_content_dir", &settings->bools.screenshots_in_content_dir, true, default_screenshots_in_content_dir, false); + SETTING_BOOL("video_msg_bgcolor_enable", &settings->bools.video_msg_bgcolor_enable, true, message_bgcolor_enable, false); + if (global) { SETTING_BOOL("custom_bgm_enable", &global->console.sound.system_bgm_enable, true, false, false); @@ -1333,6 +1335,7 @@ static struct config_float_setting *populate_settings_float(settings_t *settings SETTING_FLOAT("fastforward_ratio", &settings->floats.fastforward_ratio, true, fastforward_ratio, false); SETTING_FLOAT("slowmotion_ratio", &settings->floats.slowmotion_ratio, true, slowmotion_ratio, false); SETTING_FLOAT("input_axis_threshold", input_driver_get_float(INPUT_ACTION_AXIS_THRESHOLD), true, axis_threshold, false); + SETTING_FLOAT("video_msg_bgcolor_opacity", &settings->floats.video_msg_bgcolor_opacity, true, message_bgcolor_opacity, false); *size = count; @@ -1408,6 +1411,9 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings, SETTING_UINT("bundle_assets_extract_version_current", &settings->uints.bundle_assets_extract_version_current, true, 0, false); SETTING_UINT("bundle_assets_extract_last_version", &settings->uints.bundle_assets_extract_last_version, true, 0, false); SETTING_UINT("input_overlay_show_physical_inputs_port", &settings->uints.input_overlay_show_physical_inputs_port, true, 0, false); + SETTING_UINT("video_msg_bgcolor_red", &settings->uints.video_msg_bgcolor_red, true, message_bgcolor_red, false); + SETTING_UINT("video_msg_bgcolor_green", &settings->uints.video_msg_bgcolor_green, true, message_bgcolor_green, false); + SETTING_UINT("video_msg_bgcolor_blue", &settings->uints.video_msg_bgcolor_blue, true, message_bgcolor_blue, false); *size = count; diff --git a/configuration.h b/configuration.h index 3e46ffdec9..4c1280833f 100644 --- a/configuration.h +++ b/configuration.h @@ -83,6 +83,7 @@ typedef struct settings bool video_shared_context; bool video_force_srgb_disable; bool video_fps_show; + bool video_msg_bgcolor_enable; /* Audio */ bool audio_enable; @@ -253,6 +254,7 @@ typedef struct settings float video_msg_color_r; float video_msg_color_g; float video_msg_color_b; + float video_msg_bgcolor_opacity; float menu_wallpaper_opacity; float menu_framebuffer_opacity; @@ -321,6 +323,9 @@ typedef struct settings unsigned video_viwidth; unsigned video_aspect_ratio_idx; unsigned video_rotation; + unsigned video_msg_bgcolor_red; + unsigned video_msg_bgcolor_green; + unsigned video_msg_bgcolor_blue; unsigned menu_thumbnails; unsigned menu_dpi_override_value; diff --git a/deps/nuklear/nuklear.h b/deps/nuklear/nuklear.h index f9c7ef5412..261e8dfb6f 100644 --- a/deps/nuklear/nuklear.h +++ b/deps/nuklear/nuklear.h @@ -1,7 +1,7 @@ /* - Nuklear - 1.33.0 - public domain - no warrenty implied; use at your own risk. - authored from 2015-2016 by Micha Mettke + Nuklear - 2.00.0 - public domain + no warranty implied; use at your own risk. + authored from 2015-2017 by Micha Mettke ABOUT: This is a minimal state graphical user interface single header toolkit @@ -17,7 +17,7 @@ VALUES: - Graphical user interface toolkit - Single header library - Written in C89 (a.k.a. ANSI C or ISO C90) - - Small codebase (~17kLOC) + - Small codebase (~18kLOC) - Focus on portability, efficiency and simplicity - No dependencies (not even the standard library if not wanted) - Fully skinnable and customizable @@ -47,7 +47,7 @@ USAGE: or even worse stack corruptions. FEATURES: - - Absolutely no platform dependend code + - Absolutely no platform dependent code - Memory management control ranging from/to - Ease of use by allocating everything from standard library - Control every byte of memory inside the library @@ -108,7 +108,7 @@ OPTIONAL DEFINES: If used needs to be defined for implementation and header NK_INCLUDE_FONT_BAKING - Defining this adds the `stb_truetype` and `stb_rect_pack` implementation + Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it. @@ -128,7 +128,7 @@ OPTIONAL DEFINES: If used needs to be defined for implementation and header NK_BUTTON_TRIGGER_ON_RELEASE - Different platforms require button clicks occuring either on buttons being + Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released. @@ -262,7 +262,6 @@ extern "C" { #ifndef NK_SCROLLBAR_HIDING_TIMEOUT #define NK_SCROLLBAR_HIDING_TIMEOUT 4.0f #endif - /* * ============================================================== * @@ -316,7 +315,6 @@ extern "C" { #define NK_MIN(a,b) ((a) < (b) ? (a) : (b)) #define NK_MAX(a,b) ((a) < (b) ? (b) : (a)) #define NK_CLAMP(i,v,x) (NK_MAX(NK_MIN(v,x), i)) - /* * =============================================================== * @@ -476,7 +474,6 @@ enum nk_color_format {NK_RGB, NK_RGBA}; enum nk_popup_type {NK_POPUP_STATIC, NK_POPUP_DYNAMIC}; enum nk_layout_format {NK_DYNAMIC, NK_STATIC}; enum nk_tree_type {NK_TREE_NODE, NK_TREE_TAB}; -enum nk_anti_aliasing {NK_ANTI_ALIASING_OFF, NK_ANTI_ALIASING_ON}; typedef void*(*nk_plugin_alloc)(nk_handle, void *old, nk_size); typedef void (*nk_plugin_free)(nk_handle, void *old); @@ -489,34 +486,6 @@ struct nk_allocator { nk_plugin_alloc alloc; nk_plugin_free free; }; - -struct nk_draw_null_texture { - nk_handle texture;/* texture handle to a texture with a white pixel */ - struct nk_vec2 uv; /* coordinates to a white pixel in the texture */ -}; -struct nk_convert_config { - float global_alpha; /* global alpha value */ - enum nk_anti_aliasing line_AA; /* line anti-aliasing flag can be turned off if you are tight on memory */ - enum nk_anti_aliasing shape_AA; /* shape anti-aliasing flag can be turned off if you are tight on memory */ - unsigned int circle_segment_count; /* number of segments used for circles: default to 22 */ - unsigned int arc_segment_count; /* number of segments used for arcs: default to 22 */ - unsigned int curve_segment_count; /* number of segments used for curves: default to 22 */ - struct nk_draw_null_texture null; /* handle to texture with a white pixel for shape drawing */ - const struct nk_draw_vertex_layout_element *vertex_layout; /* describes the vertex output format and packing */ - nk_size vertex_size; /* sizeof one vertex for vertex packing */ - nk_size vertex_alignment; /* vertex alignment: Can be optained by NK_ALIGNOF */ -}; - -struct nk_list_view { -/* public: */ - int begin, end, count; -/* private: */ - int total_height; - struct nk_context *ctx; - nk_uint *scroll_pointer; - nk_uint scroll_value; -}; - enum nk_symbol_type { NK_SYMBOL_NONE, NK_SYMBOL_X, @@ -533,7 +502,161 @@ enum nk_symbol_type { NK_SYMBOL_MINUS, NK_SYMBOL_MAX }; - +/* ============================================================================= + * + * CONTEXT + * + * =============================================================================*/ +/* Contexts are the main entry point and the majestro of nuklear and contain all required state. + * They are used for window, memory, input, style, stack, commands and time management and need + * to be passed into all nuklear GUI specific functions. + * + * Usage + * ------------------- + * To use a context it first has to be initialized which can be achieved by calling + * one of either `nk_init_default`, `nk_init_fixed`, `nk_init`, `nk_init_custom`. + * Each takes in a font handle and a specific way of handling memory. Memory control + * hereby ranges from standard library to just specifying a fixed sized block of memory + * which nuklear has to manage itself from. + * + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * [...] + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * + * Reference + * ------------------- + * nk_init_default - Initializes context with standard library memory allocation (malloc,free) + * nk_init_fixed - Initializes context from single fixed size memory block + * nk_init - Initializes context with memory allocator callbacks for alloc and free + * nk_init_custom - Initializes context from two buffers. One for draw commands the other for window/panel/table allocations + * nk_clear - Called at the end of the frame to reset and prepare the context for the next frame + * nk_free - Shutdown and free all memory allocated inside the context + * nk_set_user_data - Utility function to pass user data to draw command + */ +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +/* nk_init_default - Initializes a `nk_context` struct with a default standard library allocator. + * Should be used if you don't want to be bothered with memory management in nuklear. + * Parameters: + * @ctx must point to an either stack or heap allocated `nk_context` struct + * @font must point to a previously initialized font handle for more info look at font documentation + * Return values: + * true(1) on success + * false(0) on failure */ +NK_API int nk_init_default(struct nk_context*, const struct nk_user_font*); +#endif +/* nk_init_fixed - Initializes a `nk_context` struct from a single fixed size memory block + * Should be used if you want complete control over nuklear's memory management. + * Especially recommended for system with little memory or systems with virtual memory. + * For the later case you can just allocate for example 16MB of virtual memory + * and only the required amount of memory will actually be committed. + * IMPORTANT: make sure the passed memory block is aligned correctly for `nk_draw_commands` + * Parameters: + * @ctx must point to an either stack or heap allocated `nk_context` struct + * @memory must point to a previously allocated memory block + * @size must contain the total size of @memory + * @font must point to a previously initialized font handle for more info look at font documentation + * Return values: + * true(1) on success + * false(0) on failure */ +NK_API int nk_init_fixed(struct nk_context*, void *memory, nk_size size, const struct nk_user_font*); +/* nk_init - Initializes a `nk_context` struct with memory allocation callbacks for nuklear to allocate + * memory from. Used internally for `nk_init_default` and provides a kitchen sink allocation + * interface to nuklear. Can be useful for cases like monitoring memory consumption. + * Parameters: + * @ctx must point to an either stack or heap allocated `nk_context` struct + * @alloc must point to a previously allocated memory allocator + * @font must point to a previously initialized font handle for more info look at font documentation + * Return values: + * true(1) on success + * false(0) on failure */ +NK_API int nk_init(struct nk_context*, struct nk_allocator*, const struct nk_user_font*); +/* nk_init_custom - Initializes a `nk_context` struct from two different either fixed or growing + * buffers. The first buffer is for allocating draw commands while the second buffer is + * used for allocating windows, panels and state tables. + * Parameters: + * @ctx must point to an either stack or heap allocated `nk_context` struct + * @cmds must point to a previously initialized memory buffer either fixed or dynamic to store draw commands into + * @pool must point to a previously initialized memory buffer either fixed or dynamic to store windows, panels and tables + * @font must point to a previously initialized font handle for more info look at font documentation + * Return values: + * true(1) on success + * false(0) on failure */ +NK_API int nk_init_custom(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font*); +/* nk_clear - Resets the context state at the end of the frame. This includes mostly + * garbage collector tasks like removing windows or table not called and therefore + * used anymore. + * Parameters: + * @ctx must point to a previously initialized `nk_context` struct */ +NK_API void nk_clear(struct nk_context*); +/* nk_free - Frees all memory allocated by nuklear. Not needed if context was + * initialized with `nk_init_fixed`. + * Parameters: + * @ctx must point to a previously initialized `nk_context` struct */ +NK_API void nk_free(struct nk_context*); +#ifdef NK_INCLUDE_COMMAND_USERDATA +/* nk_set_user_data - Sets the currently passed userdata passed down into each draw command. + * Parameters: + * @ctx must point to a previously initialized `nk_context` struct + * @data handle with either pointer or index to be passed into every draw commands */ +NK_API void nk_set_user_data(struct nk_context*, nk_handle handle); +#endif +/* ============================================================================= + * + * INPUT + * + * =============================================================================*/ +/* The input API is responsible for holding the current input state composed of + * mouse, key and text input states. + * It is worth noting that no direct os or window handling is done in nuklear. + * Instead all input state has to be provided by platform specific code. This in one hand + * expects more work from the user and complicates usage but on the other hand + * provides simple abstraction over a big number of platforms, libraries and other + * already provided functionality. + * + * Usage + * ------------------- + * Input state needs to be provided to nuklear by first calling `nk_input_begin` + * which resets internal state like delta mouse position and button transistions. + * After `nk_input_begin` all current input state needs to be provided. This includes + * mouse motion, button and key pressed and released, text input and scrolling. + * Both event- or state-based input handling are supported by this API + * and should work without problems. Finally after all input state has been + * mirrored `nk_input_end` needs to be called to finish input process. + * + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * Event evt; + * nk_input_begin(&ctx); + * while (GetEvent(&evt)) { + * if (evt.type == MOUSE_MOVE) + * nk_input_motion(&ctx, evt.motion.x, evt.motion.y); + * else if (evt.type == ...) { + * ... + * } + * } + * nk_input_end(&ctx); + * [...] + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * + * Reference + * ------------------- + * nk_input_begin - Begins the input mirroring process. Needs to be called before all other `nk_input_xxx` calls + * nk_input_motion - Mirrors mouse cursor position + * nk_input_key - Mirrors key state with either pressed or released + * nk_input_button - Mirrors mouse button state with either pressed or released + * nk_input_scroll - Mirrors mouse scroll values + * nk_input_char - Adds a single ASCII text character into an internal text buffer + * nk_input_glyph - Adds a single multi-byte UTF-8 character into an internal text buffer + * nk_input_unicode - Adds a single unicode rune into an internal text buffer + * nk_input_end - Ends the input mirroring process by calculating state changes. Don't call any `nk_input_xxx` function referenced above after this call + */ enum nk_keys { NK_KEY_NONE, NK_KEY_SHIFT, @@ -549,7 +672,6 @@ enum nk_keys { NK_KEY_DOWN, NK_KEY_LEFT, NK_KEY_RIGHT, - /* Shortcuts: text field */ NK_KEY_TEXT_INSERT_MODE, NK_KEY_TEXT_REPLACE_MODE, @@ -563,23 +685,1457 @@ enum nk_keys { NK_KEY_TEXT_SELECT_ALL, NK_KEY_TEXT_WORD_LEFT, NK_KEY_TEXT_WORD_RIGHT, - /* Shortcuts: scrollbar */ NK_KEY_SCROLL_START, NK_KEY_SCROLL_END, NK_KEY_SCROLL_DOWN, NK_KEY_SCROLL_UP, - NK_KEY_MAX }; - enum nk_buttons { NK_BUTTON_LEFT, NK_BUTTON_MIDDLE, NK_BUTTON_RIGHT, + NK_BUTTON_DOUBLE, NK_BUTTON_MAX }; +/* nk_input_begin - Begins the input mirroring process by resetting text, scroll + * mouse previous mouse position and movement as well as key state transitions, + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct */ +NK_API void nk_input_begin(struct nk_context*); +/* nk_input_motion - Mirrors current mouse position to nuklear + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @x must contain an integer describing the current mouse cursor x-position + * @y must contain an integer describing the current mouse cursor y-position */ +NK_API void nk_input_motion(struct nk_context*, int x, int y); +/* nk_input_key - Mirrors state of a specific key to nuklear + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @key must be any value specified in enum `nk_keys` that needs to be mirrored + * @down must be 0 for key is up and 1 for key is down */ +NK_API void nk_input_key(struct nk_context*, enum nk_keys, int down); +/* nk_input_button - Mirrors the state of a specific mouse button to nuklear + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @nk_buttons must be any value specified in enum `nk_buttons` that needs to be mirrored + * @x must contain an integer describing mouse cursor x-position on click up/down + * @y must contain an integer describing mouse cursor y-position on click up/down + * @down must be 0 for key is up and 1 for key is down */ +NK_API void nk_input_button(struct nk_context*, enum nk_buttons, int x, int y, int down); +/* nk_input_scroll - Copies the last mouse scroll value to nuklear. Is generally + * a scroll value. So does not have to come from mouse and could also originate + * from touch for example. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @val vector with both X- as well as Y-scroll value */ +NK_API void nk_input_scroll(struct nk_context*, struct nk_vec2 val); +/* nk_input_char - Copies a single ASCII character into an internal text buffer + * This is basically a helper function to quickly push ASCII characters into + * nuklear. Note that you can only push up to NK_INPUT_MAX bytes into + * struct `nk_input` between `nk_input_begin` and `nk_input_end`. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @c must be a single ASCII character preferable one that can be printed */ +NK_API void nk_input_char(struct nk_context*, char); +/* nk_input_unicode - Converts a encoded unicode rune into UTF-8 and copies the result + * into an internal text buffer. + * Note that you can only push up to NK_INPUT_MAX bytes into + * struct `nk_input` between `nk_input_begin` and `nk_input_end`. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @glyph UTF-32 unicode codepoint */ +NK_API void nk_input_glyph(struct nk_context*, const nk_glyph); +/* nk_input_unicode - Converts a unicode rune into UTF-8 and copies the result + * into an internal text buffer. + * Note that you can only push up to NK_INPUT_MAX bytes into + * struct `nk_input` between `nk_input_begin` and `nk_input_end`. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @glyph UTF-32 unicode codepoint */ +NK_API void nk_input_unicode(struct nk_context*, nk_rune); +/* nk_input_end - End the input mirroring process by resetting mouse grabbing + * state to ensure the mouse cursor is not grabbed indefinitely. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct */ +NK_API void nk_input_end(struct nk_context*); +/* ============================================================================= + * + * DRAWING + * + * =============================================================================*/ +/* This library was designed to be render backend agnostic so it does + * not draw anything to screen directly. Instead all drawn shapes, widgets + * are made of, are buffered into memory and make up a command queue. + * Each frame therefore fills the command buffer with draw commands + * that then need to be executed by the user and his own render backend. + * After that the command buffer needs to be cleared and a new frame can be + * started. It is probably important to note that the command buffer is the main + * drawing API and the optional vertex buffer API only takes this format and + * converts it into a hardware accessible format. + * + * Usage + * ------------------- + * To draw all draw commands accumulated over a frame you need your own render + * backend able to draw a number of 2D primitives. This includes at least + * filled and stroked rectangles, circles, text, lines, triangles and scissors. + * As soon as this criterion is met you can iterate over each draw command + * and execute each draw command in a interpreter like fashion: + * + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * [...] + * } + * + * In program flow context draw commands need to be executed after input has been + * gathered and the complete UI with windows and their contained widgets have + * been executed and before calling `nk_clear` which frees all previously + * allocated draw commands. + * + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * Event evt; + * nk_input_begin(&ctx); + * while (GetEvent(&evt)) { + * if (evt.type == MOUSE_MOVE) + * nk_input_motion(&ctx, evt.motion.x, evt.motion.y); + * else if (evt.type == [...]) { + * [...] + * } + * } + * nk_input_end(&ctx); + * + * [...] + * + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * [...] + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * + * You probably noticed that you have to draw all of the UI each frame which is + * quite wasteful. While the actual UI updating loop is quite fast rendering + * without actually needing it is not. So there are multiple things you could do. + * + * First is only update on input. This of course is only an option if your + * application only depends on the UI and does not require any outside calculations. + * If you actually only update on input make sure to update the UI two times each + * frame and call `nk_clear` directly after the first pass and only draw in + * the second pass. In addition it is recommended to also add additional timers + * to make sure the UI is not drawn more than a fixed number of frames per second. + * + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * [...wait for input ] + * + * [...do two UI passes ...] + * do_ui(...) + * nk_clear(&ctx); + * do_ui(...) + * + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * [...] + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * + * The second probably more applicable trick is to only draw if anything changed. + * It is not really useful for applications with continuous draw loop but + * quite useful for desktop applications. To actually get nuklear to only + * draw on changes you first have to define `NK_ZERO_COMMAND_MEMORY` and + * allocate a memory buffer that will store each unique drawing output. + * After each frame you compare the draw command memory inside the library + * with your allocated buffer by memcmp. If memcmp detects differences + * you have to copy the command buffer into the allocated buffer + * and then draw like usual (this example uses fixed memory but you could + * use dynamically allocated memory). + * + * [... other defines ...] + * #define NK_ZERO_COMMAND_MEMORY + * #include "nuklear.h" + * + * struct nk_context ctx; + * void *last = calloc(1,64*1024); + * void *buf = calloc(1,64*1024); + * nk_init_fixed(&ctx, buf, 64*1024); + * while (1) { + * [...input...] + * [...ui...] + * + * void *cmds = nk_buffer_memory(&ctx.memory); + * if (memcmp(cmds, last, ctx.memory.allocated)) { + * memcpy(last,cmds,ctx.memory.allocated); + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * [...] + * } + * } + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * + * Finally while using draw commands makes sense for higher abstracted platforms like + * X11 and Win32 or drawing libraries it is often desirable to use graphics + * hardware directly. Therefore it is possible to just define + * `NK_INCLUDE_VERTEX_BUFFER_OUTPUT` which includes optional vertex output. + * To access the vertex output you first have to convert all draw commands into + * vertexes by calling `nk_convert` which takes in your preferred vertex format. + * After successfully converting all draw commands just iterate over and execute all + * vertex draw commands: + * + * struct nk_convert_config cfg = {}; + * static const struct nk_draw_vertex_layout_element vertex_layout[] = { + * {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, pos)}, + * {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, uv)}, + * {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct your_vertex, col)}, + * {NK_VERTEX_LAYOUT_END} + * }; + * cfg.shape_AA = NK_ANTI_ALIASING_ON; + * cfg.line_AA = NK_ANTI_ALIASING_ON; + * cfg.vertex_layout = vertex_layout; + * cfg.vertex_size = sizeof(struct your_vertex); + * cfg.vertex_alignment = NK_ALIGNOF(struct your_vertex); + * cfg.circle_segment_count = 22; + * cfg.curve_segment_count = 22; + * cfg.arc_segment_count = 22; + * cfg.global_alpha = 1.0f; + * cfg.null = dev->null; + * + * struct nk_buffer cmds, verts, idx; + * nk_buffer_init_default(&cmds); + * nk_buffer_init_default(&verts); + * nk_buffer_init_default(&idx); + * nk_convert(&ctx, &cmds, &verts, &idx, &cfg); + * nk_draw_foreach(cmd, &ctx, &cmds) { + * if (!cmd->elem_count) continue; + * [...] + * } + * nk_buffer_free(&cms); + * nk_buffer_free(&verts); + * nk_buffer_free(&idx); + * + * Reference + * ------------------- + * nk__begin - Returns the first draw command in the context draw command list to be drawn + * nk__next - Increments the draw command iterator to the next command inside the context draw command list + * nk_foreach - Iterates over each draw command inside the context draw command list + * + * nk_convert - Converts from the abstract draw commands list into a hardware accessible vertex format + * nk__draw_begin - Returns the first vertex command in the context vertex draw list to be executed + * nk__draw_next - Increments the vertex command iterator to the next command inside the context vertex command list + * nk__draw_end - Returns the end of the vertex draw list + * nk_draw_foreach - Iterates over each vertex draw command inside the vertex draw list + */ +enum nk_anti_aliasing {NK_ANTI_ALIASING_OFF, NK_ANTI_ALIASING_ON}; +enum nk_convert_result { + NK_CONVERT_SUCCESS = 0, + NK_CONVERT_INVALID_PARAM = 1, + NK_CONVERT_COMMAND_BUFFER_FULL = NK_FLAG(1), + NK_CONVERT_VERTEX_BUFFER_FULL = NK_FLAG(2), + NK_CONVERT_ELEMENT_BUFFER_FULL = NK_FLAG(3) +}; +struct nk_draw_null_texture { + nk_handle texture; /* texture handle to a texture with a white pixel */ + struct nk_vec2 uv; /* coordinates to a white pixel in the texture */ +}; +struct nk_convert_config { + float global_alpha; /* global alpha value */ + enum nk_anti_aliasing line_AA; /* line anti-aliasing flag can be turned off if you are tight on memory */ + enum nk_anti_aliasing shape_AA; /* shape anti-aliasing flag can be turned off if you are tight on memory */ + unsigned circle_segment_count; /* number of segments used for circles: default to 22 */ + unsigned arc_segment_count; /* number of segments used for arcs: default to 22 */ + unsigned curve_segment_count; /* number of segments used for curves: default to 22 */ + struct nk_draw_null_texture null; /* handle to texture with a white pixel for shape drawing */ + const struct nk_draw_vertex_layout_element *vertex_layout; /* describes the vertex output format and packing */ + nk_size vertex_size; /* sizeof one vertex for vertex packing */ + nk_size vertex_alignment; /* vertex alignment: Can be obtained by NK_ALIGNOF */ +}; +/* nk__begin - Returns a draw command list iterator to iterate all draw + * commands accumulated over one frame. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct at the end of a frame + * Return values: + * draw command pointer pointing to the first command inside the draw command list */ +NK_API const struct nk_command* nk__begin(struct nk_context*); +/* nk__next - Returns a draw command list iterator to iterate all draw + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct at the end of a frame + * @cmd must point to an previously a draw command either returned by `nk__begin` or `nk__next` + * Return values: + * draw command pointer pointing to the next command inside the draw command list */ +NK_API const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); +/* nk_foreach - Iterates over each draw command inside the context draw command list + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct at the end of a frame + * @cmd pointer initialized to NULL */ +#define nk_foreach(c, ctx) for((c) = nk__begin(ctx); (c) != 0; (c) = nk__next(ctx,c)) +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT +/* nk_convert - converts all internal draw command into vertex draw commands and fills + * three buffers with vertexes, vertex draw commands and vertex indices. The vertex format + * as well as some other configuration values have to be configured by filling out a + * `nk_convert_config` struct. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct at the end of a frame + * @cmds must point to a previously initialized buffer to hold converted vertex draw commands + * @vertices must point to a previously initialized buffer to hold all produced vertices + * @elements must point to a previously initialized buffer to hold all produced vertex indices + * @config must point to a filled out `nk_config` struct to configure the conversion process + * Returns: + * returns NK_CONVERT_SUCCESS on success and a enum nk_convert_result error values if not */ +NK_API nk_flags nk_convert(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); +/* nk__draw_begin - Returns a draw vertex command buffer iterator to iterate each the vertex draw command buffer + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct at the end of a frame + * @buf must point to an previously by `nk_convert` filled out vertex draw command buffer + * Return values: + * vertex draw command pointer pointing to the first command inside the vertex draw command buffer */ +NK_API const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); +/* nk__draw_end - Returns the vertex draw command at the end of the vertex draw command buffer + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct at the end of a frame + * @buf must point to an previously by `nk_convert` filled out vertex draw command buffer + * Return values: + * vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer */ +NK_API const struct nk_draw_command* nk__draw_end(const struct nk_context*, const struct nk_buffer*); +/* nk__draw_next - Increments the vertex draw command buffer iterator + * Parameters: + * @cmd must point to an previously either by `nk__draw_begin` or `nk__draw_next` returned vertex draw command + * @buf must point to an previously by `nk_convert` filled out vertex draw command buffer + * @ctx must point to an previously initialized `nk_context` struct at the end of a frame + * Return values: + * vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer */ +NK_API const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*); +/* nk_draw_foreach - Iterates over each vertex draw command inside a vertex draw command buffer + * Parameters: + * @cmd nk_draw_command pointer set to NULL + * @buf must point to an previously by `nk_convert` filled out vertex draw command buffer + * @ctx must point to an previously initialized `nk_context` struct at the end of a frame */ +#define nk_draw_foreach(cmd,ctx, b) for((cmd)=nk__draw_begin(ctx, b); (cmd)!=0; (cmd)=nk__draw_next(cmd, b, ctx)) +#endif +/* ============================================================================= + * + * WINDOW + * + * ============================================================================= + * Windows are the main persistent state used inside nuklear and are life time + * controlled by simply "retouching" (i.e. calling) each window each frame. + * All widgets inside nuklear can only be added inside function pair `nk_begin_xxx` + * and `nk_end`. Calling any widgets outside these two functions will result in an + * assert in debug or no state change in release mode. + * + * Each window holds frame persistent state like position, size, flags, state tables, + * and some garbage collected internal persistent widget state. Each window + * is linked into a window stack list which determines the drawing and overlapping + * order. The topmost window thereby is the currently active window. + * + * To change window position inside the stack occurs either automatically by + * user input by being clicked on or programmatically by calling `nk_window_focus`. + * Windows by default are visible unless explicitly being defined with flag + * `NK_WINDOW_HIDDEN`, the user clicked the close button on windows with flag + * `NK_WINDOW_CLOSABLE` or if a window was explicitly hidden by calling + * `nk_window_show`. To explicitly close and destroy a window call `nk_window_close`. + * + * Usage + * ------------------- + * To create and keep a window you have to call one of the two `nk_begin_xxx` + * functions to start window declarations and `nk_end` at the end. Furthermore it + * is recommended to check the return value of `nk_begin_xxx` and only process + * widgets inside the window if the value is not 0. Either way you have to call + * `nk_end` at the end of window declarations. Furthermore, do not attempt to + * nest `nk_begin_xxx` calls which will hopefully result in an assert or if not + * in a segmentation fault. + * + * if (nk_begin_xxx(...) { + * [... widgets ...] + * } + * nk_end(ctx); + * + * In the grand concept window and widget declarations need to occur after input + * handling and before drawing to screen. Not doing so can result in higher + * latency or at worst invalid behavior. Furthermore make sure that `nk_clear` + * is called at the end of the frame. While nuklear's default platform backends + * already call `nk_clear` for you if you write your own backend not calling + * `nk_clear` can cause asserts or even worse undefined behavior. + * + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * Event evt; + * nk_input_begin(&ctx); + * while (GetEvent(&evt)) { + * if (evt.type == MOUSE_MOVE) + * nk_input_motion(&ctx, evt.motion.x, evt.motion.y); + * else if (evt.type == [...]) { + * nk_input_xxx(...); + * } + * } + * nk_input_end(&ctx); + * + * if (nk_begin_xxx(...) { + * [...] + * } + * nk_end(ctx); + * + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * [...] + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * + * Reference + * ------------------- + * nk_begin - starts a new window; needs to be called every frame for every window (unless hidden) or otherwise the window gets removed + * nk_begin_titled - extended window start with separated title and identifier to allow multiple windows with same name but not title + * nk_end - needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup + * + * nk_window_find - finds and returns the window with give name + * nk_window_get_bounds - returns a rectangle with screen position and size of the currently processed window. + * nk_window_get_position - returns the position of the currently processed window + * nk_window_get_size - returns the size with width and height of the currently processed window + * nk_window_get_width - returns the width of the currently processed window + * nk_window_get_height - returns the height of the currently processed window + * nk_window_get_panel - returns the underlying panel which contains all processing state of the current window + * nk_window_get_content_region - returns the position and size of the currently visible and non-clipped space inside the currently processed window + * nk_window_get_content_region_min - returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window + * nk_window_get_content_region_max - returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window + * nk_window_get_content_region_size - returns the size of the currently visible and non-clipped space inside the currently processed window + * nk_window_get_canvas - returns the draw command buffer. Can be used to draw custom widgets + * + * nk_window_has_focus - returns if the currently processed window is currently active + * nk_window_is_collapsed - returns if the window with given name is currently minimized/collapsed + * nk_window_is_closed - returns if the currently processed window was closed + * nk_window_is_hidden - returns if the currently processed window was hidden + * nk_window_is_active - same as nk_window_has_focus for some reason + * nk_window_is_hovered - returns if the currently processed window is currently being hovered by mouse + * nk_window_is_any_hovered - return if any window currently hovered + * nk_item_is_any_active - returns if any window or widgets is currently hovered or active + * + * nk_window_set_bounds - updates position and size of the currently processed window + * nk_window_set_position - updates position of the currently process window + * nk_window_set_size - updates the size of the currently processed window + * nk_window_set_focus - set the currently processed window as active window + * + * nk_window_close - closes the window with given window name which deletes the window at the end of the frame + * nk_window_collapse - collapses the window with given window name + * nk_window_collapse_if - collapses the window with given window name if the given condition was met + * nk_window_show - hides a visible or reshows a hidden window + * nk_window_show_if - hides/shows a window depending on condition + */ +enum nk_panel_flags { + NK_WINDOW_BORDER = NK_FLAG(0), /* Draws a border around the window to visually separate window from the background */ + NK_WINDOW_MOVABLE = NK_FLAG(1), /* The movable flag indicates that a window can be moved by user input or by dragging the window header */ + NK_WINDOW_SCALABLE = NK_FLAG(2), /* The scalable flag indicates that a window can be scaled by user input by dragging a scaler icon at the button of the window */ + NK_WINDOW_CLOSABLE = NK_FLAG(3), /* adds a closable icon into the header */ + NK_WINDOW_MINIMIZABLE = NK_FLAG(4), /* adds a minimize icon into the header */ + NK_WINDOW_NO_SCROLLBAR = NK_FLAG(5), /* Removes the scrollbar from the window */ + NK_WINDOW_TITLE = NK_FLAG(6), /* Forces a header at the top at the window showing the title */ + NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(7), /* Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame */ + NK_WINDOW_BACKGROUND = NK_FLAG(8), /* Always keep window in the background */ + NK_WINDOW_SCALE_LEFT = NK_FLAG(9), /* Puts window scaler in the left-ottom corner instead right-bottom*/ + NK_WINDOW_NO_INPUT = NK_FLAG(10) /* Prevents window of scaling, moving or getting focus */ +}; +/* nk_begin - starts a new window; needs to be called every frame for every window (unless hidden) or otherwise the window gets removed + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @title window title and identifier. Needs to be persistent over frames to identify the window + * @bounds initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame + * @flags window flags defined in `enum nk_panel_flags` with a number of different window behaviors + * Return values: + * returns 1 if the window can be filled up with widgets from this point until `nk_end or 0 otherwise for example if minimized `*/ +NK_API int nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); +/* nk_begin_titled - extended window start with separated title and identifier to allow multiple windows with same name but not title + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name window identifier. Needs to be persistent over frames to identify the window + * @title window title displayed inside header if flag `NK_WINDOW_TITLE` or either `NK_WINDOW_CLOSABLE` or `NK_WINDOW_MINIMIZED` was set + * @bounds initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame + * @flags window flags defined in `enum nk_panel_flags` with a number of different window behaviors + * Return values: + * returns 1 if the window can be filled up with widgets from this point until `nk_end or 0 otherwise `*/ +NK_API int nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); +/* nk_end - needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup. + * All widget calls after this functions will result in asserts or no state changes + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct */ +NK_API void nk_end(struct nk_context *ctx); +/* nk_window_find - finds and returns the window with give name + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name window identifier + * Return values: + * returns a `nk_window` struct pointing to the identified window or 0 if no window with given name was found */ +NK_API struct nk_window *nk_window_find(struct nk_context *ctx, const char *name); +/* nk_window_get_bounds - returns a rectangle with screen position and size of the currently processed window. + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns a `nk_rect` struct with window upper left position and size */ +NK_API struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); +/* nk_window_get_position - returns the position of the currently processed window. + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns a `nk_vec2` struct with window upper left position */ +NK_API struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); +/* nk_window_get_size - returns the size with width and height of the currently processed window. + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns a `nk_vec2` struct with window size */ +NK_API struct nk_vec2 nk_window_get_size(const struct nk_context*); +/* nk_window_get_width - returns the width of the currently processed window. + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns the window width */ +NK_API float nk_window_get_width(const struct nk_context*); +/* nk_window_get_height - returns the height of the currently processed window. + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns the window height */ +NK_API float nk_window_get_height(const struct nk_context*); +/* nk_window_get_panel - returns the underlying panel which contains all processing state of the current window. + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns a pointer to window internal `nk_panel` state. DO NOT keep this pointer around it is only valid until `nk_end` */ +NK_API struct nk_panel* nk_window_get_panel(struct nk_context*); +/* nk_window_get_content_region - returns the position and size of the currently visible and non-clipped space inside the currently processed window. + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns `nk_rect` struct with screen position and size (no scrollbar offset) of the visible space inside the current window */ +NK_API struct nk_rect nk_window_get_content_region(struct nk_context*); +/* nk_window_get_content_region_min - returns the upper left position of the currently visible and non-clipped space inside the currently processed window. + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns `nk_vec2` struct with upper left screen position (no scrollbar offset) of the visible space inside the current window */ +NK_API struct nk_vec2 nk_window_get_content_region_min(struct nk_context*); +/* nk_window_get_content_region_max - returns the lower right screen position of the currently visible and non-clipped space inside the currently processed window. + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns `nk_vec2` struct with lower right screen position (no scrollbar offset) of the visible space inside the current window */ +NK_API struct nk_vec2 nk_window_get_content_region_max(struct nk_context*); +/* nk_window_get_content_region_size - returns the size of the currently visible and non-clipped space inside the currently processed window + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns `nk_vec2` struct with size the visible space inside the current window */ +NK_API struct nk_vec2 nk_window_get_content_region_size(struct nk_context*); +/* nk_window_get_canvas - returns the draw command buffer. Can be used to draw custom widgets + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns a pointer to window internal `nk_command_buffer` struct used as drawing canvas. Can be used to do custom drawing */ +NK_API struct nk_command_buffer* nk_window_get_canvas(struct nk_context*); +/* nk_window_has_focus - returns if the currently processed window is currently active + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns 0 if current window is not active or 1 if it is */ +NK_API int nk_window_has_focus(const struct nk_context*); +/* nk_window_is_collapsed - returns if the window with given name is currently minimized/collapsed + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of window you want to check is collapsed + * Return values: + * returns 1 if current window is minimized and 0 if window not found or is not minimized */ +NK_API int nk_window_is_collapsed(struct nk_context *ctx, const char *name); +/* nk_window_is_closed - returns if the window with given name was closed by calling `nk_close` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of window you want to check is closed + * Return values: + * returns 1 if current window was closed or 0 window not found or not closed */ +NK_API int nk_window_is_closed(struct nk_context*, const char*); +/* nk_window_is_hidden - returns if the window with given name is hidden + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of window you want to check is hidden + * Return values: + * returns 1 if current window is hidden or 0 window not found or visible */ +NK_API int nk_window_is_hidden(struct nk_context*, const char*); +/* nk_window_is_active - same as nk_window_has_focus for some reason + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of window you want to check is hidden + * Return values: + * returns 1 if current window is active or 0 window not found or not active */ +NK_API int nk_window_is_active(struct nk_context*, const char*); +/* nk_window_is_hovered - return if the current window is being hovered + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns 1 if current window is hovered or 0 otherwise */ +NK_API int nk_window_is_hovered(struct nk_context*); +/* nk_window_is_any_hovered - returns if the any window is being hovered + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns 1 if any window is hovered or 0 otherwise */ +NK_API int nk_window_is_any_hovered(struct nk_context*); +/* nk_item_is_any_active - returns if the any window is being hovered or any widget is currently active. + * Can be used to decide if input should be processed by UI or your specific input handling. + * Example could be UI and 3D camera to move inside a 3D space. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * Return values: + * returns 1 if any window is hovered or any item is active or 0 otherwise */ +NK_API int nk_item_is_any_active(struct nk_context*); +/* nk_window_set_bounds - updates position and size of the currently processed window + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of the window to modify both position and size + * @bounds points to a `nk_rect` struct with the new position and size of currently active window */ +NK_API void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds); +/* nk_window_set_position - updates position of the currently processed window + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of the window to modify position of + * @pos points to a `nk_vec2` struct with the new position of currently active window */ +NK_API void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos); +/* nk_window_set_size - updates size of the currently processed window + * IMPORTANT: only call this function between calls `nk_begin_xxx` and `nk_end` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of the window to modify size of + * @size points to a `nk_vec2` struct with the new size of currently active window */ +NK_API void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2); +/* nk_window_set_focus - sets the window with given name as active + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of the window to be set active */ +NK_API void nk_window_set_focus(struct nk_context*, const char *name); +/* nk_window_close - closed a window and marks it for being freed at the end of the frame + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of the window to be closed */ +NK_API void nk_window_close(struct nk_context *ctx, const char *name); +/* nk_window_collapse - updates collapse state of a window with given name + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of the window to be either collapse or maximize */ +NK_API void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state); +/* nk_window_collapse - updates collapse state of a window with given name if given condition is met + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of the window to be either collapse or maximize + * @state the window should be put into + * @condition that has to be true to actually commit the collapse state change */ +NK_API void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond); +/* nk_window_show - updates visibility state of a window with given name + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of the window to be either collapse or maximize + * @state with either visible or hidden to modify the window with */ +NK_API void nk_window_show(struct nk_context*, const char *name, enum nk_show_states); +/* nk_window_show_if - updates visibility state of a window with given name if a given condition is met + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @name of the window to be either collapse or maximize + * @state with either visible or hidden to modify the window with + * @condition that has to be true to actually commit the visible state change */ +NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); +/* ============================================================================= + * + * LAYOUT + * + * ============================================================================= */ +/* Layouting in general describes placing widget inside a window with position and size. + * While in this particular implementation there are five different APIs for layouting + * each with different trade offs between control and ease of use. + * + * All layouting methods in this library are based around the concept of a row. + * A row has a height the window content grows by and a number of columns and each + * layouting method specifies how each widget is placed inside the row. + * After a row has been allocated by calling a layouting functions and then + * filled with widgets will advance an internal pointer over the allocated row. + * + * To actually define a layout you just call the appropriate layouting function + * and each subsequent widget call will place the widget as specified. Important + * here is that if you define more widgets then columns defined inside the layout + * functions it will allocate the next row without you having to make another layouting + * call. + * + * Biggest limitation with using all these APIs outside the `nk_layout_space_xxx` API + * is that you have to define the row height for each. However the row height + * often depends on the height of the font. + * + * To fix that internally nuklear uses a minimum row height that is set to the + * height plus padding of currently active font and overwrites the row height + * value if zero. + * + * If you manually want to change the minimum row height then + * use nk_layout_set_min_row_height, and use nk_layout_reset_min_row_height to + * reset it back to be derived from font height. + * + * Also if you change the font in nuklear it will automatically change the minimum + * row height for you and. This means if you change the font but still want + * a minimum row height smaller than the font you have to repush your value. + * + * For actually more advanced UI I would even recommend using the `nk_layout_space_xxx` + * layouting method in combination with a cassowary constraint solver (there are + * some versions on github with permissive license model) to take over all control over widget + * layouting yourself. However for quick and dirty layouting using all the other layouting + * functions should be fine. + * + * Usage + * ------------------- + * 1.) nk_layout_row_dynamic + * The easiest layouting function is `nk_layout_row_dynamic`. It provides each + * widgets with same horizontal space inside the row and dynamically grows + * if the owning window grows in width. So the number of columns dictates + * the size of each widget dynamically by formula: + * + * widget_width = (window_width - padding - spacing) * (1/colum_count) + * + * Just like all other layouting APIs if you define more widget than columns this + * library will allocate a new row and keep all layouting parameters previously + * defined. + * + * if (nk_begin_xxx(...) { + * // first row with height: 30 composed of two widgets + * nk_layout_row_dynamic(&ctx, 30, 2); + * nk_widget(...); + * nk_widget(...); + * + * // second row with same parameter as defined above + * nk_widget(...); + * nk_widget(...); + * + * // third row uses 0 for height which will use auto layouting + * nk_layout_row_dynamic(&ctx, 0, 2); + * nk_widget(...); + * nk_widget(...); + * } + * nk_end(...); + * + * 2.) nk_layout_row_static + * Another easy layouting function is `nk_layout_row_static`. It provides each + * widget with same horizontal pixel width inside the row and does not grow + * if the owning window scales smaller or bigger. + * + * if (nk_begin_xxx(...) { + * // first row with height: 30 composed of two widgets with width: 80 + * nk_layout_row_static(&ctx, 30, 80, 2); + * nk_widget(...); + * nk_widget(...); + * + * // second row with same parameter as defined above + * nk_widget(...); + * nk_widget(...); + * + * // third row uses 0 for height which will use auto layouting + * nk_layout_row_static(&ctx, 0, 80, 2); + * nk_widget(...); + * nk_widget(...); + * } + * nk_end(...); + * + * 3.) nk_layout_row_xxx + * A little bit more advanced layouting API are functions `nk_layout_row_begin`, + * `nk_layout_row_push` and `nk_layout_row_end`. They allow to directly + * specify each column pixel or window ratio in a row. It supports either + * directly setting per column pixel width or widget window ratio but not + * both. Furthermore it is a immediate mode API so each value is directly + * pushed before calling a widget. Therefore the layout is not automatically + * repeating like the last two layouting functions. + * + * if (nk_begin_xxx(...) { + * // first row with height: 25 composed of two widgets with width 60 and 40 + * nk_layout_row_begin(ctx, NK_STATIC, 25, 2); + * nk_layout_row_push(ctx, 60); + * nk_widget(...); + * nk_layout_row_push(ctx, 40); + * nk_widget(...); + * nk_layout_row_end(ctx); + * + * // second row with height: 25 composed of two widgets with window ratio 0.25 and 0.75 + * nk_layout_row_begin(ctx, NK_DYNAMIC, 25, 2); + * nk_layout_row_push(ctx, 0.25f); + * nk_widget(...); + * nk_layout_row_push(ctx, 0.75f); + * nk_widget(...); + * nk_layout_row_end(ctx); + * + * // third row with auto generated height: composed of two widgets with window ratio 0.25 and 0.75 + * nk_layout_row_begin(ctx, NK_DYNAMIC, 0, 2); + * nk_layout_row_push(ctx, 0.25f); + * nk_widget(...); + * nk_layout_row_push(ctx, 0.75f); + * nk_widget(...); + * nk_layout_row_end(ctx); + * } + * nk_end(...); + * + * 4.) nk_layout_row + * The array counterpart to API nk_layout_row_xxx is the single nk_layout_row + * functions. Instead of pushing either pixel or window ratio for every widget + * it allows to define it by array. The trade of for less control is that + * `nk_layout_row` is automatically repeating. Otherwise the behavior is the + * same. + * + * if (nk_begin_xxx(...) { + * // two rows with height: 30 composed of two widgets with width 60 and 40 + * const float size[] = {60,40}; + * nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * + * // two rows with height: 30 composed of two widgets with window ratio 0.25 and 0.75 + * const float ratio[] = {0.25, 0.75}; + * nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * + * // two rows with auto generated height composed of two widgets with window ratio 0.25 and 0.75 + * const float ratio[] = {0.25, 0.75}; + * nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * } + * nk_end(...); + * + * 5.) nk_layout_row_template_xxx + * The most complex and second most flexible API is a simplified flexbox version without + * line wrapping and weights for dynamic widgets. It is an immediate mode API but + * unlike `nk_layout_row_xxx` it has auto repeat behavior and needs to be called + * before calling the templated widgets. + * The row template layout has three different per widget size specifier. The first + * one is the static widget size specifier with fixed widget pixel width. They do + * not grow if the row grows and will always stay the same. The second size + * specifier is nk_layout_row_template_push_variable which defines a + * minimum widget size but it also can grow if more space is available not taken + * by other widgets. Finally there are dynamic widgets which are completely flexible + * and unlike variable widgets can even shrink to zero if not enough space + * is provided. + * + * if (nk_begin_xxx(...) { + * // two rows with height: 30 composed of three widgets + * nk_layout_row_template_begin(ctx, 30); + * nk_layout_row_template_push_dynamic(ctx); + * nk_layout_row_template_push_variable(ctx, 80); + * nk_layout_row_template_push_static(ctx, 80); + * nk_layout_row_template_end(ctx); + * + * nk_widget(...); // dynamic widget can go to zero if not enough space + * nk_widget(...); // variable widget with min 80 pixel but can grow bigger if enough space + * nk_widget(...); // static widget with fixed 80 pixel width + * + * // second row same layout + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * } + * nk_end(...); + * + * 6.) nk_layout_space_xxx + * Finally the most flexible API directly allows you to place widgets inside the + * window. The space layout API is an immediate mode API which does not support + * row auto repeat and directly sets position and size of a widget. Position + * and size hereby can be either specified as ratio of allocated space or + * allocated space local position and pixel size. Since this API is quite + * powerful there are a number of utility functions to get the available space + * and convert between local allocated space and screen space. + * + * if (nk_begin_xxx(...) { + * // static row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) + * nk_layout_space_begin(ctx, NK_STATIC, 500, INT_MAX); + * nk_layout_space_push(ctx, nk_rect(0,0,150,200)); + * nk_widget(...); + * nk_layout_space_push(ctx, nk_rect(200,200,100,200)); + * nk_widget(...); + * nk_layout_space_end(ctx); + * + * // dynamic row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) + * nk_layout_space_begin(ctx, NK_DYNAMIC, 500, INT_MAX); + * nk_layout_space_push(ctx, nk_rect(0.5,0.5,0.1,0.1)); + * nk_widget(...); + * nk_layout_space_push(ctx, nk_rect(0.7,0.6,0.1,0.1)); + * nk_widget(...); + * } + * nk_end(...); + * + * Reference + * ------------------- + * nk_layout_set_min_row_height - set the currently used minimum row height to a specified value + * nk_layout_reset_min_row_height - resets the currently used minimum row height to font height + * + * nk_layout_widget_bounds - calculates current width a static layout row can fit inside a window + * nk_layout_ratio_from_pixel - utility functions to calculate window ratio from pixel size + * + * nk_layout_row_dynamic - current layout is divided into n same sized growing columns + * nk_layout_row_static - current layout is divided into n same fixed sized columns + * nk_layout_row_begin - starts a new row with given height and number of columns + * nk_layout_row_push - pushes another column with given size or window ratio + * nk_layout_row_end - finished previously started row + * nk_layout_row - specifies row columns in array as either window ratio or size + * + * nk_layout_row_template_begin - begins the row template declaration + * nk_layout_row_template_push_dynamic - adds a dynamic column that dynamically grows and can go to zero if not enough space + * nk_layout_row_template_push_variable - adds a variable column that dynamically grows but does not shrink below specified pixel width + * nk_layout_row_template_push_static - adds a static column that does not grow and will always have the same size + * nk_layout_row_template_end - marks the end of the row template + * + * nk_layout_space_begin - begins a new layouting space that allows to specify each widgets position and size + * nk_layout_space_push - pushes position and size of the next widget in own coordinate space either as pixel or ratio + * nk_layout_space_end - marks the end of the layouting space + * + * nk_layout_space_bounds - callable after nk_layout_space_begin and returns total space allocated + * nk_layout_space_to_screen - converts vector from nk_layout_space coordinate space into screen space + * nk_layout_space_to_local - converts vector from screen space into nk_layout_space coordinates + * nk_layout_space_rect_to_screen - converts rectangle from nk_layout_space coordinate space into screen space + * nk_layout_space_rect_to_local - converts rectangle from screen space into nk_layout_space coordinates + */ +/* nk_layout_set_min_row_height - sets the currently used minimum row height. + * IMPORTANT: The passed height needs to include both your preferred row height + * as well as padding. No internal padding is added. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * @height new minimum row height to be used for auto generating the row height */ +NK_API void nk_layout_set_min_row_height(struct nk_context*, float height); +/* nk_layout_reset_min_row_height - Reset the currently used minimum row height + * back to font height + text padding + additional padding (style_window.min_row_height_padding) + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` */ +NK_API void nk_layout_reset_min_row_height(struct nk_context*); +/* nk_layout_widget_bounds - returns the width of the next row allocate by one of the layouting functions + * Parameters: + * @ctx must point to an previously initialized `nk_context` */ +NK_API struct nk_rect nk_layout_widget_bounds(struct nk_context*); +/* nk_layout_ratio_from_pixel - utility functions to calculate window ratio from pixel size + * Parameters: + * @ctx must point to an previously initialized `nk_context` + * @pixel_width to convert to window ratio */ +NK_API float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); +/* nk_layout_row_dynamic - Sets current row layout to share horizontal space + * between @cols number of widgets evenly. Once called all subsequent widget + * calls greater than @cols will allocate a new row with same layout. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * @row_height holds height of each widget in row or zero for auto layouting + * @cols number of widget inside row */ +NK_API void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols); +/* nk_layout_row_static - Sets current row layout to fill @cols number of widgets + * in row with same @item_width horizontal size. Once called all subsequent widget + * calls greater than @cols will allocate a new row with same layout. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * @height holds row height to allocate from panel for widget height + * @item_width holds width of each widget in row + * @cols number of widget inside row */ +NK_API void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols); +/* nk_layout_row_begin - Starts a new dynamic or fixed row with given height and columns. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * @fmt either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns + * @row_height holds height of each widget in row or zero for auto layouting + * @cols number of widget inside row */ +NK_API void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols); +/* nk_layout_row_push - Specifies either window ratio or width of a single column + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_row_begin` + * @value either a window ratio or fixed width depending on @fmt in previous `nk_layout_row_begin` call */ +NK_API void nk_layout_row_push(struct nk_context*, float value); +/* nk_layout_row_end - finished previously started row + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_row_begin` */ +NK_API void nk_layout_row_end(struct nk_context*); +/* nk_layout_row - specifies row columns in array as either window ratio or size + * Parameters: + * @ctx must point to an previously initialized `nk_context` + * @fmt either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns + * @row_height holds height of each widget in row or zero for auto layouting + * @cols number of widget inside row */ +NK_API void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio); +/* nk_layout_row_template_begin - Begins the row template declaration + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @row_height holds height of each widget in row or zero for auto layouting */ +NK_API void nk_layout_row_template_begin(struct nk_context*, float row_height); +/* nk_layout_row_template_push_dynamic - adds a dynamic column that dynamically grows and can go to zero if not enough space + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_row_template_begin` */ +NK_API void nk_layout_row_template_push_dynamic(struct nk_context*); +/* nk_layout_row_template_push_variable - adds a variable column that dynamically grows but does not shrink below specified pixel width + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_row_template_begin` + * @min_width holds the minimum pixel width the next column must be */ +NK_API void nk_layout_row_template_push_variable(struct nk_context*, float min_width); +/* nk_layout_row_template_push_static - adds a static column that does not grow and will always have the same size + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_row_template_begin` + * @width holds the absolute pixel width value the next column must be */ +NK_API void nk_layout_row_template_push_static(struct nk_context*, float width); +/* nk_layout_row_template_end - marks the end of the row template + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_row_template_begin` */ +NK_API void nk_layout_row_template_end(struct nk_context*); +/* nk_layout_space_begin - begins a new layouting space that allows to specify each widgets position and size. + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct + * @fmt either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns + * @row_height holds height of each widget in row or zero for auto layouting + * @widget_count number of widgets inside row */ +NK_API void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); +/* nk_layout_space_push - pushes position and size of the next widget in own coordinate space either as pixel or ratio + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * @bounds position and size in laoyut space local coordinates */ +NK_API void nk_layout_space_push(struct nk_context*, struct nk_rect); +/* nk_layout_space_end - marks the end of the layout space + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` */ +NK_API void nk_layout_space_end(struct nk_context*); +/* nk_layout_space_bounds - returns total space allocated for `nk_layout_space` + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` */ +NK_API struct nk_rect nk_layout_space_bounds(struct nk_context*); +/* nk_layout_space_to_screen - converts vector from nk_layout_space coordinate space into screen space + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * @vec position to convert from layout space into screen coordinate space */ +NK_API struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); +/* nk_layout_space_to_screen - converts vector from layout space into screen space + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * @vec position to convert from screen space into layout coordinate space */ +NK_API struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); +/* nk_layout_space_rect_to_screen - converts rectangle from screen space into layout space + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * @bounds rectangle to convert from layout space into screen space */ +NK_API struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect); +/* nk_layout_space_rect_to_local - converts rectangle from layout space into screen space + * Parameters: + * @ctx must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * @bounds rectangle to convert from screen space into layout space */ +NK_API struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect); +/* ============================================================================= + * + * GROUP + * + * ============================================================================= */ +NK_API int nk_group_begin(struct nk_context*, const char *title, nk_flags); +NK_API int nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char*, nk_flags); +NK_API int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll*, const char *title, nk_flags); +NK_API void nk_group_scrolled_end(struct nk_context*); +NK_API void nk_group_end(struct nk_context*); +/* ============================================================================= + * + * LIST VIEW + * + * ============================================================================= */ +struct nk_list_view { +/* public: */ + int begin, end, count; +/* private: */ + int total_height; + struct nk_context *ctx; + nk_uint *scroll_pointer; + nk_uint scroll_value; +}; +NK_API int nk_list_view_begin(struct nk_context*, struct nk_list_view *out, const char *id, nk_flags, int row_height, int row_count); +NK_API void nk_list_view_end(struct nk_list_view*); +/* ============================================================================= + * + * TREE + * + * ============================================================================= */ +#define nk_tree_push(ctx, type, title, state) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) +#define nk_tree_push_id(ctx, type, title, state, id) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) +NK_API int nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); +#define nk_tree_image_push(ctx, type, img, title, state) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) +#define nk_tree_image_push_id(ctx, type, img, title, state, id) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) +NK_API int nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); +NK_API void nk_tree_pop(struct nk_context*); +NK_API int nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); +NK_API int nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); +NK_API void nk_tree_state_pop(struct nk_context*); +/* ============================================================================= + * + * WIDGET + * + * ============================================================================= */ +enum nk_widget_layout_states { + NK_WIDGET_INVALID, /* The widget cannot be seen and is completely out of view */ + NK_WIDGET_VALID, /* The widget is completely inside the window and can be updated and drawn */ + NK_WIDGET_ROM /* The widget is partially visible and cannot be updated */ +}; +enum nk_widget_states { + NK_WIDGET_STATE_MODIFIED = NK_FLAG(1), + NK_WIDGET_STATE_INACTIVE = NK_FLAG(2), /* widget is neither active nor hovered */ + NK_WIDGET_STATE_ENTERED = NK_FLAG(3), /* widget has been hovered on the current frame */ + NK_WIDGET_STATE_HOVER = NK_FLAG(4), /* widget is being hovered */ + NK_WIDGET_STATE_ACTIVED = NK_FLAG(5),/* widget is currently activated */ + NK_WIDGET_STATE_LEFT = NK_FLAG(6), /* widget is from this frame on not hovered anymore */ + NK_WIDGET_STATE_HOVERED = NK_WIDGET_STATE_HOVER|NK_WIDGET_STATE_MODIFIED, /* widget is being hovered */ + NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /* widget is currently activated */ +}; +NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, const struct nk_context*); +NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2); +NK_API struct nk_rect nk_widget_bounds(struct nk_context*); +NK_API struct nk_vec2 nk_widget_position(struct nk_context*); +NK_API struct nk_vec2 nk_widget_size(struct nk_context*); +NK_API float nk_widget_width(struct nk_context*); +NK_API float nk_widget_height(struct nk_context*); +NK_API int nk_widget_is_hovered(struct nk_context*); +NK_API int nk_widget_is_mouse_clicked(struct nk_context*, enum nk_buttons); +NK_API int nk_widget_has_mouse_click_down(struct nk_context*, enum nk_buttons, int down); +NK_API void nk_spacing(struct nk_context*, int cols); +/* ============================================================================= + * + * TEXT + * + * ============================================================================= */ +enum nk_text_align { + NK_TEXT_ALIGN_LEFT = 0x01, + NK_TEXT_ALIGN_CENTERED = 0x02, + NK_TEXT_ALIGN_RIGHT = 0x04, + NK_TEXT_ALIGN_TOP = 0x08, + NK_TEXT_ALIGN_MIDDLE = 0x10, + NK_TEXT_ALIGN_BOTTOM = 0x20 +}; +enum nk_text_alignment { + NK_TEXT_LEFT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_LEFT, + NK_TEXT_CENTERED = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_CENTERED, + NK_TEXT_RIGHT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_RIGHT +}; +NK_API void nk_text(struct nk_context*, const char*, int, nk_flags); +NK_API void nk_text_colored(struct nk_context*, const char*, int, nk_flags, struct nk_color); +NK_API void nk_text_wrap(struct nk_context*, const char*, int); +NK_API void nk_text_wrap_colored(struct nk_context*, const char*, int, struct nk_color); +NK_API void nk_label(struct nk_context*, const char*, nk_flags align); +NK_API void nk_label_colored(struct nk_context*, const char*, nk_flags align, struct nk_color); +NK_API void nk_label_wrap(struct nk_context*, const char*); +NK_API void nk_label_colored_wrap(struct nk_context*, const char*, struct nk_color); +NK_API void nk_image(struct nk_context*, struct nk_image); +#ifdef NK_INCLUDE_STANDARD_VARARGS +NK_API void nk_labelf(struct nk_context*, nk_flags, const char*, ...); +NK_API void nk_labelf_colored(struct nk_context*, nk_flags align, struct nk_color, const char*,...); +NK_API void nk_labelf_wrap(struct nk_context*, const char*,...); +NK_API void nk_labelf_colored_wrap(struct nk_context*, struct nk_color, const char*,...); +NK_API void nk_value_bool(struct nk_context*, const char *prefix, int); +NK_API void nk_value_int(struct nk_context*, const char *prefix, int); +NK_API void nk_value_uint(struct nk_context*, const char *prefix, unsigned int); +NK_API void nk_value_float(struct nk_context*, const char *prefix, float); +NK_API void nk_value_color_byte(struct nk_context*, const char *prefix, struct nk_color); +NK_API void nk_value_color_float(struct nk_context*, const char *prefix, struct nk_color); +NK_API void nk_value_color_hex(struct nk_context*, const char *prefix, struct nk_color); +#endif +/* ============================================================================= + * + * BUTTON + * + * ============================================================================= */ +NK_API int nk_button_text(struct nk_context*, const char *title, int len); +NK_API int nk_button_label(struct nk_context*, const char *title); +NK_API int nk_button_color(struct nk_context*, struct nk_color); +NK_API int nk_button_symbol(struct nk_context*, enum nk_symbol_type); +NK_API int nk_button_image(struct nk_context*, struct nk_image img); +NK_API int nk_button_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags text_alignment); +NK_API int nk_button_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API int nk_button_image_label(struct nk_context*, struct nk_image img, const char*, nk_flags text_alignment); +NK_API int nk_button_image_text(struct nk_context*, struct nk_image img, const char*, int, nk_flags alignment); +NK_API int nk_button_text_styled(struct nk_context*, const struct nk_style_button*, const char *title, int len); +NK_API int nk_button_label_styled(struct nk_context*, const struct nk_style_button*, const char *title); +NK_API int nk_button_symbol_styled(struct nk_context*, const struct nk_style_button*, enum nk_symbol_type); +NK_API int nk_button_image_styled(struct nk_context*, const struct nk_style_button*, struct nk_image img); +NK_API int nk_button_symbol_text_styled(struct nk_context*,const struct nk_style_button*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API int nk_button_symbol_label_styled(struct nk_context *ctx, const struct nk_style_button *style, enum nk_symbol_type symbol, const char *title, nk_flags align); +NK_API int nk_button_image_label_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, nk_flags text_alignment); +NK_API int nk_button_image_text_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, int, nk_flags alignment); +NK_API void nk_button_set_behavior(struct nk_context*, enum nk_button_behavior); +NK_API int nk_button_push_behavior(struct nk_context*, enum nk_button_behavior); +NK_API int nk_button_pop_behavior(struct nk_context*); +/* ============================================================================= + * + * CHECKBOX + * + * ============================================================================= */ +NK_API int nk_check_label(struct nk_context*, const char*, int active); +NK_API int nk_check_text(struct nk_context*, const char*, int,int active); +NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value); +NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value); +NK_API int nk_checkbox_label(struct nk_context*, const char*, int *active); +NK_API int nk_checkbox_text(struct nk_context*, const char*, int, int *active); +NK_API int nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value); +NK_API int nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value); +/* ============================================================================= + * + * RADIO BUTTON + * + * ============================================================================= */ +NK_API int nk_radio_label(struct nk_context*, const char*, int *active); +NK_API int nk_radio_text(struct nk_context*, const char*, int, int *active); +NK_API int nk_option_label(struct nk_context*, const char*, int active); +NK_API int nk_option_text(struct nk_context*, const char*, int, int active); +/* ============================================================================= + * + * SELECTABLE + * + * ============================================================================= */ +NK_API int nk_selectable_label(struct nk_context*, const char*, nk_flags align, int *value); +NK_API int nk_selectable_text(struct nk_context*, const char*, int, nk_flags align, int *value); +NK_API int nk_selectable_image_label(struct nk_context*,struct nk_image, const char*, nk_flags align, int *value); +NK_API int nk_selectable_image_text(struct nk_context*,struct nk_image, const char*, int, nk_flags align, int *value); +NK_API int nk_select_label(struct nk_context*, const char*, nk_flags align, int value); +NK_API int nk_select_text(struct nk_context*, const char*, int, nk_flags align, int value); +NK_API int nk_select_image_label(struct nk_context*, struct nk_image,const char*, nk_flags align, int value); +NK_API int nk_select_image_text(struct nk_context*, struct nk_image,const char*, int, nk_flags align, int value); +/* ============================================================================= + * + * SLIDER + * + * ============================================================================= */ +NK_API float nk_slide_float(struct nk_context*, float min, float val, float max, float step); +NK_API int nk_slide_int(struct nk_context*, int min, int val, int max, int step); +NK_API int nk_slider_float(struct nk_context*, float min, float *val, float max, float step); +NK_API int nk_slider_int(struct nk_context*, int min, int *val, int max, int step); +/* ============================================================================= + * + * PROGRESSBAR + * + * ============================================================================= */ +NK_API int nk_progress(struct nk_context*, nk_size *cur, nk_size max, int modifyable); +NK_API nk_size nk_prog(struct nk_context*, nk_size cur, nk_size max, int modifyable); +/* ============================================================================= + * + * COLOR PICKER + * + * ============================================================================= */ +NK_API struct nk_color nk_color_picker(struct nk_context*, struct nk_color, enum nk_color_format); +NK_API int nk_color_pick(struct nk_context*, struct nk_color*, enum nk_color_format); +/* ============================================================================= + * + * PROPERTIES + * + * ============================================================================= */ +NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel); +NK_API void nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel); +NK_API void nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel); +NK_API int nk_propertyi(struct nk_context*, const char *name, int min, int val, int max, int step, float inc_per_pixel); +NK_API float nk_propertyf(struct nk_context*, const char *name, float min, float val, float max, float step, float inc_per_pixel); +NK_API double nk_propertyd(struct nk_context*, const char *name, double min, double val, double max, double step, float inc_per_pixel); +/* ============================================================================= + * + * TEXT EDIT + * + * ============================================================================= */ +enum nk_edit_flags { + NK_EDIT_DEFAULT = 0, + NK_EDIT_READ_ONLY = NK_FLAG(0), + NK_EDIT_AUTO_SELECT = NK_FLAG(1), + NK_EDIT_SIG_ENTER = NK_FLAG(2), + NK_EDIT_ALLOW_TAB = NK_FLAG(3), + NK_EDIT_NO_CURSOR = NK_FLAG(4), + NK_EDIT_SELECTABLE = NK_FLAG(5), + NK_EDIT_CLIPBOARD = NK_FLAG(6), + NK_EDIT_CTRL_ENTER_NEWLINE = NK_FLAG(7), + NK_EDIT_NO_HORIZONTAL_SCROLL = NK_FLAG(8), + NK_EDIT_ALWAYS_INSERT_MODE = NK_FLAG(9), + NK_EDIT_MULTILINE = NK_FLAG(10), + NK_EDIT_GOTO_END_ON_ACTIVATE = NK_FLAG(11) +}; +enum nk_edit_types { + NK_EDIT_SIMPLE = NK_EDIT_ALWAYS_INSERT_MODE, + NK_EDIT_FIELD = NK_EDIT_SIMPLE|NK_EDIT_SELECTABLE|NK_EDIT_CLIPBOARD, + NK_EDIT_BOX = NK_EDIT_ALWAYS_INSERT_MODE| NK_EDIT_SELECTABLE| NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB|NK_EDIT_CLIPBOARD, + NK_EDIT_EDITOR = NK_EDIT_SELECTABLE|NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB| NK_EDIT_CLIPBOARD +}; +enum nk_edit_events { + NK_EDIT_ACTIVE = NK_FLAG(0), /* edit widget is currently being modified */ + NK_EDIT_INACTIVE = NK_FLAG(1), /* edit widget is not active and is not being modified */ + NK_EDIT_ACTIVATED = NK_FLAG(2), /* edit widget went from state inactive to state active */ + NK_EDIT_DEACTIVATED = NK_FLAG(3), /* edit widget went from state active to state inactive */ + NK_EDIT_COMMITED = NK_FLAG(4) /* edit widget has received an enter and lost focus */ +}; +NK_API nk_flags nk_edit_string(struct nk_context*, nk_flags, char *buffer, int *len, int max, nk_plugin_filter); +NK_API nk_flags nk_edit_string_zero_terminated(struct nk_context*, nk_flags, char *buffer, int max, nk_plugin_filter); +NK_API nk_flags nk_edit_buffer(struct nk_context*, nk_flags, struct nk_text_edit*, nk_plugin_filter); +NK_API void nk_edit_focus(struct nk_context*, nk_flags flags); +NK_API void nk_edit_unfocus(struct nk_context*); +/* ============================================================================= + * + * CHART + * + * ============================================================================= */ +NK_API int nk_chart_begin(struct nk_context*, enum nk_chart_type, int num, float min, float max); +NK_API int nk_chart_begin_colored(struct nk_context*, enum nk_chart_type, struct nk_color, struct nk_color active, int num, float min, float max); +NK_API void nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type, int count, float min_value, float max_value); +NK_API void nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type, struct nk_color, struct nk_color active, int count, float min_value, float max_value); +NK_API nk_flags nk_chart_push(struct nk_context*, float); +NK_API nk_flags nk_chart_push_slot(struct nk_context*, float, int); +NK_API void nk_chart_end(struct nk_context*); +NK_API void nk_plot(struct nk_context*, enum nk_chart_type, const float *values, int count, int offset); +NK_API void nk_plot_function(struct nk_context*, enum nk_chart_type, void *userdata, float(*value_getter)(void* user, int index), int count, int offset); +/* ============================================================================= + * + * POPUP + * + * ============================================================================= */ +NK_API int nk_popup_begin(struct nk_context*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds); +NK_API void nk_popup_close(struct nk_context*); +NK_API void nk_popup_end(struct nk_context*); +/* ============================================================================= + * + * COMBOBOX + * + * ============================================================================= */ +NK_API int nk_combo(struct nk_context*, const char **items, int count, int selected, int item_height, struct nk_vec2 size); +NK_API int nk_combo_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int selected, int count, int item_height, struct nk_vec2 size); +NK_API int nk_combo_string(struct nk_context*, const char *items_separated_by_zeros, int selected, int count, int item_height, struct nk_vec2 size); +NK_API int nk_combo_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void *userdata, int selected, int count, int item_height, struct nk_vec2 size); +NK_API void nk_combobox(struct nk_context*, const char **items, int count, int *selected, int item_height, struct nk_vec2 size); +NK_API void nk_combobox_string(struct nk_context*, const char *items_separated_by_zeros, int *selected, int count, int item_height, struct nk_vec2 size); +NK_API void nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator,int *selected, int count, int item_height, struct nk_vec2 size); +NK_API void nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size); +/* ============================================================================= + * + * ABSTRACT COMBOBOX + * + * ============================================================================= */ +NK_API int nk_combo_begin_text(struct nk_context*, const char *selected, int, struct nk_vec2 size); +NK_API int nk_combo_begin_label(struct nk_context*, const char *selected, struct nk_vec2 size); +NK_API int nk_combo_begin_color(struct nk_context*, struct nk_color color, struct nk_vec2 size); +NK_API int nk_combo_begin_symbol(struct nk_context*, enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_combo_begin_symbol_label(struct nk_context*, const char *selected, enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_combo_begin_symbol_text(struct nk_context*, const char *selected, int, enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_combo_begin_image(struct nk_context*, struct nk_image img, struct nk_vec2 size); +NK_API int nk_combo_begin_image_label(struct nk_context*, const char *selected, struct nk_image, struct nk_vec2 size); +NK_API int nk_combo_begin_image_text(struct nk_context*, const char *selected, int, struct nk_image, struct nk_vec2 size); +NK_API int nk_combo_item_label(struct nk_context*, const char*, nk_flags alignment); +NK_API int nk_combo_item_text(struct nk_context*, const char*,int, nk_flags alignment); +NK_API int nk_combo_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); +NK_API int nk_combo_item_image_text(struct nk_context*, struct nk_image, const char*, int,nk_flags alignment); +NK_API int nk_combo_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); +NK_API int nk_combo_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API void nk_combo_close(struct nk_context*); +NK_API void nk_combo_end(struct nk_context*); +/* ============================================================================= + * + * CONTEXTUAL + * + * ============================================================================= */ +NK_API int nk_contextual_begin(struct nk_context*, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds); +NK_API int nk_contextual_item_text(struct nk_context*, const char*, int,nk_flags align); +NK_API int nk_contextual_item_label(struct nk_context*, const char*, nk_flags align); +NK_API int nk_contextual_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); +NK_API int nk_contextual_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment); +NK_API int nk_contextual_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); +NK_API int nk_contextual_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API void nk_contextual_close(struct nk_context*); +NK_API void nk_contextual_end(struct nk_context*); +/* ============================================================================= + * + * TOOLTIP + * + * ============================================================================= */ +NK_API void nk_tooltip(struct nk_context*, const char*); +NK_API int nk_tooltip_begin(struct nk_context*, float width); +NK_API void nk_tooltip_end(struct nk_context*); +/* ============================================================================= + * + * MENU + * + * ============================================================================= */ +NK_API void nk_menubar_begin(struct nk_context*); +NK_API void nk_menubar_end(struct nk_context*); +NK_API int nk_menu_begin_text(struct nk_context*, const char* title, int title_len, nk_flags align, struct nk_vec2 size); +NK_API int nk_menu_begin_label(struct nk_context*, const char*, nk_flags align, struct nk_vec2 size); +NK_API int nk_menu_begin_image(struct nk_context*, const char*, struct nk_image, struct nk_vec2 size); +NK_API int nk_menu_begin_image_text(struct nk_context*, const char*, int,nk_flags align,struct nk_image, struct nk_vec2 size); +NK_API int nk_menu_begin_image_label(struct nk_context*, const char*, nk_flags align,struct nk_image, struct nk_vec2 size); +NK_API int nk_menu_begin_symbol(struct nk_context*, const char*, enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_menu_begin_symbol_text(struct nk_context*, const char*, int,nk_flags align,enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_menu_begin_symbol_label(struct nk_context*, const char*, nk_flags align,enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_menu_item_text(struct nk_context*, const char*, int,nk_flags align); +NK_API int nk_menu_item_label(struct nk_context*, const char*, nk_flags alignment); +NK_API int nk_menu_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); +NK_API int nk_menu_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment); +NK_API int nk_menu_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API int nk_menu_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); +NK_API void nk_menu_close(struct nk_context*); +NK_API void nk_menu_end(struct nk_context*); +/* ============================================================================= + * + * STYLE + * + * ============================================================================= */ enum nk_style_colors { NK_COLOR_TEXT, NK_COLOR_WINDOW, @@ -611,7 +2167,6 @@ enum nk_style_colors { NK_COLOR_TAB_HEADER, NK_COLOR_COUNT }; - enum nk_style_cursor { NK_CURSOR_ARROW, NK_CURSOR_TEXT, @@ -622,532 +2177,142 @@ enum nk_style_cursor { NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT, NK_CURSOR_COUNT }; +NK_API void nk_style_default(struct nk_context*); +NK_API void nk_style_from_table(struct nk_context*, const struct nk_color*); +NK_API void nk_style_load_cursor(struct nk_context*, enum nk_style_cursor, const struct nk_cursor*); +NK_API void nk_style_load_all_cursors(struct nk_context*, struct nk_cursor*); +NK_API const char* nk_style_get_color_by_name(enum nk_style_colors); +NK_API void nk_style_set_font(struct nk_context*, const struct nk_user_font*); +NK_API int nk_style_set_cursor(struct nk_context*, enum nk_style_cursor); +NK_API void nk_style_show_cursor(struct nk_context*); +NK_API void nk_style_hide_cursor(struct nk_context*); -enum nk_widget_layout_states { - NK_WIDGET_INVALID, /* The widget cannot be seen and is completely out of view */ - NK_WIDGET_VALID, /* The widget is completely inside the window and can be updated and drawn */ - NK_WIDGET_ROM /* The widget is partially visible and cannot be updated */ -}; +NK_API int nk_style_push_font(struct nk_context*, const struct nk_user_font*); +NK_API int nk_style_push_float(struct nk_context*, float*, float); +NK_API int nk_style_push_vec2(struct nk_context*, struct nk_vec2*, struct nk_vec2); +NK_API int nk_style_push_style_item(struct nk_context*, struct nk_style_item*, struct nk_style_item); +NK_API int nk_style_push_flags(struct nk_context*, nk_flags*, nk_flags); +NK_API int nk_style_push_color(struct nk_context*, struct nk_color*, struct nk_color); -/* widget states */ -enum nk_widget_states { - NK_WIDGET_STATE_MODIFIED = NK_FLAG(1), - NK_WIDGET_STATE_INACTIVE = NK_FLAG(2), /* widget is neither active nor hovered */ - NK_WIDGET_STATE_ENTERED = NK_FLAG(3), /* widget has been hovered on the current frame */ - NK_WIDGET_STATE_HOVER = NK_FLAG(4), /* widget is being hovered */ - NK_WIDGET_STATE_ACTIVED = NK_FLAG(5),/* widget is currently activated */ - NK_WIDGET_STATE_LEFT = NK_FLAG(6), /* widget is from this frame on not hovered anymore */ - NK_WIDGET_STATE_HOVERED = NK_WIDGET_STATE_HOVER|NK_WIDGET_STATE_MODIFIED, /* widget is being hovered */ - NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /* widget is currently activated */ -}; +NK_API int nk_style_pop_font(struct nk_context*); +NK_API int nk_style_pop_float(struct nk_context*); +NK_API int nk_style_pop_vec2(struct nk_context*); +NK_API int nk_style_pop_style_item(struct nk_context*); +NK_API int nk_style_pop_flags(struct nk_context*); +NK_API int nk_style_pop_color(struct nk_context*); +/* ============================================================================= + * + * COLOR + * + * ============================================================================= */ +NK_API struct nk_color nk_rgb(int r, int g, int b); +NK_API struct nk_color nk_rgb_iv(const int *rgb); +NK_API struct nk_color nk_rgb_bv(const nk_byte* rgb); +NK_API struct nk_color nk_rgb_f(float r, float g, float b); +NK_API struct nk_color nk_rgb_fv(const float *rgb); +NK_API struct nk_color nk_rgb_hex(const char *rgb); -/* text alignment */ -enum nk_text_align { - NK_TEXT_ALIGN_LEFT = 0x01, - NK_TEXT_ALIGN_CENTERED = 0x02, - NK_TEXT_ALIGN_RIGHT = 0x04, - NK_TEXT_ALIGN_TOP = 0x08, - NK_TEXT_ALIGN_MIDDLE = 0x10, - NK_TEXT_ALIGN_BOTTOM = 0x20 -}; -enum nk_text_alignment { - NK_TEXT_LEFT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_LEFT, - NK_TEXT_CENTERED = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_CENTERED, - NK_TEXT_RIGHT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_RIGHT -}; +NK_API struct nk_color nk_rgba(int r, int g, int b, int a); +NK_API struct nk_color nk_rgba_u32(nk_uint); +NK_API struct nk_color nk_rgba_iv(const int *rgba); +NK_API struct nk_color nk_rgba_bv(const nk_byte *rgba); +NK_API struct nk_color nk_rgba_f(float r, float g, float b, float a); +NK_API struct nk_color nk_rgba_fv(const float *rgba); +NK_API struct nk_color nk_rgba_hex(const char *rgb); -/* edit flags */ -enum nk_edit_flags { - NK_EDIT_DEFAULT = 0, - NK_EDIT_READ_ONLY = NK_FLAG(0), - NK_EDIT_AUTO_SELECT = NK_FLAG(1), - NK_EDIT_SIG_ENTER = NK_FLAG(2), - NK_EDIT_ALLOW_TAB = NK_FLAG(3), - NK_EDIT_NO_CURSOR = NK_FLAG(4), - NK_EDIT_SELECTABLE = NK_FLAG(5), - NK_EDIT_CLIPBOARD = NK_FLAG(6), - NK_EDIT_CTRL_ENTER_NEWLINE = NK_FLAG(7), - NK_EDIT_NO_HORIZONTAL_SCROLL = NK_FLAG(8), - NK_EDIT_ALWAYS_INSERT_MODE = NK_FLAG(9), - NK_EDIT_MULTILINE = NK_FLAG(11), - NK_EDIT_GOTO_END_ON_ACTIVATE = NK_FLAG(12) -}; -enum nk_edit_types { - NK_EDIT_SIMPLE = NK_EDIT_ALWAYS_INSERT_MODE, - NK_EDIT_FIELD = NK_EDIT_SIMPLE|NK_EDIT_SELECTABLE|NK_EDIT_CLIPBOARD, - NK_EDIT_BOX = NK_EDIT_ALWAYS_INSERT_MODE| NK_EDIT_SELECTABLE| NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB|NK_EDIT_CLIPBOARD, - NK_EDIT_EDITOR = NK_EDIT_SELECTABLE|NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB| NK_EDIT_CLIPBOARD -}; -enum nk_edit_events { - NK_EDIT_ACTIVE = NK_FLAG(0), /* edit widget is currently being modified */ - NK_EDIT_INACTIVE = NK_FLAG(1), /* edit widget is not active and is not being modified */ - NK_EDIT_ACTIVATED = NK_FLAG(2), /* edit widget went from state inactive to state active */ - NK_EDIT_DEACTIVATED = NK_FLAG(3), /* edit widget went from state active to state inactive */ - NK_EDIT_COMMITED = NK_FLAG(4) /* edit widget has received an enter and lost focus */ -}; -enum nk_panel_flags { - NK_WINDOW_BORDER = NK_FLAG(0), /* Draws a border around the window to visually separate the window from the background */ - NK_WINDOW_MOVABLE = NK_FLAG(1), /* The movable flag indicates that a window can be moved by user input or by dragging the window header */ - NK_WINDOW_SCALABLE = NK_FLAG(2), /* The scalable flag indicates that a window can be scaled by user input by dragging a scaler icon at the button of the window */ - NK_WINDOW_CLOSABLE = NK_FLAG(3), /* adds a closable icon into the header */ - NK_WINDOW_MINIMIZABLE = NK_FLAG(4), /* adds a minimize icon into the header */ - NK_WINDOW_NO_SCROLLBAR = NK_FLAG(5), /* Removes the scrollbar from the window */ - NK_WINDOW_TITLE = NK_FLAG(6), /* Forces a header at the top at the window showing the title */ - NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(7), /* Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame */ - NK_WINDOW_BACKGROUND = NK_FLAG(8), /* Always keep window in the background */ - NK_WINDOW_SCALE_LEFT = NK_FLAG(9) /* Puts window scaler in the left-ottom corner instead right-bottom*/ -}; +NK_API struct nk_color nk_hsv(int h, int s, int v); +NK_API struct nk_color nk_hsv_iv(const int *hsv); +NK_API struct nk_color nk_hsv_bv(const nk_byte *hsv); +NK_API struct nk_color nk_hsv_f(float h, float s, float v); +NK_API struct nk_color nk_hsv_fv(const float *hsv); -/* context */ -#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR -NK_API int nk_init_default(struct nk_context*, const struct nk_user_font*); -#endif -NK_API int nk_init_fixed(struct nk_context*, void *memory, nk_size size, const struct nk_user_font*); -NK_API int nk_init(struct nk_context*, struct nk_allocator*, const struct nk_user_font*); -NK_API int nk_init_custom(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font*); -NK_API void nk_clear(struct nk_context*); -NK_API void nk_free(struct nk_context*); -#ifdef NK_INCLUDE_COMMAND_USERDATA -NK_API void nk_set_user_data(struct nk_context*, nk_handle handle); -#endif - -/* window */ -NK_API int nk_begin(struct nk_context*, const char *title, struct nk_rect bounds, nk_flags flags); -NK_API int nk_begin_titled(struct nk_context*, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); -NK_API void nk_end(struct nk_context*); - -NK_API struct nk_window* nk_window_find(struct nk_context *ctx, const char *name); -NK_API struct nk_rect nk_window_get_bounds(const struct nk_context*); -NK_API struct nk_vec2 nk_window_get_position(const struct nk_context*); -NK_API struct nk_vec2 nk_window_get_size(const struct nk_context*); -NK_API float nk_window_get_width(const struct nk_context*); -NK_API float nk_window_get_height(const struct nk_context*); -NK_API struct nk_panel* nk_window_get_panel(struct nk_context*); -NK_API struct nk_rect nk_window_get_content_region(struct nk_context*); -NK_API struct nk_vec2 nk_window_get_content_region_min(struct nk_context*); -NK_API struct nk_vec2 nk_window_get_content_region_max(struct nk_context*); -NK_API struct nk_vec2 nk_window_get_content_region_size(struct nk_context*); -NK_API struct nk_command_buffer* nk_window_get_canvas(struct nk_context*); - -NK_API int nk_window_has_focus(const struct nk_context*); -NK_API int nk_window_is_collapsed(struct nk_context*, const char*); -NK_API int nk_window_is_closed(struct nk_context*, const char*); -NK_API int nk_window_is_hidden(struct nk_context*, const char*); -NK_API int nk_window_is_active(struct nk_context*, const char*); -NK_API int nk_window_is_hovered(struct nk_context*); -NK_API int nk_window_is_any_hovered(struct nk_context*); -NK_API int nk_item_is_any_active(struct nk_context*); - -NK_API void nk_window_set_bounds(struct nk_context*, struct nk_rect); -NK_API void nk_window_set_position(struct nk_context*, struct nk_vec2); -NK_API void nk_window_set_size(struct nk_context*, struct nk_vec2); -NK_API void nk_window_set_focus(struct nk_context*, const char *name); - -NK_API void nk_window_close(struct nk_context *ctx, const char *name); -NK_API void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states); -NK_API void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond); -NK_API void nk_window_show(struct nk_context*, const char *name, enum nk_show_states); -NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); - -/* Layout */ -NK_API void nk_layout_row_dynamic(struct nk_context*, float height, int cols); -NK_API void nk_layout_row_static(struct nk_context*, float height, int item_width, int cols); - -NK_API void nk_layout_row_begin(struct nk_context*, enum nk_layout_format, float row_height, int cols); -NK_API void nk_layout_row_push(struct nk_context*, float value); -NK_API void nk_layout_row_end(struct nk_context*); -NK_API void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio); - -NK_API void nk_layout_row_template_begin(struct nk_context*, float height); -NK_API void nk_layout_row_template_push_dynamic(struct nk_context*); -NK_API void nk_layout_row_template_push_variable(struct nk_context*, float min_width); -NK_API void nk_layout_row_template_push_static(struct nk_context*, float width); -NK_API void nk_layout_row_template_end(struct nk_context*); - -NK_API void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); -NK_API void nk_layout_space_push(struct nk_context*, struct nk_rect); -NK_API void nk_layout_space_end(struct nk_context*); - -/* Layout: Utility */ -NK_API struct nk_rect nk_layout_space_bounds(struct nk_context*); -NK_API struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); -NK_API struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); -NK_API struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect); -NK_API struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect); -NK_API float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); - -/* Layout: Group */ -NK_API int nk_group_begin(struct nk_context*, const char *title, nk_flags); -NK_API int nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char*, nk_flags); -NK_API int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll*, const char *title, nk_flags); -NK_API void nk_group_scrolled_end(struct nk_context*); -NK_API void nk_group_end(struct nk_context*); - -NK_API int nk_list_view_begin(struct nk_context*, struct nk_list_view *out, const char *id, nk_flags, int row_height, int row_count); -NK_API void nk_list_view_end(struct nk_list_view*); - -/* Layout: Tree */ -#define nk_tree_push(ctx, type, title, state) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) -#define nk_tree_push_id(ctx, type, title, state, id) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) -NK_API int nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); -#define nk_tree_image_push(ctx, type, img, title, state) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) -#define nk_tree_image_push_id(ctx, type, img, title, state, id) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) -NK_API int nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); -NK_API void nk_tree_pop(struct nk_context*); - -NK_API int nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); -NK_API int nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); -NK_API void nk_tree_state_pop(struct nk_context*); - -/* Widgets */ -NK_API void nk_text(struct nk_context*, const char*, int, nk_flags); -NK_API void nk_text_colored(struct nk_context*, const char*, int, nk_flags, struct nk_color); -NK_API void nk_text_wrap(struct nk_context*, const char*, int); -NK_API void nk_text_wrap_colored(struct nk_context*, const char*, int, struct nk_color); - -NK_API void nk_label(struct nk_context*, const char*, nk_flags align); -NK_API void nk_label_colored(struct nk_context*, const char*, nk_flags align, struct nk_color); -NK_API void nk_label_wrap(struct nk_context*, const char*); -NK_API void nk_label_colored_wrap(struct nk_context*, const char*, struct nk_color); -NK_API void nk_image(struct nk_context*, struct nk_image); -#ifdef NK_INCLUDE_STANDARD_VARARGS -NK_API void nk_labelf(struct nk_context*, nk_flags, const char*, ...); -NK_API void nk_labelf_colored(struct nk_context*, nk_flags align, struct nk_color, const char*,...); -NK_API void nk_labelf_wrap(struct nk_context*, const char*,...); -NK_API void nk_labelf_colored_wrap(struct nk_context*, struct nk_color, const char*,...); - -NK_API void nk_value_bool(struct nk_context*, const char *prefix, int); -NK_API void nk_value_int(struct nk_context*, const char *prefix, int); -NK_API void nk_value_uint(struct nk_context*, const char *prefix, unsigned int); -NK_API void nk_value_float(struct nk_context*, const char *prefix, float); -NK_API void nk_value_color_byte(struct nk_context*, const char *prefix, struct nk_color); -NK_API void nk_value_color_float(struct nk_context*, const char *prefix, struct nk_color); -NK_API void nk_value_color_hex(struct nk_context*, const char *prefix, struct nk_color); -#endif - -/* Widgets: Buttons */ -NK_API void nk_button_set_behavior(struct nk_context*, enum nk_button_behavior); -NK_API int nk_button_push_behavior(struct nk_context*, enum nk_button_behavior); -NK_API int nk_button_pop_behavior(struct nk_context*); - -NK_API int nk_button_text(struct nk_context*, const char *title, int len); -NK_API int nk_button_label(struct nk_context*, const char *title); -NK_API int nk_button_color(struct nk_context*, struct nk_color); -NK_API int nk_button_symbol(struct nk_context*, enum nk_symbol_type); -NK_API int nk_button_image(struct nk_context*, struct nk_image img); -NK_API int nk_button_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags text_alignment); -NK_API int nk_button_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); -NK_API int nk_button_image_label(struct nk_context*, struct nk_image img, const char*, nk_flags text_alignment); -NK_API int nk_button_image_text(struct nk_context*, struct nk_image img, const char*, int, nk_flags alignment); - -NK_API int nk_button_text_styled(struct nk_context*, const struct nk_style_button*, const char *title, int len); -NK_API int nk_button_label_styled(struct nk_context*, const struct nk_style_button*, const char *title); -NK_API int nk_button_symbol_styled(struct nk_context*, const struct nk_style_button*, enum nk_symbol_type); -NK_API int nk_button_image_styled(struct nk_context*, const struct nk_style_button*, struct nk_image img); -NK_API int nk_button_symbol_label_styled(struct nk_context*,const struct nk_style_button*, enum nk_symbol_type, const char*, nk_flags text_alignment); -NK_API int nk_button_symbol_text_styled(struct nk_context*,const struct nk_style_button*, enum nk_symbol_type, const char*, int, nk_flags alignment); -NK_API int nk_button_image_label_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, nk_flags text_alignment); -NK_API int nk_button_image_text_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, int, nk_flags alignment); - -/* Widgets: Checkbox */ -NK_API int nk_check_label(struct nk_context*, const char*, int active); -NK_API int nk_check_text(struct nk_context*, const char*, int,int active); -NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value); -NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value); -NK_API int nk_checkbox_label(struct nk_context*, const char*, int *active); -NK_API int nk_checkbox_text(struct nk_context*, const char*, int, int *active); -NK_API int nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value); -NK_API int nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value); - -/* Widgets: Radio */ -NK_API int nk_radio_label(struct nk_context*, const char*, int *active); -NK_API int nk_radio_text(struct nk_context*, const char*, int, int *active); -NK_API int nk_option_label(struct nk_context*, const char*, int active); -NK_API int nk_option_text(struct nk_context*, const char*, int, int active); - -/* Widgets: Selectable */ -NK_API int nk_selectable_label(struct nk_context*, const char*, nk_flags align, int *value); -NK_API int nk_selectable_text(struct nk_context*, const char*, int, nk_flags align, int *value); -NK_API int nk_selectable_image_label(struct nk_context*,struct nk_image, const char*, nk_flags align, int *value); -NK_API int nk_selectable_image_text(struct nk_context*,struct nk_image, const char*, int, nk_flags align, int *value); - -NK_API int nk_select_label(struct nk_context*, const char*, nk_flags align, int value); -NK_API int nk_select_text(struct nk_context*, const char*, int, nk_flags align, int value); -NK_API int nk_select_image_label(struct nk_context*, struct nk_image,const char*, nk_flags align, int value); -NK_API int nk_select_image_text(struct nk_context*, struct nk_image,const char*, int, nk_flags align, int value); - -/* Widgets: Slider */ -NK_API float nk_slide_float(struct nk_context*, float min, float val, float max, float step); -NK_API int nk_slide_int(struct nk_context*, int min, int val, int max, int step); -NK_API int nk_slider_float(struct nk_context*, float min, float *val, float max, float step); -NK_API int nk_slider_int(struct nk_context*, int min, int *val, int max, int step); - -/* Widgets: Progressbar */ -NK_API int nk_progress(struct nk_context*, nk_size *cur, nk_size max, int modifyable); -NK_API nk_size nk_prog(struct nk_context*, nk_size cur, nk_size max, int modifyable); - -/* Widgets: Color picker */ -NK_API struct nk_color nk_color_picker(struct nk_context*, struct nk_color, enum nk_color_format); -NK_API int nk_color_pick(struct nk_context*, struct nk_color*, enum nk_color_format); - -/* Widgets: Property */ -NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel); -NK_API void nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel); -NK_API void nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel); -NK_API int nk_propertyi(struct nk_context*, const char *name, int min, int val, int max, int step, float inc_per_pixel); -NK_API float nk_propertyf(struct nk_context*, const char *name, float min, float val, float max, float step, float inc_per_pixel); -NK_API double nk_propertyd(struct nk_context*, const char *name, double min, double val, double max, double step, float inc_per_pixel); - -/* Widgets: TextEdit */ -NK_API void nk_edit_focus(struct nk_context*, nk_flags flags); -NK_API void nk_edit_unfocus(struct nk_context*); -NK_API nk_flags nk_edit_string(struct nk_context*, nk_flags, char *buffer, int *len, int max, nk_plugin_filter); -NK_API nk_flags nk_edit_buffer(struct nk_context*, nk_flags, struct nk_text_edit*, nk_plugin_filter); -NK_API nk_flags nk_edit_string_zero_terminated(struct nk_context*, nk_flags, char *buffer, int max, nk_plugin_filter); - -/* Chart */ -NK_API int nk_chart_begin(struct nk_context*, enum nk_chart_type, int num, float min, float max); -NK_API int nk_chart_begin_colored(struct nk_context*, enum nk_chart_type, struct nk_color, struct nk_color active, int num, float min, float max); -NK_API void nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type, int count, float min_value, float max_value); -NK_API void nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type, struct nk_color, struct nk_color active, int count, float min_value, float max_value); -NK_API nk_flags nk_chart_push(struct nk_context*, float); -NK_API nk_flags nk_chart_push_slot(struct nk_context*, float, int); -NK_API void nk_chart_end(struct nk_context*); -NK_API void nk_plot(struct nk_context*, enum nk_chart_type, const float *values, int count, int offset); -NK_API void nk_plot_function(struct nk_context*, enum nk_chart_type, void *userdata, float(*value_getter)(void* user, int index), int count, int offset); - -/* Popups */ -NK_API int nk_popup_begin(struct nk_context*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds); -NK_API void nk_popup_close(struct nk_context*); -NK_API void nk_popup_end(struct nk_context*); - -/* Combobox */ -NK_API int nk_combo(struct nk_context*, const char **items, int count, int selected, int item_height, struct nk_vec2 size); -NK_API int nk_combo_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int selected, int count, int item_height, struct nk_vec2 size); -NK_API int nk_combo_string(struct nk_context*, const char *items_separated_by_zeros, int selected, int count, int item_height, struct nk_vec2 size); -NK_API int nk_combo_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void *userdata, int selected, int count, int item_height, struct nk_vec2 size); -NK_API void nk_combobox(struct nk_context*, const char **items, int count, int *selected, int item_height, struct nk_vec2 size); -NK_API void nk_combobox_string(struct nk_context*, const char *items_separated_by_zeros, int *selected, int count, int item_height, struct nk_vec2 size); -NK_API void nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator,int *selected, int count, int item_height, struct nk_vec2 size); -NK_API void nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size); - -/* Combobox: abstract */ -NK_API int nk_combo_begin_text(struct nk_context*, const char *selected, int, struct nk_vec2 size); -NK_API int nk_combo_begin_label(struct nk_context*, const char *selected, struct nk_vec2 size); -NK_API int nk_combo_begin_color(struct nk_context*, struct nk_color color, struct nk_vec2 size); -NK_API int nk_combo_begin_symbol(struct nk_context*, enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_combo_begin_symbol_label(struct nk_context*, const char *selected, enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_combo_begin_symbol_text(struct nk_context*, const char *selected, int, enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_combo_begin_image(struct nk_context*, struct nk_image img, struct nk_vec2 size); -NK_API int nk_combo_begin_image_label(struct nk_context*, const char *selected, struct nk_image, struct nk_vec2 size); -NK_API int nk_combo_begin_image_text(struct nk_context*, const char *selected, int, struct nk_image, struct nk_vec2 size); -NK_API int nk_combo_item_label(struct nk_context*, const char*, nk_flags alignment); -NK_API int nk_combo_item_text(struct nk_context*, const char*,int, nk_flags alignment); -NK_API int nk_combo_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); -NK_API int nk_combo_item_image_text(struct nk_context*, struct nk_image, const char*, int,nk_flags alignment); -NK_API int nk_combo_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); -NK_API int nk_combo_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); -NK_API void nk_combo_close(struct nk_context*); -NK_API void nk_combo_end(struct nk_context*); - -/* Contextual */ -NK_API int nk_contextual_begin(struct nk_context*, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds); -NK_API int nk_contextual_item_text(struct nk_context*, const char*, int,nk_flags align); -NK_API int nk_contextual_item_label(struct nk_context*, const char*, nk_flags align); -NK_API int nk_contextual_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); -NK_API int nk_contextual_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment); -NK_API int nk_contextual_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); -NK_API int nk_contextual_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); -NK_API void nk_contextual_close(struct nk_context*); -NK_API void nk_contextual_end(struct nk_context*); - -/* Tooltip */ -NK_API void nk_tooltip(struct nk_context*, const char*); -NK_API int nk_tooltip_begin(struct nk_context*, float width); -NK_API void nk_tooltip_end(struct nk_context*); - -/* Menu */ -NK_API void nk_menubar_begin(struct nk_context*); -NK_API void nk_menubar_end(struct nk_context*); - -NK_API int nk_menu_begin_text(struct nk_context*, const char* title, int title_len, nk_flags align, struct nk_vec2 size); -NK_API int nk_menu_begin_label(struct nk_context*, const char*, nk_flags align, struct nk_vec2 size); -NK_API int nk_menu_begin_image(struct nk_context*, const char*, struct nk_image, struct nk_vec2 size); -NK_API int nk_menu_begin_image_text(struct nk_context*, const char*, int,nk_flags align,struct nk_image, struct nk_vec2 size); -NK_API int nk_menu_begin_image_label(struct nk_context*, const char*, nk_flags align,struct nk_image, struct nk_vec2 size); -NK_API int nk_menu_begin_symbol(struct nk_context*, const char*, enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_menu_begin_symbol_text(struct nk_context*, const char*, int,nk_flags align,enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_menu_begin_symbol_label(struct nk_context*, const char*, nk_flags align,enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_menu_item_text(struct nk_context*, const char*, int,nk_flags align); -NK_API int nk_menu_item_label(struct nk_context*, const char*, nk_flags alignment); -NK_API int nk_menu_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); -NK_API int nk_menu_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment); -NK_API int nk_menu_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); -NK_API int nk_menu_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); -NK_API void nk_menu_close(struct nk_context*); -NK_API void nk_menu_end(struct nk_context*); - -/* Drawing*/ -#define nk_foreach(c, ctx) for((c)=nk__begin(ctx); (c)!=0; (c)=nk__next(ctx, c)) -#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT -NK_API void nk_convert(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); -#define nk_draw_foreach(cmd,ctx, b) for((cmd)=nk__draw_begin(ctx, b); (cmd)!=0; (cmd)=nk__draw_next(cmd, b, ctx)) -#define nk_draw_foreach_bounded(cmd,from,to) for((cmd)=(from); (cmd) && (to) && (cmd)>=to; --(cmd)) -NK_API const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); -NK_API const struct nk_draw_command* nk__draw_end(const struct nk_context*, const struct nk_buffer*); -NK_API const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*); -#endif - -/* User Input */ -NK_API void nk_input_begin(struct nk_context*); -NK_API void nk_input_motion(struct nk_context*, int x, int y); -NK_API void nk_input_key(struct nk_context*, enum nk_keys, int down); -NK_API void nk_input_button(struct nk_context*, enum nk_buttons, int x, int y, int down); -NK_API void nk_input_scroll(struct nk_context*, float y); -NK_API void nk_input_char(struct nk_context*, char); -NK_API void nk_input_glyph(struct nk_context*, const nk_glyph); -NK_API void nk_input_unicode(struct nk_context*, nk_rune); -NK_API void nk_input_end(struct nk_context*); - -/* Style */ -NK_API void nk_style_default(struct nk_context*); -NK_API void nk_style_from_table(struct nk_context*, const struct nk_color*); -NK_API void nk_style_load_cursor(struct nk_context*, enum nk_style_cursor, const struct nk_cursor*); -NK_API void nk_style_load_all_cursors(struct nk_context*, struct nk_cursor*); -NK_API const char* nk_style_get_color_by_name(enum nk_style_colors); -NK_API void nk_style_set_font(struct nk_context*, const struct nk_user_font*); -NK_API int nk_style_set_cursor(struct nk_context*, enum nk_style_cursor); -NK_API void nk_style_show_cursor(struct nk_context*); -NK_API void nk_style_hide_cursor(struct nk_context*); - -/* Style: stack */ -NK_API int nk_style_push_font(struct nk_context*, struct nk_user_font*); -NK_API int nk_style_push_float(struct nk_context*, float*, float); -NK_API int nk_style_push_vec2(struct nk_context*, struct nk_vec2*, struct nk_vec2); -NK_API int nk_style_push_style_item(struct nk_context*, struct nk_style_item*, struct nk_style_item); -NK_API int nk_style_push_flags(struct nk_context*, nk_flags*, nk_flags); -NK_API int nk_style_push_color(struct nk_context*, struct nk_color*, struct nk_color); - -NK_API int nk_style_pop_font(struct nk_context*); -NK_API int nk_style_pop_float(struct nk_context*); -NK_API int nk_style_pop_vec2(struct nk_context*); -NK_API int nk_style_pop_style_item(struct nk_context*); -NK_API int nk_style_pop_flags(struct nk_context*); -NK_API int nk_style_pop_color(struct nk_context*); - -/* Utilities */ -NK_API struct nk_rect nk_widget_bounds(struct nk_context*); -NK_API struct nk_vec2 nk_widget_position(struct nk_context*); -NK_API struct nk_vec2 nk_widget_size(struct nk_context*); -NK_API float nk_widget_width(struct nk_context*); -NK_API float nk_widget_height(struct nk_context*); -NK_API int nk_widget_is_hovered(struct nk_context*); -NK_API int nk_widget_is_mouse_clicked(struct nk_context*, enum nk_buttons); -NK_API int nk_widget_has_mouse_click_down(struct nk_context*, enum nk_buttons, int down); -NK_API void nk_spacing(struct nk_context*, int cols); - -/* base widget function */ -NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, const struct nk_context*); -NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2); - -/* color (conversion user --> nuklear) */ -NK_API struct nk_color nk_rgb(int r, int g, int b); -NK_API struct nk_color nk_rgb_iv(const int *rgb); -NK_API struct nk_color nk_rgb_bv(const nk_byte* rgb); -NK_API struct nk_color nk_rgb_f(float r, float g, float b); -NK_API struct nk_color nk_rgb_fv(const float *rgb); -NK_API struct nk_color nk_rgb_hex(const char *rgb); - -NK_API struct nk_color nk_rgba(int r, int g, int b, int a); -NK_API struct nk_color nk_rgba_u32(nk_uint); -NK_API struct nk_color nk_rgba_iv(const int *rgba); -NK_API struct nk_color nk_rgba_bv(const nk_byte *rgba); -NK_API struct nk_color nk_rgba_f(float r, float g, float b, float a); -NK_API struct nk_color nk_rgba_fv(const float *rgba); -NK_API struct nk_color nk_rgba_hex(const char *rgb); - -NK_API struct nk_color nk_hsv(int h, int s, int v); -NK_API struct nk_color nk_hsv_iv(const int *hsv); -NK_API struct nk_color nk_hsv_bv(const nk_byte *hsv); -NK_API struct nk_color nk_hsv_f(float h, float s, float v); -NK_API struct nk_color nk_hsv_fv(const float *hsv); - -NK_API struct nk_color nk_hsva(int h, int s, int v, int a); -NK_API struct nk_color nk_hsva_iv(const int *hsva); -NK_API struct nk_color nk_hsva_bv(const nk_byte *hsva); -NK_API struct nk_color nk_hsva_f(float h, float s, float v, float a); -NK_API struct nk_color nk_hsva_fv(const float *hsva); +NK_API struct nk_color nk_hsva(int h, int s, int v, int a); +NK_API struct nk_color nk_hsva_iv(const int *hsva); +NK_API struct nk_color nk_hsva_bv(const nk_byte *hsva); +NK_API struct nk_color nk_hsva_f(float h, float s, float v, float a); +NK_API struct nk_color nk_hsva_fv(const float *hsva); /* color (conversion nuklear --> user) */ -NK_API void nk_color_f(float *r, float *g, float *b, float *a, struct nk_color); -NK_API void nk_color_fv(float *rgba_out, struct nk_color); -NK_API void nk_color_d(double *r, double *g, double *b, double *a, struct nk_color); -NK_API void nk_color_dv(double *rgba_out, struct nk_color); +NK_API void nk_color_f(float *r, float *g, float *b, float *a, struct nk_color); +NK_API void nk_color_fv(float *rgba_out, struct nk_color); +NK_API void nk_color_d(double *r, double *g, double *b, double *a, struct nk_color); +NK_API void nk_color_dv(double *rgba_out, struct nk_color); -NK_API nk_uint nk_color_u32(struct nk_color); -NK_API void nk_color_hex_rgba(char *output, struct nk_color); -NK_API void nk_color_hex_rgb(char *output, struct nk_color); +NK_API nk_uint nk_color_u32(struct nk_color); +NK_API void nk_color_hex_rgba(char *output, struct nk_color); +NK_API void nk_color_hex_rgb(char *output, struct nk_color); -NK_API void nk_color_hsv_i(int *out_h, int *out_s, int *out_v, struct nk_color); -NK_API void nk_color_hsv_b(nk_byte *out_h, nk_byte *out_s, nk_byte *out_v, struct nk_color); -NK_API void nk_color_hsv_iv(int *hsv_out, struct nk_color); -NK_API void nk_color_hsv_bv(nk_byte *hsv_out, struct nk_color); -NK_API void nk_color_hsv_f(float *out_h, float *out_s, float *out_v, struct nk_color); -NK_API void nk_color_hsv_fv(float *hsv_out, struct nk_color); +NK_API void nk_color_hsv_i(int *out_h, int *out_s, int *out_v, struct nk_color); +NK_API void nk_color_hsv_b(nk_byte *out_h, nk_byte *out_s, nk_byte *out_v, struct nk_color); +NK_API void nk_color_hsv_iv(int *hsv_out, struct nk_color); +NK_API void nk_color_hsv_bv(nk_byte *hsv_out, struct nk_color); +NK_API void nk_color_hsv_f(float *out_h, float *out_s, float *out_v, struct nk_color); +NK_API void nk_color_hsv_fv(float *hsv_out, struct nk_color); -NK_API void nk_color_hsva_i(int *h, int *s, int *v, int *a, struct nk_color); -NK_API void nk_color_hsva_b(nk_byte *h, nk_byte *s, nk_byte *v, nk_byte *a, struct nk_color); -NK_API void nk_color_hsva_iv(int *hsva_out, struct nk_color); -NK_API void nk_color_hsva_bv(nk_byte *hsva_out, struct nk_color); -NK_API void nk_color_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_color); -NK_API void nk_color_hsva_fv(float *hsva_out, struct nk_color); +NK_API void nk_color_hsva_i(int *h, int *s, int *v, int *a, struct nk_color); +NK_API void nk_color_hsva_b(nk_byte *h, nk_byte *s, nk_byte *v, nk_byte *a, struct nk_color); +NK_API void nk_color_hsva_iv(int *hsva_out, struct nk_color); +NK_API void nk_color_hsva_bv(nk_byte *hsva_out, struct nk_color); +NK_API void nk_color_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_color); +NK_API void nk_color_hsva_fv(float *hsva_out, struct nk_color); +/* ============================================================================= + * + * IMAGE + * + * ============================================================================= */ +NK_API nk_handle nk_handle_ptr(void*); +NK_API nk_handle nk_handle_id(int); +NK_API struct nk_image nk_image_handle(nk_handle); +NK_API struct nk_image nk_image_ptr(void*); +NK_API struct nk_image nk_image_id(int); +NK_API int nk_image_is_subimage(const struct nk_image* img); +NK_API struct nk_image nk_subimage_ptr(void*, unsigned short w, unsigned short h, struct nk_rect sub_region); +NK_API struct nk_image nk_subimage_id(int, unsigned short w, unsigned short h, struct nk_rect sub_region); +NK_API struct nk_image nk_subimage_handle(nk_handle, unsigned short w, unsigned short h, struct nk_rect sub_region); +/* ============================================================================= + * + * MATH + * + * ============================================================================= */ +NK_API nk_hash nk_murmur_hash(const void *key, int len, nk_hash seed); +NK_API void nk_triangle_from_direction(struct nk_vec2 *result, struct nk_rect r, float pad_x, float pad_y, enum nk_heading); -/* image */ -NK_API nk_handle nk_handle_ptr(void*); -NK_API nk_handle nk_handle_id(int); -NK_API struct nk_image nk_image_handle(nk_handle); -NK_API struct nk_image nk_image_ptr(void*); -NK_API struct nk_image nk_image_id(int); -NK_API int nk_image_is_subimage(const struct nk_image* img); -NK_API struct nk_image nk_subimage_ptr(void*, unsigned short w, unsigned short h, struct nk_rect sub_region); -NK_API struct nk_image nk_subimage_id(int, unsigned short w, unsigned short h, struct nk_rect sub_region); -NK_API struct nk_image nk_subimage_handle(nk_handle, unsigned short w, unsigned short h, struct nk_rect sub_region); - -/* math */ -NK_API nk_hash nk_murmur_hash(const void *key, int len, nk_hash seed); -NK_API void nk_triangle_from_direction(struct nk_vec2 *result, struct nk_rect r, float pad_x, float pad_y, enum nk_heading); - -NK_API struct nk_vec2 nk_vec2(float x, float y); -NK_API struct nk_vec2 nk_vec2i(int x, int y); -NK_API struct nk_vec2 nk_vec2v(const float *xy); -NK_API struct nk_vec2 nk_vec2iv(const int *xy); - -NK_API struct nk_rect nk_get_null_rect(void); -NK_API struct nk_rect nk_rect(float x, float y, float w, float h); -NK_API struct nk_rect nk_recti(int x, int y, int w, int h); -NK_API struct nk_rect nk_recta(struct nk_vec2 pos, struct nk_vec2 size); -NK_API struct nk_rect nk_rectv(const float *xywh); -NK_API struct nk_rect nk_rectiv(const int *xywh); -NK_API struct nk_vec2 nk_rect_pos(struct nk_rect); -NK_API struct nk_vec2 nk_rect_size(struct nk_rect); - -/* string*/ -NK_API int nk_strlen(const char *str); -NK_API int nk_stricmp(const char *s1, const char *s2); -NK_API int nk_stricmpn(const char *s1, const char *s2, int n); -NK_API int nk_strtoi(const char *str, char **endptr); -NK_API float nk_strtof(const char *str, char **endptr); -NK_API double nk_strtod(const char *str, char **endptr); -NK_API int nk_strfilter(const char *text, const char *regexp); -NK_API int nk_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score); -NK_API int nk_strmatch_fuzzy_text(const char *txt, int txt_len, const char *pattern, int *out_score); - -/* UTF-8 */ -NK_API int nk_utf_decode(const char*, nk_rune*, int); -NK_API int nk_utf_encode(nk_rune, char*, int); -NK_API int nk_utf_len(const char*, int byte_len); -NK_API const char* nk_utf_at(const char *buffer, int length, int index, nk_rune *unicode, int *len); +NK_API struct nk_vec2 nk_vec2(float x, float y); +NK_API struct nk_vec2 nk_vec2i(int x, int y); +NK_API struct nk_vec2 nk_vec2v(const float *xy); +NK_API struct nk_vec2 nk_vec2iv(const int *xy); +NK_API struct nk_rect nk_get_null_rect(void); +NK_API struct nk_rect nk_rect(float x, float y, float w, float h); +NK_API struct nk_rect nk_recti(int x, int y, int w, int h); +NK_API struct nk_rect nk_recta(struct nk_vec2 pos, struct nk_vec2 size); +NK_API struct nk_rect nk_rectv(const float *xywh); +NK_API struct nk_rect nk_rectiv(const int *xywh); +NK_API struct nk_vec2 nk_rect_pos(struct nk_rect); +NK_API struct nk_vec2 nk_rect_size(struct nk_rect); +/* ============================================================================= + * + * STRING + * + * ============================================================================= */ +NK_API int nk_strlen(const char *str); +NK_API int nk_stricmp(const char *s1, const char *s2); +NK_API int nk_stricmpn(const char *s1, const char *s2, int n); +NK_API int nk_strtoi(const char *str, const char **endptr); +NK_API float nk_strtof(const char *str, const char **endptr); +NK_API double nk_strtod(const char *str, const char **endptr); +NK_API int nk_strfilter(const char *text, const char *regexp); +NK_API int nk_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score); +NK_API int nk_strmatch_fuzzy_text(const char *txt, int txt_len, const char *pattern, int *out_score); +/* ============================================================================= + * + * UTF-8 + * + * ============================================================================= */ +NK_API int nk_utf_decode(const char*, nk_rune*, int); +NK_API int nk_utf_encode(nk_rune, char*, int); +NK_API int nk_utf_len(const char*, int byte_len); +NK_API const char* nk_utf_at(const char *buffer, int length, int index, nk_rune *unicode, int *len); /* =============================================================== * * FONT @@ -1158,7 +2323,7 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in different ways to use the font atlas. The first two will use your font handling scheme and only requires essential data to run nuklear. The next slightly more advanced features is font handling with vertex buffer output. - Finally the most complex API wise is using nuklears font baking API. + Finally the most complex API wise is using nuklear's font baking API. 1.) Using your own implementation without vertex buffer output -------------------------------------------------------------- @@ -1231,7 +2396,7 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in ------------------------------------ The final approach if you do not have a font handling functionality or don't want to use it in this library is by using the optional font baker. - The font baker API's can be used to create a font plus font atlas texture + The font baker APIs can be used to create a font plus font atlas texture and can be used with or without the vertex buffer output. It still uses the `nk_user_font` struct and the two different approaches @@ -1246,7 +2411,7 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in memory is temporary and therefore can be freed directly after the baking process is over or permanent you can call `nk_font_atlas_init`. - After successfull intializing the font baker you can add Truetype(.ttf) fonts from + After successfully initializing the font baker you can add Truetype(.ttf) fonts from different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. functions. Adding font will permanently store each font, font config and ttf memory block(!) inside the font atlas and allows to reuse the font atlas. If you don't want to reuse @@ -1254,7 +2419,7 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). As soon as you added all fonts you wanted you can now start the baking process - for every selected glyphes to image by calling `nk_font_atlas_bake`. + for every selected glyph to image by calling `nk_font_atlas_bake`. The baking process returns image memory, width and height which can be used to either create your own image object or upload it to any graphics library. No matter which case you finally have to call `nk_font_atlas_end` which @@ -1274,7 +2439,7 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in nk_font_atlas_begin(&atlas); nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); - void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32, 0); + const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); struct nk_context ctx; @@ -1288,7 +2453,7 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in I would suggest reading some of my examples `example/` to get a grip on how to use the font atlas. There are a number of details I left out. For example how to merge fonts, configure a font with `nk_font_config` to use other languages, - use another texture coodinate format and a lot more: + use another texture coordinate format and a lot more: struct nk_font_config cfg = nk_font_config(font_pixel_height); cfg.merge_mode = nk_false or nk_true; @@ -1623,7 +2788,7 @@ NK_API int nk_str_len_char(struct nk_str*); * First of is the most basic way of just providing a simple char array with * string length. This method is probably the easiest way of handling simple * user text input. Main upside is complete control over memory while the biggest - * downside in comparsion with the other two approaches is missing undo/redo. + * downside in comparison with the other two approaches is missing undo/redo. * * For UIs that require undo/redo the second way was created. It is based on * a fixed size nk_text_edit struct, which has an internal undo/redo stack. @@ -1770,8 +2935,8 @@ NK_API void nk_textedit_redo(struct nk_text_edit*); but also returns the state of the widget space. If your widget is not seen and does not have to be updated it is '0' and you can just return. If it only has to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both - update and draw your widget. The reason for seperating is to only draw and - update what is actually neccessary which is crucial for performance. + update and draw your widget. The reason for separating is to only draw and + update what is actually necessary which is crucial for performance. */ enum nk_command_type { NK_COMMAND_NOP, @@ -1791,7 +2956,8 @@ enum nk_command_type { NK_COMMAND_POLYGON_FILLED, NK_COMMAND_POLYLINE, NK_COMMAND_TEXT, - NK_COMMAND_IMAGE + NK_COMMAND_IMAGE, + NK_COMMAND_CUSTOM }; /* command base and header of every command inside the buffer */ @@ -1933,6 +3099,16 @@ struct nk_command_image { struct nk_color col; }; +typedef void (*nk_command_custom_callback)(void *canvas, short x,short y, + unsigned short w, unsigned short h, nk_handle callback_data); +struct nk_command_custom { + struct nk_command header; + short x, y; + unsigned short w, h; + nk_handle callback_data; + nk_command_custom_callback callback; +}; + struct nk_command_text { struct nk_command header; const struct nk_user_font *font; @@ -1977,11 +3153,10 @@ NK_API void nk_fill_triangle(struct nk_command_buffer*, float x0, float y0, floa NK_API void nk_fill_polygon(struct nk_command_buffer*, float*, int point_count, struct nk_color); /* misc */ -NK_API void nk_push_scissor(struct nk_command_buffer*, struct nk_rect); NK_API void nk_draw_image(struct nk_command_buffer*, struct nk_rect, const struct nk_image*, struct nk_color); NK_API void nk_draw_text(struct nk_command_buffer*, struct nk_rect, const char *text, int len, const struct nk_user_font*, struct nk_color, struct nk_color); -NK_API const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); -NK_API const struct nk_command* nk__begin(struct nk_context*); +NK_API void nk_push_scissor(struct nk_command_buffer*, struct nk_rect); +NK_API void nk_push_custom(struct nk_command_buffer*, struct nk_rect, nk_command_custom_callback, nk_handle usr); /* =============================================================== * @@ -1998,7 +3173,7 @@ struct nk_mouse { struct nk_vec2 pos; struct nk_vec2 prev; struct nk_vec2 delta; - float scroll_delta; + struct nk_vec2 scroll_delta; unsigned char grab; unsigned char grabbed; unsigned char ungrab; @@ -2085,6 +3260,7 @@ NK_FORMAT_COLOR_BEGIN, NK_FORMAT_R32G32B32, NK_FORMAT_R8G8B8A8, + NK_FORMAT_B8G8R8A8, NK_FORMAT_R16G15B16A16, NK_FORMAT_R32G32B32A32, NK_FORMAT_R32G32B32A32_FLOAT, @@ -2132,6 +3308,9 @@ struct nk_draw_list { unsigned int path_count; unsigned int path_offset; + enum nk_anti_aliasing line_AA; + enum nk_anti_aliasing shape_AA; + #ifdef NK_INCLUDE_COMMAND_USERDATA nk_handle userdata; #endif @@ -2139,7 +3318,7 @@ struct nk_draw_list { /* draw list */ NK_API void nk_draw_list_init(struct nk_draw_list*); -NK_API void nk_draw_list_setup(struct nk_draw_list*, const struct nk_convert_config*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements); +NK_API void nk_draw_list_setup(struct nk_draw_list*, const struct nk_convert_config*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, enum nk_anti_aliasing line_aa,enum nk_anti_aliasing shape_aa); NK_API void nk_draw_list_clear(struct nk_draw_list*); /* drawing */ @@ -2579,6 +3758,7 @@ struct nk_style_window { float group_border; float tooltip_border; float popup_border; + float min_row_height_padding; float rounding; struct nk_vec2 spacing; @@ -2681,6 +3861,7 @@ struct nk_row_layout { enum nk_panel_row_layout_type type; int index; float height; + float min_height; int columns; const float *ratio; float item_width; @@ -2720,7 +3901,6 @@ struct nk_panel { struct nk_menu_state menu; struct nk_row_layout row; struct nk_chart chart; - struct nk_popup_buffer popup_buffer; struct nk_command_buffer *buffer; struct nk_panel *parent; }; @@ -2734,24 +3914,27 @@ struct nk_panel { struct nk_table; enum nk_window_flags { - NK_WINDOW_PRIVATE = NK_FLAG(10), + NK_WINDOW_PRIVATE = NK_FLAG(11), NK_WINDOW_DYNAMIC = NK_WINDOW_PRIVATE, /* special window type growing up in height while being filled to a certain maximum height */ - NK_WINDOW_ROM = NK_FLAG(11), - /* sets the window into a read only mode and does not allow input changes */ - NK_WINDOW_HIDDEN = NK_FLAG(12), - /* Hides the window and stops any window interaction and drawing */ - NK_WINDOW_CLOSED = NK_FLAG(13), + NK_WINDOW_ROM = NK_FLAG(12), + /* sets window widgets into a read only mode and does not allow input changes */ + NK_WINDOW_NOT_INTERACTIVE = NK_WINDOW_ROM|NK_WINDOW_NO_INPUT, + /* prevents all interaction caused by input to either window or widgets inside */ + NK_WINDOW_HIDDEN = NK_FLAG(13), + /* Hides window and stops any window interaction and drawing */ + NK_WINDOW_CLOSED = NK_FLAG(14), /* Directly closes and frees the window at the end of the frame */ - NK_WINDOW_MINIMIZED = NK_FLAG(14), + NK_WINDOW_MINIMIZED = NK_FLAG(15), /* marks the window as minimized */ - NK_WINDOW_REMOVE_ROM = NK_FLAG(15) - /* Removes the read only mode at the end of the window */ + NK_WINDOW_REMOVE_ROM = NK_FLAG(16) + /* Removes read only mode at the end of the window */ }; struct nk_popup_state { struct nk_window *win; enum nk_panel_type type; + struct nk_popup_buffer buf; nk_hash name; int active; unsigned combo_count; @@ -2778,6 +3961,8 @@ struct nk_property_state { char buffer[NK_MAX_NUMBER_BUFFER]; int length; int cursor; + int select_start; + int select_end; nk_hash name; unsigned int seq; unsigned int old; @@ -2803,8 +3988,7 @@ struct nk_window { unsigned int scrolled; struct nk_table *tables; - unsigned short table_count; - unsigned short table_size; + unsigned int table_count; /* window list hooks */ struct nk_window *next; @@ -2833,7 +4017,7 @@ struct nk_window { * nk_style_pop_style_item(ctx); * nk_style_pop_vec2(ctx); * - * Nuklear has a stack for style_items, float properties, vector properties, + * Nuklear has a stack for style_items, float properties, vector properties, * flags, colors, fonts and for button_behavior. Each has it's own fixed size stack * which can be changed at compile time. */ @@ -2907,10 +4091,11 @@ struct nk_configuration_stacks { * CONTEXT * =============================================================*/ #define NK_VALUE_PAGE_CAPACITY \ - ((NK_MAX(sizeof(struct nk_window),sizeof(struct nk_panel)) / sizeof(nk_uint)) / 2) + (((NK_MAX(sizeof(struct nk_window),sizeof(struct nk_panel)) / sizeof(nk_uint))) / 2) struct nk_table { unsigned int seq; + unsigned int size; nk_hash keys[NK_VALUE_PAGE_CAPACITY]; nk_uint values[NK_VALUE_PAGE_CAPACITY]; struct nk_table *next, *prev; @@ -2997,7 +4182,7 @@ struct nk_context { #define NK_SATURATE(x) (NK_MAX(0, NK_MIN(1.0f, x))) #define NK_LEN(a) (sizeof(a)/sizeof(a)[0]) #define NK_ABS(a) (((a) < 0) ? -(a) : (a)) -#define NK_BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) +#define NK_BETWEEN(x, a, b) ((a) <= (x) && (x) < (b)) #define NK_INBOX(px, py, x, y, w, h)\ (NK_BETWEEN(px,x,x+w) && NK_BETWEEN(py,y,y+h)) #define NK_INTERSECT(x0, y0, w0, h0, x1, y1, w1, h1) \ @@ -3051,14 +4236,14 @@ template struct nk_helper{enum {value = size_diff};}; template struct nk_helper{enum {value = nk_alignof::value};}; template struct nk_alignof{struct Big {T x; char c;}; enum { diff = sizeof(Big) - sizeof(T), value = nk_helper::value};}; -#define NK_ALIGNOF(t) (nk_alignof::value); +#define NK_ALIGNOF(t) (nk_alignof::value) #elif defined(_MSC_VER) #define NK_ALIGNOF(t) (__alignof(t)) #else #define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0) #endif -#endif /* NK_H_ */ +#endif /* NK_NUKLEAR_H_ */ /* * ============================================================== * @@ -3188,7 +4373,7 @@ NK_GLOBAL const struct nk_color nk_yellow = {255,255,0,255}; ---- For square root nuklear uses the famous fast inverse square root: https://en.wikipedia.org/wiki/Fast_inverse_square_root with - slightly tweaked magic constant. While on todays hardware it is + slightly tweaked magic constant. While on today's hardware it is probably not faster it is still fast and accurate enough for nuklear's use cases. IMPORTANT: this requires float format IEEE 754 @@ -3199,7 +4384,7 @@ NK_GLOBAL const struct nk_color nk_yellow = {255,255,0,255}; approximate exactly that range is that nuklear only needs sine and cosine to generate circles which only requires that exact range. In addition I used Remez instead of Taylor for additional precision: - www.lolengine.net/blog/2011/12/21/better-function-approximatations. + www.lolengine.net/blog/2011/12/21/better-function-approximations. The tool I used to generate constants for both sine and cosine (it can actually approximate a lot more functions) can be @@ -3518,7 +4703,7 @@ nk_strlen(const char *str) } NK_API int -nk_strtoi(const char *str, char **endptr) +nk_strtoi(const char *str, const char **endptr) { int neg = 1; const char *p = str; @@ -3538,12 +4723,12 @@ nk_strtoi(const char *str, char **endptr) p++; } if (endptr) - *endptr = (char*)p; + *endptr = p; return neg*value; } NK_API double -nk_strtod(const char *str, char **endptr) +nk_strtod(const char *str, const char **endptr) { double m; double neg = 1.0; @@ -3596,12 +4781,12 @@ nk_strtod(const char *str, char **endptr) } number = value * neg; if (endptr) - *endptr = (char*)p; + *endptr = p; return number; } NK_API float -nk_strtof(const char *str, char **endptr) +nk_strtof(const char *str, const char **endptr) { float float_value; double double_value; @@ -3706,7 +4891,7 @@ nk_strmatch_fuzzy_text(const char *str, int str_len, const char *pattern, int *out_score) { /* Returns true if each character in pattern is found sequentially within str - * if found then outScore is also set. Score value has no intrinsic meaning. + * if found then out_score is also set. Score value has no intrinsic meaning. * Range varies with pattern. Can only compare scores with same search pattern. */ /* ------- scores --------- */ @@ -3884,7 +5069,7 @@ nk_iceilf(float x) { if (x >= 0) { int i = (int)x; - return i; + return (x > i) ? i+1: i; } else { int t = (int)x; float r = x - (float)t; @@ -4028,6 +5213,7 @@ nk_dtoa(char *s, double n) } #ifdef NK_INCLUDE_STANDARD_VARARGS +#ifndef NK_INCLUDE_STANDARD_IO static int nk_vsnprintf(char *buf, int buf_size, const char *fmt, va_list args) { @@ -4079,7 +5265,7 @@ nk_vsnprintf(char *buf, int buf_size, const char *fmt, va_list args) /* width argument */ width = NK_DEFAULT; if (*iter >= '1' && *iter <= '9') { - char *end; + const char *end; width = nk_strtoi(iter, &end); if (end == iter) width = -1; @@ -4097,7 +5283,7 @@ nk_vsnprintf(char *buf, int buf_size, const char *fmt, va_list args) precision = va_arg(args, int); iter++; } else { - char *end; + const char *end; precision = nk_strtoi(iter, &end); if (end == iter) precision = -1; @@ -4346,6 +5532,7 @@ nk_vsnprintf(char *buf, int buf_size, const char *fmt, va_list args) result = (len >= buf_size)?-1:len; return result; } +#endif NK_INTERN int nk_strfmt(char *buf, int buf_size, const char *fmt, va_list args) @@ -5074,7 +6261,7 @@ nk_text_clamp(const struct nk_user_font *font, const char *text, sep_len = len; break; } - if (i == NK_MAX(sep_count,0)){ + if (i == sep_count){ last_width = sep_width = width; sep_g = g+1; } @@ -5449,11 +6636,12 @@ nk_buffer_alloc(struct nk_buffer *b, enum nk_buffer_allocation_type type, /* check if buffer has enough memory*/ if (type == NK_BUFFER_FRONT) full = ((b->allocated + size + alignment) > b->size); - else full = ((b->size - (size + alignment)) <= b->allocated); + else full = ((b->size - NK_MIN(b->size,(size + alignment))) <= b->allocated); if (full) { nk_size capacity; - NK_ASSERT(b->type == NK_BUFFER_DYNAMIC); + if (b->type != NK_BUFFER_DYNAMIC) + return 0; NK_ASSERT(b->pool.alloc && b->pool.free); if (b->type != NK_BUFFER_DYNAMIC || !b->pool.alloc || !b->pool.free) return 0; @@ -5470,7 +6658,6 @@ nk_buffer_alloc(struct nk_buffer *b, enum nk_buffer_allocation_type type, else unaligned = nk_ptr_add(void, b->memory.ptr, b->size - size); memory = nk_buffer_align(unaligned, align, &alignment, type); } - if (type == NK_BUFFER_FRONT) b->allocated += size + alignment; else b->size -= (size + alignment); @@ -6156,7 +7343,7 @@ nk_stroke_line(struct nk_command_buffer *b, float x0, float y0, { struct nk_command_line *cmd; NK_ASSERT(b); - if (!b) return; + if (!b || line_thickness <= 0) return; cmd = (struct nk_command_line*) nk_command_buffer_push(b, NK_COMMAND_LINE, sizeof(*cmd)); if (!cmd) return; @@ -6175,7 +7362,7 @@ nk_stroke_curve(struct nk_command_buffer *b, float ax, float ay, { struct nk_command_curve *cmd; NK_ASSERT(b); - if (!b || col.a == 0) return; + if (!b || col.a == 0 || line_thickness <= 0) return; cmd = (struct nk_command_curve*) nk_command_buffer_push(b, NK_COMMAND_CURVE, sizeof(*cmd)); @@ -6198,13 +7385,12 @@ nk_stroke_rect(struct nk_command_buffer *b, struct nk_rect rect, { struct nk_command_rect *cmd; NK_ASSERT(b); - if (!b || c.a == 0 || rect.w == 0 || rect.h == 0) return; + if (!b || c.a == 0 || rect.w == 0 || rect.h == 0 || line_thickness <= 0) return; if (b->use_clipping) { const struct nk_rect *clip = &b->clip; if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h, clip->x, clip->y, clip->w, clip->h)) return; } - cmd = (struct nk_command_rect*) nk_command_buffer_push(b, NK_COMMAND_RECT, sizeof(*cmd)); if (!cmd) return; @@ -6273,7 +7459,7 @@ nk_stroke_circle(struct nk_command_buffer *b, struct nk_rect r, float line_thickness, struct nk_color c) { struct nk_command_circle *cmd; - if (!b || r.w == 0 || r.h == 0) return; + if (!b || r.w == 0 || r.h == 0 || line_thickness <= 0) return; if (b->use_clipping) { const struct nk_rect *clip = &b->clip; if (!NK_INTERSECT(r.x, r.y, r.w, r.h, clip->x, clip->y, clip->w, clip->h)) @@ -6318,7 +7504,7 @@ nk_stroke_arc(struct nk_command_buffer *b, float cx, float cy, float radius, float a_min, float a_max, float line_thickness, struct nk_color c) { struct nk_command_arc *cmd; - if (!b || c.a == 0) return; + if (!b || c.a == 0 || line_thickness <= 0) return; cmd = (struct nk_command_arc*) nk_command_buffer_push(b, NK_COMMAND_ARC, sizeof(*cmd)); if (!cmd) return; @@ -6355,7 +7541,7 @@ nk_stroke_triangle(struct nk_command_buffer *b, float x0, float y0, float x1, { struct nk_command_triangle *cmd; NK_ASSERT(b); - if (!b || c.a == 0) return; + if (!b || c.a == 0 || line_thickness <= 0) return; if (b->use_clipping) { const struct nk_rect *clip = &b->clip; if (!NK_INBOX(x0, y0, clip->x, clip->y, clip->w, clip->h) && @@ -6414,7 +7600,7 @@ nk_stroke_polygon(struct nk_command_buffer *b, float *points, int point_count, struct nk_command_polygon *cmd; NK_ASSERT(b); - if (!b || col.a == 0) return; + if (!b || col.a == 0 || line_thickness <= 0) return; size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count; cmd = (struct nk_command_polygon*) nk_command_buffer_push(b, NK_COMMAND_POLYGON, size); if (!cmd) return; @@ -6458,7 +7644,7 @@ nk_stroke_polyline(struct nk_command_buffer *b, float *points, int point_count, struct nk_command_polyline *cmd; NK_ASSERT(b); - if (!b || col.a == 0) return; + if (!b || col.a == 0 || line_thickness <= 0) return; size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count; cmd = (struct nk_command_polyline*) nk_command_buffer_push(b, NK_COMMAND_POLYLINE, size); if (!cmd) return; @@ -6495,6 +7681,30 @@ nk_draw_image(struct nk_command_buffer *b, struct nk_rect r, cmd->col = col; } +NK_API void +nk_push_custom(struct nk_command_buffer *b, struct nk_rect r, + nk_command_custom_callback cb, nk_handle usr) +{ + struct nk_command_custom *cmd; + NK_ASSERT(b); + if (!b) return; + if (b->use_clipping) { + const struct nk_rect *c = &b->clip; + if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h)) + return; + } + + cmd = (struct nk_command_custom*) + nk_command_buffer_push(b, NK_COMMAND_CUSTOM, sizeof(*cmd)); + if (!cmd) return; + cmd->x = (short)r.x; + cmd->y = (short)r.y; + cmd->w = (unsigned short)NK_MAX(0, r.w); + cmd->h = (unsigned short)NK_MAX(0, r.h); + cmd->callback_data = usr; + cmd->callback = cb; +} + NK_API void nk_draw_text(struct nk_command_buffer *b, struct nk_rect r, const char *string, int length, const struct nk_user_font *font, @@ -6559,7 +7769,8 @@ nk_draw_list_init(struct nk_draw_list *list) NK_API void nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config *config, - struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements) + struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, + enum nk_anti_aliasing line_aa, enum nk_anti_aliasing shape_aa) { NK_ASSERT(canvas); NK_ASSERT(config); @@ -6573,6 +7784,8 @@ nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config * canvas->config = *config; canvas->elements = elements; canvas->vertices = vertices; + canvas->line_AA = line_aa; + canvas->shape_AA = shape_aa; canvas->clip_rect = nk_null_rect; } @@ -6799,7 +8012,7 @@ nk_draw_list_alloc_elements(struct nk_draw_list *list, nk_size count) return ids; } -static int +NK_INTERN int nk_draw_vertex_layout_element_is_end_of_layout( const struct nk_draw_vertex_layout_element *element) { @@ -6807,7 +8020,7 @@ nk_draw_vertex_layout_element_is_end_of_layout( element->format == NK_FORMAT_COUNT); } -static void +NK_INTERN void nk_draw_vertex_color(void *attribute, const float *values, enum nk_draw_vertex_layout_format format) { @@ -6823,6 +8036,11 @@ nk_draw_vertex_color(void *attribute, const float *values, struct nk_color col = nk_rgba_fv(values); NK_MEMCPY(attribute, &col.r, sizeof(col)); } break; + case NK_FORMAT_B8G8R8A8: { + struct nk_color col = nk_rgba_fv(values); + struct nk_color bgra = nk_rgba(col.b, col.g, col.r, col.a); + NK_MEMCPY(attribute, &bgra, sizeof(bgra)); + } break; case NK_FORMAT_R16G15B16: { nk_ushort col[3]; col[0] = (nk_ushort)NK_CLAMP(NK_USHORT_MIN, values[0] * NK_USHORT_MAX, NK_USHORT_MAX); @@ -6873,7 +8091,7 @@ nk_draw_vertex_color(void *attribute, const float *values, } } -static void +NK_INTERN void nk_draw_vertex_element(void *dst, const float *values, int value_count, enum nk_draw_vertex_layout_format format) { @@ -6993,7 +8211,6 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p nk_size size; struct nk_vec2 *normals, *temp; - NK_ASSERT(vtx && ids); if (!vtx || !ids) return; /* temporary allocate normals + points */ @@ -7371,11 +8588,40 @@ nk_draw_list_path_arc_to(struct nk_draw_list *list, struct nk_vec2 center, NK_ASSERT(list); if (!list) return; if (radius == 0.0f) return; - for (i = 0; i <= segments; ++i) { - const float a = a_min + ((float)i / ((float)segments) * (a_max - a_min)); - const float x = center.x + (float)NK_COS(a) * radius; - const float y = center.y + (float)NK_SIN(a) * radius; + + /* This algorithm for arc drawing relies on these two trigonometric identities[1]: + sin(a + b) = sin(a) * cos(b) + cos(a) * sin(b) + cos(a + b) = cos(a) * cos(b) - sin(a) * sin(b) + + Two coordinates (x, y) of a point on a circle centered on + the origin can be written in polar form as: + x = r * cos(a) + y = r * sin(a) + where r is the radius of the circle, + a is the angle between (x, y) and the origin. + + This allows us to rotate the coordinates around the + origin by an angle b using the following transformation: + x' = r * cos(a + b) = x * cos(b) - y * sin(b) + y' = r * sin(a + b) = y * cos(b) + x * sin(b) + + [1] https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Angle_sum_and_difference_identities + */ + const float d_angle = (a_max - a_min) / (float)segments; + const float sin_d = (float)NK_SIN(d_angle); + const float cos_d = (float)NK_COS(d_angle); + + float cx = (float)NK_COS(a_min) * radius; + float cy = (float)NK_SIN(a_min) * radius; + for(i = 0; i <= segments; ++i) { + const float x = center.x + cx; + const float y = center.y + cy; nk_draw_list_path_line_to(list, nk_vec2(x, y)); + + const float new_cx = cx * cos_d - cy * sin_d; + const float new_cy = cy * cos_d + cx * sin_d; + cx = new_cx; + cy = new_cy; } } @@ -7461,8 +8707,13 @@ nk_draw_list_stroke_line(struct nk_draw_list *list, struct nk_vec2 a, { NK_ASSERT(list); if (!list || !col.a) return; - nk_draw_list_path_line_to(list, nk_vec2_add(a, nk_vec2(0.5f, 0.5f))); - nk_draw_list_path_line_to(list, nk_vec2_add(b, nk_vec2(0.5f, 0.5f))); + if (list->line_AA == NK_ANTI_ALIASING_ON) { + nk_draw_list_path_line_to(list, a); + nk_draw_list_path_line_to(list, b); + } else { + nk_draw_list_path_line_to(list, nk_vec2_sub(a,nk_vec2(0.5f,0.5f))); + nk_draw_list_path_line_to(list, nk_vec2_sub(b,nk_vec2(0.5f,0.5f))); + } nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness); } @@ -7472,9 +8723,14 @@ nk_draw_list_fill_rect(struct nk_draw_list *list, struct nk_rect rect, { NK_ASSERT(list); if (!list || !col.a) return; - nk_draw_list_path_rect_to(list, nk_vec2(rect.x + 0.5f, rect.y + 0.5f), - nk_vec2(rect.x + rect.w + 0.5f, rect.y + rect.h + 0.5f), rounding); - nk_draw_list_path_fill(list, col); + + if (list->line_AA == NK_ANTI_ALIASING_ON) { + nk_draw_list_path_rect_to(list, nk_vec2(rect.x, rect.y), + nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); + } else { + nk_draw_list_path_rect_to(list, nk_vec2(rect.x-0.5f, rect.y-0.5f), + nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); + } nk_draw_list_path_fill(list, col); } NK_API void @@ -7483,9 +8739,13 @@ nk_draw_list_stroke_rect(struct nk_draw_list *list, struct nk_rect rect, { NK_ASSERT(list); if (!list || !col.a) return; - nk_draw_list_path_rect_to(list, nk_vec2(rect.x + 0.5f, rect.y + 0.5f), - nk_vec2(rect.x + rect.w + 0.5f, rect.y + rect.h + 0.5f), rounding); - nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness); + if (list->line_AA == NK_ANTI_ALIASING_ON) { + nk_draw_list_path_rect_to(list, nk_vec2(rect.x, rect.y), + nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); + } else { + nk_draw_list_path_rect_to(list, nk_vec2(rect.x-0.5f, rect.y-0.5f), + nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); + } nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness); } NK_API void @@ -7694,11 +8954,12 @@ nk_draw_list_add_text(struct nk_draw_list *list, const struct nk_user_font *font } } -NK_API void +NK_API nk_flags nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config *config) { + nk_flags res = NK_CONVERT_SUCCESS; const struct nk_command *cmd; NK_ASSERT(ctx); NK_ASSERT(cmds); @@ -7708,9 +8969,10 @@ nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, NK_ASSERT(config->vertex_layout); NK_ASSERT(config->vertex_size); if (!ctx || !cmds || !vertices || !elements || !config || !config->vertex_layout) - return; + return NK_CONVERT_INVALID_PARAM; - nk_draw_list_setup(&ctx->draw_list, config, cmds, vertices, elements); + nk_draw_list_setup(&ctx->draw_list, config, cmds, vertices, elements, + config->line_AA, config->shape_AA); nk_foreach(cmd, ctx) { #ifdef NK_INCLUDE_COMMAND_USERDATA @@ -7822,11 +9084,18 @@ nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, const struct nk_command_image *i = (const struct nk_command_image*)cmd; nk_draw_list_add_image(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); } break; + case NK_COMMAND_CUSTOM: { + const struct nk_command_custom *c = (const struct nk_command_custom*)cmd; + c->callback(&ctx->draw_list, c->x, c->y, c->w, c->h, c->callback_data); + } break; default: break; } } + res |= (cmds->needed > cmds->allocated + (cmds->memory.size - cmds->size)) ? NK_CONVERT_COMMAND_BUFFER_FULL: 0; + res |= (vertices->needed > vertices->allocated) ? NK_CONVERT_VERTEX_BUFFER_FULL: 0; + res |= (elements->needed > elements->allocated) ? NK_CONVERT_ELEMENT_BUFFER_FULL: 0; + return res; } - NK_API const struct nk_draw_command* nk__draw_begin(const struct nk_context *ctx, const struct nk_buffer *buffer) @@ -8166,7 +9435,7 @@ nk_rect_original_order(const void *a, const void *b) return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); } -static void +NK_INTERN void nk_rp_qsort(struct nk_rp_rect *array, unsigned int len, int(*cmp)(const void*,const void*)) { /* iterative quick sort */ @@ -10118,8 +11387,8 @@ nk_font_bake_pack(struct nk_font_baker *baker, int rect_n = 0; int char_n = 0; - /* pack custom user data first so it will be in the upper left corner*/ if (custom) { + /* pack custom user data first so it will be in the upper left corner*/ struct nk_rp_rect custom_space; nk_zero(&custom_space, sizeof(custom_space)); custom_space.w = (nk_rp_coord)((custom->w * 2) + 1); @@ -10430,10 +11699,9 @@ nk_font_find_glyph(struct nk_font *font, nk_rune unicode) glyph = font->fallback; count = nk_range_count(font->info.ranges); for (i = 0; i < count; ++i) { - int diff; nk_rune f = font->info.ranges[(i*2)+0]; nk_rune t = font->info.ranges[(i*2)+1]; - diff = (int)((t - f) + 1); + int diff = (int)((t - f) + 1); if (unicode >= f && unicode <= t) return &font->glyphs[((nk_rune)total_glyphs + (unicode - f))]; total_glyphs += diff; @@ -10454,6 +11722,7 @@ nk_font_init(struct nk_font *font, float pixel_height, return; baked = *baked_font; + font->fallback = 0; font->info = baked; font->scale = (float)pixel_height / (float)font->info.height; font->glyphs = &glyphs[baked_font->glyph_offset]; @@ -11235,6 +12504,7 @@ nk_font_atlas_cleanup(struct nk_font_atlas *atlas) atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob); atlas->permanent.free(atlas->permanent.userdata, iter); } + atlas->config = 0; } } @@ -11279,7 +12549,7 @@ nk_input_begin(struct nk_context *ctx) in->mouse.buttons[i].clicked = 0; in->keyboard.text_len = 0; - in->mouse.scroll_delta = 0; + in->mouse.scroll_delta = nk_vec2(0,0); in->mouse.prev.x = in->mouse.pos.x; in->mouse.prev.y = in->mouse.pos.y; in->mouse.delta.x = 0; @@ -11324,8 +12594,9 @@ nk_input_key(struct nk_context *ctx, enum nk_keys key, int down) NK_ASSERT(ctx); if (!ctx) return; in = &ctx->input; + if (in->keyboard.keys[key].down != down) + in->keyboard.keys[key].clicked++; in->keyboard.keys[key].down = down; - in->keyboard.keys[key].clicked++; } NK_API void @@ -11346,11 +12617,12 @@ nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, int do } NK_API void -nk_input_scroll(struct nk_context *ctx, float y) +nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val) { NK_ASSERT(ctx); if (!ctx) return; - ctx->input.mouse.scroll_delta += y; + ctx->input.mouse.scroll_delta.x += val.x; + ctx->input.mouse.scroll_delta.y += val.y; } NK_API void @@ -11918,23 +13190,14 @@ nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len) if (!text || !total_len || state->mode == NK_TEXT_EDIT_MODE_VIEW) return; glyph_len = nk_utf_decode(text, &unicode, total_len); - if (!glyph_len) return; while ((text_len < total_len) && glyph_len) { /* don't insert a backward delete, just process the event */ - if (unicode == 127) - break; - + if (unicode == 127) goto next; /* can't add newline in single-line mode */ - if (unicode == '\n' && state->single_line) - break; - + if (unicode == '\n' && state->single_line) goto next; /* filter incoming text */ - if (state->filter && !state->filter(state, unicode)) { - glyph_len = nk_utf_decode(text + text_len, &unicode, total_len-text_len); - text_len += glyph_len; - continue; - } + if (state->filter && !state->filter(state, unicode)) goto next; if (!NK_TEXT_HAS_SELECTION(state) && state->cursor < state->string.len) @@ -11959,8 +13222,9 @@ nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len) state->has_preferred_x = 0; } } - glyph_len = nk_utf_decode(text + text_len, &unicode, total_len-text_len); + next: text_len += glyph_len; + glyph_len = nk_utf_decode(text + text_len, &unicode, total_len-text_len); } } @@ -12560,6 +13824,7 @@ nk_textedit_init_fixed(struct nk_text_edit *state, void *memory, nk_size size) NK_ASSERT(state); NK_ASSERT(memory); if (!state || !memory || !size) return; + NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); nk_str_init_fixed(&state->string, memory, size); } @@ -12570,6 +13835,7 @@ nk_textedit_init(struct nk_text_edit *state, struct nk_allocator *alloc, nk_size NK_ASSERT(state); NK_ASSERT(alloc); if (!state || !alloc) return; + NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); nk_str_init(&state->string, alloc, size); } @@ -12580,6 +13846,7 @@ nk_textedit_init_default(struct nk_text_edit *state) { NK_ASSERT(state); if (!state) return; + NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); nk_str_init_default(&state->string); } @@ -13422,8 +14689,7 @@ nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, NK_INTERN float nk_slider_behavior(nk_flags *state, struct nk_rect *logical_cursor, struct nk_rect *visual_cursor, struct nk_input *in, - const struct nk_style_slider *style, struct nk_rect bounds, - float slider_min, float slider_max, float slider_value, + struct nk_rect bounds, float slider_min, float slider_max, float slider_value, float slider_step, float slider_steps) { int left_mouse_down; @@ -13605,7 +14871,7 @@ nk_do_slider(nk_flags *state, visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f; slider_value = nk_slider_behavior(state, &logical_cursor, &visual_cursor, - in, style, bounds, slider_min, slider_max, slider_value, step, slider_steps); + in, bounds, slider_min, slider_max, slider_value, step, slider_steps); visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f; /* draw slider */ @@ -13678,7 +14944,7 @@ nk_draw_progress(struct nk_command_buffer *out, nk_flags state, } else nk_draw_image(out, *bounds, &background->data.image, nk_white); /* draw cursor */ - if (background->type == NK_STYLE_ITEM_COLOR) { + if (cursor->type == NK_STYLE_ITEM_COLOR) { nk_fill_rect(out, *scursor, style->rounding, cursor->data.color); nk_stroke_rect(out, *scursor, style->rounding, style->border, style->border_color); } else nk_draw_image(out, *scursor, &cursor->data.image, nk_white); @@ -13728,9 +14994,10 @@ nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, const struct nk_rect *empty1, float scroll_offset, float target, float scroll_step, enum nk_orientation o) { - nk_flags ws; + nk_flags ws = 0; int left_mouse_down; int left_mouse_click_in_cursor; + float scroll_delta; nk_widget_state_reset(state); if (!in) return scroll_offset; @@ -13741,6 +15008,7 @@ nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, if (nk_input_is_mouse_hovering_rect(in, *scroll)) *state = NK_WIDGET_STATE_HOVERED; + scroll_delta = (o == NK_VERTICAL) ? in->mouse.scroll_delta.y: in->mouse.scroll_delta.x; if (left_mouse_down && left_mouse_click_in_cursor) { /* update cursor by mouse dragging */ float pixel, delta; @@ -13773,9 +15041,9 @@ nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, scroll_offset = NK_MIN(scroll_offset + scroll->h, target - scroll->h); else scroll_offset = NK_MIN(scroll_offset + scroll->w, target - scroll->w); } else if (has_scrolling) { - if ((in->mouse.scroll_delta<0 || (in->mouse.scroll_delta>0))) { + if ((scroll_delta < 0 || (scroll_delta > 0))) { /* update cursor by mouse scrolling */ - scroll_offset = scroll_offset + scroll_step * (-in->mouse.scroll_delta); + scroll_offset = scroll_offset + scroll_step * (-scroll_delta); if (o == NK_VERTICAL) scroll_offset = NK_CLAMP(0, scroll_offset, target - scroll->h); else scroll_offset = NK_CLAMP(0, scroll_offset, target - scroll->w); @@ -13851,7 +15119,7 @@ nk_do_scrollbarv(nk_flags *state, if (!out || !style) return 0; scroll.w = NK_MAX(scroll.w, 1); - scroll.h = NK_MAX(scroll.h, 2 * scroll.w); + scroll.h = NK_MAX(scroll.h, 0); if (target <= scroll.h) return 0; /* optional scrollbar buttons */ @@ -13864,7 +15132,7 @@ nk_do_scrollbarv(nk_flags *state, button.w = scroll.w; button.h = scroll.w; - scroll_h = scroll.h - 2 * button.h; + scroll_h = NK_MAX(scroll.h - 2 * button.h,0); scroll_step = NK_MIN(step, button_pixel_inc); /* decrement button */ @@ -13890,7 +15158,7 @@ nk_do_scrollbarv(nk_flags *state, scroll_off = scroll_offset / target; /* calculate scrollbar cursor bounds */ - cursor.h = (scroll_ratio * scroll.h) - (2*style->border + 2*style->padding.y); + cursor.h = NK_MAX((scroll_ratio * scroll.h) - (2*style->border + 2*style->padding.y), 0); cursor.y = scroll.y + (scroll_off * scroll.h) + style->border + style->padding.y; cursor.w = scroll.w - (2 * style->border + 2 * style->padding.x); cursor.x = scroll.x + style->border + style->padding.x; @@ -13899,12 +15167,12 @@ nk_do_scrollbarv(nk_flags *state, empty_north.x = scroll.x; empty_north.y = scroll.y; empty_north.w = scroll.w; - empty_north.h = cursor.y - scroll.y; + empty_north.h = NK_MAX(cursor.y - scroll.y, 0); empty_south.x = scroll.x; empty_south.y = cursor.y + cursor.h; empty_south.w = scroll.w; - empty_south.h = (scroll.y + scroll.h) - (cursor.y + cursor.h); + empty_south.h = NK_MAX((scroll.y + scroll.h) - (cursor.y + cursor.h), 0); /* update scrollbar */ scroll_offset = nk_scrollbar_behavior(state, in, has_scrolling, &scroll, &cursor, @@ -14107,7 +15375,7 @@ nk_edit_draw_text(struct nk_command_buffer *out, while ((text_len < byte_len) && glyph_len) { if (unicode == '\n') { - /* new line sepeator so draw previous line */ + /* new line separator so draw previous line */ struct nk_rect label; label.y = pos_y + line_offset; label.h = row_height; @@ -14549,7 +15817,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, const char *begin = nk_str_get_const(&edit->string); int l = nk_str_len_char(&edit->string); nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, - area.y - edit->scrollbar.y, 0, begin, l, row_height, font, + area.y - edit->scrollbar.y, 0, begin, l, row_height, font, background_color, text_color, nk_false); } else { /* edit has selection so draw 1-3 text chunks */ @@ -14789,9 +16057,11 @@ nk_do_property(nk_flags *ws, struct nk_command_buffer *out, struct nk_rect property, const char *name, struct nk_property_variant *variant, float inc_per_pixel, char *buffer, int *len, - int *state, int *cursor, const struct nk_style_property *style, + int *state, int *cursor, int *select_begin, int *select_end, + const struct nk_style_property *style, enum nk_property_filter filter, struct nk_input *in, - const struct nk_user_font *font, struct nk_text_edit *text_edit) + const struct nk_user_font *font, struct nk_text_edit *text_edit, + enum nk_button_behavior behavior) { const nk_plugin_filter filters[] = { nk_filter_decimal, @@ -14880,7 +16150,7 @@ nk_do_property(nk_flags *ws, if (style->draw_end) style->draw_end(out, style->userdata); /* execute right button */ - if (nk_do_button_symbol(ws, out, left, style->sym_left, NK_BUTTON_DEFAULT, &style->dec_button, in, font)) { + if (nk_do_button_symbol(ws, out, left, style->sym_left, behavior, &style->dec_button, in, font)) { switch (variant->kind) { default: break; case NK_PROPERTY_INT: @@ -14891,9 +16161,8 @@ nk_do_property(nk_flags *ws, variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d - variant->step.d, variant->max_value.d); break; } } - /* execute left button */ - if (nk_do_button_symbol(ws, out, right, style->sym_right, NK_BUTTON_DEFAULT, &style->inc_button, in, font)) { + if (nk_do_button_symbol(ws, out, right, style->sym_right, behavior, &style->inc_button, in, font)) { switch (variant->kind) { default: break; case NK_PROPERTY_INT: @@ -14904,38 +16173,39 @@ nk_do_property(nk_flags *ws, variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d); break; } } - - active = (*state == NK_PROPERTY_EDIT); - if (old != NK_PROPERTY_EDIT && active) { + if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) { /* property has been activated so setup buffer */ NK_MEMCPY(buffer, dst, (nk_size)*length); *cursor = nk_utf_len(buffer, *length); *len = *length; length = len; dst = buffer; - } + active = 0; + } else active = (*state == NK_PROPERTY_EDIT); /* execute and run text edit field */ nk_textedit_clear_state(text_edit, NK_TEXT_EDIT_SINGLE_LINE, filters[filter]); text_edit->active = (unsigned char)active; text_edit->string.len = *length; text_edit->cursor = NK_CLAMP(0, *cursor, *length); + text_edit->select_start = NK_CLAMP(0,*select_begin, *length); + text_edit->select_end = NK_CLAMP(0,*select_end, *length); text_edit->string.buffer.allocated = (nk_size)*length; text_edit->string.buffer.memory.size = NK_MAX_NUMBER_BUFFER; text_edit->string.buffer.memory.ptr = dst; text_edit->string.buffer.size = NK_MAX_NUMBER_BUFFER; text_edit->mode = NK_TEXT_EDIT_MODE_INSERT; - nk_do_edit(ws, out, edit, NK_EDIT_ALWAYS_INSERT_MODE, filters[filter], - text_edit, &style->edit, (*state == NK_PROPERTY_EDIT) ? in: 0, font); + nk_do_edit(ws, out, edit, NK_EDIT_FIELD|NK_EDIT_AUTO_SELECT, + filters[filter], text_edit, &style->edit, (*state == NK_PROPERTY_EDIT) ? in: 0, font); *length = text_edit->string.len; - active = text_edit->active; *cursor = text_edit->cursor; + *select_begin = text_edit->select_start; + *select_end = text_edit->select_end; + if (text_edit->active && nk_input_is_key_pressed(in, NK_KEY_ENTER)) + text_edit->active = nk_false; - if (active && nk_input_is_key_pressed(in, NK_KEY_ENTER)) - active = !active; - - if (old && !active) { + if (active && !text_edit->active) { /* property is now not active so convert edit text to value*/ *state = NK_PROPERTY_DEFAULT; buffer[*len] = '\0'; @@ -15725,6 +16995,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) win->tooltip_border = 1.0f; win->popup_border = 1.0f; win->border = 2.0f; + win->min_row_height_padding = 8; win->padding = nk_vec2(4,4); win->group_padding = nk_vec2(4,4); @@ -15740,14 +17011,17 @@ nk_style_set_font(struct nk_context *ctx, const struct nk_user_font *font) { struct nk_style *style; NK_ASSERT(ctx); + if (!ctx) return; style = &ctx->style; style->font = font; ctx->stacks.fonts.head = 0; + if (ctx->current) + nk_layout_reset_min_row_height(ctx); } NK_API int -nk_style_push_font(struct nk_context *ctx, struct nk_user_font *font) +nk_style_push_font(struct nk_context *ctx, const struct nk_user_font *font) { struct nk_config_stack_user_font *font_stack; struct nk_config_stack_user_font_element *element; @@ -15889,7 +17163,7 @@ nk_style_load_all_cursors(struct nk_context *ctx, struct nk_cursor *cursors) * ===============================================================*/ NK_INTERN void nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, - unsigned int capacity) + unsigned int capacity) { nk_zero(pool, sizeof(*pool)); pool->alloc = *alloc; @@ -15901,12 +17175,11 @@ nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, NK_INTERN void nk_pool_free(struct nk_pool *pool) { - struct nk_page *next; struct nk_page *iter = pool->pages; if (!pool) return; if (pool->type == NK_BUFFER_FIXED) return; while (iter) { - next = iter->next; + struct nk_page *next = iter->next; pool->alloc.free(pool->alloc.userdata, iter); iter = next; } @@ -16099,19 +17372,21 @@ nk_clear(struct nk_context *ctx) iter = iter->next; continue; } - /* remove hotness from hidden or closed windows*/ if (((iter->flags & NK_WINDOW_HIDDEN) || (iter->flags & NK_WINDOW_CLOSED)) && - iter == ctx->active) - ctx->active = iter->next; + iter == ctx->active) { + ctx->active = iter->prev; + ctx->end = iter->prev; + if (ctx->active) + ctx->active->flags &= ~NK_WINDOW_ROM; + } /* free unused popup windows */ if (iter->popup.win && iter->popup.win->seq != ctx->seq) { nk_free_window(ctx, iter->popup.win); iter->popup.win = 0; } - /* remove unused window state tables */ {struct nk_table *n, *it = iter->tables; while (it) { @@ -16125,7 +17400,6 @@ nk_clear(struct nk_context *ctx) } it = n; }} - /* window itself is not used anymore so free */ if (iter->seq != ctx->seq || iter->flags & NK_WINDOW_CLOSED) { next = iter->next; @@ -16166,18 +17440,12 @@ NK_INTERN void nk_start_popup(struct nk_context *ctx, struct nk_window *win) { struct nk_popup_buffer *buf; - struct nk_panel *iter; NK_ASSERT(ctx); NK_ASSERT(win); if (!ctx || !win) return; - /* make sure to use the correct popup buffer*/ - iter = win->layout; - while (iter->parent) - iter = iter->parent; - /* save buffer fill state for popup */ - buf = &iter->popup_buffer; + buf = &win->popup.buf; buf->begin = win->buffer.end; buf->end = win->buffer.end; buf->parent = win->buffer.last; @@ -16189,17 +17457,11 @@ NK_INTERN void nk_finish_popup(struct nk_context *ctx, struct nk_window *win) { struct nk_popup_buffer *buf; - struct nk_panel *iter; NK_ASSERT(ctx); NK_ASSERT(win); if (!ctx || !win) return; - /* make sure to use the correct popup buffer*/ - iter = win->layout; - while (iter->parent) - iter = iter->parent; - - buf = &iter->popup_buffer; + buf = &win->popup.buf; buf->last = win->buffer.last; buf->end = win->buffer.end; } @@ -16218,41 +17480,26 @@ nk_finish(struct nk_context *ctx, struct nk_window *win) { struct nk_popup_buffer *buf; struct nk_command *parent_last; - struct nk_command *sublast; - struct nk_command *last; void *memory; NK_ASSERT(ctx); NK_ASSERT(win); if (!ctx || !win) return; nk_finish_buffer(ctx, &win->buffer); - if (!win->layout->popup_buffer.active) return; + if (!win->popup.buf.active) return; - /* from here on is for popup window buffer handling */ - /*--------------------------------------------------*/ - buf = &win->layout->popup_buffer; + buf = &win->popup.buf; memory = ctx->memory.memory.ptr; - - /* redirect the sub-window buffer to the end of the window command buffer */ parent_last = nk_ptr_add(struct nk_command, memory, buf->parent); - sublast = nk_ptr_add(struct nk_command, memory, buf->last); - last = nk_ptr_add(struct nk_command, memory, win->buffer.last); - parent_last->next = buf->end; - sublast->next = last->next; - last->next = buf->begin; - win->buffer.last = buf->last; - win->buffer.end = buf->end; - buf->active = nk_false; } NK_INTERN void nk_build(struct nk_context *ctx) { - struct nk_window *iter; - struct nk_window *next; - struct nk_command *cmd; - nk_byte *buffer; + struct nk_window *iter = 0; + struct nk_command *cmd = 0; + nk_byte *buffer = 0; /* draw cursor overlay */ if (!ctx->style.cursor_active) @@ -16271,29 +17518,42 @@ nk_build(struct nk_context *ctx) nk_draw_image(&ctx->overlay, mouse_bounds, &cursor->img, nk_white); nk_finish_buffer(ctx, &ctx->overlay); } - - /* build one big draw command list out of all buffers */ + /* build one big draw command list out of all window buffers */ iter = ctx->begin; buffer = (nk_byte*)ctx->memory.memory.ptr; while (iter != 0) { - next = iter->next; - if (iter->buffer.last == iter->buffer.begin || (iter->flags & NK_WINDOW_HIDDEN)) { - iter = next; - continue; - } + struct nk_window *next = iter->next; + if (iter->buffer.last == iter->buffer.begin || (iter->flags & NK_WINDOW_HIDDEN)|| + iter->seq != ctx->seq) + goto cont; + cmd = nk_ptr_add(struct nk_command, buffer, iter->buffer.last); while (next && ((next->buffer.last == next->buffer.begin) || (next->flags & NK_WINDOW_HIDDEN))) next = next->next; /* skip empty command buffers */ - if (next) { - cmd->next = next->buffer.begin; - } else { - if (ctx->overlay.end != ctx->overlay.begin) - cmd->next = ctx->overlay.begin; - else cmd->next = ctx->memory.allocated; - } - iter = next; + if (next) cmd->next = next->buffer.begin; + cont: iter = next; + } + /* append all popup draw commands into lists */ + iter = ctx->begin; + while (iter != 0) { + struct nk_window *next = iter->next; + struct nk_popup_buffer *buf; + if (!iter->popup.buf.active) + goto skip; + + buf = &iter->popup.buf; + cmd->next = buf->begin; + cmd = nk_ptr_add(struct nk_command, buffer, buf->last); + buf->active = nk_false; + skip: iter = next; + } + /* append overlay commands */ + if (cmd) { + if (ctx->overlay.end != ctx->overlay.begin) + cmd->next = ctx->overlay.begin; + else cmd->next = ctx->memory.allocated; } } @@ -16311,7 +17571,6 @@ nk__begin(struct nk_context *ctx) nk_build(ctx); ctx->build = nk_true; } - iter = ctx->begin; while (iter && ((iter->buffer.begin == iter->buffer.end) || (iter->flags & NK_WINDOW_HIDDEN))) iter = iter->next; @@ -16340,7 +17599,6 @@ nk__next(struct nk_context *ctx, const struct nk_command *cmd) static int nk_panel_has_header(nk_flags flags, const char *title) { - /* window header state */ int active = 0; active = (flags & (NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE)); active = active || (flags & NK_WINDOW_TITLE); @@ -16425,20 +17683,21 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return 0; nk_zero(ctx->current->layout, sizeof(*ctx->current->layout)); - if (ctx->current->flags & NK_WINDOW_HIDDEN) + if ((ctx->current->flags & NK_WINDOW_HIDDEN) || (ctx->current->flags & NK_WINDOW_CLOSED)) { + nk_zero(ctx->current->layout, sizeof(struct nk_panel)); + ctx->current->layout->type = panel_type; return 0; - + } /* pull state into local stack */ style = &ctx->style; font = style->font; - in = &ctx->input; win = ctx->current; layout = win->layout; out = &win->buffer; + in = (win->flags & NK_WINDOW_NO_INPUT) ? 0: &ctx->input; #ifdef NK_INCLUDE_COMMAND_USERDATA win->buffer.userdata = ctx->userdata; #endif - /* pull style configuration into local stack */ scrollbar_size = style->window.scrollbar_size; panel_padding = nk_panel_get_padding(style, panel_type); @@ -16486,6 +17745,7 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan layout->max_x = 0; layout->header_height = 0; layout->footer_height = 0; + nk_layout_reset_min_row_height(ctx); layout->row.index = 0; layout->row.columns = 0; layout->row.ratio = 0; @@ -16564,7 +17824,6 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan &style->window.header.close_button, in, style->font) && !(win->flags & NK_WINDOW_ROM)) { layout->flags |= NK_WINDOW_HIDDEN; - layout->flags |= NK_WINDOW_CLOSED; layout->flags &= (nk_flags)~NK_WINDOW_MINIMIZED; } } @@ -16602,6 +17861,7 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan label.y = header.y + style->window.header.label_padding.y; label.h = font->height + 2 * style->window.header.label_padding.y; label.w = t + 2 * style->window.header.spacing.x; + label.w = NK_CLAMP(0, label.w, header.x + header.w - label.x); nk_widget_text(out, label,(const char*)title, text_len, &text, NK_TEXT_LEFT, font);} } @@ -16649,7 +17909,7 @@ nk_panel_end(struct nk_context *ctx) layout = window->layout; style = &ctx->style; out = &window->buffer; - in = (layout->flags & NK_WINDOW_ROM) ? 0 :&ctx->input; + in = (layout->flags & NK_WINDOW_ROM || layout->flags & NK_WINDOW_NO_INPUT) ? 0 :&ctx->input; if (!nk_panel_is_sub(layout->type)) nk_push_scissor(out, nk_null_rect); @@ -16712,6 +17972,44 @@ nk_panel_end(struct nk_context *ctx) float scroll_offset; float scroll_step; float scroll_inc; + + /* mouse wheel scrolling */ + if (nk_panel_is_sub(layout->type)) + { + /* sub-window mouse wheel scrolling */ + struct nk_window *root_window = window; + struct nk_panel *root_panel = window->layout; + while (root_panel->parent) + root_panel = root_panel->parent; + while (root_window->parent) + root_window = root_window->parent; + + /* only allow scrolling if parent window is active */ + scroll_has_scrolling = 0; + if ((root_window == ctx->active) && layout->has_scrolling) { + /* and panel is being hovered and inside clip rect*/ + if (nk_input_is_mouse_hovering_rect(in, layout->bounds) && + NK_INTERSECT(layout->bounds.x, layout->bounds.y, layout->bounds.w, layout->bounds.h, + root_panel->clip.x, root_panel->clip.y, root_panel->clip.w, root_panel->clip.h)) + { + /* deactivate all parent scrolling */ + root_panel = window->layout; + while (root_panel->parent) { + root_panel->has_scrolling = nk_false; + root_panel = root_panel->parent; + } + root_panel->has_scrolling = nk_false; + scroll_has_scrolling = nk_true; + } + } + } else if (!nk_panel_is_sub(layout->type)) { + /* window mouse wheel scrolling */ + scroll_has_scrolling = (window == ctx->active) && layout->has_scrolling; + if (in && (in->mouse.scroll_delta.y > 0 || in->mouse.scroll_delta.x > 0) && scroll_has_scrolling) + window->scrolled = nk_true; + else window->scrolled = nk_false; + } else scroll_has_scrolling = nk_false; + { /* vertical scrollbar */ nk_flags state = 0; @@ -16724,51 +18022,12 @@ nk_panel_end(struct nk_context *ctx) scroll_step = scroll.h * 0.10f; scroll_inc = scroll.h * 0.01f; scroll_target = (float)(int)(layout->at_y - scroll.y); - - /* scrolling by mouse wheel */ - if (nk_panel_is_sub(layout->type)) - { - /* sub-window scrollbar wheel scrolling */ - struct nk_window *root_window = window; - struct nk_panel *root_panel = window->layout; - while (root_panel->parent) - root_panel = root_panel->parent; - while (root_window->parent) - root_window = root_window->parent; - - /* only allow scrolling if parent window is active */ - scroll_has_scrolling = 0; - if ((root_window == ctx->active) && layout->has_scrolling) { - /* and panel is being hovered and inside clip rect*/ - if (nk_input_is_mouse_hovering_rect(in, layout->bounds) && - NK_INTERSECT(layout->bounds.x, layout->bounds.y, layout->bounds.w, layout->bounds.h, - root_panel->clip.x, root_panel->clip.y, root_panel->clip.w, root_panel->clip.h)) - { - /* deactivate all parent scrolling */ - root_panel = window->layout; - while (root_panel->parent) { - root_panel->has_scrolling = nk_false; - root_panel = root_panel->parent; - } - root_panel->has_scrolling = nk_false; - scroll_has_scrolling = nk_true; - } - } - } else if (!nk_panel_is_sub(layout->type)) { - /* window scrollbar wheel scrolling */ - scroll_has_scrolling = (window == ctx->active) && layout->has_scrolling; - if (in && in->mouse.scroll_delta > 0 && scroll_has_scrolling) - window->scrolled = nk_true; - else window->scrolled = nk_false; - } else scroll_has_scrolling = nk_false; - - /* execute scrollbar */ scroll_offset = nk_do_scrollbarv(&state, out, scroll, scroll_has_scrolling, - scroll_offset, scroll_target, scroll_step, scroll_inc, - &ctx->style.scrollv, in, style->font); + scroll_offset, scroll_target, scroll_step, scroll_inc, + &ctx->style.scrollv, in, style->font); *layout->offset_y = (nk_uint)scroll_offset; if (in && scroll_has_scrolling) - in->mouse.scroll_delta = 0; + in->mouse.scroll_delta.y = 0; } { /* horizontal scrollbar */ @@ -16782,17 +18041,16 @@ nk_panel_end(struct nk_context *ctx) scroll_target = (float)(int)(layout->max_x - scroll.x); scroll_step = layout->max_x * 0.05f; scroll_inc = layout->max_x * 0.005f; - scroll_has_scrolling = nk_false; scroll_offset = nk_do_scrollbarh(&state, out, scroll, scroll_has_scrolling, - scroll_offset, scroll_target, scroll_step, scroll_inc, - &ctx->style.scrollh, in, style->font); + scroll_offset, scroll_target, scroll_step, scroll_inc, + &ctx->style.scrollh, in, style->font); *layout->offset_x = (nk_uint)scroll_offset; } } /* hide scroll if no user input */ if (window->flags & NK_WINDOW_SCROLL_AUTO_HIDE) { - int has_input = ctx->input.mouse.delta.x != 0 || ctx->input.mouse.delta.y != 0 || ctx->input.mouse.scroll_delta != 0; + int has_input = ctx->input.mouse.delta.x != 0 || ctx->input.mouse.delta.y != 0 || ctx->input.mouse.scroll_delta.y != 0; int is_window_hovered = nk_window_is_hovered(ctx); int any_item_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED); if ((!has_input && is_window_hovered) || (!is_window_hovered && !any_item_active)) @@ -16866,24 +18124,34 @@ nk_panel_end(struct nk_context *ctx) int left_mouse_click_in_scaler = nk_input_has_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, scaler, nk_true); - if (nk_input_is_mouse_down(in, NK_BUTTON_LEFT) && left_mouse_down && left_mouse_click_in_scaler) { + if (left_mouse_down && left_mouse_click_in_scaler) { float delta_x = in->mouse.delta.x; if (layout->flags & NK_WINDOW_SCALE_LEFT) { - delta_x =- delta_x; + delta_x = -delta_x; window->bounds.x += in->mouse.delta.x; } - window->bounds.w = NK_MAX(window_size.x, window->bounds.w + delta_x); - - /* dragging in y-direction is only possible if static window */ - if (!(layout->flags & NK_WINDOW_DYNAMIC)) - window->bounds.h = NK_MAX(window_size.y, window->bounds.h + in->mouse.delta.y); + /* dragging in x-direction */ + if (window->bounds.w + delta_x >= window_size.x) { + if ((delta_x < 0) || (delta_x > 0 && in->mouse.pos.x >= scaler.x)) { + window->bounds.w = window->bounds.w + delta_x; + scaler.x += in->mouse.delta.x; + } + } + /* dragging in y-direction (only possible if static window) */ + if (!(layout->flags & NK_WINDOW_DYNAMIC)) { + if (window_size.y < window->bounds.h + in->mouse.delta.y) { + if ((in->mouse.delta.y < 0) || (in->mouse.delta.y > 0 && in->mouse.pos.y >= scaler.y)) { + window->bounds.h = window->bounds.h + in->mouse.delta.y; + scaler.y += in->mouse.delta.y; + } + } + } ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT]; - in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = scaler.x + in->mouse.delta.x + scaler.w/2.0f; - in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y = scaler.y + in->mouse.delta.y + scaler.h/2.0f; + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = scaler.x + scaler.w/2.0f; + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y = scaler.y + scaler.h/2.0f; } } } - if (!nk_panel_is_sub(layout->type)) { /* window is hidden so clear command buffer */ if (layout->flags & NK_WINDOW_HIDDEN) @@ -16908,7 +18176,6 @@ nk_panel_end(struct nk_context *ctx) window->property.prev = window->property.active; window->property.seq = 0; } - /* edit garbage collector */ if (window->edit.active && window->edit.old != window->edit.seq && window->edit.active == window->edit.prev) { @@ -16918,7 +18185,6 @@ nk_panel_end(struct nk_context *ctx) window->edit.prev = window->edit.active; window->edit.seq = 0; } - /* contextual garbage collector */ if (window->popup.active_con && window->popup.con_old != window->popup.con_count) { window->popup.con_count = 0; @@ -16929,8 +18195,7 @@ nk_panel_end(struct nk_context *ctx) window->popup.con_count = 0; } window->popup.combo_count = 0; - - /* helper to make sure you have a 'nk_tree_push' * for every 'nk_tree_pop' */ + /* helper to make sure you have a 'nk_tree_push' for every 'nk_tree_pop' */ NK_ASSERT(!layout->row.tree_depth); } @@ -16953,7 +18218,7 @@ nk_create_page_element(struct nk_context *ctx) NK_ASSERT(elem); if (!elem) return 0; } else { - /* allocate new page element from the back of the fixed size memory buffer */ + /* allocate new page element from back of fixed size memory buffer */ NK_STORAGE const nk_size size = sizeof(struct nk_page_element); NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_page_element); elem = (struct nk_page_element*)nk_buffer_alloc(&ctx->memory, NK_BUFFER_BACK, size, align); @@ -16987,7 +18252,6 @@ nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem) nk_link_page_element_into_freelist(ctx, elem); return; } - /* if possible remove last element from back of fixed memory buffer */ {void *elem_end = (void*)(elem + 1); void *buffer_end = (nk_byte*)ctx->memory.memory.ptr + ctx->memory.size; @@ -17049,16 +18313,16 @@ nk_push_table(struct nk_window *win, struct nk_table *tbl) win->tables = tbl; tbl->next = 0; tbl->prev = 0; + tbl->size = 0; win->table_count = 1; - win->table_size = 0; return; } win->tables->prev = tbl; tbl->next = win->tables; tbl->prev = 0; + tbl->size = 0; win->tables = tbl; win->table_count++; - win->table_size = 0; } NK_INTERN void @@ -17081,32 +18345,31 @@ nk_add_value(struct nk_context *ctx, struct nk_window *win, NK_ASSERT(ctx); NK_ASSERT(win); if (!win || !ctx) return 0; - if (!win->tables || win->table_size >= NK_VALUE_PAGE_CAPACITY) { + if (!win->tables || win->tables->size >= NK_VALUE_PAGE_CAPACITY) { struct nk_table *tbl = nk_create_table(ctx); NK_ASSERT(tbl); if (!tbl) return 0; nk_push_table(win, tbl); } win->tables->seq = win->seq; - win->tables->keys[win->table_size] = name; - win->tables->values[win->table_size] = value; - return &win->tables->values[win->table_size++]; + win->tables->keys[win->tables->size] = name; + win->tables->values[win->tables->size] = value; + return &win->tables->values[win->tables->size++]; } NK_INTERN nk_uint* nk_find_value(struct nk_window *win, nk_hash name) { - nk_ushort size = win->table_size; struct nk_table *iter = win->tables; while (iter) { - nk_ushort i = 0; + unsigned int i = 0; + unsigned int size = iter->size; for (i = 0; i < size; ++i) { if (iter->keys[i] == name) { iter->seq = win->seq; return &iter->values[i]; } - } - size = NK_VALUE_PAGE_CAPACITY; + } size = NK_VALUE_PAGE_CAPACITY; iter = iter->next; } return 0; @@ -17131,7 +18394,7 @@ NK_INTERN void nk_free_window(struct nk_context *ctx, struct nk_window *win) { /* unlink windows from list */ - struct nk_table *n, *it = win->tables; + struct nk_table *it = win->tables; if (win->popup.win) { nk_free_window(ctx, win->popup.win); win->popup.win = 0; @@ -17141,7 +18404,7 @@ nk_free_window(struct nk_context *ctx, struct nk_window *win) while (it) { /*free window state tables */ - n = it->next; + struct nk_table *n = it->next; nk_remove_table(win, it); nk_free_table(ctx, it); if (it == win->tables) @@ -17212,7 +18475,7 @@ nk_insert_window(struct nk_context *ctx, struct nk_window *win, ctx->active = ctx->end; ctx->end->flags &= ~(nk_flags)NK_WINDOW_ROM; } else { - ctx->end->flags |= NK_WINDOW_ROM; + /*ctx->end->flags |= NK_WINDOW_ROM;*/ ctx->begin->prev = win; win->next = ctx->begin; win->prev = 0; @@ -17318,19 +18581,22 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, * provided demo backends). */ NK_ASSERT(win->seq != ctx->seq); win->seq = ctx->seq; - if (!ctx->active && !(win->flags & NK_WINDOW_HIDDEN)) + if (!ctx->active && !(win->flags & NK_WINDOW_HIDDEN)) { ctx->active = win; + ctx->end = win; + } } if (win->flags & NK_WINDOW_HIDDEN) { ctx->current = win; + win->layout = 0; return 0; } /* window overlapping */ - if (!(win->flags & NK_WINDOW_HIDDEN)) + if (!(win->flags & NK_WINDOW_HIDDEN) && !(win->flags & NK_WINDOW_NO_INPUT)) { int inpanel, ishovered; - const struct nk_window *iter = win; + struct nk_window *iter = win; float h = ctx->style.font->height + 2.0f * style->window.header.padding.y + (2.0f * style->window.header.label_padding.y); struct nk_rect win_bounds = (!(win->flags & NK_WINDOW_MINIMIZED))? @@ -17348,7 +18614,7 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, iter->bounds: nk_rect(iter->bounds.x, iter->bounds.y, iter->bounds.w, h); if (NK_INTERSECT(win_bounds.x, win_bounds.y, win_bounds.w, win_bounds.h, iter_bounds.x, iter_bounds.y, iter_bounds.w, iter_bounds.h) && - (!(iter->flags & NK_WINDOW_HIDDEN) || !(iter->flags & NK_WINDOW_BACKGROUND))) + (!(iter->flags & NK_WINDOW_HIDDEN))) break; if (iter->popup.win && iter->popup.active && !(iter->flags & NK_WINDOW_HIDDEN) && @@ -17361,7 +18627,7 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, } /* activate window if clicked */ - if (iter && inpanel && (win != ctx->end) && !(iter->flags & NK_WINDOW_BACKGROUND)) { + if (iter && inpanel && (win != ctx->end)) { iter = win->next; while (iter) { /* try to find a panel with higher priority in the same position */ @@ -17379,19 +18645,30 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, iter = iter->next; } } - - if (!iter && ctx->end != win) { - if (!(win->flags & NK_WINDOW_BACKGROUND)) { + if (iter && !(win->flags & NK_WINDOW_ROM) && (win->flags & NK_WINDOW_BACKGROUND)) { + win->flags |= (nk_flags)NK_WINDOW_ROM; + iter->flags &= ~(nk_flags)NK_WINDOW_ROM; + ctx->active = iter; + if (!(iter->flags & NK_WINDOW_BACKGROUND)) { /* current window is active in that position so transfer to top * at the highest priority in stack */ - nk_remove_window(ctx, win); - nk_insert_window(ctx, win, NK_INSERT_BACK); + nk_remove_window(ctx, iter); + nk_insert_window(ctx, iter, NK_INSERT_BACK); } - win->flags &= ~(nk_flags)NK_WINDOW_ROM; - ctx->active = win; + } else { + if (!iter && ctx->end != win) { + if (!(win->flags & NK_WINDOW_BACKGROUND)) { + /* current window is active in that position so transfer to top + * at the highest priority in stack */ + nk_remove_window(ctx, win); + nk_insert_window(ctx, win, NK_INSERT_BACK); + } + win->flags &= ~(nk_flags)NK_WINDOW_ROM; + ctx->active = win; + } + if (ctx->end != win && !(win->flags & NK_WINDOW_BACKGROUND)) + win->flags |= NK_WINDOW_ROM; } - if (ctx->end != win && !(win->flags & NK_WINDOW_BACKGROUND)) - win->flags |= NK_WINDOW_ROM; } win->layout = (struct nk_panel*)nk_create_panel(ctx); @@ -17408,11 +18685,11 @@ nk_end(struct nk_context *ctx) struct nk_panel *layout; NK_ASSERT(ctx); NK_ASSERT(ctx->current && "if this triggers you forgot to call `nk_begin`"); - NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current) + return; layout = ctx->current->layout; - if (!ctx || !ctx->current) return; - if (layout->type == NK_PANEL_WINDOW && (ctx->current->flags & NK_WINDOW_HIDDEN)) { + if (!layout || (layout->type == NK_PANEL_WINDOW && (ctx->current->flags & NK_WINDOW_HIDDEN))) { ctx->current = 0; return; } @@ -17541,6 +18818,8 @@ nk_window_is_hovered(struct nk_context *ctx) NK_ASSERT(ctx); NK_ASSERT(ctx->current); if (!ctx || !ctx->current) return 0; + if(ctx->current->flags & NK_WINDOW_HIDDEN) + return 0; return nk_input_is_mouse_hovering_rect(&ctx->input, ctx->current->bounds); } @@ -17553,17 +18832,20 @@ nk_window_is_any_hovered(struct nk_context *ctx) iter = ctx->begin; while (iter) { /* check if window is being hovered */ - if (iter->flags & NK_WINDOW_MINIMIZED) { - struct nk_rect header = iter->bounds; - header.h = ctx->style.font->height + 2 * ctx->style.window.header.padding.y; - if (nk_input_is_mouse_hovering_rect(&ctx->input, header)) + if(!(iter->flags & NK_WINDOW_HIDDEN)) { + /* check if window popup is being hovered */ + if (iter->popup.active && iter->popup.win && nk_input_is_mouse_hovering_rect(&ctx->input, iter->popup.win->bounds)) return 1; - } else if (nk_input_is_mouse_hovering_rect(&ctx->input, iter->bounds)) { - return 1; + + if (iter->flags & NK_WINDOW_MINIMIZED) { + struct nk_rect header = iter->bounds; + header.h = ctx->style.font->height + 2 * ctx->style.window.header.padding.y; + if (nk_input_is_mouse_hovering_rect(&ctx->input, header)) + return 1; + } else if (nk_input_is_mouse_hovering_rect(&ctx->input, iter->bounds)) { + return 1; + } } - /* check if window popup is being hovered */ - if (iter->popup.active && iter->popup.win && nk_input_is_mouse_hovering_rect(&ctx->input, iter->popup.win->bounds)) - return 1; iter = iter->next; } return 0; @@ -17666,29 +18948,40 @@ nk_window_close(struct nk_context *ctx, const char *name) } NK_API void -nk_window_set_bounds(struct nk_context *ctx, struct nk_rect bounds) +nk_window_set_bounds(struct nk_context *ctx, + const char *name, struct nk_rect bounds) { - NK_ASSERT(ctx); NK_ASSERT(ctx->current); - if (!ctx || !ctx->current) return; - ctx->current->bounds = bounds; + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return; + win = nk_window_find(ctx, name); + if (!win) return; + NK_ASSERT(ctx->current != win && "You cannot update a currently in procecss window"); + win->bounds = bounds; } NK_API void -nk_window_set_position(struct nk_context *ctx, struct nk_vec2 pos) +nk_window_set_position(struct nk_context *ctx, + const char *name, struct nk_vec2 pos) { - NK_ASSERT(ctx); NK_ASSERT(ctx->current); - if (!ctx || !ctx->current) return; - ctx->current->bounds.x = pos.x; - ctx->current->bounds.y = pos.y; + struct nk_rect bounds; + bounds.x = pos.x; + bounds.y = pos.y; + bounds.w = ctx->current->bounds.w; + bounds.h = ctx->current->bounds.h; + nk_window_set_bounds(ctx, name, bounds); } NK_API void -nk_window_set_size(struct nk_context *ctx, struct nk_vec2 size) +nk_window_set_size(struct nk_context *ctx, + const char *name, struct nk_vec2 size) { - NK_ASSERT(ctx); NK_ASSERT(ctx->current); - if (!ctx || !ctx->current) return; - ctx->current->bounds.w = size.x; - ctx->current->bounds.h = size.y; + struct nk_rect bounds; + bounds.x = ctx->current->bounds.x; + bounds.y = ctx->current->bounds.y; + bounds.w = size.x; + bounds.h = size.y; + nk_window_set_bounds(ctx, name, bounds); } NK_API void @@ -17844,6 +19137,42 @@ nk_menubar_end(struct nk_context *ctx) * LAYOUT * * --------------------------------------------------------------*/ +NK_API void +nk_layout_set_min_row_height(struct nk_context *ctx, float height) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + layout->row.min_height = height; +} + +NK_API void +nk_layout_reset_min_row_height(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + layout->row.min_height = ctx->style.font->height; + layout->row.min_height += ctx->style.text.padding.y*2; + layout->row.min_height += ctx->style.window.min_row_height_padding*2; +} + NK_INTERN float nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type, float total_space, int columns) @@ -17902,7 +19231,10 @@ nk_panel_layout(const struct nk_context *ctx, struct nk_window *win, layout->row.index = 0; layout->at_y += layout->row.height; layout->row.columns = cols; - layout->row.height = height + item_spacing.y; + if (height == 0.0f) + layout->row.height = NK_MAX(height, layout->row.min_height) + item_spacing.y; + else layout->row.height = height + item_spacing.y; + layout->row.item_offset = 0; if (layout->flags & NK_WINDOW_DYNAMIC) { /* draw background for dynamic panels */ @@ -18303,6 +19635,26 @@ nk_layout_space_bounds(struct nk_context *ctx) return ret; } +NK_API struct nk_rect +nk_layout_widget_bounds(struct nk_context *ctx) +{ + struct nk_rect ret; + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + win = ctx->current; + layout = win->layout; + + ret.x = layout->at_x; + ret.y = layout->at_y; + ret.w = layout->bounds.w - NK_MAX(layout->at_x - layout->bounds.x,0); + ret.h = layout->row.height; + return ret; +} + NK_API struct nk_vec2 nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret) { @@ -18415,7 +19767,7 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, switch (layout->row.type) { case NK_LAYOUT_DYNAMIC_FIXED: { /* scaling fixed size widgets item width */ - item_width = panel_space / (float)layout->row.columns; + item_width = NK_MAX(1.0f,panel_space-1.0f) / (float)layout->row.columns; item_offset = (float)layout->row.index * item_width; item_spacing = (float)layout->row.index * spacing.x; } break; @@ -18572,6 +19924,7 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, const struct nk_input *in; const struct nk_style_button *button; enum nk_symbol_type symbol; + float row_height; struct nk_vec2 item_spacing; struct nk_rect header = {0,0,0,0}; @@ -18595,7 +19948,11 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, item_spacing = style->window.spacing; /* calculate header bounds and draw background */ - nk_layout_row_dynamic(ctx, style->font->height + 2 * style->tab.padding.y, 1); + row_height = style->font->height + 2 * style->tab.padding.y; + nk_layout_set_min_row_height(ctx, row_height); + nk_layout_row_dynamic(ctx, row_height, 1); + nk_layout_reset_min_row_height(ctx); + widget_state = nk_widget(&header, ctx); if (type == NK_TREE_TAB) { const struct nk_style_item *background = &style->tab.background; @@ -18806,57 +20163,79 @@ nk_widget_height(struct nk_context *ctx) NK_API int nk_widget_is_hovered(struct nk_context *ctx) { - int ret; + struct nk_rect c, v; struct nk_rect bounds; NK_ASSERT(ctx); NK_ASSERT(ctx->current); - if (!ctx || !ctx->current) + if (!ctx || !ctx->current || ctx->active != ctx->current) return 0; + c = ctx->current->layout->clip; + c.x = (float)((int)c.x); + c.y = (float)((int)c.y); + c.w = (float)((int)c.w); + c.h = (float)((int)c.h); + nk_layout_peek(&bounds, ctx); - ret = (ctx->active == ctx->current); - ret = ret && nk_input_is_mouse_hovering_rect(&ctx->input, bounds); - return ret; + nk_unify(&v, &c, bounds.x, bounds.y, bounds.x + bounds.w, bounds.y + bounds.h); + if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds.x, bounds.y, bounds.w, bounds.h)) + return 0; + return nk_input_is_mouse_hovering_rect(&ctx->input, bounds); } NK_API int nk_widget_is_mouse_clicked(struct nk_context *ctx, enum nk_buttons btn) { - int ret; + struct nk_rect c, v; struct nk_rect bounds; NK_ASSERT(ctx); NK_ASSERT(ctx->current); - if (!ctx || !ctx->current) + if (!ctx || !ctx->current || ctx->active != ctx->current) return 0; + c = ctx->current->layout->clip; + c.x = (float)((int)c.x); + c.y = (float)((int)c.y); + c.w = (float)((int)c.w); + c.h = (float)((int)c.h); + nk_layout_peek(&bounds, ctx); - ret = (ctx->active == ctx->current); - ret = ret && nk_input_mouse_clicked(&ctx->input, btn, bounds); - return ret; + nk_unify(&v, &c, bounds.x, bounds.y, bounds.x + bounds.w, bounds.y + bounds.h); + if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds.x, bounds.y, bounds.w, bounds.h)) + return 0; + return nk_input_mouse_clicked(&ctx->input, btn, bounds); } NK_API int nk_widget_has_mouse_click_down(struct nk_context *ctx, enum nk_buttons btn, int down) { - int ret; + struct nk_rect c, v; struct nk_rect bounds; NK_ASSERT(ctx); NK_ASSERT(ctx->current); - if (!ctx || !ctx->current) + if (!ctx || !ctx->current || ctx->active != ctx->current) return 0; + c = ctx->current->layout->clip; + c.x = (float)((int)c.x); + c.y = (float)((int)c.y); + c.w = (float)((int)c.w); + c.h = (float)((int)c.h); + nk_layout_peek(&bounds, ctx); - ret = (ctx->active == ctx->current); - ret = ret && nk_input_has_mouse_click_down_in_rect(&ctx->input, btn, bounds, down); - return ret; + nk_unify(&v, &c, bounds.x, bounds.y, bounds.x + bounds.w, bounds.y + bounds.h); + if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds.x, bounds.y, bounds.w, bounds.h)) + return 0; + return nk_input_has_mouse_click_down_in_rect(&ctx->input, btn, bounds, down); } NK_API enum nk_widget_layout_states nk_widget(struct nk_rect *bounds, const struct nk_context *ctx) { - struct nk_rect *c = 0; + struct nk_rect c, v; struct nk_window *win; struct nk_panel *layout; + const struct nk_input *in; NK_ASSERT(ctx); NK_ASSERT(ctx->current); @@ -18864,11 +20243,12 @@ nk_widget(struct nk_rect *bounds, const struct nk_context *ctx) if (!ctx || !ctx->current || !ctx->current->layout) return NK_WIDGET_INVALID; - /* allocate space and check if the widget needs to be updated and drawn */ + /* allocate space and check if the widget needs to be updated and drawn */ nk_panel_alloc_space(bounds, ctx); win = ctx->current; layout = win->layout; - c = &layout->clip; + in = &ctx->input; + c = layout->clip; /* if one of these triggers you forgot to add an `if` condition around either a window, group, popup, combobox or contextual menu `begin` and `end` block. @@ -18879,15 +20259,21 @@ nk_widget(struct nk_rect *bounds, const struct nk_context *ctx) NK_ASSERT(!(layout->flags & NK_WINDOW_HIDDEN)); NK_ASSERT(!(layout->flags & NK_WINDOW_CLOSED)); - /* need to convert to int here to remove floating point error */ + /* need to convert to int here to remove floating point errors */ bounds->x = (float)((int)bounds->x); bounds->y = (float)((int)bounds->y); bounds->w = (float)((int)bounds->w); bounds->h = (float)((int)bounds->h); - if (!NK_INTERSECT(c->x, c->y, c->w, c->h, bounds->x, bounds->y, bounds->w, bounds->h)) + c.x = (float)((int)c.x); + c.y = (float)((int)c.y); + c.w = (float)((int)c.w); + c.h = (float)((int)c.h); + + nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); + if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) return NK_WIDGET_INVALID; - if (!NK_CONTAINS(bounds->x, bounds->y, bounds->w, bounds->h, c->x, c->y, c->w, c->h)) + if (!NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, v.x, v.y, v.w, v.h)) return NK_WIDGET_ROM; return NK_WIDGET_VALID; } @@ -18955,7 +20341,6 @@ nk_spacing(struct nk_context *ctx, int cols) nk_panel_alloc_row(ctx, win); cols = index; } - /* non table layout need to allocate space */ if (layout->row.type != NK_LAYOUT_DYNAMIC_FIXED && layout->row.type != NK_LAYOUT_STATIC_FIXED) { @@ -19929,7 +21314,9 @@ nk_edit_buffer(struct nk_context *ctx, nk_flags flags, } if (flags & NK_EDIT_CLIPBOARD) edit->clip = ctx->clip; - } + edit->active = win->edit.active; + } else edit->active = nk_false; + edit->mode = win->edit.mode; filter = (!filter) ? nk_filter_default: filter; prev_state = (unsigned char)edit->active; @@ -20020,12 +21407,16 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant char *buffer = 0; int *len = 0; int *cursor = 0; + int *select_begin = 0; + int *select_end = 0; int old_state; char dummy_buffer[NK_MAX_NUMBER_BUFFER]; int dummy_state = NK_PROPERTY_DEFAULT; int dummy_length = 0; int dummy_cursor = 0; + int dummy_select_begin = 0; + int dummy_select_end = 0; NK_ASSERT(ctx); NK_ASSERT(ctx->current); @@ -20038,7 +21429,6 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant style = &ctx->style; s = nk_widget(&bounds, ctx); if (!s) return; - in = (s == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; /* calculate hash from name */ if (name[0] == '#') { @@ -20052,18 +21442,26 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant len = &win->property.length; cursor = &win->property.cursor; state = &win->property.state; + select_begin = &win->property.select_start; + select_end = &win->property.select_end; } else { buffer = dummy_buffer; len = &dummy_length; cursor = &dummy_cursor; state = &dummy_state; + select_begin = &dummy_select_begin; + select_end = &dummy_select_end; } /* execute property widget */ old_state = *state; + ctx->text_edit.clip = ctx->clip; + in = ((s == NK_WIDGET_ROM && !win->property.active) || + layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; nk_do_property(&ctx->last_widget_state, &win->buffer, bounds, name, - variant, inc_per_pixel, buffer, len, state, cursor, - &style->property, filter, in, style->font, &ctx->text_edit); + variant, inc_per_pixel, buffer, len, state, cursor, select_begin, + select_end, &style->property, filter, in, style->font, &ctx->text_edit, + ctx->button_behavior); if (in && *state != NK_PROPERTY_DEFAULT && !win->property.active) { /* current property is now hot */ @@ -20073,12 +21471,13 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant win->property.cursor = *cursor; win->property.state = *state; win->property.name = hash; + win->property.select_start = *select_begin; + win->property.select_end = *select_end; if (*state == NK_PROPERTY_DRAG) { ctx->input.mouse.grab = nk_true; ctx->input.mouse.grabbed = nk_true; } } - /* check if previously active property is now inactive */ if (*state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT) { if (old_state == NK_PROPERTY_DRAG) { @@ -20086,6 +21485,8 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant ctx->input.mouse.grabbed = nk_false; ctx->input.mouse.ungrab = nk_true; } + win->property.select_start = 0; + win->property.select_end = 0; win->property.active = 0; } } @@ -20505,10 +21906,12 @@ nk_plot(struct nk_context *ctx, enum nk_chart_type type, const float *values, min_value = NK_MIN(values[i + offset], min_value); max_value = NK_MAX(values[i + offset], max_value); } - nk_chart_begin(ctx, type, count, min_value, max_value); - for (i = 0; i < count; ++i) - nk_chart_push(ctx, values[i + offset]); - nk_chart_end(ctx); + + if (nk_chart_begin(ctx, type, count, min_value, max_value)) { + for (i = 0; i < count; ++i) + nk_chart_push(ctx, values[i + offset]); + nk_chart_end(ctx); + } } NK_API void @@ -20529,10 +21932,12 @@ nk_plot_function(struct nk_context *ctx, enum nk_chart_type type, void *userdata min_value = NK_MIN(value, min_value); max_value = NK_MAX(value, max_value); } - nk_chart_begin(ctx, type, count, min_value, max_value); - for (i = 0; i < count; ++i) - nk_chart_push(ctx, value_getter(userdata, i + offset)); - nk_chart_end(ctx); + + if (nk_chart_begin(ctx, type, count, min_value, max_value)) { + for (i = 0; i < count; ++i) + nk_chart_push(ctx, value_getter(userdata, i + offset)); + nk_chart_end(ctx); + } } /* ------------------------------------------------------------- @@ -20550,7 +21955,6 @@ nk_group_scrolled_offset_begin(struct nk_context *ctx, win = ctx->current; nk_panel_alloc_space(&bounds, ctx); - {const struct nk_rect *c = &win->layout->clip; if (!NK_INTERSECT(c->x, c->y, c->w, c->h, bounds.x, bounds.y, bounds.w, bounds.h) && !(flags & NK_WINDOW_MOVABLE)) { @@ -20559,7 +21963,7 @@ nk_group_scrolled_offset_begin(struct nk_context *ctx, if (win->flags & NK_WINDOW_ROM) flags |= NK_WINDOW_ROM; - /* initialize a fake window to create the layout from */ + /* initialize a fake window to create the panel from */ nk_zero(&panel, sizeof(panel)); panel.bounds = bounds; panel.flags = flags; @@ -20576,7 +21980,18 @@ nk_group_scrolled_offset_begin(struct nk_context *ctx, panel.layout->offset_y = y_offset; panel.layout->parent = win->layout; win->layout = panel.layout; + ctx->current = win; + if ((panel.layout->flags & NK_WINDOW_CLOSED) || + (panel.layout->flags & NK_WINDOW_MINIMIZED)) + { + nk_flags f = panel.layout->flags; + nk_group_scrolled_end(ctx); + if (f & NK_WINDOW_CLOSED) + return NK_WINDOW_CLOSED; + if (f & NK_WINDOW_MINIMIZED) + return NK_WINDOW_MINIMIZED; + } return 1; } @@ -20730,7 +22145,7 @@ nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view, result = nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags); win = ctx->current; layout = win->layout; - + view->total_height = row_height * NK_MAX(row_count,1); view->begin = (int)NK_MAX(((float)view->scroll_value / (float)row_height), 0.0f); view->count = (int)NK_MAX(nk_iceilf((layout->clip.h)/(float)row_height), 0); @@ -20799,7 +22214,7 @@ nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type, win->popup.type = NK_PANEL_POPUP; } - /* make sure we have to correct popup */ + /* make sure we have correct popup */ if (win->popup.name != title_hash) { if (!win->popup.active) { nk_zero(popup, sizeof(*popup)); @@ -20851,7 +22266,7 @@ nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type, root->flags |= NK_WINDOW_REMOVE_ROM; root = root->parent; } - win->layout->popup_buffer.active = 0; + win->popup.buf.active = 0; win->popup.active = 0; ctx->memory.allocated = allocated; ctx->current = win; @@ -20881,7 +22296,7 @@ nk_nonblock_begin(struct nk_context *ctx, win = ctx->current; panel = win->layout; NK_ASSERT(!(panel->type & NK_PANEL_SET_POPUP)); - (void)panel; + (void)panel; popup = win->popup.win; if (!popup) { /* create window for nonblocking popup */ @@ -20903,8 +22318,7 @@ nk_nonblock_begin(struct nk_context *ctx, if (!is_active) { /* remove read only mode from all parent panels */ - struct nk_panel *root; - root = win->layout; + struct nk_panel *root = win->layout; while (root) { root->flags |= NK_WINDOW_REMOVE_ROM; root = root->parent; @@ -21262,7 +22676,7 @@ nk_contextual_end(struct nk_context *ctx) NK_ASSERT(panel->type & NK_PANEL_SET_POPUP); if (panel->flags & NK_WINDOW_DYNAMIC) { /* Close behavior - This is a bit hack solution since we do not now before we end our popup + This is a bit of a hack solution since we do not know before we end our popup how big it will be. We therefore do not directly know when a click outside the non-blocking popup must close it at that direct frame. Instead it will be closed in the next frame.*/ @@ -21273,7 +22687,6 @@ nk_contextual_end(struct nk_context *ctx) body.y = (panel->at_y + panel->footer_height + panel->border + padding.y + panel->row.height); body.h = (panel->bounds.y + panel->bounds.h) - body.y; } - {int pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT); int in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body); if (pressed && in_body) @@ -22240,4 +23653,4 @@ NK_API void nk_menu_end(struct nk_context *ctx) {nk_contextual_end(ctx);} -#endif +#endif /* NK_IMPLEMENTATION */ diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 2ccf23b458..bb0bac0edd 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -941,6 +941,129 @@ static void gl_set_texture_enable(void *data, bool state, bool full_screen) gl->menu_texture_full_screen = full_screen; } +static void gl_render_osd_background( + gl_t *gl, video_frame_info_t *video_info, + const char *msg) +{ + video_shader_ctx_mvp_t mvp; + video_shader_ctx_coords_t coords_data; + video_coords_t coords; + video_coord_array_t ca; + video_shader_ctx_info_t shader_info; + struct uniform_info uniform_param; + const unsigned vertices_total = 6; + float colors[4]; + float *dummy = (float*)calloc(4 * vertices_total, sizeof(float)); + float *verts = (float*)malloc(2 * vertices_total * sizeof(float)); + int msg_width; + float x, x2, y, y2, width, height; + settings_t *settings = config_get_ptr(); + + if (!gl || !settings) + goto end; + + msg_width = font_driver_get_message_width(NULL, msg, strlen(msg), 1.0f); + + /* shader driver expects vertex coords as 0..1 */ + x = video_info->font_msg_pos_x; + y = video_info->font_msg_pos_y; + width = msg_width / (float)video_info->width; + height = settings->floats.video_font_size / (float)video_info->height; + + x2 = 0.005f; /* extend background around text */ + y2 = 0.005f; + + x -= x2; + y -= y2; + width += x2; + height += y2; + + colors[0] = settings->uints.video_msg_bgcolor_red / 255.0f; + colors[1] = settings->uints.video_msg_bgcolor_green / 255.0f; + colors[2] = settings->uints.video_msg_bgcolor_blue / 255.0f; + colors[3] = settings->floats.video_msg_bgcolor_opacity; + + /* triangle 1 */ + verts[0] = x; + verts[1] = y; /* bottom-left */ + + verts[2] = x; + verts[3] = y + height; /* top-left */ + + verts[4] = x + width; + verts[5] = y + height; /* top-right */ + + /* triangle 2 */ + verts[6] = x; + verts[7] = y; /* bottom-left */ + + verts[8] = x + width; + verts[9] = y + height; /* top-right */ + + verts[10] = x + width; + verts[11] = y; /* bottom-right */ + + coords.color = dummy; + coords.vertex = verts; + coords.tex_coord = dummy; + coords.lut_tex_coord = dummy; + coords.vertices = vertices_total; + + coords_data.handle_data = NULL; + coords_data.data = &coords; + + shader_info.data = NULL; + shader_info.idx = VIDEO_SHADER_STOCK_BLEND; + shader_info.set_active = true; + + video_driver_set_viewport(video_info->width, video_info->height, true, false); + + video_shader_driver_use(shader_info); + video_shader_driver_set_coords(coords_data); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + mvp.data = gl; + mvp.matrix = &gl->mvp_no_rot; + + video_shader_driver_set_mvp(mvp); + + uniform_param.type = UNIFORM_4F; + uniform_param.enabled = true; + uniform_param.location = 0; + uniform_param.count = 0; + + uniform_param.lookup.type = SHADER_PROGRAM_FRAGMENT; + uniform_param.lookup.ident = "bgcolor"; + uniform_param.lookup.idx = shader_info.idx; + uniform_param.lookup.add_prefix = true; + uniform_param.lookup.enable = true; + + uniform_param.result.f.v0 = colors[0]; + uniform_param.result.f.v1 = colors[1]; + uniform_param.result.f.v2 = colors[2]; + uniform_param.result.f.v3 = colors[3]; + + video_shader_driver_set_parameter(uniform_param); + + glDrawArrays(GL_TRIANGLES, 0, coords.vertices); +end: + /* reset uniform back to zero so it is not used for anything else */ + uniform_param.result.f.v0 = 0.0f; + uniform_param.result.f.v1 = 0.0f; + uniform_param.result.f.v2 = 0.0f; + uniform_param.result.f.v3 = 0.0f; + + video_shader_driver_set_parameter(uniform_param); + + free(dummy); + free(verts); + + video_driver_set_viewport(video_info->width, video_info->height, false, true); +} + static void gl_set_osd_msg(void *data, video_frame_info_t *video_info, const char *msg, @@ -1068,8 +1191,9 @@ static bool gl_frame(void *data, const void *frame, gl_t *gl = (gl_t*)data; unsigned width = video_info->width; unsigned height = video_info->height; + settings_t *settings = config_get_ptr(); - if (!gl) + if (!gl || !settings) return false; context_bind_hw_render(false); @@ -1244,7 +1368,11 @@ static bool gl_frame(void *data, const void *frame, #endif if (!string_is_empty(msg)) + { + if (settings->bools.video_msg_bgcolor_enable) + gl_render_osd_background(gl, video_info, msg); font_driver_render_msg(video_info, NULL, msg, NULL); + } #ifdef HAVE_OVERLAY if (gl && gl->overlay_enable) diff --git a/gfx/drivers/gl_shaders/core_alpha_blend.glsl.frag.h b/gfx/drivers/gl_shaders/core_alpha_blend.glsl.frag.h index f114cf33d8..f51bc55d26 100644 --- a/gfx/drivers/gl_shaders/core_alpha_blend.glsl.frag.h +++ b/gfx/drivers/gl_shaders/core_alpha_blend.glsl.frag.h @@ -2,11 +2,15 @@ static const char *stock_fragment_core_blend = GLSL( uniform sampler2D Texture; + uniform vec4 bgcolor; in vec2 tex_coord; in vec4 color; out vec4 FragColor; void main() { - FragColor = color * texture(Texture, tex_coord); + if (bgcolor.a > 0.0) + FragColor = bgcolor; + else + FragColor = color * texture(Texture, tex_coord); } ); diff --git a/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.frag.h b/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.frag.h index 447d99f1bf..99a2300284 100644 --- a/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.frag.h +++ b/gfx/drivers/gl_shaders/modern_alpha_blend.glsl.frag.h @@ -2,9 +2,13 @@ static const char *stock_fragment_modern_blend = GLSL( uniform sampler2D Texture; + uniform vec4 bgcolor; varying vec2 tex_coord; varying vec4 color; void main() { - gl_FragColor = color * texture2D(Texture, tex_coord); + if (bgcolor.a > 0.0) + gl_FragColor = bgcolor; + else + gl_FragColor = color * texture2D(Texture, tex_coord); } ); diff --git a/gfx/drivers_font/gl_raster_font.c b/gfx/drivers_font/gl_raster_font.c index 444e8a25b6..d9b110378f 100644 --- a/gfx/drivers_font/gl_raster_font.c +++ b/gfx/drivers_font/gl_raster_font.c @@ -475,7 +475,7 @@ static void gl_raster_font_render_msg( else gl_raster_font_setup_viewport(width, height, font, full_screen); - if (!string_is_empty(msg) && font->gl + if (!string_is_empty(msg) && font->gl && font->font_data && font->font_driver) { if (drop_x || drop_y) diff --git a/gfx/video_coord_array.c b/gfx/video_coord_array.c index f1ead1ed5c..835b9ba967 100644 --- a/gfx/video_coord_array.c +++ b/gfx/video_coord_array.c @@ -75,7 +75,7 @@ bool video_coord_array_append(video_coord_array_t *ca, base_size = count * sizeof(float); offset = ca->coords.vertices; - /* XXX: I wish we used interlaced arrays so + /* XXX: I wish we used interlaced arrays so * we could call memcpy only once. */ memcpy(ca->coords.vertex + offset * 2, coords->vertex, base_size * 2); diff --git a/griffin/griffin.c b/griffin/griffin.c index a15f719fbd..4b45c1b1b6 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -1113,10 +1113,7 @@ MENU #ifdef HAVE_NUKLEAR #include "../menu/drivers/nuklear/nk_common.c" #include "../menu/drivers/nuklear/nk_menu.c" -#include "../menu/drivers/nuklear/nk_wnd_shader_parameters.c" -#include "../menu/drivers/nuklear/nk_wnd_file_picker.c" -#include "../menu/drivers/nuklear/nk_wnd_settings.c" -#include "../menu/drivers/nuklear/nk_wnd_main.c" +#include "../menu/drivers/nuklear/nk_wnd_debug.c" #include "../menu/drivers/nuklear.c" #endif diff --git a/intl/msg_hash_ja.h b/intl/msg_hash_ja.h index e1d4910954..e84db62b1b 100644 --- a/intl/msg_hash_ja.h +++ b/intl/msg_hash_ja.h @@ -610,9 +610,9 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_DOWNLOAD_CORE, MSG_HASH(MENU_ENUM_LABEL_VALUE_DOWNLOAD_CORE_CONTENT, "コンテンツをダウンロード") MSG_HASH(MENU_ENUM_LABEL_VALUE_DPI_OVERRIDE_ENABLE, - "DPI Override Enable") + "DPI優先を有効") MSG_HASH(MENU_ENUM_LABEL_VALUE_DPI_OVERRIDE_VALUE, - "DPI Override") + "DPI優先") MSG_HASH(MENU_ENUM_LABEL_VALUE_DRIVER_SETTINGS, "ドライバ") MSG_HASH(MENU_ENUM_LABEL_VALUE_DUMMY_ON_CORE_SHUTDOWN, @@ -964,9 +964,9 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_MATERIALUI_MENU_COLOR_THEME_RED, MSG_HASH(MENU_ENUM_LABEL_VALUE_MATERIALUI_MENU_COLOR_THEME_YELLOW, "黄色") MSG_HASH(MENU_ENUM_LABEL_VALUE_MATERIALUI_MENU_FOOTER_OPACITY, - "Footer Opacity") + "フッター不透明性") MSG_HASH(MENU_ENUM_LABEL_VALUE_MATERIALUI_MENU_HEADER_OPACITY, - "Header Opacity") + "ヘッダー不透明性") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_DRIVER, "メニューのドライバ") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_ENUM_THROTTLE_FRAMERATE, @@ -3016,11 +3016,11 @@ MSG_HASH(MENU_ENUM_SUBLABEL_MENU_SHOW_CORE_UPDATER, MSG_HASH(MSG_PREPARING_FOR_CONTENT_SCAN, "コンテンツをスキャンするための準備中") MSG_HASH(MENU_ENUM_LABEL_VALUE_CORE_DELETE, - "Delete core") + "コアを削除") MSG_HASH(MENU_ENUM_SUBLABEL_CORE_DELETE, - "Remove this core from disk.") + "コアをハードディスクから削除する。") MSG_HASH(MENU_ENUM_LABEL_VALUE_RENAME_ENTRY, - "Rename the title of the entry.") + "エントリーの名前を変更する") MSG_HASH(MENU_ENUM_LABEL_RENAME_ENTRY, "Rename") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_FRAMEBUFFER_OPACITY, @@ -3028,23 +3028,23 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_FRAMEBUFFER_OPACITY, MSG_HASH(MENU_ENUM_SUBLABEL_MENU_FRAMEBUFFER_OPACITY, "Modify the opacity of the framebuffer.") MSG_HASH(MENU_ENUM_LABEL_VALUE_GOTO_FAVORITES, - "Favorites") + "お気に入り") MSG_HASH(MENU_ENUM_SUBLABEL_GOTO_FAVORITES, "Content which you have added to 'Favorites' will appear here.") MSG_HASH(MENU_ENUM_LABEL_VALUE_GOTO_MUSIC, - "Music") + "音楽") MSG_HASH(MENU_ENUM_SUBLABEL_GOTO_MUSIC, "Music which has been previously played will appear here.") MSG_HASH(MENU_ENUM_LABEL_VALUE_GOTO_IMAGES, - "Image") + "画像") MSG_HASH(MENU_ENUM_SUBLABEL_GOTO_IMAGES, "Images which have been previously viewed will appear here.") MSG_HASH(MENU_ENUM_LABEL_VALUE_GOTO_VIDEO, - "Video") + "ビデオ") MSG_HASH(MENU_ENUM_SUBLABEL_GOTO_VIDEO, "Videos which have been previously played will appear here.") MSG_HASH(MENU_ENUM_LABEL_VALUE_MATERIALUI_ICONS_ENABLE, - "Menu Icons") + "メニューのアイコン") MSG_HASH(MENU_ENUM_SUBLABEL_MATERIALUI_ICONS_ENABLE, "Enable/disable the menu icons shown at the lefthand side of the menu entries.") MSG_HASH(MENU_ENUM_LABEL_VALUE_XMB_MAIN_MENU_ENABLE_SETTINGS, @@ -3066,81 +3066,93 @@ MSG_HASH(MENU_ENUM_SUBLABEL_PLAYLIST_ENTRY_RENAME, MSG_HASH(MENU_ENUM_LABEL_VALUE_PLAYLIST_ENTRY_RENAME, "エントリーの名前変更を許す") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_SHOW_LOAD_CORE, - "Show Load Core") + "「コアをロード」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_MENU_SHOW_LOAD_CORE, "Show/hide the 'Load Core' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_SHOW_LOAD_CONTENT, - "Show Load Content") + "「コンテンツをロード」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_MENU_SHOW_LOAD_CONTENT, "Show/hide the 'Load Content' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_SHOW_INFORMATION, - "Show Information") + "「情報」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_MENU_SHOW_INFORMATION, "Show/hide the 'Information' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_SHOW_CONFIGURATIONS, - "Show Configurations") + "「設定ファイル」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_MENU_SHOW_CONFIGURATIONS, "Show/hide the 'Configurations' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_SHOW_HELP, - "Show Help") + "「ヘルプ」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_MENU_SHOW_HELP, "Show/hide the 'Help' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_SHOW_QUIT_RETROARCH, - "Show Quit RetroArch") + "「終了」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_MENU_SHOW_QUIT_RETROARCH, "Show/hide the 'Quit RetroArch' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_SHOW_REBOOT, - "Show Reboot") + "「再起動」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_MENU_SHOW_REBOOT, "Show/hide the 'Reboot' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_VIEWS_SETTINGS, - "Quick Menu") + "クイックメニュー") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_VIEWS_SETTINGS, "Show or hide elements on the Quick Menu screen.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_TAKE_SCREENSHOT, - "Show Take Screenshot") + "「スクリーンショットを撮る」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_TAKE_SCREENSHOT, "Show/hide the 'Take Screenshot' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_SAVE_LOAD_STATE, - "Show Save/Load State") + "「状態保存」と「保存状態をロード」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_SAVE_LOAD_STATE, "Show/hide the options for saving/loading state.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_UNDO_SAVE_LOAD_STATE, - "Show Undo Save/Load State") + "「保存状態のロードを前に戻す」と「状態の保存を前に戻す」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_UNDO_SAVE_LOAD_STATE, "Show/hide the options for undoing save/load state.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_ADD_TO_FAVORITES, - "Show Add to Favorites") + "「お気に入りに追加」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_ADD_TO_FAVORITES, "Show/hide the 'Add to Favorites' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_OPTIONS, - "Show Options") + "「オプション」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_OPTIONS, "Show/hide the 'Options' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_CONTROLS, - "Show Controls") + "「コントロール」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_CONTROLS, "Show/hide the 'Controls' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_CHEATS, - "Show Cheats") + "「チート」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_CHEATS, "Show/hide the 'Cheats' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_SHADERS, - "Show Shaders") + "「シェーダー」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_SHADERS, "Show/hide the 'Shaders' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_SAVE_CORE_OVERRIDES, - "Show Save Core Overrides") + "「コアの優先を保存」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_SAVE_CORE_OVERRIDES, "Show/hide the 'Save Core Overrides' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_SAVE_GAME_OVERRIDES, - "Show Save Game Overrides") + "「ゲームの優先を保存」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_SAVE_GAME_OVERRIDES, "Show/hide the 'Save Game Overrides' option.") MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_INFORMATION, - "Show Information") + "「情報」を表示") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_INFORMATION, "Show/hide the 'Information' option.") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_ENABLE, + "OSDメッセージ背景を有効") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_RED, + "OSDメッセージ背景の赤色値") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_GREEN, + "OSDメッセージ背景の緑色値") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_BLUE, + "OSDメッセージ背景の青色値") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_OPACITY, + "OSDメッセージ背景の不透明性") +MSG_HASH(MENU_ENUM_LABEL_VALUE_ADD_TO_FAVORITES, + "お気に入りに追加") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_DISABLE_KIOSK_MODE, "Disable Kiosk Mode") MSG_HASH(MENU_ENUM_SUBLABEL_MENU_DISABLE_KIOSK_MODE, @@ -3159,3 +3171,4 @@ MSG_HASH(MSG_INPUT_KIOSK_MODE_PASSWORD_OK, "Password correct.") MSG_HASH(MSG_INPUT_KIOSK_MODE_PASSWORD_NOK, "Password incorrect.") + \ No newline at end of file diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index c06c947d43..649a35512d 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -1349,3 +1349,14 @@ MSG_HASH(MENU_ENUM_LABEL_MENU_DISABLE_KIOSK_MODE, "menu_disable_kiosk_mode") MSG_HASH(MENU_ENUM_LABEL_MENU_KIOSK_MODE_PASSWORD, "menu_disable_kiosk_mode_password") +MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_ENABLE, + "video_msg_bgcolor_enable") +MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_RED, + "video_msg_bgcolor_red") +MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_GREEN, + "video_msg_bgcolor_green") +MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_BLUE, + "video_msg_bgcolor_blue") +MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_OPACITY, + "video_msg_bgcolor_opacity") + \ No newline at end of file diff --git a/intl/msg_hash_us.c b/intl/msg_hash_us.c index ed275361d8..8711478ca6 100644 --- a/intl/msg_hash_us.c +++ b/intl/msg_hash_us.c @@ -1991,6 +1991,26 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len) msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_HIDE_IN_MENU) ); break; + case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_ENABLE: + snprintf(s, len, + "Enables a background color for the OSD."); + break; + case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_RED: + snprintf(s, len, + "Sets the red value of the OSD background color. Valid values are between 0 and 255."); + break; + case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_GREEN: + snprintf(s, len, + "Sets the green value of the OSD background color. Valid values are between 0 and 255."); + break; + case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_BLUE: + snprintf(s, len, + "Sets the blue value of the OSD background color. Valid values are between 0 and 255."); + break; + case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_OPACITY: + snprintf(s, len, + "Sets the opacity of the OSD background color. Valid values are between 0.0 and 1.0."); + break; default: if (string_is_empty(s)) strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_INFORMATION_AVAILABLE), len); diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 8a938d721b..fcc844aee4 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -3227,6 +3227,16 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_INFORMATION, "Show Information") MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_INFORMATION, "Show/hide the 'Information' option.") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_ENABLE, + "Onscreen Notification Background Enable") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_RED, + "Onscreen Notification Background Red Color") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_GREEN, + "Onscreen Notification Background Green Color") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_BLUE, + "Onscreen Notification Background Blue Color") +MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_OPACITY, + "Onscreen Notification Background Opacity") MSG_HASH(MENU_ENUM_LABEL_VALUE_MENU_DISABLE_KIOSK_MODE, "Disable Kiosk Mode") MSG_HASH(MENU_ENUM_SUBLABEL_MENU_DISABLE_KIOSK_MODE, diff --git a/menu/drivers/nuklear.c b/menu/drivers/nuklear.c index faaaadec9e..5bd51b5989 100644 --- a/menu/drivers/nuklear.c +++ b/menu/drivers/nuklear.c @@ -52,8 +52,8 @@ static void nk_menu_init_device(nk_menu_handle_t *nk) int w, h; char buf[PATH_MAX_LENGTH] = {0}; - fill_pathname_join(buf, nk->assets_directory, - "DroidSans.ttf", sizeof(buf)); + fill_pathname_join(buf, "assets/nuklear", + "font.ttf", sizeof(buf)); nk_alloc.userdata.ptr = NULL; nk_alloc.alloc = nk_common_mem_alloc; @@ -61,91 +61,26 @@ static void nk_menu_init_device(nk_menu_handle_t *nk) nk_buffer_init(&device.cmds, &nk_alloc, 1024); nk_font_atlas_init_default(&atlas); nk_font_atlas_begin(&atlas); - font = nk_font_atlas_add_default(&atlas, 13.0f, NULL); + + struct nk_font *font; + + font = nk_font_atlas_add_from_file(&atlas, buf, 16, 0); image = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32); - device_upload_atlas(&device, image, w, h); + nk_upload_atlas(&device, image, w, h); nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.null); nk_init_default(&nk->ctx, &font->handle); nk_common_device_init(&device); - fill_pathname_join(buf, nk->assets_directory, "folder.png", sizeof(buf)); - nk->icons.folder = nk_common_image_load(buf); - fill_pathname_join(buf, nk->assets_directory, "speaker.png", sizeof(buf)); - nk->icons.speaker = nk_common_image_load(buf); - fill_pathname_join(buf, nk->assets_directory, "gamepad.png", sizeof(buf)); - nk->icons.gamepad = nk_common_image_load(buf); - fill_pathname_join(buf, nk->assets_directory, "monitor.png", sizeof(buf)); - nk->icons.monitor = nk_common_image_load(buf); - fill_pathname_join(buf, nk->assets_directory, "settings.png", sizeof(buf)); - nk->icons.settings = nk_common_image_load(buf); - fill_pathname_join(buf, nk->assets_directory, "invader.png", sizeof(buf)); - nk->icons.invader = nk_common_image_load(buf); - fill_pathname_join(buf, nk->assets_directory, "page_on.png", sizeof(buf)); - nk->icons.page_on = nk_common_image_load(buf); - fill_pathname_join(buf, nk->assets_directory, "page_off.png", sizeof(buf)); - nk->icons.page_off = nk_common_image_load(buf); - nk->size_changed = true; - nk_common_set_style(&nk->ctx, THEME_BLUE); -} - - -#define XMB_RIBBON_ROWS 64 -#define XMB_RIBBON_COLS 64 -#define XMB_RIBBON_VERTICES 2*XMB_RIBBON_COLS*XMB_RIBBON_ROWS-2*XMB_RIBBON_COLS - -static void xmb_ribbon_set_vertex(float *ribbon_verts, unsigned idx, unsigned row, unsigned col) -{ - ribbon_verts[idx++] = ((float)col) / (XMB_RIBBON_COLS-1) * 2.0f - 1.0f; - ribbon_verts[idx++] = ((float)row) / (XMB_RIBBON_ROWS-1) * 2.0f - 1.0f; -} - -static void xmb_init_ribbon(nk_menu_handle_t * xmb) -{ - video_coords_t coords; - unsigned vertices_total; - unsigned r, c, col; - unsigned i = 0; - float *ribbon_verts = NULL; - float *dummy = NULL; - video_coord_array_t *ca = menu_display_get_coords_array(); - - vertices_total = XMB_RIBBON_VERTICES; - - dummy = (float*)calloc(4 * vertices_total, sizeof(float)); - ribbon_verts = (float*)calloc(2 * vertices_total, sizeof(float)); - - - /* Set up vertices */ - for (r = 0; r < XMB_RIBBON_ROWS - 1; r++) - { - for (c = 0; c < XMB_RIBBON_COLS; c++) - { - col = r % 2 ? XMB_RIBBON_COLS - c - 1 : c; - xmb_ribbon_set_vertex(ribbon_verts, i, r, col); - xmb_ribbon_set_vertex(ribbon_verts, i + 2, r + 1, col); - i += 4; - } - } - - coords.color = dummy; - coords.vertex = ribbon_verts; - coords.tex_coord = dummy; - coords.lut_tex_coord = dummy; - coords.vertices = vertices_total; - - video_coord_array_append(ca, &coords, coords.vertices); - - free(dummy); - free(ribbon_verts); + nk_common_set_style(&nk->ctx); } static void *nk_menu_init(void **userdata, bool video_is_threaded) { -#if 1 + unsigned i; -#endif + settings_t *settings = config_get_ptr(); nk_menu_handle_t *nk = NULL; menu_handle_t *menu = (menu_handle_t*) @@ -170,14 +105,8 @@ static void *nk_menu_init(void **userdata, bool video_is_threaded) "nuklear", sizeof(nk->assets_directory)); nk_menu_init_device(nk); - /* for demo purposes only, opens all windows */ -#if 1 - for (i = 0; i < NK_WND_LAST; i++) + for (i = 0; i < NK_WND_LAST; i++) nk->window[i].open = true; -#else - nk->window[NK_WND_MAIN].open = true; -#endif - xmb_init_ribbon(nk); return menu; error: @@ -219,8 +148,9 @@ static void nk_menu_input_mouse_movement(struct nk_context *ctx) int16_t mouse_y = menu_input_mouse_state(MENU_MOUSE_Y_AXIS); nk_input_motion(ctx, mouse_x, mouse_y); - nk_input_scroll(ctx, menu_input_mouse_state(MENU_MOUSE_WHEEL_UP) - - menu_input_mouse_state(MENU_MOUSE_WHEEL_DOWN)); + struct nk_vec2 scroll = {0 ,menu_input_mouse_state(MENU_MOUSE_WHEEL_UP) - + menu_input_mouse_state(MENU_MOUSE_WHEEL_DOWN)}; + nk_input_scroll(ctx, scroll); } static void nk_menu_input_mouse_button(struct nk_context *ctx) @@ -251,42 +181,6 @@ static void nk_menu_get_message(void *data, const char *message) strlcpy(nk->box_message, message, sizeof(nk->box_message)); } -static void nk_draw_bg( - nk_menu_handle_t *nk, - video_frame_info_t *video_info, - unsigned width, - unsigned height, - float alpha, - uintptr_t texture_id, - float *coord_black, - float *coord_white) -{ - menu_display_ctx_draw_t draw; - settings_t *settings = config_get_ptr(); - - draw.x = 0; - draw.y = 0; - draw.texture = texture_id; - draw.width = width; - draw.height = height; - draw.color = &coord_black[0]; - draw.vertex = NULL; - draw.tex_coord = NULL; - draw.vertex_count = 4; - draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP; - draw.pipeline.id = 0; - - menu_display_blend_begin(); - menu_display_set_viewport(video_info->width, video_info->height); - - draw.pipeline.id = VIDEO_SHADER_MENU_5; - draw.pipeline.active = false; - - menu_display_draw_pipeline(&draw); - menu_display_draw(&draw); - menu_display_blend_end(); -} - /* this is the main control function, it opens and closes windows and will control the logic of the whole menu driver */ static void nk_menu_main(nk_menu_handle_t *nk) @@ -294,13 +188,8 @@ static void nk_menu_main(nk_menu_handle_t *nk) struct nk_context *ctx = &nk->ctx; - if (nk->window[NK_WND_SETTINGS].open) - nk_wnd_settings(nk); - - if (nk->window[NK_WND_SHADER_PARAMETERS].open) - nk_wnd_shader_parameters(nk); - if (nk->window[NK_WND_MAIN].open) - nk_wnd_main(nk, "Demo"); + if (nk->window[NK_WND_DEBUG].open) + nk_wnd_debug(nk); nk_buffer_info(&nk->status, &nk->ctx.memory); } @@ -352,7 +241,6 @@ static void nk_menu_frame(void *data, video_frame_info_t *video_info) nk_input_end(&nk->ctx); nk_menu_main(nk); - nk_draw_bg(nk, video_info, width, height, 0.5, nk->textures.bg, coord_black, coord_white); nk_common_device_draw(&device, &nk->ctx, width, height, NK_ANTI_ALIASING_ON); menu_display_draw_cursor( @@ -404,7 +292,7 @@ static void nk_menu_context_load_textures(nk_menu_handle_t *nk, { image_texture_load(&ti, path); video_driver_texture_load(&ti, - TEXTURE_FILTER_MIPMAP_LINEAR, &nk->textures.pointer); + TEXTURE_FILTER_MIPMAP_NEAREST, &nk->textures.pointer); } fill_pathname_join(path, iconpath, @@ -413,7 +301,7 @@ static void nk_menu_context_load_textures(nk_menu_handle_t *nk, { image_texture_load(&ti, path); video_driver_texture_load(&ti, - TEXTURE_FILTER_MIPMAP_LINEAR, &nk->textures.bg); + TEXTURE_FILTER_MIPMAP_NEAREST, &nk->textures.bg); } } diff --git a/menu/drivers/nuklear/nk_common.c b/menu/drivers/nuklear/nk_common.c index 57c55c4853..7b9ed9815c 100644 --- a/menu/drivers/nuklear/nk_common.c +++ b/menu/drivers/nuklear/nk_common.c @@ -110,7 +110,7 @@ void nk_common_device_init(struct nk_device *dev) dev->attrib_pos = glGetAttribLocation(dev->prog, "Position"); dev->attrib_uv = glGetAttribLocation(dev->prog, "TexCoord"); dev->attrib_col = glGetAttribLocation(dev->prog, "Color"); - + glGenBuffers(1, &dev->vbo); glGenBuffers(1, &dev->ebo); glGenVertexArrays(1, &dev->vao); @@ -134,7 +134,7 @@ void nk_common_device_init(struct nk_device *dev) #endif } -void device_upload_atlas(struct nk_device *dev, const void *image, int width, int height) +void nk_upload_atlas(struct nk_device *dev, const void *image, int width, int height) { glGenTextures(1, &dev->font_tex); glBindTexture(GL_TEXTURE_2D, dev->font_tex); @@ -229,14 +229,19 @@ void nk_common_device_draw(struct nk_device *dev, #endif /* fill converting configuration */ - memset(&config, 0, sizeof(config)); - config.global_alpha = 1.0f; - config.shape_AA = AA; - config.line_AA = AA; + NK_MEMSET(&config, 0, sizeof(config)); + config.vertex_layout = vertex_layout; + config.vertex_size = sizeof(struct nk_vertex); + config.vertex_alignment = NK_ALIGNOF(struct nk_vertex); + config.null = dev->null; config.circle_segment_count = 22; - config.vertex_layout = vertex_layout; - config.vertex_size = sizeof(struct nk_vertex); + config.curve_segment_count = 22; + config.arc_segment_count = 22; + config.global_alpha = 1.0f; + config.shape_AA = AA; + config.line_AA = AA; + #if 0 config.line_thickness = 1.0f; #endif @@ -262,7 +267,8 @@ void nk_common_device_draw(struct nk_device *dev, glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id); glScissor((GLint)cmd->clip_rect.x, height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h), - (GLint)cmd->clip_rect.w, (GLint)cmd->clip_rect.h); + (GLint)cmd->clip_rect.w, + (GLint)cmd->clip_rect.h); glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset); #endif diff --git a/menu/drivers/nuklear/nk_common.h b/menu/drivers/nuklear/nk_common.h index 60ec992469..f0750c3c39 100644 --- a/menu/drivers/nuklear/nk_common.h +++ b/menu/drivers/nuklear/nk_common.h @@ -15,18 +15,26 @@ * If not, see . */ +/* This file is intended for backend code. */ + #ifndef _NK_COMMON_H #define _NK_COMMON_H - /* This file is intended for backend code. */ - #define NK_INCLUDE_FIXED_TYPES #define NK_INCLUDE_STANDARD_IO +#define NK_INCLUDE_STANDARD_VARARGS #define NK_INCLUDE_DEFAULT_ALLOCATOR #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT #define NK_INCLUDE_FONT_BAKING #define NK_INCLUDE_DEFAULT_FONT +#define UNUSED(a) (void)a +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MAX(a,b) ((a) < (b) ? (b) : (a)) +#define LEN(a) (sizeof(a)/sizeof(a)[0]) + +#define MAX_SIZE 256 + #include #include "../../../deps/nuklear/nuklear.h" #include "../../../deps/stb/stb_image.h" @@ -60,14 +68,13 @@ #endif }; +/* generic nuklear members*/ extern struct nk_font *font; extern struct nk_font_atlas atlas; extern struct nk_user_font usrfnt; extern struct nk_allocator nk_alloc; extern struct nk_device device; -enum theme {THEME_BLACK, THEME_WHITE, THEME_RED, THEME_BLUE, THEME_DARK}; - struct nk_image nk_common_image_load(const char *filename); char* nk_common_file_load(const char* path, size_t* size); @@ -84,6 +91,8 @@ void* nk_common_mem_alloc(nk_handle a, void *old, nk_size b); void nk_common_mem_free(nk_handle unused, void *ptr); -void device_upload_atlas(struct nk_device *dev, const void *image, int width, int height); +void nk_upload_atlas(struct nk_device *dev, const void *image, int width, int height); + +struct nk_image color_bars, test_entry, test_entry2; #endif diff --git a/menu/drivers/nuklear/nk_menu.c b/menu/drivers/nuklear/nk_menu.c index 4f2949901a..99f0bfa323 100644 --- a/menu/drivers/nuklear/nk_menu.c +++ b/menu/drivers/nuklear/nk_menu.c @@ -15,8 +15,7 @@ * If not, see . */ - - /* This file is intended for helper functions, custom controls, etc. */ + /* This file is intended for menu functions, custom controls, etc. */ #include "nk_menu.h" @@ -37,130 +36,39 @@ void nk_wnd_get_state(nk_menu_handle_t *nk, const int id, } /* sets the theme */ -void nk_common_set_style(struct nk_context *ctx, enum theme theme) -{ - struct nk_color table[NK_COLOR_COUNT]; - if (theme == THEME_WHITE) { - table[NK_COLOR_TEXT] = nk_rgba(70, 70, 70, 255); - table[NK_COLOR_WINDOW] = nk_rgba(175, 175, 175, 255); - table[NK_COLOR_HEADER] = nk_rgba(175, 175, 175, 255); - table[NK_COLOR_BORDER] = nk_rgba(0, 0, 0, 255); - table[NK_COLOR_BUTTON] = nk_rgba(185, 185, 185, 255); - table[NK_COLOR_BUTTON_HOVER] = nk_rgba(170, 170, 170, 255); - table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(160, 160, 160, 255); - table[NK_COLOR_TOGGLE] = nk_rgba(150, 150, 150, 255); - table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(120, 120, 120, 255); - table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(175, 175, 175, 255); - table[NK_COLOR_SELECT] = nk_rgba(190, 190, 190, 255); - table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(175, 175, 175, 255); - table[NK_COLOR_SLIDER] = nk_rgba(190, 190, 190, 255); - table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(80, 80, 80, 255); - table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(70, 70, 70, 255); - table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(60, 60, 60, 255); - table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255); - table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255); - table[NK_COLOR_EDIT_CURSOR] = nk_rgba(0, 0, 0, 255); - table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255); - table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255); - table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255); - table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); - table[NK_COLOR_SCROLLBAR] = nk_rgba(180, 180, 180, 255); - table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(140, 140, 140, 255); - table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255); - table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255); - table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255); - nk_style_from_table(ctx, table); - } else if (theme == THEME_RED) { - table[NK_COLOR_TEXT] = nk_rgba(190, 190, 190, 255); - table[NK_COLOR_WINDOW] = nk_rgba(30, 33, 40, 215); - table[NK_COLOR_HEADER] = nk_rgba(181, 45, 69, 220); - table[NK_COLOR_BORDER] = nk_rgba(51, 55, 67, 255); - table[NK_COLOR_BUTTON] = nk_rgba(181, 45, 69, 255); - table[NK_COLOR_BUTTON_HOVER] = nk_rgba(190, 50, 70, 255); - table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(195, 55, 75, 255); - table[NK_COLOR_TOGGLE] = nk_rgba(51, 55, 67, 255); - table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 60, 60, 255); - table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(181, 45, 69, 255); - table[NK_COLOR_SELECT] = nk_rgba(51, 55, 67, 255); - table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(181, 45, 69, 255); - table[NK_COLOR_SLIDER] = nk_rgba(51, 55, 67, 255); - table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(181, 45, 69, 255); - table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(186, 50, 74, 255); - table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(191, 55, 79, 255); - table[NK_COLOR_PROPERTY] = nk_rgba(51, 55, 67, 255); - table[NK_COLOR_EDIT] = nk_rgba(51, 55, 67, 225); - table[NK_COLOR_EDIT_CURSOR] = nk_rgba(190, 190, 190, 255); - table[NK_COLOR_COMBO] = nk_rgba(51, 55, 67, 255); - table[NK_COLOR_CHART] = nk_rgba(51, 55, 67, 255); - table[NK_COLOR_CHART_COLOR] = nk_rgba(170, 40, 60, 255); - table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); - table[NK_COLOR_SCROLLBAR] = nk_rgba(30, 33, 40, 255); - table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); - table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); - table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); - table[NK_COLOR_TAB_HEADER] = nk_rgba(181, 45, 69, 220); - nk_style_from_table(ctx, table); - } else if (theme == THEME_BLUE) { - table[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255); - table[NK_COLOR_WINDOW] = nk_rgba(202, 212, 214, 215); - table[NK_COLOR_HEADER] = nk_rgba(137, 182, 224, 220); - table[NK_COLOR_BORDER] = nk_rgba(140, 159, 173, 255); - table[NK_COLOR_BUTTON] = nk_rgba(137, 182, 224, 255); - table[NK_COLOR_BUTTON_HOVER] = nk_rgba(142, 187, 229, 255); - table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(147, 192, 234, 255); - table[NK_COLOR_TOGGLE] = nk_rgba(177, 210, 210, 255); - table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(182, 215, 215, 255); - table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(137, 182, 224, 255); - table[NK_COLOR_SELECT] = nk_rgba(177, 210, 210, 255); - table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(137, 182, 224, 255); - table[NK_COLOR_SLIDER] = nk_rgba(177, 210, 210, 255); - table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(137, 182, 224, 245); - table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(142, 188, 229, 255); - table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(147, 193, 234, 255); - table[NK_COLOR_PROPERTY] = nk_rgba(210, 210, 210, 255); - table[NK_COLOR_EDIT] = nk_rgba(210, 210, 210, 225); - table[NK_COLOR_EDIT_CURSOR] = nk_rgba(20, 20, 20, 255); - table[NK_COLOR_COMBO] = nk_rgba(210, 210, 210, 255); - table[NK_COLOR_CHART] = nk_rgba(210, 210, 210, 255); - table[NK_COLOR_CHART_COLOR] = nk_rgba(137, 182, 224, 255); - table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); - table[NK_COLOR_SCROLLBAR] = nk_rgba(190, 200, 200, 255); - table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); - table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); - table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); - table[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255); - nk_style_from_table(ctx, table); - } else if (theme == THEME_DARK) { - table[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255); - table[NK_COLOR_WINDOW] = nk_rgba(57, 67, 71, 215); - table[NK_COLOR_HEADER] = nk_rgba(51, 51, 56, 220); - table[NK_COLOR_BORDER] = nk_rgba(46, 46, 46, 255); - table[NK_COLOR_BUTTON] = nk_rgba(48, 83, 111, 255); - table[NK_COLOR_BUTTON_HOVER] = nk_rgba(58, 93, 121, 255); - table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(63, 98, 126, 255); - table[NK_COLOR_TOGGLE] = nk_rgba(50, 58, 61, 255); - table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 53, 56, 255); - table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(48, 83, 111, 255); - table[NK_COLOR_SELECT] = nk_rgba(57, 67, 61, 255); - table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(48, 83, 111, 255); - table[NK_COLOR_SLIDER] = nk_rgba(50, 58, 61, 255); - table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(48, 83, 111, 245); - table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); - table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); - table[NK_COLOR_PROPERTY] = nk_rgba(50, 58, 61, 255); - table[NK_COLOR_EDIT] = nk_rgba(50, 58, 61, 225); - table[NK_COLOR_EDIT_CURSOR] = nk_rgba(210, 210, 210, 255); - table[NK_COLOR_COMBO] = nk_rgba(50, 58, 61, 255); - table[NK_COLOR_CHART] = nk_rgba(50, 58, 61, 255); - table[NK_COLOR_CHART_COLOR] = nk_rgba(48, 83, 111, 255); - table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255); - table[NK_COLOR_SCROLLBAR] = nk_rgba(50, 58, 61, 255); - table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(48, 83, 111, 255); - table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); - table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); - table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255); - nk_style_from_table(ctx, table); - } else { - nk_style_default(ctx); - } +void nk_common_set_style(struct nk_context *ctx) +{ + /* standard nuklear colors */ + nk_colors[NK_COLOR_TEXT] = nk_rgba(158, 158, 158, 255); + nk_colors[NK_COLOR_WINDOW] = nk_rgba(57, 67, 71, 215); + nk_colors[NK_COLOR_HEADER] = nk_rgba(51, 51, 56, 220); + nk_colors[NK_COLOR_BORDER] = nk_rgba(46, 46, 46, 255); + nk_colors[NK_COLOR_BUTTON] = nk_rgba(255, 112, 67, 255); + nk_colors[NK_COLOR_BUTTON_HOVER] = nk_rgba(58, 93, 121, 255); + nk_colors[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(63, 98, 126, 255); + nk_colors[NK_COLOR_TOGGLE] = nk_rgba(50, 58, 61, 255); + nk_colors[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 53, 56, 255); + nk_colors[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(48, 83, 111, 255); + nk_colors[NK_COLOR_SELECT] = nk_rgba(57, 67, 61, 255); + nk_colors[NK_COLOR_SELECT_ACTIVE] = nk_rgba(48, 83, 111, 255); + nk_colors[NK_COLOR_SLIDER] = nk_rgba(50, 58, 61, 255); + nk_colors[NK_COLOR_SLIDER_CURSOR] = nk_rgba(48, 83, 111, 245); + nk_colors[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); + nk_colors[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); + nk_colors[NK_COLOR_PROPERTY] = nk_rgba(50, 58, 61, 255); + nk_colors[NK_COLOR_EDIT] = nk_rgba(50, 58, 61, 225); + nk_colors[NK_COLOR_EDIT_CURSOR] = nk_rgba(210, 210, 210, 255); + nk_colors[NK_COLOR_COMBO] = nk_rgba(50, 58, 61, 255); + nk_colors[NK_COLOR_CHART] = nk_rgba(50, 58, 61, 255); + nk_colors[NK_COLOR_CHART_COLOR] = nk_rgba(48, 83, 111, 255); + nk_colors[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255); + nk_colors[NK_COLOR_SCROLLBAR] = nk_rgba(50, 58, 61, 0); + nk_colors[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(48, 83, 111, 0); + nk_colors[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 50); + nk_colors[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 100); + nk_colors[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255); + nk_style_from_table(ctx, nk_colors); + + /* style */ + ctx->style.button.text_alignment = NK_TEXT_ALIGN_CENTERED; } diff --git a/menu/drivers/nuklear/nk_menu.h b/menu/drivers/nuklear/nk_menu.h index 0016083ee8..3f2cb8cc52 100644 --- a/menu/drivers/nuklear/nk_menu.h +++ b/menu/drivers/nuklear/nk_menu.h @@ -15,7 +15,7 @@ * If not, see . */ -/* This file is intended for helper functions, custom controls, etc. */ +/* This file is intended for menu functions, custom controls, etc. */ #ifndef _NK_MENU_H #define _NK_MENU_H @@ -27,10 +27,7 @@ enum { - NK_WND_MAIN = 0, - NK_WND_SETTINGS, - NK_WND_FILE_PICKER, - NK_WND_SHADER_PARAMETERS, + NK_WND_DEBUG = 0, NK_WND_LAST }; @@ -80,14 +77,13 @@ typedef struct nk_menu_handle video_font_raster_block_t list_block; } nk_menu_handle_t; -void nk_wnd_shader_parameters(nk_menu_handle_t *nk); -void nk_wnd_main(nk_menu_handle_t *nk, const char* title); -bool nk_wnd_file_picker(nk_menu_handle_t *nk, char* title, char* in, char* out, char* filter); -void nk_wnd_settings(nk_menu_handle_t *nk); +struct nk_color nk_colors[NK_COLOR_COUNT]; + +void nk_wnd_debug(nk_menu_handle_t *nk); void nk_wnd_set_state(nk_menu_handle_t *nk, const int id, struct nk_vec2 pos, struct nk_vec2 size); void nk_wnd_get_state(nk_menu_handle_t *nk, const int id, struct nk_vec2 *pos, struct nk_vec2 *size); -void nk_common_set_style(struct nk_context *ctx, enum theme theme); +void nk_common_set_style(struct nk_context *ctx); #endif diff --git a/menu/drivers/nuklear/nk_wnd_shader_parameters.c b/menu/drivers/nuklear/nk_wnd_debug.c similarity index 90% rename from menu/drivers/nuklear/nk_wnd_shader_parameters.c rename to menu/drivers/nuklear/nk_wnd_debug.c index aa16e6783d..f016baa2fd 100644 --- a/menu/drivers/nuklear/nk_wnd_shader_parameters.c +++ b/menu/drivers/nuklear/nk_wnd_debug.c @@ -33,17 +33,17 @@ #include "../../../configuration.h" #include "../../../retroarch.h" -void nk_wnd_shader_parameters(nk_menu_handle_t *nk) +void nk_wnd_debug(nk_menu_handle_t *nk) { unsigned i; video_shader_ctx_t shader_info; struct nk_panel layout; struct nk_context *ctx = &nk->ctx; - const int id = NK_WND_SHADER_PARAMETERS; + const int id = NK_WND_DEBUG; - if (nk_begin(ctx, "Shader Parameters", nk_rect(240, 10, 300, 400), + if (nk_begin(ctx, "Debug", nk_rect(10, 10, 400, 500), NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE| - NK_WINDOW_SCALABLE|NK_WINDOW_BORDER)) + NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 30, 1); diff --git a/menu/drivers/nuklear/nk_wnd_file_picker.c b/menu/drivers/nuklear/nk_wnd_file_picker.c deleted file mode 100644 index 0ef00ee077..0000000000 --- a/menu/drivers/nuklear/nk_wnd_file_picker.c +++ /dev/null @@ -1,157 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2014-2017 - Jean-André Santoni - * Copyright (C) 2016-2017- Andrés Suárez - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "nk_menu.h" - -#include "../../menu_driver.h" -#include "../../frontend/frontend_driver.h" -#include "../../configuration.h" - -static bool assets_loaded; -static char path[PATH_MAX_LENGTH]; - -struct icon_list -{ - struct nk_image disk; - struct nk_image folder; - struct nk_image file; -}; - -struct icon_list icons; - -void load_icons(nk_menu_handle_t *nk) -{ - char buf[PATH_MAX_LENGTH] = {0}; - - fill_pathname_join(buf, nk->assets_directory, - "harddisk.png", sizeof(buf)); - icons.disk = nk_common_image_load(buf); - fill_pathname_join(buf, nk->assets_directory, - "folder.png", sizeof(buf)); - icons.folder = nk_common_image_load(buf); - fill_pathname_join(buf, nk->assets_directory, - "file.png", sizeof(buf)); - icons.file = nk_common_image_load(buf); - - assets_loaded = true; -} - -bool nk_wnd_file_picker(nk_menu_handle_t *nk, char* title, char* in, char* out, char* filter) -{ - struct nk_panel layout; - struct nk_context *ctx = &nk->ctx; - const int id = NK_WND_FILE_PICKER; - int i = 0; - static file_list_t *drives = NULL; - static struct string_list *files = NULL; - settings_t *settings = config_get_ptr(); - bool ret = false; - - if (!drives) - { - drives = (file_list_t*)calloc(1, sizeof(file_list_t)); - frontend_driver_parse_drive_list(drives, false); - } - - if (!string_is_empty(in) && string_is_empty(path)) - { - strlcpy(path, in, sizeof(path)); - files = dir_list_new(path, filter, true, settings->bools.show_hidden_files, true, false); - } - - if (!assets_loaded) - load_icons(nk); - - if (nk_begin(ctx, title, nk_rect(10, 10, 500, 400), - NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE| - NK_WINDOW_BORDER)) - { - nk_layout_row_dynamic(ctx, 30, 4); - - if (drives->size == 0) - { - if(nk_button_image_label(ctx, icons.disk, "/", - NK_TEXT_CENTERED)) - { - fill_pathname_join(path, "/", - "", sizeof(path)); - files = dir_list_new(path, filter, true, settings->bools.show_hidden_files, true, false); - } - } - else - { - for (i = 0; i < drives->size; i++) - { - if(nk_button_image_label(ctx, icons.disk, drives->list[i].path, - NK_TEXT_CENTERED)) - { - fill_pathname_join(path, drives->list[i].path, - "", sizeof(path)); - files = dir_list_new(path, filter, true, settings->bools.show_hidden_files, true, false); - } - } - } - - nk_layout_row_dynamic(ctx, 30, 1); - if (files) - { - for (i = 0; i < files->size; i++) - { - if (nk_button_image_label(ctx, path_is_directory(files->elems[i].data) ? - icons.folder : icons.file, path_basename(files->elems[i].data), - NK_TEXT_RIGHT)) - { - strlcpy (path, files->elems[i].data, sizeof(path)); - if (path_is_directory (path)) - files = dir_list_new(path, filter, true, settings->bools.show_hidden_files, true, false); - } - } - } - nk_layout_row_dynamic(ctx, 30, 1); - { - if (nk_button_text(ctx, "OK", 2)) - { - ret = true; - strlcpy(out, path, sizeof(path)); - nk->window[NK_WND_FILE_PICKER].open = false; - path[0] = '\0'; - } - } - } - - /* sort the dir list with directories first */ - dir_list_sort(files, true); - - /* copy the path variable to out*/ - - /* save position and size to restore after context reset */ - nk_wnd_set_state(nk, id, nk_window_get_position(ctx), nk_window_get_size(ctx)); - nk_end(ctx); - - return ret; -} diff --git a/menu/drivers/nuklear/nk_wnd_main.c b/menu/drivers/nuklear/nk_wnd_main.c deleted file mode 100644 index fdc7d86de2..0000000000 --- a/menu/drivers/nuklear/nk_wnd_main.c +++ /dev/null @@ -1,107 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2014-2017 - Jean-André Santoni - * Copyright (C) 2016-2017 - Andrés Suárez - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include "nk_menu.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "../../menu_driver.h" -#include "../../configuration.h" - -static char* out; -static char core[PATH_MAX_LENGTH] = {0}; -static char content[PATH_MAX_LENGTH] = {0}; -float ratio[] = {0.85f, 0.15f, 0.0f}; /* TODO: what should this be? */ - -void nk_wnd_main(nk_menu_handle_t *nk, const char* title) -{ - unsigned i; - video_shader_ctx_t shader_info; - struct nk_panel layout; - struct nk_context *ctx = &nk->ctx; - const int id = NK_WND_MAIN; - settings_t *settings = config_get_ptr(); - char core_basename[PATH_MAX_LENGTH] = {0}; - - static char picker_filter[PATH_MAX_LENGTH]; - static char picker_title[PATH_MAX_LENGTH]; - static char* picker_startup_dir; - - int len_core, len_content = 0; - - strlcpy(core_basename, path_basename(core), sizeof(core_basename)); - - if (!out) - out = core; - - if (!string_is_empty(core)) - len_core = strlen(path_basename(core)); - if (!string_is_empty(content)) - len_content = strlen(content); - - if (nk->window[NK_WND_FILE_PICKER].open) - { - if (nk_wnd_file_picker(nk, picker_title, picker_startup_dir, out, picker_filter)) - { - RARCH_LOG ("%s selected\n", out); - nk_window_close(&nk->ctx, picker_title); - } - } - - - if (nk_begin(ctx, title, nk_rect(240, 10, 600, 400), - NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE| - NK_WINDOW_SCALABLE|NK_WINDOW_BORDER)) - { - nk_layout_row_dynamic(ctx, 30, 1); - nk_label(ctx,"Core:", NK_TEXT_LEFT); - nk_layout_row(ctx, NK_DYNAMIC, 30, 3, ratio); - nk_edit_string(ctx, NK_EDIT_SIMPLE, core_basename, &len_core, 64, nk_filter_default); - if (nk_button_text(ctx, "...", 3)) - { - out = core; - strlcpy(picker_title, "Select core", sizeof(picker_title)); - strlcpy(picker_filter, ".dll", sizeof(picker_filter)); - picker_startup_dir = settings->paths.directory_libretro; - nk->window[NK_WND_FILE_PICKER].open = true; - } - nk_layout_row_dynamic(ctx, 30, 1); - nk_label(ctx,"Content:", NK_TEXT_LEFT); - nk_layout_row(ctx, NK_DYNAMIC, 30, 3, ratio); - nk_edit_string(ctx, NK_EDIT_SIMPLE, content, &len_content, 64, nk_filter_default); - if (nk_button_text(ctx, "...", 3)) - { - out = content; - strlcpy(picker_title, "Select content", sizeof(picker_title)); - strlcpy(picker_filter, ".zip", sizeof(picker_filter)); - picker_startup_dir = settings->paths.directory_menu_content; - nk->window[NK_WND_FILE_PICKER].open = true; - } - } - - /* save position and size to restore after context reset */ - nk_wnd_set_state(nk, id, nk_window_get_position(ctx), nk_window_get_size(ctx)); - nk_end(ctx); -} diff --git a/menu/drivers/nuklear/nk_wnd_settings.c b/menu/drivers/nuklear/nk_wnd_settings.c deleted file mode 100644 index a88fa2ce61..0000000000 --- a/menu/drivers/nuklear/nk_wnd_settings.c +++ /dev/null @@ -1,49 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2014-2017 - Jean-André Santoni - * Copyright (C) 2016-2017 - Andrés Suárez - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include "nk_menu.h" - -#include -#include -#include -#include - -#include -#include -#include - -#include "../../menu_driver.h" - -void nk_wnd_settings(nk_menu_handle_t *nk) -{ - unsigned i; - video_shader_ctx_t shader_info; - struct nk_panel layout; - struct nk_context *ctx = &nk->ctx; - const int id = NK_WND_SETTINGS; - - if (nk_begin(ctx, "Settings", nk_rect(240, 10, 300, 400), - NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE| - NK_WINDOW_SCALABLE|NK_WINDOW_BORDER)) - { - nk_layout_row_dynamic(ctx, 30, 1); - } - - /* save position and size to restore after context reset */ - nk_wnd_set_state(nk, id, nk_window_get_position(ctx), nk_window_get_size(ctx)); - nk_end(ctx); -} diff --git a/menu/drivers_display/menu_display_gl.c b/menu/drivers_display/menu_display_gl.c index b877b94d96..3f8fd83166 100644 --- a/menu/drivers_display/menu_display_gl.c +++ b/menu/drivers_display/menu_display_gl.c @@ -83,6 +83,7 @@ static void menu_display_gl_blend_begin(void) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_SCISSOR_TEST); shader_info.data = NULL; shader_info.idx = VIDEO_SHADER_STOCK_BLEND; @@ -94,6 +95,7 @@ static void menu_display_gl_blend_begin(void) static void menu_display_gl_blend_end(void) { glDisable(GL_BLEND); + glDisable(GL_SCISSOR_TEST); } static void menu_display_gl_viewport(void *data) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 824d8c710d..ddabd41748 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -5258,6 +5258,21 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data) menu_displaylist_parse_settings_enum(menu, info, MENU_ENUM_LABEL_VIDEO_MESSAGE_POS_Y, PARSE_ONLY_FLOAT, false); + menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_ENABLE, + PARSE_ONLY_BOOL, false); + menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_RED, + PARSE_ONLY_UINT, false); + menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_GREEN, + PARSE_ONLY_UINT, false); + menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_BLUE, + PARSE_ONLY_UINT, false); + menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_OPACITY, + PARSE_ONLY_FLOAT, false); info->need_refresh = true; info->need_push = true; diff --git a/menu/menu_setting.c b/menu/menu_setting.c index d2d63e5c5a..dbf92e1578 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -4840,6 +4840,75 @@ static bool setting_append_list( general_read_handler); menu_settings_list_current_add_range(list, list_info, 0, 1, 0.01, true, true); + CONFIG_BOOL( + list, list_info, + &settings->bools.video_msg_bgcolor_enable, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_ENABLE, + MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_ENABLE, + message_bgcolor_enable, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_NONE + ); + + CONFIG_UINT( + list, list_info, + &settings->uints.video_msg_bgcolor_red, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_RED, + MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_RED, + message_bgcolor_red, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler); + menu_settings_list_current_add_range(list, list_info, 0, 255, 1, true, true); + + CONFIG_UINT( + list, list_info, + &settings->uints.video_msg_bgcolor_green, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_GREEN, + MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_GREEN, + message_bgcolor_green, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler); + menu_settings_list_current_add_range(list, list_info, 0, 255, 1, true, true); + + CONFIG_UINT( + list, list_info, + &settings->uints.video_msg_bgcolor_blue, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_BLUE, + MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_BLUE, + message_bgcolor_blue, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler); + menu_settings_list_current_add_range(list, list_info, 0, 255, 1, true, true); + + CONFIG_FLOAT( + list, list_info, + &settings->floats.video_msg_bgcolor_opacity, + MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_OPACITY, + MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_OPACITY, + message_bgcolor_opacity, + "%.2f", + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler); + menu_settings_list_current_add_range(list, list_info, 0, 1, 0.01, true, true); + END_SUB_GROUP(list, list_info, parent_group); END_GROUP(list, list_info, parent_group); break; diff --git a/msg_hash.h b/msg_hash.h index 59f1272b24..817177e382 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -628,6 +628,11 @@ enum msg_hash_enums MENU_LABEL(VIDEO_FONT_SIZE), MENU_LABEL(VIDEO_MESSAGE_POS_X), MENU_LABEL(VIDEO_MESSAGE_POS_Y), + MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_ENABLE), + MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_RED), + MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_GREEN), + MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_BLUE), + MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_OPACITY), MENU_LABEL(VIDEO_FILTER_FLICKER), MENU_LABEL(VIDEO_SOFT_FILTER), MENU_LABEL(VIDEO_MAX_SWAPCHAIN_IMAGES), diff --git a/retroarch.cfg b/retroarch.cfg index 70e50064ba..238520536b 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -262,6 +262,13 @@ # It is a regular RGB hex number, i.e. red is "ff0000". # video_message_color = ffffff +# Background color for OSD messages. Red/Green/Blue values are from 0 to 255 and opacity is 0.0 to 1.0. +video_message_bgcolor_enable = false +video_message_bgcolor_red = 0 +video_message_bgcolor_green = 0 +video_message_bgcolor_blue = 0 +video_message_bgcolor_opacity = 1.0 + # Video refresh rate of your monitor. # Used to calculate a suitable audio input rate. # video_refresh_rate = 59.94