コード例 #1
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Circumscribe" <see
        /// cref="Button"/> on the <see cref="StructureTab"/> page.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks><para>
        /// <b>OnCircumscribe</b> sets the "Side Length" control to a value that circumscribes <see
        /// cref="PolygonGrid.Element"/> of the <see cref="MapGrid"/> around the selected item, if
        /// any, in the "Image Frame Sizes" combo box.
        /// </para><para>
        /// Changing the "Side Length" control triggers <see cref="OnLengthChanged"/> which resizes
        /// the <see cref="PolygonGrid.Element"/> accordingly and sets the <see cref="DataChanged"/>
        /// flag.</para></remarks>

        private void OnCircumscribe(object sender, RoutedEventArgs args)
        {
            args.Handled = true;
            if (this._ignoreEvents)
            {
                return;
            }

            // get selected image size, if any
            ImageSizeItem item = ImageSizeCombo.SelectedItem as ImageSizeItem;

            if (item == null)
            {
                return;
            }

            // circumscribe polygon around image size
            RegularPolygon element       = MapGrid.Element;
            var            circumscribed = element.Circumscribe(item.Value.Width, item.Value.Height);

            // restrict side length to legal range
            double length = circumscribed.Length;

            if (length < AreaSection.MinPolygonLength)
            {
                length = AreaSection.MinPolygonLength;
            }
            if (length > AreaSection.MaxPolygonLength)
            {
                length = AreaSection.MaxPolygonLength;
            }

            // show new side length if changed (triggers OnLengthChanged)
            if (length != element.Length)
            {
                LengthUpDown.Value = (decimal)length;
            }
        }