From 51e4856b66fdfb38de0674d1b8adb5254b8840dc Mon Sep 17 00:00:00 2001 From: Dave White Date: Tue, 6 Apr 2004 17:41:08 +0000 Subject: [PATCH] changes to ellipse filenames --- ...se-red-bottom.png => ellipse-1-bottom.png} | Bin 613 -> 614 bytes images/misc/ellipse-1-top.png | Bin 0 -> 626 bytes images/misc/ellipse-red-top.png | Bin 625 -> 0 bytes src/cursor.cpp | 12 +++++++ src/cursor.hpp | 2 ++ src/display.cpp | 27 ++++++++++----- src/events.cpp | 32 ++++++++++++------ 7 files changed, 55 insertions(+), 18 deletions(-) rename images/misc/{ellipse-red-bottom.png => ellipse-1-bottom.png} (62%) create mode 100644 images/misc/ellipse-1-top.png delete mode 100644 images/misc/ellipse-red-top.png 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 cb180aaa345468e48a64e28f512079ba5e66e6aa..dbc2563ca082ffdbd302a1307b34ed7ace1e4ddf 100644 GIT binary patch delta 21 ccmaFL@{EP2Gr-TCmrII^fq{W{BX<-N06@0{t^fc4 delta 20 bcmaFH@|1WFU8GbZ8({Xk{QrNlj4iWF>9@00GuXL_t(|+NIRLY86os z$MMhHdo4_&B(YKuA>yBuHZi7D@C5?CfR$h=7B*sIAyy(-`2u+aK?{rcr%4(AU_dOa zl8D~KfZ073doC=?ZcO6BFgwGZGxOc~of8iEBm%S9rZJUmGF5)MmY>Yaeqa+D*of+V zlpEz&u^Obq^c4pHIDyNU$Cbofa2y4GVVKwowiDYJs^THG@;2j%35;VR7)y*rj&ThA z#LwV8-rz0XVLko_C^5h-%q13rnM8?i!54hQCw#?jwWQU$>bBVcXK)@D5@&Hb=q1*I zWfkbNsA~QjC^3WExS9XhO5$_yA2kTvZ)|$9Nc7){(27OqEur zf+f7bpDd-K1*R=7JHWbtdM#7wcR=(THoy^FPu##}Fdux6#Hqw`R3F{Xw@w|T3DpL< z7g%Zl#Xdpm&3DCve1kqn>;?;wc%q`btGbVgUVttxL_GK+s=6yzc?_`F>ze-l%oS$DuHvj+t M07*qoM6N<$f_ys(wg3PC literal 0 HcmV?d00001 diff --git a/images/misc/ellipse-red-top.png b/images/misc/ellipse-red-top.png deleted file mode 100644 index ec67e0dd974ebe28f49363db3226ae5a6f2aa6f5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 625 zcmV-%0*?KOP)$u~HBr;-8c@F{V`T1p>Z+m0&3rHezETRw7vW0(k^M3yb)tNg4lOKrF11 zh~C72**z9}E-cG#Oya^YJHwtc^WFKK6At+#0<+nsF_mpHRerjbpUlgCU=thIi0XZm z8|7EA8l=PY6$bz~fyR1aSZ*$ z&)_}Y;4R)^J^lwMF~BX%B^H92M2T;~7ktDge8q0Hq}96Ww%Gt@a2^*DXK^~{CDwvv z73j05YW^E2F@xKCMXn`pjP~`!EdJ33+3sk?BpTadHeVRq~Wi40ceMWolWQN7RN><>UpI=8e00000 LNkvXXu0mjfQN#(O 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) {