Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
nutty898 committed Jun 19, 2013
1 parent e7270be commit 4478c02
Show file tree
Hide file tree
Showing 26 changed files with 449 additions and 101 deletions.
82 changes: 63 additions & 19 deletions CocoGUILIB/CocoGUILIB/BaseClasses/Widget/CocoContainerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@

#include "CocoContainerWidget.h"
#include "CClipAbleLayerColor.h"
#include "CClipAbleLayerGradient.h"
#include "DictionaryHelper.h"

namespace cs {

CocoContainerWidget::CocoContainerWidget():
m_fWidth(0.0),
m_fHeight(0.0),
m_bClipAble(false)
m_bClipAble(false),
m_renderType(RENDER_TYPE_LAYERCOLOR)
{
this->m_nWidgetType = 1;
}
Expand Down Expand Up @@ -98,16 +100,34 @@ namespace cs {
void CocoContainerWidget::setClipAble(bool able)
{
this->m_bClipAble = able;
DYNAMIC_CAST_CLIPLAYERCOLOR->setClipAble(able);
switch (m_renderType) {
case RENDER_TYPE_LAYERCOLOR:
DYNAMIC_CAST_CLIPLAYERCOLOR->setClipAble(able);
break;
case RENDER_TYPE_LAYERGRADIENT:
DYNAMIC_CAST_CLIPLAYERGRADIENT->setClipAble(able);
break;
default:
break;
}
for (int i=0; i<this->m_children->count(); i++) {
CocoWidget* child = (CocoWidget*)(this->m_children->objectAtIndex(i));
child->setNeedCheckVisibleDepandParent(able);
}
}

void CocoContainerWidget::setClipRect(cocos2d::CCRect rect)
void CocoContainerWidget::setClipRect(const cocos2d::CCRect &rect)
{
DYNAMIC_CAST_CLIPLAYERCOLOR->setClipRect(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
switch (m_renderType) {
case RENDER_TYPE_LAYERCOLOR:
DYNAMIC_CAST_CLIPLAYERCOLOR->setClipRect(rect);
break;
case RENDER_TYPE_LAYERGRADIENT:
DYNAMIC_CAST_CLIPLAYERGRADIENT->setClipRect(rect);
break;
default:
break;
}
}

void CocoContainerWidget::updateWidth()
Expand All @@ -120,26 +140,35 @@ namespace cs {

}

void CocoContainerWidget::setColorAndSize(int r,int g,int b,int o,float width,float height)
{
DYNAMIC_CAST_CLIPLAYERCOLOR->initWithColor(cocos2d::ccc4(r, g, b, o), width, height);
this->m_fWidth = width;
this->m_fHeight = height;
this->updateClipSize();
}
// void CocoContainerWidget::setColorAndSize(int r,int g,int b,int o,float width,float height)
// {
// DYNAMIC_CAST_CLIPLAYERCOLOR->initWithColor(cocos2d::ccc4(r, g, b, o), width, height);
// this->m_fWidth = width;
// this->m_fHeight = height;
// this->updateClipSize();
// }

void CocoContainerWidget::setSize(float width,float height)
void CocoContainerWidget::setSize(const cocos2d::CCSize &size)
{
DYNAMIC_CAST_CLIPLAYERCOLOR->setContentSize(cocos2d::CCSize(width,height));
this->m_fWidth = width;
this->m_fHeight = height;
switch (m_renderType) {
case RENDER_TYPE_LAYERCOLOR:
DYNAMIC_CAST_CLIPLAYERCOLOR->setContentSize(size);
break;
case RENDER_TYPE_LAYERGRADIENT:
DYNAMIC_CAST_CLIPLAYERGRADIENT->setContentSize(size);
break;
default:
break;
}
this->m_fWidth = size.width;
this->m_fHeight = size.height;
this->updateClipSize();
}

void CocoContainerWidget::setWidth(float width)
{
this->m_fWidth = width;
this->setSize(this->m_fWidth,this->m_fHeight);
this->setSize(cocos2d::CCSize(width,this->m_fHeight));
}

float CocoContainerWidget::getWidth()
Expand All @@ -150,7 +179,7 @@ namespace cs {
void CocoContainerWidget::setHeight(float height)
{
this->m_fHeight = height;
this->setSize(this->m_fWidth,this->m_fHeight);
this->setSize(cocos2d::CCSize(this->m_fWidth,height));
}

float CocoContainerWidget::getHeight()
Expand Down Expand Up @@ -190,7 +219,22 @@ namespace cs {
{
float asx = this->getAbsoluteScaleX();
float asy = this->getAbsoluteScaleY();
cocos2d::CCSize size = DYNAMIC_CAST_CLIPLAYERCOLOR->getContentSize();
DYNAMIC_CAST_CLIPLAYERCOLOR->setClipSize(size.width*asx, size.height*asy);

switch (m_renderType) {
case RENDER_TYPE_LAYERCOLOR:
{
cocos2d::CCSize size = DYNAMIC_CAST_CLIPLAYERCOLOR->getContentSize();
DYNAMIC_CAST_CLIPLAYERCOLOR->setClipSize(size.width*asx, size.height*asy);
break;
}
case RENDER_TYPE_LAYERGRADIENT:
{
cocos2d::CCSize size = DYNAMIC_CAST_CLIPLAYERGRADIENT->getContentSize();
DYNAMIC_CAST_CLIPLAYERGRADIENT->setClipSize(size.width*asx, size.height*asy);
break;
}
default:
break;
}
}
}
15 changes: 12 additions & 3 deletions CocoGUILIB/CocoGUILIB/BaseClasses/Widget/CocoContainerWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
#include "CocoWidget.h"

namespace cs {

typedef enum
{
RENDER_TYPE_LAYERCOLOR,
RENDER_TYPE_LAYERGRADIENT
}RenderType;


class CocoContainerWidget : public CocoWidget
{
public:
Expand All @@ -42,11 +50,11 @@ namespace cs {
virtual void initNodes();
virtual bool addChild(CocoWidget* child);
virtual void setClipAble(bool able);
virtual void setClipRect(cocos2d::CCRect rect);
virtual void setClipRect(const cocos2d::CCRect &rect);
virtual void updateWidth();
virtual void updateHeight();
virtual void setColorAndSize(int r,int g,int b,int o,float width,float height);
virtual void setSize(float width,float height);
// virtual void setColorAndSize(int r,int g,int b,int o,float width,float height);
virtual void setSize(const cocos2d::CCSize &size);
virtual void setWidth(float width);
virtual float getWidth();
virtual void setHeight(float height);
Expand All @@ -61,6 +69,7 @@ namespace cs {
float m_fWidth;
float m_fHeight;
bool m_bClipAble;
RenderType m_renderType;
};
}

Expand Down
2 changes: 2 additions & 0 deletions CocoGUILIB/CocoGUILIB/BaseClasses/Widget/CocoWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@

#define DYNAMIC_CAST_CLIPLAYERCOLOR dynamic_cast<CClipAbleLayerColor*>(this->m_pCCRenderNode)

#define DYNAMIC_CAST_CLIPLAYERGRADIENT dynamic_cast<CClipAbleLayerGradient*>(this->m_pCCRenderNode)

#define DYNAMIC_CAST_CLABELATLAS dynamic_cast<CLabelAtlas*>(this->m_pCCRenderNode)

#define DYNAMIC_CAST_SCALE9SPRITE dynamic_cast<GUIScale9Sprite*>(this->m_pCCRenderNode)
Expand Down
4 changes: 2 additions & 2 deletions CocoGUILIB/CocoGUILIB/CGraphics/CClipAbleLayerColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace cocos2d;

namespace cs {

CClipAbleLayerColor* CClipAbleLayerColor::create(ccColor4B color, float width, float height){
CClipAbleLayerColor* CClipAbleLayerColor::create(const cocos2d::ccColor4B &color,float width,float height){
CClipAbleLayerColor * pLayer = new CClipAbleLayerColor();
if( pLayer && pLayer->initWithColor(color,width,height))
{
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace cs {
return this->m_bColorEnable;
}

void CClipAbleLayerColor::setClipRect(float x, float y, float width, float height)
void CClipAbleLayerColor::setClipRect(const cocos2d::CCRect &rect)
{

}
Expand Down
4 changes: 2 additions & 2 deletions CocoGUILIB/CocoGUILIB/CGraphics/CClipAbleLayerColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ namespace cs {
public:
CClipAbleLayerColor():m_bClipAble(false),m_fScissorX(0.0),m_fScissorY(0.0),m_fScissorWidth(0.0),m_fScissorHeight(0.0),m_bEnableCustomArea(false),m_bColorEnable(false){};
virtual ~CClipAbleLayerColor(){};
static CClipAbleLayerColor* create(cocos2d::ccColor4B color,float width ,float height);
static CClipAbleLayerColor* create(const cocos2d::ccColor4B &color,float width ,float height);
static CClipAbleLayerColor* create();
bool init();
virtual void visit();
void setClipAble(bool able);
void setColorEnable(bool enable);
bool getColorEnable();
void setClipRect(float x,float y,float width,float height);
void setClipRect(const cocos2d::CCRect &rect);
void setClipSize(float width,float height);
virtual void draw();
protected:
Expand Down
103 changes: 103 additions & 0 deletions CocoGUILIB/CocoGUILIB/CGraphics/CClipAbleLayerGradient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// CClipAbleLayerGradient.cpp
// Test
//
// Created by cai wenzhi on 13-6-18.
//
//

#include "CClipAbleLayerGradient.h"

using namespace cocos2d;

namespace cs {

CClipAbleLayerGradient* CClipAbleLayerGradient::create(const cocos2d::ccColor4B &colorStart,const cocos2d::ccColor4B &colorEnd){
CClipAbleLayerGradient * pLayer = new CClipAbleLayerGradient();
if( pLayer && pLayer->initWithColor(colorStart,colorEnd))
{
pLayer->autorelease();
return pLayer;
}
CC_SAFE_DELETE(pLayer);
return NULL;
}

CClipAbleLayerGradient* CClipAbleLayerGradient::create(){
CClipAbleLayerGradient * pLayer = new CClipAbleLayerGradient();
if( pLayer && pLayer->init())
{
pLayer->autorelease();
return pLayer;
}
CC_SAFE_DELETE(pLayer);
return NULL;
}

bool CClipAbleLayerGradient::init()
{
if (CCLayerGradient::init())
{
// this->setCascadeOpacityEnabled(true);
// this->setCascadeColorEnabled(true);

return true;
}

return false;
}

void CClipAbleLayerGradient::visit(){
if (this->m_bClipAble) {
glEnable(GL_SCISSOR_TEST);
CCPoint local = this->convertToWorldSpace(CCPointZero);

if (this->m_bEnableCustomArea) {
CCEGLView::sharedOpenGLView()->setScissorInPoints(local.x, local.y, this->m_fScissorWidth, this->m_fScissorHeight);
}else{
CCSize s = this->boundingBox().size;
CCEGLView::sharedOpenGLView()->setScissorInPoints(local.x, local.y, s.width, s.height);
}

CCLayerColor::visit();
glDisable(GL_SCISSOR_TEST);
}else {
CCLayerColor::visit();
}
}

void CClipAbleLayerGradient::setClipAble(bool able)
{
this->m_bClipAble = able;
}

void CClipAbleLayerGradient::setColorEnable(bool enable)
{
this->m_bColorEnable = enable;
}

bool CClipAbleLayerGradient::getColorEnable()
{
return this->m_bColorEnable;
}

void CClipAbleLayerGradient::setClipRect(const cocos2d::CCRect &rect)
{

}

void CClipAbleLayerGradient::setClipSize(float width, float height)
{
this->m_bEnableCustomArea = true;
this->m_fScissorWidth = width;
this->m_fScissorHeight = height;
}

void CClipAbleLayerGradient::draw()
{
// to head off the draw call
if (this->m_bColorEnable) {
CCLayerColor::draw();
}
}
}
40 changes: 40 additions & 0 deletions CocoGUILIB/CocoGUILIB/CGraphics/CClipAbleLayerGradient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// CClipAbleLayerGradient.h
// Test
//
// Created by cai wenzhi on 13-6-18.
//
//

#ifndef __Test__CClipAbleLayerGradient__
#define __Test__CClipAbleLayerGradient__

#include "cocos2d.h"

namespace cs {
class CClipAbleLayerGradient : public cocos2d::CCLayerGradient {
public:
CClipAbleLayerGradient():m_bClipAble(false),m_fScissorX(0.0),m_fScissorY(0.0),m_fScissorWidth(0.0),m_fScissorHeight(0.0),m_bEnableCustomArea(false),m_bColorEnable(false){};
virtual ~CClipAbleLayerGradient(){};
static CClipAbleLayerGradient* create(const cocos2d::ccColor4B &colorStart,const cocos2d::ccColor4B &colorEnd);
static CClipAbleLayerGradient* create();
bool init();
virtual void visit();
void setClipAble(bool able);
void setColorEnable(bool enable);
bool getColorEnable();
void setClipRect(const cocos2d::CCRect &rect);
void setClipSize(float width,float height);
virtual void draw();
protected:
bool m_bClipAble;
float m_fScissorX;
float m_fScissorY;
float m_fScissorWidth;
float m_fScissorHeight;
bool m_bEnableCustomArea;
bool m_bColorEnable;
};
}

#endif /* defined(__Test__CClipAbleLayerGradient__) */
1 change: 1 addition & 0 deletions CocoGUILIB/CocoGUILIB/Component/CocoControlButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace cs {
this->m_pCCRenderNode->addChild(this->m_pNormalTitle);
this->m_pCCRenderNode->addChild(this->m_pPressedTitle);
this->m_pCCRenderNode->addChild(this->m_pDisabledTitle);
this->setPressState(0);
return true;
}
return false;
Expand Down
Loading

0 comments on commit 4478c02

Please sign in to comment.