/// <summary> /// Отображает диалоговое окно "Новый документ" и, в случае нажатия пользователем кнопки "OK" в нем, производит создание нового документа /// </summary> private void CreateNewDocument() { NewDocumentDialog newDocumentDialog = new NewDocumentDialog(); newDocumentDialog.PresetTemplates = CurrentTemplates; newDocumentDialog.Owner = this; // for WidnowsStartupLocation="CenterOwner" newDocumentDialog.ShowDialog(); if (newDocumentDialog.SelectedTemplate != null) { CurrentFilePath = null; MainCanvas.Children.Clear(); BackgroundManager backgoundManager = new BackgroundManager(newDocumentDialog.SelectedTemplate); backgoundManager.InitializeCanvas(MainCanvas); if (NoDocumentMode) { DisableNoDocumentMode(); } } }
/// <summary> /// Обрабатывает перетаскивание на данный рабочий холст элементов раскадровки и изображений-фонов с панелей инструментов /// </summary> /// <param name="eventArgs"></param> protected override void OnDrop(DragEventArgs eventArgs) { base.OnDrop(eventArgs); string xamlString; Point position = eventArgs.GetPosition(this); if ((xamlString = eventArgs.Data.GetData("STORYBOARD_ITEM") as string) != null) { FrameworkElement content = XamlReader.Load(XmlReader.Create(new StringReader(xamlString))) as FrameworkElement; if (content != null) { StoryboardItem newItem = new StoryboardItem(); newItem.Content = content; if (content.MinHeight != 0 && content.MinWidth != 0) { newItem.Width = content.MinWidth * 2;; newItem.Height = content.MinHeight * 2; } else { newItem.Width = 65; newItem.Height = 65; } SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); Children.Add(newItem); DeselectAll(); newItem.IsSelected = true; } eventArgs.Handled = true; } else if ((xamlString = eventArgs.Data.GetData("STORYBOARD_BACKGROUND") as string) != null) { Image content = XamlReader.Load(XmlReader.Create(new StringReader(xamlString))) as Image; if (content != null && BackgroundManager != null) { BackgroundManager.AddImageAt(position, content.Source); } } }
/// <summary> /// Выгружает данный документ-раскадровку на рабочий холст программы /// </summary> /// <param name="storyboardCanvas">Рабочий холст программы, на который предполагается выгрузить данный документ-раскадроку</param> public void UnloadOntoCanvas(StoryboardCanvas storyboardCanvas) { storyboardCanvas.Children.Clear(); BackgroundManager backgoundManager = new BackgroundManager(Template); backgoundManager.InitializeCanvas(storyboardCanvas); for (int i = 0; i < Template.NumFrames; i++) { if (FrameBackgrounds[i] != null) { backgoundManager.AddImageToFrame(i, FrameBackgrounds[i]); } } foreach (ItemTuple itemTuple in StoryboardItems) { Image newImage = new Image(); newImage.Source = itemTuple.Item3; newImage.IsHitTestVisible = false; StoryboardItem newItem = new StoryboardItem(); newItem.Content = newImage; Rect itemRect = itemTuple.Item1; newItem.Width = itemRect.Width; newItem.Height = itemRect.Height; Canvas.SetLeft(newItem, itemRect.X); Canvas.SetTop(newItem, itemRect.Y); newItem.RenderTransform = itemTuple.Item2; storyboardCanvas.Children.Add(newItem); } }