Start moving Drawer2D functions to Context2D which takes Context2D* instead of just Bitmap*

This commit is contained in:
UnknownShadow200 2022-06-18 11:10:40 +10:00
parent af8106c97a
commit e45fad71cd
11 changed files with 131 additions and 129 deletions

View File

@ -27,22 +27,6 @@ void Bitmap_TryAllocate(struct Bitmap* bmp, int width, int height) {
bmp->scan0 = (BitmapCol*)Mem_TryAlloc(width * height, 4);
}
void Bitmap_AllocateClearedPow2(struct Bitmap* bmp, int width, int height) {
width = Math_NextPowOf2(width);
height = Math_NextPowOf2(height);
bmp->width = width; bmp->height = height;
bmp->scan0 = (BitmapCol*)Mem_AllocCleared(width * height, 4, "bitmap data");
}
void Bitmap_TryAllocateClearedPow2(struct Bitmap* bmp, int width, int height) {
width = Math_NextPowOf2(width);
height = Math_NextPowOf2(height);
bmp->width = width; bmp->height = height;
bmp->scan0 = (BitmapCol*)Mem_TryAllocCleared(width * height, 4);
}
void Bitmap_Scale(struct Bitmap* dst, struct Bitmap* src,
int srcX, int srcY, int srcWidth, int srcHeight) {
BitmapCol* dstRow;

View File

@ -67,12 +67,6 @@ void Bitmap_Allocate(struct Bitmap* bmp, int width, int height);
/* Attemps to allocates a new bitmap of the given dimensions. */
/* NOTE: You are responsible for freeing its memory! */
void Bitmap_TryAllocate(struct Bitmap* bmp, int width, int height);
/* Allocates a power-of-2 sized bitmap equal to or greater than the given size, and clears it to 0. */
/* NOTE: You are responsible for freeing its memory! */
void Bitmap_AllocateClearedPow2(struct Bitmap* bmp, int width, int height);
/* Attempts to allocate a power-of-2 sized bitmap >= than the given size, and clears it to 0. */
/* NOTE: You are responsible for freeing its memory! */
void Bitmap_TryAllocateClearedPow2(struct Bitmap* bmp, int width, int height);
/* Scales a region of the source bitmap to occupy the entirety of the destination bitmap. */
/* The pixels from the region are scaled upwards or downwards depending on destination width and height. */
CC_API void Bitmap_Scale(struct Bitmap* dst, struct Bitmap* src,

View File

@ -163,6 +163,24 @@ cc_bool Drawer2D_Clamp(struct Bitmap* bmp, int* x, int* y, int* width, int* heig
}
#define Drawer2D_ClampPixel(p) p = (p < 0 ? 0 : (p > 255 ? 255 : p))
void Context2D_Alloc(struct Context2D* ctx, int width, int height) {
ctx->width = width;
ctx->height = height;
ctx->meta = NULL;
/* Allocates a power-of-2 sized bitmap equal to or greater than the given size, and clears it to 0 */
width = Math_NextPowOf2(width);
height = Math_NextPowOf2(height);
ctx->bmp.width = width;
ctx->bmp.height = height;
ctx->bmp.scan0 = (BitmapCol*)Mem_AllocCleared(width * height, 4, "bitmap data");
}
void Context2D_Free(struct Context2D* ctx) {
Mem_Free(ctx->bmp.scan0);
}
void Gradient_Noise(struct Bitmap* bmp, BitmapCol color, int variation,
int x, int y, int width, int height) {
BitmapCol* dst;
@ -261,7 +279,7 @@ void Gradient_Tint(struct Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
}
}
void Drawer2D_BmpCopy(struct Bitmap* dst, int x, int y, struct Bitmap* src) {
void Context2D_DrawPixels(struct Bitmap* dst, int x, int y, struct Bitmap* src) {
int width = src->width, height = src->height;
BitmapCol* dstRow;
BitmapCol* srcRow;
@ -276,7 +294,7 @@ void Drawer2D_BmpCopy(struct Bitmap* dst, int x, int y, struct Bitmap* src) {
}
}
void Drawer2D_Clear(struct Bitmap* bmp, BitmapCol color,
void Context2D_Clear(struct Bitmap* bmp, BitmapCol color,
int x, int y, int width, int height) {
BitmapCol* row;
int xx, yy;
@ -291,7 +309,7 @@ void Drawer2D_Clear(struct Bitmap* bmp, BitmapCol color,
void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args) {
static struct Texture empty = { 0, Tex_Rect(0,0, 0,0), Tex_UV(0,0, 1,1) };
struct Bitmap bmp;
struct Context2D ctx;
int width, height;
/* pointless to draw anything when context is lost */
if (Gfx.LostContext) { *tex = empty; return; }
@ -300,22 +318,22 @@ void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args) {
if (!width) { *tex = empty; return; }
height = Drawer2D_TextHeight(args);
Bitmap_AllocateClearedPow2(&bmp, width, height);
Context2D_Alloc(&ctx, width, height);
{
Drawer2D_DrawText(&bmp, args, 0, 0);
Drawer2D_MakeTexture(tex, &bmp, width, height);
Context2D_DrawText(&ctx, args, 0, 0);
Context2D_MakeTexture(tex, &ctx);
}
Mem_Free(bmp.scan0);
Context2D_Free(&ctx);
}
void Drawer2D_MakeTexture(struct Texture* tex, struct Bitmap* bmp, int width, int height) {
Gfx_RecreateTexture(&tex->ID, bmp, 0, false);
tex->Width = width;
tex->Height = height;
void Context2D_MakeTexture(struct Texture* tex, struct Context2D* ctx) {
Gfx_RecreateTexture(&tex->ID, &ctx->bmp, 0, false);
tex->Width = ctx->width;
tex->Height = ctx->height;
tex->uv.U1 = 0.0f; tex->uv.V1 = 0.0f;
tex->uv.U2 = (float)width / (float)bmp->width;
tex->uv.V2 = (float)height / (float)bmp->height;
tex->uv.U2 = (float)ctx->width / (float)ctx->bmp.width;
tex->uv.V2 = (float)ctx->height / (float)ctx->bmp.height;
}
cc_bool Drawer2D_ValidColorCodeAt(const cc_string* text, int i) {
@ -574,7 +592,7 @@ static int MeasureBitmappedWidth(const struct DrawTextArgs* args) {
return width;
}
void Drawer2D_DrawText(struct Bitmap* bmp, struct DrawTextArgs* args, int x, int y) {
void Context2D_DrawText(struct Bitmap* bmp, struct DrawTextArgs* args, int x, int y) {
if (Drawer2D_IsEmptyText(&args->text)) return;
if (Font_IsBitmap(args->font)) { DrawBitmappedText(bmp, args, x, y); return; }
@ -609,7 +627,7 @@ void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
width = Drawer2D_TextWidth(args);
/* No clipping needed */
if (width <= maxWidth) { Drawer2D_DrawText(bmp, args, x, y); return; }
if (width <= maxWidth) { Context2D_DrawText(bmp, args, x, y); return; }
part = *args;
String_InitArray(part.text, strBuffer);
@ -623,13 +641,13 @@ void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
part.text.length = i + 2;
width = Drawer2D_TextWidth(&part);
if (width <= maxWidth) { Drawer2D_DrawText(bmp, &part, x, y); return; }
if (width <= maxWidth) { Context2D_DrawText(bmp, &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) { Drawer2D_DrawText(bmp, &part, x, y); return; }
if (width <= maxWidth) { Context2D_DrawText(bmp, &part, x, y); return; }
}
}

View File

@ -9,6 +9,7 @@
enum FONT_FLAGS { FONT_FLAGS_NONE = 0x00, FONT_FLAGS_BOLD = 0x01, FONT_FLAGS_UNDERLINE = 0x02, FONT_FLAGS_PADDING = 0x04 };
struct FontDesc { void* handle; cc_uint16 size, flags; int height; };
struct DrawTextArgs { cc_string text; struct FontDesc* font; cc_bool useShadow; };
struct Context2D { struct Bitmap bmp; int width, height; void* meta; };
struct Texture;
struct IGameComponent;
struct StringsBuffer;
@ -32,6 +33,22 @@ void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, cc
/* Returns false if rectangle is completely outside bitmap's rectangle */
cc_bool Drawer2D_Clamp(struct Bitmap* bmp, int* x, int* y, int* width, int* height);
/* Allocates a new context for 2D drawing */
/* Note: Allocates a power-of-2 sized backing bitmap equal to or greater than the given size */
CC_API void Context2D_Alloc(struct Context2D* ctx, int width, int height);
/* Frees/Releases a previously allocatedcontext for 2D drawing */
CC_API void Context2D_Free(struct Context2D* ctx);
/* Creates a texture consisting of the pixels from the bitmap underlying the given 2D context */
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);
/* 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);
/* Fills the area with the given color */
CC_API void Context2D_Clear(struct Bitmap* bmp, 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,
@ -49,30 +66,18 @@ CC_API void Gradient_Blend(struct Bitmap* bmp, BitmapCol color, int blend,
CC_API void Gradient_Tint(struct Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
int x, int y, int width, int height);
/* Fills the given area using pixels from the source bitmap */
CC_API void Drawer2D_BmpCopy(struct Bitmap* dst, int x, int y, struct Bitmap* src);
/* Fills the area with the given color */
CC_API void Drawer2D_Clear(struct Bitmap* bmp, BitmapCol color,
int x, int y, int width, int height);
/* Draws text using the given font at the given coordinates */
CC_API void Drawer2D_DrawText(struct Bitmap* bmp, struct DrawTextArgs* args, int x, int y);
/* Returns how wide the given text would be when drawn */
CC_API int Drawer2D_TextWidth(struct DrawTextArgs* args);
/* Returns how tall the given text would be when drawn */
/* NOTE: Height returned only depends on the font. (see Font_CalcHeight) */
CC_API int Drawer2D_TextHeight(struct DrawTextArgs* args);
/* Similar to Drawer2D_DrawText, but trims the text with trailing ".." if wider than maxWidth */
/* Similar to Context2D_DrawText, but trims the text with trailing ".." if wider than maxWidth */
void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
int x, int y, int maxWidth);
/* Creates a texture consisting only of the given text drawn onto it */
/* NOTE: The returned texture is always padded up to nearest power of two dimensions */
CC_API void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args);
/* Creates a texture consisting of the pixels from the given bitmap */
/* NOTE: bmp must always have power of two dimensions */
/* width/height specifies what region of the texture actually should be drawn */
CC_API void Drawer2D_MakeTexture(struct Texture* tex, struct Bitmap* bmp, int width, int height);
/* Returns whether the given color code is used/valid */
/* NOTE: This can change if the server defines custom color codes */

View File

@ -231,7 +231,7 @@ static void MakeNameTexture(struct Entity* e) {
struct DrawTextArgs args;
struct FontDesc font;
struct Bitmap bmp;
struct Context2D ctx;
int width, height;
cc_string name;
@ -252,21 +252,21 @@ static void MakeNameTexture(struct Entity* e) {
width += NAME_OFFSET;
height = Drawer2D_TextHeight(&args) + NAME_OFFSET;
Bitmap_AllocateClearedPow2(&bmp, width, height);
Context2D_Alloc(&ctx, width, height);
{
origWhiteColor = Drawer2D.Colors['f'];
Drawer2D.Colors['f'] = shadowColor;
Drawer2D_WithoutColors(&colorlessName, &name);
args.text = colorlessName;
Drawer2D_DrawText(&bmp, &args, NAME_OFFSET, NAME_OFFSET);
Context2D_DrawText(&ctx, &args, NAME_OFFSET, NAME_OFFSET);
Drawer2D.Colors['f'] = origWhiteColor;
args.text = name;
Drawer2D_DrawText(&bmp, &args, 0, 0);
Context2D_DrawText(&ctx, &args, 0, 0);
}
Drawer2D_MakeTexture(&e->NameTex, &bmp, width, height);
Mem_Free(bmp.scan0);
Context2D_MakeTexture(&e->NameTex, &ctx);
Context2D_Free(&ctx);
}
}

View File

@ -284,8 +284,8 @@ void Gui_RenderGui(double delta) {
*#########################################################################################################################*/
void TextAtlas_Make(struct TextAtlas* atlas, const cc_string* chars, struct FontDesc* font, const cc_string* prefix) {
struct DrawTextArgs args;
struct Context2D ctx;
int width, height;
struct Bitmap bmp;
int i, charWidth;
Gfx_DeleteTexture(&atlas->tex.ID);
@ -304,20 +304,20 @@ void TextAtlas_Make(struct TextAtlas* atlas, const cc_string* chars, struct Font
}
height = Drawer2D_TextHeight(&args);
Bitmap_AllocateClearedPow2(&bmp, width, height);
Context2D_Alloc(&ctx, width, height);
{
args.text = *prefix;
Drawer2D_DrawText(&bmp, &args, 0, 0);
Context2D_DrawText(&ctx, &args, 0, 0);
for (i = 0; i < chars->length; i++) {
args.text = String_UNSAFE_Substring(chars, i, 1);
Drawer2D_DrawText(&bmp, &args, atlas->offsets[i], 0);
Context2D_DrawText(&ctx, &args, atlas->offsets[i], 0);
}
Drawer2D_MakeTexture(&atlas->tex, &bmp, width, height);
Context2D_MakeTexture(&atlas->tex, &ctx);
}
Mem_Free(bmp.scan0);
Context2D_Free(&ctx);
atlas->uScale = 1.0f / (float)bmp.width;
atlas->uScale = 1.0f / (float)ctx.bmp.width;
atlas->tex.uv.U2 = atlas->offset * atlas->uScale;
atlas->tex.Width = atlas->offset;
}

View File

@ -188,16 +188,16 @@ void LBackend_FreeFramebuffer(void) {
*------------------------------------------------------Base drawing-------------------------------------------------------*
*#########################################################################################################################*/
static void DrawBoxBounds(BitmapCol color, int x, int y, int width, int height) {
Drawer2D_Clear(&framebuffer, color,
Context2D_Clear(&framebuffer, color,
x, y,
width, yBorder);
Drawer2D_Clear(&framebuffer, color,
Context2D_Clear(&framebuffer, color,
x, y + height - yBorder,
width, yBorder);
Drawer2D_Clear(&framebuffer, color,
Context2D_Clear(&framebuffer, color,
x, y,
xBorder, height);
Drawer2D_Clear(&framebuffer, color,
Context2D_Clear(&framebuffer, color,
x + width - xBorder, y,
xBorder, height);
}
@ -395,7 +395,7 @@ void LBackend_ButtonDraw(struct LButton* w) {
DrawTextArgs_Make(&args, &w->text, &titleFont, true);
if (!w->hovered) Drawer2D.Colors['f'] = Drawer2D.Colors['7'];
Drawer2D_DrawText(&framebuffer, &args,
Context2D_DrawText(&framebuffer, &args,
w->x + xOffset / 2, w->y + yOffset / 2);
if (!w->hovered) Drawer2D.Colors['f'] = Drawer2D.Colors['F'];
@ -506,7 +506,7 @@ void LBackend_CheckboxDraw(struct LCheckbox* w) {
DrawTextArgs_Make(&args, &w->text, &textFont, true);
x = w->x + Display_ScaleX(CB_SIZE + CB_OFFSET);
y = w->y + (height - Drawer2D_TextHeight(&args)) / 2;
Drawer2D_DrawText(&framebuffer, &args, x, y);
Context2D_DrawText(&framebuffer, &args, x, y);
}
@ -657,16 +657,16 @@ static void LInput_DrawOuterBorder(struct LInput* w) {
static void LInput_DrawInnerBorder(struct LInput* w) {
BitmapCol color = BitmapCol_Make(165, 142, 168, 255);
Drawer2D_Clear(&framebuffer, color,
Context2D_Clear(&framebuffer, color,
w->x + xBorder, w->y + yBorder,
w->width - xBorder2, yBorder);
Drawer2D_Clear(&framebuffer, color,
Context2D_Clear(&framebuffer, color,
w->x + xBorder, w->y + w->height - yBorder2,
w->width - xBorder2, yBorder);
Drawer2D_Clear(&framebuffer, color,
Context2D_Clear(&framebuffer, color,
w->x + xBorder, w->y + yBorder,
xBorder, w->height - yBorder2);
Drawer2D_Clear(&framebuffer, color,
Context2D_Clear(&framebuffer, color,
w->x + w->width - xBorder2, w->y + yBorder,
xBorder, w->height - yBorder2);
}
@ -690,7 +690,7 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
if (w->text.length || !w->hintText) {
y = w->y + (w->height - w->_textHeight) / 2;
Drawer2D_DrawText(&framebuffer, args,
Context2D_DrawText(&framebuffer, args,
w->x + xInputOffset, y + yInputOffset);
} else {
args->text = String_FromReadonly(w->hintText);
@ -700,7 +700,7 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
y = w->y + (w->height - hintHeight) / 2;
Drawer2D.Colors['f'] = BitmapCol_Make(125, 125, 125, 255);
Drawer2D_DrawText(&framebuffer, args,
Context2D_DrawText(&framebuffer, args,
w->x + xInputOffset, y);
Drawer2D.Colors['f'] = BITMAPCOL_WHITE;
}
@ -716,7 +716,7 @@ void LBackend_InputDraw(struct LInput* w) {
LInput_DrawOuterBorder(w);
LInput_DrawInnerBorder(w);
Drawer2D_Clear(&framebuffer, BITMAPCOL_WHITE,
Context2D_Clear(&framebuffer, BITMAPCOL_WHITE,
w->x + xBorder2, w->y + yBorder2,
w->width - xBorder4, w->height - yBorder4);
LInput_BlendBoxTop(w);
@ -727,7 +727,7 @@ void LBackend_InputDraw(struct LInput* w) {
caretRect = LInput_MeasureCaret(w, &text);
if (!w->caretShow) return;
Drawer2D_Clear(&framebuffer, BITMAPCOL_BLACK,
Context2D_Clear(&framebuffer, BITMAPCOL_BLACK,
caretRect.X, caretRect.Y, caretRect.Width, caretRect.Height);
}
@ -750,7 +750,7 @@ void LBackend_LabelUpdate(struct LLabel* w) {
void LBackend_LabelDraw(struct LLabel* w) {
struct DrawTextArgs args;
DrawTextArgs_Make(&args, &w->text, LLabel_GetFont(w), true);
Drawer2D_DrawText(&framebuffer, &args, w->x, w->y);
Context2D_DrawText(&framebuffer, &args, w->x, w->y);
}
@ -785,10 +785,10 @@ static void LSlider_DrawBoxBounds(struct LSlider* w) {
BitmapCol boundsBottom = BitmapCol_Make(150, 130, 165, 255);
/* TODO: Check these are actually right */
Drawer2D_Clear(&framebuffer, boundsTop,
Context2D_Clear(&framebuffer, boundsTop,
w->x, w->y,
w->width, yBorder);
Drawer2D_Clear(&framebuffer, boundsBottom,
Context2D_Clear(&framebuffer, boundsBottom,
w->x, w->y + w->height - yBorder,
w->width, yBorder);
@ -820,7 +820,7 @@ void LBackend_SliderDraw(struct LSlider* w) {
LSlider_DrawBox(w);
curWidth = (int)((w->width - xBorder2) * w->value / LSLIDER_MAXVALUE);
Drawer2D_Clear(&framebuffer, w->color,
Context2D_Clear(&framebuffer, w->color,
w->x + xBorder, w->y + yBorder,
curWidth, w->height - yBorder2);
}
@ -858,7 +858,7 @@ static void LTable_DrawHeaderBackground(struct LTable* w) {
BitmapCol gridColor = BitmapCol_Make(20, 20, 10, 255);
if (!Launcher_Theme.ClassicBackground) {
Drawer2D_Clear(&framebuffer, gridColor,
Context2D_Clear(&framebuffer, gridColor,
w->x, w->y, w->width, w->hdrHeight);
} else {
Launcher_DrawBackground(&framebuffer,
@ -888,7 +888,7 @@ static void LTable_DrawRowsBackground(struct LTable* w) {
if (height < 0) break;
if (color) {
Drawer2D_Clear(&framebuffer, color,
Context2D_Clear(&framebuffer, color,
w->x, y, w->width, height);
} else {
Launcher_DrawBackground(&framebuffer,
@ -903,14 +903,14 @@ static void LTable_DrawGridlines(struct LTable* w) {
if (Launcher_Theme.ClassicBackground) return;
x = w->x;
Drawer2D_Clear(&framebuffer, Launcher_Theme.BackgroundColor,
Context2D_Clear(&framebuffer, Launcher_Theme.BackgroundColor,
x, w->y + w->hdrHeight, w->width, gridlineHeight);
for (i = 0; i < w->numColumns; i++) {
x += w->columns[i].width;
if (!w->columns[i].hasGridline) continue;
Drawer2D_Clear(&framebuffer, Launcher_Theme.BackgroundColor,
Context2D_Clear(&framebuffer, Launcher_Theme.BackgroundColor,
x, w->y, gridlineWidth, w->height);
x += gridlineWidth;
}
@ -991,9 +991,9 @@ static void LTable_DrawScrollbar(struct LTable* w) {
x = w->x + w->width - scrollbarWidth;
LTable_GetScrollbarCoords(w, &y, &height);
Drawer2D_Clear(&framebuffer, backCol,
Context2D_Clear(&framebuffer, backCol,
x, w->y, scrollbarWidth, w->height);
Drawer2D_Clear(&framebuffer, scrollCol,
Context2D_Clear(&framebuffer, scrollCol,
x, w->y + y, scrollbarWidth, height);
}

View File

@ -1020,7 +1020,7 @@ static void CheckResourcesScreen_ResetArea(struct Bitmap* bmp, int x, int y, int
static void CheckResourcesScreen_DrawBackground(struct LScreen* s, struct Bitmap* bmp) {
int x, y, width, height;
Drawer2D_Clear(bmp, RESOURCES_BACK_COLOR, 0, 0, bmp->width, bmp->height);
Context2D_Clear(bmp, RESOURCES_BACK_COLOR, 0, 0, bmp->width, bmp->height);
width = Display_ScaleX(380);
height = Display_ScaleY(140);

View File

@ -61,16 +61,16 @@ static void LButton_DrawBorder(struct Bitmap* bmp, int x, int y, int width, int
int xoff = oneX;
#endif
Drawer2D_Clear(bmp, backColor,
Context2D_Clear(bmp, backColor,
x + xoff, y,
width - 2 * xoff, oneY);
Drawer2D_Clear(bmp, backColor,
Context2D_Clear(bmp, backColor,
x + xoff, y + height - oneY,
width - 2 * xoff, oneY);
Drawer2D_Clear(bmp, backColor,
Context2D_Clear(bmp, backColor,
x, y + oneY,
oneX, height - twoY);
Drawer2D_Clear(bmp, backColor,
Context2D_Clear(bmp, backColor,
x + width - oneX, y + oneY,
oneX, height - twoY);
}
@ -82,14 +82,14 @@ static void LButton_DrawHighlight(struct Bitmap* bmp, int x, int y, int width, i
if (Launcher_Theme.ClassicBackground) {
if (hovered) color = activeColor;
Drawer2D_Clear(bmp, color,
Context2D_Clear(bmp, color,
x + twoX, y + oneY,
width - fourX, oneY);
Drawer2D_Clear(bmp, color,
Context2D_Clear(bmp, color,
x + oneX, y + twoY,
oneX, height - fourY);
} else if (!hovered) {
Drawer2D_Clear(bmp, color,
Context2D_Clear(bmp, color,
x + twoX, y + oneY,
width - fourX, oneY);
}
@ -460,7 +460,7 @@ void LSlider_SetProgress(struct LSlider* w, int progress) {
static void FlagColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Bitmap* bmp) {
struct Flag* flag = Flags_Get(row);
if (!flag) return;
Drawer2D_BmpCopy(bmp, cell->x + flagXOffset, cell->y + flagYOffset, &flag->bmp);
Context2D_DrawPixels(bmp, cell->x + flagXOffset, cell->y + flagYOffset, &flag->bmp);
}
static void NameColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell, struct Bitmap* bmp) {

View File

@ -496,9 +496,9 @@ void Launcher_DrawLogo(struct FontDesc* font, const char* text, struct Bitmap* b
x = bmp->width / 2 - Drawer2D_TextWidth(&args) / 2;
Drawer2D.Colors['f'] = BITMAPCOL_BLACK;
Drawer2D_DrawText(bmp, &args, x + Display_ScaleX(4), Display_ScaleY(4));
Context2D_DrawText(bmp, &args, x + Display_ScaleX(4), Display_ScaleY(4));
Drawer2D.Colors['f'] = BITMAPCOL_WHITE;
Drawer2D_DrawText(bmp, &args, x, 0);
Context2D_DrawText(bmp, &args, x, 0);
}
void Launcher_MakeLogoFont(struct FontDesc* font) {

View File

@ -1544,7 +1544,7 @@ static void TextInputWidget_RemakeTexture(void* widget) {
struct Texture* tex;
int textWidth, lineHeight;
int width, height, hintX, y;
struct Bitmap bmp;
struct Context2D ctx;
DrawTextArgs_Make(&args, &w->base.text, w->base.font, false);
textWidth = Drawer2D_TextWidth(&args);
@ -1558,27 +1558,27 @@ static void TextInputWidget_RemakeTexture(void* widget) {
width = max(textWidth, w->minWidth); w->base.width = width;
height = max(lineHeight, w->minHeight); w->base.height = height;
Bitmap_AllocateClearedPow2(&bmp, width, height);
Context2D_Alloc(&ctx, width, height);
{
/* Centre text vertically */
y = 0;
if (lineHeight < height) { y = height / 2 - lineHeight / 2; }
w->base.caretOffset = 2 + y;
Drawer2D_Clear(&bmp, backColor, 0, 0, width, height);
Drawer2D_DrawText(&bmp, &args, w->base.padding, y);
Context2D_Clear(&ctx, backColor, 0, 0, width, height);
Context2D_DrawText(&ctx, &args, w->base.padding, y);
args.text = range;
hintX = width - Drawer2D_TextWidth(&args);
/* Draw hint text right-aligned if it won't overlap input text */
if (textWidth + 3 < hintX) {
Drawer2D_DrawText(&bmp, &args, hintX, y);
Context2D_DrawText(&ctx, &args, hintX, y);
}
}
tex = &w->base.inputTex;
Drawer2D_MakeTexture(tex, &bmp, width, height);
Mem_Free(bmp.scan0);
Context2D_MakeTexture(tex, &ctx);
Context2D_Free(&ctx);
Widget_Layout(&w->base);
tex->X = w->base.x; tex->Y = w->base.y;
@ -1664,7 +1664,7 @@ static void ChatInputWidget_RemakeTexture(void* widget) {
struct InputWidget* w = (struct InputWidget*)widget;
struct DrawTextArgs args;
int width = 0, height = 0;
struct Bitmap bmp;
struct Context2D ctx;
char lastCol;
int i, x, y;
@ -1676,10 +1676,10 @@ static void ChatInputWidget_RemakeTexture(void* widget) {
if (!width) width = w->prefixWidth;
if (!height) height = w->lineHeight;
Bitmap_AllocateClearedPow2(&bmp, width, height);
Context2D_Alloc(&ctx, width, height);
DrawTextArgs_Make(&args, &chatInputPrefix, w->font, true);
Drawer2D_DrawText(&bmp, &args, 0, 0);
Context2D_DrawText(&ctx, &args, 0, 0);
String_InitArray(line, lineBuffer);
for (i = 0, y = 0; i < Array_Elems(w->lines); i++) {
@ -1696,12 +1696,12 @@ static void ChatInputWidget_RemakeTexture(void* widget) {
args.text = line;
x = i == 0 ? w->prefixWidth : 0;
Drawer2D_DrawText(&bmp, &args, x, y);
Context2D_DrawText(&ctx, &args, x, y);
y += w->lineHeight;
}
Drawer2D_MakeTexture(&w->inputTex, &bmp, width, height);
Mem_Free(bmp.scan0);
Context2D_MakeTexture(&w->inputTex, &ctx);
Context2D_Free(&ctx);
w->caretAccumulator = 0;
w->width = width;
@ -2181,6 +2181,7 @@ static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Textu
struct Portion bit;
int width, height;
int partWidths[Array_Elems(portions)];
struct Context2D ctx;
struct Bitmap bmp;
int portionsCount;
int i, x, ul;
@ -2197,7 +2198,7 @@ static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Textu
width += partWidths[i];
}
Bitmap_AllocateClearedPow2(&bmp, width, height);
Context2D_Alloc(&ctx, width, height);
{
x = 0;
for (i = 0; i < portionsCount; i++) {
@ -2206,14 +2207,14 @@ 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;
Drawer2D_DrawText(&bmp, args, x, 0);
Context2D_DrawText(&bmp, args, x, 0);
if (ul) args->font->flags &= ~FONT_FLAGS_UNDERLINE;
x += partWidths[i];
}
Drawer2D_MakeTexture(tex, &bmp, width, height);
Context2D_MakeTexture(tex, &ctx);
}
Mem_Free(bmp.scan0);
Context2D_Free(&ctx);
}
void TextGroupWidget_RedrawAll(struct TextGroupWidget* w) {
@ -2406,7 +2407,7 @@ static int SpecialInputWidget_MeasureTitles(struct SpecialInputWidget* w) {
return width;
}
static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, struct Bitmap* bmp) {
static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, struct Context2D* ctx) {
BitmapCol color_selected = BitmapCol_Make(30, 30, 30, 200);
BitmapCol color_inactive = BitmapCol_Make( 0, 0, 0, 127);
BitmapCol color;
@ -2419,8 +2420,8 @@ static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, struct B
color = i == w->selectedIndex ? color_selected : color_inactive;
width = w->tabs[i].titleWidth;
Drawer2D_Clear(bmp, color, x, 0, width, w->titleHeight);
Drawer2D_DrawText(bmp, &args, x + SPECIAL_TITLE_SPACING / 2, 0);
Context2D_Clear(ctx, color, x, 0, width, w->titleHeight);
Context2D_DrawText(ctx, &args, x + SPECIAL_TITLE_SPACING / 2, 0);
x += width;
}
}
@ -2450,7 +2451,7 @@ static int SpecialInputWidget_ContentHeight(struct SpecialInputWidget* w, struct
return w->elementHeight * rows;
}
static void SpecialInputWidget_DrawContent(struct SpecialInputWidget* w, struct SpecialInputTab* tab, struct Bitmap* bmp, int yOffset) {
static void SpecialInputWidget_DrawContent(struct SpecialInputWidget* w, struct SpecialInputTab* tab, struct Context2D* ctx, int yOffset) {
struct DrawTextArgs args;
int i, x, y, item;
@ -2464,7 +2465,7 @@ static void SpecialInputWidget_DrawContent(struct SpecialInputWidget* w, struct
x = (item % wrap) * w->elementWidth;
y = (item / wrap) * w->elementHeight + yOffset;
Drawer2D_DrawText(bmp, &args, x, y);
Context2D_DrawText(ctx, &args, x, y);
}
}
@ -2472,8 +2473,8 @@ static void SpecialInputWidget_Make(struct SpecialInputWidget* w, struct Special
BitmapCol col = BitmapCol_Make(30, 30, 30, 200);
int titlesWidth, titlesHeight;
int contentWidth, contentHeight;
struct Context2D ctx;
int width, height;
struct Bitmap bmp;
titlesWidth = SpecialInputWidget_MeasureTitles(w);
titlesHeight = w->titleHeight;
@ -2484,14 +2485,14 @@ static void SpecialInputWidget_Make(struct SpecialInputWidget* w, struct Special
height = titlesHeight + contentHeight;
Gfx_DeleteTexture(&w->tex.ID);
Bitmap_AllocateClearedPow2(&bmp, width, height);
Context2D_Alloc(&ctx, width, height);
{
SpecialInputWidget_DrawTitles(w, &bmp);
Drawer2D_Clear(&bmp, col, 0, titlesHeight, width, contentHeight);
SpecialInputWidget_DrawContent(w, tab, &bmp, titlesHeight);
SpecialInputWidget_DrawTitles(w, &ctx);
Context2D_Clear(&ctx, col, 0, titlesHeight, width, contentHeight);
SpecialInputWidget_DrawContent(w, tab, &ctx, titlesHeight);
}
Drawer2D_MakeTexture(&w->tex, &bmp, width, height);
Mem_Free(bmp.scan0);
Context2D_MakeTexture(&w->tex, &ctx);
Context2D_Free(&ctx);
}
void SpecialInputWidget_Redraw(struct SpecialInputWidget* w) {