コード例 #1
0
ファイル: SongPart.cs プロジェクト: SolidStumbler/WordsLive
        /// <summary>
        /// Sets the background for every slide in the part (can be undone).
        /// </summary>
        /// <param name="bg">The background to use.</param>
        public void SetBackground(SongBackground bg)
        {
            if (!Root.Parts.Contains(this))
            {
                throw new InvalidOperationException("part has not been added to a song");
            }

            if (bg.Type == SongBackgroundType.Video)
            {
                throw new InvalidOperationException("Can't set video background to part only");
            }

            if (Root.VideoBackground != null)
            {
                throw new InvalidOperationException("Can't set background of part only if a video background is used");
            }

            using (Undo.ChangeFactory.Batch(this, "SetBackground"))
            {
                int index = Root.AddBackground(bg);

                foreach (var slide in Slides)
                {
                    slide.BackgroundIndex = index;
                }

                Root.CleanBackgrounds();
            }
        }
コード例 #2
0
ファイル: Song.cs プロジェクト: SolidStumbler/WordsLive
        /// <summary>
        /// Sets the background of every slide in the song.
        /// </summary>
        /// <param name="bg">The background to use.</param>
        public void SetBackground(SongBackground bg)
        {
            var    backup = Backgrounds.ToArray();
            Action redo   = () =>
            {
                backgrounds.Clear();
                backgrounds.Add(bg);
            };

            Action undo = () =>
            {
                backgrounds.Clear();
                foreach (var back in backup)
                {
                    backgrounds.Add(back);
                }
            };

            using (Undo.ChangeFactory.Batch(this, "SetBackground"))
            {
                backgrounds.Clear();
                backgrounds.Add(bg);

                foreach (var part in this.Parts)
                {
                    foreach (var slide in part.Slides)
                    {
                        slide.BackgroundIndex = 0;
                    }
                }

                Undo.ChangeFactory.OnChanging(this, undo, redo, "SetBackground");
            }
        }
コード例 #3
0
ファイル: Song.cs プロジェクト: SolidStumbler/WordsLive
        /// <summary>
        /// Adds the given background to the song's background list if it doesn't already exist (can be undone).
        /// </summary>
        /// <param name="bg">The background to add.</param>
        /// <param name="forceAdd">if set to <c>true</c> the background will be added even if it already exists.</param>
        /// <returns>
        /// The index of the new background.
        /// </returns>
        public int AddBackground(SongBackground bg, bool forceAdd = false)
        {
            bool contains = !forceAdd && Backgrounds.Contains(bg);

            Action redo = () =>
            {
                if (!contains)
                {
                    backgrounds.Add(bg);
                }
            };

            Action undo = () =>
            {
                if (!contains)
                {
                    backgrounds.Remove(bg);
                }
            };

            Undo.ChangeFactory.OnChanging(this, undo, redo, "AddBackground");

            if (contains)
            {
                return(Backgrounds.IndexOf(bg));
            }
            else
            {
                backgrounds.Add(bg);
                return(Backgrounds.Count - 1);
            }
        }
コード例 #4
0
        public static ImageSource CreateBackgroundSource(SongBackground bg, int width = -1)
        {
            if (bg.Type == SongBackgroundType.Image)
            {
                try
                {
                    Uri uri;
                    if (width > -1 && width <= 300)
                        uri = DataManager.Backgrounds.GetFile(bg).PreviewUri;
                    else
                        uri = DataManager.Backgrounds.GetFile(bg).Uri;

                    var img = new BitmapImage();
                    img.BeginInit();
                    img.UriSource = uri;
                    if (width > 300)
                        img.DecodePixelWidth = width;
                    img.EndInit();

                    // Without an additional frozen WritableBitmap loading locally is delayed (hangs)
                    // For remote URIs this doesn't work however, so we're not using it then
                    if (uri.IsFile)
                    {
                        WriteableBitmap writable = new WriteableBitmap(img);
                        writable.Freeze();
                        return writable;
                    }
                    else
                    {
                        return img;
                    }
                }
                catch
                {
                    return CreateColorImage(Brushes.Black);
                }
            }
            else if (bg.Type == SongBackgroundType.Color)
            {
                var c = bg.Color;
                var brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(c.A, c.R, c.G, c.B));
                return CreateColorImage(brush);
            }
            else
            {
                return CreateColorImage(Brushes.Black); // TODO: load video preview?
            }
        }
コード例 #5
0
        /// <summary>
        /// Sets the background that is assigned to this slide.
        /// </summary>
        /// <param name="bg">The background to use.</param>
        public void SetBackground(SongBackground bg)
        {
            if (bg.Type == SongBackgroundType.Video)
            {
                throw new InvalidOperationException("Can't set video background to slide only");
            }

            if (Root.VideoBackground != null)
            {
                throw new InvalidOperationException("Can't set background of slide only if a video background is used");
            }

            using (Undo.ChangeFactory.Batch(this, "SetBackground"))
            {
                int index = Root.AddBackground(bg);
                this.BackgroundIndex = index;
                Root.CleanBackgrounds();
            }
        }
コード例 #6
0
        public ChooseBackgroundWindow(SongBackground background, bool canOnlyApplyToAllSlides)
        {
            InitializeComponent();

            this.CanOnlyApplyToAllSlides = canOnlyApplyToAllSlides;

            this.DataContext = this;

            UseImage = background.IsFile;

            directoryView.DataContext = new BackgroundStorageDirectory[] { DataManager.Backgrounds.Root };

            string selectPath = String.Empty;

            if (background.IsFile)
            {
                var file = DataManager.Backgrounds.GetFile(background);
                if (file.Exists)
                {
                    selectPath = background.FilePath;
                }
                else
                {
                    MessageBox.Show(this, Resource.cbMsgNotFound, Resource.cbMsgNotFoundTitle);
                    UseColor = true;
                    ColorPicker.SelectedColor = Colors.Black;
                }
            }
            else
            {
                ColorPicker.SelectedColor = Color.FromRgb(background.Color.R, background.Color.G, background.Color.B);
            }

            RoutedEventHandler selectAction = null;
            selectAction = (sender, args) =>
            {
                SelectEntry(selectPath);
                directoryView.Loaded -= selectAction;
            };
            directoryView.Loaded += selectAction;
        }
コード例 #7
0
        private void SetResultAndClose()
        {
            if (UseImage)
            {
                var entry = (BackgroundStorageEntry)imageListView.SelectedItem;
                if (entry == null)
                {
                    MessageBox.Show(Resource.cbMsgErrNoImageSelected);
                    return;
                }

                ChosenBackground = new SongBackground(entry.Path.Substring(1).Replace('/', '\\'), entry.IsVideo);
            }
            else
            {
                ChosenBackground = new SongBackground(System.Drawing.Color.FromArgb(ColorPicker.SelectedColor.R, ColorPicker.SelectedColor.G, ColorPicker.SelectedColor.B));
            }

            this.DialogResult = true;
            this.Close();
        }
コード例 #8
0
 public void SetBackgroundUndoRedo()
 {
     Assert.Equal(System.Drawing.Color.Black.ToArgb(), slide.Background.Color.ToArgb());
     var newBg = new SongBackground(System.Drawing.Color.Red);
     slide.SetBackground(newBg);
     Assert.Equal(System.Drawing.Color.Red.ToArgb(), slide.Background.Color.ToArgb());
     Assert.Equal(1, UndoStackSize);
     Undo();
     Assert.Equal(System.Drawing.Color.Black.ToArgb(), slide.Background.Color.ToArgb());
     Redo();
     Assert.Equal(System.Drawing.Color.Red.ToArgb(), slide.Background.Color.ToArgb());
 }
コード例 #9
0
 public void GotoBlankSlide(SongBackground background)
 {
     control.ExecuteJavascript("presentation.gotoBlankSlide("+JsonConvert.SerializeObject(background)+")");
 }
コード例 #10
0
ファイル: SongSlide.cs プロジェクト: Boddlnagg/WordsLive
        /// <summary>
        /// Sets the background that is assigned to this slide.
        /// </summary>
        /// <param name="bg">The background to use.</param>
        public void SetBackground(SongBackground bg)
        {
            if (bg.Type == SongBackgroundType.Video)
            {
                throw new InvalidOperationException("Can't set video background to slide only");
            }

            if (Root.VideoBackground != null)
            {
                throw new InvalidOperationException("Can't set background of slide only if a video background is used");
            }

            using (Undo.ChangeFactory.Batch(this, "SetBackground"))
            {
                int index = Root.AddBackground(bg);
                this.BackgroundIndex = index;
                Root.CleanBackgrounds();
            }
        }
コード例 #11
0
ファイル: Song.cs プロジェクト: Boddlnagg/WordsLive
		/// <summary>
		/// Sets the background of every slide in the song.
		/// </summary>
		/// <param name="bg">The background to use.</param>
		public void SetBackground(SongBackground bg)
		{
			var backup = Backgrounds.ToArray();
			Action redo = () =>
			{
				backgrounds.Clear();
				backgrounds.Add(bg);

			};

			Action undo = () =>
			{
				backgrounds.Clear();
				foreach (var back in backup)
				{
					backgrounds.Add(back);
				}
			};

			using (Undo.ChangeFactory.Batch(this, "SetBackground"))
			{
				backgrounds.Clear();
				backgrounds.Add(bg);

				foreach (var part in this.Parts)
				{
					foreach (var slide in part.Slides)
						slide.BackgroundIndex = 0;
				}

				Undo.ChangeFactory.OnChanging(this, undo, redo, "SetBackground");
			}
		}
コード例 #12
0
ファイル: Song.cs プロジェクト: Boddlnagg/WordsLive
		/// <summary>
		/// Adds the given background to the song's background list if it doesn't already exist (can be undone).
		/// </summary>
		/// <param name="bg">The background to add.</param>
		/// <param name="forceAdd">if set to <c>true</c> the background will be added even if it already exists.</param>
		/// <returns>
		/// The index of the new background.
		/// </returns>
		public int AddBackground(SongBackground bg, bool forceAdd = false)
		{
			bool contains = !forceAdd && Backgrounds.Contains(bg);

			Action redo = () =>
			{
				if (!contains)
					backgrounds.Add(bg);
			};

			Action undo = () =>
			{
				if (!contains)
					backgrounds.Remove(bg);
			};

			Undo.ChangeFactory.OnChanging(this, undo, redo, "AddBackground");

			if (contains)
			{
				return Backgrounds.IndexOf(bg);
			}
			else
			{
				backgrounds.Add(bg);
				return Backgrounds.Count - 1;
			}
		}
コード例 #13
0
ファイル: SongPart.cs プロジェクト: Boddlnagg/WordsLive
        /// <summary>
        /// Sets the background for every slide in the part (can be undone).
        /// </summary>
        /// <param name="bg">The background to use.</param>
        public void SetBackground(SongBackground bg)
        {
            if (!Root.Parts.Contains(this))
            {
                throw new InvalidOperationException("part has not been added to a song");
            }

            if (bg.Type == SongBackgroundType.Video)
            {
                throw new InvalidOperationException("Can't set video background to part only");
            }

            if (Root.VideoBackground != null)
            {
                throw new InvalidOperationException("Can't set background of part only if a video background is used");
            }

            using (Undo.ChangeFactory.Batch(this, "SetBackground"))
            {
                int index = Root.AddBackground(bg);

                foreach (var slide in Slides)
                {
                    slide.BackgroundIndex = index;
                }

                Root.CleanBackgrounds();
            }
        }
コード例 #14
0
        public void PartSetBackgroundUndoRedo()
        {
            song.AddBackground(new SongBackground(System.Drawing.Color.Red));
            part.AddSlide();
            part.Slides[0].BackgroundIndex = 1;
            ClearUndoRedoStack();

            var newBg = new SongBackground(System.Drawing.Color.Green);

            part.SetBackground(newBg);
            Assert.Equal(newBg, song.Backgrounds.Single());
            Assert.Equal(0, part.Slides[0].BackgroundIndex);
            Assert.Equal(0, part.Slides[1].BackgroundIndex);
            Assert.Equal(1, UndoStackSize);
            Undo();
            Assert.Equal(song.Backgrounds.Count, 2);
            Assert.Equal(1, part.Slides[0].BackgroundIndex);
            Assert.Equal(0, part.Slides[1].BackgroundIndex);
        }