Esempio n. 1
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main drawing area, whose name is "Paper"
            canvas = this.FindName("Canvas") as Canvas;

            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            // And a photo from a file, then another that's
            // created on-the-fly instead of read from a file.

            tray         = new GImage("./tray.png");
            tray.Stretch = Stretch.None;
            canvas.Children.Add(tray);

            ball          = new GImage("./ball.png");
            ball.Stretch  = Stretch.None;
            ball.Position = initialBallPos;
            canvas.Children.Add(ball);

            shadow        = new Ellipse();
            shadow.Width  = 30.0;
            shadow.Height = 10.0;
            shadow.Fill   = new SolidColorBrush(Colors.Gray);
            shadow.Margin = new Thickness(ball.Position.X, ball.Position.Y - offset, 0.0, 0.0);
            canvas.Children.Add(shadow);

            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Esempio n. 2
0
 protected void buildDamagedImage()
 {
     byte[] pixelVector = new byte[nRows * nCols * 4];
     damaged          = new GImage(nRows, nCols, pixelVector);
     damaged.Position = new Point(-95.0, 0.0);
     updateDamagedImage();
 }
Esempio n. 3
0
        protected void getOriginalGrayscaleImage()
        {
            original = new GImage("images/mona2.jpg");

            byte[, ,] pixels      = original.GetPixelArray();
            nRows                 = original.PixelHeight();
            nCols                 = original.PixelWidth();
            byte[, ,] gPixelArray = new byte[nRows, nCols, 4];
            for (int i = 0; i < nRows; i++)
            {
                for (int j = 0; j < nCols; j++)
                {
                    int grayValue = 0;
                    for (int k = 0; k < 3; k++)
                    {
                        grayValue += pixels[i, j, k];
                    }
                    grayValue /= 3;
                    for (int k = 0; k < 3; k++)
                    {
                        gPixelArray[i, j, k] = (byte)grayValue;
                    }
                    gPixelArray[i, j, 3] = 255;
                }
            }
            original.SetPixelArray(gPixelArray, nRows, nCols);
        }
Esempio n. 4
0
        private static void PositionValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GImage myGImage = (GImage)d;

            //myGImage.setToolTip();
            //Debug.Print("Position Changed");
            myGImage.UpdateRenderTransform();
        }
Esempio n. 5
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main drawing area, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaperAlt;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            #region Triangles, segments, dots
            // A triangle, whose top point will be dragged by the slider.
            myTriangle = new Polygon();
            myTriangle.Points.Add(new Point(0, 10));
            myTriangle.Points.Add(new Point(10, 0));
            myTriangle.Points.Add(new Point(0, -10));
            myTriangle.Points.Add(new Point(-10, 0));

            myTriangle.Stroke          = Brushes.Black;
            myTriangle.StrokeThickness = 1; // 1 mm thick line
            myTriangle.Fill            = Brushes.LightSeaGreen;
            gp.Children.Add(myTriangle);

            // A draggable Dot, which is the basepoint of an arrow.
            Dot dd = new Dot(new Point(-40, 60));
            dd.MakeDraggable(gp);
            gp.Children.Add(dd);

            Circle cc = new Circle(20, 20, 20); // This circle wasn't included in the first testbed!
            gp.Children.Add(cc);

            Arrow ee = new Arrow(dd, new Point(10, 10), Arrow.endtype.END);
            gp.Children.Add(ee);

            // a dot and a segment that's attached to it; the dot is animated
            Dot p1 = new Dot(new Point(20, 20));
            gp.Children.Add(p1);
            Point   p2        = new Point(50, 50);
            Segment mySegment = new Segment(p1, p2);
            gp.Children.Add(mySegment);

            PointAnimation animaPoint1 = new PointAnimation(
                new Point(-20, -20),
                new Point(-40, 20),
                new Duration(new TimeSpan(0, 0, 5)));
            animaPoint1.AutoReverse    = true;
            animaPoint1.RepeatBehavior = RepeatBehavior.Forever;
            p1.BeginAnimation(Dot.PositionProperty, animaPoint1);
            #endregion
            #region Images

            // And a photo from a file; note that because our Y-coordinate increases "up",
            // but WPF Y-coordinates increase "down", the photo shows up inverted.
            // We'll add a second photo, right-side-up, afterwards, and a third that's
            // created on-the-fly instead of read from a file.

            myImage1          = new GImage("foo.jpg");
            myImage1.Width    = GraphPaper.wpf(200);
            myImage1.Position = new Point(10, 40);

            gp.Children.Add(myImage1);

            // Create source
            // Now add a second image, based on first building an array of color values
            // Create source array
            byte[, ,] stripes = createStripeImageArray();

            myImage2 = new GImage(stripes);

            // Establish the width and height for this image on the GraphPaper
            myImage2.Width  = GraphPaper.wpf(128);
            myImage2.Height = GraphPaper.wpf(128);

            myImage2.Position = new Point(-40, 20);
            gp.Children.Add(myImage2);

            #endregion
            #region Mesh, Quiver, and Text labels

            myMesh = this.createSampleMesh();
            gp.Children.Add(myMesh);

            Text myText = new Text("THIS IS TEXT", false); // the second arg says that y increases down
            myText.Position = new Point(20, 50);
            gp.Children.Add(myText);

            Text myText2 = new Text("THIS IS UPSIDE DOWN TEXT, because we didn't set the yUp flag to false");
            myText2.Position = new Point(-20, -50);
            gp.Children.Add(myText2);

            myQuiver = makeQuiver();
            foreach (Shape q in myQuiver)
            {
                gp.Children.Add(q);
            }

            #endregion
            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Esempio n. 6
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main drawing area, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaper;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            #region Triangles, segments, dots
            // A triangle, whose top point can be moved using the slider.
            myTriangle = new Polygon();
            myTriangle.Points.Add(new Point(0, 10));
            myTriangle.Points.Add(new Point(10, 0));
            myTriangle.Points.Add(new Point(-10, 0));
            myTriangle.Stroke          = Brushes.Black;
            myTriangle.StrokeThickness = 1; // 1 mm thick line
            myTriangle.Fill            = Brushes.LightSeaGreen;
            gp.Children.Add(myTriangle);

            // A draggable Dot, which is the basepoint of an arrow.
            Dot dd = new Dot(new Point(-40, 60));
            dd.MakeDraggable(gp);
            gp.Children.Add(dd);

            Arrow ee = new Arrow(dd, new Point(10, 10), Arrow.endtype.END);
            gp.Children.Add(ee);

            // a dot and a segment that's attached to it; the dot is animated
            Dot p1 = new Dot(new Point(20, 20));
            gp.Children.Add(p1);
            Point   p2        = new Point(50, 50);
            Segment mySegment = new Segment(p1, p2);
            gp.Children.Add(mySegment);

            PointAnimation animaPoint1 = new PointAnimation(
                new Point(-20, -20),
                new Point(-40, 20),
                new Duration(new TimeSpan(0, 0, 5)));
            animaPoint1.AutoReverse    = true;
            animaPoint1.RepeatBehavior = RepeatBehavior.Forever;
            p1.BeginAnimation(Dot.PositionProperty, animaPoint1);
            #endregion
            #region Images

            // And a photo from a file, then another that's
            // created on-the-fly instead of read from a file.

            myImage1          = new GImage("./foo.jpg");
            myImage1.Width    = GraphPaper.wpf(200);
            myImage1.Position = new Point(10, 40);
            Point pq = new Point(10, 40);

            gp.Children.Add(myImage1);

            // Now add a second image, based on first building an array of color values
            // Create source array
            byte[, ,] stripes = createStripeImageArray();

            myImage2 = new GImage(stripes);

            // Establish the width and height for this image on the GraphPaper
            myImage2.Width  = GraphPaper.wpf(128);
            myImage2.Height = GraphPaper.wpf(128);

            myImage2.Position = new Point(-40, 20);
            gp.Children.Add(myImage2);
            #endregion
            #region Mesh, Quiver, and Text labels

            myMesh = this.createSampleMesh();
            gp.Children.Add(myMesh);

            Text myText = new Text("THIS IS TEXT");
            myText.Position = new Point(20, 50);
            gp.Children.Add(myText);

            myQuiver = makeQuiver();
            foreach (Shape q in myQuiver)
            {
                gp.Children.Add(q);
            }

            #endregion
            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Esempio n. 7
0
 protected void buildRestoredImage()
 {
     byte[] pixelVector = new byte[nRows * nCols * 4];
     restored = new GImage(nRows, nCols, pixelVector);
     updateRestoredImage();
 }