image viewer popup when clicking an image in a message
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Has been cancelled
ContinuousDelivery / windows (push) Has been cancelled
ContinuousDelivery / windows-asan (push) Has been cancelled
ContinuousIntegration / linux (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / dumpsyms (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Has been cancelled
ContinuousDelivery / windows (push) Has been cancelled
ContinuousDelivery / windows-asan (push) Has been cancelled
ContinuousIntegration / linux (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / dumpsyms (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
This commit is contained in:
66
src/chat_gui/image_viewer_popup.cpp
Normal file
66
src/chat_gui/image_viewer_popup.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "./image_viewer_popup.hpp"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
ImageViewerPopup::ImageViewerPopup(MessageTextureCache& mtc) : _mtc(mtc) {
|
||||
}
|
||||
|
||||
// open popup with (image) file
|
||||
void ImageViewerPopup::view(Message3Handle m) {
|
||||
if (static_cast<bool>(_m)) {
|
||||
std::cout << "IVP warning: overriding open image\n";
|
||||
}
|
||||
|
||||
_m = m;
|
||||
|
||||
_open_popup = true;
|
||||
}
|
||||
|
||||
// call this each frame
|
||||
void ImageViewerPopup::render(float) {
|
||||
if (_open_popup) {
|
||||
_open_popup = false;
|
||||
ImGui::OpenPopup("Image##ImageViewerPopup");
|
||||
}
|
||||
|
||||
if (!ImGui::BeginPopup("Image##ImageViewerPopup", ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
_m = {}; // meh, event on close would be nice, but the reset is cheap
|
||||
_scale = 1.f;
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("scale", &_scale, 0.05f, 2.f);
|
||||
|
||||
auto [id, img_width, img_height] = _mtc.get(_m);
|
||||
|
||||
img_width = std::max<int32_t>(5, _scale * img_width);
|
||||
img_height = std::max<int32_t>(5, _scale * img_height);
|
||||
|
||||
ImGui::Image(
|
||||
id,
|
||||
ImVec2{
|
||||
static_cast<float>(img_width),
|
||||
static_cast<float>(img_height)
|
||||
}
|
||||
);
|
||||
|
||||
// TODO: figure out nice scroll zooming
|
||||
//ImGui::SetItemKeyOwner(ImGuiKey_MouseWheelY);
|
||||
//const auto prev_scale = _scale;
|
||||
//_scale += ImGui::GetIO().MouseWheel * 0.05f;
|
||||
//_scale = std::clamp(_scale, 0.05f, 3.f);
|
||||
|
||||
//if (std::abs(prev_scale - _scale) > 0.001f) {
|
||||
//}
|
||||
|
||||
if (ImGui::Shortcut(ImGuiKey_Escape)) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
_m = {};
|
||||
_scale = 1.f;
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
Reference in New Issue
Block a user