1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.camera.ui;
18
19import android.graphics.Rect;
20
21import javax.microedition.khronos.opengles.GL11;
22
23public class PopupWindowStencilImpl extends PopupWindow {
24
25    @Override
26    protected void renderBackground(GLRootView rootView, GL11 gl) {
27        int width = getWidth();
28        int height = getHeight();
29        int aWidth = mAnchor.getWidth();
30        int aHeight = mAnchor.getHeight();
31
32        Rect p = mPaddings;
33        int aXoffset = width - aWidth;
34        int aYoffset = Math.max(p.top, mAnchorPosition - aHeight / 2);
35        aYoffset = Math.min(aYoffset, height - p.bottom - aHeight);
36
37        if (mAnchor != null) {
38            gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
39            gl.glStencilFunc(GL11.GL_ALWAYS, 1, 1);
40            mAnchor.draw(rootView, aXoffset, aYoffset);
41            gl.glStencilFunc(GL11.GL_NOTEQUAL, 1, 1);
42            gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
43        }
44
45        if (mBackground != null) {
46            mBackground.setSize(width - aWidth + mAnchorOffset, height);
47            mBackground.draw(rootView, 0, 0);
48        }
49    }
50}
51