Example #1
0
void MWindow::sendEvents(MWinEvent * events)
{
	MKeyboard * keyboard = MKeyboard::getInstance();
	MMouse * mouse = MMouse::getInstance();

	switch(events->type)
	{
		case MWIN_EVENT_KEY_DOWN:
			keyboard->onKeyDown(events->data[0]);
			break;

		case MWIN_EVENT_KEY_UP:
			keyboard->onKeyUp(events->data[0]);
			break;

		case MWIN_EVENT_WINDOW_RESIZE:
			m_width = (unsigned int)events->data[0];
			m_height = (unsigned int)events->data[1];
			break;

		case MWIN_EVENT_WINDOW_MOVE:
			m_position[0] = events->data[0];
			m_position[1] = events->data[1];
			break;

		case MWIN_EVENT_MOUSE_BUTTON_DOWN:
			mouse->downButton(events->data[0]);
			break;

		case MWIN_EVENT_MOUSE_BUTTON_UP:
			mouse->upButton(events->data[0]);
			break;

		case MWIN_EVENT_MOUSE_WHEEL_MOVE:
			mouse->setWheelDirection(events->data[0]);
			break;

		case MWIN_EVENT_MOUSE_MOVE:
			mouse->setPosition(events->data[0], events->data[1]);
			break;
	}

	if(m_pointerEvent)
		m_pointerEvent(events);
}
Example #2
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;
}