diff options
author | Owen Lin <owenlin@google.com> | 2010-05-10 18:27:17 +0800 |
---|---|---|
committer | Owen Lin <owenlin@google.com> | 2010-05-13 18:24:53 +0800 |
commit | bef57e1d1fbb1881a7e3a22bb7567e8e7c2f0795 (patch) | |
tree | 722ac675dc0b9a2551018d879c9a05ff2a21fe09 /src | |
parent | 125dee14bedc326bfbbb751278d549bafe349135 (diff) | |
download | LegacyCamera-bef57e1d1fbb1881a7e3a22bb7567e8e7c2f0795.zip LegacyCamera-bef57e1d1fbb1881a7e3a22bb7567e8e7c2f0795.tar.gz LegacyCamera-bef57e1d1fbb1881a7e3a22bb7567e8e7c2f0795.tar.bz2 |
Create a ColorTexture to draw pure color in GL.
Change-Id: I9dfa69b6037397d01a43c976b2d02acb16f2af62
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/ui/BasicIndicator.java | 5 | ||||
-rw-r--r-- | src/com/android/camera/ui/ColorTexture.java | 34 | ||||
-rw-r--r-- | src/com/android/camera/ui/GLListView.java | 4 | ||||
-rw-r--r-- | src/com/android/camera/ui/GLOptionHeader.java | 10 | ||||
-rw-r--r-- | src/com/android/camera/ui/GLRootView.java | 43 | ||||
-rw-r--r-- | src/com/android/camera/ui/HeadUpDisplay.java | 5 | ||||
-rw-r--r-- | src/com/android/camera/ui/IndicatorBar.java | 4 | ||||
-rw-r--r-- | src/com/android/camera/ui/OtherSettingsIndicator.java | 5 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomIndicator.java | 4 |
9 files changed, 86 insertions, 28 deletions
diff --git a/src/com/android/camera/ui/BasicIndicator.java b/src/com/android/camera/ui/BasicIndicator.java index dc52af7..513b20d 100644 --- a/src/com/android/camera/ui/BasicIndicator.java +++ b/src/com/android/camera/ui/BasicIndicator.java @@ -9,6 +9,7 @@ import com.android.camera.Util; import com.android.camera.ui.GLListView.OnItemSelectedListener; class BasicIndicator extends AbstractIndicator { + private static final int COLOR_OPTION_ITEM_HIGHLIGHT = 0xFF181818; private final ResourceTexture mIcon[]; private final IconListPreference mPreference; @@ -56,8 +57,8 @@ class BasicIndicator extends AbstractIndicator { if (mPopupContent == null) { Context context = getGLRootView().getContext(); mPopupContent = new GLListView(context); - mPopupContent.setHighLight(new NinePatchTexture( - context, R.drawable.optionitem_highlight)); + mPopupContent.setHighLight( + new ColorTexture(COLOR_OPTION_ITEM_HIGHLIGHT)); mPopupContent.setScroller(new NinePatchTexture( context, R.drawable.scrollbar_handle_vertical)); mModel = new PreferenceAdapter(context, mPreference); diff --git a/src/com/android/camera/ui/ColorTexture.java b/src/com/android/camera/ui/ColorTexture.java new file mode 100644 index 0000000..9054d8f --- /dev/null +++ b/src/com/android/camera/ui/ColorTexture.java @@ -0,0 +1,34 @@ +package com.android.camera.ui; + +import android.graphics.Bitmap; +import android.graphics.Rect; + +class ColorTexture extends FrameTexture { + + private static final Rect EMPTY_PADDINGS = new Rect(); + private int mColor; + + public ColorTexture(int color) { + mColor = color; + } + + @Override + public Rect getPaddings() { + return EMPTY_PADDINGS; + } + + @Override + protected void freeBitmap(Bitmap bitmap) { + throw new UnsupportedOperationException(); + } + + @Override + protected Bitmap getBitmap() { + throw new UnsupportedOperationException(); + } + + @Override + public void draw(GLRootView root, int x, int y) { + root.drawColor(x, y, mWidth, mHeight, mColor); + } +} diff --git a/src/com/android/camera/ui/GLListView.java b/src/com/android/camera/ui/GLListView.java index c4a607c..020d6c0 100644 --- a/src/com/android/camera/ui/GLListView.java +++ b/src/com/android/camera/ui/GLListView.java @@ -32,7 +32,7 @@ class GLListView extends GLView { private int mHighlightIndex = INDEX_NONE; private GLView mHighlightView; - private NinePatchTexture mHighLight; + private FrameTexture mHighLight; private NinePatchTexture mScrollbar; private int mVisibleStart = 0; // inclusive @@ -109,7 +109,7 @@ class GLListView extends GLView { invalidate(); } - public void setHighLight(NinePatchTexture highLight) { + public void setHighLight(FrameTexture highLight) { mHighLight = highLight; } diff --git a/src/com/android/camera/ui/GLOptionHeader.java b/src/com/android/camera/ui/GLOptionHeader.java index a922026..01914e2 100644 --- a/src/com/android/camera/ui/GLOptionHeader.java +++ b/src/com/android/camera/ui/GLOptionHeader.java @@ -4,8 +4,6 @@ import static com.android.camera.ui.GLRootView.dpToPixel; import android.content.Context; import android.graphics.Rect; -import com.android.camera.R; - import javax.microedition.khronos.opengles.GL11; class GLOptionHeader extends GLView { @@ -13,12 +11,13 @@ class GLOptionHeader extends GLView { private static final float FONT_SIZE = 12; private static final int HORIZONTAL_PADDINGS = 4; private static final int VERTICAL_PADDINGS = 2; + private static final int COLOR_OPTION_HEADER = 0xFF2B2B2B; private static int sHorizontalPaddings = -1; private static int sVerticalPaddings; private final StringTexture mTitle; - private NinePatchTexture mBackground; + private FrameTexture mBackground; private static void initializeStaticVariables(Context context) { if (sHorizontalPaddings >= 0) return; @@ -31,13 +30,12 @@ class GLOptionHeader extends GLView { float fontSize = GLRootView.dpToPixel(context, FONT_SIZE); mTitle = StringTexture.newInstance(title, fontSize, FONT_COLOR); - setBackground(new NinePatchTexture( - context, R.drawable.optionheader_background)); + setBackground(new ColorTexture(COLOR_OPTION_HEADER)); setPaddings(sHorizontalPaddings, sVerticalPaddings, sHorizontalPaddings, sVerticalPaddings); } - public void setBackground(NinePatchTexture background) { + public void setBackground(FrameTexture background) { if (mBackground == background) return; mBackground = background; invalidate(); diff --git a/src/com/android/camera/ui/GLRootView.java b/src/com/android/camera/ui/GLRootView.java index 0bbc3ed..97d236f 100644 --- a/src/com/android/camera/ui/GLRootView.java +++ b/src/com/android/camera/ui/GLRootView.java @@ -4,6 +4,7 @@ import com.android.camera.Util; import android.app.Activity; import android.content.Context; +import android.graphics.Color; import android.graphics.Matrix; import android.graphics.PixelFormat; import android.opengl.GLSurfaceView; @@ -47,6 +48,8 @@ public class GLRootView extends GLSurfaceView private static final int FLAG_INITIALIZED = 1; private static final int FLAG_NEED_LAYOUT = 2; + private static boolean mTexture2DEnabled; + private static float sPixelDensity = -1f; private GL11 mGL; @@ -237,6 +240,7 @@ public class GLRootView extends GLSurfaceView gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glEnable(GL11.GL_TEXTURE_2D); + mTexture2DEnabled = true; gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE); @@ -288,14 +292,13 @@ public class GLRootView extends GLSurfaceView public void drawRect(int x, int y, int width, int height) { float matrix[] = mMatrixValues; mTransformation.getMatrix().getValues(matrix); - drawRect(x, y, width, height, matrix, mTransformation.getAlpha()); + drawRect(x, y, width, height, matrix); } private void drawRect( - int x, int y, int width, int height, float matrix[], float alpha) { + int x, int y, int width, int height, float matrix[]) { GL11 gl = mGL; gl.glPushMatrix(); - setAlphaValue(alpha); gl.glMultMatrixf(toGLMatrix(matrix), 0); gl.glTranslatef(x, y, 0); gl.glScalef(width, height, 1); @@ -303,12 +306,6 @@ public class GLRootView extends GLSurfaceView gl.glPopMatrix(); } - public void drawRect(int x, int y, int width, int height, float alpha) { - float matrix[] = mMatrixValues; - mTransformation.getMatrix().getValues(matrix); - drawRect(x, y, width, height, matrix, alpha); - } - private float[] mapPoints(Matrix matrix, int x1, int y1, int x2, int y2) { float[] point = mPointBuffer; point[0] = x1; point[1] = y1; point[2] = x2; point[3] = y2; @@ -351,9 +348,34 @@ public class GLRootView extends GLSurfaceView return v; } + public void drawColor(int x, int y, int width, int height, int color) { + drawColor(x, y, width, height, color, mTransformation.getAlpha()); + } + + public void drawColor(int x, int y, + int width, int height, int color, float alpha) { + GL11 gl = mGL; + if (mTexture2DEnabled) { + // Set mLastAlpha to an invalid value, so that it will reset again + // in setAlphaValue(float) later. + mLastAlpha = -1.0f; + mGL.glDisable(GL11.GL_TEXTURE_2D); + mTexture2DEnabled = false; + } + alpha /= 256.0f; + gl.glColor4f(Color.red(color) * alpha, Color.green(color) * alpha, + Color.blue(color) * alpha, Color.alpha(color) * alpha); + drawRect(x, y, width, height); + } + public void drawTexture( Texture texture, int x, int y, int width, int height, float alpha) { + if (!mTexture2DEnabled) { + mGL.glEnable(GL11.GL_TEXTURE_2D); + mTexture2DEnabled = true; + } + if (!texture.bind(this, mGL)) { throw new RuntimeException("cannot bind" + texture.toString()); } @@ -367,7 +389,8 @@ public class GLRootView extends GLSurfaceView if (isMatrixRotatedOrFlipped(mMatrixValues)) { texture.getTextureCoords(mCoordBuffer, 0); mTexCoordBuffer.asFloatBuffer().put(mCoordBuffer).position(0); - drawRect(x, y, width, height, mMatrixValues, alpha); + setAlphaValue(alpha); + drawRect(x, y, width, height, mMatrixValues); } else { // draw the rect from bottom-left to top-right float points[] = mapPoints(matrix, x, y + height, x + width, y); diff --git a/src/com/android/camera/ui/HeadUpDisplay.java b/src/com/android/camera/ui/HeadUpDisplay.java index 819fde7..3275d22 100644 --- a/src/com/android/camera/ui/HeadUpDisplay.java +++ b/src/com/android/camera/ui/HeadUpDisplay.java @@ -35,6 +35,8 @@ public class HeadUpDisplay extends GLView { private static final int POPUP_WINDOW_OVERLAP = 20; private static final int POPUP_TRIANGLE_OFFSET = 16; + private static final int COLOR_ICONBAR_HIGHLIGHT = 0x9A2B2B2B; + private static final float MAX_HEIGHT_RATIO = 0.8f; private static final float MAX_WIDTH_RATIO = 0.8f; @@ -322,8 +324,7 @@ public class HeadUpDisplay extends GLView { mIndicatorBar.setBackground(new NinePatchTexture( context, R.drawable.ic_viewfinder_iconbar)); - mIndicatorBar.setHighlight(new NinePatchTexture( - context, R.drawable.ic_viewfinder_iconbar_highlight)); + mIndicatorBar.setHighlight(new ColorTexture(COLOR_ICONBAR_HIGHLIGHT)); addComponent(mIndicatorBar); mIndicatorBar.setOnItemSelectedListener(new IndicatorBarListener()); } diff --git a/src/com/android/camera/ui/IndicatorBar.java b/src/com/android/camera/ui/IndicatorBar.java index 0b29c23..294e83a 100644 --- a/src/com/android/camera/ui/IndicatorBar.java +++ b/src/com/android/camera/ui/IndicatorBar.java @@ -12,7 +12,7 @@ class IndicatorBar extends GLView { public static final int INDEX_NONE = -1; private NinePatchTexture mBackground; - private NinePatchTexture mHighlight; + private FrameTexture mHighlight; private int mSelectedIndex = INDEX_NONE; private OnItemSelectedListener mSelectedListener; @@ -69,7 +69,7 @@ class IndicatorBar extends GLView { invalidate(); } - public void setHighlight(NinePatchTexture highlight) { + public void setHighlight(FrameTexture highlight) { if (mHighlight == highlight) return; mHighlight = highlight; invalidate(); diff --git a/src/com/android/camera/ui/OtherSettingsIndicator.java b/src/com/android/camera/ui/OtherSettingsIndicator.java index 807143f..178cb7f 100644 --- a/src/com/android/camera/ui/OtherSettingsIndicator.java +++ b/src/com/android/camera/ui/OtherSettingsIndicator.java @@ -8,6 +8,7 @@ import com.android.camera.R; import java.util.HashMap; class OtherSettingsIndicator extends AbstractIndicator { + private static final int COLOR_OPTION_ITEM_HIGHLIGHT = 0xFF181818; private final ListPreference mPreference[]; private final GLListView.Model mAdapters[]; @@ -81,8 +82,8 @@ class OtherSettingsIndicator extends AbstractIndicator { if (mPopupContent == null) { Context context = getGLRootView().getContext(); mPopupContent = new GLListView(context); - mPopupContent.setHighLight(new NinePatchTexture( - context, R.drawable.optionitem_highlight)); + mPopupContent.setHighLight( + new ColorTexture(COLOR_OPTION_ITEM_HIGHLIGHT)); mPopupContent.setScroller(new NinePatchTexture( context, R.drawable.scrollbar_handle_vertical)); UberAdapter adapter = buildUberAdapter(); diff --git a/src/com/android/camera/ui/ZoomIndicator.java b/src/com/android/camera/ui/ZoomIndicator.java index c115f25..4e63088 100644 --- a/src/com/android/camera/ui/ZoomIndicator.java +++ b/src/com/android/camera/ui/ZoomIndicator.java @@ -11,6 +11,7 @@ class ZoomIndicator extends AbstractIndicator { private static final DecimalFormat sZoomFormat = new DecimalFormat("#.#x"); private static final float FONT_SIZE = 18; private static final int FONT_COLOR = 0xA8FFFFFF; + private static final int COLOR_OPTION_HEADER = 0xFF2B2B2B; protected static final String TAG = "ZoomIndicator"; @@ -70,8 +71,7 @@ class ZoomIndicator extends AbstractIndicator { mPopupContent = new LinearLayout(); GLOptionHeader header = new GLOptionHeader(context, context.getString(R.string.zoom_control_title)); - header.setBackground(new NinePatchTexture( - context, R.drawable.optionheader_background)); + header.setBackground(new ColorTexture(COLOR_OPTION_HEADER)); header.setPaddings(6, 3, 6, 3); mPopupContent.addComponent(header); mPopupContent.addComponent(mZoomController); |