#include "ScrollViewReader.h" #include "ui/UIScrollView.h" #include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { static const char* P_InnerWidth = "innerWidth"; static const char* P_InnerHeight = "innerHeight"; static const char* P_Direction = "direction"; static const char* P_BounceEnable = "bounceEnable"; static ScrollViewReader* instanceScrollViewReader = nullptr; IMPLEMENT_CLASS_WIDGET_READER_INFO(ScrollViewReader) ScrollViewReader::ScrollViewReader() { } ScrollViewReader::~ScrollViewReader() { } ScrollViewReader* ScrollViewReader::getInstance() { if (!instanceScrollViewReader) { instanceScrollViewReader = new ScrollViewReader(); } return instanceScrollViewReader; } void ScrollViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode) { //TODO::need to refactor... LayoutReader::setPropsFromBinary(widget, cocoLoader, cocoNode); ScrollView* scrollView = static_cast(widget); stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader); float innerWidth; float innerHeight; for (int i = 0; i < cocoNode->GetChildNum(); ++i) { std::string key = stChildArray[i].GetName(cocoLoader); std::string value = stChildArray[i].GetValue(cocoLoader); if (key == P_InnerWidth) { innerWidth = valueToFloat(value); } else if(key == P_InnerHeight){ innerHeight = valueToFloat(value); }else if(key == P_Direction){ scrollView->setDirection((ScrollView::Direction)valueToInt(value)); }else if(key == P_BounceEnable){ scrollView->setBounceEnabled(valueToBool(value)); } } //end of for loop scrollView->setInnerContainerSize(Size(innerWidth, innerHeight)); } void ScrollViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { LayoutReader::setPropsFromJsonDictionary(widget, options); ScrollView* scrollView = static_cast(widget); float innerWidth = DICTOOL->getFloatValue_json(options, P_InnerWidth,200); float innerHeight = DICTOOL->getFloatValue_json(options, P_InnerHeight,200); scrollView->setInnerContainerSize(Size(innerWidth, innerHeight)); int direction = DICTOOL->getFloatValue_json(options, P_Direction,1); scrollView->setDirection((ScrollView::Direction)direction); scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, P_BounceEnable)); LayoutReader::setColorPropsFromJsonDictionary(widget, options); } }