This commit is contained in:
2025-07-25 01:32:11 +08:00
16 changed files with 227 additions and 217 deletions

View File

@@ -3,6 +3,13 @@
#include<hgl/type/SortedSet.h>
#include<hgl/io/event/InputEventSource.h>
/*
*
*
* -> Window -> RenderFramework -> WorkManager
*
*/
namespace hgl::io
{
struct EventHeader
@@ -23,19 +30,22 @@ namespace hgl::io
Break,
};
class EventDispatch
/**
*
*/
class EventDispatcher
{
protected:
InputEventSource source_type;
EventDispatch * parent_input_event;
EventDispatcher * parent_input_event;
SortedSet<EventDispatch *> event_dispatch_subscribers;
SortedSet<EventDispatcher *> child_dispatchers;
protected:
void SetParent(EventDispatch *ie){parent_input_event=ie;}
void SetParent(EventDispatcher *ie){parent_input_event=ie;}
public:
@@ -46,9 +56,9 @@ namespace hgl::io
if(!RangeCheck(header.type))
return(EventProcResult::Break);
if(!event_dispatch_subscribers.IsEmpty())
if(!child_dispatchers.IsEmpty())
{
for(EventDispatch *ie:event_dispatch_subscribers)
for(EventDispatcher *ie:child_dispatchers)
if(ie->OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break;
}
@@ -58,53 +68,27 @@ namespace hgl::io
public:
EventDispatch()
EventDispatcher()
{
source_type=InputEventSource::Root;
parent_input_event=nullptr;
}
EventDispatch(InputEventSource ies)
EventDispatcher(InputEventSource ies)
{
source_type=ies;
parent_input_event=nullptr;
}
virtual ~EventDispatch()
virtual ~EventDispatcher()
{
if(parent_input_event)
parent_input_event->UnregisterEventDispatch(this);
parent_input_event->RemoveChildDispatcher(this);
}
virtual bool RegisterEventDispatch(EventDispatch *ie)
{
if(!ie)
return(false);
const InputEventSource ies=ie->GetInputEventSource();
if(!RangeCheck(ies))
return(false);
ie->SetParent(this);
return(event_dispatch_subscribers.Add(ie)!=-1);
}
bool UnregisterEventDispatch(EventDispatch *ie)
{
if(!ie)return(false);
const InputEventSource ies=ie->GetInputEventSource();
if(!RangeCheck(ies))
return(false);
ie->SetParent(nullptr);
return event_dispatch_subscribers.Delete(ie);
}
virtual bool AddChildDispatcher(EventDispatcher *ie);
virtual bool RemoveChildDispatcher(EventDispatcher *ie);
virtual bool Update(){return true;}
};//class EventDispatch
};//class EventDispatcher
}//namespace hgl::io

View File

@@ -1,7 +1,7 @@
#ifndef HGL_IO_KEYBOARD_EVENT_INCLUDE
#define HGL_IO_KEYBOARD_EVENT_INCLUDE
#include<hgl/io/event/EventDispatch.h>
#include<hgl/io/event/EventDispatcher.h>
namespace hgl
{
namespace io
@@ -158,11 +158,11 @@ namespace hgl
os_char ch;
};
class KeyboardEvent:public EventDispatch
class KeyboardEvent:public EventDispatcher
{
public:
KeyboardEvent():EventDispatch(InputEventSource::Keyboard){}
KeyboardEvent():EventDispatcher(InputEventSource::Keyboard){}
virtual ~KeyboardEvent()=default;
EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
@@ -177,7 +177,7 @@ namespace hgl
}
}
if(EventDispatch::OnEvent(header,data)==EventProcResult::Break)
if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break;
return EventProcResult::Continue;

View File

@@ -1,6 +1,6 @@
#pragma once
#include<hgl/io/event/EventDispatch.h>
#include<hgl/io/event/EventDispatcher.h>
#include<hgl/math/Vector.h>
namespace hgl::io
{
@@ -42,57 +42,20 @@ namespace hgl::io
constexpr size_t MouseEventDataBytes=sizeof(MouseEventData);
class MouseEvent:public EventDispatch
class MouseEvent:public EventDispatcher
{
MouseEventData *med;
MouseEventData *med=nullptr;
Vector2i position;
Vector2i position{};
bool pressed_statues[size_t(MouseButton::RANGE_SIZE)];
bool pressed_statues[size_t(MouseButton::RANGE_SIZE)]{};
public:
MouseEvent():EventDispatch(InputEventSource::Mouse)
{
med=nullptr;
position.x=0;
position.y=0;;
hgl_zero(pressed_statues);
}
MouseEvent():EventDispatcher(InputEventSource::Mouse){}
virtual ~MouseEvent()=default;
EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
{
if(header.type==InputEventSource::Mouse)
{
med=(MouseEventData *)&data;
if(MouseEventID(header.id)==MouseEventID::Wheel)
{
if(OnWheel (med->x,med->y) )return EventProcResult::Break;
}
else
{
position.x=med->x;
position.y=med->y;
switch(MouseEventID(header.id))
{
case MouseEventID::Move: if(OnMove (med->x,med->y) )return EventProcResult::Break;break;
case MouseEventID::Pressed: pressed_statues[med->button]=true;
if(OnPressed (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
case MouseEventID::Released: pressed_statues[med->button]=false;
if(OnReleased (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
case MouseEventID::DblClicked: if(OnDblClicked (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
}
}
}
if(EventDispatch::OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break;
return EventProcResult::Continue;
}
virtual EventProcResult OnEvent (const EventHeader &header,const uint64 data) override;
virtual bool OnMove (int,int){return false;}
virtual bool OnWheel (int,int){return false;}

View File

@@ -1,7 +1,7 @@
#ifndef HGL_IO_WINDOW_EVENT_INCLUDE
#define HGL_IO_WINDOW_EVENT_INCLUDE
#include<hgl/io/event/EventDispatch.h>
#include<hgl/io/event/EventDispatcher.h>
namespace hgl
{
namespace io
@@ -27,13 +27,13 @@ namespace hgl
constexpr size_t WindowEventDataBytes=sizeof(WindowEventData);
class WindowEvent:public EventDispatch
class WindowEvent:public EventDispatcher
{
WindowEventData *wed;
public:
WindowEvent():EventDispatch(InputEventSource::Window){wed=nullptr;}
WindowEvent():EventDispatcher(InputEventSource::Window){wed=nullptr;}
virtual ~WindowEvent()=default;
virtual EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
@@ -50,7 +50,7 @@ namespace hgl
}
}
if(EventDispatch::OnEvent(header,data)==EventProcResult::Break)
if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break;
return EventProcResult::Continue;
@@ -61,7 +61,7 @@ namespace hgl
virtual void OnResize(uint w,uint h){}
virtual void OnActive(bool){}
virtual void OnClose (){}
};//class WindowEvent:public EventDispatch
};//class WindowEvent:public EventDispatcher
}//namespace io
}//namespace hgl
#endif//HGL_IO_WINDOW_EVENT_INCLUDE

View File

@@ -51,16 +51,6 @@ namespace hgl
return glm::all(glm::epsilonEqual(q1,q2,err));
}
inline Matrix4f inverse(const Matrix4f &m)
{
return glm::inverse(m);
}
inline Matrix4f transpose(const Matrix4f &m)
{
return glm::transpose(m);
}
/**
* 生成一个正角视图矩阵
* @param left 左
@@ -70,7 +60,7 @@ namespace hgl
* @param znear 近平面z值
* @param zfar 远平台z值
*/
Matrix4f ortho( float left,
Matrix4f OrthoMatrix( float left,
float right,
float bottom,
float top,
@@ -84,14 +74,14 @@ namespace hgl
* @param znear 近平面z值
* @param zfar 远平台z值
*/
Matrix4f ortho(float width,float height,float znear,float zfar);
Matrix4f OrthoMatrix(float width,float height,float znear,float zfar);
/**
* 生成一个正角视图矩阵
* @param width 宽
* @param height 高
*/
Matrix4f ortho(float width,float height);
Matrix4f OrthoMatrix(float width,float height);
/**
* 生成一个透视矩阵
@@ -100,7 +90,7 @@ namespace hgl
* @param znear 近截面
* @param zfar 远截面
*/
Matrix4f perspective( float field_of_view,
Matrix4f PerspectiveMatrix( float field_of_view,
float aspect_ratio,
float znear,
float zfar);
@@ -110,66 +100,70 @@ namespace hgl
* @param target 目标位置
* @param up 向上向量
*/
Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up=AxisVector::Z);
Matrix4f LookAtMatrix(const Vector3f &eye,const Vector3f &target,const Vector3f &up=AxisVector::Z);
inline Matrix4f translate(const Vector3f &v)
inline Matrix4f TranslateMatrix(const Vector3f &v)
{
return glm::translate(Matrix4f(1.0f),v);
}
inline Matrix4f translate(float x,float y,float z)
inline Matrix4f TranslateMatrix(float x,float y,float z)
{
return glm::translate(Matrix4f(1.0f),Vector3f(x,y,z));
}
inline Matrix4f translate(float x,float y)
inline Matrix4f TranslateMatrix(float x,float y)
{
return translate(x,y,1.0f);
return glm::translate(Matrix4f(1.0f),Vector3f(x,y,1.0f));
}
inline Matrix4f scale(const Vector3f &v)
inline Matrix4f ScaleMatrix(const Vector3f &v)
{
return glm::scale(Matrix4f(1.0f),v);
}
inline Matrix4f scale(float x,float y,float z)
inline Matrix4f ScaleMatrix(float x,float y,float z)
{
return glm::scale(Matrix4f(1.0f),Vector3f(x,y,z));
}
inline Matrix4f scale(float x,float y)
inline Matrix4f ScaleMatrix(float x,float y)
{
return scale(x,y,1.0f);
return glm::scale(Matrix4f(1.0f),Vector3f(x,y,1.0f));
}
inline Matrix4f scale(float s)
inline Matrix4f ScaleMatrix(float s)
{
return glm::scale(Matrix4f(1.0f),Vector3f(s,s,s));
}
inline Matrix4f rotate(float rad,const Vector3f &axis)
inline Matrix4f AxisXRotate(float rad){return glm::rotate(Matrix4f(1.0f),rad,AxisVector::X);}
inline Matrix4f AxisYRotate(float rad){return glm::rotate(Matrix4f(1.0f),rad,AxisVector::Y);}
inline Matrix4f AxisZRotate(float rad){return glm::rotate(Matrix4f(1.0f),rad,AxisVector::Z);}
inline Matrix4f AxisRotate(float rad,const Vector3f &axis)
{
return glm::rotate(Matrix4f(1.0f),rad,axis);
}
inline Matrix4f rotate(float rad,float x,float y,float z)
inline Matrix4f AxisRotate(float rad,float x,float y,float z)
{
return glm::rotate(Matrix4f(1.0f),rad,Vector3f(x,y,z));
}
inline Matrix4f rotate(float rad,float x,float y)
inline Matrix4f AxisRotate(float rad,float x,float y)
{
return rotate(rad,x,y,1.0f);
return AxisRotate(rad,x,y,1.0f);
}
inline Matrix4f rotate(float rad,const Vector4f &axis)
inline Matrix4f AxisRotate(float rad,const Vector4f &axis)
{
return rotate(rad,Vector3f(axis.x,axis.y,axis.z));
return AxisRotate(rad,Vector3f(axis.x,axis.y,axis.z));
}
inline Vector3f rotate(const Vector3f &v3f,float rad,const Vector3f &axis)
inline Vector3f AxisRotate(const Vector3f &v3f,float rad,const Vector3f &axis)
{
Vector4f result = rotate(rad, axis)*Vector4f(v3f, 1.0f);
Vector4f result = AxisRotate(rad, axis)*Vector4f(v3f, 1.0f);
return Vector3f(result.x,result.y,result.z);
}

View File

@@ -95,7 +95,7 @@ namespace hgl
}
/**
* 摄氏度到开
* 摄氏度到开尔文
*/
template<typename T>
inline T Celsius2Kelvin(const T &c)
@@ -104,7 +104,7 @@ namespace hgl
}
/**
* 开度到摄氏度
* 开尔文度到摄氏度
*/
template<typename T>
inline T Kelvin2Celsius(const T &k)

View File

@@ -101,7 +101,7 @@ namespace hgl
void MakeNewestData(Matrix4f &mat) override
{
mat=translate(offset);
mat=TranslateMatrix(offset);
}
public:
@@ -215,7 +215,7 @@ namespace hgl
void MakeNewestData(Matrix4f &mat) override
{
mat=rotate(angle,axis);
mat=AxisRotate(angle,axis);
}
public:
@@ -342,7 +342,7 @@ namespace hgl
void MakeNewestData(Matrix4f &mat) override
{
mat=scale(scale3f);
mat=ScaleMatrix(scale3f);
}
public:
@@ -395,7 +395,7 @@ namespace hgl
void MakeNewestData(Matrix4f &mat) override
{
mat=lookat(eye,center,up);
mat=LookAtMatrix(eye,center,up);
}
public:
@@ -695,7 +695,7 @@ namespace hgl
const Matrix4f GetMatrix()const //不能执行UpdateMatrix时的获取
{
if(matrix_dirty)
return translate(translation_vector)*ToMatrix(rotation_quat)*scale(scale_vector);
return TranslateMatrix(translation_vector)*ToMatrix(rotation_quat)*ScaleMatrix(scale_vector);
else
return matrix;
}

View File

@@ -33,7 +33,7 @@ namespace hgl
return ArrayList<T *>::Insert(index,obj);
}
virtual void Free() override ///<清除所有数据
virtual void Free() override ///<清除所有数据并释放缓冲区
{
Clear();
ArrayList<T *>::Free();

View File

@@ -1,5 +1,4 @@
#ifndef HGL_STR_TEMPLATE_INCLUDE
#define HGL_STR_TEMPLATE_INCLUDE
#pragma once
#include<hgl/TypeFunc.h>
namespace hgl
@@ -2729,7 +2728,6 @@ namespace hgl
if(pna->ToNumber(sp,result))
{
++count;
result_list.Add(result);
++p;
@@ -3004,7 +3002,7 @@ namespace hgl
}
/**
* 将一串原始数据转成16进制数值字符串
* 将一串原始数据转成16进制数值字符串
* @param str 16进制数值字符串存入处
* @param src 原始的数据
* @param size 原始数据字节长度
@@ -3056,5 +3054,4 @@ namespace hgl
template<typename T> inline void ToUpperHexStr(T *str,const void *data,const int size,const T gap_char=0){DataToHexStr<T>(str,(const uint8 *)data,size,UpperHexChar,gap_char);}
template<typename T> inline void ToLowerHexStr(T *str,const void *data,const int size,const T gap_char=0){DataToHexStr<T>(str,(const uint8 *)data,size,LowerHexChar,gap_char);}
}//namespace hgl
#endif//HGL_STR_TEMPLATE_INCLUDE
}//namespace hgl

View File

@@ -507,9 +507,9 @@ namespace hgl
/**
* 和一个字符串进行比较
* @param bs 比较字符串
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int Comp(const SelfClass &bs)const
{
@@ -525,9 +525,9 @@ namespace hgl
/**
* 和一个字符串进行比较
* @param str 比较字符串
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int Comp(const T *str)const
{
@@ -546,9 +546,9 @@ namespace hgl
* 和一个字符串进行比较
* @param pos 起始位置
* @param bs 比较字符串
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int Comp(const uint pos,const SelfClass &bs)const
{
@@ -566,9 +566,9 @@ namespace hgl
* @param pos 起始位置
* @param bs 比较字符串
* @param num 比较长度
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int Comp(const uint pos,const SelfClass &bs,const int num)const
{
@@ -585,9 +585,9 @@ namespace hgl
* 和一个字符串进行比较
* @param pos 起始位置
* @param str 比较字符串
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int Comp(const uint pos,const T *str)const
{
@@ -607,9 +607,9 @@ namespace hgl
* @param pos 起始位置
* @param str 比较字符串
* @param num 比较长度
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int Comp(const uint pos,const T *str,const int num)const
{
@@ -625,11 +625,11 @@ namespace hgl
}
/**
* 和一个字符串进行比较,英文不区分大小写
* 和一个字符串进行比较,英文不区分大小写
* @param bs 比较字符串
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int CaseComp(const SelfClass &bs)const
{
@@ -645,11 +645,11 @@ namespace hgl
}
/**
* 和一个字符串进行比较,英文不区分大小写
* 和一个字符串进行比较,英文不区分大小写
* @param str 比较字符串
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int CaseComp(const T *str)const
{
@@ -665,12 +665,12 @@ namespace hgl
}
/**
* 和一个字符串比较指长度的字符
* 和一个字符串比较指长度的字符
* @param bs 比较字符串
* @param num 比较字数
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @param num 比较字
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int Comp(const SelfClass &bs,const int num)const
{
@@ -688,12 +688,12 @@ namespace hgl
}
/**
* 和一个字符串比较指长度的字符
* 和一个字符串比较指长度的字符
* @param str 比较字符串
* @param num 比较字数
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @param num 比较字
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int Comp(const T *str,const int num)const
{
@@ -709,12 +709,12 @@ namespace hgl
}
/**
* 和一个字符串比较指长度的字符,英文不区分大小写
* 和一个字符串比较指长度的字符,英文不区分大小写
* @param bs 比较字符串
* @param num 比较字数
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @param num 比较字
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int CaseComp(const SelfClass &bs,const int num)const
{
@@ -732,12 +732,12 @@ namespace hgl
}
/**
* 和一个字符串比较指长度的字符,英文不区分大小写
* 和一个字符串比较指长度的字符,英文不区分大小写
* @param str 比较字符串
* @param num 比较字数
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @param num 比较字
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int CaseComp(const T *str,const int num)const
{
@@ -753,12 +753,12 @@ namespace hgl
}
/**
* 和一个字符串比较指长度的字符,英文不区分大小写
* 和一个字符串比较指长度的字符,英文不区分大小写
* @param str 比较字符串
* @param num 比较字数
* @return <0 自身小
* @return 0 等
* @return >0 自身大
* @param num 比较字
* @return <0 此字符串小于参数字符串
* @return 0
* @return >0 此字符串大于参数字符串
*/
int CaseComp(const uint pos,const T *str,const int num)const
{

View File

@@ -192,11 +192,11 @@ namespace hgl
}
/**
* 查找字符串,英文无视大小写
* @param str 要找的字符串
* 查找字符串,英文不区分大小写
* @param str 要找的字符串
* @return 查找到的字符串的索引,未找到返回-1
*/
int CaseFind(const StringClass &str) const ///<查找字符串,英文无视大小写,未找到返回-1
int CaseFind(const StringClass &str) const ///<查找字符串,英文不区分大小写,未找到返回-1
{
const int count=Items.GetCount();
StringClass** sl = Items.GetData();
@@ -219,9 +219,9 @@ namespace hgl
}
/**
* 确认字符串存在,英文无视大小写
* 确认字符串存在,英文不区分大小写
*/
bool CaseExist(const StringClass &str) const ///<确认字符串存在,英文无视大小写
bool CaseExist(const StringClass &str) const ///<确认字符串存在,英文不区分大小写
{
return CaseFind(str)!=-1;
}
@@ -248,12 +248,12 @@ namespace hgl
}
/**
* 查找字符串,英文无视大小写,并指定最大比较长度
* @param str 要找的字符串
* 查找字符串,英文不区分大小写,并指定最大比较长度
* @param str 要找的字符串
* @param cn 限定的要查找字符串的最大长度
* @return 查找到的字符串的索引,未找到返回-1
*/
int CaseFind(const StringClass &str,const int cn) const ///<查找字符串,英文无视大小写,未找到返回-1
int CaseFind(const StringClass &str,const int cn) const ///<查找字符串,英文不区分大小写,未找到返回-1
{
const int count=Items.GetCount();

View File

@@ -193,8 +193,10 @@ SET(IO_TEXT_FILES IO/TextOutputStream.cpp
SET(INPUT_EVENT_FILES ${IO_INCLUDE_PATH}/event/KeyboardEvent.h
${IO_INCLUDE_PATH}/event/MouseEvent.h
${IO_INCLUDE_PATH}/event/JoystickEvent.h
${IO_INCLUDE_PATH}/event/EventDispatch.h
${IO_INCLUDE_PATH}/event/EventDispatcher.h
${IO_INCLUDE_PATH}/event/InputMapping.h
IO/Event/MouseEvent.cpp
IO/Event/EventDispatcher.cpp
)
SOURCE_GROUP("IO\\Event" FILES ${INPUT_EVENT_FILES})
@@ -247,10 +249,10 @@ SOURCE_GROUP("Thread" FILES ${BASE_THREAD_HEADER_FILES}
${BASE_THREAD_SOURCE_FILES})
FILE(GLOB BASE_EVENT_HEADER_FILES ${CMCORE_ROOT_INCLUDE_PATH}/hgl/event/*.*)
FILE(GLOB BASE_EVENT_SOURCE_FILES Event/*.*)
#FILE(GLOB BASE_EVENT_SOURCE_FILES Event/*.*)
SOURCE_GROUP("Event" FILES ${BASE_EVENT_HEADER_FILES}
${BASE_EVENT_SOURCE_FILES})
SOURCE_GROUP("Event" FILES ${BASE_EVENT_HEADER_FILES})
#${BASE_EVENT_SOURCE_FILES})
file(GLOB BASE_PLUG_IN_HEADER ${CMCORE_ROOT_INCLUDE_PATH}/hgl/plugin/*.h)
file(GLOB BASE_PLUG_IN_SOURCE PlugIn/*.cpp)

View File

@@ -0,0 +1,33 @@
#include<hgl/io/event/EventDispatcher.h>
namespace hgl::io
{
bool EventDispatcher::AddChildDispatcher(EventDispatcher *ie)
{
if(!ie)
return(false);
const InputEventSource ies=ie->GetInputEventSource();
if(!RangeCheck(ies))
return(false);
ie->SetParent(this);
return(child_dispatchers.Add(ie)!=-1);
}
bool EventDispatcher::RemoveChildDispatcher(EventDispatcher *ie)
{
if(!ie)return(false);
const InputEventSource ies=ie->GetInputEventSource();
if(!RangeCheck(ies))
return(false);
ie->SetParent(nullptr);
return child_dispatchers.Delete(ie);
}
}//namespace hgl::io

View File

@@ -0,0 +1,37 @@
#include<hgl/io/event/MouseEvent.h>
namespace hgl::io
{
EventProcResult MouseEvent::OnEvent(const EventHeader &header,const uint64 data)
{
if(header.type==InputEventSource::Mouse)
{
med=(MouseEventData *)&data;
if(MouseEventID(header.id)==MouseEventID::Wheel)
{
if(OnWheel (med->x,med->y) )return EventProcResult::Break;
}
else
{
position.x=med->x;
position.y=med->y;
switch(MouseEventID(header.id))
{
case MouseEventID::Move: if(OnMove (med->x,med->y) )return EventProcResult::Break;break;
case MouseEventID::Pressed: pressed_statues[med->button]=true;
if(OnPressed (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
case MouseEventID::Released: pressed_statues[med->button]=false;
if(OnReleased (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
case MouseEventID::DblClicked: if(OnDblClicked (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
}
}
}
if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break;
return EventProcResult::Continue;
}
}//namespace hgl::io

View File

@@ -14,7 +14,7 @@
namespace hgl
{
Matrix4f ortho( float left,
Matrix4f OrthoMatrix( float left,
float right,
float bottom,
float top,
@@ -51,9 +51,9 @@ namespace hgl
* @param znear 近平面z值
* @param zfar 远平台z值
*/
Matrix4f ortho(float width,float height,float znear,float zfar)
Matrix4f OrthoMatrix(float width,float height,float znear,float zfar)
{
return ortho(0.0f,width,height,0.0f,znear,zfar);
return OrthoMatrix(0.0f,width,height,0.0f,znear,zfar);
}
/**
@@ -61,9 +61,9 @@ namespace hgl
* @param width 宽
* @param height 高
*/
Matrix4f ortho(float width,float height)
Matrix4f OrthoMatrix(float width,float height)
{
return ortho(width,height,0.0f,1.0f);
return OrthoMatrix(width,height,0.0f,1.0f);
}
/**
@@ -73,7 +73,7 @@ namespace hgl
* @param znear 近截面
* @param zfar 远截面
*/
Matrix4f perspective( float field_of_view,
Matrix4f PerspectiveMatrix( float field_of_view,
float aspect_ratio,
float znear,
float zfar)
@@ -105,7 +105,7 @@ namespace hgl
//经查证此代码等于glm::perspectiveRH_ZO之后将[1][1]乘-1在SaschaWillems的范例中如果反转Y轴则[1][1]确实要乘-1。
}
Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up)
Matrix4f LookAtMatrix(const Vector3f &eye,const Vector3f &target,const Vector3f &up)
{
Vector3f forward=normalize(target-eye);
Vector3f right =normalize(cross(forward,up));

View File

@@ -52,7 +52,7 @@ namespace hgl
}
else
{
matrix=translate(translation_vector)*ToMatrix(rotation_quat)*scale(scale_vector);
matrix=TranslateMatrix(translation_vector)*ToMatrix(rotation_quat)*ScaleMatrix(scale_vector);
inverse_matrix=inverse(matrix);
transpose_inverse_matrix=transpose(inverse_matrix);