PlainNode.cpp 1.66 KB
//
//  PlainNode.cpp
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 17.05.2017.
//
//

#include <stdio.h>
#include "PlainNode.h"
#include "JSONParseUtils.h"
#include "ScalingUtils.h"

PlainNode* PlainNode::create()
{
    PlainNode * node = new (std::nothrow) PlainNode();
    if(node && node->init())
    {
        node->autorelease();
        return node;
    }
    CC_SAFE_DELETE(node);
    return nullptr;
}

PlainNode* PlainNode::createWithColour(cocos2d::Color4B color){
    auto node = create();
    if(node != nullptr){
        node->_backgroundLayer = cocos2d::LayerColor::create(color);
        node->_backgroundLayer->setAnchorPoint(cocos2d::Vec2(0.5, 0.5));
        node->_backgroundLayer->setContentSize(node->getContentSize());
        node->_backgroundLayer->setPosition(cocos2d::Vec2(node->getContentSize().width/2, node->getContentSize().height/2));
        node->addChild(node->_backgroundLayer);
    }
    return node;
}

void PlainNode::loadPropertiesFromJSON(const rapidjson::Value& jsonValue, LayoutViewInterface* scene, const std::string resFolder, const std::string altResFolder)
{
    this->setAnchorPoint(cocos2d::Point(0.5, 0.5));
    this->loadCommonPropertiesFromJSON(jsonValue);
    if(JSONParseUtils::hasMemberBool(jsonValue, "adjustContentSizeForSmallDevices") && ScalingUtils::isSmallDevice()){
        auto scale = ScalingUtils::getScaleForSmallDevice();
        setContentSize(this->getContentSize()*scale);//,this->getContentSize().height*scale);
    }
}

void PlainNode::prepareSize(const rapidjson::Value& jsonValue, float& width, float& height)
{
    width = this->getContentSize().width;
    height = this->getContentSize().height;
}