📄 gameobjectedit.cpp
字号:
// ***************************************************************
// GameObjectButton version: 1.0
// -------------------------------------------------------------
// File Name: GameObjectEdit.cpp
// Created: 2007/07/29
// Modified: 2007/07/29 20:21
// Author: William.Liang
// Msn: lwq49@msn.com
// Email: lwq49@21cn.com, lwq49@msn.com
// Description:
//
// Purpose:
// -------------------------------------------------------------
// license:
//
// The contents of this file are subject to the Mozilla Public
// License Version 1.1 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy
// of the License at http://www.mozilla.org/MPL/ Software dis-
// tributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or im-
// plied. See the License for the specific language governing
// rights and limitations under the License.
//
// The Initial Developer of the Original Code is William.Liang .
// Copyright (C) 2007 - All Rights Reserved.
// ***************************************************************
#include "StdAfx.h"
#include ".\gameobjectedit.h"
CGameObjectEdit::CGameObjectEdit(void)
{
m_bAcceptEnterKey = true;
m_bAcceptTabKey = false;
m_bPassword = false;
m_bShowCur = true;
m_lpTextBuffer = NULL;
m_pResource = NULL;
m_wCurPosition = 0;
m_enCharScope = CharScope_Undefine;
m_pResource = NULL;
m_hWnd = NULL;
m_BasalInfo.Disabled = false;
Add(GET_OBJECT_INTERFACE(m_GOText, IGameObject), "Text");
Add(GET_OBJECT_INTERFACE(m_GOGraph, IGameObject), "BG");
}
CGameObjectEdit::~CGameObjectEdit(void)
{
m_lpTextBuffer = NULL;
}
//对象创建
bool CGameObjectEdit::Create(LPCTSTR lpName, _SIZE siSize, CResource* pResource){
__super::Create(lpName, siSize, Type_Edit);
m_GOGraph.Create("BG", siSize, pResource);
m_GOText.SetMaxLength(255);
m_GOText.Create("Text", siSize, "default.fnt");
m_GOText.SetFontSize(20);
m_lpTextBuffer = (LPTSTR)m_GOText.GetBuffer();
m_pResource = pResource;
m_hWnd = m_pResource->GetGDI()->System_GetState(HGE_HWND);
return true;
}
//渲染对象
void CGameObjectEdit::Render(WPARAM wParam){
//设置遮罩
m_pResource->GetGDI()->Gfx_SetClipping((int)m_BasalInfo.LocalPos.x, (int)m_BasalInfo.LocalPos.y, (int)m_BasalInfo.Size.cx, (int)m_BasalInfo.Size.cy);
m_GOGraph.Render(wParam);
m_GOText.Render(wParam);
//恢复遮罩
m_pResource->GetGDI()->Gfx_SetClipping(0, 0, 0, 0);
}
//接受输入回车键
void CGameObjectEdit::AcceptEnterKey(bool bFlag){
m_bAcceptEnterKey = bFlag;
}
//接受TAB键
void CGameObjectEdit::AcceptTabKey(bool bFlag){
m_bAcceptTabKey = bFlag;
}
//清空输入内容
void CGameObjectEdit::Clear(){
m_GOText.SetText("");
}
//返回背景纹理对象
IGameObjectGraph* CGameObjectEdit::GetBGObject(){
return GET_OBJECT_INTERFACE(m_GOGraph, IGameObjectGraph);
}
//返回文本内容对象
IGameObjectText* CGameObjectEdit::GetTextObject(){
return GET_OBJECT_INTERFACE(m_GOText, IGameObjectText);
}
//返回录入字符范围
enEditCharScope CGameObjectEdit::GetCharScope(){
return m_enCharScope;
}
//返回当前光标位置
WORD CGameObjectEdit::GetCurPosition(){
return m_wCurPosition;
}
//返回录入内容
LPCTSTR CGameObjectEdit::GetText(){
return m_GOText.GetText();
}
//返回录入内容的长度
WORD CGameObjectEdit::GetTextLength(){
return m_GOText.GetTextLength();
}
//是否接受回车键
bool CGameObjectEdit::IsAcceptEnterKey(){
return m_bAcceptEnterKey;
}
//是否接受TAB键
bool CGameObjectEdit::IsAcceptTabKey(){
return m_bAcceptTabKey;
}
//是否密码录入方式
bool CGameObjectEdit::IsPassword(){
return m_bPassword;
}
//是否显示光标
bool CGameObjectEdit::IsShowCursor(){
return m_bShowCur;
}
//设置为密码录入方式
void CGameObjectEdit::Password(bool bFlag){
m_bPassword = bFlag;
}
//设置录入字符集
void CGameObjectEdit::SetCharScope(enEditCharScope enCharScope){
m_enCharScope = enCharScope;
}
//设置光标位置
void CGameObjectEdit::SetCurPosition(WORD wPosition){
m_wCurPosition = wPosition;
}
//设置文本内容
void CGameObjectEdit::SetText(LPCTSTR lpText, WORD wLength){
m_GOText.SetText(lpText, wLength);
}
//显示光标
void CGameObjectEdit::ShowCursor(bool bFlag){
m_bShowCur = bFlag;
}
//************************************
// <p>Description: 鼠标点击</p>
// <p>Parameters: </p>
// <p> float x</p>
// <p> float y</p>
// <p> int nType</p>
// <p> int nKey</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameObjectEdit::OnMouseClick(float x, float y, int nType, UINT nMessage, UINT nComboKey){
//只处理MOUSE DOWN事件
if(nType==INPUT_MOUSE_DOWN){
}
return true;
}
//************************************
// <p>Description: 键盘事件</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameObjectEdit::OnKeyPass(TCHAR nKey, UINT nFlag){
int iLen = m_GOText.GetTextLength();
switch(m_enCharScope){
case CharScope_Number:
if(nKey<48 || nKey>57) return false;
break;
case CharScope_Letter:
if(nKey<65 || nKey>112) return false;
break;
case CharScope_Symbol:
if(!(nKey>=32 && nKey<=47 || nKey>=58 && nKey<=64 || nKey>=91 && nKey<=96 || nKey>=123 && nKey<=126)) return false;
break;
case CharScope_Both:
if(nKey<32 || nKey>126) return false;
break;
}
if(iLen<m_GOText.GetMaxLength()){
m_lpTextBuffer[iLen]=nKey;
m_lpTextBuffer[iLen+1]=0;
m_GOText.SetText(m_lpTextBuffer);
}
CONTROLMESSAGE* tagControlMsg = new CONTROLMESSAGE;
tagControlMsg->lpVoid = this;
tagControlMsg->wParam = nKey;
tagControlMsg->lParam = nFlag;
PostMessage(m_hWnd, CN_CONTROL_MESSAGE, (WPARAM)(tagControlMsg), sizeof(CONTROLMESSAGE));
return true;
}
//************************************
// <p>Description: 键盘事件</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameObjectEdit::OnKeyDown(TCHAR nKey, UINT nFlag){
int iLen = m_GOText.GetTextLength();
//退格键
if(nKey==VK_BACK){
if(iLen>0){
m_lpTextBuffer[iLen-1]=0;
m_GOText.SetText(m_lpTextBuffer);
}
return true;
}
if(m_bAcceptTabKey){
//Tab键处理
if(nKey==VK_TAB){
return true;
}
}
return true;
}
//重获焦点 8-27
void CGameObjectEdit::FocusGain(){
m_GOGraph.FocusGain();
}
//************************************
// <p>Description: 接口查询</p>
// <p>Parameters: </p>
// <p> const IID & Guid</p>
// <p> DWORD dwQueryVer</p>
//
// <p>Returns: void*</p>
//************************************
void* CGameObjectEdit::QueryInterface(const IID &Guid, DWORD dwQueryVer){
QUERYINTERFACE(IGameObjectEdit,Guid,dwQueryVer);
QUERYINTERFACE(IGameObject,Guid,dwQueryVer);
QUERYINTERFACE(IBaseObject,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IGameObjectEdit,Guid,dwQueryVer);
return NULL;
}
//************************************
// <p>Description: =操作重载</p>
// <p>Parameters: </p>
// <p> const CGameObjectText & GameObject</p>
//
// <p>Returns: CGameObjectText&</p>
//************************************
CGameObjectEdit& CGameObjectEdit::operator=(CGameObjectEdit& GameObject){
CGameObject* pOtherBaseClass = static_cast<CGameObject *>(&GameObject);
CGameObject* pMySelfBaseClass = static_cast<CGameObject *>(this);
*pMySelfBaseClass = *pOtherBaseClass;
m_bAcceptEnterKey = GameObject.m_bAcceptEnterKey;
m_bAcceptTabKey = GameObject.m_bAcceptTabKey;
m_bPassword = GameObject.m_bPassword;
m_bShowCur = GameObject.m_bShowCur;
m_GOGraph = GameObject.m_GOGraph;
m_GOText = GameObject.m_GOText;
m_wCurPosition = GameObject.m_wCurPosition;
m_enCharScope = GameObject.m_enCharScope;
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -