raylib-nuklear-demo.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* nuklear - 1.32.0 - public domain */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <stdarg.h>
  6. #include <string.h>
  7. #include <math.h>
  8. #include <assert.h>
  9. #include <math.h>
  10. #include <limits.h>
  11. #include <time.h>
  12. #include "raylib.h"
  13. //#define NK_INCLUDE_FIXED_TYPES
  14. //#define NK_INCLUDE_STANDARD_IO
  15. #define NK_INCLUDE_STANDARD_VARARGS
  16. //#define NK_INCLUDE_DEFAULT_ALLOCATOR
  17. //#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
  18. //#define NK_INCLUDE_FONT_BAKING
  19. //#define NK_INCLUDE_DEFAULT_FONT
  20. #define RAYLIB_NUKLEAR_IMPLEMENTATION
  21. #include "raylib-nuklear.h"
  22. #define WINDOW_WIDTH 1200
  23. #define WINDOW_HEIGHT 800
  24. /* ===============================================================
  25. *
  26. * EXAMPLE
  27. *
  28. * ===============================================================*/
  29. /* This are some code examples to provide a small overview of what can be
  30. * done with this library. To try out an example uncomment the defines */
  31. #define INCLUDE_ALL
  32. /*#define INCLUDE_STYLE */
  33. /*#define INCLUDE_CALCULATOR */
  34. /*#define INCLUDE_CANVAS */
  35. /*#define INCLUDE_OVERVIEW */
  36. /*#define INCLUDE_NODE_EDITOR */
  37. #ifdef INCLUDE_ALL
  38. //#define INCLUDE_STYLE
  39. #define INCLUDE_CALCULATOR
  40. #define INCLUDE_CANVAS
  41. #define INCLUDE_OVERVIEW
  42. #define INCLUDE_NODE_EDITOR
  43. #endif
  44. #ifdef INCLUDE_STYLE
  45. #include "../vendor/nuklear/demo/style.c"
  46. #endif
  47. #ifdef INCLUDE_CALCULATOR
  48. #include "../vendor/nuklear/demo/common/calculator.c"
  49. #endif
  50. #ifdef INCLUDE_CANVAS
  51. #include "../vendor/nuklear/demo/common/canvas.c"
  52. #endif
  53. #ifdef INCLUDE_OVERVIEW
  54. #include "../vendor/nuklear/demo/common/overview.c"
  55. #endif
  56. #ifdef INCLUDE_NODE_EDITOR
  57. #include "../vendor/nuklear/demo/common/node_editor.c"
  58. #endif
  59. /* ===============================================================
  60. *
  61. * DEMO
  62. *
  63. * ===============================================================*/
  64. int main(void)
  65. {
  66. struct nk_context *ctx;
  67. struct nk_colorf bg;
  68. /* Platform */
  69. InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "[raylib-nuklear] demo");
  70. SetTargetFPS(60);
  71. /* GUI */
  72. ctx = InitNuklear(10);
  73. /* style.c */
  74. #ifdef INCLUDE_STYLE
  75. /*set_style(ctx, THEME_WHITE);*/
  76. /*set_style(ctx, THEME_RED);*/
  77. /*set_style(ctx, THEME_BLUE);*/
  78. /*set_style(ctx, THEME_DARK);*/
  79. #endif
  80. bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
  81. while (!WindowShouldClose())
  82. {
  83. /* Input */
  84. UpdateNuklear(ctx);
  85. /* GUI */
  86. if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
  87. NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
  88. NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
  89. {
  90. enum {EASY, HARD};
  91. static int op = EASY;
  92. static int property = 20;
  93. nk_layout_row_static(ctx, 30, 80, 1);
  94. if (nk_button_label(ctx, "button"))
  95. TraceLog(LOG_INFO, "button pressed!");
  96. nk_layout_row_dynamic(ctx, 30, 2);
  97. if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
  98. if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
  99. nk_layout_row_dynamic(ctx, 22, 1);
  100. nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
  101. nk_layout_row_dynamic(ctx, 20, 1);
  102. nk_label(ctx, "background:", NK_TEXT_LEFT);
  103. nk_layout_row_dynamic(ctx, 25, 1);
  104. if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) {
  105. nk_layout_row_dynamic(ctx, 120, 1);
  106. bg = nk_color_picker(ctx, bg, NK_RGBA);
  107. nk_layout_row_dynamic(ctx, 25, 1);
  108. bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
  109. bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
  110. bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
  111. bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
  112. nk_combo_end(ctx);
  113. }
  114. }
  115. nk_end(ctx);
  116. /* -------------- EXAMPLES ---------------- */
  117. #ifdef INCLUDE_CALCULATOR
  118. calculator(ctx);
  119. #endif
  120. #ifdef INCLUDE_CANVAS
  121. canvas(ctx);
  122. #endif
  123. #ifdef INCLUDE_OVERVIEW
  124. overview(ctx);
  125. #endif
  126. #ifdef INCLUDE_NODE_EDITOR
  127. node_editor(ctx);
  128. #endif
  129. /* ----------------------------------------- */
  130. /* Draw */
  131. BeginDrawing();
  132. {
  133. ClearBackground(ColorFromNuklearF(bg));
  134. DrawNuklear(ctx);
  135. }
  136. EndDrawing();
  137. }
  138. UnloadNuklear(ctx); // Unload the Nuklear GUI
  139. CloseWindow();
  140. return 0;
  141. }