/// <summary>
        /// Reallocates the indicator line objects.
        /// </summary>
        private void AllocateIndicatorLines()
        {
            // Figure out how many lines we can show on the screen.
            double height = Allocation.Height;

            RegionBlockStyle style = Theme.RegionStyles[BackgroundRegionName];

            height -= style == null
                                ? 0
                                : style.Height;

            style   = Theme.RegionStyles[VisibleRegionName];
            height -= style == null
                                ? 0
                                : style.Height;

            visibleIndicatorLines = (int)Math.Floor(height / Theme.IndicatorPixelHeight);

            // Create a new indicator line which is then populated
            // with null values to reset the bar.
            indicatorLines = new IndicatorLine[visibleIndicatorLines];

            for (int index = 0;
                 index < visibleIndicatorLines;
                 index++)
            {
                indicatorLines[index] = new IndicatorLine();
            }

            // Assign the lines, since we may have changed.
            AssignIndicatorLines();
        }
Example #2
0
        private static void SetupThemeIndicators(Theme theme)
        {
            // Set up the indicator styles.
            theme.IndicatorRenderStyle   = IndicatorRenderStyle.Ratio;
            theme.IndicatorPixelHeight   = 2;
            theme.IndicatorRatioPixelGap = 1;

            var indicatorBackgroundStyle = new RegionBlockStyle
            {
                //BackgroundColor = new Color(1, 0.9, 1)
            };

            var indicatorVisibleStyle = new RegionBlockStyle
            {
                BackgroundColor = new Color(1, 1, 0.9)
            };

            indicatorVisibleStyle.Borders.SetBorder(new Border(1, new Color(0, 0.5, 0)));

            // Add the styles to the theme.
            theme.RegionStyles[IndicatorView.BackgroundRegionName] =
                indicatorBackgroundStyle;
            theme.RegionStyles[IndicatorView.VisibleRegionName] = indicatorVisibleStyle;

            // Set up the various indicators.
            theme.IndicatorStyles["Error"] = new IndicatorStyle(
                "Error", 100, new Color(1, 0, 0));
            theme.IndicatorStyles["Warning"] = new IndicatorStyle(
                "Warning", 10, new Color(1, 165 / 255.0, 0));
            theme.IndicatorStyles["Chapter"] = new IndicatorStyle(
                "Chapter", 2, new Color(100 / 255.0, 149 / 255.0, 237 / 255.0));
        }
        private static void SetupThemeIndicators(Theme theme)
        {
            // Set up the indicator styles.
            theme.IndicatorRenderStyle = IndicatorRenderStyle.Ratio;
            theme.IndicatorPixelHeight = 2;
            theme.IndicatorRatioPixelGap = 1;

            var indicatorBackgroundStyle = new RegionBlockStyle
            {
                //BackgroundColor = new Color(1, 0.9, 1)
            };

            var indicatorVisibleStyle = new RegionBlockStyle
            {
                BackgroundColor = new Color(1, 1, 0.9)
            };

            indicatorVisibleStyle.Borders.SetBorder(new Border(1, new Color(0, 0.5, 0)));

            // Add the styles to the theme.
            theme.RegionStyles[IndicatorView.BackgroundRegionName] =
                indicatorBackgroundStyle;
            theme.RegionStyles[IndicatorView.VisibleRegionName] = indicatorVisibleStyle;

            // Set up the various indicators.
            theme.IndicatorStyles["Error"] = new IndicatorStyle(
                "Error", 100, new Color(1, 0, 0));
            theme.IndicatorStyles["Warning"] = new IndicatorStyle(
                "Warning", 10, new Color(1, 165 / 255.0, 0));
            theme.IndicatorStyles["Chapter"] = new IndicatorStyle(
                "Chapter", 2, new Color(100 / 255.0, 149 / 255.0, 237 / 255.0));
        }
        /// <summary>
        /// Configures the theme for all the elements used in the demo.
        /// </summary>
        private void SetupTheme()
        {
            // Grab the theme.
            Theme theme = editorView.Theme;

            // Set up the indicator styles.
            theme.IndicatorStyles["Error"] = new IndicatorStyle(
                "Error", 100, new Color(1, 0, 0));
            theme.IndicatorStyles["Warning"] = new IndicatorStyle(
                "Warning", 10, new Color(1, 165 / 255.0, 0));
            theme.IndicatorRenderStyle   = IndicatorRenderStyle.Ratio;
            theme.IndicatorPixelHeight   = 2;
            theme.IndicatorRatioPixelGap = 1;

            var indicatorBackgroundStyle = new RegionBlockStyle();

            indicatorBackgroundStyle.BackgroundColor = new Color(1, 0.9, 1);
            //indicatorBackgroundStyle.Borders.SetBorder(new Border(1, new Color(0.5, 0, 0)));
            theme.RegionStyles[IndicatorView.BackgroundRegionName] =
                indicatorBackgroundStyle;

            var indicatorVisibleStyle = new RegionBlockStyle();

            indicatorVisibleStyle.BackgroundColor = new Color(1, 1, 0.9);
            indicatorVisibleStyle.Borders.SetBorder(new Border(1, new Color(0, 0.5, 0)));
            theme.RegionStyles[IndicatorView.VisibleRegionName] = indicatorVisibleStyle;

            // Set up the editable text styles.
            for (var type = DemoLineStyleType.Default;
                 type <= DemoLineStyleType.Break;
                 type++)
            {
                // Create a line style for this type.
                var lineStyle = new LineBlockStyle(theme.TextLineStyle);

                theme.LineStyles[type.ToString()] = lineStyle;

                // Custom the style based on type.
                switch (type)
                {
                case DemoLineStyleType.Chapter:
                    lineStyle.FontDescription =
                        FontDescriptionCache.GetFontDescription("Serif Bold 24");
                    lineStyle.Borders.Bottom = new Border(2, new Color(0, 0, 0));
                    lineStyle.Margins.Top    = 6;
                    lineStyle.Margins.Bottom = 6;
                    break;

                case DemoLineStyleType.Heading:
                    lineStyle.FontDescription =
                        FontDescriptionCache.GetFontDescription("Sans Bold 18");
                    lineStyle.Padding.Left = 25;
                    break;

                case DemoLineStyleType.Borders:
                    lineStyle.Padding.Left   = 15;
                    lineStyle.Padding.Right  = 15;
                    lineStyle.Margins.Left   = 10;
                    lineStyle.Margins.Right  = 10;
                    lineStyle.Margins.Top    = 10;
                    lineStyle.Margins.Bottom = 10;
                    lineStyle.Borders.Bottom = new Border(5, new Color(1, 0, 0));
                    lineStyle.Borders.Top    = new Border(5, new Color(0, 1, 0));
                    lineStyle.Borders.Right  = new Border(5, new Color(0, 0, 1));
                    lineStyle.Borders.Left   = new Border(5, new Color(1, 0, 1));
                    break;

                case DemoLineStyleType.Default:
                    lineStyle.Padding.Left = 50;
                    break;

                case DemoLineStyleType.Break:
                    lineStyle.Padding.Left = 50;
                    lineStyle.Alignment    = Alignment.Center;
                    break;
                }
            }

            // Create the inactive header style.
            var inactiveHeadingStyle = new LineBlockStyle(theme.LineStyles["Heading"]);

            inactiveHeadingStyle.ForegroundColor = new Color(0.8, 0.8, 0.8);

            theme.LineStyles["Inactive Heading"] = inactiveHeadingStyle;
        }
Example #5
0
        /// <summary>
        /// Called when the widget is exposed or drawn.
        /// </summary>
        /// <param name="e">The e.</param>
        /// <returns></returns>
        protected override bool OnExposeEvent(EventExpose e)
        {
            // Figure out the area we are rendering into.
            Gdk.Rectangle area      = e.Region.Clipbox;
            var           cairoArea = new Rectangle(area.X, area.Y, area.Width, area.Height);

            using (Context cairoContext = CairoHelper.Create(e.Window))
            {
                // Create a render context.
                var renderContext = new RenderContext(cairoContext);
                renderContext.RenderRegion = cairoArea;

                // If we don't have a buffer at this point, don't render anything.
                if (Renderer == null ||
                    LineBuffer == null)
                {
                    return(true);
                }

                // Paint the background color of the window.
                RegionBlockStyle backgroundStyle =
                    Theme.RegionStyles[Theme.BackgroundRegionStyleName];
                DrawingUtility.DrawLayout(this, renderContext, cairoArea, backgroundStyle);

                // Reset the layout and its properties.
                Renderer.Width = area.Width - margins.Width;

                // Figure out the viewport area we'll be drawing.
                int offsetY = 0;

                if (verticalAdjustment != null)
                {
                    offsetY += (int)verticalAdjustment.Value;
                }

                var viewArea = new Rectangle(
                    area.X, area.Y + offsetY, area.Width, area.Height);

                // Determine the line range visible in the given area.
                int startLine,
                    endLine;
                Renderer.GetLineLayoutRange(viewArea, out startLine, out endLine);

                // Determine where the first line actually starts.
                int startLineY = 0;

                if (startLine > 0)
                {
                    startLineY = Renderer.GetLineLayoutHeight(0, startLine - 1);
                }

                // Go through the lines and draw each one in the correct position.
                double currentY = startLineY - offsetY;

                for (int lineIndex = startLine;
                     lineIndex <= endLine;
                     lineIndex++)
                {
                    // Figure out if we are on the current line.
                    var  lineContexts = LineContexts.None;
                    bool currentLine  = false;

                    if (lineIndex == caret.Position.LinePosition)
                    {
                        // Add the curent line to the context.
                        lineContexts |= LineContexts.CurrentLine;
                        currentLine   = true;
                    }

                    // Pull out the layout and style since we'll use it.
                    Layout         layout = Renderer.GetLineLayout(lineIndex, lineContexts);
                    LineBlockStyle style  = Renderer.GetLineStyle(lineIndex, lineContexts);

                    // Get the extents for that line.
                    int layoutWidth,
                        layoutHeight;
                    layout.GetPixelSize(out layoutWidth, out layoutHeight);

                    // Figure out the height of the line including padding.
                    double height = layoutHeight + style.Height;

                    if (currentLine)
                    {
                        // If we have a full-line background color, display it.
                        RegionBlockStyle currentLineStyle =
                            Theme.RegionStyles[Theme.CurrentLineRegionStyleName];

                        if (currentLineStyle != null)
                        {
                            var lineArea = new Rectangle(TextX, currentY, TextWidth, height);

                            DrawingUtility.DrawLayout(
                                this, renderContext, lineArea, currentLineStyle);
                        }

                        // If we have a wrapped line background color, draw it.
                        RegionBlockStyle currentWrappedLineStyle =
                            Theme.RegionStyles[Theme.CurrentWrappedLineRegionStyleName];

                        if (currentWrappedLineStyle != null)
                        {
                            // Get the wrapped line for the caret's position.
                            LayoutLine      wrappedLine = caret.Position.GetWrappedLine(this);
                            Pango.Rectangle wrappedLineExtents;

                            wrappedLine.GetPixelExtents(out wrappedLineExtents);

                            // Draw the current wrapped line index.
                            var wrappedLineArea = new Rectangle(
                                TextX,
                                currentY + wrappedLineExtents.Y + style.Top,
                                TextWidth,
                                wrappedLineExtents.Height);

                            DrawingUtility.DrawLayout(
                                this, renderContext, wrappedLineArea, currentWrappedLineStyle);
                        }
                    }

                    // Draw the current line along with wrapping and padding.
                    DrawingUtility.DrawLayout(
                        this,
                        renderContext,
                        new Rectangle(TextX, currentY, TextWidth, height),
                        layout,
                        style);

                    // Render out the margin renderers.
                    margins.Draw(
                        this, renderContext, lineIndex, new PointD(0, currentY), height, style);

                    // Move down a line.
                    currentY += height;
                }

                // Draw the caret on the screen, but only if we have focus.
                if (IsFocus)
                {
                    caret.Draw(renderContext);
                }

                // Show the scroll region, if requested.
                if (editorViewSettings.ShowScrollPadding)
                {
                    cairoContext.Color = new Color(1, 0.5, 0.5);
                    cairoContext.Rectangle(scrollPaddingRegion);
                    cairoContext.Stroke();
                }
            }

            return(true);
        }