tdf#107792 vcl/win/gdi: introduce ScopedHBRUSH

Change-Id: Ieca634892f4af1b0c38fa6bd8a8bbbb8f1c7370d
Reviewed-on: https://gerrit.libreoffice.org/65141
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Dmitriy Shilin
2018-12-27 12:43:50 +01:00
committed by Mike Kaganski
parent a7ff057c2b
commit 71f02295f2
2 changed files with 49 additions and 19 deletions
+21 -19
View File
@@ -20,6 +20,7 @@
#include <svsys.h>
#include "gdiimpl.hxx"
#include "scoped_gdi.hxx"
#include <string.h>
#include <rtl/strbuf.hxx>
@@ -772,9 +773,9 @@ bool WinSalGraphicsImpl::drawAlphaRect( long nX, long nY, long nWidth,
return bRet;
}
void WinSalGraphicsImpl::drawMask( const SalTwoRect& rPosAry,
const SalBitmap& rSSalBitmap,
Color nMaskColor )
void WinSalGraphicsImpl::drawMask(const SalTwoRect& rPosAry,
const SalBitmap& rSSalBitmap,
Color nMaskColor)
{
SAL_WARN_IF( mrParent.isPrinter(), "vcl", "No transparency print possible!" );
@@ -783,12 +784,12 @@ void WinSalGraphicsImpl::drawMask( const SalTwoRect& rPosAry,
const WinSalBitmap& rSalBitmap = static_cast<const WinSalBitmap&>(rSSalBitmap);
SalTwoRect aPosAry = rPosAry;
const BYTE cRed = nMaskColor.GetRed();
const BYTE cGreen = nMaskColor.GetGreen();
const BYTE cBlue = nMaskColor.GetBlue();
HDC hDC = mrParent.getHDC();
HBRUSH hMaskBrush = CreateSolidBrush( RGB( cRed, cGreen, cBlue ) );
HBRUSH hOldBrush = SelectBrush( hDC, hMaskBrush );
const HDC hDC = mrParent.getHDC();
ScopedHBRUSH hMaskBrush(CreateSolidBrush(RGB(nMaskColor.GetRed(),
nMaskColor.GetGreen(),
nMaskColor.GetBlue())));
HBRUSH hOldBrush = SelectBrush(hDC, hMaskBrush.get());
// WIN/WNT seems to have a minor problem mapping the correct color of the
// mask to the palette if we draw the DIB directly ==> draw DDB
@@ -802,8 +803,7 @@ void WinSalGraphicsImpl::drawMask( const SalTwoRect& rPosAry,
else
ImplDrawBitmap( hDC, aPosAry, rSalBitmap, false, 0x00B8074AUL );
SelectBrush( hDC, hOldBrush );
DeleteBrush( hMaskBrush );
SelectBrush(hDC, hOldBrush);
}
std::shared_ptr<SalBitmap> WinSalGraphicsImpl::getBitmap( long nX, long nY, long nDX, long nDY )
@@ -1575,16 +1575,18 @@ void WinSalGraphicsImpl::SetROPFillColor( SalROPColor nROPColor )
void WinSalGraphicsImpl::DrawPixelImpl( long nX, long nY, COLORREF crColor )
{
if ( mbXORMode )
const HDC hDC = mrParent.getHDC();
if (!mbXORMode)
{
HBRUSH hBrush = CreateSolidBrush( crColor );
HBRUSH hOldBrush = SelectBrush( mrParent.getHDC(), hBrush );
PatBlt( mrParent.getHDC(), static_cast<int>(nX), static_cast<int>(nY), int(1), int(1), PATINVERT );
SelectBrush( mrParent.getHDC(), hOldBrush );
DeleteBrush( hBrush );
SetPixel(hDC, static_cast<int>(nX), static_cast<int>(nY), crColor);
return;
}
else
SetPixel( mrParent.getHDC(), static_cast<int>(nX), static_cast<int>(nY), crColor );
ScopedHBRUSH hBrush(CreateSolidBrush(crColor));
HBRUSH hOldBrush = SelectBrush(hDC, hBrush.get());
PatBlt(hDC, static_cast<int>(nX), static_cast<int>(nY), int(1), int(1), PATINVERT);
SelectBrush(hDC, hOldBrush);
}
void WinSalGraphicsImpl::drawPixel( long nX, long nY )
+28
View File
@@ -0,0 +1,28 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_VCL_WIN_GDI_SCOPED_GDI_HXX
#define INCLUDED_VCL_WIN_GDI_SCOPED_GDI_HXX
#include <win/svsys.h>
#include <win/wincomp.hxx>
#include <memory>
struct HBRUSHDeleter
{
using pointer = HBRUSH;
void operator()(HBRUSH hBrush) { DeleteBrush(hBrush); }
};
using ScopedHBRUSH = std::unique_ptr<HBRUSH, HBRUSHDeleter>;
#endif // INCLUDED_VCL_WIN_GDI_SCOPED_GDI_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */