mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
centralize key color management
This commit is contained in:
parent
082c9a506e
commit
638dac90af
@ -294,7 +294,7 @@ void CResDataBar::clickRight(tribool down, bool previousState)
|
|||||||
CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
|
CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
|
||||||
{
|
{
|
||||||
bg = BitmapHandler::loadBitmap(defname);
|
bg = BitmapHandler::loadBitmap(defname);
|
||||||
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
|
CSDL_Ext::setDefaultColorKey(bg);
|
||||||
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
|
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
|
||||||
pos = genRect(bg->h, bg->w, pos.x+x, pos.y+y);
|
pos = genRect(bg->h, bg->w, pos.x+x, pos.y+y);
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int
|
|||||||
CResDataBar::CResDataBar()
|
CResDataBar::CResDataBar()
|
||||||
{
|
{
|
||||||
bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
|
bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
|
||||||
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
|
CSDL_Ext::setDefaultColorKey(bg);
|
||||||
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
|
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
|
||||||
pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
|
pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
|
||||||
|
|
||||||
|
@ -639,9 +639,7 @@ SDLImage::SDLImage(std::string filename, bool compressed):
|
|||||||
#else
|
#else
|
||||||
if (surf->format->palette)
|
if (surf->format->palette)
|
||||||
{
|
{
|
||||||
const SDL_Color &c = temp->format->palette->colors[0];
|
CSDL_Ext::setColorKey(temp,temp->format->palette->colors[0]);
|
||||||
uint32_t key = SDL_MapRGBA(temp -> format, c.r, c.g, c.b,c.a);
|
|
||||||
SDL_SetColorKey(temp, SDL_TRUE, key);
|
|
||||||
}
|
}
|
||||||
SDL_SetSurfaceRLE(temp, SDL_RLEACCEL);
|
SDL_SetSurfaceRLE(temp, SDL_RLEACCEL);
|
||||||
#endif
|
#endif
|
||||||
|
@ -121,14 +121,7 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
|
|||||||
{
|
{
|
||||||
if(ret->format->BytesPerPixel == 1 && setKey)
|
if(ret->format->BytesPerPixel == 1 && setKey)
|
||||||
{
|
{
|
||||||
const SDL_Color &c = ret->format->palette->colors[0];
|
CSDL_Ext::setColorKey(ret,ret->format->palette->colors[0]);
|
||||||
#ifdef VCMI_SDL1
|
|
||||||
uint32_t key = SDL_MapRGB(ret->format, c.r, c.g, c.b);
|
|
||||||
#else
|
|
||||||
uint32_t key = SDL_MapRGBA(ret->format, c.r, c.g, c.b, c.a);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -160,7 +153,7 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When modifyin anything here please check two use cases:
|
// When modifying anything here please check two use cases:
|
||||||
// 1) Vampire mansion in Necropolis (not 1st color is transparent)
|
// 1) Vampire mansion in Necropolis (not 1st color is transparent)
|
||||||
// 2) Battle background when fighting on grass/dirt, topmost sky part (NO transparent color)
|
// 2) Battle background when fighting on grass/dirt, topmost sky part (NO transparent color)
|
||||||
// 3) New objects that may use 24-bit images for icons (e.g. witchking arts)
|
// 3) New objects that may use 24-bit images for icons (e.g. witchking arts)
|
||||||
@ -176,7 +169,7 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
|
|||||||
}
|
}
|
||||||
else // always set
|
else // always set
|
||||||
{
|
{
|
||||||
SDL_SetColorKey(ret, SDL_SRCCOLORKEY, colorID);
|
CSDL_Ext::setDefaultColorKey(ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -363,13 +363,8 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
|
|||||||
{
|
{
|
||||||
idToObstacle[ID] = CDefHandler::giveDef(elem->getInfo().defName);
|
idToObstacle[ID] = CDefHandler::giveDef(elem->getInfo().defName);
|
||||||
for(auto & _n : idToObstacle[ID]->ourImages)
|
for(auto & _n : idToObstacle[ID]->ourImages)
|
||||||
{
|
{
|
||||||
#ifdef VCMI_SDL1
|
CSDL_Ext::setDefaultColorKey(_n.bitmap);
|
||||||
uint32_t key = SDL_MapRGB(_n.bitmap->format, 0, 255, 255);
|
|
||||||
#else
|
|
||||||
uint32_t key = SDL_MapRGBA(_n.bitmap->format, 0, 255, 255, 0);
|
|
||||||
#endif
|
|
||||||
SDL_SetColorKey(_n.bitmap, SDL_SRCCOLORKEY, key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(elem->obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE)
|
else if(elem->obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE)
|
||||||
|
@ -13,6 +13,7 @@ const SDL_Color Colors::YELLOW = { 229, 215, 123, 0 };
|
|||||||
const SDL_Color Colors::WHITE = { 255, 243, 222, 0 };
|
const SDL_Color Colors::WHITE = { 255, 243, 222, 0 };
|
||||||
const SDL_Color Colors::METALLIC_GOLD = { 173, 142, 66, 0 };
|
const SDL_Color Colors::METALLIC_GOLD = { 173, 142, 66, 0 };
|
||||||
const SDL_Color Colors::GREEN = { 0, 255, 0, 0 };
|
const SDL_Color Colors::GREEN = { 0, 255, 0, 0 };
|
||||||
|
const SDL_Color Colors::DEFAULT_KEY_COLOR = {0, 255, 255, 0};
|
||||||
|
|
||||||
#if (SDL_MAJOR_VERSION == 2)
|
#if (SDL_MAJOR_VERSION == 2)
|
||||||
void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h)
|
void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h)
|
||||||
@ -1004,6 +1005,36 @@ void CSDL_Ext::stopTextInput()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color)
|
||||||
|
{
|
||||||
|
#ifdef VCMI_SDL1
|
||||||
|
return SDL_MapRGB(surface->format, color.r, color.g, color.b);
|
||||||
|
#else
|
||||||
|
return SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSDL_Ext::setColorKey(SDL_Surface * surface, SDL_Color color)
|
||||||
|
{
|
||||||
|
uint32_t key = mapColor(surface,color);
|
||||||
|
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSDL_Ext::setDefaultColorKey(SDL_Surface * surface)
|
||||||
|
{
|
||||||
|
setColorKey(surface, Colors::DEFAULT_KEY_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSDL_Ext::setDefaultColorKeyPresize(SDL_Surface * surface)
|
||||||
|
{
|
||||||
|
uint32_t key = mapColor(surface,Colors::DEFAULT_KEY_COLOR);
|
||||||
|
auto & color = surface->format->palette->colors[key];
|
||||||
|
|
||||||
|
// set color key only if exactly such color was found
|
||||||
|
if (color.r == Colors::DEFAULT_KEY_COLOR.r && color.g == Colors::DEFAULT_KEY_COLOR.g && color.b == Colors::DEFAULT_KEY_COLOR.b)
|
||||||
|
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<2>(int, int);
|
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<2>(int, int);
|
||||||
|
@ -128,6 +128,9 @@ public:
|
|||||||
|
|
||||||
/** green color used for in-game console */
|
/** green color used for in-game console */
|
||||||
static const SDL_Color GREEN;
|
static const SDL_Color GREEN;
|
||||||
|
|
||||||
|
/** default key color for all 8 & 24 bit graphics */
|
||||||
|
static const SDL_Color DEFAULT_KEY_COLOR;
|
||||||
};
|
};
|
||||||
|
|
||||||
//MSVC gives an error when calling abs with ui64 -> we add template that will match calls with unsigned arg and return it
|
//MSVC gives an error when calling abs with ui64 -> we add template that will match calls with unsigned arg and return it
|
||||||
@ -266,4 +269,10 @@ namespace CSDL_Ext
|
|||||||
|
|
||||||
void startTextInput(SDL_Rect * where);
|
void startTextInput(SDL_Rect * where);
|
||||||
void stopTextInput();
|
void stopTextInput();
|
||||||
|
|
||||||
|
void setColorKey(SDL_Surface * surface, SDL_Color color);
|
||||||
|
///set key-color to 0,255,255
|
||||||
|
void setDefaultColorKey(SDL_Surface * surface);
|
||||||
|
///set key-color to 0,255,255 only if it exactly mapped
|
||||||
|
void setDefaultColorKeyPresize(SDL_Surface * surface);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user