?? interface.cpp
字號:
#include "Interface.h"
#include "GlobalDef.h"
#include <conio.h>
#include "Input.h"
CInterface::CInterface(void)
{
}
CInterface::~CInterface(void)
{
}
//顯示信息畫面
//void CInterface::ShowMessage(char *strValue,int nRow)
//{
// COORD tempPos;
// int nNum = static_cast<int>(strlen(strValue));
// tempPos.X = (SCREENWIDTH)/4;
// tempPos.Y = (SCREENHEIGHT)/4 + nRow;
//
// WriteConsoleOutputCharacter(CInput::getHout(), strValue, nNum, tempPos, NULL);
//}
void CInterface::ShowMessage(string strValue,int nRow)
{
COORD tempPos;
//int nNum = static_cast<int>(strlen(strValue));
const char *chTemp = strValue.data();
int nNum = static_cast<int>(strlen(chTemp));
tempPos.X = (SCREENWIDTH)/4;
tempPos.Y = (SCREENHEIGHT)/4 + nRow;
WriteConsoleOutputCharacter(CInput::getHout(), chTemp, nNum, tempPos, NULL);
}
//畫出地圖各元素
void CInterface::DrawMapElement(COORD coPosition,string strValue)
{
const char *chTemp = strValue.data();
int nNum = static_cast<int>(strlen(chTemp));
WriteConsoleOutputCharacter(CInput::getHout(), chTemp, nNum, coPosition, NULL);
}
//定義非選擇菜單
void CInterface::DrawShowMenu(COORD& coPOS,int windth,string strValue)
{
const char *chTemp = strValue.data();
int nNum = static_cast<int>(strlen(chTemp));
WORD wShadowAtt=BACKGROUND_INTENSITY; // 陰影屬性
WORD wTextAtt = FOREGROUND_RED |FOREGROUND_GREEN |FOREGROUND_BLUE | FOREGROUND_INTENSITY |
BACKGROUND_RED | BACKGROUND_BLUE; // 文本屬性
COORD coShadowPOS={coPOS.X+1,coPOS.Y+1};
FillConsoleOutputAttribute(CInput::getHout(), wShadowAtt, windth, coShadowPOS, NULL);
FillConsoleOutputAttribute(CInput::getHout(), wTextAtt, windth, coPOS, NULL);
WriteConsoleOutputCharacter(CInput::getHout(), chTemp, nNum, coPOS, NULL);
}
//控制戰斗菜單顯示的屬性
void CInterface::CreateMenu(COORD& coPOS)
{
m_coFirstPOS = coPOS;
m_nMenuNum = 0;
m_nSelect = 1;
m_nMaxLength = 0;
m_wShadowAtt=BACKGROUND_INTENSITY; // 陰影屬性
m_wTextAtt = FOREGROUND_RED |FOREGROUND_GREEN |FOREGROUND_BLUE | FOREGROUND_INTENSITY |
BACKGROUND_RED | BACKGROUND_BLUE; // 文本屬性
//m_wTextAtt = FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_INTENSITY |
// BACKGROUND_RED | BACKGROUND_BLUE; // 文本屬性
m_wSelectAtt=FOREGROUND_RED|FOREGROUND_INTENSITY|BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED;
COORD coShadowPOS={coPOS.X+1,coPOS.Y+1};
FillConsoleOutputAttribute(CInput::getHout(), m_wShadowAtt, MenuWidth, coShadowPOS, NULL);
FillConsoleOutputAttribute(CInput::getHout(), m_wTextAtt, MenuWidth, coPOS, NULL);
}
//增加戰斗菜單顯示的內容
void CInterface::AddMenuCell(char* strValue)
{
// 計算顯示窗口大小和位置
int nNum = static_cast<int>(strlen(strValue));
m_nMaxLength = m_nMaxLength<nNum?nNum:m_nMaxLength;
// 設置陰影
COORD posShadow = {m_coFirstPOS.X+1, m_coFirstPOS.Y+m_nMenuNum+2};
COORD posText = {m_coFirstPOS.X, m_coFirstPOS.Y+m_nMenuNum+1};
for (int i=0; i<2; ++i){
FillConsoleOutputAttribute(CInput::getHout(), m_wShadowAtt, MenuWidth, posShadow, NULL);
++posShadow.Y;
}
// 填充窗口背景
for (int i=0; i<2; ++i){
FillConsoleOutputAttribute(CInput::getHout(), m_wTextAtt, MenuWidth, posText, NULL);
++posText.Y;
}
// 寫文本和邊框
posText.X=m_coFirstPOS.X+2;
posText.Y=m_coFirstPOS.Y+m_nMenuNum+1;
WriteConsoleOutputCharacter(CInput::getHout(), strValue, nNum, posText, NULL);
//++m_nMenuNum;
m_nMenuNum = m_nMenuNum + 2;
}
//標出選中的菜單
void CInterface::DrawMenu(int nNewSEL,int nOldSEL)
{
COORD posText = {m_coFirstPOS.X+2, m_coFirstPOS.Y+2*nNewSEL-1};
FillConsoleOutputAttribute(CInput::getHout(), m_wSelectAtt, m_nMaxLength, posText, NULL);
if (nNewSEL != nOldSEL)
{
posText.Y=m_coFirstPOS.Y+2*nOldSEL-1;
FillConsoleOutputAttribute(CInput::getHout(), m_wTextAtt, m_nMaxLength, posText, NULL);
}
}
//選擇菜單
int CInterface::SelectMenu()
{
int nMaxCount = m_nMenuNum/2;
int nKey;
//SMALL_RECT rc={SCREENWIDTH/3+MenuWidth+1,SCREENHEIGHT/3+4,SCREENWIDTH/3+MenuWidth+22,SCREENHEIGHT/3+17};
SMALL_RECT rc={SCREENWIDTH/3+MenuWidth+1,SCREENHEIGHT/3,SCREENWIDTH/3+MenuWidth+22,SCREENHEIGHT/3+17};
while (1)
{
nKey = _getch();
switch (nKey)
{
case 72://向上
if (m_nSelect == 3 || m_nSelect == 2) DeleteRect(rc);
if (m_nSelect != 1)
{
m_nSelect -= 1;
DrawMenu(m_nSelect,m_nSelect+1);
}
break;
case 80://向下
if (m_nSelect == 3 || m_nSelect == 2) DeleteRect(rc);
if (m_nSelect != nMaxCount)
{
m_nSelect += 1;
DrawMenu(m_nSelect,m_nSelect-1);
}
break;
case 13://確定--回車
return m_nSelect;
}
}
}
//刪除矩形范圍內的內容
void CInterface::DeleteRect(SMALL_RECT& rc)
{
CONSOLE_SCREEN_BUFFER_INFO bInfo;
GetConsoleScreenBufferInfo(CInput::getHout(), &bInfo);
COORD home={rc.Left,rc.Top};
DWORD size=rc.Right-rc.Left;
int line=rc.Bottom-rc.Top;
for(int i=0;i<line;++i)
{
FillConsoleOutputAttribute(CInput::getHout(), bInfo.wAttributes, size, home, NULL);
FillConsoleOutputCharacter(CInput::getHout(), ' ', size, home, NULL);
++home.Y;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -