Add TextView

This commit is contained in:
seven332 committed 2015-07-26 11:53:08 +08:00
1 parent afe28f866a
commit 8a10af090f
1 file changed
+44
@@ -0,0 +1,44 @@
package com.hippo.ehviewer.gallery.ui;
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
import com.hippo.ehviewer.gallery.glrenderer.TextTexture;
public class TextView extends GLView {
TextTexture mTextTexture;
private String mText = "";
public TextView(TextTexture textTexture) {
mTextTexture = textTexture;
}
public void setText(String text) {
if (text == null) {
text = "";
}
if (!text.equals(mText)) {
mText = text;
requestLayout();
}
}
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
int textWidth = 0;
int textHight = 0;
if (mTextTexture != null) {
textWidth = (int) mTextTexture.getTextWidth(mText);
textHight = (int) mTextTexture.getTextHeight(mText);
}
setMeasuredSize(getDefaultSize(Math.max(getMinimumWidth(), textWidth), widthSpec),
getDefaultSize(Math.max(getMinimumHeight(), textHight), heightSpec));
}
@Override
protected void onRender(GLCanvas canvas) {
mTextTexture.drawText(canvas, mText, 0, 0);
}
}