好库网
/*
 * Copyright (C) 2013 Chen Hui <calmer91@链接已屏蔽>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      链接已屏蔽
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package master.flame.danmaku.danmaku.model;

public abstract class BaseDanmaku {

    public final static String DANMAKU_BR_CHAR = "/n";

    public final static int TYPE_SCROLL_RL = 1;

    public final static int TYPE_SCROLL_LR = 6;

    public final static int TYPE_FIX_TOP = 5;

    public final static int TYPE_FIX_BOTTOM = 4;

    public final static int TYPE_SPECIAL = 7;

    public final static int TYPE_MOVEABLE_XXX = 0; // TODO: add more type

    public final static int INVISIBLE = 0;

    public final static int VISIBLE = 1;

    /**
     * 鏄剧ず鏃堕棿(姣)
     */
    public long time;

    /**
     * 鏂囨湰
     */
    public String text;
    
    /**
     * 澶氳鏂囨湰: 濡傛灉鏈夊寘鍚崲琛岀闇€浜嬪厛鎷嗗垎鍒發ines
     */
    public String[] lines;

    /**
     * 鏂囨湰棰滆壊
     */
    public int textColor;

    /**
     * Z杞磋搴?     */
    public float rotationZ;

    /**
     * Y杞磋搴?     */
    public float rotationY;

    /**
     * 闃村奖/鎻忚竟棰滆壊
     */
    public int textShadowColor;

    /**
     * 涓嬪垝绾块鑹?0琛ㄧず鏃犱笅鍒掔嚎
     */
    public int underlineColor = 0;

    /**
     * 瀛椾綋澶у皬
     */
    public float textSize = -1;
    
    /**
     * 妗嗙殑棰滆壊,0琛ㄧず鏃犳
     */
    public int borderColor = 0;
    
    /**
     * 鍐呰竟璺?鍍忕礌)
     */
    public int padding = 0;
    
    /**
     * 寮瑰箷浼樺厛绾?0涓轰綆浼樺厛绾?>0涓洪珮浼樺厛绾т笉浼氳杩囨护鍣ㄨ繃婊?     */
    public byte priority = 0;

    /**
     * 鍗犱綅瀹藉害
     */
    public float paintWidth = -1;

    /**
     * 鍗犱綅楂樺害
     */
    public float paintHeight = -1;

    /**
     * 瀛樻椿鏃堕棿(姣)
     */
    public Duration duration;

    /**
     * 绱㈠紩/缂栧彿
     */
    public int index;

    /**
     * 鏄惁鍙
     */
    public int visibility;
    
    /**
     * 閲嶇疆浣?visible
     */
    private int visibleResetFlag = 0;
    
    /**
     * 閲嶇疆浣?measure
     */
    private int measureResetFlag = 0;

    /**
     * 缁樺埗鐢ㄧ紦瀛?     */
    public IDrawingCache<?> cache;
    
    /**
     * 鏄惁鏄洿鎾脊骞?     */
    public boolean isLive;
    
    /**
     * 寮瑰箷鍙戝竷鑰卛d, 0琛ㄧず娓稿
     */
    public int userId = 0;
    
    /**
     * 寮瑰箷鍙戝竷鑰卛d
     */
    public String userHash;
    
    /**
     * 鏄惁娓稿
     */
    public boolean isGuest;

    /**
     * 璁℃椂
     */
    protected DanmakuTimer mTimer;

    /**
     * 閫忔槑搴?     */
    protected int alpha = AlphaValue.MAX;

    public long getDuration() {
        return duration.value;
    }

    public void setDuration(Duration duration) {
        this.duration = duration;
    }

    public int draw(IDisplayer displayer) {
        return displayer.draw(this);
    }

    public boolean isMeasured() {
        return paintWidth >= 0 && paintHeight >= 0
                && measureResetFlag == GlobalFlagValues.MEASURE_RESET_FLAG;
    }

    public void measure(IDisplayer displayer) {
        displayer.measure(this);
        this.measureResetFlag = GlobalFlagValues.MEASURE_RESET_FLAG;
    }

    public boolean hasDrawingCache() {
        return cache != null && cache.get() != null;
    }

    public boolean isShown() {
        return this.visibility == VISIBLE
                && visibleResetFlag == GlobalFlagValues.VISIBLE_RESET_FLAG;
    }

    public boolean isTimeOut() {
        return mTimer == null || isTimeOut(mTimer.currMillisecond);
    }

    public boolean isTimeOut(long ctime) {
        return ctime - time >= duration.value;
    }

    public boolean isOutside() {
        return mTimer == null || isOutside(mTimer.currMillisecond);
    }

    public boolean isOutside(long ctime) {
        long dtime = ctime - time;
        return dtime <= 0 ||  dtime >= duration.value;
    }
    
    public boolean isLate() {
        return mTimer == null || mTimer.currMillisecond < time;
    }

    public void setVisibility(boolean b) {
        if(b){
            this.visibleResetFlag = GlobalFlagValues.VISIBLE_RESET_FLAG;
            this.visibility = VISIBLE;
        }else
            this.visibility = INVISIBLE;
    }

    public abstract void layout(IDisplayer displayer, float x, float y);

    public abstract float[] getRectAtTime(IDisplayer displayer, long currTime);

    public abstract float getLeft();

    public abstract float getTop();

    public abstract float getRight();

    public abstract float getBottom();

    /**
     * return the type of Danmaku
     * 
     * @return TYPE_SCROLL_RL = 0 TYPE_SCROLL_RL = 1 TYPE_SCROLL_LR = 2
     *         TYPE_FIX_TOP = 3; TYPE_FIX_BOTTOM = 4;
     */
    public abstract int getType();

    public DanmakuTimer getTimer() {
        return mTimer;
    }

    public void setTimer(DanmakuTimer timer) {
        mTimer = timer;
    }

    public int getAlpha() {
        return alpha;
    }
    
}