private void Draw(RectangularGraph graph) { var textblock = new TextBlock { Text = graph.Content.Identificator.ToString() }; Canvas.SetLeft(textblock, graph.Content.Left); Canvas.SetTop(textblock, graph.Content.Top); var rectangle = new System.Windows.Shapes.Rectangle { Width = graph.Content.Width, Height = graph.Content.Height, Stroke = Brushes.LightBlue, StrokeThickness = 2, Tag = graph.Content }; Canvas.SetLeft(rectangle, graph.Content.Left); Canvas.SetTop(rectangle, graph.Content.Top); GraphCanvas.Children.Add(rectangle); GraphCanvas.Children.Add(textblock); if (graph.NextElements == null) { return; } foreach (var node in graph.NextElements) { Draw(node); } }
private void MapScreenChanged() { //remove rectangle overlay from old selection foreach (var child in MapScreenSelector.Children) { if (child is Rectangle) { MapScreenSelector.Children.Remove((System.Windows.UIElement)child); break; } } //for selected column add semi transparent rectangle overlay var rectOverlay = new System.Windows.Shapes.Rectangle(); rectOverlay.Fill = new SolidColorBrush(System.Windows.Media.Colors.Red); rectOverlay.Opacity = .5; rectOverlay.Stretch = Stretch.Fill; rectOverlay.Fill.Opacity = .5; MapScreenSelector.Children.Add(rectOverlay); Grid.SetColumn(rectOverlay, CurrentScreen); LoadMapScreen(CurrentScreen, ScreenWidth, ScreenHeight, false, ref MapScreen); if (CurrentScreen > 0) { LoadMapScreen(CurrentScreen - 1, ScreenWidth, ScreenHeight, false, ref MapScreenPrev); } else { //clear child elements from MapScreenPrev MapScreenPrev.Children.Clear(); } if (CurrentScreen < _layers[0].screens.Length - 1) { LoadMapScreen(CurrentScreen + 1, ScreenWidth, ScreenHeight, false, ref MapScreenNext); } else { //clear child elements from MapScreenNext MapScreenNext.Children.Clear(); } }
private void RefreshPreviewPositionRect() { if (mMainWindow == null) { return; } int HCount = (int)this.HCountSlider.Value; int VCount = (int)this.VCountSlider.Value; float Scale = (float)this.ScaleSlider.Value; float SplitX = (float)this.SplitSlider.Value; float StartPosX = (float)this.XStartSlider.Value; float StartPosY = (float)this.YStartSlider.Value; double L = (mMainWindow.MainGrid.ActualWidth - mMainWindow.PreviewImage.Width) / 2; double T = (mMainWindow.MainGrid.ActualHeight - mMainWindow.PreviewImage.Height) / 2; //Add element if not enough if (PreviewPositionRect.Count < HCount * VCount) { int RemainCount = HCount * VCount - PreviewPositionRect.Count; for (int i = 0; i < RemainCount; i++) { var newrect = new System.Windows.Shapes.Rectangle(); newrect.Stroke = System.Windows.Media.Brushes.Black; var imgBrush = new System.Windows.Media.ImageBrush(mMainWindow.PreviewImage.Source); imgBrush.TileMode = TileMode.None; imgBrush.Stretch = Stretch.None; imgBrush.AlignmentX = AlignmentX.Left; imgBrush.AlignmentY = AlignmentY.Top; newrect.Fill = imgBrush; mMainWindow.MainGrid.Children.Add(newrect); newrect.Visibility = Visibility.Visible; PreviewPositionRect.Add(newrect); } } //Remove no needed rect while (PreviewPositionRect.Count > HCount * VCount) { mMainWindow.MainGrid.Children.Remove(PreviewPositionRect.Last()); PreviewPositionRect.Remove(PreviewPositionRect.Last()); } for (int x = 0; x < HCount; x++) { for (int y = 0; y < VCount; y++) { PreviewPositionRect[x * VCount + y].Width = defaultwidth * Scale / DpiX; PreviewPositionRect[x * VCount + y].Height = defaultheight * Scale / DpiY; Thickness tmpMargin = PreviewPositionRect[x * VCount + y].Margin; PreviewPositionRect[x * VCount + y].HorizontalAlignment = HorizontalAlignment.Left; PreviewPositionRect[x * VCount + y].VerticalAlignment = VerticalAlignment.Top; tmpMargin.Left = ((SplitX + defaultwidth) * x * Scale + PreviewImg.Width * StartPosX) / DpiX + L; tmpMargin.Top = ((defaultSplitY + defaultheight) * y * Scale + PreviewImg.Height * StartPosY) / DpiY + T; PreviewPositionRect[x * VCount + y].Margin = tmpMargin; var ImgBrush = (ImageBrush)PreviewPositionRect[x * VCount + y].Fill; if (ImgBrush != null) { var tmpViewbox = ImgBrush.Viewbox; tmpViewbox.X = (PreviewPositionRect[x * VCount + y].Margin.Left - L) / mMainWindow.PreviewImage.Width; tmpViewbox.X += PreviewPositionRect[x * VCount + y].StrokeThickness / mMainWindow.PreviewImage.Width; tmpViewbox.Y = (PreviewPositionRect[x * VCount + y].Margin.Top - T) / mMainWindow.PreviewImage.Height; tmpViewbox.Y += PreviewPositionRect[x * VCount + y].StrokeThickness / mMainWindow.PreviewImage.Height; //ImgBrush.Viewport = tmpViewport; ImgBrush.Viewbox = tmpViewbox; //PreviewPositionRect[x * VCount + y].Fill = ImgBrush; } } } mMainWindow.MainGrid.UpdateLayout(); }
/// Downloads the first song in the Searchlist response list /// </summary> /// <param name="song"></param> /// <param name="index"></param> /// <param name="CurrentSong"></param> /// <returns></returns> public static async Task AutoPlaySong(int index, Label CurrentSong, WrapPanel MusicContainer, MediaElement mediaElement, System.Windows.Shapes.Rectangle Background, ChromiumWebBrowser youtubePlayer) { MusicPanel.SetIndex(index + 1); //make it play the first song if (MusicPanel.GetIndex() == MusicContainer.Children.Count - 1) { // MusicContainer.Children[GetIndex() + 1].MouseLeftButtonDown await Music.PlaySpecifiedSong(Background, mediaElement, QueryVideo.SongSearchListResponse.Items[0].Id.VideoId, index, QueryVideo.SongSearchListResponse.Items[0].Snippet.Title, CurrentSong, youtubePlayer); } //otherwise play the next song await Music.PlaySpecifiedSong(Background, mediaElement, QueryVideo.SongSearchListResponse.Items[index].Id.VideoId, index, QueryVideo.SongSearchListResponse.Items[index].Snippet.Title, CurrentSong, youtubePlayer); }
/// <summary> /// Gets the song /// </summary> #if OFFLINE_IMPLEMENTED public static async Task PlaySpecifiedSong(System.Windows.Shapes.Rectangle backgroundRect, MediaElement mediaElement, string musicLink, int index, string songTitle, Label songLabel, ChromiumWebBrowser youtubePlayer) { songLabel.Content = "Now Playing: " + songTitle; MusicPanel.IsPlaying = true; MusicPanel.SetIndex(index); if (GetMusic.IsConverting) { GetMusic.FFMpeg.Stop(); } //songLabel.Content = "Loading..."; Console.WriteLine("Music links: " + musicLink + " " + VideoId); //TODO: test for possible issue var fullSavePath = await GetMusicVideo(musicLink, youtubePlayer); ///<summary>Set the background</summary> var fileName = SongThumb.GetSongThumb( QueryVideo.SongSearchListResponse.Items[MusicPanel.GetIndex()].Snippet.Thumbnails.High.Url, Path.GetFileNameWithoutExtension(fullSavePath)); var image = System.Drawing.Image.FromFile(fileName); var blur = new GaussianBlur(image as Bitmap); var blurredThumb = blur.Process(50); image.Dispose(); var hBitmap = blurredThumb.GetHbitmap(); var backgroundImageBrush = new ImageBrush(); backgroundImageBrush.ImageSource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions() ); DeleteObject(hBitmap); blurredThumb.Dispose(); backgroundImageBrush.Stretch = Stretch.UniformToFill; backgroundRect.Fill = backgroundImageBrush; backgroundRect.Effect = null; mediaElement.Opacity = 100; var saveName = Path.GetFileName(fullSavePath); Console.WriteLine("Save name variable in PlaySpecifiedSong method " + saveName); try { var mp4SaveName = saveName.Replace(".webm", ".mp4"); fullSavePath = Path.Combine(FilePaths.SaveLocation(), mp4SaveName); //Console.WriteLine(fullSavePath); if (saveName.Contains(".webm") && !File.Exists(fullSavePath)) { songLabel.Content = "Converting..."; await GetMusic.ConvertWebmToMp4(Path.Combine(FilePaths.SaveLocation(), saveName), mp4SaveName); mediaElement.Source = new Uri(fullSavePath); } else { mediaElement.Source = new Uri(fullSavePath); } } catch (NullReferenceException nullReferenceException) { Console.WriteLine("Some how fullSavePath was not a file path..."); } Console.WriteLine(mediaElement.Source.ToString()); ///<summary>Renable this when coding in the offline mode</summary> /// //mediaElement.Play(); }