sdl3 migrate now compiling, need to go through all the files and clean them up
This commit is contained in:
parent
df4390ddba
commit
1b2e2cb7f1
26 changed files with 1139 additions and 0 deletions
66
packages/graphics/sdl3/text.c
Normal file
66
packages/graphics/sdl3/text.c
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <SDL3_ttf/SDL_ttf.h>
|
||||
|
||||
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 };
|
||||
|
||||
//TODO: fix this
|
||||
if(TTF_Init() == false) {
|
||||
printf("TTF_Init: %s\n", SDL_GetError());
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
void ARC_Text_Destroy(ARC_Text *font){
|
||||
if(font->texture != NULL){
|
||||
SDL_DestroyTexture(font->texture);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
|
||||
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_DestroySurface(surface);
|
||||
TTF_CloseFont(ttfont);
|
||||
}
|
||||
|
||||
void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer){
|
||||
if(text->texture == NULL){
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_FRect bounds = (SDL_FRect){ text->bounds.x, text->bounds.y, text->bounds.w, text->bounds.h };
|
||||
SDL_RenderTexture((SDL_Renderer *)renderer, text->texture, NULL, &bounds);
|
||||
}
|
||||
|
||||
void ARC_Text_SetPos(ARC_Text *text, ARC_Point pos){
|
||||
text->bounds.x = pos.x;
|
||||
text->bounds.y = pos.y;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue