[vlc-devel] [PATCH] macosx: Add VLCHexNumberFormatter

Marvin Scholz epirat07 at gmail.com
Tue Jul 18 20:30:02 CEST 2017


Adds a number formatter used for hex color text fields in the video
effects panel.
---
 .../package/macosx/VLC.xcodeproj/project.pbxproj   |  6 +++
 modules/gui/macosx/Makefile.am                     |  3 +-
 modules/gui/macosx/VLCHexNumberFormatter.h         | 28 ++++++++++++
 modules/gui/macosx/VLCHexNumberFormatter.m         | 50 ++++++++++++++++++++++
 4 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 modules/gui/macosx/VLCHexNumberFormatter.h
 create mode 100644 modules/gui/macosx/VLCHexNumberFormatter.m

diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index ce59f81adf..15b1733d21 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -76,6 +76,7 @@
 		6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50A61E7AB52C004479B5 /* NSScreen+VLCAdditions.m */; };
 		6B5978C51EFBFBF2003D9C80 /* VLCHUDPopUpButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B5978C41EFBFBF2003D9C80 /* VLCHUDPopUpButtonCell.m */; };
 		6B6FFF701EF9EC350001CEB1 /* CompatibilityFixes.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B6FFF6F1EF9EC350001CEB1 /* CompatibilityFixes.m */; };
+		6B7F1FDF1F07DA920002BDD8 /* VLCHexNumberFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B7F1FDE1F07DA920002BDD8 /* VLCHexNumberFormatter.m */; };
 		6B8166291EBFC34300C26F1B /* VLCDefaultValueSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B6A499B1DFD9B23009128AC /* VLCDefaultValueSlider.m */; };
 		6B81662A1EBFC34300C26F1B /* VLCDefaultValueSliderCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B6A499D1DFD9B23009128AC /* VLCDefaultValueSliderCell.m */; };
 		6B81662B1EBFC35D00C26F1B /* VLCVoutWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C2583F161B593D00185AAD /* VLCVoutWindowController.m */; };
@@ -138,6 +139,8 @@
 		6B6A499C1DFD9B23009128AC /* VLCDefaultValueSliderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCDefaultValueSliderCell.h; sourceTree = "<group>"; };
 		6B6A499D1DFD9B23009128AC /* VLCDefaultValueSliderCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCDefaultValueSliderCell.m; sourceTree = "<group>"; };
 		6B6FFF6F1EF9EC350001CEB1 /* CompatibilityFixes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CompatibilityFixes.m; sourceTree = "<group>"; };
+		6B7F1FDD1F07DA920002BDD8 /* VLCHexNumberFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCHexNumberFormatter.h; sourceTree = "<group>"; };
+		6B7F1FDE1F07DA920002BDD8 /* VLCHexNumberFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCHexNumberFormatter.m; sourceTree = "<group>"; };
 		6B8223FE1E4D2A8F00833BE1 /* About.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = About.xib; sourceTree = "<group>"; };
 		6B8223FF1E4D2A9000833BE1 /* AddonManager.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AddonManager.xib; sourceTree = "<group>"; };
 		6B8224001E4D2A9000833BE1 /* AudioEffects.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AudioEffects.xib; sourceTree = "<group>"; };
@@ -870,6 +873,8 @@
 		08FB77AFFE84173DC02AAC07 /* Classes */ = {
 			isa = PBXGroup;
 			children = (
+				6B7F1FDD1F07DA920002BDD8 /* VLCHexNumberFormatter.h */,
+				6B7F1FDE1F07DA920002BDD8 /* VLCHexNumberFormatter.m */,
 				6B3BE42A1E6217CB008D098A /* VLCImageButton.h */,
 				6B3BE42B1E6217CB008D098A /* VLCImageButton.m */,
 				6BF5C5051EFE7E58008A9C12 /* VLCTintedImageButtonCell.h */,
@@ -1946,6 +1951,7 @@
 				1C3113E31E508C6900D4DD76 /* VLCPlaylist.m in Sources */,
 				1C3113E51E508C6900D4DD76 /* VLCPlaylistInfo.m in Sources */,
 				1C3113E71E508C6900D4DD76 /* VLCPlaylistView.m in Sources */,
+				6B7F1FDF1F07DA920002BDD8 /* VLCHexNumberFormatter.m in Sources */,
 				1C3113E91E508C6900D4DD76 /* VLCScrollingClipView.m in Sources */,
 				1C3113EB1E508C6900D4DD76 /* VLCStatusBarIcon.m in Sources */,
 				6BBB05E31EF08181003A1019 /* VLCHUDSegmentedCell.m in Sources */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index 7a54fc74d0..fd4898f33f 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -97,7 +97,8 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/VLCDefaultValueSliderCell.h gui/macosx/VLCDefaultValueSliderCell.m \
 	gui/macosx/VLCImageButton.h gui/macosx/VLCImageButton.m \
 	gui/macosx/VLCTintedImageButtonCell.h gui/macosx/VLCTintedImageButtonCell.m \
-	gui/macosx/VLCTimeField.h gui/macosx/VLCTimeField.m
+	gui/macosx/VLCTimeField.h gui/macosx/VLCTimeField.m \
+	gui/macosx/VLCHexNumberFormatter.h gui/macosx/VLCHexNumberFormatter.m
 
 # User interface compilation
 
diff --git a/modules/gui/macosx/VLCHexNumberFormatter.h b/modules/gui/macosx/VLCHexNumberFormatter.h
new file mode 100644
index 0000000000..77605349ca
--- /dev/null
+++ b/modules/gui/macosx/VLCHexNumberFormatter.h
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * VLCHexNumberFormatter.h
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Marvin Scholz <epirat07 at gmail dot com>
+ *
+ * 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 <Foundation/Foundation.h>
+
+ at interface VLCHexNumberFormatter : NSFormatter
+
+ at end
diff --git a/modules/gui/macosx/VLCHexNumberFormatter.m b/modules/gui/macosx/VLCHexNumberFormatter.m
new file mode 100644
index 0000000000..c99887b7ba
--- /dev/null
+++ b/modules/gui/macosx/VLCHexNumberFormatter.m
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * VLCHexNumberFormatter.m
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Marvin Scholz <epirat07 at gmail dot com>
+ *
+ * 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 "VLCHexNumberFormatter.h"
+
+ at implementation VLCHexNumberFormatter
+
+- (NSString *)stringForObjectValue:(id)obj
+{
+    if (![obj isKindOfClass:[NSNumber class]]) {
+        return nil;
+    }
+
+    NSString *string = [NSString stringWithFormat:@"%06" PRIX32, [obj intValue]];
+    return string;
+}
+
+- (BOOL)getObjectValue:(out id  _Nullable __autoreleasing *)obj
+             forString:(NSString *)string
+      errorDescription:(out NSString *__autoreleasing  _Nullable *)error
+{
+    unsigned result = 0;
+    NSScanner *scanner = [NSScanner scannerWithString:string];
+    BOOL success = [scanner scanHexInt:&result];
+
+    *obj = (success) ? [NSNumber numberWithInt:result] : nil;
+    return success;
+}
+
+ at end
-- 
2.11.0 (Apple Git-81)



More information about the vlc-devel mailing list