diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj index bba52781d46d8325ce7890c137f4324c388ce323..23632d473a22428278477747e579d3c0f349358d 100644 --- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj +++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj @@ -153,6 +153,7 @@ 7DFBDCAE2269ED0C00B700A5 /* VLCLibraryDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCAD2269ED0C00B700A5 /* VLCLibraryDataSource.m */; }; 7DFBDCB1226A518400B700A5 /* VLCLibraryMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCB0226A518400B700A5 /* VLCLibraryMenuController.m */; }; 7DFBDCB4226CD00900B700A5 /* VLCLibraryDataTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCB3226CD00900B700A5 /* VLCLibraryDataTypes.m */; }; + 7DFBDCB7226CDFD600B700A5 /* VLCImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCB6226CDFD600B700A5 /* VLCImageView.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -518,6 +519,8 @@ 7DFBDCB0226A518400B700A5 /* VLCLibraryMenuController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryMenuController.m; sourceTree = "<group>"; }; 7DFBDCB2226CD00900B700A5 /* VLCLibraryDataTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryDataTypes.h; sourceTree = "<group>"; }; 7DFBDCB3226CD00900B700A5 /* VLCLibraryDataTypes.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryDataTypes.m; sourceTree = "<group>"; }; + 7DFBDCB5226CDFD600B700A5 /* VLCImageView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCImageView.h; sourceTree = "<group>"; }; + 7DFBDCB6226CDFD600B700A5 /* VLCImageView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCImageView.m; sourceTree = "<group>"; }; 8E49720006417F6800370C9F /* VLCInformationWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCInformationWindowController.h; sourceTree = "<group>"; }; 8E49720106417F6800370C9F /* VLCInformationWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCInformationWindowController.m; sourceTree = "<group>"; }; 8E55FB7F0459B0FD00FB3317 /* VLCOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCOutput.h; sourceTree = "<group>"; }; @@ -778,6 +781,8 @@ 6B2EFC621F281A0900F3C0EA /* VLCVolumeSliderCell.m */, 1C1C61FF1F8260A90052DD4F /* VLCWrappableTextField.h */, 1C1C62001F8260A90052DD4F /* VLCWrappableTextField.m */, + 7DFBDCB5226CDFD600B700A5 /* VLCImageView.h */, + 7DFBDCB6226CDFD600B700A5 /* VLCImageView.m */, ); path = views; sourceTree = "<group>"; @@ -1558,6 +1563,7 @@ 1C31138E1E508C6900D4DD76 /* VLCAboutWindowController.m in Sources */, 1C3113901E508C6900D4DD76 /* VLCHelpWindowController.m in Sources */, 1C3113921E508C6900D4DD76 /* VLCAddonListItem.m in Sources */, + 7DFBDCB7226CDFD600B700A5 /* VLCImageView.m in Sources */, 7DE9C7DD220728420089108F /* VLCPlayerController.m in Sources */, 1C3113941E508C6900D4DD76 /* VLCAddonsWindowController.m in Sources */, 7D2E0EDE20CD206F0033A221 /* VLCVideoWindowCommon.m in Sources */, diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am index 501fa05eea43ff4423771bf398dbcec711c47ef2..5a0a57574d622d413709eb9abdffd6802fc82716 100644 --- a/modules/gui/macosx/Makefile.am +++ b/modules/gui/macosx/Makefile.am @@ -153,6 +153,8 @@ libmacosx_plugin_la_SOURCES = \ gui/macosx/views/VLCHUDTableView.m \ gui/macosx/views/VLCImageButton.h \ gui/macosx/views/VLCImageButton.m \ + gui/macosx/views/VLCImageView.h \ + gui/macosx/views/VLCImageView.m \ gui/macosx/views/VLCScrollingClipView.h \ gui/macosx/views/VLCScrollingClipView.m \ gui/macosx/views/VLCSlider.h \ diff --git a/modules/gui/macosx/views/VLCImageView.h b/modules/gui/macosx/views/VLCImageView.h new file mode 100644 index 0000000000000000000000000000000000000000..46e73f95c1dc220fc54a341b1423fa418575973f --- /dev/null +++ b/modules/gui/macosx/views/VLCImageView.h @@ -0,0 +1,45 @@ +/***************************************************************************** + * VLCImageView.h: MacOS X interface module + ***************************************************************************** + * Copyright (C) 2019 VLC authors and VideoLAN + * + * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#import <Cocoa/Cocoa.h> + +typedef NS_ENUM(NSInteger, VLCImageViewContentGravity) { + VLCImageViewContentGravityCenter, + VLCImageViewContentGravityTop, + VLCImageViewContentGravityBottom, + VLCImageViewContentGravityLeft, + VLCImageViewContentGravityRight, + VLCImageViewContentGravityTopLeft, + VLCImageViewContentGravityTopRight, + VLCImageViewContentGravityBottomLeft, + VLCImageViewContentGravityBottomRight, + VLCImageViewContentGravityResize, + VLCImageViewContentGravityResizeAspect, + VLCImageViewContentGravityResizeAspectFill, +}; + +@interface VLCImageView : NSView + +@property (readwrite, retain, nonatomic, nullable) NSImage *image; +@property (readwrite) VLCImageViewContentGravity contentGravity; + +@end diff --git a/modules/gui/macosx/views/VLCImageView.m b/modules/gui/macosx/views/VLCImageView.m new file mode 100644 index 0000000000000000000000000000000000000000..e3bd78698a3c4123e8e483a0d1a92f1f6899534c --- /dev/null +++ b/modules/gui/macosx/views/VLCImageView.m @@ -0,0 +1,108 @@ +/***************************************************************************** + * VLCImageView.m: MacOS X interface module + ***************************************************************************** + * Copyright (C) 2019 VLC authors and VideoLAN + * + * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#import "VLCImageView.h" + +@implementation VLCImageView + +- (instancetype)initWithFrame:(NSRect)frameRect +{ + self = [super initWithFrame:frameRect]; + if (self) { + [self setupLayer]; + } + return self; +} + +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + self = [super initWithCoder:decoder]; + if (self) { + [self setupLayer]; + } + return self; +} + +- (void)setupLayer +{ + self.layer = [[CALayer alloc] init]; + self.contentGravity = VLCImageViewContentGravityResizeAspectFill; + self.wantsLayer = YES; +} + +- (void)setImage:(NSImage *)image +{ + _image = image; + CGFloat desiredScaleFactor = [self.window backingScaleFactor]; + CGFloat actualScaleFactor = [image recommendedLayerContentsScale:desiredScaleFactor]; + + id layerContents = [image layerContentsForContentsScale:actualScaleFactor]; + + [self setCAContentGravity:_contentGravity]; + [self.layer setContents:layerContents]; + [self.layer setContentsScale:actualScaleFactor]; +} + +- (void)setCAContentGravity:(VLCImageViewContentGravity)contentGravity +{ + switch (contentGravity) { + case VLCImageViewContentGravityCenter: + self.layer.contentsGravity = kCAGravityCenter; + break; + case VLCImageViewContentGravityTop: + self.layer.contentsGravity = kCAGravityTop; + break; + case VLCImageViewContentGravityBottom: + self.layer.contentsGravity = kCAGravityBottom; + break; + case VLCImageViewContentGravityLeft: + self.layer.contentsGravity = kCAGravityLeft; + break; + case VLCImageViewContentGravityRight: + self.layer.contentsGravity = kCAGravityRight; + break; + case VLCImageViewContentGravityTopLeft: + self.layer.contentsGravity = kCAGravityTopLeft; + break; + case VLCImageViewContentGravityTopRight: + self.layer.contentsGravity = kCAGravityTopRight; + break; + case VLCImageViewContentGravityBottomLeft: + self.layer.contentsGravity = kCAGravityBottomLeft; + break; + case VLCImageViewContentGravityBottomRight: + self.layer.contentsGravity = kCAGravityBottomRight; + break; + case VLCImageViewContentGravityResize: + self.layer.contentsGravity = kCAGravityResize; + break; + case VLCImageViewContentGravityResizeAspect: + self.layer.contentsGravity = kCAGravityResizeAspect; + break; + case VLCImageViewContentGravityResizeAspectFill: + default: + self.layer.contentsGravity = kCAGravityResizeAspectFill; + break; + } +} + +@end diff --git a/po/POTFILES.in b/po/POTFILES.in index 86bbe53ce6c6281875447e5b6088ee2d308a46ee..495eb3cb3f23cf7bede645a157defa3939ae521c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -569,6 +569,8 @@ modules/gui/macosx/views/VLCHUDTableView.h modules/gui/macosx/views/VLCHUDTableView.m modules/gui/macosx/views/VLCImageButton.h modules/gui/macosx/views/VLCImageButton.m +modules/gui/macosx/views/VLCImageView.h +modules/gui/macosx/views/VLCImageView.m modules/gui/macosx/views/VLCScrollingClipView.h modules/gui/macosx/views/VLCScrollingClipView.m modules/gui/macosx/views/VLCSlider.h