FIRE-1279: Proposed fix for pie menu being active while hidden behind another application

Wed, 10 Dec 2014 14:15:23 +0100

author
Ansariel
date
Wed, 10 Dec 2014 14:15:23 +0100
changeset 43049
9134c936410e
parent 43048
4533555eb15a
child 43050
c7b63a0a3966

FIRE-1279: Proposed fix for pie menu being active while hidden behind another application

indra/newview/piemenu.cpp file | annotate | diff | revisions
indra/newview/piemenu.h file | annotate | diff | revisions
     1.1 --- a/indra/newview/piemenu.cpp	Wed Dec 10 11:00:31 2014 +0100
     1.2 +++ b/indra/newview/piemenu.cpp	Wed Dec 10 14:15:23 2014 +0100
     1.3 @@ -55,7 +55,8 @@
     1.4  const S32 PIE_Y[] = { 0, 44, 73,  44,   0, -44, -73, -44};
     1.5  
     1.6  PieMenu::PieMenu(const LLContextMenu::Params& p) :
     1.7 -	LLContextMenu(p)
     1.8 +	LLContextMenu(p),
     1.9 +	mCurrentSegment(-1)
    1.10  {
    1.11  	LL_DEBUGS() << "PieMenu::PieMenu()" << LL_ENDL;
    1.12  	// radius, so we need this *2
    1.13 @@ -110,7 +111,37 @@
    1.14  
    1.15  BOOL PieMenu::handleHover(S32 x, S32 y, MASK mask)
    1.16  {
    1.17 -	// do nothing
    1.18 +	// initialize pie scale factor for popup effect
    1.19 +	F32 factor = getScaleFactor();
    1.20 +
    1.21 +	// initially, the current segment is marked as invalid
    1.22 +	mCurrentSegment = -1;
    1.23 +
    1.24 +	// remember to take the UI scaling into account
    1.25 +	LLVector2 scale = gViewerWindow->getDisplayScale();
    1.26 +	// move mouse coordinates to be relative to the pie center
    1.27 +	LLVector2 mouseVector(x - PIE_OUTER_SIZE / scale.mV[VX], y - PIE_OUTER_SIZE / scale.mV[VY]);
    1.28 +
    1.29 +	// get the distance from the center point
    1.30 +	F32 distance = mouseVector.length();
    1.31 +
    1.32 +	// check if our mouse pointer is within the pie slice area
    1.33 +	if (distance > PIE_INNER_SIZE && (distance < (PIE_OUTER_SIZE * factor) || mFirstClick))
    1.34 +	{
    1.35 +		// get the angle of the mouse pointer from the center in radians
    1.36 +		F32 angle = acos(mouseVector.mV[VX] / distance);
    1.37 +		// if the mouse is below the middle of the pie, reverse the angle
    1.38 +		if (mouseVector.mV[VY] < 0)
    1.39 +		{
    1.40 +			angle = F_PI * 2 - angle;
    1.41 +		}
    1.42 +		// rotate the angle slightly so the slices' centers are aligned correctly
    1.43 +		angle += F_PI / 8;
    1.44 +
    1.45 +		// calculate slice number from the angle
    1.46 +		mCurrentSegment = (S32) (8.f * angle / (F_PI * 2.f)) % 8;
    1.47 +	}
    1.48 +
    1.49  	return TRUE;
    1.50  }
    1.51  
    1.52 @@ -122,6 +153,8 @@
    1.53  		return;
    1.54  	}
    1.55  
    1.56 +	mCurrentSegment = -1;
    1.57 +
    1.58  	// play a sound
    1.59  	make_ui_sound("UISndPieMenuAppear");
    1.60  
    1.61 @@ -201,6 +234,7 @@
    1.62  
    1.63  	LL_DEBUGS() << "Clearing selections" << LL_ENDL;
    1.64  
    1.65 +	mCurrentSegment = -1;
    1.66  	mSlices = &mMySlices;
    1.67  #if PIE_POPUP_EFFECT
    1.68  	// safety in case the timer was still running
    1.69 @@ -229,32 +263,7 @@
    1.70  	LLRect r = getRect();
    1.71  
    1.72  	// initialize pie scale factor for popup effect
    1.73 -	F32 factor = 1.f;
    1.74 -
    1.75 -#if PIE_POPUP_EFFECT
    1.76 -	// set the popup size if this was the first click on the menu
    1.77 -	if (mFirstClick)
    1.78 -	{
    1.79 -		factor = PIE_POPUP_FACTOR;
    1.80 -	}
    1.81 -	// otherwise check if the popup timer is still running
    1.82 -	else if (mPopupTimer.getStarted())
    1.83 -	{
    1.84 -		// if the timer ran past the popup time, stop the timer and set the size to 1.0
    1.85 -		F32 elapsedTime = mPopupTimer.getElapsedTimeF32();
    1.86 -		if (elapsedTime > PIE_POPUP_TIME)
    1.87 -		{
    1.88 -			factor = 1.f;
    1.89 -			mPopupTimer.stop();
    1.90 -		}
    1.91 -		// otherwise calculate the size factor to make the menu shrink over time
    1.92 -		else
    1.93 -		{
    1.94 -			factor = PIE_POPUP_FACTOR - (PIE_POPUP_FACTOR - 1.f) * elapsedTime / PIE_POPUP_TIME;
    1.95 -		}
    1.96 -//		setRect(r);  // obsolete?
    1.97 -	}
    1.98 -#endif
    1.99 +	F32 factor = getScaleFactor();
   1.100  
   1.101  #if PIE_DRAW_BOUNDING_BOX
   1.102  	// draw a bounding box around the menu for debugging purposes
   1.103 @@ -285,36 +294,6 @@
   1.104  		borderColor %= 0.f;
   1.105  	}
   1.106  
   1.107 -	// initially, the current segment is marked as invalid
   1.108 -	S32 currentSegment = -1;
   1.109 -
   1.110 -	// get the current mouse pointer position local to the pie
   1.111 -	S32 x, y;
   1.112 -	LLUI::getMousePositionLocal(this, &x, &y);
   1.113 -	// remember to take the UI scaling into account
   1.114 -	LLVector2 scale = gViewerWindow->getDisplayScale();
   1.115 -	// move mouse coordinates to be relative to the pie center
   1.116 -	LLVector2 mouseVector(x - PIE_OUTER_SIZE / scale.mV[VX], y - PIE_OUTER_SIZE / scale.mV[VY]);
   1.117 -
   1.118 -	// get the distance from the center point
   1.119 -	F32 distance = mouseVector.length();
   1.120 -	// check if our mouse pointer is within the pie slice area
   1.121 -	if (distance > PIE_INNER_SIZE && (distance < (PIE_OUTER_SIZE * factor) || mFirstClick))
   1.122 -	{
   1.123 -		// get the angle of the mouse pointer from the center in radians
   1.124 -		F32 angle = acos(mouseVector.mV[VX] / distance);
   1.125 -		// if the mouse is below the middle of the pie, reverse the angle
   1.126 -		if (mouseVector.mV[VY] < 0)
   1.127 -		{
   1.128 -			angle = F_PI * 2 - angle;
   1.129 -		}
   1.130 -		// rotate the angle slightly so the slices' centers are aligned correctly
   1.131 -		angle += F_PI / 8;
   1.132 -
   1.133 -		// calculate slice number from the angle
   1.134 -		currentSegment = (S32) (8.f * angle / (F_PI * 2.f)) % 8;
   1.135 -	}
   1.136 -
   1.137  	// move origin point to the center of our rectangle
   1.138  	gGL.translatef(r.getWidth() / 2, r.getHeight() / 2, 0);
   1.139  
   1.140 @@ -427,7 +406,7 @@
   1.141  			}
   1.142  
   1.143  			// if it's a slice or submenu, the mouse pointer is over the same segment as our counter and the item is enabled
   1.144 -			if ((currentSlice || currentSubmenu) && (currentSegment==num) && item->getEnabled())
   1.145 +			if ((currentSlice || currentSubmenu) && (mCurrentSegment == num) && item->getEnabled())
   1.146  			{
   1.147  				// memorize the currently highlighted slice for later
   1.148  				mSlice = item;
   1.149 @@ -576,3 +555,36 @@
   1.150  	// give control back to the system
   1.151  	return LLView::handleMouseUp(x, y, mask);
   1.152  }
   1.153 +
   1.154 +F32 PieMenu::getScaleFactor()
   1.155 +{
   1.156 +	// initialize pie scale factor for popup effect
   1.157 +	F32 factor = 1.f;
   1.158 +
   1.159 +#if PIE_POPUP_EFFECT
   1.160 +	// set the popup size if this was the first click on the menu
   1.161 +	if (mFirstClick)
   1.162 +	{
   1.163 +		factor = PIE_POPUP_FACTOR;
   1.164 +	}
   1.165 +	// otherwise check if the popup timer is still running
   1.166 +	else if (mPopupTimer.getStarted())
   1.167 +	{
   1.168 +		// if the timer ran past the popup time, stop the timer and set the size to 1.0
   1.169 +		F32 elapsedTime = mPopupTimer.getElapsedTimeF32();
   1.170 +		if (elapsedTime > PIE_POPUP_TIME)
   1.171 +		{
   1.172 +			factor = 1.f;
   1.173 +			mPopupTimer.stop();
   1.174 +		}
   1.175 +		// otherwise calculate the size factor to make the menu shrink over time
   1.176 +		else
   1.177 +		{
   1.178 +			factor = PIE_POPUP_FACTOR - (PIE_POPUP_FACTOR - 1.f) * elapsedTime / PIE_POPUP_TIME;
   1.179 +		}
   1.180 +//		setRect(r);  // obsolete?
   1.181 +	}
   1.182 +
   1.183 +	return factor;
   1.184 +#endif
   1.185 +}
   1.186 \ No newline at end of file
     2.1 --- a/indra/newview/piemenu.h	Wed Dec 10 11:00:31 2014 +0100
     2.2 +++ b/indra/newview/piemenu.h	Wed Dec 10 14:15:23 2014 +0100
     2.3 @@ -105,6 +105,10 @@
     2.4  		S32 mCenterY;
     2.5  		// this is TRUE when the first mouseclick came to display the menu, used for borderless menu
     2.6  		bool mFirstClick;
     2.7 +
     2.8 +		F32 getScaleFactor();
     2.9 +
    2.10 +		S32 mCurrentSegment;
    2.11  };
    2.12  
    2.13  #endif // PIEMENU_H

mercurial