📄 winroot.cpp
字号:
WinDrawSurface_SetClipper(&m_windraw, (HWND) pWindow->window);
}
*/
/* if( m_boundsRect.bottom > m_boundsRect.top && m_boundsRect.left < m_boundsRect.right)
{
// {
// char szBuff[256];
// sprintf( szBuff,"Bounding Rect: (%d, %d) --- (%d, %d)\n",
// m_boundsRect.left, m_boundsRect.top,
// m_boundsRect.right, m_boundsRect.bottom);
// _DumpString(szBuff);
// }
if (NOERROR == WinDrawSurface_Blt(&m_windraw, &m_compositionSurface, (RECT*)&m_boundsRect, (RECT*)&m_boundsRect))
{
retVal = HXR_OK;
}
} */
if (m_pBltRects.GetCount())
{
while(m_pBltRects.GetCount())
{
HXxRect* pRect = (HXxRect*) m_pBltRects.RemoveHead();
if (NOERROR == WinDrawSurface_Blt(&m_windraw, &m_compositionSurface, (RECT*)pRect, (RECT*)pRect))
{
retVal = HXR_OK;
}
HX_DELETE(pRect);
}
}
}
}
return retVal;
}
HX_RESULT CWinBaseRootSurface::ScratchLock(UCHAR** pBits, INT32* pPitch)
{
HX_RESULT retVal = HXR_FAIL;
if (NOERROR == WinDrawSurface_Lock(&m_windraw, &m_scratchSurface, 0,
(void**) &m_pScratchSurface, (LONG*)&m_nScratchPitch))
{
retVal = HXR_OK;
HX_ASSERT(m_pScratchSurface);
*pBits = m_pScratchSurface;
*pPitch = m_nScratchPitch;
}
return retVal;
}
HX_RESULT CWinBaseRootSurface::ScratchUnlock(UCHAR* pBits)
{
HX_RESULT retVal = HXR_FAIL;
if (NOERROR == WinDrawSurface_Unlock(&m_windraw, &m_scratchSurface, 0))
{
m_pScratchSurface = NULL;
}
return retVal;
}
HX_RESULT CWinBaseRootSurface::CreateScratchSurface(int nCompositionSurfaceCID, HXxSize* pSize)
{
HX_RESULT retVal = HXR_FAIL;
if (m_bScratchSurfaceCreated &&
m_nScratchSurfaceCID == nCompositionSurfaceCID &&
pSize->cx <= m_allocatedScratchSize.cx &&
pSize->cy <= m_allocatedScratchSize.cy)
{
if (m_scratchSize.cx != pSize->cx || m_scratchSize.cy != pSize->cy)
{
memcpy(&m_scratchSize, pSize, sizeof(HXxSize)); /* Flawfinder: ignore */
}
return HXR_OK;
}
else
{
DestroyScratchSurface();
}
HX_ASSERT(m_bScratchSurfaceCreated == FALSE);
m_nScratchSurfaceCID = nCompositionSurfaceCID;
// create a BMI to describe the composition surface
memcpy(&m_scratchSize, pSize, sizeof(HXxSize)); /* Flawfinder: ignore */
memcpy(&m_allocatedScratchSize, pSize, sizeof(HXxSize)); /* Flawfinder: ignore */
BMI primaryBMI;
memset(&primaryBMI, 0, sizeof(BMI));
MakeBitmap((LPBITMAPINFO)&primaryBMI, sizeof(BMI), m_nScratchSurfaceCID, m_allocatedScratchSize.cx, m_allocatedScratchSize.cy, NULL, NULL);
// now attempt to create the surface
memset(&m_scratchSurface, 0, sizeof(WINDRAWSURFACE));
if (NOERROR == WinDraw2_CreateSurface(&m_windraw, &m_scratchSurface, &primaryBMI, m_fSurfaceType, 0, 0))
{
retVal = HXR_OK;
m_bScratchSurfaceCreated = TRUE;
}
return retVal;
}
HX_RESULT CWinBaseRootSurface::DestroyScratchSurface()
{
HX_RESULT retVal = HXR_OK;
if (m_bScratchSurfaceCreated)
{
if (NOERROR == WinDraw2_ReleaseSurface(&m_windraw, &m_scratchSurface))
{
m_bScratchSurfaceCreated = FALSE;
retVal = HXR_OK;
}
else
{
retVal = HXR_FAIL;
}
}
return retVal;
}
void CWinBaseRootSurface::SetFullScreen()
{
m_bBltLock = FALSE;
RECT boundRect = {0,0,0,0};
boundRect.right = GetSystemMetrics(SM_CXSCREEN);
boundRect.bottom = GetSystemMetrics(SM_CYSCREEN);
WinDrawSurface_Blt(&m_windraw, &m_compositionSurface, (RECT*)&boundRect, (RECT*)&boundRect);
}
void CWinBaseRootSurface::PrepareExitFullScreen()
{
memcpy(&m_compositionSize, &m_pSite->m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
}
void CWinBaseRootSurface::RestoreResolution()
{
WinDraw2_RestoreResolution(&m_windraw);
}
void CWinBaseRootSurface::_AdjustLastAppendedRectangle(REF(CHXSimpleList) rectList)
{
}
void CWinBaseRootSurface::_PreFlightBlt(HXxRect& dst)
{
}
void CWinBaseRootSurface::PrepareFullScreen()
{
HDC hDC;
WinDrawSurface_GetDC(&m_windraw, &m_compositionSurface, &hDC);
HBRUSH blackBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
HBRUSH oldBrush = (HBRUSH)SelectObject(hDC, blackBrush);
HPEN nullPen = (HPEN)GetStockObject(NULL_PEN);
HPEN oldPen = (HPEN)SelectObject(hDC, nullPen);
Rectangle(hDC, 0,0, m_allocatedCompositionSize.cx, m_allocatedCompositionSize.cy);
SelectObject(hDC, oldBrush);
SelectObject(hDC, oldPen);
WinDrawSurface_ReleaseDC(&m_windraw, &m_compositionSurface, hDC);
HXxWindow* pWindow = m_pSite->GetWindow();
if (pWindow && pWindow->window)
{
HWND hwnd = (HWND) pWindow->window;
hDC = GetDC(hwnd);
RECT destRect;
GetClientRect(hwnd, &destRect);
oldBrush = (HBRUSH)SelectObject(hDC, blackBrush);
oldPen = (HPEN)SelectObject(hDC, nullPen);
Rectangle(hDC, 0, 0, destRect.right+1, destRect.bottom+1);
SelectObject(hDC, oldBrush);
SelectObject(hDC, oldPen);
ReleaseDC(hwnd, hDC);
}
m_bBltLock = TRUE;
}
void CWinBaseRootSurface::GetDisplayModes(CModesDesc* pModesDesc, INT32* nNumModes)
{
OpenWindraw();
WinDraw2_GetModes(&m_windraw, pModesDesc, (UINT32*)nNumModes);
}
void CWinBaseRootSurface::SetResolution(int width, int height, int depth, void* hwnd)
{
OpenWindraw();
WinDraw2_SetResolution(&m_windraw, width, height, depth, (HWND)hwnd);
m_pCompMutex->Lock();
_DestroyCompositionSurface();
_CreateCompositionSurface();
m_pCompMutex->Unlock();
}
BOOL CWinBaseRootSurface::_OptimizedSurfaceOpened()
{
return m_bWindrawOpened;
}
void CWinBaseRootSurface::SelectFont(HDC hDC)
{
if (!m_hFont)
{
int oldMappingMode = SetMapMode( hDC, MM_TEXT );
int nHeight = -MulDiv(50, GetDeviceCaps(hDC, LOGPIXELSY), 72);
m_hFont = CreateFont(nHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Ariel");
SetMapMode( hDC, oldMappingMode);
}
m_hOldFont = (HFONT)SelectObject(hDC, m_hFont);
}
void CWinBaseRootSurface::UnSelectFont(HDC hDC)
{
SelectObject(hDC, m_hOldFont);
}
void CWinBaseRootSurface::CreateTextAlpha(COverlay* pOverlay)
{
/*
* The default function for text overlays is that anywhere
* that the pixels are set to a value the alpha will be set to
* 128, everywhere else it will be set to 0
*/
UINT32* pPixels = (UINT32*)pOverlay->LockOverlay();
UCHAR* pAlpha = pOverlay->GetAlpha();
HXxSize size;
pOverlay->GetSize(size);
int x,y;
int nCID = pOverlay->GetCID();
UINT32 rgbValue = 0;
int state =0;
switch(nCID)
{
case CID_RGB32:
case CID_RGB24:
for(y=0; y<size.cy; y++)
{
for(x=0;x<size.cx;x++, pAlpha++)
{
switch(state)
{
case 0:
{
rgbValue = (*pPixels && 0xFFFFFF00)>>8;
state = 1;
break;
}
case 1:
{
rgbValue = ((*pPixels && 0x000000FF)<<16);
pPixels++;
rgbValue += ((*pPixels && 0xFFFFF0000)>>16);
state = 2;
break;
}
case 2:
{
rgbValue = ((*pPixels && 0x0000FFFF)<<8);
pPixels++;
rgbValue += ((*pPixels && 0xFF000000)>>24);
state = 3;
break;
}
case 3:
{
rgbValue = ((*pPixels && 0x00FFFFFF));
pPixels++;
state = 0;
break;
}
}
*pAlpha = rgbValue ? 255 : 0;
}
}
break;
}
pOverlay->UnlockOverlay();
}
#if 0
void CWinBaseRootSurface::DrawFocusRect(WINDRAWSURFACE *pSurface,
int nSurfaceCID,
HXxSize *pSurfaceSize,
UCHAR *pVidMem,
CHXBaseSite* pSite)
{
// Draw the focus for this site
HXBitmapInfoHeader info;
memset(&info, 0, sizeof(info));
MakeBitmap((LPBITMAPINFO)&info, sizeof(info), nSurfaceCID,
pSurfaceSize->cx, pSurfaceSize->cy, NULL, NULL);
HDC hdc = 0;
WinDrawSurface_GetDC(&m_windraw, pSurface, &hdc);
HXxRect rc = {0,0,pSurfaceSize->cx, pSurfaceSize->cy};
pSite->_DrawFocusRect(pVidMem,
&info,
&rc,
(void*)&hdc);
WinDrawSurface_ReleaseDC(&m_windraw, pSurface, hdc);
}
#endif
void CWinBaseRootSurface::DrawText()
{
SIZE textSize;
m_bShowingText = TRUE;
HXxSize overlaySize;
COverlay* pOverlay;
if (!m_overlayMgr.GetOverlay(TEXTOVERLAY, (COverlay**)&pOverlay))
{
HDC hDC = GetDC(NULL);
SelectFont(hDC);
GetTextExtentPoint(hDC, "XXX", 4, &textSize);
UnSelectFont(hDC);
ReleaseDC(0, hDC);
overlaySize.cx = m_allocatedCompositionSize.cx;
overlaySize.cy = textSize.cy+4;
pOverlay = new COverlay(&m_windraw);
pOverlay->CreateOverlay(overlaySize, m_nCompositionSurfaceCID);
m_overlayMgr.AddOverlay(TEXTOVERLAY, pOverlay);
}
else
{
pOverlay->GetSize(overlaySize);
if (overlaySize.cx < m_allocatedCompositionSize.cx)
{
m_overlayMgr.RemoveOverlay(TEXTOVERLAY, &m_compositionSurface);
overlaySize.cx = m_allocatedCompositionSize.cx;
pOverlay->CreateOverlay(overlaySize, m_nCompositionSurfaceCID);
m_overlayMgr.AddOverlay(TEXTOVERLAY, pOverlay);
}
}
RECT boundsRect;
boundsRect.left = 0;
boundsRect.top = 0;
boundsRect.right = m_compositionSize.cx;
boundsRect.bottom = textSize.cy;
/*
* create ther drawing surface
*/
HDC hMemDC = NULL;
pOverlay->GetDC(&hMemDC);
if (!m_hBrush)
{
LOGBRUSH brush;
brush.lbStyle = BS_SOLID;
brush.lbColor = m_nTextBackgroundColor;
brush.lbHatch = 0;
m_hBrush = CreateBrushIndirect(&brush);
}
if (!m_hPen)
{
m_hPen = CreatePen(PS_SOLID, 0, m_textColor);
}
HBRUSH hOldBrush = (HBRUSH)SelectObject(hMemDC, m_hBrush);
HPEN hOldPen = (HPEN)SelectObject(hMemDC, m_hPen);
/*
* figure out how much text we should use.
*/
CHXString finalString = m_sStatusText;
HXxPoint textOffset;
SelectFont(hMemDC);
int length = m_sStatusText.GetLength();
GetTextExtentPoint(hMemDC, (const char*)m_sStatusText, m_sStatusText.GetLength(), &textSize);
if (textSize.cx > (boundsRect.right - boundsRect.left - 4))
{
/*
* we will loop to find out where to put the elipise
*/
for (int i = 1; i <= m_sStatusText.GetLength(); i++)
{
GetTextExtentPoint(hMemDC, (const char*)m_sStatusText, i, &textSize);
if (textSize.cx > (boundsRect.right - boundsRect.left - 4))
{
for(int j = i - 1; j > 0 ; j--)
{
finalString = m_sStatusText.Left(j);
finalString = finalString + "...";
GetTextExtentPoint(hMemDC, (const char*)finalString, finalString.GetLength(), &textSize);
if (textSize.cx > (boundsRect.right - boundsRect.left - 4))
{
continue;
}
break;
}
textOffset.x = 3;
textOffset.y = 3;
}
}
}
else
{
textOffset.x = (m_compositionSize.cx - textSize.cx) / 2;
textOffset.y = 3;
}
/*
* Do the drawing
*/
RECT rectBounds;
rectBounds.left = (m_compositionSize.cx - textSize.cx)/2 - 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -