Browse Source

add comments to public functions
add image function for render texture to auto flip it.

Jeffery Myers 1 year ago
parent
commit
fe0548317d
2 changed files with 127 additions and 3 deletions
  1. 31 0
      rlImGui.cpp
  2. 96 3
      rlImGui.h

+ 31 - 0
rlImGui.cpp

@@ -518,26 +518,49 @@ void rlImGuiShutdown()
 
 void rlImGuiImage(const Texture* image)
 {
+	if (!image)
+		return;
+
     ImGui::Image((ImTextureID)image, ImVec2(float(image->width), float(image->height)));
 }
 
 bool rlImGuiImageButton(const char* name, const Texture* image)
 {
+	if (!image)
+		return false;
+
     return ImGui::ImageButton(name, (ImTextureID)image, ImVec2(float(image->width), float(image->height)));
 }
 
 bool rlImGuiImageButtonSize(const char* name, const Texture* image, ImVec2 size)
 {
+	if (!image)
+		return false;
+
     return ImGui::ImageButton(name, (ImTextureID)image, size);
 }
 
 void rlImGuiImageSize(const Texture* image, int width, int height)
 {
+	if (!image)
+		return;
+
     ImGui::Image((ImTextureID)image, ImVec2(float(width), float(height)));
 }
 
+void rlImGuiImageSizeV(const Texture* image, Vector2 size)
+{
+	if (!image)
+		return;
+
+	ImGui::Image((ImTextureID)image, ImVec2(size.x, size.y));
+}
+
 void rlImGuiImageRect(const Texture* image, int destWidth, int destHeight, Rectangle sourceRect)
 {
+	if (!image)
+		return;
+
     ImVec2 uv0;
     ImVec2 uv1;
 
@@ -565,3 +588,11 @@ void rlImGuiImageRect(const Texture* image, int destWidth, int destHeight, Recta
 
     ImGui::Image((ImTextureID)image, ImVec2(float(destWidth), float(destHeight)), uv0, uv1);
 }
+
+void rlImGuiImageRenderTexture(const RenderTexture* image)
+{
+    if (!image)
+        return;
+
+    rlImGuiImageRect(&image->texture, image->texture.width, image->texture.height, Rectangle{ 0,0, float(image->texture.width), -float(image->texture.height) });
+}

+ 96 - 3
rlImGui.h

@@ -42,26 +42,119 @@ extern "C" {
 #endif
 
 // Basic API
-void rlImGuiSetup(bool dark);
+
+/// <summary>
+/// Sets up ImGui, loads fonts and themes
+/// </summary>
+/// <param name="darkTheme">when true(default) the dark theme is used, when false the light theme is used</param>
+void rlImGuiSetup(bool darkTheme);
+
+/// <summary>
+/// Starts a new ImGui Frame
+/// </summary>
 void rlImGuiBegin();
+
+/// <summary>
+/// Ends an ImGui frame and submits all ImGui drawing to raylib for processing.
+/// </summary>
 void rlImGuiEnd();
+
+/// <summary>
+/// Cleanup ImGui and unload font atlas
+/// </summary>
 void rlImGuiShutdown();
 
 // Advanced StartupAPI
+
+/// <summary>
+/// Custom initialization. Not needed if you call rlImGuiSetup. Only needed if you want to add custom setup code.
+/// must be followed by rlImGuiEndInitImGui
+/// </summary>
 void rlImGuiBeginInitImGui();
+
+/// <summary>
+/// End Custom initialization. Not needed if you call rlImGuiSetup. Only needed if you want to add custom setup code.
+/// must be proceeded by rlImGuiBeginInitImGui
+/// </summary>
 void rlImGuiEndInitImGui();
+
+/// <summary>
+/// Forces the font texture atlas to be recomputed and re-cached
+/// </summary>
 void rlImGuiReloadFonts();
 
 // Advanced Update API
+
+/// <summary>
+/// Starts a new ImGui Frame with a specified delta time
+/// </summary>
+/// <param name="dt">delta time, any value < 0 will use raylib GetFrameTime</param>
 void rlImGuiBeginDelta(float deltaTime);
 
 // image API
+
+/// <summary>
+/// Draw a texture as an image in an ImGui Context
+/// Uses the current ImGui Cursor position and the full texture size.
+/// </summary>
+/// <param name="image">The raylib texture to draw</param>
 void rlImGuiImage(const Texture *image);
-bool rlImGuiImageButton(const char* name, const Texture *image);
-bool rlImGuiImageButtonSize(const char* name, const Texture* image, struct ImVec2 size);
+
+/// <summary>
+/// Draw a texture as an image in an ImGui Context at a specific size
+/// Uses the current ImGui Cursor position and the specified width and height
+/// The image will be scaled up or down to fit as needed
+/// </summary>
+/// <param name="image">The raylib texture to draw</param>
+/// <param name="width">The width of the drawn image</param>
+/// <param name="height">The height of the drawn image</param>
 void rlImGuiImageSize(const Texture *image, int width, int height);
+
+/// <summary>
+/// Draw a texture as an image in an ImGui Context at a specific size
+/// Uses the current ImGui Cursor position and the specified size
+/// The image will be scaled up or down to fit as needed
+/// </summary>
+/// <param name="image">The raylib texture to draw</param>
+/// <param name="size">The size of drawn image</param>
+void rlImGuiImageSizeV(const Texture* image, Vector2 size);
+
+
+/// <summary>
+/// Draw a portion texture as an image in an ImGui Context at a defined size
+/// Uses the current ImGui Cursor position and the specified size
+/// The image will be scaled up or down to fit as needed
+/// </summary>
+/// <param name="image">The raylib texture to draw</param>
+/// <param name="destWidth">The width of the drawn image</param>
+/// <param name="destHeight">The height of the drawn image</param>
+/// <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>
 void rlImGuiImageRect(const Texture* image, int destWidth, int destHeight, Rectangle sourceRect);
 
+/// <summary>
+/// Draws a render texture as an image an ImGui Context, automatically flipping the Y axis so it will show correctly on screen
+/// </summary>
+/// <param name="image">The render texture to draw</param>
+void rlImGuiImageRenderTexture(const RenderTexture* image);
+
+
+/// <summary>
+/// Draws a texture as an image button in an ImGui context. Uses the current ImGui cursor position and the full size of the texture
+/// </summary>
+/// <param name="name">The display name and ImGui ID for the button</param>
+/// <param name="image">The texture to draw</param>
+/// <returns>True if the button was clicked</returns>
+bool rlImGuiImageButton(const char* name, const Texture* image);
+
+/// <summary>
+/// Draws a texture as an image button in an ImGui context. Uses the current ImGui cursor position and the specified size.
+/// </summary>
+/// <param name="name">The display name and ImGui ID for the button</param>
+/// <param name="image">The texture to draw</param>
+/// <param name="size">The size of the button/param>
+/// <returns>True if the button was clicked</returns>
+bool rlImGuiImageButtonSize(const char* name, const Texture* image, struct ImVec2 size);
+
 #ifdef __cplusplus
 }
 #endif