EventThread: Add 'recenter' parameter to window resize request
If true, centers the window on the current screen with the new size.
This commit is contained in:
		
							parent
							
								
									d09fec941b
								
							
						
					
					
						commit
						a92adee7f8
					
				
					 3 changed files with 37 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -201,9 +201,10 @@ RB_METHOD(graphicsResizeWindow)
 | 
			
		|||
	RB_UNUSED_PARAM;
 | 
			
		||||
 | 
			
		||||
	int width, height;
 | 
			
		||||
	rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END);
 | 
			
		||||
	bool recenter = false;
 | 
			
		||||
	rb_get_args(argc, argv, "ii|b", &width, &height, &recenter RB_ARG_END);
 | 
			
		||||
 | 
			
		||||
	shState->eThread().requestWindowResize(width, height);
 | 
			
		||||
	shState->eThread().requestWindowResize(width, height, recenter);
 | 
			
		||||
 | 
			
		||||
	return Qnil;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -101,6 +101,36 @@ bool EventThread::allocUserEvents()
 | 
			
		|||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void writeResizeRequest(SDL_WindowEvent &event, int w, int h, bool recenter)
 | 
			
		||||
{
 | 
			
		||||
	event.data1 = w;
 | 
			
		||||
	event.data2 = h;
 | 
			
		||||
	event.padding3 = recenter ? 1 : 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void handleResizeRequest(SDL_Window *win, SDL_WindowEvent &event)
 | 
			
		||||
{
 | 
			
		||||
	int newWidth = event.data1;
 | 
			
		||||
	int newHeight = event.data2;
 | 
			
		||||
	bool recenter = event.padding3 == 1;
 | 
			
		||||
 | 
			
		||||
	if (recenter)
 | 
			
		||||
	{
 | 
			
		||||
		int display = SDL_GetWindowDisplayIndex(win);
 | 
			
		||||
		if (display >= 0)
 | 
			
		||||
		{
 | 
			
		||||
			SDL_DisplayMode dm;
 | 
			
		||||
			SDL_GetDesktopDisplayMode(display, &dm);
 | 
			
		||||
			int newX = (dm.w - newWidth) / 2;
 | 
			
		||||
			int newY = (dm.h - newHeight) / 2;
 | 
			
		||||
 | 
			
		||||
			SDL_SetWindowPosition(win, newX, newY);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	SDL_SetWindowSize(win, newWidth, newHeight);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
EventThread::EventThread()
 | 
			
		||||
    : fullscreen(false),
 | 
			
		||||
      showCursor(false)
 | 
			
		||||
| 
						 | 
				
			
			@ -410,7 +440,7 @@ void EventThread::process(RGSSThreadData &rtData)
 | 
			
		|||
				break;
 | 
			
		||||
 | 
			
		||||
			case REQUEST_WINRESIZE :
 | 
			
		||||
				SDL_SetWindowSize(win, event.window.data1, event.window.data2);
 | 
			
		||||
				handleResizeRequest(win, event.window);
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case REQUEST_MESSAGEBOX :
 | 
			
		||||
| 
						 | 
				
			
			@ -581,12 +611,11 @@ void EventThread::requestFullscreenMode(bool mode)
 | 
			
		|||
	SDL_PushEvent(&event);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EventThread::requestWindowResize(int width, int height)
 | 
			
		||||
void EventThread::requestWindowResize(int width, int height, bool recenter)
 | 
			
		||||
{
 | 
			
		||||
	SDL_Event event;
 | 
			
		||||
	event.type = usrIdStart + REQUEST_WINRESIZE;
 | 
			
		||||
	event.window.data1 = width;
 | 
			
		||||
	event.window.data2 = height;
 | 
			
		||||
	writeResizeRequest(event.window, width, height, recenter);
 | 
			
		||||
	SDL_PushEvent(&event);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,7 +88,7 @@ public:
 | 
			
		|||
 | 
			
		||||
	/* Called from RGSS thread */
 | 
			
		||||
	void requestFullscreenMode(bool mode);
 | 
			
		||||
	void requestWindowResize(int width, int height);
 | 
			
		||||
	void requestWindowResize(int width, int height, bool recenter = false);
 | 
			
		||||
	void requestShowCursor(bool mode);
 | 
			
		||||
 | 
			
		||||
	void requestTerminate();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue