diff --git a/12306ForMac-Swift.h b/12306ForMac-Swift.h index 0aaf49a..dd40bfa 100644 --- a/12306ForMac-Swift.h +++ b/12306ForMac-Swift.h @@ -10,8 +10,8 @@ #define _Train12306_Swift_h #import "MASPreferences.h" -#import "DJProgressHUD.h" #import "DJTipHUD.h" +#import "DJLayerView.h" #import #endif diff --git a/12306ForMac.xcodeproj/project.pbxproj b/12306ForMac.xcodeproj/project.pbxproj index f27ef5f..2eaab6d 100644 --- a/12306ForMac.xcodeproj/project.pbxproj +++ b/12306ForMac.xcodeproj/project.pbxproj @@ -69,10 +69,10 @@ F13E9C981D0AA9760011F7E2 /* TrainInfoTableCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13E9C971D0AA9760011F7E2 /* TrainInfoTableCellView.swift */; }; F13E9C9A1D0AB3310011F7E2 /* TrainTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13E9C991D0AB3310011F7E2 /* TrainTableRowView.swift */; }; F14243141DB610FF0012B5E4 /* DJActivityIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = F14243111DB610FF0012B5E4 /* DJActivityIndicator.m */; }; - F14243151DB610FF0012B5E4 /* DJProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = F14243131DB610FF0012B5E4 /* DJProgressHUD.m */; }; F142431B1DB628CB0012B5E4 /* DJTipHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = F142431A1DB628CB0012B5E4 /* DJTipHUD.m */; }; F147763E1D6B2B2E002FD6AF /* InfoButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = F147763D1D6B2B2E002FD6AF /* InfoButton.swift */; }; F14D6BE41D86E91C00CBD36C /* FilterTrainCodeTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F14D6BE31D86E91C00CBD36C /* FilterTrainCodeTransformer.swift */; }; + F159C9D51DBDD76A00202143 /* DJLayerView.m in Sources */ = {isa = PBXBuildFile; fileRef = F159C9D41DBDD76A00202143 /* DJLayerView.m */; }; F17AB1CC1C95630E00FEB221 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = F17AB1CB1C95630E00FEB221 /* Credits.rtf */; }; F1AF72B81DAA24FB0047486B /* DataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1AF72B71DAA24FB0047486B /* DataManager.swift */; }; F1C075211D83F97A006EFABB /* TicketConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1C075201D83F97A006EFABB /* TicketConstants.swift */; }; @@ -181,13 +181,13 @@ F13E9C991D0AB3310011F7E2 /* TrainTableRowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainTableRowView.swift; sourceTree = ""; }; F14243101DB610FF0012B5E4 /* DJActivityIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DJActivityIndicator.h; sourceTree = ""; }; F14243111DB610FF0012B5E4 /* DJActivityIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DJActivityIndicator.m; sourceTree = ""; }; - F14243121DB610FF0012B5E4 /* DJProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DJProgressHUD.h; sourceTree = ""; }; - F14243131DB610FF0012B5E4 /* DJProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DJProgressHUD.m; sourceTree = ""; }; F14243191DB628CB0012B5E4 /* DJTipHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DJTipHUD.h; sourceTree = ""; }; F142431A1DB628CB0012B5E4 /* DJTipHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DJTipHUD.m; sourceTree = ""; }; F147763D1D6B2B2E002FD6AF /* InfoButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InfoButton.swift; sourceTree = ""; }; F14D6BE31D86E91C00CBD36C /* FilterTrainCodeTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterTrainCodeTransformer.swift; sourceTree = ""; }; F15277071DAB78D3002BAF17 /* 12306ForMac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = 12306ForMac.entitlements; path = 12306ForMac/12306ForMac.entitlements; sourceTree = ""; }; + F159C9D31DBDD76A00202143 /* DJLayerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DJLayerView.h; sourceTree = ""; }; + F159C9D41DBDD76A00202143 /* DJLayerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DJLayerView.m; sourceTree = ""; }; F17AB1CB1C95630E00FEB221 /* Credits.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; name = Credits.rtf; path = 12306ForMac/Resources/Credits.rtf; sourceTree = SOURCE_ROOT; }; F1AF72B71DAA24FB0047486B /* DataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataManager.swift; sourceTree = ""; }; F1C075201D83F97A006EFABB /* TicketConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketConstants.swift; sourceTree = ""; }; @@ -427,12 +427,12 @@ F142430F1DB610FF0012B5E4 /* DJProgressHUD */ = { isa = PBXGroup; children = ( + F159C9D31DBDD76A00202143 /* DJLayerView.h */, + F159C9D41DBDD76A00202143 /* DJLayerView.m */, F14243191DB628CB0012B5E4 /* DJTipHUD.h */, F142431A1DB628CB0012B5E4 /* DJTipHUD.m */, F14243101DB610FF0012B5E4 /* DJActivityIndicator.h */, F14243111DB610FF0012B5E4 /* DJActivityIndicator.m */, - F14243121DB610FF0012B5E4 /* DJProgressHUD.h */, - F14243131DB610FF0012B5E4 /* DJProgressHUD.m */, ); path = DJProgressHUD; sourceTree = ""; @@ -610,6 +610,7 @@ F111549F1C8D929200FA6059 /* Service+Login.swift in Sources */, F1CA120D1D1135E2003EFD0B /* Theme.swift in Sources */, F1CA12051D10F546003EFD0B /* TrainCodeDetailHeaderCell.swift in Sources */, + F159C9D51DBDD76A00202143 /* DJLayerView.m in Sources */, F1CCA2DE1D0D4A1400B6853E /* TrainCodeDetail.swift in Sources */, F1C075211D83F97A006EFABB /* TicketConstants.swift in Sources */, F11154981C8D927C00FA6059 /* StationData.swift in Sources */, @@ -642,7 +643,6 @@ F11154721C8D921400FA6059 /* LeftTicketParam.swift in Sources */, F1FEE7A21D8D464900B02C84 /* NotifySpeaker.swift in Sources */, F1FCFF4B1D386F8F0070A32C /* URLButton.swift in Sources */, - F14243151DB610FF0012B5E4 /* DJProgressHUD.m in Sources */, F11154A11C8D929200FA6059 /* Service+QueryOrder.swift in Sources */, F11154A21C8D929200FA6059 /* Service+QueryTicket.swift in Sources */, F11154A91C8D92A700FA6059 /* LoginWindowController.swift in Sources */, diff --git a/12306ForMac.xcodeproj/project.xcworkspace/xcuserdata/lindahai.xcuserdatad/UserInterfaceState.xcuserstate b/12306ForMac.xcodeproj/project.xcworkspace/xcuserdata/lindahai.xcuserdatad/UserInterfaceState.xcuserstate index fb90ea5..8fca129 100644 Binary files a/12306ForMac.xcodeproj/project.xcworkspace/xcuserdata/lindahai.xcuserdatad/UserInterfaceState.xcuserstate and b/12306ForMac.xcodeproj/project.xcworkspace/xcuserdata/lindahai.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/12306ForMac.xcodeproj/xcuserdata/lindahai.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/12306ForMac.xcodeproj/xcuserdata/lindahai.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 741cb90..9579579 100644 --- a/12306ForMac.xcodeproj/xcuserdata/lindahai.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/12306ForMac.xcodeproj/xcuserdata/lindahai.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -26,11 +26,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "12306ForMac/OrderViewControllers/OrderViewController.swift" - timestampString = "498559506.056539" + timestampString = "498981115.057717" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "130" - endingLineNumber = "130" + startingLineNumber = "139" + endingLineNumber = "139" landmarkName = "queryAllOrder()" landmarkType = "5"> @@ -42,11 +42,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "12306ForMac/OrderViewControllers/OrderViewController.swift" - timestampString = "498559506.056539" + timestampString = "498981115.057717" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "93" - endingLineNumber = "93" + startingLineNumber = "102" + endingLineNumber = "102" landmarkName = "queryHistoryOrder()" landmarkType = "5"> @@ -58,11 +58,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "12306ForMac/OrderViewControllers/OrderViewController.swift" - timestampString = "498559506.056539" + timestampString = "498981115.057717" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "118" - endingLineNumber = "118" + startingLineNumber = "127" + endingLineNumber = "127" landmarkName = "queryAllOrder()" landmarkType = "5"> @@ -74,11 +74,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "12306ForMac/OrderViewControllers/OrderViewController.swift" - timestampString = "498559506.056539" + timestampString = "498981115.057717" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "102" - endingLineNumber = "102" + startingLineNumber = "111" + endingLineNumber = "111" landmarkName = "queryHistoryOrder()" landmarkType = "5"> @@ -211,22 +211,6 @@ landmarkType = "5"> - - - - @@ -266,7 +250,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "12306ForMac/TicketViewControllers/TicketQueryViewController.swift" - timestampString = "498643637.085131" + timestampString = "498988230.929609" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "451" @@ -282,7 +266,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "12306ForMac/TicketViewControllers/TicketQueryViewController.swift" - timestampString = "498562034.070445" + timestampString = "498988230.929609" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "330" @@ -298,11 +282,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "DJProgressHUD/DJTipHUD.m" - timestampString = "498563564.481737" + timestampString = "498988164.484067" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "82" - endingLineNumber = "82" + startingLineNumber = "79" + endingLineNumber = "79" landmarkName = "-updateLayout" landmarkType = "5"> @@ -310,15 +294,15 @@ diff --git a/12306ForMac/OrderViewControllers/OrderViewController.swift b/12306ForMac/OrderViewControllers/OrderViewController.swift index ebd103f..625472d 100644 --- a/12306ForMac/OrderViewControllers/OrderViewController.swift +++ b/12306ForMac/OrderViewControllers/OrderViewController.swift @@ -43,6 +43,15 @@ class OrderViewController: NSViewController{ DJTipHUD.showStatus(tip, fromView: self.view) } + func startLoadingTip(tip:String) + { + DJLayerView.showStatus(tip, fromView: self.view) + } + + func stopLoadingTip(){ + DJLayerView.dismiss() + } + func receiveLogoutMessageNotification(notification: NSNotification) { MainModel.noCompleteOrderList.removeAll() self.orderList.removeAll() @@ -61,18 +70,18 @@ class OrderViewController: NSViewController{ alert.beginSheetModalForWindow(self.view.window!, completionHandler: { reponse in if reponse == NSAlertFirstButtonReturn { if let sequence_no = MainModel.noCompleteOrderList[0].sequence_no { - DJProgressHUD.showStatus("正在取消...", fromView: self.view) + self.startLoadingTip("正在取消...") let successHandler = { MainModel.noCompleteOrderList.removeAll() self.orderList = MainModel.historyOrderList self.orderListTable.reloadData() - DJProgressHUD.dismiss() + self.stopLoadingTip() self.showTip("取消订单成功") self.hasOrder = false } let failureHandler = {(error:NSError)->() in - DJProgressHUD.dismiss() + self.stopLoadingTip() self.showTip(translate(error)) } self.service.cancelOrderWith(sequence_no, success: successHandler, failure:failureHandler) @@ -86,17 +95,17 @@ class OrderViewController: NSViewController{ } func queryHistoryOrder(){ - DJProgressHUD.showStatus("正在查询...", fromView: self.view) + self.startLoadingTip("正在查询...") let successHandler = { self.orderList.appendContentsOf(MainModel.historyOrderList) self.orderListTable.reloadData() - DJProgressHUD.dismiss() + self.stopLoadingTip() } let failureHandler = { - DJProgressHUD.dismiss() + self.stopLoadingTip() } service.queryHistoryOrderFlow((success: successHandler, failure: failureHandler)) } @@ -111,13 +120,13 @@ class OrderViewController: NSViewController{ self.orderListTable.reloadData() hasQuery = true - DJProgressHUD.showStatus("正在查询...", fromView: self.view) + self.startLoadingTip("正在查询...") let successHandler = { self.orderList = MainModel.noCompleteOrderList self.orderListTable.reloadData() - DJProgressHUD.dismiss() + self.stopLoadingTip() if self.orderList.count > 0 { self.hasOrder = true @@ -130,7 +139,7 @@ class OrderViewController: NSViewController{ } let failureHandler = { - DJProgressHUD.dismiss() + self.stopLoadingTip() self.hasOrder = false } service.queryNoCompleteOrderFlow(success: successHandler, failure: failureHandler) diff --git a/12306ForMac/Sheets/LoginWindowController.swift b/12306ForMac/Sheets/LoginWindowController.swift index e588825..26b0efc 100644 --- a/12306ForMac/Sheets/LoginWindowController.swift +++ b/12306ForMac/Sheets/LoginWindowController.swift @@ -88,11 +88,11 @@ class LoginWindowController: NSWindowController{ func startLoadingTip(tip:String) { - DJProgressHUD.showStatus(tip, fromView: self.window?.contentView) + DJLayerView.showStatus(tip, fromView: self.window?.contentView) } func stopLoadingTip(){ - DJProgressHUD.dismiss() + DJLayerView.dismiss() } diff --git a/12306ForMac/Sheets/SubmitWindowController.swift b/12306ForMac/Sheets/SubmitWindowController.swift index 5fac653..fe36837 100644 --- a/12306ForMac/Sheets/SubmitWindowController.swift +++ b/12306ForMac/Sheets/SubmitWindowController.swift @@ -64,11 +64,11 @@ class SubmitWindowController: NSWindowController{ func startLoadingTip(tip:String) { - DJProgressHUD.showStatus(tip, fromView: self.window?.contentView) + DJLayerView.showStatus(tip, fromView: self.window?.contentView) } func stopLoadingTip(){ - DJProgressHUD.dismiss() + DJLayerView.dismiss() } func showTip(tip:String){ diff --git a/12306ForMac/TicketViewControllers/TicketQueryViewController.swift b/12306ForMac/TicketViewControllers/TicketQueryViewController.swift index aa6af57..46fa315 100644 --- a/12306ForMac/TicketViewControllers/TicketQueryViewController.swift +++ b/12306ForMac/TicketViewControllers/TicketQueryViewController.swift @@ -394,16 +394,16 @@ class TicketQueryViewController: NSViewController { } func showTip(tip:String){ - DJTipHUD.showStatus(tip, fromView: self.secondSearchView) + DJTipHUD.showStatus(tip, fromView: self.view) } func startLoadingTip(tip:String) { - DJProgressHUD.showStatus(tip, fromView: self.view) + DJLayerView.showStatus(tip, fromView: self.view) } func stopLoadingTip(){ - DJProgressHUD.dismiss() + DJLayerView.dismiss() } func queryLeftTicket(summitHandler:()->() = {}) { diff --git a/DJProgressHUD/DJLayerView.h b/DJProgressHUD/DJLayerView.h new file mode 100644 index 0000000..e46cf18 --- /dev/null +++ b/DJProgressHUD/DJLayerView.h @@ -0,0 +1,32 @@ +// +// DJLayerView.h +// Playground +// +// Created by fancymax on 16/10/24. +// Copyright © 2016年 Daniel Jackson. All rights reserved. +// + +#import + +@interface DJLayerView : NSView + ++(void)showStatus:(NSString*)status FromView:(NSView *)view; ++(void)dismiss; + +// Customization +#define pMaxWidth1 250 +#define pMaxHeight1 200 + +//General Popup Values +@property (nonatomic) CGVector pOffset; +@property (nonatomic) CGFloat pAlpha; + +//Padding +@property (nonatomic) CGFloat pPadding; + +@property (nonatomic) CGSize indicatorSize; +@property (nonatomic) CGVector indicatorOffset; +@property (nonatomic) CGSize labelSize; +@property (nonatomic) CGVector labelOffset; + +@end diff --git a/DJProgressHUD/DJProgressHUD.m b/DJProgressHUD/DJLayerView.m old mode 100755 new mode 100644 similarity index 62% rename from DJProgressHUD/DJProgressHUD.m rename to DJProgressHUD/DJLayerView.m index 3c447e0..27add2e --- a/DJProgressHUD/DJProgressHUD.m +++ b/DJProgressHUD/DJLayerView.m @@ -1,18 +1,15 @@ // -// CPProgressView.m -// Cloud Play OSX +// DJLayerView.m +// Playground // -// Created by Daniel Jackson on 4/22/14. -// Copyright (c) 2014 Daniel Jackson. All rights reserved. +// Created by fancymax on 16/10/24. +// Copyright © 2016年 Daniel Jackson. All rights reserved. // -#import "DJProgressHUD.h" +#import "DJLayerView.h" #import "DJActivityIndicator.h" -typedef void (^CompletionHander)(void); - -@interface DJProgressHUD () -{ +@interface DJLayerView(){ NSView* parentView; CGSize pSize; //This is set automatically based on the content @@ -20,122 +17,58 @@ @interface DJProgressHUD () NSTextField* label; } -@property CGFloat backgroundAlpha; - @end -@implementation DJProgressHUD +@implementation DJLayerView -#pragma mark - -#pragma mark Class Methods - -+ (void)showStatus:(NSString*)status FromView:(NSView*)view -{ - [[self instance] showStatus:status FromView:view]; ++(void)showStatus:(NSString *)status FromView:(NSView *)parentView{ + [[self instance] showStatus:status FromView:parentView]; } -+ (void)dismiss -{ - [[self instance] hideViewAnimated]; -} - -#pragma mark - -#pragma mark Master Methods - -- (void)showStatus:(NSString*)status FromView:(NSView*)view -{ - parentView = view; - - label.stringValue = status; - - [activityIndicator setHidden:FALSE]; - [activityIndicator startAnimation:nil]; - - if(![self displaying]) - [self showViewAnimated]; - else - [self replaceViewQuick]; -} - -#pragma mark - -#pragma mark Instance Methods - --(void)replaceViewQuick -{ - [self beginShowView]; - [self.layer setOpacity:_pAlpha]; -} - -- (void)beginShowView -{ - [self updateLayout]; - NSRect size = [self getCenterWithinRect:parentView.frame scale:1.0]; - - if(!self.superview) [parentView addSubview:self]; - [self.layer setFrame:size]; - - _displaying = true; - - [activityIndicator.layer setOpacity:1.0]; - [label.layer setOpacity:1.0]; ++(void)dismiss { + [[self instance] finishHideView]; } -(void)finishHideView { - if([parentView wantsLayer]) - { - [parentView setWantsLayer:NO]; - } [self removeFromSuperview]; parentView = nil; - _displaying = false; [activityIndicator stopAnimation:nil]; } -- (void)showViewAnimated -{ - if(![parentView wantsLayer]) - { - [parentView setWantsLayer:TRUE]; - [parentView setLayer:[CALayer layer]]; - } - - [self beginShowView]; - - self.layer.opacity = 0.0; - [self.layer setFrame:[self getCenterWithinRect:parentView.frame scale:0.75]]; - +-(void)showStatus:(NSString*)status FromView:(NSView *)view { + parentView = view; + label.stringValue = status; + [activityIndicator startAnimation:nil]; - [CATransaction flush]; - [CATransaction begin]; - [CATransaction setValue:[NSNumber numberWithFloat:0.6f] - forKey:kCATransactionAnimationDuration]; - [CATransaction setCompletionBlock:^{ - - }]; - - [self.layer setFrame:[self getCenterWithinRect:parentView.frame scale:1]]; - [self.layer setOpacity:_pAlpha]; - [CATransaction commit]; + if (!self.superview) { + [parentView addSubview:self]; + } - [self setNeedsDisplay:TRUE]; + [self updateLayout]; + + CGColorRef bgcolor = CGColorCreateGenericRGB(0.05, 0.05, 0.05, 0.8); + self.layer.backgroundColor = bgcolor; + self.layer.cornerRadius = 15.0; + [self setFrame:[self getCenterWithinRect:parentView.frame scale:1]]; } -- (void)hideViewAnimated +- (NSRect)getCenterWithinRect:(NSRect)parentFrame scale:(CGFloat)scale { - [self finishHideView]; - - [self setNeedsDisplay:TRUE]; + NSRect result; + CGFloat newWidth = pSize.width*scale; + CGFloat newHeight = pSize.height*scale; + result.origin.x = parentFrame.size.width/2 - newWidth/2 + _pOffset.dx; + result.origin.y = parentFrame.size.height/2 - newHeight/2 + _pOffset.dy; + result.size.width = newWidth; + result.size.height = newHeight; + + return result; } -#pragma mark - -#pragma mark Laying It Out - - (void)updateLayout { - [self setBackground]; - CGSize maxContentSize = CGSizeMake(pMaxWidth1-(_pPadding*2), pMaxHeight1-(_pPadding*2)); CGSize minContentSize = CGSizeMake(_indicatorSize.width, _indicatorSize.height); @@ -170,36 +103,15 @@ - (void)updateLayout activityIndicator.frame = indicatorRect; CGFloat spaceOnTop = (stringHeight != 0) ? _pPadding/3 : 0; - + [activityIndicator setColor:[NSColor whiteColor]]; pSize.width = popupWidth; pSize.height = iY+iH+_pPadding+spaceOnTop;//+(_pPadding/2); [self setAutoresizesSubviews:YES]; - - [self setNeedsDisplay:TRUE]; -} - -- (void)setBackground -{ - CGColorRef bgcolor = CGColorCreateGenericRGB(0.05, 0.05, 0.05, _pAlpha); - - if(![self layer]) { - CALayer* bgLayer = [CALayer layer]; - [self setLayer:bgLayer]; - [self.layer setCornerRadius:15.0]; - [self setWantsLayer:TRUE]; - } - - [self.layer setBackgroundColor:bgcolor]; - - [self setNeedsDisplay:TRUE]; } -#pragma mark - -#pragma mark Other - -(CGFloat) heightForString:(NSString *)myString font:(NSFont*) myFont width:(CGFloat)myWidth { NSTextStorage *textStorage = [[NSTextStorage alloc] initWithString:myString]; @@ -217,36 +129,20 @@ -(CGFloat) heightForString:(NSString *)myString font:(NSFont*) myFont width:(CGF usedRectForTextContainer:textContainer].size.height; } -- (NSRect)getCenterWithinRect:(NSRect)parentFrame scale:(CGFloat)scale -{ - NSRect result; - CGFloat newWidth = pSize.width*scale; - CGFloat newHeight = pSize.height*scale; - result.origin.x = parentFrame.size.width/2 - newWidth/2 + _pOffset.dx; - result.origin.y = parentFrame.size.height/2 - newHeight/2 + _pOffset.dy; - result.size.width = newWidth; - result.size.height = newHeight; - - return result; -} - -#pragma mark - - - (void)initializePopup { + [self setWantsLayer:YES]; + self.autoresizingMask = NSViewMaxXMargin | NSViewMaxYMargin | NSViewMinXMargin | NSViewMinYMargin; activityIndicator = [[DJActivityIndicator alloc] init]; label = [[NSTextField alloc] init]; - [self addSubview:label]; [self addSubview:activityIndicator]; //----DEFAULT VALUES---- - _backgroundAlpha = 0.4; - _pOffset = CGVectorMake(0, 0); _pAlpha = 0.9; _pPadding = 10; @@ -259,14 +155,14 @@ - (void)initializePopup [label setEditable:NO]; [label setSelectable:NO]; - label.font = [NSFont systemFontOfSize:12]; + label.font = [NSFont systemFontOfSize:13.0]; [label setTextColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.85]]; } -+ (DJProgressHUD *) instance ++ (DJLayerView *) instance { static dispatch_once_t once; - static DJProgressHUD *sharedView; + static DJLayerView *sharedView; dispatch_once(&once, ^ { sharedView = [[self alloc] init]; [sharedView initializePopup]; diff --git a/DJProgressHUD/DJProgressHUD.h b/DJProgressHUD/DJProgressHUD.h deleted file mode 100755 index fe3fc71..0000000 --- a/DJProgressHUD/DJProgressHUD.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// CPProgressView.h -// Cloud Play OSX -// -// Created by Daniel Jackson on 4/22/14. -// Copyright (c) 2014 Daniel Jackson. All rights reserved. -// - -#import -#import - -/*#define popupWidth 120 -#define popupHeight 120 - -#define popupAlpha 0.9 - -#define xOffset 0 -#define yOffset 0 - -#define indicatorSize 40*/ - -@class DJActivityIndicator; - -@interface DJProgressHUD : NSView - -+ (void)showStatus:(NSString*)status FromView:(NSView*)view; - -+ (void)dismiss; - -@property (nonatomic, readonly) BOOL displaying; - -// Customization -#define pMaxWidth1 250 -#define pMaxHeight1 200 - -//General Popup Values -@property (nonatomic) CGVector pOffset; -@property (nonatomic) CGFloat pAlpha; - -//Padding -@property (nonatomic) CGFloat pPadding; - -@property (nonatomic) CGSize indicatorSize; -@property (nonatomic) CGVector indicatorOffset; -@property (nonatomic) CGSize labelSize; -@property (nonatomic) CGVector labelOffset; - -@end diff --git a/DJProgressHUD/DJTipHUD.m b/DJProgressHUD/DJTipHUD.m index 625cdce..d2cb15e 100755 --- a/DJProgressHUD/DJTipHUD.m +++ b/DJProgressHUD/DJTipHUD.m @@ -39,16 +39,26 @@ - (void)showStatus:(NSString*)status FromView:(NSView*)view } parentView = view; - label.stringValue = status; - [self showViewAnimated]; + if(!self.superview) { + [parentView addSubview:self]; + _displaying = true; + } + + CGColorRef bgcolor = CGColorCreateGenericRGB(0.05, 0.05, 0.05, 0.8); + self.layer.backgroundColor = bgcolor; + self.layer.cornerRadius = 15.0; + + [self updateLayout]; + NSRect size = [self getCenterWithinRect:parentView.frame scale:1.0]; + [self setFrame:size]; + // [self setFrame:[self getCenterWithinRect:parentView.frame scale:1.0]]; NSInteger interval = 2; if ([status length] >= 10) { interval = 10; } - [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(finishHideView) userInfo:nil repeats:NO]; } @@ -62,19 +72,6 @@ -(void)finishHideView _displaying = false; } -- (void)showViewAnimated -{ - [self updateLayout]; - NSRect size = [self getCenterWithinRect:parentView.frame scale:1.0]; - - if(!self.superview) [parentView addSubview:self]; - [self setFrame:size]; - - _displaying = true; - - [self setNeedsDisplay:TRUE]; -} - #pragma mark - #pragma mark Laying It Out @@ -117,8 +114,6 @@ - (void)updateLayout pSize.height = iY+iH+_pPadding+spaceOnTop;//+(_pPadding/2); [self setAutoresizesSubviews:YES]; - - [self setNeedsDisplay:TRUE]; } #pragma mark - @@ -154,16 +149,12 @@ - (NSRect)getCenterWithinRect:(NSRect)parentFrame scale:(CGFloat)scale return result; } -- (void)drawRect:(NSRect)frame { - NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:frame xRadius:6.0 yRadius:6.0]; - [[NSColor colorWithCalibratedWhite:0.0 alpha:0.75] set]; - [path fill]; -} - #pragma mark - - (void)initializePopup { + [self setWantsLayer:YES]; + self.autoresizingMask = NSViewMaxXMargin | NSViewMaxYMargin | NSViewMinXMargin | NSViewMinYMargin; label = [[NSTextField alloc] init]; @@ -185,7 +176,7 @@ - (void)initializePopup [label setEditable:NO]; [label setSelectable:NO]; - label.font = [NSFont systemFontOfSize:12.0]; + label.font = [NSFont systemFontOfSize:13.0]; [label setTextColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.85]]; }