|
@@ -20,14 +20,11 @@
|
|
|
*
|
|
|
* 3. This notice may not be removed or altered from any
|
|
|
* source distribution.
|
|
|
+ *
|
|
|
+ * modifing by Serge 06.05.2020
|
|
|
*/
|
|
|
package zengl.android;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
import javax.microedition.khronos.egl.EGL10;
|
|
|
import javax.microedition.khronos.egl.EGLContext;
|
|
|
import javax.microedition.khronos.egl.EGLDisplay;
|
|
@@ -38,7 +35,6 @@ import javax.microedition.khronos.opengles.GL10;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
import android.opengl.GLSurfaceView;
|
|
|
-import android.os.Environment;
|
|
|
import android.text.InputType;
|
|
|
import android.view.*;
|
|
|
import android.view.inputmethod.BaseInputConnection;
|
|
@@ -49,167 +45,159 @@ import android.view.inputmethod.InputMethodManager;
|
|
|
public class ZenGL extends GLSurfaceView
|
|
|
{
|
|
|
private native void Main();
|
|
|
- private native void zglNativeInit(String AppDirectory, String HomeDirectory);
|
|
|
+ private native void zglNativeInit( String AppDirectory, String HomeDirectory );
|
|
|
private native void zglNativeDestroy();
|
|
|
private native void zglNativeSurfaceCreated();
|
|
|
- private native void zglNativeSurfaceChanged(int width, int height);
|
|
|
+ private native void zglNativeSurfaceChanged( int width, int height );
|
|
|
private native void zglNativeDrawFrame();
|
|
|
- private native void zglNativeActivate(boolean Activate);
|
|
|
-// private native boolean zglNativeCloseQuery();
|
|
|
- private native void zglNativeTouch(int ID, float X, float Y, float Pressure);
|
|
|
- private native void zglNativeInputText(String Text);
|
|
|
+ private native void zglNativeActivate( boolean Activate );
|
|
|
+ private native void zglNativeCloseQuery();
|
|
|
+ private native void zglNativeTouch( int ID, float X, float Y, int Pressure );
|
|
|
+ private native void zglNativeInputText( String Text );
|
|
|
private native void zglNativeBackspace();
|
|
|
-
|
|
|
- // add function
|
|
|
- private native byte[] bArrPasToJava();
|
|
|
- private native void bArrJavaToPas(byte[] arr);
|
|
|
|
|
|
+ // add function
|
|
|
+ private native byte[] byteArrPasToJava();
|
|
|
+ private native void byteArrJavaToPas(byte[] arr);
|
|
|
+
|
|
|
private zglCRenderer Renderer;
|
|
|
private String SourceDir;
|
|
|
private String DataDir;
|
|
|
- private String SaveDir; // äèððåêòîðèÿ äëÿ ñîõðàíåíèÿ
|
|
|
- byte[] fBuffer; // áóôôåð äëÿ ïåðåäà÷è äàííûõ
|
|
|
private InputMethodManager InputManager;
|
|
|
|
|
|
- public ZenGL(Context context, String appSourceDir) {
|
|
|
- super(context);
|
|
|
+ public ZenGL( Context context, String appName, String appSourceDir )
|
|
|
+ {
|
|
|
+ super( context );
|
|
|
|
|
|
- System.loadLibrary("zenjpeg");
|
|
|
- System.loadLibrary("openal");
|
|
|
- System.loadLibrary("ogg");
|
|
|
- System.loadLibrary("vorbis");
|
|
|
- System.loadLibrary("theoradec");
|
|
|
- System.loadLibrary("chipmunk");
|
|
|
- System.loadLibrary("GLU");
|
|
|
- System.loadLibrary("zenandroid");
|
|
|
+ System.loadLibrary( "zenjpeg" );
|
|
|
+ System.loadLibrary( "openal" );
|
|
|
+ System.loadLibrary( "ogg" );
|
|
|
+ System.loadLibrary( "vorbis" );
|
|
|
+ System.loadLibrary( "theoradec" );
|
|
|
+ System.loadLibrary( "chipmunk" );
|
|
|
+ System.loadLibrary( "GLU" );
|
|
|
+ System.loadLibrary( appName );
|
|
|
|
|
|
SourceDir = appSourceDir;
|
|
|
DataDir = context.getFilesDir().getAbsolutePath();
|
|
|
Renderer = new zglCRenderer();
|
|
|
- setRenderer(Renderer);
|
|
|
-
|
|
|
- InputManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
- setFocusableInTouchMode(true);
|
|
|
- ((Activity)context).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
|
|
-
|
|
|
- File fDir = null;
|
|
|
- // ýòî íå ðàáîòàåò, íàäî èñêàòü ñïîñîá ñîõðàíåíèÿ äàííûõ íà êàðòó ïàìÿòè, à ýòî ýìóëÿöèÿ
|
|
|
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) == true) {
|
|
|
- fDir = Environment.getExternalStorageDirectory();
|
|
|
- fDir = new File(fDir.getPath() + "/zgldat");
|
|
|
- fDir.mkdirs();
|
|
|
- }
|
|
|
- SaveDir = fDir.getPath(); // ñðàáîòàåò ýòî çäåñü? ïî èäåå äîëæíî
|
|
|
-
|
|
|
- zglNativeInit(SourceDir, DataDir);
|
|
|
- Main(); // çàïóñê èíèöèàëèçàöèè
|
|
|
- }
|
|
|
+ setRenderer( Renderer );
|
|
|
|
|
|
-// public Boolean onCloseQuery() { óäàëèë, åñòü ôóíêöèÿ âûõîäà
|
|
|
-// return zglNativeCloseQuery();
|
|
|
-// }
|
|
|
+ InputManager = (InputMethodManager)context.getSystemService( Context.INPUT_METHOD_SERVICE );
|
|
|
+ setFocusableInTouchMode( true );
|
|
|
+ ((Activity)context).getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN );
|
|
|
+
|
|
|
+ zglNativeInit( SourceDir, DataDir );
|
|
|
+ Main();
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public void onPause() {
|
|
|
- if (InputManager.isAcceptingText())
|
|
|
+ public void onPause()
|
|
|
+ {
|
|
|
+ if ( InputManager.isAcceptingText() )
|
|
|
HideKeyboard();
|
|
|
|
|
|
super.onPause();
|
|
|
- zglNativeActivate(false);
|
|
|
+ zglNativeActivate( false );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onResume() {
|
|
|
+ public void onResume()
|
|
|
+ {
|
|
|
super.onResume();
|
|
|
- zglNativeActivate(true);
|
|
|
+ zglNativeActivate( true );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean onTouchEvent(MotionEvent event) {
|
|
|
+ public boolean onTouchEvent( MotionEvent event )
|
|
|
+ {
|
|
|
int action = event.getAction();
|
|
|
int actionType = action & MotionEvent.ACTION_MASK;
|
|
|
|
|
|
- switch (actionType) {
|
|
|
- case MotionEvent.ACTION_DOWN: {
|
|
|
- int count = event.getPointerCount();
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- int pointerID = event.getPointerId(i);
|
|
|
- zglNativeTouch(pointerID, event.getX(i), event.getY(i), event.getPressure(i));
|
|
|
- }
|
|
|
+ switch ( actionType )
|
|
|
+ {
|
|
|
+ // �то �обытие �рабатывает один раз
|
|
|
+ case MotionEvent.ACTION_DOWN:
|
|
|
+ {
|
|
|
+ int pointerID = event.getPointerId(0);
|
|
|
+ zglNativeTouch( pointerID, event.getX( 0 ), event.getY( 0 ), 1 );
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
- case MotionEvent.ACTION_UP: {
|
|
|
- int count = event.getPointerCount();
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- int pointerID = event.getPointerId(i);
|
|
|
- zglNativeTouch(pointerID, event.getX(i), event.getY(i), 0);
|
|
|
- }
|
|
|
+ // и �то �обытие �рабатывает один раз
|
|
|
+ case MotionEvent.ACTION_POINTER_DOWN:
|
|
|
+ {
|
|
|
+ int pointerID = ( action & MotionEvent.ACTION_POINTER_INDEX_MASK ) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
|
|
+ int pointerIndex = event.getPointerId( pointerID );
|
|
|
+ if ( pointerID >= 0 && pointerID < event.getPointerCount() )
|
|
|
+ zglNativeTouch( pointerIndex, event.getX( pointerID ), event.getY( pointerID ), 3 );
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
- case MotionEvent.ACTION_MOVE: {
|
|
|
- int count = event.getPointerCount();
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- int pointerID = event.getPointerId(i);
|
|
|
- zglNativeTouch(pointerID, event.getX(i), event.getY(i), event.getPressure(i));
|
|
|
- }
|
|
|
+
|
|
|
+ case MotionEvent.ACTION_UP:
|
|
|
+ {
|
|
|
+ int pointerID = event.getPointerId(0);
|
|
|
+ zglNativeTouch( pointerID, event.getX( 0 ), event.getY( 0 ), 0 );
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
- case MotionEvent.ACTION_POINTER_DOWN: {
|
|
|
- int pointerID = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
|
|
- int pointerIndex = event.getPointerId(pointerID);
|
|
|
- if (pointerID >= 0 && pointerID < event.getPointerCount())
|
|
|
- zglNativeTouch(pointerIndex, event.getX(pointerID), event.getY(pointerID), event.getPressure(pointerID));
|
|
|
+
|
|
|
+ case MotionEvent.ACTION_POINTER_UP:
|
|
|
+ {
|
|
|
+ int pointerID = ( action & MotionEvent.ACTION_POINTER_INDEX_MASK ) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
|
|
+ int pointerIndex = event.getPointerId( pointerID );
|
|
|
+ if ( pointerID >= 0 && pointerID < event.getPointerCount() )
|
|
|
+ zglNativeTouch( pointerIndex, event.getX( pointerID ), event.getY( pointerID ), 2 );
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
- case MotionEvent.ACTION_POINTER_UP: {
|
|
|
- int pointerID = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
|
|
- int pointerIndex = event.getPointerId(pointerID);
|
|
|
- if (pointerID >= 0 && pointerID < event.getPointerCount())
|
|
|
- zglNativeTouch(pointerIndex, event.getX(pointerID), event.getY(pointerID), 0);
|
|
|
+
|
|
|
+ case MotionEvent.ACTION_MOVE:
|
|
|
+ {
|
|
|
+ int count = event.getPointerCount();
|
|
|
+ for ( int i = 0; i < count; i++ )
|
|
|
+ {
|
|
|
+ int pointerID = event.getPointerId( i );
|
|
|
+ zglNativeTouch( pointerID, event.getX( i ), event.getY( i ), 5 );
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public void Finish() {
|
|
|
+ public void Finish()
|
|
|
+ {
|
|
|
zglNativeDestroy();
|
|
|
((Activity)getContext()).finish();
|
|
|
- System.exit(0);
|
|
|
+ System.exit( 0 );
|
|
|
}
|
|
|
|
|
|
- // èíòåðåñíûé ôàêò, ýòî äëÿ EGL!!! Ïîýòîìó îí ðàáîòàåò îäèí ðàç, ïðè àêòèâàöèè
|
|
|
- public void SwapBuffers() {
|
|
|
+ public void SwapBuffers()
|
|
|
+ {
|
|
|
try {
|
|
|
EGL10 currEGL = (EGL10)EGLContext.getEGL();
|
|
|
|
|
|
EGLDisplay currDisplay = currEGL.eglGetCurrentDisplay();
|
|
|
- if (currDisplay == EGL10.EGL_NO_DISPLAY) return;
|
|
|
+ if ( currDisplay == EGL10.EGL_NO_DISPLAY ) return;
|
|
|
|
|
|
- EGLSurface currSurface = currEGL.eglGetCurrentSurface(EGL10.EGL_DRAW);
|
|
|
- if (currSurface == EGL10.EGL_NO_SURFACE) return;
|
|
|
+ EGLSurface currSurface = currEGL.eglGetCurrentSurface( EGL10.EGL_DRAW );
|
|
|
+ if ( currSurface == EGL10.EGL_NO_SURFACE ) return;
|
|
|
|
|
|
- currEGL.eglSwapBuffers(currDisplay, currSurface);
|
|
|
- } catch (Exception e) { }
|
|
|
+ currEGL.eglSwapBuffers( currDisplay, currSurface);
|
|
|
+ } catch ( Exception e ) { }
|
|
|
}
|
|
|
|
|
|
- // ýòè ïðîöåäóðû òîæå óáðàòü íàäî áóäåò, âñÿ êëàâèàòóðà áóäåò ðàáîòàòü âíóòðè
|
|
|
- public void ShowKeyboard() {
|
|
|
- InputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
|
|
|
+ public void ShowKeyboard()
|
|
|
+ {
|
|
|
+ InputManager.toggleSoftInput( InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS );
|
|
|
}
|
|
|
|
|
|
- public void HideKeyboard() {
|
|
|
- InputManager.hideSoftInputFromWindow(this.getWindowToken(), 0);
|
|
|
+ public void HideKeyboard()
|
|
|
+ {
|
|
|
+ InputManager.hideSoftInputFromWindow( this.getWindowToken(), 0 );
|
|
|
}
|
|
|
|
|
|
- // ðàáîòà ñ êëàâèàòóðîé
|
|
|
@Override
|
|
|
- public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
|
|
+ public InputConnection onCreateInputConnection( EditorInfo outAttrs )
|
|
|
+ {
|
|
|
outAttrs.actionLabel = "";
|
|
|
outAttrs.hintText = "";
|
|
|
outAttrs.initialCapsMode = 0;
|
|
@@ -218,104 +206,65 @@ public class ZenGL extends GLSurfaceView
|
|
|
outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
|
|
|
outAttrs.inputType = InputType.TYPE_NULL;
|
|
|
|
|
|
- return new zglInputConnection(this, false);
|
|
|
+ return new zglInputConnection( this, false );
|
|
|
}
|
|
|
|
|
|
- // ýòî âîîáùå ÷òî?
|
|
|
@Override
|
|
|
- public boolean onCheckIsTextEditor() {
|
|
|
+ public boolean onCheckIsTextEditor()
|
|
|
+ {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
- if (keyCode == KeyEvent.KEYCODE_ENTER)
|
|
|
+ public boolean onKeyDown( int keyCode, KeyEvent event )
|
|
|
+ {
|
|
|
+ if ( keyCode == KeyEvent.KEYCODE_ENTER )
|
|
|
HideKeyboard();
|
|
|
- else if (keyCode == KeyEvent.KEYCODE_DEL)
|
|
|
+ else if ( keyCode == KeyEvent.KEYCODE_DEL )
|
|
|
zglNativeBackspace();
|
|
|
- else if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9)
|
|
|
- zglNativeInputText(((Integer)(keyCode - 7)).toString());
|
|
|
+ else if ( keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9 )
|
|
|
+ zglNativeInputText( ((Integer)(keyCode - 7)).toString() );
|
|
|
|
|
|
- return super.onKeyDown(keyCode, event);
|
|
|
+ return super.onKeyDown( keyCode, event );
|
|
|
}
|
|
|
|
|
|
- // ïåðåðàáîòàòü
|
|
|
- public boolean onBackPressed() {
|
|
|
- //return zglNativeCloseQuery(); // èçíà÷àëüíî íå âåðíàÿ ôóíêöèÿ, íè ÷åãî íå óíè÷òîæàëîñü...
|
|
|
- zglNativeDestroy();
|
|
|
- return true; // êàêàÿ ôèãíÿ... êòî âîîáùå òàê äåëàåò? Êàê íàçûâàåòñÿ òàêîå ïðîãðàììèðîâàíèå?
|
|
|
+ public boolean onBackPressed()
|
|
|
+ {
|
|
|
+ zglNativeCloseQuery();
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- // à ýòî OpenGL!!!
|
|
|
- class zglCRenderer implements Renderer {
|
|
|
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
|
|
+ class zglCRenderer implements Renderer
|
|
|
+ {
|
|
|
+ public void onSurfaceCreated( GL10 gl, EGLConfig config )
|
|
|
+ {
|
|
|
zglNativeSurfaceCreated();
|
|
|
}
|
|
|
|
|
|
- public void onSurfaceChanged(GL10 gl, int width, int height) {
|
|
|
- zglNativeSurfaceChanged(width, height);
|
|
|
+ public void onSurfaceChanged( GL10 gl, int width, int height )
|
|
|
+ {
|
|
|
+ zglNativeSurfaceChanged( width, height );
|
|
|
}
|
|
|
|
|
|
- public void onDrawFrame(GL10 gl) {
|
|
|
+ public void onDrawFrame( GL10 gl )
|
|
|
+ {
|
|
|
zglNativeDrawFrame();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class zglInputConnection extends BaseInputConnection {
|
|
|
- public zglInputConnection(View targetView, boolean fullEditor) {
|
|
|
- super(targetView, fullEditor);
|
|
|
+ class zglInputConnection extends BaseInputConnection
|
|
|
+ {
|
|
|
+ public zglInputConnection( View targetView, boolean fullEditor )
|
|
|
+ {
|
|
|
+ super( targetView, fullEditor );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean commitText(CharSequence text, int newCursorPosition) {
|
|
|
- zglNativeInputText((String)text);
|
|
|
+ public boolean commitText( CharSequence text, int newCursorPosition )
|
|
|
+ {
|
|
|
+ zglNativeInputText( (String)text );
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // çàïèñü ôàéëà, äàííûå óæå äîëæíû áûòü â ìàññèâå áóôôåðà
|
|
|
- public boolean saveFile(String name) throws IOException {
|
|
|
- FileOutputStream fos = null; // çàïèñûâàåìûå äàííûå
|
|
|
- String path = SaveDir + "/" + name;
|
|
|
- try {
|
|
|
- fos = new FileOutputStream(path);
|
|
|
- fos.write(fBuffer);
|
|
|
- return true;
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
- } finally {
|
|
|
- if (fos != null) {
|
|
|
- try {
|
|
|
- fos.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // ÷òåíèå ôàéëà, çàïèñûâàåì äàííûå â ìàññèâ áóôôåðà
|
|
|
- public boolean loadFile(String name) {
|
|
|
- FileInputStream fis = null;
|
|
|
- String path = SaveDir + "/" + name;
|
|
|
- try {
|
|
|
- File file = new File(path);
|
|
|
- fBuffer = new byte[(int) file.length()];
|
|
|
- fis = new FileInputStream(file);
|
|
|
- fis.read(fBuffer);
|
|
|
- return true;
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
- } finally {
|
|
|
- if (fis != null) {
|
|
|
- try {
|
|
|
- fis.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+}
|