rlImGui.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #ifndef NO_FONT_AWESOME
  33. #include "extras/IconsFontAwesome6.h"
  34. #define FONT_AWESOME_ICON_SIZE 11
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. // High level API. This API is designed in the style of raylib and meant to work with reaylib code.
  40. // It will manage it's own ImGui context and call common ImGui functions (like NewFrame and Render) for you
  41. // for a lower level API that matches the other ImGui platforms, please see imgui_impl_raylib.h
  42. /// <summary>
  43. /// Sets up ImGui, loads fonts and themes
  44. /// Calls ImGui_ImplRaylib_Init and sets the theme. Will install Font awesome by default
  45. /// </summary>
  46. /// <param name="darkTheme">when true(default) the dark theme is used, when false the light theme is used</param>
  47. void rlImGuiSetup(bool darkTheme);
  48. /// <summary>
  49. /// Starts a new ImGui Frame
  50. /// Calls ImGui_ImplRaylib_NewFrame, ImGui_ImplRaylib_ProcessEvents, and ImGui::NewFrame together
  51. /// </summary>
  52. void rlImGuiBegin(void);
  53. /// <summary>
  54. /// Ends an ImGui frame and submits all ImGui drawing to raylib for processing.
  55. /// Calls ImGui:Render, an d ImGui_ImplRaylib_RenderDrawData to draw to the current raylib render target
  56. /// </summary>
  57. void rlImGuiEnd(void);
  58. /// <summary>
  59. /// Cleanup ImGui and unload font atlas
  60. /// Calls ImGui_ImplRaylib_Shutdown
  61. /// </summary>
  62. void rlImGuiShutdown(void);
  63. // Advanced StartupAPI
  64. /// <summary>
  65. /// Custom initialization. Not needed if you call rlImGuiSetup. Only needed if you want to add custom setup code.
  66. /// must be followed by rlImGuiEndInitImGui
  67. /// Called by ImGui_ImplRaylib_Init, and does the first part of setup, before fonts are rendered
  68. /// </summary>
  69. void rlImGuiBeginInitImGui(void);
  70. /// <summary>
  71. /// End Custom initialization. Not needed if you call rlImGuiSetup. Only needed if you want to add custom setup code.
  72. /// must be proceeded by rlImGuiBeginInitImGui
  73. /// Called by ImGui_ImplRaylib_Init and does the second part of setup, and renders fonts.
  74. /// </summary>
  75. void rlImGuiEndInitImGui(void);
  76. /// <summary>
  77. /// Forces the font texture atlas to be recomputed and re-cached
  78. /// </summary>
  79. void rlImGuiReloadFonts(void);
  80. // Advanced Update API
  81. /// <summary>
  82. /// Starts a new ImGui Frame with a specified delta time
  83. /// </summary>
  84. /// <param name="dt">delta time, any value < 0 will use raylib GetFrameTime</param>
  85. void rlImGuiBeginDelta(float deltaTime);
  86. // ImGui Image API extensions
  87. // Purely for convenience in working with raylib textures as images.
  88. // If you want to call ImGui image functions directly, simply pass them the pointer to the texture.
  89. /// <summary>
  90. /// Draw a texture as an image in an ImGui Context
  91. /// Uses the current ImGui Cursor position and the full texture size.
  92. /// </summary>
  93. /// <param name="image">The raylib texture to draw</param>
  94. void rlImGuiImage(const Texture *image);
  95. /// <summary>
  96. /// Draw a texture as an image in an ImGui Context at a specific size
  97. /// Uses the current ImGui Cursor position and the specified width and height
  98. /// The image will be scaled up or down to fit as needed
  99. /// </summary>
  100. /// <param name="image">The raylib texture to draw</param>
  101. /// <param name="width">The width of the drawn image</param>
  102. /// <param name="height">The height of the drawn image</param>
  103. void rlImGuiImageSize(const Texture *image, int width, int height);
  104. /// <summary>
  105. /// Draw a texture as an image in an ImGui Context at a specific size
  106. /// Uses the current ImGui Cursor position and the specified size
  107. /// The image will be scaled up or down to fit as needed
  108. /// </summary>
  109. /// <param name="image">The raylib texture to draw</param>
  110. /// <param name="size">The size of drawn image</param>
  111. void rlImGuiImageSizeV(const Texture* image, Vector2 size);
  112. /// <summary>
  113. /// Draw a portion texture as an image in an ImGui Context at a defined size
  114. /// Uses the current ImGui Cursor position and the specified size
  115. /// The image will be scaled up or down to fit as needed
  116. /// </summary>
  117. /// <param name="image">The raylib texture to draw</param>
  118. /// <param name="destWidth">The width of the drawn image</param>
  119. /// <param name="destHeight">The height of the drawn image</param>
  120. /// <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>
  121. void rlImGuiImageRect(const Texture* image, int destWidth, int destHeight, Rectangle sourceRect);
  122. /// <summary>
  123. /// Draws a render texture as an image an ImGui Context, automatically flipping the Y axis so it will show correctly on screen
  124. /// </summary>
  125. /// <param name="image">The render texture to draw</param>
  126. void rlImGuiImageRenderTexture(const RenderTexture* image);
  127. /// <summary>
  128. /// Draws a render texture as an image an ImGui Context, automatically flipping the Y axis so it will show correctly on screen
  129. /// Fits the render texture to the available content area
  130. /// </summary>
  131. /// <param name="image">The render texture to draw</param>
  132. /// <param name="center">When true the image will be centered in the content area</param>
  133. void rlImGuiImageRenderTextureFit(const RenderTexture* image, bool center);
  134. /// <summary>
  135. /// Draws a texture as an image button in an ImGui context. Uses the current ImGui cursor position and the full size of the texture
  136. /// </summary>
  137. /// <param name="name">The display name and ImGui ID for the button</param>
  138. /// <param name="image">The texture to draw</param>
  139. /// <returns>True if the button was clicked</returns>
  140. bool rlImGuiImageButton(const char* name, const Texture* image);
  141. /// <summary>
  142. /// Draws a texture as an image button in an ImGui context. Uses the current ImGui cursor position and the specified size.
  143. /// </summary>
  144. /// <param name="name">The display name and ImGui ID for the button</param>
  145. /// <param name="image">The texture to draw</param>
  146. /// <param name="size">The size of the button</param>
  147. /// <returns>True if the button was clicked</returns>
  148. bool rlImGuiImageButtonSize(const char* name, const Texture* image, struct ImVec2 size);
  149. #ifdef __cplusplus
  150. }
  151. #endif