mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 17:17:09 -04:00
Change Drawer2D_UNSAFE_NextPart to return color code instead of color
This commit is contained in:
parent
882b437912
commit
626b35a993
@ -316,16 +316,18 @@ cc_bool Drawer2D_ValidColorCodeAt(const cc_string* text, int i) {
|
|||||||
return BitmapCol_A(Drawer2D_GetColor(text->buffer[i])) != 0;
|
return BitmapCol_A(Drawer2D_GetColor(text->buffer[i])) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_bool Drawer2D_UNSAFE_NextPart(cc_string* left, cc_string* part, BitmapCol* color) {
|
cc_bool Drawer2D_UNSAFE_NextPart(cc_string* left, cc_string* part, char* colorCode) {
|
||||||
BitmapCol c;
|
BitmapCol color;
|
||||||
|
char cur;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* check if current part starts with a colour code */
|
/* check if current part starts with a colour code */
|
||||||
if (left->length >= 2 && left->buffer[0] == '&') {
|
if (left->length >= 2 && left->buffer[0] == '&') {
|
||||||
c = Drawer2D_GetColor(left->buffer[1]);
|
cur = left->buffer[1];
|
||||||
|
color = Drawer2D_GetColor(cur);
|
||||||
|
|
||||||
if (BitmapCol_A(c)) {
|
if (BitmapCol_A(color)) {
|
||||||
*color = c;
|
*colorCode = cur;
|
||||||
left->buffer += 2;
|
left->buffer += 2;
|
||||||
left->length -= 2;
|
left->length -= 2;
|
||||||
}
|
}
|
||||||
@ -347,9 +349,9 @@ cc_bool Drawer2D_UNSAFE_NextPart(cc_string* left, cc_string* part, BitmapCol* co
|
|||||||
|
|
||||||
cc_bool Drawer2D_IsEmptyText(const cc_string* text) {
|
cc_bool Drawer2D_IsEmptyText(const cc_string* text) {
|
||||||
cc_string left = *text, part;
|
cc_string left = *text, part;
|
||||||
BitmapCol color;
|
char colorCode;
|
||||||
|
|
||||||
while (Drawer2D_UNSAFE_NextPart(&left, &part, &color))
|
while (Drawer2D_UNSAFE_NextPart(&left, &part, &colorCode))
|
||||||
{
|
{
|
||||||
if (part.length) return false;
|
if (part.length) return false;
|
||||||
}
|
}
|
||||||
@ -358,9 +360,9 @@ cc_bool Drawer2D_IsEmptyText(const cc_string* text) {
|
|||||||
|
|
||||||
void Drawer2D_WithoutColors(cc_string* str, const cc_string* src) {
|
void Drawer2D_WithoutColors(cc_string* str, const cc_string* src) {
|
||||||
cc_string left = *src, part;
|
cc_string left = *src, part;
|
||||||
BitmapCol color;
|
char colorCode;
|
||||||
|
|
||||||
while (Drawer2D_UNSAFE_NextPart(&left, &part, &color))
|
while (Drawer2D_UNSAFE_NextPart(&left, &part, &colorCode))
|
||||||
{
|
{
|
||||||
String_AppendString(str, &part);
|
String_AppendString(str, &part);
|
||||||
}
|
}
|
||||||
@ -1287,10 +1289,10 @@ static int Font_SysTextWidth(struct DrawTextArgs* args) {
|
|||||||
struct FontDesc* font = args->font;
|
struct FontDesc* font = args->font;
|
||||||
cc_string left = args->text, part;
|
cc_string left = args->text, part;
|
||||||
double width = 0;
|
double width = 0;
|
||||||
BitmapCol color;
|
char colorCode;
|
||||||
|
|
||||||
interop_SetFont(font->handle, font->size, font->flags);
|
interop_SetFont(font->handle, font->size, font->flags);
|
||||||
while (Drawer2D_UNSAFE_NextPart(&left, &part, &color))
|
while (Drawer2D_UNSAFE_NextPart(&left, &part, &colorCode))
|
||||||
{
|
{
|
||||||
char buffer[NATIVE_STR_LEN];
|
char buffer[NATIVE_STR_LEN];
|
||||||
int len = Platform_EncodeUtf8(buffer, &part);
|
int len = Platform_EncodeUtf8(buffer, &part);
|
||||||
@ -1302,7 +1304,8 @@ static int Font_SysTextWidth(struct DrawTextArgs* args) {
|
|||||||
static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
|
static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
|
||||||
struct FontDesc* font = args->font;
|
struct FontDesc* font = args->font;
|
||||||
cc_string left = args->text, part;
|
cc_string left = args->text, part;
|
||||||
BitmapCol color = Drawer2D.Colors['f'];
|
BitmapCol color;
|
||||||
|
char colorCode = 'f';
|
||||||
double xOffset = 0;
|
double xOffset = 0;
|
||||||
char hexBuffer[7];
|
char hexBuffer[7];
|
||||||
cc_string hex;
|
cc_string hex;
|
||||||
@ -1311,10 +1314,12 @@ static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int
|
|||||||
y += (args->font->height - args->font->size) / 2;
|
y += (args->font->height - args->font->size) / 2;
|
||||||
interop_SetFont(font->handle, font->size, font->flags);
|
interop_SetFont(font->handle, font->size, font->flags);
|
||||||
|
|
||||||
while (Drawer2D_UNSAFE_NextPart(&left, &part, &color))
|
while (Drawer2D_UNSAFE_NextPart(&left, &part, &colorCode))
|
||||||
{
|
{
|
||||||
char buffer[NATIVE_STR_LEN];
|
char buffer[NATIVE_STR_LEN];
|
||||||
int len = Platform_EncodeUtf8(buffer, &part);
|
int len = Platform_EncodeUtf8(buffer, &part);
|
||||||
|
|
||||||
|
color = Drawer2D_GetColor(colorCode);
|
||||||
if (shadow) color = GetShadowColor(color);
|
if (shadow) color = GetShadowColor(color);
|
||||||
|
|
||||||
String_InitArray(hex, hexBuffer);
|
String_InitArray(hex, hexBuffer);
|
||||||
|
@ -91,7 +91,7 @@ void Drawer2D_WithoutColors(cc_string* str, const cc_string* src);
|
|||||||
char Drawer2D_LastColor(const cc_string* text, int start);
|
char Drawer2D_LastColor(const cc_string* text, int start);
|
||||||
/* Returns whether the color code is f, F or \0 */
|
/* Returns whether the color code is f, F or \0 */
|
||||||
cc_bool Drawer2D_IsWhiteColor(char c);
|
cc_bool Drawer2D_IsWhiteColor(char c);
|
||||||
cc_bool Drawer2D_UNSAFE_NextPart(cc_string* left, cc_string* part, BitmapCol* color);
|
cc_bool Drawer2D_UNSAFE_NextPart(cc_string* left, cc_string* part, char* colorCode);
|
||||||
|
|
||||||
/* Allocates a new instance of the default font using the given size and flags */
|
/* Allocates a new instance of the default font using the given size and flags */
|
||||||
/* Uses Font_MakeBitmapped or SysFont_MakeDefault depending on Drawer2D_BitmappedText */
|
/* Uses Font_MakeBitmapped or SysFont_MakeDefault depending on Drawer2D_BitmappedText */
|
||||||
|
@ -250,13 +250,14 @@ static NSString* ToNSString(const cc_string* text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NSMutableAttributedString* ToAttributedString(const cc_string* text) {
|
static NSMutableAttributedString* ToAttributedString(const cc_string* text) {
|
||||||
cc_string left = *text, part;
|
cc_string left = *text, part;
|
||||||
BitmapCol color = Drawer2D.Colors['f'];
|
char colorCode = 'f';
|
||||||
NSMutableAttributedString* str = [[NSMutableAttributedString alloc] init];
|
NSMutableAttributedString* str = [[NSMutableAttributedString alloc] init];
|
||||||
|
|
||||||
while (Drawer2D_UNSAFE_NextPart(&left, &part, &color))
|
while (Drawer2D_UNSAFE_NextPart(&left, &part, &colorCode))
|
||||||
{
|
{
|
||||||
NSString* bit = ToNSString(&part);
|
BitmapCol color = Drawer2D_GetColor(colorCode);
|
||||||
|
NSString* bit = ToNSString(&part);
|
||||||
NSDictionary* attrs =
|
NSDictionary* attrs =
|
||||||
@{
|
@{
|
||||||
//NSFontAttributeName : font,
|
//NSFontAttributeName : font,
|
||||||
@ -766,14 +767,15 @@ void interop_SysFontFree(void* handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int interop_SysTextWidth(struct DrawTextArgs* args) {
|
int interop_SysTextWidth(struct DrawTextArgs* args) {
|
||||||
UIFont* font = (__bridge UIFont*)args->font->handle;
|
UIFont* font = (__bridge UIFont*)args->font->handle;
|
||||||
cc_string left = args->text, part;
|
cc_string left = args->text, part;
|
||||||
BitmapCol color = Drawer2D.Colors['f'];
|
char colorCode = 'f';
|
||||||
NSMutableAttributedString* str = [[NSMutableAttributedString alloc] init];
|
NSMutableAttributedString* str = [[NSMutableAttributedString alloc] init];
|
||||||
|
|
||||||
while (Drawer2D_UNSAFE_NextPart(&left, &part, &color))
|
while (Drawer2D_UNSAFE_NextPart(&left, &part, &colorCode))
|
||||||
{
|
{
|
||||||
NSString* bit = ToNSString(&part);
|
BitmapCol color = Drawer2D_GetColor(colorCode);
|
||||||
|
NSString* bit = ToNSString(&part);
|
||||||
NSDictionary* attrs =
|
NSDictionary* attrs =
|
||||||
@{
|
@{
|
||||||
NSFontAttributeName : font,
|
NSFontAttributeName : font,
|
||||||
@ -792,14 +794,15 @@ int interop_SysTextWidth(struct DrawTextArgs* args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void interop_SysTextDraw(struct DrawTextArgs* args, struct Context2D* ctx, int x, int y, cc_bool shadow) {
|
void interop_SysTextDraw(struct DrawTextArgs* args, struct Context2D* ctx, int x, int y, cc_bool shadow) {
|
||||||
UIFont* font = (__bridge UIFont*)args->font->handle;
|
UIFont* font = (__bridge UIFont*)args->font->handle;
|
||||||
cc_string left = args->text, part;
|
cc_string left = args->text, part;
|
||||||
BitmapCol color = Drawer2D.Colors['f'];
|
char colorCode = 'f';
|
||||||
NSMutableAttributedString* str = [[NSMutableAttributedString alloc] init];
|
NSMutableAttributedString* str = [[NSMutableAttributedString alloc] init];
|
||||||
|
|
||||||
while (Drawer2D_UNSAFE_NextPart(&left, &part, &color))
|
while (Drawer2D_UNSAFE_NextPart(&left, &part, &colorCode))
|
||||||
{
|
{
|
||||||
NSString* bit = ToNSString(&part);
|
BitmapCol color = Drawer2D_GetColor(colorCode);
|
||||||
|
NSString* bit = ToNSString(&part);
|
||||||
NSDictionary* attrs =
|
NSDictionary* attrs =
|
||||||
@{
|
@{
|
||||||
NSFontAttributeName : font,
|
NSFontAttributeName : font,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user