mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	- vcmi will not crash if building selection area is smaller than def
- detection of transparency on selection area is closer to H3
This commit is contained in:
		| @@ -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) | ||||
| 			{ | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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 | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user