static.cpp
来自「一个自己写的游戏引擎,用DirectX 写成」· C++ 代码 · 共 179 行
CPP
179 行
//--------------------------------------------------
// Desc: Static Text
// Author: artsylee/2006.11.16
//--------------------------------------------------
#include "../stdafx.h"
#include "Static.h"
#include "../Core/IniFile.h"
#include "../Core/Message.h"
#include "../Core/Interface.h"
#include "../Core/Common.h"
#include "../Core/Input.h"
GStatic::GStatic(CWindow* pParent):CWindow(pParent)
{
m_dwGUIType = GUI_STATIC;
m_bLeft = true;
}
GStatic::~GStatic()
{
}
bool GStatic::LoadFromIni(char* pfilename, char* pIndex)
{
CIniFile ui(pfilename);
m_dwID = ui.ReadDWORD(pIndex, "ID");
m_ptPos = ui.ReadPoint(pIndex, "Position");
m_dwColor = ui.ReadDWORD(pIndex, "Color", 0xffffffff);
m_dwAttrib = ui.ReadDWORD(pIndex, "Attrib", 10);
ui.ReadString(pIndex, "Caption", m_szCaption);
char fontname[32];
ui.ReadString(pIndex, "FontName", fontname, "宋体");
int fontsize = ui.ReadInt(pIndex, "FontSize", 16);
m_Font.CreateFont(fontname, fontsize);
m_rcSrc = m_Font.GetStringRect(m_szCaption);
if(m_pParent)
{
OffSet(m_pParent->GetRect().left, m_pParent->GetRect().top);
}
return true;
}
void GStatic::Render()
{
if(m_dwAttrib & GUI_VISIBLE)
{
if(m_szCaption[0] != 0)
m_Font.DrawText(m_ptPos.x, m_ptPos.y, m_dwColor, !m_bLeft, m_szCaption);
}
}
DWORD GStatic::ProcessEvent()
{
if(!(m_dwAttrib & GUI_VISIBLE) || !(m_dwAttrib & GUI_ENABLE))
{
return INVALID_ID;
}
GRect rcPos;
rcPos.SetRectWH(m_ptPos.x, m_ptPos.y, m_rcSrc.Width(), m_rcSrc.Height());
if(CheckInRGN(rcPos))
{
if(g_stInputInfo.MouseValue==LB_DOWN)
{
//发送MOUSEDOWN信息
//OutputDebugString("LB mouse down\n");
CMessage msg(MSG_SYS_GUI, m_dwID);
msg.SetParameter(GUI_MOUSE_LDOWN, m_dwGUIType, this);
PostMessage(msg);
return m_dwID;
}
}
return INVALID_ID;
}
void GStatic::SetCaption(const char *szCaption)
{
if(!szCaption || strlen(szCaption)>255)
return;
strcpy(m_szCaption, szCaption);
m_rcSrc = m_Font.GetStringRect(m_szCaption);
}
void GStatic::GetCaption(char *szCaption)
{
if(szCaption)
strcpy(szCaption, m_szCaption);
}
//--------------------------------------------------
// Multi-Line Static
//--------------------------------------------------
MLStatic::MLStatic(CWindow* pParent):CWindow(pParent)
{
m_dwGUIType = GUI_COOLSTATIC;
}
MLStatic::~MLStatic()
{
}
bool MLStatic::LoadFromIni(char* pfilename, char* pIndex)
{
CIniFile ui(pfilename);
m_dwID = ui.ReadDWORD(pIndex, "ID");
m_ptPos = ui.ReadPoint(pIndex, "Position");
m_dwColor = ui.ReadDWORD(pIndex, "Color", 0xffffffff);
m_dwAttrib = ui.ReadDWORD(pIndex, "Attrib", 10);
ui.ReadString(pIndex, "Caption", m_szInfo);
char fontname[32];
ui.ReadString(pIndex, "FontName", fontname, "宋体");
int fontsize = ui.ReadInt(pIndex, "FontSize", 16);
m_Font.CreateFont(fontname, fontsize);
if(m_pParent)
{
OffSet(m_pParent->GetRect().left, m_pParent->GetRect().top);
}
return true;
}
void MLStatic::Render()
{
if(m_dwAttrib & GUI_VISIBLE)
{
if(m_szInfo[0] != 0)
m_Font.DrawText(m_ptPos.x, m_ptPos.y, m_dwColor, m_szInfo);
}
}
DWORD MLStatic::ProcessEvent()
{
if(!(m_dwAttrib & GUI_VISIBLE) || !(m_dwAttrib & GUI_ENABLE))
{
return INVALID_ID;
}
GRect rcPos;
rcPos.SetRectWH(m_ptPos.x, m_ptPos.y, m_rcSrc.Width(), m_rcSrc.Height());
if(CheckInRGN(rcPos))
{
if(g_stInputInfo.MouseValue==LB_DOWN)
{
//发送MOUSEDOWN信息
//OutputDebugString("LB mouse down\n");
CMessage msg(MSG_SYS_GUI, m_dwID);
msg.SetParameter(GUI_MOUSE_LDOWN, m_dwGUIType, this);
PostMessage(msg);
return m_dwID;
}
}
return INVALID_ID;
}
void MLStatic::SetCaption(const char *szCaption)
{
if(!szCaption || strlen(szCaption)>4095)
return;
strcpy(m_szInfo, szCaption);
}
void MLStatic::GetCaption(char *szCaption)
{
if(szCaption)
strcpy(szCaption, m_szInfo);
}
GFont* MLStatic::GetFont(void)
{
return &m_Font;
}
GRect MLStatic::GetFontRect()
{
return m_Font.GetStringRectMultiLine(m_szInfo);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?