2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "ImageViewReader.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UIImageView.h"
|
2014-06-05 10:25:08 +08:00
|
|
|
#include "cocostudio/CocoLoader.h"
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-03-06 16:15:03 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace ui;
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
static const char* P_Scale9Enable = "scale9Enable";
|
|
|
|
static const char* P_FileNameData = "fileNameData";
|
|
|
|
static const char* P_CapInsetsX = "capInsetsX";
|
|
|
|
static const char* P_CapInsetsY = "capInsetsY";
|
|
|
|
static const char* P_CapInsetsWidth = "capInsetsWidth";
|
|
|
|
static const char* P_CapInsetsHeight = "capInsetsHeight";
|
|
|
|
static const char* P_Scale9Width = "scale9Width";
|
|
|
|
static const char* P_Scale9Height = "scale9Height";
|
|
|
|
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
static ImageViewReader* instanceImageViewReader = nullptr;
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
IMPLEMENT_CLASS_WIDGET_READER_INFO(ImageViewReader)
|
|
|
|
|
|
|
|
ImageViewReader::ImageViewReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageViewReader::~ImageViewReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageViewReader* ImageViewReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceImageViewReader)
|
|
|
|
{
|
|
|
|
instanceImageViewReader = new ImageViewReader();
|
|
|
|
}
|
|
|
|
return instanceImageViewReader;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void ImageViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
|
2014-06-05 10:25:08 +08:00
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
ImageView* imageView = static_cast<ImageView*>(widget);
|
2014-06-11 09:35:24 +08:00
|
|
|
this->beginSetBasicProperties(widget);
|
2014-06-05 10:25:08 +08:00
|
|
|
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
|
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
|
|
|
|
std::string key = stChildArray[i].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
std::string value = stChildArray[i].GetValue(cocoLoader);
|
2014-06-11 09:35:24 +08:00
|
|
|
|
2014-06-19 15:16:56 +08:00
|
|
|
//read all basic properties of widget
|
|
|
|
CC_BASIC_PROPERTY_BINARY_READER
|
|
|
|
//read all color related properties of widget
|
|
|
|
CC_COLOR_PROPERTY_BINARY_READER
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
else if (key == P_Scale9Enable) {
|
2014-06-05 10:25:08 +08:00
|
|
|
imageView->setScale9Enabled(valueToBool(value));
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if (key == P_FileNameData){
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
|
|
|
std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
|
2014-06-11 09:35:24 +08:00
|
|
|
|
2014-06-05 10:25:08 +08:00
|
|
|
imageView->loadTexture(backgroundValue, imageFileNameType);
|
|
|
|
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if(key == P_Scale9Width){
|
2014-06-24 10:18:01 +08:00
|
|
|
imageView->setContentSize(Size(valueToFloat(value), imageView->getContentSize().height));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_Scale9Height){
|
2014-06-24 10:18:01 +08:00
|
|
|
imageView->setContentSize(Size(imageView->getContentSize().width, valueToFloat(value)));
|
2014-06-05 10:25:08 +08:00
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if(key == P_CapInsetsX){
|
2014-06-05 10:25:08 +08:00
|
|
|
capsx = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_CapInsetsY){
|
2014-06-05 10:25:08 +08:00
|
|
|
capsy = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_CapInsetsWidth){
|
2014-06-05 10:25:08 +08:00
|
|
|
capsWidth = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_CapInsetsHeight){
|
2014-06-05 10:25:08 +08:00
|
|
|
capsHeight = valueToFloat(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
} //end of for loop
|
|
|
|
|
|
|
|
if (imageView->isScale9Enabled()) {
|
|
|
|
imageView->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
|
|
|
|
}
|
2014-06-11 09:35:24 +08:00
|
|
|
|
|
|
|
this->endSetBasicProperties(widget);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
void ImageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImageView* imageView = static_cast<ImageView*>(widget);
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_FileNameData);
|
|
|
|
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType);
|
|
|
|
std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType);
|
2014-05-09 14:56:05 +08:00
|
|
|
imageView->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
|
2014-04-04 17:18:24 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, P_Scale9Enable);
|
2014-03-04 16:51:35 +08:00
|
|
|
bool scale9Enable = false;
|
|
|
|
if (scale9EnableExist)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
imageView->setScale9Enabled(scale9Enable);
|
|
|
|
|
|
|
|
|
|
|
|
if (scale9Enable)
|
|
|
|
{
|
2014-07-01 10:57:12 +08:00
|
|
|
|
|
|
|
float swf = DICTOOL->getFloatValue_json(options, P_Scale9Width,80.0f);
|
|
|
|
float shf = DICTOOL->getFloatValue_json(options, P_Scale9Height,80.0f);
|
2014-07-10 00:45:27 +08:00
|
|
|
imageView->setContentSize(Size(swf, shf));
|
2014-07-01 10:57:12 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX);
|
|
|
|
float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY);
|
2014-07-01 10:57:12 +08:00
|
|
|
float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth,1.0f);
|
|
|
|
float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight,1.0f);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
imageView->setCapInsets(Rect(cx, cy, cw, ch));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
|
|
|
}
|