Subject:
Re: [nanogui] How to draw pixmap with transparency
From:
Julian Smart ####@####.####
Date:
27 Feb 2002 14:44:06 -0000
Message-Id: <4.2.0.58.20020227143514.023b8e70@pop>
At 01:47 PM 2/27/02 +0000, Alex Holden wrote:
>> Thanks, though unfortunately I need to convert the other way around
>> (the wxWindows wxFont constructor takes a font size expressed
>> in points). I may need to set a global fudge factor to get the size
>> right.
>
>Oh, I see. Is the problem that the dpcm values are wrong? Currently I
>don't think there's any way to change it other than to hack the source
>(see scr_* ins src/drivers/).
It could just be that these values will rarely reflect reality given Nano-X
can't know the actual screen size...
In case you experiment with transparent drawing, here a fragment
from the wxWindows WIN32 code which uses a temporary bitmap
and several BitBlts to achieve transparency. In wxWindows masks,
the transparent areas are black and the rest is white.
Regards,
Julian
// create a temp buffer bitmap and DCs to access it and the mask
dc_mask = ::CreateCompatibleDC(GetHdcOf(*source));
dc_buffer = ::CreateCompatibleDC(GetHdc());
buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height);
HGDIOBJ hOldMaskBitmap = ::SelectObject(dc_mask, (HBITMAP) mask->GetMaskBitmap());
HGDIOBJ hOldBufferBitmap = ::SelectObject(dc_buffer, buffer_bmap);
// copy dest to buffer
if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
GetHdc(), xdest, ydest, SRCCOPY) )
{
wxLogLastError(wxT("BitBlt"));
}
// copy src to buffer using selected raster op (usually SRCCOPY)
if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
GetHdcOf(*source), xsrc, ysrc, dwRop) )
{
wxLogLastError(wxT("BitBlt"));
}
// set masked area in buffer to BLACK (pixel value 0)
COLORREF prevBkCol = ::SetBkColor(GetHdc(), RGB(255, 255, 255));
COLORREF prevCol = ::SetTextColor(GetHdc(), RGB(0, 0, 0));
if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
dc_mask, xsrcMask, ysrcMask, SRCAND) )
{
wxLogLastError(wxT("BitBlt"));
}
// set unmasked area in dest to BLACK
::SetBkColor(GetHdc(), RGB(0, 0, 0));
::SetTextColor(GetHdc(), RGB(255, 255, 255));
if ( !::BitBlt(GetHdc(), xdest, ydest, (int)width, (int)height,
dc_mask, xsrcMask, ysrcMask, SRCAND) )
{
wxLogLastError(wxT("BitBlt"));
}
::SetBkColor(GetHdc(), prevBkCol); // restore colours to original values
::SetTextColor(GetHdc(), prevCol);
// OR buffer to dest
success = ::BitBlt(GetHdc(), xdest, ydest,
(int)width, (int)height,
dc_buffer, 0, 0, SRCPAINT) != 0;
if ( !success )
{
wxLogLastError(wxT("BitBlt"));
}
// tidy up temporary DCs and bitmap
::SelectObject(dc_mask, hOldMaskBitmap);
::SelectObject(dc_buffer, hOldBufferBitmap);
::DeleteDC(dc_mask);
::DeleteDC(dc_buffer);
::DeleteObject(buffer_bmap);
--
Red Hat UK Ltd, Unit 200 Rustat House, 62 Clifton Road, Cambridge, UK. CB1 7EG Tel: +44 (1223) 271063