// // AniScalingUtils.cpp // SteveMaggieCpp // // Created by Katarzyna Kalinowska-Górska on 18.05.2017. // // #include #include "AniScalingUtils.h" bool AniScalingUtils::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 AniScalingUtils::isElementTooSmallForSmallDevice(int elementWidth){ return elementWidth < 300; } float AniScalingUtils::getScaleForSmallDevice(){ return 1.4f; } float AniScalingUtils::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 AniScalingUtils::getDeviceAspectRatio(){ static float currentDeviceAspectRatio = cocos2d::Director::getInstance()->getWinSize().width / cocos2d::Director::getInstance()->getWinSize().height; return currentDeviceAspectRatio; } void AniScalingUtils::setScaledScreenSurplusSize(float width, float height) { _scaledScreenSurplusWidth = width; _scaledScreenSurplusWidth = height; } float AniScalingUtils::getScaledScreenSurplusWidth() { return _scaledScreenSurplusWidth; } float AniScalingUtils::getScaledScreenSurplusHeight() { return _scaledScreenSurplusHeight; } float AniScalingUtils::widthScale(){ auto winSize = cocos2d::Director::getInstance()->getWinSize(); auto ipadProSize = getDesignSize(); return winSize.width / ipadProSize.width;// * designDpi / dpi; } float AniScalingUtils::heightScale(){ auto winSize = cocos2d::Director::getInstance()->getWinSize(); auto ipadProSize = getDesignSize(); return winSize.height / ipadProSize.height;// * designDpi / dpi; } float AniScalingUtils::scaleAspectFitToDesignIpadProSize(){ auto winSize = cocos2d::Director::getInstance()->getWinSize(); auto ipadProSize = getDesignSize(); return MIN(winSize.width / ipadProSize.width, winSize.height / ipadProSize.height); } float AniScalingUtils::scaleAspectFillToDesignIpadProSize(){ auto winSize = cocos2d::Director::getInstance()->getWinSize(); auto ipadProSize = getDesignSize(); return MAX(winSize.width / ipadProSize.width, winSize.height / ipadProSize.height); } float AniScalingUtils::getScaleForFont(){ return 1.f/cocos2d::Director::getInstance()->getContentScaleFactor(); } // cocos2d::Size AniScalingUtils::getDesignSize(){ return cocos2d::Size(2732, 2048); } float AniScalingUtils::getDesignDpi(){ return 266.f; } float AniScalingUtils::imageAspectFillGetScale(cocos2d::Size nodeSize, cocos2d::Size targetSize) { return MAX(targetSize.width / nodeSize.width, targetSize.height / nodeSize.height); } float AniScalingUtils::imageAspectFitGetScale(cocos2d::Size nodeSize, cocos2d::Size targetSize) { return MIN(targetSize.width / nodeSize.width, targetSize.height / nodeSize.height); } float AniScalingUtils::configureNodeDimension(float originalDimension) { float scale = cocos2d::Director::getInstance()->getContentScaleFactor(); return originalDimension/scale; } cocos2d::Point AniScalingUtils::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 AniScalingUtils::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); }