Example #1
0
        public BridgeBuilderForm()
        {
            InitializeComponent();
            KeyPreview = true; // needed for keyPress event to work

            int width  = pictureBox1.Width;
            int height = pictureBox1.Height;

            simulation            = new Simulation(width, height);
            interaction           = new Interaction(simulation);
            testingStress         = new TestingStress(simulation);
            simulationRenderer    = new SimulationRenderer(simulation, interaction);
            interactionRenderer   = new InteractionRenderer(interaction);
            testingStressRenderer = new TestingStressRenderer(testingStress);

            // one-way databinding (hodnoty nezmění nic jiného než GUI)
            speedUpDown.DataBindings.Add("Value", testingStress, "Speed", true, DataSourceUpdateMode.OnPropertyChanged);
            weightUpDown.DataBindings.Add("Value", testingStress, "Weight", true, DataSourceUpdateMode.OnPropertyChanged);
            simulationSpeedUpDown.DataBindings.Add("Value", this, "SimulationSpeed", true, DataSourceUpdateMode.OnPropertyChanged);

            pauseToggle.DataBindings.Add("Checked", simulation, "Pause", true, DataSourceUpdateMode.OnPropertyChanged);
            gravitationToggle.DataBindings.Add("Checked", simulation, "Gravitation", true, DataSourceUpdateMode.OnPropertyChanged);
            stressToggle.DataBindings.Add("Checked", simulationRenderer, "RenderStrain", true, DataSourceUpdateMode.OnPropertyChanged);
            snapToggle.DataBindings.Add("Checked", interaction, "SnapToGrid", true, DataSourceUpdateMode.OnPropertyChanged);

            Binding bind = new Binding("Enabled", simulation, "Pause");

            bind.Format += (sender, e) => { e.Value = !((bool)e.Value); };
            testButton.DataBindings.Add(bind);

            // two-way databinding
            roadToggle.DataBindings.Add("Checked", interaction, "PlacingRoads", true, DataSourceUpdateMode.OnPropertyChanged);
            fixingToggle.DataBindings.Add("Checked", interaction, "FixingVertices", true, DataSourceUpdateMode.OnPropertyChanged);
            addVerticesToggle.DataBindings.Add("Checked", interaction, "AddingVertices", true, DataSourceUpdateMode.OnPropertyChanged);

            db = new DoubleBuffer(width, height);

            rendererThread = new Thread(RenderLoop);
            rendererThread.Start();

            simulationThread = new Thread(UpdateLoop);
            simulationThread.Start();
        }
Example #2
0
 public TestingStressRenderer(TestingStress testingStress)
 {
     this.testingStress = testingStress;
 }