public static void PlaySong(SongBackground songID) { MediaPlayer.IsRepeating = true; MediaPlayer.Volume = fSongVolume; switch (songID) { case SongBackground.songInMenu: if (songInMenu != null) { MediaPlayer.Play(songInMenu); bIsSongInGame = false; } return; case SongBackground.songInGame: if (songInGame != null) { MediaPlayer.Play(songInGame); bIsSongInGame = true; } return; //default: // return; } }
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? } }
/// <summary> /// Helper method to save a <see cref="SongBackground"/> object to XML. /// </summary> /// <param name="background">The background object.</param> /// <returns>The path if the background is an image, otherwise the encoded color.</returns> private static string SavePowerpraiseBackground(SongBackground background) { if (background.IsFile) { return(background.FilePath); } else { return(ComputeColor(background.Color).ToString()); } }
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()); }
/// <summary> /// Helper method to load a <see cref="SongBackground"/> from XML (either an image path or a color). /// </summary> /// <param name="background">The string encoding of the background object.</param> /// <returns>The loaded background object.</returns> private static SongBackground ReadBackground(string background) { SongBackground bg; if (background == "none") { bg = new SongBackground(Color.Black); } else if (Regex.IsMatch(background, @"^\d{1,8}$")) { bg = new SongBackground(ParseColor(background)); } else { bg = new SongBackground(background, false); } return(bg); }
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); }
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; }
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(); }
/// <summary> /// Helper method to save a <see cref="SongBackground"/> object to XML. /// </summary> /// <param name="background">The background object.</param> /// <returns>The path if the background is an image, otherwise the encoded color.</returns> private static string SavePowerpraiseBackground(SongBackground background) { if (background.IsFile) return background.FilePath; else return ComputeColor(background.Color).ToString(); }
public void GotoBlankSlide(SongBackground background) { control.ExecuteJavascript("presentation.gotoBlankSlide(" + JsonConvert.SerializeObject(background) + ")"); }
/// <summary> /// Helper method to load a <see cref="SongBackground"/> from XML (either an image path or a color). /// </summary> /// <param name="background">The string encoding of the background object.</param> /// <returns>The loaded background object.</returns> private static SongBackground ReadBackground(string background) { SongBackground bg; if (background == "none") { bg = new SongBackground(Color.Black); } else if (Regex.IsMatch(background, @"^\d{1,8}$")) { bg = new SongBackground(ParseColor(background)); } else { bg = new SongBackground(background, false); } return bg; }
private void ChooseBackground(ISongElement element) { SongBackground bg = null; if (element is SongSlide) { bg = (element as SongSlide).Background; } else if (element is SongPart) { bg = (element as SongPart).Slides[0].Background; } else if (element is Song) { bg = element.Root.FirstSlide != null ? element.Root.FirstSlide.Background : element.Root.Backgrounds[0]; } else { throw new ArgumentException("element must be either Song, SongPart or SongSlide."); } var win = new ChooseBackgroundWindow(bg, element is Song); win.Owner = this.FindVisualParent <Window>(); win.ShowDialog(); if (win.DialogResult.HasValue && win.DialogResult.Value) { if (element is Song || win.ApplyToAllSlides) { var song = element.Root; song.SetBackground(win.ChosenBackground); // this needs to be called manually, because the preview can not listen to background changes // when the root node is selected this.PreviewControl.Update(); } else if (element is SongPart) { var part = element as SongPart; // only set background if it is different var bgs = part.Slides.Select(s => s.Background).Distinct(); if (bgs.Count() != 1 || !bgs.First().Equals(win.ChosenBackground)) { if (win.ChosenBackground.Type == SongBackgroundType.Video) { var res = MessageBox.Show(Resource.eMsgVideoBackgroundForElement, Resource.eMsgVideoBackgroundForElementTitle, MessageBoxButton.YesNo); if (res == MessageBoxResult.Yes) { part.Root.SetBackground(win.ChosenBackground); } } else if (part.Root.VideoBackground != null) { var res = MessageBox.Show(Resource.eMsgReplaceVideoBackground, Resource.eMsgReplaceVideoBackgroundTitle, MessageBoxButton.YesNo); if (res == MessageBoxResult.Yes) { part.Root.SetBackground(win.ChosenBackground); } } else { part.SetBackground(win.ChosenBackground); } } } else if (element is SongSlide) { var slide = element as SongSlide; if (!slide.Background.Equals(win.ChosenBackground)) { if (win.ChosenBackground.Type == SongBackgroundType.Video) { var res = MessageBox.Show(Resource.eMsgVideoBackgroundForElement, Resource.eMsgVideoBackgroundForElementTitle, MessageBoxButton.YesNo); if (res == MessageBoxResult.Yes) { slide.Root.SetBackground(win.ChosenBackground); } } else if (slide.Root.VideoBackground != null) { var res = MessageBox.Show(Resource.eMsgReplaceVideoBackground, Resource.eMsgReplaceVideoBackgroundTitle, MessageBoxButton.YesNo); if (res == MessageBoxResult.Yes) { slide.Root.SetBackground(win.ChosenBackground); } } else { slide.SetBackground(win.ChosenBackground); } } } } }