SDL2如何在第二个监视器上放置窗口? [英] SDL2 How to position a window on a second monitor?

查看:304
本文介绍了SDL2如何在第二个监视器上放置窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SDL_SetWindowPosition定位窗口.我可以使用此功能将窗口放置在另一台监视器上吗?

I am using SDL_SetWindowPosition to position my window. Can I use this function to position my window on another monitor?

更新

在Windows 10中更改文本大小时,使用SDL_GetDisplayBounds不会返回正确的监视器位置.有什么办法解决此问题吗?

Using SDL_GetDisplayBounds will not return the correct monitor positions when the text size is changed in Windows 10. Any ideas how to fix this?

推荐答案

SDL2使用全局屏幕空间坐标系.每个显示设备在此坐标空间内都有自己的边界.下面的示例在另一个显示设备上放置一个窗口:

SDL2 uses a global screen space coordinate system. Each display device has its own bounds inside this coordinate space. The following example places a window on a second display device:

// enumerate displays
int displays = SDL_GetNumVideoDisplays();
assert( displays > 1 );  // assume we have secondary monitor

// get display bounds for all displays
vector< SDL_Rect > displayBounds;
for( int i = 0; i < displays; i++ ) {
    displayBounds.push_back( SDL_Rect() );
    SDL_GetDisplayBounds( i, &displayBounds.back() );
}

// window of dimensions 500 * 500 offset 100 pixels on secondary monitor
int x = displayBounds[ 1 ].x + 100;
int y = displayBounds[ 1 ].y + 100;
int w = 500;
int h = 500;

// so now x and y are on secondary display
SDL_Window * window = SDL_CreateWindow( "title", x, y, w, h, FLAGS... );

看看SDL_video.hSDL_WINDOWPOS_CENTERED的定义,我们将其定义为

Looking at the definition of SDL_WINDOWPOS_CENTERED in SDL_video.h we see it is defined as

#define SDL_WINDOWPOS_CENTERED         SDL_WINDOWPOS_CENTERED_DISPLAY(0)

所以我们也可以使用宏SDL_WINDOWPOS_CENTERED_DISPLAY( n ),其中n是显示索引.

so we could also use the macro SDL_WINDOWPOS_CENTERED_DISPLAY( n ) where n is the display index.

Windows 10更新-DPI缩放问题

似乎SDL2和在Windows中更改DPI比例(即文本比例)确实存在错误.

It seems like there is indeed a bug with SDL2 and changing the DPI scale in Windows (i.e. text scale).

以下是与该问题相关的两个错误报告.他们两个显然仍未解决.

Here are two bug reports relevant to the problem. They are both still apparently unresolved.

https://bugzilla.libsdl.org/show_bug.cgi?id=3433

https://bugzilla.libsdl.org/show_bug.cgi?id=2713

潜在的解决方案

我确信OP可以使用WIN32 api来确定scale != 100%的dpi比例,然后以此来校正界限.

I am sure that the OP could use the WIN32 api to determine the dpi scale, for scale != 100%, and then correct the bounds by that.

这篇关于SDL2如何在第二个监视器上放置窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆