Input: Return const -20 mouse position when outside window
This commit is contained in:
		
							parent
							
								
									318162a229
								
							
						
					
					
						commit
						8ed6de22a4
					
				
					 3 changed files with 12 additions and 1 deletions
				
			
		| 
						 | 
					@ -42,7 +42,7 @@ EventThread::JoyState EventThread::joyState =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EventThread::MouseState EventThread::mouseState =
 | 
					EventThread::MouseState EventThread::mouseState =
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	0, 0, { false }
 | 
						0, 0, false, { false }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* User event codes */
 | 
					/* User event codes */
 | 
				
			||||||
| 
						 | 
					@ -129,12 +129,14 @@ void EventThread::process(RGSSThreadData &rtData)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case SDL_WINDOWEVENT_ENTER :
 | 
								case SDL_WINDOWEVENT_ENTER :
 | 
				
			||||||
				cursorInWindow = true;
 | 
									cursorInWindow = true;
 | 
				
			||||||
 | 
									mouseState.inWindow = true;
 | 
				
			||||||
				updateCursorState(cursorInWindow && windowFocused);
 | 
									updateCursorState(cursorInWindow && windowFocused);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case SDL_WINDOWEVENT_LEAVE :
 | 
								case SDL_WINDOWEVENT_LEAVE :
 | 
				
			||||||
				cursorInWindow = false;
 | 
									cursorInWindow = false;
 | 
				
			||||||
 | 
									mouseState.inWindow = false;
 | 
				
			||||||
				updateCursorState(cursorInWindow && windowFocused);
 | 
									updateCursorState(cursorInWindow && windowFocused);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,6 +56,7 @@ public:
 | 
				
			||||||
	struct MouseState
 | 
						struct MouseState
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		int x, y;
 | 
							int x, y;
 | 
				
			||||||
 | 
							bool inWindow;
 | 
				
			||||||
		bool buttons[32];
 | 
							bool buttons[32];
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -614,12 +614,20 @@ int Input::dir8Value()
 | 
				
			||||||
int Input::mouseX()
 | 
					int Input::mouseX()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	RGSSThreadData &rtData = shState->rtData();
 | 
						RGSSThreadData &rtData = shState->rtData();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!EventThread::mouseState.inWindow)
 | 
				
			||||||
 | 
							return -20;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (EventThread::mouseState.x - rtData.screenOffset.x) * rtData.sizeResoRatio.x;
 | 
						return (EventThread::mouseState.x - rtData.screenOffset.x) * rtData.sizeResoRatio.x;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Input::mouseY()
 | 
					int Input::mouseY()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	RGSSThreadData &rtData = shState->rtData();
 | 
						RGSSThreadData &rtData = shState->rtData();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!EventThread::mouseState.inWindow)
 | 
				
			||||||
 | 
							return -20;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
 | 
						return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue