Make window events a separate handler for sdl_events
This adds a new function to sdl_handler, handle_window_event that is called for all window events. It is propogated to all event contexts instead of just the current one. events::raise_draw_all_event (and a volatile variant) are added, that also sends draw events to all event contexts in reverse order so that the draw-stack can be redrawn bottom-up.
This commit is contained in:
parent
ac242376e9
commit
5f5a334fba
14 changed files with 99 additions and 30 deletions
|
@ -113,6 +113,10 @@ protected:
|
|||
*/
|
||||
void handle_event(const SDL_Event& event);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
void handle_window_event(const SDL_Event& ) {}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Process keydown (only when the general map display does not have focus).
|
||||
*/
|
||||
|
|
|
@ -447,8 +447,22 @@ void pump()
|
|||
info.resize_dimensions.second = event.window.data2;
|
||||
break;
|
||||
}
|
||||
//make sure this runs in it's own scope.
|
||||
{
|
||||
for( std::deque<context>::reverse_iterator i = event_contexts.rbegin() ; i != event_contexts.rend(); i++) {
|
||||
const std::vector<sdl_handler*>& event_handlers = (*i).handlers;
|
||||
for(size_t i1 = 0, i2 = event_handlers.size(); i1 != i2 && i1 < event_handlers.size(); ++i1) {
|
||||
event_handlers[i1]->handle_window_event(event);
|
||||
}
|
||||
}
|
||||
const std::vector<sdl_handler*>& event_handlers = global_context.handlers;
|
||||
for(size_t i1 = 0, i2 = event_handlers.size(); i1 != i2 && i1 < event_handlers.size(); ++i1) {
|
||||
event_handlers[i1]->handle_window_event(event);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
//This event was just distributed, don't re-distribute.
|
||||
continue;
|
||||
#else
|
||||
case SDL_ACTIVEEVENT: {
|
||||
SDL_ActiveEvent& ae = reinterpret_cast<SDL_ActiveEvent&>(event);
|
||||
|
@ -586,6 +600,17 @@ void raise_draw_event()
|
|||
}
|
||||
}
|
||||
|
||||
void raise_draw_all_event()
|
||||
{
|
||||
/* iterate backwards as the most recent things will be at the top */
|
||||
for( std::deque<context>::reverse_iterator i = event_contexts.rbegin() ; i != event_contexts.rend(); i++) {
|
||||
const std::vector<sdl_handler*>& event_handlers = (*i).handlers;
|
||||
for(size_t i1 = 0, i2 = event_handlers.size(); i1 != i2 && i1 < event_handlers.size(); ++i1) {
|
||||
event_handlers[i1]->draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void raise_volatile_draw_event()
|
||||
{
|
||||
if(event_contexts.empty() == false) {
|
||||
|
@ -600,6 +625,17 @@ void raise_volatile_draw_event()
|
|||
}
|
||||
}
|
||||
|
||||
void raise_volatile_draw_all_event()
|
||||
{
|
||||
/* iterate backwards as the most recent things will be at the top */
|
||||
for( std::deque<context>::reverse_iterator i = event_contexts.rbegin() ; i != event_contexts.rend(); i++) {
|
||||
const std::vector<sdl_handler*>& event_handlers = (*i).handlers;
|
||||
for(size_t i1 = 0, i2 = event_handlers.size(); i1 != i2 && i1 < event_handlers.size(); ++i1) {
|
||||
event_handlers[i1]->volatile_draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void raise_volatile_undraw_event()
|
||||
{
|
||||
if(event_contexts.empty() == false) {
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define DRAW_EVENT (SDL_USEREVENT + 3)
|
||||
#define CLOSE_WINDOW_EVENT (SDL_USEREVENT + 4)
|
||||
#define SHOW_HELPTIP_EVENT (SDL_USEREVENT + 5)
|
||||
#define DRAW_ALL_EVENT (SDL_USEREVENT + 6)
|
||||
|
||||
namespace events
|
||||
{
|
||||
|
@ -41,6 +42,9 @@ class sdl_handler
|
|||
{
|
||||
public:
|
||||
virtual void handle_event(const SDL_Event& event) = 0;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
virtual void handle_window_event(const SDL_Event& event) = 0;
|
||||
#endif
|
||||
virtual void process_event() {}
|
||||
virtual void draw() {}
|
||||
|
||||
|
@ -120,7 +124,9 @@ public:
|
|||
|
||||
void raise_process_event();
|
||||
void raise_draw_event();
|
||||
void rasie_draw_all_event();
|
||||
void raise_volatile_draw_event();
|
||||
void raise_volativle_draw_all_event();
|
||||
void raise_volatile_undraw_event();
|
||||
void raise_help_string_event(int mousex, int mousey);
|
||||
|
||||
|
|
|
@ -133,6 +133,11 @@ public:
|
|||
/** Inherited from events::sdl_handler. */
|
||||
void handle_event(const SDL_Event& event);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
/** Inherited from events::sdl_handler. */
|
||||
void handle_window_event(const SDL_Event& event);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Connects a dispatcher.
|
||||
*
|
||||
|
@ -444,6 +449,13 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
}
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
void thandler::handle_window_event(const SDL_Event& event)
|
||||
{
|
||||
handle_event(event);
|
||||
}
|
||||
#endif
|
||||
|
||||
void thandler::connect(tdispatcher* dispatcher)
|
||||
{
|
||||
assert(std::find(dispatchers_.begin(), dispatchers_.end(), dispatcher)
|
||||
|
|
|
@ -149,6 +149,9 @@ struct basic_handler : public events::sdl_handler {
|
|||
basic_handler(display* disp, command_executor* exec=NULL);
|
||||
|
||||
void handle_event(const SDL_Event& event);
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
void handle_window_event(const SDL_Event&) {}
|
||||
#endif
|
||||
|
||||
private:
|
||||
display* disp_;
|
||||
|
|
|
@ -59,7 +59,10 @@ namespace preferences {
|
|||
|
||||
class prefs_event_handler : public events::sdl_handler {
|
||||
public:
|
||||
virtual void handle_event(const SDL_Event &event);
|
||||
virtual void handle_event(const SDL_Event &) {}
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
virtual void handle_window_event(const SDL_Event &event);
|
||||
#endif
|
||||
prefs_event_handler() : sdl_handler(false) {}
|
||||
};
|
||||
|
||||
|
@ -102,14 +105,15 @@ base_manager::~base_manager()
|
|||
} catch (...) {}
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
/*
|
||||
* Hook for setting window state variables on window resize and maximize
|
||||
* events. Since there is no fullscreen window event, that setter is called
|
||||
* from the CVideo function instead.
|
||||
*/
|
||||
void prefs_event_handler::handle_event(const SDL_Event& event)
|
||||
void prefs_event_handler::handle_window_event(const SDL_Event& event)
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
||||
// Saftey check to make sure this is a window event
|
||||
if (event.type != SDL_WINDOWEVENT) return;
|
||||
|
||||
|
@ -129,10 +133,8 @@ void prefs_event_handler::handle_event(const SDL_Event& event)
|
|||
|
||||
break;
|
||||
}
|
||||
#else
|
||||
UNUSED(event);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void write_preferences()
|
||||
{
|
||||
|
|
|
@ -149,15 +149,14 @@ void dialog_frame::set_dirty(bool dirty) {
|
|||
dirty_ = dirty;
|
||||
}
|
||||
|
||||
void dialog_frame::handle_event(const SDL_Event& event) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
void dialog_frame::handle_window_event(const SDL_Event& event) {
|
||||
|
||||
if (event.type == SDL_WINDOWEVENT) {
|
||||
dirty_ = true;
|
||||
}
|
||||
#else
|
||||
UNUSED(event);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
int dialog_frame::bottom_padding() const {
|
||||
int padding = 0;
|
||||
|
|
|
@ -97,7 +97,10 @@ public:
|
|||
|
||||
void set_dirty(bool dirty = true);
|
||||
|
||||
virtual void handle_event(const SDL_Event& event);
|
||||
virtual void handle_event(const SDL_Event&) {}
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
void handle_window_event(const SDL_Event& event);
|
||||
#endif
|
||||
|
||||
private:
|
||||
void clear_background();
|
||||
|
|
|
@ -986,9 +986,10 @@ part_ui::RESULT part_ui::show()
|
|||
return ret_;
|
||||
}
|
||||
|
||||
void part_ui::handle_event(const SDL_Event &event)
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
void part_ui::handle_window_event(const SDL_Event &event)
|
||||
{
|
||||
|
||||
if (event.type == SDL_WINDOWEVENT &&
|
||||
(event.window.event == SDL_WINDOWEVENT_MAXIMIZED || SDL_WINDOWEVENT_RESIZED || SDL_WINDOWEVENT_EXPOSED || SDL_WINDOWEVENT_RESTORED)) {
|
||||
|
||||
|
@ -997,10 +998,8 @@ void part_ui::handle_event(const SDL_Event &event)
|
|||
this->prepare_floating_images();
|
||||
dirty_ = true;
|
||||
}
|
||||
#else
|
||||
UNUSED(event);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
} // end namespace storyscreen
|
||||
|
|
|
@ -64,7 +64,10 @@ public:
|
|||
*/
|
||||
RESULT show();
|
||||
|
||||
virtual void handle_event(const SDL_Event& event);
|
||||
virtual void handle_event(const SDL_Event&) {}
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
virtual void handle_window_event(const SDL_Event& event);
|
||||
#endif
|
||||
|
||||
private:
|
||||
part& p_;
|
||||
|
|
|
@ -356,10 +356,10 @@ void update_whole_screen()
|
|||
update_all = true;
|
||||
}
|
||||
|
||||
|
||||
void CVideo::video_event_handler::handle_event(const SDL_Event &event)
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
void CVideo::video_event_handler::handle_window_event(const SDL_Event &event)
|
||||
{
|
||||
|
||||
if (event.type == SDL_WINDOWEVENT) {
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
|
@ -384,10 +384,8 @@ void CVideo::video_event_handler::handle_event(const SDL_Event &event)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
#else
|
||||
UNUSED(event);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
CVideo::CVideo(FAKE_TYPES type) :
|
||||
|
|
|
@ -243,7 +243,10 @@ private:
|
|||
|
||||
class video_event_handler : public events::sdl_handler {
|
||||
public:
|
||||
virtual void handle_event(const SDL_Event &event);
|
||||
virtual void handle_event(const SDL_Event &) {}
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
virtual void handle_window_event(const SDL_Event &event);
|
||||
#endif
|
||||
video_event_handler() : sdl_handler(false) {}
|
||||
};
|
||||
|
||||
|
|
|
@ -342,15 +342,13 @@ void widget::process_tooltip_string(int mousex, int mousey)
|
|||
}
|
||||
}
|
||||
|
||||
void widget::handle_event(SDL_Event const &event) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
void widget::handle_window_event(SDL_Event const &event) {
|
||||
if (event.type == SDL_WINDOWEVENT) {
|
||||
set_dirty();
|
||||
}
|
||||
#else
|
||||
UNUSED(event);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -89,7 +89,10 @@ protected:
|
|||
const SDL_Rect* clip_rect() const;
|
||||
virtual sdl_handler_vector member_handlers() { return sdl_handler::handler_members(); }
|
||||
|
||||
virtual void handle_event(SDL_Event const &event);
|
||||
virtual void handle_event(SDL_Event const &) {};
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
virtual void handle_window_event(SDL_Event const &event);
|
||||
#endif
|
||||
bool focus_; // Should user input be ignored?
|
||||
|
||||
bool mouse_locked() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue