Exemplo n.º 1
0
 void CocoWidget::reorderChild(CocoWidget* child)
 {
     this->m_children->removeObject(child);
     int childrenCount = this->m_children->count();
     if (childrenCount <= 0) {
         this->m_children->addObject(child);
     }else{
         bool seekSucceed = false;
         for (int i=childrenCount-1; i>=0; --i) {
             CocoWidget* widget = (CocoWidget*)(this->m_children->objectAtIndex(i));
             if (child->getWidgetZOrder() >= widget->getWidgetZOrder()) {
                 if (i == childrenCount-1) {
                     this->m_children->addObject(child);
                     seekSucceed = true;
                     break;
                 }else{
                     this->m_children->insertObject(child, i+1);
                     seekSucceed = true;
                     break;
                 }
             }
         }
         if (!seekSucceed) {
             this->m_children->insertObject(child,0);
         }
     }
     COCOUISYSTEM->getUIInputManager()->uiSceneHasChanged();
 }
Exemplo n.º 2
0
 void CocoWidget::updateChildrenVisibleDirty(bool dirty)
 {
     for (int i=0; i<this->getChildren()->count(); i++) {
         CocoWidget* child = (CocoWidget*)(this->getChildren()->objectAtIndex(i));
         child->m_bVisibleDirty = dirty;
         child->updateChildrenVisibleDirty(dirty);
     }
 }
Exemplo n.º 3
0
 CocoWidget* CocoWidget::getChildByTag(int tag)
 {
     for (int i=0; i<this->m_children->count(); i++) {
         CocoWidget* child = (CocoWidget*)(this->m_children->objectAtIndex(i));
         if (child->getWidgetTag() == tag) {
             return child;
         }
     }
     return NULL;
 }
Exemplo n.º 4
0
    CocoWidget* CocoWidget::create()
    {
//        return CocoWidget::create(NULL);
        CocoWidget* widget = new CocoWidget();
        if (widget && widget->init()) {
            return widget;
        }
        CC_SAFE_DELETE(widget);
        return NULL;
    }
Exemplo n.º 5
0
 CocoWidget* CocoWidget::getChildByName(const char *name)
 {
     for (int i=0; i<this->m_children->count(); i++) {
         CocoWidget* child = (CocoWidget*)(this->m_children->objectAtIndex(i));
         if (strcmp(child->getName().c_str(), name) == 0) {
             return child;
         }
     }
     return NULL;
 }
Exemplo n.º 6
0
 CocoWidget* CCSReader::widgetFromCCDictionary(cocos2d::CCDictionary* data)
 {
     CocoWidget* widget = NULL;
     
     const char* classname = DICTOOL->getStringValue(data, "classname");
     cocos2d::CCDictionary* uiOptions = DICTOOL->getSubDictionary(data, "options");
     if (classname && strcmp(classname, "Button") == 0) {
         widget = CocoButton::create();
         this->setPropsForButtonFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "CheckBox") == 0){
         widget = CocoCheckBox::create();
         this->setPropsForCheckBoxFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "Label") == 0){
         widget = CocoLabel::create();
         this->setPropsForLabelFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "LabelAtlas") == 0){
         widget = CocoLabelAtlas::create();
         this->setPropsForLabelAtlasFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "LoadingBar") == 0){
         widget = CocoLoadingBar::create();
         this->setPropsForLoadingBarFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "ScrollView") == 0){
         widget = CocoScrollView::create();
         this->setPropsForScrollViewFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "TextArea") == 0){
         widget = CocoTextArea::create();
         this->setPropsForTextAreaFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "TextButton") == 0){
         widget = CocoTextButton::create();
         this->setPropsForTextButtonFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "TextField") == 0){
         widget = CocoTextField::create();
         this->setPropsForTextFieldFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "ImageView") == 0){
         widget = CocoImageView::create();
         this->setPropsForImageViewFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "Panel") == 0){
         widget = CocoPanel::create();
         this->setPropsForPanelFromCCDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "Slider") == 0){
         widget = CocoSlider::create();
         this->setPropsForSliderFromCCDictionary(widget, uiOptions);
     }
     cocos2d::CCArray* arr = DICTOOL->getArrayValue(data, "children");
     if (arr) {
         for (int i=0;i<arr->count();i++){
             cocos2d::CCDictionary* subData = (cocos2d::CCDictionary*)(arr->objectAtIndex(i));
             CocoWidget* child = this->widgetFromCCDictionary(subData);
             if (child) {
                 widget->addChild(child);
             }
         }
     }
     return widget;
 }
Exemplo n.º 7
0
 void CocoWidget::setVisibleTouch(bool visible)
 {
     this->m_bVisibleTouch = visible;
     if (this->m_children){
         for (int i=0;i<this->m_children->count();i++)
         {
             CocoWidget* child = (CocoWidget*)(this->m_children->objectAtIndex(i));
             child->setVisibleTouch(visible);
         }
     }
 }
Exemplo n.º 8
0
 void CocoWidget::setNeedCheckVisibleDepandParent(bool need)
 {
     this->m_bNeedCheckVisibleDependParent = need;
     if (this->m_children){
         for (int i=0;i<this->m_children->count();i++)
         {
             CocoWidget* child = (CocoWidget*)(this->m_children->objectAtIndex(i));
             child->setNeedCheckVisibleDepandParent(need);
         }
     }
 }
Exemplo n.º 9
0
 void CocoWidget::removeAllChildrenAndCleanUp(bool cleanup)
 {
     int times = this->m_children->count();
     for (int i=0;i<times;i++){
         CocoWidget* child = (CocoWidget*)(m_children->lastObject());
         m_children->removeObject(child);
         child->cleanFromUIInputManager();
         child->releaseResoures();
         delete child;
         child = NULL;
     }
 }
Exemplo n.º 10
0
 CocoWidget* CCSReader::widgetFromJsonDictionary(cs::CSJsonDictionary* data)
 {
     CocoWidget* widget = NULL;
     const char* classname = DICTOOL->getStringValue_json(data, "classname");
     cs::CSJsonDictionary* uiOptions = DICTOOL->getSubDictionary_json(data, "options");
     if (classname && strcmp(classname, "Button") == 0) {
         widget = CocoButton::create();
         this->setPropsForButtonFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "CheckBox") == 0){
         widget = CocoCheckBox::create();
         this->setPropsForCheckBoxFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "Label") == 0){
         widget = CocoLabel::create();
         this->setPropsForLabelFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "LabelAtlas") == 0){
         widget = CocoLabelAtlas::create();
         this->setPropsForLabelAtlasFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "LoadingBar") == 0){
         widget = CocoLoadingBar::create();
         this->setPropsForLoadingBarFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "ScrollView") == 0){
         widget = CocoScrollView::create();
         this->setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "TextArea") == 0){
         widget = CocoTextArea::create();
         this->setPropsForTextAreaFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "TextButton") == 0){
         widget = CocoTextButton::create();
         this->setPropsForTextButtonFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "TextField") == 0){
         widget = CocoTextField::create();
         this->setPropsForTextFieldFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "ImageView") == 0){
         widget = CocoImageView::create();
         this->setPropsForImageViewFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "Panel") == 0){
         widget = CocoPanel::create();
         this->setPropsForPanelFromJsonDictionary(widget, uiOptions);
     }else if (classname && strcmp(classname, "Slider") == 0){
         widget = CocoSlider::create();
         this->setPropsForSliderFromJsonDictionary(widget, uiOptions);
     }
     int childrenCount = DICTOOL->getArrayCount_json(data, "children");
     for (int i=0;i<childrenCount;i++){
         cs::CSJsonDictionary* subData = DICTOOL->getDictionaryFromArray_json(data, "children", i);
         CocoWidget* child = this->widgetFromJsonDictionary(subData);
         if (child) {
             widget->addChild(child);
         }
     }
     return widget;
 }
Exemplo n.º 11
0
 float CocoWidget::getAbsoluteScaleY()
 {
     if (this->m_bScaleYDirty) {
         float scaleY = this->getScaleY();
         CocoWidget* parent = this->getWidgetParent();
         while (parent){
             scaleY *= parent->getScaleY();
             parent = parent->getWidgetParent();
         }
         this->m_fAbsoluteScaleY = scaleY;
         this->m_bScaleYDirty = false;
     }
     return this->m_fAbsoluteScaleY;
 }
Exemplo n.º 12
0
 bool UIInputManager::onTouchPressed(float x,float y)
 {
     this->touchBeganedPoint.x = x;
     this->touchBeganedPoint.y = y;
     CocoWidget* hitWidget = this->checkEventWidget(this->touchBeganedPoint);
     if (!hitWidget || !hitWidget->getActive()){
         this->m_pCurSelectedWidget = NULL;
         return false;
     }
     this->m_pCurSelectedWidget = hitWidget;
     hitWidget->onTouchPressed(this->touchBeganedPoint);
     this->m_bTouchDown = true;
     return true;
 }
Exemplo n.º 13
0
 bool UIInputManager::onTouchCanceled(float x,float y)
 {
     this->m_bTouchDown = false;
     CocoWidget* hitWidget = this->m_pCurSelectedWidget;
     if (!hitWidget || !hitWidget->getActive()){
         return false;
     }
     this->touchEndedPoint.x = x;
     this->touchEndedPoint.y = y;
     hitWidget->onTouchReleased(this->touchEndedPoint);
     this->m_pCurSelectedWidget = NULL;
     hitWidget = NULL;
     return true;
 }
Exemplo n.º 14
0
 bool UIInputManager::onTouchCanceled(cocos2d::CCTouch* touch)
 {
     this->m_bTouchDown = false;
     CocoWidget* hitWidget = this->m_pCurSelectedWidget;
     if (!hitWidget || !hitWidget->getActive()){
         return false;
     }
     this->touchEndedPoint.x = touch->getLocation().x;
     this->touchEndedPoint.y = touch->getLocation().y;
     hitWidget->onTouchReleased(this->touchEndedPoint);
     this->m_pCurSelectedWidget = NULL;
     hitWidget = NULL;
     return true;
 }
Exemplo n.º 15
0
 bool UIInputManager::onTouchPressed(cocos2d::CCTouch* touch)
 {
     this->touchBeganedPoint.x = touch->getLocation().x;
     this->touchBeganedPoint.y = touch->getLocation().y;
     CocoWidget* hitWidget = this->checkEventWidget(this->touchBeganedPoint);
     if (!hitWidget || !hitWidget->getActive()){
         this->m_pCurSelectedWidget = NULL;
         return false;
     }
     this->m_pCurSelectedWidget = hitWidget;
     hitWidget->onTouchPressed(this->touchBeganedPoint);
     this->m_bTouchDown = true;
     return true;
 }
Exemplo n.º 16
0
    bool UIInputManager::onTouchMoved(cocos2d::CCTouch* touch)
    {
        CocoWidget* hitWidget = this->m_pCurSelectedWidget;
        if (!hitWidget || !hitWidget->getActive()){
            return false;
        }
        this->touchMovedPoint.x = touch->getLocation().x;
        this->touchMovedPoint.y = touch->getLocation().y;
        hitWidget->onTouchMoved(this->touchMovedPoint);
		if (this->m_bTouchDown){
			this->m_fLongClickRecordTime = 0;
			this->m_bTouchDown = false;
		}
        return true;
    }
Exemplo n.º 17
0
    bool UIInputManager::onTouchMoved(float x,float y)
    {
        CocoWidget* hitWidget = this->m_pCurSelectedWidget;
        if (!hitWidget || !hitWidget->getActive()){
            return false;
        }
        this->touchMovedPoint.x = x;
        this->touchMovedPoint.y = y;
        hitWidget->onTouchMoved(this->touchMovedPoint);
		if (this->m_bTouchDown){
			this->m_fLongClickRecordTime = 0;
			this->m_bTouchDown = false;
		}
        return true;
    }
Exemplo n.º 18
0
 bool CocoWidget::getAbsoluteVisible()
 {
     if (this->m_bVisibleDirty) {
         CocoWidget* parent = this;
         bool visible = this->getVisible();
         while (parent){
             visible &= parent->getVisible();
             if (!visible) {
                 break;
             }
             parent = parent->getWidgetParent();
         }
         this->m_bAbsoluteVisible = visible;
         this->m_bVisibleDirty = false;
     }
     return this->m_bAbsoluteVisible;
 }
Exemplo n.º 19
0
    void UIInputManager::update(float dt)
    {
        if (this->m_bTouchDown){
            this->m_fLongClickRecordTime += dt;
            if (this->m_fLongClickRecordTime >= this->m_fLongClickTime){
                this->m_fLongClickRecordTime = 0;
                this->m_bTouchDown = false;
                this->m_pCurSelectedWidget->onTouchLongClicked(this->touchBeganedPoint);
            }
        }
        for (int i=0;i<this->checkedDoubleClickWidget->count();i++){
            CocoWidget* widget = (CocoWidget*)(this->checkedDoubleClickWidget->objectAtIndex(i));
            if (!widget->getVisible()){
                continue;
            }
//            widget->checkDoubleClick(dt);
        }
    }
bool CocoContainerWidget::addChild(CocoWidget* child)
{
    CocoWidget::addChild(child);
    bool needSetChildCheckAble = false;
    CocoWidget* parent = this;
    while (parent != 0) {
        if (parent->getClipAble()) {
            needSetChildCheckAble = true;
            break;
        }
        parent = parent->getWidgetParent();
    }

    if (needSetChildCheckAble) {
        child->setNeedCheckVisibleDepandParent(true);
    }
    return true;
}
void CocoContainerWidget::setClipAble(bool able)
{
    this->m_bClipAble = 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);
    }
}
Exemplo n.º 22
0
CocoWidget* UIInputManager::checkEventWidget(cocos2d::CCPoint &touchPoint)
{
    if (!m_bWidgetBeSorted && m_pRootWidget)
    {
        this->sortWidgets(m_pRootWidget);
    }
    int widgetCount = this->m_manageredWidget->count();
    for (int i=0;i<widgetCount;i++)
    {
        CocoWidget* widget = (CocoWidget*)(this->m_manageredWidget->objectAtIndex(i));
        
        if(widget->pointAtSelfBody(touchPoint))
        {
            if (!widget->checkVisibleDependParent(touchPoint))
            {
                continue;
            }
            if (i != this->m_manageredWidget->count()-1){
                int j = i+1;
                for (;j < this->m_manageredWidget->count();j++)
                {
                    CocoWidget* wid = (CocoWidget*)(m_manageredWidget->objectAtIndex(j));
                    wid->didNotSelectSelf();
                }
            }
            return widget;
        }
        else
        {
            widget->didNotSelectSelf();
        }
    }
    return NULL;
}
Exemplo n.º 23
0
    CocoWidget* UIInputManager::checkEventWidget(cocos2d::CCPoint &touchPoint)
    {
        if (!this->m_bWidgetBeSorted){
            this->sortWidgets();
        }
        
//        for (int i=0;i<this->m_manageredWidget->count();i++) {
//            CocoWidget* widget = (CocoWidget*)(this->m_manageredWidget->objectAtIndex(i));
//            printf("widget name == [%s] z == [%d]\n",widget->getName().c_str(),widget->getWidgetZOrder());
//        }
        
        for (int i=0;i<this->m_manageredWidget->count();i++){
            CocoWidget* widget = (CocoWidget*)(this->m_manageredWidget->objectAtIndex(i));
            
            if(widget->pointAtSelfBody(touchPoint)){
                if (!widget->checkVisibleDependParent(touchPoint)){
                    continue;
                }
                if (i != this->m_manageredWidget->count()-1){
                    int j = i+1;
                    for (;j < this->m_manageredWidget->count();j++){
                        CocoWidget* widget = (CocoWidget*)(m_manageredWidget->objectAtIndex(j));
                        widget->didNotSelectSelf();
                    }
                }
                return widget;
            }else{
                widget->didNotSelectSelf();
            }
        }
        return NULL;
    }
Exemplo n.º 24
0
 bool CocoWidget::addChild(CocoWidget *child)
 {
     if (!child) {
         return false;
     }
     if (this->m_children->containsObject(child)) {
         return false;
     }
     child->m_pWidgetParent = this;
     int childrenCount = this->m_children->count();
     if (childrenCount <= 0) {
         this->m_children->addObject(child);
     }else{
         bool seekSucceed = false;
         for (int i=childrenCount-1; i>=0; --i) {
             CocoWidget* widget = (CocoWidget*)(this->m_children->objectAtIndex(i));
             if (child->getWidgetZOrder() >= widget->getWidgetZOrder()) {
                 if (i == childrenCount-1) {
                     this->m_children->addObject(child);
                     seekSucceed = true;
                     break;
                 }else{
                     this->m_children->insertObject(child, i+1);
                     seekSucceed = true;
                     break;
                 }
             }
         }
         if (!seekSucceed) {
             this->m_children->insertObject(child,0);
         }
     }
     this->addChildNode(child);
     this->activeToUIInputManager();
     return true;
 }