2019-04-11 14:40:54 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2019-03-31 01:37:06 +08:00
|
|
|
|
//
|
|
|
|
|
|
// 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 "keys.hpp"
|
|
|
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|
|
|
|
|
struct MouseEvent
|
|
|
|
|
|
{
|
2019-08-18 22:49:44 +08:00
|
|
|
|
Float32 x;
|
|
|
|
|
|
Float32 y;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
bool left_btn_down; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
bool right_btn_down; // <20>Ҽ<EFBFBD><D2BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
union
|
|
|
|
|
|
{
|
|
|
|
|
|
struct // Events::MouseDown | Events::MouseUp | Events::MouseClick
|
|
|
|
|
|
{
|
2019-08-18 22:49:44 +08:00
|
|
|
|
Int32 button;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct // Events::MouseWheel
|
|
|
|
|
|
{
|
2019-08-18 22:49:44 +08:00
|
|
|
|
Float32 wheel;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-08-18 22:49:44 +08:00
|
|
|
|
static bool Check(UInt32 type);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|
|
|
|
|
struct KeyboardEvent
|
|
|
|
|
|
{
|
2019-08-18 22:49:44 +08:00
|
|
|
|
Int32 count;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
union
|
|
|
|
|
|
{
|
|
|
|
|
|
struct // Events::KeyDown | Events::KeyUp
|
|
|
|
|
|
{
|
2019-08-18 22:49:44 +08:00
|
|
|
|
Int32 code; // enum KeyCode
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct // Events::Char
|
|
|
|
|
|
{
|
|
|
|
|
|
char c;
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-08-18 22:49:44 +08:00
|
|
|
|
static bool Check(UInt32 type);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|
|
|
|
|
struct WindowEvent
|
|
|
|
|
|
{
|
|
|
|
|
|
union
|
|
|
|
|
|
{
|
|
|
|
|
|
struct // Events::WindowMoved
|
|
|
|
|
|
{
|
2019-08-18 22:49:44 +08:00
|
|
|
|
Int32 x;
|
|
|
|
|
|
Int32 y;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct // Events::WindowResized
|
|
|
|
|
|
{
|
2019-08-18 22:49:44 +08:00
|
|
|
|
Int32 width;
|
|
|
|
|
|
Int32 height;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct // Events::WindowFocusChanged
|
|
|
|
|
|
{
|
|
|
|
|
|
bool focus;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct // Events::WindowTitleChanged
|
|
|
|
|
|
{
|
2019-08-18 22:49:44 +08:00
|
|
|
|
const WChar* title;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-08-18 22:49:44 +08:00
|
|
|
|
static bool Check(UInt32 type);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>¼<EFBFBD>
|
|
|
|
|
|
struct CustomEvent
|
|
|
|
|
|
{
|
|
|
|
|
|
void* data;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-08-12 18:30:42 +08:00
|
|
|
|
class Actor;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
// <20>¼<EFBFBD>
|
2019-04-11 14:40:54 +08:00
|
|
|
|
struct KGE_API Event
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-08-18 22:49:44 +08:00
|
|
|
|
enum Type : UInt32
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
First,
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|
|
|
|
|
MouseFirst,
|
|
|
|
|
|
MouseMove, // <20>ƶ<EFBFBD>
|
|
|
|
|
|
MouseBtnDown, // <20><><EFBFBD>갴<EFBFBD><EAB0B4>
|
|
|
|
|
|
MouseBtnUp, // <20><><EFBFBD><EFBFBD>̧<EFBFBD><CCA7>
|
|
|
|
|
|
MouseWheel, // <20><><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>
|
|
|
|
|
|
MouseHover, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
MouseOut, // <20><><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
|
|
|
|
|
|
Click, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
MouseLast,
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|
|
|
|
|
KeyFirst,
|
|
|
|
|
|
KeyDown, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
KeyUp, // <20><><EFBFBD><EFBFBD>̧<EFBFBD><CCA7>
|
|
|
|
|
|
Char, // <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
|
|
|
|
|
KeyLast,
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
WindowFirst,
|
|
|
|
|
|
WindowMoved, // <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
|
|
|
|
|
WindowResized, // <20><><EFBFBD>ڴ<EFBFBD>С<EFBFBD>仯
|
|
|
|
|
|
WindowFocusChanged, // <20><><EFBFBD>û<EFBFBD>ʧȥ<CAA7><C8A5><EFBFBD><EFBFBD>
|
|
|
|
|
|
WindowTitleChanged, // <20><><EFBFBD><EFBFBD><EFBFBD>仯
|
|
|
|
|
|
WindowClosed, // <20><><EFBFBD>ڱ<EFBFBD><DAB1>ر<EFBFBD>
|
|
|
|
|
|
WindowLast,
|
|
|
|
|
|
|
|
|
|
|
|
Last
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-08-18 22:49:44 +08:00
|
|
|
|
UInt32 type;
|
2019-08-12 18:30:42 +08:00
|
|
|
|
Actor* target;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
union
|
|
|
|
|
|
{
|
|
|
|
|
|
MouseEvent mouse;
|
|
|
|
|
|
KeyboardEvent key;
|
|
|
|
|
|
WindowEvent win;
|
|
|
|
|
|
CustomEvent custom;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-08-18 22:49:44 +08:00
|
|
|
|
Event(UInt32 type = Type::First) : type(type), target(nullptr) {}
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check-functions
|
|
|
|
|
|
|
2019-08-18 22:49:44 +08:00
|
|
|
|
inline bool MouseEvent::Check(UInt32 type)
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
return type > Event::MouseFirst && type < Event::MouseLast;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-18 22:49:44 +08:00
|
|
|
|
inline bool KeyboardEvent::Check(UInt32 type)
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
return type > Event::KeyFirst && type < Event::KeyLast;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-18 22:49:44 +08:00
|
|
|
|
inline bool WindowEvent::Check(UInt32 type)
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
return type > Event::WindowFirst && type < Event::WindowLast;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|