1 /* Copyright 2000, International Business Machines Corporation and others.
4 This software has been released under the terms of the IBM Public
5 License. For details, see the LICENSE file in the top-level source
6 directory or online at http://www.openafs.org/dl/license10.html
13 static char BASED_CODE THIS_FILE[] = __FILE__;
17 #define rgbWhite RGB(255,255,255)
19 #define DSa 0x008800C6L
20 #define DSx 0x00660046L
23 CTransBmp::CTransBmp()
30 CTransBmp::~CTransBmp()
34 void CTransBmp::GetMetrics()
36 // Get the width and height
38 GetObject(sizeof(bm), &bm);
39 m_iWidth = bm.bmWidth;
40 m_iHeight = bm.bmHeight;
44 int CTransBmp::GetWidth()
46 if ((m_iWidth == 0) || (m_iHeight == 0)){
52 int CTransBmp::GetHeight()
54 if ((m_iWidth == 0) || (m_iHeight == 0)){
60 void CTransBmp::Draw(HDC hDC, int x, int y)
63 HDC hdcMem = ::CreateCompatibleDC(hDC);
65 (HBITMAP)::SelectObject(hdcMem,
66 (HBITMAP)(m_hObject));
70 GetWidth(), GetHeight(),
74 ::SelectObject(hdcMem, hbmold);
78 void CTransBmp::Draw(CDC* pDC, int x, int y)
81 HDC hDC = pDC->GetSafeHdc();
85 void CTransBmp::UpdateMask(CWnd *wnd,CRect &rect)
88 ::DeleteObject(m_hbmMask);
90 wnd->InvalidateRect(rect,TRUE);
93 void CTransBmp::CreateMask(HDC hDC,CRect &rect,int xoff)
96 ::DeleteObject(m_hbmMask);
98 // Create memory DCs to work with
99 HDC hdcMask = ::CreateCompatibleDC(hDC);
100 HDC hdcImage = ::CreateCompatibleDC(hDC);
101 // Create a monochrome bitmap for the mask
102 m_hbmMask = ::CreateBitmap(rect.Width(),
107 // Select the mono bitmap into its DC
108 HBITMAP hbmOldMask = (HBITMAP)::SelectObject(hdcMask, m_hbmMask);
109 // Select the image bitmap into its DC
110 HBITMAP hbmOldImage = (HBITMAP)::SelectObject(hdcImage, m_hObject);
111 // Set the transparency color to be the top-left pixel
112 ::SetBkColor(hdcImage, ::GetPixel(hdcImage, 0, 0));
116 rect.Width(), rect.Height(),
120 ::SelectObject(hdcMask, hbmOldMask);
121 ::SelectObject(hdcImage, hbmOldImage);
123 ::DeleteDC(hdcImage);
127 X,Y Destaination location
131 void CTransBmp::DrawTrans(HDC hDC, CRect &rect, int xoff)
134 if (!m_hbmMask) CreateMask(hDC,rect,xoff);
136 int dx = rect.Width();
137 int dy = rect.Height();
139 // Create a memory DC to do the drawing to
140 HDC hdcOffScr = ::CreateCompatibleDC(hDC);
141 // Create a bitmap for the off-screen DC that is really
142 // color compatible with the destination DC.
143 HBITMAP hbmOffScr = ::CreateBitmap(dx, dy,
144 (BYTE)GetDeviceCaps(hDC, PLANES),
145 (BYTE)GetDeviceCaps(hDC, BITSPIXEL),
147 // Select the buffer bitmap into the off-screen DC
148 HBITMAP hbmOldOffScr = (HBITMAP)::SelectObject(hdcOffScr, hbmOffScr);
150 // Copy the image of the destination rectangle to the
151 // off-screen buffer DC so we can play with it
152 ::BitBlt(hdcOffScr, 0, 0, dx, dy, hDC, 0, 0, SRCCOPY);
154 // Create a memory DC for the source image
155 HDC hdcImage = ::CreateCompatibleDC(hDC);
156 HBITMAP hbmOldImage = (HBITMAP)::SelectObject(hdcImage, m_hObject);
158 // Create a memory DC for the mask
159 HDC hdcMask = ::CreateCompatibleDC(hDC);
160 HBITMAP hbmOldMask = (HBITMAP)::SelectObject(hdcMask, m_hbmMask);
162 // XOR the image with the destination
163 ::SetBkColor(hdcOffScr,rgbWhite);
164 ::BitBlt(hdcOffScr, 0, 0, dx, dy ,hdcImage, xoff, 0, DSx);
165 // AND the destination with the mask
166 ::BitBlt(hdcOffScr, 0, 0, dx, dy, hdcMask, 0,0, DSa);
167 // XOR the destination with the image again
168 ::BitBlt(hdcOffScr, 0, 0, dx, dy, hdcImage, xoff, 0, DSx);
170 // Copy the resultant image back to the screen DC
171 ::BitBlt(hDC, rect.left, rect.top, dx, dy, hdcOffScr, 0, 0, SRCCOPY);
174 ::SelectObject(hdcOffScr, hbmOldOffScr);
175 ::SelectObject(hdcImage, hbmOldImage);
176 ::SelectObject(hdcMask, hbmOldMask);
177 ::DeleteObject(hbmOffScr);
178 ::DeleteDC(hdcOffScr);
179 ::DeleteDC(hdcImage);
183 void CTransBmp::DrawTrans(CDC* pDC,CRect &rect, int xoff)
186 HDC hDC = pDC->GetSafeHdc();
187 DrawTrans(hDC, rect,xoff);