浏览代码

- vcmi will not crash if building selection area is smaller than def
- detection of transparency on selection area is closer to H3

Ivan Savenko 12 年之前
父节点
当前提交
655ade9a00
共有 3 个文件被更改,包括 11 次插入10 次删除
  1. 1 1
      client/CCastleInterface.cpp
  2. 10 8
      client/UIFramework/SDL_Extensions.cpp
  3. 0 1
      client/UIFramework/SDL_Extensions.h

+ 1 - 1
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)
 			{

+ 10 - 8
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)

+ 0 - 1
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