Added common touchbar utils.

This commit is contained in:
23rd 2020-07-04 14:52:18 +03:00 committed by John Preston
parent b02dd889e0
commit 0970728273
3 changed files with 64 additions and 0 deletions

View File

@ -891,6 +891,8 @@ PRIVATE
platform/mac/specific_mac_p.h
platform/mac/window_title_mac.mm
platform/mac/window_title_mac.h
platform/mac/touchbar/mac_touchbar_common.h
platform/mac/touchbar/mac_touchbar_common.mm
platform/win/audio_win.cpp
platform/win/audio_win.h
platform/win/file_utilities_win.cpp

View File

@ -0,0 +1,32 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#import <AppKit/NSImage.h>
#import <Foundation/Foundation.h>
namespace TouchBar {
constexpr auto kCircleDiameter = 30;
template <typename Callable>
void CustomEnterToCocoaEventLoop(Callable callable) {
id block = [^{ callable(); } copy]; // Don't forget to -release.
[block
performSelectorOnMainThread:@selector(invoke)
withObject:nil
waitUntilDone:true];
// [block performSelector:@selector(invoke) withObject:nil afterDelay:d];
[block release];
}
int WidthFromString(NSString *s);
NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size);
} // namespace TouchBar

View File

@ -0,0 +1,30 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "platform/mac/touchbar/mac_touchbar_common.h"
#import <AppKit/NSTextField.h>
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
namespace TouchBar {
int WidthFromString(NSString *s) {
return (int)ceil(
[[NSTextField labelWithString:s] frame].size.width) * 1.2;
}
NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size) {
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;
}
} // namespace TouchBar