public void EqualTest()
		{
			Rectangle rect = new Rectangle(0, 0, 100, 100);
			Rectangle rect2 = new Rectangle(10, 10, 90, 90);
			Size size = new Size(20, 20);
			Size size2 = new Size(30, 30);
			NuGenToolTipLayoutDescriptor descriptor = new NuGenToolTipLayoutDescriptor();
			NuGenToolTipLayoutDescriptor descriptor2 = new NuGenToolTipLayoutDescriptor();
			descriptor.BevelBounds = descriptor2.BevelBounds = rect;
			descriptor.HeaderBounds = descriptor2.HeaderBounds = rect;
			descriptor.ImageBounds = descriptor2.ImageBounds = rect;
			descriptor.RemarksBounds = descriptor2.RemarksBounds = rect;
			descriptor.RemarksHeaderBounds = descriptor2.RemarksHeaderBounds = rect;
			descriptor.RemarksImageBounds = descriptor2.RemarksImageBounds = rect;
			descriptor.TextBounds = descriptor2.TextBounds = rect;
			descriptor.TooltipSize = descriptor2.TooltipSize = size;

			NuGenToolTipLayoutDescriptor descriptor3 = new NuGenToolTipLayoutDescriptor();
			descriptor3.BevelBounds = rect;
			descriptor3.HeaderBounds = rect;
			descriptor3.ImageBounds = rect2;
			descriptor3.RemarksBounds = rect2;
			descriptor3.RemarksHeaderBounds = rect;
			descriptor3.RemarksImageBounds = rect;
			descriptor3.TextBounds = rect;
			descriptor3.TooltipSize = size2;

			Assert.AreEqual(descriptor, descriptor2);
			Assert.IsTrue(descriptor == descriptor2);
			Assert.IsTrue(descriptor != descriptor3);
			Assert.AreNotEqual(descriptor, 25);
		}
Пример #2
0
        /// <summary>
        /// Indicates whether this instance and a specified object are equal.
        /// </summary>
        /// <param name="obj">Another object to compare to.</param>
        /// <returns>
        /// true if obj and this instance are the same type and represent the same value; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj is NuGenToolTipLayoutDescriptor)
            {
                NuGenToolTipLayoutDescriptor compared = (NuGenToolTipLayoutDescriptor)obj;

                if (
                    compared.BevelBounds == this.BevelBounds &&
                    compared.HeaderBounds == this.HeaderBounds &&
                    compared.ImageBounds == this.ImageBounds &&
                    compared.RemarksBounds == this.RemarksBounds &&
                    compared.RemarksHeaderBounds == this.RemarksHeaderBounds &&
                    compared.RemarksImageBounds == this.RemarksImageBounds &&
                    compared.TextBounds == this.TextBounds
                    )
                {
                    return(compared.TooltipSize == this.TooltipSize);
                }
            }

            return(false);
        }
		/// <summary>
		/// </summary>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="g"/> is <see langword="null"/>.</para>
		/// -or-
		/// <para><paramref name="tooltipInfo"/> is <see langword="null"/>.</para>
		/// -or-
		/// <para><paramref name="headerFont"/> is <see langword="null"/>.</para>
		/// -or-
		/// <para><paramref name="textFont"/> is <see langword="null"/>.</para>
		/// </exception>
		public NuGenToolTipLayoutDescriptor BuildLayoutDescriptor(
			Graphics g,
			NuGenToolTipInfo tooltipInfo,
			Font headerFont,
			Font textFont
			)
		{
			if (g == null)
			{
				throw new ArgumentNullException("g");
			}

			if (tooltipInfo == null)
			{
				throw new ArgumentNullException("tooltipInfo");
			}

			if (headerFont == null)
			{
				throw new ArgumentNullException("headerFont");
			}

			if (textFont == null)
			{
				throw new ArgumentNullException("textFont");
			}

			NuGenToolTipLayoutDescriptor descriptor = new NuGenToolTipLayoutDescriptor();

			Size tooltipSize = tooltipInfo.IsCustomSize
				? tooltipInfo.CustomSize
				: this.GetAutoSize(g, tooltipInfo, headerFont, textFont)
				;

			Rectangle rect = new Rectangle(new Point(0, 0), tooltipSize);

			Padding headerPadding = _headerPadding;
			Padding remarksHeaderPadding = _remarksHeaderPadding;
			Padding textPadding = NuGenToolTipLayoutManager.GetTextPadding(tooltipInfo);
			Padding imagePadding = _imagePadding;

			/* Header */

			if (tooltipInfo.IsHeaderVisible)
			{
				Rectangle headerRect = new Rectangle(
					rect.X + headerPadding.Left,
					rect.Y + headerPadding.Top,
					rect.Width - headerPadding.Horizontal,
					rect.Height - headerPadding.Vertical
				);

				descriptor.HeaderBounds = headerRect;
				Size headerSize = g.MeasureString(tooltipInfo.Header, headerFont, headerRect.Width).ToSize();
				headerSize.Width += headerPadding.Horizontal;
				headerSize.Height += headerPadding.Vertical;
				rect.Y += headerSize.Height;
				rect.Height -= headerSize.Height;
			}

			/* Remarks */

			if (tooltipInfo.IsRemarksHeaderVisible && rect.Width > 0 && rect.Height > 0)
			{
				if (tooltipInfo.IsRemarksVisible)
				{
					int offset = remarksHeaderPadding.Left;

					if (tooltipInfo.IsRemarksImageVisible)
					{
						offset += tooltipInfo.RemarksImage.Width + imagePadding.Horizontal;
					}

					int remarksTextWidth = rect.Width - offset;
					Size remarksSize = g.MeasureString(tooltipInfo.Remarks, textFont, remarksTextWidth).ToSize();

					Rectangle remarksRect = new Rectangle(
						rect.X + offset,
						rect.Bottom - remarksSize.Height - textPadding.Vertical,
						remarksTextWidth,
						remarksSize.Height
					);

					descriptor.RemarksBounds = remarksRect;
					rect.Height -= (remarksRect.Height + textPadding.Vertical);
				}

				Size remarksHeaderSize = g.MeasureString(tooltipInfo.RemarksHeader, headerFont, rect.Width - remarksHeaderPadding.Horizontal).ToSize();
				Image remarksImage = tooltipInfo.RemarksImage;

				if (tooltipInfo.IsRemarksImageVisible && remarksImage.Height > remarksHeaderSize.Height)
				{
					remarksHeaderSize.Height = remarksImage.Height;
				}

				Rectangle remarksHeaderRect = new Rectangle(
					rect.X + remarksHeaderPadding.Left,
					rect.Bottom - remarksHeaderSize.Height - remarksHeaderPadding.Bottom,
					rect.Width - remarksHeaderPadding.Horizontal,
					remarksHeaderSize.Height
				);

				int bevelTop = remarksHeaderRect.Y - remarksHeaderPadding.Top - 1;
				descriptor.BevelBounds = new Rectangle(headerPadding.Horizontal, bevelTop, tooltipSize.Width - headerPadding.Horizontal, bevelTop);

				if (remarksImage != null)
				{
					descriptor.RemarksImageBounds = new Rectangle(
						remarksHeaderRect.X,
						remarksHeaderRect.Y + (remarksHeaderRect.Height - remarksImage.Height) / 2,
						remarksImage.Width,
						remarksImage.Height
					);

					remarksHeaderRect.X += (remarksImage.Width + _remarksImageOffset);
					remarksHeaderRect.Width -= (remarksImage.Width + _remarksImageOffset);
				}

				descriptor.RemarksHeaderBounds = remarksHeaderRect;

				remarksHeaderSize.Width += remarksHeaderPadding.Horizontal;
				remarksHeaderSize.Height += remarksHeaderPadding.Vertical;

				rect.Height -= remarksHeaderSize.Height;
			}

			/* Image */

			Image image = tooltipInfo.Image;

			if (tooltipInfo.IsImageVisible)
			{
				Rectangle imageRect = new Rectangle(
					rect.X + imagePadding.Left,
					rect.Y + imagePadding.Top,
					image.Width,
					image.Width
				);

				descriptor.ImageBounds = imageRect;

				rect.X += (imagePadding.Horizontal + image.Width);
				rect.Width -= (imagePadding.Horizontal + image.Width);
			}

			/* Text */

			if (tooltipInfo.IsTextVisible && rect.Width > 0 && rect.Height > 0)
			{
				Rectangle textRect = new Rectangle(
					rect.X + textPadding.Left,
					rect.Y + textPadding.Top,
					rect.Width - textPadding.Horizontal,
					rect.Height - textPadding.Vertical
				);

				descriptor.TextBounds = textRect;
			}

			Size shadowSize = this.GetShadowSize();
			descriptor.TooltipSize = new Size(tooltipSize.Width + shadowSize.Width, tooltipSize.Height + shadowSize.Height);

			return descriptor;
		}
Пример #4
0
        /// <summary>
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="g"/> is <see langword="null"/>.</para>
        /// -or-
        /// <para><paramref name="tooltipInfo"/> is <see langword="null"/>.</para>
        /// -or-
        /// <para><paramref name="headerFont"/> is <see langword="null"/>.</para>
        /// -or-
        /// <para><paramref name="textFont"/> is <see langword="null"/>.</para>
        /// </exception>
        public NuGenToolTipLayoutDescriptor BuildLayoutDescriptor(
            Graphics g,
            NuGenToolTipInfo tooltipInfo,
            Font headerFont,
            Font textFont
            )
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            if (tooltipInfo == null)
            {
                throw new ArgumentNullException("tooltipInfo");
            }

            if (headerFont == null)
            {
                throw new ArgumentNullException("headerFont");
            }

            if (textFont == null)
            {
                throw new ArgumentNullException("textFont");
            }

            NuGenToolTipLayoutDescriptor descriptor = new NuGenToolTipLayoutDescriptor();

            Size tooltipSize = tooltipInfo.IsCustomSize
                                ? tooltipInfo.CustomSize
                                : this.GetAutoSize(g, tooltipInfo, headerFont, textFont)
            ;

            Rectangle rect = new Rectangle(new Point(0, 0), tooltipSize);

            Padding headerPadding        = _headerPadding;
            Padding remarksHeaderPadding = _remarksHeaderPadding;
            Padding textPadding          = NuGenToolTipLayoutManager.GetTextPadding(tooltipInfo);
            Padding imagePadding         = _imagePadding;

            /* Header */

            if (tooltipInfo.IsHeaderVisible)
            {
                Rectangle headerRect = new Rectangle(
                    rect.X + headerPadding.Left,
                    rect.Y + headerPadding.Top,
                    rect.Width - headerPadding.Horizontal,
                    rect.Height - headerPadding.Vertical
                    );

                descriptor.HeaderBounds = headerRect;
                Size headerSize = g.MeasureString(tooltipInfo.Header, headerFont, headerRect.Width).ToSize();
                headerSize.Width  += headerPadding.Horizontal;
                headerSize.Height += headerPadding.Vertical;
                rect.Y            += headerSize.Height;
                rect.Height       -= headerSize.Height;
            }

            /* Remarks */

            if (tooltipInfo.IsRemarksHeaderVisible && rect.Width > 0 && rect.Height > 0)
            {
                if (tooltipInfo.IsRemarksVisible)
                {
                    int offset = remarksHeaderPadding.Left;

                    if (tooltipInfo.IsRemarksImageVisible)
                    {
                        offset += tooltipInfo.RemarksImage.Width + imagePadding.Horizontal;
                    }

                    int  remarksTextWidth = rect.Width - offset;
                    Size remarksSize      = g.MeasureString(tooltipInfo.Remarks, textFont, remarksTextWidth).ToSize();

                    Rectangle remarksRect = new Rectangle(
                        rect.X + offset,
                        rect.Bottom - remarksSize.Height - textPadding.Vertical,
                        remarksTextWidth,
                        remarksSize.Height
                        );

                    descriptor.RemarksBounds = remarksRect;
                    rect.Height -= (remarksRect.Height + textPadding.Vertical);
                }

                Size  remarksHeaderSize = g.MeasureString(tooltipInfo.RemarksHeader, headerFont, rect.Width - remarksHeaderPadding.Horizontal).ToSize();
                Image remarksImage      = tooltipInfo.RemarksImage;

                if (tooltipInfo.IsRemarksImageVisible && remarksImage.Height > remarksHeaderSize.Height)
                {
                    remarksHeaderSize.Height = remarksImage.Height;
                }

                Rectangle remarksHeaderRect = new Rectangle(
                    rect.X + remarksHeaderPadding.Left,
                    rect.Bottom - remarksHeaderSize.Height - remarksHeaderPadding.Bottom,
                    rect.Width - remarksHeaderPadding.Horizontal,
                    remarksHeaderSize.Height
                    );

                int bevelTop = remarksHeaderRect.Y - remarksHeaderPadding.Top - 1;
                descriptor.BevelBounds = new Rectangle(headerPadding.Horizontal, bevelTop, tooltipSize.Width - headerPadding.Horizontal, bevelTop);

                if (remarksImage != null)
                {
                    descriptor.RemarksImageBounds = new Rectangle(
                        remarksHeaderRect.X,
                        remarksHeaderRect.Y + (remarksHeaderRect.Height - remarksImage.Height) / 2,
                        remarksImage.Width,
                        remarksImage.Height
                        );

                    remarksHeaderRect.X     += (remarksImage.Width + _remarksImageOffset);
                    remarksHeaderRect.Width -= (remarksImage.Width + _remarksImageOffset);
                }

                descriptor.RemarksHeaderBounds = remarksHeaderRect;

                remarksHeaderSize.Width  += remarksHeaderPadding.Horizontal;
                remarksHeaderSize.Height += remarksHeaderPadding.Vertical;

                rect.Height -= remarksHeaderSize.Height;
            }

            /* Image */

            Image image = tooltipInfo.Image;

            if (tooltipInfo.IsImageVisible)
            {
                Rectangle imageRect = new Rectangle(
                    rect.X + imagePadding.Left,
                    rect.Y + imagePadding.Top,
                    image.Width,
                    image.Width
                    );

                descriptor.ImageBounds = imageRect;

                rect.X     += (imagePadding.Horizontal + image.Width);
                rect.Width -= (imagePadding.Horizontal + image.Width);
            }

            /* Text */

            if (tooltipInfo.IsTextVisible && rect.Width > 0 && rect.Height > 0)
            {
                Rectangle textRect = new Rectangle(
                    rect.X + textPadding.Left,
                    rect.Y + textPadding.Top,
                    rect.Width - textPadding.Horizontal,
                    rect.Height - textPadding.Vertical
                    );

                descriptor.TextBounds = textRect;
            }

            Size shadowSize = this.GetShadowSize();

            descriptor.TooltipSize = new Size(tooltipSize.Width + shadowSize.Width, tooltipSize.Height + shadowSize.Height);

            return(descriptor);
        }