Beispiel #1
0
 public static void down(MouseButtonEventArgs e, InkPresenter inkCanvas)
 {
     inkCanvas.CaptureMouse();
     setDrawingAttributes();
     newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkCanvas));
     inkCanvas.Strokes.Add(newStroke);
 }
 private static void changeStrokeToThinnerWidth(InkPresenter inkCanvas)
 {
     for (int i = 0; i < inkCanvas.Strokes.Count; i++)
     {
         inkCanvas.Strokes[i].DrawingAttributes.Height = inkCanvas.Strokes[i].DrawingAttributes.Width = 1;
     }
 }
Beispiel #3
0
 public static void move(MouseEventArgs e, InkPresenter inkCanvas)
 {
     if (newStroke != null)
     {
         newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkCanvas));
     }
 }
Beispiel #4
0
        private static void substractSelectedArea(MouseButtonEventArgs e, InkPresenter inkCanvas, int clickedLayer, WriteableBitmap compressedBitmap, WriteableBitmap clickedBitmap)
        {
            Color targetColor = Common.getTargetColor(e, inkCanvas, compressedBitmap);

            Fill.floodFill(new Point((int)e.GetPosition(inkCanvas).X, (int)e.GetPosition(inkCanvas).Y), targetColor, Color.FromArgb(0, 0, 0, 0), compressedBitmap, clickedBitmap);
            MainPage.layerList[clickedLayer].wb = clickedBitmap;
            MainPage.layerList[clickedLayer].img.Source = clickedBitmap;
        }
        private static void keepSelectedArea(MouseButtonEventArgs e, InkPresenter inkCanvas, int clickedLayer, WriteableBitmap compressBitmap, WriteableBitmap tempBitmap, WriteableBitmap outputBitmap, ref Color targetColor, ref Color tempColor)
        {
            Fill.floodFill(new Point((int)e.GetPosition(inkCanvas).X, (int)e.GetPosition(inkCanvas).Y), targetColor, tempColor, compressBitmap, tempBitmap);
            Fill.floodFill(new Point((int)e.GetPosition(inkCanvas).X, (int)e.GetPosition(inkCanvas).Y), tempColor, targetColor, tempBitmap, outputBitmap);

            MainPage.layerList[clickedLayer].wb = outputBitmap;
            MainPage.layerList[clickedLayer].img.Source = outputBitmap;
        }
Beispiel #6
0
 public InkCollector(InkPresenter presenter)
 {
     _presenter = presenter;
     _presenter.Cursor = Cursors.Stylus;
     _presenter.MouseLeftButtonDown += new MouseButtonEventHandler(_presenter_MouseLeftButtonDown);
     _presenter.MouseMove += new MouseEventHandler(_presenter_MouseMove);
     _presenter.MouseLeftButtonUp += new MouseButtonEventHandler(_presenter_MouseLeftButtonUp);
 }
Beispiel #7
0
        public static void up(MouseButtonEventArgs e, InkPresenter inkCanvas, Grid LayoutRoot)
        {
            int clickedLayer = Common.hitTestLayer(e, inkCanvas);
            StylusPointCollection spc = new StylusPointCollection();

            checkIfStrokeSelected(e, inkCanvas, spc);

            checkIfLayerSelected(LayoutRoot, clickedLayer);
        }
Beispiel #8
0
        private static void checkIfStrokeSelected(MouseButtonEventArgs e, InkPresenter inkCanvas, StylusPointCollection spc)
        {
            spc.Add(new StylusPoint(e.GetPosition(inkCanvas).X, e.GetPosition(inkCanvas).Y));

            if (inkCanvas.Strokes.HitTest(spc).Count > 0)
            {
                removeSelectedStroke(inkCanvas, spc);
            }

            return;
        }
Beispiel #9
0
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/InkPresenter;component/Page.xaml", System.UriKind.Relative));
     this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.inkCtrl    = ((System.Windows.Controls.InkPresenter)(this.FindName("inkCtrl")));
 }
Beispiel #10
0
        public static void up(MouseButtonEventArgs e, InkPresenter inkCanvas, Color selectedColor)
        {
            int clickedLayer = Common.hitTestLayer(e, inkCanvas);
            if (clickedLayer == -1)
            {
                return;
            }

            WriteableBitmap wb1 = Common.convertToBitmap(inkCanvas);
            Color targetColor = Common.getTargetColor(e, inkCanvas, wb1);

            Fill.floodFill(new Point((int)e.GetPosition(inkCanvas).X, (int)e.GetPosition(inkCanvas).Y), targetColor, selectedColor, wb1, MainPage.layerList[clickedLayer].wb);
        }
Beispiel #11
0
 public void InitializeComponent() {
     if (_contentLoaded) {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/icehockeyWA;component/Views/Signature.xaml", System.UriKind.Relative));
     this.ContentGrid = ((System.Windows.Controls.Grid)(this.FindName("ContentGrid")));
     this.inkTest = ((System.Windows.Controls.InkPresenter)(this.FindName("inkTest")));
     this.textBox1 = ((System.Windows.Controls.TextBox)(this.FindName("textBox1")));
     this.btnUndo = ((System.Windows.Controls.Button)(this.FindName("btnUndo")));
     this.btnRedo = ((System.Windows.Controls.Button)(this.FindName("btnRedo")));
     this.btnDone = ((System.Windows.Controls.Button)(this.FindName("btnDone")));
 }
Beispiel #12
0
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/AutotauschApp;component/SignumPage.xaml", System.UriKind.Relative));
     this.LayoutRoot   = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.TitlePanel   = ((System.Windows.Controls.StackPanel)(this.FindName("TitlePanel")));
     this.Title        = ((System.Windows.Controls.TextBlock)(this.FindName("Title")));
     this.InkPresenter = ((System.Windows.Controls.InkPresenter)(this.FindName("InkPresenter")));
     this.PersonName   = ((System.Windows.Controls.TextBlock)(this.FindName("PersonName")));
 }
Beispiel #13
0
		public void SetStrokesToNull ()
		{
			InkPresenter ink = new InkPresenter();
			object strokes;
			
			// check that ReadLocalValue returns a collection after setting it to null via the property accessor
			ink.Strokes = null;
			strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.IsTrue(strokes is StrokeCollection, "ReadLocalValue after setting to null returns a collection");
			
			// check that ReadLocalValue returns a collection after SetValue to null
			ink.SetValue(InkPresenter.StrokesProperty, null);
			strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.IsTrue(strokes is StrokeCollection, "ReadLocalValue after SetValue(null) returns a collection");
		}
 public void InitializeComponent() {
     if (_contentLoaded) {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/icehockeyWA;component/Views/SignatureView.xaml", System.UriKind.Relative));
     this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.TitlePanel = ((System.Windows.Controls.StackPanel)(this.FindName("TitlePanel")));
     this.PageTitle = ((System.Windows.Controls.TextBlock)(this.FindName("PageTitle")));
     this.ContentPanel = ((System.Windows.Controls.Grid)(this.FindName("ContentPanel")));
     this.signaturePad = ((System.Windows.Controls.InkPresenter)(this.FindName("signaturePad")));
     this.btnRedo = ((System.Windows.Controls.Button)(this.FindName("btnRedo")));
     this.btnUndo = ((System.Windows.Controls.Button)(this.FindName("btnUndo")));
     this.btnCommit = ((System.Windows.Controls.Button)(this.FindName("btnCommit")));
     this.btnCancel = ((System.Windows.Controls.Button)(this.FindName("btnCancel")));
 }
Beispiel #15
0
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/PiUI;component/MousePadPage.xaml", System.UriKind.Relative));
     this.LayoutRoot     = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.MousePageTitle = ((System.Windows.Controls.TextBlock)(this.FindName("MousePageTitle")));
     this.MousePadLayout = ((System.Windows.Controls.Grid)(this.FindName("MousePadLayout")));
     this.RaspPict       = ((System.Windows.Controls.Image)(this.FindName("RaspPict")));
     this.MyIP           = ((System.Windows.Controls.InkPresenter)(this.FindName("MyIP")));
     this.CoordBox       = ((System.Windows.Controls.TextBox)(this.FindName("CoordBox")));
     this.ConnectionBox  = ((System.Windows.Controls.TextBlock)(this.FindName("ConnectionBox")));
 }
Beispiel #16
0
        public static void down(MouseButtonEventArgs e, InkPresenter inkCanvas, Grid LayoutRoot)
        {
            dragStarted = true;
            inkCanvas.CaptureMouse();

            clickedLayer = Common.hitTestLayer(e, inkCanvas);
            initialPos = e.GetPosition(inkCanvas);

            StylusPointCollection spc = new StylusPointCollection();
            spc.Add(new StylusPoint(e.GetPosition(inkCanvas).X, e.GetPosition(inkCanvas).Y));

            hitCount = inkCanvas.Strokes.HitTest(spc).Count;

            System.Diagnostics.Debug.WriteLine("layer " + clickedLayer);

            if (clickedLayer != -1)
            {

                //Calculate offset of left, right, top, bottom
                calculateOffset(e, inkCanvas);

                //System.Diagnostics.Debug.WriteLine("maxLeft " + MainPage.layerList[clickedLayer].imageToBorderDist[LEFT]);
                //System.Diagnostics.Debug.WriteLine("offSetLeft " + offSetLeft);
                //System.Diagnostics.Debug.WriteLine("positionY" + e.GetPosition(inkCanvas).Y);
                //System.Diagnostics.Debug.WriteLine("maxTop " + MainPage.layerList[clickedLayer].imageToBorderDist[TOP]);
                //System.Diagnostics.Debug.WriteLine("offSetTop " + offSetTop);

                //if the clickedLayer's image is out of bound
                if (clickedLayer != -1 && MainPage.layerList[clickedLayer].imgBackup != null)
                {
                    replaceMovingImgWithBackupImg(LayoutRoot);

                }
                else
                {
                    //temporarly save image in image backup
                    imageBackup = new WriteableBitmap((BitmapSource)MainPage.layerList[clickedLayer].img.Source);
                }

            }

            //Line clicked
            if (hitCount > 0)
            {
                moveInkToNewInkPresenter(inkCanvas, LayoutRoot, spc);
            }
        }
        internal void SaveChangesToImage(InkPresenter ImageArea)
        {
            if (this.IsEditable)
            {
                WriteableBitmap wbBitmap = new WriteableBitmap(ImageArea, new TranslateTransform());
                using (var stream = new MemoryStream())
                {
                    wbBitmap.WritePNG(stream);
                    stream.Seek(0, System.IO.SeekOrigin.Begin);
                    byte[] imageBytes = new byte[stream.Length];
                    stream.Read(imageBytes, 0, (int)stream.Length);
                    this.FeedbackImage.DataBytes = imageBytes;
                }
                ImageArea.Strokes.Clear();
            }

        }
Beispiel #18
0
        public static void up(MouseButtonEventArgs e, InkPresenter inkCanvas, Grid LayoutRoot, Color selectedColor)
        {
            int clickedLayer = Common.hitTestLayer(e, inkCanvas);

            if (clickedLayer == -1)
            {
                return;
            }

            changeStrokeToThinnerWidth(inkCanvas);

            WriteableBitmap compressedBitmap = Common.convertToBitmap(inkCanvas);
            WriteableBitmap clickedBitmap = MainPage.layerList[clickedLayer].wb;

            substractSelectedArea(e, inkCanvas, clickedLayer, compressedBitmap, clickedBitmap);

            changeStrokeToOriginalWidth(inkCanvas);
        }
Beispiel #19
0
		public void ClearValueTest()
		{
			object strokes, new_strokes, rlv_strokes;
			InkPresenter ink = new InkPresenter();
			
			// check initial value
			strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(DependencyProperty.UnsetValue, strokes, "initial strokes is not set");
			
			// now try ClearValue
			ink.ClearValue(InkPresenter.StrokesProperty);
			
			// check that ReadLocalValue returns unset
			rlv_strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(DependencyProperty.UnsetValue, rlv_strokes, "ReadLocalValue after ClearValue is unset");
			
			// check that GetValue returns a StrokeCollection
			new_strokes = ink.GetValue(InkPresenter.StrokesProperty);
			Assert.AreNotEqual(DependencyProperty.UnsetValue, new_strokes, "GetValue after a ClearValue is set");
			Assert.IsNotNull(new_strokes as StrokeCollection, "GetValue after a ClearValue does not return null");
			
			// check that ReadLocalValue still returns unset
			rlv_strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(DependencyProperty.UnsetValue, rlv_strokes, "ReadLocalValue after a GetValue still returns unset");
			
			// add a stroke
			strokes = new_strokes;
			((StrokeCollection) strokes).Add(new Stroke());
			
			// check that ReadLocalValue still returns unset
			rlv_strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(DependencyProperty.UnsetValue, rlv_strokes, "ReadLocalValue after adding a stroke still returns unset");
			
			// check that GetValue still returns the same StrokeCollection
			new_strokes = ink.GetValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(strokes, new_strokes, "strokes are the same");
			
			// set the strokes to something
			strokes = ink.Strokes = new StrokeCollection();
			
			// check that ReadLocalValue doesn't return unset anymore
			rlv_strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(strokes, rlv_strokes, "ReadLocalValue returned the strokes we just set on it");
		}
Beispiel #20
0
        public static void up(MouseButtonEventArgs e, InkPresenter inkCanvas, Color selectedColor, Grid LayoutRoot)
        {
            int clickedLayer = Common.hitTestLayer(e, inkCanvas);

            if (clickedLayer == -1)
            {
                return;
            }

            changeStrokeToThinnerWidth(inkCanvas);

            WriteableBitmap compressBitmap = Common.convertToBitmap(inkCanvas);
            WriteableBitmap tempBitmap = new WriteableBitmap(compressBitmap.PixelWidth, compressBitmap.PixelHeight);
            WriteableBitmap outputBitmap = new WriteableBitmap(compressBitmap.PixelWidth, compressBitmap.PixelHeight);
            Color targetColor = Common.getTargetColor(e, inkCanvas, compressBitmap);

            int tempR = targetColor.R;
            Color tempColor = setDifferentColor(ref targetColor, ref tempR);

            keepSelectedArea(e, inkCanvas, clickedLayer, compressBitmap, tempBitmap, outputBitmap, ref targetColor, ref tempColor);

            changeStrokeToOriginalWidth(inkCanvas);
        }
		public void Register_CustomCanvasType_Height_CustomDelegate ()
		{
			CustomCanvasType the_object = new CustomCanvasType ();
			CustomCanvasType custom_canvas = new CustomCanvasType ();
			Canvas canvas = new Canvas ();
			CustomStruct custom_struct_1 = new CustomStruct (1);
			CustomEnum custom_enum = CustomEnum.EnumValue1;
			CustomDelegate custom_delegate = delegate { };
			DependencyProperty property;
			DependencyPropertyInfo info;
			DependencyPropertyInfo.ChangedInfo changed_info;
			InkPresenter ink = new InkPresenter (); // The only builtin type derived from Canvas
			object actual_value;
			object previous_expected_value = null;
			int iterations = 0;
			int changes = 0;

			CustomCanvasType_Height_CustomDelegate = new DependencyPropertyInfo ("Height", typeof (CustomCanvasType), typeof (CustomDelegate), true);
			info = CustomCanvasType_Height_CustomDelegate;

			property = info.Property;

			Assert.AreEqual (null, the_object.GetValue (property), "Default value 1");
			Assert.AreEqual (null, ink.GetValue (property), "Default value 2");

			Assert.Throws (delegate { the_object.SetValue (property, 0); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, 1); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, ""); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, new Canvas ()); }, typeof (ArgumentException));

			foreach (object expected_value in new CustomDelegate [] { null, delegate { }, delegate { }, custom_delegate, custom_delegate }) {
				iterations++;

				the_object.SetValue (property, expected_value);
				actual_value = the_object.GetValue (property);

				if (!object.Equals (expected_value, previous_expected_value)) {
					changes++;
					changed_info = info.Changes [info.Changes.Count - 1];
					DependencyPropertyChangedEventArgs args = changed_info.args;
					Assert.AreEqual (args.OldValue, previous_expected_value, "OldValue");
					Assert.AreEqual (args.NewValue, expected_value, "NewValue");
					Assert.AreSame (changed_info.obj, the_object);
				}

				previous_expected_value = expected_value;

				Assert.AreEqual (expected_value, actual_value, "Iteration #{0}", iterations);
				Assert.AreEqual (changes, info.Changes.Count, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations, changes, info.Changes.Count);
			}
		}
		public void Register_Canvas_Custom_Canvas ()
		{
			Canvas canvas = new Canvas ();
			CustomCanvasType custom_canvas = new CustomCanvasType ();
			DependencyProperty property;
			DependencyPropertyInfo info;
			DependencyPropertyInfo.ChangedInfo changed_info;
			InkPresenter ink = new InkPresenter (); // The only builtin type derived from Canvas
			object actual_value;
			object previous_expected_value = null;
			int iterations = 0;
			int changes = 0;

			Canvas_Custom_Canvas = new DependencyPropertyInfo ("Custom", typeof (Canvas), typeof (Canvas), true);
			info = Canvas_Custom_Canvas;

			property = info.Property;

			Assert.IsNull (canvas.GetValue (property));
			Assert.IsNull (ink.GetValue (property));

			Assert.Throws (delegate { canvas.SetValue (property, 1); }, typeof (ArgumentException));
			Assert.Throws (delegate { canvas.SetValue (property, ""); }, typeof (ArgumentException));
			Assert.Throws (delegate { canvas.SetValue (property, new CustomClass ()); }, typeof (ArgumentException));

			foreach (object expected_value in new object [] { null, new Canvas (), null, canvas, canvas, null, new CustomCanvasType (), custom_canvas, custom_canvas, ink }) {
				iterations++;

				canvas.SetValue (property, expected_value);
				actual_value = canvas.GetValue (property);

				if (expected_value != previous_expected_value) {
					changes++;
					changed_info = info.Changes [info.Changes.Count - 1];
					DependencyPropertyChangedEventArgs args = changed_info.args;
					Assert.AreSame (args.OldValue, previous_expected_value);
					Assert.AreSame (args.NewValue, expected_value);
					Assert.AreSame (changed_info.obj, canvas);
				}

				previous_expected_value = expected_value;

				Assert.AreSame (expected_value, actual_value, "Iteration #{0}", iterations);
				Assert.AreEqual (changes, info.Changes.Count, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations, changes, info.Changes.Count);
			}
		}
		WriteableBitmap GetImage (Color strokeColor, Color fillColor, Size size, float scale, bool shouldCrop = true)
		{
			if (size.Width == 0 || size.Height == 0 || scale <= 0 || strokeColor == null ||
			    fillColor == null)
				return null;

			float uncroppedScale;
			Size uncroppedSize;
			Rect croppedRectangle;

			if (shouldCrop && Points.Count () > 0) {
				croppedRectangle = getCroppedRectangle ();
				double scaleX = croppedRectangle.Width / size.Width;
				double scaleY = croppedRectangle.Height / size.Height;
				uncroppedScale = (float) (1 / Math.Max (scaleX, scaleY));
				uncroppedSize = getSizeFromScale (uncroppedScale, size);
			} else {
				uncroppedScale = scale;
				uncroppedSize = size;
			}

			InkPresenter presenter = new InkPresenter () { 
				Width = ActualWidth, 
				Height = ActualHeight, 
				Strokes = new StrokeCollection (),
 				Background = new SolidColorBrush (fillColor)
			};
			foreach (Stroke stroke in strokes) {
				stroke.DrawingAttributes.Color = strokeColor;
				presenter.Strokes.Add (stroke);
			}
			WriteableBitmap bitmap = new WriteableBitmap (presenter, new ScaleTransform () { ScaleX = uncroppedScale, ScaleY = uncroppedScale });
			
			if (shouldCrop) {
				croppedRectangle = getCroppedRectangle ();
				Rect scaledRectangle;
				scaledRectangle = new Rect (croppedRectangle.X * uncroppedScale,
				                            croppedRectangle.Y * uncroppedScale,
				                            size.Width,
				                            size.Height);
				if (scaledRectangle.X >= 5) {
					scaledRectangle.X -= 5;
					scaledRectangle.Width += 5;
				}
				if (scaledRectangle.Y >= 5) {
					scaledRectangle.Y -= 5;
					scaledRectangle.Height += 5;
				}
				if (scaledRectangle.X + scaledRectangle.Width <= uncroppedSize.Width - 5)
					scaledRectangle.Width += 5;
				if (scaledRectangle.Y + scaledRectangle.Height <= uncroppedSize.Height - 5)
					scaledRectangle.Height += 5;

				
				bitmap = crop (bitmap, scaledRectangle);
			}
			
			return bitmap;
		}
Beispiel #24
0
        public static void findNewImageToBorderDist(Image image, MouseButtonEventArgs e, InkPresenter inkCanvas, int clickedLayer, double offSetLeft, double offSetRight, double offSetTop, double offSetBottom, double maxLeft, double maxRight, double maxTop, double maxBottom)
        {
            if (maxLeft == 0 || maxRight == 0 || maxTop == 0 || maxBottom == 0)
            {
                return;
            }

            MainPage.layerList[clickedLayer].imageToBorderDist[LEFT] = e.GetPosition(inkCanvas).X - offSetLeft;
            MainPage.layerList[clickedLayer].imageToBorderDist[RIGHT] = e.GetPosition(inkCanvas).X + offSetRight;
            MainPage.layerList[clickedLayer].imageToBorderDist[TOP] = e.GetPosition(inkCanvas).Y - offSetTop;
            MainPage.layerList[clickedLayer].imageToBorderDist[BOTTOM] = e.GetPosition(inkCanvas).Y + offSetBottom;
        }
Beispiel #25
0
        public static WriteableBitmap convertToBitmap(InkPresenter inkCanvas)
        {
            WriteableBitmap wb = new WriteableBitmap((int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight);
            for (int i = 0; i < MainPage.layerList.Count; i++)
            {
                wb.Render(MainPage.layerList[i].img, new TranslateTransform());
            }

            wb.Render(inkCanvas, new TranslateTransform());
            wb.Invalidate();
            return wb;
        }
Beispiel #26
0
 private static void removeSelectedStroke(InkPresenter inkCanvas, StylusPointCollection spc)
 {
     inkCanvas.Strokes.Remove(inkCanvas.Strokes.HitTest(spc)[inkCanvas.Strokes.HitTest(spc).Count - 1]);
 }
		public void Register_CustomCanvasType2_Height_double ()
		{
			CustomCanvasType2 the_object = new CustomCanvasType2 ();
			CustomCanvasType custom_canvas = new CustomCanvasType ();
			Canvas canvas = new Canvas ();
			DependencyProperty property;
			DependencyPropertyInfo info;
			DependencyPropertyInfo.ChangedInfo changed_info;
			InkPresenter ink = new InkPresenter (); // The only builtin type derived from Canvas
			object actual_value;
			object previous_expected_value = (double) 0;
			int iterations = 0;
			int changes = 0;

			CustomCanvasType2_Height_double = new DependencyPropertyInfo ("Height", typeof (CustomCanvasType2), typeof (double), true);
			info = CustomCanvasType2_Height_double;

			property = info.Property;

			Assert.AreEqual (0.0, (double) the_object.GetValue (property));
			Assert.AreEqual (0.0, (double) ink.GetValue (property));
			Assert.AreEqual (0.0, (double) custom_canvas.GetValue (property));

			Assert.Throws (delegate { the_object.SetValue (property, 1); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, ""); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, null); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, new Canvas ()); }, typeof (ArgumentException));

			//Assert.Throws (delegate { custom_canvas.SetValue (property, 1.1); }, typeof (ArgumentException));

			foreach (object expected_value in new object [] { 1.1 }) {
				iterations++;

				the_object.SetValue (property, expected_value);
				actual_value = the_object.GetValue (property);

				if ((double) expected_value != (double) previous_expected_value) {
					changes++;
					changed_info = info.Changes [info.Changes.Count - 1];
					DependencyPropertyChangedEventArgs args = changed_info.args;
					Assert.AreEqual ((double) args.OldValue, (double) previous_expected_value);
					Assert.AreEqual ((double) args.NewValue, (double) expected_value);
					Assert.AreSame (changed_info.obj, the_object);
				}

				previous_expected_value = expected_value;

				Assert.AreEqual ((double) expected_value, (double) actual_value, "Iteration #{0}", iterations);
				Assert.AreEqual (changes, info.Changes.Count, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations, changes, info.Changes.Count);
			}
		}
Beispiel #28
0
        // Code to execute when the application is activated (brought to foreground)
        // This code will not execute when the application is first launched
        private void Application_Activated(object sender, ActivatedEventArgs e)
        {
            if (PhoneApplicationService.Current.State.ContainsKey("inkXML"))
            {
                XElement inkXML;
                inkStrokes = new InkPresenter();
                inkXML= PhoneApplicationService.Current.State["inkXML"] as XElement;
                if (inkXML != null)
                {
                    inkStrokes.Strokes = XMLHelpers.XMLtoSrokes(inkXML);
                }
                PhoneApplicationService.Current.State.Remove("inkXML");
             }

            if (PhoneApplicationService.Current.State.ContainsKey("inkColor"))
            {
                inkDA.Color = (Color)PhoneApplicationService.Current.State["inkColor"];
                PhoneApplicationService.Current.State.Remove("inkColor");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("inkOutlineColor"))
            {
                inkDA.OutlineColor = (Color)PhoneApplicationService.Current.State["inkOutlineColor"];
                PhoneApplicationService.Current.State.Remove("inkOutlineColor");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("inkWidth"))
            {
                inkDA.Width = (double)PhoneApplicationService.Current.State["inkWidth"];
                PhoneApplicationService.Current.State.Remove("inkWidth");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("inkHeight"))
            {
                inkDA.Height = (double)PhoneApplicationService.Current.State["inkHeight"];
                PhoneApplicationService.Current.State.Remove("inkHeight");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("CustomColor"))
            {
                CustomColor = (bool)PhoneApplicationService.Current.State["CustomColor"];
                PhoneApplicationService.Current.State.Remove("CustomColor");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("CustomBrush1"))
            {
                CustomBrush1 = (Color)PhoneApplicationService.Current.State["CustomBrush1"];
                PhoneApplicationService.Current.State.Remove("CustomBrush1");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("CustomBrush2"))
            {
                CustomBrush2 = (Color)PhoneApplicationService.Current.State["CustomBrush2"];
                PhoneApplicationService.Current.State.Remove("CustomBrush2");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("CustomBrush3"))
            {
                CustomBrush3 = (Color)PhoneApplicationService.Current.State["CustomBrush3"];
                PhoneApplicationService.Current.State.Remove("CustomBrush3");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("CustomBrush4"))
            {
                CustomBrush4 = (Color)PhoneApplicationService.Current.State["CustomBrush4"];
                PhoneApplicationService.Current.State.Remove("CustomBrush4");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("CustomBrush5"))
            {
                CustomBrush5 = (Color)PhoneApplicationService.Current.State["CustomBrush5"];
                PhoneApplicationService.Current.State.Remove("CustomBrush5");
            }

            if (PhoneApplicationService.Current.State.ContainsKey("CustomBrush6"))
            {
                CustomBrush6 = (Color)PhoneApplicationService.Current.State["CustomBrush6"];
                PhoneApplicationService.Current.State.Remove("CustomBrush6");
            }

            try
            {
                WBMP = IsolatedStorageHelper.GetImage(IsolatedStorageHelper.LoadIfExists(IMGID));
                customBG=true;
            }
            catch
            {
                customBG=false;
            }

            BrushSize = (int)inkDA.Width;
            BrushColor = inkDA.Color;
        }
Beispiel #29
0
 public static Color getTargetColor(MouseButtonEventArgs e, InkPresenter inkCanvas, WriteableBitmap wb)
 {
     return wb.GetPixel((int)e.GetPosition(inkCanvas).X, (int)e.GetPosition(inkCanvas).Y);
 }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ImgSqaure1 = ((System.Windows.Controls.Image)(target));

            #line 67 "..\..\..\Vistas-Controladores\ColorPicker.xaml"
                this.ImgSqaure1.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Swatch_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 2:
                this.ImgSqaure2 = ((System.Windows.Controls.Image)(target));

            #line 76 "..\..\..\Vistas-Controladores\ColorPicker.xaml"
                this.ImgSqaure2.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Swatch_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 3:
                this.ImgCircle1 = ((System.Windows.Controls.Image)(target));

            #line 83 "..\..\..\Vistas-Controladores\ColorPicker.xaml"
                this.ImgCircle1.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Swatch_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 4:
                this.ColorImage = ((System.Windows.Controls.Image)(target));
                return;

            case 5:
                this.CanvImage = ((System.Windows.Controls.Canvas)(target));

            #line 133 "..\..\..\Vistas-Controladores\ColorPicker.xaml"
                this.CanvImage.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.CanvImage_MouseDown);

            #line default
            #line hidden

            #line 135 "..\..\..\Vistas-Controladores\ColorPicker.xaml"
                this.CanvImage.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.CanvImage_MouseUp);

            #line default
            #line hidden

            #line 137 "..\..\..\Vistas-Controladores\ColorPicker.xaml"
                this.CanvImage.MouseMove += new System.Windows.Input.MouseEventHandler(this.CanvImage_MouseMove);

            #line default
            #line hidden
                return;

            case 6:
                this.ellipsePixel = ((System.Windows.Shapes.Ellipse)(target));
                return;

            case 7:
                this.previewPresenter = ((System.Windows.Controls.InkPresenter)(target));
                return;

            case 8:
                this.txtAlpha = ((System.Windows.Controls.TextBox)(target));
                return;

            case 9:
                this.txtAlphaHex = ((System.Windows.Controls.TextBox)(target));
                return;

            case 10:
                this.txtRed = ((System.Windows.Controls.TextBox)(target));
                return;

            case 11:
                this.txtRedHex = ((System.Windows.Controls.TextBox)(target));
                return;

            case 12:
                this.txtGreen = ((System.Windows.Controls.TextBox)(target));
                return;

            case 13:
                this.txtGreenHex = ((System.Windows.Controls.TextBox)(target));
                return;

            case 14:
                this.txtBlue = ((System.Windows.Controls.TextBox)(target));
                return;

            case 15:
                this.txtBlueHex = ((System.Windows.Controls.TextBox)(target));
                return;

            case 16:
                this.txtAll = ((System.Windows.Controls.TextBox)(target));
                return;

            case 17:
                this.AlphaBorder = ((System.Windows.Controls.Border)(target));
                return;

            case 18:
                this.AlphaSlider = ((System.Windows.Controls.Slider)(target));

            #line 372 "..\..\..\Vistas-Controladores\ColorPicker.xaml"
                this.AlphaSlider.ValueChanged += new System.Windows.RoutedPropertyChangedEventHandler <double>(this.AlphaSlider_ValueChanged);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
Beispiel #31
0
 public static int hitTestLayer(MouseButtonEventArgs e, InkPresenter inkCanvas)
 {
     for (int i = MainPage.layerList.Count - 1; i >= 0; i--)
     {
         if (getTargetColor(e, inkCanvas, MainPage.layerList[i].wb) != Color.FromArgb(0, 0, 0, 0))
         {
             return i;
         }
     }
     return -1;
 }
Beispiel #32
0
        public static void calculateMax(Image image, MouseButtonEventArgs e, InkPresenter inkCanvas, int clickedLayer)
        {
            clickedLayer = Common.hitTestLayer(e, inkCanvas);

            if (clickedLayer == -1)
            {
                return;
            }

            WriteableBitmap wb = MainPage.layerList[clickedLayer].wb;

            //max left and right
            for (int w = 0; w < MainPage.layerList[clickedLayer].wb.PixelWidth; w++)
            {
                for (int h = 0; h < MainPage.layerList[clickedLayer].wb.PixelHeight; h++)
                {
                    if (wb.GetPixel(w, h) != Color.FromArgb(0, 0, 0, 0) && !flag1)
                    {
                        flag1 = true;
                        MainPage.layerList[clickedLayer].imageToBorderDist[LEFT] = w;
                    }

                    if (wb.GetPixel(w, h) != Color.FromArgb(0, 0, 0, 0) && flag1)
                    {
                        flag2 = true;
                    }
                }

                if (flag1 && !flag2)
                {
                    MainPage.layerList[clickedLayer].imageToBorderDist[RIGHT] = w;
                    break;
                }

                flag2 = false;
            }

            flag1 = false;
            flag2 = false;

            //max top and bottom
            for (int h = 0; h < MainPage.layerList[clickedLayer].wb.PixelHeight; h++)
            {
                for (int w = 0; w < MainPage.layerList[clickedLayer].wb.PixelWidth; w++)
                {
                    if (wb.GetPixel(w, h) != Color.FromArgb(0, 0, 0, 0) && !flag1)
                    {
                        flag1 = true;
                        MainPage.layerList[clickedLayer].imageToBorderDist[TOP] = h;
                    }

                    if (wb.GetPixel(w, h) != Color.FromArgb(0, 0, 0, 0) && flag1)
                    {
                        flag2 = true;
                    }
                }

                if (flag1 && !flag2)
                {
                    MainPage.layerList[clickedLayer].imageToBorderDist[BOTTOM] = h;
                    break;
                }

                flag2 = false;
            }

            flag1 = false;
            flag2 = false;
        }
 public WhiteInkPresenterPeer(InkPresenter owner)
     : base(owner)
 {
     whitePeer = WhitePeer.Create(this, owner);
 }
Beispiel #34
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 31 "..\..\ColorPicker.xaml"
                ((System.Windows.Controls.Grid)(target)).MouseWheel += new System.Windows.Input.MouseWheelEventHandler(this.AlphaSlider_MouseWheel);

            #line default
            #line hidden

            #line 31 "..\..\ColorPicker.xaml"
                ((System.Windows.Controls.Grid)(target)).MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.CanvasImage_MouseUp);

            #line default
            #line hidden
                return;

            case 2:
                this.ImgSqaure1 = ((System.Windows.Controls.Image)(target));

            #line 46 "..\..\ColorPicker.xaml"
                this.ImgSqaure1.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Swatch_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 3:
                this.ImgSqaure2 = ((System.Windows.Controls.Image)(target));

            #line 50 "..\..\ColorPicker.xaml"
                this.ImgSqaure2.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Swatch_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 4:
                this.ImgCircle1 = ((System.Windows.Controls.Image)(target));

            #line 54 "..\..\ColorPicker.xaml"
                this.ImgCircle1.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Swatch_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 5:
                this.MainGrid = ((System.Windows.Controls.Grid)(target));

            #line 57 "..\..\ColorPicker.xaml"
                this.MainGrid.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.CanvasImage_MouseDown);

            #line default
            #line hidden

            #line 58 "..\..\ColorPicker.xaml"
                this.MainGrid.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.CanvasImage_MouseUp);

            #line default
            #line hidden
                return;

            case 6:
                this.ColorImage = ((System.Windows.Controls.Image)(target));
                return;

            case 7:
                this.canvasImage = ((System.Windows.Controls.Canvas)(target));

            #line 91 "..\..\ColorPicker.xaml"
                this.canvasImage.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.CanvasImage_MouseDown);

            #line default
            #line hidden

            #line 92 "..\..\ColorPicker.xaml"
                this.canvasImage.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.CanvasImage_MouseUp);

            #line default
            #line hidden

            #line 93 "..\..\ColorPicker.xaml"
                this.canvasImage.MouseMove += new System.Windows.Input.MouseEventHandler(this.CanvasImage_MouseMove);

            #line default
            #line hidden
                return;

            case 8:
                this.ellipsePixel = ((System.Windows.Shapes.Ellipse)(target));
                return;

            case 9:

            #line 105 "..\..\ColorPicker.xaml"
                ((System.Windows.Controls.StackPanel)(target)).MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.CanvasImage_MouseDown);

            #line default
            #line hidden

            #line 105 "..\..\ColorPicker.xaml"
                ((System.Windows.Controls.StackPanel)(target)).MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.CanvasImage_MouseUp);

            #line default
            #line hidden
                return;

            case 10:
                this.previewPresenter = ((System.Windows.Controls.InkPresenter)(target));

            #line 116 "..\..\ColorPicker.xaml"
                this.previewPresenter.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.CanvasImage_MouseDown);

            #line default
            #line hidden

            #line 117 "..\..\ColorPicker.xaml"
                this.previewPresenter.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.CanvasImage_MouseUp);

            #line default
            #line hidden
                return;

            case 11:
                this.txtAlpha = ((System.Windows.Controls.TextBox)(target));
                return;

            case 12:
                this.txtAlphaHex = ((System.Windows.Controls.TextBox)(target));
                return;

            case 13:
                this.txtRed = ((System.Windows.Controls.TextBox)(target));
                return;

            case 14:
                this.txtRedHex = ((System.Windows.Controls.TextBox)(target));
                return;

            case 15:
                this.txtGreen = ((System.Windows.Controls.TextBox)(target));
                return;

            case 16:
                this.txtGreenHex = ((System.Windows.Controls.TextBox)(target));
                return;

            case 17:
                this.txtBlue = ((System.Windows.Controls.TextBox)(target));
                return;

            case 18:
                this.txtBlueHex = ((System.Windows.Controls.TextBox)(target));
                return;

            case 19:
                this.txtAll = ((System.Windows.Controls.TextBox)(target));
                return;

            case 20:
                this.AlphaBorder = ((System.Windows.Controls.Border)(target));

            #line 209 "..\..\ColorPicker.xaml"
                this.AlphaBorder.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(this.AlphaSlider_MouseWheel);

            #line default
            #line hidden
                return;

            case 21:
                this.AlphaSlider = ((System.Windows.Controls.Slider)(target));

            #line 220 "..\..\ColorPicker.xaml"
                this.AlphaSlider.ValueChanged += new System.Windows.RoutedPropertyChangedEventHandler <double>(this.AlphaSlider_ValueChanged);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
Beispiel #35
0
        public static void checkIfOutOfBound(MouseButtonEventArgs e, InkPresenter inkCanvas, Image img, int clickedLayer, WriteableBitmap imageBackup, double offSetLeft, double offSetRight, double offSetTop, double  offSetBottom, double maxLeft, double maxRight, double maxTop, double maxBottom)
        {
            double test = e.GetPosition(inkCanvas).X;
            if ( test - offSetLeft <= 0 || maxLeft == 0)
            {
                System.Diagnostics.Debug.WriteLine("left out");
                MainPage.layerList[clickedLayer].imgBackup = imageBackup;
                Point newPoint = new Point(img.Margin.Left, img.Margin.Top);
                MainPage.layerList[clickedLayer].imageBackupOffset = newPoint;

            }
            else if (e.GetPosition(inkCanvas).X + offSetRight >= MainPage.layerList[clickedLayer].wb.PixelWidth || maxRight == 0)
            {
                System.Diagnostics.Debug.WriteLine("right out");
                MainPage.layerList[clickedLayer].imgBackup = imageBackup;
                Point newPoint = new Point(img.Margin.Left, img.Margin.Top);
                MainPage.layerList[clickedLayer].imageBackupOffset = newPoint;
            }
            else if (e.GetPosition(inkCanvas).Y - offSetTop <= 0 || maxTop == 0)
            {
                System.Diagnostics.Debug.WriteLine("top out");
                MainPage.layerList[clickedLayer].imgBackup = imageBackup;
                Point newPoint = new Point(img.Margin.Left, img.Margin.Top);
                MainPage.layerList[clickedLayer].imageBackupOffset = newPoint;
            }
            else if (e.GetPosition(inkCanvas).Y + offSetBottom >= MainPage.layerList[clickedLayer].wb.PixelHeight || maxBottom == 0)
            {
                System.Diagnostics.Debug.WriteLine("bottom out");
                MainPage.layerList[clickedLayer].imgBackup = imageBackup;
                Point newPoint = new Point(img.Margin.Left, img.Margin.Top);
                MainPage.layerList[clickedLayer].imageBackupOffset = newPoint;
            }
        }