mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -04:00
more cleanup
This commit is contained in:
parent
86a4e9d7d8
commit
870a38d008
@ -89,8 +89,9 @@ void Drawer2D_HexEncodedCol(int i, int hex, uint8_t lo, uint8_t hi) {
|
||||
}
|
||||
|
||||
void Drawer2D_Init(void) {
|
||||
int i;
|
||||
PackedCol col = PACKEDCOL_CONST(0, 0, 0, 0);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < DRAWER2D_MAX_COLS; i++) {
|
||||
Drawer2D_Cols[i] = col;
|
||||
}
|
||||
@ -110,34 +111,38 @@ void Drawer2D_Free(void) { Drawer2D_FreeFontBitmap(); }
|
||||
void Drawer2D_Rect(Bitmap* bmp, PackedCol col, int x, int y, int width, int height);
|
||||
|
||||
void Drawer2D_Clear(Bitmap* bmp, PackedCol col, int x, int y, int width, int height) {
|
||||
int xx, yy;
|
||||
uint32_t argb = PackedCol_ToARGB(col);
|
||||
uint32_t* row;
|
||||
int xx, yy;
|
||||
|
||||
if (x < 0 || y < 0 || (x + width) > bmp->Width || (y + height) > bmp->Height) {
|
||||
ErrorHandler_Fail("Drawer2D_Clear - tried to clear at invalid coords");
|
||||
}
|
||||
|
||||
for (yy = 0; yy < height; yy++) {
|
||||
uint32_t* row = Bitmap_GetRow(bmp, y + yy) + x;
|
||||
row = Bitmap_GetRow(bmp, y + yy) + x;
|
||||
for (xx = 0; xx < width; xx++) { row[xx] = argb; }
|
||||
}
|
||||
}
|
||||
|
||||
int Drawer2D_FontHeight(const FontDesc* font, bool useShadow) {
|
||||
static String text = String_FromConst("I");
|
||||
struct DrawTextArgs args;
|
||||
String text = String_FromConst("I");
|
||||
DrawTextArgs_Make(&args, &text, font, useShadow);
|
||||
return Drawer2D_MeasureText(&args).Height;
|
||||
}
|
||||
|
||||
void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, int X, int Y) {
|
||||
static struct Texture empty = { GFX_NULL, Tex_Rect(0,0, 0,0), Tex_UV(0,0, 1,1) };
|
||||
Size2D size = Drawer2D_MeasureText(args);
|
||||
if (size.Width == 0 && size.Height == 0) {
|
||||
struct Texture empty = { GFX_NULL, Tex_Rect(X,Y, 0,0), Tex_UV(0,0, 1,1) };
|
||||
*tex = empty; return;
|
||||
Bitmap bmp;
|
||||
|
||||
if (!size.Width && !size.Height) {
|
||||
*tex = empty; tex->X = X; tex->Y = Y;
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
|
||||
Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
|
||||
{
|
||||
Drawer2D_DrawText(&bmp, args, 0, 0);
|
||||
Drawer2D_Make2DTexture(tex, &bmp, size, X, Y);
|
||||
@ -146,12 +151,13 @@ void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, in
|
||||
}
|
||||
|
||||
void Drawer2D_Make2DTexture(struct Texture* tex, Bitmap* bmp, Size2D used, int X, int Y) {
|
||||
GfxResourceID texId = Gfx_CreateTexture(bmp, false, false);
|
||||
float u2 = (float)used.Width / (float)bmp->Width;
|
||||
float v2 = (float)used.Height / (float)bmp->Height;
|
||||
tex->ID = Gfx_CreateTexture(bmp, false, false);
|
||||
tex->X = X; tex->Width = used.Width;
|
||||
tex->Y = Y; tex->Height = used.Height;
|
||||
|
||||
struct Texture tmp = { texId, Tex_Rect(X,Y, used.Width,used.Height), Tex_UV(0,0, u2,v2) };
|
||||
*tex = tmp;
|
||||
tex->U1 = 0.0f; tex->V1 = 0.0f;
|
||||
tex->U2 = (float)used.Width / (float)bmp->Width;
|
||||
tex->V2 = (float)used.Height / (float)bmp->Height;
|
||||
}
|
||||
|
||||
bool Drawer2D_ValidColCodeAt(const String* text, int i) {
|
||||
@ -223,13 +229,14 @@ static int Drawer2D_NextPart(int i, STRING_REF String* value, String* part, char
|
||||
return i;
|
||||
}
|
||||
|
||||
void Drawer2D_Underline(Bitmap* bmp, int x, int y, int width, int height, PackedCol col) {
|
||||
int xx, yy;
|
||||
void Drawer2D_Underline(Bitmap* bmp, int x, int y, int width, int height, PackedCol col) {
|
||||
uint32_t argb = PackedCol_ToARGB(col);
|
||||
uint32_t* row;
|
||||
int xx, yy;
|
||||
|
||||
for (yy = y; yy < y + height; yy++) {
|
||||
if (yy >= bmp->Height) return;
|
||||
uint32_t* row = Bitmap_GetRow(bmp, yy);
|
||||
row = Bitmap_GetRow(bmp, yy);
|
||||
|
||||
for (xx = x; xx < x + width; xx++) {
|
||||
if (xx >= bmp->Width) break;
|
||||
@ -360,46 +367,48 @@ static Size2D Drawer2D_MeasureBitmapText(struct DrawTextArgs* args) {
|
||||
}
|
||||
|
||||
void Drawer2D_DrawText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y) {
|
||||
PackedCol col, backCol, black = PACKEDCOL_BLACK;
|
||||
Size2D partSize;
|
||||
String value = args->Text;
|
||||
char colCode, nextCol = 'f';
|
||||
int i;
|
||||
|
||||
if (Drawer2D_IsEmptyText(&args->Text)) return;
|
||||
if (Drawer2D_BitmappedText) { Drawer2D_DrawBitmapText(bmp, args, x, y); return; }
|
||||
|
||||
String value = args->Text;
|
||||
char nextCol = 'f';
|
||||
int i = 0;
|
||||
|
||||
while (i < value.length) {
|
||||
char colCode = nextCol;
|
||||
i = Drawer2D_NextPart(i, &value, &args->Text, &nextCol);
|
||||
PackedCol col = Drawer2D_GetCol(colCode);
|
||||
for (i = 0; i < value.length; ) {
|
||||
colCode = nextCol;
|
||||
i = Drawer2D_NextPart(i, &value, &args->Text, &nextCol);
|
||||
if (!args->Text.length) continue;
|
||||
|
||||
col = Drawer2D_GetCol(colCode);
|
||||
if (args->UseShadow) {
|
||||
PackedCol black = PACKEDCOL_BLACK;
|
||||
PackedCol backCol = Drawer2D_BlackTextShadows ? black : PackedCol_Scale(col, 0.25f);
|
||||
backCol = Drawer2D_BlackTextShadows ? black : PackedCol_Scale(col, 0.25f);
|
||||
Platform_TextDraw(args, bmp, x + DRAWER2D_OFFSET, y + DRAWER2D_OFFSET, backCol);
|
||||
}
|
||||
|
||||
Size2D partSize = Platform_TextDraw(args, bmp, x, y, col);
|
||||
partSize = Platform_TextDraw(args, bmp, x, y, col);
|
||||
x += partSize.Width;
|
||||
}
|
||||
args->Text = value;
|
||||
}
|
||||
|
||||
Size2D Drawer2D_MeasureText(struct DrawTextArgs* args) {
|
||||
Size2D size = { 0, 0 };
|
||||
Size2D size, partSize;
|
||||
String value = args->Text;
|
||||
char nextCol = 'f';
|
||||
int i;
|
||||
|
||||
size.Width = 0; size.Height = 0;
|
||||
if (Drawer2D_IsEmptyText(&args->Text)) return size;
|
||||
if (Drawer2D_BitmappedText) return Drawer2D_MeasureBitmapText(args);
|
||||
|
||||
String value = args->Text;
|
||||
char nextCol = 'f';
|
||||
int i = 0;
|
||||
|
||||
while (i < value.length) {
|
||||
for (i = 0; i < value.length; ) {
|
||||
i = Drawer2D_NextPart(i, &value, &args->Text, &nextCol);
|
||||
if (!args->Text.length) continue;
|
||||
|
||||
Size2D partSize = Platform_TextMeasure(args);
|
||||
size.Width += partSize.Width;
|
||||
partSize = Platform_TextMeasure(args);
|
||||
size.Width += partSize.Width;
|
||||
size.Height = max(size.Height, partSize.Height);
|
||||
}
|
||||
|
||||
|
@ -1347,8 +1347,7 @@ void ModelCache_Init(void) {
|
||||
void ModelCache_Free(void) {
|
||||
int i;
|
||||
for (i = 0; i < ModelCache_texCount; i++) {
|
||||
struct CachedTexture* tex = &ModelCache_Textures[i];
|
||||
Gfx_DeleteTexture(&tex->TexID);
|
||||
Gfx_DeleteTexture(&ModelCache_Textures[i].TexID);
|
||||
}
|
||||
ModelCache_ContextLost(NULL);
|
||||
|
||||
|
@ -1374,7 +1374,7 @@ static void DisconnectScreen_ReconnectMessage(struct DisconnectScreen* s, String
|
||||
|
||||
static void DisconnectScreen_UpdateDelayLeft(struct DisconnectScreen* s, double delta) {
|
||||
int elapsedMS = (int)(DateTime_CurrentUTC_MS() - s->InitTime);
|
||||
int secsLeft = (DISCONNECT_DELAY_MS - elapsedMS) / DATETIME_MILLIS_PER_SEC;
|
||||
int secsLeft = (DISCONNECT_DELAY_MS - elapsedMS) / DATETIME_MILLIS_PER_SEC;
|
||||
if (secsLeft < 0) secsLeft = 0;
|
||||
|
||||
if (s->LastSecsLeft == secsLeft && s->Reconnect.Active == s->LastActive) return;
|
||||
|
@ -2504,11 +2504,11 @@ void TextGroupWidget_SetText(struct TextGroupWidget* w, int index, const String*
|
||||
|
||||
static void TextGroupWidget_Init(void* widget) {
|
||||
struct TextGroupWidget* w = widget;
|
||||
int height = Drawer2D_FontHeight(&w->Font, true);
|
||||
int i, height;
|
||||
|
||||
height = Drawer2D_FontHeight(&w->Font, true);
|
||||
Drawer2D_ReducePadding_Height(&height, w->Font.Size, 3);
|
||||
|
||||
w->DefaultHeight = height;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < w->LinesCount; i++) {
|
||||
w->Textures[i].Height = height;
|
||||
@ -2519,8 +2519,8 @@ static void TextGroupWidget_Init(void* widget) {
|
||||
|
||||
static void TextGroupWidget_Render(void* widget, double delta) {
|
||||
struct TextGroupWidget* w = widget;
|
||||
int i;
|
||||
struct Texture* textures = w->Textures;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < w->LinesCount; i++) {
|
||||
if (!textures[i].ID) continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user