Exemplo n.º 1
0
        private void DrawPanel_Paint(object sender, PaintEventArgs e)
        {
            Size DrawSize = new Size((int)(videoSize.Width * zoomFactor), (int)(videoSize.Height * zoomFactor));

            if (curMap != null)
            {
                e.Graphics.DrawImage(curMap, topPaint.X, topPaint.Y, DrawSize.Width, DrawSize.Height);
                if (listeEtapes.Count > 0)
                {
                    RouteStep init = PtToScreen((RouteStep)listeEtapes[0]);
                    //                   DrawStep(e.Graphics, init);
                    DrawIcon(e.Graphics, init);
                    RouteStep fin = null;
                    Pen       p   = new Pen(init.Color, init.LineWidth);
                    for (int i = 1; i < listeEtapes.Count; i++)
                    {
                        fin = PtToScreen((RouteStep)listeEtapes[i]);
                        Rectangle rect = new Rectangle(init.Location.X - 5, init.Location.Y - 5, 10, 10);
                        e.Graphics.DrawLine(p, init.Location, fin.Location);
                        DrawIcon(e.Graphics, init, fin);
                        init = fin;
                        //                     DrawStep(e.Graphics, init);
                        p.Dispose();
                        p = new Pen(init.Color, init.LineWidth);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private RouteStep PtToScreen(RouteStep rs)
        {
            RouteStep rst = new RouteStep(new Point((int)(rs.Location.X * hortCorrect) + topPaint.X, (int)(rs.Location.Y * vertCorrect + topPaint.Y)));

            rst.Text       = rs.Text;
            rst.LineWidth  = rs.LineWidth;
            rst.Font       = rs.Font;
            rst.FontBrush  = rs.FontBrush;
            rst.FontColor  = rs.FontColor;
            rst.Color      = rs.Color;
            rst.isSelected = rs.isSelected;
            return(rst);
        }
Exemplo n.º 3
0
        private static void DrawStep(Graphics gr, RouteStep init)
        {
            Pen pRect = new Pen(Color.Red, 2);

            if (init.isSelected)
            {
                pRect = new Pen(Color.White, 2);
            }
            gr.DrawRectangle(pRect, init.Location.X - 5, init.Location.Y - 5, 10, 10);
            if (init.Text != "")
            {
                gr.DrawString(init.Text, init.Font, init.FontBrush, new Point(init.Location.X + 2, init.Location.Y));
            }
        }
Exemplo n.º 4
0
        private void DrawIcon(Graphics gr, RouteStep init, RouteStep fin)
        {
            float x     = fin.Location.X - init.Location.X;
            float y     = fin.Location.Y - init.Location.Y;
            float slope = (float)(Math.Atan(y / x) * (180 / Math.PI));
            //     if (x < 0)                            slope += 180;
            Image nico2 = RotateImage(ico, slope + angle);
            int   xx    = fin.Location.X - nico2.Width / 2;
            int   yy    = fin.Location.Y - nico2.Height / 2;

            if (x < 0)
            {
                nico2.RotateFlip(RotateFlipType.RotateNoneFlipXY);
            }
            //     gr.DrawString(init.ToString(), new Font("Arial", 8), Brushes.Black, xx, yy);
            gr.DrawImage(nico2, xx, yy);
        }
Exemplo n.º 5
0
        private void pBox_MouseDown(object sender, MouseEventArgs e)
        {
            moving = false;
            curEt  = FindStep(e);

            Point pt = ScreenToPoint(e.Location);

            if (e.Button == MouseButtons.Left)
            {
                if (curEt == null)
                {
                    moving = false;
                    ShowControls(false);
                    RouteStep et = new RouteStep(pt);
                    listeEtapes.Add(et);
                    if (listeEtapes.Count > 1)
                    {
                        PaintImage();
                    }
                }
                else
                {
                    ShowControls(true);
                    moving = true;
                    labelColor.BackColor = curEt.Color;
                    Etiq.Text            = curEt.Text;
                    tn.Value             = curEt.LineWidth;
                    labFont.Font         = curEt.Font;
                    labFont.ForeColor    = curEt.FontColor;
                }
            }
            else
            {
                ContextMenuStrip  c = new ContextMenuStrip();
                ToolStripMenuItem m = new ToolStripMenuItem("Delete");
                m.Click += new EventHandler(m_Click);
                c.Items.Add(m);
                c.Show(this, e.Location);
            }
            PaintImage();
        }
Exemplo n.º 6
0
        private RouteStep FindStep(MouseEventArgs e)
        {
            foreach (RouteStep ext in listeEtapes)
            {
                ext.isSelected = false;
            }
            RouteStep cet  = null;
            int       acc  = 10;
            Rectangle rect = new Rectangle((int)(e.X * hortCorrect) - acc, (int)(e.Y * vertCorrect) - acc, 2 * acc, 2 * acc);

            foreach (RouteStep et in listeEtapes)
            {
                if (rect.Contains(et.Location))
                {
                    cet           = et;
                    et.isSelected = true;
                    break;
                }
            }
            return(cet);
        }
Exemplo n.º 7
0
        private void PaintImage()
        {
            pBox.Image = Image.FromFile(ImPath);
            Graphics  gr   = Graphics.FromImage(pBox.Image);
            RouteStep init = (RouteStep)listeEtapes[0];

            DrawStep(gr, init);
            RouteStep fin = null;
            Pen       p   = new Pen(init.Color, init.LineWidth);

            for (int i = 1; i < listeEtapes.Count; i++)
            {
                fin = (RouteStep)listeEtapes[i];

                Rectangle rect = new Rectangle(init.Location.X - 5, init.Location.Y - 5, 10, 10);
                gr.DrawLine(p, init.Location, fin.Location);
                init = fin;
                DrawStep(gr, init);
                p.Dispose();
                p = new Pen(init.Color, init.LineWidth);
            }
            pBox.Refresh();
        }
Exemplo n.º 8
0
 private static long StepLength(RouteStep start, RouteStep end)
 {
     return((long)Math.Sqrt((end.Location.X - start.Location.X) * (end.Location.X - start.Location.X)
                            + (end.Location.Y - start.Location.Y) * (end.Location.Y - start.Location.Y)));
 }
Exemplo n.º 9
0
        private void Generate(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.FileName = "Film.avi";
            saveFileDialog1.Filter   = "Fichier video (*.avi)|*.avi";
            if (listeEtapes.Count > 1)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string fichier = saveFileDialog1.FileName;
                    videoName = fichier;
                    AviReaderWriter aw = new AviReaderWriter();
                    try
                    {
                        uint   framePerSecond = 25;
                        Bitmap bmp            = aw.Open(fichier, framePerSecond, vidWidth, vidHeight);
                        // image de base
                        pBox.Image = Image.FromFile(ImPath);
                        Bitmap bp = new Bitmap(pBox.Image, vidWidth, vidHeight);
                        bp.RotateFlip(RotateFlipType.Rotate180FlipX);
                        aw.AddFrame(bp);
                        bp.Dispose();
                        Graphics gr = Graphics.FromImage(pBox.Image);
                        // calcul longueur totale du chemin
                        long      longTot = 0;
                        RouteStep s       = (RouteStep)listeEtapes[0];
                        for (int i = 1; i < listeEtapes.Count; i++)
                        {
                            RouteStep f = (RouteStep)listeEtapes[i];
                            longTot = longTot + StepLength(s, f);
                            s       = f;
                        }
                        RouteStep init = (RouteStep)listeEtapes[0];
                        Pen       p    = new Pen(init.Color, init.LineWidth);
                        for (int i = 1; i < listeEtapes.Count; i++)
                        {
                            RouteStep fin  = (RouteStep)listeEtapes[i];
                            long      wdEt = (long)(fin.Location.X - init.Location.X) * (fin.Location.X - init.Location.X);
                            long      htEt = (long)(fin.Location.Y - init.Location.Y) * (fin.Location.Y - init.Location.Y);
                            long      lgEt = (long)Math.Sqrt(wdEt + htEt) * (long)vidLength / longTot;
                            if (lgEt < 1)
                            {
                                lgEt = 5;
                            }
                            int d = (int)lgEt; // nombre d'images pour une étape
                                               //                                Trace.WriteLine(d);
                            float x     = fin.Location.X - init.Location.X;
                            float y     = fin.Location.Y - init.Location.Y;
                            float slope = y / x;
                            for (int j = 1; j <= d; j++)
                            {
                                long step  = (long)x * j / d;
                                long hstep = (long)(step * slope);
                                gr.DrawLine(p, init.Location.X, init.Location.Y, init.Location.X + step, init.Location.Y + hstep);
                                if (init.Text != "")
                                {
                                    gr.DrawString(init.Text, new Font("Times New Roman", 20), Brushes.White, new Point(init.Location.X + 2, init.Location.Y));
                                }
                                pBox.Refresh();
                                bp = new Bitmap(pBox.Image, vidWidth, vidHeight);
                                bp.RotateFlip(RotateFlipType.Rotate180FlipX);
                                aw.AddFrame(bp);
                                bp.Dispose();
                            }
                            init = fin;
                            p.Dispose();
                            p = new Pen(init.Color, init.LineWidth);
                        }
                        if (init.Text != "")
                        {
                            gr.DrawString(init.Text, init.Font, Brushes.White, new Point(init.Location.X + 2, init.Location.Y));
                        }
                        for (int uu = 0; uu < 10; uu++)
                        {
                            bp = new Bitmap(pBox.Image, vidWidth, vidHeight);
                            bp.RotateFlip(RotateFlipType.Rotate180FlipX);
                            aw.AddFrame(bp);
                        }
                        bp.Dispose();

                        //                       aw.Close();
                    }
                    catch (AviException ex)
                    {
                        MessageBox.Show("AVI Exception in: " + ex.ToString());
                        //                       aw.Close();
                    }
                    finally
                    {
                        aw.Close();
                    }
                }
            }
        }
Exemplo n.º 10
0
        private void Record_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog
            {
                InitialDirectory = @"D:\Documents",
                FileName         = "Film.avi",
                Filter           = "Fichier video (*.avi)|*.avi"
            };

            //        if (mediaPlayer.playState == WMPLib.WMPPlayState.wmppsPlaying)
            {
                mediaPlayer.Visible = false;
                mediaPlayer.Ctlcontrols.stop();
                mediaPlayer.close();
            }
            splitContainer1.Panel2Collapsed = false;
            curImage    = Image.FromFile(ImPath);
            curShow     = (Image)curImage.Clone();
            isRecording = true;
            Refresh();
            int imageNumber = 1;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                currentFile = saveFileDialog1.FileName;
                if (listeEtapes.Count > 1)
                {
                    #region Calcul longueur totale du chemin
                    long      longTot = 0;
                    RouteStep init    = PtToScreen(listeEtapes[0]);
                    for (int i = 1; i < listeEtapes.Count; i++)
                    {
                        RouteStep end = PtToScreen(listeEtapes[i]);
                        longTot = longTot + StepLength(init, end);
                        init    = end;
                    }
                    #endregion
                    uint            framePerSecond = 25;
                    string          fichier        = saveFileDialog1.FileName;
                    AviReaderWriter aviWriter      = new AviReaderWriter();
                    try
                    {
                        aviWriter.Open(fichier, framePerSecond, videoSize.Width, videoSize.Height);
                        // image de base
                        Bitmap bp = new Bitmap(curImage, videoSize.Width, videoSize.Height);
                        bp.RotateFlip(RotateFlipType.Rotate180FlipX);
                        aviWriter.AddFrame(bp);
                        bp.Dispose();
                        Graphics gr = Graphics.FromImage(curImage);
                        init = PtToScreen(listeEtapes[0]);
                        Pen p = new Pen(init.Color, init.LineWidth);
                        for (int i = 1; i < listeEtapes.Count; i++)
                        {
                            #region One line
                            RouteStep fin = PtToScreen(listeEtapes[i]);
                            float     x   = fin.Location.X - init.Location.X;
                            float     y   = fin.Location.Y - init.Location.Y;
                            //long largeurEtape = (long)(x * x);
                            //long hauteurEtape = (long)(y * y);
                            long longEtape = (long)Math.Sqrt((long)(x * x) + (long)(y * y)) * (long)vidLength / longTot;
                            if (longEtape < 1)
                            {
                                longEtape = 5;
                            }
                            int   d     = (int)longEtape;
                            float slope = y / x;
                            for (int j = 1; j <= d; j++)
                            {
                                #region One step
                                gr = Graphics.FromImage(curImage);
                                long step  = (long)x * j / d;
                                long hstep = (long)(step * slope);
                                if (init.Text != "")
                                {
                                    gr.DrawString(init.Text, new Font("Times New Roman", 20), Brushes.White, new Point(init.Location.X + 2, init.Location.Y));
                                }
                                RouteStep place = PtToScreen(new RouteStep(new Point((int)(init.Location.X + step), (int)(init.Location.Y + hstep))));
                                gr.DrawLine(p, place.Location.X, place.Location.Y, place.Location.X + 2, place.Location.Y + 2);
                                curShow.Dispose();
                                curShow  = (Image)curImage.Clone();
                                curIcone = (Image)curShow.Clone();
                                gr       = Graphics.FromImage(curIcone);
                                DrawIcon(gr, place, 20, 20);
                                imageNumber      += 1;
                                nombreImages.Text = imageNumber.ToString() + " image";
                                if (imageNumber > 1)
                                {
                                    nombreImages.Text += "s";
                                }
                                AddImageToFilm(aviWriter, curShow);
                                AddImageToFilm(aviWriter, curIcone);
                                //curIcone.Dispose();
                                Refresh();
                                #endregion
                            }
                            init = fin;
                            p.Dispose();
                            p = new Pen(init.Color, init.LineWidth);
                            #endregion
                        }
                        if (init.Text != "")
                        {
                            gr.DrawString(init.Text, init.Font, Brushes.White, new Point(init.Location.X + 2, init.Location.Y));
                        }
                        curShow.Dispose();
                        curShow = (Image)curImage.Clone();
                        gr      = Graphics.FromImage(curShow);
                        DrawIcon(gr, init);

                        for (int uu = 0; uu < 10; uu++)
                        {
                            AddImageToFilm(aviWriter, curIcone);
                        }
                    }
                    catch (AviException ex)
                    {
                        MessageBox.Show("AVI Exception in: " + ex.ToString());
                    }
                    finally
                    {
                        aviWriter.Close();
                    }
                }
            }
            isRecording = false;
            //splitContainer1.Panel2Collapsed = true;
        }