mirror of https://github.com/axmolengine/axmol.git
Add custom widget and reader
This commit is contained in:
parent
c09b139fee
commit
4a2dc4a607
|
@ -1 +1 @@
|
|||
8fad051dc33d390c01df304fee2a78e22785136f
|
||||
b2a9a1c6c284417271f205039b372f82753220e1
|
|
@ -1 +1 @@
|
|||
9da17496043155938cbd8973b01514f220e7192b
|
||||
b3ac787f7396c7b2ee89daec7c75040241298efb
|
|
@ -26,6 +26,19 @@ THE SOFTWARE.
|
|||
#include "cocostudio/CCActionManagerEx.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "WidgetReader/ButtonReader/ButtonReader.h"
|
||||
#include "WidgetReader/CheckBoxReader/CheckBoxReader.h"
|
||||
#include "WidgetReader/SliderReader/SliderReader.h"
|
||||
#include "WidgetReader/ImageViewReader/ImageViewReader.h"
|
||||
#include "WidgetReader/LoadingBarReader/LoadingBarReader.h"
|
||||
#include "WidgetReader/TextAtlasReader/TextAtlasReader.h"
|
||||
#include "WidgetReader/TextReader/TextReader.h"
|
||||
#include "WidgetReader/TextBMFontReader/TextBMFontReader.h"
|
||||
#include "WidgetReader/TextFieldReader/TextFieldReader.h"
|
||||
#include "WidgetReader/LayoutReader/LayoutReader.h"
|
||||
#include "WidgetReader/PageViewReader/PageViewReader.h"
|
||||
#include "WidgetReader/ScrollViewReader/ScrollViewReader.h"
|
||||
#include "WidgetReader/ListViewReader/ListViewReader.h"
|
||||
|
||||
using namespace cocos2d::ui;
|
||||
using namespace cocos2d;
|
||||
|
@ -38,6 +51,35 @@ static GUIReader* sharedReader = nullptr;
|
|||
GUIReader::GUIReader():
|
||||
m_strFilePath("")
|
||||
{
|
||||
ObjectFactory* factoryCreate = ObjectFactory::getInstance();
|
||||
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ButtonReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(CheckBoxReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(SliderReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ImageViewReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(LoadingBarReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextAtlasReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextBMFontReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextFieldReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(LayoutReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(PageViewReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ScrollViewReader));
|
||||
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ListViewReader));
|
||||
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Button));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(CheckBox));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(ImageView));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Text));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(TextAtlas));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(TextBMFont));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(LoadingBar));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Slider));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(TextField));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Layout));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(ListView));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(PageView));
|
||||
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(ScrollView));
|
||||
}
|
||||
|
||||
GUIReader::~GUIReader()
|
||||
|
@ -112,6 +154,27 @@ const cocos2d::Size GUIReader::getFileDesignSize(const char* fileName) const
|
|||
float h = _fileDesignSizes.at(keyHeight).asFloat();
|
||||
return Size(w, h);
|
||||
}
|
||||
|
||||
void GUIReader::registerTypeAndCallBack(const std::string& classType,
|
||||
ObjectFactory::Instance ins,
|
||||
Object *object,
|
||||
SEL_ParseEvent callBack)
|
||||
{
|
||||
ObjectFactory* factoryCreate = ObjectFactory::getInstance();
|
||||
|
||||
ObjectFactory::TInfo t(classType, ins);
|
||||
factoryCreate->registerType(t);
|
||||
|
||||
if (object)
|
||||
{
|
||||
_mapObject.insert(ParseObjectMap::value_type(classType, object));
|
||||
}
|
||||
|
||||
if (callBack)
|
||||
{
|
||||
_mapParseSelector.insert(ParseCallBackMap::value_type(classType, callBack));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Widget* GUIReader::widgetFromJsonFile(const char *fileName)
|
||||
|
@ -851,6 +914,18 @@ void WidgetPropertiesReader0250::setPropsForLabelBMFontFromJsonDictionary(Widget
|
|||
|
||||
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
||||
}
|
||||
|
||||
void WidgetPropertiesReader0250::setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol *reader, Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void WidgetPropertiesReader0250::setPropsForAllCustomWidgetFromJsonDictionary(const std::string &classType,
|
||||
cocos2d::ui::Widget *widget,
|
||||
const rapidjson::Value &customOptions)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*0.3.0.0~1.0.0.0*/
|
||||
|
@ -899,96 +974,121 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c
|
|||
ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget);
|
||||
return widget;
|
||||
}
|
||||
|
||||
Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Value&data)
|
||||
|
||||
Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Value& data)
|
||||
{
|
||||
Widget* widget = nullptr;
|
||||
const char* classname = DICTOOL->getStringValue_json(data, "classname");
|
||||
const rapidjson::Value& uiOptions = DICTOOL->getSubDictionary_json(data, "options");
|
||||
if (classname && strcmp(classname, "Button") == 0)
|
||||
Widget* widget = ObjectFactory::getInstance()->createGUI(classname);
|
||||
|
||||
// create widget reader to parse properties of widget
|
||||
std::string readerName = classname;
|
||||
if (readerName == "Panel")
|
||||
{
|
||||
widget = cocos2d::ui::Button::create();
|
||||
setPropsForButtonFromJsonDictionary(widget, uiOptions);
|
||||
readerName = "Layout";
|
||||
}
|
||||
else if (classname && strcmp(classname, "CheckBox") == 0)
|
||||
else if (readerName == "TextArea")
|
||||
{
|
||||
widget = CheckBox::create();
|
||||
setPropsForCheckBoxFromJsonDictionary(widget, uiOptions);
|
||||
readerName = "Text";
|
||||
}
|
||||
else if (classname && strcmp(classname, "Label") == 0)
|
||||
else if (readerName == "TextButton")
|
||||
{
|
||||
widget = cocos2d::ui::Text::create();
|
||||
setPropsForLabelFromJsonDictionary(widget, uiOptions);
|
||||
readerName = "Button";
|
||||
}
|
||||
else if (classname && strcmp(classname, "LabelAtlas") == 0)
|
||||
else if (readerName == "Label")
|
||||
{
|
||||
widget = cocos2d::ui::TextAtlas::create();
|
||||
setPropsForLabelAtlasFromJsonDictionary(widget, uiOptions);
|
||||
readerName = "Text";
|
||||
}
|
||||
else if (classname && strcmp(classname, "LoadingBar") == 0)
|
||||
else if (readerName == "LabelAtlas")
|
||||
{
|
||||
widget = cocos2d::ui::LoadingBar::create();
|
||||
setPropsForLoadingBarFromJsonDictionary(widget, uiOptions);
|
||||
}else if (classname && strcmp(classname, "ScrollView") == 0){
|
||||
widget = cocos2d::ui::ScrollView::create();
|
||||
setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
|
||||
readerName = "TextAtlas";
|
||||
}
|
||||
else if (classname && strcmp(classname, "TextArea") == 0)
|
||||
else if (readerName == "LabelBMFont")
|
||||
{
|
||||
widget = cocos2d::ui::Text::create();
|
||||
setPropsForLabelFromJsonDictionary(widget, uiOptions);
|
||||
readerName = "TextBMFont";
|
||||
}
|
||||
else if (classname && strcmp(classname, "TextButton") == 0)
|
||||
readerName.append("Reader");
|
||||
WidgetReaderProtocol* reader = ObjectFactory::getInstance()->createWidgetReaderProtocol(readerName);
|
||||
|
||||
if (reader)
|
||||
{
|
||||
widget = cocos2d::ui::Button::create();
|
||||
setPropsForButtonFromJsonDictionary(widget, uiOptions);
|
||||
// widget parse with widget reader
|
||||
setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions);
|
||||
}
|
||||
else if (classname && strcmp(classname, "TextField") == 0)
|
||||
else
|
||||
{
|
||||
widget = cocos2d::ui::TextField::create();
|
||||
setPropsForTextFieldFromJsonDictionary(widget, uiOptions);
|
||||
}
|
||||
else if (classname && strcmp(classname, "ImageView") == 0)
|
||||
{
|
||||
widget = cocos2d::ui::ImageView::create();
|
||||
setPropsForImageViewFromJsonDictionary(widget, uiOptions);
|
||||
}
|
||||
else if (classname && strcmp(classname, "Panel") == 0)
|
||||
{
|
||||
widget = Layout::create();
|
||||
setPropsForLayoutFromJsonDictionary(widget, uiOptions);
|
||||
}
|
||||
else if (classname && strcmp(classname, "Slider") == 0)
|
||||
{
|
||||
widget = cocos2d::ui::Slider::create();
|
||||
setPropsForSliderFromJsonDictionary(widget, uiOptions);
|
||||
}
|
||||
else if (classname && strcmp(classname, "LabelBMFont") == 0)
|
||||
{
|
||||
widget = cocos2d::ui::TextBMFont::create();
|
||||
setPropsForLabelBMFontFromJsonDictionary(widget, uiOptions);
|
||||
}
|
||||
else if (classname && strcmp(classname, "DragPanel") == 0)
|
||||
{
|
||||
widget = cocos2d::ui::ScrollView::create();
|
||||
setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
|
||||
}
|
||||
else if (classname && strcmp(classname, "ListView") == 0)
|
||||
{
|
||||
widget = cocos2d::ui::ListView::create();
|
||||
setPropsForListViewFromJsonDictionary(widget, uiOptions);
|
||||
}
|
||||
else if (classname && strcmp(classname, "PageView") == 0)
|
||||
{
|
||||
widget = cocos2d::ui::PageView::create();
|
||||
setPropsForPageViewFromJsonDictionary(widget, uiOptions);
|
||||
// 1st., custom widget parse properties of parent widget with parent widget reader
|
||||
if (dynamic_cast<Button*>(widget))
|
||||
{
|
||||
readerName = "ButtonReader";
|
||||
}
|
||||
else if (dynamic_cast<CheckBox*>(widget))
|
||||
{
|
||||
readerName = "CheckBoxReader";
|
||||
}
|
||||
else if (dynamic_cast<ImageView*>(widget))
|
||||
{
|
||||
readerName = "ImageViewReader";
|
||||
}
|
||||
else if (dynamic_cast<TextAtlas*>(widget))
|
||||
{
|
||||
readerName = "TextAtlasReader";
|
||||
}
|
||||
else if (dynamic_cast<TextBMFont*>(widget))
|
||||
{
|
||||
readerName = "TextBMFontReader";
|
||||
}
|
||||
else if (dynamic_cast<Text*>(widget))
|
||||
{
|
||||
readerName = "TextReader";
|
||||
}
|
||||
else if (dynamic_cast<LoadingBar*>(widget))
|
||||
{
|
||||
readerName = "LoadingBarReader";
|
||||
}
|
||||
else if (dynamic_cast<Slider*>(widget))
|
||||
{
|
||||
readerName = "SliderReader";
|
||||
}
|
||||
else if (dynamic_cast<TextField*>(widget))
|
||||
{
|
||||
readerName = "TextFieldReader";
|
||||
}
|
||||
else if (dynamic_cast<Layout*>(widget))
|
||||
{
|
||||
readerName = "LayoutReader";
|
||||
}
|
||||
else if (dynamic_cast<ScrollView*>(widget))
|
||||
{
|
||||
readerName = "ScrollViewReader";
|
||||
}
|
||||
else if (dynamic_cast<ListView*>(widget))
|
||||
{
|
||||
readerName = "ListViewReader";
|
||||
}
|
||||
else if (dynamic_cast<PageView*>(widget))
|
||||
{
|
||||
readerName = "PageViewReader";
|
||||
}
|
||||
reader = ObjectFactory::getInstance()->createWidgetReaderProtocol(readerName);
|
||||
setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions);
|
||||
|
||||
// 2nd., custom widget parse with custom reader
|
||||
const char* customProperty = DICTOOL->getStringValue_json(uiOptions, "customProperty");
|
||||
rapidjson::Document customJsonDict;
|
||||
customJsonDict.Parse<0>(customProperty);
|
||||
if (customJsonDict.HasParseError())
|
||||
{
|
||||
CCLOG("GetParseError %s\n", customJsonDict.GetParseError());
|
||||
}
|
||||
setPropsForAllCustomWidgetFromJsonDictionary(classname, widget, customJsonDict);
|
||||
}
|
||||
|
||||
int childrenCount = DICTOOL->getArrayCount_json(data, "children");
|
||||
for (int i=0;i<childrenCount;i++)
|
||||
for (int i = 0; i < childrenCount; i++)
|
||||
{
|
||||
const rapidjson::Value& subData = DICTOOL->getDictionaryFromArray_json(data, "children", i);
|
||||
Widget* child = widgetFromJsonDictionary(subData);
|
||||
cocos2d::ui::Widget* child = widgetFromJsonDictionary(subData);
|
||||
if (child)
|
||||
{
|
||||
PageView* pageView = dynamic_cast<PageView*>(widget);
|
||||
|
@ -1010,7 +1110,6 @@ Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Va
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
@ -1489,7 +1588,7 @@ void WidgetPropertiesReader0300::setPropsForLabelAtlasFromJsonDictionary(Widget*
|
|||
std::string tp_c = m_strFilePath;
|
||||
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
|
||||
const char* cmf_tp = tp_c.append(cmfPath).c_str();
|
||||
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth") / CC_CONTENT_SCALE_FACTOR(),DICTOOL->getIntValue_json(options,"itemHeight") / CC_CONTENT_SCALE_FACTOR(), DICTOOL->getStringValue_json(options, "startCharMap"));
|
||||
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"), DICTOOL->getStringValue_json(options, "startCharMap"));
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
|
@ -1505,6 +1604,21 @@ void WidgetPropertiesReader0300::setPropsForLabelAtlasFromJsonDictionary(Widget*
|
|||
void WidgetPropertiesReader0300::setPropsForLayoutFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
||||
{
|
||||
setPropsForWidgetFromJsonDictionary(widget, options);
|
||||
|
||||
float w = 0, h = 0;
|
||||
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen");
|
||||
if (adaptScrenn)
|
||||
{
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
w = screenSize.width;
|
||||
h = screenSize.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = DICTOOL->getFloatValue_json(options, "width");
|
||||
h = DICTOOL->getFloatValue_json(options, "height");
|
||||
}
|
||||
|
||||
Layout* panel = static_cast<cocos2d::ui::Layout*>(widget);
|
||||
if (!dynamic_cast<cocos2d::ui::ScrollView*>(widget)
|
||||
&& !dynamic_cast<cocos2d::ui::ListView*>(widget))
|
||||
|
@ -1901,4 +2015,27 @@ void WidgetPropertiesReader0300::setPropsForListViewFromJsonDictionary(Widget* w
|
|||
listView->setItemsMargin(itemMargin);
|
||||
}
|
||||
|
||||
void WidgetPropertiesReader0300::setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol *reader, Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
reader->setPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
|
||||
void WidgetPropertiesReader0300::setPropsForAllCustomWidgetFromJsonDictionary(const std::string &classType,
|
||||
cocos2d::ui::Widget *widget,
|
||||
const rapidjson::Value &customOptions)
|
||||
{
|
||||
GUIReader* guiReader = GUIReader::getInstance();
|
||||
|
||||
std::map<std::string, Object*> object_map = GUIReader::getInstance()->getParseObjectMap();
|
||||
Object* object = object_map[classType];
|
||||
|
||||
std::map<std::string, SEL_ParseEvent> selector_map = guiReader->getParseCallBackMap();
|
||||
SEL_ParseEvent selector = selector_map[classType];
|
||||
|
||||
if (object && selector)
|
||||
{
|
||||
(object->*selector)(classType, widget, customOptions);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,10 +27,15 @@ THE SOFTWARE.
|
|||
|
||||
#include "gui/UIWidget.h"
|
||||
#include "cocostudio/DictionaryHelper.h"
|
||||
#include "WidgetReader/WidgetReaderProtocol.h"
|
||||
#include "ObjectFactory.h"
|
||||
|
||||
namespace cocostudio {
|
||||
|
||||
#define kCCSVersion 1.0
|
||||
|
||||
typedef void (Ref::*SEL_ParseEvent)(const std::string&, Ref*, const rapidjson::Value&);
|
||||
#define parseselector(_SELECTOR) (SEL_ParseEvent)(&_SELECTOR)
|
||||
|
||||
class GUIReader : public cocos2d::Ref
|
||||
{
|
||||
|
@ -52,6 +57,13 @@ public:
|
|||
*/
|
||||
const cocos2d::Size getFileDesignSize(const char* fileName) const;
|
||||
|
||||
const std::string& getFilePath() const { return m_strFilePath; };
|
||||
void registerTypeAndCallBack(const std::string& classType,
|
||||
ObjectFactory::Instance ins,
|
||||
Ref* object,
|
||||
SEL_ParseEvent callBack);
|
||||
|
||||
|
||||
protected:
|
||||
GUIReader();
|
||||
~GUIReader();
|
||||
|
@ -59,6 +71,15 @@ protected:
|
|||
std::string m_strFilePath;
|
||||
cocos2d::ValueMap _fileDesignSizes;
|
||||
|
||||
typedef std::map<std::string, SEL_ParseEvent> ParseCallBackMap;
|
||||
ParseCallBackMap _mapParseSelector;
|
||||
typedef std::map<std::string, Ref*> ParseObjectMap;
|
||||
ParseObjectMap _mapObject;
|
||||
|
||||
public:
|
||||
ParseCallBackMap getParseCallBackMap() { return _mapParseSelector; };
|
||||
ParseObjectMap getParseObjectMap() { return _mapObject; };
|
||||
|
||||
};
|
||||
|
||||
class WidgetPropertiesReader : public cocos2d::Ref
|
||||
|
@ -66,6 +87,10 @@ class WidgetPropertiesReader : public cocos2d::Ref
|
|||
public:
|
||||
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName)=0;
|
||||
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& data) = 0;
|
||||
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, const rapidjson::Value& options) = 0;
|
||||
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
||||
cocos2d::ui::Widget* widget,
|
||||
const rapidjson::Value& customOptions) = 0;
|
||||
protected:
|
||||
std::string m_strFilePath;
|
||||
};
|
||||
|
@ -96,6 +121,11 @@ public:
|
|||
|
||||
virtual void setPropsForLayoutFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
|
||||
virtual void setPropsForScrollViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
|
||||
|
||||
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, const rapidjson::Value& options);
|
||||
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
||||
cocos2d::ui::Widget* widget,
|
||||
const rapidjson::Value& customOptions);
|
||||
};
|
||||
|
||||
class WidgetPropertiesReader0300 : public WidgetPropertiesReader
|
||||
|
@ -125,6 +155,11 @@ public:
|
|||
virtual void setPropsForPageViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
|
||||
virtual void setPropsForScrollViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
|
||||
virtual void setPropsForListViewFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
|
||||
|
||||
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, const rapidjson::Value& options);
|
||||
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
||||
cocos2d::ui::Widget* widget,
|
||||
const rapidjson::Value& customOptions);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "ObjectFactory.h"
|
||||
#include "gui/UIWidget.h"
|
||||
#include "cocostudio/WidgetReader/WidgetReaderProtocol.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
|
@ -138,6 +140,59 @@ Component* ObjectFactory::createComponent(const std::string &name)
|
|||
return (Component*)o;
|
||||
|
||||
}
|
||||
|
||||
ui::Widget* ObjectFactory::createGUI(std::string name)
|
||||
{
|
||||
Object* object = NULL;
|
||||
|
||||
if (name == "Panel")
|
||||
{
|
||||
name = "Layout";
|
||||
}
|
||||
else if (name == "TextArea")
|
||||
{
|
||||
name = "Text";
|
||||
}
|
||||
else if (name == "TextButton")
|
||||
{
|
||||
name = "Button";
|
||||
}
|
||||
else if (name == "Label")
|
||||
{
|
||||
name = "Text";
|
||||
}
|
||||
else if (name == "LabelAtlas")
|
||||
{
|
||||
name = "TextAtlas";
|
||||
}
|
||||
else if (name == "LabelBMFont")
|
||||
{
|
||||
name = "TextBMFont";
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
const TInfo t = _typeMap[name];
|
||||
CC_BREAK_IF(t._fun == NULL);
|
||||
object = t._fun();
|
||||
} while (0);
|
||||
|
||||
return static_cast<ui::Widget*>(object);
|
||||
}
|
||||
|
||||
WidgetReaderProtocol* ObjectFactory::createWidgetReaderProtocol(std::string name)
|
||||
{
|
||||
Object* object = NULL;
|
||||
|
||||
do
|
||||
{
|
||||
const TInfo t = _typeMap[name];
|
||||
CC_BREAK_IF(t._fun == NULL);
|
||||
object = t._fun();
|
||||
} while (0);
|
||||
|
||||
return dynamic_cast<WidgetReaderProtocol*>(object);
|
||||
}
|
||||
|
||||
void ObjectFactory::registerType(const TInfo &t)
|
||||
{
|
||||
|
|
|
@ -29,6 +29,18 @@ THE SOFTWARE.
|
|||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace cocos2d
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
class Widget;
|
||||
}
|
||||
}
|
||||
namespace cocostudio
|
||||
{
|
||||
class WidgetReaderProtocol;
|
||||
}
|
||||
|
||||
namespace cocostudio {
|
||||
|
||||
class ObjectFactory
|
||||
|
@ -51,6 +63,8 @@ public:
|
|||
static void destroyInstance();
|
||||
cocos2d::Ref* createObject(const std::string &name);
|
||||
cocos2d::Component* createComponent(const std::string &name);
|
||||
cocos2d::ui::Widget* createGUI(std::string name);
|
||||
WidgetReaderProtocol* createWidgetReaderProtocol(std::string name);
|
||||
void registerType(const TInfo &t);
|
||||
void removeAll();
|
||||
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
|
||||
|
||||
#include "ButtonReader.h"
|
||||
#include "gui/UIButton.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static ButtonReader* instanceButtonReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(ButtonReader)
|
||||
|
||||
ButtonReader::ButtonReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ButtonReader::~ButtonReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ButtonReader* ButtonReader::getInstance()
|
||||
{
|
||||
if (!instanceButtonReader)
|
||||
{
|
||||
instanceButtonReader = new ButtonReader();
|
||||
}
|
||||
return instanceButtonReader;
|
||||
}
|
||||
|
||||
void ButtonReader::purge()
|
||||
{
|
||||
CC_SAFE_DELETE(instanceButtonReader);
|
||||
}
|
||||
|
||||
void ButtonReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
Button* button = static_cast<Button*>(widget);
|
||||
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
||||
button->setScale9Enabled(scale9Enable);
|
||||
|
||||
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData");
|
||||
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
|
||||
switch (normalType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_n = jsonPath;
|
||||
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
||||
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
|
||||
button->loadTextureNormal(normalFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
||||
button->loadTextureNormal(normalFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData");
|
||||
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
|
||||
switch (pressedType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_p = jsonPath;
|
||||
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
||||
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
|
||||
button->loadTexturePressed(pressedFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
||||
button->loadTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData");
|
||||
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
|
||||
switch (disabledType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_d = jsonPath;
|
||||
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
||||
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
|
||||
button->loadTextureDisabled(disabledFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
||||
button->loadTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (scale9Enable)
|
||||
{
|
||||
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
||||
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
||||
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
||||
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
||||
|
||||
button->setCapInsets(Rect(cx, cy, cw, ch));
|
||||
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
|
||||
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
|
||||
if (sw && sh)
|
||||
{
|
||||
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
|
||||
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
|
||||
button->setSize(Size(swf, shf));
|
||||
}
|
||||
}
|
||||
bool tt = DICTOOL->checkObjectExist_json(options, "text");
|
||||
if (tt)
|
||||
{
|
||||
const char* text = DICTOOL->getStringValue_json(options, "text");
|
||||
if (text)
|
||||
{
|
||||
button->setTitleText(text);
|
||||
}
|
||||
}
|
||||
|
||||
bool cr = DICTOOL->checkObjectExist_json(options, "textColorR");
|
||||
bool cg = DICTOOL->checkObjectExist_json(options, "textColorG");
|
||||
bool cb = DICTOOL->checkObjectExist_json(options, "textColorB");
|
||||
int cri = cr?DICTOOL->getIntValue_json(options, "textColorR"):255;
|
||||
int cgi = cg?DICTOOL->getIntValue_json(options, "textColorG"):255;
|
||||
int cbi = cb?DICTOOL->getIntValue_json(options, "textColorB"):255;
|
||||
button->setTitleColor(Color3B(cri,cgi,cbi));
|
||||
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
||||
if (fs)
|
||||
{
|
||||
button->setTitleFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
||||
}
|
||||
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
||||
if (fn)
|
||||
{
|
||||
button->setTitleFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__ButtonReader__
|
||||
#define __TestCpp__ButtonReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class ButtonReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
ButtonReader();
|
||||
virtual ~ButtonReader();
|
||||
|
||||
static ButtonReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__ButtonReader__) */
|
|
@ -0,0 +1,153 @@
|
|||
|
||||
|
||||
#include "CheckBoxReader.h"
|
||||
#include "gui/UICheckBox.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static CheckBoxReader* instanceCheckBoxReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(CheckBoxReader)
|
||||
|
||||
CheckBoxReader::CheckBoxReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CheckBoxReader::~CheckBoxReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CheckBoxReader* CheckBoxReader::getInstance()
|
||||
{
|
||||
if (!instanceCheckBoxReader)
|
||||
{
|
||||
instanceCheckBoxReader = new CheckBoxReader();
|
||||
}
|
||||
return instanceCheckBoxReader;
|
||||
}
|
||||
|
||||
void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
CheckBox* checkBox = static_cast<CheckBox*>(widget);
|
||||
|
||||
const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData");
|
||||
int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType");
|
||||
switch (backGroundType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path");
|
||||
const char* backGroundFileName_tp = (backGroundFileName && (strcmp(backGroundFileName, "") != 0))?tp_b.append(backGroundFileName).c_str():nullptr;
|
||||
checkBox->loadTextureBackGround(backGroundFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path");
|
||||
checkBox->loadTextureBackGround(backGroundFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData");
|
||||
int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType");
|
||||
switch (backGroundSelectedType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_bs = jsonPath;
|
||||
const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path");
|
||||
const char* backGroundSelectedFileName_tp = (backGroundSelectedFileName && (strcmp(backGroundSelectedFileName, "") != 0))?tp_bs.append(backGroundSelectedFileName).c_str():nullptr;
|
||||
checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path");
|
||||
checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData");
|
||||
int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType");
|
||||
switch (frontCrossType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_c = jsonPath;
|
||||
const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path");
|
||||
const char* frontCrossFileName_tp = (frontCrossFileName && (strcmp(frontCrossFileName, "") != 0))?tp_c.append(frontCrossFileName).c_str():nullptr;
|
||||
checkBox->loadTextureFrontCross(frontCrossFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path");
|
||||
checkBox->loadTextureFrontCross(frontCrossFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData");
|
||||
int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType");
|
||||
switch (backGroundDisabledType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_bd = jsonPath;
|
||||
const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path");
|
||||
const char* backGroundDisabledFileName_tp = (backGroundDisabledFileName && (strcmp(backGroundDisabledFileName, "") != 0))?tp_bd.append(backGroundDisabledFileName).c_str():nullptr;
|
||||
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path");
|
||||
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData");
|
||||
int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType");
|
||||
switch (frontCrossDisabledType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_cd = jsonPath;
|
||||
const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path");
|
||||
const char* frontCrossDisabledFileName_tp = (frontCrossDisabledFileName && (strcmp(frontCrossDisabledFileName, "") != 0))?tp_cd.append(frontCrossDisabledFileName).c_str():nullptr;
|
||||
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path");
|
||||
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__CheckBoxReader__
|
||||
#define __TestCpp__CheckBoxReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class CheckBoxReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
CheckBoxReader();
|
||||
virtual ~CheckBoxReader();
|
||||
|
||||
static CheckBoxReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__CheckBoxReader__) */
|
|
@ -0,0 +1,98 @@
|
|||
|
||||
|
||||
#include "ImageViewReader.h"
|
||||
#include "gui/UIImageView.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static ImageViewReader* instanceImageViewReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(ImageViewReader)
|
||||
|
||||
ImageViewReader::ImageViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ImageViewReader::~ImageViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ImageViewReader* ImageViewReader::getInstance()
|
||||
{
|
||||
if (!instanceImageViewReader)
|
||||
{
|
||||
instanceImageViewReader = new ImageViewReader();
|
||||
}
|
||||
return instanceImageViewReader;
|
||||
}
|
||||
|
||||
void ImageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
ImageView* imageView = static_cast<ImageView*>(widget);
|
||||
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
|
||||
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileNameType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_i = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = nullptr;
|
||||
if (imageFileName && (strcmp(imageFileName, "") != 0))
|
||||
{
|
||||
imageFileName_tp = tp_i.append(imageFileName).c_str();
|
||||
imageView->loadTexture(imageFileName_tp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable");
|
||||
bool scale9Enable = false;
|
||||
if (scale9EnableExist)
|
||||
{
|
||||
scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
||||
}
|
||||
imageView->setScale9Enabled(scale9Enable);
|
||||
|
||||
|
||||
if (scale9Enable)
|
||||
{
|
||||
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
|
||||
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
|
||||
if (sw && sh)
|
||||
{
|
||||
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
|
||||
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
|
||||
imageView->setSize(Size(swf, shf));
|
||||
}
|
||||
|
||||
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
||||
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
||||
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
||||
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
||||
|
||||
imageView->setCapInsets(Rect(cx, cy, cw, ch));
|
||||
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__ImageViewReader__
|
||||
#define __TestCpp__ImageViewReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class ImageViewReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
ImageViewReader();
|
||||
virtual ~ImageViewReader();
|
||||
|
||||
static ImageViewReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__ImageViewReader__) */
|
|
@ -0,0 +1,119 @@
|
|||
|
||||
|
||||
#include "LayoutReader.h"
|
||||
#include "gui/UILayout.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static LayoutReader* instanceLayoutReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(LayoutReader)
|
||||
|
||||
LayoutReader::LayoutReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LayoutReader::~LayoutReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LayoutReader* LayoutReader::getInstance()
|
||||
{
|
||||
if (!instanceLayoutReader)
|
||||
{
|
||||
instanceLayoutReader = new LayoutReader();
|
||||
}
|
||||
return instanceLayoutReader;
|
||||
}
|
||||
|
||||
void LayoutReader::setPropsFromJsonDictionary(ui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
Layout* panel = static_cast<Layout*>(widget);
|
||||
|
||||
/* adapt screen gui */
|
||||
float w = 0, h = 0;
|
||||
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen");
|
||||
if (adaptScrenn)
|
||||
{
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
w = screenSize.width;
|
||||
h = screenSize.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = DICTOOL->getFloatValue_json(options, "width");
|
||||
h = DICTOOL->getFloatValue_json(options, "height");
|
||||
}
|
||||
panel->setSize(Size(w, h));
|
||||
/**/
|
||||
|
||||
bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable");
|
||||
panel->setBackGroundImageScale9Enabled(backGroundScale9Enable);
|
||||
int cr = DICTOOL->getIntValue_json(options, "bgColorR");
|
||||
int cg = DICTOOL->getIntValue_json(options, "bgColorG");
|
||||
int cb = DICTOOL->getIntValue_json(options, "bgColorB");
|
||||
|
||||
int scr = DICTOOL->getIntValue_json(options, "bgStartColorR");
|
||||
int scg = DICTOOL->getIntValue_json(options, "bgStartColorG");
|
||||
int scb = DICTOOL->getIntValue_json(options, "bgStartColorB");
|
||||
|
||||
int ecr = DICTOOL->getIntValue_json(options, "bgEndColorR");
|
||||
int ecg = DICTOOL->getIntValue_json(options, "bgEndColorG");
|
||||
int ecb = DICTOOL->getIntValue_json(options, "bgEndColorB");
|
||||
|
||||
float bgcv1 = DICTOOL->getFloatValue_json(options, "vectorX");
|
||||
float bgcv2 = DICTOOL->getFloatValue_json(options, "vectorY");
|
||||
panel->setBackGroundColorVector(Point(bgcv1, bgcv2));
|
||||
|
||||
int co = DICTOOL->getIntValue_json(options, "bgColorOpacity");
|
||||
|
||||
int colorType = DICTOOL->getIntValue_json(options, "colorType");
|
||||
panel->setBackGroundColorType(LayoutBackGroundColorType(colorType));
|
||||
panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb));
|
||||
panel->setBackGroundColor(Color3B(cr, cg, cb));
|
||||
panel->setBackGroundColorOpacity(co);
|
||||
|
||||
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData");
|
||||
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileNameType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
||||
panel->setBackGroundImage(imageFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (backGroundScale9Enable)
|
||||
{
|
||||
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
||||
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
||||
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
||||
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
||||
panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch));
|
||||
}
|
||||
panel->setLayoutType((LayoutType)DICTOOL->getIntValue_json(options, "layoutType"));
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__LayoutReader__
|
||||
#define __TestCpp__LayoutReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class LayoutReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
LayoutReader();
|
||||
virtual ~LayoutReader();
|
||||
|
||||
static LayoutReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__LayoutReader__) */
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
|
||||
#include "ListViewReader.h"
|
||||
#include "gui/UIListView.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static ListViewReader* instanceListViewReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(ListViewReader)
|
||||
|
||||
ListViewReader::ListViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ListViewReader::~ListViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ListViewReader* ListViewReader::getInstance()
|
||||
{
|
||||
if (!instanceListViewReader)
|
||||
{
|
||||
instanceListViewReader = new ListViewReader();
|
||||
}
|
||||
return instanceListViewReader;
|
||||
}
|
||||
|
||||
void ListViewReader::setPropsFromJsonDictionary(ui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
ScrollViewReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
ListView* listView = static_cast<ListView*>(widget);
|
||||
|
||||
int direction = DICTOOL->getFloatValue_json(options, "direction");
|
||||
listView->setDirection((SCROLLVIEW_DIR)direction);
|
||||
|
||||
ListViewGravity gravity = (ListViewGravity)DICTOOL->getIntValue_json(options, "gravity");
|
||||
listView->setGravity(gravity);
|
||||
|
||||
float itemMargin = DICTOOL->getFloatValue_json(options, "itemMargin");
|
||||
listView->setItemsMargin(itemMargin);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__ListViewReader__
|
||||
#define __TestCpp__ListViewReader__
|
||||
|
||||
#include "../ScrollViewReader/ScrollViewReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class ListViewReader : public ScrollViewReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
ListViewReader();
|
||||
virtual ~ListViewReader();
|
||||
|
||||
static ListViewReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__ListViewReader__) */
|
|
@ -0,0 +1,91 @@
|
|||
|
||||
|
||||
#include "LoadingBarReader.h"
|
||||
#include "gui/UILoadingBar.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static LoadingBarReader* instanceLoadingBar = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(LoadingBarReader)
|
||||
|
||||
LoadingBarReader::LoadingBarReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LoadingBarReader::~LoadingBarReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LoadingBarReader* LoadingBarReader::getInstance()
|
||||
{
|
||||
if (!instanceLoadingBar)
|
||||
{
|
||||
instanceLoadingBar = new LoadingBarReader();
|
||||
}
|
||||
return instanceLoadingBar;
|
||||
}
|
||||
|
||||
void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
|
||||
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData");
|
||||
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileNameType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_i = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = nullptr;
|
||||
if (imageFileName && (strcmp(imageFileName, "") != 0))
|
||||
{
|
||||
imageFileName_tp = tp_i.append(imageFileName).c_str();
|
||||
loadingBar->loadTexture(imageFileName_tp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
loadingBar->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* gui mark add load bar scale9 parse */
|
||||
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
||||
loadingBar->setScale9Enabled(scale9Enable);
|
||||
|
||||
if (scale9Enable)
|
||||
{
|
||||
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
||||
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
||||
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
||||
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
||||
|
||||
loadingBar->setCapInsets(Rect(cx, cy, cw, ch));
|
||||
|
||||
float width = DICTOOL->getFloatValue_json(options, "width");
|
||||
float height = DICTOOL->getFloatValue_json(options, "height");
|
||||
loadingBar->setSize(Size(width, height));
|
||||
}
|
||||
/**/
|
||||
|
||||
loadingBar->setDirection(LoadingBarType(DICTOOL->getIntValue_json(options, "direction")));
|
||||
loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent"));
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__LoadingBarReader__
|
||||
#define __TestCpp__LoadingBarReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class LoadingBarReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
LoadingBarReader();
|
||||
virtual ~LoadingBarReader();
|
||||
|
||||
static LoadingBarReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__LoadingBarReader__) */
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
|
||||
#include "PageViewReader.h"
|
||||
#include "gui/UIPageView.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static PageViewReader* instancePageViewReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(PageViewReader)
|
||||
|
||||
PageViewReader::PageViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PageViewReader::~PageViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PageViewReader* PageViewReader::getInstance()
|
||||
{
|
||||
if (!instancePageViewReader)
|
||||
{
|
||||
instancePageViewReader = new PageViewReader();
|
||||
}
|
||||
return instancePageViewReader;
|
||||
}
|
||||
|
||||
void PageViewReader::setPropsFromJsonDictionary(ui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
LayoutReader::setPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__PageViewReader__
|
||||
#define __TestCpp__PageViewReader__
|
||||
|
||||
#include "../LayoutReader/LayoutReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class PageViewReader : public LayoutReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
PageViewReader();
|
||||
virtual ~PageViewReader();
|
||||
|
||||
static PageViewReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(ui::Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__PageViewReader__) */
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
|
||||
#include "ScrollViewReader.h"
|
||||
#include "gui/UIScrollView.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static ScrollViewReader* instanceScrollViewReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(ScrollViewReader)
|
||||
|
||||
ScrollViewReader::ScrollViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ScrollViewReader::~ScrollViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ScrollViewReader* ScrollViewReader::getInstance()
|
||||
{
|
||||
if (!instanceScrollViewReader)
|
||||
{
|
||||
instanceScrollViewReader = new ScrollViewReader();
|
||||
}
|
||||
return instanceScrollViewReader;
|
||||
}
|
||||
|
||||
void ScrollViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
LayoutReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
ScrollView* scrollView = static_cast<ScrollView*>(widget);
|
||||
float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth");
|
||||
float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight");
|
||||
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
||||
int direction = DICTOOL->getFloatValue_json(options, "direction");
|
||||
scrollView->setDirection((SCROLLVIEW_DIR)direction);
|
||||
scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, "bounceEnable"));
|
||||
|
||||
|
||||
LayoutReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__ScrollViewReader__
|
||||
#define __TestCpp__ScrollViewReader__
|
||||
|
||||
#include "../LayoutReader/LayoutReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class ScrollViewReader : public LayoutReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
ScrollViewReader();
|
||||
virtual ~ScrollViewReader();
|
||||
|
||||
static ScrollViewReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__ScrollViewReader__) */
|
|
@ -0,0 +1,192 @@
|
|||
|
||||
|
||||
#include "SliderReader.h"
|
||||
#include "gui/UISlider.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static SliderReader* instanceSliderReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(SliderReader)
|
||||
|
||||
SliderReader::SliderReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SliderReader::~SliderReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SliderReader* SliderReader::getInstance()
|
||||
{
|
||||
if (!instanceSliderReader)
|
||||
{
|
||||
instanceSliderReader = new SliderReader();
|
||||
}
|
||||
return instanceSliderReader;
|
||||
}
|
||||
|
||||
void SliderReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
Slider* slider = static_cast<Slider*>(widget);
|
||||
|
||||
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "barTextureScale9Enable");
|
||||
slider->setScale9Enabled(barTextureScale9Enable);
|
||||
bool bt = DICTOOL->checkObjectExist_json(options, "barFileName");
|
||||
float barLength = DICTOOL->getFloatValue_json(options, "length");
|
||||
if (bt)
|
||||
{
|
||||
if (barTextureScale9Enable)
|
||||
{
|
||||
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
|
||||
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
||||
slider->loadBarTexture(imageFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
slider->setSize(Size(barLength, slider->getContentSize().height));
|
||||
}
|
||||
else
|
||||
{
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
|
||||
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
||||
slider->loadBarTexture(imageFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData");
|
||||
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
|
||||
switch (normalType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_n = jsonPath;
|
||||
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
||||
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
|
||||
slider->loadSlidBallTextureNormal(normalFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
||||
slider->loadSlidBallTextureNormal(normalFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData");
|
||||
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
|
||||
switch (pressedType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_p = jsonPath;
|
||||
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
||||
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
|
||||
slider->loadSlidBallTexturePressed(pressedFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
||||
slider->loadSlidBallTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData");
|
||||
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
|
||||
switch (disabledType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_d = jsonPath;
|
||||
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
||||
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
|
||||
slider->loadSlidBallTextureDisabled(disabledFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
||||
slider->loadSlidBallTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
|
||||
|
||||
const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData");
|
||||
int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType");
|
||||
switch (progressBarType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
|
||||
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
||||
slider->loadProgressBarTexture(imageFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
|
||||
slider->loadProgressBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__SliderReader__
|
||||
#define __TestCpp__SliderReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class SliderReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
SliderReader();
|
||||
virtual ~SliderReader();
|
||||
|
||||
static SliderReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__SliderReader__) */
|
|
@ -0,0 +1,69 @@
|
|||
|
||||
|
||||
#include "TextAtlasReader.h"
|
||||
#include "gui/UITextAtlas.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static TextAtlasReader* instanceTextAtalsReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextAtlasReader)
|
||||
|
||||
TextAtlasReader::TextAtlasReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextAtlasReader::~TextAtlasReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextAtlasReader* TextAtlasReader::getInstance()
|
||||
{
|
||||
if (!instanceTextAtalsReader)
|
||||
{
|
||||
instanceTextAtalsReader = new TextAtlasReader();
|
||||
}
|
||||
return instanceTextAtalsReader;
|
||||
}
|
||||
|
||||
void TextAtlasReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget);
|
||||
bool sv = DICTOOL->checkObjectExist_json(options, "stringValue");
|
||||
bool cmf = DICTOOL->checkObjectExist_json(options, "charMapFile");
|
||||
bool iw = DICTOOL->checkObjectExist_json(options, "itemWidth");
|
||||
bool ih = DICTOOL->checkObjectExist_json(options, "itemHeight");
|
||||
bool scm = DICTOOL->checkObjectExist_json(options, "startCharMap");
|
||||
if (sv && cmf && iw && ih && scm)
|
||||
{
|
||||
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "charMapFileData");
|
||||
int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType");
|
||||
switch (cmfType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_c = jsonPath;
|
||||
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
|
||||
const char* cmf_tp = tp_c.append(cmfPath).c_str();
|
||||
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"), DICTOOL->getStringValue_json(options, "startCharMap"));
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
CCLOG("Wrong res type of LabelAtlas!");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__TextAtlasReader__
|
||||
#define __TestCpp__TextAtlasReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class TextAtlasReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
TextAtlasReader();
|
||||
virtual ~TextAtlasReader();
|
||||
|
||||
static TextAtlasReader* getInstance();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__TextAtlasReader__) */
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
|
||||
#include "TextBMFontReader.h"
|
||||
#include "gui/UITextBMFont.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static TextBMFontReader* instanceTextBMFontReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextBMFontReader)
|
||||
|
||||
TextBMFontReader::TextBMFontReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextBMFontReader::~TextBMFontReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextBMFontReader* TextBMFontReader::getInstance()
|
||||
{
|
||||
if (!instanceTextBMFontReader)
|
||||
{
|
||||
instanceTextBMFontReader = new TextBMFontReader();
|
||||
}
|
||||
return instanceTextBMFontReader;
|
||||
}
|
||||
|
||||
void TextBMFontReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget);
|
||||
|
||||
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
|
||||
int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType");
|
||||
switch (cmfType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_c = jsonPath;
|
||||
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
|
||||
const char* cmf_tp = tp_c.append(cmfPath).c_str();
|
||||
labelBMFont->setFntFile(cmf_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
CCLOG("Wrong res type of LabelAtlas!");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const char* text = DICTOOL->getStringValue_json(options, "text");
|
||||
labelBMFont->setText(text);
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__TextBMFontReader__
|
||||
#define __TestCpp__TextBMFontReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class TextBMFontReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
TextBMFontReader();
|
||||
virtual ~TextBMFontReader();
|
||||
|
||||
static TextBMFontReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__TextBMFontReader__) */
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
|
||||
#include "TextFieldReader.h"
|
||||
#include "gui/UITextField.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static TextFieldReader* instanceTextFieldReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextFieldReader)
|
||||
|
||||
TextFieldReader::TextFieldReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextFieldReader::~TextFieldReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextFieldReader* TextFieldReader::getInstance()
|
||||
{
|
||||
if (!instanceTextFieldReader)
|
||||
{
|
||||
instanceTextFieldReader = new TextFieldReader();
|
||||
}
|
||||
return instanceTextFieldReader;
|
||||
}
|
||||
|
||||
void TextFieldReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
cocos2d::ui::TextField* textField = static_cast<cocos2d::ui::TextField*>(widget);
|
||||
bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder");
|
||||
if (ph)
|
||||
{
|
||||
textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder"));
|
||||
}
|
||||
textField->setText(DICTOOL->getStringValue_json(options, "text"));
|
||||
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
||||
if (fs)
|
||||
{
|
||||
textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
||||
}
|
||||
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
||||
if (fn)
|
||||
{
|
||||
textField->setFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
||||
}
|
||||
bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth");
|
||||
bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight");
|
||||
if (tsw && tsh)
|
||||
{
|
||||
textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), DICTOOL->getFloatValue_json(options,"touchSizeHeight")));
|
||||
}
|
||||
|
||||
float dw = DICTOOL->getFloatValue_json(options, "width");
|
||||
float dh = DICTOOL->getFloatValue_json(options, "height");
|
||||
if (dw > 0.0f || dh > 0.0f)
|
||||
{
|
||||
//textField->setSize(Size(dw, dh));
|
||||
}
|
||||
bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable");
|
||||
textField->setMaxLengthEnabled(maxLengthEnable);
|
||||
|
||||
if (maxLengthEnable)
|
||||
{
|
||||
int maxLength = DICTOOL->getIntValue_json(options, "maxLength");
|
||||
textField->setMaxLength(maxLength);
|
||||
}
|
||||
bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable");
|
||||
textField->setPasswordEnabled(passwordEnable);
|
||||
if (passwordEnable)
|
||||
{
|
||||
textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText"));
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__TextFieldReader__
|
||||
#define __TestCpp__TextFieldReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class TextFieldReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
TextFieldReader();
|
||||
virtual ~TextFieldReader();
|
||||
|
||||
static TextFieldReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__TextFieldReader__) */
|
|
@ -0,0 +1,74 @@
|
|||
|
||||
|
||||
#include "TextReader.h"
|
||||
#include "gui/UIText.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static TextReader* instanceTextReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextReader)
|
||||
|
||||
TextReader::TextReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextReader::~TextReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextReader* TextReader::getInstance()
|
||||
{
|
||||
if (!instanceTextReader)
|
||||
{
|
||||
instanceTextReader = new TextReader();
|
||||
}
|
||||
return instanceTextReader;
|
||||
}
|
||||
|
||||
void TextReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
Text* label = static_cast<Text*>(widget);
|
||||
bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable");
|
||||
label->setTouchScaleChangeEnabled(touchScaleChangeAble);
|
||||
const char* text = DICTOOL->getStringValue_json(options, "text");
|
||||
label->setText(text);
|
||||
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
||||
if (fs)
|
||||
{
|
||||
label->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
||||
}
|
||||
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
||||
if (fn)
|
||||
{
|
||||
label->setFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
||||
}
|
||||
bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth");
|
||||
bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight");
|
||||
if (aw && ah)
|
||||
{
|
||||
Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight"));
|
||||
label->setTextAreaSize(size);
|
||||
}
|
||||
bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment");
|
||||
if (ha)
|
||||
{
|
||||
label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, "hAlignment"));
|
||||
}
|
||||
bool va = DICTOOL->checkObjectExist_json(options, "vAlignment");
|
||||
if (va)
|
||||
{
|
||||
label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, "vAlignment"));
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__TextReader__
|
||||
#define __TestCpp__TextReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class TextReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
TextReader();
|
||||
virtual ~TextReader();
|
||||
|
||||
static TextReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__TextReader__) */
|
|
@ -0,0 +1,172 @@
|
|||
|
||||
|
||||
#include "WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static WidgetReader* instanceWidgetReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(WidgetReader)
|
||||
|
||||
WidgetReader::WidgetReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
WidgetReader::~WidgetReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
WidgetReader* WidgetReader::getInstance()
|
||||
{
|
||||
if (!instanceWidgetReader)
|
||||
{
|
||||
instanceWidgetReader = new WidgetReader();
|
||||
}
|
||||
return instanceWidgetReader;
|
||||
}
|
||||
|
||||
void WidgetReader::purge()
|
||||
{
|
||||
CC_SAFE_DELETE(instanceWidgetReader);
|
||||
}
|
||||
|
||||
void WidgetReader::setPropsFromJsonDictionary(cocos2d::ui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize");
|
||||
if (ignoreSizeExsit)
|
||||
{
|
||||
widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize"));
|
||||
}
|
||||
|
||||
widget->setSizeType((SizeType)DICTOOL->getIntValue_json(options, "sizeType"));
|
||||
widget->setPositionType((PositionType)DICTOOL->getIntValue_json(options, "positionType"));
|
||||
|
||||
widget->setSizePercent(Point(DICTOOL->getFloatValue_json(options, "sizePercentX"), DICTOOL->getFloatValue_json(options, "sizePercentY")));
|
||||
widget->setPositionPercent(Point(DICTOOL->getFloatValue_json(options, "positionPercentX"), DICTOOL->getFloatValue_json(options, "positionPercentY")));
|
||||
|
||||
/* adapt screen */
|
||||
float w = 0, h = 0;
|
||||
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen");
|
||||
if (adaptScrenn)
|
||||
{
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
w = screenSize.width;
|
||||
h = screenSize.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = DICTOOL->getFloatValue_json(options, "width");
|
||||
h = DICTOOL->getFloatValue_json(options, "height");
|
||||
}
|
||||
widget->setSize(Size(w, h));
|
||||
// before
|
||||
/*
|
||||
float w = DICTOOL->getFloatValue_json(options, "width");
|
||||
float h = DICTOOL->getFloatValue_json(options, "height");
|
||||
widget->setSize(CCSizeMake(w, h));
|
||||
*/
|
||||
/**/
|
||||
|
||||
widget->setTag(DICTOOL->getIntValue_json(options, "tag"));
|
||||
widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag"));
|
||||
widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, "touchAble"));
|
||||
const char* name = DICTOOL->getStringValue_json(options, "name");
|
||||
const char* widgetName = name?name:"default";
|
||||
widget->setName(widgetName);
|
||||
float x = DICTOOL->getFloatValue_json(options, "x");
|
||||
float y = DICTOOL->getFloatValue_json(options, "y");
|
||||
widget->setPosition(Point(x,y));
|
||||
bool sx = DICTOOL->checkObjectExist_json(options, "scaleX");
|
||||
if (sx)
|
||||
{
|
||||
widget->setScaleX(DICTOOL->getFloatValue_json(options, "scaleX"));
|
||||
}
|
||||
bool sy = DICTOOL->checkObjectExist_json(options, "scaleY");
|
||||
if (sy)
|
||||
{
|
||||
widget->setScaleY(DICTOOL->getFloatValue_json(options, "scaleY"));
|
||||
}
|
||||
bool rt = DICTOOL->checkObjectExist_json(options, "rotation");
|
||||
if (rt)
|
||||
{
|
||||
widget->setRotation(DICTOOL->getFloatValue_json(options, "rotation"));
|
||||
}
|
||||
bool vb = DICTOOL->checkObjectExist_json(options, "visible");
|
||||
if (vb)
|
||||
{
|
||||
widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible"));
|
||||
}
|
||||
int z = DICTOOL->getIntValue_json(options, "ZOrder");
|
||||
widget->setLocalZOrder(z);
|
||||
|
||||
bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter");
|
||||
if (layout)
|
||||
{
|
||||
const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, "layoutParameter");
|
||||
int paramType = DICTOOL->getIntValue_json(layoutParameterDic, "type");
|
||||
LayoutParameter* parameter = nullptr;
|
||||
switch (paramType)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
parameter = LinearLayoutParameter::create();
|
||||
int gravity = DICTOOL->getIntValue_json(layoutParameterDic, "gravity");
|
||||
((LinearLayoutParameter*)parameter)->setGravity((LinearGravity)gravity);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
parameter = RelativeLayoutParameter::create();
|
||||
RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter;
|
||||
const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeName");
|
||||
rParameter->setRelativeName(relativeName);
|
||||
const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeToName");
|
||||
rParameter->setRelativeToWidgetName(relativeToName);
|
||||
int align = DICTOOL->getIntValue_json(layoutParameterDic, "align");
|
||||
rParameter->setAlign((RelativeAlign)align);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (parameter)
|
||||
{
|
||||
float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, "marginLeft");
|
||||
float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, "marginTop");
|
||||
float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, "marginRight");
|
||||
float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, "marginDown");
|
||||
parameter->setMargin(Margin(mgl, mgt, mgr, mgb));
|
||||
widget->setLayoutParameter(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetReader::setColorPropsFromJsonDictionary(ui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
bool op = DICTOOL->checkObjectExist_json(options, "opacity");
|
||||
if (op)
|
||||
{
|
||||
widget->setOpacity(DICTOOL->getIntValue_json(options, "opacity"));
|
||||
}
|
||||
bool cr = DICTOOL->checkObjectExist_json(options, "colorR");
|
||||
bool cg = DICTOOL->checkObjectExist_json(options, "colorG");
|
||||
bool cb = DICTOOL->checkObjectExist_json(options, "colorB");
|
||||
int colorR = cr ? DICTOOL->getIntValue_json(options, "colorR") : 255;
|
||||
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
|
||||
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
|
||||
widget->setColor(Color3B(colorR, colorG, colorB));
|
||||
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
|
||||
float apxf = apx ? DICTOOL->getFloatValue_json(options, "anchorPointX") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f);
|
||||
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
|
||||
float apyf = apy ? DICTOOL->getFloatValue_json(options, "anchorPointY") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f);
|
||||
widget->setAnchorPoint(Point(apxf, apyf));
|
||||
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
|
||||
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
|
||||
widget->setFlipX(flipX);
|
||||
widget->setFlipY(flipY);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__WidgetReader__
|
||||
#define __TestCpp__WidgetReader__
|
||||
|
||||
#include "WidgetReaderProtocol.h"
|
||||
#include "../CCSGUIReader.h"
|
||||
#include "gui/GUIDefine.h"
|
||||
#include "gui/UIWidget.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class WidgetReader : public Ref, public WidgetReaderProtocol
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
WidgetReader();
|
||||
virtual ~WidgetReader();
|
||||
|
||||
static WidgetReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
virtual void setColorPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__WidgetReader__) */
|
|
@ -0,0 +1,53 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__WidgetReaderProtocol__
|
||||
#define __TestCpp__WidgetReaderProtocol__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocostudio/DictionaryHelper.h"
|
||||
|
||||
namespace cocos2d
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
class Widget;
|
||||
}
|
||||
}
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace ui;
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class WidgetReaderProtocol
|
||||
{
|
||||
public:
|
||||
virtual ~WidgetReaderProtocol() {};
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__WidgetReaderProtocol__) */
|
|
@ -0,0 +1,79 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__GUIDefine__
|
||||
#define __TestCpp__GUIDefine__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "ExtensionMacros.h"
|
||||
#include <string>
|
||||
#include "cocostudio/ObjectFactory.h"
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Widget macro
|
||||
#pragma mark -
|
||||
|
||||
#define DECLARE_CLASS_GUI_INFO \
|
||||
public: \
|
||||
static cocostudio::ObjectFactory::TInfo Type; \
|
||||
static cocos2d::Ref* createInstance(void); \
|
||||
|
||||
#define IMPLEMENT_CLASS_GUI_INFO(className) \
|
||||
cocos2d::Ref* className::createInstance(void) \
|
||||
{ \
|
||||
return className::create(); \
|
||||
} \
|
||||
cocostudio::ObjectFactory::TInfo className::Type(#className, &className::createInstance); \
|
||||
|
||||
#define CREATE_CLASS_GUI_INFO(className) \
|
||||
cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Reader macro
|
||||
#pragma mark -
|
||||
|
||||
#define DECLARE_CLASS_WIDGET_READER_INFO \
|
||||
public: \
|
||||
static cocostudio::ObjectFactory::TInfo Type; \
|
||||
static cocos2d::Ref* createInstance(void); \
|
||||
|
||||
#define IMPLEMENT_CLASS_WIDGET_READER_INFO(className) \
|
||||
cocos2d::Ref* className::createInstance(void) \
|
||||
{ \
|
||||
return className::getInstance(); \
|
||||
} \
|
||||
cocostudio::ObjectFactory::TInfo className::Type(#className, &className::createInstance); \
|
||||
|
||||
#define CREATE_CLASS_WIDGET_READER_INFO(className) \
|
||||
cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//#define CUSTOM_GUI_PARSE_FUNCTION(className, functionName) \
|
||||
// className::functionName \
|
||||
|
||||
#endif /* defined(__TestCpp__GUIDefine__) */
|
|
@ -34,6 +34,8 @@ static const int PRESSED_RENDERER_Z = (-2);
|
|||
static const int DISABLED_RENDERER_Z = (-2);
|
||||
static const int TITLE_RENDERER_Z = (-1);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(Button)
|
||||
|
||||
Button::Button():
|
||||
_buttonNormalRenderer(nullptr),
|
||||
_buttonClickedRenderer(nullptr),
|
||||
|
|
|
@ -37,6 +37,9 @@ namespace ui{
|
|||
*/
|
||||
class Button : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -33,6 +33,8 @@ static const int BACKGROUNDSELECTEDBOX_RENDERER_Z = (-1);
|
|||
static const int FRONTCROSS_RENDERER_Z = (-1);
|
||||
static const int BACKGROUNDBOXDISABLED_RENDERER_Z = (-1);
|
||||
static const int FRONTCROSSDISABLED_RENDERER_Z = (-1);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(CheckBox)
|
||||
|
||||
CheckBox::CheckBox():
|
||||
_backGroundBoxRenderer(nullptr),
|
||||
|
|
|
@ -46,6 +46,9 @@ typedef void (Ref::*SEL_SelectedStateEvent)(Ref*,CheckBoxEventType);
|
|||
*/
|
||||
class CheckBox : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -34,6 +34,8 @@ namespace ui {
|
|||
#define STATIC_CAST_SCALE9SPRITE static_cast<extension::Scale9Sprite*>(_imageRenderer)
|
||||
|
||||
static const int IMAGE_RENDERER_Z = (-1);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(ImageView)
|
||||
|
||||
ImageView::ImageView():
|
||||
_scale9Enabled(false),
|
||||
|
|
|
@ -37,6 +37,9 @@ namespace ui {
|
|||
*/
|
||||
class ImageView : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -43,6 +43,8 @@ static const int BCAKGROUNDCOLORRENDERER_Z = (-2);
|
|||
|
||||
static GLint g_sStencilBits = -1;
|
||||
static GLint s_layer = -1;
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(Layout)
|
||||
|
||||
Layout::Layout():
|
||||
_clippingEnabled(false),
|
||||
|
|
|
@ -57,6 +57,9 @@ typedef enum {
|
|||
*/
|
||||
class Layout : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -29,6 +29,8 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN
|
||||
|
||||
namespace ui {
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(ListView)
|
||||
|
||||
ListView::ListView():
|
||||
_model(nullptr),
|
||||
|
|
|
@ -53,6 +53,8 @@ typedef void (Ref::*SEL_ListViewEvent)(Ref*,ListViewEventType);
|
|||
|
||||
class ListView : public ScrollView
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ namespace ui {
|
|||
|
||||
static const int BAR_RENDERER_Z = (-1);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(LoadingBar)
|
||||
|
||||
LoadingBar::LoadingBar():
|
||||
_barType(LoadingBarTypeLeft),
|
||||
_percent(100),
|
||||
|
|
|
@ -42,6 +42,9 @@ typedef enum
|
|||
*/
|
||||
class LoadingBar : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -27,6 +27,8 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN
|
||||
|
||||
namespace ui {
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(PageView)
|
||||
|
||||
PageView::PageView():
|
||||
_curPageIdx(0),
|
||||
|
|
|
@ -48,6 +48,8 @@ typedef enum {
|
|||
class PageView : public Layout , public UIScrollInterface
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -34,6 +34,8 @@ const Point SCROLLDIR_UP = Point(0.0f, 1.0f);
|
|||
const Point SCROLLDIR_DOWN = Point(0.0f, -1.0f);
|
||||
const Point SCROLLDIR_LEFT = Point(-1.0f, 0.0f);
|
||||
const Point SCROLLDIR_RIGHT = Point(1.0f, 0.0f);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(ScrollView)
|
||||
|
||||
ScrollView::ScrollView():
|
||||
_innerContainer(nullptr),
|
||||
|
|
|
@ -59,6 +59,9 @@ typedef void (Ref::*SEL_ScrollViewEvent)(Ref*, ScrollviewEventType);
|
|||
|
||||
class ScrollView : public Layout , public UIScrollInterface
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -33,6 +33,8 @@ static const int BASEBAR_RENDERER_Z = (-2);
|
|||
static const int PROGRESSBAR_RENDERER_Z = (-2);
|
||||
static const int SLIDBALL_RENDERER_Z = (-1);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(Slider)
|
||||
|
||||
Slider::Slider():
|
||||
_barRenderer(nullptr),
|
||||
_progressBarRenderer(nullptr),
|
||||
|
@ -134,6 +136,7 @@ void Slider::loadBarTexture(const char* fileName, TextureResType texType)
|
|||
}
|
||||
updateRGBAToRenderer(_barRenderer);
|
||||
barRendererScaleChangedWithSize();
|
||||
progressBarRendererScaleChangedWithSize();
|
||||
}
|
||||
|
||||
void Slider::loadProgressBarTexture(const char *fileName, TextureResType texType)
|
||||
|
@ -488,6 +491,7 @@ void Slider::progressBarRendererScaleChangedWithSize()
|
|||
if (_scale9Enabled)
|
||||
{
|
||||
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(_size);
|
||||
_progressBarTextureSize = _progressBarRenderer->getContentSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -45,6 +45,9 @@ typedef void (Ref::*SEL_SlidPercentChangedEvent)(Ref*,SliderEventType);
|
|||
*/
|
||||
class Slider : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -29,6 +29,8 @@ NS_CC_BEGIN
|
|||
namespace ui {
|
||||
|
||||
static const int LABEL_RENDERER_Z = (-1);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(Text)
|
||||
|
||||
Text::Text():
|
||||
_touchScaleChangeEnabled(false),
|
||||
|
|
|
@ -37,6 +37,9 @@ namespace ui {
|
|||
*/
|
||||
class Text : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -29,6 +29,8 @@ NS_CC_BEGIN
|
|||
namespace ui {
|
||||
|
||||
static const int LABELATLAS_RENDERER_Z = (-1);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(TextAtlas)
|
||||
|
||||
TextAtlas::TextAtlas():
|
||||
_labelAtlasRenderer(nullptr),
|
||||
|
|
|
@ -37,6 +37,9 @@ namespace ui {
|
|||
*/
|
||||
class TextAtlas : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -30,6 +30,8 @@ namespace ui {
|
|||
|
||||
static const int LABELBMFONT_RENDERER_Z = (-1);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(TextBMFont)
|
||||
|
||||
TextBMFont::TextBMFont():
|
||||
_labelBMFontRenderer(nullptr),
|
||||
_fntFileHasInit(false),
|
||||
|
|
|
@ -37,6 +37,9 @@ namespace ui {
|
|||
*/
|
||||
class TextBMFont : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
|
|
@ -27,6 +27,23 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN
|
||||
|
||||
namespace ui {
|
||||
|
||||
static int _calcCharCount(const char * pszText)
|
||||
{
|
||||
int n = 0;
|
||||
char ch = 0;
|
||||
while ((ch = *pszText))
|
||||
{
|
||||
CC_BREAK_IF(! ch);
|
||||
|
||||
if (0x80 != (0xC0 & ch))
|
||||
{
|
||||
++n;
|
||||
}
|
||||
++pszText;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
UICCTextField::UICCTextField()
|
||||
: _maxLengthEnabled(false)
|
||||
|
@ -106,42 +123,95 @@ bool UICCTextField::onTextFieldDetachWithIME(TextFieldTTF *pSender)
|
|||
|
||||
void UICCTextField::insertText(const char * text, int len)
|
||||
{
|
||||
std::string str_text = text;
|
||||
ssize_t str_len = TextFieldTTF::getString().size();
|
||||
std::string input_text = text;
|
||||
|
||||
if (strcmp(text, "\n") != 0)
|
||||
{
|
||||
if (_maxLengthEnabled)
|
||||
{
|
||||
int multiple = 1;
|
||||
char value = text[0];
|
||||
if (value < 0 || value > 127)
|
||||
int text_count = _calcCharCount(getString().c_str());
|
||||
if (text_count >= _maxLength)
|
||||
{
|
||||
multiple = 3;
|
||||
// password
|
||||
if (_passwordEnabled)
|
||||
{
|
||||
setPasswordText(getString().c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_len + len > _maxLength * multiple)
|
||||
#if ((CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32))
|
||||
int input_count = _calcCharCount(text);
|
||||
int total = total = text_count + input_count;
|
||||
|
||||
if (total > _maxLength)
|
||||
{
|
||||
str_text = str_text.substr(0, _maxLength * multiple);
|
||||
len = _maxLength * multiple;
|
||||
/*
|
||||
int mod = str_len % 3;
|
||||
int offset = (mod == 0) ? 0 : (3 - mod);
|
||||
int amount = str_len + offset;
|
||||
str_text = str_text.substr(0, _maxLength - amount);
|
||||
// CCLOG("str_test = %s", str_text.c_str());
|
||||
*/
|
||||
int end = 0;
|
||||
int length = _maxLength - text_count;
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
char value = text[i];
|
||||
|
||||
if (value >= 0 && value <= 127) // ascii
|
||||
{
|
||||
end++;
|
||||
}
|
||||
else
|
||||
{
|
||||
end += 3;
|
||||
}
|
||||
}
|
||||
input_text = input_text.substr(0, end);
|
||||
len = end;
|
||||
}
|
||||
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
int input_count = _calcCharCount(text);
|
||||
if (input_count > _maxLength)
|
||||
{
|
||||
int ascii = 0;
|
||||
int unicode = 0;
|
||||
int end = 0;
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < input_count * 3; ++i)
|
||||
{
|
||||
char value = text[i];
|
||||
|
||||
if (value >= 0 && value <= 127) // ascii
|
||||
{
|
||||
ascii++;
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
unicode++;
|
||||
if (unicode % 3 == 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == _maxLength)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
end = ascii + unicode;
|
||||
input_text = input_text.substr(0, end);
|
||||
len = end;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
TextFieldTTF::insertText(str_text.c_str(), len);
|
||||
TextFieldTTF::insertText(input_text.c_str(), len);
|
||||
|
||||
// password
|
||||
if (_passwordEnabled)
|
||||
{
|
||||
if (TextFieldTTF::getCharCount() > 0)
|
||||
{
|
||||
setPasswordText(_inputText.c_str());
|
||||
setPasswordText(getString().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -271,6 +341,8 @@ bool UICCTextField::getDeleteBackward()
|
|||
|
||||
static const int TEXTFIELD_RENDERER_Z = (-1);
|
||||
|
||||
IMPLEMENT_CLASS_GUI_INFO(TextField)
|
||||
|
||||
|
||||
TextField::TextField():
|
||||
_textFieldRenderer(nullptr),
|
||||
|
@ -315,11 +387,35 @@ void TextField::initRenderer()
|
|||
|
||||
void TextField::setTouchSize(const Size &size)
|
||||
{
|
||||
_useTouchArea = true;
|
||||
// _useTouchArea = true;
|
||||
_touchWidth = size.width;
|
||||
_touchHeight = size.height;
|
||||
}
|
||||
|
||||
void TextField::setTouchAreaEnabled(bool enable)
|
||||
{
|
||||
_useTouchArea = enable;
|
||||
}
|
||||
|
||||
bool TextField::hitTest(const Point &pt)
|
||||
{
|
||||
if (_useTouchArea)
|
||||
{
|
||||
Point nsp = convertToNodeSpace(pt);
|
||||
Rect bb = Rect(-_touchWidth * _anchorPoint.x, -_touchHeight * _anchorPoint.y, _touchWidth, _touchHeight);
|
||||
if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Widget::hitTest(pt);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Size TextField::getTouchSize()
|
||||
{
|
||||
return Size(_touchWidth, _touchHeight);
|
||||
|
@ -336,6 +432,7 @@ void TextField::setText(const std::string& text)
|
|||
if (isPasswordEnabled())
|
||||
{
|
||||
_textFieldRenderer->setPasswordText(content);
|
||||
_textFieldRenderer->setString("");
|
||||
_textFieldRenderer->insertText(content, static_cast<int>(strlen(content)));
|
||||
}
|
||||
else
|
||||
|
@ -411,6 +508,8 @@ bool TextField::isMaxLengthEnabled()
|
|||
void TextField::setMaxLength(int length)
|
||||
{
|
||||
_textFieldRenderer->setMaxLength(length);
|
||||
|
||||
setText(getStringValue());
|
||||
}
|
||||
|
||||
int TextField::getMaxLength()
|
||||
|
@ -433,6 +532,8 @@ void TextField::setPasswordStyleText(const char *styleText)
|
|||
_textFieldRenderer->setPasswordStyleText(styleText);
|
||||
|
||||
_passwordStyleText = styleText;
|
||||
|
||||
setText(getStringValue());
|
||||
}
|
||||
|
||||
const char* TextField::getPasswordStyleText()
|
||||
|
@ -463,6 +564,8 @@ void TextField::update(float dt)
|
|||
{
|
||||
deleteBackwardEvent();
|
||||
setDeleteBackward(false);
|
||||
|
||||
textfieldRendererScaleChangedWithSize();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -637,6 +740,21 @@ void TextField::copySpecialProperties(Widget *widget)
|
|||
setDeleteBackward(textField->getDeleteBackward());
|
||||
}
|
||||
}
|
||||
|
||||
void TextField::setTextAreaSize(const Size &size)
|
||||
{
|
||||
_textFieldRenderer->setDimensions(size);
|
||||
}
|
||||
|
||||
void TextField::setTextHorizontalAlignment(TextHAlignment alignment)
|
||||
{
|
||||
_textFieldRenderer->setHorizontalAlignment(alignment);
|
||||
}
|
||||
|
||||
void TextField::setTextVerticalAlignment(TextVAlignment alignment)
|
||||
{
|
||||
_textFieldRenderer->setVerticalAlignment(alignment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -103,12 +103,17 @@ typedef void (Ref::*SEL_TextFieldEvent)(Ref*, TextFiledEventType);
|
|||
*/
|
||||
class TextField : public Widget
|
||||
{
|
||||
|
||||
DECLARE_CLASS_GUI_INFO
|
||||
|
||||
public:
|
||||
TextField();
|
||||
virtual ~TextField();
|
||||
static TextField* create();
|
||||
void setTouchSize(const Size &size);
|
||||
Size getTouchSize();
|
||||
void setTouchAreaEnabled(bool enable);
|
||||
virtual bool hitTest(const Point &pt);
|
||||
void setText(const std::string& text);
|
||||
void setPlaceHolder(const std::string& value);
|
||||
const std::string& getPlaceHolder();
|
||||
|
@ -149,6 +154,10 @@ public:
|
|||
virtual Node* getVirtualRenderer() override;
|
||||
void attachWithIME();
|
||||
virtual void onEnter() override;
|
||||
|
||||
void setTextAreaSize(const Size &size);
|
||||
void setTextHorizontalAlignment(TextHAlignment alignment);
|
||||
void setTextVerticalAlignment(TextVAlignment alignment);
|
||||
protected:
|
||||
// event
|
||||
virtual void initRenderer() override;
|
||||
|
|
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
|||
#include "CCNode.h"
|
||||
#include "gui/UILayoutDefine.h"
|
||||
#include "gui/UILayoutParameter.h"
|
||||
#include "gui/GUIDefine.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
|
||||
|
||||
#include "ButtonReader.h"
|
||||
#include "gui/UIButton.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static ButtonReader* instanceButtonReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(ButtonReader)
|
||||
|
||||
ButtonReader::ButtonReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ButtonReader::~ButtonReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ButtonReader* ButtonReader::getInstance()
|
||||
{
|
||||
if (!instanceButtonReader)
|
||||
{
|
||||
instanceButtonReader = new ButtonReader();
|
||||
}
|
||||
return instanceButtonReader;
|
||||
}
|
||||
|
||||
void ButtonReader::purge()
|
||||
{
|
||||
CC_SAFE_DELETE(instanceButtonReader);
|
||||
}
|
||||
|
||||
void ButtonReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
Button* button = static_cast<Button*>(widget);
|
||||
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
||||
button->setScale9Enabled(scale9Enable);
|
||||
|
||||
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData");
|
||||
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
|
||||
switch (normalType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_n = jsonPath;
|
||||
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
||||
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
|
||||
button->loadTextureNormal(normalFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
||||
button->loadTextureNormal(normalFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData");
|
||||
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
|
||||
switch (pressedType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_p = jsonPath;
|
||||
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
||||
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
|
||||
button->loadTexturePressed(pressedFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
||||
button->loadTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData");
|
||||
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
|
||||
switch (disabledType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_d = jsonPath;
|
||||
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
||||
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
|
||||
button->loadTextureDisabled(disabledFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
||||
button->loadTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (scale9Enable)
|
||||
{
|
||||
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
||||
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
||||
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
||||
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
||||
|
||||
button->setCapInsets(Rect(cx, cy, cw, ch));
|
||||
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
|
||||
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
|
||||
if (sw && sh)
|
||||
{
|
||||
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
|
||||
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
|
||||
button->setSize(Size(swf, shf));
|
||||
}
|
||||
}
|
||||
bool tt = DICTOOL->checkObjectExist_json(options, "text");
|
||||
if (tt)
|
||||
{
|
||||
const char* text = DICTOOL->getStringValue_json(options, "text");
|
||||
if (text)
|
||||
{
|
||||
button->setTitleText(text);
|
||||
}
|
||||
}
|
||||
|
||||
bool cr = DICTOOL->checkObjectExist_json(options, "textColorR");
|
||||
bool cg = DICTOOL->checkObjectExist_json(options, "textColorG");
|
||||
bool cb = DICTOOL->checkObjectExist_json(options, "textColorB");
|
||||
int cri = cr?DICTOOL->getIntValue_json(options, "textColorR"):255;
|
||||
int cgi = cg?DICTOOL->getIntValue_json(options, "textColorG"):255;
|
||||
int cbi = cb?DICTOOL->getIntValue_json(options, "textColorB"):255;
|
||||
button->setTitleColor(Color3B(cri,cgi,cbi));
|
||||
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
||||
if (fs)
|
||||
{
|
||||
button->setTitleFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
||||
}
|
||||
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
||||
if (fn)
|
||||
{
|
||||
button->setTitleFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__ButtonReader__
|
||||
#define __TestCpp__ButtonReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class ButtonReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
ButtonReader();
|
||||
virtual ~ButtonReader();
|
||||
|
||||
static ButtonReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__ButtonReader__) */
|
|
@ -0,0 +1,153 @@
|
|||
|
||||
|
||||
#include "CheckBoxReader.h"
|
||||
#include "gui/UICheckBox.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static CheckBoxReader* instanceCheckBoxReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(CheckBoxReader)
|
||||
|
||||
CheckBoxReader::CheckBoxReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CheckBoxReader::~CheckBoxReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CheckBoxReader* CheckBoxReader::getInstance()
|
||||
{
|
||||
if (!instanceCheckBoxReader)
|
||||
{
|
||||
instanceCheckBoxReader = new CheckBoxReader();
|
||||
}
|
||||
return instanceCheckBoxReader;
|
||||
}
|
||||
|
||||
void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
CheckBox* checkBox = static_cast<CheckBox*>(widget);
|
||||
|
||||
const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData");
|
||||
int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType");
|
||||
switch (backGroundType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path");
|
||||
const char* backGroundFileName_tp = (backGroundFileName && (strcmp(backGroundFileName, "") != 0))?tp_b.append(backGroundFileName).c_str():nullptr;
|
||||
checkBox->loadTextureBackGround(backGroundFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path");
|
||||
checkBox->loadTextureBackGround(backGroundFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData");
|
||||
int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType");
|
||||
switch (backGroundSelectedType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_bs = jsonPath;
|
||||
const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path");
|
||||
const char* backGroundSelectedFileName_tp = (backGroundSelectedFileName && (strcmp(backGroundSelectedFileName, "") != 0))?tp_bs.append(backGroundSelectedFileName).c_str():nullptr;
|
||||
checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path");
|
||||
checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData");
|
||||
int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType");
|
||||
switch (frontCrossType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_c = jsonPath;
|
||||
const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path");
|
||||
const char* frontCrossFileName_tp = (frontCrossFileName && (strcmp(frontCrossFileName, "") != 0))?tp_c.append(frontCrossFileName).c_str():nullptr;
|
||||
checkBox->loadTextureFrontCross(frontCrossFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path");
|
||||
checkBox->loadTextureFrontCross(frontCrossFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData");
|
||||
int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType");
|
||||
switch (backGroundDisabledType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_bd = jsonPath;
|
||||
const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path");
|
||||
const char* backGroundDisabledFileName_tp = (backGroundDisabledFileName && (strcmp(backGroundDisabledFileName, "") != 0))?tp_bd.append(backGroundDisabledFileName).c_str():nullptr;
|
||||
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path");
|
||||
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData");
|
||||
int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType");
|
||||
switch (frontCrossDisabledType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_cd = jsonPath;
|
||||
const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path");
|
||||
const char* frontCrossDisabledFileName_tp = (frontCrossDisabledFileName && (strcmp(frontCrossDisabledFileName, "") != 0))?tp_cd.append(frontCrossDisabledFileName).c_str():nullptr;
|
||||
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path");
|
||||
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__CheckBoxReader__
|
||||
#define __TestCpp__CheckBoxReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class CheckBoxReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
CheckBoxReader();
|
||||
virtual ~CheckBoxReader();
|
||||
|
||||
static CheckBoxReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__CheckBoxReader__) */
|
|
@ -0,0 +1,98 @@
|
|||
|
||||
|
||||
#include "ImageViewReader.h"
|
||||
#include "gui/UIImageView.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static ImageViewReader* instanceImageViewReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(ImageViewReader)
|
||||
|
||||
ImageViewReader::ImageViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ImageViewReader::~ImageViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ImageViewReader* ImageViewReader::getInstance()
|
||||
{
|
||||
if (!instanceImageViewReader)
|
||||
{
|
||||
instanceImageViewReader = new ImageViewReader();
|
||||
}
|
||||
return instanceImageViewReader;
|
||||
}
|
||||
|
||||
void ImageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
ImageView* imageView = static_cast<ImageView*>(widget);
|
||||
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
|
||||
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileNameType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_i = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = nullptr;
|
||||
if (imageFileName && (strcmp(imageFileName, "") != 0))
|
||||
{
|
||||
imageFileName_tp = tp_i.append(imageFileName).c_str();
|
||||
imageView->loadTexture(imageFileName_tp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable");
|
||||
bool scale9Enable = false;
|
||||
if (scale9EnableExist)
|
||||
{
|
||||
scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
||||
}
|
||||
imageView->setScale9Enabled(scale9Enable);
|
||||
|
||||
|
||||
if (scale9Enable)
|
||||
{
|
||||
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
|
||||
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
|
||||
if (sw && sh)
|
||||
{
|
||||
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
|
||||
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
|
||||
imageView->setSize(Size(swf, shf));
|
||||
}
|
||||
|
||||
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
||||
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
||||
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
||||
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
||||
|
||||
imageView->setCapInsets(Rect(cx, cy, cw, ch));
|
||||
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__ImageViewReader__
|
||||
#define __TestCpp__ImageViewReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class ImageViewReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
ImageViewReader();
|
||||
virtual ~ImageViewReader();
|
||||
|
||||
static ImageViewReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__ImageViewReader__) */
|
|
@ -0,0 +1,119 @@
|
|||
|
||||
|
||||
#include "LayoutReader.h"
|
||||
#include "gui/UILayout.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static LayoutReader* instanceLayoutReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(LayoutReader)
|
||||
|
||||
LayoutReader::LayoutReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LayoutReader::~LayoutReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LayoutReader* LayoutReader::getInstance()
|
||||
{
|
||||
if (!instanceLayoutReader)
|
||||
{
|
||||
instanceLayoutReader = new LayoutReader();
|
||||
}
|
||||
return instanceLayoutReader;
|
||||
}
|
||||
|
||||
void LayoutReader::setPropsFromJsonDictionary(gui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
Layout* panel = static_cast<Layout*>(widget);
|
||||
|
||||
/* adapt screen gui */
|
||||
float w = 0, h = 0;
|
||||
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen");
|
||||
if (adaptScrenn)
|
||||
{
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
w = screenSize.width;
|
||||
h = screenSize.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = DICTOOL->getFloatValue_json(options, "width");
|
||||
h = DICTOOL->getFloatValue_json(options, "height");
|
||||
}
|
||||
panel->setSize(Size(w, h));
|
||||
/**/
|
||||
|
||||
bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable");
|
||||
panel->setBackGroundImageScale9Enabled(backGroundScale9Enable);
|
||||
int cr = DICTOOL->getIntValue_json(options, "bgColorR");
|
||||
int cg = DICTOOL->getIntValue_json(options, "bgColorG");
|
||||
int cb = DICTOOL->getIntValue_json(options, "bgColorB");
|
||||
|
||||
int scr = DICTOOL->getIntValue_json(options, "bgStartColorR");
|
||||
int scg = DICTOOL->getIntValue_json(options, "bgStartColorG");
|
||||
int scb = DICTOOL->getIntValue_json(options, "bgStartColorB");
|
||||
|
||||
int ecr = DICTOOL->getIntValue_json(options, "bgEndColorR");
|
||||
int ecg = DICTOOL->getIntValue_json(options, "bgEndColorG");
|
||||
int ecb = DICTOOL->getIntValue_json(options, "bgEndColorB");
|
||||
|
||||
float bgcv1 = DICTOOL->getFloatValue_json(options, "vectorX");
|
||||
float bgcv2 = DICTOOL->getFloatValue_json(options, "vectorY");
|
||||
panel->setBackGroundColorVector(Point(bgcv1, bgcv2));
|
||||
|
||||
int co = DICTOOL->getIntValue_json(options, "bgColorOpacity");
|
||||
|
||||
int colorType = DICTOOL->getIntValue_json(options, "colorType");
|
||||
panel->setBackGroundColorType(LayoutBackGroundColorType(colorType));
|
||||
panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb));
|
||||
panel->setBackGroundColor(Color3B(cr, cg, cb));
|
||||
panel->setBackGroundColorOpacity(co);
|
||||
|
||||
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData");
|
||||
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileNameType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
||||
panel->setBackGroundImage(imageFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (backGroundScale9Enable)
|
||||
{
|
||||
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
||||
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
||||
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
||||
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
||||
panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch));
|
||||
}
|
||||
panel->setLayoutType((LayoutType)DICTOOL->getIntValue_json(options, "layoutType"));
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__LayoutReader__
|
||||
#define __TestCpp__LayoutReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class LayoutReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
LayoutReader();
|
||||
virtual ~LayoutReader();
|
||||
|
||||
static LayoutReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__LayoutReader__) */
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
|
||||
#include "ListViewReader.h"
|
||||
#include "gui/UIListView.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static ListViewReader* instanceListViewReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(ListViewReader)
|
||||
|
||||
ListViewReader::ListViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ListViewReader::~ListViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ListViewReader* ListViewReader::getInstance()
|
||||
{
|
||||
if (!instanceListViewReader)
|
||||
{
|
||||
instanceListViewReader = new ListViewReader();
|
||||
}
|
||||
return instanceListViewReader;
|
||||
}
|
||||
|
||||
void ListViewReader::setPropsFromJsonDictionary(gui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
ScrollViewReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
ListView* listView = static_cast<ListView*>(widget);
|
||||
|
||||
int direction = DICTOOL->getFloatValue_json(options, "direction");
|
||||
listView->setDirection((SCROLLVIEW_DIR)direction);
|
||||
|
||||
ListViewGravity gravity = (ListViewGravity)DICTOOL->getIntValue_json(options, "gravity");
|
||||
listView->setGravity(gravity);
|
||||
|
||||
float itemMargin = DICTOOL->getFloatValue_json(options, "itemMargin");
|
||||
listView->setItemsMargin(itemMargin);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__ListViewReader__
|
||||
#define __TestCpp__ListViewReader__
|
||||
|
||||
#include "../ScrollViewReader/ScrollViewReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class ListViewReader : public ScrollViewReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
ListViewReader();
|
||||
virtual ~ListViewReader();
|
||||
|
||||
static ListViewReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__ListViewReader__) */
|
|
@ -0,0 +1,91 @@
|
|||
|
||||
|
||||
#include "LoadingBarReader.h"
|
||||
#include "gui/UILoadingBar.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static LoadingBarReader* instanceLoadingBar = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(LoadingBarReader)
|
||||
|
||||
LoadingBarReader::LoadingBarReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LoadingBarReader::~LoadingBarReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LoadingBarReader* LoadingBarReader::getInstance()
|
||||
{
|
||||
if (!instanceLoadingBar)
|
||||
{
|
||||
instanceLoadingBar = new LoadingBarReader();
|
||||
}
|
||||
return instanceLoadingBar;
|
||||
}
|
||||
|
||||
void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
|
||||
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData");
|
||||
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileNameType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_i = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = nullptr;
|
||||
if (imageFileName && (strcmp(imageFileName, "") != 0))
|
||||
{
|
||||
imageFileName_tp = tp_i.append(imageFileName).c_str();
|
||||
loadingBar->loadTexture(imageFileName_tp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
loadingBar->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* gui mark add load bar scale9 parse */
|
||||
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
||||
loadingBar->setScale9Enabled(scale9Enable);
|
||||
|
||||
if (scale9Enable)
|
||||
{
|
||||
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
||||
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
||||
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
||||
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
||||
|
||||
loadingBar->setCapInsets(Rect(cx, cy, cw, ch));
|
||||
|
||||
float width = DICTOOL->getFloatValue_json(options, "width");
|
||||
float height = DICTOOL->getFloatValue_json(options, "height");
|
||||
loadingBar->setSize(Size(width, height));
|
||||
}
|
||||
/**/
|
||||
|
||||
loadingBar->setDirection(LoadingBarType(DICTOOL->getIntValue_json(options, "direction")));
|
||||
loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent"));
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__LoadingBarReader__
|
||||
#define __TestCpp__LoadingBarReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class LoadingBarReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
LoadingBarReader();
|
||||
virtual ~LoadingBarReader();
|
||||
|
||||
static LoadingBarReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__LoadingBarReader__) */
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
|
||||
#include "PageViewReader.h"
|
||||
#include "gui/UIPageView.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static PageViewReader* instancePageViewReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(PageViewReader)
|
||||
|
||||
PageViewReader::PageViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PageViewReader::~PageViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PageViewReader* PageViewReader::getInstance()
|
||||
{
|
||||
if (!instancePageViewReader)
|
||||
{
|
||||
instancePageViewReader = new PageViewReader();
|
||||
}
|
||||
return instancePageViewReader;
|
||||
}
|
||||
|
||||
void PageViewReader::setPropsFromJsonDictionary(gui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
LayoutReader::setPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__PageViewReader__
|
||||
#define __TestCpp__PageViewReader__
|
||||
|
||||
#include "../LayoutReader/LayoutReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class PageViewReader : public LayoutReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
PageViewReader();
|
||||
virtual ~PageViewReader();
|
||||
|
||||
static PageViewReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(gui::Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__PageViewReader__) */
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
|
||||
#include "ScrollViewReader.h"
|
||||
#include "gui/UIScrollView.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static ScrollViewReader* instanceScrollViewReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(ScrollViewReader)
|
||||
|
||||
ScrollViewReader::ScrollViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ScrollViewReader::~ScrollViewReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ScrollViewReader* ScrollViewReader::getInstance()
|
||||
{
|
||||
if (!instanceScrollViewReader)
|
||||
{
|
||||
instanceScrollViewReader = new ScrollViewReader();
|
||||
}
|
||||
return instanceScrollViewReader;
|
||||
}
|
||||
|
||||
void ScrollViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
LayoutReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
ScrollView* scrollView = static_cast<ScrollView*>(widget);
|
||||
float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth");
|
||||
float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight");
|
||||
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
||||
int direction = DICTOOL->getFloatValue_json(options, "direction");
|
||||
scrollView->setDirection((SCROLLVIEW_DIR)direction);
|
||||
scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, "bounceEnable"));
|
||||
|
||||
|
||||
LayoutReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__ScrollViewReader__
|
||||
#define __TestCpp__ScrollViewReader__
|
||||
|
||||
#include "../LayoutReader/LayoutReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class ScrollViewReader : public LayoutReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
ScrollViewReader();
|
||||
virtual ~ScrollViewReader();
|
||||
|
||||
static ScrollViewReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__ScrollViewReader__) */
|
|
@ -0,0 +1,192 @@
|
|||
|
||||
|
||||
#include "SliderReader.h"
|
||||
#include "gui/UISlider.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static SliderReader* instanceSliderReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(SliderReader)
|
||||
|
||||
SliderReader::SliderReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SliderReader::~SliderReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SliderReader* SliderReader::getInstance()
|
||||
{
|
||||
if (!instanceSliderReader)
|
||||
{
|
||||
instanceSliderReader = new SliderReader();
|
||||
}
|
||||
return instanceSliderReader;
|
||||
}
|
||||
|
||||
void SliderReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
Slider* slider = static_cast<Slider*>(widget);
|
||||
|
||||
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "barTextureScale9Enable");
|
||||
slider->setScale9Enabled(barTextureScale9Enable);
|
||||
bool bt = DICTOOL->checkObjectExist_json(options, "barFileName");
|
||||
float barLength = DICTOOL->getFloatValue_json(options, "length");
|
||||
if (bt)
|
||||
{
|
||||
if (barTextureScale9Enable)
|
||||
{
|
||||
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
|
||||
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
||||
slider->loadBarTexture(imageFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
slider->setSize(Size(barLength, slider->getContentSize().height));
|
||||
}
|
||||
else
|
||||
{
|
||||
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
|
||||
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
||||
switch (imageFileType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
||||
slider->loadBarTexture(imageFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
||||
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData");
|
||||
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
|
||||
switch (normalType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_n = jsonPath;
|
||||
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
||||
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
|
||||
slider->loadSlidBallTextureNormal(normalFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
||||
slider->loadSlidBallTextureNormal(normalFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData");
|
||||
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
|
||||
switch (pressedType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_p = jsonPath;
|
||||
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
||||
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
|
||||
slider->loadSlidBallTexturePressed(pressedFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
||||
slider->loadSlidBallTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData");
|
||||
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
|
||||
switch (disabledType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_d = jsonPath;
|
||||
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
||||
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
|
||||
slider->loadSlidBallTextureDisabled(disabledFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
||||
slider->loadSlidBallTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
|
||||
|
||||
const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData");
|
||||
int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType");
|
||||
switch (progressBarType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_b = jsonPath;
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
|
||||
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
||||
slider->loadProgressBarTexture(imageFileName_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
|
||||
slider->loadProgressBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__SliderReader__
|
||||
#define __TestCpp__SliderReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class SliderReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
SliderReader();
|
||||
virtual ~SliderReader();
|
||||
|
||||
static SliderReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__SliderReader__) */
|
|
@ -0,0 +1,69 @@
|
|||
|
||||
|
||||
#include "TextAtlasReader.h"
|
||||
#include "gui/UITextAtlas.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static TextAtlasReader* instanceTextAtalsReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextAtlasReader)
|
||||
|
||||
TextAtlasReader::TextAtlasReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextAtlasReader::~TextAtlasReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextAtlasReader* TextAtlasReader::getInstance()
|
||||
{
|
||||
if (!instanceTextAtalsReader)
|
||||
{
|
||||
instanceTextAtalsReader = new TextAtlasReader();
|
||||
}
|
||||
return instanceTextAtalsReader;
|
||||
}
|
||||
|
||||
void TextAtlasReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget);
|
||||
bool sv = DICTOOL->checkObjectExist_json(options, "stringValue");
|
||||
bool cmf = DICTOOL->checkObjectExist_json(options, "charMapFile");
|
||||
bool iw = DICTOOL->checkObjectExist_json(options, "itemWidth");
|
||||
bool ih = DICTOOL->checkObjectExist_json(options, "itemHeight");
|
||||
bool scm = DICTOOL->checkObjectExist_json(options, "startCharMap");
|
||||
if (sv && cmf && iw && ih && scm)
|
||||
{
|
||||
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "charMapFileData");
|
||||
int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType");
|
||||
switch (cmfType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_c = jsonPath;
|
||||
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
|
||||
const char* cmf_tp = tp_c.append(cmfPath).c_str();
|
||||
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"), DICTOOL->getStringValue_json(options, "startCharMap"));
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
CCLOG("Wrong res type of LabelAtlas!");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__TextAtlasReader__
|
||||
#define __TestCpp__TextAtlasReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class TextAtlasReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
TextAtlasReader();
|
||||
virtual ~TextAtlasReader();
|
||||
|
||||
static TextAtlasReader* getInstance();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__TextAtlasReader__) */
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
|
||||
#include "TextBMFontReader.h"
|
||||
#include "gui/UITextBMFont.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static TextBMFontReader* instanceTextBMFontReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextBMFontReader)
|
||||
|
||||
TextBMFontReader::TextBMFontReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextBMFontReader::~TextBMFontReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextBMFontReader* TextBMFontReader::getInstance()
|
||||
{
|
||||
if (!instanceTextBMFontReader)
|
||||
{
|
||||
instanceTextBMFontReader = new TextBMFontReader();
|
||||
}
|
||||
return instanceTextBMFontReader;
|
||||
}
|
||||
|
||||
void TextBMFontReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget);
|
||||
|
||||
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
|
||||
int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType");
|
||||
switch (cmfType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
std::string tp_c = jsonPath;
|
||||
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
|
||||
const char* cmf_tp = tp_c.append(cmfPath).c_str();
|
||||
labelBMFont->setFntFile(cmf_tp);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
CCLOG("Wrong res type of LabelAtlas!");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const char* text = DICTOOL->getStringValue_json(options, "text");
|
||||
labelBMFont->setText(text);
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__TextBMFontReader__
|
||||
#define __TestCpp__TextBMFontReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class TextBMFontReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
TextBMFontReader();
|
||||
virtual ~TextBMFontReader();
|
||||
|
||||
static TextBMFontReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__TextBMFontReader__) */
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
|
||||
#include "TextFieldReader.h"
|
||||
#include "gui/UITextField.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static TextFieldReader* instanceTextFieldReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextFieldReader)
|
||||
|
||||
TextFieldReader::TextFieldReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextFieldReader::~TextFieldReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextFieldReader* TextFieldReader::getInstance()
|
||||
{
|
||||
if (!instanceTextFieldReader)
|
||||
{
|
||||
instanceTextFieldReader = new TextFieldReader();
|
||||
}
|
||||
return instanceTextFieldReader;
|
||||
}
|
||||
|
||||
void TextFieldReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
TextField* textField = static_cast<TextField*>(widget);
|
||||
bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder");
|
||||
if (ph)
|
||||
{
|
||||
textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder"));
|
||||
}
|
||||
textField->setText(DICTOOL->getStringValue_json(options, "text"));
|
||||
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
||||
if (fs)
|
||||
{
|
||||
textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
||||
}
|
||||
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
||||
if (fn)
|
||||
{
|
||||
textField->setFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
||||
}
|
||||
bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth");
|
||||
bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight");
|
||||
if (tsw && tsh)
|
||||
{
|
||||
textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), DICTOOL->getFloatValue_json(options,"touchSizeHeight")));
|
||||
}
|
||||
|
||||
float dw = DICTOOL->getFloatValue_json(options, "width");
|
||||
float dh = DICTOOL->getFloatValue_json(options, "height");
|
||||
if (dw > 0.0f || dh > 0.0f)
|
||||
{
|
||||
//textField->setSize(Size(dw, dh));
|
||||
}
|
||||
bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable");
|
||||
textField->setMaxLengthEnabled(maxLengthEnable);
|
||||
|
||||
if (maxLengthEnable)
|
||||
{
|
||||
int maxLength = DICTOOL->getIntValue_json(options, "maxLength");
|
||||
textField->setMaxLength(maxLength);
|
||||
}
|
||||
bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable");
|
||||
textField->setPasswordEnabled(passwordEnable);
|
||||
if (passwordEnable)
|
||||
{
|
||||
textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText"));
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__TextFieldReader__
|
||||
#define __TestCpp__TextFieldReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class TextFieldReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
TextFieldReader();
|
||||
virtual ~TextFieldReader();
|
||||
|
||||
static TextFieldReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__TextFieldReader__) */
|
|
@ -0,0 +1,74 @@
|
|||
|
||||
|
||||
#include "TextReader.h"
|
||||
#include "gui/UIText.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static TextReader* instanceTextReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextReader)
|
||||
|
||||
TextReader::TextReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextReader::~TextReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextReader* TextReader::getInstance()
|
||||
{
|
||||
if (!instanceTextReader)
|
||||
{
|
||||
instanceTextReader = new TextReader();
|
||||
}
|
||||
return instanceTextReader;
|
||||
}
|
||||
|
||||
void TextReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
||||
|
||||
|
||||
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
||||
|
||||
Text* label = static_cast<Text*>(widget);
|
||||
bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable");
|
||||
label->setTouchScaleChangeEnabled(touchScaleChangeAble);
|
||||
const char* text = DICTOOL->getStringValue_json(options, "text");
|
||||
label->setText(text);
|
||||
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
||||
if (fs)
|
||||
{
|
||||
label->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
||||
}
|
||||
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
||||
if (fn)
|
||||
{
|
||||
label->setFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
||||
}
|
||||
bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth");
|
||||
bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight");
|
||||
if (aw && ah)
|
||||
{
|
||||
Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight"));
|
||||
label->setTextAreaSize(size);
|
||||
}
|
||||
bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment");
|
||||
if (ha)
|
||||
{
|
||||
label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, "hAlignment"));
|
||||
}
|
||||
bool va = DICTOOL->checkObjectExist_json(options, "vAlignment");
|
||||
if (va)
|
||||
{
|
||||
label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, "vAlignment"));
|
||||
}
|
||||
|
||||
|
||||
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__TextReader__
|
||||
#define __TestCpp__TextReader__
|
||||
|
||||
#include "../WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class TextReader : public WidgetReader
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
TextReader();
|
||||
virtual ~TextReader();
|
||||
|
||||
static TextReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__TextReader__) */
|
|
@ -0,0 +1,172 @@
|
|||
|
||||
|
||||
#include "WidgetReader.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
static WidgetReader* instanceWidgetReader = NULL;
|
||||
|
||||
IMPLEMENT_CLASS_WIDGET_READER_INFO(WidgetReader)
|
||||
|
||||
WidgetReader::WidgetReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
WidgetReader::~WidgetReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
WidgetReader* WidgetReader::getInstance()
|
||||
{
|
||||
if (!instanceWidgetReader)
|
||||
{
|
||||
instanceWidgetReader = new WidgetReader();
|
||||
}
|
||||
return instanceWidgetReader;
|
||||
}
|
||||
|
||||
void WidgetReader::purge()
|
||||
{
|
||||
CC_SAFE_DELETE(instanceWidgetReader);
|
||||
}
|
||||
|
||||
void WidgetReader::setPropsFromJsonDictionary(cocos2d::gui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize");
|
||||
if (ignoreSizeExsit)
|
||||
{
|
||||
widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize"));
|
||||
}
|
||||
|
||||
widget->setSizeType((SizeType)DICTOOL->getIntValue_json(options, "sizeType"));
|
||||
widget->setPositionType((PositionType)DICTOOL->getIntValue_json(options, "positionType"));
|
||||
|
||||
widget->setSizePercent(Point(DICTOOL->getFloatValue_json(options, "sizePercentX"), DICTOOL->getFloatValue_json(options, "sizePercentY")));
|
||||
widget->setPositionPercent(Point(DICTOOL->getFloatValue_json(options, "positionPercentX"), DICTOOL->getFloatValue_json(options, "positionPercentY")));
|
||||
|
||||
/* adapt screen */
|
||||
float w = 0, h = 0;
|
||||
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen");
|
||||
if (adaptScrenn)
|
||||
{
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
w = screenSize.width;
|
||||
h = screenSize.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = DICTOOL->getFloatValue_json(options, "width");
|
||||
h = DICTOOL->getFloatValue_json(options, "height");
|
||||
}
|
||||
widget->setSize(Size(w, h));
|
||||
// before
|
||||
/*
|
||||
float w = DICTOOL->getFloatValue_json(options, "width");
|
||||
float h = DICTOOL->getFloatValue_json(options, "height");
|
||||
widget->setSize(CCSizeMake(w, h));
|
||||
*/
|
||||
/**/
|
||||
|
||||
widget->setTag(DICTOOL->getIntValue_json(options, "tag"));
|
||||
widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag"));
|
||||
widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, "touchAble"));
|
||||
const char* name = DICTOOL->getStringValue_json(options, "name");
|
||||
const char* widgetName = name?name:"default";
|
||||
widget->setName(widgetName);
|
||||
float x = DICTOOL->getFloatValue_json(options, "x");
|
||||
float y = DICTOOL->getFloatValue_json(options, "y");
|
||||
widget->setPosition(Point(x,y));
|
||||
bool sx = DICTOOL->checkObjectExist_json(options, "scaleX");
|
||||
if (sx)
|
||||
{
|
||||
widget->setScaleX(DICTOOL->getFloatValue_json(options, "scaleX"));
|
||||
}
|
||||
bool sy = DICTOOL->checkObjectExist_json(options, "scaleY");
|
||||
if (sy)
|
||||
{
|
||||
widget->setScaleY(DICTOOL->getFloatValue_json(options, "scaleY"));
|
||||
}
|
||||
bool rt = DICTOOL->checkObjectExist_json(options, "rotation");
|
||||
if (rt)
|
||||
{
|
||||
widget->setRotation(DICTOOL->getFloatValue_json(options, "rotation"));
|
||||
}
|
||||
bool vb = DICTOOL->checkObjectExist_json(options, "visible");
|
||||
if (vb)
|
||||
{
|
||||
widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible"));
|
||||
}
|
||||
int z = DICTOOL->getIntValue_json(options, "ZOrder");
|
||||
widget->setLocalZOrder(z);
|
||||
|
||||
bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter");
|
||||
if (layout)
|
||||
{
|
||||
const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, "layoutParameter");
|
||||
int paramType = DICTOOL->getIntValue_json(layoutParameterDic, "type");
|
||||
LayoutParameter* parameter = nullptr;
|
||||
switch (paramType)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
parameter = LinearLayoutParameter::create();
|
||||
int gravity = DICTOOL->getIntValue_json(layoutParameterDic, "gravity");
|
||||
((LinearLayoutParameter*)parameter)->setGravity((LinearGravity)gravity);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
parameter = RelativeLayoutParameter::create();
|
||||
RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter;
|
||||
const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeName");
|
||||
rParameter->setRelativeName(relativeName);
|
||||
const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeToName");
|
||||
rParameter->setRelativeToWidgetName(relativeToName);
|
||||
int align = DICTOOL->getIntValue_json(layoutParameterDic, "align");
|
||||
rParameter->setAlign((RelativeAlign)align);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (parameter)
|
||||
{
|
||||
float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, "marginLeft");
|
||||
float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, "marginTop");
|
||||
float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, "marginRight");
|
||||
float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, "marginDown");
|
||||
parameter->setMargin(Margin(mgl, mgt, mgr, mgb));
|
||||
widget->setLayoutParameter(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetReader::setColorPropsFromJsonDictionary(gui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
bool op = DICTOOL->checkObjectExist_json(options, "opacity");
|
||||
if (op)
|
||||
{
|
||||
widget->setOpacity(DICTOOL->getIntValue_json(options, "opacity"));
|
||||
}
|
||||
bool cr = DICTOOL->checkObjectExist_json(options, "colorR");
|
||||
bool cg = DICTOOL->checkObjectExist_json(options, "colorG");
|
||||
bool cb = DICTOOL->checkObjectExist_json(options, "colorB");
|
||||
int colorR = cr ? DICTOOL->getIntValue_json(options, "colorR") : 255;
|
||||
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
|
||||
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
|
||||
widget->setColor(Color3B(colorR, colorG, colorB));
|
||||
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
|
||||
float apxf = apx ? DICTOOL->getFloatValue_json(options, "anchorPointX") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f);
|
||||
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
|
||||
float apyf = apy ? DICTOOL->getFloatValue_json(options, "anchorPointY") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f);
|
||||
widget->setAnchorPoint(Point(apxf, apyf));
|
||||
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
|
||||
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
|
||||
widget->setFlipX(flipX);
|
||||
widget->setFlipY(flipY);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__WidgetReader__
|
||||
#define __TestCpp__WidgetReader__
|
||||
|
||||
#include "WidgetReaderProtocol.h"
|
||||
#include "../CCSGUIReader.h"
|
||||
#include "gui/GUIDefine.h"
|
||||
#include "gui/UIWidget.h"
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class WidgetReader : public Object, public WidgetReaderProtocol
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_WIDGET_READER_INFO
|
||||
|
||||
WidgetReader();
|
||||
virtual ~WidgetReader();
|
||||
|
||||
static WidgetReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
virtual void setColorPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__WidgetReader__) */
|
|
@ -0,0 +1,53 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TestCpp__WidgetReaderProtocol__
|
||||
#define __TestCpp__WidgetReaderProtocol__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocostudio/DictionaryHelper.h"
|
||||
|
||||
namespace cocos2d
|
||||
{
|
||||
namespace gui
|
||||
{
|
||||
class Widget;
|
||||
}
|
||||
}
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace cocos2d::gui;
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class WidgetReaderProtocol
|
||||
{
|
||||
public:
|
||||
virtual ~WidgetReaderProtocol() {};
|
||||
|
||||
virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__TestCpp__WidgetReaderProtocol__) */
|
|
@ -0,0 +1,162 @@
|
|||
|
||||
|
||||
#include "CocoStudioGUITest.h"
|
||||
#include "../../ExtensionsTest/ExtensionsTest.h"
|
||||
#include "CocosGUIScene.h"
|
||||
#include "GUIEditorTest.h"
|
||||
#include "CutomGUIScene.h"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
LINE_SPACE = 40,
|
||||
kItemTagBasic = 1000,
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
const char *name;
|
||||
std::function<void(Ref* sender)> callback;
|
||||
}
|
||||
g_guisTests[] =
|
||||
{
|
||||
{
|
||||
"GUI Dynamic Create Test",
|
||||
[](Ref* sender)
|
||||
{
|
||||
CocosGUITestScene *pScene = new CocosGUITestScene();
|
||||
pScene->runThisTest();
|
||||
pScene->release();
|
||||
}
|
||||
},
|
||||
{
|
||||
"GUI Editor Test",
|
||||
[](Ref* sender)
|
||||
{
|
||||
GUIEditorTestScene* pScene = new GUIEditorTestScene();
|
||||
pScene->runThisTest();
|
||||
pScene->release();
|
||||
}
|
||||
},
|
||||
{
|
||||
"Custom GUI Test",
|
||||
[](Ref* sender)
|
||||
{
|
||||
CustomGUITestScene* pScene = new CustomGUITestScene();
|
||||
pScene->runThisTest();
|
||||
pScene->release();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// CocoStudioGUIMainLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
static Point _curPos = Point::ZERO;
|
||||
|
||||
void CocoStudioGUIMainLayer::onEnter()
|
||||
{
|
||||
using namespace ui;
|
||||
|
||||
CCLayer::onEnter();
|
||||
|
||||
Size s = Director::getInstance()->getWinSize();
|
||||
|
||||
_itemMenu = CCMenu::create();
|
||||
_itemMenu->setPosition(Point::ZERO);
|
||||
CCMenuItemFont::setFontName("Arial");
|
||||
CCMenuItemFont::setFontSize(24);
|
||||
for (int i = 0; i < g_maxTests; ++i)
|
||||
{
|
||||
auto pItem = MenuItemFont::create(g_guisTests[i].name, g_guisTests[i].callback);
|
||||
pItem->setPosition(Point(s.width / 2, s.height / 4 * 3 - (i + 1) * LINE_SPACE));
|
||||
_itemMenu->addChild(pItem, kItemTagBasic + i);
|
||||
}
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesBegan = CC_CALLBACK_2(CocoStudioGUIMainLayer::onTouchesBegan, this);
|
||||
listener->onTouchesMoved = CC_CALLBACK_2(CocoStudioGUIMainLayer::onTouchesMoved, this);
|
||||
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
addChild(_itemMenu);
|
||||
}
|
||||
|
||||
void CocoStudioGUIMainLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
||||
{
|
||||
auto touch = static_cast<Touch*>(touches[0]);
|
||||
|
||||
_beginPos = touch->getLocation();
|
||||
}
|
||||
|
||||
/*
|
||||
void CocoStudioGUIMainLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
||||
{
|
||||
auto touch = static_cast<Touch*>(touches[0]);
|
||||
|
||||
auto touchLocation = touch->getLocation();
|
||||
float nMoveY = touchLocation.y - _beginPos.y;
|
||||
|
||||
auto curPos = _itemMenu->getPosition();
|
||||
auto nextPos = Point(curPos.x, curPos.y + nMoveY);
|
||||
|
||||
if (nextPos.y < 0.0f)
|
||||
{
|
||||
_itemMenu->setPosition(Point::ZERO);
|
||||
return;
|
||||
}
|
||||
|
||||
float y = (g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height;
|
||||
if (nextPos.y > y)
|
||||
{
|
||||
_itemMenu->setPosition(Point(0, y));
|
||||
return;
|
||||
}
|
||||
|
||||
_itemMenu->setPosition(nextPos);
|
||||
_beginPos = touchLocation;
|
||||
_curPos = nextPos;
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// CocoStudioGUITestScene
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void CocoStudioGUITestScene::onEnter()
|
||||
{
|
||||
CCScene::onEnter();
|
||||
|
||||
LabelTTF* label = LabelTTF::create("Back", "Arial", 20);
|
||||
//#endif
|
||||
MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CocoStudioGUITestScene::BackCallback, this));
|
||||
|
||||
Menu* pMenu = Menu::create(pMenuItem, NULL);
|
||||
|
||||
pMenu->setPosition( Point::ZERO );
|
||||
pMenuItem->setPosition( Point( VisibleRect::right().x - 50, VisibleRect::bottom().y + 25) );
|
||||
|
||||
addChild(pMenu, 1);
|
||||
}
|
||||
|
||||
void CocoStudioGUITestScene::runThisTest()
|
||||
{
|
||||
Layer* pLayer = new CocoStudioGUIMainLayer();
|
||||
addChild(pLayer);
|
||||
pLayer->release();
|
||||
|
||||
CCDirector::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
void CocoStudioGUITestScene::BackCallback(Ref* pSender)
|
||||
{
|
||||
ExtensionsTestScene* pScene = new ExtensionsTestScene();
|
||||
pScene->runThisTest();
|
||||
pScene->release();
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
|
||||
#ifndef __TestCpp__CocoStudioGUITest__
|
||||
#define __TestCpp__CocoStudioGUITest__
|
||||
|
||||
#include "../../testBasic.h"
|
||||
|
||||
class CocoStudioGUIMainLayer : public Layer
|
||||
{
|
||||
public:
|
||||
virtual void onEnter();
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event *event);
|
||||
// void onTouchesMoved(const std::vector<Touch*>& touches, Event *event);
|
||||
|
||||
private:
|
||||
Point _beginPos;
|
||||
Menu* _itemMenu;
|
||||
};
|
||||
|
||||
class CocoStudioGUITestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void onEnter();
|
||||
virtual void runThisTest();
|
||||
void BackCallback(Ref* pSender);
|
||||
};
|
||||
|
||||
#endif /* defined(__TestCpp__CocoStudioGUITest__) */
|
|
@ -1,4 +1,5 @@
|
|||
#include "CocosGUIScene.h"
|
||||
#include "CocoStudioGUITest.h"
|
||||
#include "UISceneManager.h"
|
||||
#include "../ExtensionsTest.h"
|
||||
#include "cocostudio/CocoStudio.h"
|
||||
|
@ -65,6 +66,8 @@ g_guisTests[] =
|
|||
Director::getInstance()->replaceScene(pScene);
|
||||
}
|
||||
},
|
||||
*/
|
||||
/*
|
||||
{
|
||||
"gui SwitchTest",
|
||||
[](Ref* sender)
|
||||
|
@ -117,37 +120,37 @@ g_guisTests[] =
|
|||
},
|
||||
*/
|
||||
{
|
||||
"gui LabelAtalsTest",
|
||||
"gui TextAtalsTest",
|
||||
[](Ref* sender)
|
||||
{
|
||||
UISceneManager* pManager = UISceneManager::sharedUISceneManager();
|
||||
pManager->setCurrentUISceneId(kUILabelAtlasTest);
|
||||
pManager->setMinUISceneId(kUILabelAtlasTest);
|
||||
pManager->setMaxUISceneId(kUILabelAtlasTest);
|
||||
pManager->setCurrentUISceneId(kUITextAtlasTest);
|
||||
pManager->setMinUISceneId(kUITextAtlasTest);
|
||||
pManager->setMaxUISceneId(kUITextAtlasTest);
|
||||
Scene* pScene = pManager->currentUIScene();
|
||||
Director::getInstance()->replaceScene(pScene);
|
||||
}
|
||||
},
|
||||
{
|
||||
"gui LabelTest",
|
||||
"gui TextTest",
|
||||
[](Ref* sender)
|
||||
{
|
||||
UISceneManager* pManager = UISceneManager::sharedUISceneManager();
|
||||
pManager->setCurrentUISceneId(kUILabelTest);
|
||||
pManager->setMinUISceneId(kUILabelTest);
|
||||
pManager->setMaxUISceneId(kUILabelTest_TTF);
|
||||
pManager->setCurrentUISceneId(kUITextTest);
|
||||
pManager->setMinUISceneId(kUITextTest);
|
||||
pManager->setMaxUISceneId(kUITextTest_TTF);
|
||||
Scene* pScene = pManager->currentUIScene();
|
||||
Director::getInstance()->replaceScene(pScene);
|
||||
}
|
||||
},
|
||||
{
|
||||
"gui LabelBMFontTest",
|
||||
"gui TextBMFontTest",
|
||||
[](Ref* sender)
|
||||
{
|
||||
UISceneManager* pManager = UISceneManager::sharedUISceneManager();
|
||||
pManager->setCurrentUISceneId(kUILabelBMFontTest);
|
||||
pManager->setMinUISceneId(kUILabelBMFontTest);
|
||||
pManager->setMaxUISceneId(kUILabelBMFontTest);
|
||||
pManager->setCurrentUISceneId(kUITextBMFontTest);
|
||||
pManager->setMinUISceneId(kUITextBMFontTest);
|
||||
pManager->setMaxUISceneId(kUITextBMFontTest);
|
||||
Scene* pScene = pManager->currentUIScene();
|
||||
Director::getInstance()->replaceScene(pScene);
|
||||
}
|
||||
|
@ -159,7 +162,7 @@ g_guisTests[] =
|
|||
UISceneManager* pManager = UISceneManager::sharedUISceneManager();
|
||||
pManager->setCurrentUISceneId(kUITextFieldTest);
|
||||
pManager->setMinUISceneId(kUITextFieldTest);
|
||||
pManager->setMaxUISceneId(kUITextFieldTest_Password);
|
||||
pManager->setMaxUISceneId(kUITextFieldTest_LineWrap);
|
||||
Scene* pScene = pManager->currentUIScene();
|
||||
Director::getInstance()->replaceScene(pScene);
|
||||
}
|
||||
|
@ -225,6 +228,8 @@ g_guisTests[] =
|
|||
Director::getInstance()->replaceScene(pScene);
|
||||
}
|
||||
},
|
||||
*/
|
||||
/*
|
||||
{
|
||||
"gui PickerViewTest",
|
||||
[](Ref* sender)
|
||||
|
@ -327,6 +332,22 @@ void CocosGUITestMainLayer::onTouchesMoved(const std::vector<Touch*>& touches, E
|
|||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void CocosGUITestScene::onEnter()
|
||||
{
|
||||
Scene::onEnter();
|
||||
|
||||
LabelTTF* label = CCLabelTTF::create("Back", "Arial", 20);
|
||||
//#endif
|
||||
auto pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CocosGUITestScene::BackCallback, this));
|
||||
|
||||
Menu* pMenu =Menu::create(pMenuItem, NULL);
|
||||
|
||||
pMenu->setPosition( Point::ZERO );
|
||||
pMenuItem->setPosition( Point( VisibleRect::right().x - 50, VisibleRect::bottom().y + 25) );
|
||||
|
||||
addChild(pMenu, 1);
|
||||
}
|
||||
|
||||
void CocosGUITestScene::runThisTest()
|
||||
{
|
||||
auto layer = new CocosGUITestMainLayer();
|
||||
|
@ -334,4 +355,86 @@ void CocosGUITestScene::runThisTest()
|
|||
layer->release();
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
}
|
||||
|
||||
void CocosGUITestScene::BackCallback(Ref* pSender)
|
||||
{
|
||||
CocoStudioGUITestScene* pScene = new CocoStudioGUITestScene();
|
||||
pScene->runThisTest();
|
||||
pScene->release();
|
||||
}
|
||||
|
||||
/*
|
||||
const char* gui_scene_names[1] =
|
||||
{
|
||||
"CocosGUIWidgetTest",
|
||||
};
|
||||
|
||||
CocosGUITestScene::CocosGUITestScene(bool bPortrait)
|
||||
: _ul(nullptr)
|
||||
, _label(nullptr)
|
||||
, _itemMenu(nullptr)
|
||||
{
|
||||
TestScene::init();
|
||||
}
|
||||
|
||||
CocosGUITestScene::~CocosGUITestScene()
|
||||
{
|
||||
cocostudio::SceneReader::getInstance()->purgeSceneReader();
|
||||
cocostudio::ActionManagerEx::purgeActionManager();
|
||||
}
|
||||
|
||||
void CocosGUITestScene::runThisTest()
|
||||
{
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
|
||||
Size s = Director::getInstance()->getWinSize();
|
||||
|
||||
_itemMenu = Menu::create();
|
||||
_itemMenu->setPosition(Point::ZERO);
|
||||
MenuItemFont::setFontName("Arial");
|
||||
MenuItemFont::setFontSize(24);
|
||||
for (int i = 0; i < sizeof(gui_scene_names) / sizeof(gui_scene_names[0]); ++i)
|
||||
{
|
||||
auto item = MenuItemFont::create(gui_scene_names[i],
|
||||
CC_CALLBACK_1( CocosGUITestScene::menuCallback, this));
|
||||
item->setPosition(Point(s.width / 2, s.height - s.height / 4 - (i + 1) * 40));
|
||||
item->setTag(i);
|
||||
_itemMenu->addChild(item);
|
||||
}
|
||||
addChild(_itemMenu);
|
||||
}
|
||||
void CocosGUITestScene::MainMenuCallback(Ref* pSender)
|
||||
{
|
||||
auto pScene = new ExtensionsTestScene();
|
||||
pScene->runThisTest();
|
||||
}
|
||||
|
||||
void CocosGUITestScene::load(Ref *pSender, int count)
|
||||
{
|
||||
char tmp[10];
|
||||
sprintf(tmp,"%d", count);
|
||||
_label->setString(CCString::createWithFormat("%i", count)->getCString());
|
||||
}
|
||||
|
||||
void CocosGUITestScene::menuCallback(Ref *pSender)
|
||||
{
|
||||
auto pItem = static_cast<MenuItemFont*>(pSender);
|
||||
|
||||
switch (pItem->getTag())
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
UISceneManager* pManager = UISceneManager::sharedUISceneManager();
|
||||
Scene* pScene = pManager->currentUIScene();
|
||||
Director::getInstance()->replaceScene(pScene);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -30,14 +30,14 @@
|
|||
#include "../../testBasic.h"
|
||||
#include "gui/CocosGUI.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::extension;
|
||||
using namespace ui;
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
using namespace cocos2d::ui;
|
||||
|
||||
class CocosGUITestMainLayer : public Layer
|
||||
{
|
||||
public:
|
||||
virtual void onEnter() override;
|
||||
virtual void onEnter();
|
||||
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event *event);
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event *event);
|
||||
|
@ -51,7 +51,9 @@ public:
|
|||
class CocosGUITestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void onEnter();
|
||||
virtual void runThisTest();
|
||||
void BackCallback(Ref* pSender);
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
|
||||
|
||||
#include "CustomImageTest.h"
|
||||
#include "../../CutomGUIScene.h"
|
||||
#include "../../CustomWidget/CustomImageView.h"
|
||||
#include "../../CustomWidget/CustomImageViewReader.h"
|
||||
#include "../../CustomWidget/CustomReader.h"
|
||||
#include "cocostudio/CCSGUIReader.h"
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark CustomImageLayer
|
||||
#pragma mark -
|
||||
|
||||
void CustomImageLayer::onEnter()
|
||||
{
|
||||
Layer::onEnter();
|
||||
|
||||
GUIReader* guiReader = GUIReader::getInstance();
|
||||
guiReader->registerTypeAndCallBack("CustomImageView",
|
||||
&CustomImageView::createInstance,
|
||||
CustomImageViewReader::getInstance(),
|
||||
parseselector(CustomImageViewReader::setProperties));
|
||||
|
||||
Layout* layout = static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/CustomImageViewTest/NewProject_2_1.ExportJson"));
|
||||
addChild(layout);
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark CustomImageScene
|
||||
#pragma mark -
|
||||
|
||||
void CustomImageScene::onEnter()
|
||||
{
|
||||
CCScene::onEnter();
|
||||
|
||||
LabelTTF* label = LabelTTF::create("Back", "Arial", 20);
|
||||
//#endif
|
||||
MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CustomImageScene::BackCallback, this));
|
||||
|
||||
Menu* pMenu = Menu::create(pMenuItem, NULL);
|
||||
|
||||
pMenu->setPosition( Point::ZERO );
|
||||
pMenuItem->setPosition( Point( VisibleRect::right().x - 50, VisibleRect::bottom().y + 25) );
|
||||
|
||||
addChild(pMenu, 1);
|
||||
}
|
||||
|
||||
void CustomImageScene::runThisTest()
|
||||
{
|
||||
Layer* pLayer = new CustomImageLayer();
|
||||
addChild(pLayer);
|
||||
pLayer->release();
|
||||
|
||||
CCDirector::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
void CustomImageScene::BackCallback(Ref* pSender)
|
||||
{
|
||||
CustomGUITestScene* pScene = new CustomGUITestScene();
|
||||
pScene->runThisTest();
|
||||
pScene->release();
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
|
||||
#ifndef __TestCpp__CustomImageScene__
|
||||
#define __TestCpp__CustomImageScene__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
#include "../../../../testBasic.h"
|
||||
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
class CustomImageLayer : public Layer
|
||||
{
|
||||
public:
|
||||
virtual void onEnter();
|
||||
};
|
||||
|
||||
class CustomImageScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void onEnter();
|
||||
virtual void runThisTest();
|
||||
void BackCallback(Ref* pSender);
|
||||
};
|
||||
|
||||
#endif /* defined(__TestCpp__CustomUIScene__) */
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
|
||||
#include "CustomImageView.h"
|
||||
|
||||
CustomImageView::CustomImageView()
|
||||
: _label(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CustomImageView::~CustomImageView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Ref* CustomImageView::createInstance()
|
||||
{
|
||||
return create();
|
||||
}
|
||||
|
||||
CustomImageView* CustomImageView::create()
|
||||
{
|
||||
CustomImageView* custom = new CustomImageView();
|
||||
|
||||
if (custom && custom->init())
|
||||
{
|
||||
custom->autorelease();
|
||||
return custom;
|
||||
}
|
||||
CC_SAFE_DELETE(custom);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CustomImageView::init()
|
||||
{
|
||||
if (ImageView::init())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CustomImageView::initRenderer()
|
||||
{
|
||||
ImageView::initRenderer();
|
||||
|
||||
_label = LabelTTF::create();
|
||||
CCNodeRGBA::addChild(_label, getZOrder() + 1, -1);
|
||||
}
|
||||
|
||||
void CustomImageView::setText(const std::string &text)
|
||||
{
|
||||
_label->setString(text.c_str());
|
||||
}
|
||||
|
||||
const std::string& CustomImageView::getText() const
|
||||
{
|
||||
return _label->getString();
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#ifndef __TestCpp__CustomImageView__
|
||||
#define __TestCpp__CustomImageView__
|
||||
|
||||
#include "CocosGUI.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace cocos2d::ui;
|
||||
|
||||
class CustomImageView : public ImageView
|
||||
{
|
||||
public:
|
||||
|
||||
CustomImageView();
|
||||
~CustomImageView();
|
||||
|
||||
static CustomImageView* create();
|
||||
static Ref* createInstance();
|
||||
|
||||
void setText(const std::string& text);
|
||||
const std::string& getText() const;
|
||||
|
||||
protected:
|
||||
virtual bool init() override;
|
||||
virtual void initRenderer() override;
|
||||
|
||||
protected:
|
||||
LabelTTF* _label;
|
||||
};
|
||||
|
||||
#endif /* defined(__TestCpp__CustomImageView__) */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue