CCursorControl of CIrrDeviceWin32.h

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
jolindien
Posts: 16
Joined: Sun Jul 16, 2006 3:00 pm
Location: Lyon (France)

CCursorControl of CIrrDeviceWin32.h

Post by jolindien »

There s problem in this cursor class that is messing up positions of the cursors on resizable windows under win32.

2 variables of CCursorControl are not updated on a window resize and thus are wrong :

Code: Select all

core::dimension2d<s32> WindowSize;
core::dimension2d<float> InvWindowSize;
Personnally i did a small function in this class:

Code: Select all

void CCursorControl::updateWindowProperties()
			{
				RECT rect;
				if (GetWindowRect(HWnd, &rect))
				{
					WindowSize.Width = rect.right-rect.left;
					WindowSize.Height = rect.bottom-rect.top;
					
					if (WindowSize.Width!=0)
						InvWindowSize.Width = 1.0f / WindowSize.Width;
					else 
						InvWindowSize.Width = 0.0f;

					if (WindowSize.Height!=0)
						InvWindowSize.Height = 1.0f / WindowSize.Height;
					else 
						InvWindowSize.Height = 0.0f;
				}
			}
And this function is called on window resize in CIrrDeviceWin32.cpp :

Code: Select all

void CIrrDeviceWin32::resizeIfNecessary()
{
	if (!Resized)
		return;

	RECT r;
	GetClientRect(HWnd, &r);

	char tmp[255];

	if (r.right <= 1 || r.bottom <= 1)
	{
		sprintf(tmp, "Ignoring resize operation to (%d %d)", r.right, r.bottom);
		os::Printer::log(tmp);
	}
	else
	{
		sprintf(tmp, "Resizing window (%d %d)", r.right, r.bottom);
		os::Printer::log(tmp);

		if ( r.right % 2 )
			r.right += 1;

		if ( r.bottom % 2 )
			r.bottom += 1;

		getVideoDriver()->OnResize(irr::core::dimension2d<irr::s32>(r.right, r.bottom));
		
		// update cursor properties
		Win32CursorControl->updateWindowProperties();
	}

	Resized = false;
}
Of course, other solutions do exist...
Post Reply