mirror of
https://github.com/cxong/cdogs-sdl.git
synced 2025-07-23 07:23:01 +02:00
Use original font (#442)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"Size": [5, 7],
|
||||
"Size": [7, 8],
|
||||
"Stride": 32,
|
||||
"Padding": [0, 0, 0, 0],
|
||||
"Gap": [-1, 0],
|
||||
"Proportional": true
|
||||
}
|
||||
"Proportional": true,
|
||||
"SpaceSize": [4, 5]
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 18 KiB |
@@ -1,7 +0,0 @@
|
||||
Derived from Tom Thumb by Robey Pointer <robeypointer@gmail.com>
|
||||
http://robey.lag.net/2010/01/23/tiny-monospace-font.html
|
||||
|
||||
And Brian J. Swetland
|
||||
|
||||
http://opengameart.org/content/tom-thumb-tiny-ascii-font-3x5
|
||||
https://creativecommons.org/publicdomain/zero/1.0/
|
@@ -54,7 +54,9 @@ FontOpts FontOptsNew(void)
|
||||
return opts;
|
||||
}
|
||||
|
||||
void FontLoad(Font *f, const char *imgPath, const bool isProportional)
|
||||
void FontLoad(
|
||||
Font *f, const char *imgPath, const bool isProportional,
|
||||
const struct vec2i spaceSize)
|
||||
{
|
||||
char buf[CDOGS_PATH_MAX];
|
||||
GetDataFilePath(buf, imgPath);
|
||||
@@ -108,7 +110,11 @@ void FontLoad(Font *f, const char *imgPath, const bool isProportional)
|
||||
&p, f->Size,
|
||||
svec2i_add(pos, svec2i(f->Padding.Left, f->Padding.Top)),
|
||||
image);
|
||||
if (isProportional)
|
||||
if (chars == ' ')
|
||||
{
|
||||
PicShrink(&p, spaceSize, svec2i_zero());
|
||||
}
|
||||
else if (isProportional)
|
||||
{
|
||||
PicTrim(&p, true, false);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015, Cong Xu
|
||||
Copyright (c) 2014-2015, 2019 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -66,7 +66,9 @@ extern Font gFont;
|
||||
|
||||
FontOpts FontOptsNew(void);
|
||||
|
||||
void FontLoad(Font *f, const char *imgPath, const bool isProportional);
|
||||
void FontLoad(
|
||||
Font *f, const char *imgPath, const bool isProportional,
|
||||
const struct vec2i spaceSize);
|
||||
void FontTerminate(Font *f);
|
||||
|
||||
int FontW(const char c);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2014-2016, Cong Xu
|
||||
Copyright (c) 2014-2016, 2019 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -59,8 +59,10 @@ void FontLoadFromJSON(Font *f, const char *imgPath, const char *jsonPath)
|
||||
YAJLVec2i(&f->Gap, node, "Gap");
|
||||
bool proportional = false;
|
||||
YAJLBool(&proportional, node, "Proportional");
|
||||
struct vec2i spaceSize = f->Size;
|
||||
YAJLVec2i(&spaceSize, node, "SpaceSize");
|
||||
|
||||
FontLoad(f, imgPath, proportional);
|
||||
FontLoad(f, imgPath, proportional, spaceSize);
|
||||
|
||||
bail:
|
||||
yajl_tree_free(node);
|
||||
|
@@ -184,14 +184,18 @@ void PicTrim(Pic *pic, const bool xTrim, const bool yTrim)
|
||||
offset.y = min.y;
|
||||
}
|
||||
}
|
||||
PicShrink(pic, newSize, offset);
|
||||
}
|
||||
void PicShrink(Pic *pic, const struct vec2i size, const struct vec2i offset)
|
||||
{
|
||||
// Trim by copying pixels
|
||||
Uint32 *newData;
|
||||
CMALLOC(newData, newSize.x * newSize.y * sizeof *newData);
|
||||
for (struct vec2i pos = svec2i_zero(); pos.y < newSize.y; pos.y++)
|
||||
CMALLOC(newData, size.x * size.y * sizeof *newData);
|
||||
for (struct vec2i pos = svec2i_zero(); pos.y < size.y; pos.y++)
|
||||
{
|
||||
for (pos.x = 0; pos.x < newSize.x; pos.x++)
|
||||
for (pos.x = 0; pos.x < size.x; pos.x++)
|
||||
{
|
||||
Uint32 *target = newData + pos.x + pos.y * newSize.x;
|
||||
Uint32 *target = newData + pos.x + pos.y * size.x;
|
||||
const int srcIdx =
|
||||
pos.x + offset.x + (pos.y + offset.y) * pic->size.x;
|
||||
*target = *(pic->Data + srcIdx);
|
||||
@@ -200,7 +204,7 @@ void PicTrim(Pic *pic, const bool xTrim, const bool yTrim)
|
||||
// Replace the old data
|
||||
CFREE(pic->Data);
|
||||
pic->Data = newData;
|
||||
pic->size = newSize;
|
||||
pic->size = size;
|
||||
pic->offset = svec2i_zero();
|
||||
PicTryMakeTex(pic);
|
||||
}
|
||||
|
@@ -58,6 +58,7 @@ bool PicIsNone(const Pic *pic);
|
||||
|
||||
// Detect unused edges and update size and offset to fit
|
||||
void PicTrim(Pic *pic, const bool xTrim, const bool yTrim);
|
||||
void PicShrink(Pic *pic, const struct vec2i size, const struct vec2i offset);
|
||||
|
||||
bool PicPxIsEdge(const Pic *pic, const struct vec2i pos, const bool isPixel);
|
||||
|
||||
|
@@ -81,8 +81,7 @@ void TextureRender(
|
||||
};
|
||||
const SDL_Rect *dstP = Rect2iIsZero(dest) ? NULL : &destRect;
|
||||
|
||||
const int renderRes = SDL_RenderCopyEx(r, t, srcP, dstP, angle, NULL, flip);
|
||||
if (renderRes != 0)
|
||||
if (SDL_RenderCopyEx(r, t, srcP, dstP, angle, NULL, flip) != 0)
|
||||
{
|
||||
LOG(LM_MAIN, LL_ERROR, "Failed to render texture: %s", SDL_GetError());
|
||||
}
|
||||
|
Reference in New Issue
Block a user