当前位置: 首页>>代码示例>>C++>>正文


C++ ImageView::addTouchEventListener方法代码示例

本文整理汇总了C++中ImageView::addTouchEventListener方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageView::addTouchEventListener方法的具体用法?C++ ImageView::addTouchEventListener怎么用?C++ ImageView::addTouchEventListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageView的用法示例。


在下文中一共展示了ImageView::addTouchEventListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

bool UIGrabInfoLayer::init()
{
    if (!UIBaseTopLayer::init())
    {
        return false;
    }
    
    mLayout = CocosHelper::singleton()->getScaleLayout("CCS_grabInfo.csb", this);
    
    CocosHelper::getWidgetByName(mLayout, "Button_tijiao")->addTouchEventListener
    ([](Ref *sender, Widget::TouchEventType type)
     {
         if ( type == Widget::TouchEventType::ENDED)
         {
             UIMainLayer::gUIMainLayer->popLayer();
         }
     });
    
    mSelects.assign(7, false);
    
    Text_select = static_cast<Text*>(CocosHelper::getNodeByName(mLayout, "Text_select"));
    
    for (int i = 0; i < 7; ++i)
    {
        ImageView *view = static_cast<ImageView*>(CocosHelper::getNodeByName(mLayout, __String::createWithFormat("Image_model%d", i)->getCString()));
        view->setTag(i);
        view->addTouchEventListener(CC_CALLBACK_2(UIGrabInfoLayer::onImageTouch, this));
        mImages.push_back(view);
    }
    
    setSelectInfo();
    
    return true;
}
开发者ID:huangtao,项目名称:SzMjMobile,代码行数:34,代码来源:UIGrabInfoLayer.cpp

示例2: SetSingleCellInfo

bool UI_Bag_Gem_Layer::SetSingleCellInfo(const int nTagID, Game_Data::Item_Container * pInfo)
{
	/************************************************************************/
	// 设置单个Cell的信息
	// 1. 判断索引ID是否异常
	if (nTagID >= MAX_TAG_COUNT)
		return false;

	// 2. 获取该物品的Config
	Game_Data::Item_Config * pItemConfig = ITEM_CONFIG_MGR::instance()->get_item_config(pInfo->item_id);
	if (pItemConfig == NULL)
		return false;

	// 3. 读取Json文件获取包裹每一个单元格
	Widget *pLayer = dynamic_cast<Widget*>(m_pBagGemScrollView->getChildByTag(nTagID));
	if (pLayer == NULL)
		return false;

	/************************************************************************/
	// 条件满足设置物品信息
	int nTemp = 0;
	const char * szTemp;
	// 1. 设置Icon
	ImageView * pMaterialImage = dynamic_cast<ui::ImageView*>(Helper::seekWidgetByName(pLayer, "Icon_ImagerView"));
	if (pMaterialImage == NULL)
		return false;

	szTemp	= ITEM_CONFIG_MGR::instance()->get_icon_path(pItemConfig->icon);
    std::string p("icon/");
    p+=szTemp;
	nTemp	= strcmp(p.c_str(), "");
	if (nTemp <= 0)
		return false;

	pMaterialImage->loadTexture(p.c_str());
	pMaterialImage->setVisible(true);
	
	// 2. 设置物品的个数
	TextAtlas * pMateriCount = dynamic_cast<ui::TextAtlas*>(Helper::seekWidgetByName(pLayer, "Count_Text"));
	if (pMaterialImage == NULL)
		return false;

	pMateriCount->setString(CCString::createWithFormat("%d", pInfo->item_count)->getCString());
	pMateriCount->setVisible(true);

	// 3. 为每件物品注册点击事件
	pMaterialImage->setTag(nTagID);
	pMaterialImage->addTouchEventListener(CC_CALLBACK_2(UI_Bag_Gem_Layer::OnBtnClickMaterialCallBack, this));
	return true;
}
开发者ID:ff78,项目名称:son,代码行数:50,代码来源:UI_Bag_Gem_Layer.cpp

示例3: init

bool UIFocusTestVertical::init()
{
    if (UIFocusTestBase::init()) {
        
        Size winSize = Director::getInstance()->getVisibleSize();
        
        _verticalLayout = VBox::create();
        _verticalLayout->setPosition(Vec2(winSize.width/2 - 100, winSize.height - 70));
        _uiLayer->addChild(_verticalLayout);
        _verticalLayout->setTag(100);
        _verticalLayout->setScale(0.5);
        
        _verticalLayout->setFocused(true);
        _verticalLayout->setLoopFocus(true);
        _firstFocusedWidget = _verticalLayout;
        
        int count = 3;
        for (int i=0; i<count; ++i) {
            ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
            w->setTouchEnabled(true);
            w->setTag(i);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestVertical::onImageViewClicked, this));
            _verticalLayout->addChild(w);
            if (i == 2) {
                w->requestFocus();
            }
        }
        
        _loopText = Text::create("loop enabled", "Airal", 20);
        _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
        _loopText->setColor(Color3B::GREEN);
        this->addChild(_loopText);
        
        auto btn = Button::create("cocosui/switch-mask.png");
        btn->setTitleText("Toggle Loop");
        btn->setPosition(Vec2(60, winSize.height - 50));
        btn->setTitleColor(Color3B::RED);
        btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestVertical::toggleFocusLoop, this));
        this->addChild(btn);
        
        
        return true;
    }
    return false;
}
开发者ID:jiaozicat,项目名称:cocos2d-x,代码行数:45,代码来源:UIFocusTest.cpp

示例4:

bool UIImageViewTest_Scale9_State_Change::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();

        Text* alert = Text::create("Click The Image", "fonts/Marker Felt.ttf", 26);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f,
            widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f));

        _uiLayer->addChild(alert);

        // Create the imageview
        ImageView* imageView = ImageView::create("cocosui/ccicon.png");
        imageView->ignoreContentAdaptWithSize(false);
        imageView->setScale9Enabled(true);
        imageView->setContentSize(Size(100, 100));
        imageView->setCapInsets(Rect(20,20,20,20));
        imageView->setPosition(Vec2(widgetSize.width / 2.0f,
            widgetSize.height / 2.0f));

        imageView->setTouchEnabled(true);
        imageView->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
            if (type == Widget::TouchEventType::ENDED) {
                if (imageView->isScale9Enabled())
                {
                    imageView->setScale9Enabled(false);
                }
                else
                    imageView->setScale9Enabled(true);
            }
        });

        _uiLayer->addChild(imageView);

        return true;
    }
    return false;
}
开发者ID:AomXD,项目名称:workspace,代码行数:40,代码来源:UIImageViewTest.cpp

示例5:

bool UIFocusTestNestedLayout3::init()
{
    if (UIFocusTestBase::init()) {

        Size winSize = Director::getInstance()->getVisibleSize();

        _verticalLayout = VBox::create();
        _verticalLayout->setPosition(Vec2(40, winSize.height - 70));
        _uiLayer->addChild(_verticalLayout);
        _verticalLayout->setScale(0.8f);

        _verticalLayout->setFocused(true);
        _verticalLayout->setLoopFocus(true);
        _verticalLayout->setTag(-1000);
        _firstFocusedWidget = _verticalLayout;


        HBox *upperHBox = HBox::create();
        upperHBox->setTag(-200);
        _verticalLayout->addChild(upperHBox);

        LinearLayoutParameter *params = LinearLayoutParameter::create();
        params->setMargin(Margin(0,0,50,0));

        LinearLayoutParameter *vparams = LinearLayoutParameter::create();
        vparams->setMargin(Margin(10, 0, 0, 140));
        upperHBox->setLayoutParameter(vparams);

        int count = 3;
        for (int i=0; i<count; ++i) {
            VBox *firstVbox = VBox::create();
            firstVbox->setScale(0.5);
            firstVbox->setLayoutParameter(params);
            firstVbox->setTag((i+1) * 100);

            int count1 = 3;
            for (int j=0; j<count1; ++j) {
                ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
                w->setTouchEnabled(true);
                w->setTag(j+firstVbox->getTag()+1);
                w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this));
                firstVbox->addChild(w);
            }

            upperHBox->addChild(firstVbox);

        }

        HBox *bottomHBox = HBox::create();
        bottomHBox->setScale(0.5);
        bottomHBox->setTag(600);

        bottomHBox->setLayoutParameter(vparams);
        count = 3;
        LinearLayoutParameter *bottomParams = LinearLayoutParameter::create();
        bottomParams->setMargin(Margin(0, 0, 8, 0));
        for (int i=0; i < count; ++i) {
            ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
            w->setLayoutParameter(bottomParams);
            w->setTouchEnabled(true);
            w->setTag(i+601);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this));
            bottomHBox->addChild(w);
        }
        _verticalLayout->addChild(bottomHBox);



        _loopText = Text::create("loop enabled", "Arial", 20);
        _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
        _loopText->setColor(Color3B::GREEN);
        this->addChild(_loopText);

        auto btn = Button::create("cocosui/switch-mask.png");
        btn->setTitleText("Toggle Loop");
        btn->setPosition(Vec2(60, winSize.height - 50));
        btn->setTitleColor(Color3B::RED);
        btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout3::toggleFocusLoop, this));
        this->addChild(btn);


        return true;
    }
    return false;
}
开发者ID:anilgulgor,项目名称:myGame,代码行数:85,代码来源:UIFocusTest.cpp

示例6: init

bool UIImageViewTest_ContentSize::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        Text* alert = Text::create("ImageView ContentSize Change", "fonts/Marker Felt.ttf", 26);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f,
                                widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f));
        
        _uiLayer->addChild(alert);
        
        Text *status = Text::create("child ImageView position percent", "fonts/Marker Felt.ttf", 16);
        status->setColor(Color3B::RED);
        status->setPosition(Vec2(widgetSize.width/2, widgetSize.height/2 + 80));
        _uiLayer->addChild(status,20);
        
        // Create the imageview
        ImageView* imageView = ImageView::create("cocosui/buttonHighlighted.png");
        imageView->setScale9Enabled(true);
        imageView->setContentSize(Size(200, 80));
        imageView->setPosition(Vec2(widgetSize.width / 2.0f,
                                    widgetSize.height / 2.0f ));
       
        
        ImageView* imageViewChild = ImageView::create("cocosui/buttonHighlighted.png");
        imageViewChild->setScale9Enabled(true);
        imageViewChild->setSizeType(Widget::SizeType::PERCENT);
        imageViewChild->setPositionType(Widget::PositionType::PERCENT);
        imageViewChild->setSizePercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild->setPositionPercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild->setPosition(Vec2(widgetSize.width / 2.0f,
                                    widgetSize.height / 2.0f));
        
        ImageView* imageViewChild2 = ImageView::create("cocosui/buttonHighlighted.png");
        imageViewChild2->setScale9Enabled(true);
        imageViewChild2->setSizeType(Widget::SizeType::PERCENT);
        imageViewChild2->setPositionType(Widget::PositionType::PERCENT);
        imageViewChild2->setSizePercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild2->setPositionPercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild->addChild(imageViewChild2);
        
        
        imageView->addChild(imageViewChild);
        
        imageView->setTouchEnabled(true);
        imageView->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
            if (type == Widget::TouchEventType::ENDED) {
                float width = CCRANDOM_0_1() * 200 + 50;
                float height = CCRANDOM_0_1() * 80 + 30;
                imageView->setContentSize(Size(width, height));
                
                imageViewChild->setPositionPercent(Vec2(CCRANDOM_0_1(), CCRANDOM_0_1()));
                status->setString(StringUtils::format("child ImageView position percent: %f, %f",
                                                      imageViewChild->getPositionPercent().x, imageViewChild->getPositionPercent().y));
            }
        });
        
        _uiLayer->addChild(imageView);
        
        return true;
    }
    return false;
}
开发者ID:AomXD,项目名称:workspace,代码行数:65,代码来源:UIImageViewTest.cpp


注:本文中的ImageView::addTouchEventListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。