예제 #1
0
LRESULT CChildView::OnNcHitTest(CPoint point)
{
	UINT nHitTest = CWnd::OnNcHitTest(point);

	CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());

	WINDOWPLACEMENT wp;
	pFrame->GetWindowPlacement(&wp);

	if (!pFrame->m_fFullScreen && wp.showCmd != SW_SHOWMAXIMIZED && AfxGetAppSettings().iCaptionMenuMode==MODE_BORDERLESS) {
		CRect rcClient, rcFrame;
		GetWindowRect(&rcFrame);
		rcClient = rcFrame;

		CSize sizeBorder(GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));

		rcClient.InflateRect(-(5 * sizeBorder.cx), -(5 * sizeBorder.cy));
		rcFrame.InflateRect(sizeBorder.cx, sizeBorder.cy);

		if (rcFrame.PtInRect(point)) {
			if (point.x > rcClient.right) {
				if (point.y < rcClient.top) {
					nHitTest = HTTOPRIGHT;
				} else if (point.y > rcClient.bottom) {
					nHitTest = HTBOTTOMRIGHT;
				} else {
					nHitTest = HTRIGHT;
				}
			} else if (point.x < rcClient.left) {
				if (point.y < rcClient.top) {
					nHitTest = HTTOPLEFT;
				} else if (point.y > rcClient.bottom) {
					nHitTest = HTBOTTOMLEFT;
				} else {
					nHitTest = HTLEFT;
				}
			} else if (point.y < rcClient.top) {
				nHitTest = HTTOP;
			} else if (point.y > rcClient.bottom) {
				nHitTest = HTBOTTOM;
			}
		}
	}

	return nHitTest;
}
예제 #2
0
LRESULT CChildView::OnNcHitTest(CPoint point)
{
    LRESULT nHitTest = CWnd::OnNcHitTest(point);

    CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
    bool fLeftMouseBtnUnassigned = !AssignedToCmd(wmcmd::LDOWN);
    if (!pFrame->m_fFullScreen && (pFrame->IsCaptionHidden() || fLeftMouseBtnUnassigned)) {
        CRect rcClient, rcFrame;
        GetWindowRect(&rcFrame);
        rcClient = rcFrame;

        CSize sizeBorder(GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));

        rcClient.InflateRect(-(5 * sizeBorder.cx), -(5 * sizeBorder.cy));
        rcFrame.InflateRect(sizeBorder.cx, sizeBorder.cy);

        if (rcFrame.PtInRect(point)) {
            if (point.x > rcClient.right) {
                if (point.y < rcClient.top) {
                    nHitTest = HTTOPRIGHT;
                } else if (point.y > rcClient.bottom) {
                    nHitTest = HTBOTTOMRIGHT;
                } else {
                    nHitTest = HTRIGHT;
                }
            } else if (point.x < rcClient.left) {
                if (point.y < rcClient.top) {
                    nHitTest = HTTOPLEFT;
                } else if (point.y > rcClient.bottom) {
                    nHitTest = HTBOTTOMLEFT;
                } else {
                    nHitTest = HTLEFT;
                }
            } else if (point.y < rcClient.top) {
                nHitTest = HTTOP;
            } else if (point.y > rcClient.bottom) {
                nHitTest = HTBOTTOM;
            }
        }
    }
    return nHitTest;
}
예제 #3
0
HRESULT TextSprite::VOnRestore()
{
	// Two situations:
	// 1) String should be broken into a multiline entity to fit into a specific area
	// 2) String sent it need should take up as much space H&V that it needs

	// Set the width and height
	CSize sizeText;
	CSize sizeTotal;

	std::wstring multiline;

	if ( m_size.valid() )
	{
		// This is the total to fit into	
		sizeTotal = *m_size;

		// Fit the original text inside the bounds
		multiline = g_pApp->GetFontHandler()->ParseMessage( m_text, m_style, sizeTotal);
		sizeText = g_pApp->GetFontHandler()->GetStringSize(multiline, m_style);
	}
	else
	{
		// Set the width and height
		sizeText = g_pApp->GetFontHandler()->GetStringSize(m_text, m_style);
        sizeTotal = sizeText;

		multiline = m_text;
	}

	int numLines = CountLines(multiline);

	GCC_ASSERT(sizeTotal.cx > 0 && sizeTotal.cy > 0 && "About to create sprite with no width or height, is this what you want?");

	m_TextureWidth = m_Width = sizeTotal.cx;
	m_TextureHeight = m_Height = sizeTotal.cy;
	
	UINT texW = static_cast<UINT>(m_TextureWidth);
	UINT texH = static_cast<UINT>(m_TextureHeight);
	UINT numMipLevels = D3DX_DEFAULT;
	D3DFORMAT format = D3DFMT_UNKNOWN;
	
	// This call will reset width, height, and miplevels to the 
	// correct values.
	if (FAILED (D3DXCheckTextureRequirements(
		DXUTGetD3D9Device(), 
		&texW,
		&texH,
		&numMipLevels,
		0,
		&format,
		D3DPOOL_DEFAULT	) ) )
	{
		return false;
	}

	// Create the texture
	SAFE_RELEASE(m_pTexture);
	if ( FAILED ( DXUTGetD3D9Device()->CreateTexture(
		texW,		// width 
		texH,	// height 
		numMipLevels,		// miplevels - use default
		0,					// useage - default (not a render target or dynamic)
		format,				// format - unknown format
		D3DPOOL_DEFAULT,	// pool - use default
		&m_pTexture,		// the texture pointer
		NULL ) ) )
	{
		return false;
	}

	m_TextureWidth = texW;
	m_TextureHeight = texH;

	// Reinitialize the utility string to count the line breaks
	std::wstring utilString = multiline;

	// Size of border
	CSize sizeBorder( sizeTotal - sizeText );

	int initialX = sizeBorder.cx / 2;
	int initialY = sizeBorder.cy / 2;
	int deltaY = sizeText.cy / numLines;
	
	if (m_isCentered)
	{	
		// Determine how the lines will be spaced vertically
		std::wstring firstLine;
		RemoveFirstLine(utilString, firstLine);
		CSize const firstLineSize = g_pApp->GetFontHandler()->GetStringSize( firstLine, m_style );
		CSize printArea = sizeTotal - sizeBorder;
		bool const fitsVertically = printArea.cy >= firstLineSize.cy * numLines;

		if (fitsVertically)
		{	// Enough room, place lines in the center of the print area
			initialY += (printArea.cy - firstLineSize.cy * numLines) / 2;
			deltaY = firstLineSize.cy;
		}
		else
		{	// Not enough room, squeeze lines on top of each other
			deltaY = printArea.cy / numLines;
			initialY += (deltaY - firstLineSize.cy) / 2;
		}
	}
	else
	{
		deltaY = g_pApp->GetFontHandler()->GetHeight( m_style );
	}

	//Draw each line one at a time
	for(int i=0; i<numLines; ++i)
	{
		std::wstring line;
		RemoveFirstLine(multiline, line);
		
		int x = initialX;
		int y = initialY + i * deltaY;

		if (line.length())
		{
			if ( m_isCentered )
			{
				CSize sizeText = g_pApp->GetFontHandler()->GetStringSize( line, m_style );
				x = x + ( sizeTotal.cx - sizeBorder.cx - sizeText.cx ) / 2;
			}

			if(FAILED(g_pApp->GetFontHandler()->DrawText( this, line, m_style, CPoint( x, y ) ) ) )
				return false;
		}
	}

    return true;
}