void ZoomableImageArea::setImage(QImage inImage) { image = inImage; if (zoomScale == 0) { setZoomScale(1); } else { setZoomScale(zoomScale); } }
void PreviewWidget::zoomOut() { int new_scale = m_zoomScale - ((m_zoomScale <= ZOOM_ORIGINAL_SCALE) ? ZOOM_SMALL_INCREMENT : ZOOM_BIG_INCREMENT); if (new_scale < MIN_ZOOM_SCALE) new_scale = MIN_ZOOM_SCALE; setZoomScale(new_scale); }
void PreviewWidget::zoomIn() { int new_scale = m_zoomScale + ((m_zoomScale >= ZOOM_ORIGINAL_SCALE) ? ZOOM_BIG_INCREMENT : ZOOM_SMALL_INCREMENT); if (new_scale > MAX_ZOOM_SCALE) new_scale = MAX_ZOOM_SCALE; setZoomScale(new_scale); }
Layout* UI::createLayout(int i){ auto lo=Layout::create(); lo->setBackGroundImage("HelloWorld.png"); lo->setBackGroundImageScale9Enabled(true); lo->setContentSize(Size(480,320)*1.5); for (int i=0; i<5; i++) { for (int j=0; j<7; j++) { auto ub=Button::create(); ub->loadTextureNormal("editBG.png"); ub->loadTexturePressed("editBG.png"); ub->loadTextureDisabled("editBg.png"); ub->setScale9Enabled(true); ub->setContentSize(Size(100,50)); ub->setPressedActionEnabled(true); ub->setZoomScale(0.5f); ub->setTitleFontName("fonts/Marker Felt.ttf"); ub->setTitleFontSize(30); ub->setTitleColor(Color3B::GREEN); ub->setTitleText(StringUtils::format("%d--%d",i,j)); ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this)); ub->setTag(i); ub->setPosition(Vec2(70+120*i, 35+j*60)); lo->addChild(ub); } } return lo; }
void wxOgre::cameraTrackNode(Ogre::SceneNode* target) { static const wxString camCalcPosCaption(wxT("CalcCamPos:X:%08.4f, Y:%08.4f, Z:%08.4f")); static const wxString camRealPosCaption(wxT("CalcCamPos:X:%08.4f, Y:%08.4f, Z:%08.4f")); // TODO: Position camera somwehere sensible relative to object if (target) { Ogre::LogManager* logMgr = Ogre::LogManager::getSingletonPtr(); Ogre::Log* log(logMgr->getDefaultLog()); mTarget = target; Ogre::Vector3 size( target->getAttachedObject(0)->getBoundingBox().getSize() ); Ogre::Vector3 camPos(target->getPosition() + size * 1.2f); setZoomScale(size.length() / 30.0f); mCameraNode->setPosition(camPos); mCamera->lookAt(target->getPosition()); mDebugPanelOverlay->show(); wxString msg(wxString::Format(camCalcPosCaption, camPos.x, camPos.y, camPos.x)); log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8))); Ogre::Vector3 camRealPos(mCamera->getRealPosition()); msg = wxString(wxString::Format(camCalcPosCaption, camRealPos.x, camRealPos.y, camRealPos.x)); log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8))); } else { mTarget = NULL; } }
void GraphEditor::handleZoomOut(void) { if (not this->isVisible()) return; auto draw = this->getCurrentGraphDraw(); if (draw->zoomScale() <= GraphDrawZoomMin) return; draw->setZoomScale(draw->zoomScale() - GraphDrawZoomStep); }
bool UIButtonTextOnly::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add a label in which the button events will be displayed _displayValueLabel = Text::create("Text Only Button", "fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20)); _uiLayer->addChild(_displayValueLabel); // Create the button auto button = Button::create(); button->setNormalizedPosition(Vec2(0.5f, 0.5f)); button->setTitleText("PLAY GAME"); CCLOG("content size should be greater than 0: width = %f, height = %f", button->getContentSize().width, button->getContentSize().height); button->setZoomScale(0.3f); button->setPressedActionEnabled(true); button->addClickEventListener([this](Ref* sender) { CCLOG("clicked!"); }); _uiLayer->addChild(button); return true; } return false; }
void EstimatePlace::setSecondSelect() { Vector<__String*> vInfo = setSecondSelectListInfo(); if(_vSecondButton.size() > 0) _vSecondButton.clear(); for(int i = 0 ; i < vInfo.size(); i++) { auto button = ui::Button::create("UI_TopMenuBG-hd.png"); button->setBright(true); button->setZoomScale(0.1f); button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type){ switch (type) { case ui::Widget::TouchEventType::BEGAN: break; case ui::Widget::TouchEventType::ENDED: SecondbuttonCallBack(sender); break; default: break; } }); _vSecondButton.pushBack(button); setTypeLabel(1, vInfo.at(i)->getCString()); } }
void EstimatePlace::setFirstSelect() { for(int i=0;i<3;i++) { auto button = ui::Button::create("UI_TopMenuBG-hd.png"); button->setBright(true); button->setZoomScale(0.1f); button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type){ switch (type) { case ui::Widget::TouchEventType::BEGAN: break; case ui::Widget::TouchEventType::ENDED: buttonCallBack(sender); break; default: break; } }); _vFirstButton.pushBack(button); setTypeLabel(0, i==0 ? "주거공간": i==1? "상업공간": "사무공간"); } }
bool UIButtonIgnoreContentSizeTest::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add a label in which the button events will be displayed _displayValueLabel = Text::create("Button IgnoreContent Size Test", "fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20)); _uiLayer->addChild(_displayValueLabel); // Create the button auto button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->ignoreContentAdaptWithSize(false); button->setContentSize(Size(200,100)); button->setNormalizedPosition(Vec2(0.3f, 0.5f)); button->setTitleText("PLAY GAME"); button->setZoomScale(0.3f); button->setPressedActionEnabled(true); button->addClickEventListener([=](Ref* sender) { CCLOG("clicked!"); button->setScale(1.2f); }); _uiLayer->addChild(button); // Create the button auto button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->ignoreContentAdaptWithSize(false); button2->setContentSize(Size(200,100)); button2->setNormalizedPosition(Vec2(0.8f, 0.5f)); button2->setTitleText("PLAY GAME"); button2->setZoomScale(0.3f); button2->setPressedActionEnabled(true); button2->addClickEventListener([=](Ref* sender) { button2->runAction(ScaleTo::create(1.0f, 1.2f)); CCLOG("clicked!"); }); _uiLayer->addChild(button2); return true; } return false; }
void Button::copySpecialProperties(Widget *widget) { Button* button = dynamic_cast<Button*>(widget); if (button) { _prevIgnoreSize = button->_prevIgnoreSize; setScale9Enabled(button->_scale9Enabled); // clone the inner sprite: https://github.com/cocos2d/cocos2d-x/issues/16924 button->_buttonNormalRenderer->copyTo(_buttonNormalRenderer); _normalFileName = button->_normalFileName; _normalTextureSize = button->_normalTextureSize; _normalTexType = button->_normalTexType; _normalTextureLoaded = button->_normalTextureLoaded; setupNormalTexture(!_normalFileName.empty()); button->_buttonClickedRenderer->copyTo(_buttonClickedRenderer); _clickedFileName = button->_clickedFileName; _pressedTextureSize = button->_pressedTextureSize; _pressedTexType = button->_pressedTexType; _pressedTextureLoaded = button->_pressedTextureLoaded; setupPressedTexture(!_clickedFileName.empty()); button->_buttonDisabledRenderer->copyTo(_buttonDisabledRenderer); _disabledFileName = button->_disabledFileName; _disabledTextureSize = button->_disabledTextureSize; _disabledTexType = button->_disabledTexType; _disabledTextureLoaded = button->_disabledTextureLoaded; setupDisabledTexture(!_disabledFileName.empty()); setCapInsetsNormalRenderer(button->_capInsetsNormal); setCapInsetsPressedRenderer(button->_capInsetsPressed); setCapInsetsDisabledRenderer(button->_capInsetsDisabled); if(nullptr != button->getTitleRenderer()) { setTitleText(button->getTitleText()); setTitleFontName(button->getTitleFontName()); setTitleFontSize(button->getTitleFontSize()); setTitleColor(button->getTitleColor()); } setPressedActionEnabled(button->_pressedActionEnabled); setZoomScale(button->_zoomScale); } }
OneBtDlg::OneBtDlg() { auto bg = util::graphic::getSprite(Constants::ASS_BG_DLG_TEXT); bg->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); auto bt = ui::Button::create(); bt->loadTextureNormal(util::graphic::getAssetName(Constants::ASS_BG_DLG_BT),ui::Widget::TextureResType::PLIST); bt->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); bt->setZoomScale(0); Size size = bt->getContentSize(); bg->setPosition(Vec2(0, size.height)); size.height += bg->getContentSize().height; bt->setPosition(Vec2(0, 0)); this->setContentSize(size); addChild(bg, 1); addChild(bt, 1); util::graphic::addSwallowTouch(this); util::graphic::addClosedWhenClickOutside(this); util::graphic::addClickBtCallback(bt, CC_CALLBACK_0(OneBtDlg::onBtClick, this)); }
bool UIButtonTitleEffectTest::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add a label in which the button events will be displayed _displayValueLabel = Text::create("Button Title Effect", "fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20)); _uiLayer->addChild(_displayValueLabel); // Create the button auto button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setNormalizedPosition(Vec2(0.3f, 0.5f)); button->setTitleText("PLAY GAME"); button->setTitleFontName("fonts/Marker Felt.ttf"); button->setZoomScale(0.3f); button->setScale(2.0f); button->setPressedActionEnabled(true); Label *title = button->getTitleRenderer(); button->setTitleColor(Color3B::RED); title->enableShadow(Color4B::BLACK,Size(2,-2)); _uiLayer->addChild(button); // Create the button auto button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setNormalizedPosition(Vec2(0.8f, 0.5f)); button2->setTitleText("PLAY GAME"); auto title2 = button2->getTitleRenderer(); title2->enableOutline(Color4B::GREEN, 3); _uiLayer->addChild(button2); return true; } return false; }
bool UIButtonFlipTest::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add a label in which the button events will be displayed _displayValueLabel = Text::create("Button X Flipped", "fonts/Marker Felt.ttf",20); _displayValueLabel->setNormalizedPosition(Vec2(0.3, 0.7)); _uiLayer->addChild(_displayValueLabel); // Create the button auto button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setNormalizedPosition(Vec2(0.3f, 0.5f)); button->setTitleText("PLAY GAME"); button->setTitleFontName("fonts/Marker Felt.ttf"); button->setZoomScale(0.3f); button->setScale(2.0f); button->setFlippedX(true); button->setPressedActionEnabled(true); _uiLayer->addChild(button); // Create the button auto button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setNormalizedPosition(Vec2(0.8f, 0.5f)); button2->setTitleText("PLAY GAME"); button2->setFlippedY(true); _uiLayer->addChild(button2); auto titleLabel = Text::create("Button Y flipped", "Arial", 20); titleLabel->setNormalizedPosition(Vec2(0.8, 0.7)); this->addChild(titleLabel); return true; } return false; }
//按钮 void UI:: initButton(){ auto visibleSize=Director::getInstance()->getVisibleSize(); auto ub=Button::create(); ub->loadTextureNormal("0.png"); ub->loadTexturePressed("2.png"); ub->loadTextureDisabled("2.png"); ub->setScale9Enabled(true); ub->setContentSize(cocos2d::Size(128,128)); ub->setPressedActionEnabled(true); ub->setZoomScale(2); ub->setTitleFontName("fonts/Marker Felt.ttf"); ub->setTitleFontSize(30); ub->setTitleColor(cocos2d::Color3B::YELLOW); ub->setTitleText("HHLLO Button"); // ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this)); //添加触摸事件 ub->addTouchEventListener (this,toucheventselector(UI::buttonClick)); ub->setPosition(visibleSize/2); addChild(ub); }
void ZoomableImageArea::mousePressEvent(QMouseEvent *event) { int scale = zoomScale; if (event->button() == Qt::LeftButton) { if (scale < 8) { ++scale; } } else { if (scale > 1) { --scale; } } if (scale != zoomScale) { setZoomScale(scale); } }
void Button::copySpecialProperties(Widget *widget) { Button* button = dynamic_cast<Button*>(widget); if (button) { _prevIgnoreSize = button->_prevIgnoreSize; setScale9Enabled(button->_scale9Enabled); loadTextureNormal(button->_normalFileName, button->_normalTexType); loadTexturePressed(button->_clickedFileName, button->_pressedTexType); loadTextureDisabled(button->_disabledFileName, button->_disabledTexType); setCapInsetsNormalRenderer(button->_capInsetsNormal); setCapInsetsPressedRenderer(button->_capInsetsPressed); setCapInsetsDisabledRenderer(button->_capInsetsDisabled); setTitleText(button->getTitleText()); setTitleFontName(button->getTitleFontName()); setTitleFontSize(button->getTitleFontSize()); setTitleColor(button->getTitleColor()); setPressedActionEnabled(button->_pressedActionEnabled); setZoomScale(button->_zoomScale); } }
void UI::initListView(){ auto lv=ListView::create(); lv->setContentSize(cocos2d::Size(640,480)); lv->setItemsMargin(20);//设置间隔 lv->setDirection(cocos2d::ui::ScrollView::Direction::VERTICAL); for (int i=0; i<50; i++) { auto ub=Button::create(); ub->loadTextureNormal("0.png"); ub->loadTexturePressed("1.png"); ub->loadTextureDisabled("0.png"); ub->setScale9Enabled(true); ub->setContentSize(Size(600,400)); ub->setPressedActionEnabled(true); ub->setZoomScale(0.5f); ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this)); ub->setTag(i); lv->pushBackCustomItem(ub); } lv->addEventListener(CC_CALLBACK_2(UI::ListViewCall, this)); addChild(lv); }
void Button::copySpecialProperties(Widget *widget) { Button* button = dynamic_cast<Button*>(widget); if (button) { _prevIgnoreSize = button->_prevIgnoreSize; setScale9Enabled(button->_scale9Enabled); auto normalSprite = button->_buttonNormalRenderer->getSprite(); if (nullptr != normalSprite) { loadTextureNormal(normalSprite->getSpriteFrame()); } auto clickedSprite = button->_buttonClickedRenderer->getSprite(); if (nullptr != clickedSprite) { loadTexturePressed(clickedSprite->getSpriteFrame()); } auto disabledSprite = button->_buttonDisableRenderer->getSprite(); if (nullptr != disabledSprite) { loadTextureDisabled(disabledSprite->getSpriteFrame()); } setCapInsetsNormalRenderer(button->_capInsetsNormal); setCapInsetsPressedRenderer(button->_capInsetsPressed); setCapInsetsDisabledRenderer(button->_capInsetsDisabled); if(nullptr != button->getTitleRenderer()) { setTitleText(button->getTitleText()); setTitleFontName(button->getTitleFontName()); setTitleFontSize(button->getTitleFontSize()); setTitleColor(button->getTitleColor()); } setPressedActionEnabled(button->_pressedActionEnabled); setZoomScale(button->_zoomScale); } }
void PreviewWidget::zoomOriginal() { setZoomScale(ZOOM_ORIGINAL_SCALE); }
void ZoomableImageArea::updateImage() { setZoomScale(zoomScale); }
void WebContentAnimationItem::resizeEvent(QGraphicsSceneResizeEvent* event) { QGraphicsWidget::resizeEvent(event); setZoomScale(size().width() / contentsSize().width()); }
//添加一些显示标签 void GameLayer:: addSprite(){ //显第几关的label auto temp = __String::createWithFormat("Level: %d",level); levelLabel = Label::createWithSystemFont(temp->getCString(), "fonts/Marker Felt.ttf", 32); levelLabel->setPosition(Point(80, visibleSize.height-40)); levelLabel->setColor(Color3B(255, 255, 255)); this->addChild(levelLabel,1); //显分数的label xmller.XmlParse(str); std::string level02= xmller.getLevel02(); int number=atoi(level02.c_str()); log("xml score=%d",number); auto sc = __String::createWithFormat("Money: %d",number); scoreLabel = Label::createWithSystemFont(sc->getCString(), "fonts/Marker Felt.ttf", 32); scoreLabel->setPosition(Point(110, visibleSize.height-80)); scoreLabel->setColor(Color3B(255, 255, 0)); this->addChild(scoreLabel,1); //显示子弹数量 std::string level03 = xmller.getLevel03(); int bb = atoi(level03.c_str()); auto cc = __String::createWithFormat("Bullet: %d",bb); bulletLabel = Label::createWithSystemFont(cc->getCString(), "fonts/Marker Felt.ttf", 32); bulletLabel->setPosition(Point(110, visibleSize.height-120)); bulletLabel->setColor(Color3B(0, 255, 0)); this->addChild(bulletLabel,1); //暂停的按钮 auto ub=Button::create(); ub->loadTextureNormal("newPause_Normal.png"); ub->loadTexturePressed("newPause_Select.png"); ub->setScale(0.4); ub->setScale9Enabled(true); ub->setContentSize(Size(128,128)); ub->setPressedActionEnabled(false); ub->setZoomScale(2.0f);//大于1有效小于1无效 ub->addClickEventListener([this](Ref*){ auto l = PauseLayer::createLayer(); l->setDelegate(this); //设置代理---------------------- this->addChild(l); auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan=([](Touch*, Event*){ return true; }); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, l); Director::getInstance()->pause(); }); ub->setPosition(Vec2(visibleSize.width-50,50)); this->addChild(ub); }
void GraphEditor::handleZoomOriginal(void) { if (not this->isVisible()) return; auto draw = this->getCurrentGraphDraw(); draw->setZoomScale(1.0); }
void WHScrollView::onTouchMoved(cocos2d::Touch *pTouch, cocos2d::Event *pEvent) { if (m_PointerId != pTouch->getID()) return; if (m_MoveCount < 8) m_MoveCount++; //CCScrollView::ccTouchMoved(pTouch, pEvent); if (!isVisible()) return; if (m_bScroll) { //if (_touches->containsObject(pTouch)) if (std::find(_touches.begin(), _touches.end(), pTouch) != _touches.end()) { if (_touches.size() == 1 && _dragging) { // scrolling CCPoint moveDistance, newPoint, maxInset, minInset; CCRect frame; float newX, newY; _touchMoved = true; CCPoint frameOriginal = getParent()->convertToWorldSpace(getPosition()); //frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height); frame = CCRectMake(0, 0, _viewSize.width, _viewSize.height); newPoint = convertTouchToNodeSpace((CCTouch*)_touches[0]); moveDistance = ccpSub(newPoint, _touchPoint); _touchPoint = newPoint; CCSize contentsize = getContentSize(); CCPoint offset = getContentOffset(); if (offset.y <= _viewSize.height - contentsize.height) { moveDistance.y = moveDistance.y / m_MoveCount; } //if (frame.containsPoint(convertToWorldSpace(newPoint))) if (frame.containsPoint(newPoint)) { switch (_direction) { case ScrollView::Direction::VERTICAL: moveDistance = ccp(0.0f, moveDistance.y); break; case ScrollView::Direction::HORIZONTAL: moveDistance = ccp(moveDistance.x, 0.0f); break; default: break; } _container->setPosition(ccpAdd(_container->getPosition(), moveDistance)); maxInset = _maxInset; minInset = _minInset; //check to see if offset lies within the inset bounds newX = MIN(_container->getPosition().x, maxInset.x); newX = MAX(newX, minInset.x); newY = MIN(_container->getPosition().y, maxInset.y); newY = MAX(newY, minInset.y); _scrollDistance = ccpSub(moveDistance, ccp(newX - _container->getPosition().x, newY - _container->getPosition().y)); setContentOffset(ccp(newX, newY)); } } else if (_touches.size() == 2 && !_dragging) { const float len = ccpDistance(_container->convertTouchToNodeSpace((CCTouch*)_touches[0]),_container->convertTouchToNodeSpace((CCTouch*)_touches[1])); setZoomScale(getZoomScale()*len / _touchLength); } } } for (int i = 0; i < m_TouchLayer.size(); i++) { if (m_TouchLayerTouched[i]) { CCLayer* pTouchLayer = m_TouchLayer[i]; pTouchLayer->ccTouchMoved(pTouch, pEvent); } } //CCScrollView::ccTouchMoved(pTouch, pEvent); }