Commit 2f12c304 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: add custom view to show images

This custom class allows a plethora of content gravities like its UIKit equivaltent
parent 72d032eb
......@@ -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 */,
......
......@@ -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 \
......
/*****************************************************************************
* 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
/*****************************************************************************
* 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
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment