예제 #1
0
        private void ShowTip()
        {
            lastTipClientWidth = ClientSize.Width;
            var  font   = ((IView)FindForm()).Settings.Get <EnvironmentSettings>().Font;
            var  eWidth = editor.Info.TextWidth / 2;
            Size size;
            var  err = "M " + error;

            error = null;

            using (var g = CreateGraphics())
                size = g.MeasureString(err, font, eWidth).ToSize();

            var ovl  = GetMessageOverlay();
            var xpad = Dpi.GetWidth(8);
            var ypad = Dpi.GetHeight(4);

            ovl.Padding  = new Padding(xpad, ypad, xpad, ypad);
            ovl.Width    = size.Width + xpad * 2 + ovl.BorderWidth * 2;
            ovl.Height   = size.Height + ypad * 2 + ovl.BorderWidth * 2;
            ovl.Location = new Point(FindForm().ClientRectangle.Width - ovl.Width, ClientSize.Height + editor.Info.TextTop);
            ovl.Font     = font;
            ovl.Text     = err;
            ovl.Visible  = true;
        }
예제 #2
0
        internal int MeasureHeight()
        {
            var env  = App.Component <IViewManager>().ActiveView.Settings.Get <EnvironmentSettings>();
            var padx = Dpi.GetWidth(30);
            var pady = Dpi.GetWidth(20);

            using (var g = CreateGraphics())
                using (var bigfont = new Font(env.FontName, env.FontSize + 3))
                {
                    var x     = Padding.Left + padx;
                    var y     = Padding.Top + pady + 0f;
                    var width = Width - Padding.Left - Padding.Right - padx * 2;
                    var size  = g.MeasureString(Caption, bigfont, width, TextFormats.Wrap);
                    y += size.Height + bigfont.Height;

                    foreach (var str in Detail.Split('\n'))
                    {
                        size = g.MeasureString(str, env.Font, width, TextFormats.Wrap);
                        y   += size.Height;
                    }

                    var ret = (int)Math.Round(y + pady, MidpointRounding.AwayFromZero);

                    if (Buttons != MessageButtons.None)
                    {
                        ret += bigfont.Height;
                        ret += env.Font.Height * 2;
                    }

                    return(ret);
                }
        }
예제 #3
0
        private void MarkOccurences(Graphics g, Style hl, Rectangle bounds, IEnumerable <SearchResult> seq)
        {
            var markHeight = bounds.Height / Editor.Lines.Count;
            var min        = Dpi.GetHeight(6);

            markHeight = markHeight < min ? min : markHeight;
            var lastLine = -1;

            foreach (var f in seq)
            {
                if (f.Line == lastLine)
                {
                    continue;
                }

                var linePos = f.Line / (Editor.Lines.Count / 100f);
                var markY   = Editor.Info.TextTop + linePos * (bounds.Height / 100f);
                var w       = Dpi.GetWidth(5);

                g.FillRectangle((hl.AdornmentColor.IsEmpty ? hl.BackColor : hl.AdornmentColor).Brush(), new RectangleF(
                                    bounds.X + (bounds.Width - w) / 2f,
                                    markY,
                                    w,
                                    Dpi.GetHeight(markHeight)));
                lastLine = f.Line;
            }
        }
예제 #4
0
 public MessageWindow()
 {
     DoubleBuffered = true;
     SetStyle(ControlStyles.FixedHeight | ControlStyles.FixedWidth, true);
     ShowInTaskbar   = ControlBox = MinimizeBox = MaximizeBox = false;
     FormBorderStyle = FormBorderStyle.None;
     StartPosition   = FormStartPosition.CenterParent;
     Padding         = new Padding(Dpi.GetWidth(3), Dpi.GetHeight(10), Dpi.GetWidth(3), Dpi.GetWidth(3));
     Width           = Dpi.GetWidth(420);
     KeyPreview      = true;
 }
예제 #5
0
파일: ViewForm.cs 프로젝트: vorov2/slot
        public ViewForm()
        {
            editor     = new StandardEditor(Settings.Get <EditorSettings>());
            statusBar  = new StatusBarControl(editor);
            commandBar = new CommandBarControl(editor);
            header     = new HeaderControl(editor);
            Initialize();

            if (!ReadState())
            {
                Width  = 800 * Dpi.GetWidth(1);
                Height = 600 * Dpi.GetWidth(1);
            }
        }
예제 #6
0
        private int AddButton(int x, int y, MessageButtons button, bool selected = false, bool cancel = false)
        {
            var but = new MessageButton(button, selected, cancel)
            {
                Top  = y,
                Left = x
            };

            but.ButtonClick += (o, e) =>
            {
                ButtonClicked = e.Button;
                AllowClose    = true;
                Close();
            };
            Controls.Add(but);
            but.Invalidate();
            return(but.Width + Dpi.GetWidth(10));
        }
예제 #7
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var theme = App.Component <ITheme>();
            var g     = e.Graphics;

            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.FillRectangle(theme.GetStyle(StandardStyle.PopupBorder).ForeColor.Brush(), ClientRectangle);
            g.FillRectangle(theme.GetStyle(StandardStyle.Popup).BackColor.Brush(),
                            new Rectangle(ClientRectangle.X + Padding.Left, ClientRectangle.Y + Padding.Top,
                                          ClientRectangle.Width - Padding.Right - Padding.Left,
                                          ClientRectangle.Height - Padding.Top - Padding.Bottom));

            var env  = App.Component <IViewManager>().ActiveView.Settings.Get <EnvironmentSettings>();
            var padx = Dpi.GetWidth(30);
            var pady = Dpi.GetWidth(20);

            using (var bigfont = new Font(env.FontName, env.FontSize + 3))
            {
                var x     = Padding.Left + padx;
                var y     = Padding.Top + pady + 0f;
                var width = Width - Padding.Left - Padding.Right - padx * 2;
                var size  = g.MeasureString(Caption, bigfont, width, TextFormats.Wrap);

                g.DrawString(Caption, bigfont, theme.GetStyle(StandardStyle.Keyword).ForeColor.Brush(),
                             new RectangleF(x, y, width, Height), TextFormats.Wrap);
                y += size.Height + bigfont.Height;

                foreach (var str in Detail.Split('\n'))
                {
                    size = g.MeasureString(str, env.Font, width, TextFormats.Wrap);
                    g.DrawString(str, env.Font, theme.GetStyle(StandardStyle.Default).ForeColor.Brush(),
                                 new RectangleF(x, y, width, Height), TextFormats.Wrap);
                    y += size.Height;
                }

                y += bigfont.Height;
                AddButtons(x, (int)y);
            }

            base.OnPaint(e);
        }
예제 #8
0
 private int GetCaretWidth(Graphics g)
 {
     return(BlockCaret ?
            editor.Info.CharWidth : Dpi.GetWidth(ThinCaret ? 1 : 2));
 }
예제 #9
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            var view   = App.Component <IViewManager>().ActiveView;
            var theme  = App.Component <ITheme>();
            var bag    = view.Settings.Get <EnvironmentSettings>();
            var style  = theme.GetStyle(StandardStyle.Popup);
            var style1 = theme.GetStyle(StandardStyle.PopupSelected);
            var style2 = theme.GetStyle(StandardStyle.PopupBorder);

            var g = e.Graphics;

            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            var xPad   = Dpi.GetHeight(3);
            var yPad   = Dpi.GetHeight(3);
            var x      = xPad;
            var y      = yPad;
            var height = (int)Math.Round(bag.Font.Height() * 1.1, MidpointRounding.AwayFromZero);

            if (SelectedIndex >= 10)
            {
                y -= height * (SelectedIndex - 9);
            }

            g.FillRectangle(style.BackColor.Brush(), e.ClipRectangle);
            var pen = style2.ForeColor.Pen();

            g.DrawRectangle(pen, new Rectangle(e.ClipRectangle.Location,
                                               new Size(e.ClipRectangle.Width - pen.Size(), e.ClipRectangle.Height - pen.Size())));
            var ws = App.Component <IViewManager>().ActiveView.Workspace;

            for (var i = 0; i < Buffers.Count; i++)
            {
                if (y > 0 && y < ClientSize.Height - yPad)
                {
                    var b  = Buffers[i];
                    var ic = style.ForeColor;

                    if (i == SelectedIndex)
                    {
                        g.FillRectangle(style1.BackColor.Brush(), new Rectangle(x - xPad + Dpi.GetWidth(1), y,
                                                                                ClientSize.Width - 2 * Dpi.GetWidth(1), height));
                        ic = style1.ForeColor.IsEmpty ? style.ForeColor : style1.ForeColor;
                    }

                    var font = bag.Font;
                    var size = g.MeasureString(b.File.Name, font.Get(FontStyle.Bold));
                    g.DrawString(b.File.Name, font.Get(FontStyle.Bold), ic.Brush(), x, y);

                    x += (int)size.Width;
                    var dirName = GetDirectoryName(ws, b.File.Directory);
                    g.DrawString(dirName, font, ic.Brush(),
                                 new RectangleF(x, y, ClientSize.Width - xPad * 2 - x, bag.Font.Height()), TextFormats.Path);
                    x = xPad;
                }

                y += height;
            }
        }
예제 #10
0
        public virtual int MeasureWidth(Graphics g)
        {
            var size = g.MeasureString(Text, Font, int.MaxValue, measureFormat);

            return((int)Math.Round(size.Width, MidpointRounding.AwayFromZero) + Dpi.GetWidth(8));
        }
예제 #11
0
파일: Editor.cs 프로젝트: vorov2/slot
        protected override void OnPaint(PaintEventArgs e)
        {
            if (Buffer == null)
            {
                return;
            }

            var dt = DateTime.Now;

            CaretRenderer.Suspend();

            e.Graphics.FillRectangle(Theme.GetStyle(StandardStyle.Default).BackColor.Brush(),
                                     new Rectangle(Info.TextLeft, Info.TextTop, Info.TextWidth, Info.TextHeight));

            e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            Renderer.DrawMargins(0, e.Graphics, TopMargins);
            Renderer.DrawMargins(0, e.Graphics, LeftMargins);
            e.Graphics.TranslateTransform(Scroll.ScrollPosition.X, Scroll.ScrollPosition.Y);

            var carets = new List <CaretData>();

            Renderer.DrawLines(e.Graphics, carets);

            e.Graphics.ResetTransform();

            Renderer.DrawLongLineIndicators(e.Graphics);
            Renderer.DrawWordWrapColumn(e.Graphics);

            Renderer.DrawMargins(Info.TextBottom, e.Graphics, BottomMargins);
            if (RightMargins.Count > 0)
            {
                Renderer.DrawMargins(ClientSize.Width - RightMargins.First().CalculateSize(), e.Graphics, RightMargins);
            }

            e.Graphics.TranslateTransform(Scroll.ScrollPosition.X, Scroll.ScrollPosition.Y);

            if (!LimitedMode || Focused)
            {
                foreach (var c in carets)
                {
                    CaretRenderer.DrawCaret(e.Graphics, c.X, c.Y, c.Blink);
                }
            }

            if (Scroll.ScrollPosition.X != 0)
            {
                var cs = Theme.GetStyle(StandardStyle.Default);
                e.Graphics.FillRectangle(ControlPaint.Dark(cs.BackColor, .05f).Brush(),
                                         new Rectangle(Info.TextLeft - Scroll.ScrollPosition.X,
                                                       Info.TextTop - Scroll.ScrollPosition.Y, Dpi.GetWidth(2),
                                                       Info.TextHeight + BottomMargins.TotalWidth));
            }

            Console.WriteLine("OnPaint time: " + (DateTime.Now - dt).TotalMilliseconds);
            base.OnPaint(e);
        }
예제 #12
0
        protected override void OnPaint(PaintEventArgs e)
        {
            AdjustHeight();
            var g      = e.Graphics;
            var bounds = e.ClipRectangle;
            var theme  = App.Component <ITheme>();
            var style  = theme.GetStyle(StandardStyle.StatusBar);
            var astyle = theme.GetStyle(StandardStyle.ActiveStatusBar);
            var font   = ((IView)FindForm()).Settings.Get <EnvironmentSettings>().SmallFont;

            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.FillRectangle(style.BackColor.Brush(), bounds);

            var ys = Dpi.GetHeight(2);

            g.FillRectangle(style.BackColor.Brush(),
                            new Rectangle(bounds.X, bounds.Y, bounds.Width, ys));
            var pad   = Dpi.GetWidth(6);
            var space = Editor.Info.SmallCharWidth;

            var lefts = Tiles.Where(t => t.Alignment == TileAlignment.Left);
            var x     = bounds.X + pad;

            foreach (var tile in lefts)
            {
                var foreColor = style.ForeColor;
                tile.Font = font;
                var width = tile.MeasureWidth(g);

                if (x + width > bounds.Width)
                {
                    break;
                }

                var rect = new Rectangle(x, bounds.Y + ys, width, bounds.Height - ys * 2);

                if (tile.Hover)
                {
                    g.FillRectangle(astyle.BackColor.Brush(), rect);
                    foreColor = astyle.ForeColor;
                }

                tile.Draw(g, foreColor, rect);
                tile.Left  = x;
                tile.Right = x + width;
                x         += width + space;
            }

            var maxx   = x;
            var rights = Tiles.Where(t => t.Alignment == TileAlignment.Right);

            x = bounds.X + bounds.Width - pad;

            foreach (var tile in rights)
            {
                var foreColor = style.ForeColor;
                tile.Font = font;
                var width = tile.MeasureWidth(g);
                x -= width;

                if (x < maxx)
                {
                    break;
                }

                var rect = new Rectangle(x, bounds.Y + ys, width, bounds.Height - ys * 2);

                if (tile.Hover)
                {
                    g.FillRectangle(astyle.BackColor.Brush(), rect);
                    foreColor = astyle.ForeColor;
                }

                tile.Left  = x;
                tile.Right = x + width;
                tile.Draw(g, foreColor, rect);
                x -= space;
            }
        }
예제 #13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            var g = e.Graphics;

            var ps        = editor.Theme.GetStyle(StandardStyle.Popup);
            var hps       = editor.Theme.GetStyle(StandardStyle.PopupHover);
            var sps       = editor.Theme.GetStyle(StandardStyle.PopupSelected);
            var bps       = editor.Theme.GetStyle(StandardStyle.PopupBorder);
            var borderPen = bps.ForeColor.Pen();

            g.FillRectangle(ps.BackColor.Brush(), e.ClipRectangle);
            g.DrawRectangle(borderPen,
                            e.ClipRectangle.Location.X, e.ClipRectangle.Location.Y,
                            e.ClipRectangle.Width - borderPen.Size(), e.ClipRectangle.Height - borderPen.Size());
            format.Trimming = Trimming;

            if (items != null)
            {
                for (var i = 0; i < items.Count; i++)
                {
                    var s = items[i];
                    var y = s.Y + CharWidth + ScrollPosition;

                    if (y >= CharWidth && y + LineHeight < Height)
                    {
                        var fc = ps.ForeColor;

                        if (hoverLine == i || selectedLine == i)
                        {
                            g.FillRectangle((selectedLine == i ? sps.BackColor : hps.BackColor).Brush(),
                                            new Rectangle(Dpi.GetWidth(1), y, Width - CharWidth - Dpi.GetWidth(1), LineHeight));
                            fc = selectedLine == i ? sps.ForeColor : hps.ForeColor;

                            if (fc.IsEmpty)
                            {
                                fc = ps.ForeColor;
                            }
                        }

                        g.DrawString(s.Item.ToString(),
                                     SmallFont ? editor.EditorSettings.SmallFont : editor.EditorSettings.Font,
                                     fc.Brush(),
                                     new Rectangle(CharWidth, y, Width - CharWidth * 2, LineHeight),
                                     format);

                        if (s.Item.Meta != null)
                        {
                            var mstr = s.Item.Meta.ToString();
                            var x    = Width - mstr.Length * CharWidth - CharWidth * 2;
                            foreach (var mc in mstr)
                            {
                                g.DrawString(mc.ToString(),
                                             SmallFont ? editor.EditorSettings.SmallFont : editor.EditorSettings.Font,
                                             fc.Brush(),
                                             new Point(x, y),
                                             format);
                                x += CharWidth;
                            }
                        }
                    }
                }
            }

            scrollBar.Size = CharWidth;
            var border = (int)borderPen.Width;

            scrollBar.Draw(g, new Rectangle(
                               Width - CharWidth - border,
                               border,
                               CharWidth,
                               Height - border * 2));
        }
예제 #14
0
파일: Renderer.cs 프로젝트: vorov2/slot
        private void DrawLine(Graphics g, Line line, int lineIndex, List <CaretData> carets)
        {
            var lmarg         = editor.Info.TextLeft;
            var tmarg         = editor.Info.TextTop;
            var cwidth        = editor.ClientSize.Width;//editor.Info.TextRight;
            var x             = lmarg;
            var y             = tmarg + line.Y;
            var oldcut        = 0;
            var sel           = editor.Buffer.Selections.IsLineSelected(lineIndex);
            var showEol       = editor.ShowEol;
            var showWs        = editor.ShowWhitespace;
            var specialSymbol = editor.Theme.GetStyle(StandardStyle.SpecialSymbol);
            var selection     = editor.Theme.GetStyle(StandardStyle.Selection);
            var currentLine   = editor.Theme.GetStyle(StandardStyle.CurrentLine);
            var indent        = -1;
            var nonWs         = false;
            var showInd       = editor.EditorSettings.ShowIndentationGuides;
            var indentSize    = editor.IndentSize;
            var cw            = editor.UseSmallFont ? editor.Info.SmallCharWidth : editor.Info.CharWidth;

            for (var j = 0; j < line.Stripes; j++)
            {
                var cut = line.GetCut(j);

                if (cut == line.Length)
                {
                    cut++;
                }

                if (y + editor.Scroll.ScrollPosition.Y >= tmarg && y + editor.Scroll.ScrollPosition.Y < editor.ClientSize.Height /*editor.Info.TextBottom*/)
                {
                    var curline = false;

                    if (lineIndex == editor.Buffer.Selections.Main.Caret.Line)
                    {
                        curline = DrawCurrentLineIndicator(g, y);
                    }

                    var tet = 0;

                    if (indent != -1)
                    {
                        tet = indent;
                        x  += tet * cw;
                    }

                    for (var i = oldcut; i < cut; i++)
                    {
                        var c  = line.CharAt(i);
                        var ct = c == '\t' ? Line.GetIndentationSize(tet, editor.IndentSize) : Line.GetCharWidth(c);

                        tet += ct;
                        var xw      = ct * cw;
                        var visible = x + editor.Scroll.ScrollPosition.X >= lmarg && x + editor.Scroll.ScrollPosition.X + xw <= cwidth;
                        var guide   = false;

                        if (visible)
                        {
                            var style = Style.Empty;
                            var rect  = new Rectangle(x, y, xw, editor.Info.LineHeight);
                            var pos   = new Pos(lineIndex, i);
                            var high  = sel && editor.Buffer.Selections.IsSelected(pos);
                            var ws    = c == '\t' || c == ' ';

                            if (!ws && !nonWs)
                            {
                                nonWs = true;
                            }

                            if (!nonWs && showInd && (tet - ct) % indentSize == 0)
                            {
                                DrawIndentationGuide(g, specialSymbol, x, y);
                                guide = true;
                            }

                            if (c == '\0' && showEol || ws && (showWs == ShowWhitespace.All ||
                                                               showWs == ShowWhitespace.Boundary && !nonWs ||
                                                               showWs == ShowWhitespace.Selection && high))
                            {
                                c     = c == '\0' ? '\u00B6' : c == '\t' ? '\u2192' : '·';
                                style = specialSymbol;
                                style = style.Combine(line.GetStyle(i, editor.Theme));
                            }
                            else
                            {
                                style = line.GetStyle(i, editor.Theme);
                            }

                            if (high)
                            {
                                var sstyle = selection;
                                style = sstyle.Combine(style);
                            }

                            StyleRenderer.DrawAll(style, g, rect, c, pos);

                            if (editor.Buffer.Selections.HasCaret(pos))
                            {
                                var blink = editor.Buffer.Selections.Main.Caret.Line == lineIndex &&
                                            editor.Buffer.Selections.Main.Caret.Col == i;

                                if (blink)
                                {
                                    var cg = editor.CaretRenderer.GetDrawingSurface();
                                    cg.Clear(high ? selection.BackColor
                                        : curline ? currentLine.BackColor
                                        : StyleRenderer.DefaultStyle.BackColor);
                                    StyleRenderer.DrawAll(style, cg, new Rectangle(default(Point), rect.Size), c, pos);

                                    if (editor.EditorSettings.LongLineIndicators.Any(ind => ind == i) || (editor.WordWrap && editor.WordWrapColumn == i))
                                    {
                                        cg.DrawLine(specialSymbol.ForeColor.Pen(), 0, 0, 0, rect.Size.Height);
                                    }

                                    if (guide)
                                    {
                                        DrawIndentationGuide(cg, specialSymbol, 0, 0);
                                    }

                                    if (editor.Scroll.ScrollPosition.X != 0 && x + editor.Scroll.ScrollPosition.X == editor.Info.TextLeft)
                                    {
                                        cg.FillRectangle(ControlPaint.Dark(StyleRenderer.DefaultStyle.BackColor, .05f).Brush(),
                                                         new Rectangle(0, 0, Dpi.GetWidth(2), rect.Height));
                                    }

                                    editor.CaretRenderer.Resume();
                                }

                                carets.Add(new CaretData(x, y, pos.Line, pos.Col, blink));
                            }
                        }

                        x += xw;
                    }

                    var addedWidth = 0;

                    if (line.Length > 0 && editor.ShowLineLength && j == line.Stripes - 1)
                    {
                        addedWidth = DrawLineLengthIndicator(g, line.Length, x, y);
                    }

                    if (line.Folding.Has(FoldingStates.Header) && lineIndex + 1 < editor.Buffer.Document.Lines.Count &&
                        !editor.Folding.IsLineVisible(lineIndex + 1))
                    {
                        DrawFoldingIndicator(g, x + addedWidth, y);
                    }
                }

                oldcut = cut;
                y     += editor.Info.LineHeight;
                x      = lmarg;
                indent = line.Indent;
            }
        }