Пример #1
0
        /// <summary>
        ///     Handles the SelectedIndexChanged event of the _styleManagerTypeCmb control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        /// <exception cref="System.InvalidOperationException"></exception>
        private void _styleManagerTypeCmb_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBoxValue <Type> val = (ComboBoxValue <Type>)_styleManagerTypeCmb.SelectedItem;

            TilingController controller = _tilingController;

            if (controller == null)
            {
                return;
            }
            lock (_lock)
            {
                controller = _tilingController;
                if (controller == null)
                {
                    return;
                }

                StyleManager currManager = controller.StyleManager;
                if (currManager.GetType() == val.Value)
                {
                    return;
                }

                StyleManager newManager;

                if (val.Value == typeof(RandomStyleManager))
                {
                    newManager = new RandomStyleManager((int)_seedNum.Value, currManager.LineStyle, currManager.Styles);
                }
                else if (val.Value == typeof(RandomGreedyStyleManager))
                {
                    newManager = new RandomGreedyStyleManager(
                        (int)_seedNum.Value,
                        currManager.LineStyle,
                        currManager.Styles);
                }
                else if (val.Value == typeof(GreedyStyleManager))
                {
                    newManager = new GreedyStyleManager(1, 1, 1, currManager.LineStyle, currManager.Styles);
                }
                else if (val.Value == typeof(SimpleStyleManager))
                {
                    // TODO filter styles properly when multiple shapes are supported
                    newManager = new SimpleStyleManager(currManager.LineStyle, currManager.Styles.First());
                }
                else
                {
                    throw new InvalidOperationException();
                }

                Debug.Assert(newManager.GetType() == val.Value);

                controller.Tiling.SetStyleManager(newManager, controller.Tiles);
                UpdateStyleManager(newManager);
            }
        }
Пример #2
0
        /// <summary>
        ///     Handles the ValueChanged event of the _seedNum control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void _seedNum_ValueChanged(object sender, EventArgs e)
        {
            RandomStyleManager manager = _tilingController?.StyleManager as RandomStyleManager;

            if (manager == null)
            {
                return;
            }

            manager.Seed = (int)_seedNum.Value;
        }
Пример #3
0
        /// <summary>
        ///     Updates the style manager that the UI controls.
        /// </summary>
        /// <param name="manager">The manager.</param>
        private void UpdateStyleManager([NotNull] StyleManager manager)
        {
            Debug.Assert(manager != null, "manager != null");

            _styleManagerTypeCmb.Enabled = true;
            _lineStyleGroup.Enabled      = true;
            _fillStylesGroup.Enabled     = true;

            _lineWidthTrack.Value   = (int)(manager.LineStyle.Width * 10);
            _lineStyleControl.Style = manager.LineStyle.Style;

            RandomStyleManager randomStyleManager = manager as RandomStyleManager;
            GreedyStyleManager greedyStyleManager;

            if (randomStyleManager != null)
            {
                _randomStyleMangerPnl.Visible = true;
                _seedNum.Value = randomStyleManager.Seed;
            }
            else if ((greedyStyleManager = manager as GreedyStyleManager) != null)
            {
                _greedyStyleManagerPnl.Visible = true;

                _greedyParamATrack.Maximum = manager.Styles.Count - 1;
                _greedyParamBTrack.Maximum = manager.Styles.Count - 1;
                _greedyParamCTrack.Maximum = manager.Styles.Count - 1;

                _greedyParamATrack.Value = greedyStyleManager.ParamA % manager.Styles.Count;
                _greedyParamBTrack.Value = greedyStyleManager.ParamB % manager.Styles.Count;
                _greedyParamCTrack.Value = greedyStyleManager.ParamC % manager.Styles.Count;
            }
            else
            {
                foreach (Control panel in _styleManagerPanels)
                {
                    Debug.Assert(panel != null, "panel != null");
                    panel.Visible = false;
                }
            }

            _styleList.SetStyles(manager.Styles, _lineStyleControl.ResourceManager);
        }