gs_ui_activecaption.cpp

来自「网络泡泡被.net管理」· C++ 代码 · 共 402 行

CPP
402
字号
// GS_UI_ActiveCaption.cpp: implementation of the GS_UI_ActiveCaption class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GsUI.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

GS_UI_ActiveCaption::GS_UI_ActiveCaption(CGsUIPanel*	pParent)
:CGsUIPanel(pParent)
{
	m_key_style				= "active_caption";

	m_speed_x			= 0;
	m_speed_y			= 0;
	m_pos_x				= 0;
	m_pos_y				= 0;
	m_caption_width		= 0;
	m_caption_height	= 0;
	m_current_line		= 0;
	m_is_flash			= true;
}

GS_UI_ActiveCaption::~GS_UI_ActiveCaption()
{

}

HRESULT GS_UI_ActiveCaption::UpdateCaptionEx()
{

	m_tex_caption.Clear(0);
	std::list<_SHOW_LINE>::iterator it = m_show_list.begin();
	while(it!=m_show_list.end())
	{
		HRESULT hr;
		GRECT rc(m_rcHeader.top_left()+GPOINT(it->pos_x, it->pos_y), GPOINT(it->width, it->height));
		hr = m_tex_caption.DrawText(m_hfont,
								it->caption.c_str(),
								&rc,
								m_rcHeader.width(),
								m_rcHeader.height(),
								m_align|DT_SINGLELINE|DT_VCENTER,
								m_color,
								RGBA_MAKE(0,0,0,0)
								);
//		return hr;
		it++;
	}
	return S_OK;
}

HRESULT GS_UI_ActiveCaption::UpdateCaption()
{
	m_caption_buf.clear();
	char seps[]	= "|";
	if(m_caption.empty())
		return S_OK;
	char strCaption[1000];
	strcpy(strCaption, m_caption.c_str());
	char* sz	= strtok(strCaption, seps);
	while(sz)
	{
		_CAPTION_LINE	line;
		line.caption	= sz;
		{
			HDC hdc	= GetDC(NULL);
			HFONT old_font;
			if( m_hfont )
				old_font = (HFONT)SelectObject( hdc, m_hfont );

			SIZE size;
			GetTextExtentPoint(hdc, line.caption.c_str(), strlen(line.caption.c_str()), &size);
			line.width = size.cx;
			line.height = size.cy;
			if( m_hfont )
			{
				SelectObject( hdc, old_font );
				ReleaseDC(NULL, hdc);
			}
		}
		
		m_caption_buf.push_back(line);
		sz	= strtok(NULL, seps);
	}
	

	if(m_is_flash)
	{
		m_show_list.clear();
//		for(int i=0; i<m_caption_buf.size(); i++)
//		{
			AddShowLine();
//		}
		std::list<_SHOW_LINE>::iterator it = m_show_list.begin();
		int width=m_rcHeader.width() - m_space_size, height=m_rcHeader.height() - m_space_size;
		while(it!=m_show_list.end())
		{
			width	+= it->width;
			height	+= it->height;
			it++;
		}

		it = m_show_list.begin();
		while(it!=m_show_list.end())
		{
			if(m_speed_x>0)
			{
				it->pos_x += width/2;
			}
			else if(m_speed_x<0)
			{
				it->pos_x -= width/2;
			}
			else
			{
			}
			if(m_speed_y>0)
			{
				it->pos_y += height/2;

			}
			else if(m_speed_y<0)
			{
				it->pos_y -= height/2;
			}
			else
			{
			}
			it++;
		}

	}
/*
	if(m_speed_x!=0 && 0==config.GetFloat("ACTIVE_CAPTION", "width"))
	{
		HDC hdc	= GetDC(NULL);
		HFONT old_font;
		if( m_hfont )
			old_font = (HFONT)SelectObject( hdc, m_hfont );

		SIZE size;
		GetTextExtentPoint(hdc, m_caption.c_str(), strlen(m_caption.c_str()), &size);
		m_caption_width = size.cx;
		if( m_hfont )
		{
			SelectObject( hdc, old_font );
			ReleaseDC(NULL, hdc);
		}
	}
*/

	return UpdateCaptionEx();
}
LONG	GS_UI_ActiveCaption::OnUpdate()
{
	LONG lret = CGsUIPanel::OnUpdate();

	float dx	= m_speed_x*m_pEngine->m_dwPassTime/1000.0f;
	float dy	= m_speed_y*m_pEngine->m_dwPassTime/1000.0f;
/*
	m_pos_x		+= m_speed_x*m_pEngine->m_dwPassTime/1000.0f;
	m_pos_y		+= m_speed_y*m_pEngine->m_dwPassTime/1000.0f;
	if(m_speed_x>0)
	{
		if(m_pos_x>m_caption_width)
			m_pos_x		= -m_caption_width;
	}
	else if(m_speed_x<0)
	{
		if(m_pos_x<-m_caption_width)
			m_pos_x		= m_rcHeader.width();
	}
	else
	{
		m_pos_x		= 0;
	}

	if(m_speed_y>0)
	{
		if(m_pos_y>m_caption_height)
			m_pos_y		= -m_caption_height;
	}
	else if(m_speed_y<0)
	{
		if(m_pos_y<-m_caption_height)
			m_pos_y		= m_rcHeader.height();
	}
	else
	{
		m_pos_y		= 0;
	}
*/
	if(!m_is_flash)
	{
		std::list<_SHOW_LINE>::iterator it = m_show_list.begin();
		while(it!=m_show_list.end())
		{
			it->pos_x += dx;
			it->pos_y += dy;
			if((m_speed_x>0 && it->pos_x>it->end_show)
				|| (m_speed_x<0 && it->pos_x<it->end_show)
				|| (m_speed_y>0 && it->pos_y>it->end_show)
				|| (m_speed_y<0 && it->pos_y<it->end_show))
			{
				it = m_show_list.erase(it);
				continue;
			}
			it++;
		}
		std::list<_SHOW_LINE>::reverse_iterator rit = m_show_list.rbegin();
		if(rit!=m_show_list.rend())
		{
			if((m_speed_x>0 && rit->pos_x>rit->full_show)
				|| (m_speed_x<0 && rit->pos_x<rit->full_show)
				|| (m_speed_y>0 && rit->pos_y>rit->full_show)
				|| (m_speed_y<0 && rit->pos_y<rit->full_show))
				AddShowLine();
		}
		else
		{
				AddShowLine();
		}

		UpdateCaptionEx();
	}
	return lret;
}

BOOL GS_UI_ActiveCaption::AddShowLine()
{
	if(m_caption_buf.size()<=0)
		return false;
	if(m_current_line>=m_caption_buf.size())
	{
		m_current_line = 0;
	}

	float fStart = 0.0f;
	while(m_current_line<m_caption_buf.size())
	{
		_SHOW_LINE show_line;
		show_line.caption	= m_caption_buf[m_current_line].caption;
		if(m_speed_x>0)
		{
			show_line.pos_x		= -m_caption_buf[m_current_line].width-m_space_size - fStart;
			show_line.end_show	= m_rcHeader.width();
			show_line.full_show	= 0;
			show_line.width		= m_caption_buf[m_current_line].width+m_space_size;
			show_line.height	= (m_caption_height==0)?m_rcHeader.height():m_caption_height;
			fStart				+= m_caption_buf[m_current_line].width+m_space_size;
		}
		else if(m_speed_x<0)
		{
			show_line.pos_x		= m_rcHeader.width() + fStart;
			show_line.end_show	= -m_caption_buf[m_current_line].width-m_space_size;
			show_line.full_show	= m_rcHeader.width()-m_caption_buf[m_current_line].width-m_space_size;
			show_line.width		= m_caption_buf[m_current_line].width+m_space_size;
			show_line.height	= (m_caption_height==0)?m_rcHeader.height():m_caption_height;
			fStart				+= m_caption_buf[m_current_line].width+m_space_size;
		}
		else
		{
			show_line.pos_x		= 0;
		}

		if(m_speed_y>0)
		{
			show_line.pos_y		= -m_caption_buf[m_current_line].height-m_space_size - fStart;
			show_line.end_show	= m_rcHeader.height();
			show_line.full_show	= 0;
			show_line.width		= m_rcHeader.width();
			show_line.height	= m_caption_buf[m_current_line].height+m_space_size;
			fStart				+= m_caption_buf[m_current_line].height+m_space_size;
		}
		else if(m_speed_y<0)
		{
			show_line.pos_y		= m_rcHeader.height() + fStart;
			show_line.end_show	= -m_caption_buf[m_current_line].height-m_space_size;
			show_line.full_show	= m_rcHeader.height()-m_caption_buf[m_current_line].height-m_space_size;
			show_line.width		= m_rcHeader.width();
			show_line.height	= m_caption_buf[m_current_line].height+m_space_size;
			fStart				+= m_caption_buf[m_current_line].height+m_space_size;
		}
		else
		{
			show_line.pos_y		= 0;
		}

		m_show_list.push_back(show_line);

		m_current_line++;
	}

	return TRUE;
}

BOOL GS_UI_ActiveCaption::Restore()
{
	GRECT rc		= config.GetRect("SETING", "header_rect");

	m_speed_x	= config.GetFloat("ACTIVE_CAPTION", "speed_x");
	m_speed_y	= config.GetFloat("ACTIVE_CAPTION", "speed_y");

	m_caption_width		= config.GetFloat("ACTIVE_CAPTION", "width");
	m_caption_height	= config.GetFloat("ACTIVE_CAPTION", "height");

	m_space_size	= config.GetFloat("ACTIVE_CAPTION", "space_size");

	m_is_flash		= config.GetBOOL("ACTIVE_CAPTION", "is_flash");

	if(m_speed_x>0)
	{
		m_pos_x		= -m_caption_width;
	}
	else if(m_speed_x<0)
	{
		m_pos_x		= rc.width();
	}
	else
	{
		m_pos_x		= 0;
	}

	if(m_speed_y>0)
	{
		m_pos_y		= -m_caption_height;
	}
	else if(m_speed_y<0)
	{
		m_pos_y		= rc.height();
	}
	else
	{
		m_pos_y		= 0;
	}
	BOOL bret = CGsUIPanel::Restore();

	m_current_line		= 0;

	AddShowLine();

	return bret;
}


HRESULT GS_UI_ActiveCaption::OnDraw(GPOINT point)
{
//	D3DCOLOR	color	= D3DRGBA(0.5,0.5,0.5,1.0);
	if(m_bk_color>0)
	{
		GRECT rc = m_rcClient - m_rcClient.top_left() + point;
		m_pEngine->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
		m_pEngine->Render_DrawRect(&rc, TRUE, m_bk_color, m_isBackLayer ? 0.99f : 0.0f);
		if(m_isCanEdit)
		{
			if(m_isFocus)
			{
				float fv = m_pEngine->ValueCycle(0.5f, 1,0,300);
				int r = (255)*fv;
				int g = (255)*fv;
				int b = (255)*fv;
				D3DCOLOR cr = RGBA_MAKE(r, g, b, 255);
				m_pEngine->Render_DrawRect(&rc, FALSE, cr, m_isBackLayer ? 0.99f : 0.0f);
			}
			else if(m_isTouch)
			{
				D3DCOLOR cr = RGBA_MAKE(255, 255, 255, 255);
				m_pEngine->Render_DrawRect(&rc, FALSE, cr, m_isBackLayer ? 0.99f : 0.0f);
			}
		}
		m_pEngine->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
	}
	float alpha = 1.0f;
	if(m_is_flash)
	{
		alpha = m_pEngine->ValueCycle(0.0f, 1.0f, 0, 100);
	}

	if(m_pImage)
		m_pImage->Draw(point.x, point.y, m_isBackLayer ? 0.99f : 0.0f);
	if(m_isCaption)
	{
// 		m_pEngine->PreparePaint();
//		UpdateCaption();
		m_pEngine->Render_PaintFast(point.x + m_rcHeader.left, point.y + m_rcHeader.top, &m_tex_caption, m_isBackLayer ? 0.99f : 0.0f, 1.0f, 1.0f, alpha);
	}
	return S_OK;
}

VOID GS_UI_ActiveCaption::SetFlash(BOOL bFlash)	
{
	if(m_is_flash == bFlash)
		return;
	m_is_flash = bFlash;
	m_show_list.clear();
	UpdateCaption();
}

⌨️ 快捷键说明

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