Example #1
0
 public Shape(Shape shape)
 {
     this.Height = shape.Height;
     this.Width = shape.Width;
     this.Location = shape.Location;
     this.Rectangle = shape.rectangle;
     this.FillColor =  shape.FillColor;
     this.LineColor = shape.LineColor;
     this.LineWidth = shape.LineWidth;
     this.TransformMatrix = shape.TransformMatrix;
 }
Example #2
0
        private RectangleShape CreateFrame(Shape shape)
        {
            RectangleF rect = shape.Rectangle;
            byte frameOffset = 5;
            float frameMargin = shape.LineWidth / 2 + frameOffset;
            rect.Inflate(frameMargin, frameMargin);

            RectangleShape frame = new RectangleShape(rect);
            frame.LineWidth = 2;
            frame.LineColor = Color.Black;
            frame.Transparency = 0;
            return frame;
        }
Example #3
0
 private void AddShape(Shape shape)
 {
     shapeNumber++;
     shape.ID = shapeNumber;
     IsChanged = true;
     Shapes.Add(shape);
 }
Example #4
0
 private void Form1_MouseDown(object sender, MouseEventArgs e)
 {
     pt1 = e.Location;
     Pen pen = new Pen(penColor, penWidth);
     shape = Shape.CreateShape(currentShape, pt1, pen);
 }
Example #5
0
        private void readShapesFileAsText(StreamReader reader)
        {
            // String rawText = reader.ReadToEnd();
            //parse text

            while(reader.Peek()>0)
            {

                String line = reader.ReadLine();
                string type =line.Split(new char[0])[0];
                //Shape shape=null;
                //using the global shape obj he added

                switch (type)
                {
                    case "Line":
                        shape = new Line();
                        shape.readText(line);
                        break;
                    case "FreeLine":

                        shape = new FreeLine();
                        shape.readText(line);
                        break;
                    case "Rect":
                        shape = new Rect();
                        shape.readText(line);
                        break;

                }

                shapeList.Add(shape);

            }
        }
Example #6
0
        private void readShapesFileAsBin(BinaryReader br)
        {
            while (br.PeekChar() > -1)
            {
                String line = br.ReadString();

                string type = line.Split(new char[0])[0];

                switch (type)
                {
                    case "Line":
                        shape = new Line();
                        shape.readText(line);
                        break;
                    case "FreeLine":

                        shape = new FreeLine();
                        shape.readText(line);
                        break;
                    case "Rect":
                        shape = new Rect();
                        shape.readText(line);
                        break;

                }

                shapeList.Add(shape);

            }
        }
Example #7
0
 private void RemoveFromSelection(Shape shape)
 {
     dialogProcessor.Selection.Remove(shape);
 }
Example #8
0
 private void AddToSelection(Shape shape)
 {
     dialogProcessor.Selection.Add(shape);
 }
Example #9
0
 private void LoadShapeProperties(Shape shape)
 {
     SetXY();
     tbWidth.Text = shape.Width.ToString();
     tbHeight.Text = shape.Height.ToString();
     btnLineColor.BackColor = shape.LineColor;
     btnFillColor.BackColor = shape.FillColor;
     numericLineWidth.Value = shape.LineWidth;
     transperancyTextBox.Text = shape.Transparency.ToString();
     transperancyTrackBar.Value = shape.Transparency;
 }
Example #10
0
 private void EditShapeProperties(Shape shape)
 {
     if (shape != null)
     {
         EditShapePropertiesForm frmEditShapePropertiesForm = new EditShapePropertiesForm(shape);
         if (frmEditShapePropertiesForm.ShowDialog() == DialogResult.OK)
         {
             LoadShapeProperties(shape);
         }
     }
 }
Example #11
0
        private void ClickOnShape(Shape shape)
        {
            statusBar.Items[0].Text = "Last action: Click on shape";

            if ((ModifierKeys & Keys.Control) == Keys.Control)
            {
                if (dialogProcessor.Selection.Contains(shape))
                {
                    RemoveFromSelection(shape);
                }
                else
                {
                    AddToSelection(shape);
                }
            }
            else
            {
                dialogProcessor.Selection.Clear();
                AddToSelection(shape);
            }

            dialogProcessor.IsDragging = true;
        }
Example #12
0
        private void openMenuItem_Click(object sender, EventArgs e)
        {
            //Open Menu & check condition
            if (dataModified)
            {
                // Offer to save drawing & display dialog
                DialogResult dialogResult = MessageBox.Show("Do you want to save changes?", "Form1", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                switch (dialogResult)
                {
                    case DialogResult.Yes: writeFile(currentFile);
                        break;
                    case DialogResult.No: reset();
                        this.CreateGraphics().Clear(Form1.ActiveForm.BackColor);
                        break;
                    case DialogResult.Cancel: return;
                }
            }

            //open dialog
            String line = null;
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Text files(*.txt)|*.txt|Binary Files(*.bin)|*.bin|Serialized files(*.ser)|*.ser|XML files(*.xml)|*.xml|All files(*.*)|*.*";
            dlg.InitialDirectory = Directory.GetCurrentDirectory();

            if (dlg.ShowDialog() == DialogResult.Cancel)
                return;

            reset();
            this.CreateGraphics().Clear(Form1.ActiveForm.BackColor);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                currentFile = dlg.FileName;
                //FileStream fs = new FileStream(currentFile, FileMode.Open);
                FileInfo fileInfo = new FileInfo(dlg.FileName);
                Graphics graphics = this.CreateGraphics();

                // check for text files & selecting the shape
                if (fileInfo.Extension == ".txt")
                {
                    FileStream fs = new FileStream(currentFile, FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    while ((line = sr.ReadLine()) != null)
                    {
                        switch (line)
                        {
                            case "Line": currentShapeType = ShapeType.Line;
                                break;
                            case "Rect": currentShapeType = ShapeType.Rectangle;
                                break;
                            case "FreeLine": currentShapeType = ShapeType.FreeLine;
                                break;
                            case "Text": currentShapeType = ShapeType.Text;
                                break;
                        }
                        shape = Shape.CreateShape(currentShapeType);

                        shape.readText(sr);
                        shape.Draw(graphics);
                        shapeList.Add(shape);
                    }
                    sr.Close();
                    fs.Close();
                }
                // Check for bin files & selecting encoding
                else if (fileInfo.Extension == ".bin")
                {
                    FileStream fs = new FileStream(currentFile, FileMode.Open);
                    BinaryReader br = new BinaryReader(fs);

                    switch (br.ReadString())
                    {
                        case "us-ascii":
                            Shape.TextEncodingType = Encoding.ASCII;
                            break;
                        case "utf-8":
                            Shape.TextEncodingType = Encoding.UTF8;
                            break;
                        case "u\0t\0f\0-\01\06\0":
                            Shape.TextEncodingType = Encoding.Unicode;
                            break;
                        case "u\0\0\0t\0\0\0f\0\0\0-\0\0\03\0\0\02\0\0\0":
                            Shape.TextEncodingType = Encoding.UTF32;
                            break;
                        case "\0u\0n\0i\0c\0o\0d\0e\0F\0F\0F\0E":
                            Shape.TextEncodingType = Encoding.BigEndianUnicode;
                            break;
                        case "utf-7":
                            Shape.TextEncodingType = Encoding.UTF7;
                            break;
                    }

                    br = new BinaryReader(fs, Shape.TextEncodingType);

                    int length = (int)br.BaseStream.Length;
                    MessageBox.Show(length.ToString());
                    while (br.PeekChar() != -1)
                    {
                        // Selecting shape for bin file & recreating the figures
                        switch (br.ReadString())
                        {
                            case "Line":
                                currentShapeType = ShapeType.Line;
                                shape = Shape.CreateShape(currentShapeType);
                                shape.readBinary(br);
                                shape.Draw(graphics);
                                shapeList.Add(shape);
                                break;

                            case "Rect":
                                currentShapeType = ShapeType.Rectangle;
                                shape = Shape.CreateShape(currentShapeType);
                                shape.readBinary(br);
                                shape.Draw(graphics);
                                shapeList.Add(shape);
                                break;

                            case "FreeLine":
                                currentShapeType = ShapeType.FreeLine;
                                shape = Shape.CreateShape(currentShapeType);
                                shape.readBinary(br);
                                shape.Draw(graphics);
                                shapeList.Add(shape);
                                break;

                            case "Text":
                                currentShapeType = ShapeType.Text;
                                shape = Shape.CreateShape(currentShapeType);
                                shape.readBinary(br);
                                shape.Draw(graphics);
                                shapeList.Add(shape);
                                break;
                        }
                    }
                    fs.Close();
                }
                else if (fileInfo.Extension == ".ser")
                {

                    FileStream fs = new FileStream(currentFile, FileMode.Open);
                    BinaryFormatter bf = new BinaryFormatter();
                    shapeList = (List<Shape>)bf.Deserialize(fs);

                    foreach (Shape shape in shapeList)

                        shape.Draw(graphics);
                    fs.Close();
                }//end ser
                else if (fileInfo.Extension == ".xml")
                {

                    XDocument document = XDocument.Load(currentFile);
                    XElement root = document.Root;
                    foreach (XElement xe in root.Elements())
                    {
                        switch (xe.Name.ToString())
                        {
                            case "Line": currentShapeType = ShapeType.Line;
                                break;
                            case "Rect": currentShapeType = ShapeType.Rectangle;
                                break;
                            case "FreeLine": currentShapeType = ShapeType.FreeLine;
                                break;
                            case "Text": currentShapeType = ShapeType.Text;
                                break;
                        }
                        shape = Shape.CreateShape(currentShapeType);
                        foreach (XElement xee in xe.Elements())
                        {
                            shape.readXmlElement(xee);
                        }

                        shape.Draw(graphics);

                        shapeList.Add(shape);
                        //fs1.Close();
                    }// End  xml
                }
            }
        }
Example #13
0
 private void Form1_MouseDown(object sender, MouseEventArgs e)
 {
     if (currentShapeType == ShapeType.None)
     {
         MessageBox.Show("Must select shape type");
         return;
     }
     pt1 = e.Location;
     Console.WriteLine("currentShapeType = {0}", currentShapeType);
     shape = Shape.CreateShape(currentShapeType);
     shape.Pt1 = pt1;
     shape.PenColor = Color.Black;
     //shape.Pen = penTemp;
     Shape.MouseIsDown = true;
     Shape.CurrentShape = shape;
 }
Example #14
0
 public virtual void DrawShape(Graphics grfx, Shape item)
 {
     item.DrawSelf(grfx);
 }
 public EditShapePropertiesForm(Shape originalShape)
 {
     InitializeComponent();
     shape = originalShape;
     EnagleOrDisableCoordinates();
 }