Browse Source

don't send mouse event on multitouch devices
fixed marmalade build error

Denis Muratshin 12 years ago
parent
commit
59ee64ee7e

+ 2 - 2
.hg_archival.txt

@@ -1,5 +1,5 @@
 repo: b6d71054df5712e643a0685bc3ba54b123db5729
-node: 5e5366dbfaa6e45c43d1550345b46a8088d7916a
+node: 82d55e1469f1b711668130bab1723c7378551c07
 branch: default
 latesttag: oldrender
-latesttagdistance: 175
+latesttagdistance: 180

BIN
doc.zip


+ 7 - 0
oxygine/src/Input.cpp

@@ -3,6 +3,9 @@
 #include "core/log.h"
 #include <string.h>
 
+//#define LOGD(...) oxygine::log::message("input: "); oxygine::log::messageln(__VA_ARGS__)
+#define LOGD(...) ((void)0)
+
 namespace oxygine
 {
 	Input Input::instance;
@@ -29,6 +32,8 @@ namespace oxygine
 
 		ps->_position = p;
 
+		LOGD("sendPointerButtonEvent %d - (%.2f, %.2f), %d", me.index, p.x, p.y, type);
+
 		getRoot()->handleEvent(&me);
 	}
 
@@ -39,6 +44,7 @@ namespace oxygine
 		me.pressure = pressure;
 		ps->_position = Vector2(x, y);
 
+		LOGD("sendPointerMotionEvent %d - (%.2f, %.2f)", me.index, x, y);
 		getRoot()->handleEvent(&me);
 	}
 
@@ -55,6 +61,7 @@ namespace oxygine
 
 	Input::Input()
 	{
+		addRef();
 		_pointerMouse.init(MAX_TOUCHES + 1);
 		for (int i = 0; i < MAX_TOUCHES; ++i)
 			_pointers[i].init(i + 1);

+ 7 - 1
oxygine/src/Input.h

@@ -1,5 +1,6 @@
 #pragma once
 #include "oxygine_include.h"
+#include "EventDispatcher.h"
 #include "math/vector3.h"
 #include "math/vector2.h"
 #include "closure/closure.h"
@@ -14,7 +15,7 @@ namespace oxygine
 	
 	const int MAX_TOUCHES = 8;
 
-	class Input
+	class Input: public EventDispatcher
 	{
 	public:
 		static Input instance;
@@ -22,6 +23,11 @@ namespace oxygine
 		Input();
 		~Input();
 
+		enum
+		{
+			event_platform = makefourcc('_', 's', 'd', 'l')
+		};
+
 		void cleanup();
 
 		/**id should be in range [1, MAX_TOUCHES]*/

+ 11 - 6
oxygine/src/InputText.cpp

@@ -1,6 +1,7 @@
 #include "InputText.h"
 #include "TextActor.h"
 #include "utils/stringUtils.h"
+#include "Input.h"
 
 #ifndef __S3E__
 #include "SDL_keyboard.h"
@@ -37,8 +38,10 @@ namespace oxygine
 		_active = this;
 
 		_textActor = ta;		
+
+		Input::instance.addEventListener(Input::event_platform, CLOSURE(this, &InputText::_onPlatform));
+
 #ifndef __S3E__
-		SDL_AddEventWatch(onSDLEvent, this);
 		SDL_StartTextInput();
 #endif
 		//log::messageln("InputText::start  %x", this);
@@ -70,20 +73,21 @@ namespace oxygine
 	{
 #ifndef __S3E__
 		SDL_StopTextInput();
-		SDL_DelEventWatch(onSDLEvent, this);		
 #endif
+		Input::instance.removeEventListeners(this);
+
 		_active = 0;
 		_textActor = 0;
 		//log::messageln("InputText::stop  %x", this);
 		releaseRef();
 	}
 
-#ifndef __S3E__
-	int SDLCALL InputText::onSDLEvent(void *userdata, SDL_Event * event)
+	void InputText::_onPlatform(Event *event)
 	{
-		return ((InputText*)userdata)->_onSDLEvent(event);
-	}
+#ifndef __S3E__
+		_onSDLEvent((SDL_Event*)event->userData);
 #endif
+	}
 
 	void InputText::updateText()
 	{
@@ -143,6 +147,7 @@ namespace oxygine
 			break;
 		case SDL_KEYDOWN:
 			{
+				log::messageln("SDL_KEYDOWN");
 				switch (event->key.keysym.sym)
 				{
 				case SDLK_BACKSPACE:

+ 2 - 2
oxygine/src/InputText.h

@@ -37,8 +37,8 @@ namespace oxygine
 		void updateText();
 		static InputText *_active;		
 
-#ifndef __S3E__		
-		static int SDLCALL onSDLEvent(void *userdata, SDL_Event * event);
+		void _onPlatform(Event *event);
+#ifndef __S3E__
 		int _onSDLEvent(SDL_Event *event);
 #endif
 	};

+ 17 - 8
oxygine/src/core/ThreadMessages.cpp

@@ -31,19 +31,28 @@ namespace oxygine
 			pthread_cond_wait(&_cond, &_mutex);			
 	}
 
-	void mywait(pthread_cond_t *cond, pthread_mutex_t *mutex)
+	void addtime(timespec& ts, int ms)
 	{
-#ifdef __S3E__
-		timespec ts;
-		clock_gettime(CLOCK_REALTIME, &ts);
-		//ts.tv_sec += 1;
-		ts.tv_nsec += 300 * 1000000;
-		if (ts.tv_nsec >= 1000000000)
+		ts.tv_nsec += ms * 1000000;
+		while(ts.tv_nsec >= 1000000000)
 		{
 			ts.tv_nsec -= 1000000000;
 			++ts.tv_sec;
 		}
-		
+	}
+
+
+	void mywait(pthread_cond_t *cond, pthread_mutex_t *mutex)
+	{
+#ifdef __S3E__
+		timespec ts;
+		clock_gettime(CLOCK_REALTIME, &ts);
+		addtime(ts, 300);		
+		pthread_cond_timedwait(cond, mutex, &ts);
+#elif __ANDROID__
+		timespec ts;
+		clock_gettime(CLOCK_REALTIME, &ts);
+		addtime(ts, 500);		
 		pthread_cond_timedwait(cond, mutex, &ts);
 #else
 		pthread_cond_wait(cond, mutex);		

+ 7 - 2
oxygine/src/core/oxygine.cpp

@@ -566,6 +566,10 @@ namespace oxygine
 			SDL_Event event;
 			while (SDL_PollEvent(&event)) 
 			{
+				Event ev(Input::event_platform);
+				ev.userData = &event;
+				Input::instance.dispatchEvent(&ev);
+
 				switch(event.type)
 				{
 				case SDL_QUIT:
@@ -617,13 +621,13 @@ namespace oxygine
 				case SDL_MOUSEWHEEL:
 					input->sendPointerWheelEvent(event.wheel.y, &input->_pointerMouse);
 					break;
+#if SDL_VIDEO_OPENGL
 				case SDL_MOUSEMOTION:
 					input->sendPointerMotionEvent((float)event.motion.x, (float)event.motion.y, 1.0f, &input->_pointerMouse);
 					break;
 				case SDL_MOUSEBUTTONDOWN:
 				case SDL_MOUSEBUTTONUP:
 					{
-#ifndef ANDROID
 						MouseButton b = MouseButton_Left;
 						switch(event.button.button)
 						{
@@ -634,9 +638,9 @@ namespace oxygine
 
 						input->sendPointerButtonEvent(b, (float)event.button.x, (float)event.button.y, 1.0f, 
 							event.type == SDL_MOUSEBUTTONDOWN ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP, &input->_pointerMouse);
-#endif
 					}					
 					break;
+#else
 
 				case SDL_FINGERMOTION:
 					{
@@ -660,6 +664,7 @@ namespace oxygine
 							input->getTouchByID((int)event.tfinger.fingerId));
 					}				
 					break;
+#endif
 					/*
 				case SDL_TEXTEDITING:
 					{