/// <summary>
        /// Create a keyframe and a label to host the subtitle.
        /// </summary>
        private static void AddSubtitle(Metadata metadata, int start, int end, string content)
        {
            long startTs = (long)(start * metadata.AverageTimeStampsPerSecond / 1000.0f);
            long endTs   = (long)(end * metadata.AverageTimeStampsPerSecond / 1000.0f);

            // Make sure the keyframe timestamps corresponds to an actual video frame.
            long startFrame = (long)Math.Round((float)startTs / metadata.AverageTimeStampsPerFrame);

            startTs = startFrame * metadata.AverageTimeStampsPerFrame;
            long endFrame = (long)Math.Round((float)endTs / metadata.AverageTimeStampsPerFrame);

            endTs = endFrame * metadata.AverageTimeStampsPerFrame;

            Guid   id       = Guid.NewGuid();
            long   position = startTs;
            string title    = null;
            string timecode = start.ToString();
            string comments = "";
            List <AbstractDrawing> drawings = new List <AbstractDrawing>();

            // Create a label object.
            float  top      = metadata.ImageSize.Height * 0.75f;
            PointF location = new PointF(200, top);

            DrawingText drawing = new DrawingText(location, startTs, metadata.AverageTimeStampsPerFrame, content);

            drawing.Name = "Subtitle";

            drawing.InfosFading.UseDefault                = false;
            drawing.InfosFading.ReferenceTimestamp        = position;
            drawing.InfosFading.AverageTimeStampsPerFrame = metadata.AverageTimeStampsPerFrame;
            drawing.InfosFading.AlwaysVisible             = false;
            drawing.InfosFading.OpaqueFrames              = (int)((endTs - startTs) / (float)metadata.AverageTimeStampsPerFrame);
            drawing.InfosFading.FadingFrames              = 10;

            // FIXME: there seems to be an issue with style element .Value modification.
            //StyleElementFontSize styleElement = label.DrawingStyle.Elements["font size"] as StyleElementFontSize;
            //if (styleElement != null)
            //{
            //    styleElement.Value = 24;
            //    label.DrawingStyle.RaiseValueChanged();
            //}

            drawings.Add(drawing);
            Keyframe keyframe = new Keyframe(id, position, title, timecode, comments, drawings, metadata);

            metadata.MergeInsertKeyframe(keyframe);
        }
Exemple #2
0
        public static AbstractDrawing FromXml(XmlTextReader _xmlReader, PointF _scale)
        {
            DrawingText dt = new DrawingText(0, 0, 0, 0, 0, 0);

            while (_xmlReader.Read())
            {
                if (_xmlReader.IsStartElement())
                {
                    if (_xmlReader.Name == "Text")
                    {
                        dt.m_Text = _xmlReader.ReadString();
                    }
                    else if (_xmlReader.Name == "Position")
                    {
                        Point p = XmlHelper.PointParse(_xmlReader.ReadString(), ';');
                        //dt.Background.Location = new Point(plotGrid.X, plotGrid.Y);

                        // Adapt to new Image size.
                        dt.m_BackgroundRectangle.Location = new Point((int)((float)p.X * _scale.X), (int)((float)p.Y * _scale.Y));
                    }
                    else if (_xmlReader.Name == "TextDecoration")
                    {
                        dt.m_TextStyle = InfosTextDecoration.FromXml(_xmlReader);
                    }
                    else if (_xmlReader.Name == "InfosFading")
                    {
                        dt.m_InfosFading.FromXml(_xmlReader);
                    }
                    else
                    {
                        // forward compatibility : ignore new fields.
                    }
                }
                else if (_xmlReader.Name == "Drawing")
                {
                    break;
                }
                else
                {
                    // Fermeture d'un tag interne.
                }
            }

            dt.RescaleCoordinates(dt.m_fStretchFactor, dt.m_DirectZoomTopLeft);
            dt.AutoSizeTextbox();

            return(dt);
        }
Exemple #3
0
        private void LabelAdded(object sender, DrawingEventArgs e)
        {
            //AbstractDrawing drawing, int keyframeIndex)


            DrawingText label = e.Drawing as DrawingText;

            if (label == null)
            {
                return;
            }

            label.ContainerScreen = view;
            view.Controls.Add(label.EditBox);
            label.EditBox.BringToFront();
            label.EditBox.Focus();
        }