Exemplo n.º 1
0
/*
=================
UI_DrawMouseCursor
=================
*/
void UI_DrawMouseCursor( void )
{
	menuCommon_s	*item;
	HICON		hCursor = NULL;
	int		i;

	if( uiStatic.hideCursor ) return;

	for( i = 0; i < uiStatic.menuActive->numItems; i++ )
	{
		item = (menuCommon_s *)uiStatic.menuActive->items[i];

		if ( item->flags & (QMF_INACTIVE|QMF_HIDDEN))
			continue;

		if ( !UI_CursorInRect( item->x, item->y, item->width, item->height ))
			continue;

		if ( item->flags & QMF_GRAYED )
		{
			hCursor = (HICON)LoadCursor( NULL, (LPCTSTR)OCR_NO );
		}
		else
		{
			if( item->type == QMTYPE_FIELD )
				hCursor = (HICON)LoadCursor( NULL, (LPCTSTR)OCR_IBEAM );
		}
		break;
	}

	if( !hCursor ) hCursor = (HICON)LoadCursor( NULL, (LPCTSTR)OCR_NORMAL );

	SET_CURSOR( hCursor );
}
Exemplo n.º 2
0
/*
=================
UI_TeamOrdersMenu_Key
=================
*/
sfxHandle_t UI_TeamOrdersMenu_Key( int key ) {
	menulist_s	*l;
	int	x;
	int	y;
	int	index;

	l = (menulist_s	*)Menu_ItemAtCursor( &teamOrdersMenuInfo.menu );
	if( l != &teamOrdersMenuInfo.list ) {
		return Menu_DefaultKey( &teamOrdersMenuInfo.menu, key );
	}

	switch( key ) {
		case K_MOUSE1:
			x = l->generic.left;
			y = l->generic.top;
			if( UI_CursorInRect( x, y, l->generic.right - x, l->generic.bottom - y ) ) {
				index = (uis.cursory - y) / PROP_HEIGHT;
				l->oldvalue = l->curvalue;
				l->curvalue = index;

				if( l->generic.callback ) {
					l->generic.callback( l, QM_ACTIVATED );
					return menu_move_sound;
				}
			}
			return menu_null_sound;

		case K_KP_UPARROW:
		case K_UPARROW:
			l->oldvalue = l->curvalue;

			if( l->curvalue == 0 ) {
				l->curvalue = l->numitems - 1;
			}
			else {
				l->curvalue--;
			}
			return menu_move_sound;

		case K_KP_DOWNARROW:
		case K_DOWNARROW:
			l->oldvalue = l->curvalue;

			if( l->curvalue == l->numitems - 1 ) {
				l->curvalue = 0;;
			}
			else {
				l->curvalue++;
			}
			return menu_move_sound;
	}

	return Menu_DefaultKey( &teamOrdersMenuInfo.menu, key );
}
Exemplo n.º 3
0
sfxHandle_t ScrollList_Key(menulist_s *l, int key)
{
	int	x;
	int	y;
	int	w;
	int	i;
	int	j;
	int	c;
	int	cursorx;
	int	cursory;
	int	column;
	int	index;

	switch (key) {
	case K_MOUSE1:
		if (l->generic.flags & QMF_HASMOUSEFOCUS) {
			// check scroll region
			x = l->generic.x;
			y = l->generic.y;
			w = ((l->width + l->seperation) * l->columns - l->seperation) * SMALLCHAR_SIZE;
			if (l->generic.flags & QMF_CENTER_JUSTIFY) {
				x -= w / 2;
			}
			if (UI_CursorInRect(x, y, w, l->height*SMALLCHAR_SIZE)) {
				cursorx = (uis.cursorx - x)/SMALLCHAR_SIZE;
				column = cursorx / (l->width + l->seperation);
				cursory = (uis.cursory - y)/SMALLCHAR_SIZE;
				index = column * l->height + cursory;
				if (l->top + index < l->numitems) {
					l->oldvalue = l->curvalue;
					l->curvalue = l->top + index;

					if (l->oldvalue != l->curvalue && l->generic.callback) {
						l->generic.callback(l, QM_GOTFOCUS);
						return (menu_move_sound);
					}
				}
			}

			// absorbed, silent sound effect
			return (menu_null_sound);
		}
		break;

	case K_KP_HOME:
	case K_HOME:
		l->oldvalue = l->curvalue;
		l->curvalue = 0;
		l->top      = 0;

		if (l->oldvalue != l->curvalue && l->generic.callback) {
			l->generic.callback(l, QM_GOTFOCUS);
			return (menu_move_sound);
		}
		return (menu_buzz_sound);

	case K_KP_END:
	case K_END:
		l->oldvalue = l->curvalue;
		l->curvalue = l->numitems-1;
		if (l->columns > 1) {
			c = (l->curvalue / l->height + 1) * l->height;
			l->top = c - (l->columns * l->height);
		} else {
			l->top = l->curvalue - (l->height - 1);
		}

		if (l->top < 0) {
			l->top = 0;
		}

		if (l->oldvalue != l->curvalue && l->generic.callback) {
			l->generic.callback(l, QM_GOTFOCUS);
			return (menu_move_sound);
		}
		return (menu_buzz_sound);

	case K_PGUP:
	case K_KP_PGUP:
		if (l->columns > 1) {
			return menu_null_sound;
		}

		if (l->curvalue > 0) {
			l->oldvalue = l->curvalue;
			l->curvalue -= l->height-1;
			if (l->curvalue < 0) {
				l->curvalue = 0;
			}
			l->top = l->curvalue;
			if (l->top < 0) {
				l->top = 0;
			}

			if (l->generic.callback) {
				l->generic.callback(l, QM_GOTFOCUS);
			}

			return (menu_move_sound);
		}
		return (menu_buzz_sound);

	case K_PGDN:
	case K_KP_PGDN:
		if (l->columns > 1) {
			return menu_null_sound;
		}

		if (l->curvalue < l->numitems-1) {
			l->oldvalue = l->curvalue;
			l->curvalue += l->height-1;
			if (l->curvalue > l->numitems-1) {
				l->curvalue = l->numitems-1;
			}
			l->top = l->curvalue - (l->height-1);
			if (l->top < 0) {
				l->top = 0;
			}

			if (l->generic.callback) {
				l->generic.callback(l, QM_GOTFOCUS);
			}

			return (menu_move_sound);
		}
		return (menu_buzz_sound);

	case K_KP_UPARROW:
	case K_UPARROW:
		if (l->curvalue == 0) {
			return menu_buzz_sound;
		}

		l->oldvalue = l->curvalue;
		l->curvalue--;

		if (l->curvalue < l->top) {
			if (l->columns == 1) {
				l->top--;
			} else {
				l->top -= l->height;
			}
		}

		if (l->generic.callback) {
			l->generic.callback(l, QM_GOTFOCUS);
		}

		return (menu_move_sound);

	case K_KP_DOWNARROW:
	case K_DOWNARROW:
		if (l->curvalue == l->numitems - 1) {
			return menu_buzz_sound;
		}

		l->oldvalue = l->curvalue;
		l->curvalue++;

		if (l->curvalue >= l->top + l->columns * l->height) {
			if (l->columns == 1) {
				l->top++;
			} else {
				l->top += l->height;
			}
		}

		if (l->generic.callback) {
			l->generic.callback(l, QM_GOTFOCUS);
		}

		return menu_move_sound;

	case K_KP_LEFTARROW:
	case K_LEFTARROW:
		if (l->columns == 1) {
			return menu_null_sound;
		}

		if (l->curvalue < l->height) {
			return menu_buzz_sound;
		}

		l->oldvalue = l->curvalue;
		l->curvalue -= l->height;

		if (l->curvalue < l->top) {
			l->top -= l->height;
		}

		if (l->generic.callback) {
			l->generic.callback(l, QM_GOTFOCUS);
		}

		return menu_move_sound;

	case K_KP_RIGHTARROW:
	case K_RIGHTARROW:
		if (l->columns == 1) {
			return menu_null_sound;
		}

		c = l->curvalue + l->height;

		if (c >= l->numitems) {
			return menu_buzz_sound;
		}

		l->oldvalue = l->curvalue;
		l->curvalue = c;

		if (l->curvalue > l->top + l->columns * l->height - 1) {
			l->top += l->height;
		}

		if (l->generic.callback) {
			l->generic.callback(l, QM_GOTFOCUS);
		}

		return menu_move_sound;
	}

	// cycle look for ascii key inside list items
	if (!Q_isprint(key)) {
		return 0;
	}

	// force to lower for case insensitive compare
	if (Q_isupper(key)) {
		key -= 'A' - 'a';
	}

	// iterate list items
	for (i=1; i<=l->numitems; i++) {
		j = (l->curvalue + i) % l->numitems;
		c = l->itemnames[j][0];
		if (Q_isupper(c)) {
			c -= 'A' - 'a';
		}

		if (c == key) {
			// set current item, mimic windows listbox scroll behavior
			if (j < l->top) {
				// behind top most item, set this as new top
				l->top = j;
			} else if (j > l->top+l->height-1) {
				// past end of list box, do page down
				l->top = (j+1) - l->height;
			}

			if (l->curvalue != j) {
				l->oldvalue = l->curvalue;
				l->curvalue = j;
				if (l->generic.callback)
					l->generic.callback(l, QM_GOTFOCUS);
				return (menu_move_sound);
			}

			return (menu_buzz_sound);
		}
	}

	return (menu_buzz_sound);
}
Exemplo n.º 4
0
/*
=================
UI_MouseMove
=================
*/
void UI_MouseMove( int x, int y )
{
	int		i;
	menuCommon_s	*item;

	if( !uiStatic.initialized )
		return;

	if( !uiStatic.visible )
		return;

	if( !uiStatic.menuActive )
		return;

	// now menu uses absolute coordinates
	uiStatic.cursorX = x;
	uiStatic.cursorY = y;

	if( UI_CursorInRect( 1, 1, ScreenWidth - 1, ScreenHeight - 1 ))
		uiStatic.mouseInRect = true;
	else uiStatic.mouseInRect = false;

	uiStatic.cursorX = bound( 0, uiStatic.cursorX, ScreenWidth );
	uiStatic.cursorY = bound( 0, uiStatic.cursorY, ScreenHeight );

	// region test the active menu items
	for( i = 0; i < uiStatic.menuActive->numItems; i++ )
	{
		item = (menuCommon_s *)uiStatic.menuActive->items[i];

		if( item->flags & (QMF_GRAYED|QMF_INACTIVE|QMF_HIDDEN))
		{
			if( item->flags & QMF_HASMOUSEFOCUS )
			{
				if( !UI_CursorInRect( item->x, item->y, item->width, item->height ))
					item->flags &= ~QMF_HASMOUSEFOCUS;
				else item->lastFocusTime = uiStatic.realTime;
			}
			continue;
		}

		if( !UI_CursorInRect( item->x, item->y, item->width, item->height ))
		{
			item->bPressed = false;
			continue;
		}

		// set focus to item at cursor
		if( uiStatic.menuActive->cursor != i )
		{
			UI_SetCursor( uiStatic.menuActive, i );
			((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursorPrev]))->flags &= ~QMF_HASMOUSEFOCUS;

			if (!(((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->flags & QMF_SILENT ))
				UI_StartSound( uiSoundMove );
		}

		((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->flags |= QMF_HASMOUSEFOCUS;
		((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->lastFocusTime = uiStatic.realTime;
		return;
	}

	// out of any region
	if( uiStatic.menuActive->numItems )
	{
		((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->flags &= ~QMF_HASMOUSEFOCUS;
		((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->bPressed = false;

		// a mouse only item restores focus to the previous item
		if(((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->flags & QMF_MOUSEONLY )
		{
			if( uiStatic.menuActive->cursorPrev != -1 )
				uiStatic.menuActive->cursor = uiStatic.menuActive->cursorPrev;
		}
	}
}