Skip to content

Commit

Permalink
GUI2: moved event handling into main context
Browse files Browse the repository at this point in the history
Not sure why I need to call join() in connect() instead of the ctor, though.
  • Loading branch information
Vultraz committed Aug 12, 2017
1 parent b7a263f commit dbac9db
Showing 1 changed file with 9 additions and 55 deletions.
64 changes: 9 additions & 55 deletions src/gui/core/event/handler.cpp
Expand Up @@ -43,16 +43,6 @@
* their own window, therefore the code will be cleaned up after that has been
* determined.
*/

/*
* At some point in the future this event handler should become the main event
* handler. This switch controls the experimental switch for that change.
*/
//#define MAIN_EVENT_HANDLER

/* Since this code is still very experimental it's not enabled yet. */
//#define ENABLE

namespace gui2
{

Expand All @@ -61,40 +51,13 @@ namespace event

/***** Static data. *****/
static std::unique_ptr<class sdl_event_handler> handler_ = nullptr;
static events::event_context* event_context = nullptr;

#ifdef MAIN_EVENT_HANDLER
static unsigned draw_interval = 0;
// TODO: note sure if this is useful for something so I'm leaving it here.
#if 0
static unsigned event_poll_interval = 0;

/***** Static functions. *****/

/**
* SDL_AddTimer() callback for the draw event.
*
* When this callback is called it pushes a new draw event in the event queue.
*
* @returns The new timer interval, 0 to stop.
*/
static Uint32 timer_sdl_draw_event(Uint32, void*)
{
// DBG_GUI_E << "Pushing draw event in queue.\n";

SDL_Event event;
SDL_UserEvent data;

data.type = DRAW_EVENT;
data.code = 0;
data.data1 = nullptr;
data.data2 = nullptr;

event.type = DRAW_EVENT;
event.user = data;

SDL_PushEvent(&event);
return draw_interval;
}

/**
* SDL_AddTimer() callback for the poll event.
*
Expand Down Expand Up @@ -329,17 +292,14 @@ sdl_event_handler::sdl_event_handler()
}
}

// The event context is created now we join it.
#ifdef ENABLE
join();
#endif
// The event context is created now we join it.
// TODO: shouldn't this be the correct time to join the context not in connect()?
//join();
}

sdl_event_handler::~sdl_event_handler()
{
#ifdef ENABLE
leave();
#endif
//leave();
}

void sdl_event_handler::handle_event(const SDL_Event& event)
Expand Down Expand Up @@ -478,7 +438,6 @@ void sdl_event_handler::connect(dispatcher* dispatcher)
== dispatchers_.end());

if(dispatchers_.empty()) {
event_context = new events::event_context();
join();
}

Expand Down Expand Up @@ -509,8 +468,6 @@ void sdl_event_handler::disconnect(dispatcher* disp)

if(dispatchers_.empty()) {
leave();
delete event_context;
event_context = nullptr;
}
}

Expand Down Expand Up @@ -770,10 +727,7 @@ manager::manager()
{
handler_.reset(new sdl_event_handler());

#ifdef MAIN_EVENT_HANDLER
draw_interval = 30;
SDL_AddTimer(draw_interval, timer_sdl_draw_event, nullptr);

#if 0
event_poll_interval = 10;
SDL_AddTimer(event_poll_interval, timer_sdl_poll_events, nullptr);
#endif
Expand All @@ -783,10 +737,10 @@ manager::~manager()
{
handler_.reset(nullptr);

#ifdef MAIN_EVENT_HANDLER
draw_interval = 0;
#if 0
event_poll_interval = 0;
#endif

}

/***** free functions class. *****/
Expand Down

0 comments on commit dbac9db

Please sign in to comment.