diff --git a/src/common/gfx.cpp b/src/common/gfx.cpp index 6b1700ed..f41b7344 100644 --- a/src/common/gfx.cpp +++ b/src/common/gfx.cpp @@ -270,7 +270,7 @@ bool gfx_loadfullskin(gfxSprite ** gSprites, const std::string& filename, const return true; } -SDL_Surface * gfx_createteamcoloredsurface(SDL_Surface * sImage, short iColor, const RGBA& rgba) +SDL_Surface * gfx_createteamcoloredsurface(SDL_Surface * sImage, short iColor, const RGB& key, Uint8 alpha) { SDL_Surface * sTempImage = SDL_CreateRGBSurface(sImage->flags, iColor == -2 ? sImage->w << 2 : sImage->w, iColor == -1 ? sImage->h << 2 : sImage->h, sImage->format->BitsPerPixel, sImage->format->Rmask, sImage->format->Gmask, sImage->format->Bmask, sImage->format->Amask); @@ -356,13 +356,13 @@ SDL_Surface * gfx_createteamcoloredsurface(SDL_Surface * sImage, short iColor, c SDL_UnlockSurface(sImage); SDL_UnlockSurface(sTempImage); - if ( SDL_SETCOLORKEY(sTempImage, SDL_TRUE, SDL_MapRGB(sTempImage->format, rgba.r, rgba.g, rgba.b)) < 0 ) { + if ( SDL_SETCOLORKEY(sTempImage, SDL_TRUE, SDL_MapRGB(sTempImage->format, key.r, key.g, key.b)) < 0 ) { printf("\n ERROR: Couldn't set ColorKey + RLE for new team colored surface: %s\n", SDL_GetError()); return NULL; } - if (rgba.a < 255) { - if (SDL_SETALPHABYTE(sTempImage, SDL_TRUE, rgba.a) < 0) { + if (alpha < 255) { + if (SDL_SETALPHABYTE(sTempImage, SDL_TRUE, alpha) < 0) { cout << endl << " ERROR: Couldn't set per-surface alpha: " << SDL_GetError() << endl; return NULL; } @@ -393,7 +393,7 @@ bool gfx_loadteamcoloredimage(gfxSprite ** gSprites, const std::string& filename } for (short k = 0; k < 4; k++) { - SDL_Surface * sTeamColoredSurface = gfx_createteamcoloredsurface(sImage, k, rgb.withAlpha(a)); + SDL_Surface * sTeamColoredSurface = gfx_createteamcoloredsurface(sImage, k, rgb, a); if (sTeamColoredSurface == NULL) { cout << endl << " ERROR: Couldn't create menu skin from " << filename << ": " << SDL_GetError() << endl; @@ -411,7 +411,7 @@ bool gfx_loadteamcoloredimage(gfxSprite ** gSprites, const std::string& filename return true; } -bool gfx_loadteamcoloredimage(gfxSprite * gSprites, const std::string& filename, const RGBA& rgba, bool fVertical, bool fWrap) +bool gfx_loadteamcoloredimage(gfxSprite * gSprites, const std::string& filename, const RGB& rgb, Uint8 a, bool fVertical, bool fWrap) { //Load the image into a surface SDL_Surface * sImage = IMG_Load(filename.c_str()); @@ -421,7 +421,7 @@ bool gfx_loadteamcoloredimage(gfxSprite * gSprites, const std::string& filename, return false; } - SDL_Surface * sTeamColoredSurface = gfx_createteamcoloredsurface(sImage, fVertical ? -1 : -2, rgba); + SDL_Surface * sTeamColoredSurface = gfx_createteamcoloredsurface(sImage, fVertical ? -1 : -2, rgb, a); if (sTeamColoredSurface == NULL) { cout << endl << " ERROR: Couldn't create menu skin from " << filename << ": " << SDL_GetError() << endl; @@ -580,12 +580,12 @@ void gfx_drawpreview( bool gfx_loadteamcoloredimage(gfxSprite* sprites, const std::string& path, bool fVertical, bool fWrap) { - return gfx_loadteamcoloredimage(sprites, path, colors::MAGENTA.withAlpha(255), fVertical, fWrap); + return gfx_loadteamcoloredimage(sprites, path, colors::MAGENTA, 255, fVertical, fWrap); } bool gfx_loadteamcoloredimage(gfxSprite* sprites, const std::string& path, Uint8 a, bool fVertical, bool fWrap) { - return gfx_loadteamcoloredimage(sprites, path, colors::MAGENTA.withAlpha(a), fVertical, fWrap); + return gfx_loadteamcoloredimage(sprites, path, colors::MAGENTA, a, fVertical, fWrap); } bool gfx_loadimagenocolorkey(gfxSprite* sprite, const std::string& path) @@ -600,7 +600,7 @@ bool gfx_loadimage(gfxSprite& gSprite, const std::string& path, bool fWrap) bool gfx_loadimage(gfxSprite& gSprite, const std::string& path, Uint8 alpha, bool fWrap) { - bool success = gSprite.init(path, colors::MAGENTA.withAlpha(alpha)); + bool success = gSprite.init(path, colors::MAGENTA, alpha); if (success) gSprite.SetWrap(fWrap); diff --git a/src/common/gfx.h b/src/common/gfx.h index db036bdb..938ddfbc 100644 --- a/src/common/gfx.h +++ b/src/common/gfx.h @@ -58,7 +58,7 @@ void gfx_drawpreview(SDL_Surface * surface, short dstX, short dstY, short srcX, bool gfx_loadfullskin(gfxSprite ** gSprites, const std::string& filename, const RGB& colorkey, short colorScheme); bool gfx_loadmenuskin(gfxSprite ** gSprite, const std::string& filename, const RGB& colorkey, short colorScheme, bool fLoadBothDirections); -bool gfx_loadteamcoloredimage(gfxSprite * gSprites, const std::string& filename, const RGBA& rgba, bool fVertical, bool fWrap); +bool gfx_loadteamcoloredimage(gfxSprite * gSprites, const std::string& filename, const RGB& rgb, Uint8 a, bool fVertical, bool fWrap); //Load image into an array of 4 gfxSprites, each with it's own team color bool gfx_loadteamcoloredimage(gfxSprite ** gSprites, const std::string& filename, const RGB& rgb, Uint8 a, bool fWrap); diff --git a/src/common/gfx/Color.h b/src/common/gfx/Color.h index 55acdce5..856cc4a9 100644 --- a/src/common/gfx/Color.h +++ b/src/common/gfx/Color.h @@ -3,24 +3,11 @@ #include -/// Represents an RGBA color. -struct RGBA { - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t a; -}; - - /// Represents a solid RGB color. struct RGB { uint8_t r; uint8_t g; uint8_t b; - - constexpr RGBA withAlpha(uint8_t a) const { - return RGBA { r, g, b, a }; - } }; diff --git a/src/common/gfx/gfxSprite.cpp b/src/common/gfx/gfxSprite.cpp index 528f317d..3ef3ed6d 100644 --- a/src/common/gfx/gfxSprite.cpp +++ b/src/common/gfx/gfxSprite.cpp @@ -50,7 +50,7 @@ void gfxSprite::freeSurface() // // Color keyed without alpha // -bool gfxSprite::init(const std::string& filename, const RGB& rgb) +bool gfxSprite::init(const std::string& filename, const RGB& key) { cout << "loading sprite (mode 1) " << filename << "..."; @@ -66,7 +66,7 @@ bool gfxSprite::init(const std::string& filename, const RGB& rgb) return false; } - if ( SDL_SETCOLORKEY(m_picture, SDL_TRUE, SDL_MapRGB(m_picture->format, rgb.r, rgb.g, rgb.b)) < 0) { + if ( SDL_SETCOLORKEY(m_picture, SDL_TRUE, SDL_MapRGB(m_picture->format, key.r, key.g, key.b)) < 0) { cout << endl << " ERROR: Couldn't set ColorKey + RLE for " << filename << ": " << SDL_GetError() << endl; return false; @@ -98,7 +98,7 @@ bool gfxSprite::init(const std::string& filename, const RGB& rgb) // // Color keyed + alpha // -bool gfxSprite::init(const std::string& filename, const RGBA& rgba) +bool gfxSprite::init(const std::string& filename, const RGB& key, Uint8 alpha) { cout << "Loading sprite (mode 2) " << filename << " ..."; @@ -115,13 +115,13 @@ bool gfxSprite::init(const std::string& filename, const RGBA& rgba) return false; } - if ( SDL_SETCOLORKEY(m_picture, SDL_TRUE, SDL_MapRGB(m_picture->format, rgba.r, rgba.g, rgba.b)) < 0) { + if ( SDL_SETCOLORKEY(m_picture, SDL_TRUE, SDL_MapRGB(m_picture->format, key.r, key.g, key.b)) < 0) { cout << endl << " ERROR: Couldn't set ColorKey + RLE for " << filename << ": " << SDL_GetError() << endl; return false; } - if ( (SDL_SETALPHABYTE(m_picture, SDL_TRUE, rgba.a)) < 0) { + if ( (SDL_SETALPHABYTE(m_picture, SDL_TRUE, alpha)) < 0) { cout << endl << " ERROR: Couldn't set per-surface alpha on " << filename << ": " << SDL_GetError() << endl; return false; diff --git a/src/common/gfx/gfxSprite.h b/src/common/gfx/gfxSprite.h index 9bd2fb21..4fa99bcb 100644 --- a/src/common/gfx/gfxSprite.h +++ b/src/common/gfx/gfxSprite.h @@ -14,10 +14,9 @@ class gfxSprite { void freeSurface(); void clearSurface(); - bool init(const std::string& filename, const RGB& rgb); //color keyed - bool init(const std::string& filename, const RGBA& rgba); //color keyed + alpha bool init(const std::string& filename); //non color keyed - bool initskin(const std::string& filename, const RGB& rgb, short colorscheme, bool expand); + bool init(const std::string& filename, const RGB& key); //color keyed + bool init(const std::string& filename, const RGB& key, Uint8 alpha); //color keyed + alpha bool draw(short x, short y); bool draw(short x, short y, short srcx, short srcy, short w, short h, short iHiddenDirection = -1, short iHiddenValue = -1); diff --git a/src/leveleditor/leveleditor.cpp b/src/leveleditor/leveleditor.cpp index a6f23408..6a7cb28f 100644 --- a/src/leveleditor/leveleditor.cpp +++ b/src/leveleditor/leveleditor.cpp @@ -456,7 +456,7 @@ int main(int argc, char *argv[]) printf("\n---------------- loading graphics ----------------\n"); rm->spr_tiletypes.init(convertPath("gfx/leveleditor/leveleditor_tile_types.png")); - rm->spr_transparenttiles.init(convertPath("gfx/leveleditor/leveleditor_transparent_tiles.png"), colors::MAGENTA.withAlpha(160)); + rm->spr_transparenttiles.init(convertPath("gfx/leveleditor/leveleditor_transparent_tiles.png"), colors::MAGENTA, 160); rm->spr_backgroundlevel.init(convertPath("gfx/leveleditor/leveleditor_background_levels.png"), colors::MAGENTA); rm->spr_tilesetlevel.init(convertPath("gfx/leveleditor/leveleditor_tileset_levels.png"), colors::MAGENTA); @@ -471,13 +471,13 @@ int main(int argc, char *argv[]) rm->spr_warps[1].init(convertPath("gfx/leveleditor/leveleditor_warp_preview.png"), colors::MAGENTA); rm->spr_warps[2].init(convertPath("gfx/leveleditor/leveleditor_warp_thumbnail.png"), colors::MAGENTA); - rm->spr_platformpath.init(convertPath("gfx/leveleditor/leveleditor_platform_path.png"), colors::MAGENTA.withAlpha(128)); + rm->spr_platformpath.init(convertPath("gfx/leveleditor/leveleditor_platform_path.png"), colors::MAGENTA, 128); - rm->spr_selectedtile.init(convertPath("gfx/leveleditor/leveleditor_selectedtile.png"), colors::BLACK.withAlpha(128)); - rm->spr_nospawntile.init(convertPath("gfx/leveleditor/leveleditor_nospawntile.png"), colors::BLACK.withAlpha(128)); - rm->spr_noitemspawntile.init(convertPath("gfx/leveleditor/leveleditor_noitemspawntile.png"), colors::BLACK.withAlpha(128)); - rm->spr_platformstarttile.init(convertPath("gfx/leveleditor/leveleditor_platformstarttile.png"), colors::BLACK.withAlpha(64)); - rm->spr_platformendtile.init(convertPath("gfx/leveleditor/leveleditor_selectedtile.png"), colors::BLACK.withAlpha(64)); + rm->spr_selectedtile.init(convertPath("gfx/leveleditor/leveleditor_selectedtile.png"), colors::BLACK, 128); + rm->spr_nospawntile.init(convertPath("gfx/leveleditor/leveleditor_nospawntile.png"), colors::BLACK, 128); + rm->spr_noitemspawntile.init(convertPath("gfx/leveleditor/leveleditor_noitemspawntile.png"), colors::BLACK, 128); + rm->spr_platformstarttile.init(convertPath("gfx/leveleditor/leveleditor_platformstarttile.png"), colors::BLACK, 64); + rm->spr_platformendtile.init(convertPath("gfx/leveleditor/leveleditor_selectedtile.png"), colors::BLACK, 64); rm->spr_platformstarttile.SetWrap(true); rm->spr_platformendtile.SetWrap(true); @@ -485,8 +485,8 @@ int main(int argc, char *argv[]) rm->spr_mapitems[1].init(convertPath("gfx/leveleditor/leveleditor_mapitems_preview.png"), colors::MAGENTA); rm->spr_mapitems[2].init(convertPath("gfx/leveleditor/leveleditor_mapitems_thumbnail.png"), colors::MAGENTA); - rm->spr_dialog.init(convertPath("gfx/leveleditor/leveleditor_dialog.png"), colors::MAGENTA.withAlpha(255)); - rm->menu_shade.init(convertPath("gfx/leveleditor/leveleditor_shade.png"), colors::MAGENTA.withAlpha(128)); + rm->spr_dialog.init(convertPath("gfx/leveleditor/leveleditor_dialog.png"), colors::MAGENTA, 255); + rm->menu_shade.init(convertPath("gfx/leveleditor/leveleditor_shade.png"), colors::MAGENTA, 128); rm->spr_tileanimation[0].init(convertPath("gfx/packs/Classic/tilesets/tile_animation.png"), colors::MAGENTA); rm->spr_tileanimation[1].init(convertPath("gfx/packs/Classic/tilesets/tile_animation_preview.png"), colors::MAGENTA); @@ -501,7 +501,7 @@ int main(int argc, char *argv[]) rm->spr_unknowntile[2].init(convertPath("gfx/packs/Classic/tilesets/unknown_tile_thumbnail.png"), colors::MAGENTA); rm->spr_powerups.init(convertPath("gfx/packs/Classic/powerups/large.png"), colors::MAGENTA); - rm->spr_powerupselector.init(convertPath("gfx/leveleditor/leveleditor_powerup_selector.png"), colors::MAGENTA.withAlpha(128)); + rm->spr_powerupselector.init(convertPath("gfx/leveleditor/leveleditor_powerup_selector.png"), colors::MAGENTA, 128); rm->spr_hidden_marker.init(convertPath("gfx/leveleditor/leveleditor_hidden_marker.png"), colors::MAGENTA); rm->spr_flagbases.init(convertPath("gfx/packs/Classic/modeobjects/flagbases.png"), colors::MAGENTA); diff --git a/src/worldeditor/worldeditor.cpp b/src/worldeditor/worldeditor.cpp index e9d6144e..19c88db0 100644 --- a/src/worldeditor/worldeditor.cpp +++ b/src/worldeditor/worldeditor.cpp @@ -524,11 +524,11 @@ int main(int argc, char *argv[]) spr_path.init(convertPath("gfx/leveleditor/leveleditor_world_path.png"), colors::MAGENTA); - rm->spr_selectedtile.init(convertPath("gfx/leveleditor/leveleditor_selectedtile.png"), {0, 0, 0, 128}); + rm->spr_selectedtile.init(convertPath("gfx/leveleditor/leveleditor_selectedtile.png"), colors::BLACK, 128); - spr_dialog.init(convertPath("gfx/leveleditor/leveleditor_dialog.png"), colors::MAGENTA.withAlpha(255)); - menu_shade.init(convertPath("gfx/leveleditor/leveleditor_shade.png"), colors::MAGENTA.withAlpha(128)); - spr_largedialog.init(convertPath("gfx/leveleditor/leveleditor_platform.png"), colors::MAGENTA.withAlpha(255)); + spr_dialog.init(convertPath("gfx/leveleditor/leveleditor_dialog.png"), colors::MAGENTA, 255); + menu_shade.init(convertPath("gfx/leveleditor/leveleditor_shade.png"), colors::MAGENTA, 128); + spr_largedialog.init(convertPath("gfx/leveleditor/leveleditor_platform.png"), colors::MAGENTA, 255); rm->menu_font_small.init(convertPath("gfx/packs/Classic/fonts/font_small.png")); rm->menu_font_large.init(convertPath("gfx/packs/Classic/fonts/font_large.png"));