Пример #1
0
        /// <summary>
        /// Загружает документ-раскадровку с рабочего холста программы
        /// </summary>
        /// <param name="storyboardCanvas">Рабочий холст программы, с которой предполагается загрузить документ-раскадровку</param>
        /// <returns></returns>
        public static StoryboardDocument LoadFromCanvas(StoryboardCanvas storyboardCanvas)
        {
            StoryboardDocument newDocument = new StoryboardDocument();

            newDocument.Template = storyboardCanvas.BackgroundManager.CurrentTempalte;

            List <ImageSource> frameBackgrounds = new List <ImageSource>();

            for (int i = 0; i < storyboardCanvas.BackgroundManager.CurrentTempalte.NumFrames; i++)
            {
                frameBackgrounds.Add(storyboardCanvas.BackgroundManager.GetImageOfFrame(i));
            }

            newDocument.FrameBackgrounds = frameBackgrounds;

            List <ItemTuple> storyboardItems = new List <ItemTuple>();

            UIElement[] storyboardCanvasChildren = new UIElement[storyboardCanvas.Children.Count];

            storyboardCanvas.Children.CopyTo(storyboardCanvasChildren, 0);

            foreach (UIElement element in storyboardCanvasChildren.OrderBy(x => Panel.GetZIndex(x)))
            {
                StoryboardItem item = element as StoryboardItem;

                if (item != null)
                {
                    RotateTransform itemTransform = item.RenderTransform as RotateTransform;

                    item.RenderTransform = null;

                    Rect itemRect = new Rect();

                    itemRect.X      = Canvas.GetLeft(item);
                    itemRect.Y      = Canvas.GetTop(item);
                    itemRect.Width  = item.ActualWidth;
                    itemRect.Height = item.ActualHeight;

                    item.RenderTransform = itemTransform;

                    Image itemImageSource = (Image)item.Content;

                    ItemTuple newTuple = new ItemTuple(itemRect, itemTransform, itemImageSource.Source);

                    storyboardItems.Add(newTuple);
                }
            }

            newDocument.StoryboardItems = storyboardItems;

            return(newDocument);
        }
Пример #2
0
        /// <summary>
        /// Загружает с рабочего холста документ-раскадровку и сохраняет его по указанному пути
        /// </summary>
        /// <param name="filePath">Путь, по которому предполагается сохранить документ</param>
        void SaveDocument(string filePath)
        {
            StoryboardDocument document = StoryboardDocument.LoadFromCanvas(MainCanvas);

            try {
                using (FileStream fileStream = new FileStream(filePath, FileMode.Create)) {
                    document.SaveToXML(fileStream);
                }
            }
            catch (Exception ex) {
                MessageBox.Show(this, $"При попытке сохранения файла произошла ошибка\r\n\r\n{ex.Message}");
            }
        }
Пример #3
0
        /// <summary>
        /// Открывает документ-видеораскадровку, сохраненный в файле по заданному пути, и выгружает его на рабочий холст главного окна
        /// </summary>
        /// <param name="filePath">Путь к файлу, содержащему сохраненный документ-видеораскадровку</param>
        void OpenDocument(string filePath)
        {
            using (FileStream fileStream = new FileStream(filePath, FileMode.Open)) {
                StoryboardDocument newDocument = StoryboardDocument.LoadFromXML(fileStream);

                newDocument.UnloadOntoCanvas(MainCanvas);

                CurrentFilePath = filePath;

                if (NoDocumentMode)
                {
                    DisableNoDocumentMode();
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Загружает документ-раскадровку из потока, в котором она доступна для чтения в XML-формате (см. ПЗ)
        /// </summary>
        /// <param name="fileStream">Поток, из которого предполагается загрузить документ-раскадровку в XML-формате</param>
        /// <returns>Документ-раскадровка, загруженная из переданного потока</returns>
        public static StoryboardDocument LoadFromXML(FileStream fileStream)
        {
            StoryboardDocument newDocument = new StoryboardDocument();

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(fileStream);

            XmlNode templateNode = xmlDoc.GetElementsByTagName("BackgroundTemplate")[0];

            newDocument.Template = BackgroundTemplate.ReadFromXML(templateNode.OuterXml);

            List <ImageSource> frameBackgrounds = new List <ImageSource>();

            foreach (XmlNode backgroundNode in xmlDoc.GetElementsByTagName("StoryboardBackground"))
            {
                XmlAttribute contentAttr = backgroundNode.Attributes["Content"];

                if (contentAttr == null)
                {
                    frameBackgrounds.Add(null);
                }
                else
                {
                    frameBackgrounds.Add(Base64StringToImageSource(contentAttr.Value));
                }
            }

            newDocument.FrameBackgrounds = frameBackgrounds;

            List <ItemTuple> storyboardItems = new List <ItemTuple>();

            foreach (XmlNode itemNode in xmlDoc.GetElementsByTagName("StoryboardItem"))
            {
                Rect itemRect = new Rect();

                itemRect.X      = double.Parse(itemNode.Attributes["X"].Value);
                itemRect.Y      = double.Parse(itemNode.Attributes["Y"].Value);
                itemRect.Width  = double.Parse(itemNode.Attributes["Width"].Value);
                itemRect.Height = double.Parse(itemNode.Attributes["Height"].Value);

                BitmapImage itemImageSource;

                XmlAttribute contentAttr = itemNode.Attributes["Content"];

                if (contentAttr == null)
                {
                    itemImageSource = null;
                }
                else
                {
                    itemImageSource = Base64StringToImageSource(contentAttr.Value);
                }

                RotateTransform itemTransform = new RotateTransform();

                XmlAttribute angleAttr = itemNode.Attributes["Angle"];

                if (angleAttr != null)
                {
                    itemTransform.Angle = double.Parse(angleAttr.Value);
                }

                storyboardItems.Add(new ItemTuple(itemRect, itemTransform, itemImageSource));
            }

            newDocument.StoryboardItems = storyboardItems;

            return(newDocument);
        }