Пример #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();
 }
Пример #2
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;
 }