コード例 #1
0
ファイル: SMImage.cs プロジェクト: gopa810/Rambha
        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);
        }
コード例 #2
0
ファイル: SMLabel.cs プロジェクト: gopa810/Rambha
        public override void Paint(MNPageContext context)
        {
            SMRectangleArea area   = this.Area;
            Rectangle       bounds = area.GetBounds(context);

            SMConnection conn = context.CurrentPage.FindConnection(this);

            if (conn != null)
            {
                UIStateHover = true;
            }


            bool b = UIStateHover;

            UIStateHover |= SwitchStatus;
            SMStatusLayout layout = PrepareBrushesAndPens();

            UIStateHover = b;

            Rectangle boundsA = bounds;

            boundsA.Y       = Math.Max(0, bounds.Top);
            boundsA.X       = Math.Max(0, bounds.Left);
            boundsA.Width   = Math.Min(context.PageWidth, bounds.Right);
            boundsA.Height  = Math.Min(context.PageHeight, bounds.Bottom);
            boundsA.Width  -= boundsA.X;
            boundsA.Height -= boundsA.Y;

            Rectangle textBounds = ContentPadding.ApplyPadding(boundsA);

            if (Text != null && Text.Contains("\\n"))
            {
                Text = Text.Replace("\\n", "\n");
            }
            string plainText = Text;
            MNReferencedAudioText runningText = null;

            if (Content != null)
            {
                plainText = null;
                if (Content is MNReferencedText)
                {
                    plainText = ((MNReferencedText)Content).Text;
                }
                else if (Content is MNReferencedAudioText)
                {
                    runningText = Content as MNReferencedAudioText;
                }
                else if (Content is MNReferencedSound)
                {
                    plainText = Text;
                }
            }

            if (plainText.StartsWith("$"))
            {
                plainText = Document.ResolveProperty(plainText.Substring(1));
            }

            Font usedFont = GetUsedFont();

            if (plainText != null)
            {
                Size      textSize = richText.MeasureString(context, plainText, textBounds.Width);
                Rectangle r        = Area.GetDockedRectangle(context.PageSize, textSize);
                if (Area.Dock != SMControlSelection.None)
                {
                    textBounds.X     = Area.RelativeArea.X + SMRectangleArea.PADDING_DOCK_LEFT;
                    textBounds.Y     = Area.RelativeArea.Y + SMRectangleArea.PADDING_DOCK_TOP;
                    textBounds.Width = Area.RelativeArea.Width - SMRectangleArea.PADDING_DOCK_LEFT
                                       - SMRectangleArea.PADDING_DOCK_RIGHT + 2;
                    textBounds.Height            = Area.RelativeArea.Height - SMRectangleArea.PADDING_DOCK_TOP - SMRectangleArea.PADDING_DOCK_BOTTOM + 2;
                    richText.Paragraph.VertAlign = SMVerticalAlign.Top;
                }

                if (Area.BackType == SMBackgroundType.None)
                {
                    DrawStyledBackground(context, layout, bounds);
                }
                else if (Area.BackType == SMBackgroundType.Solid)
                {
                    context.g.FillRectangle(SMGraphics.GetBrush(Page.BackgroundColor), r);
                }
                else if (Area.BackType == SMBackgroundType.Shadow && Area.BackgroundImage != null)
                {
                    context.g.DrawImage(Area.BackgroundImage,
                                        textBounds.X + Area.BackgroundImageOffset.X,
                                        textBounds.Y + Area.BackgroundImageOffset.Y);
                }

                if (Area.Dock == SMControlSelection.None)
                {
                    DrawStyledBorder(context, layout, bounds);
                }

                richText.DrawString(context, layout, textBounds);
            }
            else if (runningText != null)
            {
                DrawStyledBackground(context, layout, bounds);
                DrawStyledBorder(context, layout, bounds);

                Point curr  = new Point(textBounds.Left, textBounds.Top);
                int   index = 0;
                foreach (GOFRunningTextItem w in runningText.Words)
                {
                    Brush currBrush = (runningText.currentWord >= index ? Brushes.Red : tempForeBrush);
                    SizeF textSize  = context.g.MeasureString(w.Text, usedFont);
                    if (curr.X + textSize.Width > textBounds.Right)
                    {
                        curr.X  = textBounds.Left;
                        curr.Y += (int)textSize.Height;
                    }
                    context.g.DrawString(w.Text, usedFont, currBrush, curr);
                    curr.X += (int)textSize.Width;

                    index++;
                }
            }

            if (UIStateError == MNEvaluationResult.Incorrect && UIStateChecked)
            {
                if (Document.HasViewer)
                {
                    Document.Viewer.ScheduleCall(MNNotificationCenter.RectifyDelay, this, "clearCheck");
                }
            }

            // draw selection marks
            base.Paint(context);
        }