Ejemplo n.º 1
0
        public void DrawBorder()
        {
            IStyle style = currentElement.style;

            if (style.borderColor != Color.clear && (style.borderLeftWidth > 0.0f || style.borderTopWidth > 0.0f || style.borderRightWidth > 0.0f || style.borderBottomWidth > 0.0f))
            {
                var painterParams = RectStylePainterParameters.GetDefault(currentElement);
                painterParams.color = style.borderColor;
                DrawRect(painterParams);
            }
        }
Ejemplo n.º 2
0
        public void DrawBackground()
        {
            IStyle style = currentElement.style;

            if (style.backgroundColor != Color.clear)
            {
                var painterParams = RectStylePainterParameters.GetDefault(currentElement);
                painterParams.border.SetWidth(0.0f);
                DrawRect(painterParams);
            }

            if (style.backgroundImage.value != null)
            {
                var painterParams = TextureStylePainterParameters.GetDefault(currentElement);
                painterParams.border.SetWidth(0.0f);
                DrawTexture(painterParams);
            }
        }
Ejemplo n.º 3
0
        internal void DrawWithTextSelectionAndCursor(IStylePainterInternal painter, string newText)
        {
            var keyboardTextEditor = editorEventHandler as KeyboardTextEditorEventHandler;

            if (keyboardTextEditor == null)
            {
                return;
            }

            keyboardTextEditor.PreDrawCursor(newText);

            int     cursorIndex   = editorEngine.cursorIndex;
            int     selectIndex   = editorEngine.selectIndex;
            Rect    localPosition = editorEngine.localPosition;
            Vector2 scrollOffset  = editorEngine.scrollOffset;

            IStyle style = this.style;

            float textScaling = TextNative.ComputeTextScaling(worldTransform);

            var textParams = TextStylePainterParameters.GetDefault(this, text);

            textParams.text          = " ";
            textParams.wordWrapWidth = 0.0f;
            textParams.wordWrap      = false;

            var   textNativeSettings = textParams.GetTextNativeSettings(textScaling);
            float lineHeight         = TextNative.ComputeTextHeight(textNativeSettings);
            float wordWrapWidth      = editorEngine.multiline
                ? contentRect.width
                : 0.0f;

            Input.compositionCursorPos = editorEngine.graphicalCursorPos - scrollOffset +
                                         new Vector2(localPosition.x, localPosition.y + lineHeight);

            Color drawCursorColor = m_CursorColor.GetSpecifiedValueOrDefault(Color.grey);

            int selectionEndIndex = string.IsNullOrEmpty(Input.compositionString)
                ? selectIndex
                : cursorIndex + Input.compositionString.Length;

            CursorPositionStylePainterParameters cursorParams;

            // Draw highlighted section, if any
            if (cursorIndex != selectionEndIndex)
            {
                var painterParams = RectStylePainterParameters.GetDefault(this);
                painterParams.color = selectionColor;
                painterParams.border.SetWidth(0.0f);
                painterParams.border.SetRadius(0.0f);

                int min = cursorIndex < selectionEndIndex ? cursorIndex : selectionEndIndex;
                int max = cursorIndex > selectionEndIndex ? cursorIndex : selectionEndIndex;

                cursorParams               = CursorPositionStylePainterParameters.GetDefault(this, text);
                cursorParams.text          = editorEngine.text;
                cursorParams.wordWrapWidth = wordWrapWidth;
                cursorParams.cursorIndex   = min;

                textNativeSettings = cursorParams.GetTextNativeSettings(textScaling);
                Vector2 minPos = TextNative.GetCursorPosition(textNativeSettings, cursorParams.rect, min);
                Vector2 maxPos = TextNative.GetCursorPosition(textNativeSettings, cursorParams.rect, max);

                minPos -= scrollOffset;
                maxPos -= scrollOffset;

                if (Mathf.Approximately(minPos.y, maxPos.y))
                {
                    painterParams.rect = new Rect(minPos.x, minPos.y, maxPos.x - minPos.x, lineHeight);
                    painter.DrawRect(painterParams);
                }
                else
                {
                    // Draw first line
                    painterParams.rect = new Rect(minPos.x, minPos.y, contentRect.xMax - minPos.x, lineHeight);
                    painter.DrawRect(painterParams);

                    var inbetweenHeight = (maxPos.y - minPos.y) - lineHeight;
                    if (inbetweenHeight > 0f)
                    {
                        // Draw all lines in-between
                        painterParams.rect = new Rect(contentRect.x, minPos.y + lineHeight, wordWrapWidth, inbetweenHeight);
                        painter.DrawRect(painterParams);
                    }

                    // Draw last line if not empty
                    if (maxPos.x != contentRect.x)
                    {
                        painterParams.rect = new Rect(contentRect.x, maxPos.y, maxPos.x, lineHeight);
                        painter.DrawRect(painterParams);
                    }
                }
            }

            // Draw the text with the scroll offset
            if (!string.IsNullOrEmpty(editorEngine.text) && contentRect.width > 0.0f && contentRect.height > 0.0f)
            {
                textParams      = TextStylePainterParameters.GetDefault(this, text);
                textParams.rect = new Rect(contentRect.x - scrollOffset.x, contentRect.y - scrollOffset.y, contentRect.width, contentRect.height);
                textParams.text = editorEngine.text;
                painter.DrawText(textParams);
            }

            // Draw the cursor
            if (cursorIndex == selectionEndIndex && (Font)style.font != null)
            {
                cursorParams               = CursorPositionStylePainterParameters.GetDefault(this, text);
                cursorParams.text          = editorEngine.text;
                cursorParams.wordWrapWidth = wordWrapWidth;
                cursorParams.cursorIndex   = cursorIndex;

                textNativeSettings = cursorParams.GetTextNativeSettings(textScaling);
                Vector2 cursorPosition = TextNative.GetCursorPosition(textNativeSettings, cursorParams.rect, cursorParams.cursorIndex);
                cursorPosition -= scrollOffset;
                var painterParams = new RectStylePainterParameters
                {
                    rect  = new Rect(cursorPosition.x, cursorPosition.y, 1f, lineHeight),
                    color = drawCursorColor
                };
                painter.DrawRect(painterParams);
            }

            // Draw alternate cursor, if any
            if (editorEngine.altCursorPosition != -1)
            {
                cursorParams               = CursorPositionStylePainterParameters.GetDefault(this, text);
                cursorParams.text          = editorEngine.text.Substring(0, editorEngine.altCursorPosition);
                cursorParams.wordWrapWidth = wordWrapWidth;
                cursorParams.cursorIndex   = editorEngine.altCursorPosition;

                textNativeSettings = cursorParams.GetTextNativeSettings(textScaling);
                Vector2 altCursorPosition = TextNative.GetCursorPosition(textNativeSettings, cursorParams.rect, cursorParams.cursorIndex);
                altCursorPosition -= scrollOffset;

                var painterParams = new RectStylePainterParameters
                {
                    rect  = new Rect(altCursorPosition.x, altCursorPosition.y, 1f, lineHeight),
                    color = drawCursorColor
                };
                painter.DrawRect(painterParams);
            }

            keyboardTextEditor.PostDrawCursor();
        }