Пример #1
0
    private void SplitCanvas(int numberOfSliders, int numberOfLabels)
    {
        // Find the size of the canvas

        float heightOfCanvas = sliderCanvasTransform.sizeDelta.y;

        float width = sliderCanvasTransform.rect.width / numberOfSliders;


        float height = labelCanvasTransform.rect.height / numberOfLabels;

        // Update the sliders
        for (int i = 0; i < numberOfSliders; i++)
        {
            // Create a new Slider Item
            GameObject tmpSlider = Instantiate(sliderPrefab, sliderCanvasTransform.transform) as GameObject;

            RectTransform tmpRectTransform = tmpSlider.GetComponent <RectTransform>();

            float x = sliderCanvasTransform.rect.width / 2 + width * (i % numberOfSliders);
            float y = 0;

            tmpRectTransform.offsetMin = new Vector2(x, y);


            x = tmpRectTransform.offsetMin.x + width;
            tmpRectTransform.offsetMax = new Vector2(x - 1000, y);
            tmpRectTransform.sizeDelta = new Vector2(20f, 120f);

            // Add slider to list of active sliders
            this.activeSliders.Add(tmpSlider);
            SliderSettings sliderSettings = tmpSlider.GetComponent <SliderSettings>();
            sliderSettings.isMushra = isMushra;
            sliderSettings.SetUpIndex(i);
        }

        // Update the labels
        for (int j = 0; j < numberOfLabels; j++)
        {
            // Create a new Slider Item
            GameObject tmpLabel = Instantiate(labelPrefab, labelCanvasTransform.transform) as GameObject;

            RectTransform tmpRectTransform = tmpLabel.GetComponent <RectTransform>();

            float x = 0;
            float y = 0;

            if (j != 0)
            {
                y = height * j;
            }

            tmpRectTransform.offsetMin = new Vector2(x, y);

            y = tmpRectTransform.offsetMin.y + height;
            tmpRectTransform.offsetMax = new Vector2(x, y - 100);
            tmpRectTransform.sizeDelta = new Vector2(140f, 30f);

            this.activeLabels.Add(tmpLabel);
            LabelSettings labelSettings = tmpLabel.GetComponent <LabelSettings>();
            labelSettings.UpdateIndex(j);
        }
    }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {

                // Field
                _field = new FluidField2D(200, 200, 3);
                _field.UseCheapDiffusion = !chkUseStandardDiffusion.IsChecked.Value;

                _field.Vorticity = 0;       //this is currently broken

                // Sliders
                PropertyInfo[] propsOptions = typeof(FluidField2D).GetProperties();
                _propLinks.Add(new SliderShowValues.PropSync(trkDiffusion, propsOptions.Where(o => o.Name == "Diffusion").First(), _field, 0, .1));
                _propLinks.Add(new SliderShowValues.PropSync(trkViscocity, propsOptions.Where(o => o.Name == "Viscosity").First(), _field, 0, .1));
                _propLinks.Add(new SliderShowValues.PropSync(trkWallReflection, propsOptions.Where(o => o.Name == "WallReflectivity").First(), _field, 0, 1));
                _propLinks.Add(new SliderShowValues.PropSync(trkVorticity, propsOptions.Where(o => o.Name == "Vorticity").First(), _field, 0, 1));
                _propLinks.Add(new SliderShowValues.PropSync(trkTimestep, propsOptions.Where(o => o.Name == "TimeStep").First(), _field, 0, 100));
                _propLinks.Add(new SliderShowValues.PropSync(trkIterations, propsOptions.Where(o => o.Name == "Iterations").First(), _field, 0, 20));

                _colorBrushSize = new SliderSettings() { Min = 0, Max = .5, Value = .125 };
                _wallBrushSize = new SliderSettings() { Min = 0, Max = .1, Value = .033 };

                trkBrushSize.Minimum = _colorBrushSize.Min;
                trkBrushSize.Maximum = _colorBrushSize.Max;
                trkBrushSize.Value = _colorBrushSize.Value;

                trkVelocityMultiplier.Minimum = .1;
                trkVelocityMultiplier.Maximum = 100;        //NOTE: the right side scales from 1 to 100, but the left side scales from 1/10 to 1 (because large multipliers are more interesting)
                trkVelocityMultiplier.Value = 8;

                ResetField();

                // Create a new image
                Image img = new Image();
                RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.NearestNeighbor);
                RenderOptions.SetEdgeMode(img, EdgeMode.Aliased);

                // Add this image to the canvas
                grdFluid.Children.Add(img);

                // Create the bitmap, and set
                _bitmap = new WriteableBitmap(_field.XSize, _field.YSize, UtilityWPF.DPI, UtilityWPF.DPI, PixelFormats.Bgra32, null);

                img.Source = _bitmap;
                img.Stretch = Stretch.Fill;

                // Timer
                _timer = new DispatcherTimer();
                _timer.Interval = TimeSpan.FromMilliseconds(1);
                _timer.Tick += Timer_Tick;
                _timer.IsEnabled = true;

                // Need to manually set the scrollviewer's height (a binding can't be conditional - see Window_SizeChanged)
                expanderScrollViewer.MaxHeight = expanderRow.ActualHeight;

                _isInitialized = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Field
                _field = new FluidField2D(200, 200, 3);
                _field.UseCheapDiffusion = !chkUseStandardDiffusion.IsChecked.Value;

                _field.Vorticity = 0;       //this is currently broken

                // Sliders
                PropertyInfo[] propsOptions = typeof(FluidField2D).GetProperties();
                _propLinks.Add(new SliderShowValues.PropSync(trkDiffusion, propsOptions.Where(o => o.Name == "Diffusion").First(), _field, 0, .1));
                _propLinks.Add(new SliderShowValues.PropSync(trkViscocity, propsOptions.Where(o => o.Name == "Viscosity").First(), _field, 0, .1));
                _propLinks.Add(new SliderShowValues.PropSync(trkWallReflection, propsOptions.Where(o => o.Name == "WallReflectivity").First(), _field, 0, 1));
                _propLinks.Add(new SliderShowValues.PropSync(trkVorticity, propsOptions.Where(o => o.Name == "Vorticity").First(), _field, 0, 1));
                _propLinks.Add(new SliderShowValues.PropSync(trkTimestep, propsOptions.Where(o => o.Name == "TimeStep").First(), _field, 0, 100));
                _propLinks.Add(new SliderShowValues.PropSync(trkIterations, propsOptions.Where(o => o.Name == "Iterations").First(), _field, 0, 20));

                _colorBrushSize = new SliderSettings()
                {
                    Min = 0, Max = .5, Value = .125
                };
                _wallBrushSize = new SliderSettings()
                {
                    Min = 0, Max = .1, Value = .033
                };

                trkBrushSize.Minimum = _colorBrushSize.Min;
                trkBrushSize.Maximum = _colorBrushSize.Max;
                trkBrushSize.Value   = _colorBrushSize.Value;

                trkVelocityMultiplier.Minimum = .1;
                trkVelocityMultiplier.Maximum = 100;        //NOTE: the right side scales from 1 to 100, but the left side scales from 1/10 to 1 (because large multipliers are more interesting)
                trkVelocityMultiplier.Value   = 8;

                ResetField();

                // Create a new image
                Image img = new Image();
                RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.NearestNeighbor);
                RenderOptions.SetEdgeMode(img, EdgeMode.Aliased);

                // Add this image to the canvas
                grdFluid.Children.Add(img);

                // Create the bitmap, and set
                _bitmap = new WriteableBitmap(_field.XSize, _field.YSize, UtilityWPF.DPI, UtilityWPF.DPI, PixelFormats.Bgra32, null);

                img.Source  = _bitmap;
                img.Stretch = Stretch.Fill;

                // Timer
                _timer           = new DispatcherTimer();
                _timer.Interval  = TimeSpan.FromMilliseconds(1);
                _timer.Tick     += Timer_Tick;
                _timer.IsEnabled = true;

                // Need to manually set the scrollviewer's height (a binding can't be conditional - see Window_SizeChanged)
                expanderScrollViewer.MaxHeight = expanderRow.ActualHeight;

                _isInitialized = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }