mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-19 04:38:01 +00:00
fix accidental change of SDL2 renderer
This commit is contained in:
parent
ecf00251bf
commit
cbdfc63c2a
@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.27)
|
|||||||
|
|
||||||
# Project setup
|
# Project setup
|
||||||
project(clay_examples_sdl3_simple_demo C)
|
project(clay_examples_sdl3_simple_demo C)
|
||||||
|
set(CMAKE_C_STANDARD 99)
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -Wall -Werror")
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -Wall -Werror")
|
||||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
|
||||||
|
|
||||||
|
@ -4,39 +4,6 @@
|
|||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static void SDL_RenderClayCommands(SDL_Renderer *renderer, Clay_RenderCommandArray *rcommands)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < rcommands->length; i++) {
|
|
||||||
Clay_RenderCommand *rcmd = Clay_RenderCommandArray_Get(rcommands, i);
|
|
||||||
Clay_BoundingBox bounding_box = rcmd->boundingBox;
|
|
||||||
SDL_FRect rect = { bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height };
|
|
||||||
|
|
||||||
switch (rcmd->commandType) {
|
|
||||||
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
|
||||||
Clay_RectangleElementConfig *config = rcmd->config.rectangleElementConfig;
|
|
||||||
Clay_Color color = config->color;
|
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
|
||||||
} break;
|
|
||||||
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
|
||||||
Clay_TextElementConfig *config = rcmd->config.textElementConfig;
|
|
||||||
Clay_String *text = &rcmd->text;
|
|
||||||
SDL_Color color = { config->textColor.r, config->textColor.g, config->textColor.b, config->textColor.a };
|
|
||||||
|
|
||||||
TTF_Font *font = gFonts[config->fontId];
|
|
||||||
SDL_Surface *surface = TTF_RenderText_Blended(font, text->chars, text->length, color);
|
|
||||||
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
|
||||||
SDL_RenderTexture(renderer, texture, NULL, &rect);
|
|
||||||
|
|
||||||
SDL_DestroySurface(surface);
|
|
||||||
SDL_DestroyTexture(texture);
|
|
||||||
} break;
|
|
||||||
default:
|
|
||||||
SDL_Log("Unknown render command type: %d", rcmd->commandType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CLAY_COLOR_TO_SDL_COLOR_ARGS(color) color.r, color.g, color.b, color.a
|
#define CLAY_COLOR_TO_SDL_COLOR_ARGS(color) color.r, color.g, color.b, color.a
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -12,7 +12,7 @@ static void SDL_RenderClayCommands(SDL_Renderer *renderer, Clay_RenderCommandArr
|
|||||||
for (size_t i = 0; i < rcommands->length; i++) {
|
for (size_t i = 0; i < rcommands->length; i++) {
|
||||||
Clay_RenderCommand *rcmd = Clay_RenderCommandArray_Get(rcommands, i);
|
Clay_RenderCommand *rcmd = Clay_RenderCommandArray_Get(rcommands, i);
|
||||||
Clay_BoundingBox bounding_box = rcmd->boundingBox;
|
Clay_BoundingBox bounding_box = rcmd->boundingBox;
|
||||||
SDL_FRect rect = { bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height };
|
const SDL_FRect rect = { bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height };
|
||||||
|
|
||||||
switch (rcmd->commandType) {
|
switch (rcmd->commandType) {
|
||||||
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
||||||
|
Loading…
Reference in New Issue
Block a user