コード例 #1
0
void TipWnd::Render()
{
    if (m_Show && !m_vStringLine.empty())
    {
        //先绘制tip窗口
        hgeQuad quad;
        quad.v[0].x = m_OffX - m_OffLeft;
        quad.v[0].y = m_OffY - m_OffTop;
        quad.v[0].tx = 0;
        quad.v[0].ty = 0;
        quad.v[1].x = m_OffX+m_Width + m_OffRight;
        quad.v[1].y = m_OffY - m_OffTop;
        quad.v[1].tx = 1;
        quad.v[1].ty = 0;
        quad.v[2].x = m_OffX+m_Width + m_OffRight;
        quad.v[2].y = m_OffY+m_Height + m_OffBottom;
        quad.v[2].tx = 1;
        quad.v[2].ty = 1;
        quad.v[3].x = m_OffX - m_OffLeft;
        quad.v[3].y = m_OffY+m_Height + m_OffBottom;
        quad.v[3].tx = 0;
        quad.v[3].ty = 1;

        for (int i=0; i<4; i++)
        {
            quad.v[i].col = 0xAF484848;
            quad.v[i].z = 0.5;
        }
        quad.blend = BLEND_DEFAULT_Z;
        quad.tex = 0;
        App::sInstance().GetHGE()->Gfx_RenderQuad(&quad);

        //绘制文字
        m_LastX = m_OffX;
        m_LastY = m_OffY;
        for (VStringLine::iterator it=m_vStringLine.begin(); it!=m_vStringLine.end(); it++)
        {
            GfxFont* font = FontManager::sInstance().GetFont(FontAttr(it->fontType,it->size));
            DWORD color = font->GetColor();
            font->SetColor(it->color);
            //从指定位置绘制文字
            if(it->x!=-1 && it->y!=-1)
            {
                m_LastX = m_OffX + it->x;
                m_LastY = m_OffY + it->y;
                int width = it->x;
                int height = it->y;
                //采用一个一个字符绘制来控制文本宽度不超过tip窗口最大宽度
                SIZE size = font->GetTextSize((*it).str.c_str());
                if(size.cx + it->x <= m_Width)
                {
                    if(height + size.cy >= m_Height)
                        m_Height += size.cy;
                    font->Render(m_LastX,m_LastY,(*it).str.c_str());
                    if(it->autoEnter)
                    {
                        m_LastY += it->size;
                        m_LastX = m_OffX;
                        height += size.cy;
                        width = 0;
                        if(height+size.cy >= m_Height)
                            m_Height += size.cy;
                    }
                    else
                    {
                        m_LastX += size.cx;
                        width += size.cx;
                        height += size.cy;
                    }
                }
                else
                {
                    SIZE charSize;
                    wchar_t temp[256];
                    const wchar_t* oneChar = (*it).str.c_str();
                    while (*oneChar)
                    {
                        memcpy(temp,oneChar,2);
                        temp[1] = '\0';
                        charSize = font->GetTextSize(temp);
                        if(width + charSize.cx <= m_Width)
                        {
                            if (height + charSize.cy >= m_Height)
                            {
                                m_Height += charSize.cy;
                            }
                            font->Render(m_LastX,m_LastY,temp);
                            m_LastX += charSize.cx;
                            width += charSize.cx;
                        }
                        else	//换行
                        {
                            width = 0;
                            height += charSize.cy;
                            if(height + charSize.cy  >= m_Height)
                            {
                                m_Height += charSize.cy;
                            }
                            m_LastY += charSize.cy;
                            m_LastX = m_OffX;
                            font->Render(m_LastX,m_LastY,temp);
                            m_LastX += charSize.cx;
                            width += charSize.cx;
                        }
                        oneChar++;
                    }
                    if(it->autoEnter)
                    {
                        m_LastY += it->size;
                        m_LastX = m_OffX;
                        height += size.cy;
                    }
                }
            }
            //没有指定位置,继续上次绘制位置来绘制文本
            else if (it->x == -1 && it->y == -1)
            {
                int width = m_LastX - m_OffX;
                int height = m_LastY - m_OffY;
                SIZE size = font->GetTextSize((*it).str.c_str());
                if (size.cx + width <= m_Width)
                {
                    if(size.cy + height >= m_Height)
                        m_Height += size.cy;
                    font->Render(m_LastX,m_LastY,(*it).str.c_str());
                    if (it->autoEnter)
                    {
                        m_LastY += size.cy;
                        m_LastX = m_OffX;
                        width = 0;
                        height += size.cy;
                        if(height + size.cy >= m_Height)
                            m_Height += size.cy;
                    }
                    else
                        m_LastX += size.cx;
                }
                else
                {
                    SIZE charSize;
                    wchar_t temp[256];
                    const wchar_t* oneChar = (*it).str.c_str();
                    while (*oneChar)
                    {
                        memcpy(temp,oneChar,2);
                        temp[1] = '\0';
                        charSize = font->GetTextSize(temp);
                        if(width + charSize.cx <= m_Width)
                        {
                            if (height + charSize.cy >= m_Height)
                            {
                                m_Height += charSize.cy;
                            }
                            font->Render(m_LastX,m_LastY,temp);
                            m_LastX += charSize.cx;
                            width += charSize.cx;
                        }
                        else	//换行
                        {
                            width = 0;
                            height += charSize.cy;
                            if(height + charSize.cy  >= m_Height)
                            {
                                m_Height += charSize.cy;
                            }
                            m_LastY += charSize.cy;
                            m_LastX = m_OffX;
                            font->Render(m_LastX,m_LastY,temp);
                            m_LastX += charSize.cx;
                            width += charSize.cx;
                        }
                        oneChar++;
                    }
                    if(it->autoEnter)
                    {
                        m_LastY += it->size;
                        m_LastX = m_OffX;
                        height += size.cy;
                    }
                }
            }
            font->SetColor(color);
        }
    }
}
コード例 #2
0
ファイル: GameDisplayDlg.cpp プロジェクト: sryanyuan/rtttest
void GameDisplayDlg::Render()
{
	if(m_xItemList.empty())
	{
		return;
	}
	if(m_rcClient.left == m_rcClient.right ||
		m_rcClient.top == m_rcClient.bottom)
	{
		return;
	}

	hgeResourceManager* pResMgr = g_pResMgr;
	HTEXTURE tex = 0;

	{
		//	draw bk
		tex = pResMgr->GetTexture("bmcolor");
		if(tex)
		{
			m_pRender->SetTexture(tex);
			m_pRender->SetTextureRect(0,
				0,
				m_rcClient.right - m_rcClient.left,
				m_rcClient.bottom - m_rcClient.top);
			m_pRender->Render(m_rcClient.left,
				m_rcClient.top);
		}
	}

	int nDrawX = 0;
	int nDrawY = 0;

	{
		//	render strings
		std::list<DisplayItem*>::const_iterator begIter = m_xItemList.begin();
		std::list<DisplayItem*>::const_iterator endIter = m_xItemList.end();

		for(begIter;
			begIter != endIter;
			++begIter)
		{
			DisplayItem* pDisplayItem = *begIter;

			if(pDisplayItem)
			{
				GfxFont* pFont = pDisplayItem->pFont;

				if(SHOW_STRING == pDisplayItem->nShowType)
				{
					if(NULL == pFont)
					{
						//	default font
						pFont = AfxGetFont();
					}

					pFont->SetColor(ARGB_WHITE);
					if(0 != pDisplayItem->dwColor)
					{
						pFont->SetColor(pDisplayItem->dwColor);
					}

					nDrawX = RELATIVE_X(pDisplayItem->nPosX);
					nDrawY = RELATIVE_Y(pDisplayItem->nPosY);

					pFont->Print((float)nDrawX,
						(float)nDrawY,
						pDisplayItem->xText.c_str());
				}
			}
		}
	}
}