示例#1
0
        protected void Redraw(Graphics graphics)
        {
            allInvalid = false;

            if (backBrush == null)
            {
                backBrush = new SolidBrush(BackColor);
            }

            graphics.FillRectangle(backBrush, ClientRectangle);

            for (int i = 0; i < info.Count; i++)
            {
                if (graphics.IsVisible(new Rectangle(info[i].x, 0, info[i].width, FontHeight * lines.Count)))
                {
                    for (int l = 0; l < lines.Count; l++)
                    {
                        bool   highlight = (i == highlightedIndex) && (l == highlightedLine);
                        string s         = GetValue(info[i].note, lines[l]);
                        MyTextRenderer.DrawText(
                            graphics,
                            s,
                            Font,
                            new Rectangle(
                                info[i].x,
                                l * FontHeight,
                                info[i].width,
                                FontHeight),
                            !highlight ? ForeColor : BackColor,
                            !highlight ? BackColor : ForeColor,
                            Flags);
                    }
                }
            }
        }
示例#2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            using (GDIOffscreenBitmap hBitmapOffscreen = new GDIOffscreenBitmap(e.Graphics, ClientSize.Width, ClientSize.Height))
            {
                using (Brush backBrush = new SolidBrush(BackColor))
                {
                    hBitmapOffscreen.Graphics.FillRectangle(backBrush, ClientRectangle);
                }
                MyTextRenderer.DrawText(hBitmapOffscreen.Graphics, text, Font, new Point(), ForeColor);
                using (GDIRegion gdiRgnClip = new GDIRegion(e.Graphics.Clip.GetHrgn(e.Graphics)))
                {
                    using (GraphicsHDC hDC = new GraphicsHDC(e.Graphics))
                    {
                        // Graphics/GDI+ doesn't pass clip region through so we have to reset it explicitly
                        GDI.SelectClipRgn(hDC, gdiRgnClip);

                        bool f = GDI.BitBlt(
                            hDC,
                            0,
                            0,
                            hBitmapOffscreen.Width,
                            hBitmapOffscreen.Height,
                            hBitmapOffscreen.HDC,
                            0,
                            0,
                            GDI.SRCCOPY);
                    }
                }
            }
            base.OnPaint(e);
        }
示例#3
0
 public override Size GetPreferredSize(Size proposedSize)
 {
     using (Graphics graphics = CreateGraphics())
     {
         return(MyTextRenderer.MeasureText(graphics, Text, Font));
     }
 }
示例#4
0
        private void DrawOnePrimitive(Graphics graphics, int i)
        {
            object    item = i < underlying.Count ? underlying[i] : null;
            Rectangle rect = new Rectangle(0, i * fontHeight, Width, fontHeight);

            if (graphics.IsVisible(rect))
            {
                Brush foreground, background;
                Color foregroundColor, backgroundColor;
                if ((i >= underlying.Count) || !selected.ContainsKey(item))
                {
                    foreground      = foreBrush;
                    background      = backBrush;
                    foregroundColor = ForeColor;
                    backgroundColor = BackColor;
                }
                else
                {
                    foreground      = Focused ? selectForeBrush : selectForeInactiveBrush;
                    background      = Focused ? selectBackBrush : selectBackInactiveBrush;
                    foregroundColor = Focused ? selectedForeColor : selectedForeInactiveColor;
                    backgroundColor = Focused ? selectedBackColor : selectedBackInactiveColor;
                }
                using (Graphics graphics2 = Graphics.FromImage(offscreenStrip))
                {
                    Rectangle rect2 = rect;
                    rect2.Offset(-rect.X, -rect.Y);

                    graphics2.FillRectangle(background, rect2);
                    if (i < underlying.Count)
                    {
                        string text = getDisplayNameMethod(item);
                        if (showBlankItemsDifferently && String.IsNullOrEmpty(text))
                        {
                            text = "(no name)";
                        }
                        MyTextRenderer.DrawText(
                            graphics2,
                            text,
                            Font,
                            rect2.Location,
                            foregroundColor,
                            backgroundColor);
                    }

                    if ((cursor == i) && Focused)
                    {
                        graphics2.DrawRectangle(cursorPen, rect2.X, rect2.Y, rect2.Width - 1, rect2.Height - 1);
                    }
                }

                graphics.DrawImage(offscreenStrip, rect);
            }
        }
示例#5
0
 private int MeasureText(
     Graphics graphics,
     string text,
     Font font)
 {
     return(MyTextRenderer.MeasureText(
                graphics,
                text,
                font,
                new Size(ClientSize.Width, FontHeight),
                FormatFlags).Width);
 }
示例#6
0
        private int MeasureWidth(Graphics graphics, NoteNoteObjectRec note)
        {
            int width = 0;

            for (int i = 0; i < lines.Count; i++)
            {
                int width1 = MyTextRenderer.MeasureText(
                    graphics,
                    GetValue(note, lines[i]),
                    Font,
                    new Size(Int16.MaxValue, FontHeight),
                    Flags).Width;
                width = Math.Max(width, width1);
            }
            return(width);
        }
示例#7
0
        private void AddText(
            Graphics graphics,
            string label,
            string value,
            bool bold,
            bool highlight,
            ref int x,
            ref int y,
            out Rectangle bounds,
            out Rectangle editableBounds)
        {
            int labelWidth = MeasureText(graphics, label, Font);
            int valueWidth = MeasureText(graphics, value, bold ? boldFont : Font);

            if (x + labelWidth + valueWidth > ClientSize.Width)
            {
                FinishLine(graphics, ref x, ref y);
                StartLine(graphics, y);
            }
            bounds         = new Rectangle(x, y, labelWidth + valueWidth, FontHeight);
            editableBounds = new Rectangle(x + labelWidth, y, valueWidth, FontHeight);
            MyTextRenderer.DrawText(
                graphics,
                label,
                Font,
                new Point(
                    x,
                    y),
                ForeColor,
                FormatFlags);
            x += labelWidth;
            MyTextRenderer.DrawText(
                graphics,
                value,
                bold ? boldFont : Font,
                new Point(
                    x,
                    y),
                !highlight ? ForeColor : BackColor,
                !highlight ? Color.Transparent : ForeColor,
                FormatFlags);
            x += valueWidth;
        }
示例#8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle       face  = DeflateRect(ClientRectangle, Padding);
            TextFormatFlags flags = 0;

            if ((TextAlign & (ContentAlignment.BottomLeft | ContentAlignment.MiddleLeft | ContentAlignment.TopLeft)) != 0)
            {
                flags |= TextFormatFlags.Left;
            }
            if ((TextAlign & (ContentAlignment.BottomRight | ContentAlignment.MiddleRight | ContentAlignment.TopRight)) != 0)
            {
                flags |= TextFormatFlags.Right;
            }
            if ((TextAlign & (ContentAlignment.BottomCenter | ContentAlignment.MiddleCenter | ContentAlignment.TopCenter)) != 0)
            {
                flags |= TextFormatFlags.HorizontalCenter;
            }
            MyTextRenderer.DrawText(e.Graphics, Text, Font, face, ForeColor, flags);
        }
示例#9
0
        private void Redraw(Graphics graphics, bool drawSample)
        {
            EnsureGraphicsObjects();

            SetScrollOffsetsForRendering(graphics);

            Rectangle boundsWave = GetBoundsWave();

            if (sampleObject != null)
            {
                if (drawSample)
                {
                    RedrawSamplePartial(boundsWave.X, boundsWave.X + boundsWave.Width);
                }
                if (sampleObject.NumChannels == NumChannelsType.eSampleStereo)
                {
                    graphics.DrawLine(
                        trimPen,
                        0,
                        boundsWave.Y + boundsWave.Height / 2 - 1,
                        ContentWidth,
                        boundsWave.Y + boundsWave.Height / 2 - 1);
                }
            }

            using (Bitmap offscreenBitmap = new Bitmap(ClientSize.Width, 3 * OVERLINEHEIGHT, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
            {
                using (Graphics offscreenGraphics = Graphics.FromImage(offscreenBitmap))
                {
                    string[]  lines = new string[] { "Origin", loopStartLabel, loopEndLabel };
                    Rectangle rect  = new Rectangle(0, 0, ClientSize.Width, OVERLINEHEIGHT - 1);
                    foreach (string line in lines)
                    {
                        const TextFormatFlags format = TextFormatFlags.Left | TextFormatFlags.LeftAndRightPadding
                                                       | TextFormatFlags.NoPrefix | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.SingleLine;
                        offscreenGraphics.FillRectangle(backBrush, rect);
                        if (scrolling == 0)
                        {
                            MyTextRenderer.DrawText(offscreenGraphics, line, Font, rect, ForeColor, BackColor, format);
                        }
                        offscreenGraphics.DrawLine(forePen, 0, rect.Y + rect.Height, ClientSize.Width, rect.Y + rect.Height);
                        rect.Offset(0, OVERLINEHEIGHT);
                    }

                    int prevIndex = -1;
                    for (int X = 0; X < ClientSize.Width; X++)
                    {
                        int Index     = (int)((X + horizontalIndex) * xScale);
                        int IndexNext = (int)((X + 1 + horizontalIndex) * xScale);
                        if (IndexNext < Index + 1)
                        {
                            IndexNext = Index + 1;
                        }

                        if (prevIndex != Index)
                        {
                            bool[] which = new bool[]
                            {
                                (origin >= Index) && (origin < IndexNext),
                                (loopStart >= Index) && (loopStart < IndexNext),
                                (loopEnd >= Index) && (loopEnd < IndexNext),
                            };
                            for (int i = 0; i < which.Length; i++)
                            {
                                if (which[i])
                                {
                                    SmoothingMode oldSmoothingMode = offscreenGraphics.SmoothingMode;
                                    offscreenGraphics.SmoothingMode = SmoothingMode.AntiAlias;

                                    int Location = X;
                                    offscreenGraphics.FillPolygon(
                                        foreBrush,
                                        new Point[]
                                    {
                                        new Point(-4 + Location, i * OVERLINEHEIGHT - 1),
                                        new Point(Location, 7 + i * OVERLINEHEIGHT),
                                        new Point(4 + Location, i * OVERLINEHEIGHT - 1),
                                    });

                                    offscreenGraphics.SmoothingMode = oldSmoothingMode;

                                    offscreenGraphics.DrawLine(
                                        forePen,
                                        Location,
                                        i * OVERLINEHEIGHT,
                                        Location,
                                        Height);
                                }
                            }
                        }

                        prevIndex = Index;
                    }
                }

                graphics.DrawImage(offscreenBitmap, 0, 0, offscreenBitmap.Width, offscreenBitmap.Height);
            }
        }