public static void ShowModal(ImageSource imageSource, string title) { WindowImage window = new WindowImage(); window.Title = title; window.image.Dispatcher.Invoke(() => { window.image.Source = imageSource; window.image.Height = window.image.Source.Height; window.image.Width = window.image.Source.Width; }); window.ShowDialog(); window.Close(); }
private void button_Click(object sender, RoutedEventArgs e) { int w = 200, h = 120; double wPix = 1000, hPix = 1000; image.StretchDirection = StretchDirection.Both; image1.StretchDirection = StretchDirection.Both; MouseButtonEventHandler mouseDownOnImage = (s, ev) => { if (un != null) { //double modificator = Point pos = ev.GetPosition(s as Image); PointInt posCube = rm.GetCubePosition(pos.X, pos.Y, image.ActualWidth, image.ActualHeight); UniverseObject uo = un.GetMatrixElement(posCube.X, posCube.Y); if (uo is Cell) { WindowImage.ShowModal( ritm.DrawCellInfo(uo as Cell, 400, 20, Brushes.Black), LanguageHandler.GetInstance().CellInfoWindowTitle ); } } }; image.MouseDown += mouseDownOnImage; thr = new Thread(() => { Thread.CurrentThread.Priority = ThreadPriority.Highest; un = new Universe(w, h); un.GenerateCells(5); rm = new RenderManagerMainField(w, h, wPix, hPix); ritm = new RenderManagerInfoText(); while (thr == Thread.CurrentThread) { un.DoUniverseTick(); ImageSource img = rm.RenderField(un.GetAllDescriptors()); img.Freeze(); ImageSource info = ritm.DrawUniverseInfo(un, 300, 20, Brushes.Black); info.Freeze(); try { image.Dispatcher.Invoke(() => { image.Source = img; }); image1.Dispatcher.Invoke(() => { image1.Source = info; }); } catch { thr = null; } Thread.Sleep(30); } image.MouseDown -= mouseDownOnImage; }); AppDomain.CurrentDomain.ProcessExit += delegate { thr = null; }; thr.Start(); }
/// <summary> /// It attaches events to IUniverseOutputUIElement. /// <para></para> /// Прикрепляет к IUniverseOutputUIElement события. /// </summary> void InitializeEvents() { mouseDownOnFieldImage = (s, ev) => { try { if (UniverseProperty != null) { Image image = s as Image; Point pos = ev.GetPosition(image); PointInt posCube = RenderManagerMainFieldProperty.GetCubePosition(pos.X, pos.Y, image.ActualWidth, image.ActualHeight); UniverseObject uo = UniverseProperty.GetMatrixElement(posCube.X, posCube.Y); if (uo is Cell) { WindowImage.ShowModal( RenderManagerInfoTextProperty.DrawCellInfo(uo as Cell, maxInfoTextWidth, infoTextFontSize, Brushes.Black), LanguageHandler.GetInstance().CellInfoWindowTitle ); } } } catch { } }; universeOutputUIElement.ImageUniverseField.MouseDown += mouseDownOnFieldImage; universeOutputUIElement.OnStart = delegate { StartWork(); }; universeOutputUIElement.OnPause = delegate { PauseWorkAsync(); }; universeOutputUIElement.OnExit = delegate { Dispose(); }; universeOutputUIElement.OnOpenUniverseConstsRedactor = delegate { OpenUniverseConstsRedactor(); }; universeOutputUIElement.OnOpenFoodPlaceRedactor = delegate { OpenFoodPlaceRedactor(); }; universeOutputUIElement.OnOpenPoisonPlaceRedactor = delegate { OpenPoisonPlaceRedactor();; }; universeOutputUIElement.OnClearUniverseField = delegate { ClearUniverseField(); }; universeOutputUIElement.OnGenerateCells = delegate { if (universeOutputUIElement.CountOfCellsToGenerate != null) { GenerateCells((int)universeOutputUIElement.CountOfCellsToGenerate); } }; universeOutputUIElement.OnGenerateFoodOnAllField = delegate { GenerateFoodOnAllField(); }; universeOutputUIElement.OnResetResolution = delegate { if (universeOutputUIElement.ResolutionToReset == null) { return; } Size resolution = (Size)universeOutputUIElement.ResolutionToReset; ResetResolution(resolution.Width, resolution.Height); }; universeOutputUIElement.OnSaveUniverse = delegate { SaveUniverse(); }; universeOutputUIElement.OnGetWorkDeley = delegate { GetWorkDelay(); }; }