Browse Source

os/android cleaned

mikymod 13 years ago
parent
commit
355ad9e873

+ 0 - 70
src/os/android/AndroidInputManager.cpp

@@ -1,70 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "AndroidInputManager.h"
-#include "AndroidTouch.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-AndroidInputManager::AndroidInputManager() :
-	mIsTouchAvailable(false),
-	mAndroidApp(NULL)
-{
-}
-
-//-----------------------------------------------------------------------------
-AndroidInputManager::~AndroidInputManager()
-{
-	if (mMouse)
-	{
-		delete mMouse;
-	}
-
-	if (mKeyboard)
-	{
-		delete mKeyboard;
-	}
-
-	if (mTouch)
-	{
-		delete mTouch;
-	}
-}
-
-//-----------------------------------------------------------------------------
-void AndroidInputManager::Init(const EventSource& source)
-{
-	mAndroidApp = source.AndroidApp;
-
-	if (!mTouch)
-	{
-		mTouch = new AndroidTouch(this);
-	}
-}
-
-} // namespace crown
-

+ 0 - 88
src/os/android/AndroidInputManager.h

@@ -1,88 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "InputManager.h"
-
-namespace crown
-{
-
-class AndroidInputManager : public InputManager
-{
-
-	friend class AndroidTouch;
-
-public:
-
-	/** @copydoc InputManager::InputManager() */
-	AndroidInputManager();
-
-	/** @copydoc InputManager::~InputManager() */
-	virtual ~AndroidInputManager();
-
-	/** @copydoc InputManager::Init() */
-	virtual void Init(const EventSource& source);
-
-	/** @copydoc InputManager::IsMouseAvailable() */
-	virtual bool IsMouseAvailable()
-	{
-		return false;
-	}
-
-	/** @copydoc InputManager::IsKeyboardAvailable() */
-	virtual bool IsKeyboardAvailable()
-	{
-		return false;
-	}
-
-	/** @copydoc InputManager::IsTouchAvailable() */
-	virtual bool IsTouchAvailable()
-	{
-		return mIsTouchAvailable;
-	}
-
-	/**
-		Returns the android_app structure.
-	@return
-		The android_app structure
-	*/
-	inline struct android_app* GetAndroidApp()
-	{
-		return mAndroidApp;
-	}
-
-private:
-
-	void SetTouchAvailable(bool available) { mIsTouchAvailable = available; }
-
-	bool mIsTouchAvailable : 1;
-
-	// Android related
-	struct android_app* mAndroidApp;
-};
-
-} // namespace crown
-

+ 0 - 161
src/os/android/AndroidRenderWindow.cpp

@@ -1,161 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Log.h"
-#include "Types.h"
-#include "OS.h"
-#include <EGL/egl.h>
-//#include <android_native_app_glue.h>
-#include <jni.h>
-
-namespace crown
-{
-namespace os
-{
-
-EGLint w;
-EGLint h;
-EGLDisplay display;
-EGLSurface surface;
-EGLContext context;
-//android_app* application;
-
-bool create_render_window(uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool fullscreen)
-{
-//	display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-
-//	assert(display != EGL_NO_DISPLAY);
-
-//	const EGLint attribs[] =
-//	{
-//		EGL_BUFFER_SIZE, 24,
-//		EGL_DEPTH_SIZE, 24,
-//		EGL_SURFACE_TYPE, 
-//		EGL_WINDOW_BIT,
-//		EGL_RENDERABLE_TYPE, 
-//		EGL_OPENGL_ES_BIT,
-//		EGL_NONE
-//	};
-//	
-//	EGLint major;
-//	EGLint minor;
-
-//	assert(eglInitialize(display, &major, &minor));
-
-//	EGLConfig  config;
-//	EGLint     num_config;
-//	assert(eglChooseConfig(display, attribs, &config, 1, &num_config));
-
-//	EGLint format;
-//    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
-
-//	// Reconfigure ANativeWindow buffer
-//    ANativeWindow_setBuffersGeometry(application->window, 0, 0, format);
-
-//	surface = eglCreateWindowSurface(display, config, application->window, NULL);
-//	assert(surface != EGL_NO_SURFACE);
-
-
-//	EGLint ctxattr[] =
-//	{
-//		EGL_CONTEXT_CLIENT_VERSION, 
-//		1,
-//		EGL_NONE
-//	};
-
-//	context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctxattr);
-//	assert(context != EGL_NO_CONTEXT);
-
-//	assert(eglMakeCurrent(display, surface, surface, context) != EGL_NO_CONTEXT);
-
-//	eglQuerySurface(display, surface, EGL_WIDTH, &w);
-//    eglQuerySurface(display, surface, EGL_HEIGHT, &h);
-
-//	return true;
-}
-
-bool destroy_render_window()
-{
-//	if (display != EGL_NO_DISPLAY)
-//	{
-//		eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-
-//		if (context != EGL_NO_CONTEXT)
-//		{
-//            eglDestroyContext(display, context);
-//		}
-//		
-//		if (surface != EGL_NO_SURFACE)
-//		{
-//            eglDestroySurface(display, surface);
-//		}
-
-//		eglTerminate(display);
-//	}
-}
-
-void get_render_window_metrics(uint32_t& width, uint32_t& height)
-{
-//	width = w;
-//	height = h;
-}
-
-void swap_buffers()
-{
-//	eglSwapBuffers(display, surface);
-}
-
-void event_loop()
-{
-	// FIXME
-}
-
-
-
-
-/* 
-tmp JNI definitions, just for testing
-TODO: remove this methods
-*/
-//extern "C"
-//{
-//	JNIEXPORT bool JNICALL Java_crown_android_CrownLib_create(JNIEnv* env, jobject obj);
-//	JNIEXPORT bool JNICALL Java_crown_android_CrownLib_destroy(JNIEnv* env, jobject obj);
-//}
-
-//JNIEXPORT bool JNICALL Java_crown_android_CrownLib_create(JNIEnv* env, jobject obj, jint x, jint y, jint width, jint height, jboolean fullscreen)
-//{
-//	create_render_window(x, y, width, height, fullscreen);
-//}
-
-//JNIEXPORT bool JNICALL Java_crown_android_CrownLib_destroy(JNIEnv* env, jobject obj)
-//{
-//	destroy_render_window();
-//}
-
-
-} // namespace os
-} // namespace crown
-

+ 0 - 93
src/os/android/AndroidRenderWindow.h

@@ -1,93 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "RenderWindow.h"
-#include "Types.h"
-#include <EGL/egl.h>
-
-namespace crown
-{
-
-class AndroidRenderWindow : public RenderWindow
-{
-
-public:
-
-	//! See RenderWindow
-	AndroidRenderWindow();
-
-	//! See RenderWindow
-	~AndroidRenderWindow();
-
-	//! See RenderWindow
-	virtual bool Create(uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t depth, bool fullscreen);
-
-	//! See RenderWindow
-	virtual void Destroy();
-
-	//! See RenderWindow
-	virtual void SetVisible(bool visible);
-
-	//! See RenderWindow
-	virtual void Move(uint32_t x, uint32_t y);
-
-	//! See RenderWindow
-	virtual void Resize(uint32_t width, uint32_t height);
-
-	//! See RenderWindow
-	virtual void SetFullscreen(bool full);
-
-	virtual void Bind();
-
-	virtual void Unbind();
-
-	//! See RenderWindow
-	virtual void Update();
-
-	virtual void EventLoop();
-
-	inline EGLSurface GetEGLWindow() const
-	{
-		return mEGLWindow;
-	}
-
-private:
-
-	//! See RenderWindow
-	void _NotifyMetricsChange(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
-
-	//! Sets the window's title plus the additional title text in the window
-	virtual void _SetTitleAndAdditionalTextToWindow();
-
-    ANativeWindow* mANativeWindow;
-	EGLDisplay mEGLDisplay;
-	EGLContext mEGLContext;
-	EGLSurface mEGLWindow;
-};
-
-} // namespace crown
-

+ 0 - 155
src/os/android/AndroidTouch.cpp

@@ -1,155 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "AndroidTouch.h"
-#include <android/input.h>
-#include "Log.h"
-#include "AndroidInputManager.h"
-
-namespace crown
-{
-
-AndroidTouch::AndroidTouch(InputManager* creator) :
-	Touch(creator),
-	mAndroidApp(NULL)
-{
-	if (mCreator)
-	{
-		mAndroidApp = static_cast<AndroidInputManager*>(mCreator)->GetAndroidApp();
-		static_cast<AndroidInputManager*>(mCreator)->SetTouchAvailable(true);
-	}
-}
-
-AndroidTouch::~AndroidTouch()
-{
-	if (mCreator)
-	{
-		static_cast<AndroidInputManager*>(mCreator)->SetTouchAvailable(false);
-	}
-}
-
-void AndroidTouch::EventLoop()
-{
-	int32_t ident;
-	int32_t events;
-	struct android_poll_source* source;
-
-	struct android_app* app = mAndroidApp;
-
-	if ((ident=ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0)
-	{
-		if (source != NULL && source->id == LOOPER_ID_INPUT)
-		{
-			AInputEvent* event = NULL;
-
-			if (AInputQueue_getEvent(app->inputQueue, &event) >= 0)
-			{
-				if (AInputQueue_preDispatchEvent(app->inputQueue, event))
-				{
-					return;
-				}
-
-				int32_t32_t handled = 0;
-				handled = this->HandleTouchEvent(app, event);
-				AInputQueue_finishEvent(app->inputQueue, event, handled);
-			}
-			else
-			{
-				//LOGI("Failure reading next input event: %s\n", strerror(errno));
-			}
-			//LOGI("Uscito da LOOPER_ID_INPUT");
-		}
-	}
-}
-
-int32_t32_t AndroidTouch::HandleTouchEvent(struct android_app* app, AInputEvent* event)
-{
-	TouchEvent touchEvent;
-
-	if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
-	{
-		int32_t32_t motionAction = AMotionEvent_getAction(event);
-		int32_t32_t motionCode = motionAction & AMOTION_EVENT_ACTION_MASK;
-		int32_t32_t point32_terIndex =
-			(motionAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
-		int32_t32_t point32_terCount = AMotionEvent_getPoint32_terCount(event);
-
-		touchEvent.point32_ter_id	= AMotionEvent_getPoint32_terId(event, point32_terIndex);
-		touchEvent.x			= AMotionEvent_getX(event, point32_terIndex);
-		touchEvent.y			= AMotionEvent_getY(event, point32_terIndex);
-
-		switch (motionCode)
-		{
-			case AMOTION_EVENT_ACTION_DOWN:
-			case AMOTION_EVENT_ACTION_POINTER_DOWN:
-			{
-				if (mListener)
-				{
-					mListener->TouchDown(touchEvent);
-				}
-				break;
-			}
-			case AMOTION_EVENT_ACTION_UP:
-			case AMOTION_EVENT_ACTION_POINTER_UP:
-			{
-				if (mListener)
-				{
-					mListener->TouchUp(touchEvent);
-				}
-				break;
-			}
-			case AMOTION_EVENT_ACTION_CANCEL:
-			{
-				if (mListener)
-				{
-					mListener->TouchCancel(touchEvent);
-				}
-				break;
-			}
-			case AMOTION_EVENT_ACTION_MOVE:
-			{
-				for (int32_t32_t i = 0; i < point32_terCount; i++)
-				{
-					touchEvent.point32_ter_id	= AMotionEvent_getPoint32_terId(event, i);
-					touchEvent.x			= AMotionEvent_getX(event, i);
-					touchEvent.y			= AMotionEvent_getY(event, i);
-
-					if (mListener)
-					{
-						mListener->TouchMove(touchEvent);
-					}
-				}
-				break;
-			}
-		}
-
-		return 1;
-	}
-
-	return 0;
-}
-
-} // namespace crown
-

+ 0 - 57
src/os/android/AndroidTouch.h

@@ -1,57 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include <android_native_app_glue.h>
-#include "Touch.h"
-
-namespace crown
-{
-
-class AndroidTouch : public Touch
-{
-
-public:
-
-	/** @copydoc Touch::Touch() */
-	AndroidTouch(InputManager* creator);
-
-	/** @copydoc Touch::~Touch() */
-	~AndroidTouch();
-
-	/** @copydoc Touch::EventLoop() */
-	virtual void EventLoop();
-
-public:
-
-	int32_t32_t HandleTouchEvent(struct android_app* app, AInputEvent* event);
-
-	// Android related
-	struct android_app* mAndroidApp;
-};
-
-};
-