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

@ -62,6 +62,21 @@ void ARC_Renderer_InitBuffer(ARC_Renderer *renderer, uint32_t zIndex);
*/
void ARC_Renderer_RemoveBuffer(ARC_Renderer *renderer, uint32_t zIndex);
/**
* @brief
*
* @param renderer
* @param zIndex
*/
void ARC_Renderer_RenderBuffer(ARC_Renderer *renderer, uint32_t zIndex);
/**
* @brief
*
* @param renderer
*/
void ARC_Renderer_RenderBuffers(ARC_Renderer *renderer);
/**
* @brief
*

View file

@ -9,18 +9,43 @@ extern "C" {
#include "arc/graphics/color.h"
#include "arc/graphics/renderer.h"
#include "arc/math/point.h"
#include "arc/math/rectangle.h"
#include "arc/std/string.h"
typedef struct ARC_Text ARC_Text;
typedef struct ARC_Text {
ARC_String *name;
int32_t fontSize;
ARC_FRect bounds;
ARC_Color color;
void *backendData;
} ARC_Text;
/**
* @brief
*/
void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color color);
void ARC_Text_Destroy(ARC_Text *font);
/**
* @brief
*/
void ARC_Text_Destroy(ARC_Text *text);
/**
* @brief
*/
void ARC_Text_SetString(ARC_Text *text, ARC_Renderer *renderer, ARC_String *string);
/**
* @brief
*/
void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer);
/**
* @brief
*/
void ARC_Text_SetPos(ARC_Text *text, ARC_Point pos);
#ifdef __cplusplus

View file

@ -206,8 +206,9 @@ void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type){
ARC_String_CreateWithStrlen(&spritesheetName, pointerCString);
ARC_String_AppendCStringWithStrlen(&spritesheetName, "ARC_Spritesheet");
//TODO: FIX THIS
//remove the spritesheet from the config (it won't error if it doesn't exist)
ARC_Config_RemoveWithCStr(config, spritesheetName->data, ARC_False);
//ARC_Config_RemoveWithCStr(config, spritesheetName->data, ARC_False);
/* ~ ARC_FRect Array ~ */
//create a name based on the type and the sprite pointer to have a unique name for cleanup on remove
@ -215,8 +216,9 @@ void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type){
ARC_String_CreateWithStrlen(&boundsName, pointerCString);
ARC_String_AppendCStringWithStrlen(&boundsName, "ARC_FRect");
//TODO: FIX THIS
//remove the ARC_FRect from the config (it won't error if it doesn't exist)
ARC_Config_RemoveWithCStr(config, boundsName->data, ARC_False);
//ARC_Config_RemoveWithCStr(config, boundsName->data, ARC_False);
//cleanup
ARC_String_Destroy(boundsName);

View file

@ -62,6 +62,8 @@ void ARC_Renderer_Clear(ARC_Renderer *renderer){
SDL_SetRenderTarget(renderer->renderer, NULL);
SDL_SetRenderDrawColor(renderer->renderer, renderer->clearColor.r, renderer->clearColor.g, renderer->clearColor.b, renderer->clearColor.a);
SDL_RenderClear(renderer->renderer);
ARC_Renderer_ClearBuffers(renderer);
}
void ARC_Renderer_Render(ARC_Renderer *renderer){
@ -90,6 +92,20 @@ void ARC_Renderer_RemoveBuffer(ARC_Renderer *renderer, uint32_t zIndex){
ARC_Hashtable_Remove(renderer->buffers, &zIndex);
}
void ARC_Renderer_RenderBuffer(ARC_Renderer *renderer, uint32_t zIndex){
SDL_Texture *buffer = (SDL_Texture *)ARC_Hashtable_Get(renderer->buffers, &zIndex);
SDL_RenderTexture(renderer->renderer, buffer, NULL, NULL);
}
//TODO: write this
void ARC_Renderer_BuffersHashtableRenderIteratorFn(void *key, void *value, void *userData){
}
//TODO: write this
void ARC_Renderer_RenderBuffers(ARC_Renderer *renderer){
}
//private function to iterate and clear each available buffer
void ARC_Renderer_BuffersHashtableClearIteratorFn(void *key, void *value, void *userData){
ARC_Renderer *renderer = (ARC_Renderer *)userData;

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){

View file

@ -1,20 +0,0 @@
#ifndef ARC_SDL_TEXT_H_
#define ARC_SDL_TEXT_H_
#include "arc/std/string.h"
#include "arc/graphics/color.h"
#include "arc/math/rectangle.h"
#include <SDL3/SDL.h>
typedef struct ARC_Text {
ARC_String *name;
int32_t size;
ARC_Color color;
SDL_Texture *texture;
ARC_Rect bounds;
} ARC_Text;
#endif // !ARC_SDL_TEXT_H_

View file

@ -358,7 +358,10 @@ void ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
//copy the last value and free the temp value
ARC_FRect *point = (ARC_FRect *)malloc(sizeof(ARC_FPoint));
*point = (ARC_FRect){ pointX, pointY, pointW, *pointTemp };
point->x = pointX;
point->y = pointY;
point->w = pointW;
point->h = *pointTemp;
free(pointTemp);
//set the type value

View file

@ -1428,7 +1428,8 @@ void ARC_ConfigType_DoubleDestroyFn(ARC_Config *config, void *type){
}
void ARC_ConfigType_StringCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
if(parsedData->id != ARC_CONFIG_STRING){
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
if(childTagToken->id != ARC_CONFIG_STRING){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_StringCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), string was not passed in for ARC_String");
type = NULL;
@ -1436,7 +1437,8 @@ void ARC_ConfigType_StringCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
}
//get the string chars between the quotes
ARC_ParserTagToken *stringCharsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 1);
ARC_ParserTagToken *stringCharsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 1);
ARC_String_Create((ARC_String **)type, NULL, 0);
ARC_ParserData_HelperRecurseStringAdd((ARC_String **)type, stringCharsTagToken);
}