From 9fb590097d389ab47445a157d1bf6a27a59e36db Mon Sep 17 00:00:00 2001 From: nedko Date: Sun, 3 Aug 2003 16:56:29 +0000 Subject: [PATCH] Flush current work --- Makefile | 4 +- desktopswitcher.cpp | 14 +++-- png.cpp | 114 +++++++++++++++++++------------------ png.h | 9 ++- switcherwindow.cpp | 160 ++++++++++++++-------------------------------------- switcherwindow.h | 6 +- 6 files changed, 123 insertions(+), 184 deletions(-) diff --git a/Makefile b/Makefile index 15ff203..a1c679d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.4 2002/06/29 15:05:41 nedko Exp $ +# $Id: Makefile,v 1.5 2003/08/03 16:56:29 nedko Exp $ # # Desktop Switcher # Copyright (C) 2000,2001,2002 Nedko Arnaudov @@ -38,7 +38,7 @@ switcher.obj: ph.h switcher.cpp switcher.h DesktopSwitcher.h png.h RunDialog.obj: ph.h RunDialog.cpp RunDialog.h $(cc) RunDialog.cpp -SwitcherWindow.obj: ph.h SwitcherWindow.cpp SwitcherWindow.h DesktopSwitcher.h RunDialog.h switcher.h ShadowWindow.h +SwitcherWindow.obj: ph.h SwitcherWindow.cpp SwitcherWindow.h DesktopSwitcher.h RunDialog.h switcher.h ShadowWindow.h png.h $(cc) SwitcherWindow.cpp Desktop.obj: ph.h Desktop.cpp Desktop.h SwitcherWindow.h switcher.h ShadowWindow.h diff --git a/desktopswitcher.cpp b/desktopswitcher.cpp index 2453dfa..ff562e7 100644 --- a/desktopswitcher.cpp +++ b/desktopswitcher.cpp @@ -1,4 +1,4 @@ -// $Id: desktopswitcher.cpp,v 1.1 2002/05/29 22:06:50 nedko Exp $ +// $Id: desktopswitcher.cpp,v 1.2 2003/08/03 16:56:29 nedko Exp $ // // Desktop Switcher // Copyright (C) 2000,2001,2002 Nedko Arnaudov @@ -175,10 +175,15 @@ HRESULT CDesktopSwitcher::HotKeyPressed(WORD wVKey, WORD wModifiers) return S_OK; } - if (wVKey == 'R' && wModifiers == (MOD_WIN|MOD_SHIFT)) + else if (wVKey == 'R' && wModifiers == (MOD_WIN|MOD_SHIFT)) { - m_ppDesktops[m_nCurrentDesktopIndex]->RunPrompt(); - return S_OK; + m_ppDesktops[m_nCurrentDesktopIndex]->RunPrompt(); + return S_OK; + } + else if (wVKey == VK_ESCAPE && wModifiers == (MOD_WIN)) + { + Exit(); + return S_OK; } return S_FALSE; @@ -193,4 +198,5 @@ void CDesktopSwitcher::RegisterHotKeys(HWND hWnd) RegisterHotKey(hWnd, VK_ADD, MOD_WIN, VK_ADD); RegisterHotKey(hWnd, VK_SUBTRACT, MOD_WIN, VK_SUBTRACT); RegisterHotKey(hWnd, 'R', MOD_WIN|MOD_SHIFT, 'R'); + RegisterHotKey(hWnd, VK_ESCAPE, MOD_WIN, VK_ESCAPE); } diff --git a/png.cpp b/png.cpp index 6f7cabc..83a488c 100644 --- a/png.cpp +++ b/png.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////////// // -// $Id: png.cpp,v 1.3 2002/06/29 16:00:28 nedko Exp $ +// $Id: png.cpp,v 1.4 2003/08/03 16:56:29 nedko Exp $ // // DESCRIPTION: // @@ -98,6 +98,8 @@ CPNGImage::LoadPNGImage(const char *pszPath) memcpy(m_pData + m_nWidth * 4 * y,row_pointers[y],m_nWidth*4); } + PremultiplyAlpha(m_nWidth, m_nHeight, m_pData); + /* clean up after the read, and free any memory allocated - REQUIRED */ png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); @@ -119,66 +121,79 @@ CPNGImage::GetHeight() return m_nHeight; } -bool -CPNGImage::SelectBitmap(HDC hMemoryDC) +HBITMAP +CPNGImage::CreateBitmap(HDC hMemoryDC) { - BITMAPV4HEADER BIH; - ZeroMemory(&BIH,sizeof(BIH)); - BIH.bV4Size = sizeof(BIH); HBITMAP hBitmap; - unsigned int x,y; - unsigned char *pPixel; + BITMAPINFO bi; + ZeroMemory(&bi,sizeof(bi)); + bi.bmiHeader.biSize = sizeof(bi.bmiHeader); + bi.bmiHeader.biWidth = m_nWidth; + bi.bmiHeader.biHeight = m_nHeight; + bi.bmiHeader.biPlanes = 1; + bi.bmiHeader.biBitCount = 32; + bi.bmiHeader.biCompression = BI_RGB; + + void *pDIBBits; + + hBitmap = ::CreateDIBSection(hMemoryDC,&bi,DIB_RGB_COLORS,&pDIBBits,NULL,0); if (m_pData) { - hBitmap = CreateBitmap(m_nWidth,m_nHeight,1,32,m_pData); + memcpy(pDIBBits, m_pData, m_nWidth * m_nHeight * 4); } else { - unsigned char *pInternalData = new unsigned char[m_nWidth*m_nHeight*4]; - for (y = 0 ; y < m_nHeight; y++) - { - pPixel= pInternalData + m_nWidth * 4 * y; - - for (x = 0 ; x < m_nWidth ; x++) - { - pPixel[0]= NOT_LOADED_BITMAP_BLUE; - pPixel[1]= NOT_LOADED_BITMAP_GREEN; - pPixel[2]= NOT_LOADED_BITMAP_RED; - pPixel[3]= NOT_LOADED_BITMAP_ALPHA; + unsigned char *pData = GenerateNotLoadedBitmapData(m_nWidth, m_nHeight); - pPixel+= 4; - } - } + memcpy(pDIBBits, pData, m_nWidth * m_nHeight * 4); - hBitmap = CreateBitmap(m_nWidth,m_nHeight,1,32,pInternalData); - - delete pInternalData; + delete pData; } - if (!hBitmap) - return false; - - if (!GetDIBits(hMemoryDC, hBitmap, 0, 0, NULL, (BITMAPINFO *)&BIH, DIB_RGB_COLORS)) - return false; + return hBitmap; +} - BIH.bV4RedMask = 0x00FF0000; - BIH.bV4GreenMask = 0x0000FF00; - BIH.bV4BlueMask = 0x000000FF; - BIH.bV4AlphaMask = 0xFF000000; +unsigned char * +CPNGImage::GenerateNotLoadedBitmapData(unsigned int nWidth, unsigned int nHeight) +{ + unsigned int x,y; + unsigned char *pPixel; - unsigned char *pData = new unsigned char[BIH.bV4SizeImage]; - if (!GetDIBits(hMemoryDC, hBitmap, 0, BIH.bV4Height, pData, (BITMAPINFO *)&BIH, DIB_RGB_COLORS)) + unsigned char *pData = new unsigned char[nWidth*nHeight*4]; + for (y = 0 ; y < nHeight; y++) { - delete pData; - return false; + pPixel= pData + nWidth * 4 * y; + + for (x = 0 ; x < nWidth ; x++) + { + pPixel[0]= NOT_LOADED_BITMAP_BLUE; + pPixel[1]= NOT_LOADED_BITMAP_GREEN; + pPixel[2]= NOT_LOADED_BITMAP_RED; + pPixel[3]= NOT_LOADED_BITMAP_ALPHA; + + pPixel+= 4; + } } - for (y = 0 ; y < BIH.bV4Height; y++) + PremultiplyAlpha(nWidth, nHeight, pData); + + return pData; +} + +void +CPNGImage::PremultiplyAlpha(unsigned int nWidth, + unsigned int nHeight, + unsigned char *pData) +{ + unsigned int x,y; + unsigned char *pPixel; + + for (y = 0 ; y < nHeight; y++) { - pPixel= pData + BIH.bV4Width * 4 * y; + pPixel = pData + nWidth * 4 * y; - for (x = 0 ; x < BIH.bV4Width ; x++) + for (x = 0 ; x < nWidth ; x++) { pPixel[0]= (unsigned __int8)(((unsigned int)pPixel[0])*pPixel[3]/255); pPixel[1]= (unsigned __int8)(((unsigned int)pPixel[1])*pPixel[3]/255); @@ -186,18 +201,6 @@ CPNGImage::SelectBitmap(HDC hMemoryDC) pPixel+= 4; } } - - if (!SetDIBits(hMemoryDC, hBitmap, 0, BIH.bV4Height, pData, (BITMAPINFO *)&BIH, DIB_RGB_COLORS)) - { - delete pData; - return false; - } - - delete pData; - - SelectObject(hMemoryDC, hBitmap); - - return true; } ///////////////////////////////////////////////////////////////////////////////// @@ -207,6 +210,9 @@ CPNGImage::SelectBitmap(HDC hMemoryDC) // !!! WARNING !!! Following lines are automatically updated by the CVS system. // // $Log: png.cpp,v $ +// Revision 1.4 2003/08/03 16:56:29 nedko +// Flush current work +// // Revision 1.3 2002/06/29 16:00:28 nedko // *** empty log message *** // diff --git a/png.h b/png.h index d3170af..79d3b54 100644 --- a/png.h +++ b/png.h @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////////// // -// $Id: png.h,v 1.1 2002/06/29 15:03:33 nedko Exp $ +// $Id: png.h,v 1.2 2003/08/03 16:56:29 nedko Exp $ // // DESCRIPTION: // @@ -20,9 +20,11 @@ public: bool LoadPNGImage(const char *pszPath); unsigned int GetWidth(); unsigned int GetHeight(); - bool SelectBitmap(HDC hMemoryDC); + HBITMAP CreateBitmap(HDC hMemoryDC); private: static void PNGAPI PNG_ErrorHandler PNGARG((png_structp s, png_const_charp str)); + static void PremultiplyAlpha(unsigned int nWidth, unsigned int nHeight, unsigned char *pData); + static unsigned char * GenerateNotLoadedBitmapData(unsigned int nWidth, unsigned int nHeight); private: unsigned int m_nWidth; @@ -41,6 +43,9 @@ extern CPNGImage g_Image; // !!! WARNING !!! Following lines are automatically updated by the CVS system. // // $Log: png.h,v $ +// Revision 1.2 2003/08/03 16:56:29 nedko +// Flush current work +// // Revision 1.1 2002/06/29 15:03:33 nedko // *** empty log message *** // diff --git a/switcherwindow.cpp b/switcherwindow.cpp index 1be2470..9ad94e5 100644 --- a/switcherwindow.cpp +++ b/switcherwindow.cpp @@ -1,4 +1,4 @@ -// $Id: switcherwindow.cpp,v 1.2 2002/06/29 15:03:33 nedko Exp $ +// $Id: switcherwindow.cpp,v 1.3 2003/08/03 16:56:29 nedko Exp $ // // Desktop Switcher // Copyright (C) 2000,2001,2002 Nedko Arnaudov @@ -34,17 +34,10 @@ CSwitcherWindow::CSwitcherWindow(CDesktopSwitcher *pDesktopSwitcher, CDesktop *p m_pDesktopSwitcher = pDesktopSwitcher; m_pDesktop = pDesktop; m_pMoveWnd = NULL; - m_hBackground = NULL; - m_hdcMemory = NULL; } CSwitcherWindow::~CSwitcherWindow() { - if (m_hBackground) - VERIFY(DeleteObject(m_hBackground)); - - if (m_hdcMemory) - VERIFY(DeleteDC(m_hdcMemory)); } BOOL CSwitcherWindow::Create() @@ -116,125 +109,58 @@ LRESULT CSwitcherWindow::OnRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, void CSwitcherWindow::DrawWindow() { const char *pszDesktopName = m_pDesktop->GetDesktopName(); - - if (pszDesktopName == NULL) - { - Beep(10000,10000); - return; - } - - HDC hdcScreen = ::GetDC(m_hWnd); - - if (m_hdcMemory == NULL) - { - ASSERT(hdcScreen); - m_hdcMemory = ::CreateCompatibleDC(hdcScreen); - ASSERT(m_hdcMemory); - - if (!g_Image.SelectBitmap(m_hdcMemory)) - { - return; - } -/* - const char *pszImage = "C:\\topka.png"; - - BITMAPV4HEADER BIH; - ZeroMemory(&BIH,sizeof(BIH)); - BIH.bV4Size = sizeof(BIH); - - CPNGImage img; - if (img.LoadPNGImage(pszImage)) - { - unsigned char *pInternalData = new unsigned char[327*45*4]; - for (int y = 0 ; y < 45; y++) - { - unsigned char *pPixel= pInternalData + 327 * 4 * y; - - for (int x = 0 ; x < 327 ; x++) - { - pPixel[0]= 0xFF; // blue - pPixel[1]= 0xFF; // green - pPixel[2]= 0xFF; // red - pPixel[3]= 180; // alpha - pPixel+= 4; - } - } - - m_hBackground = CreateBitmap(327,45,1,32,pInternalData); - ASSERT(m_hBackground); - - VERIFY(GetDIBits(m_hdcMemory, m_hBackground, 0, 0, NULL, (BITMAPINFO *)&BIH, DIB_RGB_COLORS)); - - BIH.bV4RedMask = 0x00FF0000; - BIH.bV4GreenMask = 0x0000FF00; - BIH.bV4BlueMask = 0x000000FF; - BIH.bV4AlphaMask = 0xFF000000; - } - else - { - m_hBackground = LoadBitmap(_Module.GetModuleInstance(),MAKEINTRESOURCE(IDB_BACKGROUND)); - ASSERT(m_hBackground); - - VERIFY(GetDIBits(m_hdcMemory, m_hBackground, 0, 0, NULL, (BITMAPINFO *)&BIH, DIB_RGB_COLORS)); - } - - unsigned char *pData = new unsigned char[BIH.bV4SizeImage]; - VERIFY(GetDIBits(m_hdcMemory, m_hBackground, 0, BIH.bV4Height, pData, (BITMAPINFO *)&BIH, DIB_RGB_COLORS)); - - for (int y = 0 ; y < BIH.bV4Height; y++) - { - unsigned char *pPixel= pData + BIH.bV4Width * 4 * y; - - for (int x = 0 ; x < BIH.bV4Width ; x++) - { - pPixel[0]= (unsigned __int8)(((unsigned int)pPixel[0])*pPixel[3]/255); - pPixel[1]= (unsigned __int8)(((unsigned int)pPixel[1])*pPixel[3]/255); - pPixel[2]= (unsigned __int8)(((unsigned int)pPixel[2])*pPixel[3]/255); - pPixel+= 4; - } - } - - if (!SetDIBits(m_hdcMemory, m_hBackground, 0, BIH.bV4Height, pData, (BITMAPINFO *)&BIH, DIB_RGB_COLORS)) - { - char Buffer[256]; - sprintf(Buffer,"SetDIBits() failed. GetLastError() returns %u",GetLastError()); - ::MessageBox(NULL, Buffer, "DesktopSwitcher", MB_OK | MB_ICONINFORMATION); - } - - delete pData; - - SelectObject(m_hdcMemory,m_hBackground); -*/ - } - + HDC hScreenDC = NULL; + HDC hMemoryDC = NULL; + HBITMAP hBitmap = NULL; RECT r; + GetWindowRect(&r); // setup the blend function BLENDFUNCTION blendPixelFunction = { AC_SRC_OVER, 0, 0xFF,AC_SRC_ALPHA }; - POINT ptSrc = {0,0}; // start point of the copy from dcMemory to dcScreen + POINT ptSrc = {0,0}; // start point of the copy from hMemoryDC to hScreenDC POINT ptWindowScreenPosition = {r.left,r.top}; SIZE szWindow = {g_Image.GetWidth(), g_Image.GetHeight()}; - // perform the alpha blend - if (!UpdateLayeredWindow(m_hWnd, - hdcScreen, - &ptWindowScreenPosition, - &szWindow, - m_hdcMemory, - &ptSrc, - 0, - &blendPixelFunction, - ULW_ALPHA)) - { - char Buffer[256]; - sprintf(Buffer,"UpdateLayeredWindow() failed. GetLastError() returns %u",GetLastError()); - ::MessageBox(NULL, Buffer, "DesktopSwitcher", MB_OK | MB_ICONINFORMATION); -// ::MessageBox(NULL, strMsg, "DesktopSwitcher", MB_OK | MB_ICONINFORMATION); - } + if (pszDesktopName == NULL) + goto Exit; - VERIFY(ReleaseDC(hdcScreen)); + hScreenDC = ::GetDC(m_hWnd); + if (hScreenDC == NULL) + goto Exit; + + hMemoryDC = ::CreateCompatibleDC(hScreenDC); + if (hMemoryDC == NULL) + goto Exit; + + hBitmap = g_Image.CreateBitmap(hMemoryDC); + if (hBitmap == NULL) + goto Exit; + + if (SelectObject(hMemoryDC,hBitmap) == NULL) + goto Exit; + + // perform the alpha blend + UpdateLayeredWindow(m_hWnd, + hScreenDC, + &ptWindowScreenPosition, + &szWindow, + hMemoryDC, + &ptSrc, + 0, + &blendPixelFunction, + ULW_ALPHA); + + Exit: + if (hMemoryDC) + VERIFY(DeleteDC(hMemoryDC)); + + if (hScreenDC) + VERIFY(ReleaseDC(hScreenDC)); + + if (hBitmap) + VERIFY(DeleteObject(hBitmap)); } LRESULT CSwitcherWindow::OnNCHitText(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) diff --git a/switcherwindow.h b/switcherwindow.h index adb89db..1f3a8a4 100644 --- a/switcherwindow.h +++ b/switcherwindow.h @@ -1,4 +1,4 @@ -// $Id: switcherwindow.h,v 1.2 2002/06/29 15:03:33 nedko Exp $ +// $Id: switcherwindow.h,v 1.3 2003/08/03 16:56:29 nedko Exp $ // // Desktop Switcher // Copyright (C) 2000,2001,2002 Nedko Arnaudov @@ -73,10 +73,6 @@ private: CShadowWindow *m_pMoveWnd; POINT m_ptMoveBegin; - - HBITMAP m_hBackground; - - HDC m_hdcMemory; }; #endif // #ifndef _SWITCHER_WINDOW_H_f8ade2f7_4bdf_4b29_9e91_fd26a09ff35d__INCLUDED -- 2.11.4.GIT