예제 #1
0
		protected override Size OnArrange(Size finalSize)
		{
			if (m_Image == null)
			{
				if (m_Text != null)
				{
					Size innerSize = finalSize - Padding;
					Size textSize = m_Text.MeasuredSize + m_TextPadding;
					Rectangle rect = new Rectangle(Point.Zero, textSize);

					if ((m_Align & Alignment.CenterH) != 0)
						rect.X = (innerSize.Width - rect.Width) / 2;
					else if ((m_Align & Alignment.Right) != 0)
						rect.X = innerSize.Width - rect.Width;

					if ((m_Align & Alignment.CenterV) != 0)
						rect.Y = (innerSize.Height - rect.Height) / 2;
					else if ((m_Align & Alignment.Bottom) != 0)
						rect.Y = innerSize.Height - rect.Height;

					rect.Offset(m_TextPadding + Padding);

					m_Text.Arrange(rect);
				}
			}
			else
			{
				Size innerSize = finalSize - Padding;

				Size imageSize = m_Image.MeasuredSize;
				Size textSize = m_Text != null ? m_Text.MeasuredSize + m_TextPadding : Size.Zero;

				Rectangle rect;
				switch (m_ImageAlign)
				{
					case ImageAlign.LeftSide:
						rect = new Rectangle(Point.Zero, textSize.Width + imageSize.Width, Math.Max(imageSize.Height, textSize.Height));
						break;
					case ImageAlign.Above:
						rect = new Rectangle(Point.Zero, Math.Max(imageSize.Width, textSize.Width), textSize.Height + imageSize.Height);
						break;
					default:
						rect = new Rectangle(Point.Zero, textSize);
						break;
				}

				if ((m_Align & Alignment.Right) != 0)
					rect.X = innerSize.Width - rect.Width;
				else if ((m_Align & Alignment.CenterH) != 0)
					rect.X = (innerSize.Width - rect.Width) / 2;
				if ((m_Align & Alignment.Bottom) != 0)
					rect.Y = innerSize.Height - rect.Height;
				else if ((m_Align & Alignment.CenterV) != 0)
					rect.Y = (innerSize.Height - rect.Height) / 2;

				Rectangle imageRect = new Rectangle(Point.Zero, imageSize);
				Rectangle textRect = new Rectangle(rect.Location, m_Text != null ? m_Text.MeasuredSize : Size.Zero);

				switch (m_ImageAlign)
				{
					case ImageAlign.LeftSide:
						imageRect.Location = new Point(rect.X, rect.Y + (rect.Height - imageSize.Height) / 2);
						textRect.Location = new Point(rect.X + imageSize.Width, rect.Y + (rect.Height - textSize.Height) / 2);
						break;
					case ImageAlign.Above:
						imageRect.Location = new Point(rect.X + (rect.Width - imageSize.Width) / 2, rect.Y);
						textRect.Location = new Point(rect.X + (rect.Width - textSize.Width) / 2, rect.Y + imageSize.Height);
						break;
					case ImageAlign.Fill:
						imageRect.Size = innerSize;
						break;
					default:
						if ((m_ImageAlign & ImageAlign.Right) != 0)
							imageRect.X = innerSize.Width - imageRect.Width;
						else if ((m_ImageAlign & ImageAlign.CenterH) != 0)
							imageRect.X = (innerSize.Width - imageRect.Width) / 2;
						if ((m_ImageAlign & ImageAlign.Bottom) != 0)
							imageRect.Y = innerSize.Height - imageRect.Height;
						else if ((m_ImageAlign & ImageAlign.CenterV) != 0)
							imageRect.Y = (innerSize.Height - imageRect.Height) / 2;
						break;
				}

				imageRect.Offset(Padding);
				m_Image.Arrange(imageRect);

				if (m_Text != null)
				{
					textRect.Offset(Padding + m_TextPadding);
					m_Text.Arrange(textRect);
				}
			}

			return finalSize;
		}
예제 #2
0
        protected void Rebuild()
        {
            m_Updating = true;

            DeleteAllChildren();

            Size size = Size.Zero;

            if (m_Document != null && m_Document.Paragraphs.Count > 0)
            {
#if USE_KNUTH_PLASS_LINE_BREAKING
                LineBreaker lineBreaker = new RichText.KnuthPlass.LineBreaker(Skin.Renderer, Skin.DefaultFont);
#else
                LineBreaker lineBreaker = new RichText.Simple.LineBreaker(Skin.Renderer, Skin.DefaultFont);
#endif

                int y = 0;
                int x;
                int width;
                int height;

                foreach (Paragraph paragraph in m_Document.Paragraphs)
                {
                    if (paragraph is ImageParagraph)
                    {
                        ImageParagraph imageParagraph = paragraph as ImageParagraph;

                        ImagePanel image = new ImagePanel(this);
                        image.ImageName = imageParagraph.ImageName;
                        if (imageParagraph.ImageSize != null)
                        {
                            image.Size = (Size)imageParagraph.ImageSize;
                        }
                        if (imageParagraph.TextureRect != null)
                        {
                            image.TextureRect = (Rectangle)imageParagraph.TextureRect;
                        }
                        if (imageParagraph.ImageColor != null)
                        {
                            image.ImageColor = (Color)imageParagraph.ImageColor;
                        }

                        image.Measure(Size.Infinity);
                        image.Arrange(paragraph.Margin.Left, y + paragraph.Margin.Top, image.MeasuredSize.Width, image.MeasuredSize.Height);

                        size.Width = Math.Max(size.Width, image.MeasuredSize.Width + paragraph.Margin.Left + paragraph.Margin.Right);

                        y += image.MeasuredSize.Height + paragraph.Margin.Top + paragraph.Margin.Bottom;
                    }
                    else
                    {
                        List <TextBlock> textBlocks = lineBreaker.LineBreak(paragraph, m_BuildWidth);

                        if (textBlocks != null)
                        {
                            x      = paragraph.Margin.Left;
                            y     += paragraph.Margin.Top;
                            width  = 0;
                            height = 0;

                            foreach (TextBlock textBlock in textBlocks)
                            {
                                if (textBlock.Part is LinkPart)
                                {
                                    LinkPart linkPart = textBlock.Part as LinkPart;

                                    LinkLabel link = new LinkLabel(this);
                                    link.Text         = textBlock.Text;
                                    link.Link         = linkPart.Link;
                                    link.Font         = linkPart.Font;
                                    link.LinkClicked += OnLinkClicked;
                                    if (linkPart.Color != null)
                                    {
                                        link.TextColor = (Color)linkPart.Color;
                                    }
                                    if (linkPart.HoverColor != null)
                                    {
                                        link.HoverColor = (Color)linkPart.HoverColor;
                                    }
                                    if (linkPart.HoverFont != null)
                                    {
                                        link.HoverFont = linkPart.HoverFont;
                                    }

                                    link.Measure(Size.Infinity);
                                    link.Arrange(new Rectangle(x + textBlock.Position.X, y + textBlock.Position.Y, textBlock.Size.Width, textBlock.Size.Height));

                                    width  = Math.Max(width, link.ActualRight);
                                    height = Math.Max(height, link.ActualBottom);
                                }
                                else if (textBlock.Part is TextPart)
                                {
                                    TextPart textPart = textBlock.Part as TextPart;

                                    Text text = new Text(this);
                                    text.String = textBlock.Text;
                                    text.Font   = textPart.Font;
                                    if (textPart.Color != null)
                                    {
                                        text.TextColor = (Color)textPart.Color;
                                    }

                                    text.Measure(Size.Infinity);
                                    text.Arrange(new Rectangle(x + textBlock.Position.X, y + textBlock.Position.Y, textBlock.Size.Width, textBlock.Size.Height));

                                    width  = Math.Max(width, text.ActualRight + 1);
                                    height = Math.Max(height, text.ActualBottom + 1);
                                }
                            }

                            size.Width = Math.Max(size.Width, width + paragraph.Margin.Right);

                            y = height + paragraph.Margin.Bottom;
                        }
                    }
                }

                size.Height = y;
            }

            m_TextSize = size;

            m_NeedsRebuild = false;

            m_Updating = false;
        }