 import AudioToolbox
 import AssetsLibrary
 
+enum GradientSaveState {
+    case Idle
+    case Saving
+    case Saved
+}
+
 class ViewController: UIViewController, UIScrollViewDelegate, UIGestureRecognizerDelegate {
     
-    let kInfoButtonSideLength : CGFloat = 44.0;
-    let kInfoButtonMargin : CGFloat = 10.0;
+    var saveState : GradientSaveState = .Idle
     
     @IBOutlet weak var scrollView : UIScrollView!
     @IBOutlet weak var gradientView : GradientView!

            btn.transform = CGAffineTransformMakeScale(0.01, 0.01)
            }, completion: { (finished : Bool) -> Void in
                btn.removeFromSuperview();
        })
    }
    

    @IBAction func handleRotation(gr : UIRotationGestureRecognizer) {
        if gr.state == .Began {
            gr.rotation = self.gradientView.rotation;
        } else if gr.state == .Changed {
            self.gradientView.rotation = gr.rotation
        }
    }
    
    @IBAction func handleTap(gr : UITapGestureRecognizer) {
        switch self.saveState {
            case .Idle:
                self.saveGradient()
            case .Saved:
                self.hideSaveIndicator()
            case .Saving:
                return // save in progress... do nothing
        }
    }
    
    func saveGradient () {
        self.saveState = .Saving
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, true, 0.0)
        self.view.drawViewHierarchyInRect(self.view.bounds, afterScreenUpdates: false)
        let screenshot = UIGraphicsGetImageFromCurrentImageContext()
