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

📄 cuserinterface.cpp

📁 一个个人开发的rpg游戏<亚特兰蒂斯传奇>的源码
💻 CPP
字号:
//--------------------------------------------------------------------------------------------------------
//                        游戏UI模块
//CUserInterface.cpp
//游戏引擎中的UI部分
//作者:吴振华(kylinx)(中国科大01级11系)
//E-mail:game-diy@163.com
//创建于:2003/7/20 by Kylinx
//--------------------------------------------------------------------------------------------------------
#include"CUserInterface.h"
#include"dxlib\\ddutil.h"
#include"CFont.h"
#include"CCursor.h"
#include"CMacro.h"
BOOL CListBox::InitTable(CDisplay*pDisplay,int left,int top,int DeltaY,DWORD dwUnSelectColor,DWORD dwSelectColor,int nShowStringCount,int nMaxStringCount)
{
	LOA_ASSERT(pDisplay);

	m_pDisplay=pDisplay;
	m_left=left;
	m_top=top;
	m_nDeltaY=DeltaY;
	m_nShowStringCount=nShowStringCount;
	m_nMaxStringCount=nMaxStringCount;
	this->m_nCurrentSelect=0;
	this->m_nCurrentShowStart=0;
	this->m_nCurrentStringCount=0;

	m_dwSelectColor=dwSelectColor;
	m_dwUnSelectColor=dwUnSelectColor;

	m_pIcon=new CIcon();
	if(!m_pIcon || !m_pIcon->InitIcon(pDisplay,LOA_ICON_ARROW))
		return false;

	m_aElems=new STListElem[m_nMaxStringCount];
	if(!m_aElems)
		return false;
	m_pFont=new CFont();
	if(!m_pFont)
		return false;
	m_pFont->CreateFont();
	return true;
}
BOOL CListBox::InsertString(char*str)
{
	LOA_ASSERT(str);

	if(this->m_nCurrentStringCount>m_nMaxStringCount)
		return false;

	m_nCurrentStringCount++;

	STListElem elem;
	elem.SetString(str);
	m_aElems[m_nCurrentStringCount-1]=elem;
	return true;
	
}
BOOL CListBox::DeleteString(int ID)
{
	if(ID<0 || ID>=m_nCurrentStringCount)
		return false;
	for(int i=ID;i<=m_nCurrentStringCount-1;i++)
	{
		m_aElems[i]=m_aElems[i+1];
	}
	m_nCurrentStringCount--;
	if(m_nCurrentStringCount<=0)
		this->m_nCurrentSelect=0;
	return true;
}
BOOL CListBox::ModifyString(int ID,char*str)
{
	LOA_ASSERT(str);

	if(ID<0 || ID>=m_nCurrentStringCount)
		return false;
	STListElem elem;
	elem.SetString(str);
	m_aElems[ID]=elem;
	return true;
}
void CListBox::SelectNextElem()
{
	this->m_nCurrentSelect++;
	if(m_nCurrentSelect>m_nCurrentStringCount)
		m_nCurrentSelect--;
	else
	{
		if(m_nCurrentSelect-1 >=this->m_nCurrentShowStart+this->m_nShowStringCount)
			m_nCurrentShowStart++;
	}
}
void CListBox::SelectPrevElem()
{
	this->m_nCurrentSelect--;
	if(m_nCurrentSelect<1)
		m_nCurrentSelect++;
	else
	{
		if(m_nCurrentSelect-1 < this->m_nCurrentShowStart)
			m_nCurrentShowStart--;
	}
}
void LOA_RENDER_API CListBox::Release()
{
	if(m_aElems)
	{
		delete [] m_aElems;
		m_aElems=NULL;
	}
	if(m_pFont)
	{
		delete m_pFont;
		m_pFont=NULL;
	}
	if(m_pIcon)
	{
		delete m_pIcon;
		m_pIcon=NULL;
	}
}
BOOL LOA_RENDER_API CListBox::IsRenderComplete()
{
	return false;
}
void LOA_RENDER_API CListBox::Render()
{
	HDC hdc; 
	m_pDisplay->GetBackBuffer()->GetDC(&hdc);
	::SelectObject(hdc,m_pFont->GetFont());
	::SetBkMode(hdc,TRANSPARENT);
	for(int i=this->m_nCurrentShowStart;i<this->m_nCurrentShowStart+this->m_nShowStringCount;i++)
	{
		if(i==this->m_nCurrentSelect-1)
			::SetTextColor(hdc,m_dwSelectColor);
		else
			::SetTextColor(hdc,m_dwUnSelectColor);

		::TextOut(hdc,m_left,m_top+(i-this->m_nCurrentShowStart)*this->m_nDeltaY,
					  m_aElems[i].GetString(),strlen(m_aElems[i].GetString()));
	}
	m_pDisplay->GetBackBuffer()->ReleaseDC(hdc);
	if(m_nCurrentSelect>0)
		m_pIcon->Show(m_left-20,m_top+(m_nCurrentSelect-1-this->m_nCurrentShowStart)*this->m_nDeltaY);
}

⌨️ 快捷键说明

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