Skip to content

Commit

Permalink
DrawTask: check if verifer-enabled before DanmakuRetainer.fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiao committed Sep 21, 2015
1 parent 57fbaa5 commit daf4af1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package master.flame.danmaku.controller;

import android.content.Context;
import android.graphics.Canvas;

import master.flame.danmaku.danmaku.model.AbsDisplayer;
Expand Down Expand Up @@ -76,6 +75,7 @@ public DrawTask(DanmakuTimer timer, AbsDisplayer<?> disp,
TaskListener taskListener) {
mTaskListener = taskListener;
mRenderer = new DanmakuRenderer();
mRenderer.setVerifierEnabled(DanmakuGlobalConfig.DEFAULT.isPreventOverlappingEnabled() || DanmakuGlobalConfig.DEFAULT.isMaxLinesLimited());
mDisp = disp;
initTimer(timer);
Boolean enable = DanmakuGlobalConfig.DEFAULT.isDuplicateMergingEnabled();
Expand Down Expand Up @@ -302,6 +302,11 @@ protected boolean handleOnDanmakuConfigChanged(DanmakuGlobalConfig config, Danma
} else if (DanmakuConfigTag.SCALE_TEXTSIZE.equals(tag) || DanmakuConfigTag.SCROLL_SPEED_FACTOR.equals(tag)) {
requestClearRetainer();
handled = false;
} else if (DanmakuConfigTag.MAXIMUN_LINES.equals(tag) || DanmakuConfigTag.OVERLAPPING_ENABLE.equals(tag)) {
if (mRenderer != null) {
mRenderer.setVerifierEnabled(values != null);
}
handled = true;
}
return handled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public enum BorderType {

private BaseCacheStuffer mCacheStuffer;

private boolean mIsMaxLinesLimited;

private boolean mIsPreventOverlappingEnabled;

/**
* set typeface
*
Expand Down Expand Up @@ -559,6 +563,7 @@ public boolean isDuplicateMergingEnabled() {
* @return
*/
public DanmakuGlobalConfig setMaximumLines(Map<Integer, Integer> pairs) {
mIsMaxLinesLimited = (pairs != null);
if (pairs == null) {
DanmakuFilters.getDefault()
.unregisterFilter(DanmakuFilters.TAG_MAXIMUN_LINES_FILTER, false);
Expand All @@ -583,6 +588,7 @@ public DanmakuGlobalConfig setOverlapping(Map<Integer, Boolean> pairs) {
* @return
*/
public DanmakuGlobalConfig preventOverlapping(Map<Integer, Boolean> pairs) {
mIsPreventOverlappingEnabled = (pairs != null);
if (pairs == null) {
DanmakuFilters.getDefault()
.unregisterFilter(DanmakuFilters.TAG_OVERLAPPING_FILTER, false);
Expand All @@ -594,6 +600,14 @@ public DanmakuGlobalConfig preventOverlapping(Map<Integer, Boolean> pairs) {
return this;
}

public boolean isMaxLinesLimited() {
return mIsMaxLinesLimited;
}

public boolean isPreventOverlappingEnabled() {
return mIsPreventOverlappingEnabled;
}

/**
* 设置缓存绘制填充器,默认使用{@link SimpleTextCacheStuffer}只支持纯文字显示, 如果需要图文混排请设置{@link SpannedCacheStuffer}
* 如果需要定制其他样式请扩展{@link SimpleTextCacheStuffer}|{@link SpannedCacheStuffer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface IRenderer {

public static final int NOTHING_RENDERING = 0;
public static final int CACHE_RENDERING = 1;
public static final int TEXT_RENDERING = 2;
public static final int TEXT_RENDERING = 2;

public class Area {

Expand Down Expand Up @@ -131,4 +131,6 @@ public void set(RenderingState other) {

public void release();

public void setVerifierEnabled(boolean enabled);

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public boolean skipLayout(BaseDanmaku danmaku, float fixedTop, int lines, boolea
return false;
}
};
private boolean mVerifierEnabled;

@Override
public void clear() {
Expand All @@ -53,7 +54,12 @@ public void release() {
DanmakusRetainer.release();
DanmakuFilters.getDefault().clear();
}


@Override
public void setVerifierEnabled(boolean enabled) {
mVerifierEnabled = enabled;
}

@Override
public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRenderTime) {
int lastTotalDanmakuCount = mRenderingState.totalDanmakuCount;
Expand Down Expand Up @@ -91,7 +97,7 @@ public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRender
}

// layout
DanmakusRetainer.fix(drawItem, disp, mVerifier);
DanmakusRetainer.fix(drawItem, disp, mVerifierEnabled ? mVerifier : null);

// draw
if (!drawItem.isOutside() && drawItem.isShown()) {
Expand Down

0 comments on commit daf4af1

Please sign in to comment.