mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-30 01:48:15 +03:00
Use SDL_Color for colors instead of colourTransform
colourTransform is a struct with only one member, a Uint32. The issue with `Uint32`s is that it requires a bunch of bit shifting logic to edit the colors. The issue with bit shifting logic is that people have a tendency to hardcode the shift amounts instead of using the shift amount variables of the SDL_PixelFormat, which makes it annoying to change the color masks of surfaces. This commit fixes both issues by unhardcoding the bit shift amounts in DrawPixel and ReadPixel, and by axing the `Uint32`s in favor of using SDL_Color. According to the SDL_PixelFormat documentation ( https://wiki.libsdl.org/SDL2/SDL_PixelFormat ), the logic to read and draw to pixels from colors below 32-bit was just wrong. Specifically, for 8-bit, there's a color palette used instead of some intrinsic color information stored in the pixel itself. But we shouldn't need that logic anyways because we don't use colors below 32-bit. So I axed that too.
This commit is contained in:
@@ -279,20 +279,20 @@ static int edentat( int xp, int yp )
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void fillbox( int x, int y, int x2, int y2, int c )
|
||||
static void fillbox(const int x, const int y, const int x2, const int y2, const SDL_Color color)
|
||||
{
|
||||
FillRect(graphics.backBuffer, x, y, x2-x, 1, c);
|
||||
FillRect(graphics.backBuffer, x, y2-1, x2-x, 1, c);
|
||||
FillRect(graphics.backBuffer, x, y, 1, y2-y, c);
|
||||
FillRect(graphics.backBuffer, x2-1, y, 1, y2-y, c);
|
||||
FillRect(graphics.backBuffer, x, y, x2-x, 1, color);
|
||||
FillRect(graphics.backBuffer, x, y2-1, x2-x, 1, color);
|
||||
FillRect(graphics.backBuffer, x, y, 1, y2-y, color);
|
||||
FillRect(graphics.backBuffer, x2-1, y, 1, y2-y, color);
|
||||
}
|
||||
|
||||
static void fillboxabs( int x, int y, int x2, int y2, int c )
|
||||
static void fillboxabs(const int x, const int y, const int x2, const int y2, const SDL_Color color)
|
||||
{
|
||||
FillRect(graphics.backBuffer, x, y, x2, 1, c);
|
||||
FillRect(graphics.backBuffer, x, y+y2-1, x2, 1, c);
|
||||
FillRect(graphics.backBuffer, x, y, 1, y2, c);
|
||||
FillRect(graphics.backBuffer, x+x2-1, y, 1, y2, c);
|
||||
FillRect(graphics.backBuffer, x, y, x2, 1, color);
|
||||
FillRect(graphics.backBuffer, x, y+y2-1, x2, 1, color);
|
||||
FillRect(graphics.backBuffer, x, y, 1, y2, color);
|
||||
FillRect(graphics.backBuffer, x+x2-1, y, 1, y2, color);
|
||||
}
|
||||
|
||||
|
||||
@@ -595,8 +595,7 @@ void editorrender(void)
|
||||
|
||||
// Special case for drawing gray entities
|
||||
bool custom_gray = room->tileset == 3 && room->tilecol == 6;
|
||||
colourTransform gray_ct;
|
||||
gray_ct.colour = 0xFFFFFFFF;
|
||||
const SDL_Color gray_ct = {255, 255, 255, 255};
|
||||
|
||||
// Draw entities backward to remain accurate with ingame
|
||||
for (int i = customentities.size() - 1; i >= 0; i--)
|
||||
@@ -610,9 +609,10 @@ void editorrender(void)
|
||||
switch(customentities[i].t)
|
||||
{
|
||||
case 1: //Entities
|
||||
if (custom_gray) {
|
||||
if (custom_gray)
|
||||
{
|
||||
graphics.setcol(18);
|
||||
ed.entcolreal = graphics.ct.colour;
|
||||
ed.entcolreal = graphics.ct;
|
||||
}
|
||||
graphics.drawsprite((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),ed.getenemyframe(room->enemytype),ed.entcolreal);
|
||||
if(customentities[i].p1==0) graphics.Print((customentities[i].x*8)- (ed.levx*40*8)+4,(customentities[i].y*8)- (ed.levy*30*8)+4, "V", 255, 255, 255 - help.glow, false);
|
||||
@@ -933,10 +933,8 @@ void editorrender(void)
|
||||
tpoint.x = ed.ghosts[i].x;
|
||||
tpoint.y = ed.ghosts[i].y;
|
||||
graphics.setcolreal(ed.ghosts[i].realcol);
|
||||
Uint32 alpha = graphics.ct.colour & graphics.backBuffer->format->Amask;
|
||||
Uint32 therest = graphics.ct.colour & 0x00FFFFFF;
|
||||
alpha = (3 * (alpha >> 24) / 4) << 24;
|
||||
graphics.ct.colour = therest | alpha;
|
||||
const int alpha = 3 * graphics.ct.a / 4;
|
||||
graphics.ct.a = (Uint8) alpha;
|
||||
SDL_Rect drawRect = graphics.sprites_rect;
|
||||
drawRect.x += tpoint.x;
|
||||
drawRect.y += tpoint.y;
|
||||
@@ -1607,7 +1605,7 @@ void editorrenderfixed(void)
|
||||
ed.entcol=cl.getenemycol(game.customcol);
|
||||
|
||||
graphics.setcol(ed.entcol);
|
||||
ed.entcolreal = graphics.ct.colour;
|
||||
ed.entcolreal = graphics.ct;
|
||||
|
||||
if (game.ghostsenabled)
|
||||
{
|
||||
@@ -1621,7 +1619,7 @@ void editorrenderfixed(void)
|
||||
}
|
||||
|
||||
graphics.setcol(ghost.col);
|
||||
ghost.realcol = graphics.ct.colour;
|
||||
ghost.realcol = graphics.ct;
|
||||
}
|
||||
|
||||
if (ed.currentghosts + 1 < (int)ed.ghosts.size()) {
|
||||
|
||||
Reference in New Issue
Block a user