216 #ifndef NK_SINGLE_FILE
217 #define NK_SINGLE_FILE
220 #ifndef NK_NUKLEAR_H_
221 #define NK_NUKLEAR_H_
233 #define NK_UNDEFINED (-1.0f)
234 #define NK_UTF_INVALID 0xFFFD
235 #define NK_UTF_SIZE 4
237 #define NK_INPUT_MAX 16
239 #ifndef NK_MAX_NUMBER_BUFFER
240 #define NK_MAX_NUMBER_BUFFER 64
242 #ifndef NK_SCROLLBAR_HIDING_TIMEOUT
243 #define NK_SCROLLBAR_HIDING_TIMEOUT 4.0f
254 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199409L))
255 #define NK_API static inline
256 #elif defined(__cplusplus)
257 #define NK_API static inline
259 #define NK_API static
262 #define NK_API extern
266 #ifdef NK_SINGLE_FILE
267 #define NK_LIB static
269 #define NK_LIB extern
273 #define NK_INTERN static
274 #define NK_STORAGE static
275 #define NK_GLOBAL static
277 #define NK_FLAG(x) (1 << (x))
278 #define NK_STRINGIFY(x) #x
279 #define NK_MACRO_STRINGIFY(x) NK_STRINGIFY(x)
280 #define NK_STRING_JOIN_IMMEDIATE(arg1, arg2) arg1 ## arg2
281 #define NK_STRING_JOIN_DELAY(arg1, arg2) NK_STRING_JOIN_IMMEDIATE(arg1, arg2)
282 #define NK_STRING_JOIN(arg1, arg2) NK_STRING_JOIN_DELAY(arg1, arg2)
285 #define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__COUNTER__)
287 #define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__LINE__)
290 #ifndef NK_STATIC_ASSERT
291 #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
296 #define NK_FILE_LINE __FILE__ ":" NK_MACRO_STRINGIFY(__COUNTER__)
298 #define NK_FILE_LINE __FILE__ ":" NK_MACRO_STRINGIFY(__LINE__)
302 #define NK_MIN(a,b) ((a) < (b) ? (a) : (b))
303 #define NK_MAX(a,b) ((a) < (b) ? (b) : (a))
304 #define NK_CLAMP(i,v,x) (NK_MAX(NK_MIN(v,x), i))
306 #ifdef NK_INCLUDE_STANDARD_VARARGS
307 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
309 #define NK_PRINTF_FORMAT_STRING _Printf_format_string_
311 #define NK_PRINTF_FORMAT_STRING
313 #if defined(__GNUC__)
314 #define NK_PRINTF_VARARG_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, fmtargnumber+1)))
315 #define NK_PRINTF_VALIST_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, 0)))
317 #define NK_PRINTF_VARARG_FUNC(fmtargnumber)
318 #define NK_PRINTF_VALIST_FUNC(fmtargnumber)
329 #ifdef NK_INCLUDE_FIXED_TYPES
331 #define NK_INT8 int8_t
332 #define NK_UINT8 uint8_t
333 #define NK_INT16 int16_t
334 #define NK_UINT16 uint16_t
335 #define NK_INT32 int32_t
336 #define NK_UINT32 uint32_t
337 #define NK_SIZE_TYPE uintptr_t
338 #define NK_POINTER_TYPE uintptr_t
341 #define NK_INT8 signed char
344 #define NK_UINT8 unsigned char
347 #define NK_INT16 signed short
350 #define NK_UINT16 unsigned short
353 #if defined(_MSC_VER)
354 #define NK_INT32 __int32
356 #define NK_INT32 signed int
360 #if defined(_MSC_VER)
361 #define NK_UINT32 unsigned __int32
363 #define NK_UINT32 unsigned int
367 #if defined(_WIN64) && defined(_MSC_VER)
368 #define NK_SIZE_TYPE unsigned __int64
369 #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER)
370 #define NK_SIZE_TYPE unsigned __int32
371 #elif defined(__GNUC__) || defined(__clang__)
372 #if defined(__x86_64__) || defined(__ppc64__)
373 #define NK_SIZE_TYPE unsigned long
375 #define NK_SIZE_TYPE unsigned int
378 #define NK_SIZE_TYPE unsigned long
381 #ifndef NK_POINTER_TYPE
382 #if defined(_WIN64) && defined(_MSC_VER)
383 #define NK_POINTER_TYPE unsigned __int64
384 #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER)
385 #define NK_POINTER_TYPE unsigned __int32
386 #elif defined(__GNUC__) || defined(__clang__)
387 #if defined(__x86_64__) || defined(__ppc64__)
388 #define NK_POINTER_TYPE unsigned long
390 #define NK_POINTER_TYPE unsigned int
393 #define NK_POINTER_TYPE unsigned long
433 struct nk_draw_command;
441 struct nk_draw_vertex_layout_element;
445 struct nk_style_slide;
547 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
654 #ifdef NK_INCLUDE_COMMAND_USERDATA
1210 #define nk_foreach(c, ctx) for((c) = nk__begin(ctx); (c) != 0; (c) = nk__next(ctx,c))
1211 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
1287 NK_API const struct nk_draw_command* nk__draw_next(
const struct nk_draw_command*,
const struct nk_buffer*,
const struct nk_context*);
1301 #define nk_draw_foreach(cmd,ctx, b) for((cmd)=nk__draw_begin(ctx, b); (cmd)!=0; (cmd)=nk__draw_next(cmd, b, ctx))
2856 #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__)
2873 #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)
2916 #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__)
2936 #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)
3014 #define nk_tree_element_push(ctx, type, title, state, sel) nk_tree_element_push_hashed(ctx, type, title, state, sel, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__)
3015 #define nk_tree_element_push_id(ctx, type, title, state, sel, id) nk_tree_element_push_hashed(ctx, type, title, state, sel, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id)
3095 #ifdef NK_INCLUDE_STANDARD_VARARGS
3096 NK_API void nk_labelf(
struct nk_context*,
nk_flags, NK_PRINTF_FORMAT_STRING
const char*, ...) NK_PRINTF_VARARG_FUNC(3);
3098 NK_API void nk_labelf_wrap(struct
nk_context*, NK_PRINTF_FORMAT_STRING const
char*,...) NK_PRINTF_VARARG_FUNC(2);
3099 NK_API void nk_labelf_colored_wrap(struct
nk_context*, struct
nk_color, NK_PRINTF_FORMAT_STRING const
char*,...) NK_PRINTF_VARARG_FUNC(3);
3100 NK_API void nk_labelfv(struct
nk_context*,
nk_flags, NK_PRINTF_FORMAT_STRING const
char*, va_list) NK_PRINTF_VALIST_FUNC(3);
3102 NK_API void nk_labelfv_wrap(struct
nk_context*, NK_PRINTF_FORMAT_STRING const
char*, va_list) NK_PRINTF_VALIST_FUNC(2);
3103 NK_API void nk_labelfv_colored_wrap(struct
nk_context*, struct
nk_color, NK_PRINTF_FORMAT_STRING const
char*, va_list) NK_PRINTF_VALIST_FUNC(3);
3106 NK_API void nk_value_uint(struct
nk_context*, const
char *prefix,
unsigned int);
3409 NK_API double nk_propertyd(
struct nk_context*,
const char *name,
double min,
double val,
double max,
double step,
float inc_per_pixel);
3527 #ifdef NK_INCLUDE_STANDARD_VARARGS
3528 NK_API void nk_tooltipf(
struct nk_context*, NK_PRINTF_FORMAT_STRING
const char*, ...) NK_PRINTF_VARARG_FUNC(2);
3529 NK_API void nk_tooltipfv(struct
nk_context*, NK_PRINTF_FORMAT_STRING const
char*, va_list) NK_PRINTF_VALIST_FUNC(2);
3895 struct nk_user_font_glyph;
3898 struct nk_user_font_glyph *glyph,
3901 #if defined(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) || defined(NK_INCLUDE_SOFTWARE_FONT)
3902 struct nk_user_font_glyph {
3907 float width, height;
3921 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
3929 #ifdef NK_INCLUDE_FONT_BAKING
3930 enum nk_font_coord_type {
3936 struct nk_baked_font {
3939 float ascent, descent;
3949 struct nk_font_config {
3950 struct nk_font_config *next;
3959 unsigned char ttf_data_owned_by_atlas;
3961 unsigned char merge_mode;
3963 unsigned char pixel_snap;
3965 unsigned char oversample_v, oversample_h;
3967 unsigned char padding[3];
3971 enum nk_font_coord_type coord_type;
3977 struct nk_baked_font *font;
3981 struct nk_font_config *n;
3982 struct nk_font_config *p;
3985 struct nk_font_glyph {
3988 float x0, y0, x1, y1, w, h;
3989 float u0, v0, u1, v1;
3993 struct nk_font *next;
3995 struct nk_baked_font info;
3997 struct nk_font_glyph *glyphs;
3998 const struct nk_font_glyph *fallback;
4001 struct nk_font_config *config;
4004 enum nk_font_atlas_format {
4005 NK_FONT_ATLAS_ALPHA8,
4006 NK_FONT_ATLAS_RGBA32
4009 struct nk_font_atlas {
4021 struct nk_font_glyph *glyphs;
4022 struct nk_font *default_font;
4023 struct nk_font *fonts;
4024 struct nk_font_config *config;
4034 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
4035 NK_API void nk_font_atlas_init_default(
struct nk_font_atlas*);
4039 NK_API void nk_font_atlas_begin(
struct nk_font_atlas*);
4040 NK_API struct nk_font_config nk_font_config(float pixel_height);
4041 NK_API struct nk_font *nk_font_atlas_add(
struct nk_font_atlas*,
const struct nk_font_config*);
4042 #ifdef NK_INCLUDE_DEFAULT_FONT
4043 NK_API struct nk_font* nk_font_atlas_add_default(
struct nk_font_atlas*,
float height,
const struct nk_font_config*);
4045 NK_API struct nk_font* nk_font_atlas_add_from_memory(
struct nk_font_atlas *atlas,
void *memory,
nk_size size,
float height,
const struct nk_font_config *config);
4046 #ifdef NK_INCLUDE_STANDARD_IO
4047 NK_API struct nk_font* nk_font_atlas_add_from_file(
struct nk_font_atlas *atlas,
const char *file_path,
float height,
const struct nk_font_config*);
4049 NK_API struct nk_font *nk_font_atlas_add_compressed(
struct nk_font_atlas*,
void *memory,
nk_size size,
float height,
const struct nk_font_config*);
4050 NK_API struct nk_font* nk_font_atlas_add_compressed_base85(
struct nk_font_atlas*,
const char *data,
float height,
const struct nk_font_config *config);
4051 NK_API const void* nk_font_atlas_bake(
struct nk_font_atlas*,
int *width,
int *height,
enum nk_font_atlas_format);
4053 NK_API const struct nk_font_glyph* nk_font_find_glyph(
struct nk_font*,
nk_rune unicode);
4054 NK_API void nk_font_atlas_cleanup(
struct nk_font_atlas *atlas);
4055 NK_API void nk_font_atlas_clear(
struct nk_font_atlas*);
4139 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
4169 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
4238 #ifndef NK_TEXTEDIT_UNDOSTATECOUNT
4239 #define NK_TEXTEDIT_UNDOSTATECOUNT 99
4242 #ifndef NK_TEXTEDIT_UNDOCHARCOUNT
4243 #define NK_TEXTEDIT_UNDOCHARCOUNT 999
4310 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
4400 #ifdef NK_INCLUDE_COMMAND_USERDATA
4536 unsigned short w,
unsigned short h,
nk_handle callback_data);
4572 NK_API void nk_stroke_curve(
struct nk_command_buffer*,
float,
float,
float,
float,
float,
float,
float,
float,
float line_thickness,
struct nk_color);
4651 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
4665 #ifdef NK_UINT_DRAW_INDEX
4666 typedef nk_uint nk_draw_index;
4670 enum nk_draw_list_stroke {
4677 enum nk_draw_vertex_layout_attribute {
4681 NK_VERTEX_ATTRIBUTE_COUNT
4684 enum nk_draw_vertex_layout_format {
4694 NK_FORMAT_COLOR_BEGIN,
4695 NK_FORMAT_R8G8B8 = NK_FORMAT_COLOR_BEGIN,
4696 NK_FORMAT_R16G15B16,
4697 NK_FORMAT_R32G32B32,
4701 NK_FORMAT_R16G15B16A16,
4702 NK_FORMAT_R32G32B32A32,
4703 NK_FORMAT_R32G32B32A32_FLOAT,
4704 NK_FORMAT_R32G32B32A32_DOUBLE,
4708 NK_FORMAT_COLOR_END = NK_FORMAT_RGBA32,
4712 #define NK_VERTEX_LAYOUT_END NK_VERTEX_ATTRIBUTE_COUNT,NK_FORMAT_COUNT,0
4713 struct nk_draw_vertex_layout_element {
4714 enum nk_draw_vertex_layout_attribute attribute;
4715 enum nk_draw_vertex_layout_format format;
4719 struct nk_draw_command {
4720 unsigned int elem_count;
4726 #ifdef NK_INCLUDE_COMMAND_USERDATA
4731 struct nk_draw_list {
4733 struct nk_vec2 circle_vtx[12];
4740 unsigned int element_count;
4741 unsigned int vertex_count;
4742 unsigned int cmd_count;
4745 unsigned int path_count;
4746 unsigned int path_offset;
4751 #ifdef NK_INCLUDE_COMMAND_USERDATA
4757 NK_API void nk_draw_list_init(
struct nk_draw_list*);
4761 #define nk_draw_list_foreach(cmd, can, b) for((cmd)=nk__draw_list_begin(can, b); (cmd)!=0; (cmd)=nk__draw_list_next(cmd, b, can))
4762 NK_API const struct nk_draw_command* nk__draw_list_begin(
const struct nk_draw_list*,
const struct nk_buffer*);
4763 NK_API const struct nk_draw_command* nk__draw_list_next(
const struct nk_draw_command*,
const struct nk_buffer*,
const struct nk_draw_list*);
4764 NK_API const struct nk_draw_command* nk__draw_list_end(
const struct nk_draw_list*,
const struct nk_buffer*);
4767 NK_API void nk_draw_list_path_clear(
struct nk_draw_list*);
4768 NK_API void nk_draw_list_path_line_to(
struct nk_draw_list*,
struct nk_vec2 pos);
4769 NK_API void nk_draw_list_path_arc_to_fast(
struct nk_draw_list*,
struct nk_vec2 center,
float radius,
int a_min,
int a_max);
4770 NK_API void nk_draw_list_path_arc_to(
struct nk_draw_list*,
struct nk_vec2 center,
float radius,
float a_min,
float a_max,
unsigned int segments);
4771 NK_API void nk_draw_list_path_rect_to(
struct nk_draw_list*,
struct nk_vec2 a,
struct nk_vec2 b,
float rounding);
4772 NK_API void nk_draw_list_path_curve_to(
struct nk_draw_list*,
struct nk_vec2 p2,
struct nk_vec2 p3,
struct nk_vec2 p4,
unsigned int num_segments);
4773 NK_API void nk_draw_list_path_fill(
struct nk_draw_list*,
struct nk_color);
4774 NK_API void nk_draw_list_path_stroke(
struct nk_draw_list*,
struct nk_color,
enum nk_draw_list_stroke closed,
float thickness);
4778 NK_API void nk_draw_list_stroke_rect(
struct nk_draw_list*,
struct nk_rect rect,
struct nk_color,
float rounding,
float thickness);
4780 NK_API void nk_draw_list_stroke_circle(
struct nk_draw_list*,
struct nk_vec2 center,
float radius,
struct nk_color,
unsigned int segs,
float thickness);
4782 NK_API void nk_draw_list_stroke_poly_line(
struct nk_draw_list*,
const struct nk_vec2 *pnts,
const unsigned int cnt,
struct nk_color,
enum nk_draw_list_stroke,
float thickness,
enum nk_anti_aliasing);
4785 NK_API void nk_draw_list_fill_rect(
struct nk_draw_list*,
struct nk_rect rect,
struct nk_color,
float rounding);
4788 NK_API void nk_draw_list_fill_circle(
struct nk_draw_list*,
struct nk_vec2 center,
float radius,
struct nk_color col,
unsigned int segs);
4793 NK_API void nk_draw_list_add_text(
struct nk_draw_list*,
const struct nk_user_font*,
struct nk_rect,
const char *text,
int len,
float font_height,
struct nk_color);
4794 #ifdef NK_INCLUDE_COMMAND_USERDATA
4795 NK_API void nk_draw_list_push_userdata(
struct nk_draw_list*,
nk_handle userdata);
5245 #ifndef NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS
5246 #define NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS 16
5248 #ifndef NK_CHART_MAX_SLOT
5249 #define NK_CHART_MAX_SLOT 4
5347 #ifndef NK_WINDOW_MAX_NAME
5348 #define NK_WINDOW_MAX_NAME 64
5460 #ifndef NK_BUTTON_BEHAVIOR_STACK_SIZE
5461 #define NK_BUTTON_BEHAVIOR_STACK_SIZE 8
5464 #ifndef NK_FONT_STACK_SIZE
5465 #define NK_FONT_STACK_SIZE 8
5468 #ifndef NK_STYLE_ITEM_STACK_SIZE
5469 #define NK_STYLE_ITEM_STACK_SIZE 16
5472 #ifndef NK_FLOAT_STACK_SIZE
5473 #define NK_FLOAT_STACK_SIZE 32
5476 #ifndef NK_VECTOR_STACK_SIZE
5477 #define NK_VECTOR_STACK_SIZE 16
5480 #ifndef NK_FLAGS_STACK_SIZE
5481 #define NK_FLAGS_STACK_SIZE 32
5484 #ifndef NK_COLOR_STACK_SIZE
5485 #define NK_COLOR_STACK_SIZE 32
5488 #define NK_CONFIGURATION_STACK_TYPE(prefix, name, type)\
5489 struct nk_config_stack_##name##_element {\
5490 prefix##_##type *address;\
5491 prefix##_##type old_value;\
5493 #define NK_CONFIG_STACK(type,size)\
5494 struct nk_config_stack_##type {\
5496 struct nk_config_stack_##type##_element elements[size];\
5499 #define nk_float float
5529 #define NK_VALUE_PAGE_CAPACITY \
5530 (((NK_MAX(sizeof(struct nk_window),sizeof(struct nk_panel)) / sizeof(nk_uint))) / 2)
5583 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
5584 struct nk_draw_list draw_list;
5586 #ifdef NK_INCLUDE_COMMAND_USERDATA
5613 #define NK_PI 3.141592654f
5614 #define NK_UTF_INVALID 0xFFFD
5615 #define NK_MAX_FLOAT_PRECISION 2
5617 #define NK_UNUSED(x) ((void)(x))
5618 #define NK_SATURATE(x) (NK_MAX(0, NK_MIN(1.0f, x)))
5619 #define NK_LEN(a) (sizeof(a)/sizeof(a)[0])
5620 #define NK_ABS(a) (((a) < 0) ? -(a) : (a))
5621 #define NK_BETWEEN(x, a, b) ((a) <= (x) && (x) < (b))
5622 #define NK_INBOX(px, py, x, y, w, h)\
5623 (NK_BETWEEN(px,x,x+w) && NK_BETWEEN(py,y,y+h))
5624 #define NK_INTERSECT(x0, y0, w0, h0, x1, y1, w1, h1) \
5625 (!(((x1 > (x0 + w0)) || ((x1 + w1) < x0) || (y1 > (y0 + h0)) || (y1 + h1) < y0)))
5626 #define NK_CONTAINS(x, y, w, h, bx, by, bw, bh)\
5627 (NK_INBOX(x,y, bx, by, bw, bh) && NK_INBOX(x+w,y+h, bx, by, bw, bh))
5629 #define nk_vec2_sub(a, b) nk_vec2((a).x - (b).x, (a).y - (b).y)
5630 #define nk_vec2_add(a, b) nk_vec2((a).x + (b).x, (a).y + (b).y)
5631 #define nk_vec2_len_sqr(a) ((a).x*(a).x+(a).y*(a).y)
5632 #define nk_vec2_muls(a, t) nk_vec2((a).x * (t), (a).y * (t))
5634 #define nk_ptr_add(t, p, i) ((t*)((void*)((nk_byte*)(p) + (i))))
5635 #define nk_ptr_add_const(t, p, i) ((const t*)((const void*)((const nk_byte*)(p) + (i))))
5636 #define nk_zero_struct(s) nk_zero(&s, sizeof(s))
5642 #if defined(__PTRDIFF_TYPE__)
5643 # define NK_UINT_TO_PTR(x) ((void*)(__PTRDIFF_TYPE__)(x))
5644 # define NK_PTR_TO_UINT(x) ((nk_size)(__PTRDIFF_TYPE__)(x))
5645 #elif !defined(__GNUC__)
5646 # define NK_UINT_TO_PTR(x) ((void*)&((char*)0)[x])
5647 # define NK_PTR_TO_UINT(x) ((nk_size)(((char*)x)-(char*)0))
5648 #elif defined(NK_USE_FIXED_TYPES)
5649 # define NK_UINT_TO_PTR(x) ((void*)(uintptr_t)(x))
5650 # define NK_PTR_TO_UINT(x) ((uintptr_t)(x))
5652 # define NK_UINT_TO_PTR(x) ((void*)(x))
5653 # define NK_PTR_TO_UINT(x) ((nk_size)(x))
5656 #define NK_ALIGN_PTR(x, mask)\
5657 (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x) + (mask-1)) & ~(mask-1))))
5658 #define NK_ALIGN_PTR_BACK(x, mask)\
5659 (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x)) & ~(mask-1))))
5661 #define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m))
5662 #define NK_CONTAINER_OF(ptr,type,member)\
5663 (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member)))
5670 template<
typename T>
struct nk_alignof;
5671 template<
typename T,
int size_diff>
struct nk_helper{
enum {value = size_diff};};
5672 template<
typename T>
struct nk_helper<T,0>{
enum {value = nk_alignof<T>::value};};
5673 template<
typename T>
struct nk_alignof{
struct Big {T x;
char c;};
enum {
5674 diff =
sizeof(Big) -
sizeof(T), value = nk_helper<Big, diff>::value};};
5675 #define NK_ALIGNOF(t) (nk_alignof<t>::value)
5676 #elif defined(_MSC_VER)
5677 #define NK_ALIGNOF(t) (__alignof(t))
5679 #define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0)
5684 #ifdef NK_IMPLEMENTATION
5686 #ifndef NK_INTERNAL_H
5687 #define NK_INTERNAL_H
5689 #ifndef NK_POOL_DEFAULT_CAPACITY
5690 #define NK_POOL_DEFAULT_CAPACITY 16
5693 #ifndef NK_DEFAULT_COMMAND_BUFFER_SIZE
5694 #define NK_DEFAULT_COMMAND_BUFFER_SIZE (4*1024)
5697 #ifndef NK_BUFFER_DEFAULT_INITIAL_SIZE
5698 #define NK_BUFFER_DEFAULT_INITIAL_SIZE (4*1024)
5702 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
5705 #ifdef NK_INCLUDE_STANDARD_IO
5708 #ifdef NK_INCLUDE_STANDARD_VARARGS
5713 #define NK_ASSERT(expr) assert(expr)
5717 #define NK_MEMSET nk_memset
5720 #define NK_MEMCPY nk_memcopy
5723 #define NK_SQRT nk_sqrt
5726 #define NK_SIN nk_sin
5729 #define NK_COS nk_cos
5732 #define NK_STRTOD nk_strtod
5735 #define NK_DTOA nk_dtoa
5738 #define NK_DEFAULT (-1)
5740 #ifndef NK_VSNPRINTF
5745 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) ||\
5746 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
5747 (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) ||\
5748 (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)) ||\
5749 defined(_ISOC99_SOURCE) || defined(_BSD_SOURCE)
5750 #define NK_VSNPRINTF(s,n,f,a) vsnprintf(s,n,f,a)
5752 #define NK_VSNPRINTF(s,n,f,a) vsprintf(s,f,a)
5756 #define NK_SCHAR_MIN (-127)
5757 #define NK_SCHAR_MAX 127
5758 #define NK_UCHAR_MIN 0
5759 #define NK_UCHAR_MAX 256
5760 #define NK_SSHORT_MIN (-32767)
5761 #define NK_SSHORT_MAX 32767
5762 #define NK_USHORT_MIN 0
5763 #define NK_USHORT_MAX 65535
5764 #define NK_SINT_MIN (-2147483647)
5765 #define NK_SINT_MAX 2147483647
5766 #define NK_UINT_MIN 0
5767 #define NK_UINT_MAX 4294967295u
5782 NK_GLOBAL const struct nk_rect nk_null_rect = {-8192.0f, -8192.0f, 16384, 16384};
5783 #define NK_FLOAT_PRECISION 0.00000000000001
5793 #define nk_widget_state_reset(s)\
5794 if ((*(s)) & NK_WIDGET_STATE_MODIFIED)\
5795 (*(s)) = NK_WIDGET_STATE_INACTIVE|NK_WIDGET_STATE_MODIFIED;\
5796 else (*(s)) = NK_WIDGET_STATE_INACTIVE;
5799 NK_LIB float nk_inv_sqrt(
float n);
5800 NK_LIB float nk_sqrt(
float x);
5801 NK_LIB float nk_sin(
float x);
5802 NK_LIB float nk_cos(
float x);
5806 NK_LIB void nk_unify(
struct nk_rect *clip,
const struct nk_rect *a,
float x0,
float y0,
float x1,
float y1);
5807 NK_LIB double nk_pow(
double x,
int n);
5808 NK_LIB int nk_ifloord(
double x);
5809 NK_LIB int nk_ifloorf(
float x);
5810 NK_LIB int nk_iceilf(
float x);
5811 NK_LIB int nk_log10(
double n);
5814 enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE};
5815 NK_LIB int nk_is_lower(
int c);
5816 NK_LIB int nk_is_upper(
int c);
5817 NK_LIB int nk_to_upper(
int c);
5818 NK_LIB int nk_to_lower(
int c);
5819 NK_LIB void* nk_memcopy(
void *dst,
const void *src,
nk_size n);
5822 NK_LIB char *nk_itoa(
char *s,
long n);
5823 NK_LIB int nk_string_float_limit(
char *
string,
int prec);
5824 NK_LIB char *nk_dtoa(
char *s,
double n);
5825 NK_LIB int nk_text_clamp(
const struct nk_user_font *font,
const char *text,
int text_len,
float space,
int *glyphs,
float *text_width,
nk_rune *sep_list,
int sep_count);
5826 NK_LIB struct nk_vec2 nk_text_calculate_text_bounds(const struct
nk_user_font *font,
const char *begin,
int byte_len,
float row_height,
const char **remaining,
struct nk_vec2 *out_offset,
int *glyphs,
int op);
5827 #ifdef NK_INCLUDE_STANDARD_VARARGS
5828 NK_LIB int nk_strfmt(
char *buf,
int buf_size,
const char *fmt, va_list args);
5830 #ifdef NK_INCLUDE_STANDARD_IO
5835 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
5865 enum nk_window_insert_location {
5897 NK_LIB int nk_panel_has_header(
nk_flags flags,
const char *title);
5907 NK_LIB float nk_layout_row_calculate_usable_space(
const struct nk_style *style,
enum nk_panel_type type,
float total_space,
int columns);
5938 NK_LIB int nk_do_button_text_symbol(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect bounds,
enum nk_symbol_type symbol,
const char *str,
int len,
nk_flags align,
enum nk_button_behavior behavior,
const struct nk_style_button *style,
const struct nk_user_font *font,
const struct nk_input *in);
5940 NK_LIB int nk_do_button_text_image(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect bounds,
struct nk_image img,
const char* str,
int len,
nk_flags align,
enum nk_button_behavior behavior,
const struct nk_style_button *style,
const struct nk_user_font *font,
const struct nk_input *in);
5943 enum nk_toggle_type {
5958 NK_LIB float nk_slider_behavior(
nk_flags *state,
struct nk_rect *logical_cursor,
struct nk_rect *visual_cursor,
struct nk_input *in,
struct nk_rect bounds,
float slider_min,
float slider_max,
float slider_value,
float slider_step,
float slider_steps);
5963 NK_LIB float nk_scrollbar_behavior(
nk_flags *state,
struct nk_input *in,
int has_scrolling,
const struct nk_rect *scroll,
const struct nk_rect *cursor,
const struct nk_rect *empty0,
const struct nk_rect *empty1,
float scroll_offset,
float target,
float scroll_step,
enum nk_orientation o);
5965 NK_LIB float nk_do_scrollbarv(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect scroll,
int has_scrolling,
float offset,
float target,
float step,
float button_pixel_inc,
const struct nk_style_scrollbar *style,
struct nk_input *in,
const struct nk_user_font *font);
5966 NK_LIB float nk_do_scrollbarh(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect scroll,
int has_scrolling,
float offset,
float target,
float step,
float button_pixel_inc,
const struct nk_style_scrollbar *style,
struct nk_input *in,
const struct nk_user_font *font);
5969 NK_LIB void nk_draw_selectable(
struct nk_command_buffer *out,
nk_flags state,
const struct nk_style_selectable *style,
int active,
const struct nk_rect *bounds,
const struct nk_rect *icon,
const struct nk_image *img,
enum nk_symbol_type sym,
const char *
string,
int len,
nk_flags align,
const struct nk_user_font *font);
5971 NK_LIB int nk_do_selectable_image(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect bounds,
const char *str,
int len,
nk_flags align,
int *value,
const struct nk_image *img,
const struct nk_style_selectable *style,
const struct nk_input *in,
const struct nk_user_font *font);
5974 NK_LIB void nk_edit_draw_text(
struct nk_command_buffer *out,
const struct nk_style_edit *style,
float pos_x,
float pos_y,
float x_offset,
const char *text,
int byte_len,
float row_height,
const struct nk_user_font *font,
struct nk_color background,
struct nk_color foreground,
int is_selected);
5983 enum nk_property_status {
5984 NK_PROPERTY_DEFAULT,
5988 enum nk_property_filter {
5992 enum nk_property_kind {
6002 struct nk_property_variant {
6003 enum nk_property_kind kind;
6004 union nk_property value;
6005 union nk_property min_value;
6006 union nk_property max_value;
6007 union nk_property step;
6009 NK_LIB struct nk_property_variant nk_property_variant_int(int value, int min_value, int max_value, int step);
6010 NK_LIB struct nk_property_variant nk_property_variant_float(float value, float min_value, float max_value, float step);
6011 NK_LIB struct nk_property_variant nk_property_variant_double(double value, double min_value, double max_value, double step);
6013 NK_LIB void nk_drag_behavior(
nk_flags *state,
const struct nk_input *in,
struct nk_rect drag,
struct nk_property_variant *variant,
float inc_per_pixel);
6016 NK_LIB void 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,
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,
enum nk_button_behavior behavior);
6017 NK_LIB void nk_property(
struct nk_context *ctx,
const char *name,
struct nk_property_variant *variant,
float inc_per_pixel,
const enum nk_property_filter filter);
6058 nk_inv_sqrt(
float n)
6061 const float threehalfs = 1.5f;
6062 union {
nk_uint i;
float f;} conv = {0};
6065 conv.i = 0x5f375A84 - (conv.i >> 1);
6066 conv.f = conv.f * (threehalfs - (x2 * conv.f * conv.f));
6072 return x * nk_inv_sqrt(x);
6077 NK_STORAGE const float a0 = +1.91059300966915117e-31f;
6078 NK_STORAGE const float a1 = +1.00086760103908896f;
6079 NK_STORAGE const float a2 = -1.21276126894734565e-2f;
6080 NK_STORAGE const float a3 = -1.38078780785773762e-1f;
6081 NK_STORAGE const float a4 = -2.67353392911981221e-2f;
6082 NK_STORAGE const float a5 = +2.08026600266304389e-2f;
6083 NK_STORAGE const float a6 = -3.03996055049204407e-3f;
6084 NK_STORAGE const float a7 = +1.38235642404333740e-4f;
6085 return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7))))));
6092 NK_STORAGE const float a0 = 9.9995999154986614e-1f;
6093 NK_STORAGE const float a1 = 1.2548995793001028e-3f;
6094 NK_STORAGE const float a2 = -5.0648546280678015e-1f;
6095 NK_STORAGE const float a3 = 1.2942246466519995e-2f;
6096 NK_STORAGE const float a4 = 2.8668384702547972e-2f;
6097 NK_STORAGE const float a5 = 7.3726485210586547e-3f;
6098 NK_STORAGE const float a6 = -3.8510875386947414e-3f;
6099 NK_STORAGE const float a7 = 4.7196604604366623e-4f;
6100 NK_STORAGE const float a8 = -1.8776444013090451e-5f;
6101 return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*(a7 + x*a8)))))));
6116 nk_pow(
double x,
int n)
6121 n = (plus) ? n : -n;
6128 return plus ? r : 1.0 / r;
6131 nk_ifloord(
double x)
6133 x = (double)((
int)x - ((x < 0.0) ? 1 : 0));
6139 x = (float)((
int)x - ((x < 0.0f) ? 1 : 0));
6147 return (x > i) ? i+1: i;
6150 float r = x - (float)t;
6151 return (r > 0.0f) ? t+1: t;
6161 neg = (n < 0) ? 1 : 0;
6162 ret = (neg) ? (
int)-n : (int)n;
6163 while ((ret / 10) > 0) {
6167 if (neg) exp = -exp;
6173 return nk_null_rect;
6201 return nk_rect(r[0], r[1], r[2], r[3]);
6206 return nk_recti(r[0], r[1], r[2], r[3]);
6212 ret.
x = r.x; ret.y = r.y;
6219 ret.
x = r.w; ret.y = r.h;
6223 nk_shrink_rect(struct
nk_rect r, float amount)
6226 r.
w =
NK_MAX(r.w, 2 * amount);
6227 r.h =
NK_MAX(r.h, 2 * amount);
6228 res.x = r.x + amount;
6229 res.y = r.y + amount;
6230 res.w = r.w - 2 * amount;
6231 res.h = r.h - 2 * amount;
6238 r.h =
NK_MAX(r.h, 2 * pad.y);
6239 r.x += pad.x; r.y += pad.y;
6248 ret.
x =
x; ret.y =
y;
6270 nk_unify(
struct nk_rect *clip,
const struct nk_rect *a,
float x0,
float y0,
6285 float pad_x,
float pad_y,
enum nk_heading direction)
6287 float w_half, h_half;
6292 r.
w = r.
w - 2 * pad_x;
6293 r.
h = r.
h - 2 * pad_y;
6298 w_half = r.
w / 2.0f;
6299 h_half = r.
h / 2.0f;
6301 if (direction ==
NK_UP) {
6305 }
else if (direction ==
NK_RIGHT) {
6307 result[1] =
nk_vec2(r.
x + r.
w, r.
y + h_half);
6309 }
else if (direction ==
NK_DOWN) {
6312 result[2] =
nk_vec2(r.
x + w_half, r.
y + r.
h);
6329 NK_INTERN int nk_str_match_here(
const char *regexp,
const char *text);
6330 NK_INTERN int nk_str_match_star(
int c,
const char *regexp,
const char *text);
6331 NK_LIB int nk_is_lower(
int c) {
return (c >=
'a' && c <=
'z') || (c >= 0xE0 && c <= 0xFF);}
6332 NK_LIB int nk_is_upper(
int c){
return (c >=
'A' && c <=
'Z') || (c >= 0xC0 && c <= 0xDF);}
6333 NK_LIB int nk_to_upper(
int c) {
return (c >=
'a' && c <=
'z') ? (c - (
'a' -
'A')) : c;}
6334 NK_LIB int nk_to_lower(
int c) {
return (c >=
'A' && c <=
'Z') ? (c - (
'a' +
'A')) : c;}
6337 nk_memcopy(
void *dst0,
const void *src0,
nk_size length)
6340 char *dst = (
char*)dst0;
6341 const char *src = (
const char*)src0;
6342 if (length == 0 || dst == src)
6346 #define nk_wsize sizeof(nk_word)
6347 #define nk_wmask (nk_wsize-1)
6348 #define NK_TLOOP(s) if (t) NK_TLOOP1(s)
6349 #define NK_TLOOP1(s) do { s; } while (--t)
6353 if ((t | (
nk_ptr)dst) & nk_wmask) {
6354 if ((t ^ (
nk_ptr)dst) & nk_wmask || length < nk_wsize)
6357 t = nk_wsize - (t & nk_wmask);
6359 NK_TLOOP1(*dst++ = *src++);
6361 t = length / nk_wsize;
6362 NK_TLOOP(*(nk_word*)(
void*)dst = *(
const nk_word*)(
const void*)src;
6363 src += nk_wsize; dst += nk_wsize);
6364 t = length & nk_wmask;
6365 NK_TLOOP(*dst++ = *src++);
6370 if ((t | (
nk_ptr)dst) & nk_wmask) {
6371 if ((t ^ (
nk_ptr)dst) & nk_wmask || length <= nk_wsize)
6376 NK_TLOOP1(*--dst = *--src);
6378 t = length / nk_wsize;
6379 NK_TLOOP(src -= nk_wsize; dst -= nk_wsize;
6380 *(nk_word*)(
void*)dst = *(
const nk_word*)(
const void*)src);
6381 t = length & nk_wmask;
6382 NK_TLOOP(*--dst = *--src);
6395 #define nk_word unsigned
6396 #define nk_wsize sizeof(nk_word)
6397 #define nk_wmask (nk_wsize - 1)
6404 if (
sizeof(
unsigned int) > 2)
6410 if (
size < 3 * nk_wsize) {
6425 t =
size / nk_wsize;
6427 *(nk_word*)((
void*)dst) = c;
6432 t = (
size & nk_wmask);
6447 NK_MEMSET(ptr, 0,
size);
6454 while (str && *str++ !=
'\0') siz++;
6458 nk_strtoi(
const char *str,
const char **endptr)
6461 const char *p = str;
6468 while (*p ==
' ') p++;
6473 while (*p && *p >=
'0' && *p <=
'9') {
6474 value = value * 10 + (int) (*p -
'0');
6482 nk_strtod(
const char *str,
const char **endptr)
6486 const char *p = str;
6494 while (*p ==
' ') p++;
6500 while (*p && *p !=
'.' && *p !=
'e') {
6501 value = value * 10.0 + (double) (*p -
'0');
6507 for(m = 0.1; *p && *p !=
'e'; p++ ) {
6508 value = value + (double) (*p -
'0') * m;
6518 }
else if (*p ==
'+') {
6523 for (pow = 0; *p; p++)
6524 pow = pow * 10 + (
int) (*p -
'0');
6526 for (m = 1.0, i = 0; i < pow; i++)
6533 number = value * neg;
6539 nk_strtof(
const char *str,
const char **endptr)
6542 double double_value;
6543 double_value = NK_STRTOD(str, endptr);
6544 float_value = (float)double_value;
6556 if (c1 <= 'Z' && c1 >=
'A') {
6560 if (c2 <= 'Z' && c2 >=
'A') {
6564 return ((d >= 0) << 1) - 1;
6570 nk_stricmpn(
const char *s1,
const char *s2,
int n)
6581 if (c1 <= 'Z' && c1 >=
'A') {
6585 if (c2 <= 'Z' && c2 >=
'A') {
6589 return ((d >= 0) << 1) - 1;
6595 nk_str_match_here(
const char *regexp,
const char *text)
6597 if (regexp[0] ==
'\0')
6599 if (regexp[1] ==
'*')
6600 return nk_str_match_star(regexp[0], regexp+2, text);
6601 if (regexp[0] ==
'$' && regexp[1] ==
'\0')
6602 return *text ==
'\0';
6603 if (*text!=
'\0' && (regexp[0]==
'.' || regexp[0]==*text))
6604 return nk_str_match_here(regexp+1, text+1);
6608 nk_str_match_star(
int c,
const char *regexp,
const char *text)
6611 if (nk_str_match_here(regexp, text))
6613 }
while (*text !=
'\0' && (*text++ == c || c ==
'.'));
6625 if (regexp[0] ==
'^')
6626 return nk_str_match_here(regexp+1, text);
6628 if (nk_str_match_here(regexp, text))
6630 }
while (*text++ !=
'\0');
6635 const char *pattern,
int *out_score)
6642 #define NK_ADJACENCY_BONUS 5
6644 #define NK_SEPARATOR_BONUS 10
6646 #define NK_CAMEL_BONUS 10
6648 #define NK_LEADING_LETTER_PENALTY (-3)
6650 #define NK_MAX_LEADING_LETTER_PENALTY (-9)
6652 #define NK_UNMATCHED_LETTER_PENALTY (-1)
6656 char const * pattern_iter = pattern;
6664 char const * best_letter = 0;
6665 int best_letter_score = 0;
6670 if (!str || !str_len || !pattern)
return 0;
6671 while (str_iter < str_len)
6673 const char pattern_letter = *pattern_iter;
6674 const char str_letter = str[str_iter];
6676 int next_match = *pattern_iter !=
'\0' &&
6677 nk_to_lower(pattern_letter) == nk_to_lower(str_letter);
6678 int rematch = best_letter && nk_to_upper(*best_letter) == nk_to_upper(str_letter);
6680 int advanced = next_match && best_letter;
6681 int pattern_repeat = best_letter && *pattern_iter !=
'\0';
6682 pattern_repeat = pattern_repeat &&
6683 nk_to_lower(*best_letter) == nk_to_lower(pattern_letter);
6685 if (advanced || pattern_repeat) {
6686 score += best_letter_score;
6688 best_letter_score = 0;
6691 if (next_match || rematch)
6695 if (pattern_iter == pattern) {
6696 int count = (int)(&str[str_iter] - str);
6697 int penalty = NK_LEADING_LETTER_PENALTY * count;
6698 if (penalty < NK_MAX_LEADING_LETTER_PENALTY)
6699 penalty = NK_MAX_LEADING_LETTER_PENALTY;
6706 new_score += NK_ADJACENCY_BONUS;
6710 new_score += NK_SEPARATOR_BONUS;
6713 if (prev_lower && nk_is_upper(str_letter))
6714 new_score += NK_CAMEL_BONUS;
6721 if (new_score >= best_letter_score) {
6723 if (best_letter != 0)
6724 score += NK_UNMATCHED_LETTER_PENALTY;
6726 best_letter = &str[str_iter];
6727 best_letter_score = new_score;
6731 score += NK_UNMATCHED_LETTER_PENALTY;
6736 prev_lower = nk_is_lower(str_letter) != 0;
6737 prev_separator = str_letter ==
'_' || str_letter ==
' ';
6744 score += best_letter_score;
6747 if (*pattern_iter !=
'\0')
6760 nk_string_float_limit(
char *
string,
int prec)
6770 if (dot == (prec+1)) {
6777 return (
int)(c - string);
6780 nk_strrev_ascii(
char *s)
6786 for (; i < end; ++i) {
6788 s[i] = s[len - 1 - i];
6793 nk_itoa(
char *s,
long n)
6806 s[i++] = (char)(
'0' + (n % 10));
6817 nk_dtoa(
char *s,
double n)
6820 int digit = 0, m = 0, m1 = 0;
6828 s[0] =
'0'; s[1] =
'\0';
6837 useExp = (m >= 14 || (neg && m >= 9) || m <= -9);
6838 if (neg) *(c++) =
'-';
6844 n = n / (double)nk_pow(10.0, m);
6853 while (n > NK_FLOAT_PRECISION || m >= 0) {
6854 double weight = nk_pow(10.0, m);
6856 double t = (double)n / weight;
6857 digit = nk_ifloord(t);
6858 n -= ((double)digit * weight);
6859 *(c++) = (
char)(
'0' + (char)digit);
6861 if (m == 0 && n > 0)
6878 *(c++) = (
char)(
'0' + (char)(m1 % 10));
6883 for (i = 0, j = m-1; i<j; i++, j--) {
6894 #ifdef NK_INCLUDE_STANDARD_VARARGS
6895 #ifndef NK_INCLUDE_STANDARD_IO
6897 nk_vsnprintf(
char *buf,
int buf_size,
const char *fmt, va_list args)
6902 NK_ARG_TYPE_DEFAULT,
6906 NK_ARG_FLAG_LEFT = 0x01,
6907 NK_ARG_FLAG_PLUS = 0x02,
6908 NK_ARG_FLAG_SPACE = 0x04,
6909 NK_ARG_FLAG_NUM = 0x10,
6910 NK_ARG_FLAG_ZERO = 0x20
6914 enum nk_arg_type arg_type = NK_ARG_TYPE_DEFAULT;
6915 int precision = NK_DEFAULT;
6916 int width = NK_DEFAULT;
6921 const char *iter = fmt;
6924 NK_ASSERT(buf_size);
6925 if (!buf || !buf_size || !fmt)
return 0;
6926 for (iter = fmt; *iter && len < buf_size; iter++) {
6928 while (*iter && (*iter !=
'%') && (len < buf_size))
6929 buf[len++] = *iter++;
6930 if (!(*iter) || len >= buf_size)
break;
6935 if (*iter ==
'-') flag |= NK_ARG_FLAG_LEFT;
6936 else if (*iter ==
'+') flag |= NK_ARG_FLAG_PLUS;
6937 else if (*iter ==
' ') flag |= NK_ARG_FLAG_SPACE;
6938 else if (*iter ==
'#') flag |= NK_ARG_FLAG_NUM;
6939 else if (*iter ==
'0') flag |= NK_ARG_FLAG_ZERO;
6946 if (*iter >=
'1' && *iter <=
'9') {
6952 }
else if (*iter ==
'*') {
6953 width = va_arg(args,
int);
6958 precision = NK_DEFAULT;
6962 precision = va_arg(args,
int);
6975 if (*(iter+1) ==
'h') {
6976 arg_type = NK_ARG_TYPE_CHAR;
6978 }
else arg_type = NK_ARG_TYPE_SHORT;
6980 }
else if (*iter ==
'l') {
6981 arg_type = NK_ARG_TYPE_LONG;
6983 }
else arg_type = NK_ARG_TYPE_DEFAULT;
6987 NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT);
6988 NK_ASSERT(precision == NK_DEFAULT);
6989 NK_ASSERT(width == NK_DEFAULT);
6992 }
else if (*iter ==
's') {
6994 const char *str = va_arg(args,
const char*);
6995 NK_ASSERT(str != buf &&
"buffer and argument are not allowed to overlap!");
6996 NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT);
6997 NK_ASSERT(precision == NK_DEFAULT);
6998 NK_ASSERT(width == NK_DEFAULT);
6999 if (str == buf)
return -1;
7000 while (str && *str && len < buf_size)
7001 buf[len++] = *str++;
7002 }
else if (*iter ==
'n') {
7004 signed int *n = va_arg(args,
int*);
7005 NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT);
7006 NK_ASSERT(precision == NK_DEFAULT);
7007 NK_ASSERT(width == NK_DEFAULT);
7009 }
else if (*iter ==
'c' || *iter ==
'i' || *iter ==
'd') {
7012 const char *num_iter;
7013 int num_len, num_print, padding;
7014 int cur_precision =
NK_MAX(precision, 1);
7015 int cur_width =
NK_MAX(width, 0);
7018 if (arg_type == NK_ARG_TYPE_CHAR)
7019 value = (
signed char)va_arg(args,
int);
7020 else if (arg_type == NK_ARG_TYPE_SHORT)
7021 value = (
signed short)va_arg(args,
int);
7022 else if (arg_type == NK_ARG_TYPE_LONG)
7023 value = va_arg(args,
signed long);
7024 else if (*iter ==
'c')
7025 value = (
unsigned char)va_arg(args,
int);
7026 else value = va_arg(args,
signed int);
7029 nk_itoa(number_buffer, value);
7031 padding =
NK_MAX(cur_width -
NK_MAX(cur_precision, num_len), 0);
7032 if ((flag & NK_ARG_FLAG_PLUS) || (flag & NK_ARG_FLAG_SPACE))
7033 padding =
NK_MAX(padding-1, 0);
7036 if (!(flag & NK_ARG_FLAG_LEFT)) {
7037 while (padding-- > 0 && (len < buf_size)) {
7038 if ((flag & NK_ARG_FLAG_ZERO) && (precision == NK_DEFAULT))
7040 else buf[len++] =
' ';
7045 if ((flag & NK_ARG_FLAG_PLUS) && value >= 0 && len < buf_size)
7047 else if ((flag & NK_ARG_FLAG_SPACE) && value >= 0 && len < buf_size)
7051 num_print =
NK_MAX(cur_precision, num_len);
7052 while (precision && (num_print > num_len) && (len < buf_size)) {
7058 num_iter = number_buffer;
7059 while (precision && *num_iter && len < buf_size)
7060 buf[len++] = *num_iter++;
7063 if (flag & NK_ARG_FLAG_LEFT) {
7064 while ((padding-- > 0) && (len < buf_size))
7067 }
else if (*iter ==
'o' || *iter ==
'x' || *iter ==
'X' || *iter ==
'u') {
7069 unsigned long value = 0;
7070 int num_len = 0, num_print, padding = 0;
7071 int cur_precision =
NK_MAX(precision, 1);
7072 int cur_width =
NK_MAX(width, 0);
7073 unsigned int base = (*iter ==
'o') ? 8: (*iter ==
'u')? 10: 16;
7076 const char *upper_output_format =
"0123456789ABCDEF";
7077 const char *lower_output_format =
"0123456789abcdef";
7078 const char *output_format = (*iter ==
'x') ?
7079 lower_output_format: upper_output_format;
7082 if (arg_type == NK_ARG_TYPE_CHAR)
7083 value = (
unsigned char)va_arg(args,
int);
7084 else if (arg_type == NK_ARG_TYPE_SHORT)
7085 value = (
unsigned short)va_arg(args,
int);
7086 else if (arg_type == NK_ARG_TYPE_LONG)
7087 value = va_arg(args,
unsigned long);
7088 else value = va_arg(args,
unsigned int);
7092 int digit = output_format[value % base];
7094 number_buffer[num_len++] = (char)digit;
7096 }
while (value > 0);
7098 num_print =
NK_MAX(cur_precision, num_len);
7099 padding =
NK_MAX(cur_width -
NK_MAX(cur_precision, num_len), 0);
7100 if (flag & NK_ARG_FLAG_NUM)
7101 padding =
NK_MAX(padding-1, 0);
7104 if (!(flag & NK_ARG_FLAG_LEFT)) {
7105 while ((padding-- > 0) && (len < buf_size)) {
7106 if ((flag & NK_ARG_FLAG_ZERO) && (precision == NK_DEFAULT))
7108 else buf[len++] =
' ';
7113 if (num_print && (flag & NK_ARG_FLAG_NUM)) {
7114 if ((*iter ==
'o') && (len < buf_size)) {
7116 }
else if ((*iter ==
'x') && ((len+1) < buf_size)) {
7119 }
else if ((*iter ==
'X') && ((len+1) < buf_size)) {
7124 while (precision && (num_print > num_len) && (len < buf_size)) {
7130 while (num_len > 0) {
7131 if (precision && (len < buf_size))
7132 buf[len++] = number_buffer[num_len-1];
7137 if (flag & NK_ARG_FLAG_LEFT) {
7138 while ((padding-- > 0) && (len < buf_size))
7141 }
else if (*iter ==
'f') {
7143 const char *num_iter;
7144 int cur_precision = (precision < 0) ? 6: precision;
7145 int prefix, cur_width =
NK_MAX(width, 0);
7146 double value = va_arg(args,
double);
7147 int num_len = 0, frac_len = 0, dot = 0;
7150 NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT);
7151 NK_DTOA(number_buffer, value);
7155 num_iter = number_buffer;
7156 while (*num_iter && *num_iter !=
'.')
7159 prefix = (*num_iter ==
'.')?(
int)(num_iter - number_buffer)+1:0;
7160 padding =
NK_MAX(cur_width - (prefix +
NK_MIN(cur_precision, num_len - prefix)) , 0);
7161 if ((flag & NK_ARG_FLAG_PLUS) || (flag & NK_ARG_FLAG_SPACE))
7162 padding =
NK_MAX(padding-1, 0);
7165 if (!(flag & NK_ARG_FLAG_LEFT)) {
7166 while (padding-- > 0 && (len < buf_size)) {
7167 if (flag & NK_ARG_FLAG_ZERO)
7169 else buf[len++] =
' ';
7174 num_iter = number_buffer;
7175 if ((flag & NK_ARG_FLAG_PLUS) && (value >= 0) && (len < buf_size))
7177 else if ((flag & NK_ARG_FLAG_SPACE) && (value >= 0) && (len < buf_size))
7180 if (dot) frac_len++;
7182 buf[len++] = *num_iter;
7183 if (*num_iter ==
'.') dot = 1;
7184 if (frac_len >= cur_precision)
break;
7189 while (frac_len < cur_precision) {
7190 if (!dot && len < buf_size) {
7200 if (flag & NK_ARG_FLAG_LEFT) {
7201 while ((padding-- > 0) && (len < buf_size))
7206 NK_ASSERT(0 &&
"specifier is not supported!");
7210 buf[(len >= buf_size)?(buf_size-1):len] = 0;
7211 result = (len >= buf_size)?-1:len;
7216 nk_strfmt(
char *buf,
int buf_size,
const char *fmt, va_list args)
7220 NK_ASSERT(buf_size);
7221 if (!buf || !buf_size || !fmt)
return 0;
7222 #ifdef NK_INCLUDE_STANDARD_IO
7223 result = NK_VSNPRINTF(buf, (
nk_size)buf_size, fmt, args);
7224 result = (result >= buf_size) ? -1: result;
7225 buf[buf_size-1] = 0;
7227 result = nk_vsnprintf(buf, buf_size, fmt, args);
7236 #define NK_ROTL(x,r) ((x) << (r) | ((x) >> (32 - r)))
7243 const int bsize =
sizeof(k1);
7244 const int nblocks = len/4;
7246 const nk_uint c1 = 0xcc9e2d51;
7247 const nk_uint c2 = 0x1b873593;
7253 for (i = 0; i < nblocks; ++i, keyptr += bsize) {
7255 k1ptr[0] = keyptr[0];
7256 k1ptr[1] = keyptr[1];
7257 k1ptr[2] = keyptr[2];
7258 k1ptr[3] = keyptr[3];
7261 k1 = NK_ROTL(k1,15);
7265 h1 = NK_ROTL(h1,13);
7266 h1 = h1*5+0xe6546b64;
7270 tail = (
const nk_byte*)(data + nblocks*4);
7273 case 3: k1 ^= (
nk_uint)(tail[2] << 16);
7274 case 2: k1 ^= (
nk_uint)(tail[1] << 8u);
7275 case 1: k1 ^= tail[0];
7277 k1 = NK_ROTL(k1,15);
7296 #ifdef NK_INCLUDE_STANDARD_IO
7307 if (!path || !siz || !alloc)
7310 fd = fopen(path,
"rb");
7312 fseek(fd, 0, SEEK_END);
7319 fseek(fd, 0, SEEK_SET);
7326 *siz = (
nk_size)fread(buf, 1,*siz, fd);
7332 nk_text_clamp(
const struct nk_user_font *font,
const char *text,
7333 int text_len,
float space,
int *glyphs,
float *text_width,
7334 nk_rune *sep_list,
int sep_count)
7338 float last_width = 0;
7347 float sep_width = 0;
7348 sep_count =
NK_MAX(sep_count,0);
7351 while (glyph_len && (width < space) && (len < text_len)) {
7354 for (i = 0; i < sep_count; ++i) {
7355 if (unicode != sep_list[i])
continue;
7356 sep_width = last_width = width;
7361 if (i == sep_count){
7362 last_width = sep_width = width;
7366 glyph_len =
nk_utf_decode(&text[len], &unicode, text_len - len);
7369 if (len >= text_len) {
7371 *text_width = last_width;
7375 *text_width = sep_width;
7376 return (!sep_len) ? len: sep_len;
7380 nk_text_calculate_text_bounds(const struct
nk_user_font *font,
7381 const char *begin,
int byte_len,
float row_height,
const char **remaining,
7382 struct nk_vec2 *out_offset,
int *glyphs,
int op)
7384 float line_height = row_height;
7386 float line_width = 0.0f;
7392 if (!begin || byte_len <= 0 || !font)
7396 if (!glyph_len)
return text_size;
7397 glyph_width = font->width(font->userdata, font->height, begin, glyph_len);
7400 while ((text_len < byte_len) && glyph_len) {
7401 if (unicode ==
'\n') {
7402 text_size.
x =
NK_MAX(text_size.
x, line_width);
7403 text_size.
y += line_height;
7406 if (op == NK_STOP_ON_NEW_LINE)
7410 glyph_len =
nk_utf_decode(begin + text_len, &unicode, byte_len-text_len);
7414 if (unicode ==
'\r') {
7417 glyph_len =
nk_utf_decode(begin + text_len, &unicode, byte_len-text_len);
7421 *glyphs = *glyphs + 1;
7422 text_len += glyph_len;
7423 line_width += (float)glyph_width;
7424 glyph_len =
nk_utf_decode(begin + text_len, &unicode, byte_len-text_len);
7425 glyph_width = font->width(font->userdata, font->height, begin+text_len, glyph_len);
7429 if (text_size.
x < line_width)
7430 text_size.
x = line_width;
7432 *out_offset =
nk_vec2(line_width, text_size.
y + line_height);
7433 if (line_width > 0 || text_size.
y == 0.0f)
7434 text_size.
y += line_height;
7436 *remaining = begin+text_len;
7450 nk_parse_hex(
const char *p,
int length)
7454 while (len < length) {
7456 if (p[len] >=
'a' && p[len] <=
'f')
7457 i += ((p[len] -
'a') + 10);
7458 else if (p[len] >=
'A' && p[len] <=
'F')
7459 i += ((p[len] -
'A') + 10);
7460 else i += (p[len] -
'0');
7479 const char *c = rgb;
7481 col.
r = (
nk_byte)nk_parse_hex(c, 2);
7482 col.g = (
nk_byte)nk_parse_hex(c+2, 2);
7483 col.b = (
nk_byte)nk_parse_hex(c+4, 2);
7491 const char *c = rgb;
7493 col.
r = (
nk_byte)nk_parse_hex(c, 2);
7494 col.g = (
nk_byte)nk_parse_hex(c+2, 2);
7495 col.b = (
nk_byte)nk_parse_hex(c+4, 2);
7496 col.a = (
nk_byte)nk_parse_hex(c+6, 2);
7502 #define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i))
7503 output[0] = (char)NK_TO_HEX((col.
r & 0xF0) >> 4);
7504 output[1] = (char)NK_TO_HEX((col.
r & 0x0F));
7505 output[2] = (char)NK_TO_HEX((col.
g & 0xF0) >> 4);
7506 output[3] = (char)NK_TO_HEX((col.
g & 0x0F));
7507 output[4] = (char)NK_TO_HEX((col.
b & 0xF0) >> 4);
7508 output[5] = (char)NK_TO_HEX((col.
b & 0x0F));
7509 output[6] = (char)NK_TO_HEX((col.
a & 0xF0) >> 4);
7510 output[7] = (char)NK_TO_HEX((col.
a & 0x0F));
7517 #define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i))
7518 output[0] = (char)NK_TO_HEX((col.
r & 0xF0) >> 4);
7519 output[1] = (char)NK_TO_HEX((col.
r & 0x0F));
7520 output[2] = (char)NK_TO_HEX((col.
g & 0xF0) >> 4);
7521 output[3] = (char)NK_TO_HEX((col.
g & 0x0F));
7522 output[4] = (char)NK_TO_HEX((col.
b & 0xF0) >> 4);
7523 output[5] = (char)NK_TO_HEX((col.
b & 0x0F));
7530 return nk_rgba(c[0], c[1], c[2], c[3]);
7535 return nk_rgba(c[0], c[1], c[2], c[3]);
7550 return nk_rgb(c[0], c[1], c[2]);
7555 return nk_rgb(c[0], c[1], c[2]);
7561 ret.
r = (in & 0xFF);
7562 ret.g = ((in >> 8) & 0xFF);
7563 ret.b = ((in >> 16) & 0xFF);
7564 ret.a = (
nk_byte)((in >> 24) & 0xFF);
7580 return nk_rgba_f(c[0], c[1], c[2], c[3]);
7608 nk_hsv(int h, int s, int v)
7615 return nk_hsv(c[0], c[1], c[2]);
7620 return nk_hsv(c[0], c[1], c[2]);
7623 nk_hsv_f(float h, float s, float v)
7633 nk_hsva(int h, int s, int v, int
a)
7635 float hf = ((float)
NK_CLAMP(0, h, 255)) / 255.0f;
7636 float sf = ((float)
NK_CLAMP(0, s, 255)) / 255.0f;
7637 float vf = ((float)
NK_CLAMP(0, v, 255)) / 255.0f;
7638 float af = ((float)
NK_CLAMP(0,
a, 255)) / 255.0f;
7644 return nk_hsva(c[0], c[1], c[2], c[3]);
7649 return nk_hsva(c[0], c[1], c[2], c[3]);
7658 out.
r = v; out.
g = v; out.
b = v; out.
a =
a;
7661 h = h / (60.0f/360.0f);
7665 q = v * (1.0f - (s * f));
7666 t = v * (1.0f - s * (1.0f - f));
7669 case 0:
default: out.r = v; out.g = t; out.b = p;
break;
7670 case 1: out.r = q; out.g = v; out.b = p;
break;
7671 case 2: out.r = p; out.g = v; out.b = t;
break;
7672 case 3: out.r = p; out.g = q; out.b = v;
break;
7673 case 4: out.r = t; out.g = p; out.b = v;
break;
7674 case 5: out.r = v; out.g = p; out.b = q;
break;}
7684 nk_hsva_f(float h, float s, float v, float
a)
7692 return nk_hsva_f(c[0], c[1], c[2], c[3]);
7707 *
r = (float)in.
r * s;
7708 *
g = (
float)in.
g * s;
7709 *
b = (float)in.
b * s;
7710 *
a = (
float)in.
a * s;
7728 *
r = (double)in.
r * s;
7729 *
g = (
double)in.
g * s;
7730 *
b = (double)in.
b * s;
7731 *
a = (
double)in.
a * s;
7752 float *out_v,
float *out_a,
struct nk_colorf in)
7757 const float t = in.
g; in.
g = in.
b; in.
b = t;
7761 const float t = in.
r; in.
r = in.
g; in.
g = t;
7764 chroma = in.
r - ((in.
g < in.
b) ? in.
g: in.
b);
7765 *out_h =
NK_ABS(K + (in.
g - in.
b)/(6.0f * chroma + 1e-20f));
7766 *out_s = chroma / (in.
r + 1e-20f);
7778 float *out_v,
float *out_a,
struct nk_color in)
7795 *out_h = (
nk_byte)(h * 255.0f);
7796 *out_s = (
nk_byte)(s * 255.0f);
7797 *out_v = (
nk_byte)(v * 255.0f);
7870 nk_utf_validate(
nk_rune *u,
int i)
7874 if (!
NK_BETWEEN(*u, nk_utfmin[i], nk_utfmax[i]) ||
7877 for (i = 1; *u > nk_utfmax[i]; ++i);
7881 nk_utf_decode_byte(
char c,
int *i)
7885 for(*i = 0; *i < (int)
NK_LEN(nk_utfmask); ++(*i)) {
7886 if (((
nk_byte)c & nk_utfmask[*i]) == nk_utfbyte[*i])
7887 return (
nk_byte)(c & ~nk_utfmask[*i]);
7894 int i, j, len, type=0;
7900 if (!c || !u)
return 0;
7901 if (!clen)
return 0;
7904 udecoded = nk_utf_decode_byte(c[0], &len);
7908 for (i = 1, j = 1; i < clen && j < len; ++i, ++j) {
7909 udecoded = (udecoded << 6) | nk_utf_decode_byte(c[i], &type);
7916 nk_utf_validate(u, len);
7920 nk_utf_encode_byte(
nk_rune u,
int i)
7922 return (
char)((nk_utfbyte[i]) | ((
nk_byte)u & ~nk_utfmask[i]));
7928 len = nk_utf_validate(&u, 0);
7932 for (i = len - 1; i != 0; --i) {
7933 c[i] = nk_utf_encode_byte(u, 0);
7936 c[0] = nk_utf_encode_byte(u, len);
7950 if (!str || !len)
return 0;
7955 while (glyph_len && src_len < len) {
7957 src_len = src_len + glyph_len;
7958 glyph_len =
nk_utf_decode(text + src_len, &unicode, text_len - src_len);
7963 nk_utf_at(
const char *buffer,
int length,
int index,
7976 if (!buffer || !unicode || !len)
return 0;
7993 src_len = src_len + glyph_len;
7994 glyph_len =
nk_utf_decode(text + src_len, unicode, text_len - src_len);
7996 if (i != index)
return 0;
7997 return buffer + src_len;
8009 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
8015 return malloc(
size);
8024 nk_buffer_init_default(
struct nk_buffer *buffer)
8027 alloc.userdata.ptr = 0;
8028 alloc.alloc = nk_malloc;
8029 alloc.free = nk_mfree;
8040 NK_ASSERT(initial_size);
8041 if (!b || !a || !initial_size)
return;
8043 nk_zero(b,
sizeof(*b));
8047 b->
size = initial_size;
8057 if (!b || !m || !
size)
return;
8059 nk_zero(b,
sizeof(*b));
8066 nk_buffer_align(
void *unaligned,
8109 if (!temp)
return 0;
8113 NK_MEMCPY(temp, b->
memory.
ptr, buffer_size);
8117 if (b->
size == buffer_size) {
8125 back_size = buffer_size - b->
size;
8126 dst =
nk_ptr_add(
void, temp, capacity - back_size);
8128 NK_MEMCPY(dst, src, back_size);
8129 b->
size = capacity - back_size;
8144 if (!b || !
size)
return 0;
8151 memory = nk_buffer_align(unaligned, align, &alignment, type);
8176 memory = nk_buffer_align(unaligned, align, &alignment, type);
8180 else b->
size -= (
size + alignment);
8189 void *mem = nk_buffer_alloc(b, type,
size, align);
8191 NK_MEMCPY(mem, memory,
size);
8197 if (!buffer)
return;
8207 if (!buffer)
return;
8249 if (!s || !b)
return;
8260 if (!buffer)
return 0;
8267 if (!buffer)
return 0;
8274 if (!buffer)
return 0;
8287 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
8289 nk_str_init_default(
struct nk_str *str)
8292 alloc.userdata.ptr = 0;
8293 alloc.alloc = nk_malloc;
8294 alloc.free = nk_mfree;
8318 if (!s || !str || !len)
return 0;
8321 NK_MEMCPY(mem, str, (
nk_size)len *
sizeof(
char));
8336 if (!str || !text || !len)
return 0;
8337 for (i = 0; i < len; ++i)
8350 if (!str || !text)
return 0;
8352 glyph_len = byte_len =
nk_utf_decode(text+byte_len, &unicode, 4);
8353 while (unicode !=
'\0' && glyph_len) {
8355 byte_len += glyph_len;
8369 if (!str || !text || !len)
return 0;
8370 for (i = 0; i < len; ++i) {
8372 if (!byte_len)
break;
8384 if (!str || !runes)
return 0;
8385 while (runes[i] !=
'\0') {
8403 NK_ASSERT(len >= 0);
8417 NK_ASSERT(((
int)pos + (
int)len + ((
int)copylen - 1)) >= 0);
8418 NK_ASSERT(((
int)pos + ((
int)copylen - 1)) >= 0);
8421 for (i = 0; i < copylen; ++i) *dst-- = *src--;
8423 NK_MEMCPY(mem, str, (
nk_size)len *
sizeof(
char));
8438 if (!str || !cstr || !len)
return 0;
8443 if (!begin)
return 0;
8465 if (!str || !text || !len)
return 0;
8466 for (i = 0; i < len; ++i)
8479 if (!str || !text)
return 0;
8481 glyph_len = byte_len =
nk_utf_decode(text+byte_len, &unicode, 4);
8482 while (unicode !=
'\0' && glyph_len) {
8484 byte_len += glyph_len;
8498 if (!str || !runes || !len)
return 0;
8499 for (i = 0; i < len; ++i) {
8501 if (!byte_len)
break;
8513 if (!str || !runes)
return 0;
8514 while (runes[i] !=
'\0') {
8525 NK_ASSERT(len >= 0);
8540 NK_ASSERT(len >= 0);
8541 if (!str || len < 0)
return;
8542 if (len >= str->
len) {
8547 index = str->
len - len;
8579 NK_ASSERT(s->
len >= pos + len);
8580 if (s->
len < pos + len)
8613 if (!str || !unicode || !len)
return 0;
8630 src_len = src_len + glyph_len;
8631 glyph_len =
nk_utf_decode(text + src_len, unicode, text_len - src_len);
8633 if (i != pos)
return 0;
8634 return text + src_len;
8656 if (!str || !unicode || !len)
return 0;
8673 src_len = src_len + glyph_len;
8674 glyph_len =
nk_utf_decode(text + src_len, unicode, text_len - src_len);
8676 if (i != pos)
return 0;
8677 return text + src_len;
8745 if (!cb || !b)
return;
8760 b->
clip = nk_null_rect;
8761 #ifdef NK_INCLUDE_COMMAND_USERDATA
8786 #ifdef NK_ZERO_COMMAND_MEMORY
8787 NK_MEMSET(cmd, 0,
size + alignment);
8792 #ifdef NK_INCLUDE_COMMAND_USERDATA
8813 cmd->
x = (short)r.
x;
8814 cmd->
y = (
short)r.
y;
8815 cmd->
w = (
unsigned short)
NK_MAX(0, r.
w);
8816 cmd->
h = (
unsigned short)
NK_MAX(0, r.
h);
8820 float x1,
float y1,
float line_thickness,
struct nk_color c)
8829 cmd->
begin.
x = (short)x0;
8830 cmd->
begin.
y = (short)y0;
8831 cmd->
end.
x = (short)x1;
8832 cmd->
end.
y = (short)y1;
8837 float ctrl0x,
float ctrl0y,
float ctrl1x,
float ctrl1y,
8848 cmd->
begin.
x = (short)ax;
8849 cmd->
begin.
y = (short)ay;
8850 cmd->
ctrl[0].
x = (short)ctrl0x;
8851 cmd->
ctrl[0].
y = (short)ctrl0y;
8852 cmd->
ctrl[1].
x = (short)ctrl1x;
8853 cmd->
ctrl[1].
y = (short)ctrl1y;
8854 cmd->
end.
x = (short)bx;
8855 cmd->
end.
y = (short)by;
8864 if (!b || c.
a == 0 || rect.
w == 0 || rect.
h == 0 ||
line_thickness <= 0)
return;
8868 clip->
x, clip->
y, clip->
w, clip->
h))
return;
8875 cmd->
x = (short)rect.
x;
8876 cmd->
y = (
short)rect.
y;
8877 cmd->
w = (
unsigned short)
NK_MAX(0, rect.
w);
8878 cmd->
h = (
unsigned short)
NK_MAX(0, rect.
h);
8887 if (!b || c.
a == 0 || rect.
w == 0 || rect.
h == 0)
return;
8891 clip->
x, clip->
y, clip->
w, clip->
h))
return;
8898 cmd->
x = (short)rect.
x;
8899 cmd->
y = (
short)rect.
y;
8900 cmd->
w = (
unsigned short)
NK_MAX(0, rect.
w);
8901 cmd->
h = (
unsigned short)
NK_MAX(0, rect.
h);
8911 if (!b || rect.
w == 0 || rect.
h == 0)
return;
8915 clip->
x, clip->
y, clip->
w, clip->
h))
return;
8921 cmd->
x = (short)rect.
x;
8922 cmd->
y = (
short)rect.
y;
8923 cmd->
w = (
unsigned short)
NK_MAX(0, rect.
w);
8924 cmd->
h = (
unsigned short)
NK_MAX(0, rect.
h);
8932 float line_thickness,
struct nk_color c)
8946 cmd->
x = (short)r.
x;
8947 cmd->
y = (
short)r.
y;
8948 cmd->
w = (
unsigned short)
NK_MAX(r.
w, 0);
8949 cmd->
h = (
unsigned short)
NK_MAX(r.
h, 0);
8957 if (!b || c.
a == 0 || r.
w == 0 || r.
h == 0)
return;
8967 cmd->
x = (short)r.
x;
8968 cmd->
y = (
short)r.
y;
8969 cmd->
w = (
unsigned short)
NK_MAX(r.
w, 0);
8970 cmd->
h = (
unsigned short)
NK_MAX(r.
h, 0);
8975 float a_min,
float a_max,
float line_thickness,
struct nk_color c)
8983 cmd->
cx = (short)
cx;
8984 cmd->
cy = (short)
cy;
8985 cmd->
r = (
unsigned short)radius;
8992 float a_min,
float a_max,
struct nk_color c)
8996 if (!b || c.
a == 0)
return;
9000 cmd->
cx = (short)
cx;
9001 cmd->
cy = (short)
cy;
9002 cmd->
r = (
unsigned short)radius;
9009 float y1,
float x2,
float y2,
float line_thickness,
struct nk_color c)
9014 if (
b->use_clipping) {
9016 if (!
NK_INBOX(x0, y0, clip->
x, clip->
y, clip->
w, clip->
h) &&
9017 !
NK_INBOX(x1, y1, clip->
x, clip->
y, clip->
w, clip->
h) &&
9026 cmd->
a.
x = (short)x0;
9027 cmd->
a.
y = (short)y0;
9028 cmd->
b.
x = (short)x1;
9029 cmd->
b.
y = (short)y1;
9030 cmd->
c.
x = (short)x2;
9031 cmd->
c.
y = (short)y2;
9036 float y1,
float x2,
float y2,
struct nk_color c)
9040 if (!
b ||
c.a == 0)
return;
9042 if (
b->use_clipping) {
9044 if (!
NK_INBOX(x0, y0, clip->
x, clip->
y, clip->
w, clip->
h) &&
9045 !
NK_INBOX(x1, y1, clip->
x, clip->
y, clip->
w, clip->
h) &&
9053 cmd->
a.
x = (short)x0;
9054 cmd->
a.
y = (short)y0;
9055 cmd->
b.
x = (short)x1;
9056 cmd->
b.
y = (short)y1;
9057 cmd->
c.
x = (short)x2;
9058 cmd->
c.
y = (short)y2;
9063 float line_thickness,
struct nk_color col)
9091 if (!b || col.
a == 0)
return;
9105 float line_thickness,
struct nk_color col)
9140 cmd->
x = (short)r.
x;
9141 cmd->
y = (
short)r.
y;
9142 cmd->
w = (
unsigned short)
NK_MAX(0, r.
w);
9143 cmd->
h = (
unsigned short)
NK_MAX(0, r.
h);
9163 cmd->
x = (short)r.
x;
9164 cmd->
y = (
short)r.
y;
9165 cmd->
w = (
unsigned short)
NK_MAX(0, r.
w);
9166 cmd->
h = (
unsigned short)
NK_MAX(0, r.
h);
9172 const char *
string,
int length,
const struct nk_user_font *font,
9175 float text_width = 0;
9180 if (!b || !
string || !
length || (bg.
a == 0 && fg.
a == 0))
return;
9189 if (text_width > r.
w){
9191 float txt_width = (float)text_width;
9192 length = nk_text_clamp(font,
string, length, r.
w, &glyphs, &txt_width, 0,0);
9195 if (!length)
return;
9199 cmd->
x = (short)r.
x;
9200 cmd->
y = (
short)r.
y;
9201 cmd->
w = (
unsigned short)r.
w;
9202 cmd->
h = (
unsigned short)r.
h;
9221 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
9223 nk_draw_list_init(
struct nk_draw_list *list)
9228 nk_zero(list,
sizeof(*list));
9229 for (i = 0; i <
NK_LEN(list->circle_vtx); ++i) {
9230 const float a = ((float)i / (
float)
NK_LEN(list->circle_vtx)) * 2 *
NK_PI;
9231 list->circle_vtx[i].x = (float)NK_COS(a);
9232 list->circle_vtx[i].y = (float)NK_SIN(a);
9236 nk_draw_list_setup(
struct nk_draw_list *canvas,
const struct nk_convert_config *config,
9243 NK_ASSERT(vertices);
9244 NK_ASSERT(elements);
9245 if (!canvas || !config || !cmds || !vertices || !elements)
9248 canvas->buffer = cmds;
9249 canvas->config = *config;
9250 canvas->elements = elements;
9251 canvas->vertices = vertices;
9252 canvas->line_AA = line_aa;
9253 canvas->shape_AA = shape_aa;
9254 canvas->clip_rect = nk_null_rect;
9256 canvas->cmd_offset = 0;
9257 canvas->element_count = 0;
9258 canvas->vertex_count = 0;
9259 canvas->cmd_offset = 0;
9260 canvas->cmd_count = 0;
9261 canvas->path_count = 0;
9263 NK_API const struct nk_draw_command*
9264 nk__draw_list_begin(
const struct nk_draw_list *canvas,
const struct nk_buffer *buffer)
9268 const struct nk_draw_command *cmd;
9271 if (!buffer || !buffer->
size || !canvas->cmd_count)
9275 offset = buffer->
memory.
size - canvas->cmd_offset;
9276 cmd =
nk_ptr_add(
const struct nk_draw_command, memory, offset);
9279 NK_API const struct nk_draw_command*
9280 nk__draw_list_end(
const struct nk_draw_list *canvas,
const struct nk_buffer *buffer)
9285 const struct nk_draw_command *end;
9289 if (!buffer || !canvas)
9294 offset =
size - canvas->cmd_offset;
9295 end =
nk_ptr_add(
const struct nk_draw_command, memory, offset);
9296 end -= (canvas->cmd_count-1);
9299 NK_API const struct nk_draw_command*
9300 nk__draw_list_next(
const struct nk_draw_command *cmd,
9301 const struct nk_buffer *buffer,
const struct nk_draw_list *canvas)
9303 const struct nk_draw_command *end;
9306 if (!cmd || !buffer || !canvas)
9309 end = nk__draw_list_end(canvas, buffer);
9310 if (cmd <= end)
return 0;
9314 nk_draw_list_alloc_path(
struct nk_draw_list *list,
int count)
9321 point_size * (
nk_size)count, point_align);
9323 if (!points)
return 0;
9324 if (!list->path_offset) {
9326 list->path_offset = (
unsigned int)((
nk_byte*)points - (
nk_byte*)memory);
9328 list->path_count += (
unsigned int)count;
9332 nk_draw_list_path_last(struct nk_draw_list *list)
9336 NK_ASSERT(list->path_count);
9339 point += (list->path_count-1);
9343 nk_draw_list_push_command(
struct nk_draw_list *list,
struct nk_rect clip,
9348 struct nk_draw_command *cmd;
9351 cmd = (
struct nk_draw_command*)
9352 nk_buffer_alloc(list->buffer,
NK_BUFFER_BACK, cmd_size, cmd_align);
9355 if (!list->cmd_count) {
9362 cmd->elem_count = 0;
9363 cmd->clip_rect = clip;
9364 cmd->texture = texture;
9365 #ifdef NK_INCLUDE_COMMAND_USERDATA
9366 cmd->userdata = list->userdata;
9370 list->clip_rect = clip;
9374 nk_draw_list_command_last(
struct nk_draw_list *list)
9378 struct nk_draw_command *cmd;
9379 NK_ASSERT(list->cmd_count);
9383 cmd =
nk_ptr_add(
struct nk_draw_command, memory,
size - list->cmd_offset);
9384 return (cmd - (list->cmd_count-1));
9387 nk_draw_list_add_clip(
struct nk_draw_list *list,
struct nk_rect rect)
9391 if (!list->cmd_count) {
9392 nk_draw_list_push_command(list, rect, list->config.null.texture);
9394 struct nk_draw_command *prev = nk_draw_list_command_last(list);
9395 if (prev->elem_count == 0)
9396 prev->clip_rect = rect;
9397 nk_draw_list_push_command(list, rect, prev->texture);
9401 nk_draw_list_push_image(
struct nk_draw_list *list,
nk_handle texture)
9405 if (!list->cmd_count) {
9406 nk_draw_list_push_command(list, nk_null_rect, texture);
9408 struct nk_draw_command *prev = nk_draw_list_command_last(list);
9409 if (prev->elem_count == 0) {
9410 prev->texture = texture;
9411 #ifdef NK_INCLUDE_COMMAND_USERDATA
9412 prev->userdata = list->userdata;
9414 }
else if (prev->texture.id != texture.
id
9415 #ifdef NK_INCLUDE_COMMAND_USERDATA
9416 || prev->userdata.id != list->userdata.id
9418 ) nk_draw_list_push_command(list, prev->clip_rect, texture);
9421 #ifdef NK_INCLUDE_COMMAND_USERDATA
9423 nk_draw_list_push_userdata(
struct nk_draw_list *list,
nk_handle userdata)
9425 list->userdata = userdata;
9429 nk_draw_list_alloc_vertices(
struct nk_draw_list *list,
nk_size count)
9433 if (!list)
return 0;
9435 list->config.vertex_size*count, list->config.vertex_alignment);
9437 list->vertex_count += (
unsigned int)count;
9448 if(
sizeof(nk_draw_index)==2) NK_ASSERT((list->vertex_count < NK_USHORT_MAX &&
9449 "To many verticies for 16-bit vertex indicies. Please read comment above on how to solve this problem"));
9453 nk_draw_list_alloc_elements(
struct nk_draw_list *list,
nk_size count)
9456 struct nk_draw_command *cmd;
9460 if (!list)
return 0;
9462 ids = (nk_draw_index*)
9463 nk_buffer_alloc(list->elements,
NK_BUFFER_FRONT, elem_size*count, elem_align);
9465 cmd = nk_draw_list_command_last(list);
9466 list->element_count += (
unsigned int)count;
9467 cmd->elem_count += (
unsigned int)count;
9471 nk_draw_vertex_layout_element_is_end_of_layout(
9472 const struct nk_draw_vertex_layout_element *element)
9474 return (element->attribute == NK_VERTEX_ATTRIBUTE_COUNT ||
9475 element->format == NK_FORMAT_COUNT);
9478 nk_draw_vertex_color(
void *attr,
const float *vals,
9479 enum nk_draw_vertex_layout_format format)
9483 NK_ASSERT(format >= NK_FORMAT_COLOR_BEGIN);
9484 NK_ASSERT(format <= NK_FORMAT_COLOR_END);
9485 if (format < NK_FORMAT_COLOR_BEGIN || format > NK_FORMAT_COLOR_END)
return;
9493 default: NK_ASSERT(0 &&
"Invalid vertex layout color format");
break;
9494 case NK_FORMAT_R8G8B8A8:
9495 case NK_FORMAT_R8G8B8: {
9497 NK_MEMCPY(attr, &col.
r,
sizeof(col));
9499 case NK_FORMAT_B8G8R8A8: {
9502 NK_MEMCPY(attr, &bgra,
sizeof(bgra));
9504 case NK_FORMAT_R16G15B16: {
9506 col[0] = (
nk_ushort)(val[0]*(
float)NK_USHORT_MAX);
9507 col[1] = (
nk_ushort)(val[1]*(
float)NK_USHORT_MAX);
9508 col[2] = (
nk_ushort)(val[2]*(
float)NK_USHORT_MAX);
9509 NK_MEMCPY(attr, col,
sizeof(col));
9511 case NK_FORMAT_R16G15B16A16: {
9513 col[0] = (
nk_ushort)(val[0]*(
float)NK_USHORT_MAX);
9514 col[1] = (
nk_ushort)(val[1]*(
float)NK_USHORT_MAX);
9515 col[2] = (
nk_ushort)(val[2]*(
float)NK_USHORT_MAX);
9516 col[3] = (
nk_ushort)(val[3]*(
float)NK_USHORT_MAX);
9517 NK_MEMCPY(attr, col,
sizeof(col));
9519 case NK_FORMAT_R32G32B32: {
9521 col[0] = (
nk_uint)(val[0]*(
float)NK_UINT_MAX);
9522 col[1] = (
nk_uint)(val[1]*(
float)NK_UINT_MAX);
9523 col[2] = (
nk_uint)(val[2]*(
float)NK_UINT_MAX);
9524 NK_MEMCPY(attr, col,
sizeof(col));
9526 case NK_FORMAT_R32G32B32A32: {
9528 col[0] = (
nk_uint)(val[0]*(
float)NK_UINT_MAX);
9529 col[1] = (
nk_uint)(val[1]*(
float)NK_UINT_MAX);
9530 col[2] = (
nk_uint)(val[2]*(
float)NK_UINT_MAX);
9531 col[3] = (
nk_uint)(val[3]*(
float)NK_UINT_MAX);
9532 NK_MEMCPY(attr, col,
sizeof(col));
9534 case NK_FORMAT_R32G32B32A32_FLOAT:
9535 NK_MEMCPY(attr, val,
sizeof(
float)*4);
9537 case NK_FORMAT_R32G32B32A32_DOUBLE: {
9539 col[0] = (double)val[0];
9540 col[1] = (double)val[1];
9541 col[2] = (double)val[2];
9542 col[3] = (double)val[3];
9543 NK_MEMCPY(attr, col,
sizeof(col));
9545 case NK_FORMAT_RGB32:
9546 case NK_FORMAT_RGBA32: {
9549 NK_MEMCPY(attr, &color,
sizeof(color));
9553 nk_draw_vertex_element(
void *dst,
const float *values,
int value_count,
9554 enum nk_draw_vertex_layout_format format)
9557 void *attribute = dst;
9559 NK_ASSERT(format < NK_FORMAT_COLOR_BEGIN);
9560 if (format >= NK_FORMAT_COLOR_BEGIN && format <= NK_FORMAT_COLOR_END)
return;
9561 for (value_index = 0; value_index < value_count; ++value_index) {
9563 default: NK_ASSERT(0 &&
"invalid vertex layout format");
break;
9564 case NK_FORMAT_SCHAR: {
9565 char value = (char)
NK_CLAMP((
float)NK_SCHAR_MIN, values[value_index], (float)NK_SCHAR_MAX);
9566 NK_MEMCPY(attribute, &value,
sizeof(value));
9567 attribute = (
void*)((
char*)attribute +
sizeof(char));
9569 case NK_FORMAT_SSHORT: {
9571 NK_MEMCPY(attribute, &value,
sizeof(value));
9572 attribute = (
void*)((
char*)attribute +
sizeof(value));
9574 case NK_FORMAT_SINT: {
9576 NK_MEMCPY(attribute, &value,
sizeof(value));
9577 attribute = (
void*)((
char*)attribute +
sizeof(
nk_int));
9579 case NK_FORMAT_UCHAR: {
9580 unsigned char value = (
unsigned char)
NK_CLAMP((
float)NK_UCHAR_MIN, values[value_index], (float)NK_UCHAR_MAX);
9581 NK_MEMCPY(attribute, &value,
sizeof(value));
9582 attribute = (
void*)((
char*)attribute +
sizeof(
unsigned char));
9584 case NK_FORMAT_USHORT: {
9586 NK_MEMCPY(attribute, &value,
sizeof(value));
9587 attribute = (
void*)((
char*)attribute +
sizeof(value));
9589 case NK_FORMAT_UINT: {
9591 NK_MEMCPY(attribute, &value,
sizeof(value));
9592 attribute = (
void*)((
char*)attribute +
sizeof(
nk_uint));
9594 case NK_FORMAT_FLOAT:
9595 NK_MEMCPY(attribute, &values[value_index],
sizeof(values[value_index]));
9596 attribute = (
void*)((
char*)attribute +
sizeof(float));
9598 case NK_FORMAT_DOUBLE: {
9599 double value = (double)values[value_index];
9600 NK_MEMCPY(attribute, &value,
sizeof(value));
9601 attribute = (
void*)((
char*)attribute +
sizeof(double));
9610 void *result = (
void*)((
char*)dst + config->
vertex_size);
9611 const struct nk_draw_vertex_layout_element *elem_iter = config->
vertex_layout;
9612 while (!nk_draw_vertex_layout_element_is_end_of_layout(elem_iter)) {
9613 void *address = (
void*)((
char*)dst + elem_iter->offset);
9614 switch (elem_iter->attribute) {
9615 case NK_VERTEX_ATTRIBUTE_COUNT:
9616 default: NK_ASSERT(0 &&
"wrong element attribute");
break;
9617 case NK_VERTEX_POSITION: nk_draw_vertex_element(address, &pos.
x, 2, elem_iter->format);
break;
9618 case NK_VERTEX_TEXCOORD: nk_draw_vertex_element(address, &uv.
x, 2, elem_iter->format);
break;
9619 case NK_VERTEX_COLOR: nk_draw_vertex_color(address, &color.
r, elem_iter->format);
break;
9626 nk_draw_list_stroke_poly_line(
struct nk_draw_list *list,
const struct nk_vec2 *points,
9627 const unsigned int points_count,
struct nk_color color,
enum nk_draw_list_stroke closed,
9635 if (!list || points_count < 2)
return;
9637 color.
a = (
nk_byte)((
float)color.
a * list->config.global_alpha);
9638 count = points_count;
9639 if (!closed) count = points_count-1;
9640 thick_line = thickness > 1.0f;
9642 #ifdef NK_INCLUDE_COMMAND_USERDATA
9643 nk_draw_list_push_userdata(list, list->userdata);
9646 color.
a = (
nk_byte)((
float)color.
a * list->config.global_alpha);
9653 const float AA_SIZE = 1.0f;
9660 nk_size index = list->vertex_count;
9662 const nk_size idx_count = (thick_line) ? (count * 18) : (count * 12);
9663 const nk_size vtx_count = (thick_line) ? (points_count * 4): (points_count *3);
9665 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
9666 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
9669 struct nk_vec2 *normals, *temp;
9670 if (!vtx || !ids)
return;
9675 size = pnt_size * ((thick_line) ? 5 : 3) * points_count;
9677 if (!normals)
return;
9678 temp = normals + points_count;
9681 vtx = (
void*)((
nk_byte*)list->vertices->memory.ptr + vertex_offset);
9684 for (i1 = 0; i1 < count; ++i1) {
9685 const nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1);
9692 len = nk_inv_sqrt(len);
9696 normals[i1].
x = diff.
y;
9697 normals[i1].
y = -diff.
x;
9701 normals[points_count-1] = normals[points_count-2];
9710 temp[(points_count-1) * 2 + 0] =
nk_vec2_add(points[points_count-1], d);
9711 temp[(points_count-1) * 2 + 1] =
nk_vec2_sub(points[points_count-1], d);
9716 for (i1 = 0; i1 < count; i1++) {
9719 nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1);
9720 nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 3);
9724 dmr2 = dm.x * dm.x + dm.y* dm.y;
9725 if (dmr2 > 0.000001f) {
9726 float scale = 1.0f/dmr2;
9727 scale =
NK_MIN(100.0f, scale);
9735 ids[0] = (nk_draw_index)(idx2 + 0); ids[1] = (nk_draw_index)(idx1+0);
9736 ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2);
9737 ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+0);
9738 ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1);
9739 ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0);
9740 ids[10]= (nk_draw_index)(idx2 + 0); ids[11]= (nk_draw_index)(idx2+1);
9746 for (i = 0; i < points_count; ++i) {
9747 const struct nk_vec2 uv = list->config.null.uv;
9748 vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col);
9749 vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans);
9750 vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans);
9754 const float half_inner_thickness = (thickness - AA_SIZE) * 0.5f;
9764 d1 =
nk_vec2_muls(normals[points_count-1], half_inner_thickness + AA_SIZE);
9765 d2 =
nk_vec2_muls(normals[points_count-1], half_inner_thickness);
9767 temp[(points_count-1)*4+0] =
nk_vec2_add(points[points_count-1], d1);
9768 temp[(points_count-1)*4+1] =
nk_vec2_add(points[points_count-1], d2);
9769 temp[(points_count-1)*4+2] =
nk_vec2_sub(points[points_count-1], d2);
9770 temp[(points_count-1)*4+3] =
nk_vec2_sub(points[points_count-1], d1);
9775 for (i1 = 0; i1 < count; ++i1) {
9777 const nk_size i2 = ((i1+1) == points_count) ? 0: (i1 + 1);
9778 nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 4);
9782 float dmr2 = dm.
x * dm.
x + dm.
y* dm.
y;
9783 if (dmr2 > 0.000001f) {
9784 float scale = 1.0f/dmr2;
9785 scale =
NK_MIN(100.0f, scale);
9789 dm_out =
nk_vec2_muls(dm, ((half_inner_thickness) + AA_SIZE));
9797 ids[0] = (nk_draw_index)(idx2 + 1); ids[1] = (nk_draw_index)(idx1+1);
9798 ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2);
9799 ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+1);
9800 ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1);
9801 ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0);
9802 ids[10]= (nk_draw_index)(idx2 + 0); ids[11] = (nk_draw_index)(idx2+1);
9803 ids[12]= (nk_draw_index)(idx2 + 2); ids[13] = (nk_draw_index)(idx1+2);
9804 ids[14]= (nk_draw_index)(idx1 + 3); ids[15] = (nk_draw_index)(idx1+3);
9805 ids[16]= (nk_draw_index)(idx2 + 3); ids[17] = (nk_draw_index)(idx2+2);
9811 for (i = 0; i < points_count; ++i) {
9812 const struct nk_vec2 uv = list->config.null.uv;
9813 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans);
9814 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col);
9815 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col);
9816 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+3], uv, col_trans);
9824 nk_size idx = list->vertex_count;
9825 const nk_size idx_count = count * 6;
9826 const nk_size vtx_count = count * 4;
9827 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
9828 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
9829 if (!vtx || !ids)
return;
9831 for (i1 = 0; i1 < count; ++i1) {
9833 const struct nk_vec2 uv = list->config.null.uv;
9834 const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1;
9835 const struct nk_vec2 p1 = points[i1];
9836 const struct nk_vec2 p2 = points[i2];
9843 len = nk_inv_sqrt(len);
9848 dx = diff.
x * (thickness * 0.5f);
9849 dy = diff.
y * (thickness * 0.5f);
9851 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p1.
x + dy, p1.
y - dx), uv, col);
9852 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p2.
x + dy, p2.
y - dx), uv, col);
9853 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p2.
x - dy, p2.
y + dx), uv, col);
9854 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p1.
x - dy, p1.
y + dx), uv, col);
9856 ids[0] = (nk_draw_index)(idx+0); ids[1] = (nk_draw_index)(idx+1);
9857 ids[2] = (nk_draw_index)(idx+2); ids[3] = (nk_draw_index)(idx+0);
9858 ids[4] = (nk_draw_index)(idx+2); ids[5] = (nk_draw_index)(idx+3);
9866 nk_draw_list_fill_poly_convex(
struct nk_draw_list *list,
9867 const struct nk_vec2 *points,
const unsigned int points_count,
9876 if (!list || points_count < 3)
return;
9878 #ifdef NK_INCLUDE_COMMAND_USERDATA
9879 nk_draw_list_push_userdata(list, list->userdata);
9882 color.
a = (
nk_byte)((
float)color.
a * list->config.global_alpha);
9892 const float AA_SIZE = 1.0f;
9894 nk_size index = list->vertex_count;
9896 const nk_size idx_count = (points_count-2)*3 + points_count*6;
9897 const nk_size vtx_count = (points_count*2);
9899 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
9900 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
9904 unsigned int vtx_inner_idx = (
unsigned int)(index + 0);
9905 unsigned int vtx_outer_idx = (
unsigned int)(index + 1);
9906 if (!vtx || !ids)
return;
9911 size = pnt_size * points_count;
9913 if (!normals)
return;
9914 vtx = (
void*)((
nk_byte*)list->vertices->memory.ptr + vertex_offset);
9917 for (i = 2; i < points_count; i++) {
9918 ids[0] = (nk_draw_index)(vtx_inner_idx);
9919 ids[1] = (nk_draw_index)(vtx_inner_idx + ((i-1) << 1));
9920 ids[2] = (nk_draw_index)(vtx_inner_idx + (i << 1));
9925 for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
9926 struct nk_vec2 p0 = points[i0];
9927 struct nk_vec2 p1 = points[i1];
9933 len = nk_inv_sqrt(len);
9937 normals[i0].
x = diff.
y;
9938 normals[i0].
y = -diff.
x;
9942 for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
9943 const struct nk_vec2 uv = list->config.null.uv;
9944 struct nk_vec2 n0 = normals[i0];
9945 struct nk_vec2 n1 = normals[i1];
9947 float dmr2 = dm.
x*dm.
x + dm.
y*dm.
y;
9948 if (dmr2 > 0.000001f) {
9949 float scale = 1.0f / dmr2;
9950 scale =
NK_MIN(scale, 100.0f);
9956 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2_sub(points[i1], dm), uv, col);
9957 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2_add(points[i1], dm), uv, col_trans);
9960 ids[0] = (nk_draw_index)(vtx_inner_idx+(i1<<1));
9961 ids[1] = (nk_draw_index)(vtx_inner_idx+(i0<<1));
9962 ids[2] = (nk_draw_index)(vtx_outer_idx+(i0<<1));
9963 ids[3] = (nk_draw_index)(vtx_outer_idx+(i0<<1));
9964 ids[4] = (nk_draw_index)(vtx_outer_idx+(i1<<1));
9965 ids[5] = (nk_draw_index)(vtx_inner_idx+(i1<<1));
9972 nk_size index = list->vertex_count;
9973 const nk_size idx_count = (points_count-2)*3;
9974 const nk_size vtx_count = points_count;
9975 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
9976 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
9978 if (!vtx || !ids)
return;
9979 for (i = 0; i < vtx_count; ++i)
9980 vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.null.uv, col);
9981 for (i = 2; i < points_count; ++i) {
9982 ids[0] = (nk_draw_index)index;
9983 ids[1] = (nk_draw_index)(index+ i - 1);
9984 ids[2] = (nk_draw_index)(index+i);
9990 nk_draw_list_path_clear(
struct nk_draw_list *list)
9995 list->path_count = 0;
9996 list->path_offset = 0;
9999 nk_draw_list_path_line_to(
struct nk_draw_list *list,
struct nk_vec2 pos)
10002 struct nk_draw_command *cmd = 0;
10005 if (!list->cmd_count)
10006 nk_draw_list_add_clip(list, nk_null_rect);
10008 cmd = nk_draw_list_command_last(list);
10009 if (cmd && cmd->texture.ptr != list->config.null.texture.ptr)
10010 nk_draw_list_push_image(list, list->config.null.texture);
10012 points = nk_draw_list_alloc_path(list, 1);
10013 if (!points)
return;
10017 nk_draw_list_path_arc_to_fast(
struct nk_draw_list *list,
struct nk_vec2 center,
10018 float radius,
int a_min,
int a_max)
10023 if (a_min <= a_max) {
10024 for (a = a_min; a <= a_max; a++) {
10026 const float x = center.
x + c.
x * radius;
10027 const float y = center.
y + c.
y * radius;
10028 nk_draw_list_path_line_to(list,
nk_vec2(
x,
y));
10033 nk_draw_list_path_arc_to(
struct nk_draw_list *list,
struct nk_vec2 center,
10034 float radius,
float a_min,
float a_max,
unsigned int segments)
10036 unsigned int i = 0;
10039 if (radius == 0.0f)
return;
10059 {
const float d_angle = (a_max - a_min) / (
float)segments;
10060 const float sin_d = (float)NK_SIN(d_angle);
10061 const float cos_d = (float)NK_COS(d_angle);
10063 float cx = (float)NK_COS(a_min) * radius;
10064 float cy = (float)NK_SIN(a_min) * radius;
10065 for(i = 0; i <= segments; ++i) {
10066 float new_cx, new_cy;
10067 const float x = center.
x + cx;
10068 const float y = center.
y + cy;
10069 nk_draw_list_path_line_to(list,
nk_vec2(
x,
y));
10071 new_cx = cx * cos_d - cy * sin_d;
10072 new_cy = cy * cos_d + cx * sin_d;
10078 nk_draw_list_path_rect_to(
struct nk_draw_list *list,
struct nk_vec2 a,
10079 struct nk_vec2 b,
float rounding)
10085 r =
NK_MIN(r, ((b.
x-a.
x) < 0) ? -(b.
x-a.
x): (b.
x-a.
x));
10086 r =
NK_MIN(r, ((b.
y-a.
y) < 0) ? -(b.
y-a.
y): (b.
y-a.
y));
10089 nk_draw_list_path_line_to(list, a);
10090 nk_draw_list_path_line_to(list,
nk_vec2(b.
x,a.
y));
10091 nk_draw_list_path_line_to(list, b);
10092 nk_draw_list_path_line_to(list,
nk_vec2(a.
x,b.
y));
10094 nk_draw_list_path_arc_to_fast(list,
nk_vec2(a.
x + r, a.
y + r), r, 6, 9);
10095 nk_draw_list_path_arc_to_fast(list,
nk_vec2(b.
x - r, a.
y + r), r, 9, 12);
10096 nk_draw_list_path_arc_to_fast(list,
nk_vec2(b.
x - r, b.
y - r), r, 0, 3);
10097 nk_draw_list_path_arc_to_fast(list,
nk_vec2(a.
x + r, b.
y - r), r, 3, 6);
10101 nk_draw_list_path_curve_to(
struct nk_draw_list *list,
struct nk_vec2 p2,
10102 struct nk_vec2 p3,
struct nk_vec2 p4,
unsigned int num_segments)
10105 unsigned int i_step;
10109 NK_ASSERT(list->path_count);
10110 if (!list || !list->path_count)
return;
10111 num_segments =
NK_MAX(num_segments, 1);
10113 p1 = nk_draw_list_path_last(list);
10114 t_step = 1.0f/(float)num_segments;
10115 for (i_step = 1; i_step <= num_segments; ++i_step) {
10116 float t = t_step * (float)i_step;
10117 float u = 1.0f - t;
10119 float w2 = 3*u*u*t;
10120 float w3 = 3*u*t*t;
10121 float w4 = t * t *t;
10122 float x = w1 * p1.
x + w2 * p2.
x + w3 * p3.
x + w4 * p4.
x;
10123 float y = w1 * p1.
y + w2 * p2.
y + w3 * p3.
y + w4 * p4.
y;
10124 nk_draw_list_path_line_to(list,
nk_vec2(
x,
y));
10128 nk_draw_list_path_fill(
struct nk_draw_list *list,
struct nk_color color)
10134 nk_draw_list_fill_poly_convex(list, points, list->path_count, color, list->config.shape_AA);
10135 nk_draw_list_path_clear(list);
10138 nk_draw_list_path_stroke(
struct nk_draw_list *list,
struct nk_color color,
10139 enum nk_draw_list_stroke closed,
float thickness)
10145 nk_draw_list_stroke_poly_line(list, points, list->path_count, color,
10146 closed, thickness, list->config.line_AA);
10147 nk_draw_list_path_clear(list);
10150 nk_draw_list_stroke_line(
struct nk_draw_list *list,
struct nk_vec2 a,
10154 if (!list || !col.
a)
return;
10156 nk_draw_list_path_line_to(list, a);
10157 nk_draw_list_path_line_to(list, b);
10162 nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness);
10165 nk_draw_list_fill_rect(
struct nk_draw_list *list,
struct nk_rect rect,
10166 struct nk_color col,
float rounding)
10169 if (!list || !col.
a)
return;
10172 nk_draw_list_path_rect_to(list,
nk_vec2(rect.
x, rect.
y),
10173 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), rounding);
10175 nk_draw_list_path_rect_to(list,
nk_vec2(rect.
x-0.5f, rect.
y-0.5f),
10176 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), rounding);
10177 } nk_draw_list_path_fill(list, col);
10180 nk_draw_list_stroke_rect(
struct nk_draw_list *list,
struct nk_rect rect,
10181 struct nk_color col,
float rounding,
float thickness)
10184 if (!list || !col.
a)
return;
10186 nk_draw_list_path_rect_to(list,
nk_vec2(rect.
x, rect.
y),
10187 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), rounding);
10189 nk_draw_list_path_rect_to(list,
nk_vec2(rect.
x-0.5f, rect.
y-0.5f),
10190 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), rounding);
10191 } nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
10194 nk_draw_list_fill_rect_multi_color(
struct nk_draw_list *list,
struct nk_rect rect,
10200 struct nk_colorf col_right, col_bottom;
10201 nk_draw_index *idx;
10202 nk_draw_index index;
10212 nk_draw_list_push_image(list, list->config.null.texture);
10213 index = (nk_draw_index)list->vertex_count;
10214 vtx = nk_draw_list_alloc_vertices(list, 4);
10215 idx = nk_draw_list_alloc_elements(list, 6);
10216 if (!vtx || !idx)
return;
10218 idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1);
10219 idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
10220 idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
10222 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.
x, rect.
y), list->config.null.uv, col_left);
10223 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.
x + rect.
w, rect.
y), list->config.null.uv, col_top);
10224 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), list->config.null.uv, col_right);
10225 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.
x, rect.
y + rect.
h), list->config.null.uv, col_bottom);
10228 nk_draw_list_fill_triangle(
struct nk_draw_list *list,
struct nk_vec2 a,
10232 if (!list || !col.
a)
return;
10233 nk_draw_list_path_line_to(list,
a);
10234 nk_draw_list_path_line_to(list,
b);
10235 nk_draw_list_path_line_to(list, c);
10236 nk_draw_list_path_fill(list, col);
10239 nk_draw_list_stroke_triangle(
struct nk_draw_list *list,
struct nk_vec2 a,
10243 if (!list || !col.
a)
return;
10244 nk_draw_list_path_line_to(list,
a);
10245 nk_draw_list_path_line_to(list,
b);
10246 nk_draw_list_path_line_to(list, c);
10247 nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
10250 nk_draw_list_fill_circle(
struct nk_draw_list *list,
struct nk_vec2 center,
10251 float radius,
struct nk_color col,
unsigned int segs)
10255 if (!list || !col.
a)
return;
10256 a_max =
NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs;
10257 nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs);
10258 nk_draw_list_path_fill(list, col);
10261 nk_draw_list_stroke_circle(
struct nk_draw_list *list,
struct nk_vec2 center,
10262 float radius,
struct nk_color col,
unsigned int segs,
float thickness)
10266 if (!list || !col.
a)
return;
10267 a_max =
NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs;
10268 nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs);
10269 nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
10272 nk_draw_list_stroke_curve(
struct nk_draw_list *list,
struct nk_vec2 p0,
10274 struct nk_color col,
unsigned int segments,
float thickness)
10277 if (!list || !col.
a)
return;
10278 nk_draw_list_path_line_to(list, p0);
10279 nk_draw_list_path_curve_to(list, cp0, cp1, p1, segments);
10280 nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness);
10283 nk_draw_list_push_rect_uv(
struct nk_draw_list *list,
struct nk_vec2 a,
10294 nk_draw_index *idx;
10295 nk_draw_index index;
10305 index = (nk_draw_index)list->vertex_count;
10306 vtx = nk_draw_list_alloc_vertices(list, 4);
10307 idx = nk_draw_list_alloc_elements(list, 6);
10308 if (!vtx || !idx)
return;
10310 idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1);
10311 idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
10312 idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
10314 vtx = nk_draw_vertex(vtx, &list->config,
a, uva, col);
10315 vtx = nk_draw_vertex(vtx, &list->config,
b, uvb, col);
10316 vtx = nk_draw_vertex(vtx, &list->config, c, uvc, col);
10317 vtx = nk_draw_vertex(vtx, &list->config, d, uvd, col);
10320 nk_draw_list_add_image(
struct nk_draw_list *list,
struct nk_image texture,
10326 nk_draw_list_push_image(list, texture.
handle);
10330 uv[0].
x = (float)texture.
region[0]/(
float)texture.
w;
10331 uv[0].
y = (float)texture.
region[1]/(
float)texture.
h;
10332 uv[1].
x = (float)(texture.
region[0] + texture.
region[2])/(float)texture.
w;
10333 uv[1].y = (
float)(texture.
region[1] + texture.
region[3])/(
float)texture.
h;
10334 nk_draw_list_push_rect_uv(list,
nk_vec2(rect.
x, rect.
y),
10335 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), uv[0], uv[1], color);
10336 }
else nk_draw_list_push_rect_uv(list,
nk_vec2(rect.
x, rect.
y),
10341 nk_draw_list_add_text(
struct nk_draw_list *list,
const struct nk_user_font *font,
10342 struct nk_rect rect,
const char *text,
int len,
float font_height,
10350 int next_glyph_len = 0;
10351 struct nk_user_font_glyph g;
10354 if (!list || !len || !text)
return;
10356 list->clip_rect.x, list->clip_rect.y, list->clip_rect.w, list->clip_rect.h))
return;
10358 nk_draw_list_push_image(list, font->texture);
10361 if (!glyph_len)
return;
10364 fg.
a = (
nk_byte)((
float)fg.
a * list->config.global_alpha);
10365 while (text_len < len && glyph_len) {
10366 float gx, gy, gh, gw;
10367 float char_width = 0;
10371 next_glyph_len =
nk_utf_decode(text + text_len + glyph_len, &next, (
int)len - text_len);
10372 font->query(font->
userdata, font_height, &g, unicode,
10376 gx = x + g.offset.x;
10377 gy = rect.
y + g.offset.y;
10378 gw = g.width; gh = g.height;
10379 char_width = g.xadvance;
10380 nk_draw_list_push_rect_uv(list,
nk_vec2(gx,gy),
nk_vec2(gx + gw, gy+ gh),
10381 g.uv[0], g.uv[1], fg);
10384 text_len += glyph_len;
10386 glyph_len = next_glyph_len;
10399 NK_ASSERT(vertices);
10400 NK_ASSERT(elements);
10404 if (!ctx || !cmds || !vertices || !elements || !config || !config->
vertex_layout)
10407 nk_draw_list_setup(&ctx->draw_list, config, cmds, vertices, elements,
10411 #ifdef NK_INCLUDE_COMMAND_USERDATA
10412 ctx->draw_list.userdata = cmd->userdata;
10414 switch (cmd->
type) {
10418 nk_draw_list_add_clip(&ctx->draw_list,
nk_rect(s->
x, s->
y, s->
w, s->
h));
10434 nk_draw_list_stroke_rect(&ctx->draw_list,
nk_rect(r->
x, r->
y, r->
w, r->
h),
10439 nk_draw_list_fill_rect(&ctx->draw_list,
nk_rect(r->
x, r->
y, r->
w, r->
h),
10444 nk_draw_list_fill_rect_multi_color(&ctx->draw_list,
nk_rect(r->
x, r->
y, r->
w, r->
h),
10449 nk_draw_list_stroke_circle(&ctx->draw_list,
nk_vec2((
float)c->
x + (
float)c->
w/2,
10450 (
float)c->
y + (
float)c->
h/2), (
float)c->
w/2, c->
color,
10455 nk_draw_list_fill_circle(&ctx->draw_list,
nk_vec2((
float)c->
x + (
float)c->
w/2,
10456 (
float)c->
y + (
float)c->
h/2), (
float)c->
w/2, c->
color,
10461 nk_draw_list_path_line_to(&ctx->draw_list,
nk_vec2(c->
cx, c->
cy));
10462 nk_draw_list_path_arc_to(&ctx->draw_list,
nk_vec2(c->
cx, c->
cy), c->
r,
10464 nk_draw_list_path_stroke(&ctx->draw_list, c->
color, NK_STROKE_CLOSED, c->
line_thickness);
10468 nk_draw_list_path_line_to(&ctx->draw_list,
nk_vec2(c->
cx, c->
cy));
10469 nk_draw_list_path_arc_to(&ctx->draw_list,
nk_vec2(c->
cx, c->
cy), c->
r,
10471 nk_draw_list_path_fill(&ctx->draw_list, c->
color);
10475 nk_draw_list_stroke_triangle(&ctx->draw_list,
nk_vec2(t->
a.
x, t->
a.
y),
10481 nk_draw_list_fill_triangle(&ctx->draw_list,
nk_vec2(t->
a.
x, t->
a.
y),
10489 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
10491 nk_draw_list_path_stroke(&ctx->draw_list, p->
color, NK_STROKE_CLOSED, p->
line_thickness);
10498 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
10500 nk_draw_list_path_fill(&ctx->draw_list, p->
color);
10507 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
10513 nk_draw_list_add_text(&ctx->draw_list, t->
font,
nk_rect(t->
x, t->
y, t->
w, t->
h),
10518 nk_draw_list_add_image(&ctx->draw_list, i->
img,
nk_rect(i->
x, i->
y, i->
w, i->
h), i->
col);
10532 NK_API const struct nk_draw_command*
10533 nk__draw_begin(
const struct nk_context *ctx,
10536 return nk__draw_list_begin(&ctx->draw_list, buffer);
10538 NK_API const struct nk_draw_command*
10541 return nk__draw_list_end(&ctx->draw_list, buffer);
10543 NK_API const struct nk_draw_command*
10544 nk__draw_next(
const struct nk_draw_command *cmd,
10547 return nk__draw_list_next(cmd, buffer, &ctx->draw_list);
10555 #ifdef NK_INCLUDE_FONT_BAKING
10563 #define NK_RP__MAXVAL 0xffff
10564 typedef unsigned short nk_rp_coord;
10566 struct nk_rp_rect {
10577 struct nk_rp_node {
10579 struct nk_rp_node *next;
10582 struct nk_rp_context {
10589 struct nk_rp_node *active_head;
10590 struct nk_rp_node *free_head;
10591 struct nk_rp_node extra[2];
10595 struct nk_rp__findresult {
10597 struct nk_rp_node **prev_link;
10600 enum NK_RP_HEURISTIC {
10601 NK_RP_HEURISTIC_Skyline_default=0,
10602 NK_RP_HEURISTIC_Skyline_BL_sortHeight = NK_RP_HEURISTIC_Skyline_default,
10603 NK_RP_HEURISTIC_Skyline_BF_sortHeight
10605 enum NK_RP_INIT_STATE{NK_RP__INIT_skyline = 1};
10608 nk_rp_setup_allow_out_of_mem(
struct nk_rp_context *context,
int allow_out_of_mem)
10610 if (allow_out_of_mem)
10615 context->align = 1;
10623 context->align = (context->width + context->num_nodes-1) / context->num_nodes;
10627 nk_rp_init_target(
struct nk_rp_context *context,
int width,
int height,
10628 struct nk_rp_node *nodes,
int num_nodes)
10631 #ifndef STBRP_LARGE_RECTS
10632 NK_ASSERT(width <= 0xffff && height <= 0xffff);
10635 for (i=0; i < num_nodes-1; ++i)
10636 nodes[i].next = &nodes[i+1];
10638 context->init_mode = NK_RP__INIT_skyline;
10639 context->heuristic = NK_RP_HEURISTIC_Skyline_default;
10640 context->free_head = &nodes[0];
10641 context->active_head = &context->extra[0];
10642 context->width = width;
10643 context->height = height;
10644 context->num_nodes = num_nodes;
10645 nk_rp_setup_allow_out_of_mem(context, 0);
10648 context->extra[0].x = 0;
10649 context->extra[0].y = 0;
10650 context->extra[0].next = &context->extra[1];
10651 context->extra[1].x = (nk_rp_coord) width;
10652 context->extra[1].y = 65535;
10653 context->extra[1].next = 0;
10657 nk_rp__skyline_find_min_y(
struct nk_rp_context *c,
struct nk_rp_node *first,
10658 int x0,
int width,
int *pwaste)
10660 struct nk_rp_node *node = first;
10661 int x1 = x0 + width;
10662 int min_y, visited_width, waste_area;
10663 NK_ASSERT(first->x <= x0);
10666 NK_ASSERT(node->next->x > x0);
10668 NK_ASSERT(node->x <= x0);
10673 while (node->x < x1)
10675 if (node->y > min_y) {
10679 waste_area += visited_width * (node->y - min_y);
10683 visited_width += node->next->x - x0;
10685 visited_width += node->next->x - node->x;
10688 int under_width = node->next->x - node->x;
10689 if (under_width + visited_width > width)
10690 under_width = width - visited_width;
10691 waste_area += under_width * (min_y - node->y);
10692 visited_width += under_width;
10696 *pwaste = waste_area;
10700 nk_rp__skyline_find_best_pos(struct nk_rp_context *c,
int width,
int height)
10702 int best_waste = (1<<30), best_x, best_y = (1 << 30);
10703 struct nk_rp__findresult fr;
10704 struct nk_rp_node **prev, *node, *tail, **best = 0;
10707 width = (width + c->align - 1);
10708 width -= width % c->align;
10709 NK_ASSERT(width % c->align == 0);
10711 node = c->active_head;
10712 prev = &c->active_head;
10713 while (node->x + width <= c->width) {
10715 y = nk_rp__skyline_find_min_y(c, node, node->x, width, &waste);
10717 if (c->heuristic == NK_RP_HEURISTIC_Skyline_BL_sortHeight) {
10725 if (y + height <= c->height) {
10727 if (y < best_y || (y == best_y && waste < best_waste)) {
10729 best_waste = waste;
10734 prev = &node->next;
10737 best_x = (best == 0) ? 0 : (*best)->x;
10755 if (c->heuristic == NK_RP_HEURISTIC_Skyline_BF_sortHeight)
10757 tail = c->active_head;
10758 node = c->active_head;
10759 prev = &c->active_head;
10761 while (tail->x < width)
10765 int xpos = tail->x - width;
10767 NK_ASSERT(xpos >= 0);
10769 while (node->next->x <= xpos) {
10770 prev = &node->next;
10773 NK_ASSERT(node->next->x > xpos && node->x <= xpos);
10774 y = nk_rp__skyline_find_min_y(c, node, xpos, width, &waste);
10775 if (y + height < c->height) {
10777 if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
10779 NK_ASSERT(y <= best_y);
10781 best_waste = waste;
10789 fr.prev_link = best;
10795 nk_rp__skyline_pack_rectangle(struct nk_rp_context *context,
int width,
int height)
10798 struct nk_rp__findresult res = nk_rp__skyline_find_best_pos(context, width, height);
10799 struct nk_rp_node *node, *cur;
10805 if (res.prev_link == 0 || res.y + height > context->height || context->free_head == 0) {
10811 node = context->free_head;
10812 node->x = (nk_rp_coord) res.x;
10813 node->y = (nk_rp_coord) (res.y + height);
10815 context->free_head = node->next;
10820 cur = *res.prev_link;
10821 if (cur->x < res.x) {
10823 struct nk_rp_node *next = cur->next;
10827 *res.prev_link = node;
10832 while (cur->next && cur->next->x <= res.x + width) {
10833 struct nk_rp_node *next = cur->next;
10835 cur->next = context->free_head;
10836 context->free_head = cur;
10842 if (cur->x < res.x + width)
10843 cur->x = (nk_rp_coord) (res.x + width);
10847 nk_rect_height_compare(
const void *a,
const void *b)
10849 const struct nk_rp_rect *p = (
const struct nk_rp_rect *) a;
10850 const struct nk_rp_rect *q = (
const struct nk_rp_rect *) b;
10855 return (p->w > q->w) ? -1 : (p->w < q->w);
10858 nk_rect_original_order(
const void *a,
const void *b)
10860 const struct nk_rp_rect *p = (
const struct nk_rp_rect *) a;
10861 const struct nk_rp_rect *q = (
const struct nk_rp_rect *) b;
10862 return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
10865 nk_rp_qsort(
struct nk_rp_rect *array,
unsigned int len,
int(*cmp)(
const void*,
const void*))
10868 #define NK_MAX_SORT_STACK 64
10869 unsigned right, left = 0, stack[NK_MAX_SORT_STACK], pos = 0;
10870 unsigned seed = len/2 * 69069+1;
10872 for (; left+1 < len; len++) {
10873 struct nk_rp_rect pivot, tmp;
10874 if (pos == NK_MAX_SORT_STACK) len = stack[pos = 0];
10875 pivot = array[left+seed%(len-left)];
10876 seed = seed * 69069 + 1;
10877 stack[pos++] = len;
10878 for (right = left-1;;) {
10879 while (cmp(&array[++right], &pivot) < 0);
10880 while (cmp(&pivot, &array[--len]) < 0);
10881 if (right >= len)
break;
10882 tmp = array[right];
10883 array[right] = array[len];
10887 if (pos == 0)
break;
10889 len = stack[--pos];
10891 #undef NK_MAX_SORT_STACK
10894 nk_rp_pack_rects(
struct nk_rp_context *context,
struct nk_rp_rect *rects,
int num_rects)
10898 for (i=0; i < num_rects; ++i) {
10899 rects[i].was_packed = i;
10903 nk_rp_qsort(rects, (
unsigned)num_rects, nk_rect_height_compare);
10905 for (i=0; i < num_rects; ++i) {
10906 struct nk_rp__findresult fr = nk_rp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
10907 if (fr.prev_link) {
10908 rects[i].x = (nk_rp_coord) fr.x;
10909 rects[i].y = (nk_rp_coord) fr.y;
10911 rects[i].x = rects[i].y = NK_RP__MAXVAL;
10916 nk_rp_qsort(rects, (
unsigned)num_rects, nk_rect_original_order);
10919 for (i=0; i < num_rects; ++i)
10920 rects[i].was_packed = !(rects[i].x == NK_RP__MAXVAL && rects[i].y == NK_RP__MAXVAL);
10931 #define NK_TT_MAX_OVERSAMPLE 8
10932 #define NK_TT__OVER_MASK (NK_TT_MAX_OVERSAMPLE-1)
10934 struct nk_tt_bakedchar {
10935 unsigned short x0,y0,x1,y1;
10937 float xoff,yoff,xadvance;
10940 struct nk_tt_aligned_quad{
10945 struct nk_tt_packedchar {
10946 unsigned short x0,y0,x1,y1;
10948 float xoff,yoff,xadvance;
10952 struct nk_tt_pack_range {
10954 int first_unicode_codepoint_in_range;
10956 int *array_of_unicode_codepoints;
10959 struct nk_tt_packedchar *chardata_for_range;
10960 unsigned char h_oversample, v_oversample;
10964 struct nk_tt_pack_context {
10968 int stride_in_bytes;
10970 unsigned int h_oversample, v_oversample;
10971 unsigned char *pixels;
10975 struct nk_tt_fontinfo {
10976 const unsigned char* data;
10979 int loca,head,glyf,hhea,hmtx,kern;
10981 int indexToLocFormat;
10990 struct nk_tt_vertex {
10992 unsigned char type,padding;
10995 struct nk_tt__bitmap{
10997 unsigned char *pixels;
11000 struct nk_tt__hheap_chunk {
11001 struct nk_tt__hheap_chunk *next;
11003 struct nk_tt__hheap {
11005 struct nk_tt__hheap_chunk *head;
11007 int num_remaining_in_head_chunk;
11010 struct nk_tt__edge {
11011 float x0,y0, x1,y1;
11015 struct nk_tt__active_edge {
11016 struct nk_tt__active_edge *next;
11022 struct nk_tt__point {
float x,y;};
11024 #define NK_TT_MACSTYLE_DONTCARE 0
11025 #define NK_TT_MACSTYLE_BOLD 1
11026 #define NK_TT_MACSTYLE_ITALIC 2
11027 #define NK_TT_MACSTYLE_UNDERSCORE 4
11028 #define NK_TT_MACSTYLE_NONE 8
11032 NK_TT_PLATFORM_ID_UNICODE =0,
11033 NK_TT_PLATFORM_ID_MAC =1,
11034 NK_TT_PLATFORM_ID_ISO =2,
11035 NK_TT_PLATFORM_ID_MICROSOFT =3
11039 NK_TT_UNICODE_EID_UNICODE_1_0 =0,
11040 NK_TT_UNICODE_EID_UNICODE_1_1 =1,
11041 NK_TT_UNICODE_EID_ISO_10646 =2,
11042 NK_TT_UNICODE_EID_UNICODE_2_0_BMP=3,
11043 NK_TT_UNICODE_EID_UNICODE_2_0_FULL=4
11047 NK_TT_MS_EID_SYMBOL =0,
11048 NK_TT_MS_EID_UNICODE_BMP =1,
11049 NK_TT_MS_EID_SHIFTJIS =2,
11050 NK_TT_MS_EID_UNICODE_FULL =10
11054 NK_TT_MAC_EID_ROMAN =0, NK_TT_MAC_EID_ARABIC =4,
11055 NK_TT_MAC_EID_JAPANESE =1, NK_TT_MAC_EID_HEBREW =5,
11056 NK_TT_MAC_EID_CHINESE_TRAD =2, NK_TT_MAC_EID_GREEK =6,
11057 NK_TT_MAC_EID_KOREAN =3, NK_TT_MAC_EID_RUSSIAN =7
11062 NK_TT_MS_LANG_ENGLISH =0x0409, NK_TT_MS_LANG_ITALIAN =0x0410,
11063 NK_TT_MS_LANG_CHINESE =0x0804, NK_TT_MS_LANG_JAPANESE =0x0411,
11064 NK_TT_MS_LANG_DUTCH =0x0413, NK_TT_MS_LANG_KOREAN =0x0412,
11065 NK_TT_MS_LANG_FRENCH =0x040c, NK_TT_MS_LANG_RUSSIAN =0x0419,
11066 NK_TT_MS_LANG_GERMAN =0x0407, NK_TT_MS_LANG_SPANISH =0x0409,
11067 NK_TT_MS_LANG_HEBREW =0x040d, NK_TT_MS_LANG_SWEDISH =0x041D
11071 NK_TT_MAC_LANG_ENGLISH =0 , NK_TT_MAC_LANG_JAPANESE =11,
11072 NK_TT_MAC_LANG_ARABIC =12, NK_TT_MAC_LANG_KOREAN =23,
11073 NK_TT_MAC_LANG_DUTCH =4 , NK_TT_MAC_LANG_RUSSIAN =32,
11074 NK_TT_MAC_LANG_FRENCH =1 , NK_TT_MAC_LANG_SPANISH =6 ,
11075 NK_TT_MAC_LANG_GERMAN =2 , NK_TT_MAC_LANG_SWEDISH =5 ,
11076 NK_TT_MAC_LANG_HEBREW =10, NK_TT_MAC_LANG_CHINESE_SIMPLIFIED =33,
11077 NK_TT_MAC_LANG_ITALIAN =3 , NK_TT_MAC_LANG_CHINESE_TRAD =19
11080 #define nk_ttBYTE(p) (* (const nk_byte *) (p))
11081 #define nk_ttCHAR(p) (* (const char *) (p))
11083 #if defined(NK_BIGENDIAN) && !defined(NK_ALLOW_UNALIGNED_TRUETYPE)
11084 #define nk_ttUSHORT(p) (* (nk_ushort *) (p))
11085 #define nk_ttSHORT(p) (* (nk_short *) (p))
11086 #define nk_ttULONG(p) (* (nk_uint *) (p))
11087 #define nk_ttLONG(p) (* (nk_int *) (p))
11091 static nk_uint nk_ttULONG(
const nk_byte *p) {
return (
nk_uint)((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]); }
11094 #define nk_tt_tag4(p,c0,c1,c2,c3)\
11095 ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3))
11096 #define nk_tt_tag(p,str) nk_tt_tag4(p,str[0],str[1],str[2],str[3])
11099 int glyph_index,
struct nk_tt_vertex **pvertices);
11102 nk_tt__find_table(
const nk_byte *data,
nk_uint fontstart,
const char *tag)
11105 nk_int num_tables = nk_ttUSHORT(data+fontstart+4);
11106 nk_uint tabledir = fontstart + 12;
11108 for (i = 0; i < num_tables; ++i) {
11110 if (nk_tt_tag(data+loc+0, tag))
11111 return nk_ttULONG(data+loc+8);
11116 nk_tt_InitFont(
struct nk_tt_fontinfo *info,
const unsigned char *data2,
int fontstart)
11123 info->fontstart = fontstart;
11125 cmap = nk_tt__find_table(data, (
nk_uint)fontstart,
"cmap");
11126 info->loca = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"loca");
11127 info->head = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"head");
11128 info->glyf = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"glyf");
11129 info->hhea = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"hhea");
11130 info->hmtx = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"hmtx");
11131 info->kern = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"kern");
11132 if (!cmap || !info->loca || !info->head || !info->glyf || !info->hhea || !info->hmtx)
11135 t = nk_tt__find_table(data, (
nk_uint)fontstart,
"maxp");
11136 if (t) info->numGlyphs = nk_ttUSHORT(data+t+4);
11137 else info->numGlyphs = 0xffff;
11142 numTables = nk_ttUSHORT(data + cmap + 2);
11143 info->index_map = 0;
11144 for (i=0; i < numTables; ++i)
11148 switch(nk_ttUSHORT(data+encoding_record)) {
11149 case NK_TT_PLATFORM_ID_MICROSOFT:
11150 switch (nk_ttUSHORT(data+encoding_record+2)) {
11151 case NK_TT_MS_EID_UNICODE_BMP:
11152 case NK_TT_MS_EID_UNICODE_FULL:
11154 info->index_map = (int)(cmap + nk_ttULONG(data+encoding_record+4));
11158 case NK_TT_PLATFORM_ID_UNICODE:
11161 info->index_map = (int)(cmap + nk_ttULONG(data+encoding_record+4));
11166 if (info->index_map == 0)
11168 info->indexToLocFormat = nk_ttUSHORT(data+info->head + 50);
11172 nk_tt_FindGlyphIndex(
const struct nk_tt_fontinfo *info,
int unicode_codepoint)
11174 const nk_byte *data = info->data;
11177 nk_ushort format = nk_ttUSHORT(data + index_map + 0);
11179 nk_int bytes = nk_ttUSHORT(data + index_map + 2);
11180 if (unicode_codepoint < bytes-6)
11181 return nk_ttBYTE(data + index_map + 6 + unicode_codepoint);
11183 }
else if (format == 6) {
11184 nk_uint first = nk_ttUSHORT(data + index_map + 6);
11185 nk_uint count = nk_ttUSHORT(data + index_map + 8);
11186 if ((
nk_uint) unicode_codepoint >= first && (
nk_uint) unicode_codepoint < first+count)
11187 return nk_ttUSHORT(data + index_map + 10 + (unicode_codepoint - (
int)first)*2);
11189 }
else if (format == 2) {
11192 }
else if (format == 4) {
11193 nk_ushort segcount = nk_ttUSHORT(data+index_map+6) >> 1;
11194 nk_ushort searchRange = nk_ttUSHORT(data+index_map+8) >> 1;
11195 nk_ushort entrySelector = nk_ttUSHORT(data+index_map+10);
11196 nk_ushort rangeShift = nk_ttUSHORT(data+index_map+12) >> 1;
11199 nk_uint endCount = index_map + 14;
11202 if (unicode_codepoint > 0xffff)
11207 if (unicode_codepoint >= nk_ttUSHORT(data + search + rangeShift*2))
11208 search += (
nk_uint)(rangeShift*2);
11212 while (entrySelector) {
11215 end = nk_ttUSHORT(data + search + searchRange*2);
11216 if (unicode_codepoint > end)
11217 search += (
nk_uint)(searchRange*2);
11226 NK_ASSERT(unicode_codepoint <= nk_ttUSHORT(data + endCount + 2*item));
11227 start = nk_ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);
11228 if (unicode_codepoint < start)
11231 offset = nk_ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);
11233 return (
nk_ushort) (unicode_codepoint + nk_ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item));
11235 return nk_ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);
11237 }
else if (format == 12 || format == 13) {
11238 nk_uint ngroups = nk_ttULONG(data+index_map+12);
11240 low = 0; high = (
nk_int)ngroups;
11242 while (low < high) {
11243 nk_int mid = low + ((high-low) >> 1);
11244 nk_uint start_char = nk_ttULONG(data+index_map+16+mid*12);
11245 nk_uint end_char = nk_ttULONG(data+index_map+16+mid*12+4);
11246 if ((
nk_uint) unicode_codepoint < start_char)
11248 else if ((
nk_uint) unicode_codepoint > end_char)
11251 nk_uint start_glyph = nk_ttULONG(data+index_map+16+mid*12+8);
11253 return (
int)start_glyph + (int)unicode_codepoint - (
int)start_char;
11255 return (
int)start_glyph;
11274 nk_tt__GetGlyfOffset(
const struct nk_tt_fontinfo *info,
int glyph_index)
11277 if (glyph_index >= info->numGlyphs)
return -1;
11278 if (info->indexToLocFormat >= 2)
return -1;
11280 if (info->indexToLocFormat == 0) {
11281 g1 = info->glyf + nk_ttUSHORT(info->data + info->loca + glyph_index * 2) * 2;
11282 g2 = info->glyf + nk_ttUSHORT(info->data + info->loca + glyph_index * 2 + 2) * 2;
11284 g1 = info->glyf + (int)nk_ttULONG (info->data + info->loca + glyph_index * 4);
11285 g2 = info->glyf + (int)nk_ttULONG (info->data + info->loca + glyph_index * 4 + 4);
11287 return g1==g2 ? -1 : g1;
11290 nk_tt_GetGlyphBox(
const struct nk_tt_fontinfo *info,
int glyph_index,
11291 int *x0,
int *y0,
int *x1,
int *y1)
11293 int g = nk_tt__GetGlyfOffset(info, glyph_index);
11294 if (g < 0)
return 0;
11296 if (x0) *x0 = nk_ttSHORT(info->data + g + 2);
11297 if (y0) *y0 = nk_ttSHORT(info->data + g + 4);
11298 if (x1) *x1 = nk_ttSHORT(info->data + g + 6);
11299 if (y1) *y1 = nk_ttSHORT(info->data + g + 8);
11303 nk_tt__close_shape(
struct nk_tt_vertex *vertices,
int num_vertices,
int was_off,
11308 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, (cx+scx)>>1, (cy+scy)>>1, cx,cy);
11309 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, sx,sy,scx,scy);
11312 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve,sx,sy,cx,cy);
11314 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vline,sx,sy,0,0);
11316 return num_vertices;
11319 nk_tt_GetGlyphShape(
const struct nk_tt_fontinfo *info,
struct nk_allocator *alloc,
11320 int glyph_index,
struct nk_tt_vertex **pvertices)
11323 const nk_byte *endPtsOfContours;
11324 const nk_byte *data = info->data;
11325 struct nk_tt_vertex *vertices=0;
11326 int num_vertices=0;
11327 int g = nk_tt__GetGlyfOffset(info, glyph_index);
11330 if (g < 0)
return 0;
11331 numberOfContours = nk_ttSHORT(data + g);
11332 if (numberOfContours > 0) {
11334 nk_int ins, i,j=0,m,n, next_move, was_off=0, off, start_off=0;
11335 nk_int x,y,cx,cy,sx,sy, scx,scy;
11337 endPtsOfContours = (data + g + 10);
11338 ins = nk_ttUSHORT(data + g + 10 + numberOfContours * 2);
11339 points = data + g + 10 + numberOfContours * 2 + 2 + ins;
11341 n = 1+nk_ttUSHORT(endPtsOfContours + numberOfContours*2-2);
11342 m = n + 2*numberOfContours;
11343 vertices = (
struct nk_tt_vertex *)alloc->
alloc(alloc->
userdata, 0, (
nk_size)m *
sizeof(vertices[0]));
11356 for (i=0; i < n; ++i) {
11357 if (flagcount == 0) {
11360 flagcount = *points++;
11361 }
else --flagcount;
11362 vertices[off+i].type = flags;
11367 for (i=0; i < n; ++i) {
11368 flags = vertices[off+i].type;
11371 x += (flags & 16) ? dx : -dx;
11373 if (!(flags & 16)) {
11374 x = x + (
nk_short) (points[0]*256 + points[1]);
11383 for (i=0; i < n; ++i) {
11384 flags = vertices[off+i].type;
11387 y += (flags & 32) ? dy : -dy;
11389 if (!(flags & 32)) {
11390 y = y + (
nk_short) (points[0]*256 + points[1]);
11399 sx = sy = cx = cy = scx = scy = 0;
11400 for (i=0; i < n; ++i)
11402 flags = vertices[off+i].type;
11406 if (next_move == i) {
11408 num_vertices = nk_tt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy);
11411 start_off = !(flags & 1);
11417 if (!(vertices[off+i+1].type & 1)) {
11419 sx = (x + (
nk_int) vertices[off+i+1].x) >> 1;
11420 sy = (y + (
nk_int) vertices[off+i+1].y) >> 1;
11423 sx = (
nk_int) vertices[off+i+1].x;
11424 sy = (
nk_int) vertices[off+i+1].y;
11431 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vmove,sx,sy,0,0);
11433 next_move = 1 + nk_ttUSHORT(endPtsOfContours+j*2);
11439 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, (cx+x)>>1, (cy+y)>>1, cx, cy);
11445 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, x,y, cx, cy);
11446 else nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vline, x,y,0,0);
11451 num_vertices = nk_tt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy);
11452 }
else if (numberOfContours == -1) {
11455 const nk_byte *comp = data + g + 10;
11462 int comp_num_verts = 0, i;
11463 struct nk_tt_vertex *comp_verts = 0, *tmp = 0;
11464 float mtx[6] = {1,0,0,1,0,0}, m, n;
11466 flags = (
nk_ushort)nk_ttSHORT(comp); comp+=2;
11467 gidx = (
nk_ushort)nk_ttSHORT(comp); comp+=2;
11471 mtx[4] = nk_ttSHORT(comp); comp+=2;
11472 mtx[5] = nk_ttSHORT(comp); comp+=2;
11474 mtx[4] = nk_ttCHAR(comp); comp+=1;
11475 mtx[5] = nk_ttCHAR(comp); comp+=1;
11481 if (flags & (1<<3)) {
11482 mtx[0] = mtx[3] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11483 mtx[1] = mtx[2] = 0;
11484 }
else if (flags & (1<<6)) {
11485 mtx[0] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11486 mtx[1] = mtx[2] = 0;
11487 mtx[3] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11488 }
else if (flags & (1<<7)) {
11489 mtx[0] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11490 mtx[1] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11491 mtx[2] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11492 mtx[3] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11496 m = (float) NK_SQRT(mtx[0]*mtx[0] + mtx[1]*mtx[1]);
11497 n = (float) NK_SQRT(mtx[2]*mtx[2] + mtx[3]*mtx[3]);
11500 comp_num_verts = nk_tt_GetGlyphShape(info, alloc, gidx, &comp_verts);
11501 if (comp_num_verts > 0)
11504 for (i = 0; i < comp_num_verts; ++i) {
11505 struct nk_tt_vertex* v = &comp_verts[i];
11508 v->x = (short)(m * (mtx[0]*x + mtx[2]*y + mtx[4]));
11509 v->y = (short)(n * (mtx[1]*x + mtx[3]*y + mtx[5]));
11511 v->cx = (short)(m * (mtx[0]*x + mtx[2]*y + mtx[4]));
11512 v->cy = (short)(n * (mtx[1]*x + mtx[3]*y + mtx[5]));
11515 tmp = (
struct nk_tt_vertex*)alloc->
alloc(alloc->
userdata, 0,
11516 (
nk_size)(num_vertices+comp_num_verts)*
sizeof(
struct nk_tt_vertex));
11519 if (comp_verts) alloc->
free(alloc->
userdata, comp_verts);
11522 if (num_vertices > 0) NK_MEMCPY(tmp, vertices, (
nk_size)num_vertices*
sizeof(
struct nk_tt_vertex));
11523 NK_MEMCPY(tmp+num_vertices, comp_verts, (
nk_size)comp_num_verts*
sizeof(
struct nk_tt_vertex));
11527 num_vertices += comp_num_verts;
11530 more = flags & (1<<5);
11532 }
else if (numberOfContours < 0) {
11538 *pvertices = vertices;
11539 return num_vertices;
11542 nk_tt_GetGlyphHMetrics(
const struct nk_tt_fontinfo *info,
int glyph_index,
11543 int *advanceWidth,
int *leftSideBearing)
11545 nk_ushort numOfLongHorMetrics = nk_ttUSHORT(info->data+info->hhea + 34);
11546 if (glyph_index < numOfLongHorMetrics) {
11548 *advanceWidth = nk_ttSHORT(info->data + info->hmtx + 4*glyph_index);
11549 if (leftSideBearing)
11550 *leftSideBearing = nk_ttSHORT(info->data + info->hmtx + 4*glyph_index + 2);
11553 *advanceWidth = nk_ttSHORT(info->data + info->hmtx + 4*(numOfLongHorMetrics-1));
11554 if (leftSideBearing)
11555 *leftSideBearing = nk_ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics));
11559 nk_tt_GetFontVMetrics(
const struct nk_tt_fontinfo *info,
11560 int *ascent,
int *descent,
int *lineGap)
11562 if (ascent ) *ascent = nk_ttSHORT(info->data+info->hhea + 4);
11563 if (descent) *descent = nk_ttSHORT(info->data+info->hhea + 6);
11564 if (lineGap) *lineGap = nk_ttSHORT(info->data+info->hhea + 8);
11567 nk_tt_ScaleForPixelHeight(
const struct nk_tt_fontinfo *info,
float height)
11569 int fheight = nk_ttSHORT(info->data + info->hhea + 4) - nk_ttSHORT(info->data + info->hhea + 6);
11570 return (
float) height / (float)fheight;
11573 nk_tt_ScaleForMappingEmToPixels(
const struct nk_tt_fontinfo *info,
float pixels)
11575 int unitsPerEm = nk_ttUSHORT(info->data + info->head + 18);
11576 return pixels / (float)unitsPerEm;
11583 nk_tt_GetGlyphBitmapBoxSubpixel(
const struct nk_tt_fontinfo *font,
11584 int glyph,
float scale_x,
float scale_y,
float shift_x,
float shift_y,
11585 int *ix0,
int *iy0,
int *ix1,
int *iy1)
11588 if (!nk_tt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) {
11596 if (ix0) *ix0 = nk_ifloorf((
float)x0 * scale_x + shift_x);
11597 if (iy0) *iy0 = nk_ifloorf((
float)-y1 * scale_y + shift_y);
11598 if (ix1) *ix1 = nk_iceilf ((
float)x1 * scale_x + shift_x);
11599 if (iy1) *iy1 = nk_iceilf ((
float)-y0 * scale_y + shift_y);
11603 nk_tt_GetGlyphBitmapBox(
const struct nk_tt_fontinfo *font,
int glyph,
11604 float scale_x,
float scale_y,
int *ix0,
int *iy0,
int *ix1,
int *iy1)
11606 nk_tt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1);
11613 nk_tt__hheap_alloc(
struct nk_tt__hheap *hh,
nk_size size)
11615 if (hh->first_free) {
11616 void *p = hh->first_free;
11617 hh->first_free = * (
void **) p;
11620 if (hh->num_remaining_in_head_chunk == 0) {
11621 int count = (
size < 32 ? 2000 :
size < 128 ? 800 : 100);
11622 struct nk_tt__hheap_chunk *c = (
struct nk_tt__hheap_chunk *)
11623 hh->alloc.alloc(hh->alloc.userdata, 0,
11624 sizeof(
struct nk_tt__hheap_chunk) +
size * (
nk_size)count);
11625 if (c == 0)
return 0;
11626 c->next = hh->head;
11628 hh->num_remaining_in_head_chunk = count;
11630 --hh->num_remaining_in_head_chunk;
11631 return (
char *) (hh->head) +
size * (
nk_size)hh->num_remaining_in_head_chunk;
11635 nk_tt__hheap_free(
struct nk_tt__hheap *hh,
void *p)
11637 *(
void **) p = hh->first_free;
11638 hh->first_free = p;
11641 nk_tt__hheap_cleanup(
struct nk_tt__hheap *hh)
11643 struct nk_tt__hheap_chunk *c = hh->head;
11645 struct nk_tt__hheap_chunk *n = c->next;
11646 hh->alloc.free(hh->alloc.userdata, c);
11651 nk_tt__new_active(
struct nk_tt__hheap *hh,
struct nk_tt__edge *e,
11652 int off_x,
float start_point)
11654 struct nk_tt__active_edge *z = (
struct nk_tt__active_edge *)
11655 nk_tt__hheap_alloc(hh,
sizeof(*z));
11656 float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
11660 z->fdy = (dxdy != 0) ? (1/dxdy): 0;
11661 z->fx = e->x0 + dxdy * (start_point - e->y0);
11662 z->fx -= (float)off_x;
11663 z->direction = e->invert ? 1.0f : -1.0f;
11670 nk_tt__handle_clipped_edge(
float *scanline,
int x,
struct nk_tt__active_edge *e,
11671 float x0,
float y0,
float x1,
float y1)
11673 if (y0 == y1)
return;
11674 NK_ASSERT(y0 < y1);
11675 NK_ASSERT(e->sy <= e->ey);
11676 if (y0 > e->ey)
return;
11677 if (y1 < e->sy)
return;
11679 x0 += (x1-x0) * (e->sy - y0) / (y1-y0);
11683 x1 += (x1-x0) * (e->ey - y1) / (y1-y0);
11687 if (x0 == x) NK_ASSERT(x1 <= x+1);
11688 else if (x0 == x+1) NK_ASSERT(x1 >= x);
11689 else if (x0 <= x) NK_ASSERT(x1 <= x);
11690 else if (x0 >= x+1) NK_ASSERT(x1 >= x+1);
11691 else NK_ASSERT(x1 >= x && x1 <= x+1);
11693 if (x0 <= x && x1 <= x)
11694 scanline[x] += e->direction * (y1-y0);
11695 else if (x0 >= x+1 && x1 >= x+1);
11697 NK_ASSERT(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1);
11699 scanline[x] += (float)e->direction * (
float)(y1-y0) * (1.0f-((x0-(
float)x)+(x1-(float)x))/2.0f);
11703 nk_tt__fill_active_edges_new(
float *scanline,
float *scanline_fill,
int len,
11704 struct nk_tt__active_edge *e,
float y_top)
11706 float y_bottom = y_top+1;
11711 NK_ASSERT(e->ey >= y_top);
11716 nk_tt__handle_clipped_edge(scanline,(
int) x0,e, x0,y_top, x0,y_bottom);
11717 nk_tt__handle_clipped_edge(scanline_fill-1,(
int) x0+1,e, x0,y_top, x0,y_bottom);
11719 nk_tt__handle_clipped_edge(scanline_fill-1,0,e, x0,y_top, x0,y_bottom);
11725 float xb = x0 + dx;
11726 float x_top, x_bottom;
11729 NK_ASSERT(e->sy <= y_bottom && e->ey >= y_top);
11734 if (e->sy > y_top) {
11735 x_top = x0 + dx * (e->sy - y_top);
11742 if (e->ey < y_bottom) {
11743 x_bottom = x0 + dx * (e->ey - y_top);
11750 if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len)
11753 if ((
int) x_top == (int) x_bottom) {
11756 int x = (int) x_top;
11758 NK_ASSERT(x >= 0 && x < len);
11759 scanline[x] += e->direction * (1.0f-(((float)x_top - (
float)x) + ((
float)x_bottom-(float)x))/2.0f) * (float)height;
11760 scanline_fill[x] += e->direction * (float)height;
11763 float y_crossing, step, sign, area;
11765 if (x_top > x_bottom)
11769 y0 = y_bottom - (y0 - y_top);
11770 y1 = y_bottom - (y1 - y_top);
11771 t = y0; y0 = y1; y1 = t;
11772 t = x_bottom; x_bottom = x_top; x_top = t;
11775 t = x0; x0 = xb; xb = t;
11779 x2 = (int) x_bottom;
11781 y_crossing = ((float)x1+1 - (
float)x0) * (
float)dy + (float)y_top;
11783 sign = e->direction;
11785 area = sign * (y_crossing-y0);
11787 scanline[x1] += area * (1.0f-((float)((
float)x_top - (float)x1)+(float)(x1+1-x1))/2.0f);
11790 for (x = x1+1; x < x2; ++x) {
11791 scanline[x] += area + step/2;
11794 y_crossing += (float)dy * (
float)(x2 - (x1+1));
11796 scanline[x2] += area + sign * (1.0f-((float)(x2-x2)+((float)x_bottom-(
float)x2))/2.0f) * (y1-y_crossing);
11797 scanline_fill[x2] += sign * (y1-y0);
11807 for (x=0; x < len; ++x)
11824 float x1 = (float) (x);
11825 float x2 = (float) (x+1);
11827 float y3 = y_bottom;
11830 yb = ((float)x - x0) / dx + y_top;
11831 y2 = ((float)x+1 - x0) / dx + y_top;
11833 if (x0 < x1 && x3 > x2) {
11834 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x1,yb);
11835 nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x2,y2);
11836 nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3);
11837 }
else if (x3 < x1 && x0 > x2) {
11838 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x2,y2);
11839 nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x1,yb);
11840 nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x3,y3);
11841 }
else if (x0 < x1 && x3 > x1) {
11842 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x1,yb);
11843 nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x3,y3);
11844 }
else if (x3 < x1 && x0 > x1) {
11845 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x1,yb);
11846 nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x3,y3);
11847 }
else if (x0 < x2 && x3 > x2) {
11848 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x2,y2);
11849 nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3);
11850 }
else if (x3 < x2 && x0 > x2) {
11851 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x2,y2);
11852 nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3);
11854 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x3,y3);
11863 nk_tt__rasterize_sorted_edges(
struct nk_tt__bitmap *result,
struct nk_tt__edge *e,
11864 int n,
int vsubsample,
int off_x,
int off_y,
struct nk_allocator *alloc)
11867 struct nk_tt__hheap hh;
11868 struct nk_tt__active_edge *active = 0;
11870 float scanline_data[129], *scanline, *scanline2;
11876 if (result->w > 64)
11877 scanline = (
float *) alloc->
alloc(alloc->
userdata,0, (
nk_size)(result->w*2+1) *
sizeof(
float));
11878 else scanline = scanline_data;
11880 scanline2 = scanline + result->w;
11882 e[n].y0 = (float) (off_y + result->h) + 1;
11884 while (j < result->h)
11887 float scan_y_top = (float)y + 0.0f;
11888 float scan_y_bottom = (float)y + 1.0f;
11889 struct nk_tt__active_edge **step = &active;
11891 NK_MEMSET(scanline , 0, (
nk_size)result->w*
sizeof(scanline[0]));
11892 NK_MEMSET(scanline2, 0, (
nk_size)(result->w+1)*
sizeof(scanline[0]));
11897 struct nk_tt__active_edge * z = *step;
11898 if (z->ey <= scan_y_top) {
11900 NK_ASSERT(z->direction);
11902 nk_tt__hheap_free(&hh, z);
11904 step = &((*step)->next);
11909 while (e->y0 <= scan_y_bottom) {
11910 if (e->y0 != e->y1) {
11911 struct nk_tt__active_edge *z = nk_tt__new_active(&hh, e, off_x, scan_y_top);
11913 NK_ASSERT(z->ey >= scan_y_top);
11924 nk_tt__fill_active_edges_new(scanline, scanline2+1, result->w, active, scan_y_top);
11928 for (i=0; i < result->w; ++i) {
11931 sum += scanline2[i];
11932 k = scanline[i] + sum;
11933 k = (float)
NK_ABS(k) * 255.0f + 0.5f;
11935 if (m > 255) m = 255;
11936 result->pixels[j*result->stride + i] = (
unsigned char) m;
11942 struct nk_tt__active_edge *z = *step;
11944 step = &((*step)->next);
11949 nk_tt__hheap_cleanup(&hh);
11950 if (scanline != scanline_data)
11954 nk_tt__sort_edges_ins_sort(
struct nk_tt__edge *p,
int n)
11957 #define NK_TT__COMPARE(a,b) ((a)->y0 < (b)->y0)
11958 for (i=1; i < n; ++i) {
11959 struct nk_tt__edge t = p[i], *a = &t;
11962 struct nk_tt__edge *b = &p[j-1];
11963 int c = NK_TT__COMPARE(a,b);
11973 nk_tt__sort_edges_quicksort(
struct nk_tt__edge *p,
int n)
11977 struct nk_tt__edge t;
11978 int c01,c12,c,m,i,j;
11982 c01 = NK_TT__COMPARE(&p[0],&p[m]);
11983 c12 = NK_TT__COMPARE(&p[m],&p[n-1]);
11989 c = NK_TT__COMPARE(&p[0],&p[n-1]);
11992 z = (c == c12) ? 0 : n-1;
12011 if (!NK_TT__COMPARE(&p[i], &p[0]))
break;
12014 if (!NK_TT__COMPARE(&p[0], &p[j]))
break;
12030 nk_tt__sort_edges_quicksort(p,j);
12034 nk_tt__sort_edges_quicksort(p+i, n-i);
12040 nk_tt__sort_edges(
struct nk_tt__edge *p,
int n)
12042 nk_tt__sort_edges_quicksort(p, n);
12043 nk_tt__sort_edges_ins_sort(p, n);
12046 nk_tt__rasterize(
struct nk_tt__bitmap *result,
struct nk_tt__point *pts,
12047 int *wcount,
int windings,
float scale_x,
float scale_y,
12048 float shift_x,
float shift_y,
int off_x,
int off_y,
int invert,
12051 float y_scale_inv = invert ? -scale_y : scale_y;
12052 struct nk_tt__edge *e;
12054 int vsubsample = 1;
12059 for (i=0; i < windings; ++i)
12062 e = (
struct nk_tt__edge*)
12064 if (e == 0)
return;
12068 for (i=0; i < windings; ++i)
12070 struct nk_tt__point *p = pts + m;
12073 for (k=0; k < wcount[i]; j=k++) {
12076 if (p[j].y == p[k].y)
12081 if (invert ? p[j].y > p[k].y : p[j].y < p[k].y) {
12085 e[n].x0 = p[a].x * scale_x + shift_x;
12086 e[n].y0 = (p[a].y * y_scale_inv + shift_y) * (
float)vsubsample;
12087 e[n].x1 = p[b].x * scale_x + shift_x;
12088 e[n].y1 = (p[b].y * y_scale_inv + shift_y) * (
float)vsubsample;
12095 nk_tt__sort_edges(e, n);
12097 nk_tt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, alloc);
12101 nk_tt__add_point(
struct nk_tt__point *points,
int n,
float x,
float y)
12103 if (!points)
return;
12108 nk_tt__tesselate_curve(
struct nk_tt__point *points,
int *num_points,
12109 float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
12110 float objspace_flatness_squared,
int n)
12115 float mx = (x0 + 2*x1 + x2)/4;
12116 float my = (y0 + 2*y1 + y2)/4;
12118 float dx = (x0+x2)/2 - mx;
12119 float dy = (y0+y2)/2 - my;
12124 if (dx*dx+dy*dy > objspace_flatness_squared) {
12125 nk_tt__tesselate_curve(points, num_points, x0,y0,
12126 (x0+x1)/2.0f,(y0+y1)/2.0f, mx,my, objspace_flatness_squared,n+1);
12127 nk_tt__tesselate_curve(points, num_points, mx,my,
12128 (x1+x2)/2.0f,(y1+y2)/2.0f, x2,y2, objspace_flatness_squared,n+1);
12130 nk_tt__add_point(points, *num_points,x2,y2);
12131 *num_points = *num_points+1;
12136 nk_tt_FlattenCurves(
struct nk_tt_vertex *vertices,
int num_verts,
12137 float objspace_flatness,
int **contour_lengths,
int *num_contours,
12141 struct nk_tt__point *points=0;
12143 float objspace_flatness_squared = objspace_flatness * objspace_flatness;
12150 for (i=0; i < num_verts; ++i)
12151 if (vertices[i].type == NK_TT_vmove) ++n;
12154 if (n == 0)
return 0;
12156 *contour_lengths = (
int *)
12158 if (*contour_lengths == 0) {
12164 for (pass=0; pass < 2; ++pass)
12168 points = (
struct nk_tt__point *)
12170 if (points == 0)
goto error;
12175 for (i=0; i < num_verts; ++i)
12177 switch (vertices[i].type) {
12181 (*contour_lengths)[n] = num_points - start;
12183 start = num_points;
12185 x = vertices[i].x, y = vertices[i].y;
12186 nk_tt__add_point(points, num_points++, x,y);
12189 x = vertices[i].x, y = vertices[i].y;
12190 nk_tt__add_point(points, num_points++, x, y);
12193 nk_tt__tesselate_curve(points, &num_points, x,y,
12194 vertices[i].cx, vertices[i].cy,
12195 vertices[i].x, vertices[i].y,
12196 objspace_flatness_squared, 0);
12197 x = vertices[i].x, y = vertices[i].y;
12202 (*contour_lengths)[n] = num_points - start;
12209 *contour_lengths = 0;
12214 nk_tt_Rasterize(
struct nk_tt__bitmap *result,
float flatness_in_pixels,
12215 struct nk_tt_vertex *vertices,
int num_verts,
12216 float scale_x,
float scale_y,
float shift_x,
float shift_y,
12217 int x_off,
int y_off,
int invert,
struct nk_allocator *alloc)
12219 float scale = scale_x > scale_y ? scale_y : scale_x;
12220 int winding_count, *winding_lengths;
12221 struct nk_tt__point *windings = nk_tt_FlattenCurves(vertices, num_verts,
12222 flatness_in_pixels / scale, &winding_lengths, &winding_count, alloc);
12226 nk_tt__rasterize(result, windings, winding_lengths, winding_count,
12227 scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, alloc);
12233 nk_tt_MakeGlyphBitmapSubpixel(
const struct nk_tt_fontinfo *info,
unsigned char *output,
12234 int out_w,
int out_h,
int out_stride,
float scale_x,
float scale_y,
12235 float shift_x,
float shift_y,
int glyph,
struct nk_allocator *alloc)
12238 struct nk_tt_vertex *vertices;
12239 int num_verts = nk_tt_GetGlyphShape(info, alloc, glyph, &vertices);
12240 struct nk_tt__bitmap gbm;
12242 nk_tt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x,
12243 shift_y, &ix0,&iy0,0,0);
12244 gbm.pixels = output;
12247 gbm.stride = out_stride;
12249 if (gbm.w && gbm.h)
12250 nk_tt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y,
12251 shift_x, shift_y, ix0,iy0, 1, alloc);
12259 nk_tt_PackBegin(
struct nk_tt_pack_context *spc,
unsigned char *pixels,
12260 int pw,
int ph,
int stride_in_bytes,
int padding,
struct nk_allocator *alloc)
12262 int num_nodes = pw - padding;
12263 struct nk_rp_context *context = (
struct nk_rp_context *)
12265 struct nk_rp_node *nodes = (
struct nk_rp_node*)
12268 if (context == 0 || nodes == 0) {
12269 if (context != 0) alloc->
free(alloc->
userdata, context);
12276 spc->pixels = pixels;
12277 spc->pack_info = context;
12278 spc->nodes = nodes;
12279 spc->padding = padding;
12280 spc->stride_in_bytes = (stride_in_bytes != 0) ? stride_in_bytes : pw;
12281 spc->h_oversample = 1;
12282 spc->v_oversample = 1;
12284 nk_rp_init_target(context, pw-padding, ph-padding, nodes, num_nodes);
12286 NK_MEMSET(pixels, 0, (
nk_size)(pw*ph));
12290 nk_tt_PackEnd(
struct nk_tt_pack_context *spc,
struct nk_allocator *alloc)
12296 nk_tt_PackSetOversampling(
struct nk_tt_pack_context *spc,
12297 unsigned int h_oversample,
unsigned int v_oversample)
12299 NK_ASSERT(h_oversample <= NK_TT_MAX_OVERSAMPLE);
12300 NK_ASSERT(v_oversample <= NK_TT_MAX_OVERSAMPLE);
12301 if (h_oversample <= NK_TT_MAX_OVERSAMPLE)
12302 spc->h_oversample = h_oversample;
12303 if (v_oversample <= NK_TT_MAX_OVERSAMPLE)
12304 spc->v_oversample = v_oversample;
12307 nk_tt__h_prefilter(
unsigned char *pixels,
int w,
int h,
int stride_in_bytes,
12310 unsigned char buffer[NK_TT_MAX_OVERSAMPLE];
12311 int safe_w = w - kernel_width;
12314 for (j=0; j < h; ++j)
12317 unsigned int total;
12318 NK_MEMSET(buffer, 0, (
nk_size)kernel_width);
12323 switch (kernel_width) {
12325 for (i=0; i <= safe_w; ++i) {
12326 total += (
unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]);
12327 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12328 pixels[i] = (
unsigned char) (total / 2);
12332 for (i=0; i <= safe_w; ++i) {
12333 total += (
unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]);
12334 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12335 pixels[i] = (
unsigned char) (total / 3);
12339 for (i=0; i <= safe_w; ++i) {
12340 total += (
unsigned int)pixels[i] - buffer[i & NK_TT__OVER_MASK];
12341 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12342 pixels[i] = (
unsigned char) (total / 4);
12346 for (i=0; i <= safe_w; ++i) {
12347 total += (
unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]);
12348 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12349 pixels[i] = (
unsigned char) (total / 5);
12353 for (i=0; i <= safe_w; ++i) {
12354 total += (
unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]);
12355 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12356 pixels[i] = (
unsigned char) (total / (
unsigned int)kernel_width);
12361 for (; i < w; ++i) {
12362 NK_ASSERT(pixels[i] == 0);
12363 total -= (
unsigned int)(buffer[i & NK_TT__OVER_MASK]);
12364 pixels[i] = (
unsigned char) (total / (
unsigned int)kernel_width);
12366 pixels += stride_in_bytes;
12370 nk_tt__v_prefilter(
unsigned char *pixels,
int w,
int h,
int stride_in_bytes,
12373 unsigned char buffer[NK_TT_MAX_OVERSAMPLE];
12374 int safe_h = h - kernel_width;
12377 for (j=0; j < w; ++j)
12380 unsigned int total;
12381 NK_MEMSET(buffer, 0, (
nk_size)kernel_width);
12386 switch (kernel_width) {
12388 for (i=0; i <= safe_h; ++i) {
12389 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12390 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12391 pixels[i*stride_in_bytes] = (
unsigned char) (total / 2);
12395 for (i=0; i <= safe_h; ++i) {
12396 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12397 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12398 pixels[i*stride_in_bytes] = (
unsigned char) (total / 3);
12402 for (i=0; i <= safe_h; ++i) {
12403 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12404 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12405 pixels[i*stride_in_bytes] = (
unsigned char) (total / 4);
12409 for (i=0; i <= safe_h; ++i) {
12410 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12411 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12412 pixels[i*stride_in_bytes] = (
unsigned char) (total / 5);
12416 for (i=0; i <= safe_h; ++i) {
12417 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12418 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12419 pixels[i*stride_in_bytes] = (
unsigned char) (total / (
unsigned int)kernel_width);
12424 for (; i < h; ++i) {
12425 NK_ASSERT(pixels[i*stride_in_bytes] == 0);
12426 total -= (
unsigned int)(buffer[i & NK_TT__OVER_MASK]);
12427 pixels[i*stride_in_bytes] = (
unsigned char) (total / (
unsigned int)kernel_width);
12433 nk_tt__oversample_shift(
int oversample)
12442 return (
float)-(oversample - 1) / (2.0f * (
float)oversample);
12445 nk_tt_PackFontRangesGatherRects(
struct nk_tt_pack_context *spc,
12446 struct nk_tt_fontinfo *info,
struct nk_tt_pack_range *ranges,
12447 int num_ranges,
struct nk_rp_rect *rects)
12453 for (i=0; i < num_ranges; ++i) {
12454 float fh = ranges[i].font_size;
12455 float scale = (fh > 0) ? nk_tt_ScaleForPixelHeight(info, fh):
12456 nk_tt_ScaleForMappingEmToPixels(info, -fh);
12457 ranges[i].h_oversample = (
unsigned char) spc->h_oversample;
12458 ranges[i].v_oversample = (
unsigned char) spc->v_oversample;
12459 for (j=0; j < ranges[i].num_chars; ++j) {
12461 int codepoint = ranges[i].first_unicode_codepoint_in_range ?
12462 ranges[i].first_unicode_codepoint_in_range + j :
12463 ranges[i].array_of_unicode_codepoints[j];
12465 int glyph = nk_tt_FindGlyphIndex(info, codepoint);
12466 nk_tt_GetGlyphBitmapBoxSubpixel(info,glyph, scale * (
float)spc->h_oversample,
12467 scale * (
float)spc->v_oversample, 0,0, &x0,&y0,&x1,&y1);
12468 rects[k].w = (nk_rp_coord) (x1-x0 + spc->padding + (
int)spc->h_oversample-1);
12469 rects[k].h = (nk_rp_coord) (y1-y0 + spc->padding + (
int)spc->v_oversample-1);
12476 nk_tt_PackFontRangesRenderIntoRects(
struct nk_tt_pack_context *spc,
12477 struct nk_tt_fontinfo *info,
struct nk_tt_pack_range *ranges,
12478 int num_ranges,
struct nk_rp_rect *rects,
struct nk_allocator *alloc)
12480 int i,j,k, return_value = 1;
12482 int old_h_over = (int)spc->h_oversample;
12483 int old_v_over = (
int)spc->v_oversample;
12487 for (i=0; i < num_ranges; ++i)
12489 float fh = ranges[i].font_size;
12490 float recip_h,recip_v,sub_x,sub_y;
12491 float scale = fh > 0 ? nk_tt_ScaleForPixelHeight(info, fh):
12492 nk_tt_ScaleForMappingEmToPixels(info, -fh);
12494 spc->h_oversample = ranges[i].h_oversample;
12495 spc->v_oversample = ranges[i].v_oversample;
12497 recip_h = 1.0f / (float)spc->h_oversample;
12498 recip_v = 1.0f / (
float)spc->v_oversample;
12500 sub_x = nk_tt__oversample_shift((
int)spc->h_oversample);
12501 sub_y = nk_tt__oversample_shift((
int)spc->v_oversample);
12503 for (j=0; j < ranges[i].num_chars; ++j)
12505 struct nk_rp_rect *r = &rects[k];
12508 struct nk_tt_packedchar *bc = &ranges[i].chardata_for_range[j];
12509 int advance, lsb, x0,y0,x1,y1;
12510 int codepoint = ranges[i].first_unicode_codepoint_in_range ?
12511 ranges[i].first_unicode_codepoint_in_range + j :
12512 ranges[i].array_of_unicode_codepoints[j];
12513 int glyph = nk_tt_FindGlyphIndex(info, codepoint);
12514 nk_rp_coord pad = (nk_rp_coord) spc->padding;
12517 r->x = (nk_rp_coord)((int)r->x + (
int)pad);
12518 r->y = (nk_rp_coord)((
int)r->y + (int)pad);
12519 r->w = (nk_rp_coord)((
int)r->w - (int)pad);
12520 r->h = (nk_rp_coord)((
int)r->h - (int)pad);
12522 nk_tt_GetGlyphHMetrics(info, glyph, &advance, &lsb);
12523 nk_tt_GetGlyphBitmapBox(info, glyph, scale * (
float)spc->h_oversample,
12524 (scale * (
float)spc->v_oversample), &x0,&y0,&x1,&y1);
12525 nk_tt_MakeGlyphBitmapSubpixel(info, spc->pixels + r->x + r->y*spc->stride_in_bytes,
12526 (
int)(r->w - spc->h_oversample+1), (
int)(r->h - spc->v_oversample+1),
12527 spc->stride_in_bytes, scale * (
float)spc->h_oversample,
12528 scale * (
float)spc->v_oversample, 0,0, glyph, alloc);
12530 if (spc->h_oversample > 1)
12531 nk_tt__h_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes,
12532 r->w, r->h, spc->stride_in_bytes, (
int)spc->h_oversample);
12534 if (spc->v_oversample > 1)
12535 nk_tt__v_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes,
12536 r->w, r->h, spc->stride_in_bytes, (
int)spc->v_oversample);
12542 bc->xadvance = scale * (float)advance;
12543 bc->xoff = (float) x0 * recip_h + sub_x;
12544 bc->yoff = (float) y0 * recip_v + sub_y;
12545 bc->xoff2 = ((float)x0 + r->w) * recip_h + sub_x;
12546 bc->yoff2 = ((float)y0 + r->h) * recip_v + sub_y;
12554 spc->h_oversample = (
unsigned int)old_h_over;
12555 spc->v_oversample = (
unsigned int)old_v_over;
12556 return return_value;
12559 nk_tt_GetPackedQuad(
struct nk_tt_packedchar *chardata,
int pw,
int ph,
12560 int char_index,
float *xpos,
float *ypos,
struct nk_tt_aligned_quad *q,
12561 int align_to_integer)
12563 float ipw = 1.0f / (float)pw, iph = 1.0f / (
float)ph;
12564 struct nk_tt_packedchar *b = (
struct nk_tt_packedchar*)(chardata + char_index);
12565 if (align_to_integer) {
12566 int tx = nk_ifloorf((*xpos + b->xoff) + 0.5f);
12567 int ty = nk_ifloorf((*ypos + b->yoff) + 0.5f);
12569 float x = (float)tx;
12570 float y = (float)ty;
12574 q->x1 = x + b->xoff2 - b->xoff;
12575 q->y1 = y + b->yoff2 - b->yoff;
12577 q->x0 = *xpos + b->xoff;
12578 q->y0 = *ypos + b->yoff;
12579 q->x1 = *xpos + b->xoff2;
12580 q->y1 = *ypos + b->yoff2;
12582 q->s0 = b->x0 * ipw;
12583 q->t0 = b->y0 * iph;
12584 q->s1 = b->x1 * ipw;
12585 q->t1 = b->y1 * iph;
12586 *xpos += b->xadvance;
12594 struct nk_font_bake_data {
12595 struct nk_tt_fontinfo info;
12596 struct nk_rp_rect *rects;
12597 struct nk_tt_pack_range *ranges;
12601 struct nk_font_baker {
12603 struct nk_tt_pack_context spc;
12604 struct nk_font_bake_data *build;
12605 struct nk_tt_packedchar *packed_chars;
12606 struct nk_rp_rect *rects;
12607 struct nk_tt_pack_range *ranges;
12617 nk_range_count(
const nk_rune *range)
12621 if (!range)
return 0;
12622 while (*(iter++) != 0);
12623 return (iter == range) ? 0 : (int)((iter - range)/2);
12626 nk_range_glyph_count(
const nk_rune *range,
int count)
12629 int total_glyphs = 0;
12630 for (i = 0; i < count; ++i) {
12635 diff = (int)((t - f) + 1);
12636 total_glyphs += diff;
12638 return total_glyphs;
12641 nk_font_default_glyph_ranges(
void)
12647 nk_font_chinese_glyph_ranges(
void)
12660 nk_font_cyrillic_glyph_ranges(
void)
12672 nk_font_korean_glyph_ranges(
void)
12683 nk_font_baker_memory(
nk_size *temp,
int *glyph_count,
12684 struct nk_font_config *config_list,
int count)
12686 int range_count = 0;
12687 int total_range_count = 0;
12688 struct nk_font_config *iter, *i;
12690 NK_ASSERT(config_list);
12691 NK_ASSERT(glyph_count);
12692 if (!config_list) {
12698 for (iter = config_list; iter; iter = iter->next) {
12700 do {
if (!i->range) iter->range = nk_font_default_glyph_ranges();
12701 range_count = nk_range_count(i->range);
12702 total_range_count += range_count;
12703 *glyph_count += nk_range_glyph_count(i->range, range_count);
12704 }
while ((i = i->n) != iter);
12706 *temp = (
nk_size)*glyph_count *
sizeof(
struct nk_rp_rect);
12707 *temp += (
nk_size)total_range_count *
sizeof(
struct nk_tt_pack_range);
12708 *temp += (
nk_size)*glyph_count *
sizeof(
struct nk_tt_packedchar);
12709 *temp += (
nk_size)count *
sizeof(
struct nk_font_bake_data);
12710 *temp +=
sizeof(
struct nk_font_baker);
12711 *temp += nk_rect_align + nk_range_align + nk_char_align;
12712 *temp += nk_build_align + nk_baker_align;
12715 nk_font_baker(
void *memory,
int glyph_count,
int count,
struct nk_allocator *alloc)
12717 struct nk_font_baker *baker;
12718 if (!memory)
return 0;
12720 baker = (
struct nk_font_baker*)
NK_ALIGN_PTR(memory, nk_baker_align);
12721 baker->build = (
struct nk_font_bake_data*)
NK_ALIGN_PTR((baker + 1), nk_build_align);
12722 baker->packed_chars = (
struct nk_tt_packedchar*)
NK_ALIGN_PTR((baker->build + count), nk_char_align);
12723 baker->rects = (
struct nk_rp_rect*)
NK_ALIGN_PTR((baker->packed_chars + glyph_count), nk_rect_align);
12724 baker->ranges = (
struct nk_tt_pack_range*)
NK_ALIGN_PTR((baker->rects + glyph_count), nk_range_align);
12725 baker->alloc = *alloc;
12729 nk_font_bake_pack(
struct nk_font_baker *baker,
12730 nk_size *image_memory,
int *width,
int *height,
struct nk_recti *custom,
12731 const struct nk_font_config *config_list,
int count,
12735 const struct nk_font_config *config_iter, *it;
12736 int total_glyph_count = 0;
12737 int total_range_count = 0;
12738 int range_count = 0;
12741 NK_ASSERT(image_memory);
12744 NK_ASSERT(config_list);
12748 if (!image_memory || !width || !height || !config_list || !count)
return nk_false;
12749 for (config_iter = config_list; config_iter; config_iter = config_iter->next) {
12751 do {range_count = nk_range_count(it->range);
12752 total_range_count += range_count;
12753 total_glyph_count += nk_range_glyph_count(it->range, range_count);
12754 }
while ((it = it->n) != config_iter);
12757 for (config_iter = config_list; config_iter; config_iter = config_iter->next) {
12759 do {
if (!nk_tt_InitFont(&baker->build[i++].info, (
const unsigned char*)it->ttf_blob, 0))
12761 }
while ((it = it->n) != config_iter);
12764 *width = (total_glyph_count > 1000) ? 1024 : 512;
12765 nk_tt_PackBegin(&baker->spc, 0, (
int)*width, (
int)max_height, 0, 1, alloc);
12774 struct nk_rp_rect custom_space;
12775 nk_zero(&custom_space,
sizeof(custom_space));
12776 custom_space.w = (nk_rp_coord)(custom->
w);
12777 custom_space.h = (nk_rp_coord)(custom->
h);
12779 nk_tt_PackSetOversampling(&baker->spc, 1, 1);
12780 nk_rp_pack_rects((
struct nk_rp_context*)baker->spc.pack_info, &custom_space, 1);
12781 *height =
NK_MAX(*height, (
int)(custom_space.y + custom_space.h));
12783 custom->
x = (short)custom_space.x;
12784 custom->
y = (
short)custom_space.y;
12785 custom->
w = (short)custom_space.w;
12786 custom->
h = (
short)custom_space.h;
12790 for (input_i = 0, config_iter = config_list; input_i < count && config_iter;
12791 config_iter = config_iter->next) {
12796 const struct nk_font_config *cfg = it;
12797 struct nk_font_bake_data *tmp = &baker->build[input_i++];
12800 glyph_count = 0; range_count = 0;
12801 for (in_range = cfg->range; in_range[0] && in_range[1]; in_range += 2) {
12802 glyph_count += (int)(in_range[1] - in_range[0]) + 1;
12807 tmp->ranges = baker->ranges + range_n;
12808 tmp->range_count = (
nk_rune)range_count;
12809 range_n += range_count;
12810 for (i = 0; i < range_count; ++i) {
12811 in_range = &cfg->range[i * 2];
12812 tmp->ranges[i].font_size = cfg->size;
12813 tmp->ranges[i].first_unicode_codepoint_in_range = (int)in_range[0];
12814 tmp->ranges[i].num_chars = (int)(in_range[1]- in_range[0]) + 1;
12815 tmp->ranges[i].chardata_for_range = baker->packed_chars + char_n;
12816 char_n += tmp->ranges[i].num_chars;
12820 tmp->rects = baker->rects + rect_n;
12821 rect_n += glyph_count;
12822 nk_tt_PackSetOversampling(&baker->spc, cfg->oversample_h, cfg->oversample_v);
12823 n = nk_tt_PackFontRangesGatherRects(&baker->spc, &tmp->info,
12824 tmp->ranges, (
int)tmp->range_count, tmp->rects);
12825 nk_rp_pack_rects((
struct nk_rp_context*)baker->spc.pack_info, tmp->rects, (
int)n);
12828 for (i = 0; i < n; ++i) {
12829 if (tmp->rects[i].was_packed)
12830 *height =
NK_MAX(*height, tmp->rects[i].y + tmp->rects[i].h);
12832 }
while ((it = it->n) != config_iter);
12834 NK_ASSERT(rect_n == total_glyph_count);
12835 NK_ASSERT(char_n == total_glyph_count);
12836 NK_ASSERT(range_n == total_range_count);
12838 *height = (int)nk_round_up_pow2((
nk_uint)*height);
12843 nk_font_bake(
struct nk_font_baker *baker,
void *image_memory,
int width,
int height,
12844 struct nk_font_glyph *glyphs,
int glyphs_count,
12845 const struct nk_font_config *config_list,
int font_count)
12849 const struct nk_font_config *config_iter;
12850 const struct nk_font_config *it;
12852 NK_ASSERT(image_memory);
12855 NK_ASSERT(config_list);
12857 NK_ASSERT(font_count);
12858 NK_ASSERT(glyphs_count);
12859 if (!image_memory || !width || !height || !config_list ||
12860 !font_count || !glyphs || !glyphs_count)
12865 baker->spc.pixels = (
unsigned char*)image_memory;
12866 baker->spc.height = (int)height;
12867 for (input_i = 0, config_iter = config_list; input_i < font_count && config_iter;
12868 config_iter = config_iter->next) {
12870 do {
const struct nk_font_config *cfg = it;
12871 struct nk_font_bake_data *tmp = &baker->build[input_i++];
12872 nk_tt_PackSetOversampling(&baker->spc, cfg->oversample_h, cfg->oversample_v);
12873 nk_tt_PackFontRangesRenderIntoRects(&baker->spc, &tmp->info, tmp->ranges,
12874 (
int)tmp->range_count, tmp->rects, &baker->alloc);
12875 }
while ((it = it->n) != config_iter);
12876 } nk_tt_PackEnd(&baker->spc, &baker->alloc);
12879 for (input_i = 0, config_iter = config_list; input_i < font_count && config_iter;
12880 config_iter = config_iter->next) {
12885 const struct nk_font_config *cfg = it;
12886 struct nk_font_bake_data *tmp = &baker->build[input_i++];
12887 struct nk_baked_font *dst_font = cfg->font;
12889 float font_scale = nk_tt_ScaleForPixelHeight(&tmp->info, cfg->size);
12890 int unscaled_ascent, unscaled_descent, unscaled_line_gap;
12891 nk_tt_GetFontVMetrics(&tmp->info, &unscaled_ascent, &unscaled_descent,
12892 &unscaled_line_gap);
12895 if (!cfg->merge_mode) {
12896 dst_font->ranges = cfg->range;
12897 dst_font->height = cfg->size;
12898 dst_font->ascent = ((float)unscaled_ascent * font_scale);
12899 dst_font->descent = ((float)unscaled_descent * font_scale);
12900 dst_font->glyph_offset = glyph_n;
12903 dst_font->glyph_count = 0;
12907 for (i = 0; i < tmp->range_count; ++i) {
12908 struct nk_tt_pack_range *range = &tmp->ranges[i];
12909 for (char_idx = 0; char_idx < range->num_chars; char_idx++)
12912 float dummy_x = 0, dummy_y = 0;
12913 struct nk_tt_aligned_quad q;
12914 struct nk_font_glyph *glyph;
12917 const struct nk_tt_packedchar *pc = &range->chardata_for_range[char_idx];
12918 if (!pc->x0 && !pc->x1 && !pc->y0 && !pc->y1)
continue;
12919 codepoint = (
nk_rune)(range->first_unicode_codepoint_in_range + char_idx);
12920 nk_tt_GetPackedQuad(range->chardata_for_range, (
int)width,
12921 (
int)height, char_idx, &dummy_x, &dummy_y, &q, 0);
12924 glyph = &glyphs[dst_font->glyph_offset + dst_font->glyph_count + (
unsigned int)glyph_count];
12925 glyph->codepoint = codepoint;
12926 glyph->x0 = q.x0; glyph->y0 = q.y0;
12927 glyph->x1 = q.x1; glyph->y1 = q.y1;
12928 glyph->y0 += (dst_font->ascent + 0.5f);
12929 glyph->y1 += (dst_font->ascent + 0.5f);
12930 glyph->w = glyph->x1 - glyph->x0 + 0.5f;
12931 glyph->h = glyph->y1 - glyph->y0;
12933 if (cfg->coord_type == NK_COORD_PIXEL) {
12934 glyph->u0 = q.s0 * (float)width;
12935 glyph->v0 = q.t0 * (float)height;
12936 glyph->u1 = q.s1 * (float)width;
12937 glyph->v1 = q.t1 * (float)height;
12944 glyph->xadvance = (pc->xadvance + cfg->spacing.x);
12945 if (cfg->pixel_snap)
12946 glyph->xadvance = (float)(
int)(glyph->xadvance + 0.5f);
12950 dst_font->glyph_count += glyph_count;
12951 glyph_n += glyph_count;
12952 }
while ((it = it->n) != config_iter);
12956 nk_font_bake_custom_data(
void *img_memory,
int img_width,
int img_height,
12957 struct nk_recti img_dst,
const char *texture_data_mask,
int tex_width,
12958 int tex_height,
char white,
char black)
12965 NK_ASSERT(img_memory);
12966 NK_ASSERT(img_width);
12967 NK_ASSERT(img_height);
12968 NK_ASSERT(texture_data_mask);
12970 if (!img_memory || !img_width || !img_height || !texture_data_mask)
12973 pixels = (
nk_byte*)img_memory;
12974 for (y = 0, n = 0; y < tex_height; ++y) {
12975 for (x = 0; x < tex_width; ++x, ++n) {
12976 const int off0 = ((img_dst.
x + x) + (img_dst.
y + y) * img_width);
12977 const int off1 = off0 + 1 + tex_width;
12978 pixels[off0] = (texture_data_mask[n] == white) ? 0xFF : 0x00;
12979 pixels[off1] = (texture_data_mask[n] == black) ? 0xFF : 0x00;
12984 nk_font_bake_convert(
void *out_memory,
int img_width,
int img_height,
12985 const void *in_memory)
12991 NK_ASSERT(out_memory);
12992 NK_ASSERT(in_memory);
12993 NK_ASSERT(img_width);
12994 NK_ASSERT(img_height);
12995 if (!out_memory || !in_memory || !img_height || !img_width)
return;
12998 src = (
const nk_byte*)in_memory;
12999 for (n = (
int)(img_width * img_height); n > 0; n--)
13000 *dst++ = ((
nk_rune)(*src++) << 24) | 0x00FFFFFF;
13009 nk_font_text_width(
nk_handle handle,
float height,
const char *text,
int len)
13013 float text_width = 0;
13017 struct nk_font *font = (
struct nk_font*)handle.
ptr;
13019 NK_ASSERT(font->glyphs);
13020 if (!font || !text || !len)
13023 scale = height/font->info.height;
13024 glyph_len = text_len =
nk_utf_decode(text, &unicode, (
int)len);
13025 if (!glyph_len)
return 0;
13026 while (text_len <= (
int)len && glyph_len) {
13027 const struct nk_font_glyph *g;
13031 g = nk_font_find_glyph(font, unicode);
13032 text_width += g->xadvance * scale;
13035 glyph_len =
nk_utf_decode(text + text_len, &unicode, (
int)len - text_len);
13036 text_len += glyph_len;
13040 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
13042 nk_font_query_font_glyph(
nk_handle handle,
float height,
13043 struct nk_user_font_glyph *glyph,
nk_rune codepoint,
nk_rune next_codepoint)
13046 const struct nk_font_glyph *g;
13047 struct nk_font *font;
13052 font = (
struct nk_font*)handle.
ptr;
13054 NK_ASSERT(font->glyphs);
13055 if (!font || !glyph)
13058 scale = height/font->info.height;
13059 g = nk_font_find_glyph(font, codepoint);
13060 glyph->width = (g->x1 - g->x0) * scale;
13061 glyph->height = (g->y1 - g->y0) * scale;
13062 glyph->offset =
nk_vec2(g->x0 * scale, g->y0 * scale);
13063 glyph->xadvance = (g->xadvance * scale);
13064 glyph->uv[0] =
nk_vec2(g->u0, g->v0);
13065 glyph->uv[1] =
nk_vec2(g->u1, g->v1);
13068 NK_API const struct nk_font_glyph*
13069 nk_font_find_glyph(
struct nk_font *font,
nk_rune unicode)
13073 int total_glyphs = 0;
13074 const struct nk_font_glyph *glyph = 0;
13075 const struct nk_font_config *iter = 0;
13078 NK_ASSERT(font->glyphs);
13079 NK_ASSERT(font->info.ranges);
13080 if (!font || !font->glyphs)
return 0;
13082 glyph = font->fallback;
13083 iter = font->config;
13084 do {count = nk_range_count(iter->range);
13085 for (i = 0; i < count; ++i) {
13086 nk_rune f = iter->range[(i*2)+0];
13087 nk_rune t = iter->range[(i*2)+1];
13088 int diff = (int)((t - f) + 1);
13089 if (unicode >= f && unicode <= t)
13090 return &font->glyphs[((
nk_rune)total_glyphs + (unicode - f))];
13091 total_glyphs += diff;
13093 }
while ((iter = iter->n) != font->config);
13097 nk_font_init(
struct nk_font *font,
float pixel_height,
13098 nk_rune fallback_codepoint,
struct nk_font_glyph *glyphs,
13099 const struct nk_baked_font *baked_font,
nk_handle atlas)
13101 struct nk_baked_font baked;
13104 NK_ASSERT(baked_font);
13105 if (!font || !glyphs || !baked_font)
13108 baked = *baked_font;
13109 font->fallback = 0;
13110 font->info = baked;
13111 font->scale = (float)pixel_height / (
float)font->info.height;
13112 font->glyphs = &glyphs[baked_font->glyph_offset];
13113 font->texture = atlas;
13114 font->fallback_codepoint = fallback_codepoint;
13115 font->fallback = nk_font_find_glyph(font, fallback_codepoint);
13117 font->handle.height = font->info.height * font->scale;
13118 font->handle.width = nk_font_text_width;
13119 font->handle.userdata.ptr = font;
13120 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
13121 font->handle.query = nk_font_query_font_glyph;
13122 font->handle.texture = font->texture;
13136 #pragma clang diagnostic push
13137 #pragma clang diagnostic ignored "-Woverlength-strings"
13138 #elif defined(__GNUC__) || defined(__GNUG__)
13139 #pragma GCC diagnostic push
13140 #pragma GCC diagnostic ignored "-Woverlength-strings"
13143 #ifdef NK_INCLUDE_DEFAULT_FONT
13145 NK_GLOBAL const char nk_proggy_clean_ttf_compressed_data_base85[11980+1] =
13146 "7])#######hV0qs'/###[),##/l:$#Q6>##5[n42>c-TH`->>#/e>11NNV=Bv(*:.F?uu#(gRU.o0XGH`$vhLG1hxt9?W`#,5LsCp#-i>.r$<$6pD>Lb';9Crc6tgXmKVeU2cD4Eo3R/"
13147 "2*>]b(MC;$jPfY.;h^`IWM9<Lh2TlS+f-s$o6Q<BWH`YiU.xfLq$N;$0iR/GX:U(jcW2p/W*q?-qmnUCI;jHSAiFWM.R*kU@C=GH?a9wp8f$e.-4^Qg1)Q-GL(lf(r/7GrRgwV%MS=C#"
13148 "`8ND>Qo#t'X#(v#Y9w0#1D$CIf;W'#pWUPXOuxXuU(H9M(1<q-UE31#^-V'8IRUo7Qf./L>=Ke$$'5F%)]0^#0X@U.a<r:QLtFsLcL6##lOj)#.Y5<-R&KgLwqJfLgN&;Q?gI^#DY2uL"
13149 "i@^rMl9t=cWq6##weg>$FBjVQTSDgEKnIS7EM9>ZY9w0#L;>>#Mx&4Mvt//L[MkA#W@lK.N'[0#7RL_&#w+F%HtG9M#XL`N&.,GM4Pg;-<nLENhvx>-VsM.M0rJfLH2eTM`*oJMHRC`N"
13150 "kfimM2J,W-jXS:)r0wK#@Fge$U>`w'N7G#$#fB#$E^$#:9:hk+eOe--6x)F7*E%?76%^GMHePW-Z5l'&GiF#$956:rS?dA#fiK:)Yr+`�j@'DbG&#^$PG.Ll+DNa<XCMKEV*N)LN/N"
13151 "*b=%Q6pia-Xg8I$<MR&,VdJe$<(7G;Ckl'&hF;;$<_=X(b.RS%%)###MPBuuE1V:v&cXm#(&cV]`k9OhLMbn%s$G2,B$BfD3X*sp5#l,$R#]x_X1xKX%b5U*[r5iMfUo9U`N99hG)"
13152 "tm+/Us9pG)XPu`<0s-)WTt(gCRxIg(%6sfh=ktMKn3j)<6<b5Sk_/0(^]AaN#(p/L>&VZ>1i%h1S9u5o@YaaW$e+b<TWFn/Z:Oh(Cx2$lNEoN^e)#CFY@@I;BOQ*sRwZtZxRcU7uW6CX"
13153 "ow0i(?$Q[cjOd[P4d)]>ROPOpxTO7Stwi1::iB1q)C_=dV26J;2,]7op$]uQr@_V7$q^%lQwtuHY]=DX,n3L#0PHDO4f9>dC@O>HBuKPpP*E,N+b3L#lpR/MrTEH.IAQk.a>D[.e;mc."
13154 "x]Ip.PH^'/aqUO/$1WxLoW0[iLA<QT;5HKD+@qQ'NQ(3_PLhE48R.qAPSwQ0/WK?Z,[x?-J;jQTWA0X@KJ(_Y8N-:/M74:/-ZpKrUss?d#dZq]DAbkU*JqkL+nwX@@47`5>w=4h(9.`G"
13155 "CRUxHPeR`5Mjol(dUWxZa(>STrPkrJiWx`5U7F#.g*jrohGg`cg:lSTvEY/EV_7H4Q9[Z%cnv;JQYZ5q.l7Zeas:HOIZOB?G<Nald$qs]@]L<J7bR*>gv:[7MI2k).'2($5FNP&EQ(,)"
13156 "U]W]+fh18.vsai00);D3@4ku5P?DP8aJt+;qUM]=+b'8@;mViBKx0DE[-auGl8:PJ&Dj+M6OC]O^((##]`0i)drT;-7X`=-H3[igUnPG-NZlo.#k@h#=Ork$m>a>$-?Tm$UV(?#P6YY#"
13157 "'/###xe7q.73rI3*pP/$1>s9)W,JrM7SN]'/4C#v$U`0#V.[0>xQsH$fEmPMgY2u7Kh(G%siIfLSoS+MK2eTM$=5,M8p`A.;_R%#u[K#$x4AG8.kK/HSB==-'Ie/QTtG?-.*^N-4B/ZM"
13158 "_3YlQC7(p7q)&](`6_c)$/*JL(L-^(]$wIM`dPtOdGA,U3:w2M-0<q-]L_?^)1vw'.,MRsqVr.L;aN&#/EgJ)PBc[-f>+WomX2u7lqM2iEumMTcsF?-aT=Z-97UEnXglEn1K-bnEO`gu"
13159 "Ft(c%=;Am_Qs@jLooI&NX;]0#j4#F14;gl8-GQpgwhrq8'=l_f-b49'UOqkLu7-##oDY2L(te+Mch&gLYtJ,MEtJfLh'x'M=$CS-ZZ%P]8bZ>#S?YY#%Q&q'3^Fw&?D)UDNrocM3A76/"
13160 "/oL?#h7gl85[qW/NDOk%16ij;+:1a'iNIdb-ou8.P*w,v5#EI$TWS>Pot-R*H'-SEpA:g)f+O$%%`kA#G=8RMmG1&O`>to8bC]T&$,n.LoO>29sp3dt-52U%VM#q7'DHpg+#Z9%H[K<L"
13161 "%a2E-grWVM3@2=-k22tL]4$##6We'8UJCKE[d_=%wI;'6X-GsLX4j^SgJ$##R*w,vP3wK#iiW&#*h^D&R?jp7+/u&#(AP##XU8c$fSYW-J95_-Dp[g9wcO&#M-h1OcJlc-*vpw0xUX&#"
13162 "OQFKNX@QI'IoPp7nb,QU//MQ&ZDkKP)X<WSVL(68uVl&#c'[0#(s1X&xm$Y%B7*K:eDA323j998GXbA#pwMs-jgD$9QISB-A_(aN4xoFM^@C58D0+Q+q3n0#3U1InDjF682-SjMXJK)("
13163 "h$hxua_K]ul92%'BOU&#BRRh-slg8KDlr:%L71Ka:.A;%YULjDPmL<LYs8i#XwJOYaKPKc1h:'9Ke,g)b),78=I39B;xiY$bgGw-&.Zi9InXDuYa%G*f2Bq7mn9^#p1vv%#(Wi-;/Z5h"
13164 "o;#2:;%d	v68C5g?ntX0X)pT`;%pB3q7mgGN)3%(P8nTd5L7GeA-GL@+%J3u2:(Yf>et`e;)f#Km8&+DC$I46>#Kr]]u-[=99tts1.qb#q72g1WJO81q+eN'03'eM>&1XxY-caEnO"
13165 "j%2n8)),?ILR5^.Ibn<-X-Mq7[a82Lq:F&#ce+S9wsCK*x`569E8ew'He]h:sI[2LM$[guka3ZRd6:t%IG:;$%YiJ:Nq=?eAw;/:nnDq0(CYcMpG)qLN4$##&J<j$UpK<Q4a1]MupW^-"
13166 "sj_$%[HK%'F####QRZJ::Y3EGl4'@%FkiAOg#p[##O`gukTfBHagL<LHw%q&OV0##F=6/:chIm0@eCP8X]:kFI%hl8hgO@RcBhS-@Qb$%+m=hPDLg*%K8ln(wcf3/'DW-$.lR?n[nCH-"
13167 "eXOONTJlh:.RYF%3'p6sq:UIMA945&^HFS87@$EP2iG<-lCO$%c`uKGD3rC$x0BL8aFn--`ke%#HMP'vh1/R&O_J9'um,.<tx[@%wsJk&bUT2`0uMv7gg#qp/ij.L56'hl;.s5CUrxjO"
13168 "M7-##.l+Au'A&O:-T72L]P`&=;ctp'XScX*rU.>-XTt,%OVU4)S1+R-#dg0/Nn?Ku1^0f$B*P:Rowwm-`0PKjYDDM'3]d39VZHEl4,.j']Pk-M.h^&:0FACm$maq-&sgw0t7/6(^xtk%"
13169 "LuH88Fj-ekm>GA#_>568x6(OFRl-IZp`&b,_P'$M<Jnq79VsJW/mWS*PUiq76;]/NM_>hLbxfc$mj`,O;&%W2m`Zh:/)Uetw:aJ%]K9h:TcF]u_-Sj9,VK3M.*'&0D[Ca]J9gp8,kAW]"
13170 "%(?A%R$f<->Zts'^kn=-^@c4%-pY6qI%J%1IGxfLU9CP8cbPlXv);C=b),<2mOvP8up,UVf3839acAWAW-W?#ao/^#%KYo8fRULNd2.>%m]UK:n%r$'sw]J;5pAoO_#2mO3n,'=H5(et"
13171 "Hg*`+RLgv>=4U8guD$I%D:W>-r5V*%j*W:Kvej.Lp$<M-SGZ':+Q_k+uvOSLiEo(<aD/K<CCc`'Lx>'?;++O'>()jLR-^u68PHm8ZFWe+ej8h:9r6L*0//c&iH&R8pRbA#Kjm%upV1g:"
13172 "a_#Ur7FuA#(tRh#.Y5K+@?3<-8m0$PEn;J:rh6?I6uG<-`wMU'ircp0LaE_OtlMb&1#6T.#FDKu#1Lw%u%+GM+X'e?YLfjM[VO0MbuFp7;>Q&#WIo)0@F%q7c#4XAXN-U&VB<HFF*qL("
13173 "$/V,;(kXZejWO`<[5?\?ewY(*9=%wDc;,u<'9t3W-(H1th3+G]ucQ]kLs7df($/*JL]@*t7Bu_G3_7mp7<iaQjO@.kLg;x3B0lqp7Hf,^Ze7-##@/c58Mo(3;knp0%)A7?-W+eI'o8)b<"
13174 "nKnw'Ho8C=Y>pqB>0ie&jhZ[?iLR@@_AvA-iQC(=ksRZRVp7`.=+NpBC%rh&3]R:8XDmE5^V8O(x<<aG/1N$#FX$0V5Y6x'aErI3I$7x%E`v<-BY,)%-?Psf*l?%C3.mM(=/M0:JxG'?"
13175 "7WhH%o'a<-80g0NBxoO(GH<dM]n.+%q@jH?f.UsJ2Ggs&4<-e47&Kl+f//9@`b+?.TeN_&B8Ss?v;^Trk;f#YvJkl&w$]>-+k?'(<S:68tq*WoDfZu';mM?8X[ma8W%*`-=;D.(nc7/;"
13176 ")g:T1=^J$&BRV(-lTmNB6xqB[@0*o.erM*<SWF]u2=st-*(6v>^](H.aREZSi,#1:[IXaZFOm<-ui#qUq2$##Ri;u75OK#(RtaW-K-F`S+cF]uN`-KMQ%rP/Xri.LRcB##=YL3BgM/3M"
13177 "D?@f&1'BW-)Ju<L25gl8uhVm1hL$##*8###'A3/LkKW+(^rWX?5W_8g)a(m&K8P>#bmmWCMkk&#TR`C,5d>g)F;t,4:@_l8G/5h4vUd%&%950:VXD'QdWoY-F$BtUwmfe$YqL'8(PWX("
13178 "P?^@Po3$##`MSs?DWBZ/S>+4%>fX,VWv/w'KD`LP5IbH;rTV>n3cEK8U#bX]l-/V+^lj3;vlMb&[5YQ8#pekX9JP3XUC72L,,?+Ni&co7ApnO*5NK,((W-i:$,kp'UDAO(G0Sq7MVjJs"
13179 "bIu)'Z,*[>br5fX^:FPAWr-m2KgL<LUN098kTF&#lvo58=/vjDo;.;)Ka*hLR#/k=rKbxuV`>Q_nN6'8uTGT5g)uLv:873UpTLgH+#FgpH'_o1780Ph8KmxQJ8#H72L4@768@Tm&Q"
13180 "h4CB/5OvmA&,Q&QbUoi$a_%3M01H)4x7I^&KQVgtFnV+;[Pc>[m4k//,]1?#`VY[Jr*3&&slRfLiVZJ:]?=K3Sw=[$=uRB?3xk48@aeg<Z'<$#4H)6,>e0jT6'N#(q%.O=?2S]u*(m<-"
13181 "V8J'(1)G][68hW$5'q[GC&5j`TE?m'esFGNRM)j,ffZ?-qx8;->g4t*:CIP/[Qap7/9'#(1sao7w-.qNUdkJ)tCF&#B^;xGvn2r9FEPFFFcL@.iFNkTve$m%#QvQS8U@)2Z+3K:AKM5i"
13182 "sZ88+dKQ)W6>J%CL<KE>`.d*(B`-n8D9oK<Up]c$X$(,)M8Zt7/[rdkqTgl-0cuGMv'?>-XV1q['-5k'cAZ69e;D_?$ZPP&s^+7])$*$#@QYi9,5P	r+$%CE=68>K8r0=dSC%%(@p7"
13183 ".m7jilQ02'0-VWAg<a/''3u.=4L$Y)6k/K:_[3=&jvL<L0C/2'v:^;-DIBW,B4E68:kZ;%?8(Q8BH=kO65BW?xSG&#@uU,DS*,?.+(o(#1vCS8#CHF>TlGW'b)Tq7VT9q^*^$$.:&N@@"
13184 "$&)WHtPm*5_rO0&e%K&#-30j(E4#'Zb.o/(Tpm$>K'f@[PvFl,hfINTNU6u'0pao7%XUp9]5.>%h`8_=VYbxuel.NTSsJfLacFu3B'lQSu/m6-Oqem8T+oE--$0a/k]uj9EwsG>%veR*"
13185 "hv^BFpQj:K'#SJ,sB-'#](j.Lg92rTw-*n%@/;39rrJF,l#qV%OrtBeC6/,;qB3ebNW[?,Hqj2L.1NP&GjUR=1D8QaS3Up&@*9wP?+lo7b?@%'k4`p0Z$22%K3+iCZj?XJN4Nm&+YF]u"
13186 "@-W$U%VEQ/,,>>#)D<h#`)h0:<Q6909ua+&VU%n2:cG3FJ-%@Bj-DgLr`Hw&HAKjKjseK</xKT*)B,N9X3]krc12t'pgTV(Lv-tL[xg_%=M_q7a^x?7Ubd>#%8cY#YZ?=,`Wdxu/ae&#"
13187 "w6)R89tI#6@s'(6Bf7a&?S=^ZI_kS&ai`&=tE72L_D,;^R)7[$s<Eh#c&)q.MXI%#v9ROa5FZO%sF7q7Nwb&#ptUJ:aqJe$Sl68%.D###EC><?-aF&#RNQv>o8lKN%5/$(vdfq7+ebA#"
13188 "u1p]ovUKW&Y%q]'>$1@-[xfn$7ZTp7mM,G,Ko7a&Gu%G[RMxJs[0MM%wci.LFDK)(<c`Q8N)jEIF*+?P2a8g%)$q]o2aH8C&<SibC/q,(e:v;-b#6[$NtDZ84Je2KNvB#$P5?tQ3nt(0"
13189 "d=j.LQf./Ll33+(;q3L-w=8dX$#WF&uIJ@-bfI>%:_i2B5CsR8&9Z&#=mPEnm0f`<&c)QL5uJ#%u%lJj+D-r;BoFDoS97h5g)E#o:&S4weDF,9^Hoe`h*L+_a*NrLW-1pG_&2UdB8"
13190 "6e%B/:=>)N4xeW.*wft-;$'58-ESqr<b?UI(_%@[P46>#U`'6AQ]m&6/`Z>#S?YY#Vc;r7U2&326d=w&H####?TZ`*4?&.MK?LP8Vxg>$[QXc%QJv92.(Db*B)gb*BM9dM*hJMAo*c&#"
13191 "b0v=Pjer]$gG&JXDf->'StvU7505l9$AFvgYRI^&<^b68?j#q9QX4SM'RO#&sL1IM.rJfLUAj221]d##DW=m83u5;'bYx,*Sl0hL(W;;$doB&O/TQ:(Z^xBdLjL<Lni;''X.`$#8+1GD"
13192 ":k$YUWsbn8ogh6rxZ2Z9]%nd+>V#*8U_72Lh+2Q8Cj0i:6hp&$C/:p(HK>T8Y[gHQ4`4)'$Ab(Nof%V'8hL&#<NEdtg(n'=S1A(Q1/I&4([%dM`,Iu'1:_hL>SfD07&6D<fp8dHM7/g+"
13193 "tlPN9J*rKaPct&?'uBCem^jn%9_K)<,C5K3s=5g&GmJb*[SYq7K;TRLGCsM-$$;S%:Y@r7AK0pprpL<Lrh,q7e/%KWK:50I^+m'vi`3?%Zp+<-d+$L-Sv:@.o19n$s0&39;kn;S%BSq*"
13194 "$3WoJSCLweV[aZ'MQIjO<7;X-X;&+dMLvu#^UsGEC9WEc[X(wI7#2.(F0jV*eZf<-Qv3J-c+J5AlrB#$p(H68LvEA'q3n0#m,[`*8Ft)FcYgEud]CWfm68,(aLA$@EFTgLXoBq/UPlp7"
13195 ":d[/;r_ix=:TF`S5H-b<LI&HY(K=h#)]Lk$K14lVfm:x$H<3^Ql<M`$OhapBnkup'D#L$Pb_`N*g]2e;X/Dtg,bsj&K#2[-:iYr'_wgH)NUIR8a1n#S?Yej'h8^58UbZd+^FKD*T@;6A"
13196 "7aQC[K8d-(v6GI$x:T<&'Gp5Uf>@M.*J:;$-rv29'M]8qMv-tLp,'886iaC=Hb*YJoKJ,(j%K=H`K.v9HggqBIiZu'QvBT.#=)0ukruV&.)3=(^1`o*Pj4<-<aN((^7('#Z0wK#5GX@7"
13197 "u][`*S^43933A4rl][`*O4CgLEl]v$1Q3AeF37dbXk,.)vj#x'd`;qgbQR%FW,2(?LO=s%Sc68%NP'##Aotl8x=BE#j1UD([3$M(]UI2LX3RpKN@;/#f'f/&_mt&F)XdF<9t4)Qa.*kT"
13198 "LwQ'(TTB9.xH'>#MJ+gLq9-##@HuZPN0]u:h7.T..G:;$/Usj(T7`Q8tT72LnYl<-qx8;-HV7Q-&Xdx%1a,hC=0u+HlsV>nuIQL-5<N?)NBS)QN*_I,?&)2'IM%L3I)X((e/dl2&8'<M"
13199 ":^#M*Q+[T.Xri.LYS3v%fF`68h;b-X[/En'CR.q7E)p'/kle2HM,u;^%OKC-N+Ll%F9CF<Nf'^#t2L,;27W:0O@6##U6W7:$rJfLWHj$#)woqBefIZ.PK<b*t7ed;p*_m;4ExK#h@&]>"
13200 "_>@kXQtMacfD.m-VAb8;IReM3$wf0''hra*so568'Ip&vRs849'MRYSp%:t:h5qSgwpEr$B>Q,;s(C#$)`svQuF$##-D,##,g68@2[T;.XSdN9Qe)rpt._K-#5wF)sP'##p#C0c%-Gb%"
13201 "hd+<-j'Ai*x&&HMkT]C'OSl##5RG[JXaHN;d'uA#x._U;.`PU@(Z3dt4r152@:v,'R.Sj'w#0<-;kPI)FfJ&#AYJ&#//)>-k=m=*XnK$>=)72L]0I%>.G690a:$##<,);?;72#?x9+d;"
13202 "^V'9;jY@;)br#q^YQpx:X#Te$Z^'=-=bGhLf:D6&bNwZ9-ZD#n^9HhLMr5G;']d&6'wYmTFmL<LD)F^%[tC'8;+9E#C$g%#5Y>q9wI>P(9mI[>kC-ekLC/R&CH+s'B;K-M6$EB%is00:"
13203 "+A4[7xks.LrNk0&E)wILYF@2L'0Nb$+pv<(2.768/FrY&h$^3i&@+G%JT'<-,v`3;_)I9M^AE]CN?Cl2AZg+%4iTpT3<n-&%H%b<FDj2M<hH=&Eh<2Len$b*aTX=-8QxN)k11IM1c^j%"
13204 "9s<L<NFSo)B?+<-(GxsF,^-Eh@$4dXhN$+#rxK8'je'D7k`e;)2pYwPA'_p9&@^18ml1^[@g4t*[JOa*[=Qp7(qJ_oOL^('7fB&Hq-:sf,sNj8xq^>$U4O]GKx'm9)b@p7YsvK3w^YR-"
13205 "CdQ*:Ir<($u&)#(&?L9Rg3H)4fiEp^iI9O8KnTj,]H?D*r7'M;PwZ9K0E^k&-cpI;.p/6_vwoFMV<->#%Xi.LxVnrU(4&8/P+:hLSKj$#U%]49t'I:rgMi'FL@a:0Y-uA[39',(vbma*"
13206 "hU%<-SRF`Tt:542R_VV$p@[p8DV[A,?1839FWdF<TddF<9Ah-6&9tWoDlh]&1SpGMq>Ti1O*H&#(AL8[_P%.M>v^-))qOT*F5Cq0`Ye%+$B6i:7@0IX<N+T+0MlMBPQ*Vj>SsD<U4JHY"
13207 "8kD2)2fU/M#$e.)T4,_=8hLim[&);?UkK'-x?'(:siIfL<$pFM`i<?%W(mGDHM%>iWP,##P`%/L<eXi:@Z9C.7o=@(pXdAO/NLQ8lPl+HPOQa8wD8=^GlPa8TKI1CjhsCTSLJM'/Wl>-"
13208 "S(qw%sf/@%#B6;/U7K]uZbi^Oc^2n<bhPmUkMw>%t<)'mEVE''n`WnJra$^TKvX5B>;_aSEK',(hwa0:i4G?.Bci.(X[?b*($,=-n<.Q%`(X=?+@Am*Js0&=3bh8K]mL<LoNs'6,'85`"
13209 "0?t/'_U59@]ddF<#LdF<eWdF<OuN/45rY<-L@&#+fm>69=Lb,OcZV/);TTm8VI;?%OtJ<(b4mq7M6:u?KRdF<gR@2L=FNU-<b[(9c/ML3m;Z[$oF3g)GAWqpARc=<ROu7cL5l;-[A]%/"
13210 "+fsd;l#SafT/f*W]0=O'$(Tb<[)*@e775R-:Yob%g*>l*:xP?Yb.5)%w_I?7uk5JC+FS(m#i'k.'a0i)9<7b'fs'59hq$*5Uhv##pi^8+hIEBF`nvo`;'l0.^S1<-wUK2/Coh58KKhLj"
13211 "M=SO*rfO`+qC`W-On.=AJ56>>i2@2LH6A:&5q`?9I3@@'04&p2/LVa*T-4<-i3;M9UvZd+N7>b*eIwg:CC)c<>nO&#<IGe;__.thjZl<%w(Wk2xmp4Q@I#I9,DF]u7-P=.-_:YJ]aS@V"
13212 "?6*C()dOp7:WL,b&3Rg/.cmM9&r^>$(>.Z-I&J(Q0Hd5Q%7Co-b`-c<N(6r@ip+AurK<m86QIth*#v;-OBqi+L7wDE-Ir8K['m+DDSLwK&/.?-V%U_%3:qKNu$_b*B-kp7NaD'QdWQPK"
13213 "Yq[@>P)hI;*_F]u`Rb[.j8_Q/<&>uu+VsH$sM9TA%?)(vmJ80),P7E>)tjD%2L=-t#fK[%`v=Q8<FfNkgg^oIbah*#8/Qt$F&:K*-(N/'+1vMB,u()-a.VUU*#[e%gAAO(S>WlA2);Sa"
13214 ">gXm8YB`1d@K#n]76-a$U,mF<fX]idqd)<3,]J7JmW4`6]uks=4-72L(jEk+:bJ0M^q-8Dm_Z?0olP1C9Sa&H[d&c$ooQUj]Exd*3ZM@-WGW2%s',B-_M%>%Ul:#/'xoFM9QX-$.QN'>"
13215 "[%$Z$uF6pA6Ki2O5:8w*vP1<-1`[G,)-m#>0`P&#eb#.3i)rtB61(o'$?X3B</R90;eZ]%Ncq;-Tl]#F>2Qft^ae_5tKL9MUe9b*sLEQ95C&`=G?@Mj=wh*'3E>=-<)Gt*Iw)'QG:`@I"
13216 "wOf7&]1i'S01B+Ev/Nac#9S;=;YQpg_6U`*kVY39xK,[/6Aj7:'1Bm-_1EYfa1+o&o4hp7KN_Q(OlIo@S%;jVdn0'1<Vc52=u`3^o-n1'g4v58Hj&6_t7$##?M)c<$bgQ_'SY((-xkA#"
13217 "Y(,p'H9rIVY-b,'%bCPF7.J<Up^,(dU1VY*5#WkTU>h19w,WQhLI)3S#f$2(eb,jr*b;3Vw]*7NH%$c4Vs,eD9>XW8?N]o+(*pgC%/72LV-u<Hp,3@e^9UB1J+ak9-TN/mhKPg+AJYd$"
13218 "MlvAF_jCK*.O-^(63adMT->W%iewS8W6m2rtCpo'RS1R84=@paTKt)>=%&1[)*vp'u+x,VrwN;&]kuO9JDbg=pO$J*.jVe;u'm0dr9l,<*wMK*Oe=g8lV_KEBFkO'oU]^=[-792#ok,)"
13219 "i]lR8qQ2oA8wcRCZ^7w/Njh;?.stX?Q1>S1q4Bn$)K1<-rGdO'$Wr.Lc.CG)$/*JL4tNR/,SVO3,aUw'DJN:)Ss;wGn9A32ijw%FL+Z0Fn.U9;reSq)bmI32U==5ALuG&#Vf1398/pVo"
13220 "1*c-(aY168o<`JsSbk-,1N;$>0:OUas(3:8Z972LSfF8eb=c-;>SPw7.6hn3m`9^Xkn(r.qS[0;T%&Qc=+STRxX'q1BNk3&*eu2;&8q$&x>Q#Q7^Tf+6<(d%ZVmj2bDi%.3L2n+4W'$P"
13221 "iDDG)g,r%+?,$@?uou5tSe2aN_AQU*<h`e-GI7)?OK2A.d7_c)?wQ5AS@DL3r#7fSkgl6-++D:'A,uq7SvlB$pcpH'q3n0#_%dY#xCpr-l<F0NR@-##FEV6NTF6##$l84N1w?AO>'IAO"
13222 "URQ##V^Fv-XFbGM7Fl(N<3DhLGF%q.1rC$#:T__&Pi68%0xi_&[qFJ(77j_&JWoF.V735&T,[R*:xFR*K5>>#`bW-?4Ne_&6Ne_&6Ne_&n`kr-#GJcM6X;uM6X;uM(.a..^2TkL%oR(#"
13223 ";u.T%fAr%4tJ8&><1=GHZ_+m9/#H1F^R#SC#*N=BA9(D?v[UiFY>>^8p,KKF.W]L29uLkLlu/+4T<XoIB&hx=T1PcDaB&;HH+-AFr?(m9HZV)FKS8JCw;SD=6[^/DZUL`EUDf]GGlG&>"
13224 "w$)F./^n3+rlo+DB;5sIYGNk+i1t-69Jg--0pao7Sm#K)pdHW&;LuDNH@H>#/X-TI(;P>#,Gc>#0Su>#4`1?#8lC?#<xU?#@.i?#D:%@#HF7@#LRI@#P_[@#Tkn@#Xw*A#]-=A#a9OA#"
13225 "d<F&#*;G##.GY##2Sl##6`($#:l:$#>xL$#B.`$#F:r$#JF.%#NR@%#R_R%#Vke%#Zww%#_-4^Rh%Sflr-k'MS.o?.5/sWel/wpEM0%3'/1)K^f1-d>G21&v(35>V`39V7A4=onx4"
13226 "A1OY5EI0;6Ibgr6M$HS7Q<)58C5w,;WoA*#[%T*#`1g*#d=#+#hI5+#lUG+#pbY+#tnl+#x$),#&1;,#*=M,#.I`,#2Ur,#6b.-#;w[H#iQtA#m^0B#qjBB#uvTB##-hB#'9$C#+E6C#"
13227 "/QHC#3^ZC#7jmC#;v)D#?,<D#C8ND#GDaD#KPsD#O]/E#g1A5#KA*1#gC17#MGd;#8(02#L-d3#rWM4#Hga1#,<w0#T.j<#O#'2#CYN1#qa^:#_4m3#o@/=#eG8=#t8J5#`+78#4uI-#"
13228 "m3B2#SB[8#Q0@8#i[*9#iOn8#1Nm;#^sN9#qh<9#:=x-#P;K2#$%X9#bC+.#Rg;<#mN=.#MTF.#RZO.#2?)4#Y#(/#[)1/#b;L/#dAU/#0Sv;#lY$0#n`-0#sf60#(F24#wrH0#%/e0#"
13229 "TmD<#%JSMFove:CTBEXI:<eh2g)B,3h2^G3i;#d3jD>)4kMYD4lVu`4m`:&5niUA5@(A5BA1]PBB:xlBCC=2CDLXMCEUtiCf&0g2'tN?PGT4CPGT4CPGT4CPGT4CPGT4CPGT4CPGT4CP"
13230 "GT4CPGT4CPGT4CPGT4CPGT4CPGT4CP-qekC`.9kEg^+F$kwViFJTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5o,^<-28ZI'O?;xp"
13231 "O?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xp;7q-#lLYI:xvD=#";
13235 #define NK_CURSOR_DATA_W 90
13236 #define NK_CURSOR_DATA_H 27
13237 NK_GLOBAL const char nk_custom_cursor_data[NK_CURSOR_DATA_W * NK_CURSOR_DATA_H + 1] =
13239 "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX"
13240 "..- -X.....X- X.X - X.X -X.....X - X.....X"
13241 "--- -XXX.XXX- X...X - X...X -X....X - X....X"
13242 "X - X.X - X.....X - X.....X -X...X - X...X"
13243 "XX - X.X -X.......X- X.......X -X..X.X - X.X..X"
13244 "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X"
13245 "X..X - X.X - X.X - X.X -XX X.X - X.X XX"
13246 "X...X - X.X - X.X - XX X.X XX - X.X - X.X "
13247 "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X "
13248 "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X "
13249 "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X "
13250 "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X "
13251 "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X "
13252 "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X "
13253 "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X "
13254 "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X "
13255 "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX "
13256 "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------"
13257 "X.X X..X - -X.......X- X.......X - XX XX - "
13258 "XX X..X - - X.....X - X.....X - X.X X.X - "
13259 " X..X - X...X - X...X - X..X X..X - "
13260 " XX - X.X - X.X - X...XXXXXXXXXXXXX...X - "
13261 "------------ - X - X -X.....................X- "
13262 " ----------------------------------- X...XXXXXXXXXXXXX...X - "
13269 #pragma clang diagnostic pop
13270 #elif defined(__GNUC__) || defined(__GNUG__)
13271 #pragma GCC diagnostic pop
13281 nk_decompress_length(
unsigned char *input)
13283 return (
unsigned int)((input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11]);
13286 nk__match(
unsigned char *data,
unsigned int length)
13289 NK_ASSERT (nk__dout + length <= nk__barrier);
13290 if (nk__dout + length > nk__barrier) { nk__dout += length;
return; }
13291 if (data < nk__barrier4) { nk__dout = nk__barrier+1;
return; }
13292 while (length--) *nk__dout++ = *data++;
13295 nk__lit(
unsigned char *data,
unsigned int length)
13297 NK_ASSERT (nk__dout + length <= nk__barrier);
13298 if (nk__dout + length > nk__barrier) { nk__dout += length;
return; }
13299 if (data < nk__barrier2) { nk__dout = nk__barrier+1;
return; }
13300 NK_MEMCPY(nk__dout, data, length);
13301 nk__dout += length;
13304 nk_decompress_token(
unsigned char *i)
13306 #define nk__in2(x) ((i[x] << 8) + i[(x)+1])
13307 #define nk__in3(x) ((i[x] << 16) + nk__in2((x)+1))
13308 #define nk__in4(x) ((i[x] << 24) + nk__in3((x)+1))
13311 if (*i >= 0x80) nk__match(nk__dout-i[1]-1, (
unsigned int)i[0] - 0x80 + 1), i += 2;
13312 else if (*i >= 0x40) nk__match(nk__dout-(nk__in2(0) - 0x4000 + 1), (
unsigned int)i[2]+1), i += 3;
13313 else nk__lit(i+1, (
unsigned int)i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1);
13315 if (*i >= 0x18) nk__match(nk__dout-(
unsigned int)(nk__in3(0) - 0x180000 + 1), (
unsigned int)i[3]+1), i += 4;
13316 else if (*i >= 0x10) nk__match(nk__dout-(
unsigned int)(nk__in3(0) - 0x100000 + 1), (
unsigned int)nk__in2(3)+1), i += 5;
13317 else if (*i >= 0x08) nk__lit(i+2, (
unsigned int)nk__in2(0) - 0x0800 + 1), i += 2 + (nk__in2(0) - 0x0800 + 1);
13318 else if (*i == 0x07) nk__lit(i+3, (
unsigned int)nk__in2(1) + 1), i += 3 + (nk__in2(1) + 1);
13319 else if (*i == 0x06) nk__match(nk__dout-(
unsigned int)(nk__in3(1)+1), i[4]+1u), i += 5;
13320 else if (*i == 0x04) nk__match(nk__dout-(
unsigned int)(nk__in3(1)+1), (
unsigned int)nk__in2(4)+1u), i += 6;
13325 nk_adler32(
unsigned int adler32,
unsigned char *buffer,
unsigned int buflen)
13327 const unsigned long ADLER_MOD = 65521;
13328 unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16;
13329 unsigned long blocklen, i;
13331 blocklen = buflen % 5552;
13333 for (i=0; i + 7 < blocklen; i += 8) {
13334 s1 += buffer[0]; s2 += s1;
13335 s1 += buffer[1]; s2 += s1;
13336 s1 += buffer[2]; s2 += s1;
13337 s1 += buffer[3]; s2 += s1;
13338 s1 += buffer[4]; s2 += s1;
13339 s1 += buffer[5]; s2 += s1;
13340 s1 += buffer[6]; s2 += s1;
13341 s1 += buffer[7]; s2 += s1;
13344 for (; i < blocklen; ++i) {
13345 s1 += *buffer++; s2 += s1;
13348 s1 %= ADLER_MOD; s2 %= ADLER_MOD;
13349 buflen -= (
unsigned int)blocklen;
13352 return (
unsigned int)(s2 << 16) + (
unsigned int)s1;
13355 nk_decompress(
unsigned char *output,
unsigned char *i,
unsigned int length)
13358 if (nk__in4(0) != 0x57bC0000)
return 0;
13359 if (nk__in4(4) != 0)
return 0;
13360 olen = nk_decompress_length(i);
13362 nk__barrier3 = i+length;
13363 nk__barrier = output + olen;
13364 nk__barrier4 = output;
13369 unsigned char *old_i = i;
13370 i = nk_decompress_token(i);
13372 if (*i == 0x05 && i[1] == 0xfa) {
13373 NK_ASSERT(nk__dout == output + olen);
13374 if (nk__dout != output + olen)
return 0;
13375 if (nk_adler32(1, output, olen) != (
unsigned int) nk__in4(2))
13383 NK_ASSERT(nk__dout <= output + olen);
13384 if (nk__dout > output + olen)
13389 nk_decode_85_byte(
char c)
13391 return (
unsigned int)((c >=
'\\') ? c-36 : c-35);
13394 nk_decode_85(
unsigned char* dst,
const unsigned char* src)
13399 nk_decode_85_byte((
char)src[0]) +
13400 85 * (nk_decode_85_byte((
char)src[1]) +
13401 85 * (nk_decode_85_byte((
char)src[2]) +
13402 85 * (nk_decode_85_byte((
char)src[3]) +
13403 85 * nk_decode_85_byte((
char)src[4]))));
13406 dst[0] = (
unsigned char)((tmp >> 0) & 0xFF);
13407 dst[1] = (
unsigned char)((tmp >> 8) & 0xFF);
13408 dst[2] = (
unsigned char)((tmp >> 16) & 0xFF);
13409 dst[3] = (
unsigned char)((tmp >> 24) & 0xFF);
13421 NK_API struct nk_font_config
13422 nk_font_config(float pixel_height)
13424 struct nk_font_config cfg;
13428 cfg.ttf_data_owned_by_atlas = 0;
13429 cfg.size = pixel_height;
13430 cfg.oversample_h = 3;
13431 cfg.oversample_v = 1;
13432 cfg.pixel_snap = 0;
13433 cfg.coord_type = NK_COORD_UV;
13435 cfg.range = nk_font_default_glyph_ranges();
13436 cfg.merge_mode = 0;
13437 cfg.fallback_glyph =
'?';
13442 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
13444 nk_font_atlas_init_default(
struct nk_font_atlas *atlas)
13447 if (!atlas)
return;
13449 atlas->temporary.userdata.ptr = 0;
13450 atlas->temporary.alloc = nk_malloc;
13451 atlas->temporary.free = nk_mfree;
13452 atlas->permanent.userdata.ptr = 0;
13453 atlas->permanent.alloc = nk_malloc;
13454 atlas->permanent.free = nk_mfree;
13458 nk_font_atlas_init(
struct nk_font_atlas *atlas,
struct nk_allocator *alloc)
13462 if (!atlas || !alloc)
return;
13464 atlas->permanent = *alloc;
13465 atlas->temporary = *alloc;
13468 nk_font_atlas_init_custom(
struct nk_font_atlas *atlas,
13472 NK_ASSERT(permanent);
13473 NK_ASSERT(temporary);
13474 if (!atlas || !permanent || !temporary)
return;
13476 atlas->permanent = *permanent;
13477 atlas->temporary = *temporary;
13480 nk_font_atlas_begin(
struct nk_font_atlas *atlas)
13483 NK_ASSERT(atlas->temporary.alloc && atlas->temporary.free);
13484 NK_ASSERT(atlas->permanent.alloc && atlas->permanent.free);
13485 if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free ||
13486 !atlas->temporary.alloc || !atlas->temporary.free)
return;
13487 if (atlas->glyphs) {
13488 atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
13491 if (atlas->pixel) {
13492 atlas->permanent.free(atlas->permanent.userdata, atlas->pixel);
13497 nk_font_atlas_add(
struct nk_font_atlas *atlas,
const struct nk_font_config *config)
13499 struct nk_font *font = 0;
13500 struct nk_font_config *cfg;
13503 NK_ASSERT(atlas->permanent.alloc);
13504 NK_ASSERT(atlas->permanent.free);
13505 NK_ASSERT(atlas->temporary.alloc);
13506 NK_ASSERT(atlas->temporary.free);
13509 NK_ASSERT(config->ttf_blob);
13510 NK_ASSERT(config->ttf_size);
13511 NK_ASSERT(config->size > 0.0f);
13513 if (!atlas || !config || !config->ttf_blob || !config->ttf_size || config->size <= 0.0f||
13514 !atlas->permanent.alloc || !atlas->permanent.free ||
13515 !atlas->temporary.alloc || !atlas->temporary.free)
13519 cfg = (
struct nk_font_config*)
13520 atlas->permanent.alloc(atlas->permanent.userdata,0,
sizeof(
struct nk_font_config));
13521 NK_MEMCPY(cfg, config,
sizeof(*config));
13525 if (!config->merge_mode) {
13527 if (!atlas->config) {
13528 atlas->config = cfg;
13531 struct nk_font_config *i = atlas->config;
13532 while (i->next) i = i->next;
13537 font = (
struct nk_font*)
13538 atlas->permanent.alloc(atlas->permanent.userdata,0,
sizeof(
struct nk_font));
13540 nk_zero(font,
sizeof(*font));
13541 if (!font)
return 0;
13542 font->config = cfg;
13545 if (!atlas->fonts) {
13546 atlas->fonts = font;
13549 struct nk_font *i = atlas->fonts;
13550 while (i->next) i = i->next;
13554 cfg->font = &font->info;
13557 struct nk_font *f = 0;
13558 struct nk_font_config *c = 0;
13559 NK_ASSERT(atlas->font_num);
13562 cfg->font = &f->info;
13570 if (!config->ttf_data_owned_by_atlas) {
13571 cfg->ttf_blob = atlas->permanent.alloc(atlas->permanent.userdata,0, cfg->ttf_size);
13572 NK_ASSERT(cfg->ttf_blob);
13573 if (!cfg->ttf_blob) {
13577 NK_MEMCPY(cfg->ttf_blob, config->ttf_blob, cfg->ttf_size);
13578 cfg->ttf_data_owned_by_atlas = 1;
13584 nk_font_atlas_add_from_memory(
struct nk_font_atlas *atlas,
void *memory,
13585 nk_size size,
float height,
const struct nk_font_config *config)
13587 struct nk_font_config cfg;
13592 NK_ASSERT(atlas->temporary.alloc);
13593 NK_ASSERT(atlas->temporary.free);
13594 NK_ASSERT(atlas->permanent.alloc);
13595 NK_ASSERT(atlas->permanent.free);
13596 if (!atlas || !atlas->temporary.alloc || !atlas->temporary.free || !memory || !
size ||
13597 !atlas->permanent.alloc || !atlas->permanent.free)
13600 cfg = (config) ? *config: nk_font_config(height);
13601 cfg.ttf_blob = memory;
13602 cfg.ttf_size =
size;
13604 cfg.ttf_data_owned_by_atlas = 0;
13605 return nk_font_atlas_add(atlas, &cfg);
13607 #ifdef NK_INCLUDE_STANDARD_IO
13609 nk_font_atlas_add_from_file(
struct nk_font_atlas *atlas,
const char *file_path,
13610 float height,
const struct nk_font_config *config)
13614 struct nk_font_config cfg;
13617 NK_ASSERT(atlas->temporary.alloc);
13618 NK_ASSERT(atlas->temporary.free);
13619 NK_ASSERT(atlas->permanent.alloc);
13620 NK_ASSERT(atlas->permanent.free);
13622 if (!atlas || !file_path)
return 0;
13623 memory = nk_file_load(file_path, &
size, &atlas->permanent);
13624 if (!memory)
return 0;
13626 cfg = (config) ? *config: nk_font_config(height);
13627 cfg.ttf_blob = memory;
13628 cfg.ttf_size =
size;
13630 cfg.ttf_data_owned_by_atlas = 1;
13631 return nk_font_atlas_add(atlas, &cfg);
13635 nk_font_atlas_add_compressed(
struct nk_font_atlas *atlas,
13636 void *compressed_data,
nk_size compressed_size,
float height,
13637 const struct nk_font_config *config)
13639 unsigned int decompressed_size;
13640 void *decompressed_data;
13641 struct nk_font_config cfg;
13644 NK_ASSERT(atlas->temporary.alloc);
13645 NK_ASSERT(atlas->temporary.free);
13646 NK_ASSERT(atlas->permanent.alloc);
13647 NK_ASSERT(atlas->permanent.free);
13649 NK_ASSERT(compressed_data);
13650 NK_ASSERT(compressed_size);
13651 if (!atlas || !compressed_data || !atlas->temporary.alloc || !atlas->temporary.free ||
13652 !atlas->permanent.alloc || !atlas->permanent.free)
13655 decompressed_size = nk_decompress_length((
unsigned char*)compressed_data);
13656 decompressed_data = atlas->permanent.alloc(atlas->permanent.userdata,0,decompressed_size);
13657 NK_ASSERT(decompressed_data);
13658 if (!decompressed_data)
return 0;
13659 nk_decompress((
unsigned char*)decompressed_data, (
unsigned char*)compressed_data,
13660 (
unsigned int)compressed_size);
13662 cfg = (config) ? *config: nk_font_config(height);
13663 cfg.ttf_blob = decompressed_data;
13664 cfg.ttf_size = decompressed_size;
13666 cfg.ttf_data_owned_by_atlas = 1;
13667 return nk_font_atlas_add(atlas, &cfg);
13670 nk_font_atlas_add_compressed_base85(
struct nk_font_atlas *atlas,
13671 const char *data_base85,
float height,
const struct nk_font_config *config)
13673 int compressed_size;
13674 void *compressed_data;
13675 struct nk_font *font;
13678 NK_ASSERT(atlas->temporary.alloc);
13679 NK_ASSERT(atlas->temporary.free);
13680 NK_ASSERT(atlas->permanent.alloc);
13681 NK_ASSERT(atlas->permanent.free);
13683 NK_ASSERT(data_base85);
13684 if (!atlas || !data_base85 || !atlas->temporary.alloc || !atlas->temporary.free ||
13685 !atlas->permanent.alloc || !atlas->permanent.free)
13688 compressed_size = (((int)
nk_strlen(data_base85) + 4) / 5) * 4;
13689 compressed_data = atlas->temporary.alloc(atlas->temporary.userdata,0, (
nk_size)compressed_size);
13690 NK_ASSERT(compressed_data);
13691 if (!compressed_data)
return 0;
13692 nk_decode_85((
unsigned char*)compressed_data, (
const unsigned char*)data_base85);
13693 font = nk_font_atlas_add_compressed(atlas, compressed_data,
13694 (
nk_size)compressed_size, height, config);
13695 atlas->temporary.free(atlas->temporary.userdata, compressed_data);
13699 #ifdef NK_INCLUDE_DEFAULT_FONT
13701 nk_font_atlas_add_default(
struct nk_font_atlas *atlas,
13702 float pixel_height,
const struct nk_font_config *config)
13705 NK_ASSERT(atlas->temporary.alloc);
13706 NK_ASSERT(atlas->temporary.free);
13707 NK_ASSERT(atlas->permanent.alloc);
13708 NK_ASSERT(atlas->permanent.free);
13709 return nk_font_atlas_add_compressed_base85(atlas,
13710 nk_proggy_clean_ttf_compressed_data_base85, pixel_height, config);
13714 nk_font_atlas_bake(
struct nk_font_atlas *atlas,
int *width,
int *height,
13715 enum nk_font_atlas_format fmt)
13720 struct nk_font *font_iter;
13721 struct nk_font_baker *baker;
13724 NK_ASSERT(atlas->temporary.alloc);
13725 NK_ASSERT(atlas->temporary.free);
13726 NK_ASSERT(atlas->permanent.alloc);
13727 NK_ASSERT(atlas->permanent.free);
13731 if (!atlas || !width || !height ||
13732 !atlas->temporary.alloc || !atlas->temporary.free ||
13733 !atlas->permanent.alloc || !atlas->permanent.free)
13736 #ifdef NK_INCLUDE_DEFAULT_FONT
13738 if (!atlas->font_num)
13739 atlas->default_font = nk_font_atlas_add_default(atlas, 13.0f, 0);
13741 NK_ASSERT(atlas->font_num);
13742 if (!atlas->font_num)
return 0;
13745 nk_font_baker_memory(&tmp_size, &atlas->glyph_count, atlas->config, atlas->font_num);
13746 tmp = atlas->temporary.alloc(atlas->temporary.userdata,0, tmp_size);
13748 if (!tmp)
goto failed;
13751 baker = nk_font_baker(tmp, atlas->glyph_count, atlas->font_num, &atlas->temporary);
13752 atlas->glyphs = (
struct nk_font_glyph*)atlas->permanent.alloc(
13753 atlas->permanent.userdata,0,
sizeof(
struct nk_font_glyph)*(
nk_size)atlas->glyph_count);
13754 NK_ASSERT(atlas->glyphs);
13755 if (!atlas->glyphs)
13759 atlas->custom.w = (NK_CURSOR_DATA_W*2)+1;
13760 atlas->custom.h = NK_CURSOR_DATA_H + 1;
13761 if (!nk_font_bake_pack(baker, &img_size, width, height, &atlas->custom,
13762 atlas->config, atlas->font_num, &atlas->temporary))
13766 atlas->pixel = atlas->temporary.alloc(atlas->temporary.userdata,0, img_size);
13767 NK_ASSERT(atlas->pixel);
13772 nk_font_bake(baker, atlas->pixel, *width, *height,
13773 atlas->glyphs, atlas->glyph_count, atlas->config, atlas->font_num);
13774 nk_font_bake_custom_data(atlas->pixel, *width, *height, atlas->custom,
13775 nk_custom_cursor_data, NK_CURSOR_DATA_W, NK_CURSOR_DATA_H,
'.',
'X');
13777 if (fmt == NK_FONT_ATLAS_RGBA32) {
13779 void *img_rgba = atlas->temporary.alloc(atlas->temporary.userdata,0,
13780 (
nk_size)(*width * *height * 4));
13781 NK_ASSERT(img_rgba);
13782 if (!img_rgba)
goto failed;
13783 nk_font_bake_convert(img_rgba, *width, *height, atlas->pixel);
13784 atlas->temporary.free(atlas->temporary.userdata, atlas->pixel);
13785 atlas->pixel = img_rgba;
13787 atlas->tex_width = *width;
13788 atlas->tex_height = *height;
13791 for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) {
13792 struct nk_font *font = font_iter;
13793 struct nk_font_config *config = font->config;
13794 nk_font_init(font, config->size, config->fallback_glyph, atlas->glyphs,
13801 {{ 0, 3}, {12,19}, { 0, 0}},
13802 {{13, 0}, { 7,16}, { 4, 8}},
13803 {{31, 0}, {23,23}, {11,11}},
13804 {{21, 0}, { 9, 23}, { 5,11}},
13805 {{55,18}, {23, 9}, {11, 5}},
13806 {{73, 0}, {17,17}, { 9, 9}},
13807 {{55, 0}, {17,17}, { 9, 9}}
13810 struct nk_cursor *cursor = &atlas->cursors[i];
13811 cursor->
img.
w = (
unsigned short)*width;
13812 cursor->
img.
h = (
unsigned short)*height;
13813 cursor->
img.
region[0] = (
unsigned short)(atlas->custom.x + nk_cursor_data[i][0].x);
13814 cursor->
img.
region[1] = (
unsigned short)(atlas->custom.y + nk_cursor_data[i][0].y);
13815 cursor->
img.
region[2] = (
unsigned short)nk_cursor_data[i][1].x;
13816 cursor->
img.
region[3] = (
unsigned short)nk_cursor_data[i][1].y;
13817 cursor->size = nk_cursor_data[i][1];
13818 cursor->
offset = nk_cursor_data[i][2];
13821 atlas->temporary.free(atlas->temporary.userdata, tmp);
13822 return atlas->pixel;
13826 if (tmp) atlas->temporary.free(atlas->temporary.userdata, tmp);
13827 if (atlas->glyphs) {
13828 atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
13831 if (atlas->pixel) {
13832 atlas->temporary.free(atlas->temporary.userdata, atlas->pixel);
13838 nk_font_atlas_end(
struct nk_font_atlas *atlas,
nk_handle texture,
13842 struct nk_font *font_iter;
13846 null->texture = texture;
13847 null->uv =
nk_vec2(0.5f,0.5f);
13850 null->texture = texture;
13851 null->uv.x = (atlas->custom.x + 0.5f)/(
float)atlas->tex_width;
13852 null->uv.y = (atlas->custom.y + 0.5f)/(
float)atlas->tex_height;
13854 for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) {
13855 font_iter->texture = texture;
13856 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
13857 font_iter->handle.texture = texture;
13861 atlas->cursors[i].img.handle = texture;
13863 atlas->temporary.free(atlas->temporary.userdata, atlas->pixel);
13865 atlas->tex_width = 0;
13866 atlas->tex_height = 0;
13867 atlas->custom.x = 0;
13868 atlas->custom.y = 0;
13869 atlas->custom.w = 0;
13870 atlas->custom.h = 0;
13873 nk_font_atlas_cleanup(
struct nk_font_atlas *atlas)
13876 NK_ASSERT(atlas->temporary.alloc);
13877 NK_ASSERT(atlas->temporary.free);
13878 NK_ASSERT(atlas->permanent.alloc);
13879 NK_ASSERT(atlas->permanent.free);
13880 if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free)
return;
13881 if (atlas->config) {
13882 struct nk_font_config *iter;
13883 for (iter = atlas->config; iter; iter = iter->next) {
13884 struct nk_font_config *i;
13885 for (i = iter->n; i != iter; i = i->n) {
13886 atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob);
13889 atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob);
13890 iter->ttf_blob = 0;
13895 nk_font_atlas_clear(
struct nk_font_atlas *atlas)
13898 NK_ASSERT(atlas->temporary.alloc);
13899 NK_ASSERT(atlas->temporary.free);
13900 NK_ASSERT(atlas->permanent.alloc);
13901 NK_ASSERT(atlas->permanent.free);
13902 if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free)
return;
13904 if (atlas->config) {
13905 struct nk_font_config *iter, *next;
13906 for (iter = atlas->config; iter; iter = next) {
13907 struct nk_font_config *i, *n;
13908 for (i = iter->n; i != iter; i = n) {
13911 atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob);
13912 atlas->permanent.free(atlas->permanent.userdata, i);
13916 atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob);
13917 atlas->permanent.free(atlas->permanent.userdata, iter);
13921 if (atlas->fonts) {
13922 struct nk_font *iter, *next;
13923 for (iter = atlas->fonts; iter; iter = next) {
13925 atlas->permanent.free(atlas->permanent.userdata, iter);
13930 atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
13998 #ifdef NK_KEYSTATE_BASED_INPUT
14203 #define NK_COLOR_MAP(NK_COLOR)\
14204 NK_COLOR(NK_COLOR_TEXT, 175,175,175,255) \
14205 NK_COLOR(NK_COLOR_WINDOW, 45, 45, 45, 255) \
14206 NK_COLOR(NK_COLOR_HEADER, 40, 40, 40, 255) \
14207 NK_COLOR(NK_COLOR_BORDER, 65, 65, 65, 255) \
14208 NK_COLOR(NK_COLOR_BUTTON, 50, 50, 50, 255) \
14209 NK_COLOR(NK_COLOR_BUTTON_HOVER, 40, 40, 40, 255) \
14210 NK_COLOR(NK_COLOR_BUTTON_ACTIVE, 35, 35, 35, 255) \
14211 NK_COLOR(NK_COLOR_TOGGLE, 100,100,100,255) \
14212 NK_COLOR(NK_COLOR_TOGGLE_HOVER, 120,120,120,255) \
14213 NK_COLOR(NK_COLOR_TOGGLE_CURSOR, 45, 45, 45, 255) \
14214 NK_COLOR(NK_COLOR_SELECT, 45, 45, 45, 255) \
14215 NK_COLOR(NK_COLOR_SELECT_ACTIVE, 35, 35, 35,255) \
14216 NK_COLOR(NK_COLOR_SLIDER, 38, 38, 38, 255) \
14217 NK_COLOR(NK_COLOR_SLIDER_CURSOR, 100,100,100,255) \
14218 NK_COLOR(NK_COLOR_SLIDER_CURSOR_HOVER, 120,120,120,255) \
14219 NK_COLOR(NK_COLOR_SLIDER_CURSOR_ACTIVE, 150,150,150,255) \
14220 NK_COLOR(NK_COLOR_PROPERTY, 38, 38, 38, 255) \
14221 NK_COLOR(NK_COLOR_EDIT, 38, 38, 38, 255) \
14222 NK_COLOR(NK_COLOR_EDIT_CURSOR, 175,175,175,255) \
14223 NK_COLOR(NK_COLOR_COMBO, 45, 45, 45, 255) \
14224 NK_COLOR(NK_COLOR_CHART, 120,120,120,255) \
14225 NK_COLOR(NK_COLOR_CHART_COLOR, 45, 45, 45, 255) \
14226 NK_COLOR(NK_COLOR_CHART_COLOR_HIGHLIGHT, 255, 0, 0, 255) \
14227 NK_COLOR(NK_COLOR_SCROLLBAR, 40, 40, 40, 255) \
14228 NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR, 100,100,100,255) \
14229 NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_HOVER, 120,120,120,255) \
14230 NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_ACTIVE, 150,150,150,255) \
14231 NK_COLOR(NK_COLOR_TAB_HEADER, 40, 40, 40,255)
14235 #define NK_COLOR(a,b,c,d,e) {b,c,d,e},
14236 NK_COLOR_MAP(NK_COLOR)
14240 #define NK_COLOR(a,b,c,d,e) #a,
14241 NK_COLOR_MAP(NK_COLOR)
14248 return nk_color_names[c];
14255 i.data.image = img;
14263 i.data.color = col;
14271 i.data.color =
nk_rgba(0,0,0,0);
14294 style = &ctx->
style;
14295 table = (!table) ? nk_default_color_style: table;
14298 text = &style->
text;
14303 button = &style->
button;
14383 toggle = &style->
option;
14425 slider = &style->
slider;
14536 edit = &style->
edit;
14574 property->padding =
nk_vec2(4,4);
14575 property->border = 1;
14576 property->rounding = 10;
14577 property->draw_begin = 0;
14578 property->draw_end = 0;
14625 chart = &style->
chart;
14636 combo = &style->
combo;
14796 win->rounding = 0.0f;
14801 win->combo_border = 1.0f;
14802 win->contextual_border = 1.0f;
14803 win->menu_border = 1.0f;
14804 win->group_border = 1.0f;
14805 win->tooltip_border = 1.0f;
14806 win->popup_border = 1.0f;
14807 win->border = 2.0f;
14808 win->min_row_height_padding = 8;
14825 style = &ctx->
style;
14834 struct nk_config_stack_user_font *font_stack;
14835 struct nk_config_stack_user_font_element *element;
14838 if (!ctx)
return 0;
14841 NK_ASSERT(font_stack->head < (
int)
NK_LEN(font_stack->elements));
14842 if (font_stack->head >= (
int)
NK_LEN(font_stack->elements))
14845 element = &font_stack->elements[font_stack->head++];
14854 struct nk_config_stack_user_font *font_stack;
14855 struct nk_config_stack_user_font_element *element;
14858 if (!ctx)
return 0;
14861 NK_ASSERT(font_stack->head > 0);
14862 if (font_stack->head < 1)
14865 element = &font_stack->elements[--font_stack->head];
14866 *element->address = element->old_value;
14869 #define NK_STYLE_PUSH_IMPLEMENATION(prefix, type, stack) \
14870 nk_style_push_##type(struct nk_context *ctx, prefix##_##type *address, prefix##_##type value)\
14872 struct nk_config_stack_##type * type_stack;\
14873 struct nk_config_stack_##type##_element *element;\
14875 if (!ctx) return 0;\
14876 type_stack = &ctx->stacks.stack;\
14877 NK_ASSERT(type_stack->head < (int)NK_LEN(type_stack->elements));\
14878 if (type_stack->head >= (int)NK_LEN(type_stack->elements))\
14880 element = &type_stack->elements[type_stack->head++];\
14881 element->address = address;\
14882 element->old_value = *address;\
14886 #define NK_STYLE_POP_IMPLEMENATION(type, stack) \
14887 nk_style_pop_##type(struct nk_context *ctx)\
14889 struct nk_config_stack_##type *type_stack;\
14890 struct nk_config_stack_##type##_element *element;\
14892 if (!ctx) return 0;\
14893 type_stack = &ctx->stacks.stack;\
14894 NK_ASSERT(type_stack->head > 0);\
14895 if (type_stack->head < 1)\
14897 element = &type_stack->elements[--type_stack->head];\
14898 *element->address = element->old_value;\
14901 NK_API int NK_STYLE_PUSH_IMPLEMENATION(
struct nk, style_item, style_items)
14902 NK_API int NK_STYLE_PUSH_IMPLEMENATION(nk,
float, floats)
14903 NK_API int NK_STYLE_PUSH_IMPLEMENATION(
struct nk, vec2, vectors)
14904 NK_API int NK_STYLE_PUSH_IMPLEMENATION(nk,flags, flags)
14905 NK_API int NK_STYLE_PUSH_IMPLEMENATION(
struct nk,color, colors)
14907 NK_API int NK_STYLE_POP_IMPLEMENATION(style_item, style_items)
14908 NK_API int NK_STYLE_POP_IMPLEMENATION(
float,floats)
14909 NK_API int NK_STYLE_POP_IMPLEMENATION(vec2, vectors)
14910 NK_API int NK_STYLE_POP_IMPLEMENATION(flags,flags)
14911 NK_API int NK_STYLE_POP_IMPLEMENATION(color,colors)
14918 if (!ctx)
return 0;
14919 style = &ctx->
style;
14943 style = &ctx->
style;
14953 style = &ctx->
style;
14977 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
14978 nk_draw_list_init(&ctx->draw_list);
14981 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
14986 alloc.userdata.ptr = 0;
14987 alloc.alloc = nk_malloc;
14988 alloc.free = nk_mfree;
14997 if (!memory)
return 0;
14998 nk_setup(ctx, font);
15009 if (!cmds || !pool)
return 0;
15011 nk_setup(ctx, font);
15019 nk_pool_init(&ctx->
pool,
alloc, NK_POOL_DEFAULT_CAPACITY);
15029 if (!
alloc)
return 0;
15030 nk_setup(ctx, font);
15032 nk_pool_init(&ctx->
pool,
alloc, NK_POOL_DEFAULT_CAPACITY);
15036 #ifdef NK_INCLUDE_COMMAND_USERDATA
15041 ctx->userdata = handle;
15053 nk_pool_free(&ctx->
pool);
15092 iter->
seq == ctx->
seq) {
15109 nk_free_window(ctx, iter->
popup.
win);
15116 if (it->
seq != ctx->
seq) {
15117 nk_remove_table(iter, it);
15119 nk_free_table(ctx, it);
15127 nk_remove_window(ctx, iter);
15128 nk_free_window(ctx, iter);
15130 }
else iter = iter->
next;
15139 if (!ctx || !buffer)
return;
15143 buffer->
clip = nk_null_rect;
15158 if (!ctx || !
win)
return;
15174 if (!ctx || !
win)
return;
15185 if (!ctx || !buffer)
return;
15197 if (!ctx || !
win)
return;
15204 parent_last->
next = buf->
end;
15220 nk_start_buffer(ctx, &ctx->
overlay);
15224 mouse_bounds.w = cursor->size.x;
15225 mouse_bounds.h = cursor->size.y;
15228 nk_finish_buffer(ctx, &ctx->
overlay);
15274 if (!ctx)
return 0;
15275 if (!ctx->
count)
return 0;
15286 if (!iter)
return 0;
15296 if (!ctx || !cmd || !ctx->
count)
return 0;
15315 unsigned int capacity)
15317 nk_zero(pool,
sizeof(*pool));
15318 pool->
alloc = *alloc;
15324 nk_pool_free(
struct nk_pool *pool)
15338 nk_zero(pool,
sizeof(*pool));
15347 nk_pool_alloc(
struct nk_pool *pool)
15353 NK_ASSERT(pool->
pages);
15354 if (!pool->
pages)
return 0;
15361 page->next = pool->
pages;
15362 pool->
pages = page;
15378 nk_create_page_element(
struct nk_context *ctx)
15387 elem = nk_pool_alloc(&ctx->
pool);
15389 if (!elem)
return 0;
15396 if (!elem)
return 0;
15404 nk_link_page_element_into_freelist(
struct nk_context *ctx,
15420 nk_link_page_element_into_freelist(ctx, elem);
15424 {
void *elem_end = (
void*)(elem + 1);
15426 if (elem_end == buffer_end)
15428 else nk_link_page_element_into_freelist(ctx, elem);}
15444 elem = nk_create_page_element(ctx);
15445 if (!elem)
return 0;
15454 nk_free_page_element(ctx, pe);
15492 if (!
win || !ctx)
return 0;
15494 struct nk_table *tbl = nk_create_table(ctx);
15496 if (!tbl)
return 0;
15497 nk_push_table(
win, tbl);
15509 unsigned int i = 0;
15511 for (i = 0; i <
size; ++i) {
15512 if (iter->
keys[i] == name) {
15514 return &iter->
values[i];
15535 elem = nk_create_page_element(ctx);
15536 if (!elem)
return 0;
15545 nk_free_page_element(ctx, pe);
15548 nk_panel_has_header(
nk_flags flags,
const char *title)
15595 case NK_PANEL_MENU:
return style->window.menu_border_color;
15618 struct nk_vec2 scrollbar_size;
15619 struct nk_vec2 panel_padding;
15632 style = &ctx->
style;
15633 font = style->
font;
15638 #ifdef NK_INCLUDE_COMMAND_USERDATA
15643 panel_padding = nk_panel_get_padding(style, panel_type);
15647 int left_mouse_down;
15648 int left_mouse_clicked;
15649 int left_mouse_click_in_cursor;
15656 if (nk_panel_has_header(
win->
flags, title)) {
15659 }
else header.h = panel_padding.y;
15666 if (left_mouse_down && left_mouse_click_in_cursor && !left_mouse_clicked) {
15676 layout->
type = panel_type;
15679 layout->
bounds.
x += panel_padding.x;
15680 layout->
bounds.
w -= 2*panel_padding.x;
15682 layout->
border = nk_panel_get_border(style,
win->
flags, panel_type);
15684 }
else layout->
border = 0;
15699 layout->
bounds.
w -= scrollbar_size.x;
15700 if (!nk_panel_is_nonblock(panel_type)) {
15708 if (nk_panel_has_header(
win->
flags, title))
15723 layout->
bounds.
y += header.h;
15724 layout->
bounds.
h -= header.h;
15725 layout->
at_y += header.h;
15742 text.background =
nk_rgba(0,0,0,0);
15745 text.background = background->
data.
color;
15753 button.w = button.h;
15764 if (nk_do_button_symbol(&ws, &
win->
buffer, button,
15777 button.x = (header.w + header.x) - button.w;
15784 button.x = header.x;
15797 struct nk_rect label = {0,0,0,0};
15806 label.
w =
NK_CLAMP(0, label.
w, header.x + header.w - label.
x);
15807 nk_widget_text(out, label,(
const char*)title, text_len, &text,
NK_TEXT_LEFT, font);}
15828 layout->
clip = clip;}
15840 struct nk_vec2 scrollbar_size;
15841 struct nk_vec2 panel_padding;
15850 layout = window->
layout;
15851 style = &ctx->
style;
15854 if (!nk_panel_is_sub(layout->
type))
15859 panel_padding = nk_panel_get_padding(style, layout->
type);
15873 empty_space.x = window->
bounds.
x;
15874 empty_space.y = layout->
bounds.
y;
15875 empty_space.h = panel_padding.y;
15876 empty_space.w = window->
bounds.
w;
15880 empty_space.x = window->
bounds.
x;
15881 empty_space.y = layout->
bounds.
y;
15882 empty_space.w = panel_padding.x + layout->
border;
15883 empty_space.h = layout->
bounds.
h;
15888 empty_space.y = layout->
bounds.
y;
15889 empty_space.w = panel_padding.x + layout->
border;
15890 empty_space.h = layout->
bounds.
h;
15892 empty_space.w += scrollbar_size.x;
15897 empty_space.x = window->
bounds.
x;
15899 empty_space.w = window->
bounds.
w;
15911 int scroll_has_scrolling;
15912 float scroll_target;
15913 float scroll_offset;
15918 if (nk_panel_is_sub(layout->
type))
15921 struct nk_window *root_window = window;
15923 while (root_panel->
parent)
15924 root_panel = root_panel->
parent;
15925 while (root_window->
parent)
15926 root_window = root_window->
parent;
15929 scroll_has_scrolling = 0;
15937 root_panel = window->
layout;
15938 while (root_panel->
parent) {
15940 root_panel = root_panel->
parent;
15943 scroll_has_scrolling =
nk_true;
15946 }
else if (!nk_panel_is_sub(layout->
type)) {
15952 }
else scroll_has_scrolling =
nk_false;
15957 scroll.x = layout->
bounds.
x + layout->
bounds.
w + panel_padding.x;
15959 scroll.w = scrollbar_size.x;
15962 scroll_offset = (float)*layout->
offset_y;
15963 scroll_step = scroll.h * 0.10f;
15964 scroll_inc = scroll.h * 0.01f;
15965 scroll_target = (
float)(int)(layout->
at_y - scroll.y);
15966 scroll_offset = nk_do_scrollbarv(&state, out, scroll, scroll_has_scrolling,
15967 scroll_offset, scroll_target, scroll_step, scroll_inc,
15970 if (in && scroll_has_scrolling)
15979 scroll.h = scrollbar_size.y;
15981 scroll_offset = (float)*layout->
offset_x;
15982 scroll_target = (
float)(int)(layout->
max_x - scroll.x);
15983 scroll_step = layout->
max_x * 0.05f;
15984 scroll_inc = layout->
max_x * 0.005f;
15985 scroll_offset = nk_do_scrollbarh(&state, out, scroll, scroll_has_scrolling,
15986 scroll_offset, scroll_target, scroll_step, scroll_inc,
15997 if ((!has_input && is_window_hovered) || (!is_window_hovered && !any_item_active))
16005 struct nk_color border_color = nk_panel_get_border_color(style, layout->
type);
16012 b.
h = padding_y - window->
bounds.
y;
16021 scaler.
w = scrollbar_size.x;
16022 scaler.h = scrollbar_size.y;
16025 scaler.x = layout->
bounds.
x - panel_padding.x * 0.5f;
16026 else scaler.x = layout->
bounds.
x + layout->
bounds.
w + panel_padding.x;
16028 scaler.x -= scaler.w;
16037 scaler.y + scaler.h, scaler.x + scaler.w,
16038 scaler.y + scaler.h, item->
data.
color);
16041 scaler.y + scaler.h, scaler.x, scaler.y + scaler.h, item->
data.
color);
16052 if (left_mouse_down && left_mouse_click_in_scaler) {
16055 delta_x = -delta_x;
16059 if (window->
bounds.
w + delta_x >= window_size.
x) {
16060 if ((delta_x < 0) || (delta_x > 0 && in->
mouse.
pos.
x >= scaler.x)) {
16080 if (!nk_panel_is_sub(layout->
type)) {
16083 nk_command_buffer_reset(&window->
buffer);
16085 else nk_finish(ctx, window);
16107 nk_zero(&window->
edit,
sizeof(window->
edit));
16140 elem = nk_create_page_element(ctx);
16141 if (!elem)
return 0;
16160 nk_remove_table(
win, it);
16161 nk_free_table(ctx, it);
16170 nk_free_page_element(ctx, pe);}
16178 NK_ASSERT(iter != iter->
next);
16179 if (iter->
name == hash) {
16190 enum nk_window_insert_location loc)
16195 if (!
win || !ctx)
return;
16199 NK_ASSERT(iter != iter->
next);
16200 NK_ASSERT(iter !=
win);
16201 if (iter ==
win)
return;
16213 if (loc == NK_INSERT_BACK) {
16282 NK_ASSERT(!ctx->
current &&
"if this triggers you missed a `nk_end` call");
16283 if (!ctx || ctx->
current || !title || !name)
16287 style = &ctx->
style;
16290 win = nk_find_window(ctx, name_hash, name);
16296 if (!
win)
return 0;
16299 nk_insert_window(ctx,
win, NK_INSERT_FRONT);
16300 else nk_insert_window(ctx,
win, NK_INSERT_BACK);
16336 }
else nk_start(ctx,
win);
16341 int inpanel, ishovered;
16358 iter_bounds.
x, iter_bounds.
y, iter_bounds.
w, iter_bounds.
h) &&
16372 if (iter && inpanel && (
win != ctx->
end)) {
16379 iter_bounds.
x, iter_bounds.
y, iter_bounds.
w, iter_bounds.
h) &&
16397 nk_remove_window(ctx, iter);
16398 nk_insert_window(ctx, iter, NK_INSERT_BACK);
16401 if (!iter && ctx->
end !=
win) {
16405 nk_remove_window(ctx,
win);
16406 nk_insert_window(ctx,
win, NK_INSERT_BACK);
16427 NK_ASSERT(ctx->
current &&
"if this triggers you forgot to call `nk_begin`");
16469 if (!ctx || !ctx->
current)
return 0;
16477 if (!ctx || !ctx->
current)
return 0;
16522 if (!ctx || !ctx->
current)
return 0;
16530 if (!ctx || !ctx->
current)
return 0;
16553 if (!ctx || !ctx->
current)
return 0;
16561 if (!ctx || !ctx->
current)
return 0;
16571 if (!ctx)
return 0;
16598 return any_hovered || any_active;
16607 if (!ctx)
return 0;
16611 win = nk_find_window(ctx, title_hash,
name);
16612 if (!
win)
return 0;
16622 if (!ctx)
return 1;
16626 win = nk_find_window(ctx, title_hash,
name);
16627 if (!
win)
return 1;
16637 if (!ctx)
return 1;
16641 win = nk_find_window(ctx, title_hash,
name);
16642 if (!
win)
return 1;
16652 if (!ctx)
return 0;
16656 win = nk_find_window(ctx, title_hash,
name);
16657 if (!
win)
return 0;
16667 return nk_find_window(ctx, title_hash,
name);
16677 NK_ASSERT(ctx->
current !=
win &&
"You cannot close a currently active window");
16691 NK_ASSERT(ctx->
current !=
win &&
"You cannot update a currently in procecss window");
16736 win = nk_find_window(ctx, title_hash,
name);
16747 if (!ctx || !cond)
return;
16761 win = nk_find_window(ctx, title_hash,
name);
16772 if (!ctx || !cond)
return;
16787 win = nk_find_window(ctx, title_hash,
name);
16789 nk_remove_window(ctx,
win);
16790 nk_insert_window(ctx,
win, NK_INSERT_BACK);
16831 popup = (
struct nk_window*)nk_create_window(ctx);
16855 popup->bounds = rect;
16864 nk_start_popup(ctx,
win);
16894 nk_free_panel(ctx, popup->
layout);
16923 popup = (
struct nk_window*)nk_create_window(ctx);
16930 int pressed, in_body, in_header;
16931 #ifdef NK_BUTTON_TRIGGER_ON_RELEASE
16938 if (pressed && (!in_body || in_header))
16960 NK_ASSERT(popup->
layout);
16962 nk_start_popup(ctx,
win);
16967 nk_panel_begin(ctx, 0, panel_type);
16987 if (!ctx || !ctx->
current)
return;
16990 NK_ASSERT(
popup->parent);
17007 if (!
popup->parent)
return;
17022 nk_finish_popup(ctx,
win);
17039 *offset_x =
popup->scrollbar.x;
17041 *offset_y =
popup->scrollbar.y;
17055 popup->scrollbar.x = offset_x;
17056 popup->scrollbar.y = offset_y;
17069 struct nk_rect trigger_bounds)
17076 int is_clicked = 0;
17099 if ((!is_open && !is_clicked))
17144 style = &ctx->
style;
17163 const char *text,
int len,
nk_flags align)
17179 style = &ctx->
style;
17193 const char *label,
nk_flags align)
17199 const char *text,
int len,
nk_flags align)
17215 style = &ctx->
style;
17249 if (!ctx || !ctx->
current)
return;
17253 NK_ASSERT(popup->
parent);
17261 struct nk_rect body = {0,0,0,0};
17270 if (pressed && in_body)
17375 body.
y = header.
y + header.
h;
17381 if ((is_clicked && is_open && !is_active) || (is_open && !is_active) ||
17382 (!is_open && !is_active && !is_clicked))
return 0;
17408 if (!state)
return 0;
17413 return nk_menu_begin(ctx,
win, title, is_clicked, header,
size);
17438 if (!state)
return 0;
17443 return nk_menu_begin(ctx,
win,
id, is_clicked, header,
size);
17463 if (!state)
return 0;
17468 return nk_menu_begin(ctx,
win,
id, is_clicked, header,
size);
17488 if (!state)
return 0;
17494 return nk_menu_begin(ctx,
win, title, is_clicked, header,
size);
17520 if (!state)
return 0;
17526 return nk_menu_begin(ctx,
win, title, is_clicked, header,
size);
17546 const char *label,
nk_flags align)
17552 const char *text,
int len,
nk_flags align)
17557 const char *text,
int len,
nk_flags align)
17562 const char *label,
nk_flags align)
17621 float total_space,
int columns)
17623 float panel_padding;
17624 float panel_spacing;
17631 padding = nk_panel_get_padding(style, type);
17634 panel_padding = 2 * padding.x;
17635 panel_spacing = (float)
NK_MAX(columns - 1, 0) * spacing.x;
17636 panel_space = total_space - panel_padding - panel_spacing;
17637 return panel_space;
17641 float height,
int cols)
17658 style = &ctx->
style;
17676 if (height == 0.0f)
17678 else layout->
row.
height = height + item_spacing.y;
17686 background.y = layout->
at_y - 1.0f;
17687 background.h = layout->
row.
height + 1.0f;
17693 float height,
int cols,
int width)
17704 nk_panel_layout(ctx,
win, height, cols);
17719 NK_ASSERT(pixel_width);
17736 float row_height,
int cols)
17749 nk_panel_layout(ctx,
win, row_height, cols);
17779 float ratio = ratio_or_width;
17780 if ((ratio + layout->
row.
filled) > 1.0f)
return;
17808 float height,
int cols,
const float *ratio)
17823 nk_panel_layout(ctx,
win, height, cols);
17828 for (i = 0; i < cols; ++i) {
17829 if (ratio[i] < 0.0f)
17831 else r += ratio[i];
17835 layout->
row.
item_width = (r > 0 && n_undef > 0) ? (r / (
float)n_undef):0;
17859 nk_panel_layout(ctx,
win, height, 1);
17939 int variable_count = 0;
17940 int min_variable_count = 0;
17941 float min_fixed_width = 0.0f;
17942 float total_fixed_width = 0.0f;
17943 float max_variable_width = 0.0f;
17957 if (width >= 0.0f) {
17958 total_fixed_width += width;
17959 min_fixed_width += width;
17960 }
else if (width < -1.0f) {
17962 total_fixed_width += width;
17963 max_variable_width =
NK_MAX(max_variable_width, width);
17966 min_variable_count++;
17970 if (variable_count) {
17971 float space = nk_layout_row_calculate_usable_space(&ctx->
style, layout->
type,
17973 float var_width = (
NK_MAX(space-min_fixed_width,0.0f)) / (
float)variable_count;
17974 int enough_space = var_width >= max_variable_width;
17976 var_width = (
NK_MAX(space-total_fixed_width,0)) / (
float)min_variable_count;
17979 *width = (*width >= 0.0f)? *width: (*width < -1.0f && !enough_space)? -(*width): var_width;
17985 float height,
int widget_count)
17998 nk_panel_layout(ctx,
win, height, widget_count);
18056 ret.x = layout->
clip.
x;
18057 ret.y = layout->
clip.
y;
18058 ret.w = layout->
clip.
w;
18075 ret.x = layout->
at_x;
18076 ret.y = layout->
at_y;
18088 NK_ASSERT(ctx->current);
18089 NK_ASSERT(ctx->current->layout);
18090 win = ctx->current;
18104 NK_ASSERT(ctx->current);
18105 NK_ASSERT(ctx->current->layout);
18106 win = ctx->current;
18120 NK_ASSERT(ctx->current);
18121 NK_ASSERT(ctx->current->layout);
18122 win = ctx->current;
18136 NK_ASSERT(ctx->current);
18137 NK_ASSERT(ctx->current->layout);
18138 win = ctx->current;
18150 const float row_height = layout->
row.
height - spacing.
y;
18151 nk_panel_layout(ctx,
win, row_height, layout->
row.
columns);
18163 float item_offset = 0;
18164 float item_width = 0;
18165 float item_spacing = 0;
18166 float panel_space = 0;
18176 style = &ctx->
style;
18180 padding = nk_panel_get_padding(style, layout->
type);
18181 panel_space = nk_layout_row_calculate_usable_space(&ctx->
style, layout->
type,
18184 #define NK_FRAC(x) (x - (int)x)
18190 item_offset = (
float)layout->
row.
index * w;
18191 item_width = w + NK_FRAC(item_offset);
18192 item_spacing = (float)layout->
row.
index * spacing.x;
18198 item_width = w + NK_FRAC(item_offset);
18224 w = (ratio * panel_space);
18225 item_spacing = (float)layout->
row.
index * spacing.x;
18227 item_width = w + NK_FRAC(item_offset);
18237 item_offset = (float)layout->
row.
index * item_width;
18238 item_spacing = (
float)layout->
row.
index * spacing.x;
18244 item_spacing = (float)layout->
row.
index * spacing.x;
18251 if (((bounds->
x + bounds->
w) > layout->
max_x) && modify)
18252 layout->
max_x = (bounds->
x + bounds->
w);
18261 item_spacing = (float)layout->
row.
index * spacing.x;
18273 item_width = w + NK_FRAC(item_offset);
18274 item_spacing = (float)layout->
row.
index * spacing.x;
18278 default: NK_ASSERT(0);
break;
18282 bounds->
w = item_width;
18285 bounds->
x = layout->
at_x + item_offset + item_spacing + padding.x;
18286 if (((bounds->
x + bounds->
w) > layout->
max_x) && modify)
18287 layout->
max_x = bounds->
x + bounds->
w;
18306 nk_panel_alloc_row(ctx,
win);
18365 struct nk_rect header = {0,0,0,0};
18366 struct nk_rect sym = {0,0,0,0};
18382 style = &ctx->
style;
18391 widget_state =
nk_widget(&header, ctx);
18396 text.background =
nk_rgba(0,0,0,0);
18398 text.background = background->
data.
color;
18429 button, 0, style->
font);
18433 sym.
x = sym.
x + sym.
w + 4 * item_spacing.x;
18440 header.
w =
NK_MAX(header.
w, sym.
w + item_spacing.x);
18441 label.x = sym.
x + sym.
w + item_spacing.x;
18443 label.w = header.
w - (sym.
w + item_spacing.y + style->
tab.
indent);
18447 nk_widget_text(out, label, title,
nk_strlen(title), &text,
18462 const char *hash,
int len,
int line)
18474 state = nk_find_value(
win, tree_hash);
18476 state = nk_add_value(ctx,
win, tree_hash, 0);
18477 *state = initial_state;
18485 return nk_tree_state_base(ctx, type, 0, title, state);
18491 return nk_tree_state_base(ctx, type, &img, title, state);
18515 const char *hash,
int len,
int line)
18517 return nk_tree_base(ctx,
type, 0, title, initial_state, hash, len, line);
18522 const char *hash,
int len,
int seed)
18524 return nk_tree_base(ctx,
type, &img, title, initial_state, hash, len, seed);
18533 struct nk_image *img,
const char *title,
int title_len,
18550 struct nk_rect header = {0,0,0,0};
18551 struct nk_rect sym = {0,0,0,0};
18567 style = &ctx->
style;
18577 widget_state =
nk_widget(&header, ctx);
18582 text.background =
nk_rgba(0,0,0,0);
18584 text.background = background->
data.
color;
18619 text_width += (4 * padding.x);
18621 header.
w =
NK_MAX(header.
w, sym.
w + item_spacing.x);
18622 label.x = sym.
x + sym.
w + item_spacing.x;
18624 label.w =
NK_MIN(header.
w - (sym.
w + item_spacing.y + style->
tab.
indent), text_width);
18645 int *selected,
const char *hash,
int len,
int line)
18657 state = nk_find_value(
win, tree_hash);
18659 state = nk_add_value(ctx,
win, tree_hash, 0);
18660 *state = initial_state;
18661 }
return nk_tree_element_image_push_hashed_base(ctx, type, img, title,
18667 int *selected,
const char *hash,
int len,
int seed)
18669 return nk_tree_element_base(ctx, type, 0, title, initial_state, selected, hash, len, seed);
18674 int *selected,
const char *hash,
int len,
int seed)
18676 return nk_tree_element_base(ctx, type, &img, title, initial_state, selected, hash, len, seed);
18702 nk_panel_alloc_space(&
bounds, ctx);
18712 nk_zero(&panel,
sizeof(panel));
18714 panel.
flags = flags;
18715 panel.scrollbar.x = *x_offset;
18716 panel.scrollbar.y = *y_offset;
18718 panel.layout = (
struct nk_panel*)nk_create_panel(ctx);
18724 panel.layout->
offset_x = x_offset;
18725 panel.layout->
offset_y = y_offset;
18751 struct nk_vec2 panel_padding;
18770 pan.bounds.x = g->
bounds.
x - panel_padding.x;
18771 pan.bounds.w = g->
bounds.
w + 2 * panel_padding.x;
18774 pan.bounds.x -= g->
border;
18775 pan.bounds.y -= g->
border;
18776 pan.bounds.w += 2*g->
border;
18777 pan.bounds.h += 2*g->
border;
18785 pan.flags = g->
flags;
18792 nk_unify(&clip, &parent->
clip, pan.bounds.
x, pan.bounds.y,
18793 pan.bounds.x + pan.bounds.w, pan.bounds.y + pan.bounds.h + panel_padding.x);
18812 const char *title,
nk_flags flags)
18831 x_offset = nk_find_value(
win, id_hash);
18833 x_offset = nk_add_value(ctx,
win, id_hash, 0);
18834 y_offset = nk_add_value(ctx,
win, id_hash+1, 0);
18836 NK_ASSERT(x_offset);
18837 NK_ASSERT(y_offset);
18838 if (!x_offset || !y_offset)
return 0;
18839 *x_offset = *y_offset = 0;
18840 }
else y_offset = nk_find_value(
win, id_hash+1);
18873 x_offset_ptr = nk_find_value(
win, id_hash);
18874 if (!x_offset_ptr) {
18875 x_offset_ptr = nk_add_value(ctx,
win, id_hash, 0);
18876 y_offset_ptr = nk_add_value(ctx,
win, id_hash+1, 0);
18878 NK_ASSERT(x_offset_ptr);
18879 NK_ASSERT(y_offset_ptr);
18880 if (!x_offset_ptr || !y_offset_ptr)
return;
18881 *x_offset_ptr = *y_offset_ptr = 0;
18882 }
else y_offset_ptr = nk_find_value(
win, id_hash+1);
18884 *x_offset = *x_offset_ptr;
18886 *y_offset = *y_offset_ptr;
18908 x_offset_ptr = nk_find_value(
win, id_hash);
18909 if (!x_offset_ptr) {
18910 x_offset_ptr = nk_add_value(ctx,
win, id_hash, 0);
18911 y_offset_ptr = nk_add_value(ctx,
win, id_hash+1, 0);
18913 NK_ASSERT(x_offset_ptr);
18914 NK_ASSERT(y_offset_ptr);
18915 if (!x_offset_ptr || !y_offset_ptr)
return;
18916 *x_offset_ptr = *y_offset_ptr = 0;
18917 }
else y_offset_ptr = nk_find_value(
win, id_hash+1);
18918 *x_offset_ptr = x_offset;
18919 *y_offset_ptr = y_offset;
18932 const char *title,
nk_flags flags,
int row_height,
int row_count)
18948 if (!ctx || !view || !title)
return 0;
18951 style = &ctx->
style;
18953 row_height +=
NK_MAX(0, (
int)item_spacing.y);
18958 x_offset = nk_find_value(
win, title_hash);
18960 x_offset = nk_add_value(ctx,
win, title_hash, 0);
18961 y_offset = nk_add_value(ctx,
win, title_hash+1, 0);
18963 NK_ASSERT(x_offset);
18964 NK_ASSERT(y_offset);
18965 if (!x_offset || !y_offset)
return 0;
18966 *x_offset = *y_offset = 0;
18967 }
else y_offset = nk_find_value(
win, title_hash+1);
18978 view->
count = (int)
NK_MAX(nk_iceilf((layout->
clip.
h)/(float)row_height),0);
18992 NK_ASSERT(view->
ctx);
18994 if (!view || !view->
ctx)
return;
19021 nk_layout_peek(&bounds, ctx);
19033 nk_layout_peek(&bounds, ctx);
19045 nk_layout_peek(&bounds, ctx);
19057 nk_layout_peek(&bounds, ctx);
19069 nk_layout_peek(&bounds, ctx);
19083 c.
x = (float)((
int)c.
x);
19084 c.
y = (float)((
int)c.
y);
19085 c.
w = (float)((
int)c.
w);
19086 c.
h = (float)((
int)c.
h);
19088 nk_layout_peek(&bounds, ctx);
19089 nk_unify(&v, &c, bounds.
x, bounds.
y, bounds.
x + bounds.
w, bounds.
y + bounds.
h);
19105 c.
x = (float)((
int)c.
x);
19106 c.
y = (float)((
int)c.
y);
19107 c.
w = (float)((
int)c.
w);
19108 c.
h = (float)((
int)c.
h);
19110 nk_layout_peek(&bounds, ctx);
19111 nk_unify(&v, &c, bounds.
x, bounds.
y, bounds.
x + bounds.
w, bounds.
y + bounds.
h);
19127 c.
x = (float)((
int)c.
x);
19128 c.
y = (float)((
int)c.
y);
19129 c.
w = (float)((
int)c.
w);
19130 c.
h = (float)((
int)c.
h);
19132 nk_layout_peek(&bounds, ctx);
19133 nk_unify(&v, &c, bounds.
x, bounds.
y, bounds.
x + bounds.
w, bounds.
y + bounds.
h);
19153 nk_panel_alloc_space(bounds, ctx);
19169 bounds->
x = (float)((
int)bounds->
x);
19170 bounds->
y = (float)((
int)bounds->
y);
19171 bounds->
w = (float)((
int)bounds->
w);
19172 bounds->
h = (float)((
int)bounds->
h);
19174 c.
x = (float)((
int)c.
x);
19175 c.
y = (float)((
int)c.
y);
19176 c.
w = (float)((
int)c.
w);
19177 c.
h = (float)((
int)c.
h);
19179 nk_unify(&v, &c, bounds->
x, bounds->
y, bounds->
x + bounds->
w, bounds->
y + bounds->
h);
19195 struct nk_vec2 panel_padding;
19204 style = &ctx->
style;
19208 panel_padding = nk_panel_get_padding(style, layout->
type);
19210 bounds->
w += panel_padding.x;
19211 bounds->
x -= panel_padding.x;
19212 }
else bounds->
x -= item_padding.
x;
19215 bounds->
w += panel_padding.x;
19216 else bounds->
w += item_padding.
x;
19225 int i, index, rows;
19239 for (i = 0; i < rows; ++i)
19240 nk_panel_alloc_row(ctx,
win);
19246 for (i = 0; i < cols; ++i)
19247 nk_panel_alloc_space(&none, ctx);
19262 const char *
string,
int len,
const struct nk_text *t,
19270 if (!o || !t)
return;
19272 b.
h =
NK_MAX(b.
h, 2 * t->padding.y);
19273 label.x = 0; label.w = 0;
19274 label.y = b.
y + t->padding.y;
19278 text_width += (2.0f * t->padding.x);
19282 label.x = b.
x + t->padding.x;
19283 label.w =
NK_MAX(0, b.
w - 2 * t->padding.x);
19285 label.w =
NK_MAX(1, 2 * t->padding.x + (
float)text_width);
19286 label.x = (b.
x + t->padding.x + ((b.
w - 2 * t->padding.x) - label.w) / 2);
19287 label.x =
NK_MAX(b.
x + t->padding.x, label.x);
19288 label.w =
NK_MIN(b.
x + b.
w, label.x + label.w);
19289 if (label.w >= label.x) label.w -= label.x;
19291 label.x =
NK_MAX(b.
x + t->padding.x, (b.
x + b.
w) - (2 * t->padding.x + (
float)text_width));
19292 label.w = (float)text_width + 2 * t->padding.x;
19297 label.y = b.
y + b.
h/2.0f - (float)f->
height/2.0f;
19303 nk_draw_text(o, label, (
const char*)
string, len, f, t->background, t->text);
19307 const char *
string,
int len,
const struct nk_text *t,
19320 if (!o || !t)
return;
19323 text.background = t->background;
19324 text.text = t->text;
19326 b.
w =
NK_MAX(b.
w, 2 * t->padding.x);
19327 b.
h =
NK_MAX(b.
h, 2 * t->padding.y);
19328 b.
h = b.
h - 2 * t->padding.y;
19330 line.x = b.
x + t->padding.x;
19331 line.y = b.
y + t->padding.y;
19332 line.w = b.
w - 2 * t->padding.x;
19333 line.h = 2 * t->padding.y + f->
height;
19335 fitting = nk_text_clamp(f,
string, len, line.w, &glyphs, &width, seperator,
NK_LEN(seperator));
19336 while (done < len) {
19337 if (!fitting || line.y + line.h >= (b.
y + b.
h))
break;
19338 nk_widget_text(o, line, &
string[done], fitting, &text,
NK_TEXT_LEFT, f);
19340 line.y += f->
height + 2 * t->padding.y;
19341 fitting = nk_text_clamp(f, &
string[done], len - done, line.w, &glyphs, &width, seperator,
NK_LEN(seperator));
19361 style = &ctx->
style;
19362 nk_panel_alloc_space(&bounds, ctx);
19365 text.padding.
x = item_padding.
x;
19366 text.padding.y = item_padding.
y;
19369 nk_widget_text(&
win->
buffer, bounds, str, len, &text, alignment, style->
font);
19388 style = &ctx->
style;
19389 nk_panel_alloc_space(&bounds, ctx);
19392 text.padding.
x = item_padding.
x;
19393 text.padding.y = item_padding.
y;
19396 nk_widget_text_wrap(&
win->
buffer, bounds, str, len, &text, style->
font);
19398 #ifdef NK_INCLUDE_STANDARD_VARARGS
19401 struct nk_color color,
const char *fmt, ...)
19404 va_start(args, fmt);
19405 nk_labelfv_colored(ctx, flags, color, fmt, args);
19410 const char *fmt, ...)
19413 va_start(args, fmt);
19414 nk_labelfv_colored_wrap(ctx, color, fmt, args);
19421 va_start(args, fmt);
19422 nk_labelfv(ctx, flags, fmt, args);
19426 nk_labelf_wrap(
struct nk_context *ctx,
const char *fmt,...)
19429 va_start(args, fmt);
19430 nk_labelfv_wrap(ctx, fmt, args);
19435 struct nk_color color,
const char *fmt, va_list args)
19438 nk_strfmt(buf,
NK_LEN(buf), fmt, args);
19444 const char *fmt, va_list args)
19447 nk_strfmt(buf,
NK_LEN(buf), fmt, args);
19455 nk_strfmt(buf,
NK_LEN(buf), fmt, args);
19460 nk_labelfv_wrap(
struct nk_context *ctx,
const char *fmt, va_list args)
19463 nk_strfmt(buf,
NK_LEN(buf), fmt, args);
19468 nk_value_bool(
struct nk_context *ctx,
const char *prefix,
int value)
19470 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: %s", prefix, ((value) ?
"true":
"false"));
19473 nk_value_int(
struct nk_context *ctx,
const char *prefix,
int value)
19475 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: %d", prefix, value);
19478 nk_value_uint(
struct nk_context *ctx,
const char *prefix,
unsigned int value)
19480 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: %u", prefix, value);
19483 nk_value_float(
struct nk_context *ctx,
const char *prefix,
float value)
19485 double double_value = (double)value;
19486 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: %.3f", prefix, double_value);
19491 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: (%d, %d, %d, %d)", p, c.
r, c.
g, c.
b, c.
a);
19497 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: (%.2f, %.2f, %.2f, %.2f)",
19498 p, c[0], c[1], c[2], c[3]);
19501 nk_value_color_hex(
struct nk_context *ctx,
const char *prefix,
struct nk_color color)
19572 nk_zero(&s,
sizeof(s));
19573 s.handle.ptr = ptr;
19575 s.region[0] = (
unsigned short)r.x;
19576 s.region[1] = (
unsigned short)r.y;
19577 s.region[2] = (
unsigned short)r.w;
19578 s.region[3] = (
unsigned short)r.h;
19585 nk_zero(&s,
sizeof(s));
19588 s.region[0] = (
unsigned short)r.x;
19589 s.region[1] = (
unsigned short)r.y;
19590 s.region[2] = (
unsigned short)r.w;
19591 s.region[3] = (
unsigned short)r.h;
19599 nk_zero(&s,
sizeof(s));
19602 s.region[0] = (
unsigned short)r.x;
19603 s.region[1] = (
unsigned short)r.y;
19604 s.region[2] = (
unsigned short)r.w;
19605 s.region[3] = (
unsigned short)r.h;
19612 nk_zero(&s,
sizeof(s));
19625 nk_zero(&s,
sizeof(s));
19627 s.handle.ptr = ptr;
19639 nk_zero(&s,
sizeof(s));
19652 return !(img->
w == 0 && img->
h == 0);
19710 text.background = background;
19711 text.text = foreground;
19722 nk_fill_rect(out, nk_shrink_rect(content, border_width), 0, background);
19740 points[2].
x, points[2].
y, foreground);
19752 nk_widget_state_reset(state);
19761 #ifdef NK_BUTTON_TRIGGER_ON_RELEASE
19781 background = &style->
hover;
19783 background = &style->
active;
19784 else background = &style->
normal;
19803 if (!out || !style)
19827 background = nk_draw_button(out, bounds, state, style);
19831 text.background = background->
data.
color;
19840 nk_widget_text(out, *content, txt, len, &text, text_alignment, font);
19843 nk_do_button_text(
nk_flags *state,
19857 if (!out || !style || !font || !
string)
19860 ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
19862 nk_draw_button_text(out, &bounds, &content, *state, style,
string, len, align, font);
19876 background = nk_draw_button(out, bounds, state, style);
19886 nk_draw_symbol(out,
type, *content, bg, sym, 1, font);
19889 nk_do_button_symbol(
nk_flags *state,
19902 if (!out || !style || !font || !state)
19905 ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
19907 nk_draw_button_symbol(out, &bounds, &content, *state, style, symbol, font);
19916 nk_draw_button(out, bounds, state, style);
19920 nk_do_button_image(
nk_flags *state,
19931 if (!out || !style || !state)
19934 ret = nk_do_button(state, out, bounds, style, in, b, &content);
19941 nk_draw_button_image(out, &bounds, &content, *state, style, &img);
19957 background = nk_draw_button(out, bounds, state, style);
19959 text.background = background->
data.
color;
19979 nk_do_button_text_symbol(
nk_flags *state,
19986 struct nk_rect tri = {0,0,0,0};
19992 if (!out || !style || !font)
19995 ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
19996 tri.
y = content.
y + (content.
h/2) - font->
height/2;
19999 tri.
x = (content.
x + content.
w) - (2 * style->
padding.
x + tri.
w);
20001 }
else tri.
x = content.
x + 2 * style->
padding.
x;
20005 nk_draw_button_text_symbol(out, &bounds, &content, &tri,
20006 *state, style, str, len, symbol, font);
20014 const char *str,
int len,
const struct nk_user_font *font,
20019 background = nk_draw_button(out, bounds, state, style);
20023 text.background = background->
data.
color;
20036 nk_do_button_text_image(
nk_flags *state,
20050 if (!out || !font || !style || !str)
20053 ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
20055 icon.w = icon.h = bounds.
h - 2 * style->
padding.
y;
20057 icon.x = (bounds.
x + bounds.
w) - (2 * style->
padding.
x + icon.w);
20058 icon.x =
NK_MAX(icon.x, 0);
20059 }
else icon.x = bounds.
x + 2 * style->
padding.
x;
20067 nk_draw_button_text_image(out, &bounds, &content, &icon, *state, style, str, len, font, &img);
20081 struct nk_config_stack_button_behavior *button_stack;
20082 struct nk_config_stack_button_behavior_element *element;
20085 if (!ctx)
return 0;
20088 NK_ASSERT(button_stack->head < (
int)
NK_LEN(button_stack->elements));
20089 if (button_stack->head >= (
int)
NK_LEN(button_stack->elements))
20092 element = &button_stack->elements[button_stack->head++];
20101 struct nk_config_stack_button_behavior *button_stack;
20102 struct nk_config_stack_button_behavior_element *element;
20105 if (!ctx)
return 0;
20108 NK_ASSERT(button_stack->head > 0);
20109 if (button_stack->head < 1)
20112 element = &button_stack->elements[--button_stack->head];
20113 *element->address = element->old_value;
20137 if (!state)
return 0;
20147 if (!ctx)
return 0;
20182 if (!state)
return 0;
20214 if (!state)
return 0;
20223 if (!ctx)
return 0;
20247 if (!state)
return 0;
20256 if (!ctx)
return 0;
20262 const char *text,
int len,
nk_flags align)
20281 if (!state)
return 0;
20289 const char* text,
int len,
nk_flags align)
20292 if (!ctx)
return 0;
20296 const char *label,
nk_flags align)
20302 const char *title,
nk_flags align)
20328 if (!state)
return 0;
20336 const char *text,
int len,
nk_flags align)
20341 const char *label,
nk_flags align)
20347 const char *label,
nk_flags text_alignment)
20365 nk_widget_state_reset(state);
20380 const struct nk_rect *cursors,
const char *
string,
int len,
20389 background = &style->
hover;
20393 background = &style->
hover;
20397 background = &style->
normal;
20413 text.padding.x = 0;
20414 text.padding.y = 0;
20416 nk_widget_text(out, *label,
string, len, &text,
NK_TEXT_LEFT, font);
20422 const struct nk_rect *cursors,
const char *
string,
int len,
20431 background = &style->
hover;
20435 background = &style->
hover;
20439 background = &style->
normal;
20455 text.padding.x = 0;
20456 text.padding.y = 0;
20458 nk_widget_text(out, *label,
string, len, &text,
NK_TEXT_LEFT, font);
20463 int *active,
const char *str,
int len,
enum nk_toggle_type type,
20476 if (!out || !style || !font || !active)
20490 select.
h = select.
w;
20491 select.
y = r.
y + r.
h/2.0f - select.
h/2.0f;
20501 label.
x = select.
x + select.
w + style->
spacing;
20502 label.
y = select.
y;
20504 label.
h = select.
w;
20507 was_active = *active;
20508 *active = nk_toggle_behavior(in, bounds, state, *active);
20513 if (type == NK_TOGGLE_CHECK) {
20514 nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font);
20516 nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font);
20520 return (was_active != *active);
20545 style = &ctx->
style;
20549 if (!state)
return active;
20552 text, len, NK_TOGGLE_CHECK, &style->
checkbox, in, style->
font);
20557 unsigned int flags,
unsigned int value)
20562 if (!ctx || !text)
return flags;
20563 old_active = (int)((flags & value) & value);
20566 else flags &= ~value;
20576 if (!ctx || !text || !active)
return 0;
20579 return old_val != *active;
20583 unsigned int *flags,
unsigned int value)
20589 if (!ctx || !text || !flags)
return 0;
20591 active = (int)((*flags & value) & value);
20593 if (active) *flags |= value;
20594 else *flags &= ~value;
20604 unsigned int flags,
unsigned int value)
20613 unsigned int *flags,
unsigned int value)
20640 style = &ctx->
style;
20644 if (!state)
return (
int)state;
20647 text, len, NK_TOGGLE_OPTION, &style->
option, in, style->
font);
20657 if (!ctx || !text || !active)
return 0;
20658 old_value = *active;
20660 return old_value != *active;
20685 const struct nk_rect *bounds,
20691 text.padding = style->
padding;
20696 background = &style->
pressed;
20699 background = &style->
hover;
20702 background = &style->
normal;
20720 text.background =
nk_rgba(0,0,0,0);
20723 text.background = background->
data.
color;
20727 else nk_draw_symbol(out, sym, *icon, text.background, text.text, 1, font);
20729 nk_widget_text(out, *bounds,
string, len, &text, align, font);
20733 struct nk_rect bounds,
const char *str,
int len,
nk_flags align,
int *value,
20748 if (!state || !out || !str || !len || !value || !style || !font)
return 0;
20749 old_value = *value;
20759 *value = !(*value);
20763 nk_draw_selectable(out, *state, style, *value, &bounds, 0,0,
NK_SYMBOL_NONE, str, len, align, font);
20765 return old_value != *value;
20769 struct nk_rect bounds,
const char *str,
int len,
nk_flags align,
int *value,
20785 if (!state || !out || !str || !len || !value || !style || !font)
return 0;
20786 old_value = *value;
20794 *value = !(*value);
20797 icon.
w = icon.
h = bounds.
h - 2 * style->
padding.
y;
20799 icon.
x = (bounds.
x + bounds.
w) - (2 * style->
padding.
x + icon.
w);
20801 }
else icon.
x = bounds.
x + 2 * style->
padding.
x;
20810 nk_draw_selectable(out, *state, style, *value, &bounds, &icon, img,
NK_SYMBOL_NONE, str, len, align, font);
20812 return old_value != *value;
20816 struct nk_rect bounds,
const char *str,
int len,
nk_flags align,
int *value,
20832 if (!state || !out || !str || !len || !value || !style || !font)
return 0;
20833 old_value = *value;
20841 *value = !(*value);
20844 icon.
w = icon.
h = bounds.
h - 2 * style->
padding.
y;
20846 icon.
x = (bounds.
x + bounds.
w) - (2 * style->
padding.
x + icon.
w);
20848 }
else icon.
x = bounds.
x + 2 * style->
padding.
x;
20857 nk_draw_selectable(out, *state, style, *value, &bounds, &icon, 0, sym, str, len, align, font);
20859 return old_value != *value;
20883 style = &ctx->
style;
20886 if (!state)
return 0;
20893 const char *str,
int len,
nk_flags align,
int *value)
20912 style = &ctx->
style;
20915 if (!state)
return 0;
20918 str, len, align, value, &img, &style->
selectable, in, style->
font);
20922 const char *str,
int len,
nk_flags align,
int *value)
20941 style = &ctx->
style;
20944 if (!state)
return 0;
20947 str, len, align, value, sym, &style->
selectable, in, style->
font);
20951 const char *title,
nk_flags align,
int *value)
20965 const char *str,
nk_flags align,
int *value)
20974 const char *str,
nk_flags align,
int value)
20979 const char *str,
int len,
nk_flags align,
int value)
20985 const char *title,
int title_len,
nk_flags align,
int value)
20991 const char *title,
nk_flags align,
int value)
21008 struct nk_rect bounds,
float slider_min,
float slider_max,
float slider_value,
21009 float slider_step,
float slider_steps)
21011 int left_mouse_down;
21012 int left_mouse_click_in_cursor;
21015 nk_widget_state_reset(state);
21020 if (left_mouse_down && left_mouse_click_in_cursor) {
21022 const float d = in->
mouse.
pos.
x - (visual_cursor->
x+visual_cursor->
w*0.5f);
21023 const float pxstep = bounds.
w / slider_steps;
21027 if (
NK_ABS(d) >= pxstep) {
21028 const float steps = (float)((
int)(
NK_ABS(d) / pxstep));
21029 slider_value += (d > 0) ? (slider_step*steps) : -(slider_step*steps);
21030 slider_value =
NK_CLAMP(slider_min, slider_value, slider_max);
21031 ratio = (slider_value - slider_min)/slider_step;
21032 logical_cursor->
x = bounds.
x + (logical_cursor->
w * ratio);
21045 return slider_value;
21050 const struct nk_rect *visual_cursor,
float min,
float value,
float max)
21065 background = &style->
active;
21069 background = &style->
hover;
21073 background = &style->
normal;
21079 bar.y = (visual_cursor->
y + visual_cursor->
h/2) - bounds->
h/12;
21081 bar.h = bounds->
h/6;
21084 fill.w = (visual_cursor->
x + (visual_cursor->
w/2.0f)) - bar.x;
21109 float min,
float val,
float max,
float step,
21113 float slider_range;
21116 float slider_value;
21117 float slider_steps;
21118 float cursor_offset;
21120 struct nk_rect visual_cursor;
21121 struct nk_rect logical_cursor;
21125 if (!out || !style)
21140 button.y = bounds.
y;
21141 button.w = bounds.
h;
21142 button.h = bounds.
h;
21145 button.x = bounds.
x;
21151 button.x = (bounds.
x + bounds.
w) - button.w;
21156 bounds.
x = bounds.
x + button.w + style->
spacing.
x;
21157 bounds.
w = bounds.
w - (2*button.w + 2*style->
spacing.
x);
21165 slider_max =
NK_MAX(min, max);
21166 slider_min =
NK_MIN(min, max);
21167 slider_value =
NK_CLAMP(slider_min, val, slider_max);
21168 slider_range = slider_max - slider_min;
21169 slider_steps = slider_range / step;
21170 cursor_offset = (slider_value - slider_min) / step;
21175 logical_cursor.
h = bounds.
h;
21176 logical_cursor.
w = bounds.
w / slider_steps;
21177 logical_cursor.
x = bounds.
x + (logical_cursor.
w * cursor_offset);
21178 logical_cursor.
y = bounds.
y;
21182 visual_cursor.
y = (bounds.
y + bounds.
h*0.5f) - visual_cursor.
h*0.5f;
21183 visual_cursor.
x = logical_cursor.
x - visual_cursor.
w*0.5f;
21185 slider_value = nk_slider_behavior(state, &logical_cursor, &visual_cursor,
21186 in, bounds, slider_min, slider_max, slider_value, step, slider_steps);
21187 visual_cursor.
x = logical_cursor.
x - visual_cursor.
w*0.5f;
21191 nk_draw_slider(out, *state, style, &bounds, &visual_cursor, slider_min, slider_value, slider_max);
21193 return slider_value;
21217 style = &ctx->
style;
21221 if (!state)
return ret;
21224 old_value = *value;
21226 old_value, max_value, value_step, &style->
slider, in, style->
font);
21227 return (old_value > *value || old_value < *value);
21237 float value = (float)val;
21245 float value = (float)*val;
21246 ret =
nk_slider_float(ctx, (
float)min, &value, (
float)max, (
float)step);
21264 int left_mouse_down = 0;
21265 int left_mouse_click_in_cursor = 0;
21267 nk_widget_state_reset(state);
21268 if (!in || !modifiable)
return value;
21275 if (in && left_mouse_down && left_mouse_click_in_cursor) {
21276 if (left_mouse_down && left_mouse_click_in_cursor) {
21277 float ratio =
NK_MAX(0, (
float)(in->
mouse.
pos.
x - cursor.
x)) / (float)cursor.
w;
21303 background = &style->
active;
21306 background = &style->
hover;
21309 background = &style->
normal;
21337 if (!out || !style)
return 0;
21343 prog_scale = (float)value / (
float)max;
21346 prog_value =
NK_MIN(value, max);
21347 prog_value = nk_progress_behavior(state, in, bounds, cursor,max, prog_value, modifiable);
21348 cursor.w = cursor.w * prog_scale;
21352 nk_draw_progress(out, *state, style, &bounds, &cursor, value, max);
21376 style = &ctx->
style;
21379 if (!state)
return 0;
21384 *cur, max, is_modifyable, &style->
progress, in);
21385 return (*cur != old_value);
21405 int has_scrolling,
const struct nk_rect *scroll,
21407 const struct nk_rect *empty1,
float scroll_offset,
21411 int left_mouse_down;
21412 int left_mouse_clicked;
21413 int left_mouse_click_in_cursor;
21414 float scroll_delta;
21416 nk_widget_state_reset(state);
21417 if (!in)
return scroll_offset;
21427 if (left_mouse_down && left_mouse_click_in_cursor && !left_mouse_clicked) {
21429 float pixel, delta;
21434 delta = (pixel / scroll->
h) * target;
21435 scroll_offset =
NK_CLAMP(0, scroll_offset + delta, target - scroll->
h);
21436 cursor_y = scroll->
y + ((scroll_offset/target) * scroll->
h);
21441 delta = (pixel / scroll->
w) * target;
21442 scroll_offset =
NK_CLAMP(0, scroll_offset + delta, target - scroll->
w);
21443 cursor_x = scroll->
x + ((scroll_offset/target) * scroll->
w);
21450 scroll_offset =
NK_MAX(0, scroll_offset - scroll->
h);
21451 else scroll_offset =
NK_MAX(0, scroll_offset - scroll->
w);
21456 scroll_offset =
NK_MIN(scroll_offset + scroll->
h, target - scroll->
h);
21457 else scroll_offset =
NK_MIN(scroll_offset + scroll->
w, target - scroll->
w);
21458 }
else if (has_scrolling) {
21459 if ((scroll_delta < 0 || (scroll_delta > 0))) {
21461 scroll_offset = scroll_offset + scroll_step * (-scroll_delta);
21463 scroll_offset =
NK_CLAMP(0, scroll_offset, target - scroll->
h);
21464 else scroll_offset =
NK_CLAMP(0, scroll_offset, target - scroll->
w);
21470 if (o ==
NK_VERTICAL) scroll_offset = target - scroll->
h;
21477 return scroll_offset;
21482 const struct nk_rect *scroll)
21489 background = &style->
active;
21492 background = &style->
hover;
21495 background = &style->
normal;
21516 float offset,
float target,
float step,
float button_pixel_inc,
21525 float scroll_offset;
21527 float scroll_ratio;
21532 if (!out || !style)
return 0;
21536 if (target <= scroll.
h)
return 0;
21544 button.x = scroll.
x;
21545 button.w = scroll.
w;
21546 button.h = scroll.
w;
21548 scroll_h =
NK_MAX(scroll.
h - 2 * button.h,0);
21549 scroll_step =
NK_MIN(step, button_pixel_inc);
21552 button.y = scroll.
y;
21553 if (nk_do_button_symbol(&ws, out, button, style->
dec_symbol,
21555 offset = offset - scroll_step;
21558 button.y = scroll.
y + scroll.
h - button.h;
21559 if (nk_do_button_symbol(&ws, out, button, style->
inc_symbol,
21561 offset = offset + scroll_step;
21563 scroll.
y = scroll.
y + button.h;
21564 scroll.
h = scroll_h;
21568 scroll_step =
NK_MIN(step, scroll.
h);
21569 scroll_offset =
NK_CLAMP(0, offset, target - scroll.
h);
21570 scroll_ratio = scroll.
h / target;
21571 scroll_off = scroll_offset / target;
21575 cursor.y = scroll.
y + (scroll_off * scroll.
h) + style->
border + style->
padding.
y;
21580 empty_north.x = scroll.
x;
21581 empty_north.y = scroll.
y;
21582 empty_north.w = scroll.
w;
21583 empty_north.h =
NK_MAX(cursor.y - scroll.
y, 0);
21585 empty_south.x = scroll.
x;
21586 empty_south.y = cursor.y + cursor.h;
21587 empty_south.w = scroll.
w;
21588 empty_south.h =
NK_MAX((scroll.
y + scroll.
h) - (cursor.y + cursor.h), 0);
21591 scroll_offset = nk_scrollbar_behavior(state, in, has_scrolling, &scroll, &cursor,
21592 &empty_north, &empty_south, scroll_offset, target, scroll_step,
NK_VERTICAL);
21593 scroll_off = scroll_offset / target;
21598 nk_draw_scrollbar(out, *state, style, &scroll, &cursor);
21600 return scroll_offset;
21605 float offset,
float target,
float step,
float button_pixel_inc,
21614 float scroll_offset;
21616 float scroll_ratio;
21620 if (!out || !style)
return 0;
21624 scroll.
w =
NK_MAX(scroll.
w, 2 * scroll.
h);
21625 if (target <= scroll.
w)
return 0;
21632 button.y = scroll.
y;
21633 button.w = scroll.
h;
21634 button.h = scroll.
h;
21636 scroll_w = scroll.
w - 2 * button.w;
21637 scroll_step =
NK_MIN(step, button_pixel_inc);
21640 button.x = scroll.
x;
21641 if (nk_do_button_symbol(&ws, out, button, style->
dec_symbol,
21643 offset = offset - scroll_step;
21646 button.x = scroll.
x + scroll.
w - button.w;
21647 if (nk_do_button_symbol(&ws, out, button, style->
inc_symbol,
21649 offset = offset + scroll_step;
21651 scroll.
x = scroll.
x + button.w;
21652 scroll.
w = scroll_w;
21656 scroll_step =
NK_MIN(step, scroll.
w);
21657 scroll_offset =
NK_CLAMP(0, offset, target - scroll.
w);
21658 scroll_ratio = scroll.
w / target;
21659 scroll_off = scroll_offset / target;
21662 cursor.w = (scroll_ratio * scroll.
w) - (2*style->
border + 2*style->
padding.
x);
21663 cursor.x = scroll.
x + (scroll_off * scroll.
w) + style->
border + style->
padding.
x;
21668 empty_west.x = scroll.
x;
21669 empty_west.y = scroll.
y;
21670 empty_west.w = cursor.x - scroll.
x;
21671 empty_west.h = scroll.
h;
21673 empty_east.x = cursor.x + cursor.w;
21674 empty_east.y = scroll.
y;
21675 empty_east.w = (scroll.
x + scroll.
w) - (cursor.x + cursor.w);
21676 empty_east.h = scroll.
h;
21679 scroll_offset = nk_scrollbar_behavior(state, in, has_scrolling, &scroll, &cursor,
21680 &empty_west, &empty_east, scroll_offset, target, scroll_step,
NK_HORIZONTAL);
21681 scroll_off = scroll_offset / target;
21682 cursor.x = scroll.
x + (scroll_off * scroll.
w);
21686 nk_draw_scrollbar(out, *state, style, &scroll, &cursor);
21688 return scroll_offset;
21701 struct nk_text_find {
21704 int first_char, length;
21708 struct nk_text_edit_row {
21711 float baseline_y_delta;
21722 #define NK_TEXT_HAS_SELECTION(s) ((s)->select_start != (s)->select_end)
21725 nk_textedit_get_width(
const struct nk_text_edit *edit,
int line_start,
int char_id,
21734 nk_textedit_layout_row(
struct nk_text_edit_row *r,
struct nk_text_edit *edit,
21735 int line_start_id,
float row_height,
const struct nk_user_font *font)
21740 const char *remaining;
21744 const struct nk_vec2 size = nk_text_calculate_text_bounds(font,
21745 text, (
int)(end - text), row_height, &remaining, 0, &glyphs, NK_STOP_ON_NEW_LINE);
21749 r->baseline_y_delta =
size.y;
21752 r->num_chars = glyphs;
21755 nk_textedit_locate_coord(
struct nk_text_edit *edit,
float x,
float y,
21758 struct nk_text_edit_row r;
21760 float base_y = 0, prev_x;
21764 r.ymin = r.ymax = 0;
21769 nk_textedit_layout_row(&r, edit, i, row_height, font);
21770 if (r.num_chars <= 0)
21773 if (i==0 && y < base_y + r.ymin)
21776 if (y < base_y + r.ymax)
21780 base_y += r.baseline_y_delta;
21796 for (i=0; i < r.num_chars; ++i) {
21797 float w = nk_textedit_get_width(edit, k, i, font);
21798 if (x < prev_x+w) {
21799 if (x < prev_x+w/2)
21811 return i+r.num_chars-1;
21812 else return i+r.num_chars;
21815 nk_textedit_click(
struct nk_text_edit *state,
float x,
float y,
21820 state->
cursor = nk_textedit_locate_coord(state, x, y, font, row_height);
21826 nk_textedit_drag(
struct nk_text_edit *state,
float x,
float y,
21831 int p = nk_textedit_locate_coord(state, x, y, font, row_height);
21837 nk_textedit_find_charpos(
struct nk_text_find *find,
struct nk_text_edit *state,
21838 int n,
int single_line,
const struct nk_user_font *font,
float row_height)
21842 struct nk_text_edit_row r;
21843 int prev_start = 0;
21851 nk_textedit_layout_row(&r, state, 0, row_height, font);
21853 find->first_char = 0;
21859 nk_textedit_layout_row(&r, state, i, row_height, font);
21862 find->first_char = i;
21863 find->length = r.num_chars;
21867 find->height = r.ymax - r.ymin;
21868 find->prev_first = prev_start;
21876 nk_textedit_layout_row(&r, state, i, row_height, font);
21877 if (n < i + r.num_chars)
break;
21880 find->y += r.baseline_y_delta;
21883 find->first_char = first = i;
21884 find->length = r.num_chars;
21885 find->height = r.ymax - r.ymin;
21886 find->prev_first = prev_start;
21890 for (i=0; first+i < n; ++i)
21891 find->x += nk_textedit_get_width(state, first, i, font);
21898 if (NK_TEXT_HAS_SELECTION(state)) {
21911 nk_textedit_makeundo_delete(state, where, len);
21919 nk_textedit_clamp(state);
21920 if (NK_TEXT_HAS_SELECTION(state)) {
21947 if (NK_TEXT_HAS_SELECTION(state)) {
21948 nk_textedit_sortselection(state);
21958 if (NK_TEXT_HAS_SELECTION(state)) {
21959 nk_textedit_sortselection(state);
21960 nk_textedit_clamp(state);
21967 nk_is_word_boundary(
struct nk_text_edit *state,
int idx)
21971 if (idx <= 0)
return 1;
21973 return (c ==
' ' || c ==
'\t' ||c == 0x3000 || c ==
',' || c ==
';' ||
21974 c ==
'(' || c ==
')' || c ==
'{' || c ==
'}' || c ==
'[' || c ==
']' ||
21978 nk_textedit_move_to_word_previous(
struct nk_text_edit *state)
21980 int c = state->
cursor - 1;
21981 while( c >= 0 && !nk_is_word_boundary(state, c))
21990 nk_textedit_move_to_word_next(
struct nk_text_edit *state)
21993 int c = state->
cursor+1;
21994 while( c < len && !nk_is_word_boundary(state, c))
22003 nk_textedit_prep_selection_at_cursor(
struct nk_text_edit *state)
22006 if (!NK_TEXT_HAS_SELECTION(state))
22016 if (NK_TEXT_HAS_SELECTION(state)) {
22028 const char *text = (
const char *) ctext;
22032 nk_textedit_clamp(state);
22038 nk_textedit_makeundo_insert(state, state->
cursor, glyphs);
22060 while ((text_len < total_len) && glyph_len)
22063 if (unicode == 127)
goto next;
22065 if (unicode ==
'\n' && state->
single_line)
goto next;
22067 if (state->
filter && !state->
filter(state, unicode))
goto next;
22069 if (!NK_TEXT_HAS_SELECTION(state) &&
22073 nk_textedit_makeundo_replace(state, state->
cursor, 1, 1);
22087 nk_textedit_makeundo_insert(state, state->
cursor, 1);
22093 text_len += glyph_len;
22094 glyph_len =
nk_utf_decode(text + text_len, &unicode, total_len-text_len);
22145 nk_textedit_clamp(state);
22146 nk_textedit_prep_selection_at_cursor(state);
22155 if (NK_TEXT_HAS_SELECTION(state))
22156 nk_textedit_move_to_first(state);
22157 else if (state->
cursor > 0)
22164 nk_textedit_prep_selection_at_cursor(state);
22167 nk_textedit_clamp(state);
22173 if (NK_TEXT_HAS_SELECTION(state))
22174 nk_textedit_move_to_last(state);
22176 nk_textedit_clamp(state);
22182 if( !NK_TEXT_HAS_SELECTION( state ) )
22183 nk_textedit_prep_selection_at_cursor(state);
22184 state->
cursor = nk_textedit_move_to_word_previous(state);
22186 nk_textedit_clamp(state );
22188 if (NK_TEXT_HAS_SELECTION(state))
22189 nk_textedit_move_to_first(state);
22191 state->
cursor = nk_textedit_move_to_word_previous(state);
22192 nk_textedit_clamp(state );
22198 if( !NK_TEXT_HAS_SELECTION( state ) )
22199 nk_textedit_prep_selection_at_cursor(state);
22200 state->
cursor = nk_textedit_move_to_word_next(state);
22202 nk_textedit_clamp(state);
22204 if (NK_TEXT_HAS_SELECTION(state))
22205 nk_textedit_move_to_last(state);
22207 state->
cursor = nk_textedit_move_to_word_next(state);
22208 nk_textedit_clamp(state );
22213 struct nk_text_find find;
22214 struct nk_text_edit_row row;
22215 int i, sel = shift_mod;
22224 nk_textedit_prep_selection_at_cursor(state);
22225 else if (NK_TEXT_HAS_SELECTION(state))
22226 nk_textedit_move_to_last(state);
22229 nk_textedit_clamp(state);
22238 int start = find.first_char + find.length;
22241 nk_textedit_layout_row(&row, state, state->
cursor, row_height, font);
22244 for (i=0; i < row.num_chars && x < row.x1; ++i) {
22245 float dx = nk_textedit_get_width(state, start, i, font);
22251 nk_textedit_clamp(state);
22261 struct nk_text_find find;
22262 struct nk_text_edit_row row;
22263 int i, sel = shift_mod;
22272 nk_textedit_prep_selection_at_cursor(state);
22273 else if (NK_TEXT_HAS_SELECTION(state))
22274 nk_textedit_move_to_first(state);
22277 nk_textedit_clamp(state);
22282 if (find.prev_first != find.first_char) {
22287 state->
cursor = find.prev_first;
22288 nk_textedit_layout_row(&row, state, state->
cursor, row_height, font);
22291 for (i=0; i < row.num_chars && x < row.x1; ++i) {
22292 float dx = nk_textedit_get_width(state, find.prev_first, i, font);
22298 nk_textedit_clamp(state);
22309 if (NK_TEXT_HAS_SELECTION(state))
22322 if (NK_TEXT_HAS_SELECTION(state))
22325 nk_textedit_clamp(state);
22326 if (state->
cursor > 0) {
22336 nk_textedit_prep_selection_at_cursor(state);
22347 nk_textedit_prep_selection_at_cursor(state);
22359 struct nk_text_find find;
22360 nk_textedit_clamp(state);
22361 nk_textedit_prep_selection_at_cursor(state);
22369 struct nk_text_find find;
22372 nk_textedit_clamp(state);
22373 nk_textedit_move_to_first(state);
22376 state->
cursor = find.first_char;
22383 struct nk_text_find find;
22384 nk_textedit_clamp(state);
22385 nk_textedit_prep_selection_at_cursor(state);
22389 state->
cursor = find.first_char + find.length;
22394 struct nk_text_find find;
22395 nk_textedit_clamp(state);
22396 nk_textedit_move_to_first(state);
22401 state->
cursor = find.first_char + find.length;
22471 nk_textedit_flush_redo(state);
22476 nk_textedit_discard_undo(state);
22489 nk_textedit_discard_undo(state);
22494 int insert_len,
int delete_len)
22504 if (insert_len == 0) {
22528 r->
where = u.where;
22530 if (u.delete_length)
22549 nk_textedit_discard_redo(s);
22560 for (i=0; i < u.delete_length; ++i)
22569 if (u.insert_length) {
22572 &s->
undo_char[u.char_storage], u.insert_length);
22575 state->
cursor = (short)(u.where + u.insert_length);
22632 nk_textedit_createundo(&state->
undo,
where, 0, length);
22640 for (i=0; i < length; ++i)
22646 int old_length,
int new_length)
22649 nk_rune *p = nk_textedit_createundo(&state->
undo,
where, old_length, new_length);
22651 for (i=0; i < old_length; ++i)
22680 if (!state || !memory || !
size)
return;
22690 if (!state || !alloc)
return;
22695 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
22700 if (!state)
return;
22703 nk_str_init_default(&state->
string);
22717 if (!state)
return;
22741 if (unicode > 128)
return nk_false;
22748 if ((unicode < '0' || unicode >
'9') && unicode !=
'.' && unicode !=
'-')
22756 if ((unicode < '0' || unicode >
'9') && unicode !=
'-')
22764 if ((unicode < '0' || unicode >
'9') &&
22765 (unicode < 'a' || unicode >
'f') &&
22766 (unicode < 'A' || unicode >
'F'))
22774 if (unicode < '0' || unicode >
'7')
22782 if (unicode !=
'0' && unicode !=
'1')
22794 const struct nk_style_edit *style,
float pos_x,
float pos_y,
22795 float x_offset,
const char *text,
int byte_len,
float row_height,
22797 struct nk_color foreground,
int is_selected)
22802 if (!text || !byte_len || !out || !style)
return;
22804 {
int glyph_len = 0;
22807 float line_width = 0;
22809 const char *line = text;
22810 float line_offset = 0;
22811 int line_count = 0;
22815 txt.background = background;
22816 txt.text = foreground;
22818 glyph_len =
nk_utf_decode(text+text_len, &unicode, byte_len-text_len);
22819 if (!glyph_len)
return;
22820 while ((text_len < byte_len) && glyph_len)
22822 if (unicode ==
'\n') {
22825 label.
y = pos_y + line_offset;
22826 label.h = row_height;
22827 label.w = line_width;
22830 label.x += x_offset;
22834 nk_widget_text(out, label, line, (
int)((text + text_len) - line),
22840 line = text + text_len;
22841 line_offset += row_height;
22842 glyph_len =
nk_utf_decode(text + text_len, &unicode, (
int)(byte_len-text_len));
22845 if (unicode ==
'\r') {
22847 glyph_len =
nk_utf_decode(text + text_len, &unicode, byte_len-text_len);
22851 line_width += (float)glyph_width;
22852 text_len += glyph_len;
22853 glyph_len =
nk_utf_decode(text + text_len, &unicode, byte_len-text_len);
22856 if (line_width > 0) {
22859 label.
y = pos_y + line_offset;
22860 label.h = row_height;
22861 label.w = line_width;
22864 label.x += x_offset;
22868 nk_widget_text(out, label, line, (
int)((text + text_len) - line),
22881 char prev_state = 0;
22882 char is_hovered = 0;
22883 char select_all = 0;
22884 char cursor_follow = 0;
22891 if (!state || !out || !style)
22904 old_clip = out->
clip;
22905 nk_unify(&clip, &old_clip, area.x, area.y, area.x + area.w, area.y + area.h);
22908 prev_state = (char)edit->
active;
22912 bounds.
x, bounds.
y, bounds.
w, bounds.
h);
22916 if (!prev_state && edit->
active) {
22919 nk_textedit_clear_state(edit, type, filter);
22933 if (prev_state != edit->
active)
22949 nk_textedit_click(edit, mouse_x, mouse_y, font, row_height);
22952 nk_textedit_drag(edit, mouse_x, mouse_y, font, row_height);
22962 int old_mode = edit->
mode;
22966 nk_textedit_key(edit, (
enum nk_keys)i, shift_mod, font, row_height);
22970 if (old_mode != edit->
mode) {
23003 int begin =
NK_MIN(b, e);
23032 else nk_widget_state_reset(state);
23044 background = &style->
active;
23046 background = &style->
hover;
23047 else background = &style->
normal;
23058 int total_lines = 1;
23062 const char *cursor_ptr = 0;
23063 const char *select_begin_ptr = 0;
23064 const char *select_end_ptr = 0;
23075 float line_width = 0.0f;
23091 while ((text_len < len) && glyph_len)
23094 if (!cursor_ptr && glyphs == edit->
cursor)
23099 const char *remaining;
23102 cursor_pos.
y = (float)(total_lines-1) * row_height;
23103 row_size = nk_text_calculate_text_bounds(font, text+row_begin,
23104 text_len-row_begin, row_height, &remaining,
23105 &out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE);
23106 cursor_pos.
x = row_size.x;
23107 cursor_ptr = text + text_len;
23112 glyphs == selection_begin)
23117 const char *remaining;
23120 selection_offset_start.
y = (float)(
NK_MAX(total_lines-1,0)) * row_height;
23121 row_size = nk_text_calculate_text_bounds(font, text+row_begin,
23122 text_len-row_begin, row_height, &remaining,
23123 &out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE);
23124 selection_offset_start.
x = row_size.x;
23125 select_begin_ptr = text + text_len;
23130 glyphs == selection_end)
23135 const char *remaining;
23138 selection_offset_end.
y = (float)(total_lines-1) * row_height;
23139 row_size = nk_text_calculate_text_bounds(font, text+row_begin,
23140 text_len-row_begin, row_height, &remaining,
23141 &out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE);
23142 selection_offset_end.
x = row_size.x;
23143 select_end_ptr = text + text_len;
23145 if (unicode ==
'\n') {
23146 text_size.
x =
NK_MAX(text_size.
x, line_width);
23151 row_begin = text_len;
23152 glyph_len =
nk_utf_decode(text + text_len, &unicode, len-text_len);
23158 text_len += glyph_len;
23159 line_width += (float)glyph_width;
23161 glyph_len =
nk_utf_decode(text + text_len, &unicode, len-text_len);
23163 text+text_len, glyph_len);
23166 text_size.
y = (float)total_lines * row_height;
23170 cursor_pos.
x = line_width;
23171 cursor_pos.
y = text_size.
y - row_height;
23181 const float scroll_increment = area.w * 0.25f;
23202 float scroll_target;
23203 float scroll_offset;
23212 scroll_step = scroll.
h * 0.10f;
23213 scroll_inc = scroll.
h * 0.01f;
23214 scroll_target = text_size.
y;
23215 edit->
scrollbar.
y = nk_do_scrollbarv(&ws, out, scroll, 0,
23216 scroll_offset, scroll_target, scroll_step, scroll_inc,
23222 {
struct nk_color background_color;
23224 struct nk_color sel_background_color;
23227 struct nk_color cursor_text_color;
23233 background = &style->
active;
23240 background = &style->
hover;
23247 background = &style->
normal;
23255 background_color =
nk_rgba(0,0,0,0);
23256 else background_color = background->
data.
color;
23263 nk_edit_draw_text(out, style, area.x - edit->
scrollbar.
x,
23264 area.y - edit->
scrollbar.
y, 0, begin, l, row_height, font,
23265 background_color, text_color,
nk_false);
23271 NK_ASSERT(select_begin_ptr);
23272 nk_edit_draw_text(out, style, area.x - edit->
scrollbar.
x,
23273 area.y - edit->
scrollbar.
y, 0, begin, (
int)(select_begin_ptr - begin),
23274 row_height, font, background_color, text_color,
nk_false);
23278 NK_ASSERT(select_begin_ptr);
23279 if (!select_end_ptr) {
23283 nk_edit_draw_text(out, style,
23285 area.y + selection_offset_start.
y - edit->
scrollbar.
y,
23286 selection_offset_start.
x,
23287 select_begin_ptr, (
int)(select_end_ptr - select_begin_ptr),
23288 row_height, font, sel_background_color, sel_text_color,
nk_true);
23291 selection_end < edit->
string.len))
23294 const char *begin = select_end_ptr;
23297 NK_ASSERT(select_end_ptr);
23298 nk_edit_draw_text(out, style,
23300 area.y + selection_offset_end.
y - edit->
scrollbar.
y,
23301 selection_offset_end.
x,
23302 begin, (
int)(end - begin), row_height, font,
23303 background_color, text_color,
nk_true);
23311 (cursor_ptr && *cursor_ptr ==
'\n')) {
23315 cursor.h = font->
height;
23316 cursor.x = area.x + cursor_pos.
x - edit->
scrollbar.
x;
23317 cursor.y = area.y + cursor_pos.
y + row_height/2.0f - cursor.h/2.0f;
23327 NK_ASSERT(cursor_ptr);
23330 label.x = area.x + cursor_pos.
x - edit->
scrollbar.
x;
23331 label.y = area.y + cursor_pos.
y - edit->
scrollbar.
y;
23333 label.h = row_height;
23336 txt.background = cursor_color;;
23337 txt.text = cursor_text_color;
23339 nk_widget_text(out, label, cursor_ptr, glyph_len, &txt,
NK_TEXT_LEFT, font);
23352 background = &style->
active;
23355 background = &style->
hover;
23358 background = &style->
normal;
23362 background_color =
nk_rgba(0,0,0,0);
23363 else background_color = background->
data.
color;
23364 nk_edit_draw_text(out, style, area.x - edit->
scrollbar.
x,
23365 area.y - edit->
scrollbar.
y, 0, begin, l, row_height, font,
23366 background_color, text_color,
nk_false);
23379 if (!ctx || !ctx->
current)
return;
23394 if (!ctx || !ctx->
current)
return;
23412 if (!ctx || !memory || !len)
23440 *len =
NK_MIN(*len, max-1);
23445 *len = (int)
edit->string.buffer.allocated;
23468 unsigned char prev_state;
23480 style = &ctx->
style;
23482 if (!state)
return state;
23501 prev_state = (
unsigned char)edit->
active;
23504 filter, edit, &style->
edit, in, style->
font);
23512 }
else if (prev_state && !edit->
active) {
23515 }
return ret_flags;
23539 struct nk_rect drag,
struct nk_property_variant *variant,
23540 float inc_per_pixel)
23543 int left_mouse_click_in_cursor = in &&
23546 nk_widget_state_reset(state);
23550 if (left_mouse_down && left_mouse_click_in_cursor) {
23551 float delta, pixels;
23553 delta = pixels * inc_per_pixel;
23554 switch (variant->kind) {
23556 case NK_PROPERTY_INT:
23557 variant->value.i = variant->value.i + (int)delta;
23558 variant->value.i =
NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i);
23560 case NK_PROPERTY_FLOAT:
23561 variant->value.f = variant->value.f + (float)delta;
23562 variant->value.f =
NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f);
23564 case NK_PROPERTY_DOUBLE:
23565 variant->value.d = variant->value.d + (double)delta;
23566 variant->value.d =
NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d);
23579 struct nk_rect empty,
int *state,
struct nk_property_variant *variant,
23580 float inc_per_pixel)
23582 if (in && *state == NK_PROPERTY_DEFAULT) {
23584 *state = NK_PROPERTY_EDIT;
23586 *state = NK_PROPERTY_DRAG;
23588 *state = NK_PROPERTY_DRAG;
23590 if (*state == NK_PROPERTY_DRAG) {
23591 nk_drag_behavior(ws, in, property, variant, inc_per_pixel);
23598 const char *name,
int len,
const struct nk_user_font *font)
23605 background = &style->
active;
23608 background = &style->
hover;
23611 background = &style->
normal;
23618 text.background =
nk_rgba(0,0,0,0);
23620 text.background = background->
data.
color;
23632 const char *name,
struct nk_property_variant *variant,
23633 float inc_per_pixel,
char *buffer,
int *len,
23634 int *state,
int *cursor,
int *select_begin,
int *select_end,
23636 enum nk_property_filter filter,
struct nk_input *in,
23645 int num_len, name_len;
23662 left.y =
property.y + style->
border +
property.h/2.0f - left.h/2;
23667 label.
x = left.x + left.w + style->
padding.
x;
23676 right.x =
property.x +
property.w - (right.w + style->
padding.
x);
23679 if (*state == NK_PROPERTY_EDIT) {
23685 switch (variant->kind) {
23687 case NK_PROPERTY_INT:
23688 nk_itoa(
string, variant->value.i);
23691 case NK_PROPERTY_FLOAT:
23692 NK_DTOA(
string, (
double)variant->value.f);
23695 case NK_PROPERTY_DOUBLE:
23696 NK_DTOA(
string, variant->value.d);
23706 edit.
w =
NK_MIN(edit.
w, right.x - (label.
x + label.
w));
23707 edit.
x = right.x - (edit.
w + style->
padding.
x);
23708 edit.
y =
property.y + style->
border;
23709 edit.
h =
property.h - (2 * style->
border);
23712 empty.
w = edit.
x - (label.
x + label.
w);
23713 empty.
x = label.
x + label.
w;
23714 empty.
y =
property.y;
23715 empty.
h =
property.h;
23718 old = (*state == NK_PROPERTY_EDIT);
23719 nk_property_behavior(ws, in, property, label, edit, empty, state, variant, inc_per_pixel);
23723 nk_draw_property(out, style, &property, &label, *ws, name, name_len, font);
23727 if (nk_do_button_symbol(ws, out, left, style->
sym_left, behavior, &style->
dec_button, in, font)) {
23728 switch (variant->kind) {
23730 case NK_PROPERTY_INT:
23731 variant->value.i =
NK_CLAMP(variant->min_value.i, variant->value.i - variant->step.i, variant->max_value.i);
break;
23732 case NK_PROPERTY_FLOAT:
23733 variant->value.f =
NK_CLAMP(variant->min_value.f, variant->value.f - variant->step.f, variant->max_value.f);
break;
23734 case NK_PROPERTY_DOUBLE:
23735 variant->value.d =
NK_CLAMP(variant->min_value.d, variant->value.d - variant->step.d, variant->max_value.d);
break;
23739 if (nk_do_button_symbol(ws, out, right, style->
sym_right, behavior, &style->
inc_button, in, font)) {
23740 switch (variant->kind) {
23742 case NK_PROPERTY_INT:
23743 variant->value.i =
NK_CLAMP(variant->min_value.i, variant->value.i + variant->step.i, variant->max_value.i);
break;
23744 case NK_PROPERTY_FLOAT:
23745 variant->value.f =
NK_CLAMP(variant->min_value.f, variant->value.f + variant->step.f, variant->max_value.f);
break;
23746 case NK_PROPERTY_DOUBLE:
23747 variant->value.d =
NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d);
break;
23750 if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) {
23752 NK_MEMCPY(buffer, dst, (
nk_size)*length);
23758 }
else active = (*state == NK_PROPERTY_EDIT);
23762 text_edit->
active = (
unsigned char)active;
23773 filters[filter], text_edit, &style->
edit, (*state == NK_PROPERTY_EDIT) ? in: 0, font);
23776 *cursor = text_edit->
cursor;
23782 if (active && !text_edit->
active) {
23784 *state = NK_PROPERTY_DEFAULT;
23785 buffer[*len] =
'\0';
23786 switch (variant->kind) {
23788 case NK_PROPERTY_INT:
23789 variant->value.i =
nk_strtoi(buffer, 0);
23790 variant->value.i =
NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i);
23792 case NK_PROPERTY_FLOAT:
23794 variant->value.f =
nk_strtof(buffer, 0);
23795 variant->value.f =
NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f);
23797 case NK_PROPERTY_DOUBLE:
23799 variant->value.d =
nk_strtod(buffer, 0);
23800 variant->value.d =
NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d);
23805 NK_LIB struct nk_property_variant
23806 nk_property_variant_int(int value, int min_value, int max_value, int step)
23808 struct nk_property_variant result;
23809 result.kind = NK_PROPERTY_INT;
23810 result.value.i = value;
23811 result.min_value.i = min_value;
23812 result.max_value.i = max_value;
23813 result.step.i = step;
23816 NK_LIB struct nk_property_variant
23817 nk_property_variant_float(float value, float min_value, float max_value, float step)
23819 struct nk_property_variant result;
23820 result.kind = NK_PROPERTY_FLOAT;
23821 result.value.f = value;
23822 result.min_value.f = min_value;
23823 result.max_value.f = max_value;
23824 result.step.f = step;
23827 NK_LIB struct nk_property_variant
23828 nk_property_variant_double(double value, double min_value, double max_value,
23831 struct nk_property_variant result;
23832 result.kind = NK_PROPERTY_DOUBLE;
23833 result.value.d = value;
23834 result.min_value.d = min_value;
23835 result.max_value.d = max_value;
23836 result.step.d = step;
23840 nk_property(
struct nk_context *ctx,
const char *name,
struct nk_property_variant *variant,
23841 float inc_per_pixel,
const enum nk_property_filter filter)
23856 int *select_begin = 0;
23857 int *select_end = 0;
23861 int dummy_state = NK_PROPERTY_DEFAULT;
23862 int dummy_length = 0;
23863 int dummy_cursor = 0;
23864 int dummy_select_begin = 0;
23865 int dummy_select_end = 0;
23875 style = &ctx->
style;
23880 if (name[0] ==
'#') {
23894 buffer = dummy_buffer;
23895 len = &dummy_length;
23896 cursor = &dummy_cursor;
23897 state = &dummy_state;
23898 select_begin = &dummy_select_begin;
23899 select_end = &dummy_select_end;
23903 old_state = *state;
23908 variant, inc_per_pixel, buffer, len, state, cursor, select_begin,
23922 if (*state == NK_PROPERTY_DRAG) {
23928 if (*state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT) {
23929 if (old_state == NK_PROPERTY_DRAG) {
23941 int min,
int *val,
int max,
int step,
float inc_per_pixel)
23943 struct nk_property_variant variant;
23948 if (!ctx || !ctx->
current || !name || !val)
return;
23949 variant = nk_property_variant_int(*val, min, max, step);
23950 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT);
23951 *val = variant.value.i;
23955 float min,
float *val,
float max,
float step,
float inc_per_pixel)
23957 struct nk_property_variant variant;
23962 if (!ctx || !ctx->
current || !name || !val)
return;
23963 variant = nk_property_variant_float(*val, min, max, step);
23964 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
23965 *val = variant.value.f;
23969 double min,
double *val,
double max,
double step,
float inc_per_pixel)
23971 struct nk_property_variant variant;
23976 if (!ctx || !ctx->
current || !name || !val)
return;
23977 variant = nk_property_variant_double(*val, min, max, step);
23978 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
23979 *val = variant.value.d;
23983 int max,
int step,
float inc_per_pixel)
23985 struct nk_property_variant variant;
23989 if (!ctx || !ctx->
current || !name)
return val;
23990 variant = nk_property_variant_int(val, min, max, step);
23991 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT);
23992 val = variant.value.i;
23997 float val,
float max,
float step,
float inc_per_pixel)
23999 struct nk_property_variant variant;
24003 if (!ctx || !ctx->
current || !name)
return val;
24004 variant = nk_property_variant_float(val, min, max, step);
24005 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
24006 val = variant.value.f;
24011 double val,
double max,
double step,
float inc_per_pixel)
24013 struct nk_property_variant variant;
24017 if (!ctx || !ctx->
current || !name)
return val;
24018 variant = nk_property_variant_double(val, min, max, step);
24019 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
24020 val = variant.value.d;
24036 int count,
float min_value,
float max_value)
24044 struct nk_rect bounds = {0, 0, 0, 0};
24053 nk_zero(chart,
sizeof(*chart));
24058 config = &ctx->
style;
24060 style = &config->
chart;
24063 nk_zero(chart,
sizeof(*chart));
24077 slot->
min =
NK_MIN(min_value, max_value);
24078 slot->
max =
NK_MAX(min_value, max_value);
24094 int count,
float min_value,
float max_value)
24102 int count,
float min_value,
float max_value)
24118 slot->
min =
NK_MIN(min_value, max_value);
24119 slot->
max =
NK_MAX(min_value, max_value);
24124 int count,
float min_value,
float max_value)
24131 struct nk_chart *g,
float value,
int slot)
24146 step =
g->w / (float)
g->slots[slot].count;
24147 range =
g->slots[slot].max -
g->slots[slot].min;
24148 ratio = (value -
g->slots[slot].min) / range;
24150 if (
g->slots[slot].index == 0) {
24152 g->slots[slot].last.x =
g->x;
24153 g->slots[slot].last.y = (
g->y +
g->h) - ratio * (
float)
g->h;
24155 bounds.
x =
g->slots[slot].last.x - 2;
24156 bounds.
y =
g->slots[slot].last.y - 2;
24157 bounds.
w = bounds.
h = 4;
24159 color =
g->slots[slot].color;
24165 color =
g->slots[slot].highlight;
24168 g->slots[slot].index += 1;
24173 color =
g->slots[slot].color;
24174 cur.x =
g->x + (float)(step * (
float)
g->slots[slot].index);
24175 cur.y = (
g->y +
g->h) - (ratio * (
float)
g->h);
24176 nk_stroke_line(out,
g->slots[slot].last.x,
g->slots[slot].last.y, cur.x, cur.y, 1.0f, color);
24178 bounds.
x = cur.x - 3;
24179 bounds.
y = cur.y - 3;
24180 bounds.
w = bounds.
h = 6;
24188 color =
g->slots[slot].highlight;
24194 g->slots[slot].last.x = cur.x;
24195 g->slots[slot].last.y = cur.y;
24196 g->slots[slot].index += 1;
24201 struct nk_chart *chart,
float value,
int slot)
24210 struct nk_rect item = {0,0,0,0};
24216 float padding = (float)(chart->
slots[slot].
count-1);
24217 item.
w = (chart->
w - padding) / (
float)(chart->
slots[slot].
count);
24225 item.
y = (chart->
y + chart->
h) - chart->
h * ratio;
24228 item.
y = chart->
y + (chart->
h *
NK_ABS(ratio)) - item.
h;
24230 item.
x = chart->
x + ((float)chart->
slots[slot].
index * item.
w);
24254 NK_ASSERT(slot < ctx->current->layout->chart.slot);
24289 NK_MEMSET(chart, 0,
sizeof(*chart));
24294 int count,
int offset)
24302 if (!ctx || !values || !count)
return;
24304 min_value = values[offset];
24305 max_value = values[offset];
24306 for (i = 0; i < count; ++i) {
24307 min_value =
NK_MIN(values[i + offset], min_value);
24308 max_value =
NK_MAX(values[i + offset], max_value);
24312 for (i = 0; i < count; ++i)
24319 float(*value_getter)(
void* user,
int index),
int count,
int offset)
24326 NK_ASSERT(value_getter);
24327 if (!ctx || !value_getter || !count)
return;
24329 max_value = min_value = value_getter(userdata, offset);
24330 for (i = 0; i < count; ++i) {
24331 float value = value_getter(userdata, i + offset);
24332 min_value =
NK_MIN(value, min_value);
24333 max_value =
NK_MAX(value, max_value);
24337 for (i = 0; i < count; ++i)
24353 nk_color_picker_behavior(
nk_flags *state,
24359 int value_changed = 0;
24360 int hsv_changed = 0;
24364 NK_ASSERT(hue_bar);
24372 value_changed = hsv_changed = 1;
24377 value_changed = hsv_changed = 1;
24386 nk_widget_state_reset(state);
24391 if (value_changed) {
24392 color->
a = hsva[3];
24402 return value_changed;
24413 const float crosshair_size = 7.0f;
24421 NK_ASSERT(hue_bar);
24425 for (i = 0; i < 6; ++i) {
24427 {255, 0, 0, 255}, {255,255,0,255}, {0,255,0,255}, {0, 255,255,255},
24428 {0,0,255,255}, {255, 0, 255, 255}, {255, 0, 0, 255}
24431 nk_rect(hue_bar->
x, hue_bar->
y + (
float)i * (hue_bar->
h/6.0f) + 0.5f,
24432 hue_bar->
w, (hue_bar->
h/6.0f) + 0.5f), hue_colors[i], hue_colors[i],
24433 hue_colors[i+1], hue_colors[i+1]);
24435 line_y = (float)(
int)(hue_bar->
y + hsva[0] * matrix->
h + 0.5f);
24437 line_y, 1,
nk_rgb(255,255,255));
24442 line_y = (float)(
int)(alpha_bar->
y + (1.0f - alpha) * matrix->
h + 0.5f);
24446 line_y, 1,
nk_rgb(255,255,255));
24450 temp =
nk_hsv_f(hsva[0], 1.0f, 1.0f);
24455 {
struct nk_vec2 p;
float S = hsva[1];
float V = hsva[2];
24456 p.
x = (float)(
int)(matrix->
x + S * matrix->
w);
24457 p.y = (float)(
int)(matrix->
y + (1.0f - V) * matrix->
h);
24458 nk_stroke_line(o, p.x - crosshair_size, p.y, p.x-2, p.y, 1.0f, white);
24459 nk_stroke_line(o, p.x + crosshair_size + 1, p.y, p.x+3, p.y, 1.0f, white);
24460 nk_stroke_line(o, p.x, p.y + crosshair_size + 1, p.x, p.y+3, 1.0f, white);
24461 nk_stroke_line(o, p.x, p.y - crosshair_size, p.x, p.y-2, 1.0f, white);}
24464 nk_do_color_picker(
nk_flags *state,
24480 if (!out || !col || !state || !font)
24484 bounds.
x += padding.
x;
24485 bounds.
y += padding.
x;
24486 bounds.
w -= 2 * padding.
x;
24487 bounds.
h -= 2 * padding.
y;
24489 matrix.
x = bounds.
x;
24490 matrix.
y = bounds.
y;
24491 matrix.
h = bounds.
h;
24492 matrix.
w = bounds.
w - (3 * padding.
x + 2 * bar_w);
24495 hue_bar.
y = bounds.
y;
24496 hue_bar.
h = matrix.
h;
24497 hue_bar.
x = matrix.
x + matrix.
w + padding.
x;
24499 alpha_bar.
x = hue_bar.
x + hue_bar.
w + padding.
x;
24500 alpha_bar.
y = bounds.
y;
24501 alpha_bar.
w = bar_w;
24502 alpha_bar.
h = matrix.
h;
24504 ret = nk_color_picker_behavior(state, &bounds, &matrix, &hue_bar,
24505 (fmt ==
NK_RGBA) ? &alpha_bar:0, col, in);
24506 nk_draw_color_picker(out, &matrix, &hue_bar, (fmt ==
NK_RGBA) ? &alpha_bar:0, *col);
24529 config = &ctx->
style;
24532 if (!state)
return 0;
24579 if ((is_clicked && is_open && !is_active) || (is_open && !is_active) ||
24580 (!is_open && !is_active && !is_clicked))
return 0;
24581 if (!nk_nonblock_begin(ctx, 0, body,
24603 NK_ASSERT(selected);
24610 style = &ctx->
style;
24631 text.background =
nk_rgba(0,0,0,0);
24634 text.background = background->
data.
color;
24647 else if (is_clicked)
24655 button.h = button.w;
24668 nk_widget_text(&
win->
buffer, label, selected, len, &text,
24675 return nk_combo_begin(ctx,
win,
size, is_clicked, header);
24701 style = &ctx->
style;
24731 else if (is_clicked)
24739 button.h = button.w;
24757 return nk_combo_begin(ctx,
win,
size, is_clicked, header);
24780 style = &ctx->
style;
24802 sym_background =
nk_rgba(0,0,0,0);
24805 sym_background = background->
data.
color;
24810 struct nk_rect bounds = {0,0,0,0};
24817 else if (is_clicked)
24825 button.h = button.w;
24837 nk_draw_symbol(&
win->
buffer, symbol, bounds, sym_background, symbol_color,
24838 1.0f, style->
font);
24844 return nk_combo_begin(ctx,
win,
size, is_clicked, header);
24868 style = &ctx->
style;
24891 text.background =
nk_rgba(0,0,0,0);
24894 text.background = background->
data.
color;
24907 else if (is_clicked)
24915 button.h = button.w;
24929 nk_draw_symbol(&
win->
buffer, symbol, image, text.background, symbol_color,
24930 1.0f, style->
font);
24940 return nk_combo_begin(ctx,
win,
size, is_clicked, header);
24961 style = &ctx->
style;
24984 struct nk_rect bounds = {0,0,0,0};
24991 else if (is_clicked)
24999 button.h = button.w;
25017 return nk_combo_begin(ctx,
win,
size, is_clicked, header);
25040 style = &ctx->
style;
25060 text.background =
nk_rgba(0,0,0,0);
25063 text.background = background->
data.
color;
25076 else if (is_clicked)
25084 button.h = button.w;
25108 return nk_combo_begin(ctx,
win,
size, is_clicked, header);
25140 const char *text,
nk_flags alignment)
25146 const char *text,
int len,
nk_flags alignment)
25152 const char *label,
nk_flags alignment)
25166 int selected,
int item_height,
struct nk_vec2 size)
25171 struct nk_vec2 window_padding;
25176 if (!ctx || !items ||!count)
25181 max_height = count * item_height + count * (int)item_spacing.y;
25182 max_height += (
int)item_spacing.y * 2 + (int)window_padding.y * 2;
25186 for (i = 0; i < count; ++i) {
25196 int separator,
int selected,
int count,
int item_height,
struct nk_vec2 size)
25201 struct nk_vec2 window_padding;
25202 const char *current_item;
25207 NK_ASSERT(items_separated_by_separator);
25208 if (!ctx || !items_separated_by_separator)
25214 max_height = count * item_height + count * (int)item_spacing.y;
25215 max_height += (
int)item_spacing.y * 2 + (int)window_padding.y * 2;
25219 current_item = items_separated_by_separator;
25220 for (i = 0; i < count; ++i) {
25221 iter = current_item;
25222 while (*iter && *iter != separator) iter++;
25223 length = (int)(iter - current_item);
25224 if (i == selected)
break;
25225 current_item = iter + 1;
25229 current_item = items_separated_by_separator;
25231 for (i = 0; i < count; ++i) {
25232 iter = current_item;
25233 while (*iter && *iter != separator) iter++;
25234 length = (int)(iter - current_item);
25237 current_item = current_item + length + 1;
25245 int selected,
int count,
int item_height,
struct nk_vec2 size)
25251 void *userdata,
int selected,
int count,
int item_height,
struct nk_vec2 size)
25256 struct nk_vec2 window_padding;
25260 NK_ASSERT(item_getter);
25261 if (!ctx || !item_getter)
25267 max_height = count * item_height + count * (int)item_spacing.y;
25268 max_height += (
int)item_spacing.y * 2 + (int)window_padding.y * 2;
25271 item_getter(userdata, selected, &item);
25274 for (i = 0; i < count; ++i) {
25275 item_getter(userdata, i, &item);
25284 int *selected,
int item_height,
struct nk_vec2 size)
25286 *selected =
nk_combo(ctx, items, count, *selected, item_height,
size);
25290 int *selected,
int count,
int item_height,
struct nk_vec2 size)
25292 *selected =
nk_combo_string(ctx, items_separated_by_zeros, *selected, count, item_height,
size);
25296 int separator,
int *selected,
int count,
int item_height,
struct nk_vec2 size)
25299 *selected, count, item_height,
size);
25303 void(*item_getter)(
void* data,
int id,
const char **out_text),
25304 void *userdata,
int *selected,
int count,
int item_height,
struct nk_vec2 size)
25339 w = nk_iceilf(width);
25340 h = nk_iceilf(nk_null_rect.h);
25344 bounds.
x = (
float)
x;
25345 bounds.
y = (float)
y;
25346 bounds.
w = (float)
w;
25347 bounds.
h = (float)
h;
25362 if (!ctx || !ctx->
current)
return;
25385 style = &ctx->
style;
25392 text_width += (4 * padding.
x);
25393 text_height = (style->
font->
height + 2 * padding.
y);
25402 #ifdef NK_INCLUDE_STANDARD_VARARGS
25404 nk_tooltipf(
struct nk_context *ctx,
const char *fmt, ...)
25407 va_start(args, fmt);
25408 nk_tooltipfv(ctx, fmt, args);
25412 nk_tooltipfv(
struct nk_context *ctx,
const char *fmt, va_list args)
25415 nk_strfmt(buf,
NK_LEN(buf), fmt, args);