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 },
};
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) {
width: 37px;

View File

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