Skip to content
Permalink
Browse files

cegui: add OnClickHandler mouse events support

  • Loading branch information
qaisjp committed Mar 21, 2020
1 parent 2c5251a commit 6ede4f2c04ac6298bd3f2dd08739f4cc0bfac2b5
@@ -205,7 +205,7 @@ CMainMenu::CMainMenu(CGUI* pManager)
m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
m_pMenuArea->SetAlpha(0);
m_pMenuArea->SetZOrderingEnabled(false);
m_pMenuArea->SetClickHandler(GUI_CALLBACK(&CMainMenu::OnMenuClick, this));
m_pMenuArea->SetClickHandler(GUI_CALLBACK_MOUSE(&CMainMenu::OnMenuClick, this));
m_pMenuArea->SetMouseEnterHandler(GUI_CALLBACK(&CMainMenu::OnMenuEnter, this));
m_pMenuArea->SetMouseLeaveHandler(GUI_CALLBACK(&CMainMenu::OnMenuExit, this));

@@ -792,8 +792,10 @@ bool CMainMenu::OnMenuExit(CGUIElement* pElement)
return true;
}

bool CMainMenu::OnMenuClick(CGUIElement* pElement)
bool CMainMenu::OnMenuClick(CGUIMouseEventArgs Args)
{
CGUIElement* pElement = Args.pWindow;

// Handle all our clicks to the menu from here
if (m_pHoveredItem)
{
@@ -81,7 +81,7 @@ class CMainMenu

bool OnMenuEnter(CGUIElement* pElement);
bool OnMenuExit(CGUIElement* pElement);
bool OnMenuClick(CGUIElement* pElement);
bool OnMenuClick(CGUIMouseEventArgs Args);
bool OnQuickConnectButtonClick(CGUIElement* pElement);
bool OnResumeButtonClick(CGUIElement* pElement);
bool OnBrowseServersButtonClick(CGUIElement* pElement);
@@ -495,6 +495,11 @@ void CGUIElement_Impl::SetClickHandler(GUI_CALLBACK Callback)
m_OnClick = Callback;
}

void CGUIElement_Impl::SetClickHandler(const GUI_CALLBACK_MOUSE& Callback)
{
m_OnClickWithArgs = Callback;
}

void CGUIElement_Impl::SetDoubleClickHandler(GUI_CALLBACK Callback)
{
m_OnDoubleClick = Callback;
@@ -565,10 +570,29 @@ bool CGUIElement_Impl::Event_OnSized(const CEGUI::EventArgs& e)
return true;
}

bool CGUIElement_Impl::Event_OnClick()
bool CGUIElement_Impl::Event_OnClick(const CEGUI::EventArgs& eBase)
{
const CEGUI::MouseEventArgs& e = reinterpret_cast<const CEGUI::MouseEventArgs&>(eBase);
CGUIElement* pElement = reinterpret_cast<CGUIElement*>(this);

if (m_OnClick)
m_OnClick(reinterpret_cast<CGUIElement*>(this));
m_OnClick(pElement);

if (m_OnClickWithArgs)
{
CGUIMouseEventArgs NewArgs;

// copy the variables
NewArgs.button = static_cast<CGUIMouse::MouseButton>(e.button);
NewArgs.moveDelta = CVector2D(e.moveDelta.d_x, e.moveDelta.d_y);
NewArgs.position = CGUIPosition(e.position.d_x, e.position.d_y);
NewArgs.sysKeys = e.sysKeys;
NewArgs.wheelChange = e.wheelChange;
NewArgs.pWindow = pElement;

m_OnClickWithArgs(NewArgs);
}

return true;
}

@@ -661,4 +685,4 @@ bool CGUIElement_Impl::Event_OnKeyDown(const CEGUI::EventArgs& e)
inline void CGUIElement_Impl::ForceRedraw()
{
m_pWindow->forceRedraw();
}
}
@@ -103,6 +103,7 @@ class CGUIElement_Impl : public CGUIElement
void SetMovedHandler(GUI_CALLBACK Callback);
void SetSizedHandler(GUI_CALLBACK Callback);
void SetClickHandler(GUI_CALLBACK Callback);
void SetClickHandler(const GUI_CALLBACK_MOUSE& Callback);
void SetDoubleClickHandler(GUI_CALLBACK Callback);
void SetMouseEnterHandler(GUI_CALLBACK Callback);
void SetMouseLeaveHandler(GUI_CALLBACK Callback);
@@ -113,7 +114,7 @@ class CGUIElement_Impl : public CGUIElement
void SetKeyDownHandler(const GUI_CALLBACK_KEY& Callback);
void SetEnterKeyHandler(GUI_CALLBACK Callback);

bool Event_OnClick();
bool Event_OnClick(const CEGUI::EventArgs& e);
bool Event_OnDoubleClick();
bool Event_OnMouseEnter();
bool Event_OnMouseLeave();
@@ -143,16 +144,18 @@ class CGUIElement_Impl : public CGUIElement

std::list<CGUIProperty*> m_Properties;

GUI_CALLBACK m_OnClick;
GUI_CALLBACK m_OnDoubleClick;
GUI_CALLBACK m_OnMoved;
GUI_CALLBACK m_OnSized;
GUI_CALLBACK m_OnMouseEnter;
GUI_CALLBACK m_OnMouseLeave;
GUI_CALLBACK m_OnMouseDown;
GUI_CALLBACK m_OnActivate;
GUI_CALLBACK m_OnDeactivate;
GUI_CALLBACK m_OnKeyDown;
GUI_CALLBACK m_OnEnter;
GUI_CALLBACK_KEY m_OnKeyDownWithArgs;
GUI_CALLBACK m_OnClick;
GUI_CALLBACK m_OnDoubleClick;
GUI_CALLBACK m_OnMoved;
GUI_CALLBACK m_OnSized;
GUI_CALLBACK m_OnMouseEnter;
GUI_CALLBACK m_OnMouseLeave;
GUI_CALLBACK m_OnMouseDown;
GUI_CALLBACK m_OnActivate;
GUI_CALLBACK m_OnDeactivate;
GUI_CALLBACK m_OnKeyDown;
GUI_CALLBACK m_OnEnter;

GUI_CALLBACK_MOUSE m_OnClickWithArgs;
GUI_CALLBACK_KEY m_OnKeyDownWithArgs;
};
@@ -248,6 +248,10 @@ void SetClickHandler(GUI_CALLBACK Callback)
{
CGUIElement_Impl::SetClickHandler(Callback);
};
void SetClickHandler(const GUI_CALLBACK_MOUSE& Callback)
{
CGUIElement_Impl::SetClickHandler(Callback);
};
void SetDoubleClickHandler(GUI_CALLBACK Callback)
{
CGUIElement_Impl::SetDoubleClickHandler(Callback);
@@ -293,9 +297,9 @@ void SetEnterKeyHandler(GUI_CALLBACK Callback)
CGUIElement_Impl::SetEnterKeyHandler(Callback);
};

bool Event_OnClick()
bool Event_OnClick(const CEGUI::EventArgs& e)
{
return CGUIElement_Impl::Event_OnClick();
return CGUIElement_Impl::Event_OnClick(e);
};
bool Event_OnDoubleClick()
{
@@ -1041,7 +1041,7 @@ bool CGUI_Impl::Event_MouseClick(const CEGUI::EventArgs& Args)

// Call global and object handlers
if (pElement)
pElement->Event_OnClick();
pElement->Event_OnClick(Args);

if (m_MouseClickHandlers[m_Channel])
{
@@ -18,6 +18,12 @@ class CGUIElement;
#include <string>
#include "CGUITypes.h"

// Forward declaration
namespace CEGUI
{
class EventArgs;
}

enum eCGUIType
{
CGUI_BUTTON,
@@ -119,6 +125,7 @@ class CGUIElement
virtual void SetMovedHandler(GUI_CALLBACK Callback) = 0;
virtual void SetSizedHandler(GUI_CALLBACK Callback) = 0;
virtual void SetClickHandler(GUI_CALLBACK Callback) = 0;
virtual void SetClickHandler(const GUI_CALLBACK_MOUSE& Callback) = 0;
virtual void SetDoubleClickHandler(GUI_CALLBACK Callback) = 0;
virtual void SetMouseEnterHandler(GUI_CALLBACK Callback) = 0;
virtual void SetMouseLeaveHandler(GUI_CALLBACK Callback) = 0;
@@ -129,7 +136,7 @@ class CGUIElement
virtual void SetKeyDownHandler(const GUI_CALLBACK_KEY& Callback) = 0;
virtual void SetEnterKeyHandler(GUI_CALLBACK Callback) = 0;

virtual bool Event_OnClick() = 0;
virtual bool Event_OnClick(const CEGUI::EventArgs& e) = 0;
virtual bool Event_OnDoubleClick() = 0;
virtual bool Event_OnMouseEnter() = 0;
virtual bool Event_OnMouseLeave() = 0;

0 comments on commit 6ede4f2

Please sign in to comment.
You can’t perform that action at this time.