From 550341ad8bf16a2dcf90d257a8a37fe8f7feb0f0 Mon Sep 17 00:00:00 2001 From: pelya Date: Wed, 1 Jun 2011 13:13:29 +0300 Subject: [PATCH] Draw the logo when app loads, until the first SDL_Flip(), also fixed small bug in menu --- project/java/GLSurfaceView_SDL.java | 14 ++---- project/java/Settings.java | 8 +-- project/java/Video.java | 77 ++++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 15 deletions(-) diff --git a/project/java/GLSurfaceView_SDL.java b/project/java/GLSurfaceView_SDL.java index ade15f6f0..55fb1b04f 100644 --- a/project/java/GLSurfaceView_SDL.java +++ b/project/java/GLSurfaceView_SDL.java @@ -595,6 +595,8 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call public void setSwapBuffersCallback( SwapBuffersCallback c ) { mSwapBuffersCallback = c; } + + public abstract void DrawLogo(GL10 gl); private SwapBuffersCallback mSwapBuffersCallback = null; } @@ -904,7 +906,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call mNeedStart = true; mSizeChanged = true; SwapBuffers(); - DrawLogo(); + mRenderer.DrawLogo(mGL); SwapBuffers(); mRenderer.onDrawFrame(mGL); @@ -1113,16 +1115,6 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call return null; } - private void DrawLogo() { - // TODO: draw some logo instead of making screen non-black - /* - mGL.glClearColor(0.0f, 0.5f, 0.7f, 1.0f); - mGL.glClear(mGL.GL_COLOR_BUFFER_BIT | mGL.GL_DEPTH_BUFFER_BIT); - mGL.glFlush(); - mGL.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - */ - } - private boolean mDone; private boolean mPaused; private boolean mHasSurface; diff --git a/project/java/Settings.java b/project/java/Settings.java index f44e03db5..30672f6ee 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -1072,7 +1072,6 @@ class Settings { public void onClick(DialogInterface dialog, int item) { - Globals.LeftClickMethod = item; dialog.dismiss(); if( item == 0 ) { @@ -1107,7 +1106,9 @@ class Settings if( firstStart ) builder.setItems(items, new ClickListener()); else - builder.setSingleChoiceItems(items, (Globals.LeftClickMethod == Mouse.LEFT_CLICK_WITH_TAP_OR_TIMEOUT && ! Globals.RelativeMouseMovement) ? 0 : 1, new ClickListener()); + builder.setSingleChoiceItems(items, + (Globals.LeftClickMethod == Mouse.LEFT_CLICK_WITH_TAP_OR_TIMEOUT && ! Globals.RelativeMouseMovement) ? 0 : 1, + new ClickListener()); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) @@ -1142,9 +1143,10 @@ class Settings builder.setTitle(R.string.leftclick_question); builder.setSingleChoiceItems(items, Globals.LeftClickMethod, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int item) + public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); + Globals.LeftClickMethod = item; if( item == Mouse.LEFT_CLICK_WITH_KEY ) p.keyListener = new KeyRemapToolMouseClick(p, true); else if( item == Mouse.LEFT_CLICK_WITH_TIMEOUT || item == Mouse.LEFT_CLICK_WITH_TAP_OR_TIMEOUT ) diff --git a/project/java/Video.java b/project/java/Video.java index d4d68ebb2..2ef024ced 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -12,6 +12,8 @@ package net.sourceforge.clonekeenplus; import javax.microedition.khronos.opengles.GL10; +import javax.microedition.khronos.opengles.GL11; +import javax.microedition.khronos.opengles.GL11Ext; import javax.microedition.khronos.egl.EGL10; import javax.microedition.khronos.egl.EGL11; @@ -29,6 +31,10 @@ import android.view.Window; import android.view.WindowManager; import android.os.Environment; import java.io.File; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.content.res.Resources; +import android.content.res.AssetManager; import android.widget.TextView; import java.lang.Thread; @@ -37,6 +43,9 @@ import android.os.Build; import java.lang.reflect.Method; import java.util.LinkedList; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + class Mouse { @@ -236,6 +245,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer } public void onSurfaceChanged(GL10 gl, int w, int h) { + mWidth = w; + mHeight = h; nativeResize(w, h, Globals.KeepAspectRatio ? 1 : 0); } @@ -319,10 +330,72 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer context.runOnUiThread(cb); } - public void exitApp() { + public void exitApp() + { nativeDone(); }; + private int PowerOf2(int i) + { + int value = 1; + while (value < i) + value <<= 1; + return value; + } + public void DrawLogo(GL10 gl) + { + BitmapDrawable bmp = null; + try + { + bmp = new BitmapDrawable(context.getAssets().open("logo.png")); + } + catch(Exception e) + { + bmp = new BitmapDrawable(context.getResources().openRawResource(R.drawable.publisherlogo)); + } + int width = bmp.getBitmap().getWidth(); + int height = bmp.getBitmap().getHeight(); + ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * width * height); + byteBuffer.order(ByteOrder.BIG_ENDIAN); + bmp.getBitmap().copyPixelsToBuffer(byteBuffer); + byteBuffer.position(0); + + gl.glViewport(0, 0, mWidth, mHeight); + gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); + gl.glColor4x(0x10000, 0x10000, 0x10000, 0x10000); + gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1); + gl.glEnable(GL10.GL_TEXTURE_2D); + int textureName = -1; + int mTextureNameWorkspace[] = new int[1]; + int mCropWorkspace[] = new int[4]; + gl.glGenTextures(1, mTextureNameWorkspace, 0); + textureName = mTextureNameWorkspace[0]; + gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName); + gl.glActiveTexture(textureName); + gl.glClientActiveTexture(textureName); + gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, + PowerOf2(width), PowerOf2(height), 0, + GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, null); + gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, + width, height, + GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, byteBuffer); + mCropWorkspace[0] = 0; // u + mCropWorkspace[1] = height; // v + mCropWorkspace[2] = width; + mCropWorkspace[3] = -height; + ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, + GL11Ext.GL_TEXTURE_CROP_RECT_OES, mCropWorkspace, 0); + ((GL11Ext) gl).glDrawTexiOES(0, -mHeight, 0, mWidth, mHeight); + gl.glActiveTexture(0); + gl.glClientActiveTexture(0); + gl.glBindTexture(GL10.GL_TEXTURE_2D, 0); + gl.glDeleteTextures(1, mTextureNameWorkspace, 0); + + gl.glFlush(); + } + + private native void nativeInitJavaCallbacks(); private native void nativeInit(String CurrentPath, String CommandLine, int multiThreadedVideo); private native void nativeResize(int w, int h, int keepAspectRatio); @@ -343,6 +416,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer public boolean mGlSurfaceCreated = false; public boolean mPaused = false; private boolean mFirstTimeStart = true; + public int mWidth = 0; + public int mHeight = 0; } class DemoGLSurfaceView extends GLSurfaceView_SDL {