📄 gameobjectgraph.cpp
字号:
// ***************************************************************
// GameObjectGraph version: 1.0
// -------------------------------------------------------------
// File Name: GameObjectGraph.cpp
// Created: 2007/07/20
// Modified: 2007/07/20 12:35
// Author: Ben
// Msn: bwenpig@gmail.com
// Email: bwenpig@gmail.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 Ben .
// Copyright (C) 2007 - All Rights Reserved.
// ***************************************************************
#include "StdAfx.h"
#include ".\gameobjectgraph.h"
#define _Min3(x, y, z) (x<y?x:y)<z?(x<y?x:y):z;
#define _Max3(x, y, z) (x>y?x:y)>z?(x>y?x:y):z;
CGameObjectGraph::CGameObjectGraph(void)
{
m_enGraphType = Graph_Square;
m_enGraphLine = Line_Normal;
m_wBorderWidth = 1;
m_dwBorderColor = 0xFFFFFFFF;
m_dwBackGroundColor = 0xFF000000;
m_hTarget = NULL;
m_pResource = NULL;
m_hPreTarget = NULL;
ZeroMemory(m_piPoints, sizeof(m_piPoints));
m_hgeSprite = new hgeSprite(NULL, 0, 0, 0, 0);
m_hgeSprite->SetBlendMode(BLEND_ALPHAADD);
}
CGameObjectGraph::~CGameObjectGraph(void)
{
if(m_hgeSprite)
SafeDelete(m_hgeSprite);
if(m_hTarget){
m_pResource->GetGDI()->Target_Free(m_hTarget);
m_hTarget = NULL;
}
}
/**
* 对象创建
*/
bool CGameObjectGraph::Create(LPCTSTR lpName, _SIZE siSize, CResource* pResource, enGraphType enGraphType, enGraphLine enGraphLine, WORD wBorderWidth, DWORD dwBackGroundColor, DWORD dwBorderColor){
__super::Create(lpName,siSize,Type_Graph);
m_pResource=pResource;
m_enGraphLine = enGraphLine;
m_wBorderWidth = wBorderWidth;
m_dwBorderColor = dwBorderColor;
m_dwBackGroundColor = dwBackGroundColor;
SetGraphType(enGraphType);
ReDraw();
return true;
}
/**
* 对象创建(三角形)
*/
bool CGameObjectGraph::Create(LPCTSTR lpName, _SIZE siSize, CResource* pResource, _POINT piPoint1, _POINT piPoint2, _POINT piPoint3){
//计算三角形的正方体大小
siSize.cx = _Max3(piPoint1.x, piPoint2.x, piPoint3.x) - _Min3(piPoint1.x, piPoint2.x, piPoint3.x);
siSize.cy = _Max3(piPoint1.y, piPoint2.y, piPoint3.y) - _Min3(piPoint1.y, piPoint2.y, piPoint3.y);
__super::Create(lpName,siSize,Type_Graph);
m_pResource=pResource;
m_enGraphType = Graph_Triangle;
m_piPoints[0] = piPoint1;
m_piPoints[1] = piPoint2;
m_piPoints[2] = piPoint3;
ReDraw();
return false;
}
/**
* 对象创建(线形)
*/
bool CGameObjectGraph::Create(LPCTSTR lpName, _SIZE siSize, CResource* pResource, _POINT piPoint1, _POINT piPoint2){
//计算线形的正方体大小
siSize.cx = abs(piPoint1.x - piPoint2.x)+1;
siSize.cy = abs(piPoint1.y - piPoint2.y)+1;
__super::Create(lpName,siSize,Type_Graph);
m_pResource=pResource;
m_enGraphType = Graph_Line;
m_piPoints[0] = piPoint1;
m_piPoints[1] = piPoint2;
ReDraw();
return false;
}
/**
* 对象创建(圆形)
*/
bool CGameObjectGraph::Create(LPCTSTR lpName, _SIZE siSize, CResource* pResource, float fRadii1, float fRadii2){
m_fRadii1 = fRadii1;
m_fRadii2 = fRadii2;
siSize.cx = 2*fRadii1;
siSize.cy = 2*fRadii2;
__super::Create(lpName,siSize,Type_Graph);
m_pResource=pResource;
m_enGraphType = Graph_Circular;
m_piPoints[0].x = fRadii1; m_piPoints[1].x = fRadii2;
return false;
}
//************************************
// <p>Description: Render 对象渲染</p>
// <p>Parameters: </p>
// <p> WPARAM wParam Update时间参数</p>
//
// <p>Returns: void</p>
//************************************
void CGameObjectGraph::Render(WPARAM wParam/* =NULL */)
{
//m_hgeSprite->RenderEx(0, 0, 0);
if(m_hgeSprite)
m_hgeSprite->RenderEx(m_BasalInfo.ScreenPos.x, m_BasalInfo.ScreenPos.y, m_GameBasalInfo.Angle, m_GameBasalInfo.Scaling.cx, m_GameBasalInfo.Scaling.cy);
return;
}
/**
* 输出至纹理
*/
void CGameObjectGraph::ReDraw(){
//当渲染大小与对象大小不一致时重新生成渲染目标
if(m_siTarget.cx != m_BasalInfo.Size.cx || m_siTarget.cy != m_BasalInfo.Size.cy){
m_GameBasalInfo.Scaling.cx = m_GameBasalInfo.Scaling.cy = 1;
m_siTarget = m_BasalInfo.Size;
if(m_hTarget){
m_hPreTarget = m_hTarget;
}
m_hTarget = m_pResource->GetGDI()->Target_Create((int)m_siTarget.cx, (int)m_siTarget.cy, false);
}
m_pResource->GetGDI()->Gfx_BeginScene(m_hTarget);
m_pResource->GetGDI()->Gfx_Clear(m_dwBackGroundColor);
if(m_pResource->GetTexture()){
m_hgeSprite->SetTexture(m_pResource->GetTexture());
m_hgeSprite->SetTextureRect(0, 0, m_BasalInfo.Size.cx, m_BasalInfo.Size.cy, false);
m_hgeSprite->Render(0, 0);
}
switch(m_enGraphType){
case Graph_Line:
DrawLine(_POINT(0, 0), _POINT(m_BasalInfo.Size.cx, m_BasalInfo.Size.cy));
break;
case Graph_Square:
DrawSquare();
break;
case Graph_Triangle:
DrawTriangle();
break;
}
m_pResource->GetGDI()->Gfx_EndScene();
//if(m_hgeSprite){
// SafeDelete(m_hgeSprite);
// m_hgeSprite = new hgeSprite(m_pResource->GetGDI()->Target_GetTexture(m_hTarget), 0, 0, m_BasalInfo.Size.cx, m_BasalInfo.Size.cy);
//}
//m_pResource->GetGDI()->Texture_Free(m_hgeSprite->GetTexture());
m_hgeSprite->SetTexture(m_pResource->GetGDI()->Target_GetTexture(m_hTarget));
m_hgeSprite->SetTextureRect(0,0,m_BasalInfo.Size.cx, m_BasalInfo.Size.cy, false);
if(m_hPreTarget){
m_pResource->GetGDI()->Target_Free(m_hPreTarget);
m_hPreTarget = NULL;
}
}
/**
* 画圆形
*/
void CGameObjectGraph::DrawCircular(){
}
/**
* 画线
*/
void CGameObjectGraph::DrawLine(_POINT piStart, _POINT piEnd){
for(WORD wWidth=0;wWidth<m_wBorderWidth;wWidth++)
m_pResource->GetGDI()->Gfx_RenderLine(piStart.x, piStart.y + wWidth, piEnd.x, piEnd.y+wWidth, m_dwBorderColor, 0);
return;
}
/**
* 画方体
*/
void CGameObjectGraph::DrawSquare(){
DrawLine(m_piPoints[0], m_piPoints[1]);
DrawLine(m_piPoints[1], m_piPoints[2]);
DrawLine(m_piPoints[2], m_piPoints[3]);
DrawLine(m_piPoints[3], m_piPoints[0]);
}
/**
* 画三角形
*/
void CGameObjectGraph::DrawTriangle(){
DrawLine(m_piPoints[0], m_piPoints[1]);
DrawLine(m_piPoints[1], m_piPoints[2]);
DrawLine(m_piPoints[2], m_piPoints[0]);
}
/**
* 设置背景颜色
*/
void CGameObjectGraph::SetBackGroundColor(DWORD dwColor){
m_dwBackGroundColor = dwColor;
}
/**
* 设置边框颜色
*/
void CGameObjectGraph::SetBorderColor(DWORD dwColor){
m_dwBorderColor = dwColor;
}
/**
* 设置边框宽度
*/
void CGameObjectGraph::SetBorderWidth(WORD wWidth){
m_wBorderWidth = wWidth;
}
/**
* 设置圆形的参数
*/
void CGameObjectGraph::SetCircular(float fRadii1, float fRadii2){
m_fRadii1 = fRadii1;
m_fRadii2 = fRadii2;
}
/**
* 设置图形类型
*/
void CGameObjectGraph::SetGraphType(enGraphType enGraphType){
m_enGraphType = enGraphType;
_SIZE siSize = m_BasalInfo.Size;
switch(m_enGraphType){
case Graph_Line:
m_piPoints[0].x = m_piPoints[0].y = 1;
m_piPoints[1].x = siSize.cx;m_piPoints[1].y = siSize.cy;
break;
case Graph_Square:
m_piPoints[0].x = m_piPoints[0].y = 1;
m_piPoints[1].x = siSize.cx; m_piPoints[1].y = 1;
m_piPoints[2].x = siSize.cx; m_piPoints[2].y = siSize.cy;
m_piPoints[3].x = 1; m_piPoints[3].y = siSize.cy;
break;
case Graph_Triangle:
m_piPoints[0].x = siSize.cx/2;m_piPoints[0].y = 1;
m_piPoints[1].x = siSize.cx;m_piPoints[1].y = siSize.cy;
m_piPoints[2].x = 1;m_piPoints[2].y = siSize.cy;
break;
case Graph_Circular:
m_piPoints[0].x = siSize.cx/2;
m_piPoints[0].y = siSize.cy/2;
break;
}
}
/**
* 设置线的类型
*/
void CGameObjectGraph::SetLineType(enGraphLine enGraphLine){
m_enGraphLine = enGraphLine;
}
/**
* 设置三角形参数
*/
void CGameObjectGraph::SetTriangle(_POINT piPoint1, _POINT piPoint2, _POINT piPoint3){
m_piPoints[0] = piPoint1;
m_piPoints[1] = piPoint2;
m_piPoints[2] = piPoint3;
}
/**
* 设置混和模式
*/
void CGameObjectGraph::SetBlendMode(int nBlendMode){
m_hgeSprite->SetBlendMode(nBlendMode);
}
/**
* 设置背景纹理
*/
void CGameObjectGraph::SetBackGround(CResource* pResource){
//m_hgeSprite->SetTexture(pResource->GetTexture());
m_pResource = pResource;
}
/**
* 调整各顶点
*/
void CGameObjectGraph::AdjustPoints(_LPPOINT pPoints, WORD wLen){
if(pPoints==NULL) return;
switch(m_enGraphType){
case Graph_Line:
if(wLen!=2) return;
m_piPoints[0] = pPoints[0];
m_piPoints[1] = pPoints[1];
break;
case Graph_Square:
if(wLen!=4) return;
m_piPoints[0] = pPoints[0];
m_piPoints[1] = pPoints[1];
m_piPoints[2] = pPoints[2];
m_piPoints[3] = pPoints[3];
break;
case Graph_Triangle:
if(wLen!=3) return;
m_piPoints[0] = pPoints[0];
m_piPoints[1] = pPoints[1];
m_piPoints[2] = pPoints[2];
break;
case Graph_Circular:
break;
}
ReDraw();
}
/**
* 调整大小(有别于SetSize的缩放)
*/
void CGameObjectGraph::AdjustPoints(_SIZE siSize){
m_BasalInfo.Size = siSize;
SetGraphType(m_enGraphType);
ReDraw();
}
/**
* 返回背景颜色
*/
DWORD CGameObjectGraph::GetBackGroundColor(){
return m_dwBackGroundColor;
}
/**
* 返回边框颜色
*/
DWORD CGameObjectGraph::GetBorderColor(){
return m_dwBorderColor;
}
/**
* 返回边框宽度
*/
WORD CGameObjectGraph::GetBorderWidth(){
return m_wBorderWidth;
}
/**
* 返回图形类型
*/
enGraphType CGameObjectGraph::GetGraphType(){
return m_enGraphType;
}
/**
* 返回线的类型
*/
enGraphLine CGameObjectGraph::GetLineType(){
return m_enGraphLine;
}
/**
* 返回背景纹理
*/
CResource* CGameObjectGraph::GetBackGround(){
return m_pResource;
}
//************************************
// <p>Description: 重获焦点</p>
// <p>Parameters: </p>
// Randy 8-27
// <p>Returns: void</p>
//************************************
void CGameObjectGraph::FocusGain(){
if(m_hgeSprite&&m_pResource)
{
ReDraw();
}
}
//************************************
// <p>Description: QueryInterface 查询接口</p>
// <p>Parameters: </p>
// <p> const IID & Guid 接口ID</p>
// <p> DWORD dwQueryVer 接口版本</p>
//
// <p>Returns: void*</p>
//************************************
void* CGameObjectGraph::QueryInterface(const IID &Guid,DWORD dwQueryVer){
QUERYINTERFACE(IGameObjectGraph,Guid,dwQueryVer);
QUERYINTERFACE(IGameObject,Guid,dwQueryVer);
QUERYINTERFACE(IBaseObject,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IGameObjectGraph,Guid,dwQueryVer);
return NULL;
}
//************************************
// <p>Description: 操作重载</p>
// <p>Parameters: </p>
// <p> CGameObjectGraph& GameObject</p>
//
// <p>Returns: CGameObjectGraph&</p>
//************************************
CGameObjectGraph& CGameObjectGraph::operator=(CGameObjectGraph& GameObject){
CGameObject* pOtherBaseClass = static_cast<CGameObject *>(&GameObject);
CGameObject* pMySelfBaseClass = static_cast<CGameObject *>(this);
*pMySelfBaseClass = *pOtherBaseClass;
m_enGraphType = GameObject.m_enGraphType;
m_enGraphLine = GameObject.m_enGraphLine;
m_wBorderWidth = GameObject.m_wBorderWidth;
m_dwBorderColor = GameObject.m_dwBorderColor;
m_dwBackGroundColor = GameObject.m_dwBackGroundColor;
m_pResource = GameObject.m_pResource;
//*m_hgeSprite = *GameObject.m_hgeSprite;
CopyMemory((LPVOID)m_piPoints, GameObject.m_piPoints, sizeof(m_piPoints));
m_hgeSprite->SetBlendMode(GameObject.m_hgeSprite->GetBlendMode());
ReDraw();
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -