| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
#ifndef NK_SINGLE_FILE |
| 217 |
#define NK_SINGLE_FILE |
| 218 |
#endif |
| 219 |
|
| 220 |
#ifndef NK_NUKLEAR_H_ |
| 221 |
#define NK_NUKLEAR_H_ |
| 222 |
|
| 223 |
#ifdef __cplusplus |
| 224 |
extern "C" { |
| 225 |
#endif |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
#define NK_UNDEFINED (-1.0f) |
| 234 |
#define NK_UTF_INVALID 0xFFFD |
| 235 |
#define NK_UTF_SIZE 4 |
| 236 |
#ifndef NK_INPUT_MAX |
| 237 |
#define NK_INPUT_MAX 16 |
| 238 |
#endif |
| 239 |
#ifndef NK_MAX_NUMBER_BUFFER |
| 240 |
#define NK_MAX_NUMBER_BUFFER 64 |
| 241 |
#endif |
| 242 |
#ifndef NK_SCROLLBAR_HIDING_TIMEOUT |
| 243 |
#define NK_SCROLLBAR_HIDING_TIMEOUT 4.0f |
| 244 |
#endif |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
#ifndef NK_API |
| 253 |
#ifdef NK_PRIVATE |
| 254 |
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199409L)) |
| 255 |
#define NK_API static inline |
| 256 |
#elif defined(__cplusplus) |
| 257 |
#define NK_API static inline |
| 258 |
#else |
| 259 |
#define NK_API static |
| 260 |
#endif |
| 261 |
#else |
| 262 |
#define NK_API extern |
| 263 |
#endif |
| 264 |
#endif |
| 265 |
#ifndef NK_LIB |
| 266 |
#ifdef NK_SINGLE_FILE |
| 267 |
#define NK_LIB static |
| 268 |
#else |
| 269 |
#define NK_LIB extern |
| 270 |
#endif |
| 271 |
#endif |
| 272 |
|
| 273 |
#define NK_INTERN static |
| 274 |
#define NK_STORAGE static |
| 275 |
#define NK_GLOBAL static |
| 276 |
|
| 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) |
| 283 |
|
| 284 |
#ifdef _MSC_VER |
| 285 |
#define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__COUNTER__) |
| 286 |
#else |
| 287 |
#define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__LINE__) |
| 288 |
#endif |
| 289 |
|
| 290 |
#ifndef NK_STATIC_ASSERT |
| 291 |
#define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1] |
| 292 |
#endif |
| 293 |
|
| 294 |
#ifndef NK_FILE_LINE |
| 295 |
#ifdef _MSC_VER |
| 296 |
#define NK_FILE_LINE __FILE__ ":" NK_MACRO_STRINGIFY(__COUNTER__) |
| 297 |
#else |
| 298 |
#define NK_FILE_LINE __FILE__ ":" NK_MACRO_STRINGIFY(__LINE__) |
| 299 |
#endif |
| 300 |
#endif |
| 301 |
|
| 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)) |
| 305 |
|
| 306 |
#ifdef NK_INCLUDE_STANDARD_VARARGS |
| 307 |
#if defined(_MSC_VER) && (_MSC_VER >= 1600) |
| 308 |
#include <sal.h> |
| 309 |
#define NK_PRINTF_FORMAT_STRING _Printf_format_string_ |
| 310 |
#else |
| 311 |
#define NK_PRINTF_FORMAT_STRING |
| 312 |
#endif |
| 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))) |
| 316 |
#else |
| 317 |
#define NK_PRINTF_VARARG_FUNC(fmtargnumber) |
| 318 |
#define NK_PRINTF_VALIST_FUNC(fmtargnumber) |
| 319 |
#endif |
| 320 |
#endif |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
#ifdef NK_INCLUDE_FIXED_TYPES |
| 330 |
#include <stdint.h> |
| 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 |
| 339 |
#else |
| 340 |
#ifndef NK_INT8 |
| 341 |
#define NK_INT8 signed char |
| 342 |
#endif |
| 343 |
#ifndef NK_UINT8 |
| 344 |
#define NK_UINT8 unsigned char |
| 345 |
#endif |
| 346 |
#ifndef NK_INT16 |
| 347 |
#define NK_INT16 signed short |
| 348 |
#endif |
| 349 |
#ifndef NK_UINT16 |
| 350 |
#define NK_UINT16 unsigned short |
| 351 |
#endif |
| 352 |
#ifndef NK_INT32 |
| 353 |
#if defined(_MSC_VER) |
| 354 |
#define NK_INT32 __int32 |
| 355 |
#else |
| 356 |
#define NK_INT32 signed int |
| 357 |
#endif |
| 358 |
#endif |
| 359 |
#ifndef NK_UINT32 |
| 360 |
#if defined(_MSC_VER) |
| 361 |
#define NK_UINT32 unsigned __int32 |
| 362 |
#else |
| 363 |
#define NK_UINT32 unsigned int |
| 364 |
#endif |
| 365 |
#endif |
| 366 |
#ifndef NK_SIZE_TYPE |
| 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 |
| 374 |
#else |
| 375 |
#define NK_SIZE_TYPE unsigned int |
| 376 |
#endif |
| 377 |
#else |
| 378 |
#define NK_SIZE_TYPE unsigned long |
| 379 |
#endif |
| 380 |
#endif |
| 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 |
| 389 |
#else |
| 390 |
#define NK_POINTER_TYPE unsigned int |
| 391 |
#endif |
| 392 |
#else |
| 393 |
#define NK_POINTER_TYPE unsigned long |
| 394 |
#endif |
| 395 |
#endif |
| 396 |
#endif |
| 397 |
|
| 398 |
typedef NK_INT8 nk_char; |
| 399 |
typedef NK_UINT8 nk_uchar; |
| 400 |
typedef NK_UINT8 nk_byte; |
| 401 |
typedef NK_INT16 nk_short; |
| 402 |
typedef NK_UINT16 nk_ushort; |
| 403 |
typedef NK_INT32 nk_int; |
| 404 |
typedef NK_UINT32 nk_uint; |
| 405 |
typedef NK_SIZE_TYPE nk_size; |
| 406 |
typedef NK_POINTER_TYPE nk_ptr; |
| 407 |
|
| 408 |
typedef nk_uint nk_hash; |
| 409 |
typedef nk_uint nk_flags; |
| 410 |
typedef nk_uint nk_rune; |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
NK_STATIC_ASSERT(sizeof(nk_short) == 2); |
| 416 |
NK_STATIC_ASSERT(sizeof(nk_ushort) == 2); |
| 417 |
NK_STATIC_ASSERT(sizeof(nk_uint) == 4); |
| 418 |
NK_STATIC_ASSERT(sizeof(nk_int) == 4); |
| 419 |
NK_STATIC_ASSERT(sizeof(nk_byte) == 1); |
| 420 |
NK_STATIC_ASSERT(sizeof(nk_flags) >= 4); |
| 421 |
NK_STATIC_ASSERT(sizeof(nk_rune) >= 4); |
| 422 |
NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*)); |
| 423 |
NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*)); |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
struct nk_buffer; |
| 431 |
struct nk_allocator; |
| 432 |
struct nk_command_buffer; |
| 433 |
struct nk_draw_command; |
| 434 |
struct nk_convert_config; |
| 435 |
struct nk_style_item; |
| 436 |
struct nk_text_edit; |
| 437 |
struct nk_draw_list; |
| 438 |
struct nk_user_font; |
| 439 |
struct nk_panel; |
| 440 |
struct nk_context; |
| 441 |
struct nk_draw_vertex_layout_element; |
| 442 |
struct nk_style_button; |
| 443 |
struct nk_style_toggle; |
| 444 |
struct nk_style_selectable; |
| 445 |
struct nk_style_slide; |
| 446 |
struct nk_style_progress; |
| 447 |
struct nk_style_scrollbar; |
| 448 |
struct nk_style_edit; |
| 449 |
struct nk_style_property; |
| 450 |
struct nk_style_chart; |
| 451 |
struct nk_style_combo; |
| 452 |
struct nk_style_tab; |
| 453 |
struct nk_style_window_header; |
| 454 |
struct nk_style_window; |
| 455 |
|
| 456 |
enum {nk_false, nk_true}; |
| 457 |
struct nk_color {nk_byte r,g,b,a;}; |
| 458 |
struct nk_colorf {float r,g,b,a;}; |
| 459 |
struct nk_vec2 {float x,y;}; |
| 460 |
struct nk_vec2i {short x, y;}; |
| 461 |
struct nk_rect {float x,y,w,h;}; |
| 462 |
struct nk_recti {short x,y,w,h;}; |
| 463 |
typedef char nk_glyph[NK_UTF_SIZE]; |
| 464 |
typedef union {void *ptr; int id;} nk_handle; |
| 465 |
struct nk_image {nk_handle handle;unsigned short w,h;unsigned short region[4];}; |
| 466 |
struct nk_cursor {struct nk_image img; struct nk_vec2 size, offset;}; |
| 467 |
struct nk_scroll {nk_uint x, y;}; |
| 468 |
|
| 469 |
enum nk_heading {NK_UP, NK_RIGHT, NK_DOWN, NK_LEFT}; |
| 470 |
enum nk_button_behavior {NK_BUTTON_DEFAULT, NK_BUTTON_REPEATER}; |
| 471 |
enum nk_modify {NK_FIXED = nk_false, NK_MODIFIABLE = nk_true}; |
| 472 |
enum nk_orientation {NK_VERTICAL, NK_HORIZONTAL}; |
| 473 |
enum nk_collapse_states {NK_MINIMIZED = nk_false, NK_MAXIMIZED = nk_true}; |
| 474 |
enum nk_show_states {NK_HIDDEN = nk_false, NK_SHOWN = nk_true}; |
| 475 |
enum nk_chart_type {NK_CHART_LINES, NK_CHART_COLUMN, NK_CHART_MAX}; |
| 476 |
enum nk_chart_event {NK_CHART_HOVERING = 0x01, NK_CHART_CLICKED = 0x02}; |
| 477 |
enum nk_color_format {NK_RGB, NK_RGBA}; |
| 478 |
enum nk_popup_type {NK_POPUP_STATIC, NK_POPUP_DYNAMIC}; |
| 479 |
enum nk_layout_format {NK_DYNAMIC, NK_STATIC}; |
| 480 |
enum nk_tree_type {NK_TREE_NODE, NK_TREE_TAB}; |
| 481 |
|
| 482 |
typedef void*(*nk_plugin_alloc)(nk_handle, void *old, nk_size); |
| 483 |
typedef void (*nk_plugin_free)(nk_handle, void *old); |
| 484 |
typedef int(*nk_plugin_filter)(const struct nk_text_edit*, nk_rune unicode); |
| 485 |
typedef void(*nk_plugin_paste)(nk_handle, struct nk_text_edit*); |
| 486 |
typedef void(*nk_plugin_copy)(nk_handle, const char*, int len); |
| 487 |
|
| 488 |
struct nk_allocator { |
| 489 |
nk_handle userdata; |
| 490 |
nk_plugin_alloc alloc; |
| 491 |
nk_plugin_free free; |
| 492 |
}; |
| 493 |
enum nk_symbol_type { |
| 494 |
NK_SYMBOL_NONE, |
| 495 |
NK_SYMBOL_X, |
| 496 |
NK_SYMBOL_UNDERSCORE, |
| 497 |
NK_SYMBOL_CIRCLE_SOLID, |
| 498 |
NK_SYMBOL_CIRCLE_OUTLINE, |
| 499 |
NK_SYMBOL_RECT_SOLID, |
| 500 |
NK_SYMBOL_RECT_OUTLINE, |
| 501 |
NK_SYMBOL_TRIANGLE_UP, |
| 502 |
NK_SYMBOL_TRIANGLE_DOWN, |
| 503 |
NK_SYMBOL_TRIANGLE_LEFT, |
| 504 |
NK_SYMBOL_TRIANGLE_RIGHT, |
| 505 |
NK_SYMBOL_PLUS, |
| 506 |
NK_SYMBOL_MINUS, |
| 507 |
NK_SYMBOL_MAX |
| 508 |
}; |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
NK_API int nk_init_default(struct nk_context*, const struct nk_user_font*); |
| 565 |
#endif |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
NK_API int nk_init_fixed(struct nk_context*, void *memory, nk_size size, const struct nk_user_font*); |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
NK_API int nk_init(struct nk_context*, struct nk_allocator*, const struct nk_user_font*); |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
NK_API int nk_init_custom(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font*); |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
NK_API void nk_clear(struct nk_context*); |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
NK_API void nk_free(struct nk_context*); |
| 654 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
NK_API void nk_set_user_data(struct nk_context*, nk_handle handle); |
| 668 |
#endif |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
enum nk_keys { |
| 736 |
NK_KEY_NONE, |
| 737 |
NK_KEY_SHIFT, |
| 738 |
NK_KEY_CTRL, |
| 739 |
NK_KEY_DEL, |
| 740 |
NK_KEY_ENTER, |
| 741 |
NK_KEY_TAB, |
| 742 |
NK_KEY_BACKSPACE, |
| 743 |
NK_KEY_COPY, |
| 744 |
NK_KEY_CUT, |
| 745 |
NK_KEY_PASTE, |
| 746 |
NK_KEY_UP, |
| 747 |
NK_KEY_DOWN, |
| 748 |
NK_KEY_LEFT, |
| 749 |
NK_KEY_RIGHT, |
| 750 |
|
| 751 |
NK_KEY_TEXT_INSERT_MODE, |
| 752 |
NK_KEY_TEXT_REPLACE_MODE, |
| 753 |
NK_KEY_TEXT_RESET_MODE, |
| 754 |
NK_KEY_TEXT_LINE_START, |
| 755 |
NK_KEY_TEXT_LINE_END, |
| 756 |
NK_KEY_TEXT_START, |
| 757 |
NK_KEY_TEXT_END, |
| 758 |
NK_KEY_TEXT_UNDO, |
| 759 |
NK_KEY_TEXT_REDO, |
| 760 |
NK_KEY_TEXT_SELECT_ALL, |
| 761 |
NK_KEY_TEXT_WORD_LEFT, |
| 762 |
NK_KEY_TEXT_WORD_RIGHT, |
| 763 |
|
| 764 |
NK_KEY_SCROLL_START, |
| 765 |
NK_KEY_SCROLL_END, |
| 766 |
NK_KEY_SCROLL_DOWN, |
| 767 |
NK_KEY_SCROLL_UP, |
| 768 |
NK_KEY_MAX |
| 769 |
}; |
| 770 |
enum nk_buttons { |
| 771 |
NK_BUTTON_LEFT, |
| 772 |
NK_BUTTON_MIDDLE, |
| 773 |
NK_BUTTON_RIGHT, |
| 774 |
NK_BUTTON_DOUBLE, |
| 775 |
NK_BUTTON_MAX |
| 776 |
}; |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
NK_API void nk_input_begin(struct nk_context*); |
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
NK_API void nk_input_motion(struct nk_context*, int x, int y); |
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
NK_API void nk_input_key(struct nk_context*, enum nk_keys, int down); |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
NK_API void nk_input_button(struct nk_context*, enum nk_buttons, int x, int y, int down); |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
NK_API void nk_input_scroll(struct nk_context*, struct nk_vec2 val); |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
NK_API void nk_input_char(struct nk_context*, char); |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
NK_API void nk_input_glyph(struct nk_context*, const nk_glyph); |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
NK_API void nk_input_unicode(struct nk_context*, nk_rune); |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
NK_API void nk_input_end(struct nk_context*); |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
enum nk_anti_aliasing {NK_ANTI_ALIASING_OFF, NK_ANTI_ALIASING_ON}; |
| 1143 |
enum nk_convert_result { |
| 1144 |
NK_CONVERT_SUCCESS = 0, |
| 1145 |
NK_CONVERT_INVALID_PARAM = 1, |
| 1146 |
NK_CONVERT_COMMAND_BUFFER_FULL = NK_FLAG(1), |
| 1147 |
NK_CONVERT_VERTEX_BUFFER_FULL = NK_FLAG(2), |
| 1148 |
NK_CONVERT_ELEMENT_BUFFER_FULL = NK_FLAG(3) |
| 1149 |
}; |
| 1150 |
struct nk_draw_null_texture { |
| 1151 |
nk_handle texture; |
| 1152 |
struct nk_vec2 uv; |
| 1153 |
}; |
| 1154 |
struct nk_convert_config { |
| 1155 |
float global_alpha; |
| 1156 |
enum nk_anti_aliasing line_AA; |
| 1157 |
enum nk_anti_aliasing shape_AA; |
| 1158 |
unsigned circle_segment_count; |
| 1159 |
unsigned arc_segment_count; |
| 1160 |
unsigned curve_segment_count; |
| 1161 |
struct nk_draw_null_texture null; |
| 1162 |
const struct nk_draw_vertex_layout_element *vertex_layout; |
| 1163 |
nk_size vertex_size; |
| 1164 |
nk_size vertex_alignment; |
| 1165 |
}; |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
NK_API const struct nk_command* nk__begin(struct nk_context*); |
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
NK_API const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); |
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 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 |
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
NK_API nk_flags nk_convert(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); |
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
NK_API const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); |
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
NK_API const struct nk_draw_command* nk__draw_end(const struct nk_context*, const struct nk_buffer*); |
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
NK_API const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*); |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
#define nk_draw_foreach(cmd,ctx, b) for((cmd)=nk__draw_begin(ctx, b); (cmd)!=0; (cmd)=nk__draw_next(cmd, b, ctx)) |
| 1302 |
#endif |
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
enum nk_panel_flags { |
| 1451 |
NK_WINDOW_BORDER = NK_FLAG(0), |
| 1452 |
NK_WINDOW_MOVABLE = NK_FLAG(1), |
| 1453 |
NK_WINDOW_SCALABLE = NK_FLAG(2), |
| 1454 |
NK_WINDOW_CLOSABLE = NK_FLAG(3), |
| 1455 |
NK_WINDOW_MINIMIZABLE = NK_FLAG(4), |
| 1456 |
NK_WINDOW_NO_SCROLLBAR = NK_FLAG(5), |
| 1457 |
NK_WINDOW_TITLE = NK_FLAG(6), |
| 1458 |
NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(7), |
| 1459 |
NK_WINDOW_BACKGROUND = NK_FLAG(8), |
| 1460 |
NK_WINDOW_SCALE_LEFT = NK_FLAG(9), |
| 1461 |
NK_WINDOW_NO_INPUT = NK_FLAG(10) |
| 1462 |
}; |
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
NK_API int nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); |
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
NK_API int nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); |
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
NK_API void nk_end(struct nk_context *ctx); |
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
NK_API struct nk_window *nk_window_find(struct nk_context *ctx, const char *name); |
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
NK_API struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); |
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
NK_API struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); |
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
NK_API struct nk_vec2 nk_window_get_size(const struct nk_context*); |
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
NK_API float nk_window_get_width(const struct nk_context*); |
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
NK_API float nk_window_get_height(const struct nk_context*); |
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
NK_API struct nk_panel* nk_window_get_panel(struct nk_context*); |
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
NK_API struct nk_rect nk_window_get_content_region(struct nk_context*); |
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
NK_API struct nk_vec2 nk_window_get_content_region_min(struct nk_context*); |
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
NK_API struct nk_vec2 nk_window_get_content_region_max(struct nk_context*); |
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
NK_API struct nk_vec2 nk_window_get_content_region_size(struct nk_context*); |
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
NK_API struct nk_command_buffer* nk_window_get_canvas(struct nk_context*); |
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
NK_API void nk_window_get_scroll(struct nk_context*, nk_uint *offset_x, nk_uint *offset_y); |
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
NK_API int nk_window_has_focus(const struct nk_context*); |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
NK_API int nk_window_is_hovered(struct nk_context*); |
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
NK_API int nk_window_is_collapsed(struct nk_context *ctx, const char *name); |
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
NK_API int nk_window_is_closed(struct nk_context*, const char*); |
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
NK_API int nk_window_is_hidden(struct nk_context*, const char*); |
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
NK_API int nk_window_is_active(struct nk_context*, const char*); |
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
NK_API int nk_window_is_any_hovered(struct nk_context*); |
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
NK_API int nk_item_is_any_active(struct nk_context*); |
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
NK_API void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds); |
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
NK_API void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos); |
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
NK_API void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2); |
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
NK_API void nk_window_set_focus(struct nk_context*, const char *name); |
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
NK_API void nk_window_set_scroll(struct nk_context*, nk_uint offset_x, nk_uint offset_y); |
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
NK_API void nk_window_close(struct nk_context *ctx, const char *name); |
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
NK_API void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state); |
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
NK_API void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond); |
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
NK_API void nk_window_show(struct nk_context*, const char *name, enum nk_show_states); |
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); |
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
|
| 2112 |
|
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
NK_API void nk_layout_set_min_row_height(struct nk_context*, float height); |
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
NK_API void nk_layout_reset_min_row_height(struct nk_context*); |
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
NK_API struct nk_rect nk_layout_widget_bounds(struct nk_context*); |
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
NK_API float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); |
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
NK_API void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols); |
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
NK_API void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols); |
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
NK_API void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols); |
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
NK_API void nk_layout_row_push(struct nk_context*, float value); |
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
NK_API void nk_layout_row_end(struct nk_context*); |
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
NK_API void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio); |
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
NK_API void nk_layout_row_template_begin(struct nk_context*, float row_height); |
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
NK_API void nk_layout_row_template_push_dynamic(struct nk_context*); |
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
NK_API void nk_layout_row_template_push_variable(struct nk_context*, float min_width); |
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
NK_API void nk_layout_row_template_push_static(struct nk_context*, float width); |
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
NK_API void nk_layout_row_template_end(struct nk_context*); |
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
NK_API void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); |
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
NK_API void nk_layout_space_push(struct nk_context*, struct nk_rect bounds); |
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
NK_API void nk_layout_space_end(struct nk_context*); |
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
NK_API struct nk_rect nk_layout_space_bounds(struct nk_context*); |
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
|
| 2516 |
|
| 2517 |
|
| 2518 |
NK_API struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); |
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
NK_API struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); |
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
|
| 2545 |
|
| 2546 |
NK_API struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect); |
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
|
| 2560 |
NK_API struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect); |
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
|
| 2640 |
|
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
NK_API int nk_group_begin(struct nk_context*, const char *title, nk_flags); |
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
NK_API int nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); |
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
NK_API void nk_group_end(struct nk_context*); |
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
NK_API int nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); |
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
|
| 2725 |
NK_API int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); |
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
NK_API void nk_group_scrolled_end(struct nk_context*); |
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
|
| 2750 |
NK_API void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset); |
| 2751 |
|
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
NK_API void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset); |
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
|
| 2774 |
|
| 2775 |
|
| 2776 |
|
| 2777 |
|
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
|
| 2823 |
|
| 2824 |
|
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
|
| 2848 |
|
| 2849 |
|
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 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__) |
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
|
| 2868 |
|
| 2869 |
|
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 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) |
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
|
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
|
| 2893 |
NK_API int nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); |
| 2894 |
|
| 2895 |
|
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
|
| 2910 |
|
| 2911 |
|
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 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__) |
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
|
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 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) |
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
NK_API int nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); |
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
|
| 2968 |
NK_API void nk_tree_pop(struct nk_context*); |
| 2969 |
|
| 2970 |
|
| 2971 |
|
| 2972 |
|
| 2973 |
|
| 2974 |
|
| 2975 |
|
| 2976 |
|
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
NK_API int nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); |
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
|
| 2995 |
|
| 2996 |
|
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
|
| 3001 |
NK_API int nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); |
| 3002 |
|
| 3003 |
|
| 3004 |
|
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
NK_API void nk_tree_state_pop(struct nk_context*); |
| 3013 |
|
| 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) |
| 3016 |
NK_API int nk_tree_element_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, int *selected, const char *hash, int len, int seed); |
| 3017 |
NK_API int nk_tree_element_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, int *selected, const char *hash, int len,int seed); |
| 3018 |
NK_API void nk_tree_element_pop(struct nk_context*); |
| 3019 |
|
| 3020 |
|
| 3021 |
|
| 3022 |
|
| 3023 |
|
| 3024 |
|
| 3025 |
struct nk_list_view { |
| 3026 |
|
| 3027 |
int begin, end, count; |
| 3028 |
|
| 3029 |
int total_height; |
| 3030 |
struct nk_context *ctx; |
| 3031 |
nk_uint *scroll_pointer; |
| 3032 |
nk_uint scroll_value; |
| 3033 |
}; |
| 3034 |
NK_API int nk_list_view_begin(struct nk_context*, struct nk_list_view *out, const char *id, nk_flags, int row_height, int row_count); |
| 3035 |
NK_API void nk_list_view_end(struct nk_list_view*); |
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
enum nk_widget_layout_states { |
| 3042 |
NK_WIDGET_INVALID, |
| 3043 |
NK_WIDGET_VALID, |
| 3044 |
NK_WIDGET_ROM |
| 3045 |
}; |
| 3046 |
enum nk_widget_states { |
| 3047 |
NK_WIDGET_STATE_MODIFIED = NK_FLAG(1), |
| 3048 |
NK_WIDGET_STATE_INACTIVE = NK_FLAG(2), |
| 3049 |
NK_WIDGET_STATE_ENTERED = NK_FLAG(3), |
| 3050 |
NK_WIDGET_STATE_HOVER = NK_FLAG(4), |
| 3051 |
NK_WIDGET_STATE_ACTIVED = NK_FLAG(5), |
| 3052 |
NK_WIDGET_STATE_LEFT = NK_FLAG(6), |
| 3053 |
NK_WIDGET_STATE_HOVERED = NK_WIDGET_STATE_HOVER|NK_WIDGET_STATE_MODIFIED, |
| 3054 |
NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED |
| 3055 |
}; |
| 3056 |
NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, const struct nk_context*); |
| 3057 |
NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2); |
| 3058 |
NK_API struct nk_rect nk_widget_bounds(struct nk_context*); |
| 3059 |
NK_API struct nk_vec2 nk_widget_position(struct nk_context*); |
| 3060 |
NK_API struct nk_vec2 nk_widget_size(struct nk_context*); |
| 3061 |
NK_API float nk_widget_width(struct nk_context*); |
| 3062 |
NK_API float nk_widget_height(struct nk_context*); |
| 3063 |
NK_API int nk_widget_is_hovered(struct nk_context*); |
| 3064 |
NK_API int nk_widget_is_mouse_clicked(struct nk_context*, enum nk_buttons); |
| 3065 |
NK_API int nk_widget_has_mouse_click_down(struct nk_context*, enum nk_buttons, int down); |
| 3066 |
NK_API void nk_spacing(struct nk_context*, int cols); |
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
enum nk_text_align { |
| 3073 |
NK_TEXT_ALIGN_LEFT = 0x01, |
| 3074 |
NK_TEXT_ALIGN_CENTERED = 0x02, |
| 3075 |
NK_TEXT_ALIGN_RIGHT = 0x04, |
| 3076 |
NK_TEXT_ALIGN_TOP = 0x08, |
| 3077 |
NK_TEXT_ALIGN_MIDDLE = 0x10, |
| 3078 |
NK_TEXT_ALIGN_BOTTOM = 0x20 |
| 3079 |
}; |
| 3080 |
enum nk_text_alignment { |
| 3081 |
NK_TEXT_LEFT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_LEFT, |
| 3082 |
NK_TEXT_CENTERED = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_CENTERED, |
| 3083 |
NK_TEXT_RIGHT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_RIGHT |
| 3084 |
}; |
| 3085 |
NK_API void nk_text(struct nk_context*, const char*, int, nk_flags); |
| 3086 |
NK_API void nk_text_colored(struct nk_context*, const char*, int, nk_flags, struct nk_color); |
| 3087 |
NK_API void nk_text_wrap(struct nk_context*, const char*, int); |
| 3088 |
NK_API void nk_text_wrap_colored(struct nk_context*, const char*, int, struct nk_color); |
| 3089 |
NK_API void nk_label(struct nk_context*, const char*, nk_flags align); |
| 3090 |
NK_API void nk_label_colored(struct nk_context*, const char*, nk_flags align, struct nk_color); |
| 3091 |
NK_API void nk_label_wrap(struct nk_context*, const char*); |
| 3092 |
NK_API void nk_label_colored_wrap(struct nk_context*, const char*, struct nk_color); |
| 3093 |
NK_API void nk_image(struct nk_context*, struct nk_image); |
| 3094 |
NK_API void nk_image_color(struct nk_context*, struct nk_image, struct nk_color); |
| 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); |
| 3097 |
NK_API void nk_labelf_colored(struct nk_context*, nk_flags, struct nk_color, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(4); |
| 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); |
| 3101 |
NK_API void nk_labelfv_colored(struct nk_context*, nk_flags, struct nk_color, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(4); |
| 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); |
| 3104 |
NK_API void nk_value_bool(struct nk_context*, const char *prefix, int); |
| 3105 |
NK_API void nk_value_int(struct nk_context*, const char *prefix, int); |
| 3106 |
NK_API void nk_value_uint(struct nk_context*, const char *prefix, unsigned int); |
| 3107 |
NK_API void nk_value_float(struct nk_context*, const char *prefix, float); |
| 3108 |
NK_API void nk_value_color_byte(struct nk_context*, const char *prefix, struct nk_color); |
| 3109 |
NK_API void nk_value_color_float(struct nk_context*, const char *prefix, struct nk_color); |
| 3110 |
NK_API void nk_value_color_hex(struct nk_context*, const char *prefix, struct nk_color); |
| 3111 |
#endif |
| 3112 |
|
| 3113 |
|
| 3114 |
|
| 3115 |
|
| 3116 |
|
| 3117 |
NK_API int nk_button_text(struct nk_context*, const char *title, int len); |
| 3118 |
NK_API int nk_button_label(struct nk_context*, const char *title); |
| 3119 |
NK_API int nk_button_color(struct nk_context*, struct nk_color); |
| 3120 |
NK_API int nk_button_symbol(struct nk_context*, enum nk_symbol_type); |
| 3121 |
NK_API int nk_button_image(struct nk_context*, struct nk_image img); |
| 3122 |
NK_API int nk_button_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags text_alignment); |
| 3123 |
NK_API int nk_button_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); |
| 3124 |
NK_API int nk_button_image_label(struct nk_context*, struct nk_image img, const char*, nk_flags text_alignment); |
| 3125 |
NK_API int nk_button_image_text(struct nk_context*, struct nk_image img, const char*, int, nk_flags alignment); |
| 3126 |
NK_API int nk_button_text_styled(struct nk_context*, const struct nk_style_button*, const char *title, int len); |
| 3127 |
NK_API int nk_button_label_styled(struct nk_context*, const struct nk_style_button*, const char *title); |
| 3128 |
NK_API int nk_button_symbol_styled(struct nk_context*, const struct nk_style_button*, enum nk_symbol_type); |
| 3129 |
NK_API int nk_button_image_styled(struct nk_context*, const struct nk_style_button*, struct nk_image img); |
| 3130 |
NK_API int nk_button_symbol_text_styled(struct nk_context*,const struct nk_style_button*, enum nk_symbol_type, const char*, int, nk_flags alignment); |
| 3131 |
NK_API int nk_button_symbol_label_styled(struct nk_context *ctx, const struct nk_style_button *style, enum nk_symbol_type symbol, const char *title, nk_flags align); |
| 3132 |
NK_API int nk_button_image_label_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, nk_flags text_alignment); |
| 3133 |
NK_API int nk_button_image_text_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, int, nk_flags alignment); |
| 3134 |
NK_API void nk_button_set_behavior(struct nk_context*, enum nk_button_behavior); |
| 3135 |
NK_API int nk_button_push_behavior(struct nk_context*, enum nk_button_behavior); |
| 3136 |
NK_API int nk_button_pop_behavior(struct nk_context*); |
| 3137 |
|
| 3138 |
|
| 3139 |
|
| 3140 |
|
| 3141 |
|
| 3142 |
NK_API int nk_check_label(struct nk_context*, const char*, int active); |
| 3143 |
NK_API int nk_check_text(struct nk_context*, const char*, int,int active); |
| 3144 |
NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value); |
| 3145 |
NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value); |
| 3146 |
NK_API int nk_checkbox_label(struct nk_context*, const char*, int *active); |
| 3147 |
NK_API int nk_checkbox_text(struct nk_context*, const char*, int, int *active); |
| 3148 |
NK_API int nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value); |
| 3149 |
NK_API int nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value); |
| 3150 |
|
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
NK_API int nk_radio_label(struct nk_context*, const char*, int *active); |
| 3156 |
NK_API int nk_radio_text(struct nk_context*, const char*, int, int *active); |
| 3157 |
NK_API int nk_option_label(struct nk_context*, const char*, int active); |
| 3158 |
NK_API int nk_option_text(struct nk_context*, const char*, int, int active); |
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
|
| 3163 |
|
| 3164 |
NK_API int nk_selectable_label(struct nk_context*, const char*, nk_flags align, int *value); |
| 3165 |
NK_API int nk_selectable_text(struct nk_context*, const char*, int, nk_flags align, int *value); |
| 3166 |
NK_API int nk_selectable_image_label(struct nk_context*,struct nk_image, const char*, nk_flags align, int *value); |
| 3167 |
NK_API int nk_selectable_image_text(struct nk_context*,struct nk_image, const char*, int, nk_flags align, int *value); |
| 3168 |
NK_API int nk_selectable_symbol_label(struct nk_context*,enum nk_symbol_type, const char*, nk_flags align, int *value); |
| 3169 |
NK_API int nk_selectable_symbol_text(struct nk_context*,enum nk_symbol_type, const char*, int, nk_flags align, int *value); |
| 3170 |
|
| 3171 |
NK_API int nk_select_label(struct nk_context*, const char*, nk_flags align, int value); |
| 3172 |
NK_API int nk_select_text(struct nk_context*, const char*, int, nk_flags align, int value); |
| 3173 |
NK_API int nk_select_image_label(struct nk_context*, struct nk_image,const char*, nk_flags align, int value); |
| 3174 |
NK_API int nk_select_image_text(struct nk_context*, struct nk_image,const char*, int, nk_flags align, int value); |
| 3175 |
NK_API int nk_select_symbol_label(struct nk_context*,enum nk_symbol_type, const char*, nk_flags align, int value); |
| 3176 |
NK_API int nk_select_symbol_text(struct nk_context*,enum nk_symbol_type, const char*, int, nk_flags align, int value); |
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
|
| 3182 |
|
| 3183 |
NK_API float nk_slide_float(struct nk_context*, float min, float val, float max, float step); |
| 3184 |
NK_API int nk_slide_int(struct nk_context*, int min, int val, int max, int step); |
| 3185 |
NK_API int nk_slider_float(struct nk_context*, float min, float *val, float max, float step); |
| 3186 |
NK_API int nk_slider_int(struct nk_context*, int min, int *val, int max, int step); |
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
NK_API int nk_progress(struct nk_context*, nk_size *cur, nk_size max, int modifyable); |
| 3193 |
NK_API nk_size nk_prog(struct nk_context*, nk_size cur, nk_size max, int modifyable); |
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
|
| 3198 |
|
| 3199 |
|
| 3200 |
NK_API struct nk_colorf nk_color_picker(struct nk_context*, struct nk_colorf, enum nk_color_format); |
| 3201 |
NK_API int nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_color_format); |
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
|
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
|
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
|
| 3255 |
|
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
|
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
|
| 3287 |
|
| 3288 |
|
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
|
| 3297 |
|
| 3298 |
NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel); |
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
NK_API void nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel); |
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
NK_API void nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel); |
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
|
| 3363 |
NK_API int nk_propertyi(struct nk_context*, const char *name, int min, int val, int max, int step, float inc_per_pixel); |
| 3364 |
|
| 3365 |
|
| 3366 |
|
| 3367 |
|
| 3368 |
|
| 3369 |
|
| 3370 |
|
| 3371 |
|
| 3372 |
|
| 3373 |
|
| 3374 |
|
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
|
| 3385 |
|
| 3386 |
NK_API float nk_propertyf(struct nk_context*, const char *name, float min, float val, float max, float step, float inc_per_pixel); |
| 3387 |
|
| 3388 |
|
| 3389 |
|
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
|
| 3394 |
|
| 3395 |
|
| 3396 |
|
| 3397 |
|
| 3398 |
|
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
|
| 3409 |
NK_API double nk_propertyd(struct nk_context*, const char *name, double min, double val, double max, double step, float inc_per_pixel); |
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
enum nk_edit_flags { |
| 3416 |
NK_EDIT_DEFAULT = 0, |
| 3417 |
NK_EDIT_READ_ONLY = NK_FLAG(0), |
| 3418 |
NK_EDIT_AUTO_SELECT = NK_FLAG(1), |
| 3419 |
NK_EDIT_SIG_ENTER = NK_FLAG(2), |
| 3420 |
NK_EDIT_ALLOW_TAB = NK_FLAG(3), |
| 3421 |
NK_EDIT_NO_CURSOR = NK_FLAG(4), |
| 3422 |
NK_EDIT_SELECTABLE = NK_FLAG(5), |
| 3423 |
NK_EDIT_CLIPBOARD = NK_FLAG(6), |
| 3424 |
NK_EDIT_CTRL_ENTER_NEWLINE = NK_FLAG(7), |
| 3425 |
NK_EDIT_NO_HORIZONTAL_SCROLL = NK_FLAG(8), |
| 3426 |
NK_EDIT_ALWAYS_INSERT_MODE = NK_FLAG(9), |
| 3427 |
NK_EDIT_MULTILINE = NK_FLAG(10), |
| 3428 |
NK_EDIT_GOTO_END_ON_ACTIVATE = NK_FLAG(11) |
| 3429 |
}; |
| 3430 |
enum nk_edit_types { |
| 3431 |
NK_EDIT_SIMPLE = NK_EDIT_ALWAYS_INSERT_MODE, |
| 3432 |
NK_EDIT_FIELD = NK_EDIT_SIMPLE|NK_EDIT_SELECTABLE|NK_EDIT_CLIPBOARD, |
| 3433 |
NK_EDIT_BOX = NK_EDIT_ALWAYS_INSERT_MODE| NK_EDIT_SELECTABLE| NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB|NK_EDIT_CLIPBOARD, |
| 3434 |
NK_EDIT_EDITOR = NK_EDIT_SELECTABLE|NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB| NK_EDIT_CLIPBOARD |
| 3435 |
}; |
| 3436 |
enum nk_edit_events { |
| 3437 |
NK_EDIT_ACTIVE = NK_FLAG(0), |
| 3438 |
NK_EDIT_INACTIVE = NK_FLAG(1), |
| 3439 |
NK_EDIT_ACTIVATED = NK_FLAG(2), |
| 3440 |
NK_EDIT_DEACTIVATED = NK_FLAG(3), |
| 3441 |
NK_EDIT_COMMITED = NK_FLAG(4) |
| 3442 |
}; |
| 3443 |
NK_API nk_flags nk_edit_string(struct nk_context*, nk_flags, char *buffer, int *len, int max, nk_plugin_filter); |
| 3444 |
NK_API nk_flags nk_edit_string_zero_terminated(struct nk_context*, nk_flags, char *buffer, int max, nk_plugin_filter); |
| 3445 |
NK_API nk_flags nk_edit_buffer(struct nk_context*, nk_flags, struct nk_text_edit*, nk_plugin_filter); |
| 3446 |
NK_API void nk_edit_focus(struct nk_context*, nk_flags flags); |
| 3447 |
NK_API void nk_edit_unfocus(struct nk_context*); |
| 3448 |
|
| 3449 |
|
| 3450 |
|
| 3451 |
|
| 3452 |
|
| 3453 |
NK_API int nk_chart_begin(struct nk_context*, enum nk_chart_type, int num, float min, float max); |
| 3454 |
NK_API int nk_chart_begin_colored(struct nk_context*, enum nk_chart_type, struct nk_color, struct nk_color active, int num, float min, float max); |
| 3455 |
NK_API void nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type, int count, float min_value, float max_value); |
| 3456 |
NK_API void nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type, struct nk_color, struct nk_color active, int count, float min_value, float max_value); |
| 3457 |
NK_API nk_flags nk_chart_push(struct nk_context*, float); |
| 3458 |
NK_API nk_flags nk_chart_push_slot(struct nk_context*, float, int); |
| 3459 |
NK_API void nk_chart_end(struct nk_context*); |
| 3460 |
NK_API void nk_plot(struct nk_context*, enum nk_chart_type, const float *values, int count, int offset); |
| 3461 |
NK_API void nk_plot_function(struct nk_context*, enum nk_chart_type, void *userdata, float(*value_getter)(void* user, int index), int count, int offset); |
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
|
| 3466 |
|
| 3467 |
NK_API int nk_popup_begin(struct nk_context*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds); |
| 3468 |
NK_API void nk_popup_close(struct nk_context*); |
| 3469 |
NK_API void nk_popup_end(struct nk_context*); |
| 3470 |
NK_API void nk_popup_get_scroll(struct nk_context*, nk_uint *offset_x, nk_uint *offset_y); |
| 3471 |
NK_API void nk_popup_set_scroll(struct nk_context*, nk_uint offset_x, nk_uint offset_y); |
| 3472 |
|
| 3473 |
|
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
NK_API int nk_combo(struct nk_context*, const char **items, int count, int selected, int item_height, struct nk_vec2 size); |
| 3478 |
NK_API int nk_combo_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int selected, int count, int item_height, struct nk_vec2 size); |
| 3479 |
NK_API int nk_combo_string(struct nk_context*, const char *items_separated_by_zeros, int selected, int count, int item_height, struct nk_vec2 size); |
| 3480 |
NK_API int nk_combo_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void *userdata, int selected, int count, int item_height, struct nk_vec2 size); |
| 3481 |
NK_API void nk_combobox(struct nk_context*, const char **items, int count, int *selected, int item_height, struct nk_vec2 size); |
| 3482 |
NK_API void nk_combobox_string(struct nk_context*, const char *items_separated_by_zeros, int *selected, int count, int item_height, struct nk_vec2 size); |
| 3483 |
NK_API void nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator,int *selected, int count, int item_height, struct nk_vec2 size); |
| 3484 |
NK_API void nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size); |
| 3485 |
|
| 3486 |
|
| 3487 |
|
| 3488 |
|
| 3489 |
|
| 3490 |
NK_API int nk_combo_begin_text(struct nk_context*, const char *selected, int, struct nk_vec2 size); |
| 3491 |
NK_API int nk_combo_begin_label(struct nk_context*, const char *selected, struct nk_vec2 size); |
| 3492 |
NK_API int nk_combo_begin_color(struct nk_context*, struct nk_color color, struct nk_vec2 size); |
| 3493 |
NK_API int nk_combo_begin_symbol(struct nk_context*, enum nk_symbol_type, struct nk_vec2 size); |
| 3494 |
NK_API int nk_combo_begin_symbol_label(struct nk_context*, const char *selected, enum nk_symbol_type, struct nk_vec2 size); |
| 3495 |
NK_API int nk_combo_begin_symbol_text(struct nk_context*, const char *selected, int, enum nk_symbol_type, struct nk_vec2 size); |
| 3496 |
NK_API int nk_combo_begin_image(struct nk_context*, struct nk_image img, struct nk_vec2 size); |
| 3497 |
NK_API int nk_combo_begin_image_label(struct nk_context*, const char *selected, struct nk_image, struct nk_vec2 size); |
| 3498 |
NK_API int nk_combo_begin_image_text(struct nk_context*, const char *selected, int, struct nk_image, struct nk_vec2 size); |
| 3499 |
NK_API int nk_combo_item_label(struct nk_context*, const char*, nk_flags alignment); |
| 3500 |
NK_API int nk_combo_item_text(struct nk_context*, const char*,int, nk_flags alignment); |
| 3501 |
NK_API int nk_combo_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); |
| 3502 |
NK_API int nk_combo_item_image_text(struct nk_context*, struct nk_image, const char*, int,nk_flags alignment); |
| 3503 |
NK_API int nk_combo_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); |
| 3504 |
NK_API int nk_combo_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); |
| 3505 |
NK_API void nk_combo_close(struct nk_context*); |
| 3506 |
NK_API void nk_combo_end(struct nk_context*); |
| 3507 |
|
| 3508 |
|
| 3509 |
|
| 3510 |
|
| 3511 |
|
| 3512 |
NK_API int nk_contextual_begin(struct nk_context*, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds); |
| 3513 |
NK_API int nk_contextual_item_text(struct nk_context*, const char*, int,nk_flags align); |
| 3514 |
NK_API int nk_contextual_item_label(struct nk_context*, const char*, nk_flags align); |
| 3515 |
NK_API int nk_contextual_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); |
| 3516 |
NK_API int nk_contextual_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment); |
| 3517 |
NK_API int nk_contextual_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); |
| 3518 |
NK_API int nk_contextual_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); |
| 3519 |
NK_API void nk_contextual_close(struct nk_context*); |
| 3520 |
NK_API void nk_contextual_end(struct nk_context*); |
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
|
| 3526 |
NK_API void nk_tooltip(struct nk_context*, const char*); |
| 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); |
| 3530 |
#endif |
| 3531 |
NK_API int nk_tooltip_begin(struct nk_context*, float width); |
| 3532 |
NK_API void nk_tooltip_end(struct nk_context*); |
| 3533 |
|
| 3534 |
|
| 3535 |
|
| 3536 |
|
| 3537 |
|
| 3538 |
NK_API void nk_menubar_begin(struct nk_context*); |
| 3539 |
NK_API void nk_menubar_end(struct nk_context*); |
| 3540 |
NK_API int nk_menu_begin_text(struct nk_context*, const char* title, int title_len, nk_flags align, struct nk_vec2 size); |
| 3541 |
NK_API int nk_menu_begin_label(struct nk_context*, const char*, nk_flags align, struct nk_vec2 size); |
| 3542 |
NK_API int nk_menu_begin_image(struct nk_context*, const char*, struct nk_image, struct nk_vec2 size); |
| 3543 |
NK_API int nk_menu_begin_image_text(struct nk_context*, const char*, int,nk_flags align,struct nk_image, struct nk_vec2 size); |
| 3544 |
NK_API int nk_menu_begin_image_label(struct nk_context*, const char*, nk_flags align,struct nk_image, struct nk_vec2 size); |
| 3545 |
NK_API int nk_menu_begin_symbol(struct nk_context*, const char*, enum nk_symbol_type, struct nk_vec2 size); |
| 3546 |
NK_API int nk_menu_begin_symbol_text(struct nk_context*, const char*, int,nk_flags align,enum nk_symbol_type, struct nk_vec2 size); |
| 3547 |
NK_API int nk_menu_begin_symbol_label(struct nk_context*, const char*, nk_flags align,enum nk_symbol_type, struct nk_vec2 size); |
| 3548 |
NK_API int nk_menu_item_text(struct nk_context*, const char*, int,nk_flags align); |
| 3549 |
NK_API int nk_menu_item_label(struct nk_context*, const char*, nk_flags alignment); |
| 3550 |
NK_API int nk_menu_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); |
| 3551 |
NK_API int nk_menu_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment); |
| 3552 |
NK_API int nk_menu_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); |
| 3553 |
NK_API int nk_menu_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); |
| 3554 |
NK_API void nk_menu_close(struct nk_context*); |
| 3555 |
NK_API void nk_menu_end(struct nk_context*); |
| 3556 |
|
| 3557 |
|
| 3558 |
|
| 3559 |
|
| 3560 |
|
| 3561 |
enum nk_style_colors { |
| 3562 |
NK_COLOR_TEXT, |
| 3563 |
NK_COLOR_WINDOW, |
| 3564 |
NK_COLOR_HEADER, |
| 3565 |
NK_COLOR_BORDER, |
| 3566 |
NK_COLOR_BUTTON, |
| 3567 |
NK_COLOR_BUTTON_HOVER, |
| 3568 |
NK_COLOR_BUTTON_ACTIVE, |
| 3569 |
NK_COLOR_TOGGLE, |
| 3570 |
NK_COLOR_TOGGLE_HOVER, |
| 3571 |
NK_COLOR_TOGGLE_CURSOR, |
| 3572 |
NK_COLOR_SELECT, |
| 3573 |
NK_COLOR_SELECT_ACTIVE, |
| 3574 |
NK_COLOR_SLIDER, |
| 3575 |
NK_COLOR_SLIDER_CURSOR, |
| 3576 |
NK_COLOR_SLIDER_CURSOR_HOVER, |
| 3577 |
NK_COLOR_SLIDER_CURSOR_ACTIVE, |
| 3578 |
NK_COLOR_PROPERTY, |
| 3579 |
NK_COLOR_EDIT, |
| 3580 |
NK_COLOR_EDIT_CURSOR, |
| 3581 |
NK_COLOR_COMBO, |
| 3582 |
NK_COLOR_CHART, |
| 3583 |
NK_COLOR_CHART_COLOR, |
| 3584 |
NK_COLOR_CHART_COLOR_HIGHLIGHT, |
| 3585 |
NK_COLOR_SCROLLBAR, |
| 3586 |
NK_COLOR_SCROLLBAR_CURSOR, |
| 3587 |
NK_COLOR_SCROLLBAR_CURSOR_HOVER, |
| 3588 |
NK_COLOR_SCROLLBAR_CURSOR_ACTIVE, |
| 3589 |
NK_COLOR_TAB_HEADER, |
| 3590 |
NK_COLOR_COUNT |
| 3591 |
}; |
| 3592 |
enum nk_style_cursor { |
| 3593 |
NK_CURSOR_ARROW, |
| 3594 |
NK_CURSOR_TEXT, |
| 3595 |
NK_CURSOR_MOVE, |
| 3596 |
NK_CURSOR_RESIZE_VERTICAL, |
| 3597 |
NK_CURSOR_RESIZE_HORIZONTAL, |
| 3598 |
NK_CURSOR_RESIZE_TOP_LEFT_DOWN_RIGHT, |
| 3599 |
NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT, |
| 3600 |
NK_CURSOR_COUNT |
| 3601 |
}; |
| 3602 |
NK_API void nk_style_default(struct nk_context*); |
| 3603 |
NK_API void nk_style_from_table(struct nk_context*, const struct nk_color*); |
| 3604 |
NK_API void nk_style_load_cursor(struct nk_context*, enum nk_style_cursor, const struct nk_cursor*); |
| 3605 |
NK_API void nk_style_load_all_cursors(struct nk_context*, struct nk_cursor*); |
| 3606 |
NK_API const char* nk_style_get_color_by_name(enum nk_style_colors); |
| 3607 |
NK_API void nk_style_set_font(struct nk_context*, const struct nk_user_font*); |
| 3608 |
NK_API int nk_style_set_cursor(struct nk_context*, enum nk_style_cursor); |
| 3609 |
NK_API void nk_style_show_cursor(struct nk_context*); |
| 3610 |
NK_API void nk_style_hide_cursor(struct nk_context*); |
| 3611 |
|
| 3612 |
NK_API int nk_style_push_font(struct nk_context*, const struct nk_user_font*); |
| 3613 |
NK_API int nk_style_push_float(struct nk_context*, float*, float); |
| 3614 |
NK_API int nk_style_push_vec2(struct nk_context*, struct nk_vec2*, struct nk_vec2); |
| 3615 |
NK_API int nk_style_push_style_item(struct nk_context*, struct nk_style_item*, struct nk_style_item); |
| 3616 |
NK_API int nk_style_push_flags(struct nk_context*, nk_flags*, nk_flags); |
| 3617 |
NK_API int nk_style_push_color(struct nk_context*, struct nk_color*, struct nk_color); |
| 3618 |
|
| 3619 |
NK_API int nk_style_pop_font(struct nk_context*); |
| 3620 |
NK_API int nk_style_pop_float(struct nk_context*); |
| 3621 |
NK_API int nk_style_pop_vec2(struct nk_context*); |
| 3622 |
NK_API int nk_style_pop_style_item(struct nk_context*); |
| 3623 |
NK_API int nk_style_pop_flags(struct nk_context*); |
| 3624 |
NK_API int nk_style_pop_color(struct nk_context*); |
| 3625 |
|
| 3626 |
|
| 3627 |
|
| 3628 |
|
| 3629 |
|
| 3630 |
NK_API struct nk_color nk_rgb(int r, int g, int b); |
| 3631 |
NK_API struct nk_color nk_rgb_iv(const int *rgb); |
| 3632 |
NK_API struct nk_color nk_rgb_bv(const nk_byte* rgb); |
| 3633 |
NK_API struct nk_color nk_rgb_f(float r, float g, float b); |
| 3634 |
NK_API struct nk_color nk_rgb_fv(const float *rgb); |
| 3635 |
NK_API struct nk_color nk_rgb_cf(struct nk_colorf c); |
| 3636 |
NK_API struct nk_color nk_rgb_hex(const char *rgb); |
| 3637 |
|
| 3638 |
NK_API struct nk_color nk_rgba(int r, int g, int b, int a); |
| 3639 |
NK_API struct nk_color nk_rgba_u32(nk_uint); |
| 3640 |
NK_API struct nk_color nk_rgba_iv(const int *rgba); |
| 3641 |
NK_API struct nk_color nk_rgba_bv(const nk_byte *rgba); |
| 3642 |
NK_API struct nk_color nk_rgba_f(float r, float g, float b, float a); |
| 3643 |
NK_API struct nk_color nk_rgba_fv(const float *rgba); |
| 3644 |
NK_API struct nk_color nk_rgba_cf(struct nk_colorf c); |
| 3645 |
NK_API struct nk_color nk_rgba_hex(const char *rgb); |
| 3646 |
|
| 3647 |
NK_API struct nk_colorf nk_hsva_colorf(float h, float s, float v, float a); |
| 3648 |
NK_API struct nk_colorf nk_hsva_colorfv(float *c); |
| 3649 |
NK_API void nk_colorf_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_colorf in); |
| 3650 |
NK_API void nk_colorf_hsva_fv(float *hsva, struct nk_colorf in); |
| 3651 |
|
| 3652 |
NK_API struct nk_color nk_hsv(int h, int s, int v); |
| 3653 |
NK_API struct nk_color nk_hsv_iv(const int *hsv); |
| 3654 |
NK_API struct nk_color nk_hsv_bv(const nk_byte *hsv); |
| 3655 |
NK_API struct nk_color nk_hsv_f(float h, float s, float v); |
| 3656 |
NK_API struct nk_color nk_hsv_fv(const float *hsv); |
| 3657 |
|
| 3658 |
NK_API struct nk_color nk_hsva(int h, int s, int v, int a); |
| 3659 |
NK_API struct nk_color nk_hsva_iv(const int *hsva); |
| 3660 |
NK_API struct nk_color nk_hsva_bv(const nk_byte *hsva); |
| 3661 |
NK_API struct nk_color nk_hsva_f(float h, float s, float v, float a); |
| 3662 |
NK_API struct nk_color nk_hsva_fv(const float *hsva); |
| 3663 |
|
| 3664 |
|
| 3665 |
NK_API void nk_color_f(float *r, float *g, float *b, float *a, struct nk_color); |
| 3666 |
NK_API void nk_color_fv(float *rgba_out, struct nk_color); |
| 3667 |
NK_API struct nk_colorf nk_color_cf(struct nk_color); |
| 3668 |
NK_API void nk_color_d(double *r, double *g, double *b, double *a, struct nk_color); |
| 3669 |
NK_API void nk_color_dv(double *rgba_out, struct nk_color); |
| 3670 |
|
| 3671 |
NK_API nk_uint nk_color_u32(struct nk_color); |
| 3672 |
NK_API void nk_color_hex_rgba(char *output, struct nk_color); |
| 3673 |
NK_API void nk_color_hex_rgb(char *output, struct nk_color); |
| 3674 |
|
| 3675 |
NK_API void nk_color_hsv_i(int *out_h, int *out_s, int *out_v, struct nk_color); |
| 3676 |
NK_API void nk_color_hsv_b(nk_byte *out_h, nk_byte *out_s, nk_byte *out_v, struct nk_color); |
| 3677 |
NK_API void nk_color_hsv_iv(int *hsv_out, struct nk_color); |
| 3678 |
NK_API void nk_color_hsv_bv(nk_byte *hsv_out, struct nk_color); |
| 3679 |
NK_API void nk_color_hsv_f(float *out_h, float *out_s, float *out_v, struct nk_color); |
| 3680 |
NK_API void nk_color_hsv_fv(float *hsv_out, struct nk_color); |
| 3681 |
|
| 3682 |
NK_API void nk_color_hsva_i(int *h, int *s, int *v, int *a, struct nk_color); |
| 3683 |
NK_API void nk_color_hsva_b(nk_byte *h, nk_byte *s, nk_byte *v, nk_byte *a, struct nk_color); |
| 3684 |
NK_API void nk_color_hsva_iv(int *hsva_out, struct nk_color); |
| 3685 |
NK_API void nk_color_hsva_bv(nk_byte *hsva_out, struct nk_color); |
| 3686 |
NK_API void nk_color_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_color); |
| 3687 |
NK_API void nk_color_hsva_fv(float *hsva_out, struct nk_color); |
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
NK_API nk_handle nk_handle_ptr(void*); |
| 3694 |
NK_API nk_handle nk_handle_id(int); |
| 3695 |
NK_API struct nk_image nk_image_handle(nk_handle); |
| 3696 |
NK_API struct nk_image nk_image_ptr(void*); |
| 3697 |
NK_API struct nk_image nk_image_id(int); |
| 3698 |
NK_API int nk_image_is_subimage(const struct nk_image* img); |
| 3699 |
NK_API struct nk_image nk_subimage_ptr(void*, unsigned short w, unsigned short h, struct nk_rect sub_region); |
| 3700 |
NK_API struct nk_image nk_subimage_id(int, unsigned short w, unsigned short h, struct nk_rect sub_region); |
| 3701 |
NK_API struct nk_image nk_subimage_handle(nk_handle, unsigned short w, unsigned short h, struct nk_rect sub_region); |
| 3702 |
|
| 3703 |
|
| 3704 |
|
| 3705 |
|
| 3706 |
|
| 3707 |
NK_API nk_hash nk_murmur_hash(const void *key, int len, nk_hash seed); |
| 3708 |
NK_API void nk_triangle_from_direction(struct nk_vec2 *result, struct nk_rect r, float pad_x, float pad_y, enum nk_heading); |
| 3709 |
|
| 3710 |
NK_API struct nk_vec2 nk_vec2(float x, float y); |
| 3711 |
NK_API struct nk_vec2 nk_vec2i(int x, int y); |
| 3712 |
NK_API struct nk_vec2 nk_vec2v(const float *xy); |
| 3713 |
NK_API struct nk_vec2 nk_vec2iv(const int *xy); |
| 3714 |
|
| 3715 |
NK_API struct nk_rect nk_get_null_rect(void); |
| 3716 |
NK_API struct nk_rect nk_rect(float x, float y, float w, float h); |
| 3717 |
NK_API struct nk_rect nk_recti(int x, int y, int w, int h); |
| 3718 |
NK_API struct nk_rect nk_recta(struct nk_vec2 pos, struct nk_vec2 size); |
| 3719 |
NK_API struct nk_rect nk_rectv(const float *xywh); |
| 3720 |
NK_API struct nk_rect nk_rectiv(const int *xywh); |
| 3721 |
NK_API struct nk_vec2 nk_rect_pos(struct nk_rect); |
| 3722 |
NK_API struct nk_vec2 nk_rect_size(struct nk_rect); |
| 3723 |
|
| 3724 |
|
| 3725 |
|
| 3726 |
|
| 3727 |
|
| 3728 |
NK_API int nk_strlen(const char *str); |
| 3729 |
NK_API int nk_stricmp(const char *s1, const char *s2); |
| 3730 |
NK_API int nk_stricmpn(const char *s1, const char *s2, int n); |
| 3731 |
NK_API int nk_strtoi(const char *str, const char **endptr); |
| 3732 |
NK_API float nk_strtof(const char *str, const char **endptr); |
| 3733 |
NK_API double nk_strtod(const char *str, const char **endptr); |
| 3734 |
NK_API int nk_strfilter(const char *text, const char *regexp); |
| 3735 |
NK_API int nk_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score); |
| 3736 |
NK_API int nk_strmatch_fuzzy_text(const char *txt, int txt_len, const char *pattern, int *out_score); |
| 3737 |
|
| 3738 |
|
| 3739 |
|
| 3740 |
|
| 3741 |
|
| 3742 |
NK_API int nk_utf_decode(const char*, nk_rune*, int); |
| 3743 |
NK_API int nk_utf_encode(nk_rune, char*, int); |
| 3744 |
NK_API int nk_utf_len(const char*, int byte_len); |
| 3745 |
NK_API const char* nk_utf_at(const char *buffer, int length, int index, nk_rune *unicode, int *len); |
| 3746 |
|
| 3747 |
|
| 3748 |
|
| 3749 |
|
| 3750 |
|
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
|
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
|
| 3764 |
|
| 3765 |
|
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
|
| 3772 |
|
| 3773 |
|
| 3774 |
|
| 3775 |
|
| 3776 |
|
| 3777 |
|
| 3778 |
|
| 3779 |
|
| 3780 |
|
| 3781 |
|
| 3782 |
|
| 3783 |
|
| 3784 |
|
| 3785 |
|
| 3786 |
|
| 3787 |
|
| 3788 |
|
| 3789 |
|
| 3790 |
|
| 3791 |
|
| 3792 |
|
| 3793 |
|
| 3794 |
|
| 3795 |
|
| 3796 |
|
| 3797 |
|
| 3798 |
|
| 3799 |
|
| 3800 |
|
| 3801 |
|
| 3802 |
|
| 3803 |
|
| 3804 |
|
| 3805 |
|
| 3806 |
|
| 3807 |
|
| 3808 |
|
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
|
| 3816 |
|
| 3817 |
|
| 3818 |
|
| 3819 |
|
| 3820 |
|
| 3821 |
|
| 3822 |
|
| 3823 |
|
| 3824 |
|
| 3825 |
|
| 3826 |
|
| 3827 |
|
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
|
| 3852 |
|
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
|
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
|
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
|
| 3876 |
|
| 3877 |
|
| 3878 |
|
| 3879 |
|
| 3880 |
|
| 3881 |
|
| 3882 |
|
| 3883 |
|
| 3884 |
|
| 3885 |
|
| 3886 |
|
| 3887 |
|
| 3888 |
|
| 3889 |
|
| 3890 |
|
| 3891 |
|
| 3892 |
|
| 3893 |
|
| 3894 |
|
| 3895 |
struct nk_user_font_glyph; |
| 3896 |
typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len); |
| 3897 |
typedef void(*nk_query_font_glyph_f)(nk_handle handle, float font_height, |
| 3898 |
struct nk_user_font_glyph *glyph, |
| 3899 |
nk_rune codepoint, nk_rune next_codepoint); |
| 3900 |
|
| 3901 |
#if defined(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) || defined(NK_INCLUDE_SOFTWARE_FONT) |
| 3902 |
struct nk_user_font_glyph { |
| 3903 |
struct nk_vec2 uv[2]; |
| 3904 |
|
| 3905 |
struct nk_vec2 offset; |
| 3906 |
|
| 3907 |
float width, height; |
| 3908 |
|
| 3909 |
float xadvance; |
| 3910 |
|
| 3911 |
}; |
| 3912 |
#endif |
| 3913 |
|
| 3914 |
struct nk_user_font { |
| 3915 |
nk_handle userdata; |
| 3916 |
|
| 3917 |
float height; |
| 3918 |
|
| 3919 |
nk_text_width_f width; |
| 3920 |
|
| 3921 |
#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT |
| 3922 |
nk_query_font_glyph_f query; |
| 3923 |
|
| 3924 |
nk_handle texture; |
| 3925 |
|
| 3926 |
#endif |
| 3927 |
}; |
| 3928 |
|
| 3929 |
#ifdef NK_INCLUDE_FONT_BAKING |
| 3930 |
enum nk_font_coord_type { |
| 3931 |
NK_COORD_UV, |
| 3932 |
NK_COORD_PIXEL |
| 3933 |
}; |
| 3934 |
|
| 3935 |
struct nk_font; |
| 3936 |
struct nk_baked_font { |
| 3937 |
float height; |
| 3938 |
|
| 3939 |
float ascent, descent; |
| 3940 |
|
| 3941 |
nk_rune glyph_offset; |
| 3942 |
|
| 3943 |
nk_rune glyph_count; |
| 3944 |
|
| 3945 |
const nk_rune *ranges; |
| 3946 |
|
| 3947 |
}; |
| 3948 |
|
| 3949 |
struct nk_font_config { |
| 3950 |
struct nk_font_config *next; |
| 3951 |
|
| 3952 |
void *ttf_blob; |
| 3953 |
|
| 3954 |
|
| 3955 |
nk_size ttf_size; |
| 3956 |
|
| 3957 |
|
| 3958 |
|
| 3959 |
unsigned char ttf_data_owned_by_atlas; |
| 3960 |
|
| 3961 |
unsigned char merge_mode; |
| 3962 |
|
| 3963 |
unsigned char pixel_snap; |
| 3964 |
|
| 3965 |
unsigned char oversample_v, oversample_h; |
| 3966 |
|
| 3967 |
unsigned char padding[3]; |
| 3968 |
|
| 3969 |
float size; |
| 3970 |
|
| 3971 |
enum nk_font_coord_type coord_type; |
| 3972 |
|
| 3973 |
struct nk_vec2 spacing; |
| 3974 |
|
| 3975 |
const nk_rune *range; |
| 3976 |
|
| 3977 |
struct nk_baked_font *font; |
| 3978 |
|
| 3979 |
nk_rune fallback_glyph; |
| 3980 |
|
| 3981 |
struct nk_font_config *n; |
| 3982 |
struct nk_font_config *p; |
| 3983 |
}; |
| 3984 |
|
| 3985 |
struct nk_font_glyph { |
| 3986 |
nk_rune codepoint; |
| 3987 |
float xadvance; |
| 3988 |
float x0, y0, x1, y1, w, h; |
| 3989 |
float u0, v0, u1, v1; |
| 3990 |
}; |
| 3991 |
|
| 3992 |
struct nk_font { |
| 3993 |
struct nk_font *next; |
| 3994 |
struct nk_user_font handle; |
| 3995 |
struct nk_baked_font info; |
| 3996 |
float scale; |
| 3997 |
struct nk_font_glyph *glyphs; |
| 3998 |
const struct nk_font_glyph *fallback; |
| 3999 |
nk_rune fallback_codepoint; |
| 4000 |
nk_handle texture; |
| 4001 |
struct nk_font_config *config; |
| 4002 |
}; |
| 4003 |
|
| 4004 |
enum nk_font_atlas_format { |
| 4005 |
NK_FONT_ATLAS_ALPHA8, |
| 4006 |
NK_FONT_ATLAS_RGBA32 |
| 4007 |
}; |
| 4008 |
|
| 4009 |
struct nk_font_atlas { |
| 4010 |
void *pixel; |
| 4011 |
int tex_width; |
| 4012 |
int tex_height; |
| 4013 |
|
| 4014 |
struct nk_allocator permanent; |
| 4015 |
struct nk_allocator temporary; |
| 4016 |
|
| 4017 |
struct nk_recti custom; |
| 4018 |
struct nk_cursor cursors[NK_CURSOR_COUNT]; |
| 4019 |
|
| 4020 |
int glyph_count; |
| 4021 |
struct nk_font_glyph *glyphs; |
| 4022 |
struct nk_font *default_font; |
| 4023 |
struct nk_font *fonts; |
| 4024 |
struct nk_font_config *config; |
| 4025 |
int font_num; |
| 4026 |
}; |
| 4027 |
|
| 4028 |
|
| 4029 |
NK_API const nk_rune *nk_font_default_glyph_ranges(void); |
| 4030 |
NK_API const nk_rune *nk_font_chinese_glyph_ranges(void); |
| 4031 |
NK_API const nk_rune *nk_font_cyrillic_glyph_ranges(void); |
| 4032 |
NK_API const nk_rune *nk_font_korean_glyph_ranges(void); |
| 4033 |
|
| 4034 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 4035 |
NK_API void nk_font_atlas_init_default(struct nk_font_atlas*); |
| 4036 |
#endif |
| 4037 |
NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*); |
| 4038 |
NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, struct nk_allocator *persistent, struct nk_allocator *transient); |
| 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*); |
| 4044 |
#endif |
| 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*); |
| 4048 |
#endif |
| 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); |
| 4052 |
NK_API void nk_font_atlas_end(struct nk_font_atlas*, nk_handle tex, struct nk_draw_null_texture*); |
| 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*); |
| 4056 |
|
| 4057 |
#endif |
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
|
| 4071 |
|
| 4072 |
|
| 4073 |
|
| 4074 |
|
| 4075 |
|
| 4076 |
|
| 4077 |
|
| 4078 |
|
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
|
| 4085 |
|
| 4086 |
|
| 4087 |
|
| 4088 |
|
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
struct nk_memory_status { |
| 4093 |
void *memory; |
| 4094 |
unsigned int type; |
| 4095 |
nk_size size; |
| 4096 |
nk_size allocated; |
| 4097 |
nk_size needed; |
| 4098 |
nk_size calls; |
| 4099 |
}; |
| 4100 |
|
| 4101 |
enum nk_allocation_type { |
| 4102 |
NK_BUFFER_FIXED, |
| 4103 |
NK_BUFFER_DYNAMIC |
| 4104 |
}; |
| 4105 |
|
| 4106 |
enum nk_buffer_allocation_type { |
| 4107 |
NK_BUFFER_FRONT, |
| 4108 |
NK_BUFFER_BACK, |
| 4109 |
NK_BUFFER_MAX |
| 4110 |
}; |
| 4111 |
|
| 4112 |
struct nk_buffer_marker { |
| 4113 |
int active; |
| 4114 |
nk_size offset; |
| 4115 |
}; |
| 4116 |
|
| 4117 |
struct nk_memory {void *ptr;nk_size size;}; |
| 4118 |
struct nk_buffer { |
| 4119 |
struct nk_buffer_marker marker[NK_BUFFER_MAX]; |
| 4120 |
|
| 4121 |
struct nk_allocator pool; |
| 4122 |
|
| 4123 |
enum nk_allocation_type type; |
| 4124 |
|
| 4125 |
struct nk_memory memory; |
| 4126 |
|
| 4127 |
float grow_factor; |
| 4128 |
|
| 4129 |
nk_size allocated; |
| 4130 |
|
| 4131 |
nk_size needed; |
| 4132 |
|
| 4133 |
nk_size calls; |
| 4134 |
|
| 4135 |
nk_size size; |
| 4136 |
|
| 4137 |
}; |
| 4138 |
|
| 4139 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 4140 |
NK_API void nk_buffer_init_default(struct nk_buffer*); |
| 4141 |
#endif |
| 4142 |
NK_API void nk_buffer_init(struct nk_buffer*, const struct nk_allocator*, nk_size size); |
| 4143 |
NK_API void nk_buffer_init_fixed(struct nk_buffer*, void *memory, nk_size size); |
| 4144 |
NK_API void nk_buffer_info(struct nk_memory_status*, struct nk_buffer*); |
| 4145 |
NK_API void nk_buffer_push(struct nk_buffer*, enum nk_buffer_allocation_type type, const void *memory, nk_size size, nk_size align); |
| 4146 |
NK_API void nk_buffer_mark(struct nk_buffer*, enum nk_buffer_allocation_type type); |
| 4147 |
NK_API void nk_buffer_reset(struct nk_buffer*, enum nk_buffer_allocation_type type); |
| 4148 |
NK_API void nk_buffer_clear(struct nk_buffer*); |
| 4149 |
NK_API void nk_buffer_free(struct nk_buffer*); |
| 4150 |
NK_API void *nk_buffer_memory(struct nk_buffer*); |
| 4151 |
NK_API const void *nk_buffer_memory_const(const struct nk_buffer*); |
| 4152 |
NK_API nk_size nk_buffer_total(struct nk_buffer*); |
| 4153 |
|
| 4154 |
|
| 4155 |
|
| 4156 |
|
| 4157 |
|
| 4158 |
|
| 4159 |
|
| 4160 |
|
| 4161 |
|
| 4162 |
|
| 4163 |
|
| 4164 |
struct nk_str { |
| 4165 |
struct nk_buffer buffer; |
| 4166 |
int len; |
| 4167 |
}; |
| 4168 |
|
| 4169 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 4170 |
NK_API void nk_str_init_default(struct nk_str*); |
| 4171 |
#endif |
| 4172 |
NK_API void nk_str_init(struct nk_str*, const struct nk_allocator*, nk_size size); |
| 4173 |
NK_API void nk_str_init_fixed(struct nk_str*, void *memory, nk_size size); |
| 4174 |
NK_API void nk_str_clear(struct nk_str*); |
| 4175 |
NK_API void nk_str_free(struct nk_str*); |
| 4176 |
|
| 4177 |
NK_API int nk_str_append_text_char(struct nk_str*, const char*, int); |
| 4178 |
NK_API int nk_str_append_str_char(struct nk_str*, const char*); |
| 4179 |
NK_API int nk_str_append_text_utf8(struct nk_str*, const char*, int); |
| 4180 |
NK_API int nk_str_append_str_utf8(struct nk_str*, const char*); |
| 4181 |
NK_API int nk_str_append_text_runes(struct nk_str*, const nk_rune*, int); |
| 4182 |
NK_API int nk_str_append_str_runes(struct nk_str*, const nk_rune*); |
| 4183 |
|
| 4184 |
NK_API int nk_str_insert_at_char(struct nk_str*, int pos, const char*, int); |
| 4185 |
NK_API int nk_str_insert_at_rune(struct nk_str*, int pos, const char*, int); |
| 4186 |
|
| 4187 |
NK_API int nk_str_insert_text_char(struct nk_str*, int pos, const char*, int); |
| 4188 |
NK_API int nk_str_insert_str_char(struct nk_str*, int pos, const char*); |
| 4189 |
NK_API int nk_str_insert_text_utf8(struct nk_str*, int pos, const char*, int); |
| 4190 |
NK_API int nk_str_insert_str_utf8(struct nk_str*, int pos, const char*); |
| 4191 |
NK_API int nk_str_insert_text_runes(struct nk_str*, int pos, const nk_rune*, int); |
| 4192 |
NK_API int nk_str_insert_str_runes(struct nk_str*, int pos, const nk_rune*); |
| 4193 |
|
| 4194 |
NK_API void nk_str_remove_chars(struct nk_str*, int len); |
| 4195 |
NK_API void nk_str_remove_runes(struct nk_str *str, int len); |
| 4196 |
NK_API void nk_str_delete_chars(struct nk_str*, int pos, int len); |
| 4197 |
NK_API void nk_str_delete_runes(struct nk_str*, int pos, int len); |
| 4198 |
|
| 4199 |
NK_API char *nk_str_at_char(struct nk_str*, int pos); |
| 4200 |
NK_API char *nk_str_at_rune(struct nk_str*, int pos, nk_rune *unicode, int *len); |
| 4201 |
NK_API nk_rune nk_str_rune_at(const struct nk_str*, int pos); |
| 4202 |
NK_API const char *nk_str_at_char_const(const struct nk_str*, int pos); |
| 4203 |
NK_API const char *nk_str_at_const(const struct nk_str*, int pos, nk_rune *unicode, int *len); |
| 4204 |
|
| 4205 |
NK_API char *nk_str_get(struct nk_str*); |
| 4206 |
NK_API const char *nk_str_get_const(const struct nk_str*); |
| 4207 |
NK_API int nk_str_len(struct nk_str*); |
| 4208 |
NK_API int nk_str_len_char(struct nk_str*); |
| 4209 |
|
| 4210 |
|
| 4211 |
|
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
|
| 4216 |
|
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
|
| 4224 |
|
| 4225 |
|
| 4226 |
|
| 4227 |
|
| 4228 |
|
| 4229 |
|
| 4230 |
|
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
|
| 4237 |
|
| 4238 |
#ifndef NK_TEXTEDIT_UNDOSTATECOUNT |
| 4239 |
#define NK_TEXTEDIT_UNDOSTATECOUNT 99 |
| 4240 |
#endif |
| 4241 |
|
| 4242 |
#ifndef NK_TEXTEDIT_UNDOCHARCOUNT |
| 4243 |
#define NK_TEXTEDIT_UNDOCHARCOUNT 999 |
| 4244 |
#endif |
| 4245 |
|
| 4246 |
struct nk_text_edit; |
| 4247 |
struct nk_clipboard { |
| 4248 |
nk_handle userdata; |
| 4249 |
nk_plugin_paste paste; |
| 4250 |
nk_plugin_copy copy; |
| 4251 |
}; |
| 4252 |
|
| 4253 |
struct nk_text_undo_record { |
| 4254 |
int where; |
| 4255 |
short insert_length; |
| 4256 |
short delete_length; |
| 4257 |
short char_storage; |
| 4258 |
}; |
| 4259 |
|
| 4260 |
struct nk_text_undo_state { |
| 4261 |
struct nk_text_undo_record undo_rec[NK_TEXTEDIT_UNDOSTATECOUNT]; |
| 4262 |
nk_rune undo_char[NK_TEXTEDIT_UNDOCHARCOUNT]; |
| 4263 |
short undo_point; |
| 4264 |
short redo_point; |
| 4265 |
short undo_char_point; |
| 4266 |
short redo_char_point; |
| 4267 |
}; |
| 4268 |
|
| 4269 |
enum nk_text_edit_type { |
| 4270 |
NK_TEXT_EDIT_SINGLE_LINE, |
| 4271 |
NK_TEXT_EDIT_MULTI_LINE |
| 4272 |
}; |
| 4273 |
|
| 4274 |
enum nk_text_edit_mode { |
| 4275 |
NK_TEXT_EDIT_MODE_VIEW, |
| 4276 |
NK_TEXT_EDIT_MODE_INSERT, |
| 4277 |
NK_TEXT_EDIT_MODE_REPLACE |
| 4278 |
}; |
| 4279 |
|
| 4280 |
struct nk_text_edit { |
| 4281 |
struct nk_clipboard clip; |
| 4282 |
struct nk_str string; |
| 4283 |
nk_plugin_filter filter; |
| 4284 |
struct nk_vec2 scrollbar; |
| 4285 |
|
| 4286 |
int cursor; |
| 4287 |
int select_start; |
| 4288 |
int select_end; |
| 4289 |
unsigned char mode; |
| 4290 |
unsigned char cursor_at_end_of_line; |
| 4291 |
unsigned char initialized; |
| 4292 |
unsigned char has_preferred_x; |
| 4293 |
unsigned char single_line; |
| 4294 |
unsigned char active; |
| 4295 |
unsigned char padding1; |
| 4296 |
float preferred_x; |
| 4297 |
struct nk_text_undo_state undo; |
| 4298 |
}; |
| 4299 |
|
| 4300 |
|
| 4301 |
NK_API int nk_filter_default(const struct nk_text_edit*, nk_rune unicode); |
| 4302 |
NK_API int nk_filter_ascii(const struct nk_text_edit*, nk_rune unicode); |
| 4303 |
NK_API int nk_filter_float(const struct nk_text_edit*, nk_rune unicode); |
| 4304 |
NK_API int nk_filter_decimal(const struct nk_text_edit*, nk_rune unicode); |
| 4305 |
NK_API int nk_filter_hex(const struct nk_text_edit*, nk_rune unicode); |
| 4306 |
NK_API int nk_filter_oct(const struct nk_text_edit*, nk_rune unicode); |
| 4307 |
NK_API int nk_filter_binary(const struct nk_text_edit*, nk_rune unicode); |
| 4308 |
|
| 4309 |
|
| 4310 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 4311 |
NK_API void nk_textedit_init_default(struct nk_text_edit*); |
| 4312 |
#endif |
| 4313 |
NK_API void nk_textedit_init(struct nk_text_edit*, struct nk_allocator*, nk_size size); |
| 4314 |
NK_API void nk_textedit_init_fixed(struct nk_text_edit*, void *memory, nk_size size); |
| 4315 |
NK_API void nk_textedit_free(struct nk_text_edit*); |
| 4316 |
NK_API void nk_textedit_text(struct nk_text_edit*, const char*, int total_len); |
| 4317 |
NK_API void nk_textedit_delete(struct nk_text_edit*, int where, int len); |
| 4318 |
NK_API void nk_textedit_delete_selection(struct nk_text_edit*); |
| 4319 |
NK_API void nk_textedit_select_all(struct nk_text_edit*); |
| 4320 |
NK_API int nk_textedit_cut(struct nk_text_edit*); |
| 4321 |
NK_API int nk_textedit_paste(struct nk_text_edit*, char const*, int len); |
| 4322 |
NK_API void nk_textedit_undo(struct nk_text_edit*); |
| 4323 |
NK_API void nk_textedit_redo(struct nk_text_edit*); |
| 4324 |
|
| 4325 |
|
| 4326 |
|
| 4327 |
|
| 4328 |
|
| 4329 |
|
| 4330 |
|
| 4331 |
|
| 4332 |
|
| 4333 |
|
| 4334 |
|
| 4335 |
|
| 4336 |
|
| 4337 |
|
| 4338 |
|
| 4339 |
|
| 4340 |
|
| 4341 |
|
| 4342 |
|
| 4343 |
|
| 4344 |
|
| 4345 |
|
| 4346 |
|
| 4347 |
|
| 4348 |
|
| 4349 |
|
| 4350 |
|
| 4351 |
|
| 4352 |
|
| 4353 |
|
| 4354 |
|
| 4355 |
|
| 4356 |
|
| 4357 |
|
| 4358 |
|
| 4359 |
|
| 4360 |
|
| 4361 |
|
| 4362 |
|
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
|
| 4371 |
|
| 4372 |
|
| 4373 |
|
| 4374 |
enum nk_command_type { |
| 4375 |
NK_COMMAND_NOP, |
| 4376 |
NK_COMMAND_SCISSOR, |
| 4377 |
NK_COMMAND_LINE, |
| 4378 |
NK_COMMAND_CURVE, |
| 4379 |
NK_COMMAND_RECT, |
| 4380 |
NK_COMMAND_RECT_FILLED, |
| 4381 |
NK_COMMAND_RECT_MULTI_COLOR, |
| 4382 |
NK_COMMAND_CIRCLE, |
| 4383 |
NK_COMMAND_CIRCLE_FILLED, |
| 4384 |
NK_COMMAND_ARC, |
| 4385 |
NK_COMMAND_ARC_FILLED, |
| 4386 |
NK_COMMAND_TRIANGLE, |
| 4387 |
NK_COMMAND_TRIANGLE_FILLED, |
| 4388 |
NK_COMMAND_POLYGON, |
| 4389 |
NK_COMMAND_POLYGON_FILLED, |
| 4390 |
NK_COMMAND_POLYLINE, |
| 4391 |
NK_COMMAND_TEXT, |
| 4392 |
NK_COMMAND_IMAGE, |
| 4393 |
NK_COMMAND_CUSTOM |
| 4394 |
}; |
| 4395 |
|
| 4396 |
|
| 4397 |
struct nk_command { |
| 4398 |
enum nk_command_type type; |
| 4399 |
nk_size next; |
| 4400 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 4401 |
nk_handle userdata; |
| 4402 |
#endif |
| 4403 |
}; |
| 4404 |
|
| 4405 |
struct nk_command_scissor { |
| 4406 |
struct nk_command header; |
| 4407 |
short x, y; |
| 4408 |
unsigned short w, h; |
| 4409 |
}; |
| 4410 |
|
| 4411 |
struct nk_command_line { |
| 4412 |
struct nk_command header; |
| 4413 |
unsigned short line_thickness; |
| 4414 |
struct nk_vec2i begin; |
| 4415 |
struct nk_vec2i end; |
| 4416 |
struct nk_color color; |
| 4417 |
}; |
| 4418 |
|
| 4419 |
struct nk_command_curve { |
| 4420 |
struct nk_command header; |
| 4421 |
unsigned short line_thickness; |
| 4422 |
struct nk_vec2i begin; |
| 4423 |
struct nk_vec2i end; |
| 4424 |
struct nk_vec2i ctrl[2]; |
| 4425 |
struct nk_color color; |
| 4426 |
}; |
| 4427 |
|
| 4428 |
struct nk_command_rect { |
| 4429 |
struct nk_command header; |
| 4430 |
unsigned short rounding; |
| 4431 |
unsigned short line_thickness; |
| 4432 |
short x, y; |
| 4433 |
unsigned short w, h; |
| 4434 |
struct nk_color color; |
| 4435 |
}; |
| 4436 |
|
| 4437 |
struct nk_command_rect_filled { |
| 4438 |
struct nk_command header; |
| 4439 |
unsigned short rounding; |
| 4440 |
short x, y; |
| 4441 |
unsigned short w, h; |
| 4442 |
struct nk_color color; |
| 4443 |
}; |
| 4444 |
|
| 4445 |
struct nk_command_rect_multi_color { |
| 4446 |
struct nk_command header; |
| 4447 |
short x, y; |
| 4448 |
unsigned short w, h; |
| 4449 |
struct nk_color left; |
| 4450 |
struct nk_color top; |
| 4451 |
struct nk_color bottom; |
| 4452 |
struct nk_color right; |
| 4453 |
}; |
| 4454 |
|
| 4455 |
struct nk_command_triangle { |
| 4456 |
struct nk_command header; |
| 4457 |
unsigned short line_thickness; |
| 4458 |
struct nk_vec2i a; |
| 4459 |
struct nk_vec2i b; |
| 4460 |
struct nk_vec2i c; |
| 4461 |
struct nk_color color; |
| 4462 |
}; |
| 4463 |
|
| 4464 |
struct nk_command_triangle_filled { |
| 4465 |
struct nk_command header; |
| 4466 |
struct nk_vec2i a; |
| 4467 |
struct nk_vec2i b; |
| 4468 |
struct nk_vec2i c; |
| 4469 |
struct nk_color color; |
| 4470 |
}; |
| 4471 |
|
| 4472 |
struct nk_command_circle { |
| 4473 |
struct nk_command header; |
| 4474 |
short x, y; |
| 4475 |
unsigned short line_thickness; |
| 4476 |
unsigned short w, h; |
| 4477 |
struct nk_color color; |
| 4478 |
}; |
| 4479 |
|
| 4480 |
struct nk_command_circle_filled { |
| 4481 |
struct nk_command header; |
| 4482 |
short x, y; |
| 4483 |
unsigned short w, h; |
| 4484 |
struct nk_color color; |
| 4485 |
}; |
| 4486 |
|
| 4487 |
struct nk_command_arc { |
| 4488 |
struct nk_command header; |
| 4489 |
short cx, cy; |
| 4490 |
unsigned short r; |
| 4491 |
unsigned short line_thickness; |
| 4492 |
float a[2]; |
| 4493 |
struct nk_color color; |
| 4494 |
}; |
| 4495 |
|
| 4496 |
struct nk_command_arc_filled { |
| 4497 |
struct nk_command header; |
| 4498 |
short cx, cy; |
| 4499 |
unsigned short r; |
| 4500 |
float a[2]; |
| 4501 |
struct nk_color color; |
| 4502 |
}; |
| 4503 |
|
| 4504 |
struct nk_command_polygon { |
| 4505 |
struct nk_command header; |
| 4506 |
struct nk_color color; |
| 4507 |
unsigned short line_thickness; |
| 4508 |
unsigned short point_count; |
| 4509 |
struct nk_vec2i points[1]; |
| 4510 |
}; |
| 4511 |
|
| 4512 |
struct nk_command_polygon_filled { |
| 4513 |
struct nk_command header; |
| 4514 |
struct nk_color color; |
| 4515 |
unsigned short point_count; |
| 4516 |
struct nk_vec2i points[1]; |
| 4517 |
}; |
| 4518 |
|
| 4519 |
struct nk_command_polyline { |
| 4520 |
struct nk_command header; |
| 4521 |
struct nk_color color; |
| 4522 |
unsigned short line_thickness; |
| 4523 |
unsigned short point_count; |
| 4524 |
struct nk_vec2i points[1]; |
| 4525 |
}; |
| 4526 |
|
| 4527 |
struct nk_command_image { |
| 4528 |
struct nk_command header; |
| 4529 |
short x, y; |
| 4530 |
unsigned short w, h; |
| 4531 |
struct nk_image img; |
| 4532 |
struct nk_color col; |
| 4533 |
}; |
| 4534 |
|
| 4535 |
typedef void (*nk_command_custom_callback)(void *canvas, short x,short y, |
| 4536 |
unsigned short w, unsigned short h, nk_handle callback_data); |
| 4537 |
struct nk_command_custom { |
| 4538 |
struct nk_command header; |
| 4539 |
short x, y; |
| 4540 |
unsigned short w, h; |
| 4541 |
nk_handle callback_data; |
| 4542 |
nk_command_custom_callback callback; |
| 4543 |
}; |
| 4544 |
|
| 4545 |
struct nk_command_text { |
| 4546 |
struct nk_command header; |
| 4547 |
const struct nk_user_font *font; |
| 4548 |
struct nk_color background; |
| 4549 |
struct nk_color foreground; |
| 4550 |
short x, y; |
| 4551 |
unsigned short w, h; |
| 4552 |
float height; |
| 4553 |
int length; |
| 4554 |
char string[1]; |
| 4555 |
}; |
| 4556 |
|
| 4557 |
enum nk_command_clipping { |
| 4558 |
NK_CLIPPING_OFF = nk_false, |
| 4559 |
NK_CLIPPING_ON = nk_true |
| 4560 |
}; |
| 4561 |
|
| 4562 |
struct nk_command_buffer { |
| 4563 |
struct nk_buffer *base; |
| 4564 |
struct nk_rect clip; |
| 4565 |
int use_clipping; |
| 4566 |
nk_handle userdata; |
| 4567 |
nk_size begin, end, last; |
| 4568 |
}; |
| 4569 |
|
| 4570 |
|
| 4571 |
NK_API void nk_stroke_line(struct nk_command_buffer *b, float x0, float y0, float x1, float y1, float line_thickness, struct nk_color); |
| 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); |
| 4573 |
NK_API void nk_stroke_rect(struct nk_command_buffer*, struct nk_rect, float rounding, float line_thickness, struct nk_color); |
| 4574 |
NK_API void nk_stroke_circle(struct nk_command_buffer*, struct nk_rect, float line_thickness, struct nk_color); |
| 4575 |
NK_API void nk_stroke_arc(struct nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, float line_thickness, struct nk_color); |
| 4576 |
NK_API void nk_stroke_triangle(struct nk_command_buffer*, float, float, float, float, float, float, float line_thichness, struct nk_color); |
| 4577 |
NK_API void nk_stroke_polyline(struct nk_command_buffer*, float *points, int point_count, float line_thickness, struct nk_color col); |
| 4578 |
NK_API void nk_stroke_polygon(struct nk_command_buffer*, float*, int point_count, float line_thickness, struct nk_color); |
| 4579 |
|
| 4580 |
|
| 4581 |
NK_API void nk_fill_rect(struct nk_command_buffer*, struct nk_rect, float rounding, struct nk_color); |
| 4582 |
NK_API void nk_fill_rect_multi_color(struct nk_command_buffer*, struct nk_rect, struct nk_color left, struct nk_color top, struct nk_color right, struct nk_color bottom); |
| 4583 |
NK_API void nk_fill_circle(struct nk_command_buffer*, struct nk_rect, struct nk_color); |
| 4584 |
NK_API void nk_fill_arc(struct nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, struct nk_color); |
| 4585 |
NK_API void nk_fill_triangle(struct nk_command_buffer*, float x0, float y0, float x1, float y1, float x2, float y2, struct nk_color); |
| 4586 |
NK_API void nk_fill_polygon(struct nk_command_buffer*, float*, int point_count, struct nk_color); |
| 4587 |
|
| 4588 |
|
| 4589 |
NK_API void nk_draw_image(struct nk_command_buffer*, struct nk_rect, const struct nk_image*, struct nk_color); |
| 4590 |
NK_API void nk_draw_text(struct nk_command_buffer*, struct nk_rect, const char *text, int len, const struct nk_user_font*, struct nk_color, struct nk_color); |
| 4591 |
NK_API void nk_push_scissor(struct nk_command_buffer*, struct nk_rect); |
| 4592 |
NK_API void nk_push_custom(struct nk_command_buffer*, struct nk_rect, nk_command_custom_callback, nk_handle usr); |
| 4593 |
|
| 4594 |
|
| 4595 |
|
| 4596 |
|
| 4597 |
|
| 4598 |
|
| 4599 |
struct nk_mouse_button { |
| 4600 |
int down; |
| 4601 |
unsigned int clicked; |
| 4602 |
struct nk_vec2 clicked_pos; |
| 4603 |
}; |
| 4604 |
struct nk_mouse { |
| 4605 |
struct nk_mouse_button buttons[NK_BUTTON_MAX]; |
| 4606 |
struct nk_vec2 pos; |
| 4607 |
struct nk_vec2 prev; |
| 4608 |
struct nk_vec2 delta; |
| 4609 |
struct nk_vec2 scroll_delta; |
| 4610 |
unsigned char grab; |
| 4611 |
unsigned char grabbed; |
| 4612 |
unsigned char ungrab; |
| 4613 |
}; |
| 4614 |
|
| 4615 |
struct nk_key { |
| 4616 |
int down; |
| 4617 |
unsigned int clicked; |
| 4618 |
}; |
| 4619 |
struct nk_keyboard { |
| 4620 |
struct nk_key keys[NK_KEY_MAX]; |
| 4621 |
char text[NK_INPUT_MAX]; |
| 4622 |
int text_len; |
| 4623 |
}; |
| 4624 |
|
| 4625 |
struct nk_input { |
| 4626 |
struct nk_keyboard keyboard; |
| 4627 |
struct nk_mouse mouse; |
| 4628 |
}; |
| 4629 |
|
| 4630 |
NK_API int nk_input_has_mouse_click(const struct nk_input*, enum nk_buttons); |
| 4631 |
NK_API int nk_input_has_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); |
| 4632 |
NK_API int nk_input_has_mouse_click_down_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect, int down); |
| 4633 |
NK_API int nk_input_is_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); |
| 4634 |
NK_API int nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b, int down); |
| 4635 |
NK_API int nk_input_any_mouse_click_in_rect(const struct nk_input*, struct nk_rect); |
| 4636 |
NK_API int nk_input_is_mouse_prev_hovering_rect(const struct nk_input*, struct nk_rect); |
| 4637 |
NK_API int nk_input_is_mouse_hovering_rect(const struct nk_input*, struct nk_rect); |
| 4638 |
NK_API int nk_input_mouse_clicked(const struct nk_input*, enum nk_buttons, struct nk_rect); |
| 4639 |
NK_API int nk_input_is_mouse_down(const struct nk_input*, enum nk_buttons); |
| 4640 |
NK_API int nk_input_is_mouse_pressed(const struct nk_input*, enum nk_buttons); |
| 4641 |
NK_API int nk_input_is_mouse_released(const struct nk_input*, enum nk_buttons); |
| 4642 |
NK_API int nk_input_is_key_pressed(const struct nk_input*, enum nk_keys); |
| 4643 |
NK_API int nk_input_is_key_released(const struct nk_input*, enum nk_keys); |
| 4644 |
NK_API int nk_input_is_key_down(const struct nk_input*, enum nk_keys); |
| 4645 |
|
| 4646 |
|
| 4647 |
|
| 4648 |
|
| 4649 |
|
| 4650 |
|
| 4651 |
#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT |
| 4652 |
|
| 4653 |
|
| 4654 |
|
| 4655 |
|
| 4656 |
|
| 4657 |
|
| 4658 |
|
| 4659 |
|
| 4660 |
|
| 4661 |
|
| 4662 |
|
| 4663 |
|
| 4664 |
|
| 4665 |
#ifdef NK_UINT_DRAW_INDEX |
| 4666 |
typedef nk_uint nk_draw_index; |
| 4667 |
#else |
| 4668 |
typedef nk_ushort nk_draw_index; |
| 4669 |
#endif |
| 4670 |
enum nk_draw_list_stroke { |
| 4671 |
NK_STROKE_OPEN = nk_false, |
| 4672 |
|
| 4673 |
NK_STROKE_CLOSED = nk_true |
| 4674 |
|
| 4675 |
}; |
| 4676 |
|
| 4677 |
enum nk_draw_vertex_layout_attribute { |
| 4678 |
NK_VERTEX_POSITION, |
| 4679 |
NK_VERTEX_COLOR, |
| 4680 |
NK_VERTEX_TEXCOORD, |
| 4681 |
NK_VERTEX_ATTRIBUTE_COUNT |
| 4682 |
}; |
| 4683 |
|
| 4684 |
enum nk_draw_vertex_layout_format { |
| 4685 |
NK_FORMAT_SCHAR, |
| 4686 |
NK_FORMAT_SSHORT, |
| 4687 |
NK_FORMAT_SINT, |
| 4688 |
NK_FORMAT_UCHAR, |
| 4689 |
NK_FORMAT_USHORT, |
| 4690 |
NK_FORMAT_UINT, |
| 4691 |
NK_FORMAT_FLOAT, |
| 4692 |
NK_FORMAT_DOUBLE, |
| 4693 |
|
| 4694 |
NK_FORMAT_COLOR_BEGIN, |
| 4695 |
NK_FORMAT_R8G8B8 = NK_FORMAT_COLOR_BEGIN, |
| 4696 |
NK_FORMAT_R16G15B16, |
| 4697 |
NK_FORMAT_R32G32B32, |
| 4698 |
|
| 4699 |
NK_FORMAT_R8G8B8A8, |
| 4700 |
NK_FORMAT_B8G8R8A8, |
| 4701 |
NK_FORMAT_R16G15B16A16, |
| 4702 |
NK_FORMAT_R32G32B32A32, |
| 4703 |
NK_FORMAT_R32G32B32A32_FLOAT, |
| 4704 |
NK_FORMAT_R32G32B32A32_DOUBLE, |
| 4705 |
|
| 4706 |
NK_FORMAT_RGB32, |
| 4707 |
NK_FORMAT_RGBA32, |
| 4708 |
NK_FORMAT_COLOR_END = NK_FORMAT_RGBA32, |
| 4709 |
NK_FORMAT_COUNT |
| 4710 |
}; |
| 4711 |
|
| 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; |
| 4716 |
nk_size offset; |
| 4717 |
}; |
| 4718 |
|
| 4719 |
struct nk_draw_command { |
| 4720 |
unsigned int elem_count; |
| 4721 |
|
| 4722 |
struct nk_rect clip_rect; |
| 4723 |
|
| 4724 |
nk_handle texture; |
| 4725 |
|
| 4726 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 4727 |
nk_handle userdata; |
| 4728 |
#endif |
| 4729 |
}; |
| 4730 |
|
| 4731 |
struct nk_draw_list { |
| 4732 |
struct nk_rect clip_rect; |
| 4733 |
struct nk_vec2 circle_vtx[12]; |
| 4734 |
struct nk_convert_config config; |
| 4735 |
|
| 4736 |
struct nk_buffer *buffer; |
| 4737 |
struct nk_buffer *vertices; |
| 4738 |
struct nk_buffer *elements; |
| 4739 |
|
| 4740 |
unsigned int element_count; |
| 4741 |
unsigned int vertex_count; |
| 4742 |
unsigned int cmd_count; |
| 4743 |
nk_size cmd_offset; |
| 4744 |
|
| 4745 |
unsigned int path_count; |
| 4746 |
unsigned int path_offset; |
| 4747 |
|
| 4748 |
enum nk_anti_aliasing line_AA; |
| 4749 |
enum nk_anti_aliasing shape_AA; |
| 4750 |
|
| 4751 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 4752 |
nk_handle userdata; |
| 4753 |
#endif |
| 4754 |
}; |
| 4755 |
|
| 4756 |
|
| 4757 |
NK_API void nk_draw_list_init(struct nk_draw_list*); |
| 4758 |
NK_API void nk_draw_list_setup(struct nk_draw_list*, const struct nk_convert_config*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, enum nk_anti_aliasing line_aa,enum nk_anti_aliasing shape_aa); |
| 4759 |
|
| 4760 |
|
| 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*); |
| 4765 |
|
| 4766 |
|
| 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); |
| 4775 |
|
| 4776 |
|
| 4777 |
NK_API void nk_draw_list_stroke_line(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, struct nk_color, 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); |
| 4779 |
NK_API void nk_draw_list_stroke_triangle(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, struct nk_vec2 c, struct nk_color, 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); |
| 4781 |
NK_API void nk_draw_list_stroke_curve(struct nk_draw_list*, struct nk_vec2 p0, struct nk_vec2 cp0, struct nk_vec2 cp1, struct nk_vec2 p1, struct nk_color, unsigned int segments, 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); |
| 4783 |
|
| 4784 |
|
| 4785 |
NK_API void nk_draw_list_fill_rect(struct nk_draw_list*, struct nk_rect rect, struct nk_color, float rounding); |
| 4786 |
NK_API void nk_draw_list_fill_rect_multi_color(struct nk_draw_list*, struct nk_rect rect, struct nk_color left, struct nk_color top, struct nk_color right, struct nk_color bottom); |
| 4787 |
NK_API void nk_draw_list_fill_triangle(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, struct nk_vec2 c, struct nk_color); |
| 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); |
| 4789 |
NK_API void nk_draw_list_fill_poly_convex(struct nk_draw_list*, const struct nk_vec2 *points, const unsigned int count, struct nk_color, enum nk_anti_aliasing); |
| 4790 |
|
| 4791 |
|
| 4792 |
NK_API void nk_draw_list_add_image(struct nk_draw_list*, struct nk_image texture, struct nk_rect rect, struct nk_color); |
| 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); |
| 4796 |
#endif |
| 4797 |
|
| 4798 |
#endif |
| 4799 |
|
| 4800 |
|
| 4801 |
|
| 4802 |
|
| 4803 |
|
| 4804 |
|
| 4805 |
enum nk_style_item_type { |
| 4806 |
NK_STYLE_ITEM_COLOR, |
| 4807 |
NK_STYLE_ITEM_IMAGE |
| 4808 |
}; |
| 4809 |
|
| 4810 |
union nk_style_item_data { |
| 4811 |
struct nk_image image; |
| 4812 |
struct nk_color color; |
| 4813 |
}; |
| 4814 |
|
| 4815 |
struct nk_style_item { |
| 4816 |
enum nk_style_item_type type; |
| 4817 |
union nk_style_item_data data; |
| 4818 |
}; |
| 4819 |
|
| 4820 |
struct nk_style_text { |
| 4821 |
struct nk_color color; |
| 4822 |
struct nk_vec2 padding; |
| 4823 |
}; |
| 4824 |
|
| 4825 |
struct nk_style_button { |
| 4826 |
|
| 4827 |
struct nk_style_item normal; |
| 4828 |
struct nk_style_item hover; |
| 4829 |
struct nk_style_item active; |
| 4830 |
struct nk_color border_color; |
| 4831 |
|
| 4832 |
|
| 4833 |
struct nk_color text_background; |
| 4834 |
struct nk_color text_normal; |
| 4835 |
struct nk_color text_hover; |
| 4836 |
struct nk_color text_active; |
| 4837 |
nk_flags text_alignment; |
| 4838 |
|
| 4839 |
|
| 4840 |
float border; |
| 4841 |
float rounding; |
| 4842 |
struct nk_vec2 padding; |
| 4843 |
struct nk_vec2 image_padding; |
| 4844 |
struct nk_vec2 touch_padding; |
| 4845 |
|
| 4846 |
|
| 4847 |
nk_handle userdata; |
| 4848 |
void(*draw_begin)(struct nk_command_buffer*, nk_handle userdata); |
| 4849 |
void(*draw_end)(struct nk_command_buffer*, nk_handle userdata); |
| 4850 |
}; |
| 4851 |
|
| 4852 |
struct nk_style_toggle { |
| 4853 |
|
| 4854 |
struct nk_style_item normal; |
| 4855 |
struct nk_style_item hover; |
| 4856 |
struct nk_style_item active; |
| 4857 |
struct nk_color border_color; |
| 4858 |
|
| 4859 |
|
| 4860 |
struct nk_style_item cursor_normal; |
| 4861 |
struct nk_style_item cursor_hover; |
| 4862 |
|
| 4863 |
|
| 4864 |
struct nk_color text_normal; |
| 4865 |
struct nk_color text_hover; |
| 4866 |
struct nk_color text_active; |
| 4867 |
struct nk_color text_background; |
| 4868 |
nk_flags text_alignment; |
| 4869 |
|
| 4870 |
|
| 4871 |
struct nk_vec2 padding; |
| 4872 |
struct nk_vec2 touch_padding; |
| 4873 |
float spacing; |
| 4874 |
float border; |
| 4875 |
|
| 4876 |
|
| 4877 |
nk_handle userdata; |
| 4878 |
void(*draw_begin)(struct nk_command_buffer*, nk_handle); |
| 4879 |
void(*draw_end)(struct nk_command_buffer*, nk_handle); |
| 4880 |
}; |
| 4881 |
|
| 4882 |
struct nk_style_selectable { |
| 4883 |
|
| 4884 |
struct nk_style_item normal; |
| 4885 |
struct nk_style_item hover; |
| 4886 |
struct nk_style_item pressed; |
| 4887 |
|
| 4888 |
|
| 4889 |
struct nk_style_item normal_active; |
| 4890 |
struct nk_style_item hover_active; |
| 4891 |
struct nk_style_item pressed_active; |
| 4892 |
|
| 4893 |
|
| 4894 |
struct nk_color text_normal; |
| 4895 |
struct nk_color text_hover; |
| 4896 |
struct nk_color text_pressed; |
| 4897 |
|
| 4898 |
|
| 4899 |
struct nk_color text_normal_active; |
| 4900 |
struct nk_color text_hover_active; |
| 4901 |
struct nk_color text_pressed_active; |
| 4902 |
struct nk_color text_background; |
| 4903 |
nk_flags text_alignment; |
| 4904 |
|
| 4905 |
|
| 4906 |
float rounding; |
| 4907 |
struct nk_vec2 padding; |
| 4908 |
struct nk_vec2 touch_padding; |
| 4909 |
struct nk_vec2 image_padding; |
| 4910 |
|
| 4911 |
|
| 4912 |
nk_handle userdata; |
| 4913 |
void(*draw_begin)(struct nk_command_buffer*, nk_handle); |
| 4914 |
void(*draw_end)(struct nk_command_buffer*, nk_handle); |
| 4915 |
}; |
| 4916 |
|
| 4917 |
struct nk_style_slider { |
| 4918 |
|
| 4919 |
struct nk_style_item normal; |
| 4920 |
struct nk_style_item hover; |
| 4921 |
struct nk_style_item active; |
| 4922 |
struct nk_color border_color; |
| 4923 |
|
| 4924 |
|
| 4925 |
struct nk_color bar_normal; |
| 4926 |
struct nk_color bar_hover; |
| 4927 |
struct nk_color bar_active; |
| 4928 |
struct nk_color bar_filled; |
| 4929 |
|
| 4930 |
|
| 4931 |
struct nk_style_item cursor_normal; |
| 4932 |
struct nk_style_item cursor_hover; |
| 4933 |
struct nk_style_item cursor_active; |
| 4934 |
|
| 4935 |
|
| 4936 |
float border; |
| 4937 |
float rounding; |
| 4938 |
float bar_height; |
| 4939 |
struct nk_vec2 padding; |
| 4940 |
struct nk_vec2 spacing; |
| 4941 |
struct nk_vec2 cursor_size; |
| 4942 |
|
| 4943 |
|
| 4944 |
int show_buttons; |
| 4945 |
struct nk_style_button inc_button; |
| 4946 |
struct nk_style_button dec_button; |
| 4947 |
enum nk_symbol_type inc_symbol; |
| 4948 |
enum nk_symbol_type dec_symbol; |
| 4949 |
|
| 4950 |
|
| 4951 |
nk_handle userdata; |
| 4952 |
void(*draw_begin)(struct nk_command_buffer*, nk_handle); |
| 4953 |
void(*draw_end)(struct nk_command_buffer*, nk_handle); |
| 4954 |
}; |
| 4955 |
|
| 4956 |
struct nk_style_progress { |
| 4957 |
|
| 4958 |
struct nk_style_item normal; |
| 4959 |
struct nk_style_item hover; |
| 4960 |
struct nk_style_item active; |
| 4961 |
struct nk_color border_color; |
| 4962 |
|
| 4963 |
|
| 4964 |
struct nk_style_item cursor_normal; |
| 4965 |
struct nk_style_item cursor_hover; |
| 4966 |
struct nk_style_item cursor_active; |
| 4967 |
struct nk_color cursor_border_color; |
| 4968 |
|
| 4969 |
|
| 4970 |
float rounding; |
| 4971 |
float border; |
| 4972 |
float cursor_border; |
| 4973 |
float cursor_rounding; |
| 4974 |
struct nk_vec2 padding; |
| 4975 |
|
| 4976 |
|
| 4977 |
nk_handle userdata; |
| 4978 |
void(*draw_begin)(struct nk_command_buffer*, nk_handle); |
| 4979 |
void(*draw_end)(struct nk_command_buffer*, nk_handle); |
| 4980 |
}; |
| 4981 |
|
| 4982 |
struct nk_style_scrollbar { |
| 4983 |
|
| 4984 |
struct nk_style_item normal; |
| 4985 |
struct nk_style_item hover; |
| 4986 |
struct nk_style_item active; |
| 4987 |
struct nk_color border_color; |
| 4988 |
|
| 4989 |
|
| 4990 |
struct nk_style_item cursor_normal; |
| 4991 |
struct nk_style_item cursor_hover; |
| 4992 |
struct nk_style_item cursor_active; |
| 4993 |
struct nk_color cursor_border_color; |
| 4994 |
|
| 4995 |
|
| 4996 |
float border; |
| 4997 |
float rounding; |
| 4998 |
float border_cursor; |
| 4999 |
float rounding_cursor; |
| 5000 |
struct nk_vec2 padding; |
| 5001 |
|
| 5002 |
|
| 5003 |
int show_buttons; |
| 5004 |
struct nk_style_button inc_button; |
| 5005 |
struct nk_style_button dec_button; |
| 5006 |
enum nk_symbol_type inc_symbol; |
| 5007 |
enum nk_symbol_type dec_symbol; |
| 5008 |
|
| 5009 |
|
| 5010 |
nk_handle userdata; |
| 5011 |
void(*draw_begin)(struct nk_command_buffer*, nk_handle); |
| 5012 |
void(*draw_end)(struct nk_command_buffer*, nk_handle); |
| 5013 |
}; |
| 5014 |
|
| 5015 |
struct nk_style_edit { |
| 5016 |
|
| 5017 |
struct nk_style_item normal; |
| 5018 |
struct nk_style_item hover; |
| 5019 |
struct nk_style_item active; |
| 5020 |
struct nk_color border_color; |
| 5021 |
struct nk_style_scrollbar scrollbar; |
| 5022 |
|
| 5023 |
|
| 5024 |
struct nk_color cursor_normal; |
| 5025 |
struct nk_color cursor_hover; |
| 5026 |
struct nk_color cursor_text_normal; |
| 5027 |
struct nk_color cursor_text_hover; |
| 5028 |
|
| 5029 |
|
| 5030 |
struct nk_color text_normal; |
| 5031 |
struct nk_color text_hover; |
| 5032 |
struct nk_color text_active; |
| 5033 |
|
| 5034 |
|
| 5035 |
struct nk_color selected_normal; |
| 5036 |
struct nk_color selected_hover; |
| 5037 |
struct nk_color selected_text_normal; |
| 5038 |
struct nk_color selected_text_hover; |
| 5039 |
|
| 5040 |
|
| 5041 |
float border; |
| 5042 |
float rounding; |
| 5043 |
float cursor_size; |
| 5044 |
struct nk_vec2 scrollbar_size; |
| 5045 |
struct nk_vec2 padding; |
| 5046 |
float row_padding; |
| 5047 |
}; |
| 5048 |
|
| 5049 |
struct nk_style_property { |
| 5050 |
|
| 5051 |
struct nk_style_item normal; |
| 5052 |
struct nk_style_item hover; |
| 5053 |
struct nk_style_item active; |
| 5054 |
struct nk_color border_color; |
| 5055 |
|
| 5056 |
|
| 5057 |
struct nk_color label_normal; |
| 5058 |
struct nk_color label_hover; |
| 5059 |
struct nk_color label_active; |
| 5060 |
|
| 5061 |
|
| 5062 |
enum nk_symbol_type sym_left; |
| 5063 |
enum nk_symbol_type sym_right; |
| 5064 |
|
| 5065 |
|
| 5066 |
float border; |
| 5067 |
float rounding; |
| 5068 |
struct nk_vec2 padding; |
| 5069 |
|
| 5070 |
struct nk_style_edit edit; |
| 5071 |
struct nk_style_button inc_button; |
| 5072 |
struct nk_style_button dec_button; |
| 5073 |
|
| 5074 |
|
| 5075 |
nk_handle userdata; |
| 5076 |
void(*draw_begin)(struct nk_command_buffer*, nk_handle); |
| 5077 |
void(*draw_end)(struct nk_command_buffer*, nk_handle); |
| 5078 |
}; |
| 5079 |
|
| 5080 |
struct nk_style_chart { |
| 5081 |
|
| 5082 |
struct nk_style_item background; |
| 5083 |
struct nk_color border_color; |
| 5084 |
struct nk_color selected_color; |
| 5085 |
struct nk_color color; |
| 5086 |
|
| 5087 |
|
| 5088 |
float border; |
| 5089 |
float rounding; |
| 5090 |
struct nk_vec2 padding; |
| 5091 |
}; |
| 5092 |
|
| 5093 |
struct nk_style_combo { |
| 5094 |
|
| 5095 |
struct nk_style_item normal; |
| 5096 |
struct nk_style_item hover; |
| 5097 |
struct nk_style_item active; |
| 5098 |
struct nk_color border_color; |
| 5099 |
|
| 5100 |
|
| 5101 |
struct nk_color label_normal; |
| 5102 |
struct nk_color label_hover; |
| 5103 |
struct nk_color label_active; |
| 5104 |
|
| 5105 |
|
| 5106 |
struct nk_color symbol_normal; |
| 5107 |
struct nk_color symbol_hover; |
| 5108 |
struct nk_color symbol_active; |
| 5109 |
|
| 5110 |
|
| 5111 |
struct nk_style_button button; |
| 5112 |
enum nk_symbol_type sym_normal; |
| 5113 |
enum nk_symbol_type sym_hover; |
| 5114 |
enum nk_symbol_type sym_active; |
| 5115 |
|
| 5116 |
|
| 5117 |
float border; |
| 5118 |
float rounding; |
| 5119 |
struct nk_vec2 content_padding; |
| 5120 |
struct nk_vec2 button_padding; |
| 5121 |
struct nk_vec2 spacing; |
| 5122 |
}; |
| 5123 |
|
| 5124 |
struct nk_style_tab { |
| 5125 |
|
| 5126 |
struct nk_style_item background; |
| 5127 |
struct nk_color border_color; |
| 5128 |
struct nk_color text; |
| 5129 |
|
| 5130 |
|
| 5131 |
struct nk_style_button tab_maximize_button; |
| 5132 |
struct nk_style_button tab_minimize_button; |
| 5133 |
struct nk_style_button node_maximize_button; |
| 5134 |
struct nk_style_button node_minimize_button; |
| 5135 |
enum nk_symbol_type sym_minimize; |
| 5136 |
enum nk_symbol_type sym_maximize; |
| 5137 |
|
| 5138 |
|
| 5139 |
float border; |
| 5140 |
float rounding; |
| 5141 |
float indent; |
| 5142 |
struct nk_vec2 padding; |
| 5143 |
struct nk_vec2 spacing; |
| 5144 |
}; |
| 5145 |
|
| 5146 |
enum nk_style_header_align { |
| 5147 |
NK_HEADER_LEFT, |
| 5148 |
NK_HEADER_RIGHT |
| 5149 |
}; |
| 5150 |
struct nk_style_window_header { |
| 5151 |
|
| 5152 |
struct nk_style_item normal; |
| 5153 |
struct nk_style_item hover; |
| 5154 |
struct nk_style_item active; |
| 5155 |
|
| 5156 |
|
| 5157 |
struct nk_style_button close_button; |
| 5158 |
struct nk_style_button minimize_button; |
| 5159 |
enum nk_symbol_type close_symbol; |
| 5160 |
enum nk_symbol_type minimize_symbol; |
| 5161 |
enum nk_symbol_type maximize_symbol; |
| 5162 |
|
| 5163 |
|
| 5164 |
struct nk_color label_normal; |
| 5165 |
struct nk_color label_hover; |
| 5166 |
struct nk_color label_active; |
| 5167 |
|
| 5168 |
|
| 5169 |
enum nk_style_header_align align; |
| 5170 |
struct nk_vec2 padding; |
| 5171 |
struct nk_vec2 label_padding; |
| 5172 |
struct nk_vec2 spacing; |
| 5173 |
}; |
| 5174 |
|
| 5175 |
struct nk_style_window { |
| 5176 |
struct nk_style_window_header header; |
| 5177 |
struct nk_style_item fixed_background; |
| 5178 |
struct nk_color background; |
| 5179 |
|
| 5180 |
struct nk_color border_color; |
| 5181 |
struct nk_color popup_border_color; |
| 5182 |
struct nk_color combo_border_color; |
| 5183 |
struct nk_color contextual_border_color; |
| 5184 |
struct nk_color menu_border_color; |
| 5185 |
struct nk_color group_border_color; |
| 5186 |
struct nk_color tooltip_border_color; |
| 5187 |
struct nk_style_item scaler; |
| 5188 |
|
| 5189 |
float border; |
| 5190 |
float combo_border; |
| 5191 |
float contextual_border; |
| 5192 |
float menu_border; |
| 5193 |
float group_border; |
| 5194 |
float tooltip_border; |
| 5195 |
float popup_border; |
| 5196 |
float min_row_height_padding; |
| 5197 |
|
| 5198 |
float rounding; |
| 5199 |
struct nk_vec2 spacing; |
| 5200 |
struct nk_vec2 scrollbar_size; |
| 5201 |
struct nk_vec2 min_size; |
| 5202 |
|
| 5203 |
struct nk_vec2 padding; |
| 5204 |
struct nk_vec2 group_padding; |
| 5205 |
struct nk_vec2 popup_padding; |
| 5206 |
struct nk_vec2 combo_padding; |
| 5207 |
struct nk_vec2 contextual_padding; |
| 5208 |
struct nk_vec2 menu_padding; |
| 5209 |
struct nk_vec2 tooltip_padding; |
| 5210 |
}; |
| 5211 |
|
| 5212 |
struct nk_style { |
| 5213 |
const struct nk_user_font *font; |
| 5214 |
const struct nk_cursor *cursors[NK_CURSOR_COUNT]; |
| 5215 |
const struct nk_cursor *cursor_active; |
| 5216 |
struct nk_cursor *cursor_last; |
| 5217 |
int cursor_visible; |
| 5218 |
|
| 5219 |
struct nk_style_text text; |
| 5220 |
struct nk_style_button button; |
| 5221 |
struct nk_style_button contextual_button; |
| 5222 |
struct nk_style_button menu_button; |
| 5223 |
struct nk_style_toggle option; |
| 5224 |
struct nk_style_toggle checkbox; |
| 5225 |
struct nk_style_selectable selectable; |
| 5226 |
struct nk_style_slider slider; |
| 5227 |
struct nk_style_progress progress; |
| 5228 |
struct nk_style_property property; |
| 5229 |
struct nk_style_edit edit; |
| 5230 |
struct nk_style_chart chart; |
| 5231 |
struct nk_style_scrollbar scrollh; |
| 5232 |
struct nk_style_scrollbar scrollv; |
| 5233 |
struct nk_style_tab tab; |
| 5234 |
struct nk_style_combo combo; |
| 5235 |
struct nk_style_window window; |
| 5236 |
}; |
| 5237 |
|
| 5238 |
NK_API struct nk_style_item nk_style_item_image(struct nk_image img); |
| 5239 |
NK_API struct nk_style_item nk_style_item_color(struct nk_color); |
| 5240 |
NK_API struct nk_style_item nk_style_item_hide(void); |
| 5241 |
|
| 5242 |
|
| 5243 |
|
| 5244 |
|
| 5245 |
#ifndef NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS |
| 5246 |
#define NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS 16 |
| 5247 |
#endif |
| 5248 |
#ifndef NK_CHART_MAX_SLOT |
| 5249 |
#define NK_CHART_MAX_SLOT 4 |
| 5250 |
#endif |
| 5251 |
|
| 5252 |
enum nk_panel_type { |
| 5253 |
NK_PANEL_NONE = 0, |
| 5254 |
NK_PANEL_WINDOW = NK_FLAG(0), |
| 5255 |
NK_PANEL_GROUP = NK_FLAG(1), |
| 5256 |
NK_PANEL_POPUP = NK_FLAG(2), |
| 5257 |
NK_PANEL_CONTEXTUAL = NK_FLAG(4), |
| 5258 |
NK_PANEL_COMBO = NK_FLAG(5), |
| 5259 |
NK_PANEL_MENU = NK_FLAG(6), |
| 5260 |
NK_PANEL_TOOLTIP = NK_FLAG(7) |
| 5261 |
}; |
| 5262 |
enum nk_panel_set { |
| 5263 |
NK_PANEL_SET_NONBLOCK = NK_PANEL_CONTEXTUAL|NK_PANEL_COMBO|NK_PANEL_MENU|NK_PANEL_TOOLTIP, |
| 5264 |
NK_PANEL_SET_POPUP = NK_PANEL_SET_NONBLOCK|NK_PANEL_POPUP, |
| 5265 |
NK_PANEL_SET_SUB = NK_PANEL_SET_POPUP|NK_PANEL_GROUP |
| 5266 |
}; |
| 5267 |
|
| 5268 |
struct nk_chart_slot { |
| 5269 |
enum nk_chart_type type; |
| 5270 |
struct nk_color color; |
| 5271 |
struct nk_color highlight; |
| 5272 |
float min, max, range; |
| 5273 |
int count; |
| 5274 |
struct nk_vec2 last; |
| 5275 |
int index; |
| 5276 |
}; |
| 5277 |
|
| 5278 |
struct nk_chart { |
| 5279 |
int slot; |
| 5280 |
float x, y, w, h; |
| 5281 |
struct nk_chart_slot slots[NK_CHART_MAX_SLOT]; |
| 5282 |
}; |
| 5283 |
|
| 5284 |
enum nk_panel_row_layout_type { |
| 5285 |
NK_LAYOUT_DYNAMIC_FIXED = 0, |
| 5286 |
NK_LAYOUT_DYNAMIC_ROW, |
| 5287 |
NK_LAYOUT_DYNAMIC_FREE, |
| 5288 |
NK_LAYOUT_DYNAMIC, |
| 5289 |
NK_LAYOUT_STATIC_FIXED, |
| 5290 |
NK_LAYOUT_STATIC_ROW, |
| 5291 |
NK_LAYOUT_STATIC_FREE, |
| 5292 |
NK_LAYOUT_STATIC, |
| 5293 |
NK_LAYOUT_TEMPLATE, |
| 5294 |
NK_LAYOUT_COUNT |
| 5295 |
}; |
| 5296 |
struct nk_row_layout { |
| 5297 |
enum nk_panel_row_layout_type type; |
| 5298 |
int index; |
| 5299 |
float height; |
| 5300 |
float min_height; |
| 5301 |
int columns; |
| 5302 |
const float *ratio; |
| 5303 |
float item_width; |
| 5304 |
float item_height; |
| 5305 |
float item_offset; |
| 5306 |
float filled; |
| 5307 |
struct nk_rect item; |
| 5308 |
int tree_depth; |
| 5309 |
float templates[NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS]; |
| 5310 |
}; |
| 5311 |
|
| 5312 |
struct nk_popup_buffer { |
| 5313 |
nk_size begin; |
| 5314 |
nk_size parent; |
| 5315 |
nk_size last; |
| 5316 |
nk_size end; |
| 5317 |
int active; |
| 5318 |
}; |
| 5319 |
|
| 5320 |
struct nk_menu_state { |
| 5321 |
float x, y, w, h; |
| 5322 |
struct nk_scroll offset; |
| 5323 |
}; |
| 5324 |
|
| 5325 |
struct nk_panel { |
| 5326 |
enum nk_panel_type type; |
| 5327 |
nk_flags flags; |
| 5328 |
struct nk_rect bounds; |
| 5329 |
nk_uint *offset_x; |
| 5330 |
nk_uint *offset_y; |
| 5331 |
float at_x, at_y, max_x; |
| 5332 |
float footer_height; |
| 5333 |
float header_height; |
| 5334 |
float border; |
| 5335 |
unsigned int has_scrolling; |
| 5336 |
struct nk_rect clip; |
| 5337 |
struct nk_menu_state menu; |
| 5338 |
struct nk_row_layout row; |
| 5339 |
struct nk_chart chart; |
| 5340 |
struct nk_command_buffer *buffer; |
| 5341 |
struct nk_panel *parent; |
| 5342 |
}; |
| 5343 |
|
| 5344 |
|
| 5345 |
|
| 5346 |
|
| 5347 |
#ifndef NK_WINDOW_MAX_NAME |
| 5348 |
#define NK_WINDOW_MAX_NAME 64 |
| 5349 |
#endif |
| 5350 |
|
| 5351 |
struct nk_table; |
| 5352 |
enum nk_window_flags { |
| 5353 |
NK_WINDOW_PRIVATE = NK_FLAG(11), |
| 5354 |
NK_WINDOW_DYNAMIC = NK_WINDOW_PRIVATE, |
| 5355 |
|
| 5356 |
NK_WINDOW_ROM = NK_FLAG(12), |
| 5357 |
|
| 5358 |
NK_WINDOW_NOT_INTERACTIVE = NK_WINDOW_ROM|NK_WINDOW_NO_INPUT, |
| 5359 |
|
| 5360 |
NK_WINDOW_HIDDEN = NK_FLAG(13), |
| 5361 |
|
| 5362 |
NK_WINDOW_CLOSED = NK_FLAG(14), |
| 5363 |
|
| 5364 |
NK_WINDOW_MINIMIZED = NK_FLAG(15), |
| 5365 |
|
| 5366 |
NK_WINDOW_REMOVE_ROM = NK_FLAG(16) |
| 5367 |
|
| 5368 |
}; |
| 5369 |
|
| 5370 |
struct nk_popup_state { |
| 5371 |
struct nk_window *win; |
| 5372 |
enum nk_panel_type type; |
| 5373 |
struct nk_popup_buffer buf; |
| 5374 |
nk_hash name; |
| 5375 |
int active; |
| 5376 |
unsigned combo_count; |
| 5377 |
unsigned con_count, con_old; |
| 5378 |
unsigned active_con; |
| 5379 |
struct nk_rect header; |
| 5380 |
}; |
| 5381 |
|
| 5382 |
struct nk_edit_state { |
| 5383 |
nk_hash name; |
| 5384 |
unsigned int seq; |
| 5385 |
unsigned int old; |
| 5386 |
int active, prev; |
| 5387 |
int cursor; |
| 5388 |
int sel_start; |
| 5389 |
int sel_end; |
| 5390 |
struct nk_scroll scrollbar; |
| 5391 |
unsigned char mode; |
| 5392 |
unsigned char single_line; |
| 5393 |
}; |
| 5394 |
|
| 5395 |
struct nk_property_state { |
| 5396 |
int active, prev; |
| 5397 |
char buffer[NK_MAX_NUMBER_BUFFER]; |
| 5398 |
int length; |
| 5399 |
int cursor; |
| 5400 |
int select_start; |
| 5401 |
int select_end; |
| 5402 |
nk_hash name; |
| 5403 |
unsigned int seq; |
| 5404 |
unsigned int old; |
| 5405 |
int state; |
| 5406 |
}; |
| 5407 |
|
| 5408 |
struct nk_window { |
| 5409 |
unsigned int seq; |
| 5410 |
nk_hash name; |
| 5411 |
char name_string[NK_WINDOW_MAX_NAME]; |
| 5412 |
nk_flags flags; |
| 5413 |
|
| 5414 |
struct nk_rect bounds; |
| 5415 |
struct nk_scroll scrollbar; |
| 5416 |
struct nk_command_buffer buffer; |
| 5417 |
struct nk_panel *layout; |
| 5418 |
float scrollbar_hiding_timer; |
| 5419 |
|
| 5420 |
|
| 5421 |
struct nk_property_state property; |
| 5422 |
struct nk_popup_state popup; |
| 5423 |
struct nk_edit_state edit; |
| 5424 |
unsigned int scrolled; |
| 5425 |
|
| 5426 |
struct nk_table *tables; |
| 5427 |
unsigned int table_count; |
| 5428 |
|
| 5429 |
|
| 5430 |
struct nk_window *next; |
| 5431 |
struct nk_window *prev; |
| 5432 |
struct nk_window *parent; |
| 5433 |
}; |
| 5434 |
|
| 5435 |
|
| 5436 |
|
| 5437 |
|
| 5438 |
|
| 5439 |
|
| 5440 |
|
| 5441 |
|
| 5442 |
|
| 5443 |
|
| 5444 |
|
| 5445 |
|
| 5446 |
|
| 5447 |
|
| 5448 |
|
| 5449 |
|
| 5450 |
|
| 5451 |
|
| 5452 |
|
| 5453 |
|
| 5454 |
|
| 5455 |
|
| 5456 |
|
| 5457 |
|
| 5458 |
|
| 5459 |
|
| 5460 |
#ifndef NK_BUTTON_BEHAVIOR_STACK_SIZE |
| 5461 |
#define NK_BUTTON_BEHAVIOR_STACK_SIZE 8 |
| 5462 |
#endif |
| 5463 |
|
| 5464 |
#ifndef NK_FONT_STACK_SIZE |
| 5465 |
#define NK_FONT_STACK_SIZE 8 |
| 5466 |
#endif |
| 5467 |
|
| 5468 |
#ifndef NK_STYLE_ITEM_STACK_SIZE |
| 5469 |
#define NK_STYLE_ITEM_STACK_SIZE 16 |
| 5470 |
#endif |
| 5471 |
|
| 5472 |
#ifndef NK_FLOAT_STACK_SIZE |
| 5473 |
#define NK_FLOAT_STACK_SIZE 32 |
| 5474 |
#endif |
| 5475 |
|
| 5476 |
#ifndef NK_VECTOR_STACK_SIZE |
| 5477 |
#define NK_VECTOR_STACK_SIZE 16 |
| 5478 |
#endif |
| 5479 |
|
| 5480 |
#ifndef NK_FLAGS_STACK_SIZE |
| 5481 |
#define NK_FLAGS_STACK_SIZE 32 |
| 5482 |
#endif |
| 5483 |
|
| 5484 |
#ifndef NK_COLOR_STACK_SIZE |
| 5485 |
#define NK_COLOR_STACK_SIZE 32 |
| 5486 |
#endif |
| 5487 |
|
| 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;\ |
| 5492 |
} |
| 5493 |
#define NK_CONFIG_STACK(type,size)\ |
| 5494 |
struct nk_config_stack_##type {\ |
| 5495 |
int head;\ |
| 5496 |
struct nk_config_stack_##type##_element elements[size];\ |
| 5497 |
} |
| 5498 |
|
| 5499 |
#define nk_float float |
| 5500 |
NK_CONFIGURATION_STACK_TYPE(struct nk, style_item, style_item); |
| 5501 |
NK_CONFIGURATION_STACK_TYPE(nk ,float, float); |
| 5502 |
NK_CONFIGURATION_STACK_TYPE(struct nk, vec2, vec2); |
| 5503 |
NK_CONFIGURATION_STACK_TYPE(nk ,flags, flags); |
| 5504 |
NK_CONFIGURATION_STACK_TYPE(struct nk, color, color); |
| 5505 |
NK_CONFIGURATION_STACK_TYPE(const struct nk, user_font, user_font*); |
| 5506 |
NK_CONFIGURATION_STACK_TYPE(enum nk, button_behavior, button_behavior); |
| 5507 |
|
| 5508 |
NK_CONFIG_STACK(style_item, NK_STYLE_ITEM_STACK_SIZE); |
| 5509 |
NK_CONFIG_STACK(float, NK_FLOAT_STACK_SIZE); |
| 5510 |
NK_CONFIG_STACK(vec2, NK_VECTOR_STACK_SIZE); |
| 5511 |
NK_CONFIG_STACK(flags, NK_FLAGS_STACK_SIZE); |
| 5512 |
NK_CONFIG_STACK(color, NK_COLOR_STACK_SIZE); |
| 5513 |
NK_CONFIG_STACK(user_font, NK_FONT_STACK_SIZE); |
| 5514 |
NK_CONFIG_STACK(button_behavior, NK_BUTTON_BEHAVIOR_STACK_SIZE); |
| 5515 |
|
| 5516 |
struct nk_configuration_stacks { |
| 5517 |
struct nk_config_stack_style_item style_items; |
| 5518 |
struct nk_config_stack_float floats; |
| 5519 |
struct nk_config_stack_vec2 vectors; |
| 5520 |
struct nk_config_stack_flags flags; |
| 5521 |
struct nk_config_stack_color colors; |
| 5522 |
struct nk_config_stack_user_font fonts; |
| 5523 |
struct nk_config_stack_button_behavior button_behaviors; |
| 5524 |
}; |
| 5525 |
|
| 5526 |
|
| 5527 |
|
| 5528 |
|
| 5529 |
#define NK_VALUE_PAGE_CAPACITY \ |
| 5530 |
(((NK_MAX(sizeof(struct nk_window),sizeof(struct nk_panel)) / sizeof(nk_uint))) / 2) |
| 5531 |
|
| 5532 |
struct nk_table { |
| 5533 |
unsigned int seq; |
| 5534 |
unsigned int size; |
| 5535 |
nk_hash keys[NK_VALUE_PAGE_CAPACITY]; |
| 5536 |
nk_uint values[NK_VALUE_PAGE_CAPACITY]; |
| 5537 |
struct nk_table *next, *prev; |
| 5538 |
}; |
| 5539 |
|
| 5540 |
union nk_page_data { |
| 5541 |
struct nk_table tbl; |
| 5542 |
struct nk_panel pan; |
| 5543 |
struct nk_window win; |
| 5544 |
}; |
| 5545 |
|
| 5546 |
struct nk_page_element { |
| 5547 |
union nk_page_data data; |
| 5548 |
struct nk_page_element *next; |
| 5549 |
struct nk_page_element *prev; |
| 5550 |
}; |
| 5551 |
|
| 5552 |
struct nk_page { |
| 5553 |
unsigned int size; |
| 5554 |
struct nk_page *next; |
| 5555 |
struct nk_page_element win[1]; |
| 5556 |
}; |
| 5557 |
|
| 5558 |
struct nk_pool { |
| 5559 |
struct nk_allocator alloc; |
| 5560 |
enum nk_allocation_type type; |
| 5561 |
unsigned int page_count; |
| 5562 |
struct nk_page *pages; |
| 5563 |
struct nk_page_element *freelist; |
| 5564 |
unsigned capacity; |
| 5565 |
nk_size size; |
| 5566 |
nk_size cap; |
| 5567 |
}; |
| 5568 |
|
| 5569 |
struct nk_context { |
| 5570 |
|
| 5571 |
struct nk_input input; |
| 5572 |
struct nk_style style; |
| 5573 |
struct nk_buffer memory; |
| 5574 |
struct nk_clipboard clip; |
| 5575 |
nk_flags last_widget_state; |
| 5576 |
enum nk_button_behavior button_behavior; |
| 5577 |
struct nk_configuration_stacks stacks; |
| 5578 |
float delta_time_seconds; |
| 5579 |
|
| 5580 |
|
| 5581 |
|
| 5582 |
|
| 5583 |
#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT |
| 5584 |
struct nk_draw_list draw_list; |
| 5585 |
#endif |
| 5586 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 5587 |
nk_handle userdata; |
| 5588 |
#endif |
| 5589 |
|
| 5590 |
|
| 5591 |
|
| 5592 |
|
| 5593 |
struct nk_text_edit text_edit; |
| 5594 |
|
| 5595 |
struct nk_command_buffer overlay; |
| 5596 |
|
| 5597 |
|
| 5598 |
int build; |
| 5599 |
int use_pool; |
| 5600 |
struct nk_pool pool; |
| 5601 |
struct nk_window *begin; |
| 5602 |
struct nk_window *end; |
| 5603 |
struct nk_window *active; |
| 5604 |
struct nk_window *current; |
| 5605 |
struct nk_page_element *freelist; |
| 5606 |
unsigned int count; |
| 5607 |
unsigned int seq; |
| 5608 |
}; |
| 5609 |
|
| 5610 |
|
| 5611 |
|
| 5612 |
|
| 5613 |
#define NK_PI 3.141592654f |
| 5614 |
#define NK_UTF_INVALID 0xFFFD |
| 5615 |
#define NK_MAX_FLOAT_PRECISION 2 |
| 5616 |
|
| 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)) && (x0 < (x1 + w1)) && \ |
| 5626 |
(y1 < (y0 + h0)) && (y0 < (y1 + h1))) |
| 5627 |
#define NK_CONTAINS(x, y, w, h, bx, by, bw, bh)\ |
| 5628 |
(NK_INBOX(x,y, bx, by, bw, bh) && NK_INBOX(x+w,y+h, bx, by, bw, bh)) |
| 5629 |
|
| 5630 |
#define nk_vec2_sub(a, b) nk_vec2((a).x - (b).x, (a).y - (b).y) |
| 5631 |
#define nk_vec2_add(a, b) nk_vec2((a).x + (b).x, (a).y + (b).y) |
| 5632 |
#define nk_vec2_len_sqr(a) ((a).x*(a).x+(a).y*(a).y) |
| 5633 |
#define nk_vec2_muls(a, t) nk_vec2((a).x * (t), (a).y * (t)) |
| 5634 |
|
| 5635 |
#define nk_ptr_add(t, p, i) ((t*)((void*)((nk_byte*)(p) + (i)))) |
| 5636 |
#define nk_ptr_add_const(t, p, i) ((const t*)((const void*)((const nk_byte*)(p) + (i)))) |
| 5637 |
#define nk_zero_struct(s) nk_zero(&s, sizeof(s)) |
| 5638 |
|
| 5639 |
|
| 5640 |
|
| 5641 |
|
| 5642 |
|
| 5643 |
#if defined(__PTRDIFF_TYPE__) |
| 5644 |
# define NK_UINT_TO_PTR(x) ((void*)(__PTRDIFF_TYPE__)(x)) |
| 5645 |
# define NK_PTR_TO_UINT(x) ((nk_size)(__PTRDIFF_TYPE__)(x)) |
| 5646 |
#elif !defined(__GNUC__) |
| 5647 |
# define NK_UINT_TO_PTR(x) ((void*)&((char*)0)[x]) |
| 5648 |
# define NK_PTR_TO_UINT(x) ((nk_size)(((char*)x)-(char*)0)) |
| 5649 |
#elif defined(NK_USE_FIXED_TYPES) |
| 5650 |
# define NK_UINT_TO_PTR(x) ((void*)(uintptr_t)(x)) |
| 5651 |
# define NK_PTR_TO_UINT(x) ((uintptr_t)(x)) |
| 5652 |
#else |
| 5653 |
# define NK_UINT_TO_PTR(x) ((void*)(x)) |
| 5654 |
# define NK_PTR_TO_UINT(x) ((nk_size)(x)) |
| 5655 |
#endif |
| 5656 |
|
| 5657 |
#define NK_ALIGN_PTR(x, mask)\ |
| 5658 |
(NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x) + (mask-1)) & ~(mask-1)))) |
| 5659 |
#define NK_ALIGN_PTR_BACK(x, mask)\ |
| 5660 |
(NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x)) & ~(mask-1)))) |
| 5661 |
|
| 5662 |
#define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m)) |
| 5663 |
#define NK_CONTAINER_OF(ptr,type,member)\ |
| 5664 |
(type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) |
| 5665 |
|
| 5666 |
#ifdef __cplusplus |
| 5667 |
} |
| 5668 |
#endif |
| 5669 |
|
| 5670 |
#ifdef __cplusplus |
| 5671 |
template<typename T> struct nk_alignof; |
| 5672 |
template<typename T, int size_diff> struct nk_helper{enum {value = size_diff};}; |
| 5673 |
template<typename T> struct nk_helper<T,0>{enum {value = nk_alignof<T>::value};}; |
| 5674 |
template<typename T> struct nk_alignof{struct Big {T x; char c;}; enum { |
| 5675 |
diff = sizeof(Big) - sizeof(T), value = nk_helper<Big, diff>::value};}; |
| 5676 |
#define NK_ALIGNOF(t) (nk_alignof<t>::value) |
| 5677 |
#elif defined(_MSC_VER) |
| 5678 |
#define NK_ALIGNOF(t) (__alignof(t)) |
| 5679 |
#else |
| 5680 |
#define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0) |
| 5681 |
#endif |
| 5682 |
|
| 5683 |
#endif |
| 5684 |
|
| 5685 |
#ifdef NK_IMPLEMENTATION |
| 5686 |
|
| 5687 |
#ifndef NK_INTERNAL_H |
| 5688 |
#define NK_INTERNAL_H |
| 5689 |
|
| 5690 |
#ifndef NK_POOL_DEFAULT_CAPACITY |
| 5691 |
#define NK_POOL_DEFAULT_CAPACITY 16 |
| 5692 |
#endif |
| 5693 |
|
| 5694 |
#ifndef NK_DEFAULT_COMMAND_BUFFER_SIZE |
| 5695 |
#define NK_DEFAULT_COMMAND_BUFFER_SIZE (4*1024) |
| 5696 |
#endif |
| 5697 |
|
| 5698 |
#ifndef NK_BUFFER_DEFAULT_INITIAL_SIZE |
| 5699 |
#define NK_BUFFER_DEFAULT_INITIAL_SIZE (4*1024) |
| 5700 |
#endif |
| 5701 |
|
| 5702 |
|
| 5703 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 5704 |
#include <stdlib.h> |
| 5705 |
#endif |
| 5706 |
#ifdef NK_INCLUDE_STANDARD_IO |
| 5707 |
#include <stdio.h> |
| 5708 |
#endif |
| 5709 |
#ifdef NK_INCLUDE_STANDARD_VARARGS |
| 5710 |
#include <stdarg.h> |
| 5711 |
#endif |
| 5712 |
#ifndef NK_ASSERT |
| 5713 |
#include <assert.h> |
| 5714 |
#define NK_ASSERT(expr) assert(expr) |
| 5715 |
#endif |
| 5716 |
|
| 5717 |
#ifndef NK_MEMSET |
| 5718 |
#define NK_MEMSET nk_memset |
| 5719 |
#endif |
| 5720 |
#ifndef NK_MEMCPY |
| 5721 |
#define NK_MEMCPY nk_memcopy |
| 5722 |
#endif |
| 5723 |
#ifndef NK_SQRT |
| 5724 |
#define NK_SQRT nk_sqrt |
| 5725 |
#endif |
| 5726 |
#ifndef NK_SIN |
| 5727 |
#define NK_SIN nk_sin |
| 5728 |
#endif |
| 5729 |
#ifndef NK_COS |
| 5730 |
#define NK_COS nk_cos |
| 5731 |
#endif |
| 5732 |
#ifndef NK_STRTOD |
| 5733 |
#define NK_STRTOD nk_strtod |
| 5734 |
#endif |
| 5735 |
#ifndef NK_DTOA |
| 5736 |
#define NK_DTOA nk_dtoa |
| 5737 |
#endif |
| 5738 |
|
| 5739 |
#define NK_DEFAULT (-1) |
| 5740 |
|
| 5741 |
#ifndef NK_VSNPRINTF |
| 5742 |
|
| 5743 |
|
| 5744 |
|
| 5745 |
|
| 5746 |
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) ||\ |
| 5747 |
(defined(__cplusplus) && (__cplusplus >= 201103L)) || \ |
| 5748 |
(defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) ||\ |
| 5749 |
(defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)) ||\ |
| 5750 |
defined(_ISOC99_SOURCE) || defined(_BSD_SOURCE) |
| 5751 |
#define NK_VSNPRINTF(s,n,f,a) vsnprintf(s,n,f,a) |
| 5752 |
#else |
| 5753 |
#define NK_VSNPRINTF(s,n,f,a) vsprintf(s,f,a) |
| 5754 |
#endif |
| 5755 |
#endif |
| 5756 |
|
| 5757 |
#define NK_SCHAR_MIN (-127) |
| 5758 |
#define NK_SCHAR_MAX 127 |
| 5759 |
#define NK_UCHAR_MIN 0 |
| 5760 |
#define NK_UCHAR_MAX 256 |
| 5761 |
#define NK_SSHORT_MIN (-32767) |
| 5762 |
#define NK_SSHORT_MAX 32767 |
| 5763 |
#define NK_USHORT_MIN 0 |
| 5764 |
#define NK_USHORT_MAX 65535 |
| 5765 |
#define NK_SINT_MIN (-2147483647) |
| 5766 |
#define NK_SINT_MAX 2147483647 |
| 5767 |
#define NK_UINT_MIN 0 |
| 5768 |
#define NK_UINT_MAX 4294967295u |
| 5769 |
|
| 5770 |
|
| 5771 |
|
| 5772 |
|
| 5773 |
NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*)); |
| 5774 |
NK_STATIC_ASSERT(sizeof(nk_ptr) == sizeof(void*)); |
| 5775 |
NK_STATIC_ASSERT(sizeof(nk_flags) >= 4); |
| 5776 |
NK_STATIC_ASSERT(sizeof(nk_rune) >= 4); |
| 5777 |
NK_STATIC_ASSERT(sizeof(nk_ushort) == 2); |
| 5778 |
NK_STATIC_ASSERT(sizeof(nk_short) == 2); |
| 5779 |
NK_STATIC_ASSERT(sizeof(nk_uint) == 4); |
| 5780 |
NK_STATIC_ASSERT(sizeof(nk_int) == 4); |
| 5781 |
NK_STATIC_ASSERT(sizeof(nk_byte) == 1); |
| 5782 |
|
| 5783 |
NK_GLOBAL const struct nk_rect nk_null_rect = {-8192.0f, -8192.0f, 16384, 16384}; |
| 5784 |
#define NK_FLOAT_PRECISION 0.00000000000001 |
| 5785 |
|
| 5786 |
NK_GLOBAL const struct nk_color nk_red = {255,0,0,255}; |
| 5787 |
NK_GLOBAL const struct nk_color nk_green = {0,255,0,255}; |
| 5788 |
NK_GLOBAL const struct nk_color nk_blue = {0,0,255,255}; |
| 5789 |
NK_GLOBAL const struct nk_color nk_white = {255,255,255,255}; |
| 5790 |
NK_GLOBAL const struct nk_color nk_black = {0,0,0,255}; |
| 5791 |
NK_GLOBAL const struct nk_color nk_yellow = {255,255,0,255}; |
| 5792 |
|
| 5793 |
|
| 5794 |
#define nk_widget_state_reset(s)\ |
| 5795 |
if ((*(s)) & NK_WIDGET_STATE_MODIFIED)\ |
| 5796 |
(*(s)) = NK_WIDGET_STATE_INACTIVE|NK_WIDGET_STATE_MODIFIED;\ |
| 5797 |
else (*(s)) = NK_WIDGET_STATE_INACTIVE; |
| 5798 |
|
| 5799 |
|
| 5800 |
NK_LIB float nk_inv_sqrt(float n); |
| 5801 |
NK_LIB float nk_sqrt(float x); |
| 5802 |
NK_LIB float nk_sin(float x); |
| 5803 |
NK_LIB float nk_cos(float x); |
| 5804 |
NK_LIB nk_uint nk_round_up_pow2(nk_uint v); |
| 5805 |
NK_LIB struct nk_rect nk_shrink_rect(struct nk_rect r, float amount); |
| 5806 |
NK_LIB struct nk_rect nk_pad_rect(struct nk_rect r, struct nk_vec2 pad); |
| 5807 |
NK_LIB void nk_unify(struct nk_rect *clip, const struct nk_rect *a, float x0, float y0, float x1, float y1); |
| 5808 |
NK_LIB double nk_pow(double x, int n); |
| 5809 |
NK_LIB int nk_ifloord(double x); |
| 5810 |
NK_LIB int nk_ifloorf(float x); |
| 5811 |
NK_LIB int nk_iceilf(float x); |
| 5812 |
NK_LIB int nk_log10(double n); |
| 5813 |
|
| 5814 |
|
| 5815 |
enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE}; |
| 5816 |
NK_LIB int nk_is_lower(int c); |
| 5817 |
NK_LIB int nk_is_upper(int c); |
| 5818 |
NK_LIB int nk_to_upper(int c); |
| 5819 |
NK_LIB int nk_to_lower(int c); |
| 5820 |
NK_LIB void* nk_memcopy(void *dst, const void *src, nk_size n); |
| 5821 |
NK_LIB void nk_memset(void *ptr, int c0, nk_size size); |
| 5822 |
NK_LIB void nk_zero(void *ptr, nk_size size); |
| 5823 |
NK_LIB char *nk_itoa(char *s, long n); |
| 5824 |
NK_LIB int nk_string_float_limit(char *string, int prec); |
| 5825 |
NK_LIB char *nk_dtoa(char *s, double n); |
| 5826 |
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); |
| 5827 |
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); |
| 5828 |
#ifdef NK_INCLUDE_STANDARD_VARARGS |
| 5829 |
NK_LIB int nk_strfmt(char *buf, int buf_size, const char *fmt, va_list args); |
| 5830 |
#endif |
| 5831 |
#ifdef NK_INCLUDE_STANDARD_IO |
| 5832 |
NK_LIB char *nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc); |
| 5833 |
#endif |
| 5834 |
|
| 5835 |
|
| 5836 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 5837 |
NK_LIB void* nk_malloc(nk_handle unused, void *old,nk_size size); |
| 5838 |
NK_LIB void nk_mfree(nk_handle unused, void *ptr); |
| 5839 |
#endif |
| 5840 |
NK_LIB void* nk_buffer_align(void *unaligned, nk_size align, nk_size *alignment, enum nk_buffer_allocation_type type); |
| 5841 |
NK_LIB void* nk_buffer_alloc(struct nk_buffer *b, enum nk_buffer_allocation_type type, nk_size size, nk_size align); |
| 5842 |
NK_LIB void* nk_buffer_realloc(struct nk_buffer *b, nk_size capacity, nk_size *size); |
| 5843 |
|
| 5844 |
|
| 5845 |
NK_LIB void nk_command_buffer_init(struct nk_command_buffer *cb, struct nk_buffer *b, enum nk_command_clipping clip); |
| 5846 |
NK_LIB void nk_command_buffer_reset(struct nk_command_buffer *b); |
| 5847 |
NK_LIB void* nk_command_buffer_push(struct nk_command_buffer* b, enum nk_command_type t, nk_size size); |
| 5848 |
NK_LIB void nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type, struct nk_rect content, struct nk_color background, struct nk_color foreground, float border_width, const struct nk_user_font *font); |
| 5849 |
|
| 5850 |
|
| 5851 |
NK_LIB void nk_start_buffer(struct nk_context *ctx, struct nk_command_buffer *b); |
| 5852 |
NK_LIB void nk_start(struct nk_context *ctx, struct nk_window *win); |
| 5853 |
NK_LIB void nk_start_popup(struct nk_context *ctx, struct nk_window *win); |
| 5854 |
NK_LIB void nk_finish_popup(struct nk_context *ctx, struct nk_window*); |
| 5855 |
NK_LIB void nk_finish_buffer(struct nk_context *ctx, struct nk_command_buffer *b); |
| 5856 |
NK_LIB void nk_finish(struct nk_context *ctx, struct nk_window *w); |
| 5857 |
NK_LIB void nk_build(struct nk_context *ctx); |
| 5858 |
|
| 5859 |
|
| 5860 |
NK_LIB void nk_textedit_clear_state(struct nk_text_edit *state, enum nk_text_edit_type type, nk_plugin_filter filter); |
| 5861 |
NK_LIB void nk_textedit_click(struct nk_text_edit *state, float x, float y, const struct nk_user_font *font, float row_height); |
| 5862 |
NK_LIB void nk_textedit_drag(struct nk_text_edit *state, float x, float y, const struct nk_user_font *font, float row_height); |
| 5863 |
NK_LIB void nk_textedit_key(struct nk_text_edit *state, enum nk_keys key, int shift_mod, const struct nk_user_font *font, float row_height); |
| 5864 |
|
| 5865 |
|
| 5866 |
enum nk_window_insert_location { |
| 5867 |
NK_INSERT_BACK, |
| 5868 |
NK_INSERT_FRONT |
| 5869 |
}; |
| 5870 |
NK_LIB void *nk_create_window(struct nk_context *ctx); |
| 5871 |
NK_LIB void nk_remove_window(struct nk_context*, struct nk_window*); |
| 5872 |
NK_LIB void nk_free_window(struct nk_context *ctx, struct nk_window *win); |
| 5873 |
NK_LIB struct nk_window *nk_find_window(struct nk_context *ctx, nk_hash hash, const char *name); |
| 5874 |
NK_LIB void nk_insert_window(struct nk_context *ctx, struct nk_window *win, enum nk_window_insert_location loc); |
| 5875 |
|
| 5876 |
|
| 5877 |
NK_LIB void nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, unsigned int capacity); |
| 5878 |
NK_LIB void nk_pool_free(struct nk_pool *pool); |
| 5879 |
NK_LIB void nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size); |
| 5880 |
NK_LIB struct nk_page_element *nk_pool_alloc(struct nk_pool *pool); |
| 5881 |
|
| 5882 |
|
| 5883 |
NK_LIB struct nk_page_element* nk_create_page_element(struct nk_context *ctx); |
| 5884 |
NK_LIB void nk_link_page_element_into_freelist(struct nk_context *ctx, struct nk_page_element *elem); |
| 5885 |
NK_LIB void nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem); |
| 5886 |
|
| 5887 |
|
| 5888 |
NK_LIB struct nk_table* nk_create_table(struct nk_context *ctx); |
| 5889 |
NK_LIB void nk_remove_table(struct nk_window *win, struct nk_table *tbl); |
| 5890 |
NK_LIB void nk_free_table(struct nk_context *ctx, struct nk_table *tbl); |
| 5891 |
NK_LIB void nk_push_table(struct nk_window *win, struct nk_table *tbl); |
| 5892 |
NK_LIB nk_uint *nk_add_value(struct nk_context *ctx, struct nk_window *win, nk_hash name, nk_uint value); |
| 5893 |
NK_LIB nk_uint *nk_find_value(struct nk_window *win, nk_hash name); |
| 5894 |
|
| 5895 |
|
| 5896 |
NK_LIB void *nk_create_panel(struct nk_context *ctx); |
| 5897 |
NK_LIB void nk_free_panel(struct nk_context*, struct nk_panel *pan); |
| 5898 |
NK_LIB int nk_panel_has_header(nk_flags flags, const char *title); |
| 5899 |
NK_LIB struct nk_vec2 nk_panel_get_padding(const struct nk_style *style, enum nk_panel_type type); |
| 5900 |
NK_LIB float nk_panel_get_border(const struct nk_style *style, nk_flags flags, enum nk_panel_type type); |
| 5901 |
NK_LIB struct nk_color nk_panel_get_border_color(const struct nk_style *style, enum nk_panel_type type); |
| 5902 |
NK_LIB int nk_panel_is_sub(enum nk_panel_type type); |
| 5903 |
NK_LIB int nk_panel_is_nonblock(enum nk_panel_type type); |
| 5904 |
NK_LIB int nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type panel_type); |
| 5905 |
NK_LIB void nk_panel_end(struct nk_context *ctx); |
| 5906 |
|
| 5907 |
|
| 5908 |
NK_LIB float nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type, float total_space, int columns); |
| 5909 |
NK_LIB void nk_panel_layout(const struct nk_context *ctx, struct nk_window *win, float height, int cols); |
| 5910 |
NK_LIB void nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, float height, int cols, int width); |
| 5911 |
NK_LIB void nk_panel_alloc_row(const struct nk_context *ctx, struct nk_window *win); |
| 5912 |
NK_LIB void nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, struct nk_window *win, int modify); |
| 5913 |
NK_LIB void nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx); |
| 5914 |
NK_LIB void nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx); |
| 5915 |
|
| 5916 |
|
| 5917 |
NK_LIB int nk_nonblock_begin(struct nk_context *ctx, nk_flags flags, struct nk_rect body, struct nk_rect header, enum nk_panel_type panel_type); |
| 5918 |
|
| 5919 |
|
| 5920 |
struct nk_text { |
| 5921 |
struct nk_vec2 padding; |
| 5922 |
struct nk_color background; |
| 5923 |
struct nk_color text; |
| 5924 |
}; |
| 5925 |
NK_LIB void nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, const char *string, int len, const struct nk_text *t, nk_flags a, const struct nk_user_font *f); |
| 5926 |
NK_LIB void nk_widget_text_wrap(struct nk_command_buffer *o, struct nk_rect b, const char *string, int len, const struct nk_text *t, const struct nk_user_font *f); |
| 5927 |
|
| 5928 |
|
| 5929 |
NK_LIB int nk_button_behavior(nk_flags *state, struct nk_rect r, const struct nk_input *i, enum nk_button_behavior behavior); |
| 5930 |
NK_LIB const struct nk_style_item* nk_draw_button(struct nk_command_buffer *out, const struct nk_rect *bounds, nk_flags state, const struct nk_style_button *style); |
| 5931 |
NK_LIB int nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, const struct nk_style_button *style, const struct nk_input *in, enum nk_button_behavior behavior, struct nk_rect *content); |
| 5932 |
NK_LIB void nk_draw_button_text(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, const char *txt, int len, nk_flags text_alignment, const struct nk_user_font *font); |
| 5933 |
NK_LIB int nk_do_button_text(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *string, int len, nk_flags align, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_input *in, const struct nk_user_font *font); |
| 5934 |
NK_LIB void nk_draw_button_symbol(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, enum nk_symbol_type type, const struct nk_user_font *font); |
| 5935 |
NK_LIB int nk_do_button_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, enum nk_symbol_type symbol, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_input *in, const struct nk_user_font *font); |
| 5936 |
NK_LIB void nk_draw_button_image(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, const struct nk_image *img); |
| 5937 |
NK_LIB int nk_do_button_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, struct nk_image img, enum nk_button_behavior b, const struct nk_style_button *style, const struct nk_input *in); |
| 5938 |
NK_LIB void nk_draw_button_text_symbol(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *label, const struct nk_rect *symbol, nk_flags state, const struct nk_style_button *style, const char *str, int len, enum nk_symbol_type type, const struct nk_user_font *font); |
| 5939 |
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 void nk_draw_button_text_image(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *label, const struct nk_rect *image, nk_flags state, const struct nk_style_button *style, const char *str, int len, const struct nk_user_font *font, const struct nk_image *img); |
| 5941 |
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); |
| 5942 |
|
| 5943 |
|
| 5944 |
enum nk_toggle_type { |
| 5945 |
NK_TOGGLE_CHECK, |
| 5946 |
NK_TOGGLE_OPTION |
| 5947 |
}; |
| 5948 |
NK_LIB int nk_toggle_behavior(const struct nk_input *in, struct nk_rect select, nk_flags *state, int active); |
| 5949 |
NK_LIB void nk_draw_checkbox(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, int active, const struct nk_rect *label, const struct nk_rect *selector, const struct nk_rect *cursors, const char *string, int len, const struct nk_user_font *font); |
| 5950 |
NK_LIB void nk_draw_option(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, int active, const struct nk_rect *label, const struct nk_rect *selector, const struct nk_rect *cursors, const char *string, int len, const struct nk_user_font *font); |
| 5951 |
NK_LIB int nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, int *active, const char *str, int len, enum nk_toggle_type type, const struct nk_style_toggle *style, const struct nk_input *in, const struct nk_user_font *font); |
| 5952 |
|
| 5953 |
|
| 5954 |
NK_LIB nk_size nk_progress_behavior(nk_flags *state, struct nk_input *in, struct nk_rect r, struct nk_rect cursor, nk_size max, nk_size value, int modifiable); |
| 5955 |
NK_LIB void nk_draw_progress(struct nk_command_buffer *out, nk_flags state, const struct nk_style_progress *style, const struct nk_rect *bounds, const struct nk_rect *scursor, nk_size value, nk_size max); |
| 5956 |
NK_LIB nk_size nk_do_progress(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, nk_size value, nk_size max, int modifiable, const struct nk_style_progress *style, struct nk_input *in); |
| 5957 |
|
| 5958 |
|
| 5959 |
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); |
| 5960 |
NK_LIB void nk_draw_slider(struct nk_command_buffer *out, nk_flags state, const struct nk_style_slider *style, const struct nk_rect *bounds, const struct nk_rect *visual_cursor, float min, float value, float max); |
| 5961 |
NK_LIB float nk_do_slider(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, float min, float val, float max, float step, const struct nk_style_slider *style, struct nk_input *in, const struct nk_user_font *font); |
| 5962 |
|
| 5963 |
|
| 5964 |
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 void nk_draw_scrollbar(struct nk_command_buffer *out, nk_flags state, const struct nk_style_scrollbar *style, const struct nk_rect *bounds, const struct nk_rect *scroll); |
| 5966 |
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); |
| 5967 |
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); |
| 5968 |
|
| 5969 |
|
| 5970 |
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(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_style_selectable *style, const struct nk_input *in, const struct nk_user_font *font); |
| 5972 |
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); |
| 5973 |
|
| 5974 |
|
| 5975 |
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); |
| 5976 |
NK_LIB nk_flags nk_do_edit(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, nk_flags flags, nk_plugin_filter filter, struct nk_text_edit *edit, const struct nk_style_edit *style, struct nk_input *in, const struct nk_user_font *font); |
| 5977 |
|
| 5978 |
|
| 5979 |
NK_LIB int nk_color_picker_behavior(nk_flags *state, const struct nk_rect *bounds, const struct nk_rect *matrix, const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, struct nk_colorf *color, const struct nk_input *in); |
| 5980 |
NK_LIB void nk_draw_color_picker(struct nk_command_buffer *o, const struct nk_rect *matrix, const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, struct nk_colorf col); |
| 5981 |
NK_LIB int nk_do_color_picker(nk_flags *state, struct nk_command_buffer *out, struct nk_colorf *col, enum nk_color_format fmt, struct nk_rect bounds, struct nk_vec2 padding, const struct nk_input *in, const struct nk_user_font *font); |
| 5982 |
|
| 5983 |
|
| 5984 |
enum nk_property_status { |
| 5985 |
NK_PROPERTY_DEFAULT, |
| 5986 |
NK_PROPERTY_EDIT, |
| 5987 |
NK_PROPERTY_DRAG |
| 5988 |
}; |
| 5989 |
enum nk_property_filter { |
| 5990 |
NK_FILTER_INT, |
| 5991 |
NK_FILTER_FLOAT |
| 5992 |
}; |
| 5993 |
enum nk_property_kind { |
| 5994 |
NK_PROPERTY_INT, |
| 5995 |
NK_PROPERTY_FLOAT, |
| 5996 |
NK_PROPERTY_DOUBLE |
| 5997 |
}; |
| 5998 |
union nk_property { |
| 5999 |
int i; |
| 6000 |
float f; |
| 6001 |
double d; |
| 6002 |
}; |
| 6003 |
struct nk_property_variant { |
| 6004 |
enum nk_property_kind kind; |
| 6005 |
union nk_property value; |
| 6006 |
union nk_property min_value; |
| 6007 |
union nk_property max_value; |
| 6008 |
union nk_property step; |
| 6009 |
}; |
| 6010 |
NK_LIB struct nk_property_variant nk_property_variant_int(int value, int min_value, int max_value, int step); |
| 6011 |
NK_LIB struct nk_property_variant nk_property_variant_float(float value, float min_value, float max_value, float step); |
| 6012 |
NK_LIB struct nk_property_variant nk_property_variant_double(double value, double min_value, double max_value, double step); |
| 6013 |
|
| 6014 |
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); |
| 6015 |
NK_LIB void nk_property_behavior(nk_flags *ws, const struct nk_input *in, struct nk_rect property, struct nk_rect label, struct nk_rect edit, struct nk_rect empty, int *state, struct nk_property_variant *variant, float inc_per_pixel); |
| 6016 |
NK_LIB void nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property *style, const struct nk_rect *bounds, const struct nk_rect *label, nk_flags state, const char *name, int len, const struct nk_user_font *font); |
| 6017 |
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); |
| 6018 |
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); |
| 6019 |
|
| 6020 |
#endif |
| 6021 |
|
| 6022 |
|
| 6023 |
|
| 6024 |
|
| 6025 |
|
| 6026 |
|
| 6027 |
|
| 6028 |
|
| 6029 |
|
| 6030 |
|
| 6031 |
|
| 6032 |
|
| 6033 |
|
| 6034 |
|
| 6035 |
|
| 6036 |
|
| 6037 |
|
| 6038 |
|
| 6039 |
|
| 6040 |
|
| 6041 |
|
| 6042 |
|
| 6043 |
|
| 6044 |
|
| 6045 |
|
| 6046 |
|
| 6047 |
|
| 6048 |
|
| 6049 |
|
| 6050 |
|
| 6051 |
|
| 6052 |
|
| 6053 |
|
| 6054 |
|
| 6055 |
|
| 6056 |
|
| 6057 |
|
| 6058 |
NK_LIB float |
| 6059 |
nk_inv_sqrt(float n) |
| 6060 |
{ |
| 6061 |
float x2; |
| 6062 |
const float threehalfs = 1.5f; |
| 6063 |
union {nk_uint i; float f;} conv = {0}; |
| 6064 |
conv.f = n; |
| 6065 |
x2 = n * 0.5f; |
| 6066 |
conv.i = 0x5f375A84 - (conv.i >> 1); |
| 6067 |
conv.f = conv.f * (threehalfs - (x2 * conv.f * conv.f)); |
| 6068 |
return conv.f; |
| 6069 |
} |
| 6070 |
NK_LIB float |
| 6071 |
nk_sqrt(float x) |
| 6072 |
{ |
| 6073 |
return x * nk_inv_sqrt(x); |
| 6074 |
} |
| 6075 |
NK_LIB float |
| 6076 |
nk_sin(float x) |
| 6077 |
{ |
| 6078 |
NK_STORAGE const float a0 = +1.91059300966915117e-31f; |
| 6079 |
NK_STORAGE const float a1 = +1.00086760103908896f; |
| 6080 |
NK_STORAGE const float a2 = -1.21276126894734565e-2f; |
| 6081 |
NK_STORAGE const float a3 = -1.38078780785773762e-1f; |
| 6082 |
NK_STORAGE const float a4 = -2.67353392911981221e-2f; |
| 6083 |
NK_STORAGE const float a5 = +2.08026600266304389e-2f; |
| 6084 |
NK_STORAGE const float a6 = -3.03996055049204407e-3f; |
| 6085 |
NK_STORAGE const float a7 = +1.38235642404333740e-4f; |
| 6086 |
return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7)))))); |
| 6087 |
} |
| 6088 |
NK_LIB float |
| 6089 |
nk_cos(float x) |
| 6090 |
{ |
| 6091 |
|
| 6092 |
|
| 6093 |
NK_STORAGE const float a0 = 9.9995999154986614e-1f; |
| 6094 |
NK_STORAGE const float a1 = 1.2548995793001028e-3f; |
| 6095 |
NK_STORAGE const float a2 = -5.0648546280678015e-1f; |
| 6096 |
NK_STORAGE const float a3 = 1.2942246466519995e-2f; |
| 6097 |
NK_STORAGE const float a4 = 2.8668384702547972e-2f; |
| 6098 |
NK_STORAGE const float a5 = 7.3726485210586547e-3f; |
| 6099 |
NK_STORAGE const float a6 = -3.8510875386947414e-3f; |
| 6100 |
NK_STORAGE const float a7 = 4.7196604604366623e-4f; |
| 6101 |
NK_STORAGE const float a8 = -1.8776444013090451e-5f; |
| 6102 |
return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*(a7 + x*a8))))))); |
| 6103 |
} |
| 6104 |
NK_LIB nk_uint |
| 6105 |
nk_round_up_pow2(nk_uint v) |
| 6106 |
{ |
| 6107 |
v--; |
| 6108 |
v |= v >> 1; |
| 6109 |
v |= v >> 2; |
| 6110 |
v |= v >> 4; |
| 6111 |
v |= v >> 8; |
| 6112 |
v |= v >> 16; |
| 6113 |
v++; |
| 6114 |
return v; |
| 6115 |
} |
| 6116 |
NK_LIB double |
| 6117 |
nk_pow(double x, int n) |
| 6118 |
{ |
| 6119 |
|
| 6120 |
double r = 1; |
| 6121 |
int plus = n >= 0; |
| 6122 |
n = (plus) ? n : -n; |
| 6123 |
while (n > 0) { |
| 6124 |
if ((n & 1) == 1) |
| 6125 |
r *= x; |
| 6126 |
n /= 2; |
| 6127 |
x *= x; |
| 6128 |
} |
| 6129 |
return plus ? r : 1.0 / r; |
| 6130 |
} |
| 6131 |
NK_LIB int |
| 6132 |
nk_ifloord(double x) |
| 6133 |
{ |
| 6134 |
x = (double)((int)x - ((x < 0.0) ? 1 : 0)); |
| 6135 |
return (int)x; |
| 6136 |
} |
| 6137 |
NK_LIB int |
| 6138 |
nk_ifloorf(float x) |
| 6139 |
{ |
| 6140 |
x = (float)((int)x - ((x < 0.0f) ? 1 : 0)); |
| 6141 |
return (int)x; |
| 6142 |
} |
| 6143 |
NK_LIB int |
| 6144 |
nk_iceilf(float x) |
| 6145 |
{ |
| 6146 |
if (x >= 0) { |
| 6147 |
int i = (int)x; |
| 6148 |
return (x > i) ? i+1: i; |
| 6149 |
} else { |
| 6150 |
int t = (int)x; |
| 6151 |
float r = x - (float)t; |
| 6152 |
return (r > 0.0f) ? t+1: t; |
| 6153 |
} |
| 6154 |
} |
| 6155 |
NK_LIB int |
| 6156 |
nk_log10(double n) |
| 6157 |
{ |
| 6158 |
int neg; |
| 6159 |
int ret; |
| 6160 |
int exp = 0; |
| 6161 |
|
| 6162 |
neg = (n < 0) ? 1 : 0; |
| 6163 |
ret = (neg) ? (int)-n : (int)n; |
| 6164 |
while ((ret / 10) > 0) { |
| 6165 |
ret /= 10; |
| 6166 |
exp++; |
| 6167 |
} |
| 6168 |
if (neg) exp = -exp; |
| 6169 |
return exp; |
| 6170 |
} |
| 6171 |
NK_API struct nk_rect |
| 6172 |
nk_get_null_rect(void) |
| 6173 |
{ |
| 6174 |
return nk_null_rect; |
| 6175 |
} |
| 6176 |
NK_API struct nk_rect |
| 6177 |
nk_rect(float x, float y, float w, float h) |
| 6178 |
{ |
| 6179 |
struct nk_rect r; |
| 6180 |
r.x = x; r.y = y; |
| 6181 |
r.w = w; r.h = h; |
| 6182 |
return r; |
| 6183 |
} |
| 6184 |
NK_API struct nk_rect |
| 6185 |
nk_recti(int x, int y, int w, int h) |
| 6186 |
{ |
| 6187 |
struct nk_rect r; |
| 6188 |
r.x = (float)x; |
| 6189 |
r.y = (float)y; |
| 6190 |
r.w = (float)w; |
| 6191 |
r.h = (float)h; |
| 6192 |
return r; |
| 6193 |
} |
| 6194 |
NK_API struct nk_rect |
| 6195 |
nk_recta(struct nk_vec2 pos, struct nk_vec2 size) |
| 6196 |
{ |
| 6197 |
return nk_rect(pos.x, pos.y, size.x, size.y); |
| 6198 |
} |
| 6199 |
NK_API struct nk_rect |
| 6200 |
nk_rectv(const float *r) |
| 6201 |
{ |
| 6202 |
return nk_rect(r[0], r[1], r[2], r[3]); |
| 6203 |
} |
| 6204 |
NK_API struct nk_rect |
| 6205 |
nk_rectiv(const int *r) |
| 6206 |
{ |
| 6207 |
return nk_recti(r[0], r[1], r[2], r[3]); |
| 6208 |
} |
| 6209 |
NK_API struct nk_vec2 |
| 6210 |
nk_rect_pos(struct nk_rect r) |
| 6211 |
{ |
| 6212 |
struct nk_vec2 ret; |
| 6213 |
ret.x = r.x; ret.y = r.y; |
| 6214 |
return ret; |
| 6215 |
} |
| 6216 |
NK_API struct nk_vec2 |
| 6217 |
nk_rect_size(struct nk_rect r) |
| 6218 |
{ |
| 6219 |
struct nk_vec2 ret; |
| 6220 |
ret.x = r.w; ret.y = r.h; |
| 6221 |
return ret; |
| 6222 |
} |
| 6223 |
NK_LIB struct nk_rect |
| 6224 |
nk_shrink_rect(struct nk_rect r, float amount) |
| 6225 |
{ |
| 6226 |
struct nk_rect res; |
| 6227 |
r.w = NK_MAX(r.w, 2 * amount); |
| 6228 |
r.h = NK_MAX(r.h, 2 * amount); |
| 6229 |
res.x = r.x + amount; |
| 6230 |
res.y = r.y + amount; |
| 6231 |
res.w = r.w - 2 * amount; |
| 6232 |
res.h = r.h - 2 * amount; |
| 6233 |
return res; |
| 6234 |
} |
| 6235 |
NK_LIB struct nk_rect |
| 6236 |
nk_pad_rect(struct nk_rect r, struct nk_vec2 pad) |
| 6237 |
{ |
| 6238 |
r.w = NK_MAX(r.w, 2 * pad.x); |
| 6239 |
r.h = NK_MAX(r.h, 2 * pad.y); |
| 6240 |
r.x += pad.x; r.y += pad.y; |
| 6241 |
r.w -= 2 * pad.x; |
| 6242 |
r.h -= 2 * pad.y; |
| 6243 |
return r; |
| 6244 |
} |
| 6245 |
NK_API struct nk_vec2 |
| 6246 |
nk_vec2(float x, float y) |
| 6247 |
{ |
| 6248 |
struct nk_vec2 ret; |
| 6249 |
ret.x = x; ret.y = y; |
| 6250 |
return ret; |
| 6251 |
} |
| 6252 |
NK_API struct nk_vec2 |
| 6253 |
nk_vec2i(int x, int y) |
| 6254 |
{ |
| 6255 |
struct nk_vec2 ret; |
| 6256 |
ret.x = (float)x; |
| 6257 |
ret.y = (float)y; |
| 6258 |
return ret; |
| 6259 |
} |
| 6260 |
NK_API struct nk_vec2 |
| 6261 |
nk_vec2v(const float *v) |
| 6262 |
{ |
| 6263 |
return nk_vec2(v[0], v[1]); |
| 6264 |
} |
| 6265 |
NK_API struct nk_vec2 |
| 6266 |
nk_vec2iv(const int *v) |
| 6267 |
{ |
| 6268 |
return nk_vec2i(v[0], v[1]); |
| 6269 |
} |
| 6270 |
NK_LIB void |
| 6271 |
nk_unify(struct nk_rect *clip, const struct nk_rect *a, float x0, float y0, |
| 6272 |
float x1, float y1) |
| 6273 |
{ |
| 6274 |
NK_ASSERT(a); |
| 6275 |
NK_ASSERT(clip); |
| 6276 |
clip->x = NK_MAX(a->x, x0); |
| 6277 |
clip->y = NK_MAX(a->y, y0); |
| 6278 |
clip->w = NK_MIN(a->x + a->w, x1) - clip->x; |
| 6279 |
clip->h = NK_MIN(a->y + a->h, y1) - clip->y; |
| 6280 |
clip->w = NK_MAX(0, clip->w); |
| 6281 |
clip->h = NK_MAX(0, clip->h); |
| 6282 |
} |
| 6283 |
|
| 6284 |
NK_API void |
| 6285 |
nk_triangle_from_direction(struct nk_vec2 *result, struct nk_rect r, |
| 6286 |
float pad_x, float pad_y, enum nk_heading direction) |
| 6287 |
{ |
| 6288 |
float w_half, h_half; |
| 6289 |
NK_ASSERT(result); |
| 6290 |
|
| 6291 |
r.w = NK_MAX(2 * pad_x, r.w); |
| 6292 |
r.h = NK_MAX(2 * pad_y, r.h); |
| 6293 |
r.w = r.w - 2 * pad_x; |
| 6294 |
r.h = r.h - 2 * pad_y; |
| 6295 |
|
| 6296 |
r.x = r.x + pad_x; |
| 6297 |
r.y = r.y + pad_y; |
| 6298 |
|
| 6299 |
w_half = r.w / 2.0f; |
| 6300 |
h_half = r.h / 2.0f; |
| 6301 |
|
| 6302 |
if (direction == NK_UP) { |
| 6303 |
result[0] = nk_vec2(r.x + w_half, r.y); |
| 6304 |
result[1] = nk_vec2(r.x + r.w, r.y + r.h); |
| 6305 |
result[2] = nk_vec2(r.x, r.y + r.h); |
| 6306 |
} else if (direction == NK_RIGHT) { |
| 6307 |
result[0] = nk_vec2(r.x, r.y); |
| 6308 |
result[1] = nk_vec2(r.x + r.w, r.y + h_half); |
| 6309 |
result[2] = nk_vec2(r.x, r.y + r.h); |
| 6310 |
} else if (direction == NK_DOWN) { |
| 6311 |
result[0] = nk_vec2(r.x, r.y); |
| 6312 |
result[1] = nk_vec2(r.x + r.w, r.y); |
| 6313 |
result[2] = nk_vec2(r.x + w_half, r.y + r.h); |
| 6314 |
} else { |
| 6315 |
result[0] = nk_vec2(r.x, r.y + h_half); |
| 6316 |
result[1] = nk_vec2(r.x + r.w, r.y); |
| 6317 |
result[2] = nk_vec2(r.x + r.w, r.y + r.h); |
| 6318 |
} |
| 6319 |
} |
| 6320 |
|
| 6321 |
|
| 6322 |
|
| 6323 |
|
| 6324 |
|
| 6325 |
|
| 6326 |
|
| 6327 |
|
| 6328 |
|
| 6329 |
|
| 6330 |
NK_INTERN int nk_str_match_here(const char *regexp, const char *text); |
| 6331 |
NK_INTERN int nk_str_match_star(int c, const char *regexp, const char *text); |
| 6332 |
NK_LIB int nk_is_lower(int c) {return (c >= 'a' && c <= 'z') || (c >= 0xE0 && c <= 0xFF);} |
| 6333 |
NK_LIB int nk_is_upper(int c){return (c >= 'A' && c <= 'Z') || (c >= 0xC0 && c <= 0xDF);} |
| 6334 |
NK_LIB int nk_to_upper(int c) {return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c;} |
| 6335 |
NK_LIB int nk_to_lower(int c) {return (c >= 'A' && c <= 'Z') ? (c - ('a' + 'A')) : c;} |
| 6336 |
|
| 6337 |
NK_LIB void* |
| 6338 |
nk_memcopy(void *dst0, const void *src0, nk_size length) |
| 6339 |
{ |
| 6340 |
nk_ptr t; |
| 6341 |
char *dst = (char*)dst0; |
| 6342 |
const char *src = (const char*)src0; |
| 6343 |
if (length == 0 || dst == src) |
| 6344 |
goto done; |
| 6345 |
|
| 6346 |
#define nk_word int |
| 6347 |
#define nk_wsize sizeof(nk_word) |
| 6348 |
#define nk_wmask (nk_wsize-1) |
| 6349 |
#define NK_TLOOP(s) if (t) NK_TLOOP1(s) |
| 6350 |
#define NK_TLOOP1(s) do { s; } while (--t) |
| 6351 |
|
| 6352 |
if (dst < src) { |
| 6353 |
t = (nk_ptr)src; |
| 6354 |
if ((t | (nk_ptr)dst) & nk_wmask) { |
| 6355 |
if ((t ^ (nk_ptr)dst) & nk_wmask || length < nk_wsize) |
| 6356 |
t = length; |
| 6357 |
else |
| 6358 |
t = nk_wsize - (t & nk_wmask); |
| 6359 |
length -= t; |
| 6360 |
NK_TLOOP1(*dst++ = *src++); |
| 6361 |
} |
| 6362 |
t = length / nk_wsize; |
| 6363 |
NK_TLOOP(*(nk_word*)(void*)dst = *(const nk_word*)(const void*)src; |
| 6364 |
src += nk_wsize; dst += nk_wsize); |
| 6365 |
t = length & nk_wmask; |
| 6366 |
NK_TLOOP(*dst++ = *src++); |
| 6367 |
} else { |
| 6368 |
src += length; |
| 6369 |
dst += length; |
| 6370 |
t = (nk_ptr)src; |
| 6371 |
if ((t | (nk_ptr)dst) & nk_wmask) { |
| 6372 |
if ((t ^ (nk_ptr)dst) & nk_wmask || length <= nk_wsize) |
| 6373 |
t = length; |
| 6374 |
else |
| 6375 |
t &= nk_wmask; |
| 6376 |
length -= t; |
| 6377 |
NK_TLOOP1(*--dst = *--src); |
| 6378 |
} |
| 6379 |
t = length / nk_wsize; |
| 6380 |
NK_TLOOP(src -= nk_wsize; dst -= nk_wsize; |
| 6381 |
*(nk_word*)(void*)dst = *(const nk_word*)(const void*)src); |
| 6382 |
t = length & nk_wmask; |
| 6383 |
NK_TLOOP(*--dst = *--src); |
| 6384 |
} |
| 6385 |
#undef nk_word |
| 6386 |
#undef nk_wsize |
| 6387 |
#undef nk_wmask |
| 6388 |
#undef NK_TLOOP |
| 6389 |
#undef NK_TLOOP1 |
| 6390 |
done: |
| 6391 |
return (dst0); |
| 6392 |
} |
| 6393 |
NK_LIB void |
| 6394 |
nk_memset(void *ptr, int c0, nk_size size) |
| 6395 |
{ |
| 6396 |
#define nk_word unsigned |
| 6397 |
#define nk_wsize sizeof(nk_word) |
| 6398 |
#define nk_wmask (nk_wsize - 1) |
| 6399 |
nk_byte *dst = (nk_byte*)ptr; |
| 6400 |
unsigned c = 0; |
| 6401 |
nk_size t = 0; |
| 6402 |
|
| 6403 |
if ((c = (nk_byte)c0) != 0) { |
| 6404 |
c = (c << 8) | c; |
| 6405 |
if (sizeof(unsigned int) > 2) |
| 6406 |
c = (c << 16) | c; |
| 6407 |
} |
| 6408 |
|
| 6409 |
|
| 6410 |
dst = (nk_byte*)ptr; |
| 6411 |
if (size < 3 * nk_wsize) { |
| 6412 |
while (size--) *dst++ = (nk_byte)c0; |
| 6413 |
return; |
| 6414 |
} |
| 6415 |
|
| 6416 |
|
| 6417 |
if ((t = NK_PTR_TO_UINT(dst) & nk_wmask) != 0) { |
| 6418 |
t = nk_wsize -t; |
| 6419 |
size -= t; |
| 6420 |
do { |
| 6421 |
*dst++ = (nk_byte)c0; |
| 6422 |
} while (--t != 0); |
| 6423 |
} |
| 6424 |
|
| 6425 |
|
| 6426 |
t = size / nk_wsize; |
| 6427 |
do { |
| 6428 |
*(nk_word*)((void*)dst) = c; |
| 6429 |
dst += nk_wsize; |
| 6430 |
} while (--t != 0); |
| 6431 |
|
| 6432 |
|
| 6433 |
t = (size & nk_wmask); |
| 6434 |
if (t != 0) { |
| 6435 |
do { |
| 6436 |
*dst++ = (nk_byte)c0; |
| 6437 |
} while (--t != 0); |
| 6438 |
} |
| 6439 |
|
| 6440 |
#undef nk_word |
| 6441 |
#undef nk_wsize |
| 6442 |
#undef nk_wmask |
| 6443 |
} |
| 6444 |
NK_LIB void |
| 6445 |
nk_zero(void *ptr, nk_size size) |
| 6446 |
{ |
| 6447 |
NK_ASSERT(ptr); |
| 6448 |
NK_MEMSET(ptr, 0, size); |
| 6449 |
} |
| 6450 |
NK_API int |
| 6451 |
nk_strlen(const char *str) |
| 6452 |
{ |
| 6453 |
int siz = 0; |
| 6454 |
NK_ASSERT(str); |
| 6455 |
while (str && *str++ != '\0') siz++; |
| 6456 |
return siz; |
| 6457 |
} |
| 6458 |
NK_API int |
| 6459 |
nk_strtoi(const char *str, const char **endptr) |
| 6460 |
{ |
| 6461 |
int neg = 1; |
| 6462 |
const char *p = str; |
| 6463 |
int value = 0; |
| 6464 |
|
| 6465 |
NK_ASSERT(str); |
| 6466 |
if (!str) return 0; |
| 6467 |
|
| 6468 |
|
| 6469 |
while (*p == ' ') p++; |
| 6470 |
if (*p == '-') { |
| 6471 |
neg = -1; |
| 6472 |
p++; |
| 6473 |
} |
| 6474 |
while (*p && *p >= '0' && *p <= '9') { |
| 6475 |
value = value * 10 + (int) (*p - '0'); |
| 6476 |
p++; |
| 6477 |
} |
| 6478 |
if (endptr) |
| 6479 |
*endptr = p; |
| 6480 |
return neg*value; |
| 6481 |
} |
| 6482 |
NK_API double |
| 6483 |
nk_strtod(const char *str, const char **endptr) |
| 6484 |
{ |
| 6485 |
double m; |
| 6486 |
double neg = 1.0; |
| 6487 |
const char *p = str; |
| 6488 |
double value = 0; |
| 6489 |
double number = 0; |
| 6490 |
|
| 6491 |
NK_ASSERT(str); |
| 6492 |
if (!str) return 0; |
| 6493 |
|
| 6494 |
|
| 6495 |
while (*p == ' ') p++; |
| 6496 |
if (*p == '-') { |
| 6497 |
neg = -1.0; |
| 6498 |
p++; |
| 6499 |
} |
| 6500 |
|
| 6501 |
while (*p && *p != '.' && *p != 'e') { |
| 6502 |
value = value * 10.0 + (double) (*p - '0'); |
| 6503 |
p++; |
| 6504 |
} |
| 6505 |
|
| 6506 |
if (*p == '.') { |
| 6507 |
p++; |
| 6508 |
for(m = 0.1; *p && *p != 'e'; p++ ) { |
| 6509 |
value = value + (double) (*p - '0') * m; |
| 6510 |
m *= 0.1; |
| 6511 |
} |
| 6512 |
} |
| 6513 |
if (*p == 'e') { |
| 6514 |
int i, pow, div; |
| 6515 |
p++; |
| 6516 |
if (*p == '-') { |
| 6517 |
div = nk_true; |
| 6518 |
p++; |
| 6519 |
} else if (*p == '+') { |
| 6520 |
div = nk_false; |
| 6521 |
p++; |
| 6522 |
} else div = nk_false; |
| 6523 |
|
| 6524 |
for (pow = 0; *p; p++) |
| 6525 |
pow = pow * 10 + (int) (*p - '0'); |
| 6526 |
|
| 6527 |
for (m = 1.0, i = 0; i < pow; i++) |
| 6528 |
m *= 10.0; |
| 6529 |
|
| 6530 |
if (div) |
| 6531 |
value /= m; |
| 6532 |
else value *= m; |
| 6533 |
} |
| 6534 |
number = value * neg; |
| 6535 |
if (endptr) |
| 6536 |
*endptr = p; |
| 6537 |
return number; |
| 6538 |
} |
| 6539 |
NK_API float |
| 6540 |
nk_strtof(const char *str, const char **endptr) |
| 6541 |
{ |
| 6542 |
float float_value; |
| 6543 |
double double_value; |
| 6544 |
double_value = NK_STRTOD(str, endptr); |
| 6545 |
float_value = (float)double_value; |
| 6546 |
return float_value; |
| 6547 |
} |
| 6548 |
NK_API int |
| 6549 |
nk_stricmp(const char *s1, const char *s2) |
| 6550 |
{ |
| 6551 |
nk_int c1,c2,d; |
| 6552 |
do { |
| 6553 |
c1 = *s1++; |
| 6554 |
c2 = *s2++; |
| 6555 |
d = c1 - c2; |
| 6556 |
while (d) { |
| 6557 |
if (c1 <= 'Z' && c1 >= 'A') { |
| 6558 |
d += ('a' - 'A'); |
| 6559 |
if (!d) break; |
| 6560 |
} |
| 6561 |
if (c2 <= 'Z' && c2 >= 'A') { |
| 6562 |
d -= ('a' - 'A'); |
| 6563 |
if (!d) break; |
| 6564 |
} |
| 6565 |
return ((d >= 0) << 1) - 1; |
| 6566 |
} |
| 6567 |
} while (c1); |
| 6568 |
return 0; |
| 6569 |
} |
| 6570 |
NK_API int |
| 6571 |
nk_stricmpn(const char *s1, const char *s2, int n) |
| 6572 |
{ |
| 6573 |
int c1,c2,d; |
| 6574 |
NK_ASSERT(n >= 0); |
| 6575 |
do { |
| 6576 |
c1 = *s1++; |
| 6577 |
c2 = *s2++; |
| 6578 |
if (!n--) return 0; |
| 6579 |
|
| 6580 |
d = c1 - c2; |
| 6581 |
while (d) { |
| 6582 |
if (c1 <= 'Z' && c1 >= 'A') { |
| 6583 |
d += ('a' - 'A'); |
| 6584 |
if (!d) break; |
| 6585 |
} |
| 6586 |
if (c2 <= 'Z' && c2 >= 'A') { |
| 6587 |
d -= ('a' - 'A'); |
| 6588 |
if (!d) break; |
| 6589 |
} |
| 6590 |
return ((d >= 0) << 1) - 1; |
| 6591 |
} |
| 6592 |
} while (c1); |
| 6593 |
return 0; |
| 6594 |
} |
| 6595 |
NK_INTERN int |
| 6596 |
nk_str_match_here(const char *regexp, const char *text) |
| 6597 |
{ |
| 6598 |
if (regexp[0] == '\0') |
| 6599 |
return 1; |
| 6600 |
if (regexp[1] == '*') |
| 6601 |
return nk_str_match_star(regexp[0], regexp+2, text); |
| 6602 |
if (regexp[0] == '$' && regexp[1] == '\0') |
| 6603 |
return *text == '\0'; |
| 6604 |
if (*text!='\0' && (regexp[0]=='.' || regexp[0]==*text)) |
| 6605 |
return nk_str_match_here(regexp+1, text+1); |
| 6606 |
return 0; |
| 6607 |
} |
| 6608 |
NK_INTERN int |
| 6609 |
nk_str_match_star(int c, const char *regexp, const char *text) |
| 6610 |
{ |
| 6611 |
do { |
| 6612 |
if (nk_str_match_here(regexp, text)) |
| 6613 |
return 1; |
| 6614 |
} while (*text != '\0' && (*text++ == c || c == '.')); |
| 6615 |
return 0; |
| 6616 |
} |
| 6617 |
NK_API int |
| 6618 |
nk_strfilter(const char *text, const char *regexp) |
| 6619 |
{ |
| 6620 |
|
| 6621 |
|
| 6622 |
|
| 6623 |
|
| 6624 |
|
| 6625 |
|
| 6626 |
if (regexp[0] == '^') |
| 6627 |
return nk_str_match_here(regexp+1, text); |
| 6628 |
do { |
| 6629 |
if (nk_str_match_here(regexp, text)) |
| 6630 |
return 1; |
| 6631 |
} while (*text++ != '\0'); |
| 6632 |
return 0; |
| 6633 |
} |
| 6634 |
NK_API int |
| 6635 |
nk_strmatch_fuzzy_text(const char *str, int str_len, |
| 6636 |
const char *pattern, int *out_score) |
| 6637 |
{ |
| 6638 |
|
| 6639 |
|
| 6640 |
|
| 6641 |
|
| 6642 |
|
| 6643 |
#define NK_ADJACENCY_BONUS 5 |
| 6644 |
|
| 6645 |
#define NK_SEPARATOR_BONUS 10 |
| 6646 |
|
| 6647 |
#define NK_CAMEL_BONUS 10 |
| 6648 |
|
| 6649 |
#define NK_LEADING_LETTER_PENALTY (-3) |
| 6650 |
|
| 6651 |
#define NK_MAX_LEADING_LETTER_PENALTY (-9) |
| 6652 |
|
| 6653 |
#define NK_UNMATCHED_LETTER_PENALTY (-1) |
| 6654 |
|
| 6655 |
|
| 6656 |
int score = 0; |
| 6657 |
char const * pattern_iter = pattern; |
| 6658 |
int str_iter = 0; |
| 6659 |
int prev_matched = nk_false; |
| 6660 |
int prev_lower = nk_false; |
| 6661 |
|
| 6662 |
int prev_separator = nk_true; |
| 6663 |
|
| 6664 |
|
| 6665 |
char const * best_letter = 0; |
| 6666 |
int best_letter_score = 0; |
| 6667 |
|
| 6668 |
|
| 6669 |
NK_ASSERT(str); |
| 6670 |
NK_ASSERT(pattern); |
| 6671 |
if (!str || !str_len || !pattern) return 0; |
| 6672 |
while (str_iter < str_len) |
| 6673 |
{ |
| 6674 |
const char pattern_letter = *pattern_iter; |
| 6675 |
const char str_letter = str[str_iter]; |
| 6676 |
|
| 6677 |
int next_match = *pattern_iter != '\0' && |
| 6678 |
nk_to_lower(pattern_letter) == nk_to_lower(str_letter); |
| 6679 |
int rematch = best_letter && nk_to_upper(*best_letter) == nk_to_upper(str_letter); |
| 6680 |
|
| 6681 |
int advanced = next_match && best_letter; |
| 6682 |
int pattern_repeat = best_letter && *pattern_iter != '\0'; |
| 6683 |
pattern_repeat = pattern_repeat && |
| 6684 |
nk_to_lower(*best_letter) == nk_to_lower(pattern_letter); |
| 6685 |
|
| 6686 |
if (advanced || pattern_repeat) { |
| 6687 |
score += best_letter_score; |
| 6688 |
best_letter = 0; |
| 6689 |
best_letter_score = 0; |
| 6690 |
} |
| 6691 |
|
| 6692 |
if (next_match || rematch) |
| 6693 |
{ |
| 6694 |
int new_score = 0; |
| 6695 |
|
| 6696 |
if (pattern_iter == pattern) { |
| 6697 |
int count = (int)(&str[str_iter] - str); |
| 6698 |
int penalty = NK_LEADING_LETTER_PENALTY * count; |
| 6699 |
if (penalty < NK_MAX_LEADING_LETTER_PENALTY) |
| 6700 |
penalty = NK_MAX_LEADING_LETTER_PENALTY; |
| 6701 |
|
| 6702 |
score += penalty; |
| 6703 |
} |
| 6704 |
|
| 6705 |
|
| 6706 |
if (prev_matched) |
| 6707 |
new_score += NK_ADJACENCY_BONUS; |
| 6708 |
|
| 6709 |
|
| 6710 |
if (prev_separator) |
| 6711 |
new_score += NK_SEPARATOR_BONUS; |
| 6712 |
|
| 6713 |
|
| 6714 |
if (prev_lower && nk_is_upper(str_letter)) |
| 6715 |
new_score += NK_CAMEL_BONUS; |
| 6716 |
|
| 6717 |
|
| 6718 |
if (next_match) |
| 6719 |
++pattern_iter; |
| 6720 |
|
| 6721 |
|
| 6722 |
if (new_score >= best_letter_score) { |
| 6723 |
|
| 6724 |
if (best_letter != 0) |
| 6725 |
score += NK_UNMATCHED_LETTER_PENALTY; |
| 6726 |
|
| 6727 |
best_letter = &str[str_iter]; |
| 6728 |
best_letter_score = new_score; |
| 6729 |
} |
| 6730 |
prev_matched = nk_true; |
| 6731 |
} else { |
| 6732 |
score += NK_UNMATCHED_LETTER_PENALTY; |
| 6733 |
prev_matched = nk_false; |
| 6734 |
} |
| 6735 |
|
| 6736 |
|
| 6737 |
prev_lower = nk_is_lower(str_letter) != 0; |
| 6738 |
prev_separator = str_letter == '_' || str_letter == ' '; |
| 6739 |
|
| 6740 |
++str_iter; |
| 6741 |
} |
| 6742 |
|
| 6743 |
|
| 6744 |
if (best_letter) |
| 6745 |
score += best_letter_score; |
| 6746 |
|
| 6747 |
|
| 6748 |
if (*pattern_iter != '\0') |
| 6749 |
return nk_false; |
| 6750 |
|
| 6751 |
if (out_score) |
| 6752 |
*out_score = score; |
| 6753 |
return nk_true; |
| 6754 |
} |
| 6755 |
NK_API int |
| 6756 |
nk_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score) |
| 6757 |
{ |
| 6758 |
return nk_strmatch_fuzzy_text(str, nk_strlen(str), pattern, out_score); |
| 6759 |
} |
| 6760 |
NK_LIB int |
| 6761 |
nk_string_float_limit(char *string, int prec) |
| 6762 |
{ |
| 6763 |
int dot = 0; |
| 6764 |
char *c = string; |
| 6765 |
while (*c) { |
| 6766 |
if (*c == '.') { |
| 6767 |
dot = 1; |
| 6768 |
c++; |
| 6769 |
continue; |
| 6770 |
} |
| 6771 |
if (dot == (prec+1)) { |
| 6772 |
*c = 0; |
| 6773 |
break; |
| 6774 |
} |
| 6775 |
if (dot > 0) dot++; |
| 6776 |
c++; |
| 6777 |
} |
| 6778 |
return (int)(c - string); |
| 6779 |
} |
| 6780 |
NK_INTERN void |
| 6781 |
nk_strrev_ascii(char *s) |
| 6782 |
{ |
| 6783 |
int len = nk_strlen(s); |
| 6784 |
int end = len / 2; |
| 6785 |
int i = 0; |
| 6786 |
char t; |
| 6787 |
for (; i < end; ++i) { |
| 6788 |
t = s[i]; |
| 6789 |
s[i] = s[len - 1 - i]; |
| 6790 |
s[len -1 - i] = t; |
| 6791 |
} |
| 6792 |
} |
| 6793 |
NK_LIB char* |
| 6794 |
nk_itoa(char *s, long n) |
| 6795 |
{ |
| 6796 |
long i = 0; |
| 6797 |
if (n == 0) { |
| 6798 |
s[i++] = '0'; |
| 6799 |
s[i] = 0; |
| 6800 |
return s; |
| 6801 |
} |
| 6802 |
if (n < 0) { |
| 6803 |
s[i++] = '-'; |
| 6804 |
n = -n; |
| 6805 |
} |
| 6806 |
while (n > 0) { |
| 6807 |
s[i++] = (char)('0' + (n % 10)); |
| 6808 |
n /= 10; |
| 6809 |
} |
| 6810 |
s[i] = 0; |
| 6811 |
if (s[0] == '-') |
| 6812 |
++s; |
| 6813 |
|
| 6814 |
nk_strrev_ascii(s); |
| 6815 |
return s; |
| 6816 |
} |
| 6817 |
NK_LIB char* |
| 6818 |
nk_dtoa(char *s, double n) |
| 6819 |
{ |
| 6820 |
int useExp = 0; |
| 6821 |
int digit = 0, m = 0, m1 = 0; |
| 6822 |
char *c = s; |
| 6823 |
int neg = 0; |
| 6824 |
|
| 6825 |
NK_ASSERT(s); |
| 6826 |
if (!s) return 0; |
| 6827 |
|
| 6828 |
if (n == 0.0) { |
| 6829 |
s[0] = '0'; s[1] = '\0'; |
| 6830 |
return s; |
| 6831 |
} |
| 6832 |
|
| 6833 |
neg = (n < 0); |
| 6834 |
if (neg) n = -n; |
| 6835 |
|
| 6836 |
|
| 6837 |
m = nk_log10(n); |
| 6838 |
useExp = (m >= 14 || (neg && m >= 9) || m <= -9); |
| 6839 |
if (neg) *(c++) = '-'; |
| 6840 |
|
| 6841 |
|
| 6842 |
if (useExp) { |
| 6843 |
if (m < 0) |
| 6844 |
m -= 1; |
| 6845 |
n = n / (double)nk_pow(10.0, m); |
| 6846 |
m1 = m; |
| 6847 |
m = 0; |
| 6848 |
} |
| 6849 |
if (m < 1.0) { |
| 6850 |
m = 0; |
| 6851 |
} |
| 6852 |
|
| 6853 |
|
| 6854 |
while (n > NK_FLOAT_PRECISION || m >= 0) { |
| 6855 |
double weight = nk_pow(10.0, m); |
| 6856 |
if (weight > 0) { |
| 6857 |
double t = (double)n / weight; |
| 6858 |
digit = nk_ifloord(t); |
| 6859 |
n -= ((double)digit * weight); |
| 6860 |
*(c++) = (char)('0' + (char)digit); |
| 6861 |
} |
| 6862 |
if (m == 0 && n > 0) |
| 6863 |
*(c++) = '.'; |
| 6864 |
m--; |
| 6865 |
} |
| 6866 |
|
| 6867 |
if (useExp) { |
| 6868 |
|
| 6869 |
int i, j; |
| 6870 |
*(c++) = 'e'; |
| 6871 |
if (m1 > 0) { |
| 6872 |
*(c++) = '+'; |
| 6873 |
} else { |
| 6874 |
*(c++) = '-'; |
| 6875 |
m1 = -m1; |
| 6876 |
} |
| 6877 |
m = 0; |
| 6878 |
while (m1 > 0) { |
| 6879 |
*(c++) = (char)('0' + (char)(m1 % 10)); |
| 6880 |
m1 /= 10; |
| 6881 |
m++; |
| 6882 |
} |
| 6883 |
c -= m; |
| 6884 |
for (i = 0, j = m-1; i<j; i++, j--) { |
| 6885 |
|
| 6886 |
c[i] ^= c[j]; |
| 6887 |
c[j] ^= c[i]; |
| 6888 |
c[i] ^= c[j]; |
| 6889 |
} |
| 6890 |
c += m; |
| 6891 |
} |
| 6892 |
*(c) = '\0'; |
| 6893 |
return s; |
| 6894 |
} |
| 6895 |
#ifdef NK_INCLUDE_STANDARD_VARARGS |
| 6896 |
#ifndef NK_INCLUDE_STANDARD_IO |
| 6897 |
NK_INTERN int |
| 6898 |
nk_vsnprintf(char *buf, int buf_size, const char *fmt, va_list args) |
| 6899 |
{ |
| 6900 |
enum nk_arg_type { |
| 6901 |
NK_ARG_TYPE_CHAR, |
| 6902 |
NK_ARG_TYPE_SHORT, |
| 6903 |
NK_ARG_TYPE_DEFAULT, |
| 6904 |
NK_ARG_TYPE_LONG |
| 6905 |
}; |
| 6906 |
enum nk_arg_flags { |
| 6907 |
NK_ARG_FLAG_LEFT = 0x01, |
| 6908 |
NK_ARG_FLAG_PLUS = 0x02, |
| 6909 |
NK_ARG_FLAG_SPACE = 0x04, |
| 6910 |
NK_ARG_FLAG_NUM = 0x10, |
| 6911 |
NK_ARG_FLAG_ZERO = 0x20 |
| 6912 |
}; |
| 6913 |
|
| 6914 |
char number_buffer[NK_MAX_NUMBER_BUFFER]; |
| 6915 |
enum nk_arg_type arg_type = NK_ARG_TYPE_DEFAULT; |
| 6916 |
int precision = NK_DEFAULT; |
| 6917 |
int width = NK_DEFAULT; |
| 6918 |
nk_flags flag = 0; |
| 6919 |
|
| 6920 |
int len = 0; |
| 6921 |
int result = -1; |
| 6922 |
const char *iter = fmt; |
| 6923 |
|
| 6924 |
NK_ASSERT(buf); |
| 6925 |
NK_ASSERT(buf_size); |
| 6926 |
if (!buf || !buf_size || !fmt) return 0; |
| 6927 |
for (iter = fmt; *iter && len < buf_size; iter++) { |
| 6928 |
|
| 6929 |
while (*iter && (*iter != '%') && (len < buf_size)) |
| 6930 |
buf[len++] = *iter++; |
| 6931 |
if (!(*iter) || len >= buf_size) break; |
| 6932 |
iter++; |
| 6933 |
|
| 6934 |
|
| 6935 |
while (*iter) { |
| 6936 |
if (*iter == '-') flag |= NK_ARG_FLAG_LEFT; |
| 6937 |
else if (*iter == '+') flag |= NK_ARG_FLAG_PLUS; |
| 6938 |
else if (*iter == ' ') flag |= NK_ARG_FLAG_SPACE; |
| 6939 |
else if (*iter == '#') flag |= NK_ARG_FLAG_NUM; |
| 6940 |
else if (*iter == '0') flag |= NK_ARG_FLAG_ZERO; |
| 6941 |
else break; |
| 6942 |
iter++; |
| 6943 |
} |
| 6944 |
|
| 6945 |
|
| 6946 |
width = NK_DEFAULT; |
| 6947 |
if (*iter >= '1' && *iter <= '9') { |
| 6948 |
const char *end; |
| 6949 |
width = nk_strtoi(iter, &end); |
| 6950 |
if (end == iter) |
| 6951 |
width = -1; |
| 6952 |
else iter = end; |
| 6953 |
} else if (*iter == '*') { |
| 6954 |
width = va_arg(args, int); |
| 6955 |
iter++; |
| 6956 |
} |
| 6957 |
|
| 6958 |
|
| 6959 |
precision = NK_DEFAULT; |
| 6960 |
if (*iter == '.') { |
| 6961 |
iter++; |
| 6962 |
if (*iter == '*') { |
| 6963 |
precision = va_arg(args, int); |
| 6964 |
iter++; |
| 6965 |
} else { |
| 6966 |
const char *end; |
| 6967 |
precision = nk_strtoi(iter, &end); |
| 6968 |
if (end == iter) |
| 6969 |
precision = -1; |
| 6970 |
else iter = end; |
| 6971 |
} |
| 6972 |
} |
| 6973 |
|
| 6974 |
|
| 6975 |
if (*iter == 'h') { |
| 6976 |
if (*(iter+1) == 'h') { |
| 6977 |
arg_type = NK_ARG_TYPE_CHAR; |
| 6978 |
iter++; |
| 6979 |
} else arg_type = NK_ARG_TYPE_SHORT; |
| 6980 |
iter++; |
| 6981 |
} else if (*iter == 'l') { |
| 6982 |
arg_type = NK_ARG_TYPE_LONG; |
| 6983 |
iter++; |
| 6984 |
} else arg_type = NK_ARG_TYPE_DEFAULT; |
| 6985 |
|
| 6986 |
|
| 6987 |
if (*iter == '%') { |
| 6988 |
NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT); |
| 6989 |
NK_ASSERT(precision == NK_DEFAULT); |
| 6990 |
NK_ASSERT(width == NK_DEFAULT); |
| 6991 |
if (len < buf_size) |
| 6992 |
buf[len++] = '%'; |
| 6993 |
} else if (*iter == 's') { |
| 6994 |
|
| 6995 |
const char *str = va_arg(args, const char*); |
| 6996 |
NK_ASSERT(str != buf && "buffer and argument are not allowed to overlap!"); |
| 6997 |
NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT); |
| 6998 |
NK_ASSERT(precision == NK_DEFAULT); |
| 6999 |
NK_ASSERT(width == NK_DEFAULT); |
| 7000 |
if (str == buf) return -1; |
| 7001 |
while (str && *str && len < buf_size) |
| 7002 |
buf[len++] = *str++; |
| 7003 |
} else if (*iter == 'n') { |
| 7004 |
|
| 7005 |
signed int *n = va_arg(args, int*); |
| 7006 |
NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT); |
| 7007 |
NK_ASSERT(precision == NK_DEFAULT); |
| 7008 |
NK_ASSERT(width == NK_DEFAULT); |
| 7009 |
if (n) *n = len; |
| 7010 |
} else if (*iter == 'c' || *iter == 'i' || *iter == 'd') { |
| 7011 |
|
| 7012 |
long value = 0; |
| 7013 |
const char *num_iter; |
| 7014 |
int num_len, num_print, padding; |
| 7015 |
int cur_precision = NK_MAX(precision, 1); |
| 7016 |
int cur_width = NK_MAX(width, 0); |
| 7017 |
|
| 7018 |
|
| 7019 |
if (arg_type == NK_ARG_TYPE_CHAR) |
| 7020 |
value = (signed char)va_arg(args, int); |
| 7021 |
else if (arg_type == NK_ARG_TYPE_SHORT) |
| 7022 |
value = (signed short)va_arg(args, int); |
| 7023 |
else if (arg_type == NK_ARG_TYPE_LONG) |
| 7024 |
value = va_arg(args, signed long); |
| 7025 |
else if (*iter == 'c') |
| 7026 |
value = (unsigned char)va_arg(args, int); |
| 7027 |
else value = va_arg(args, signed int); |
| 7028 |
|
| 7029 |
|
| 7030 |
nk_itoa(number_buffer, value); |
| 7031 |
num_len = nk_strlen(number_buffer); |
| 7032 |
padding = NK_MAX(cur_width - NK_MAX(cur_precision, num_len), 0); |
| 7033 |
if ((flag & NK_ARG_FLAG_PLUS) || (flag & NK_ARG_FLAG_SPACE)) |
| 7034 |
padding = NK_MAX(padding-1, 0); |
| 7035 |
|
| 7036 |
|
| 7037 |
if (!(flag & NK_ARG_FLAG_LEFT)) { |
| 7038 |
while (padding-- > 0 && (len < buf_size)) { |
| 7039 |
if ((flag & NK_ARG_FLAG_ZERO) && (precision == NK_DEFAULT)) |
| 7040 |
buf[len++] = '0'; |
| 7041 |
else buf[len++] = ' '; |
| 7042 |
} |
| 7043 |
} |
| 7044 |
|
| 7045 |
|
| 7046 |
if ((flag & NK_ARG_FLAG_PLUS) && value >= 0 && len < buf_size) |
| 7047 |
buf[len++] = '+'; |
| 7048 |
else if ((flag & NK_ARG_FLAG_SPACE) && value >= 0 && len < buf_size) |
| 7049 |
buf[len++] = ' '; |
| 7050 |
|
| 7051 |
|
| 7052 |
num_print = NK_MAX(cur_precision, num_len); |
| 7053 |
while (precision && (num_print > num_len) && (len < buf_size)) { |
| 7054 |
buf[len++] = '0'; |
| 7055 |
num_print--; |
| 7056 |
} |
| 7057 |
|
| 7058 |
|
| 7059 |
num_iter = number_buffer; |
| 7060 |
while (precision && *num_iter && len < buf_size) |
| 7061 |
buf[len++] = *num_iter++; |
| 7062 |
|
| 7063 |
|
| 7064 |
if (flag & NK_ARG_FLAG_LEFT) { |
| 7065 |
while ((padding-- > 0) && (len < buf_size)) |
| 7066 |
buf[len++] = ' '; |
| 7067 |
} |
| 7068 |
} else if (*iter == 'o' || *iter == 'x' || *iter == 'X' || *iter == 'u') { |
| 7069 |
|
| 7070 |
unsigned long value = 0; |
| 7071 |
int num_len = 0, num_print, padding = 0; |
| 7072 |
int cur_precision = NK_MAX(precision, 1); |
| 7073 |
int cur_width = NK_MAX(width, 0); |
| 7074 |
unsigned int base = (*iter == 'o') ? 8: (*iter == 'u')? 10: 16; |
| 7075 |
|
| 7076 |
|
| 7077 |
const char *upper_output_format = "0123456789ABCDEF"; |
| 7078 |
const char *lower_output_format = "0123456789abcdef"; |
| 7079 |
const char *output_format = (*iter == 'x') ? |
| 7080 |
lower_output_format: upper_output_format; |
| 7081 |
|
| 7082 |
|
| 7083 |
if (arg_type == NK_ARG_TYPE_CHAR) |
| 7084 |
value = (unsigned char)va_arg(args, int); |
| 7085 |
else if (arg_type == NK_ARG_TYPE_SHORT) |
| 7086 |
value = (unsigned short)va_arg(args, int); |
| 7087 |
else if (arg_type == NK_ARG_TYPE_LONG) |
| 7088 |
value = va_arg(args, unsigned long); |
| 7089 |
else value = va_arg(args, unsigned int); |
| 7090 |
|
| 7091 |
do { |
| 7092 |
|
| 7093 |
int digit = output_format[value % base]; |
| 7094 |
if (num_len < NK_MAX_NUMBER_BUFFER) |
| 7095 |
number_buffer[num_len++] = (char)digit; |
| 7096 |
value /= base; |
| 7097 |
} while (value > 0); |
| 7098 |
|
| 7099 |
num_print = NK_MAX(cur_precision, num_len); |
| 7100 |
padding = NK_MAX(cur_width - NK_MAX(cur_precision, num_len), 0); |
| 7101 |
if (flag & NK_ARG_FLAG_NUM) |
| 7102 |
padding = NK_MAX(padding-1, 0); |
| 7103 |
|
| 7104 |
|
| 7105 |
if (!(flag & NK_ARG_FLAG_LEFT)) { |
| 7106 |
while ((padding-- > 0) && (len < buf_size)) { |
| 7107 |
if ((flag & NK_ARG_FLAG_ZERO) && (precision == NK_DEFAULT)) |
| 7108 |
buf[len++] = '0'; |
| 7109 |
else buf[len++] = ' '; |
| 7110 |
} |
| 7111 |
} |
| 7112 |
|
| 7113 |
|
| 7114 |
if (num_print && (flag & NK_ARG_FLAG_NUM)) { |
| 7115 |
if ((*iter == 'o') && (len < buf_size)) { |
| 7116 |
buf[len++] = '0'; |
| 7117 |
} else if ((*iter == 'x') && ((len+1) < buf_size)) { |
| 7118 |
buf[len++] = '0'; |
| 7119 |
buf[len++] = 'x'; |
| 7120 |
} else if ((*iter == 'X') && ((len+1) < buf_size)) { |
| 7121 |
buf[len++] = '0'; |
| 7122 |
buf[len++] = 'X'; |
| 7123 |
} |
| 7124 |
} |
| 7125 |
while (precision && (num_print > num_len) && (len < buf_size)) { |
| 7126 |
buf[len++] = '0'; |
| 7127 |
num_print--; |
| 7128 |
} |
| 7129 |
|
| 7130 |
|
| 7131 |
while (num_len > 0) { |
| 7132 |
if (precision && (len < buf_size)) |
| 7133 |
buf[len++] = number_buffer[num_len-1]; |
| 7134 |
num_len--; |
| 7135 |
} |
| 7136 |
|
| 7137 |
|
| 7138 |
if (flag & NK_ARG_FLAG_LEFT) { |
| 7139 |
while ((padding-- > 0) && (len < buf_size)) |
| 7140 |
buf[len++] = ' '; |
| 7141 |
} |
| 7142 |
} else if (*iter == 'f') { |
| 7143 |
|
| 7144 |
const char *num_iter; |
| 7145 |
int cur_precision = (precision < 0) ? 6: precision; |
| 7146 |
int prefix, cur_width = NK_MAX(width, 0); |
| 7147 |
double value = va_arg(args, double); |
| 7148 |
int num_len = 0, frac_len = 0, dot = 0; |
| 7149 |
int padding = 0; |
| 7150 |
|
| 7151 |
NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT); |
| 7152 |
NK_DTOA(number_buffer, value); |
| 7153 |
num_len = nk_strlen(number_buffer); |
| 7154 |
|
| 7155 |
|
| 7156 |
num_iter = number_buffer; |
| 7157 |
while (*num_iter && *num_iter != '.') |
| 7158 |
num_iter++; |
| 7159 |
|
| 7160 |
prefix = (*num_iter == '.')?(int)(num_iter - number_buffer)+1:0; |
| 7161 |
padding = NK_MAX(cur_width - (prefix + NK_MIN(cur_precision, num_len - prefix)) , 0); |
| 7162 |
if ((flag & NK_ARG_FLAG_PLUS) || (flag & NK_ARG_FLAG_SPACE)) |
| 7163 |
padding = NK_MAX(padding-1, 0); |
| 7164 |
|
| 7165 |
|
| 7166 |
if (!(flag & NK_ARG_FLAG_LEFT)) { |
| 7167 |
while (padding-- > 0 && (len < buf_size)) { |
| 7168 |
if (flag & NK_ARG_FLAG_ZERO) |
| 7169 |
buf[len++] = '0'; |
| 7170 |
else buf[len++] = ' '; |
| 7171 |
} |
| 7172 |
} |
| 7173 |
|
| 7174 |
|
| 7175 |
num_iter = number_buffer; |
| 7176 |
if ((flag & NK_ARG_FLAG_PLUS) && (value >= 0) && (len < buf_size)) |
| 7177 |
buf[len++] = '+'; |
| 7178 |
else if ((flag & NK_ARG_FLAG_SPACE) && (value >= 0) && (len < buf_size)) |
| 7179 |
buf[len++] = ' '; |
| 7180 |
while (*num_iter) { |
| 7181 |
if (dot) frac_len++; |
| 7182 |
if (len < buf_size) |
| 7183 |
buf[len++] = *num_iter; |
| 7184 |
if (*num_iter == '.') dot = 1; |
| 7185 |
if (frac_len >= cur_precision) break; |
| 7186 |
num_iter++; |
| 7187 |
} |
| 7188 |
|
| 7189 |
|
| 7190 |
while (frac_len < cur_precision) { |
| 7191 |
if (!dot && len < buf_size) { |
| 7192 |
buf[len++] = '.'; |
| 7193 |
dot = 1; |
| 7194 |
} |
| 7195 |
if (len < buf_size) |
| 7196 |
buf[len++] = '0'; |
| 7197 |
frac_len++; |
| 7198 |
} |
| 7199 |
|
| 7200 |
|
| 7201 |
if (flag & NK_ARG_FLAG_LEFT) { |
| 7202 |
while ((padding-- > 0) && (len < buf_size)) |
| 7203 |
buf[len++] = ' '; |
| 7204 |
} |
| 7205 |
} else { |
| 7206 |
|
| 7207 |
NK_ASSERT(0 && "specifier is not supported!"); |
| 7208 |
return result; |
| 7209 |
} |
| 7210 |
} |
| 7211 |
buf[(len >= buf_size)?(buf_size-1):len] = 0; |
| 7212 |
result = (len >= buf_size)?-1:len; |
| 7213 |
return result; |
| 7214 |
} |
| 7215 |
#endif |
| 7216 |
NK_LIB int |
| 7217 |
nk_strfmt(char *buf, int buf_size, const char *fmt, va_list args) |
| 7218 |
{ |
| 7219 |
int result = -1; |
| 7220 |
NK_ASSERT(buf); |
| 7221 |
NK_ASSERT(buf_size); |
| 7222 |
if (!buf || !buf_size || !fmt) return 0; |
| 7223 |
#ifdef NK_INCLUDE_STANDARD_IO |
| 7224 |
result = NK_VSNPRINTF(buf, (nk_size)buf_size, fmt, args); |
| 7225 |
result = (result >= buf_size) ? -1: result; |
| 7226 |
buf[buf_size-1] = 0; |
| 7227 |
#else |
| 7228 |
result = nk_vsnprintf(buf, buf_size, fmt, args); |
| 7229 |
#endif |
| 7230 |
return result; |
| 7231 |
} |
| 7232 |
#endif |
| 7233 |
NK_API nk_hash |
| 7234 |
nk_murmur_hash(const void * key, int len, nk_hash seed) |
| 7235 |
{ |
| 7236 |
|
| 7237 |
#define NK_ROTL(x,r) ((x) << (r) | ((x) >> (32 - r))) |
| 7238 |
|
| 7239 |
nk_uint h1 = seed; |
| 7240 |
nk_uint k1; |
| 7241 |
const nk_byte *data = (const nk_byte*)key; |
| 7242 |
const nk_byte *keyptr = data; |
| 7243 |
nk_byte *k1ptr; |
| 7244 |
const int bsize = sizeof(k1); |
| 7245 |
const int nblocks = len/4; |
| 7246 |
|
| 7247 |
const nk_uint c1 = 0xcc9e2d51; |
| 7248 |
const nk_uint c2 = 0x1b873593; |
| 7249 |
const nk_byte *tail; |
| 7250 |
int i; |
| 7251 |
|
| 7252 |
|
| 7253 |
if (!key) return 0; |
| 7254 |
for (i = 0; i < nblocks; ++i, keyptr += bsize) { |
| 7255 |
k1ptr = (nk_byte*)&k1; |
| 7256 |
k1ptr[0] = keyptr[0]; |
| 7257 |
k1ptr[1] = keyptr[1]; |
| 7258 |
k1ptr[2] = keyptr[2]; |
| 7259 |
k1ptr[3] = keyptr[3]; |
| 7260 |
|
| 7261 |
k1 *= c1; |
| 7262 |
k1 = NK_ROTL(k1,15); |
| 7263 |
k1 *= c2; |
| 7264 |
|
| 7265 |
h1 ^= k1; |
| 7266 |
h1 = NK_ROTL(h1,13); |
| 7267 |
h1 = h1*5+0xe6546b64; |
| 7268 |
} |
| 7269 |
|
| 7270 |
|
| 7271 |
tail = (const nk_byte*)(data + nblocks*4); |
| 7272 |
k1 = 0; |
| 7273 |
switch (len & 3) { |
| 7274 |
case 3: k1 ^= (nk_uint)(tail[2] << 16); |
| 7275 |
case 2: k1 ^= (nk_uint)(tail[1] << 8u); |
| 7276 |
case 1: k1 ^= tail[0]; |
| 7277 |
k1 *= c1; |
| 7278 |
k1 = NK_ROTL(k1,15); |
| 7279 |
k1 *= c2; |
| 7280 |
h1 ^= k1; |
| 7281 |
break; |
| 7282 |
default: break; |
| 7283 |
} |
| 7284 |
|
| 7285 |
|
| 7286 |
h1 ^= (nk_uint)len; |
| 7287 |
|
| 7288 |
h1 ^= h1 >> 16; |
| 7289 |
h1 *= 0x85ebca6b; |
| 7290 |
h1 ^= h1 >> 13; |
| 7291 |
h1 *= 0xc2b2ae35; |
| 7292 |
h1 ^= h1 >> 16; |
| 7293 |
|
| 7294 |
#undef NK_ROTL |
| 7295 |
return h1; |
| 7296 |
} |
| 7297 |
#ifdef NK_INCLUDE_STANDARD_IO |
| 7298 |
NK_LIB char* |
| 7299 |
nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc) |
| 7300 |
{ |
| 7301 |
char *buf; |
| 7302 |
FILE *fd; |
| 7303 |
long ret; |
| 7304 |
|
| 7305 |
NK_ASSERT(path); |
| 7306 |
NK_ASSERT(siz); |
| 7307 |
NK_ASSERT(alloc); |
| 7308 |
if (!path || !siz || !alloc) |
| 7309 |
return 0; |
| 7310 |
|
| 7311 |
fd = fopen(path, "rb"); |
| 7312 |
if (!fd) return 0; |
| 7313 |
fseek(fd, 0, SEEK_END); |
| 7314 |
ret = ftell(fd); |
| 7315 |
if (ret < 0) { |
| 7316 |
fclose(fd); |
| 7317 |
return 0; |
| 7318 |
} |
| 7319 |
*siz = (nk_size)ret; |
| 7320 |
fseek(fd, 0, SEEK_SET); |
| 7321 |
buf = (char*)alloc->alloc(alloc->userdata,0, *siz); |
| 7322 |
NK_ASSERT(buf); |
| 7323 |
if (!buf) { |
| 7324 |
fclose(fd); |
| 7325 |
return 0; |
| 7326 |
} |
| 7327 |
*siz = (nk_size)fread(buf, 1,*siz, fd); |
| 7328 |
fclose(fd); |
| 7329 |
return buf; |
| 7330 |
} |
| 7331 |
#endif |
| 7332 |
NK_LIB int |
| 7333 |
nk_text_clamp(const struct nk_user_font *font, const char *text, |
| 7334 |
int text_len, float space, int *glyphs, float *text_width, |
| 7335 |
nk_rune *sep_list, int sep_count) |
| 7336 |
{ |
| 7337 |
int i = 0; |
| 7338 |
int glyph_len = 0; |
| 7339 |
float last_width = 0; |
| 7340 |
nk_rune unicode = 0; |
| 7341 |
float width = 0; |
| 7342 |
int len = 0; |
| 7343 |
int g = 0; |
| 7344 |
float s; |
| 7345 |
|
| 7346 |
int sep_len = 0; |
| 7347 |
int sep_g = 0; |
| 7348 |
float sep_width = 0; |
| 7349 |
sep_count = NK_MAX(sep_count,0); |
| 7350 |
|
| 7351 |
glyph_len = nk_utf_decode(text, &unicode, text_len); |
| 7352 |
while (glyph_len && (width < space) && (len < text_len)) { |
| 7353 |
len += glyph_len; |
| 7354 |
s = font->width(font->userdata, font->height, text, len); |
| 7355 |
for (i = 0; i < sep_count; ++i) { |
| 7356 |
if (unicode != sep_list[i]) continue; |
| 7357 |
sep_width = last_width = width; |
| 7358 |
sep_g = g+1; |
| 7359 |
sep_len = len; |
| 7360 |
break; |
| 7361 |
} |
| 7362 |
if (i == sep_count){ |
| 7363 |
last_width = sep_width = width; |
| 7364 |
sep_g = g+1; |
| 7365 |
} |
| 7366 |
width = s; |
| 7367 |
glyph_len = nk_utf_decode(&text[len], &unicode, text_len - len); |
| 7368 |
g++; |
| 7369 |
} |
| 7370 |
if (len >= text_len) { |
| 7371 |
*glyphs = g; |
| 7372 |
*text_width = last_width; |
| 7373 |
return len; |
| 7374 |
} else { |
| 7375 |
*glyphs = sep_g; |
| 7376 |
*text_width = sep_width; |
| 7377 |
return (!sep_len) ? len: sep_len; |
| 7378 |
} |
| 7379 |
} |
| 7380 |
NK_LIB struct nk_vec2 |
| 7381 |
nk_text_calculate_text_bounds(const struct nk_user_font *font, |
| 7382 |
const char *begin, int byte_len, float row_height, const char **remaining, |
| 7383 |
struct nk_vec2 *out_offset, int *glyphs, int op) |
| 7384 |
{ |
| 7385 |
float line_height = row_height; |
| 7386 |
struct nk_vec2 text_size = nk_vec2(0,0); |
| 7387 |
float line_width = 0.0f; |
| 7388 |
|
| 7389 |
float glyph_width; |
| 7390 |
int glyph_len = 0; |
| 7391 |
nk_rune unicode = 0; |
| 7392 |
int text_len = 0; |
| 7393 |
if (!begin || byte_len <= 0 || !font) |
| 7394 |
return nk_vec2(0,row_height); |
| 7395 |
|
| 7396 |
glyph_len = nk_utf_decode(begin, &unicode, byte_len); |
| 7397 |
if (!glyph_len) return text_size; |
| 7398 |
glyph_width = font->width(font->userdata, font->height, begin, glyph_len); |
| 7399 |
|
| 7400 |
*glyphs = 0; |
| 7401 |
while ((text_len < byte_len) && glyph_len) { |
| 7402 |
if (unicode == '\n') { |
| 7403 |
text_size.x = NK_MAX(text_size.x, line_width); |
| 7404 |
text_size.y += line_height; |
| 7405 |
line_width = 0; |
| 7406 |
*glyphs+=1; |
| 7407 |
if (op == NK_STOP_ON_NEW_LINE) |
| 7408 |
break; |
| 7409 |
|
| 7410 |
text_len++; |
| 7411 |
glyph_len = nk_utf_decode(begin + text_len, &unicode, byte_len-text_len); |
| 7412 |
continue; |
| 7413 |
} |
| 7414 |
|
| 7415 |
if (unicode == '\r') { |
| 7416 |
text_len++; |
| 7417 |
*glyphs+=1; |
| 7418 |
glyph_len = nk_utf_decode(begin + text_len, &unicode, byte_len-text_len); |
| 7419 |
continue; |
| 7420 |
} |
| 7421 |
|
| 7422 |
*glyphs = *glyphs + 1; |
| 7423 |
text_len += glyph_len; |
| 7424 |
line_width += (float)glyph_width; |
| 7425 |
glyph_len = nk_utf_decode(begin + text_len, &unicode, byte_len-text_len); |
| 7426 |
glyph_width = font->width(font->userdata, font->height, begin+text_len, glyph_len); |
| 7427 |
continue; |
| 7428 |
} |
| 7429 |
|
| 7430 |
if (text_size.x < line_width) |
| 7431 |
text_size.x = line_width; |
| 7432 |
if (out_offset) |
| 7433 |
*out_offset = nk_vec2(line_width, text_size.y + line_height); |
| 7434 |
if (line_width > 0 || text_size.y == 0.0f) |
| 7435 |
text_size.y += line_height; |
| 7436 |
if (remaining) |
| 7437 |
*remaining = begin+text_len; |
| 7438 |
return text_size; |
| 7439 |
} |
| 7440 |
|
| 7441 |
|
| 7442 |
|
| 7443 |
|
| 7444 |
|
| 7445 |
|
| 7446 |
|
| 7447 |
|
| 7448 |
|
| 7449 |
|
| 7450 |
NK_INTERN int |
| 7451 |
nk_parse_hex(const char *p, int length) |
| 7452 |
{ |
| 7453 |
int i = 0; |
| 7454 |
int len = 0; |
| 7455 |
while (len < length) { |
| 7456 |
i <<= 4; |
| 7457 |
if (p[len] >= 'a' && p[len] <= 'f') |
| 7458 |
i += ((p[len] - 'a') + 10); |
| 7459 |
else if (p[len] >= 'A' && p[len] <= 'F') |
| 7460 |
i += ((p[len] - 'A') + 10); |
| 7461 |
else i += (p[len] - '0'); |
| 7462 |
len++; |
| 7463 |
} |
| 7464 |
return i; |
| 7465 |
} |
| 7466 |
NK_API struct nk_color |
| 7467 |
nk_rgba(int r, int g, int b, int a) |
| 7468 |
{ |
| 7469 |
struct nk_color ret; |
| 7470 |
ret.r = (nk_byte)NK_CLAMP(0, r, 255); |
| 7471 |
ret.g = (nk_byte)NK_CLAMP(0, g, 255); |
| 7472 |
ret.b = (nk_byte)NK_CLAMP(0, b, 255); |
| 7473 |
ret.a = (nk_byte)NK_CLAMP(0, a, 255); |
| 7474 |
return ret; |
| 7475 |
} |
| 7476 |
NK_API struct nk_color |
| 7477 |
nk_rgb_hex(const char *rgb) |
| 7478 |
{ |
| 7479 |
struct nk_color col; |
| 7480 |
const char *c = rgb; |
| 7481 |
if (*c == '#') c++; |
| 7482 |
col.r = (nk_byte)nk_parse_hex(c, 2); |
| 7483 |
col.g = (nk_byte)nk_parse_hex(c+2, 2); |
| 7484 |
col.b = (nk_byte)nk_parse_hex(c+4, 2); |
| 7485 |
col.a = 255; |
| 7486 |
return col; |
| 7487 |
} |
| 7488 |
NK_API struct nk_color |
| 7489 |
nk_rgba_hex(const char *rgb) |
| 7490 |
{ |
| 7491 |
struct nk_color col; |
| 7492 |
const char *c = rgb; |
| 7493 |
if (*c == '#') c++; |
| 7494 |
col.r = (nk_byte)nk_parse_hex(c, 2); |
| 7495 |
col.g = (nk_byte)nk_parse_hex(c+2, 2); |
| 7496 |
col.b = (nk_byte)nk_parse_hex(c+4, 2); |
| 7497 |
col.a = (nk_byte)nk_parse_hex(c+6, 2); |
| 7498 |
return col; |
| 7499 |
} |
| 7500 |
NK_API void |
| 7501 |
nk_color_hex_rgba(char *output, struct nk_color col) |
| 7502 |
{ |
| 7503 |
#define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i)) |
| 7504 |
output[0] = (char)NK_TO_HEX((col.r & 0xF0) >> 4); |
| 7505 |
output[1] = (char)NK_TO_HEX((col.r & 0x0F)); |
| 7506 |
output[2] = (char)NK_TO_HEX((col.g & 0xF0) >> 4); |
| 7507 |
output[3] = (char)NK_TO_HEX((col.g & 0x0F)); |
| 7508 |
output[4] = (char)NK_TO_HEX((col.b & 0xF0) >> 4); |
| 7509 |
output[5] = (char)NK_TO_HEX((col.b & 0x0F)); |
| 7510 |
output[6] = (char)NK_TO_HEX((col.a & 0xF0) >> 4); |
| 7511 |
output[7] = (char)NK_TO_HEX((col.a & 0x0F)); |
| 7512 |
output[8] = '\0'; |
| 7513 |
#undef NK_TO_HEX |
| 7514 |
} |
| 7515 |
NK_API void |
| 7516 |
nk_color_hex_rgb(char *output, struct nk_color col) |
| 7517 |
{ |
| 7518 |
#define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i)) |
| 7519 |
output[0] = (char)NK_TO_HEX((col.r & 0xF0) >> 4); |
| 7520 |
output[1] = (char)NK_TO_HEX((col.r & 0x0F)); |
| 7521 |
output[2] = (char)NK_TO_HEX((col.g & 0xF0) >> 4); |
| 7522 |
output[3] = (char)NK_TO_HEX((col.g & 0x0F)); |
| 7523 |
output[4] = (char)NK_TO_HEX((col.b & 0xF0) >> 4); |
| 7524 |
output[5] = (char)NK_TO_HEX((col.b & 0x0F)); |
| 7525 |
output[6] = '\0'; |
| 7526 |
#undef NK_TO_HEX |
| 7527 |
} |
| 7528 |
NK_API struct nk_color |
| 7529 |
nk_rgba_iv(const int *c) |
| 7530 |
{ |
| 7531 |
return nk_rgba(c[0], c[1], c[2], c[3]); |
| 7532 |
} |
| 7533 |
NK_API struct nk_color |
| 7534 |
nk_rgba_bv(const nk_byte *c) |
| 7535 |
{ |
| 7536 |
return nk_rgba(c[0], c[1], c[2], c[3]); |
| 7537 |
} |
| 7538 |
NK_API struct nk_color |
| 7539 |
nk_rgb(int r, int g, int b) |
| 7540 |
{ |
| 7541 |
struct nk_color ret; |
| 7542 |
ret.r = (nk_byte)NK_CLAMP(0, r, 255); |
| 7543 |
ret.g = (nk_byte)NK_CLAMP(0, g, 255); |
| 7544 |
ret.b = (nk_byte)NK_CLAMP(0, b, 255); |
| 7545 |
ret.a = (nk_byte)255; |
| 7546 |
return ret; |
| 7547 |
} |
| 7548 |
NK_API struct nk_color |
| 7549 |
nk_rgb_iv(const int *c) |
| 7550 |
{ |
| 7551 |
return nk_rgb(c[0], c[1], c[2]); |
| 7552 |
} |
| 7553 |
NK_API struct nk_color |
| 7554 |
nk_rgb_bv(const nk_byte* c) |
| 7555 |
{ |
| 7556 |
return nk_rgb(c[0], c[1], c[2]); |
| 7557 |
} |
| 7558 |
NK_API struct nk_color |
| 7559 |
nk_rgba_u32(nk_uint in) |
| 7560 |
{ |
| 7561 |
struct nk_color ret; |
| 7562 |
ret.r = (in & 0xFF); |
| 7563 |
ret.g = ((in >> 8) & 0xFF); |
| 7564 |
ret.b = ((in >> 16) & 0xFF); |
| 7565 |
ret.a = (nk_byte)((in >> 24) & 0xFF); |
| 7566 |
return ret; |
| 7567 |
} |
| 7568 |
NK_API struct nk_color |
| 7569 |
nk_rgba_f(float r, float g, float b, float a) |
| 7570 |
{ |
| 7571 |
struct nk_color ret; |
| 7572 |
ret.r = (nk_byte)(NK_SATURATE(r) * 255.0f); |
| 7573 |
ret.g = (nk_byte)(NK_SATURATE(g) * 255.0f); |
| 7574 |
ret.b = (nk_byte)(NK_SATURATE(b) * 255.0f); |
| 7575 |
ret.a = (nk_byte)(NK_SATURATE(a) * 255.0f); |
| 7576 |
return ret; |
| 7577 |
} |
| 7578 |
NK_API struct nk_color |
| 7579 |
nk_rgba_fv(const float *c) |
| 7580 |
{ |
| 7581 |
return nk_rgba_f(c[0], c[1], c[2], c[3]); |
| 7582 |
} |
| 7583 |
NK_API struct nk_color |
| 7584 |
nk_rgba_cf(struct nk_colorf c) |
| 7585 |
{ |
| 7586 |
return nk_rgba_f(c.r, c.g, c.b, c.a); |
| 7587 |
} |
| 7588 |
NK_API struct nk_color |
| 7589 |
nk_rgb_f(float r, float g, float b) |
| 7590 |
{ |
| 7591 |
struct nk_color ret; |
| 7592 |
ret.r = (nk_byte)(NK_SATURATE(r) * 255.0f); |
| 7593 |
ret.g = (nk_byte)(NK_SATURATE(g) * 255.0f); |
| 7594 |
ret.b = (nk_byte)(NK_SATURATE(b) * 255.0f); |
| 7595 |
ret.a = 255; |
| 7596 |
return ret; |
| 7597 |
} |
| 7598 |
NK_API struct nk_color |
| 7599 |
nk_rgb_fv(const float *c) |
| 7600 |
{ |
| 7601 |
return nk_rgb_f(c[0], c[1], c[2]); |
| 7602 |
} |
| 7603 |
NK_API struct nk_color |
| 7604 |
nk_rgb_cf(struct nk_colorf c) |
| 7605 |
{ |
| 7606 |
return nk_rgb_f(c.r, c.g, c.b); |
| 7607 |
} |
| 7608 |
NK_API struct nk_color |
| 7609 |
nk_hsv(int h, int s, int v) |
| 7610 |
{ |
| 7611 |
return nk_hsva(h, s, v, 255); |
| 7612 |
} |
| 7613 |
NK_API struct nk_color |
| 7614 |
nk_hsv_iv(const int *c) |
| 7615 |
{ |
| 7616 |
return nk_hsv(c[0], c[1], c[2]); |
| 7617 |
} |
| 7618 |
NK_API struct nk_color |
| 7619 |
nk_hsv_bv(const nk_byte *c) |
| 7620 |
{ |
| 7621 |
return nk_hsv(c[0], c[1], c[2]); |
| 7622 |
} |
| 7623 |
NK_API struct nk_color |
| 7624 |
nk_hsv_f(float h, float s, float v) |
| 7625 |
{ |
| 7626 |
return nk_hsva_f(h, s, v, 1.0f); |
| 7627 |
} |
| 7628 |
NK_API struct nk_color |
| 7629 |
nk_hsv_fv(const float *c) |
| 7630 |
{ |
| 7631 |
return nk_hsv_f(c[0], c[1], c[2]); |
| 7632 |
} |
| 7633 |
NK_API struct nk_color |
| 7634 |
nk_hsva(int h, int s, int v, int a) |
| 7635 |
{ |
| 7636 |
float hf = ((float)NK_CLAMP(0, h, 255)) / 255.0f; |
| 7637 |
float sf = ((float)NK_CLAMP(0, s, 255)) / 255.0f; |
| 7638 |
float vf = ((float)NK_CLAMP(0, v, 255)) / 255.0f; |
| 7639 |
float af = ((float)NK_CLAMP(0, a, 255)) / 255.0f; |
| 7640 |
return nk_hsva_f(hf, sf, vf, af); |
| 7641 |
} |
| 7642 |
NK_API struct nk_color |
| 7643 |
nk_hsva_iv(const int *c) |
| 7644 |
{ |
| 7645 |
return nk_hsva(c[0], c[1], c[2], c[3]); |
| 7646 |
} |
| 7647 |
NK_API struct nk_color |
| 7648 |
nk_hsva_bv(const nk_byte *c) |
| 7649 |
{ |
| 7650 |
return nk_hsva(c[0], c[1], c[2], c[3]); |
| 7651 |
} |
| 7652 |
NK_API struct nk_colorf |
| 7653 |
nk_hsva_colorf(float h, float s, float v, float a) |
| 7654 |
{ |
| 7655 |
int i; |
| 7656 |
float p, q, t, f; |
| 7657 |
struct nk_colorf out = {0,0,0,0}; |
| 7658 |
if (s <= 0.0f) { |
| 7659 |
out.r = v; out.g = v; out.b = v; out.a = a; |
| 7660 |
return out; |
| 7661 |
} |
| 7662 |
h = h / (60.0f/360.0f); |
| 7663 |
i = (int)h; |
| 7664 |
f = h - (float)i; |
| 7665 |
p = v * (1.0f - s); |
| 7666 |
q = v * (1.0f - (s * f)); |
| 7667 |
t = v * (1.0f - s * (1.0f - f)); |
| 7668 |
|
| 7669 |
switch (i) { |
| 7670 |
case 0: default: out.r = v; out.g = t; out.b = p; break; |
| 7671 |
case 1: out.r = q; out.g = v; out.b = p; break; |
| 7672 |
case 2: out.r = p; out.g = v; out.b = t; break; |
| 7673 |
case 3: out.r = p; out.g = q; out.b = v; break; |
| 7674 |
case 4: out.r = t; out.g = p; out.b = v; break; |
| 7675 |
case 5: out.r = v; out.g = p; out.b = q; break;} |
| 7676 |
out.a = a; |
| 7677 |
return out; |
| 7678 |
} |
| 7679 |
NK_API struct nk_colorf |
| 7680 |
nk_hsva_colorfv(float *c) |
| 7681 |
{ |
| 7682 |
return nk_hsva_colorf(c[0], c[1], c[2], c[3]); |
| 7683 |
} |
| 7684 |
NK_API struct nk_color |
| 7685 |
nk_hsva_f(float h, float s, float v, float a) |
| 7686 |
{ |
| 7687 |
struct nk_colorf c = nk_hsva_colorf(h, s, v, a); |
| 7688 |
return nk_rgba_f(c.r, c.g, c.b, c.a); |
| 7689 |
} |
| 7690 |
NK_API struct nk_color |
| 7691 |
nk_hsva_fv(const float *c) |
| 7692 |
{ |
| 7693 |
return nk_hsva_f(c[0], c[1], c[2], c[3]); |
| 7694 |
} |
| 7695 |
NK_API nk_uint |
| 7696 |
nk_color_u32(struct nk_color in) |
| 7697 |
{ |
| 7698 |
nk_uint out = (nk_uint)in.r; |
| 7699 |
out |= ((nk_uint)in.g << 8); |
| 7700 |
out |= ((nk_uint)in.b << 16); |
| 7701 |
out |= ((nk_uint)in.a << 24); |
| 7702 |
return out; |
| 7703 |
} |
| 7704 |
NK_API void |
| 7705 |
nk_color_f(float *r, float *g, float *b, float *a, struct nk_color in) |
| 7706 |
{ |
| 7707 |
NK_STORAGE const float s = 1.0f/255.0f; |
| 7708 |
*r = (float)in.r * s; |
| 7709 |
*g = (float)in.g * s; |
| 7710 |
*b = (float)in.b * s; |
| 7711 |
*a = (float)in.a * s; |
| 7712 |
} |
| 7713 |
NK_API void |
| 7714 |
nk_color_fv(float *c, struct nk_color in) |
| 7715 |
{ |
| 7716 |
nk_color_f(&c[0], &c[1], &c[2], &c[3], in); |
| 7717 |
} |
| 7718 |
NK_API struct nk_colorf |
| 7719 |
nk_color_cf(struct nk_color in) |
| 7720 |
{ |
| 7721 |
struct nk_colorf o; |
| 7722 |
nk_color_f(&o.r, &o.g, &o.b, &o.a, in); |
| 7723 |
return o; |
| 7724 |
} |
| 7725 |
NK_API void |
| 7726 |
nk_color_d(double *r, double *g, double *b, double *a, struct nk_color in) |
| 7727 |
{ |
| 7728 |
NK_STORAGE const double s = 1.0/255.0; |
| 7729 |
*r = (double)in.r * s; |
| 7730 |
*g = (double)in.g * s; |
| 7731 |
*b = (double)in.b * s; |
| 7732 |
*a = (double)in.a * s; |
| 7733 |
} |
| 7734 |
NK_API void |
| 7735 |
nk_color_dv(double *c, struct nk_color in) |
| 7736 |
{ |
| 7737 |
nk_color_d(&c[0], &c[1], &c[2], &c[3], in); |
| 7738 |
} |
| 7739 |
NK_API void |
| 7740 |
nk_color_hsv_f(float *out_h, float *out_s, float *out_v, struct nk_color in) |
| 7741 |
{ |
| 7742 |
float a; |
| 7743 |
nk_color_hsva_f(out_h, out_s, out_v, &a, in); |
| 7744 |
} |
| 7745 |
NK_API void |
| 7746 |
nk_color_hsv_fv(float *out, struct nk_color in) |
| 7747 |
{ |
| 7748 |
float a; |
| 7749 |
nk_color_hsva_f(&out[0], &out[1], &out[2], &a, in); |
| 7750 |
} |
| 7751 |
NK_API void |
| 7752 |
nk_colorf_hsva_f(float *out_h, float *out_s, |
| 7753 |
float *out_v, float *out_a, struct nk_colorf in) |
| 7754 |
{ |
| 7755 |
float chroma; |
| 7756 |
float K = 0.0f; |
| 7757 |
if (in.g < in.b) { |
| 7758 |
const float t = in.g; in.g = in.b; in.b = t; |
| 7759 |
K = -1.f; |
| 7760 |
} |
| 7761 |
if (in.r < in.g) { |
| 7762 |
const float t = in.r; in.r = in.g; in.g = t; |
| 7763 |
K = -2.f/6.0f - K; |
| 7764 |
} |
| 7765 |
chroma = in.r - ((in.g < in.b) ? in.g: in.b); |
| 7766 |
*out_h = NK_ABS(K + (in.g - in.b)/(6.0f * chroma + 1e-20f)); |
| 7767 |
*out_s = chroma / (in.r + 1e-20f); |
| 7768 |
*out_v = in.r; |
| 7769 |
*out_a = in.a; |
| 7770 |
|
| 7771 |
} |
| 7772 |
NK_API void |
| 7773 |
nk_colorf_hsva_fv(float *hsva, struct nk_colorf in) |
| 7774 |
{ |
| 7775 |
nk_colorf_hsva_f(&hsva[0], &hsva[1], &hsva[2], &hsva[3], in); |
| 7776 |
} |
| 7777 |
NK_API void |
| 7778 |
nk_color_hsva_f(float *out_h, float *out_s, |
| 7779 |
float *out_v, float *out_a, struct nk_color in) |
| 7780 |
{ |
| 7781 |
struct nk_colorf col; |
| 7782 |
nk_color_f(&col.r,&col.g,&col.b,&col.a, in); |
| 7783 |
nk_colorf_hsva_f(out_h, out_s, out_v, out_a, col); |
| 7784 |
} |
| 7785 |
NK_API void |
| 7786 |
nk_color_hsva_fv(float *out, struct nk_color in) |
| 7787 |
{ |
| 7788 |
nk_color_hsva_f(&out[0], &out[1], &out[2], &out[3], in); |
| 7789 |
} |
| 7790 |
NK_API void |
| 7791 |
nk_color_hsva_i(int *out_h, int *out_s, int *out_v, |
| 7792 |
int *out_a, struct nk_color in) |
| 7793 |
{ |
| 7794 |
float h,s,v,a; |
| 7795 |
nk_color_hsva_f(&h, &s, &v, &a, in); |
| 7796 |
*out_h = (nk_byte)(h * 255.0f); |
| 7797 |
*out_s = (nk_byte)(s * 255.0f); |
| 7798 |
*out_v = (nk_byte)(v * 255.0f); |
| 7799 |
*out_a = (nk_byte)(a * 255.0f); |
| 7800 |
} |
| 7801 |
NK_API void |
| 7802 |
nk_color_hsva_iv(int *out, struct nk_color in) |
| 7803 |
{ |
| 7804 |
nk_color_hsva_i(&out[0], &out[1], &out[2], &out[3], in); |
| 7805 |
} |
| 7806 |
NK_API void |
| 7807 |
nk_color_hsva_bv(nk_byte *out, struct nk_color in) |
| 7808 |
{ |
| 7809 |
int tmp[4]; |
| 7810 |
nk_color_hsva_i(&tmp[0], &tmp[1], &tmp[2], &tmp[3], in); |
| 7811 |
out[0] = (nk_byte)tmp[0]; |
| 7812 |
out[1] = (nk_byte)tmp[1]; |
| 7813 |
out[2] = (nk_byte)tmp[2]; |
| 7814 |
out[3] = (nk_byte)tmp[3]; |
| 7815 |
} |
| 7816 |
NK_API void |
| 7817 |
nk_color_hsva_b(nk_byte *h, nk_byte *s, nk_byte *v, nk_byte *a, struct nk_color in) |
| 7818 |
{ |
| 7819 |
int tmp[4]; |
| 7820 |
nk_color_hsva_i(&tmp[0], &tmp[1], &tmp[2], &tmp[3], in); |
| 7821 |
*h = (nk_byte)tmp[0]; |
| 7822 |
*s = (nk_byte)tmp[1]; |
| 7823 |
*v = (nk_byte)tmp[2]; |
| 7824 |
*a = (nk_byte)tmp[3]; |
| 7825 |
} |
| 7826 |
NK_API void |
| 7827 |
nk_color_hsv_i(int *out_h, int *out_s, int *out_v, struct nk_color in) |
| 7828 |
{ |
| 7829 |
int a; |
| 7830 |
nk_color_hsva_i(out_h, out_s, out_v, &a, in); |
| 7831 |
} |
| 7832 |
NK_API void |
| 7833 |
nk_color_hsv_b(nk_byte *out_h, nk_byte *out_s, nk_byte *out_v, struct nk_color in) |
| 7834 |
{ |
| 7835 |
int tmp[4]; |
| 7836 |
nk_color_hsva_i(&tmp[0], &tmp[1], &tmp[2], &tmp[3], in); |
| 7837 |
*out_h = (nk_byte)tmp[0]; |
| 7838 |
*out_s = (nk_byte)tmp[1]; |
| 7839 |
*out_v = (nk_byte)tmp[2]; |
| 7840 |
} |
| 7841 |
NK_API void |
| 7842 |
nk_color_hsv_iv(int *out, struct nk_color in) |
| 7843 |
{ |
| 7844 |
nk_color_hsv_i(&out[0], &out[1], &out[2], in); |
| 7845 |
} |
| 7846 |
NK_API void |
| 7847 |
nk_color_hsv_bv(nk_byte *out, struct nk_color in) |
| 7848 |
{ |
| 7849 |
int tmp[4]; |
| 7850 |
nk_color_hsv_i(&tmp[0], &tmp[1], &tmp[2], in); |
| 7851 |
out[0] = (nk_byte)tmp[0]; |
| 7852 |
out[1] = (nk_byte)tmp[1]; |
| 7853 |
out[2] = (nk_byte)tmp[2]; |
| 7854 |
} |
| 7855 |
|
| 7856 |
|
| 7857 |
|
| 7858 |
|
| 7859 |
|
| 7860 |
|
| 7861 |
|
| 7862 |
|
| 7863 |
|
| 7864 |
|
| 7865 |
NK_GLOBAL const nk_byte nk_utfbyte[NK_UTF_SIZE+1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; |
| 7866 |
NK_GLOBAL const nk_byte nk_utfmask[NK_UTF_SIZE+1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; |
| 7867 |
NK_GLOBAL const nk_uint nk_utfmin[NK_UTF_SIZE+1] = {0, 0, 0x80, 0x800, 0x10000}; |
| 7868 |
NK_GLOBAL const nk_uint nk_utfmax[NK_UTF_SIZE+1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; |
| 7869 |
|
| 7870 |
NK_INTERN int |
| 7871 |
nk_utf_validate(nk_rune *u, int i) |
| 7872 |
{ |
| 7873 |
NK_ASSERT(u); |
| 7874 |
if (!u) return 0; |
| 7875 |
if (!NK_BETWEEN(*u, nk_utfmin[i], nk_utfmax[i]) || |
| 7876 |
NK_BETWEEN(*u, 0xD800, 0xDFFF)) |
| 7877 |
*u = NK_UTF_INVALID; |
| 7878 |
for (i = 1; *u > nk_utfmax[i]; ++i); |
| 7879 |
return i; |
| 7880 |
} |
| 7881 |
NK_INTERN nk_rune |
| 7882 |
nk_utf_decode_byte(char c, int *i) |
| 7883 |
{ |
| 7884 |
NK_ASSERT(i); |
| 7885 |
if (!i) return 0; |
| 7886 |
for(*i = 0; *i < (int)NK_LEN(nk_utfmask); ++(*i)) { |
| 7887 |
if (((nk_byte)c & nk_utfmask[*i]) == nk_utfbyte[*i]) |
| 7888 |
return (nk_byte)(c & ~nk_utfmask[*i]); |
| 7889 |
} |
| 7890 |
return 0; |
| 7891 |
} |
| 7892 |
NK_API int |
| 7893 |
nk_utf_decode(const char *c, nk_rune *u, int clen) |
| 7894 |
{ |
| 7895 |
int i, j, len, type=0; |
| 7896 |
nk_rune udecoded; |
| 7897 |
|
| 7898 |
NK_ASSERT(c); |
| 7899 |
NK_ASSERT(u); |
| 7900 |
|
| 7901 |
if (!c || !u) return 0; |
| 7902 |
if (!clen) return 0; |
| 7903 |
*u = NK_UTF_INVALID; |
| 7904 |
|
| 7905 |
udecoded = nk_utf_decode_byte(c[0], &len); |
| 7906 |
if (!NK_BETWEEN(len, 1, NK_UTF_SIZE)) |
| 7907 |
return 1; |
| 7908 |
|
| 7909 |
for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { |
| 7910 |
udecoded = (udecoded << 6) | nk_utf_decode_byte(c[i], &type); |
| 7911 |
if (type != 0) |
| 7912 |
return j; |
| 7913 |
} |
| 7914 |
if (j < len) |
| 7915 |
return 0; |
| 7916 |
*u = udecoded; |
| 7917 |
nk_utf_validate(u, len); |
| 7918 |
return len; |
| 7919 |
} |
| 7920 |
NK_INTERN char |
| 7921 |
nk_utf_encode_byte(nk_rune u, int i) |
| 7922 |
{ |
| 7923 |
return (char)((nk_utfbyte[i]) | ((nk_byte)u & ~nk_utfmask[i])); |
| 7924 |
} |
| 7925 |
NK_API int |
| 7926 |
nk_utf_encode(nk_rune u, char *c, int clen) |
| 7927 |
{ |
| 7928 |
int len, i; |
| 7929 |
len = nk_utf_validate(&u, 0); |
| 7930 |
if (clen < len || !len || len > NK_UTF_SIZE) |
| 7931 |
return 0; |
| 7932 |
|
| 7933 |
for (i = len - 1; i != 0; --i) { |
| 7934 |
c[i] = nk_utf_encode_byte(u, 0); |
| 7935 |
u >>= 6; |
| 7936 |
} |
| 7937 |
c[0] = nk_utf_encode_byte(u, len); |
| 7938 |
return len; |
| 7939 |
} |
| 7940 |
NK_API int |
| 7941 |
nk_utf_len(const char *str, int len) |
| 7942 |
{ |
| 7943 |
const char *text; |
| 7944 |
int glyphs = 0; |
| 7945 |
int text_len; |
| 7946 |
int glyph_len; |
| 7947 |
int src_len = 0; |
| 7948 |
nk_rune unicode; |
| 7949 |
|
| 7950 |
NK_ASSERT(str); |
| 7951 |
if (!str || !len) return 0; |
| 7952 |
|
| 7953 |
text = str; |
| 7954 |
text_len = len; |
| 7955 |
glyph_len = nk_utf_decode(text, &unicode, text_len); |
| 7956 |
while (glyph_len && src_len < len) { |
| 7957 |
glyphs++; |
| 7958 |
src_len = src_len + glyph_len; |
| 7959 |
glyph_len = nk_utf_decode(text + src_len, &unicode, text_len - src_len); |
| 7960 |
} |
| 7961 |
return glyphs; |
| 7962 |
} |
| 7963 |
NK_API const char* |
| 7964 |
nk_utf_at(const char *buffer, int length, int index, |
| 7965 |
nk_rune *unicode, int *len) |
| 7966 |
{ |
| 7967 |
int i = 0; |
| 7968 |
int src_len = 0; |
| 7969 |
int glyph_len = 0; |
| 7970 |
const char *text; |
| 7971 |
int text_len; |
| 7972 |
|
| 7973 |
NK_ASSERT(buffer); |
| 7974 |
NK_ASSERT(unicode); |
| 7975 |
NK_ASSERT(len); |
| 7976 |
|
| 7977 |
if (!buffer || !unicode || !len) return 0; |
| 7978 |
if (index < 0) { |
| 7979 |
*unicode = NK_UTF_INVALID; |
| 7980 |
*len = 0; |
| 7981 |
return 0; |
| 7982 |
} |
| 7983 |
|
| 7984 |
text = buffer; |
| 7985 |
text_len = length; |
| 7986 |
glyph_len = nk_utf_decode(text, unicode, text_len); |
| 7987 |
while (glyph_len) { |
| 7988 |
if (i == index) { |
| 7989 |
*len = glyph_len; |
| 7990 |
break; |
| 7991 |
} |
| 7992 |
|
| 7993 |
i++; |
| 7994 |
src_len = src_len + glyph_len; |
| 7995 |
glyph_len = nk_utf_decode(text + src_len, unicode, text_len - src_len); |
| 7996 |
} |
| 7997 |
if (i != index) return 0; |
| 7998 |
return buffer + src_len; |
| 7999 |
} |
| 8000 |
|
| 8001 |
|
| 8002 |
|
| 8003 |
|
| 8004 |
|
| 8005 |
|
| 8006 |
|
| 8007 |
|
| 8008 |
|
| 8009 |
|
| 8010 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 8011 |
NK_LIB void* |
| 8012 |
nk_malloc(nk_handle unused, void *old,nk_size size) |
| 8013 |
{ |
| 8014 |
NK_UNUSED(unused); |
| 8015 |
NK_UNUSED(old); |
| 8016 |
return malloc(size); |
| 8017 |
} |
| 8018 |
NK_LIB void |
| 8019 |
nk_mfree(nk_handle unused, void *ptr) |
| 8020 |
{ |
| 8021 |
NK_UNUSED(unused); |
| 8022 |
free(ptr); |
| 8023 |
} |
| 8024 |
NK_API void |
| 8025 |
nk_buffer_init_default(struct nk_buffer *buffer) |
| 8026 |
{ |
| 8027 |
struct nk_allocator alloc; |
| 8028 |
alloc.userdata.ptr = 0; |
| 8029 |
alloc.alloc = nk_malloc; |
| 8030 |
alloc.free = nk_mfree; |
| 8031 |
nk_buffer_init(buffer, &alloc, NK_BUFFER_DEFAULT_INITIAL_SIZE); |
| 8032 |
} |
| 8033 |
#endif |
| 8034 |
|
| 8035 |
NK_API void |
| 8036 |
nk_buffer_init(struct nk_buffer *b, const struct nk_allocator *a, |
| 8037 |
nk_size initial_size) |
| 8038 |
{ |
| 8039 |
NK_ASSERT(b); |
| 8040 |
NK_ASSERT(a); |
| 8041 |
NK_ASSERT(initial_size); |
| 8042 |
if (!b || !a || !initial_size) return; |
| 8043 |
|
| 8044 |
nk_zero(b, sizeof(*b)); |
| 8045 |
b->type = NK_BUFFER_DYNAMIC; |
| 8046 |
b->memory.ptr = a->alloc(a->userdata,0, initial_size); |
| 8047 |
b->memory.size = initial_size; |
| 8048 |
b->size = initial_size; |
| 8049 |
b->grow_factor = 2.0f; |
| 8050 |
b->pool = *a; |
| 8051 |
} |
| 8052 |
NK_API void |
| 8053 |
nk_buffer_init_fixed(struct nk_buffer *b, void *m, nk_size size) |
| 8054 |
{ |
| 8055 |
NK_ASSERT(b); |
| 8056 |
NK_ASSERT(m); |
| 8057 |
NK_ASSERT(size); |
| 8058 |
if (!b || !m || !size) return; |
| 8059 |
|
| 8060 |
nk_zero(b, sizeof(*b)); |
| 8061 |
b->type = NK_BUFFER_FIXED; |
| 8062 |
b->memory.ptr = m; |
| 8063 |
b->memory.size = size; |
| 8064 |
b->size = size; |
| 8065 |
} |
| 8066 |
NK_LIB void* |
| 8067 |
nk_buffer_align(void *unaligned, |
| 8068 |
nk_size align, nk_size *alignment, |
| 8069 |
enum nk_buffer_allocation_type type) |
| 8070 |
{ |
| 8071 |
void *memory = 0; |
| 8072 |
switch (type) { |
| 8073 |
default: |
| 8074 |
case NK_BUFFER_MAX: |
| 8075 |
case NK_BUFFER_FRONT: |
| 8076 |
if (align) { |
| 8077 |
memory = NK_ALIGN_PTR(unaligned, align); |
| 8078 |
*alignment = (nk_size)((nk_byte*)memory - (nk_byte*)unaligned); |
| 8079 |
} else { |
| 8080 |
memory = unaligned; |
| 8081 |
*alignment = 0; |
| 8082 |
} |
| 8083 |
break; |
| 8084 |
case NK_BUFFER_BACK: |
| 8085 |
if (align) { |
| 8086 |
memory = NK_ALIGN_PTR_BACK(unaligned, align); |
| 8087 |
*alignment = (nk_size)((nk_byte*)unaligned - (nk_byte*)memory); |
| 8088 |
} else { |
| 8089 |
memory = unaligned; |
| 8090 |
*alignment = 0; |
| 8091 |
} |
| 8092 |
break; |
| 8093 |
} |
| 8094 |
return memory; |
| 8095 |
} |
| 8096 |
NK_LIB void* |
| 8097 |
nk_buffer_realloc(struct nk_buffer *b, nk_size capacity, nk_size *size) |
| 8098 |
{ |
| 8099 |
void *temp; |
| 8100 |
nk_size buffer_size; |
| 8101 |
|
| 8102 |
NK_ASSERT(b); |
| 8103 |
NK_ASSERT(size); |
| 8104 |
if (!b || !size || !b->pool.alloc || !b->pool.free) |
| 8105 |
return 0; |
| 8106 |
|
| 8107 |
buffer_size = b->memory.size; |
| 8108 |
temp = b->pool.alloc(b->pool.userdata, b->memory.ptr, capacity); |
| 8109 |
NK_ASSERT(temp); |
| 8110 |
if (!temp) return 0; |
| 8111 |
|
| 8112 |
*size = capacity; |
| 8113 |
if (temp != b->memory.ptr) { |
| 8114 |
NK_MEMCPY(temp, b->memory.ptr, buffer_size); |
| 8115 |
b->pool.free(b->pool.userdata, b->memory.ptr); |
| 8116 |
} |
| 8117 |
|
| 8118 |
if (b->size == buffer_size) { |
| 8119 |
|
| 8120 |
b->size = capacity; |
| 8121 |
return temp; |
| 8122 |
} else { |
| 8123 |
|
| 8124 |
void *dst, *src; |
| 8125 |
nk_size back_size; |
| 8126 |
back_size = buffer_size - b->size; |
| 8127 |
dst = nk_ptr_add(void, temp, capacity - back_size); |
| 8128 |
src = nk_ptr_add(void, temp, b->size); |
| 8129 |
NK_MEMCPY(dst, src, back_size); |
| 8130 |
b->size = capacity - back_size; |
| 8131 |
} |
| 8132 |
return temp; |
| 8133 |
} |
| 8134 |
NK_LIB void* |
| 8135 |
nk_buffer_alloc(struct nk_buffer *b, enum nk_buffer_allocation_type type, |
| 8136 |
nk_size size, nk_size align) |
| 8137 |
{ |
| 8138 |
int full; |
| 8139 |
nk_size alignment; |
| 8140 |
void *unaligned; |
| 8141 |
void *memory; |
| 8142 |
|
| 8143 |
NK_ASSERT(b); |
| 8144 |
NK_ASSERT(size); |
| 8145 |
if (!b || !size) return 0; |
| 8146 |
b->needed += size; |
| 8147 |
|
| 8148 |
|
| 8149 |
if (type == NK_BUFFER_FRONT) |
| 8150 |
unaligned = nk_ptr_add(void, b->memory.ptr, b->allocated); |
| 8151 |
else unaligned = nk_ptr_add(void, b->memory.ptr, b->size - size); |
| 8152 |
memory = nk_buffer_align(unaligned, align, &alignment, type); |
| 8153 |
|
| 8154 |
|
| 8155 |
if (type == NK_BUFFER_FRONT) |
| 8156 |
full = ((b->allocated + size + alignment) > b->size); |
| 8157 |
else full = ((b->size - NK_MIN(b->size,(size + alignment))) <= b->allocated); |
| 8158 |
|
| 8159 |
if (full) { |
| 8160 |
nk_size capacity; |
| 8161 |
if (b->type != NK_BUFFER_DYNAMIC) |
| 8162 |
return 0; |
| 8163 |
NK_ASSERT(b->pool.alloc && b->pool.free); |
| 8164 |
if (b->type != NK_BUFFER_DYNAMIC || !b->pool.alloc || !b->pool.free) |
| 8165 |
return 0; |
| 8166 |
|
| 8167 |
|
| 8168 |
capacity = (nk_size)((float)b->memory.size * b->grow_factor); |
| 8169 |
capacity = NK_MAX(capacity, nk_round_up_pow2((nk_uint)(b->allocated + size))); |
| 8170 |
b->memory.ptr = nk_buffer_realloc(b, capacity, &b->memory.size); |
| 8171 |
if (!b->memory.ptr) return 0; |
| 8172 |
|
| 8173 |
|
| 8174 |
if (type == NK_BUFFER_FRONT) |
| 8175 |
unaligned = nk_ptr_add(void, b->memory.ptr, b->allocated); |
| 8176 |
else unaligned = nk_ptr_add(void, b->memory.ptr, b->size - size); |
| 8177 |
memory = nk_buffer_align(unaligned, align, &alignment, type); |
| 8178 |
} |
| 8179 |
if (type == NK_BUFFER_FRONT) |
| 8180 |
b->allocated += size + alignment; |
| 8181 |
else b->size -= (size + alignment); |
| 8182 |
b->needed += alignment; |
| 8183 |
b->calls++; |
| 8184 |
return memory; |
| 8185 |
} |
| 8186 |
NK_API void |
| 8187 |
nk_buffer_push(struct nk_buffer *b, enum nk_buffer_allocation_type type, |
| 8188 |
const void *memory, nk_size size, nk_size align) |
| 8189 |
{ |
| 8190 |
void *mem = nk_buffer_alloc(b, type, size, align); |
| 8191 |
if (!mem) return; |
| 8192 |
NK_MEMCPY(mem, memory, size); |
| 8193 |
} |
| 8194 |
NK_API void |
| 8195 |
nk_buffer_mark(struct nk_buffer *buffer, enum nk_buffer_allocation_type type) |
| 8196 |
{ |
| 8197 |
NK_ASSERT(buffer); |
| 8198 |
if (!buffer) return; |
| 8199 |
buffer->marker[type].active = nk_true; |
| 8200 |
if (type == NK_BUFFER_BACK) |
| 8201 |
buffer->marker[type].offset = buffer->size; |
| 8202 |
else buffer->marker[type].offset = buffer->allocated; |
| 8203 |
} |
| 8204 |
NK_API void |
| 8205 |
nk_buffer_reset(struct nk_buffer *buffer, enum nk_buffer_allocation_type type) |
| 8206 |
{ |
| 8207 |
NK_ASSERT(buffer); |
| 8208 |
if (!buffer) return; |
| 8209 |
if (type == NK_BUFFER_BACK) { |
| 8210 |
|
| 8211 |
buffer->needed -= (buffer->memory.size - buffer->marker[type].offset); |
| 8212 |
if (buffer->marker[type].active) |
| 8213 |
buffer->size = buffer->marker[type].offset; |
| 8214 |
else buffer->size = buffer->memory.size; |
| 8215 |
buffer->marker[type].active = nk_false; |
| 8216 |
} else { |
| 8217 |
|
| 8218 |
buffer->needed -= (buffer->allocated - buffer->marker[type].offset); |
| 8219 |
if (buffer->marker[type].active) |
| 8220 |
buffer->allocated = buffer->marker[type].offset; |
| 8221 |
else buffer->allocated = 0; |
| 8222 |
buffer->marker[type].active = nk_false; |
| 8223 |
} |
| 8224 |
} |
| 8225 |
NK_API void |
| 8226 |
nk_buffer_clear(struct nk_buffer *b) |
| 8227 |
{ |
| 8228 |
NK_ASSERT(b); |
| 8229 |
if (!b) return; |
| 8230 |
b->allocated = 0; |
| 8231 |
b->size = b->memory.size; |
| 8232 |
b->calls = 0; |
| 8233 |
b->needed = 0; |
| 8234 |
} |
| 8235 |
NK_API void |
| 8236 |
nk_buffer_free(struct nk_buffer *b) |
| 8237 |
{ |
| 8238 |
NK_ASSERT(b); |
| 8239 |
if (!b || !b->memory.ptr) return; |
| 8240 |
if (b->type == NK_BUFFER_FIXED) return; |
| 8241 |
if (!b->pool.free) return; |
| 8242 |
NK_ASSERT(b->pool.free); |
| 8243 |
b->pool.free(b->pool.userdata, b->memory.ptr); |
| 8244 |
} |
| 8245 |
NK_API void |
| 8246 |
nk_buffer_info(struct nk_memory_status *s, struct nk_buffer *b) |
| 8247 |
{ |
| 8248 |
NK_ASSERT(b); |
| 8249 |
NK_ASSERT(s); |
| 8250 |
if (!s || !b) return; |
| 8251 |
s->allocated = b->allocated; |
| 8252 |
s->size = b->memory.size; |
| 8253 |
s->needed = b->needed; |
| 8254 |
s->memory = b->memory.ptr; |
| 8255 |
s->calls = b->calls; |
| 8256 |
} |
| 8257 |
NK_API void* |
| 8258 |
nk_buffer_memory(struct nk_buffer *buffer) |
| 8259 |
{ |
| 8260 |
NK_ASSERT(buffer); |
| 8261 |
if (!buffer) return 0; |
| 8262 |
return buffer->memory.ptr; |
| 8263 |
} |
| 8264 |
NK_API const void* |
| 8265 |
nk_buffer_memory_const(const struct nk_buffer *buffer) |
| 8266 |
{ |
| 8267 |
NK_ASSERT(buffer); |
| 8268 |
if (!buffer) return 0; |
| 8269 |
return buffer->memory.ptr; |
| 8270 |
} |
| 8271 |
NK_API nk_size |
| 8272 |
nk_buffer_total(struct nk_buffer *buffer) |
| 8273 |
{ |
| 8274 |
NK_ASSERT(buffer); |
| 8275 |
if (!buffer) return 0; |
| 8276 |
return buffer->memory.size; |
| 8277 |
} |
| 8278 |
|
| 8279 |
|
| 8280 |
|
| 8281 |
|
| 8282 |
|
| 8283 |
|
| 8284 |
|
| 8285 |
|
| 8286 |
|
| 8287 |
|
| 8288 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 8289 |
NK_API void |
| 8290 |
nk_str_init_default(struct nk_str *str) |
| 8291 |
{ |
| 8292 |
struct nk_allocator alloc; |
| 8293 |
alloc.userdata.ptr = 0; |
| 8294 |
alloc.alloc = nk_malloc; |
| 8295 |
alloc.free = nk_mfree; |
| 8296 |
nk_buffer_init(&str->buffer, &alloc, 32); |
| 8297 |
str->len = 0; |
| 8298 |
} |
| 8299 |
#endif |
| 8300 |
|
| 8301 |
NK_API void |
| 8302 |
nk_str_init(struct nk_str *str, const struct nk_allocator *alloc, nk_size size) |
| 8303 |
{ |
| 8304 |
nk_buffer_init(&str->buffer, alloc, size); |
| 8305 |
str->len = 0; |
| 8306 |
} |
| 8307 |
NK_API void |
| 8308 |
nk_str_init_fixed(struct nk_str *str, void *memory, nk_size size) |
| 8309 |
{ |
| 8310 |
nk_buffer_init_fixed(&str->buffer, memory, size); |
| 8311 |
str->len = 0; |
| 8312 |
} |
| 8313 |
NK_API int |
| 8314 |
nk_str_append_text_char(struct nk_str *s, const char *str, int len) |
| 8315 |
{ |
| 8316 |
char *mem; |
| 8317 |
NK_ASSERT(s); |
| 8318 |
NK_ASSERT(str); |
| 8319 |
if (!s || !str || !len) return 0; |
| 8320 |
mem = (char*)nk_buffer_alloc(&s->buffer, NK_BUFFER_FRONT, (nk_size)len * sizeof(char), 0); |
| 8321 |
if (!mem) return 0; |
| 8322 |
NK_MEMCPY(mem, str, (nk_size)len * sizeof(char)); |
| 8323 |
s->len += nk_utf_len(str, len); |
| 8324 |
return len; |
| 8325 |
} |
| 8326 |
NK_API int |
| 8327 |
nk_str_append_str_char(struct nk_str *s, const char *str) |
| 8328 |
{ |
| 8329 |
return nk_str_append_text_char(s, str, nk_strlen(str)); |
| 8330 |
} |
| 8331 |
NK_API int |
| 8332 |
nk_str_append_text_utf8(struct nk_str *str, const char *text, int len) |
| 8333 |
{ |
| 8334 |
int i = 0; |
| 8335 |
int byte_len = 0; |
| 8336 |
nk_rune unicode; |
| 8337 |
if (!str || !text || !len) return 0; |
| 8338 |
for (i = 0; i < len; ++i) |
| 8339 |
byte_len += nk_utf_decode(text+byte_len, &unicode, 4); |
| 8340 |
nk_str_append_text_char(str, text, byte_len); |
| 8341 |
return len; |
| 8342 |
} |
| 8343 |
NK_API int |
| 8344 |
nk_str_append_str_utf8(struct nk_str *str, const char *text) |
| 8345 |
{ |
| 8346 |
int runes = 0; |
| 8347 |
int byte_len = 0; |
| 8348 |
int glyph_len = 0; |
| 8349 |
nk_rune unicode; |
| 8350 |
if (!str || !text) return 0; |
| 8351 |
|
| 8352 |
glyph_len = byte_len = nk_utf_decode(text+byte_len, &unicode, 4); |
| 8353 |
while (unicode != '\0' && glyph_len) { |
| 8354 |
glyph_len = nk_utf_decode(text+byte_len, &unicode, 4); |
| 8355 |
byte_len += glyph_len; |
| 8356 |
} |
| 8357 |
nk_str_append_text_char(str, text, byte_len); |
| 8358 |
return runes; |
| 8359 |
} |
| 8360 |
NK_API int |
| 8361 |
nk_str_append_text_runes(struct nk_str *str, const nk_rune *text, int len) |
| 8362 |
{ |
| 8363 |
int i = 0; |
| 8364 |
int byte_len = 0; |
| 8365 |
nk_glyph glyph; |
| 8366 |
|
| 8367 |
NK_ASSERT(str); |
| 8368 |
if (!str || !text || !len) return 0; |
| 8369 |
for (i = 0; i < len; ++i) { |
| 8370 |
byte_len = nk_utf_encode(text[i], glyph, NK_UTF_SIZE); |
| 8371 |
if (!byte_len) break; |
| 8372 |
nk_str_append_text_char(str, glyph, byte_len); |
| 8373 |
} |
| 8374 |
return len; |
| 8375 |
} |
| 8376 |
NK_API int |
| 8377 |
nk_str_append_str_runes(struct nk_str *str, const nk_rune *runes) |
| 8378 |
{ |
| 8379 |
int i = 0; |
| 8380 |
nk_glyph glyph; |
| 8381 |
int byte_len; |
| 8382 |
NK_ASSERT(str); |
| 8383 |
if (!str || !runes) return 0; |
| 8384 |
while (runes[i] != '\0') { |
| 8385 |
byte_len = nk_utf_encode(runes[i], glyph, NK_UTF_SIZE); |
| 8386 |
nk_str_append_text_char(str, glyph, byte_len); |
| 8387 |
i++; |
| 8388 |
} |
| 8389 |
return i; |
| 8390 |
} |
| 8391 |
NK_API int |
| 8392 |
nk_str_insert_at_char(struct nk_str *s, int pos, const char *str, int len) |
| 8393 |
{ |
| 8394 |
int i; |
| 8395 |
void *mem; |
| 8396 |
char *src; |
| 8397 |
char *dst; |
| 8398 |
|
| 8399 |
int copylen; |
| 8400 |
NK_ASSERT(s); |
| 8401 |
NK_ASSERT(str); |
| 8402 |
NK_ASSERT(len >= 0); |
| 8403 |
if (!s || !str || !len || (nk_size)pos > s->buffer.allocated) return 0; |
| 8404 |
if ((s->buffer.allocated + (nk_size)len >= s->buffer.memory.size) && |
| 8405 |
(s->buffer.type == NK_BUFFER_FIXED)) return 0; |
| 8406 |
|
| 8407 |
copylen = (int)s->buffer.allocated - pos; |
| 8408 |
if (!copylen) { |
| 8409 |
nk_str_append_text_char(s, str, len); |
| 8410 |
return 1; |
| 8411 |
} |
| 8412 |
mem = nk_buffer_alloc(&s->buffer, NK_BUFFER_FRONT, (nk_size)len * sizeof(char), 0); |
| 8413 |
if (!mem) return 0; |
| 8414 |
|
| 8415 |
|
| 8416 |
NK_ASSERT(((int)pos + (int)len + ((int)copylen - 1)) >= 0); |
| 8417 |
NK_ASSERT(((int)pos + ((int)copylen - 1)) >= 0); |
| 8418 |
dst = nk_ptr_add(char, s->buffer.memory.ptr, pos + len + (copylen - 1)); |
| 8419 |
src = nk_ptr_add(char, s->buffer.memory.ptr, pos + (copylen-1)); |
| 8420 |
for (i = 0; i < copylen; ++i) *dst-- = *src--; |
| 8421 |
mem = nk_ptr_add(void, s->buffer.memory.ptr, pos); |
| 8422 |
NK_MEMCPY(mem, str, (nk_size)len * sizeof(char)); |
| 8423 |
s->len = nk_utf_len((char *)s->buffer.memory.ptr, (int)s->buffer.allocated); |
| 8424 |
return 1; |
| 8425 |
} |
| 8426 |
NK_API int |
| 8427 |
nk_str_insert_at_rune(struct nk_str *str, int pos, const char *cstr, int len) |
| 8428 |
{ |
| 8429 |
int glyph_len; |
| 8430 |
nk_rune unicode; |
| 8431 |
const char *begin; |
| 8432 |
const char *buffer; |
| 8433 |
|
| 8434 |
NK_ASSERT(str); |
| 8435 |
NK_ASSERT(cstr); |
| 8436 |
NK_ASSERT(len); |
| 8437 |
if (!str || !cstr || !len) return 0; |
| 8438 |
begin = nk_str_at_rune(str, pos, &unicode, &glyph_len); |
| 8439 |
if (!str->len) |
| 8440 |
return nk_str_append_text_char(str, cstr, len); |
| 8441 |
buffer = nk_str_get_const(str); |
| 8442 |
if (!begin) return 0; |
| 8443 |
return nk_str_insert_at_char(str, (int)(begin - buffer), cstr, len); |
| 8444 |
} |
| 8445 |
NK_API int |
| 8446 |
nk_str_insert_text_char(struct nk_str *str, int pos, const char *text, int len) |
| 8447 |
{ |
| 8448 |
return nk_str_insert_text_utf8(str, pos, text, len); |
| 8449 |
} |
| 8450 |
NK_API int |
| 8451 |
nk_str_insert_str_char(struct nk_str *str, int pos, const char *text) |
| 8452 |
{ |
| 8453 |
return nk_str_insert_text_utf8(str, pos, text, nk_strlen(text)); |
| 8454 |
} |
| 8455 |
NK_API int |
| 8456 |
nk_str_insert_text_utf8(struct nk_str *str, int pos, const char *text, int len) |
| 8457 |
{ |
| 8458 |
int i = 0; |
| 8459 |
int byte_len = 0; |
| 8460 |
nk_rune unicode; |
| 8461 |
|
| 8462 |
NK_ASSERT(str); |
| 8463 |
NK_ASSERT(text); |
| 8464 |
if (!str || !text || !len) return 0; |
| 8465 |
for (i = 0; i < len; ++i) |
| 8466 |
byte_len += nk_utf_decode(text+byte_len, &unicode, 4); |
| 8467 |
nk_str_insert_at_rune(str, pos, text, byte_len); |
| 8468 |
return len; |
| 8469 |
} |
| 8470 |
NK_API int |
| 8471 |
nk_str_insert_str_utf8(struct nk_str *str, int pos, const char *text) |
| 8472 |
{ |
| 8473 |
int runes = 0; |
| 8474 |
int byte_len = 0; |
| 8475 |
int glyph_len = 0; |
| 8476 |
nk_rune unicode; |
| 8477 |
if (!str || !text) return 0; |
| 8478 |
|
| 8479 |
glyph_len = byte_len = nk_utf_decode(text+byte_len, &unicode, 4); |
| 8480 |
while (unicode != '\0' && glyph_len) { |
| 8481 |
glyph_len = nk_utf_decode(text+byte_len, &unicode, 4); |
| 8482 |
byte_len += glyph_len; |
| 8483 |
} |
| 8484 |
nk_str_insert_at_rune(str, pos, text, byte_len); |
| 8485 |
return runes; |
| 8486 |
} |
| 8487 |
NK_API int |
| 8488 |
nk_str_insert_text_runes(struct nk_str *str, int pos, const nk_rune *runes, int len) |
| 8489 |
{ |
| 8490 |
int i = 0; |
| 8491 |
int byte_len = 0; |
| 8492 |
nk_glyph glyph; |
| 8493 |
|
| 8494 |
NK_ASSERT(str); |
| 8495 |
if (!str || !runes || !len) return 0; |
| 8496 |
for (i = 0; i < len; ++i) { |
| 8497 |
byte_len = nk_utf_encode(runes[i], glyph, NK_UTF_SIZE); |
| 8498 |
if (!byte_len) break; |
| 8499 |
nk_str_insert_at_rune(str, pos+i, glyph, byte_len); |
| 8500 |
} |
| 8501 |
return len; |
| 8502 |
} |
| 8503 |
NK_API int |
| 8504 |
nk_str_insert_str_runes(struct nk_str *str, int pos, const nk_rune *runes) |
| 8505 |
{ |
| 8506 |
int i = 0; |
| 8507 |
nk_glyph glyph; |
| 8508 |
int byte_len; |
| 8509 |
NK_ASSERT(str); |
| 8510 |
if (!str || !runes) return 0; |
| 8511 |
while (runes[i] != '\0') { |
| 8512 |
byte_len = nk_utf_encode(runes[i], glyph, NK_UTF_SIZE); |
| 8513 |
nk_str_insert_at_rune(str, pos+i, glyph, byte_len); |
| 8514 |
i++; |
| 8515 |
} |
| 8516 |
return i; |
| 8517 |
} |
| 8518 |
NK_API void |
| 8519 |
nk_str_remove_chars(struct nk_str *s, int len) |
| 8520 |
{ |
| 8521 |
NK_ASSERT(s); |
| 8522 |
NK_ASSERT(len >= 0); |
| 8523 |
if (!s || len < 0 || (nk_size)len > s->buffer.allocated) return; |
| 8524 |
NK_ASSERT(((int)s->buffer.allocated - (int)len) >= 0); |
| 8525 |
s->buffer.allocated -= (nk_size)len; |
| 8526 |
s->len = nk_utf_len((char *)s->buffer.memory.ptr, (int)s->buffer.allocated); |
| 8527 |
} |
| 8528 |
NK_API void |
| 8529 |
nk_str_remove_runes(struct nk_str *str, int len) |
| 8530 |
{ |
| 8531 |
int index; |
| 8532 |
const char *begin; |
| 8533 |
const char *end; |
| 8534 |
nk_rune unicode; |
| 8535 |
|
| 8536 |
NK_ASSERT(str); |
| 8537 |
NK_ASSERT(len >= 0); |
| 8538 |
if (!str || len < 0) return; |
| 8539 |
if (len >= str->len) { |
| 8540 |
str->len = 0; |
| 8541 |
return; |
| 8542 |
} |
| 8543 |
|
| 8544 |
index = str->len - len; |
| 8545 |
begin = nk_str_at_rune(str, index, &unicode, &len); |
| 8546 |
end = (const char*)str->buffer.memory.ptr + str->buffer.allocated; |
| 8547 |
nk_str_remove_chars(str, (int)(end-begin)+1); |
| 8548 |
} |
| 8549 |
NK_API void |
| 8550 |
nk_str_delete_chars(struct nk_str *s, int pos, int len) |
| 8551 |
{ |
| 8552 |
NK_ASSERT(s); |
| 8553 |
if (!s || !len || (nk_size)pos > s->buffer.allocated || |
| 8554 |
(nk_size)(pos + len) > s->buffer.allocated) return; |
| 8555 |
|
| 8556 |
if ((nk_size)(pos + len) < s->buffer.allocated) { |
| 8557 |
|
| 8558 |
char *dst = nk_ptr_add(char, s->buffer.memory.ptr, pos); |
| 8559 |
char *src = nk_ptr_add(char, s->buffer.memory.ptr, pos + len); |
| 8560 |
NK_MEMCPY(dst, src, s->buffer.allocated - (nk_size)(pos + len)); |
| 8561 |
NK_ASSERT(((int)s->buffer.allocated - (int)len) >= 0); |
| 8562 |
s->buffer.allocated -= (nk_size)len; |
| 8563 |
} else nk_str_remove_chars(s, len); |
| 8564 |
s->len = nk_utf_len((char *)s->buffer.memory.ptr, (int)s->buffer.allocated); |
| 8565 |
} |
| 8566 |
NK_API void |
| 8567 |
nk_str_delete_runes(struct nk_str *s, int pos, int len) |
| 8568 |
{ |
| 8569 |
char *temp; |
| 8570 |
nk_rune unicode; |
| 8571 |
char *begin; |
| 8572 |
char *end; |
| 8573 |
int unused; |
| 8574 |
|
| 8575 |
NK_ASSERT(s); |
| 8576 |
NK_ASSERT(s->len >= pos + len); |
| 8577 |
if (s->len < pos + len) |
| 8578 |
len = NK_CLAMP(0, (s->len - pos), s->len); |
| 8579 |
if (!len) return; |
| 8580 |
|
| 8581 |
temp = (char *)s->buffer.memory.ptr; |
| 8582 |
begin = nk_str_at_rune(s, pos, &unicode, &unused); |
| 8583 |
if (!begin) return; |
| 8584 |
s->buffer.memory.ptr = begin; |
| 8585 |
end = nk_str_at_rune(s, len, &unicode, &unused); |
| 8586 |
s->buffer.memory.ptr = temp; |
| 8587 |
if (!end) return; |
| 8588 |
nk_str_delete_chars(s, (int)(begin - temp), (int)(end - begin)); |
| 8589 |
} |
| 8590 |
NK_API char* |
| 8591 |
nk_str_at_char(struct nk_str *s, int pos) |
| 8592 |
{ |
| 8593 |
NK_ASSERT(s); |
| 8594 |
if (!s || pos > (int)s->buffer.allocated) return 0; |
| 8595 |
return nk_ptr_add(char, s->buffer.memory.ptr, pos); |
| 8596 |
} |
| 8597 |
NK_API char* |
| 8598 |
nk_str_at_rune(struct nk_str *str, int pos, nk_rune *unicode, int *len) |
| 8599 |
{ |
| 8600 |
int i = 0; |
| 8601 |
int src_len = 0; |
| 8602 |
int glyph_len = 0; |
| 8603 |
char *text; |
| 8604 |
int text_len; |
| 8605 |
|
| 8606 |
NK_ASSERT(str); |
| 8607 |
NK_ASSERT(unicode); |
| 8608 |
NK_ASSERT(len); |
| 8609 |
|
| 8610 |
if (!str || !unicode || !len) return 0; |
| 8611 |
if (pos < 0) { |
| 8612 |
*unicode = 0; |
| 8613 |
*len = 0; |
| 8614 |
return 0; |
| 8615 |
} |
| 8616 |
|
| 8617 |
text = (char*)str->buffer.memory.ptr; |
| 8618 |
text_len = (int)str->buffer.allocated; |
| 8619 |
glyph_len = nk_utf_decode(text, unicode, text_len); |
| 8620 |
while (glyph_len) { |
| 8621 |
if (i == pos) { |
| 8622 |
*len = glyph_len; |
| 8623 |
break; |
| 8624 |
} |
| 8625 |
|
| 8626 |
i++; |
| 8627 |
src_len = src_len + glyph_len; |
| 8628 |
glyph_len = nk_utf_decode(text + src_len, unicode, text_len - src_len); |
| 8629 |
} |
| 8630 |
if (i != pos) return 0; |
| 8631 |
return text + src_len; |
| 8632 |
} |
| 8633 |
NK_API const char* |
| 8634 |
nk_str_at_char_const(const struct nk_str *s, int pos) |
| 8635 |
{ |
| 8636 |
NK_ASSERT(s); |
| 8637 |
if (!s || pos > (int)s->buffer.allocated) return 0; |
| 8638 |
return nk_ptr_add(char, s->buffer.memory.ptr, pos); |
| 8639 |
} |
| 8640 |
NK_API const char* |
| 8641 |
nk_str_at_const(const struct nk_str *str, int pos, nk_rune *unicode, int *len) |
| 8642 |
{ |
| 8643 |
int i = 0; |
| 8644 |
int src_len = 0; |
| 8645 |
int glyph_len = 0; |
| 8646 |
char *text; |
| 8647 |
int text_len; |
| 8648 |
|
| 8649 |
NK_ASSERT(str); |
| 8650 |
NK_ASSERT(unicode); |
| 8651 |
NK_ASSERT(len); |
| 8652 |
|
| 8653 |
if (!str || !unicode || !len) return 0; |
| 8654 |
if (pos < 0) { |
| 8655 |
*unicode = 0; |
| 8656 |
*len = 0; |
| 8657 |
return 0; |
| 8658 |
} |
| 8659 |
|
| 8660 |
text = (char*)str->buffer.memory.ptr; |
| 8661 |
text_len = (int)str->buffer.allocated; |
| 8662 |
glyph_len = nk_utf_decode(text, unicode, text_len); |
| 8663 |
while (glyph_len) { |
| 8664 |
if (i == pos) { |
| 8665 |
*len = glyph_len; |
| 8666 |
break; |
| 8667 |
} |
| 8668 |
|
| 8669 |
i++; |
| 8670 |
src_len = src_len + glyph_len; |
| 8671 |
glyph_len = nk_utf_decode(text + src_len, unicode, text_len - src_len); |
| 8672 |
} |
| 8673 |
if (i != pos) return 0; |
| 8674 |
return text + src_len; |
| 8675 |
} |
| 8676 |
NK_API nk_rune |
| 8677 |
nk_str_rune_at(const struct nk_str *str, int pos) |
| 8678 |
{ |
| 8679 |
int len; |
| 8680 |
nk_rune unicode = 0; |
| 8681 |
nk_str_at_const(str, pos, &unicode, &len); |
| 8682 |
return unicode; |
| 8683 |
} |
| 8684 |
NK_API char* |
| 8685 |
nk_str_get(struct nk_str *s) |
| 8686 |
{ |
| 8687 |
NK_ASSERT(s); |
| 8688 |
if (!s || !s->len || !s->buffer.allocated) return 0; |
| 8689 |
return (char*)s->buffer.memory.ptr; |
| 8690 |
} |
| 8691 |
NK_API const char* |
| 8692 |
nk_str_get_const(const struct nk_str *s) |
| 8693 |
{ |
| 8694 |
NK_ASSERT(s); |
| 8695 |
if (!s || !s->len || !s->buffer.allocated) return 0; |
| 8696 |
return (const char*)s->buffer.memory.ptr; |
| 8697 |
} |
| 8698 |
NK_API int |
| 8699 |
nk_str_len(struct nk_str *s) |
| 8700 |
{ |
| 8701 |
NK_ASSERT(s); |
| 8702 |
if (!s || !s->len || !s->buffer.allocated) return 0; |
| 8703 |
return s->len; |
| 8704 |
} |
| 8705 |
NK_API int |
| 8706 |
nk_str_len_char(struct nk_str *s) |
| 8707 |
{ |
| 8708 |
NK_ASSERT(s); |
| 8709 |
if (!s || !s->len || !s->buffer.allocated) return 0; |
| 8710 |
return (int)s->buffer.allocated; |
| 8711 |
} |
| 8712 |
NK_API void |
| 8713 |
nk_str_clear(struct nk_str *str) |
| 8714 |
{ |
| 8715 |
NK_ASSERT(str); |
| 8716 |
nk_buffer_clear(&str->buffer); |
| 8717 |
str->len = 0; |
| 8718 |
} |
| 8719 |
NK_API void |
| 8720 |
nk_str_free(struct nk_str *str) |
| 8721 |
{ |
| 8722 |
NK_ASSERT(str); |
| 8723 |
nk_buffer_free(&str->buffer); |
| 8724 |
str->len = 0; |
| 8725 |
} |
| 8726 |
|
| 8727 |
|
| 8728 |
|
| 8729 |
|
| 8730 |
|
| 8731 |
|
| 8732 |
|
| 8733 |
|
| 8734 |
|
| 8735 |
|
| 8736 |
NK_LIB void |
| 8737 |
nk_command_buffer_init(struct nk_command_buffer *cb, |
| 8738 |
struct nk_buffer *b, enum nk_command_clipping clip) |
| 8739 |
{ |
| 8740 |
NK_ASSERT(cb); |
| 8741 |
NK_ASSERT(b); |
| 8742 |
if (!cb || !b) return; |
| 8743 |
cb->base = b; |
| 8744 |
cb->use_clipping = (int)clip; |
| 8745 |
cb->begin = b->allocated; |
| 8746 |
cb->end = b->allocated; |
| 8747 |
cb->last = b->allocated; |
| 8748 |
} |
| 8749 |
NK_LIB void |
| 8750 |
nk_command_buffer_reset(struct nk_command_buffer *b) |
| 8751 |
{ |
| 8752 |
NK_ASSERT(b); |
| 8753 |
if (!b) return; |
| 8754 |
b->begin = 0; |
| 8755 |
b->end = 0; |
| 8756 |
b->last = 0; |
| 8757 |
b->clip = nk_null_rect; |
| 8758 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 8759 |
b->userdata.ptr = 0; |
| 8760 |
#endif |
| 8761 |
} |
| 8762 |
NK_LIB void* |
| 8763 |
nk_command_buffer_push(struct nk_command_buffer* b, |
| 8764 |
enum nk_command_type t, nk_size size) |
| 8765 |
{ |
| 8766 |
NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_command); |
| 8767 |
struct nk_command *cmd; |
| 8768 |
nk_size alignment; |
| 8769 |
void *unaligned; |
| 8770 |
void *memory; |
| 8771 |
|
| 8772 |
NK_ASSERT(b); |
| 8773 |
NK_ASSERT(b->base); |
| 8774 |
if (!b) return 0; |
| 8775 |
cmd = (struct nk_command*)nk_buffer_alloc(b->base,NK_BUFFER_FRONT,size,align); |
| 8776 |
if (!cmd) return 0; |
| 8777 |
|
| 8778 |
|
| 8779 |
b->last = (nk_size)((nk_byte*)cmd - (nk_byte*)b->base->memory.ptr); |
| 8780 |
unaligned = (nk_byte*)cmd + size; |
| 8781 |
memory = NK_ALIGN_PTR(unaligned, align); |
| 8782 |
alignment = (nk_size)((nk_byte*)memory - (nk_byte*)unaligned); |
| 8783 |
#ifdef NK_ZERO_COMMAND_MEMORY |
| 8784 |
NK_MEMSET(cmd, 0, size + alignment); |
| 8785 |
#endif |
| 8786 |
|
| 8787 |
cmd->type = t; |
| 8788 |
cmd->next = b->base->allocated + alignment; |
| 8789 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 8790 |
cmd->userdata = b->userdata; |
| 8791 |
#endif |
| 8792 |
b->end = cmd->next; |
| 8793 |
return cmd; |
| 8794 |
} |
| 8795 |
NK_API void |
| 8796 |
nk_push_scissor(struct nk_command_buffer *b, struct nk_rect r) |
| 8797 |
{ |
| 8798 |
struct nk_command_scissor *cmd; |
| 8799 |
NK_ASSERT(b); |
| 8800 |
if (!b) return; |
| 8801 |
|
| 8802 |
b->clip.x = r.x; |
| 8803 |
b->clip.y = r.y; |
| 8804 |
b->clip.w = r.w; |
| 8805 |
b->clip.h = r.h; |
| 8806 |
cmd = (struct nk_command_scissor*) |
| 8807 |
nk_command_buffer_push(b, NK_COMMAND_SCISSOR, sizeof(*cmd)); |
| 8808 |
|
| 8809 |
if (!cmd) return; |
| 8810 |
cmd->x = (short)r.x; |
| 8811 |
cmd->y = (short)r.y; |
| 8812 |
cmd->w = (unsigned short)NK_MAX(0, r.w); |
| 8813 |
cmd->h = (unsigned short)NK_MAX(0, r.h); |
| 8814 |
} |
| 8815 |
NK_API void |
| 8816 |
nk_stroke_line(struct nk_command_buffer *b, float x0, float y0, |
| 8817 |
float x1, float y1, float line_thickness, struct nk_color c) |
| 8818 |
{ |
| 8819 |
struct nk_command_line *cmd; |
| 8820 |
NK_ASSERT(b); |
| 8821 |
if (!b || line_thickness <= 0) return; |
| 8822 |
cmd = (struct nk_command_line*) |
| 8823 |
nk_command_buffer_push(b, NK_COMMAND_LINE, sizeof(*cmd)); |
| 8824 |
if (!cmd) return; |
| 8825 |
cmd->line_thickness = (unsigned short)line_thickness; |
| 8826 |
cmd->begin.x = (short)x0; |
| 8827 |
cmd->begin.y = (short)y0; |
| 8828 |
cmd->end.x = (short)x1; |
| 8829 |
cmd->end.y = (short)y1; |
| 8830 |
cmd->color = c; |
| 8831 |
} |
| 8832 |
NK_API void |
| 8833 |
nk_stroke_curve(struct nk_command_buffer *b, float ax, float ay, |
| 8834 |
float ctrl0x, float ctrl0y, float ctrl1x, float ctrl1y, |
| 8835 |
float bx, float by, float line_thickness, struct nk_color col) |
| 8836 |
{ |
| 8837 |
struct nk_command_curve *cmd; |
| 8838 |
NK_ASSERT(b); |
| 8839 |
if (!b || col.a == 0 || line_thickness <= 0) return; |
| 8840 |
|
| 8841 |
cmd = (struct nk_command_curve*) |
| 8842 |
nk_command_buffer_push(b, NK_COMMAND_CURVE, sizeof(*cmd)); |
| 8843 |
if (!cmd) return; |
| 8844 |
cmd->line_thickness = (unsigned short)line_thickness; |
| 8845 |
cmd->begin.x = (short)ax; |
| 8846 |
cmd->begin.y = (short)ay; |
| 8847 |
cmd->ctrl[0].x = (short)ctrl0x; |
| 8848 |
cmd->ctrl[0].y = (short)ctrl0y; |
| 8849 |
cmd->ctrl[1].x = (short)ctrl1x; |
| 8850 |
cmd->ctrl[1].y = (short)ctrl1y; |
| 8851 |
cmd->end.x = (short)bx; |
| 8852 |
cmd->end.y = (short)by; |
| 8853 |
cmd->color = col; |
| 8854 |
} |
| 8855 |
NK_API void |
| 8856 |
nk_stroke_rect(struct nk_command_buffer *b, struct nk_rect rect, |
| 8857 |
float rounding, float line_thickness, struct nk_color c) |
| 8858 |
{ |
| 8859 |
struct nk_command_rect *cmd; |
| 8860 |
NK_ASSERT(b); |
| 8861 |
if (!b || c.a == 0 || rect.w == 0 || rect.h == 0 || line_thickness <= 0) return; |
| 8862 |
if (b->use_clipping) { |
| 8863 |
const struct nk_rect *clip = &b->clip; |
| 8864 |
if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h, |
| 8865 |
clip->x, clip->y, clip->w, clip->h)) return; |
| 8866 |
} |
| 8867 |
cmd = (struct nk_command_rect*) |
| 8868 |
nk_command_buffer_push(b, NK_COMMAND_RECT, sizeof(*cmd)); |
| 8869 |
if (!cmd) return; |
| 8870 |
cmd->rounding = (unsigned short)rounding; |
| 8871 |
cmd->line_thickness = (unsigned short)line_thickness; |
| 8872 |
cmd->x = (short)rect.x; |
| 8873 |
cmd->y = (short)rect.y; |
| 8874 |
cmd->w = (unsigned short)NK_MAX(0, rect.w); |
| 8875 |
cmd->h = (unsigned short)NK_MAX(0, rect.h); |
| 8876 |
cmd->color = c; |
| 8877 |
} |
| 8878 |
NK_API void |
| 8879 |
nk_fill_rect(struct nk_command_buffer *b, struct nk_rect rect, |
| 8880 |
float rounding, struct nk_color c) |
| 8881 |
{ |
| 8882 |
struct nk_command_rect_filled *cmd; |
| 8883 |
NK_ASSERT(b); |
| 8884 |
if (!b || c.a == 0 || rect.w == 0 || rect.h == 0) return; |
| 8885 |
if (b->use_clipping) { |
| 8886 |
const struct nk_rect *clip = &b->clip; |
| 8887 |
if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h, |
| 8888 |
clip->x, clip->y, clip->w, clip->h)) return; |
| 8889 |
} |
| 8890 |
|
| 8891 |
cmd = (struct nk_command_rect_filled*) |
| 8892 |
nk_command_buffer_push(b, NK_COMMAND_RECT_FILLED, sizeof(*cmd)); |
| 8893 |
if (!cmd) return; |
| 8894 |
cmd->rounding = (unsigned short)rounding; |
| 8895 |
cmd->x = (short)rect.x; |
| 8896 |
cmd->y = (short)rect.y; |
| 8897 |
cmd->w = (unsigned short)NK_MAX(0, rect.w); |
| 8898 |
cmd->h = (unsigned short)NK_MAX(0, rect.h); |
| 8899 |
cmd->color = c; |
| 8900 |
} |
| 8901 |
NK_API void |
| 8902 |
nk_fill_rect_multi_color(struct nk_command_buffer *b, struct nk_rect rect, |
| 8903 |
struct nk_color left, struct nk_color top, struct nk_color right, |
| 8904 |
struct nk_color bottom) |
| 8905 |
{ |
| 8906 |
struct nk_command_rect_multi_color *cmd; |
| 8907 |
NK_ASSERT(b); |
| 8908 |
if (!b || rect.w == 0 || rect.h == 0) return; |
| 8909 |
if (b->use_clipping) { |
| 8910 |
const struct nk_rect *clip = &b->clip; |
| 8911 |
if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h, |
| 8912 |
clip->x, clip->y, clip->w, clip->h)) return; |
| 8913 |
} |
| 8914 |
|
| 8915 |
cmd = (struct nk_command_rect_multi_color*) |
| 8916 |
nk_command_buffer_push(b, NK_COMMAND_RECT_MULTI_COLOR, sizeof(*cmd)); |
| 8917 |
if (!cmd) return; |
| 8918 |
cmd->x = (short)rect.x; |
| 8919 |
cmd->y = (short)rect.y; |
| 8920 |
cmd->w = (unsigned short)NK_MAX(0, rect.w); |
| 8921 |
cmd->h = (unsigned short)NK_MAX(0, rect.h); |
| 8922 |
cmd->left = left; |
| 8923 |
cmd->top = top; |
| 8924 |
cmd->right = right; |
| 8925 |
cmd->bottom = bottom; |
| 8926 |
} |
| 8927 |
NK_API void |
| 8928 |
nk_stroke_circle(struct nk_command_buffer *b, struct nk_rect r, |
| 8929 |
float line_thickness, struct nk_color c) |
| 8930 |
{ |
| 8931 |
struct nk_command_circle *cmd; |
| 8932 |
if (!b || r.w == 0 || r.h == 0 || line_thickness <= 0) return; |
| 8933 |
if (b->use_clipping) { |
| 8934 |
const struct nk_rect *clip = &b->clip; |
| 8935 |
if (!NK_INTERSECT(r.x, r.y, r.w, r.h, clip->x, clip->y, clip->w, clip->h)) |
| 8936 |
return; |
| 8937 |
} |
| 8938 |
|
| 8939 |
cmd = (struct nk_command_circle*) |
| 8940 |
nk_command_buffer_push(b, NK_COMMAND_CIRCLE, sizeof(*cmd)); |
| 8941 |
if (!cmd) return; |
| 8942 |
cmd->line_thickness = (unsigned short)line_thickness; |
| 8943 |
cmd->x = (short)r.x; |
| 8944 |
cmd->y = (short)r.y; |
| 8945 |
cmd->w = (unsigned short)NK_MAX(r.w, 0); |
| 8946 |
cmd->h = (unsigned short)NK_MAX(r.h, 0); |
| 8947 |
cmd->color = c; |
| 8948 |
} |
| 8949 |
NK_API void |
| 8950 |
nk_fill_circle(struct nk_command_buffer *b, struct nk_rect r, struct nk_color c) |
| 8951 |
{ |
| 8952 |
struct nk_command_circle_filled *cmd; |
| 8953 |
NK_ASSERT(b); |
| 8954 |
if (!b || c.a == 0 || r.w == 0 || r.h == 0) return; |
| 8955 |
if (b->use_clipping) { |
| 8956 |
const struct nk_rect *clip = &b->clip; |
| 8957 |
if (!NK_INTERSECT(r.x, r.y, r.w, r.h, clip->x, clip->y, clip->w, clip->h)) |
| 8958 |
return; |
| 8959 |
} |
| 8960 |
|
| 8961 |
cmd = (struct nk_command_circle_filled*) |
| 8962 |
nk_command_buffer_push(b, NK_COMMAND_CIRCLE_FILLED, sizeof(*cmd)); |
| 8963 |
if (!cmd) return; |
| 8964 |
cmd->x = (short)r.x; |
| 8965 |
cmd->y = (short)r.y; |
| 8966 |
cmd->w = (unsigned short)NK_MAX(r.w, 0); |
| 8967 |
cmd->h = (unsigned short)NK_MAX(r.h, 0); |
| 8968 |
cmd->color = c; |
| 8969 |
} |
| 8970 |
NK_API void |
| 8971 |
nk_stroke_arc(struct nk_command_buffer *b, float cx, float cy, float radius, |
| 8972 |
float a_min, float a_max, float line_thickness, struct nk_color c) |
| 8973 |
{ |
| 8974 |
struct nk_command_arc *cmd; |
| 8975 |
if (!b || c.a == 0 || line_thickness <= 0) return; |
| 8976 |
cmd = (struct nk_command_arc*) |
| 8977 |
nk_command_buffer_push(b, NK_COMMAND_ARC, sizeof(*cmd)); |
| 8978 |
if (!cmd) return; |
| 8979 |
cmd->line_thickness = (unsigned short)line_thickness; |
| 8980 |
cmd->cx = (short)cx; |
| 8981 |
cmd->cy = (short)cy; |
| 8982 |
cmd->r = (unsigned short)radius; |
| 8983 |
cmd->a[0] = a_min; |
| 8984 |
cmd->a[1] = a_max; |
| 8985 |
cmd->color = c; |
| 8986 |
} |
| 8987 |
NK_API void |
| 8988 |
nk_fill_arc(struct nk_command_buffer *b, float cx, float cy, float radius, |
| 8989 |
float a_min, float a_max, struct nk_color c) |
| 8990 |
{ |
| 8991 |
struct nk_command_arc_filled *cmd; |
| 8992 |
NK_ASSERT(b); |
| 8993 |
if (!b || c.a == 0) return; |
| 8994 |
cmd = (struct nk_command_arc_filled*) |
| 8995 |
nk_command_buffer_push(b, NK_COMMAND_ARC_FILLED, sizeof(*cmd)); |
| 8996 |
if (!cmd) return; |
| 8997 |
cmd->cx = (short)cx; |
| 8998 |
cmd->cy = (short)cy; |
| 8999 |
cmd->r = (unsigned short)radius; |
| 9000 |
cmd->a[0] = a_min; |
| 9001 |
cmd->a[1] = a_max; |
| 9002 |
cmd->color = c; |
| 9003 |
} |
| 9004 |
NK_API void |
| 9005 |
nk_stroke_triangle(struct nk_command_buffer *b, float x0, float y0, float x1, |
| 9006 |
float y1, float x2, float y2, float line_thickness, struct nk_color c) |
| 9007 |
{ |
| 9008 |
struct nk_command_triangle *cmd; |
| 9009 |
NK_ASSERT(b); |
| 9010 |
if (!b || c.a == 0 || line_thickness <= 0) return; |
| 9011 |
if (b->use_clipping) { |
| 9012 |
const struct nk_rect *clip = &b->clip; |
| 9013 |
if (!NK_INBOX(x0, y0, clip->x, clip->y, clip->w, clip->h) && |
| 9014 |
!NK_INBOX(x1, y1, clip->x, clip->y, clip->w, clip->h) && |
| 9015 |
!NK_INBOX(x2, y2, clip->x, clip->y, clip->w, clip->h)) |
| 9016 |
return; |
| 9017 |
} |
| 9018 |
|
| 9019 |
cmd = (struct nk_command_triangle*) |
| 9020 |
nk_command_buffer_push(b, NK_COMMAND_TRIANGLE, sizeof(*cmd)); |
| 9021 |
if (!cmd) return; |
| 9022 |
cmd->line_thickness = (unsigned short)line_thickness; |
| 9023 |
cmd->a.x = (short)x0; |
| 9024 |
cmd->a.y = (short)y0; |
| 9025 |
cmd->b.x = (short)x1; |
| 9026 |
cmd->b.y = (short)y1; |
| 9027 |
cmd->c.x = (short)x2; |
| 9028 |
cmd->c.y = (short)y2; |
| 9029 |
cmd->color = c; |
| 9030 |
} |
| 9031 |
NK_API void |
| 9032 |
nk_fill_triangle(struct nk_command_buffer *b, float x0, float y0, float x1, |
| 9033 |
float y1, float x2, float y2, struct nk_color c) |
| 9034 |
{ |
| 9035 |
struct nk_command_triangle_filled *cmd; |
| 9036 |
NK_ASSERT(b); |
| 9037 |
if (!b || c.a == 0) return; |
| 9038 |
if (!b) return; |
| 9039 |
if (b->use_clipping) { |
| 9040 |
const struct nk_rect *clip = &b->clip; |
| 9041 |
if (!NK_INBOX(x0, y0, clip->x, clip->y, clip->w, clip->h) && |
| 9042 |
!NK_INBOX(x1, y1, clip->x, clip->y, clip->w, clip->h) && |
| 9043 |
!NK_INBOX(x2, y2, clip->x, clip->y, clip->w, clip->h)) |
| 9044 |
return; |
| 9045 |
} |
| 9046 |
|
| 9047 |
cmd = (struct nk_command_triangle_filled*) |
| 9048 |
nk_command_buffer_push(b, NK_COMMAND_TRIANGLE_FILLED, sizeof(*cmd)); |
| 9049 |
if (!cmd) return; |
| 9050 |
cmd->a.x = (short)x0; |
| 9051 |
cmd->a.y = (short)y0; |
| 9052 |
cmd->b.x = (short)x1; |
| 9053 |
cmd->b.y = (short)y1; |
| 9054 |
cmd->c.x = (short)x2; |
| 9055 |
cmd->c.y = (short)y2; |
| 9056 |
cmd->color = c; |
| 9057 |
} |
| 9058 |
NK_API void |
| 9059 |
nk_stroke_polygon(struct nk_command_buffer *b, float *points, int point_count, |
| 9060 |
float line_thickness, struct nk_color col) |
| 9061 |
{ |
| 9062 |
int i; |
| 9063 |
nk_size size = 0; |
| 9064 |
struct nk_command_polygon *cmd; |
| 9065 |
|
| 9066 |
NK_ASSERT(b); |
| 9067 |
if (!b || col.a == 0 || line_thickness <= 0) return; |
| 9068 |
size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count; |
| 9069 |
cmd = (struct nk_command_polygon*) nk_command_buffer_push(b, NK_COMMAND_POLYGON, size); |
| 9070 |
if (!cmd) return; |
| 9071 |
cmd->color = col; |
| 9072 |
cmd->line_thickness = (unsigned short)line_thickness; |
| 9073 |
cmd->point_count = (unsigned short)point_count; |
| 9074 |
for (i = 0; i < point_count; ++i) { |
| 9075 |
cmd->points[i].x = (short)points[i*2]; |
| 9076 |
cmd->points[i].y = (short)points[i*2+1]; |
| 9077 |
} |
| 9078 |
} |
| 9079 |
NK_API void |
| 9080 |
nk_fill_polygon(struct nk_command_buffer *b, float *points, int point_count, |
| 9081 |
struct nk_color col) |
| 9082 |
{ |
| 9083 |
int i; |
| 9084 |
nk_size size = 0; |
| 9085 |
struct nk_command_polygon_filled *cmd; |
| 9086 |
|
| 9087 |
NK_ASSERT(b); |
| 9088 |
if (!b || col.a == 0) return; |
| 9089 |
size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count; |
| 9090 |
cmd = (struct nk_command_polygon_filled*) |
| 9091 |
nk_command_buffer_push(b, NK_COMMAND_POLYGON_FILLED, size); |
| 9092 |
if (!cmd) return; |
| 9093 |
cmd->color = col; |
| 9094 |
cmd->point_count = (unsigned short)point_count; |
| 9095 |
for (i = 0; i < point_count; ++i) { |
| 9096 |
cmd->points[i].x = (short)points[i*2+0]; |
| 9097 |
cmd->points[i].y = (short)points[i*2+1]; |
| 9098 |
} |
| 9099 |
} |
| 9100 |
NK_API void |
| 9101 |
nk_stroke_polyline(struct nk_command_buffer *b, float *points, int point_count, |
| 9102 |
float line_thickness, struct nk_color col) |
| 9103 |
{ |
| 9104 |
int i; |
| 9105 |
nk_size size = 0; |
| 9106 |
struct nk_command_polyline *cmd; |
| 9107 |
|
| 9108 |
NK_ASSERT(b); |
| 9109 |
if (!b || col.a == 0 || line_thickness <= 0) return; |
| 9110 |
size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count; |
| 9111 |
cmd = (struct nk_command_polyline*) nk_command_buffer_push(b, NK_COMMAND_POLYLINE, size); |
| 9112 |
if (!cmd) return; |
| 9113 |
cmd->color = col; |
| 9114 |
cmd->point_count = (unsigned short)point_count; |
| 9115 |
cmd->line_thickness = (unsigned short)line_thickness; |
| 9116 |
for (i = 0; i < point_count; ++i) { |
| 9117 |
cmd->points[i].x = (short)points[i*2]; |
| 9118 |
cmd->points[i].y = (short)points[i*2+1]; |
| 9119 |
} |
| 9120 |
} |
| 9121 |
NK_API void |
| 9122 |
nk_draw_image(struct nk_command_buffer *b, struct nk_rect r, |
| 9123 |
const struct nk_image *img, struct nk_color col) |
| 9124 |
{ |
| 9125 |
struct nk_command_image *cmd; |
| 9126 |
NK_ASSERT(b); |
| 9127 |
if (!b) return; |
| 9128 |
if (b->use_clipping) { |
| 9129 |
const struct nk_rect *c = &b->clip; |
| 9130 |
if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h)) |
| 9131 |
return; |
| 9132 |
} |
| 9133 |
|
| 9134 |
cmd = (struct nk_command_image*) |
| 9135 |
nk_command_buffer_push(b, NK_COMMAND_IMAGE, sizeof(*cmd)); |
| 9136 |
if (!cmd) return; |
| 9137 |
cmd->x = (short)r.x; |
| 9138 |
cmd->y = (short)r.y; |
| 9139 |
cmd->w = (unsigned short)NK_MAX(0, r.w); |
| 9140 |
cmd->h = (unsigned short)NK_MAX(0, r.h); |
| 9141 |
cmd->img = *img; |
| 9142 |
cmd->col = col; |
| 9143 |
} |
| 9144 |
NK_API void |
| 9145 |
nk_push_custom(struct nk_command_buffer *b, struct nk_rect r, |
| 9146 |
nk_command_custom_callback cb, nk_handle usr) |
| 9147 |
{ |
| 9148 |
struct nk_command_custom *cmd; |
| 9149 |
NK_ASSERT(b); |
| 9150 |
if (!b) return; |
| 9151 |
if (b->use_clipping) { |
| 9152 |
const struct nk_rect *c = &b->clip; |
| 9153 |
if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h)) |
| 9154 |
return; |
| 9155 |
} |
| 9156 |
|
| 9157 |
cmd = (struct nk_command_custom*) |
| 9158 |
nk_command_buffer_push(b, NK_COMMAND_CUSTOM, sizeof(*cmd)); |
| 9159 |
if (!cmd) return; |
| 9160 |
cmd->x = (short)r.x; |
| 9161 |
cmd->y = (short)r.y; |
| 9162 |
cmd->w = (unsigned short)NK_MAX(0, r.w); |
| 9163 |
cmd->h = (unsigned short)NK_MAX(0, r.h); |
| 9164 |
cmd->callback_data = usr; |
| 9165 |
cmd->callback = cb; |
| 9166 |
} |
| 9167 |
NK_API void |
| 9168 |
nk_draw_text(struct nk_command_buffer *b, struct nk_rect r, |
| 9169 |
const char *string, int length, const struct nk_user_font *font, |
| 9170 |
struct nk_color bg, struct nk_color fg) |
| 9171 |
{ |
| 9172 |
float text_width = 0; |
| 9173 |
struct nk_command_text *cmd; |
| 9174 |
|
| 9175 |
NK_ASSERT(b); |
| 9176 |
NK_ASSERT(font); |
| 9177 |
if (!b || !string || !length || (bg.a == 0 && fg.a == 0)) return; |
| 9178 |
if (b->use_clipping) { |
| 9179 |
const struct nk_rect *c = &b->clip; |
| 9180 |
if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h)) |
| 9181 |
return; |
| 9182 |
} |
| 9183 |
|
| 9184 |
|
| 9185 |
text_width = font->width(font->userdata, font->height, string, length); |
| 9186 |
if (text_width > r.w){ |
| 9187 |
int glyphs = 0; |
| 9188 |
float txt_width = (float)text_width; |
| 9189 |
length = nk_text_clamp(font, string, length, r.w, &glyphs, &txt_width, 0,0); |
| 9190 |
} |
| 9191 |
|
| 9192 |
if (!length) return; |
| 9193 |
cmd = (struct nk_command_text*) |
| 9194 |
nk_command_buffer_push(b, NK_COMMAND_TEXT, sizeof(*cmd) + (nk_size)(length + 1)); |
| 9195 |
if (!cmd) return; |
| 9196 |
cmd->x = (short)r.x; |
| 9197 |
cmd->y = (short)r.y; |
| 9198 |
cmd->w = (unsigned short)r.w; |
| 9199 |
cmd->h = (unsigned short)r.h; |
| 9200 |
cmd->background = bg; |
| 9201 |
cmd->foreground = fg; |
| 9202 |
cmd->font = font; |
| 9203 |
cmd->length = length; |
| 9204 |
cmd->height = font->height; |
| 9205 |
NK_MEMCPY(cmd->string, string, (nk_size)length); |
| 9206 |
cmd->string[length] = '\0'; |
| 9207 |
} |
| 9208 |
|
| 9209 |
|
| 9210 |
|
| 9211 |
|
| 9212 |
|
| 9213 |
|
| 9214 |
|
| 9215 |
|
| 9216 |
|
| 9217 |
|
| 9218 |
#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT |
| 9219 |
NK_API void |
| 9220 |
nk_draw_list_init(struct nk_draw_list *list) |
| 9221 |
{ |
| 9222 |
nk_size i = 0; |
| 9223 |
NK_ASSERT(list); |
| 9224 |
if (!list) return; |
| 9225 |
nk_zero(list, sizeof(*list)); |
| 9226 |
for (i = 0; i < NK_LEN(list->circle_vtx); ++i) { |
| 9227 |
const float a = ((float)i / (float)NK_LEN(list->circle_vtx)) * 2 * NK_PI; |
| 9228 |
list->circle_vtx[i].x = (float)NK_COS(a); |
| 9229 |
list->circle_vtx[i].y = (float)NK_SIN(a); |
| 9230 |
} |
| 9231 |
} |
| 9232 |
NK_API void |
| 9233 |
nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config *config, |
| 9234 |
struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, |
| 9235 |
enum nk_anti_aliasing line_aa, enum nk_anti_aliasing shape_aa) |
| 9236 |
{ |
| 9237 |
NK_ASSERT(canvas); |
| 9238 |
NK_ASSERT(config); |
| 9239 |
NK_ASSERT(cmds); |
| 9240 |
NK_ASSERT(vertices); |
| 9241 |
NK_ASSERT(elements); |
| 9242 |
if (!canvas || !config || !cmds || !vertices || !elements) |
| 9243 |
return; |
| 9244 |
|
| 9245 |
canvas->buffer = cmds; |
| 9246 |
canvas->config = *config; |
| 9247 |
canvas->elements = elements; |
| 9248 |
canvas->vertices = vertices; |
| 9249 |
canvas->line_AA = line_aa; |
| 9250 |
canvas->shape_AA = shape_aa; |
| 9251 |
canvas->clip_rect = nk_null_rect; |
| 9252 |
|
| 9253 |
canvas->cmd_offset = 0; |
| 9254 |
canvas->element_count = 0; |
| 9255 |
canvas->vertex_count = 0; |
| 9256 |
canvas->cmd_offset = 0; |
| 9257 |
canvas->cmd_count = 0; |
| 9258 |
canvas->path_count = 0; |
| 9259 |
} |
| 9260 |
NK_API const struct nk_draw_command* |
| 9261 |
nk__draw_list_begin(const struct nk_draw_list *canvas, const struct nk_buffer *buffer) |
| 9262 |
{ |
| 9263 |
nk_byte *memory; |
| 9264 |
nk_size offset; |
| 9265 |
const struct nk_draw_command *cmd; |
| 9266 |
|
| 9267 |
NK_ASSERT(buffer); |
| 9268 |
if (!buffer || !buffer->size || !canvas->cmd_count) |
| 9269 |
return 0; |
| 9270 |
|
| 9271 |
memory = (nk_byte*)buffer->memory.ptr; |
| 9272 |
offset = buffer->memory.size - canvas->cmd_offset; |
| 9273 |
cmd = nk_ptr_add(const struct nk_draw_command, memory, offset); |
| 9274 |
return cmd; |
| 9275 |
} |
| 9276 |
NK_API const struct nk_draw_command* |
| 9277 |
nk__draw_list_end(const struct nk_draw_list *canvas, const struct nk_buffer *buffer) |
| 9278 |
{ |
| 9279 |
nk_size size; |
| 9280 |
nk_size offset; |
| 9281 |
nk_byte *memory; |
| 9282 |
const struct nk_draw_command *end; |
| 9283 |
|
| 9284 |
NK_ASSERT(buffer); |
| 9285 |
NK_ASSERT(canvas); |
| 9286 |
if (!buffer || !canvas) |
| 9287 |
return 0; |
| 9288 |
|
| 9289 |
memory = (nk_byte*)buffer->memory.ptr; |
| 9290 |
size = buffer->memory.size; |
| 9291 |
offset = size - canvas->cmd_offset; |
| 9292 |
end = nk_ptr_add(const struct nk_draw_command, memory, offset); |
| 9293 |
end -= (canvas->cmd_count-1); |
| 9294 |
return end; |
| 9295 |
} |
| 9296 |
NK_API const struct nk_draw_command* |
| 9297 |
nk__draw_list_next(const struct nk_draw_command *cmd, |
| 9298 |
const struct nk_buffer *buffer, const struct nk_draw_list *canvas) |
| 9299 |
{ |
| 9300 |
const struct nk_draw_command *end; |
| 9301 |
NK_ASSERT(buffer); |
| 9302 |
NK_ASSERT(canvas); |
| 9303 |
if (!cmd || !buffer || !canvas) |
| 9304 |
return 0; |
| 9305 |
|
| 9306 |
end = nk__draw_list_end(canvas, buffer); |
| 9307 |
if (cmd <= end) return 0; |
| 9308 |
return (cmd-1); |
| 9309 |
} |
| 9310 |
NK_INTERN struct nk_vec2* |
| 9311 |
nk_draw_list_alloc_path(struct nk_draw_list *list, int count) |
| 9312 |
{ |
| 9313 |
struct nk_vec2 *points; |
| 9314 |
NK_STORAGE const nk_size point_align = NK_ALIGNOF(struct nk_vec2); |
| 9315 |
NK_STORAGE const nk_size point_size = sizeof(struct nk_vec2); |
| 9316 |
points = (struct nk_vec2*) |
| 9317 |
nk_buffer_alloc(list->buffer, NK_BUFFER_FRONT, |
| 9318 |
point_size * (nk_size)count, point_align); |
| 9319 |
|
| 9320 |
if (!points) return 0; |
| 9321 |
if (!list->path_offset) { |
| 9322 |
void *memory = nk_buffer_memory(list->buffer); |
| 9323 |
list->path_offset = (unsigned int)((nk_byte*)points - (nk_byte*)memory); |
| 9324 |
} |
| 9325 |
list->path_count += (unsigned int)count; |
| 9326 |
return points; |
| 9327 |
} |
| 9328 |
NK_INTERN struct nk_vec2 |
| 9329 |
nk_draw_list_path_last(struct nk_draw_list *list) |
| 9330 |
{ |
| 9331 |
void *memory; |
| 9332 |
struct nk_vec2 *point; |
| 9333 |
NK_ASSERT(list->path_count); |
| 9334 |
memory = nk_buffer_memory(list->buffer); |
| 9335 |
point = nk_ptr_add(struct nk_vec2, memory, list->path_offset); |
| 9336 |
point += (list->path_count-1); |
| 9337 |
return *point; |
| 9338 |
} |
| 9339 |
NK_INTERN struct nk_draw_command* |
| 9340 |
nk_draw_list_push_command(struct nk_draw_list *list, struct nk_rect clip, |
| 9341 |
nk_handle texture) |
| 9342 |
{ |
| 9343 |
NK_STORAGE const nk_size cmd_align = NK_ALIGNOF(struct nk_draw_command); |
| 9344 |
NK_STORAGE const nk_size cmd_size = sizeof(struct nk_draw_command); |
| 9345 |
struct nk_draw_command *cmd; |
| 9346 |
|
| 9347 |
NK_ASSERT(list); |
| 9348 |
cmd = (struct nk_draw_command*) |
| 9349 |
nk_buffer_alloc(list->buffer, NK_BUFFER_BACK, cmd_size, cmd_align); |
| 9350 |
|
| 9351 |
if (!cmd) return 0; |
| 9352 |
if (!list->cmd_count) { |
| 9353 |
nk_byte *memory = (nk_byte*)nk_buffer_memory(list->buffer); |
| 9354 |
nk_size total = nk_buffer_total(list->buffer); |
| 9355 |
memory = nk_ptr_add(nk_byte, memory, total); |
| 9356 |
list->cmd_offset = (nk_size)(memory - (nk_byte*)cmd); |
| 9357 |
} |
| 9358 |
|
| 9359 |
cmd->elem_count = 0; |
| 9360 |
cmd->clip_rect = clip; |
| 9361 |
cmd->texture = texture; |
| 9362 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 9363 |
cmd->userdata = list->userdata; |
| 9364 |
#endif |
| 9365 |
|
| 9366 |
list->cmd_count++; |
| 9367 |
list->clip_rect = clip; |
| 9368 |
return cmd; |
| 9369 |
} |
| 9370 |
NK_INTERN struct nk_draw_command* |
| 9371 |
nk_draw_list_command_last(struct nk_draw_list *list) |
| 9372 |
{ |
| 9373 |
void *memory; |
| 9374 |
nk_size size; |
| 9375 |
struct nk_draw_command *cmd; |
| 9376 |
NK_ASSERT(list->cmd_count); |
| 9377 |
|
| 9378 |
memory = nk_buffer_memory(list->buffer); |
| 9379 |
size = nk_buffer_total(list->buffer); |
| 9380 |
cmd = nk_ptr_add(struct nk_draw_command, memory, size - list->cmd_offset); |
| 9381 |
return (cmd - (list->cmd_count-1)); |
| 9382 |
} |
| 9383 |
NK_INTERN void |
| 9384 |
nk_draw_list_add_clip(struct nk_draw_list *list, struct nk_rect rect) |
| 9385 |
{ |
| 9386 |
NK_ASSERT(list); |
| 9387 |
if (!list) return; |
| 9388 |
if (!list->cmd_count) { |
| 9389 |
nk_draw_list_push_command(list, rect, list->config.null.texture); |
| 9390 |
} else { |
| 9391 |
struct nk_draw_command *prev = nk_draw_list_command_last(list); |
| 9392 |
if (prev->elem_count == 0) |
| 9393 |
prev->clip_rect = rect; |
| 9394 |
nk_draw_list_push_command(list, rect, prev->texture); |
| 9395 |
} |
| 9396 |
} |
| 9397 |
NK_INTERN void |
| 9398 |
nk_draw_list_push_image(struct nk_draw_list *list, nk_handle texture) |
| 9399 |
{ |
| 9400 |
NK_ASSERT(list); |
| 9401 |
if (!list) return; |
| 9402 |
if (!list->cmd_count) { |
| 9403 |
nk_draw_list_push_command(list, nk_null_rect, texture); |
| 9404 |
} else { |
| 9405 |
struct nk_draw_command *prev = nk_draw_list_command_last(list); |
| 9406 |
if (prev->elem_count == 0) { |
| 9407 |
prev->texture = texture; |
| 9408 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 9409 |
prev->userdata = list->userdata; |
| 9410 |
#endif |
| 9411 |
} else if (prev->texture.id != texture.id |
| 9412 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 9413 |
|| prev->userdata.id != list->userdata.id |
| 9414 |
#endif |
| 9415 |
) nk_draw_list_push_command(list, prev->clip_rect, texture); |
| 9416 |
} |
| 9417 |
} |
| 9418 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 9419 |
NK_API void |
| 9420 |
nk_draw_list_push_userdata(struct nk_draw_list *list, nk_handle userdata) |
| 9421 |
{ |
| 9422 |
list->userdata = userdata; |
| 9423 |
} |
| 9424 |
#endif |
| 9425 |
NK_INTERN void* |
| 9426 |
nk_draw_list_alloc_vertices(struct nk_draw_list *list, nk_size count) |
| 9427 |
{ |
| 9428 |
void *vtx; |
| 9429 |
NK_ASSERT(list); |
| 9430 |
if (!list) return 0; |
| 9431 |
vtx = nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, |
| 9432 |
list->config.vertex_size*count, list->config.vertex_alignment); |
| 9433 |
if (!vtx) return 0; |
| 9434 |
list->vertex_count += (unsigned int)count; |
| 9435 |
|
| 9436 |
|
| 9437 |
|
| 9438 |
|
| 9439 |
|
| 9440 |
|
| 9441 |
|
| 9442 |
|
| 9443 |
|
| 9444 |
|
| 9445 |
if(sizeof(nk_draw_index)==2) NK_ASSERT((list->vertex_count < NK_USHORT_MAX && |
| 9446 |
"To many verticies for 16-bit vertex indicies. Please read comment above on how to solve this problem")); |
| 9447 |
return vtx; |
| 9448 |
} |
| 9449 |
NK_INTERN nk_draw_index* |
| 9450 |
nk_draw_list_alloc_elements(struct nk_draw_list *list, nk_size count) |
| 9451 |
{ |
| 9452 |
nk_draw_index *ids; |
| 9453 |
struct nk_draw_command *cmd; |
| 9454 |
NK_STORAGE const nk_size elem_align = NK_ALIGNOF(nk_draw_index); |
| 9455 |
NK_STORAGE const nk_size elem_size = sizeof(nk_draw_index); |
| 9456 |
NK_ASSERT(list); |
| 9457 |
if (!list) return 0; |
| 9458 |
|
| 9459 |
ids = (nk_draw_index*) |
| 9460 |
nk_buffer_alloc(list->elements, NK_BUFFER_FRONT, elem_size*count, elem_align); |
| 9461 |
if (!ids) return 0; |
| 9462 |
cmd = nk_draw_list_command_last(list); |
| 9463 |
list->element_count += (unsigned int)count; |
| 9464 |
cmd->elem_count += (unsigned int)count; |
| 9465 |
return ids; |
| 9466 |
} |
| 9467 |
NK_INTERN int |
| 9468 |
nk_draw_vertex_layout_element_is_end_of_layout( |
| 9469 |
const struct nk_draw_vertex_layout_element *element) |
| 9470 |
{ |
| 9471 |
return (element->attribute == NK_VERTEX_ATTRIBUTE_COUNT || |
| 9472 |
element->format == NK_FORMAT_COUNT); |
| 9473 |
} |
| 9474 |
NK_INTERN void |
| 9475 |
nk_draw_vertex_color(void *attr, const float *vals, |
| 9476 |
enum nk_draw_vertex_layout_format format) |
| 9477 |
{ |
| 9478 |
|
| 9479 |
float val[4]; |
| 9480 |
NK_ASSERT(format >= NK_FORMAT_COLOR_BEGIN); |
| 9481 |
NK_ASSERT(format <= NK_FORMAT_COLOR_END); |
| 9482 |
if (format < NK_FORMAT_COLOR_BEGIN || format > NK_FORMAT_COLOR_END) return; |
| 9483 |
|
| 9484 |
val[0] = NK_SATURATE(vals[0]); |
| 9485 |
val[1] = NK_SATURATE(vals[1]); |
| 9486 |
val[2] = NK_SATURATE(vals[2]); |
| 9487 |
val[3] = NK_SATURATE(vals[3]); |
| 9488 |
|
| 9489 |
switch (format) { |
| 9490 |
default: NK_ASSERT(0 && "Invalid vertex layout color format"); break; |
| 9491 |
case NK_FORMAT_R8G8B8A8: |
| 9492 |
case NK_FORMAT_R8G8B8: { |
| 9493 |
struct nk_color col = nk_rgba_fv(val); |
| 9494 |
NK_MEMCPY(attr, &col.r, sizeof(col)); |
| 9495 |
} break; |
| 9496 |
case NK_FORMAT_B8G8R8A8: { |
| 9497 |
struct nk_color col = nk_rgba_fv(val); |
| 9498 |
struct nk_color bgra = nk_rgba(col.b, col.g, col.r, col.a); |
| 9499 |
NK_MEMCPY(attr, &bgra, sizeof(bgra)); |
| 9500 |
} break; |
| 9501 |
case NK_FORMAT_R16G15B16: { |
| 9502 |
nk_ushort col[3]; |
| 9503 |
col[0] = (nk_ushort)(val[0]*(float)NK_USHORT_MAX); |
| 9504 |
col[1] = (nk_ushort)(val[1]*(float)NK_USHORT_MAX); |
| 9505 |
col[2] = (nk_ushort)(val[2]*(float)NK_USHORT_MAX); |
| 9506 |
NK_MEMCPY(attr, col, sizeof(col)); |
| 9507 |
} break; |
| 9508 |
case NK_FORMAT_R16G15B16A16: { |
| 9509 |
nk_ushort col[4]; |
| 9510 |
col[0] = (nk_ushort)(val[0]*(float)NK_USHORT_MAX); |
| 9511 |
col[1] = (nk_ushort)(val[1]*(float)NK_USHORT_MAX); |
| 9512 |
col[2] = (nk_ushort)(val[2]*(float)NK_USHORT_MAX); |
| 9513 |
col[3] = (nk_ushort)(val[3]*(float)NK_USHORT_MAX); |
| 9514 |
NK_MEMCPY(attr, col, sizeof(col)); |
| 9515 |
} break; |
| 9516 |
case NK_FORMAT_R32G32B32: { |
| 9517 |
nk_uint col[3]; |
| 9518 |
col[0] = (nk_uint)(val[0]*(float)NK_UINT_MAX); |
| 9519 |
col[1] = (nk_uint)(val[1]*(float)NK_UINT_MAX); |
| 9520 |
col[2] = (nk_uint)(val[2]*(float)NK_UINT_MAX); |
| 9521 |
NK_MEMCPY(attr, col, sizeof(col)); |
| 9522 |
} break; |
| 9523 |
case NK_FORMAT_R32G32B32A32: { |
| 9524 |
nk_uint col[4]; |
| 9525 |
col[0] = (nk_uint)(val[0]*(float)NK_UINT_MAX); |
| 9526 |
col[1] = (nk_uint)(val[1]*(float)NK_UINT_MAX); |
| 9527 |
col[2] = (nk_uint)(val[2]*(float)NK_UINT_MAX); |
| 9528 |
col[3] = (nk_uint)(val[3]*(float)NK_UINT_MAX); |
| 9529 |
NK_MEMCPY(attr, col, sizeof(col)); |
| 9530 |
} break; |
| 9531 |
case NK_FORMAT_R32G32B32A32_FLOAT: |
| 9532 |
NK_MEMCPY(attr, val, sizeof(float)*4); |
| 9533 |
break; |
| 9534 |
case NK_FORMAT_R32G32B32A32_DOUBLE: { |
| 9535 |
double col[4]; |
| 9536 |
col[0] = (double)val[0]; |
| 9537 |
col[1] = (double)val[1]; |
| 9538 |
col[2] = (double)val[2]; |
| 9539 |
col[3] = (double)val[3]; |
| 9540 |
NK_MEMCPY(attr, col, sizeof(col)); |
| 9541 |
} break; |
| 9542 |
case NK_FORMAT_RGB32: |
| 9543 |
case NK_FORMAT_RGBA32: { |
| 9544 |
struct nk_color col = nk_rgba_fv(val); |
| 9545 |
nk_uint color = nk_color_u32(col); |
| 9546 |
NK_MEMCPY(attr, &color, sizeof(color)); |
| 9547 |
} break; } |
| 9548 |
} |
| 9549 |
NK_INTERN void |
| 9550 |
nk_draw_vertex_element(void *dst, const float *values, int value_count, |
| 9551 |
enum nk_draw_vertex_layout_format format) |
| 9552 |
{ |
| 9553 |
int value_index; |
| 9554 |
void *attribute = dst; |
| 9555 |
|
| 9556 |
NK_ASSERT(format < NK_FORMAT_COLOR_BEGIN); |
| 9557 |
if (format >= NK_FORMAT_COLOR_BEGIN && format <= NK_FORMAT_COLOR_END) return; |
| 9558 |
for (value_index = 0; value_index < value_count; ++value_index) { |
| 9559 |
switch (format) { |
| 9560 |
default: NK_ASSERT(0 && "invalid vertex layout format"); break; |
| 9561 |
case NK_FORMAT_SCHAR: { |
| 9562 |
char value = (char)NK_CLAMP((float)NK_SCHAR_MIN, values[value_index], (float)NK_SCHAR_MAX); |
| 9563 |
NK_MEMCPY(attribute, &value, sizeof(value)); |
| 9564 |
attribute = (void*)((char*)attribute + sizeof(char)); |
| 9565 |
} break; |
| 9566 |
case NK_FORMAT_SSHORT: { |
| 9567 |
nk_short value = (nk_short)NK_CLAMP((float)NK_SSHORT_MIN, values[value_index], (float)NK_SSHORT_MAX); |
| 9568 |
NK_MEMCPY(attribute, &value, sizeof(value)); |
| 9569 |
attribute = (void*)((char*)attribute + sizeof(value)); |
| 9570 |
} break; |
| 9571 |
case NK_FORMAT_SINT: { |
| 9572 |
nk_int value = (nk_int)NK_CLAMP((float)NK_SINT_MIN, values[value_index], (float)NK_SINT_MAX); |
| 9573 |
NK_MEMCPY(attribute, &value, sizeof(value)); |
| 9574 |
attribute = (void*)((char*)attribute + sizeof(nk_int)); |
| 9575 |
} break; |
| 9576 |
case NK_FORMAT_UCHAR: { |
| 9577 |
unsigned char value = (unsigned char)NK_CLAMP((float)NK_UCHAR_MIN, values[value_index], (float)NK_UCHAR_MAX); |
| 9578 |
NK_MEMCPY(attribute, &value, sizeof(value)); |
| 9579 |
attribute = (void*)((char*)attribute + sizeof(unsigned char)); |
| 9580 |
} break; |
| 9581 |
case NK_FORMAT_USHORT: { |
| 9582 |
nk_ushort value = (nk_ushort)NK_CLAMP((float)NK_USHORT_MIN, values[value_index], (float)NK_USHORT_MAX); |
| 9583 |
NK_MEMCPY(attribute, &value, sizeof(value)); |
| 9584 |
attribute = (void*)((char*)attribute + sizeof(value)); |
| 9585 |
} break; |
| 9586 |
case NK_FORMAT_UINT: { |
| 9587 |
nk_uint value = (nk_uint)NK_CLAMP((float)NK_UINT_MIN, values[value_index], (float)NK_UINT_MAX); |
| 9588 |
NK_MEMCPY(attribute, &value, sizeof(value)); |
| 9589 |
attribute = (void*)((char*)attribute + sizeof(nk_uint)); |
| 9590 |
} break; |
| 9591 |
case NK_FORMAT_FLOAT: |
| 9592 |
NK_MEMCPY(attribute, &values[value_index], sizeof(values[value_index])); |
| 9593 |
attribute = (void*)((char*)attribute + sizeof(float)); |
| 9594 |
break; |
| 9595 |
case NK_FORMAT_DOUBLE: { |
| 9596 |
double value = (double)values[value_index]; |
| 9597 |
NK_MEMCPY(attribute, &value, sizeof(value)); |
| 9598 |
attribute = (void*)((char*)attribute + sizeof(double)); |
| 9599 |
} break; |
| 9600 |
} |
| 9601 |
} |
| 9602 |
} |
| 9603 |
NK_INTERN void* |
| 9604 |
nk_draw_vertex(void *dst, const struct nk_convert_config *config, |
| 9605 |
struct nk_vec2 pos, struct nk_vec2 uv, struct nk_colorf color) |
| 9606 |
{ |
| 9607 |
void *result = (void*)((char*)dst + config->vertex_size); |
| 9608 |
const struct nk_draw_vertex_layout_element *elem_iter = config->vertex_layout; |
| 9609 |
while (!nk_draw_vertex_layout_element_is_end_of_layout(elem_iter)) { |
| 9610 |
void *address = (void*)((char*)dst + elem_iter->offset); |
| 9611 |
switch (elem_iter->attribute) { |
| 9612 |
case NK_VERTEX_ATTRIBUTE_COUNT: |
| 9613 |
default: NK_ASSERT(0 && "wrong element attribute"); break; |
| 9614 |
case NK_VERTEX_POSITION: nk_draw_vertex_element(address, &pos.x, 2, elem_iter->format); break; |
| 9615 |
case NK_VERTEX_TEXCOORD: nk_draw_vertex_element(address, &uv.x, 2, elem_iter->format); break; |
| 9616 |
case NK_VERTEX_COLOR: nk_draw_vertex_color(address, &color.r, elem_iter->format); break; |
| 9617 |
} |
| 9618 |
elem_iter++; |
| 9619 |
} |
| 9620 |
return result; |
| 9621 |
} |
| 9622 |
NK_API void |
| 9623 |
nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *points, |
| 9624 |
const unsigned int points_count, struct nk_color color, enum nk_draw_list_stroke closed, |
| 9625 |
float thickness, enum nk_anti_aliasing aliasing) |
| 9626 |
{ |
| 9627 |
nk_size count; |
| 9628 |
int thick_line; |
| 9629 |
struct nk_colorf col; |
| 9630 |
struct nk_colorf col_trans; |
| 9631 |
NK_ASSERT(list); |
| 9632 |
if (!list || points_count < 2) return; |
| 9633 |
|
| 9634 |
color.a = (nk_byte)((float)color.a * list->config.global_alpha); |
| 9635 |
count = points_count; |
| 9636 |
if (!closed) count = points_count-1; |
| 9637 |
thick_line = thickness > 1.0f; |
| 9638 |
|
| 9639 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 9640 |
nk_draw_list_push_userdata(list, list->userdata); |
| 9641 |
#endif |
| 9642 |
|
| 9643 |
color.a = (nk_byte)((float)color.a * list->config.global_alpha); |
| 9644 |
nk_color_fv(&col.r, color); |
| 9645 |
col_trans = col; |
| 9646 |
col_trans.a = 0; |
| 9647 |
|
| 9648 |
if (aliasing == NK_ANTI_ALIASING_ON) { |
| 9649 |
|
| 9650 |
const float AA_SIZE = 1.0f; |
| 9651 |
NK_STORAGE const nk_size pnt_align = NK_ALIGNOF(struct nk_vec2); |
| 9652 |
NK_STORAGE const nk_size pnt_size = sizeof(struct nk_vec2); |
| 9653 |
|
| 9654 |
|
| 9655 |
nk_size i1 = 0; |
| 9656 |
nk_size vertex_offset; |
| 9657 |
nk_size index = list->vertex_count; |
| 9658 |
|
| 9659 |
const nk_size idx_count = (thick_line) ? (count * 18) : (count * 12); |
| 9660 |
const nk_size vtx_count = (thick_line) ? (points_count * 4): (points_count *3); |
| 9661 |
|
| 9662 |
void *vtx = nk_draw_list_alloc_vertices(list, vtx_count); |
| 9663 |
nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count); |
| 9664 |
|
| 9665 |
nk_size size; |
| 9666 |
struct nk_vec2 *normals, *temp; |
| 9667 |
if (!vtx || !ids) return; |
| 9668 |
|
| 9669 |
|
| 9670 |
vertex_offset = (nk_size)((nk_byte*)vtx - (nk_byte*)list->vertices->memory.ptr); |
| 9671 |
nk_buffer_mark(list->vertices, NK_BUFFER_FRONT); |
| 9672 |
size = pnt_size * ((thick_line) ? 5 : 3) * points_count; |
| 9673 |
normals = (struct nk_vec2*) nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align); |
| 9674 |
if (!normals) return; |
| 9675 |
temp = normals + points_count; |
| 9676 |
|
| 9677 |
|
| 9678 |
vtx = (void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset); |
| 9679 |
|
| 9680 |
|
| 9681 |
for (i1 = 0; i1 < count; ++i1) { |
| 9682 |
const nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1); |
| 9683 |
struct nk_vec2 diff = nk_vec2_sub(points[i2], points[i1]); |
| 9684 |
float len; |
| 9685 |
|
| 9686 |
|
| 9687 |
len = nk_vec2_len_sqr(diff); |
| 9688 |
if (len != 0.0f) |
| 9689 |
len = nk_inv_sqrt(len); |
| 9690 |
else len = 1.0f; |
| 9691 |
|
| 9692 |
diff = nk_vec2_muls(diff, len); |
| 9693 |
normals[i1].x = diff.y; |
| 9694 |
normals[i1].y = -diff.x; |
| 9695 |
} |
| 9696 |
|
| 9697 |
if (!closed) |
| 9698 |
normals[points_count-1] = normals[points_count-2]; |
| 9699 |
|
| 9700 |
if (!thick_line) { |
| 9701 |
nk_size idx1, i; |
| 9702 |
if (!closed) { |
| 9703 |
struct nk_vec2 d; |
| 9704 |
temp[0] = nk_vec2_add(points[0], nk_vec2_muls(normals[0], AA_SIZE)); |
| 9705 |
temp[1] = nk_vec2_sub(points[0], nk_vec2_muls(normals[0], AA_SIZE)); |
| 9706 |
d = nk_vec2_muls(normals[points_count-1], AA_SIZE); |
| 9707 |
temp[(points_count-1) * 2 + 0] = nk_vec2_add(points[points_count-1], d); |
| 9708 |
temp[(points_count-1) * 2 + 1] = nk_vec2_sub(points[points_count-1], d); |
| 9709 |
} |
| 9710 |
|
| 9711 |
|
| 9712 |
idx1 = index; |
| 9713 |
for (i1 = 0; i1 < count; i1++) { |
| 9714 |
struct nk_vec2 dm; |
| 9715 |
float dmr2; |
| 9716 |
nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1); |
| 9717 |
nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 3); |
| 9718 |
|
| 9719 |
|
| 9720 |
dm = nk_vec2_muls(nk_vec2_add(normals[i1], normals[i2]), 0.5f); |
| 9721 |
dmr2 = dm.x * dm.x + dm.y* dm.y; |
| 9722 |
if (dmr2 > 0.000001f) { |
| 9723 |
float scale = 1.0f/dmr2; |
| 9724 |
scale = NK_MIN(100.0f, scale); |
| 9725 |
dm = nk_vec2_muls(dm, scale); |
| 9726 |
} |
| 9727 |
|
| 9728 |
dm = nk_vec2_muls(dm, AA_SIZE); |
| 9729 |
temp[i2*2+0] = nk_vec2_add(points[i2], dm); |
| 9730 |
temp[i2*2+1] = nk_vec2_sub(points[i2], dm); |
| 9731 |
|
| 9732 |
ids[0] = (nk_draw_index)(idx2 + 0); ids[1] = (nk_draw_index)(idx1+0); |
| 9733 |
ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2); |
| 9734 |
ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+0); |
| 9735 |
ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1); |
| 9736 |
ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0); |
| 9737 |
ids[10]= (nk_draw_index)(idx2 + 0); ids[11]= (nk_draw_index)(idx2+1); |
| 9738 |
ids += 12; |
| 9739 |
idx1 = idx2; |
| 9740 |
} |
| 9741 |
|
| 9742 |
|
| 9743 |
for (i = 0; i < points_count; ++i) { |
| 9744 |
const struct nk_vec2 uv = list->config.null.uv; |
| 9745 |
vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col); |
| 9746 |
vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans); |
| 9747 |
vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans); |
| 9748 |
} |
| 9749 |
} else { |
| 9750 |
nk_size idx1, i; |
| 9751 |
const float half_inner_thickness = (thickness - AA_SIZE) * 0.5f; |
| 9752 |
if (!closed) { |
| 9753 |
struct nk_vec2 d1 = nk_vec2_muls(normals[0], half_inner_thickness + AA_SIZE); |
| 9754 |
struct nk_vec2 d2 = nk_vec2_muls(normals[0], half_inner_thickness); |
| 9755 |
|
| 9756 |
temp[0] = nk_vec2_add(points[0], d1); |
| 9757 |
temp[1] = nk_vec2_add(points[0], d2); |
| 9758 |
temp[2] = nk_vec2_sub(points[0], d2); |
| 9759 |
temp[3] = nk_vec2_sub(points[0], d1); |
| 9760 |
|
| 9761 |
d1 = nk_vec2_muls(normals[points_count-1], half_inner_thickness + AA_SIZE); |
| 9762 |
d2 = nk_vec2_muls(normals[points_count-1], half_inner_thickness); |
| 9763 |
|
| 9764 |
temp[(points_count-1)*4+0] = nk_vec2_add(points[points_count-1], d1); |
| 9765 |
temp[(points_count-1)*4+1] = nk_vec2_add(points[points_count-1], d2); |
| 9766 |
temp[(points_count-1)*4+2] = nk_vec2_sub(points[points_count-1], d2); |
| 9767 |
temp[(points_count-1)*4+3] = nk_vec2_sub(points[points_count-1], d1); |
| 9768 |
} |
| 9769 |
|
| 9770 |
|
| 9771 |
idx1 = index; |
| 9772 |
for (i1 = 0; i1 < count; ++i1) { |
| 9773 |
struct nk_vec2 dm_out, dm_in; |
| 9774 |
const nk_size i2 = ((i1+1) == points_count) ? 0: (i1 + 1); |
| 9775 |
nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 4); |
| 9776 |
|
| 9777 |
|
| 9778 |
struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(normals[i1], normals[i2]), 0.5f); |
| 9779 |
float dmr2 = dm.x * dm.x + dm.y* dm.y; |
| 9780 |
if (dmr2 > 0.000001f) { |
| 9781 |
float scale = 1.0f/dmr2; |
| 9782 |
scale = NK_MIN(100.0f, scale); |
| 9783 |
dm = nk_vec2_muls(dm, scale); |
| 9784 |
} |
| 9785 |
|
| 9786 |
dm_out = nk_vec2_muls(dm, ((half_inner_thickness) + AA_SIZE)); |
| 9787 |
dm_in = nk_vec2_muls(dm, half_inner_thickness); |
| 9788 |
temp[i2*4+0] = nk_vec2_add(points[i2], dm_out); |
| 9789 |
temp[i2*4+1] = nk_vec2_add(points[i2], dm_in); |
| 9790 |
temp[i2*4+2] = nk_vec2_sub(points[i2], dm_in); |
| 9791 |
temp[i2*4+3] = nk_vec2_sub(points[i2], dm_out); |
| 9792 |
|
| 9793 |
|
| 9794 |
ids[0] = (nk_draw_index)(idx2 + 1); ids[1] = (nk_draw_index)(idx1+1); |
| 9795 |
ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2); |
| 9796 |
ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+1); |
| 9797 |
ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1); |
| 9798 |
ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0); |
| 9799 |
ids[10]= (nk_draw_index)(idx2 + 0); ids[11] = (nk_draw_index)(idx2+1); |
| 9800 |
ids[12]= (nk_draw_index)(idx2 + 2); ids[13] = (nk_draw_index)(idx1+2); |
| 9801 |
ids[14]= (nk_draw_index)(idx1 + 3); ids[15] = (nk_draw_index)(idx1+3); |
| 9802 |
ids[16]= (nk_draw_index)(idx2 + 3); ids[17] = (nk_draw_index)(idx2+2); |
| 9803 |
ids += 18; |
| 9804 |
idx1 = idx2; |
| 9805 |
} |
| 9806 |
|
| 9807 |
|
| 9808 |
for (i = 0; i < points_count; ++i) { |
| 9809 |
const struct nk_vec2 uv = list->config.null.uv; |
| 9810 |
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans); |
| 9811 |
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col); |
| 9812 |
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col); |
| 9813 |
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+3], uv, col_trans); |
| 9814 |
} |
| 9815 |
} |
| 9816 |
|
| 9817 |
nk_buffer_reset(list->vertices, NK_BUFFER_FRONT); |
| 9818 |
} else { |
| 9819 |
|
| 9820 |
nk_size i1 = 0; |
| 9821 |
nk_size idx = list->vertex_count; |
| 9822 |
const nk_size idx_count = count * 6; |
| 9823 |
const nk_size vtx_count = count * 4; |
| 9824 |
void *vtx = nk_draw_list_alloc_vertices(list, vtx_count); |
| 9825 |
nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count); |
| 9826 |
if (!vtx || !ids) return; |
| 9827 |
|
| 9828 |
for (i1 = 0; i1 < count; ++i1) { |
| 9829 |
float dx, dy; |
| 9830 |
const struct nk_vec2 uv = list->config.null.uv; |
| 9831 |
const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1; |
| 9832 |
const struct nk_vec2 p1 = points[i1]; |
| 9833 |
const struct nk_vec2 p2 = points[i2]; |
| 9834 |
struct nk_vec2 diff = nk_vec2_sub(p2, p1); |
| 9835 |
float len; |
| 9836 |
|
| 9837 |
|
| 9838 |
len = nk_vec2_len_sqr(diff); |
| 9839 |
if (len != 0.0f) |
| 9840 |
len = nk_inv_sqrt(len); |
| 9841 |
else len = 1.0f; |
| 9842 |
diff = nk_vec2_muls(diff, len); |
| 9843 |
|
| 9844 |
|
| 9845 |
dx = diff.x * (thickness * 0.5f); |
| 9846 |
dy = diff.y * (thickness * 0.5f); |
| 9847 |
|
| 9848 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p1.x + dy, p1.y - dx), uv, col); |
| 9849 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p2.x + dy, p2.y - dx), uv, col); |
| 9850 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p2.x - dy, p2.y + dx), uv, col); |
| 9851 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p1.x - dy, p1.y + dx), uv, col); |
| 9852 |
|
| 9853 |
ids[0] = (nk_draw_index)(idx+0); ids[1] = (nk_draw_index)(idx+1); |
| 9854 |
ids[2] = (nk_draw_index)(idx+2); ids[3] = (nk_draw_index)(idx+0); |
| 9855 |
ids[4] = (nk_draw_index)(idx+2); ids[5] = (nk_draw_index)(idx+3); |
| 9856 |
|
| 9857 |
ids += 6; |
| 9858 |
idx += 4; |
| 9859 |
} |
| 9860 |
} |
| 9861 |
} |
| 9862 |
NK_API void |
| 9863 |
nk_draw_list_fill_poly_convex(struct nk_draw_list *list, |
| 9864 |
const struct nk_vec2 *points, const unsigned int points_count, |
| 9865 |
struct nk_color color, enum nk_anti_aliasing aliasing) |
| 9866 |
{ |
| 9867 |
struct nk_colorf col; |
| 9868 |
struct nk_colorf col_trans; |
| 9869 |
|
| 9870 |
NK_STORAGE const nk_size pnt_align = NK_ALIGNOF(struct nk_vec2); |
| 9871 |
NK_STORAGE const nk_size pnt_size = sizeof(struct nk_vec2); |
| 9872 |
NK_ASSERT(list); |
| 9873 |
if (!list || points_count < 3) return; |
| 9874 |
|
| 9875 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 9876 |
nk_draw_list_push_userdata(list, list->userdata); |
| 9877 |
#endif |
| 9878 |
|
| 9879 |
color.a = (nk_byte)((float)color.a * list->config.global_alpha); |
| 9880 |
nk_color_fv(&col.r, color); |
| 9881 |
col_trans = col; |
| 9882 |
col_trans.a = 0; |
| 9883 |
|
| 9884 |
if (aliasing == NK_ANTI_ALIASING_ON) { |
| 9885 |
nk_size i = 0; |
| 9886 |
nk_size i0 = 0; |
| 9887 |
nk_size i1 = 0; |
| 9888 |
|
| 9889 |
const float AA_SIZE = 1.0f; |
| 9890 |
nk_size vertex_offset = 0; |
| 9891 |
nk_size index = list->vertex_count; |
| 9892 |
|
| 9893 |
const nk_size idx_count = (points_count-2)*3 + points_count*6; |
| 9894 |
const nk_size vtx_count = (points_count*2); |
| 9895 |
|
| 9896 |
void *vtx = nk_draw_list_alloc_vertices(list, vtx_count); |
| 9897 |
nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count); |
| 9898 |
|
| 9899 |
nk_size size = 0; |
| 9900 |
struct nk_vec2 *normals = 0; |
| 9901 |
unsigned int vtx_inner_idx = (unsigned int)(index + 0); |
| 9902 |
unsigned int vtx_outer_idx = (unsigned int)(index + 1); |
| 9903 |
if (!vtx || !ids) return; |
| 9904 |
|
| 9905 |
|
| 9906 |
vertex_offset = (nk_size)((nk_byte*)vtx - (nk_byte*)list->vertices->memory.ptr); |
| 9907 |
nk_buffer_mark(list->vertices, NK_BUFFER_FRONT); |
| 9908 |
size = pnt_size * points_count; |
| 9909 |
normals = (struct nk_vec2*) nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align); |
| 9910 |
if (!normals) return; |
| 9911 |
vtx = (void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset); |
| 9912 |
|
| 9913 |
|
| 9914 |
for (i = 2; i < points_count; i++) { |
| 9915 |
ids[0] = (nk_draw_index)(vtx_inner_idx); |
| 9916 |
ids[1] = (nk_draw_index)(vtx_inner_idx + ((i-1) << 1)); |
| 9917 |
ids[2] = (nk_draw_index)(vtx_inner_idx + (i << 1)); |
| 9918 |
ids += 3; |
| 9919 |
} |
| 9920 |
|
| 9921 |
|
| 9922 |
for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) { |
| 9923 |
struct nk_vec2 p0 = points[i0]; |
| 9924 |
struct nk_vec2 p1 = points[i1]; |
| 9925 |
struct nk_vec2 diff = nk_vec2_sub(p1, p0); |
| 9926 |
|
| 9927 |
|
| 9928 |
float len = nk_vec2_len_sqr(diff); |
| 9929 |
if (len != 0.0f) |
| 9930 |
len = nk_inv_sqrt(len); |
| 9931 |
else len = 1.0f; |
| 9932 |
diff = nk_vec2_muls(diff, len); |
| 9933 |
|
| 9934 |
normals[i0].x = diff.y; |
| 9935 |
normals[i0].y = -diff.x; |
| 9936 |
} |
| 9937 |
|
| 9938 |
|
| 9939 |
for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) { |
| 9940 |
const struct nk_vec2 uv = list->config.null.uv; |
| 9941 |
struct nk_vec2 n0 = normals[i0]; |
| 9942 |
struct nk_vec2 n1 = normals[i1]; |
| 9943 |
struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(n0, n1), 0.5f); |
| 9944 |
float dmr2 = dm.x*dm.x + dm.y*dm.y; |
| 9945 |
if (dmr2 > 0.000001f) { |
| 9946 |
float scale = 1.0f / dmr2; |
| 9947 |
scale = NK_MIN(scale, 100.0f); |
| 9948 |
dm = nk_vec2_muls(dm, scale); |
| 9949 |
} |
| 9950 |
dm = nk_vec2_muls(dm, AA_SIZE * 0.5f); |
| 9951 |
|
| 9952 |
|
| 9953 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_sub(points[i1], dm), uv, col); |
| 9954 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_add(points[i1], dm), uv, col_trans); |
| 9955 |
|
| 9956 |
|
| 9957 |
ids[0] = (nk_draw_index)(vtx_inner_idx+(i1<<1)); |
| 9958 |
ids[1] = (nk_draw_index)(vtx_inner_idx+(i0<<1)); |
| 9959 |
ids[2] = (nk_draw_index)(vtx_outer_idx+(i0<<1)); |
| 9960 |
ids[3] = (nk_draw_index)(vtx_outer_idx+(i0<<1)); |
| 9961 |
ids[4] = (nk_draw_index)(vtx_outer_idx+(i1<<1)); |
| 9962 |
ids[5] = (nk_draw_index)(vtx_inner_idx+(i1<<1)); |
| 9963 |
ids += 6; |
| 9964 |
} |
| 9965 |
|
| 9966 |
nk_buffer_reset(list->vertices, NK_BUFFER_FRONT); |
| 9967 |
} else { |
| 9968 |
nk_size i = 0; |
| 9969 |
nk_size index = list->vertex_count; |
| 9970 |
const nk_size idx_count = (points_count-2)*3; |
| 9971 |
const nk_size vtx_count = points_count; |
| 9972 |
void *vtx = nk_draw_list_alloc_vertices(list, vtx_count); |
| 9973 |
nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count); |
| 9974 |
|
| 9975 |
if (!vtx || !ids) return; |
| 9976 |
for (i = 0; i < vtx_count; ++i) |
| 9977 |
vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.null.uv, col); |
| 9978 |
for (i = 2; i < points_count; ++i) { |
| 9979 |
ids[0] = (nk_draw_index)index; |
| 9980 |
ids[1] = (nk_draw_index)(index+ i - 1); |
| 9981 |
ids[2] = (nk_draw_index)(index+i); |
| 9982 |
ids += 3; |
| 9983 |
} |
| 9984 |
} |
| 9985 |
} |
| 9986 |
NK_API void |
| 9987 |
nk_draw_list_path_clear(struct nk_draw_list *list) |
| 9988 |
{ |
| 9989 |
NK_ASSERT(list); |
| 9990 |
if (!list) return; |
| 9991 |
nk_buffer_reset(list->buffer, NK_BUFFER_FRONT); |
| 9992 |
list->path_count = 0; |
| 9993 |
list->path_offset = 0; |
| 9994 |
} |
| 9995 |
NK_API void |
| 9996 |
nk_draw_list_path_line_to(struct nk_draw_list *list, struct nk_vec2 pos) |
| 9997 |
{ |
| 9998 |
struct nk_vec2 *points = 0; |
| 9999 |
struct nk_draw_command *cmd = 0; |
| 10000 |
NK_ASSERT(list); |
| 10001 |
if (!list) return; |
| 10002 |
if (!list->cmd_count) |
| 10003 |
nk_draw_list_add_clip(list, nk_null_rect); |
| 10004 |
|
| 10005 |
cmd = nk_draw_list_command_last(list); |
| 10006 |
if (cmd && cmd->texture.ptr != list->config.null.texture.ptr) |
| 10007 |
nk_draw_list_push_image(list, list->config.null.texture); |
| 10008 |
|
| 10009 |
points = nk_draw_list_alloc_path(list, 1); |
| 10010 |
if (!points) return; |
| 10011 |
points[0] = pos; |
| 10012 |
} |
| 10013 |
NK_API void |
| 10014 |
nk_draw_list_path_arc_to_fast(struct nk_draw_list *list, struct nk_vec2 center, |
| 10015 |
float radius, int a_min, int a_max) |
| 10016 |
{ |
| 10017 |
int a = 0; |
| 10018 |
NK_ASSERT(list); |
| 10019 |
if (!list) return; |
| 10020 |
if (a_min <= a_max) { |
| 10021 |
for (a = a_min; a <= a_max; a++) { |
| 10022 |
const struct nk_vec2 c = list->circle_vtx[(nk_size)a % NK_LEN(list->circle_vtx)]; |
| 10023 |
const float x = center.x + c.x * radius; |
| 10024 |
const float y = center.y + c.y * radius; |
| 10025 |
nk_draw_list_path_line_to(list, nk_vec2(x, y)); |
| 10026 |
} |
| 10027 |
} |
| 10028 |
} |
| 10029 |
NK_API void |
| 10030 |
nk_draw_list_path_arc_to(struct nk_draw_list *list, struct nk_vec2 center, |
| 10031 |
float radius, float a_min, float a_max, unsigned int segments) |
| 10032 |
{ |
| 10033 |
unsigned int i = 0; |
| 10034 |
NK_ASSERT(list); |
| 10035 |
if (!list) return; |
| 10036 |
if (radius == 0.0f) return; |
| 10037 |
|
| 10038 |
|
| 10039 |
|
| 10040 |
|
| 10041 |
|
| 10042 |
|
| 10043 |
|
| 10044 |
|
| 10045 |
|
| 10046 |
|
| 10047 |
|
| 10048 |
|
| 10049 |
|
| 10050 |
|
| 10051 |
|
| 10052 |
|
| 10053 |
|
| 10054 |
|
| 10055 |
|
| 10056 |
{const float d_angle = (a_max - a_min) / (float)segments; |
| 10057 |
const float sin_d = (float)NK_SIN(d_angle); |
| 10058 |
const float cos_d = (float)NK_COS(d_angle); |
| 10059 |
|
| 10060 |
float cx = (float)NK_COS(a_min) * radius; |
| 10061 |
float cy = (float)NK_SIN(a_min) * radius; |
| 10062 |
for(i = 0; i <= segments; ++i) { |
| 10063 |
float new_cx, new_cy; |
| 10064 |
const float x = center.x + cx; |
| 10065 |
const float y = center.y + cy; |
| 10066 |
nk_draw_list_path_line_to(list, nk_vec2(x, y)); |
| 10067 |
|
| 10068 |
new_cx = cx * cos_d - cy * sin_d; |
| 10069 |
new_cy = cy * cos_d + cx * sin_d; |
| 10070 |
cx = new_cx; |
| 10071 |
cy = new_cy; |
| 10072 |
}} |
| 10073 |
} |
| 10074 |
NK_API void |
| 10075 |
nk_draw_list_path_rect_to(struct nk_draw_list *list, struct nk_vec2 a, |
| 10076 |
struct nk_vec2 b, float rounding) |
| 10077 |
{ |
| 10078 |
float r; |
| 10079 |
NK_ASSERT(list); |
| 10080 |
if (!list) return; |
| 10081 |
r = rounding; |
| 10082 |
r = NK_MIN(r, ((b.x-a.x) < 0) ? -(b.x-a.x): (b.x-a.x)); |
| 10083 |
r = NK_MIN(r, ((b.y-a.y) < 0) ? -(b.y-a.y): (b.y-a.y)); |
| 10084 |
|
| 10085 |
if (r == 0.0f) { |
| 10086 |
nk_draw_list_path_line_to(list, a); |
| 10087 |
nk_draw_list_path_line_to(list, nk_vec2(b.x,a.y)); |
| 10088 |
nk_draw_list_path_line_to(list, b); |
| 10089 |
nk_draw_list_path_line_to(list, nk_vec2(a.x,b.y)); |
| 10090 |
} else { |
| 10091 |
nk_draw_list_path_arc_to_fast(list, nk_vec2(a.x + r, a.y + r), r, 6, 9); |
| 10092 |
nk_draw_list_path_arc_to_fast(list, nk_vec2(b.x - r, a.y + r), r, 9, 12); |
| 10093 |
nk_draw_list_path_arc_to_fast(list, nk_vec2(b.x - r, b.y - r), r, 0, 3); |
| 10094 |
nk_draw_list_path_arc_to_fast(list, nk_vec2(a.x + r, b.y - r), r, 3, 6); |
| 10095 |
} |
| 10096 |
} |
| 10097 |
NK_API void |
| 10098 |
nk_draw_list_path_curve_to(struct nk_draw_list *list, struct nk_vec2 p2, |
| 10099 |
struct nk_vec2 p3, struct nk_vec2 p4, unsigned int num_segments) |
| 10100 |
{ |
| 10101 |
float t_step; |
| 10102 |
unsigned int i_step; |
| 10103 |
struct nk_vec2 p1; |
| 10104 |
|
| 10105 |
NK_ASSERT(list); |
| 10106 |
NK_ASSERT(list->path_count); |
| 10107 |
if (!list || !list->path_count) return; |
| 10108 |
num_segments = NK_MAX(num_segments, 1); |
| 10109 |
|
| 10110 |
p1 = nk_draw_list_path_last(list); |
| 10111 |
t_step = 1.0f/(float)num_segments; |
| 10112 |
for (i_step = 1; i_step <= num_segments; ++i_step) { |
| 10113 |
float t = t_step * (float)i_step; |
| 10114 |
float u = 1.0f - t; |
| 10115 |
float w1 = u*u*u; |
| 10116 |
float w2 = 3*u*u*t; |
| 10117 |
float w3 = 3*u*t*t; |
| 10118 |
float w4 = t * t *t; |
| 10119 |
float x = w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x; |
| 10120 |
float y = w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y; |
| 10121 |
nk_draw_list_path_line_to(list, nk_vec2(x,y)); |
| 10122 |
} |
| 10123 |
} |
| 10124 |
NK_API void |
| 10125 |
nk_draw_list_path_fill(struct nk_draw_list *list, struct nk_color color) |
| 10126 |
{ |
| 10127 |
struct nk_vec2 *points; |
| 10128 |
NK_ASSERT(list); |
| 10129 |
if (!list) return; |
| 10130 |
points = (struct nk_vec2*)nk_buffer_memory(list->buffer); |
| 10131 |
nk_draw_list_fill_poly_convex(list, points, list->path_count, color, list->config.shape_AA); |
| 10132 |
nk_draw_list_path_clear(list); |
| 10133 |
} |
| 10134 |
NK_API void |
| 10135 |
nk_draw_list_path_stroke(struct nk_draw_list *list, struct nk_color color, |
| 10136 |
enum nk_draw_list_stroke closed, float thickness) |
| 10137 |
{ |
| 10138 |
struct nk_vec2 *points; |
| 10139 |
NK_ASSERT(list); |
| 10140 |
if (!list) return; |
| 10141 |
points = (struct nk_vec2*)nk_buffer_memory(list->buffer); |
| 10142 |
nk_draw_list_stroke_poly_line(list, points, list->path_count, color, |
| 10143 |
closed, thickness, list->config.line_AA); |
| 10144 |
nk_draw_list_path_clear(list); |
| 10145 |
} |
| 10146 |
NK_API void |
| 10147 |
nk_draw_list_stroke_line(struct nk_draw_list *list, struct nk_vec2 a, |
| 10148 |
struct nk_vec2 b, struct nk_color col, float thickness) |
| 10149 |
{ |
| 10150 |
NK_ASSERT(list); |
| 10151 |
if (!list || !col.a) return; |
| 10152 |
if (list->line_AA == NK_ANTI_ALIASING_ON) { |
| 10153 |
nk_draw_list_path_line_to(list, a); |
| 10154 |
nk_draw_list_path_line_to(list, b); |
| 10155 |
} else { |
| 10156 |
nk_draw_list_path_line_to(list, nk_vec2_sub(a,nk_vec2(0.5f,0.5f))); |
| 10157 |
nk_draw_list_path_line_to(list, nk_vec2_sub(b,nk_vec2(0.5f,0.5f))); |
| 10158 |
} |
| 10159 |
nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness); |
| 10160 |
} |
| 10161 |
NK_API void |
| 10162 |
nk_draw_list_fill_rect(struct nk_draw_list *list, struct nk_rect rect, |
| 10163 |
struct nk_color col, float rounding) |
| 10164 |
{ |
| 10165 |
NK_ASSERT(list); |
| 10166 |
if (!list || !col.a) return; |
| 10167 |
|
| 10168 |
if (list->line_AA == NK_ANTI_ALIASING_ON) { |
| 10169 |
nk_draw_list_path_rect_to(list, nk_vec2(rect.x, rect.y), |
| 10170 |
nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); |
| 10171 |
} else { |
| 10172 |
nk_draw_list_path_rect_to(list, nk_vec2(rect.x-0.5f, rect.y-0.5f), |
| 10173 |
nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); |
| 10174 |
} nk_draw_list_path_fill(list, col); |
| 10175 |
} |
| 10176 |
NK_API void |
| 10177 |
nk_draw_list_stroke_rect(struct nk_draw_list *list, struct nk_rect rect, |
| 10178 |
struct nk_color col, float rounding, float thickness) |
| 10179 |
{ |
| 10180 |
NK_ASSERT(list); |
| 10181 |
if (!list || !col.a) return; |
| 10182 |
if (list->line_AA == NK_ANTI_ALIASING_ON) { |
| 10183 |
nk_draw_list_path_rect_to(list, nk_vec2(rect.x, rect.y), |
| 10184 |
nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); |
| 10185 |
} else { |
| 10186 |
nk_draw_list_path_rect_to(list, nk_vec2(rect.x-0.5f, rect.y-0.5f), |
| 10187 |
nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); |
| 10188 |
} nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness); |
| 10189 |
} |
| 10190 |
NK_API void |
| 10191 |
nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rect, |
| 10192 |
struct nk_color left, struct nk_color top, struct nk_color right, |
| 10193 |
struct nk_color bottom) |
| 10194 |
{ |
| 10195 |
void *vtx; |
| 10196 |
struct nk_colorf col_left, col_top; |
| 10197 |
struct nk_colorf col_right, col_bottom; |
| 10198 |
nk_draw_index *idx; |
| 10199 |
nk_draw_index index; |
| 10200 |
|
| 10201 |
nk_color_fv(&col_left.r, left); |
| 10202 |
nk_color_fv(&col_right.r, right); |
| 10203 |
nk_color_fv(&col_top.r, top); |
| 10204 |
nk_color_fv(&col_bottom.r, bottom); |
| 10205 |
|
| 10206 |
NK_ASSERT(list); |
| 10207 |
if (!list) return; |
| 10208 |
|
| 10209 |
nk_draw_list_push_image(list, list->config.null.texture); |
| 10210 |
index = (nk_draw_index)list->vertex_count; |
| 10211 |
vtx = nk_draw_list_alloc_vertices(list, 4); |
| 10212 |
idx = nk_draw_list_alloc_elements(list, 6); |
| 10213 |
if (!vtx || !idx) return; |
| 10214 |
|
| 10215 |
idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1); |
| 10216 |
idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0); |
| 10217 |
idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3); |
| 10218 |
|
| 10219 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y), list->config.null.uv, col_left); |
| 10220 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y), list->config.null.uv, col_top); |
| 10221 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.null.uv, col_right); |
| 10222 |
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y + rect.h), list->config.null.uv, col_bottom); |
| 10223 |
} |
| 10224 |
NK_API void |
| 10225 |
nk_draw_list_fill_triangle(struct nk_draw_list *list, struct nk_vec2 a, |
| 10226 |
struct nk_vec2 b, struct nk_vec2 c, struct nk_color col) |
| 10227 |
{ |
| 10228 |
NK_ASSERT(list); |
| 10229 |
if (!list || !col.a) return; |
| 10230 |
nk_draw_list_path_line_to(list, a); |
| 10231 |
nk_draw_list_path_line_to(list, b); |
| 10232 |
nk_draw_list_path_line_to(list, c); |
| 10233 |
nk_draw_list_path_fill(list, col); |
| 10234 |
} |
| 10235 |
NK_API void |
| 10236 |
nk_draw_list_stroke_triangle(struct nk_draw_list *list, struct nk_vec2 a, |
| 10237 |
struct nk_vec2 b, struct nk_vec2 c, struct nk_color col, float thickness) |
| 10238 |
{ |
| 10239 |
NK_ASSERT(list); |
| 10240 |
if (!list || !col.a) return; |
| 10241 |
nk_draw_list_path_line_to(list, a); |
| 10242 |
nk_draw_list_path_line_to(list, b); |
| 10243 |
nk_draw_list_path_line_to(list, c); |
| 10244 |
nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness); |
| 10245 |
} |
| 10246 |
NK_API void |
| 10247 |
nk_draw_list_fill_circle(struct nk_draw_list *list, struct nk_vec2 center, |
| 10248 |
float radius, struct nk_color col, unsigned int segs) |
| 10249 |
{ |
| 10250 |
float a_max; |
| 10251 |
NK_ASSERT(list); |
| 10252 |
if (!list || !col.a) return; |
| 10253 |
a_max = NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs; |
| 10254 |
nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs); |
| 10255 |
nk_draw_list_path_fill(list, col); |
| 10256 |
} |
| 10257 |
NK_API void |
| 10258 |
nk_draw_list_stroke_circle(struct nk_draw_list *list, struct nk_vec2 center, |
| 10259 |
float radius, struct nk_color col, unsigned int segs, float thickness) |
| 10260 |
{ |
| 10261 |
float a_max; |
| 10262 |
NK_ASSERT(list); |
| 10263 |
if (!list || !col.a) return; |
| 10264 |
a_max = NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs; |
| 10265 |
nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs); |
| 10266 |
nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness); |
| 10267 |
} |
| 10268 |
NK_API void |
| 10269 |
nk_draw_list_stroke_curve(struct nk_draw_list *list, struct nk_vec2 p0, |
| 10270 |
struct nk_vec2 cp0, struct nk_vec2 cp1, struct nk_vec2 p1, |
| 10271 |
struct nk_color col, unsigned int segments, float thickness) |
| 10272 |
{ |
| 10273 |
NK_ASSERT(list); |
| 10274 |
if (!list || !col.a) return; |
| 10275 |
nk_draw_list_path_line_to(list, p0); |
| 10276 |
nk_draw_list_path_curve_to(list, cp0, cp1, p1, segments); |
| 10277 |
nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness); |
| 10278 |
} |
| 10279 |
NK_INTERN void |
| 10280 |
nk_draw_list_push_rect_uv(struct nk_draw_list *list, struct nk_vec2 a, |
| 10281 |
struct nk_vec2 c, struct nk_vec2 uva, struct nk_vec2 uvc, |
| 10282 |
struct nk_color color) |
| 10283 |
{ |
| 10284 |
void *vtx; |
| 10285 |
struct nk_vec2 uvb; |
| 10286 |
struct nk_vec2 uvd; |
| 10287 |
struct nk_vec2 b; |
| 10288 |
struct nk_vec2 d; |
| 10289 |
|
| 10290 |
struct nk_colorf col; |
| 10291 |
nk_draw_index *idx; |
| 10292 |
nk_draw_index index; |
| 10293 |
NK_ASSERT(list); |
| 10294 |
if (!list) return; |
| 10295 |
|
| 10296 |
nk_color_fv(&col.r, color); |
| 10297 |
uvb = nk_vec2(uvc.x, uva.y); |
| 10298 |
uvd = nk_vec2(uva.x, uvc.y); |
| 10299 |
b = nk_vec2(c.x, a.y); |
| 10300 |
d = nk_vec2(a.x, c.y); |
| 10301 |
|
| 10302 |
index = (nk_draw_index)list->vertex_count; |
| 10303 |
vtx = nk_draw_list_alloc_vertices(list, 4); |
| 10304 |
idx = nk_draw_list_alloc_elements(list, 6); |
| 10305 |
if (!vtx || !idx) return; |
| 10306 |
|
| 10307 |
idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1); |
| 10308 |
idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0); |
| 10309 |
idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3); |
| 10310 |
|
| 10311 |
vtx = nk_draw_vertex(vtx, &list->config, a, uva, col); |
| 10312 |
vtx = nk_draw_vertex(vtx, &list->config, b, uvb, col); |
| 10313 |
vtx = nk_draw_vertex(vtx, &list->config, c, uvc, col); |
| 10314 |
vtx = nk_draw_vertex(vtx, &list->config, d, uvd, col); |
| 10315 |
} |
| 10316 |
NK_API void |
| 10317 |
nk_draw_list_add_image(struct nk_draw_list *list, struct nk_image texture, |
| 10318 |
struct nk_rect rect, struct nk_color color) |
| 10319 |
{ |
| 10320 |
NK_ASSERT(list); |
| 10321 |
if (!list) return; |
| 10322 |
|
| 10323 |
nk_draw_list_push_image(list, texture.handle); |
| 10324 |
if (nk_image_is_subimage(&texture)) { |
| 10325 |
|
| 10326 |
struct nk_vec2 uv[2]; |
| 10327 |
uv[0].x = (float)texture.region[0]/(float)texture.w; |
| 10328 |
uv[0].y = (float)texture.region[1]/(float)texture.h; |
| 10329 |
uv[1].x = (float)(texture.region[0] + texture.region[2])/(float)texture.w; |
| 10330 |
uv[1].y = (float)(texture.region[1] + texture.region[3])/(float)texture.h; |
| 10331 |
nk_draw_list_push_rect_uv(list, nk_vec2(rect.x, rect.y), |
| 10332 |
nk_vec2(rect.x + rect.w, rect.y + rect.h), uv[0], uv[1], color); |
| 10333 |
} else nk_draw_list_push_rect_uv(list, nk_vec2(rect.x, rect.y), |
| 10334 |
nk_vec2(rect.x + rect.w, rect.y + rect.h), |
| 10335 |
nk_vec2(0.0f, 0.0f), nk_vec2(1.0f, 1.0f),color); |
| 10336 |
} |
| 10337 |
NK_API void |
| 10338 |
nk_draw_list_add_text(struct nk_draw_list *list, const struct nk_user_font *font, |
| 10339 |
struct nk_rect rect, const char *text, int len, float font_height, |
| 10340 |
struct nk_color fg) |
| 10341 |
{ |
| 10342 |
float x = 0; |
| 10343 |
int text_len = 0; |
| 10344 |
nk_rune unicode = 0; |
| 10345 |
nk_rune next = 0; |
| 10346 |
int glyph_len = 0; |
| 10347 |
int next_glyph_len = 0; |
| 10348 |
struct nk_user_font_glyph g; |
| 10349 |
|
| 10350 |
NK_ASSERT(list); |
| 10351 |
if (!list || !len || !text) return; |
| 10352 |
if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h, |
| 10353 |
list->clip_rect.x, list->clip_rect.y, list->clip_rect.w, list->clip_rect.h)) return; |
| 10354 |
|
| 10355 |
nk_draw_list_push_image(list, font->texture); |
| 10356 |
x = rect.x; |
| 10357 |
glyph_len = nk_utf_decode(text, &unicode, len); |
| 10358 |
if (!glyph_len) return; |
| 10359 |
|
| 10360 |
|
| 10361 |
fg.a = (nk_byte)((float)fg.a * list->config.global_alpha); |
| 10362 |
while (text_len < len && glyph_len) { |
| 10363 |
float gx, gy, gh, gw; |
| 10364 |
float char_width = 0; |
| 10365 |
if (unicode == NK_UTF_INVALID) break; |
| 10366 |
|
| 10367 |
|
| 10368 |
next_glyph_len = nk_utf_decode(text + text_len + glyph_len, &next, (int)len - text_len); |
| 10369 |
font->query(font->userdata, font_height, &g, unicode, |
| 10370 |
(next == NK_UTF_INVALID) ? '\0' : next); |
| 10371 |
|
| 10372 |
|
| 10373 |
gx = x + g.offset.x; |
| 10374 |
gy = rect.y + g.offset.y; |
| 10375 |
gw = g.width; gh = g.height; |
| 10376 |
char_width = g.xadvance; |
| 10377 |
nk_draw_list_push_rect_uv(list, nk_vec2(gx,gy), nk_vec2(gx + gw, gy+ gh), |
| 10378 |
g.uv[0], g.uv[1], fg); |
| 10379 |
|
| 10380 |
|
| 10381 |
text_len += glyph_len; |
| 10382 |
x += char_width; |
| 10383 |
glyph_len = next_glyph_len; |
| 10384 |
unicode = next; |
| 10385 |
} |
| 10386 |
} |
| 10387 |
NK_API nk_flags |
| 10388 |
nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, |
| 10389 |
struct nk_buffer *vertices, struct nk_buffer *elements, |
| 10390 |
const struct nk_convert_config *config) |
| 10391 |
{ |
| 10392 |
nk_flags res = NK_CONVERT_SUCCESS; |
| 10393 |
const struct nk_command *cmd; |
| 10394 |
NK_ASSERT(ctx); |
| 10395 |
NK_ASSERT(cmds); |
| 10396 |
NK_ASSERT(vertices); |
| 10397 |
NK_ASSERT(elements); |
| 10398 |
NK_ASSERT(config); |
| 10399 |
NK_ASSERT(config->vertex_layout); |
| 10400 |
NK_ASSERT(config->vertex_size); |
| 10401 |
if (!ctx || !cmds || !vertices || !elements || !config || !config->vertex_layout) |
| 10402 |
return NK_CONVERT_INVALID_PARAM; |
| 10403 |
|
| 10404 |
nk_draw_list_setup(&ctx->draw_list, config, cmds, vertices, elements, |
| 10405 |
config->line_AA, config->shape_AA); |
| 10406 |
nk_foreach(cmd, ctx) |
| 10407 |
{ |
| 10408 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 10409 |
ctx->draw_list.userdata = cmd->userdata; |
| 10410 |
#endif |
| 10411 |
switch (cmd->type) { |
| 10412 |
case NK_COMMAND_NOP: break; |
| 10413 |
case NK_COMMAND_SCISSOR: { |
| 10414 |
const struct nk_command_scissor *s = (const struct nk_command_scissor*)cmd; |
| 10415 |
nk_draw_list_add_clip(&ctx->draw_list, nk_rect(s->x, s->y, s->w, s->h)); |
| 10416 |
} break; |
| 10417 |
case NK_COMMAND_LINE: { |
| 10418 |
const struct nk_command_line *l = (const struct nk_command_line*)cmd; |
| 10419 |
nk_draw_list_stroke_line(&ctx->draw_list, nk_vec2(l->begin.x, l->begin.y), |
| 10420 |
nk_vec2(l->end.x, l->end.y), l->color, l->line_thickness); |
| 10421 |
} break; |
| 10422 |
case NK_COMMAND_CURVE: { |
| 10423 |
const struct nk_command_curve *q = (const struct nk_command_curve*)cmd; |
| 10424 |
nk_draw_list_stroke_curve(&ctx->draw_list, nk_vec2(q->begin.x, q->begin.y), |
| 10425 |
nk_vec2(q->ctrl[0].x, q->ctrl[0].y), nk_vec2(q->ctrl[1].x, |
| 10426 |
q->ctrl[1].y), nk_vec2(q->end.x, q->end.y), q->color, |
| 10427 |
config->curve_segment_count, q->line_thickness); |
| 10428 |
} break; |
| 10429 |
case NK_COMMAND_RECT: { |
| 10430 |
const struct nk_command_rect *r = (const struct nk_command_rect*)cmd; |
| 10431 |
nk_draw_list_stroke_rect(&ctx->draw_list, nk_rect(r->x, r->y, r->w, r->h), |
| 10432 |
r->color, (float)r->rounding, r->line_thickness); |
| 10433 |
} break; |
| 10434 |
case NK_COMMAND_RECT_FILLED: { |
| 10435 |
const struct nk_command_rect_filled *r = (const struct nk_command_rect_filled*)cmd; |
| 10436 |
nk_draw_list_fill_rect(&ctx->draw_list, nk_rect(r->x, r->y, r->w, r->h), |
| 10437 |
r->color, (float)r->rounding); |
| 10438 |
} break; |
| 10439 |
case NK_COMMAND_RECT_MULTI_COLOR: { |
| 10440 |
const struct nk_command_rect_multi_color *r = (const struct nk_command_rect_multi_color*)cmd; |
| 10441 |
nk_draw_list_fill_rect_multi_color(&ctx->draw_list, nk_rect(r->x, r->y, r->w, r->h), |
| 10442 |
r->left, r->top, r->right, r->bottom); |
| 10443 |
} break; |
| 10444 |
case NK_COMMAND_CIRCLE: { |
| 10445 |
const struct nk_command_circle *c = (const struct nk_command_circle*)cmd; |
| 10446 |
nk_draw_list_stroke_circle(&ctx->draw_list, nk_vec2((float)c->x + (float)c->w/2, |
| 10447 |
(float)c->y + (float)c->h/2), (float)c->w/2, c->color, |
| 10448 |
config->circle_segment_count, c->line_thickness); |
| 10449 |
} break; |
| 10450 |
case NK_COMMAND_CIRCLE_FILLED: { |
| 10451 |
const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd; |
| 10452 |
nk_draw_list_fill_circle(&ctx->draw_list, nk_vec2((float)c->x + (float)c->w/2, |
| 10453 |
(float)c->y + (float)c->h/2), (float)c->w/2, c->color, |
| 10454 |
config->circle_segment_count); |
| 10455 |
} break; |
| 10456 |
case NK_COMMAND_ARC: { |
| 10457 |
const struct nk_command_arc *c = (const struct nk_command_arc*)cmd; |
| 10458 |
nk_draw_list_path_line_to(&ctx->draw_list, nk_vec2(c->cx, c->cy)); |
| 10459 |
nk_draw_list_path_arc_to(&ctx->draw_list, nk_vec2(c->cx, c->cy), c->r, |
| 10460 |
c->a[0], c->a[1], config->arc_segment_count); |
| 10461 |
nk_draw_list_path_stroke(&ctx->draw_list, c->color, NK_STROKE_CLOSED, c->line_thickness); |
| 10462 |
} break; |
| 10463 |
case NK_COMMAND_ARC_FILLED: { |
| 10464 |
const struct nk_command_arc_filled *c = (const struct nk_command_arc_filled*)cmd; |
| 10465 |
nk_draw_list_path_line_to(&ctx->draw_list, nk_vec2(c->cx, c->cy)); |
| 10466 |
nk_draw_list_path_arc_to(&ctx->draw_list, nk_vec2(c->cx, c->cy), c->r, |
| 10467 |
c->a[0], c->a[1], config->arc_segment_count); |
| 10468 |
nk_draw_list_path_fill(&ctx->draw_list, c->color); |
| 10469 |
} break; |
| 10470 |
case NK_COMMAND_TRIANGLE: { |
| 10471 |
const struct nk_command_triangle *t = (const struct nk_command_triangle*)cmd; |
| 10472 |
nk_draw_list_stroke_triangle(&ctx->draw_list, nk_vec2(t->a.x, t->a.y), |
| 10473 |
nk_vec2(t->b.x, t->b.y), nk_vec2(t->c.x, t->c.y), t->color, |
| 10474 |
t->line_thickness); |
| 10475 |
} break; |
| 10476 |
case NK_COMMAND_TRIANGLE_FILLED: { |
| 10477 |
const struct nk_command_triangle_filled *t = (const struct nk_command_triangle_filled*)cmd; |
| 10478 |
nk_draw_list_fill_triangle(&ctx->draw_list, nk_vec2(t->a.x, t->a.y), |
| 10479 |
nk_vec2(t->b.x, t->b.y), nk_vec2(t->c.x, t->c.y), t->color); |
| 10480 |
} break; |
| 10481 |
case NK_COMMAND_POLYGON: { |
| 10482 |
int i; |
| 10483 |
const struct nk_command_polygon*p = (const struct nk_command_polygon*)cmd; |
| 10484 |
for (i = 0; i < p->point_count; ++i) { |
| 10485 |
struct nk_vec2 pnt = nk_vec2((float)p->points[i].x, (float)p->points[i].y); |
| 10486 |
nk_draw_list_path_line_to(&ctx->draw_list, pnt); |
| 10487 |
} |
| 10488 |
nk_draw_list_path_stroke(&ctx->draw_list, p->color, NK_STROKE_CLOSED, p->line_thickness); |
| 10489 |
} break; |
| 10490 |
case NK_COMMAND_POLYGON_FILLED: { |
| 10491 |
int i; |
| 10492 |
const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled*)cmd; |
| 10493 |
for (i = 0; i < p->point_count; ++i) { |
| 10494 |
struct nk_vec2 pnt = nk_vec2((float)p->points[i].x, (float)p->points[i].y); |
| 10495 |
nk_draw_list_path_line_to(&ctx->draw_list, pnt); |
| 10496 |
} |
| 10497 |
nk_draw_list_path_fill(&ctx->draw_list, p->color); |
| 10498 |
} break; |
| 10499 |
case NK_COMMAND_POLYLINE: { |
| 10500 |
int i; |
| 10501 |
const struct nk_command_polyline *p = (const struct nk_command_polyline*)cmd; |
| 10502 |
for (i = 0; i < p->point_count; ++i) { |
| 10503 |
struct nk_vec2 pnt = nk_vec2((float)p->points[i].x, (float)p->points[i].y); |
| 10504 |
nk_draw_list_path_line_to(&ctx->draw_list, pnt); |
| 10505 |
} |
| 10506 |
nk_draw_list_path_stroke(&ctx->draw_list, p->color, NK_STROKE_OPEN, p->line_thickness); |
| 10507 |
} break; |
| 10508 |
case NK_COMMAND_TEXT: { |
| 10509 |
const struct nk_command_text *t = (const struct nk_command_text*)cmd; |
| 10510 |
nk_draw_list_add_text(&ctx->draw_list, t->font, nk_rect(t->x, t->y, t->w, t->h), |
| 10511 |
t->string, t->length, t->height, t->foreground); |
| 10512 |
} break; |
| 10513 |
case NK_COMMAND_IMAGE: { |
| 10514 |
const struct nk_command_image *i = (const struct nk_command_image*)cmd; |
| 10515 |
nk_draw_list_add_image(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); |
| 10516 |
} break; |
| 10517 |
case NK_COMMAND_CUSTOM: { |
| 10518 |
const struct nk_command_custom *c = (const struct nk_command_custom*)cmd; |
| 10519 |
c->callback(&ctx->draw_list, c->x, c->y, c->w, c->h, c->callback_data); |
| 10520 |
} break; |
| 10521 |
default: break; |
| 10522 |
} |
| 10523 |
} |
| 10524 |
res |= (cmds->needed > cmds->allocated + (cmds->memory.size - cmds->size)) ? NK_CONVERT_COMMAND_BUFFER_FULL: 0; |
| 10525 |
res |= (vertices->needed > vertices->allocated) ? NK_CONVERT_VERTEX_BUFFER_FULL: 0; |
| 10526 |
res |= (elements->needed > elements->allocated) ? NK_CONVERT_ELEMENT_BUFFER_FULL: 0; |
| 10527 |
return res; |
| 10528 |
} |
| 10529 |
NK_API const struct nk_draw_command* |
| 10530 |
nk__draw_begin(const struct nk_context *ctx, |
| 10531 |
const struct nk_buffer *buffer) |
| 10532 |
{ |
| 10533 |
return nk__draw_list_begin(&ctx->draw_list, buffer); |
| 10534 |
} |
| 10535 |
NK_API const struct nk_draw_command* |
| 10536 |
nk__draw_end(const struct nk_context *ctx, const struct nk_buffer *buffer) |
| 10537 |
{ |
| 10538 |
return nk__draw_list_end(&ctx->draw_list, buffer); |
| 10539 |
} |
| 10540 |
NK_API const struct nk_draw_command* |
| 10541 |
nk__draw_next(const struct nk_draw_command *cmd, |
| 10542 |
const struct nk_buffer *buffer, const struct nk_context *ctx) |
| 10543 |
{ |
| 10544 |
return nk__draw_list_next(cmd, buffer, &ctx->draw_list); |
| 10545 |
} |
| 10546 |
#endif |
| 10547 |
|
| 10548 |
|
| 10549 |
|
| 10550 |
|
| 10551 |
|
| 10552 |
#ifdef NK_INCLUDE_FONT_BAKING |
| 10553 |
|
| 10554 |
|
| 10555 |
|
| 10556 |
|
| 10557 |
|
| 10558 |
|
| 10559 |
|
| 10560 |
#define NK_RP__MAXVAL 0xffff |
| 10561 |
typedef unsigned short nk_rp_coord; |
| 10562 |
|
| 10563 |
struct nk_rp_rect { |
| 10564 |
|
| 10565 |
int id; |
| 10566 |
|
| 10567 |
nk_rp_coord w, h; |
| 10568 |
|
| 10569 |
nk_rp_coord x, y; |
| 10570 |
int was_packed; |
| 10571 |
|
| 10572 |
}; |
| 10573 |
|
| 10574 |
struct nk_rp_node { |
| 10575 |
nk_rp_coord x,y; |
| 10576 |
struct nk_rp_node *next; |
| 10577 |
}; |
| 10578 |
|
| 10579 |
struct nk_rp_context { |
| 10580 |
int width; |
| 10581 |
int height; |
| 10582 |
int align; |
| 10583 |
int init_mode; |
| 10584 |
int heuristic; |
| 10585 |
int num_nodes; |
| 10586 |
struct nk_rp_node *active_head; |
| 10587 |
struct nk_rp_node *free_head; |
| 10588 |
struct nk_rp_node extra[2]; |
| 10589 |
|
| 10590 |
}; |
| 10591 |
|
| 10592 |
struct nk_rp__findresult { |
| 10593 |
int x,y; |
| 10594 |
struct nk_rp_node **prev_link; |
| 10595 |
}; |
| 10596 |
|
| 10597 |
enum NK_RP_HEURISTIC { |
| 10598 |
NK_RP_HEURISTIC_Skyline_default=0, |
| 10599 |
NK_RP_HEURISTIC_Skyline_BL_sortHeight = NK_RP_HEURISTIC_Skyline_default, |
| 10600 |
NK_RP_HEURISTIC_Skyline_BF_sortHeight |
| 10601 |
}; |
| 10602 |
enum NK_RP_INIT_STATE{NK_RP__INIT_skyline = 1}; |
| 10603 |
|
| 10604 |
NK_INTERN void |
| 10605 |
nk_rp_setup_allow_out_of_mem(struct nk_rp_context *context, int allow_out_of_mem) |
| 10606 |
{ |
| 10607 |
if (allow_out_of_mem) |
| 10608 |
|
| 10609 |
|
| 10610 |
|
| 10611 |
|
| 10612 |
context->align = 1; |
| 10613 |
else { |
| 10614 |
|
| 10615 |
|
| 10616 |
|
| 10617 |
|
| 10618 |
|
| 10619 |
|
| 10620 |
context->align = (context->width + context->num_nodes-1) / context->num_nodes; |
| 10621 |
} |
| 10622 |
} |
| 10623 |
NK_INTERN void |
| 10624 |
nk_rp_init_target(struct nk_rp_context *context, int width, int height, |
| 10625 |
struct nk_rp_node *nodes, int num_nodes) |
| 10626 |
{ |
| 10627 |
int i; |
| 10628 |
#ifndef STBRP_LARGE_RECTS |
| 10629 |
NK_ASSERT(width <= 0xffff && height <= 0xffff); |
| 10630 |
#endif |
| 10631 |
|
| 10632 |
for (i=0; i < num_nodes-1; ++i) |
| 10633 |
nodes[i].next = &nodes[i+1]; |
| 10634 |
nodes[i].next = 0; |
| 10635 |
context->init_mode = NK_RP__INIT_skyline; |
| 10636 |
context->heuristic = NK_RP_HEURISTIC_Skyline_default; |
| 10637 |
context->free_head = &nodes[0]; |
| 10638 |
context->active_head = &context->extra[0]; |
| 10639 |
context->width = width; |
| 10640 |
context->height = height; |
| 10641 |
context->num_nodes = num_nodes; |
| 10642 |
nk_rp_setup_allow_out_of_mem(context, 0); |
| 10643 |
|
| 10644 |
|
| 10645 |
context->extra[0].x = 0; |
| 10646 |
context->extra[0].y = 0; |
| 10647 |
context->extra[0].next = &context->extra[1]; |
| 10648 |
context->extra[1].x = (nk_rp_coord) width; |
| 10649 |
context->extra[1].y = 65535; |
| 10650 |
context->extra[1].next = 0; |
| 10651 |
} |
| 10652 |
|
| 10653 |
NK_INTERN int |
| 10654 |
nk_rp__skyline_find_min_y(struct nk_rp_context *c, struct nk_rp_node *first, |
| 10655 |
int x0, int width, int *pwaste) |
| 10656 |
{ |
| 10657 |
struct nk_rp_node *node = first; |
| 10658 |
int x1 = x0 + width; |
| 10659 |
int min_y, visited_width, waste_area; |
| 10660 |
NK_ASSERT(first->x <= x0); |
| 10661 |
NK_UNUSED(c); |
| 10662 |
|
| 10663 |
NK_ASSERT(node->next->x > x0); |
| 10664 |
|
| 10665 |
NK_ASSERT(node->x <= x0); |
| 10666 |
|
| 10667 |
min_y = 0; |
| 10668 |
waste_area = 0; |
| 10669 |
visited_width = 0; |
| 10670 |
while (node->x < x1) |
| 10671 |
{ |
| 10672 |
if (node->y > min_y) { |
| 10673 |
|
| 10674 |
|
| 10675 |
|
| 10676 |
waste_area += visited_width * (node->y - min_y); |
| 10677 |
min_y = node->y; |
| 10678 |
|
| 10679 |
if (node->x < x0) |
| 10680 |
visited_width += node->next->x - x0; |
| 10681 |
else |
| 10682 |
visited_width += node->next->x - node->x; |
| 10683 |
} else { |
| 10684 |
|
| 10685 |
int under_width = node->next->x - node->x; |
| 10686 |
if (under_width + visited_width > width) |
| 10687 |
under_width = width - visited_width; |
| 10688 |
waste_area += under_width * (min_y - node->y); |
| 10689 |
visited_width += under_width; |
| 10690 |
} |
| 10691 |
node = node->next; |
| 10692 |
} |
| 10693 |
*pwaste = waste_area; |
| 10694 |
return min_y; |
| 10695 |
} |
| 10696 |
NK_INTERN struct nk_rp__findresult |
| 10697 |
nk_rp__skyline_find_best_pos(struct nk_rp_context *c, int width, int height) |
| 10698 |
{ |
| 10699 |
int best_waste = (1<<30), best_x, best_y = (1 << 30); |
| 10700 |
struct nk_rp__findresult fr; |
| 10701 |
struct nk_rp_node **prev, *node, *tail, **best = 0; |
| 10702 |
|
| 10703 |
|
| 10704 |
width = (width + c->align - 1); |
| 10705 |
width -= width % c->align; |
| 10706 |
NK_ASSERT(width % c->align == 0); |
| 10707 |
|
| 10708 |
node = c->active_head; |
| 10709 |
prev = &c->active_head; |
| 10710 |
while (node->x + width <= c->width) { |
| 10711 |
int y,waste; |
| 10712 |
y = nk_rp__skyline_find_min_y(c, node, node->x, width, &waste); |
| 10713 |
|
| 10714 |
if (c->heuristic == NK_RP_HEURISTIC_Skyline_BL_sortHeight) { |
| 10715 |
|
| 10716 |
if (y < best_y) { |
| 10717 |
best_y = y; |
| 10718 |
best = prev; |
| 10719 |
} |
| 10720 |
} else { |
| 10721 |
|
| 10722 |
if (y + height <= c->height) { |
| 10723 |
|
| 10724 |
if (y < best_y || (y == best_y && waste < best_waste)) { |
| 10725 |
best_y = y; |
| 10726 |
best_waste = waste; |
| 10727 |
best = prev; |
| 10728 |
} |
| 10729 |
} |
| 10730 |
} |
| 10731 |
prev = &node->next; |
| 10732 |
node = node->next; |
| 10733 |
} |
| 10734 |
best_x = (best == 0) ? 0 : (*best)->x; |
| 10735 |
|
| 10736 |
|
| 10737 |
|
| 10738 |
|
| 10739 |
|
| 10740 |
|
| 10741 |
|
| 10742 |
|
| 10743 |
|
| 10744 |
|
| 10745 |
|
| 10746 |
|
| 10747 |
|
| 10748 |
|
| 10749 |
|
| 10750 |
|
| 10751 |
|
| 10752 |
if (c->heuristic == NK_RP_HEURISTIC_Skyline_BF_sortHeight) |
| 10753 |
{ |
| 10754 |
tail = c->active_head; |
| 10755 |
node = c->active_head; |
| 10756 |
prev = &c->active_head; |
| 10757 |
|
| 10758 |
while (tail->x < width) |
| 10759 |
tail = tail->next; |
| 10760 |
while (tail) |
| 10761 |
{ |
| 10762 |
int xpos = tail->x - width; |
| 10763 |
int y,waste; |
| 10764 |
NK_ASSERT(xpos >= 0); |
| 10765 |
|
| 10766 |
while (node->next->x <= xpos) { |
| 10767 |
prev = &node->next; |
| 10768 |
node = node->next; |
| 10769 |
} |
| 10770 |
NK_ASSERT(node->next->x > xpos && node->x <= xpos); |
| 10771 |
y = nk_rp__skyline_find_min_y(c, node, xpos, width, &waste); |
| 10772 |
if (y + height < c->height) { |
| 10773 |
if (y <= best_y) { |
| 10774 |
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { |
| 10775 |
best_x = xpos; |
| 10776 |
NK_ASSERT(y <= best_y); |
| 10777 |
best_y = y; |
| 10778 |
best_waste = waste; |
| 10779 |
best = prev; |
| 10780 |
} |
| 10781 |
} |
| 10782 |
} |
| 10783 |
tail = tail->next; |
| 10784 |
} |
| 10785 |
} |
| 10786 |
fr.prev_link = best; |
| 10787 |
fr.x = best_x; |
| 10788 |
fr.y = best_y; |
| 10789 |
return fr; |
| 10790 |
} |
| 10791 |
NK_INTERN struct nk_rp__findresult |
| 10792 |
nk_rp__skyline_pack_rectangle(struct nk_rp_context *context, int width, int height) |
| 10793 |
{ |
| 10794 |
|
| 10795 |
struct nk_rp__findresult res = nk_rp__skyline_find_best_pos(context, width, height); |
| 10796 |
struct nk_rp_node *node, *cur; |
| 10797 |
|
| 10798 |
|
| 10799 |
|
| 10800 |
|
| 10801 |
|
| 10802 |
if (res.prev_link == 0 || res.y + height > context->height || context->free_head == 0) { |
| 10803 |
res.prev_link = 0; |
| 10804 |
return res; |
| 10805 |
} |
| 10806 |
|
| 10807 |
|
| 10808 |
node = context->free_head; |
| 10809 |
node->x = (nk_rp_coord) res.x; |
| 10810 |
node->y = (nk_rp_coord) (res.y + height); |
| 10811 |
|
| 10812 |
context->free_head = node->next; |
| 10813 |
|
| 10814 |
|
| 10815 |
|
| 10816 |
|
| 10817 |
cur = *res.prev_link; |
| 10818 |
if (cur->x < res.x) { |
| 10819 |
|
| 10820 |
struct nk_rp_node *next = cur->next; |
| 10821 |
cur->next = node; |
| 10822 |
cur = next; |
| 10823 |
} else { |
| 10824 |
*res.prev_link = node; |
| 10825 |
} |
| 10826 |
|
| 10827 |
|
| 10828 |
|
| 10829 |
while (cur->next && cur->next->x <= res.x + width) { |
| 10830 |
struct nk_rp_node *next = cur->next; |
| 10831 |
|
| 10832 |
cur->next = context->free_head; |
| 10833 |
context->free_head = cur; |
| 10834 |
cur = next; |
| 10835 |
} |
| 10836 |
|
| 10837 |
node->next = cur; |
| 10838 |
|
| 10839 |
if (cur->x < res.x + width) |
| 10840 |
cur->x = (nk_rp_coord) (res.x + width); |
| 10841 |
return res; |
| 10842 |
} |
| 10843 |
NK_INTERN int |
| 10844 |
nk_rect_height_compare(const void *a, const void *b) |
| 10845 |
{ |
| 10846 |
const struct nk_rp_rect *p = (const struct nk_rp_rect *) a; |
| 10847 |
const struct nk_rp_rect *q = (const struct nk_rp_rect *) b; |
| 10848 |
if (p->h > q->h) |
| 10849 |
return -1; |
| 10850 |
if (p->h < q->h) |
| 10851 |
return 1; |
| 10852 |
return (p->w > q->w) ? -1 : (p->w < q->w); |
| 10853 |
} |
| 10854 |
NK_INTERN int |
| 10855 |
nk_rect_original_order(const void *a, const void *b) |
| 10856 |
{ |
| 10857 |
const struct nk_rp_rect *p = (const struct nk_rp_rect *) a; |
| 10858 |
const struct nk_rp_rect *q = (const struct nk_rp_rect *) b; |
| 10859 |
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); |
| 10860 |
} |
| 10861 |
NK_INTERN void |
| 10862 |
nk_rp_qsort(struct nk_rp_rect *array, unsigned int len, int(*cmp)(const void*,const void*)) |
| 10863 |
{ |
| 10864 |
|
| 10865 |
#define NK_MAX_SORT_STACK 64 |
| 10866 |
unsigned right, left = 0, stack[NK_MAX_SORT_STACK], pos = 0; |
| 10867 |
unsigned seed = len/2 * 69069+1; |
| 10868 |
for (;;) { |
| 10869 |
for (; left+1 < len; len++) { |
| 10870 |
struct nk_rp_rect pivot, tmp; |
| 10871 |
if (pos == NK_MAX_SORT_STACK) len = stack[pos = 0]; |
| 10872 |
pivot = array[left+seed%(len-left)]; |
| 10873 |
seed = seed * 69069 + 1; |
| 10874 |
stack[pos++] = len; |
| 10875 |
for (right = left-1;;) { |
| 10876 |
while (cmp(&array[++right], &pivot) < 0); |
| 10877 |
while (cmp(&pivot, &array[--len]) < 0); |
| 10878 |
if (right >= len) break; |
| 10879 |
tmp = array[right]; |
| 10880 |
array[right] = array[len]; |
| 10881 |
array[len] = tmp; |
| 10882 |
} |
| 10883 |
} |
| 10884 |
if (pos == 0) break; |
| 10885 |
left = len; |
| 10886 |
len = stack[--pos]; |
| 10887 |
} |
| 10888 |
#undef NK_MAX_SORT_STACK |
| 10889 |
} |
| 10890 |
NK_INTERN void |
| 10891 |
nk_rp_pack_rects(struct nk_rp_context *context, struct nk_rp_rect *rects, int num_rects) |
| 10892 |
{ |
| 10893 |
int i; |
| 10894 |
|
| 10895 |
for (i=0; i < num_rects; ++i) { |
| 10896 |
rects[i].was_packed = i; |
| 10897 |
} |
| 10898 |
|
| 10899 |
|
| 10900 |
nk_rp_qsort(rects, (unsigned)num_rects, nk_rect_height_compare); |
| 10901 |
|
| 10902 |
for (i=0; i < num_rects; ++i) { |
| 10903 |
struct nk_rp__findresult fr = nk_rp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); |
| 10904 |
if (fr.prev_link) { |
| 10905 |
rects[i].x = (nk_rp_coord) fr.x; |
| 10906 |
rects[i].y = (nk_rp_coord) fr.y; |
| 10907 |
} else { |
| 10908 |
rects[i].x = rects[i].y = NK_RP__MAXVAL; |
| 10909 |
} |
| 10910 |
} |
| 10911 |
|
| 10912 |
|
| 10913 |
nk_rp_qsort(rects, (unsigned)num_rects, nk_rect_original_order); |
| 10914 |
|
| 10915 |
|
| 10916 |
for (i=0; i < num_rects; ++i) |
| 10917 |
rects[i].was_packed = !(rects[i].x == NK_RP__MAXVAL && rects[i].y == NK_RP__MAXVAL); |
| 10918 |
} |
| 10919 |
|
| 10920 |
|
| 10921 |
|
| 10922 |
|
| 10923 |
|
| 10924 |
|
| 10925 |
|
| 10926 |
|
| 10927 |
|
| 10928 |
#define NK_TT_MAX_OVERSAMPLE 8 |
| 10929 |
#define NK_TT__OVER_MASK (NK_TT_MAX_OVERSAMPLE-1) |
| 10930 |
|
| 10931 |
struct nk_tt_bakedchar { |
| 10932 |
unsigned short x0,y0,x1,y1; |
| 10933 |
|
| 10934 |
float xoff,yoff,xadvance; |
| 10935 |
}; |
| 10936 |
|
| 10937 |
struct nk_tt_aligned_quad{ |
| 10938 |
float x0,y0,s0,t0; |
| 10939 |
float x1,y1,s1,t1; |
| 10940 |
}; |
| 10941 |
|
| 10942 |
struct nk_tt_packedchar { |
| 10943 |
unsigned short x0,y0,x1,y1; |
| 10944 |
|
| 10945 |
float xoff,yoff,xadvance; |
| 10946 |
float xoff2,yoff2; |
| 10947 |
}; |
| 10948 |
|
| 10949 |
struct nk_tt_pack_range { |
| 10950 |
float font_size; |
| 10951 |
int first_unicode_codepoint_in_range; |
| 10952 |
|
| 10953 |
int *array_of_unicode_codepoints; |
| 10954 |
|
| 10955 |
int num_chars; |
| 10956 |
struct nk_tt_packedchar *chardata_for_range; |
| 10957 |
unsigned char h_oversample, v_oversample; |
| 10958 |
|
| 10959 |
}; |
| 10960 |
|
| 10961 |
struct nk_tt_pack_context { |
| 10962 |
void *pack_info; |
| 10963 |
int width; |
| 10964 |
int height; |
| 10965 |
int stride_in_bytes; |
| 10966 |
int padding; |
| 10967 |
unsigned int h_oversample, v_oversample; |
| 10968 |
unsigned char *pixels; |
| 10969 |
void *nodes; |
| 10970 |
}; |
| 10971 |
|
| 10972 |
struct nk_tt_fontinfo { |
| 10973 |
const unsigned char* data; |
| 10974 |
int fontstart; |
| 10975 |
int numGlyphs; |
| 10976 |
int loca,head,glyf,hhea,hmtx,kern; |
| 10977 |
int index_map; |
| 10978 |
int indexToLocFormat; |
| 10979 |
}; |
| 10980 |
|
| 10981 |
enum { |
| 10982 |
NK_TT_vmove=1, |
| 10983 |
NK_TT_vline, |
| 10984 |
NK_TT_vcurve |
| 10985 |
}; |
| 10986 |
|
| 10987 |
struct nk_tt_vertex { |
| 10988 |
short x,y,cx,cy; |
| 10989 |
unsigned char type,padding; |
| 10990 |
}; |
| 10991 |
|
| 10992 |
struct nk_tt__bitmap{ |
| 10993 |
int w,h,stride; |
| 10994 |
unsigned char *pixels; |
| 10995 |
}; |
| 10996 |
|
| 10997 |
struct nk_tt__hheap_chunk { |
| 10998 |
struct nk_tt__hheap_chunk *next; |
| 10999 |
}; |
| 11000 |
struct nk_tt__hheap { |
| 11001 |
struct nk_allocator alloc; |
| 11002 |
struct nk_tt__hheap_chunk *head; |
| 11003 |
void *first_free; |
| 11004 |
int num_remaining_in_head_chunk; |
| 11005 |
}; |
| 11006 |
|
| 11007 |
struct nk_tt__edge { |
| 11008 |
float x0,y0, x1,y1; |
| 11009 |
int invert; |
| 11010 |
}; |
| 11011 |
|
| 11012 |
struct nk_tt__active_edge { |
| 11013 |
struct nk_tt__active_edge *next; |
| 11014 |
float fx,fdx,fdy; |
| 11015 |
float direction; |
| 11016 |
float sy; |
| 11017 |
float ey; |
| 11018 |
}; |
| 11019 |
struct nk_tt__point {float x,y;}; |
| 11020 |
|
| 11021 |
#define NK_TT_MACSTYLE_DONTCARE 0 |
| 11022 |
#define NK_TT_MACSTYLE_BOLD 1 |
| 11023 |
#define NK_TT_MACSTYLE_ITALIC 2 |
| 11024 |
#define NK_TT_MACSTYLE_UNDERSCORE 4 |
| 11025 |
#define NK_TT_MACSTYLE_NONE 8 |
| 11026 |
|
| 11027 |
|
| 11028 |
enum { |
| 11029 |
NK_TT_PLATFORM_ID_UNICODE =0, |
| 11030 |
NK_TT_PLATFORM_ID_MAC =1, |
| 11031 |
NK_TT_PLATFORM_ID_ISO =2, |
| 11032 |
NK_TT_PLATFORM_ID_MICROSOFT =3 |
| 11033 |
}; |
| 11034 |
|
| 11035 |
enum { |
| 11036 |
NK_TT_UNICODE_EID_UNICODE_1_0 =0, |
| 11037 |
NK_TT_UNICODE_EID_UNICODE_1_1 =1, |
| 11038 |
NK_TT_UNICODE_EID_ISO_10646 =2, |
| 11039 |
NK_TT_UNICODE_EID_UNICODE_2_0_BMP=3, |
| 11040 |
NK_TT_UNICODE_EID_UNICODE_2_0_FULL=4 |
| 11041 |
}; |
| 11042 |
|
| 11043 |
enum { |
| 11044 |
NK_TT_MS_EID_SYMBOL =0, |
| 11045 |
NK_TT_MS_EID_UNICODE_BMP =1, |
| 11046 |
NK_TT_MS_EID_SHIFTJIS =2, |
| 11047 |
NK_TT_MS_EID_UNICODE_FULL =10 |
| 11048 |
}; |
| 11049 |
|
| 11050 |
enum { |
| 11051 |
NK_TT_MAC_EID_ROMAN =0, NK_TT_MAC_EID_ARABIC =4, |
| 11052 |
NK_TT_MAC_EID_JAPANESE =1, NK_TT_MAC_EID_HEBREW =5, |
| 11053 |
NK_TT_MAC_EID_CHINESE_TRAD =2, NK_TT_MAC_EID_GREEK =6, |
| 11054 |
NK_TT_MAC_EID_KOREAN =3, NK_TT_MAC_EID_RUSSIAN =7 |
| 11055 |
}; |
| 11056 |
|
| 11057 |
enum { |
| 11058 |
|
| 11059 |
NK_TT_MS_LANG_ENGLISH =0x0409, NK_TT_MS_LANG_ITALIAN =0x0410, |
| 11060 |
NK_TT_MS_LANG_CHINESE =0x0804, NK_TT_MS_LANG_JAPANESE =0x0411, |
| 11061 |
NK_TT_MS_LANG_DUTCH =0x0413, NK_TT_MS_LANG_KOREAN =0x0412, |
| 11062 |
NK_TT_MS_LANG_FRENCH =0x040c, NK_TT_MS_LANG_RUSSIAN =0x0419, |
| 11063 |
NK_TT_MS_LANG_GERMAN =0x0407, NK_TT_MS_LANG_SPANISH =0x0409, |
| 11064 |
NK_TT_MS_LANG_HEBREW =0x040d, NK_TT_MS_LANG_SWEDISH =0x041D |
| 11065 |
}; |
| 11066 |
|
| 11067 |
enum { |
| 11068 |
NK_TT_MAC_LANG_ENGLISH =0 , NK_TT_MAC_LANG_JAPANESE =11, |
| 11069 |
NK_TT_MAC_LANG_ARABIC =12, NK_TT_MAC_LANG_KOREAN =23, |
| 11070 |
NK_TT_MAC_LANG_DUTCH =4 , NK_TT_MAC_LANG_RUSSIAN =32, |
| 11071 |
NK_TT_MAC_LANG_FRENCH =1 , NK_TT_MAC_LANG_SPANISH =6 , |
| 11072 |
NK_TT_MAC_LANG_GERMAN =2 , NK_TT_MAC_LANG_SWEDISH =5 , |
| 11073 |
NK_TT_MAC_LANG_HEBREW =10, NK_TT_MAC_LANG_CHINESE_SIMPLIFIED =33, |
| 11074 |
NK_TT_MAC_LANG_ITALIAN =3 , NK_TT_MAC_LANG_CHINESE_TRAD =19 |
| 11075 |
}; |
| 11076 |
|
| 11077 |
#define nk_ttBYTE(p) (* (const nk_byte *) (p)) |
| 11078 |
#define nk_ttCHAR(p) (* (const char *) (p)) |
| 11079 |
|
| 11080 |
#if defined(NK_BIGENDIAN) && !defined(NK_ALLOW_UNALIGNED_TRUETYPE) |
| 11081 |
#define nk_ttUSHORT(p) (* (nk_ushort *) (p)) |
| 11082 |
#define nk_ttSHORT(p) (* (nk_short *) (p)) |
| 11083 |
#define nk_ttULONG(p) (* (nk_uint *) (p)) |
| 11084 |
#define nk_ttLONG(p) (* (nk_int *) (p)) |
| 11085 |
#else |
| 11086 |
static nk_ushort nk_ttUSHORT(const nk_byte *p) { return (nk_ushort)(p[0]*256 + p[1]); } |
| 11087 |
static nk_short nk_ttSHORT(const nk_byte *p) { return (nk_short)(p[0]*256 + p[1]); } |
| 11088 |
static nk_uint nk_ttULONG(const nk_byte *p) { return (nk_uint)((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]); } |
| 11089 |
#endif |
| 11090 |
|
| 11091 |
#define nk_tt_tag4(p,c0,c1,c2,c3)\ |
| 11092 |
((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3)) |
| 11093 |
#define nk_tt_tag(p,str) nk_tt_tag4(p,str[0],str[1],str[2],str[3]) |
| 11094 |
|
| 11095 |
NK_INTERN int nk_tt_GetGlyphShape(const struct nk_tt_fontinfo *info, struct nk_allocator *alloc, |
| 11096 |
int glyph_index, struct nk_tt_vertex **pvertices); |
| 11097 |
|
| 11098 |
NK_INTERN nk_uint |
| 11099 |
nk_tt__find_table(const nk_byte *data, nk_uint fontstart, const char *tag) |
| 11100 |
{ |
| 11101 |
|
| 11102 |
nk_int num_tables = nk_ttUSHORT(data+fontstart+4); |
| 11103 |
nk_uint tabledir = fontstart + 12; |
| 11104 |
nk_int i; |
| 11105 |
for (i = 0; i < num_tables; ++i) { |
| 11106 |
nk_uint loc = tabledir + (nk_uint)(16*i); |
| 11107 |
if (nk_tt_tag(data+loc+0, tag)) |
| 11108 |
return nk_ttULONG(data+loc+8); |
| 11109 |
} |
| 11110 |
return 0; |
| 11111 |
} |
| 11112 |
NK_INTERN int |
| 11113 |
nk_tt_InitFont(struct nk_tt_fontinfo *info, const unsigned char *data2, int fontstart) |
| 11114 |
{ |
| 11115 |
nk_uint cmap, t; |
| 11116 |
nk_int i,numTables; |
| 11117 |
const nk_byte *data = (const nk_byte *) data2; |
| 11118 |
|
| 11119 |
info->data = data; |
| 11120 |
info->fontstart = fontstart; |
| 11121 |
|
| 11122 |
cmap = nk_tt__find_table(data, (nk_uint)fontstart, "cmap"); |
| 11123 |
info->loca = (int)nk_tt__find_table(data, (nk_uint)fontstart, "loca"); |
| 11124 |
info->head = (int)nk_tt__find_table(data, (nk_uint)fontstart, "head"); |
| 11125 |
info->glyf = (int)nk_tt__find_table(data, (nk_uint)fontstart, "glyf"); |
| 11126 |
info->hhea = (int)nk_tt__find_table(data, (nk_uint)fontstart, "hhea"); |
| 11127 |
info->hmtx = (int)nk_tt__find_table(data, (nk_uint)fontstart, "hmtx"); |
| 11128 |
info->kern = (int)nk_tt__find_table(data, (nk_uint)fontstart, "kern"); |
| 11129 |
if (!cmap || !info->loca || !info->head || !info->glyf || !info->hhea || !info->hmtx) |
| 11130 |
return 0; |
| 11131 |
|
| 11132 |
t = nk_tt__find_table(data, (nk_uint)fontstart, "maxp"); |
| 11133 |
if (t) info->numGlyphs = nk_ttUSHORT(data+t+4); |
| 11134 |
else info->numGlyphs = 0xffff; |
| 11135 |
|
| 11136 |
|
| 11137 |
|
| 11138 |
|
| 11139 |
numTables = nk_ttUSHORT(data + cmap + 2); |
| 11140 |
info->index_map = 0; |
| 11141 |
for (i=0; i < numTables; ++i) |
| 11142 |
{ |
| 11143 |
nk_uint encoding_record = cmap + 4 + 8 * (nk_uint)i; |
| 11144 |
|
| 11145 |
switch(nk_ttUSHORT(data+encoding_record)) { |
| 11146 |
case NK_TT_PLATFORM_ID_MICROSOFT: |
| 11147 |
switch (nk_ttUSHORT(data+encoding_record+2)) { |
| 11148 |
case NK_TT_MS_EID_UNICODE_BMP: |
| 11149 |
case NK_TT_MS_EID_UNICODE_FULL: |
| 11150 |
|
| 11151 |
info->index_map = (int)(cmap + nk_ttULONG(data+encoding_record+4)); |
| 11152 |
break; |
| 11153 |
default: break; |
| 11154 |
} break; |
| 11155 |
case NK_TT_PLATFORM_ID_UNICODE: |
| 11156 |
|
| 11157 |
|
| 11158 |
info->index_map = (int)(cmap + nk_ttULONG(data+encoding_record+4)); |
| 11159 |
break; |
| 11160 |
default: break; |
| 11161 |
} |
| 11162 |
} |
| 11163 |
if (info->index_map == 0) |
| 11164 |
return 0; |
| 11165 |
info->indexToLocFormat = nk_ttUSHORT(data+info->head + 50); |
| 11166 |
return 1; |
| 11167 |
} |
| 11168 |
NK_INTERN int |
| 11169 |
nk_tt_FindGlyphIndex(const struct nk_tt_fontinfo *info, int unicode_codepoint) |
| 11170 |
{ |
| 11171 |
const nk_byte *data = info->data; |
| 11172 |
nk_uint index_map = (nk_uint)info->index_map; |
| 11173 |
|
| 11174 |
nk_ushort format = nk_ttUSHORT(data + index_map + 0); |
| 11175 |
if (format == 0) { |
| 11176 |
nk_int bytes = nk_ttUSHORT(data + index_map + 2); |
| 11177 |
if (unicode_codepoint < bytes-6) |
| 11178 |
return nk_ttBYTE(data + index_map + 6 + unicode_codepoint); |
| 11179 |
return 0; |
| 11180 |
} else if (format == 6) { |
| 11181 |
nk_uint first = nk_ttUSHORT(data + index_map + 6); |
| 11182 |
nk_uint count = nk_ttUSHORT(data + index_map + 8); |
| 11183 |
if ((nk_uint) unicode_codepoint >= first && (nk_uint) unicode_codepoint < first+count) |
| 11184 |
return nk_ttUSHORT(data + index_map + 10 + (unicode_codepoint - (int)first)*2); |
| 11185 |
return 0; |
| 11186 |
} else if (format == 2) { |
| 11187 |
NK_ASSERT(0); |
| 11188 |
return 0; |
| 11189 |
} else if (format == 4) { |
| 11190 |
nk_ushort segcount = nk_ttUSHORT(data+index_map+6) >> 1; |
| 11191 |
nk_ushort searchRange = nk_ttUSHORT(data+index_map+8) >> 1; |
| 11192 |
nk_ushort entrySelector = nk_ttUSHORT(data+index_map+10); |
| 11193 |
nk_ushort rangeShift = nk_ttUSHORT(data+index_map+12) >> 1; |
| 11194 |
|
| 11195 |
|
| 11196 |
nk_uint endCount = index_map + 14; |
| 11197 |
nk_uint search = endCount; |
| 11198 |
|
| 11199 |
if (unicode_codepoint > 0xffff) |
| 11200 |
return 0; |
| 11201 |
|
| 11202 |
|
| 11203 |
|
| 11204 |
if (unicode_codepoint >= nk_ttUSHORT(data + search + rangeShift*2)) |
| 11205 |
search += (nk_uint)(rangeShift*2); |
| 11206 |
|
| 11207 |
|
| 11208 |
search -= 2; |
| 11209 |
while (entrySelector) { |
| 11210 |
nk_ushort end; |
| 11211 |
searchRange >>= 1; |
| 11212 |
end = nk_ttUSHORT(data + search + searchRange*2); |
| 11213 |
if (unicode_codepoint > end) |
| 11214 |
search += (nk_uint)(searchRange*2); |
| 11215 |
--entrySelector; |
| 11216 |
} |
| 11217 |
search += 2; |
| 11218 |
|
| 11219 |
{ |
| 11220 |
nk_ushort offset, start; |
| 11221 |
nk_ushort item = (nk_ushort) ((search - endCount) >> 1); |
| 11222 |
|
| 11223 |
NK_ASSERT(unicode_codepoint <= nk_ttUSHORT(data + endCount + 2*item)); |
| 11224 |
start = nk_ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item); |
| 11225 |
if (unicode_codepoint < start) |
| 11226 |
return 0; |
| 11227 |
|
| 11228 |
offset = nk_ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item); |
| 11229 |
if (offset == 0) |
| 11230 |
return (nk_ushort) (unicode_codepoint + nk_ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item)); |
| 11231 |
|
| 11232 |
return nk_ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item); |
| 11233 |
} |
| 11234 |
} else if (format == 12 || format == 13) { |
| 11235 |
nk_uint ngroups = nk_ttULONG(data+index_map+12); |
| 11236 |
nk_int low,high; |
| 11237 |
low = 0; high = (nk_int)ngroups; |
| 11238 |
|
| 11239 |
while (low < high) { |
| 11240 |
nk_int mid = low + ((high-low) >> 1); |
| 11241 |
nk_uint start_char = nk_ttULONG(data+index_map+16+mid*12); |
| 11242 |
nk_uint end_char = nk_ttULONG(data+index_map+16+mid*12+4); |
| 11243 |
if ((nk_uint) unicode_codepoint < start_char) |
| 11244 |
high = mid; |
| 11245 |
else if ((nk_uint) unicode_codepoint > end_char) |
| 11246 |
low = mid+1; |
| 11247 |
else { |
| 11248 |
nk_uint start_glyph = nk_ttULONG(data+index_map+16+mid*12+8); |
| 11249 |
if (format == 12) |
| 11250 |
return (int)start_glyph + (int)unicode_codepoint - (int)start_char; |
| 11251 |
else |
| 11252 |
return (int)start_glyph; |
| 11253 |
} |
| 11254 |
} |
| 11255 |
return 0; |
| 11256 |
} |
| 11257 |
|
| 11258 |
NK_ASSERT(0); |
| 11259 |
return 0; |
| 11260 |
} |
| 11261 |
NK_INTERN void |
| 11262 |
nk_tt_setvertex(struct nk_tt_vertex *v, nk_byte type, nk_int x, nk_int y, nk_int cx, nk_int cy) |
| 11263 |
{ |
| 11264 |
v->type = type; |
| 11265 |
v->x = (nk_short) x; |
| 11266 |
v->y = (nk_short) y; |
| 11267 |
v->cx = (nk_short) cx; |
| 11268 |
v->cy = (nk_short) cy; |
| 11269 |
} |
| 11270 |
NK_INTERN int |
| 11271 |
nk_tt__GetGlyfOffset(const struct nk_tt_fontinfo *info, int glyph_index) |
| 11272 |
{ |
| 11273 |
int g1,g2; |
| 11274 |
if (glyph_index >= info->numGlyphs) return -1; |
| 11275 |
if (info->indexToLocFormat >= 2) return -1; |
| 11276 |
|
| 11277 |
if (info->indexToLocFormat == 0) { |
| 11278 |
g1 = info->glyf + nk_ttUSHORT(info->data + info->loca + glyph_index * 2) * 2; |
| 11279 |
g2 = info->glyf + nk_ttUSHORT(info->data + info->loca + glyph_index * 2 + 2) * 2; |
| 11280 |
} else { |
| 11281 |
g1 = info->glyf + (int)nk_ttULONG (info->data + info->loca + glyph_index * 4); |
| 11282 |
g2 = info->glyf + (int)nk_ttULONG (info->data + info->loca + glyph_index * 4 + 4); |
| 11283 |
} |
| 11284 |
return g1==g2 ? -1 : g1; |
| 11285 |
} |
| 11286 |
NK_INTERN int |
| 11287 |
nk_tt_GetGlyphBox(const struct nk_tt_fontinfo *info, int glyph_index, |
| 11288 |
int *x0, int *y0, int *x1, int *y1) |
| 11289 |
{ |
| 11290 |
int g = nk_tt__GetGlyfOffset(info, glyph_index); |
| 11291 |
if (g < 0) return 0; |
| 11292 |
|
| 11293 |
if (x0) *x0 = nk_ttSHORT(info->data + g + 2); |
| 11294 |
if (y0) *y0 = nk_ttSHORT(info->data + g + 4); |
| 11295 |
if (x1) *x1 = nk_ttSHORT(info->data + g + 6); |
| 11296 |
if (y1) *y1 = nk_ttSHORT(info->data + g + 8); |
| 11297 |
return 1; |
| 11298 |
} |
| 11299 |
NK_INTERN int |
| 11300 |
nk_tt__close_shape(struct nk_tt_vertex *vertices, int num_vertices, int was_off, |
| 11301 |
int start_off, nk_int sx, nk_int sy, nk_int scx, nk_int scy, nk_int cx, nk_int cy) |
| 11302 |
{ |
| 11303 |
if (start_off) { |
| 11304 |
if (was_off) |
| 11305 |
nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, (cx+scx)>>1, (cy+scy)>>1, cx,cy); |
| 11306 |
nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, sx,sy,scx,scy); |
| 11307 |
} else { |
| 11308 |
if (was_off) |
| 11309 |
nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve,sx,sy,cx,cy); |
| 11310 |
else |
| 11311 |
nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vline,sx,sy,0,0); |
| 11312 |
} |
| 11313 |
return num_vertices; |
| 11314 |
} |
| 11315 |
NK_INTERN int |
| 11316 |
nk_tt_GetGlyphShape(const struct nk_tt_fontinfo *info, struct nk_allocator *alloc, |
| 11317 |
int glyph_index, struct nk_tt_vertex **pvertices) |
| 11318 |
{ |
| 11319 |
nk_short numberOfContours; |
| 11320 |
const nk_byte *endPtsOfContours; |
| 11321 |
const nk_byte *data = info->data; |
| 11322 |
struct nk_tt_vertex *vertices=0; |
| 11323 |
int num_vertices=0; |
| 11324 |
int g = nk_tt__GetGlyfOffset(info, glyph_index); |
| 11325 |
*pvertices = 0; |
| 11326 |
|
| 11327 |
if (g < 0) return 0; |
| 11328 |
numberOfContours = nk_ttSHORT(data + g); |
| 11329 |
if (numberOfContours > 0) { |
| 11330 |
nk_byte flags=0,flagcount; |
| 11331 |
nk_int ins, i,j=0,m,n, next_move, was_off=0, off, start_off=0; |
| 11332 |
nk_int x,y,cx,cy,sx,sy, scx,scy; |
| 11333 |
const nk_byte *points; |
| 11334 |
endPtsOfContours = (data + g + 10); |
| 11335 |
ins = nk_ttUSHORT(data + g + 10 + numberOfContours * 2); |
| 11336 |
points = data + g + 10 + numberOfContours * 2 + 2 + ins; |
| 11337 |
|
| 11338 |
n = 1+nk_ttUSHORT(endPtsOfContours + numberOfContours*2-2); |
| 11339 |
m = n + 2*numberOfContours; |
| 11340 |
vertices = (struct nk_tt_vertex *)alloc->alloc(alloc->userdata, 0, (nk_size)m * sizeof(vertices[0])); |
| 11341 |
if (vertices == 0) |
| 11342 |
return 0; |
| 11343 |
|
| 11344 |
next_move = 0; |
| 11345 |
flagcount=0; |
| 11346 |
|
| 11347 |
|
| 11348 |
|
| 11349 |
|
| 11350 |
off = m - n; |
| 11351 |
|
| 11352 |
|
| 11353 |
for (i=0; i < n; ++i) { |
| 11354 |
if (flagcount == 0) { |
| 11355 |
flags = *points++; |
| 11356 |
if (flags & 8) |
| 11357 |
flagcount = *points++; |
| 11358 |
} else --flagcount; |
| 11359 |
vertices[off+i].type = flags; |
| 11360 |
} |
| 11361 |
|
| 11362 |
|
| 11363 |
x=0; |
| 11364 |
for (i=0; i < n; ++i) { |
| 11365 |
flags = vertices[off+i].type; |
| 11366 |
if (flags & 2) { |
| 11367 |
nk_short dx = *points++; |
| 11368 |
x += (flags & 16) ? dx : -dx; |
| 11369 |
} else { |
| 11370 |
if (!(flags & 16)) { |
| 11371 |
x = x + (nk_short) (points[0]*256 + points[1]); |
| 11372 |
points += 2; |
| 11373 |
} |
| 11374 |
} |
| 11375 |
vertices[off+i].x = (nk_short) x; |
| 11376 |
} |
| 11377 |
|
| 11378 |
|
| 11379 |
y=0; |
| 11380 |
for (i=0; i < n; ++i) { |
| 11381 |
flags = vertices[off+i].type; |
| 11382 |
if (flags & 4) { |
| 11383 |
nk_short dy = *points++; |
| 11384 |
y += (flags & 32) ? dy : -dy; |
| 11385 |
} else { |
| 11386 |
if (!(flags & 32)) { |
| 11387 |
y = y + (nk_short) (points[0]*256 + points[1]); |
| 11388 |
points += 2; |
| 11389 |
} |
| 11390 |
} |
| 11391 |
vertices[off+i].y = (nk_short) y; |
| 11392 |
} |
| 11393 |
|
| 11394 |
|
| 11395 |
num_vertices=0; |
| 11396 |
sx = sy = cx = cy = scx = scy = 0; |
| 11397 |
for (i=0; i < n; ++i) |
| 11398 |
{ |
| 11399 |
flags = vertices[off+i].type; |
| 11400 |
x = (nk_short) vertices[off+i].x; |
| 11401 |
y = (nk_short) vertices[off+i].y; |
| 11402 |
|
| 11403 |
if (next_move == i) { |
| 11404 |
if (i != 0) |
| 11405 |
num_vertices = nk_tt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy); |
| 11406 |
|
| 11407 |
|
| 11408 |
start_off = !(flags & 1); |
| 11409 |
if (start_off) { |
| 11410 |
|
| 11411 |
|
| 11412 |
scx = x; |
| 11413 |
scy = y; |
| 11414 |
if (!(vertices[off+i+1].type & 1)) { |
| 11415 |
|
| 11416 |
sx = (x + (nk_int) vertices[off+i+1].x) >> 1; |
| 11417 |
sy = (y + (nk_int) vertices[off+i+1].y) >> 1; |
| 11418 |
} else { |
| 11419 |
|
| 11420 |
sx = (nk_int) vertices[off+i+1].x; |
| 11421 |
sy = (nk_int) vertices[off+i+1].y; |
| 11422 |
++i; |
| 11423 |
} |
| 11424 |
} else { |
| 11425 |
sx = x; |
| 11426 |
sy = y; |
| 11427 |
} |
| 11428 |
nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vmove,sx,sy,0,0); |
| 11429 |
was_off = 0; |
| 11430 |
next_move = 1 + nk_ttUSHORT(endPtsOfContours+j*2); |
| 11431 |
++j; |
| 11432 |
} else { |
| 11433 |
if (!(flags & 1)) |
| 11434 |
{ |
| 11435 |
if (was_off) |
| 11436 |
nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, (cx+x)>>1, (cy+y)>>1, cx, cy); |
| 11437 |
cx = x; |
| 11438 |
cy = y; |
| 11439 |
was_off = 1; |
| 11440 |
} else { |
| 11441 |
if (was_off) |
| 11442 |
nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, x,y, cx, cy); |
| 11443 |
else nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vline, x,y,0,0); |
| 11444 |
was_off = 0; |
| 11445 |
} |
| 11446 |
} |
| 11447 |
} |
| 11448 |
num_vertices = nk_tt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy); |
| 11449 |
} else if (numberOfContours == -1) { |
| 11450 |
|
| 11451 |
int more = 1; |
| 11452 |
const nk_byte *comp = data + g + 10; |
| 11453 |
num_vertices = 0; |
| 11454 |
vertices = 0; |
| 11455 |
|
| 11456 |
while (more) |
| 11457 |
{ |
| 11458 |
nk_ushort flags, gidx; |
| 11459 |
int comp_num_verts = 0, i; |
| 11460 |
struct nk_tt_vertex *comp_verts = 0, *tmp = 0; |
| 11461 |
float mtx[6] = {1,0,0,1,0,0}, m, n; |
| 11462 |
|
| 11463 |
flags = (nk_ushort)nk_ttSHORT(comp); comp+=2; |
| 11464 |
gidx = (nk_ushort)nk_ttSHORT(comp); comp+=2; |
| 11465 |
|
| 11466 |
if (flags & 2) { |
| 11467 |
if (flags & 1) { |
| 11468 |
mtx[4] = nk_ttSHORT(comp); comp+=2; |
| 11469 |
mtx[5] = nk_ttSHORT(comp); comp+=2; |
| 11470 |
} else { |
| 11471 |
mtx[4] = nk_ttCHAR(comp); comp+=1; |
| 11472 |
mtx[5] = nk_ttCHAR(comp); comp+=1; |
| 11473 |
} |
| 11474 |
} else { |
| 11475 |
|
| 11476 |
NK_ASSERT(0); |
| 11477 |
} |
| 11478 |
if (flags & (1<<3)) { |
| 11479 |
mtx[0] = mtx[3] = nk_ttSHORT(comp)/16384.0f; comp+=2; |
| 11480 |
mtx[1] = mtx[2] = 0; |
| 11481 |
} else if (flags & (1<<6)) { |
| 11482 |
mtx[0] = nk_ttSHORT(comp)/16384.0f; comp+=2; |
| 11483 |
mtx[1] = mtx[2] = 0; |
| 11484 |
mtx[3] = nk_ttSHORT(comp)/16384.0f; comp+=2; |
| 11485 |
} else if (flags & (1<<7)) { |
| 11486 |
mtx[0] = nk_ttSHORT(comp)/16384.0f; comp+=2; |
| 11487 |
mtx[1] = nk_ttSHORT(comp)/16384.0f; comp+=2; |
| 11488 |
mtx[2] = nk_ttSHORT(comp)/16384.0f; comp+=2; |
| 11489 |
mtx[3] = nk_ttSHORT(comp)/16384.0f; comp+=2; |
| 11490 |
} |
| 11491 |
|
| 11492 |
|
| 11493 |
m = (float) NK_SQRT(mtx[0]*mtx[0] + mtx[1]*mtx[1]); |
| 11494 |
n = (float) NK_SQRT(mtx[2]*mtx[2] + mtx[3]*mtx[3]); |
| 11495 |
|
| 11496 |
|
| 11497 |
comp_num_verts = nk_tt_GetGlyphShape(info, alloc, gidx, &comp_verts); |
| 11498 |
if (comp_num_verts > 0) |
| 11499 |
{ |
| 11500 |
|
| 11501 |
for (i = 0; i < comp_num_verts; ++i) { |
| 11502 |
struct nk_tt_vertex* v = &comp_verts[i]; |
| 11503 |
short x,y; |
| 11504 |
x=v->x; y=v->y; |
| 11505 |
v->x = (short)(m * (mtx[0]*x + mtx[2]*y + mtx[4])); |
| 11506 |
v->y = (short)(n * (mtx[1]*x + mtx[3]*y + mtx[5])); |
| 11507 |
x=v->cx; y=v->cy; |
| 11508 |
v->cx = (short)(m * (mtx[0]*x + mtx[2]*y + mtx[4])); |
| 11509 |
v->cy = (short)(n * (mtx[1]*x + mtx[3]*y + mtx[5])); |
| 11510 |
} |
| 11511 |
|
| 11512 |
tmp = (struct nk_tt_vertex*)alloc->alloc(alloc->userdata, 0, |
| 11513 |
(nk_size)(num_vertices+comp_num_verts)*sizeof(struct nk_tt_vertex)); |
| 11514 |
if (!tmp) { |
| 11515 |
if (vertices) alloc->free(alloc->userdata, vertices); |
| 11516 |
if (comp_verts) alloc->free(alloc->userdata, comp_verts); |
| 11517 |
return 0; |
| 11518 |
} |
| 11519 |
if (num_vertices > 0) NK_MEMCPY(tmp, vertices, (nk_size)num_vertices*sizeof(struct nk_tt_vertex)); |
| 11520 |
NK_MEMCPY(tmp+num_vertices, comp_verts, (nk_size)comp_num_verts*sizeof(struct nk_tt_vertex)); |
| 11521 |
if (vertices) alloc->free(alloc->userdata,vertices); |
| 11522 |
vertices = tmp; |
| 11523 |
alloc->free(alloc->userdata,comp_verts); |
| 11524 |
num_vertices += comp_num_verts; |
| 11525 |
} |
| 11526 |
|
| 11527 |
more = flags & (1<<5); |
| 11528 |
} |
| 11529 |
} else if (numberOfContours < 0) { |
| 11530 |
|
| 11531 |
NK_ASSERT(0); |
| 11532 |
} else { |
| 11533 |
|
| 11534 |
} |
| 11535 |
*pvertices = vertices; |
| 11536 |
return num_vertices; |
| 11537 |
} |
| 11538 |
NK_INTERN void |
| 11539 |
nk_tt_GetGlyphHMetrics(const struct nk_tt_fontinfo *info, int glyph_index, |
| 11540 |
int *advanceWidth, int *leftSideBearing) |
| 11541 |
{ |
| 11542 |
nk_ushort numOfLongHorMetrics = nk_ttUSHORT(info->data+info->hhea + 34); |
| 11543 |
if (glyph_index < numOfLongHorMetrics) { |
| 11544 |
if (advanceWidth) |
| 11545 |
*advanceWidth = nk_ttSHORT(info->data + info->hmtx + 4*glyph_index); |
| 11546 |
if (leftSideBearing) |
| 11547 |
*leftSideBearing = nk_ttSHORT(info->data + info->hmtx + 4*glyph_index + 2); |
| 11548 |
} else { |
| 11549 |
if (advanceWidth) |
| 11550 |
*advanceWidth = nk_ttSHORT(info->data + info->hmtx + 4*(numOfLongHorMetrics-1)); |
| 11551 |
if (leftSideBearing) |
| 11552 |
*leftSideBearing = nk_ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics)); |
| 11553 |
} |
| 11554 |
} |
| 11555 |
NK_INTERN void |
| 11556 |
nk_tt_GetFontVMetrics(const struct nk_tt_fontinfo *info, |
| 11557 |
int *ascent, int *descent, int *lineGap) |
| 11558 |
{ |
| 11559 |
if (ascent ) *ascent = nk_ttSHORT(info->data+info->hhea + 4); |
| 11560 |
if (descent) *descent = nk_ttSHORT(info->data+info->hhea + 6); |
| 11561 |
if (lineGap) *lineGap = nk_ttSHORT(info->data+info->hhea + 8); |
| 11562 |
} |
| 11563 |
NK_INTERN float |
| 11564 |
nk_tt_ScaleForPixelHeight(const struct nk_tt_fontinfo *info, float height) |
| 11565 |
{ |
| 11566 |
int fheight = nk_ttSHORT(info->data + info->hhea + 4) - nk_ttSHORT(info->data + info->hhea + 6); |
| 11567 |
return (float) height / (float)fheight; |
| 11568 |
} |
| 11569 |
NK_INTERN float |
| 11570 |
nk_tt_ScaleForMappingEmToPixels(const struct nk_tt_fontinfo *info, float pixels) |
| 11571 |
{ |
| 11572 |
int unitsPerEm = nk_ttUSHORT(info->data + info->head + 18); |
| 11573 |
return pixels / (float)unitsPerEm; |
| 11574 |
} |
| 11575 |
|
| 11576 |
|
| 11577 |
|
| 11578 |
|
| 11579 |
NK_INTERN void |
| 11580 |
nk_tt_GetGlyphBitmapBoxSubpixel(const struct nk_tt_fontinfo *font, |
| 11581 |
int glyph, float scale_x, float scale_y,float shift_x, float shift_y, |
| 11582 |
int *ix0, int *iy0, int *ix1, int *iy1) |
| 11583 |
{ |
| 11584 |
int x0,y0,x1,y1; |
| 11585 |
if (!nk_tt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) { |
| 11586 |
|
| 11587 |
if (ix0) *ix0 = 0; |
| 11588 |
if (iy0) *iy0 = 0; |
| 11589 |
if (ix1) *ix1 = 0; |
| 11590 |
if (iy1) *iy1 = 0; |
| 11591 |
} else { |
| 11592 |
|
| 11593 |
if (ix0) *ix0 = nk_ifloorf((float)x0 * scale_x + shift_x); |
| 11594 |
if (iy0) *iy0 = nk_ifloorf((float)-y1 * scale_y + shift_y); |
| 11595 |
if (ix1) *ix1 = nk_iceilf ((float)x1 * scale_x + shift_x); |
| 11596 |
if (iy1) *iy1 = nk_iceilf ((float)-y0 * scale_y + shift_y); |
| 11597 |
} |
| 11598 |
} |
| 11599 |
NK_INTERN void |
| 11600 |
nk_tt_GetGlyphBitmapBox(const struct nk_tt_fontinfo *font, int glyph, |
| 11601 |
float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1) |
| 11602 |
{ |
| 11603 |
nk_tt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1); |
| 11604 |
} |
| 11605 |
|
| 11606 |
|
| 11607 |
|
| 11608 |
|
| 11609 |
NK_INTERN void* |
| 11610 |
nk_tt__hheap_alloc(struct nk_tt__hheap *hh, nk_size size) |
| 11611 |
{ |
| 11612 |
if (hh->first_free) { |
| 11613 |
void *p = hh->first_free; |
| 11614 |
hh->first_free = * (void **) p; |
| 11615 |
return p; |
| 11616 |
} else { |
| 11617 |
if (hh->num_remaining_in_head_chunk == 0) { |
| 11618 |
int count = (size < 32 ? 2000 : size < 128 ? 800 : 100); |
| 11619 |
struct nk_tt__hheap_chunk *c = (struct nk_tt__hheap_chunk *) |
| 11620 |
hh->alloc.alloc(hh->alloc.userdata, 0, |
| 11621 |
sizeof(struct nk_tt__hheap_chunk) + size * (nk_size)count); |
| 11622 |
if (c == 0) return 0; |
| 11623 |
c->next = hh->head; |
| 11624 |
hh->head = c; |
| 11625 |
hh->num_remaining_in_head_chunk = count; |
| 11626 |
} |
| 11627 |
--hh->num_remaining_in_head_chunk; |
| 11628 |
return (char *) (hh->head) + size * (nk_size)hh->num_remaining_in_head_chunk; |
| 11629 |
} |
| 11630 |
} |
| 11631 |
NK_INTERN void |
| 11632 |
nk_tt__hheap_free(struct nk_tt__hheap *hh, void *p) |
| 11633 |
{ |
| 11634 |
*(void **) p = hh->first_free; |
| 11635 |
hh->first_free = p; |
| 11636 |
} |
| 11637 |
NK_INTERN void |
| 11638 |
nk_tt__hheap_cleanup(struct nk_tt__hheap *hh) |
| 11639 |
{ |
| 11640 |
struct nk_tt__hheap_chunk *c = hh->head; |
| 11641 |
while (c) { |
| 11642 |
struct nk_tt__hheap_chunk *n = c->next; |
| 11643 |
hh->alloc.free(hh->alloc.userdata, c); |
| 11644 |
c = n; |
| 11645 |
} |
| 11646 |
} |
| 11647 |
NK_INTERN struct nk_tt__active_edge* |
| 11648 |
nk_tt__new_active(struct nk_tt__hheap *hh, struct nk_tt__edge *e, |
| 11649 |
int off_x, float start_point) |
| 11650 |
{ |
| 11651 |
struct nk_tt__active_edge *z = (struct nk_tt__active_edge *) |
| 11652 |
nk_tt__hheap_alloc(hh, sizeof(*z)); |
| 11653 |
float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); |
| 11654 |
|
| 11655 |
if (!z) return z; |
| 11656 |
z->fdx = dxdy; |
| 11657 |
z->fdy = (dxdy != 0) ? (1/dxdy): 0; |
| 11658 |
z->fx = e->x0 + dxdy * (start_point - e->y0); |
| 11659 |
z->fx -= (float)off_x; |
| 11660 |
z->direction = e->invert ? 1.0f : -1.0f; |
| 11661 |
z->sy = e->y0; |
| 11662 |
z->ey = e->y1; |
| 11663 |
z->next = 0; |
| 11664 |
return z; |
| 11665 |
} |
| 11666 |
NK_INTERN void |
| 11667 |
nk_tt__handle_clipped_edge(float *scanline, int x, struct nk_tt__active_edge *e, |
| 11668 |
float x0, float y0, float x1, float y1) |
| 11669 |
{ |
| 11670 |
if (y0 == y1) return; |
| 11671 |
NK_ASSERT(y0 < y1); |
| 11672 |
NK_ASSERT(e->sy <= e->ey); |
| 11673 |
if (y0 > e->ey) return; |
| 11674 |
if (y1 < e->sy) return; |
| 11675 |
if (y0 < e->sy) { |
| 11676 |
x0 += (x1-x0) * (e->sy - y0) / (y1-y0); |
| 11677 |
y0 = e->sy; |
| 11678 |
} |
| 11679 |
if (y1 > e->ey) { |
| 11680 |
x1 += (x1-x0) * (e->ey - y1) / (y1-y0); |
| 11681 |
y1 = e->ey; |
| 11682 |
} |
| 11683 |
|
| 11684 |
if (x0 == x) NK_ASSERT(x1 <= x+1); |
| 11685 |
else if (x0 == x+1) NK_ASSERT(x1 >= x); |
| 11686 |
else if (x0 <= x) NK_ASSERT(x1 <= x); |
| 11687 |
else if (x0 >= x+1) NK_ASSERT(x1 >= x+1); |
| 11688 |
else NK_ASSERT(x1 >= x && x1 <= x+1); |
| 11689 |
|
| 11690 |
if (x0 <= x && x1 <= x) |
| 11691 |
scanline[x] += e->direction * (y1-y0); |
| 11692 |
else if (x0 >= x+1 && x1 >= x+1); |
| 11693 |
else { |
| 11694 |
NK_ASSERT(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1); |
| 11695 |
|
| 11696 |
scanline[x] += (float)e->direction * (float)(y1-y0) * (1.0f-((x0-(float)x)+(x1-(float)x))/2.0f); |
| 11697 |
} |
| 11698 |
} |
| 11699 |
NK_INTERN void |
| 11700 |
nk_tt__fill_active_edges_new(float *scanline, float *scanline_fill, int len, |
| 11701 |
struct nk_tt__active_edge *e, float y_top) |
| 11702 |
{ |
| 11703 |
float y_bottom = y_top+1; |
| 11704 |
while (e) |
| 11705 |
{ |
| 11706 |
|
| 11707 |
|
| 11708 |
NK_ASSERT(e->ey >= y_top); |
| 11709 |
if (e->fdx == 0) { |
| 11710 |
float x0 = e->fx; |
| 11711 |
if (x0 < len) { |
| 11712 |
if (x0 >= 0) { |
| 11713 |
nk_tt__handle_clipped_edge(scanline,(int) x0,e, x0,y_top, x0,y_bottom); |
| 11714 |
nk_tt__handle_clipped_edge(scanline_fill-1,(int) x0+1,e, x0,y_top, x0,y_bottom); |
| 11715 |
} else { |
| 11716 |
nk_tt__handle_clipped_edge(scanline_fill-1,0,e, x0,y_top, x0,y_bottom); |
| 11717 |
} |
| 11718 |
} |
| 11719 |
} else { |
| 11720 |
float x0 = e->fx; |
| 11721 |
float dx = e->fdx; |
| 11722 |
float xb = x0 + dx; |
| 11723 |
float x_top, x_bottom; |
| 11724 |
float y0,y1; |
| 11725 |
float dy = e->fdy; |
| 11726 |
NK_ASSERT(e->sy <= y_bottom && e->ey >= y_top); |
| 11727 |
|
| 11728 |
|
| 11729 |
|
| 11730 |
|
| 11731 |
if (e->sy > y_top) { |
| 11732 |
x_top = x0 + dx * (e->sy - y_top); |
| 11733 |
y0 = e->sy; |
| 11734 |
} else { |
| 11735 |
x_top = x0; |
| 11736 |
y0 = y_top; |
| 11737 |
} |
| 11738 |
|
| 11739 |
if (e->ey < y_bottom) { |
| 11740 |
x_bottom = x0 + dx * (e->ey - y_top); |
| 11741 |
y1 = e->ey; |
| 11742 |
} else { |
| 11743 |
x_bottom = xb; |
| 11744 |
y1 = y_bottom; |
| 11745 |
} |
| 11746 |
|
| 11747 |
if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len) |
| 11748 |
{ |
| 11749 |
|
| 11750 |
if ((int) x_top == (int) x_bottom) { |
| 11751 |
float height; |
| 11752 |
|
| 11753 |
int x = (int) x_top; |
| 11754 |
height = y1 - y0; |
| 11755 |
NK_ASSERT(x >= 0 && x < len); |
| 11756 |
scanline[x] += e->direction * (1.0f-(((float)x_top - (float)x) + ((float)x_bottom-(float)x))/2.0f) * (float)height; |
| 11757 |
scanline_fill[x] += e->direction * (float)height; |
| 11758 |
} else { |
| 11759 |
int x,x1,x2; |
| 11760 |
float y_crossing, step, sign, area; |
| 11761 |
|
| 11762 |
if (x_top > x_bottom) |
| 11763 |
{ |
| 11764 |
|
| 11765 |
float t; |
| 11766 |
y0 = y_bottom - (y0 - y_top); |
| 11767 |
y1 = y_bottom - (y1 - y_top); |
| 11768 |
t = y0; y0 = y1; y1 = t; |
| 11769 |
t = x_bottom; x_bottom = x_top; x_top = t; |
| 11770 |
dx = -dx; |
| 11771 |
dy = -dy; |
| 11772 |
t = x0; x0 = xb; xb = t; |
| 11773 |
} |
| 11774 |
|
| 11775 |
x1 = (int) x_top; |
| 11776 |
x2 = (int) x_bottom; |
| 11777 |
|
| 11778 |
y_crossing = ((float)x1+1 - (float)x0) * (float)dy + (float)y_top; |
| 11779 |
|
| 11780 |
sign = e->direction; |
| 11781 |
|
| 11782 |
area = sign * (y_crossing-y0); |
| 11783 |
|
| 11784 |
scanline[x1] += area * (1.0f-((float)((float)x_top - (float)x1)+(float)(x1+1-x1))/2.0f); |
| 11785 |
|
| 11786 |
step = sign * dy; |
| 11787 |
for (x = x1+1; x < x2; ++x) { |
| 11788 |
scanline[x] += area + step/2; |
| 11789 |
area += step; |
| 11790 |
} |
| 11791 |
y_crossing += (float)dy * (float)(x2 - (x1+1)); |
| 11792 |
|
| 11793 |
scanline[x2] += area + sign * (1.0f-((float)(x2-x2)+((float)x_bottom-(float)x2))/2.0f) * (y1-y_crossing); |
| 11794 |
scanline_fill[x2] += sign * (y1-y0); |
| 11795 |
} |
| 11796 |
} |
| 11797 |
else |
| 11798 |
{ |
| 11799 |
|
| 11800 |
|
| 11801 |
|
| 11802 |
|
| 11803 |
int x; |
| 11804 |
for (x=0; x < len; ++x) |
| 11805 |
{ |
| 11806 |
|
| 11807 |
|
| 11808 |
|
| 11809 |
|
| 11810 |
|
| 11811 |
|
| 11812 |
|
| 11813 |
|
| 11814 |
|
| 11815 |
|
| 11816 |
|
| 11817 |
|
| 11818 |
|
| 11819 |
|
| 11820 |
float ya = y_top; |
| 11821 |
float x1 = (float) (x); |
| 11822 |
float x2 = (float) (x+1); |
| 11823 |
float x3 = xb; |
| 11824 |
float y3 = y_bottom; |
| 11825 |
float yb,y2; |
| 11826 |
|
| 11827 |
yb = ((float)x - x0) / dx + y_top; |
| 11828 |
y2 = ((float)x+1 - x0) / dx + y_top; |
| 11829 |
|
| 11830 |
if (x0 < x1 && x3 > x2) { |
| 11831 |
nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x1,yb); |
| 11832 |
nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x2,y2); |
| 11833 |
nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); |
| 11834 |
} else if (x3 < x1 && x0 > x2) { |
| 11835 |
nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x2,y2); |
| 11836 |
nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x1,yb); |
| 11837 |
nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x3,y3); |
| 11838 |
} else if (x0 < x1 && x3 > x1) { |
| 11839 |
nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x1,yb); |
| 11840 |
nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x3,y3); |
| 11841 |
} else if (x3 < x1 && x0 > 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 (x0 < x2 && x3 > x2) { |
| 11845 |
nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x2,y2); |
| 11846 |
nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); |
| 11847 |
} else if (x3 < x2 && x0 > 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 { |
| 11851 |
nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x3,y3); |
| 11852 |
} |
| 11853 |
} |
| 11854 |
} |
| 11855 |
} |
| 11856 |
e = e->next; |
| 11857 |
} |
| 11858 |
} |
| 11859 |
NK_INTERN void |
| 11860 |
nk_tt__rasterize_sorted_edges(struct nk_tt__bitmap *result, struct nk_tt__edge *e, |
| 11861 |
int n, int vsubsample, int off_x, int off_y, struct nk_allocator *alloc) |
| 11862 |
{ |
| 11863 |
|
| 11864 |
struct nk_tt__hheap hh; |
| 11865 |
struct nk_tt__active_edge *active = 0; |
| 11866 |
int y,j=0, i; |
| 11867 |
float scanline_data[129], *scanline, *scanline2; |
| 11868 |
|
| 11869 |
NK_UNUSED(vsubsample); |
| 11870 |
nk_zero_struct(hh); |
| 11871 |
hh.alloc = *alloc; |
| 11872 |
|
| 11873 |
if (result->w > 64) |
| 11874 |
scanline = (float *) alloc->alloc(alloc->userdata,0, (nk_size)(result->w*2+1) * sizeof(float)); |
| 11875 |
else scanline = scanline_data; |
| 11876 |
|
| 11877 |
scanline2 = scanline + result->w; |
| 11878 |
y = off_y; |
| 11879 |
e[n].y0 = (float) (off_y + result->h) + 1; |
| 11880 |
|
| 11881 |
while (j < result->h) |
| 11882 |
{ |
| 11883 |
|
| 11884 |
float scan_y_top = (float)y + 0.0f; |
| 11885 |
float scan_y_bottom = (float)y + 1.0f; |
| 11886 |
struct nk_tt__active_edge **step = &active; |
| 11887 |
|
| 11888 |
NK_MEMSET(scanline , 0, (nk_size)result->w*sizeof(scanline[0])); |
| 11889 |
NK_MEMSET(scanline2, 0, (nk_size)(result->w+1)*sizeof(scanline[0])); |
| 11890 |
|
| 11891 |
|
| 11892 |
|
| 11893 |
while (*step) { |
| 11894 |
struct nk_tt__active_edge * z = *step; |
| 11895 |
if (z->ey <= scan_y_top) { |
| 11896 |
*step = z->next; |
| 11897 |
NK_ASSERT(z->direction); |
| 11898 |
z->direction = 0; |
| 11899 |
nk_tt__hheap_free(&hh, z); |
| 11900 |
} else { |
| 11901 |
step = &((*step)->next); |
| 11902 |
} |
| 11903 |
} |
| 11904 |
|
| 11905 |
|
| 11906 |
while (e->y0 <= scan_y_bottom) { |
| 11907 |
if (e->y0 != e->y1) { |
| 11908 |
struct nk_tt__active_edge *z = nk_tt__new_active(&hh, e, off_x, scan_y_top); |
| 11909 |
if (z != 0) { |
| 11910 |
NK_ASSERT(z->ey >= scan_y_top); |
| 11911 |
|
| 11912 |
z->next = active; |
| 11913 |
active = z; |
| 11914 |
} |
| 11915 |
} |
| 11916 |
++e; |
| 11917 |
} |
| 11918 |
|
| 11919 |
|
| 11920 |
if (active) |
| 11921 |
nk_tt__fill_active_edges_new(scanline, scanline2+1, result->w, active, scan_y_top); |
| 11922 |
|
| 11923 |
{ |
| 11924 |
float sum = 0; |
| 11925 |
for (i=0; i < result->w; ++i) { |
| 11926 |
float k; |
| 11927 |
int m; |
| 11928 |
sum += scanline2[i]; |
| 11929 |
k = scanline[i] + sum; |
| 11930 |
k = (float) NK_ABS(k) * 255.0f + 0.5f; |
| 11931 |
m = (int) k; |
| 11932 |
if (m > 255) m = 255; |
| 11933 |
result->pixels[j*result->stride + i] = (unsigned char) m; |
| 11934 |
} |
| 11935 |
} |
| 11936 |
|
| 11937 |
step = &active; |
| 11938 |
while (*step) { |
| 11939 |
struct nk_tt__active_edge *z = *step; |
| 11940 |
z->fx += z->fdx; |
| 11941 |
step = &((*step)->next); |
| 11942 |
} |
| 11943 |
++y; |
| 11944 |
++j; |
| 11945 |
} |
| 11946 |
nk_tt__hheap_cleanup(&hh); |
| 11947 |
if (scanline != scanline_data) |
| 11948 |
alloc->free(alloc->userdata, scanline); |
| 11949 |
} |
| 11950 |
NK_INTERN void |
| 11951 |
nk_tt__sort_edges_ins_sort(struct nk_tt__edge *p, int n) |
| 11952 |
{ |
| 11953 |
int i,j; |
| 11954 |
#define NK_TT__COMPARE(a,b) ((a)->y0 < (b)->y0) |
| 11955 |
for (i=1; i < n; ++i) { |
| 11956 |
struct nk_tt__edge t = p[i], *a = &t; |
| 11957 |
j = i; |
| 11958 |
while (j > 0) { |
| 11959 |
struct nk_tt__edge *b = &p[j-1]; |
| 11960 |
int c = NK_TT__COMPARE(a,b); |
| 11961 |
if (!c) break; |
| 11962 |
p[j] = p[j-1]; |
| 11963 |
--j; |
| 11964 |
} |
| 11965 |
if (i != j) |
| 11966 |
p[j] = t; |
| 11967 |
} |
| 11968 |
} |
| 11969 |
NK_INTERN void |
| 11970 |
nk_tt__sort_edges_quicksort(struct nk_tt__edge *p, int n) |
| 11971 |
{ |
| 11972 |
|
| 11973 |
while (n > 12) { |
| 11974 |
struct nk_tt__edge t; |
| 11975 |
int c01,c12,c,m,i,j; |
| 11976 |
|
| 11977 |
|
| 11978 |
m = n >> 1; |
| 11979 |
c01 = NK_TT__COMPARE(&p[0],&p[m]); |
| 11980 |
c12 = NK_TT__COMPARE(&p[m],&p[n-1]); |
| 11981 |
|
| 11982 |
|
| 11983 |
if (c01 != c12) { |
| 11984 |
|
| 11985 |
int z; |
| 11986 |
c = NK_TT__COMPARE(&p[0],&p[n-1]); |
| 11987 |
|
| 11988 |
|
| 11989 |
z = (c == c12) ? 0 : n-1; |
| 11990 |
t = p[z]; |
| 11991 |
p[z] = p[m]; |
| 11992 |
p[m] = t; |
| 11993 |
} |
| 11994 |
|
| 11995 |
|
| 11996 |
|
| 11997 |
t = p[0]; |
| 11998 |
p[0] = p[m]; |
| 11999 |
p[m] = t; |
| 12000 |
|
| 12001 |
|
| 12002 |
i=1; |
| 12003 |
j=n-1; |
| 12004 |
for(;;) { |
| 12005 |
|
| 12006 |
|
| 12007 |
for (;;++i) { |
| 12008 |
if (!NK_TT__COMPARE(&p[i], &p[0])) break; |
| 12009 |
} |
| 12010 |
for (;;--j) { |
| 12011 |
if (!NK_TT__COMPARE(&p[0], &p[j])) break; |
| 12012 |
} |
| 12013 |
|
| 12014 |
|
| 12015 |
if (i >= j) break; |
| 12016 |
t = p[i]; |
| 12017 |
p[i] = p[j]; |
| 12018 |
p[j] = t; |
| 12019 |
|
| 12020 |
++i; |
| 12021 |
--j; |
| 12022 |
|
| 12023 |
} |
| 12024 |
|
| 12025 |
|
| 12026 |
if (j < (n-i)) { |
| 12027 |
nk_tt__sort_edges_quicksort(p,j); |
| 12028 |
p = p+i; |
| 12029 |
n = n-i; |
| 12030 |
} else { |
| 12031 |
nk_tt__sort_edges_quicksort(p+i, n-i); |
| 12032 |
n = j; |
| 12033 |
} |
| 12034 |
} |
| 12035 |
} |
| 12036 |
NK_INTERN void |
| 12037 |
nk_tt__sort_edges(struct nk_tt__edge *p, int n) |
| 12038 |
{ |
| 12039 |
nk_tt__sort_edges_quicksort(p, n); |
| 12040 |
nk_tt__sort_edges_ins_sort(p, n); |
| 12041 |
} |
| 12042 |
NK_INTERN void |
| 12043 |
nk_tt__rasterize(struct nk_tt__bitmap *result, struct nk_tt__point *pts, |
| 12044 |
int *wcount, int windings, float scale_x, float scale_y, |
| 12045 |
float shift_x, float shift_y, int off_x, int off_y, int invert, |
| 12046 |
struct nk_allocator *alloc) |
| 12047 |
{ |
| 12048 |
float y_scale_inv = invert ? -scale_y : scale_y; |
| 12049 |
struct nk_tt__edge *e; |
| 12050 |
int n,i,j,k,m; |
| 12051 |
int vsubsample = 1; |
| 12052 |
|
| 12053 |
|
| 12054 |
|
| 12055 |
n = 0; |
| 12056 |
for (i=0; i < windings; ++i) |
| 12057 |
n += wcount[i]; |
| 12058 |
|
| 12059 |
e = (struct nk_tt__edge*) |
| 12060 |
alloc->alloc(alloc->userdata, 0,(sizeof(*e) * (nk_size)(n+1))); |
| 12061 |
if (e == 0) return; |
| 12062 |
n = 0; |
| 12063 |
|
| 12064 |
m=0; |
| 12065 |
for (i=0; i < windings; ++i) |
| 12066 |
{ |
| 12067 |
struct nk_tt__point *p = pts + m; |
| 12068 |
m += wcount[i]; |
| 12069 |
j = wcount[i]-1; |
| 12070 |
for (k=0; k < wcount[i]; j=k++) { |
| 12071 |
int a=k,b=j; |
| 12072 |
|
| 12073 |
if (p[j].y == p[k].y) |
| 12074 |
continue; |
| 12075 |
|
| 12076 |
|
| 12077 |
e[n].invert = 0; |
| 12078 |
if (invert ? p[j].y > p[k].y : p[j].y < p[k].y) { |
| 12079 |
e[n].invert = 1; |
| 12080 |
a=j,b=k; |
| 12081 |
} |
| 12082 |
e[n].x0 = p[a].x * scale_x + shift_x; |
| 12083 |
e[n].y0 = (p[a].y * y_scale_inv + shift_y) * (float)vsubsample; |
| 12084 |
e[n].x1 = p[b].x * scale_x + shift_x; |
| 12085 |
e[n].y1 = (p[b].y * y_scale_inv + shift_y) * (float)vsubsample; |
| 12086 |
++n; |
| 12087 |
} |
| 12088 |
} |
| 12089 |
|
| 12090 |
|
| 12091 |
|
| 12092 |
nk_tt__sort_edges(e, n); |
| 12093 |
|
| 12094 |
nk_tt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, alloc); |
| 12095 |
alloc->free(alloc->userdata, e); |
| 12096 |
} |
| 12097 |
NK_INTERN void |
| 12098 |
nk_tt__add_point(struct nk_tt__point *points, int n, float x, float y) |
| 12099 |
{ |
| 12100 |
if (!points) return; |
| 12101 |
points[n].x = x; |
| 12102 |
points[n].y = y; |
| 12103 |
} |
| 12104 |
NK_INTERN int |
| 12105 |
nk_tt__tesselate_curve(struct nk_tt__point *points, int *num_points, |
| 12106 |
float x0, float y0, float x1, float y1, float x2, float y2, |
| 12107 |
float objspace_flatness_squared, int n) |
| 12108 |
{ |
| 12109 |
|
| 12110 |
|
| 12111 |
|
| 12112 |
float mx = (x0 + 2*x1 + x2)/4; |
| 12113 |
float my = (y0 + 2*y1 + y2)/4; |
| 12114 |
|
| 12115 |
float dx = (x0+x2)/2 - mx; |
| 12116 |
float dy = (y0+y2)/2 - my; |
| 12117 |
if (n > 16) |
| 12118 |
return 1; |
| 12119 |
|
| 12120 |
|
| 12121 |
if (dx*dx+dy*dy > objspace_flatness_squared) { |
| 12122 |
nk_tt__tesselate_curve(points, num_points, x0,y0, |
| 12123 |
(x0+x1)/2.0f,(y0+y1)/2.0f, mx,my, objspace_flatness_squared,n+1); |
| 12124 |
nk_tt__tesselate_curve(points, num_points, mx,my, |
| 12125 |
(x1+x2)/2.0f,(y1+y2)/2.0f, x2,y2, objspace_flatness_squared,n+1); |
| 12126 |
} else { |
| 12127 |
nk_tt__add_point(points, *num_points,x2,y2); |
| 12128 |
*num_points = *num_points+1; |
| 12129 |
} |
| 12130 |
return 1; |
| 12131 |
} |
| 12132 |
NK_INTERN struct nk_tt__point* |
| 12133 |
nk_tt_FlattenCurves(struct nk_tt_vertex *vertices, int num_verts, |
| 12134 |
float objspace_flatness, int **contour_lengths, int *num_contours, |
| 12135 |
struct nk_allocator *alloc) |
| 12136 |
{ |
| 12137 |
|
| 12138 |
struct nk_tt__point *points=0; |
| 12139 |
int num_points=0; |
| 12140 |
float objspace_flatness_squared = objspace_flatness * objspace_flatness; |
| 12141 |
int i; |
| 12142 |
int n=0; |
| 12143 |
int start=0; |
| 12144 |
int pass; |
| 12145 |
|
| 12146 |
|
| 12147 |
for (i=0; i < num_verts; ++i) |
| 12148 |
if (vertices[i].type == NK_TT_vmove) ++n; |
| 12149 |
|
| 12150 |
*num_contours = n; |
| 12151 |
if (n == 0) return 0; |
| 12152 |
|
| 12153 |
*contour_lengths = (int *) |
| 12154 |
alloc->alloc(alloc->userdata,0, (sizeof(**contour_lengths) * (nk_size)n)); |
| 12155 |
if (*contour_lengths == 0) { |
| 12156 |
*num_contours = 0; |
| 12157 |
return 0; |
| 12158 |
} |
| 12159 |
|
| 12160 |
|
| 12161 |
for (pass=0; pass < 2; ++pass) |
| 12162 |
{ |
| 12163 |
float x=0,y=0; |
| 12164 |
if (pass == 1) { |
| 12165 |
points = (struct nk_tt__point *) |
| 12166 |
alloc->alloc(alloc->userdata,0, (nk_size)num_points * sizeof(points[0])); |
| 12167 |
if (points == 0) goto error; |
| 12168 |
} |
| 12169 |
num_points = 0; |
| 12170 |
n= -1; |
| 12171 |
|
| 12172 |
for (i=0; i < num_verts; ++i) |
| 12173 |
{ |
| 12174 |
switch (vertices[i].type) { |
| 12175 |
case NK_TT_vmove: |
| 12176 |
|
| 12177 |
if (n >= 0) |
| 12178 |
(*contour_lengths)[n] = num_points - start; |
| 12179 |
++n; |
| 12180 |
start = num_points; |
| 12181 |
|
| 12182 |
x = vertices[i].x, y = vertices[i].y; |
| 12183 |
nk_tt__add_point(points, num_points++, x,y); |
| 12184 |
break; |
| 12185 |
case NK_TT_vline: |
| 12186 |
x = vertices[i].x, y = vertices[i].y; |
| 12187 |
nk_tt__add_point(points, num_points++, x, y); |
| 12188 |
break; |
| 12189 |
case NK_TT_vcurve: |
| 12190 |
nk_tt__tesselate_curve(points, &num_points, x,y, |
| 12191 |
vertices[i].cx, vertices[i].cy, |
| 12192 |
vertices[i].x, vertices[i].y, |
| 12193 |
objspace_flatness_squared, 0); |
| 12194 |
x = vertices[i].x, y = vertices[i].y; |
| 12195 |
break; |
| 12196 |
default: break; |
| 12197 |
} |
| 12198 |
} |
| 12199 |
(*contour_lengths)[n] = num_points - start; |
| 12200 |
} |
| 12201 |
return points; |
| 12202 |
|
| 12203 |
error: |
| 12204 |
alloc->free(alloc->userdata, points); |
| 12205 |
alloc->free(alloc->userdata, *contour_lengths); |
| 12206 |
*contour_lengths = 0; |
| 12207 |
*num_contours = 0; |
| 12208 |
return 0; |
| 12209 |
} |
| 12210 |
NK_INTERN void |
| 12211 |
nk_tt_Rasterize(struct nk_tt__bitmap *result, float flatness_in_pixels, |
| 12212 |
struct nk_tt_vertex *vertices, int num_verts, |
| 12213 |
float scale_x, float scale_y, float shift_x, float shift_y, |
| 12214 |
int x_off, int y_off, int invert, struct nk_allocator *alloc) |
| 12215 |
{ |
| 12216 |
float scale = scale_x > scale_y ? scale_y : scale_x; |
| 12217 |
int winding_count, *winding_lengths; |
| 12218 |
struct nk_tt__point *windings = nk_tt_FlattenCurves(vertices, num_verts, |
| 12219 |
flatness_in_pixels / scale, &winding_lengths, &winding_count, alloc); |
| 12220 |
|
| 12221 |
NK_ASSERT(alloc); |
| 12222 |
if (windings) { |
| 12223 |
nk_tt__rasterize(result, windings, winding_lengths, winding_count, |
| 12224 |
scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, alloc); |
| 12225 |
alloc->free(alloc->userdata, winding_lengths); |
| 12226 |
alloc->free(alloc->userdata, windings); |
| 12227 |
} |
| 12228 |
} |
| 12229 |
NK_INTERN void |
| 12230 |
nk_tt_MakeGlyphBitmapSubpixel(const struct nk_tt_fontinfo *info, unsigned char *output, |
| 12231 |
int out_w, int out_h, int out_stride, float scale_x, float scale_y, |
| 12232 |
float shift_x, float shift_y, int glyph, struct nk_allocator *alloc) |
| 12233 |
{ |
| 12234 |
int ix0,iy0; |
| 12235 |
struct nk_tt_vertex *vertices; |
| 12236 |
int num_verts = nk_tt_GetGlyphShape(info, alloc, glyph, &vertices); |
| 12237 |
struct nk_tt__bitmap gbm; |
| 12238 |
|
| 12239 |
nk_tt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x, |
| 12240 |
shift_y, &ix0,&iy0,0,0); |
| 12241 |
gbm.pixels = output; |
| 12242 |
gbm.w = out_w; |
| 12243 |
gbm.h = out_h; |
| 12244 |
gbm.stride = out_stride; |
| 12245 |
|
| 12246 |
if (gbm.w && gbm.h) |
| 12247 |
nk_tt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y, |
| 12248 |
shift_x, shift_y, ix0,iy0, 1, alloc); |
| 12249 |
alloc->free(alloc->userdata, vertices); |
| 12250 |
} |
| 12251 |
|
| 12252 |
|
| 12253 |
|
| 12254 |
|
| 12255 |
NK_INTERN int |
| 12256 |
nk_tt_PackBegin(struct nk_tt_pack_context *spc, unsigned char *pixels, |
| 12257 |
int pw, int ph, int stride_in_bytes, int padding, struct nk_allocator *alloc) |
| 12258 |
{ |
| 12259 |
int num_nodes = pw - padding; |
| 12260 |
struct nk_rp_context *context = (struct nk_rp_context *) |
| 12261 |
alloc->alloc(alloc->userdata,0, sizeof(*context)); |
| 12262 |
struct nk_rp_node *nodes = (struct nk_rp_node*) |
| 12263 |
alloc->alloc(alloc->userdata,0, (sizeof(*nodes ) * (nk_size)num_nodes)); |
| 12264 |
|
| 12265 |
if (context == 0 || nodes == 0) { |
| 12266 |
if (context != 0) alloc->free(alloc->userdata, context); |
| 12267 |
if (nodes != 0) alloc->free(alloc->userdata, nodes); |
| 12268 |
return 0; |
| 12269 |
} |
| 12270 |
|
| 12271 |
spc->width = pw; |
| 12272 |
spc->height = ph; |
| 12273 |
spc->pixels = pixels; |
| 12274 |
spc->pack_info = context; |
| 12275 |
spc->nodes = nodes; |
| 12276 |
spc->padding = padding; |
| 12277 |
spc->stride_in_bytes = (stride_in_bytes != 0) ? stride_in_bytes : pw; |
| 12278 |
spc->h_oversample = 1; |
| 12279 |
spc->v_oversample = 1; |
| 12280 |
|
| 12281 |
nk_rp_init_target(context, pw-padding, ph-padding, nodes, num_nodes); |
| 12282 |
if (pixels) |
| 12283 |
NK_MEMSET(pixels, 0, (nk_size)(pw*ph)); |
| 12284 |
return 1; |
| 12285 |
} |
| 12286 |
NK_INTERN void |
| 12287 |
nk_tt_PackEnd(struct nk_tt_pack_context *spc, struct nk_allocator *alloc) |
| 12288 |
{ |
| 12289 |
alloc->free(alloc->userdata, spc->nodes); |
| 12290 |
alloc->free(alloc->userdata, spc->pack_info); |
| 12291 |
} |
| 12292 |
NK_INTERN void |
| 12293 |
nk_tt_PackSetOversampling(struct nk_tt_pack_context *spc, |
| 12294 |
unsigned int h_oversample, unsigned int v_oversample) |
| 12295 |
{ |
| 12296 |
NK_ASSERT(h_oversample <= NK_TT_MAX_OVERSAMPLE); |
| 12297 |
NK_ASSERT(v_oversample <= NK_TT_MAX_OVERSAMPLE); |
| 12298 |
if (h_oversample <= NK_TT_MAX_OVERSAMPLE) |
| 12299 |
spc->h_oversample = h_oversample; |
| 12300 |
if (v_oversample <= NK_TT_MAX_OVERSAMPLE) |
| 12301 |
spc->v_oversample = v_oversample; |
| 12302 |
} |
| 12303 |
NK_INTERN void |
| 12304 |
nk_tt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, |
| 12305 |
int kernel_width) |
| 12306 |
{ |
| 12307 |
unsigned char buffer[NK_TT_MAX_OVERSAMPLE]; |
| 12308 |
int safe_w = w - kernel_width; |
| 12309 |
int j; |
| 12310 |
|
| 12311 |
for (j=0; j < h; ++j) |
| 12312 |
{ |
| 12313 |
int i; |
| 12314 |
unsigned int total; |
| 12315 |
NK_MEMSET(buffer, 0, (nk_size)kernel_width); |
| 12316 |
|
| 12317 |
total = 0; |
| 12318 |
|
| 12319 |
|
| 12320 |
switch (kernel_width) { |
| 12321 |
case 2: |
| 12322 |
for (i=0; i <= safe_w; ++i) { |
| 12323 |
total += (unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]); |
| 12324 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i]; |
| 12325 |
pixels[i] = (unsigned char) (total / 2); |
| 12326 |
} |
| 12327 |
break; |
| 12328 |
case 3: |
| 12329 |
for (i=0; i <= safe_w; ++i) { |
| 12330 |
total += (unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]); |
| 12331 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i]; |
| 12332 |
pixels[i] = (unsigned char) (total / 3); |
| 12333 |
} |
| 12334 |
break; |
| 12335 |
case 4: |
| 12336 |
for (i=0; i <= safe_w; ++i) { |
| 12337 |
total += (unsigned int)pixels[i] - buffer[i & NK_TT__OVER_MASK]; |
| 12338 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i]; |
| 12339 |
pixels[i] = (unsigned char) (total / 4); |
| 12340 |
} |
| 12341 |
break; |
| 12342 |
case 5: |
| 12343 |
for (i=0; i <= safe_w; ++i) { |
| 12344 |
total += (unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]); |
| 12345 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i]; |
| 12346 |
pixels[i] = (unsigned char) (total / 5); |
| 12347 |
} |
| 12348 |
break; |
| 12349 |
default: |
| 12350 |
for (i=0; i <= safe_w; ++i) { |
| 12351 |
total += (unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]); |
| 12352 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i]; |
| 12353 |
pixels[i] = (unsigned char) (total / (unsigned int)kernel_width); |
| 12354 |
} |
| 12355 |
break; |
| 12356 |
} |
| 12357 |
|
| 12358 |
for (; i < w; ++i) { |
| 12359 |
NK_ASSERT(pixels[i] == 0); |
| 12360 |
total -= (unsigned int)(buffer[i & NK_TT__OVER_MASK]); |
| 12361 |
pixels[i] = (unsigned char) (total / (unsigned int)kernel_width); |
| 12362 |
} |
| 12363 |
pixels += stride_in_bytes; |
| 12364 |
} |
| 12365 |
} |
| 12366 |
NK_INTERN void |
| 12367 |
nk_tt__v_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, |
| 12368 |
int kernel_width) |
| 12369 |
{ |
| 12370 |
unsigned char buffer[NK_TT_MAX_OVERSAMPLE]; |
| 12371 |
int safe_h = h - kernel_width; |
| 12372 |
int j; |
| 12373 |
|
| 12374 |
for (j=0; j < w; ++j) |
| 12375 |
{ |
| 12376 |
int i; |
| 12377 |
unsigned int total; |
| 12378 |
NK_MEMSET(buffer, 0, (nk_size)kernel_width); |
| 12379 |
|
| 12380 |
total = 0; |
| 12381 |
|
| 12382 |
|
| 12383 |
switch (kernel_width) { |
| 12384 |
case 2: |
| 12385 |
for (i=0; i <= safe_h; ++i) { |
| 12386 |
total += (unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]); |
| 12387 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes]; |
| 12388 |
pixels[i*stride_in_bytes] = (unsigned char) (total / 2); |
| 12389 |
} |
| 12390 |
break; |
| 12391 |
case 3: |
| 12392 |
for (i=0; i <= safe_h; ++i) { |
| 12393 |
total += (unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]); |
| 12394 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes]; |
| 12395 |
pixels[i*stride_in_bytes] = (unsigned char) (total / 3); |
| 12396 |
} |
| 12397 |
break; |
| 12398 |
case 4: |
| 12399 |
for (i=0; i <= safe_h; ++i) { |
| 12400 |
total += (unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]); |
| 12401 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes]; |
| 12402 |
pixels[i*stride_in_bytes] = (unsigned char) (total / 4); |
| 12403 |
} |
| 12404 |
break; |
| 12405 |
case 5: |
| 12406 |
for (i=0; i <= safe_h; ++i) { |
| 12407 |
total += (unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]); |
| 12408 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes]; |
| 12409 |
pixels[i*stride_in_bytes] = (unsigned char) (total / 5); |
| 12410 |
} |
| 12411 |
break; |
| 12412 |
default: |
| 12413 |
for (i=0; i <= safe_h; ++i) { |
| 12414 |
total += (unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]); |
| 12415 |
buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes]; |
| 12416 |
pixels[i*stride_in_bytes] = (unsigned char) (total / (unsigned int)kernel_width); |
| 12417 |
} |
| 12418 |
break; |
| 12419 |
} |
| 12420 |
|
| 12421 |
for (; i < h; ++i) { |
| 12422 |
NK_ASSERT(pixels[i*stride_in_bytes] == 0); |
| 12423 |
total -= (unsigned int)(buffer[i & NK_TT__OVER_MASK]); |
| 12424 |
pixels[i*stride_in_bytes] = (unsigned char) (total / (unsigned int)kernel_width); |
| 12425 |
} |
| 12426 |
pixels += 1; |
| 12427 |
} |
| 12428 |
} |
| 12429 |
NK_INTERN float |
| 12430 |
nk_tt__oversample_shift(int oversample) |
| 12431 |
{ |
| 12432 |
if (!oversample) |
| 12433 |
return 0.0f; |
| 12434 |
|
| 12435 |
|
| 12436 |
|
| 12437 |
|
| 12438 |
|
| 12439 |
return (float)-(oversample - 1) / (2.0f * (float)oversample); |
| 12440 |
} |
| 12441 |
NK_INTERN int |
| 12442 |
nk_tt_PackFontRangesGatherRects(struct nk_tt_pack_context *spc, |
| 12443 |
struct nk_tt_fontinfo *info, struct nk_tt_pack_range *ranges, |
| 12444 |
int num_ranges, struct nk_rp_rect *rects) |
| 12445 |
{ |
| 12446 |
|
| 12447 |
int i,j,k; |
| 12448 |
k = 0; |
| 12449 |
|
| 12450 |
for (i=0; i < num_ranges; ++i) { |
| 12451 |
float fh = ranges[i].font_size; |
| 12452 |
float scale = (fh > 0) ? nk_tt_ScaleForPixelHeight(info, fh): |
| 12453 |
nk_tt_ScaleForMappingEmToPixels(info, -fh); |
| 12454 |
ranges[i].h_oversample = (unsigned char) spc->h_oversample; |
| 12455 |
ranges[i].v_oversample = (unsigned char) spc->v_oversample; |
| 12456 |
for (j=0; j < ranges[i].num_chars; ++j) { |
| 12457 |
int x0,y0,x1,y1; |
| 12458 |
int codepoint = ranges[i].first_unicode_codepoint_in_range ? |
| 12459 |
ranges[i].first_unicode_codepoint_in_range + j : |
| 12460 |
ranges[i].array_of_unicode_codepoints[j]; |
| 12461 |
|
| 12462 |
int glyph = nk_tt_FindGlyphIndex(info, codepoint); |
| 12463 |
nk_tt_GetGlyphBitmapBoxSubpixel(info,glyph, scale * (float)spc->h_oversample, |
| 12464 |
scale * (float)spc->v_oversample, 0,0, &x0,&y0,&x1,&y1); |
| 12465 |
rects[k].w = (nk_rp_coord) (x1-x0 + spc->padding + (int)spc->h_oversample-1); |
| 12466 |
rects[k].h = (nk_rp_coord) (y1-y0 + spc->padding + (int)spc->v_oversample-1); |
| 12467 |
++k; |
| 12468 |
} |
| 12469 |
} |
| 12470 |
return k; |
| 12471 |
} |
| 12472 |
NK_INTERN int |
| 12473 |
nk_tt_PackFontRangesRenderIntoRects(struct nk_tt_pack_context *spc, |
| 12474 |
struct nk_tt_fontinfo *info, struct nk_tt_pack_range *ranges, |
| 12475 |
int num_ranges, struct nk_rp_rect *rects, struct nk_allocator *alloc) |
| 12476 |
{ |
| 12477 |
int i,j,k, return_value = 1; |
| 12478 |
|
| 12479 |
int old_h_over = (int)spc->h_oversample; |
| 12480 |
int old_v_over = (int)spc->v_oversample; |
| 12481 |
|
| 12482 |
|
| 12483 |
k = 0; |
| 12484 |
for (i=0; i < num_ranges; ++i) |
| 12485 |
{ |
| 12486 |
float fh = ranges[i].font_size; |
| 12487 |
float recip_h,recip_v,sub_x,sub_y; |
| 12488 |
float scale = fh > 0 ? nk_tt_ScaleForPixelHeight(info, fh): |
| 12489 |
nk_tt_ScaleForMappingEmToPixels(info, -fh); |
| 12490 |
|
| 12491 |
spc->h_oversample = ranges[i].h_oversample; |
| 12492 |
spc->v_oversample = ranges[i].v_oversample; |
| 12493 |
|
| 12494 |
recip_h = 1.0f / (float)spc->h_oversample; |
| 12495 |
recip_v = 1.0f / (float)spc->v_oversample; |
| 12496 |
|
| 12497 |
sub_x = nk_tt__oversample_shift((int)spc->h_oversample); |
| 12498 |
sub_y = nk_tt__oversample_shift((int)spc->v_oversample); |
| 12499 |
|
| 12500 |
for (j=0; j < ranges[i].num_chars; ++j) |
| 12501 |
{ |
| 12502 |
struct nk_rp_rect *r = &rects[k]; |
| 12503 |
if (r->was_packed) |
| 12504 |
{ |
| 12505 |
struct nk_tt_packedchar *bc = &ranges[i].chardata_for_range[j]; |
| 12506 |
int advance, lsb, x0,y0,x1,y1; |
| 12507 |
int codepoint = ranges[i].first_unicode_codepoint_in_range ? |
| 12508 |
ranges[i].first_unicode_codepoint_in_range + j : |
| 12509 |
ranges[i].array_of_unicode_codepoints[j]; |
| 12510 |
int glyph = nk_tt_FindGlyphIndex(info, codepoint); |
| 12511 |
nk_rp_coord pad = (nk_rp_coord) spc->padding; |
| 12512 |
|
| 12513 |
|
| 12514 |
r->x = (nk_rp_coord)((int)r->x + (int)pad); |
| 12515 |
r->y = (nk_rp_coord)((int)r->y + (int)pad); |
| 12516 |
r->w = (nk_rp_coord)((int)r->w - (int)pad); |
| 12517 |
r->h = (nk_rp_coord)((int)r->h - (int)pad); |
| 12518 |
|
| 12519 |
nk_tt_GetGlyphHMetrics(info, glyph, &advance, &lsb); |
| 12520 |
nk_tt_GetGlyphBitmapBox(info, glyph, scale * (float)spc->h_oversample, |
| 12521 |
(scale * (float)spc->v_oversample), &x0,&y0,&x1,&y1); |
| 12522 |
nk_tt_MakeGlyphBitmapSubpixel(info, spc->pixels + r->x + r->y*spc->stride_in_bytes, |
| 12523 |
(int)(r->w - spc->h_oversample+1), (int)(r->h - spc->v_oversample+1), |
| 12524 |
spc->stride_in_bytes, scale * (float)spc->h_oversample, |
| 12525 |
scale * (float)spc->v_oversample, 0,0, glyph, alloc); |
| 12526 |
|
| 12527 |
if (spc->h_oversample > 1) |
| 12528 |
nk_tt__h_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes, |
| 12529 |
r->w, r->h, spc->stride_in_bytes, (int)spc->h_oversample); |
| 12530 |
|
| 12531 |
if (spc->v_oversample > 1) |
| 12532 |
nk_tt__v_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes, |
| 12533 |
r->w, r->h, spc->stride_in_bytes, (int)spc->v_oversample); |
| 12534 |
|
| 12535 |
bc->x0 = (nk_ushort) r->x; |
| 12536 |
bc->y0 = (nk_ushort) r->y; |
| 12537 |
bc->x1 = (nk_ushort) (r->x + r->w); |
| 12538 |
bc->y1 = (nk_ushort) (r->y + r->h); |
| 12539 |
bc->xadvance = scale * (float)advance; |
| 12540 |
bc->xoff = (float) x0 * recip_h + sub_x; |
| 12541 |
bc->yoff = (float) y0 * recip_v + sub_y; |
| 12542 |
bc->xoff2 = ((float)x0 + r->w) * recip_h + sub_x; |
| 12543 |
bc->yoff2 = ((float)y0 + r->h) * recip_v + sub_y; |
| 12544 |
} else { |
| 12545 |
return_value = 0; |
| 12546 |
} |
| 12547 |
++k; |
| 12548 |
} |
| 12549 |
} |
| 12550 |
|
| 12551 |
spc->h_oversample = (unsigned int)old_h_over; |
| 12552 |
spc->v_oversample = (unsigned int)old_v_over; |
| 12553 |
return return_value; |
| 12554 |
} |
| 12555 |
NK_INTERN void |
| 12556 |
nk_tt_GetPackedQuad(struct nk_tt_packedchar *chardata, int pw, int ph, |
| 12557 |
int char_index, float *xpos, float *ypos, struct nk_tt_aligned_quad *q, |
| 12558 |
int align_to_integer) |
| 12559 |
{ |
| 12560 |
float ipw = 1.0f / (float)pw, iph = 1.0f / (float)ph; |
| 12561 |
struct nk_tt_packedchar *b = (struct nk_tt_packedchar*)(chardata + char_index); |
| 12562 |
if (align_to_integer) { |
| 12563 |
int tx = nk_ifloorf((*xpos + b->xoff) + 0.5f); |
| 12564 |
int ty = nk_ifloorf((*ypos + b->yoff) + 0.5f); |
| 12565 |
|
| 12566 |
float x = (float)tx; |
| 12567 |
float y = (float)ty; |
| 12568 |
|
| 12569 |
q->x0 = x; |
| 12570 |
q->y0 = y; |
| 12571 |
q->x1 = x + b->xoff2 - b->xoff; |
| 12572 |
q->y1 = y + b->yoff2 - b->yoff; |
| 12573 |
} else { |
| 12574 |
q->x0 = *xpos + b->xoff; |
| 12575 |
q->y0 = *ypos + b->yoff; |
| 12576 |
q->x1 = *xpos + b->xoff2; |
| 12577 |
q->y1 = *ypos + b->yoff2; |
| 12578 |
} |
| 12579 |
q->s0 = b->x0 * ipw; |
| 12580 |
q->t0 = b->y0 * iph; |
| 12581 |
q->s1 = b->x1 * ipw; |
| 12582 |
q->t1 = b->y1 * iph; |
| 12583 |
*xpos += b->xadvance; |
| 12584 |
} |
| 12585 |
|
| 12586 |
|
| 12587 |
|
| 12588 |
|
| 12589 |
|
| 12590 |
|
| 12591 |
struct nk_font_bake_data { |
| 12592 |
struct nk_tt_fontinfo info; |
| 12593 |
struct nk_rp_rect *rects; |
| 12594 |
struct nk_tt_pack_range *ranges; |
| 12595 |
nk_rune range_count; |
| 12596 |
}; |
| 12597 |
|
| 12598 |
struct nk_font_baker { |
| 12599 |
struct nk_allocator alloc; |
| 12600 |
struct nk_tt_pack_context spc; |
| 12601 |
struct nk_font_bake_data *build; |
| 12602 |
struct nk_tt_packedchar *packed_chars; |
| 12603 |
struct nk_rp_rect *rects; |
| 12604 |
struct nk_tt_pack_range *ranges; |
| 12605 |
}; |
| 12606 |
|
| 12607 |
NK_GLOBAL const nk_size nk_rect_align = NK_ALIGNOF(struct nk_rp_rect); |
| 12608 |
NK_GLOBAL const nk_size nk_range_align = NK_ALIGNOF(struct nk_tt_pack_range); |
| 12609 |
NK_GLOBAL const nk_size nk_char_align = NK_ALIGNOF(struct nk_tt_packedchar); |
| 12610 |
NK_GLOBAL const nk_size nk_build_align = NK_ALIGNOF(struct nk_font_bake_data); |
| 12611 |
NK_GLOBAL const nk_size nk_baker_align = NK_ALIGNOF(struct nk_font_baker); |
| 12612 |
|
| 12613 |
NK_INTERN int |
| 12614 |
nk_range_count(const nk_rune *range) |
| 12615 |
{ |
| 12616 |
const nk_rune *iter = range; |
| 12617 |
NK_ASSERT(range); |
| 12618 |
if (!range) return 0; |
| 12619 |
while (*(iter++) != 0); |
| 12620 |
return (iter == range) ? 0 : (int)((iter - range)/2); |
| 12621 |
} |
| 12622 |
NK_INTERN int |
| 12623 |
nk_range_glyph_count(const nk_rune *range, int count) |
| 12624 |
{ |
| 12625 |
int i = 0; |
| 12626 |
int total_glyphs = 0; |
| 12627 |
for (i = 0; i < count; ++i) { |
| 12628 |
int diff; |
| 12629 |
nk_rune f = range[(i*2)+0]; |
| 12630 |
nk_rune t = range[(i*2)+1]; |
| 12631 |
NK_ASSERT(t >= f); |
| 12632 |
diff = (int)((t - f) + 1); |
| 12633 |
total_glyphs += diff; |
| 12634 |
} |
| 12635 |
return total_glyphs; |
| 12636 |
} |
| 12637 |
NK_API const nk_rune* |
| 12638 |
nk_font_default_glyph_ranges(void) |
| 12639 |
{ |
| 12640 |
NK_STORAGE const nk_rune ranges[] = {0x0020, 0x00FF, 0}; |
| 12641 |
return ranges; |
| 12642 |
} |
| 12643 |
NK_API const nk_rune* |
| 12644 |
nk_font_chinese_glyph_ranges(void) |
| 12645 |
{ |
| 12646 |
NK_STORAGE const nk_rune ranges[] = { |
| 12647 |
0x0020, 0x00FF, |
| 12648 |
0x3000, 0x30FF, |
| 12649 |
0x31F0, 0x31FF, |
| 12650 |
0xFF00, 0xFFEF, |
| 12651 |
0x4e00, 0x9FAF, |
| 12652 |
0 |
| 12653 |
}; |
| 12654 |
return ranges; |
| 12655 |
} |
| 12656 |
NK_API const nk_rune* |
| 12657 |
nk_font_cyrillic_glyph_ranges(void) |
| 12658 |
{ |
| 12659 |
NK_STORAGE const nk_rune ranges[] = { |
| 12660 |
0x0020, 0x00FF, |
| 12661 |
0x0400, 0x052F, |
| 12662 |
0x2DE0, 0x2DFF, |
| 12663 |
0xA640, 0xA69F, |
| 12664 |
0 |
| 12665 |
}; |
| 12666 |
return ranges; |
| 12667 |
} |
| 12668 |
NK_API const nk_rune* |
| 12669 |
nk_font_korean_glyph_ranges(void) |
| 12670 |
{ |
| 12671 |
NK_STORAGE const nk_rune ranges[] = { |
| 12672 |
0x0020, 0x00FF, |
| 12673 |
0x3131, 0x3163, |
| 12674 |
0xAC00, 0xD79D, |
| 12675 |
0 |
| 12676 |
}; |
| 12677 |
return ranges; |
| 12678 |
} |
| 12679 |
NK_INTERN void |
| 12680 |
nk_font_baker_memory(nk_size *temp, int *glyph_count, |
| 12681 |
struct nk_font_config *config_list, int count) |
| 12682 |
{ |
| 12683 |
int range_count = 0; |
| 12684 |
int total_range_count = 0; |
| 12685 |
struct nk_font_config *iter, *i; |
| 12686 |
|
| 12687 |
NK_ASSERT(config_list); |
| 12688 |
NK_ASSERT(glyph_count); |
| 12689 |
if (!config_list) { |
| 12690 |
*temp = 0; |
| 12691 |
*glyph_count = 0; |
| 12692 |
return; |
| 12693 |
} |
| 12694 |
*glyph_count = 0; |
| 12695 |
for (iter = config_list; iter; iter = iter->next) { |
| 12696 |
i = iter; |
| 12697 |
do {if (!i->range) iter->range = nk_font_default_glyph_ranges(); |
| 12698 |
range_count = nk_range_count(i->range); |
| 12699 |
total_range_count += range_count; |
| 12700 |
*glyph_count += nk_range_glyph_count(i->range, range_count); |
| 12701 |
} while ((i = i->n) != iter); |
| 12702 |
} |
| 12703 |
*temp = (nk_size)*glyph_count * sizeof(struct nk_rp_rect); |
| 12704 |
*temp += (nk_size)total_range_count * sizeof(struct nk_tt_pack_range); |
| 12705 |
*temp += (nk_size)*glyph_count * sizeof(struct nk_tt_packedchar); |
| 12706 |
*temp += (nk_size)count * sizeof(struct nk_font_bake_data); |
| 12707 |
*temp += sizeof(struct nk_font_baker); |
| 12708 |
*temp += nk_rect_align + nk_range_align + nk_char_align; |
| 12709 |
*temp += nk_build_align + nk_baker_align; |
| 12710 |
} |
| 12711 |
NK_INTERN struct nk_font_baker* |
| 12712 |
nk_font_baker(void *memory, int glyph_count, int count, struct nk_allocator *alloc) |
| 12713 |
{ |
| 12714 |
struct nk_font_baker *baker; |
| 12715 |
if (!memory) return 0; |
| 12716 |
|
| 12717 |
baker = (struct nk_font_baker*)NK_ALIGN_PTR(memory, nk_baker_align); |
| 12718 |
baker->build = (struct nk_font_bake_data*)NK_ALIGN_PTR((baker + 1), nk_build_align); |
| 12719 |
baker->packed_chars = (struct nk_tt_packedchar*)NK_ALIGN_PTR((baker->build + count), nk_char_align); |
| 12720 |
baker->rects = (struct nk_rp_rect*)NK_ALIGN_PTR((baker->packed_chars + glyph_count), nk_rect_align); |
| 12721 |
baker->ranges = (struct nk_tt_pack_range*)NK_ALIGN_PTR((baker->rects + glyph_count), nk_range_align); |
| 12722 |
baker->alloc = *alloc; |
| 12723 |
return baker; |
| 12724 |
} |
| 12725 |
NK_INTERN int |
| 12726 |
nk_font_bake_pack(struct nk_font_baker *baker, |
| 12727 |
nk_size *image_memory, int *width, int *height, struct nk_recti *custom, |
| 12728 |
const struct nk_font_config *config_list, int count, |
| 12729 |
struct nk_allocator *alloc) |
| 12730 |
{ |
| 12731 |
NK_STORAGE const nk_size max_height = 1024 * 32; |
| 12732 |
const struct nk_font_config *config_iter, *it; |
| 12733 |
int total_glyph_count = 0; |
| 12734 |
int total_range_count = 0; |
| 12735 |
(void)total_range_count; |
| 12736 |
int range_count = 0; |
| 12737 |
int i = 0; |
| 12738 |
|
| 12739 |
NK_ASSERT(image_memory); |
| 12740 |
NK_ASSERT(width); |
| 12741 |
NK_ASSERT(height); |
| 12742 |
NK_ASSERT(config_list); |
| 12743 |
NK_ASSERT(count); |
| 12744 |
NK_ASSERT(alloc); |
| 12745 |
|
| 12746 |
if (!image_memory || !width || !height || !config_list || !count) return nk_false; |
| 12747 |
for (config_iter = config_list; config_iter; config_iter = config_iter->next) { |
| 12748 |
it = config_iter; |
| 12749 |
do {range_count = nk_range_count(it->range); |
| 12750 |
total_range_count += range_count; |
| 12751 |
total_glyph_count += nk_range_glyph_count(it->range, range_count); |
| 12752 |
} while ((it = it->n) != config_iter); |
| 12753 |
} |
| 12754 |
|
| 12755 |
for (config_iter = config_list; config_iter; config_iter = config_iter->next) { |
| 12756 |
it = config_iter; |
| 12757 |
do {if (!nk_tt_InitFont(&baker->build[i++].info, (const unsigned char*)it->ttf_blob, 0)) |
| 12758 |
return nk_false; |
| 12759 |
} while ((it = it->n) != config_iter); |
| 12760 |
} |
| 12761 |
*height = 0; |
| 12762 |
*width = (total_glyph_count > 1000) ? 1024 : 512; |
| 12763 |
nk_tt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, alloc); |
| 12764 |
{ |
| 12765 |
int input_i = 0; |
| 12766 |
int range_n = 0; |
| 12767 |
int rect_n = 0; |
| 12768 |
int char_n = 0; |
| 12769 |
|
| 12770 |
if (custom) { |
| 12771 |
|
| 12772 |
struct nk_rp_rect custom_space; |
| 12773 |
nk_zero(&custom_space, sizeof(custom_space)); |
| 12774 |
custom_space.w = (nk_rp_coord)(custom->w); |
| 12775 |
custom_space.h = (nk_rp_coord)(custom->h); |
| 12776 |
|
| 12777 |
nk_tt_PackSetOversampling(&baker->spc, 1, 1); |
| 12778 |
nk_rp_pack_rects((struct nk_rp_context*)baker->spc.pack_info, &custom_space, 1); |
| 12779 |
*height = NK_MAX(*height, (int)(custom_space.y + custom_space.h)); |
| 12780 |
|
| 12781 |
custom->x = (short)custom_space.x; |
| 12782 |
custom->y = (short)custom_space.y; |
| 12783 |
custom->w = (short)custom_space.w; |
| 12784 |
custom->h = (short)custom_space.h; |
| 12785 |
} |
| 12786 |
|
| 12787 |
|
| 12788 |
for (input_i = 0, config_iter = config_list; input_i < count && config_iter; |
| 12789 |
config_iter = config_iter->next) { |
| 12790 |
it = config_iter; |
| 12791 |
do {int n = 0; |
| 12792 |
int glyph_count; |
| 12793 |
const nk_rune *in_range; |
| 12794 |
const struct nk_font_config *cfg = it; |
| 12795 |
struct nk_font_bake_data *tmp = &baker->build[input_i++]; |
| 12796 |
|
| 12797 |
|
| 12798 |
glyph_count = 0; range_count = 0; |
| 12799 |
for (in_range = cfg->range; in_range[0] && in_range[1]; in_range += 2) { |
| 12800 |
glyph_count += (int)(in_range[1] - in_range[0]) + 1; |
| 12801 |
range_count++; |
| 12802 |
} |
| 12803 |
|
| 12804 |
|
| 12805 |
tmp->ranges = baker->ranges + range_n; |
| 12806 |
tmp->range_count = (nk_rune)range_count; |
| 12807 |
range_n += range_count; |
| 12808 |
for (i = 0; i < range_count; ++i) { |
| 12809 |
in_range = &cfg->range[i * 2]; |
| 12810 |
tmp->ranges[i].font_size = cfg->size; |
| 12811 |
tmp->ranges[i].first_unicode_codepoint_in_range = (int)in_range[0]; |
| 12812 |
tmp->ranges[i].num_chars = (int)(in_range[1]- in_range[0]) + 1; |
| 12813 |
tmp->ranges[i].chardata_for_range = baker->packed_chars + char_n; |
| 12814 |
char_n += tmp->ranges[i].num_chars; |
| 12815 |
} |
| 12816 |
|
| 12817 |
|
| 12818 |
tmp->rects = baker->rects + rect_n; |
| 12819 |
rect_n += glyph_count; |
| 12820 |
nk_tt_PackSetOversampling(&baker->spc, cfg->oversample_h, cfg->oversample_v); |
| 12821 |
n = nk_tt_PackFontRangesGatherRects(&baker->spc, &tmp->info, |
| 12822 |
tmp->ranges, (int)tmp->range_count, tmp->rects); |
| 12823 |
nk_rp_pack_rects((struct nk_rp_context*)baker->spc.pack_info, tmp->rects, (int)n); |
| 12824 |
|
| 12825 |
|
| 12826 |
for (i = 0; i < n; ++i) { |
| 12827 |
if (tmp->rects[i].was_packed) |
| 12828 |
*height = NK_MAX(*height, tmp->rects[i].y + tmp->rects[i].h); |
| 12829 |
} |
| 12830 |
} while ((it = it->n) != config_iter); |
| 12831 |
} |
| 12832 |
NK_ASSERT(rect_n == total_glyph_count); |
| 12833 |
NK_ASSERT(char_n == total_glyph_count); |
| 12834 |
NK_ASSERT(range_n == total_range_count); |
| 12835 |
} |
| 12836 |
*height = (int)nk_round_up_pow2((nk_uint)*height); |
| 12837 |
*image_memory = (nk_size)(*width) * (nk_size)(*height); |
| 12838 |
return nk_true; |
| 12839 |
} |
| 12840 |
NK_INTERN void |
| 12841 |
nk_font_bake(struct nk_font_baker *baker, void *image_memory, int width, int height, |
| 12842 |
struct nk_font_glyph *glyphs, int glyphs_count, |
| 12843 |
const struct nk_font_config *config_list, int font_count) |
| 12844 |
{ |
| 12845 |
int input_i = 0; |
| 12846 |
nk_rune glyph_n = 0; |
| 12847 |
const struct nk_font_config *config_iter; |
| 12848 |
const struct nk_font_config *it; |
| 12849 |
|
| 12850 |
NK_ASSERT(image_memory); |
| 12851 |
NK_ASSERT(width); |
| 12852 |
NK_ASSERT(height); |
| 12853 |
NK_ASSERT(config_list); |
| 12854 |
NK_ASSERT(baker); |
| 12855 |
NK_ASSERT(font_count); |
| 12856 |
NK_ASSERT(glyphs_count); |
| 12857 |
if (!image_memory || !width || !height || !config_list || |
| 12858 |
!font_count || !glyphs || !glyphs_count) |
| 12859 |
return; |
| 12860 |
|
| 12861 |
|
| 12862 |
nk_zero(image_memory, (nk_size)((nk_size)width * (nk_size)height)); |
| 12863 |
baker->spc.pixels = (unsigned char*)image_memory; |
| 12864 |
baker->spc.height = (int)height; |
| 12865 |
for (input_i = 0, config_iter = config_list; input_i < font_count && config_iter; |
| 12866 |
config_iter = config_iter->next) { |
| 12867 |
it = config_iter; |
| 12868 |
do {const struct nk_font_config *cfg = it; |
| 12869 |
struct nk_font_bake_data *tmp = &baker->build[input_i++]; |
| 12870 |
nk_tt_PackSetOversampling(&baker->spc, cfg->oversample_h, cfg->oversample_v); |
| 12871 |
nk_tt_PackFontRangesRenderIntoRects(&baker->spc, &tmp->info, tmp->ranges, |
| 12872 |
(int)tmp->range_count, tmp->rects, &baker->alloc); |
| 12873 |
} while ((it = it->n) != config_iter); |
| 12874 |
} nk_tt_PackEnd(&baker->spc, &baker->alloc); |
| 12875 |
|
| 12876 |
|
| 12877 |
for (input_i = 0, config_iter = config_list; input_i < font_count && config_iter; |
| 12878 |
config_iter = config_iter->next) { |
| 12879 |
it = config_iter; |
| 12880 |
do {nk_size i = 0; |
| 12881 |
int char_idx = 0; |
| 12882 |
nk_rune glyph_count = 0; |
| 12883 |
const struct nk_font_config *cfg = it; |
| 12884 |
struct nk_font_bake_data *tmp = &baker->build[input_i++]; |
| 12885 |
struct nk_baked_font *dst_font = cfg->font; |
| 12886 |
|
| 12887 |
float font_scale = nk_tt_ScaleForPixelHeight(&tmp->info, cfg->size); |
| 12888 |
int unscaled_ascent, unscaled_descent, unscaled_line_gap; |
| 12889 |
nk_tt_GetFontVMetrics(&tmp->info, &unscaled_ascent, &unscaled_descent, |
| 12890 |
&unscaled_line_gap); |
| 12891 |
|
| 12892 |
|
| 12893 |
if (!cfg->merge_mode) { |
| 12894 |
dst_font->ranges = cfg->range; |
| 12895 |
dst_font->height = cfg->size; |
| 12896 |
dst_font->ascent = ((float)unscaled_ascent * font_scale); |
| 12897 |
dst_font->descent = ((float)unscaled_descent * font_scale); |
| 12898 |
dst_font->glyph_offset = glyph_n; |
| 12899 |
|
| 12900 |
|
| 12901 |
dst_font->glyph_count = 0; |
| 12902 |
} |
| 12903 |
|
| 12904 |
|
| 12905 |
for (i = 0; i < tmp->range_count; ++i) { |
| 12906 |
struct nk_tt_pack_range *range = &tmp->ranges[i]; |
| 12907 |
for (char_idx = 0; char_idx < range->num_chars; char_idx++) |
| 12908 |
{ |
| 12909 |
nk_rune codepoint = 0; |
| 12910 |
float dummy_x = 0, dummy_y = 0; |
| 12911 |
struct nk_tt_aligned_quad q; |
| 12912 |
struct nk_font_glyph *glyph; |
| 12913 |
|
| 12914 |
|
| 12915 |
const struct nk_tt_packedchar *pc = &range->chardata_for_range[char_idx]; |
| 12916 |
if (!pc->x0 && !pc->x1 && !pc->y0 && !pc->y1) continue; |
| 12917 |
codepoint = (nk_rune)(range->first_unicode_codepoint_in_range + char_idx); |
| 12918 |
nk_tt_GetPackedQuad(range->chardata_for_range, (int)width, |
| 12919 |
(int)height, char_idx, &dummy_x, &dummy_y, &q, 0); |
| 12920 |
|
| 12921 |
|
| 12922 |
glyph = &glyphs[dst_font->glyph_offset + dst_font->glyph_count + (unsigned int)glyph_count]; |
| 12923 |
glyph->codepoint = codepoint; |
| 12924 |
glyph->x0 = q.x0; glyph->y0 = q.y0; |
| 12925 |
glyph->x1 = q.x1; glyph->y1 = q.y1; |
| 12926 |
glyph->y0 += (dst_font->ascent + 0.5f); |
| 12927 |
glyph->y1 += (dst_font->ascent + 0.5f); |
| 12928 |
glyph->w = glyph->x1 - glyph->x0 + 0.5f; |
| 12929 |
glyph->h = glyph->y1 - glyph->y0; |
| 12930 |
|
| 12931 |
if (cfg->coord_type == NK_COORD_PIXEL) { |
| 12932 |
glyph->u0 = q.s0 * (float)width; |
| 12933 |
glyph->v0 = q.t0 * (float)height; |
| 12934 |
glyph->u1 = q.s1 * (float)width; |
| 12935 |
glyph->v1 = q.t1 * (float)height; |
| 12936 |
} else { |
| 12937 |
glyph->u0 = q.s0; |
| 12938 |
glyph->v0 = q.t0; |
| 12939 |
glyph->u1 = q.s1; |
| 12940 |
glyph->v1 = q.t1; |
| 12941 |
} |
| 12942 |
glyph->xadvance = (pc->xadvance + cfg->spacing.x); |
| 12943 |
if (cfg->pixel_snap) |
| 12944 |
glyph->xadvance = (float)(int)(glyph->xadvance + 0.5f); |
| 12945 |
glyph_count++; |
| 12946 |
} |
| 12947 |
} |
| 12948 |
dst_font->glyph_count += glyph_count; |
| 12949 |
glyph_n += glyph_count; |
| 12950 |
} while ((it = it->n) != config_iter); |
| 12951 |
} |
| 12952 |
} |
| 12953 |
NK_INTERN void |
| 12954 |
nk_font_bake_custom_data(void *img_memory, int img_width, int img_height, |
| 12955 |
struct nk_recti img_dst, const char *texture_data_mask, int tex_width, |
| 12956 |
int tex_height, char white, char black) |
| 12957 |
{ |
| 12958 |
nk_byte *pixels; |
| 12959 |
int y = 0; |
| 12960 |
int x = 0; |
| 12961 |
int n = 0; |
| 12962 |
|
| 12963 |
NK_ASSERT(img_memory); |
| 12964 |
NK_ASSERT(img_width); |
| 12965 |
NK_ASSERT(img_height); |
| 12966 |
NK_ASSERT(texture_data_mask); |
| 12967 |
NK_UNUSED(tex_height); |
| 12968 |
if (!img_memory || !img_width || !img_height || !texture_data_mask) |
| 12969 |
return; |
| 12970 |
|
| 12971 |
pixels = (nk_byte*)img_memory; |
| 12972 |
for (y = 0, n = 0; y < tex_height; ++y) { |
| 12973 |
for (x = 0; x < tex_width; ++x, ++n) { |
| 12974 |
const int off0 = ((img_dst.x + x) + (img_dst.y + y) * img_width); |
| 12975 |
const int off1 = off0 + 1 + tex_width; |
| 12976 |
pixels[off0] = (texture_data_mask[n] == white) ? 0xFF : 0x00; |
| 12977 |
pixels[off1] = (texture_data_mask[n] == black) ? 0xFF : 0x00; |
| 12978 |
} |
| 12979 |
} |
| 12980 |
} |
| 12981 |
NK_INTERN void |
| 12982 |
nk_font_bake_convert(void *out_memory, int img_width, int img_height, |
| 12983 |
const void *in_memory) |
| 12984 |
{ |
| 12985 |
int n = 0; |
| 12986 |
nk_rune *dst; |
| 12987 |
const nk_byte *src; |
| 12988 |
|
| 12989 |
NK_ASSERT(out_memory); |
| 12990 |
NK_ASSERT(in_memory); |
| 12991 |
NK_ASSERT(img_width); |
| 12992 |
NK_ASSERT(img_height); |
| 12993 |
if (!out_memory || !in_memory || !img_height || !img_width) return; |
| 12994 |
|
| 12995 |
dst = (nk_rune*)out_memory; |
| 12996 |
src = (const nk_byte*)in_memory; |
| 12997 |
for (n = (int)(img_width * img_height); n > 0; n--) |
| 12998 |
*dst++ = ((nk_rune)(*src++) << 24) | 0x00FFFFFF; |
| 12999 |
} |
| 13000 |
|
| 13001 |
|
| 13002 |
|
| 13003 |
|
| 13004 |
|
| 13005 |
|
| 13006 |
NK_INTERN float |
| 13007 |
nk_font_text_width(nk_handle handle, float height, const char *text, int len) |
| 13008 |
{ |
| 13009 |
nk_rune unicode; |
| 13010 |
int text_len = 0; |
| 13011 |
float text_width = 0; |
| 13012 |
int glyph_len = 0; |
| 13013 |
float scale = 0; |
| 13014 |
|
| 13015 |
struct nk_font *font = (struct nk_font*)handle.ptr; |
| 13016 |
NK_ASSERT(font); |
| 13017 |
NK_ASSERT(font->glyphs); |
| 13018 |
if (!font || !text || !len) |
| 13019 |
return 0; |
| 13020 |
|
| 13021 |
scale = height/font->info.height; |
| 13022 |
glyph_len = text_len = nk_utf_decode(text, &unicode, (int)len); |
| 13023 |
if (!glyph_len) return 0; |
| 13024 |
while (text_len <= (int)len && glyph_len) { |
| 13025 |
const struct nk_font_glyph *g; |
| 13026 |
if (unicode == NK_UTF_INVALID) break; |
| 13027 |
|
| 13028 |
|
| 13029 |
g = nk_font_find_glyph(font, unicode); |
| 13030 |
text_width += g->xadvance * scale; |
| 13031 |
|
| 13032 |
|
| 13033 |
glyph_len = nk_utf_decode(text + text_len, &unicode, (int)len - text_len); |
| 13034 |
text_len += glyph_len; |
| 13035 |
} |
| 13036 |
return text_width; |
| 13037 |
} |
| 13038 |
#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT |
| 13039 |
NK_INTERN void |
| 13040 |
nk_font_query_font_glyph(nk_handle handle, float height, |
| 13041 |
struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) |
| 13042 |
{ |
| 13043 |
float scale; |
| 13044 |
const struct nk_font_glyph *g; |
| 13045 |
struct nk_font *font; |
| 13046 |
|
| 13047 |
NK_ASSERT(glyph); |
| 13048 |
NK_UNUSED(next_codepoint); |
| 13049 |
|
| 13050 |
font = (struct nk_font*)handle.ptr; |
| 13051 |
NK_ASSERT(font); |
| 13052 |
NK_ASSERT(font->glyphs); |
| 13053 |
if (!font || !glyph) |
| 13054 |
return; |
| 13055 |
|
| 13056 |
scale = height/font->info.height; |
| 13057 |
g = nk_font_find_glyph(font, codepoint); |
| 13058 |
glyph->width = (g->x1 - g->x0) * scale; |
| 13059 |
glyph->height = (g->y1 - g->y0) * scale; |
| 13060 |
glyph->offset = nk_vec2(g->x0 * scale, g->y0 * scale); |
| 13061 |
glyph->xadvance = (g->xadvance * scale); |
| 13062 |
glyph->uv[0] = nk_vec2(g->u0, g->v0); |
| 13063 |
glyph->uv[1] = nk_vec2(g->u1, g->v1); |
| 13064 |
} |
| 13065 |
#endif |
| 13066 |
NK_API const struct nk_font_glyph* |
| 13067 |
nk_font_find_glyph(struct nk_font *font, nk_rune unicode) |
| 13068 |
{ |
| 13069 |
int i = 0; |
| 13070 |
int count; |
| 13071 |
int total_glyphs = 0; |
| 13072 |
const struct nk_font_glyph *glyph = 0; |
| 13073 |
const struct nk_font_config *iter = 0; |
| 13074 |
|
| 13075 |
NK_ASSERT(font); |
| 13076 |
NK_ASSERT(font->glyphs); |
| 13077 |
NK_ASSERT(font->info.ranges); |
| 13078 |
if (!font || !font->glyphs) return 0; |
| 13079 |
|
| 13080 |
glyph = font->fallback; |
| 13081 |
iter = font->config; |
| 13082 |
do {count = nk_range_count(iter->range); |
| 13083 |
for (i = 0; i < count; ++i) { |
| 13084 |
nk_rune f = iter->range[(i*2)+0]; |
| 13085 |
nk_rune t = iter->range[(i*2)+1]; |
| 13086 |
int diff = (int)((t - f) + 1); |
| 13087 |
if (unicode >= f && unicode <= t) |
| 13088 |
return &font->glyphs[((nk_rune)total_glyphs + (unicode - f))]; |
| 13089 |
total_glyphs += diff; |
| 13090 |
} |
| 13091 |
} while ((iter = iter->n) != font->config); |
| 13092 |
return glyph; |
| 13093 |
} |
| 13094 |
NK_INTERN void |
| 13095 |
nk_font_init(struct nk_font *font, float pixel_height, |
| 13096 |
nk_rune fallback_codepoint, struct nk_font_glyph *glyphs, |
| 13097 |
const struct nk_baked_font *baked_font, nk_handle atlas) |
| 13098 |
{ |
| 13099 |
struct nk_baked_font baked; |
| 13100 |
NK_ASSERT(font); |
| 13101 |
NK_ASSERT(glyphs); |
| 13102 |
NK_ASSERT(baked_font); |
| 13103 |
if (!font || !glyphs || !baked_font) |
| 13104 |
return; |
| 13105 |
|
| 13106 |
baked = *baked_font; |
| 13107 |
font->fallback = 0; |
| 13108 |
font->info = baked; |
| 13109 |
font->scale = (float)pixel_height / (float)font->info.height; |
| 13110 |
font->glyphs = &glyphs[baked_font->glyph_offset]; |
| 13111 |
font->texture = atlas; |
| 13112 |
font->fallback_codepoint = fallback_codepoint; |
| 13113 |
font->fallback = nk_font_find_glyph(font, fallback_codepoint); |
| 13114 |
|
| 13115 |
font->handle.height = font->info.height * font->scale; |
| 13116 |
font->handle.width = nk_font_text_width; |
| 13117 |
font->handle.userdata.ptr = font; |
| 13118 |
#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT |
| 13119 |
font->handle.query = nk_font_query_font_glyph; |
| 13120 |
font->handle.texture = font->texture; |
| 13121 |
#endif |
| 13122 |
} |
| 13123 |
|
| 13124 |
|
| 13125 |
|
| 13126 |
|
| 13127 |
|
| 13128 |
|
| 13129 |
|
| 13130 |
|
| 13131 |
|
| 13132 |
|
| 13133 |
#ifdef __clang__ |
| 13134 |
#pragma clang diagnostic push |
| 13135 |
#pragma clang diagnostic ignored "-Woverlength-strings" |
| 13136 |
#elif defined(__GNUC__) || defined(__GNUG__) |
| 13137 |
#pragma GCC diagnostic push |
| 13138 |
#pragma GCC diagnostic ignored "-Woverlength-strings" |
| 13139 |
#endif |
| 13140 |
|
| 13141 |
#ifdef NK_INCLUDE_DEFAULT_FONT |
| 13142 |
|
| 13143 |
NK_GLOBAL const char nk_proggy_clean_ttf_compressed_data_base85[11980+1] = |
| 13144 |
"7])#######hV0qs'/###[),##/l:$#Q6>##5[n42>c-TH`->>#/e>11NNV=Bv(*:.F?uu#(gRU.o0XGH`$vhLG1hxt9?W`#,5LsCp#-i>.r$<$6pD>Lb';9Crc6tgXmKVeU2cD4Eo3R/" |
| 13145 |
"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#" |
| 13146 |
"`8ND>Qo#t'X#(v#Y9w0#1D$CIf;W'#pWUPXOuxXuU(H9M(1<q-UE31#^-V'8IRUo7Qf./L>=Ke$$'5F%)]0^#[email protected]<r:QLtFsLcL6##lOj)#.Y5<-R&KgLwqJfLgN&;Q?gI^#DY2uL" |
| 13147 |
"i@^rMl9t=cWq6##weg>$FBjVQTSDgEKnIS7EM9>ZY9w0#L;>>#Mx&4Mvt//L[MkA#[email protected]'[0#7RL_&#w+F%HtG9M#XL`N&.,GM4Pg;-<nLENhvx>-VsM.M0rJfLH2eTM`*oJMHRC`N" |
| 13148 |
"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" |
| 13149 |
"*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)" |
| 13150 |
"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" |
| 13151 |
"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." |
| 13152 |
"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" |
| 13153 |
"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(,)" |
| 13154 |
"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#" |
| 13155 |
"'/###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" |
| 13156 |
"_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" |
| 13157 |
"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/" |
| 13158 |
"/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" |
| 13159 |
"%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&#" |
| 13160 |
"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)(" |
| 13161 |
"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" |
| 13162 |
"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" |
| 13163 |
"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^-" |
| 13164 |
"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-" |
| 13165 |
"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" |
| 13166 |
"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%" |
| 13167 |
"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]" |
| 13168 |
"%(?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" |
| 13169 |
"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:" |
| 13170 |
"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(" |
| 13171 |
"$/V,;(kXZejWO`<[5?\?ewY(*9=%wDc;,u<'9t3W-(H1th3+G]ucQ]kLs7df($/*JL]@*t7Bu_G3_7mp7<[email protected];x3B0lqp7Hf,^Ze7-##@/c58Mo(3;knp0%)A7?-W+eI'o8)b<" |
| 13172 |
"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'?" |
| 13173 |
"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/;" |
| 13174 |
")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" |
| 13175 |
"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(" |
| 13176 |
"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" |
| 13177 |
"bIu)'Z,*[>br5fX^:FPAWr-m2KgL<LUN098kTF&#lvo58=/vjDo;.;)Ka*hLR#/k=rKbxuV`>Q_nN6'8uTGT5g)uLv:873UpTLgH+#FgpH'_o1780Ph8KmxQJ8#H72L4@768@Tm&Q" |
| 13178 |
"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<-" |
| 13179 |
"V8J'(1)G][68hW$5'q[GC&5j`TE?m'esFGNRM)j,ffZ?-qx8;->g4t*:CIP/[Qap7/9'#(1sao7w-.qNUdkJ)tCF&#B^;[email protected]$m%#QvQS8U@)2Z+3K:AKM5i" |
| 13180 |
"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" |
| 13181 |
".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@@" |
| 13182 |
"$&)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*" |
| 13183 |
"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" |
| 13184 |
"@-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&#" |
| 13185 |
"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#" |
| 13186 |
"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" |
| 13187 |
"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" |
| 13188 |
"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&#" |
| 13189 |
"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" |
| 13190 |
":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+" |
| 13191 |
"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*" |
| 13192 |
"$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" |
| 13193 |
":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" |
| 13194 |
"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" |
| 13195 |
"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" |
| 13196 |
"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" |
| 13197 |
":^#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@&]>" |
| 13198 |
"_>@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%" |
| 13199 |
"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;" |
| 13200 |
"^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:" |
| 13201 |
"+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%" |
| 13202 |
"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-" |
| 13203 |
"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*" |
| 13204 |
"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" |
| 13205 |
"8kD2)2fU/M#$e.)T4,_=8hLim[&);?UkK'-x?'(:siIfL<$pFM`i<?%W(mGDHM%>iWP,##P`%/L<eXi:@Z9C.7o=@(pXdAO/NLQ8lPl+HPOQa8wD8=^GlPa8TKI1CjhsCTSLJM'/Wl>-" |
| 13206 |
"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`" |
| 13207 |
"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]%/" |
| 13208 |
"+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" |
| 13209 |
"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" |
| 13210 |
"?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" |
| 13211 |
"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" |
| 13212 |
">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'>" |
| 13213 |
"[%$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" |
| 13214 |
"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#" |
| 13215 |
"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$" |
| 13216 |
"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,)" |
| 13217 |
"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" |
| 13218 |
"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" |
| 13219 |
"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" |
| 13220 |
"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(#" |
| 13221 |
";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&>" |
| 13222 |
"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#" |
| 13223 |
"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" |
| 13224 |
"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#" |
| 13225 |
"/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-#" |
| 13226 |
"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#" |
| 13227 |
"TmD<#%JSMFove:CTBEXI:<eh2g)B,3h2^G3i;#d3jD>)4kMYD4lVu`4m`:&5niUA5@(A5BA1]PBB:xlBCC=2CDLXMCEUtiCf&0g2'tN?PGT4CPGT4CPGT4CPGT4CPGT4CPGT4CPGT4CP" |
| 13228 |
"GT4CPGT4CPGT4CPGT4CPGT4CPGT4CP-qekC`.9kEg^+F$kwViFJTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5o,^<-28ZI'O?;xp" |
| 13229 |
"O?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xp;7q-#lLYI:xvD=#"; |
| 13230 |
|
| 13231 |
#endif |
| 13232 |
|
| 13233 |
#define NK_CURSOR_DATA_W 90 |
| 13234 |
#define NK_CURSOR_DATA_H 27 |
| 13235 |
NK_GLOBAL const char nk_custom_cursor_data[NK_CURSOR_DATA_W * NK_CURSOR_DATA_H + 1] = |
| 13236 |
{ |
| 13237 |
"..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX" |
| 13238 |
"..- -X.....X- X.X - X.X -X.....X - X.....X" |
| 13239 |
"--- -XXX.XXX- X...X - X...X -X....X - X....X" |
| 13240 |
"X - X.X - X.....X - X.....X -X...X - X...X" |
| 13241 |
"XX - X.X -X.......X- X.......X -X..X.X - X.X..X" |
| 13242 |
"X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X" |
| 13243 |
"X..X - X.X - X.X - X.X -XX X.X - X.X XX" |
| 13244 |
"X...X - X.X - X.X - XX X.X XX - X.X - X.X " |
| 13245 |
"X....X - X.X - X.X - X.X X.X X.X - X.X - X.X " |
| 13246 |
"X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X " |
| 13247 |
"X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX 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..X-X..X.X " |
| 13250 |
"X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X " |
| 13251 |
"X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X " |
| 13252 |
"X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X " |
| 13253 |
"X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX " |
| 13254 |
"X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------" |
| 13255 |
"X.X X..X - -X.......X- X.......X - XX XX - " |
| 13256 |
"XX X..X - - X.....X - X.....X - X.X X.X - " |
| 13257 |
" X..X - X...X - X...X - X..X X..X - " |
| 13258 |
" XX - X.X - X.X - X...XXXXXXXXXXXXX...X - " |
| 13259 |
"------------ - X - X -X.....................X- " |
| 13260 |
" ----------------------------------- X...XXXXXXXXXXXXX...X - " |
| 13261 |
" - X..X X..X - " |
| 13262 |
" - X.X X.X - " |
| 13263 |
" - XX XX - " |
| 13264 |
}; |
| 13265 |
|
| 13266 |
#ifdef __clang__ |
| 13267 |
#pragma clang diagnostic pop |
| 13268 |
#elif defined(__GNUC__) || defined(__GNUG__) |
| 13269 |
#pragma GCC diagnostic pop |
| 13270 |
#endif |
| 13271 |
|
| 13272 |
NK_GLOBAL unsigned char *nk__barrier; |
| 13273 |
NK_GLOBAL unsigned char *nk__barrier2; |
| 13274 |
NK_GLOBAL unsigned char *nk__barrier3; |
| 13275 |
NK_GLOBAL unsigned char *nk__barrier4; |
| 13276 |
NK_GLOBAL unsigned char *nk__dout; |
| 13277 |
|
| 13278 |
NK_INTERN unsigned int |
| 13279 |
nk_decompress_length(unsigned char *input) |
| 13280 |
{ |
| 13281 |
return (unsigned int)((input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11]); |
| 13282 |
} |
| 13283 |
NK_INTERN void |
| 13284 |
nk__match(unsigned char *data, unsigned int length) |
| 13285 |
{ |
| 13286 |
|
| 13287 |
NK_ASSERT (nk__dout + length <= nk__barrier); |
| 13288 |
if (nk__dout + length > nk__barrier) { nk__dout += length; return; } |
| 13289 |
if (data < nk__barrier4) { nk__dout = nk__barrier+1; return; } |
| 13290 |
while (length--) *nk__dout++ = *data++; |
| 13291 |
} |
| 13292 |
NK_INTERN void |
| 13293 |
nk__lit(unsigned char *data, unsigned int length) |
| 13294 |
{ |
| 13295 |
NK_ASSERT (nk__dout + length <= nk__barrier); |
| 13296 |
if (nk__dout + length > nk__barrier) { nk__dout += length; return; } |
| 13297 |
if (data < nk__barrier2) { nk__dout = nk__barrier+1; return; } |
| 13298 |
NK_MEMCPY(nk__dout, data, length); |
| 13299 |
nk__dout += length; |
| 13300 |
} |
| 13301 |
NK_INTERN unsigned char* |
| 13302 |
nk_decompress_token(unsigned char *i) |
| 13303 |
{ |
| 13304 |
#define nk__in2(x) ((i[x] << 8) + i[(x)+1]) |
| 13305 |
#define nk__in3(x) ((i[x] << 16) + nk__in2((x)+1)) |
| 13306 |
#define nk__in4(x) ((i[x] << 24) + nk__in3((x)+1)) |
| 13307 |
|
| 13308 |
if (*i >= 0x20) { |
| 13309 |
if (*i >= 0x80) nk__match(nk__dout-i[1]-1, (unsigned int)i[0] - 0x80 + 1), i += 2; |
| 13310 |
else if (*i >= 0x40) nk__match(nk__dout-(nk__in2(0) - 0x4000 + 1), (unsigned int)i[2]+1), i += 3; |
| 13311 |
else nk__lit(i+1, (unsigned int)i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1); |
| 13312 |
} else { |
| 13313 |
if (*i >= 0x18) nk__match(nk__dout-(unsigned int)(nk__in3(0) - 0x180000 + 1), (unsigned int)i[3]+1), i += 4; |
| 13314 |
else if (*i >= 0x10) nk__match(nk__dout-(unsigned int)(nk__in3(0) - 0x100000 + 1), (unsigned int)nk__in2(3)+1), i += 5; |
| 13315 |
else if (*i >= 0x08) nk__lit(i+2, (unsigned int)nk__in2(0) - 0x0800 + 1), i += 2 + (nk__in2(0) - 0x0800 + 1); |
| 13316 |
else if (*i == 0x07) nk__lit(i+3, (unsigned int)nk__in2(1) + 1), i += 3 + (nk__in2(1) + 1); |
| 13317 |
else if (*i == 0x06) nk__match(nk__dout-(unsigned int)(nk__in3(1)+1), i[4]+1u), i += 5; |
| 13318 |
else if (*i == 0x04) nk__match(nk__dout-(unsigned int)(nk__in3(1)+1), (unsigned int)nk__in2(4)+1u), i += 6; |
| 13319 |
} |
| 13320 |
return i; |
| 13321 |
} |
| 13322 |
NK_INTERN unsigned int |
| 13323 |
nk_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen) |
| 13324 |
{ |
| 13325 |
const unsigned long ADLER_MOD = 65521; |
| 13326 |
unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16; |
| 13327 |
unsigned long blocklen, i; |
| 13328 |
|
| 13329 |
blocklen = buflen % 5552; |
| 13330 |
while (buflen) { |
| 13331 |
for (i=0; i + 7 < blocklen; i += 8) { |
| 13332 |
s1 += buffer[0]; s2 += s1; |
| 13333 |
s1 += buffer[1]; s2 += s1; |
| 13334 |
s1 += buffer[2]; s2 += s1; |
| 13335 |
s1 += buffer[3]; s2 += s1; |
| 13336 |
s1 += buffer[4]; s2 += s1; |
| 13337 |
s1 += buffer[5]; s2 += s1; |
| 13338 |
s1 += buffer[6]; s2 += s1; |
| 13339 |
s1 += buffer[7]; s2 += s1; |
| 13340 |
buffer += 8; |
| 13341 |
} |
| 13342 |
for (; i < blocklen; ++i) { |
| 13343 |
s1 += *buffer++; s2 += s1; |
| 13344 |
} |
| 13345 |
|
| 13346 |
s1 %= ADLER_MOD; s2 %= ADLER_MOD; |
| 13347 |
buflen -= (unsigned int)blocklen; |
| 13348 |
blocklen = 5552; |
| 13349 |
} |
| 13350 |
return (unsigned int)(s2 << 16) + (unsigned int)s1; |
| 13351 |
} |
| 13352 |
NK_INTERN unsigned int |
| 13353 |
nk_decompress(unsigned char *output, unsigned char *i, unsigned int length) |
| 13354 |
{ |
| 13355 |
unsigned int olen; |
| 13356 |
if (nk__in4(0) != 0x57bC0000) return 0; |
| 13357 |
if (nk__in4(4) != 0) return 0; |
| 13358 |
olen = nk_decompress_length(i); |
| 13359 |
nk__barrier2 = i; |
| 13360 |
nk__barrier3 = i+length; |
| 13361 |
nk__barrier = output + olen; |
| 13362 |
nk__barrier4 = output; |
| 13363 |
i += 16; |
| 13364 |
|
| 13365 |
nk__dout = output; |
| 13366 |
for (;;) { |
| 13367 |
unsigned char *old_i = i; |
| 13368 |
i = nk_decompress_token(i); |
| 13369 |
if (i == old_i) { |
| 13370 |
if (*i == 0x05 && i[1] == 0xfa) { |
| 13371 |
NK_ASSERT(nk__dout == output + olen); |
| 13372 |
if (nk__dout != output + olen) return 0; |
| 13373 |
if (nk_adler32(1, output, olen) != (unsigned int) nk__in4(2)) |
| 13374 |
return 0; |
| 13375 |
return olen; |
| 13376 |
} else { |
| 13377 |
NK_ASSERT(0); |
| 13378 |
return 0; |
| 13379 |
} |
| 13380 |
} |
| 13381 |
NK_ASSERT(nk__dout <= output + olen); |
| 13382 |
if (nk__dout > output + olen) |
| 13383 |
return 0; |
| 13384 |
} |
| 13385 |
} |
| 13386 |
NK_INTERN unsigned int |
| 13387 |
nk_decode_85_byte(char c) |
| 13388 |
{ |
| 13389 |
return (unsigned int)((c >= '\\') ? c-36 : c-35); |
| 13390 |
} |
| 13391 |
NK_INTERN void |
| 13392 |
nk_decode_85(unsigned char* dst, const unsigned char* src) |
| 13393 |
{ |
| 13394 |
while (*src) |
| 13395 |
{ |
| 13396 |
unsigned int tmp = |
| 13397 |
nk_decode_85_byte((char)src[0]) + |
| 13398 |
85 * (nk_decode_85_byte((char)src[1]) + |
| 13399 |
85 * (nk_decode_85_byte((char)src[2]) + |
| 13400 |
85 * (nk_decode_85_byte((char)src[3]) + |
| 13401 |
85 * nk_decode_85_byte((char)src[4])))); |
| 13402 |
|
| 13403 |
|
| 13404 |
dst[0] = (unsigned char)((tmp >> 0) & 0xFF); |
| 13405 |
dst[1] = (unsigned char)((tmp >> 8) & 0xFF); |
| 13406 |
dst[2] = (unsigned char)((tmp >> 16) & 0xFF); |
| 13407 |
dst[3] = (unsigned char)((tmp >> 24) & 0xFF); |
| 13408 |
|
| 13409 |
src += 5; |
| 13410 |
dst += 4; |
| 13411 |
} |
| 13412 |
} |
| 13413 |
|
| 13414 |
|
| 13415 |
|
| 13416 |
|
| 13417 |
|
| 13418 |
|
| 13419 |
NK_API struct nk_font_config |
| 13420 |
nk_font_config(float pixel_height) |
| 13421 |
{ |
| 13422 |
struct nk_font_config cfg; |
| 13423 |
nk_zero_struct(cfg); |
| 13424 |
cfg.ttf_blob = 0; |
| 13425 |
cfg.ttf_size = 0; |
| 13426 |
cfg.ttf_data_owned_by_atlas = 0; |
| 13427 |
cfg.size = pixel_height; |
| 13428 |
cfg.oversample_h = 3; |
| 13429 |
cfg.oversample_v = 1; |
| 13430 |
cfg.pixel_snap = 0; |
| 13431 |
cfg.coord_type = NK_COORD_UV; |
| 13432 |
cfg.spacing = nk_vec2(0,0); |
| 13433 |
cfg.range = nk_font_default_glyph_ranges(); |
| 13434 |
cfg.merge_mode = 0; |
| 13435 |
cfg.fallback_glyph = '?'; |
| 13436 |
cfg.font = 0; |
| 13437 |
cfg.n = 0; |
| 13438 |
return cfg; |
| 13439 |
} |
| 13440 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 13441 |
NK_API void |
| 13442 |
nk_font_atlas_init_default(struct nk_font_atlas *atlas) |
| 13443 |
{ |
| 13444 |
NK_ASSERT(atlas); |
| 13445 |
if (!atlas) return; |
| 13446 |
nk_zero_struct(*atlas); |
| 13447 |
atlas->temporary.userdata.ptr = 0; |
| 13448 |
atlas->temporary.alloc = nk_malloc; |
| 13449 |
atlas->temporary.free = nk_mfree; |
| 13450 |
atlas->permanent.userdata.ptr = 0; |
| 13451 |
atlas->permanent.alloc = nk_malloc; |
| 13452 |
atlas->permanent.free = nk_mfree; |
| 13453 |
} |
| 13454 |
#endif |
| 13455 |
NK_API void |
| 13456 |
nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc) |
| 13457 |
{ |
| 13458 |
NK_ASSERT(atlas); |
| 13459 |
NK_ASSERT(alloc); |
| 13460 |
if (!atlas || !alloc) return; |
| 13461 |
nk_zero_struct(*atlas); |
| 13462 |
atlas->permanent = *alloc; |
| 13463 |
atlas->temporary = *alloc; |
| 13464 |
} |
| 13465 |
NK_API void |
| 13466 |
nk_font_atlas_init_custom(struct nk_font_atlas *atlas, |
| 13467 |
struct nk_allocator *permanent, struct nk_allocator *temporary) |
| 13468 |
{ |
| 13469 |
NK_ASSERT(atlas); |
| 13470 |
NK_ASSERT(permanent); |
| 13471 |
NK_ASSERT(temporary); |
| 13472 |
if (!atlas || !permanent || !temporary) return; |
| 13473 |
nk_zero_struct(*atlas); |
| 13474 |
atlas->permanent = *permanent; |
| 13475 |
atlas->temporary = *temporary; |
| 13476 |
} |
| 13477 |
NK_API void |
| 13478 |
nk_font_atlas_begin(struct nk_font_atlas *atlas) |
| 13479 |
{ |
| 13480 |
NK_ASSERT(atlas); |
| 13481 |
NK_ASSERT(atlas->temporary.alloc && atlas->temporary.free); |
| 13482 |
NK_ASSERT(atlas->permanent.alloc && atlas->permanent.free); |
| 13483 |
if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free || |
| 13484 |
!atlas->temporary.alloc || !atlas->temporary.free) return; |
| 13485 |
if (atlas->glyphs) { |
| 13486 |
atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs); |
| 13487 |
atlas->glyphs = 0; |
| 13488 |
} |
| 13489 |
if (atlas->pixel) { |
| 13490 |
atlas->permanent.free(atlas->permanent.userdata, atlas->pixel); |
| 13491 |
atlas->pixel = 0; |
| 13492 |
} |
| 13493 |
} |
| 13494 |
NK_API struct nk_font* |
| 13495 |
nk_font_atlas_add(struct nk_font_atlas *atlas, const struct nk_font_config *config) |
| 13496 |
{ |
| 13497 |
struct nk_font *font = 0; |
| 13498 |
struct nk_font_config *cfg; |
| 13499 |
|
| 13500 |
NK_ASSERT(atlas); |
| 13501 |
NK_ASSERT(atlas->permanent.alloc); |
| 13502 |
NK_ASSERT(atlas->permanent.free); |
| 13503 |
NK_ASSERT(atlas->temporary.alloc); |
| 13504 |
NK_ASSERT(atlas->temporary.free); |
| 13505 |
|
| 13506 |
NK_ASSERT(config); |
| 13507 |
NK_ASSERT(config->ttf_blob); |
| 13508 |
NK_ASSERT(config->ttf_size); |
| 13509 |
NK_ASSERT(config->size > 0.0f); |
| 13510 |
|
| 13511 |
if (!atlas || !config || !config->ttf_blob || !config->ttf_size || config->size <= 0.0f|| |
| 13512 |
!atlas->permanent.alloc || !atlas->permanent.free || |
| 13513 |
!atlas->temporary.alloc || !atlas->temporary.free) |
| 13514 |
return 0; |
| 13515 |
|
| 13516 |
|
| 13517 |
cfg = (struct nk_font_config*) |
| 13518 |
atlas->permanent.alloc(atlas->permanent.userdata,0, sizeof(struct nk_font_config)); |
| 13519 |
NK_MEMCPY(cfg, config, sizeof(*config)); |
| 13520 |
cfg->n = cfg; |
| 13521 |
cfg->p = cfg; |
| 13522 |
|
| 13523 |
if (!config->merge_mode) { |
| 13524 |
|
| 13525 |
if (!atlas->config) { |
| 13526 |
atlas->config = cfg; |
| 13527 |
cfg->next = 0; |
| 13528 |
} else { |
| 13529 |
struct nk_font_config *i = atlas->config; |
| 13530 |
while (i->next) i = i->next; |
| 13531 |
i->next = cfg; |
| 13532 |
cfg->next = 0; |
| 13533 |
} |
| 13534 |
|
| 13535 |
font = (struct nk_font*) |
| 13536 |
atlas->permanent.alloc(atlas->permanent.userdata,0, sizeof(struct nk_font)); |
| 13537 |
NK_ASSERT(font); |
| 13538 |
nk_zero(font, sizeof(*font)); |
| 13539 |
if (!font) return 0; |
| 13540 |
font->config = cfg; |
| 13541 |
|
| 13542 |
|
| 13543 |
if (!atlas->fonts) { |
| 13544 |
atlas->fonts = font; |
| 13545 |
font->next = 0; |
| 13546 |
} else { |
| 13547 |
struct nk_font *i = atlas->fonts; |
| 13548 |
while (i->next) i = i->next; |
| 13549 |
i->next = font; |
| 13550 |
font->next = 0; |
| 13551 |
} |
| 13552 |
cfg->font = &font->info; |
| 13553 |
} else { |
| 13554 |
|
| 13555 |
struct nk_font *f = 0; |
| 13556 |
struct nk_font_config *c = 0; |
| 13557 |
NK_ASSERT(atlas->font_num); |
| 13558 |
f = atlas->fonts; |
| 13559 |
c = f->config; |
| 13560 |
cfg->font = &f->info; |
| 13561 |
|
| 13562 |
cfg->n = c; |
| 13563 |
cfg->p = c->p; |
| 13564 |
c->p->n = cfg; |
| 13565 |
c->p = cfg; |
| 13566 |
} |
| 13567 |
|
| 13568 |
if (!config->ttf_data_owned_by_atlas) { |
| 13569 |
cfg->ttf_blob = atlas->permanent.alloc(atlas->permanent.userdata,0, cfg->ttf_size); |
| 13570 |
NK_ASSERT(cfg->ttf_blob); |
| 13571 |
if (!cfg->ttf_blob) { |
| 13572 |
atlas->font_num++; |
| 13573 |
return 0; |
| 13574 |
} |
| 13575 |
NK_MEMCPY(cfg->ttf_blob, config->ttf_blob, cfg->ttf_size); |
| 13576 |
cfg->ttf_data_owned_by_atlas = 1; |
| 13577 |
} |
| 13578 |
atlas->font_num++; |
| 13579 |
return font; |
| 13580 |
} |
| 13581 |
NK_API struct nk_font* |
| 13582 |
nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory, |
| 13583 |
nk_size size, float height, const struct nk_font_config *config) |
| 13584 |
{ |
| 13585 |
struct nk_font_config cfg; |
| 13586 |
NK_ASSERT(memory); |
| 13587 |
NK_ASSERT(size); |
| 13588 |
|
| 13589 |
NK_ASSERT(atlas); |
| 13590 |
NK_ASSERT(atlas->temporary.alloc); |
| 13591 |
NK_ASSERT(atlas->temporary.free); |
| 13592 |
NK_ASSERT(atlas->permanent.alloc); |
| 13593 |
NK_ASSERT(atlas->permanent.free); |
| 13594 |
if (!atlas || !atlas->temporary.alloc || !atlas->temporary.free || !memory || !size || |
| 13595 |
!atlas->permanent.alloc || !atlas->permanent.free) |
| 13596 |
return 0; |
| 13597 |
|
| 13598 |
cfg = (config) ? *config: nk_font_config(height); |
| 13599 |
cfg.ttf_blob = memory; |
| 13600 |
cfg.ttf_size = size; |
| 13601 |
cfg.size = height; |
| 13602 |
cfg.ttf_data_owned_by_atlas = 0; |
| 13603 |
return nk_font_atlas_add(atlas, &cfg); |
| 13604 |
} |
| 13605 |
#ifdef NK_INCLUDE_STANDARD_IO |
| 13606 |
NK_API struct nk_font* |
| 13607 |
nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path, |
| 13608 |
float height, const struct nk_font_config *config) |
| 13609 |
{ |
| 13610 |
nk_size size; |
| 13611 |
char *memory; |
| 13612 |
struct nk_font_config cfg; |
| 13613 |
|
| 13614 |
NK_ASSERT(atlas); |
| 13615 |
NK_ASSERT(atlas->temporary.alloc); |
| 13616 |
NK_ASSERT(atlas->temporary.free); |
| 13617 |
NK_ASSERT(atlas->permanent.alloc); |
| 13618 |
NK_ASSERT(atlas->permanent.free); |
| 13619 |
|
| 13620 |
if (!atlas || !file_path) return 0; |
| 13621 |
memory = nk_file_load(file_path, &size, &atlas->permanent); |
| 13622 |
if (!memory) return 0; |
| 13623 |
|
| 13624 |
cfg = (config) ? *config: nk_font_config(height); |
| 13625 |
cfg.ttf_blob = memory; |
| 13626 |
cfg.ttf_size = size; |
| 13627 |
cfg.size = height; |
| 13628 |
cfg.ttf_data_owned_by_atlas = 1; |
| 13629 |
return nk_font_atlas_add(atlas, &cfg); |
| 13630 |
} |
| 13631 |
#endif |
| 13632 |
NK_API struct nk_font* |
| 13633 |
nk_font_atlas_add_compressed(struct nk_font_atlas *atlas, |
| 13634 |
void *compressed_data, nk_size compressed_size, float height, |
| 13635 |
const struct nk_font_config *config) |
| 13636 |
{ |
| 13637 |
unsigned int decompressed_size; |
| 13638 |
void *decompressed_data; |
| 13639 |
struct nk_font_config cfg; |
| 13640 |
|
| 13641 |
NK_ASSERT(atlas); |
| 13642 |
NK_ASSERT(atlas->temporary.alloc); |
| 13643 |
NK_ASSERT(atlas->temporary.free); |
| 13644 |
NK_ASSERT(atlas->permanent.alloc); |
| 13645 |
NK_ASSERT(atlas->permanent.free); |
| 13646 |
|
| 13647 |
NK_ASSERT(compressed_data); |
| 13648 |
NK_ASSERT(compressed_size); |
| 13649 |
if (!atlas || !compressed_data || !atlas->temporary.alloc || !atlas->temporary.free || |
| 13650 |
!atlas->permanent.alloc || !atlas->permanent.free) |
| 13651 |
return 0; |
| 13652 |
|
| 13653 |
decompressed_size = nk_decompress_length((unsigned char*)compressed_data); |
| 13654 |
decompressed_data = atlas->permanent.alloc(atlas->permanent.userdata,0,decompressed_size); |
| 13655 |
NK_ASSERT(decompressed_data); |
| 13656 |
if (!decompressed_data) return 0; |
| 13657 |
nk_decompress((unsigned char*)decompressed_data, (unsigned char*)compressed_data, |
| 13658 |
(unsigned int)compressed_size); |
| 13659 |
|
| 13660 |
cfg = (config) ? *config: nk_font_config(height); |
| 13661 |
cfg.ttf_blob = decompressed_data; |
| 13662 |
cfg.ttf_size = decompressed_size; |
| 13663 |
cfg.size = height; |
| 13664 |
cfg.ttf_data_owned_by_atlas = 1; |
| 13665 |
return nk_font_atlas_add(atlas, &cfg); |
| 13666 |
} |
| 13667 |
NK_API struct nk_font* |
| 13668 |
nk_font_atlas_add_compressed_base85(struct nk_font_atlas *atlas, |
| 13669 |
const char *data_base85, float height, const struct nk_font_config *config) |
| 13670 |
{ |
| 13671 |
int compressed_size; |
| 13672 |
void *compressed_data; |
| 13673 |
struct nk_font *font; |
| 13674 |
|
| 13675 |
NK_ASSERT(atlas); |
| 13676 |
NK_ASSERT(atlas->temporary.alloc); |
| 13677 |
NK_ASSERT(atlas->temporary.free); |
| 13678 |
NK_ASSERT(atlas->permanent.alloc); |
| 13679 |
NK_ASSERT(atlas->permanent.free); |
| 13680 |
|
| 13681 |
NK_ASSERT(data_base85); |
| 13682 |
if (!atlas || !data_base85 || !atlas->temporary.alloc || !atlas->temporary.free || |
| 13683 |
!atlas->permanent.alloc || !atlas->permanent.free) |
| 13684 |
return 0; |
| 13685 |
|
| 13686 |
compressed_size = (((int)nk_strlen(data_base85) + 4) / 5) * 4; |
| 13687 |
compressed_data = atlas->temporary.alloc(atlas->temporary.userdata,0, (nk_size)compressed_size); |
| 13688 |
NK_ASSERT(compressed_data); |
| 13689 |
if (!compressed_data) return 0; |
| 13690 |
nk_decode_85((unsigned char*)compressed_data, (const unsigned char*)data_base85); |
| 13691 |
font = nk_font_atlas_add_compressed(atlas, compressed_data, |
| 13692 |
(nk_size)compressed_size, height, config); |
| 13693 |
atlas->temporary.free(atlas->temporary.userdata, compressed_data); |
| 13694 |
return font; |
| 13695 |
} |
| 13696 |
|
| 13697 |
#ifdef NK_INCLUDE_DEFAULT_FONT |
| 13698 |
NK_API struct nk_font* |
| 13699 |
nk_font_atlas_add_default(struct nk_font_atlas *atlas, |
| 13700 |
float pixel_height, const struct nk_font_config *config) |
| 13701 |
{ |
| 13702 |
NK_ASSERT(atlas); |
| 13703 |
NK_ASSERT(atlas->temporary.alloc); |
| 13704 |
NK_ASSERT(atlas->temporary.free); |
| 13705 |
NK_ASSERT(atlas->permanent.alloc); |
| 13706 |
NK_ASSERT(atlas->permanent.free); |
| 13707 |
return nk_font_atlas_add_compressed_base85(atlas, |
| 13708 |
nk_proggy_clean_ttf_compressed_data_base85, pixel_height, config); |
| 13709 |
} |
| 13710 |
#endif |
| 13711 |
NK_API const void* |
| 13712 |
nk_font_atlas_bake(struct nk_font_atlas *atlas, int *width, int *height, |
| 13713 |
enum nk_font_atlas_format fmt) |
| 13714 |
{ |
| 13715 |
int i = 0; |
| 13716 |
void *tmp = 0; |
| 13717 |
nk_size tmp_size, img_size; |
| 13718 |
struct nk_font *font_iter; |
| 13719 |
struct nk_font_baker *baker; |
| 13720 |
|
| 13721 |
NK_ASSERT(atlas); |
| 13722 |
NK_ASSERT(atlas->temporary.alloc); |
| 13723 |
NK_ASSERT(atlas->temporary.free); |
| 13724 |
NK_ASSERT(atlas->permanent.alloc); |
| 13725 |
NK_ASSERT(atlas->permanent.free); |
| 13726 |
|
| 13727 |
NK_ASSERT(width); |
| 13728 |
NK_ASSERT(height); |
| 13729 |
if (!atlas || !width || !height || |
| 13730 |
!atlas->temporary.alloc || !atlas->temporary.free || |
| 13731 |
!atlas->permanent.alloc || !atlas->permanent.free) |
| 13732 |
return 0; |
| 13733 |
|
| 13734 |
#ifdef NK_INCLUDE_DEFAULT_FONT |
| 13735 |
|
| 13736 |
if (!atlas->font_num) |
| 13737 |
atlas->default_font = nk_font_atlas_add_default(atlas, 13.0f, 0); |
| 13738 |
#endif |
| 13739 |
NK_ASSERT(atlas->font_num); |
| 13740 |
if (!atlas->font_num) return 0; |
| 13741 |
|
| 13742 |
|
| 13743 |
nk_font_baker_memory(&tmp_size, &atlas->glyph_count, atlas->config, atlas->font_num); |
| 13744 |
tmp = atlas->temporary.alloc(atlas->temporary.userdata,0, tmp_size); |
| 13745 |
NK_ASSERT(tmp); |
| 13746 |
if (!tmp) goto failed; |
| 13747 |
|
| 13748 |
|
| 13749 |
baker = nk_font_baker(tmp, atlas->glyph_count, atlas->font_num, &atlas->temporary); |
| 13750 |
atlas->glyphs = (struct nk_font_glyph*)atlas->permanent.alloc( |
| 13751 |
atlas->permanent.userdata,0, sizeof(struct nk_font_glyph)*(nk_size)atlas->glyph_count); |
| 13752 |
NK_ASSERT(atlas->glyphs); |
| 13753 |
if (!atlas->glyphs) |
| 13754 |
goto failed; |
| 13755 |
|
| 13756 |
|
| 13757 |
atlas->custom.w = (NK_CURSOR_DATA_W*2)+1; |
| 13758 |
atlas->custom.h = NK_CURSOR_DATA_H + 1; |
| 13759 |
if (!nk_font_bake_pack(baker, &img_size, width, height, &atlas->custom, |
| 13760 |
atlas->config, atlas->font_num, &atlas->temporary)) |
| 13761 |
goto failed; |
| 13762 |
|
| 13763 |
|
| 13764 |
atlas->pixel = atlas->temporary.alloc(atlas->temporary.userdata,0, img_size); |
| 13765 |
NK_ASSERT(atlas->pixel); |
| 13766 |
if (!atlas->pixel) |
| 13767 |
goto failed; |
| 13768 |
|
| 13769 |
|
| 13770 |
nk_font_bake(baker, atlas->pixel, *width, *height, |
| 13771 |
atlas->glyphs, atlas->glyph_count, atlas->config, atlas->font_num); |
| 13772 |
nk_font_bake_custom_data(atlas->pixel, *width, *height, atlas->custom, |
| 13773 |
nk_custom_cursor_data, NK_CURSOR_DATA_W, NK_CURSOR_DATA_H, '.', 'X'); |
| 13774 |
|
| 13775 |
if (fmt == NK_FONT_ATLAS_RGBA32) { |
| 13776 |
|
| 13777 |
void *img_rgba = atlas->temporary.alloc(atlas->temporary.userdata,0, |
| 13778 |
(nk_size)(*width * *height * 4)); |
| 13779 |
NK_ASSERT(img_rgba); |
| 13780 |
if (!img_rgba) goto failed; |
| 13781 |
nk_font_bake_convert(img_rgba, *width, *height, atlas->pixel); |
| 13782 |
atlas->temporary.free(atlas->temporary.userdata, atlas->pixel); |
| 13783 |
atlas->pixel = img_rgba; |
| 13784 |
} |
| 13785 |
atlas->tex_width = *width; |
| 13786 |
atlas->tex_height = *height; |
| 13787 |
|
| 13788 |
|
| 13789 |
for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) { |
| 13790 |
struct nk_font *font = font_iter; |
| 13791 |
struct nk_font_config *config = font->config; |
| 13792 |
nk_font_init(font, config->size, config->fallback_glyph, atlas->glyphs, |
| 13793 |
config->font, nk_handle_ptr(0)); |
| 13794 |
} |
| 13795 |
|
| 13796 |
|
| 13797 |
{NK_STORAGE const struct nk_vec2 nk_cursor_data[NK_CURSOR_COUNT][3] = { |
| 13798 |
|
| 13799 |
{{ 0, 3}, {12,19}, { 0, 0}}, |
| 13800 |
{{13, 0}, { 7,16}, { 4, 8}}, |
| 13801 |
{{31, 0}, {23,23}, {11,11}}, |
| 13802 |
{{21, 0}, { 9, 23}, { 5,11}}, |
| 13803 |
{{55,18}, {23, 9}, {11, 5}}, |
| 13804 |
{{73, 0}, {17,17}, { 9, 9}}, |
| 13805 |
{{55, 0}, {17,17}, { 9, 9}} |
| 13806 |
}; |
| 13807 |
for (i = 0; i < NK_CURSOR_COUNT; ++i) { |
| 13808 |
struct nk_cursor *cursor = &atlas->cursors[i]; |
| 13809 |
cursor->img.w = (unsigned short)*width; |
| 13810 |
cursor->img.h = (unsigned short)*height; |
| 13811 |
cursor->img.region[0] = (unsigned short)(atlas->custom.x + nk_cursor_data[i][0].x); |
| 13812 |
cursor->img.region[1] = (unsigned short)(atlas->custom.y + nk_cursor_data[i][0].y); |
| 13813 |
cursor->img.region[2] = (unsigned short)nk_cursor_data[i][1].x; |
| 13814 |
cursor->img.region[3] = (unsigned short)nk_cursor_data[i][1].y; |
| 13815 |
cursor->size = nk_cursor_data[i][1]; |
| 13816 |
cursor->offset = nk_cursor_data[i][2]; |
| 13817 |
}} |
| 13818 |
|
| 13819 |
atlas->temporary.free(atlas->temporary.userdata, tmp); |
| 13820 |
return atlas->pixel; |
| 13821 |
|
| 13822 |
failed: |
| 13823 |
|
| 13824 |
if (tmp) atlas->temporary.free(atlas->temporary.userdata, tmp); |
| 13825 |
if (atlas->glyphs) { |
| 13826 |
atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs); |
| 13827 |
atlas->glyphs = 0; |
| 13828 |
} |
| 13829 |
if (atlas->pixel) { |
| 13830 |
atlas->temporary.free(atlas->temporary.userdata, atlas->pixel); |
| 13831 |
atlas->pixel = 0; |
| 13832 |
} |
| 13833 |
return 0; |
| 13834 |
} |
| 13835 |
NK_API void |
| 13836 |
nk_font_atlas_end(struct nk_font_atlas *atlas, nk_handle texture, |
| 13837 |
struct nk_draw_null_texture *null) |
| 13838 |
{ |
| 13839 |
int i = 0; |
| 13840 |
struct nk_font *font_iter; |
| 13841 |
NK_ASSERT(atlas); |
| 13842 |
if (!atlas) { |
| 13843 |
if (!null) return; |
| 13844 |
null->texture = texture; |
| 13845 |
null->uv = nk_vec2(0.5f,0.5f); |
| 13846 |
} |
| 13847 |
if (null) { |
| 13848 |
null->texture = texture; |
| 13849 |
null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width; |
| 13850 |
null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height; |
| 13851 |
} |
| 13852 |
for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) { |
| 13853 |
font_iter->texture = texture; |
| 13854 |
#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT |
| 13855 |
font_iter->handle.texture = texture; |
| 13856 |
#endif |
| 13857 |
} |
| 13858 |
for (i = 0; i < NK_CURSOR_COUNT; ++i) |
| 13859 |
atlas->cursors[i].img.handle = texture; |
| 13860 |
|
| 13861 |
atlas->temporary.free(atlas->temporary.userdata, atlas->pixel); |
| 13862 |
atlas->pixel = 0; |
| 13863 |
atlas->tex_width = 0; |
| 13864 |
atlas->tex_height = 0; |
| 13865 |
atlas->custom.x = 0; |
| 13866 |
atlas->custom.y = 0; |
| 13867 |
atlas->custom.w = 0; |
| 13868 |
atlas->custom.h = 0; |
| 13869 |
} |
| 13870 |
NK_API void |
| 13871 |
nk_font_atlas_cleanup(struct nk_font_atlas *atlas) |
| 13872 |
{ |
| 13873 |
NK_ASSERT(atlas); |
| 13874 |
NK_ASSERT(atlas->temporary.alloc); |
| 13875 |
NK_ASSERT(atlas->temporary.free); |
| 13876 |
NK_ASSERT(atlas->permanent.alloc); |
| 13877 |
NK_ASSERT(atlas->permanent.free); |
| 13878 |
if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free) return; |
| 13879 |
if (atlas->config) { |
| 13880 |
struct nk_font_config *iter; |
| 13881 |
for (iter = atlas->config; iter; iter = iter->next) { |
| 13882 |
struct nk_font_config *i; |
| 13883 |
for (i = iter->n; i != iter; i = i->n) { |
| 13884 |
atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob); |
| 13885 |
i->ttf_blob = 0; |
| 13886 |
} |
| 13887 |
atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob); |
| 13888 |
iter->ttf_blob = 0; |
| 13889 |
} |
| 13890 |
} |
| 13891 |
} |
| 13892 |
NK_API void |
| 13893 |
nk_font_atlas_clear(struct nk_font_atlas *atlas) |
| 13894 |
{ |
| 13895 |
NK_ASSERT(atlas); |
| 13896 |
NK_ASSERT(atlas->temporary.alloc); |
| 13897 |
NK_ASSERT(atlas->temporary.free); |
| 13898 |
NK_ASSERT(atlas->permanent.alloc); |
| 13899 |
NK_ASSERT(atlas->permanent.free); |
| 13900 |
if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free) return; |
| 13901 |
|
| 13902 |
if (atlas->config) { |
| 13903 |
struct nk_font_config *iter, *next; |
| 13904 |
for (iter = atlas->config; iter; iter = next) { |
| 13905 |
struct nk_font_config *i, *n; |
| 13906 |
for (i = iter->n; i != iter; i = n) { |
| 13907 |
n = i->n; |
| 13908 |
if (i->ttf_blob) |
| 13909 |
atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob); |
| 13910 |
atlas->permanent.free(atlas->permanent.userdata, i); |
| 13911 |
} |
| 13912 |
next = iter->next; |
| 13913 |
if (i->ttf_blob) |
| 13914 |
atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob); |
| 13915 |
atlas->permanent.free(atlas->permanent.userdata, iter); |
| 13916 |
} |
| 13917 |
atlas->config = 0; |
| 13918 |
} |
| 13919 |
if (atlas->fonts) { |
| 13920 |
struct nk_font *iter, *next; |
| 13921 |
for (iter = atlas->fonts; iter; iter = next) { |
| 13922 |
next = iter->next; |
| 13923 |
atlas->permanent.free(atlas->permanent.userdata, iter); |
| 13924 |
} |
| 13925 |
atlas->fonts = 0; |
| 13926 |
} |
| 13927 |
if (atlas->glyphs) |
| 13928 |
atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs); |
| 13929 |
nk_zero_struct(*atlas); |
| 13930 |
} |
| 13931 |
#endif |
| 13932 |
|
| 13933 |
|
| 13934 |
|
| 13935 |
|
| 13936 |
|
| 13937 |
|
| 13938 |
|
| 13939 |
|
| 13940 |
|
| 13941 |
|
| 13942 |
NK_API void |
| 13943 |
nk_input_begin(struct nk_context *ctx) |
| 13944 |
{ |
| 13945 |
int i; |
| 13946 |
struct nk_input *in; |
| 13947 |
NK_ASSERT(ctx); |
| 13948 |
if (!ctx) return; |
| 13949 |
in = &ctx->input; |
| 13950 |
for (i = 0; i < NK_BUTTON_MAX; ++i) |
| 13951 |
in->mouse.buttons[i].clicked = 0; |
| 13952 |
|
| 13953 |
in->keyboard.text_len = 0; |
| 13954 |
in->mouse.scroll_delta = nk_vec2(0,0); |
| 13955 |
in->mouse.prev.x = in->mouse.pos.x; |
| 13956 |
in->mouse.prev.y = in->mouse.pos.y; |
| 13957 |
in->mouse.delta.x = 0; |
| 13958 |
in->mouse.delta.y = 0; |
| 13959 |
for (i = 0; i < NK_KEY_MAX; i++) |
| 13960 |
in->keyboard.keys[i].clicked = 0; |
| 13961 |
} |
| 13962 |
NK_API void |
| 13963 |
nk_input_end(struct nk_context *ctx) |
| 13964 |
{ |
| 13965 |
struct nk_input *in; |
| 13966 |
NK_ASSERT(ctx); |
| 13967 |
if (!ctx) return; |
| 13968 |
in = &ctx->input; |
| 13969 |
if (in->mouse.grab) |
| 13970 |
in->mouse.grab = 0; |
| 13971 |
if (in->mouse.ungrab) { |
| 13972 |
in->mouse.grabbed = 0; |
| 13973 |
in->mouse.ungrab = 0; |
| 13974 |
in->mouse.grab = 0; |
| 13975 |
} |
| 13976 |
} |
| 13977 |
NK_API void |
| 13978 |
nk_input_motion(struct nk_context *ctx, int x, int y) |
| 13979 |
{ |
| 13980 |
struct nk_input *in; |
| 13981 |
NK_ASSERT(ctx); |
| 13982 |
if (!ctx) return; |
| 13983 |
in = &ctx->input; |
| 13984 |
in->mouse.pos.x = (float)x; |
| 13985 |
in->mouse.pos.y = (float)y; |
| 13986 |
in->mouse.delta.x = in->mouse.pos.x - in->mouse.prev.x; |
| 13987 |
in->mouse.delta.y = in->mouse.pos.y - in->mouse.prev.y; |
| 13988 |
} |
| 13989 |
NK_API void |
| 13990 |
nk_input_key(struct nk_context *ctx, enum nk_keys key, int down) |
| 13991 |
{ |
| 13992 |
struct nk_input *in; |
| 13993 |
NK_ASSERT(ctx); |
| 13994 |
if (!ctx) return; |
| 13995 |
in = &ctx->input; |
| 13996 |
#ifdef NK_KEYSTATE_BASED_INPUT |
| 13997 |
if (in->keyboard.keys[key].down != down) |
| 13998 |
in->keyboard.keys[key].clicked++; |
| 13999 |
#else |
| 14000 |
in->keyboard.keys[key].clicked++; |
| 14001 |
#endif |
| 14002 |
in->keyboard.keys[key].down = down; |
| 14003 |
} |
| 14004 |
NK_API void |
| 14005 |
nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, int down) |
| 14006 |
{ |
| 14007 |
struct nk_mouse_button *btn; |
| 14008 |
struct nk_input *in; |
| 14009 |
NK_ASSERT(ctx); |
| 14010 |
if (!ctx) return; |
| 14011 |
in = &ctx->input; |
| 14012 |
if (in->mouse.buttons[id].down == down) return; |
| 14013 |
|
| 14014 |
btn = &in->mouse.buttons[id]; |
| 14015 |
btn->clicked_pos.x = (float)x; |
| 14016 |
btn->clicked_pos.y = (float)y; |
| 14017 |
btn->down = down; |
| 14018 |
btn->clicked++; |
| 14019 |
} |
| 14020 |
NK_API void |
| 14021 |
nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val) |
| 14022 |
{ |
| 14023 |
NK_ASSERT(ctx); |
| 14024 |
if (!ctx) return; |
| 14025 |
ctx->input.mouse.scroll_delta.x += val.x; |
| 14026 |
ctx->input.mouse.scroll_delta.y += val.y; |
| 14027 |
} |
| 14028 |
NK_API void |
| 14029 |
nk_input_glyph(struct nk_context *ctx, const nk_glyph glyph) |
| 14030 |
{ |
| 14031 |
int len = 0; |
| 14032 |
nk_rune unicode; |
| 14033 |
struct nk_input *in; |
| 14034 |
|
| 14035 |
NK_ASSERT(ctx); |
| 14036 |
if (!ctx) return; |
| 14037 |
in = &ctx->input; |
| 14038 |
|
| 14039 |
len = nk_utf_decode(glyph, &unicode, NK_UTF_SIZE); |
| 14040 |
if (len && ((in->keyboard.text_len + len) < NK_INPUT_MAX)) { |
| 14041 |
nk_utf_encode(unicode, &in->keyboard.text[in->keyboard.text_len], |
| 14042 |
NK_INPUT_MAX - in->keyboard.text_len); |
| 14043 |
in->keyboard.text_len += len; |
| 14044 |
} |
| 14045 |
} |
| 14046 |
NK_API void |
| 14047 |
nk_input_char(struct nk_context *ctx, char c) |
| 14048 |
{ |
| 14049 |
nk_glyph glyph; |
| 14050 |
NK_ASSERT(ctx); |
| 14051 |
if (!ctx) return; |
| 14052 |
glyph[0] = c; |
| 14053 |
nk_input_glyph(ctx, glyph); |
| 14054 |
} |
| 14055 |
NK_API void |
| 14056 |
nk_input_unicode(struct nk_context *ctx, nk_rune unicode) |
| 14057 |
{ |
| 14058 |
nk_glyph rune; |
| 14059 |
NK_ASSERT(ctx); |
| 14060 |
if (!ctx) return; |
| 14061 |
nk_utf_encode(unicode, rune, NK_UTF_SIZE); |
| 14062 |
nk_input_glyph(ctx, rune); |
| 14063 |
} |
| 14064 |
NK_API int |
| 14065 |
nk_input_has_mouse_click(const struct nk_input *i, enum nk_buttons id) |
| 14066 |
{ |
| 14067 |
const struct nk_mouse_button *btn; |
| 14068 |
if (!i) return nk_false; |
| 14069 |
btn = &i->mouse.buttons[id]; |
| 14070 |
return (btn->clicked && btn->down == nk_false) ? nk_true : nk_false; |
| 14071 |
} |
| 14072 |
NK_API int |
| 14073 |
nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, |
| 14074 |
struct nk_rect b) |
| 14075 |
{ |
| 14076 |
const struct nk_mouse_button *btn; |
| 14077 |
if (!i) return nk_false; |
| 14078 |
btn = &i->mouse.buttons[id]; |
| 14079 |
if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)) |
| 14080 |
return nk_false; |
| 14081 |
return nk_true; |
| 14082 |
} |
| 14083 |
NK_API int |
| 14084 |
nk_input_has_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, |
| 14085 |
struct nk_rect b, int down) |
| 14086 |
{ |
| 14087 |
const struct nk_mouse_button *btn; |
| 14088 |
if (!i) return nk_false; |
| 14089 |
btn = &i->mouse.buttons[id]; |
| 14090 |
return nk_input_has_mouse_click_in_rect(i, id, b) && (btn->down == down); |
| 14091 |
} |
| 14092 |
NK_API int |
| 14093 |
nk_input_is_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, |
| 14094 |
struct nk_rect b) |
| 14095 |
{ |
| 14096 |
const struct nk_mouse_button *btn; |
| 14097 |
if (!i) return nk_false; |
| 14098 |
btn = &i->mouse.buttons[id]; |
| 14099 |
return (nk_input_has_mouse_click_down_in_rect(i, id, b, nk_false) && |
| 14100 |
btn->clicked) ? nk_true : nk_false; |
| 14101 |
} |
| 14102 |
NK_API int |
| 14103 |
nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, |
| 14104 |
struct nk_rect b, int down) |
| 14105 |
{ |
| 14106 |
const struct nk_mouse_button *btn; |
| 14107 |
if (!i) return nk_false; |
| 14108 |
btn = &i->mouse.buttons[id]; |
| 14109 |
return (nk_input_has_mouse_click_down_in_rect(i, id, b, down) && |
| 14110 |
btn->clicked) ? nk_true : nk_false; |
| 14111 |
} |
| 14112 |
NK_API int |
| 14113 |
nk_input_any_mouse_click_in_rect(const struct nk_input *in, struct nk_rect b) |
| 14114 |
{ |
| 14115 |
int i, down = 0; |
| 14116 |
for (i = 0; i < NK_BUTTON_MAX; ++i) |
| 14117 |
down = down || nk_input_is_mouse_click_in_rect(in, (enum nk_buttons)i, b); |
| 14118 |
return down; |
| 14119 |
} |
| 14120 |
NK_API int |
| 14121 |
nk_input_is_mouse_hovering_rect(const struct nk_input *i, struct nk_rect rect) |
| 14122 |
{ |
| 14123 |
if (!i) return nk_false; |
| 14124 |
return NK_INBOX(i->mouse.pos.x, i->mouse.pos.y, rect.x, rect.y, rect.w, rect.h); |
| 14125 |
} |
| 14126 |
NK_API int |
| 14127 |
nk_input_is_mouse_prev_hovering_rect(const struct nk_input *i, struct nk_rect rect) |
| 14128 |
{ |
| 14129 |
if (!i) return nk_false; |
| 14130 |
return NK_INBOX(i->mouse.prev.x, i->mouse.prev.y, rect.x, rect.y, rect.w, rect.h); |
| 14131 |
} |
| 14132 |
NK_API int |
| 14133 |
nk_input_mouse_clicked(const struct nk_input *i, enum nk_buttons id, struct nk_rect rect) |
| 14134 |
{ |
| 14135 |
if (!i) return nk_false; |
| 14136 |
if (!nk_input_is_mouse_hovering_rect(i, rect)) return nk_false; |
| 14137 |
return nk_input_is_mouse_click_in_rect(i, id, rect); |
| 14138 |
} |
| 14139 |
NK_API int |
| 14140 |
nk_input_is_mouse_down(const struct nk_input *i, enum nk_buttons id) |
| 14141 |
{ |
| 14142 |
if (!i) return nk_false; |
| 14143 |
return i->mouse.buttons[id].down; |
| 14144 |
} |
| 14145 |
NK_API int |
| 14146 |
nk_input_is_mouse_pressed(const struct nk_input *i, enum nk_buttons id) |
| 14147 |
{ |
| 14148 |
const struct nk_mouse_button *b; |
| 14149 |
if (!i) return nk_false; |
| 14150 |
b = &i->mouse.buttons[id]; |
| 14151 |
if (b->down && b->clicked) |
| 14152 |
return nk_true; |
| 14153 |
return nk_false; |
| 14154 |
} |
| 14155 |
NK_API int |
| 14156 |
nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id) |
| 14157 |
{ |
| 14158 |
if (!i) return nk_false; |
| 14159 |
return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked); |
| 14160 |
} |
| 14161 |
NK_API int |
| 14162 |
nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key) |
| 14163 |
{ |
| 14164 |
const struct nk_key *k; |
| 14165 |
if (!i) return nk_false; |
| 14166 |
k = &i->keyboard.keys[key]; |
| 14167 |
if ((k->down && k->clicked) || (!k->down && k->clicked >= 2)) |
| 14168 |
return nk_true; |
| 14169 |
return nk_false; |
| 14170 |
} |
| 14171 |
NK_API int |
| 14172 |
nk_input_is_key_released(const struct nk_input *i, enum nk_keys key) |
| 14173 |
{ |
| 14174 |
const struct nk_key *k; |
| 14175 |
if (!i) return nk_false; |
| 14176 |
k = &i->keyboard.keys[key]; |
| 14177 |
if ((!k->down && k->clicked) || (k->down && k->clicked >= 2)) |
| 14178 |
return nk_true; |
| 14179 |
return nk_false; |
| 14180 |
} |
| 14181 |
NK_API int |
| 14182 |
nk_input_is_key_down(const struct nk_input *i, enum nk_keys key) |
| 14183 |
{ |
| 14184 |
const struct nk_key *k; |
| 14185 |
if (!i) return nk_false; |
| 14186 |
k = &i->keyboard.keys[key]; |
| 14187 |
if (k->down) return nk_true; |
| 14188 |
return nk_false; |
| 14189 |
} |
| 14190 |
|
| 14191 |
|
| 14192 |
|
| 14193 |
|
| 14194 |
|
| 14195 |
|
| 14196 |
|
| 14197 |
|
| 14198 |
|
| 14199 |
|
| 14200 |
NK_API void nk_style_default(struct nk_context *ctx){nk_style_from_table(ctx, 0);} |
| 14201 |
#define NK_COLOR_MAP(NK_COLOR)\ |
| 14202 |
NK_COLOR(NK_COLOR_TEXT, 175,175,175,255) \ |
| 14203 |
NK_COLOR(NK_COLOR_WINDOW, 45, 45, 45, 255) \ |
| 14204 |
NK_COLOR(NK_COLOR_HEADER, 40, 40, 40, 255) \ |
| 14205 |
NK_COLOR(NK_COLOR_BORDER, 65, 65, 65, 255) \ |
| 14206 |
NK_COLOR(NK_COLOR_BUTTON, 50, 50, 50, 255) \ |
| 14207 |
NK_COLOR(NK_COLOR_BUTTON_HOVER, 40, 40, 40, 255) \ |
| 14208 |
NK_COLOR(NK_COLOR_BUTTON_ACTIVE, 35, 35, 35, 255) \ |
| 14209 |
NK_COLOR(NK_COLOR_TOGGLE, 100,100,100,255) \ |
| 14210 |
NK_COLOR(NK_COLOR_TOGGLE_HOVER, 120,120,120,255) \ |
| 14211 |
NK_COLOR(NK_COLOR_TOGGLE_CURSOR, 45, 45, 45, 255) \ |
| 14212 |
NK_COLOR(NK_COLOR_SELECT, 45, 45, 45, 255) \ |
| 14213 |
NK_COLOR(NK_COLOR_SELECT_ACTIVE, 35, 35, 35,255) \ |
| 14214 |
NK_COLOR(NK_COLOR_SLIDER, 38, 38, 38, 255) \ |
| 14215 |
NK_COLOR(NK_COLOR_SLIDER_CURSOR, 100,100,100,255) \ |
| 14216 |
NK_COLOR(NK_COLOR_SLIDER_CURSOR_HOVER, 120,120,120,255) \ |
| 14217 |
NK_COLOR(NK_COLOR_SLIDER_CURSOR_ACTIVE, 150,150,150,255) \ |
| 14218 |
NK_COLOR(NK_COLOR_PROPERTY, 38, 38, 38, 255) \ |
| 14219 |
NK_COLOR(NK_COLOR_EDIT, 38, 38, 38, 255) \ |
| 14220 |
NK_COLOR(NK_COLOR_EDIT_CURSOR, 175,175,175,255) \ |
| 14221 |
NK_COLOR(NK_COLOR_COMBO, 45, 45, 45, 255) \ |
| 14222 |
NK_COLOR(NK_COLOR_CHART, 120,120,120,255) \ |
| 14223 |
NK_COLOR(NK_COLOR_CHART_COLOR, 45, 45, 45, 255) \ |
| 14224 |
NK_COLOR(NK_COLOR_CHART_COLOR_HIGHLIGHT, 255, 0, 0, 255) \ |
| 14225 |
NK_COLOR(NK_COLOR_SCROLLBAR, 40, 40, 40, 255) \ |
| 14226 |
NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR, 100,100,100,255) \ |
| 14227 |
NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_HOVER, 120,120,120,255) \ |
| 14228 |
NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_ACTIVE, 150,150,150,255) \ |
| 14229 |
NK_COLOR(NK_COLOR_TAB_HEADER, 40, 40, 40,255) |
| 14230 |
|
| 14231 |
NK_GLOBAL const struct nk_color |
| 14232 |
nk_default_color_style[NK_COLOR_COUNT] = { |
| 14233 |
#define NK_COLOR(a,b,c,d,e) {b,c,d,e}, |
| 14234 |
NK_COLOR_MAP(NK_COLOR) |
| 14235 |
#undef NK_COLOR |
| 14236 |
}; |
| 14237 |
NK_GLOBAL const char *nk_color_names[NK_COLOR_COUNT] = { |
| 14238 |
#define NK_COLOR(a,b,c,d,e) #a, |
| 14239 |
NK_COLOR_MAP(NK_COLOR) |
| 14240 |
#undef NK_COLOR |
| 14241 |
}; |
| 14242 |
|
| 14243 |
NK_API const char* |
| 14244 |
nk_style_get_color_by_name(enum nk_style_colors c) |
| 14245 |
{ |
| 14246 |
return nk_color_names[c]; |
| 14247 |
} |
| 14248 |
NK_API struct nk_style_item |
| 14249 |
nk_style_item_image(struct nk_image img) |
| 14250 |
{ |
| 14251 |
struct nk_style_item i; |
| 14252 |
i.type = NK_STYLE_ITEM_IMAGE; |
| 14253 |
i.data.image = img; |
| 14254 |
return i; |
| 14255 |
} |
| 14256 |
NK_API struct nk_style_item |
| 14257 |
nk_style_item_color(struct nk_color col) |
| 14258 |
{ |
| 14259 |
struct nk_style_item i; |
| 14260 |
i.type = NK_STYLE_ITEM_COLOR; |
| 14261 |
i.data.color = col; |
| 14262 |
return i; |
| 14263 |
} |
| 14264 |
NK_API struct nk_style_item |
| 14265 |
nk_style_item_hide(void) |
| 14266 |
{ |
| 14267 |
struct nk_style_item i; |
| 14268 |
i.type = NK_STYLE_ITEM_COLOR; |
| 14269 |
i.data.color = nk_rgba(0,0,0,0); |
| 14270 |
return i; |
| 14271 |
} |
| 14272 |
NK_API void |
| 14273 |
nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) |
| 14274 |
{ |
| 14275 |
struct nk_style *style; |
| 14276 |
struct nk_style_text *text; |
| 14277 |
struct nk_style_button *button; |
| 14278 |
struct nk_style_toggle *toggle; |
| 14279 |
struct nk_style_selectable *select; |
| 14280 |
struct nk_style_slider *slider; |
| 14281 |
struct nk_style_progress *prog; |
| 14282 |
struct nk_style_scrollbar *scroll; |
| 14283 |
struct nk_style_edit *edit; |
| 14284 |
struct nk_style_property *property; |
| 14285 |
struct nk_style_combo *combo; |
| 14286 |
struct nk_style_chart *chart; |
| 14287 |
struct nk_style_tab *tab; |
| 14288 |
struct nk_style_window *win; |
| 14289 |
|
| 14290 |
NK_ASSERT(ctx); |
| 14291 |
if (!ctx) return; |
| 14292 |
style = &ctx->style; |
| 14293 |
table = (!table) ? nk_default_color_style: table; |
| 14294 |
|
| 14295 |
|
| 14296 |
text = &style->text; |
| 14297 |
text->color = table[NK_COLOR_TEXT]; |
| 14298 |
text->padding = nk_vec2(0,0); |
| 14299 |
|
| 14300 |
|
| 14301 |
button = &style->button; |
| 14302 |
nk_zero_struct(*button); |
| 14303 |
button->normal = nk_style_item_color(table[NK_COLOR_BUTTON]); |
| 14304 |
button->hover = nk_style_item_color(table[NK_COLOR_BUTTON_HOVER]); |
| 14305 |
button->active = nk_style_item_color(table[NK_COLOR_BUTTON_ACTIVE]); |
| 14306 |
button->border_color = table[NK_COLOR_BORDER]; |
| 14307 |
button->text_background = table[NK_COLOR_BUTTON]; |
| 14308 |
button->text_normal = table[NK_COLOR_TEXT]; |
| 14309 |
button->text_hover = table[NK_COLOR_TEXT]; |
| 14310 |
button->text_active = table[NK_COLOR_TEXT]; |
| 14311 |
button->padding = nk_vec2(2.0f,2.0f); |
| 14312 |
button->image_padding = nk_vec2(0.0f,0.0f); |
| 14313 |
button->touch_padding = nk_vec2(0.0f, 0.0f); |
| 14314 |
button->userdata = nk_handle_ptr(0); |
| 14315 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14316 |
button->border = 1.0f; |
| 14317 |
button->rounding = 4.0f; |
| 14318 |
button->draw_begin = 0; |
| 14319 |
button->draw_end = 0; |
| 14320 |
|
| 14321 |
|
| 14322 |
button = &style->contextual_button; |
| 14323 |
nk_zero_struct(*button); |
| 14324 |
button->normal = nk_style_item_color(table[NK_COLOR_WINDOW]); |
| 14325 |
button->hover = nk_style_item_color(table[NK_COLOR_BUTTON_HOVER]); |
| 14326 |
button->active = nk_style_item_color(table[NK_COLOR_BUTTON_ACTIVE]); |
| 14327 |
button->border_color = table[NK_COLOR_WINDOW]; |
| 14328 |
button->text_background = table[NK_COLOR_WINDOW]; |
| 14329 |
button->text_normal = table[NK_COLOR_TEXT]; |
| 14330 |
button->text_hover = table[NK_COLOR_TEXT]; |
| 14331 |
button->text_active = table[NK_COLOR_TEXT]; |
| 14332 |
button->padding = nk_vec2(2.0f,2.0f); |
| 14333 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14334 |
button->userdata = nk_handle_ptr(0); |
| 14335 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14336 |
button->border = 0.0f; |
| 14337 |
button->rounding = 0.0f; |
| 14338 |
button->draw_begin = 0; |
| 14339 |
button->draw_end = 0; |
| 14340 |
|
| 14341 |
|
| 14342 |
button = &style->menu_button; |
| 14343 |
nk_zero_struct(*button); |
| 14344 |
button->normal = nk_style_item_color(table[NK_COLOR_WINDOW]); |
| 14345 |
button->hover = nk_style_item_color(table[NK_COLOR_WINDOW]); |
| 14346 |
button->active = nk_style_item_color(table[NK_COLOR_WINDOW]); |
| 14347 |
button->border_color = table[NK_COLOR_WINDOW]; |
| 14348 |
button->text_background = table[NK_COLOR_WINDOW]; |
| 14349 |
button->text_normal = table[NK_COLOR_TEXT]; |
| 14350 |
button->text_hover = table[NK_COLOR_TEXT]; |
| 14351 |
button->text_active = table[NK_COLOR_TEXT]; |
| 14352 |
button->padding = nk_vec2(2.0f,2.0f); |
| 14353 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14354 |
button->userdata = nk_handle_ptr(0); |
| 14355 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14356 |
button->border = 0.0f; |
| 14357 |
button->rounding = 1.0f; |
| 14358 |
button->draw_begin = 0; |
| 14359 |
button->draw_end = 0; |
| 14360 |
|
| 14361 |
|
| 14362 |
toggle = &style->checkbox; |
| 14363 |
nk_zero_struct(*toggle); |
| 14364 |
toggle->normal = nk_style_item_color(table[NK_COLOR_TOGGLE]); |
| 14365 |
toggle->hover = nk_style_item_color(table[NK_COLOR_TOGGLE_HOVER]); |
| 14366 |
toggle->active = nk_style_item_color(table[NK_COLOR_TOGGLE_HOVER]); |
| 14367 |
toggle->cursor_normal = nk_style_item_color(table[NK_COLOR_TOGGLE_CURSOR]); |
| 14368 |
toggle->cursor_hover = nk_style_item_color(table[NK_COLOR_TOGGLE_CURSOR]); |
| 14369 |
toggle->userdata = nk_handle_ptr(0); |
| 14370 |
toggle->text_background = table[NK_COLOR_WINDOW]; |
| 14371 |
toggle->text_normal = table[NK_COLOR_TEXT]; |
| 14372 |
toggle->text_hover = table[NK_COLOR_TEXT]; |
| 14373 |
toggle->text_active = table[NK_COLOR_TEXT]; |
| 14374 |
toggle->padding = nk_vec2(2.0f, 2.0f); |
| 14375 |
toggle->touch_padding = nk_vec2(0,0); |
| 14376 |
toggle->border_color = nk_rgba(0,0,0,0); |
| 14377 |
toggle->border = 0.0f; |
| 14378 |
toggle->spacing = 4; |
| 14379 |
|
| 14380 |
|
| 14381 |
toggle = &style->option; |
| 14382 |
nk_zero_struct(*toggle); |
| 14383 |
toggle->normal = nk_style_item_color(table[NK_COLOR_TOGGLE]); |
| 14384 |
toggle->hover = nk_style_item_color(table[NK_COLOR_TOGGLE_HOVER]); |
| 14385 |
toggle->active = nk_style_item_color(table[NK_COLOR_TOGGLE_HOVER]); |
| 14386 |
toggle->cursor_normal = nk_style_item_color(table[NK_COLOR_TOGGLE_CURSOR]); |
| 14387 |
toggle->cursor_hover = nk_style_item_color(table[NK_COLOR_TOGGLE_CURSOR]); |
| 14388 |
toggle->userdata = nk_handle_ptr(0); |
| 14389 |
toggle->text_background = table[NK_COLOR_WINDOW]; |
| 14390 |
toggle->text_normal = table[NK_COLOR_TEXT]; |
| 14391 |
toggle->text_hover = table[NK_COLOR_TEXT]; |
| 14392 |
toggle->text_active = table[NK_COLOR_TEXT]; |
| 14393 |
toggle->padding = nk_vec2(3.0f, 3.0f); |
| 14394 |
toggle->touch_padding = nk_vec2(0,0); |
| 14395 |
toggle->border_color = nk_rgba(0,0,0,0); |
| 14396 |
toggle->border = 0.0f; |
| 14397 |
toggle->spacing = 4; |
| 14398 |
|
| 14399 |
|
| 14400 |
select = &style->selectable; |
| 14401 |
nk_zero_struct(*select); |
| 14402 |
select->normal = nk_style_item_color(table[NK_COLOR_SELECT]); |
| 14403 |
select->hover = nk_style_item_color(table[NK_COLOR_SELECT]); |
| 14404 |
select->pressed = nk_style_item_color(table[NK_COLOR_SELECT]); |
| 14405 |
select->normal_active = nk_style_item_color(table[NK_COLOR_SELECT_ACTIVE]); |
| 14406 |
select->hover_active = nk_style_item_color(table[NK_COLOR_SELECT_ACTIVE]); |
| 14407 |
select->pressed_active = nk_style_item_color(table[NK_COLOR_SELECT_ACTIVE]); |
| 14408 |
select->text_normal = table[NK_COLOR_TEXT]; |
| 14409 |
select->text_hover = table[NK_COLOR_TEXT]; |
| 14410 |
select->text_pressed = table[NK_COLOR_TEXT]; |
| 14411 |
select->text_normal_active = table[NK_COLOR_TEXT]; |
| 14412 |
select->text_hover_active = table[NK_COLOR_TEXT]; |
| 14413 |
select->text_pressed_active = table[NK_COLOR_TEXT]; |
| 14414 |
select->padding = nk_vec2(2.0f,2.0f); |
| 14415 |
select->image_padding = nk_vec2(2.0f,2.0f); |
| 14416 |
select->touch_padding = nk_vec2(0,0); |
| 14417 |
select->userdata = nk_handle_ptr(0); |
| 14418 |
select->rounding = 0.0f; |
| 14419 |
select->draw_begin = 0; |
| 14420 |
select->draw_end = 0; |
| 14421 |
|
| 14422 |
|
| 14423 |
slider = &style->slider; |
| 14424 |
nk_zero_struct(*slider); |
| 14425 |
slider->normal = nk_style_item_hide(); |
| 14426 |
slider->hover = nk_style_item_hide(); |
| 14427 |
slider->active = nk_style_item_hide(); |
| 14428 |
slider->bar_normal = table[NK_COLOR_SLIDER]; |
| 14429 |
slider->bar_hover = table[NK_COLOR_SLIDER]; |
| 14430 |
slider->bar_active = table[NK_COLOR_SLIDER]; |
| 14431 |
slider->bar_filled = table[NK_COLOR_SLIDER_CURSOR]; |
| 14432 |
slider->cursor_normal = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR]); |
| 14433 |
slider->cursor_hover = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR_HOVER]); |
| 14434 |
slider->cursor_active = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR_ACTIVE]); |
| 14435 |
slider->inc_symbol = NK_SYMBOL_TRIANGLE_RIGHT; |
| 14436 |
slider->dec_symbol = NK_SYMBOL_TRIANGLE_LEFT; |
| 14437 |
slider->cursor_size = nk_vec2(16,16); |
| 14438 |
slider->padding = nk_vec2(2,2); |
| 14439 |
slider->spacing = nk_vec2(2,2); |
| 14440 |
slider->userdata = nk_handle_ptr(0); |
| 14441 |
slider->show_buttons = nk_false; |
| 14442 |
slider->bar_height = 8; |
| 14443 |
slider->rounding = 0; |
| 14444 |
slider->draw_begin = 0; |
| 14445 |
slider->draw_end = 0; |
| 14446 |
|
| 14447 |
|
| 14448 |
button = &style->slider.inc_button; |
| 14449 |
button->normal = nk_style_item_color(nk_rgb(40,40,40)); |
| 14450 |
button->hover = nk_style_item_color(nk_rgb(42,42,42)); |
| 14451 |
button->active = nk_style_item_color(nk_rgb(44,44,44)); |
| 14452 |
button->border_color = nk_rgb(65,65,65); |
| 14453 |
button->text_background = nk_rgb(40,40,40); |
| 14454 |
button->text_normal = nk_rgb(175,175,175); |
| 14455 |
button->text_hover = nk_rgb(175,175,175); |
| 14456 |
button->text_active = nk_rgb(175,175,175); |
| 14457 |
button->padding = nk_vec2(8.0f,8.0f); |
| 14458 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14459 |
button->userdata = nk_handle_ptr(0); |
| 14460 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14461 |
button->border = 1.0f; |
| 14462 |
button->rounding = 0.0f; |
| 14463 |
button->draw_begin = 0; |
| 14464 |
button->draw_end = 0; |
| 14465 |
style->slider.dec_button = style->slider.inc_button; |
| 14466 |
|
| 14467 |
|
| 14468 |
prog = &style->progress; |
| 14469 |
nk_zero_struct(*prog); |
| 14470 |
prog->normal = nk_style_item_color(table[NK_COLOR_SLIDER]); |
| 14471 |
prog->hover = nk_style_item_color(table[NK_COLOR_SLIDER]); |
| 14472 |
prog->active = nk_style_item_color(table[NK_COLOR_SLIDER]); |
| 14473 |
prog->cursor_normal = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR]); |
| 14474 |
prog->cursor_hover = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR_HOVER]); |
| 14475 |
prog->cursor_active = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR_ACTIVE]); |
| 14476 |
prog->border_color = nk_rgba(0,0,0,0); |
| 14477 |
prog->cursor_border_color = nk_rgba(0,0,0,0); |
| 14478 |
prog->userdata = nk_handle_ptr(0); |
| 14479 |
prog->padding = nk_vec2(4,4); |
| 14480 |
prog->rounding = 0; |
| 14481 |
prog->border = 0; |
| 14482 |
prog->cursor_rounding = 0; |
| 14483 |
prog->cursor_border = 0; |
| 14484 |
prog->draw_begin = 0; |
| 14485 |
prog->draw_end = 0; |
| 14486 |
|
| 14487 |
|
| 14488 |
scroll = &style->scrollh; |
| 14489 |
nk_zero_struct(*scroll); |
| 14490 |
scroll->normal = nk_style_item_color(table[NK_COLOR_SCROLLBAR]); |
| 14491 |
scroll->hover = nk_style_item_color(table[NK_COLOR_SCROLLBAR]); |
| 14492 |
scroll->active = nk_style_item_color(table[NK_COLOR_SCROLLBAR]); |
| 14493 |
scroll->cursor_normal = nk_style_item_color(table[NK_COLOR_SCROLLBAR_CURSOR]); |
| 14494 |
scroll->cursor_hover = nk_style_item_color(table[NK_COLOR_SCROLLBAR_CURSOR_HOVER]); |
| 14495 |
scroll->cursor_active = nk_style_item_color(table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE]); |
| 14496 |
scroll->dec_symbol = NK_SYMBOL_CIRCLE_SOLID; |
| 14497 |
scroll->inc_symbol = NK_SYMBOL_CIRCLE_SOLID; |
| 14498 |
scroll->userdata = nk_handle_ptr(0); |
| 14499 |
scroll->border_color = table[NK_COLOR_SCROLLBAR]; |
| 14500 |
scroll->cursor_border_color = table[NK_COLOR_SCROLLBAR]; |
| 14501 |
scroll->padding = nk_vec2(0,0); |
| 14502 |
scroll->show_buttons = nk_false; |
| 14503 |
scroll->border = 0; |
| 14504 |
scroll->rounding = 0; |
| 14505 |
scroll->border_cursor = 0; |
| 14506 |
scroll->rounding_cursor = 0; |
| 14507 |
scroll->draw_begin = 0; |
| 14508 |
scroll->draw_end = 0; |
| 14509 |
style->scrollv = style->scrollh; |
| 14510 |
|
| 14511 |
|
| 14512 |
button = &style->scrollh.inc_button; |
| 14513 |
button->normal = nk_style_item_color(nk_rgb(40,40,40)); |
| 14514 |
button->hover = nk_style_item_color(nk_rgb(42,42,42)); |
| 14515 |
button->active = nk_style_item_color(nk_rgb(44,44,44)); |
| 14516 |
button->border_color = nk_rgb(65,65,65); |
| 14517 |
button->text_background = nk_rgb(40,40,40); |
| 14518 |
button->text_normal = nk_rgb(175,175,175); |
| 14519 |
button->text_hover = nk_rgb(175,175,175); |
| 14520 |
button->text_active = nk_rgb(175,175,175); |
| 14521 |
button->padding = nk_vec2(4.0f,4.0f); |
| 14522 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14523 |
button->userdata = nk_handle_ptr(0); |
| 14524 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14525 |
button->border = 1.0f; |
| 14526 |
button->rounding = 0.0f; |
| 14527 |
button->draw_begin = 0; |
| 14528 |
button->draw_end = 0; |
| 14529 |
style->scrollh.dec_button = style->scrollh.inc_button; |
| 14530 |
style->scrollv.inc_button = style->scrollh.inc_button; |
| 14531 |
style->scrollv.dec_button = style->scrollh.inc_button; |
| 14532 |
|
| 14533 |
|
| 14534 |
edit = &style->edit; |
| 14535 |
nk_zero_struct(*edit); |
| 14536 |
edit->normal = nk_style_item_color(table[NK_COLOR_EDIT]); |
| 14537 |
edit->hover = nk_style_item_color(table[NK_COLOR_EDIT]); |
| 14538 |
edit->active = nk_style_item_color(table[NK_COLOR_EDIT]); |
| 14539 |
edit->cursor_normal = table[NK_COLOR_TEXT]; |
| 14540 |
edit->cursor_hover = table[NK_COLOR_TEXT]; |
| 14541 |
edit->cursor_text_normal= table[NK_COLOR_EDIT]; |
| 14542 |
edit->cursor_text_hover = table[NK_COLOR_EDIT]; |
| 14543 |
edit->border_color = table[NK_COLOR_BORDER]; |
| 14544 |
edit->text_normal = table[NK_COLOR_TEXT]; |
| 14545 |
edit->text_hover = table[NK_COLOR_TEXT]; |
| 14546 |
edit->text_active = table[NK_COLOR_TEXT]; |
| 14547 |
edit->selected_normal = table[NK_COLOR_TEXT]; |
| 14548 |
edit->selected_hover = table[NK_COLOR_TEXT]; |
| 14549 |
edit->selected_text_normal = table[NK_COLOR_EDIT]; |
| 14550 |
edit->selected_text_hover = table[NK_COLOR_EDIT]; |
| 14551 |
edit->scrollbar_size = nk_vec2(10,10); |
| 14552 |
edit->scrollbar = style->scrollv; |
| 14553 |
edit->padding = nk_vec2(4,4); |
| 14554 |
edit->row_padding = 2; |
| 14555 |
edit->cursor_size = 4; |
| 14556 |
edit->border = 1; |
| 14557 |
edit->rounding = 0; |
| 14558 |
|
| 14559 |
|
| 14560 |
property = &style->property; |
| 14561 |
nk_zero_struct(*property); |
| 14562 |
property->normal = nk_style_item_color(table[NK_COLOR_PROPERTY]); |
| 14563 |
property->hover = nk_style_item_color(table[NK_COLOR_PROPERTY]); |
| 14564 |
property->active = nk_style_item_color(table[NK_COLOR_PROPERTY]); |
| 14565 |
property->border_color = table[NK_COLOR_BORDER]; |
| 14566 |
property->label_normal = table[NK_COLOR_TEXT]; |
| 14567 |
property->label_hover = table[NK_COLOR_TEXT]; |
| 14568 |
property->label_active = table[NK_COLOR_TEXT]; |
| 14569 |
property->sym_left = NK_SYMBOL_TRIANGLE_LEFT; |
| 14570 |
property->sym_right = NK_SYMBOL_TRIANGLE_RIGHT; |
| 14571 |
property->userdata = nk_handle_ptr(0); |
| 14572 |
property->padding = nk_vec2(4,4); |
| 14573 |
property->border = 1; |
| 14574 |
property->rounding = 10; |
| 14575 |
property->draw_begin = 0; |
| 14576 |
property->draw_end = 0; |
| 14577 |
|
| 14578 |
|
| 14579 |
button = &style->property.dec_button; |
| 14580 |
nk_zero_struct(*button); |
| 14581 |
button->normal = nk_style_item_color(table[NK_COLOR_PROPERTY]); |
| 14582 |
button->hover = nk_style_item_color(table[NK_COLOR_PROPERTY]); |
| 14583 |
button->active = nk_style_item_color(table[NK_COLOR_PROPERTY]); |
| 14584 |
button->border_color = nk_rgba(0,0,0,0); |
| 14585 |
button->text_background = table[NK_COLOR_PROPERTY]; |
| 14586 |
button->text_normal = table[NK_COLOR_TEXT]; |
| 14587 |
button->text_hover = table[NK_COLOR_TEXT]; |
| 14588 |
button->text_active = table[NK_COLOR_TEXT]; |
| 14589 |
button->padding = nk_vec2(0.0f,0.0f); |
| 14590 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14591 |
button->userdata = nk_handle_ptr(0); |
| 14592 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14593 |
button->border = 0.0f; |
| 14594 |
button->rounding = 0.0f; |
| 14595 |
button->draw_begin = 0; |
| 14596 |
button->draw_end = 0; |
| 14597 |
style->property.inc_button = style->property.dec_button; |
| 14598 |
|
| 14599 |
|
| 14600 |
edit = &style->property.edit; |
| 14601 |
nk_zero_struct(*edit); |
| 14602 |
edit->normal = nk_style_item_color(table[NK_COLOR_PROPERTY]); |
| 14603 |
edit->hover = nk_style_item_color(table[NK_COLOR_PROPERTY]); |
| 14604 |
edit->active = nk_style_item_color(table[NK_COLOR_PROPERTY]); |
| 14605 |
edit->border_color = nk_rgba(0,0,0,0); |
| 14606 |
edit->cursor_normal = table[NK_COLOR_TEXT]; |
| 14607 |
edit->cursor_hover = table[NK_COLOR_TEXT]; |
| 14608 |
edit->cursor_text_normal= table[NK_COLOR_EDIT]; |
| 14609 |
edit->cursor_text_hover = table[NK_COLOR_EDIT]; |
| 14610 |
edit->text_normal = table[NK_COLOR_TEXT]; |
| 14611 |
edit->text_hover = table[NK_COLOR_TEXT]; |
| 14612 |
edit->text_active = table[NK_COLOR_TEXT]; |
| 14613 |
edit->selected_normal = table[NK_COLOR_TEXT]; |
| 14614 |
edit->selected_hover = table[NK_COLOR_TEXT]; |
| 14615 |
edit->selected_text_normal = table[NK_COLOR_EDIT]; |
| 14616 |
edit->selected_text_hover = table[NK_COLOR_EDIT]; |
| 14617 |
edit->padding = nk_vec2(0,0); |
| 14618 |
edit->cursor_size = 8; |
| 14619 |
edit->border = 0; |
| 14620 |
edit->rounding = 0; |
| 14621 |
|
| 14622 |
|
| 14623 |
chart = &style->chart; |
| 14624 |
nk_zero_struct(*chart); |
| 14625 |
chart->background = nk_style_item_color(table[NK_COLOR_CHART]); |
| 14626 |
chart->border_color = table[NK_COLOR_BORDER]; |
| 14627 |
chart->selected_color = table[NK_COLOR_CHART_COLOR_HIGHLIGHT]; |
| 14628 |
chart->color = table[NK_COLOR_CHART_COLOR]; |
| 14629 |
chart->padding = nk_vec2(4,4); |
| 14630 |
chart->border = 0; |
| 14631 |
chart->rounding = 0; |
| 14632 |
|
| 14633 |
|
| 14634 |
combo = &style->combo; |
| 14635 |
combo->normal = nk_style_item_color(table[NK_COLOR_COMBO]); |
| 14636 |
combo->hover = nk_style_item_color(table[NK_COLOR_COMBO]); |
| 14637 |
combo->active = nk_style_item_color(table[NK_COLOR_COMBO]); |
| 14638 |
combo->border_color = table[NK_COLOR_BORDER]; |
| 14639 |
combo->label_normal = table[NK_COLOR_TEXT]; |
| 14640 |
combo->label_hover = table[NK_COLOR_TEXT]; |
| 14641 |
combo->label_active = table[NK_COLOR_TEXT]; |
| 14642 |
combo->sym_normal = NK_SYMBOL_TRIANGLE_DOWN; |
| 14643 |
combo->sym_hover = NK_SYMBOL_TRIANGLE_DOWN; |
| 14644 |
combo->sym_active = NK_SYMBOL_TRIANGLE_DOWN; |
| 14645 |
combo->content_padding = nk_vec2(4,4); |
| 14646 |
combo->button_padding = nk_vec2(0,4); |
| 14647 |
combo->spacing = nk_vec2(4,0); |
| 14648 |
combo->border = 1; |
| 14649 |
combo->rounding = 0; |
| 14650 |
|
| 14651 |
|
| 14652 |
button = &style->combo.button; |
| 14653 |
nk_zero_struct(*button); |
| 14654 |
button->normal = nk_style_item_color(table[NK_COLOR_COMBO]); |
| 14655 |
button->hover = nk_style_item_color(table[NK_COLOR_COMBO]); |
| 14656 |
button->active = nk_style_item_color(table[NK_COLOR_COMBO]); |
| 14657 |
button->border_color = nk_rgba(0,0,0,0); |
| 14658 |
button->text_background = table[NK_COLOR_COMBO]; |
| 14659 |
button->text_normal = table[NK_COLOR_TEXT]; |
| 14660 |
button->text_hover = table[NK_COLOR_TEXT]; |
| 14661 |
button->text_active = table[NK_COLOR_TEXT]; |
| 14662 |
button->padding = nk_vec2(2.0f,2.0f); |
| 14663 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14664 |
button->userdata = nk_handle_ptr(0); |
| 14665 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14666 |
button->border = 0.0f; |
| 14667 |
button->rounding = 0.0f; |
| 14668 |
button->draw_begin = 0; |
| 14669 |
button->draw_end = 0; |
| 14670 |
|
| 14671 |
|
| 14672 |
tab = &style->tab; |
| 14673 |
tab->background = nk_style_item_color(table[NK_COLOR_TAB_HEADER]); |
| 14674 |
tab->border_color = table[NK_COLOR_BORDER]; |
| 14675 |
tab->text = table[NK_COLOR_TEXT]; |
| 14676 |
tab->sym_minimize = NK_SYMBOL_TRIANGLE_RIGHT; |
| 14677 |
tab->sym_maximize = NK_SYMBOL_TRIANGLE_DOWN; |
| 14678 |
tab->padding = nk_vec2(4,4); |
| 14679 |
tab->spacing = nk_vec2(4,4); |
| 14680 |
tab->indent = 10.0f; |
| 14681 |
tab->border = 1; |
| 14682 |
tab->rounding = 0; |
| 14683 |
|
| 14684 |
|
| 14685 |
button = &style->tab.tab_minimize_button; |
| 14686 |
nk_zero_struct(*button); |
| 14687 |
button->normal = nk_style_item_color(table[NK_COLOR_TAB_HEADER]); |
| 14688 |
button->hover = nk_style_item_color(table[NK_COLOR_TAB_HEADER]); |
| 14689 |
button->active = nk_style_item_color(table[NK_COLOR_TAB_HEADER]); |
| 14690 |
button->border_color = nk_rgba(0,0,0,0); |
| 14691 |
button->text_background = table[NK_COLOR_TAB_HEADER]; |
| 14692 |
button->text_normal = table[NK_COLOR_TEXT]; |
| 14693 |
button->text_hover = table[NK_COLOR_TEXT]; |
| 14694 |
button->text_active = table[NK_COLOR_TEXT]; |
| 14695 |
button->padding = nk_vec2(2.0f,2.0f); |
| 14696 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14697 |
button->userdata = nk_handle_ptr(0); |
| 14698 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14699 |
button->border = 0.0f; |
| 14700 |
button->rounding = 0.0f; |
| 14701 |
button->draw_begin = 0; |
| 14702 |
button->draw_end = 0; |
| 14703 |
style->tab.tab_maximize_button =*button; |
| 14704 |
|
| 14705 |
|
| 14706 |
button = &style->tab.node_minimize_button; |
| 14707 |
nk_zero_struct(*button); |
| 14708 |
button->normal = nk_style_item_color(table[NK_COLOR_WINDOW]); |
| 14709 |
button->hover = nk_style_item_color(table[NK_COLOR_WINDOW]); |
| 14710 |
button->active = nk_style_item_color(table[NK_COLOR_WINDOW]); |
| 14711 |
button->border_color = nk_rgba(0,0,0,0); |
| 14712 |
button->text_background = table[NK_COLOR_TAB_HEADER]; |
| 14713 |
button->text_normal = table[NK_COLOR_TEXT]; |
| 14714 |
button->text_hover = table[NK_COLOR_TEXT]; |
| 14715 |
button->text_active = table[NK_COLOR_TEXT]; |
| 14716 |
button->padding = nk_vec2(2.0f,2.0f); |
| 14717 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14718 |
button->userdata = nk_handle_ptr(0); |
| 14719 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14720 |
button->border = 0.0f; |
| 14721 |
button->rounding = 0.0f; |
| 14722 |
button->draw_begin = 0; |
| 14723 |
button->draw_end = 0; |
| 14724 |
style->tab.node_maximize_button =*button; |
| 14725 |
|
| 14726 |
|
| 14727 |
win = &style->window; |
| 14728 |
win->header.align = NK_HEADER_RIGHT; |
| 14729 |
win->header.close_symbol = NK_SYMBOL_X; |
| 14730 |
win->header.minimize_symbol = NK_SYMBOL_MINUS; |
| 14731 |
win->header.maximize_symbol = NK_SYMBOL_PLUS; |
| 14732 |
win->header.normal = nk_style_item_color(table[NK_COLOR_HEADER]); |
| 14733 |
win->header.hover = nk_style_item_color(table[NK_COLOR_HEADER]); |
| 14734 |
win->header.active = nk_style_item_color(table[NK_COLOR_HEADER]); |
| 14735 |
win->header.label_normal = table[NK_COLOR_TEXT]; |
| 14736 |
win->header.label_hover = table[NK_COLOR_TEXT]; |
| 14737 |
win->header.label_active = table[NK_COLOR_TEXT]; |
| 14738 |
win->header.label_padding = nk_vec2(4,4); |
| 14739 |
win->header.padding = nk_vec2(4,4); |
| 14740 |
win->header.spacing = nk_vec2(0,0); |
| 14741 |
|
| 14742 |
|
| 14743 |
button = &style->window.header.close_button; |
| 14744 |
nk_zero_struct(*button); |
| 14745 |
button->normal = nk_style_item_color(table[NK_COLOR_HEADER]); |
| 14746 |
button->hover = nk_style_item_color(table[NK_COLOR_HEADER]); |
| 14747 |
button->active = nk_style_item_color(table[NK_COLOR_HEADER]); |
| 14748 |
button->border_color = nk_rgba(0,0,0,0); |
| 14749 |
button->text_background = table[NK_COLOR_HEADER]; |
| 14750 |
button->text_normal = table[NK_COLOR_TEXT]; |
| 14751 |
button->text_hover = table[NK_COLOR_TEXT]; |
| 14752 |
button->text_active = table[NK_COLOR_TEXT]; |
| 14753 |
button->padding = nk_vec2(0.0f,0.0f); |
| 14754 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14755 |
button->userdata = nk_handle_ptr(0); |
| 14756 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14757 |
button->border = 0.0f; |
| 14758 |
button->rounding = 0.0f; |
| 14759 |
button->draw_begin = 0; |
| 14760 |
button->draw_end = 0; |
| 14761 |
|
| 14762 |
|
| 14763 |
button = &style->window.header.minimize_button; |
| 14764 |
nk_zero_struct(*button); |
| 14765 |
button->normal = nk_style_item_color(table[NK_COLOR_HEADER]); |
| 14766 |
button->hover = nk_style_item_color(table[NK_COLOR_HEADER]); |
| 14767 |
button->active = nk_style_item_color(table[NK_COLOR_HEADER]); |
| 14768 |
button->border_color = nk_rgba(0,0,0,0); |
| 14769 |
button->text_background = table[NK_COLOR_HEADER]; |
| 14770 |
button->text_normal = table[NK_COLOR_TEXT]; |
| 14771 |
button->text_hover = table[NK_COLOR_TEXT]; |
| 14772 |
button->text_active = table[NK_COLOR_TEXT]; |
| 14773 |
button->padding = nk_vec2(0.0f,0.0f); |
| 14774 |
button->touch_padding = nk_vec2(0.0f,0.0f); |
| 14775 |
button->userdata = nk_handle_ptr(0); |
| 14776 |
button->text_alignment = NK_TEXT_CENTERED; |
| 14777 |
button->border = 0.0f; |
| 14778 |
button->rounding = 0.0f; |
| 14779 |
button->draw_begin = 0; |
| 14780 |
button->draw_end = 0; |
| 14781 |
|
| 14782 |
|
| 14783 |
win->background = table[NK_COLOR_WINDOW]; |
| 14784 |
win->fixed_background = nk_style_item_color(table[NK_COLOR_WINDOW]); |
| 14785 |
win->border_color = table[NK_COLOR_BORDER]; |
| 14786 |
win->popup_border_color = table[NK_COLOR_BORDER]; |
| 14787 |
win->combo_border_color = table[NK_COLOR_BORDER]; |
| 14788 |
win->contextual_border_color = table[NK_COLOR_BORDER]; |
| 14789 |
win->menu_border_color = table[NK_COLOR_BORDER]; |
| 14790 |
win->group_border_color = table[NK_COLOR_BORDER]; |
| 14791 |
win->tooltip_border_color = table[NK_COLOR_BORDER]; |
| 14792 |
win->scaler = nk_style_item_color(table[NK_COLOR_TEXT]); |
| 14793 |
|
| 14794 |
win->rounding = 0.0f; |
| 14795 |
win->spacing = nk_vec2(4,4); |
| 14796 |
win->scrollbar_size = nk_vec2(10,10); |
| 14797 |
win->min_size = nk_vec2(64,64); |
| 14798 |
|
| 14799 |
win->combo_border = 1.0f; |
| 14800 |
win->contextual_border = 1.0f; |
| 14801 |
win->menu_border = 1.0f; |
| 14802 |
win->group_border = 1.0f; |
| 14803 |
win->tooltip_border = 1.0f; |
| 14804 |
win->popup_border = 1.0f; |
| 14805 |
win->border = 2.0f; |
| 14806 |
win->min_row_height_padding = 8; |
| 14807 |
|
| 14808 |
win->padding = nk_vec2(4,4); |
| 14809 |
win->group_padding = nk_vec2(4,4); |
| 14810 |
win->popup_padding = nk_vec2(4,4); |
| 14811 |
win->combo_padding = nk_vec2(4,4); |
| 14812 |
win->contextual_padding = nk_vec2(4,4); |
| 14813 |
win->menu_padding = nk_vec2(4,4); |
| 14814 |
win->tooltip_padding = nk_vec2(4,4); |
| 14815 |
} |
| 14816 |
NK_API void |
| 14817 |
nk_style_set_font(struct nk_context *ctx, const struct nk_user_font *font) |
| 14818 |
{ |
| 14819 |
struct nk_style *style; |
| 14820 |
NK_ASSERT(ctx); |
| 14821 |
|
| 14822 |
if (!ctx) return; |
| 14823 |
style = &ctx->style; |
| 14824 |
style->font = font; |
| 14825 |
ctx->stacks.fonts.head = 0; |
| 14826 |
if (ctx->current) |
| 14827 |
nk_layout_reset_min_row_height(ctx); |
| 14828 |
} |
| 14829 |
NK_API int |
| 14830 |
nk_style_push_font(struct nk_context *ctx, const struct nk_user_font *font) |
| 14831 |
{ |
| 14832 |
struct nk_config_stack_user_font *font_stack; |
| 14833 |
struct nk_config_stack_user_font_element *element; |
| 14834 |
|
| 14835 |
NK_ASSERT(ctx); |
| 14836 |
if (!ctx) return 0; |
| 14837 |
|
| 14838 |
font_stack = &ctx->stacks.fonts; |
| 14839 |
NK_ASSERT(font_stack->head < (int)NK_LEN(font_stack->elements)); |
| 14840 |
if (font_stack->head >= (int)NK_LEN(font_stack->elements)) |
| 14841 |
return 0; |
| 14842 |
|
| 14843 |
element = &font_stack->elements[font_stack->head++]; |
| 14844 |
element->address = &ctx->style.font; |
| 14845 |
element->old_value = ctx->style.font; |
| 14846 |
ctx->style.font = font; |
| 14847 |
return 1; |
| 14848 |
} |
| 14849 |
NK_API int |
| 14850 |
nk_style_pop_font(struct nk_context *ctx) |
| 14851 |
{ |
| 14852 |
struct nk_config_stack_user_font *font_stack; |
| 14853 |
struct nk_config_stack_user_font_element *element; |
| 14854 |
|
| 14855 |
NK_ASSERT(ctx); |
| 14856 |
if (!ctx) return 0; |
| 14857 |
|
| 14858 |
font_stack = &ctx->stacks.fonts; |
| 14859 |
NK_ASSERT(font_stack->head > 0); |
| 14860 |
if (font_stack->head < 1) |
| 14861 |
return 0; |
| 14862 |
|
| 14863 |
element = &font_stack->elements[--font_stack->head]; |
| 14864 |
*element->address = element->old_value; |
| 14865 |
return 1; |
| 14866 |
} |
| 14867 |
#define NK_STYLE_PUSH_IMPLEMENATION(prefix, type, stack) \ |
| 14868 |
nk_style_push_##type(struct nk_context *ctx, prefix##_##type *address, prefix##_##type value)\ |
| 14869 |
{\ |
| 14870 |
struct nk_config_stack_##type * type_stack;\ |
| 14871 |
struct nk_config_stack_##type##_element *element;\ |
| 14872 |
NK_ASSERT(ctx);\ |
| 14873 |
if (!ctx) return 0;\ |
| 14874 |
type_stack = &ctx->stacks.stack;\ |
| 14875 |
NK_ASSERT(type_stack->head < (int)NK_LEN(type_stack->elements));\ |
| 14876 |
if (type_stack->head >= (int)NK_LEN(type_stack->elements))\ |
| 14877 |
return 0;\ |
| 14878 |
element = &type_stack->elements[type_stack->head++];\ |
| 14879 |
element->address = address;\ |
| 14880 |
element->old_value = *address;\ |
| 14881 |
*address = value;\ |
| 14882 |
return 1;\ |
| 14883 |
} |
| 14884 |
#define NK_STYLE_POP_IMPLEMENATION(type, stack) \ |
| 14885 |
nk_style_pop_##type(struct nk_context *ctx)\ |
| 14886 |
{\ |
| 14887 |
struct nk_config_stack_##type *type_stack;\ |
| 14888 |
struct nk_config_stack_##type##_element *element;\ |
| 14889 |
NK_ASSERT(ctx);\ |
| 14890 |
if (!ctx) return 0;\ |
| 14891 |
type_stack = &ctx->stacks.stack;\ |
| 14892 |
NK_ASSERT(type_stack->head > 0);\ |
| 14893 |
if (type_stack->head < 1)\ |
| 14894 |
return 0;\ |
| 14895 |
element = &type_stack->elements[--type_stack->head];\ |
| 14896 |
*element->address = element->old_value;\ |
| 14897 |
return 1;\ |
| 14898 |
} |
| 14899 |
NK_API int NK_STYLE_PUSH_IMPLEMENATION(struct nk, style_item, style_items) |
| 14900 |
NK_API int NK_STYLE_PUSH_IMPLEMENATION(nk,float, floats) |
| 14901 |
NK_API int NK_STYLE_PUSH_IMPLEMENATION(struct nk, vec2, vectors) |
| 14902 |
NK_API int NK_STYLE_PUSH_IMPLEMENATION(nk,flags, flags) |
| 14903 |
NK_API int NK_STYLE_PUSH_IMPLEMENATION(struct nk,color, colors) |
| 14904 |
|
| 14905 |
NK_API int NK_STYLE_POP_IMPLEMENATION(style_item, style_items) |
| 14906 |
NK_API int NK_STYLE_POP_IMPLEMENATION(float,floats) |
| 14907 |
NK_API int NK_STYLE_POP_IMPLEMENATION(vec2, vectors) |
| 14908 |
NK_API int NK_STYLE_POP_IMPLEMENATION(flags,flags) |
| 14909 |
NK_API int NK_STYLE_POP_IMPLEMENATION(color,colors) |
| 14910 |
|
| 14911 |
NK_API int |
| 14912 |
nk_style_set_cursor(struct nk_context *ctx, enum nk_style_cursor c) |
| 14913 |
{ |
| 14914 |
struct nk_style *style; |
| 14915 |
NK_ASSERT(ctx); |
| 14916 |
if (!ctx) return 0; |
| 14917 |
style = &ctx->style; |
| 14918 |
if (style->cursors[c]) { |
| 14919 |
style->cursor_active = style->cursors[c]; |
| 14920 |
return 1; |
| 14921 |
} |
| 14922 |
return 0; |
| 14923 |
} |
| 14924 |
NK_API void |
| 14925 |
nk_style_show_cursor(struct nk_context *ctx) |
| 14926 |
{ |
| 14927 |
ctx->style.cursor_visible = nk_true; |
| 14928 |
} |
| 14929 |
NK_API void |
| 14930 |
nk_style_hide_cursor(struct nk_context *ctx) |
| 14931 |
{ |
| 14932 |
ctx->style.cursor_visible = nk_false; |
| 14933 |
} |
| 14934 |
NK_API void |
| 14935 |
nk_style_load_cursor(struct nk_context *ctx, enum nk_style_cursor cursor, |
| 14936 |
const struct nk_cursor *c) |
| 14937 |
{ |
| 14938 |
struct nk_style *style; |
| 14939 |
NK_ASSERT(ctx); |
| 14940 |
if (!ctx) return; |
| 14941 |
style = &ctx->style; |
| 14942 |
style->cursors[cursor] = c; |
| 14943 |
} |
| 14944 |
NK_API void |
| 14945 |
nk_style_load_all_cursors(struct nk_context *ctx, struct nk_cursor *cursors) |
| 14946 |
{ |
| 14947 |
int i = 0; |
| 14948 |
struct nk_style *style; |
| 14949 |
NK_ASSERT(ctx); |
| 14950 |
if (!ctx) return; |
| 14951 |
style = &ctx->style; |
| 14952 |
for (i = 0; i < NK_CURSOR_COUNT; ++i) |
| 14953 |
style->cursors[i] = &cursors[i]; |
| 14954 |
style->cursor_visible = nk_true; |
| 14955 |
} |
| 14956 |
|
| 14957 |
|
| 14958 |
|
| 14959 |
|
| 14960 |
|
| 14961 |
|
| 14962 |
|
| 14963 |
|
| 14964 |
|
| 14965 |
|
| 14966 |
NK_INTERN void |
| 14967 |
nk_setup(struct nk_context *ctx, const struct nk_user_font *font) |
| 14968 |
{ |
| 14969 |
NK_ASSERT(ctx); |
| 14970 |
if (!ctx) return; |
| 14971 |
nk_zero_struct(*ctx); |
| 14972 |
nk_style_default(ctx); |
| 14973 |
ctx->seq = 1; |
| 14974 |
if (font) ctx->style.font = font; |
| 14975 |
#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT |
| 14976 |
nk_draw_list_init(&ctx->draw_list); |
| 14977 |
#endif |
| 14978 |
} |
| 14979 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 14980 |
NK_API int |
| 14981 |
nk_init_default(struct nk_context *ctx, const struct nk_user_font *font) |
| 14982 |
{ |
| 14983 |
struct nk_allocator alloc; |
| 14984 |
alloc.userdata.ptr = 0; |
| 14985 |
alloc.alloc = nk_malloc; |
| 14986 |
alloc.free = nk_mfree; |
| 14987 |
return nk_init(ctx, &alloc, font); |
| 14988 |
} |
| 14989 |
#endif |
| 14990 |
NK_API int |
| 14991 |
nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, |
| 14992 |
const struct nk_user_font *font) |
| 14993 |
{ |
| 14994 |
NK_ASSERT(memory); |
| 14995 |
if (!memory) return 0; |
| 14996 |
nk_setup(ctx, font); |
| 14997 |
nk_buffer_init_fixed(&ctx->memory, memory, size); |
| 14998 |
ctx->use_pool = nk_false; |
| 14999 |
return 1; |
| 15000 |
} |
| 15001 |
NK_API int |
| 15002 |
nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, |
| 15003 |
struct nk_buffer *pool, const struct nk_user_font *font) |
| 15004 |
{ |
| 15005 |
NK_ASSERT(cmds); |
| 15006 |
NK_ASSERT(pool); |
| 15007 |
if (!cmds || !pool) return 0; |
| 15008 |
|
| 15009 |
nk_setup(ctx, font); |
| 15010 |
ctx->memory = *cmds; |
| 15011 |
if (pool->type == NK_BUFFER_FIXED) { |
| 15012 |
|
| 15013 |
nk_pool_init_fixed(&ctx->pool, pool->memory.ptr, pool->memory.size); |
| 15014 |
} else { |
| 15015 |
|
| 15016 |
struct nk_allocator *alloc = &pool->pool; |
| 15017 |
nk_pool_init(&ctx->pool, alloc, NK_POOL_DEFAULT_CAPACITY); |
| 15018 |
} |
| 15019 |
ctx->use_pool = nk_true; |
| 15020 |
return 1; |
| 15021 |
} |
| 15022 |
NK_API int |
| 15023 |
nk_init(struct nk_context *ctx, struct nk_allocator *alloc, |
| 15024 |
const struct nk_user_font *font) |
| 15025 |
{ |
| 15026 |
NK_ASSERT(alloc); |
| 15027 |
if (!alloc) return 0; |
| 15028 |
nk_setup(ctx, font); |
| 15029 |
nk_buffer_init(&ctx->memory, alloc, NK_DEFAULT_COMMAND_BUFFER_SIZE); |
| 15030 |
nk_pool_init(&ctx->pool, alloc, NK_POOL_DEFAULT_CAPACITY); |
| 15031 |
ctx->use_pool = nk_true; |
| 15032 |
return 1; |
| 15033 |
} |
| 15034 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 15035 |
NK_API void |
| 15036 |
nk_set_user_data(struct nk_context *ctx, nk_handle handle) |
| 15037 |
{ |
| 15038 |
if (!ctx) return; |
| 15039 |
ctx->userdata = handle; |
| 15040 |
if (ctx->current) |
| 15041 |
ctx->current->buffer.userdata = handle; |
| 15042 |
} |
| 15043 |
#endif |
| 15044 |
NK_API void |
| 15045 |
nk_free(struct nk_context *ctx) |
| 15046 |
{ |
| 15047 |
NK_ASSERT(ctx); |
| 15048 |
if (!ctx) return; |
| 15049 |
nk_buffer_free(&ctx->memory); |
| 15050 |
if (ctx->use_pool) |
| 15051 |
nk_pool_free(&ctx->pool); |
| 15052 |
|
| 15053 |
nk_zero(&ctx->input, sizeof(ctx->input)); |
| 15054 |
nk_zero(&ctx->style, sizeof(ctx->style)); |
| 15055 |
nk_zero(&ctx->memory, sizeof(ctx->memory)); |
| 15056 |
|
| 15057 |
ctx->seq = 0; |
| 15058 |
ctx->build = 0; |
| 15059 |
ctx->begin = 0; |
| 15060 |
ctx->end = 0; |
| 15061 |
ctx->active = 0; |
| 15062 |
ctx->current = 0; |
| 15063 |
ctx->freelist = 0; |
| 15064 |
ctx->count = 0; |
| 15065 |
} |
| 15066 |
NK_API void |
| 15067 |
nk_clear(struct nk_context *ctx) |
| 15068 |
{ |
| 15069 |
struct nk_window *iter; |
| 15070 |
struct nk_window *next; |
| 15071 |
NK_ASSERT(ctx); |
| 15072 |
|
| 15073 |
if (!ctx) return; |
| 15074 |
if (ctx->use_pool) |
| 15075 |
nk_buffer_clear(&ctx->memory); |
| 15076 |
else nk_buffer_reset(&ctx->memory, NK_BUFFER_FRONT); |
| 15077 |
|
| 15078 |
ctx->build = 0; |
| 15079 |
ctx->memory.calls = 0; |
| 15080 |
ctx->last_widget_state = 0; |
| 15081 |
ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_ARROW]; |
| 15082 |
NK_MEMSET(&ctx->overlay, 0, sizeof(ctx->overlay)); |
| 15083 |
|
| 15084 |
|
| 15085 |
iter = ctx->begin; |
| 15086 |
while (iter) { |
| 15087 |
|
| 15088 |
if ((iter->flags & NK_WINDOW_MINIMIZED) && |
| 15089 |
!(iter->flags & NK_WINDOW_CLOSED) && |
| 15090 |
iter->seq == ctx->seq) { |
| 15091 |
iter = iter->next; |
| 15092 |
continue; |
| 15093 |
} |
| 15094 |
|
| 15095 |
if (((iter->flags & NK_WINDOW_HIDDEN) || |
| 15096 |
(iter->flags & NK_WINDOW_CLOSED)) && |
| 15097 |
iter == ctx->active) { |
| 15098 |
ctx->active = iter->prev; |
| 15099 |
ctx->end = iter->prev; |
| 15100 |
if (!ctx->end) |
| 15101 |
ctx->begin = 0; |
| 15102 |
if (ctx->active) |
| 15103 |
ctx->active->flags &= ~(unsigned)NK_WINDOW_ROM; |
| 15104 |
} |
| 15105 |
|
| 15106 |
if (iter->popup.win && iter->popup.win->seq != ctx->seq) { |
| 15107 |
nk_free_window(ctx, iter->popup.win); |
| 15108 |
iter->popup.win = 0; |
| 15109 |
} |
| 15110 |
|
| 15111 |
{struct nk_table *n, *it = iter->tables; |
| 15112 |
while (it) { |
| 15113 |
n = it->next; |
| 15114 |
if (it->seq != ctx->seq) { |
| 15115 |
nk_remove_table(iter, it); |
| 15116 |
nk_zero(it, sizeof(union nk_page_data)); |
| 15117 |
nk_free_table(ctx, it); |
| 15118 |
if (it == iter->tables) |
| 15119 |
iter->tables = n; |
| 15120 |
} it = n; |
| 15121 |
}} |
| 15122 |
|
| 15123 |
if (iter->seq != ctx->seq || iter->flags & NK_WINDOW_CLOSED) { |
| 15124 |
next = iter->next; |
| 15125 |
nk_remove_window(ctx, iter); |
| 15126 |
nk_free_window(ctx, iter); |
| 15127 |
iter = next; |
| 15128 |
} else iter = iter->next; |
| 15129 |
} |
| 15130 |
ctx->seq++; |
| 15131 |
} |
| 15132 |
NK_LIB void |
| 15133 |
nk_start_buffer(struct nk_context *ctx, struct nk_command_buffer *buffer) |
| 15134 |
{ |
| 15135 |
NK_ASSERT(ctx); |
| 15136 |
NK_ASSERT(buffer); |
| 15137 |
if (!ctx || !buffer) return; |
| 15138 |
buffer->begin = ctx->memory.allocated; |
| 15139 |
buffer->end = buffer->begin; |
| 15140 |
buffer->last = buffer->begin; |
| 15141 |
buffer->clip = nk_null_rect; |
| 15142 |
} |
| 15143 |
NK_LIB void |
| 15144 |
nk_start(struct nk_context *ctx, struct nk_window *win) |
| 15145 |
{ |
| 15146 |
NK_ASSERT(ctx); |
| 15147 |
NK_ASSERT(win); |
| 15148 |
nk_start_buffer(ctx, &win->buffer); |
| 15149 |
} |
| 15150 |
NK_LIB void |
| 15151 |
nk_start_popup(struct nk_context *ctx, struct nk_window *win) |
| 15152 |
{ |
| 15153 |
struct nk_popup_buffer *buf; |
| 15154 |
NK_ASSERT(ctx); |
| 15155 |
NK_ASSERT(win); |
| 15156 |
if (!ctx || !win) return; |
| 15157 |
|
| 15158 |
|
| 15159 |
buf = &win->popup.buf; |
| 15160 |
buf->begin = win->buffer.end; |
| 15161 |
buf->end = win->buffer.end; |
| 15162 |
buf->parent = win->buffer.last; |
| 15163 |
buf->last = buf->begin; |
| 15164 |
buf->active = nk_true; |
| 15165 |
} |
| 15166 |
NK_LIB void |
| 15167 |
nk_finish_popup(struct nk_context *ctx, struct nk_window *win) |
| 15168 |
{ |
| 15169 |
struct nk_popup_buffer *buf; |
| 15170 |
NK_ASSERT(ctx); |
| 15171 |
NK_ASSERT(win); |
| 15172 |
if (!ctx || !win) return; |
| 15173 |
|
| 15174 |
buf = &win->popup.buf; |
| 15175 |
buf->last = win->buffer.last; |
| 15176 |
buf->end = win->buffer.end; |
| 15177 |
} |
| 15178 |
NK_LIB void |
| 15179 |
nk_finish_buffer(struct nk_context *ctx, struct nk_command_buffer *buffer) |
| 15180 |
{ |
| 15181 |
NK_ASSERT(ctx); |
| 15182 |
NK_ASSERT(buffer); |
| 15183 |
if (!ctx || !buffer) return; |
| 15184 |
buffer->end = ctx->memory.allocated; |
| 15185 |
} |
| 15186 |
NK_LIB void |
| 15187 |
nk_finish(struct nk_context *ctx, struct nk_window *win) |
| 15188 |
{ |
| 15189 |
struct nk_popup_buffer *buf; |
| 15190 |
struct nk_command *parent_last; |
| 15191 |
void *memory; |
| 15192 |
|
| 15193 |
NK_ASSERT(ctx); |
| 15194 |
NK_ASSERT(win); |
| 15195 |
if (!ctx || !win) return; |
| 15196 |
nk_finish_buffer(ctx, &win->buffer); |
| 15197 |
if (!win->popup.buf.active) return; |
| 15198 |
|
| 15199 |
buf = &win->popup.buf; |
| 15200 |
memory = ctx->memory.memory.ptr; |
| 15201 |
parent_last = nk_ptr_add(struct nk_command, memory, buf->parent); |
| 15202 |
parent_last->next = buf->end; |
| 15203 |
} |
| 15204 |
NK_LIB void |
| 15205 |
nk_build(struct nk_context *ctx) |
| 15206 |
{ |
| 15207 |
struct nk_window *it = 0; |
| 15208 |
struct nk_command *cmd = 0; |
| 15209 |
nk_byte *buffer = 0; |
| 15210 |
|
| 15211 |
|
| 15212 |
if (!ctx->style.cursor_active) |
| 15213 |
ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_ARROW]; |
| 15214 |
if (ctx->style.cursor_active && !ctx->input.mouse.grabbed && ctx->style.cursor_visible) { |
| 15215 |
struct nk_rect mouse_bounds; |
| 15216 |
const struct nk_cursor *cursor = ctx->style.cursor_active; |
| 15217 |
nk_command_buffer_init(&ctx->overlay, &ctx->memory, NK_CLIPPING_OFF); |
| 15218 |
nk_start_buffer(ctx, &ctx->overlay); |
| 15219 |
|
| 15220 |
mouse_bounds.x = ctx->input.mouse.pos.x - cursor->offset.x; |
| 15221 |
mouse_bounds.y = ctx->input.mouse.pos.y - cursor->offset.y; |
| 15222 |
mouse_bounds.w = cursor->size.x; |
| 15223 |
mouse_bounds.h = cursor->size.y; |
| 15224 |
|
| 15225 |
nk_draw_image(&ctx->overlay, mouse_bounds, &cursor->img, nk_white); |
| 15226 |
nk_finish_buffer(ctx, &ctx->overlay); |
| 15227 |
} |
| 15228 |
|
| 15229 |
it = ctx->begin; |
| 15230 |
buffer = (nk_byte*)ctx->memory.memory.ptr; |
| 15231 |
while (it != 0) { |
| 15232 |
struct nk_window *next = it->next; |
| 15233 |
if (it->buffer.last == it->buffer.begin || (it->flags & NK_WINDOW_HIDDEN)|| |
| 15234 |
it->seq != ctx->seq) |
| 15235 |
goto cont; |
| 15236 |
|
| 15237 |
cmd = nk_ptr_add(struct nk_command, buffer, it->buffer.last); |
| 15238 |
while (next && ((next->buffer.last == next->buffer.begin) || |
| 15239 |
(next->flags & NK_WINDOW_HIDDEN) || next->seq != ctx->seq)) |
| 15240 |
next = next->next; |
| 15241 |
|
| 15242 |
if (next) cmd->next = next->buffer.begin; |
| 15243 |
cont: it = next; |
| 15244 |
} |
| 15245 |
|
| 15246 |
it = ctx->begin; |
| 15247 |
while (it != 0) { |
| 15248 |
struct nk_window *next = it->next; |
| 15249 |
struct nk_popup_buffer *buf; |
| 15250 |
if (!it->popup.buf.active) |
| 15251 |
goto skip; |
| 15252 |
|
| 15253 |
buf = &it->popup.buf; |
| 15254 |
cmd->next = buf->begin; |
| 15255 |
cmd = nk_ptr_add(struct nk_command, buffer, buf->last); |
| 15256 |
buf->active = nk_false; |
| 15257 |
skip: it = next; |
| 15258 |
} |
| 15259 |
if (cmd) { |
| 15260 |
|
| 15261 |
if (ctx->overlay.end != ctx->overlay.begin) |
| 15262 |
cmd->next = ctx->overlay.begin; |
| 15263 |
else cmd->next = ctx->memory.allocated; |
| 15264 |
} |
| 15265 |
} |
| 15266 |
NK_API const struct nk_command* |
| 15267 |
nk__begin(struct nk_context *ctx) |
| 15268 |
{ |
| 15269 |
struct nk_window *iter; |
| 15270 |
nk_byte *buffer; |
| 15271 |
NK_ASSERT(ctx); |
| 15272 |
if (!ctx) return 0; |
| 15273 |
if (!ctx->count) return 0; |
| 15274 |
|
| 15275 |
buffer = (nk_byte*)ctx->memory.memory.ptr; |
| 15276 |
if (!ctx->build) { |
| 15277 |
nk_build(ctx); |
| 15278 |
ctx->build = nk_true; |
| 15279 |
} |
| 15280 |
iter = ctx->begin; |
| 15281 |
while (iter && ((iter->buffer.begin == iter->buffer.end) || |
| 15282 |
(iter->flags & NK_WINDOW_HIDDEN) || iter->seq != ctx->seq)) |
| 15283 |
iter = iter->next; |
| 15284 |
if (!iter) return 0; |
| 15285 |
return nk_ptr_add_const(struct nk_command, buffer, iter->buffer.begin); |
| 15286 |
} |
| 15287 |
|
| 15288 |
NK_API const struct nk_command* |
| 15289 |
nk__next(struct nk_context *ctx, const struct nk_command *cmd) |
| 15290 |
{ |
| 15291 |
nk_byte *buffer; |
| 15292 |
const struct nk_command *next; |
| 15293 |
NK_ASSERT(ctx); |
| 15294 |
if (!ctx || !cmd || !ctx->count) return 0; |
| 15295 |
if (cmd->next >= ctx->memory.allocated) return 0; |
| 15296 |
buffer = (nk_byte*)ctx->memory.memory.ptr; |
| 15297 |
next = nk_ptr_add_const(struct nk_command, buffer, cmd->next); |
| 15298 |
return next; |
| 15299 |
} |
| 15300 |
|
| 15301 |
|
| 15302 |
|
| 15303 |
|
| 15304 |
|
| 15305 |
|
| 15306 |
|
| 15307 |
|
| 15308 |
|
| 15309 |
|
| 15310 |
|
| 15311 |
NK_LIB void |
| 15312 |
nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, |
| 15313 |
unsigned int capacity) |
| 15314 |
{ |
| 15315 |
nk_zero(pool, sizeof(*pool)); |
| 15316 |
pool->alloc = *alloc; |
| 15317 |
pool->capacity = capacity; |
| 15318 |
pool->type = NK_BUFFER_DYNAMIC; |
| 15319 |
pool->pages = 0; |
| 15320 |
} |
| 15321 |
NK_LIB void |
| 15322 |
nk_pool_free(struct nk_pool *pool) |
| 15323 |
{ |
| 15324 |
struct nk_page *iter = pool->pages; |
| 15325 |
if (!pool) return; |
| 15326 |
if (pool->type == NK_BUFFER_FIXED) return; |
| 15327 |
while (iter) { |
| 15328 |
struct nk_page *next = iter->next; |
| 15329 |
pool->alloc.free(pool->alloc.userdata, iter); |
| 15330 |
iter = next; |
| 15331 |
} |
| 15332 |
} |
| 15333 |
NK_LIB void |
| 15334 |
nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size) |
| 15335 |
{ |
| 15336 |
nk_zero(pool, sizeof(*pool)); |
| 15337 |
NK_ASSERT(size >= sizeof(struct nk_page)); |
| 15338 |
if (size < sizeof(struct nk_page)) return; |
| 15339 |
pool->capacity = (unsigned)(size - sizeof(struct nk_page)) / sizeof(struct nk_page_element); |
| 15340 |
pool->pages = (struct nk_page*)memory; |
| 15341 |
pool->type = NK_BUFFER_FIXED; |
| 15342 |
pool->size = size; |
| 15343 |
} |
| 15344 |
NK_LIB struct nk_page_element* |
| 15345 |
nk_pool_alloc(struct nk_pool *pool) |
| 15346 |
{ |
| 15347 |
if (!pool->pages || pool->pages->size >= pool->capacity) { |
| 15348 |
|
| 15349 |
struct nk_page *page; |
| 15350 |
if (pool->type == NK_BUFFER_FIXED) { |
| 15351 |
NK_ASSERT(pool->pages); |
| 15352 |
if (!pool->pages) return 0; |
| 15353 |
NK_ASSERT(pool->pages->size < pool->capacity); |
| 15354 |
return 0; |
| 15355 |
} else { |
| 15356 |
nk_size size = sizeof(struct nk_page); |
| 15357 |
size += NK_POOL_DEFAULT_CAPACITY * sizeof(union nk_page_data); |
| 15358 |
page = (struct nk_page*)pool->alloc.alloc(pool->alloc.userdata,0, size); |
| 15359 |
page->next = pool->pages; |
| 15360 |
pool->pages = page; |
| 15361 |
page->size = 0; |
| 15362 |
} |
| 15363 |
} return &pool->pages->win[pool->pages->size++]; |
| 15364 |
} |
| 15365 |
|
| 15366 |
|
| 15367 |
|
| 15368 |
|
| 15369 |
|
| 15370 |
|
| 15371 |
|
| 15372 |
|
| 15373 |
|
| 15374 |
|
| 15375 |
NK_LIB struct nk_page_element* |
| 15376 |
nk_create_page_element(struct nk_context *ctx) |
| 15377 |
{ |
| 15378 |
struct nk_page_element *elem; |
| 15379 |
if (ctx->freelist) { |
| 15380 |
|
| 15381 |
elem = ctx->freelist; |
| 15382 |
ctx->freelist = elem->next; |
| 15383 |
} else if (ctx->use_pool) { |
| 15384 |
|
| 15385 |
elem = nk_pool_alloc(&ctx->pool); |
| 15386 |
NK_ASSERT(elem); |
| 15387 |
if (!elem) return 0; |
| 15388 |
} else { |
| 15389 |
|
| 15390 |
NK_STORAGE const nk_size size = sizeof(struct nk_page_element); |
| 15391 |
NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_page_element); |
| 15392 |
elem = (struct nk_page_element*)nk_buffer_alloc(&ctx->memory, NK_BUFFER_BACK, size, align); |
| 15393 |
NK_ASSERT(elem); |
| 15394 |
if (!elem) return 0; |
| 15395 |
} |
| 15396 |
nk_zero_struct(*elem); |
| 15397 |
elem->next = 0; |
| 15398 |
elem->prev = 0; |
| 15399 |
return elem; |
| 15400 |
} |
| 15401 |
NK_LIB void |
| 15402 |
nk_link_page_element_into_freelist(struct nk_context *ctx, |
| 15403 |
struct nk_page_element *elem) |
| 15404 |
{ |
| 15405 |
|
| 15406 |
if (!ctx->freelist) { |
| 15407 |
ctx->freelist = elem; |
| 15408 |
} else { |
| 15409 |
elem->next = ctx->freelist; |
| 15410 |
ctx->freelist = elem; |
| 15411 |
} |
| 15412 |
} |
| 15413 |
NK_LIB void |
| 15414 |
nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem) |
| 15415 |
{ |
| 15416 |
|
| 15417 |
if (ctx->use_pool) { |
| 15418 |
nk_link_page_element_into_freelist(ctx, elem); |
| 15419 |
return; |
| 15420 |
} |
| 15421 |
|
| 15422 |
{void *elem_end = (void*)(elem + 1); |
| 15423 |
void *buffer_end = (nk_byte*)ctx->memory.memory.ptr + ctx->memory.size; |
| 15424 |
if (elem_end == buffer_end) |
| 15425 |
ctx->memory.size -= sizeof(struct nk_page_element); |
| 15426 |
else nk_link_page_element_into_freelist(ctx, elem);} |
| 15427 |
} |
| 15428 |
|
| 15429 |
|
| 15430 |
|
| 15431 |
|
| 15432 |
|
| 15433 |
|
| 15434 |
|
| 15435 |
|
| 15436 |
|
| 15437 |
|
| 15438 |
NK_LIB struct nk_table* |
| 15439 |
nk_create_table(struct nk_context *ctx) |
| 15440 |
{ |
| 15441 |
struct nk_page_element *elem; |
| 15442 |
elem = nk_create_page_element(ctx); |
| 15443 |
if (!elem) return 0; |
| 15444 |
nk_zero_struct(*elem); |
| 15445 |
return &elem->data.tbl; |
| 15446 |
} |
| 15447 |
NK_LIB void |
| 15448 |
nk_free_table(struct nk_context *ctx, struct nk_table *tbl) |
| 15449 |
{ |
| 15450 |
union nk_page_data *pd = NK_CONTAINER_OF(tbl, union nk_page_data, tbl); |
| 15451 |
struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data); |
| 15452 |
nk_free_page_element(ctx, pe); |
| 15453 |
} |
| 15454 |
NK_LIB void |
| 15455 |
nk_push_table(struct nk_window *win, struct nk_table *tbl) |
| 15456 |
{ |
| 15457 |
if (!win->tables) { |
| 15458 |
win->tables = tbl; |
| 15459 |
tbl->next = 0; |
| 15460 |
tbl->prev = 0; |
| 15461 |
tbl->size = 0; |
| 15462 |
win->table_count = 1; |
| 15463 |
return; |
| 15464 |
} |
| 15465 |
win->tables->prev = tbl; |
| 15466 |
tbl->next = win->tables; |
| 15467 |
tbl->prev = 0; |
| 15468 |
tbl->size = 0; |
| 15469 |
win->tables = tbl; |
| 15470 |
win->table_count++; |
| 15471 |
} |
| 15472 |
NK_LIB void |
| 15473 |
nk_remove_table(struct nk_window *win, struct nk_table *tbl) |
| 15474 |
{ |
| 15475 |
if (win->tables == tbl) |
| 15476 |
win->tables = tbl->next; |
| 15477 |
if (tbl->next) |
| 15478 |
tbl->next->prev = tbl->prev; |
| 15479 |
if (tbl->prev) |
| 15480 |
tbl->prev->next = tbl->next; |
| 15481 |
tbl->next = 0; |
| 15482 |
tbl->prev = 0; |
| 15483 |
} |
| 15484 |
NK_LIB nk_uint* |
| 15485 |
nk_add_value(struct nk_context *ctx, struct nk_window *win, |
| 15486 |
nk_hash name, nk_uint value) |
| 15487 |
{ |
| 15488 |
NK_ASSERT(ctx); |
| 15489 |
NK_ASSERT(win); |
| 15490 |
if (!win || !ctx) return 0; |
| 15491 |
if (!win->tables || win->tables->size >= NK_VALUE_PAGE_CAPACITY) { |
| 15492 |
struct nk_table *tbl = nk_create_table(ctx); |
| 15493 |
NK_ASSERT(tbl); |
| 15494 |
if (!tbl) return 0; |
| 15495 |
nk_push_table(win, tbl); |
| 15496 |
} |
| 15497 |
win->tables->seq = win->seq; |
| 15498 |
win->tables->keys[win->tables->size] = name; |
| 15499 |
win->tables->values[win->tables->size] = value; |
| 15500 |
return &win->tables->values[win->tables->size++]; |
| 15501 |
} |
| 15502 |
NK_LIB nk_uint* |
| 15503 |
nk_find_value(struct nk_window *win, nk_hash name) |
| 15504 |
{ |
| 15505 |
struct nk_table *iter = win->tables; |
| 15506 |
while (iter) { |
| 15507 |
unsigned int i = 0; |
| 15508 |
unsigned int size = iter->size; |
| 15509 |
for (i = 0; i < size; ++i) { |
| 15510 |
if (iter->keys[i] == name) { |
| 15511 |
iter->seq = win->seq; |
| 15512 |
return &iter->values[i]; |
| 15513 |
} |
| 15514 |
} size = NK_VALUE_PAGE_CAPACITY; |
| 15515 |
iter = iter->next; |
| 15516 |
} |
| 15517 |
return 0; |
| 15518 |
} |
| 15519 |
|
| 15520 |
|
| 15521 |
|
| 15522 |
|
| 15523 |
|
| 15524 |
|
| 15525 |
|
| 15526 |
|
| 15527 |
|
| 15528 |
|
| 15529 |
NK_LIB void* |
| 15530 |
nk_create_panel(struct nk_context *ctx) |
| 15531 |
{ |
| 15532 |
struct nk_page_element *elem; |
| 15533 |
elem = nk_create_page_element(ctx); |
| 15534 |
if (!elem) return 0; |
| 15535 |
nk_zero_struct(*elem); |
| 15536 |
return &elem->data.pan; |
| 15537 |
} |
| 15538 |
NK_LIB void |
| 15539 |
nk_free_panel(struct nk_context *ctx, struct nk_panel *pan) |
| 15540 |
{ |
| 15541 |
union nk_page_data *pd = NK_CONTAINER_OF(pan, union nk_page_data, pan); |
| 15542 |
struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data); |
| 15543 |
nk_free_page_element(ctx, pe); |
| 15544 |
} |
| 15545 |
NK_LIB int |
| 15546 |
nk_panel_has_header(nk_flags flags, const char *title) |
| 15547 |
{ |
| 15548 |
int active = 0; |
| 15549 |
active = (flags & (NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE)); |
| 15550 |
active = active || (flags & NK_WINDOW_TITLE); |
| 15551 |
active = active && !(flags & NK_WINDOW_HIDDEN) && title; |
| 15552 |
return active; |
| 15553 |
} |
| 15554 |
NK_LIB struct nk_vec2 |
| 15555 |
nk_panel_get_padding(const struct nk_style *style, enum nk_panel_type type) |
| 15556 |
{ |
| 15557 |
switch (type) { |
| 15558 |
default: |
| 15559 |
case NK_PANEL_WINDOW: return style->window.padding; |
| 15560 |
case NK_PANEL_GROUP: return style->window.group_padding; |
| 15561 |
case NK_PANEL_POPUP: return style->window.popup_padding; |
| 15562 |
case NK_PANEL_CONTEXTUAL: return style->window.contextual_padding; |
| 15563 |
case NK_PANEL_COMBO: return style->window.combo_padding; |
| 15564 |
case NK_PANEL_MENU: return style->window.menu_padding; |
| 15565 |
case NK_PANEL_TOOLTIP: return style->window.menu_padding;} |
| 15566 |
} |
| 15567 |
NK_LIB float |
| 15568 |
nk_panel_get_border(const struct nk_style *style, nk_flags flags, |
| 15569 |
enum nk_panel_type type) |
| 15570 |
{ |
| 15571 |
if (flags & NK_WINDOW_BORDER) { |
| 15572 |
switch (type) { |
| 15573 |
default: |
| 15574 |
case NK_PANEL_WINDOW: return style->window.border; |
| 15575 |
case NK_PANEL_GROUP: return style->window.group_border; |
| 15576 |
case NK_PANEL_POPUP: return style->window.popup_border; |
| 15577 |
case NK_PANEL_CONTEXTUAL: return style->window.contextual_border; |
| 15578 |
case NK_PANEL_COMBO: return style->window.combo_border; |
| 15579 |
case NK_PANEL_MENU: return style->window.menu_border; |
| 15580 |
case NK_PANEL_TOOLTIP: return style->window.menu_border; |
| 15581 |
}} else return 0; |
| 15582 |
} |
| 15583 |
NK_LIB struct nk_color |
| 15584 |
nk_panel_get_border_color(const struct nk_style *style, enum nk_panel_type type) |
| 15585 |
{ |
| 15586 |
switch (type) { |
| 15587 |
default: |
| 15588 |
case NK_PANEL_WINDOW: return style->window.border_color; |
| 15589 |
case NK_PANEL_GROUP: return style->window.group_border_color; |
| 15590 |
case NK_PANEL_POPUP: return style->window.popup_border_color; |
| 15591 |
case NK_PANEL_CONTEXTUAL: return style->window.contextual_border_color; |
| 15592 |
case NK_PANEL_COMBO: return style->window.combo_border_color; |
| 15593 |
case NK_PANEL_MENU: return style->window.menu_border_color; |
| 15594 |
case NK_PANEL_TOOLTIP: return style->window.menu_border_color;} |
| 15595 |
} |
| 15596 |
NK_LIB int |
| 15597 |
nk_panel_is_sub(enum nk_panel_type type) |
| 15598 |
{ |
| 15599 |
return (type & NK_PANEL_SET_SUB)?1:0; |
| 15600 |
} |
| 15601 |
NK_LIB int |
| 15602 |
nk_panel_is_nonblock(enum nk_panel_type type) |
| 15603 |
{ |
| 15604 |
return (type & NK_PANEL_SET_NONBLOCK)?1:0; |
| 15605 |
} |
| 15606 |
NK_LIB int |
| 15607 |
nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type panel_type) |
| 15608 |
{ |
| 15609 |
struct nk_input *in; |
| 15610 |
struct nk_window *win; |
| 15611 |
struct nk_panel *layout; |
| 15612 |
struct nk_command_buffer *out; |
| 15613 |
const struct nk_style *style; |
| 15614 |
const struct nk_user_font *font; |
| 15615 |
|
| 15616 |
struct nk_vec2 scrollbar_size; |
| 15617 |
struct nk_vec2 panel_padding; |
| 15618 |
|
| 15619 |
NK_ASSERT(ctx); |
| 15620 |
NK_ASSERT(ctx->current); |
| 15621 |
NK_ASSERT(ctx->current->layout); |
| 15622 |
if (!ctx || !ctx->current || !ctx->current->layout) return 0; |
| 15623 |
nk_zero(ctx->current->layout, sizeof(*ctx->current->layout)); |
| 15624 |
if ((ctx->current->flags & NK_WINDOW_HIDDEN) || (ctx->current->flags & NK_WINDOW_CLOSED)) { |
| 15625 |
nk_zero(ctx->current->layout, sizeof(struct nk_panel)); |
| 15626 |
ctx->current->layout->type = panel_type; |
| 15627 |
return 0; |
| 15628 |
} |
| 15629 |
|
| 15630 |
style = &ctx->style; |
| 15631 |
font = style->font; |
| 15632 |
win = ctx->current; |
| 15633 |
layout = win->layout; |
| 15634 |
out = &win->buffer; |
| 15635 |
in = (win->flags & NK_WINDOW_NO_INPUT) ? 0: &ctx->input; |
| 15636 |
#ifdef NK_INCLUDE_COMMAND_USERDATA |
| 15637 |
win->buffer.userdata = ctx->userdata; |
| 15638 |
#endif |
| 15639 |
|
| 15640 |
scrollbar_size = style->window.scrollbar_size; |
| 15641 |
panel_padding = nk_panel_get_padding(style, panel_type); |
| 15642 |
|
| 15643 |
|
| 15644 |
if ((win->flags & NK_WINDOW_MOVABLE) && !(win->flags & NK_WINDOW_ROM)) { |
| 15645 |
int left_mouse_down; |
| 15646 |
int left_mouse_clicked; |
| 15647 |
int left_mouse_click_in_cursor; |
| 15648 |
|
| 15649 |
|
| 15650 |
struct nk_rect header; |
| 15651 |
header.x = win->bounds.x; |
| 15652 |
header.y = win->bounds.y; |
| 15653 |
header.w = win->bounds.w; |
| 15654 |
if (nk_panel_has_header(win->flags, title)) { |
| 15655 |
header.h = font->height + 2.0f * style->window.header.padding.y; |
| 15656 |
header.h += 2.0f * style->window.header.label_padding.y; |
| 15657 |
} else header.h = panel_padding.y; |
| 15658 |
|
| 15659 |
|
| 15660 |
left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down; |
| 15661 |
left_mouse_clicked = (int)in->mouse.buttons[NK_BUTTON_LEFT].clicked; |
| 15662 |
left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(in, |
| 15663 |
NK_BUTTON_LEFT, header, nk_true); |
| 15664 |
if (left_mouse_down && left_mouse_click_in_cursor && !left_mouse_clicked) { |
| 15665 |
win->bounds.x = win->bounds.x + in->mouse.delta.x; |
| 15666 |
win->bounds.y = win->bounds.y + in->mouse.delta.y; |
| 15667 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x += in->mouse.delta.x; |
| 15668 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y += in->mouse.delta.y; |
| 15669 |
ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_MOVE]; |
| 15670 |
} |
| 15671 |
} |
| 15672 |
|
| 15673 |
|
| 15674 |
layout->type = panel_type; |
| 15675 |
layout->flags = win->flags; |
| 15676 |
layout->bounds = win->bounds; |
| 15677 |
layout->bounds.x += panel_padding.x; |
| 15678 |
layout->bounds.w -= 2*panel_padding.x; |
| 15679 |
if (win->flags & NK_WINDOW_BORDER) { |
| 15680 |
layout->border = nk_panel_get_border(style, win->flags, panel_type); |
| 15681 |
layout->bounds = nk_shrink_rect(layout->bounds, layout->border); |
| 15682 |
} else layout->border = 0; |
| 15683 |
layout->at_y = layout->bounds.y; |
| 15684 |
layout->at_x = layout->bounds.x; |
| 15685 |
layout->max_x = 0; |
| 15686 |
layout->header_height = 0; |
| 15687 |
layout->footer_height = 0; |
| 15688 |
nk_layout_reset_min_row_height(ctx); |
| 15689 |
layout->row.index = 0; |
| 15690 |
layout->row.columns = 0; |
| 15691 |
layout->row.ratio = 0; |
| 15692 |
layout->row.item_width = 0; |
| 15693 |
layout->row.tree_depth = 0; |
| 15694 |
layout->row.height = panel_padding.y; |
| 15695 |
layout->has_scrolling = nk_true; |
| 15696 |
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR)) |
| 15697 |
layout->bounds.w -= scrollbar_size.x; |
| 15698 |
if (!nk_panel_is_nonblock(panel_type)) { |
| 15699 |
layout->footer_height = 0; |
| 15700 |
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR) || win->flags & NK_WINDOW_SCALABLE) |
| 15701 |
layout->footer_height = scrollbar_size.y; |
| 15702 |
layout->bounds.h -= layout->footer_height; |
| 15703 |
} |
| 15704 |
|
| 15705 |
|
| 15706 |
if (nk_panel_has_header(win->flags, title)) |
| 15707 |
{ |
| 15708 |
struct nk_text text; |
| 15709 |
struct nk_rect header; |
| 15710 |
const struct nk_style_item *background = 0; |
| 15711 |
|
| 15712 |
|
| 15713 |
header.x = win->bounds.x; |
| 15714 |
header.y = win->bounds.y; |
| 15715 |
header.w = win->bounds.w; |
| 15716 |
header.h = font->height + 2.0f * style->window.header.padding.y; |
| 15717 |
header.h += (2.0f * style->window.header.label_padding.y); |
| 15718 |
|
| 15719 |
|
| 15720 |
layout->header_height = header.h; |
| 15721 |
layout->bounds.y += header.h; |
| 15722 |
layout->bounds.h -= header.h; |
| 15723 |
layout->at_y += header.h; |
| 15724 |
|
| 15725 |
|
| 15726 |
if (ctx->active == win) { |
| 15727 |
background = &style->window.header.active; |
| 15728 |
text.text = style->window.header.label_active; |
| 15729 |
} else if (nk_input_is_mouse_hovering_rect(&ctx->input, header)) { |
| 15730 |
background = &style->window.header.hover; |
| 15731 |
text.text = style->window.header.label_hover; |
| 15732 |
} else { |
| 15733 |
background = &style->window.header.normal; |
| 15734 |
text.text = style->window.header.label_normal; |
| 15735 |
} |
| 15736 |
|
| 15737 |
|
| 15738 |
header.h += 1.0f; |
| 15739 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 15740 |
text.background = nk_rgba(0,0,0,0); |
| 15741 |
nk_draw_image(&win->buffer, header, &background->data.image, nk_white); |
| 15742 |
} else { |
| 15743 |
text.background = background->data.color; |
| 15744 |
nk_fill_rect(out, header, 0, background->data.color); |
| 15745 |
} |
| 15746 |
|
| 15747 |
|
| 15748 |
{struct nk_rect button; |
| 15749 |
button.y = header.y + style->window.header.padding.y; |
| 15750 |
button.h = header.h - 2 * style->window.header.padding.y; |
| 15751 |
button.w = button.h; |
| 15752 |
if (win->flags & NK_WINDOW_CLOSABLE) { |
| 15753 |
nk_flags ws = 0; |
| 15754 |
if (style->window.header.align == NK_HEADER_RIGHT) { |
| 15755 |
button.x = (header.w + header.x) - (button.w + style->window.header.padding.x); |
| 15756 |
header.w -= button.w + style->window.header.spacing.x + style->window.header.padding.x; |
| 15757 |
} else { |
| 15758 |
button.x = header.x + style->window.header.padding.x; |
| 15759 |
header.x += button.w + style->window.header.spacing.x + style->window.header.padding.x; |
| 15760 |
} |
| 15761 |
|
| 15762 |
if (nk_do_button_symbol(&ws, &win->buffer, button, |
| 15763 |
style->window.header.close_symbol, NK_BUTTON_DEFAULT, |
| 15764 |
&style->window.header.close_button, in, style->font) && !(win->flags & NK_WINDOW_ROM)) |
| 15765 |
{ |
| 15766 |
layout->flags |= NK_WINDOW_HIDDEN; |
| 15767 |
layout->flags &= (nk_flags)~NK_WINDOW_MINIMIZED; |
| 15768 |
} |
| 15769 |
} |
| 15770 |
|
| 15771 |
|
| 15772 |
if (win->flags & NK_WINDOW_MINIMIZABLE) { |
| 15773 |
nk_flags ws = 0; |
| 15774 |
if (style->window.header.align == NK_HEADER_RIGHT) { |
| 15775 |
button.x = (header.w + header.x) - button.w; |
| 15776 |
if (!(win->flags & NK_WINDOW_CLOSABLE)) { |
| 15777 |
button.x -= style->window.header.padding.x; |
| 15778 |
header.w -= style->window.header.padding.x; |
| 15779 |
} |
| 15780 |
header.w -= button.w + style->window.header.spacing.x; |
| 15781 |
} else { |
| 15782 |
button.x = header.x; |
| 15783 |
header.x += button.w + style->window.header.spacing.x + style->window.header.padding.x; |
| 15784 |
} |
| 15785 |
if (nk_do_button_symbol(&ws, &win->buffer, button, (layout->flags & NK_WINDOW_MINIMIZED)? |
| 15786 |
style->window.header.maximize_symbol: style->window.header.minimize_symbol, |
| 15787 |
NK_BUTTON_DEFAULT, &style->window.header.minimize_button, in, style->font) && !(win->flags & NK_WINDOW_ROM)) |
| 15788 |
layout->flags = (layout->flags & NK_WINDOW_MINIMIZED) ? |
| 15789 |
layout->flags & (nk_flags)~NK_WINDOW_MINIMIZED: |
| 15790 |
layout->flags | NK_WINDOW_MINIMIZED; |
| 15791 |
}} |
| 15792 |
|
| 15793 |
{ |
| 15794 |
int text_len = nk_strlen(title); |
| 15795 |
struct nk_rect label = {0,0,0,0}; |
| 15796 |
float t = font->width(font->userdata, font->height, title, text_len); |
| 15797 |
text.padding = nk_vec2(0,0); |
| 15798 |
|
| 15799 |
label.x = header.x + style->window.header.padding.x; |
| 15800 |
label.x += style->window.header.label_padding.x; |
| 15801 |
label.y = header.y + style->window.header.label_padding.y; |
| 15802 |
label.h = font->height + 2 * style->window.header.label_padding.y; |
| 15803 |
label.w = t + 2 * style->window.header.spacing.x; |
| 15804 |
label.w = NK_CLAMP(0, label.w, header.x + header.w - label.x); |
| 15805 |
nk_widget_text(out, label,(const char*)title, text_len, &text, NK_TEXT_LEFT, font);} |
| 15806 |
} |
| 15807 |
|
| 15808 |
|
| 15809 |
if (!(layout->flags & NK_WINDOW_MINIMIZED) && !(layout->flags & NK_WINDOW_DYNAMIC)) { |
| 15810 |
struct nk_rect body; |
| 15811 |
body.x = win->bounds.x; |
| 15812 |
body.w = win->bounds.w; |
| 15813 |
body.y = (win->bounds.y + layout->header_height); |
| 15814 |
body.h = (win->bounds.h - layout->header_height); |
| 15815 |
if (style->window.fixed_background.type == NK_STYLE_ITEM_IMAGE) |
| 15816 |
nk_draw_image(out, body, &style->window.fixed_background.data.image, nk_white); |
| 15817 |
else nk_fill_rect(out, body, 0, style->window.fixed_background.data.color); |
| 15818 |
} |
| 15819 |
|
| 15820 |
|
| 15821 |
{struct nk_rect clip; |
| 15822 |
layout->clip = layout->bounds; |
| 15823 |
nk_unify(&clip, &win->buffer.clip, layout->clip.x, layout->clip.y, |
| 15824 |
layout->clip.x + layout->clip.w, layout->clip.y + layout->clip.h); |
| 15825 |
nk_push_scissor(out, clip); |
| 15826 |
layout->clip = clip;} |
| 15827 |
return !(layout->flags & NK_WINDOW_HIDDEN) && !(layout->flags & NK_WINDOW_MINIMIZED); |
| 15828 |
} |
| 15829 |
NK_LIB void |
| 15830 |
nk_panel_end(struct nk_context *ctx) |
| 15831 |
{ |
| 15832 |
struct nk_input *in; |
| 15833 |
struct nk_window *window; |
| 15834 |
struct nk_panel *layout; |
| 15835 |
const struct nk_style *style; |
| 15836 |
struct nk_command_buffer *out; |
| 15837 |
|
| 15838 |
struct nk_vec2 scrollbar_size; |
| 15839 |
struct nk_vec2 panel_padding; |
| 15840 |
|
| 15841 |
NK_ASSERT(ctx); |
| 15842 |
NK_ASSERT(ctx->current); |
| 15843 |
NK_ASSERT(ctx->current->layout); |
| 15844 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 15845 |
return; |
| 15846 |
|
| 15847 |
window = ctx->current; |
| 15848 |
layout = window->layout; |
| 15849 |
style = &ctx->style; |
| 15850 |
out = &window->buffer; |
| 15851 |
in = (layout->flags & NK_WINDOW_ROM || layout->flags & NK_WINDOW_NO_INPUT) ? 0 :&ctx->input; |
| 15852 |
if (!nk_panel_is_sub(layout->type)) |
| 15853 |
nk_push_scissor(out, nk_null_rect); |
| 15854 |
|
| 15855 |
|
| 15856 |
scrollbar_size = style->window.scrollbar_size; |
| 15857 |
panel_padding = nk_panel_get_padding(style, layout->type); |
| 15858 |
|
| 15859 |
|
| 15860 |
layout->at_y += layout->row.height; |
| 15861 |
|
| 15862 |
|
| 15863 |
if (layout->flags & NK_WINDOW_DYNAMIC && !(layout->flags & NK_WINDOW_MINIMIZED)) |
| 15864 |
{ |
| 15865 |
|
| 15866 |
struct nk_rect empty_space; |
| 15867 |
if (layout->at_y < (layout->bounds.y + layout->bounds.h)) |
| 15868 |
layout->bounds.h = layout->at_y - layout->bounds.y; |
| 15869 |
|
| 15870 |
|
| 15871 |
empty_space.x = window->bounds.x; |
| 15872 |
empty_space.y = layout->bounds.y; |
| 15873 |
empty_space.h = panel_padding.y; |
| 15874 |
empty_space.w = window->bounds.w; |
| 15875 |
nk_fill_rect(out, empty_space, 0, style->window.background); |
| 15876 |
|
| 15877 |
|
| 15878 |
empty_space.x = window->bounds.x; |
| 15879 |
empty_space.y = layout->bounds.y; |
| 15880 |
empty_space.w = panel_padding.x + layout->border; |
| 15881 |
empty_space.h = layout->bounds.h; |
| 15882 |
nk_fill_rect(out, empty_space, 0, style->window.background); |
| 15883 |
|
| 15884 |
|
| 15885 |
empty_space.x = layout->bounds.x + layout->bounds.w; |
| 15886 |
empty_space.y = layout->bounds.y; |
| 15887 |
empty_space.w = panel_padding.x + layout->border; |
| 15888 |
empty_space.h = layout->bounds.h; |
| 15889 |
if (*layout->offset_y == 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR)) |
| 15890 |
empty_space.w += scrollbar_size.x; |
| 15891 |
nk_fill_rect(out, empty_space, 0, style->window.background); |
| 15892 |
|
| 15893 |
|
| 15894 |
if (layout->footer_height > 0) { |
| 15895 |
empty_space.x = window->bounds.x; |
| 15896 |
empty_space.y = layout->bounds.y + layout->bounds.h; |
| 15897 |
empty_space.w = window->bounds.w; |
| 15898 |
empty_space.h = layout->footer_height; |
| 15899 |
nk_fill_rect(out, empty_space, 0, style->window.background); |
| 15900 |
} |
| 15901 |
} |
| 15902 |
|
| 15903 |
|
| 15904 |
if (!(layout->flags & NK_WINDOW_NO_SCROLLBAR) && |
| 15905 |
!(layout->flags & NK_WINDOW_MINIMIZED) && |
| 15906 |
window->scrollbar_hiding_timer < NK_SCROLLBAR_HIDING_TIMEOUT) |
| 15907 |
{ |
| 15908 |
struct nk_rect scroll; |
| 15909 |
int scroll_has_scrolling; |
| 15910 |
float scroll_target; |
| 15911 |
float scroll_offset; |
| 15912 |
float scroll_step; |
| 15913 |
float scroll_inc; |
| 15914 |
|
| 15915 |
|
| 15916 |
if (nk_panel_is_sub(layout->type)) |
| 15917 |
{ |
| 15918 |
|
| 15919 |
struct nk_window *root_window = window; |
| 15920 |
struct nk_panel *root_panel = window->layout; |
| 15921 |
while (root_panel->parent) |
| 15922 |
root_panel = root_panel->parent; |
| 15923 |
while (root_window->parent) |
| 15924 |
root_window = root_window->parent; |
| 15925 |
|
| 15926 |
|
| 15927 |
scroll_has_scrolling = 0; |
| 15928 |
if ((root_window == ctx->active) && layout->has_scrolling) { |
| 15929 |
|
| 15930 |
if (nk_input_is_mouse_hovering_rect(in, layout->bounds) && |
| 15931 |
NK_INTERSECT(layout->bounds.x, layout->bounds.y, layout->bounds.w, layout->bounds.h, |
| 15932 |
root_panel->clip.x, root_panel->clip.y, root_panel->clip.w, root_panel->clip.h)) |
| 15933 |
{ |
| 15934 |
|
| 15935 |
root_panel = window->layout; |
| 15936 |
while (root_panel->parent) { |
| 15937 |
root_panel->has_scrolling = nk_false; |
| 15938 |
root_panel = root_panel->parent; |
| 15939 |
} |
| 15940 |
root_panel->has_scrolling = nk_false; |
| 15941 |
scroll_has_scrolling = nk_true; |
| 15942 |
} |
| 15943 |
} |
| 15944 |
} else if (!nk_panel_is_sub(layout->type)) { |
| 15945 |
|
| 15946 |
scroll_has_scrolling = (window == ctx->active) && layout->has_scrolling; |
| 15947 |
if (in && (in->mouse.scroll_delta.y > 0 || in->mouse.scroll_delta.x > 0) && scroll_has_scrolling) |
| 15948 |
window->scrolled = nk_true; |
| 15949 |
else window->scrolled = nk_false; |
| 15950 |
} else scroll_has_scrolling = nk_false; |
| 15951 |
|
| 15952 |
{ |
| 15953 |
|
| 15954 |
nk_flags state = 0; |
| 15955 |
scroll.x = layout->bounds.x + layout->bounds.w + panel_padding.x; |
| 15956 |
scroll.y = layout->bounds.y; |
| 15957 |
scroll.w = scrollbar_size.x; |
| 15958 |
scroll.h = layout->bounds.h; |
| 15959 |
|
| 15960 |
scroll_offset = (float)*layout->offset_y; |
| 15961 |
scroll_step = scroll.h * 0.10f; |
| 15962 |
scroll_inc = scroll.h * 0.01f; |
| 15963 |
scroll_target = (float)(int)(layout->at_y - scroll.y); |
| 15964 |
scroll_offset = nk_do_scrollbarv(&state, out, scroll, scroll_has_scrolling, |
| 15965 |
scroll_offset, scroll_target, scroll_step, scroll_inc, |
| 15966 |
&ctx->style.scrollv, in, style->font); |
| 15967 |
*layout->offset_y = (nk_uint)scroll_offset; |
| 15968 |
if (in && scroll_has_scrolling) |
| 15969 |
in->mouse.scroll_delta.y = 0; |
| 15970 |
} |
| 15971 |
{ |
| 15972 |
|
| 15973 |
nk_flags state = 0; |
| 15974 |
scroll.x = layout->bounds.x; |
| 15975 |
scroll.y = layout->bounds.y + layout->bounds.h; |
| 15976 |
scroll.w = layout->bounds.w; |
| 15977 |
scroll.h = scrollbar_size.y; |
| 15978 |
|
| 15979 |
scroll_offset = (float)*layout->offset_x; |
| 15980 |
scroll_target = (float)(int)(layout->max_x - scroll.x); |
| 15981 |
scroll_step = layout->max_x * 0.05f; |
| 15982 |
scroll_inc = layout->max_x * 0.005f; |
| 15983 |
scroll_offset = nk_do_scrollbarh(&state, out, scroll, scroll_has_scrolling, |
| 15984 |
scroll_offset, scroll_target, scroll_step, scroll_inc, |
| 15985 |
&ctx->style.scrollh, in, style->font); |
| 15986 |
*layout->offset_x = (nk_uint)scroll_offset; |
| 15987 |
} |
| 15988 |
} |
| 15989 |
|
| 15990 |
|
| 15991 |
if (window->flags & NK_WINDOW_SCROLL_AUTO_HIDE) { |
| 15992 |
int has_input = ctx->input.mouse.delta.x != 0 || ctx->input.mouse.delta.y != 0 || ctx->input.mouse.scroll_delta.y != 0; |
| 15993 |
int is_window_hovered = nk_window_is_hovered(ctx); |
| 15994 |
int any_item_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED); |
| 15995 |
if ((!has_input && is_window_hovered) || (!is_window_hovered && !any_item_active)) |
| 15996 |
window->scrollbar_hiding_timer += ctx->delta_time_seconds; |
| 15997 |
else window->scrollbar_hiding_timer = 0; |
| 15998 |
} else window->scrollbar_hiding_timer = 0; |
| 15999 |
|
| 16000 |
|
| 16001 |
if (layout->flags & NK_WINDOW_BORDER) |
| 16002 |
{ |
| 16003 |
struct nk_color border_color = nk_panel_get_border_color(style, layout->type); |
| 16004 |
const float padding_y = (layout->flags & NK_WINDOW_MINIMIZED) |
| 16005 |
? (style->window.border + window->bounds.y + layout->header_height) |
| 16006 |
: ((layout->flags & NK_WINDOW_DYNAMIC) |
| 16007 |
? (layout->bounds.y + layout->bounds.h + layout->footer_height) |
| 16008 |
: (window->bounds.y + window->bounds.h)); |
| 16009 |
struct nk_rect b = window->bounds; |
| 16010 |
b.h = padding_y - window->bounds.y; |
| 16011 |
nk_stroke_rect(out, b, 0, layout->border, border_color); |
| 16012 |
} |
| 16013 |
|
| 16014 |
|
| 16015 |
if ((layout->flags & NK_WINDOW_SCALABLE) && in && !(layout->flags & NK_WINDOW_MINIMIZED)) |
| 16016 |
{ |
| 16017 |
|
| 16018 |
struct nk_rect scaler; |
| 16019 |
scaler.w = scrollbar_size.x; |
| 16020 |
scaler.h = scrollbar_size.y; |
| 16021 |
scaler.y = layout->bounds.y + layout->bounds.h; |
| 16022 |
if (layout->flags & NK_WINDOW_SCALE_LEFT) |
| 16023 |
scaler.x = layout->bounds.x - panel_padding.x * 0.5f; |
| 16024 |
else scaler.x = layout->bounds.x + layout->bounds.w + panel_padding.x; |
| 16025 |
if (layout->flags & NK_WINDOW_NO_SCROLLBAR) |
| 16026 |
scaler.x -= scaler.w; |
| 16027 |
|
| 16028 |
|
| 16029 |
{const struct nk_style_item *item = &style->window.scaler; |
| 16030 |
if (item->type == NK_STYLE_ITEM_IMAGE) |
| 16031 |
nk_draw_image(out, scaler, &item->data.image, nk_white); |
| 16032 |
else { |
| 16033 |
if (layout->flags & NK_WINDOW_SCALE_LEFT) { |
| 16034 |
nk_fill_triangle(out, scaler.x, scaler.y, scaler.x, |
| 16035 |
scaler.y + scaler.h, scaler.x + scaler.w, |
| 16036 |
scaler.y + scaler.h, item->data.color); |
| 16037 |
} else { |
| 16038 |
nk_fill_triangle(out, scaler.x + scaler.w, scaler.y, scaler.x + scaler.w, |
| 16039 |
scaler.y + scaler.h, scaler.x, scaler.y + scaler.h, item->data.color); |
| 16040 |
} |
| 16041 |
}} |
| 16042 |
|
| 16043 |
|
| 16044 |
if (!(window->flags & NK_WINDOW_ROM)) { |
| 16045 |
struct nk_vec2 window_size = style->window.min_size; |
| 16046 |
int left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down; |
| 16047 |
int left_mouse_click_in_scaler = nk_input_has_mouse_click_down_in_rect(in, |
| 16048 |
NK_BUTTON_LEFT, scaler, nk_true); |
| 16049 |
|
| 16050 |
if (left_mouse_down && left_mouse_click_in_scaler) { |
| 16051 |
float delta_x = in->mouse.delta.x; |
| 16052 |
if (layout->flags & NK_WINDOW_SCALE_LEFT) { |
| 16053 |
delta_x = -delta_x; |
| 16054 |
window->bounds.x += in->mouse.delta.x; |
| 16055 |
} |
| 16056 |
|
| 16057 |
if (window->bounds.w + delta_x >= window_size.x) { |
| 16058 |
if ((delta_x < 0) || (delta_x > 0 && in->mouse.pos.x >= scaler.x)) { |
| 16059 |
window->bounds.w = window->bounds.w + delta_x; |
| 16060 |
scaler.x += in->mouse.delta.x; |
| 16061 |
} |
| 16062 |
} |
| 16063 |
|
| 16064 |
if (!(layout->flags & NK_WINDOW_DYNAMIC)) { |
| 16065 |
if (window_size.y < window->bounds.h + in->mouse.delta.y) { |
| 16066 |
if ((in->mouse.delta.y < 0) || (in->mouse.delta.y > 0 && in->mouse.pos.y >= scaler.y)) { |
| 16067 |
window->bounds.h = window->bounds.h + in->mouse.delta.y; |
| 16068 |
scaler.y += in->mouse.delta.y; |
| 16069 |
} |
| 16070 |
} |
| 16071 |
} |
| 16072 |
ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT]; |
| 16073 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = scaler.x + scaler.w/2.0f; |
| 16074 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y = scaler.y + scaler.h/2.0f; |
| 16075 |
} |
| 16076 |
} |
| 16077 |
} |
| 16078 |
if (!nk_panel_is_sub(layout->type)) { |
| 16079 |
|
| 16080 |
if (layout->flags & NK_WINDOW_HIDDEN) |
| 16081 |
nk_command_buffer_reset(&window->buffer); |
| 16082 |
|
| 16083 |
else nk_finish(ctx, window); |
| 16084 |
} |
| 16085 |
|
| 16086 |
|
| 16087 |
if (layout->flags & NK_WINDOW_REMOVE_ROM) { |
| 16088 |
layout->flags &= ~(nk_flags)NK_WINDOW_ROM; |
| 16089 |
layout->flags &= ~(nk_flags)NK_WINDOW_REMOVE_ROM; |
| 16090 |
} |
| 16091 |
window->flags = layout->flags; |
| 16092 |
|
| 16093 |
|
| 16094 |
if (window->property.active && window->property.old != window->property.seq && |
| 16095 |
window->property.active == window->property.prev) { |
| 16096 |
nk_zero(&window->property, sizeof(window->property)); |
| 16097 |
} else { |
| 16098 |
window->property.old = window->property.seq; |
| 16099 |
window->property.prev = window->property.active; |
| 16100 |
window->property.seq = 0; |
| 16101 |
} |
| 16102 |
|
| 16103 |
if (window->edit.active && window->edit.old != window->edit.seq && |
| 16104 |
window->edit.active == window->edit.prev) { |
| 16105 |
nk_zero(&window->edit, sizeof(window->edit)); |
| 16106 |
} else { |
| 16107 |
window->edit.old = window->edit.seq; |
| 16108 |
window->edit.prev = window->edit.active; |
| 16109 |
window->edit.seq = 0; |
| 16110 |
} |
| 16111 |
|
| 16112 |
if (window->popup.active_con && window->popup.con_old != window->popup.con_count) { |
| 16113 |
window->popup.con_count = 0; |
| 16114 |
window->popup.con_old = 0; |
| 16115 |
window->popup.active_con = 0; |
| 16116 |
} else { |
| 16117 |
window->popup.con_old = window->popup.con_count; |
| 16118 |
window->popup.con_count = 0; |
| 16119 |
} |
| 16120 |
window->popup.combo_count = 0; |
| 16121 |
|
| 16122 |
NK_ASSERT(!layout->row.tree_depth); |
| 16123 |
} |
| 16124 |
|
| 16125 |
|
| 16126 |
|
| 16127 |
|
| 16128 |
|
| 16129 |
|
| 16130 |
|
| 16131 |
|
| 16132 |
|
| 16133 |
|
| 16134 |
NK_LIB void* |
| 16135 |
nk_create_window(struct nk_context *ctx) |
| 16136 |
{ |
| 16137 |
struct nk_page_element *elem; |
| 16138 |
elem = nk_create_page_element(ctx); |
| 16139 |
if (!elem) return 0; |
| 16140 |
elem->data.win.seq = ctx->seq; |
| 16141 |
return &elem->data.win; |
| 16142 |
} |
| 16143 |
NK_LIB void |
| 16144 |
nk_free_window(struct nk_context *ctx, struct nk_window *win) |
| 16145 |
{ |
| 16146 |
|
| 16147 |
struct nk_table *it = win->tables; |
| 16148 |
if (win->popup.win) { |
| 16149 |
nk_free_window(ctx, win->popup.win); |
| 16150 |
win->popup.win = 0; |
| 16151 |
} |
| 16152 |
win->next = 0; |
| 16153 |
win->prev = 0; |
| 16154 |
|
| 16155 |
while (it) { |
| 16156 |
|
| 16157 |
struct nk_table *n = it->next; |
| 16158 |
nk_remove_table(win, it); |
| 16159 |
nk_free_table(ctx, it); |
| 16160 |
if (it == win->tables) |
| 16161 |
win->tables = n; |
| 16162 |
it = n; |
| 16163 |
} |
| 16164 |
|
| 16165 |
|
| 16166 |
{union nk_page_data *pd = NK_CONTAINER_OF(win, union nk_page_data, win); |
| 16167 |
struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data); |
| 16168 |
nk_free_page_element(ctx, pe);} |
| 16169 |
} |
| 16170 |
NK_LIB struct nk_window* |
| 16171 |
nk_find_window(struct nk_context *ctx, nk_hash hash, const char *name) |
| 16172 |
{ |
| 16173 |
struct nk_window *iter; |
| 16174 |
iter = ctx->begin; |
| 16175 |
while (iter) { |
| 16176 |
NK_ASSERT(iter != iter->next); |
| 16177 |
if (iter->name == hash) { |
| 16178 |
int max_len = nk_strlen(iter->name_string); |
| 16179 |
if (!nk_stricmpn(iter->name_string, name, max_len)) |
| 16180 |
return iter; |
| 16181 |
} |
| 16182 |
iter = iter->next; |
| 16183 |
} |
| 16184 |
return 0; |
| 16185 |
} |
| 16186 |
NK_LIB void |
| 16187 |
nk_insert_window(struct nk_context *ctx, struct nk_window *win, |
| 16188 |
enum nk_window_insert_location loc) |
| 16189 |
{ |
| 16190 |
const struct nk_window *iter; |
| 16191 |
NK_ASSERT(ctx); |
| 16192 |
NK_ASSERT(win); |
| 16193 |
if (!win || !ctx) return; |
| 16194 |
|
| 16195 |
iter = ctx->begin; |
| 16196 |
while (iter) { |
| 16197 |
NK_ASSERT(iter != iter->next); |
| 16198 |
NK_ASSERT(iter != win); |
| 16199 |
if (iter == win) return; |
| 16200 |
iter = iter->next; |
| 16201 |
} |
| 16202 |
|
| 16203 |
if (!ctx->begin) { |
| 16204 |
win->next = 0; |
| 16205 |
win->prev = 0; |
| 16206 |
ctx->begin = win; |
| 16207 |
ctx->end = win; |
| 16208 |
ctx->count = 1; |
| 16209 |
return; |
| 16210 |
} |
| 16211 |
if (loc == NK_INSERT_BACK) { |
| 16212 |
struct nk_window *end; |
| 16213 |
end = ctx->end; |
| 16214 |
end->flags |= NK_WINDOW_ROM; |
| 16215 |
end->next = win; |
| 16216 |
win->prev = ctx->end; |
| 16217 |
win->next = 0; |
| 16218 |
ctx->end = win; |
| 16219 |
ctx->active = ctx->end; |
| 16220 |
ctx->end->flags &= ~(nk_flags)NK_WINDOW_ROM; |
| 16221 |
} else { |
| 16222 |
|
| 16223 |
ctx->begin->prev = win; |
| 16224 |
win->next = ctx->begin; |
| 16225 |
win->prev = 0; |
| 16226 |
ctx->begin = win; |
| 16227 |
ctx->begin->flags &= ~(nk_flags)NK_WINDOW_ROM; |
| 16228 |
} |
| 16229 |
ctx->count++; |
| 16230 |
} |
| 16231 |
NK_LIB void |
| 16232 |
nk_remove_window(struct nk_context *ctx, struct nk_window *win) |
| 16233 |
{ |
| 16234 |
if (win == ctx->begin || win == ctx->end) { |
| 16235 |
if (win == ctx->begin) { |
| 16236 |
ctx->begin = win->next; |
| 16237 |
if (win->next) |
| 16238 |
win->next->prev = 0; |
| 16239 |
} |
| 16240 |
if (win == ctx->end) { |
| 16241 |
ctx->end = win->prev; |
| 16242 |
if (win->prev) |
| 16243 |
win->prev->next = 0; |
| 16244 |
} |
| 16245 |
} else { |
| 16246 |
if (win->next) |
| 16247 |
win->next->prev = win->prev; |
| 16248 |
if (win->prev) |
| 16249 |
win->prev->next = win->next; |
| 16250 |
} |
| 16251 |
if (win == ctx->active || !ctx->active) { |
| 16252 |
ctx->active = ctx->end; |
| 16253 |
if (ctx->end) |
| 16254 |
ctx->end->flags &= ~(nk_flags)NK_WINDOW_ROM; |
| 16255 |
} |
| 16256 |
win->next = 0; |
| 16257 |
win->prev = 0; |
| 16258 |
ctx->count--; |
| 16259 |
} |
| 16260 |
NK_API int |
| 16261 |
nk_begin(struct nk_context *ctx, const char *title, |
| 16262 |
struct nk_rect bounds, nk_flags flags) |
| 16263 |
{ |
| 16264 |
return nk_begin_titled(ctx, title, title, bounds, flags); |
| 16265 |
} |
| 16266 |
NK_API int |
| 16267 |
nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, |
| 16268 |
struct nk_rect bounds, nk_flags flags) |
| 16269 |
{ |
| 16270 |
struct nk_window *win; |
| 16271 |
struct nk_style *style; |
| 16272 |
nk_hash name_hash; |
| 16273 |
int name_len; |
| 16274 |
int ret = 0; |
| 16275 |
|
| 16276 |
NK_ASSERT(ctx); |
| 16277 |
NK_ASSERT(name); |
| 16278 |
NK_ASSERT(title); |
| 16279 |
NK_ASSERT(ctx->style.font && ctx->style.font->width && "if this triggers you forgot to add a font"); |
| 16280 |
NK_ASSERT(!ctx->current && "if this triggers you missed a `nk_end` call"); |
| 16281 |
if (!ctx || ctx->current || !title || !name) |
| 16282 |
return 0; |
| 16283 |
|
| 16284 |
|
| 16285 |
style = &ctx->style; |
| 16286 |
name_len = (int)nk_strlen(name); |
| 16287 |
name_hash = nk_murmur_hash(name, (int)name_len, NK_WINDOW_TITLE); |
| 16288 |
win = nk_find_window(ctx, name_hash, name); |
| 16289 |
if (!win) { |
| 16290 |
|
| 16291 |
nk_size name_length = (nk_size)name_len; |
| 16292 |
win = (struct nk_window*)nk_create_window(ctx); |
| 16293 |
NK_ASSERT(win); |
| 16294 |
if (!win) return 0; |
| 16295 |
|
| 16296 |
if (flags & NK_WINDOW_BACKGROUND) |
| 16297 |
nk_insert_window(ctx, win, NK_INSERT_FRONT); |
| 16298 |
else nk_insert_window(ctx, win, NK_INSERT_BACK); |
| 16299 |
nk_command_buffer_init(&win->buffer, &ctx->memory, NK_CLIPPING_ON); |
| 16300 |
|
| 16301 |
win->flags = flags; |
| 16302 |
win->bounds = bounds; |
| 16303 |
win->name = name_hash; |
| 16304 |
name_length = NK_MIN(name_length, NK_WINDOW_MAX_NAME-1); |
| 16305 |
NK_MEMCPY(win->name_string, name, name_length); |
| 16306 |
win->name_string[name_length] = 0; |
| 16307 |
win->popup.win = 0; |
| 16308 |
if (!ctx->active) |
| 16309 |
ctx->active = win; |
| 16310 |
} else { |
| 16311 |
|
| 16312 |
win->flags &= ~(nk_flags)(NK_WINDOW_PRIVATE-1); |
| 16313 |
win->flags |= flags; |
| 16314 |
if (!(win->flags & (NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE))) |
| 16315 |
win->bounds = bounds; |
| 16316 |
|
| 16317 |
|
| 16318 |
|
| 16319 |
|
| 16320 |
|
| 16321 |
|
| 16322 |
|
| 16323 |
NK_ASSERT(win->seq != ctx->seq); |
| 16324 |
win->seq = ctx->seq; |
| 16325 |
if (!ctx->active && !(win->flags & NK_WINDOW_HIDDEN)) { |
| 16326 |
ctx->active = win; |
| 16327 |
ctx->end = win; |
| 16328 |
} |
| 16329 |
} |
| 16330 |
if (win->flags & NK_WINDOW_HIDDEN) { |
| 16331 |
ctx->current = win; |
| 16332 |
win->layout = 0; |
| 16333 |
return 0; |
| 16334 |
} else nk_start(ctx, win); |
| 16335 |
|
| 16336 |
|
| 16337 |
if (!(win->flags & NK_WINDOW_HIDDEN) && !(win->flags & NK_WINDOW_NO_INPUT)) |
| 16338 |
{ |
| 16339 |
int inpanel, ishovered; |
| 16340 |
struct nk_window *iter = win; |
| 16341 |
float h = ctx->style.font->height + 2.0f * style->window.header.padding.y + |
| 16342 |
(2.0f * style->window.header.label_padding.y); |
| 16343 |
struct nk_rect win_bounds = (!(win->flags & NK_WINDOW_MINIMIZED))? |
| 16344 |
win->bounds: nk_rect(win->bounds.x, win->bounds.y, win->bounds.w, h); |
| 16345 |
|
| 16346 |
|
| 16347 |
inpanel = nk_input_has_mouse_click_down_in_rect(&ctx->input, NK_BUTTON_LEFT, win_bounds, nk_true); |
| 16348 |
inpanel = inpanel && ctx->input.mouse.buttons[NK_BUTTON_LEFT].clicked; |
| 16349 |
ishovered = nk_input_is_mouse_hovering_rect(&ctx->input, win_bounds); |
| 16350 |
if ((win != ctx->active) && ishovered && !ctx->input.mouse.buttons[NK_BUTTON_LEFT].down) { |
| 16351 |
iter = win->next; |
| 16352 |
while (iter) { |
| 16353 |
struct nk_rect iter_bounds = (!(iter->flags & NK_WINDOW_MINIMIZED))? |
| 16354 |
iter->bounds: nk_rect(iter->bounds.x, iter->bounds.y, iter->bounds.w, h); |
| 16355 |
if (NK_INTERSECT(win_bounds.x, win_bounds.y, win_bounds.w, win_bounds.h, |
| 16356 |
iter_bounds.x, iter_bounds.y, iter_bounds.w, iter_bounds.h) && |
| 16357 |
(!(iter->flags & NK_WINDOW_HIDDEN))) |
| 16358 |
break; |
| 16359 |
|
| 16360 |
if (iter->popup.win && iter->popup.active && !(iter->flags & NK_WINDOW_HIDDEN) && |
| 16361 |
NK_INTERSECT(win->bounds.x, win_bounds.y, win_bounds.w, win_bounds.h, |
| 16362 |
iter->popup.win->bounds.x, iter->popup.win->bounds.y, |
| 16363 |
iter->popup.win->bounds.w, iter->popup.win->bounds.h)) |
| 16364 |
break; |
| 16365 |
iter = iter->next; |
| 16366 |
} |
| 16367 |
} |
| 16368 |
|
| 16369 |
|
| 16370 |
if (iter && inpanel && (win != ctx->end)) { |
| 16371 |
iter = win->next; |
| 16372 |
while (iter) { |
| 16373 |
|
| 16374 |
struct nk_rect iter_bounds = (!(iter->flags & NK_WINDOW_MINIMIZED))? |
| 16375 |
iter->bounds: nk_rect(iter->bounds.x, iter->bounds.y, iter->bounds.w, h); |
| 16376 |
if (NK_INBOX(ctx->input.mouse.pos.x, ctx->input.mouse.pos.y, |
| 16377 |
iter_bounds.x, iter_bounds.y, iter_bounds.w, iter_bounds.h) && |
| 16378 |
!(iter->flags & NK_WINDOW_HIDDEN)) |
| 16379 |
break; |
| 16380 |
if (iter->popup.win && iter->popup.active && !(iter->flags & NK_WINDOW_HIDDEN) && |
| 16381 |
NK_INTERSECT(win_bounds.x, win_bounds.y, win_bounds.w, win_bounds.h, |
| 16382 |
iter->popup.win->bounds.x, iter->popup.win->bounds.y, |
| 16383 |
iter->popup.win->bounds.w, iter->popup.win->bounds.h)) |
| 16384 |
break; |
| 16385 |
iter = iter->next; |
| 16386 |
} |
| 16387 |
} |
| 16388 |
if (iter && !(win->flags & NK_WINDOW_ROM) && (win->flags & NK_WINDOW_BACKGROUND)) { |
| 16389 |
win->flags |= (nk_flags)NK_WINDOW_ROM; |
| 16390 |
iter->flags &= ~(nk_flags)NK_WINDOW_ROM; |
| 16391 |
ctx->active = iter; |
| 16392 |
if (!(iter->flags & NK_WINDOW_BACKGROUND)) { |
| 16393 |
|
| 16394 |
|
| 16395 |
nk_remove_window(ctx, iter); |
| 16396 |
nk_insert_window(ctx, iter, NK_INSERT_BACK); |
| 16397 |
} |
| 16398 |
} else { |
| 16399 |
if (!iter && ctx->end != win) { |
| 16400 |
if (!(win->flags & NK_WINDOW_BACKGROUND)) { |
| 16401 |
|
| 16402 |
|
| 16403 |
nk_remove_window(ctx, win); |
| 16404 |
nk_insert_window(ctx, win, NK_INSERT_BACK); |
| 16405 |
} |
| 16406 |
win->flags &= ~(nk_flags)NK_WINDOW_ROM; |
| 16407 |
ctx->active = win; |
| 16408 |
} |
| 16409 |
if (ctx->end != win && !(win->flags & NK_WINDOW_BACKGROUND)) |
| 16410 |
win->flags |= NK_WINDOW_ROM; |
| 16411 |
} |
| 16412 |
} |
| 16413 |
win->layout = (struct nk_panel*)nk_create_panel(ctx); |
| 16414 |
ctx->current = win; |
| 16415 |
ret = nk_panel_begin(ctx, title, NK_PANEL_WINDOW); |
| 16416 |
win->layout->offset_x = &win->scrollbar.x; |
| 16417 |
win->layout->offset_y = &win->scrollbar.y; |
| 16418 |
return ret; |
| 16419 |
} |
| 16420 |
NK_API void |
| 16421 |
nk_end(struct nk_context *ctx) |
| 16422 |
{ |
| 16423 |
struct nk_panel *layout; |
| 16424 |
NK_ASSERT(ctx); |
| 16425 |
NK_ASSERT(ctx->current && "if this triggers you forgot to call `nk_begin`"); |
| 16426 |
if (!ctx || !ctx->current) |
| 16427 |
return; |
| 16428 |
|
| 16429 |
layout = ctx->current->layout; |
| 16430 |
if (!layout || (layout->type == NK_PANEL_WINDOW && (ctx->current->flags & NK_WINDOW_HIDDEN))) { |
| 16431 |
ctx->current = 0; |
| 16432 |
return; |
| 16433 |
} |
| 16434 |
nk_panel_end(ctx); |
| 16435 |
nk_free_panel(ctx, ctx->current->layout); |
| 16436 |
ctx->current = 0; |
| 16437 |
} |
| 16438 |
NK_API struct nk_rect |
| 16439 |
nk_window_get_bounds(const struct nk_context *ctx) |
| 16440 |
{ |
| 16441 |
NK_ASSERT(ctx); |
| 16442 |
NK_ASSERT(ctx->current); |
| 16443 |
if (!ctx || !ctx->current) return nk_rect(0,0,0,0); |
| 16444 |
return ctx->current->bounds; |
| 16445 |
} |
| 16446 |
NK_API struct nk_vec2 |
| 16447 |
nk_window_get_position(const struct nk_context *ctx) |
| 16448 |
{ |
| 16449 |
NK_ASSERT(ctx); |
| 16450 |
NK_ASSERT(ctx->current); |
| 16451 |
if (!ctx || !ctx->current) return nk_vec2(0,0); |
| 16452 |
return nk_vec2(ctx->current->bounds.x, ctx->current->bounds.y); |
| 16453 |
} |
| 16454 |
NK_API struct nk_vec2 |
| 16455 |
nk_window_get_size(const struct nk_context *ctx) |
| 16456 |
{ |
| 16457 |
NK_ASSERT(ctx); |
| 16458 |
NK_ASSERT(ctx->current); |
| 16459 |
if (!ctx || !ctx->current) return nk_vec2(0,0); |
| 16460 |
return nk_vec2(ctx->current->bounds.w, ctx->current->bounds.h); |
| 16461 |
} |
| 16462 |
NK_API float |
| 16463 |
nk_window_get_width(const struct nk_context *ctx) |
| 16464 |
{ |
| 16465 |
NK_ASSERT(ctx); |
| 16466 |
NK_ASSERT(ctx->current); |
| 16467 |
if (!ctx || !ctx->current) return 0; |
| 16468 |
return ctx->current->bounds.w; |
| 16469 |
} |
| 16470 |
NK_API float |
| 16471 |
nk_window_get_height(const struct nk_context *ctx) |
| 16472 |
{ |
| 16473 |
NK_ASSERT(ctx); |
| 16474 |
NK_ASSERT(ctx->current); |
| 16475 |
if (!ctx || !ctx->current) return 0; |
| 16476 |
return ctx->current->bounds.h; |
| 16477 |
} |
| 16478 |
NK_API struct nk_rect |
| 16479 |
nk_window_get_content_region(struct nk_context *ctx) |
| 16480 |
{ |
| 16481 |
NK_ASSERT(ctx); |
| 16482 |
NK_ASSERT(ctx->current); |
| 16483 |
if (!ctx || !ctx->current) return nk_rect(0,0,0,0); |
| 16484 |
return ctx->current->layout->clip; |
| 16485 |
} |
| 16486 |
NK_API struct nk_vec2 |
| 16487 |
nk_window_get_content_region_min(struct nk_context *ctx) |
| 16488 |
{ |
| 16489 |
NK_ASSERT(ctx); |
| 16490 |
NK_ASSERT(ctx->current); |
| 16491 |
NK_ASSERT(ctx->current->layout); |
| 16492 |
if (!ctx || !ctx->current) return nk_vec2(0,0); |
| 16493 |
return nk_vec2(ctx->current->layout->clip.x, ctx->current->layout->clip.y); |
| 16494 |
} |
| 16495 |
NK_API struct nk_vec2 |
| 16496 |
nk_window_get_content_region_max(struct nk_context *ctx) |
| 16497 |
{ |
| 16498 |
NK_ASSERT(ctx); |
| 16499 |
NK_ASSERT(ctx->current); |
| 16500 |
NK_ASSERT(ctx->current->layout); |
| 16501 |
if (!ctx || !ctx->current) return nk_vec2(0,0); |
| 16502 |
return nk_vec2(ctx->current->layout->clip.x + ctx->current->layout->clip.w, |
| 16503 |
ctx->current->layout->clip.y + ctx->current->layout->clip.h); |
| 16504 |
} |
| 16505 |
NK_API struct nk_vec2 |
| 16506 |
nk_window_get_content_region_size(struct nk_context *ctx) |
| 16507 |
{ |
| 16508 |
NK_ASSERT(ctx); |
| 16509 |
NK_ASSERT(ctx->current); |
| 16510 |
NK_ASSERT(ctx->current->layout); |
| 16511 |
if (!ctx || !ctx->current) return nk_vec2(0,0); |
| 16512 |
return nk_vec2(ctx->current->layout->clip.w, ctx->current->layout->clip.h); |
| 16513 |
} |
| 16514 |
NK_API struct nk_command_buffer* |
| 16515 |
nk_window_get_canvas(struct nk_context *ctx) |
| 16516 |
{ |
| 16517 |
NK_ASSERT(ctx); |
| 16518 |
NK_ASSERT(ctx->current); |
| 16519 |
NK_ASSERT(ctx->current->layout); |
| 16520 |
if (!ctx || !ctx->current) return 0; |
| 16521 |
return &ctx->current->buffer; |
| 16522 |
} |
| 16523 |
NK_API struct nk_panel* |
| 16524 |
nk_window_get_panel(struct nk_context *ctx) |
| 16525 |
{ |
| 16526 |
NK_ASSERT(ctx); |
| 16527 |
NK_ASSERT(ctx->current); |
| 16528 |
if (!ctx || !ctx->current) return 0; |
| 16529 |
return ctx->current->layout; |
| 16530 |
} |
| 16531 |
NK_API void |
| 16532 |
nk_window_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y) |
| 16533 |
{ |
| 16534 |
struct nk_window *win; |
| 16535 |
NK_ASSERT(ctx); |
| 16536 |
NK_ASSERT(ctx->current); |
| 16537 |
if (!ctx || !ctx->current) |
| 16538 |
return ; |
| 16539 |
win = ctx->current; |
| 16540 |
if (offset_x) |
| 16541 |
*offset_x = win->scrollbar.x; |
| 16542 |
if (offset_y) |
| 16543 |
*offset_y = win->scrollbar.y; |
| 16544 |
} |
| 16545 |
NK_API int |
| 16546 |
nk_window_has_focus(const struct nk_context *ctx) |
| 16547 |
{ |
| 16548 |
NK_ASSERT(ctx); |
| 16549 |
NK_ASSERT(ctx->current); |
| 16550 |
NK_ASSERT(ctx->current->layout); |
| 16551 |
if (!ctx || !ctx->current) return 0; |
| 16552 |
return ctx->current == ctx->active; |
| 16553 |
} |
| 16554 |
NK_API int |
| 16555 |
nk_window_is_hovered(struct nk_context *ctx) |
| 16556 |
{ |
| 16557 |
NK_ASSERT(ctx); |
| 16558 |
NK_ASSERT(ctx->current); |
| 16559 |
if (!ctx || !ctx->current) return 0; |
| 16560 |
if(ctx->current->flags & NK_WINDOW_HIDDEN) |
| 16561 |
return 0; |
| 16562 |
return nk_input_is_mouse_hovering_rect(&ctx->input, ctx->current->bounds); |
| 16563 |
} |
| 16564 |
NK_API int |
| 16565 |
nk_window_is_any_hovered(struct nk_context *ctx) |
| 16566 |
{ |
| 16567 |
struct nk_window *iter; |
| 16568 |
NK_ASSERT(ctx); |
| 16569 |
if (!ctx) return 0; |
| 16570 |
iter = ctx->begin; |
| 16571 |
while (iter) { |
| 16572 |
|
| 16573 |
if(!(iter->flags & NK_WINDOW_HIDDEN)) { |
| 16574 |
|
| 16575 |
if (iter->popup.active && iter->popup.win && nk_input_is_mouse_hovering_rect(&ctx->input, iter->popup.win->bounds)) |
| 16576 |
return 1; |
| 16577 |
|
| 16578 |
if (iter->flags & NK_WINDOW_MINIMIZED) { |
| 16579 |
struct nk_rect header = iter->bounds; |
| 16580 |
header.h = ctx->style.font->height + 2 * ctx->style.window.header.padding.y; |
| 16581 |
if (nk_input_is_mouse_hovering_rect(&ctx->input, header)) |
| 16582 |
return 1; |
| 16583 |
} else if (nk_input_is_mouse_hovering_rect(&ctx->input, iter->bounds)) { |
| 16584 |
return 1; |
| 16585 |
} |
| 16586 |
} |
| 16587 |
iter = iter->next; |
| 16588 |
} |
| 16589 |
return 0; |
| 16590 |
} |
| 16591 |
NK_API int |
| 16592 |
nk_item_is_any_active(struct nk_context *ctx) |
| 16593 |
{ |
| 16594 |
int any_hovered = nk_window_is_any_hovered(ctx); |
| 16595 |
int any_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED); |
| 16596 |
return any_hovered || any_active; |
| 16597 |
} |
| 16598 |
NK_API int |
| 16599 |
nk_window_is_collapsed(struct nk_context *ctx, const char *name) |
| 16600 |
{ |
| 16601 |
int title_len; |
| 16602 |
nk_hash title_hash; |
| 16603 |
struct nk_window *win; |
| 16604 |
NK_ASSERT(ctx); |
| 16605 |
if (!ctx) return 0; |
| 16606 |
|
| 16607 |
title_len = (int)nk_strlen(name); |
| 16608 |
title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); |
| 16609 |
win = nk_find_window(ctx, title_hash, name); |
| 16610 |
if (!win) return 0; |
| 16611 |
return win->flags & NK_WINDOW_MINIMIZED; |
| 16612 |
} |
| 16613 |
NK_API int |
| 16614 |
nk_window_is_closed(struct nk_context *ctx, const char *name) |
| 16615 |
{ |
| 16616 |
int title_len; |
| 16617 |
nk_hash title_hash; |
| 16618 |
struct nk_window *win; |
| 16619 |
NK_ASSERT(ctx); |
| 16620 |
if (!ctx) return 1; |
| 16621 |
|
| 16622 |
title_len = (int)nk_strlen(name); |
| 16623 |
title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); |
| 16624 |
win = nk_find_window(ctx, title_hash, name); |
| 16625 |
if (!win) return 1; |
| 16626 |
return (win->flags & NK_WINDOW_CLOSED); |
| 16627 |
} |
| 16628 |
NK_API int |
| 16629 |
nk_window_is_hidden(struct nk_context *ctx, const char *name) |
| 16630 |
{ |
| 16631 |
int title_len; |
| 16632 |
nk_hash title_hash; |
| 16633 |
struct nk_window *win; |
| 16634 |
NK_ASSERT(ctx); |
| 16635 |
if (!ctx) return 1; |
| 16636 |
|
| 16637 |
title_len = (int)nk_strlen(name); |
| 16638 |
title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); |
| 16639 |
win = nk_find_window(ctx, title_hash, name); |
| 16640 |
if (!win) return 1; |
| 16641 |
return (win->flags & NK_WINDOW_HIDDEN); |
| 16642 |
} |
| 16643 |
NK_API int |
| 16644 |
nk_window_is_active(struct nk_context *ctx, const char *name) |
| 16645 |
{ |
| 16646 |
int title_len; |
| 16647 |
nk_hash title_hash; |
| 16648 |
struct nk_window *win; |
| 16649 |
NK_ASSERT(ctx); |
| 16650 |
if (!ctx) return 0; |
| 16651 |
|
| 16652 |
title_len = (int)nk_strlen(name); |
| 16653 |
title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); |
| 16654 |
win = nk_find_window(ctx, title_hash, name); |
| 16655 |
if (!win) return 0; |
| 16656 |
return win == ctx->active; |
| 16657 |
} |
| 16658 |
NK_API struct nk_window* |
| 16659 |
nk_window_find(struct nk_context *ctx, const char *name) |
| 16660 |
{ |
| 16661 |
int title_len; |
| 16662 |
nk_hash title_hash; |
| 16663 |
title_len = (int)nk_strlen(name); |
| 16664 |
title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); |
| 16665 |
return nk_find_window(ctx, title_hash, name); |
| 16666 |
} |
| 16667 |
NK_API void |
| 16668 |
nk_window_close(struct nk_context *ctx, const char *name) |
| 16669 |
{ |
| 16670 |
struct nk_window *win; |
| 16671 |
NK_ASSERT(ctx); |
| 16672 |
if (!ctx) return; |
| 16673 |
win = nk_window_find(ctx, name); |
| 16674 |
if (!win) return; |
| 16675 |
NK_ASSERT(ctx->current != win && "You cannot close a currently active window"); |
| 16676 |
if (ctx->current == win) return; |
| 16677 |
win->flags |= NK_WINDOW_HIDDEN; |
| 16678 |
win->flags |= NK_WINDOW_CLOSED; |
| 16679 |
} |
| 16680 |
NK_API void |
| 16681 |
nk_window_set_bounds(struct nk_context *ctx, |
| 16682 |
const char *name, struct nk_rect bounds) |
| 16683 |
{ |
| 16684 |
struct nk_window *win; |
| 16685 |
NK_ASSERT(ctx); |
| 16686 |
if (!ctx) return; |
| 16687 |
win = nk_window_find(ctx, name); |
| 16688 |
if (!win) return; |
| 16689 |
NK_ASSERT(ctx->current != win && "You cannot update a currently in procecss window"); |
| 16690 |
win->bounds = bounds; |
| 16691 |
} |
| 16692 |
NK_API void |
| 16693 |
nk_window_set_position(struct nk_context *ctx, |
| 16694 |
const char *name, struct nk_vec2 pos) |
| 16695 |
{ |
| 16696 |
struct nk_window *win = nk_window_find(ctx, name); |
| 16697 |
if (!win) return; |
| 16698 |
win->bounds.x = pos.x; |
| 16699 |
win->bounds.y = pos.y; |
| 16700 |
} |
| 16701 |
NK_API void |
| 16702 |
nk_window_set_size(struct nk_context *ctx, |
| 16703 |
const char *name, struct nk_vec2 size) |
| 16704 |
{ |
| 16705 |
struct nk_window *win = nk_window_find(ctx, name); |
| 16706 |
if (!win) return; |
| 16707 |
win->bounds.w = size.x; |
| 16708 |
win->bounds.h = size.y; |
| 16709 |
} |
| 16710 |
NK_API void |
| 16711 |
nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y) |
| 16712 |
{ |
| 16713 |
struct nk_window *win; |
| 16714 |
NK_ASSERT(ctx); |
| 16715 |
NK_ASSERT(ctx->current); |
| 16716 |
if (!ctx || !ctx->current) |
| 16717 |
return; |
| 16718 |
win = ctx->current; |
| 16719 |
win->scrollbar.x = offset_x; |
| 16720 |
win->scrollbar.y = offset_y; |
| 16721 |
} |
| 16722 |
NK_API void |
| 16723 |
nk_window_collapse(struct nk_context *ctx, const char *name, |
| 16724 |
enum nk_collapse_states c) |
| 16725 |
{ |
| 16726 |
int title_len; |
| 16727 |
nk_hash title_hash; |
| 16728 |
struct nk_window *win; |
| 16729 |
NK_ASSERT(ctx); |
| 16730 |
if (!ctx) return; |
| 16731 |
|
| 16732 |
title_len = (int)nk_strlen(name); |
| 16733 |
title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); |
| 16734 |
win = nk_find_window(ctx, title_hash, name); |
| 16735 |
if (!win) return; |
| 16736 |
if (c == NK_MINIMIZED) |
| 16737 |
win->flags |= NK_WINDOW_MINIMIZED; |
| 16738 |
else win->flags &= ~(nk_flags)NK_WINDOW_MINIMIZED; |
| 16739 |
} |
| 16740 |
NK_API void |
| 16741 |
nk_window_collapse_if(struct nk_context *ctx, const char *name, |
| 16742 |
enum nk_collapse_states c, int cond) |
| 16743 |
{ |
| 16744 |
NK_ASSERT(ctx); |
| 16745 |
if (!ctx || !cond) return; |
| 16746 |
nk_window_collapse(ctx, name, c); |
| 16747 |
} |
| 16748 |
NK_API void |
| 16749 |
nk_window_show(struct nk_context *ctx, const char *name, enum nk_show_states s) |
| 16750 |
{ |
| 16751 |
int title_len; |
| 16752 |
nk_hash title_hash; |
| 16753 |
struct nk_window *win; |
| 16754 |
NK_ASSERT(ctx); |
| 16755 |
if (!ctx) return; |
| 16756 |
|
| 16757 |
title_len = (int)nk_strlen(name); |
| 16758 |
title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); |
| 16759 |
win = nk_find_window(ctx, title_hash, name); |
| 16760 |
if (!win) return; |
| 16761 |
if (s == NK_HIDDEN) { |
| 16762 |
win->flags |= NK_WINDOW_HIDDEN; |
| 16763 |
} else win->flags &= ~(nk_flags)NK_WINDOW_HIDDEN; |
| 16764 |
} |
| 16765 |
NK_API void |
| 16766 |
nk_window_show_if(struct nk_context *ctx, const char *name, |
| 16767 |
enum nk_show_states s, int cond) |
| 16768 |
{ |
| 16769 |
NK_ASSERT(ctx); |
| 16770 |
if (!ctx || !cond) return; |
| 16771 |
nk_window_show(ctx, name, s); |
| 16772 |
} |
| 16773 |
|
| 16774 |
NK_API void |
| 16775 |
nk_window_set_focus(struct nk_context *ctx, const char *name) |
| 16776 |
{ |
| 16777 |
int title_len; |
| 16778 |
nk_hash title_hash; |
| 16779 |
struct nk_window *win; |
| 16780 |
NK_ASSERT(ctx); |
| 16781 |
if (!ctx) return; |
| 16782 |
|
| 16783 |
title_len = (int)nk_strlen(name); |
| 16784 |
title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); |
| 16785 |
win = nk_find_window(ctx, title_hash, name); |
| 16786 |
if (win && ctx->end != win) { |
| 16787 |
nk_remove_window(ctx, win); |
| 16788 |
nk_insert_window(ctx, win, NK_INSERT_BACK); |
| 16789 |
} |
| 16790 |
ctx->active = win; |
| 16791 |
} |
| 16792 |
|
| 16793 |
|
| 16794 |
|
| 16795 |
|
| 16796 |
|
| 16797 |
|
| 16798 |
|
| 16799 |
|
| 16800 |
|
| 16801 |
NK_API int |
| 16802 |
nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type, |
| 16803 |
const char *title, nk_flags flags, struct nk_rect rect) |
| 16804 |
{ |
| 16805 |
struct nk_window *popup; |
| 16806 |
struct nk_window *win; |
| 16807 |
struct nk_panel *panel; |
| 16808 |
|
| 16809 |
int title_len; |
| 16810 |
nk_hash title_hash; |
| 16811 |
nk_size allocated; |
| 16812 |
|
| 16813 |
NK_ASSERT(ctx); |
| 16814 |
NK_ASSERT(title); |
| 16815 |
NK_ASSERT(ctx->current); |
| 16816 |
NK_ASSERT(ctx->current->layout); |
| 16817 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 16818 |
return 0; |
| 16819 |
|
| 16820 |
win = ctx->current; |
| 16821 |
panel = win->layout; |
| 16822 |
NK_ASSERT(!(panel->type & NK_PANEL_SET_POPUP) && "popups are not allowed to have popups"); |
| 16823 |
(void)panel; |
| 16824 |
title_len = (int)nk_strlen(title); |
| 16825 |
title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_POPUP); |
| 16826 |
|
| 16827 |
popup = win->popup.win; |
| 16828 |
if (!popup) { |
| 16829 |
popup = (struct nk_window*)nk_create_window(ctx); |
| 16830 |
popup->parent = win; |
| 16831 |
win->popup.win = popup; |
| 16832 |
win->popup.active = 0; |
| 16833 |
win->popup.type = NK_PANEL_POPUP; |
| 16834 |
} |
| 16835 |
|
| 16836 |
|
| 16837 |
if (win->popup.name != title_hash) { |
| 16838 |
if (!win->popup.active) { |
| 16839 |
nk_zero(popup, sizeof(*popup)); |
| 16840 |
win->popup.name = title_hash; |
| 16841 |
win->popup.active = 1; |
| 16842 |
win->popup.type = NK_PANEL_POPUP; |
| 16843 |
} else return 0; |
| 16844 |
} |
| 16845 |
|
| 16846 |
|
| 16847 |
ctx->current = popup; |
| 16848 |
rect.x += win->layout->clip.x; |
| 16849 |
rect.y += win->layout->clip.y; |
| 16850 |
|
| 16851 |
|
| 16852 |
popup->parent = win; |
| 16853 |
popup->bounds = rect; |
| 16854 |
popup->seq = ctx->seq; |
| 16855 |
popup->layout = (struct nk_panel*)nk_create_panel(ctx); |
| 16856 |
popup->flags = flags; |
| 16857 |
popup->flags |= NK_WINDOW_BORDER; |
| 16858 |
if (type == NK_POPUP_DYNAMIC) |
| 16859 |
popup->flags |= NK_WINDOW_DYNAMIC; |
| 16860 |
|
| 16861 |
popup->buffer = win->buffer; |
| 16862 |
nk_start_popup(ctx, win); |
| 16863 |
allocated = ctx->memory.allocated; |
| 16864 |
nk_push_scissor(&popup->buffer, nk_null_rect); |
| 16865 |
|
| 16866 |
if (nk_panel_begin(ctx, title, NK_PANEL_POPUP)) { |
| 16867 |
|
| 16868 |
struct nk_panel *root; |
| 16869 |
root = win->layout; |
| 16870 |
while (root) { |
| 16871 |
root->flags |= NK_WINDOW_ROM; |
| 16872 |
root->flags &= ~(nk_flags)NK_WINDOW_REMOVE_ROM; |
| 16873 |
root = root->parent; |
| 16874 |
} |
| 16875 |
win->popup.active = 1; |
| 16876 |
popup->layout->offset_x = &popup->scrollbar.x; |
| 16877 |
popup->layout->offset_y = &popup->scrollbar.y; |
| 16878 |
popup->layout->parent = win->layout; |
| 16879 |
return 1; |
| 16880 |
} else { |
| 16881 |
|
| 16882 |
struct nk_panel *root; |
| 16883 |
root = win->layout; |
| 16884 |
while (root) { |
| 16885 |
root->flags |= NK_WINDOW_REMOVE_ROM; |
| 16886 |
root = root->parent; |
| 16887 |
} |
| 16888 |
win->popup.buf.active = 0; |
| 16889 |
win->popup.active = 0; |
| 16890 |
ctx->memory.allocated = allocated; |
| 16891 |
ctx->current = win; |
| 16892 |
nk_free_panel(ctx, popup->layout); |
| 16893 |
popup->layout = 0; |
| 16894 |
return 0; |
| 16895 |
} |
| 16896 |
} |
| 16897 |
NK_LIB int |
| 16898 |
nk_nonblock_begin(struct nk_context *ctx, |
| 16899 |
nk_flags flags, struct nk_rect body, struct nk_rect header, |
| 16900 |
enum nk_panel_type panel_type) |
| 16901 |
{ |
| 16902 |
struct nk_window *popup; |
| 16903 |
struct nk_window *win; |
| 16904 |
struct nk_panel *panel; |
| 16905 |
int is_active = nk_true; |
| 16906 |
|
| 16907 |
NK_ASSERT(ctx); |
| 16908 |
NK_ASSERT(ctx->current); |
| 16909 |
NK_ASSERT(ctx->current->layout); |
| 16910 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 16911 |
return 0; |
| 16912 |
|
| 16913 |
|
| 16914 |
win = ctx->current; |
| 16915 |
panel = win->layout; |
| 16916 |
NK_ASSERT(!(panel->type & NK_PANEL_SET_POPUP)); |
| 16917 |
(void)panel; |
| 16918 |
popup = win->popup.win; |
| 16919 |
if (!popup) { |
| 16920 |
|
| 16921 |
popup = (struct nk_window*)nk_create_window(ctx); |
| 16922 |
popup->parent = win; |
| 16923 |
win->popup.win = popup; |
| 16924 |
win->popup.type = panel_type; |
| 16925 |
nk_command_buffer_init(&popup->buffer, &ctx->memory, NK_CLIPPING_ON); |
| 16926 |
} else { |
| 16927 |
|
| 16928 |
int pressed, in_body, in_header; |
| 16929 |
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE |
| 16930 |
pressed = nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT); |
| 16931 |
#else |
| 16932 |
pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT); |
| 16933 |
#endif |
| 16934 |
in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body); |
| 16935 |
in_header = nk_input_is_mouse_hovering_rect(&ctx->input, header); |
| 16936 |
if (pressed && (!in_body || in_header)) |
| 16937 |
is_active = nk_false; |
| 16938 |
} |
| 16939 |
win->popup.header = header; |
| 16940 |
|
| 16941 |
if (!is_active) { |
| 16942 |
|
| 16943 |
struct nk_panel *root = win->layout; |
| 16944 |
while (root) { |
| 16945 |
root->flags |= NK_WINDOW_REMOVE_ROM; |
| 16946 |
root = root->parent; |
| 16947 |
} |
| 16948 |
return is_active; |
| 16949 |
} |
| 16950 |
popup->bounds = body; |
| 16951 |
popup->parent = win; |
| 16952 |
popup->layout = (struct nk_panel*)nk_create_panel(ctx); |
| 16953 |
popup->flags = flags; |
| 16954 |
popup->flags |= NK_WINDOW_BORDER; |
| 16955 |
popup->flags |= NK_WINDOW_DYNAMIC; |
| 16956 |
popup->seq = ctx->seq; |
| 16957 |
win->popup.active = 1; |
| 16958 |
NK_ASSERT(popup->layout); |
| 16959 |
|
| 16960 |
nk_start_popup(ctx, win); |
| 16961 |
popup->buffer = win->buffer; |
| 16962 |
nk_push_scissor(&popup->buffer, nk_null_rect); |
| 16963 |
ctx->current = popup; |
| 16964 |
|
| 16965 |
nk_panel_begin(ctx, 0, panel_type); |
| 16966 |
win->buffer = popup->buffer; |
| 16967 |
popup->layout->parent = win->layout; |
| 16968 |
popup->layout->offset_x = &popup->scrollbar.x; |
| 16969 |
popup->layout->offset_y = &popup->scrollbar.y; |
| 16970 |
|
| 16971 |
|
| 16972 |
{struct nk_panel *root; |
| 16973 |
root = win->layout; |
| 16974 |
while (root) { |
| 16975 |
root->flags |= NK_WINDOW_ROM; |
| 16976 |
root = root->parent; |
| 16977 |
}} |
| 16978 |
return is_active; |
| 16979 |
} |
| 16980 |
NK_API void |
| 16981 |
nk_popup_close(struct nk_context *ctx) |
| 16982 |
{ |
| 16983 |
struct nk_window *popup; |
| 16984 |
NK_ASSERT(ctx); |
| 16985 |
if (!ctx || !ctx->current) return; |
| 16986 |
|
| 16987 |
popup = ctx->current; |
| 16988 |
NK_ASSERT(popup->parent); |
| 16989 |
NK_ASSERT(popup->layout->type & NK_PANEL_SET_POPUP); |
| 16990 |
popup->flags |= NK_WINDOW_HIDDEN; |
| 16991 |
} |
| 16992 |
NK_API void |
| 16993 |
nk_popup_end(struct nk_context *ctx) |
| 16994 |
{ |
| 16995 |
struct nk_window *win; |
| 16996 |
struct nk_window *popup; |
| 16997 |
|
| 16998 |
NK_ASSERT(ctx); |
| 16999 |
NK_ASSERT(ctx->current); |
| 17000 |
NK_ASSERT(ctx->current->layout); |
| 17001 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17002 |
return; |
| 17003 |
|
| 17004 |
popup = ctx->current; |
| 17005 |
if (!popup->parent) return; |
| 17006 |
win = popup->parent; |
| 17007 |
if (popup->flags & NK_WINDOW_HIDDEN) { |
| 17008 |
struct nk_panel *root; |
| 17009 |
root = win->layout; |
| 17010 |
while (root) { |
| 17011 |
root->flags |= NK_WINDOW_REMOVE_ROM; |
| 17012 |
root = root->parent; |
| 17013 |
} |
| 17014 |
win->popup.active = 0; |
| 17015 |
} |
| 17016 |
nk_push_scissor(&popup->buffer, nk_null_rect); |
| 17017 |
nk_end(ctx); |
| 17018 |
|
| 17019 |
win->buffer = popup->buffer; |
| 17020 |
nk_finish_popup(ctx, win); |
| 17021 |
ctx->current = win; |
| 17022 |
nk_push_scissor(&win->buffer, win->layout->clip); |
| 17023 |
} |
| 17024 |
NK_API void |
| 17025 |
nk_popup_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y) |
| 17026 |
{ |
| 17027 |
struct nk_window *popup; |
| 17028 |
|
| 17029 |
NK_ASSERT(ctx); |
| 17030 |
NK_ASSERT(ctx->current); |
| 17031 |
NK_ASSERT(ctx->current->layout); |
| 17032 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17033 |
return; |
| 17034 |
|
| 17035 |
popup = ctx->current; |
| 17036 |
if (offset_x) |
| 17037 |
*offset_x = popup->scrollbar.x; |
| 17038 |
if (offset_y) |
| 17039 |
*offset_y = popup->scrollbar.y; |
| 17040 |
} |
| 17041 |
NK_API void |
| 17042 |
nk_popup_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y) |
| 17043 |
{ |
| 17044 |
struct nk_window *popup; |
| 17045 |
|
| 17046 |
NK_ASSERT(ctx); |
| 17047 |
NK_ASSERT(ctx->current); |
| 17048 |
NK_ASSERT(ctx->current->layout); |
| 17049 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17050 |
return; |
| 17051 |
|
| 17052 |
popup = ctx->current; |
| 17053 |
popup->scrollbar.x = offset_x; |
| 17054 |
popup->scrollbar.y = offset_y; |
| 17055 |
} |
| 17056 |
|
| 17057 |
|
| 17058 |
|
| 17059 |
|
| 17060 |
|
| 17061 |
|
| 17062 |
|
| 17063 |
|
| 17064 |
|
| 17065 |
NK_API int |
| 17066 |
nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size, |
| 17067 |
struct nk_rect trigger_bounds) |
| 17068 |
{ |
| 17069 |
struct nk_window *win; |
| 17070 |
struct nk_window *popup; |
| 17071 |
struct nk_rect body; |
| 17072 |
|
| 17073 |
NK_STORAGE const struct nk_rect null_rect = {-1,-1,0,0}; |
| 17074 |
int is_clicked = 0; |
| 17075 |
int is_open = 0; |
| 17076 |
int ret = 0; |
| 17077 |
|
| 17078 |
NK_ASSERT(ctx); |
| 17079 |
NK_ASSERT(ctx->current); |
| 17080 |
NK_ASSERT(ctx->current->layout); |
| 17081 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17082 |
return 0; |
| 17083 |
|
| 17084 |
win = ctx->current; |
| 17085 |
++win->popup.con_count; |
| 17086 |
if (ctx->current != ctx->active) |
| 17087 |
return 0; |
| 17088 |
|
| 17089 |
|
| 17090 |
popup = win->popup.win; |
| 17091 |
is_open = (popup && win->popup.type == NK_PANEL_CONTEXTUAL); |
| 17092 |
is_clicked = nk_input_mouse_clicked(&ctx->input, NK_BUTTON_RIGHT, trigger_bounds); |
| 17093 |
if (win->popup.active_con && win->popup.con_count != win->popup.active_con) |
| 17094 |
return 0; |
| 17095 |
if (!is_open && win->popup.active_con) |
| 17096 |
win->popup.active_con = 0; |
| 17097 |
if ((!is_open && !is_clicked)) |
| 17098 |
return 0; |
| 17099 |
|
| 17100 |
|
| 17101 |
win->popup.active_con = win->popup.con_count; |
| 17102 |
if (is_clicked) { |
| 17103 |
body.x = ctx->input.mouse.pos.x; |
| 17104 |
body.y = ctx->input.mouse.pos.y; |
| 17105 |
} else { |
| 17106 |
body.x = popup->bounds.x; |
| 17107 |
body.y = popup->bounds.y; |
| 17108 |
} |
| 17109 |
body.w = size.x; |
| 17110 |
body.h = size.y; |
| 17111 |
|
| 17112 |
|
| 17113 |
ret = nk_nonblock_begin(ctx, flags|NK_WINDOW_NO_SCROLLBAR, body, |
| 17114 |
null_rect, NK_PANEL_CONTEXTUAL); |
| 17115 |
if (ret) win->popup.type = NK_PANEL_CONTEXTUAL; |
| 17116 |
else { |
| 17117 |
win->popup.active_con = 0; |
| 17118 |
win->popup.type = NK_PANEL_NONE; |
| 17119 |
if (win->popup.win) |
| 17120 |
win->popup.win->flags = 0; |
| 17121 |
} |
| 17122 |
return ret; |
| 17123 |
} |
| 17124 |
NK_API int |
| 17125 |
nk_contextual_item_text(struct nk_context *ctx, const char *text, int len, |
| 17126 |
nk_flags alignment) |
| 17127 |
{ |
| 17128 |
struct nk_window *win; |
| 17129 |
const struct nk_input *in; |
| 17130 |
const struct nk_style *style; |
| 17131 |
|
| 17132 |
struct nk_rect bounds; |
| 17133 |
enum nk_widget_layout_states state; |
| 17134 |
|
| 17135 |
NK_ASSERT(ctx); |
| 17136 |
NK_ASSERT(ctx->current); |
| 17137 |
NK_ASSERT(ctx->current->layout); |
| 17138 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17139 |
return 0; |
| 17140 |
|
| 17141 |
win = ctx->current; |
| 17142 |
style = &ctx->style; |
| 17143 |
state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding); |
| 17144 |
if (!state) return nk_false; |
| 17145 |
|
| 17146 |
in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 17147 |
if (nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, |
| 17148 |
text, len, alignment, NK_BUTTON_DEFAULT, &style->contextual_button, in, style->font)) { |
| 17149 |
nk_contextual_close(ctx); |
| 17150 |
return nk_true; |
| 17151 |
} |
| 17152 |
return nk_false; |
| 17153 |
} |
| 17154 |
NK_API int |
| 17155 |
nk_contextual_item_label(struct nk_context *ctx, const char *label, nk_flags align) |
| 17156 |
{ |
| 17157 |
return nk_contextual_item_text(ctx, label, nk_strlen(label), align); |
| 17158 |
} |
| 17159 |
NK_API int |
| 17160 |
nk_contextual_item_image_text(struct nk_context *ctx, struct nk_image img, |
| 17161 |
const char *text, int len, nk_flags align) |
| 17162 |
{ |
| 17163 |
struct nk_window *win; |
| 17164 |
const struct nk_input *in; |
| 17165 |
const struct nk_style *style; |
| 17166 |
|
| 17167 |
struct nk_rect bounds; |
| 17168 |
enum nk_widget_layout_states state; |
| 17169 |
|
| 17170 |
NK_ASSERT(ctx); |
| 17171 |
NK_ASSERT(ctx->current); |
| 17172 |
NK_ASSERT(ctx->current->layout); |
| 17173 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17174 |
return 0; |
| 17175 |
|
| 17176 |
win = ctx->current; |
| 17177 |
style = &ctx->style; |
| 17178 |
state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding); |
| 17179 |
if (!state) return nk_false; |
| 17180 |
|
| 17181 |
in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 17182 |
if (nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, bounds, |
| 17183 |
img, text, len, align, NK_BUTTON_DEFAULT, &style->contextual_button, style->font, in)){ |
| 17184 |
nk_contextual_close(ctx); |
| 17185 |
return nk_true; |
| 17186 |
} |
| 17187 |
return nk_false; |
| 17188 |
} |
| 17189 |
NK_API int |
| 17190 |
nk_contextual_item_image_label(struct nk_context *ctx, struct nk_image img, |
| 17191 |
const char *label, nk_flags align) |
| 17192 |
{ |
| 17193 |
return nk_contextual_item_image_text(ctx, img, label, nk_strlen(label), align); |
| 17194 |
} |
| 17195 |
NK_API int |
| 17196 |
nk_contextual_item_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbol, |
| 17197 |
const char *text, int len, nk_flags align) |
| 17198 |
{ |
| 17199 |
struct nk_window *win; |
| 17200 |
const struct nk_input *in; |
| 17201 |
const struct nk_style *style; |
| 17202 |
|
| 17203 |
struct nk_rect bounds; |
| 17204 |
enum nk_widget_layout_states state; |
| 17205 |
|
| 17206 |
NK_ASSERT(ctx); |
| 17207 |
NK_ASSERT(ctx->current); |
| 17208 |
NK_ASSERT(ctx->current->layout); |
| 17209 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17210 |
return 0; |
| 17211 |
|
| 17212 |
win = ctx->current; |
| 17213 |
style = &ctx->style; |
| 17214 |
state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding); |
| 17215 |
if (!state) return nk_false; |
| 17216 |
|
| 17217 |
in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 17218 |
if (nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds, |
| 17219 |
symbol, text, len, align, NK_BUTTON_DEFAULT, &style->contextual_button, style->font, in)) { |
| 17220 |
nk_contextual_close(ctx); |
| 17221 |
return nk_true; |
| 17222 |
} |
| 17223 |
return nk_false; |
| 17224 |
} |
| 17225 |
NK_API int |
| 17226 |
nk_contextual_item_symbol_label(struct nk_context *ctx, enum nk_symbol_type symbol, |
| 17227 |
const char *text, nk_flags align) |
| 17228 |
{ |
| 17229 |
return nk_contextual_item_symbol_text(ctx, symbol, text, nk_strlen(text), align); |
| 17230 |
} |
| 17231 |
NK_API void |
| 17232 |
nk_contextual_close(struct nk_context *ctx) |
| 17233 |
{ |
| 17234 |
NK_ASSERT(ctx); |
| 17235 |
NK_ASSERT(ctx->current); |
| 17236 |
NK_ASSERT(ctx->current->layout); |
| 17237 |
if (!ctx || !ctx->current || !ctx->current->layout) return; |
| 17238 |
nk_popup_close(ctx); |
| 17239 |
} |
| 17240 |
NK_API void |
| 17241 |
nk_contextual_end(struct nk_context *ctx) |
| 17242 |
{ |
| 17243 |
struct nk_window *popup; |
| 17244 |
struct nk_panel *panel; |
| 17245 |
NK_ASSERT(ctx); |
| 17246 |
NK_ASSERT(ctx->current); |
| 17247 |
if (!ctx || !ctx->current) return; |
| 17248 |
|
| 17249 |
popup = ctx->current; |
| 17250 |
panel = popup->layout; |
| 17251 |
NK_ASSERT(popup->parent); |
| 17252 |
NK_ASSERT(panel->type & NK_PANEL_SET_POPUP); |
| 17253 |
if (panel->flags & NK_WINDOW_DYNAMIC) { |
| 17254 |
|
| 17255 |
|
| 17256 |
|
| 17257 |
|
| 17258 |
|
| 17259 |
struct nk_rect body = {0,0,0,0}; |
| 17260 |
if (panel->at_y < (panel->bounds.y + panel->bounds.h)) { |
| 17261 |
struct nk_vec2 padding = nk_panel_get_padding(&ctx->style, panel->type); |
| 17262 |
body = panel->bounds; |
| 17263 |
body.y = (panel->at_y + panel->footer_height + panel->border + padding.y + panel->row.height); |
| 17264 |
body.h = (panel->bounds.y + panel->bounds.h) - body.y; |
| 17265 |
} |
| 17266 |
{int pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT); |
| 17267 |
int in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body); |
| 17268 |
if (pressed && in_body) |
| 17269 |
popup->flags |= NK_WINDOW_HIDDEN; |
| 17270 |
} |
| 17271 |
} |
| 17272 |
if (popup->flags & NK_WINDOW_HIDDEN) |
| 17273 |
popup->seq = 0; |
| 17274 |
nk_popup_end(ctx); |
| 17275 |
return; |
| 17276 |
} |
| 17277 |
|
| 17278 |
|
| 17279 |
|
| 17280 |
|
| 17281 |
|
| 17282 |
|
| 17283 |
|
| 17284 |
|
| 17285 |
|
| 17286 |
|
| 17287 |
NK_API void |
| 17288 |
nk_menubar_begin(struct nk_context *ctx) |
| 17289 |
{ |
| 17290 |
struct nk_panel *layout; |
| 17291 |
NK_ASSERT(ctx); |
| 17292 |
NK_ASSERT(ctx->current); |
| 17293 |
NK_ASSERT(ctx->current->layout); |
| 17294 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17295 |
return; |
| 17296 |
|
| 17297 |
layout = ctx->current->layout; |
| 17298 |
NK_ASSERT(layout->at_y == layout->bounds.y); |
| 17299 |
|
| 17300 |
|
| 17301 |
|
| 17302 |
|
| 17303 |
|
| 17304 |
|
| 17305 |
|
| 17306 |
|
| 17307 |
|
| 17308 |
|
| 17309 |
|
| 17310 |
|
| 17311 |
|
| 17312 |
|
| 17313 |
|
| 17314 |
if (layout->flags & NK_WINDOW_HIDDEN || layout->flags & NK_WINDOW_MINIMIZED) |
| 17315 |
return; |
| 17316 |
|
| 17317 |
layout->menu.x = layout->at_x; |
| 17318 |
layout->menu.y = layout->at_y + layout->row.height; |
| 17319 |
layout->menu.w = layout->bounds.w; |
| 17320 |
layout->menu.offset.x = *layout->offset_x; |
| 17321 |
layout->menu.offset.y = *layout->offset_y; |
| 17322 |
*layout->offset_y = 0; |
| 17323 |
} |
| 17324 |
NK_API void |
| 17325 |
nk_menubar_end(struct nk_context *ctx) |
| 17326 |
{ |
| 17327 |
struct nk_window *win; |
| 17328 |
struct nk_panel *layout; |
| 17329 |
struct nk_command_buffer *out; |
| 17330 |
|
| 17331 |
NK_ASSERT(ctx); |
| 17332 |
NK_ASSERT(ctx->current); |
| 17333 |
NK_ASSERT(ctx->current->layout); |
| 17334 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17335 |
return; |
| 17336 |
|
| 17337 |
win = ctx->current; |
| 17338 |
out = &win->buffer; |
| 17339 |
layout = win->layout; |
| 17340 |
if (layout->flags & NK_WINDOW_HIDDEN || layout->flags & NK_WINDOW_MINIMIZED) |
| 17341 |
return; |
| 17342 |
|
| 17343 |
layout->menu.h = layout->at_y - layout->menu.y; |
| 17344 |
layout->bounds.y += layout->menu.h + ctx->style.window.spacing.y + layout->row.height; |
| 17345 |
layout->bounds.h -= layout->menu.h + ctx->style.window.spacing.y + layout->row.height; |
| 17346 |
|
| 17347 |
*layout->offset_x = layout->menu.offset.x; |
| 17348 |
*layout->offset_y = layout->menu.offset.y; |
| 17349 |
layout->at_y = layout->bounds.y - layout->row.height; |
| 17350 |
|
| 17351 |
layout->clip.y = layout->bounds.y; |
| 17352 |
layout->clip.h = layout->bounds.h; |
| 17353 |
nk_push_scissor(out, layout->clip); |
| 17354 |
} |
| 17355 |
NK_INTERN int |
| 17356 |
nk_menu_begin(struct nk_context *ctx, struct nk_window *win, |
| 17357 |
const char *id, int is_clicked, struct nk_rect header, struct nk_vec2 size) |
| 17358 |
{ |
| 17359 |
int is_open = 0; |
| 17360 |
int is_active = 0; |
| 17361 |
struct nk_rect body; |
| 17362 |
struct nk_window *popup; |
| 17363 |
nk_hash hash = nk_murmur_hash(id, (int)nk_strlen(id), NK_PANEL_MENU); |
| 17364 |
|
| 17365 |
NK_ASSERT(ctx); |
| 17366 |
NK_ASSERT(ctx->current); |
| 17367 |
NK_ASSERT(ctx->current->layout); |
| 17368 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17369 |
return 0; |
| 17370 |
|
| 17371 |
body.x = header.x; |
| 17372 |
body.w = size.x; |
| 17373 |
body.y = header.y + header.h; |
| 17374 |
body.h = size.y; |
| 17375 |
|
| 17376 |
popup = win->popup.win; |
| 17377 |
is_open = popup ? nk_true : nk_false; |
| 17378 |
is_active = (popup && (win->popup.name == hash) && win->popup.type == NK_PANEL_MENU); |
| 17379 |
if ((is_clicked && is_open && !is_active) || (is_open && !is_active) || |
| 17380 |
(!is_open && !is_active && !is_clicked)) return 0; |
| 17381 |
if (!nk_nonblock_begin(ctx, NK_WINDOW_NO_SCROLLBAR, body, header, NK_PANEL_MENU)) |
| 17382 |
return 0; |
| 17383 |
|
| 17384 |
win->popup.type = NK_PANEL_MENU; |
| 17385 |
win->popup.name = hash; |
| 17386 |
return 1; |
| 17387 |
} |
| 17388 |
NK_API int |
| 17389 |
nk_menu_begin_text(struct nk_context *ctx, const char *title, int len, |
| 17390 |
nk_flags align, struct nk_vec2 size) |
| 17391 |
{ |
| 17392 |
struct nk_window *win; |
| 17393 |
const struct nk_input *in; |
| 17394 |
struct nk_rect header; |
| 17395 |
int is_clicked = nk_false; |
| 17396 |
nk_flags state; |
| 17397 |
|
| 17398 |
NK_ASSERT(ctx); |
| 17399 |
NK_ASSERT(ctx->current); |
| 17400 |
NK_ASSERT(ctx->current->layout); |
| 17401 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17402 |
return 0; |
| 17403 |
|
| 17404 |
win = ctx->current; |
| 17405 |
state = nk_widget(&header, ctx); |
| 17406 |
if (!state) return 0; |
| 17407 |
in = (state == NK_WIDGET_ROM || win->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 17408 |
if (nk_do_button_text(&ctx->last_widget_state, &win->buffer, header, |
| 17409 |
title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) |
| 17410 |
is_clicked = nk_true; |
| 17411 |
return nk_menu_begin(ctx, win, title, is_clicked, header, size); |
| 17412 |
} |
| 17413 |
NK_API int nk_menu_begin_label(struct nk_context *ctx, |
| 17414 |
const char *text, nk_flags align, struct nk_vec2 size) |
| 17415 |
{ |
| 17416 |
return nk_menu_begin_text(ctx, text, nk_strlen(text), align, size); |
| 17417 |
} |
| 17418 |
NK_API int |
| 17419 |
nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img, |
| 17420 |
struct nk_vec2 size) |
| 17421 |
{ |
| 17422 |
struct nk_window *win; |
| 17423 |
struct nk_rect header; |
| 17424 |
const struct nk_input *in; |
| 17425 |
int is_clicked = nk_false; |
| 17426 |
nk_flags state; |
| 17427 |
|
| 17428 |
NK_ASSERT(ctx); |
| 17429 |
NK_ASSERT(ctx->current); |
| 17430 |
NK_ASSERT(ctx->current->layout); |
| 17431 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17432 |
return 0; |
| 17433 |
|
| 17434 |
win = ctx->current; |
| 17435 |
state = nk_widget(&header, ctx); |
| 17436 |
if (!state) return 0; |
| 17437 |
in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 17438 |
if (nk_do_button_image(&ctx->last_widget_state, &win->buffer, header, |
| 17439 |
img, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in)) |
| 17440 |
is_clicked = nk_true; |
| 17441 |
return nk_menu_begin(ctx, win, id, is_clicked, header, size); |
| 17442 |
} |
| 17443 |
NK_API int |
| 17444 |
nk_menu_begin_symbol(struct nk_context *ctx, const char *id, |
| 17445 |
enum nk_symbol_type sym, struct nk_vec2 size) |
| 17446 |
{ |
| 17447 |
struct nk_window *win; |
| 17448 |
const struct nk_input *in; |
| 17449 |
struct nk_rect header; |
| 17450 |
int is_clicked = nk_false; |
| 17451 |
nk_flags state; |
| 17452 |
|
| 17453 |
NK_ASSERT(ctx); |
| 17454 |
NK_ASSERT(ctx->current); |
| 17455 |
NK_ASSERT(ctx->current->layout); |
| 17456 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17457 |
return 0; |
| 17458 |
|
| 17459 |
win = ctx->current; |
| 17460 |
state = nk_widget(&header, ctx); |
| 17461 |
if (!state) return 0; |
| 17462 |
in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 17463 |
if (nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, header, |
| 17464 |
sym, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) |
| 17465 |
is_clicked = nk_true; |
| 17466 |
return nk_menu_begin(ctx, win, id, is_clicked, header, size); |
| 17467 |
} |
| 17468 |
NK_API int |
| 17469 |
nk_menu_begin_image_text(struct nk_context *ctx, const char *title, int len, |
| 17470 |
nk_flags align, struct nk_image img, struct nk_vec2 size) |
| 17471 |
{ |
| 17472 |
struct nk_window *win; |
| 17473 |
struct nk_rect header; |
| 17474 |
const struct nk_input *in; |
| 17475 |
int is_clicked = nk_false; |
| 17476 |
nk_flags state; |
| 17477 |
|
| 17478 |
NK_ASSERT(ctx); |
| 17479 |
NK_ASSERT(ctx->current); |
| 17480 |
NK_ASSERT(ctx->current->layout); |
| 17481 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17482 |
return 0; |
| 17483 |
|
| 17484 |
win = ctx->current; |
| 17485 |
state = nk_widget(&header, ctx); |
| 17486 |
if (!state) return 0; |
| 17487 |
in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 17488 |
if (nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, |
| 17489 |
header, img, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, |
| 17490 |
ctx->style.font, in)) |
| 17491 |
is_clicked = nk_true; |
| 17492 |
return nk_menu_begin(ctx, win, title, is_clicked, header, size); |
| 17493 |
} |
| 17494 |
NK_API int |
| 17495 |
nk_menu_begin_image_label(struct nk_context *ctx, |
| 17496 |
const char *title, nk_flags align, struct nk_image img, struct nk_vec2 size) |
| 17497 |
{ |
| 17498 |
return nk_menu_begin_image_text(ctx, title, nk_strlen(title), align, img, size); |
| 17499 |
} |
| 17500 |
NK_API int |
| 17501 |
nk_menu_begin_symbol_text(struct nk_context *ctx, const char *title, int len, |
| 17502 |
nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size) |
| 17503 |
{ |
| 17504 |
struct nk_window *win; |
| 17505 |
struct nk_rect header; |
| 17506 |
const struct nk_input *in; |
| 17507 |
int is_clicked = nk_false; |
| 17508 |
nk_flags state; |
| 17509 |
|
| 17510 |
NK_ASSERT(ctx); |
| 17511 |
NK_ASSERT(ctx->current); |
| 17512 |
NK_ASSERT(ctx->current->layout); |
| 17513 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17514 |
return 0; |
| 17515 |
|
| 17516 |
win = ctx->current; |
| 17517 |
state = nk_widget(&header, ctx); |
| 17518 |
if (!state) return 0; |
| 17519 |
|
| 17520 |
in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 17521 |
if (nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, |
| 17522 |
header, sym, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, |
| 17523 |
ctx->style.font, in)) is_clicked = nk_true; |
| 17524 |
return nk_menu_begin(ctx, win, title, is_clicked, header, size); |
| 17525 |
} |
| 17526 |
NK_API int |
| 17527 |
nk_menu_begin_symbol_label(struct nk_context *ctx, |
| 17528 |
const char *title, nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size ) |
| 17529 |
{ |
| 17530 |
return nk_menu_begin_symbol_text(ctx, title, nk_strlen(title), align,sym,size); |
| 17531 |
} |
| 17532 |
NK_API int |
| 17533 |
nk_menu_item_text(struct nk_context *ctx, const char *title, int len, nk_flags align) |
| 17534 |
{ |
| 17535 |
return nk_contextual_item_text(ctx, title, len, align); |
| 17536 |
} |
| 17537 |
NK_API int |
| 17538 |
nk_menu_item_label(struct nk_context *ctx, const char *label, nk_flags align) |
| 17539 |
{ |
| 17540 |
return nk_contextual_item_label(ctx, label, align); |
| 17541 |
} |
| 17542 |
NK_API int |
| 17543 |
nk_menu_item_image_label(struct nk_context *ctx, struct nk_image img, |
| 17544 |
const char *label, nk_flags align) |
| 17545 |
{ |
| 17546 |
return nk_contextual_item_image_label(ctx, img, label, align); |
| 17547 |
} |
| 17548 |
NK_API int |
| 17549 |
nk_menu_item_image_text(struct nk_context *ctx, struct nk_image img, |
| 17550 |
const char *text, int len, nk_flags align) |
| 17551 |
{ |
| 17552 |
return nk_contextual_item_image_text(ctx, img, text, len, align); |
| 17553 |
} |
| 17554 |
NK_API int nk_menu_item_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, |
| 17555 |
const char *text, int len, nk_flags align) |
| 17556 |
{ |
| 17557 |
return nk_contextual_item_symbol_text(ctx, sym, text, len, align); |
| 17558 |
} |
| 17559 |
NK_API int nk_menu_item_symbol_label(struct nk_context *ctx, enum nk_symbol_type sym, |
| 17560 |
const char *label, nk_flags align) |
| 17561 |
{ |
| 17562 |
return nk_contextual_item_symbol_label(ctx, sym, label, align); |
| 17563 |
} |
| 17564 |
NK_API void nk_menu_close(struct nk_context *ctx) |
| 17565 |
{ |
| 17566 |
nk_contextual_close(ctx); |
| 17567 |
} |
| 17568 |
NK_API void |
| 17569 |
nk_menu_end(struct nk_context *ctx) |
| 17570 |
{ |
| 17571 |
nk_contextual_end(ctx); |
| 17572 |
} |
| 17573 |
|
| 17574 |
|
| 17575 |
|
| 17576 |
|
| 17577 |
|
| 17578 |
|
| 17579 |
|
| 17580 |
|
| 17581 |
|
| 17582 |
|
| 17583 |
NK_API void |
| 17584 |
nk_layout_set_min_row_height(struct nk_context *ctx, float height) |
| 17585 |
{ |
| 17586 |
struct nk_window *win; |
| 17587 |
struct nk_panel *layout; |
| 17588 |
|
| 17589 |
NK_ASSERT(ctx); |
| 17590 |
NK_ASSERT(ctx->current); |
| 17591 |
NK_ASSERT(ctx->current->layout); |
| 17592 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17593 |
return; |
| 17594 |
|
| 17595 |
win = ctx->current; |
| 17596 |
layout = win->layout; |
| 17597 |
layout->row.min_height = height; |
| 17598 |
} |
| 17599 |
NK_API void |
| 17600 |
nk_layout_reset_min_row_height(struct nk_context *ctx) |
| 17601 |
{ |
| 17602 |
struct nk_window *win; |
| 17603 |
struct nk_panel *layout; |
| 17604 |
|
| 17605 |
NK_ASSERT(ctx); |
| 17606 |
NK_ASSERT(ctx->current); |
| 17607 |
NK_ASSERT(ctx->current->layout); |
| 17608 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17609 |
return; |
| 17610 |
|
| 17611 |
win = ctx->current; |
| 17612 |
layout = win->layout; |
| 17613 |
layout->row.min_height = ctx->style.font->height; |
| 17614 |
layout->row.min_height += ctx->style.text.padding.y*2; |
| 17615 |
layout->row.min_height += ctx->style.window.min_row_height_padding*2; |
| 17616 |
} |
| 17617 |
NK_LIB float |
| 17618 |
nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type, |
| 17619 |
float total_space, int columns) |
| 17620 |
{ |
| 17621 |
float panel_padding; |
| 17622 |
float panel_spacing; |
| 17623 |
float panel_space; |
| 17624 |
|
| 17625 |
struct nk_vec2 spacing; |
| 17626 |
struct nk_vec2 padding; |
| 17627 |
|
| 17628 |
spacing = style->window.spacing; |
| 17629 |
padding = nk_panel_get_padding(style, type); |
| 17630 |
|
| 17631 |
|
| 17632 |
panel_padding = 2 * padding.x; |
| 17633 |
panel_spacing = (float)NK_MAX(columns - 1, 0) * spacing.x; |
| 17634 |
panel_space = total_space - panel_padding - panel_spacing; |
| 17635 |
return panel_space; |
| 17636 |
} |
| 17637 |
NK_LIB void |
| 17638 |
nk_panel_layout(const struct nk_context *ctx, struct nk_window *win, |
| 17639 |
float height, int cols) |
| 17640 |
{ |
| 17641 |
struct nk_panel *layout; |
| 17642 |
const struct nk_style *style; |
| 17643 |
struct nk_command_buffer *out; |
| 17644 |
|
| 17645 |
struct nk_vec2 item_spacing; |
| 17646 |
struct nk_color color; |
| 17647 |
|
| 17648 |
NK_ASSERT(ctx); |
| 17649 |
NK_ASSERT(ctx->current); |
| 17650 |
NK_ASSERT(ctx->current->layout); |
| 17651 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17652 |
return; |
| 17653 |
|
| 17654 |
|
| 17655 |
layout = win->layout; |
| 17656 |
style = &ctx->style; |
| 17657 |
out = &win->buffer; |
| 17658 |
color = style->window.background; |
| 17659 |
item_spacing = style->window.spacing; |
| 17660 |
|
| 17661 |
|
| 17662 |
|
| 17663 |
|
| 17664 |
|
| 17665 |
|
| 17666 |
NK_ASSERT(!(layout->flags & NK_WINDOW_MINIMIZED)); |
| 17667 |
NK_ASSERT(!(layout->flags & NK_WINDOW_HIDDEN)); |
| 17668 |
NK_ASSERT(!(layout->flags & NK_WINDOW_CLOSED)); |
| 17669 |
|
| 17670 |
|
| 17671 |
layout->row.index = 0; |
| 17672 |
layout->at_y += layout->row.height; |
| 17673 |
layout->row.columns = cols; |
| 17674 |
if (height == 0.0f) |
| 17675 |
layout->row.height = NK_MAX(height, layout->row.min_height) + item_spacing.y; |
| 17676 |
else layout->row.height = height + item_spacing.y; |
| 17677 |
|
| 17678 |
layout->row.item_offset = 0; |
| 17679 |
if (layout->flags & NK_WINDOW_DYNAMIC) { |
| 17680 |
|
| 17681 |
struct nk_rect background; |
| 17682 |
background.x = win->bounds.x; |
| 17683 |
background.w = win->bounds.w; |
| 17684 |
background.y = layout->at_y - 1.0f; |
| 17685 |
background.h = layout->row.height + 1.0f; |
| 17686 |
nk_fill_rect(out, background, 0, color); |
| 17687 |
} |
| 17688 |
} |
| 17689 |
NK_LIB void |
| 17690 |
nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, |
| 17691 |
float height, int cols, int width) |
| 17692 |
{ |
| 17693 |
|
| 17694 |
struct nk_window *win; |
| 17695 |
NK_ASSERT(ctx); |
| 17696 |
NK_ASSERT(ctx->current); |
| 17697 |
NK_ASSERT(ctx->current->layout); |
| 17698 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17699 |
return; |
| 17700 |
|
| 17701 |
win = ctx->current; |
| 17702 |
nk_panel_layout(ctx, win, height, cols); |
| 17703 |
if (fmt == NK_DYNAMIC) |
| 17704 |
win->layout->row.type = NK_LAYOUT_DYNAMIC_FIXED; |
| 17705 |
else win->layout->row.type = NK_LAYOUT_STATIC_FIXED; |
| 17706 |
|
| 17707 |
win->layout->row.ratio = 0; |
| 17708 |
win->layout->row.filled = 0; |
| 17709 |
win->layout->row.item_offset = 0; |
| 17710 |
win->layout->row.item_width = (float)width; |
| 17711 |
} |
| 17712 |
NK_API float |
| 17713 |
nk_layout_ratio_from_pixel(struct nk_context *ctx, float pixel_width) |
| 17714 |
{ |
| 17715 |
struct nk_window *win; |
| 17716 |
NK_ASSERT(ctx); |
| 17717 |
NK_ASSERT(pixel_width); |
| 17718 |
if (!ctx || !ctx->current || !ctx->current->layout) return 0; |
| 17719 |
win = ctx->current; |
| 17720 |
return NK_CLAMP(0.0f, pixel_width/win->bounds.x, 1.0f); |
| 17721 |
} |
| 17722 |
NK_API void |
| 17723 |
nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols) |
| 17724 |
{ |
| 17725 |
nk_row_layout(ctx, NK_DYNAMIC, height, cols, 0); |
| 17726 |
} |
| 17727 |
NK_API void |
| 17728 |
nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols) |
| 17729 |
{ |
| 17730 |
nk_row_layout(ctx, NK_STATIC, height, cols, item_width); |
| 17731 |
} |
| 17732 |
NK_API void |
| 17733 |
nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, |
| 17734 |
float row_height, int cols) |
| 17735 |
{ |
| 17736 |
struct nk_window *win; |
| 17737 |
struct nk_panel *layout; |
| 17738 |
|
| 17739 |
NK_ASSERT(ctx); |
| 17740 |
NK_ASSERT(ctx->current); |
| 17741 |
NK_ASSERT(ctx->current->layout); |
| 17742 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17743 |
return; |
| 17744 |
|
| 17745 |
win = ctx->current; |
| 17746 |
layout = win->layout; |
| 17747 |
nk_panel_layout(ctx, win, row_height, cols); |
| 17748 |
if (fmt == NK_DYNAMIC) |
| 17749 |
layout->row.type = NK_LAYOUT_DYNAMIC_ROW; |
| 17750 |
else layout->row.type = NK_LAYOUT_STATIC_ROW; |
| 17751 |
|
| 17752 |
layout->row.ratio = 0; |
| 17753 |
layout->row.filled = 0; |
| 17754 |
layout->row.item_width = 0; |
| 17755 |
layout->row.item_offset = 0; |
| 17756 |
layout->row.columns = cols; |
| 17757 |
} |
| 17758 |
NK_API void |
| 17759 |
nk_layout_row_push(struct nk_context *ctx, float ratio_or_width) |
| 17760 |
{ |
| 17761 |
struct nk_window *win; |
| 17762 |
struct nk_panel *layout; |
| 17763 |
|
| 17764 |
NK_ASSERT(ctx); |
| 17765 |
NK_ASSERT(ctx->current); |
| 17766 |
NK_ASSERT(ctx->current->layout); |
| 17767 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17768 |
return; |
| 17769 |
|
| 17770 |
win = ctx->current; |
| 17771 |
layout = win->layout; |
| 17772 |
NK_ASSERT(layout->row.type == NK_LAYOUT_STATIC_ROW || layout->row.type == NK_LAYOUT_DYNAMIC_ROW); |
| 17773 |
if (layout->row.type != NK_LAYOUT_STATIC_ROW && layout->row.type != NK_LAYOUT_DYNAMIC_ROW) |
| 17774 |
return; |
| 17775 |
|
| 17776 |
if (layout->row.type == NK_LAYOUT_DYNAMIC_ROW) { |
| 17777 |
float ratio = ratio_or_width; |
| 17778 |
if ((ratio + layout->row.filled) > 1.0f) return; |
| 17779 |
if (ratio > 0.0f) |
| 17780 |
layout->row.item_width = NK_SATURATE(ratio); |
| 17781 |
else layout->row.item_width = 1.0f - layout->row.filled; |
| 17782 |
} else layout->row.item_width = ratio_or_width; |
| 17783 |
} |
| 17784 |
NK_API void |
| 17785 |
nk_layout_row_end(struct nk_context *ctx) |
| 17786 |
{ |
| 17787 |
struct nk_window *win; |
| 17788 |
struct nk_panel *layout; |
| 17789 |
|
| 17790 |
NK_ASSERT(ctx); |
| 17791 |
NK_ASSERT(ctx->current); |
| 17792 |
NK_ASSERT(ctx->current->layout); |
| 17793 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17794 |
return; |
| 17795 |
|
| 17796 |
win = ctx->current; |
| 17797 |
layout = win->layout; |
| 17798 |
NK_ASSERT(layout->row.type == NK_LAYOUT_STATIC_ROW || layout->row.type == NK_LAYOUT_DYNAMIC_ROW); |
| 17799 |
if (layout->row.type != NK_LAYOUT_STATIC_ROW && layout->row.type != NK_LAYOUT_DYNAMIC_ROW) |
| 17800 |
return; |
| 17801 |
layout->row.item_width = 0; |
| 17802 |
layout->row.item_offset = 0; |
| 17803 |
} |
| 17804 |
NK_API void |
| 17805 |
nk_layout_row(struct nk_context *ctx, enum nk_layout_format fmt, |
| 17806 |
float height, int cols, const float *ratio) |
| 17807 |
{ |
| 17808 |
int i; |
| 17809 |
int n_undef = 0; |
| 17810 |
struct nk_window *win; |
| 17811 |
struct nk_panel *layout; |
| 17812 |
|
| 17813 |
NK_ASSERT(ctx); |
| 17814 |
NK_ASSERT(ctx->current); |
| 17815 |
NK_ASSERT(ctx->current->layout); |
| 17816 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17817 |
return; |
| 17818 |
|
| 17819 |
win = ctx->current; |
| 17820 |
layout = win->layout; |
| 17821 |
nk_panel_layout(ctx, win, height, cols); |
| 17822 |
if (fmt == NK_DYNAMIC) { |
| 17823 |
|
| 17824 |
float r = 0; |
| 17825 |
layout->row.ratio = ratio; |
| 17826 |
for (i = 0; i < cols; ++i) { |
| 17827 |
if (ratio[i] < 0.0f) |
| 17828 |
n_undef++; |
| 17829 |
else r += ratio[i]; |
| 17830 |
} |
| 17831 |
r = NK_SATURATE(1.0f - r); |
| 17832 |
layout->row.type = NK_LAYOUT_DYNAMIC; |
| 17833 |
layout->row.item_width = (r > 0 && n_undef > 0) ? (r / (float)n_undef):0; |
| 17834 |
} else { |
| 17835 |
layout->row.ratio = ratio; |
| 17836 |
layout->row.type = NK_LAYOUT_STATIC; |
| 17837 |
layout->row.item_width = 0; |
| 17838 |
layout->row.item_offset = 0; |
| 17839 |
} |
| 17840 |
layout->row.item_offset = 0; |
| 17841 |
layout->row.filled = 0; |
| 17842 |
} |
| 17843 |
NK_API void |
| 17844 |
nk_layout_row_template_begin(struct nk_context *ctx, float height) |
| 17845 |
{ |
| 17846 |
struct nk_window *win; |
| 17847 |
struct nk_panel *layout; |
| 17848 |
|
| 17849 |
NK_ASSERT(ctx); |
| 17850 |
NK_ASSERT(ctx->current); |
| 17851 |
NK_ASSERT(ctx->current->layout); |
| 17852 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17853 |
return; |
| 17854 |
|
| 17855 |
win = ctx->current; |
| 17856 |
layout = win->layout; |
| 17857 |
nk_panel_layout(ctx, win, height, 1); |
| 17858 |
layout->row.type = NK_LAYOUT_TEMPLATE; |
| 17859 |
layout->row.columns = 0; |
| 17860 |
layout->row.ratio = 0; |
| 17861 |
layout->row.item_width = 0; |
| 17862 |
layout->row.item_height = 0; |
| 17863 |
layout->row.item_offset = 0; |
| 17864 |
layout->row.filled = 0; |
| 17865 |
layout->row.item.x = 0; |
| 17866 |
layout->row.item.y = 0; |
| 17867 |
layout->row.item.w = 0; |
| 17868 |
layout->row.item.h = 0; |
| 17869 |
} |
| 17870 |
NK_API void |
| 17871 |
nk_layout_row_template_push_dynamic(struct nk_context *ctx) |
| 17872 |
{ |
| 17873 |
struct nk_window *win; |
| 17874 |
struct nk_panel *layout; |
| 17875 |
|
| 17876 |
NK_ASSERT(ctx); |
| 17877 |
NK_ASSERT(ctx->current); |
| 17878 |
NK_ASSERT(ctx->current->layout); |
| 17879 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17880 |
return; |
| 17881 |
|
| 17882 |
win = ctx->current; |
| 17883 |
layout = win->layout; |
| 17884 |
NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE); |
| 17885 |
NK_ASSERT(layout->row.columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS); |
| 17886 |
if (layout->row.type != NK_LAYOUT_TEMPLATE) return; |
| 17887 |
if (layout->row.columns >= NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS) return; |
| 17888 |
layout->row.templates[layout->row.columns++] = -1.0f; |
| 17889 |
} |
| 17890 |
NK_API void |
| 17891 |
nk_layout_row_template_push_variable(struct nk_context *ctx, float min_width) |
| 17892 |
{ |
| 17893 |
struct nk_window *win; |
| 17894 |
struct nk_panel *layout; |
| 17895 |
|
| 17896 |
NK_ASSERT(ctx); |
| 17897 |
NK_ASSERT(ctx->current); |
| 17898 |
NK_ASSERT(ctx->current->layout); |
| 17899 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17900 |
return; |
| 17901 |
|
| 17902 |
win = ctx->current; |
| 17903 |
layout = win->layout; |
| 17904 |
NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE); |
| 17905 |
NK_ASSERT(layout->row.columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS); |
| 17906 |
if (layout->row.type != NK_LAYOUT_TEMPLATE) return; |
| 17907 |
if (layout->row.columns >= NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS) return; |
| 17908 |
layout->row.templates[layout->row.columns++] = -min_width; |
| 17909 |
} |
| 17910 |
NK_API void |
| 17911 |
nk_layout_row_template_push_static(struct nk_context *ctx, float width) |
| 17912 |
{ |
| 17913 |
struct nk_window *win; |
| 17914 |
struct nk_panel *layout; |
| 17915 |
|
| 17916 |
NK_ASSERT(ctx); |
| 17917 |
NK_ASSERT(ctx->current); |
| 17918 |
NK_ASSERT(ctx->current->layout); |
| 17919 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17920 |
return; |
| 17921 |
|
| 17922 |
win = ctx->current; |
| 17923 |
layout = win->layout; |
| 17924 |
NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE); |
| 17925 |
NK_ASSERT(layout->row.columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS); |
| 17926 |
if (layout->row.type != NK_LAYOUT_TEMPLATE) return; |
| 17927 |
if (layout->row.columns >= NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS) return; |
| 17928 |
layout->row.templates[layout->row.columns++] = width; |
| 17929 |
} |
| 17930 |
NK_API void |
| 17931 |
nk_layout_row_template_end(struct nk_context *ctx) |
| 17932 |
{ |
| 17933 |
struct nk_window *win; |
| 17934 |
struct nk_panel *layout; |
| 17935 |
|
| 17936 |
int i = 0; |
| 17937 |
int variable_count = 0; |
| 17938 |
int min_variable_count = 0; |
| 17939 |
float min_fixed_width = 0.0f; |
| 17940 |
float total_fixed_width = 0.0f; |
| 17941 |
float max_variable_width = 0.0f; |
| 17942 |
|
| 17943 |
NK_ASSERT(ctx); |
| 17944 |
NK_ASSERT(ctx->current); |
| 17945 |
NK_ASSERT(ctx->current->layout); |
| 17946 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17947 |
return; |
| 17948 |
|
| 17949 |
win = ctx->current; |
| 17950 |
layout = win->layout; |
| 17951 |
NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE); |
| 17952 |
if (layout->row.type != NK_LAYOUT_TEMPLATE) return; |
| 17953 |
for (i = 0; i < layout->row.columns; ++i) { |
| 17954 |
float width = layout->row.templates[i]; |
| 17955 |
if (width >= 0.0f) { |
| 17956 |
total_fixed_width += width; |
| 17957 |
min_fixed_width += width; |
| 17958 |
} else if (width < -1.0f) { |
| 17959 |
width = -width; |
| 17960 |
total_fixed_width += width; |
| 17961 |
max_variable_width = NK_MAX(max_variable_width, width); |
| 17962 |
variable_count++; |
| 17963 |
} else { |
| 17964 |
min_variable_count++; |
| 17965 |
variable_count++; |
| 17966 |
} |
| 17967 |
} |
| 17968 |
if (variable_count) { |
| 17969 |
float space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type, |
| 17970 |
layout->bounds.w, layout->row.columns); |
| 17971 |
float var_width = (NK_MAX(space-min_fixed_width,0.0f)) / (float)variable_count; |
| 17972 |
int enough_space = var_width >= max_variable_width; |
| 17973 |
if (!enough_space) |
| 17974 |
var_width = (NK_MAX(space-total_fixed_width,0)) / (float)min_variable_count; |
| 17975 |
for (i = 0; i < layout->row.columns; ++i) { |
| 17976 |
float *width = &layout->row.templates[i]; |
| 17977 |
*width = (*width >= 0.0f)? *width: (*width < -1.0f && !enough_space)? -(*width): var_width; |
| 17978 |
} |
| 17979 |
} |
| 17980 |
} |
| 17981 |
NK_API void |
| 17982 |
nk_layout_space_begin(struct nk_context *ctx, enum nk_layout_format fmt, |
| 17983 |
float height, int widget_count) |
| 17984 |
{ |
| 17985 |
struct nk_window *win; |
| 17986 |
struct nk_panel *layout; |
| 17987 |
|
| 17988 |
NK_ASSERT(ctx); |
| 17989 |
NK_ASSERT(ctx->current); |
| 17990 |
NK_ASSERT(ctx->current->layout); |
| 17991 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 17992 |
return; |
| 17993 |
|
| 17994 |
win = ctx->current; |
| 17995 |
layout = win->layout; |
| 17996 |
nk_panel_layout(ctx, win, height, widget_count); |
| 17997 |
if (fmt == NK_STATIC) |
| 17998 |
layout->row.type = NK_LAYOUT_STATIC_FREE; |
| 17999 |
else layout->row.type = NK_LAYOUT_DYNAMIC_FREE; |
| 18000 |
|
| 18001 |
layout->row.ratio = 0; |
| 18002 |
layout->row.filled = 0; |
| 18003 |
layout->row.item_width = 0; |
| 18004 |
layout->row.item_offset = 0; |
| 18005 |
} |
| 18006 |
NK_API void |
| 18007 |
nk_layout_space_end(struct nk_context *ctx) |
| 18008 |
{ |
| 18009 |
struct nk_window *win; |
| 18010 |
struct nk_panel *layout; |
| 18011 |
|
| 18012 |
NK_ASSERT(ctx); |
| 18013 |
NK_ASSERT(ctx->current); |
| 18014 |
NK_ASSERT(ctx->current->layout); |
| 18015 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 18016 |
return; |
| 18017 |
|
| 18018 |
win = ctx->current; |
| 18019 |
layout = win->layout; |
| 18020 |
layout->row.item_width = 0; |
| 18021 |
layout->row.item_height = 0; |
| 18022 |
layout->row.item_offset = 0; |
| 18023 |
nk_zero(&layout->row.item, sizeof(layout->row.item)); |
| 18024 |
} |
| 18025 |
NK_API void |
| 18026 |
nk_layout_space_push(struct nk_context *ctx, struct nk_rect rect) |
| 18027 |
{ |
| 18028 |
struct nk_window *win; |
| 18029 |
struct nk_panel *layout; |
| 18030 |
|
| 18031 |
NK_ASSERT(ctx); |
| 18032 |
NK_ASSERT(ctx->current); |
| 18033 |
NK_ASSERT(ctx->current->layout); |
| 18034 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 18035 |
return; |
| 18036 |
|
| 18037 |
win = ctx->current; |
| 18038 |
layout = win->layout; |
| 18039 |
layout->row.item = rect; |
| 18040 |
} |
| 18041 |
NK_API struct nk_rect |
| 18042 |
nk_layout_space_bounds(struct nk_context *ctx) |
| 18043 |
{ |
| 18044 |
struct nk_rect ret; |
| 18045 |
struct nk_window *win; |
| 18046 |
struct nk_panel *layout; |
| 18047 |
|
| 18048 |
NK_ASSERT(ctx); |
| 18049 |
NK_ASSERT(ctx->current); |
| 18050 |
NK_ASSERT(ctx->current->layout); |
| 18051 |
win = ctx->current; |
| 18052 |
layout = win->layout; |
| 18053 |
|
| 18054 |
ret.x = layout->clip.x; |
| 18055 |
ret.y = layout->clip.y; |
| 18056 |
ret.w = layout->clip.w; |
| 18057 |
ret.h = layout->row.height; |
| 18058 |
return ret; |
| 18059 |
} |
| 18060 |
NK_API struct nk_rect |
| 18061 |
nk_layout_widget_bounds(struct nk_context *ctx) |
| 18062 |
{ |
| 18063 |
struct nk_rect ret; |
| 18064 |
struct nk_window *win; |
| 18065 |
struct nk_panel *layout; |
| 18066 |
|
| 18067 |
NK_ASSERT(ctx); |
| 18068 |
NK_ASSERT(ctx->current); |
| 18069 |
NK_ASSERT(ctx->current->layout); |
| 18070 |
win = ctx->current; |
| 18071 |
layout = win->layout; |
| 18072 |
|
| 18073 |
ret.x = layout->at_x; |
| 18074 |
ret.y = layout->at_y; |
| 18075 |
ret.w = layout->bounds.w - NK_MAX(layout->at_x - layout->bounds.x,0); |
| 18076 |
ret.h = layout->row.height; |
| 18077 |
return ret; |
| 18078 |
} |
| 18079 |
NK_API struct nk_vec2 |
| 18080 |
nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret) |
| 18081 |
{ |
| 18082 |
struct nk_window *win; |
| 18083 |
struct nk_panel *layout; |
| 18084 |
|
| 18085 |
NK_ASSERT(ctx); |
| 18086 |
NK_ASSERT(ctx->current); |
| 18087 |
NK_ASSERT(ctx->current->layout); |
| 18088 |
win = ctx->current; |
| 18089 |
layout = win->layout; |
| 18090 |
|
| 18091 |
ret.x += layout->at_x - (float)*layout->offset_x; |
| 18092 |
ret.y += layout->at_y - (float)*layout->offset_y; |
| 18093 |
return ret; |
| 18094 |
} |
| 18095 |
NK_API struct nk_vec2 |
| 18096 |
nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret) |
| 18097 |
{ |
| 18098 |
struct nk_window *win; |
| 18099 |
struct nk_panel *layout; |
| 18100 |
|
| 18101 |
NK_ASSERT(ctx); |
| 18102 |
NK_ASSERT(ctx->current); |
| 18103 |
NK_ASSERT(ctx->current->layout); |
| 18104 |
win = ctx->current; |
| 18105 |
layout = win->layout; |
| 18106 |
|
| 18107 |
ret.x += -layout->at_x + (float)*layout->offset_x; |
| 18108 |
ret.y += -layout->at_y + (float)*layout->offset_y; |
| 18109 |
return ret; |
| 18110 |
} |
| 18111 |
NK_API struct nk_rect |
| 18112 |
nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret) |
| 18113 |
{ |
| 18114 |
struct nk_window *win; |
| 18115 |
struct nk_panel *layout; |
| 18116 |
|
| 18117 |
NK_ASSERT(ctx); |
| 18118 |
NK_ASSERT(ctx->current); |
| 18119 |
NK_ASSERT(ctx->current->layout); |
| 18120 |
win = ctx->current; |
| 18121 |
layout = win->layout; |
| 18122 |
|
| 18123 |
ret.x += layout->at_x - (float)*layout->offset_x; |
| 18124 |
ret.y += layout->at_y - (float)*layout->offset_y; |
| 18125 |
return ret; |
| 18126 |
} |
| 18127 |
NK_API struct nk_rect |
| 18128 |
nk_layout_space_rect_to_local(struct nk_context *ctx, struct nk_rect ret) |
| 18129 |
{ |
| 18130 |
struct nk_window *win; |
| 18131 |
struct nk_panel *layout; |
| 18132 |
|
| 18133 |
NK_ASSERT(ctx); |
| 18134 |
NK_ASSERT(ctx->current); |
| 18135 |
NK_ASSERT(ctx->current->layout); |
| 18136 |
win = ctx->current; |
| 18137 |
layout = win->layout; |
| 18138 |
|
| 18139 |
ret.x += -layout->at_x + (float)*layout->offset_x; |
| 18140 |
ret.y += -layout->at_y + (float)*layout->offset_y; |
| 18141 |
return ret; |
| 18142 |
} |
| 18143 |
NK_LIB void |
| 18144 |
nk_panel_alloc_row(const struct nk_context *ctx, struct nk_window *win) |
| 18145 |
{ |
| 18146 |
struct nk_panel *layout = win->layout; |
| 18147 |
struct nk_vec2 spacing = ctx->style.window.spacing; |
| 18148 |
const float row_height = layout->row.height - spacing.y; |
| 18149 |
nk_panel_layout(ctx, win, row_height, layout->row.columns); |
| 18150 |
} |
| 18151 |
NK_LIB void |
| 18152 |
nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, |
| 18153 |
struct nk_window *win, int modify) |
| 18154 |
{ |
| 18155 |
struct nk_panel *layout; |
| 18156 |
const struct nk_style *style; |
| 18157 |
|
| 18158 |
struct nk_vec2 spacing; |
| 18159 |
struct nk_vec2 padding; |
| 18160 |
|
| 18161 |
float item_offset = 0; |
| 18162 |
float item_width = 0; |
| 18163 |
float item_spacing = 0; |
| 18164 |
float panel_space = 0; |
| 18165 |
|
| 18166 |
NK_ASSERT(ctx); |
| 18167 |
NK_ASSERT(ctx->current); |
| 18168 |
NK_ASSERT(ctx->current->layout); |
| 18169 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 18170 |
return; |
| 18171 |
|
| 18172 |
win = ctx->current; |
| 18173 |
layout = win->layout; |
| 18174 |
style = &ctx->style; |
| 18175 |
NK_ASSERT(bounds); |
| 18176 |
|
| 18177 |
spacing = style->window.spacing; |
| 18178 |
padding = nk_panel_get_padding(style, layout->type); |
| 18179 |
panel_space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type, |
| 18180 |
layout->bounds.w, layout->row.columns); |
| 18181 |
|
| 18182 |
#define NK_FRAC(x) (x - (int)x) |
| 18183 |
|
| 18184 |
switch (layout->row.type) { |
| 18185 |
case NK_LAYOUT_DYNAMIC_FIXED: { |
| 18186 |
|
| 18187 |
float w = NK_MAX(1.0f,panel_space) / (float)layout->row.columns; |
| 18188 |
item_offset = (float)layout->row.index * w; |
| 18189 |
item_width = w + NK_FRAC(item_offset); |
| 18190 |
item_spacing = (float)layout->row.index * spacing.x; |
| 18191 |
} break; |
| 18192 |
case NK_LAYOUT_DYNAMIC_ROW: { |
| 18193 |
|
| 18194 |
float w = layout->row.item_width * panel_space; |
| 18195 |
item_offset = layout->row.item_offset; |
| 18196 |
item_width = w + NK_FRAC(item_offset); |
| 18197 |
item_spacing = 0; |
| 18198 |
|
| 18199 |
if (modify) { |
| 18200 |
layout->row.item_offset += w + spacing.x; |
| 18201 |
layout->row.filled += layout->row.item_width; |
| 18202 |
layout->row.index = 0; |
| 18203 |
} |
| 18204 |
} break; |
| 18205 |
case NK_LAYOUT_DYNAMIC_FREE: { |
| 18206 |
|
| 18207 |
bounds->x = layout->at_x + (layout->bounds.w * layout->row.item.x); |
| 18208 |
bounds->x -= (float)*layout->offset_x; |
| 18209 |
bounds->y = layout->at_y + (layout->row.height * layout->row.item.y); |
| 18210 |
bounds->y -= (float)*layout->offset_y; |
| 18211 |
bounds->w = layout->bounds.w * layout->row.item.w + NK_FRAC(bounds->x); |
| 18212 |
bounds->h = layout->row.height * layout->row.item.h + NK_FRAC(bounds->y); |
| 18213 |
return; |
| 18214 |
} |
| 18215 |
case NK_LAYOUT_DYNAMIC: { |
| 18216 |
|
| 18217 |
float ratio, w; |
| 18218 |
NK_ASSERT(layout->row.ratio); |
| 18219 |
ratio = (layout->row.ratio[layout->row.index] < 0) ? |
| 18220 |
layout->row.item_width : layout->row.ratio[layout->row.index]; |
| 18221 |
|
| 18222 |
w = (ratio * panel_space); |
| 18223 |
item_spacing = (float)layout->row.index * spacing.x; |
| 18224 |
item_offset = layout->row.item_offset; |
| 18225 |
item_width = w + NK_FRAC(item_offset); |
| 18226 |
|
| 18227 |
if (modify) { |
| 18228 |
layout->row.item_offset += w; |
| 18229 |
layout->row.filled += ratio; |
| 18230 |
} |
| 18231 |
} break; |
| 18232 |
case NK_LAYOUT_STATIC_FIXED: { |
| 18233 |
|
| 18234 |
item_width = layout->row.item_width; |
| 18235 |
item_offset = (float)layout->row.index * item_width; |
| 18236 |
item_spacing = (float)layout->row.index * spacing.x; |
| 18237 |
} break; |
| 18238 |
case NK_LAYOUT_STATIC_ROW: { |
| 18239 |
|
| 18240 |
item_width = layout->row.item_width; |
| 18241 |
item_offset = layout->row.item_offset; |
| 18242 |
item_spacing = (float)layout->row.index * spacing.x; |
| 18243 |
if (modify) layout->row.item_offset += item_width; |
| 18244 |
} break; |
| 18245 |
case NK_LAYOUT_STATIC_FREE: { |
| 18246 |
|
| 18247 |
bounds->x = layout->at_x + layout->row.item.x; |
| 18248 |
bounds->w = layout->row.item.w; |
| 18249 |
if (((bounds->x + bounds->w) > layout->max_x) && modify) |
| 18250 |
layout->max_x = (bounds->x + bounds->w); |
| 18251 |
bounds->x -= (float)*layout->offset_x; |
| 18252 |
bounds->y = layout->at_y + layout->row.item.y; |
| 18253 |
bounds->y -= (float)*layout->offset_y; |
| 18254 |
bounds->h = layout->row.item.h; |
| 18255 |
return; |
| 18256 |
} |
| 18257 |
case NK_LAYOUT_STATIC: { |
| 18258 |
|
| 18259 |
item_spacing = (float)layout->row.index * spacing.x; |
| 18260 |
item_width = layout->row.ratio[layout->row.index]; |
| 18261 |
item_offset = layout->row.item_offset; |
| 18262 |
if (modify) layout->row.item_offset += item_width; |
| 18263 |
} break; |
| 18264 |
case NK_LAYOUT_TEMPLATE: { |
| 18265 |
|
| 18266 |
float w; |
| 18267 |
NK_ASSERT(layout->row.index < layout->row.columns); |
| 18268 |
NK_ASSERT(layout->row.index < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS); |
| 18269 |
w = layout->row.templates[layout->row.index]; |
| 18270 |
item_offset = layout->row.item_offset; |
| 18271 |
item_width = w + NK_FRAC(item_offset); |
| 18272 |
item_spacing = (float)layout->row.index * spacing.x; |
| 18273 |
if (modify) layout->row.item_offset += w; |
| 18274 |
} break; |
| 18275 |
#undef NK_FRAC |
| 18276 |
default: NK_ASSERT(0); break; |
| 18277 |
}; |
| 18278 |
|
| 18279 |
|
| 18280 |
bounds->w = item_width; |
| 18281 |
bounds->h = layout->row.height - spacing.y; |
| 18282 |
bounds->y = layout->at_y - (float)*layout->offset_y; |
| 18283 |
bounds->x = layout->at_x + item_offset + item_spacing + padding.x; |
| 18284 |
if (((bounds->x + bounds->w) > layout->max_x) && modify) |
| 18285 |
layout->max_x = bounds->x + bounds->w; |
| 18286 |
bounds->x -= (float)*layout->offset_x; |
| 18287 |
} |
| 18288 |
NK_LIB void |
| 18289 |
nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx) |
| 18290 |
{ |
| 18291 |
struct nk_window *win; |
| 18292 |
struct nk_panel *layout; |
| 18293 |
|
| 18294 |
NK_ASSERT(ctx); |
| 18295 |
NK_ASSERT(ctx->current); |
| 18296 |
NK_ASSERT(ctx->current->layout); |
| 18297 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 18298 |
return; |
| 18299 |
|
| 18300 |
|
| 18301 |
win = ctx->current; |
| 18302 |
layout = win->layout; |
| 18303 |
if (layout->row.index >= layout->row.columns) |
| 18304 |
nk_panel_alloc_row(ctx, win); |
| 18305 |
|
| 18306 |
|
| 18307 |
nk_layout_widget_space(bounds, ctx, win, nk_true); |
| 18308 |
layout->row.index++; |
| 18309 |
} |
| 18310 |
NK_LIB void |
| 18311 |
nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx) |
| 18312 |
{ |
| 18313 |
float y; |
| 18314 |
int index; |
| 18315 |
struct nk_window *win; |
| 18316 |
struct nk_panel *layout; |
| 18317 |
|
| 18318 |
NK_ASSERT(ctx); |
| 18319 |
NK_ASSERT(ctx->current); |
| 18320 |
NK_ASSERT(ctx->current->layout); |
| 18321 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 18322 |
return; |
| 18323 |
|
| 18324 |
win = ctx->current; |
| 18325 |
layout = win->layout; |
| 18326 |
y = layout->at_y; |
| 18327 |
index = layout->row.index; |
| 18328 |
if (layout->row.index >= layout->row.columns) { |
| 18329 |
layout->at_y += layout->row.height; |
| 18330 |
layout->row.index = 0; |
| 18331 |
} |
| 18332 |
nk_layout_widget_space(bounds, ctx, win, nk_false); |
| 18333 |
if (!layout->row.index) { |
| 18334 |
bounds->x -= layout->row.item_offset; |
| 18335 |
} |
| 18336 |
layout->at_y = y; |
| 18337 |
layout->row.index = index; |
| 18338 |
} |
| 18339 |
|
| 18340 |
|
| 18341 |
|
| 18342 |
|
| 18343 |
|
| 18344 |
|
| 18345 |
|
| 18346 |
|
| 18347 |
|
| 18348 |
|
| 18349 |
NK_INTERN int |
| 18350 |
nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, |
| 18351 |
struct nk_image *img, const char *title, enum nk_collapse_states *state) |
| 18352 |
{ |
| 18353 |
struct nk_window *win; |
| 18354 |
struct nk_panel *layout; |
| 18355 |
const struct nk_style *style; |
| 18356 |
struct nk_command_buffer *out; |
| 18357 |
const struct nk_input *in; |
| 18358 |
const struct nk_style_button *button; |
| 18359 |
enum nk_symbol_type symbol; |
| 18360 |
float row_height; |
| 18361 |
|
| 18362 |
struct nk_vec2 item_spacing; |
| 18363 |
struct nk_rect header = {0,0,0,0}; |
| 18364 |
struct nk_rect sym = {0,0,0,0}; |
| 18365 |
struct nk_text text; |
| 18366 |
|
| 18367 |
nk_flags ws = 0; |
| 18368 |
enum nk_widget_layout_states widget_state; |
| 18369 |
|
| 18370 |
NK_ASSERT(ctx); |
| 18371 |
NK_ASSERT(ctx->current); |
| 18372 |
NK_ASSERT(ctx->current->layout); |
| 18373 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 18374 |
return 0; |
| 18375 |
|
| 18376 |
|
| 18377 |
win = ctx->current; |
| 18378 |
layout = win->layout; |
| 18379 |
out = &win->buffer; |
| 18380 |
style = &ctx->style; |
| 18381 |
item_spacing = style->window.spacing; |
| 18382 |
|
| 18383 |
|
| 18384 |
row_height = style->font->height + 2 * style->tab.padding.y; |
| 18385 |
nk_layout_set_min_row_height(ctx, row_height); |
| 18386 |
nk_layout_row_dynamic(ctx, row_height, 1); |
| 18387 |
nk_layout_reset_min_row_height(ctx); |
| 18388 |
|
| 18389 |
widget_state = nk_widget(&header, ctx); |
| 18390 |
if (type == NK_TREE_TAB) { |
| 18391 |
const struct nk_style_item *background = &style->tab.background; |
| 18392 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 18393 |
nk_draw_image(out, header, &background->data.image, nk_white); |
| 18394 |
text.background = nk_rgba(0,0,0,0); |
| 18395 |
} else { |
| 18396 |
text.background = background->data.color; |
| 18397 |
nk_fill_rect(out, header, 0, style->tab.border_color); |
| 18398 |
nk_fill_rect(out, nk_shrink_rect(header, style->tab.border), |
| 18399 |
style->tab.rounding, background->data.color); |
| 18400 |
} |
| 18401 |
} else text.background = style->window.background; |
| 18402 |
|
| 18403 |
|
| 18404 |
in = (!(layout->flags & NK_WINDOW_ROM)) ? &ctx->input: 0; |
| 18405 |
in = (in && widget_state == NK_WIDGET_VALID) ? &ctx->input : 0; |
| 18406 |
if (nk_button_behavior(&ws, header, in, NK_BUTTON_DEFAULT)) |
| 18407 |
*state = (*state == NK_MAXIMIZED) ? NK_MINIMIZED : NK_MAXIMIZED; |
| 18408 |
|
| 18409 |
|
| 18410 |
if (*state == NK_MAXIMIZED) { |
| 18411 |
symbol = style->tab.sym_maximize; |
| 18412 |
if (type == NK_TREE_TAB) |
| 18413 |
button = &style->tab.tab_maximize_button; |
| 18414 |
else button = &style->tab.node_maximize_button; |
| 18415 |
} else { |
| 18416 |
symbol = style->tab.sym_minimize; |
| 18417 |
if (type == NK_TREE_TAB) |
| 18418 |
button = &style->tab.tab_minimize_button; |
| 18419 |
else button = &style->tab.node_minimize_button; |
| 18420 |
} |
| 18421 |
|
| 18422 |
{ |
| 18423 |
sym.w = sym.h = style->font->height; |
| 18424 |
sym.y = header.y + style->tab.padding.y; |
| 18425 |
sym.x = header.x + style->tab.padding.x; |
| 18426 |
nk_do_button_symbol(&ws, &win->buffer, sym, symbol, NK_BUTTON_DEFAULT, |
| 18427 |
button, 0, style->font); |
| 18428 |
|
| 18429 |
if (img) { |
| 18430 |
|
| 18431 |
sym.x = sym.x + sym.w + 4 * item_spacing.x; |
| 18432 |
nk_draw_image(&win->buffer, sym, img, nk_white); |
| 18433 |
sym.w = style->font->height + style->tab.spacing.x;} |
| 18434 |
} |
| 18435 |
|
| 18436 |
{ |
| 18437 |
struct nk_rect label; |
| 18438 |
header.w = NK_MAX(header.w, sym.w + item_spacing.x); |
| 18439 |
label.x = sym.x + sym.w + item_spacing.x; |
| 18440 |
label.y = sym.y; |
| 18441 |
label.w = header.w - (sym.w + item_spacing.y + style->tab.indent); |
| 18442 |
label.h = style->font->height; |
| 18443 |
text.text = style->tab.text; |
| 18444 |
text.padding = nk_vec2(0,0); |
| 18445 |
nk_widget_text(out, label, title, nk_strlen(title), &text, |
| 18446 |
NK_TEXT_LEFT, style->font);} |
| 18447 |
|
| 18448 |
|
| 18449 |
if (*state == NK_MAXIMIZED) { |
| 18450 |
layout->at_x = header.x + (float)*layout->offset_x + style->tab.indent; |
| 18451 |
layout->bounds.w = NK_MAX(layout->bounds.w, style->tab.indent); |
| 18452 |
layout->bounds.w -= (style->tab.indent + style->window.padding.x); |
| 18453 |
layout->row.tree_depth++; |
| 18454 |
return nk_true; |
| 18455 |
} else return nk_false; |
| 18456 |
} |
| 18457 |
NK_INTERN int |
| 18458 |
nk_tree_base(struct nk_context *ctx, enum nk_tree_type type, |
| 18459 |
struct nk_image *img, const char *title, enum nk_collapse_states initial_state, |
| 18460 |
const char *hash, int len, int line) |
| 18461 |
{ |
| 18462 |
struct nk_window *win = ctx->current; |
| 18463 |
int title_len = 0; |
| 18464 |
nk_hash tree_hash = 0; |
| 18465 |
nk_uint *state = 0; |
| 18466 |
|
| 18467 |
|
| 18468 |
if (!hash) { |
| 18469 |
title_len = (int)nk_strlen(title); |
| 18470 |
tree_hash = nk_murmur_hash(title, (int)title_len, (nk_hash)line); |
| 18471 |
} else tree_hash = nk_murmur_hash(hash, len, (nk_hash)line); |
| 18472 |
state = nk_find_value(win, tree_hash); |
| 18473 |
if (!state) { |
| 18474 |
state = nk_add_value(ctx, win, tree_hash, 0); |
| 18475 |
*state = initial_state; |
| 18476 |
} |
| 18477 |
return nk_tree_state_base(ctx, type, img, title, (enum nk_collapse_states*)state); |
| 18478 |
} |
| 18479 |
NK_API int |
| 18480 |
nk_tree_state_push(struct nk_context *ctx, enum nk_tree_type type, |
| 18481 |
const char *title, enum nk_collapse_states *state) |
| 18482 |
{ |
| 18483 |
return nk_tree_state_base(ctx, type, 0, title, state); |
| 18484 |
} |
| 18485 |
NK_API int |
| 18486 |
nk_tree_state_image_push(struct nk_context *ctx, enum nk_tree_type type, |
| 18487 |
struct nk_image img, const char *title, enum nk_collapse_states *state) |
| 18488 |
{ |
| 18489 |
return nk_tree_state_base(ctx, type, &img, title, state); |
| 18490 |
} |
| 18491 |
NK_API void |
| 18492 |
nk_tree_state_pop(struct nk_context *ctx) |
| 18493 |
{ |
| 18494 |
struct nk_window *win = 0; |
| 18495 |
struct nk_panel *layout = 0; |
| 18496 |
|
| 18497 |
NK_ASSERT(ctx); |
| 18498 |
NK_ASSERT(ctx->current); |
| 18499 |
NK_ASSERT(ctx->current->layout); |
| 18500 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 18501 |
return; |
| 18502 |
|
| 18503 |
win = ctx->current; |
| 18504 |
layout = win->layout; |
| 18505 |
layout->at_x -= ctx->style.tab.indent + ctx->style.window.padding.x; |
| 18506 |
layout->bounds.w += ctx->style.tab.indent + ctx->style.window.padding.x; |
| 18507 |
NK_ASSERT(layout->row.tree_depth); |
| 18508 |
layout->row.tree_depth--; |
| 18509 |
} |
| 18510 |
NK_API int |
| 18511 |
nk_tree_push_hashed(struct nk_context *ctx, enum nk_tree_type type, |
| 18512 |
const char *title, enum nk_collapse_states initial_state, |
| 18513 |
const char *hash, int len, int line) |
| 18514 |
{ |
| 18515 |
return nk_tree_base(ctx, type, 0, title, initial_state, hash, len, line); |
| 18516 |
} |
| 18517 |
NK_API int |
| 18518 |
nk_tree_image_push_hashed(struct nk_context *ctx, enum nk_tree_type type, |
| 18519 |
struct nk_image img, const char *title, enum nk_collapse_states initial_state, |
| 18520 |
const char *hash, int len,int seed) |
| 18521 |
{ |
| 18522 |
return nk_tree_base(ctx, type, &img, title, initial_state, hash, len, seed); |
| 18523 |
} |
| 18524 |
NK_API void |
| 18525 |
nk_tree_pop(struct nk_context *ctx) |
| 18526 |
{ |
| 18527 |
nk_tree_state_pop(ctx); |
| 18528 |
} |
| 18529 |
NK_INTERN int |
| 18530 |
nk_tree_element_image_push_hashed_base(struct nk_context *ctx, enum nk_tree_type type, |
| 18531 |
struct nk_image *img, const char *title, int title_len, |
| 18532 |
enum nk_collapse_states *state, int *selected) |
| 18533 |
{ |
| 18534 |
struct nk_window *win; |
| 18535 |
struct nk_panel *layout; |
| 18536 |
const struct nk_style *style; |
| 18537 |
struct nk_command_buffer *out; |
| 18538 |
const struct nk_input *in; |
| 18539 |
const struct nk_style_button *button; |
| 18540 |
enum nk_symbol_type symbol; |
| 18541 |
float row_height; |
| 18542 |
struct nk_vec2 padding; |
| 18543 |
|
| 18544 |
int text_len; |
| 18545 |
float text_width; |
| 18546 |
|
| 18547 |
struct nk_vec2 item_spacing; |
| 18548 |
struct nk_rect header = {0,0,0,0}; |
| 18549 |
struct nk_rect sym = {0,0,0,0}; |
| 18550 |
|
| 18551 |
nk_flags ws = 0; |
| 18552 |
enum nk_widget_layout_states widget_state; |
| 18553 |
|
| 18554 |
NK_ASSERT(ctx); |
| 18555 |
NK_ASSERT(ctx->current); |
| 18556 |
NK_ASSERT(ctx->current->layout); |
| 18557 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 18558 |
return 0; |
| 18559 |
|
| 18560 |
|
| 18561 |
win = ctx->current; |
| 18562 |
layout = win->layout; |
| 18563 |
out = &win->buffer; |
| 18564 |
style = &ctx->style; |
| 18565 |
item_spacing = style->window.spacing; |
| 18566 |
padding = style->selectable.padding; |
| 18567 |
|
| 18568 |
|
| 18569 |
row_height = style->font->height + 2 * style->tab.padding.y; |
| 18570 |
nk_layout_set_min_row_height(ctx, row_height); |
| 18571 |
nk_layout_row_dynamic(ctx, row_height, 1); |
| 18572 |
nk_layout_reset_min_row_height(ctx); |
| 18573 |
|
| 18574 |
widget_state = nk_widget(&header, ctx); |
| 18575 |
if (type == NK_TREE_TAB) { |
| 18576 |
const struct nk_style_item *background = &style->tab.background; |
| 18577 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 18578 |
nk_draw_image(out, header, &background->data.image, nk_white); |
| 18579 |
} else { |
| 18580 |
nk_fill_rect(out, header, 0, style->tab.border_color); |
| 18581 |
nk_fill_rect(out, nk_shrink_rect(header, style->tab.border), |
| 18582 |
style->tab.rounding, background->data.color); |
| 18583 |
} |
| 18584 |
} |
| 18585 |
|
| 18586 |
in = (!(layout->flags & NK_WINDOW_ROM)) ? &ctx->input: 0; |
| 18587 |
in = (in && widget_state == NK_WIDGET_VALID) ? &ctx->input : 0; |
| 18588 |
|
| 18589 |
|
| 18590 |
if (*state == NK_MAXIMIZED) { |
| 18591 |
symbol = style->tab.sym_maximize; |
| 18592 |
if (type == NK_TREE_TAB) |
| 18593 |
button = &style->tab.tab_maximize_button; |
| 18594 |
else button = &style->tab.node_maximize_button; |
| 18595 |
} else { |
| 18596 |
symbol = style->tab.sym_minimize; |
| 18597 |
if (type == NK_TREE_TAB) |
| 18598 |
button = &style->tab.tab_minimize_button; |
| 18599 |
else button = &style->tab.node_minimize_button; |
| 18600 |
} |
| 18601 |
{ |
| 18602 |
sym.w = sym.h = style->font->height; |
| 18603 |
sym.y = header.y + style->tab.padding.y; |
| 18604 |
sym.x = header.x + style->tab.padding.x; |
| 18605 |
if (nk_do_button_symbol(&ws, &win->buffer, sym, symbol, NK_BUTTON_DEFAULT, button, in, style->font)) |
| 18606 |
*state = (*state == NK_MAXIMIZED) ? NK_MINIMIZED : NK_MAXIMIZED;} |
| 18607 |
|
| 18608 |
|
| 18609 |
{nk_flags dummy = 0; |
| 18610 |
struct nk_rect label; |
| 18611 |
|
| 18612 |
text_len = nk_strlen(title); |
| 18613 |
text_width = style->font->width(style->font->userdata, style->font->height, title, text_len); |
| 18614 |
text_width += (4 * padding.x); |
| 18615 |
|
| 18616 |
header.w = NK_MAX(header.w, sym.w + item_spacing.x); |
| 18617 |
label.x = sym.x + sym.w + item_spacing.x; |
| 18618 |
label.y = sym.y; |
| 18619 |
label.w = NK_MIN(header.w - (sym.w + item_spacing.y + style->tab.indent), text_width); |
| 18620 |
label.h = style->font->height; |
| 18621 |
|
| 18622 |
if (img) { |
| 18623 |
nk_do_selectable_image(&dummy, &win->buffer, label, title, title_len, NK_TEXT_LEFT, |
| 18624 |
selected, img, &style->selectable, in, style->font); |
| 18625 |
} else nk_do_selectable(&dummy, &win->buffer, label, title, title_len, NK_TEXT_LEFT, |
| 18626 |
selected, &style->selectable, in, style->font); |
| 18627 |
} |
| 18628 |
|
| 18629 |
if (*state == NK_MAXIMIZED) { |
| 18630 |
layout->at_x = header.x + (float)*layout->offset_x + style->tab.indent; |
| 18631 |
layout->bounds.w = NK_MAX(layout->bounds.w, style->tab.indent); |
| 18632 |
layout->bounds.w -= (style->tab.indent + style->window.padding.x); |
| 18633 |
layout->row.tree_depth++; |
| 18634 |
return nk_true; |
| 18635 |
} else return nk_false; |
| 18636 |
} |
| 18637 |
NK_INTERN int |
| 18638 |
nk_tree_element_base(struct nk_context *ctx, enum nk_tree_type type, |
| 18639 |
struct nk_image *img, const char *title, enum nk_collapse_states initial_state, |
| 18640 |
int *selected, const char *hash, int len, int line) |
| 18641 |
{ |
| 18642 |
struct nk_window *win = ctx->current; |
| 18643 |
int title_len = 0; |
| 18644 |
nk_hash tree_hash = 0; |
| 18645 |
nk_uint *state = 0; |
| 18646 |
|
| 18647 |
|
| 18648 |
if (!hash) { |
| 18649 |
title_len = (int)nk_strlen(title); |
| 18650 |
tree_hash = nk_murmur_hash(title, (int)title_len, (nk_hash)line); |
| 18651 |
} else tree_hash = nk_murmur_hash(hash, len, (nk_hash)line); |
| 18652 |
state = nk_find_value(win, tree_hash); |
| 18653 |
if (!state) { |
| 18654 |
state = nk_add_value(ctx, win, tree_hash, 0); |
| 18655 |
*state = initial_state; |
| 18656 |
} return nk_tree_element_image_push_hashed_base(ctx, type, img, title, |
| 18657 |
nk_strlen(title), (enum nk_collapse_states*)state, selected); |
| 18658 |
} |
| 18659 |
NK_API int |
| 18660 |
nk_tree_element_push_hashed(struct nk_context *ctx, enum nk_tree_type type, |
| 18661 |
const char *title, enum nk_collapse_states initial_state, |
| 18662 |
int *selected, const char *hash, int len, int seed) |
| 18663 |
{ |
| 18664 |
return nk_tree_element_base(ctx, type, 0, title, initial_state, selected, hash, len, seed); |
| 18665 |
} |
| 18666 |
NK_API int |
| 18667 |
nk_tree_element_image_push_hashed(struct nk_context *ctx, enum nk_tree_type type, |
| 18668 |
struct nk_image img, const char *title, enum nk_collapse_states initial_state, |
| 18669 |
int *selected, const char *hash, int len,int seed) |
| 18670 |
{ |
| 18671 |
return nk_tree_element_base(ctx, type, &img, title, initial_state, selected, hash, len, seed); |
| 18672 |
} |
| 18673 |
NK_API void |
| 18674 |
nk_tree_element_pop(struct nk_context *ctx) |
| 18675 |
{ |
| 18676 |
nk_tree_state_pop(ctx); |
| 18677 |
} |
| 18678 |
|
| 18679 |
|
| 18680 |
|
| 18681 |
|
| 18682 |
|
| 18683 |
|
| 18684 |
|
| 18685 |
|
| 18686 |
|
| 18687 |
|
| 18688 |
NK_API int |
| 18689 |
nk_group_scrolled_offset_begin(struct nk_context *ctx, |
| 18690 |
nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags) |
| 18691 |
{ |
| 18692 |
struct nk_rect bounds; |
| 18693 |
struct nk_window panel; |
| 18694 |
struct nk_window *win; |
| 18695 |
|
| 18696 |
win = ctx->current; |
| 18697 |
nk_panel_alloc_space(&bounds, ctx); |
| 18698 |
{const struct nk_rect *c = &win->layout->clip; |
| 18699 |
if (!NK_INTERSECT(c->x, c->y, c->w, c->h, bounds.x, bounds.y, bounds.w, bounds.h) && |
| 18700 |
!(flags & NK_WINDOW_MOVABLE)) { |
| 18701 |
return 0; |
| 18702 |
}} |
| 18703 |
if (win->flags & NK_WINDOW_ROM) |
| 18704 |
flags |= NK_WINDOW_ROM; |
| 18705 |
|
| 18706 |
|
| 18707 |
nk_zero(&panel, sizeof(panel)); |
| 18708 |
panel.bounds = bounds; |
| 18709 |
panel.flags = flags; |
| 18710 |
panel.scrollbar.x = *x_offset; |
| 18711 |
panel.scrollbar.y = *y_offset; |
| 18712 |
panel.buffer = win->buffer; |
| 18713 |
panel.layout = (struct nk_panel*)nk_create_panel(ctx); |
| 18714 |
ctx->current = &panel; |
| 18715 |
nk_panel_begin(ctx, (flags & NK_WINDOW_TITLE) ? title: 0, NK_PANEL_GROUP); |
| 18716 |
|
| 18717 |
win->buffer = panel.buffer; |
| 18718 |
win->buffer.clip = panel.layout->clip; |
| 18719 |
panel.layout->offset_x = x_offset; |
| 18720 |
panel.layout->offset_y = y_offset; |
| 18721 |
panel.layout->parent = win->layout; |
| 18722 |
win->layout = panel.layout; |
| 18723 |
|
| 18724 |
ctx->current = win; |
| 18725 |
if ((panel.layout->flags & NK_WINDOW_CLOSED) || |
| 18726 |
(panel.layout->flags & NK_WINDOW_MINIMIZED)) |
| 18727 |
{ |
| 18728 |
nk_flags f = panel.layout->flags; |
| 18729 |
nk_group_scrolled_end(ctx); |
| 18730 |
if (f & NK_WINDOW_CLOSED) |
| 18731 |
return NK_WINDOW_CLOSED; |
| 18732 |
if (f & NK_WINDOW_MINIMIZED) |
| 18733 |
return NK_WINDOW_MINIMIZED; |
| 18734 |
} |
| 18735 |
return 1; |
| 18736 |
} |
| 18737 |
NK_API void |
| 18738 |
nk_group_scrolled_end(struct nk_context *ctx) |
| 18739 |
{ |
| 18740 |
struct nk_window *win; |
| 18741 |
struct nk_panel *parent; |
| 18742 |
struct nk_panel *g; |
| 18743 |
|
| 18744 |
struct nk_rect clip; |
| 18745 |
struct nk_window pan; |
| 18746 |
struct nk_vec2 panel_padding; |
| 18747 |
|
| 18748 |
NK_ASSERT(ctx); |
| 18749 |
NK_ASSERT(ctx->current); |
| 18750 |
if (!ctx || !ctx->current) |
| 18751 |
return; |
| 18752 |
|
| 18753 |
|
| 18754 |
NK_ASSERT(ctx->current); |
| 18755 |
win = ctx->current; |
| 18756 |
NK_ASSERT(win->layout); |
| 18757 |
g = win->layout; |
| 18758 |
NK_ASSERT(g->parent); |
| 18759 |
parent = g->parent; |
| 18760 |
|
| 18761 |
|
| 18762 |
nk_zero_struct(pan); |
| 18763 |
panel_padding = nk_panel_get_padding(&ctx->style, NK_PANEL_GROUP); |
| 18764 |
pan.bounds.y = g->bounds.y - (g->header_height + g->menu.h); |
| 18765 |
pan.bounds.x = g->bounds.x - panel_padding.x; |
| 18766 |
pan.bounds.w = g->bounds.w + 2 * panel_padding.x; |
| 18767 |
pan.bounds.h = g->bounds.h + g->header_height + g->menu.h; |
| 18768 |
if (g->flags & NK_WINDOW_BORDER) { |
| 18769 |
pan.bounds.x -= g->border; |
| 18770 |
pan.bounds.y -= g->border; |
| 18771 |
pan.bounds.w += 2*g->border; |
| 18772 |
pan.bounds.h += 2*g->border; |
| 18773 |
} |
| 18774 |
if (!(g->flags & NK_WINDOW_NO_SCROLLBAR)) { |
| 18775 |
pan.bounds.w += ctx->style.window.scrollbar_size.x; |
| 18776 |
pan.bounds.h += ctx->style.window.scrollbar_size.y; |
| 18777 |
} |
| 18778 |
pan.scrollbar.x = *g->offset_x; |
| 18779 |
pan.scrollbar.y = *g->offset_y; |
| 18780 |
pan.flags = g->flags; |
| 18781 |
pan.buffer = win->buffer; |
| 18782 |
pan.layout = g; |
| 18783 |
pan.parent = win; |
| 18784 |
ctx->current = &pan; |
| 18785 |
|
| 18786 |
|
| 18787 |
nk_unify(&clip, &parent->clip, pan.bounds.x, pan.bounds.y, |
| 18788 |
pan.bounds.x + pan.bounds.w, pan.bounds.y + pan.bounds.h + panel_padding.x); |
| 18789 |
nk_push_scissor(&pan.buffer, clip); |
| 18790 |
nk_end(ctx); |
| 18791 |
|
| 18792 |
win->buffer = pan.buffer; |
| 18793 |
nk_push_scissor(&win->buffer, parent->clip); |
| 18794 |
ctx->current = win; |
| 18795 |
win->layout = parent; |
| 18796 |
g->bounds = pan.bounds; |
| 18797 |
return; |
| 18798 |
} |
| 18799 |
NK_API int |
| 18800 |
nk_group_scrolled_begin(struct nk_context *ctx, |
| 18801 |
struct nk_scroll *scroll, const char *title, nk_flags flags) |
| 18802 |
{ |
| 18803 |
return nk_group_scrolled_offset_begin(ctx, &scroll->x, &scroll->y, title, flags); |
| 18804 |
} |
| 18805 |
NK_API int |
| 18806 |
nk_group_begin_titled(struct nk_context *ctx, const char *id, |
| 18807 |
const char *title, nk_flags flags) |
| 18808 |
{ |
| 18809 |
int id_len; |
| 18810 |
nk_hash id_hash; |
| 18811 |
struct nk_window *win; |
| 18812 |
nk_uint *x_offset; |
| 18813 |
nk_uint *y_offset; |
| 18814 |
|
| 18815 |
NK_ASSERT(ctx); |
| 18816 |
NK_ASSERT(id); |
| 18817 |
NK_ASSERT(ctx->current); |
| 18818 |
NK_ASSERT(ctx->current->layout); |
| 18819 |
if (!ctx || !ctx->current || !ctx->current->layout || !id) |
| 18820 |
return 0; |
| 18821 |
|
| 18822 |
|
| 18823 |
win = ctx->current; |
| 18824 |
id_len = (int)nk_strlen(id); |
| 18825 |
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP); |
| 18826 |
x_offset = nk_find_value(win, id_hash); |
| 18827 |
if (!x_offset) { |
| 18828 |
x_offset = nk_add_value(ctx, win, id_hash, 0); |
| 18829 |
y_offset = nk_add_value(ctx, win, id_hash+1, 0); |
| 18830 |
|
| 18831 |
NK_ASSERT(x_offset); |
| 18832 |
NK_ASSERT(y_offset); |
| 18833 |
if (!x_offset || !y_offset) return 0; |
| 18834 |
*x_offset = *y_offset = 0; |
| 18835 |
} else y_offset = nk_find_value(win, id_hash+1); |
| 18836 |
return nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags); |
| 18837 |
} |
| 18838 |
NK_API int |
| 18839 |
nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags) |
| 18840 |
{ |
| 18841 |
return nk_group_begin_titled(ctx, title, title, flags); |
| 18842 |
} |
| 18843 |
NK_API void |
| 18844 |
nk_group_end(struct nk_context *ctx) |
| 18845 |
{ |
| 18846 |
nk_group_scrolled_end(ctx); |
| 18847 |
} |
| 18848 |
NK_API void |
| 18849 |
nk_group_get_scroll(struct nk_context *ctx, const char *id, nk_uint *x_offset, nk_uint *y_offset) |
| 18850 |
{ |
| 18851 |
int id_len; |
| 18852 |
nk_hash id_hash; |
| 18853 |
struct nk_window *win; |
| 18854 |
nk_uint *x_offset_ptr; |
| 18855 |
nk_uint *y_offset_ptr; |
| 18856 |
|
| 18857 |
NK_ASSERT(ctx); |
| 18858 |
NK_ASSERT(id); |
| 18859 |
NK_ASSERT(ctx->current); |
| 18860 |
NK_ASSERT(ctx->current->layout); |
| 18861 |
if (!ctx || !ctx->current || !ctx->current->layout || !id) |
| 18862 |
return; |
| 18863 |
|
| 18864 |
|
| 18865 |
win = ctx->current; |
| 18866 |
id_len = (int)nk_strlen(id); |
| 18867 |
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP); |
| 18868 |
x_offset_ptr = nk_find_value(win, id_hash); |
| 18869 |
if (!x_offset_ptr) { |
| 18870 |
x_offset_ptr = nk_add_value(ctx, win, id_hash, 0); |
| 18871 |
y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0); |
| 18872 |
|
| 18873 |
NK_ASSERT(x_offset_ptr); |
| 18874 |
NK_ASSERT(y_offset_ptr); |
| 18875 |
if (!x_offset_ptr || !y_offset_ptr) return; |
| 18876 |
*x_offset_ptr = *y_offset_ptr = 0; |
| 18877 |
} else y_offset_ptr = nk_find_value(win, id_hash+1); |
| 18878 |
if (x_offset) |
| 18879 |
*x_offset = *x_offset_ptr; |
| 18880 |
if (y_offset) |
| 18881 |
*y_offset = *y_offset_ptr; |
| 18882 |
} |
| 18883 |
NK_API void |
| 18884 |
nk_group_set_scroll(struct nk_context *ctx, const char *id, nk_uint x_offset, nk_uint y_offset) |
| 18885 |
{ |
| 18886 |
int id_len; |
| 18887 |
nk_hash id_hash; |
| 18888 |
struct nk_window *win; |
| 18889 |
nk_uint *x_offset_ptr; |
| 18890 |
nk_uint *y_offset_ptr; |
| 18891 |
|
| 18892 |
NK_ASSERT(ctx); |
| 18893 |
NK_ASSERT(id); |
| 18894 |
NK_ASSERT(ctx->current); |
| 18895 |
NK_ASSERT(ctx->current->layout); |
| 18896 |
if (!ctx || !ctx->current || !ctx->current->layout || !id) |
| 18897 |
return; |
| 18898 |
|
| 18899 |
|
| 18900 |
win = ctx->current; |
| 18901 |
id_len = (int)nk_strlen(id); |
| 18902 |
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP); |
| 18903 |
x_offset_ptr = nk_find_value(win, id_hash); |
| 18904 |
if (!x_offset_ptr) { |
| 18905 |
x_offset_ptr = nk_add_value(ctx, win, id_hash, 0); |
| 18906 |
y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0); |
| 18907 |
|
| 18908 |
NK_ASSERT(x_offset_ptr); |
| 18909 |
NK_ASSERT(y_offset_ptr); |
| 18910 |
if (!x_offset_ptr || !y_offset_ptr) return; |
| 18911 |
*x_offset_ptr = *y_offset_ptr = 0; |
| 18912 |
} else y_offset_ptr = nk_find_value(win, id_hash+1); |
| 18913 |
*x_offset_ptr = x_offset; |
| 18914 |
*y_offset_ptr = y_offset; |
| 18915 |
} |
| 18916 |
|
| 18917 |
|
| 18918 |
|
| 18919 |
|
| 18920 |
|
| 18921 |
|
| 18922 |
|
| 18923 |
|
| 18924 |
|
| 18925 |
NK_API int |
| 18926 |
nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view, |
| 18927 |
const char *title, nk_flags flags, int row_height, int row_count) |
| 18928 |
{ |
| 18929 |
int title_len; |
| 18930 |
nk_hash title_hash; |
| 18931 |
nk_uint *x_offset; |
| 18932 |
nk_uint *y_offset; |
| 18933 |
|
| 18934 |
int result; |
| 18935 |
struct nk_window *win; |
| 18936 |
struct nk_panel *layout; |
| 18937 |
const struct nk_style *style; |
| 18938 |
struct nk_vec2 item_spacing; |
| 18939 |
|
| 18940 |
NK_ASSERT(ctx); |
| 18941 |
NK_ASSERT(view); |
| 18942 |
NK_ASSERT(title); |
| 18943 |
if (!ctx || !view || !title) return 0; |
| 18944 |
|
| 18945 |
win = ctx->current; |
| 18946 |
style = &ctx->style; |
| 18947 |
item_spacing = style->window.spacing; |
| 18948 |
row_height += NK_MAX(0, (int)item_spacing.y); |
| 18949 |
|
| 18950 |
|
| 18951 |
title_len = (int)nk_strlen(title); |
| 18952 |
title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_GROUP); |
| 18953 |
x_offset = nk_find_value(win, title_hash); |
| 18954 |
if (!x_offset) { |
| 18955 |
x_offset = nk_add_value(ctx, win, title_hash, 0); |
| 18956 |
y_offset = nk_add_value(ctx, win, title_hash+1, 0); |
| 18957 |
|
| 18958 |
NK_ASSERT(x_offset); |
| 18959 |
NK_ASSERT(y_offset); |
| 18960 |
if (!x_offset || !y_offset) return 0; |
| 18961 |
*x_offset = *y_offset = 0; |
| 18962 |
} else y_offset = nk_find_value(win, title_hash+1); |
| 18963 |
view->scroll_value = *y_offset; |
| 18964 |
view->scroll_pointer = y_offset; |
| 18965 |
|
| 18966 |
*y_offset = 0; |
| 18967 |
result = nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags); |
| 18968 |
win = ctx->current; |
| 18969 |
layout = win->layout; |
| 18970 |
|
| 18971 |
view->total_height = row_height * NK_MAX(row_count,1); |
| 18972 |
view->begin = (int)NK_MAX(((float)view->scroll_value / (float)row_height), 0.0f); |
| 18973 |
view->count = (int)NK_MAX(nk_iceilf((layout->clip.h)/(float)row_height),0); |
| 18974 |
view->count = NK_MIN(view->count, row_count - view->begin); |
| 18975 |
view->end = view->begin + view->count; |
| 18976 |
view->ctx = ctx; |
| 18977 |
return result; |
| 18978 |
} |
| 18979 |
NK_API void |
| 18980 |
nk_list_view_end(struct nk_list_view *view) |
| 18981 |
{ |
| 18982 |
struct nk_context *ctx; |
| 18983 |
struct nk_window *win; |
| 18984 |
struct nk_panel *layout; |
| 18985 |
|
| 18986 |
NK_ASSERT(view); |
| 18987 |
NK_ASSERT(view->ctx); |
| 18988 |
NK_ASSERT(view->scroll_pointer); |
| 18989 |
if (!view || !view->ctx) return; |
| 18990 |
|
| 18991 |
ctx = view->ctx; |
| 18992 |
win = ctx->current; |
| 18993 |
layout = win->layout; |
| 18994 |
layout->at_y = layout->bounds.y + (float)view->total_height; |
| 18995 |
*view->scroll_pointer = *view->scroll_pointer + view->scroll_value; |
| 18996 |
nk_group_end(view->ctx); |
| 18997 |
} |
| 18998 |
|
| 18999 |
|
| 19000 |
|
| 19001 |
|
| 19002 |
|
| 19003 |
|
| 19004 |
|
| 19005 |
|
| 19006 |
|
| 19007 |
|
| 19008 |
NK_API struct nk_rect |
| 19009 |
nk_widget_bounds(struct nk_context *ctx) |
| 19010 |
{ |
| 19011 |
struct nk_rect bounds; |
| 19012 |
NK_ASSERT(ctx); |
| 19013 |
NK_ASSERT(ctx->current); |
| 19014 |
if (!ctx || !ctx->current) |
| 19015 |
return nk_rect(0,0,0,0); |
| 19016 |
nk_layout_peek(&bounds, ctx); |
| 19017 |
return bounds; |
| 19018 |
} |
| 19019 |
NK_API struct nk_vec2 |
| 19020 |
nk_widget_position(struct nk_context *ctx) |
| 19021 |
{ |
| 19022 |
struct nk_rect bounds; |
| 19023 |
NK_ASSERT(ctx); |
| 19024 |
NK_ASSERT(ctx->current); |
| 19025 |
if (!ctx || !ctx->current) |
| 19026 |
return nk_vec2(0,0); |
| 19027 |
|
| 19028 |
nk_layout_peek(&bounds, ctx); |
| 19029 |
return nk_vec2(bounds.x, bounds.y); |
| 19030 |
} |
| 19031 |
NK_API struct nk_vec2 |
| 19032 |
nk_widget_size(struct nk_context *ctx) |
| 19033 |
{ |
| 19034 |
struct nk_rect bounds; |
| 19035 |
NK_ASSERT(ctx); |
| 19036 |
NK_ASSERT(ctx->current); |
| 19037 |
if (!ctx || !ctx->current) |
| 19038 |
return nk_vec2(0,0); |
| 19039 |
|
| 19040 |
nk_layout_peek(&bounds, ctx); |
| 19041 |
return nk_vec2(bounds.w, bounds.h); |
| 19042 |
} |
| 19043 |
NK_API float |
| 19044 |
nk_widget_width(struct nk_context *ctx) |
| 19045 |
{ |
| 19046 |
struct nk_rect bounds; |
| 19047 |
NK_ASSERT(ctx); |
| 19048 |
NK_ASSERT(ctx->current); |
| 19049 |
if (!ctx || !ctx->current) |
| 19050 |
return 0; |
| 19051 |
|
| 19052 |
nk_layout_peek(&bounds, ctx); |
| 19053 |
return bounds.w; |
| 19054 |
} |
| 19055 |
NK_API float |
| 19056 |
nk_widget_height(struct nk_context *ctx) |
| 19057 |
{ |
| 19058 |
struct nk_rect bounds; |
| 19059 |
NK_ASSERT(ctx); |
| 19060 |
NK_ASSERT(ctx->current); |
| 19061 |
if (!ctx || !ctx->current) |
| 19062 |
return 0; |
| 19063 |
|
| 19064 |
nk_layout_peek(&bounds, ctx); |
| 19065 |
return bounds.h; |
| 19066 |
} |
| 19067 |
NK_API int |
| 19068 |
nk_widget_is_hovered(struct nk_context *ctx) |
| 19069 |
{ |
| 19070 |
struct nk_rect c, v; |
| 19071 |
struct nk_rect bounds; |
| 19072 |
NK_ASSERT(ctx); |
| 19073 |
NK_ASSERT(ctx->current); |
| 19074 |
if (!ctx || !ctx->current || ctx->active != ctx->current) |
| 19075 |
return 0; |
| 19076 |
|
| 19077 |
c = ctx->current->layout->clip; |
| 19078 |
c.x = (float)((int)c.x); |
| 19079 |
c.y = (float)((int)c.y); |
| 19080 |
c.w = (float)((int)c.w); |
| 19081 |
c.h = (float)((int)c.h); |
| 19082 |
|
| 19083 |
nk_layout_peek(&bounds, ctx); |
| 19084 |
nk_unify(&v, &c, bounds.x, bounds.y, bounds.x + bounds.w, bounds.y + bounds.h); |
| 19085 |
if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds.x, bounds.y, bounds.w, bounds.h)) |
| 19086 |
return 0; |
| 19087 |
return nk_input_is_mouse_hovering_rect(&ctx->input, bounds); |
| 19088 |
} |
| 19089 |
NK_API int |
| 19090 |
nk_widget_is_mouse_clicked(struct nk_context *ctx, enum nk_buttons btn) |
| 19091 |
{ |
| 19092 |
struct nk_rect c, v; |
| 19093 |
struct nk_rect bounds; |
| 19094 |
NK_ASSERT(ctx); |
| 19095 |
NK_ASSERT(ctx->current); |
| 19096 |
if (!ctx || !ctx->current || ctx->active != ctx->current) |
| 19097 |
return 0; |
| 19098 |
|
| 19099 |
c = ctx->current->layout->clip; |
| 19100 |
c.x = (float)((int)c.x); |
| 19101 |
c.y = (float)((int)c.y); |
| 19102 |
c.w = (float)((int)c.w); |
| 19103 |
c.h = (float)((int)c.h); |
| 19104 |
|
| 19105 |
nk_layout_peek(&bounds, ctx); |
| 19106 |
nk_unify(&v, &c, bounds.x, bounds.y, bounds.x + bounds.w, bounds.y + bounds.h); |
| 19107 |
if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds.x, bounds.y, bounds.w, bounds.h)) |
| 19108 |
return 0; |
| 19109 |
return nk_input_mouse_clicked(&ctx->input, btn, bounds); |
| 19110 |
} |
| 19111 |
NK_API int |
| 19112 |
nk_widget_has_mouse_click_down(struct nk_context *ctx, enum nk_buttons btn, int down) |
| 19113 |
{ |
| 19114 |
struct nk_rect c, v; |
| 19115 |
struct nk_rect bounds; |
| 19116 |
NK_ASSERT(ctx); |
| 19117 |
NK_ASSERT(ctx->current); |
| 19118 |
if (!ctx || !ctx->current || ctx->active != ctx->current) |
| 19119 |
return 0; |
| 19120 |
|
| 19121 |
c = ctx->current->layout->clip; |
| 19122 |
c.x = (float)((int)c.x); |
| 19123 |
c.y = (float)((int)c.y); |
| 19124 |
c.w = (float)((int)c.w); |
| 19125 |
c.h = (float)((int)c.h); |
| 19126 |
|
| 19127 |
nk_layout_peek(&bounds, ctx); |
| 19128 |
nk_unify(&v, &c, bounds.x, bounds.y, bounds.x + bounds.w, bounds.y + bounds.h); |
| 19129 |
if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds.x, bounds.y, bounds.w, bounds.h)) |
| 19130 |
return 0; |
| 19131 |
return nk_input_has_mouse_click_down_in_rect(&ctx->input, btn, bounds, down); |
| 19132 |
} |
| 19133 |
NK_API enum nk_widget_layout_states |
| 19134 |
nk_widget(struct nk_rect *bounds, const struct nk_context *ctx) |
| 19135 |
{ |
| 19136 |
struct nk_rect c, v; |
| 19137 |
struct nk_window *win; |
| 19138 |
struct nk_panel *layout; |
| 19139 |
const struct nk_input *in; |
| 19140 |
|
| 19141 |
NK_ASSERT(ctx); |
| 19142 |
NK_ASSERT(ctx->current); |
| 19143 |
NK_ASSERT(ctx->current->layout); |
| 19144 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 19145 |
return NK_WIDGET_INVALID; |
| 19146 |
|
| 19147 |
|
| 19148 |
nk_panel_alloc_space(bounds, ctx); |
| 19149 |
win = ctx->current; |
| 19150 |
layout = win->layout; |
| 19151 |
in = &ctx->input; |
| 19152 |
c = layout->clip; |
| 19153 |
|
| 19154 |
|
| 19155 |
|
| 19156 |
|
| 19157 |
|
| 19158 |
|
| 19159 |
NK_ASSERT(!(layout->flags & NK_WINDOW_MINIMIZED)); |
| 19160 |
NK_ASSERT(!(layout->flags & NK_WINDOW_HIDDEN)); |
| 19161 |
NK_ASSERT(!(layout->flags & NK_WINDOW_CLOSED)); |
| 19162 |
|
| 19163 |
|
| 19164 |
bounds->x = (float)((int)bounds->x); |
| 19165 |
bounds->y = (float)((int)bounds->y); |
| 19166 |
bounds->w = (float)((int)bounds->w); |
| 19167 |
bounds->h = (float)((int)bounds->h); |
| 19168 |
|
| 19169 |
c.x = (float)((int)c.x); |
| 19170 |
c.y = (float)((int)c.y); |
| 19171 |
c.w = (float)((int)c.w); |
| 19172 |
c.h = (float)((int)c.h); |
| 19173 |
|
| 19174 |
nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); |
| 19175 |
if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) |
| 19176 |
return NK_WIDGET_INVALID; |
| 19177 |
if (!NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, v.x, v.y, v.w, v.h)) |
| 19178 |
return NK_WIDGET_ROM; |
| 19179 |
return NK_WIDGET_VALID; |
| 19180 |
} |
| 19181 |
NK_API enum nk_widget_layout_states |
| 19182 |
nk_widget_fitting(struct nk_rect *bounds, struct nk_context *ctx, |
| 19183 |
struct nk_vec2 item_padding) |
| 19184 |
{ |
| 19185 |
|
| 19186 |
struct nk_window *win; |
| 19187 |
struct nk_style *style; |
| 19188 |
struct nk_panel *layout; |
| 19189 |
enum nk_widget_layout_states state; |
| 19190 |
struct nk_vec2 panel_padding; |
| 19191 |
|
| 19192 |
NK_ASSERT(ctx); |
| 19193 |
NK_ASSERT(ctx->current); |
| 19194 |
NK_ASSERT(ctx->current->layout); |
| 19195 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 19196 |
return NK_WIDGET_INVALID; |
| 19197 |
|
| 19198 |
win = ctx->current; |
| 19199 |
style = &ctx->style; |
| 19200 |
layout = win->layout; |
| 19201 |
state = nk_widget(bounds, ctx); |
| 19202 |
|
| 19203 |
panel_padding = nk_panel_get_padding(style, layout->type); |
| 19204 |
if (layout->row.index == 1) { |
| 19205 |
bounds->w += panel_padding.x; |
| 19206 |
bounds->x -= panel_padding.x; |
| 19207 |
} else bounds->x -= item_padding.x; |
| 19208 |
|
| 19209 |
if (layout->row.index == layout->row.columns) |
| 19210 |
bounds->w += panel_padding.x; |
| 19211 |
else bounds->w += item_padding.x; |
| 19212 |
return state; |
| 19213 |
} |
| 19214 |
NK_API void |
| 19215 |
nk_spacing(struct nk_context *ctx, int cols) |
| 19216 |
{ |
| 19217 |
struct nk_window *win; |
| 19218 |
struct nk_panel *layout; |
| 19219 |
struct nk_rect none; |
| 19220 |
int i, index, rows; |
| 19221 |
|
| 19222 |
NK_ASSERT(ctx); |
| 19223 |
NK_ASSERT(ctx->current); |
| 19224 |
NK_ASSERT(ctx->current->layout); |
| 19225 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 19226 |
return; |
| 19227 |
|
| 19228 |
|
| 19229 |
win = ctx->current; |
| 19230 |
layout = win->layout; |
| 19231 |
index = (layout->row.index + cols) % layout->row.columns; |
| 19232 |
rows = (layout->row.index + cols) / layout->row.columns; |
| 19233 |
if (rows) { |
| 19234 |
for (i = 0; i < rows; ++i) |
| 19235 |
nk_panel_alloc_row(ctx, win); |
| 19236 |
cols = index; |
| 19237 |
} |
| 19238 |
|
| 19239 |
if (layout->row.type != NK_LAYOUT_DYNAMIC_FIXED && |
| 19240 |
layout->row.type != NK_LAYOUT_STATIC_FIXED) { |
| 19241 |
for (i = 0; i < cols; ++i) |
| 19242 |
nk_panel_alloc_space(&none, ctx); |
| 19243 |
} layout->row.index = index; |
| 19244 |
} |
| 19245 |
|
| 19246 |
|
| 19247 |
|
| 19248 |
|
| 19249 |
|
| 19250 |
|
| 19251 |
|
| 19252 |
|
| 19253 |
|
| 19254 |
|
| 19255 |
NK_LIB void |
| 19256 |
nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, |
| 19257 |
const char *string, int len, const struct nk_text *t, |
| 19258 |
nk_flags a, const struct nk_user_font *f) |
| 19259 |
{ |
| 19260 |
struct nk_rect label; |
| 19261 |
float text_width; |
| 19262 |
|
| 19263 |
NK_ASSERT(o); |
| 19264 |
NK_ASSERT(t); |
| 19265 |
if (!o || !t) return; |
| 19266 |
|
| 19267 |
b.h = NK_MAX(b.h, 2 * t->padding.y); |
| 19268 |
label.x = 0; label.w = 0; |
| 19269 |
label.y = b.y + t->padding.y; |
| 19270 |
label.h = NK_MIN(f->height, b.h - 2 * t->padding.y); |
| 19271 |
|
| 19272 |
text_width = f->width(f->userdata, f->height, (const char*)string, len); |
| 19273 |
text_width += (2.0f * t->padding.x); |
| 19274 |
|
| 19275 |
|
| 19276 |
if (a & NK_TEXT_ALIGN_LEFT) { |
| 19277 |
label.x = b.x + t->padding.x; |
| 19278 |
label.w = NK_MAX(0, b.w - 2 * t->padding.x); |
| 19279 |
} else if (a & NK_TEXT_ALIGN_CENTERED) { |
| 19280 |
label.w = NK_MAX(1, 2 * t->padding.x + (float)text_width); |
| 19281 |
label.x = (b.x + t->padding.x + ((b.w - 2 * t->padding.x) - label.w) / 2); |
| 19282 |
label.x = NK_MAX(b.x + t->padding.x, label.x); |
| 19283 |
label.w = NK_MIN(b.x + b.w, label.x + label.w); |
| 19284 |
if (label.w >= label.x) label.w -= label.x; |
| 19285 |
} else if (a & NK_TEXT_ALIGN_RIGHT) { |
| 19286 |
label.x = NK_MAX(b.x + t->padding.x, (b.x + b.w) - (2 * t->padding.x + (float)text_width)); |
| 19287 |
label.w = (float)text_width + 2 * t->padding.x; |
| 19288 |
} else return; |
| 19289 |
|
| 19290 |
|
| 19291 |
if (a & NK_TEXT_ALIGN_MIDDLE) { |
| 19292 |
label.y = b.y + b.h/2.0f - (float)f->height/2.0f; |
| 19293 |
label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->height/2.0f)); |
| 19294 |
} else if (a & NK_TEXT_ALIGN_BOTTOM) { |
| 19295 |
label.y = b.y + b.h - f->height; |
| 19296 |
label.h = f->height; |
| 19297 |
} |
| 19298 |
nk_draw_text(o, label, (const char*)string, len, f, t->background, t->text); |
| 19299 |
} |
| 19300 |
NK_LIB void |
| 19301 |
nk_widget_text_wrap(struct nk_command_buffer *o, struct nk_rect b, |
| 19302 |
const char *string, int len, const struct nk_text *t, |
| 19303 |
const struct nk_user_font *f) |
| 19304 |
{ |
| 19305 |
float width; |
| 19306 |
int glyphs = 0; |
| 19307 |
int fitting = 0; |
| 19308 |
int done = 0; |
| 19309 |
struct nk_rect line; |
| 19310 |
struct nk_text text; |
| 19311 |
NK_INTERN nk_rune seperator[] = {' '}; |
| 19312 |
|
| 19313 |
NK_ASSERT(o); |
| 19314 |
NK_ASSERT(t); |
| 19315 |
if (!o || !t) return; |
| 19316 |
|
| 19317 |
text.padding = nk_vec2(0,0); |
| 19318 |
text.background = t->background; |
| 19319 |
text.text = t->text; |
| 19320 |
|
| 19321 |
b.w = NK_MAX(b.w, 2 * t->padding.x); |
| 19322 |
b.h = NK_MAX(b.h, 2 * t->padding.y); |
| 19323 |
b.h = b.h - 2 * t->padding.y; |
| 19324 |
|
| 19325 |
line.x = b.x + t->padding.x; |
| 19326 |
line.y = b.y + t->padding.y; |
| 19327 |
line.w = b.w - 2 * t->padding.x; |
| 19328 |
line.h = 2 * t->padding.y + f->height; |
| 19329 |
|
| 19330 |
fitting = nk_text_clamp(f, string, len, line.w, &glyphs, &width, seperator,NK_LEN(seperator)); |
| 19331 |
while (done < len) { |
| 19332 |
if (!fitting || line.y + line.h >= (b.y + b.h)) break; |
| 19333 |
nk_widget_text(o, line, &string[done], fitting, &text, NK_TEXT_LEFT, f); |
| 19334 |
done += fitting; |
| 19335 |
line.y += f->height + 2 * t->padding.y; |
| 19336 |
fitting = nk_text_clamp(f, &string[done], len - done, line.w, &glyphs, &width, seperator,NK_LEN(seperator)); |
| 19337 |
} |
| 19338 |
} |
| 19339 |
NK_API void |
| 19340 |
nk_text_colored(struct nk_context *ctx, const char *str, int len, |
| 19341 |
nk_flags alignment, struct nk_color color) |
| 19342 |
{ |
| 19343 |
struct nk_window *win; |
| 19344 |
const struct nk_style *style; |
| 19345 |
|
| 19346 |
struct nk_vec2 item_padding; |
| 19347 |
struct nk_rect bounds; |
| 19348 |
struct nk_text text; |
| 19349 |
|
| 19350 |
NK_ASSERT(ctx); |
| 19351 |
NK_ASSERT(ctx->current); |
| 19352 |
NK_ASSERT(ctx->current->layout); |
| 19353 |
if (!ctx || !ctx->current || !ctx->current->layout) return; |
| 19354 |
|
| 19355 |
win = ctx->current; |
| 19356 |
style = &ctx->style; |
| 19357 |
nk_panel_alloc_space(&bounds, ctx); |
| 19358 |
item_padding = style->text.padding; |
| 19359 |
|
| 19360 |
text.padding.x = item_padding.x; |
| 19361 |
text.padding.y = item_padding.y; |
| 19362 |
text.background = style->window.background; |
| 19363 |
text.text = color; |
| 19364 |
nk_widget_text(&win->buffer, bounds, str, len, &text, alignment, style->font); |
| 19365 |
} |
| 19366 |
NK_API void |
| 19367 |
nk_text_wrap_colored(struct nk_context *ctx, const char *str, |
| 19368 |
int len, struct nk_color color) |
| 19369 |
{ |
| 19370 |
struct nk_window *win; |
| 19371 |
const struct nk_style *style; |
| 19372 |
|
| 19373 |
struct nk_vec2 item_padding; |
| 19374 |
struct nk_rect bounds; |
| 19375 |
struct nk_text text; |
| 19376 |
|
| 19377 |
NK_ASSERT(ctx); |
| 19378 |
NK_ASSERT(ctx->current); |
| 19379 |
NK_ASSERT(ctx->current->layout); |
| 19380 |
if (!ctx || !ctx->current || !ctx->current->layout) return; |
| 19381 |
|
| 19382 |
win = ctx->current; |
| 19383 |
style = &ctx->style; |
| 19384 |
nk_panel_alloc_space(&bounds, ctx); |
| 19385 |
item_padding = style->text.padding; |
| 19386 |
|
| 19387 |
text.padding.x = item_padding.x; |
| 19388 |
text.padding.y = item_padding.y; |
| 19389 |
text.background = style->window.background; |
| 19390 |
text.text = color; |
| 19391 |
nk_widget_text_wrap(&win->buffer, bounds, str, len, &text, style->font); |
| 19392 |
} |
| 19393 |
#ifdef NK_INCLUDE_STANDARD_VARARGS |
| 19394 |
NK_API void |
| 19395 |
nk_labelf_colored(struct nk_context *ctx, nk_flags flags, |
| 19396 |
struct nk_color color, const char *fmt, ...) |
| 19397 |
{ |
| 19398 |
va_list args; |
| 19399 |
va_start(args, fmt); |
| 19400 |
nk_labelfv_colored(ctx, flags, color, fmt, args); |
| 19401 |
va_end(args); |
| 19402 |
} |
| 19403 |
NK_API void |
| 19404 |
nk_labelf_colored_wrap(struct nk_context *ctx, struct nk_color color, |
| 19405 |
const char *fmt, ...) |
| 19406 |
{ |
| 19407 |
va_list args; |
| 19408 |
va_start(args, fmt); |
| 19409 |
nk_labelfv_colored_wrap(ctx, color, fmt, args); |
| 19410 |
va_end(args); |
| 19411 |
} |
| 19412 |
NK_API void |
| 19413 |
nk_labelf(struct nk_context *ctx, nk_flags flags, const char *fmt, ...) |
| 19414 |
{ |
| 19415 |
va_list args; |
| 19416 |
va_start(args, fmt); |
| 19417 |
nk_labelfv(ctx, flags, fmt, args); |
| 19418 |
va_end(args); |
| 19419 |
} |
| 19420 |
NK_API void |
| 19421 |
nk_labelf_wrap(struct nk_context *ctx, const char *fmt,...) |
| 19422 |
{ |
| 19423 |
va_list args; |
| 19424 |
va_start(args, fmt); |
| 19425 |
nk_labelfv_wrap(ctx, fmt, args); |
| 19426 |
va_end(args); |
| 19427 |
} |
| 19428 |
NK_API void |
| 19429 |
nk_labelfv_colored(struct nk_context *ctx, nk_flags flags, |
| 19430 |
struct nk_color color, const char *fmt, va_list args) |
| 19431 |
{ |
| 19432 |
char buf[256]; |
| 19433 |
nk_strfmt(buf, NK_LEN(buf), fmt, args); |
| 19434 |
nk_label_colored(ctx, buf, flags, color); |
| 19435 |
} |
| 19436 |
|
| 19437 |
NK_API void |
| 19438 |
nk_labelfv_colored_wrap(struct nk_context *ctx, struct nk_color color, |
| 19439 |
const char *fmt, va_list args) |
| 19440 |
{ |
| 19441 |
char buf[256]; |
| 19442 |
nk_strfmt(buf, NK_LEN(buf), fmt, args); |
| 19443 |
nk_label_colored_wrap(ctx, buf, color); |
| 19444 |
} |
| 19445 |
|
| 19446 |
NK_API void |
| 19447 |
nk_labelfv(struct nk_context *ctx, nk_flags flags, const char *fmt, va_list args) |
| 19448 |
{ |
| 19449 |
char buf[256]; |
| 19450 |
nk_strfmt(buf, NK_LEN(buf), fmt, args); |
| 19451 |
nk_label(ctx, buf, flags); |
| 19452 |
} |
| 19453 |
|
| 19454 |
NK_API void |
| 19455 |
nk_labelfv_wrap(struct nk_context *ctx, const char *fmt, va_list args) |
| 19456 |
{ |
| 19457 |
char buf[256]; |
| 19458 |
nk_strfmt(buf, NK_LEN(buf), fmt, args); |
| 19459 |
nk_label_wrap(ctx, buf); |
| 19460 |
} |
| 19461 |
|
| 19462 |
NK_API void |
| 19463 |
nk_value_bool(struct nk_context *ctx, const char *prefix, int value) |
| 19464 |
{ |
| 19465 |
nk_labelf(ctx, NK_TEXT_LEFT, "%s: %s", prefix, ((value) ? "true": "false")); |
| 19466 |
} |
| 19467 |
NK_API void |
| 19468 |
nk_value_int(struct nk_context *ctx, const char *prefix, int value) |
| 19469 |
{ |
| 19470 |
nk_labelf(ctx, NK_TEXT_LEFT, "%s: %d", prefix, value); |
| 19471 |
} |
| 19472 |
NK_API void |
| 19473 |
nk_value_uint(struct nk_context *ctx, const char *prefix, unsigned int value) |
| 19474 |
{ |
| 19475 |
nk_labelf(ctx, NK_TEXT_LEFT, "%s: %u", prefix, value); |
| 19476 |
} |
| 19477 |
NK_API void |
| 19478 |
nk_value_float(struct nk_context *ctx, const char *prefix, float value) |
| 19479 |
{ |
| 19480 |
double double_value = (double)value; |
| 19481 |
nk_labelf(ctx, NK_TEXT_LEFT, "%s: %.3f", prefix, double_value); |
| 19482 |
} |
| 19483 |
NK_API void |
| 19484 |
nk_value_color_byte(struct nk_context *ctx, const char *p, struct nk_color c) |
| 19485 |
{ |
| 19486 |
nk_labelf(ctx, NK_TEXT_LEFT, "%s: (%d, %d, %d, %d)", p, c.r, c.g, c.b, c.a); |
| 19487 |
} |
| 19488 |
NK_API void |
| 19489 |
nk_value_color_float(struct nk_context *ctx, const char *p, struct nk_color color) |
| 19490 |
{ |
| 19491 |
double c[4]; nk_color_dv(c, color); |
| 19492 |
nk_labelf(ctx, NK_TEXT_LEFT, "%s: (%.2f, %.2f, %.2f, %.2f)", |
| 19493 |
p, c[0], c[1], c[2], c[3]); |
| 19494 |
} |
| 19495 |
NK_API void |
| 19496 |
nk_value_color_hex(struct nk_context *ctx, const char *prefix, struct nk_color color) |
| 19497 |
{ |
| 19498 |
char hex[16]; |
| 19499 |
nk_color_hex_rgba(hex, color); |
| 19500 |
nk_labelf(ctx, NK_TEXT_LEFT, "%s: %s", prefix, hex); |
| 19501 |
} |
| 19502 |
#endif |
| 19503 |
NK_API void |
| 19504 |
nk_text(struct nk_context *ctx, const char *str, int len, nk_flags alignment) |
| 19505 |
{ |
| 19506 |
NK_ASSERT(ctx); |
| 19507 |
if (!ctx) return; |
| 19508 |
nk_text_colored(ctx, str, len, alignment, ctx->style.text.color); |
| 19509 |
} |
| 19510 |
NK_API void |
| 19511 |
nk_text_wrap(struct nk_context *ctx, const char *str, int len) |
| 19512 |
{ |
| 19513 |
NK_ASSERT(ctx); |
| 19514 |
if (!ctx) return; |
| 19515 |
nk_text_wrap_colored(ctx, str, len, ctx->style.text.color); |
| 19516 |
} |
| 19517 |
NK_API void |
| 19518 |
nk_label(struct nk_context *ctx, const char *str, nk_flags alignment) |
| 19519 |
{ |
| 19520 |
nk_text(ctx, str, nk_strlen(str), alignment); |
| 19521 |
} |
| 19522 |
NK_API void |
| 19523 |
nk_label_colored(struct nk_context *ctx, const char *str, nk_flags align, |
| 19524 |
struct nk_color color) |
| 19525 |
{ |
| 19526 |
nk_text_colored(ctx, str, nk_strlen(str), align, color); |
| 19527 |
} |
| 19528 |
NK_API void |
| 19529 |
nk_label_wrap(struct nk_context *ctx, const char *str) |
| 19530 |
{ |
| 19531 |
nk_text_wrap(ctx, str, nk_strlen(str)); |
| 19532 |
} |
| 19533 |
NK_API void |
| 19534 |
nk_label_colored_wrap(struct nk_context *ctx, const char *str, struct nk_color color) |
| 19535 |
{ |
| 19536 |
nk_text_wrap_colored(ctx, str, nk_strlen(str), color); |
| 19537 |
} |
| 19538 |
|
| 19539 |
|
| 19540 |
|
| 19541 |
|
| 19542 |
|
| 19543 |
|
| 19544 |
|
| 19545 |
|
| 19546 |
|
| 19547 |
|
| 19548 |
NK_API nk_handle |
| 19549 |
nk_handle_ptr(void *ptr) |
| 19550 |
{ |
| 19551 |
nk_handle handle = {0}; |
| 19552 |
handle.ptr = ptr; |
| 19553 |
return handle; |
| 19554 |
} |
| 19555 |
NK_API nk_handle |
| 19556 |
nk_handle_id(int id) |
| 19557 |
{ |
| 19558 |
nk_handle handle; |
| 19559 |
nk_zero_struct(handle); |
| 19560 |
handle.id = id; |
| 19561 |
return handle; |
| 19562 |
} |
| 19563 |
NK_API struct nk_image |
| 19564 |
nk_subimage_ptr(void *ptr, unsigned short w, unsigned short h, struct nk_rect r) |
| 19565 |
{ |
| 19566 |
struct nk_image s; |
| 19567 |
nk_zero(&s, sizeof(s)); |
| 19568 |
s.handle.ptr = ptr; |
| 19569 |
s.w = w; s.h = h; |
| 19570 |
s.region[0] = (unsigned short)r.x; |
| 19571 |
s.region[1] = (unsigned short)r.y; |
| 19572 |
s.region[2] = (unsigned short)r.w; |
| 19573 |
s.region[3] = (unsigned short)r.h; |
| 19574 |
return s; |
| 19575 |
} |
| 19576 |
NK_API struct nk_image |
| 19577 |
nk_subimage_id(int id, unsigned short w, unsigned short h, struct nk_rect r) |
| 19578 |
{ |
| 19579 |
struct nk_image s; |
| 19580 |
nk_zero(&s, sizeof(s)); |
| 19581 |
s.handle.id = id; |
| 19582 |
s.w = w; s.h = h; |
| 19583 |
s.region[0] = (unsigned short)r.x; |
| 19584 |
s.region[1] = (unsigned short)r.y; |
| 19585 |
s.region[2] = (unsigned short)r.w; |
| 19586 |
s.region[3] = (unsigned short)r.h; |
| 19587 |
return s; |
| 19588 |
} |
| 19589 |
NK_API struct nk_image |
| 19590 |
nk_subimage_handle(nk_handle handle, unsigned short w, unsigned short h, |
| 19591 |
struct nk_rect r) |
| 19592 |
{ |
| 19593 |
struct nk_image s; |
| 19594 |
nk_zero(&s, sizeof(s)); |
| 19595 |
s.handle = handle; |
| 19596 |
s.w = w; s.h = h; |
| 19597 |
s.region[0] = (unsigned short)r.x; |
| 19598 |
s.region[1] = (unsigned short)r.y; |
| 19599 |
s.region[2] = (unsigned short)r.w; |
| 19600 |
s.region[3] = (unsigned short)r.h; |
| 19601 |
return s; |
| 19602 |
} |
| 19603 |
NK_API struct nk_image |
| 19604 |
nk_image_handle(nk_handle handle) |
| 19605 |
{ |
| 19606 |
struct nk_image s; |
| 19607 |
nk_zero(&s, sizeof(s)); |
| 19608 |
s.handle = handle; |
| 19609 |
s.w = 0; s.h = 0; |
| 19610 |
s.region[0] = 0; |
| 19611 |
s.region[1] = 0; |
| 19612 |
s.region[2] = 0; |
| 19613 |
s.region[3] = 0; |
| 19614 |
return s; |
| 19615 |
} |
| 19616 |
NK_API struct nk_image |
| 19617 |
nk_image_ptr(void *ptr) |
| 19618 |
{ |
| 19619 |
struct nk_image s; |
| 19620 |
nk_zero(&s, sizeof(s)); |
| 19621 |
NK_ASSERT(ptr); |
| 19622 |
s.handle.ptr = ptr; |
| 19623 |
s.w = 0; s.h = 0; |
| 19624 |
s.region[0] = 0; |
| 19625 |
s.region[1] = 0; |
| 19626 |
s.region[2] = 0; |
| 19627 |
s.region[3] = 0; |
| 19628 |
return s; |
| 19629 |
} |
| 19630 |
NK_API struct nk_image |
| 19631 |
nk_image_id(int id) |
| 19632 |
{ |
| 19633 |
struct nk_image s; |
| 19634 |
nk_zero(&s, sizeof(s)); |
| 19635 |
s.handle.id = id; |
| 19636 |
s.w = 0; s.h = 0; |
| 19637 |
s.region[0] = 0; |
| 19638 |
s.region[1] = 0; |
| 19639 |
s.region[2] = 0; |
| 19640 |
s.region[3] = 0; |
| 19641 |
return s; |
| 19642 |
} |
| 19643 |
NK_API int |
| 19644 |
nk_image_is_subimage(const struct nk_image* img) |
| 19645 |
{ |
| 19646 |
NK_ASSERT(img); |
| 19647 |
return !(img->w == 0 && img->h == 0); |
| 19648 |
} |
| 19649 |
NK_API void |
| 19650 |
nk_image(struct nk_context *ctx, struct nk_image img) |
| 19651 |
{ |
| 19652 |
struct nk_window *win; |
| 19653 |
struct nk_rect bounds; |
| 19654 |
|
| 19655 |
NK_ASSERT(ctx); |
| 19656 |
NK_ASSERT(ctx->current); |
| 19657 |
NK_ASSERT(ctx->current->layout); |
| 19658 |
if (!ctx || !ctx->current || !ctx->current->layout) return; |
| 19659 |
|
| 19660 |
win = ctx->current; |
| 19661 |
if (!nk_widget(&bounds, ctx)) return; |
| 19662 |
nk_draw_image(&win->buffer, bounds, &img, nk_white); |
| 19663 |
} |
| 19664 |
NK_API void |
| 19665 |
nk_image_color(struct nk_context *ctx, struct nk_image img, struct nk_color col) |
| 19666 |
{ |
| 19667 |
struct nk_window *win; |
| 19668 |
struct nk_rect bounds; |
| 19669 |
|
| 19670 |
NK_ASSERT(ctx); |
| 19671 |
NK_ASSERT(ctx->current); |
| 19672 |
NK_ASSERT(ctx->current->layout); |
| 19673 |
if (!ctx || !ctx->current || !ctx->current->layout) return; |
| 19674 |
|
| 19675 |
win = ctx->current; |
| 19676 |
if (!nk_widget(&bounds, ctx)) return; |
| 19677 |
nk_draw_image(&win->buffer, bounds, &img, col); |
| 19678 |
} |
| 19679 |
|
| 19680 |
|
| 19681 |
|
| 19682 |
|
| 19683 |
|
| 19684 |
|
| 19685 |
|
| 19686 |
|
| 19687 |
|
| 19688 |
|
| 19689 |
NK_LIB void |
| 19690 |
nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type, |
| 19691 |
struct nk_rect content, struct nk_color background, struct nk_color foreground, |
| 19692 |
float border_width, const struct nk_user_font *font) |
| 19693 |
{ |
| 19694 |
switch (type) { |
| 19695 |
case NK_SYMBOL_X: |
| 19696 |
case NK_SYMBOL_UNDERSCORE: |
| 19697 |
case NK_SYMBOL_PLUS: |
| 19698 |
case NK_SYMBOL_MINUS: { |
| 19699 |
|
| 19700 |
const char *X = (type == NK_SYMBOL_X) ? "x": |
| 19701 |
(type == NK_SYMBOL_UNDERSCORE) ? "_": |
| 19702 |
(type == NK_SYMBOL_PLUS) ? "+": "-"; |
| 19703 |
struct nk_text text; |
| 19704 |
text.padding = nk_vec2(0,0); |
| 19705 |
text.background = background; |
| 19706 |
text.text = foreground; |
| 19707 |
nk_widget_text(out, content, X, 1, &text, NK_TEXT_CENTERED, font); |
| 19708 |
} break; |
| 19709 |
case NK_SYMBOL_CIRCLE_SOLID: |
| 19710 |
case NK_SYMBOL_CIRCLE_OUTLINE: |
| 19711 |
case NK_SYMBOL_RECT_SOLID: |
| 19712 |
case NK_SYMBOL_RECT_OUTLINE: { |
| 19713 |
|
| 19714 |
if (type == NK_SYMBOL_RECT_SOLID || type == NK_SYMBOL_RECT_OUTLINE) { |
| 19715 |
nk_fill_rect(out, content, 0, foreground); |
| 19716 |
if (type == NK_SYMBOL_RECT_OUTLINE) |
| 19717 |
nk_fill_rect(out, nk_shrink_rect(content, border_width), 0, background); |
| 19718 |
} else { |
| 19719 |
nk_fill_circle(out, content, foreground); |
| 19720 |
if (type == NK_SYMBOL_CIRCLE_OUTLINE) |
| 19721 |
nk_fill_circle(out, nk_shrink_rect(content, 1), background); |
| 19722 |
} |
| 19723 |
} break; |
| 19724 |
case NK_SYMBOL_TRIANGLE_UP: |
| 19725 |
case NK_SYMBOL_TRIANGLE_DOWN: |
| 19726 |
case NK_SYMBOL_TRIANGLE_LEFT: |
| 19727 |
case NK_SYMBOL_TRIANGLE_RIGHT: { |
| 19728 |
enum nk_heading heading; |
| 19729 |
struct nk_vec2 points[3]; |
| 19730 |
heading = (type == NK_SYMBOL_TRIANGLE_RIGHT) ? NK_RIGHT : |
| 19731 |
(type == NK_SYMBOL_TRIANGLE_LEFT) ? NK_LEFT: |
| 19732 |
(type == NK_SYMBOL_TRIANGLE_UP) ? NK_UP: NK_DOWN; |
| 19733 |
nk_triangle_from_direction(points, content, 0, 0, heading); |
| 19734 |
nk_fill_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y, |
| 19735 |
points[2].x, points[2].y, foreground); |
| 19736 |
} break; |
| 19737 |
default: |
| 19738 |
case NK_SYMBOL_NONE: |
| 19739 |
case NK_SYMBOL_MAX: break; |
| 19740 |
} |
| 19741 |
} |
| 19742 |
NK_LIB int |
| 19743 |
nk_button_behavior(nk_flags *state, struct nk_rect r, |
| 19744 |
const struct nk_input *i, enum nk_button_behavior behavior) |
| 19745 |
{ |
| 19746 |
int ret = 0; |
| 19747 |
nk_widget_state_reset(state); |
| 19748 |
if (!i) return 0; |
| 19749 |
if (nk_input_is_mouse_hovering_rect(i, r)) { |
| 19750 |
*state = NK_WIDGET_STATE_HOVERED; |
| 19751 |
if (nk_input_is_mouse_down(i, NK_BUTTON_LEFT)) |
| 19752 |
*state = NK_WIDGET_STATE_ACTIVE; |
| 19753 |
if (nk_input_has_mouse_click_in_rect(i, NK_BUTTON_LEFT, r)) { |
| 19754 |
ret = (behavior != NK_BUTTON_DEFAULT) ? |
| 19755 |
nk_input_is_mouse_down(i, NK_BUTTON_LEFT): |
| 19756 |
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE |
| 19757 |
nk_input_is_mouse_released(i, NK_BUTTON_LEFT); |
| 19758 |
#else |
| 19759 |
nk_input_is_mouse_pressed(i, NK_BUTTON_LEFT); |
| 19760 |
#endif |
| 19761 |
} |
| 19762 |
} |
| 19763 |
if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(i, r)) |
| 19764 |
*state |= NK_WIDGET_STATE_ENTERED; |
| 19765 |
else if (nk_input_is_mouse_prev_hovering_rect(i, r)) |
| 19766 |
*state |= NK_WIDGET_STATE_LEFT; |
| 19767 |
return ret; |
| 19768 |
} |
| 19769 |
NK_LIB const struct nk_style_item* |
| 19770 |
nk_draw_button(struct nk_command_buffer *out, |
| 19771 |
const struct nk_rect *bounds, nk_flags state, |
| 19772 |
const struct nk_style_button *style) |
| 19773 |
{ |
| 19774 |
const struct nk_style_item *background; |
| 19775 |
if (state & NK_WIDGET_STATE_HOVER) |
| 19776 |
background = &style->hover; |
| 19777 |
else if (state & NK_WIDGET_STATE_ACTIVED) |
| 19778 |
background = &style->active; |
| 19779 |
else background = &style->normal; |
| 19780 |
|
| 19781 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 19782 |
nk_draw_image(out, *bounds, &background->data.image, nk_white); |
| 19783 |
} else { |
| 19784 |
nk_fill_rect(out, *bounds, style->rounding, background->data.color); |
| 19785 |
nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); |
| 19786 |
} |
| 19787 |
return background; |
| 19788 |
} |
| 19789 |
NK_LIB int |
| 19790 |
nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, |
| 19791 |
const struct nk_style_button *style, const struct nk_input *in, |
| 19792 |
enum nk_button_behavior behavior, struct nk_rect *content) |
| 19793 |
{ |
| 19794 |
struct nk_rect bounds; |
| 19795 |
NK_ASSERT(style); |
| 19796 |
NK_ASSERT(state); |
| 19797 |
NK_ASSERT(out); |
| 19798 |
if (!out || !style) |
| 19799 |
return nk_false; |
| 19800 |
|
| 19801 |
|
| 19802 |
content->x = r.x + style->padding.x + style->border + style->rounding; |
| 19803 |
content->y = r.y + style->padding.y + style->border + style->rounding; |
| 19804 |
content->w = r.w - (2 * style->padding.x + style->border + style->rounding*2); |
| 19805 |
content->h = r.h - (2 * style->padding.y + style->border + style->rounding*2); |
| 19806 |
|
| 19807 |
|
| 19808 |
bounds.x = r.x - style->touch_padding.x; |
| 19809 |
bounds.y = r.y - style->touch_padding.y; |
| 19810 |
bounds.w = r.w + 2 * style->touch_padding.x; |
| 19811 |
bounds.h = r.h + 2 * style->touch_padding.y; |
| 19812 |
return nk_button_behavior(state, bounds, in, behavior); |
| 19813 |
} |
| 19814 |
NK_LIB void |
| 19815 |
nk_draw_button_text(struct nk_command_buffer *out, |
| 19816 |
const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, |
| 19817 |
const struct nk_style_button *style, const char *txt, int len, |
| 19818 |
nk_flags text_alignment, const struct nk_user_font *font) |
| 19819 |
{ |
| 19820 |
struct nk_text text; |
| 19821 |
const struct nk_style_item *background; |
| 19822 |
background = nk_draw_button(out, bounds, state, style); |
| 19823 |
|
| 19824 |
|
| 19825 |
if (background->type == NK_STYLE_ITEM_COLOR) |
| 19826 |
text.background = background->data.color; |
| 19827 |
else text.background = style->text_background; |
| 19828 |
if (state & NK_WIDGET_STATE_HOVER) |
| 19829 |
text.text = style->text_hover; |
| 19830 |
else if (state & NK_WIDGET_STATE_ACTIVED) |
| 19831 |
text.text = style->text_active; |
| 19832 |
else text.text = style->text_normal; |
| 19833 |
|
| 19834 |
text.padding = nk_vec2(0,0); |
| 19835 |
nk_widget_text(out, *content, txt, len, &text, text_alignment, font); |
| 19836 |
} |
| 19837 |
NK_LIB int |
| 19838 |
nk_do_button_text(nk_flags *state, |
| 19839 |
struct nk_command_buffer *out, struct nk_rect bounds, |
| 19840 |
const char *string, int len, nk_flags align, enum nk_button_behavior behavior, |
| 19841 |
const struct nk_style_button *style, const struct nk_input *in, |
| 19842 |
const struct nk_user_font *font) |
| 19843 |
{ |
| 19844 |
struct nk_rect content; |
| 19845 |
int ret = nk_false; |
| 19846 |
|
| 19847 |
NK_ASSERT(state); |
| 19848 |
NK_ASSERT(style); |
| 19849 |
NK_ASSERT(out); |
| 19850 |
NK_ASSERT(string); |
| 19851 |
NK_ASSERT(font); |
| 19852 |
if (!out || !style || !font || !string) |
| 19853 |
return nk_false; |
| 19854 |
|
| 19855 |
ret = nk_do_button(state, out, bounds, style, in, behavior, &content); |
| 19856 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 19857 |
nk_draw_button_text(out, &bounds, &content, *state, style, string, len, align, font); |
| 19858 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 19859 |
return ret; |
| 19860 |
} |
| 19861 |
NK_LIB void |
| 19862 |
nk_draw_button_symbol(struct nk_command_buffer *out, |
| 19863 |
const struct nk_rect *bounds, const struct nk_rect *content, |
| 19864 |
nk_flags state, const struct nk_style_button *style, |
| 19865 |
enum nk_symbol_type type, const struct nk_user_font *font) |
| 19866 |
{ |
| 19867 |
struct nk_color sym, bg; |
| 19868 |
const struct nk_style_item *background; |
| 19869 |
|
| 19870 |
|
| 19871 |
background = nk_draw_button(out, bounds, state, style); |
| 19872 |
if (background->type == NK_STYLE_ITEM_COLOR) |
| 19873 |
bg = background->data.color; |
| 19874 |
else bg = style->text_background; |
| 19875 |
|
| 19876 |
if (state & NK_WIDGET_STATE_HOVER) |
| 19877 |
sym = style->text_hover; |
| 19878 |
else if (state & NK_WIDGET_STATE_ACTIVED) |
| 19879 |
sym = style->text_active; |
| 19880 |
else sym = style->text_normal; |
| 19881 |
nk_draw_symbol(out, type, *content, bg, sym, 1, font); |
| 19882 |
} |
| 19883 |
NK_LIB int |
| 19884 |
nk_do_button_symbol(nk_flags *state, |
| 19885 |
struct nk_command_buffer *out, struct nk_rect bounds, |
| 19886 |
enum nk_symbol_type symbol, enum nk_button_behavior behavior, |
| 19887 |
const struct nk_style_button *style, const struct nk_input *in, |
| 19888 |
const struct nk_user_font *font) |
| 19889 |
{ |
| 19890 |
int ret; |
| 19891 |
struct nk_rect content; |
| 19892 |
|
| 19893 |
NK_ASSERT(state); |
| 19894 |
NK_ASSERT(style); |
| 19895 |
NK_ASSERT(font); |
| 19896 |
NK_ASSERT(out); |
| 19897 |
if (!out || !style || !font || !state) |
| 19898 |
return nk_false; |
| 19899 |
|
| 19900 |
ret = nk_do_button(state, out, bounds, style, in, behavior, &content); |
| 19901 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 19902 |
nk_draw_button_symbol(out, &bounds, &content, *state, style, symbol, font); |
| 19903 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 19904 |
return ret; |
| 19905 |
} |
| 19906 |
NK_LIB void |
| 19907 |
nk_draw_button_image(struct nk_command_buffer *out, |
| 19908 |
const struct nk_rect *bounds, const struct nk_rect *content, |
| 19909 |
nk_flags state, const struct nk_style_button *style, const struct nk_image *img) |
| 19910 |
{ |
| 19911 |
nk_draw_button(out, bounds, state, style); |
| 19912 |
nk_draw_image(out, *content, img, nk_white); |
| 19913 |
} |
| 19914 |
NK_LIB int |
| 19915 |
nk_do_button_image(nk_flags *state, |
| 19916 |
struct nk_command_buffer *out, struct nk_rect bounds, |
| 19917 |
struct nk_image img, enum nk_button_behavior b, |
| 19918 |
const struct nk_style_button *style, const struct nk_input *in) |
| 19919 |
{ |
| 19920 |
int ret; |
| 19921 |
struct nk_rect content; |
| 19922 |
|
| 19923 |
NK_ASSERT(state); |
| 19924 |
NK_ASSERT(style); |
| 19925 |
NK_ASSERT(out); |
| 19926 |
if (!out || !style || !state) |
| 19927 |
return nk_false; |
| 19928 |
|
| 19929 |
ret = nk_do_button(state, out, bounds, style, in, b, &content); |
| 19930 |
content.x += style->image_padding.x; |
| 19931 |
content.y += style->image_padding.y; |
| 19932 |
content.w -= 2 * style->image_padding.x; |
| 19933 |
content.h -= 2 * style->image_padding.y; |
| 19934 |
|
| 19935 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 19936 |
nk_draw_button_image(out, &bounds, &content, *state, style, &img); |
| 19937 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 19938 |
return ret; |
| 19939 |
} |
| 19940 |
NK_LIB void |
| 19941 |
nk_draw_button_text_symbol(struct nk_command_buffer *out, |
| 19942 |
const struct nk_rect *bounds, const struct nk_rect *label, |
| 19943 |
const struct nk_rect *symbol, nk_flags state, const struct nk_style_button *style, |
| 19944 |
const char *str, int len, enum nk_symbol_type type, |
| 19945 |
const struct nk_user_font *font) |
| 19946 |
{ |
| 19947 |
struct nk_color sym; |
| 19948 |
struct nk_text text; |
| 19949 |
const struct nk_style_item *background; |
| 19950 |
|
| 19951 |
|
| 19952 |
background = nk_draw_button(out, bounds, state, style); |
| 19953 |
if (background->type == NK_STYLE_ITEM_COLOR) |
| 19954 |
text.background = background->data.color; |
| 19955 |
else text.background = style->text_background; |
| 19956 |
|
| 19957 |
|
| 19958 |
if (state & NK_WIDGET_STATE_HOVER) { |
| 19959 |
sym = style->text_hover; |
| 19960 |
text.text = style->text_hover; |
| 19961 |
} else if (state & NK_WIDGET_STATE_ACTIVED) { |
| 19962 |
sym = style->text_active; |
| 19963 |
text.text = style->text_active; |
| 19964 |
} else { |
| 19965 |
sym = style->text_normal; |
| 19966 |
text.text = style->text_normal; |
| 19967 |
} |
| 19968 |
|
| 19969 |
text.padding = nk_vec2(0,0); |
| 19970 |
nk_draw_symbol(out, type, *symbol, style->text_background, sym, 0, font); |
| 19971 |
nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); |
| 19972 |
} |
| 19973 |
NK_LIB int |
| 19974 |
nk_do_button_text_symbol(nk_flags *state, |
| 19975 |
struct nk_command_buffer *out, struct nk_rect bounds, |
| 19976 |
enum nk_symbol_type symbol, const char *str, int len, nk_flags align, |
| 19977 |
enum nk_button_behavior behavior, const struct nk_style_button *style, |
| 19978 |
const struct nk_user_font *font, const struct nk_input *in) |
| 19979 |
{ |
| 19980 |
int ret; |
| 19981 |
struct nk_rect tri = {0,0,0,0}; |
| 19982 |
struct nk_rect content; |
| 19983 |
|
| 19984 |
NK_ASSERT(style); |
| 19985 |
NK_ASSERT(out); |
| 19986 |
NK_ASSERT(font); |
| 19987 |
if (!out || !style || !font) |
| 19988 |
return nk_false; |
| 19989 |
|
| 19990 |
ret = nk_do_button(state, out, bounds, style, in, behavior, &content); |
| 19991 |
tri.y = content.y + (content.h/2) - font->height/2; |
| 19992 |
tri.w = font->height; tri.h = font->height; |
| 19993 |
if (align & NK_TEXT_ALIGN_LEFT) { |
| 19994 |
tri.x = (content.x + content.w) - (2 * style->padding.x + tri.w); |
| 19995 |
tri.x = NK_MAX(tri.x, 0); |
| 19996 |
} else tri.x = content.x + 2 * style->padding.x; |
| 19997 |
|
| 19998 |
|
| 19999 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 20000 |
nk_draw_button_text_symbol(out, &bounds, &content, &tri, |
| 20001 |
*state, style, str, len, symbol, font); |
| 20002 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 20003 |
return ret; |
| 20004 |
} |
| 20005 |
NK_LIB void |
| 20006 |
nk_draw_button_text_image(struct nk_command_buffer *out, |
| 20007 |
const struct nk_rect *bounds, const struct nk_rect *label, |
| 20008 |
const struct nk_rect *image, nk_flags state, const struct nk_style_button *style, |
| 20009 |
const char *str, int len, const struct nk_user_font *font, |
| 20010 |
const struct nk_image *img) |
| 20011 |
{ |
| 20012 |
struct nk_text text; |
| 20013 |
const struct nk_style_item *background; |
| 20014 |
background = nk_draw_button(out, bounds, state, style); |
| 20015 |
|
| 20016 |
|
| 20017 |
if (background->type == NK_STYLE_ITEM_COLOR) |
| 20018 |
text.background = background->data.color; |
| 20019 |
else text.background = style->text_background; |
| 20020 |
if (state & NK_WIDGET_STATE_HOVER) |
| 20021 |
text.text = style->text_hover; |
| 20022 |
else if (state & NK_WIDGET_STATE_ACTIVED) |
| 20023 |
text.text = style->text_active; |
| 20024 |
else text.text = style->text_normal; |
| 20025 |
|
| 20026 |
text.padding = nk_vec2(0,0); |
| 20027 |
nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); |
| 20028 |
nk_draw_image(out, *image, img, nk_white); |
| 20029 |
} |
| 20030 |
NK_LIB int |
| 20031 |
nk_do_button_text_image(nk_flags *state, |
| 20032 |
struct nk_command_buffer *out, struct nk_rect bounds, |
| 20033 |
struct nk_image img, const char* str, int len, nk_flags align, |
| 20034 |
enum nk_button_behavior behavior, const struct nk_style_button *style, |
| 20035 |
const struct nk_user_font *font, const struct nk_input *in) |
| 20036 |
{ |
| 20037 |
int ret; |
| 20038 |
struct nk_rect icon; |
| 20039 |
struct nk_rect content; |
| 20040 |
|
| 20041 |
NK_ASSERT(style); |
| 20042 |
NK_ASSERT(state); |
| 20043 |
NK_ASSERT(font); |
| 20044 |
NK_ASSERT(out); |
| 20045 |
if (!out || !font || !style || !str) |
| 20046 |
return nk_false; |
| 20047 |
|
| 20048 |
ret = nk_do_button(state, out, bounds, style, in, behavior, &content); |
| 20049 |
icon.y = bounds.y + style->padding.y; |
| 20050 |
icon.w = icon.h = bounds.h - 2 * style->padding.y; |
| 20051 |
if (align & NK_TEXT_ALIGN_LEFT) { |
| 20052 |
icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w); |
| 20053 |
icon.x = NK_MAX(icon.x, 0); |
| 20054 |
} else icon.x = bounds.x + 2 * style->padding.x; |
| 20055 |
|
| 20056 |
icon.x += style->image_padding.x; |
| 20057 |
icon.y += style->image_padding.y; |
| 20058 |
icon.w -= 2 * style->image_padding.x; |
| 20059 |
icon.h -= 2 * style->image_padding.y; |
| 20060 |
|
| 20061 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 20062 |
nk_draw_button_text_image(out, &bounds, &content, &icon, *state, style, str, len, font, &img); |
| 20063 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 20064 |
return ret; |
| 20065 |
} |
| 20066 |
NK_API void |
| 20067 |
nk_button_set_behavior(struct nk_context *ctx, enum nk_button_behavior behavior) |
| 20068 |
{ |
| 20069 |
NK_ASSERT(ctx); |
| 20070 |
if (!ctx) return; |
| 20071 |
ctx->button_behavior = behavior; |
| 20072 |
} |
| 20073 |
NK_API int |
| 20074 |
nk_button_push_behavior(struct nk_context *ctx, enum nk_button_behavior behavior) |
| 20075 |
{ |
| 20076 |
struct nk_config_stack_button_behavior *button_stack; |
| 20077 |
struct nk_config_stack_button_behavior_element *element; |
| 20078 |
|
| 20079 |
NK_ASSERT(ctx); |
| 20080 |
if (!ctx) return 0; |
| 20081 |
|
| 20082 |
button_stack = &ctx->stacks.button_behaviors; |
| 20083 |
NK_ASSERT(button_stack->head < (int)NK_LEN(button_stack->elements)); |
| 20084 |
if (button_stack->head >= (int)NK_LEN(button_stack->elements)) |
| 20085 |
return 0; |
| 20086 |
|
| 20087 |
element = &button_stack->elements[button_stack->head++]; |
| 20088 |
element->address = &ctx->button_behavior; |
| 20089 |
element->old_value = ctx->button_behavior; |
| 20090 |
ctx->button_behavior = behavior; |
| 20091 |
return 1; |
| 20092 |
} |
| 20093 |
NK_API int |
| 20094 |
nk_button_pop_behavior(struct nk_context *ctx) |
| 20095 |
{ |
| 20096 |
struct nk_config_stack_button_behavior *button_stack; |
| 20097 |
struct nk_config_stack_button_behavior_element *element; |
| 20098 |
|
| 20099 |
NK_ASSERT(ctx); |
| 20100 |
if (!ctx) return 0; |
| 20101 |
|
| 20102 |
button_stack = &ctx->stacks.button_behaviors; |
| 20103 |
NK_ASSERT(button_stack->head > 0); |
| 20104 |
if (button_stack->head < 1) |
| 20105 |
return 0; |
| 20106 |
|
| 20107 |
element = &button_stack->elements[--button_stack->head]; |
| 20108 |
*element->address = element->old_value; |
| 20109 |
return 1; |
| 20110 |
} |
| 20111 |
NK_API int |
| 20112 |
nk_button_text_styled(struct nk_context *ctx, |
| 20113 |
const struct nk_style_button *style, const char *title, int len) |
| 20114 |
{ |
| 20115 |
struct nk_window *win; |
| 20116 |
struct nk_panel *layout; |
| 20117 |
const struct nk_input *in; |
| 20118 |
|
| 20119 |
struct nk_rect bounds; |
| 20120 |
enum nk_widget_layout_states state; |
| 20121 |
|
| 20122 |
NK_ASSERT(ctx); |
| 20123 |
NK_ASSERT(style); |
| 20124 |
NK_ASSERT(ctx->current); |
| 20125 |
NK_ASSERT(ctx->current->layout); |
| 20126 |
if (!style || !ctx || !ctx->current || !ctx->current->layout) return 0; |
| 20127 |
|
| 20128 |
win = ctx->current; |
| 20129 |
layout = win->layout; |
| 20130 |
state = nk_widget(&bounds, ctx); |
| 20131 |
|
| 20132 |
if (!state) return 0; |
| 20133 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20134 |
return nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, |
| 20135 |
title, len, style->text_alignment, ctx->button_behavior, |
| 20136 |
style, in, ctx->style.font); |
| 20137 |
} |
| 20138 |
NK_API int |
| 20139 |
nk_button_text(struct nk_context *ctx, const char *title, int len) |
| 20140 |
{ |
| 20141 |
NK_ASSERT(ctx); |
| 20142 |
if (!ctx) return 0; |
| 20143 |
return nk_button_text_styled(ctx, &ctx->style.button, title, len); |
| 20144 |
} |
| 20145 |
NK_API int nk_button_label_styled(struct nk_context *ctx, |
| 20146 |
const struct nk_style_button *style, const char *title) |
| 20147 |
{ |
| 20148 |
return nk_button_text_styled(ctx, style, title, nk_strlen(title)); |
| 20149 |
} |
| 20150 |
NK_API int nk_button_label(struct nk_context *ctx, const char *title) |
| 20151 |
{ |
| 20152 |
return nk_button_text(ctx, title, nk_strlen(title)); |
| 20153 |
} |
| 20154 |
NK_API int |
| 20155 |
nk_button_color(struct nk_context *ctx, struct nk_color color) |
| 20156 |
{ |
| 20157 |
struct nk_window *win; |
| 20158 |
struct nk_panel *layout; |
| 20159 |
const struct nk_input *in; |
| 20160 |
struct nk_style_button button; |
| 20161 |
|
| 20162 |
int ret = 0; |
| 20163 |
struct nk_rect bounds; |
| 20164 |
struct nk_rect content; |
| 20165 |
enum nk_widget_layout_states state; |
| 20166 |
|
| 20167 |
NK_ASSERT(ctx); |
| 20168 |
NK_ASSERT(ctx->current); |
| 20169 |
NK_ASSERT(ctx->current->layout); |
| 20170 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 20171 |
return 0; |
| 20172 |
|
| 20173 |
win = ctx->current; |
| 20174 |
layout = win->layout; |
| 20175 |
|
| 20176 |
state = nk_widget(&bounds, ctx); |
| 20177 |
if (!state) return 0; |
| 20178 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20179 |
|
| 20180 |
button = ctx->style.button; |
| 20181 |
button.normal = nk_style_item_color(color); |
| 20182 |
button.hover = nk_style_item_color(color); |
| 20183 |
button.active = nk_style_item_color(color); |
| 20184 |
ret = nk_do_button(&ctx->last_widget_state, &win->buffer, bounds, |
| 20185 |
&button, in, ctx->button_behavior, &content); |
| 20186 |
nk_draw_button(&win->buffer, &bounds, ctx->last_widget_state, &button); |
| 20187 |
return ret; |
| 20188 |
} |
| 20189 |
NK_API int |
| 20190 |
nk_button_symbol_styled(struct nk_context *ctx, |
| 20191 |
const struct nk_style_button *style, enum nk_symbol_type symbol) |
| 20192 |
{ |
| 20193 |
struct nk_window *win; |
| 20194 |
struct nk_panel *layout; |
| 20195 |
const struct nk_input *in; |
| 20196 |
|
| 20197 |
struct nk_rect bounds; |
| 20198 |
enum nk_widget_layout_states state; |
| 20199 |
|
| 20200 |
NK_ASSERT(ctx); |
| 20201 |
NK_ASSERT(ctx->current); |
| 20202 |
NK_ASSERT(ctx->current->layout); |
| 20203 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 20204 |
return 0; |
| 20205 |
|
| 20206 |
win = ctx->current; |
| 20207 |
layout = win->layout; |
| 20208 |
state = nk_widget(&bounds, ctx); |
| 20209 |
if (!state) return 0; |
| 20210 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20211 |
return nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds, |
| 20212 |
symbol, ctx->button_behavior, style, in, ctx->style.font); |
| 20213 |
} |
| 20214 |
NK_API int |
| 20215 |
nk_button_symbol(struct nk_context *ctx, enum nk_symbol_type symbol) |
| 20216 |
{ |
| 20217 |
NK_ASSERT(ctx); |
| 20218 |
if (!ctx) return 0; |
| 20219 |
return nk_button_symbol_styled(ctx, &ctx->style.button, symbol); |
| 20220 |
} |
| 20221 |
NK_API int |
| 20222 |
nk_button_image_styled(struct nk_context *ctx, const struct nk_style_button *style, |
| 20223 |
struct nk_image img) |
| 20224 |
{ |
| 20225 |
struct nk_window *win; |
| 20226 |
struct nk_panel *layout; |
| 20227 |
const struct nk_input *in; |
| 20228 |
|
| 20229 |
struct nk_rect bounds; |
| 20230 |
enum nk_widget_layout_states state; |
| 20231 |
|
| 20232 |
NK_ASSERT(ctx); |
| 20233 |
NK_ASSERT(ctx->current); |
| 20234 |
NK_ASSERT(ctx->current->layout); |
| 20235 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 20236 |
return 0; |
| 20237 |
|
| 20238 |
win = ctx->current; |
| 20239 |
layout = win->layout; |
| 20240 |
|
| 20241 |
state = nk_widget(&bounds, ctx); |
| 20242 |
if (!state) return 0; |
| 20243 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20244 |
return nk_do_button_image(&ctx->last_widget_state, &win->buffer, bounds, |
| 20245 |
img, ctx->button_behavior, style, in); |
| 20246 |
} |
| 20247 |
NK_API int |
| 20248 |
nk_button_image(struct nk_context *ctx, struct nk_image img) |
| 20249 |
{ |
| 20250 |
NK_ASSERT(ctx); |
| 20251 |
if (!ctx) return 0; |
| 20252 |
return nk_button_image_styled(ctx, &ctx->style.button, img); |
| 20253 |
} |
| 20254 |
NK_API int |
| 20255 |
nk_button_symbol_text_styled(struct nk_context *ctx, |
| 20256 |
const struct nk_style_button *style, enum nk_symbol_type symbol, |
| 20257 |
const char *text, int len, nk_flags align) |
| 20258 |
{ |
| 20259 |
struct nk_window *win; |
| 20260 |
struct nk_panel *layout; |
| 20261 |
const struct nk_input *in; |
| 20262 |
|
| 20263 |
struct nk_rect bounds; |
| 20264 |
enum nk_widget_layout_states state; |
| 20265 |
|
| 20266 |
NK_ASSERT(ctx); |
| 20267 |
NK_ASSERT(ctx->current); |
| 20268 |
NK_ASSERT(ctx->current->layout); |
| 20269 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 20270 |
return 0; |
| 20271 |
|
| 20272 |
win = ctx->current; |
| 20273 |
layout = win->layout; |
| 20274 |
|
| 20275 |
state = nk_widget(&bounds, ctx); |
| 20276 |
if (!state) return 0; |
| 20277 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20278 |
return nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds, |
| 20279 |
symbol, text, len, align, ctx->button_behavior, |
| 20280 |
style, ctx->style.font, in); |
| 20281 |
} |
| 20282 |
NK_API int |
| 20283 |
nk_button_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbol, |
| 20284 |
const char* text, int len, nk_flags align) |
| 20285 |
{ |
| 20286 |
NK_ASSERT(ctx); |
| 20287 |
if (!ctx) return 0; |
| 20288 |
return nk_button_symbol_text_styled(ctx, &ctx->style.button, symbol, text, len, align); |
| 20289 |
} |
| 20290 |
NK_API int nk_button_symbol_label(struct nk_context *ctx, enum nk_symbol_type symbol, |
| 20291 |
const char *label, nk_flags align) |
| 20292 |
{ |
| 20293 |
return nk_button_symbol_text(ctx, symbol, label, nk_strlen(label), align); |
| 20294 |
} |
| 20295 |
NK_API int nk_button_symbol_label_styled(struct nk_context *ctx, |
| 20296 |
const struct nk_style_button *style, enum nk_symbol_type symbol, |
| 20297 |
const char *title, nk_flags align) |
| 20298 |
{ |
| 20299 |
return nk_button_symbol_text_styled(ctx, style, symbol, title, nk_strlen(title), align); |
| 20300 |
} |
| 20301 |
NK_API int |
| 20302 |
nk_button_image_text_styled(struct nk_context *ctx, |
| 20303 |
const struct nk_style_button *style, struct nk_image img, const char *text, |
| 20304 |
int len, nk_flags align) |
| 20305 |
{ |
| 20306 |
struct nk_window *win; |
| 20307 |
struct nk_panel *layout; |
| 20308 |
const struct nk_input *in; |
| 20309 |
|
| 20310 |
struct nk_rect bounds; |
| 20311 |
enum nk_widget_layout_states state; |
| 20312 |
|
| 20313 |
NK_ASSERT(ctx); |
| 20314 |
NK_ASSERT(ctx->current); |
| 20315 |
NK_ASSERT(ctx->current->layout); |
| 20316 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 20317 |
return 0; |
| 20318 |
|
| 20319 |
win = ctx->current; |
| 20320 |
layout = win->layout; |
| 20321 |
|
| 20322 |
state = nk_widget(&bounds, ctx); |
| 20323 |
if (!state) return 0; |
| 20324 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20325 |
return nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, |
| 20326 |
bounds, img, text, len, align, ctx->button_behavior, |
| 20327 |
style, ctx->style.font, in); |
| 20328 |
} |
| 20329 |
NK_API int |
| 20330 |
nk_button_image_text(struct nk_context *ctx, struct nk_image img, |
| 20331 |
const char *text, int len, nk_flags align) |
| 20332 |
{ |
| 20333 |
return nk_button_image_text_styled(ctx, &ctx->style.button,img, text, len, align); |
| 20334 |
} |
| 20335 |
NK_API int nk_button_image_label(struct nk_context *ctx, struct nk_image img, |
| 20336 |
const char *label, nk_flags align) |
| 20337 |
{ |
| 20338 |
return nk_button_image_text(ctx, img, label, nk_strlen(label), align); |
| 20339 |
} |
| 20340 |
NK_API int nk_button_image_label_styled(struct nk_context *ctx, |
| 20341 |
const struct nk_style_button *style, struct nk_image img, |
| 20342 |
const char *label, nk_flags text_alignment) |
| 20343 |
{ |
| 20344 |
return nk_button_image_text_styled(ctx, style, img, label, nk_strlen(label), text_alignment); |
| 20345 |
} |
| 20346 |
|
| 20347 |
|
| 20348 |
|
| 20349 |
|
| 20350 |
|
| 20351 |
|
| 20352 |
|
| 20353 |
|
| 20354 |
|
| 20355 |
|
| 20356 |
NK_LIB int |
| 20357 |
nk_toggle_behavior(const struct nk_input *in, struct nk_rect select, |
| 20358 |
nk_flags *state, int active) |
| 20359 |
{ |
| 20360 |
nk_widget_state_reset(state); |
| 20361 |
if (nk_button_behavior(state, select, in, NK_BUTTON_DEFAULT)) { |
| 20362 |
*state = NK_WIDGET_STATE_ACTIVE; |
| 20363 |
active = !active; |
| 20364 |
} |
| 20365 |
if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, select)) |
| 20366 |
*state |= NK_WIDGET_STATE_ENTERED; |
| 20367 |
else if (nk_input_is_mouse_prev_hovering_rect(in, select)) |
| 20368 |
*state |= NK_WIDGET_STATE_LEFT; |
| 20369 |
return active; |
| 20370 |
} |
| 20371 |
NK_LIB void |
| 20372 |
nk_draw_checkbox(struct nk_command_buffer *out, |
| 20373 |
nk_flags state, const struct nk_style_toggle *style, int active, |
| 20374 |
const struct nk_rect *label, const struct nk_rect *selector, |
| 20375 |
const struct nk_rect *cursors, const char *string, int len, |
| 20376 |
const struct nk_user_font *font) |
| 20377 |
{ |
| 20378 |
const struct nk_style_item *background; |
| 20379 |
const struct nk_style_item *cursor; |
| 20380 |
struct nk_text text; |
| 20381 |
|
| 20382 |
|
| 20383 |
if (state & NK_WIDGET_STATE_HOVER) { |
| 20384 |
background = &style->hover; |
| 20385 |
cursor = &style->cursor_hover; |
| 20386 |
text.text = style->text_hover; |
| 20387 |
} else if (state & NK_WIDGET_STATE_ACTIVED) { |
| 20388 |
background = &style->hover; |
| 20389 |
cursor = &style->cursor_hover; |
| 20390 |
text.text = style->text_active; |
| 20391 |
} else { |
| 20392 |
background = &style->normal; |
| 20393 |
cursor = &style->cursor_normal; |
| 20394 |
text.text = style->text_normal; |
| 20395 |
} |
| 20396 |
|
| 20397 |
|
| 20398 |
if (background->type == NK_STYLE_ITEM_COLOR) { |
| 20399 |
nk_fill_rect(out, *selector, 0, style->border_color); |
| 20400 |
nk_fill_rect(out, nk_shrink_rect(*selector, style->border), 0, background->data.color); |
| 20401 |
} else nk_draw_image(out, *selector, &background->data.image, nk_white); |
| 20402 |
if (active) { |
| 20403 |
if (cursor->type == NK_STYLE_ITEM_IMAGE) |
| 20404 |
nk_draw_image(out, *cursors, &cursor->data.image, nk_white); |
| 20405 |
else nk_fill_rect(out, *cursors, 0, cursor->data.color); |
| 20406 |
} |
| 20407 |
|
| 20408 |
text.padding.x = 0; |
| 20409 |
text.padding.y = 0; |
| 20410 |
text.background = style->text_background; |
| 20411 |
nk_widget_text(out, *label, string, len, &text, NK_TEXT_LEFT, font); |
| 20412 |
} |
| 20413 |
NK_LIB void |
| 20414 |
nk_draw_option(struct nk_command_buffer *out, |
| 20415 |
nk_flags state, const struct nk_style_toggle *style, int active, |
| 20416 |
const struct nk_rect *label, const struct nk_rect *selector, |
| 20417 |
const struct nk_rect *cursors, const char *string, int len, |
| 20418 |
const struct nk_user_font *font) |
| 20419 |
{ |
| 20420 |
const struct nk_style_item *background; |
| 20421 |
const struct nk_style_item *cursor; |
| 20422 |
struct nk_text text; |
| 20423 |
|
| 20424 |
|
| 20425 |
if (state & NK_WIDGET_STATE_HOVER) { |
| 20426 |
background = &style->hover; |
| 20427 |
cursor = &style->cursor_hover; |
| 20428 |
text.text = style->text_hover; |
| 20429 |
} else if (state & NK_WIDGET_STATE_ACTIVED) { |
| 20430 |
background = &style->hover; |
| 20431 |
cursor = &style->cursor_hover; |
| 20432 |
text.text = style->text_active; |
| 20433 |
} else { |
| 20434 |
background = &style->normal; |
| 20435 |
cursor = &style->cursor_normal; |
| 20436 |
text.text = style->text_normal; |
| 20437 |
} |
| 20438 |
|
| 20439 |
|
| 20440 |
if (background->type == NK_STYLE_ITEM_COLOR) { |
| 20441 |
nk_fill_circle(out, *selector, style->border_color); |
| 20442 |
nk_fill_circle(out, nk_shrink_rect(*selector, style->border), background->data.color); |
| 20443 |
} else nk_draw_image(out, *selector, &background->data.image, nk_white); |
| 20444 |
if (active) { |
| 20445 |
if (cursor->type == NK_STYLE_ITEM_IMAGE) |
| 20446 |
nk_draw_image(out, *cursors, &cursor->data.image, nk_white); |
| 20447 |
else nk_fill_circle(out, *cursors, cursor->data.color); |
| 20448 |
} |
| 20449 |
|
| 20450 |
text.padding.x = 0; |
| 20451 |
text.padding.y = 0; |
| 20452 |
text.background = style->text_background; |
| 20453 |
nk_widget_text(out, *label, string, len, &text, NK_TEXT_LEFT, font); |
| 20454 |
} |
| 20455 |
NK_LIB int |
| 20456 |
nk_do_toggle(nk_flags *state, |
| 20457 |
struct nk_command_buffer *out, struct nk_rect r, |
| 20458 |
int *active, const char *str, int len, enum nk_toggle_type type, |
| 20459 |
const struct nk_style_toggle *style, const struct nk_input *in, |
| 20460 |
const struct nk_user_font *font) |
| 20461 |
{ |
| 20462 |
int was_active; |
| 20463 |
struct nk_rect bounds; |
| 20464 |
struct nk_rect select; |
| 20465 |
struct nk_rect cursor; |
| 20466 |
struct nk_rect label; |
| 20467 |
|
| 20468 |
NK_ASSERT(style); |
| 20469 |
NK_ASSERT(out); |
| 20470 |
NK_ASSERT(font); |
| 20471 |
if (!out || !style || !font || !active) |
| 20472 |
return 0; |
| 20473 |
|
| 20474 |
r.w = NK_MAX(r.w, font->height + 2 * style->padding.x); |
| 20475 |
r.h = NK_MAX(r.h, font->height + 2 * style->padding.y); |
| 20476 |
|
| 20477 |
|
| 20478 |
bounds.x = r.x - style->touch_padding.x; |
| 20479 |
bounds.y = r.y - style->touch_padding.y; |
| 20480 |
bounds.w = r.w + 2 * style->touch_padding.x; |
| 20481 |
bounds.h = r.h + 2 * style->touch_padding.y; |
| 20482 |
|
| 20483 |
|
| 20484 |
select.w = font->height; |
| 20485 |
select.h = select.w; |
| 20486 |
select.y = r.y + r.h/2.0f - select.h/2.0f; |
| 20487 |
select.x = r.x; |
| 20488 |
|
| 20489 |
|
| 20490 |
cursor.x = select.x + style->padding.x + style->border; |
| 20491 |
cursor.y = select.y + style->padding.y + style->border; |
| 20492 |
cursor.w = select.w - (2 * style->padding.x + 2 * style->border); |
| 20493 |
cursor.h = select.h - (2 * style->padding.y + 2 * style->border); |
| 20494 |
|
| 20495 |
|
| 20496 |
label.x = select.x + select.w + style->spacing; |
| 20497 |
label.y = select.y; |
| 20498 |
label.w = NK_MAX(r.x + r.w, label.x) - label.x; |
| 20499 |
label.h = select.w; |
| 20500 |
|
| 20501 |
|
| 20502 |
was_active = *active; |
| 20503 |
*active = nk_toggle_behavior(in, bounds, state, *active); |
| 20504 |
|
| 20505 |
|
| 20506 |
if (style->draw_begin) |
| 20507 |
style->draw_begin(out, style->userdata); |
| 20508 |
if (type == NK_TOGGLE_CHECK) { |
| 20509 |
nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font); |
| 20510 |
} else { |
| 20511 |
nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font); |
| 20512 |
} |
| 20513 |
if (style->draw_end) |
| 20514 |
style->draw_end(out, style->userdata); |
| 20515 |
return (was_active != *active); |
| 20516 |
} |
| 20517 |
|
| 20518 |
|
| 20519 |
|
| 20520 |
|
| 20521 |
|
| 20522 |
NK_API int |
| 20523 |
nk_check_text(struct nk_context *ctx, const char *text, int len, int active) |
| 20524 |
{ |
| 20525 |
struct nk_window *win; |
| 20526 |
struct nk_panel *layout; |
| 20527 |
const struct nk_input *in; |
| 20528 |
const struct nk_style *style; |
| 20529 |
|
| 20530 |
struct nk_rect bounds; |
| 20531 |
enum nk_widget_layout_states state; |
| 20532 |
|
| 20533 |
NK_ASSERT(ctx); |
| 20534 |
NK_ASSERT(ctx->current); |
| 20535 |
NK_ASSERT(ctx->current->layout); |
| 20536 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 20537 |
return active; |
| 20538 |
|
| 20539 |
win = ctx->current; |
| 20540 |
style = &ctx->style; |
| 20541 |
layout = win->layout; |
| 20542 |
|
| 20543 |
state = nk_widget(&bounds, ctx); |
| 20544 |
if (!state) return active; |
| 20545 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20546 |
nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &active, |
| 20547 |
text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font); |
| 20548 |
return active; |
| 20549 |
} |
| 20550 |
NK_API unsigned int |
| 20551 |
nk_check_flags_text(struct nk_context *ctx, const char *text, int len, |
| 20552 |
unsigned int flags, unsigned int value) |
| 20553 |
{ |
| 20554 |
int old_active; |
| 20555 |
NK_ASSERT(ctx); |
| 20556 |
NK_ASSERT(text); |
| 20557 |
if (!ctx || !text) return flags; |
| 20558 |
old_active = (int)((flags & value) & value); |
| 20559 |
if (nk_check_text(ctx, text, len, old_active)) |
| 20560 |
flags |= value; |
| 20561 |
else flags &= ~value; |
| 20562 |
return flags; |
| 20563 |
} |
| 20564 |
NK_API int |
| 20565 |
nk_checkbox_text(struct nk_context *ctx, const char *text, int len, int *active) |
| 20566 |
{ |
| 20567 |
int old_val; |
| 20568 |
NK_ASSERT(ctx); |
| 20569 |
NK_ASSERT(text); |
| 20570 |
NK_ASSERT(active); |
| 20571 |
if (!ctx || !text || !active) return 0; |
| 20572 |
old_val = *active; |
| 20573 |
*active = nk_check_text(ctx, text, len, *active); |
| 20574 |
return old_val != *active; |
| 20575 |
} |
| 20576 |
NK_API int |
| 20577 |
nk_checkbox_flags_text(struct nk_context *ctx, const char *text, int len, |
| 20578 |
unsigned int *flags, unsigned int value) |
| 20579 |
{ |
| 20580 |
int active; |
| 20581 |
NK_ASSERT(ctx); |
| 20582 |
NK_ASSERT(text); |
| 20583 |
NK_ASSERT(flags); |
| 20584 |
if (!ctx || !text || !flags) return 0; |
| 20585 |
|
| 20586 |
active = (int)((*flags & value) & value); |
| 20587 |
if (nk_checkbox_text(ctx, text, len, &active)) { |
| 20588 |
if (active) *flags |= value; |
| 20589 |
else *flags &= ~value; |
| 20590 |
return 1; |
| 20591 |
} |
| 20592 |
return 0; |
| 20593 |
} |
| 20594 |
NK_API int nk_check_label(struct nk_context *ctx, const char *label, int active) |
| 20595 |
{ |
| 20596 |
return nk_check_text(ctx, label, nk_strlen(label), active); |
| 20597 |
} |
| 20598 |
NK_API unsigned int nk_check_flags_label(struct nk_context *ctx, const char *label, |
| 20599 |
unsigned int flags, unsigned int value) |
| 20600 |
{ |
| 20601 |
return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value); |
| 20602 |
} |
| 20603 |
NK_API int nk_checkbox_label(struct nk_context *ctx, const char *label, int *active) |
| 20604 |
{ |
| 20605 |
return nk_checkbox_text(ctx, label, nk_strlen(label), active); |
| 20606 |
} |
| 20607 |
NK_API int nk_checkbox_flags_label(struct nk_context *ctx, const char *label, |
| 20608 |
unsigned int *flags, unsigned int value) |
| 20609 |
{ |
| 20610 |
return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value); |
| 20611 |
} |
| 20612 |
|
| 20613 |
|
| 20614 |
|
| 20615 |
|
| 20616 |
|
| 20617 |
NK_API int |
| 20618 |
nk_option_text(struct nk_context *ctx, const char *text, int len, int is_active) |
| 20619 |
{ |
| 20620 |
struct nk_window *win; |
| 20621 |
struct nk_panel *layout; |
| 20622 |
const struct nk_input *in; |
| 20623 |
const struct nk_style *style; |
| 20624 |
|
| 20625 |
struct nk_rect bounds; |
| 20626 |
enum nk_widget_layout_states state; |
| 20627 |
|
| 20628 |
NK_ASSERT(ctx); |
| 20629 |
NK_ASSERT(ctx->current); |
| 20630 |
NK_ASSERT(ctx->current->layout); |
| 20631 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 20632 |
return is_active; |
| 20633 |
|
| 20634 |
win = ctx->current; |
| 20635 |
style = &ctx->style; |
| 20636 |
layout = win->layout; |
| 20637 |
|
| 20638 |
state = nk_widget(&bounds, ctx); |
| 20639 |
if (!state) return (int)state; |
| 20640 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20641 |
nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &is_active, |
| 20642 |
text, len, NK_TOGGLE_OPTION, &style->option, in, style->font); |
| 20643 |
return is_active; |
| 20644 |
} |
| 20645 |
NK_API int |
| 20646 |
nk_radio_text(struct nk_context *ctx, const char *text, int len, int *active) |
| 20647 |
{ |
| 20648 |
int old_value; |
| 20649 |
NK_ASSERT(ctx); |
| 20650 |
NK_ASSERT(text); |
| 20651 |
NK_ASSERT(active); |
| 20652 |
if (!ctx || !text || !active) return 0; |
| 20653 |
old_value = *active; |
| 20654 |
*active = nk_option_text(ctx, text, len, old_value); |
| 20655 |
return old_value != *active; |
| 20656 |
} |
| 20657 |
NK_API int |
| 20658 |
nk_option_label(struct nk_context *ctx, const char *label, int active) |
| 20659 |
{ |
| 20660 |
return nk_option_text(ctx, label, nk_strlen(label), active); |
| 20661 |
} |
| 20662 |
NK_API int |
| 20663 |
nk_radio_label(struct nk_context *ctx, const char *label, int *active) |
| 20664 |
{ |
| 20665 |
return nk_radio_text(ctx, label, nk_strlen(label), active); |
| 20666 |
} |
| 20667 |
|
| 20668 |
|
| 20669 |
|
| 20670 |
|
| 20671 |
|
| 20672 |
|
| 20673 |
|
| 20674 |
|
| 20675 |
|
| 20676 |
|
| 20677 |
NK_LIB void |
| 20678 |
nk_draw_selectable(struct nk_command_buffer *out, |
| 20679 |
nk_flags state, const struct nk_style_selectable *style, int active, |
| 20680 |
const struct nk_rect *bounds, |
| 20681 |
const struct nk_rect *icon, const struct nk_image *img, enum nk_symbol_type sym, |
| 20682 |
const char *string, int len, nk_flags align, const struct nk_user_font *font) |
| 20683 |
{ |
| 20684 |
const struct nk_style_item *background; |
| 20685 |
struct nk_text text; |
| 20686 |
text.padding = style->padding; |
| 20687 |
|
| 20688 |
|
| 20689 |
if (!active) { |
| 20690 |
if (state & NK_WIDGET_STATE_ACTIVED) { |
| 20691 |
background = &style->pressed; |
| 20692 |
text.text = style->text_pressed; |
| 20693 |
} else if (state & NK_WIDGET_STATE_HOVER) { |
| 20694 |
background = &style->hover; |
| 20695 |
text.text = style->text_hover; |
| 20696 |
} else { |
| 20697 |
background = &style->normal; |
| 20698 |
text.text = style->text_normal; |
| 20699 |
} |
| 20700 |
} else { |
| 20701 |
if (state & NK_WIDGET_STATE_ACTIVED) { |
| 20702 |
background = &style->pressed_active; |
| 20703 |
text.text = style->text_pressed_active; |
| 20704 |
} else if (state & NK_WIDGET_STATE_HOVER) { |
| 20705 |
background = &style->hover_active; |
| 20706 |
text.text = style->text_hover_active; |
| 20707 |
} else { |
| 20708 |
background = &style->normal_active; |
| 20709 |
text.text = style->text_normal_active; |
| 20710 |
} |
| 20711 |
} |
| 20712 |
|
| 20713 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 20714 |
nk_draw_image(out, *bounds, &background->data.image, nk_white); |
| 20715 |
text.background = nk_rgba(0,0,0,0); |
| 20716 |
} else { |
| 20717 |
nk_fill_rect(out, *bounds, style->rounding, background->data.color); |
| 20718 |
text.background = background->data.color; |
| 20719 |
} |
| 20720 |
if (icon) { |
| 20721 |
if (img) nk_draw_image(out, *icon, img, nk_white); |
| 20722 |
else nk_draw_symbol(out, sym, *icon, text.background, text.text, 1, font); |
| 20723 |
} |
| 20724 |
nk_widget_text(out, *bounds, string, len, &text, align, font); |
| 20725 |
} |
| 20726 |
NK_LIB int |
| 20727 |
nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, |
| 20728 |
struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, |
| 20729 |
const struct nk_style_selectable *style, const struct nk_input *in, |
| 20730 |
const struct nk_user_font *font) |
| 20731 |
{ |
| 20732 |
int old_value; |
| 20733 |
struct nk_rect touch; |
| 20734 |
|
| 20735 |
NK_ASSERT(state); |
| 20736 |
NK_ASSERT(out); |
| 20737 |
NK_ASSERT(str); |
| 20738 |
NK_ASSERT(len); |
| 20739 |
NK_ASSERT(value); |
| 20740 |
NK_ASSERT(style); |
| 20741 |
NK_ASSERT(font); |
| 20742 |
|
| 20743 |
if (!state || !out || !str || !len || !value || !style || !font) return 0; |
| 20744 |
old_value = *value; |
| 20745 |
|
| 20746 |
|
| 20747 |
touch.x = bounds.x - style->touch_padding.x; |
| 20748 |
touch.y = bounds.y - style->touch_padding.y; |
| 20749 |
touch.w = bounds.w + style->touch_padding.x * 2; |
| 20750 |
touch.h = bounds.h + style->touch_padding.y * 2; |
| 20751 |
|
| 20752 |
|
| 20753 |
if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT)) |
| 20754 |
*value = !(*value); |
| 20755 |
|
| 20756 |
|
| 20757 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 20758 |
nk_draw_selectable(out, *state, style, *value, &bounds, 0,0,NK_SYMBOL_NONE, str, len, align, font); |
| 20759 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 20760 |
return old_value != *value; |
| 20761 |
} |
| 20762 |
NK_LIB int |
| 20763 |
nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, |
| 20764 |
struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, |
| 20765 |
const struct nk_image *img, const struct nk_style_selectable *style, |
| 20766 |
const struct nk_input *in, const struct nk_user_font *font) |
| 20767 |
{ |
| 20768 |
int old_value; |
| 20769 |
struct nk_rect touch; |
| 20770 |
struct nk_rect icon; |
| 20771 |
|
| 20772 |
NK_ASSERT(state); |
| 20773 |
NK_ASSERT(out); |
| 20774 |
NK_ASSERT(str); |
| 20775 |
NK_ASSERT(len); |
| 20776 |
NK_ASSERT(value); |
| 20777 |
NK_ASSERT(style); |
| 20778 |
NK_ASSERT(font); |
| 20779 |
|
| 20780 |
if (!state || !out || !str || !len || !value || !style || !font) return 0; |
| 20781 |
old_value = *value; |
| 20782 |
|
| 20783 |
|
| 20784 |
touch.x = bounds.x - style->touch_padding.x; |
| 20785 |
touch.y = bounds.y - style->touch_padding.y; |
| 20786 |
touch.w = bounds.w + style->touch_padding.x * 2; |
| 20787 |
touch.h = bounds.h + style->touch_padding.y * 2; |
| 20788 |
if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT)) |
| 20789 |
*value = !(*value); |
| 20790 |
|
| 20791 |
icon.y = bounds.y + style->padding.y; |
| 20792 |
icon.w = icon.h = bounds.h - 2 * style->padding.y; |
| 20793 |
if (align & NK_TEXT_ALIGN_LEFT) { |
| 20794 |
icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w); |
| 20795 |
icon.x = NK_MAX(icon.x, 0); |
| 20796 |
} else icon.x = bounds.x + 2 * style->padding.x; |
| 20797 |
|
| 20798 |
icon.x += style->image_padding.x; |
| 20799 |
icon.y += style->image_padding.y; |
| 20800 |
icon.w -= 2 * style->image_padding.x; |
| 20801 |
icon.h -= 2 * style->image_padding.y; |
| 20802 |
|
| 20803 |
|
| 20804 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 20805 |
nk_draw_selectable(out, *state, style, *value, &bounds, &icon, img, NK_SYMBOL_NONE, str, len, align, font); |
| 20806 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 20807 |
return old_value != *value; |
| 20808 |
} |
| 20809 |
NK_LIB int |
| 20810 |
nk_do_selectable_symbol(nk_flags *state, struct nk_command_buffer *out, |
| 20811 |
struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, |
| 20812 |
enum nk_symbol_type sym, const struct nk_style_selectable *style, |
| 20813 |
const struct nk_input *in, const struct nk_user_font *font) |
| 20814 |
{ |
| 20815 |
int old_value; |
| 20816 |
struct nk_rect touch; |
| 20817 |
struct nk_rect icon; |
| 20818 |
|
| 20819 |
NK_ASSERT(state); |
| 20820 |
NK_ASSERT(out); |
| 20821 |
NK_ASSERT(str); |
| 20822 |
NK_ASSERT(len); |
| 20823 |
NK_ASSERT(value); |
| 20824 |
NK_ASSERT(style); |
| 20825 |
NK_ASSERT(font); |
| 20826 |
|
| 20827 |
if (!state || !out || !str || !len || !value || !style || !font) return 0; |
| 20828 |
old_value = *value; |
| 20829 |
|
| 20830 |
|
| 20831 |
touch.x = bounds.x - style->touch_padding.x; |
| 20832 |
touch.y = bounds.y - style->touch_padding.y; |
| 20833 |
touch.w = bounds.w + style->touch_padding.x * 2; |
| 20834 |
touch.h = bounds.h + style->touch_padding.y * 2; |
| 20835 |
if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT)) |
| 20836 |
*value = !(*value); |
| 20837 |
|
| 20838 |
icon.y = bounds.y + style->padding.y; |
| 20839 |
icon.w = icon.h = bounds.h - 2 * style->padding.y; |
| 20840 |
if (align & NK_TEXT_ALIGN_LEFT) { |
| 20841 |
icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w); |
| 20842 |
icon.x = NK_MAX(icon.x, 0); |
| 20843 |
} else icon.x = bounds.x + 2 * style->padding.x; |
| 20844 |
|
| 20845 |
icon.x += style->image_padding.x; |
| 20846 |
icon.y += style->image_padding.y; |
| 20847 |
icon.w -= 2 * style->image_padding.x; |
| 20848 |
icon.h -= 2 * style->image_padding.y; |
| 20849 |
|
| 20850 |
|
| 20851 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 20852 |
nk_draw_selectable(out, *state, style, *value, &bounds, &icon, 0, sym, str, len, align, font); |
| 20853 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 20854 |
return old_value != *value; |
| 20855 |
} |
| 20856 |
|
| 20857 |
NK_API int |
| 20858 |
nk_selectable_text(struct nk_context *ctx, const char *str, int len, |
| 20859 |
nk_flags align, int *value) |
| 20860 |
{ |
| 20861 |
struct nk_window *win; |
| 20862 |
struct nk_panel *layout; |
| 20863 |
const struct nk_input *in; |
| 20864 |
const struct nk_style *style; |
| 20865 |
|
| 20866 |
enum nk_widget_layout_states state; |
| 20867 |
struct nk_rect bounds; |
| 20868 |
|
| 20869 |
NK_ASSERT(ctx); |
| 20870 |
NK_ASSERT(value); |
| 20871 |
NK_ASSERT(ctx->current); |
| 20872 |
NK_ASSERT(ctx->current->layout); |
| 20873 |
if (!ctx || !ctx->current || !ctx->current->layout || !value) |
| 20874 |
return 0; |
| 20875 |
|
| 20876 |
win = ctx->current; |
| 20877 |
layout = win->layout; |
| 20878 |
style = &ctx->style; |
| 20879 |
|
| 20880 |
state = nk_widget(&bounds, ctx); |
| 20881 |
if (!state) return 0; |
| 20882 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20883 |
return nk_do_selectable(&ctx->last_widget_state, &win->buffer, bounds, |
| 20884 |
str, len, align, value, &style->selectable, in, style->font); |
| 20885 |
} |
| 20886 |
NK_API int |
| 20887 |
nk_selectable_image_text(struct nk_context *ctx, struct nk_image img, |
| 20888 |
const char *str, int len, nk_flags align, int *value) |
| 20889 |
{ |
| 20890 |
struct nk_window *win; |
| 20891 |
struct nk_panel *layout; |
| 20892 |
const struct nk_input *in; |
| 20893 |
const struct nk_style *style; |
| 20894 |
|
| 20895 |
enum nk_widget_layout_states state; |
| 20896 |
struct nk_rect bounds; |
| 20897 |
|
| 20898 |
NK_ASSERT(ctx); |
| 20899 |
NK_ASSERT(value); |
| 20900 |
NK_ASSERT(ctx->current); |
| 20901 |
NK_ASSERT(ctx->current->layout); |
| 20902 |
if (!ctx || !ctx->current || !ctx->current->layout || !value) |
| 20903 |
return 0; |
| 20904 |
|
| 20905 |
win = ctx->current; |
| 20906 |
layout = win->layout; |
| 20907 |
style = &ctx->style; |
| 20908 |
|
| 20909 |
state = nk_widget(&bounds, ctx); |
| 20910 |
if (!state) return 0; |
| 20911 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20912 |
return nk_do_selectable_image(&ctx->last_widget_state, &win->buffer, bounds, |
| 20913 |
str, len, align, value, &img, &style->selectable, in, style->font); |
| 20914 |
} |
| 20915 |
NK_API int |
| 20916 |
nk_selectable_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, |
| 20917 |
const char *str, int len, nk_flags align, int *value) |
| 20918 |
{ |
| 20919 |
struct nk_window *win; |
| 20920 |
struct nk_panel *layout; |
| 20921 |
const struct nk_input *in; |
| 20922 |
const struct nk_style *style; |
| 20923 |
|
| 20924 |
enum nk_widget_layout_states state; |
| 20925 |
struct nk_rect bounds; |
| 20926 |
|
| 20927 |
NK_ASSERT(ctx); |
| 20928 |
NK_ASSERT(value); |
| 20929 |
NK_ASSERT(ctx->current); |
| 20930 |
NK_ASSERT(ctx->current->layout); |
| 20931 |
if (!ctx || !ctx->current || !ctx->current->layout || !value) |
| 20932 |
return 0; |
| 20933 |
|
| 20934 |
win = ctx->current; |
| 20935 |
layout = win->layout; |
| 20936 |
style = &ctx->style; |
| 20937 |
|
| 20938 |
state = nk_widget(&bounds, ctx); |
| 20939 |
if (!state) return 0; |
| 20940 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 20941 |
return nk_do_selectable_symbol(&ctx->last_widget_state, &win->buffer, bounds, |
| 20942 |
str, len, align, value, sym, &style->selectable, in, style->font); |
| 20943 |
} |
| 20944 |
NK_API int |
| 20945 |
nk_selectable_symbol_label(struct nk_context *ctx, enum nk_symbol_type sym, |
| 20946 |
const char *title, nk_flags align, int *value) |
| 20947 |
{ |
| 20948 |
return nk_selectable_symbol_text(ctx, sym, title, nk_strlen(title), align, value); |
| 20949 |
} |
| 20950 |
NK_API int nk_select_text(struct nk_context *ctx, const char *str, int len, |
| 20951 |
nk_flags align, int value) |
| 20952 |
{ |
| 20953 |
nk_selectable_text(ctx, str, len, align, &value);return value; |
| 20954 |
} |
| 20955 |
NK_API int nk_selectable_label(struct nk_context *ctx, const char *str, nk_flags align, int *value) |
| 20956 |
{ |
| 20957 |
return nk_selectable_text(ctx, str, nk_strlen(str), align, value); |
| 20958 |
} |
| 20959 |
NK_API int nk_selectable_image_label(struct nk_context *ctx,struct nk_image img, |
| 20960 |
const char *str, nk_flags align, int *value) |
| 20961 |
{ |
| 20962 |
return nk_selectable_image_text(ctx, img, str, nk_strlen(str), align, value); |
| 20963 |
} |
| 20964 |
NK_API int nk_select_label(struct nk_context *ctx, const char *str, nk_flags align, int value) |
| 20965 |
{ |
| 20966 |
nk_selectable_text(ctx, str, nk_strlen(str), align, &value);return value; |
| 20967 |
} |
| 20968 |
NK_API int nk_select_image_label(struct nk_context *ctx, struct nk_image img, |
| 20969 |
const char *str, nk_flags align, int value) |
| 20970 |
{ |
| 20971 |
nk_selectable_image_text(ctx, img, str, nk_strlen(str), align, &value);return value; |
| 20972 |
} |
| 20973 |
NK_API int nk_select_image_text(struct nk_context *ctx, struct nk_image img, |
| 20974 |
const char *str, int len, nk_flags align, int value) |
| 20975 |
{ |
| 20976 |
nk_selectable_image_text(ctx, img, str, len, align, &value);return value; |
| 20977 |
} |
| 20978 |
NK_API int |
| 20979 |
nk_select_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, |
| 20980 |
const char *title, int title_len, nk_flags align, int value) |
| 20981 |
{ |
| 20982 |
nk_selectable_symbol_text(ctx, sym, title, title_len, align, &value);return value; |
| 20983 |
} |
| 20984 |
NK_API int |
| 20985 |
nk_select_symbol_label(struct nk_context *ctx, enum nk_symbol_type sym, |
| 20986 |
const char *title, nk_flags align, int value) |
| 20987 |
{ |
| 20988 |
return nk_select_symbol_text(ctx, sym, title, nk_strlen(title), align, value); |
| 20989 |
} |
| 20990 |
|
| 20991 |
|
| 20992 |
|
| 20993 |
|
| 20994 |
|
| 20995 |
|
| 20996 |
|
| 20997 |
|
| 20998 |
|
| 20999 |
|
| 21000 |
NK_LIB float |
| 21001 |
nk_slider_behavior(nk_flags *state, struct nk_rect *logical_cursor, |
| 21002 |
struct nk_rect *visual_cursor, struct nk_input *in, |
| 21003 |
struct nk_rect bounds, float slider_min, float slider_max, float slider_value, |
| 21004 |
float slider_step, float slider_steps) |
| 21005 |
{ |
| 21006 |
int left_mouse_down; |
| 21007 |
int left_mouse_click_in_cursor; |
| 21008 |
|
| 21009 |
|
| 21010 |
nk_widget_state_reset(state); |
| 21011 |
left_mouse_down = in && in->mouse.buttons[NK_BUTTON_LEFT].down; |
| 21012 |
left_mouse_click_in_cursor = in && nk_input_has_mouse_click_down_in_rect(in, |
| 21013 |
NK_BUTTON_LEFT, *visual_cursor, nk_true); |
| 21014 |
|
| 21015 |
if (left_mouse_down && left_mouse_click_in_cursor) { |
| 21016 |
float ratio = 0; |
| 21017 |
const float d = in->mouse.pos.x - (visual_cursor->x+visual_cursor->w*0.5f); |
| 21018 |
const float pxstep = bounds.w / slider_steps; |
| 21019 |
|
| 21020 |
|
| 21021 |
*state = NK_WIDGET_STATE_ACTIVE; |
| 21022 |
if (NK_ABS(d) >= pxstep) { |
| 21023 |
const float steps = (float)((int)(NK_ABS(d) / pxstep)); |
| 21024 |
slider_value += (d > 0) ? (slider_step*steps) : -(slider_step*steps); |
| 21025 |
slider_value = NK_CLAMP(slider_min, slider_value, slider_max); |
| 21026 |
ratio = (slider_value - slider_min)/slider_step; |
| 21027 |
logical_cursor->x = bounds.x + (logical_cursor->w * ratio); |
| 21028 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = logical_cursor->x; |
| 21029 |
} |
| 21030 |
} |
| 21031 |
|
| 21032 |
|
| 21033 |
if (nk_input_is_mouse_hovering_rect(in, bounds)) |
| 21034 |
*state = NK_WIDGET_STATE_HOVERED; |
| 21035 |
if (*state & NK_WIDGET_STATE_HOVER && |
| 21036 |
!nk_input_is_mouse_prev_hovering_rect(in, bounds)) |
| 21037 |
*state |= NK_WIDGET_STATE_ENTERED; |
| 21038 |
else if (nk_input_is_mouse_prev_hovering_rect(in, bounds)) |
| 21039 |
*state |= NK_WIDGET_STATE_LEFT; |
| 21040 |
return slider_value; |
| 21041 |
} |
| 21042 |
NK_LIB void |
| 21043 |
nk_draw_slider(struct nk_command_buffer *out, nk_flags state, |
| 21044 |
const struct nk_style_slider *style, const struct nk_rect *bounds, |
| 21045 |
const struct nk_rect *visual_cursor, float min, float value, float max) |
| 21046 |
{ |
| 21047 |
struct nk_rect fill; |
| 21048 |
struct nk_rect bar; |
| 21049 |
const struct nk_style_item *background; |
| 21050 |
|
| 21051 |
|
| 21052 |
struct nk_color bar_color; |
| 21053 |
const struct nk_style_item *cursor; |
| 21054 |
|
| 21055 |
NK_UNUSED(min); |
| 21056 |
NK_UNUSED(max); |
| 21057 |
NK_UNUSED(value); |
| 21058 |
|
| 21059 |
if (state & NK_WIDGET_STATE_ACTIVED) { |
| 21060 |
background = &style->active; |
| 21061 |
bar_color = style->bar_active; |
| 21062 |
cursor = &style->cursor_active; |
| 21063 |
} else if (state & NK_WIDGET_STATE_HOVER) { |
| 21064 |
background = &style->hover; |
| 21065 |
bar_color = style->bar_hover; |
| 21066 |
cursor = &style->cursor_hover; |
| 21067 |
} else { |
| 21068 |
background = &style->normal; |
| 21069 |
bar_color = style->bar_normal; |
| 21070 |
cursor = &style->cursor_normal; |
| 21071 |
} |
| 21072 |
|
| 21073 |
bar.x = bounds->x; |
| 21074 |
bar.y = (visual_cursor->y + visual_cursor->h/2) - bounds->h/12; |
| 21075 |
bar.w = bounds->w; |
| 21076 |
bar.h = bounds->h/6; |
| 21077 |
|
| 21078 |
|
| 21079 |
fill.w = (visual_cursor->x + (visual_cursor->w/2.0f)) - bar.x; |
| 21080 |
fill.x = bar.x; |
| 21081 |
fill.y = bar.y; |
| 21082 |
fill.h = bar.h; |
| 21083 |
|
| 21084 |
|
| 21085 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 21086 |
nk_draw_image(out, *bounds, &background->data.image, nk_white); |
| 21087 |
} else { |
| 21088 |
nk_fill_rect(out, *bounds, style->rounding, background->data.color); |
| 21089 |
nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); |
| 21090 |
} |
| 21091 |
|
| 21092 |
|
| 21093 |
nk_fill_rect(out, bar, style->rounding, bar_color); |
| 21094 |
nk_fill_rect(out, fill, style->rounding, style->bar_filled); |
| 21095 |
|
| 21096 |
|
| 21097 |
if (cursor->type == NK_STYLE_ITEM_IMAGE) |
| 21098 |
nk_draw_image(out, *visual_cursor, &cursor->data.image, nk_white); |
| 21099 |
else nk_fill_circle(out, *visual_cursor, cursor->data.color); |
| 21100 |
} |
| 21101 |
NK_LIB float |
| 21102 |
nk_do_slider(nk_flags *state, |
| 21103 |
struct nk_command_buffer *out, struct nk_rect bounds, |
| 21104 |
float min, float val, float max, float step, |
| 21105 |
const struct nk_style_slider *style, struct nk_input *in, |
| 21106 |
const struct nk_user_font *font) |
| 21107 |
{ |
| 21108 |
float slider_range; |
| 21109 |
float slider_min; |
| 21110 |
float slider_max; |
| 21111 |
float slider_value; |
| 21112 |
float slider_steps; |
| 21113 |
float cursor_offset; |
| 21114 |
|
| 21115 |
struct nk_rect visual_cursor; |
| 21116 |
struct nk_rect logical_cursor; |
| 21117 |
|
| 21118 |
NK_ASSERT(style); |
| 21119 |
NK_ASSERT(out); |
| 21120 |
if (!out || !style) |
| 21121 |
return 0; |
| 21122 |
|
| 21123 |
|
| 21124 |
bounds.x = bounds.x + style->padding.x; |
| 21125 |
bounds.y = bounds.y + style->padding.y; |
| 21126 |
bounds.h = NK_MAX(bounds.h, 2*style->padding.y); |
| 21127 |
bounds.w = NK_MAX(bounds.w, 2*style->padding.x + style->cursor_size.x); |
| 21128 |
bounds.w -= 2 * style->padding.x; |
| 21129 |
bounds.h -= 2 * style->padding.y; |
| 21130 |
|
| 21131 |
|
| 21132 |
if (style->show_buttons) { |
| 21133 |
nk_flags ws; |
| 21134 |
struct nk_rect button; |
| 21135 |
button.y = bounds.y; |
| 21136 |
button.w = bounds.h; |
| 21137 |
button.h = bounds.h; |
| 21138 |
|
| 21139 |
|
| 21140 |
button.x = bounds.x; |
| 21141 |
if (nk_do_button_symbol(&ws, out, button, style->dec_symbol, NK_BUTTON_DEFAULT, |
| 21142 |
&style->dec_button, in, font)) |
| 21143 |
val -= step; |
| 21144 |
|
| 21145 |
|
| 21146 |
button.x = (bounds.x + bounds.w) - button.w; |
| 21147 |
if (nk_do_button_symbol(&ws, out, button, style->inc_symbol, NK_BUTTON_DEFAULT, |
| 21148 |
&style->inc_button, in, font)) |
| 21149 |
val += step; |
| 21150 |
|
| 21151 |
bounds.x = bounds.x + button.w + style->spacing.x; |
| 21152 |
bounds.w = bounds.w - (2*button.w + 2*style->spacing.x); |
| 21153 |
} |
| 21154 |
|
| 21155 |
|
| 21156 |
bounds.x += style->cursor_size.x*0.5f; |
| 21157 |
bounds.w -= style->cursor_size.x; |
| 21158 |
|
| 21159 |
|
| 21160 |
slider_max = NK_MAX(min, max); |
| 21161 |
slider_min = NK_MIN(min, max); |
| 21162 |
slider_value = NK_CLAMP(slider_min, val, slider_max); |
| 21163 |
slider_range = slider_max - slider_min; |
| 21164 |
slider_steps = slider_range / step; |
| 21165 |
cursor_offset = (slider_value - slider_min) / step; |
| 21166 |
|
| 21167 |
|
| 21168 |
|
| 21169 |
|
| 21170 |
logical_cursor.h = bounds.h; |
| 21171 |
logical_cursor.w = bounds.w / slider_steps; |
| 21172 |
logical_cursor.x = bounds.x + (logical_cursor.w * cursor_offset); |
| 21173 |
logical_cursor.y = bounds.y; |
| 21174 |
|
| 21175 |
visual_cursor.h = style->cursor_size.y; |
| 21176 |
visual_cursor.w = style->cursor_size.x; |
| 21177 |
visual_cursor.y = (bounds.y + bounds.h*0.5f) - visual_cursor.h*0.5f; |
| 21178 |
visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f; |
| 21179 |
|
| 21180 |
slider_value = nk_slider_behavior(state, &logical_cursor, &visual_cursor, |
| 21181 |
in, bounds, slider_min, slider_max, slider_value, step, slider_steps); |
| 21182 |
visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f; |
| 21183 |
|
| 21184 |
|
| 21185 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 21186 |
nk_draw_slider(out, *state, style, &bounds, &visual_cursor, slider_min, slider_value, slider_max); |
| 21187 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 21188 |
return slider_value; |
| 21189 |
} |
| 21190 |
NK_API int |
| 21191 |
nk_slider_float(struct nk_context *ctx, float min_value, float *value, float max_value, |
| 21192 |
float value_step) |
| 21193 |
{ |
| 21194 |
struct nk_window *win; |
| 21195 |
struct nk_panel *layout; |
| 21196 |
struct nk_input *in; |
| 21197 |
const struct nk_style *style; |
| 21198 |
|
| 21199 |
int ret = 0; |
| 21200 |
float old_value; |
| 21201 |
struct nk_rect bounds; |
| 21202 |
enum nk_widget_layout_states state; |
| 21203 |
|
| 21204 |
NK_ASSERT(ctx); |
| 21205 |
NK_ASSERT(ctx->current); |
| 21206 |
NK_ASSERT(ctx->current->layout); |
| 21207 |
NK_ASSERT(value); |
| 21208 |
if (!ctx || !ctx->current || !ctx->current->layout || !value) |
| 21209 |
return ret; |
| 21210 |
|
| 21211 |
win = ctx->current; |
| 21212 |
style = &ctx->style; |
| 21213 |
layout = win->layout; |
| 21214 |
|
| 21215 |
state = nk_widget(&bounds, ctx); |
| 21216 |
if (!state) return ret; |
| 21217 |
in = ( layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 21218 |
|
| 21219 |
old_value = *value; |
| 21220 |
*value = nk_do_slider(&ctx->last_widget_state, &win->buffer, bounds, min_value, |
| 21221 |
old_value, max_value, value_step, &style->slider, in, style->font); |
| 21222 |
return (old_value > *value || old_value < *value); |
| 21223 |
} |
| 21224 |
NK_API float |
| 21225 |
nk_slide_float(struct nk_context *ctx, float min, float val, float max, float step) |
| 21226 |
{ |
| 21227 |
nk_slider_float(ctx, min, &val, max, step); return val; |
| 21228 |
} |
| 21229 |
NK_API int |
| 21230 |
nk_slide_int(struct nk_context *ctx, int min, int val, int max, int step) |
| 21231 |
{ |
| 21232 |
float value = (float)val; |
| 21233 |
nk_slider_float(ctx, (float)min, &value, (float)max, (float)step); |
| 21234 |
return (int)value; |
| 21235 |
} |
| 21236 |
NK_API int |
| 21237 |
nk_slider_int(struct nk_context *ctx, int min, int *val, int max, int step) |
| 21238 |
{ |
| 21239 |
int ret; |
| 21240 |
float value = (float)*val; |
| 21241 |
ret = nk_slider_float(ctx, (float)min, &value, (float)max, (float)step); |
| 21242 |
*val = (int)value; |
| 21243 |
return ret; |
| 21244 |
} |
| 21245 |
|
| 21246 |
|
| 21247 |
|
| 21248 |
|
| 21249 |
|
| 21250 |
|
| 21251 |
|
| 21252 |
|
| 21253 |
|
| 21254 |
|
| 21255 |
NK_LIB nk_size |
| 21256 |
nk_progress_behavior(nk_flags *state, struct nk_input *in, |
| 21257 |
struct nk_rect r, struct nk_rect cursor, nk_size max, nk_size value, int modifiable) |
| 21258 |
{ |
| 21259 |
int left_mouse_down = 0; |
| 21260 |
int left_mouse_click_in_cursor = 0; |
| 21261 |
|
| 21262 |
nk_widget_state_reset(state); |
| 21263 |
if (!in || !modifiable) return value; |
| 21264 |
left_mouse_down = in && in->mouse.buttons[NK_BUTTON_LEFT].down; |
| 21265 |
left_mouse_click_in_cursor = in && nk_input_has_mouse_click_down_in_rect(in, |
| 21266 |
NK_BUTTON_LEFT, cursor, nk_true); |
| 21267 |
if (nk_input_is_mouse_hovering_rect(in, r)) |
| 21268 |
*state = NK_WIDGET_STATE_HOVERED; |
| 21269 |
|
| 21270 |
if (in && left_mouse_down && left_mouse_click_in_cursor) { |
| 21271 |
if (left_mouse_down && left_mouse_click_in_cursor) { |
| 21272 |
float ratio = NK_MAX(0, (float)(in->mouse.pos.x - cursor.x)) / (float)cursor.w; |
| 21273 |
value = (nk_size)NK_CLAMP(0, (float)max * ratio, (float)max); |
| 21274 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = cursor.x + cursor.w/2.0f; |
| 21275 |
*state |= NK_WIDGET_STATE_ACTIVE; |
| 21276 |
} |
| 21277 |
} |
| 21278 |
|
| 21279 |
if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, r)) |
| 21280 |
*state |= NK_WIDGET_STATE_ENTERED; |
| 21281 |
else if (nk_input_is_mouse_prev_hovering_rect(in, r)) |
| 21282 |
*state |= NK_WIDGET_STATE_LEFT; |
| 21283 |
return value; |
| 21284 |
} |
| 21285 |
NK_LIB void |
| 21286 |
nk_draw_progress(struct nk_command_buffer *out, nk_flags state, |
| 21287 |
const struct nk_style_progress *style, const struct nk_rect *bounds, |
| 21288 |
const struct nk_rect *scursor, nk_size value, nk_size max) |
| 21289 |
{ |
| 21290 |
const struct nk_style_item *background; |
| 21291 |
const struct nk_style_item *cursor; |
| 21292 |
|
| 21293 |
NK_UNUSED(max); |
| 21294 |
NK_UNUSED(value); |
| 21295 |
|
| 21296 |
|
| 21297 |
if (state & NK_WIDGET_STATE_ACTIVED) { |
| 21298 |
background = &style->active; |
| 21299 |
cursor = &style->cursor_active; |
| 21300 |
} else if (state & NK_WIDGET_STATE_HOVER){ |
| 21301 |
background = &style->hover; |
| 21302 |
cursor = &style->cursor_hover; |
| 21303 |
} else { |
| 21304 |
background = &style->normal; |
| 21305 |
cursor = &style->cursor_normal; |
| 21306 |
} |
| 21307 |
|
| 21308 |
|
| 21309 |
if (background->type == NK_STYLE_ITEM_COLOR) { |
| 21310 |
nk_fill_rect(out, *bounds, style->rounding, background->data.color); |
| 21311 |
nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); |
| 21312 |
} else nk_draw_image(out, *bounds, &background->data.image, nk_white); |
| 21313 |
|
| 21314 |
|
| 21315 |
if (cursor->type == NK_STYLE_ITEM_COLOR) { |
| 21316 |
nk_fill_rect(out, *scursor, style->rounding, cursor->data.color); |
| 21317 |
nk_stroke_rect(out, *scursor, style->rounding, style->border, style->border_color); |
| 21318 |
} else nk_draw_image(out, *scursor, &cursor->data.image, nk_white); |
| 21319 |
} |
| 21320 |
NK_LIB nk_size |
| 21321 |
nk_do_progress(nk_flags *state, |
| 21322 |
struct nk_command_buffer *out, struct nk_rect bounds, |
| 21323 |
nk_size value, nk_size max, int modifiable, |
| 21324 |
const struct nk_style_progress *style, struct nk_input *in) |
| 21325 |
{ |
| 21326 |
float prog_scale; |
| 21327 |
nk_size prog_value; |
| 21328 |
struct nk_rect cursor; |
| 21329 |
|
| 21330 |
NK_ASSERT(style); |
| 21331 |
NK_ASSERT(out); |
| 21332 |
if (!out || !style) return 0; |
| 21333 |
|
| 21334 |
|
| 21335 |
cursor.w = NK_MAX(bounds.w, 2 * style->padding.x + 2 * style->border); |
| 21336 |
cursor.h = NK_MAX(bounds.h, 2 * style->padding.y + 2 * style->border); |
| 21337 |
cursor = nk_pad_rect(bounds, nk_vec2(style->padding.x + style->border, style->padding.y + style->border)); |
| 21338 |
prog_scale = (float)value / (float)max; |
| 21339 |
|
| 21340 |
|
| 21341 |
prog_value = NK_MIN(value, max); |
| 21342 |
prog_value = nk_progress_behavior(state, in, bounds, cursor,max, prog_value, modifiable); |
| 21343 |
cursor.w = cursor.w * prog_scale; |
| 21344 |
|
| 21345 |
|
| 21346 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 21347 |
nk_draw_progress(out, *state, style, &bounds, &cursor, value, max); |
| 21348 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 21349 |
return prog_value; |
| 21350 |
} |
| 21351 |
NK_API int |
| 21352 |
nk_progress(struct nk_context *ctx, nk_size *cur, nk_size max, int is_modifyable) |
| 21353 |
{ |
| 21354 |
struct nk_window *win; |
| 21355 |
struct nk_panel *layout; |
| 21356 |
const struct nk_style *style; |
| 21357 |
struct nk_input *in; |
| 21358 |
|
| 21359 |
struct nk_rect bounds; |
| 21360 |
enum nk_widget_layout_states state; |
| 21361 |
nk_size old_value; |
| 21362 |
|
| 21363 |
NK_ASSERT(ctx); |
| 21364 |
NK_ASSERT(cur); |
| 21365 |
NK_ASSERT(ctx->current); |
| 21366 |
NK_ASSERT(ctx->current->layout); |
| 21367 |
if (!ctx || !ctx->current || !ctx->current->layout || !cur) |
| 21368 |
return 0; |
| 21369 |
|
| 21370 |
win = ctx->current; |
| 21371 |
style = &ctx->style; |
| 21372 |
layout = win->layout; |
| 21373 |
state = nk_widget(&bounds, ctx); |
| 21374 |
if (!state) return 0; |
| 21375 |
|
| 21376 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 21377 |
old_value = *cur; |
| 21378 |
*cur = nk_do_progress(&ctx->last_widget_state, &win->buffer, bounds, |
| 21379 |
*cur, max, is_modifyable, &style->progress, in); |
| 21380 |
return (*cur != old_value); |
| 21381 |
} |
| 21382 |
NK_API nk_size |
| 21383 |
nk_prog(struct nk_context *ctx, nk_size cur, nk_size max, int modifyable) |
| 21384 |
{ |
| 21385 |
nk_progress(ctx, &cur, max, modifyable); |
| 21386 |
return cur; |
| 21387 |
} |
| 21388 |
|
| 21389 |
|
| 21390 |
|
| 21391 |
|
| 21392 |
|
| 21393 |
|
| 21394 |
|
| 21395 |
|
| 21396 |
|
| 21397 |
|
| 21398 |
NK_LIB float |
| 21399 |
nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, |
| 21400 |
int has_scrolling, const struct nk_rect *scroll, |
| 21401 |
const struct nk_rect *cursor, const struct nk_rect *empty0, |
| 21402 |
const struct nk_rect *empty1, float scroll_offset, |
| 21403 |
float target, float scroll_step, enum nk_orientation o) |
| 21404 |
{ |
| 21405 |
nk_flags ws = 0; |
| 21406 |
int left_mouse_down; |
| 21407 |
int left_mouse_clicked; |
| 21408 |
int left_mouse_click_in_cursor; |
| 21409 |
float scroll_delta; |
| 21410 |
|
| 21411 |
nk_widget_state_reset(state); |
| 21412 |
if (!in) return scroll_offset; |
| 21413 |
|
| 21414 |
left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down; |
| 21415 |
left_mouse_clicked = in->mouse.buttons[NK_BUTTON_LEFT].clicked; |
| 21416 |
left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(in, |
| 21417 |
NK_BUTTON_LEFT, *cursor, nk_true); |
| 21418 |
if (nk_input_is_mouse_hovering_rect(in, *scroll)) |
| 21419 |
*state = NK_WIDGET_STATE_HOVERED; |
| 21420 |
|
| 21421 |
scroll_delta = (o == NK_VERTICAL) ? in->mouse.scroll_delta.y: in->mouse.scroll_delta.x; |
| 21422 |
if (left_mouse_down && left_mouse_click_in_cursor && !left_mouse_clicked) { |
| 21423 |
|
| 21424 |
float pixel, delta; |
| 21425 |
*state = NK_WIDGET_STATE_ACTIVE; |
| 21426 |
if (o == NK_VERTICAL) { |
| 21427 |
float cursor_y; |
| 21428 |
pixel = in->mouse.delta.y; |
| 21429 |
delta = (pixel / scroll->h) * target; |
| 21430 |
scroll_offset = NK_CLAMP(0, scroll_offset + delta, target - scroll->h); |
| 21431 |
cursor_y = scroll->y + ((scroll_offset/target) * scroll->h); |
| 21432 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y = cursor_y + cursor->h/2.0f; |
| 21433 |
} else { |
| 21434 |
float cursor_x; |
| 21435 |
pixel = in->mouse.delta.x; |
| 21436 |
delta = (pixel / scroll->w) * target; |
| 21437 |
scroll_offset = NK_CLAMP(0, scroll_offset + delta, target - scroll->w); |
| 21438 |
cursor_x = scroll->x + ((scroll_offset/target) * scroll->w); |
| 21439 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = cursor_x + cursor->w/2.0f; |
| 21440 |
} |
| 21441 |
} else if ((nk_input_is_key_pressed(in, NK_KEY_SCROLL_UP) && o == NK_VERTICAL && has_scrolling)|| |
| 21442 |
nk_button_behavior(&ws, *empty0, in, NK_BUTTON_DEFAULT)) { |
| 21443 |
|
| 21444 |
if (o == NK_VERTICAL) |
| 21445 |
scroll_offset = NK_MAX(0, scroll_offset - scroll->h); |
| 21446 |
else scroll_offset = NK_MAX(0, scroll_offset - scroll->w); |
| 21447 |
} else if ((nk_input_is_key_pressed(in, NK_KEY_SCROLL_DOWN) && o == NK_VERTICAL && has_scrolling) || |
| 21448 |
nk_button_behavior(&ws, *empty1, in, NK_BUTTON_DEFAULT)) { |
| 21449 |
|
| 21450 |
if (o == NK_VERTICAL) |
| 21451 |
scroll_offset = NK_MIN(scroll_offset + scroll->h, target - scroll->h); |
| 21452 |
else scroll_offset = NK_MIN(scroll_offset + scroll->w, target - scroll->w); |
| 21453 |
} else if (has_scrolling) { |
| 21454 |
if ((scroll_delta < 0 || (scroll_delta > 0))) { |
| 21455 |
|
| 21456 |
scroll_offset = scroll_offset + scroll_step * (-scroll_delta); |
| 21457 |
if (o == NK_VERTICAL) |
| 21458 |
scroll_offset = NK_CLAMP(0, scroll_offset, target - scroll->h); |
| 21459 |
else scroll_offset = NK_CLAMP(0, scroll_offset, target - scroll->w); |
| 21460 |
} else if (nk_input_is_key_pressed(in, NK_KEY_SCROLL_START)) { |
| 21461 |
|
| 21462 |
if (o == NK_VERTICAL) scroll_offset = 0; |
| 21463 |
} else if (nk_input_is_key_pressed(in, NK_KEY_SCROLL_END)) { |
| 21464 |
|
| 21465 |
if (o == NK_VERTICAL) scroll_offset = target - scroll->h; |
| 21466 |
} |
| 21467 |
} |
| 21468 |
if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, *scroll)) |
| 21469 |
*state |= NK_WIDGET_STATE_ENTERED; |
| 21470 |
else if (nk_input_is_mouse_prev_hovering_rect(in, *scroll)) |
| 21471 |
*state |= NK_WIDGET_STATE_LEFT; |
| 21472 |
return scroll_offset; |
| 21473 |
} |
| 21474 |
NK_LIB void |
| 21475 |
nk_draw_scrollbar(struct nk_command_buffer *out, nk_flags state, |
| 21476 |
const struct nk_style_scrollbar *style, const struct nk_rect *bounds, |
| 21477 |
const struct nk_rect *scroll) |
| 21478 |
{ |
| 21479 |
const struct nk_style_item *background; |
| 21480 |
const struct nk_style_item *cursor; |
| 21481 |
|
| 21482 |
|
| 21483 |
if (state & NK_WIDGET_STATE_ACTIVED) { |
| 21484 |
background = &style->active; |
| 21485 |
cursor = &style->cursor_active; |
| 21486 |
} else if (state & NK_WIDGET_STATE_HOVER) { |
| 21487 |
background = &style->hover; |
| 21488 |
cursor = &style->cursor_hover; |
| 21489 |
} else { |
| 21490 |
background = &style->normal; |
| 21491 |
cursor = &style->cursor_normal; |
| 21492 |
} |
| 21493 |
|
| 21494 |
|
| 21495 |
if (background->type == NK_STYLE_ITEM_COLOR) { |
| 21496 |
nk_fill_rect(out, *bounds, style->rounding, background->data.color); |
| 21497 |
nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); |
| 21498 |
} else { |
| 21499 |
nk_draw_image(out, *bounds, &background->data.image, nk_white); |
| 21500 |
} |
| 21501 |
|
| 21502 |
|
| 21503 |
if (cursor->type == NK_STYLE_ITEM_COLOR) { |
| 21504 |
nk_fill_rect(out, *scroll, style->rounding_cursor, cursor->data.color); |
| 21505 |
nk_stroke_rect(out, *scroll, style->rounding_cursor, style->border_cursor, style->cursor_border_color); |
| 21506 |
} else nk_draw_image(out, *scroll, &cursor->data.image, nk_white); |
| 21507 |
} |
| 21508 |
NK_LIB float |
| 21509 |
nk_do_scrollbarv(nk_flags *state, |
| 21510 |
struct nk_command_buffer *out, struct nk_rect scroll, int has_scrolling, |
| 21511 |
float offset, float target, float step, float button_pixel_inc, |
| 21512 |
const struct nk_style_scrollbar *style, struct nk_input *in, |
| 21513 |
const struct nk_user_font *font) |
| 21514 |
{ |
| 21515 |
struct nk_rect empty_north; |
| 21516 |
struct nk_rect empty_south; |
| 21517 |
struct nk_rect cursor; |
| 21518 |
|
| 21519 |
float scroll_step; |
| 21520 |
float scroll_offset; |
| 21521 |
float scroll_off; |
| 21522 |
float scroll_ratio; |
| 21523 |
|
| 21524 |
NK_ASSERT(out); |
| 21525 |
NK_ASSERT(style); |
| 21526 |
NK_ASSERT(state); |
| 21527 |
if (!out || !style) return 0; |
| 21528 |
|
| 21529 |
scroll.w = NK_MAX(scroll.w, 1); |
| 21530 |
scroll.h = NK_MAX(scroll.h, 0); |
| 21531 |
if (target <= scroll.h) return 0; |
| 21532 |
|
| 21533 |
|
| 21534 |
if (style->show_buttons) { |
| 21535 |
nk_flags ws; |
| 21536 |
float scroll_h; |
| 21537 |
struct nk_rect button; |
| 21538 |
|
| 21539 |
button.x = scroll.x; |
| 21540 |
button.w = scroll.w; |
| 21541 |
button.h = scroll.w; |
| 21542 |
|
| 21543 |
scroll_h = NK_MAX(scroll.h - 2 * button.h,0); |
| 21544 |
scroll_step = NK_MIN(step, button_pixel_inc); |
| 21545 |
|
| 21546 |
|
| 21547 |
button.y = scroll.y; |
| 21548 |
if (nk_do_button_symbol(&ws, out, button, style->dec_symbol, |
| 21549 |
NK_BUTTON_REPEATER, &style->dec_button, in, font)) |
| 21550 |
offset = offset - scroll_step; |
| 21551 |
|
| 21552 |
|
| 21553 |
button.y = scroll.y + scroll.h - button.h; |
| 21554 |
if (nk_do_button_symbol(&ws, out, button, style->inc_symbol, |
| 21555 |
NK_BUTTON_REPEATER, &style->inc_button, in, font)) |
| 21556 |
offset = offset + scroll_step; |
| 21557 |
|
| 21558 |
scroll.y = scroll.y + button.h; |
| 21559 |
scroll.h = scroll_h; |
| 21560 |
} |
| 21561 |
|
| 21562 |
|
| 21563 |
scroll_step = NK_MIN(step, scroll.h); |
| 21564 |
scroll_offset = NK_CLAMP(0, offset, target - scroll.h); |
| 21565 |
scroll_ratio = scroll.h / target; |
| 21566 |
scroll_off = scroll_offset / target; |
| 21567 |
|
| 21568 |
|
| 21569 |
cursor.h = NK_MAX((scroll_ratio * scroll.h) - (2*style->border + 2*style->padding.y), 0); |
| 21570 |
cursor.y = scroll.y + (scroll_off * scroll.h) + style->border + style->padding.y; |
| 21571 |
cursor.w = scroll.w - (2 * style->border + 2 * style->padding.x); |
| 21572 |
cursor.x = scroll.x + style->border + style->padding.x; |
| 21573 |
|
| 21574 |
|
| 21575 |
empty_north.x = scroll.x; |
| 21576 |
empty_north.y = scroll.y; |
| 21577 |
empty_north.w = scroll.w; |
| 21578 |
empty_north.h = NK_MAX(cursor.y - scroll.y, 0); |
| 21579 |
|
| 21580 |
empty_south.x = scroll.x; |
| 21581 |
empty_south.y = cursor.y + cursor.h; |
| 21582 |
empty_south.w = scroll.w; |
| 21583 |
empty_south.h = NK_MAX((scroll.y + scroll.h) - (cursor.y + cursor.h), 0); |
| 21584 |
|
| 21585 |
|
| 21586 |
scroll_offset = nk_scrollbar_behavior(state, in, has_scrolling, &scroll, &cursor, |
| 21587 |
&empty_north, &empty_south, scroll_offset, target, scroll_step, NK_VERTICAL); |
| 21588 |
scroll_off = scroll_offset / target; |
| 21589 |
cursor.y = scroll.y + (scroll_off * scroll.h) + style->border_cursor + style->padding.y; |
| 21590 |
|
| 21591 |
|
| 21592 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 21593 |
nk_draw_scrollbar(out, *state, style, &scroll, &cursor); |
| 21594 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 21595 |
return scroll_offset; |
| 21596 |
} |
| 21597 |
NK_LIB float |
| 21598 |
nk_do_scrollbarh(nk_flags *state, |
| 21599 |
struct nk_command_buffer *out, struct nk_rect scroll, int has_scrolling, |
| 21600 |
float offset, float target, float step, float button_pixel_inc, |
| 21601 |
const struct nk_style_scrollbar *style, struct nk_input *in, |
| 21602 |
const struct nk_user_font *font) |
| 21603 |
{ |
| 21604 |
struct nk_rect cursor; |
| 21605 |
struct nk_rect empty_west; |
| 21606 |
struct nk_rect empty_east; |
| 21607 |
|
| 21608 |
float scroll_step; |
| 21609 |
float scroll_offset; |
| 21610 |
float scroll_off; |
| 21611 |
float scroll_ratio; |
| 21612 |
|
| 21613 |
NK_ASSERT(out); |
| 21614 |
NK_ASSERT(style); |
| 21615 |
if (!out || !style) return 0; |
| 21616 |
|
| 21617 |
|
| 21618 |
scroll.h = NK_MAX(scroll.h, 1); |
| 21619 |
scroll.w = NK_MAX(scroll.w, 2 * scroll.h); |
| 21620 |
if (target <= scroll.w) return 0; |
| 21621 |
|
| 21622 |
|
| 21623 |
if (style->show_buttons) { |
| 21624 |
nk_flags ws; |
| 21625 |
float scroll_w; |
| 21626 |
struct nk_rect button; |
| 21627 |
button.y = scroll.y; |
| 21628 |
button.w = scroll.h; |
| 21629 |
button.h = scroll.h; |
| 21630 |
|
| 21631 |
scroll_w = scroll.w - 2 * button.w; |
| 21632 |
scroll_step = NK_MIN(step, button_pixel_inc); |
| 21633 |
|
| 21634 |
|
| 21635 |
button.x = scroll.x; |
| 21636 |
if (nk_do_button_symbol(&ws, out, button, style->dec_symbol, |
| 21637 |
NK_BUTTON_REPEATER, &style->dec_button, in, font)) |
| 21638 |
offset = offset - scroll_step; |
| 21639 |
|
| 21640 |
|
| 21641 |
button.x = scroll.x + scroll.w - button.w; |
| 21642 |
if (nk_do_button_symbol(&ws, out, button, style->inc_symbol, |
| 21643 |
NK_BUTTON_REPEATER, &style->inc_button, in, font)) |
| 21644 |
offset = offset + scroll_step; |
| 21645 |
|
| 21646 |
scroll.x = scroll.x + button.w; |
| 21647 |
scroll.w = scroll_w; |
| 21648 |
} |
| 21649 |
|
| 21650 |
|
| 21651 |
scroll_step = NK_MIN(step, scroll.w); |
| 21652 |
scroll_offset = NK_CLAMP(0, offset, target - scroll.w); |
| 21653 |
scroll_ratio = scroll.w / target; |
| 21654 |
scroll_off = scroll_offset / target; |
| 21655 |
|
| 21656 |
|
| 21657 |
cursor.w = (scroll_ratio * scroll.w) - (2*style->border + 2*style->padding.x); |
| 21658 |
cursor.x = scroll.x + (scroll_off * scroll.w) + style->border + style->padding.x; |
| 21659 |
cursor.h = scroll.h - (2 * style->border + 2 * style->padding.y); |
| 21660 |
cursor.y = scroll.y + style->border + style->padding.y; |
| 21661 |
|
| 21662 |
|
| 21663 |
empty_west.x = scroll.x; |
| 21664 |
empty_west.y = scroll.y; |
| 21665 |
empty_west.w = cursor.x - scroll.x; |
| 21666 |
empty_west.h = scroll.h; |
| 21667 |
|
| 21668 |
empty_east.x = cursor.x + cursor.w; |
| 21669 |
empty_east.y = scroll.y; |
| 21670 |
empty_east.w = (scroll.x + scroll.w) - (cursor.x + cursor.w); |
| 21671 |
empty_east.h = scroll.h; |
| 21672 |
|
| 21673 |
|
| 21674 |
scroll_offset = nk_scrollbar_behavior(state, in, has_scrolling, &scroll, &cursor, |
| 21675 |
&empty_west, &empty_east, scroll_offset, target, scroll_step, NK_HORIZONTAL); |
| 21676 |
scroll_off = scroll_offset / target; |
| 21677 |
cursor.x = scroll.x + (scroll_off * scroll.w); |
| 21678 |
|
| 21679 |
|
| 21680 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 21681 |
nk_draw_scrollbar(out, *state, style, &scroll, &cursor); |
| 21682 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 21683 |
return scroll_offset; |
| 21684 |
} |
| 21685 |
|
| 21686 |
|
| 21687 |
|
| 21688 |
|
| 21689 |
|
| 21690 |
|
| 21691 |
|
| 21692 |
|
| 21693 |
|
| 21694 |
|
| 21695 |
|
| 21696 |
struct nk_text_find { |
| 21697 |
float x,y; |
| 21698 |
float height; |
| 21699 |
int first_char, length; |
| 21700 |
int prev_first; |
| 21701 |
}; |
| 21702 |
|
| 21703 |
struct nk_text_edit_row { |
| 21704 |
float x0,x1; |
| 21705 |
|
| 21706 |
float baseline_y_delta; |
| 21707 |
|
| 21708 |
float ymin,ymax; |
| 21709 |
|
| 21710 |
int num_chars; |
| 21711 |
}; |
| 21712 |
|
| 21713 |
|
| 21714 |
NK_INTERN void nk_textedit_makeundo_delete(struct nk_text_edit*, int, int); |
| 21715 |
NK_INTERN void nk_textedit_makeundo_insert(struct nk_text_edit*, int, int); |
| 21716 |
NK_INTERN void nk_textedit_makeundo_replace(struct nk_text_edit*, int, int, int); |
| 21717 |
#define NK_TEXT_HAS_SELECTION(s) ((s)->select_start != (s)->select_end) |
| 21718 |
|
| 21719 |
NK_INTERN float |
| 21720 |
nk_textedit_get_width(const struct nk_text_edit *edit, int line_start, int char_id, |
| 21721 |
const struct nk_user_font *font) |
| 21722 |
{ |
| 21723 |
int len = 0; |
| 21724 |
nk_rune unicode = 0; |
| 21725 |
const char *str = nk_str_at_const(&edit->string, line_start + char_id, &unicode, &len); |
| 21726 |
return font->width(font->userdata, font->height, str, len); |
| 21727 |
} |
| 21728 |
NK_INTERN void |
| 21729 |
nk_textedit_layout_row(struct nk_text_edit_row *r, struct nk_text_edit *edit, |
| 21730 |
int line_start_id, float row_height, const struct nk_user_font *font) |
| 21731 |
{ |
| 21732 |
int l; |
| 21733 |
int glyphs = 0; |
| 21734 |
nk_rune unicode; |
| 21735 |
const char *remaining; |
| 21736 |
int len = nk_str_len_char(&edit->string); |
| 21737 |
const char *end = nk_str_get_const(&edit->string) + len; |
| 21738 |
const char *text = nk_str_at_const(&edit->string, line_start_id, &unicode, &l); |
| 21739 |
const struct nk_vec2 size = nk_text_calculate_text_bounds(font, |
| 21740 |
text, (int)(end - text), row_height, &remaining, 0, &glyphs, NK_STOP_ON_NEW_LINE); |
| 21741 |
|
| 21742 |
r->x0 = 0.0f; |
| 21743 |
r->x1 = size.x; |
| 21744 |
r->baseline_y_delta = size.y; |
| 21745 |
r->ymin = 0.0f; |
| 21746 |
r->ymax = size.y; |
| 21747 |
r->num_chars = glyphs; |
| 21748 |
} |
| 21749 |
NK_INTERN int |
| 21750 |
nk_textedit_locate_coord(struct nk_text_edit *edit, float x, float y, |
| 21751 |
const struct nk_user_font *font, float row_height) |
| 21752 |
{ |
| 21753 |
struct nk_text_edit_row r; |
| 21754 |
int n = edit->string.len; |
| 21755 |
float base_y = 0, prev_x; |
| 21756 |
int i=0, k; |
| 21757 |
|
| 21758 |
r.x0 = r.x1 = 0; |
| 21759 |
r.ymin = r.ymax = 0; |
| 21760 |
r.num_chars = 0; |
| 21761 |
|
| 21762 |
|
| 21763 |
while (i < n) { |
| 21764 |
nk_textedit_layout_row(&r, edit, i, row_height, font); |
| 21765 |
if (r.num_chars <= 0) |
| 21766 |
return n; |
| 21767 |
|
| 21768 |
if (i==0 && y < base_y + r.ymin) |
| 21769 |
return 0; |
| 21770 |
|
| 21771 |
if (y < base_y + r.ymax) |
| 21772 |
break; |
| 21773 |
|
| 21774 |
i += r.num_chars; |
| 21775 |
base_y += r.baseline_y_delta; |
| 21776 |
} |
| 21777 |
|
| 21778 |
|
| 21779 |
if (i >= n) |
| 21780 |
return n; |
| 21781 |
|
| 21782 |
|
| 21783 |
if (x < r.x0) |
| 21784 |
return i; |
| 21785 |
|
| 21786 |
|
| 21787 |
if (x < r.x1) { |
| 21788 |
|
| 21789 |
k = i; |
| 21790 |
prev_x = r.x0; |
| 21791 |
for (i=0; i < r.num_chars; ++i) { |
| 21792 |
float w = nk_textedit_get_width(edit, k, i, font); |
| 21793 |
if (x < prev_x+w) { |
| 21794 |
if (x < prev_x+w/2) |
| 21795 |
return k+i; |
| 21796 |
else return k+i+1; |
| 21797 |
} |
| 21798 |
prev_x += w; |
| 21799 |
} |
| 21800 |
|
| 21801 |
} |
| 21802 |
|
| 21803 |
|
| 21804 |
|
| 21805 |
if (nk_str_rune_at(&edit->string, i+r.num_chars-1) == '\n') |
| 21806 |
return i+r.num_chars-1; |
| 21807 |
else return i+r.num_chars; |
| 21808 |
} |
| 21809 |
NK_LIB void |
| 21810 |
nk_textedit_click(struct nk_text_edit *state, float x, float y, |
| 21811 |
const struct nk_user_font *font, float row_height) |
| 21812 |
{ |
| 21813 |
|
| 21814 |
|
| 21815 |
state->cursor = nk_textedit_locate_coord(state, x, y, font, row_height); |
| 21816 |
state->select_start = state->cursor; |
| 21817 |
state->select_end = state->cursor; |
| 21818 |
state->has_preferred_x = 0; |
| 21819 |
} |
| 21820 |
NK_LIB void |
| 21821 |
nk_textedit_drag(struct nk_text_edit *state, float x, float y, |
| 21822 |
const struct nk_user_font *font, float row_height) |
| 21823 |
{ |
| 21824 |
|
| 21825 |
|
| 21826 |
int p = nk_textedit_locate_coord(state, x, y, font, row_height); |
| 21827 |
if (state->select_start == state->select_end) |
| 21828 |
state->select_start = state->cursor; |
| 21829 |
state->cursor = state->select_end = p; |
| 21830 |
} |
| 21831 |
NK_INTERN void |
| 21832 |
nk_textedit_find_charpos(struct nk_text_find *find, struct nk_text_edit *state, |
| 21833 |
int n, int single_line, const struct nk_user_font *font, float row_height) |
| 21834 |
{ |
| 21835 |
|
| 21836 |
|
| 21837 |
struct nk_text_edit_row r; |
| 21838 |
int prev_start = 0; |
| 21839 |
int z = state->string.len; |
| 21840 |
int i=0, first; |
| 21841 |
|
| 21842 |
nk_zero_struct(r); |
| 21843 |
if (n == z) { |
| 21844 |
|
| 21845 |
|
| 21846 |
nk_textedit_layout_row(&r, state, 0, row_height, font); |
| 21847 |
if (single_line) { |
| 21848 |
find->first_char = 0; |
| 21849 |
find->length = z; |
| 21850 |
} else { |
| 21851 |
while (i < z) { |
| 21852 |
prev_start = i; |
| 21853 |
i += r.num_chars; |
| 21854 |
nk_textedit_layout_row(&r, state, i, row_height, font); |
| 21855 |
} |
| 21856 |
|
| 21857 |
find->first_char = i; |
| 21858 |
find->length = r.num_chars; |
| 21859 |
} |
| 21860 |
find->x = r.x1; |
| 21861 |
find->y = r.ymin; |
| 21862 |
find->height = r.ymax - r.ymin; |
| 21863 |
find->prev_first = prev_start; |
| 21864 |
return; |
| 21865 |
} |
| 21866 |
|
| 21867 |
|
| 21868 |
find->y = 0; |
| 21869 |
|
| 21870 |
for(;;) { |
| 21871 |
nk_textedit_layout_row(&r, state, i, row_height, font); |
| 21872 |
if (n < i + r.num_chars) break; |
| 21873 |
prev_start = i; |
| 21874 |
i += r.num_chars; |
| 21875 |
find->y += r.baseline_y_delta; |
| 21876 |
} |
| 21877 |
|
| 21878 |
find->first_char = first = i; |
| 21879 |
find->length = r.num_chars; |
| 21880 |
find->height = r.ymax - r.ymin; |
| 21881 |
find->prev_first = prev_start; |
| 21882 |
|
| 21883 |
|
| 21884 |
find->x = r.x0; |
| 21885 |
for (i=0; first+i < n; ++i) |
| 21886 |
find->x += nk_textedit_get_width(state, first, i, font); |
| 21887 |
} |
| 21888 |
NK_INTERN void |
| 21889 |
nk_textedit_clamp(struct nk_text_edit *state) |
| 21890 |
{ |
| 21891 |
|
| 21892 |
int n = state->string.len; |
| 21893 |
if (NK_TEXT_HAS_SELECTION(state)) { |
| 21894 |
if (state->select_start > n) state->select_start = n; |
| 21895 |
if (state->select_end > n) state->select_end = n; |
| 21896 |
|
| 21897 |
if (state->select_start == state->select_end) |
| 21898 |
state->cursor = state->select_start; |
| 21899 |
} |
| 21900 |
if (state->cursor > n) state->cursor = n; |
| 21901 |
} |
| 21902 |
NK_API void |
| 21903 |
nk_textedit_delete(struct nk_text_edit *state, int where, int len) |
| 21904 |
{ |
| 21905 |
|
| 21906 |
nk_textedit_makeundo_delete(state, where, len); |
| 21907 |
nk_str_delete_runes(&state->string, where, len); |
| 21908 |
state->has_preferred_x = 0; |
| 21909 |
} |
| 21910 |
NK_API void |
| 21911 |
nk_textedit_delete_selection(struct nk_text_edit *state) |
| 21912 |
{ |
| 21913 |
|
| 21914 |
nk_textedit_clamp(state); |
| 21915 |
if (NK_TEXT_HAS_SELECTION(state)) { |
| 21916 |
if (state->select_start < state->select_end) { |
| 21917 |
nk_textedit_delete(state, state->select_start, |
| 21918 |
state->select_end - state->select_start); |
| 21919 |
state->select_end = state->cursor = state->select_start; |
| 21920 |
} else { |
| 21921 |
nk_textedit_delete(state, state->select_end, |
| 21922 |
state->select_start - state->select_end); |
| 21923 |
state->select_start = state->cursor = state->select_end; |
| 21924 |
} |
| 21925 |
state->has_preferred_x = 0; |
| 21926 |
} |
| 21927 |
} |
| 21928 |
NK_INTERN void |
| 21929 |
nk_textedit_sortselection(struct nk_text_edit *state) |
| 21930 |
{ |
| 21931 |
|
| 21932 |
if (state->select_end < state->select_start) { |
| 21933 |
int temp = state->select_end; |
| 21934 |
state->select_end = state->select_start; |
| 21935 |
state->select_start = temp; |
| 21936 |
} |
| 21937 |
} |
| 21938 |
NK_INTERN void |
| 21939 |
nk_textedit_move_to_first(struct nk_text_edit *state) |
| 21940 |
{ |
| 21941 |
|
| 21942 |
if (NK_TEXT_HAS_SELECTION(state)) { |
| 21943 |
nk_textedit_sortselection(state); |
| 21944 |
state->cursor = state->select_start; |
| 21945 |
state->select_end = state->select_start; |
| 21946 |
state->has_preferred_x = 0; |
| 21947 |
} |
| 21948 |
} |
| 21949 |
NK_INTERN void |
| 21950 |
nk_textedit_move_to_last(struct nk_text_edit *state) |
| 21951 |
{ |
| 21952 |
|
| 21953 |
if (NK_TEXT_HAS_SELECTION(state)) { |
| 21954 |
nk_textedit_sortselection(state); |
| 21955 |
nk_textedit_clamp(state); |
| 21956 |
state->cursor = state->select_end; |
| 21957 |
state->select_start = state->select_end; |
| 21958 |
state->has_preferred_x = 0; |
| 21959 |
} |
| 21960 |
} |
| 21961 |
NK_INTERN int |
| 21962 |
nk_is_word_boundary( struct nk_text_edit *state, int idx) |
| 21963 |
{ |
| 21964 |
int len; |
| 21965 |
nk_rune c; |
| 21966 |
if (idx <= 0) return 1; |
| 21967 |
if (!nk_str_at_rune(&state->string, idx, &c, &len)) return 1; |
| 21968 |
return (c == ' ' || c == '\t' ||c == 0x3000 || c == ',' || c == ';' || |
| 21969 |
c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' || |
| 21970 |
c == '|'); |
| 21971 |
} |
| 21972 |
NK_INTERN int |
| 21973 |
nk_textedit_move_to_word_previous(struct nk_text_edit *state) |
| 21974 |
{ |
| 21975 |
int c = state->cursor - 1; |
| 21976 |
while( c >= 0 && !nk_is_word_boundary(state, c)) |
| 21977 |
--c; |
| 21978 |
|
| 21979 |
if( c < 0 ) |
| 21980 |
c = 0; |
| 21981 |
|
| 21982 |
return c; |
| 21983 |
} |
| 21984 |
NK_INTERN int |
| 21985 |
nk_textedit_move_to_word_next(struct nk_text_edit *state) |
| 21986 |
{ |
| 21987 |
const int len = state->string.len; |
| 21988 |
int c = state->cursor+1; |
| 21989 |
while( c < len && !nk_is_word_boundary(state, c)) |
| 21990 |
++c; |
| 21991 |
|
| 21992 |
if( c > len ) |
| 21993 |
c = len; |
| 21994 |
|
| 21995 |
return c; |
| 21996 |
} |
| 21997 |
NK_INTERN void |
| 21998 |
nk_textedit_prep_selection_at_cursor(struct nk_text_edit *state) |
| 21999 |
{ |
| 22000 |
|
| 22001 |
if (!NK_TEXT_HAS_SELECTION(state)) |
| 22002 |
state->select_start = state->select_end = state->cursor; |
| 22003 |
else state->cursor = state->select_end; |
| 22004 |
} |
| 22005 |
NK_API int |
| 22006 |
nk_textedit_cut(struct nk_text_edit *state) |
| 22007 |
{ |
| 22008 |
|
| 22009 |
if (state->mode == NK_TEXT_EDIT_MODE_VIEW) |
| 22010 |
return 0; |
| 22011 |
if (NK_TEXT_HAS_SELECTION(state)) { |
| 22012 |
nk_textedit_delete_selection(state); |
| 22013 |
state->has_preferred_x = 0; |
| 22014 |
return 1; |
| 22015 |
} |
| 22016 |
return 0; |
| 22017 |
} |
| 22018 |
NK_API int |
| 22019 |
nk_textedit_paste(struct nk_text_edit *state, char const *ctext, int len) |
| 22020 |
{ |
| 22021 |
|
| 22022 |
int glyphs; |
| 22023 |
const char *text = (const char *) ctext; |
| 22024 |
if (state->mode == NK_TEXT_EDIT_MODE_VIEW) return 0; |
| 22025 |
|
| 22026 |
|
| 22027 |
nk_textedit_clamp(state); |
| 22028 |
nk_textedit_delete_selection(state); |
| 22029 |
|
| 22030 |
|
| 22031 |
glyphs = nk_utf_len(ctext, len); |
| 22032 |
if (nk_str_insert_text_char(&state->string, state->cursor, text, len)) { |
| 22033 |
nk_textedit_makeundo_insert(state, state->cursor, glyphs); |
| 22034 |
state->cursor += len; |
| 22035 |
state->has_preferred_x = 0; |
| 22036 |
return 1; |
| 22037 |
} |
| 22038 |
|
| 22039 |
if (state->undo.undo_point) |
| 22040 |
--state->undo.undo_point; |
| 22041 |
return 0; |
| 22042 |
} |
| 22043 |
NK_API void |
| 22044 |
nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len) |
| 22045 |
{ |
| 22046 |
nk_rune unicode; |
| 22047 |
int glyph_len; |
| 22048 |
int text_len = 0; |
| 22049 |
|
| 22050 |
NK_ASSERT(state); |
| 22051 |
NK_ASSERT(text); |
| 22052 |
if (!text || !total_len || state->mode == NK_TEXT_EDIT_MODE_VIEW) return; |
| 22053 |
|
| 22054 |
glyph_len = nk_utf_decode(text, &unicode, total_len); |
| 22055 |
while ((text_len < total_len) && glyph_len) |
| 22056 |
{ |
| 22057 |
|
| 22058 |
if (unicode == 127) goto next; |
| 22059 |
|
| 22060 |
if (unicode == '\n' && state->single_line) goto next; |
| 22061 |
|
| 22062 |
if (state->filter && !state->filter(state, unicode)) goto next; |
| 22063 |
|
| 22064 |
if (!NK_TEXT_HAS_SELECTION(state) && |
| 22065 |
state->cursor < state->string.len) |
| 22066 |
{ |
| 22067 |
if (state->mode == NK_TEXT_EDIT_MODE_REPLACE) { |
| 22068 |
nk_textedit_makeundo_replace(state, state->cursor, 1, 1); |
| 22069 |
nk_str_delete_runes(&state->string, state->cursor, 1); |
| 22070 |
} |
| 22071 |
if (nk_str_insert_text_utf8(&state->string, state->cursor, |
| 22072 |
text+text_len, 1)) |
| 22073 |
{ |
| 22074 |
++state->cursor; |
| 22075 |
state->has_preferred_x = 0; |
| 22076 |
} |
| 22077 |
} else { |
| 22078 |
nk_textedit_delete_selection(state); |
| 22079 |
if (nk_str_insert_text_utf8(&state->string, state->cursor, |
| 22080 |
text+text_len, 1)) |
| 22081 |
{ |
| 22082 |
nk_textedit_makeundo_insert(state, state->cursor, 1); |
| 22083 |
++state->cursor; |
| 22084 |
state->has_preferred_x = 0; |
| 22085 |
} |
| 22086 |
} |
| 22087 |
next: |
| 22088 |
text_len += glyph_len; |
| 22089 |
glyph_len = nk_utf_decode(text + text_len, &unicode, total_len-text_len); |
| 22090 |
} |
| 22091 |
} |
| 22092 |
NK_LIB void |
| 22093 |
nk_textedit_key(struct nk_text_edit *state, enum nk_keys key, int shift_mod, |
| 22094 |
const struct nk_user_font *font, float row_height) |
| 22095 |
{ |
| 22096 |
retry: |
| 22097 |
switch (key) |
| 22098 |
{ |
| 22099 |
case NK_KEY_NONE: |
| 22100 |
case NK_KEY_CTRL: |
| 22101 |
case NK_KEY_ENTER: |
| 22102 |
case NK_KEY_SHIFT: |
| 22103 |
case NK_KEY_TAB: |
| 22104 |
case NK_KEY_COPY: |
| 22105 |
case NK_KEY_CUT: |
| 22106 |
case NK_KEY_PASTE: |
| 22107 |
case NK_KEY_MAX: |
| 22108 |
default: break; |
| 22109 |
case NK_KEY_TEXT_UNDO: |
| 22110 |
nk_textedit_undo(state); |
| 22111 |
state->has_preferred_x = 0; |
| 22112 |
break; |
| 22113 |
|
| 22114 |
case NK_KEY_TEXT_REDO: |
| 22115 |
nk_textedit_redo(state); |
| 22116 |
state->has_preferred_x = 0; |
| 22117 |
break; |
| 22118 |
|
| 22119 |
case NK_KEY_TEXT_SELECT_ALL: |
| 22120 |
nk_textedit_select_all(state); |
| 22121 |
state->has_preferred_x = 0; |
| 22122 |
break; |
| 22123 |
|
| 22124 |
case NK_KEY_TEXT_INSERT_MODE: |
| 22125 |
if (state->mode == NK_TEXT_EDIT_MODE_VIEW) |
| 22126 |
state->mode = NK_TEXT_EDIT_MODE_INSERT; |
| 22127 |
break; |
| 22128 |
case NK_KEY_TEXT_REPLACE_MODE: |
| 22129 |
if (state->mode == NK_TEXT_EDIT_MODE_VIEW) |
| 22130 |
state->mode = NK_TEXT_EDIT_MODE_REPLACE; |
| 22131 |
break; |
| 22132 |
case NK_KEY_TEXT_RESET_MODE: |
| 22133 |
if (state->mode == NK_TEXT_EDIT_MODE_INSERT || |
| 22134 |
state->mode == NK_TEXT_EDIT_MODE_REPLACE) |
| 22135 |
state->mode = NK_TEXT_EDIT_MODE_VIEW; |
| 22136 |
break; |
| 22137 |
|
| 22138 |
case NK_KEY_LEFT: |
| 22139 |
if (shift_mod) { |
| 22140 |
nk_textedit_clamp(state); |
| 22141 |
nk_textedit_prep_selection_at_cursor(state); |
| 22142 |
|
| 22143 |
if (state->select_end > 0) |
| 22144 |
--state->select_end; |
| 22145 |
state->cursor = state->select_end; |
| 22146 |
state->has_preferred_x = 0; |
| 22147 |
} else { |
| 22148 |
|
| 22149 |
|
| 22150 |
if (NK_TEXT_HAS_SELECTION(state)) |
| 22151 |
nk_textedit_move_to_first(state); |
| 22152 |
else if (state->cursor > 0) |
| 22153 |
--state->cursor; |
| 22154 |
state->has_preferred_x = 0; |
| 22155 |
} break; |
| 22156 |
|
| 22157 |
case NK_KEY_RIGHT: |
| 22158 |
if (shift_mod) { |
| 22159 |
nk_textedit_prep_selection_at_cursor(state); |
| 22160 |
|
| 22161 |
++state->select_end; |
| 22162 |
nk_textedit_clamp(state); |
| 22163 |
state->cursor = state->select_end; |
| 22164 |
state->has_preferred_x = 0; |
| 22165 |
} else { |
| 22166 |
|
| 22167 |
|
| 22168 |
if (NK_TEXT_HAS_SELECTION(state)) |
| 22169 |
nk_textedit_move_to_last(state); |
| 22170 |
else ++state->cursor; |
| 22171 |
nk_textedit_clamp(state); |
| 22172 |
state->has_preferred_x = 0; |
| 22173 |
} break; |
| 22174 |
|
| 22175 |
case NK_KEY_TEXT_WORD_LEFT: |
| 22176 |
if (shift_mod) { |
| 22177 |
if( !NK_TEXT_HAS_SELECTION( state ) ) |
| 22178 |
nk_textedit_prep_selection_at_cursor(state); |
| 22179 |
state->cursor = nk_textedit_move_to_word_previous(state); |
| 22180 |
state->select_end = state->cursor; |
| 22181 |
nk_textedit_clamp(state ); |
| 22182 |
} else { |
| 22183 |
if (NK_TEXT_HAS_SELECTION(state)) |
| 22184 |
nk_textedit_move_to_first(state); |
| 22185 |
else { |
| 22186 |
state->cursor = nk_textedit_move_to_word_previous(state); |
| 22187 |
nk_textedit_clamp(state ); |
| 22188 |
} |
| 22189 |
} break; |
| 22190 |
|
| 22191 |
case NK_KEY_TEXT_WORD_RIGHT: |
| 22192 |
if (shift_mod) { |
| 22193 |
if( !NK_TEXT_HAS_SELECTION( state ) ) |
| 22194 |
nk_textedit_prep_selection_at_cursor(state); |
| 22195 |
state->cursor = nk_textedit_move_to_word_next(state); |
| 22196 |
state->select_end = state->cursor; |
| 22197 |
nk_textedit_clamp(state); |
| 22198 |
} else { |
| 22199 |
if (NK_TEXT_HAS_SELECTION(state)) |
| 22200 |
nk_textedit_move_to_last(state); |
| 22201 |
else { |
| 22202 |
state->cursor = nk_textedit_move_to_word_next(state); |
| 22203 |
nk_textedit_clamp(state ); |
| 22204 |
} |
| 22205 |
} break; |
| 22206 |
|
| 22207 |
case NK_KEY_DOWN: { |
| 22208 |
struct nk_text_find find; |
| 22209 |
struct nk_text_edit_row row; |
| 22210 |
int i, sel = shift_mod; |
| 22211 |
|
| 22212 |
if (state->single_line) { |
| 22213 |
|
| 22214 |
key = NK_KEY_RIGHT; |
| 22215 |
goto retry; |
| 22216 |
} |
| 22217 |
|
| 22218 |
if (sel) |
| 22219 |
nk_textedit_prep_selection_at_cursor(state); |
| 22220 |
else if (NK_TEXT_HAS_SELECTION(state)) |
| 22221 |
nk_textedit_move_to_last(state); |
| 22222 |
|
| 22223 |
|
| 22224 |
nk_textedit_clamp(state); |
| 22225 |
nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, |
| 22226 |
font, row_height); |
| 22227 |
|
| 22228 |
|
| 22229 |
if (find.length) |
| 22230 |
{ |
| 22231 |
float x; |
| 22232 |
float goal_x = state->has_preferred_x ? state->preferred_x : find.x; |
| 22233 |
int start = find.first_char + find.length; |
| 22234 |
|
| 22235 |
state->cursor = start; |
| 22236 |
nk_textedit_layout_row(&row, state, state->cursor, row_height, font); |
| 22237 |
x = row.x0; |
| 22238 |
|
| 22239 |
for (i=0; i < row.num_chars && x < row.x1; ++i) { |
| 22240 |
float dx = nk_textedit_get_width(state, start, i, font); |
| 22241 |
x += dx; |
| 22242 |
if (x > goal_x) |
| 22243 |
break; |
| 22244 |
++state->cursor; |
| 22245 |
} |
| 22246 |
nk_textedit_clamp(state); |
| 22247 |
|
| 22248 |
state->has_preferred_x = 1; |
| 22249 |
state->preferred_x = goal_x; |
| 22250 |
if (sel) |
| 22251 |
state->select_end = state->cursor; |
| 22252 |
} |
| 22253 |
} break; |
| 22254 |
|
| 22255 |
case NK_KEY_UP: { |
| 22256 |
struct nk_text_find find; |
| 22257 |
struct nk_text_edit_row row; |
| 22258 |
int i, sel = shift_mod; |
| 22259 |
|
| 22260 |
if (state->single_line) { |
| 22261 |
|
| 22262 |
key = NK_KEY_LEFT; |
| 22263 |
goto retry; |
| 22264 |
} |
| 22265 |
|
| 22266 |
if (sel) |
| 22267 |
nk_textedit_prep_selection_at_cursor(state); |
| 22268 |
else if (NK_TEXT_HAS_SELECTION(state)) |
| 22269 |
nk_textedit_move_to_first(state); |
| 22270 |
|
| 22271 |
|
| 22272 |
nk_textedit_clamp(state); |
| 22273 |
nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, |
| 22274 |
font, row_height); |
| 22275 |
|
| 22276 |
|
| 22277 |
if (find.prev_first != find.first_char) { |
| 22278 |
|
| 22279 |
float x; |
| 22280 |
float goal_x = state->has_preferred_x ? state->preferred_x : find.x; |
| 22281 |
|
| 22282 |
state->cursor = find.prev_first; |
| 22283 |
nk_textedit_layout_row(&row, state, state->cursor, row_height, font); |
| 22284 |
x = row.x0; |
| 22285 |
|
| 22286 |
for (i=0; i < row.num_chars && x < row.x1; ++i) { |
| 22287 |
float dx = nk_textedit_get_width(state, find.prev_first, i, font); |
| 22288 |
x += dx; |
| 22289 |
if (x > goal_x) |
| 22290 |
break; |
| 22291 |
++state->cursor; |
| 22292 |
} |
| 22293 |
nk_textedit_clamp(state); |
| 22294 |
|
| 22295 |
state->has_preferred_x = 1; |
| 22296 |
state->preferred_x = goal_x; |
| 22297 |
if (sel) state->select_end = state->cursor; |
| 22298 |
} |
| 22299 |
} break; |
| 22300 |
|
| 22301 |
case NK_KEY_DEL: |
| 22302 |
if (state->mode == NK_TEXT_EDIT_MODE_VIEW) |
| 22303 |
break; |
| 22304 |
if (NK_TEXT_HAS_SELECTION(state)) |
| 22305 |
nk_textedit_delete_selection(state); |
| 22306 |
else { |
| 22307 |
int n = state->string.len; |
| 22308 |
if (state->cursor < n) |
| 22309 |
nk_textedit_delete(state, state->cursor, 1); |
| 22310 |
} |
| 22311 |
state->has_preferred_x = 0; |
| 22312 |
break; |
| 22313 |
|
| 22314 |
case NK_KEY_BACKSPACE: |
| 22315 |
if (state->mode == NK_TEXT_EDIT_MODE_VIEW) |
| 22316 |
break; |
| 22317 |
if (NK_TEXT_HAS_SELECTION(state)) |
| 22318 |
nk_textedit_delete_selection(state); |
| 22319 |
else { |
| 22320 |
nk_textedit_clamp(state); |
| 22321 |
if (state->cursor > 0) { |
| 22322 |
nk_textedit_delete(state, state->cursor-1, 1); |
| 22323 |
--state->cursor; |
| 22324 |
} |
| 22325 |
} |
| 22326 |
state->has_preferred_x = 0; |
| 22327 |
break; |
| 22328 |
|
| 22329 |
case NK_KEY_TEXT_START: |
| 22330 |
if (shift_mod) { |
| 22331 |
nk_textedit_prep_selection_at_cursor(state); |
| 22332 |
state->cursor = state->select_end = 0; |
| 22333 |
state->has_preferred_x = 0; |
| 22334 |
} else { |
| 22335 |
state->cursor = state->select_start = state->select_end = 0; |
| 22336 |
state->has_preferred_x = 0; |
| 22337 |
} |
| 22338 |
break; |
| 22339 |
|
| 22340 |
case NK_KEY_TEXT_END: |
| 22341 |
if (shift_mod) { |
| 22342 |
nk_textedit_prep_selection_at_cursor(state); |
| 22343 |
state->cursor = state->select_end = state->string.len; |
| 22344 |
state->has_preferred_x = 0; |
| 22345 |
} else { |
| 22346 |
state->cursor = state->string.len; |
| 22347 |
state->select_start = state->select_end = 0; |
| 22348 |
state->has_preferred_x = 0; |
| 22349 |
} |
| 22350 |
break; |
| 22351 |
|
| 22352 |
case NK_KEY_TEXT_LINE_START: { |
| 22353 |
if (shift_mod) { |
| 22354 |
struct nk_text_find find; |
| 22355 |
nk_textedit_clamp(state); |
| 22356 |
nk_textedit_prep_selection_at_cursor(state); |
| 22357 |
if (state->string.len && state->cursor == state->string.len) |
| 22358 |
--state->cursor; |
| 22359 |
nk_textedit_find_charpos(&find, state,state->cursor, state->single_line, |
| 22360 |
font, row_height); |
| 22361 |
state->cursor = state->select_end = find.first_char; |
| 22362 |
state->has_preferred_x = 0; |
| 22363 |
} else { |
| 22364 |
struct nk_text_find find; |
| 22365 |
if (state->string.len && state->cursor == state->string.len) |
| 22366 |
--state->cursor; |
| 22367 |
nk_textedit_clamp(state); |
| 22368 |
nk_textedit_move_to_first(state); |
| 22369 |
nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, |
| 22370 |
font, row_height); |
| 22371 |
state->cursor = find.first_char; |
| 22372 |
state->has_preferred_x = 0; |
| 22373 |
} |
| 22374 |
} break; |
| 22375 |
|
| 22376 |
case NK_KEY_TEXT_LINE_END: { |
| 22377 |
if (shift_mod) { |
| 22378 |
struct nk_text_find find; |
| 22379 |
nk_textedit_clamp(state); |
| 22380 |
nk_textedit_prep_selection_at_cursor(state); |
| 22381 |
nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, |
| 22382 |
font, row_height); |
| 22383 |
state->has_preferred_x = 0; |
| 22384 |
state->cursor = find.first_char + find.length; |
| 22385 |
if (find.length > 0 && nk_str_rune_at(&state->string, state->cursor-1) == '\n') |
| 22386 |
--state->cursor; |
| 22387 |
state->select_end = state->cursor; |
| 22388 |
} else { |
| 22389 |
struct nk_text_find find; |
| 22390 |
nk_textedit_clamp(state); |
| 22391 |
nk_textedit_move_to_first(state); |
| 22392 |
nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, |
| 22393 |
font, row_height); |
| 22394 |
|
| 22395 |
state->has_preferred_x = 0; |
| 22396 |
state->cursor = find.first_char + find.length; |
| 22397 |
if (find.length > 0 && nk_str_rune_at(&state->string, state->cursor-1) == '\n') |
| 22398 |
--state->cursor; |
| 22399 |
}} break; |
| 22400 |
} |
| 22401 |
} |
| 22402 |
NK_INTERN void |
| 22403 |
nk_textedit_flush_redo(struct nk_text_undo_state *state) |
| 22404 |
{ |
| 22405 |
state->redo_point = NK_TEXTEDIT_UNDOSTATECOUNT; |
| 22406 |
state->redo_char_point = NK_TEXTEDIT_UNDOCHARCOUNT; |
| 22407 |
} |
| 22408 |
NK_INTERN void |
| 22409 |
nk_textedit_discard_undo(struct nk_text_undo_state *state) |
| 22410 |
{ |
| 22411 |
|
| 22412 |
if (state->undo_point > 0) { |
| 22413 |
|
| 22414 |
if (state->undo_rec[0].char_storage >= 0) { |
| 22415 |
int n = state->undo_rec[0].insert_length, i; |
| 22416 |
|
| 22417 |
state->undo_char_point = (short)(state->undo_char_point - n); |
| 22418 |
NK_MEMCPY(state->undo_char, state->undo_char + n, |
| 22419 |
(nk_size)state->undo_char_point*sizeof(nk_rune)); |
| 22420 |
for (i=0; i < state->undo_point; ++i) { |
| 22421 |
if (state->undo_rec[i].char_storage >= 0) |
| 22422 |
state->undo_rec[i].char_storage = (short) |
| 22423 |
(state->undo_rec[i].char_storage - n); |
| 22424 |
} |
| 22425 |
} |
| 22426 |
--state->undo_point; |
| 22427 |
NK_MEMCPY(state->undo_rec, state->undo_rec+1, |
| 22428 |
(nk_size)((nk_size)state->undo_point * sizeof(state->undo_rec[0]))); |
| 22429 |
} |
| 22430 |
} |
| 22431 |
NK_INTERN void |
| 22432 |
nk_textedit_discard_redo(struct nk_text_undo_state *state) |
| 22433 |
{ |
| 22434 |
|
| 22435 |
|
| 22436 |
|
| 22437 |
|
| 22438 |
nk_size num; |
| 22439 |
int k = NK_TEXTEDIT_UNDOSTATECOUNT-1; |
| 22440 |
if (state->redo_point <= k) { |
| 22441 |
|
| 22442 |
if (state->undo_rec[k].char_storage >= 0) { |
| 22443 |
int n = state->undo_rec[k].insert_length, i; |
| 22444 |
|
| 22445 |
state->redo_char_point = (short)(state->redo_char_point + n); |
| 22446 |
num = (nk_size)(NK_TEXTEDIT_UNDOCHARCOUNT - state->redo_char_point); |
| 22447 |
NK_MEMCPY(state->undo_char + state->redo_char_point, |
| 22448 |
state->undo_char + state->redo_char_point-n, num * sizeof(char)); |
| 22449 |
for (i = state->redo_point; i < k; ++i) { |
| 22450 |
if (state->undo_rec[i].char_storage >= 0) { |
| 22451 |
state->undo_rec[i].char_storage = (short) |
| 22452 |
(state->undo_rec[i].char_storage + n); |
| 22453 |
} |
| 22454 |
} |
| 22455 |
} |
| 22456 |
++state->redo_point; |
| 22457 |
num = (nk_size)(NK_TEXTEDIT_UNDOSTATECOUNT - state->redo_point); |
| 22458 |
if (num) NK_MEMCPY(state->undo_rec + state->redo_point-1, |
| 22459 |
state->undo_rec + state->redo_point, num * sizeof(state->undo_rec[0])); |
| 22460 |
} |
| 22461 |
} |
| 22462 |
NK_INTERN struct nk_text_undo_record* |
| 22463 |
nk_textedit_create_undo_record(struct nk_text_undo_state *state, int numchars) |
| 22464 |
{ |
| 22465 |
|
| 22466 |
nk_textedit_flush_redo(state); |
| 22467 |
|
| 22468 |
|
| 22469 |
|
| 22470 |
if (state->undo_point == NK_TEXTEDIT_UNDOSTATECOUNT) |
| 22471 |
nk_textedit_discard_undo(state); |
| 22472 |
|
| 22473 |
|
| 22474 |
|
| 22475 |
if (numchars > NK_TEXTEDIT_UNDOCHARCOUNT) { |
| 22476 |
state->undo_point = 0; |
| 22477 |
state->undo_char_point = 0; |
| 22478 |
return 0; |
| 22479 |
} |
| 22480 |
|
| 22481 |
|
| 22482 |
|
| 22483 |
while (state->undo_char_point + numchars > NK_TEXTEDIT_UNDOCHARCOUNT) |
| 22484 |
nk_textedit_discard_undo(state); |
| 22485 |
return &state->undo_rec[state->undo_point++]; |
| 22486 |
} |
| 22487 |
NK_INTERN nk_rune* |
| 22488 |
nk_textedit_createundo(struct nk_text_undo_state *state, int pos, |
| 22489 |
int insert_len, int delete_len) |
| 22490 |
{ |
| 22491 |
struct nk_text_undo_record *r = nk_textedit_create_undo_record(state, insert_len); |
| 22492 |
if (r == 0) |
| 22493 |
return 0; |
| 22494 |
|
| 22495 |
r->where = pos; |
| 22496 |
r->insert_length = (short) insert_len; |
| 22497 |
r->delete_length = (short) delete_len; |
| 22498 |
|
| 22499 |
if (insert_len == 0) { |
| 22500 |
r->char_storage = -1; |
| 22501 |
return 0; |
| 22502 |
} else { |
| 22503 |
r->char_storage = state->undo_char_point; |
| 22504 |
state->undo_char_point = (short)(state->undo_char_point + insert_len); |
| 22505 |
return &state->undo_char[r->char_storage]; |
| 22506 |
} |
| 22507 |
} |
| 22508 |
NK_API void |
| 22509 |
nk_textedit_undo(struct nk_text_edit *state) |
| 22510 |
{ |
| 22511 |
struct nk_text_undo_state *s = &state->undo; |
| 22512 |
struct nk_text_undo_record u, *r; |
| 22513 |
if (s->undo_point == 0) |
| 22514 |
return; |
| 22515 |
|
| 22516 |
|
| 22517 |
u = s->undo_rec[s->undo_point-1]; |
| 22518 |
r = &s->undo_rec[s->redo_point-1]; |
| 22519 |
r->char_storage = -1; |
| 22520 |
|
| 22521 |
r->insert_length = u.delete_length; |
| 22522 |
r->delete_length = u.insert_length; |
| 22523 |
r->where = u.where; |
| 22524 |
|
| 22525 |
if (u.delete_length) |
| 22526 |
{ |
| 22527 |
|
| 22528 |
|
| 22529 |
|
| 22530 |
|
| 22531 |
|
| 22532 |
|
| 22533 |
|
| 22534 |
|
| 22535 |
if (s->undo_char_point + u.delete_length >= NK_TEXTEDIT_UNDOCHARCOUNT) { |
| 22536 |
|
| 22537 |
|
| 22538 |
r->insert_length = 0; |
| 22539 |
} else { |
| 22540 |
int i; |
| 22541 |
|
| 22542 |
while (s->undo_char_point + u.delete_length > s->redo_char_point) { |
| 22543 |
|
| 22544 |
nk_textedit_discard_redo(s); |
| 22545 |
|
| 22546 |
if (s->redo_point == NK_TEXTEDIT_UNDOSTATECOUNT) |
| 22547 |
return; |
| 22548 |
} |
| 22549 |
|
| 22550 |
r = &s->undo_rec[s->redo_point-1]; |
| 22551 |
r->char_storage = (short)(s->redo_char_point - u.delete_length); |
| 22552 |
s->redo_char_point = (short)(s->redo_char_point - u.delete_length); |
| 22553 |
|
| 22554 |
|
| 22555 |
for (i=0; i < u.delete_length; ++i) |
| 22556 |
s->undo_char[r->char_storage + i] = |
| 22557 |
nk_str_rune_at(&state->string, u.where + i); |
| 22558 |
} |
| 22559 |
|
| 22560 |
nk_str_delete_runes(&state->string, u.where, u.delete_length); |
| 22561 |
} |
| 22562 |
|
| 22563 |
|
| 22564 |
if (u.insert_length) { |
| 22565 |
|
| 22566 |
nk_str_insert_text_runes(&state->string, u.where, |
| 22567 |
&s->undo_char[u.char_storage], u.insert_length); |
| 22568 |
s->undo_char_point = (short)(s->undo_char_point - u.insert_length); |
| 22569 |
} |
| 22570 |
state->cursor = (short)(u.where + u.insert_length); |
| 22571 |
|
| 22572 |
s->undo_point--; |
| 22573 |
s->redo_point--; |
| 22574 |
} |
| 22575 |
NK_API void |
| 22576 |
nk_textedit_redo(struct nk_text_edit *state) |
| 22577 |
{ |
| 22578 |
struct nk_text_undo_state *s = &state->undo; |
| 22579 |
struct nk_text_undo_record *u, r; |
| 22580 |
if (s->redo_point == NK_TEXTEDIT_UNDOSTATECOUNT) |
| 22581 |
return; |
| 22582 |
|
| 22583 |
|
| 22584 |
u = &s->undo_rec[s->undo_point]; |
| 22585 |
r = s->undo_rec[s->redo_point]; |
| 22586 |
|
| 22587 |
|
| 22588 |
|
| 22589 |
u->delete_length = r.insert_length; |
| 22590 |
u->insert_length = r.delete_length; |
| 22591 |
u->where = r.where; |
| 22592 |
u->char_storage = -1; |
| 22593 |
|
| 22594 |
if (r.delete_length) { |
| 22595 |
|
| 22596 |
|
| 22597 |
if (s->undo_char_point + u->insert_length > s->redo_char_point) { |
| 22598 |
u->insert_length = 0; |
| 22599 |
u->delete_length = 0; |
| 22600 |
} else { |
| 22601 |
int i; |
| 22602 |
u->char_storage = s->undo_char_point; |
| 22603 |
s->undo_char_point = (short)(s->undo_char_point + u->insert_length); |
| 22604 |
|
| 22605 |
|
| 22606 |
for (i=0; i < u->insert_length; ++i) { |
| 22607 |
s->undo_char[u->char_storage + i] = |
| 22608 |
nk_str_rune_at(&state->string, u->where + i); |
| 22609 |
} |
| 22610 |
} |
| 22611 |
nk_str_delete_runes(&state->string, r.where, r.delete_length); |
| 22612 |
} |
| 22613 |
|
| 22614 |
if (r.insert_length) { |
| 22615 |
|
| 22616 |
nk_str_insert_text_runes(&state->string, r.where, |
| 22617 |
&s->undo_char[r.char_storage], r.insert_length); |
| 22618 |
} |
| 22619 |
state->cursor = r.where + r.insert_length; |
| 22620 |
|
| 22621 |
s->undo_point++; |
| 22622 |
s->redo_point++; |
| 22623 |
} |
| 22624 |
NK_INTERN void |
| 22625 |
nk_textedit_makeundo_insert(struct nk_text_edit *state, int where, int length) |
| 22626 |
{ |
| 22627 |
nk_textedit_createundo(&state->undo, where, 0, length); |
| 22628 |
} |
| 22629 |
NK_INTERN void |
| 22630 |
nk_textedit_makeundo_delete(struct nk_text_edit *state, int where, int length) |
| 22631 |
{ |
| 22632 |
int i; |
| 22633 |
nk_rune *p = nk_textedit_createundo(&state->undo, where, length, 0); |
| 22634 |
if (p) { |
| 22635 |
for (i=0; i < length; ++i) |
| 22636 |
p[i] = nk_str_rune_at(&state->string, where+i); |
| 22637 |
} |
| 22638 |
} |
| 22639 |
NK_INTERN void |
| 22640 |
nk_textedit_makeundo_replace(struct nk_text_edit *state, int where, |
| 22641 |
int old_length, int new_length) |
| 22642 |
{ |
| 22643 |
int i; |
| 22644 |
nk_rune *p = nk_textedit_createundo(&state->undo, where, old_length, new_length); |
| 22645 |
if (p) { |
| 22646 |
for (i=0; i < old_length; ++i) |
| 22647 |
p[i] = nk_str_rune_at(&state->string, where+i); |
| 22648 |
} |
| 22649 |
} |
| 22650 |
NK_LIB void |
| 22651 |
nk_textedit_clear_state(struct nk_text_edit *state, enum nk_text_edit_type type, |
| 22652 |
nk_plugin_filter filter) |
| 22653 |
{ |
| 22654 |
|
| 22655 |
state->undo.undo_point = 0; |
| 22656 |
state->undo.undo_char_point = 0; |
| 22657 |
state->undo.redo_point = NK_TEXTEDIT_UNDOSTATECOUNT; |
| 22658 |
state->undo.redo_char_point = NK_TEXTEDIT_UNDOCHARCOUNT; |
| 22659 |
state->select_end = state->select_start = 0; |
| 22660 |
state->cursor = 0; |
| 22661 |
state->has_preferred_x = 0; |
| 22662 |
state->preferred_x = 0; |
| 22663 |
state->cursor_at_end_of_line = 0; |
| 22664 |
state->initialized = 1; |
| 22665 |
state->single_line = (unsigned char)(type == NK_TEXT_EDIT_SINGLE_LINE); |
| 22666 |
state->mode = NK_TEXT_EDIT_MODE_VIEW; |
| 22667 |
state->filter = filter; |
| 22668 |
state->scrollbar = nk_vec2(0,0); |
| 22669 |
} |
| 22670 |
NK_API void |
| 22671 |
nk_textedit_init_fixed(struct nk_text_edit *state, void *memory, nk_size size) |
| 22672 |
{ |
| 22673 |
NK_ASSERT(state); |
| 22674 |
NK_ASSERT(memory); |
| 22675 |
if (!state || !memory || !size) return; |
| 22676 |
NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); |
| 22677 |
nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); |
| 22678 |
nk_str_init_fixed(&state->string, memory, size); |
| 22679 |
} |
| 22680 |
NK_API void |
| 22681 |
nk_textedit_init(struct nk_text_edit *state, struct nk_allocator *alloc, nk_size size) |
| 22682 |
{ |
| 22683 |
NK_ASSERT(state); |
| 22684 |
NK_ASSERT(alloc); |
| 22685 |
if (!state || !alloc) return; |
| 22686 |
NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); |
| 22687 |
nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); |
| 22688 |
nk_str_init(&state->string, alloc, size); |
| 22689 |
} |
| 22690 |
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
| 22691 |
NK_API void |
| 22692 |
nk_textedit_init_default(struct nk_text_edit *state) |
| 22693 |
{ |
| 22694 |
NK_ASSERT(state); |
| 22695 |
if (!state) return; |
| 22696 |
NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); |
| 22697 |
nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); |
| 22698 |
nk_str_init_default(&state->string); |
| 22699 |
} |
| 22700 |
#endif |
| 22701 |
NK_API void |
| 22702 |
nk_textedit_select_all(struct nk_text_edit *state) |
| 22703 |
{ |
| 22704 |
NK_ASSERT(state); |
| 22705 |
state->select_start = 0; |
| 22706 |
state->select_end = state->string.len; |
| 22707 |
} |
| 22708 |
NK_API void |
| 22709 |
nk_textedit_free(struct nk_text_edit *state) |
| 22710 |
{ |
| 22711 |
NK_ASSERT(state); |
| 22712 |
if (!state) return; |
| 22713 |
nk_str_free(&state->string); |
| 22714 |
} |
| 22715 |
|
| 22716 |
|
| 22717 |
|
| 22718 |
|
| 22719 |
|
| 22720 |
|
| 22721 |
|
| 22722 |
|
| 22723 |
|
| 22724 |
|
| 22725 |
NK_API int |
| 22726 |
nk_filter_default(const struct nk_text_edit *box, nk_rune unicode) |
| 22727 |
{ |
| 22728 |
NK_UNUSED(unicode); |
| 22729 |
NK_UNUSED(box); |
| 22730 |
return nk_true; |
| 22731 |
} |
| 22732 |
NK_API int |
| 22733 |
nk_filter_ascii(const struct nk_text_edit *box, nk_rune unicode) |
| 22734 |
{ |
| 22735 |
NK_UNUSED(box); |
| 22736 |
if (unicode > 128) return nk_false; |
| 22737 |
else return nk_true; |
| 22738 |
} |
| 22739 |
NK_API int |
| 22740 |
nk_filter_float(const struct nk_text_edit *box, nk_rune unicode) |
| 22741 |
{ |
| 22742 |
NK_UNUSED(box); |
| 22743 |
if ((unicode < '0' || unicode > '9') && unicode != '.' && unicode != '-') |
| 22744 |
return nk_false; |
| 22745 |
else return nk_true; |
| 22746 |
} |
| 22747 |
NK_API int |
| 22748 |
nk_filter_decimal(const struct nk_text_edit *box, nk_rune unicode) |
| 22749 |
{ |
| 22750 |
NK_UNUSED(box); |
| 22751 |
if ((unicode < '0' || unicode > '9') && unicode != '-') |
| 22752 |
return nk_false; |
| 22753 |
else return nk_true; |
| 22754 |
} |
| 22755 |
NK_API int |
| 22756 |
nk_filter_hex(const struct nk_text_edit *box, nk_rune unicode) |
| 22757 |
{ |
| 22758 |
NK_UNUSED(box); |
| 22759 |
if ((unicode < '0' || unicode > '9') && |
| 22760 |
(unicode < 'a' || unicode > 'f') && |
| 22761 |
(unicode < 'A' || unicode > 'F')) |
| 22762 |
return nk_false; |
| 22763 |
else return nk_true; |
| 22764 |
} |
| 22765 |
NK_API int |
| 22766 |
nk_filter_oct(const struct nk_text_edit *box, nk_rune unicode) |
| 22767 |
{ |
| 22768 |
NK_UNUSED(box); |
| 22769 |
if (unicode < '0' || unicode > '7') |
| 22770 |
return nk_false; |
| 22771 |
else return nk_true; |
| 22772 |
} |
| 22773 |
NK_API int |
| 22774 |
nk_filter_binary(const struct nk_text_edit *box, nk_rune unicode) |
| 22775 |
{ |
| 22776 |
NK_UNUSED(box); |
| 22777 |
if (unicode != '0' && unicode != '1') |
| 22778 |
return nk_false; |
| 22779 |
else return nk_true; |
| 22780 |
} |
| 22781 |
|
| 22782 |
|
| 22783 |
|
| 22784 |
|
| 22785 |
|
| 22786 |
|
| 22787 |
NK_LIB void |
| 22788 |
nk_edit_draw_text(struct nk_command_buffer *out, |
| 22789 |
const struct nk_style_edit *style, float pos_x, float pos_y, |
| 22790 |
float x_offset, const char *text, int byte_len, float row_height, |
| 22791 |
const struct nk_user_font *font, struct nk_color background, |
| 22792 |
struct nk_color foreground, int is_selected) |
| 22793 |
{ |
| 22794 |
NK_ASSERT(out); |
| 22795 |
NK_ASSERT(font); |
| 22796 |
NK_ASSERT(style); |
| 22797 |
if (!text || !byte_len || !out || !style) return; |
| 22798 |
|
| 22799 |
{int glyph_len = 0; |
| 22800 |
nk_rune unicode = 0; |
| 22801 |
int text_len = 0; |
| 22802 |
float line_width = 0; |
| 22803 |
float glyph_width; |
| 22804 |
const char *line = text; |
| 22805 |
float line_offset = 0; |
| 22806 |
int line_count = 0; |
| 22807 |
|
| 22808 |
struct nk_text txt; |
| 22809 |
txt.padding = nk_vec2(0,0); |
| 22810 |
txt.background = background; |
| 22811 |
txt.text = foreground; |
| 22812 |
|
| 22813 |
glyph_len = nk_utf_decode(text+text_len, &unicode, byte_len-text_len); |
| 22814 |
if (!glyph_len) return; |
| 22815 |
while ((text_len < byte_len) && glyph_len) |
| 22816 |
{ |
| 22817 |
if (unicode == '\n') { |
| 22818 |
|
| 22819 |
struct nk_rect label; |
| 22820 |
label.y = pos_y + line_offset; |
| 22821 |
label.h = row_height; |
| 22822 |
label.w = line_width; |
| 22823 |
label.x = pos_x; |
| 22824 |
if (!line_count) |
| 22825 |
label.x += x_offset; |
| 22826 |
|
| 22827 |
if (is_selected) |
| 22828 |
nk_fill_rect(out, label, 0, background); |
| 22829 |
nk_widget_text(out, label, line, (int)((text + text_len) - line), |
| 22830 |
&txt, NK_TEXT_CENTERED, font); |
| 22831 |
|
| 22832 |
text_len++; |
| 22833 |
line_count++; |
| 22834 |
line_width = 0; |
| 22835 |
line = text + text_len; |
| 22836 |
line_offset += row_height; |
| 22837 |
glyph_len = nk_utf_decode(text + text_len, &unicode, (int)(byte_len-text_len)); |
| 22838 |
continue; |
| 22839 |
} |
| 22840 |
if (unicode == '\r') { |
| 22841 |
text_len++; |
| 22842 |
glyph_len = nk_utf_decode(text + text_len, &unicode, byte_len-text_len); |
| 22843 |
continue; |
| 22844 |
} |
| 22845 |
glyph_width = font->width(font->userdata, font->height, text+text_len, glyph_len); |
| 22846 |
line_width += (float)glyph_width; |
| 22847 |
text_len += glyph_len; |
| 22848 |
glyph_len = nk_utf_decode(text + text_len, &unicode, byte_len-text_len); |
| 22849 |
continue; |
| 22850 |
} |
| 22851 |
if (line_width > 0) { |
| 22852 |
|
| 22853 |
struct nk_rect label; |
| 22854 |
label.y = pos_y + line_offset; |
| 22855 |
label.h = row_height; |
| 22856 |
label.w = line_width; |
| 22857 |
label.x = pos_x; |
| 22858 |
if (!line_count) |
| 22859 |
label.x += x_offset; |
| 22860 |
|
| 22861 |
if (is_selected) |
| 22862 |
nk_fill_rect(out, label, 0, background); |
| 22863 |
nk_widget_text(out, label, line, (int)((text + text_len) - line), |
| 22864 |
&txt, NK_TEXT_LEFT, font); |
| 22865 |
}} |
| 22866 |
} |
| 22867 |
NK_LIB nk_flags |
| 22868 |
nk_do_edit(nk_flags *state, struct nk_command_buffer *out, |
| 22869 |
struct nk_rect bounds, nk_flags flags, nk_plugin_filter filter, |
| 22870 |
struct nk_text_edit *edit, const struct nk_style_edit *style, |
| 22871 |
struct nk_input *in, const struct nk_user_font *font) |
| 22872 |
{ |
| 22873 |
struct nk_rect area; |
| 22874 |
nk_flags ret = 0; |
| 22875 |
float row_height; |
| 22876 |
char prev_state = 0; |
| 22877 |
char is_hovered = 0; |
| 22878 |
char select_all = 0; |
| 22879 |
char cursor_follow = 0; |
| 22880 |
struct nk_rect old_clip; |
| 22881 |
struct nk_rect clip; |
| 22882 |
|
| 22883 |
NK_ASSERT(state); |
| 22884 |
NK_ASSERT(out); |
| 22885 |
NK_ASSERT(style); |
| 22886 |
if (!state || !out || !style) |
| 22887 |
return ret; |
| 22888 |
|
| 22889 |
|
| 22890 |
area.x = bounds.x + style->padding.x + style->border; |
| 22891 |
area.y = bounds.y + style->padding.y + style->border; |
| 22892 |
area.w = bounds.w - (2.0f * style->padding.x + 2 * style->border); |
| 22893 |
area.h = bounds.h - (2.0f * style->padding.y + 2 * style->border); |
| 22894 |
if (flags & NK_EDIT_MULTILINE) |
| 22895 |
area.w = NK_MAX(0, area.w - style->scrollbar_size.x); |
| 22896 |
row_height = (flags & NK_EDIT_MULTILINE)? font->height + style->row_padding: area.h; |
| 22897 |
|
| 22898 |
|
| 22899 |
old_clip = out->clip; |
| 22900 |
nk_unify(&clip, &old_clip, area.x, area.y, area.x + area.w, area.y + area.h); |
| 22901 |
|
| 22902 |
|
| 22903 |
prev_state = (char)edit->active; |
| 22904 |
is_hovered = (char)nk_input_is_mouse_hovering_rect(in, bounds); |
| 22905 |
if (in && in->mouse.buttons[NK_BUTTON_LEFT].clicked && in->mouse.buttons[NK_BUTTON_LEFT].down) { |
| 22906 |
edit->active = NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, |
| 22907 |
bounds.x, bounds.y, bounds.w, bounds.h); |
| 22908 |
} |
| 22909 |
|
| 22910 |
|
| 22911 |
if (!prev_state && edit->active) { |
| 22912 |
const enum nk_text_edit_type type = (flags & NK_EDIT_MULTILINE) ? |
| 22913 |
NK_TEXT_EDIT_MULTI_LINE: NK_TEXT_EDIT_SINGLE_LINE; |
| 22914 |
nk_textedit_clear_state(edit, type, filter); |
| 22915 |
if (flags & NK_EDIT_AUTO_SELECT) |
| 22916 |
select_all = nk_true; |
| 22917 |
if (flags & NK_EDIT_GOTO_END_ON_ACTIVATE) { |
| 22918 |
edit->cursor = edit->string.len; |
| 22919 |
in = 0; |
| 22920 |
} |
| 22921 |
} else if (!edit->active) edit->mode = NK_TEXT_EDIT_MODE_VIEW; |
| 22922 |
if (flags & NK_EDIT_READ_ONLY) |
| 22923 |
edit->mode = NK_TEXT_EDIT_MODE_VIEW; |
| 22924 |
else if (flags & NK_EDIT_ALWAYS_INSERT_MODE) |
| 22925 |
edit->mode = NK_TEXT_EDIT_MODE_INSERT; |
| 22926 |
|
| 22927 |
ret = (edit->active) ? NK_EDIT_ACTIVE: NK_EDIT_INACTIVE; |
| 22928 |
if (prev_state != edit->active) |
| 22929 |
ret |= (edit->active) ? NK_EDIT_ACTIVATED: NK_EDIT_DEACTIVATED; |
| 22930 |
|
| 22931 |
|
| 22932 |
if (edit->active && in) |
| 22933 |
{ |
| 22934 |
int shift_mod = in->keyboard.keys[NK_KEY_SHIFT].down; |
| 22935 |
const float mouse_x = (in->mouse.pos.x - area.x) + edit->scrollbar.x; |
| 22936 |
const float mouse_y = (in->mouse.pos.y - area.y) + edit->scrollbar.y; |
| 22937 |
|
| 22938 |
|
| 22939 |
is_hovered = (char)nk_input_is_mouse_hovering_rect(in, area); |
| 22940 |
if (select_all) { |
| 22941 |
nk_textedit_select_all(edit); |
| 22942 |
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_LEFT].down && |
| 22943 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked) { |
| 22944 |
nk_textedit_click(edit, mouse_x, mouse_y, font, row_height); |
| 22945 |
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_LEFT].down && |
| 22946 |
(in->mouse.delta.x != 0.0f || in->mouse.delta.y != 0.0f)) { |
| 22947 |
nk_textedit_drag(edit, mouse_x, mouse_y, font, row_height); |
| 22948 |
cursor_follow = nk_true; |
| 22949 |
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_RIGHT].clicked && |
| 22950 |
in->mouse.buttons[NK_BUTTON_RIGHT].down) { |
| 22951 |
nk_textedit_key(edit, NK_KEY_TEXT_WORD_LEFT, nk_false, font, row_height); |
| 22952 |
nk_textedit_key(edit, NK_KEY_TEXT_WORD_RIGHT, nk_true, font, row_height); |
| 22953 |
cursor_follow = nk_true; |
| 22954 |
} |
| 22955 |
|
| 22956 |
{int i; |
| 22957 |
int old_mode = edit->mode; |
| 22958 |
for (i = 0; i < NK_KEY_MAX; ++i) { |
| 22959 |
if (i == NK_KEY_ENTER || i == NK_KEY_TAB) continue; |
| 22960 |
if (nk_input_is_key_pressed(in, (enum nk_keys)i)) { |
| 22961 |
nk_textedit_key(edit, (enum nk_keys)i, shift_mod, font, row_height); |
| 22962 |
cursor_follow = nk_true; |
| 22963 |
} |
| 22964 |
} |
| 22965 |
if (old_mode != edit->mode) { |
| 22966 |
in->keyboard.text_len = 0; |
| 22967 |
}} |
| 22968 |
|
| 22969 |
|
| 22970 |
edit->filter = filter; |
| 22971 |
if (in->keyboard.text_len) { |
| 22972 |
nk_textedit_text(edit, in->keyboard.text, in->keyboard.text_len); |
| 22973 |
cursor_follow = nk_true; |
| 22974 |
in->keyboard.text_len = 0; |
| 22975 |
} |
| 22976 |
|
| 22977 |
|
| 22978 |
if (nk_input_is_key_pressed(in, NK_KEY_ENTER)) { |
| 22979 |
cursor_follow = nk_true; |
| 22980 |
if (flags & NK_EDIT_CTRL_ENTER_NEWLINE && shift_mod) |
| 22981 |
nk_textedit_text(edit, "\n", 1); |
| 22982 |
else if (flags & NK_EDIT_SIG_ENTER) |
| 22983 |
ret |= NK_EDIT_COMMITED; |
| 22984 |
else nk_textedit_text(edit, "\n", 1); |
| 22985 |
} |
| 22986 |
|
| 22987 |
|
| 22988 |
{int copy= nk_input_is_key_pressed(in, NK_KEY_COPY); |
| 22989 |
int cut = nk_input_is_key_pressed(in, NK_KEY_CUT); |
| 22990 |
if ((copy || cut) && (flags & NK_EDIT_CLIPBOARD)) |
| 22991 |
{ |
| 22992 |
int glyph_len; |
| 22993 |
nk_rune unicode; |
| 22994 |
const char *text; |
| 22995 |
int b = edit->select_start; |
| 22996 |
int e = edit->select_end; |
| 22997 |
|
| 22998 |
int begin = NK_MIN(b, e); |
| 22999 |
int end = NK_MAX(b, e); |
| 23000 |
text = nk_str_at_const(&edit->string, begin, &unicode, &glyph_len); |
| 23001 |
if (edit->clip.copy) |
| 23002 |
edit->clip.copy(edit->clip.userdata, text, end - begin); |
| 23003 |
if (cut && !(flags & NK_EDIT_READ_ONLY)){ |
| 23004 |
nk_textedit_cut(edit); |
| 23005 |
cursor_follow = nk_true; |
| 23006 |
} |
| 23007 |
}} |
| 23008 |
|
| 23009 |
|
| 23010 |
{int paste = nk_input_is_key_pressed(in, NK_KEY_PASTE); |
| 23011 |
if (paste && (flags & NK_EDIT_CLIPBOARD) && edit->clip.paste) { |
| 23012 |
edit->clip.paste(edit->clip.userdata, edit); |
| 23013 |
cursor_follow = nk_true; |
| 23014 |
}} |
| 23015 |
|
| 23016 |
|
| 23017 |
{int tab = nk_input_is_key_pressed(in, NK_KEY_TAB); |
| 23018 |
if (tab && (flags & NK_EDIT_ALLOW_TAB)) { |
| 23019 |
nk_textedit_text(edit, " ", 4); |
| 23020 |
cursor_follow = nk_true; |
| 23021 |
}} |
| 23022 |
} |
| 23023 |
|
| 23024 |
|
| 23025 |
if (edit->active) |
| 23026 |
*state = NK_WIDGET_STATE_ACTIVE; |
| 23027 |
else nk_widget_state_reset(state); |
| 23028 |
|
| 23029 |
if (is_hovered) |
| 23030 |
*state |= NK_WIDGET_STATE_HOVERED; |
| 23031 |
|
| 23032 |
|
| 23033 |
{const char *text = nk_str_get_const(&edit->string); |
| 23034 |
int len = nk_str_len_char(&edit->string); |
| 23035 |
|
| 23036 |
{ |
| 23037 |
const struct nk_style_item *background; |
| 23038 |
if (*state & NK_WIDGET_STATE_ACTIVED) |
| 23039 |
background = &style->active; |
| 23040 |
else if (*state & NK_WIDGET_STATE_HOVER) |
| 23041 |
background = &style->hover; |
| 23042 |
else background = &style->normal; |
| 23043 |
|
| 23044 |
|
| 23045 |
if (background->type == NK_STYLE_ITEM_COLOR) { |
| 23046 |
nk_stroke_rect(out, bounds, style->rounding, style->border, style->border_color); |
| 23047 |
nk_fill_rect(out, bounds, style->rounding, background->data.color); |
| 23048 |
} else nk_draw_image(out, bounds, &background->data.image, nk_white);} |
| 23049 |
|
| 23050 |
area.w = NK_MAX(0, area.w - style->cursor_size); |
| 23051 |
if (edit->active) |
| 23052 |
{ |
| 23053 |
int total_lines = 1; |
| 23054 |
struct nk_vec2 text_size = nk_vec2(0,0); |
| 23055 |
|
| 23056 |
|
| 23057 |
const char *cursor_ptr = 0; |
| 23058 |
const char *select_begin_ptr = 0; |
| 23059 |
const char *select_end_ptr = 0; |
| 23060 |
|
| 23061 |
|
| 23062 |
struct nk_vec2 cursor_pos = nk_vec2(0,0); |
| 23063 |
struct nk_vec2 selection_offset_start = nk_vec2(0,0); |
| 23064 |
struct nk_vec2 selection_offset_end = nk_vec2(0,0); |
| 23065 |
|
| 23066 |
int selection_begin = NK_MIN(edit->select_start, edit->select_end); |
| 23067 |
int selection_end = NK_MAX(edit->select_start, edit->select_end); |
| 23068 |
|
| 23069 |
|
| 23070 |
float line_width = 0.0f; |
| 23071 |
if (text && len) |
| 23072 |
{ |
| 23073 |
|
| 23074 |
float glyph_width; |
| 23075 |
int glyph_len = 0; |
| 23076 |
nk_rune unicode = 0; |
| 23077 |
int text_len = 0; |
| 23078 |
int glyphs = 0; |
| 23079 |
int row_begin = 0; |
| 23080 |
|
| 23081 |
glyph_len = nk_utf_decode(text, &unicode, len); |
| 23082 |
glyph_width = font->width(font->userdata, font->height, text, glyph_len); |
| 23083 |
line_width = 0; |
| 23084 |
|
| 23085 |
|
| 23086 |
while ((text_len < len) && glyph_len) |
| 23087 |
{ |
| 23088 |
|
| 23089 |
if (!cursor_ptr && glyphs == edit->cursor) |
| 23090 |
{ |
| 23091 |
int glyph_offset; |
| 23092 |
struct nk_vec2 out_offset; |
| 23093 |
struct nk_vec2 row_size; |
| 23094 |
const char *remaining; |
| 23095 |
|
| 23096 |
|
| 23097 |
cursor_pos.y = (float)(total_lines-1) * row_height; |
| 23098 |
row_size = nk_text_calculate_text_bounds(font, text+row_begin, |
| 23099 |
text_len-row_begin, row_height, &remaining, |
| 23100 |
&out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE); |
| 23101 |
cursor_pos.x = row_size.x; |
| 23102 |
cursor_ptr = text + text_len; |
| 23103 |
} |
| 23104 |
|
| 23105 |
|
| 23106 |
if (!select_begin_ptr && edit->select_start != edit->select_end && |
| 23107 |
glyphs == selection_begin) |
| 23108 |
{ |
| 23109 |
int glyph_offset; |
| 23110 |
struct nk_vec2 out_offset; |
| 23111 |
struct nk_vec2 row_size; |
| 23112 |
const char *remaining; |
| 23113 |
|
| 23114 |
|
| 23115 |
selection_offset_start.y = (float)(NK_MAX(total_lines-1,0)) * row_height; |
| 23116 |
row_size = nk_text_calculate_text_bounds(font, text+row_begin, |
| 23117 |
text_len-row_begin, row_height, &remaining, |
| 23118 |
&out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE); |
| 23119 |
selection_offset_start.x = row_size.x; |
| 23120 |
select_begin_ptr = text + text_len; |
| 23121 |
} |
| 23122 |
|
| 23123 |
|
| 23124 |
if (!select_end_ptr && edit->select_start != edit->select_end && |
| 23125 |
glyphs == selection_end) |
| 23126 |
{ |
| 23127 |
int glyph_offset; |
| 23128 |
struct nk_vec2 out_offset; |
| 23129 |
struct nk_vec2 row_size; |
| 23130 |
const char *remaining; |
| 23131 |
|
| 23132 |
|
| 23133 |
selection_offset_end.y = (float)(total_lines-1) * row_height; |
| 23134 |
row_size = nk_text_calculate_text_bounds(font, text+row_begin, |
| 23135 |
text_len-row_begin, row_height, &remaining, |
| 23136 |
&out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE); |
| 23137 |
selection_offset_end.x = row_size.x; |
| 23138 |
select_end_ptr = text + text_len; |
| 23139 |
} |
| 23140 |
if (unicode == '\n') { |
| 23141 |
text_size.x = NK_MAX(text_size.x, line_width); |
| 23142 |
total_lines++; |
| 23143 |
line_width = 0; |
| 23144 |
text_len++; |
| 23145 |
glyphs++; |
| 23146 |
row_begin = text_len; |
| 23147 |
glyph_len = nk_utf_decode(text + text_len, &unicode, len-text_len); |
| 23148 |
glyph_width = font->width(font->userdata, font->height, text+text_len, glyph_len); |
| 23149 |
continue; |
| 23150 |
} |
| 23151 |
|
| 23152 |
glyphs++; |
| 23153 |
text_len += glyph_len; |
| 23154 |
line_width += (float)glyph_width; |
| 23155 |
|
| 23156 |
glyph_len = nk_utf_decode(text + text_len, &unicode, len-text_len); |
| 23157 |
glyph_width = font->width(font->userdata, font->height, |
| 23158 |
text+text_len, glyph_len); |
| 23159 |
continue; |
| 23160 |
} |
| 23161 |
text_size.y = (float)total_lines * row_height; |
| 23162 |
|
| 23163 |
|
| 23164 |
if (!cursor_ptr && edit->cursor == edit->string.len) { |
| 23165 |
cursor_pos.x = line_width; |
| 23166 |
cursor_pos.y = text_size.y - row_height; |
| 23167 |
} |
| 23168 |
} |
| 23169 |
{ |
| 23170 |
|
| 23171 |
if (cursor_follow) |
| 23172 |
{ |
| 23173 |
|
| 23174 |
if (!(flags & NK_EDIT_NO_HORIZONTAL_SCROLL)) { |
| 23175 |
|
| 23176 |
const float scroll_increment = area.w * 0.25f; |
| 23177 |
if (cursor_pos.x < edit->scrollbar.x) |
| 23178 |
edit->scrollbar.x = (float)(int)NK_MAX(0.0f, cursor_pos.x - scroll_increment); |
| 23179 |
if (cursor_pos.x >= edit->scrollbar.x + area.w) |
| 23180 |
edit->scrollbar.x = (float)(int)NK_MAX(0.0f, cursor_pos.x - area.w + scroll_increment); |
| 23181 |
} else edit->scrollbar.x = 0; |
| 23182 |
|
| 23183 |
if (flags & NK_EDIT_MULTILINE) { |
| 23184 |
|
| 23185 |
if (cursor_pos.y < edit->scrollbar.y) |
| 23186 |
edit->scrollbar.y = NK_MAX(0.0f, cursor_pos.y - row_height); |
| 23187 |
if (cursor_pos.y >= edit->scrollbar.y + area.h) |
| 23188 |
edit->scrollbar.y = edit->scrollbar.y + row_height; |
| 23189 |
} else edit->scrollbar.y = 0; |
| 23190 |
} |
| 23191 |
|
| 23192 |
|
| 23193 |
if (flags & NK_EDIT_MULTILINE) |
| 23194 |
{ |
| 23195 |
nk_flags ws; |
| 23196 |
struct nk_rect scroll; |
| 23197 |
float scroll_target; |
| 23198 |
float scroll_offset; |
| 23199 |
float scroll_step; |
| 23200 |
float scroll_inc; |
| 23201 |
|
| 23202 |
scroll = area; |
| 23203 |
scroll.x = (bounds.x + bounds.w - style->border) - style->scrollbar_size.x; |
| 23204 |
scroll.w = style->scrollbar_size.x; |
| 23205 |
|
| 23206 |
scroll_offset = edit->scrollbar.y; |
| 23207 |
scroll_step = scroll.h * 0.10f; |
| 23208 |
scroll_inc = scroll.h * 0.01f; |
| 23209 |
scroll_target = text_size.y; |
| 23210 |
edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, 0, |
| 23211 |
scroll_offset, scroll_target, scroll_step, scroll_inc, |
| 23212 |
&style->scrollbar, in, font); |
| 23213 |
} |
| 23214 |
} |
| 23215 |
|
| 23216 |
|
| 23217 |
{struct nk_color background_color; |
| 23218 |
struct nk_color text_color; |
| 23219 |
struct nk_color sel_background_color; |
| 23220 |
struct nk_color sel_text_color; |
| 23221 |
struct nk_color cursor_color; |
| 23222 |
struct nk_color cursor_text_color; |
| 23223 |
const struct nk_style_item *background; |
| 23224 |
nk_push_scissor(out, clip); |
| 23225 |
|
| 23226 |
|
| 23227 |
if (*state & NK_WIDGET_STATE_ACTIVED) { |
| 23228 |
background = &style->active; |
| 23229 |
text_color = style->text_active; |
| 23230 |
sel_text_color = style->selected_text_hover; |
| 23231 |
sel_background_color = style->selected_hover; |
| 23232 |
cursor_color = style->cursor_hover; |
| 23233 |
cursor_text_color = style->cursor_text_hover; |
| 23234 |
} else if (*state & NK_WIDGET_STATE_HOVER) { |
| 23235 |
background = &style->hover; |
| 23236 |
text_color = style->text_hover; |
| 23237 |
sel_text_color = style->selected_text_hover; |
| 23238 |
sel_background_color = style->selected_hover; |
| 23239 |
cursor_text_color = style->cursor_text_hover; |
| 23240 |
cursor_color = style->cursor_hover; |
| 23241 |
} else { |
| 23242 |
background = &style->normal; |
| 23243 |
text_color = style->text_normal; |
| 23244 |
sel_text_color = style->selected_text_normal; |
| 23245 |
sel_background_color = style->selected_normal; |
| 23246 |
cursor_color = style->cursor_normal; |
| 23247 |
cursor_text_color = style->cursor_text_normal; |
| 23248 |
} |
| 23249 |
if (background->type == NK_STYLE_ITEM_IMAGE) |
| 23250 |
background_color = nk_rgba(0,0,0,0); |
| 23251 |
else background_color = background->data.color; |
| 23252 |
|
| 23253 |
|
| 23254 |
if (edit->select_start == edit->select_end) { |
| 23255 |
|
| 23256 |
const char *begin = nk_str_get_const(&edit->string); |
| 23257 |
int l = nk_str_len_char(&edit->string); |
| 23258 |
nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, |
| 23259 |
area.y - edit->scrollbar.y, 0, begin, l, row_height, font, |
| 23260 |
background_color, text_color, nk_false); |
| 23261 |
} else { |
| 23262 |
|
| 23263 |
if (edit->select_start != edit->select_end && selection_begin > 0){ |
| 23264 |
|
| 23265 |
const char *begin = nk_str_get_const(&edit->string); |
| 23266 |
NK_ASSERT(select_begin_ptr); |
| 23267 |
nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, |
| 23268 |
area.y - edit->scrollbar.y, 0, begin, (int)(select_begin_ptr - begin), |
| 23269 |
row_height, font, background_color, text_color, nk_false); |
| 23270 |
} |
| 23271 |
if (edit->select_start != edit->select_end) { |
| 23272 |
|
| 23273 |
NK_ASSERT(select_begin_ptr); |
| 23274 |
if (!select_end_ptr) { |
| 23275 |
const char *begin = nk_str_get_const(&edit->string); |
| 23276 |
select_end_ptr = begin + nk_str_len_char(&edit->string); |
| 23277 |
} |
| 23278 |
nk_edit_draw_text(out, style, |
| 23279 |
area.x - edit->scrollbar.x, |
| 23280 |
area.y + selection_offset_start.y - edit->scrollbar.y, |
| 23281 |
selection_offset_start.x, |
| 23282 |
select_begin_ptr, (int)(select_end_ptr - select_begin_ptr), |
| 23283 |
row_height, font, sel_background_color, sel_text_color, nk_true); |
| 23284 |
} |
| 23285 |
if ((edit->select_start != edit->select_end && |
| 23286 |
selection_end < edit->string.len)) |
| 23287 |
{ |
| 23288 |
|
| 23289 |
const char *begin = select_end_ptr; |
| 23290 |
const char *end = nk_str_get_const(&edit->string) + |
| 23291 |
nk_str_len_char(&edit->string); |
| 23292 |
NK_ASSERT(select_end_ptr); |
| 23293 |
nk_edit_draw_text(out, style, |
| 23294 |
area.x - edit->scrollbar.x, |
| 23295 |
area.y + selection_offset_end.y - edit->scrollbar.y, |
| 23296 |
selection_offset_end.x, |
| 23297 |
begin, (int)(end - begin), row_height, font, |
| 23298 |
background_color, text_color, nk_true); |
| 23299 |
} |
| 23300 |
} |
| 23301 |
|
| 23302 |
|
| 23303 |
if (edit->select_start == edit->select_end) |
| 23304 |
{ |
| 23305 |
if (edit->cursor >= nk_str_len(&edit->string) || |
| 23306 |
(cursor_ptr && *cursor_ptr == '\n')) { |
| 23307 |
|
| 23308 |
struct nk_rect cursor; |
| 23309 |
cursor.w = style->cursor_size; |
| 23310 |
cursor.h = font->height; |
| 23311 |
cursor.x = area.x + cursor_pos.x - edit->scrollbar.x; |
| 23312 |
cursor.y = area.y + cursor_pos.y + row_height/2.0f - cursor.h/2.0f; |
| 23313 |
cursor.y -= edit->scrollbar.y; |
| 23314 |
nk_fill_rect(out, cursor, 0, cursor_color); |
| 23315 |
} else { |
| 23316 |
|
| 23317 |
int glyph_len; |
| 23318 |
struct nk_rect label; |
| 23319 |
struct nk_text txt; |
| 23320 |
|
| 23321 |
nk_rune unicode; |
| 23322 |
NK_ASSERT(cursor_ptr); |
| 23323 |
glyph_len = nk_utf_decode(cursor_ptr, &unicode, 4); |
| 23324 |
|
| 23325 |
label.x = area.x + cursor_pos.x - edit->scrollbar.x; |
| 23326 |
label.y = area.y + cursor_pos.y - edit->scrollbar.y; |
| 23327 |
label.w = font->width(font->userdata, font->height, cursor_ptr, glyph_len); |
| 23328 |
label.h = row_height; |
| 23329 |
|
| 23330 |
txt.padding = nk_vec2(0,0); |
| 23331 |
txt.background = cursor_color;; |
| 23332 |
txt.text = cursor_text_color; |
| 23333 |
nk_fill_rect(out, label, 0, cursor_color); |
| 23334 |
nk_widget_text(out, label, cursor_ptr, glyph_len, &txt, NK_TEXT_LEFT, font); |
| 23335 |
} |
| 23336 |
}} |
| 23337 |
} else { |
| 23338 |
|
| 23339 |
int l = nk_str_len_char(&edit->string); |
| 23340 |
const char *begin = nk_str_get_const(&edit->string); |
| 23341 |
|
| 23342 |
const struct nk_style_item *background; |
| 23343 |
struct nk_color background_color; |
| 23344 |
struct nk_color text_color; |
| 23345 |
nk_push_scissor(out, clip); |
| 23346 |
if (*state & NK_WIDGET_STATE_ACTIVED) { |
| 23347 |
background = &style->active; |
| 23348 |
text_color = style->text_active; |
| 23349 |
} else if (*state & NK_WIDGET_STATE_HOVER) { |
| 23350 |
background = &style->hover; |
| 23351 |
text_color = style->text_hover; |
| 23352 |
} else { |
| 23353 |
background = &style->normal; |
| 23354 |
text_color = style->text_normal; |
| 23355 |
} |
| 23356 |
if (background->type == NK_STYLE_ITEM_IMAGE) |
| 23357 |
background_color = nk_rgba(0,0,0,0); |
| 23358 |
else background_color = background->data.color; |
| 23359 |
nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, |
| 23360 |
area.y - edit->scrollbar.y, 0, begin, l, row_height, font, |
| 23361 |
background_color, text_color, nk_false); |
| 23362 |
} |
| 23363 |
nk_push_scissor(out, old_clip);} |
| 23364 |
return ret; |
| 23365 |
} |
| 23366 |
NK_API void |
| 23367 |
nk_edit_focus(struct nk_context *ctx, nk_flags flags) |
| 23368 |
{ |
| 23369 |
nk_hash hash; |
| 23370 |
struct nk_window *win; |
| 23371 |
|
| 23372 |
NK_ASSERT(ctx); |
| 23373 |
NK_ASSERT(ctx->current); |
| 23374 |
if (!ctx || !ctx->current) return; |
| 23375 |
|
| 23376 |
win = ctx->current; |
| 23377 |
hash = win->edit.seq; |
| 23378 |
win->edit.active = nk_true; |
| 23379 |
win->edit.name = hash; |
| 23380 |
if (flags & NK_EDIT_ALWAYS_INSERT_MODE) |
| 23381 |
win->edit.mode = NK_TEXT_EDIT_MODE_INSERT; |
| 23382 |
} |
| 23383 |
NK_API void |
| 23384 |
nk_edit_unfocus(struct nk_context *ctx) |
| 23385 |
{ |
| 23386 |
struct nk_window *win; |
| 23387 |
NK_ASSERT(ctx); |
| 23388 |
NK_ASSERT(ctx->current); |
| 23389 |
if (!ctx || !ctx->current) return; |
| 23390 |
|
| 23391 |
win = ctx->current; |
| 23392 |
win->edit.active = nk_false; |
| 23393 |
win->edit.name = 0; |
| 23394 |
} |
| 23395 |
NK_API nk_flags |
| 23396 |
nk_edit_string(struct nk_context *ctx, nk_flags flags, |
| 23397 |
char *memory, int *len, int max, nk_plugin_filter filter) |
| 23398 |
{ |
| 23399 |
nk_hash hash; |
| 23400 |
nk_flags state; |
| 23401 |
struct nk_text_edit *edit; |
| 23402 |
struct nk_window *win; |
| 23403 |
|
| 23404 |
NK_ASSERT(ctx); |
| 23405 |
NK_ASSERT(memory); |
| 23406 |
NK_ASSERT(len); |
| 23407 |
if (!ctx || !memory || !len) |
| 23408 |
return 0; |
| 23409 |
|
| 23410 |
filter = (!filter) ? nk_filter_default: filter; |
| 23411 |
win = ctx->current; |
| 23412 |
hash = win->edit.seq; |
| 23413 |
edit = &ctx->text_edit; |
| 23414 |
nk_textedit_clear_state(&ctx->text_edit, (flags & NK_EDIT_MULTILINE)? |
| 23415 |
NK_TEXT_EDIT_MULTI_LINE: NK_TEXT_EDIT_SINGLE_LINE, filter); |
| 23416 |
|
| 23417 |
if (win->edit.active && hash == win->edit.name) { |
| 23418 |
if (flags & NK_EDIT_NO_CURSOR) |
| 23419 |
edit->cursor = nk_utf_len(memory, *len); |
| 23420 |
else edit->cursor = win->edit.cursor; |
| 23421 |
if (!(flags & NK_EDIT_SELECTABLE)) { |
| 23422 |
edit->select_start = win->edit.cursor; |
| 23423 |
edit->select_end = win->edit.cursor; |
| 23424 |
} else { |
| 23425 |
edit->select_start = win->edit.sel_start; |
| 23426 |
edit->select_end = win->edit.sel_end; |
| 23427 |
} |
| 23428 |
edit->mode = win->edit.mode; |
| 23429 |
edit->scrollbar.x = (float)win->edit.scrollbar.x; |
| 23430 |
edit->scrollbar.y = (float)win->edit.scrollbar.y; |
| 23431 |
edit->active = nk_true; |
| 23432 |
} else edit->active = nk_false; |
| 23433 |
|
| 23434 |
max = NK_MAX(1, max); |
| 23435 |
*len = NK_MIN(*len, max-1); |
| 23436 |
nk_str_init_fixed(&edit->string, memory, (nk_size)max); |
| 23437 |
edit->string.buffer.allocated = (nk_size)*len; |
| 23438 |
edit->string.len = nk_utf_len(memory, *len); |
| 23439 |
state = nk_edit_buffer(ctx, flags, edit, filter); |
| 23440 |
*len = (int)edit->string.buffer.allocated; |
| 23441 |
|
| 23442 |
if (edit->active) { |
| 23443 |
win->edit.cursor = edit->cursor; |
| 23444 |
win->edit.sel_start = edit->select_start; |
| 23445 |
win->edit.sel_end = edit->select_end; |
| 23446 |
win->edit.mode = edit->mode; |
| 23447 |
win->edit.scrollbar.x = (nk_uint)edit->scrollbar.x; |
| 23448 |
win->edit.scrollbar.y = (nk_uint)edit->scrollbar.y; |
| 23449 |
} return state; |
| 23450 |
} |
| 23451 |
NK_API nk_flags |
| 23452 |
nk_edit_buffer(struct nk_context *ctx, nk_flags flags, |
| 23453 |
struct nk_text_edit *edit, nk_plugin_filter filter) |
| 23454 |
{ |
| 23455 |
struct nk_window *win; |
| 23456 |
struct nk_style *style; |
| 23457 |
struct nk_input *in; |
| 23458 |
|
| 23459 |
enum nk_widget_layout_states state; |
| 23460 |
struct nk_rect bounds; |
| 23461 |
|
| 23462 |
nk_flags ret_flags = 0; |
| 23463 |
unsigned char prev_state; |
| 23464 |
nk_hash hash; |
| 23465 |
|
| 23466 |
|
| 23467 |
NK_ASSERT(ctx); |
| 23468 |
NK_ASSERT(edit); |
| 23469 |
NK_ASSERT(ctx->current); |
| 23470 |
NK_ASSERT(ctx->current->layout); |
| 23471 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 23472 |
return 0; |
| 23473 |
|
| 23474 |
win = ctx->current; |
| 23475 |
style = &ctx->style; |
| 23476 |
state = nk_widget(&bounds, ctx); |
| 23477 |
if (!state) return state; |
| 23478 |
in = (win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 23479 |
|
| 23480 |
|
| 23481 |
hash = win->edit.seq++; |
| 23482 |
if (win->edit.active && hash == win->edit.name) { |
| 23483 |
if (flags & NK_EDIT_NO_CURSOR) |
| 23484 |
edit->cursor = edit->string.len; |
| 23485 |
if (!(flags & NK_EDIT_SELECTABLE)) { |
| 23486 |
edit->select_start = edit->cursor; |
| 23487 |
edit->select_end = edit->cursor; |
| 23488 |
} |
| 23489 |
if (flags & NK_EDIT_CLIPBOARD) |
| 23490 |
edit->clip = ctx->clip; |
| 23491 |
edit->active = (unsigned char)win->edit.active; |
| 23492 |
} else edit->active = nk_false; |
| 23493 |
edit->mode = win->edit.mode; |
| 23494 |
|
| 23495 |
filter = (!filter) ? nk_filter_default: filter; |
| 23496 |
prev_state = (unsigned char)edit->active; |
| 23497 |
in = (flags & NK_EDIT_READ_ONLY) ? 0: in; |
| 23498 |
ret_flags = nk_do_edit(&ctx->last_widget_state, &win->buffer, bounds, flags, |
| 23499 |
filter, edit, &style->edit, in, style->font); |
| 23500 |
|
| 23501 |
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) |
| 23502 |
ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_TEXT]; |
| 23503 |
if (edit->active && prev_state != edit->active) { |
| 23504 |
|
| 23505 |
win->edit.active = nk_true; |
| 23506 |
win->edit.name = hash; |
| 23507 |
} else if (prev_state && !edit->active) { |
| 23508 |
|
| 23509 |
win->edit.active = nk_false; |
| 23510 |
} return ret_flags; |
| 23511 |
} |
| 23512 |
NK_API nk_flags |
| 23513 |
nk_edit_string_zero_terminated(struct nk_context *ctx, nk_flags flags, |
| 23514 |
char *buffer, int max, nk_plugin_filter filter) |
| 23515 |
{ |
| 23516 |
nk_flags result; |
| 23517 |
int len = nk_strlen(buffer); |
| 23518 |
result = nk_edit_string(ctx, flags, buffer, &len, max, filter); |
| 23519 |
buffer[NK_MIN(NK_MAX(max-1,0), len)] = '\0'; |
| 23520 |
return result; |
| 23521 |
} |
| 23522 |
|
| 23523 |
|
| 23524 |
|
| 23525 |
|
| 23526 |
|
| 23527 |
|
| 23528 |
|
| 23529 |
|
| 23530 |
|
| 23531 |
|
| 23532 |
NK_LIB void |
| 23533 |
nk_drag_behavior(nk_flags *state, const struct nk_input *in, |
| 23534 |
struct nk_rect drag, struct nk_property_variant *variant, |
| 23535 |
float inc_per_pixel) |
| 23536 |
{ |
| 23537 |
int left_mouse_down = in && in->mouse.buttons[NK_BUTTON_LEFT].down; |
| 23538 |
int left_mouse_click_in_cursor = in && |
| 23539 |
nk_input_has_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, drag, nk_true); |
| 23540 |
|
| 23541 |
nk_widget_state_reset(state); |
| 23542 |
if (nk_input_is_mouse_hovering_rect(in, drag)) |
| 23543 |
*state = NK_WIDGET_STATE_HOVERED; |
| 23544 |
|
| 23545 |
if (left_mouse_down && left_mouse_click_in_cursor) { |
| 23546 |
float delta, pixels; |
| 23547 |
pixels = in->mouse.delta.x; |
| 23548 |
delta = pixels * inc_per_pixel; |
| 23549 |
switch (variant->kind) { |
| 23550 |
default: break; |
| 23551 |
case NK_PROPERTY_INT: |
| 23552 |
variant->value.i = variant->value.i + (int)delta; |
| 23553 |
variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i); |
| 23554 |
break; |
| 23555 |
case NK_PROPERTY_FLOAT: |
| 23556 |
variant->value.f = variant->value.f + (float)delta; |
| 23557 |
variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f); |
| 23558 |
break; |
| 23559 |
case NK_PROPERTY_DOUBLE: |
| 23560 |
variant->value.d = variant->value.d + (double)delta; |
| 23561 |
variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d); |
| 23562 |
break; |
| 23563 |
} |
| 23564 |
*state = NK_WIDGET_STATE_ACTIVE; |
| 23565 |
} |
| 23566 |
if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, drag)) |
| 23567 |
*state |= NK_WIDGET_STATE_ENTERED; |
| 23568 |
else if (nk_input_is_mouse_prev_hovering_rect(in, drag)) |
| 23569 |
*state |= NK_WIDGET_STATE_LEFT; |
| 23570 |
} |
| 23571 |
NK_LIB void |
| 23572 |
nk_property_behavior(nk_flags *ws, const struct nk_input *in, |
| 23573 |
struct nk_rect property, struct nk_rect label, struct nk_rect edit, |
| 23574 |
struct nk_rect empty, int *state, struct nk_property_variant *variant, |
| 23575 |
float inc_per_pixel) |
| 23576 |
{ |
| 23577 |
if (in && *state == NK_PROPERTY_DEFAULT) { |
| 23578 |
if (nk_button_behavior(ws, edit, in, NK_BUTTON_DEFAULT)) |
| 23579 |
*state = NK_PROPERTY_EDIT; |
| 23580 |
else if (nk_input_is_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, label, nk_true)) |
| 23581 |
*state = NK_PROPERTY_DRAG; |
| 23582 |
else if (nk_input_is_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, empty, nk_true)) |
| 23583 |
*state = NK_PROPERTY_DRAG; |
| 23584 |
} |
| 23585 |
if (*state == NK_PROPERTY_DRAG) { |
| 23586 |
nk_drag_behavior(ws, in, property, variant, inc_per_pixel); |
| 23587 |
if (!(*ws & NK_WIDGET_STATE_ACTIVED)) *state = NK_PROPERTY_DEFAULT; |
| 23588 |
} |
| 23589 |
} |
| 23590 |
NK_LIB void |
| 23591 |
nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property *style, |
| 23592 |
const struct nk_rect *bounds, const struct nk_rect *label, nk_flags state, |
| 23593 |
const char *name, int len, const struct nk_user_font *font) |
| 23594 |
{ |
| 23595 |
struct nk_text text; |
| 23596 |
const struct nk_style_item *background; |
| 23597 |
|
| 23598 |
|
| 23599 |
if (state & NK_WIDGET_STATE_ACTIVED) { |
| 23600 |
background = &style->active; |
| 23601 |
text.text = style->label_active; |
| 23602 |
} else if (state & NK_WIDGET_STATE_HOVER) { |
| 23603 |
background = &style->hover; |
| 23604 |
text.text = style->label_hover; |
| 23605 |
} else { |
| 23606 |
background = &style->normal; |
| 23607 |
text.text = style->label_normal; |
| 23608 |
} |
| 23609 |
|
| 23610 |
|
| 23611 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 23612 |
nk_draw_image(out, *bounds, &background->data.image, nk_white); |
| 23613 |
text.background = nk_rgba(0,0,0,0); |
| 23614 |
} else { |
| 23615 |
text.background = background->data.color; |
| 23616 |
nk_fill_rect(out, *bounds, style->rounding, background->data.color); |
| 23617 |
nk_stroke_rect(out, *bounds, style->rounding, style->border, background->data.color); |
| 23618 |
} |
| 23619 |
|
| 23620 |
|
| 23621 |
text.padding = nk_vec2(0,0); |
| 23622 |
nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font); |
| 23623 |
} |
| 23624 |
NK_LIB void |
| 23625 |
nk_do_property(nk_flags *ws, |
| 23626 |
struct nk_command_buffer *out, struct nk_rect property, |
| 23627 |
const char *name, struct nk_property_variant *variant, |
| 23628 |
float inc_per_pixel, char *buffer, int *len, |
| 23629 |
int *state, int *cursor, int *select_begin, int *select_end, |
| 23630 |
const struct nk_style_property *style, |
| 23631 |
enum nk_property_filter filter, struct nk_input *in, |
| 23632 |
const struct nk_user_font *font, struct nk_text_edit *text_edit, |
| 23633 |
enum nk_button_behavior behavior) |
| 23634 |
{ |
| 23635 |
const nk_plugin_filter filters[] = { |
| 23636 |
nk_filter_decimal, |
| 23637 |
nk_filter_float |
| 23638 |
}; |
| 23639 |
int active, old; |
| 23640 |
int num_len = 0, name_len; |
| 23641 |
char string[NK_MAX_NUMBER_BUFFER]; |
| 23642 |
float size; |
| 23643 |
|
| 23644 |
char *dst = 0; |
| 23645 |
int *length; |
| 23646 |
|
| 23647 |
struct nk_rect left; |
| 23648 |
struct nk_rect right; |
| 23649 |
struct nk_rect label; |
| 23650 |
struct nk_rect edit; |
| 23651 |
struct nk_rect empty; |
| 23652 |
|
| 23653 |
|
| 23654 |
left.h = font->height/2; |
| 23655 |
left.w = left.h; |
| 23656 |
left.x = property.x + style->border + style->padding.x; |
| 23657 |
left.y = property.y + style->border + property.h/2.0f - left.h/2; |
| 23658 |
|
| 23659 |
|
| 23660 |
name_len = nk_strlen(name); |
| 23661 |
size = font->width(font->userdata, font->height, name, name_len); |
| 23662 |
label.x = left.x + left.w + style->padding.x; |
| 23663 |
label.w = (float)size + 2 * style->padding.x; |
| 23664 |
label.y = property.y + style->border + style->padding.y; |
| 23665 |
label.h = property.h - (2 * style->border + 2 * style->padding.y); |
| 23666 |
|
| 23667 |
|
| 23668 |
right.y = left.y; |
| 23669 |
right.w = left.w; |
| 23670 |
right.h = left.h; |
| 23671 |
right.x = property.x + property.w - (right.w + style->padding.x); |
| 23672 |
|
| 23673 |
|
| 23674 |
if (*state == NK_PROPERTY_EDIT) { |
| 23675 |
size = font->width(font->userdata, font->height, buffer, *len); |
| 23676 |
size += style->edit.cursor_size; |
| 23677 |
length = len; |
| 23678 |
dst = buffer; |
| 23679 |
} else { |
| 23680 |
switch (variant->kind) { |
| 23681 |
default: break; |
| 23682 |
case NK_PROPERTY_INT: |
| 23683 |
nk_itoa(string, variant->value.i); |
| 23684 |
num_len = nk_strlen(string); |
| 23685 |
break; |
| 23686 |
case NK_PROPERTY_FLOAT: |
| 23687 |
NK_DTOA(string, (double)variant->value.f); |
| 23688 |
num_len = nk_string_float_limit(string, NK_MAX_FLOAT_PRECISION); |
| 23689 |
break; |
| 23690 |
case NK_PROPERTY_DOUBLE: |
| 23691 |
NK_DTOA(string, variant->value.d); |
| 23692 |
num_len = nk_string_float_limit(string, NK_MAX_FLOAT_PRECISION); |
| 23693 |
break; |
| 23694 |
} |
| 23695 |
size = font->width(font->userdata, font->height, string, num_len); |
| 23696 |
dst = string; |
| 23697 |
length = &num_len; |
| 23698 |
} |
| 23699 |
|
| 23700 |
edit.w = (float)size + 2 * style->padding.x; |
| 23701 |
edit.w = NK_MIN(edit.w, right.x - (label.x + label.w)); |
| 23702 |
edit.x = right.x - (edit.w + style->padding.x); |
| 23703 |
edit.y = property.y + style->border; |
| 23704 |
edit.h = property.h - (2 * style->border); |
| 23705 |
|
| 23706 |
|
| 23707 |
empty.w = edit.x - (label.x + label.w); |
| 23708 |
empty.x = label.x + label.w; |
| 23709 |
empty.y = property.y; |
| 23710 |
empty.h = property.h; |
| 23711 |
|
| 23712 |
|
| 23713 |
old = (*state == NK_PROPERTY_EDIT); |
| 23714 |
nk_property_behavior(ws, in, property, label, edit, empty, state, variant, inc_per_pixel); |
| 23715 |
|
| 23716 |
|
| 23717 |
if (style->draw_begin) style->draw_begin(out, style->userdata); |
| 23718 |
nk_draw_property(out, style, &property, &label, *ws, name, name_len, font); |
| 23719 |
if (style->draw_end) style->draw_end(out, style->userdata); |
| 23720 |
|
| 23721 |
|
| 23722 |
if (nk_do_button_symbol(ws, out, left, style->sym_left, behavior, &style->dec_button, in, font)) { |
| 23723 |
switch (variant->kind) { |
| 23724 |
default: break; |
| 23725 |
case NK_PROPERTY_INT: |
| 23726 |
variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i - variant->step.i, variant->max_value.i); break; |
| 23727 |
case NK_PROPERTY_FLOAT: |
| 23728 |
variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f - variant->step.f, variant->max_value.f); break; |
| 23729 |
case NK_PROPERTY_DOUBLE: |
| 23730 |
variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d - variant->step.d, variant->max_value.d); break; |
| 23731 |
} |
| 23732 |
} |
| 23733 |
|
| 23734 |
if (nk_do_button_symbol(ws, out, right, style->sym_right, behavior, &style->inc_button, in, font)) { |
| 23735 |
switch (variant->kind) { |
| 23736 |
default: break; |
| 23737 |
case NK_PROPERTY_INT: |
| 23738 |
variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i + variant->step.i, variant->max_value.i); break; |
| 23739 |
case NK_PROPERTY_FLOAT: |
| 23740 |
variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f + variant->step.f, variant->max_value.f); break; |
| 23741 |
case NK_PROPERTY_DOUBLE: |
| 23742 |
variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d); break; |
| 23743 |
} |
| 23744 |
} |
| 23745 |
if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) { |
| 23746 |
|
| 23747 |
NK_MEMCPY(buffer, dst, (nk_size)*length); |
| 23748 |
*cursor = nk_utf_len(buffer, *length); |
| 23749 |
*len = *length; |
| 23750 |
length = len; |
| 23751 |
dst = buffer; |
| 23752 |
active = 0; |
| 23753 |
} else active = (*state == NK_PROPERTY_EDIT); |
| 23754 |
|
| 23755 |
|
| 23756 |
nk_textedit_clear_state(text_edit, NK_TEXT_EDIT_SINGLE_LINE, filters[filter]); |
| 23757 |
text_edit->active = (unsigned char)active; |
| 23758 |
text_edit->string.len = *length; |
| 23759 |
text_edit->cursor = NK_CLAMP(0, *cursor, *length); |
| 23760 |
text_edit->select_start = NK_CLAMP(0,*select_begin, *length); |
| 23761 |
text_edit->select_end = NK_CLAMP(0,*select_end, *length); |
| 23762 |
text_edit->string.buffer.allocated = (nk_size)*length; |
| 23763 |
text_edit->string.buffer.memory.size = NK_MAX_NUMBER_BUFFER; |
| 23764 |
text_edit->string.buffer.memory.ptr = dst; |
| 23765 |
text_edit->string.buffer.size = NK_MAX_NUMBER_BUFFER; |
| 23766 |
text_edit->mode = NK_TEXT_EDIT_MODE_INSERT; |
| 23767 |
nk_do_edit(ws, out, edit, NK_EDIT_FIELD|NK_EDIT_AUTO_SELECT, |
| 23768 |
filters[filter], text_edit, &style->edit, (*state == NK_PROPERTY_EDIT) ? in: 0, font); |
| 23769 |
|
| 23770 |
*length = text_edit->string.len; |
| 23771 |
*cursor = text_edit->cursor; |
| 23772 |
*select_begin = text_edit->select_start; |
| 23773 |
*select_end = text_edit->select_end; |
| 23774 |
if (text_edit->active && nk_input_is_key_pressed(in, NK_KEY_ENTER)) |
| 23775 |
text_edit->active = nk_false; |
| 23776 |
|
| 23777 |
if (active && !text_edit->active) { |
| 23778 |
|
| 23779 |
*state = NK_PROPERTY_DEFAULT; |
| 23780 |
buffer[*len] = '\0'; |
| 23781 |
switch (variant->kind) { |
| 23782 |
default: break; |
| 23783 |
case NK_PROPERTY_INT: |
| 23784 |
variant->value.i = nk_strtoi(buffer, 0); |
| 23785 |
variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i); |
| 23786 |
break; |
| 23787 |
case NK_PROPERTY_FLOAT: |
| 23788 |
nk_string_float_limit(buffer, NK_MAX_FLOAT_PRECISION); |
| 23789 |
variant->value.f = nk_strtof(buffer, 0); |
| 23790 |
variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f); |
| 23791 |
break; |
| 23792 |
case NK_PROPERTY_DOUBLE: |
| 23793 |
nk_string_float_limit(buffer, NK_MAX_FLOAT_PRECISION); |
| 23794 |
variant->value.d = nk_strtod(buffer, 0); |
| 23795 |
variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d); |
| 23796 |
break; |
| 23797 |
} |
| 23798 |
} |
| 23799 |
} |
| 23800 |
NK_LIB struct nk_property_variant |
| 23801 |
nk_property_variant_int(int value, int min_value, int max_value, int step) |
| 23802 |
{ |
| 23803 |
struct nk_property_variant result; |
| 23804 |
result.kind = NK_PROPERTY_INT; |
| 23805 |
result.value.i = value; |
| 23806 |
result.min_value.i = min_value; |
| 23807 |
result.max_value.i = max_value; |
| 23808 |
result.step.i = step; |
| 23809 |
return result; |
| 23810 |
} |
| 23811 |
NK_LIB struct nk_property_variant |
| 23812 |
nk_property_variant_float(float value, float min_value, float max_value, float step) |
| 23813 |
{ |
| 23814 |
struct nk_property_variant result; |
| 23815 |
result.kind = NK_PROPERTY_FLOAT; |
| 23816 |
result.value.f = value; |
| 23817 |
result.min_value.f = min_value; |
| 23818 |
result.max_value.f = max_value; |
| 23819 |
result.step.f = step; |
| 23820 |
return result; |
| 23821 |
} |
| 23822 |
NK_LIB struct nk_property_variant |
| 23823 |
nk_property_variant_double(double value, double min_value, double max_value, |
| 23824 |
double step) |
| 23825 |
{ |
| 23826 |
struct nk_property_variant result; |
| 23827 |
result.kind = NK_PROPERTY_DOUBLE; |
| 23828 |
result.value.d = value; |
| 23829 |
result.min_value.d = min_value; |
| 23830 |
result.max_value.d = max_value; |
| 23831 |
result.step.d = step; |
| 23832 |
return result; |
| 23833 |
} |
| 23834 |
NK_LIB void |
| 23835 |
nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant *variant, |
| 23836 |
float inc_per_pixel, const enum nk_property_filter filter) |
| 23837 |
{ |
| 23838 |
struct nk_window *win; |
| 23839 |
struct nk_panel *layout; |
| 23840 |
struct nk_input *in; |
| 23841 |
const struct nk_style *style; |
| 23842 |
|
| 23843 |
struct nk_rect bounds; |
| 23844 |
enum nk_widget_layout_states s; |
| 23845 |
|
| 23846 |
int *state = 0; |
| 23847 |
nk_hash hash = 0; |
| 23848 |
char *buffer = 0; |
| 23849 |
int *len = 0; |
| 23850 |
int *cursor = 0; |
| 23851 |
int *select_begin = 0; |
| 23852 |
int *select_end = 0; |
| 23853 |
int old_state; |
| 23854 |
|
| 23855 |
char dummy_buffer[NK_MAX_NUMBER_BUFFER]; |
| 23856 |
int dummy_state = NK_PROPERTY_DEFAULT; |
| 23857 |
int dummy_length = 0; |
| 23858 |
int dummy_cursor = 0; |
| 23859 |
int dummy_select_begin = 0; |
| 23860 |
int dummy_select_end = 0; |
| 23861 |
|
| 23862 |
NK_ASSERT(ctx); |
| 23863 |
NK_ASSERT(ctx->current); |
| 23864 |
NK_ASSERT(ctx->current->layout); |
| 23865 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 23866 |
return; |
| 23867 |
|
| 23868 |
win = ctx->current; |
| 23869 |
layout = win->layout; |
| 23870 |
style = &ctx->style; |
| 23871 |
s = nk_widget(&bounds, ctx); |
| 23872 |
if (!s) return; |
| 23873 |
|
| 23874 |
|
| 23875 |
if (name[0] == '#') { |
| 23876 |
hash = nk_murmur_hash(name, (int)nk_strlen(name), win->property.seq++); |
| 23877 |
name++; |
| 23878 |
} else hash = nk_murmur_hash(name, (int)nk_strlen(name), 42); |
| 23879 |
|
| 23880 |
|
| 23881 |
if (win->property.active && hash == win->property.name) { |
| 23882 |
buffer = win->property.buffer; |
| 23883 |
len = &win->property.length; |
| 23884 |
cursor = &win->property.cursor; |
| 23885 |
state = &win->property.state; |
| 23886 |
select_begin = &win->property.select_start; |
| 23887 |
select_end = &win->property.select_end; |
| 23888 |
} else { |
| 23889 |
buffer = dummy_buffer; |
| 23890 |
len = &dummy_length; |
| 23891 |
cursor = &dummy_cursor; |
| 23892 |
state = &dummy_state; |
| 23893 |
select_begin = &dummy_select_begin; |
| 23894 |
select_end = &dummy_select_end; |
| 23895 |
} |
| 23896 |
|
| 23897 |
|
| 23898 |
old_state = *state; |
| 23899 |
ctx->text_edit.clip = ctx->clip; |
| 23900 |
in = ((s == NK_WIDGET_ROM && !win->property.active) || |
| 23901 |
layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 23902 |
nk_do_property(&ctx->last_widget_state, &win->buffer, bounds, name, |
| 23903 |
variant, inc_per_pixel, buffer, len, state, cursor, select_begin, |
| 23904 |
select_end, &style->property, filter, in, style->font, &ctx->text_edit, |
| 23905 |
ctx->button_behavior); |
| 23906 |
|
| 23907 |
if (in && *state != NK_PROPERTY_DEFAULT && !win->property.active) { |
| 23908 |
|
| 23909 |
win->property.active = 1; |
| 23910 |
NK_MEMCPY(win->property.buffer, buffer, (nk_size)*len); |
| 23911 |
win->property.length = *len; |
| 23912 |
win->property.cursor = *cursor; |
| 23913 |
win->property.state = *state; |
| 23914 |
win->property.name = hash; |
| 23915 |
win->property.select_start = *select_begin; |
| 23916 |
win->property.select_end = *select_end; |
| 23917 |
if (*state == NK_PROPERTY_DRAG) { |
| 23918 |
ctx->input.mouse.grab = nk_true; |
| 23919 |
ctx->input.mouse.grabbed = nk_true; |
| 23920 |
} |
| 23921 |
} |
| 23922 |
|
| 23923 |
if (*state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT) { |
| 23924 |
if (old_state == NK_PROPERTY_DRAG) { |
| 23925 |
ctx->input.mouse.grab = nk_false; |
| 23926 |
ctx->input.mouse.grabbed = nk_false; |
| 23927 |
ctx->input.mouse.ungrab = nk_true; |
| 23928 |
} |
| 23929 |
win->property.select_start = 0; |
| 23930 |
win->property.select_end = 0; |
| 23931 |
win->property.active = 0; |
| 23932 |
} |
| 23933 |
} |
| 23934 |
NK_API void |
| 23935 |
nk_property_int(struct nk_context *ctx, const char *name, |
| 23936 |
int min, int *val, int max, int step, float inc_per_pixel) |
| 23937 |
{ |
| 23938 |
struct nk_property_variant variant; |
| 23939 |
NK_ASSERT(ctx); |
| 23940 |
NK_ASSERT(name); |
| 23941 |
NK_ASSERT(val); |
| 23942 |
|
| 23943 |
if (!ctx || !ctx->current || !name || !val) return; |
| 23944 |
variant = nk_property_variant_int(*val, min, max, step); |
| 23945 |
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT); |
| 23946 |
*val = variant.value.i; |
| 23947 |
} |
| 23948 |
NK_API void |
| 23949 |
nk_property_float(struct nk_context *ctx, const char *name, |
| 23950 |
float min, float *val, float max, float step, float inc_per_pixel) |
| 23951 |
{ |
| 23952 |
struct nk_property_variant variant; |
| 23953 |
NK_ASSERT(ctx); |
| 23954 |
NK_ASSERT(name); |
| 23955 |
NK_ASSERT(val); |
| 23956 |
|
| 23957 |
if (!ctx || !ctx->current || !name || !val) return; |
| 23958 |
variant = nk_property_variant_float(*val, min, max, step); |
| 23959 |
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT); |
| 23960 |
*val = variant.value.f; |
| 23961 |
} |
| 23962 |
NK_API void |
| 23963 |
nk_property_double(struct nk_context *ctx, const char *name, |
| 23964 |
double min, double *val, double max, double step, float inc_per_pixel) |
| 23965 |
{ |
| 23966 |
struct nk_property_variant variant; |
| 23967 |
NK_ASSERT(ctx); |
| 23968 |
NK_ASSERT(name); |
| 23969 |
NK_ASSERT(val); |
| 23970 |
|
| 23971 |
if (!ctx || !ctx->current || !name || !val) return; |
| 23972 |
variant = nk_property_variant_double(*val, min, max, step); |
| 23973 |
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT); |
| 23974 |
*val = variant.value.d; |
| 23975 |
} |
| 23976 |
NK_API int |
| 23977 |
nk_propertyi(struct nk_context *ctx, const char *name, int min, int val, |
| 23978 |
int max, int step, float inc_per_pixel) |
| 23979 |
{ |
| 23980 |
struct nk_property_variant variant; |
| 23981 |
NK_ASSERT(ctx); |
| 23982 |
NK_ASSERT(name); |
| 23983 |
|
| 23984 |
if (!ctx || !ctx->current || !name) return val; |
| 23985 |
variant = nk_property_variant_int(val, min, max, step); |
| 23986 |
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT); |
| 23987 |
val = variant.value.i; |
| 23988 |
return val; |
| 23989 |
} |
| 23990 |
NK_API float |
| 23991 |
nk_propertyf(struct nk_context *ctx, const char *name, float min, |
| 23992 |
float val, float max, float step, float inc_per_pixel) |
| 23993 |
{ |
| 23994 |
struct nk_property_variant variant; |
| 23995 |
NK_ASSERT(ctx); |
| 23996 |
NK_ASSERT(name); |
| 23997 |
|
| 23998 |
if (!ctx || !ctx->current || !name) return val; |
| 23999 |
variant = nk_property_variant_float(val, min, max, step); |
| 24000 |
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT); |
| 24001 |
val = variant.value.f; |
| 24002 |
return val; |
| 24003 |
} |
| 24004 |
NK_API double |
| 24005 |
nk_propertyd(struct nk_context *ctx, const char *name, double min, |
| 24006 |
double val, double max, double step, float inc_per_pixel) |
| 24007 |
{ |
| 24008 |
struct nk_property_variant variant; |
| 24009 |
NK_ASSERT(ctx); |
| 24010 |
NK_ASSERT(name); |
| 24011 |
|
| 24012 |
if (!ctx || !ctx->current || !name) return val; |
| 24013 |
variant = nk_property_variant_double(val, min, max, step); |
| 24014 |
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT); |
| 24015 |
val = variant.value.d; |
| 24016 |
return val; |
| 24017 |
} |
| 24018 |
|
| 24019 |
|
| 24020 |
|
| 24021 |
|
| 24022 |
|
| 24023 |
|
| 24024 |
|
| 24025 |
|
| 24026 |
|
| 24027 |
|
| 24028 |
NK_API int |
| 24029 |
nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type, |
| 24030 |
struct nk_color color, struct nk_color highlight, |
| 24031 |
int count, float min_value, float max_value) |
| 24032 |
{ |
| 24033 |
struct nk_window *win; |
| 24034 |
struct nk_chart *chart; |
| 24035 |
const struct nk_style *config; |
| 24036 |
const struct nk_style_chart *style; |
| 24037 |
|
| 24038 |
const struct nk_style_item *background; |
| 24039 |
struct nk_rect bounds = {0, 0, 0, 0}; |
| 24040 |
|
| 24041 |
NK_ASSERT(ctx); |
| 24042 |
NK_ASSERT(ctx->current); |
| 24043 |
NK_ASSERT(ctx->current->layout); |
| 24044 |
|
| 24045 |
if (!ctx || !ctx->current || !ctx->current->layout) return 0; |
| 24046 |
if (!nk_widget(&bounds, ctx)) { |
| 24047 |
chart = &ctx->current->layout->chart; |
| 24048 |
nk_zero(chart, sizeof(*chart)); |
| 24049 |
return 0; |
| 24050 |
} |
| 24051 |
|
| 24052 |
win = ctx->current; |
| 24053 |
config = &ctx->style; |
| 24054 |
chart = &win->layout->chart; |
| 24055 |
style = &config->chart; |
| 24056 |
|
| 24057 |
|
| 24058 |
nk_zero(chart, sizeof(*chart)); |
| 24059 |
chart->x = bounds.x + style->padding.x; |
| 24060 |
chart->y = bounds.y + style->padding.y; |
| 24061 |
chart->w = bounds.w - 2 * style->padding.x; |
| 24062 |
chart->h = bounds.h - 2 * style->padding.y; |
| 24063 |
chart->w = NK_MAX(chart->w, 2 * style->padding.x); |
| 24064 |
chart->h = NK_MAX(chart->h, 2 * style->padding.y); |
| 24065 |
|
| 24066 |
|
| 24067 |
{struct nk_chart_slot *slot = &chart->slots[chart->slot++]; |
| 24068 |
slot->type = type; |
| 24069 |
slot->count = count; |
| 24070 |
slot->color = color; |
| 24071 |
slot->highlight = highlight; |
| 24072 |
slot->min = NK_MIN(min_value, max_value); |
| 24073 |
slot->max = NK_MAX(min_value, max_value); |
| 24074 |
slot->range = slot->max - slot->min;} |
| 24075 |
|
| 24076 |
|
| 24077 |
background = &style->background; |
| 24078 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 24079 |
nk_draw_image(&win->buffer, bounds, &background->data.image, nk_white); |
| 24080 |
} else { |
| 24081 |
nk_fill_rect(&win->buffer, bounds, style->rounding, style->border_color); |
| 24082 |
nk_fill_rect(&win->buffer, nk_shrink_rect(bounds, style->border), |
| 24083 |
style->rounding, style->background.data.color); |
| 24084 |
} |
| 24085 |
return 1; |
| 24086 |
} |
| 24087 |
NK_API int |
| 24088 |
nk_chart_begin(struct nk_context *ctx, const enum nk_chart_type type, |
| 24089 |
int count, float min_value, float max_value) |
| 24090 |
{ |
| 24091 |
return nk_chart_begin_colored(ctx, type, ctx->style.chart.color, |
| 24092 |
ctx->style.chart.selected_color, count, min_value, max_value); |
| 24093 |
} |
| 24094 |
NK_API void |
| 24095 |
nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type type, |
| 24096 |
struct nk_color color, struct nk_color highlight, |
| 24097 |
int count, float min_value, float max_value) |
| 24098 |
{ |
| 24099 |
NK_ASSERT(ctx); |
| 24100 |
NK_ASSERT(ctx->current); |
| 24101 |
NK_ASSERT(ctx->current->layout); |
| 24102 |
NK_ASSERT(ctx->current->layout->chart.slot < NK_CHART_MAX_SLOT); |
| 24103 |
if (!ctx || !ctx->current || !ctx->current->layout) return; |
| 24104 |
if (ctx->current->layout->chart.slot >= NK_CHART_MAX_SLOT) return; |
| 24105 |
|
| 24106 |
|
| 24107 |
{struct nk_chart *chart = &ctx->current->layout->chart; |
| 24108 |
struct nk_chart_slot *slot = &chart->slots[chart->slot++]; |
| 24109 |
slot->type = type; |
| 24110 |
slot->count = count; |
| 24111 |
slot->color = color; |
| 24112 |
slot->highlight = highlight; |
| 24113 |
slot->min = NK_MIN(min_value, max_value); |
| 24114 |
slot->max = NK_MAX(min_value, max_value); |
| 24115 |
slot->range = slot->max - slot->min;} |
| 24116 |
} |
| 24117 |
NK_API void |
| 24118 |
nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type type, |
| 24119 |
int count, float min_value, float max_value) |
| 24120 |
{ |
| 24121 |
nk_chart_add_slot_colored(ctx, type, ctx->style.chart.color, |
| 24122 |
ctx->style.chart.selected_color, count, min_value, max_value); |
| 24123 |
} |
| 24124 |
NK_INTERN nk_flags |
| 24125 |
nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, |
| 24126 |
struct nk_chart *g, float value, int slot) |
| 24127 |
{ |
| 24128 |
struct nk_panel *layout = win->layout; |
| 24129 |
const struct nk_input *i = &ctx->input; |
| 24130 |
struct nk_command_buffer *out = &win->buffer; |
| 24131 |
|
| 24132 |
nk_flags ret = 0; |
| 24133 |
struct nk_vec2 cur; |
| 24134 |
struct nk_rect bounds; |
| 24135 |
struct nk_color color; |
| 24136 |
float step; |
| 24137 |
float range; |
| 24138 |
float ratio; |
| 24139 |
|
| 24140 |
NK_ASSERT(slot >= 0 && slot < NK_CHART_MAX_SLOT); |
| 24141 |
step = g->w / (float)g->slots[slot].count; |
| 24142 |
range = g->slots[slot].max - g->slots[slot].min; |
| 24143 |
ratio = (value - g->slots[slot].min) / range; |
| 24144 |
|
| 24145 |
if (g->slots[slot].index == 0) { |
| 24146 |
|
| 24147 |
g->slots[slot].last.x = g->x; |
| 24148 |
g->slots[slot].last.y = (g->y + g->h) - ratio * (float)g->h; |
| 24149 |
|
| 24150 |
bounds.x = g->slots[slot].last.x - 2; |
| 24151 |
bounds.y = g->slots[slot].last.y - 2; |
| 24152 |
bounds.w = bounds.h = 4; |
| 24153 |
|
| 24154 |
color = g->slots[slot].color; |
| 24155 |
if (!(layout->flags & NK_WINDOW_ROM) && |
| 24156 |
NK_INBOX(i->mouse.pos.x,i->mouse.pos.y, g->slots[slot].last.x-3, g->slots[slot].last.y-3, 6, 6)){ |
| 24157 |
ret = nk_input_is_mouse_hovering_rect(i, bounds) ? NK_CHART_HOVERING : 0; |
| 24158 |
ret |= (i->mouse.buttons[NK_BUTTON_LEFT].down && |
| 24159 |
i->mouse.buttons[NK_BUTTON_LEFT].clicked) ? NK_CHART_CLICKED: 0; |
| 24160 |
color = g->slots[slot].highlight; |
| 24161 |
} |
| 24162 |
nk_fill_rect(out, bounds, 0, color); |
| 24163 |
g->slots[slot].index += 1; |
| 24164 |
return ret; |
| 24165 |
} |
| 24166 |
|
| 24167 |
|
| 24168 |
color = g->slots[slot].color; |
| 24169 |
cur.x = g->x + (float)(step * (float)g->slots[slot].index); |
| 24170 |
cur.y = (g->y + g->h) - (ratio * (float)g->h); |
| 24171 |
nk_stroke_line(out, g->slots[slot].last.x, g->slots[slot].last.y, cur.x, cur.y, 1.0f, color); |
| 24172 |
|
| 24173 |
bounds.x = cur.x - 3; |
| 24174 |
bounds.y = cur.y - 3; |
| 24175 |
bounds.w = bounds.h = 6; |
| 24176 |
|
| 24177 |
|
| 24178 |
if (!(layout->flags & NK_WINDOW_ROM)) { |
| 24179 |
if (nk_input_is_mouse_hovering_rect(i, bounds)) { |
| 24180 |
ret = NK_CHART_HOVERING; |
| 24181 |
ret |= (!i->mouse.buttons[NK_BUTTON_LEFT].down && |
| 24182 |
i->mouse.buttons[NK_BUTTON_LEFT].clicked) ? NK_CHART_CLICKED: 0; |
| 24183 |
color = g->slots[slot].highlight; |
| 24184 |
} |
| 24185 |
} |
| 24186 |
nk_fill_rect(out, nk_rect(cur.x - 2, cur.y - 2, 4, 4), 0, color); |
| 24187 |
|
| 24188 |
|
| 24189 |
g->slots[slot].last.x = cur.x; |
| 24190 |
g->slots[slot].last.y = cur.y; |
| 24191 |
g->slots[slot].index += 1; |
| 24192 |
return ret; |
| 24193 |
} |
| 24194 |
NK_INTERN nk_flags |
| 24195 |
nk_chart_push_column(const struct nk_context *ctx, struct nk_window *win, |
| 24196 |
struct nk_chart *chart, float value, int slot) |
| 24197 |
{ |
| 24198 |
struct nk_command_buffer *out = &win->buffer; |
| 24199 |
const struct nk_input *in = &ctx->input; |
| 24200 |
struct nk_panel *layout = win->layout; |
| 24201 |
|
| 24202 |
float ratio; |
| 24203 |
nk_flags ret = 0; |
| 24204 |
struct nk_color color; |
| 24205 |
struct nk_rect item = {0,0,0,0}; |
| 24206 |
|
| 24207 |
NK_ASSERT(slot >= 0 && slot < NK_CHART_MAX_SLOT); |
| 24208 |
if (chart->slots[slot].index >= chart->slots[slot].count) |
| 24209 |
return nk_false; |
| 24210 |
if (chart->slots[slot].count) { |
| 24211 |
float padding = (float)(chart->slots[slot].count-1); |
| 24212 |
item.w = (chart->w - padding) / (float)(chart->slots[slot].count); |
| 24213 |
} |
| 24214 |
|
| 24215 |
|
| 24216 |
color = chart->slots[slot].color;; |
| 24217 |
item.h = chart->h * NK_ABS((value/chart->slots[slot].range)); |
| 24218 |
if (value >= 0) { |
| 24219 |
ratio = (value + NK_ABS(chart->slots[slot].min)) / NK_ABS(chart->slots[slot].range); |
| 24220 |
item.y = (chart->y + chart->h) - chart->h * ratio; |
| 24221 |
} else { |
| 24222 |
ratio = (value - chart->slots[slot].max) / chart->slots[slot].range; |
| 24223 |
item.y = chart->y + (chart->h * NK_ABS(ratio)) - item.h; |
| 24224 |
} |
| 24225 |
item.x = chart->x + ((float)chart->slots[slot].index * item.w); |
| 24226 |
item.x = item.x + ((float)chart->slots[slot].index); |
| 24227 |
|
| 24228 |
|
| 24229 |
if (!(layout->flags & NK_WINDOW_ROM) && |
| 24230 |
NK_INBOX(in->mouse.pos.x,in->mouse.pos.y,item.x,item.y,item.w,item.h)) { |
| 24231 |
ret = NK_CHART_HOVERING; |
| 24232 |
ret |= (!in->mouse.buttons[NK_BUTTON_LEFT].down && |
| 24233 |
in->mouse.buttons[NK_BUTTON_LEFT].clicked) ? NK_CHART_CLICKED: 0; |
| 24234 |
color = chart->slots[slot].highlight; |
| 24235 |
} |
| 24236 |
nk_fill_rect(out, item, 0, color); |
| 24237 |
chart->slots[slot].index += 1; |
| 24238 |
return ret; |
| 24239 |
} |
| 24240 |
NK_API nk_flags |
| 24241 |
nk_chart_push_slot(struct nk_context *ctx, float value, int slot) |
| 24242 |
{ |
| 24243 |
nk_flags flags; |
| 24244 |
struct nk_window *win; |
| 24245 |
|
| 24246 |
NK_ASSERT(ctx); |
| 24247 |
NK_ASSERT(ctx->current); |
| 24248 |
NK_ASSERT(slot >= 0 && slot < NK_CHART_MAX_SLOT); |
| 24249 |
NK_ASSERT(slot < ctx->current->layout->chart.slot); |
| 24250 |
if (!ctx || !ctx->current || slot >= NK_CHART_MAX_SLOT) return nk_false; |
| 24251 |
if (slot >= ctx->current->layout->chart.slot) return nk_false; |
| 24252 |
|
| 24253 |
win = ctx->current; |
| 24254 |
if (win->layout->chart.slot < slot) return nk_false; |
| 24255 |
switch (win->layout->chart.slots[slot].type) { |
| 24256 |
case NK_CHART_LINES: |
| 24257 |
flags = nk_chart_push_line(ctx, win, &win->layout->chart, value, slot); break; |
| 24258 |
case NK_CHART_COLUMN: |
| 24259 |
flags = nk_chart_push_column(ctx, win, &win->layout->chart, value, slot); break; |
| 24260 |
default: |
| 24261 |
case NK_CHART_MAX: |
| 24262 |
flags = 0; |
| 24263 |
} |
| 24264 |
return flags; |
| 24265 |
} |
| 24266 |
NK_API nk_flags |
| 24267 |
nk_chart_push(struct nk_context *ctx, float value) |
| 24268 |
{ |
| 24269 |
return nk_chart_push_slot(ctx, value, 0); |
| 24270 |
} |
| 24271 |
NK_API void |
| 24272 |
nk_chart_end(struct nk_context *ctx) |
| 24273 |
{ |
| 24274 |
struct nk_window *win; |
| 24275 |
struct nk_chart *chart; |
| 24276 |
|
| 24277 |
NK_ASSERT(ctx); |
| 24278 |
NK_ASSERT(ctx->current); |
| 24279 |
if (!ctx || !ctx->current) |
| 24280 |
return; |
| 24281 |
|
| 24282 |
win = ctx->current; |
| 24283 |
chart = &win->layout->chart; |
| 24284 |
NK_MEMSET(chart, 0, sizeof(*chart)); |
| 24285 |
return; |
| 24286 |
} |
| 24287 |
NK_API void |
| 24288 |
nk_plot(struct nk_context *ctx, enum nk_chart_type type, const float *values, |
| 24289 |
int count, int offset) |
| 24290 |
{ |
| 24291 |
int i = 0; |
| 24292 |
float min_value; |
| 24293 |
float max_value; |
| 24294 |
|
| 24295 |
NK_ASSERT(ctx); |
| 24296 |
NK_ASSERT(values); |
| 24297 |
if (!ctx || !values || !count) return; |
| 24298 |
|
| 24299 |
min_value = values[offset]; |
| 24300 |
max_value = values[offset]; |
| 24301 |
for (i = 0; i < count; ++i) { |
| 24302 |
min_value = NK_MIN(values[i + offset], min_value); |
| 24303 |
max_value = NK_MAX(values[i + offset], max_value); |
| 24304 |
} |
| 24305 |
|
| 24306 |
if (nk_chart_begin(ctx, type, count, min_value, max_value)) { |
| 24307 |
for (i = 0; i < count; ++i) |
| 24308 |
nk_chart_push(ctx, values[i + offset]); |
| 24309 |
nk_chart_end(ctx); |
| 24310 |
} |
| 24311 |
} |
| 24312 |
NK_API void |
| 24313 |
nk_plot_function(struct nk_context *ctx, enum nk_chart_type type, void *userdata, |
| 24314 |
float(*value_getter)(void* user, int index), int count, int offset) |
| 24315 |
{ |
| 24316 |
int i = 0; |
| 24317 |
float min_value; |
| 24318 |
float max_value; |
| 24319 |
|
| 24320 |
NK_ASSERT(ctx); |
| 24321 |
NK_ASSERT(value_getter); |
| 24322 |
if (!ctx || !value_getter || !count) return; |
| 24323 |
|
| 24324 |
max_value = min_value = value_getter(userdata, offset); |
| 24325 |
for (i = 0; i < count; ++i) { |
| 24326 |
float value = value_getter(userdata, i + offset); |
| 24327 |
min_value = NK_MIN(value, min_value); |
| 24328 |
max_value = NK_MAX(value, max_value); |
| 24329 |
} |
| 24330 |
|
| 24331 |
if (nk_chart_begin(ctx, type, count, min_value, max_value)) { |
| 24332 |
for (i = 0; i < count; ++i) |
| 24333 |
nk_chart_push(ctx, value_getter(userdata, i + offset)); |
| 24334 |
nk_chart_end(ctx); |
| 24335 |
} |
| 24336 |
} |
| 24337 |
|
| 24338 |
|
| 24339 |
|
| 24340 |
|
| 24341 |
|
| 24342 |
|
| 24343 |
|
| 24344 |
|
| 24345 |
|
| 24346 |
|
| 24347 |
NK_LIB int |
| 24348 |
nk_color_picker_behavior(nk_flags *state, |
| 24349 |
const struct nk_rect *bounds, const struct nk_rect *matrix, |
| 24350 |
const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, |
| 24351 |
struct nk_colorf *color, const struct nk_input *in) |
| 24352 |
{ |
| 24353 |
float hsva[4]; |
| 24354 |
int value_changed = 0; |
| 24355 |
int hsv_changed = 0; |
| 24356 |
|
| 24357 |
NK_ASSERT(state); |
| 24358 |
NK_ASSERT(matrix); |
| 24359 |
NK_ASSERT(hue_bar); |
| 24360 |
NK_ASSERT(color); |
| 24361 |
|
| 24362 |
|
| 24363 |
nk_colorf_hsva_fv(hsva, *color); |
| 24364 |
if (nk_button_behavior(state, *matrix, in, NK_BUTTON_REPEATER)) { |
| 24365 |
hsva[1] = NK_SATURATE((in->mouse.pos.x - matrix->x) / (matrix->w-1)); |
| 24366 |
hsva[2] = 1.0f - NK_SATURATE((in->mouse.pos.y - matrix->y) / (matrix->h-1)); |
| 24367 |
value_changed = hsv_changed = 1; |
| 24368 |
} |
| 24369 |
|
| 24370 |
if (nk_button_behavior(state, *hue_bar, in, NK_BUTTON_REPEATER)) { |
| 24371 |
hsva[0] = NK_SATURATE((in->mouse.pos.y - hue_bar->y) / (hue_bar->h-1)); |
| 24372 |
value_changed = hsv_changed = 1; |
| 24373 |
} |
| 24374 |
|
| 24375 |
if (alpha_bar) { |
| 24376 |
if (nk_button_behavior(state, *alpha_bar, in, NK_BUTTON_REPEATER)) { |
| 24377 |
hsva[3] = 1.0f - NK_SATURATE((in->mouse.pos.y - alpha_bar->y) / (alpha_bar->h-1)); |
| 24378 |
value_changed = 1; |
| 24379 |
} |
| 24380 |
} |
| 24381 |
nk_widget_state_reset(state); |
| 24382 |
if (hsv_changed) { |
| 24383 |
*color = nk_hsva_colorfv(hsva); |
| 24384 |
*state = NK_WIDGET_STATE_ACTIVE; |
| 24385 |
} |
| 24386 |
if (value_changed) { |
| 24387 |
color->a = hsva[3]; |
| 24388 |
*state = NK_WIDGET_STATE_ACTIVE; |
| 24389 |
} |
| 24390 |
|
| 24391 |
if (nk_input_is_mouse_hovering_rect(in, *bounds)) |
| 24392 |
*state = NK_WIDGET_STATE_HOVERED; |
| 24393 |
if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, *bounds)) |
| 24394 |
*state |= NK_WIDGET_STATE_ENTERED; |
| 24395 |
else if (nk_input_is_mouse_prev_hovering_rect(in, *bounds)) |
| 24396 |
*state |= NK_WIDGET_STATE_LEFT; |
| 24397 |
return value_changed; |
| 24398 |
} |
| 24399 |
NK_LIB void |
| 24400 |
nk_draw_color_picker(struct nk_command_buffer *o, const struct nk_rect *matrix, |
| 24401 |
const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, |
| 24402 |
struct nk_colorf col) |
| 24403 |
{ |
| 24404 |
NK_STORAGE const struct nk_color black = {0,0,0,255}; |
| 24405 |
NK_STORAGE const struct nk_color white = {255, 255, 255, 255}; |
| 24406 |
NK_STORAGE const struct nk_color black_trans = {0,0,0,0}; |
| 24407 |
|
| 24408 |
const float crosshair_size = 7.0f; |
| 24409 |
struct nk_color temp; |
| 24410 |
float hsva[4]; |
| 24411 |
float line_y; |
| 24412 |
int i; |
| 24413 |
|
| 24414 |
NK_ASSERT(o); |
| 24415 |
NK_ASSERT(matrix); |
| 24416 |
NK_ASSERT(hue_bar); |
| 24417 |
|
| 24418 |
|
| 24419 |
nk_colorf_hsva_fv(hsva, col); |
| 24420 |
for (i = 0; i < 6; ++i) { |
| 24421 |
NK_GLOBAL const struct nk_color hue_colors[] = { |
| 24422 |
{255, 0, 0, 255}, {255,255,0,255}, {0,255,0,255}, {0, 255,255,255}, |
| 24423 |
{0,0,255,255}, {255, 0, 255, 255}, {255, 0, 0, 255} |
| 24424 |
}; |
| 24425 |
nk_fill_rect_multi_color(o, |
| 24426 |
nk_rect(hue_bar->x, hue_bar->y + (float)i * (hue_bar->h/6.0f) + 0.5f, |
| 24427 |
hue_bar->w, (hue_bar->h/6.0f) + 0.5f), hue_colors[i], hue_colors[i], |
| 24428 |
hue_colors[i+1], hue_colors[i+1]); |
| 24429 |
} |
| 24430 |
line_y = (float)(int)(hue_bar->y + hsva[0] * matrix->h + 0.5f); |
| 24431 |
nk_stroke_line(o, hue_bar->x-1, line_y, hue_bar->x + hue_bar->w + 2, |
| 24432 |
line_y, 1, nk_rgb(255,255,255)); |
| 24433 |
|
| 24434 |
|
| 24435 |
if (alpha_bar) { |
| 24436 |
float alpha = NK_SATURATE(col.a); |
| 24437 |
line_y = (float)(int)(alpha_bar->y + (1.0f - alpha) * matrix->h + 0.5f); |
| 24438 |
|
| 24439 |
nk_fill_rect_multi_color(o, *alpha_bar, white, white, black, black); |
| 24440 |
nk_stroke_line(o, alpha_bar->x-1, line_y, alpha_bar->x + alpha_bar->w + 2, |
| 24441 |
line_y, 1, nk_rgb(255,255,255)); |
| 24442 |
} |
| 24443 |
|
| 24444 |
|
| 24445 |
temp = nk_hsv_f(hsva[0], 1.0f, 1.0f); |
| 24446 |
nk_fill_rect_multi_color(o, *matrix, white, temp, temp, white); |
| 24447 |
nk_fill_rect_multi_color(o, *matrix, black_trans, black_trans, black, black); |
| 24448 |
|
| 24449 |
|
| 24450 |
{struct nk_vec2 p; float S = hsva[1]; float V = hsva[2]; |
| 24451 |
p.x = (float)(int)(matrix->x + S * matrix->w); |
| 24452 |
p.y = (float)(int)(matrix->y + (1.0f - V) * matrix->h); |
| 24453 |
nk_stroke_line(o, p.x - crosshair_size, p.y, p.x-2, p.y, 1.0f, white); |
| 24454 |
nk_stroke_line(o, p.x + crosshair_size + 1, p.y, p.x+3, p.y, 1.0f, white); |
| 24455 |
nk_stroke_line(o, p.x, p.y + crosshair_size + 1, p.x, p.y+3, 1.0f, white); |
| 24456 |
nk_stroke_line(o, p.x, p.y - crosshair_size, p.x, p.y-2, 1.0f, white);} |
| 24457 |
} |
| 24458 |
NK_LIB int |
| 24459 |
nk_do_color_picker(nk_flags *state, |
| 24460 |
struct nk_command_buffer *out, struct nk_colorf *col, |
| 24461 |
enum nk_color_format fmt, struct nk_rect bounds, |
| 24462 |
struct nk_vec2 padding, const struct nk_input *in, |
| 24463 |
const struct nk_user_font *font) |
| 24464 |
{ |
| 24465 |
int ret = 0; |
| 24466 |
struct nk_rect matrix; |
| 24467 |
struct nk_rect hue_bar; |
| 24468 |
struct nk_rect alpha_bar; |
| 24469 |
float bar_w; |
| 24470 |
|
| 24471 |
NK_ASSERT(out); |
| 24472 |
NK_ASSERT(col); |
| 24473 |
NK_ASSERT(state); |
| 24474 |
NK_ASSERT(font); |
| 24475 |
if (!out || !col || !state || !font) |
| 24476 |
return ret; |
| 24477 |
|
| 24478 |
bar_w = font->height; |
| 24479 |
bounds.x += padding.x; |
| 24480 |
bounds.y += padding.x; |
| 24481 |
bounds.w -= 2 * padding.x; |
| 24482 |
bounds.h -= 2 * padding.y; |
| 24483 |
|
| 24484 |
matrix.x = bounds.x; |
| 24485 |
matrix.y = bounds.y; |
| 24486 |
matrix.h = bounds.h; |
| 24487 |
matrix.w = bounds.w - (3 * padding.x + 2 * bar_w); |
| 24488 |
|
| 24489 |
hue_bar.w = bar_w; |
| 24490 |
hue_bar.y = bounds.y; |
| 24491 |
hue_bar.h = matrix.h; |
| 24492 |
hue_bar.x = matrix.x + matrix.w + padding.x; |
| 24493 |
|
| 24494 |
alpha_bar.x = hue_bar.x + hue_bar.w + padding.x; |
| 24495 |
alpha_bar.y = bounds.y; |
| 24496 |
alpha_bar.w = bar_w; |
| 24497 |
alpha_bar.h = matrix.h; |
| 24498 |
|
| 24499 |
ret = nk_color_picker_behavior(state, &bounds, &matrix, &hue_bar, |
| 24500 |
(fmt == NK_RGBA) ? &alpha_bar:0, col, in); |
| 24501 |
nk_draw_color_picker(out, &matrix, &hue_bar, (fmt == NK_RGBA) ? &alpha_bar:0, *col); |
| 24502 |
return ret; |
| 24503 |
} |
| 24504 |
NK_API int |
| 24505 |
nk_color_pick(struct nk_context * ctx, struct nk_colorf *color, |
| 24506 |
enum nk_color_format fmt) |
| 24507 |
{ |
| 24508 |
struct nk_window *win; |
| 24509 |
struct nk_panel *layout; |
| 24510 |
const struct nk_style *config; |
| 24511 |
const struct nk_input *in; |
| 24512 |
|
| 24513 |
enum nk_widget_layout_states state; |
| 24514 |
struct nk_rect bounds; |
| 24515 |
|
| 24516 |
NK_ASSERT(ctx); |
| 24517 |
NK_ASSERT(color); |
| 24518 |
NK_ASSERT(ctx->current); |
| 24519 |
NK_ASSERT(ctx->current->layout); |
| 24520 |
if (!ctx || !ctx->current || !ctx->current->layout || !color) |
| 24521 |
return 0; |
| 24522 |
|
| 24523 |
win = ctx->current; |
| 24524 |
config = &ctx->style; |
| 24525 |
layout = win->layout; |
| 24526 |
state = nk_widget(&bounds, ctx); |
| 24527 |
if (!state) return 0; |
| 24528 |
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
| 24529 |
return nk_do_color_picker(&ctx->last_widget_state, &win->buffer, color, fmt, bounds, |
| 24530 |
nk_vec2(0,0), in, config->font); |
| 24531 |
} |
| 24532 |
NK_API struct nk_colorf |
| 24533 |
nk_color_picker(struct nk_context *ctx, struct nk_colorf color, |
| 24534 |
enum nk_color_format fmt) |
| 24535 |
{ |
| 24536 |
nk_color_pick(ctx, &color, fmt); |
| 24537 |
return color; |
| 24538 |
} |
| 24539 |
|
| 24540 |
|
| 24541 |
|
| 24542 |
|
| 24543 |
|
| 24544 |
|
| 24545 |
|
| 24546 |
|
| 24547 |
|
| 24548 |
|
| 24549 |
NK_INTERN int |
| 24550 |
nk_combo_begin(struct nk_context *ctx, struct nk_window *win, |
| 24551 |
struct nk_vec2 size, int is_clicked, struct nk_rect header) |
| 24552 |
{ |
| 24553 |
struct nk_window *popup; |
| 24554 |
int is_open = 0; |
| 24555 |
int is_active = 0; |
| 24556 |
struct nk_rect body; |
| 24557 |
nk_hash hash; |
| 24558 |
|
| 24559 |
NK_ASSERT(ctx); |
| 24560 |
NK_ASSERT(ctx->current); |
| 24561 |
NK_ASSERT(ctx->current->layout); |
| 24562 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 24563 |
return 0; |
| 24564 |
|
| 24565 |
popup = win->popup.win; |
| 24566 |
body.x = header.x; |
| 24567 |
body.w = size.x; |
| 24568 |
body.y = header.y + header.h-ctx->style.window.combo_border; |
| 24569 |
body.h = size.y; |
| 24570 |
|
| 24571 |
hash = win->popup.combo_count++; |
| 24572 |
is_open = (popup) ? nk_true:nk_false; |
| 24573 |
is_active = (popup && (win->popup.name == hash) && win->popup.type == NK_PANEL_COMBO); |
| 24574 |
if ((is_clicked && is_open && !is_active) || (is_open && !is_active) || |
| 24575 |
(!is_open && !is_active && !is_clicked)) return 0; |
| 24576 |
if (!nk_nonblock_begin(ctx, 0, body, |
| 24577 |
(is_clicked && is_open)?nk_rect(0,0,0,0):header, NK_PANEL_COMBO)) return 0; |
| 24578 |
|
| 24579 |
win->popup.type = NK_PANEL_COMBO; |
| 24580 |
win->popup.name = hash; |
| 24581 |
return 1; |
| 24582 |
} |
| 24583 |
NK_API int |
| 24584 |
nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, |
| 24585 |
struct nk_vec2 size) |
| 24586 |
{ |
| 24587 |
const struct nk_input *in; |
| 24588 |
struct nk_window *win; |
| 24589 |
struct nk_style *style; |
| 24590 |
|
| 24591 |
enum nk_widget_layout_states s; |
| 24592 |
int is_clicked = nk_false; |
| 24593 |
struct nk_rect header; |
| 24594 |
const struct nk_style_item *background; |
| 24595 |
struct nk_text text; |
| 24596 |
|
| 24597 |
NK_ASSERT(ctx); |
| 24598 |
NK_ASSERT(selected); |
| 24599 |
NK_ASSERT(ctx->current); |
| 24600 |
NK_ASSERT(ctx->current->layout); |
| 24601 |
if (!ctx || !ctx->current || !ctx->current->layout || !selected) |
| 24602 |
return 0; |
| 24603 |
|
| 24604 |
win = ctx->current; |
| 24605 |
style = &ctx->style; |
| 24606 |
s = nk_widget(&header, ctx); |
| 24607 |
if (s == NK_WIDGET_INVALID) |
| 24608 |
return 0; |
| 24609 |
|
| 24610 |
in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; |
| 24611 |
if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) |
| 24612 |
is_clicked = nk_true; |
| 24613 |
|
| 24614 |
|
| 24615 |
if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) { |
| 24616 |
background = &style->combo.active; |
| 24617 |
text.text = style->combo.label_active; |
| 24618 |
} else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) { |
| 24619 |
background = &style->combo.hover; |
| 24620 |
text.text = style->combo.label_hover; |
| 24621 |
} else { |
| 24622 |
background = &style->combo.normal; |
| 24623 |
text.text = style->combo.label_normal; |
| 24624 |
} |
| 24625 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 24626 |
text.background = nk_rgba(0,0,0,0); |
| 24627 |
nk_draw_image(&win->buffer, header, &background->data.image, nk_white); |
| 24628 |
} else { |
| 24629 |
text.background = background->data.color; |
| 24630 |
nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); |
| 24631 |
nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); |
| 24632 |
} |
| 24633 |
{ |
| 24634 |
|
| 24635 |
struct nk_rect label; |
| 24636 |
struct nk_rect button; |
| 24637 |
struct nk_rect content; |
| 24638 |
|
| 24639 |
enum nk_symbol_type sym; |
| 24640 |
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) |
| 24641 |
sym = style->combo.sym_hover; |
| 24642 |
else if (is_clicked) |
| 24643 |
sym = style->combo.sym_active; |
| 24644 |
else sym = style->combo.sym_normal; |
| 24645 |
|
| 24646 |
|
| 24647 |
button.w = header.h - 2 * style->combo.button_padding.y; |
| 24648 |
button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; |
| 24649 |
button.y = header.y + style->combo.button_padding.y; |
| 24650 |
button.h = button.w; |
| 24651 |
|
| 24652 |
content.x = button.x + style->combo.button.padding.x; |
| 24653 |
content.y = button.y + style->combo.button.padding.y; |
| 24654 |
content.w = button.w - 2 * style->combo.button.padding.x; |
| 24655 |
content.h = button.h - 2 * style->combo.button.padding.y; |
| 24656 |
|
| 24657 |
|
| 24658 |
text.padding = nk_vec2(0,0); |
| 24659 |
label.x = header.x + style->combo.content_padding.x; |
| 24660 |
label.y = header.y + style->combo.content_padding.y; |
| 24661 |
label.w = button.x - (style->combo.content_padding.x + style->combo.spacing.x) - label.x;; |
| 24662 |
label.h = header.h - 2 * style->combo.content_padding.y; |
| 24663 |
nk_widget_text(&win->buffer, label, selected, len, &text, |
| 24664 |
NK_TEXT_LEFT, ctx->style.font); |
| 24665 |
|
| 24666 |
|
| 24667 |
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, |
| 24668 |
&ctx->style.combo.button, sym, style->font); |
| 24669 |
} |
| 24670 |
return nk_combo_begin(ctx, win, size, is_clicked, header); |
| 24671 |
} |
| 24672 |
NK_API int |
| 24673 |
nk_combo_begin_label(struct nk_context *ctx, const char *selected, struct nk_vec2 size) |
| 24674 |
{ |
| 24675 |
return nk_combo_begin_text(ctx, selected, nk_strlen(selected), size); |
| 24676 |
} |
| 24677 |
NK_API int |
| 24678 |
nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_vec2 size) |
| 24679 |
{ |
| 24680 |
struct nk_window *win; |
| 24681 |
struct nk_style *style; |
| 24682 |
const struct nk_input *in; |
| 24683 |
|
| 24684 |
struct nk_rect header; |
| 24685 |
int is_clicked = nk_false; |
| 24686 |
enum nk_widget_layout_states s; |
| 24687 |
const struct nk_style_item *background; |
| 24688 |
|
| 24689 |
NK_ASSERT(ctx); |
| 24690 |
NK_ASSERT(ctx->current); |
| 24691 |
NK_ASSERT(ctx->current->layout); |
| 24692 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 24693 |
return 0; |
| 24694 |
|
| 24695 |
win = ctx->current; |
| 24696 |
style = &ctx->style; |
| 24697 |
s = nk_widget(&header, ctx); |
| 24698 |
if (s == NK_WIDGET_INVALID) |
| 24699 |
return 0; |
| 24700 |
|
| 24701 |
in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; |
| 24702 |
if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) |
| 24703 |
is_clicked = nk_true; |
| 24704 |
|
| 24705 |
|
| 24706 |
if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) |
| 24707 |
background = &style->combo.active; |
| 24708 |
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) |
| 24709 |
background = &style->combo.hover; |
| 24710 |
else background = &style->combo.normal; |
| 24711 |
|
| 24712 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 24713 |
nk_draw_image(&win->buffer, header, &background->data.image,nk_white); |
| 24714 |
} else { |
| 24715 |
nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); |
| 24716 |
nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); |
| 24717 |
} |
| 24718 |
{ |
| 24719 |
struct nk_rect content; |
| 24720 |
struct nk_rect button; |
| 24721 |
struct nk_rect bounds; |
| 24722 |
|
| 24723 |
enum nk_symbol_type sym; |
| 24724 |
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) |
| 24725 |
sym = style->combo.sym_hover; |
| 24726 |
else if (is_clicked) |
| 24727 |
sym = style->combo.sym_active; |
| 24728 |
else sym = style->combo.sym_normal; |
| 24729 |
|
| 24730 |
|
| 24731 |
button.w = header.h - 2 * style->combo.button_padding.y; |
| 24732 |
button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; |
| 24733 |
button.y = header.y + style->combo.button_padding.y; |
| 24734 |
button.h = button.w; |
| 24735 |
|
| 24736 |
content.x = button.x + style->combo.button.padding.x; |
| 24737 |
content.y = button.y + style->combo.button.padding.y; |
| 24738 |
content.w = button.w - 2 * style->combo.button.padding.x; |
| 24739 |
content.h = button.h - 2 * style->combo.button.padding.y; |
| 24740 |
|
| 24741 |
|
| 24742 |
bounds.h = header.h - 4 * style->combo.content_padding.y; |
| 24743 |
bounds.y = header.y + 2 * style->combo.content_padding.y; |
| 24744 |
bounds.x = header.x + 2 * style->combo.content_padding.x; |
| 24745 |
bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x; |
| 24746 |
nk_fill_rect(&win->buffer, bounds, 0, color); |
| 24747 |
|
| 24748 |
|
| 24749 |
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, |
| 24750 |
&ctx->style.combo.button, sym, style->font); |
| 24751 |
} |
| 24752 |
return nk_combo_begin(ctx, win, size, is_clicked, header); |
| 24753 |
} |
| 24754 |
NK_API int |
| 24755 |
nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct nk_vec2 size) |
| 24756 |
{ |
| 24757 |
struct nk_window *win; |
| 24758 |
struct nk_style *style; |
| 24759 |
const struct nk_input *in; |
| 24760 |
|
| 24761 |
struct nk_rect header; |
| 24762 |
int is_clicked = nk_false; |
| 24763 |
enum nk_widget_layout_states s; |
| 24764 |
const struct nk_style_item *background; |
| 24765 |
struct nk_color sym_background; |
| 24766 |
struct nk_color symbol_color; |
| 24767 |
|
| 24768 |
NK_ASSERT(ctx); |
| 24769 |
NK_ASSERT(ctx->current); |
| 24770 |
NK_ASSERT(ctx->current->layout); |
| 24771 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 24772 |
return 0; |
| 24773 |
|
| 24774 |
win = ctx->current; |
| 24775 |
style = &ctx->style; |
| 24776 |
s = nk_widget(&header, ctx); |
| 24777 |
if (s == NK_WIDGET_INVALID) |
| 24778 |
return 0; |
| 24779 |
|
| 24780 |
in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; |
| 24781 |
if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) |
| 24782 |
is_clicked = nk_true; |
| 24783 |
|
| 24784 |
|
| 24785 |
if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) { |
| 24786 |
background = &style->combo.active; |
| 24787 |
symbol_color = style->combo.symbol_active; |
| 24788 |
} else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) { |
| 24789 |
background = &style->combo.hover; |
| 24790 |
symbol_color = style->combo.symbol_hover; |
| 24791 |
} else { |
| 24792 |
background = &style->combo.normal; |
| 24793 |
symbol_color = style->combo.symbol_hover; |
| 24794 |
} |
| 24795 |
|
| 24796 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 24797 |
sym_background = nk_rgba(0,0,0,0); |
| 24798 |
nk_draw_image(&win->buffer, header, &background->data.image, nk_white); |
| 24799 |
} else { |
| 24800 |
sym_background = background->data.color; |
| 24801 |
nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); |
| 24802 |
nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); |
| 24803 |
} |
| 24804 |
{ |
| 24805 |
struct nk_rect bounds = {0,0,0,0}; |
| 24806 |
struct nk_rect content; |
| 24807 |
struct nk_rect button; |
| 24808 |
|
| 24809 |
enum nk_symbol_type sym; |
| 24810 |
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) |
| 24811 |
sym = style->combo.sym_hover; |
| 24812 |
else if (is_clicked) |
| 24813 |
sym = style->combo.sym_active; |
| 24814 |
else sym = style->combo.sym_normal; |
| 24815 |
|
| 24816 |
|
| 24817 |
button.w = header.h - 2 * style->combo.button_padding.y; |
| 24818 |
button.x = (header.x + header.w - header.h) - style->combo.button_padding.y; |
| 24819 |
button.y = header.y + style->combo.button_padding.y; |
| 24820 |
button.h = button.w; |
| 24821 |
|
| 24822 |
content.x = button.x + style->combo.button.padding.x; |
| 24823 |
content.y = button.y + style->combo.button.padding.y; |
| 24824 |
content.w = button.w - 2 * style->combo.button.padding.x; |
| 24825 |
content.h = button.h - 2 * style->combo.button.padding.y; |
| 24826 |
|
| 24827 |
|
| 24828 |
bounds.h = header.h - 2 * style->combo.content_padding.y; |
| 24829 |
bounds.y = header.y + style->combo.content_padding.y; |
| 24830 |
bounds.x = header.x + style->combo.content_padding.x; |
| 24831 |
bounds.w = (button.x - style->combo.content_padding.y) - bounds.x; |
| 24832 |
nk_draw_symbol(&win->buffer, symbol, bounds, sym_background, symbol_color, |
| 24833 |
1.0f, style->font); |
| 24834 |
|
| 24835 |
|
| 24836 |
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state, |
| 24837 |
&ctx->style.combo.button, sym, style->font); |
| 24838 |
} |
| 24839 |
return nk_combo_begin(ctx, win, size, is_clicked, header); |
| 24840 |
} |
| 24841 |
NK_API int |
| 24842 |
nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len, |
| 24843 |
enum nk_symbol_type symbol, struct nk_vec2 size) |
| 24844 |
{ |
| 24845 |
struct nk_window *win; |
| 24846 |
struct nk_style *style; |
| 24847 |
struct nk_input *in; |
| 24848 |
|
| 24849 |
struct nk_rect header; |
| 24850 |
int is_clicked = nk_false; |
| 24851 |
enum nk_widget_layout_states s; |
| 24852 |
const struct nk_style_item *background; |
| 24853 |
struct nk_color symbol_color; |
| 24854 |
struct nk_text text; |
| 24855 |
|
| 24856 |
NK_ASSERT(ctx); |
| 24857 |
NK_ASSERT(ctx->current); |
| 24858 |
NK_ASSERT(ctx->current->layout); |
| 24859 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 24860 |
return 0; |
| 24861 |
|
| 24862 |
win = ctx->current; |
| 24863 |
style = &ctx->style; |
| 24864 |
s = nk_widget(&header, ctx); |
| 24865 |
if (!s) return 0; |
| 24866 |
|
| 24867 |
in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; |
| 24868 |
if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) |
| 24869 |
is_clicked = nk_true; |
| 24870 |
|
| 24871 |
|
| 24872 |
if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) { |
| 24873 |
background = &style->combo.active; |
| 24874 |
symbol_color = style->combo.symbol_active; |
| 24875 |
text.text = style->combo.label_active; |
| 24876 |
} else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) { |
| 24877 |
background = &style->combo.hover; |
| 24878 |
symbol_color = style->combo.symbol_hover; |
| 24879 |
text.text = style->combo.label_hover; |
| 24880 |
} else { |
| 24881 |
background = &style->combo.normal; |
| 24882 |
symbol_color = style->combo.symbol_normal; |
| 24883 |
text.text = style->combo.label_normal; |
| 24884 |
} |
| 24885 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 24886 |
text.background = nk_rgba(0,0,0,0); |
| 24887 |
nk_draw_image(&win->buffer, header, &background->data.image, nk_white); |
| 24888 |
} else { |
| 24889 |
text.background = background->data.color; |
| 24890 |
nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); |
| 24891 |
nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); |
| 24892 |
} |
| 24893 |
{ |
| 24894 |
struct nk_rect content; |
| 24895 |
struct nk_rect button; |
| 24896 |
struct nk_rect label; |
| 24897 |
struct nk_rect image; |
| 24898 |
|
| 24899 |
enum nk_symbol_type sym; |
| 24900 |
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) |
| 24901 |
sym = style->combo.sym_hover; |
| 24902 |
else if (is_clicked) |
| 24903 |
sym = style->combo.sym_active; |
| 24904 |
else sym = style->combo.sym_normal; |
| 24905 |
|
| 24906 |
|
| 24907 |
button.w = header.h - 2 * style->combo.button_padding.y; |
| 24908 |
button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; |
| 24909 |
button.y = header.y + style->combo.button_padding.y; |
| 24910 |
button.h = button.w; |
| 24911 |
|
| 24912 |
content.x = button.x + style->combo.button.padding.x; |
| 24913 |
content.y = button.y + style->combo.button.padding.y; |
| 24914 |
content.w = button.w - 2 * style->combo.button.padding.x; |
| 24915 |
content.h = button.h - 2 * style->combo.button.padding.y; |
| 24916 |
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, |
| 24917 |
&ctx->style.combo.button, sym, style->font); |
| 24918 |
|
| 24919 |
|
| 24920 |
image.x = header.x + style->combo.content_padding.x; |
| 24921 |
image.y = header.y + style->combo.content_padding.y; |
| 24922 |
image.h = header.h - 2 * style->combo.content_padding.y; |
| 24923 |
image.w = image.h; |
| 24924 |
nk_draw_symbol(&win->buffer, symbol, image, text.background, symbol_color, |
| 24925 |
1.0f, style->font); |
| 24926 |
|
| 24927 |
|
| 24928 |
text.padding = nk_vec2(0,0); |
| 24929 |
label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x; |
| 24930 |
label.y = header.y + style->combo.content_padding.y; |
| 24931 |
label.w = (button.x - style->combo.content_padding.x) - label.x; |
| 24932 |
label.h = header.h - 2 * style->combo.content_padding.y; |
| 24933 |
nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font); |
| 24934 |
} |
| 24935 |
return nk_combo_begin(ctx, win, size, is_clicked, header); |
| 24936 |
} |
| 24937 |
NK_API int |
| 24938 |
nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 size) |
| 24939 |
{ |
| 24940 |
struct nk_window *win; |
| 24941 |
struct nk_style *style; |
| 24942 |
const struct nk_input *in; |
| 24943 |
|
| 24944 |
struct nk_rect header; |
| 24945 |
int is_clicked = nk_false; |
| 24946 |
enum nk_widget_layout_states s; |
| 24947 |
const struct nk_style_item *background; |
| 24948 |
|
| 24949 |
NK_ASSERT(ctx); |
| 24950 |
NK_ASSERT(ctx->current); |
| 24951 |
NK_ASSERT(ctx->current->layout); |
| 24952 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 24953 |
return 0; |
| 24954 |
|
| 24955 |
win = ctx->current; |
| 24956 |
style = &ctx->style; |
| 24957 |
s = nk_widget(&header, ctx); |
| 24958 |
if (s == NK_WIDGET_INVALID) |
| 24959 |
return 0; |
| 24960 |
|
| 24961 |
in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; |
| 24962 |
if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) |
| 24963 |
is_clicked = nk_true; |
| 24964 |
|
| 24965 |
|
| 24966 |
if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) |
| 24967 |
background = &style->combo.active; |
| 24968 |
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) |
| 24969 |
background = &style->combo.hover; |
| 24970 |
else background = &style->combo.normal; |
| 24971 |
|
| 24972 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 24973 |
nk_draw_image(&win->buffer, header, &background->data.image, nk_white); |
| 24974 |
} else { |
| 24975 |
nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); |
| 24976 |
nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); |
| 24977 |
} |
| 24978 |
{ |
| 24979 |
struct nk_rect bounds = {0,0,0,0}; |
| 24980 |
struct nk_rect content; |
| 24981 |
struct nk_rect button; |
| 24982 |
|
| 24983 |
enum nk_symbol_type sym; |
| 24984 |
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) |
| 24985 |
sym = style->combo.sym_hover; |
| 24986 |
else if (is_clicked) |
| 24987 |
sym = style->combo.sym_active; |
| 24988 |
else sym = style->combo.sym_normal; |
| 24989 |
|
| 24990 |
|
| 24991 |
button.w = header.h - 2 * style->combo.button_padding.y; |
| 24992 |
button.x = (header.x + header.w - header.h) - style->combo.button_padding.y; |
| 24993 |
button.y = header.y + style->combo.button_padding.y; |
| 24994 |
button.h = button.w; |
| 24995 |
|
| 24996 |
content.x = button.x + style->combo.button.padding.x; |
| 24997 |
content.y = button.y + style->combo.button.padding.y; |
| 24998 |
content.w = button.w - 2 * style->combo.button.padding.x; |
| 24999 |
content.h = button.h - 2 * style->combo.button.padding.y; |
| 25000 |
|
| 25001 |
|
| 25002 |
bounds.h = header.h - 2 * style->combo.content_padding.y; |
| 25003 |
bounds.y = header.y + style->combo.content_padding.y; |
| 25004 |
bounds.x = header.x + style->combo.content_padding.x; |
| 25005 |
bounds.w = (button.x - style->combo.content_padding.y) - bounds.x; |
| 25006 |
nk_draw_image(&win->buffer, bounds, &img, nk_white); |
| 25007 |
|
| 25008 |
|
| 25009 |
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state, |
| 25010 |
&ctx->style.combo.button, sym, style->font); |
| 25011 |
} |
| 25012 |
return nk_combo_begin(ctx, win, size, is_clicked, header); |
| 25013 |
} |
| 25014 |
NK_API int |
| 25015 |
nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, |
| 25016 |
struct nk_image img, struct nk_vec2 size) |
| 25017 |
{ |
| 25018 |
struct nk_window *win; |
| 25019 |
struct nk_style *style; |
| 25020 |
struct nk_input *in; |
| 25021 |
|
| 25022 |
struct nk_rect header; |
| 25023 |
int is_clicked = nk_false; |
| 25024 |
enum nk_widget_layout_states s; |
| 25025 |
const struct nk_style_item *background; |
| 25026 |
struct nk_text text; |
| 25027 |
|
| 25028 |
NK_ASSERT(ctx); |
| 25029 |
NK_ASSERT(ctx->current); |
| 25030 |
NK_ASSERT(ctx->current->layout); |
| 25031 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 25032 |
return 0; |
| 25033 |
|
| 25034 |
win = ctx->current; |
| 25035 |
style = &ctx->style; |
| 25036 |
s = nk_widget(&header, ctx); |
| 25037 |
if (!s) return 0; |
| 25038 |
|
| 25039 |
in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; |
| 25040 |
if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) |
| 25041 |
is_clicked = nk_true; |
| 25042 |
|
| 25043 |
|
| 25044 |
if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) { |
| 25045 |
background = &style->combo.active; |
| 25046 |
text.text = style->combo.label_active; |
| 25047 |
} else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) { |
| 25048 |
background = &style->combo.hover; |
| 25049 |
text.text = style->combo.label_hover; |
| 25050 |
} else { |
| 25051 |
background = &style->combo.normal; |
| 25052 |
text.text = style->combo.label_normal; |
| 25053 |
} |
| 25054 |
if (background->type == NK_STYLE_ITEM_IMAGE) { |
| 25055 |
text.background = nk_rgba(0,0,0,0); |
| 25056 |
nk_draw_image(&win->buffer, header, &background->data.image, nk_white); |
| 25057 |
} else { |
| 25058 |
text.background = background->data.color; |
| 25059 |
nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); |
| 25060 |
nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); |
| 25061 |
} |
| 25062 |
{ |
| 25063 |
struct nk_rect content; |
| 25064 |
struct nk_rect button; |
| 25065 |
struct nk_rect label; |
| 25066 |
struct nk_rect image; |
| 25067 |
|
| 25068 |
enum nk_symbol_type sym; |
| 25069 |
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) |
| 25070 |
sym = style->combo.sym_hover; |
| 25071 |
else if (is_clicked) |
| 25072 |
sym = style->combo.sym_active; |
| 25073 |
else sym = style->combo.sym_normal; |
| 25074 |
|
| 25075 |
|
| 25076 |
button.w = header.h - 2 * style->combo.button_padding.y; |
| 25077 |
button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; |
| 25078 |
button.y = header.y + style->combo.button_padding.y; |
| 25079 |
button.h = button.w; |
| 25080 |
|
| 25081 |
content.x = button.x + style->combo.button.padding.x; |
| 25082 |
content.y = button.y + style->combo.button.padding.y; |
| 25083 |
content.w = button.w - 2 * style->combo.button.padding.x; |
| 25084 |
content.h = button.h - 2 * style->combo.button.padding.y; |
| 25085 |
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, |
| 25086 |
&ctx->style.combo.button, sym, style->font); |
| 25087 |
|
| 25088 |
|
| 25089 |
image.x = header.x + style->combo.content_padding.x; |
| 25090 |
image.y = header.y + style->combo.content_padding.y; |
| 25091 |
image.h = header.h - 2 * style->combo.content_padding.y; |
| 25092 |
image.w = image.h; |
| 25093 |
nk_draw_image(&win->buffer, image, &img, nk_white); |
| 25094 |
|
| 25095 |
|
| 25096 |
text.padding = nk_vec2(0,0); |
| 25097 |
label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x; |
| 25098 |
label.y = header.y + style->combo.content_padding.y; |
| 25099 |
label.w = (button.x - style->combo.content_padding.x) - label.x; |
| 25100 |
label.h = header.h - 2 * style->combo.content_padding.y; |
| 25101 |
nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font); |
| 25102 |
} |
| 25103 |
return nk_combo_begin(ctx, win, size, is_clicked, header); |
| 25104 |
} |
| 25105 |
NK_API int |
| 25106 |
nk_combo_begin_symbol_label(struct nk_context *ctx, |
| 25107 |
const char *selected, enum nk_symbol_type type, struct nk_vec2 size) |
| 25108 |
{ |
| 25109 |
return nk_combo_begin_symbol_text(ctx, selected, nk_strlen(selected), type, size); |
| 25110 |
} |
| 25111 |
NK_API int |
| 25112 |
nk_combo_begin_image_label(struct nk_context *ctx, |
| 25113 |
const char *selected, struct nk_image img, struct nk_vec2 size) |
| 25114 |
{ |
| 25115 |
return nk_combo_begin_image_text(ctx, selected, nk_strlen(selected), img, size); |
| 25116 |
} |
| 25117 |
NK_API int |
| 25118 |
nk_combo_item_text(struct nk_context *ctx, const char *text, int len,nk_flags align) |
| 25119 |
{ |
| 25120 |
return nk_contextual_item_text(ctx, text, len, align); |
| 25121 |
} |
| 25122 |
NK_API int |
| 25123 |
nk_combo_item_label(struct nk_context *ctx, const char *label, nk_flags align) |
| 25124 |
{ |
| 25125 |
return nk_contextual_item_label(ctx, label, align); |
| 25126 |
} |
| 25127 |
NK_API int |
| 25128 |
nk_combo_item_image_text(struct nk_context *ctx, struct nk_image img, const char *text, |
| 25129 |
int len, nk_flags alignment) |
| 25130 |
{ |
| 25131 |
return nk_contextual_item_image_text(ctx, img, text, len, alignment); |
| 25132 |
} |
| 25133 |
NK_API int |
| 25134 |
nk_combo_item_image_label(struct nk_context *ctx, struct nk_image img, |
| 25135 |
const char *text, nk_flags alignment) |
| 25136 |
{ |
| 25137 |
return nk_contextual_item_image_label(ctx, img, text, alignment); |
| 25138 |
} |
| 25139 |
NK_API int |
| 25140 |
nk_combo_item_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, |
| 25141 |
const char *text, int len, nk_flags alignment) |
| 25142 |
{ |
| 25143 |
return nk_contextual_item_symbol_text(ctx, sym, text, len, alignment); |
| 25144 |
} |
| 25145 |
NK_API int |
| 25146 |
nk_combo_item_symbol_label(struct nk_context *ctx, enum nk_symbol_type sym, |
| 25147 |
const char *label, nk_flags alignment) |
| 25148 |
{ |
| 25149 |
return nk_contextual_item_symbol_label(ctx, sym, label, alignment); |
| 25150 |
} |
| 25151 |
NK_API void nk_combo_end(struct nk_context *ctx) |
| 25152 |
{ |
| 25153 |
nk_contextual_end(ctx); |
| 25154 |
} |
| 25155 |
NK_API void nk_combo_close(struct nk_context *ctx) |
| 25156 |
{ |
| 25157 |
nk_contextual_close(ctx); |
| 25158 |
} |
| 25159 |
NK_API int |
| 25160 |
nk_combo(struct nk_context *ctx, const char **items, int count, |
| 25161 |
int selected, int item_height, struct nk_vec2 size) |
| 25162 |
{ |
| 25163 |
int i = 0; |
| 25164 |
int max_height; |
| 25165 |
struct nk_vec2 item_spacing; |
| 25166 |
struct nk_vec2 window_padding; |
| 25167 |
|
| 25168 |
NK_ASSERT(ctx); |
| 25169 |
NK_ASSERT(items); |
| 25170 |
NK_ASSERT(ctx->current); |
| 25171 |
if (!ctx || !items ||!count) |
| 25172 |
return selected; |
| 25173 |
|
| 25174 |
item_spacing = ctx->style.window.spacing; |
| 25175 |
window_padding = nk_panel_get_padding(&ctx->style, ctx->current->layout->type); |
| 25176 |
max_height = count * item_height + count * (int)item_spacing.y; |
| 25177 |
max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; |
| 25178 |
size.y = NK_MIN(size.y, (float)max_height); |
| 25179 |
if (nk_combo_begin_label(ctx, items[selected], size)) { |
| 25180 |
nk_layout_row_dynamic(ctx, (float)item_height, 1); |
| 25181 |
for (i = 0; i < count; ++i) { |
| 25182 |
if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) |
| 25183 |
selected = i; |
| 25184 |
} |
| 25185 |
nk_combo_end(ctx); |
| 25186 |
} |
| 25187 |
return selected; |
| 25188 |
} |
| 25189 |
NK_API int |
| 25190 |
nk_combo_separator(struct nk_context *ctx, const char *items_separated_by_separator, |
| 25191 |
int separator, int selected, int count, int item_height, struct nk_vec2 size) |
| 25192 |
{ |
| 25193 |
int i; |
| 25194 |
int max_height; |
| 25195 |
struct nk_vec2 item_spacing; |
| 25196 |
struct nk_vec2 window_padding; |
| 25197 |
const char *current_item; |
| 25198 |
const char *iter; |
| 25199 |
int length = 0; |
| 25200 |
|
| 25201 |
NK_ASSERT(ctx); |
| 25202 |
NK_ASSERT(items_separated_by_separator); |
| 25203 |
if (!ctx || !items_separated_by_separator) |
| 25204 |
return selected; |
| 25205 |
|
| 25206 |
|
| 25207 |
item_spacing = ctx->style.window.spacing; |
| 25208 |
window_padding = nk_panel_get_padding(&ctx->style, ctx->current->layout->type); |
| 25209 |
max_height = count * item_height + count * (int)item_spacing.y; |
| 25210 |
max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; |
| 25211 |
size.y = NK_MIN(size.y, (float)max_height); |
| 25212 |
|
| 25213 |
|
| 25214 |
current_item = items_separated_by_separator; |
| 25215 |
for (i = 0; i < count; ++i) { |
| 25216 |
iter = current_item; |
| 25217 |
while (*iter && *iter != separator) iter++; |
| 25218 |
length = (int)(iter - current_item); |
| 25219 |
if (i == selected) break; |
| 25220 |
current_item = iter + 1; |
| 25221 |
} |
| 25222 |
|
| 25223 |
if (nk_combo_begin_text(ctx, current_item, length, size)) { |
| 25224 |
current_item = items_separated_by_separator; |
| 25225 |
nk_layout_row_dynamic(ctx, (float)item_height, 1); |
| 25226 |
for (i = 0; i < count; ++i) { |
| 25227 |
iter = current_item; |
| 25228 |
while (*iter && *iter != separator) iter++; |
| 25229 |
length = (int)(iter - current_item); |
| 25230 |
if (nk_combo_item_text(ctx, current_item, length, NK_TEXT_LEFT)) |
| 25231 |
selected = i; |
| 25232 |
current_item = current_item + length + 1; |
| 25233 |
} |
| 25234 |
nk_combo_end(ctx); |
| 25235 |
} |
| 25236 |
return selected; |
| 25237 |
} |
| 25238 |
NK_API int |
| 25239 |
nk_combo_string(struct nk_context *ctx, const char *items_separated_by_zeros, |
| 25240 |
int selected, int count, int item_height, struct nk_vec2 size) |
| 25241 |
{ |
| 25242 |
return nk_combo_separator(ctx, items_separated_by_zeros, '\0', selected, count, item_height, size); |
| 25243 |
} |
| 25244 |
NK_API int |
| 25245 |
nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const char**), |
| 25246 |
void *userdata, int selected, int count, int item_height, struct nk_vec2 size) |
| 25247 |
{ |
| 25248 |
int i; |
| 25249 |
int max_height; |
| 25250 |
struct nk_vec2 item_spacing; |
| 25251 |
struct nk_vec2 window_padding; |
| 25252 |
const char *item; |
| 25253 |
|
| 25254 |
NK_ASSERT(ctx); |
| 25255 |
NK_ASSERT(item_getter); |
| 25256 |
if (!ctx || !item_getter) |
| 25257 |
return selected; |
| 25258 |
|
| 25259 |
|
| 25260 |
item_spacing = ctx->style.window.spacing; |
| 25261 |
window_padding = nk_panel_get_padding(&ctx->style, ctx->current->layout->type); |
| 25262 |
max_height = count * item_height + count * (int)item_spacing.y; |
| 25263 |
max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; |
| 25264 |
size.y = NK_MIN(size.y, (float)max_height); |
| 25265 |
|
| 25266 |
item_getter(userdata, selected, &item); |
| 25267 |
if (nk_combo_begin_label(ctx, item, size)) { |
| 25268 |
nk_layout_row_dynamic(ctx, (float)item_height, 1); |
| 25269 |
for (i = 0; i < count; ++i) { |
| 25270 |
item_getter(userdata, i, &item); |
| 25271 |
if (nk_combo_item_label(ctx, item, NK_TEXT_LEFT)) |
| 25272 |
selected = i; |
| 25273 |
} |
| 25274 |
nk_combo_end(ctx); |
| 25275 |
} return selected; |
| 25276 |
} |
| 25277 |
NK_API void |
| 25278 |
nk_combobox(struct nk_context *ctx, const char **items, int count, |
| 25279 |
int *selected, int item_height, struct nk_vec2 size) |
| 25280 |
{ |
| 25281 |
*selected = nk_combo(ctx, items, count, *selected, item_height, size); |
| 25282 |
} |
| 25283 |
NK_API void |
| 25284 |
nk_combobox_string(struct nk_context *ctx, const char *items_separated_by_zeros, |
| 25285 |
int *selected, int count, int item_height, struct nk_vec2 size) |
| 25286 |
{ |
| 25287 |
*selected = nk_combo_string(ctx, items_separated_by_zeros, *selected, count, item_height, size); |
| 25288 |
} |
| 25289 |
NK_API void |
| 25290 |
nk_combobox_separator(struct nk_context *ctx, const char *items_separated_by_separator, |
| 25291 |
int separator,int *selected, int count, int item_height, struct nk_vec2 size) |
| 25292 |
{ |
| 25293 |
*selected = nk_combo_separator(ctx, items_separated_by_separator, separator, |
| 25294 |
*selected, count, item_height, size); |
| 25295 |
} |
| 25296 |
NK_API void |
| 25297 |
nk_combobox_callback(struct nk_context *ctx, |
| 25298 |
void(*item_getter)(void* data, int id, const char **out_text), |
| 25299 |
void *userdata, int *selected, int count, int item_height, struct nk_vec2 size) |
| 25300 |
{ |
| 25301 |
*selected = nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size); |
| 25302 |
} |
| 25303 |
|
| 25304 |
|
| 25305 |
|
| 25306 |
|
| 25307 |
|
| 25308 |
|
| 25309 |
|
| 25310 |
|
| 25311 |
|
| 25312 |
|
| 25313 |
NK_API int |
| 25314 |
nk_tooltip_begin(struct nk_context *ctx, float width) |
| 25315 |
{ |
| 25316 |
int x,y,w,h; |
| 25317 |
struct nk_window *win; |
| 25318 |
const struct nk_input *in; |
| 25319 |
struct nk_rect bounds; |
| 25320 |
int ret; |
| 25321 |
|
| 25322 |
NK_ASSERT(ctx); |
| 25323 |
NK_ASSERT(ctx->current); |
| 25324 |
NK_ASSERT(ctx->current->layout); |
| 25325 |
if (!ctx || !ctx->current || !ctx->current->layout) |
| 25326 |
return 0; |
| 25327 |
|
| 25328 |
|
| 25329 |
win = ctx->current; |
| 25330 |
in = &ctx->input; |
| 25331 |
if (win->popup.win && (win->popup.type & NK_PANEL_SET_NONBLOCK)) |
| 25332 |
return 0; |
| 25333 |
|
| 25334 |
w = nk_iceilf(width); |
| 25335 |
h = nk_iceilf(nk_null_rect.h); |
| 25336 |
x = nk_ifloorf(in->mouse.pos.x + 1) - (int)win->layout->clip.x; |
| 25337 |
y = nk_ifloorf(in->mouse.pos.y + 1) - (int)win->layout->clip.y; |
| 25338 |
|
| 25339 |
bounds.x = (float)x; |
| 25340 |
bounds.y = (float)y; |
| 25341 |
bounds.w = (float)w; |
| 25342 |
bounds.h = (float)h; |
| 25343 |
|
| 25344 |
ret = nk_popup_begin(ctx, NK_POPUP_DYNAMIC, |
| 25345 |
"__##Tooltip##__", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER, bounds); |
| 25346 |
if (ret) win->layout->flags &= ~(nk_flags)NK_WINDOW_ROM; |
| 25347 |
win->popup.type = NK_PANEL_TOOLTIP; |
| 25348 |
ctx->current->layout->type = NK_PANEL_TOOLTIP; |
| 25349 |
return ret; |
| 25350 |
} |
| 25351 |
|
| 25352 |
NK_API void |
| 25353 |
nk_tooltip_end(struct nk_context *ctx) |
| 25354 |
{ |
| 25355 |
NK_ASSERT(ctx); |
| 25356 |
NK_ASSERT(ctx->current); |
| 25357 |
if (!ctx || !ctx->current) return; |
| 25358 |
ctx->current->seq--; |
| 25359 |
nk_popup_close(ctx); |
| 25360 |
nk_popup_end(ctx); |
| 25361 |
} |
| 25362 |
NK_API void |
| 25363 |
nk_tooltip(struct nk_context *ctx, const char *text) |
| 25364 |
{ |
| 25365 |
const struct nk_style *style; |
| 25366 |
struct nk_vec2 padding; |
| 25367 |
|
| 25368 |
int text_len; |
| 25369 |
float text_width; |
| 25370 |
float text_height; |
| 25371 |
|
| 25372 |
NK_ASSERT(ctx); |
| 25373 |
NK_ASSERT(ctx->current); |
| 25374 |
NK_ASSERT(ctx->current->layout); |
| 25375 |
NK_ASSERT(text); |
| 25376 |
if (!ctx || !ctx->current || !ctx->current->layout || !text) |
| 25377 |
return; |
| 25378 |
|
| 25379 |
|
| 25380 |
style = &ctx->style; |
| 25381 |
padding = style->window.padding; |
| 25382 |
|
| 25383 |
|
| 25384 |
text_len = nk_strlen(text); |
| 25385 |
text_width = style->font->width(style->font->userdata, |
| 25386 |
style->font->height, text, text_len); |
| 25387 |
text_width += (4 * padding.x); |
| 25388 |
text_height = (style->font->height + 2 * padding.y); |
| 25389 |
|
| 25390 |
|
| 25391 |
if (nk_tooltip_begin(ctx, (float)text_width)) { |
| 25392 |
nk_layout_row_dynamic(ctx, (float)text_height, 1); |
| 25393 |
nk_text(ctx, text, text_len, NK_TEXT_LEFT); |
| 25394 |
nk_tooltip_end(ctx); |
| 25395 |
} |
| 25396 |
} |
| 25397 |
#ifdef NK_INCLUDE_STANDARD_VARARGS |
| 25398 |
NK_API void |
| 25399 |
nk_tooltipf(struct nk_context *ctx, const char *fmt, ...) |
| 25400 |
{ |
| 25401 |
va_list args; |
| 25402 |
va_start(args, fmt); |
| 25403 |
nk_tooltipfv(ctx, fmt, args); |
| 25404 |
va_end(args); |
| 25405 |
} |
| 25406 |
NK_API void |
| 25407 |
nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) |
| 25408 |
{ |
| 25409 |
char buf[256]; |
| 25410 |
nk_strfmt(buf, NK_LEN(buf), fmt, args); |
| 25411 |
nk_tooltip(ctx, buf); |
| 25412 |
} |
| 25413 |
#endif |
| 25414 |
|
| 25415 |
|
| 25416 |
|
| 25417 |
#endif |
| 25418 |
|
| 25419 |
|
| 25420 |
|
| 25421 |
|
| 25422 |
|
| 25423 |
|
| 25424 |
|
| 25425 |
|
| 25426 |
|
| 25427 |
|
| 25428 |
|
| 25429 |
|
| 25430 |
|
| 25431 |
|
| 25432 |
|
| 25433 |
|
| 25434 |
|
| 25435 |
|
| 25436 |
|
| 25437 |
|
| 25438 |
|
| 25439 |
|
| 25440 |
|
| 25441 |
|
| 25442 |
|
| 25443 |
|
| 25444 |
|
| 25445 |
|
| 25446 |
|
| 25447 |
|
| 25448 |
|
| 25449 |
|
| 25450 |
|
| 25451 |
|
| 25452 |
|
| 25453 |
|
| 25454 |
|
| 25455 |
|
| 25456 |
|
| 25457 |
|
| 25458 |
|
| 25459 |
|
| 25460 |
|
| 25461 |
|
| 25462 |
|
| 25463 |
|
| 25464 |
|
| 25465 |
|
| 25466 |
|
| 25467 |
|
| 25468 |
|
| 25469 |
|
| 25470 |
|
| 25471 |
|
| 25472 |
|
| 25473 |
|
| 25474 |
|
| 25475 |
|
| 25476 |
|
| 25477 |
|
| 25478 |
|
| 25479 |
|
| 25480 |
|
| 25481 |
|
| 25482 |
|
| 25483 |
|
| 25484 |
|
| 25485 |
|
| 25486 |
|
| 25487 |
|
| 25488 |
|
| 25489 |
|
| 25490 |
|
| 25491 |
|
| 25492 |
|
| 25493 |
|
| 25494 |
|
| 25495 |
|
| 25496 |
|
| 25497 |
|
| 25498 |
|
| 25499 |
|
| 25500 |
|
| 25501 |
|
| 25502 |
|
| 25503 |
|
| 25504 |
|
| 25505 |
|
| 25506 |
|
| 25507 |
|
| 25508 |
|
| 25509 |
|
| 25510 |
|
| 25511 |
|
| 25512 |
|
| 25513 |
|
| 25514 |
|
| 25515 |
|
| 25516 |
|
| 25517 |
|
| 25518 |
|
| 25519 |
|
| 25520 |
|
| 25521 |
|
| 25522 |
|
| 25523 |
|
| 25524 |
|
| 25525 |
|
| 25526 |
|
| 25527 |
|
| 25528 |
|
| 25529 |
|
| 25530 |
|
| 25531 |
|
| 25532 |
|
| 25533 |
|
| 25534 |
|
| 25535 |
|
| 25536 |
|
| 25537 |
|
| 25538 |
|
| 25539 |
|
| 25540 |
|
| 25541 |
|
| 25542 |
|
| 25543 |
|
| 25544 |
|
| 25545 |
|
| 25546 |
|
| 25547 |
|
| 25548 |
|
| 25549 |
|
| 25550 |
|
| 25551 |
|
| 25552 |
|
| 25553 |
|
| 25554 |
|
| 25555 |
|
| 25556 |
|
| 25557 |
|
| 25558 |
|
| 25559 |
|
| 25560 |
|
| 25561 |
|
| 25562 |
|
| 25563 |
|
| 25564 |
|
| 25565 |
|
| 25566 |
|
| 25567 |
|
| 25568 |
|
| 25569 |
|
| 25570 |
|
| 25571 |
|
| 25572 |
|
| 25573 |
|
| 25574 |
|
| 25575 |
|
| 25576 |
|
| 25577 |
|
| 25578 |
|
| 25579 |
|
| 25580 |
|
| 25581 |
|
| 25582 |
|
| 25583 |
|
| 25584 |
|
| 25585 |
|
| 25586 |
|
| 25587 |
|
| 25588 |
|
| 25589 |
|
| 25590 |
|
| 25591 |
|
| 25592 |
|
| 25593 |
|
| 25594 |
|
| 25595 |
|
| 25596 |
|
| 25597 |
|
| 25598 |
|
| 25599 |
|
| 25600 |
|
| 25601 |
|
| 25602 |
|
| 25603 |
|
| 25604 |
|
| 25605 |
|
| 25606 |
|
| 25607 |
|
| 25608 |
|
| 25609 |
|
| 25610 |
|
| 25611 |
|
| 25612 |
|
| 25613 |
|
| 25614 |
|
| 25615 |
|
| 25616 |
|
| 25617 |
|
| 25618 |
|
| 25619 |
|
| 25620 |
|
| 25621 |
|
| 25622 |
|
| 25623 |
|
| 25624 |
|
| 25625 |
|
| 25626 |
|
| 25627 |
|
| 25628 |
|
| 25629 |
|
| 25630 |
|
| 25631 |
|
| 25632 |
|
| 25633 |
|
| 25634 |
|
| 25635 |
|
| 25636 |
|
| 25637 |
|
| 25638 |
|
| 25639 |
|
| 25640 |
|
| 25641 |
|
| 25642 |
|
| 25643 |
|
| 25644 |
|
| 25645 |
|
| 25646 |
|
| 25647 |
|
| 25648 |
|
| 25649 |
|
| 25650 |
|
| 25651 |
|
| 25652 |
|
| 25653 |
|
| 25654 |
|
| 25655 |
|
| 25656 |
|
| 25657 |
|
| 25658 |
|
| 25659 |
|
| 25660 |
|
| 25661 |
|
| 25662 |
|
| 25663 |
|
| 25664 |
|
| 25665 |
|
| 25666 |
|
| 25667 |
|
| 25668 |
|
| 25669 |
|
| 25670 |
|
| 25671 |
|
| 25672 |
|
| 25673 |
|
| 25674 |
|
| 25675 |
|
| 25676 |
|
| 25677 |
|
| 25678 |
|
| 25679 |
|
| 25680 |
|
| 25681 |
|
| 25682 |
|
| 25683 |
|
| 25684 |
|
| 25685 |
|
| 25686 |
|
| 25687 |
|
| 25688 |
|
| 25689 |
|
| 25690 |
|
| 25691 |
|
| 25692 |
|
| 25693 |
|
| 25694 |
|
| 25695 |
|
| 25696 |
|
| 25697 |
|
| 25698 |
|
| 25699 |
|
| 25700 |
|
| 25701 |
|
| 25702 |
|
| 25703 |
|
| 25704 |
|
| 25705 |
|
| 25706 |
|
| 25707 |
|
| 25708 |
|
| 25709 |
|
| 25710 |
|
| 25711 |
|
| 25712 |
|
| 25713 |
|
| 25714 |
|
| 25715 |
|
| 25716 |
|
| 25717 |
|
| 25718 |
|
| 25719 |
|
| 25720 |
|
| 25721 |
|
| 25722 |
|
| 25723 |
|
| 25724 |
|
| 25725 |
|
| 25726 |
|
| 25727 |
|
| 25728 |
|
| 25729 |
|
| 25730 |
|
| 25731 |
|
| 25732 |
|
| 25733 |
|
| 25734 |
|
| 25735 |
|
| 25736 |
|
| 25737 |
|
| 25738 |
|
| 25739 |
|
| 25740 |
|
| 25741 |
|
| 25742 |
|
| 25743 |
|
| 25744 |
|
| 25745 |
|
| 25746 |
|
| 25747 |
|
| 25748 |
|
| 25749 |
|
| 25750 |
|
| 25751 |
|
| 25752 |
|
| 25753 |
|
| 25754 |
|
| 25755 |
|
| 25756 |
|
| 25757 |
|
| 25758 |
|
| 25759 |
|
| 25760 |
|
| 25761 |
|
| 25762 |
|
| 25763 |
|
| 25764 |
|
| 25765 |
|
| 25766 |
|
| 25767 |
|
| 25768 |
|
| 25769 |
|
| 25770 |
|
| 25771 |
|
| 25772 |
|
| 25773 |
|
| 25774 |
|
| 25775 |
|
| 25776 |
|
| 25777 |
|