CMCore/inc/hgl/io/event/WindowEvent.h

68 lines
1.8 KiB
C
Raw Normal View History

2025-01-18 20:27:28 +08:00
#ifndef HGL_IO_WINDOW_EVENT_INCLUDE
2022-01-24 18:56:05 +08:00
#define HGL_IO_WINDOW_EVENT_INCLUDE
#include<hgl/io/event/InputEvent.h>
namespace hgl
{
namespace io
{
enum class WindowEventID
{
Active,
Resize,
Close
};//enum class WindowEventID
union WindowEventData
{
uint64 data;
struct
{
int16 width,height;
};
bool active;
};
constexpr size_t WindowEventDataBytes=sizeof(WindowEventData);
class WindowEvent:public InputEvent
{
WindowEventData *wed;
public:
2025-06-10 01:31:18 +08:00
WindowEvent():InputEvent(InputEventSource::Window){wed=nullptr;}
2022-01-24 18:56:05 +08:00
virtual ~WindowEvent()=default;
2025-03-06 01:20:37 +08:00
virtual EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
2022-01-24 18:56:05 +08:00
{
2025-06-10 01:31:18 +08:00
if(header.type==InputEventSource::Window)
2022-01-24 18:56:05 +08:00
{
2025-06-10 01:31:18 +08:00
wed=(WindowEventData *)&data;
switch(WindowEventID(header.id))
{
case WindowEventID::Active:OnActive (wed->active) ;break;
case WindowEventID::Resize:OnResize (wed->width,wed->height);break;
case WindowEventID::Close: OnClose () ;break;
}
2022-01-24 18:56:05 +08:00
}
if(InputEvent::OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break;
return EventProcResult::Continue;
}
public:
2025-01-24 23:14:17 +08:00
virtual void OnResize(uint w,uint h){}
2022-01-24 18:56:05 +08:00
virtual void OnActive(bool){}
virtual void OnClose (){}
};//class WindowEvent:public InputEvent
}//namespace io
}//namespace hgl
2025-03-06 01:20:37 +08:00
#endif//HGL_IO_WINDOW_EVENT_INCLUDE