コード例 #1
0
ファイル: FirstPage.xaml.cs プロジェクト: 35T4N0R/Grafika
        private void LoadCanvas_Click(object sender, RoutedEventArgs e)
        {
            List <JsonObject> objects        = new List <JsonObject>();
            OpenFileDialog    openFileDialog = new OpenFileDialog();

            openFileDialog.CheckFileExists = true;
            openFileDialog.ShowDialog();

            if (openFileDialog.FileName.Trim() != string.Empty)
            {
                using (StreamReader r = new StreamReader(openFileDialog.FileName))
                {
                    string jsonString = r.ReadToEnd();
                    objects = JsonConvert.DeserializeObject <List <JsonObject> >(jsonString);
                }
            }
            foreach (var obj in objects)
            {
                if (obj.shapeType.Equals("Line"))
                {
                    var newLine = new myLine(new Point((double)obj.x1, (double)obj.y1), new Point((double)obj.x2, (double)obj.y2));
                    _pen.Down(newLine);
                }
                else if (obj.shapeType.Equals("Rectangle"))
                {
                    var newRectangle = new myRectangle(new Point((double)obj.x1, (double)obj.y1), new Point((double)obj.x1 + (double)obj.width, (double)obj.y1 + (double)obj.height));
                    _pen.Down(newRectangle);
                }
                else if (obj.shapeType.Equals("Ellipse"))
                {
                    var newCricle = new myCircle(new Point((double)obj.x1 + (double)obj.r, (double)obj.y1 + (double)obj.r), (double)obj.r);
                    _pen.Down(newCricle);
                }
            }
        }
コード例 #2
0
ファイル: FirstPage.xaml.cs プロジェクト: 35T4N0R/Grafika
        public void rysujButton_Click(object sender, RoutedEventArgs e)
        {
            switch (currentShape)
            {
            case Shapes.Line:
                if (!checkInputs(Shapes.Line))
                {
                    var newLine = new myLine(new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x1")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y1")).Text)),
                                             new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x2")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y2")).Text)));

                    _pen.Down(newLine);
                }
                break;

            case Shapes.Rectangle:
                if (!checkInputs(Shapes.Rectangle))
                {
                    var newRectangle = new myRectangle(new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x1")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y1")).Text)),
                                                       new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x2")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y2")).Text)));

                    _pen.Down(newRectangle);
                }
                break;

            case Shapes.Circle:
                if (!checkInputs(Shapes.Circle))
                {
                    var newCricle = new myCircle(new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x1")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y1")).Text)),
                                                 Convert.ToDouble(((TextBox)this.inputs.FindName("r")).Text));

                    _pen.Down(newCricle);
                }
                break;

            default:
                break;
            }
        }