fixed ARC_String, worked on ARC_Text, and did some stuff with buffers

This commit is contained in:
herbglitch 2025-04-11 04:34:00 -06:00
parent 21a66f7fe6
commit d01d78972e
8 changed files with 86 additions and 41 deletions

View file

@ -1,6 +1,5 @@
#include "arc/graphics/text.h"
#include "text.h"
#include "renderer.h"
#include "arc/graphics/color.h"
#include "arc/math/point.h"
@ -13,11 +12,13 @@
void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color color){
*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 };
(*text)->fontSize = size;
(*text)->bounds = (ARC_FRect){ 0.0f, 0.0f, 0.0f, 0.0f };
(*text)->color = color;
(*text)->backendData = NULL;
//TODO: fix this
if(TTF_Init() == false) {
@ -27,15 +28,16 @@ void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color
}
void ARC_Text_Destroy(ARC_Text *font){
if(font->texture != NULL){
SDL_DestroyTexture(font->texture);
if(font->backendData != NULL){
SDL_DestroyTexture((SDL_Texture *)font->backendData);
}
ARC_String_Destroy(font->name);
free(font);
}
void ARC_Text_SetString(ARC_Text *text, ARC_Renderer *renderer, ARC_String *string){
TTF_Font *ttfont = TTF_OpenFont(text->name->data, text->size);
TTF_Font *ttfont = TTF_OpenFont(text->name->data, text->fontSize);
SDL_Color textColor = (SDL_Color){ text->color.r, text->color.g, text->color.b, text->color.a };
SDL_Surface *surface = TTF_RenderText_Blended(ttfont, string->data, 0, textColor);
@ -43,22 +45,22 @@ void ARC_Text_SetString(ARC_Text *text, ARC_Renderer *renderer, ARC_String *stri
text->bounds.w = surface->w;
text->bounds.h = surface->h;
if(text->texture){
SDL_DestroyTexture(text->texture);
if(text->backendData != NULL){
SDL_DestroyTexture((SDL_Texture *)text->backendData);
}
text->texture = SDL_CreateTextureFromSurface(renderer->renderer, surface);
text->backendData = (void *)SDL_CreateTextureFromSurface(renderer->renderer, surface);
SDL_DestroySurface(surface);
TTF_CloseFont(ttfont);
}
void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer){
if(text->texture == NULL){
if(text->backendData == NULL){
return;
}
SDL_FRect bounds = (SDL_FRect){ text->bounds.x, text->bounds.y, text->bounds.w, text->bounds.h };
SDL_RenderTexture(renderer->renderer, text->texture, NULL, &bounds);
SDL_RenderTexture(renderer->renderer, (SDL_Texture *)(text->backendData), NULL, &bounds);
}
void ARC_Text_SetPos(ARC_Text *text, ARC_Point pos){