Cleanup: store const events in GHOST's event handling logic

This commit is contained in:
Campbell Barton 2023-10-08 15:23:40 +11:00
parent fc78182cc8
commit 39295476d0
11 changed files with 21 additions and 21 deletions

View File

@ -32,7 +32,7 @@ class GHOST_IEventConsumer {
* \param event: The event that can be handled or ignored.
* \return Indication as to whether the event was handled.
*/
virtual bool processEvent(GHOST_IEvent *event) = 0;
virtual bool processEvent(const GHOST_IEvent *event) = 0;
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_IEventConsumer")

View File

@ -21,7 +21,7 @@ GHOST_CallbackEventConsumer::GHOST_CallbackEventConsumer(GHOST_EventCallbackProc
m_userData = userData;
}
bool GHOST_CallbackEventConsumer::processEvent(GHOST_IEvent *event)
bool GHOST_CallbackEventConsumer::processEvent(const GHOST_IEvent *event)
{
return m_eventCallback((GHOST_EventHandle)event, m_userData);
}

View File

@ -36,7 +36,7 @@ class GHOST_CallbackEventConsumer : public GHOST_IEventConsumer {
* \param event: The event that can be handled or ignored.
* \return Indication as to whether the event was handled.
*/
bool processEvent(GHOST_IEvent *event);
bool processEvent(const GHOST_IEvent *event);
protected:
/** The call-back routine invoked. */

View File

@ -45,7 +45,7 @@ uint32_t GHOST_EventManager::getNumEvents(GHOST_TEventType type)
return numEvents;
}
GHOST_TSuccess GHOST_EventManager::pushEvent(GHOST_IEvent *event)
GHOST_TSuccess GHOST_EventManager::pushEvent(const GHOST_IEvent *event)
{
GHOST_TSuccess success;
GHOST_ASSERT(event, "invalid event");
@ -59,7 +59,7 @@ GHOST_TSuccess GHOST_EventManager::pushEvent(GHOST_IEvent *event)
return success;
}
void GHOST_EventManager::dispatchEvent(GHOST_IEvent *event)
void GHOST_EventManager::dispatchEvent(const GHOST_IEvent *event)
{
TConsumerVector::iterator iter;
@ -70,7 +70,7 @@ void GHOST_EventManager::dispatchEvent(GHOST_IEvent *event)
void GHOST_EventManager::dispatchEvent()
{
GHOST_IEvent *event = m_events.back();
const GHOST_IEvent *event = m_events.back();
m_events.pop_back();
m_handled_events.push_back(event);
@ -130,7 +130,7 @@ void GHOST_EventManager::removeWindowEvents(const GHOST_IWindow *window)
TEventStack::iterator iter;
iter = m_events.begin();
while (iter != m_events.end()) {
GHOST_IEvent *event = *iter;
const GHOST_IEvent *event = *iter;
if (event->getWindow() == window) {
GHOST_PRINT("GHOST_EventManager::removeWindowEvents(): removing event\n");
/*
@ -152,7 +152,7 @@ void GHOST_EventManager::removeTypeEvents(GHOST_TEventType type, const GHOST_IWi
TEventStack::iterator iter;
iter = m_events.begin();
while (iter != m_events.end()) {
GHOST_IEvent *event = *iter;
const GHOST_IEvent *event = *iter;
if ((event->getType() == type) && (!window || (event->getWindow() == window))) {
GHOST_PRINT("GHOST_EventManager::removeTypeEvents(): removing event\n");
/*

View File

@ -53,12 +53,12 @@ class GHOST_EventManager {
* Do not delete the event!
* \param event: The event to push on the stack.
*/
GHOST_TSuccess pushEvent(GHOST_IEvent *event);
GHOST_TSuccess pushEvent(const GHOST_IEvent *event);
/**
* Dispatches the given event directly, bypassing the event stack.
*/
void dispatchEvent(GHOST_IEvent *event);
void dispatchEvent(const GHOST_IEvent *event);
/**
* Dispatches the event at the back of the stack.
@ -108,11 +108,11 @@ class GHOST_EventManager {
void disposeEvents();
/** A stack with events. */
typedef std::deque<GHOST_IEvent *> TEventStack;
typedef std::deque<const GHOST_IEvent *> TEventStack;
/** The event stack. */
std::deque<GHOST_IEvent *> m_events;
std::deque<GHOST_IEvent *> m_handled_events;
std::deque<const GHOST_IEvent *> m_events;
std::deque<const GHOST_IEvent *> m_handled_events;
/** A vector with event consumers. */
typedef std::vector<GHOST_IEventConsumer *> TConsumerVector;

View File

@ -31,7 +31,7 @@ static const char *getButtonActionString(const GHOST_TButtonAction action)
}
#endif /* WITH_INPUT_NDOF */
bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event)
bool GHOST_EventPrinter::processEvent(const GHOST_IEvent *event)
{
bool handled = false;

View File

@ -22,7 +22,7 @@ class GHOST_EventPrinter : public GHOST_IEventConsumer {
* \param event: The event that can be handled or not.
* \return Indication as to whether the event was handled.
*/
bool processEvent(GHOST_IEvent *event);
bool processEvent(const GHOST_IEvent *event);
protected:
/**

View File

@ -267,7 +267,7 @@ GHOST_TSuccess GHOST_System::removeEventConsumer(GHOST_IEventConsumer *consumer)
return success;
}
GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent *event)
GHOST_TSuccess GHOST_System::pushEvent(const GHOST_IEvent *event)
{
GHOST_TSuccess success;
if (m_eventManager) {

View File

@ -285,7 +285,7 @@ class GHOST_System : public GHOST_ISystem {
* Do not delete the event!
* \param event: The event to push on the stack.
*/
GHOST_TSuccess pushEvent(GHOST_IEvent *event);
GHOST_TSuccess pushEvent(const GHOST_IEvent *event);
/**
* \return The timer manager.

View File

@ -1005,7 +1005,7 @@ struct GWL_Display {
* Events added from the event reading thread.
* Added into the main event queue when on #GHOST_SystemWayland::processEvents.
*/
std::vector<GHOST_IEvent *> events_pending;
std::vector<const GHOST_IEvent *> events_pending;
/** Guard against multiple threads accessing `events_pending` at once. */
std::mutex events_pending_mutex;
@ -1081,7 +1081,7 @@ static void gwl_display_destroy(GWL_Display *display)
display->ghost_timer_manager = nullptr;
}
/* Pending events may be left unhandled. */
for (GHOST_IEvent *event : display->events_pending) {
for (const GHOST_IEvent *event : display->events_pending) {
delete event;
}
@ -5737,7 +5737,7 @@ bool GHOST_SystemWayland::processEvents(bool waitForEvent)
{
std::lock_guard lock{display_->events_pending_mutex};
for (GHOST_IEvent *event : display_->events_pending) {
for (const GHOST_IEvent *event : display_->events_pending) {
/* Perform actions that aren't handled in a thread. */
switch (event->getType()) {

View File

@ -443,7 +443,7 @@ Application::~Application()
}
}
bool Application::processEvent(GHOST_IEvent *event)
bool Application::processEvent(const GHOST_IEvent *event)
{
GHOST_IWindow *window = event->getWindow();
bool handled = true;