diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index 53ce6fe93..8327ea11a 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -223,7 +223,7 @@ void CBuildingRect::mouseMoved (const SDL_MouseMotionEvent & sEvent) { if(area && isItIn(&pos,sEvent.x, sEvent.y)) { - if(CSDL_Ext::SDL_GetPixel(area,sEvent.x-pos.x,sEvent.y-pos.y) == 0) //hovered pixel is inside this building + if(CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y)) //hovered pixel is inside this building { if(parent->selectedBuilding == this) { diff --git a/client/UIFramework/SDL_Extensions.cpp b/client/UIFramework/SDL_Extensions.cpp index e4abea733..fe6a648c9 100644 --- a/client/UIFramework/SDL_Extensions.cpp +++ b/client/UIFramework/SDL_Extensions.cpp @@ -652,15 +652,17 @@ bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y ) if (x < 0 || y < 0 || x >= srf->w || y >= srf->h) return true; - if(srf->format->BytesPerPixel == 1) - { - return ((ui8*)srf->pixels)[x + srf->pitch * y] == 0; - } + SDL_Color color; + + SDL_GetRGBA(SDL_GetPixel(srf, x, y), srf->format, &color.r, &color.g, &color.b, &color.unused); + + // color is considered transparent here if + // a) image has aplha: less than 50% transparency + // b) no alpha: color is cyan + if (srf->format->Amask) + return color.unused < 128; // almost transparent else - { - assert(!"isTransparent called with non-8bpp surface!"); - } - return false; + return (color.r == 0 && color.g == 255 && color.b == 255); } void CSDL_Ext::VflipSurf(SDL_Surface * surf) diff --git a/client/UIFramework/SDL_Extensions.h b/client/UIFramework/SDL_Extensions.h index 9eed46023..93244d3a9 100644 --- a/client/UIFramework/SDL_Extensions.h +++ b/client/UIFramework/SDL_Extensions.h @@ -143,7 +143,6 @@ namespace CSDL_Ext SDL_Surface * rotate03(SDL_Surface * toRot); //rotate 180 degrees SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy); //creates cursor from bitmap Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false); - SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y); //returns color of pixel at given position void alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details) bool isTransparent(SDL_Surface * srf, int x, int y); //checks if surface is transparent at given position