⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtwin.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			     lWindowHeight);	}// /END XXXEH-1. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */#endif /* !(USE_FREETYPE_DIRECTLY). */	IHXVideoSurface* pVideoSurface = (IHXVideoSurface*)((HXxEvent*)pVoid)->param1;	pVideoSurface->AddRef();	if(!pTextWindow->m_bHandlingWindowResizing		&&  pTextWindow->m_hBitmap)//avoid race condition				      // when re-allocating offscreen bitmap:	{#if defined(XXXMEH_BACKGROUND_NO_GDI) && defined(HANDLE_TRANSPARENT_WINDOW_BACKGROUND)            DWORD oldComp = pHeader->biCompression;            if (pTextWindow->getBackgroundOpacity() < 255 ||                pTextWindow->getMediaOpacity() < 255 ||                bChromaKeyWasApplied)            {                pHeader->biCompression = HX_ARGB;            }#endif	    ((HXxEvent*)pVoid)->result = pVideoSurface->Blt(		    pBits + lImageOffset,		    (HXBitmapInfoHeader*)pHeader,		    destRect, 		    srcRect);#if defined(XXXMEH_BACKGROUND_NO_GDI) && defined(HANDLE_TRANSPARENT_WINDOW_BACKGROUND)            pHeader->biCompression = oldComp;#endif	}#if defined(SCROLLINGVERSION_SCROLL_BY_MOVING_WINDOW)	if (lSavedHeaderHeight > 0)	{	    pHeader->biHeight = lSavedHeaderHeight; //Restore it for the next time.	}#endif	HX_RELEASE(pVideoSurface);    }    else    {	b_FunctionSucceeded = FALSE;    }        return b_FunctionSucceeded;}/////////////////////////////////////////////////////////////////////////////// Function://  BOOL//  PaintBackground//  (//  	TextWindow* pTextWindow,//  	void* pPaintstruct//  )//// Purpose://  This function paints the background of the window at the given rectangle//  of pPaintstruct.//  This Function is called from WM_PAINT, and pPaintstruct is (in Windows)//  from  BeginPaint(); pPaintstruct holds the invalid rectangle to be//  updated.//// Returns://  Returns FALSE on error, TRUE otherwise. //BOOL PaintBackground(TextWindow* pTextWindow, void* pPaintstruct){    HX_ASSERT_VALID_PTR(pTextWindow);    HX_ASSERT_VALID_PTR(pPaintstruct);    if(!pTextWindow  ||  !pPaintstruct)    {	return FALSE;    }    RECT updateRect = ((PAINTSTRUCT*)pPaintstruct)->rcPaint;    // If backgroundOpacity is specified, then we will use it.    // If backgroundOpacity is not specified, then we will    // see if the chromaKey is specified. If it is, then    // we will check if the background color is the same    // as the chromakey. If it is, then we will use the    // chromakey opacity for the background.    UINT32 ulOpacity = pTextWindow->getBackgroundOpacity();    if (pTextWindow->isChromaKeySet())    {        if (DoesChromaKeyMatch(pTextWindow->getBackgroundColor(),                               pTextWindow->getChromaKey(),                               pTextWindow->getChromaKeyTolerance()))        {            ulOpacity = pTextWindow->getChromaKeyOpacity();        }    }    BOOL bIsPaintBackgroundCall = TRUE;    return PaintRectangle(pTextWindow, updateRect,	    (COLORREF)pTextWindow->getBackgroundColor(),            ulOpacity, bIsPaintBackgroundCall);}BOOL PaintRectangle(TextWindow* pTextWindow, RECT& updateRect,		    COLORREF rectColor, UINT32 ulOpacity,		    BOOL bIsPaintBackgroundCall){    HX_ASSERT_VALID_PTR(pTextWindow);    if(!pTextWindow)    {	return FALSE;    }#if defined(XXXMEH_BACKGROUND_NO_GDI)// The following code only works for 32bpp#if defined(USE_16_BIT_COLOR_DEPTH)#error Cannot define both XXXMEH_BACKGROUND_NO_GDI and USE_16_BIT_COLOR_DEPTH#endif    UCHAR*             pBits   = NULL;    LPBITMAPINFOHEADER pHeader = NULL;#if !defined(USE_DIB_SECTION)    // convert HBITMAP to DIB:    pTextWindow->m_hDIB->GetDIBits(hDC, hBM, pBits, pHeader);#else    //we already have a DIB, so use it:    pBits   = (UCHAR*)(pTextWindow->m_pBits);    pHeader = &(pTextWindow->m_BITMAPINFOHEADER);#endif    // Compute the color to copy    UINT32* pulBits   = (UINT32*) pBits;    UINT32  ulColor   = rectColor; // /Use rectColor! fixes PR 56578.    if (ulOpacity > 255) ulOpacity = 255;    UINT32  ulAlpha   = 255 - ulOpacity;    UINT32  ulColorA  = (ulColor & 0x00FFFFFF) |                        (ulAlpha << 24);    RECT updateRectAdjustedForTopDown;    updateRectAdjustedForTopDown.left = updateRect.left;    updateRectAdjustedForTopDown.right = updateRect.right;    // /Fixes PR 62883: if left is less than 0 (as can happen with underlined    // text in a crawling (horizontally-scrolling) window, then clip it at 0    // so we don't try to draw beyond the bounds of the offscreen bitmap:    if (updateRectAdjustedForTopDown.left < 0)    {	updateRectAdjustedForTopDown.left = 0;    }    // /If right is less than left, then there's nothing to draw:    if (updateRectAdjustedForTopDown.right < updateRectAdjustedForTopDown.left)    {	return FALSE;    }    // /Inverting these fixes PR 56577.  In Windows, the bitmap is inverted    // so we need to draw top-down instead of bottom up otherwise underlines,    // strike-throughs, and font bgcolor rects will get drawn inverted in y.    // The bonus side-effect of this fix is that it also fixes PR 54635,    // where the entire window's background was not drawing at lines 0 to n    // if 0<n<4 and where n is the difference between the actual 4-pixel-aligned    // width of the DIB and the calculated window width and height.    updateRectAdjustedForTopDown.bottom =	    (UINT32)pHeader->biHeight - updateRect.top;    updateRectAdjustedForTopDown.top =	    (UINT32)pHeader->biHeight - updateRect.bottom;    // /Fixes PR 56145: if updateRect.right is out of bounds (beyond the    // pHeader's biWidth), then don't count on that being clipped by the    // OS.  Just reduce it to pHeader->biWidth here to prevent accessing    // beyond the buffer.  (The old GDI call used to clip the rect which    // is why RT didn't used to crash when the text string bounding box    // extended beyond the width of the offscreen area):    if ((UINT32)updateRectAdjustedForTopDown.right > (UINT32)pHeader->biWidth)    {	updateRectAdjustedForTopDown.right = pHeader->biWidth;    }    // /Do same fix for vertical:    if ((UINT32)updateRectAdjustedForTopDown.bottom > (UINT32)pHeader->biHeight)    {	updateRectAdjustedForTopDown.bottom = pHeader->biHeight;    }    // /Fixes part 2 of PR 54635: if this is a paintBackground rect call,    // then we need to paint into the 0 to 3 extra 4-byte-aligned pixels    // width-wise.  (Part 1 of PR 54635 is a height-only problem):    if (bIsPaintBackgroundCall)    {	INT32 lDiff = pHeader->biWidth - updateRectAdjustedForTopDown.right;	if (0 < lDiff  &&  lDiff < 4)	{	    updateRectAdjustedForTopDown.right = pHeader->biWidth;	}    }        // Copy the color 32bits at a time    UINT32  ulWidth = (UINT32) pHeader->biWidth;    UINT32  ulX     = (UINT32) updateRectAdjustedForTopDown.left;    UINT32  ulNumX  = (UINT32) updateRectAdjustedForTopDown.right -	    updateRectAdjustedForTopDown.left;    for (UINT32 ulY = (UINT32) updateRectAdjustedForTopDown.top;	    ulY < (UINT32) updateRectAdjustedForTopDown.bottom;	    ulY++)    {        UINT32* pPix  = pulBits + ulY * ulWidth + ulX;        UINT32  ulNum = ulNumX;        while (ulNum--)        {            *pPix++ = ulColorA;        }    }#else    HBRUSH hBrush, hBrushOld;    LOGBRUSH logBrush;#if defined (HANDLE_TRANSPARENT_WINDOW_BACKGROUND)    ULONG32 ulAlpha = 0xFF000000 & rectColor;    if (BAD_RGB_COLOR == rectColor)    {	ulAlpha = 0;    }#endif    logBrush.lbStyle = BS_SOLID;    logBrush.lbColor = convertCOLORTYPEtoWinBGRColor(rectColor);#if defined (HANDLE_TRANSPARENT_WINDOW_BACKGROUND)    logBrush.lbColor |= ulAlpha;#endif    hBrush = CreateBrushIndirect(&logBrush);    if(!hBrush)    {	return FALSE;    }    hBrushOld = (HBRUSH)SelectObject(	    (HDC)pTextWindow->m_pDeviceContextMemory,	    hBrush);    if(!hBrushOld)    {	DeleteObject(hBrush);	return FALSE;    }    //Added this so black edge is not drawn around window:    HPEN hPen, hPenOld;    LOGPEN logPen;    logPen.lopnStyle = PS_NULL;    hPen = CreatePenIndirect(&logPen);    if(!hPen)    {	return FALSE;    }    hPenOld = (HPEN)SelectObject(	    (HDC)pTextWindow->m_pDeviceContextMemory,	    hPen);    if(!hPenOld)    {	DeleteObject(hPen);	return FALSE;    }    Rectangle((HDC)pTextWindow->m_pDeviceContextMemory, 	    updateRect.left,updateRect.top,	    updateRect.right+1, updateRect.bottom+1);    SelectObject((HDC)pTextWindow->m_pDeviceContextMemory,	    hBrushOld);    DeleteObject(hBrush);    SelectObject((HDC)pTextWindow->m_pDeviceContextMemory,	    hPenOld);    DeleteObject(hPen);#endif    return TRUE;}BOOL ApplyTextOpacity(TextWindow* pTextWindow,                      INT32       lX,                      INT32       lY,                      INT32       lW,                      INT32       lH,                      BOOL        bRowsInverted,                      UINT32      ulColor,                      UINT32      ulOpacity){    BOOL bRet = TRUE;#if defined(XXXMEH_BACKGROUND_NO_GDI)#if defined(USE_16_BIT_COLOR_DEPTH)#error Cannot define both XXXMEH_BACKGROUND_NO_GDI and USE_16_BIT_COLOR_DEPTH#endif    UCHAR*             pBits   = NULL;    LPBITMAPINFOHEADER pHeader = NULL;#if !defined(USE_DIB_SECTION)    // convert HBITMAP to DIB:    pTextWindow->m_hDIB->GetDIBits(hDC, hBM, pBits, pHeader);#else    //we already have a DIB, so use it:    pBits   = (UCHAR*)(pTextWindow->m_pBits);    pHeader = &(pTextWindow->m_BITMAPINFOHEADER);#endif    // Make sure the color to match doesn't already    // have an alpha value    UINT32 ulColorNoAlpha = ulColor & 0x00FFFFFF;    // Compute the alpha to set    if (ulOpacity > 255) ulOpacity = 255;    UINT32  ulAlphaShifted = (255 - ulOpacity) << 24;    // Run through the rectangle    UINT32* pulBits  = (UINT32*) pBits;    // /Use of lMaxRows in the for loop, below, fixes PR 66089: crash when    // resizing semi-opaque plain text.  Don't exceed the bitmap boundaries:    LONG32 lMaxRows = pHeader->biHeight;    LONG32 lWBoundsChecked = lW < pHeader->biWidth? lW : pHeader->biWidth-1;    for (INT32 lRow = lY; lRow < lY + lH  &&  lRow < lMaxRows; lRow++)    {        UINT32* pPix  = pulBits +                        (bRowsInverted ? pHeader->biHeight - 1 - lRow : lRow) *                         pHeader->biWidth + lX;        UINT32  ulNum = (UINT32) lWBoundsChecked; // /For PR 66089.        while (ulNum--)        {            // Is this one of the colors that we are looking for?            UINT32 ulPixNoAlpha = *pPix & 0x00FFFFFF;            if (ulPixNoAlpha == ulColorNoAlpha)            {                *pPix = ulPixNoAlpha | ulAlphaShifted;            }            pPix++;        }    }#endif    return bRet;}BOOL DoesChromaKeyChannelMatch(UINT32 ulColor,                               UINT32 ulChromaKey,                               UINT32 ulChromaKeyTol){    BOOL bRet = FALSE;    INT32 lDiff = ((INT32) ulColor) - ((INT32) ulChromaKey);    if (lDiff < 0)    {        lDiff = -lDiff;    }    if (lDiff <= (INT32) ulChromaKeyTol)    {        bRet = TRUE;    }    return bRet;}#define ARGB32_RED(a)   (((a) & 0x00FF0000) >> 16)#define ARGB32_GREEN(a) (((a) & 0x0000FF00) >>  8)#define ARGB32_BLUE(a)   ((a) & 0x000000FF)BOOL DoesChromaKeyMatch(UINT32 ulColor,                        UINT32 ulChromaKey,                        UINT32 ulChromaKeyTol){    BOOL bRet = FALSE;    if (DoesChromaKeyChannelMatch(ARGB32_RED(ulColor),                                  ARGB32_RED(ulChromaKey),                                  ARGB32_RED(ulChromaKeyTol)) &&        DoesChromaKeyChannelMatch(ARGB32_GREEN(ulColor),                                  ARGB32_GREEN(ulChromaKey),                                  ARGB32_GREEN(ulChromaKeyTol)) &&        DoesChromaKeyChannelMatch(ARGB32_BLUE(ulColor),                                  ARGB32_BLUE(ulChromaKey),                                  ARGB32_BLUE(ulChromaKeyTol)))    {        bRet = TRUE;    }    return bRet;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -