FHSSnapshotNodes.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // FHSSnapshotNodes.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 1/7/20.
  6. //
  7. #import "FHSSnapshotNodes.h"
  8. #import "SceneKit+Snapshot.h"
  9. @interface FHSSnapshotNodes ()
  10. @property (nonatomic, nullable) SCNNode *highlight;
  11. @property (nonatomic, nullable) SCNNode *dimming;
  12. @end
  13. @implementation FHSSnapshotNodes
  14. + (instancetype)snapshot:(FHSViewSnapshot *)snapshot depth:(NSInteger)depth {
  15. FHSSnapshotNodes *nodes = [self new];
  16. nodes->_snapshotItem = snapshot;
  17. nodes->_depth = depth;
  18. return nodes;
  19. }
  20. - (void)setHighlighted:(BOOL)highlighted {
  21. if (_highlighted != highlighted) {
  22. _highlighted = highlighted;
  23. if (highlighted) {
  24. if (!self.highlight) {
  25. // Create highlight node
  26. self.highlight = [SCNNode
  27. highlight:self.snapshotItem
  28. color:[UIColor.blueColor colorWithAlphaComponent:0.5]
  29. ];
  30. }
  31. // Add add highlight node, remove dimming node if dimmed
  32. [self.snapshot addChildNode:self.highlight];
  33. if (self.isDimmed) {
  34. [self.dimming removeFromParentNode];
  35. }
  36. } else {
  37. // Remove highlight node, add back dimming node if dimmed
  38. [self.highlight removeFromParentNode];
  39. if (self.isDimmed) {
  40. [self.snapshot addChildNode:self.dimming];
  41. }
  42. }
  43. }
  44. }
  45. - (void)setDimmed:(BOOL)dimmed {
  46. if (_dimmed != dimmed) {
  47. _dimmed = dimmed;
  48. if (dimmed) {
  49. if (!self.dimming) {
  50. // Create dimming node
  51. self.dimming = [SCNNode
  52. highlight:self.snapshotItem
  53. color:[UIColor.blackColor colorWithAlphaComponent:0.5]
  54. ];
  55. }
  56. // Add add dimming node if not highlighted
  57. if (!self.isHighlighted) {
  58. [self.snapshot addChildNode:self.dimming];
  59. }
  60. } else {
  61. // Remove dimming node (if not already highlighted)
  62. if (!self.isHighlighted) {
  63. [self.dimming removeFromParentNode];
  64. }
  65. }
  66. }
  67. }
  68. - (void)setForceHideHeader:(BOOL)forceHideHeader {
  69. if (_forceHideHeader != forceHideHeader) {
  70. _forceHideHeader = forceHideHeader;
  71. if (self.header.parentNode) {
  72. self.header.hidden = YES;
  73. [self.header removeFromParentNode];
  74. } else {
  75. self.header.hidden = NO;
  76. [self.snapshot addChildNode:self.header];
  77. }
  78. }
  79. }
  80. @end