// // ToyScalingUtils.cpp // SteveMaggieCpp // // Created by Katarzyna Kalinowska-Górska on 18.05.2017. // // #include #include "ToyScalingUtils.h" bool ToyScalingUtils::isSmallDevice(){ int dpi = cocos2d::Device::getDPI(); float xInches = cocos2d::Director::getInstance()->getWinSize().width / dpi; float yInches = cocos2d::Director::getInstance()->getWinSize().height / dpi; float diagonalInches = sqrtf(xInches * xInches + yInches * yInches); diagonalInches = roundf(diagonalInches * 100.0f) / 100.0f; return diagonalInches < 7.0f; } bool ToyScalingUtils::isElementTooSmallForSmallDevice(int elementWidth){ return elementWidth < 300; } float ToyScalingUtils::getScaleForSmallDevice(){ return 1.4f; } float ToyScalingUtils::getAspectRatioBasedModifierForVelocity(){ static float designTabletAspectRatio = 2560.f / 1600.f;//my huawei media pad m5 static float currentDeviceAspectRatio = cocos2d::Director::getInstance()->getWinSize().width / cocos2d::Director::getInstance()->getWinSize().height; if(currentDeviceAspectRatio < 1.4){ //around 1.333 is an ipad, and it's too difficult for ipads - so this is a fix return 0.9f;//currentDeviceAspectRatio / designTabletAspectRatio; } return 1.0f; //else just leave the velocity as it is - let is adjust based on scale factor only } float ToyScalingUtils::getDeviceAspectRatio(){ static float currentDeviceAspectRatio = cocos2d::Director::getInstance()->getWinSize().width / cocos2d::Director::getInstance()->getWinSize().height; return currentDeviceAspectRatio; } void ToyScalingUtils::setScaledScreenSurplusSize(float width, float height) { _scaledScreenSurplusWidth = width; _scaledScreenSurplusWidth = height; } float ToyScalingUtils::getScaledScreenSurplusWidth() { return _scaledScreenSurplusWidth; } float ToyScalingUtils::getScaledScreenSurplusHeight() { return _scaledScreenSurplusHeight; } float ToyScalingUtils::widthScale(){ auto winSize = cocos2d::Director::getInstance()->getWinSize(); auto ipadProSize = getDesignSize(); return winSize.width / ipadProSize.width;// * designDpi / dpi; } float ToyScalingUtils::heightScale(){ auto winSize = cocos2d::Director::getInstance()->getWinSize(); auto ipadProSize = getDesignSize(); return winSize.height / ipadProSize.height;// * designDpi / dpi; } float ToyScalingUtils::scaleAspectFitToDesignIpadProSize(){ auto winSize = cocos2d::Director::getInstance()->getWinSize(); auto ipadProSize = getDesignSize(); return MIN(winSize.width / ipadProSize.width, winSize.height / ipadProSize.height); } float ToyScalingUtils::scaleAspectFillToDesignIpadProSize(){ auto winSize = cocos2d::Director::getInstance()->getWinSize(); auto ipadProSize = getDesignSize(); return MAX(winSize.width / ipadProSize.width, winSize.height / ipadProSize.height); } float ToyScalingUtils::getScaleForFont(){ return 1.f/cocos2d::Director::getInstance()->getContentScaleFactor(); } // cocos2d::Size ToyScalingUtils::getDesignSize(){ return cocos2d::Size(2732, 2048); } float ToyScalingUtils::getDesignDpi(){ return 266.f; } float ToyScalingUtils::imageAspectFillGetScale(cocos2d::Size nodeSize, cocos2d::Size targetSize) { return MAX(targetSize.width / nodeSize.width, targetSize.height / nodeSize.height); } float ToyScalingUtils::imageAspectFitGetScale(cocos2d::Size nodeSize, cocos2d::Size targetSize) { return MIN(targetSize.width / nodeSize.width, targetSize.height / nodeSize.height); } float ToyScalingUtils::configureNodeDimension(float originalDimension) { float scale = cocos2d::Director::getInstance()->getContentScaleFactor(); return originalDimension/scale; } cocos2d::Point ToyScalingUtils::configurePoint(cocos2d::Point point) { auto scale = cocos2d::Director::getInstance()->getContentScaleFactor(); auto additionalPaddingW = _scaledScreenSurplusWidth/2; auto additionalPaddingH = _scaledScreenSurplusHeight/2; return cocos2d::Point(point.x/scale+additionalPaddingW, point.y/scale+additionalPaddingH); } cocos2d::Rect ToyScalingUtils::configureRect(cocos2d::Rect rect) { auto scale = cocos2d::Director::getInstance()->getContentScaleFactor(); auto additionalPaddingW = _scaledScreenSurplusWidth/2; auto additionalPaddingH = _scaledScreenSurplusHeight/2; return cocos2d::Rect(rect.origin.x/scale+additionalPaddingW, rect.origin.y/scale+additionalPaddingH, rect.size.width/scale, rect.size.height/scale); }