Ver Fonte

Use CSDL_Ext blit for paletted sprites, use SDL blit otherwise.
* No solution found to blit paletted images with alpha channel with SDL

AlexVinS há 9 anos atrás
pai
commit
f32097339c
2 ficheiros alterados com 16 adições e 3 exclusões
  1. 15 3
      client/gui/CAnimation.cpp
  2. 1 0
      client/gui/CAnimation.h

+ 15 - 3
client/gui/CAnimation.cpp

@@ -269,7 +269,7 @@ void CDefFile::loadFrame(size_t frame, size_t group, ImageLoader &loader) const
 
 					if (code==7)//Raw data
 					{
-						loader.Load(length, FDef[currentOffset]);
+						loader.Load(length, FDef + currentOffset);
 						currentOffset += length;
 					}
 					else//RLE
@@ -631,7 +631,7 @@ SDLImage::SDLImage(std::string filename, bool compressed):
 	}
 }
 
-void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 rotation) const
+void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alpha) const
 {
 	if (!surf)
 		return;
@@ -645,7 +645,19 @@ void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 rotat
 	Rect destRect(posX, posY, surf->w, surf->h);
 	destRect += sourceRect.topLeft();
 	sourceRect -= margins;
-	CSDL_Ext::blitSurface(surf, &sourceRect, where, &destRect);
+
+	if(surf->format->palette)
+	{
+		CSDL_Ext::blit8bppAlphaTo24bpp(surf, &sourceRect, where, &destRect);
+	}
+	if(surf->format->Amask == 0)
+		SDL_BlitSurface(surf, &sourceRect, where, &destRect);
+	else
+	{
+		SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_BLEND);
+		SDL_BlitSurface(surf, &sourceRect, where, &destRect);
+		SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE);
+	}
 }
 
 void SDLImage::playerColored(PlayerColor player)

+ 1 - 0
client/gui/CAnimation.h

@@ -99,6 +99,7 @@ public:
 	~SDLImage();
 
 	void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=nullptr,  ui8 alpha=255) const override;
+
 	void playerColored(PlayerColor player) override;
 	int width() const override;
 	int height() const override;