[vlc-commits] macosx: coding style improvements

Felix Paul Kühne git at videolan.org
Wed May 15 18:18:10 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Wed May 15 18:17:59 2019 +0200| [9339899f467383f34a5d4def91d740b89b27ff87] | committer: Felix Paul Kühne

macosx: coding style improvements

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9339899f467383f34a5d4def91d740b89b27ff87
---

 modules/gui/macosx/extensions/NSFont+VLCAdditions.h  |  2 ++
 modules/gui/macosx/extensions/NSFont+VLCAdditions.m  | 10 ++++++++++
 .../macosx/library/VLCLibraryAlbumTableCellView.m    |  9 ++++++---
 .../macosx/library/VLCLibraryCollectionViewItem.m    |  8 +++++---
 modules/gui/macosx/library/VLCLibraryDataTypes.h     |  5 +++++
 modules/gui/macosx/library/VLCLibraryDataTypes.m     |  5 +++++
 modules/gui/macosx/library/VLCLibraryWindow.m        | 20 ++++++++++----------
 .../gui/macosx/playlist/VLCPlaylistTableCellView.m   | 10 ++--------
 .../macosx/windows/video/VLCDetachedVideoWindow.m    |  2 +-
 .../macosx/windows/video/VLCVideoOutputProvider.m    |  2 +-
 .../gui/macosx/windows/video/VLCVideoWindowCommon.h  |  2 +-
 .../gui/macosx/windows/video/VLCVideoWindowCommon.m  |  5 +++--
 12 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/modules/gui/macosx/extensions/NSFont+VLCAdditions.h b/modules/gui/macosx/extensions/NSFont+VLCAdditions.h
index df7058a7c1..0d74b79c7c 100644
--- a/modules/gui/macosx/extensions/NSFont+VLCAdditions.h
+++ b/modules/gui/macosx/extensions/NSFont+VLCAdditions.h
@@ -34,6 +34,8 @@ NS_ASSUME_NONNULL_BEGIN
 + (instancetype)VLClibraryCellSubtitleFont;
 + (instancetype)VLClibraryCellAnnotationFont;
 + (instancetype)VLClibraryButtonFont;
++ (instancetype)VLCplaylistLabelFont;
++ (instancetype)VLCplaylistSelectedItemLabelFont;
 
 @end
 
diff --git a/modules/gui/macosx/extensions/NSFont+VLCAdditions.m b/modules/gui/macosx/extensions/NSFont+VLCAdditions.m
index 74c227c075..2a61bd649d 100644
--- a/modules/gui/macosx/extensions/NSFont+VLCAdditions.m
+++ b/modules/gui/macosx/extensions/NSFont+VLCAdditions.m
@@ -64,4 +64,14 @@
     return [NSFont systemFontOfSize:15. weight:NSFontWeightBold];
 }
 
++ (instancetype)VLCplaylistLabelFont
+{
+    return [NSFont systemFontOfSize:13. weight:NSFontWeightRegular];
+}
+
++ (instancetype)VLCplaylistSelectedItemLabelFont
+{
+    return [NSFont systemFontOfSize:13. weight:NSFontWeightBold];
+}
+
 @end
diff --git a/modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m b/modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m
index a126e63b5b..7c475a5c83 100644
--- a/modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m
+++ b/modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m
@@ -30,7 +30,8 @@
 #import "library/VLCLibraryDataTypes.h"
 #import "library/VLCLibraryTableCellView.h"
 
-static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier";
+NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier";
+const CGFloat VLCLibraryTracksRowHeight = 50.;
 
 @interface VLCLibraryTracksDataSource : NSObject <NSTableViewDataSource, NSTableViewDelegate>
 
@@ -87,7 +88,9 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
 {
     _representedAlbum = representedAlbum;
     self.albumNameTextField.stringValue = _representedAlbum.title;
-    self.yearTextField.intValue = _representedAlbum.year;
+    if (_representedAlbum.year > 0) {
+        self.yearTextField.intValue = _representedAlbum.year;
+    }
     self.summaryTextField.stringValue = _representedAlbum.summary;
 
     NSImage *image;
@@ -99,7 +102,7 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
     }
     self.representedImageView.image = image;
 
-    self.tracksTableView.rowHeight = 50.;
+    self.tracksTableView.rowHeight = VLCLibraryTracksRowHeight;
     _tracksDataSource = [[VLCLibraryTracksDataSource alloc] init];
     _tracksDataSource.representedAlbum = _representedAlbum;
     self.tracksTableView.dataSource = _tracksDataSource;
diff --git a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
index ce07f70edd..d2457114a9 100644
--- a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
+++ b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
@@ -36,6 +36,8 @@
 #import "extensions/NSView+VLCAdditions.h"
 
 NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier";
+const CGFloat VLCLibraryCollectionViewItemMinimalDisplayedProgress = 0.05;
+const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
 
 @interface VLCLibraryCollectionViewItem()
 {
@@ -151,10 +153,10 @@ NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier";
     VLCMediaLibraryTrack *videoTrack = _representedMediaItem.firstVideoTrack;
     CGFloat width = videoTrack.videoWidth;
     CGFloat height = videoTrack.videoHeight;
-    if (width >= 3840. || height >= 2160.) {
+    if (width >= VLCMediaLibrary4KWidth || height >= VLCMediaLibrary4KHeight) {
         _annotationTextField.stringValue = @" 4K ";
         _annotationTextField.hidden = NO;
-    } else if (width >= 1280. || height >= 720.) {
+    } else if (width >= VLCMediaLibrary720pWidth || height >= VLCMediaLibrary720pHeight) {
         _annotationTextField.stringValue = @" HD ";
         _annotationTextField.hidden = NO;
     } else {
@@ -162,7 +164,7 @@ NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier";
     }
 
     CGFloat position = _representedMediaItem.lastPlaybackPosition;
-    if (position > .05 && position < .95) {
+    if (position > VLCLibraryCollectionViewItemMinimalDisplayedProgress && position < VLCLibraryCollectionViewItemMaximumDisplayedProgress) {
         _progressIndicator.progress = position;
         _progressIndicator.hidden = NO;
     } else {
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.h b/modules/gui/macosx/library/VLCLibraryDataTypes.h
index ebf691f8af..8fb75bc8a8 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.h
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.h
@@ -27,6 +27,11 @@ NS_ASSUME_NONNULL_BEGIN
 
 @class VLCMediaLibraryMediaItem;
 
+extern const CGFloat VLCMediaLibrary4KWidth;
+extern const CGFloat VLCMediaLibrary4KHeight;
+extern const CGFloat VLCMediaLibrary720pWidth;
+extern const CGFloat VLCMediaLibrary720pHeight;
+
 @interface VLCMediaLibraryFile : NSObject
 
 - (instancetype)initWithFile:(struct vlc_ml_file_t *)p_file;
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.m b/modules/gui/macosx/library/VLCLibraryDataTypes.m
index 3cd63dd0aa..af99634fd2 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.m
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.m
@@ -27,6 +27,11 @@
 
 #import <vlc_url.h>
 
+const CGFloat VLCMediaLibrary4KWidth = 3840.;
+const CGFloat VLCMediaLibrary4KHeight = 2160.;
+const CGFloat VLCMediaLibrary720pWidth = 1280.;
+const CGFloat VLCMediaLibrary720pHeight = 720.;
+
 @implementation VLCMediaLibraryFile
 
 - (instancetype)initWithFile:(struct vlc_ml_file_t *)p_file
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.m b/modules/gui/macosx/library/VLCLibraryWindow.m
index e9c1906060..92f7ecee0c 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.m
+++ b/modules/gui/macosx/library/VLCLibraryWindow.m
@@ -45,11 +45,11 @@
 #import "windows/video/VLCVoutView.h"
 #import "windows/video/VLCVideoOutputProvider.h"
 
-static const float f_min_window_width = 604.;
-static const float f_min_window_height = 307.;
-static const float f_playlist_row_height = 72.;
-static const float f_library_small_row_height = 24.;
-static const float f_library_large_row_height = 50.;
+const CGFloat VLCLibraryWindowMinimalWidth = 604.;
+const CGFloat VLCLibraryWindowMinimalHeight = 307.;
+const CGFloat VLCLibraryWindowPlaylistRowHeight = 72.;
+const CGFloat VLCLibraryWindowSmallRowHeight = 24.;
+const CGFloat VLCLibraryWindowLargeRowHeight = 50.;
 
 @interface VLCLibraryWindow ()
 {
@@ -136,7 +136,7 @@ static const float f_library_large_row_height = 50.;
 
     _playlistTableView.dataSource = _playlistDataSource;
     _playlistTableView.delegate = _playlistDataSource;
-    _playlistTableView.rowHeight = f_playlist_row_height;
+    _playlistTableView.rowHeight = VLCLibraryWindowPlaylistRowHeight;
     [_playlistTableView reloadData];
 
     _libraryVideoDataSource = [[VLCLibraryVideoDataSource alloc] init];
@@ -161,10 +161,10 @@ static const float f_library_large_row_height = 50.;
     _libraryAudioDataSource.groupSelectionTableView = _audioGroupSelectionTableView;
     _audioCategorySelectionTableView.dataSource = _libraryAudioDataSource;
     _audioCategorySelectionTableView.delegate = _libraryAudioDataSource;
-    _audioCategorySelectionTableView.rowHeight = f_library_small_row_height;
+    _audioCategorySelectionTableView.rowHeight = VLCLibraryWindowSmallRowHeight;
     _audioCollectionSelectionTableView.dataSource = _libraryAudioDataSource;
     _audioCollectionSelectionTableView.delegate = _libraryAudioDataSource;
-    _audioCollectionSelectionTableView.rowHeight = f_library_large_row_height;
+    _audioCollectionSelectionTableView.rowHeight = VLCLibraryWindowLargeRowHeight;
     _libraryAudioGroupDataSource = [[VLCLibraryGroupDataSource alloc] init];
     _libraryAudioDataSource.groupDataSource = _libraryAudioGroupDataSource;
     _audioGroupSelectionTableView.dataSource = _libraryAudioGroupDataSource;
@@ -378,7 +378,7 @@ static const float f_library_large_row_height = 50.;
         && _windowFrameBeforePlayback.size.height > 0) {
 
         // only resize back to minimum view of this is still desired final state
-        CGFloat f_threshold_height = f_min_video_height + [self.controlsBar height];
+        CGFloat f_threshold_height = VLCVideoWindowCommonMinimalHeight + [self.controlsBar height];
         if (_windowFrameBeforePlayback.size.height > f_threshold_height) {
             if ([[VLCMain sharedInstance] isTerminating]) {
                 [self setFrame:_windowFrameBeforePlayback display:YES];
@@ -442,7 +442,7 @@ static const float f_library_large_row_height = 50.;
     [window setRestorable:NO];
     [window setExcludedFromWindowsMenu:YES];
     [window setAcceptsMouseMovedEvents:YES];
-    [window setContentMinSize:NSMakeSize(f_min_window_width, f_min_window_height)];
+    [window setContentMinSize:NSMakeSize(VLCLibraryWindowMinimalWidth, VLCLibraryWindowMinimalHeight)];
 }
 
 @end
diff --git a/modules/gui/macosx/playlist/VLCPlaylistTableCellView.m b/modules/gui/macosx/playlist/VLCPlaylistTableCellView.m
index 1f0bec1b3b..3c980c0371 100644
--- a/modules/gui/macosx/playlist/VLCPlaylistTableCellView.m
+++ b/modules/gui/macosx/playlist/VLCPlaylistTableCellView.m
@@ -21,20 +21,14 @@
  *****************************************************************************/
 
 #import "VLCPlaylistTableCellView.h"
-
-static const float fontSizeForMediaTitle = 13.;
+#import "extensions/NSFont+VLCAdditions.h"
 
 @implementation VLCPlaylistTableCellView
 
 - (void)setRepresentsCurrentPlaylistItem:(BOOL)representsCurrentPlaylistItem
 {
     _representsCurrentPlaylistItem = representsCurrentPlaylistItem;
-    NSFont *displayedFont;
-    if (_representsCurrentPlaylistItem) {
-        displayedFont = [NSFont boldSystemFontOfSize:fontSizeForMediaTitle];
-    } else {
-        displayedFont = [NSFont systemFontOfSize:fontSizeForMediaTitle];
-    }
+    NSFont *displayedFont = _representsCurrentPlaylistItem ? [NSFont VLCplaylistSelectedItemLabelFont] : [NSFont VLCplaylistLabelFont];
     self.mediaTitleTextField.font = displayedFont;
     self.secondaryMediaTitleTextField.font = displayedFont;
 }
diff --git a/modules/gui/macosx/windows/video/VLCDetachedVideoWindow.m b/modules/gui/macosx/windows/video/VLCDetachedVideoWindow.m
index 4aa053469c..87bbbbe18b 100644
--- a/modules/gui/macosx/windows/video/VLCDetachedVideoWindow.m
+++ b/modules/gui/macosx/windows/video/VLCDetachedVideoWindow.m
@@ -33,7 +33,7 @@
     [super awakeFromNib];
     [self setAcceptsMouseMovedEvents: YES];
 
-    [self setContentMinSize: NSMakeSize(363., f_min_video_height + [[self controlsBar] height])];
+    [self setContentMinSize: NSMakeSize(363., VLCVideoWindowCommonMinimalHeight + [[self controlsBar] height])];
 }
 
 @end
diff --git a/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m b/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m
index d239d00a01..b9acdc0cb8 100644
--- a/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m
+++ b/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m
@@ -280,7 +280,7 @@ int WindowOpen(vout_window_t *p_wnd)
                 [newVideoWindow setFrameAutosaveName:@"extra-videowindow"];
             }
 
-            [newVideoWindow setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
+            [newVideoWindow setContentMinSize: NSMakeSize(VLCVideoWindowCommonMinimalHeight, VLCVideoWindowCommonMinimalHeight)];
         }
 
         isEmbedded = NO;
diff --git a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.h b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.h
index 83e05966f1..89376c007c 100644
--- a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.h
+++ b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.h
@@ -32,7 +32,7 @@ extern NSString *VLCVideoWindowDidEnterFullscreen;
 
 @class VLCControlsBarCommon;
 
-static const float f_min_video_height = 70.0;
+extern const CGFloat VLCVideoWindowCommonMinimalHeight;
 
 /*****************************************************************************
  * VLCVideoWindowCommon
diff --git a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m
index 130b8f93d0..9851a2f230 100644
--- a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m
+++ b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m
@@ -35,6 +35,7 @@
 #import "playlist/VLCPlayerController.h"
 #import "library/VLCLibraryWindow.h"
 
+const CGFloat VLCVideoWindowCommonMinimalHeight = 70.;
 NSString *VLCVideoWindowShouldShowFullscreenController = @"VLCVideoWindowShouldShowFullscreenController";
 NSString *VLCVideoWindowDidEnterFullscreen = @"VLCVideoWindowDidEnterFullscreen";
 
@@ -334,8 +335,8 @@ NSString *VLCVideoWindowDidEnterFullscreen = @"VLCVideoWindowDidEnterFullscreen"
     CGFloat f_height = size.height;
     if (f_width < windowMinSize.width)
         f_width = windowMinSize.width;
-    if (f_height < f_min_video_height)
-        f_height = f_min_video_height;
+    if (f_height < VLCVideoWindowCommonMinimalHeight)
+        f_height = VLCVideoWindowCommonMinimalHeight;
 
     /* Calculate the window's new size */
     NSRect new_frame;



More information about the vlc-commits mailing list