mirror of https://github.com/axmolengine/axmol.git
315 lines
8.2 KiB
C++
315 lines
8.2 KiB
C++
/****************************************************************************
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
https://axmolengine.github.io/
|
|
|
|
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.
|
|
****************************************************************************/
|
|
|
|
//
|
|
// NewEventDispatcherTest.h
|
|
// samples
|
|
//
|
|
// Created by James Chen on 9/13/13.
|
|
//
|
|
//
|
|
|
|
#ifndef __samples__NewEventDispatcherTest__
|
|
#define __samples__NewEventDispatcherTest__
|
|
|
|
#include "axmol.h"
|
|
#include "../BaseTest.h"
|
|
|
|
DEFINE_TEST_SUITE(EventDispatcherTests);
|
|
|
|
class EventDispatcherTestDemo : public TestCase
|
|
{
|
|
public:
|
|
virtual std::string title() const override;
|
|
};
|
|
|
|
class TouchableSpriteTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(TouchableSpriteTest);
|
|
virtual void onEnter() override;
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
};
|
|
|
|
class FixedPriorityTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(FixedPriorityTest);
|
|
virtual void onEnter() override;
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
};
|
|
|
|
class RemoveListenerWhenDispatching : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(RemoveListenerWhenDispatching);
|
|
virtual void onEnter() override;
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
};
|
|
|
|
class CustomEventTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(CustomEventTest);
|
|
virtual void onEnter() override;
|
|
virtual void onExit() override;
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
private:
|
|
axis::EventListenerCustom* _listener;
|
|
axis::EventListenerCustom* _listener2;
|
|
};
|
|
|
|
class LabelKeyboardEventTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(LabelKeyboardEventTest);
|
|
virtual void onEnter() override;
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
};
|
|
|
|
class SpriteAccelerationEventTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(SpriteAccelerationEventTest);
|
|
virtual void onEnter() override;
|
|
virtual void onExit() override;
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
};
|
|
|
|
class RemoveAndRetainNodeTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(RemoveAndRetainNodeTest);
|
|
virtual void onEnter() override;
|
|
virtual void onExit() override;
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
private:
|
|
axis::Sprite* _sprite;
|
|
bool _spriteSaved;
|
|
};
|
|
|
|
class RemoveListenerAfterAddingTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(RemoveListenerAfterAddingTest);
|
|
virtual void onEnter() override;
|
|
virtual void onExit() override;
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
};
|
|
|
|
class DirectorEventTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(DirectorEventTest);
|
|
DirectorEventTest();
|
|
virtual void onEnter() override;
|
|
virtual void onExit() override;
|
|
|
|
virtual void update(float dt) override;
|
|
|
|
void onEvent1(axis::EventCustom* event);
|
|
void onEvent2(axis::EventCustom* event);
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
protected:
|
|
int _count1, _count2, _count3, _count4;
|
|
axis::Label *_label1, *_label2, *_label3, *_label4;
|
|
axis::EventListenerCustom *_event1, *_event2, *_event3, *_event4;
|
|
};
|
|
|
|
class GlobalZTouchTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(GlobalZTouchTest);
|
|
GlobalZTouchTest();
|
|
|
|
virtual void update(float dt) override;
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
protected:
|
|
axis::Sprite* _sprite;
|
|
float _accum;
|
|
};
|
|
|
|
class StopPropagationTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(StopPropagationTest);
|
|
StopPropagationTest();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
protected:
|
|
bool isPointInNode(axis::Vec2 pt, axis::Node* node);
|
|
bool isPointInTopHalfAreaOfScreen(axis::Vec2 pt);
|
|
};
|
|
|
|
class PauseResumeTargetTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(PauseResumeTargetTest);
|
|
PauseResumeTargetTest();
|
|
virtual ~PauseResumeTargetTest();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
private:
|
|
};
|
|
|
|
class PauseResumeTargetTest2 : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(PauseResumeTargetTest2);
|
|
PauseResumeTargetTest2();
|
|
virtual ~PauseResumeTargetTest2();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
private:
|
|
axis::Sprite* _touchableSprite;
|
|
axis::MenuItemFont* _itemPauseTouch;
|
|
axis::MenuItemFont* _itemResumeTouch;
|
|
axis::MenuItemFont* _itemAddToScene;
|
|
axis::MenuItemFont* _itemRemoveFromScene;
|
|
};
|
|
|
|
class PauseResumeTargetTest3 : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(PauseResumeTargetTest3);
|
|
PauseResumeTargetTest3();
|
|
virtual ~PauseResumeTargetTest3();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
private:
|
|
axis::Sprite* _touchableSprite;
|
|
};
|
|
|
|
class Issue4129 : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(Issue4129);
|
|
Issue4129();
|
|
virtual ~Issue4129();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
private:
|
|
axis::EventListenerCustom* _customlistener;
|
|
bool _bugFixed;
|
|
};
|
|
|
|
class Issue4160 : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(Issue4160);
|
|
Issue4160();
|
|
virtual ~Issue4160();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
private:
|
|
};
|
|
|
|
class DanglingNodePointersTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(DanglingNodePointersTest);
|
|
DanglingNodePointersTest();
|
|
virtual ~DanglingNodePointersTest();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
};
|
|
|
|
class RegisterAndUnregisterWhileEventHanldingTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(RegisterAndUnregisterWhileEventHanldingTest);
|
|
RegisterAndUnregisterWhileEventHanldingTest();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
};
|
|
|
|
class WindowEventsTest : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(WindowEventsTest);
|
|
WindowEventsTest();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
};
|
|
|
|
class Issue8194 : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(Issue8194);
|
|
Issue8194();
|
|
virtual ~Issue8194();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
private:
|
|
axis::EventListenerCustom* _listener;
|
|
};
|
|
|
|
class Issue9898 : public EventDispatcherTestDemo
|
|
{
|
|
public:
|
|
CREATE_FUNC(Issue9898);
|
|
Issue9898();
|
|
|
|
virtual std::string title() const override;
|
|
virtual std::string subtitle() const override;
|
|
|
|
private:
|
|
axis::EventListenerCustom* _listener;
|
|
};
|
|
|
|
#endif /* defined(__samples__NewEventDispatcherTest__) */
|