Esempio n. 1
1
        /// <summary>A method used to calculate layout for Image and Text content with standard options.</summary>
        /// <param name="bounds">The bounding Rectangle within which to draw.</param>
        /// <param name="text">The text to draw.</param>
        /// <param name="font">The font used to draw text.</param>
        /// <param name="image">The image to draw (this may be null).</param>
        /// <param name="textAlignment">The vertical and horizontal alignment of the text.</param>
        /// <param name="imageAlignment">The vertical and horizontal alignment of the image.</param>
        /// <param name="textImageRelation">The placement of the image and text relative to each other.</param>
        /// <param name="wordWrap">set true if text should wrap.</param>
        /// <param name="glowSize">The size in pixels of the glow around text.</param>
        /// <param name="format">The format.</param>
        /// <param name="actualTextBounds">The actual text bounds.</param>
        /// <param name="actualImageBounds">The actual image bounds.</param>
        public static void CalcImageAndTextBounds(Rectangle bounds, string text, Font font, Image image, ContentAlignment textAlignment,
                                                  ContentAlignment imageAlignment, TextImageRelation textImageRelation, bool wordWrap, int glowSize,
                                                  ref TextFormatFlags format, out Rectangle actualTextBounds, out Rectangle actualImageBounds)
        {
            var horizontalRelation = (int)textImageRelation > 2;
            var imageHasPreference = textImageRelation == TextImageRelation.ImageBeforeText || textImageRelation == TextImageRelation.ImageAboveText;

            var preferredAlignmentValue = imageHasPreference ? (int)imageAlignment : (int)textAlignment;

            var contentRectangle = bounds;

            format |= TextFormatFlags.TextBoxControl | (wordWrap ? TextFormatFlags.WordBreak : TextFormatFlags.SingleLine);

            // Get ImageSize
            var imageSize = image?.Size ?? Size.Empty;

            // Get AvailableTextSize
            var availableTextSize = horizontalRelation ?
                                    new Size(bounds.Width - imageSize.Width, bounds.Height) :
                                    new Size(bounds.Width, bounds.Height - imageSize.Height);

            // Get ActualTextSize
            var actualTextSize = text?.Length > 0 ? TextRenderer.MeasureText(text, font, availableTextSize, format) : Size.Empty;

            // Get ContentRectangle based upon TextImageRelation
            if (textImageRelation != 0)
            {
                // Get ContentSize
                var contentSize = horizontalRelation ?
                                  new Size(imageSize.Width + actualTextSize.Width, Math.Max(imageSize.Height, availableTextSize.Height)) :
                                  new Size(Math.Max(imageSize.Width, availableTextSize.Width), imageSize.Height + actualTextSize.Height);

                // Get ContentLocation
                var contentLocation = bounds.Location;
                if (horizontalRelation)
                {
                    if (preferredAlignmentValue % 15 == 1)
                    {
                        contentLocation.X = bounds.Left;
                    }
                    else if (preferredAlignmentValue % 15 == 2)
                    {
                        contentLocation.X = bounds.Left + (bounds.Width / 2 - contentSize.Width / 2);
                    }
                    else if (preferredAlignmentValue % 15 == 4)
                    {
                        contentLocation.X = bounds.Right - contentSize.Width;
                    }
                }
                else
                {
                    if (preferredAlignmentValue <= 4)
                    {
                        contentLocation.Y = bounds.Top;
                    }
                    else if (preferredAlignmentValue >= 256)
                    {
                        contentLocation.Y = bounds.Bottom - contentSize.Height;
                    }
                    else
                    {
                        contentLocation.Y = bounds.Top + (bounds.Height / 2 - contentSize.Height / 2);
                    }
                }

                contentRectangle = new Rectangle(contentLocation, contentSize);
            }

            actualImageBounds = Rectangle.Empty;
            if (image != null)
            {
                // Get ActualImageBounds
                actualImageBounds = new Rectangle(bounds.Location, imageSize);
                if (horizontalRelation)
                {
                    actualImageBounds.X = imageHasPreference ? contentRectangle.X : contentRectangle.Right - imageSize.Width;
                    actualImageBounds.Y = (int)imageAlignment <= 4 ?
                                          contentRectangle.Y : (int)imageAlignment >= 256 ?
                                          contentRectangle.Bottom - imageSize.Height :
                                          contentRectangle.Y + contentRectangle.Height / 2 - imageSize.Height / 2;
                }
                else if (textImageRelation == 0)
                {
                    if ((int)imageAlignment <= 4)
                    {
                        actualImageBounds.Y = bounds.Top;
                    }
                    else if ((int)imageAlignment >= 256)
                    {
                        actualImageBounds.Y = bounds.Bottom - imageSize.Height;
                    }
                    else
                    {
                        actualImageBounds.Y = bounds.Top + (bounds.Height / 2 - imageSize.Height / 2);
                    }

                    if ((int)imageAlignment % 15 == 1)
                    {
                        actualImageBounds.X = bounds.Left;
                    }
                    else if ((int)imageAlignment % 15 == 2)
                    {
                        actualImageBounds.X = bounds.Left + (bounds.Width / 2 - imageSize.Width / 2);
                    }
                    else if ((int)imageAlignment % 15 == 4)
                    {
                        actualImageBounds.X = bounds.Right - imageSize.Width;
                    }
                }
                else
                {
                    actualImageBounds.Y = imageHasPreference ? contentRectangle.Y : contentRectangle.Bottom - imageSize.Height;
                    actualImageBounds.X = (int)imageAlignment % 15 == 1 ?
                                          contentRectangle.X : (int)imageAlignment % 15 == 2 ?
                                          contentRectangle.X + contentRectangle.Width / 2 - imageSize.Width / 2 :
                                          contentRectangle.Right - imageSize.Width;
                }
            }

            // Get ActualTextBounds
            actualTextBounds = Rectangle.Empty;
            if (!(text?.Length > 0))
            {
                return;
            }

            actualTextBounds = new Rectangle(Point.Empty, actualTextSize);
            if (horizontalRelation)
            {
                actualTextBounds.X = imageHasPreference ? contentRectangle.Right - actualTextSize.Width : contentRectangle.X;
                actualTextBounds.Y = (int)textAlignment <= 4
                                        ? contentRectangle.Y
                                        : (int)textAlignment >= 256
                                                ? contentRectangle.Bottom - actualTextSize.Height
                                                : contentRectangle.Y + (contentRectangle.Height / 2) - (actualTextSize.Height / 2);
            }
            else if (textImageRelation == 0)
            {
                if ((int)textAlignment <= 4)
                {
                    actualTextBounds.Y = bounds.Top;
                }
                else if ((int)textAlignment >= 256)
                {
                    actualTextBounds.Y = bounds.Bottom - actualTextSize.Height;
                }
                else
                {
                    actualTextBounds.Y = bounds.Top + (bounds.Height / 2 - actualTextSize.Height / 2);
                }

                if ((int)textAlignment % 15 == 1)
                {
                    actualTextBounds.X = bounds.Left;
                }
                else if ((int)textAlignment % 15 == 2)
                {
                    actualTextBounds.X = bounds.Left + (bounds.Width / 2 - actualTextSize.Width / 2);
                }
                else if ((int)textAlignment % 15 == 4)
                {
                    actualTextBounds.X = bounds.Right - actualTextSize.Width;
                }
            }
            else
            {
                actualTextBounds.Y = imageHasPreference ? contentRectangle.Bottom - actualTextSize.Height : contentRectangle.Y;
                actualTextBounds.X = (int)textAlignment % 15 == 1
                                        ? contentRectangle.X
                                        : (int)textAlignment % 15 == 2
                                                ? contentRectangle.X + contentRectangle.Width / 2 - actualTextSize.Width / 2
                                                : contentRectangle.Right - actualTextSize.Width;
            }
        }
Esempio n. 2
1
        /// <summary>A method used to draw standard Image and Text content with standard layout options.</summary>
        /// <param name="graphics">The Graphics object on which to draw.</param>
        /// <param name="bounds">The bounding Rectangle within which to draw.</param>
        /// <param name="text">The text to draw.</param>
        /// <param name="font">The font used to draw text.</param>
        /// <param name="image">The image to draw (this may be null).</param>
        /// <param name="textAlignment">The vertical and horizontal alignment of the text.</param>
        /// <param name="imageAlignment">The vertical and horizontal alignment of the image.</param>
        /// <param name="textImageRelation">The placement of the image and text relative to each other.</param>
        /// <param name="textColor">The color to draw the text.</param>
        /// <param name="wordWrap">set true if text should wrap.</param>
        /// <param name="glowSize">The size in pixels of the glow around text.</param>
        /// <param name="enabled">Set false to draw image grayed out.</param>
        /// <param name="format">The <see cref="TextFormatFlags"/> used to format the text.</param>
        public static void DrawImageAndText(this Graphics graphics, Rectangle bounds, string text, Font font, Image image,
                                            ContentAlignment textAlignment, ContentAlignment imageAlignment, TextImageRelation textImageRelation, Color textColor,
                                            bool wordWrap, int glowSize, bool enabled = true, TextFormatFlags format = TextFormatFlags.TextBoxControl)
        {
            CalcImageAndTextBounds(bounds, text, font, image, textAlignment, imageAlignment, textImageRelation, wordWrap, glowSize, ref format, out Rectangle tRect, out Rectangle iRect);

            // Draw Image
            if (image != null)
            {
                if (enabled)
                {
                    graphics.DrawImage(image, iRect);
                }
                else
                {
                    ControlPaint.DrawImageDisabled(graphics, image, iRect.X, iRect.Y, Color.Transparent);
                }
            }

            // Draw text
            if (text?.Length > 0)
            {
                TextRenderer.DrawText(graphics, text, font, tRect, textColor, format);
            }
        }
Esempio n. 3
0
		protected ButtonBase() : base()
		{
			flat_style	= FlatStyle.Standard;
			flat_button_appearance = new FlatButtonAppearance (this);
			this.image_key = string.Empty;
			this.text_image_relation = TextImageRelation.Overlay;
			this.use_mnemonic = true;
			use_visual_style_back_color = true;
			image_index	= -1;
			image		= null;
			image_list	= null;
			image_alignment	= ContentAlignment.MiddleCenter;
			ImeMode         = ImeMode.Disable;
			text_alignment	= ContentAlignment.MiddleCenter;
			is_default	= false;
			is_pressed	= false;
			text_format	= new StringFormat();
			text_format.Alignment = StringAlignment.Center;
			text_format.LineAlignment = StringAlignment.Center;
			text_format.HotkeyPrefix = HotkeyPrefix.Show;
			text_format.FormatFlags |= StringFormatFlags.LineLimit;

			text_format_flags = TextFormatFlags.HorizontalCenter;
			text_format_flags |= TextFormatFlags.VerticalCenter;
			text_format_flags |= TextFormatFlags.TextBoxControl;

			SetStyle (ControlStyles.ResizeRedraw | 
				ControlStyles.Opaque | 
				ControlStyles.UserMouse | 
				ControlStyles.SupportsTransparentBackColor | 
				ControlStyles.CacheText |
				ControlStyles.OptimizedDoubleBuffer, true);
			SetStyle (ControlStyles.StandardClick, false);
		}
Esempio n. 4
0
        private ToolStripItem SetToolStripItem(ToolStripItem toolStripItem, Operation operation,
            IResourceService resourceService, int rowCount, bool isTextShown, ContentAlignment txtAlign, TextImageRelation txtImgRelation, Font font)
        {
            string toolStripResourceName = string.Empty;

            if (toolStripItem is ToolStripSplitButton)
            {
                toolStripResourceName = string.Format(resourceService.GetResourceString(operation.Name), rowCount);
                toolStripItem.Tag = operation.Name + '#' + operation.Detail;
            }
            else
            {
                toolStripResourceName = resourceService.GetResourceString(operation.Name);
                toolStripItem.Tag = operation.Name;
            }

            toolStripItem.ToolTipText = toolStripResourceName;
            toolStripItem.Name = operation.Name;
            toolStripItem.Image = GetIcon(operation.NormalResId, RESOURCE_TYPE); //
            if (isTextShown)
            {
                toolStripItem.Text = toolStripResourceName;
                toolStripItem.TextAlign = txtAlign;
                toolStripItem.TextImageRelation = txtImgRelation;
                toolStripItem.Font = font;
            }
            return toolStripItem;
        }
Esempio n. 5
0
 public static bool IsValidTextImageRelation(TextImageRelation relation) =>
 ClientUtils.IsEnumValid(relation, (int)relation, 0, 8, 1);
Esempio n. 6
0
 // IsValidTextImageRelation
 // valid values are 0,1,2,4,8
 // Method for verifying
 //   Verify that the number is between 0 and 8
 //   Verify that the bit that is on - thus forcing it to be a power of two.
 //
 public static bool IsValidTextImageRelation(TextImageRelation relation)
 {
     return(ClientUtils.IsEnumValid(relation, (int)relation, (int)TextImageRelation.Overlay, (int)TextImageRelation.TextBeforeImage, 1));
 }
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            SizeF      fieldSize   = finalSize;
            RectangleF layoutField = new RectangleF(PointF.Empty, finalSize);

            RectangleF imageBounds = RectangleF.Empty;
            RectangleF textBounds  = RectangleF.Empty;
            SizeF      textSize    = SizeF.Empty;
            SizeF      imageSize   = SizeF.Empty;

            ContentAlignment  imageAlign        = this.ImageAlignment;
            ContentAlignment  textAlign         = this.TextAlignment;
            TextImageRelation textImageRelation = this.TextImageRelation;

            if (this.RightToLeft)
            {
                imageAlign        = TelerikAlignHelper.RtlTranslateContent(ImageAlignment);
                textAlign         = TelerikAlignHelper.RtlTranslateContent(TextAlignment);
                textImageRelation = TelerikAlignHelper.RtlTranslateRelation(TextImageRelation);
            }

            if ((this.textElement != null) && IsPrimitiveNullOrEmpty(this.imageElement))
            {
                this.textElement.Arrange(layoutField);
                if (this.imageElement != null)
                {
                    this.imageElement.Arrange(layoutField);
                }
                return(finalSize);
            }
            if ((this.imageElement != null) && IsPrimitiveNullOrEmpty(this.textElement))
            {
                this.imageElement.Arrange(layoutField);
                if (this.textElement != null)
                {
                    this.textElement.Arrange(layoutField);
                }
                return(finalSize);
            }

            textSize  = this.GetInvariantLength(textElement.DesiredSize, textElement.Margin);
            imageSize = this.GetInvariantLength(imageElement.DesiredSize, imageElement.Margin);

            // Subtract the image size from the whole field size
            SizeF textSizeLeft = LayoutUtils.SubAlignedRegion(fieldSize, imageSize, textImageRelation);
            // Create a new size based on the text size and the image size
            SizeF newSize = LayoutUtils.AddAlignedRegion(textSize, imageSize, textImageRelation);
            // The new field which is a union of the new sizes
            RectangleF maxFieldRectangle = RectangleF.Empty;

            maxFieldRectangle.Size = LayoutUtils.UnionSizes(fieldSize, newSize);
            // Image doesn't overlay text
            bool imageAlignNoOverlay = (TelerikAlignHelper.ImageAlignToRelation(imageAlign) & textImageRelation) !=
                                       TextImageRelation.Overlay;
            // Text doesn't overlay image
            bool textAlignNoOverlay = (TelerikAlignHelper.TextAlignToRelation(textAlign) & textImageRelation) !=
                                      TextImageRelation.Overlay;

            if (imageAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
            }
            else if (textAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, textSize, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(textImageRelation), out textBounds, out imageBounds);
            }
            else
            {
                // Both image overlays text and text overlays image
                if (textImageRelation == TextImageRelation.Overlay)
                {
                    LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                }
                else
                {
                    RectangleF alignedField = LayoutUtils.Align(newSize, maxFieldRectangle, ContentAlignment.MiddleCenter);
                    LayoutUtils.SplitRegion(alignedField, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                    LayoutUtils.ExpandRegionsToFillBounds(maxFieldRectangle, (AnchorStyles)textImageRelation, ref imageBounds, ref textBounds);
                }
            }


            textBounds.Size  = SizeF.Subtract(textBounds.Size, this.textElement.Margin.Size);
            imageBounds.Size = SizeF.Subtract(imageBounds.Size, this.imageElement.Margin.Size);

            this.textElement.Arrange(textBounds);
            this.imageElement.Arrange(imageBounds);

            return(finalSize);
        }
Esempio n. 8
0
 public ToolStripBuilderStyle(ToolStripItemDisplayStyle toolStripItemDisplayStyle, ToolStripItemAlignment toolStripItemAlignment, TextImageRelation textImageRelation)
 {
     _toolStripItemAlignment = toolStripItemAlignment;
     _toolStripItemDisplayStyle = toolStripItemDisplayStyle;
     _textImageRelation = textImageRelation;
 }
Esempio n. 9
0
 public static Size AddAlignedRegion(Size textSize, Size imageSize, TextImageRelation relation) {
     return AddAlignedRegionCore(textSize, imageSize, IsVerticalRelation(relation));
 }
 private TextImageRelation RtlTranslateRelation(TextImageRelation relation)
 {
     if (!this.layoutRTL)
     {
         return relation;
     }
     TextImageRelation relation2 = relation;
     if (relation2 != TextImageRelation.ImageBeforeText)
     {
         if (relation2 == TextImageRelation.TextBeforeImage)
         {
             return TextImageRelation.ImageBeforeText;
         }
         return relation;
     }
     return TextImageRelation.TextBeforeImage;
 }
Esempio n. 11
0
 /// <summary>
 /// 两个大小相加,by关系.重叠关系(需要预先手动排除)
 /// </summary>
 /// <param name="contentSize1">内容大小1</param>
 /// <param name="contentSize2">内容大小2</param>
 /// <param name="relation">两个内容关系</param>
 /// <returns>新大小</returns>
 public static Size AddAlignedRegion(Size contentSize1, Size contentSize2, TextImageRelation relation)
 {
     return(AddAlignedRegionCore(contentSize1, contentSize2, IsVerticalRelation(relation)));
 }
Esempio n. 12
0
        /// <summary>Draws the text image relation.</summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="relation">The relation type.</param>
        /// <param name="image">The image rectangle.</param>
        /// <param name="text">The text.</param>
        /// <param name="font">The font.</param>
        /// <param name="bounds">The outer bounds.</param>
        /// <param name="imagePoint">Return image point.</param>
        /// <returns>The <see cref="Point" />.</returns>
        public static Point GetTextImageRelationLocation(Graphics graphics, TextImageRelation relation, Rectangle image, string text, Font font, Rectangle bounds, bool imagePoint)
        {
            Point _newPosition   = new Point(0, 0);
            Point _imageLocation = new Point(0, 0);
            Point _textLocation  = new Point(0, 0);
            Size  textSize       = GraphicsManager.MeasureText(text, font, graphics);

            switch (relation)
            {
            case TextImageRelation.Overlay:
            {
                // Set center
                _newPosition.X = bounds.Width / 2;
                _newPosition.Y = bounds.Height / 2;

                // Set image
                _imageLocation.X = _newPosition.X - (image.Width / 2);
                _imageLocation.Y = _newPosition.Y - (image.Height / 2);

                // Set text
                _textLocation.X = _newPosition.X - (textSize.Width / 2);
                _textLocation.Y = _newPosition.Y - (textSize.Height / 2);
                break;
            }

            case TextImageRelation.ImageBeforeText:
            {
                // Set center
                _newPosition.Y = bounds.Height / 2;

                // Set image
                _imageLocation.X = _newPosition.X + 4;
                _imageLocation.Y = _newPosition.Y - (image.Height / 2);

                // Set text
                _textLocation.X = _imageLocation.X + image.Width;
                _textLocation.Y = _newPosition.Y - (textSize.Height / 2);
                break;
            }

            case TextImageRelation.TextBeforeImage:
            {
                // Set center
                _newPosition.Y = bounds.Height / 2;

                // Set text
                _textLocation.X = _newPosition.X + 4;
                _textLocation.Y = _newPosition.Y - (textSize.Height / 2);

                // Set image
                _imageLocation.X = _textLocation.X + textSize.Width;
                _imageLocation.Y = _newPosition.Y - (image.Height / 2);
                break;
            }

            case TextImageRelation.ImageAboveText:
            {
                // Set center
                _newPosition.X = bounds.Width / 2;

                // Set image
                _imageLocation.X = _newPosition.X - (image.Width / 2);
                _imageLocation.Y = _newPosition.Y + 4;

                // Set text
                _textLocation.X = _newPosition.X - (textSize.Width / 2);
                _textLocation.Y = _imageLocation.Y + image.Height;
                break;
            }

            case TextImageRelation.TextAboveImage:
            {
                // Set center
                _newPosition.X = bounds.Width / 2;

                // Set text
                _textLocation.X = _newPosition.X - (textSize.Width / 2);
                _textLocation.Y = _imageLocation.Y + 4;

                // Set image
                _imageLocation.X = _newPosition.X - (image.Width / 2);
                _imageLocation.Y = _newPosition.Y + textSize.Height + 4;
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(relation), relation, null);
            }
            }

            if (imagePoint)
            {
                return(_imageLocation);
            }
            else
            {
                return(_textLocation);
            }
        }
Esempio n. 13
0
        public override SizeF Measure(SizeF availableSize)
        {
            SizeF             result            = SizeF.Empty;
            SizeF             leftSize          = SizeF.Empty;
            SizeF             rightSize         = SizeF.Empty;
            TextImageRelation textImageRelation = this.owner.TextImageRelation;

            switch (textImageRelation)
            {
            case TextImageRelation.ImageAboveText:
            case TextImageRelation.TextAboveImage:
                if (this.left != null)
                {
                    leftSize = this.left.Measure(availableSize);
                }

                if (this.right != null)
                {
                    rightSize = this.right.Measure(new SizeF(availableSize.Width, availableSize.Height - leftSize.Height));
                }

                result.Height += leftSize.Height;
                result.Height += rightSize.Height;
                result.Width   = Math.Max(leftSize.Width, rightSize.Width);
                break;

            case TextImageRelation.Overlay:
                if (this.left != null)
                {
                    leftSize = this.left.Measure(availableSize);
                }

                if (this.right != null)
                {
                    rightSize = this.right.Measure(availableSize);
                }

                result.Height = Math.Max(leftSize.Height, rightSize.Height);
                result.Width  = Math.Max(leftSize.Width, rightSize.Width);
                break;

            case TextImageRelation.ImageBeforeText:
            case TextImageRelation.TextBeforeImage:
                if (this.left != null)
                {
                    leftSize = this.left.Measure(availableSize);
                }

                if (this.right != null)
                {
                    rightSize = this.right.Measure(new SizeF(availableSize.Width - leftSize.Width, availableSize.Height));
                }

                result.Width += leftSize.Width;
                result.Width += rightSize.Width;
                result.Height = Math.Max(leftSize.Height, rightSize.Height);
                break;

            default:
                break;
            }

            this.DesiredSize = result;

            return(result);
        }
Esempio n. 14
0
        public override SizeF Arrange(RectangleF bounds)
        {
            SizeF finalSize = bounds.Size;

            if (this.lastFinalSize != finalSize || this.isDirty)
            {
                this.lastFinalSize = finalSize;
                this.Measure(finalSize);
            }

            SizeF      fieldSize   = finalSize;
            RectangleF layoutField = new RectangleF(bounds.Location, finalSize);

            RectangleF imageBounds = RectangleF.Empty;
            RectangleF textBounds  = RectangleF.Empty;
            SizeF      textSize    = SizeF.Empty;
            SizeF      imageSize   = SizeF.Empty;

            ContentAlignment  imageAlign        = this.owner.ImageAlignment;
            ContentAlignment  textAlign         = this.owner.TextAlignment;
            TextImageRelation textImageRelation = this.owner.TextImageRelation;

            if (this.owner.RightToLeft)
            {
                imageAlign        = TelerikAlignHelper.RtlTranslateContent(imageAlign);
                textAlign         = TelerikAlignHelper.RtlTranslateContent(textAlign);
                textImageRelation = TelerikAlignHelper.RtlTranslateRelation(textImageRelation);
            }

            if ((this.left != null) && (this.owner.Image == null))
            {
                this.left.Arrange(layoutField);
                if (this.right != null)
                {
                    this.right.Arrange(layoutField);
                }
                return(finalSize);
            }
            if (this.right != null && (string.IsNullOrEmpty(this.owner.Text) || !this.owner.DrawText))
            {
                this.right.Arrange(layoutField);
                if (this.left != null)
                {
                    this.left.Arrange(layoutField);
                }
                return(finalSize);
            }

            imageSize = this.GetInvariantLength(Size.Ceiling(this.left.DesiredSize), this.left.Margin);
            textSize  = this.GetInvariantLength(Size.Ceiling(this.right.DesiredSize), this.right.Margin);

            // Subtract the image size from the whole field size
            SizeF textSizeLeft = LayoutUtils.SubAlignedRegion(fieldSize, imageSize, textImageRelation);
            // Create a new size based on the text size and the image size
            SizeF newSize = LayoutUtils.AddAlignedRegion(textSize, imageSize, textImageRelation);

            // The new field which is a union of the new sizes
            RectangleF maxFieldRectangle = Rectangle.Empty;

            maxFieldRectangle.Size = LayoutUtils.UnionSizes(fieldSize, newSize);
            maxFieldRectangle.X   += layoutField.X;
            maxFieldRectangle.Y   += layoutField.Y;
            // Image doesn't overlay text
            bool imageAlignNoOverlay = (TelerikAlignHelper.ImageAlignToRelation(imageAlign) & textImageRelation) != TextImageRelation.Overlay;
            // Text doesn't overlay image
            bool textAlignNoOverlay = (TelerikAlignHelper.TextAlignToRelation(textAlign) & textImageRelation) != TextImageRelation.Overlay;

            if (imageAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
            }
            else if (textAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, textSize, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(textImageRelation), out textBounds, out imageBounds);
            }
            else
            {
                // Both image overlays text and text overlays image
                if (textImageRelation == TextImageRelation.Overlay)
                {
                    LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                }
                else
                {
                    RectangleF alignedField = LayoutUtils.Align(newSize, maxFieldRectangle, ContentAlignment.MiddleCenter);
                    LayoutUtils.SplitRegion(alignedField, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                    LayoutUtils.ExpandRegionsToFillBounds(maxFieldRectangle, (AnchorStyles)textImageRelation, ref imageBounds, ref textBounds);
                }
            }
            ///////////////////////////////////////////////////////////////////////////

            //set image and text bounds according the size of the field
            if ((textImageRelation == TextImageRelation.TextBeforeImage) || (textImageRelation == TextImageRelation.ImageBeforeText))
            {
                float num1 = Math.Min(textBounds.Bottom, layoutField.Bottom);
                textBounds.Y      = Math.Max(Math.Min(textBounds.Y, layoutField.Y + ((layoutField.Height - textBounds.Height) / 2)), layoutField.Y);
                textBounds.Height = num1 - textBounds.Y;
            }
            if ((textImageRelation == TextImageRelation.TextAboveImage) || (textImageRelation == TextImageRelation.ImageAboveText))
            {
                float num2 = Math.Min(textBounds.Right, layoutField.Right);
                textBounds.X     = Math.Max(Math.Min(textBounds.X, layoutField.X + ((layoutField.Width - textBounds.Width) / 2)), layoutField.X);
                textBounds.Width = num2 - textBounds.X;
            }
            if ((textImageRelation == TextImageRelation.ImageBeforeText) && (imageBounds.Size.Width != 0))
            {
                imageBounds.Width = Math.Max(0, Math.Min(fieldSize.Width - textBounds.Width, imageBounds.Width));
                textBounds.X      = imageBounds.X + imageBounds.Width;
            }
            if ((textImageRelation == TextImageRelation.ImageAboveText) && (imageBounds.Size.Height != 0))
            {
                imageBounds.Height = Math.Max(0, Math.Min(fieldSize.Height - textBounds.Height, imageBounds.Height));
                textBounds.Y       = imageBounds.Y + imageBounds.Height;
            }
            textBounds = RectangleF.Intersect(textBounds, layoutField);

            //align image and if its size is greater than the field's size it is become offseted as much as the difference
            RectangleF newImageBounds = LayoutUtils.Align(imageSize, imageBounds, imageAlign);

            if (newImageBounds.Width > imageBounds.Width)
            {
                newImageBounds.X = imageBounds.Width - imageSize.Width;
            }
            if (newImageBounds.Height > imageBounds.Height)
            {
                newImageBounds.Y = imageBounds.Height - imageSize.Height;
            }

            textBounds = LayoutUtils.Align(textSize, textBounds, textAlign);
            //textBounds.Offset(layoutField.Location);
            //imageBounds.Offset(layoutField.Location);

            /////////////////////////////////////////////////////////////////////////
            textBounds.Size  = SizeF.Subtract(textBounds.Size, this.left.Margin.Size);
            imageBounds.Size = SizeF.Subtract(imageBounds.Size, this.right.Margin.Size);

            this.left.Arrange(imageBounds);
            this.right.Arrange(textBounds);

            return(finalSize);
        }
Esempio n. 15
0
 TextImageRelation RtlTranslateRelation(TextImageRelation relation) {
     // If RTL, we swap ImageBeforeText and TextBeforeImage
     if (layoutRTL) {
         switch(relation) {
             case TextImageRelation.ImageBeforeText:
                 return TextImageRelation.TextBeforeImage;
             case TextImageRelation.TextBeforeImage:
                 return TextImageRelation.ImageBeforeText;
         }
     }
     return relation;
 }
Esempio n. 16
0
 // IsValidTextImageRelation
 // valid values are 0,1,2,4,8
 // Method for verifying
 //   Verify that the number is between 0 and 8
 //   Verify that the bit that is on - thus forcing it to be a power of two.
 //          
 public static bool IsValidTextImageRelation(TextImageRelation relation) {
     return ClientUtils.IsEnumValid(relation, (int)relation, (int)TextImageRelation.Overlay, (int)TextImageRelation.TextBeforeImage,1);           
 }
 static LayoutOptions()
 {
     TextImageRelation[] relationArray = new TextImageRelation[11];
     relationArray[0] = TextImageRelation.ImageBeforeText | TextImageRelation.ImageAboveText;
     relationArray[1] = TextImageRelation.ImageAboveText;
     relationArray[2] = TextImageRelation.TextBeforeImage | TextImageRelation.ImageAboveText;
     relationArray[4] = TextImageRelation.ImageBeforeText;
     relationArray[6] = TextImageRelation.TextBeforeImage;
     relationArray[8] = TextImageRelation.ImageBeforeText | TextImageRelation.TextAboveImage;
     relationArray[9] = TextImageRelation.TextAboveImage;
     relationArray[10] = TextImageRelation.TextBeforeImage | TextImageRelation.TextAboveImage;
     _imageAlignToRelation = relationArray;
 }
Esempio n. 18
0
 // True if text & image should be lined up vertically.  False if horizontal or overlay.
 public static bool IsVerticalRelation(TextImageRelation relation) {
     return (relation & (TextImageRelation.TextAboveImage | TextImageRelation.ImageAboveText)) != 0;
 }
Esempio n. 19
0
        public override SizeF Arrange(RectangleF bounds)
        {
            SizeF size = bounds.Size;

            if (this.lastFinalSize != size || this.isDirty)
            {
                this.lastFinalSize = size;
                this.Measure(size);
            }
            SizeF             sizeF1           = size;
            RectangleF        rectangleF1      = new RectangleF(bounds.Location, size);
            RectangleF        empty1           = RectangleF.Empty;
            RectangleF        region2          = RectangleF.Empty;
            SizeF             empty2           = SizeF.Empty;
            SizeF             empty3           = SizeF.Empty;
            ContentAlignment  contentAlignment = this.Owner.ImageAlignment;
            TextImageRelation relation         = this.Owner.TextImageRelation;

            if (this.Owner.RightToLeft)
            {
                contentAlignment = TelerikAlignHelper.RtlTranslateContent(contentAlignment);
                relation         = TelerikAlignHelper.RtlTranslateRelation(relation);
            }
            if (this.left != null && this.Owner.Image == null)
            {
                this.left.Arrange(rectangleF1);
                if (this.right != null)
                {
                    this.right.Arrange(rectangleF1);
                }
                return(size);
            }
            if (this.right != null && (string.IsNullOrEmpty(this.Owner.Text) || !this.Owner.DrawText))
            {
                this.right.Arrange(rectangleF1);
                if (this.left != null)
                {
                    this.left.Arrange(rectangleF1);
                }
                return(size);
            }
            SizeF invariantLength1 = (SizeF)this.GetInvariantLength(Size.Ceiling(this.left.DesiredSize), this.left.Margin);
            SizeF invariantLength2 = (SizeF)this.GetInvariantLength(Size.Ceiling(this.right.DesiredSize), this.right.Margin);

            LayoutUtils.SubAlignedRegion(sizeF1, invariantLength1, relation);
            SizeF      sizeF2 = LayoutUtils.AddAlignedRegion(invariantLength2, invariantLength1, relation);
            RectangleF empty4 = (RectangleF)Rectangle.Empty;

            empty4.Size = LayoutUtils.UnionSizes(sizeF1, sizeF2);
            empty4.X   += rectangleF1.X;
            empty4.Y   += rectangleF1.Y;
            bool flag1 = (TelerikAlignHelper.ImageAlignToRelation(contentAlignment) & relation) != TextImageRelation.Overlay;
            bool flag2 = (TelerikAlignHelper.TextAlignToRelation(this.Owner.TextAlignment) & relation) != TextImageRelation.Overlay;

            if (flag1)
            {
                LayoutUtils.SplitRegion(empty4, invariantLength1, (AnchorStyles)relation, out empty1, out region2);
            }
            else if (flag2)
            {
                LayoutUtils.SplitRegion(empty4, invariantLength2, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(relation), out region2, out empty1);
            }
            else if (relation == TextImageRelation.Overlay)
            {
                LayoutUtils.SplitRegion(empty4, invariantLength1, (AnchorStyles)relation, out empty1, out region2);
            }
            else
            {
                LayoutUtils.SplitRegion(LayoutUtils.Align(sizeF2, empty4, ContentAlignment.MiddleCenter), invariantLength1, (AnchorStyles)relation, out empty1, out region2);
                LayoutUtils.ExpandRegionsToFillBounds(empty4, (AnchorStyles)relation, ref empty1, ref region2);
            }
            if (relation == TextImageRelation.TextBeforeImage || relation == TextImageRelation.ImageBeforeText)
            {
                float num = Math.Min(region2.Bottom, rectangleF1.Bottom);
                region2.Y      = Math.Max(Math.Min(region2.Y, rectangleF1.Y + (float)(((double)rectangleF1.Height - (double)region2.Height) / 2.0)), rectangleF1.Y);
                region2.Height = num - region2.Y;
            }
            if (relation == TextImageRelation.TextAboveImage || relation == TextImageRelation.ImageAboveText)
            {
                float num = Math.Min(region2.Right, rectangleF1.Right);
                region2.X     = Math.Max(Math.Min(region2.X, rectangleF1.X + (float)(((double)rectangleF1.Width - (double)region2.Width) / 2.0)), rectangleF1.X);
                region2.Width = num - region2.X;
            }
            if (relation == TextImageRelation.ImageBeforeText && (double)empty1.Size.Width != 0.0)
            {
                empty1.Width = Math.Max(0.0f, Math.Min(sizeF1.Width - region2.Width, empty1.Width));
                region2.X    = empty1.X + empty1.Width;
            }
            if (relation == TextImageRelation.ImageAboveText && (double)empty1.Size.Height != 0.0)
            {
                empty1.Height = Math.Max(0.0f, Math.Min(sizeF1.Height - region2.Height, empty1.Height));
                region2.Y     = empty1.Y + empty1.Height;
            }
            region2 = RectangleF.Intersect(region2, rectangleF1);
            RectangleF rectangleF2 = LayoutUtils.Align(invariantLength1, empty1, contentAlignment);

            if ((double)rectangleF2.Width > (double)empty1.Width)
            {
                rectangleF2.X = empty1.Width - invariantLength1.Width;
            }
            if ((double)rectangleF2.Height > (double)empty1.Height)
            {
                rectangleF2.Y = empty1.Height - invariantLength1.Height;
            }
            region2.Size = SizeF.Subtract(region2.Size, (SizeF)this.left.Margin.Size);
            empty1.Size  = SizeF.Subtract(empty1.Size, (SizeF)this.right.Margin.Size);
            this.left.Arrange(empty1);
            this.right.Arrange(region2);
            return(size);
        }
Esempio n. 20
0
 public void OnmyTextImageRelationChanged(TextImageRelation oldValue, TextImageRelation newValue)
 {
     SetTextImageRelation();
 }
Esempio n. 21
0
        public void ButtonBase_TextImageRelation_SetInvalid_ThrowsInvalidEnumArgumentException(TextImageRelation value)
        {
            var button = new SubButtonBase();

            Assert.Throws <InvalidEnumArgumentException>("value", () => button.TextImageRelation = value);
        }
Esempio n. 22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fieldSize"></param>
        /// <param name="layoutField"></param>
        /// <param name="newLayouts"></param>
        public void LayoutTextAndImage(Size fieldSize, Rectangle layoutField, bool newLayouts)
        {
            Rectangle imageBounds = Rectangle.Empty;
            Rectangle textBounds  = Rectangle.Empty;
            Size      textSize    = Size.Empty;
            Size      imageSize   = Size.Empty;

            ContentAlignment  imageAlign        = ImageAlignment;
            ContentAlignment  textAlign         = TextAlignment;
            TextImageRelation textImageRelation = TextImageRelation;

            //DK_2006_07_28
            if (!newLayouts)
            {
                List <PreferredSizeData> prefSizelist = new List <PreferredSizeData>();
                FillList(prefSizelist, fieldSize);
            }

            if (this.RightToLeft)
            {
                imageAlign        = TelerikAlignHelper.RtlTranslateContent(ImageAlignment);
                textAlign         = TelerikAlignHelper.RtlTranslateContent(TextAlignment);
                textImageRelation = TelerikAlignHelper.RtlTranslateRelation(TextImageRelation);
            }

            if (textElement != null)
            {
                textSize = newLayouts ? Size.Ceiling(textElement.DesiredSize) : Size.Ceiling(textElement.GetPreferredSize(fieldSize));
                textSize = this.GetInvariantLength(textSize, textElement.Margin);
            }
            if (imageElement != null)
            {
                imageSize = newLayouts ? Size.Ceiling(imageElement.DesiredSize) : Size.Ceiling(imageElement.GetPreferredSize(fieldSize));
                imageSize = this.GetInvariantLength(imageSize, imageElement.Margin);
            }

            if ((textElement != null) && IsPrimitiveNullOrEmpty(this.imageElement))
            {
                Rectangle bounds = LayoutUtils.Align(textSize, new Rectangle(Point.Empty, fieldSize), textAlign);
                bounds.Size = Size.Subtract(textSize, textElement.Margin.Size);
                if (newLayouts)
                {
                    textElement.Arrange(bounds);
                }
                else
                {
                    textElement.Bounds = bounds;
                }
                return;
            }
            if ((imageElement != null) && IsPrimitiveNullOrEmpty(this.textElement))
            {
                Rectangle bounds = LayoutUtils.Align(imageSize, new Rectangle(Point.Empty, fieldSize), imageAlign);
                bounds.Size = Size.Subtract(imageSize, imageElement.Margin.Size);
                if (newLayouts)
                {
                    imageElement.Arrange(bounds);
                }
                else
                {
                    imageElement.Bounds = bounds;
                }
                return;
            }
            // Subtract the image size from the whole field size
            Size textSizeLeft = LayoutUtils.SubAlignedRegion(fieldSize, imageSize, textImageRelation);

            textSize = newLayouts ? Size.Ceiling(this.textElement.DesiredSize) : Size.Ceiling(this.textElement.GetPreferredSize(textSizeLeft));
            textSize = this.GetInvariantLength(textSize, textElement.Margin);

            // Create a new size based on the text size and the image size
            Size newSize = LayoutUtils.AddAlignedRegion(textSize, imageSize, textImageRelation);
            // The new field which is a union of the new sizes
            Rectangle maxFieldRectangle = Rectangle.Empty;

            maxFieldRectangle.Size = LayoutUtils.UnionSizes(fieldSize, newSize);
            // Image doesn't overlay text
            bool imageAlignNoOverlay = (TelerikAlignHelper.ImageAlignToRelation(imageAlign) & textImageRelation) !=
                                       TextImageRelation.Overlay;
            // Text doesn't overlay image
            bool textAlignNoOverlay = (TelerikAlignHelper.TextAlignToRelation(textAlign) & textImageRelation) !=
                                      TextImageRelation.Overlay;

            if (imageAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
            }
            else if (textAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, textSize, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(textImageRelation), out textBounds, out imageBounds);
            }
            else
            {
                // Both image overlays text and text overlays image
                if (textImageRelation == TextImageRelation.Overlay)
                {
                    LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                }
                else
                {
                    Rectangle alignedField = LayoutUtils.Align(newSize, maxFieldRectangle, ContentAlignment.MiddleCenter);
                    LayoutUtils.SplitRegion(alignedField, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                    LayoutUtils.ExpandRegionsToFillBounds(maxFieldRectangle, (AnchorStyles)textImageRelation, ref imageBounds, ref textBounds);
                }
            }
            //set image and text bounds according the size of the field
            if ((textImageRelation == TextImageRelation.TextBeforeImage) || (textImageRelation == TextImageRelation.ImageBeforeText))
            {
                int num1 = Math.Min(textBounds.Bottom, layoutField.Bottom);
                textBounds.Y      = Math.Max(Math.Min(textBounds.Y, layoutField.Y + ((layoutField.Height - textBounds.Height) / 2)), layoutField.Y);
                textBounds.Height = num1 - textBounds.Y;
            }
            if ((textImageRelation == TextImageRelation.TextAboveImage) || (textImageRelation == TextImageRelation.ImageAboveText))
            {
                int num2 = Math.Min(textBounds.Right, layoutField.Right);
                textBounds.X     = Math.Max(Math.Min(textBounds.X, layoutField.X + ((layoutField.Width - textBounds.Width) / 2)), layoutField.X);
                textBounds.Width = num2 - textBounds.X;
            }
            if ((textImageRelation == TextImageRelation.ImageBeforeText) && (imageBounds.Size.Width != 0))
            {
                imageBounds.Width = Math.Max(0, Math.Min(fieldSize.Width - textBounds.Width, imageBounds.Width));
                textBounds.X      = imageBounds.X + imageBounds.Width;
            }
            if ((textImageRelation == TextImageRelation.ImageAboveText) && (imageBounds.Size.Height != 0))
            {
                imageBounds.Height = Math.Max(0, Math.Min(fieldSize.Height - textBounds.Height, imageBounds.Height));
                textBounds.Y       = imageBounds.Y + imageBounds.Height;
            }
            textBounds = Rectangle.Intersect(textBounds, layoutField);

            //align image and if its size is greater than the field's size it is become offseted as much as the difference
            Rectangle newImageBounds = LayoutUtils.Align(imageSize, imageBounds, imageAlign);

            if (newImageBounds.Width > imageBounds.Width)
            {
                newImageBounds.X = imageBounds.Width - imageSize.Width;
            }
            if (newImageBounds.Height > imageBounds.Height)
            {
                newImageBounds.Y = imageBounds.Height - imageSize.Height;
            }

            textBounds = LayoutUtils.Align(textSize, textBounds, textAlign);

            textBounds.Size  = Size.Subtract(textBounds.Size, this.textElement.Margin.Size);
            imageBounds.Size = Size.Subtract(newImageBounds.Size, this.imageElement.Margin.Size);

            if (newLayouts)
            {
                this.textElement.Arrange(textBounds);
                this.imageElement.Arrange(newImageBounds);
            }
            else
            {
                this.textElement.Bounds  = textBounds;
                this.imageElement.Bounds = newImageBounds;
            }
        }
Esempio n. 23
0
        /// <summary>Draws the internal text and image content.</summary>
        /// <param name="graphics">The graphics to draw on.</param>
        /// <param name="rectangle">The coordinates of the rectangle to draw.</param>
        /// <param name="text">The string to draw.</param>
        /// <param name="font">The font to use in the string.</param>
        /// <param name="foreColor">The color of the string.</param>
        /// <param name="image">The image to draw.</param>
        /// <param name="textImageRelation">The text image relation.</param>
        public static void DrawInternalContent(Graphics graphics, Rectangle rectangle, string text, Font font, Color foreColor, VisualBitmap image, TextImageRelation textImageRelation)
        {
            image.Point = GDI.ApplyTextImageRelation(graphics, textImageRelation, new Rectangle(image.Point, image.Size), text, font, rectangle, true);
            Point textPoint = GDI.ApplyTextImageRelation(graphics, textImageRelation, new Rectangle(image.Point, image.Size), text, font, rectangle, false);

            VisualBitmap.DrawImage(graphics, image.Border, image.Point, image.Image, image.Size, image.Visible);
            graphics.DrawString(text, font, new SolidBrush(foreColor), textPoint);
        }
Esempio n. 24
0
 public static void Set_TextImageRelation(this UpgradeHelpers.BasicViewModels.ButtonViewModel _ButtonBase, TextImageRelation TextImageRelation)
 {
     throw new NotImplementedException("This is an automatic generated code, please implement the requested logic.");
 }
Esempio n. 25
0
        /// <summary>Draws the text image relation.</summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="relation">The relation type.</param>
        /// <param name="imageRectangle">The image rectangle.</param>
        /// <param name="text">The text.</param>
        /// <param name="font">The font.</param>
        /// <param name="outerBounds">The outer bounds.</param>
        /// <param name="imagePoint">Return image point.</param>
        /// <returns>The return point.</returns>
        public static Point ApplyTextImageRelation(Graphics graphics, TextImageRelation relation, Rectangle imageRectangle, string text, Font font, Rectangle outerBounds, bool imagePoint)
        {
            Point newPosition   = new Point(0, 0);
            Point newImagePoint = new Point(0, 0);
            Point newTextPoint  = new Point(0, 0);
            Size  textSize      = MeasureText(graphics, text, font);

            switch (relation)
            {
            case TextImageRelation.Overlay:
            {
                // Set center
                newPosition.X = outerBounds.Width / 2;
                newPosition.Y = outerBounds.Height / 2;

                // Set image
                newImagePoint.X = newPosition.X - (imageRectangle.Width / 2);
                newImagePoint.Y = newPosition.Y - (imageRectangle.Height / 2);

                // Set text
                newTextPoint.X = newPosition.X - (textSize.Width / 2);
                newTextPoint.Y = newPosition.Y - (textSize.Height / 2);
                break;
            }

            case TextImageRelation.ImageBeforeText:
            {
                // Set center
                newPosition.Y = outerBounds.Height / 2;

                // Set image
                newImagePoint.X = newPosition.X + 4;
                newImagePoint.Y = newPosition.Y - (imageRectangle.Height / 2);

                // Set text
                newTextPoint.X = newImagePoint.X + imageRectangle.Width;
                newTextPoint.Y = newPosition.Y - (textSize.Height / 2);
                break;
            }

            case TextImageRelation.TextBeforeImage:
            {
                // Set center
                newPosition.Y = outerBounds.Height / 2;

                // Set text
                newTextPoint.X = newPosition.X + 4;
                newTextPoint.Y = newPosition.Y - (textSize.Height / 2);

                // Set image
                newImagePoint.X = newTextPoint.X + textSize.Width;
                newImagePoint.Y = newPosition.Y - (imageRectangle.Height / 2);
                break;
            }

            case TextImageRelation.ImageAboveText:
            {
                // Set center
                newPosition.X = outerBounds.Width / 2;

                // Set image
                newImagePoint.X = newPosition.X - (imageRectangle.Width / 2);
                newImagePoint.Y = newPosition.Y + 4;

                // Set text
                newTextPoint.X = newPosition.X - (textSize.Width / 2);
                newTextPoint.Y = newImagePoint.Y + imageRectangle.Height;
                break;
            }

            case TextImageRelation.TextAboveImage:
            {
                // Set center
                newPosition.X = outerBounds.Width / 2;

                // Set text
                newTextPoint.X = newPosition.X - (textSize.Width / 2);
                newTextPoint.Y = newImagePoint.Y + 4;

                // Set image
                newImagePoint.X = newPosition.X - (imageRectangle.Width / 2);
                newImagePoint.Y = newPosition.Y + textSize.Height + 4;
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(relation), relation, null);
            }
            }

            if (imagePoint)
            {
                return(newImagePoint);
            }
            else
            {
                return(newTextPoint);
            }
        }
Esempio n. 26
0
        public GitToolbar(GuiProvider guiProvider)
        {
            Verify.Argument.IsNotNull(guiProvider, "guiProvider");

            _guiProvider = guiProvider;

            Text = Resources.StrGit;

            const TextImageRelation         tir = TextImageRelation.ImageAboveText;
            const ToolStripItemDisplayStyle ds  = ToolStripItemDisplayStyle.ImageAndText;

            Items.AddRange(new ToolStripItem[]
            {
                _fetchButton = new ToolStripSplitButton(Resources.StrFetch, CachedResources.Bitmaps["ImgFetch"])
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipFetch
                },
                _pullButton = new ToolStripSplitButton(Resources.StrPull, CachedResources.Bitmaps["ImgPull"])
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipPull
                },
                _pushButton = new ToolStripButton(Resources.StrPush, CachedResources.Bitmaps["ImgPush"])
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipPush
                },
                new ToolStripSeparator(),
                _historyButton = new ToolStripButton(Resources.StrHistory, CachedResources.Bitmaps["ImgHistory"], OnHistoryClick)
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipHistory
                },
                new ToolStripSeparator(),
                _commitButton = new ToolStripButton(Resources.StrCommit, CachedResources.Bitmaps["ImgCommit"], OnCommitClick)
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipCommit
                },
                _applyPatchButton = new ToolStripButton(Resources.StrPatch, CachedResources.Bitmaps["ImgPatchApply"], OnApplyPatchClick)
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipApplyPatches
                },
                _stashButton = new ToolStripSplitButton(Resources.StrStash, CachedResources.Bitmaps["ImgStash"])
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipStash
                },
                _cleanButton = new ToolStripButton(Resources.StrClean, CachedResources.Bitmaps["ImgClean"], OnCleanClick)
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipClean
                },
                new ToolStripSeparator(),
                _checkoutButton = new ToolStripButton(Resources.StrCheckout, CachedResources.Bitmaps["ImgCheckout"], OnCheckoutClick)
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipCheckoutBranch
                },
                _branchButton = new ToolStripButton(Resources.StrBranch, CachedResources.Bitmaps["ImgBranch"], OnBranchClick)
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipCreateBranch
                },
                _mergeButton = new ToolStripSplitButton(Resources.StrMerge, CachedResources.Bitmaps["ImgMerge"])
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipMerge
                },
                new ToolStripSeparator(),
                _tagButton = new ToolStripButton(Resources.StrTag, CachedResources.Bitmaps["ImgTag"], OnTagClick)
                {
                    TextImageRelation = tir, DisplayStyle = ds, ToolTipText = Resources.TipCreateTag
                },
                _noteButton = new ToolStripButton(Resources.StrNote, CachedResources.Bitmaps["ImgNote"], OnNoteClick)
                {
                    TextImageRelation = tir, DisplayStyle = ds, Available = false                               /* GitFeatures.AdvancedNotesCommands.IsAvailable */
                },
            });

            _fetchButton.ButtonClick += OnFetchClick;
            _pullButton.ButtonClick  += OnPullClick;
            _pushButton.Click        += OnPushClick;

            _mergeButton.ButtonClick += OnMergeClick;

            _mergeButton.DropDown.Items.Add(
                _mergeMultipleItem = new ToolStripMenuItem(Resources.StrMergeMultipleBranches, null, OnMultipleMergeClick));

            _stashButton.ButtonClick += OnStashClick;
            _stashButton.DropDown.Items.Add(
                _stashPopItem = new ToolStripMenuItem(Resources.StrSave, CachedResources.Bitmaps["ImgStashSave"], OnStashSaveClick));
            _stashButton.DropDown.Items.Add(
                _stashPopItem = new ToolStripMenuItem(Resources.StrPop, CachedResources.Bitmaps["ImgStashPop"], OnStashPopClick));
            _stashButton.DropDown.Items.Add(
                _stashApplyItem = new ToolStripMenuItem(Resources.StrApply, CachedResources.Bitmaps["ImgStashApply"], OnStashApplyClick));

            if (guiProvider.Repository != null)
            {
                AttachToRepository(guiProvider.Repository);
            }
        }
Esempio n. 27
0
 public static bool IsHorizontalRelation(TextImageRelation relation)
 {
     return((relation & (TextImageRelation.ImageBeforeText | TextImageRelation.TextBeforeImage)) != TextImageRelation.Overlay);
 }
Esempio n. 28
0
        public virtual void InitPopupCommandButtonLayout(
            ToolStripPanel toolStripPanel,
            IView hostedView,
            Size btnSize,
            bool isTextShown,
            ContentAlignment txtAlign,
            TextImageRelation txtImgRelation,
            Font font,
            IResourceService resourceService,
            EventHandler buttonClickHandler)
        {
            if (hostedView == null)
                return;

            foreach (Control control in toolStripPanel.Controls)
            {
                ToolStrip toolStrip = control as ToolStrip;
                if (toolStrip != null)
                {
                    toolStrip.ImageScalingSize = btnSize;

                    IDictionary<string, CommandStatus> commandButtonList = GetCommandButtonList(hostedView.ProgramID);
                    IEnumerator<KeyValuePair<string, CommandStatus>> enumerator = commandButtonList.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        ToolStripButton toolStripButton = new ToolStripButton();
                        string commandKey = enumerator.Current.Key;
                        toolStripButton.Image = GetIcon("img" + commandKey, RESOURCE_TYPE);
                        toolStripButton.Name = commandKey;
                        toolStripButton.ToolTipText = commandKey;
                        toolStripButton.Click += buttonClickHandler;
                        toolStrip.Items.Add(toolStripButton);
                    }

                    toolStripPanel.Controls.Add(toolStrip);
                    hostedView.AvailButtonList = commandButtonList;
                }
            }
        }
Esempio n. 29
0
 public static bool IsVerticalRelation(TextImageRelation relation)
 {
     return((relation & (TextImageRelation.ImageAboveText | TextImageRelation.TextAboveImage)) != TextImageRelation.Overlay);
 }
 public static bool IsValidTextImageRelation(TextImageRelation relation)
 {
 }
Esempio n. 31
0
 public static TextImageRelation GetOppositeTextImageRelation(TextImageRelation relation)
 {
     return((TextImageRelation)GetOppositeAnchor((AnchorStyles)relation));
 }
Esempio n. 32
0
 public static Size AddAlignedRegion(Size textSize, Size imageSize, TextImageRelation relation)
 {
     return(AddAlignedRegionCore(textSize, imageSize, IsVerticalRelation(relation)));
 }
Esempio n. 33
0
 // True if text & image should be lined up horizontally.  False if vertical or overlay.
 public static bool IsHorizontalRelation(TextImageRelation relation)
 {
     return((relation & (TextImageRelation.TextBeforeImage | TextImageRelation.ImageBeforeText)) != 0);
 }
Esempio n. 34
0
 public static TextImageRelation GetOppositeTextImageRelation(TextImageRelation relation) {
     return (TextImageRelation) GetOppositeAnchor((AnchorStyles)relation);
 }
Esempio n. 35
0
 // True if text & image should be lined up vertically.  False if horizontal or overlay.
 public static bool IsVerticalRelation(TextImageRelation relation)
 {
     return((relation & (TextImageRelation.TextAboveImage | TextImageRelation.ImageAboveText)) != 0);
 }
Esempio n. 36
0
 // True if text & image should be lined up horizontally.  False if vertical or overlay.
 public static bool IsHorizontalRelation(TextImageRelation relation) {
     return (relation & (TextImageRelation.TextBeforeImage | TextImageRelation.ImageBeforeText)) != 0;
 }
Esempio n. 37
0
 public static Size SubAlignedRegion(Size currentSize, Size contentSize, TextImageRelation relation)
 {
     return(SubAlignedRegionCore(currentSize, contentSize, IsVerticalRelation(relation)));
 }
Esempio n. 38
0
 public static Size SubAlignedRegion(Size currentSize, Size contentSize, TextImageRelation relation) {
     return SubAlignedRegionCore(currentSize, contentSize, IsVerticalRelation(relation));
 }
        /// <summary>Draws a button control.</summary>
        /// <param name="graphics">The graphics to draw on.</param>
        /// <param name="rectangle">The coordinates of the rectangle to draw.</param>
        /// <param name="backColor">The BackColor of the button.</param>
        /// <param name="backgroundImage">The background image for the button.</param>
        /// <param name="border">The border.</param>
        /// <param name="mouseState">The mouse State.</param>
        /// <param name="text">The string to draw.</param>
        /// <param name="font">The font to use in the string.</param>
        /// <param name="foreColor">The color of the string.</param>
        /// <param name="image">The image to draw.</param>
        /// <param name="imageSize">The image Size.</param>
        /// <param name="textImageRelation">The text image relation.</param>
        public static void DrawButton(Graphics graphics, Rectangle rectangle, Color backColor, Image backgroundImage, Border border, MouseStates mouseState, string text, Font font, Color foreColor, Image image, Size imageSize, TextImageRelation textImageRelation)
        {
            GraphicsPath _controlGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(rectangle, border);

            VisualBackgroundRenderer.DrawBackground(graphics, backColor, backgroundImage, mouseState, rectangle, border);
            DrawContent(graphics, rectangle, text, font, foreColor, image, imageSize, textImageRelation);
            VisualBorderRenderer.DrawBorderStyle(graphics, border, _controlGraphicsPath, mouseState);
        }
		protected ToolStripItem (string text, Image image, EventHandler onClick, string name)
		{
			this.alignment = ToolStripItemAlignment.Left;
			this.anchor = AnchorStyles.Left | AnchorStyles.Top;
			this.auto_size = true;
			this.auto_tool_tip = this.DefaultAutoToolTip;
			this.available = true;
			this.back_color = Color.Empty;
			this.background_image_layout = ImageLayout.Tile;
			this.can_select = true;
			this.display_style = this.DefaultDisplayStyle;
			this.dock = DockStyle.None;
			this.enabled = true;
			this.fore_color = Color.Empty;
			this.image = image;
			this.image_align = ContentAlignment.MiddleCenter;
			this.image_index = -1;
			this.image_key = string.Empty;
			this.image_scaling = ToolStripItemImageScaling.SizeToFit;
			this.image_transparent_color = Color.Empty;
			this.margin = this.DefaultMargin;
			this.merge_action = MergeAction.Append;
			this.merge_index = -1;
			this.name = name;
			this.overflow = ToolStripItemOverflow.AsNeeded;
			this.padding = this.DefaultPadding;
			this.placement = ToolStripItemPlacement.None;
			this.right_to_left = RightToLeft.Inherit;
			this.bounds.Size = this.DefaultSize;
			this.text = text;
			this.text_align = ContentAlignment.MiddleCenter;
			this.text_direction = DefaultTextDirection;
			this.text_image_relation = TextImageRelation.ImageBeforeText;
			this.visible = true;

			this.Click += onClick;
			OnLayout (new LayoutEventArgs (null, string.Empty));
		}
        /// <summary>Draws the text and image content.</summary>
        /// <param name="graphics">The graphics to draw on.</param>
        /// <param name="rectangle">The coordinates of the rectangle to draw.</param>
        /// <param name="text">The string to draw.</param>
        /// <param name="font">The font to use in the string.</param>
        /// <param name="foreColor">The color of the string.</param>
        /// <param name="image">The image to draw.</param>
        /// <param name="imageSize">The image Size.</param>
        /// <param name="textImageRelation">The text image relation.</param>
        public static void DrawContent(Graphics graphics, Rectangle rectangle, string text, Font font, Color foreColor, Image image, Size imageSize, TextImageRelation textImageRelation)
        {
            Rectangle _imageRectangle = new Rectangle(new Point(), imageSize);
            Point     _imagePoint     = RelationManager.GetTextImageRelationLocation(graphics, textImageRelation, _imageRectangle, text, font, rectangle, true);
            Point     _textPoint      = RelationManager.GetTextImageRelationLocation(graphics, textImageRelation, _imageRectangle, text, font, rectangle, false);

            graphics.DrawImage(image, new Rectangle(_imagePoint, imageSize));
            graphics.DrawString(text, font, new SolidBrush(foreColor), _textPoint);
        }
Esempio n. 42
0
 private string GetStrFromTextImageRelation(TextImageRelation t)
 {
     string s = null;
     if (t == TextImageRelation.ImageAboveText)
     {
         s = "ImageAboveText";
     }
     else if (t == TextImageRelation.ImageBeforeText)
     {
         s = "ImageBeforeText";
     }
     else if (t == TextImageRelation.Overlay)
     {
         s = "Overlay";
     }
     else if (t == TextImageRelation.TextAboveImage)
     {
         s = "TextAboveImage";
     }
     else if (t == TextImageRelation.TextBeforeImage)
     {
         s = "TextBeforeImage";
     }
     if (string.IsNullOrEmpty(s))
     {
         s = "ImageBeforeText";
         return s;
     }
     else
     {
         return s;
     }
 }
 public static bool IsValidTextImageRelation(TextImageRelation relation)
 {
     return System.Windows.Forms.ClientUtils.IsEnumValid(relation, (int) relation, 0, 8, 1);
 }