public UniverseOutputManager(Universe universe, IUniverseOutputUIElement universeOutputUIElement, double pixelsWidth, double pixelsHeight) { this.universe = universe; this.universeOutputUIElement = universeOutputUIElement; renderManagerMainField = new RenderManagerMainField(UniverseProperty.Width, UniverseProperty.Height, pixelsWidth, pixelsHeight); renderManagerInfoText = new RenderManagerInfoText(); universeOutputUIElement.ResolutionToReset = new Size(pixelsWidth, pixelsHeight); universeOutputUIElement.WorkDelay = PauseBetweenRender; universeOutputUIElement.CountOfCellsToGenerate = 10; StartWork(); InitializeEvents(); }
public void Dispose() { if (!IsDisposed()) { universeOutputUIElement.ImageUniverseField.MouseDown -= mouseDownOnFieldImage; StopWork(); universe = null; renderManagerMainField = null; renderManagerInfoText = null; universeOutputUIElement = null; disposed = true; } }
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(); }