Skip to content

Commit

Permalink
Make storyscreen respect draw-all events
Browse files Browse the repository at this point in the history
The storyscreen now marks itself as dirty on a draw-all event and
redraws itself. There's also some code cleanup in here.
  • Loading branch information
aginor committed Feb 24, 2016
1 parent 7565ae0 commit d00e207
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/display.cpp
Expand Up @@ -883,6 +883,7 @@ void display::layout_buttons()
if (s) {
const SDL_Rect& loc = i->location(screen_area());
s->set_location(loc);
s->set_measurements(0,0);
s->set_volatile(
sdl::rects_overlap(s->location(),map_outside_area()));
}
Expand All @@ -895,6 +896,7 @@ void display::layout_buttons()
if(b) {
const SDL_Rect& loc = i->location(screen_area());
b->set_location(loc);
b->set_measurements(0,0);
b->set_label(i->title());
b->set_volatile(
sdl::rects_overlap(b->location(),map_outside_area()));
Expand All @@ -908,6 +910,7 @@ void display::layout_buttons()
if(b) {
const SDL_Rect& loc = i->location(screen_area());
b->set_location(loc);
b->set_measurements(0,0);
b->set_label(i->title());
b->set_volatile(
sdl::rects_overlap(b->location(),map_outside_area()));
Expand Down
13 changes: 6 additions & 7 deletions src/events.cpp
Expand Up @@ -443,7 +443,7 @@ void pump()
}
//make sure this runs in it's own scope.
{
for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); i++) {
for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); ++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);
Expand Down Expand Up @@ -512,11 +512,10 @@ void pump()
case DRAW_ALL_EVENT:
{
/* iterate backwards as the most recent things will be at the top */
for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); i++) {
for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); ++i) {
const std::vector<sdl_handler*>& event_handlers = (*i).handlers;
for( std::vector<sdl_handler*>::const_iterator i1 = event_handlers.begin(); i1 != event_handlers.end(); i1++) {
for( std::vector<sdl_handler*>::const_iterator i1 = event_handlers.begin(); i1 != event_handlers.end(); ++i1) {
(*i1)->handle_event(event);
//event_handlers[i1]->draw();
}
}
continue; //do not do further handling here
Expand Down Expand Up @@ -610,7 +609,7 @@ void raise_draw_event()

void raise_draw_all_event()
{
for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); i++) {
for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); ++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();
Expand All @@ -634,7 +633,7 @@ void raise_volatile_draw_event()

void raise_volatile_draw_all_event()
{
for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); i++) {
for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); ++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();
Expand Down Expand Up @@ -696,7 +695,7 @@ void peek_for_resize()
{
SDL_Event events[100];
int num = SDL_PeepEvents(events, 100, SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT);
for (int i = 0; i < num; i++) {
for (int i = 0; i < num; ++i) {
if (events[i].type == SDL_WINDOWEVENT &&
events[i].window.event == SDL_WINDOWEVENT_RESIZED) {
CVideo::get_singleton().update_framebuffer();
Expand Down
9 changes: 9 additions & 0 deletions src/storyscreen/render.cpp
Expand Up @@ -1000,6 +1000,15 @@ part_ui::RESULT part_ui::show()
return ret_;
}

void part_ui::handle_event(const SDL_Event &event)
{
if (event.type == DRAW_ALL_EVENT) {
dirty_ = true;
draw();
}

}

#if SDL_VERSION_ATLEAST(2, 0, 0)
void part_ui::handle_window_event(const SDL_Event &event)
{
Expand Down
3 changes: 2 additions & 1 deletion src/storyscreen/render.hpp
Expand Up @@ -65,7 +65,8 @@ class part_ui : public video2::draw_layering
*/
RESULT show();

virtual void handle_event(const SDL_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
Expand Down
2 changes: 1 addition & 1 deletion src/video.cpp
Expand Up @@ -270,7 +270,7 @@ draw_layering::~draw_layering()
event.window.data1 = (*frameBuffer).h;
event.window.data2 = (*frameBuffer).w;

for(std::list<events::sdl_handler*>::iterator it = draw_layers.begin(); it != draw_layers.end(); it++) {
for(std::list<events::sdl_handler*>::iterator it = draw_layers.begin(); it != draw_layers.end(); ++it) {
(*it)->handle_window_event(event);
}
#endif
Expand Down

3 comments on commit d00e207

@CelticMinstrel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see the point of changing from postincrement to preincrement, unless it produces a noticeable speed difference? (Postincrement is theoretically slower since it involves a copy, but I'd expect a copy in this situation to be pretty fast.)

@aginor
Copy link
Contributor Author

@aginor aginor commented on d00e207 Feb 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to use the same style as in other parts of Wesnoth.

@CelticMinstrel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, there really wasn't a point to it.

Please sign in to comment.