public void SetValueAt(double xPixel, double yPixel, double stretchedWidth, double stretchedHeight, bool value) { PointInt positionCube = renderManager.GetCubePosition(xPixel, yPixel, stretchedWidth, stretchedHeight); if (!(positionCube.X >= 0 && positionCube.X < width && positionCube.Y >= 0 && positionCube.Y < height)) { return; } SetValueAt(positionCube.X, positionCube.Y, value); }
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(); }