Merge branch 'master' into jgrpp-beta
# Conflicts: # src/company_cmd.cpp # src/economy.cpp # src/lang/swedish.txt # src/network/network_command.cpp # src/news_gui.cpp # src/saveload/saveload.h # src/script/api/script_list.cpp # src/video/cocoa/cocoa_v.mm # src/video/sdl2_v.cpp
This commit is contained in:
		| @@ -12,6 +12,8 @@ | ||||
| #include "../../stdafx.h" | ||||
| #include "../../os/macosx/macos.h" | ||||
|  | ||||
| #define GL_SILENCE_DEPRECATION | ||||
|  | ||||
| #define Rect  OTTDRect | ||||
| #define Point OTTDPoint | ||||
| #import <Cocoa/Cocoa.h> | ||||
| @@ -150,7 +152,6 @@ static bool _allowSoftware; | ||||
| { | ||||
| 	if (self = [ super initWithFrame:frameRect ]) { | ||||
| 		/* We manage our content updates ourselves. */ | ||||
| 		self.wantsBestResolutionOpenGLSurface = _allow_hidpi_window ? YES : NO; | ||||
| 		self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay; | ||||
|  | ||||
| 		/* Create backing layer. */ | ||||
|   | ||||
| @@ -45,6 +45,17 @@ | ||||
| #import <sys/time.h> /* gettimeofday */ | ||||
| #include <array> | ||||
|  | ||||
| /* The 10.12 SDK added new names for some enum constants and | ||||
|  * deprecated the old ones. As there's no functional change in any | ||||
|  * way, just use a define for older SDKs to the old names. */ | ||||
| #ifndef HAVE_OSX_1012_SDK | ||||
| #	define NSEventModifierFlagCommand NSCommandKeyMask | ||||
| #	define NSEventModifierFlagControl NSControlKeyMask | ||||
| #	define NSEventModifierFlagOption NSAlternateKeyMask | ||||
| #	define NSEventModifierFlagShift NSShiftKeyMask | ||||
| #	define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask | ||||
| #endif | ||||
|  | ||||
| /** | ||||
|  * Important notice regarding all modifications!!!!!!! | ||||
|  * There are certain limitations because the file is objective C++. | ||||
| @@ -360,7 +371,11 @@ bool VideoDriver_Cocoa::MakeWindow(int width, int height) | ||||
| 	NSRect contentRect = NSMakeRect(0, 0, width, height); | ||||
|  | ||||
| 	/* Create main window. */ | ||||
| #ifdef HAVE_OSX_1012_SDK | ||||
| 	unsigned int style = NSWindowStyleMaskTitled | NSWindowStyleMaskResizable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskClosable; | ||||
| #else | ||||
| 	unsigned int style = NSTitledWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask; | ||||
| #endif | ||||
| 	this->window = [ [ OTTD_CocoaWindow alloc ] initWithContentRect:contentRect styleMask:style backing:NSBackingStoreBuffered defer:NO driver:this ]; | ||||
| 	if (this->window == nil) { | ||||
| 		DEBUG(driver, 0, "Could not create the Cocoa window."); | ||||
| @@ -376,7 +391,7 @@ bool VideoDriver_Cocoa::MakeWindow(int width, int height) | ||||
| 		behavior |= NSWindowCollectionBehaviorFullScreenPrimary; | ||||
| 		[ this->window setCollectionBehavior:behavior ]; | ||||
|  | ||||
| 		NSButton* fullscreenButton = [ this->window standardWindowButton:NSWindowFullScreenButton ]; | ||||
| 		NSButton* fullscreenButton = [ this->window standardWindowButton:NSWindowZoomButton ]; | ||||
| 		[ fullscreenButton setAction:@selector(toggleFullScreen:) ]; | ||||
| 		[ fullscreenButton setTarget:this->window ]; | ||||
| 	} | ||||
| @@ -430,7 +445,12 @@ bool VideoDriver_Cocoa::MakeWindow(int width, int height) | ||||
|  */ | ||||
| bool VideoDriver_Cocoa::PollEvent() | ||||
| { | ||||
| 	NSEvent *event = [ NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[ NSDate distantPast ] inMode:NSDefaultRunLoopMode dequeue:YES ]; | ||||
| #ifdef HAVE_OSX_1012_SDK | ||||
| 	NSEventMask mask = NSEventMaskAny; | ||||
| #else | ||||
| 	NSEventMask mask = NSAnyEventMask; | ||||
| #endif | ||||
| 	NSEvent *event = [ NSApp nextEventMatchingMask:mask untilDate:[ NSDate distantPast ] inMode:NSDefaultRunLoopMode dequeue:YES ]; | ||||
|  | ||||
| 	if (event == nil) return false; | ||||
|  | ||||
| @@ -446,8 +466,8 @@ void VideoDriver_Cocoa::InputLoop() | ||||
| 	bool old_ctrl_pressed = _ctrl_pressed; | ||||
| 	bool old_shift_pressed = _shift_pressed; | ||||
|  | ||||
| 	_ctrl_pressed = ((cur_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask)) != 0) != _invert_ctrl; | ||||
| 	_shift_pressed = ((cur_mods & NSShiftKeyMask) != 0) != _invert_shift; | ||||
| 	_ctrl_pressed = ((cur_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSEventModifierFlagControl : NSEventModifierFlagCommand)) != 0) != _invert_ctrl; | ||||
| 	_shift_pressed = ((cur_mods & NSEventModifierFlagShift) != 0) != _invert_shift; | ||||
|  | ||||
| #if defined(_DEBUG) | ||||
| 	this->fast_forward_key_pressed = _shift_pressed; | ||||
|   | ||||
| @@ -32,7 +32,6 @@ extern NSString *OTTDMainLaunchGameEngine; | ||||
| @interface OTTD_CocoaWindow : NSWindow | ||||
| - (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag driver:(VideoDriver_Cocoa *)drv; | ||||
|  | ||||
| - (void)display; | ||||
| - (void)setFrame:(NSRect)frameRect display:(BOOL)flag; | ||||
| @end | ||||
|  | ||||
|   | ||||
| @@ -37,6 +37,16 @@ | ||||
| /* Table data for key mapping. */ | ||||
| #include "cocoa_keys.h" | ||||
|  | ||||
| /* The 10.12 SDK added new names for some enum constants and | ||||
|  * deprecated the old ones. As there's no functional change in any | ||||
|  * way, just use a define for older SDKs to the old names. */ | ||||
| #ifndef HAVE_OSX_1012_SDK | ||||
| #	define NSEventModifierFlagCommand NSCommandKeyMask | ||||
| #	define NSEventModifierFlagControl NSControlKeyMask | ||||
| #	define NSEventModifierFlagOption NSAlternateKeyMask | ||||
| #	define NSEventModifierFlagShift NSShiftKeyMask | ||||
| #	define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask | ||||
| #endif | ||||
|  | ||||
| /** | ||||
|  * Important notice regarding all modifications!!!!!!! | ||||
| @@ -135,7 +145,12 @@ static std::vector<WChar> NSStringToUTF32(NSString *s) | ||||
| 	[ NSApp stop:self ]; | ||||
|  | ||||
| 	/* Send an empty event to return from the run loop. Without that, application is stuck waiting for an event. */ | ||||
| 	NSEvent *event = [ NSEvent otherEventWithType:NSApplicationDefined location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0 windowNumber:0 context:nil subtype:0 data1:0 data2:0 ]; | ||||
| #ifdef HAVE_OSX_1012_SDK | ||||
| 	NSEventType type = NSEventTypeApplicationDefined; | ||||
| #else | ||||
| 	NSEventType type = NSApplicationDefined; | ||||
| #endif | ||||
| 	NSEvent *event = [ NSEvent otherEventWithType:type location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0 windowNumber:0 context:nil subtype:0 data1:0 data2:0 ]; | ||||
| 	[ NSApp postEvent:event atStart:YES ]; | ||||
| } | ||||
|  | ||||
| @@ -207,7 +222,7 @@ static void setApplicationMenu() | ||||
| 	[ appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h" ]; | ||||
|  | ||||
| 	NSMenuItem *menuItem = [ appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h" ]; | ||||
| 	[ menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask) ]; | ||||
| 	[ menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption | NSEventModifierFlagCommand) ]; | ||||
|  | ||||
| 	[ appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@"" ]; | ||||
|  | ||||
| @@ -329,7 +344,11 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel | ||||
|  | ||||
| 	@autoreleasepool { | ||||
| 		NSAlert *alert = [ [ NSAlert alloc ] init ]; | ||||
| #ifdef HAVE_OSX_1012_SDK | ||||
| 		[ alert setAlertStyle: NSAlertStyleCritical ]; | ||||
| #else | ||||
| 		[ alert setAlertStyle: NSCriticalAlertStyle ]; | ||||
| #endif | ||||
| 		[ alert setMessageText:[ NSString stringWithUTF8String:title ] ]; | ||||
| 		[ alert setInformativeText:[ NSString stringWithUTF8String:message ] ]; | ||||
| 		[ alert addButtonWithTitle: [ NSString stringWithUTF8String:buttonLabel ] ]; | ||||
| @@ -386,23 +405,6 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel | ||||
| 	return self; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * This method fires just before the window deminaturizes from the Dock. | ||||
|  * We'll save the current visible surface, let the window manager redraw any | ||||
|  * UI elements, and restore the surface. This way, no expose event | ||||
|  * is required, and the deminiaturize works perfectly. | ||||
|  */ | ||||
| - (void)display | ||||
| { | ||||
| 	/* save current visible surface */ | ||||
| 	[ self cacheImageInRect:[ driver->cocoaview frame ] ]; | ||||
|  | ||||
| 	/* let the window manager redraw controls, border, etc */ | ||||
| 	[ super display ]; | ||||
|  | ||||
| 	/* restore visible surface */ | ||||
| 	[ self restoreCachedImage ]; | ||||
| } | ||||
| /** | ||||
|  * Define the rectangle we draw our window in | ||||
|  */ | ||||
| @@ -536,8 +538,8 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel | ||||
| - (BOOL)emulateRightButton:(NSEvent *)event | ||||
| { | ||||
| 	uint32 keymask = 0; | ||||
| 	if (_settings_client.gui.right_mouse_btn_emulation == RMBE_COMMAND) keymask |= NSCommandKeyMask; | ||||
| 	if (_settings_client.gui.right_mouse_btn_emulation == RMBE_CONTROL) keymask |= NSControlKeyMask; | ||||
| 	if (_settings_client.gui.right_mouse_btn_emulation == RMBE_COMMAND) keymask |= NSEventModifierFlagCommand; | ||||
| 	if (_settings_client.gui.right_mouse_btn_emulation == RMBE_CONTROL) keymask |= NSEventModifierFlagControl; | ||||
|  | ||||
| 	return (event.modifierFlags & keymask) != 0; | ||||
| } | ||||
| @@ -653,18 +655,18 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel | ||||
|  | ||||
| 		case QZ_RETURN: | ||||
| 		case QZ_f: | ||||
| 			if (down && (modifiers & NSCommandKeyMask)) { | ||||
| 			if (down && (modifiers & NSEventModifierFlagCommand)) { | ||||
| 				VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen); | ||||
| 			} | ||||
| 			break; | ||||
|  | ||||
| 		case QZ_v: | ||||
| 			if (down && EditBoxInGlobalFocus() && (modifiers & (NSCommandKeyMask | NSControlKeyMask))) { | ||||
| 			if (down && EditBoxInGlobalFocus() && (modifiers & (NSEventModifierFlagCommand | NSEventModifierFlagControl))) { | ||||
| 				HandleKeypress(WKC_CTRL | 'V', unicode); | ||||
| 			} | ||||
| 			break; | ||||
| 		case QZ_u: | ||||
| 			if (down && EditBoxInGlobalFocus() && (modifiers & (NSCommandKeyMask | NSControlKeyMask))) { | ||||
| 			if (down && EditBoxInGlobalFocus() && (modifiers & (NSEventModifierFlagCommand | NSEventModifierFlagControl))) { | ||||
| 				HandleKeypress(WKC_CTRL | 'U', unicode); | ||||
| 			} | ||||
| 			break; | ||||
| @@ -676,10 +678,10 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel | ||||
| 		auto vk = std::find_if(std::begin(_vk_mapping), std::end(_vk_mapping), [=](const CocoaVkMapping &m) { return m.vk_from == keycode; }); | ||||
| 		uint32 pressed_key = vk != std::end(_vk_mapping) ? vk->map_to : 0; | ||||
|  | ||||
| 		if (modifiers & NSShiftKeyMask)     pressed_key |= WKC_SHIFT; | ||||
| 		if (modifiers & NSControlKeyMask)   pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_CTRL : WKC_META); | ||||
| 		if (modifiers & NSAlternateKeyMask) pressed_key |= WKC_ALT; | ||||
| 		if (modifiers & NSCommandKeyMask)   pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_META : WKC_CTRL); | ||||
| 		if (modifiers & NSEventModifierFlagShift)   pressed_key |= WKC_SHIFT; | ||||
| 		if (modifiers & NSEventModifierFlagControl) pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_CTRL : WKC_META); | ||||
| 		if (modifiers & NSEventModifierFlagOption)  pressed_key |= WKC_ALT; | ||||
| 		if (modifiers & NSEventModifierFlagCommand) pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_META : WKC_CTRL); | ||||
|  | ||||
| 		static bool console = false; | ||||
|  | ||||
| @@ -715,7 +717,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel | ||||
| 		case QZ_q: | ||||
| 		case QZ_h: | ||||
| 		case QZ_m: | ||||
| 			if (event.modifierFlags & NSCommandKeyMask) { | ||||
| 			if (event.modifierFlags & NSEventModifierFlagCommand) { | ||||
| 				[ self interpretKeyEvents:[ NSArray arrayWithObject:event ] ]; | ||||
| 			} | ||||
| 			break; | ||||
| @@ -744,7 +746,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel | ||||
| 		case QZ_q: | ||||
| 		case QZ_h: | ||||
| 		case QZ_m: | ||||
| 			if (event.modifierFlags & NSCommandKeyMask) { | ||||
| 			if (event.modifierFlags & NSEventModifierFlagCommand) { | ||||
| 				[ self interpretKeyEvents:[ NSArray arrayWithObject:event ] ]; | ||||
| 			} | ||||
| 			break; | ||||
| @@ -765,7 +767,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel | ||||
| 	if (self->_current_mods == newMods) return; | ||||
|  | ||||
| 	/* Iterate through the bits, testing each against the current modifiers */ | ||||
| 	for (unsigned int i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) { | ||||
| 	for (unsigned int i = 0, bit = NSEventModifierFlagCapsLock; bit <= NSEventModifierFlagCommand; bit <<= 1, ++i) { | ||||
| 		unsigned int currentMask, newMask; | ||||
|  | ||||
| 		currentMask = self->_current_mods & bit; | ||||
|   | ||||
| @@ -22,6 +22,7 @@ | ||||
|  | ||||
| #define GL_GLEXT_PROTOTYPES | ||||
| #if defined(__APPLE__) | ||||
| #	define GL_SILENCE_DEPRECATION | ||||
| #	include <OpenGL/gl3.h> | ||||
| #else | ||||
| #	include <GL/gl.h> | ||||
| @@ -146,7 +147,7 @@ GetOGLProcAddressProc GetOGLProcAddress; | ||||
|  */ | ||||
| const char *FindStringInExtensionList(const char *string, const char *substring) | ||||
| { | ||||
| 	while (1) { | ||||
| 	while (true) { | ||||
| 		/* Is the extension string present at all? */ | ||||
| 		const char *pos = strstr(string, substring); | ||||
| 		if (pos == nullptr) break; | ||||
| @@ -1309,7 +1310,7 @@ void OpenGLBackend::RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, int | ||||
| 			_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); | ||||
|  | ||||
| 			_glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, 256, GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1); | ||||
| 			_glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_RED, GL_UNSIGNED_BYTE, 0); | ||||
| 			_glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_RED, GL_UNSIGNED_BYTE, nullptr); | ||||
|  | ||||
| 			_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | ||||
|  | ||||
|   | ||||
| @@ -41,11 +41,6 @@ | ||||
|  | ||||
| #include "../safeguards.h" | ||||
|  | ||||
| #ifdef __EMSCRIPTEN__ | ||||
| /** Whether we just had a window-enter event. */ | ||||
| static bool _cursor_new_in_window = false; | ||||
| #endif | ||||
|  | ||||
| static std::string _editing_text; | ||||
|  | ||||
| static void SetTextInputRect(); | ||||
| @@ -424,9 +419,9 @@ bool VideoDriver_SDL_Base::CreateMainSurface(uint w, uint h, bool resize) | ||||
|  | ||||
| bool VideoDriver_SDL_Base::ClaimMousePointer() | ||||
| { | ||||
| 	/* Emscripten never claims the pointer, so we do not need to change the cursor visibility. */ | ||||
| #ifndef __EMSCRIPTEN__ | ||||
| 	SDL_ShowCursor(0); | ||||
| #ifdef __EMSCRIPTEN__ | ||||
| 	SDL_SetRelativeMouseMode(SDL_TRUE); | ||||
| #endif | ||||
| 	return true; | ||||
| } | ||||
| @@ -659,27 +654,9 @@ bool VideoDriver_SDL_Base::PollEvent() | ||||
|  | ||||
| 	switch (ev.type) { | ||||
| 		case SDL_MOUSEMOTION: | ||||
| #ifdef __EMSCRIPTEN__ | ||||
| 			if (_cursor_new_in_window) { | ||||
| 				/* The cursor just moved into the window; this means we don't | ||||
| 				 * know the absolutely position yet to move relative from. | ||||
| 				 * Before this time, SDL didn't know it either, and this is | ||||
| 				 * why we postpone it till now. Update the absolute position | ||||
| 				 * for this once, and work relative after. */ | ||||
| 				_cursor.pos.x = ev.motion.x; | ||||
| 				_cursor.pos.y = ev.motion.y; | ||||
| 				_cursor.dirty = true; | ||||
|  | ||||
| 				_cursor_new_in_window = false; | ||||
| 				SDL_SetRelativeMouseMode(SDL_TRUE); | ||||
| 			} else { | ||||
| 				_cursor.UpdateCursorPositionRelative(ev.motion.xrel, ev.motion.yrel); | ||||
| 			} | ||||
| #else | ||||
| 			if (_cursor.UpdateCursorPosition(ev.motion.x, ev.motion.y, true)) { | ||||
| 				SDL_WarpMouseInWindow(this->sdl_window, _cursor.pos.x, _cursor.pos.y); | ||||
| 			} | ||||
| #endif | ||||
| 			HandleMouseEvents(); | ||||
| 			break; | ||||
|  | ||||
| @@ -814,9 +791,7 @@ bool VideoDriver_SDL_Base::PollEvent() | ||||
| 				// mouse entered the window, enable cursor | ||||
| 				_cursor.in_window = true; | ||||
| #ifdef __EMSCRIPTEN__ | ||||
| 				/* Disable relative mouse mode for the first mouse motion, | ||||
| 				 * so we can pick up the absolutely position again. */ | ||||
| 				_cursor_new_in_window = true; | ||||
| 				/* Ensure pointer lock will not occur. */ | ||||
| 				SDL_SetRelativeMouseMode(SDL_FALSE); | ||||
| #endif | ||||
| 			} else if (ev.window.event == SDL_WINDOWEVENT_LEAVE) { | ||||
| @@ -857,7 +832,9 @@ static const char *InitializeSDL() | ||||
| 	 * UpdateWindowSurface() to update the window's texture instead of | ||||
| 	 * its surface. */ | ||||
| 	SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0"); | ||||
| #ifndef __EMSCRIPTEN__ | ||||
| 	SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1"); | ||||
| #endif | ||||
|  | ||||
| 	/* Check if the video-driver is already initialized. */ | ||||
| 	if (SDL_WasInit(SDL_INIT_VIDEO) != 0) return nullptr; | ||||
| @@ -926,7 +903,7 @@ void VideoDriver_SDL_Base::Stop() | ||||
| void VideoDriver_SDL_Base::InputLoop() | ||||
| { | ||||
| 	uint32 mod = SDL_GetModState(); | ||||
| 	const Uint8 *keys = SDL_GetKeyboardState(NULL); | ||||
| 	const Uint8 *keys = SDL_GetKeyboardState(nullptr); | ||||
|  | ||||
| 	bool old_ctrl_pressed = _ctrl_pressed; | ||||
| 	bool old_shift_pressed = _shift_pressed; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan G Rennison
					Jonathan G Rennison