Backdrop Path + Cybersteel (#23)
Co-authored-by: Zachary Levy <zachary@sunforge.is> Reviewed-on: #23
This commit was merged in pull request #23.
This commit is contained in:
+11
-3
@@ -8,21 +8,25 @@ import sdl_ttf "vendor:sdl3/ttf"
|
||||
|
||||
Font_Id :: u16
|
||||
|
||||
//INTERNAL
|
||||
Font_Key :: struct {
|
||||
id: Font_Id,
|
||||
size: u16,
|
||||
}
|
||||
|
||||
//INTERNAL
|
||||
Cache_Source :: enum u8 {
|
||||
Custom,
|
||||
Clay,
|
||||
}
|
||||
|
||||
//INTERNAL
|
||||
Cache_Key :: struct {
|
||||
id: u32,
|
||||
source: Cache_Source,
|
||||
}
|
||||
|
||||
//INTERNAL
|
||||
Text_Cache :: struct {
|
||||
engine: ^sdl_ttf.TextEngine,
|
||||
font_bytes: [dynamic][]u8,
|
||||
@@ -30,7 +34,8 @@ Text_Cache :: struct {
|
||||
cache: map[Cache_Key]^sdl_ttf.Text,
|
||||
}
|
||||
|
||||
// Internal for fetching SDL TTF font pointer for rendering
|
||||
// Fetch SDL TTF font pointer for rendering.
|
||||
//INTERNAL
|
||||
get_font :: proc(id: Font_Id, size: u16) -> ^sdl_ttf.Font {
|
||||
assert(int(id) < len(GLOB.text_cache.font_bytes), "Invalid font ID.")
|
||||
key := Font_Key{id, size}
|
||||
@@ -77,6 +82,7 @@ register_font :: proc(bytes: []u8) -> (id: Font_Id, ok: bool) #optional_ok {
|
||||
return Font_Id(len(GLOB.text_cache.font_bytes) - 1), true
|
||||
}
|
||||
|
||||
//INTERNAL
|
||||
Text :: struct {
|
||||
sdl_text: ^sdl_ttf.Text,
|
||||
position: Vec2,
|
||||
@@ -89,7 +95,7 @@ Text :: struct {
|
||||
|
||||
// Shared cache lookup/create/update logic used by both the `text` proc and the Clay render path.
|
||||
// Returns the cached (or newly created) TTF_Text pointer.
|
||||
@(private)
|
||||
//INTERNAL
|
||||
cache_get_or_update :: proc(key: Cache_Key, c_str: cstring, font: ^sdl_ttf.Font) -> ^sdl_ttf.Text {
|
||||
existing, found := GLOB.text_cache.cache[key]
|
||||
if !found {
|
||||
@@ -268,7 +274,8 @@ clear_text_cache_entry :: proc(id: u32) {
|
||||
// ----- Internal cache lifecycle ------
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@(private, require_results)
|
||||
//INTERNAL
|
||||
@(require_results)
|
||||
init_text_cache :: proc(
|
||||
device: ^sdl.GPUDevice,
|
||||
allocator := context.allocator,
|
||||
@@ -299,6 +306,7 @@ init_text_cache :: proc(
|
||||
return text_cache, true
|
||||
}
|
||||
|
||||
//INTERNAL
|
||||
destroy_text_cache :: proc() {
|
||||
for _, font in GLOB.text_cache.sdl_fonts {
|
||||
sdl_ttf.CloseFont(font)
|
||||
|
||||
Reference in New Issue
Block a user