utils.mm 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * utils.mm, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "utils.h"
  12. #import <UIKit/UIKit.h>
  13. namespace
  14. {
  15. UIActivityIndicatorView *indicator;
  16. }
  17. namespace iOS_utils
  18. {
  19. double screenScale()
  20. {
  21. return UIScreen.mainScreen.nativeScale;
  22. }
  23. void showLoadingIndicator()
  24. {
  25. NSCAssert(!indicator, @"activity indicator must be hidden before attempting to show it again");
  26. indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  27. [indicator startAnimating];
  28. auto mainView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
  29. mainView.userInteractionEnabled = NO;
  30. [mainView addSubview:indicator];
  31. indicator.center = {CGRectGetMidX(mainView.bounds), CGRectGetMidY(mainView.bounds)};
  32. }
  33. void hideLoadingIndicator()
  34. {
  35. indicator.superview.userInteractionEnabled = YES;
  36. [indicator stopAnimating];
  37. [indicator removeFromSuperview];
  38. indicator = nil;
  39. }
  40. void hapticFeedback()
  41. {
  42. auto hapticGen = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
  43. [hapticGen impactOccurred];
  44. }
  45. }