本文整理汇总了C++中ImageView::ignoreContentAdaptWithSize方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageView::ignoreContentAdaptWithSize方法的具体用法?C++ ImageView::ignoreContentAdaptWithSize怎么用?C++ ImageView::ignoreContentAdaptWithSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageView
的用法示例。
在下文中一共展示了ImageView::ignoreContentAdaptWithSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setPropsWithFlatBuffers
void ImageViewReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *imageViewOptions)
{
ImageView* imageView = static_cast<ImageView*>(node);
auto options = (ImageViewOptions*)imageViewOptions;
auto imageFileNameDic = options->fileNameData();
int imageFileNameType = imageFileNameDic->resourceType();
std::string imageFileName = imageFileNameDic->path()->c_str();
imageView->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
bool scale9Enabled = options->scale9Enabled();
imageView->setScale9Enabled(scale9Enabled);
auto widgetReader = WidgetReader::getInstance();
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
if (scale9Enabled)
{
imageView->setUnifySizeEnabled(false);
imageView->ignoreContentAdaptWithSize(false);
auto f_scale9Size = options->scale9Size();
Size scale9Size(f_scale9Size->width(), f_scale9Size->height());
imageView->setContentSize(scale9Size);
auto f_capInset = options->capInsets();
Rect capInsets(f_capInset->x(), f_capInset->y(), f_capInset->width(), f_capInset->height());
imageView->setCapInsets(capInsets);
}
}
示例2: init
bool UIImageViewFlipTest::init()
{
if (UIScene::init())
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist");
Size widgetSize = _widget->getContentSize();
Text* alert = Text::create("ImageView flip test", "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("blocks9r.png", Widget::TextureResType::PLIST);
imageView->setScale9Enabled(true);
imageView->setContentSize(Size(250, 115));
imageView->setFlippedX(true);
imageView->setScale(0.5);
imageView->ignoreContentAdaptWithSize(false);
imageView->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f));
_uiLayer->addChild(imageView);
auto toggleButton = Button::create();
toggleButton->setTitleText("Toggle FlipX");
toggleButton->setPosition(imageView->getPosition() + Vec2(-50, - imageView->getContentSize().height/2 - 20));
this->addChild(toggleButton);
toggleButton->addClickEventListener([=](Ref*){
imageView->setFlippedX(!imageView->isFlippedX());
});
auto toggleScale9 = Button::create();
toggleScale9->setTitleText("Toggle Scale9");
toggleScale9->setPosition(imageView->getPosition() + Vec2(+50, - imageView->getContentSize().height/2- 20));
this->addChild(toggleScale9);
toggleScale9->addClickEventListener([=](Ref*){
imageView->setScale9Enabled(!imageView->isScale9Enabled());
//after switching scale9, you must call setContentSize to keep the size not change
imageView->setContentSize(Size(250, 115));
});
return true;
}
return false;
}
示例3: setPropsFromProtocolBuffers
void ImageViewReader::setPropsFromProtocolBuffers(ui::Widget *widget, const protocolbuffers::NodeTree &nodeTree)
{
WidgetReader::setPropsFromProtocolBuffers(widget, nodeTree);
const protocolbuffers::ImageViewOptions& options = nodeTree.imageviewoptions();
ImageView* imageView = static_cast<ImageView*>(widget);
std::string protocolBuffersPath = GUIReader::getInstance()->getFilePath();
const protocolbuffers::ResourceData& imageFileNameDic = options.filenamedata();
int imageFileNameType = imageFileNameDic.resourcetype();
std::string imageFileName = this->getResourcePath(imageFileNameDic.path(), (Widget::TextureResType)imageFileNameType);
imageView->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
bool scale9EnableExist = options.has_scale9enable();
bool scale9Enable = false;
if (scale9EnableExist)
{
scale9Enable = options.scale9enable();
}
imageView->setScale9Enabled(scale9Enable);
if (scale9Enable)
{
imageView->setUnifySizeEnabled(false);
imageView->ignoreContentAdaptWithSize(false);
float swf = options.has_scale9width() ? options.scale9width() : 80.0f;
float shf = options.has_scale9height() ? options.scale9height() : 80.0f;
imageView->setContentSize(Size(swf, shf));
float cx = options.capinsetsx();
float cy = options.capinsetsy();
float cw = options.has_capinsetswidth() ? options.capinsetswidth() : 1.0;
float ch = options.has_capinsetsheight() ? options.capinsetsheight() : 1.0;
imageView->setCapInsets(Rect(cx, cy, cw, ch));
}
// other commonly protperties
WidgetReader::setColorPropsFromProtocolBuffers(widget, nodeTree);
}
示例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;
}
示例5: setPropsWithFlatBuffers
void ImageViewReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *imageViewOptions)
{
ImageView* imageView = static_cast<ImageView*>(node);
auto options = (ImageViewOptions*)imageViewOptions;
bool fileExist = false;
std::string errorFilePath = "";
auto imageFileNameDic = options->fileNameData();
int imageFileNameType = imageFileNameDic->resourceType();
std::string imageFileName = imageFileNameDic->path()->c_str();
switch (imageFileNameType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(imageFileName))
{
fileExist = true;
}
else
{
errorFilePath = imageFileName;
fileExist = false;
}
break;
}
case 1:
{
std::string plist = imageFileNameDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName);
if (spriteFrame)
{
fileExist = true;
}
else
{
if (FileUtils::getInstance()->isFileExist(plist))
{
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
ValueMap metadata = value["metadata"].asValueMap();
std::string textureFileName = metadata["textureFileName"].asString();
if (!FileUtils::getInstance()->isFileExist(textureFileName))
{
errorFilePath = textureFileName;
}
}
else
{
errorFilePath = plist;
}
fileExist = false;
}
break;
}
default:
break;
}
if (fileExist)
{
imageView->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
}
//else
//{
// auto label = Label::create();
// label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString());
// imageView->addChild(label);
//}
bool scale9Enabled = options->scale9Enabled() != 0;
imageView->setScale9Enabled(scale9Enabled);
auto widgetReader = WidgetReader::getInstance();
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
if (scale9Enabled)
{
imageView->setUnifySizeEnabled(false);
imageView->ignoreContentAdaptWithSize(false);
auto f_scale9Size = options->scale9Size();
Size scale9Size(f_scale9Size->width(), f_scale9Size->height());
imageView->setContentSize(scale9Size);
auto f_capInset = options->capInsets();
Rect capInsets(f_capInset->x(), f_capInset->y(), f_capInset->width(), f_capInset->height());
imageView->setCapInsets(capInsets);
}
else
{
Size contentSize(options->widgetOptions()->size()->width(), options->widgetOptions()->size()->height());
imageView->setContentSize(contentSize);
}
}