axmol/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp

86 lines
2.9 KiB
C++
Raw Normal View History

2014-03-04 16:51:35 +08:00
#include "ScrollViewReader.h"
2014-03-11 17:13:54 +08:00
#include "ui/UIScrollView.h"
#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
{
static const char* P_InnerWidth = "innerWidth";
static const char* P_InnerHeight = "innerHeight";
static const char* P_Direction = "direction";
static const char* P_BounceEnable = "bounceEnable";
2014-06-23 10:12:54 +08:00
static ScrollViewReader* instanceScrollViewReader = nullptr;
2014-03-04 16:51:35 +08:00
IMPLEMENT_CLASS_WIDGET_READER_INFO(ScrollViewReader)
ScrollViewReader::ScrollViewReader()
{
}
ScrollViewReader::~ScrollViewReader()
{
}
ScrollViewReader* ScrollViewReader::getInstance()
{
if (!instanceScrollViewReader)
{
instanceScrollViewReader = new (std::nothrow) ScrollViewReader();
2014-03-04 16:51:35 +08:00
}
return instanceScrollViewReader;
}
2014-06-23 10:02:09 +08:00
void ScrollViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode)
{
//TODO: need to refactor...
2014-06-23 10:02:09 +08:00
LayoutReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
ScrollView* scrollView = static_cast<ScrollView*>(widget);
2014-07-01 16:31:17 +08:00
stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
2014-06-11 09:35:24 +08:00
float innerWidth;
float innerHeight;
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);
if (key == P_InnerWidth) {
2014-06-11 09:35:24 +08:00
innerWidth = valueToFloat(value);
}
else if(key == P_InnerHeight){
2014-06-11 09:35:24 +08:00
innerHeight = valueToFloat(value);
}else if(key == P_Direction){
2014-06-18 14:35:43 +08:00
scrollView->setDirection((ScrollView::Direction)valueToInt(value));
}else if(key == P_BounceEnable){
scrollView->setBounceEnabled(valueToBool(value));
}
} //end of for loop
2014-06-11 09:35:24 +08:00
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
}
2014-03-04 16:51:35 +08:00
void ScrollViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
LayoutReader::setPropsFromJsonDictionary(widget, options);
ScrollView* scrollView = static_cast<ScrollView*>(widget);
2014-07-01 10:57:12 +08:00
float innerWidth = DICTOOL->getFloatValue_json(options, P_InnerWidth,200);
float innerHeight = DICTOOL->getFloatValue_json(options, P_InnerHeight,200);
2014-03-04 16:51:35 +08:00
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
2014-07-01 10:57:12 +08:00
int direction = DICTOOL->getFloatValue_json(options, P_Direction,1);
2014-05-12 11:08:10 +08:00
scrollView->setDirection((ScrollView::Direction)direction);
scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, P_BounceEnable));
2014-03-04 16:51:35 +08:00
LayoutReader::setColorPropsFromJsonDictionary(widget, options);
}
}