From 536aaa14cb97b8f67551c11b554355643dd96927 Mon Sep 17 00:00:00 2001 From: Cherif Yaya Date: Sun, 13 Jan 2013 22:17:55 +0100 Subject: [PATCH 1/7] Separate core files from sample app supporting files for more clarity. --- STOverlay.xcodeproj/project.pbxproj | 90 ++++++++++--------- {STOverlay => SampleApp}/AppDelegate.h | 0 {STOverlay => SampleApp}/AppDelegate.m | 0 {STOverlay => SampleApp}/STOverlay-Info.plist | 0 {STOverlay => SampleApp}/STOverlay-Prefix.pch | 0 {STOverlay => SampleApp}/en.lproj/Credits.rtf | 0 .../en.lproj/InfoPlist.strings | 0 .../en.lproj/MainMenu.xib | 0 {STOverlay => SampleApp}/main.m | 0 9 files changed, 50 insertions(+), 40 deletions(-) rename {STOverlay => SampleApp}/AppDelegate.h (100%) rename {STOverlay => SampleApp}/AppDelegate.m (100%) rename {STOverlay => SampleApp}/STOverlay-Info.plist (100%) rename {STOverlay => SampleApp}/STOverlay-Prefix.pch (100%) rename {STOverlay => SampleApp}/en.lproj/Credits.rtf (100%) rename {STOverlay => SampleApp}/en.lproj/InfoPlist.strings (100%) rename {STOverlay => SampleApp}/en.lproj/MainMenu.xib (100%) rename {STOverlay => SampleApp}/main.m (100%) diff --git a/STOverlay.xcodeproj/project.pbxproj b/STOverlay.xcodeproj/project.pbxproj index d59cf65..b6ba4e0 100644 --- a/STOverlay.xcodeproj/project.pbxproj +++ b/STOverlay.xcodeproj/project.pbxproj @@ -12,11 +12,12 @@ 2441F57514DA954000F3D64D /* STOverlayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2441F57414DA954000F3D64D /* STOverlayController.m */; }; 2441F58F14DAEFCF00F3D64D /* README.markdown in Resources */ = {isa = PBXBuildFile; fileRef = 2441F58E14DAEFCF00F3D64D /* README.markdown */; }; 249860FF14DA3AAB004D1710 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 249860FE14DA3AAB004D1710 /* Cocoa.framework */; }; - 2498610914DA3AAB004D1710 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2498610714DA3AAB004D1710 /* InfoPlist.strings */; }; - 2498610B14DA3AAC004D1710 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2498610A14DA3AAB004D1710 /* main.m */; }; - 2498610F14DA3AAC004D1710 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2498610D14DA3AAC004D1710 /* Credits.rtf */; }; - 2498611214DA3AAC004D1710 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2498611114DA3AAC004D1710 /* AppDelegate.m */; }; - 2498611514DA3AAC004D1710 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2498611314DA3AAC004D1710 /* MainMenu.xib */; }; + 7D932BC716A35AE300C45439 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D932BBD16A35AE300C45439 /* AppDelegate.m */; }; + 7D932BC816A35AE300C45439 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 7D932BBE16A35AE300C45439 /* Credits.rtf */; }; + 7D932BC916A35AE300C45439 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7D932BC016A35AE300C45439 /* InfoPlist.strings */; }; + 7D932BCA16A35AE300C45439 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7D932BC216A35AE300C45439 /* MainMenu.xib */; }; + 7D932BCB16A35AE300C45439 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D932BC416A35AE300C45439 /* main.m */; }; + 7D932BCC16A35AE300C45439 /* STOverlay-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7D932BC516A35AE300C45439 /* STOverlay-Info.plist */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,14 +33,14 @@ 2498610114DA3AAB004D1710 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; 2498610214DA3AAB004D1710 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; 2498610314DA3AAB004D1710 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - 2498610614DA3AAB004D1710 /* STOverlay-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "STOverlay-Info.plist"; sourceTree = ""; }; - 2498610814DA3AAB004D1710 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; - 2498610A14DA3AAB004D1710 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - 2498610C14DA3AAC004D1710 /* STOverlay-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "STOverlay-Prefix.pch"; sourceTree = ""; }; - 2498610E14DA3AAC004D1710 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = ""; }; - 2498611014DA3AAC004D1710 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 2498611114DA3AAC004D1710 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 2498611414DA3AAC004D1710 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = ""; }; + 7D932BBC16A35AE300C45439 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 7D932BBD16A35AE300C45439 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 7D932BBF16A35AE300C45439 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = ""; }; + 7D932BC116A35AE300C45439 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 7D932BC316A35AE300C45439 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = ""; }; + 7D932BC416A35AE300C45439 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 7D932BC516A35AE300C45439 /* STOverlay-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "STOverlay-Info.plist"; sourceTree = ""; }; + 7D932BC616A35AE300C45439 /* STOverlay-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "STOverlay-Prefix.pch"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -58,6 +59,7 @@ isa = PBXGroup; children = ( 2441F58E14DAEFCF00F3D64D /* README.markdown */, + 7D932BBB16A35AE300C45439 /* SampleApp */, 2498610414DA3AAB004D1710 /* STOverlay */, 249860FD14DA3AAB004D1710 /* Frameworks */, 249860FB14DA3AAB004D1710 /* Products */, @@ -94,28 +96,35 @@ 2498610414DA3AAB004D1710 /* STOverlay */ = { isa = PBXGroup; children = ( - 2498611014DA3AAC004D1710 /* AppDelegate.h */, - 2498611114DA3AAC004D1710 /* AppDelegate.m */, 2441F56C14DA822400F3D64D /* STOverlayWindow.h */, 2441F56D14DA822400F3D64D /* STOverlayWindow.m */, 2441F57014DA83E500F3D64D /* STOverlayView.h */, 2441F57114DA83E500F3D64D /* STOverlayView.m */, 2441F57314DA954000F3D64D /* STOverlayController.h */, 2441F57414DA954000F3D64D /* STOverlayController.m */, - 2498611314DA3AAC004D1710 /* MainMenu.xib */, - 2498610514DA3AAB004D1710 /* Supporting Files */, ); path = STOverlay; sourceTree = ""; }; - 2498610514DA3AAB004D1710 /* Supporting Files */ = { + 7D932BBB16A35AE300C45439 /* SampleApp */ = { isa = PBXGroup; children = ( - 2498610614DA3AAB004D1710 /* STOverlay-Info.plist */, - 2498610714DA3AAB004D1710 /* InfoPlist.strings */, - 2498610A14DA3AAB004D1710 /* main.m */, - 2498610C14DA3AAC004D1710 /* STOverlay-Prefix.pch */, - 2498610D14DA3AAC004D1710 /* Credits.rtf */, + 7D932BCD16A35AFE00C45439 /* Supporting Files */, + 7D932BBC16A35AE300C45439 /* AppDelegate.h */, + 7D932BBD16A35AE300C45439 /* AppDelegate.m */, + 7D932BC216A35AE300C45439 /* MainMenu.xib */, + ); + path = SampleApp; + sourceTree = ""; + }; + 7D932BCD16A35AFE00C45439 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 7D932BBE16A35AE300C45439 /* Credits.rtf */, + 7D932BC016A35AE300C45439 /* InfoPlist.strings */, + 7D932BC416A35AE300C45439 /* main.m */, + 7D932BC516A35AE300C45439 /* STOverlay-Info.plist */, + 7D932BC616A35AE300C45439 /* STOverlay-Prefix.pch */, ); name = "Supporting Files"; sourceTree = ""; @@ -170,10 +179,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2498610914DA3AAB004D1710 /* InfoPlist.strings in Resources */, - 2498610F14DA3AAC004D1710 /* Credits.rtf in Resources */, - 2498611514DA3AAC004D1710 /* MainMenu.xib in Resources */, 2441F58F14DAEFCF00F3D64D /* README.markdown in Resources */, + 7D932BC816A35AE300C45439 /* Credits.rtf in Resources */, + 7D932BC916A35AE300C45439 /* InfoPlist.strings in Resources */, + 7D932BCA16A35AE300C45439 /* MainMenu.xib in Resources */, + 7D932BCC16A35AE300C45439 /* STOverlay-Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -184,37 +194,37 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2498610B14DA3AAC004D1710 /* main.m in Sources */, - 2498611214DA3AAC004D1710 /* AppDelegate.m in Sources */, 2441F56E14DA822400F3D64D /* STOverlayWindow.m in Sources */, 2441F57214DA83E500F3D64D /* STOverlayView.m in Sources */, 2441F57514DA954000F3D64D /* STOverlayController.m in Sources */, + 7D932BC716A35AE300C45439 /* AppDelegate.m in Sources */, + 7D932BCB16A35AE300C45439 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 2498610714DA3AAB004D1710 /* InfoPlist.strings */ = { + 7D932BBE16A35AE300C45439 /* Credits.rtf */ = { isa = PBXVariantGroup; children = ( - 2498610814DA3AAB004D1710 /* en */, + 7D932BBF16A35AE300C45439 /* en */, ); - name = InfoPlist.strings; + name = Credits.rtf; sourceTree = ""; }; - 2498610D14DA3AAC004D1710 /* Credits.rtf */ = { + 7D932BC016A35AE300C45439 /* InfoPlist.strings */ = { isa = PBXVariantGroup; children = ( - 2498610E14DA3AAC004D1710 /* en */, + 7D932BC116A35AE300C45439 /* en */, ); - name = Credits.rtf; + name = InfoPlist.strings; sourceTree = ""; }; - 2498611314DA3AAC004D1710 /* MainMenu.xib */ = { + 7D932BC216A35AE300C45439 /* MainMenu.xib */ = { isa = PBXVariantGroup; children = ( - 2498611414DA3AAC004D1710 /* en */, + 7D932BC316A35AE300C45439 /* en */, ); name = MainMenu.xib; sourceTree = ""; @@ -272,8 +282,8 @@ buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "STOverlay/STOverlay-Prefix.pch"; - INFOPLIST_FILE = "STOverlay/STOverlay-Info.plist"; + GCC_PREFIX_HEADER = "SampleApp/STOverlay-Prefix.pch"; + INFOPLIST_FILE = "$(SRCROOT)/SampleApp/STOverlay-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -284,8 +294,8 @@ buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "STOverlay/STOverlay-Prefix.pch"; - INFOPLIST_FILE = "STOverlay/STOverlay-Info.plist"; + GCC_PREFIX_HEADER = "SampleApp/STOverlay-Prefix.pch"; + INFOPLIST_FILE = "$(SRCROOT)/SampleApp/STOverlay-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/STOverlay/AppDelegate.h b/SampleApp/AppDelegate.h similarity index 100% rename from STOverlay/AppDelegate.h rename to SampleApp/AppDelegate.h diff --git a/STOverlay/AppDelegate.m b/SampleApp/AppDelegate.m similarity index 100% rename from STOverlay/AppDelegate.m rename to SampleApp/AppDelegate.m diff --git a/STOverlay/STOverlay-Info.plist b/SampleApp/STOverlay-Info.plist similarity index 100% rename from STOverlay/STOverlay-Info.plist rename to SampleApp/STOverlay-Info.plist diff --git a/STOverlay/STOverlay-Prefix.pch b/SampleApp/STOverlay-Prefix.pch similarity index 100% rename from STOverlay/STOverlay-Prefix.pch rename to SampleApp/STOverlay-Prefix.pch diff --git a/STOverlay/en.lproj/Credits.rtf b/SampleApp/en.lproj/Credits.rtf similarity index 100% rename from STOverlay/en.lproj/Credits.rtf rename to SampleApp/en.lproj/Credits.rtf diff --git a/STOverlay/en.lproj/InfoPlist.strings b/SampleApp/en.lproj/InfoPlist.strings similarity index 100% rename from STOverlay/en.lproj/InfoPlist.strings rename to SampleApp/en.lproj/InfoPlist.strings diff --git a/STOverlay/en.lproj/MainMenu.xib b/SampleApp/en.lproj/MainMenu.xib similarity index 100% rename from STOverlay/en.lproj/MainMenu.xib rename to SampleApp/en.lproj/MainMenu.xib diff --git a/STOverlay/main.m b/SampleApp/main.m similarity index 100% rename from STOverlay/main.m rename to SampleApp/main.m From 36e310bd86d14d50756d14a834cfef71f0155bbd Mon Sep 17 00:00:00 2001 From: Cherif Yaya Date: Sun, 13 Jan 2013 22:37:49 +0100 Subject: [PATCH 2/7] Add support for custom font and color for the label. --- STOverlay/STOverlayController.h | 3 +++ STOverlay/STOverlayController.m | 17 +++++++++++++++++ STOverlay/STOverlayView.h | 2 ++ STOverlay/STOverlayView.m | 5 +++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/STOverlay/STOverlayController.h b/STOverlay/STOverlayController.h index f5c100d..b1c0228 100644 --- a/STOverlay/STOverlayController.h +++ b/STOverlay/STOverlayController.h @@ -28,6 +28,9 @@ @interface STOverlayController : NSObject +@property (strong, nonatomic) NSFont *labelFont; +@property (strong, nonatomic) NSColor *labelColor; + - (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radius:(CGFloat)radius diff --git a/STOverlay/STOverlayController.m b/STOverlay/STOverlayController.m index a0319c7..759b9a9 100644 --- a/STOverlay/STOverlayController.m +++ b/STOverlay/STOverlayController.m @@ -39,6 +39,19 @@ @implementation STOverlayController { __weak NSView *_targetView; } +@synthesize labelColor = _labelColor, labelFont = _labelFont; + +- (id)init { + self = [super init]; + if (self) { + //init label font and color properties + self.labelFont = [NSFont systemFontOfSize:48.0]; + self.labelColor = [NSColor redColor]; + } + + return self; +} + - (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radius:(CGFloat)radius { _targetView = targetView; [targetView addObserver:self @@ -50,8 +63,12 @@ - (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radi _overlayWindow = [[STOverlayWindow alloc] initWithContentRect:overlayRect]; [_overlayWindow setReleasedWhenClosed:NO]; STOverlayView *overlayView = [_overlayWindow overlayView]; + //configure label overlayView.label = label; + overlayView.labelColor = self.labelColor; + overlayView.labelFont = self.labelFont; overlayView.bezelRadius = radius; + [parentWindow addChildWindow:_overlayWindow ordered:NSWindowAbove]; } diff --git a/STOverlay/STOverlayView.h b/STOverlay/STOverlayView.h index 85b25d4..4367ed7 100644 --- a/STOverlay/STOverlayView.h +++ b/STOverlay/STOverlayView.h @@ -32,5 +32,7 @@ extern CGFloat STOverlayViewStandardRadius; @property CGFloat bezelRadius; @property (copy) NSString *label; +@property (copy) NSFont *labelFont; +@property (copy) NSColor *labelColor; @end diff --git a/STOverlay/STOverlayView.m b/STOverlay/STOverlayView.m index ca122ec..2d999c5 100644 --- a/STOverlay/STOverlayView.m +++ b/STOverlay/STOverlayView.m @@ -39,6 +39,7 @@ @implementation STOverlayView @synthesize bezelRadius = _bezelRadius; @synthesize label = _label; +@synthesize labelFont = _labelFont, labelColor = _labelColor; - (id)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; @@ -65,8 +66,8 @@ - (void)drawBezel { - (void)drawLabel { NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: - [NSFont systemFontOfSize:48.0], NSFontAttributeName, - [NSColor whiteColor], NSForegroundColorAttributeName, + self.labelFont, NSFontAttributeName, + self.labelColor, NSForegroundColorAttributeName, nil]; NSAttributedString *labelToDraw = [[NSAttributedString alloc] initWithString:self.label attributes:attributes]; From fb30e94fbf2574b02c30d7c0727815010049b829 Mon Sep 17 00:00:00 2001 From: Cherif Yaya Date: Mon, 14 Jan 2013 00:38:19 +0100 Subject: [PATCH 3/7] Add close button for dismissing the overlay. --- STOverlay.xcodeproj/project.pbxproj | 16 +++++++ STOverlay/Images/close.png | Bin 0 -> 1015 bytes STOverlay/Images/close@2x.png | Bin 0 -> 829 bytes STOverlay/STOverlayController.m | 68 ++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 STOverlay/Images/close.png create mode 100644 STOverlay/Images/close@2x.png diff --git a/STOverlay.xcodeproj/project.pbxproj b/STOverlay.xcodeproj/project.pbxproj index b6ba4e0..5a0b0e0 100644 --- a/STOverlay.xcodeproj/project.pbxproj +++ b/STOverlay.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ 7D932BCA16A35AE300C45439 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7D932BC216A35AE300C45439 /* MainMenu.xib */; }; 7D932BCB16A35AE300C45439 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D932BC416A35AE300C45439 /* main.m */; }; 7D932BCC16A35AE300C45439 /* STOverlay-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7D932BC516A35AE300C45439 /* STOverlay-Info.plist */; }; + 7D932BD116A3646400C45439 /* close.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D932BCF16A3646400C45439 /* close.png */; }; + 7D932BD216A3646400C45439 /* close@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D932BD016A3646400C45439 /* close@2x.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -41,6 +43,8 @@ 7D932BC416A35AE300C45439 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 7D932BC516A35AE300C45439 /* STOverlay-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "STOverlay-Info.plist"; sourceTree = ""; }; 7D932BC616A35AE300C45439 /* STOverlay-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "STOverlay-Prefix.pch"; sourceTree = ""; }; + 7D932BCF16A3646400C45439 /* close.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = close.png; sourceTree = ""; }; + 7D932BD016A3646400C45439 /* close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close@2x.png"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -96,6 +100,7 @@ 2498610414DA3AAB004D1710 /* STOverlay */ = { isa = PBXGroup; children = ( + 7D932BCE16A3646400C45439 /* Images */, 2441F56C14DA822400F3D64D /* STOverlayWindow.h */, 2441F56D14DA822400F3D64D /* STOverlayWindow.m */, 2441F57014DA83E500F3D64D /* STOverlayView.h */, @@ -129,6 +134,15 @@ name = "Supporting Files"; sourceTree = ""; }; + 7D932BCE16A3646400C45439 /* Images */ = { + isa = PBXGroup; + children = ( + 7D932BCF16A3646400C45439 /* close.png */, + 7D932BD016A3646400C45439 /* close@2x.png */, + ); + path = Images; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -184,6 +198,8 @@ 7D932BC916A35AE300C45439 /* InfoPlist.strings in Resources */, 7D932BCA16A35AE300C45439 /* MainMenu.xib in Resources */, 7D932BCC16A35AE300C45439 /* STOverlay-Info.plist in Resources */, + 7D932BD116A3646400C45439 /* close.png in Resources */, + 7D932BD216A3646400C45439 /* close@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/STOverlay/Images/close.png b/STOverlay/Images/close.png new file mode 100644 index 0000000000000000000000000000000000000000..70b4847ef959574c17004da92d920de470b9e71d GIT binary patch literal 1015 zcmVKLZ*U+R`sCEkzKl)gj5&q@hY_5?)@_euSf22N!q0z{yc?Q2YY_Kym8e z5Fvwu2%hQO!{u_psMvL#(bD64NQRTZj^-}DnS22ry9f-;mW=gZvQj}U-ZdMsK&I8^7~DvX`q=ilSd2k_rKGbtoS z@|kHAVtl+(WPvgw7Lt4{n3XiiXN)3+SdbVNv%tc}W>)esu|cEBgptHFX)Gp%m5k41 z!LYe+-5$^TKGU4l`<`>}|9|ee=l;)A(b(81$EIOEW@C8peMb+v@xI*Vsxq;O*oO63 zh!Lm=v4KF+h3ja=w=9sP1o(D5#(6Bm$Oyc+Z!}inGCD&dxdg*-1y@mP@HQ7WajIO2 zk^tOb=yoh5c_ixuhf?5AacK~s7x5+7{_*bUxDN~9Pe9c+Zglif8GdV2`pA+=ufX5d)Cz6nXGA&%R-ULs=;ymyI z?%{4u3m5GN9wm5zmr-B$p4kA~y8@M0K^)Ku|2gXJje93s_u`LM0W?ba!!#?~?%XJU7pg($v z)q{}h82l|Z#B(}5(H>weo)2Nzv||lk<;~z@+$TtOw=>Px#8FWQhbW?9;ba!ELWdK2BZ(?O2No`?g zWm08fWO;GPWjp`?0=h{=K~#9!B-Jus1b?9d)N;aAd}>sODe5!I-Op@ zWrWQpD`@NaeEw??1OV^_Tqf9ZkFFbNOK1z-fYA1&1aPKH1kRNW5~+a5OH=|l<1-=P zHmS6Jszp*y@Skyj^T@HehE@QH?;->M_y?Tz;>1a&1QK6a1Q5Iqw(%Qf${I-A_1!!h zICw4NEXzhs(|ohtRF2MX4Zf8ECiC8l0CpG?2ug`dR|%MINCfb~(lsmKo7dV$C1#kY ztHw0mPr%4Ht^ptQ4-BxH37)F!yo=3df$~Tlvo~NX3=$!_CRha=62RFneFkKZ;OMIQ zEKqP(Sq~Du;E9sAR!|oAaRt#WlY|pIjPXEN^@}|M(CO0Q`w}Fiz$a}nsk(nqm-he? zlHhk4NxP9rAouh`Dv4PH@UNItL&5LB0Okf{D0nRk)mbEhszsM2B7xswR>t;_Rq}?A zV1nPdkV@pli-Z7pQaK$$;(`GFR%&-AO`xEhDqzspLnGjojRdOLe*`GI{}`!MfW%UD z4wp^_UWmlTB(RDBUT;kW3cx;DDaQVmS{{@_Rjkv677@S~!ln40`{>wJMrVE8y^aJv z28o3&jn)ytOOvQ=1ZIqE+O7Fk{wGBsCb!;VeS>a${Mqw7B zYiTaL%Hn@p0+`o<1*%FPU7POx^w Date: Tue, 15 Jan 2013 06:06:57 +0100 Subject: [PATCH 4/7] Improve close button display and add flag to enable/disable the button. --- STOverlay/STOverlayController.h | 2 + STOverlay/STOverlayController.m | 93 ++++++++++++++------------------- 2 files changed, 42 insertions(+), 53 deletions(-) diff --git a/STOverlay/STOverlayController.h b/STOverlay/STOverlayController.h index b1c0228..f09d93d 100644 --- a/STOverlay/STOverlayController.h +++ b/STOverlay/STOverlayController.h @@ -31,6 +31,8 @@ @property (strong, nonatomic) NSFont *labelFont; @property (strong, nonatomic) NSColor *labelColor; +@property (nonatomic) BOOL hasCloseButton; + - (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radius:(CGFloat)radius diff --git a/STOverlay/STOverlayController.m b/STOverlay/STOverlayController.m index 8bb3ae0..f7ae31e 100644 --- a/STOverlay/STOverlayController.m +++ b/STOverlay/STOverlayController.m @@ -48,28 +48,13 @@ - (id)init { //init label font and color properties self.labelFont = [NSFont systemFontOfSize:48.0]; self.labelColor = [NSColor redColor]; + self.hasCloseButton = YES; } return self; } -- (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radius:(CGFloat)radius { - _targetView = targetView; - [targetView addObserver:self - forKeyPath:@"frame" - options:NSKeyValueObservingOptionNew - context:NULL]; - NSWindow *parentWindow = _targetView.window; - NSRect overlayRect = [parentWindow convertRectToScreen:[_targetView.superview convertRectToBacking:_targetView.frame]]; - _overlayWindow = [[STOverlayWindow alloc] initWithContentRect:overlayRect]; - [_overlayWindow setReleasedWhenClosed:NO]; - STOverlayView *overlayView = [_overlayWindow overlayView]; - //configure label - overlayView.label = label; - overlayView.labelColor = self.labelColor; - overlayView.labelFont = self.labelFont; - overlayView.bezelRadius = radius; - +- (void)createCloseButtonInView:(NSView *)overlayView { if (closeButton) { closeButton = nil; } @@ -80,50 +65,57 @@ - (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radi closeButton.imagePosition = NSImageOnly; closeButton.image = [NSImage imageNamed:@"close"]; closeButton.bezelStyle = NSShadowlessSquareBezelStyle; - [closeButton setBordered:YES]; + [closeButton setBordered:NO]; closeButton.showsBorderOnlyWhileMouseInside = YES; + [[closeButton cell] setHighlightsBy:NSChangeGrayCellMask]; + + [closeButton setButtonType:NSMomentaryChangeButton]; + closeButton.action = @selector(closeButtonPressed:); closeButton.target = self; - //[closeButton setAutoresizingMask:NSViewMinXMargin|NSViewMaxYMargin]; - [overlayView addSubview:closeButton]; + closeButton.translatesAutoresizingMaskIntoConstraints = NO; - /* + [overlayView addSubview:closeButton]; + //make button sits in top right corner NSMutableArray *constraints = [NSMutableArray array]; [constraints addObjectsFromArray:[NSLayoutConstraint - constraintsWithVisualFormat:@"[closeButton(24)]" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(closeButton)]]; + constraintsWithVisualFormat:@"[closeButton(24)]-6-|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(closeButton)]]; [constraints addObjectsFromArray:[NSLayoutConstraint - constraintsWithVisualFormat:@"V:[closeButton(24)]" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(closeButton)]]; - + constraintsWithVisualFormat:@"V:|-6-[closeButton(24)]" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(closeButton)]]; + [overlayView addConstraints:constraints]; +} +- (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radius:(CGFloat)radius { + _targetView = targetView; + [targetView addObserver:self + forKeyPath:@"frame" + options:NSKeyValueObservingOptionNew + context:NULL]; + NSWindow *parentWindow = _targetView.window; + NSRect overlayRect = [parentWindow convertRectToScreen:[_targetView.superview convertRectToBacking:_targetView.frame]]; + _overlayWindow = [[STOverlayWindow alloc] initWithContentRect:overlayRect]; + [_overlayWindow setReleasedWhenClosed:NO]; + STOverlayView *overlayView = [_overlayWindow overlayView]; + //configure label + overlayView.label = label; + overlayView.labelColor = self.labelColor; + overlayView.labelFont = self.labelFont; + overlayView.bezelRadius = radius; - [constraints addObject:[NSLayoutConstraint constraintWithItem:closeButton - attribute:NSLayoutAttributeTop - relatedBy:NSLayoutRelationEqual - toItem:overlayView - attribute:NSLayoutAttributeTop - multiplier:1.0 - constant:0]]; - [constraints addObject:[NSLayoutConstraint constraintWithItem:closeButton - attribute:NSLayoutAttributeRight - relatedBy:NSLayoutRelationEqual - toItem:overlayView - attribute:NSLayoutAttributeRight - multiplier:1.0 - constant:0]]; - - [overlayView addConstraints:constraints]; - - */ + //create button if needed + if (self.hasCloseButton) { + [self createCloseButtonInView:overlayView]; + } [parentWindow addChildWindow:_overlayWindow ordered:NSWindowAbove]; } @@ -213,11 +205,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath NSWindow *parentWindow = _targetView.window; NSRect overlayRect = [parentWindow convertRectToScreen:[_targetView.superview convertRectToBacking:_targetView.frame]]; [_overlayWindow setFrame:overlayRect display:NO]; - CGRect f = overlayRect; - f.origin.y = f.size.height - 24 - 6; - f.origin.x = f.size.width - 24 - 6; - f.size.width = f.size.height = 24; - closeButton.frame = f; } } From d371f3ae72847a9c11f490d49e2618bcb27405ac Mon Sep 17 00:00:00 2001 From: Cherif Yaya Date: Tue, 15 Jan 2013 06:20:11 +0100 Subject: [PATCH 5/7] Add auto hide support. --- STOverlay/STOverlayController.h | 11 +++++++++++ STOverlay/STOverlayController.m | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/STOverlay/STOverlayController.h b/STOverlay/STOverlayController.h index f09d93d..4e9cd51 100644 --- a/STOverlay/STOverlayController.h +++ b/STOverlay/STOverlayController.h @@ -37,10 +37,21 @@ withLabel:(NSString *)label radius:(CGFloat)radius offset:(CGFloat)offset; +- (void)beginOverlayToView:(NSView *)targetView + withLabel:(NSString *)label + radius:(CGFloat)radius + offset:(CGFloat)offset + hideAfter:(NSInteger)delay; - (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radius:(CGFloat)radius size:(NSSize)size; +- (void)beginOverlayToView:(NSView *)targetView + withLabel:(NSString *)label + radius:(CGFloat)radius + size:(NSSize)size + hideAfter:(NSInteger)delay; + - (void)endOverlay; - (BOOL)isOverlay; diff --git a/STOverlay/STOverlayController.m b/STOverlay/STOverlayController.m index f7ae31e..7222b68 100644 --- a/STOverlay/STOverlayController.m +++ b/STOverlay/STOverlayController.m @@ -144,6 +144,16 @@ - (void)beginOverlayToView:(NSView *)targetView [_overlayWindow.contentView addConstraints:constraints]; } +- (void)beginOverlayToView:(NSView *)targetView + withLabel:(NSString *)label + radius:(CGFloat)radius + offset:(CGFloat)offset + hideAfter:(NSInteger)delay { + [self beginOverlayToView:targetView withLabel:label radius:radius offset:offset]; + + [self hideOverlayAfter:delay]; +} + - (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radius:(CGFloat)radius @@ -181,6 +191,24 @@ - (void)beginOverlayToView:(NSView *)targetView [_overlayWindow.contentView addConstraints:constraints]; } +- (void)beginOverlayToView:(NSView *)targetView + withLabel:(NSString *)label + radius:(CGFloat)radius + size:(NSSize)size + hideAfter:(NSInteger)delay { + [self beginOverlayToView:targetView withLabel:label radius:radius size:size]; + + [self hideOverlayAfter:delay]; + +} + +- (void)hideOverlayAfter:(NSInteger)delay { + //set timeout to hide view + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{ + [self endOverlay]; + }); +} + - (void)endOverlay { NSWindow *parentWindow = _overlayWindow.parentWindow; [parentWindow removeChildWindow:_overlayWindow]; From f6321212453f61696cfa9a2ca02cf9a7b0660454 Mon Sep 17 00:00:00 2001 From: Cherif Yaya Date: Tue, 15 Jan 2013 06:23:44 +0100 Subject: [PATCH 6/7] Make the controller manage cleaning up itself before showing a new message. --- STOverlay/STOverlayController.m | 4 ++++ SampleApp/AppDelegate.m | 26 ++++++++------------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/STOverlay/STOverlayController.m b/STOverlay/STOverlayController.m index 7222b68..d869115 100644 --- a/STOverlay/STOverlayController.m +++ b/STOverlay/STOverlayController.m @@ -96,6 +96,10 @@ - (void)createCloseButtonInView:(NSView *)overlayView { } - (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label radius:(CGFloat)radius { + //if currently displayed, hide first + if ([self isOverlay]) { + [self endOverlay]; + } _targetView = targetView; [targetView addObserver:self forKeyPath:@"frame" diff --git a/SampleApp/AppDelegate.m b/SampleApp/AppDelegate.m index 6bf1324..30a9852 100644 --- a/SampleApp/AppDelegate.m +++ b/SampleApp/AppDelegate.m @@ -43,27 +43,17 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification } - (IBAction)overlay1:(id)sender { - if (self.overlayController.isOverlay) { - [self.overlayController endOverlay]; - } - else { - [self.overlayController beginOverlayToView:self.targetView - withLabel:@"Loading..." - radius:self.radiusSlider.doubleValue - offset:self.offsetSlider.doubleValue]; - } + [self.overlayController beginOverlayToView:self.targetView + withLabel:@"Loading..." + radius:self.radiusSlider.doubleValue + offset:self.offsetSlider.doubleValue]; } - (IBAction)overlay2:(id)sender { - if (self.overlayController.isOverlay) { - [self.overlayController endOverlay]; - } - else { - [self.overlayController beginOverlayToView:self.targetView - withLabel:@"Loading..." - radius:self.radiusSlider.doubleValue - size:NSMakeSize(self.widthSlider.doubleValue, self.heightSlider.doubleValue)]; - } + [self.overlayController beginOverlayToView:self.targetView + withLabel:@"Loading..." + radius:self.radiusSlider.doubleValue + size:NSMakeSize(self.widthSlider.doubleValue, self.heightSlider.doubleValue)]; } @end From 9faa215b3a2b3fd1ee7d7c577c324eb192225acc Mon Sep 17 00:00:00 2001 From: Cherif Yaya Date: Tue, 15 Jan 2013 06:28:06 +0100 Subject: [PATCH 7/7] Add configuration property for close button. --- STOverlay/STOverlayController.h | 3 ++- STOverlay/STOverlayController.m | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/STOverlay/STOverlayController.h b/STOverlay/STOverlayController.h index 4e9cd51..678b97e 100644 --- a/STOverlay/STOverlayController.h +++ b/STOverlay/STOverlayController.h @@ -31,7 +31,8 @@ @property (strong, nonatomic) NSFont *labelFont; @property (strong, nonatomic) NSColor *labelColor; -@property (nonatomic) BOOL hasCloseButton; +@property (nonatomic) float hasCloseButton; +@property (nonatomic) NSUInteger closeButtonOffset; - (void)beginOverlayToView:(NSView *)targetView withLabel:(NSString *)label diff --git a/STOverlay/STOverlayController.m b/STOverlay/STOverlayController.m index d869115..23078db 100644 --- a/STOverlay/STOverlayController.m +++ b/STOverlay/STOverlayController.m @@ -45,10 +45,11 @@ @implementation STOverlayController { - (id)init { self = [super init]; if (self) { - //init label font and color properties + //init label font, color and close button properties self.labelFont = [NSFont systemFontOfSize:48.0]; - self.labelColor = [NSColor redColor]; + self.labelColor = [NSColor whiteColor]; self.hasCloseButton = YES; + self.closeButtonOffset = 8.0f; } return self; @@ -80,16 +81,19 @@ - (void)createCloseButtonInView:(NSView *)overlayView { //make button sits in top right corner NSMutableArray *constraints = [NSMutableArray array]; + NSDictionary *metrics = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:self.closeButtonOffset] + forKey:@"offset"]; + [constraints addObjectsFromArray:[NSLayoutConstraint - constraintsWithVisualFormat:@"[closeButton(24)]-6-|" + constraintsWithVisualFormat:@"[closeButton(24)]-(offset)-|" options:0 - metrics:nil + metrics:metrics views:NSDictionaryOfVariableBindings(closeButton)]]; [constraints addObjectsFromArray:[NSLayoutConstraint - constraintsWithVisualFormat:@"V:|-6-[closeButton(24)]" + constraintsWithVisualFormat:@"V:|-(offset)-[closeButton(24)]" options:0 - metrics:nil + metrics:metrics views:NSDictionaryOfVariableBindings(closeButton)]]; [overlayView addConstraints:constraints];