public override void Paint(MNPageContext context) { Graphics g = context.g; SMImageButton pi = this; Rectangle rect = Area.GetBounds(context); SMStatusLayout layout = PrepareBrushesAndPens(); DrawStyledBackground(context, layout, rect); DrawStyledBorder(context, layout, rect); Rectangle bounds = ContentPadding.ApplyPadding(rect); Rectangle imageBounds = Rectangle.Empty; Rectangle textBounds = Rectangle.Empty; SMContentArangement argm = this.ContentArangement; SMContentScaling ContentScaling = SMContentScaling.Fit; Image image = GetContentImage(); if (image == null) { argm = SMContentArangement.TextOnly; } if (argm == SMContentArangement.ImageOnly) { SMContentScaling scaling = ContentScaling; Rectangle rc = DrawImage(context, null, bounds, image, scaling, 0, 0); showRect = rc; } else { Rectangle imgRect = bounds; Size textSize = Size.Empty; Font usedFont = GetUsedFont(); string plainText = Text; if (plainText.Length != 0) { textSize = rt.MeasureString(context, plainText, bounds.Width); } Rectangle textRect = bounds; if (argm == SMContentArangement.ImageAbove) { textRect.Height = textSize.Height; textRect.Y = bounds.Bottom - textRect.Height; textRect.X = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2; textRect.Width = textSize.Width; imgRect.Height = bounds.Height - textRect.Height - ContentPadding.Top; } else if (argm == SMContentArangement.ImageBelow) { textRect.Height = textSize.Height; textRect.X = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2; textRect.Width = textSize.Width; imgRect.Y = textRect.Bottom + ContentPadding.Bottom; imgRect.Height = bounds.Height - textRect.Height - ContentPadding.Bottom; } else if (argm == SMContentArangement.ImageOnLeft) { imgRect.Size = SMControl.GetImageDrawSize(bounds, image); if (bounds.Width - imgRect.Width < textSize.Width + ContentPadding.LeftRight) { imgRect.Width = bounds.Width - textSize.Width - ContentPadding.LeftRight; imgRect.Size = SMControl.GetImageDrawSize(imgRect, image); } textRect.Width = bounds.Width - imgRect.Width - ContentPadding.LeftRight; textRect.X = bounds.Right - textRect.Width; imgRect.Y = (bounds.Top + bounds.Bottom) / 2 - imgRect.Height / 2; } else if (argm == SMContentArangement.ImageOnRight) { imgRect.Size = SMControl.GetImageDrawSize(bounds, image); if (bounds.Width - imgRect.Width < textSize.Width + ContentPadding.LeftRight) { imgRect.Width = bounds.Width - textSize.Width - ContentPadding.LeftRight; imgRect.Size = SMControl.GetImageDrawSize(imgRect, image); } textRect.Width = bounds.Width - imgRect.Width - ContentPadding.LeftRight; imgRect.X = textRect.Right + ContentPadding.Right; } else if (argm == SMContentArangement.ImageOnly) { textRect = Rectangle.Empty; } else if (argm == SMContentArangement.TextOnly) { imgRect = Rectangle.Empty; } if (!imgRect.IsEmpty) { Rectangle rc = DrawImage(context, null, imgRect, image, ContentScaling, 0, 0); showRect = rc; } if (!textRect.IsEmpty) { textRect.Inflate(1, 1); rt.DrawString(context, layout, plainText, textRect); } } base.Paint(context); }
public override void Paint(MNPageContext context) { Graphics g = context.g; SMImage pi = this; Rectangle rect = Area.GetBounds(context); SMConnection conn = context.CurrentPage.FindConnection(this); if (conn != null) { UIStateHover = true; } SMStatusLayout layout = PrepareBrushesAndPens(); Debugger.Log(0, "", "State of " + Text + " Image is " + UIStateChecked.ToString() + "\n"); Rectangle bounds = ContentPadding.ApplyPadding(rect); SMContentArangement argm = this.ContentArangement; MNReferencedImage refImage = null; Rectangle imgRect = bounds; Image image = GetContentImage(out refImage); if (image == null) { argm = SMContentArangement.TextOnly; } if (ExpectedChecked != Bool3.Undef) { DrawStyledBackground(context, layout, bounds); } if (argm == SMContentArangement.ImageOnly) { SMContentScaling scaling = ContentScaling; Rectangle rc = DrawImage(context, layout, bounds, image, scaling, SourceOffsetX, SourceOffsetY); if (ContentScaling == SMContentScaling.Fill) { showRect = bounds; sourceRect = rc; } else { showRect = rc; sourceRect = new Rectangle(0, 0, image.Width, image.Height); } } else { Size textSize = Size.Empty; Font usedFont = GetUsedFont(); string plainText = Text.Length > 0 ? Text : DroppedText; if (plainText.IndexOf("_") >= 0 && DroppedTag.Length > 0) { plainText = plainText.Replace("_", DroppedTag); } if (plainText.Length != 0) { textSize = rt.MeasureString(context, plainText, bounds.Width); } Rectangle textRect = bounds; if (argm == SMContentArangement.ImageAbove) { textRect.Height = textSize.Height; textRect.Y = bounds.Bottom - textRect.Height; textRect.X = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2; textRect.Width = textSize.Width; imgRect.Height = bounds.Height - textRect.Height - ContentPadding.Top; } else if (argm == SMContentArangement.ImageBelow) { textRect.Height = textSize.Height; textRect.X = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2; textRect.Width = textSize.Width; imgRect.Y = textRect.Bottom + ContentPadding.Bottom; imgRect.Height = bounds.Height - textRect.Height - ContentPadding.Bottom; } else if (argm == SMContentArangement.ImageOnLeft) { textRect.Width = textSize.Width; textRect.X = bounds.Right - textSize.Width; imgRect.Width = bounds.Width - textSize.Width - ContentPadding.Left; } else if (argm == SMContentArangement.ImageOnRight) { textRect.Width = textSize.Width; imgRect.X = textRect.Right + ContentPadding.Right; imgRect.Width = bounds.Width - textSize.Width - ContentPadding.Right; } else if (argm == SMContentArangement.ImageOnly) { textRect = Rectangle.Empty; } else if (argm == SMContentArangement.TextOnly) { imgRect = Rectangle.Empty; } if (!imgRect.IsEmpty) { Rectangle rc = DrawImage(context, layout, imgRect, image, ContentScaling, SourceOffsetX, SourceOffsetY); if (ContentScaling == SMContentScaling.Fill) { showRect = imgRect; sourceRect = rc; } else { showRect = rc; sourceRect = new Rectangle(0, 0, image.Width, image.Height); } } if (!textRect.IsEmpty) { if (argm == SMContentArangement.TextOnly) { DrawStyledBorder(context, layout, bounds); } textRect.Inflate(2, 2); rt.DrawString(context, layout, plainText, textRect); } } if (!imgRect.IsEmpty && refImage != null && refImage.HasSpots()) { foreach (MNReferencedSpot rs in refImage.SafeSpots) { if (rs.ContentType != SMContentType.TaggedArea) { continue; } if (rs.UIStateHighlighted || (HoverSpot == rs)) { rs.Paint(context.g, showRect, false, context.SpotAreaBorderPen, null); } } } if (UIStateError == MNEvaluationResult.Incorrect && UIStateChecked) { if (Document.HasViewer) { Document.Viewer.ScheduleCall(MNNotificationCenter.RectifyDelay, this, "clearCheck"); } } base.Paint(context); }