Move must previous usages of Bitmap to newer Context2D

This commit is contained in:
UnknownShadow200 2022-06-19 13:39:26 +10:00
parent e45fad71cd
commit 548924c854
11 changed files with 104 additions and 92 deletions

View File

@ -181,8 +181,9 @@ void Context2D_Free(struct Context2D* ctx) {
Mem_Free(ctx->bmp.scan0);
}
void Gradient_Noise(struct Bitmap* bmp, BitmapCol color, int variation,
void Gradient_Noise(struct Context2D* ctx, BitmapCol color, int variation,
int x, int y, int width, int height) {
struct Bitmap* bmp = (struct Bitmap*)ctx;
BitmapCol* dst;
int R, G, B, xx, yy, n;
float noise;
@ -205,8 +206,9 @@ void Gradient_Noise(struct Bitmap* bmp, BitmapCol color, int variation,
}
}
void Gradient_Vertical(struct Bitmap* bmp, BitmapCol a, BitmapCol b,
void Gradient_Vertical(struct Context2D* ctx, BitmapCol a, BitmapCol b,
int x, int y, int width, int height) {
struct Bitmap* bmp = (struct Bitmap*)ctx;
BitmapCol* row, color;
int xx, yy;
float t;
@ -226,8 +228,9 @@ void Gradient_Vertical(struct Bitmap* bmp, BitmapCol a, BitmapCol b,
}
}
void Gradient_Blend(struct Bitmap* bmp, BitmapCol color, int blend,
void Gradient_Blend(struct Context2D* ctx, BitmapCol color, int blend,
int x, int y, int width, int height) {
struct Bitmap* bmp = (struct Bitmap*)ctx;
BitmapCol* dst;
int R, G, B, xx, yy;
if (!Drawer2D_Clamp(bmp, &x, &y, &width, &height)) return;
@ -255,8 +258,9 @@ void Gradient_Blend(struct Bitmap* bmp, BitmapCol color, int blend,
}
}
void Gradient_Tint(struct Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
void Gradient_Tint(struct Context2D* ctx, cc_uint8 tintA, cc_uint8 tintB,
int x, int y, int width, int height) {
struct Bitmap* bmp = (struct Bitmap*)ctx;
BitmapCol* row, color;
cc_uint8 tint;
int xx, yy;
@ -279,7 +283,8 @@ void Gradient_Tint(struct Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
}
}
void Context2D_DrawPixels(struct Bitmap* dst, int x, int y, struct Bitmap* src) {
void Context2D_DrawPixels(struct Context2D* ctx, int x, int y, struct Bitmap* src) {
struct Bitmap* dst = (struct Bitmap*)ctx;
int width = src->width, height = src->height;
BitmapCol* dstRow;
BitmapCol* srcRow;
@ -294,8 +299,9 @@ void Context2D_DrawPixels(struct Bitmap* dst, int x, int y, struct Bitmap* src)
}
}
void Context2D_Clear(struct Bitmap* bmp, BitmapCol color,
void Context2D_Clear(struct Context2D* ctx, BitmapCol color,
int x, int y, int width, int height) {
struct Bitmap* bmp = (struct Bitmap*)ctx;
BitmapCol* row;
int xx, yy;
if (!Drawer2D_Clamp(bmp, &x, &y, &width, &height)) return;
@ -592,7 +598,8 @@ static int MeasureBitmappedWidth(const struct DrawTextArgs* args) {
return width;
}
void Context2D_DrawText(struct Bitmap* bmp, struct DrawTextArgs* args, int x, int y) {
void Context2D_DrawText(struct Context2D* ctx, struct DrawTextArgs* args, int x, int y) {
struct Bitmap* bmp = (struct Bitmap*)ctx;
if (Drawer2D_IsEmptyText(&args->text)) return;
if (Font_IsBitmap(args->font)) { DrawBitmappedText(bmp, args, x, y); return; }
@ -619,7 +626,7 @@ int Font_CalcHeight(const struct FontDesc* font, cc_bool useShadow) {
return height;
}
void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
void Drawer2D_DrawClippedText(struct Context2D* ctx, struct DrawTextArgs* args,
int x, int y, int maxWidth) {
char strBuffer[512];
struct DrawTextArgs part;
@ -627,7 +634,7 @@ void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
width = Drawer2D_TextWidth(args);
/* No clipping needed */
if (width <= maxWidth) { Context2D_DrawText(bmp, args, x, y); return; }
if (width <= maxWidth) { Context2D_DrawText(ctx, args, x, y); return; }
part = *args;
String_InitArray(part.text, strBuffer);
@ -641,13 +648,13 @@ void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
part.text.length = i + 2;
width = Drawer2D_TextWidth(&part);
if (width <= maxWidth) { Context2D_DrawText(bmp, &part, x, y); return; }
if (width <= maxWidth) { Context2D_DrawText(ctx, &part, x, y); return; }
/* If down to <= 2 chars, try omitting the .. */
if (i > 2) continue;
part.text.length = i;
width = Drawer2D_TextWidth(&part);
if (width <= maxWidth) { Context2D_DrawText(bmp, &part, x, y); return; }
if (width <= maxWidth) { Context2D_DrawText(ctx, &part, x, y); return; }
}
}

View File

@ -42,28 +42,28 @@ CC_API void Context2D_Free(struct Context2D* ctx);
CC_API void Context2D_MakeTexture(struct Texture* tex, struct Context2D* ctx);
/* Draws text using the given font at the given coordinates */
CC_API void Context2D_DrawText(struct Bitmap* bmp, struct DrawTextArgs* args, int x, int y);
CC_API void Context2D_DrawText(struct Context2D* ctx, struct DrawTextArgs* args, int x, int y);
/* Fills the given area using pixels from the source bitmap */
CC_API void Context2D_DrawPixels(struct Bitmap* dst, int x, int y, struct Bitmap* src);
CC_API void Context2D_DrawPixels(struct Context2D* ctx, int x, int y, struct Bitmap* src);
/* Fills the area with the given color */
CC_API void Context2D_Clear(struct Bitmap* bmp, BitmapCol color,
CC_API void Context2D_Clear(struct Context2D* ctx, BitmapCol color,
int x, int y, int width, int height);
/* Fills the given area with a simple noisy pattern */
/* Variation determines how 'visible/obvious' the noise is */
CC_API void Gradient_Noise(struct Bitmap* bmp, BitmapCol color, int variation,
CC_API void Gradient_Noise(struct Context2D* ctx, BitmapCol color, int variation,
int x, int y, int width, int height);
/* Fills the given area with a vertical gradient, linerarly interpolating from a to b */
/* First drawn row is filled with 'a', while last drawn is filled with 'b' */
CC_API void Gradient_Vertical(struct Bitmap* bmp, BitmapCol a, BitmapCol b,
CC_API void Gradient_Vertical(struct Context2D* ctx, BitmapCol a, BitmapCol b,
int x, int y, int width, int height);
/* Blends the given area with the given color */
/* Note that this only blends RGB, A is not blended */
CC_API void Gradient_Blend(struct Bitmap* bmp, BitmapCol color, int blend,
CC_API void Gradient_Blend(struct Context2D* ctx, BitmapCol color, int blend,
int x, int y, int width, int height);
/* Tints the given area, linearly interpolating from a to b */
/* Note that this only tints RGB, A is not tinted */
CC_API void Gradient_Tint(struct Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
CC_API void Gradient_Tint(struct Context2D* ctx, cc_uint8 tintA, cc_uint8 tintB,
int x, int y, int width, int height);
/* Returns how wide the given text would be when drawn */
@ -72,7 +72,7 @@ CC_API int Drawer2D_TextWidth(struct DrawTextArgs* args);
/* NOTE: Height returned only depends on the font. (see Font_CalcHeight) */
CC_API int Drawer2D_TextHeight(struct DrawTextArgs* args);
/* Similar to Context2D_DrawText, but trims the text with trailing ".." if wider than maxWidth */
void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
void Drawer2D_DrawClippedText(struct Context2D* ctx, struct DrawTextArgs* args,
int x, int y, int maxWidth);
/* Creates a texture consisting only of the given text drawn onto it */

View File

@ -27,7 +27,7 @@
struct FontDesc titleFont, textFont, hintFont, logoFont, rowFont;
/* Contains the pixels that are drawn to the window */
static struct Bitmap framebuffer;
static struct Context2D framebuffer;
/* The area/region of the window that needs to be redrawn and presented to the screen. */
/* If width is 0, means no area needs to be redrawn. */
static Rect2D dirty_rect;
@ -92,8 +92,8 @@ void LBackend_UpdateLogoFont(void) {
Font_Free(&logoFont);
Launcher_MakeLogoFont(&logoFont);
}
void LBackend_DrawLogo(struct Bitmap* bmp, const char* title) {
Launcher_DrawLogo(&logoFont, title, bmp);
void LBackend_DrawLogo(struct Context2D* ctx, const char* title) {
Launcher_DrawLogo(&logoFont, title, ctx);
}
static void OnPointerMove(void* obj, int idx);
@ -155,7 +155,7 @@ static CC_NOINLINE void MarkAllDirty(void) {
/* Marks the given area/region as needing to be redrawn. */
static CC_NOINLINE void MarkAreaDirty(int x, int y, int width, int height) {
int x1, y1, x2, y2;
if (!Drawer2D_Clamp(&framebuffer, &x, &y, &width, &height)) return;
if (!Drawer2D_Clamp(&framebuffer.bmp, &x, &y, &width, &height)) return;
/* union with existing dirty area */
if (dirty_rect.Width) {
@ -174,13 +174,16 @@ static CC_NOINLINE void MarkAreaDirty(int x, int y, int width, int height) {
}
void LBackend_InitFramebuffer(void) {
framebuffer.width = max(WindowInfo.Width, 1);
framebuffer.height = max(WindowInfo.Height, 1);
Window_AllocFramebuffer(&framebuffer);
framebuffer.bmp.width = max(WindowInfo.Width, 1);
framebuffer.bmp.height = max(WindowInfo.Height, 1);
Window_AllocFramebuffer(&framebuffer.bmp);
framebuffer.width = framebuffer.bmp.width;
framebuffer.height = framebuffer.bmp.height;
}
void LBackend_FreeFramebuffer(void) {
Window_FreeFramebuffer(&framebuffer);
Window_FreeFramebuffer(&framebuffer.bmp);
}
@ -462,7 +465,8 @@ static const BitmapCol checkbox_palette[] = {
BitmapCol_Make( 75, 75, 75, 255), BitmapCol_Make(184, 184, 184, 255),
};
static void DrawIndexed(int size, int x, int y, struct Bitmap* bmp) {
static void DrawIndexed(int size, int x, int y, struct Context2D* ctx) {
struct Bitmap* bmp = (struct Bitmap*)ctx;
BitmapCol* row, color;
int i, xx, yy;
@ -636,20 +640,20 @@ void LBackend_InputUnselect(struct LInput* w) {
static void LInput_DrawOuterBorder(struct LInput* w) {
struct LScreen* s = Launcher_Active;
struct Bitmap* bmp = &framebuffer;
BitmapCol color = BitmapCol_Make(97, 81, 110, 255);
struct LScreen* s = Launcher_Active;
struct Context2D* ctx = &framebuffer;
BitmapCol color = BitmapCol_Make(97, 81, 110, 255);
if (w->selected) {
DrawBoxBounds(color, w->x, w->y, w->width, w->height);
} else {
s->ResetArea(bmp, w->x, w->y,
s->ResetArea(ctx, w->x, w->y,
w->width, yBorder);
s->ResetArea(bmp, w->x, w->y + w->height - yBorder,
s->ResetArea(ctx, w->x, w->y + w->height - yBorder,
w->width, yBorder);
s->ResetArea(bmp, w->x, w->y,
s->ResetArea(ctx, w->x, w->y,
xBorder, w->height);
s->ResetArea(bmp, w->x + w->width - xBorder, w->y,
s->ResetArea(ctx, w->x + w->width - xBorder, w->y,
xBorder, w->height);
}
}

View File

@ -5,7 +5,7 @@
Abstracts the gui drawing backend for the Launcher
Copyright 2014-2022 ClassiCube | Licensed under BSD-3
*/
struct Bitmap;
struct Context2D;
struct LScreen;
struct LWidget;
struct LButton;
@ -22,7 +22,7 @@ void LBackend_SetScreen(struct LScreen* s);
void LBackend_CloseScreen(struct LScreen* s);
void LBackend_UpdateLogoFont(void);
void LBackend_DrawLogo(struct Bitmap* bmp, const char* title);
void LBackend_DrawLogo(struct Context2D* ctx, const char* title);
/* Resets pixels to default, then draws widgets of current screen over it */
void LBackend_Redraw(void);

View File

@ -103,13 +103,13 @@ static void LScreen_KeyDown(struct LScreen* s, int key, cc_bool was) {
static void LScreen_MouseUp(struct LScreen* s, int idx) { }
static void LScreen_MouseWheel(struct LScreen* s, float delta) { }
static void LScreen_DrawBackground(struct LScreen* s, struct Bitmap* bmp) {
static void LScreen_DrawBackground(struct LScreen* s, struct Context2D* ctx) {
if (!s->title) {
Launcher_DrawBackground(bmp, 0, 0, bmp->width, bmp->height);
Launcher_DrawBackground(ctx, 0, 0, ctx->width, ctx->height);
return;
}
Launcher_DrawBackgroundAll(bmp);
LBackend_DrawLogo(bmp, s->title);
Launcher_DrawBackgroundAll(ctx);
LBackend_DrawLogo(ctx, s->title);
}
CC_NOINLINE static void LScreen_Reset(struct LScreen* s) {
@ -1014,19 +1014,19 @@ static void CheckResourcesScreen_Show(struct LScreen* s_) {
#define RESOURCES_BACK_COLOR BitmapCol_Make( 12, 12, 12, 255)
#define RESOURCES_FORE_COLOR BitmapCol_Make(120, 85, 151, 255)
static void CheckResourcesScreen_ResetArea(struct Bitmap* bmp, int x, int y, int width, int height) {
Gradient_Noise(bmp, RESOURCES_FORE_COLOR, 4, x, y, width, height);
static void CheckResourcesScreen_ResetArea(struct Context2D* ctx, int x, int y, int width, int height) {
Gradient_Noise(ctx, RESOURCES_FORE_COLOR, 4, x, y, width, height);
}
static void CheckResourcesScreen_DrawBackground(struct LScreen* s, struct Bitmap* bmp) {
static void CheckResourcesScreen_DrawBackground(struct LScreen* s, struct Context2D* ctx) {
int x, y, width, height;
Context2D_Clear(bmp, RESOURCES_BACK_COLOR, 0, 0, bmp->width, bmp->height);
Context2D_Clear(ctx, RESOURCES_BACK_COLOR, 0, 0, ctx->width, ctx->height);
width = Display_ScaleX(380);
height = Display_ScaleY(140);
x = Gui_CalcPos(ANCHOR_CENTRE, 0, width, bmp->width);
y = Gui_CalcPos(ANCHOR_CENTRE, 0, height, bmp->height);
CheckResourcesScreen_ResetArea(bmp, x, y, width, height);
x = Gui_CalcPos(ANCHOR_CENTRE, 0, width, ctx->width);
y = Gui_CalcPos(ANCHOR_CENTRE, 0, height, ctx->height);
CheckResourcesScreen_ResetArea(ctx, x, y, width, height);
}
void CheckResourcesScreen_SetActive(void) {

View File

@ -5,9 +5,9 @@
Implements all of the screens/menus in the launcher
Copyright 2014-2022 ClassiCube | Licensed under BSD-3
*/
struct Bitmap;
struct LWidget;
struct LScreen;
struct Context2D;
typedef void (*LScreen_Func)(struct LScreen* s);
@ -17,11 +17,11 @@ typedef void (*LScreen_Func)(struct LScreen* s);
LScreen_Func Free; /* Cleans up all native resources. */ \
LScreen_Func Layout; /* Positions the widgets on the screen. */ \
LScreen_Func Tick; /* Repeatedly called multiple times every second. */ \
void (*DrawBackground)(struct LScreen* s, struct Bitmap* bmp); \
void (*DrawBackground)(struct LScreen* s, struct Context2D* ctx); \
void (*KeyDown)(struct LScreen* s, int key, cc_bool wasDown); \
void (*MouseUp)(struct LScreen* s, int idx); \
void (*MouseWheel)(struct LScreen* s, float delta); \
void (*ResetArea)(struct Bitmap* bmp, int x, int y, int width, int height); \
void (*ResetArea)(struct Context2D* ctx, int x, int y, int width, int height); \
struct LWidget* onEnterWidget; /* Default widget to auto-click when Enter is pressed. Can be NULL. */ \
struct LWidget* hoveredWidget; /* Widget the mouse is currently hovering over. */ \
struct LWidget* selectedWidget; /* Widget mouse last clicked on. */ \

View File

@ -38,22 +38,22 @@ static BitmapCol LButton_Expand(BitmapCol a, int amount) {
return BitmapCol_Make(r, g, b, 255);
}
static void LButton_DrawBase(struct Bitmap* bmp, int x, int y, int width, int height, cc_bool hovered) {
static void LButton_DrawBase(struct Context2D* ctx, int x, int y, int width, int height, cc_bool hovered) {
BitmapCol color = hovered ? Launcher_Theme.ButtonForeActiveColor
: Launcher_Theme.ButtonForeColor;
if (Launcher_Theme.ClassicBackground) {
Gradient_Noise(bmp, color, 8,
Gradient_Noise(ctx, color, 8,
x + oneX, y + oneY,
width - twoX, height - twoY);
} else {
Gradient_Vertical(bmp, LButton_Expand(color, 8), LButton_Expand(color, -8),
Gradient_Vertical(ctx, LButton_Expand(color, 8), LButton_Expand(color, -8),
x + oneX, y + oneY,
width - twoX, height - twoY);
}
}
static void LButton_DrawBorder(struct Bitmap* bmp, int x, int y, int width, int height) {
static void LButton_DrawBorder(struct Context2D* ctx, int x, int y, int width, int height) {
BitmapCol backColor = Launcher_Theme.ButtonBorderColor;
#ifdef CC_BUILD_IOS
int xoff = 0; /* TODO temp hack */
@ -61,44 +61,44 @@ static void LButton_DrawBorder(struct Bitmap* bmp, int x, int y, int width, int
int xoff = oneX;
#endif
Context2D_Clear(bmp, backColor,
Context2D_Clear(ctx, backColor,
x + xoff, y,
width - 2 * xoff, oneY);
Context2D_Clear(bmp, backColor,
Context2D_Clear(ctx, backColor,
x + xoff, y + height - oneY,
width - 2 * xoff, oneY);
Context2D_Clear(bmp, backColor,
Context2D_Clear(ctx, backColor,
x, y + oneY,
oneX, height - twoY);
Context2D_Clear(bmp, backColor,
Context2D_Clear(ctx, backColor,
x + width - oneX, y + oneY,
oneX, height - twoY);
}
static void LButton_DrawHighlight(struct Bitmap* bmp, int x, int y, int width, int height, cc_bool hovered) {
static void LButton_DrawHighlight(struct Context2D* ctx, int x, int y, int width, int height, cc_bool hovered) {
BitmapCol activeColor = BitmapCol_Make(189, 198, 255, 255);
BitmapCol color = Launcher_Theme.ButtonHighlightColor;
if (Launcher_Theme.ClassicBackground) {
if (hovered) color = activeColor;
Context2D_Clear(bmp, color,
Context2D_Clear(ctx, color,
x + twoX, y + oneY,
width - fourX, oneY);
Context2D_Clear(bmp, color,
Context2D_Clear(ctx, color,
x + oneX, y + twoY,
oneX, height - fourY);
} else if (!hovered) {
Context2D_Clear(bmp, color,
Context2D_Clear(ctx, color,
x + twoX, y + oneY,
width - fourX, oneY);
}
}
void LButton_DrawBackground(struct Bitmap* bmp, int x, int y, int width, int height, cc_bool hovered) {
LButton_DrawBase( bmp, x, y, width, height, hovered);
LButton_DrawBorder( bmp, x, y, width, height);
LButton_DrawHighlight(bmp, x, y, width, height, hovered);
void LButton_DrawBackground(struct Context2D* ctx, int x, int y, int width, int height, cc_bool hovered) {
LButton_DrawBase( ctx, x, y, width, height, hovered);
LButton_DrawBorder( ctx, x, y, width, height);
LButton_DrawHighlight(ctx, x, y, width, height, hovered);
}
static void LButton_Draw(void* widget) {
@ -457,34 +457,34 @@ void LSlider_SetProgress(struct LSlider* w, int progress) {
/*########################################################################################################################*
*------------------------------------------------------TableWidget--------------------------------------------------------*
*#########################################################################################################################*/
static void FlagColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Bitmap* bmp) {
static void FlagColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Context2D* ctx) {
struct Flag* flag = Flags_Get(row);
if (!flag) return;
Context2D_DrawPixels(bmp, cell->x + flagXOffset, cell->y + flagYOffset, &flag->bmp);
Context2D_DrawPixels(ctx, cell->x + flagXOffset, cell->y + flagYOffset, &flag->bmp);
}
static void NameColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Bitmap* bmp) {
static void NameColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Context2D* ctx) {
args->text = row->name;
}
static int NameColumn_Sort(const struct ServerInfo* a, const struct ServerInfo* b) {
return String_Compare(&b->name, &a->name);
}
static void PlayersColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Bitmap* bmp) {
static void PlayersColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Context2D* ctx) {
String_Format2(&args->text, "%i/%i", &row->players, &row->maxPlayers);
}
static int PlayersColumn_Sort(const struct ServerInfo* a, const struct ServerInfo* b) {
return b->players - a->players;
}
static void UptimeColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Bitmap* bmp) {
static void UptimeColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Context2D* ctx) {
LTable_FormatUptime(&args->text, row->uptime);
}
static int UptimeColumn_Sort(const struct ServerInfo* a, const struct ServerInfo* b) {
return b->uptime - a->uptime;
}
static void SoftwareColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Bitmap* bmp) {
static void SoftwareColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Context2D* ctx) {
/* last column, so adjust to fit size of table */
int leftover = cell->table->width - cell->x;
cell->width = max(cell->width, leftover);

View File

@ -6,6 +6,7 @@
Copyright 2014-2021 ClassiCube | Licensed under BSD-3
*/
struct FontDesc;
struct Context2D;
enum LWIDGET_TYPE {
LWIDGET_BUTTON, LWIDGET_CHECKBOX, LWIDGET_INPUT,
LWIDGET_LABEL, LWIDGET_LINE, LWIDGET_SLIDER, LWIDGET_TABLE
@ -69,7 +70,7 @@ struct LButton {
};
CC_NOINLINE void LButton_Init(struct LButton* w, int width, int height, const char* text, const struct LLayout* layouts);
CC_NOINLINE void LButton_SetConst(struct LButton* w, const char* text);
CC_NOINLINE void LButton_DrawBackground(struct Bitmap* bmp, int x, int y, int width, int height, cc_bool hovered);
CC_NOINLINE void LButton_DrawBackground(struct Context2D* ctx, int x, int y, int width, int height, cc_bool hovered);
struct LCheckbox;
struct LCheckbox {
@ -155,7 +156,7 @@ struct LTableColumn {
/* Draws the value of this column for the given row. */
/* If args.Text is changed to something, that text gets drawn afterwards. */
/* Most of the time that's all you need to do. */
void (*DrawRow)(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Bitmap* bmp);
void (*DrawRow)(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Context2D* ctx);
/* Returns sort order of two rows, based on value of this column in both rows. */
int (*SortOrder)(const struct ServerInfo* a, const struct ServerInfo* b);
/* Whether a vertical gridline (and padding) appears after this. */

View File

@ -450,7 +450,8 @@ void Launcher_TryLoadTexturePack(void) {
*#########################################################################################################################*/
/* Fills the given area using pixels from the source bitmap, by repeatedly tiling the bitmap */
CC_NOINLINE static void ClearTile(int x, int y, int width, int height,
struct Bitmap* dst, struct Bitmap* src) {
struct Context2D* ctx, struct Bitmap* src) {
struct Bitmap* dst = (struct Bitmap*)ctx;
BitmapCol* dstRow;
BitmapCol* srcRow;
int xx, yy;
@ -466,20 +467,20 @@ CC_NOINLINE static void ClearTile(int x, int y, int width, int height,
}
}
void Launcher_DrawBackground(struct Bitmap* bmp, int x, int y, int width, int height) {
void Launcher_DrawBackground(struct Context2D* ctx, int x, int y, int width, int height) {
if (Launcher_Theme.ClassicBackground && dirtBmp.scan0) {
ClearTile(x, y, width, height, bmp, &stoneBmp);
ClearTile(x, y, width, height, ctx, &stoneBmp);
} else {
Gradient_Noise(bmp, Launcher_Theme.BackgroundColor, 6, x, y, width, height);
Gradient_Noise(ctx, Launcher_Theme.BackgroundColor, 6, x, y, width, height);
}
}
void Launcher_DrawBackgroundAll(struct Bitmap* bmp) {
void Launcher_DrawBackgroundAll(struct Context2D* ctx) {
if (Launcher_Theme.ClassicBackground && dirtBmp.scan0) {
ClearTile(0, 0, bmp->width, TILESIZE, bmp, &dirtBmp);
ClearTile(0, TILESIZE, bmp->width, bmp->height - TILESIZE, bmp, &stoneBmp);
ClearTile(0, 0, ctx->width, TILESIZE, ctx, &dirtBmp);
ClearTile(0, TILESIZE, ctx->width, ctx->height - TILESIZE, ctx, &stoneBmp);
} else {
Launcher_DrawBackground(bmp, 0, 0, bmp->width, bmp->height);
Launcher_DrawBackground(ctx, 0, 0, ctx->width, ctx->height);
}
}
@ -487,18 +488,18 @@ cc_bool Launcher_BitmappedText(void) {
return (useBitmappedFont || Launcher_Theme.ClassicBackground) && hasBitmappedFont;
}
void Launcher_DrawLogo(struct FontDesc* font, const char* text, struct Bitmap* bmp) {
void Launcher_DrawLogo(struct FontDesc* font, const char* text, struct Context2D* ctx) {
cc_string title = String_FromReadonly(text);
struct DrawTextArgs args;
int x;
DrawTextArgs_Make(&args, &title, font, false);
x = bmp->width / 2 - Drawer2D_TextWidth(&args) / 2;
x = ctx->width / 2 - Drawer2D_TextWidth(&args) / 2;
Drawer2D.Colors['f'] = BITMAPCOL_BLACK;
Context2D_DrawText(bmp, &args, x + Display_ScaleX(4), Display_ScaleY(4));
Context2D_DrawText(ctx, &args, x + Display_ScaleX(4), Display_ScaleY(4));
Drawer2D.Colors['f'] = BITMAPCOL_WHITE;
Context2D_DrawText(bmp, &args, x, 0);
Context2D_DrawText(ctx, &args, x, 0);
}
void Launcher_MakeLogoFont(struct FontDesc* font) {

View File

@ -53,17 +53,17 @@ void Launcher_SaveTheme(void);
/* Whether logo should be drawn using bitmapped text */
cc_bool Launcher_BitmappedText(void);
/* Draws logo styled text using the given font */
void Launcher_DrawLogo(struct FontDesc* font, const char* text, struct Bitmap* bmp);
void Launcher_DrawLogo(struct FontDesc* font, const char* text, struct Context2D* ctx);
/* Allocates a font appropriate for drawing logo text */
void Launcher_MakeLogoFont(struct FontDesc* font);
/* Attempts to load font and terrain from texture pack. */
void Launcher_TryLoadTexturePack(void);
/* Fills the given region of the given bitmap with the default background */
void Launcher_DrawBackground(struct Bitmap* bmp, int x, int y, int width, int height);
void Launcher_DrawBackground(struct Context2D* ctx, int x, int y, int width, int height);
/* Fills the entire contents of the given bitmap with the default background */
/* NOTE: Also draws titlebar at top, if current screen permits it */
void Launcher_DrawBackgroundAll(struct Bitmap* bmp);
void Launcher_DrawBackgroundAll(struct Context2D* ctx);
/* Sets currently active screen/menu, freeing old one. */
void Launcher_SetScreen(struct LScreen* screen);

View File

@ -2182,7 +2182,6 @@ static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Textu
int width, height;
int partWidths[Array_Elems(portions)];
struct Context2D ctx;
struct Bitmap bmp;
int portionsCount;
int i, x, ul;
@ -2207,7 +2206,7 @@ static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Textu
args->text = String_UNSAFE_Substring(text, bit.LineBeg, bit.LineLen);
if (ul) args->font->flags |= FONT_FLAGS_UNDERLINE;
Context2D_DrawText(&bmp, args, x, 0);
Context2D_DrawText(&ctx, args, x, 0);
if (ul) args->font->flags &= ~FONT_FLAGS_UNDERLINE;
x += partWidths[i];