Skip to content

Commit

Permalink
Added info messages on copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Jun 26, 2024
1 parent 9bad27d commit fb59ec1
Showing 1 changed file with 85 additions and 42 deletions.
127 changes: 85 additions & 42 deletions src/tabs/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,58 +1437,100 @@ SKIF_UI_Tab_DrawViewer (void)
//
// User is requesting to copy the loaded image to clipboard,
// let's download it back from the GPU and have some fun!
if (wantCopyToClipboard && cover.pRawTexSRV.p != nullptr /* && cover.is_hdr */)
{
auto
pDevice = SKIF_D3D11_GetDevice ();
if (pDevice != nullptr)
if (wantCopyToClipboard)
{ wantCopyToClipboard = false;

if (cover.pRawTexSRV.p != nullptr /* && cover.is_hdr */)
{
CComPtr <ID3D11DeviceContext> pDevCtx;
pDevice->GetImmediateContext (&pDevCtx.p);
auto
pDevice = SKIF_D3D11_GetDevice ();
if (pDevice != nullptr)
{
CComPtr <ID3D11DeviceContext> pDevCtx;
pDevice->GetImmediateContext (&pDevCtx.p);

CComPtr <ID3D11Resource> pTexResource;
cover.pRawTexSRV->GetResource (&pTexResource.p);
CComPtr <ID3D11Resource> pTexResource;
cover.pRawTexSRV->GetResource (&pTexResource.p);

if (pTexResource.p != nullptr)
{
DirectX::ScratchImage captured_img;
if (SUCCEEDED (DirectX::CaptureTexture (pDevice, pDevCtx, pTexResource.p, captured_img)))
if (pTexResource.p != nullptr)
{
if (copyRect.GetArea () != 0)
DirectX::ScratchImage captured_img;
if (SUCCEEDED (DirectX::CaptureTexture (pDevice, pDevCtx, pTexResource.p, captured_img)))
{
const size_t
x = static_cast <size_t> (std::max (0.0f, copyRect.Min.x)),
y = static_cast <size_t> (std::max (0.0f, copyRect.Min.y)),
width = static_cast <size_t> (std::max (0.0f, copyRect.GetWidth ())),
height = static_cast <size_t> (std::max (0.0f, copyRect.GetHeight ()));

const DirectX::Rect
src_rect (x,y, width,height);

DirectX::ScratchImage
subrect;
if (SUCCEEDED (subrect.Initialize2D ( captured_img.GetMetadata ().format, width, height, 1, 1)) &&
SUCCEEDED (DirectX::CopyRectangle (*captured_img.GetImages (), src_rect,
*subrect.GetImages (), DirectX::TEX_FILTER_DEFAULT, 0, 0)))
if (copyRect.GetArea () != 0)
{
extern bool
SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped);
if (SKIV_Image_CopyToClipboard (subrect.GetImages (), true))
const size_t
x = static_cast <size_t> (std::max (0.0f, copyRect.Min.x)),
y = static_cast <size_t> (std::max (0.0f, copyRect.Min.y)),
width = static_cast <size_t> (std::max (0.0f, copyRect.GetWidth ())),
height = static_cast <size_t> (std::max (0.0f, copyRect.GetHeight ()));

const DirectX::Rect
src_rect (x,y, width,height);

DirectX::ScratchImage
subrect;
if (SUCCEEDED (subrect.Initialize2D ( captured_img.GetMetadata ().format, width, height, 1, 1)) &&
SUCCEEDED (DirectX::CopyRectangle (*captured_img.GetImages (), src_rect,
*subrect.GetImages (), DirectX::TEX_FILTER_DEFAULT, 0, 0)))
{
std::exchange (wantCopyToClipboard, false);

copyRect = { 0,0,0,0 };
extern bool
SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped);
if (SKIV_Image_CopyToClipboard (subrect.GetImages (), true))
{
ImGui::InsertNotification (
{
ImGuiToastType::Info,
3000,
"Copied area to clipboard", "%.fx%.f -> %.fx%.f",
copyRect.Min.x,
copyRect.Min.y,
copyRect.Max.x,
copyRect.Max.y
}
);

copyRect = { 0,0,0,0 };
}
else {
ImGui::InsertNotification (
{
ImGuiToastType::Error,
3000,
"Failed to copy area to clipboard", "Area: %.fx%.f -> %.fx%.f",
copyRect.Min.x,
copyRect.Min.y,
copyRect.Max.x,
copyRect.Max.y
}
);
}
}
}
}

else
{
extern bool
SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped);
if (SKIV_Image_CopyToClipboard (captured_img.GetImages (), false))
else
{
std::exchange (wantCopyToClipboard, false);
extern bool
SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped);
if (SKIV_Image_CopyToClipboard (captured_img.GetImages (), false))
{
ImGui::InsertNotification (
{
ImGuiToastType::Info,
3000,
"Copied image to clipboard", ""
}
);
}
else {
ImGui::InsertNotification (
{
ImGuiToastType::Error,
3000,
"Failed to copy image to clipboard", ""
}
);
}
}
}
}
Expand Down Expand Up @@ -1974,7 +2016,7 @@ SKIF_UI_Tab_DrawViewer (void)
translated.Min *= scale;
translated.Max *= scale;

// On release, do something
/*
ImGui::InsertNotification (
{
ImGuiToastType::Info,
Expand All @@ -1990,6 +2032,7 @@ SKIF_UI_Tab_DrawViewer (void)
translated.Max.y
}
);
*/

wantCopyToClipboard = true;
copyRect = translated;
Expand Down

0 comments on commit fb59ec1

Please sign in to comment.