开发者

how to make half round rect in BlackBerry application

how to make half round rect in BlackBerry application

Below email, user will enter emai开发者_运维问答l n below password a user will enter password, i m able to make square but upper square should be curve in upper side and lower square in lower side.


Something I made that I think will do what you want. You just have to add them to this Manager. Note that I don't think I have it compensating for things like margin or padding, so you can either figure that in with the paint() method, or just enclose it in another Manager that has the proper padding/margin:

public class GroupFieldManager extends VerticalFieldManager {
    private int _rounding;
    private int _bgColor;
    private int _borderColor;

    private boolean _divider;
    private int _dividerColor;

    public GroupFieldManager(boolean divider, long style) {
        super(style);
        _rounding = 20;
        _bgColor = 0xFFFFFF;
        _borderColor = 0xAAAAAA;
        _divider = divider;
        _dividerColor = 0xAAAAAA;
    }

    public GroupFieldManager(boolean divider) {
        this(divider, 0);
    }

    public GroupFieldManager() {
        this(false, 0);
    }

    /**
     * Sets whether or not to draw a divider
     * @param on
     */
    public void setDivider(boolean on) {
        _divider = on;
    }

    /**
     * Sets the color for the divider (also turns divider on)
     * @param color
     */
    public void setDividerColor(int color){
        _dividerColor = color;
        _divider = true;
    }

    /**
     * Sets the background color for the grouping
     * @param color
     */
    public void setBackgroundColor(int color) {
        _bgColor = color;
    }

    /**
     * Sets the border color for the grouping
     * @param color
     */
    public void setBorderColor(int color) {
        _borderColor = color;
    }

    /**
     * Sets the amount of rounding for the border
     * @param rounding
     */
    public void setRounding(int rounding) {
        _rounding = rounding;
    }

    protected void paint(Graphics graphics) {
        int oldColor = graphics.getColor();

        //draw the background
        graphics.setColor(_bgColor);
        graphics.fillRoundRect(0, 0, getWidth(), getHeight(), _rounding, _rounding);

        //draw the border
        graphics.setColor(_borderColor);
        graphics.drawRoundRect(0, 0, getWidth(), getHeight(), _rounding, _rounding);

        //draw dividers
        if(_divider) {
            graphics.setColor(_dividerColor);
            int y = 0;

            //go through each field, figure it's height, and draw a line under it
            for(int i=0;i<getFieldCount();i++) {
                if(i != getFieldCount() - 1) {
                    int height = getField(i).getHeight();
                    y += height;

                    graphics.drawLine(0, y, getWidth(), y);
                }
            }
        }

        graphics.setColor(oldColor);
        super.paint(graphics);
    }
}


Since there are only methods available to draw four round corners you can use a clipping rectangle to clip the drawing at a straight line, i.e. you actually paint a larger rounded rect but clip the lower (or upper) part of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜