issue #2087: Updating the constructor of XXXEvent.

This commit is contained in:
James Chen 2013-09-18 18:16:14 +08:00
parent 6f53dcb49f
commit e697b0fc0b
8 changed files with 167 additions and 165 deletions

View File

@ -28,8 +28,10 @@ NS_CC_BEGIN
const char* AccelerationEvent::EVENT_TYPE = "AccelerometerEvent";
AccelerationEvent::AccelerationEvent()
AccelerationEvent::AccelerationEvent(Acceleration acc)
: Event(EVENT_TYPE)
{}
, _acc(acc)
{
}
NS_CC_END

View File

@ -35,8 +35,10 @@ class AccelerationEvent : public Event
public:
static const char* EVENT_TYPE;
AccelerationEvent();
Acceleration acc;
AccelerationEvent(Acceleration acc);
private:
Acceleration _acc;
};
NS_CC_END

View File

@ -198,7 +198,13 @@ public:
static const char* EVENT_TYPE;
KeyboardEvent() : Event(EVENT_TYPE) {};
KeyboardEvent(KeyCode keyCode, bool isPressed)
: Event(EVENT_TYPE)
, _keyCode(keyCode)
, _isPressed(isPressed)
{};
private:
KeyCode _keyCode;
bool _isPressed;
};

View File

@ -400,17 +400,13 @@ static int32_t handle_key_input(AInputEvent *event)
{
case AKEYCODE_BACK:
{
cocos2d::KeyboardEvent event;
event._keyCode = cocos2d::KeyboardEvent::KeyCode::KEY_BACKSPACE;
event._isPressed = false;
cocos2d::KeyboardEvent event(cocos2d::KeyboardEvent::KeyCode::KEY_BACKSPACE, false);
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&event);
}
return 1;
case AKEYCODE_MENU:
{
cocos2d::KeyboardEvent event;
event._keyCode = cocos2d::KeyboardEvent::KeyCode::KEY_MENU;
event._isPressed = false;
cocos2d::KeyboardEvent event(cocos2d::KeyboardEvent::KeyCode::KEY_MENU, false);
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&event);
}
return 1;
@ -601,21 +597,24 @@ void android_main(struct android_app* state) {
// ACONFIGURATION_ORIENTATION_ANY
// ACONFIGURATION_ORIENTATION_PORT
// ACONFIGURATION_ORIENTATION_SQUARE
cocos2d::AccelerationEvent accEvent;
accEvent.acc.x = event.acceleration.x;
accEvent.acc.y = event.acceleration.y;
accEvent.acc.z = event.acceleration.z;
accEvent.acc.timestamp = 0;
cocos2d::Acceleration acc;
acc.x = event.acceleration.x;
acc.y = event.acceleration.y;
acc.z = event.acceleration.z;
acc.timestamp = 0;
cocos2d::AccelerationEvent accEvent(acc);
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&accEvent);
} else {
// ACONFIGURATION_ORIENTATION_LAND
// swap x and y parameters
cocos2d::Acceleration acc;
acc.x = -event.acceleration.y;
acc.y = event.acceleration.x;
acc.z = event.acceleration.z;
acc.timestamp = 0;
cocos2d::AccelerationEvent accEvent(acc);
cocos2d::AccelerationEvent accEvent;
accEvent.acc.x = -event.acceleration.y;
accEvent.acc.y = event.acceleration.x;
accEvent.acc.z = event.acceleration.z;
accEvent.acc.timestamp = 0;
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&accEvent);
}
}

View File

@ -95,8 +95,7 @@ static CCAccelerometerDispatcher* s_pAccelerometerDispatcher;
break;
}
cocos2d::AccelerationEvent event;
event.acc = *_acceleration;
cocos2d::AccelerationEvent event(*_acceleration);
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&event);
}

View File

@ -222,9 +222,7 @@ void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x,
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
{
KeyboardEvent event;
event._keyCode = g_keyCodeMap[key];
event._isPressed = (GLFW_PRESS == action);
KeyboardEvent event(g_keyCodeMap[key], GLFW_PRESS == action);
EventDispatcher::getInstance()->dispatchEvent(&event);
}

View File

@ -238,9 +238,7 @@ void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x,
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
{
KeyboardEvent event;
event._keyCode = g_keyCodeMap[key];
event._isPressed = (GLFW_PRESS == action);
KeyboardEvent event(g_keyCodeMap[key], GLFW_PRESS == action);
EventDispatcher::getInstance()->dispatchEvent(&event);
}

View File

@ -340,9 +340,7 @@ void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x,
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
{
KeyboardEvent event;
event._keyCode = g_keyCodeMap[key];
event._isPressed = (GLFW_PRESS == action);
KeyboardEvent event(g_keyCodeMap[key], GLFW_PRESS == action);
EventDispatcher::getInstance()->dispatchEvent(&event);
}