예제 #1
0
MVector2 MGui2d::getMouseLocalPosition(void)
{
	MVector2 mousePosition;
	MMouse * mouse = MMouse::getInstance();

	if(m_parentWindow)
	{
		if(isScrollAffected())
		{
			mousePosition.set(
				mouse->getXPosition() - m_parentWindow->getPosition().x - m_parentWindow->getScroll().x, 
				mouse->getYPosition() - m_parentWindow->getPosition().y - m_parentWindow->getScroll().y
				);
		}
		else
		{
			mousePosition.set(
				mouse->getXPosition() - m_parentWindow->getPosition().x, 
				mouse->getYPosition() - m_parentWindow->getPosition().y
				);
		}
	}
	else{
		mousePosition.set((float)mouse->getXPosition(), (float)mouse->getYPosition());
	}

	return mousePosition;
}
예제 #2
0
파일: MX11Window.cpp 프로젝트: galek/MIngEd
bool MWindow::isMouseOverWindow(void)
{
	MMouse * mouse = MMouse::getInstance();
	int x = mouse->getXPosition();
	int y = mouse->getYPosition();

	if(x >= 0 && y >= 0 && x < (int)getWidth() && y < (int)getHeight())
		return true;

	return false;
}
예제 #3
0
bool MWindow::onEvents(void)
{
	JOYCAPS	caps;
	MWindow * window = MWindow::getInstance();

	// joystick 1
	if(joyGetDevCaps(JOYSTICKID1, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR)
	{
		JOYINFOEX joyinfo;
		MJoystick * joystick = window->getJoystick1();

		joyinfo.dwSize = sizeof(JOYINFOEX);
		memset(&(joyinfo.dwFlags), 0, sizeof(JOYINFOEX) - sizeof(DWORD));
		joyinfo.dwFlags = JOY_RETURNALL;

		joyGetPosEx(JOYSTICKID1, &joyinfo);
		updateJoystick(joystick, &caps, &joyinfo);

		MWinEvent events;
		events.type = MWIN_EVENT_JOYSTICK1_UPDATE;
		window->sendEvents(&events);

		joystick->flush();
	}

	// joystick 2
	if(joyGetDevCaps(JOYSTICKID2, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR)
	{
		JOYINFOEX joyinfo;
		MJoystick * joystick = window->getJoystick2();

		joyinfo.dwSize = sizeof(JOYINFOEX);
		memset(&(joyinfo.dwFlags), 0, sizeof(JOYINFOEX) - sizeof(DWORD));
		joyinfo.dwFlags = JOY_RETURNALL;

		joyGetPosEx(JOYSTICKID2, &joyinfo);
		updateJoystick(joystick, &caps, &joyinfo);

		MWinEvent events;
		events.type = MWIN_EVENT_JOYSTICK2_UPDATE;
		window->sendEvents(&events);

		joystick->flush();
	}

	// mouse move event
	{
		POINT p;
		MWinEvent events;
		MMouse * mouse = MMouse::getInstance();

		GetCursorPos(&p);
		p.x -= window->getXPosition();
		p.y -= window->getYPosition();

		int dx = p.x - mouse->getXPosition();
		int dy = p.y - mouse->getYPosition();
		if((dx != 0) || (dy != 0))
		{
			mouse->setPosition(p.x, p.y);

			events.type = MWIN_EVENT_MOUSE_MOVE;
			events.data[0] = p.x;
			events.data[1] = p.y;
			window->sendEvents(&events);
		}
	}

	MSG msg;
	if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
		return false;
	}

	return true;
}