Skip to content

Commit 98952f4

Browse files
committed
Add param CanResize
1 parent 1dc76ff commit 98952f4

5 files changed

Lines changed: 107 additions & 0 deletions

File tree

src/immvision/image.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ namespace ImmVision
134134
bool PanWithMouse = true;
135135
bool ZoomWithMouseWheel = true;
136136

137+
// Can the image widget be resized by the user
138+
bool CanResize = true;
139+
137140
// Color Order: RGB or RGBA versus BGR or BGRA (Note: by default OpenCV uses BGR and BGRA)
138141
bool IsColorOrderBGR = true;
139142

src/immvision/internal/image.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ namespace ImmVision
375375
// Mouse dragging
376376
auto fnHandleMouseDragging = [&params](CachedParams & cacheParams)
377377
{
378+
if (cacheParams.IsResizing)
379+
return;
378380
ZoomPanTransform::MatrixType& zoomMatrix = params->ZoomPanMatrix;
379381

380382
int mouseDragButton = 0;
@@ -478,6 +480,50 @@ namespace ImmVision
478480
return mouseInfo;
479481
};
480482

483+
//
484+
// Lambda / Show resize widget in the bottom right corner
485+
//
486+
auto fnShowResizeWidget = [&params](CachedParams & cacheParams)
487+
{
488+
if (!params->CanResize)
489+
return;
490+
ImVec2 imageBottomRight = ImGui::GetItemRectMax();
491+
float em = ImGui::GetFontSize();
492+
float size = em * 1.0f;
493+
ImVec2 br(imageBottomRight.x, imageBottomRight.y);
494+
ImVec2 bl(br.x - size, br.y);
495+
ImVec2 tr(br.x, br.y - size);
496+
ImVec2 tl(br.x - size, br.y - size);
497+
498+
ImRect zone(tl, br);
499+
ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, ImGui::GetColorU32(ImGuiCol_ButtonHovered));
500+
501+
if (!cacheParams.IsResizing)
502+
{
503+
if (ImGui::IsMouseHoveringRect(zone.Min, zone.Max) && ImGui::IsMouseDown(0))
504+
{
505+
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNWSE);
506+
cacheParams.IsResizing = true;
507+
}
508+
}
509+
if (cacheParams.IsResizing)
510+
{
511+
if (ImGui::IsMouseDown(0))
512+
{
513+
if (ImGui::GetIO().MouseDelta.x != 0. || ImGui::GetIO().MouseDelta.y != 0.)
514+
{
515+
params->ImageDisplaySize.width += ImGui::GetIO().MouseDelta.x;
516+
params->ImageDisplaySize.height += ImGui::GetIO().MouseDelta.y;
517+
}
518+
}
519+
else
520+
{
521+
ImGui::SetMouseCursor(ImGuiMouseCursor_Arrow);
522+
cacheParams.IsResizing = false;
523+
}
524+
}
525+
};
526+
481527

482528
//
483529
// Lambda / Show pixel info
@@ -506,6 +552,7 @@ namespace ImmVision
506552
ImGui::BeginGroup();
507553
// Show image
508554
auto mouseInfo = fnShowImage(*cacheImages.GlTexture);
555+
fnShowResizeWidget(cacheParams);
509556
// Add Watched Pixel on double click
510557
if ( params->AddWatchedPixelOnDoubleClick
511558
&& ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)
@@ -630,6 +677,7 @@ namespace ImmVision
630677
imageParams.ShowOptionsPanel = false;
631678
imageParams.ZoomWithMouseWheel = false;
632679
imageParams.PanWithMouse = false;
680+
imageParams.CanResize = false;
633681
imageParams.ShowPixelInfo = false;
634682
imageParams.ShowImageInfo = false;
635683
imageParams.ShowGrid = false;

src/immvision/internal/image_cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace ImmVision
2222
std::vector<char> FilenameEditBuffer = std::vector<char>(1000, '\0');
2323
bool IsMouseDragging = false;
2424
bool WasZoomJustUpdatedByLink = false;
25+
bool IsResizing = false;
2526
cv::Size PreviousImageSize;
2627
struct ImageParams PreviousParams;
2728
};

src_all_in_one/immvision/immvision.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ namespace ImmVision
147147
bool PanWithMouse = true;
148148
bool ZoomWithMouseWheel = true;
149149

150+
// Can the image widget be resized by the user
151+
bool CanResize = true;
152+
150153
// Color Order: RGB or RGBA versus BGR or BGRA (Note: by default OpenCV uses BGR and BGRA)
151154
bool IsColorOrderBGR = true;
152155

@@ -9363,6 +9366,7 @@ namespace ImmVision
93639366
std::vector<char> FilenameEditBuffer = std::vector<char>(1000, '\0');
93649367
bool IsMouseDragging = false;
93659368
bool WasZoomJustUpdatedByLink = false;
9369+
bool IsResizing = false;
93669370
cv::Size PreviousImageSize;
93679371
struct ImageParams PreviousParams;
93689372
};
@@ -9811,6 +9815,8 @@ namespace ImmVision
98119815
// Mouse dragging
98129816
auto fnHandleMouseDragging = [&params](CachedParams & cacheParams)
98139817
{
9818+
if (cacheParams.IsResizing)
9819+
return;
98149820
ZoomPanTransform::MatrixType& zoomMatrix = params->ZoomPanMatrix;
98159821

98169822
int mouseDragButton = 0;
@@ -9914,6 +9920,50 @@ namespace ImmVision
99149920
return mouseInfo;
99159921
};
99169922

9923+
//
9924+
// Lambda / Show resize widget in the bottom right corner
9925+
//
9926+
auto fnShowResizeWidget = [&params](CachedParams & cacheParams)
9927+
{
9928+
if (!params->CanResize)
9929+
return;
9930+
ImVec2 imageBottomRight = ImGui::GetItemRectMax();
9931+
float em = ImGui::GetFontSize();
9932+
float size = em * 1.0f;
9933+
ImVec2 br(imageBottomRight.x, imageBottomRight.y);
9934+
ImVec2 bl(br.x - size, br.y);
9935+
ImVec2 tr(br.x, br.y - size);
9936+
ImVec2 tl(br.x - size, br.y - size);
9937+
9938+
ImRect zone(tl, br);
9939+
ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, ImGui::GetColorU32(ImGuiCol_ButtonHovered));
9940+
9941+
if (!cacheParams.IsResizing)
9942+
{
9943+
if (ImGui::IsMouseHoveringRect(zone.Min, zone.Max) && ImGui::IsMouseDown(0))
9944+
{
9945+
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNWSE);
9946+
cacheParams.IsResizing = true;
9947+
}
9948+
}
9949+
if (cacheParams.IsResizing)
9950+
{
9951+
if (ImGui::IsMouseDown(0))
9952+
{
9953+
if (ImGui::GetIO().MouseDelta.x != 0. || ImGui::GetIO().MouseDelta.y != 0.)
9954+
{
9955+
params->ImageDisplaySize.width += ImGui::GetIO().MouseDelta.x;
9956+
params->ImageDisplaySize.height += ImGui::GetIO().MouseDelta.y;
9957+
}
9958+
}
9959+
else
9960+
{
9961+
ImGui::SetMouseCursor(ImGuiMouseCursor_Arrow);
9962+
cacheParams.IsResizing = false;
9963+
}
9964+
}
9965+
};
9966+
99179967

99189968
//
99199969
// Lambda / Show pixel info
@@ -9942,6 +9992,7 @@ namespace ImmVision
99429992
ImGui::BeginGroup();
99439993
// Show image
99449994
auto mouseInfo = fnShowImage(*cacheImages.GlTexture);
9995+
fnShowResizeWidget(cacheParams);
99459996
// Add Watched Pixel on double click
99469997
if ( params->AddWatchedPixelOnDoubleClick
99479998
&& ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)
@@ -10066,6 +10117,7 @@ namespace ImmVision
1006610117
imageParams.ShowOptionsPanel = false;
1006710118
imageParams.ZoomWithMouseWheel = false;
1006810119
imageParams.PanWithMouse = false;
10120+
imageParams.CanResize = false;
1006910121
imageParams.ShowPixelInfo = false;
1007010122
imageParams.ShowImageInfo = false;
1007110123
imageParams.ShowGrid = false;

src_all_in_one/immvision/immvision.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ namespace ImmVision
142142
bool PanWithMouse = true;
143143
bool ZoomWithMouseWheel = true;
144144

145+
// Can the image widget be resized by the user
146+
bool CanResize = true;
147+
145148
// Color Order: RGB or RGBA versus BGR or BGRA (Note: by default OpenCV uses BGR and BGRA)
146149
bool IsColorOrderBGR = true;
147150

0 commit comments

Comments
 (0)