If you think the Android project clash_of_balls listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2012-2013 Hans Hardmeier <hanshardmeier@gmail.com>
* Copyright (C) 2012-2013 Andrin Jenal//fromwww.java2s.com
* Copyright (C) 2012-2013 Beat Kng <beat-kueng@gmx.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/package com.sapos_aplastados.game.clash_of_balls.menu;
import com.sapos_aplastados.game.clash_of_balls.R;
import com.sapos_aplastados.game.clash_of_balls.Texture;
import com.sapos_aplastados.game.clash_of_balls.TextureManager;
import com.sapos_aplastados.game.clash_of_balls.VertexBufferFloat;
import com.sapos_aplastados.game.clash_of_balls.game.RenderHelper;
import com.sapos_aplastados.game.clash_of_balls.game.Vector;
import android.content.Context;
import android.opengl.GLES20;
/**
* base class for a popup menu as an overlay over a menu/game
*
* when a popup is shown over a menu, the movement of the menu is not stopped
* but all input events only go to the popup
*
* a fixed aspect ratio is used
*
*/publicclass PopupBase extends GameMenuBase {
publicstaticfinalfloat width_scaling = 0.8f; //output width = scaling * screen width
publicstaticfinalfloat aspect_ratio = 1.66666f; //output height = output width / aspect
protectedfloat m_color[] = newfloat[4];
protected VertexBufferFloat m_position_data;
private Texture m_background_texture;
protected Vector m_position;
protected Vector m_size;
public PopupBase(Context context, TextureManager tex_manager
, float screen_width, float screen_height) {
super(null, context);
m_position_data = new VertexBufferFloat
(VertexBufferFloat.sprite_position_data, 3);
RenderHelper.initColorArray(0xffffffff, m_color);
m_background_texture = tex_manager.get(R.raw.texture_popup_bg);
float width = screen_width * width_scaling;
float height = width/aspect_ratio;
if(height > screen_height) {
height = screen_height;
width = height * aspect_ratio;
}
m_size = new Vector(width , height);
m_position = new Vector((screen_width-m_size.x)/2.f, (screen_height-m_size.y)/2.f);
}
publicvoid draw(RenderHelper renderer) {
renderer.pushModelMat();
renderer.modelMatTranslate(m_position.x, m_position.y, 0.f);
renderer.modelMatScale(m_size.x, m_size.y, 0.f);
drawTexture(renderer, m_background_texture);
renderer.popModelMat();
super.draw(renderer);
}
protectedvoid drawTexture(RenderHelper renderer, Texture texture) {
renderer.shaderManager().activateTexture(0);
texture.useTexture(renderer);
// position
int position_handle = renderer.shaderManager().a_Position_handle;
if(position_handle != -1)
m_position_data.apply(position_handle);
// color
int color_handle = renderer.shaderManager().u_Color_handle;
if(color_handle != -1)
GLES20.glUniform4fv(color_handle, 1, m_color, 0);
renderer.apply();
// Draw
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
protectedvoid onTouchDown(MenuItem item) {
}
protectedvoid onTouchUp(MenuItem item) {
}
publicvoid onBackButtonPressed() {
//we do nothing here. this event is handled inside the menus
//and not in the popup's
}
}