Merge branch 'master' into jgrpp-beta
# Conflicts: # src/command.cpp # src/console_cmds.cpp # src/group_gui.cpp # src/lang/catalan.txt # src/lang/czech.txt # src/lang/danish.txt # src/lang/greek.txt # src/lang/hungarian.txt # src/lang/irish.txt # src/lang/japanese.txt # src/lang/luxembourgish.txt # src/lang/norwegian_bokmal.txt # src/lang/romanian.txt # src/lang/russian.txt # src/lang/serbian.txt # src/lang/simplified_chinese.txt # src/lang/slovak.txt # src/lang/spanish_MX.txt # src/lang/swedish.txt # src/lang/tamil.txt # src/lang/traditional_chinese.txt # src/lang/turkish.txt # src/lang/ukrainian.txt # src/lang/vietnamese.txt # src/network/network.cpp # src/network/network_client.cpp # src/network/network_func.h # src/network/network_internal.h # src/network/network_server.cpp # src/network/network_server.h # src/saveload/afterload.cpp # src/saveload/newgrf_sl.cpp # src/saveload/saveload.h # src/script/script_instance.cpp # src/toolbar_gui.cpp # src/toolbar_gui.h # src/vehicle_gui.cpp # src/widgets/rail_widget.h # src/widgets/vehicle_widget.h # src/window.cpp
This commit is contained in:
		| @@ -11,6 +11,8 @@ | ||||
| #define COCOA_WND_H | ||||
|  | ||||
| #import <Cocoa/Cocoa.h> | ||||
| #include "toolbar_gui.h" | ||||
| #include "table/sprites.h" | ||||
|  | ||||
| class VideoDriver_Cocoa; | ||||
|  | ||||
| @@ -28,8 +30,67 @@ extern NSString *OTTDMainLaunchGameEngine; | ||||
| + (NSCursor *) clearCocoaCursor; | ||||
| @end | ||||
|  | ||||
| #ifdef HAVE_OSX_1015_SDK | ||||
| /* 9 items can be displayed on the touch bar when using default buttons. */ | ||||
| static NSArray *touchBarButtonIdentifiers = @[ | ||||
| 	@"openttd.pause", | ||||
| 	@"openttd.fastforward", | ||||
| 	@"openttd.zoom_in", | ||||
| 	@"openttd.zoom_out", | ||||
| 	@"openttd.build_rail", | ||||
| 	@"openttd.build_road", | ||||
| 	@"openttd.build_tram", | ||||
| 	@"openttd.build_docks", | ||||
| 	@"openttd.build_airport", | ||||
| 	NSTouchBarItemIdentifierOtherItemsProxy | ||||
| ]; | ||||
|  | ||||
| static NSDictionary *touchBarButtonSprites = @{ | ||||
| 	@"openttd.pause":           [NSNumber numberWithInt:SPR_IMG_PAUSE], | ||||
| 	@"openttd.fastforward":     [NSNumber numberWithInt:SPR_IMG_FASTFORWARD], | ||||
| 	@"openttd.zoom_in":         [NSNumber numberWithInt:SPR_IMG_ZOOMIN], | ||||
| 	@"openttd.zoom_out":        [NSNumber numberWithInt:SPR_IMG_ZOOMOUT], | ||||
| 	@"openttd.build_rail":      [NSNumber numberWithInt:SPR_IMG_BUILDRAIL], | ||||
| 	@"openttd.build_road":      [NSNumber numberWithInt:SPR_IMG_BUILDROAD], | ||||
| 	@"openttd.build_tram":      [NSNumber numberWithInt:SPR_IMG_BUILDTRAMS], | ||||
| 	@"openttd.build_docks":     [NSNumber numberWithInt:SPR_IMG_BUILDWATER], | ||||
| 	@"openttd.build_airport":   [NSNumber numberWithInt:SPR_IMG_BUILDAIR], | ||||
| }; | ||||
|  | ||||
| static NSDictionary *touchBarButtonActions = @{ | ||||
| 	@"openttd.pause":           [NSNumber numberWithInt:MTHK_PAUSE], | ||||
| 	@"openttd.fastforward":     [NSNumber numberWithInt:MTHK_FASTFORWARD], | ||||
| 	@"openttd.zoom_in":         [NSNumber numberWithInt:MTHK_ZOOM_IN], | ||||
| 	@"openttd.zoom_out":        [NSNumber numberWithInt:MTHK_ZOOM_OUT], | ||||
| 	@"openttd.build_rail":      [NSNumber numberWithInt:MTHK_BUILD_RAIL], | ||||
| 	@"openttd.build_road":      [NSNumber numberWithInt:MTHK_BUILD_ROAD], | ||||
| 	@"openttd.build_tram":      [NSNumber numberWithInt:MTHK_BUILD_TRAM], | ||||
| 	@"openttd.build_docks":     [NSNumber numberWithInt:MTHK_BUILD_DOCKS], | ||||
| 	@"openttd.build_airport":   [NSNumber numberWithInt:MTHK_BUILD_AIRPORT], | ||||
| }; | ||||
|  | ||||
| static NSDictionary *touchBarFallbackText = @{ | ||||
| 	@"openttd.pause":           @"Pause", | ||||
| 	@"openttd.fastforward":     @"Fast Forward", | ||||
| 	@"openttd.zoom_in":         @"Zoom In", | ||||
| 	@"openttd.zoom_out":        @"Zoom Out", | ||||
| 	@"openttd.build_rail":      @"Rail", | ||||
| 	@"openttd.build_road":      @"Road", | ||||
| 	@"openttd.build_tram":      @"Tram", | ||||
| 	@"openttd.build_docks":     @"Docks", | ||||
| 	@"openttd.build_airport":   @"Airport", | ||||
| }; | ||||
| #endif | ||||
|  | ||||
| /** Subclass of NSWindow to cater our special needs */ | ||||
| #ifdef HAVE_OSX_1015_SDK | ||||
| @interface OTTD_CocoaWindow : NSWindow <NSTouchBarDelegate> | ||||
| @property (strong) NSSet *touchbarItems; | ||||
| - (NSImage*)generateImage:(int)spriteId; | ||||
| #else | ||||
| @interface OTTD_CocoaWindow : NSWindow | ||||
| #endif | ||||
|  | ||||
| - (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag driver:(VideoDriver_Cocoa *)drv; | ||||
|  | ||||
| - (void)setFrame:(NSRect)frameRect display:(BOOL)flag; | ||||
|   | ||||
| @@ -32,7 +32,7 @@ | ||||
| #include "../../gfx_func.h" | ||||
| #include "../../window_func.h" | ||||
| #include "../../window_gui.h" | ||||
|  | ||||
| #include "spritecache.h" | ||||
|  | ||||
| /* Table data for key mapping. */ | ||||
| #include "cocoa_keys.h" | ||||
| @@ -405,6 +405,87 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel | ||||
| 	return self; | ||||
| } | ||||
|  | ||||
| #ifdef HAVE_OSX_1015_SDK | ||||
|  | ||||
| - (void)touchBarButtonAction:(id)sender | ||||
| { | ||||
| 	if (@available(macOS 10.15, *)) { | ||||
| 		NSButtonTouchBarItem *btn = (NSButtonTouchBarItem *)sender; | ||||
| 		NSNumber *hotkeyIndex = [ touchBarButtonActions objectForKey:btn.identifier ]; | ||||
| 		HandleToolbarHotkey(hotkeyIndex.intValue); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| #pragma mark NSTouchBarProvider | ||||
| - (nullable NSTouchBar *)makeTouchBar | ||||
| { | ||||
| 	NSTouchBar *bar = [ [ NSTouchBar alloc ] init ]; | ||||
| 	bar.delegate = self; | ||||
| 	bar.defaultItemIdentifiers = touchBarButtonIdentifiers; | ||||
|  | ||||
| 	return bar; | ||||
| } | ||||
|  | ||||
| -(NSImage *)generateImage:(int)spriteId | ||||
| { | ||||
| 	if (!SpriteExists(spriteId)) { | ||||
| 		return nullptr; | ||||
| 	} | ||||
|  | ||||
| 	/* Fetch the sprite and create a new bitmap */ | ||||
| 	const Sprite *fullspr = GetSprite(spriteId, ST_NORMAL); | ||||
| 	const std::unique_ptr<uint32[]> buffer = DrawSpriteToRgbaBuffer(spriteId); | ||||
| 	if (!buffer) { | ||||
| 		return nullptr; // failed to blit sprite or we're using an 8bpp blitter. | ||||
| 	} | ||||
|  | ||||
| 	NSBitmapImageRep *bitmap = [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes:nil pixelsWide:fullspr->width pixelsHigh:fullspr->height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:0 ]; | ||||
|  | ||||
| 	/* Copy the sprite to the NSBitmapImageRep image buffer */ | ||||
| 	const Colour *src = (const Colour *)buffer.get(); | ||||
| 	for (int y = 0; y < fullspr->height; y++) { | ||||
| 		for (int x = 0; x < fullspr->width; x++) { | ||||
| 			NSUInteger pixel[4]; | ||||
| 			pixel[0] = src->r; | ||||
| 			pixel[1] = src->g; | ||||
| 			pixel[2] = src->b; | ||||
| 			pixel[3] = src->a; | ||||
| 			[ bitmap setPixel:pixel atX:x y:y ]; | ||||
|  | ||||
| 			src += 1; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	/* Finally, convert the NSBitmapImageRep we created to a NSimage we can put on the button and clean up. */ | ||||
| 	NSImage *outImage = [ [ NSImage alloc ] initWithSize:NSMakeSize(fullspr->width, fullspr->height) ]; | ||||
| 	[ outImage addRepresentation:bitmap ]; | ||||
| 	[ bitmap release ]; | ||||
|  | ||||
| 	return outImage; | ||||
| } | ||||
|  | ||||
| #pragma mark NSTouchBarDelegate | ||||
| - (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier | ||||
| { | ||||
| 	if (@available(macOS 10.15, *)) { | ||||
| 		NSButtonTouchBarItem *button = [ [ NSButtonTouchBarItem alloc ] initWithIdentifier:identifier ]; | ||||
| 		button.target = self; | ||||
| 		button.action = @selector(touchBarButtonAction:); | ||||
|  | ||||
| 		NSNumber *num = touchBarButtonSprites[identifier]; | ||||
| 		NSImage *generatedImage = [ self generateImage:num.unsignedIntValue ]; | ||||
| 		if (generatedImage != nullptr) { | ||||
| 			button.image = generatedImage; | ||||
| 		} else { | ||||
| 			button.title = NSLocalizedString(touchBarFallbackText[identifier], @""); | ||||
| 		} | ||||
| 		return button; | ||||
| 	} else { | ||||
| 		return nullptr; | ||||
| 	} | ||||
| } | ||||
| #endif | ||||
|  | ||||
| /** | ||||
|  * Define the rectangle we draw our window in | ||||
|  */ | ||||
|   | ||||
| @@ -325,6 +325,8 @@ protected: | ||||
|  | ||||
| 	std::chrono::steady_clock::duration GetDrawInterval() | ||||
| 	{ | ||||
| 		/* If vsync, draw interval is decided by the display driver */ | ||||
| 		if (_video_vsync && _video_hw_accel) return std::chrono::microseconds(0); | ||||
| 		return std::chrono::microseconds(1000000 / _settings_client.gui.refresh_rate); | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan G Rennison
					Jonathan G Rennison