示例#1
0
 public Canvas(RectangleF frame, UIInterfaceOrientation orientation, Crayon [] crayons, List<UIImage> swatches)
     : base(frame)
 {
     this.orientation = orientation;
     this.crayons = crayons;
     this.swatches = swatches;
     BackgroundColor = UIColor.White;
 }
        public override void LoadView()
        {
            base.LoadView ();

            //get the latest selected crayon
            foreach (var crayon in Application.Crayons) {
                if(crayon.Selected)
                    selectedCrayon = crayon;
            }

            //load our swatches (transparent, colorless pngs that we then add color to, and use as a textured brush)
            var swatchesDirectory = Path.Combine (NSBundle.MainBundle.BundlePath, "Swatches");
            swatches = new List<UIImage>();
            foreach (var swatchFile in Directory.EnumerateFiles (swatchesDirectory)) {
                var swatch = UIImage.FromFile (swatchFile);
                if (swatch == null) {
                    Application.Log ("WARN: couldn't load swatch: {0}", swatchFile);
                    continue;
                }
                swatches.Add(swatch);
            }

            //make our brush size slider
            swatchSlider = new UISlider(new RectangleF(50, 30, 250, 50));
            swatchSlider.MinValue = 1;
            swatchSlider.MaxValue = 40;
            swatchSlider.Value = 10;
            swatchSlider.MinimumTrackTintColor = UIColor.FromRGB(selectedCrayon.R/255f, selectedCrayon.G/255f, selectedCrayon.B/255f);
            swatchSlider.MaximumTrackTintColor = UIColor.LightGray;

            //generate our clear and save buttons
            //TODO: this should happen in a split-view, so the user can show and hide
            redoButton = UIButton.FromType(UIButtonType.RoundedRect);
            saveButton = UIButton.FromType(UIButtonType.RoundedRect);
            redoButton.Frame = new RectangleF(100, 825, 200, 100);
            saveButton.Frame = new RectangleF(400, 825, 200, 100);
            redoButton.SetTitle ("Start Over", UIControlState.Normal);
            saveButton.SetTitle ("I'm Done!", UIControlState.Normal);
            redoButton.TouchUpInside += ClearCanvas;
            saveButton.TouchUpInside += SaveAsImage;

            //TODO: manage slider position wrt screen orientation
            canvas = new Canvas (UIScreen.MainScreen.ApplicationFrame, InterfaceOrientation, Application.Crayons, swatches);
            canvas.Background = image;
            canvas.swatchSlider = swatchSlider;

            canvas.AddSubviews (swatchSlider, redoButton, saveButton);

            //load this puppy
            View = canvas;
        }
示例#3
0
 public static void SaveCrayons(string fileName, Crayon [] crayons)
 {
     using (var stream = File.Create (fileName))
         Serializer.Serialize (stream, crayons);
 }
示例#4
0
        void DrawCrayon(CGContext context, Crayon crayon)
        {
            // I <3 Paintcode

            //// Color Declarations
            var gradientColor  = UIColor.FromRGBA(crayon.R / 255f, crayon.G / 255f, crayon.B / 255f, 1.00f);
            var gradientColor2 = UIColor.FromRGBA(crayon.R / 255f, crayon.G / 255f, crayon.B / 255f, 0.69f);
            var gradientColor3 = UIColor.FromRGBA(crayon.R / 255f, crayon.G / 255f, crayon.B / 255f, 0.37f);

            //// Gradient Declarations
            var gradientColors = new CGColor [] {
                gradientColor.CGColor,
                gradientColor2.CGColor,
                gradientColor3.CGColor,
                gradientColor2.CGColor,
                gradientColor.CGColor
            };
            var gradientLocations = new float [] {0, 0.37f, 0.66f, 1, 1};
            var gradient = new CGGradient(colorSpace, gradientColors, gradientLocations);

            //// Rectangle Drawing
            var rectanglePath = UIBezierPath.FromRoundedRect(new RectangleF(0.5f, 20.5f, 25, 100), UIRectCorner.TopLeft | UIRectCorner.TopRight, new SizeF(8, 8));
            context.SaveState();
            rectanglePath.AddClip();
            context.DrawLinearGradient(gradient, new PointF(0.5f, 70.5f), new PointF(25.5f, 70.5f), 0);
            context.RestoreState();

            //// Bezier Drawing
            UIBezierPath bezierPath = new UIBezierPath();
            bezierPath.MoveTo(new PointF(3.5f, 24.5f));
            bezierPath.AddCurveToPoint(new PointF(12, 0.09f), new PointF(6.5f, 17.57f), new PointF(9.79f, -4.27f));
            bezierPath.AddCurveToPoint(new PointF(22.5f, 24.5f), new PointF(16.3f, 8.57f), new PointF(22.5f, 24.5f));
            context.SaveState();
            bezierPath.AddClip();
            context.DrawLinearGradient(gradient, new PointF(3.5f, 12.01f), new PointF(22.5f, 12.01f), 0);
            context.RestoreState();
        }
示例#5
0
        public override void TouchesMoved(NSSet touchSet, UIEvent evt)
        {
            var touches = touchSet.ToArray<UITouch> ();
            if (touchedCrayon != null) {
                if (touches.All (touch => GetTouchingCrayon (touch) == null))
                    touchedCrayon = null;
                return;
            }

            AddPoint (touches);
        }
示例#6
0
        /******Touches******/
        public override void TouchesBegan(NSSet touchSet, UIEvent evt)
        {
            var touches = touchSet.ToArray<UITouch> ();
            foreach (var touch in touches) {
                touchedCrayon = GetTouchingCrayon (touch);
                if (touchedCrayon != null)
                     return;
            }

            AddPoint (touches);
        }