Beispiel #1
0
        private void buttonOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog opendialog = new OpenFileDialog();

            opendialog.Filter = "Image files (*.TXT)| *.txt";
            if (opendialog.ShowDialog() == DialogResult.OK)
            {
                FileStream   file1  = new FileStream(opendialog.FileName, FileMode.Open); //создаем файловый поток
                StreamReader reader = new StreamReader(file1);                            // создаем «потоковый читатель» и связываем его с файловым потоком
                while (reader.Peek() >= 0)
                {
                    string str = reader.ReadLine();
                    switch (str[0])
                    {
                    case 'L':
                    {
                        Line l = new Line();
                        l.Deserialize(str);
                        listOfGraphObjects.Add(l);
                        break;
                    }

                    case 'P':
                    {
                        PolyLine l = new PolyLine();
                        l.Deserialize(str);
                        listOfGraphObjects.Add(l);
                        break;
                    }

                    case 'M':
                    {
                        Polygon l = new Polygon();
                        l.Deserialize(str);
                        listOfGraphObjects.Add(l);
                        break;
                    }

                    case 'R':
                    {
                        Rectangle l = new Rectangle();
                        l.Deserialize(str);
                        listOfGraphObjects.Add(l);
                        break;
                    }

                    case 'E':
                    {
                        Ellipse l = new Ellipse();
                        l.Deserialize(str);
                        listOfGraphObjects.Add(l);
                        break;
                    }

                    case 'C':
                    {
                        Circle l = new Circle();
                        l.Deserialize(str);
                        listOfGraphObjects.Add(l);
                        break;
                    }

                    case 'T':
                    {
                        Text l = new Text();
                        l.Deserialize(str);
                        listOfGraphObjects.Add(l);
                        break;
                    }

                    case 'B':
                    {
                        Bezier l = new Bezier();
                        l.Deserialize(str);
                        listOfGraphObjects.Add(l);
                        break;
                    }
                    }
                }
                PaintObjects();
            }
        }
Beispiel #2
0
        private void CheckGraphObject(bool bFlush)
        {
            switch (tool)
            {
            case ObjectType.Line:
                if (listOfPoints.Count == 2)
                {
                    Line l = new Line(listOfPoints[0], listOfPoints[1]);
                    listOfPoints.Clear();
                    AddGraphObject(l);
                }
                break;

            case ObjectType.PolyLine:
                if (bFlush && (listOfPoints.Count >= 2))
                {
                    PolyLine p = new PolyLine(listOfPoints);
                    listOfPoints.Clear();
                    AddGraphObject(p);
                }
                break;

            case ObjectType.Rectangle:
                if (listOfPoints.Count == 2)
                {
                    w = Math.Abs(listOfPoints[0].X - listOfPoints[1].X);
                    h = Math.Abs(listOfPoints[0].Y - listOfPoints[1].Y);
                    Rectangle r = new Rectangle(listOfPoints[0], w, h);
                    listOfPoints.Clear();
                    AddGraphObject(r);
                }
                break;

            case ObjectType.Polygon:
                if (bFlush && (listOfPoints.Count > 2))
                {
                    Polygon p = new Polygon(listOfPoints);
                    listOfPoints.Clear();
                    AddGraphObject(p);
                }
                break;

            case ObjectType.Circle:
                if (listOfPoints.Count == 2)
                {
                    if (Math.Abs(listOfPoints[1].X) > Math.Abs(listOfPoints[1].Y))
                    {
                        h = Math.Abs(listOfPoints[0].Y - listOfPoints[1].Y);
                        w = h;
                    }
                    else
                    {
                        w = Math.Abs(listOfPoints[0].X - listOfPoints[1].X);
                        h = w;
                    }

                    Ellipse c = new Ellipse(listOfPoints[0], w, h);
                    listOfPoints.Clear();
                    AddGraphObject(c);
                }
                break;

            case ObjectType.Ellipse:
                if (listOfPoints.Count == 2)
                {
                    if (Math.Abs(listOfPoints[1].X) > Math.Abs(listOfPoints[1].Y))
                    {
                        h = Math.Abs(listOfPoints[0].Y - listOfPoints[1].Y);
                        w = Math.Abs(listOfPoints[0].X - listOfPoints[1].X);
                    }
                    else
                    {
                        w = Math.Abs(listOfPoints[0].X - listOfPoints[1].X);
                        h = Math.Abs(listOfPoints[0].Y - listOfPoints[1].Y);
                    }
                    Ellipse el = new Ellipse(listOfPoints[0], w, h);
                    listOfPoints.Clear();
                    AddGraphObject(el);
                }
                break;

            case ObjectType.Text:
                if (listOfPoints.Count == 1)
                {
                    Text t = new Text(listOfPoints[0]);
                    listOfPoints.Clear();
                    AddGraphObject(t);
                }
                break;

            case ObjectType.Bezier:
                if (listOfPoints.Count == 4)
                {
                    Bezier b = new Bezier(listOfPoints);
                    listOfPoints.Clear();
                    AddGraphObject(b);
                }
                break;
            }
        }
Beispiel #3
0
        private void PaintObjects()
        {
            Bitmap   bmp = new Bitmap(@"Blank.bmp", true);
            Graphics gr  = Graphics.FromImage(bmp);

            foreach (GraphObject obj in listOfGraphObjects)
            {
                obj.Paint(gr);
            }
            switch (tool)
            {
            case ObjectType.Line:
                if (listOfPoints.Count > 0)
                {
                    Line l = new Line(listOfPoints[0], curentPoint);
                    l.PenColor     = ContourColor;
                    l.Transparancy = (byte)trackBarTransparancy.Value;
                    l.PenWidth     = (float)trackBarWidth.Value;
                    l.Transparancy = (byte)trackBarTransparancy.Value;
                    l.Paint(gr);
                }
                break;

            case ObjectType.PolyLine:
                if ((listOfPoints.Count == 1))
                {
                    Line l = new Line(listOfPoints[0], curentPoint);
                    l.PenColor     = ContourColor;
                    l.Transparancy = (byte)trackBarTransparancy.Value;
                    l.PenWidth     = (float)trackBarWidth.Value;
                    l.Transparancy = (byte)trackBarTransparancy.Value;
                    l.Paint(gr);
                }
                if ((listOfPoints.Count > 1))
                {
                    if (listOfPoints[listOfPoints.Count - 1] == mouseDown)
                    {
                        listOfPoints.RemoveAt(listOfPoints.Count - 1);
                        curentPoint = mouseDown;
                    }
                    PolyLine p = new PolyLine(listOfPoints);
                    Line     l = new Line(listOfPoints[listOfPoints.Count - 1], curentPoint);
                    p.PenColor     = ContourColor;
                    p.Transparancy = (byte)trackBarTransparancy.Value;
                    p.PenWidth     = (float)trackBarWidth.Value;
                    p.Transparancy = (byte)trackBarTransparancy.Value;
                    l.PenColor     = ContourColor;
                    l.Transparancy = (byte)trackBarTransparancy.Value;
                    l.PenWidth     = (float)trackBarWidth.Value;
                    l.Transparancy = (byte)trackBarTransparancy.Value;
                    l.Paint(gr);
                    p.Paint(gr);
                }
                break;

            case ObjectType.Rectangle:
                if (listOfPoints.Count > 0)
                {
                    if (listOfPoints.Count > 0)
                    {
                        Rectangle r = new Rectangle(listOfPoints[0], Math.Abs(listOfPoints[0].X - curentPoint.X), Math.Abs(listOfPoints[0].Y - curentPoint.Y));
                        r.PenColor     = ContourColor;
                        r.BrushColor   = BackColor;
                        r.PenWidth     = (float)trackBarWidth.Value;
                        r.Transparancy = (byte)trackBarTransparancy.Value;
                        r.Paint(gr);
                    }
                }
                break;

            case ObjectType.Polygon:
                if ((listOfPoints.Count == 1))
                {
                    Line l = new Line(listOfPoints[0], curentPoint);
                    l.PenColor     = ContourColor;
                    l.Transparancy = (byte)trackBarTransparancy.Value;
                    l.PenWidth     = (float)trackBarWidth.Value;
                    l.Transparancy = (byte)trackBarTransparancy.Value;
                    l.Paint(gr);
                }
                if ((listOfPoints.Count > 1))
                {
                    if (listOfPoints[listOfPoints.Count - 1] == mouseDown)
                    {
                        listOfPoints.RemoveAt(listOfPoints.Count - 1);
                        curentPoint = mouseDown;
                    }
                    if ((listOfPoints[listOfPoints.Count - 1].X <= listOfPoints[0].X + 3) &&
                        (listOfPoints[listOfPoints.Count - 1].X >= listOfPoints[0].X - 3) &&
                        (listOfPoints[listOfPoints.Count - 1].Y <= listOfPoints[0].Y + 3) &&
                        (listOfPoints[listOfPoints.Count - 1].Y >= listOfPoints[0].Y - 3))
                    {
                        listOfPoints.RemoveAt(listOfPoints.Count - 1);
                        CheckGraphObject(true);
                        listOfPoints.Clear();
                    }
                    else
                    {
                        PolyLine p = new PolyLine(listOfPoints);
                        Line     l = new Line(listOfPoints[listOfPoints.Count - 1], curentPoint);
                        p.PenColor     = ContourColor;
                        p.Transparancy = (byte)trackBarTransparancy.Value;
                        p.PenWidth     = (float)trackBarWidth.Value;
                        p.Transparancy = (byte)trackBarTransparancy.Value;
                        l.PenColor     = ContourColor;
                        l.Transparancy = (byte)trackBarTransparancy.Value;
                        l.PenWidth     = (float)trackBarWidth.Value;
                        l.Transparancy = (byte)trackBarTransparancy.Value;
                        l.Paint(gr);
                        p.Paint(gr);
                    }
                }
                break;

            case ObjectType.Circle:
                if (listOfPoints.Count > 0)
                {
                    if (Math.Abs(curentPoint.X) > Math.Abs(curentPoint.Y))
                    {
                        h = Math.Abs(listOfPoints[0].Y - curentPoint.Y);
                        w = h;
                    }
                    else
                    {
                        w = Math.Abs(listOfPoints[0].X - curentPoint.X);
                        h = w;
                    }

                    Ellipse c = new Ellipse(listOfPoints[0], w, h);
                    c.PenColor     = ContourColor;
                    c.BrushColor   = BackColor;
                    c.Transparancy = (byte)trackBarTransparancy.Value;
                    c.PenWidth     = (float)trackBarWidth.Value;
                    c.Transparancy = (byte)trackBarTransparancy.Value;
                    c.Paint(gr);
                }
                break;

            case ObjectType.Ellipse:
                if (listOfPoints.Count > 0)
                {
                    if (Math.Abs(curentPoint.X) > Math.Abs(curentPoint.Y))
                    {
                        h = Math.Abs(listOfPoints[0].Y - curentPoint.Y);
                        w = Math.Abs(listOfPoints[0].X - curentPoint.X);
                    }
                    else
                    {
                        w = Math.Abs(listOfPoints[0].X - curentPoint.X);
                        h = Math.Abs(listOfPoints[0].Y - curentPoint.Y);
                    }
                    Ellipse el = new Ellipse(listOfPoints[0], w, h);
                    el.PenColor     = ContourColor;
                    el.BrushColor   = BackColor;
                    el.Transparancy = (byte)trackBarTransparancy.Value;
                    el.PenWidth     = (float)trackBarWidth.Value;
                    el.Transparancy = (byte)trackBarTransparancy.Value;
                    el.Paint(gr);
                }
                break;

            case ObjectType.Text:
                if (listOfPoints.Count > 0)
                {
                    Text t = new Text(listOfPoints[0]);
                    t.TextColor    = TextColor;
                    t.Transparancy = (byte)trackBarTransparancy.Value;
                    t.text         = s;
                    t.myFont       = font1;
                    t.Paint(gr);
                    listOfPoints.Clear();
                }
                break;

            case ObjectType.Bezier:
                if (listOfPoints.Count == 4)
                {
                    Bezier b = new Bezier(listOfPoints);
                    b.PenColor     = ContourColor;
                    b.Transparancy = (byte)trackBarTransparancy.Value;
                    b.PenWidth     = (float)trackBarWidth.Value;
                    b.Transparancy = (byte)trackBarTransparancy.Value;
                    b.Paint(gr);
                }
                break;
            }
            pictureBox1.Image = bmp;
        }