feat: added renderscale and reorganized initialisation
This commit is contained in:
parent
04a612e0c1
commit
e7d11d4551
42
src/main.c
42
src/main.c
|
@ -1,4 +1,5 @@
|
||||||
#include <SDL3/SDL_hints.h>
|
#include <SDL3/SDL_hints.h>
|
||||||
|
#include <SDL3/SDL_oldnames.h>
|
||||||
#include <clay/clay.h>
|
#include <clay/clay.h>
|
||||||
#include "renderer/clay_renderer_SDL3.h"
|
#include "renderer/clay_renderer_SDL3.h"
|
||||||
|
|
||||||
|
@ -22,6 +23,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
constexpr SDL_InitFlags sdlInitFlags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY;
|
||||||
|
|
||||||
SDL_Window *window = nullptr;
|
SDL_Window *window = nullptr;
|
||||||
SDL_Renderer *renderer = nullptr;
|
SDL_Renderer *renderer = nullptr;
|
||||||
int screenWidth = 1920, screenHeight = 1080;
|
int screenWidth = 1920, screenHeight = 1080;
|
||||||
|
@ -58,6 +61,22 @@ void HandleClayErrors(Clay_ErrorData data) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", data.errorText.chars);
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", data.errorText.chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void InitFonts() {
|
||||||
|
fonts[FONT_DEFAULT] = TTF_OpenFont("assets/AdwaitaSans-Regular.ttf", baseFontSize * 5);
|
||||||
|
if (fonts[FONT_DEFAULT] == nullptr) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_OpenFont failed: Failed to load adwaita sans: %s", SDL_GetError());
|
||||||
|
exit(6);
|
||||||
|
}
|
||||||
|
TTF_SetFontHinting(fonts[FONT_DEFAULT], TTF_HINTING_LIGHT_SUBPIXEL);
|
||||||
|
fonts[FONT_BOLD] = TTF_OpenFont("assets/AdwaitaSans-Regular.ttf", baseFontSize * 5);
|
||||||
|
if (fonts[FONT_BOLD] == nullptr) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_OpenFont failed: Failed to load adwaita sans bold: %s", SDL_GetError());
|
||||||
|
exit(7);
|
||||||
|
}
|
||||||
|
TTF_SetFontHinting(fonts[FONT_BOLD], TTF_HINTING_LIGHT_SUBPIXEL);
|
||||||
|
TTF_SetFontStyle(fonts[FONT_BOLD], TTF_STYLE_BOLD);
|
||||||
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
void InitSDL() {
|
void InitSDL() {
|
||||||
SDL_SetHint(SDL_HINT_RENDER_LINE_METHOD, "3");
|
SDL_SetHint(SDL_HINT_RENDER_LINE_METHOD, "3");
|
||||||
|
@ -65,7 +84,7 @@ void InitSDL() {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_Init failed: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_Init failed: %s", SDL_GetError());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if ((window = SDL_CreateWindow("Window", screenWidth, screenHeight, SDL_WINDOW_RESIZABLE)) == nullptr) {
|
if ((window = SDL_CreateWindow("Window", screenWidth, screenHeight, sdlInitFlags)) == nullptr) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_CreateWindow failed: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_CreateWindow failed: %s", SDL_GetError());
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
@ -81,18 +100,11 @@ void InitSDL() {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_CreateRendererTextEngine failed: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_CreateRendererTextEngine failed: %s", SDL_GetError());
|
||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
fonts[FONT_DEFAULT] = TTF_OpenFont("assets/AdwaitaSans-Regular.ttf", baseFontSize * 5);
|
SDL_SetRenderScale(renderer, 1.0/renderScale, 1.0/renderScale);
|
||||||
if (fonts[FONT_DEFAULT] == nullptr) {
|
InitFonts();
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_OpenFont failed: Failed to load adwaita sans: %s", SDL_GetError());
|
int w, h;
|
||||||
exit(6);
|
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
|
||||||
}
|
SDL_Log("output size: %i, %d", w, h);
|
||||||
fonts[FONT_BOLD] = TTF_OpenFont("assets/AdwaitaSans-Regular.ttf", baseFontSize * 5);
|
|
||||||
if (fonts[FONT_BOLD] == nullptr) {
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_OpenFont failed: Failed to load adwaita sans bold: %s", SDL_GetError());
|
|
||||||
exit(6);
|
|
||||||
} else {
|
|
||||||
TTF_SetFontStyle(fonts[FONT_BOLD], TTF_STYLE_BOLD);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -125,8 +137,8 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_WINDOW_RESIZED:
|
case SDL_EVENT_WINDOW_RESIZED:
|
||||||
Clay_SetLayoutDimensions((Clay_Dimensions){
|
Clay_SetLayoutDimensions((Clay_Dimensions){
|
||||||
event.window.data1,
|
event.window.data1 * (double)renderScale,
|
||||||
event.window.data2
|
event.window.data2 * (double)renderScale
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_MOUSE_WHEEL:
|
case SDL_EVENT_MOUSE_WHEEL:
|
||||||
|
|
19
src/style.h
19
src/style.h
|
@ -5,14 +5,16 @@
|
||||||
#include <clay/clay.h>
|
#include <clay/clay.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
constexpr int renderScale = 1;
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
// CONTAINER STYLE
|
// CONTAINER STYLE
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
|
||||||
constexpr uint16_t containerGap = 5;
|
constexpr uint16_t containerGap = 5 * renderScale;
|
||||||
constexpr Clay_Padding containerPadding = {
|
constexpr Clay_Padding containerPadding = {
|
||||||
32, 32,
|
32 * renderScale, 32 * renderScale,
|
||||||
16, 16
|
16 * renderScale, 16 * renderScale
|
||||||
};
|
};
|
||||||
constexpr Clay_Color containerColors[] = {
|
constexpr Clay_Color containerColors[] = {
|
||||||
{ 255*0.25, 255*0.25, 255*0.25, 255 },
|
{ 255*0.25, 255*0.25, 255*0.25, 255 },
|
||||||
|
@ -25,7 +27,7 @@ constexpr Clay_Sizing layoutExpand = {
|
||||||
.height = CLAY_SIZING_GROW(0)
|
.height = CLAY_SIZING_GROW(0)
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr float defaultRadius = 5.f;
|
constexpr double defaultRadius = 5.0 * renderScale;
|
||||||
constexpr Clay_CornerRadius defaultRadiusAll = {
|
constexpr Clay_CornerRadius defaultRadiusAll = {
|
||||||
defaultRadius, defaultRadius,
|
defaultRadius, defaultRadius,
|
||||||
defaultRadius, defaultRadius
|
defaultRadius, defaultRadius
|
||||||
|
@ -40,7 +42,7 @@ backgroundColor = containerColors[depth_],\
|
||||||
// WINDOW STYLE
|
// WINDOW STYLE
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
|
||||||
constexpr float windowPadding = 5;
|
constexpr uint16_t windowPadding = containerGap;
|
||||||
constexpr Clay_Color windowBackground = {
|
constexpr Clay_Color windowBackground = {
|
||||||
255*0.35, 255*0.35, 255*0.35, 255
|
255*0.35, 255*0.35, 255*0.35, 255
|
||||||
};
|
};
|
||||||
|
@ -58,8 +60,8 @@ constexpr Clay_ElementDeclaration windowStyle = {
|
||||||
// TEXT STYLE
|
// TEXT STYLE
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
|
||||||
constexpr float paragraphGap = 10;
|
constexpr float paragraphGap = 10 * renderScale;
|
||||||
constexpr uint16_t baseFontSize = 16;
|
constexpr uint16_t baseFontSize = 16 * renderScale;
|
||||||
|
|
||||||
constexpr Clay_Color textColors[] = {
|
constexpr Clay_Color textColors[] = {
|
||||||
{ 250, 250, 250, 255 },
|
{ 250, 250, 250, 255 },
|
||||||
|
@ -68,7 +70,8 @@ constexpr Clay_Color textColors[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr uint16_t headerSizes[] = {
|
constexpr uint16_t headerSizes[] = {
|
||||||
64, 32, 28, 16
|
64 * renderScale, 32 * renderScale,
|
||||||
|
28 * renderScale, 16 * renderScale
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TEXT_STYLE(color_)\
|
#define TEXT_STYLE(color_)\
|
||||||
|
|
Loading…
Reference in a new issue