diff --git a/images/misc/ellipse-red-bottom.png b/images/misc/ellipse-1-bottom.png similarity index 62% rename from images/misc/ellipse-red-bottom.png rename to images/misc/ellipse-1-bottom.png index cb180aaa345..dbc2563ca08 100644 Binary files a/images/misc/ellipse-red-bottom.png and b/images/misc/ellipse-1-bottom.png differ diff --git a/images/misc/ellipse-1-top.png b/images/misc/ellipse-1-top.png new file mode 100644 index 00000000000..5714aaceacc Binary files /dev/null and b/images/misc/ellipse-1-top.png differ diff --git a/images/misc/ellipse-red-top.png b/images/misc/ellipse-red-top.png deleted file mode 100644 index ec67e0dd974..00000000000 Binary files a/images/misc/ellipse-red-top.png and /dev/null differ diff --git a/src/cursor.cpp b/src/cursor.cpp index e60cccfe68e..d9b837c35dd 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -61,6 +61,7 @@ cursor::CURSOR_TYPE current_cursor = cursor::NUM_CURSORS; int cursor_x = -1, cursor_y = -1; SDL_Surface* cursor_buf = NULL; +bool have_focus = true; SDL_Cursor* get_cursor(cursor::CURSOR_TYPE type) { @@ -123,6 +124,11 @@ void set(CURSOR_TYPE type) } } +void set_focus(bool focus) +{ + have_focus = focus; +} + setter::setter(CURSOR_TYPE type) : old_(current_cursor) { set(type); @@ -143,6 +149,12 @@ void draw(SDL_Surface* screen) return; } + if(have_focus == NULL) { + SDL_FreeSurface(cursor_buf); + cursor_buf = NULL; + return; + } + int new_cursor_x, new_cursor_y; SDL_GetMouseState(&new_cursor_x,&new_cursor_y); diff --git a/src/cursor.hpp b/src/cursor.hpp index fd7c89a5a8d..84d2441b247 100644 --- a/src/cursor.hpp +++ b/src/cursor.hpp @@ -21,6 +21,8 @@ void set(CURSOR_TYPE type); void draw(SDL_Surface* screen); void undraw(SDL_Surface* screen); +void set_focus(bool focus); + struct setter { setter(CURSOR_TYPE type); diff --git a/src/display.cpp b/src/display.cpp index ccea138b9b3..c52ec266651 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1185,11 +1185,16 @@ void display::draw_unit_on_tile(int x, int y, SDL_Surface* unit_image_override, if(loc != hiddenUnit_) { //the circle around the base of the unit if(preferences::show_side_colours() && !fogged(x,y) && it != units_.end()) { - const SDL_Color& col = font::get_side_colour(it->second.side()); - const Uint16 colour = SDL_MapRGB(dst->format,col.r,col.g,col.b); - SDL_Rect clip = {xpos,ypos,unit_image->w,unit_image->h}; + char buf[50]; + sprintf(buf,"misc/ellipse-%d-top.png",it->second.side()); + const scoped_sdl_surface surf(image::get_image(buf)); - draw_unit_ellipse(dst,colour,energy_uses_alpha ? Uint8(highlight_ratio*255) : SDL_ALPHA_OPAQUE,clip,xpos,ypos-height_adjust,unit_image,!face_left,ELLIPSE_TOP); + if(surf != NULL) { + SDL_Surface* const dst = screen_.getSurface(); + SDL_Rect rect = {xpos,ypos - height_adjust,surf->w,surf->h}; + + SDL_BlitSurface(surf,NULL,dst,&rect); + } } draw_unit(xpos,ypos - height_adjust,unit_image,face_left,false, @@ -1224,11 +1229,17 @@ void display::draw_unit_on_tile(int x, int y, SDL_Surface* unit_image_override, //the bottom half of the circle around the base of the unit if(loc != hiddenUnit_ && preferences::show_side_colours() && !fogged(x,y) && it != units_.end()) { - const SDL_Color& col = font::get_side_colour(it->second.side()); - const Uint16 colour = SDL_MapRGB(dst->format,col.r,col.g,col.b); - SDL_Rect clip = {xpos,ypos,unit_image->w,unit_image->h}; - draw_unit_ellipse(dst,colour,energy_uses_alpha ? Uint8(highlight_ratio*255) : SDL_ALPHA_OPAQUE,clip,xpos,ypos-height_adjust,unit_image,!face_left,ELLIPSE_BOTTOM); + char buf[50]; + sprintf(buf,"misc/ellipse-%d-bottom.png",it->second.side()); + const scoped_sdl_surface surf(image::get_image(buf)); + + if(surf != NULL) { + SDL_Surface* const dst = screen_.getSurface(); + SDL_Rect rect = {xpos,ypos - height_adjust,surf->w,surf->h}; + + SDL_BlitSurface(surf,NULL,dst,&rect); + } } } diff --git a/src/events.cpp b/src/events.cpp index 00d94a054cd..bd7d3061c28 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -1,3 +1,4 @@ +#include "cursor.hpp" #include "events.hpp" #include "mouse.hpp" #include "preferences.hpp" @@ -89,18 +90,18 @@ void pump() SDL_Event event; while(SDL_PollEvent(&event)) { - if(event_contexts.empty() == false) { - - const std::vector& event_handlers = event_contexts.top(); - - //events may cause more event handlers to be added and/or removed, - //so we must use indexes instead of iterators here. - for(size_t i1 = 0, i2 = event_handlers.size(); i1 != i2 && i1 < event_handlers.size(); ++i1) { - event_handlers[i1]->handle_event(event); - } - } switch(event.type) { + + case SDL_APPMOUSEFOCUS: { + SDL_ActiveEvent& ae = reinterpret_cast(event); + if(ae.state == SDL_APPMOUSEFOCUS) { + cursor::set_focus(ae.gain == 1); + } + break; + } + + //if the window must be redrawn, update the entire screen case SDL_VIDEOEXPOSE: { update_whole_screen(); break; @@ -157,6 +158,17 @@ void pump() throw CVideo::quit(); } } + + if(event_contexts.empty() == false) { + + const std::vector& event_handlers = event_contexts.top(); + + //events may cause more event handlers to be added and/or removed, + //so we must use indexes instead of iterators here. + for(size_t i1 = 0, i2 = event_handlers.size(); i1 != i2 && i1 < event_handlers.size(); ++i1) { + event_handlers[i1]->handle_event(event); + } + } } if(resize_dimensions.first > 0 && disallow_resize == 0) {