Magic_Game/src/core/Event.hpp

163 lines
3.0 KiB
C++
Raw Normal View History

2018-10-03 22:02:46 +08:00
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// 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 "macros.h"
2019-01-24 12:21:01 +08:00
#include "keys.hpp"
2018-11-08 00:21:59 +08:00
namespace easy2d
{
2018-11-22 19:31:44 +08:00
typedef UINT EventType;
2019-01-24 12:21:01 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
struct MouseEvent
2018-11-22 19:31:44 +08:00
{
2019-01-24 12:21:01 +08:00
enum Type : EventType
{
First = WM_MOUSEFIRST,
2018-05-14 00:36:01 +08:00
2019-01-24 12:21:01 +08:00
Move, // <20>ƶ<EFBFBD>
Down, // <20><><EFBFBD><EFBFBD>
Up, // ̧<><CCA7>
Wheel, // <20><><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>
2019-01-24 12:21:01 +08:00
Hover, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Out, // <20><><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
Click, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Last // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
};
float x;
float y;
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>
struct
{
MouseButton button; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>Ϊ Down | Up | Click ʱ<><CAB1>Ч
};
struct
{
float wheel_delta; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>Ϊ Wheel ʱ<><CAB1>Ч
};
static inline bool Check(EventType type)
{
return type > Type::First && type < Type::Last;
}
};
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
struct KeyboardEvent
{
enum Type : UINT
{
First = WM_KEYFIRST,
Down, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Up, // <20><>̧<EFBFBD><CCA7>
Last
};
KeyCode code;
int count;
static inline bool Check(UINT type)
{
return type > Type::First && type < Type::Last;
}
2018-11-22 19:31:44 +08:00
};
2019-01-24 12:21:01 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
struct WindowEvent
2018-11-22 19:31:44 +08:00
{
public:
2019-01-24 12:21:01 +08:00
enum Type : EventType
2018-11-22 19:31:44 +08:00
{
First = WM_NULL,
2019-01-24 22:22:11 +08:00
Moved, // <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
Resized, // <20><><EFBFBD>ڴ<EFBFBD>С<EFBFBD>
FocusChanged, // <20><><EFBFBD>û<EFBFBD>ʧȥ<CAA7><C8A5><EFBFBD><EFBFBD>
TitleChanged, // <20><><EFBFBD><EFBFBD><EFBFBD>
2019-01-25 14:48:37 +08:00
Closed, // <20><><EFBFBD>ڱ<EFBFBD><DAB1>ر<EFBFBD>
2018-05-10 14:03:54 +08:00
2018-11-22 19:31:44 +08:00
Last
};
2019-01-24 22:22:11 +08:00
union
{
struct // WindowEvent::Moved
{
int x;
int y;
};
struct // WindowEvent::Resized
{
int width;
int height;
};
struct // WindowEvent::FocusChanged
{
bool focus;
};
struct // WindowEvent::TitleChanged
{
const wchar_t* title;
};
};
2019-01-24 12:21:01 +08:00
static inline bool Check(EventType type)
{
return type > Type::First && type < Type::Last;
}
};
// <20>¼<EFBFBD>
struct Event
{
EventType type;
bool has_target;
union
{
MouseEvent mouse;
KeyboardEvent key;
WindowEvent win;
};
Event()
: type(0)
, has_target(false)
{}
2019-01-24 12:21:01 +08:00
Event(EventType type)
: type(type)
, has_target(false)
{}
};
}