2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "ScrollViewReader.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UIScrollView.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_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)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
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)
|
2014-06-05 10:25:08 +08:00
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
//TODO::need to refactor...
|
2014-06-23 10:02:09 +08:00
|
|
|
LayoutReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
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);
|
2014-06-19 17:04:14 +08:00
|
|
|
if (key == P_InnerWidth) {
|
2014-06-11 09:35:24 +08:00
|
|
|
innerWidth = valueToFloat(value);
|
2014-06-05 10:25:08 +08:00
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if(key == P_InnerHeight){
|
2014-06-11 09:35:24 +08:00
|
|
|
innerHeight = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_Direction){
|
2014-06-18 14:35:43 +08:00
|
|
|
scrollView->setDirection((ScrollView::Direction)valueToInt(value));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_BounceEnable){
|
2014-06-05 10:25:08 +08:00
|
|
|
scrollView->setBounceEnabled(valueToBool(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
} //end of for loop
|
2014-06-11 09:35:24 +08:00
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
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);
|
2014-06-19 17:04:14 +08:00
|
|
|
scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, P_BounceEnable));
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
LayoutReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
|
|
|
}
|