1 /*************************************
2 *函数名称:visit
3 *函数功能:获取游戏设计的分辨率与真实设备的比例,并根据值来剪切显示区域
4 *函数参数:void
5 *函数返回值:void
6 *笔记:
7 1.glEnable用于开启opengl相应的功能
8 2.GL_SCISSOR_TEST根据函数glScissor设置,启用图形剪切
9 3.glScissor
10 http://blog.csdn.net/augusdi/article/details/7282214
11 *************************************/
12 void CXSroll::visit()
13 {
14 glEnable(GL_SCISSOR_TEST);
15
16 CCRect tPrtScr(0, 0, 0, 0);
17 if (this->getParent())
18 {
19 tPrtScr.origin = this->getParent()->convertToWorldSpace(this->getPosition());
20 }
21 else
22 {
23 tPrtScr.origin = this->getPosition();
24 }
25
26 tPrtScr.size.width = this->getContentSize().width;
27 tPrtScr.size.height = this->getContentSize().height;
28
29 //获取游戏设计的分辨率与真实设备的比例
30 tPrtScr.origin.x /= CCDirector::sharedDirector()->getWinSize().width / CCDirector::sharedDirector()->getOpenGLView()->getFrameSize().width;
31 tPrtScr.origin.y /= CCDirector::sharedDirector()->getWinSize().height / CCDirector::sharedDirector()->getOpenGLView()->getFrameSize().height;
32 tPrtScr.size.width /= CCDirector::sharedDirector()->getWinSize().width / CCDirector::sharedDirector()->getOpenGLView()->getFrameSize().width;
33 tPrtScr.size.height /= CCDirector::sharedDirector()->getWinSize().height / CCDirector::sharedDirector()->getOpenGLView()->getFrameSize().height;
34
35 glScissor( tPrtScr.origin.x, tPrtScr.origin.y, tPrtScr.size.width, tPrtScr.size.height);
36
37 CXWindow::visit();
38 glDisable(GL_SCISSOR_TEST);
39 }