private void PositionTextChanged(object sender, TextChangedEventArgs e) { TextBox currentTextBox = (TextBox)sender; bool changed = false; if (this.previousTextBox == currentTextBox) { try { Double.Parse(currentTextBox.Text, CultureInfo.InvariantCulture); if (currentTextBox.Text.Contains(',')) { currentTextBox.Text = currentTextBox.Text.Replace(',', '.'); } } catch (Exception) { if (!(currentTextBox.Text == "-" || currentTextBox.Text == "")) { currentTextBox.Text = previousString; changed = true; } } } if (!changed && selected != null) { try { double value = Double.Parse(currentTextBox.Text, CultureInfo.InvariantCulture) * CANVAS_SCALE; if (selected.GetType() == typeof(Ellipse)) { value = value - (selected.Width / 2.0); } if (currentTextBox.Name == "positionX") { if (currentView != View.RIGHT) { if (Canvas.GetLeft(selected) != value) { Canvas.SetLeft(selected, value); } } } if (currentTextBox.Name == "positionY") { if (currentView != View.TOP) { if (Canvas.GetTop(selected) != value) { Canvas.SetTop(selected, value); } } } if (currentTextBox.Name == "positionZ") { if (currentView == View.TOP) { if (Canvas.GetTop(selected) != value) { Canvas.SetTop(selected, value); } } else if (currentView == View.RIGHT) { if (Canvas.GetLeft(selected) != value) { Canvas.SetLeft(selected, value); } } } if (currentTextBox.Name == "rectangleWidth") { if (currentView != View.RIGHT) { selected.Width = value; } } if (currentTextBox.Name == "rectangleHeight") { if (currentView != View.TOP) { selected.Height = value; } } if (currentTextBox.Name == "rectangleDepth") { if (currentView == View.TOP) { selected.Height = value; } else if (currentView == View.RIGHT) { selected.Width = value; } } if (currentTextBox.Name == "diameter") { selected.Width = selected.Height = Double.Parse(currentTextBox.Text, CultureInfo.InvariantCulture) * CANVAS_SCALE; } UpdatePositionValues(selected); } catch (Exception) { } } this.previousTextBox = (TextBox)sender; }
private double GetX(Shape shape) { return(Canvas.GetLeft(shape) / CANVAS_SCALE); }
private void UpdatePositionValues(Shape shape) { if (currentView == View.FRONT) { if (shape.GetType() == typeof(Rectangle)) { Rectangle rectangle = (Rectangle)shape; RayTracer.Block block = (RayTracer.Block)objects[rectangle.Name]; double x = GetX(rectangle); double y = GetY(rectangle); block.SetPosition((float)x, (float)y, block.a.Z, (float)(rectangle.Width / CANVAS_SCALE), (float)(rectangle.Height / CANVAS_SCALE), block.getDepth()); } else if (shape.GetType() == typeof(Ellipse)) { Ellipse ellipse = (Ellipse)shape; RayTracer.Sphere sphere = (RayTracer.Sphere)objects[ellipse.Name]; double x = (Canvas.GetLeft(ellipse) + (ellipse.Width / 2)) / CANVAS_SCALE; double y = (Canvas.GetTop(ellipse) + (ellipse.Height / 2)) / CANVAS_SCALE; sphere.xPos = (float)x; sphere.yPos = (float)y; sphere.diameter = (float)(ellipse.Width / CANVAS_SCALE); } } else if (currentView == View.TOP) { if (shape.GetType() == typeof(Rectangle)) { Rectangle rectangle = (Rectangle)shape; RayTracer.Block block = (RayTracer.Block)objects[rectangle.Name]; double x = GetX(rectangle); double z = GetY(rectangle); block.SetPosition((float)x, block.a.Y, (float)z, (float)(rectangle.Width / CANVAS_SCALE), block.getHeight(), (float)(rectangle.Height / CANVAS_SCALE)); } else if (shape.GetType() == typeof(Ellipse)) { Ellipse ellipse = (Ellipse)shape; RayTracer.Sphere sphere = (RayTracer.Sphere)objects[ellipse.Name]; double x = (Canvas.GetLeft(ellipse) + (ellipse.Width / 2)) / CANVAS_SCALE; double z = (Canvas.GetTop(ellipse) + (ellipse.Height / 2)) / CANVAS_SCALE; sphere.xPos = (float)x; sphere.zPos = (float)z; sphere.diameter = (float)(ellipse.Width / CANVAS_SCALE); } } else if (currentView == View.RIGHT) { if (shape.GetType() == typeof(Rectangle)) { Rectangle rectangle = (Rectangle)shape; RayTracer.Block block = (RayTracer.Block)objects[rectangle.Name]; double z = GetX(rectangle); double y = GetY(rectangle); block.SetPosition(block.a.X, (float)y, (float)z, block.getWidth(), (float)(rectangle.Height / CANVAS_SCALE), (float)(rectangle.Width / CANVAS_SCALE)); } else if (shape.GetType() == typeof(Ellipse)) { Ellipse ellipse = (Ellipse)shape; RayTracer.Sphere sphere = (RayTracer.Sphere)objects[ellipse.Name]; double z = (Canvas.GetLeft(ellipse) + (ellipse.Width / 2)) / CANVAS_SCALE; double y = (Canvas.GetTop(ellipse) + (ellipse.Height / 2)) / CANVAS_SCALE; sphere.zPos = (float)z; sphere.yPos = (float)y; sphere.diameter = (float)(ellipse.Width / CANVAS_SCALE); } } }