ImageVerifierCode 换一换
你正在下载:

include.docx

[预览]
格式:DOCX , 页数:13 ,大小:17.70KB ,
资源ID:7949888      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7949888.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(include.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

include.docx

1、include#include#include#includeD3DGUIClass.h/-/ Desc: 构造函数/-D3DGUIClass:D3DGUIClass(LPDIRECT3DDEVICE9 device, int w, int h) m_pFonts = NULL; m_pControls = NULL; m_pVertexBuffer = NULL; m_nTotalFontNum = m_nTotalControlNum = m_nTotalBufferNum = 0; m_nWindowWidth = m_nWindowHeight = 0; m_bIsBackground

2、Used = false; m_pd3dDevice = device; m_nWindowWidth = w; m_nWindowHeight = h; memset(&m_Background, 0, sizeof(GUICONTROL);/-/ Name: D3DGUIClass:CreateTextFont( )/ Desc: 字体创建函数/-bool D3DGUIClass:CreateTextFont(wchar_t *fontName, int size, int *fontID) if(!m_pd3dDevice) return false; if(!m_pFonts) m_p

3、Fonts = new LPD3DXFONT1; if(!m_pFonts) return false; else LPD3DXFONT *temp; temp = new LPD3DXFONTm_nTotalFontNum + 1; if(!temp) return false; memcpy(temp, m_pFonts, sizeof(LPD3DXFONT) * m_nTotalFontNum); delete m_pFonts; m_pFonts = temp; / 调用D3DXCreateTextFont函数创建字体 D3DXCreateFont(m_pd3dDevice, size

4、, 0, 0, 1000, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, fontName, &m_pFontsm_nTotalFontNum); if(!m_pFontsm_nTotalFontNum) return false; / 存下字体ID和ID计数。 if(fontID) *fontID = m_nTotalFontNum; m_nTotalFontNum+; return true;/-/ Name: D3DGUIClass:AddBackground( )/ Desc: 创建保存背景图的缓存函数/-boo

5、l D3DGUIClass:AddBackground(wchar_t *fileName) if(!fileName) return false; m_Background.m_type = UGP_GUI_Background; /从文件载入纹理图片 if(D3DXCreateTextureFromFile(m_pd3dDevice, fileName, &m_Background.m_Background) != D3D_OK) return false; / 获取窗口宽度和高度,以便稍后的背景铺满窗口 float w = (float)m_nWindowWidth; float h =

6、 (float)m_nWindowHeight; GUIVERTEX obj = w, 0, 0.0f, 1, D3DCOLOR_XRGB(255,255,255), 1.0f, 0.0f, w, h, 0.0f, 1, D3DCOLOR_XRGB(255,255,255), 1.0f, 1.0f, 0, 0, 0.0f, 1, D3DCOLOR_XRGB(255,255,255), 0.0f, 0.0f, 0, h, 0.0f, 1, D3DCOLOR_XRGB(255,255,255), 0.0f, 1.0f, ; / 创建顶点缓存 if(FAILED(m_pd3dDevice-Creat

7、eVertexBuffer(sizeof(obj), 0, D3DFVF_GUI, D3DPOOL_DEFAULT, &m_BackgroundBuffer, NULL) return false; / 填充顶点缓存 void *ptr; if(FAILED(m_BackgroundBuffer-Lock(0, sizeof(obj), (void*)&ptr, 0) return false; memcpy(ptr, obj, sizeof(obj); m_BackgroundBuffer-Unlock(); m_bIsBackgroundUsed = true; return true;/

8、-/ Name: D3DGUIClass:AddStaticText( )/ Desc: 创建静态文本控件/-bool D3DGUIClass:AddStaticText(int id, wchar_t *text, float x, float y, unsigned long color, int fontID) if(!text | fontID = m_nTotalFontNum) return false; /下面的代码用于创建一个控件 if(!m_pControls) m_pControls = new GUICONTROL1; if(!m_pControls) return fa

9、lse; memset(&m_pControls0, 0, sizeof(GUICONTROL); else GUICONTROL *temp; temp = new GUICONTROLm_nTotalControlNum + 1; if(!temp) return false; memset(temp, 0, sizeof(GUICONTROL) * (m_nTotalControlNum + 1); memcpy(temp, m_pControls, sizeof(GUICONTROL) * m_nTotalControlNum); delete m_pControls; m_pCont

10、rols = temp; / 填充我们需要的静态文本信息 m_pControlsm_nTotalControlNum.m_type = UGP_GUI_STATICTEXT; m_pControlsm_nTotalControlNum.m_id = id; m_pControlsm_nTotalControlNum.m_color = color; m_pControlsm_nTotalControlNum.m_xPos = x; m_pControlsm_nTotalControlNum.m_yPos = y; m_pControlsm_nTotalControlNum.m_listID =

11、 fontID; / 复制文本数据 int len = wcslen(text); m_pControlsm_nTotalControlNum.m_text = new wchar_tlen+1; if(!m_pControlsm_nTotalControlNum.m_text) return false; wcscpy(m_pControlsm_nTotalControlNum.m_text, text); /m_pControlsm_nTotalControlNum.m_textlen = 0; /增量总数的计算 m_nTotalControlNum+; return true;/-/ N

12、ame: D3DGUIClass:AddButton( )/ Desc: 创建按钮控件的函数/-bool D3DGUIClass:AddButton(int id, float x, float y, wchar_t *up, wchar_t *over, wchar_t *down) if(!up | !over | !down) return false; if(!m_pControls) m_pControls = new GUICONTROL1; if(!m_pControls) return false; memset(&m_pControls0, 0, sizeof(GUICONT

13、ROL); else GUICONTROL *temp; temp = new GUICONTROLm_nTotalControlNum + 1; if(!temp) return false; memset(temp, 0, sizeof(GUICONTROL) * (m_nTotalControlNum + 1); memcpy(temp, m_pControls, sizeof(GUICONTROL) * m_nTotalControlNum); delete m_pControls; m_pControls = temp; / Set all the data needed to re

14、nder/process a button. m_pControlsm_nTotalControlNum.m_type = UGP_GUI_BUTTON; m_pControlsm_nTotalControlNum.m_id = id; m_pControlsm_nTotalControlNum.m_xPos = x; m_pControlsm_nTotalControlNum.m_yPos = y; m_pControlsm_nTotalControlNum.m_listID = m_nTotalBufferNum; / 从文件加载纹理 if(D3DXCreateTextureFromFil

15、e(m_pd3dDevice, up, &m_pControlsm_nTotalControlNum.m_upTex) != D3D_OK) return false; if(D3DXCreateTextureFromFile(m_pd3dDevice, over, &m_pControlsm_nTotalControlNum.m_overTex) != D3D_OK) return false; if(D3DXCreateTextureFromFile(m_pd3dDevice, down, &m_pControlsm_nTotalControlNum.m_downTex) != D3D_O

16、K) return false; unsigned long white = D3DCOLOR_XRGB(255,255,255); /获取一下图形的宽度和高度 D3DSURFACE_DESC desc; m_pControlsm_nTotalControlNum.m_upTex-GetLevelDesc(0, &desc); float w = (float)desc.Width; float h = (float)desc.Height; m_pControlsm_nTotalControlNum.m_width = w; m_pControlsm_nTotalControlNum.m_h

17、eight = h; GUIVERTEX obj = w + x, 0 + y, 0.0f, 1, white, 1.0f, 0.0f, w + x, h + y, 0.0f, 1, white, 1.0f, 1.0f, 0 + x, 0 + y, 0.0f, 1, white, 0.0f, 0.0f, 0 + x, h + y, 0.0f, 1, white, 0.0f, 1.0f, ; /创建顶点缓存 if(!m_pVertexBuffer) m_pVertexBuffer = new LPDIRECT3DVERTEXBUFFER91; if(!m_pVertexBuffer) retur

18、n false; else LPDIRECT3DVERTEXBUFFER9 *temp; temp = new LPDIRECT3DVERTEXBUFFER9m_nTotalBufferNum + 1; if(!temp) return false; memcpy(temp, m_pVertexBuffer, sizeof(LPDIRECT3DVERTEXBUFFER9) * m_nTotalBufferNum); delete m_pVertexBuffer; m_pVertexBuffer = temp; if(FAILED(m_pd3dDevice-CreateVertexBuffer(

19、sizeof(obj), 0, D3DFVF_GUI, D3DPOOL_DEFAULT, &m_pVertexBufferm_nTotalBufferNum, NULL) return false; /填充顶点缓存 void *ptr; if(FAILED(m_pVertexBufferm_nTotalBufferNum-Lock(0, sizeof(obj), (void*)&ptr, 0) return false; memcpy(ptr, obj, sizeof(obj); m_pVertexBufferm_nTotalBufferNum-Unlock(); / 自增 m_nTotalB

20、ufferNum+; / 自增 m_nTotalControlNum+; return true;/-/ Name: D3DGUIClass:ClearUp( )/ Desc: 清理门户释放资源的函数/-void D3DGUIClass:ClearUp() /清理门户,释放所有的资源 if(m_bIsBackgroundUsed) if(m_Background.m_Background) m_Background.m_Background-Release(); if(m_BackgroundBuffer) m_BackgroundBuffer-Release(); m_Background.

21、m_Background = NULL; m_BackgroundBuffer = NULL; for(int i = 0; i Release(); m_pFontsi = NULL; if(m_pFonts) delete m_pFonts; m_pFonts = NULL; m_nTotalFontNum = 0; for(int i = 0; i Release(); m_pVertexBufferi = NULL; if(m_pVertexBuffer) delete m_pVertexBuffer; m_pVertexBuffer = NULL; m_nTotalBufferNum

22、 = 0; for(int i = 0; i Release(); m_pControlsi.m_Background = NULL; if(m_pControlsi.m_upTex) m_pControlsi.m_upTex-Release(); m_pControlsi.m_upTex = NULL; if(m_pControlsi.m_downTex) m_pControlsi.m_downTex-Release(); m_pControlsi.m_downTex = NULL; if(m_pControlsi.m_overTex) m_pControlsi.m_overTex-Rele

23、ase(); m_pControlsi.m_overTex = NULL; if(m_pControlsi.m_text) delete m_pControlsi.m_text; m_pControlsi.m_text = NULL; if(m_pControls) delete m_pControls; m_pControls = NULL; m_nTotalControlNum = 0;/-/ Name:ProcessGUI/ Desc: 全局的函数,封装渲染整个GUI系统,同样还为控件调用回调函数/-void ProcessGUI(D3DGUIClass *gui, bool LMBDo

24、wn, int mouseX, int mouseY, void(*funcPtr)(int id, int state) if(!gui) return; LPDIRECT3DDEVICE9 device = gui-GetD3dDevice(); if(!device) return; / 绘制背景 GUICONTROL *Background = gui-GetBackground(); LPDIRECT3DVERTEXBUFFER9 bdBuffer = gui-GetBackgroundBuffer(); /已经创建出的东西才绘制,所以来个if if(gui-IsBackground

25、Used() & Background & bdBuffer) device-SetTexture(0, Background-m_Background); device-SetStreamSource(0, bdBuffer, 0, sizeof(GUIVERTEX); device-SetFVF(D3DFVF_GUI); device-DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); device-SetTexture(0, NULL); /用来显示文本的对象 LPD3DXFONT pFont = NULL; RECT fontPosition = 0, 0, (long)gui-GetWindowWidth(), (long)gui-GetWindowHeig

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1