Layout.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:JotaTextEditor 作者:
/**
 * Fills in the specified Path with a representation of a cursor
 * at the specified offset.  This will often be a vertical line
 * but can be multiple discontinous lines in text with multiple
 * directionalities.
 */
public void getCursorPath(int point, Path dest,
                          CharSequence editingBuffer) {
    dest.reset();

    int line = getLineForOffset(point);
    int top = getLineTop(line);
    int bottom = getLineTop(line+1);

    float h1 = getPrimaryHorizontal(point) - 0.5f;
    float h2 = getSecondaryHorizontal(point) - 0.5f;

    int caps = TextKeyListener.getMetaState(editingBuffer,
                                            KeyEvent.META_SHIFT_ON) |
               JotaTextKeyListener.getMetaStateSelecting(editingBuffer);
    int fn = TextKeyListener.getMetaState(editingBuffer,
                                          KeyEvent.META_ALT_ON);
    int dist = 0;

    if (caps != 0 || fn != 0) {
        dist = (bottom - top) >> 2;

        if (fn != 0)
            top += dist;
        if (caps != 0)
            bottom -= dist;
    }

    if (h1 < 0.5f)
        h1 = 0.5f;
    if (h2 < 0.5f)
        h2 = 0.5f;

    if (h1 == h2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1, bottom);
    } else {
        dest.moveTo(h1, top);
        dest.lineTo(h1, (top + bottom) >> 1);

        dest.moveTo(h2, (top + bottom) >> 1);
        dest.lineTo(h2, bottom);
    }

    if (caps == 2) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);
        dest.lineTo(h2, bottom);
        dest.lineTo(h2 + dist, bottom + dist);
    } else if (caps == 1) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);

        dest.moveTo(h2 - dist, bottom + dist - 0.5f);
        dest.lineTo(h2 + dist, bottom + dist - 0.5f);

        dest.moveTo(h2 + dist, bottom + dist);
        dest.lineTo(h2, bottom);
    }

    if (fn == 2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);
        dest.lineTo(h1, top);
        dest.lineTo(h1 + dist, top - dist);
    } else if (fn == 1) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);

        dest.moveTo(h1 - dist, top - dist + 0.5f);
        dest.lineTo(h1 + dist, top - dist + 0.5f);

        dest.moveTo(h1 + dist, top - dist);
        dest.lineTo(h1, top);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号