Skip to content

Commit

Permalink
Fixes issues with clips containing both text and bitmaps.
Browse files Browse the repository at this point in the history
Also fixes an issue with duplicating bitmaps.
  • Loading branch information
Carson-Shook committed May 2, 2019
1 parent ec25982 commit e06574d
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 101 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ You will need Visual Studio 2017 to build Winclipper. The solution file should c

## Changelog

**1.3.1** - 2019-05-01

This release of Winclipper includes the following bug fixes:
- Adds a de-duplication comparison to bitmaps. Unfortunately the issue did not occur on any of my test machines, only the machines of my coworkers, so I missed it. Thanks guys for helping me work out the bugs!
- It now prioritizes previewing bitmaps over text.
- If a clip contains both a bitmap and text, then the bitmap thumbnail will display alongside the text, but without the image size.

**1.3** - 2019-05-01

This release of Winclipper includes the biggest addition since its original release: Bitmap support! Now you can copy images and paste them at a later time, and of course, if you don't want to do that (or you want to reduce or increase the amount of memory to cache images) you can change that in the settings.
Expand Down
2 changes: 1 addition & 1 deletion Setup-x64/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Winclipper" Language="1033" Version="1.3.0.0" Manufacturer="Carson Shook" UpgradeCode="34e3392e-e835-41c9-ac2b-f0c68176f4ca">
<Product Id="*" Name="Winclipper" Language="1033" Version="1.3.1.0" Manufacturer="Carson Shook" UpgradeCode="34e3392e-e835-41c9-ac2b-f0c68176f4ca">
<Package InstallerVersion="301" Compressed="yes" InstallScope="perMachine" />

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
Expand Down
2 changes: 1 addition & 1 deletion Setup-x86/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Winclipper" Language="1033" Version="1.3.0.0" Manufacturer="Carson Shook" UpgradeCode="a332e06b-480d-4d31-aaca-e5f7a2ef1dbb">
<Product Id="*" Name="Winclipper" Language="1033" Version="1.3.1.0" Manufacturer="Carson Shook" UpgradeCode="a332e06b-480d-4d31-aaca-e5f7a2ef1dbb">
<Package InstallerVersion="301" Compressed="yes" InstallScope="perMachine" />

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
Expand Down
19 changes: 17 additions & 2 deletions Winclipper/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,23 @@ bool Clip::Equals(std::shared_ptr<Clip> other)

if (format == CF_DIB)
{
isEqual = false;
break;
if (other->bitmapHeight != bitmapHeight || other->bitmapWidth != bitmapWidth)
{
isEqual = false;
break;
}
auto mySize = DibSize();
if (other->DibSize() != mySize)
{
isEqual = false;
break;
}

if (std::memcmp(other->DibBitmapBits().get(), DibBitmapBits().get(), mySize))
{
isEqual = false;
break;
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion Winclipper/ClipsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ void ClipsManager::ShowClipsMenu(HWND hWnd, const LPPOINT cPos, bool showExit)
std::wstring menuText;
menuText = clip->GetUnicodeMenuText(MenuDisplayChars());

AppendMenuW(menu, MF_STRING, UINT_PTR{ i } + 1, menuText.c_str());
AppendMenuW(menu, MF_STRING, UINT_PTR{ i } +1, menuText.c_str());
if (clip->ContainsFormat(CF_DIB))
{
SetMenuItemBitmaps(menu, UINT{ i } +1, MF_BYCOMMAND, clip->GetThumbnail(), clip->GetThumbnail());
}
}
else if (clip->ContainsFormat(CF_DIB))
{
Expand All @@ -519,6 +523,10 @@ void ClipsManager::ShowClipsMenu(HWND hWnd, const LPPOINT cPos, bool showExit)
menuText = clip->GetUnicodeMenuText(MenuDisplayChars());

AppendMenuW(sMenu, MF_STRING, UINT_PTR{ j } + 1, menuText.c_str());
if (clip->ContainsFormat(CF_DIB))
{
SetMenuItemBitmaps(sMenu, UINT{ j } + 1, MF_BYCOMMAND, clip->GetThumbnail(), clip->GetThumbnail());
}
}
else if (clip->ContainsFormat(CF_DIB))
{
Expand Down
193 changes: 97 additions & 96 deletions Winclipper/PreviewWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,69 @@ LRESULT PreviewWindow::WmPaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP

hr = CreateDeviceDependentResources(hWnd);

if (previewClip->ContainsFormat(CF_UNICODETEXT))

if (previewClip->ContainsFormat(CF_DIB))
{
if (SUCCEEDED(hr))
{
if (bitmapReady && pConvertedSourceBitmap != nullptr)
{
// Need to release the previous D2DBitmap if there is one
SafeRelease(&pD2DBitmap);
hr = pRT->CreateBitmapFromWicBitmap(pConvertedSourceBitmap, nullptr, &pD2DBitmap);
}
else if (pD2DLoadingBitmap == nullptr)
{
hr = pRT->CreateBitmapFromWicBitmap(pConvertedLoadingBitmap, nullptr, &pD2DLoadingBitmap);
}
}

if (SUCCEEDED(hr))
{
pRT->BeginDraw();

pRT->SetTransform(D2D1::Matrix3x2F::Identity());

pRT->Clear(WindowColor);

const auto rect = D2D1::RectF(
windowBorderWidth,
windowBorderWidth,
pRT->GetSize().width - windowBorderWidth,
pRT->GetSize().height - windowBorderWidth);

pRT->FillRectangle(
rect,
pWhiteBrush);

if (bitmapReady)
{
pRT->DrawBitmap(pD2DBitmap, rect);
}
else
{
const float left = (windowBorderWidth + rect.right) / 2.0F;
const float bottom = (windowBorderWidth + rect.bottom) / 2.0F;
const auto loadingRect = D2D1::RectF(
left - (pD2DLoadingBitmap->GetSize().width / ScaleX(2.0F)),
bottom - (pD2DLoadingBitmap->GetSize().height / ScaleY(2.0F)),
left + (pD2DLoadingBitmap->GetSize().width / ScaleX(2.0F)),
bottom + (pD2DLoadingBitmap->GetSize().height / ScaleY(2.0F))
);
pRT->DrawBitmap(pD2DLoadingBitmap, loadingRect);
}

pRT->DrawRectangle(
rect,
pLightGrayBrush, 0.5F);

hr = pRT->EndDraw();

SafeRelease(&pD2DBitmap);
SafeRelease(&pConvertedSourceBitmap);
}
}
else if (previewClip->ContainsFormat(CF_UNICODETEXT))
{
std::wstring infoBreakText;

Expand Down Expand Up @@ -199,67 +261,6 @@ LRESULT PreviewWindow::WmPaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
}
SafeRelease(&pDWriteInfoBreakLayout);
}
else if (previewClip->ContainsFormat(CF_DIB))
{
if (SUCCEEDED(hr))
{
if (bitmapReady)
{
// Need to release the previous D2DBitmap if there is one
SafeRelease(&pD2DBitmap);
hr = pRT->CreateBitmapFromWicBitmap(pConvertedSourceBitmap, nullptr, &pD2DBitmap);
}
else if (pD2DLoadingBitmap == nullptr)
{
hr = pRT->CreateBitmapFromWicBitmap(pConvertedLoadingBitmap, nullptr, &pD2DLoadingBitmap);
}
}

if (SUCCEEDED(hr))
{
pRT->BeginDraw();

pRT->SetTransform(D2D1::Matrix3x2F::Identity());

pRT->Clear(WindowColor);

const auto rect = D2D1::RectF(
windowBorderWidth,
windowBorderWidth,
pRT->GetSize().width - windowBorderWidth,
pRT->GetSize().height - windowBorderWidth);

pRT->FillRectangle(
rect,
pWhiteBrush);

if (bitmapReady)
{
pRT->DrawBitmap(pD2DBitmap, rect);
}
else
{
const float left = (windowBorderWidth + rect.right) / 2.0F;
const float bottom = (windowBorderWidth + rect.bottom) / 2.0F;
const auto loadingRect = D2D1::RectF(
left - (pD2DLoadingBitmap->GetSize().width / ScaleX(2.0F)),
bottom - (pD2DLoadingBitmap->GetSize().height / ScaleY(2.0F)),
left + (pD2DLoadingBitmap->GetSize().width / ScaleX(2.0F)),
bottom + (pD2DLoadingBitmap->GetSize().height / ScaleY(2.0F))
);
pRT->DrawBitmap(pD2DLoadingBitmap, loadingRect);
}

pRT->DrawRectangle(
rect,
pLightGrayBrush, 0.5F);

hr = pRT->EndDraw();

SafeRelease(&pD2DBitmap);
SafeRelease(&pConvertedSourceBitmap);
}
}
if (hr == D2DERR_RECREATE_TARGET)
{
DestroyDeviceDependentResources();
Expand Down Expand Up @@ -715,7 +716,39 @@ void PreviewWindow::MoveRelativeToRect(const LPRECT rect, unsigned int index)
float renderingWidth = layoutMaxWidth;
float renderingHeight = layoutMaxHeight;

if (previewClip->ContainsFormat(CF_UNICODETEXT))
if (previewClip->ContainsFormat(CF_DIB))
{
if (previewClip->BitmapReady())
{
hr = SetBitmapConverter();
}
else
{
previewClip->EnsureBitmapAsync();
bitmapReady = false;
SetTimer(GetHandle(), IDT_BITMAPTIMER, 100, nullptr);
}

renderingHeight = static_cast<float>(previewClip->DibHeight());
renderingWidth = static_cast<float>(previewClip->DibWidth());

if (renderingWidth > layoutMaxWidth || renderingHeight > layoutMaxHeight)
{
if (renderingWidth >= renderingHeight)
{
const float ratio = layoutMaxWidth / renderingWidth;
renderingWidth = layoutMaxWidth;
renderingHeight = renderingHeight * ratio;
}
else
{
const float ratio = layoutMaxHeight / renderingHeight;
renderingHeight = layoutMaxHeight;
renderingWidth = renderingWidth * ratio;
}
}
}
else if (previewClip->ContainsFormat(CF_UNICODETEXT))
{
const size_t clipLength = previewClip->UnicodeTextWString().length();

Expand Down Expand Up @@ -812,39 +845,7 @@ void PreviewWindow::MoveRelativeToRect(const LPRECT rect, unsigned int index)
remainingTextLines = 0;
}
}
else if (previewClip->ContainsFormat(CF_DIB))
{
if (previewClip->BitmapReady())
{
hr = SetBitmapConverter();
}
else
{
previewClip->EnsureBitmapAsync();
bitmapReady = false;
SetTimer(GetHandle(), IDT_BITMAPTIMER, 100, nullptr);
}

renderingHeight = static_cast<float>(previewClip->DibHeight());
renderingWidth = static_cast<float>(previewClip->DibWidth());

if (renderingWidth > layoutMaxWidth || renderingHeight > layoutMaxHeight)
{
if (renderingWidth >= renderingHeight)
{
const float ratio = layoutMaxWidth / renderingWidth;
renderingWidth = layoutMaxWidth;
renderingHeight = renderingHeight * ratio;
}
else
{
const float ratio = layoutMaxHeight / renderingHeight;
renderingHeight = layoutMaxHeight;
renderingWidth = renderingWidth * ratio;
}
}
}


const int totalWindowWidth = static_cast<int>(ScaleX(renderingWidth + (windowBorderWidth * 2.0f) + (textMarginWidth * 2.0f)));
const int totalWindowHeight = static_cast<int>(ScaleY(renderingHeight + (windowBorderWidth * 2.0f) + (textMarginHeight * 2.0f)));

Expand Down
Binary file modified Winclipper/Winclipper.rc
Binary file not shown.

0 comments on commit e06574d

Please sign in to comment.