Пример #1
0
        public override void Draw(Graphics gr, Point position, Range range)
        {
            //   ushort _nData =  range.tb.TextSource[range.FromLine][range.Start.iChar].nCustomData;
            ushort _nData     = CwRange.fGetStyleData(range);
            char   _nBackData = (char)((_nData & 0x00F0) >> 4);

            //draw background
            Brush backgroundBrush = CwFCTB.fGetBrush(_nBackData);

            if (backgroundBrush != Brushes.Black) // TODO or same as background color
            {
                Rectangle rect = new Rectangle(position.X, position.Y, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth + 1, range.tb.CharHeight);
                if (rect.Width == 0)
                {
                    return;
                }


                gr.FillRectangle(backgroundBrush, rect);
            }
        }
Пример #2
0
        public override void Draw(Graphics gr, Point position, Range range)
        {
            //   ushort _nData =  range.tb.TextSource[range.FromLine][range.Start.iChar].nCustomData;
            ushort _nData = CwRange.fGetStyleData(range);
            //    char _nBackData =  (char)((_nData & 0x00F0) >> 4);

            //draw background
            Brush backgroundBrush = Brushes.Aquamarine;

            if (backgroundBrush != Brushes.Black) // TODO or same as background color
            {
                // Rectangle rect = new Rectangle(position.X, position.Y, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth+1, range.tb.CharHeight);
                //      float _nHeight = (((float)(range.tb.CharHeight)) *0.90f);
                float _nHeight = (int)(((range.tb.CharHeight)) * 0.90f);
                if (range.tb.CharHeight < 10.0f)
                {
                    _nHeight += 0.5f;
                }


                //  Rectangle rect = new Rectangle(position.X, position.Y + _nHeight, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth+1, 1);
                //   Line line = new Line(position.X, position.Y + (int)((double)(range.tb.CharHeight) *0.80), (range.End.iChar - range.Start.iChar) * range.tb.CharWidth+1, 1);


                Pen pen = new Pen(Color.DarkGoldenrod);
                // Pen pen = new Pen(  Color.DarkCyan);

                gr.DrawLine(pen, (float)position.X, (float)position.Y + _nHeight, (float)position.X + (range.End.iChar - range.Start.iChar) * range.tb.CharWidth + 1, (float)position.Y + _nHeight);

                pen.Dispose();

                //    if (rect.Width == 0)
                //       return;

                // gr.FillRectangle(backgroundBrush, rect);
            }
            backgroundBrush.Dispose();
        }
Пример #3
0
        public override void Draw(Graphics gr, Point position, Range range)
        {
            ushort _nData     = CwRange.fGetStyleData(range);
            char   _nForeData = (char)((_nData & 0x000F));



            //draw background
            // if (BackgroundBrush != null)
            //      gr.FillRectangle(BackgroundBrush, position.X, position.Y, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth, range.tb.CharHeight);
            //draw chars
            using (var f = new Font(range.tb.Font, FontStyle))
            {
                Line  line = range.tb[range.Start.iLine];
                float dx   = range.tb.CharWidth;
                float y    = position.Y + range.tb.LineInterval / 2;
                float x    = position.X - range.tb.CharWidth / 3;

                /*
                 * Brush  ForeBrush  = CwFCTB.fGetBrush(_nForeData);
                 * if (ForeBrush == null)
                 *   ForeBrush = new SolidBrush(range.tb.ForeColor);
                 *
                 * //  ForeBrush = Brushes.Blue;
                 * if (range.tb.ImeAllowed)
                 * {
                 *   //IME mode
                 *   for (int i = range.Start.iChar; i < range.End.iChar; i++)
                 *   {
                 *       SizeF size = FastColoredTextBox.GetCharSize(f, line[i].c);
                 *
                 *       var gs = gr.Save();
                 *       float k = size.Width > range.tb.CharWidth + 1 ? range.tb.CharWidth/size.Width : 1;
                 *       gr.TranslateTransform(x, y + (1 - k)*range.tb.CharHeight/2);
                 *       gr.ScaleTransform(k, (float) Math.Sqrt(k));
                 *       gr.DrawString(line[i].c.ToString(), f, ForeBrush, 0, 0, stringFormat);
                 *       gr.Restore(gs);
                 *       x += dx;
                 *
                 *   }
                 * }else {
                 */


                //         gr.DrawString(   range.Text, f, ForeBrush, x, y, stringFormat);


                TextRenderer.DrawText(gr, range.Text, f, new Point((int)x, (int)y), CwFCTB.fGetColor(_nForeData), Color.Transparent);


                /*
                 * //classic mode
                 * for (int i = range.Start.iChar; i < range.End.iChar; i++) {
                 *  //draw char
                 *  gr.DrawString(line[i].c.ToString(), f, ForeBrush, x, y, stringFormat);
                 *  x += dx;
                 * }
                 */


                //  }

                //  gr.Dispose();
                f.Dispose();
            }
        }
Пример #4
0
        //  Range oLastRange = new Range();

        public CwRange AddText(string text, Style style, int _nFore, Style _oBackStyle = null, int _nBack = 0)
        {
            //  AppendText(text,style);

            CwRange _oRange;

            if (text == null)
            {
                return(null);
            }

            Selection.ColumnSelectionMode = false;

            Place oldStart = Selection.Start;
            Place oldEnd   = Selection.End;

            Selection.BeginUpdate();
            TextSource.Manager.BeginAutoUndoCommands();
            try
            {
                if (TextSource.Count > 0)
                {
                    Selection.Start = new Place(TextSource[TextSource.Count - 1].Count, TextSource.Count - 1);
                }
                else
                {
                    Selection.Start = new Place(0, 0);
                }

                //remember last caret position
                Place last = Selection.Start;

                TextSource.Manager.ExecuteCommand(new InsertTextCommand(TextSource, text));


                _oRange = new CwRange(this, last, Selection.Start);
                _oRange.SetStyles(style, (char)_nFore, _oBackStyle, (char)_nBack);
                // _oRange.SetStyle(GuiConsole.oLinkStyle);


                //   CwRange _oCwRage = new CwRange(this,new Place(),null);
                ///   Range _oRange  = new Range(this);

                /*
                 *
                 * if (_oBackStyle != null) {
                 *  new Range(this, last, Selection.Start).SetStyle(_oBackStyle);
                 * }
                 * if (style != null){
                 * new Range(this, last, Selection.Start).SetStyle(style);
                 * //   new CwRange(this, last, Selection.Start).SetStyles(style, (char)_nFore, _oBackStyle, (char)2);
                 * }
                 *
                 */
            }
            finally
            {
                TextSource.Manager.EndAutoUndoCommands();
                Selection.Start = oldStart;
                Selection.End   = oldEnd;
                Selection.EndUpdate();
            }
            //
            Invalidate();
            return(_oRange);
        }