Exemplo n.º 1
0
        /// <summary>
        ///     Handles the ValueChanged event of the _lineWidthTrack 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 _lineWidthTrack_ValueChanged(object sender, EventArgs e)
        {
            if (_lineWidthTrack.Value < 1)
            {
                _lineWidthTrack.Value = 1;
                return;
            }

            TilingController controller = _tilingController;

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

                controller.StyleManager.LineStyle =
                    controller.StyleManager.LineStyle.WithWidth(_lineWidthTrack.Value / 10f);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Handles the StyleChanged event of the _lineStyleControl 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 _lineStyleControl_StyleChanged(object sender, EventArgs e)
        {
            if (_lineStyleControl.Style == null)
            {
                return;
            }

            TilingController controller = _tilingController;

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

                controller.StyleManager.LineStyle =
                    controller.StyleManager.LineStyle.WithStyle((SolidColourStyle)_lineStyleControl.Style);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Selects a tile from the tiling.
        /// </summary>
        /// <param name="initialTile">The initial tile.</param>
        /// <returns></returns>
        /// <exception cref="System.ObjectDisposedException"></exception>
        private Task <TileBase> SelectTileAsync(TileBase initialTile)
        {
            TilingController controller = _tilingController;

            if (controller == null)
            {
                return(Task.FromResult <TileBase>(null));
            }

            _selectTileTool.LastTool        = controller.CurrentTool;
            _selectTileTool.TileSelectedTcs = new TaskCompletionSource <TileBase>();
            controller.CurrentTool          = _selectTileTool;
            return(_selectTileTool.TileSelectedTcs.Task);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Handles the StylesChanged event of the _styleList 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 _styleList_StylesChanged(object sender, EventArgs e)
        {
            TilingController controller = _tilingController;

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

                controller.Tiling.UpdateStyles(controller.Tiles);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Saves the current tiling.
        /// </summary>
        /// <param name="askForPath">
        ///     If set to <see langword="true" /> the user will be prompted for the location to save the tiling.
        /// </param>
        /// <returns><see langword="true" /> if the tiling was saved; otherwise <see langword="false" />.</returns>
        private bool Save(bool askForPath = false)
        {
            if (!IsDirty)
            {
                return(true);
            }

            lock (_lock)
            {
                if (!IsDirty)
                {
                    return(true);
                }

                TilingController controller = _tilingController;
                if (controller == null)
                {
                    return(false);
                }

                if (DocumentPath == null || askForPath)
                {
                    _saveFileDialog.FileName = DocumentPath ?? DocumentName;
                    if (_saveFileDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        DocumentPath = _saveFileDialog.FileName;
                    }
                    else
                    {
                        return(false);
                    }
                }

                // TODO Create thumbnail

                Debug.Assert(DocumentPath != null, "DocumentPath != null");
                FileStorage.SaveTiling(controller.Tiling, DocumentPath);
                IsDirty = false;
                return(true);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        ///     Handles the Click event of the printMenuItem 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 printMenuItem_Click(object sender, EventArgs e)
        {
            TilingController controller = _tilingController;

            if (controller == null || controller != ActiveController)
            {
                return;
            }

            _printDocument.DocumentName = DocumentName;
            _printDocument.Tiling       = controller?.Tiling;
            if (_tilingPrintSettingsDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            if (_printDialog.ShowDialog(this) == DialogResult.OK)
            {
                _printDocument.Print();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Creates the tiling controller.
        /// </summary>
        /// <param name="tiling">The tiling.</param>
        /// <returns></returns>
        private TilingController CreateTilingController([NotNull] Tiling tiling)
        {
            Debug.Assert(tiling != null, "tiling != null");

            TilingController tc = new TilingController(tiling, this);

            tc.EditLine.OptionsChanged += TilingController_EditLineTool_OptionsChanged;
            tc.EditLine.ChangeLineOption.ValueChanged += v => _changeLineTypeCmb.SelectedItem = v;
            _changeLineTypeCmb.SelectedItem            = tc.EditLine.ChangeLineOption.Value;

            tc.StyleManagerChanged += (sender, args) => IsDirty = true;
            tc.CurrentToolChanged  += controller_CurrentToolChanged;
            _panTool        = new PanTool(tc, this);
            _selectTileTool = new SelectTileTool(tc);

            _toolBtns.Add(_panTool, _panToolBtn);

            UpdateTools();

            return(tc);
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Opens the tiling given for editing.
        /// </summary>
        /// <param name="tiling">The tiling.</param>
        private void OpenTiling([NotNull] Tiling tiling)
        {
            Debug.Assert(tiling != null, "tiling != null");

            lock (_lock)
            {
                try
                {
                    // Dont call the ViewBoundsChanged event handler while changing the tiling
                    _layoutSuspended = true;

                    // Reset view
                    _translate = _invTranslate = Matrix3x2.Identity;
                    _zoom      = 100f;
                    UpdateScale();

                    if (_tilingController == null)
                    {
                        _tilingController = CreateTilingController(tiling);
                    }
                    else
                    {
                        _tilingController.SetTiling(tiling);
                    }

                    ActiveController = _tilingController;

                    UpdateStyleManager(tiling.StyleManager);

                    IsDirty = false;
                }
                finally
                {
                    _layoutSuspended = false;
                }
            }
        }
Exemplo n.º 10
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="SelectTileTool" /> class.
 /// </summary>
 /// <param name="controller">The controller.</param>
 public SelectTileTool([NotNull] TilingController controller)
     : base(controller)
 {
 }