Пример #1
0
        public override void Paint(MNPageContext context)
        {
            Rectangle bounds = Area.GetBounds(context);

            Rectangle textBounds = bounds;

            if (Drawings.Length == 0)
            {
                context.g.DrawRectangle(Pens.Gray, textBounds);
                context.g.DrawLine(Pens.LightGray, textBounds.Left, textBounds.Bottom, textBounds.Right, textBounds.Top);
                context.g.DrawLine(Pens.LightGray, textBounds.Left, textBounds.Top, textBounds.Right, textBounds.Bottom);
            }
            else
            {
                DrawingContext dc = new DrawingContext();
                dc.Graphics = context.g;
                dc.Bounds   = bounds;
                string[] lines = Drawings.Split('\r', '\n', ';');
                foreach (string line in lines)
                {
                    dc.lineparts = line.Split(' ');
                    dc.PaintShape();
                }
            }

            // draw selection marks
            base.Paint(context);
        }
Пример #2
0
        public virtual void PaintSelectionMarks(MNPageContext context)
        {
            int x = RelativeArea.X;
            int y = RelativeArea.Y;
            int r = RelativeArea.Right;
            int b = RelativeArea.Bottom;

            int markWidth = context.PhysicalToLogical(3);

            if (Dock == SMControlSelection.None || Dock == SMControlSelection.Bottom)
            {
                context.g.FillRectangle(Brushes.DarkBlue, (x + r) / 2 - markWidth, y - markWidth, 2 * markWidth, 2 * markWidth);
            }
            if (Dock == SMControlSelection.None || Dock == SMControlSelection.Top)
            {
                context.g.FillRectangle(Brushes.DarkBlue, (x + r) / 2 - markWidth, b - markWidth, 2 * markWidth, 2 * markWidth);
            }
            if (Dock == SMControlSelection.None || Dock == SMControlSelection.Right)
            {
                context.g.FillRectangle(Brushes.DarkBlue, x - markWidth, (y + b) / 2 - markWidth, 2 * markWidth, 2 * markWidth);
            }
            if (Dock == SMControlSelection.None || Dock == SMControlSelection.Left)
            {
                context.g.FillRectangle(Brushes.DarkBlue, r - markWidth, (y + b) / 2 - markWidth, 2 * markWidth, 2 * markWidth);
            }

            if (Dock == SMControlSelection.None)
            {
                context.g.FillRectangle(Brushes.DarkBlue, x - markWidth, y - markWidth, 2 * markWidth, 2 * markWidth);
                context.g.FillRectangle(Brushes.DarkBlue, r - markWidth, y - markWidth, 2 * markWidth, 2 * markWidth);
                context.g.FillRectangle(Brushes.DarkBlue, x - markWidth, b - markWidth, 2 * markWidth, 2 * markWidth);
                context.g.FillRectangle(Brushes.DarkBlue, r - markWidth, b - markWidth, 2 * markWidth, 2 * markWidth);
            }
        }
Пример #3
0
        public bool ProcessChar(MNPageContext context, float width, char c)
        {
            bool refused = false;

            if (c == Convert.ToChar(9))
            {
                if (TextBuilder.Length > 0)
                {
                    TextBuilder.Remove(TextBuilder.Length - 1, 1);
                    RecalculateWords(context, width);
                }
            }
            else
            {
                TextBuilder.Append(c);
                RecalculateWords(context, width);

                // if adding character will cause to exceed the maximum number of lines
                // then character is not appended (in this case it is removed from the end)
                if (Lines.Count > LinesCount)
                {
                    TextBuilder.Remove(TextBuilder.Length - 1, 1);
                    RecalculateWords(context, width);
                    refused = true;
                }
            }

            if (HasImmediateEvaluation)
            {
                Evaluate();
            }

            return(refused);
        }
Пример #4
0
        private Rectangle DrawNavigationButtons(MNPageContext context, Rectangle textBounds)
        {
            context.g.DrawLine(SMGraphics.GetPen(NormalState.ForeColor, 1), textBounds.Left, textBounds.Bottom,
                               textBounds.Right, textBounds.Bottom);
            if (HasPrevPage())
            {
                prevBtnRect = new Rectangle(textBounds.Left, textBounds.Bottom, textBounds.Width / 2 - 32, navigButtonsHeight);
                if (prevBtnPressed)
                {
                    context.g.FillRectangle(SMGraphics.GetBrush(Color.LightGreen), prevBtnRect);
                }
                context.g.DrawString("< PREV", SMGraphics.GetFontVariation(SystemFonts.MenuFont, 20f), SMGraphics.GetBrush(Color.Gray), prevBtnRect, SMGraphics.StrFormatCenter);
            }
            if (HasNextPage())
            {
                nextBtnRect = new Rectangle(textBounds.Left + textBounds.Width / 2 + 32, textBounds.Bottom, textBounds.Width / 2 - 32, navigButtonsHeight);
                if (nextBtnPressed)
                {
                    context.g.FillRectangle(SMGraphics.GetBrush(Color.LightGreen), nextBtnRect);
                }
                context.g.DrawString("NEXT >", SMGraphics.GetFontVariation(SystemFonts.MenuFont, 20f), SMGraphics.GetBrush(Color.Gray), nextBtnRect, SMGraphics.StrFormatCenter);
            }

            context.g.DrawString(string.Format("{0}/{1}", CurrentPage + 1, PageCount), SMGraphics.GetFontVariation(SystemFonts.MenuFont, 20f),
                                 SMGraphics.GetBrush(Color.Gray), new Rectangle(textBounds.Left + textBounds.Width / 2 - 48, textBounds.Bottom, 96, navigButtonsHeight),
                                 SMGraphics.StrFormatCenter);
            return(textBounds);
        }
Пример #5
0
        private void DrawCard(MNPageContext context, Rectangle rect, MNReferencedImage image)
        {
            Size imgSize = SMGraphics.GetMaximumSize(rect, image.ImageData.Size);

            context.g.DrawImage(image.ImageData, rect.X + rect.Width / 2 - imgSize.Width / 2,
                                rect.Y + rect.Height / 2 - imgSize.Height / 2, imgSize.Width, imgSize.Height);
        }
Пример #6
0
        public int RecalculateWords(MNPageContext context, float width)
        {
            string[]      p         = TextBuilder.ToString().Split(' ');
            Font          font      = Font.Font;
            Graphics      g         = context.g;
            StringBuilder currLine  = new StringBuilder();
            float         currWidth = 0;
            int           counter   = 0;
            SizeF         ts;

            Lines.Clear();

            foreach (string s in p)
            {
                /*if (counter > 0)
                 * {
                 *  ts = g.MeasureString(" ", font);
                 *  if (ts.Width + currWidth > width)
                 *  {
                 *      Lines.Add(currLine.ToString());
                 *      currLine.Clear();
                 *      currWidth = 0;
                 *  }
                 *  else
                 *  {
                 *      currLine.Append(" ");
                 *      currWidth += ts.Width;
                 *  }
                 * }*/

                ts = g.MeasureString(s, font);
                if (ts.Width + currWidth > width)
                {
                    Lines.Add(currLine.ToString());
                    currLine.Clear();
                    currWidth = 0;
                }

                if (currLine.Length > 0)
                {
                    currLine.Append(" ");
                }
                currLine.Append(s);
                currWidth += ts.Width;

                counter++;
            }

            if (currLine.Length > 0)
            {
                Lines.Add(currLine.ToString());
            }

            if (Lines.Count == 0)
            {
                Lines.Add("");
            }
            return(-1);
        }
Пример #7
0
 public override void Paint(MNPageContext context, SMStatusLayout layout, int X, int Y)
 {
     if (Type == SMWordSpecialType.HorizontalLine)
     {
         context.g.DrawLine(SMGraphics.GetPen(layout.ForeColor, 1), rect.X + X, rect.Y + Y + rect.Height / 2, rect.Right + X, rect.Y + Y + rect.Height / 2);
     }
     base.Paint(context, layout, X, Y);
 }
Пример #8
0
        public override void Paint(MNPageContext context)
        {
            if (!Visible || context.CurrentPage == null)
            {
                return;
            }

            //Rectangle bounds = Area.GetBounds(context);
            Rectangle textBounds = new Rectangle(32, 0, context.PageWidth - 64, context.PageHeight);

            string plainText = context.CurrentPage.MessageText;
            string titleText = context.CurrentPage.MessageTitle;

            SMStatusLayout layout      = GetFullStatusLayout();
            Font           usedFont    = GetUsedFont();
            int            titleHeight = 0;
            int            textHeight  = 0;

            if (titleText != null)
            {
                Size size = titleRichText.MeasureString(context, titleText, textBounds.Width);
                titleHeight = size.Height;
            }

            if (plainText != null)
            {
                Size size = messageRichText.MeasureString(context, plainText, textBounds.Width);
                textHeight = size.Height;
            }

            int cy = context.PageHeight;

            if (textHeight > 0)
            {
                cy = cy - textHeight - 32;
                context.g.FillRectangle(Brushes.LightBlue, 0, cy, context.PageWidth, textHeight + 32);
                textBounds.Y      = cy;
                textBounds.Height = textHeight + 32;
                messageRichText.DrawString(context, layout, plainText, textBounds);
            }

            if (titleHeight > 0)
            {
                cy = cy - titleHeight - 16;
                context.g.FillRectangle(Brushes.CadetBlue, 0, cy, context.PageWidth, titleHeight + 16);
                textBounds.Y      = cy;
                textBounds.Height = titleHeight + 16;
                titleRichText.DrawString(context, layout, titleText, textBounds);
            }

            if (titleHeight + textHeight > 0)
            {
                cy -= 4;
                context.g.FillRectangle(Brushes.Black, 0, cy, context.PageWidth, 4);
            }

            CurrentTop = cy;
        }
Пример #9
0
        public override void Paint(MNPageContext context)
        {
            Rectangle bounds = Area.GetBounds(context);

            SMStatusLayout layout = PrepareBrushesAndPens();

            Rectangle textBounds = ContentPadding.ApplyPadding(bounds);

            // size of one cell
            SizeF sizeChar = context.g.MeasureString("M", Font.Font);
            int   cellSize = (int)(sizeChar.Height * 12 / 10);
            Font  drawFont = GetUsedFont();

            // prepare formating
            StringFormat format = new StringFormat();

            format.Alignment     = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            if (wordsModified)
            {
                RecalculateWords(context, textBounds.Width);
                while (Lines.Count > LinesCount && LinesCount > 0)
                {
                    TextBuilder.Remove(TextBuilder.Length - 1, 1);
                    RecalculateWords(context, textBounds.Width);
                }
                wordsModified = false;
            }

            Brush textB = (UIStateError == MNEvaluationResult.Incorrect ? Brushes.Red : tempForeBrush);
            Brush cursB = (UIStateError == MNEvaluationResult.Incorrect ? Brushes.Pink : Brushes.LightBlue);

            Font usedFont = Font.Font;

            // drawing all positions
            for (int i = 0; i < LinesCount; i++)
            {
                int y = cellSize * (i + 1) + textBounds.Y;
                context.g.DrawLine(Pens.Gray, textBounds.Left, y, textBounds.Right, y);
                // draws cursor only if control is focused
                if (i < Lines.Count)
                {
                    SizeF ll = context.g.MeasureString(Lines[i], usedFont);
                    int   y2 = y - (int)ll.Height - 3;
                    context.g.DrawString(Lines[i], usedFont, textB, textBounds.X, y2);

                    if (i == Lines.Count - 1)
                    {
                        context.g.FillRectangle(cursB, textBounds.X + ll.Width + 2, y2, cellSize * 2 / 3, cellSize);
                    }
                }
            }

            // draw selection marks
            base.Paint(context);
        }
Пример #10
0
        public override void Paint(MNPageContext context)
        {
            Rectangle bounds = Area.GetBounds(context);

            Rectangle textBounds = ContentPadding.ApplyPadding(bounds);

            SMStatusLayout layout;

            if (IsDraggable())
            {
                SMDragResponse dr = Draggable;
                Draggable = SMDragResponse.None;
                layout    = PrepareBrushesAndPens();
                Draggable = dr;
            }
            else
            {
                layout = PrepareBrushesAndPens();
            }

            DrawStyledBackground(context, layout, bounds);
            DrawStyledBorder(context, layout, bounds);

            string stext = Text;

            if (Content != null)
            {
                if (Content is MNReferencedText)
                {
                    stext = (Content as MNReferencedText).Text;
                }
            }

            if (!p_prevText.Equals(stext))
            {
                Text       = stext;
                p_prevText = stext;

                SplitTextToWords(stext);
            }

            if (drawWordsModified)
            {
                RecalculateWordsLayout(context, textBounds.Size, drawWords);

                drawWordsModified = false;
            }

            context.g.DrawRectangle(Pens.Black, textBounds);
            PaintPageNo(context, IsDraggable() ? SMGraphics.draggableLayoutN : layout, textBounds.X, textBounds.Y);

            // draw selection marks
            base.Paint(context);
        }
Пример #11
0
        public void PrepareContent(MNPageContext context)
        {
            if (p_prevtext.Equals(Text))
            {
                return;
            }

            p_prevtext = Text;
            texts.Clear();
            string[] p     = null;
            int      index = 0;
            string   s     = Text.Replace("\r\n", "\n");

            //Debugger.Log(0, "", "PrepareSelectionContents: " + Text + "<< end cont<<\n");
            if (s.IndexOf("\n\n") >= 0)
            {
                bHorizontal = false;
                p           = s.Split(p_strSep, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                bHorizontal = true;
                p           = s.Split('|');
            }

            if (p != null)
            {
                foreach (string line in p)
                {
                    if (line.StartsWith("*"))
                    {
                        p_expectedSelection = index;
                        texts.Add(new SelText(line.Substring(1)));
                    }
                    else
                    {
                        texts.Add(new SelText(line));
                    }
                    index++;
                }

                Font font = GetUsedFont();

                foreach (SelText st in texts)
                {
                    SizeF sf = context.g.MeasureString(st.text, font);
                    st.size.Width  = (int)sf.Width;
                    st.size.Height = (int)sf.Height;
                }
            }
        }
Пример #12
0
        private Rectangle DrawColumnSeparators(MNPageContext context, Rectangle textBounds)
        {
            Pen pen = SMGraphics.GetPen(NormalState.ForeColor, 1);

            for (int i = 1; i < Columns; i++)
            {
                int x  = textBounds.Left + i * textBounds.Width / Columns;
                int y  = textBounds.Top;
                int y2 = textBounds.Bottom;
                if (ShowNavigationButtons)
                {
                    y2 -= navigButtonsHeight;
                }

                int cy = y;
                switch (ColumnSeparatorStyle)
                {
                case SMLineStyle.Plain:
                    context.g.DrawLine(pen, x, y, x, y2);
                    break;

                case SMLineStyle.Dashed:
                    while (cy + 16 < y2)
                    {
                        context.g.DrawLine(pen, x, cy, x, cy + 16);
                        cy += 24;
                    }
                    break;

                case SMLineStyle.Doted:
                    while (cy + 3 < y2)
                    {
                        context.g.DrawRectangle(pen, x, cy, 2, 2);
                        cy += 8;
                    }
                    break;

                case SMLineStyle.ZigZag:
                    while (cy + 16 < y2)
                    {
                        context.g.DrawLine(pen, x, cy, x - 4, cy + 4);
                        context.g.DrawLine(pen, x - 4, cy + 4, x + 4, cy + 12);
                        context.g.DrawLine(pen, x + 4, cy + 12, x, cy + 16);
                        cy += 16;
                    }
                    break;
                }
            }
            return(textBounds);
        }
Пример #13
0
        public override void Paint(MNPageContext context)
        {
            if (context.drawSelectionMarks)
            {
                Rectangle bounds = Area.GetBounds(context);

                string title = string.Format("[{0}] {1}", GroupType.ToString(), Text);

                context.g.DrawRectangle(Pens.DarkKhaki, bounds);
                context.g.DrawString(title, SystemFonts.CaptionFont, Brushes.DarkKhaki, bounds);
            }

            // draw selection marks
            base.Paint(context);
        }
Пример #14
0
        public void DrawString(MNPageContext context, SMStatusLayout layout, string plainText, Rectangle textBounds, int nPage)
        {
            if (!p_prevText.Equals(plainText) || (p_prevWidth != textBounds.Width) || drawWords == null)
            {
                p_prevText = plainText;
                drawWords  = WordListFromString(plainText);
                richLayout = RecalculateWordsLayout(context, textBounds);
            }

            foreach (SMWordBase wt in drawWords)
            {
                if (wt.PageNo == nPage)
                {
                    wt.Paint(context, layout, textBounds.X, textBounds.Y);
                }
            }
        }
Пример #15
0
        public void PaintPageNo(MNPageContext context, SMStatusLayout layout, int X, int Y)
        {
            Brush backgroundBrush     = SMGraphics.GetBrush(layout.BackColor);
            Brush highBackgroundBrush = SMGraphics.GetBrush(Color.LightGray);
            Brush textBrush           = SMGraphics.GetBrush(layout.ForeColor);

            foreach (SMTextContainerLine wline in drawLines)
            {
                foreach (SMTextContainerWord wt in wline)
                {
                    Rectangle r = wt.rect;
                    r.Offset(X, Y);
                    context.g.DrawFillRoundedRectangle(Pens.Black, wt.Used ? highBackgroundBrush : backgroundBrush, r, 5);
                    context.g.DrawString(wt.text, Font.Font, textBrush, r, SMGraphics.StrFormatCenter);
                }
            }
        }
Пример #16
0
 private void DrawListItem(MNPageContext context, SMStatusLayout layout, Font usedFont, Rectangle showRect, bool isFirst, StringItem obj)
 {
     if (obj.IsText)
     {
         StringFormat format = Paragraph.GetAlignmentStringFormat();
         if (Orientation == SMTextDirection.Horizontal)
         {
             format.Trimming     = StringTrimming.None;
             format.FormatFlags |= StringFormatFlags.NoClip | StringFormatFlags.NoWrap;
         }
         context.g.DrawString(CapitalizeCond(obj.Text, isFirst), usedFont, tempForeBrush, showRect, format);
     }
     else if (obj.IsImage)
     {
         DrawImage(context, layout, showRect, obj.Image.ImageData, SMContentScaling.Fit);
     }
 }
Пример #17
0
        public Size MeasureString(MNPageContext context, string plainText, int width)
        {
            if (width < 0)
            {
                width = 5000;
            }
            if (!p_prevText.Equals(plainText) || (p_prevWidth != width) || drawWords == null || richLayout == null)
            {
                p_prevText = plainText;
                drawWords  = WordListFromString(plainText);
                Rectangle textBounds = new Rectangle(0, 0, width, 100);
                richLayout = RecalculateWordsLayout(context, textBounds);
                drawLines  = richLayout.Lines;
            }

            return(new Size(richLayout.rightX, richLayout.bottomY));
        }
Пример #18
0
        public Rectangle[] CalcRectangles(MNPageContext context, string plainText, Rectangle textBounds)
        {
            p_prevText = plainText;
            drawWords  = WordListFromString(plainText);
            richLayout = RecalculateWordsLayout(context, textBounds);
            drawLines  = richLayout.Lines;

            List <Rectangle> ra = new List <Rectangle>();

            foreach (SMWordBase wb in drawWords)
            {
                if (wb is SMWordText)
                {
                    ra.Add(new Rectangle((int)wb.rect.X, (int)wb.rect.Y, (int)wb.rect.Width, (int)wb.rect.Height));
                }
            }

            return(ra.ToArray <Rectangle>());
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="textBounds"></param>
        /// <param name="drawWords"></param>
        /// <param name="control"></param>
        /// <param name="RunningLine"></param>
        /// <param name="Columns">Value -1 means, that no paging is done, normaly columns are 1,2,3...</param>
        /// <param name="ColumnSeparatorWidth"></param>
        /// <param name="PageCount"></param>
        /// <returns></returns>
        public void RecalculateWordsLayout(MNPageContext context, Size textBoundsSize, List <SMTextContainerWord> drawWords)
        {
            Rectangle textBounds = Rectangle.Empty;

            textBounds.Size = textBoundsSize;
            float lineY = 0;
            float lineX = ItemMargin.Left;
            float maxX  = textBoundsSize.Width - ItemMargin.Right;

            SMTextContainerLine currLine = new SMTextContainerLine();

            drawLines.Clear();
            drawLines.Add(currLine);

            // first placement of word tokens
            foreach (SMTextContainerWord wt in drawWords)
            {
                SizeF szf = context.g.MeasureString(wt.text, Font.Font, textBounds.Width, StringFormat.GenericDefault);

                wt.rect.Width  = (int)szf.Width + ItemPadding.Left + ItemPadding.Right;
                wt.rect.Height = (int)szf.Height + ItemPadding.Top + ItemPadding.Bottom;

                if (((lineX + wt.rect.Width + ItemMargin.Left) > maxX) &&
                    currLine.Count > 0)
                {
                    lineX    = ItemMargin.Left;
                    lineY   += wt.rect.Height + ItemMargin.Top + ItemMargin.Bottom;
                    currLine = new SMTextContainerLine();
                    drawLines.Add(currLine);
                }

                wt.rect.X = (int)lineX;
                wt.rect.Y = (int)lineY;
                lineX    += wt.rect.Width + ItemMargin.Left + ItemMargin.Right;
                currLine.Add(wt);
            }

            // vertical alignment
            AdjustLinesVerticaly(textBounds, drawLines, GetVerticalAlign());

            // horizontal aligment
            AdjustLinesHorizontaly((int)textBounds.Width, GetHorizontalAlign(), drawLines);
        }
Пример #20
0
        public override void Paint(MNPageContext context)
        {
            Rectangle bounds = Area.GetBounds(context);

            Rectangle textBounds = bounds;
            Pen       currentPen;

            // background image is drawn centered
            if (BackgroundImage != null)
            {
                BackgroundImageRect = new Rectangle(textBounds.Location, SMGraphics.GetMaximumSize(textBounds, BackgroundImage.ImageData.Size));
                BackgroundImageRect.Offset((textBounds.Width - BackgroundImageRect.Width) / 2,
                                           (textBounds.Height - BackgroundImageRect.Height) / 2);
                context.g.DrawImage(BackgroundImage.ImageData, BackgroundImageRect);
            }

            /*context.g.DrawRectangle(Pens.Gray, textBounds.Right - 16, textBounds.Bottom - 48, 16, 16);
            *  context.g.DrawRectangle(Pens.Gray, textBounds.Right - 16, textBounds.Bottom - 32, 16, 16);
            *  context.g.DrawRectangle(Pens.Gray, textBounds.Right - 16, textBounds.Bottom - 16, 16, 16);*/
            context.g.DrawRectangle(Pens.Black, textBounds);

            if (!context.drawSelectionMarks)
            {
                foreach (DrawPoints dp in drawPoints)
                {
                    currentPen = SMGraphics.GetPen(dp.penColor, dp.penWidth);
                    context.g.DrawLines(currentPen, dp.pts);
                }

                if (tempPoints.pts.Count > 1)
                {
                    currentPen = SMGraphics.GetPen(tempPoints.penColor, tempPoints.penWidth);
                    context.g.DrawLines(currentPen, tempPoints.pts.ToArray <Point>());
                }
            }

            // draw selection marks
            base.Paint(context);
        }
Пример #21
0
        public void PaintPageNo(MNPageContext context, SMStatusLayout layout, int pageNo, int X, int Y)
        {
            if (pageNo >= PageCount)
            {
                pageNo = PageCount - 1;
            }
            if (pageNo < 0)
            {
                pageNo = 0;
            }

            foreach (SMWordLine wline in drawLines)
            {
                foreach (SMWordBase wt in wline)
                {
                    if (wt.PageNo == pageNo)
                    {
                        wt.Paint(context, layout, X, Y);
                    }
                }
            }
        }
Пример #22
0
        public override void Paint(MNPageContext context, SMStatusLayout layout, int X, int Y)
        {
            string s = GetCurrentText();

            //Brush b = SMGraphics.GetBrush(layout.BackColor);

            if (UIStateHover)
            {
                context.g.DrawRectangle(SMGraphics.GetPen(SMGraphics.dropableLayoutH.BorderColor, 4), rect.X + X, rect.Y + Y, rect.Width, rect.Height);
            }
            else
            {
                context.g.DrawRectangle(SMGraphics.GetPen(SMGraphics.dropableLayoutN.BorderColor, 2), rect.X + X, rect.Y + Y, rect.Width, rect.Height);
            }

            if (Editable && Focused)
            {
                SizeF sz = context.g.MeasureString(editedText, this.Font.Font);
                context.g.FillRectangle(Brushes.LightBlue, rect.X + X + (int)sz.Width, rect.Y + Y + 1, 10, rect.Height - 2);
            }

            context.g.DrawString(s, this.Font.Font, GetCurrentTextBrush(layout), rect.Location.X + X, rect.Location.Y + Y);
        }
Пример #23
0
        public override void Paint(MNPageContext context)
        {
            Rectangle rect     = Area.GetBounds(context);
            Brush     keyBack  = Brushes.LightGray;
            Brush     keyPress = Brushes.Blue;

            float  ax             = rect.Width / 100f;
            float  ay             = rect.Height / 28f;
            Font   font           = SMGraphics.GetFontVariation(SystemFonts.DefaultFont, 4 * Math.Min(ax, ay));
            PointF origin         = new PointF(rect.X + rect.Width / 2 - 50 * ax, rect.Y + rect.Height / 2 - 14 * ay);
            Brush  textBrush      = Brushes.Black;
            Brush  textPressBrush = Brushes.White;

            foreach (SMKeyboardKey key in Keys)
            {
                key.PaintedRect = new RectangleF(key.X * ax + origin.X, key.Y * ay + origin.Y, key.Width * ax, key.Height * ay);
                Rectangle r = new Rectangle((int)key.PaintedRect.X, (int)key.PaintedRect.Y, (int)key.PaintedRect.Width, (int)key.PaintedRect.Height);
                context.g.FillRectangle(key.Pressed ? keyPress : keyBack, r);
                if (key.Image != null)
                {
                    float b = Math.Min(key.PaintedRect.Width / key.Image.Width, key.PaintedRect.Height / key.Image.Height);
                    b *= 0.7f;
                    Rectangle r2 = new Rectangle(Convert.ToInt32(key.PaintedRect.X + key.PaintedRect.Width / 2),
                                                 Convert.ToInt32(key.PaintedRect.Y + key.PaintedRect.Height / 2),
                                                 Convert.ToInt32(b * key.Image.Width), Convert.ToInt32(b * key.Image.Height));
                    r2.X -= r2.Width / 2;
                    r2.Y -= r2.Height / 2;
                    context.g.DrawImage(key.Image, r2);
                }
                else
                {
                    context.g.DrawString(key.Key, font, key.Pressed ? textPressBrush : textBrush, r, p_sf);
                }
            }

            base.Paint(context);
        }
Пример #24
0
 public Rectangle GetBoundsRecalc(MNPageContext ctx)
 {
     return(RelativeArea);
 }
Пример #25
0
 public virtual SMControlSelection TestHitLogical(MNPageContext context, Rectangle logRect)
 {
     return(RelativeArea.IntersectsWith(logRect) ? SMControlSelection.All : SMControlSelection.None);
 }
Пример #26
0
 public virtual bool TestHitLogical(MNPageContext context, Point logicalPoint)
 {
     return(RelativeArea.Contains(logicalPoint));
 }
Пример #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="textBounds"></param>
        /// <param name="drawWords"></param>
        /// <param name="control"></param>
        /// <param name="RunningLine"></param>
        /// <param name="Columns">Value -1 means, that no paging is done, normaly columns are 1,2,3...</param>
        /// <param name="ColumnSeparatorWidth"></param>
        /// <param name="PageCount"></param>
        /// <returns></returns>
        public static SMRichLayout RecalculateWordsLayout(MNPageContext context, Rectangle textBounds, List <SMWordBase> drawWords, SMControl control, SMRunningLine RunningLine,
                                                          int Columns)
        {
            textBounds.X = 0;
            textBounds.Y = 0;
            float        lineY       = textBounds.Y;
            float        lineX       = textBounds.X;
            float        lineEnd     = textBounds.Right;
            float        lineHeight  = 0f;
            float        lineWidth   = textBounds.Width;
            float        columnWidth = textBounds.Width;
            int          lineNo      = 0;
            int          columnNo    = 0;
            int          pageNo      = 0;
            int          rightX      = textBounds.X;
            bool         writeLineNo = false;
            bool         isNewLine   = false;
            bool         isNewColumn = false;
            SMWordLine   currLine    = new SMWordLine();
            SMRichLayout richLayout  = new SMRichLayout();

            richLayout.Lines = new List <SMWordLine>();
            richLayout.Lines.Add(currLine);
            richLayout.DropablesCount = 0;
            //context.g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            if (Columns > 1)
            {
                columnWidth = textBounds.Width / Columns;
                lineWidth   = textBounds.Width / Columns - control.ContentPadding.Left - control.ContentPadding.Right;
                lineX       = textBounds.X + columnNo * columnWidth + control.ContentPadding.Left;
                lineEnd     = lineX + lineWidth;
            }
            else
            {
                columnWidth = textBounds.Width;
                lineWidth   = textBounds.Width - control.ContentPadding.Left - control.ContentPadding.Right;
                lineX       = textBounds.X + control.ContentPadding.Left;
                lineEnd     = lineX + lineWidth;
            }

            float bottom                = textBounds.Bottom;
            bool  isSpaceText           = false;
            int   startsWithParentheses = 0;
            bool  isNewPage             = false;

            // first placement of word tokens
            foreach (SMWordBase wt in drawWords)
            {
                isSpaceText           = false;
                writeLineNo           = true;
                isNewLine             = false;
                isNewColumn           = false;
                isNewPage             = false;
                startsWithParentheses = 0;
                if (wt is SMWordSpecial)
                {
                    SMWordSpecial spwt = (SMWordSpecial)wt;
                    if (spwt.Type == SMWordSpecialType.Newline)
                    {
                        isNewLine   = true;
                        writeLineNo = false;
                    }
                    else if (spwt.Type == SMWordSpecialType.NewColumn)
                    {
                        isNewLine   = false;
                        writeLineNo = false;
                        isNewColumn = true;
                    }
                    else if (spwt.Type == SMWordSpecialType.HorizontalLine)
                    {
                        wt.rect.Width  = lineEnd - lineX - 1;
                        wt.rect.Height = 20;
                    }
                    else if (spwt.Type == SMWordSpecialType.NewPage)
                    {
                        isNewPage   = true;
                        writeLineNo = false;
                    }
                }
                else if (wt is SMWordToken)
                {
                    SMWordToken wtk = (SMWordToken)wt;
                    if (wtk.Cardinality == SMConnectionCardinality.One || wtk.Editable)
                    {
                        richLayout.DropablesCount++;
                    }
                    string s = wtk.GetCurrentText();
                    wt.rect.Size = context.g.MeasureString(s, wtk.Font.Font, textBounds.Width, StringFormat.GenericTypographic);
                }
                else if (wt is SMWordText)
                {
                    SMWordText wtt = wt as SMWordText;
                    if (wtt.Draggable != SMDragResponse.None && control.Draggable != wtt.Draggable)
                    {
                        control.Draggable = wtt.Draggable;
                    }
                    if (wtt.text.StartsWith("\"") || wtt.text.StartsWith("\u201c"))
                    {
                        SizeF sf = context.g.MeasureString("\u201c", wtt.Font.Font, textBounds.Width, StringFormat.GenericTypographic);
                        startsWithParentheses = (int)sf.Width;
                    }
                    if (wtt.text.Equals(" "))
                    {
                        wtt.rect.Size = context.g.MeasureString(wtt.text, wtt.Font.Font);
                        isSpaceText   = true;
                    }
                    else
                    {
                        wtt.rect.Size = context.g.MeasureString(wtt.text, wtt.Font.Font, textBounds.Width, StringFormat.GenericTypographic);
                    }
                }
                else if (wt is SMWordImage)
                {
                    SMWordImage wti = wt as SMWordImage;
                    wti.rect.Size = wti.imageSize;
                }

                if (writeLineNo && !control.Autosize)
                {
                    if ((lineX + wt.rect.Width > lineEnd) || RunningLine == SMRunningLine.SingleWord)
                    {
                        if (currLine.Count > 0)
                        {
                            isNewLine = true;
                        }
                    }
                }

                if (isNewLine)
                {
                    if (currLine.Count == 0)
                    {
                        lineY += lineHeight * control.Paragraph.LineSpacing / 2;
                    }
                    else
                    {
                        lineY += lineHeight * control.Paragraph.LineSpacing;
                    }

                    currLine = new SMWordLine();
                    richLayout.Lines.Add(currLine);

                    lineHeight = context.g.MeasureString("M", control.GetUsedFont()).Height / 2;
                    lineNo++;

                    if (Columns != -1 && !control.Autosize)
                    {
                        if (lineY + lineHeight > textBounds.Bottom)
                        {
                            isNewColumn = true;
                        }
                    }
                }

                if (isNewPage)
                {
                    lineNo   = 0;
                    columnNo = 0;
                    pageNo++;
                    lineY = textBounds.Top;
                }


                if (isNewColumn)
                {
                    columnNo++;
                    lineNo = 0;

                    if (columnNo >= Columns)
                    {
                        pageNo++;
                        columnNo = 0;
                    }

                    lineY = textBounds.Top;
                }

                if (isNewLine || isNewColumn || isNewPage)
                {
                    lineX   = textBounds.X + columnNo * columnWidth + control.ContentPadding.Left;
                    lineEnd = lineX + lineWidth;
                }

                if (writeLineNo)
                {
                    if (currLine.Count == 0 && startsWithParentheses > 0)
                    {
                        wt.rect.X -= startsWithParentheses;
                        lineX     -= startsWithParentheses;
                    }
                    if (currLine.Count > 0 || !isSpaceText)
                    {
                        currLine.Add(wt);

                        wt.LineNo        = lineNo;
                        wt.ColumnNo      = columnNo;
                        wt.PageNo        = pageNo;
                        wt.rect.Location = new PointF(lineX, lineY);
                        lineX           += wt.rect.Width;
                        rightX           = Math.Max(rightX, (int)lineX);
                    }

                    lineHeight  = Math.Max(lineHeight, wt.rect.Height);
                    writeLineNo = false;
                }
            }

            lineY += lineHeight * control.Paragraph.LineSpacing;

            // vertical alignment
            AdjustVerticaly(textBounds, richLayout.Lines, control.GetVerticalAlign());

            // horizontal aligment
            AdjustLinesHorizontaly((int)lineWidth, control.GetHorizontalAlign(), richLayout.Lines);

            richLayout.Pages   = pageNo + 1;
            richLayout.bottomY = (int)lineY + 1;
            richLayout.rightX  = rightX + 1;

            return(richLayout);
        }
Пример #28
0
        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);
        }
Пример #29
0
        public override void Paint(MNPageContext context)
        {
            Rectangle bounds = Area.GetBounds(context);
            Rectangle boundsWithoutNavigation = bounds;

            if (ShowNavigationButtons)
            {
                boundsWithoutNavigation.Height -= navigButtonsHeight;
            }

            Rectangle               textBounds = ContentPadding.ApplyPadding(bounds);
            SMStatusLayout          layout;
            SMConnectionCardinality scard = Cardinality;

            if (UIStateHover && DropablesCount == 1)
            {
                Cardinality = SMConnectionCardinality.One;
            }

            layout      = PrepareBrushesAndPens();
            Cardinality = scard;

            DrawStyledBackground(context, layout, bounds);
            DrawStyledBorder(context, layout, bounds);

            string stext = Text;

            if (Content != null)
            {
                if (Content is MNReferencedText)
                {
                    stext = (Content as MNReferencedText).Text;
                }
            }

            if (!p_prevText.Equals(stext))
            {
                Text       = stext;
                p_prevText = stext;
            }

            if (drawWordsModified)
            {
                Rectangle layoutBounds = textBounds;
                if (ShowNavigationButtons)
                {
                    layoutBounds.Height -= navigButtonsHeight;
                }
                SMRichLayout lay = null;
                lay            = RecalculateWordsLayout(context, layoutBounds, drawWords, this, RunningLine, Columns);
                drawLines      = lay.Lines;
                PageCount      = lay.Pages;
                DropablesCount = lay.DropablesCount;

                drawWordsModified = false;
            }

            PaintPageNo(context, layout, CurrentPage, textBounds.X, textBounds.Y);

            if (ShowNavigationButtons)
            {
                textBounds = DrawNavigationButtons(context, boundsWithoutNavigation);
            }

            if (Columns > 1)
            {
                textBounds = DrawColumnSeparators(context, textBounds);
            }

            // draw selection marks
            base.Paint(context);
        }
Пример #30
0
        public void Paint(MNPageContext Context)
        {
            // if needed, calculate dimensions
            int spaceItems = 16;
            int itemHeight = 64;
            int padding    = 32;

            SizeF titleSize = SizeF.Empty;
            bool  hasTitle  = false;

            if (UserTitle.Length > 0)
            {
                titleSize = Context.g.MeasureString(UserTitle, Context.MenuTitleFont);
                hasTitle  = true;
            }

            float maxItemWidth    = 324f;
            float itemsAreaHeight = 0;

            foreach (MNMenuItem mi in Items)
            {
                SizeF szf = Context.g.MeasureString(mi.Text, Context.MenuFont);
                maxItemWidth     = Math.Max(maxItemWidth, szf.Width);
                itemsAreaHeight += mi.IsSeparator ? spaceItems : itemHeight;
            }

            int ay = padding;
            int by = ay + (hasTitle ? (int)titleSize.Height + spaceItems : 0);
            int cy = by + (int)itemsAreaHeight + padding;

            int width = (int)Math.Max(titleSize.Width, maxItemWidth) + 2 * padding;

            drawRect = new Rectangle(Context.PageWidth / 2 - width / 2, Context.PageHeight / 2 - cy / 2,
                                     width, cy);

            // draw menu
            Context.g.FillRectangle(Context.semitransparentGrayBrush, 0, 0, Context.PageWidth, Context.PageHeight);
            Context.g.FillRectangle(Brushes.White, drawRect);
            Context.g.DrawRectangle(Pens.Black, drawRect);

            if (hasTitle)
            {
                Context.g.DrawString(UserTitle, Context.MenuTitleFont, Brushes.DarkGray,
                                     Context.PageWidth / 2 - (int)titleSize.Width / 2, drawRect.Top + ay);
                Context.g.FillRectangle(Brushes.Gray, drawRect.X + 8, drawRect.Top + (int)titleSize.Height + 2 * ay, drawRect.Width - 16, 3);
            }

            int ix = 0;
            int iy = by;

            foreach (MNMenuItem mi in Items)
            {
                mi.drawRect.X      = drawRect.X;
                mi.drawRect.Y      = drawRect.Top + iy;
                mi.drawRect.Width  = drawRect.Width;
                mi.drawRect.Height = mi.IsSeparator ? spaceItems : itemHeight;

                if (ix == Context.selectedMenuItem)
                {
                    Context.g.FillRectangle(Brushes.LightSkyBlue, mi.drawRect);
                }

                if (!mi.IsSeparator)
                {
                    Context.g.DrawImage(mi.Image, drawRect.Left + 8,
                                        mi.drawRect.Top + 8, itemHeight - 16, itemHeight - 16);
                    Rectangle rtext = new Rectangle(mi.drawRect.Left + itemHeight + 16, mi.drawRect.Top,
                                                    mi.drawRect.Width - itemHeight - 16, itemHeight);
                    Context.g.DrawString(mi.Text, Context.MenuFont, Brushes.Black, rtext, SMGraphics.StrFormatLeftCenter);
                    iy += itemHeight;
                }
                else
                {
                    Context.g.DrawLine(Pens.Gray, mi.drawRect.Left + spaceItems, mi.drawRect.Top + spaceItems / 2,
                                       mi.drawRect.Right - spaceItems, mi.drawRect.Top + spaceItems / 2);
                    iy += spaceItems;
                }
                ix++;
            }
        }