Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wesnoth/wesnoth
Browse files Browse the repository at this point in the history
  • Loading branch information
ln-zookeeper committed Aug 17, 2014
2 parents a7f17cd + 15a654c commit 9e4e547
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/display.cpp
Expand Up @@ -1404,7 +1404,11 @@ void display::flip()

cursor::undraw(frameBuffer);
events::raise_volatile_undraw_event();
#ifdef SDL_GPU
font::undraw_floating_labels(screen_);
#else
font::undraw_floating_labels(frameBuffer);
#endif
}

void display::update_display()
Expand Down
40 changes: 34 additions & 6 deletions src/font.cpp
Expand Up @@ -1124,6 +1124,7 @@ void floating_label::draw(CVideo &video)
video.blit_to_overlay(surf_, xpos(surf_->w), int(ypos_));
#endif
}

#else
void floating_label::draw(surface screen)
{
Expand Down Expand Up @@ -1157,9 +1158,12 @@ void floating_label::draw(surface screen)
}
#endif

#if 0
// No undrawing for SDL_gpu, it won't be necessary once z-order is implemented
void floating_label::undraw(surface) {}
#ifdef SDL_GPU
void floating_label::undraw(CVideo &video)
{
SDL_Rect r = sdl::create_rect(xpos(surf_->w), ypos_, surf_->w, surf_->h);
video.clear_overlay_area(r);
}
#else
void floating_label::undraw(surface screen)
{
Expand Down Expand Up @@ -1281,6 +1285,9 @@ floating_label_context::~floating_label_context()

label_contexts.pop();

#ifdef SDL_GPU
//TODO
#else
#if SDL_VERSION_ATLEAST(2, 0, 0)
surface const screen = NULL;
#else
Expand All @@ -1289,6 +1296,7 @@ floating_label_context::~floating_label_context()
if(screen != NULL) {
undraw_floating_labels(screen);
}
#endif
}

#ifdef SDL_GPU
Expand All @@ -1308,6 +1316,27 @@ void draw_floating_labels(CVideo &video)
}
}
}

void undraw_floating_labels(CVideo &video)
{
if(label_contexts.empty()) {
return;
}

std::set<int>& context = label_contexts.top();

//remove expired labels
for(label_map::iterator j = labels.begin(); j != labels.end(); ) {
if(context.count(j->first) > 0 && j->second.expired()) {
j->second.undraw(video);
context.erase(j->first);
labels.erase(j++);
} else {
++j;
}
}
}

#else
void draw_floating_labels(surface screen)
{
Expand All @@ -1325,7 +1354,6 @@ void draw_floating_labels(surface screen)
}
}
}
#endif

void undraw_floating_labels(surface screen)
{
Expand All @@ -1338,7 +1366,7 @@ void undraw_floating_labels(surface screen)
//undraw labels in reverse order, so that a LIFO process occurs, and the screen is restored
//into the exact state it started in.
for(label_map::reverse_iterator i = labels.rbegin(); i != labels.rend(); ++i) {
if(context.count(i->first) > 0) {
if(context.count(i->first) > 0) {
i->second.undraw(screen);
}
}
Expand All @@ -1353,7 +1381,7 @@ void undraw_floating_labels(surface screen)
}
}
}

#endif
}

static bool add_font_to_fontlist(const config &fonts_config,
Expand Down
7 changes: 4 additions & 3 deletions src/font.hpp
Expand Up @@ -156,10 +156,11 @@ class floating_label
void move(double xmove, double ymove);
#ifdef SDL_GPU
void draw(CVideo &video);
void undraw(CVideo &video);
#else
void draw(surface screen);
#endif
void undraw(surface screen);
#endif

#if 0
sdl::timage create_image();
Expand Down Expand Up @@ -219,11 +220,11 @@ void show_floating_label(int handle, bool show);
SDL_Rect get_floating_label_rect(int handle);
#ifdef SDL_GPU
void draw_floating_labels(CVideo &video);
void undraw_floating_labels(CVideo &video);
#else
void draw_floating_labels(surface screen);
#endif

void undraw_floating_labels(surface screen);
#endif

bool load_font_config();

Expand Down
8 changes: 8 additions & 0 deletions src/gui/widgets/window.cpp
Expand Up @@ -680,7 +680,11 @@ int twindow::show(const bool restore, const unsigned auto_close_timeout)
SDL_Rect rect = get_rectangle();
sdl_blit(restorer_, 0, video_.getSurface(), &rect);
update_rect(get_rectangle());
#ifdef SDL_GPU
font::undraw_floating_labels(video_);
#else
font::undraw_floating_labels(video_.getSurface());
#endif
}
throw;
}
Expand All @@ -692,7 +696,11 @@ int twindow::show(const bool restore, const unsigned auto_close_timeout)
SDL_Rect rect = get_rectangle();
sdl_blit(restorer_, 0, video_.getSurface(), &rect);
update_rect(get_rectangle());
#ifdef SDL_GPU
font::undraw_floating_labels(video_);
#else
font::undraw_floating_labels(video_.getSurface());
#endif
}

return retval_;
Expand Down
10 changes: 8 additions & 2 deletions src/video.cpp
Expand Up @@ -435,8 +435,14 @@ void CVideo::blit_to_overlay(surface surf, int x, int y)

void CVideo::clear_overlay_area(SDL_Rect area)
{
//TODO: proper implementation
sdl::fill_rect(overlay_, &area, 0xFF000000);
const Uint32 color = SDL_MapRGBA(overlay_->format, 0, 0, 0, 0);
Uint32 *pixels = static_cast<Uint32*>(overlay_->pixels);
for (int x = area.x; x<area.x + area.w; ++x) {
for (int y = area.y; y<area.y +area.h; ++y) {
const int index = y * (area.w + overlay_->pitch) + x;
pixels[index] = color;
}
}
}

void CVideo::clear_overlay()
Expand Down

0 comments on commit 9e4e547

Please sign in to comment.