Loading...
Searching...
No Matches
text.c File Reference
`#include "arc/graphics/text.h"`
`#include "text.h"`
`#include "arc/graphics/color.h"`
`#include "arc/math/point.h"`
`#include "arc/math/rectangle.h"`
`#include "arc/std/string.h"`
`#include <SDL2/SDL_ttf.h>`

Go to the source code of this file.

## Functions

void | ARC_Text_Create (ARC_Text **text, ARC_String *path, int32_t size, ARC_Color color)
void | ARC_Text_Destroy (ARC_Text *font)
void | ARC_Text_SetString (ARC_Text *text, ARC_Renderer *renderer, ARC_String *string)
void | ARC_Text_Render (ARC_Text *text, ARC_Renderer *renderer)
void | ARC_Text_SetPos (ARC_Text *text, ARC_Point pos)

## Function Documentation

## ARC_Text_Create()

void ARC_Text_Create | ( | ARC_Text ** | text,
|  | ARC_String * | path,
|  | int32_t | size,
|  | ARC_Color | color )

Definition at line 11 of file text.c.

{
*text = (ARC_Text *)malloc(sizeof(ARC_Text));
ARC_String_Copy(&(*text)->name, path);
(*text)->size = size;
(*text)->color = color;
(*text)->texture = NULL;
(*text)->bounds = (ARC_Rect){ 0, 0, 0, 0 };
//TODO: fix this
if(TTF_Init()==-1) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(2);
}
}
ARC_Rect
struct ARC_Rect ARC_Rect
ARC_String_Copy
void ARC_String_Copy(ARC_String **copy, ARC_String *original)
copy a ARC_String
Definition string.c:62
ARC_Text
Definition text.h:10

References ARC_String_Copy().

## ARC_Text_Destroy()

void ARC_Text_Destroy | ( | ARC_Text * | font | ) |

Definition at line 26 of file text.c.

{
if(font->texture != NULL){
SDL_DestroyTexture(font->texture);
}
ARC_String_Destroy(font->name);
free(font);
}
ARC_String_Destroy
void ARC_String_Destroy(ARC_String *string)
destroys ARC_String type
Definition string.c:52
ARC_Text::name
ARC_String * name
Definition text.h:11
ARC_Text::texture
SDL_Texture * texture
Definition text.h:16

References ARC_String_Destroy(), ARC_Text::name, and ARC_Text::texture.

## ARC_Text_Render()

void ARC_Text_Render | ( | ARC_Text * | text,
|  | ARC_Renderer * | renderer )

Definition at line 52 of file text.c.

{
if(text->texture == NULL){
return;
}
SDL_Rect bounds = (SDL_Rect){ text->bounds.x, text->bounds.y, text->bounds.w, text->bounds.h };
SDL_RenderCopy((SDL_Renderer *)renderer, text->texture, NULL, &bounds);
}
ARC_Rect::x
int32_t x
Definition rectangle.h:13
ARC_Rect::w
int32_t w
Definition rectangle.h:15
ARC_Rect::y
int32_t y
Definition rectangle.h:14
ARC_Rect::h
int32_t h
Definition rectangle.h:16
ARC_Text::bounds
ARC_Rect bounds
Definition text.h:17

References ARC_Text::bounds, ARC_Rect::h, ARC_Text::texture, ARC_Rect::w, ARC_Rect::x, and ARC_Rect::y.

## ARC_Text_SetPos()

void ARC_Text_SetPos | ( | ARC_Text * | text,
|  | ARC_Point | pos )

Definition at line 61 of file text.c.

{
text->bounds.x = pos.x;
text->bounds.y = pos.y;
}
ARC_Point::y
int32_t y
Definition point.h:12
ARC_Point::x
int32_t x
Definition point.h:11

References ARC_Text::bounds, ARC_Point::x, ARC_Rect::x, ARC_Point::y, and ARC_Rect::y.

## ARC_Text_SetString()

void ARC_Text_SetString | ( | ARC_Text * | text,
|  | ARC_Renderer * | renderer,
|  | ARC_String * | string )

Definition at line 34 of file text.c.

{
TTF_Font *ttfont = TTF_OpenFont(text->name->data, text->size);
SDL_Color textColor = (SDL_Color){ text->color.r, text->color.g, text->color.b, text->color.a };
SDL_Surface *surface = TTF_RenderText_Blended_Wrapped(ttfont, string->data, textColor, 0);
text->bounds.w = surface->w;
text->bounds.h = surface->h;
if(text->texture){
SDL_DestroyTexture(text->texture);
}
text->texture = SDL_CreateTextureFromSurface((SDL_Renderer *)renderer, surface);
SDL_FreeSurface(surface);
TTF_CloseFont(ttfont);
}
ARC_Color::a
uint8_t a
Definition color.h:11
ARC_Color::r
uint8_t r
Definition color.h:11
ARC_Color::b
uint8_t b
Definition color.h:11
ARC_Color::g
uint8_t g
Definition color.h:11
ARC_String::data
char * data
Definition string.h:15
ARC_Text::color
ARC_Color color
Definition text.h:14
ARC_Text::size
int32_t size
Definition text.h:12

References ARC_Color::a, ARC_Color::b, ARC_Text::bounds, ARC_Text::color, ARC_String::data, ARC_Color::g, ARC_Rect::h, ARC_Text::name, ARC_Color::r, ARC_Text::size, ARC_Text::texture, and ARC_Rect::w.