Page 1 of 1

getScreenSize() bug (Win)

Posted: Thu Mar 20, 2014 4:52 pm
by sawada
I've found a bug.

getScreenSize() is expected to return a value of a window's client area.
But, Only when using the external window , getScreenSize() is not that.

because GetWindowRect() is used.
GetClientRect() is correctly.

irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWin32.cpp
line1010-

Code: Select all

 
    else if (CreationParams.WindowId)
    {
        // attach external window
        HWnd = static_cast<HWND>(CreationParams.WindowId);
        RECT r;
        GetWindowRect(HWnd, &r);
        CreationParams.WindowSize.Width = r.right - r.left;
        CreationParams.WindowSize.Height = r.bottom - r.top;
        CreationParams.Fullscreen = false;
        ExternalWindow = true;
    }
 

Re: getScreenSize() bug (Win)

Posted: Thu Mar 20, 2014 7:05 pm
by CuteAlien
Yeah - that looks wrong on first view. Thanks sawada, I'll check it next time I'm working on Windows (I'm a little surprised it doesn't cause troubles already, so I will have to write some test for it first before changing that).

Re: getScreenSize() bug (Win)

Posted: Wed Mar 26, 2014 11:29 pm
by hybrid
Well, you usually use some frame or render pane inside the actual window as the WindowId given here. That's why you usually don't have to bother with those different sizes. At least that's what our examples do.

Re: getScreenSize() bug (Win)

Posted: Thu Mar 27, 2014 4:03 am
by thanhle
Yup, when render to a window or a control, client rectangle is the actual target.
This was the issue I have before, as the mouse position wasn't correct when I do collision test on multiple windows (> 4). But as I fixed it without doing anything to irrlicht for future compatibility.

---Just a side note
If you have MDI render child windows. You might also want to update your mouse referenceRect relative to each window when you move it.

Point p = this->PointToScreen(this->ClientRectangle.Location); //Sorry this was .net for the position of the client window.
core::rect<s32> rec = core::rect<s32>(p.X, p.Y, p.X + this->ClientRectangle.Width, p.Y + this->ClientRectangle.Height);
device->getCursorControl()->setReferenceRect(&rec);
Also reset aspect ratio and call resize when ever you resize your window.
driver->OnResize(newsize);

Re: getScreenSize() bug (Win)

Posted: Thu Mar 27, 2014 10:31 am
by CuteAlien
@hybrid: So... this needs to be fixed or not?

Re: getScreenSize() bug (Win)

Posted: Thu Mar 27, 2014 10:14 pm
by hybrid
I always thought that you need some extra pane or so to render to and never used mouse controls on such things. But if there's some offset in certain situations, we probably have to fix this. Maybe someone can set up an example where the offset occurs? Can we simplify example 14?