Пример #1
0
void ListView::updateInnerContainerSize()
{
    switch (_direction)
    {
        case SCROLLVIEW_DIR_VERTICAL:
        {
            size_t length = _items.size();
            float totalHeight = (length - 1) * _itemsMargin;
            for (auto& item : _items)
            {
                totalHeight += item->getSize().height;
            }
            float finalWidth = _size.width;
            float finalHeight = totalHeight;
            setInnerContainerSize(Size(finalWidth, finalHeight));
            break;
        }
        case SCROLLVIEW_DIR_HORIZONTAL:
        {
            size_t length = _items.size();
            float totalWidth = (length - 1) * _itemsMargin;
            for (auto& item : _items)
            {
                totalWidth += item->getSize().width;
            }
            float finalWidth = totalWidth;
            float finalHeight = _size.height;
            setInnerContainerSize(Size(finalWidth, finalHeight));
            break;
        }
        default:
            break;
    }
}
Пример #2
0
void UIListView::updateInnerContainerSize()
{
    if (!_model)
    {
        return;
    }
    switch (_direction) {
        case SCROLLVIEW_DIR_VERTICAL:
        {
            int childrenCount = _items->count();
            float totalHeight = _model->getSize().height * childrenCount + (childrenCount - 1) * _itemsMargin;
            float finalWidth = _size.width;
            float finalHeight = totalHeight;
            setInnerContainerSize(cocos2d::Size(finalWidth, finalHeight));
            break;
        }
        case SCROLLVIEW_DIR_HORIZONTAL:
        {
            int childrenCount = _items->count();
            float totalWidth = _model->getSize().width * childrenCount + (childrenCount - 1) * _itemsMargin;
            float finalWidth = totalWidth;
            float finalHeight = _size.height;
            setInnerContainerSize(cocos2d::Size(finalWidth, finalHeight));
            break;
        }
        default:
            break;
    }
}
Пример #3
0
void UIListViewEx::updateInnerContainerSize()
{
    if (!m_pModel)
    {
        return;
    }
    switch (m_eDirection) {
        case SCROLLVIEW_DIR_VERTICAL:
        {
            int childrenCount = m_pItems->count();
            float totalHeight = m_pModel->getSize().height * childrenCount + (childrenCount - 1) * m_fItemsMargin;
            float finalWidth = m_size.width;
            float finalHeight = totalHeight;
            setInnerContainerSize(CCSizeMake(finalWidth, finalHeight));
            break;
        }
        case SCROLLVIEW_DIR_HORIZONTAL:
        {
            int childrenCount = m_pItems->count();
            float totalWidth = m_pModel->getSize().width * childrenCount + (childrenCount - 1) * m_fItemsMargin;
            float finalWidth = totalWidth;
            float finalHeight = m_size.height;
            setInnerContainerSize(CCSizeMake(finalWidth, finalHeight));
            break;
        }
        default:
            break;
    }
}
Пример #4
0
void UIListViewEx::updateInnerContainerSize()
{
    //if (!m_pModel)
    //{
    //    return;
    //}
	switch (m_eDirection) {
	case SCROLLVIEW_DIR_VERTICAL:
		{
			ccArray* arrayItems = m_pItems->data;
			int length = arrayItems->num;
			float totalHeight = (length - 1) * m_fItemsMargin;
			for (int i=0; i<length; i++)
			{
				UIWidget* item = (UIWidget*)arrayItems->arr[i];
				totalHeight += item->getSize().height;
			}
			float finalWidth = m_size.width;
			float finalHeight = totalHeight;
			setInnerContainerSize(CCSizeMake(finalWidth, finalHeight));
			break;
		}
	case SCROLLVIEW_DIR_HORIZONTAL:
		{
			ccArray* arrayItems = m_pItems->data;
			int length = arrayItems->num;
			float totalWidth = (length - 1) * m_fItemsMargin;
			for (int i=0; i<length; i++)
			{
				UIWidget* item = (UIWidget*)arrayItems->arr[i];
				totalWidth += item->getSize().width;
			}

			float finalWidth = totalWidth;
			float finalHeight = m_size.height;
			setInnerContainerSize(CCSizeMake(finalWidth, finalHeight));
			break;
		}
	default:
		break;
	}
}
Пример #5
0
void ScrollView::copySpecialProperties(Widget *widget)
{
    ScrollView* scrollView = dynamic_cast<ScrollView*>(widget);
    if (scrollView)
    {
        Layout::copySpecialProperties(widget);
        setDirection(scrollView->_direction);
        setInnerContainerPosition(scrollView->getInnerContainerPosition());
        setInnerContainerSize(scrollView->getInnerContainerSize());
        _topBoundary = scrollView->_topBoundary;
        _bottomBoundary = scrollView->_bottomBoundary;
        _leftBoundary = scrollView->_leftBoundary;
        _rightBoundary = scrollView->_rightBoundary;
        _bePressed = scrollView->_bePressed;
        _childFocusCancelOffsetInInch = scrollView->_childFocusCancelOffsetInInch;
        setInertiaScrollEnabled(scrollView->_inertiaScrollEnabled);
        _inertiaScrolling = scrollView->_inertiaScrolling;
        _inertiaInitiVelocity = scrollView->_inertiaInitiVelocity;
        _inertiaTouchDisplacements = scrollView->_inertiaTouchDisplacements;
        _inertiaTouchTimeDeltas = scrollView->_inertiaTouchTimeDeltas;
        _inertiaPrevTouchTimestamp = scrollView->_inertiaPrevTouchTimestamp;
        _inertiaScrollExpectedTime = scrollView->_inertiaScrollExpectedTime;
        _inertiaScrollElapsedTime = scrollView->_inertiaScrollElapsedTime;
        _autoScrolling = scrollView->_autoScrolling;
        _autoScrollAttenuate = scrollView->_autoScrollAttenuate;
        _autoScrollStartPosition = scrollView->_autoScrollStartPosition;
        _autoScrollTargetDelta = scrollView->_autoScrollTargetDelta;
        _autoScrollDuration = scrollView->_autoScrollDuration;
        _autoScrollAccumulatedTime = scrollView->_autoScrollAccumulatedTime;
        setBounceEnabled(scrollView->_bounceEnabled);
        _bouncingBack = scrollView->_bouncingBack;
        _scrollViewEventListener = scrollView->_scrollViewEventListener;
        _scrollViewEventSelector = scrollView->_scrollViewEventSelector;
        _eventCallback = scrollView->_eventCallback;
        _ccEventCallback = scrollView->_ccEventCallback;
        
        setScrollBarEnabled(scrollView->isScrollBarEnabled());
        if(isScrollBarEnabled())
        {
            if(_direction != Direction::HORIZONTAL)
            {
                setScrollBarPositionFromCornerForVertical(scrollView->getScrollBarPositionFromCornerForVertical());
            }
            if(_direction != Direction::VERTICAL)
            {
                setScrollBarPositionFromCornerForHorizontal(scrollView->getScrollBarPositionFromCornerForHorizontal());
            }
            setScrollBarWidth(scrollView->getScrollBarWidth());
            setScrollBarColor(scrollView->getScrollBarColor());
            setScrollBarAutoHideEnabled(scrollView->isScrollBarAutoHideEnabled());
            setScrollBarAutoHideTime(scrollView->getScrollBarAutoHideTime());
        }
    }
}
Пример #6
0
void ListView::updateInnerContainerSize()
{
    switch (_direction)
    {
        case SCROLLVIEW_DIR_VERTICAL:
        {
            ccArray* arrayItems = _items->data;
            int length = arrayItems->num;
            float totalHeight = (length - 1) * _itemsMargin;
            for (int i=0; i<length; i++)
            {
                Widget* item = static_cast<Widget*>(arrayItems->arr[i]);
                float sca  = item->getScale();
                totalHeight += item->getSize().height*sca;
            }
            float finalWidth = _size.width;
            float finalHeight = totalHeight;
            setInnerContainerSize(CCSize(finalWidth, finalHeight));
            break;
        }
        case SCROLLVIEW_DIR_HORIZONTAL:
        {
            ccArray* arrayItems = _items->data;
            int length = arrayItems->num;
            float totalWidth = (length - 1) * _itemsMargin;
            for (int i=0; i<length; i++)
            {
                Widget* item = static_cast<Widget*>(arrayItems->arr[i]);
                totalWidth += item->getSize().width;
            }
            float finalWidth = totalWidth;
            float finalHeight = _size.height;
            setInnerContainerSize(CCSize(finalWidth, finalHeight));
            break;
        }
        default:
            break;
    }
}
Пример #7
0
void UI:: initSrollView(){
    auto sc=ScrollView::create();
    //表面的大小
    sc->setContentSize(cocos2d::Size(960,640));
    //内部大小
    sc->setInnerContainerSize(cocos2d::Size(960*5,640));
    sc->setDirection(cocos2d::ui::ScrollView::Direction::HORIZONTAL);
    //默认回弹是关闭的
    sc->setBounceEnabled(true);
    //默认惯性滑动是开启的
    sc->setInertiaScrollEnabled(true);
   // sc->addEventListener(CC_CALLBACK_2(UI::ScrollView, this));
    for (int i=0; i<5; i++) {
        auto sp=Sprite::create("HelloWorld.png");
        sp->setPosition(Vec2(480+960*i,320));
        sc->addChild(sp);
    }
    sc->setPosition(Vec2(0,0));
    this-> addChild(sc);
}
Пример #8
0
cocos2d::ui::ScrollView* GameLayer::create_center_scrollview()
{
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    auto scroll = ui::ScrollView::create();
    //scroll->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
    int scroll_w = sx(600);
    int scroll_h = sy(400);
    Size scroll_size = Size(scroll_w, scroll_h);
    scroll->setSize(scroll_size);
    scroll->setAnchorPoint(Vec2(0.5, 0.5));
    scroll->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
    scroll->setDirection(ui::ScrollView::Direction::VERTICAL);
    this->addChild(scroll);
    //scroll->setBackGroundColor(Color3B::GREEN);

    auto container_size = Size(scroll_w, scroll_h*3);
    scroll->setInnerContainerSize(container_size);
    scroll->setLayoutType(ui::Layout::Type::VERTICAL);

    return scroll;
}
Пример #9
0
void Sensors::showSensorList() {
    // get http response
    auto http_response_data =
        lib::network::DataStoreSingleton::getInstance()->getResponseData(
            lib::network::DataStoreSingleton::Request_Pointcast_Home_e);

    const char* json = http_response_data.c_str();

    // JSON解析
    rapidjson::Document document;
    document.Parse<0>(json);
    if (document.HasParseError()) {
        // 解析エラー
        assert(false);
        return;
    }

    // read list view
    auto p_panel =
        this->_p_contents->getChildByName<ui::Layout*>("panelBackground");

    auto p_list_view = p_panel->getChildByName<ui::ListView*>("listSensors");
    p_list_view->setInnerContainerSize(p_list_view->getContentSize());
    p_list_view->setBounceEnabled(true);
    p_list_view->setTouchEnabled(true);

    p_list_view->addEventListener(
        [this](Ref* ref, ui::ListView::EventType eventType) {
            if (eventType == ui::ListView::EventType::ON_SELECTED_ITEM_END) {
                auto listView = static_cast<ui::ListView*>(ref);
                auto selectedIndex = listView->getCurSelectedIndex();

                // revert color all record
                for (auto widget : listView->getItems()) {
                    auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record);
                    p_record->getChildByName<ui::Layout*>("panelRecord")
                        ->setColor(Color3B::WHITE);
                }
                // change color selected record
                auto widget = listView->getItem(selectedIndex);
                auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record);
                p_record->getChildByName<ui::Layout*>("panelRecord")
                    ->setColor(Color3B(250, 219, 218));
                CCLOG("selected index %ld", selectedIndex);

                this->showAnalyticsDialog(widget->getTag());
            } else {
                CCLOG("touch list event type %d", eventType);
            }
        });

    std::map<int, lib::object::LocationItem> m_sensors =
        lib::network::DataStoreSingleton::getInstance()->getLocationItemAll();

    for (auto item : m_sensors) {
        auto p_record =
            CSLoader::getInstance()->createNode("res/sensors_record.csb");

        this->setMesurementData(p_record, item.second);

        auto widget = ui::Widget::create();
        p_record->setTag(Tag_Id_Sensor_Record);
        widget->addChild(p_record);
        widget->setTag(item.second.m_sensor_main_id);

        widget->setContentSize(p_record->getContentSize());
        p_list_view->pushBackCustomItem(widget);

        widget->setTouchEnabled(true);  // enable listview touch event
    }
}
Пример #10
0
bool Sensors::init() {
  if (!Node::init()) {
    return false;
  }

  // set task id
  this->task_id = Task_Id_World;

  // set sort type
  this->sort_id = Sort_Id_Near_Point;

  // load sensors layout
  this->_p_contents = CSLoader::getInstance()->createNode(
      "res/MenuSensorList.csb"); // .csbを読み込んだディレクトリを保持してリソースを探す指定

  // back button
  auto p_panel =
      this->_p_contents->getChildByName<ui::Layout *>("panelBackground");

  auto p_list_view = p_panel->getChildByName<ui::ListView *>("listSensors");
  p_list_view->setInnerContainerSize(p_list_view->getContentSize());
  p_list_view->setBounceEnabled(true);
  p_list_view->setTouchEnabled(true);
  p_list_view->setScrollBarEnabled(false);
  p_list_view->addEventListener(
      [this](Ref *ref, ui::ListView::EventType eventType) {
        if (eventType == ui::ListView::EventType::ON_SELECTED_ITEM_END) {
          auto listView = static_cast<ui::ListView *>(ref);
          auto selectedIndex = listView->getCurSelectedIndex();

          // revert color all record
          for (auto widget : listView->getItems()) {
            auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record);
            p_record->getChildByName<ui::Layout *>("panelRecord")
                ->setColor(Color3B::WHITE);
          }
          // change color selected record
          lib::network::DataStoreSingleton *p_datastore_singleton =
              lib::network::DataStoreSingleton::getInstance();
          auto widget = listView->getItem(selectedIndex);
          auto location_item =
              p_datastore_singleton->getLocationItem(widget->getTag());

          if (location_item.sensor_status != 1) {
            // if status inactive
            return;
          }

          auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record);
          p_record->getChildByName<ui::Layout *>("panelRecord")
              ->setColor(Color3B(250, 219, 218));
          CCLOG("selected index %ld", selectedIndex);

          this->showAnalyticsDialog(widget->getTag());
        } else {
          CCLOG("touch list event type %d", eventType);
        }
      });

  //  auto label_back = p_panel->getChildByName<ui::Text *>("txtBack");
  //  label_back->addTouchEventListener(
  //      [this](Ref *sender, ui::Widget::TouchEventType type) {
  //        if (type == ui::Widget::TouchEventType::ENDED) {
  //          this->touchBack();
  //        }
  //      });

  // search
  auto button_search = p_panel->getChildByName<ui::ImageView *>("imgSearch");
  button_search->addTouchEventListener(
      [this](Ref *sender, ui::Widget::TouchEventType type) {
        auto p_sender = static_cast<cocos2d::Node *>(sender);
        if (type == ui::Widget::TouchEventType::BEGAN) {
          this->attachTouchParticle(p_sender->getPosition());
        } else if (type == ui::Widget::TouchEventType::MOVED) {

        } else if (type == ui::Widget::TouchEventType::ENDED) {
          this->touchSearch(sender);
        } else {
          this->detachTouchParticle();
        }
      });

  // sort
  auto button_sort = p_panel->getChildByName<ui::ImageView *>("imgSort");
  button_sort->addTouchEventListener(
      [this](Ref *sender, ui::Widget::TouchEventType type) {
        auto p_sender = static_cast<cocos2d::Node *>(sender);
        if (type == ui::Widget::TouchEventType::BEGAN) {
          this->attachTouchParticle(p_sender->getPosition());
        } else if (type == ui::Widget::TouchEventType::MOVED) {

        } else if (type == ui::Widget::TouchEventType::ENDED) {
          this->touchSort(sender);
        } else {
          this->detachTouchParticle();
        }
      });

  // panel world
  auto panel_world = p_panel->getChildByName<ui::Button *>("panelWorld");
  panel_world->addTouchEventListener(
      [this](Ref *sender, ui::Widget::TouchEventType type) {
        if (type == ui::Widget::TouchEventType::ENDED) {
          this->touchPanelWorld();
        }
      });

  // panel favorite
  auto panel_favorite = p_panel->getChildByName<ui::Button *>("panelFavorite");
  panel_favorite->addTouchEventListener(
      [this](Ref *sender, ui::Widget::TouchEventType type) {
        if (type == ui::Widget::TouchEventType::ENDED) {
          this->touchPanelFavorite();
        }
      });

  // last updated at
  auto label_last_updated_at =
      p_panel->getChildByName<ui::Text *>("txtLastUpdatedAt");
  label_last_updated_at->setString(
      lib::network::DataStoreSingleton::getInstance()
          ->getLastUpdatedAtToFormatString());

  this->_p_contents->setTag(Tag_Id_Sensor);
  this->addChild(this->_p_contents);

  // initialize sort type
  this->updateSortType();

  // this->nextScene(Task_Id_World);

  return true;
}
Пример #11
0
void CScrollList::LayOut()
{
	int nItemHeight = (m_vtrButtons.size() ? m_vtrButtons.back()->getSize().height : 0);
	int nTitleHeight = (m_vtrGroupInfo.size() ? m_vtrGroupInfo.back().pGroupTitle->getSize().height : 0);

	float minHeight = 0;
	for (size_t i = 0; i < m_vtrGroupInfo.size(); i++)
	{
		if (m_vtrGroupInfo[i].bSpread && m_vtrGroupInfo[i].nItemNum)
			minHeight += (m_vtrGroupInfo[i].nItemNum * nItemHeight + (m_vtrGroupInfo[i].nItemNum - 1) * m_nRowInterval);
		minHeight += (nTitleHeight + m_nRowInterval);
	}
	if (minHeight == 0)
	{
		minHeight = m_vtrButtons.size() * nItemHeight + (nItemHeight ? (m_vtrButtons.size() - 1) * m_nRowInterval : 0);
	}

	float fRealHeight = MAX(minHeight, getContentSize().height);
	int nCurPlaceY = fRealHeight;

	// 计算全体成员的位置
	vector<GroupInfo> vtrGroupTemp = m_vtrGroupInfo;
	int nGroupIndex = -1;
	for (ssize_t i = 0; i < m_vtrButtons.size(); i++)
	{
		bool bSpreadItem = true;
		for (size_t j = 0; j < vtrGroupTemp.size(); j++)
		{
			if (vtrGroupTemp[j].pStartItem == m_vtrButtons.at(i))
			{
				// 排版没有列表项目的组标题栏
				for (size_t k = 1; k <= j - nGroupIndex; k++)
				{
					vtrGroupTemp[nGroupIndex + k].pGroupTitle->setPosition(Point(_size.width / 2, nCurPlaceY));
					nCurPlaceY -= (vtrGroupTemp[nGroupIndex + k].pGroupTitle->getSize().height + m_nRowInterval);
				}
				nGroupIndex = j;

				if (!vtrGroupTemp[j].bSpread)
				{
					// 隐藏折叠的项
					for (ssize_t k = 0; k < vtrGroupTemp[j].nItemNum; k++)
					{
						m_vtrButtons.at(i + k)->removeFromParentAndCleanup(false);
					}

					i += (vtrGroupTemp[j].nItemNum - 1);
					bSpreadItem = false;
				}
				else if (vtrGroupTemp[j].nItemNum && vtrGroupTemp[j].pStartItem->getParent() == NULL)
				{
					// 显示之前折叠的项
					for (ssize_t k = 0; k < vtrGroupTemp[j].nItemNum; k++)
					{
						addChild(m_vtrButtons.at(i + k));
					}
				}

				break;
				//vtrGroupTemp.erase(vtrGroupTemp.begin() + j);
			}
		}

		if (bSpreadItem)
		{
			m_vtrButtons.at(i)->setPosition(Point(0, nCurPlaceY));
			nCurPlaceY -= (nItemHeight + m_nRowInterval);
		}
	}

	// 排版剩下的没有列表项目的组标题栏
	for (size_t k = nGroupIndex + 1; k < vtrGroupTemp.size(); k++)
	{
		vtrGroupTemp[k].pGroupTitle->setPosition(Point(_size.width / 2, nCurPlaceY));
		nCurPlaceY -= (vtrGroupTemp[k].pGroupTitle->getSize().height + m_nRowInterval);
	}

	setInnerContainerSize(Size(getContentSize().width, fRealHeight));
}
Пример #12
0
void CScrollMenu::updateInnerSize()
{
	m_sRadioSize = Size((m_pRadioMenu->GetButtonSize().width+m_fInterval)*m_pRadioMenu->GetButtonNum()+m_fInterval,m_sRadioSize.height);
	m_pRadioMenu->setContentSize(m_sRadioSize);
	setInnerContainerSize(m_sRadioSize);
}