-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
166 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,17 @@ | ||
#ifdef HELLOIMGUI_HAS_OPENGL | ||
#include "hello_imgui/image_gl.h" | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
#include "image_from_asset.h" | ||
|
||
namespace HelloImGui | ||
{ | ||
std::unordered_map<std::string, ImageGlPtr> gImageFromAssetMap; | ||
|
||
void _LoadImageGl(const char *assetPath) | ||
{ | ||
if (gImageFromAssetMap.find(assetPath) == gImageFromAssetMap.end()) | ||
gImageFromAssetMap[assetPath] = ImageGl::FactorImage(assetPath); | ||
} | ||
|
||
void ImageFromAsset(const char *assetPath, const ImVec2 &size, const ImVec2 &uv0, const ImVec2 &uv1, | ||
const ImVec4 &tint_col, const ImVec4 &border_col) | ||
{ | ||
_LoadImageGl(assetPath); | ||
gImageFromAssetMap.at(assetPath)->Draw(size, uv0, uv1, tint_col, border_col); | ||
} | ||
|
||
bool ImageButtonFromAsset(const char *assetPath, const ImVec2 &size, const ImVec2 &uv0, const ImVec2 &uv1, | ||
int frame_padding, const ImVec4 &bg_col, const ImVec4 &tint_col) | ||
{ | ||
_LoadImageGl(assetPath); | ||
return gImageFromAssetMap.at(assetPath)->DrawButton(size, uv0, uv1, frame_padding, bg_col, tint_col); | ||
} | ||
|
||
ImTextureID ImTextureIdFromAsset(const char *assetPath) | ||
{ | ||
_LoadImageGl(assetPath); | ||
return gImageFromAssetMap.at(assetPath)->imTextureId; | ||
} | ||
|
||
|
||
namespace internal | ||
{ | ||
void Free_ImageFromAssetMap() | ||
ImVec2 ImageProportionalSize(const ImVec2& askedSize, const ImVec2& imageSize) | ||
{ | ||
// this function is called by HelloImGui during the application's TearDown | ||
// and will clear all asset images textures when the OpenGL context is still valid. | ||
gImageFromAssetMap.clear(); | ||
ImVec2 r(askedSize); | ||
|
||
if ((r.x == 0.f) && (r.y == 0.f)) | ||
r = imageSize; | ||
else if (r.y == 0.f) | ||
r.y = imageSize.y / imageSize.x * r.x; | ||
else if (r.x == 0.f) | ||
r.x = imageSize.x / imageSize.y * r.y; | ||
return r; | ||
} | ||
} | ||
|
||
} // namespace HelloImGui | ||
|
||
|
||
#elif defined(HELLOIMGUI_HAS_VULKAN) | ||
// See image_from_asset_vulkan.cpp | ||
|
||
#else // #ifdef HELLOIMGUI_HAS_OPENGL | ||
|
||
#include "imgui.h" | ||
|
||
namespace HelloImGui | ||
{ | ||
void ImageFromAsset(const char *assetPath, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col) | ||
{ | ||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 0.f, 0.f, 1.f)); | ||
ImGui::Text("ImageFromAsset requires OpenGL"); | ||
ImGui::PopStyleColor(); | ||
} | ||
|
||
bool ImageButtonFromAsset(const char *assetPath, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col) | ||
{ | ||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 0.f, 0.f, 1.f)); | ||
ImGui::Text("ButtonFromAsset requires OpenGL"); | ||
ImGui::PopStyleColor(); | ||
return false; | ||
} | ||
|
||
ImTextureID ImTextureIDFromAsset(const char *assetPath) | ||
{ | ||
// Requires OpenGL! | ||
return nullptr; | ||
} | ||
|
||
namespace internal | ||
{ | ||
void Free_ImageFromAssetMap() {} | ||
} | ||
} // namespace HelloImGui | ||
#endif // #ifdef HELLOIMGUI_HAS_OPENGL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "image_from_asset.h" | ||
|
||
|
||
#if !defined(HELLOIMGUI_HAS_VULKAN) && !defined(HELLOIMGUI_HAS_OPENGL) | ||
|
||
#include "imgui.h" | ||
|
||
namespace HelloImGui | ||
{ | ||
void ImageFromAsset(const char *assetPath, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col) | ||
{ | ||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 0.f, 0.f, 1.f)); | ||
ImGui::Text("ImageFromAsset not available"); | ||
ImGui::PopStyleColor(); | ||
} | ||
|
||
bool ImageButtonFromAsset(const char *assetPath, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col) | ||
{ | ||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 0.f, 0.f, 1.f)); | ||
ImGui::Text("ButtonFromAsset not available"); | ||
ImGui::PopStyleColor(); | ||
return false; | ||
} | ||
|
||
ImTextureID ImTextureIDFromAsset(const char *assetPath) | ||
{ | ||
// Requires OpenGL! | ||
return nullptr; | ||
} | ||
|
||
ImVec2 ImageSizeFromAsset(const char *assetPath) | ||
{ | ||
return ImVec2(0.f, 0.f); | ||
} | ||
|
||
namespace internal | ||
{ | ||
void Free_ImageFromAssetMap() {} | ||
} | ||
} // namespace HelloImGui | ||
#endif // #if !defined(HELLOIMGUI_HAS_VULKAN) && !defined(HELLOIMGUI_HAS_OPENGL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "image_from_asset.h" | ||
|
||
#ifdef HELLOIMGUI_HAS_OPENGL | ||
#include "hello_imgui/image_gl.h" | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace HelloImGui | ||
{ | ||
static std::unordered_map<std::string, ImageGlPtr> gImageFromAssetMap; | ||
|
||
void _LoadImageGl(const char *assetPath) | ||
{ | ||
if (gImageFromAssetMap.find(assetPath) == gImageFromAssetMap.end()) | ||
gImageFromAssetMap[assetPath] = ImageGl::FactorImage(assetPath); | ||
} | ||
|
||
void ImageFromAsset(const char *assetPath, const ImVec2 &size, const ImVec2 &uv0, const ImVec2 &uv1, | ||
const ImVec4 &tint_col, const ImVec4 &border_col) | ||
{ | ||
_LoadImageGl(assetPath); | ||
gImageFromAssetMap.at(assetPath)->Draw(size, uv0, uv1, tint_col, border_col); | ||
} | ||
|
||
bool ImageButtonFromAsset(const char *assetPath, const ImVec2 &size, const ImVec2 &uv0, const ImVec2 &uv1, | ||
int frame_padding, const ImVec4 &bg_col, const ImVec4 &tint_col) | ||
{ | ||
_LoadImageGl(assetPath); | ||
return gImageFromAssetMap.at(assetPath)->DrawButton(size, uv0, uv1, frame_padding, bg_col, tint_col); | ||
} | ||
|
||
ImTextureID ImTextureIdFromAsset(const char *assetPath) | ||
{ | ||
_LoadImageGl(assetPath); | ||
return gImageFromAssetMap.at(assetPath)->imTextureId; | ||
} | ||
|
||
ImVec2 ImageSizeFromAsset(const char *assetPath) | ||
{ | ||
_LoadImageGl(assetPath); | ||
return gImageFromAssetMap.at(assetPath)->imageSize; | ||
} | ||
|
||
|
||
namespace internal | ||
{ | ||
void Free_ImageFromAssetMap() | ||
{ | ||
// this function is called by HelloImGui during the application's TearDown | ||
// and will clear all asset images textures when the OpenGL context is still valid. | ||
gImageFromAssetMap.clear(); | ||
} | ||
} | ||
|
||
} // namespace HelloImGui | ||
|
||
|
||
#endif // #ifdef HELLOIMGUI_HAS_OPENGL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters