raylib-nuklear-font-default.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**********************************************************************************************
  2. *
  3. * raylib-nuklear-font - Example of using Nuklear with a custom Raylib font.
  4. *
  5. * LICENSE: zlib/libpng
  6. *
  7. * raylib-nuklear is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software:
  9. *
  10. * Copyright (c) 2020 Rob Loach (@RobLoach)
  11. *
  12. * This software is provided "as-is", without any express or implied warranty. In no event
  13. * will the authors be held liable for any damages arising from the use of this software.
  14. *
  15. * Permission is granted to anyone to use this software for any purpose, including commercial
  16. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  17. *
  18. * 1. The origin of this software must not be misrepresented; you must not claim that you
  19. * wrote the original software. If you use this software in a product, an acknowledgment
  20. * in the product documentation would be appreciated but is not required.
  21. *
  22. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  23. * as being the original software.
  24. *
  25. * 3. This notice may not be removed or altered from any source distribution.
  26. *
  27. **********************************************************************************************/
  28. #include "raylib.h"
  29. #define RAYLIB_NUKLEAR_IMPLEMENTATION
  30. #define RAYLIB_NUKLEAR_INCLUDE_DEFAULT_FONT
  31. #include "raylib-nuklear.h"
  32. int main(void)
  33. {
  34. // Initialization
  35. //--------------------------------------------------------------------------------------
  36. const int screenWidth = 800;
  37. const int screenHeight = 450;
  38. const int fontSize = 14;
  39. InitWindow(screenWidth, screenHeight, "[raylib-nuklear] font example");
  40. Font font = LoadFontFromNuklear(0);
  41. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  42. //--------------------------------------------------------------------------------------
  43. /* GUI */
  44. struct nk_colorf bg = ColorToNuklearF(SKYBLUE);
  45. struct nk_context *ctx = InitNuklearEx(font, 0);
  46. // Main game loop
  47. while (!WindowShouldClose()) // Detect window close button or ESC key
  48. {
  49. // Update
  50. UpdateNuklear(ctx);
  51. // GUI
  52. if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
  53. NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
  54. NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
  55. {
  56. enum {EASY, HARD};
  57. static int op = EASY;
  58. static int property = 20;
  59. nk_layout_row_static(ctx, 30, 80, 1);
  60. if (nk_button_label(ctx, "button"))
  61. TraceLog(LOG_INFO, "button pressed");
  62. nk_layout_row_dynamic(ctx, 30, 2);
  63. if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
  64. if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
  65. nk_layout_row_dynamic(ctx, 25, 1);
  66. nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
  67. nk_layout_row_dynamic(ctx, 20, 1);
  68. nk_label(ctx, "background:", NK_TEXT_LEFT);
  69. nk_layout_row_dynamic(ctx, 25, 1);
  70. if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) {
  71. nk_layout_row_dynamic(ctx, 120, 1);
  72. bg = nk_color_picker(ctx, bg, NK_RGBA);
  73. nk_layout_row_dynamic(ctx, 25, 1);
  74. bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
  75. bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
  76. bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
  77. bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
  78. nk_combo_end(ctx);
  79. }
  80. }
  81. nk_end(ctx);
  82. // Draw
  83. //----------------------------------------------------------------------------------
  84. BeginDrawing();
  85. ClearBackground(ColorFromNuklearF(bg));
  86. DrawNuklear(ctx);
  87. EndDrawing();
  88. //----------------------------------------------------------------------------------
  89. }
  90. // De-Initialization
  91. //--------------------------------------------------------------------------------------
  92. UnloadNuklear(ctx); // Unload the Nuklear GUI
  93. UnloadFont(font);
  94. CloseWindow();
  95. //--------------------------------------------------------------------------------------
  96. return 0;
  97. }