SlateApplication学习

2018-04-27  本文已影响0人  handBag

1 一些基本函数的学习

FSlateApplication在构造函数里,会调用一个SetupPhysicalSensitivities函数.

const float DragTriggerDistanceInInches = FUnitConversion::Convert(1.0f, EUnit::Millimeters, EUnit::Inches);
FPlatformApplicationMisc::ConvertInchesToPixels(DragTriggerDistanceInInches, DragTriggerDistance);
#if PLATFORM_DESKTOP
    DragTriggerDistance = FMath::Max(DragTriggerDistance, 5.0f);
#else
    DragTriggerDistance = FMath::Max(DragTriggerDistance, 10.0f);
#endif

    FGestureDetector::LongPressAllowedMovement = DragTriggerDistance;

第一句作用是将1mm变成一英寸

第二句是根据平台将对应的英寸值转为像素数量

ConvertInchesToPixels函数,

执行过程
1 先获取真正的dpi数据

int32 ScreenDensity;
EScreenPhysicalAccuracy Accuracy = GetPhysicalScreenDensity(ScreenDensity);

2 GetPhysicalScreenDensity 做了一层缓存,保证只计算一次

CachedPhysicalScreenData = true;
CachedPhysicalScreenAccuracy = 
FPlatformApplicationMisc::ComputePhysicalScreenDensity(CachedPhysicalScreenDensity);

3 ComputePhysicalScreenDensity函数里
3.1 首先从配置文件里判断有没有DeviceScreenDensity选项
3.2 如果有,则直接返回,否则下一不
3.3 通过下面的函数
AndroidThunkCpp_GetMetaDataString(TEXT("ue4.displaymetrics.dpi"));
调用Java里的函数
3.4 核心函数如下:

if (key.equals("ue4.displaymetrics.dpi"))
{
  DisplayMetrics metrics = new DisplayMetrics();
  if (android.os.Build.VERSION.SDK_INT >= 17)
  {
    getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
  } else {
  // note: not available so get what we can
  getWindowManager().getDefaultDisplay().getMetrics(metrics);
  }
            
  }

此函数作用就是返回水平方向的dpi和竖直方向的dpi,和与标准dpi的关系,标准dpi是160

4 最终值会保存在
FGestureDetector::LongPressAllowedMovement

上一篇 下一篇

猜你喜欢

热点阅读