Ejemplo n.º 1
0
void WzMainWindow::mouseReleaseEvent(QMouseEvent *event)
{
	mouseXPos = event->x();
	mouseYPos = event->y();

	MOUSE_KEY_CODE idx = buttonToIdx(event->button());

	if (idx == MOUSE_BAD)
	{
		return; // not recognized mouse button
	}

	MousePress mousePress;
	mousePress.action = MousePress::Release;
	mousePress.key = idx;
	mousePress.pos = Vector2i(mouseXPos, mouseYPos);
	mousePresses.push_back(mousePress);

	aMouseState[idx].releasePos.x = mouseXPos;
	aMouseState[idx].releasePos.y = mouseYPos;

	if (aMouseState[idx].state == KEY_PRESSED)
	{
		aMouseState[idx].state = KEY_PRESSRELEASE;
	}
	else if (aMouseState[idx].state == KEY_DOWN
			|| aMouseState[idx].state == KEY_DRAG
			|| aMouseState[idx].state == KEY_DOUBLECLICK)
	{
		aMouseState[idx].state = KEY_RELEASED;
	}
}
Ejemplo n.º 2
0
// TODO consider using QWidget::mouseDoubleClickEvent() for double-click
void WzMainWindow::mousePressEvent(QMouseEvent *event)
{
	mouseXPos = event->x();
	mouseYPos = event->y();

	Qt::MouseButtons presses = event->buttons();	// full state info for all buttons
	MOUSE_KEY_CODE idx = buttonToIdx(event->button());			// index of button that caused event

	if (idx == MOUSE_BAD)
	{
		debug(LOG_ERROR, "bad mouse idx");	// FIXME remove
		return; // not recognized mouse button
	}

	MousePress mousePress;
	mousePress.action = MousePress::Press;
	mousePress.key = idx;
	mousePress.pos = Vector2i(mouseXPos, mouseYPos);
	mousePresses.push_back(mousePress);

	aMouseState[idx].pressPos.x = mouseXPos;
	aMouseState[idx].pressPos.y = mouseYPos;

	if (aMouseState[idx].state == KEY_UP
		|| aMouseState[idx].state == KEY_RELEASED
		|| aMouseState[idx].state == KEY_PRESSRELEASE)
	{
		if (!presses.testFlag(Qt::MidButton)) //skip doubleclick check for wheel
		{
			// whether double click or not
			if (realTime - aMouseState[idx].lastdown < DOUBLE_CLICK_INTERVAL)
			{
				aMouseState[idx].state = KEY_DOUBLECLICK;
				aMouseState[idx].lastdown = 0;
			}
			else
			{
				aMouseState[idx].state = KEY_PRESSED;
				aMouseState[idx].lastdown = realTime;
			}
		}
		else	//mouse wheel up/down was used, so notify. FIXME.
		{
			aMouseState[idx].state = KEY_PRESSED;
			aMouseState[idx].lastdown = 0;
		}

		if (idx == MOUSE_LMB || idx == MOUSE_RMB || idx == MOUSE_MMB)
		{
			dragKey = idx;
			dragX = mouseX();
			dragY = mouseY();
		}
	}
}
Ejemplo n.º 3
0
/*!
 * Handle mouse button events (We can handle up to 5)
 */
static void inputHandleMouseButtonEvent(SDL_MouseButtonEvent *buttonEvent)
{
	mouseXPos = buttonEvent->x;
	mouseYPos = buttonEvent->y;

	MOUSE_KEY_CODE mouseKeyCode;
	switch (buttonEvent->button)
	{
	case SDL_BUTTON_LEFT: mouseKeyCode = MOUSE_LMB; break;
	case SDL_BUTTON_MIDDLE: mouseKeyCode = MOUSE_MMB; break;
	case SDL_BUTTON_RIGHT: mouseKeyCode = MOUSE_RMB; break;
	case SDL_BUTTON_X1: mouseKeyCode = MOUSE_X1; break;
	case SDL_BUTTON_X2: mouseKeyCode = MOUSE_X2; break;
	default: return;  // Unknown button.
	}

	MousePress mousePress;
	mousePress.key = mouseKeyCode;
	mousePress.pos = Vector2i(mouseXPos, mouseYPos);

	switch (buttonEvent->type)
	{
	case SDL_MOUSEBUTTONDOWN:
		mousePress.action = MousePress::Press;
		mousePresses.push_back(mousePress);

		aMouseState[mouseKeyCode].pressPos.x = mouseXPos;
		aMouseState[mouseKeyCode].pressPos.y = mouseYPos;
		if (aMouseState[mouseKeyCode].state == KEY_UP
		    || aMouseState[mouseKeyCode].state == KEY_RELEASED
		    || aMouseState[mouseKeyCode].state == KEY_PRESSRELEASE)
		{
			// whether double click or not
			if (realTime - aMouseState[mouseKeyCode].lastdown < DOUBLE_CLICK_INTERVAL)
			{
				aMouseState[mouseKeyCode].state = KEY_DOUBLECLICK;
				aMouseState[mouseKeyCode].lastdown = 0;
			}
			else
			{
				aMouseState[mouseKeyCode].state = KEY_PRESSED;
				aMouseState[mouseKeyCode].lastdown = realTime;
			}

			if (mouseKeyCode < MOUSE_X1) // Assume they are draggin' with either LMB|RMB|MMB
			{
				dragKey = mouseKeyCode;
				dragX = mouseXPos;
				dragY = mouseYPos;
			}
		}
		break;
	case SDL_MOUSEBUTTONUP:
		mousePress.action = MousePress::Release;
		mousePresses.push_back(mousePress);

		aMouseState[mouseKeyCode].releasePos.x = mouseXPos;
		aMouseState[mouseKeyCode].releasePos.y = mouseYPos;
		if (aMouseState[mouseKeyCode].state == KEY_PRESSED)
		{
			aMouseState[mouseKeyCode].state = KEY_PRESSRELEASE;
		}
		else if (aMouseState[mouseKeyCode].state == KEY_DOWN
		         || aMouseState[mouseKeyCode].state == KEY_DRAG
		         || aMouseState[mouseKeyCode].state == KEY_DOUBLECLICK)
		{
			aMouseState[mouseKeyCode].state = KEY_RELEASED;
		}
		break;
	default:
		break;
	}
}