105105#define INLINE_SEPARATOR " \t "
106106#define IDLE_INTERVAL 3.0
107107
108- static double FONT_SIZE = 8.0 ;
109- static uint8_t DATAUNIT = 0 ;
110- static uint8_t SHOW_UPLOAD_SPEED = 1 ;
111- static uint8_t SHOW_DOWNLOAD_SPEED = 1 ;
112- static uint8_t SHOW_DOWNLOAD_SPEED_FIRST = 1 ;
113- static uint8_t SHOW_SECOND_SPEED_IN_NEW_LINE = 0 ;
114- static const char *UPLOAD_PREFIX = " ▲" ;
115- static const char *DOWNLOAD_PREFIX = " ▼" ;
108+ static double HUD_FONT_SIZE = 8.0 ;
109+ static UIFontWeight HUD_FONT_WEIGHT = UIFontWeightRegular;
110+ static CGFloat HUD_INACTIVE_OPACITY = 0.667 ;
111+ static uint8_t HUD_DATA_UNIT = 0 ;
112+ static uint8_t HUD_SHOW_UPLOAD_SPEED = 1 ;
113+ static uint8_t HUD_SHOW_DOWNLOAD_SPEED = 1 ;
114+ static uint8_t HUD_SHOW_DOWNLOAD_SPEED_FIRST = 1 ;
115+ static uint8_t HUD_SHOW_SECOND_SPEED_IN_NEW_LINE = 0 ;
116+ static const char *HUD_UPLOAD_PREFIX = " ▲" ;
117+ static const char *HUD_DOWNLOAD_PREFIX = " ▼" ;
116118
117119typedef struct {
118120 uint64_t inputBytes;
123125{
124126 if (isFocused)
125127 {
126- if (0 == DATAUNIT )
128+ if (0 == HUD_DATA_UNIT )
127129 {
128130 if (bytes < KILOBYTES) return NSLocalizedString(@" 0 KB" , @" formattedSpeed" );
129131 else if (bytes < MEGABYTES) return [NSString stringWithFormat: NSLocalizedString(@" %.0f KB" , @" formattedSpeed" ), (double )bytes / KILOBYTES];
139141 }
140142 }
141143 else {
142- if (0 == DATAUNIT )
144+ if (0 == HUD_DATA_UNIT )
143145 {
144146 if (bytes < KILOBYTES) return NSLocalizedString(@" 0 KB/s" , @" formattedSpeed" );
145147 else if (bytes < MEGABYTES) return [NSString stringWithFormat: NSLocalizedString(@" %.0f KB/s" , @" formattedSpeed" ), (double )bytes / KILOBYTES];
@@ -205,13 +207,13 @@ static UpDownBytes getUpDownBytes()
205207 @autoreleasepool
206208 {
207209 if (!attributedUploadPrefix)
208- attributedUploadPrefix = [[NSAttributedString alloc ] initWithString: [[NSString stringWithUTF8String: UPLOAD_PREFIX ] stringByAppendingString: @" " ] attributes: @{NSFontAttributeName : [UIFont boldSystemFontOfSize: FONT_SIZE] }];
210+ attributedUploadPrefix = [[NSAttributedString alloc ] initWithString: [[NSString stringWithUTF8String: HUD_UPLOAD_PREFIX ] stringByAppendingString: @" " ] attributes: @{ NSFontAttributeName : [UIFont boldSystemFontOfSize: HUD_FONT_SIZE] }];
209211 if (!attributedDownloadPrefix)
210- attributedDownloadPrefix = [[NSAttributedString alloc ] initWithString: [[NSString stringWithUTF8String: DOWNLOAD_PREFIX ] stringByAppendingString: @" " ] attributes: @{NSFontAttributeName : [UIFont boldSystemFontOfSize: FONT_SIZE] }];
212+ attributedDownloadPrefix = [[NSAttributedString alloc ] initWithString: [[NSString stringWithUTF8String: HUD_DOWNLOAD_PREFIX ] stringByAppendingString: @" " ] attributes: @{ NSFontAttributeName : [UIFont boldSystemFontOfSize: HUD_FONT_SIZE] }];
211213 if (!attributedInlineSeparator)
212- attributedInlineSeparator = [[NSAttributedString alloc ] initWithString: [NSString stringWithUTF8String: INLINE_SEPARATOR] attributes: @{NSFontAttributeName : [UIFont systemFontOfSize: FONT_SIZE] }];
214+ attributedInlineSeparator = [[NSAttributedString alloc ] initWithString: [NSString stringWithUTF8String: INLINE_SEPARATOR] attributes: @{ NSFontAttributeName : [UIFont boldSystemFontOfSize: HUD_FONT_SIZE] }];
213215 if (!attributedLineSeparator)
214- attributedLineSeparator = [[NSAttributedString alloc ] initWithString: @" \n " attributes: @{NSFontAttributeName : [UIFont systemFontOfSize: FONT_SIZE] }];
216+ attributedLineSeparator = [[NSAttributedString alloc ] initWithString: @" \n " attributes: @{ NSFontAttributeName : [UIFont boldSystemFontOfSize: HUD_FONT_SIZE] }];
215217
216218 NSMutableAttributedString *mutableString = [[NSMutableAttributedString alloc ] init ];
217219
@@ -248,49 +250,49 @@ static UpDownBytes getUpDownBytes()
248250 }
249251 else shouldUpdateSpeedLabel = YES ;
250252
251- if (DATAUNIT == 1 )
253+ if (HUD_DATA_UNIT == 1 )
252254 {
253255 upDiff *= BYTE_SIZE;
254256 downDiff *= BYTE_SIZE;
255257 }
256258
257- if (SHOW_DOWNLOAD_SPEED_FIRST )
259+ if (HUD_SHOW_DOWNLOAD_SPEED_FIRST )
258260 {
259- if (SHOW_DOWNLOAD_SPEED )
261+ if (HUD_SHOW_DOWNLOAD_SPEED )
260262 {
261263 [mutableString appendAttributedString: attributedDownloadPrefix];
262- [mutableString appendAttributedString: [[NSAttributedString alloc ] initWithString: formattedSpeed (downDiff, isFocused) attributes: @{ NSFontAttributeName : [UIFont monospacedDigitSystemFontOfSize: FONT_SIZE weight: UIFontWeightRegular ] }]];
264+ [mutableString appendAttributedString: [[NSAttributedString alloc ] initWithString: formattedSpeed (downDiff, isFocused) attributes: @{ NSFontAttributeName : [UIFont monospacedDigitSystemFontOfSize: HUD_FONT_SIZE weight: HUD_FONT_WEIGHT ] }]];
263265 }
264266
265- if (SHOW_UPLOAD_SPEED )
267+ if (HUD_SHOW_UPLOAD_SPEED )
266268 {
267269 if ([mutableString length ] > 0 )
268270 {
269- if (SHOW_SECOND_SPEED_IN_NEW_LINE ) [mutableString appendAttributedString: attributedLineSeparator];
271+ if (HUD_SHOW_SECOND_SPEED_IN_NEW_LINE ) [mutableString appendAttributedString: attributedLineSeparator];
270272 else [mutableString appendAttributedString: attributedInlineSeparator];
271273 }
272274
273275 [mutableString appendAttributedString: attributedUploadPrefix];
274- [mutableString appendAttributedString: [[NSAttributedString alloc ] initWithString: formattedSpeed (upDiff, isFocused) attributes: @{ NSFontAttributeName : [UIFont monospacedDigitSystemFontOfSize: FONT_SIZE weight: UIFontWeightRegular ] }]];
276+ [mutableString appendAttributedString: [[NSAttributedString alloc ] initWithString: formattedSpeed (upDiff, isFocused) attributes: @{ NSFontAttributeName : [UIFont monospacedDigitSystemFontOfSize: HUD_FONT_SIZE weight: HUD_FONT_WEIGHT ] }]];
275277 }
276278 }
277279 else
278280 {
279- if (SHOW_UPLOAD_SPEED )
281+ if (HUD_SHOW_UPLOAD_SPEED )
280282 {
281283 [mutableString appendAttributedString: attributedUploadPrefix];
282- [mutableString appendAttributedString: [[NSAttributedString alloc ] initWithString: formattedSpeed (upDiff, isFocused) attributes: @{ NSFontAttributeName : [UIFont monospacedDigitSystemFontOfSize: FONT_SIZE weight: UIFontWeightRegular ] }]];
284+ [mutableString appendAttributedString: [[NSAttributedString alloc ] initWithString: formattedSpeed (upDiff, isFocused) attributes: @{ NSFontAttributeName : [UIFont monospacedDigitSystemFontOfSize: HUD_FONT_SIZE weight: HUD_FONT_WEIGHT ] }]];
283285 }
284- if (SHOW_DOWNLOAD_SPEED )
286+ if (HUD_SHOW_DOWNLOAD_SPEED )
285287 {
286288 if ([mutableString length ] > 0 )
287289 {
288- if (SHOW_SECOND_SPEED_IN_NEW_LINE ) [mutableString appendAttributedString: attributedLineSeparator];
290+ if (HUD_SHOW_SECOND_SPEED_IN_NEW_LINE ) [mutableString appendAttributedString: attributedLineSeparator];
289291 else [mutableString appendAttributedString: attributedInlineSeparator];
290292 }
291293
292294 [mutableString appendAttributedString: attributedDownloadPrefix];
293- [mutableString appendAttributedString: [[NSAttributedString alloc ] initWithString: formattedSpeed (downDiff, isFocused) attributes: @{ NSFontAttributeName : [UIFont monospacedDigitSystemFontOfSize: FONT_SIZE weight: UIFontWeightRegular ] }]];
295+ [mutableString appendAttributedString: [[NSAttributedString alloc ] initWithString: formattedSpeed (downDiff, isFocused) attributes: @{ NSFontAttributeName : [UIFont monospacedDigitSystemFontOfSize: HUD_FONT_SIZE weight: HUD_FONT_WEIGHT ] }]];
294296 }
295297 }
296298
@@ -406,14 +408,16 @@ - (void)reloadUserDefaults
406408 [_lockedView setImage: [UIImage systemImageNamed: @" lock.fill" ]];
407409 }
408410
409- DATAUNIT = usesBitrate;
410- SHOW_UPLOAD_SPEED = !singleLineMode;
411- SHOW_DOWNLOAD_SPEED_FIRST = isCentered;
412- SHOW_SECOND_SPEED_IN_NEW_LINE = !isCentered;
413- FONT_SIZE = (usesLargeFont ? 9.0 : 8.0 );
411+ HUD_DATA_UNIT = usesBitrate;
412+ HUD_SHOW_UPLOAD_SPEED = !singleLineMode;
413+ HUD_SHOW_DOWNLOAD_SPEED_FIRST = isCentered;
414+ HUD_SHOW_SECOND_SPEED_IN_NEW_LINE = !isCentered;
415+ HUD_FONT_SIZE = (usesLargeFont ? 9.0 : 8.0 );
416+ HUD_FONT_WEIGHT = (usesInvertedColor ? UIFontWeightSemibold : UIFontWeightRegular);
417+ HUD_INACTIVE_OPACITY = (usesInvertedColor ? 1.0 : 0.667 );
414418
415- UPLOAD_PREFIX = (usesArrowPrefixes ? " ↑" : " ▲" );
416- DOWNLOAD_PREFIX = (usesArrowPrefixes ? " ↓" : " ▼" );
419+ HUD_UPLOAD_PREFIX = (usesArrowPrefixes ? " ↑" : " ▲" );
420+ HUD_DOWNLOAD_PREFIX = (usesArrowPrefixes ? " ↓" : " ▼" );
417421
418422 prevInputBytes = 0 ;
419423 prevOutputBytes = 0 ;
@@ -595,7 +599,7 @@ - (void)viewDidLoad
595599 _speedLabel.numberOfLines = 0 ;
596600 _speedLabel.textAlignment = NSTextAlignmentCenter;
597601 _speedLabel.textColor = [UIColor whiteColor ];
598- _speedLabel.font = [UIFont systemFontOfSize: FONT_SIZE ];
602+ _speedLabel.font = [UIFont systemFontOfSize: HUD_FONT_SIZE ];
599603 _speedLabel.translatesAutoresizingMaskIntoConstraints = NO ;
600604 [_speedLabel setContentHuggingPriority: UILayoutPriorityDefaultHigh forAxis: UILayoutConstraintAxisVertical];
601605 [_blurView.contentView addSubview: _speedLabel];
@@ -847,8 +851,9 @@ - (void)onFocus:(UIView *)view scaleFactor:(CGFloat)scaleFactor duration:(NSTime
847851
848852 view.alpha = 1.0 ;
849853 } completion: ^(BOOL finished) {
850- if (blurWhenDone)
854+ if (blurWhenDone) {
851855 [self performSelector: @selector (onBlur: ) withObject: view afterDelay: IDLE_INTERVAL];
856+ }
852857 }];
853858}
854859
@@ -868,7 +873,7 @@ - (void)onBlur:(UIView *)view duration:(NSTimeInterval)duration
868873
869874 [UIView animateWithDuration: duration delay: 0.0 usingSpringWithDamping: 1.0 initialSpringVelocity: 1.0 options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState animations: ^{
870875 view.transform = CGAffineTransformIdentity;
871- view.alpha = 0.667 ;
876+ view.alpha = HUD_INACTIVE_OPACITY ;
872877 } completion: nil ];
873878}
874879
@@ -1048,7 +1053,7 @@ - (void)updateOrientation:(UIInterfaceOrientation)orientation animateWithDuratio
10481053 __weak typeof (self) weakSelf = self;
10491054 [UIView animateWithDuration: duration animations: ^{
10501055 __strong typeof (weakSelf) strongSelf = weakSelf;
1051- strongSelf->_contentView .alpha = strongSelf->_isFocused ? 1.0 : 0.667 ;
1056+ strongSelf->_contentView .alpha = strongSelf->_isFocused ? 1.0 : HUD_INACTIVE_OPACITY ;
10521057 }];
10531058 }
10541059 else
@@ -1115,7 +1120,7 @@ - (void)viewWillTransitionToSize:(CGSize)size
11151120 [strongSelf onBlur: strongSelf->_contentView duration: 0 ];
11161121
11171122 if (orientation == UIInterfaceOrientationPortrait) {
1118- strongSelf->_contentView .alpha = strongSelf->_isFocused ? 1.0 : 0.667 ;
1123+ strongSelf->_contentView .alpha = strongSelf->_isFocused ? 1.0 : HUD_INACTIVE_OPACITY ;
11191124 } else {
11201125 strongSelf->_contentView .alpha = 0.0 ;
11211126 }
0 commit comments