SDL中文论坛
标题:
twidget::orientation_swap_size
[打印本页]
作者:
ancientcc
时间:
2016-5-15 21:10
标题:
twidget::orientation_swap_size
本帖最后由 ancientcc 于 2020-11-7 15:18 编辑
横屏尺寸。宽度总是大于高度的尺寸。在配置中存储的总是模屏尺寸。
朝向尺寸。和当前朝向一样的尺寸。模屏尺寸+当前朝向==>朝向尺寸,朝向不是存储在配置中,而是写在app内在逻辑。
根据当前要求的朝向,须要的话互换宽度和高度。互换条件:当前要求的朝向不是横屏就互换。从使用角度归纳,该函数可方便实现横屏尺寸、朝向尺寸之间相互转换。
语法
tpoint twidget::orientation_swap_size(int width, int height)
复制代码
参数
width
计算了hdpi_scale
height
计算了hdpi_scale
(width、height)或是横屏尺寸,或是朝向尺寸。
返回值
tpoint.x指示结果的宽度、tpoint.y指示结果的高度。
范例
tpoint revise_screen_size(const int width, const int height)
{
tpoint landscape_size = twidget::orientation_swap_size(width, height);
if (landscape_size.x < preferences::min_allowed_width()) {
landscape_size.x = preferences::min_allowed_width();
}
if (landscape_size.y < preferences::min_allowed_height()) {
landscape_size.y = preferences::min_allowed_height();
}
tpoint normal_size = twidget::orientation_swap_size(landscape_size.x, landscape_size.y);
return normal_size;
}
第一个orientation_swap_size从朝向尺寸得到横屏尺寸,然后确保尺寸不小于容许尺寸,第二个orientation_swap_size从横屏尺寸恢复回朝向尺寸。
复制代码
注释
一般用在两种场合。
从横屏尺寸得到朝向尺寸。举个例子,配置中存的是横屏尺寸,App启动时调用该函数得到朝向尺寸。
从朝向尺寸得到横屏尺寸。
相关类、函数
bool twidget::landscape_from_orientation(torientation orientation, bool def)
复制代码
根据指定的朝向值判断是否要求横屏。orientation设定了自动判断时,取def,否则取orientation。它的一个主要作用是根据窗口中的“orientation”字段判断显示该窗口要使用什么朝向。
bool twidget::should_conside_orientation(const int width, const int height)
复制代码
判断指定的尺寸是否要考虑朝向。当窗口尺寸已经很大时,会认为不必再考虑横屏竖屏了,像iPad。当前使用不必考虑的最小值是都宽度、高度都大于540。width、height是计算了hdpi_scale。
欢迎光临 SDL中文论坛 (http://www.libsdl.cn/bbs/)
Powered by Discuz! X3.3