public void drawScroller(DrawCanvas canvas, Rect drawRegion, Rect contentsSize)
        {
            this.drawRegion   = drawRegion;
            this.contentsSize = contentsSize;

            if (hideBars)
            {
                return;
            }

            if (yScrollEnabled())
            {
                ICanvasRectItem rectangle = new CanvasItemFactory().createCanvasRectItem();
                rectangle.setColor(new Layout.Color(scrollerBrightness, scrollerBrightness, scrollerBrightness));
                rectangle.setSize(scrollerWidth, scrollerHeight);
                canvas.drawToCanvas(rectangle, drawRegion.Right - scrollerWidth - scrollerPadding, drawRegion.Top + scrollerPadding + getYScrollerYPos());
            }

            if (drawRegion.Width < contentsSize.Width)
            {
                ICanvasRectItem rectangle = new CanvasItemFactory().createCanvasRectItem();
                rectangle.setColor(new Layout.Color(scrollerBrightness, scrollerBrightness, scrollerBrightness));
                rectangle.setSize(scrollerHeight, scrollerWidth);
                canvas.drawToCanvas(rectangle, drawRegion.Left + scrollerPadding + getXScrollerXPos(), drawRegion.Bottom - scrollerWidth - scrollerPadding);
            }
        }
        public override void draw(DrawCanvas drawCanvas, Rect rect)
        {
            drawCanvas.enableClipping((int)rect.Left, (int)rect.Top, (int)rect.Width, (int)rect.Height);

            ICanvasTextItem textCanvasItem = new CanvasItemFactory().createCanvasTextItem();

            textCanvasItem.setText(text);
            textCanvasItem.setTextColor(textColor);
            textCanvasItem.setTextSize(textSize);
            drawCanvas.drawToCanvas(textCanvasItem, rect.Left, rect.Top);

            drawCanvas.disableClipping();
        }
Пример #3
0
        private void drawCursor(DrawCanvas drawCanvas, Rect bounds, double charWidth, double charHeight)
        {
            Point cursorPos = getTextPosForIndex(getCursorIndex());

            cursorPos.X += bounds.Left;      // Add textBox offset
            cursorPos.Y += bounds.Top;
            cursorPos.X += scroller.scrollX; // Add textBox offset
            cursorPos.Y += scroller.scrollY;

            ICanvasRectItem cursorRect = new CanvasItemFactory().createCanvasRectItem();

            cursorRect.setColor(edgeColor);
            cursorRect.setSize(CURSOR_WIDTH, charHeight - 2);
            drawCanvas.drawToCanvas(cursorRect, cursorPos.X + 1, cursorPos.Y + 1);
        }
        private void drawCharecterHighlight(DrawCanvas canvas, char charecter, double x, double y, Color color)
        {
            if (color.a == 0)
            {
                return;
            }

            double selectionWidth = charecterDimensions.Width;

            if (charecter == '\t')
            {
                selectionWidth *= tabSpaces;
            }

            ICanvasRectItem selection = new CanvasItemFactory().createCanvasRectItem();

            selection.setColor(color);
            selection.setSize(selectionWidth, charecterDimensions.Height);
            canvas.drawToCanvas(selection, x, y);
        }
        public override void draw(DrawCanvas drawCanvas, Rect rect)
        {
            ICanvasRectItem edge = new CanvasItemFactory().createCanvasRectItem();

            edge.setColor(edgeColor);
            edge.setSize(rect.Width, rect.Height);
            drawCanvas.drawToCanvas(edge, rect.Left, rect.Top);

            if (rect.Width - 2 * BORDER_SIZE < 0 || rect.Height - 2 * BORDER_SIZE < 0)
            {
                return;
            }

            Rect textRegion = new Rect(new Point(rect.Left + BORDER_SIZE, rect.Top + BORDER_SIZE), new Size(rect.Width - 2 * BORDER_SIZE, rect.Height - 2 * BORDER_SIZE));

            drawCanvas.enableClipping((int)textRegion.Left, (int)textRegion.Top, (int)textRegion.Width, (int)textRegion.Height);

            ICanvasRectItem background = new CanvasItemFactory().createCanvasRectItem();

            background.setColor(backgroundColor);
            background.setSize(textRegion.Width, textRegion.Height);
            drawCanvas.drawToCanvas(background, textRegion.X, textRegion.Y);

            calcualteAllTextPositions();

            previousBounds = new Rect(new Point(textRegion.X, textRegion.Y), new Size(textRegion.Width, textRegion.Height));

            int selectionStartIndex = Math.Min(selectionBeganIndex, cursorIndex);
            int selectionEndIndex   = Math.Max(selectionBeganIndex, cursorIndex);

            for (int i = 0; i < displayText.Length; i++)
            {
                if (displayText[i] == '\r' || displayText[i] == '\n')
                {
                    continue;
                }

                Point letterPos = getTextPosForIndex(i);
                letterPos.X += textRegion.Left;  // Add textBox offset
                letterPos.Y += textRegion.Top;
                letterPos.X += scroller.scrollX; // Add textBox offset
                letterPos.Y += scroller.scrollY;

                if (letterPos.X + charecterDimensions.Width < 0)
                {
                    continue;
                }
                if (letterPos.Y + charecterDimensions.Height < 0)
                {
                    continue;
                }
                if (letterPos.X > textRegion.Width)
                {
                    continue;
                }
                if (letterPos.Y > textRegion.Height + rect.Top)
                {
                    continue;
                }

                if ((i >= selectionStartIndex && i < selectionEndIndex)) // Draw cursor selection
                {
                    drawCharecterHighlight(drawCanvas, displayText[i], letterPos.X, letterPos.Y, edgeColor);
                }
                else
                {
                    drawCharecterHighlight(drawCanvas, displayText[i], letterPos.X, letterPos.Y, contents.getColorForCharAtIndex(i));
                }

                if (displayText[i] != '\t')
                {
                    ICanvasTextItem letterCanvasItem = new CanvasItemFactory().createCanvasTextItem();
                    letterCanvasItem.setText(displayText[i] + "");
                    drawCanvas.drawToCanvas(letterCanvasItem, letterPos.X, letterPos.Y);
                }
            }

            if (singleLine)
            {
                scroller.hideBars = true;
            }

            scroller.drawScroller(drawCanvas, textRegion, new Rect(new Size(maxXPos + charecterDimensions.Width, maxYPos + charecterDimensions.Height)));

            drawCanvas.disableClipping();
        }