From df31c95f8311ac78f99120acc8228b4ed2f90978 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 6 Oct 2019 14:01:31 +1100 Subject: [PATCH] Initial WIP on making BitmapCol raw uint32. Also causes hundreds of compile errors, oops. --- src/Bitmap.c | 21 ++++++++---------- src/Bitmap.h | 48 +++++++++++++++++++++++++----------------- src/Core.h | 5 +++-- src/Drawer2D.c | 19 +++++++---------- src/Entity.c | 10 ++++----- src/EntityComponents.c | 4 ++-- src/LScreens.c | 12 +++++------ src/LWidgets.c | 47 +++++++++++++++++++---------------------- src/Launcher.c | 35 +++++++++++++++--------------- src/Protocol.c | 9 +++----- src/Utils.c | 5 ++--- src/Widgets.c | 6 +++--- 12 files changed, 108 insertions(+), 113 deletions(-) diff --git a/src/Bitmap.c b/src/Bitmap.c index a917bf3e4..b55759bd6 100644 --- a/src/Bitmap.c +++ b/src/Bitmap.c @@ -54,7 +54,6 @@ void Bitmap_Scale(Bitmap* dst, Bitmap* src, int srcX, int srcY, int srcWidth, in *#########################################################################################################################*/ #define PNG_SIG_SIZE 8 #define PNG_IHDR_SIZE 13 -#define PNG_RGB_MASK 0xFFFFFFUL #define PNG_PALETTE 256 #define PNG_FourCC(a, b, c, d) (((cc_uint32)a << 24) | ((cc_uint32)b << 16) | ((cc_uint32)c << 8) | (cc_uint32)d) @@ -127,7 +126,7 @@ static void Png_Reconstruct(cc_uint8 type, cc_uint8 bytesPerPixel, cc_uint8* lin } } -#define Bitmap_Set(dst, r,g,b,a) dst.B = b; dst.G = g; dst.R = r; dst.A = a; +#define Bitmap_Set(dst, r,g,b,a) dst = BitmapCol_Make(r, g, b, a); #define PNG_Do_Grayscale(dstI, src, scale) rgb = (src) * scale; Bitmap_Set(dst[dstI], rgb, rgb, rgb, 255); #define PNG_Do_Grayscale_8(dstI, srcI) rgb = src[srcI]; Bitmap_Set(dst[dstI], rgb, rgb, rgb, 255); @@ -307,14 +306,15 @@ static Png_RowExpander Png_GetExpander(cc_uint8 col, cc_uint8 bitsPerSample) { return NULL; } +/* Sets alpha to 0 for any pixels in the bitmap whose RGB is same as col */ static void Png_ComputeTransparency(Bitmap* bmp, BitmapCol col) { - cc_uint32 trnsRGB = col.B | (col.G << 8) | (col.R << 16); /* TODO: Remove this!! */ + BitmapCol trnsRGB = col & BITMAPCOL_RGB_MASK; int x, y, width = bmp->Width, height = bmp->Height; for (y = 0; y < height; y++) { - cc_uint32* row = Bitmap_RawRow(bmp, y); + BitmapCol* row = Bitmap_GetRow(bmp, y); for (x = 0; x < width; x++) { - cc_uint32 rgb = row[x] & PNG_RGB_MASK; + BitmapCol rgb = row[x] & BITMAPCOL_RGB_MASK; row[x] = (rgb == trnsRGB) ? trnsRGB : row[x]; } } @@ -337,7 +337,6 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) { cc_uint32 scanlineSize, scanlineBytes; /* palette data */ - BitmapCol black = BITMAPCOL_CONST(0, 0, 0, 255); BitmapCol transparentCol; BitmapCol palette[PNG_PALETTE]; cc_uint32 i; @@ -360,8 +359,8 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) { if (res) return res; if (!Png_Detect(tmp, PNG_SIG_SIZE)) return PNG_ERR_INVALID_SIG; - transparentCol = black; - for (i = 0; i < PNG_PALETTE; i++) { palette[i] = black; } + transparentCol = BITMAPCOL_BLACK; + for (i = 0; i < PNG_PALETTE; i++) { palette[i] = BITMAPCOL_BLACK; } Inflate_MakeStream(&compStream, &inflate, stream); ZLibHeader_Init(&zlibHeader); @@ -424,8 +423,7 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) { if (res) return res; /* RGB is 16 bits big endian, ignore least significant 8 bits */ - transparentCol.R = tmp[0]; transparentCol.G = tmp[0]; - transparentCol.B = tmp[0]; transparentCol.A = 0; + transparentCol = BitmapCol_Make(tmp[0], tmp[0], tmp[0], 0); } else if (col == PNG_COL_INDEXED) { if (dataSize > PNG_PALETTE) return PNG_ERR_TRANS_COUNT; res = Stream_Read(stream, tmp, dataSize); @@ -441,8 +439,7 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) { if (res) return res; /* R,G,B is 16 bits big endian, ignore least significant 8 bits */ - transparentCol.R = tmp[0]; transparentCol.G = tmp[2]; - transparentCol.B = tmp[4]; transparentCol.A = 0; + transparentCol = BitmapCol_Make(tmp[0], tmp[2], tmp[4], 0); } else { return PNG_ERR_TRANS_INVALID; } diff --git a/src/Bitmap.h b/src/Bitmap.h index ce98eed2f..6c662612f 100644 --- a/src/Bitmap.h +++ b/src/Bitmap.h @@ -6,37 +6,47 @@ */ struct Stream; -/* Represents an ARGB colour, suitable for native graphics API texture pixels. */ -typedef union BitmapCol_ { +/* Represents a packed 32 bit RGBA colour, suitable for native graphics API texture pixels. */ +typedef cc_uint32 BitmapCol; #if defined CC_BUILD_WEB || defined CC_BUILD_ANDROID - struct { cc_uint8 R, G, B, A; }; +#define BITMAPCOL_R_SHIFT 0 +#define BITMAPCOL_G_SHIFT 8 +#define BITMAPCOL_B_SHIFT 16 +#define BITMAPCOL_A_SHIFT 24 #else - struct { cc_uint8 B, G, R, A; }; +#define BITMAPCOL_B_SHIFT 0 +#define BITMAPCOL_G_SHIFT 8 +#define BITMAPCOL_R_SHIFT 16 +#define BITMAPCOL_A_SHIFT 24 #endif - cc_uint32 _raw; -} BitmapCol; -/* Whether components of two colours are all equal. */ -#define BitmapCol_Equals(a,b) ((a)._raw == (b)._raw) -#define PackedCol_ARGB(r, g, b, a) (((cc_uint32)(r) << 16) | ((cc_uint32)(g) << 8) | ((cc_uint32)(b)) | ((cc_uint32)(a) << 24)) +#define BITMAPCOL_R_MASK (0xFFU << BITMAPCOL_R_SHIFT) +#define BITMAPCOL_G_MASK (0xFFU << BITMAPCOL_G_SHIFT) +#define BITMAPCOL_B_MASK (0xFFU << BITMAPCOL_B_SHIFT) +#define BITMAPCOL_A_MASK (0xFFU << BITMAPCOL_A_SHIFT) +#define BitmapCol_R(col) ((cc_uint8)(col >> BITMAPCOL_R_SHIFT)) +#define BitmapCol_G(col) ((cc_uint8)(col >> BITMAPCOL_G_SHIFT)) +#define BitmapCol_B(col) ((cc_uint8)(col >> BITMAPCOL_B_SHIFT)) +#define BitmapCol_A(col) ((cc_uint8)(col >> BITMAPCOL_A_SHIFT)) + +#define BitmapCol_R_Bits(col) ((cc_uint8)(col) << BITMAPCOL_R_SHIFT) +#define BitmapCol_G_Bits(col) ((cc_uint8)(col) << BITMAPCOL_G_SHIFT) +#define BitmapCol_B_Bits(col) ((cc_uint8)(col) << BITMAPCOL_B_SHIFT) +#define BitmapCol_A_Bits(col) ((cc_uint8)(col) << BITMAPCOL_A_SHIFT) + +#define BitmapCol_Make(r, g, b, a) (BitmapCol_R_Bits(r) | BitmapCol_G_Bits(g) | BitmapCol_B_Bits(b) | BitmapCol_A_Bits(a)) +#define BITMAPCOL_RGB_MASK (BITMAPCOL_R_MASK | BITMAPCOL_G_MASK | BITMAPCOL_B_MASK) + +#define BITMAPCOL_BLACK BitmapCol_Make( 0, 0, 0, 255) +#define BITMAPCOL_WHITE BitmapCol_Make(255, 255, 255, 255) /* A 2D array of BitmapCol pixels */ typedef struct Bitmap_ { cc_uint8* Scan0; int Width, Height; } Bitmap; - #define PNG_MAX_DIMS 0x8000 -#if defined CC_BUILD_WEB || defined CC_BUILD_ANDROID -#define BITMAPCOL_CONST(r, g, b, a) { r, g, b, a } -#else -#define BITMAPCOL_CONST(r, g, b, a) { b, g, r, a } -#endif /* Returns number of bytes a bitmap consumes. */ #define Bitmap_DataSize(width, height) ((cc_uint32)(width) * (cc_uint32)(height) * 4) -/* Gets the yth row of a bitmap as raw cc_uint32* pointer. */ -/* NOTE: You SHOULD not rely on the order of the 4 bytes in the pointer. */ -/* Different platforms may have different endian, or different component order. */ -#define Bitmap_RawRow(bmp, y) ((cc_uint32*)(bmp)->Scan0 + (y) * (bmp)->Width) /* Gets the yth row of the given bitmap. */ #define Bitmap_GetRow(bmp, y) ((BitmapCol*)(bmp)->Scan0 + (y) * (bmp)->Width) /* Gets the pixel at (x,y) in the given bitmap. */ diff --git a/src/Core.h b/src/Core.h index 4cd6fcdc1..849c6f823 100644 --- a/src/Core.h +++ b/src/Core.h @@ -30,8 +30,9 @@ typedef unsigned int cc_uintptr; #define CC_HAS_TYPES #define CC_HAS_MISC #elif __GNUC__ -/* really old GCC/clang might not have these */ +/* really old GCC/clang might not have these defined */ #ifdef __INT8_TYPE__ +/* avoid including because it breaks defining UNICODE in Platform.c with MinGW */ typedef __INT8_TYPE__ cc_int8; typedef __INT16_TYPE__ cc_int16; typedef __INT32_TYPE__ cc_int32; @@ -74,7 +75,7 @@ typedef unsigned __INTPTR_TYPE__ cc_uintptr; #define CC_BIG_ENDIAN #endif -/* Unrecognised compiler, so just go with sensisble defaults */ +/* Unrecognised compiler, so just go with sensible defaults */ #ifndef CC_HAS_TYPES #include typedef int8_t cc_int8; diff --git a/src/Drawer2D.c b/src/Drawer2D.c index bcee951c5..e813b04d9 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -278,7 +278,7 @@ void Drawer2D_BmpIndexed(Bitmap* bmp, int x, int y, int size, for (xx = 0; xx < size; xx++) { col = palette[*indices++]; - if (col._raw == 0) continue; /* transparent pixel */ + if (col == 0) continue; /* transparent pixel */ if ((x + xx) < 0 || (x + xx) >= bmp->Width) continue; row[xx] = col; } @@ -433,7 +433,6 @@ void Drawer2D_Underline(Bitmap* bmp, int x, int y, int width, int height, Bitmap } static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int y, bool shadow) { - BitmapCol black = BITMAPCOL_CONST(0, 0, 0, 255); BitmapCol col; String text = args->text; int i, point = args->font->size, count = 0; @@ -454,7 +453,7 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int col = Drawer2D_Cols['f']; if (shadow) { - col = Drawer2D_BlackTextShadows ? black : Drawer2D_ShadowCol(col); + col = Drawer2D_BlackTextShadows ? BITMAPCOL_BLACK : Drawer2D_ShadowCol(col); } for (i = 0; i < text.length; i++) { @@ -462,7 +461,7 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int if (c == '&' && Drawer2D_ValidColCodeAt(&text, i + 1)) { col = Drawer2D_GetCol(text.buffer[i + 1]); if (shadow) { - col = Drawer2D_BlackTextShadows ? black : Drawer2D_ShadowCol(col); + col = Drawer2D_BlackTextShadows ? BITMAPCOL_BLACK : Drawer2D_ShadowCol(col); } i++; continue; /* skip over the colour code */ } @@ -523,7 +522,7 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int dstWidth = 0; col = cols[i]; - for (; i < count && BitmapCol_Equals(col, cols[i]); i++) { + for (; i < count && col == cols[i]; i++) { dstWidth += dstWidths[i] + xPadding; } Drawer2D_Underline(bmp, x, underlineY, dstWidth, underlineHeight, col); @@ -567,7 +566,7 @@ static int Drawer2D_MeasureBitmapWidth(const struct DrawTextArgs* args) { } void Drawer2D_DrawText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y) { - BitmapCol col, backCol, black = BITMAPCOL_CONST(0, 0, 0, 255); + BitmapCol col, backCol; String value = args->text; char colCode, nextCol = 'f'; int i, partWidth; @@ -582,7 +581,7 @@ void Drawer2D_DrawText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y) { col = Drawer2D_GetCol(colCode); if (args->useShadow) { - backCol = Drawer2D_BlackTextShadows ? black : Drawer2D_ShadowCol(col); + backCol = Drawer2D_BlackTextShadows ? BITMAPCOL_BLACK : Drawer2D_ShadowCol(col); Font_SysTextDraw(args, bmp, x, y, backCol, true); } @@ -679,11 +678,9 @@ static void Drawer2D_HexEncodedCol(int i, int hex, cc_uint8 lo, cc_uint8 hi) { } static void Drawer2D_Reset(void) { - BitmapCol col = BITMAPCOL_CONST(0, 0, 0, 0); - int i; - + int i; for (i = 0; i < DRAWER2D_MAX_COLS; i++) { - Drawer2D_Cols[i] = col; + Drawer2D_Cols[i] = 0; } for (i = 0; i <= 9; i++) { diff --git a/src/Entity.c b/src/Entity.c index fa30bc6cc..a1c43e0a8 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -229,7 +229,7 @@ bool Entity_TouchesAnyWater(struct Entity* e) { static void Entity_MakeNameTexture(struct Entity* e) { String colorlessName; char colorlessBuffer[STRING_SIZE]; - BitmapCol shadowCol = BITMAPCOL_CONST(80, 80, 80, 255); + BitmapCol shadowCol = BitmapCol_Make(80, 80, 80, 255); BitmapCol origWhiteCol; struct DrawTextArgs args; @@ -401,13 +401,11 @@ static void Entity_ClearHat(Bitmap* bmp, cc_uint8 skinType) { } /* only perform filtering when the entire hat is opaque */ - cc_uint32 white = PackedCol_ARGB(255, 255, 255, 255); - cc_uint32 black = PackedCol_ARGB(0, 0, 0, 255); for (y = 0; y < sizeY; y++) { - cc_uint32* row = Bitmap_RawRow(bmp, y) + sizeX; + BitmapCol* row = Bitmap_GetRow(bmp, y) + sizeX; for (x = 0; x < sizeX; x++) { - cc_uint32 pixel = row[x]; - if (pixel == white || pixel == black) row[x] = 0; + BitmapCol c = row[x]; + if (c == BITMAPCOL_WHITE || c == BITMAPCOL_BLACK) row[x] = 0; } } } diff --git a/src/EntityComponents.c b/src/EntityComponents.c index bfac6b146..c7f220970 100644 --- a/src/EntityComponents.c +++ b/src/EntityComponents.c @@ -586,8 +586,8 @@ static bool ShadowComponent_GetBlocks(struct Entity* e, int x, int y, int z, str #define sh_half (sh_size / 2) static void ShadowComponent_MakeTex(void) { cc_uint8 pixels[Bitmap_DataSize(sh_size, sh_size)]; - BitmapCol inPix = BITMAPCOL_CONST(0, 0, 0, 200); - BitmapCol outPix = BITMAPCOL_CONST(0, 0, 0, 0); + BitmapCol inPix = BitmapCol_Make(0, 0, 0, 200); + BitmapCol outPix = BitmapCol_Make(0, 0, 0, 0); Bitmap bmp; cc_uint32 x, y; diff --git a/src/LScreens.c b/src/LScreens.c index 465cf63dd..cbc6c503c 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -330,15 +330,15 @@ CC_NOINLINE static void ColoursScreen_Update(struct ColoursScreen* s, int i, Bit String tmp; char tmpBuffer[3]; String_InitArray(tmp, tmpBuffer); - String_AppendInt(&tmp, col.R); + String_AppendInt(&tmp, BitmapCol_R(col)); LInput_SetText(&s->iptColours[i + 0], &tmp); tmp.length = 0; - String_AppendInt(&tmp, col.G); + String_AppendInt(&tmp, BitmapCol_G(col)); LInput_SetText(&s->iptColours[i + 1], &tmp); tmp.length = 0; - String_AppendInt(&tmp, col.B); + String_AppendInt(&tmp, BitmapCol_B(col)); LInput_SetText(&s->iptColours[i + 2], &tmp); } @@ -952,7 +952,7 @@ static void ResourcesScreen_Next(void* w, int x, int y) { static void ResourcesScreen_Init(struct LScreen* s_) { String str; char buffer[STRING_SIZE]; - BitmapCol progressCol = BITMAPCOL_CONST(0, 220, 0, 255); + BitmapCol progressCol = BitmapCol_Make(0, 220, 0, 255); struct ResourcesScreen* s = (struct ResourcesScreen*)s_; float size; @@ -1001,13 +1001,13 @@ static void ResourcesScreen_Layout(struct LScreen* s_) { } CC_NOINLINE static void ResourcesScreen_ResetArea(int x, int y, int width, int height) { - BitmapCol boxCol = BITMAPCOL_CONST(120, 85, 151, 255); + BitmapCol boxCol = BitmapCol_Make(120, 85, 151, 255); Gradient_Noise(&Launcher_Framebuffer, boxCol, 4, x, y, width, height); Launcher_MarkDirty(x, y, width, height); } static void ResourcesScreen_Draw(struct LScreen* s) { - BitmapCol backCol = BITMAPCOL_CONST(12, 12, 12, 255); + BitmapCol backCol = BitmapCol_Make(12, 12, 12, 255); int x, y, width, height; Drawer2D_Clear(&Launcher_Framebuffer, backCol, diff --git a/src/LWidgets.c b/src/LWidgets.c index 43b01561f..e48610aea 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -57,8 +57,8 @@ static BitmapCol LButton_Expand(BitmapCol a, int amount) { } static void LButton_DrawBackground(struct LButton* w) { - BitmapCol activeCol = BITMAPCOL_CONST(126, 136, 191, 255); - BitmapCol inactiveCol = BITMAPCOL_CONST(111, 111, 111, 255); + BitmapCol activeCol = BitmapCol_Make(126, 136, 191, 255); + BitmapCol inactiveCol = BitmapCol_Make(111, 111, 111, 255); BitmapCol col; if (Launcher_ClassicBackground) { @@ -75,7 +75,7 @@ static void LButton_DrawBackground(struct LButton* w) { } static void LButton_DrawBorder(struct LButton* w) { - BitmapCol black = BITMAPCOL_CONST(0, 0, 0, 255); + BitmapCol black = BitmapCol_Make(0, 0, 0, 255); BitmapCol backCol = Launcher_ClassicBackground ? black : Launcher_ButtonBorderCol; Drawer2D_Clear(&Launcher_Framebuffer, backCol, @@ -93,8 +93,8 @@ static void LButton_DrawBorder(struct LButton* w) { } static void LButton_DrawHighlight(struct LButton* w) { - BitmapCol activeCol = BITMAPCOL_CONST(189, 198, 255, 255); - BitmapCol inactiveCol = BITMAPCOL_CONST(168, 168, 168, 255); + BitmapCol activeCol = BitmapCol_Make(189, 198, 255, 255); + BitmapCol inactiveCol = BitmapCol_Make(168, 168, 168, 255); BitmapCol highlightCol; if (Launcher_ClassicBackground) { @@ -176,7 +176,7 @@ CC_NOINLINE static void LInput_GetText(struct LInput* w, String* text) { } static void LInput_DrawOuterBorder(struct LInput* w) { - BitmapCol col = BITMAPCOL_CONST(97, 81, 110, 255); + BitmapCol col = BitmapCol_Make(97, 81, 110, 255); if (w->Selected) { Drawer2D_Clear(&Launcher_Framebuffer, col, @@ -204,7 +204,7 @@ static void LInput_DrawOuterBorder(struct LInput* w) { } static void LInput_DrawInnerBorder(struct LInput* w) { - BitmapCol col = BITMAPCOL_CONST(165, 142, 168, 255); + BitmapCol col = BitmapCol_Make(165, 142, 168, 255); Drawer2D_Clear(&Launcher_Framebuffer, col, w->X + BORDER, w->Y + BORDER, @@ -221,7 +221,7 @@ static void LInput_DrawInnerBorder(struct LInput* w) { } static void LInput_BlendBoxTop(struct LInput* w) { - BitmapCol col = BITMAPCOL_CONST(0, 0, 0, 255); + BitmapCol col = BitmapCol_Make(0, 0, 0, 255); Gradient_Blend(&Launcher_Framebuffer, col, 75, w->X + BORDER, w->Y + BORDER, @@ -255,7 +255,6 @@ static void LInput_Draw(void* widget) { String text; char textBuffer[STRING_SIZE]; struct DrawTextArgs args; Size2D size; - BitmapCol white = BITMAPCOL_CONST(255, 255, 255, 255); String_InitArray(text, textBuffer); LInput_GetText(w, &text); @@ -267,7 +266,7 @@ static void LInput_Draw(void* widget) { LInput_DrawOuterBorder(w); LInput_DrawInnerBorder(w); - Drawer2D_Clear(&Launcher_Framebuffer, white, + Drawer2D_Clear(&Launcher_Framebuffer, BITMAPCOL_WHITE, w->X + BORDER2, w->Y + BORDER2, w->Width - BORDER4, w->Height - BORDER4); LInput_BlendBoxTop(w); @@ -309,7 +308,6 @@ static Rect2D lastCaretRec; static void LInput_TickCaret(void* widget) { struct LInput* w = (struct LInput*)widget; - BitmapCol col = BITMAPCOL_CONST(0, 0, 0, 255); int elapsed; bool caretShow; Rect2D r; @@ -325,7 +323,7 @@ static void LInput_TickCaret(void* widget) { r = LInput_MeasureCaret(w); if (caretShow) { - Drawer2D_Clear(&Launcher_Framebuffer, col, + Drawer2D_Clear(&Launcher_Framebuffer, BITMAPCOL_BLACK, r.X, r.Y, r.Width, r.Height); } @@ -607,8 +605,8 @@ void LLine_Init(struct LScreen* s, struct LLine* w, int width) { *------------------------------------------------------SliderWidget-------------------------------------------------------* *#########################################################################################################################*/ static void LSlider_DrawBoxBounds(struct LSlider* w) { - BitmapCol boundsTop = BITMAPCOL_CONST(119, 100, 132, 255); - BitmapCol boundsBottom = BITMAPCOL_CONST(150, 130, 165, 255); + BitmapCol boundsTop = BitmapCol_Make(119, 100, 132, 255); + BitmapCol boundsBottom = BitmapCol_Make(150, 130, 165, 255); /* TODO: Check these are actually right */ Drawer2D_Clear(&Launcher_Framebuffer, boundsTop, @@ -627,8 +625,8 @@ static void LSlider_DrawBoxBounds(struct LSlider* w) { } static void LSlider_DrawBox(struct LSlider* w) { - BitmapCol progTop = BITMAPCOL_CONST(220, 204, 233, 255); - BitmapCol progBottom = BITMAPCOL_CONST(207, 181, 216, 255); + BitmapCol progTop = BitmapCol_Make(220, 204, 233, 255); + BitmapCol progBottom = BitmapCol_Make(207, 181, 216, 255); int halfHeight = (w->Height - BORDER2) / 2; Gradient_Vertical(&Launcher_Framebuffer, progTop, progBottom, @@ -775,7 +773,7 @@ static void LTable_SetSelectedTo(struct LTable* w, int index) { /* Draws background behind column headers */ static void LTable_DrawHeaderBackground(struct LTable* w) { - BitmapCol gridCol = BITMAPCOL_CONST(20, 20, 10, 255); + BitmapCol gridCol = BitmapCol_Make(20, 20, 10, 255); if (!Launcher_ClassicBackground) { Drawer2D_Clear(&Launcher_Framebuffer, gridCol, @@ -787,11 +785,10 @@ static void LTable_DrawHeaderBackground(struct LTable* w) { /* Works out the background colour of the given row */ static BitmapCol LTable_RowCol(struct LTable* w, struct ServerInfo* row) { - BitmapCol emptyCol = BITMAPCOL_CONST(0, 0, 0, 0); - BitmapCol gridCol = BITMAPCOL_CONST(20, 20, 10, 255); - BitmapCol featSelCol = BITMAPCOL_CONST( 50, 53, 0, 255); - BitmapCol featuredCol = BITMAPCOL_CONST(101, 107, 0, 255); - BitmapCol selectedCol = BITMAPCOL_CONST( 40, 40, 40, 255); + BitmapCol gridCol = BitmapCol_Make( 20, 20, 10, 255); + BitmapCol featSelCol = BitmapCol_Make( 50, 53, 0, 255); + BitmapCol featuredCol = BitmapCol_Make(101, 107, 0, 255); + BitmapCol selectedCol = BitmapCol_Make( 40, 40, 40, 255); bool selected; if (row) { @@ -802,7 +799,7 @@ static BitmapCol LTable_RowCol(struct LTable* w, struct ServerInfo* row) { return selectedCol; } } - return Launcher_ClassicBackground ? emptyCol : gridCol; + return Launcher_ClassicBackground ? 0 : gridCol; } /* Draws background behind each row in the table */ @@ -912,8 +909,8 @@ static void LTable_DrawRows(struct LTable* w) { /* Draws scrollbar on the right edge of the table */ static void LTable_DrawScrollbar(struct LTable* w) { - BitmapCol classicBack = BITMAPCOL_CONST( 80, 80, 80, 255); - BitmapCol classicScroll = BITMAPCOL_CONST(160, 160, 160, 255); + BitmapCol classicBack = BitmapCol_Make( 80, 80, 80, 255); + BitmapCol classicScroll = BitmapCol_Make(160, 160, 160, 255); BitmapCol backCol = Launcher_ClassicBackground ? classicBack : Launcher_ButtonBorderCol; BitmapCol scrollCol = Launcher_ClassicBackground ? classicScroll : Launcher_ButtonForeActiveCol; diff --git a/src/Launcher.c b/src/Launcher.c index 554665deb..4a03bcdc9 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -161,7 +161,7 @@ static void Launcher_Display(void) { } static void Launcher_Init(void) { - BitmapCol col = BITMAPCOL_CONST(125, 125, 125, 255); + BitmapCol col = BitmapCol_Make(125, 125, 125, 255); Event_RegisterVoid(&WindowEvents.Resized, NULL, Launcher_OnResize); Event_RegisterVoid(&WindowEvents.StateChanged, NULL, Launcher_OnResize); @@ -302,25 +302,24 @@ void Launcher_Run(void) { /*########################################################################################################################* *---------------------------------------------------------Colours/Skin----------------------------------------------------* *#########################################################################################################################*/ -BitmapCol Launcher_BackgroundCol = BITMAPCOL_CONST(153, 127, 172, 255); -BitmapCol Launcher_ButtonBorderCol = BITMAPCOL_CONST( 97, 81, 110, 255); -BitmapCol Launcher_ButtonForeActiveCol = BITMAPCOL_CONST(189, 168, 206, 255); -BitmapCol Launcher_ButtonForeCol = BITMAPCOL_CONST(141, 114, 165, 255); -BitmapCol Launcher_ButtonHighlightCol = BITMAPCOL_CONST(162, 131, 186, 255); +#define DEFAULT_BACKGROUND_COL BitmapCol_Make(153, 127, 172, 255); +#define DEFAULT_BUTTON_BORDER_COL BitmapCol_Make( 97, 81, 110, 255); +#define DEFAULT_BUTTON_FORE_ACTIVE_COL BitmapCol_Make(189, 168, 206, 255); +#define DEFAULT_BUTTON_FORE_COL BitmapCol_Make(141, 114, 165, 255); +#define DEFAULT_BUTTON_HIGHLIGHT_COL BitmapCol_Make(162, 131, 186, 255); + +BitmapCol Launcher_BackgroundCol = DEFAULT_BACKGROUND_COL; +BitmapCol Launcher_ButtonBorderCol = DEFAULT_BUTTON_BORDER_COL; +BitmapCol Launcher_ButtonForeActiveCol = DEFAULT_BUTTON_FORE_ACTIVE_COL; +BitmapCol Launcher_ButtonForeCol = DEFAULT_BUTTON_FORE_COL; +BitmapCol Launcher_ButtonHighlightCol = DEFAULT_BUTTON_HIGHLIGHT_COL; void Launcher_ResetSkin(void) { - /* Have to duplicate it here, sigh */ - BitmapCol defaultBackgroundCol = BITMAPCOL_CONST(153, 127, 172, 255); - BitmapCol defaultButtonBorderCol = BITMAPCOL_CONST( 97, 81, 110, 255); - BitmapCol defaultButtonForeActiveCol = BITMAPCOL_CONST(189, 168, 206, 255); - BitmapCol defaultButtonForeCol = BITMAPCOL_CONST(141, 114, 165, 255); - BitmapCol defaultButtonHighlightCol = BITMAPCOL_CONST(162, 131, 186, 255); - - Launcher_BackgroundCol = defaultBackgroundCol; - Launcher_ButtonBorderCol = defaultButtonBorderCol; - Launcher_ButtonForeActiveCol = defaultButtonForeActiveCol; - Launcher_ButtonForeCol = defaultButtonForeCol; - Launcher_ButtonHighlightCol = defaultButtonHighlightCol; + Launcher_BackgroundCol = DEFAULT_BACKGROUND_COL; + Launcher_ButtonBorderCol = DEFAULT_BUTTON_BORDER_COL; + Launcher_ButtonForeActiveCol = DEFAULT_BUTTON_FORE_ACTIVE_COL; + Launcher_ButtonForeCol = DEFAULT_BUTTON_FORE_COL; + Launcher_ButtonHighlightCol = DEFAULT_BUTTON_HIGHLIGHT_COL; } CC_NOINLINE static void Launcher_GetCol(const char* key, BitmapCol* col) { diff --git a/src/Protocol.c b/src/Protocol.c index ac8b0400b..aa0c73494 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -1161,15 +1161,12 @@ static void CPE_BulkBlockUpdate(cc_uint8* data) { } static void CPE_SetTextColor(cc_uint8* data) { - BitmapCol c; - cc_uint8 code; - - c.R = *data++; c.G = *data++; c.B = *data++; c.A = *data++; - code = *data; + BitmapCol c = BitmapCol_Make(data[0], data[1], data[2], data[3]); + cc_uint8 code = data[4]; /* disallow space, null, and colour code specifiers */ if (code == '\0' || code == ' ' || code == 0xFF) return; - if (code == '%' || code == '&') return; + if (code == '%' || code == '&') return; Drawer2D_Cols[code] = c; Event_RaiseInt(&ChatEvents.ColCodeChanged, code); diff --git a/src/Utils.c b/src/Utils.c index 37f671fd1..81d0801f4 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -61,13 +61,12 @@ int Utils_AccumulateWheelDelta(float* accumulator, float delta) { /* Checks if an area is completely black, so Alex skins edited with Microsoft Paint are still treated as Alex */ static bool Utils_IsAllBlack(const Bitmap* bmp, int x1, int y1, int width, int height) { - cc_uint32 black = PackedCol_ARGB(0, 0, 0, 255); int x, y; for (y = y1; y < y1 + height; y++) { - cc_uint32* row = Bitmap_RawRow(bmp, y); + BitmapCol* row = Bitmap_GetRow(bmp, y); for (x = x1; x < x1 + width; x++) { - if (row[x] != black) return false; + if (row[x] != BITMAPCOL_BLACK) return false; } } return true; diff --git a/src/Widgets.c b/src/Widgets.c index df72ab560..f14c4b377 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -2557,8 +2557,8 @@ static Size2D SpecialInputWidget_MeasureTitles(struct SpecialInputWidget* w) { } static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, Bitmap* bmp) { - BitmapCol col_selected = BITMAPCOL_CONST(30, 30, 30, 200); - BitmapCol col_inactive = BITMAPCOL_CONST( 0, 0, 0, 127); + BitmapCol col_selected = BitmapCol_Make(30, 30, 30, 200); + BitmapCol col_inactive = BitmapCol_Make( 0, 0, 0, 127); BitmapCol col; struct DrawTextArgs args; int i, width, x = 0; @@ -2618,7 +2618,7 @@ static void SpecialInputWidget_DrawContent(struct SpecialInputWidget* w, struct } static void SpecialInputWidget_Make(struct SpecialInputWidget* w, struct SpecialInputTab* tab) { - BitmapCol col = BITMAPCOL_CONST(30, 30, 30, 200); + BitmapCol col = BitmapCol_Make(30, 30, 30, 200); Size2D size, titles, content; Bitmap bmp;