Ejemplo n.º 1
0
        /// <summary>
        /// Adds all defined <see cref="ImageFrame"/> sizes to the "Image Frame Sizes" <see
        /// cref="ComboBox"/> on the <see cref="StructureTab"/> page.</summary>
        /// <remarks><para>
        /// <b>AddImageSizes</b> iterates through all <see cref="EntityImage.Frames"/> of every <see
        /// cref="EntityImage"/> in the current <see cref="ImageSection"/>, and adds all unique <see
        /// cref="ImageFrame.Bounds"/> sizes to the "Image Frame Sizes" combo box.
        /// </para><para>
        /// The combo box and the "Circumscribe" button are disabled if the <see
        /// cref="ImageSection"/> does not define any <see cref="ImageFrame"/> objects.
        /// </para></remarks>

        private void AddImageSizes()
        {
            // extract all distinct sizes of image frames
            List <SizeI> sizes = new List <SizeI>();

            foreach (EntityImage image in MasterSection.Instance.Images.Collection.Values)
            {
                if (image != null)
                {
                    for (int i = 0; i < image.Frames.Count; i++)
                    {
                        SizeI size = image.Frames[i].Bounds.Size;
                        if (!sizes.Contains(size))
                        {
                            sizes.Add(size);
                        }
                    }
                }
            }

            if (sizes.Count == 0)
            {
                // disable controls if no image sizes defined
                CircumscribeButton.IsEnabled = false;
                ImageSizeCombo.IsEnabled     = false;
                ImageSizeCombo.Items.Add(Global.Strings.LabelNone);
            }
            else
            {
                // sort image sizes by width, then by height
                sizes.Sort((x, y) => {
                    int delta = x.Width - y.Width;
                    return(delta != 0 ? delta : x.Height - y.Height);
                });

                // add image sizes to combo box
                foreach (SizeI size in sizes)
                {
                    ImageSizeItem item = new ImageSizeItem(size);
                    ImageSizeCombo.Items.Add(item);
                }
            }

            Debug.Assert(ImageSizeCombo.Items.Count > 0);
            ImageSizeCombo.SelectedIndex = 0;
        }
Ejemplo n.º 2
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;
            }
        }