📄 gameobjectbutton.cpp
字号:
// ***************************************************************
// GameObjectButton version: 1.0
// -------------------------------------------------------------
// File Name: GameObjectButton.cpp
// Created: 2007/07/18
// Modified: 2007/07/18 15:47
// 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 ".\gameobjectbutton.h"
//************************************
// <p>Description: 构造函数</p>
//************************************
CGameObjectButton::CGameObjectButton(void)
{
m_BasalInfo.Disabled = false;
ZeroMemory(m_rcStatus, sizeof(m_rcStatus));
Add(GET_OBJECT_INTERFACE(m_Sprite, IGameObject), "Sprite");
Add(GET_OBJECT_INTERFACE(m_Caption, IGameObject), "Caption");
}
//************************************
// <p>Description: 析构函数</p>
//************************************
CGameObjectButton::~CGameObjectButton(void)
{
}
//************************************
// <p>Description: 按钮创建</p>
// <p>Parameters: </p>
// <p> LPCTSTR lpName</p>
// <p> _SIZE siSize</p>
// <p> CResource* pResource</p>
// <p> LPCTSTR lpCaption</p>
// <p> LPCTSTR szFont</p>
// <p> int nAlign</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameObjectButton::Create(LPCTSTR lpName, _SIZE siSize, CResource* pResource, LPCTSTR lpCaption, LPCTSTR szFont, int nAlign){
__super::Create(lpName, siSize, Type_Button);
//BUTTON纹理
m_Sprite.Create(lpName, siSize, pResource);
//Button Caption
m_Caption.Create(lpName, siSize, szFont);
//设置标题
m_Caption.SetText(lpCaption);
//设置对齐方式
m_Caption.SetAlign(nAlign);
//设置按钮纹理
for(int i=0;i<5;i++){
m_rcStatus[i].left = 0;
m_rcStatus[i].top = siSize.cy*i;
m_rcStatus[i].right = siSize.cx;
m_rcStatus[i].bottom = siSize.cy*(i+1);
}
return true;
}
//************************************
// <p>Description: 按钮创建</p>
// <p>Parameters: </p>
// <p> LPCTSTR lpName</p>
// <p> _RECT rcRes</p>
// <p> CResource * pResource</p>
// <p> LPCTSTR lpCaption</p>
// <p> LPCTSTR szFont</p>
// <p> int nAlign</p>
// Randy 8-25
// <p>Returns: bool</p>
//************************************
bool CGameObjectButton::Create(LPCTSTR lpName, _RECT rcRes, CResource* pResource, LPCTSTR lpCaption, LPCTSTR szFont, int nAlign){
_SIZE siSize;
siSize.cx=rcRes.right-rcRes.left;
siSize.cy=rcRes.bottom-rcRes.top;
__super::Create(lpName, siSize, Type_Button);
//BUTTON纹理
m_Sprite.Create(lpName, rcRes, pResource);
//Button Caption
m_Caption.Create(lpName, siSize, szFont);
//设置标题
m_Caption.SetText(lpCaption);
//设置对齐方式
m_Caption.SetAlign(nAlign);
//设置按钮纹理
for(int i=0;i<5;i++){
m_rcStatus[i].left = rcRes.left;
m_rcStatus[i].top = siSize.cy*i;
m_rcStatus[i].right = siSize.cx;
m_rcStatus[i].bottom = siSize.cy*(i+1);
}
return true;
}
//************************************
// <p>Description: 按钮渲染</p>
// <p>Parameters: </p>
// <p> WPARAM wParam</p>
//
// <p>Returns: void</p>
//************************************
void CGameObjectButton::Render(WPARAM wParam){
m_Sprite.Render(wParam);
m_Caption.Render(wParam);
}
//************************************
// <p>Description: 设置标题</p>
// <p>Parameters: </p>
// <p> LPCTSTR lpCaption</p>
// <p> int nAlign</p>
//
// <p>Returns: void</p>
//************************************
void CGameObjectButton::SetCaption(LPCTSTR lpCaption, int nAlign){
m_Caption.SetText(lpCaption);
m_Caption.SetAlign(nAlign);
}
//************************************
// <p>Description: 返回标题</p>
// <p>Parameters: </p>
//
// <p>Returns: LPCTSTR</p>
//************************************
LPCTSTR CGameObjectButton::GetCaption(){
return m_Caption.GetText();
}
//************************************
// <p>Description: 设置标题对齐</p>
// <p>Parameters: </p>
// <p> int nAlign</p>
//
// <p>Returns: void</p>
//************************************
void CGameObjectButton::SetCaptionAlign(int nAlign){
m_Caption.SetAlign(nAlign);
}
//************************************
// <p>Description: 返回标题对齐方式</p>
// <p>Parameters: </p>
//
// <p>Returns: WORD</p>
//************************************
WORD CGameObjectButton::GetCaptionAlign(){
return m_Caption.GetAlign();
}
//返回标题对象
IGameObjectText* CGameObjectButton::GetCaptionObject(){
return GET_OBJECT_INTERFACE(m_Caption, IGameObjectText);
}
//返回图片对象
IGameObjectSprite* CGameObjectButton::GetSpriteObject(){
return GET_OBJECT_INTERFACE(m_Sprite, IGameObjectSprite);
}
//************************************
// <p>Description: 设置禁用</p>
// <p>Parameters: </p>
// <p> bool bFlag</p>
//
// <p>Returns: void</p>
//************************************
void CGameObjectButton::SetDisabled(bool bFlag){
if(bFlag){
m_Sprite.SetTextureSize(m_rcStatus[Button_Disabled]);
}
else{
m_Sprite.SetTextureSize(m_rcStatus[Button_Normal]);
}
__super::SetDisabled(bFlag);
}
//************************************
// <p>Description: 设置点击</p>
// <p>Parameters: </p>
// <p> bool bFlag</p>
//
// <p>Returns: void</p>
//************************************
void CGameObjectButton::SetClickabled(bool bFlag){
if(bFlag){
m_Sprite.SetTextureSize(m_rcStatus[Button_Normal]);
}
else{
m_Sprite.SetTextureSize(m_rcStatus[Button_UnClickabled]);
}
__super::SetClickabled(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 CGameObjectButton::OnMouseIn(float x, float y, int nType, UINT nMessage, UINT nComboKey){
//禁止状态不作处理
if(IsDisabled()) return true;
m_Sprite.SetTextureSize(m_rcStatus[Button_MoveIn]);
return true;
}
//************************************
// <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 CGameObjectButton::OnMouseOut(float x, float y, int nType, UINT nMessage, UINT nComboKey){
//禁止状态不作处理
if(IsDisabled()) return true;
int nState = IsDisabled()?Button_Disabled:(IsClickabled()?Button_Normal:Button_UnClickabled);
m_Sprite.SetTextureSize(m_rcStatus[nState]);
return true;
}
//************************************
// <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 CGameObjectButton::OnMouseClick(float x, float y, int nType, UINT nMessage, UINT nComboKey){
//禁止状态不作处理
if(IsDisabled() || !IsClickabled()) return true;
if(nType==INPUT_MOUSE_DOWN){
m_Sprite.SetTextureSize(m_rcStatus[Button_Click]);
}
else{
m_Sprite.SetTextureSize(m_rcStatus[Button_MoveIn]);
}
return true;
}
//************************************
// <p>Description: 接口查询</p>
// <p>Parameters: </p>
// <p> const IID & Guid</p>
// <p> DWORD dwQueryVer</p>
//
// <p>Returns: void *</p>
//************************************
void * CGameObjectButton::QueryInterface(const IID & Guid, DWORD dwQueryVer){
QUERYINTERFACE(IGameObjectButton,Guid,dwQueryVer);
QUERYINTERFACE(IGameObject,Guid,dwQueryVer);
QUERYINTERFACE(IBaseObject,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IGameObjectButton,Guid,dwQueryVer);
return NULL;
}
//************************************
// <p>Description: =操作重载</p>
// <p>Parameters: </p>
// <p> const CGameObjectButton & GameObject</p>
//
// <p>Returns: CGameObjectButton&</p>
//************************************
CGameObjectButton& CGameObjectButton::operator=(CGameObjectButton& GameObject){
CGameGroup* pOtherBaseClass = static_cast<CGameGroup *>(&GameObject);
CGameGroup* pMySelfBaseClass = static_cast<CGameGroup *>(this);
*pMySelfBaseClass = *pOtherBaseClass;
CopyMemory(m_rcStatus, GameObject.m_rcStatus, sizeof(m_rcStatus));
m_Sprite = GameObject.m_Sprite;
m_Caption = GameObject.m_Caption;
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -