Просмотр исходного кода

Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop

pull/75/head
Joshua Reisenauer 10 лет назад
Родитель
Сommit
e624973200
2 измененных файлов: 29 добавлений и 7 удалений
  1. +28
    -6
      src/text.c
  2. +1
    -1
      src/textures.c

+ 28
- 6
src/text.c Просмотреть файл

@ -256,7 +256,7 @@ SpriteFont LoadSpriteFont(const char *fileName)
}
else
{
TraceLog(WARNING, "[%s] SpriteFont could not be loaded, using default font", fileName, numChars);
TraceLog(WARNING, "[%s] SpriteFont could not be loaded, using default font", fileName);
spriteFont = GetDefaultFont();
}
@ -378,20 +378,42 @@ int MeasureText(const char *text, int fontSize)
Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing)
{
int len = strlen(text);
int tempLen = 0; // Used to count longer text line num chars
int lenCounter = 0;
int textWidth = 0;
int tempTextWidth = 0; // Used to count longer text line width
int textHeight = spriteFont.size;
float scaleFactor;
for (int i = 0; i < len; i++)
{
if (text[i] != '\n') textWidth += spriteFont.charRecs[(int)text[i] - FONT_FIRST_CHAR].width;
lenCounter++;
if (text[i] != '\n')
{
textWidth += spriteFont.charRecs[(int)text[i] - FONT_FIRST_CHAR].width;
}
else
{
if (tempTextWidth < textWidth) tempTextWidth = textWidth;
lenCounter = 0;
textWidth = 0;
textHeight += (spriteFont.size + spriteFont.size/2);
}
if (tempLen < lenCounter) tempLen = lenCounter;
}
if (tempTextWidth < textWidth) tempTextWidth = textWidth;
if (fontSize <= spriteFont.charRecs[0].height) scaleFactor = 1.0f;
else scaleFactor = (float)fontSize / spriteFont.charRecs[0].height;
if (fontSize <= spriteFont.size) scaleFactor = 1.0f;
else scaleFactor = (float)fontSize/spriteFont.size;
Vector2 vec;
vec.x = (float)textWidth * scaleFactor + (len - 1) * spacing; // Adds chars spacing to measure
vec.y = (float)spriteFont.charRecs[0].height * scaleFactor;
vec.x = (float)tempTextWidth*scaleFactor + (tempLen - 1)*spacing; // Adds chars spacing to measure
vec.y = (float)textHeight*scaleFactor;
return vec;
}

+ 1
- 1
src/textures.c Просмотреть файл

@ -1206,7 +1206,7 @@ void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float sc
// Draw a part of a texture (defined by a rectangle)
void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint)
{
Rectangle destRec = { (int)position.x, (int)position.y, sourceRec.width, sourceRec.height };
Rectangle destRec = { (int)position.x, (int)position.y, abs(sourceRec.width), abs(sourceRec.height) };
Vector2 origin = { 0, 0 };
DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint);

Загрузка…
Отмена
Сохранить