SlateApplication学习

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容