Replaced Apple icons for touchbar with custom icons in audio player.

This commit is contained in:
23rd 2019-05-04 13:24:56 +03:00 committed by John Preston
parent 757e0e6335
commit a80f7c53ea
2 changed files with 17 additions and 10 deletions

View File

@ -153,7 +153,11 @@ mediaPlayerPreviousDisabledIcon: icon {
{ "player_next-flip_horizontal", mediaPlayerInactiveFg, mediaPlayerSkipIconPosition }, { "player_next-flip_horizontal", mediaPlayerInactiveFg, mediaPlayerSkipIconPosition },
}; };
iconPlayerClose: icon {{ "player_close", windowFg }}; touchBarIconPlayerClose: icon {{ "player_close", windowFg }};
touchBarIconPlayerPlay: icon {{ "media_play", windowFg }};
touchBarIconPlayerPause: icon {{ "media_pause", windowFg }};
touchBarIconPlayerNext: icon {{ "player_next", windowFg }};
touchBarIconPlayerPrevious: icon {{ "player_next-flip_horizontal", windowFg }};
mediaPlayerClose: IconButton(mediaPlayerRepeatButton) { mediaPlayerClose: IconButton(mediaPlayerRepeatButton) {
width: 37px; width: 37px;

View File

@ -216,6 +216,7 @@ auto lifetime = rpl::lifetime();
- (id) init:(NSView *)view { - (id) init:(NSView *)view {
self = [super init]; self = [super init];
if (self) { if (self) {
const auto iconSize = kIdealIconSize / 3;
self.view = view; self.view = view;
self.touchbarItems = @{ self.touchbarItems = @{
pinnedPanel: [NSMutableDictionary dictionaryWithDictionary:@{ pinnedPanel: [NSMutableDictionary dictionaryWithDictionary:@{
@ -229,26 +230,26 @@ auto lifetime = rpl::lifetime();
@"type": @"button", @"type": @"button",
@"name": @"Play Button", @"name": @"Play Button",
@"cmd": [NSNumber numberWithInt:kPlayPause], @"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarPauseTemplate], @"image": createImageFromStyleIcon(st::touchBarIconPlayerPause, iconSize),
@"imageAlt": [NSImage imageNamed:NSImageNameTouchBarPlayTemplate] @"imageAlt": createImageFromStyleIcon(st::touchBarIconPlayerPlay, iconSize),
}], }],
previousItem: [NSMutableDictionary dictionaryWithDictionary:@{ previousItem: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button", @"type": @"button",
@"name": @"Previous Playlist Item", @"name": @"Previous Playlist Item",
@"cmd": [NSNumber numberWithInt:kPlaylistPrevious], @"cmd": [NSNumber numberWithInt:kPlaylistPrevious],
@"image": [NSImage imageNamed:NSImageNameTouchBarGoBackTemplate] @"image": createImageFromStyleIcon(st::touchBarIconPlayerPrevious, iconSize),
}], }],
nextItem: [NSMutableDictionary dictionaryWithDictionary:@{ nextItem: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button", @"type": @"button",
@"name": @"Next Playlist Item", @"name": @"Next Playlist Item",
@"cmd": [NSNumber numberWithInt:kPlaylistNext], @"cmd": [NSNumber numberWithInt:kPlaylistNext],
@"image": [NSImage imageNamed:NSImageNameTouchBarGoForwardTemplate] @"image": createImageFromStyleIcon(st::touchBarIconPlayerNext, iconSize),
}], }],
closePlayer: [NSMutableDictionary dictionaryWithDictionary:@{ closePlayer: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button", @"type": @"button",
@"name": @"Close Player", @"name": @"Close Player",
@"cmd": [NSNumber numberWithInt:kClosePlayer], @"cmd": [NSNumber numberWithInt:kClosePlayer],
@"image": createImageFromStyleIcon(st::iconPlayerClose, NSMakeSize(kIdealIconSize / 3, kIdealIconSize / 3)) @"image": createImageFromStyleIcon(st::touchBarIconPlayerClose, iconSize),
}], }],
currentPosition: [NSMutableDictionary dictionaryWithDictionary:@{ currentPosition: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"text", @"type": @"text",
@ -281,10 +282,12 @@ auto lifetime = rpl::lifetime();
return self; return self;
} }
NSImage *createImageFromStyleIcon(const style::icon &icon, NSSize size) { NSImage *createImageFromStyleIcon(const style::icon &icon, int size = kIdealIconSize) {
const auto pixmap = icon.instance(QColor(255, 255, 255, 255), 100); const auto instance = icon.instance(QColor(255, 255, 255, 255), 100);
NSImage *image = [qt_mac_create_nsimage(QPixmap::fromImage(pixmap)) autorelease]; auto pixmap = QPixmap::fromImage(instance);
[image setSize:size]; pixmap.setDevicePixelRatio(cRetinaFactor());
NSImage *image = [qt_mac_create_nsimage(pixmap) autorelease];
[image setSize:NSMakeSize(size, size)];
return image; return image;
} }