示例#1
0
文件: cg_newdraw.c 项目: Razish/QtZ
void CG_MouseEvent(int x, int y) {
	int n;

	if ( (cg.predictedPlayerState.pm_type == PM_NORMAL || cg.predictedPlayerState.pm_type == PM_SPECTATOR) && cg.showScores == qfalse) {
		trap->Key_SetCatcher(0);
		return;
	}

	cgs.cursorX += x;
	if (cgs.cursorX < 0)
		cgs.cursorX = 0;
	else if (cgs.cursorX > SCREEN_WIDTH)
		cgs.cursorX = SCREEN_WIDTH;

	cgs.cursorY += y;
	if (cgs.cursorY < 0)
		cgs.cursorY = 0;
	else if (cgs.cursorY > SCREEN_HEIGHT)
		cgs.cursorY = SCREEN_HEIGHT;

	n = Display_CursorType(cgs.cursorX, cgs.cursorY);
	cgs.activeCursor = 0;
	if (n == CURSOR_ARROW) {
		cgs.activeCursor = cgs.media.selectCursor;
	} else if (n == CURSOR_SIZER) {
		cgs.activeCursor = cgs.media.sizeCursor;
	}

	if (cgs.capturedItem) {
		Display_MouseMove(cgs.capturedItem, (float)x, (float)y);
	} else {
		Display_MouseMove(NULL, cgs.cursorX, cgs.cursorY);
	}

}
示例#2
0
void Menu_HandleKey(menuDef_t *menu, int key, qboolean down)
{
	int       i;
	itemDef_t *item = NULL;

	Menu_HandleMouseMove(menu, DC->cursorx, DC->cursory);       // fix for focus not resetting on unhidden buttons

	// enter key handling for the window supercedes item enter handling
	if (down && ((key == K_ENTER || key == K_KP_ENTER) && menu->onEnter))
	{
		itemDef_t it;

		it.parent = menu;
		Item_RunScript(&it, NULL, menu->onEnter);
		return;
	}

	if (g_waitingForKey && down)
	{
		Item_Bind_HandleKey(g_bindItem, key, down);
		return;
	}

	if (g_editingField && down)
	{
		if (g_editItem->type == ITEM_TYPE_COMBO)
		{
			Item_Combo_HandleKey(g_editItem, key);
			Item_ComboDeSelect(g_editItem);
			return;
		}
		else
		{
			if (!Item_TextField_HandleKey(g_editItem, key))
			{
				Item_HandleTextFieldDeSelect(g_editItem);
				return;
			}
			else if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3)
			{
				Item_HandleTextFieldDeSelect(g_editItem);
				Display_MouseMove(NULL, DC->cursorx, DC->cursory);
			}
			else if (key == K_TAB || key == K_UPARROW || key == K_DOWNARROW)
			{
				return;
			}
		}
	}

	if (menu == NULL)
	{
		return;
	}

	// see if the mouse is within the window bounds and if so is this a mouse click
	if (down && !(menu->window.flags & WINDOW_POPUP) && !Rect_ContainsPoint(&menu->window.rect, DC->cursorx, DC->cursory))
	{
		static qboolean inHandleKey = qfalse;
		// bk001206 - parentheses
		if (!inHandleKey && (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3))
		{
			inHandleKey = qtrue;
			Menus_HandleOOBClick(menu, key, down);
			inHandleKey = qfalse;
			return;
		}
	}

	// get the item with focus
	for (i = 0; i < menu->itemCount; i++)
	{
		if (menu->items[i]->window.flags & WINDOW_HASFOCUS)
		{
			item = menu->items[i];
		}
	}

	// handle clipboard event if the menu has it set and there is no item selected which has the action
	if (K_CLIPBOARD(key) && down && menu->onPaste && (item == NULL || (item != NULL && !item->onPaste)) && !g_editingField)
	{
		itemDef_t it;
		it.parent = menu;
		Item_RunScript(&it, NULL, menu->onPaste);
		return;
	}

	if (item != NULL)
	{
		if (Item_HandleKey(item, key, down))
		{
			Item_Action(item);
			return;
		}
	}

	if (!down)
	{
		return;
	}

	// we need to check and see if we're supposed to loop through the items to find the key press func
	if (!menu->itemHotkeyMode)
	{
		if (key > 0 && key <= 255 && menu->onKey[key])
		{
			itemDef_t it;
			it.parent = menu;
			Item_RunScript(&it, NULL, menu->onKey[key]);
			return;
		}
	}
	else if (key > 0 && key <= 255)
	{
		itemDef_t *it;

		// we're using the item hotkey mode, so we want to loop through all the items in this menu
		for (i = 0; i < menu->itemCount; i++)
		{
			it = menu->items[i];

			// is the hotkey for this the same as what was pressed?
			if (it->hotkey == key
			    // and is this item visible?
			    && Item_EnableShowViaCvar(it, CVAR_SHOW))
			{
				Item_RunScript(it, NULL, it->onKey);
				return;
			}
		}
	}

	// default handling
	switch (key)
	{
	case K_F11:
		if (DC->getCVarValue("developer"))
		{
			debugMode ^= 1;
		}
		break;
	case K_F12:
		if (DC->getCVarValue("developer"))
		{
			DC->executeText(EXEC_APPEND, "screenshot\n");
		}
		break;
	case K_KP_UPARROW:
	case K_UPARROW:
		Menu_SetPrevCursorItem(menu);
		break;
	case K_ESCAPE:
		if (!g_waitingForKey && menu->onESC)
		{
			itemDef_t it;
			it.parent = menu;
			Item_RunScript(&it, NULL, menu->onESC);
		}
		break;
	case K_ENTER:
	case K_KP_ENTER:
	case K_MOUSE3:
		Item_KeyboardActivate(item);
		break;
	case K_TAB:
		if (DC->keyIsDown(K_SHIFT))
		{
			Menu_SetPrevCursorItem(menu);
		}
		else
		{
			Menu_SetNextCursorItem(menu);
		}
		break;
	case K_KP_DOWNARROW:
	case K_DOWNARROW:
		Menu_SetNextCursorItem(menu);
		break;
	case K_MOUSE1:
	case K_MOUSE2:
		Item_MouseActivate(item);
		break;
	case K_JOY1:
	case K_JOY2:
	case K_JOY3:
	case K_JOY4:
	case K_AUX1:
	case K_AUX2:
	case K_AUX3:
	case K_AUX4:
	case K_AUX5:
	case K_AUX6:
	case K_AUX7:
	case K_AUX8:
	case K_AUX9:
	case K_AUX10:
	case K_AUX11:
	case K_AUX12:
	case K_AUX13:
	case K_AUX14:
	case K_AUX15:
	case K_AUX16:
		break;
	}
}