rlImGui.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /**********************************************************************************************
  2. *
  3. * raylibExtras * Utilities and Shared Components for Raylib
  4. *
  5. * rlImGui * basic ImGui integration
  6. *
  7. * LICENSE: ZLIB
  8. *
  9. * Copyright (c) 2024 Jeffery Myers
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a copy
  12. * of this software and associated documentation files (the "Software"), to deal
  13. * in the Software without restriction, including without limitation the rights
  14. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. * copies of the Software, and to permit persons to whom the Software is
  16. * furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in all
  19. * copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27. * SOFTWARE.
  28. *
  29. **********************************************************************************************/
  30. #pragma once
  31. #include "raylib.h"
  32. // Function specifiers in case library is build/used as a shared library
  33. // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
  34. // NOTE: visibility("default") attribute makes symbols "visible" when compiled with -fvisibility=hidden
  35. #if defined(_WIN32)
  36. #if defined(__TINYC__)
  37. #define __declspec(x) __attribute__((x))
  38. #endif
  39. #if defined(BUILD_LIBTYPE_SHARED)
  40. #define RLIMGUIAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
  41. #elif defined(USE_LIBTYPE_SHARED)
  42. #define RLIMGUIAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
  43. #endif
  44. #else
  45. #if defined(BUILD_LIBTYPE_SHARED)
  46. #define RLIMGUIAPI __attribute__((visibility("default"))) // We are building as a Unix shared library (.so/.dylib)
  47. #endif
  48. #endif
  49. #ifndef RLIMGUIAPI
  50. #define RLIMGUIAPI // Functions defined as 'extern' by default (implicit specifiers)
  51. #endif
  52. #ifndef NO_FONT_AWESOME
  53. #include "extras/IconsFontAwesome6.h"
  54. #ifndef FONT_AWESOME_ICON_SIZE
  55. #define FONT_AWESOME_ICON_SIZE 11
  56. #endif
  57. #endif
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. // High level API. This API is designed in the style of raylib and meant to work with reaylib code.
  62. // It will manage it's own ImGui context and call common ImGui functions (like NewFrame and Render) for you
  63. // for a lower level API that matches the other ImGui platforms, please see imgui_impl_raylib.h
  64. /// <summary>
  65. /// Sets up ImGui, loads fonts and themes
  66. /// Calls ImGui_ImplRaylib_Init and sets the theme. Will install Font awesome by default
  67. /// </summary>
  68. /// <param name="darkTheme">when true(default) the dark theme is used, when false the light theme is used</param>
  69. RLIMGUIAPI void rlImGuiSetup(bool darkTheme);
  70. /// <summary>
  71. /// Starts a new ImGui Frame
  72. /// Calls ImGui_ImplRaylib_NewFrame, ImGui_ImplRaylib_ProcessEvents, and ImGui::NewFrame together
  73. /// </summary>
  74. RLIMGUIAPI void rlImGuiBegin(void);
  75. /// <summary>
  76. /// Ends an ImGui frame and submits all ImGui drawing to raylib for processing.
  77. /// Calls ImGui:Render, an d ImGui_ImplRaylib_RenderDrawData to draw to the current raylib render target
  78. /// </summary>
  79. RLIMGUIAPI void rlImGuiEnd(void);
  80. /// <summary>
  81. /// Cleanup ImGui and unload font atlas
  82. /// Calls ImGui_ImplRaylib_Shutdown
  83. /// </summary>
  84. RLIMGUIAPI void rlImGuiShutdown(void);
  85. // Advanced StartupAPI
  86. /// <summary>
  87. /// Custom initialization. Not needed if you call rlImGuiSetup. Only needed if you want to add custom setup code.
  88. /// must be followed by rlImGuiEndInitImGui
  89. /// Called by ImGui_ImplRaylib_Init, and does the first part of setup, before fonts are rendered
  90. /// </summary>
  91. RLIMGUIAPI void rlImGuiBeginInitImGui(void);
  92. /// <summary>
  93. /// End Custom initialization. Not needed if you call rlImGuiSetup. Only needed if you want to add custom setup code.
  94. /// must be proceeded by rlImGuiBeginInitImGui
  95. /// Called by ImGui_ImplRaylib_Init and does the second part of setup, and renders fonts.
  96. /// </summary>
  97. RLIMGUIAPI void rlImGuiEndInitImGui(void);
  98. // Advanced Update API
  99. /// <summary>
  100. /// Starts a new ImGui Frame with a specified delta time
  101. /// </summary>
  102. /// <param name="dt">delta time, any value < 0 will use raylib GetFrameTime</param>
  103. RLIMGUIAPI void rlImGuiBeginDelta(float deltaTime);
  104. // ImGui Image API extensions
  105. // Purely for convenience in working with raylib textures as images.
  106. // If you want to call ImGui image functions directly, simply pass them the pointer to the texture.
  107. /// <summary>
  108. /// Draw a texture as an image in an ImGui Context
  109. /// Uses the current ImGui Cursor position and the full texture size.
  110. /// </summary>
  111. /// <param name="image">The raylib texture to draw</param>
  112. RLIMGUIAPI void rlImGuiImage(const Texture *image);
  113. /// <summary>
  114. /// Draw a texture as an image in an ImGui Context at a specific size
  115. /// Uses the current ImGui Cursor position and the specified width and height
  116. /// The image will be scaled up or down to fit as needed
  117. /// </summary>
  118. /// <param name="image">The raylib texture to draw</param>
  119. /// <param name="width">The width of the drawn image</param>
  120. /// <param name="height">The height of the drawn image</param>
  121. RLIMGUIAPI void rlImGuiImageSize(const Texture *image, int width, int height);
  122. /// <summary>
  123. /// Draw a texture as an image in an ImGui Context at a specific size
  124. /// Uses the current ImGui Cursor position and the specified size
  125. /// The image will be scaled up or down to fit as needed
  126. /// </summary>
  127. /// <param name="image">The raylib texture to draw</param>
  128. /// <param name="size">The size of drawn image</param>
  129. RLIMGUIAPI void rlImGuiImageSizeV(const Texture* image, Vector2 size);
  130. /// <summary>
  131. /// Draw a portion texture as an image in an ImGui Context at a defined size
  132. /// Uses the current ImGui Cursor position and the specified size
  133. /// The image will be scaled up or down to fit as needed
  134. /// </summary>
  135. /// <param name="image">The raylib texture to draw</param>
  136. /// <param name="destWidth">The width of the drawn image</param>
  137. /// <param name="destHeight">The height of the drawn image</param>
  138. /// <param name="sourceRect">The portion of the texture to draw as an image. Negative values for the width and height will flip the image</param>
  139. RLIMGUIAPI void rlImGuiImageRect(const Texture* image, int destWidth, int destHeight, Rectangle sourceRect);
  140. /// <summary>
  141. /// Draws a render texture as an image an ImGui Context, automatically flipping the Y axis so it will show correctly on screen
  142. /// </summary>
  143. /// <param name="image">The render texture to draw</param>
  144. RLIMGUIAPI void rlImGuiImageRenderTexture(const RenderTexture* image);
  145. /// <summary>
  146. /// Draws a render texture as an image an ImGui Context, automatically flipping the Y axis so it will show correctly on screen
  147. /// Fits the render texture to the available content area
  148. /// </summary>
  149. /// <param name="image">The render texture to draw</param>
  150. /// <param name="center">When true the image will be centered in the content area</param>
  151. RLIMGUIAPI void rlImGuiImageRenderTextureFit(const RenderTexture* image, bool center);
  152. /// <summary>
  153. /// Draws a texture as an image button in an ImGui context. Uses the current ImGui cursor position and the full size of the texture
  154. /// </summary>
  155. /// <param name="name">The display name and ImGui ID for the button</param>
  156. /// <param name="image">The texture to draw</param>
  157. /// <returns>True if the button was clicked</returns>
  158. bool rlImGuiImageButton(const char* name, const Texture* image);
  159. /// <summary>
  160. /// Draws a texture as an image button in an ImGui context. Uses the current ImGui cursor position and the specified size.
  161. /// </summary>
  162. /// <param name="name">The display name and ImGui ID for the button</param>
  163. /// <param name="image">The texture to draw</param>
  164. /// <param name="size">The size of the button</param>
  165. /// <returns>True if the button was clicked</returns>
  166. RLIMGUIAPI bool rlImGuiImageButtonSize(const char* name, const Texture* image, Vector2 size);
  167. #ifdef __cplusplus
  168. }
  169. #endif