简体   繁体   English

如何根据窗口客户区相对于屏幕的位置设置 Direct Draw Clipper

[英]How to set Direct Draw clipper according to window's client area position relative to the screen

I'm adding Direct Draw rendering option to my 2D Graphics Engine.我正在向我的 2D 图形引擎添加 Direct Draw 渲染选项。

When setting the Direct Draw Clipper on a non fullscreen application clipper clips the client area with an offset if the Window's client area top left position is not on the 0,0 of the screen.在非全屏应用程序上设置 Direct Draw Clipper 时,如果 Window 的客户区左上角位置不在屏幕的 0,0 上,则剪辑器会使用偏移量剪辑客户区。

Here is my clipper setup code :这是我的剪刀设置代码:

LPDIRECTDRAWCLIPPER directDrawClipper = nullptr;
if (!FAILED(mDirectDraw->CreateClipper(0, &directDrawClipper, NULL))) {
    if (!FAILED(directDrawClipper->SetHWnd(0, App->getWindow()->getHandle()))) {
        if (!FAILED(mDirectDrawFrontBuffer->SetClipper(directDrawClipper))) {
            if (!FAILED(mDirectDrawBackBuffer->SetClipper(directDrawClipper))) {    
                return true; //all good
            } else {
                throw Error::Exception(L"DirectDraw arka görüntü bellek tamponu kesicisi kurulamadı", 
                                       L"Renderer Kurulum Hatası");
            }
        } else {
            throw Error::Exception(L"DirectDraw ana görüntü bellek tamponu kesicisi kurulamadı", 
                                   L"Renderer Kurulum Hatası");
        }
    } else {
        throw Error::Exception(L"DirectDraw kesicisi pencereye kurulamadı", 
                               L"Renderer Kurulum Hatası");
    }
} else {
    throw Error::Exception(L"DirectDraw kesicisi kurulamadı", 
                           L"Renderer Kurulum Hatası");
}
    

And here is the screenshot :这是屏幕截图:

在此处输入图片说明

the size of the white areas are the distance of client area to the screen upper left corner.白色区域的大小是客户区到屏幕左上角的距离。

Moving the window to upper left corner of the screen before setting the clipper and moving it back to original position doesn't help.在设置剪刀之前将窗口移动到屏幕的左上角并将其移回原始位置并没有帮助。

Thanks in advance.提前致谢。

For the curious I solved the problem with a hack.出于好奇,我用 hack 解决了这个问题。

Before setting the clipper move the window to a position which the client area of the window will be on 0,0 of the screen.在设置裁剪器之前,将窗口移动到窗口客户区位于屏幕 0,0 的位置。 You can use ClientToScreen function to determine the window position which client area will be on the 0,0 of the screen.您可以使用ClientToScreen函数来确定哪个客户区将在屏幕的 0,0 上的窗口位置。

After setting up the DirectDraw move the window back to it's original position but there is a problem, if you move the window immediately after setting up the DirectDraw issue persists.设置 DirectDraw 后,将窗口移回其原始位置,但存在问题,如果在设置 DirectDraw 后立即移动窗口,问题仍然存在。 (I believe clipper setting functions works async). (我相信剪刀设置功能是异步的)。 To solve that you can set a windows timer , right after setting the DirectDraw set a timer (1 second got the job done in my case) and move window back to it's original position when the timer updates.为了解决这个问题,您可以设置一个 windows timer ,在设置 DirectDraw 后立即设置一个计时器(在我的情况下,1 秒完成了工作)并在计时器更新时将窗口移回其原始位置。

To summarize the process :总结一下这个过程:

  • Move window to a new position which client area of the window will be on the 0,0 of the screen.将窗口移动到一个新位置,窗口的客户区将位于屏幕的 0,0。
  • Set up the clipper设置剪刀
  • Set a timer (1 second worked in my case)设置计时器(在我的情况下为 1 秒)
  • When timer updates move window back the it's original position.当计时器更新时,将窗口移回其原始位置。

But still if someone knows the proper solution it would be nice.但是,如果有人知道正确的解决方案,那就太好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM