Skip to content

Commit

Permalink
Added ShapeProxy -> now supporting native implementations of onAreaTo…
Browse files Browse the repository at this point in the history
…uched().
  • Loading branch information
Nicolas Gramlich committed Mar 2, 2012
1 parent 6bfb205 commit 3b961ee
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 13 deletions.
1 change: 1 addition & 0 deletions jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ LOCAL_SRC_FILES := src/ScriptingEnvironment.cpp \
src/Wrapper.cpp \
src/EngineProxy.cpp \
src/EntityProxy.cpp \
src/ShapeProxy.cpp \
src/RectangleProxy.cpp \
src/Test.cpp

Expand Down
6 changes: 2 additions & 4 deletions jni/src/EntityProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ JNIEXPORT jboolean JNICALL Java_org_andengine_extension_scripting_entity_EntityP



EntityProxy::EntityProxy () {
EntityProxy::EntityProxy() {
/* Intentionally empty. */
}

Expand Down Expand Up @@ -47,9 +47,7 @@ void EntityProxy::setScale(float pScale) {
}

bool EntityProxy::onAttached() {
this->setScale(2);

return true;
return false;
}

bool EntityProxy::onDetached() {
Expand Down
6 changes: 6 additions & 0 deletions jni/src/RectangleProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ JNIEXPORT jboolean JNICALL Java_org_andengine_extension_scripting_entity_primiti
return rectangle->onDetached();
}

JNIEXPORT jboolean JNICALL Java_org_andengine_extension_scripting_entity_primitive_RectangleProxy_nativeOnAreaTouched(JNIEnv*, jobject pJObject, jlong pAddress, jobject pSceneTouchEvent, jfloat pTouchAreaLocalX, jfloat pTouchAreaLocalY) {
RectangleProxy* rectangle = (RectangleProxy*)pAddress;

return rectangle->onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
}


RectangleProxy::RectangleProxy() {
/* Intentionally empty. */
Expand Down
5 changes: 3 additions & 2 deletions jni/src/RectangleProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <jni.h>
#include "ScriptingEnvironment.h"
#include "EntityProxy.h"
#include "ShapeProxy.h"

extern "C" {
// ===========================================================
Expand All @@ -12,9 +12,10 @@ extern "C" {

JNIEXPORT jboolean JNICALL Java_org_andengine_extension_scripting_entity_primitive_RectangleProxy_nativeOnAttached(JNIEnv*, jobject, jlong);
JNIEXPORT jboolean JNICALL Java_org_andengine_extension_scripting_entity_primitive_RectangleProxy_nativeOnDetached(JNIEnv*, jobject, jlong);
JNIEXPORT jboolean JNICALL Java_org_andengine_extension_scripting_entity_primitive_RectangleProxy_nativeOnAreaTouched(JNIEnv*, jobject, jlong, jobject, jfloat, jfloat);
}

class RectangleProxy : public EntityProxy {
class RectangleProxy : public ShapeProxy {
protected:
/* Constructors */
RectangleProxy();
Expand Down
15 changes: 15 additions & 0 deletions jni/src/ShapeProxy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "ShapeProxy.h"

// ===========================================================
// org.andengine.extension.scripting.entity.EntityProxy
// ===========================================================

ShapeProxy::ShapeProxy() {
/* Intentionally empty. */
}

bool ShapeProxy::onAreaTouched(jobject pSceneTouchEvent, jfloat pTouchAreaLocalX, jfloat pTouchAreaLocalY) {
this->setScale(2);

return true;
}
18 changes: 18 additions & 0 deletions jni/src/ShapeProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef ShapeProxy_H
#define ShapeProxy_H

#include <jni.h>
#include "ScriptingEnvironment.h"
#include "EntityProxy.h"

class ShapeProxy : public EntityProxy {
protected:
/* Constructors */
ShapeProxy();

public:
/* Callbacks. */
bool onAreaTouched(jobject pSceneTouchEvent, jfloat pTouchAreaLocalX, jfloat pTouchAreaLocalY);
};

#endif
Binary file modified libs/armeabi-v7a/libandenginescriptingextension.so
Binary file not shown.
Binary file modified libs/armeabi/libandenginescriptingextension.so
Binary file not shown.
Binary file modified libs/x86/libandenginescriptingextension.so
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.andengine.extension.scripting.entity.primitive;

import org.andengine.entity.primitive.Rectangle;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.debug.Debug;

/**
* (c) Zynga 2012
Expand All @@ -28,12 +28,6 @@ public class RectangleProxy extends Rectangle {
public RectangleProxy(final long pAddress, final float pX, final float pY, final float pWidth, final float pHeight, final VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, pWidth, pHeight, pVertexBufferObjectManager);

Debug.d("WORKS!");
if(pVertexBufferObjectManager != null) {
Debug.d("NOT NULL!");
Debug.d("NATIVE CRASH: " + pVertexBufferObjectManager);
}

this.mAddress = pAddress;
}

Expand Down Expand Up @@ -63,6 +57,18 @@ public void onDetached() {

private native boolean nativeOnDetached(final long pAddress);

@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
final boolean handledNative = this.nativeOnAreaTouched(this.mAddress, pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
if(handledNative) {
return true;
} else {
return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
}
}

private native boolean nativeOnAreaTouched(final long pAddress, final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY);

// ===========================================================
// Methods
// ===========================================================
Expand Down

0 comments on commit 3b961ee

Please sign in to comment.