Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluggable text-renderer #741

Open
katajakasa opened this issue Nov 3, 2024 · 0 comments
Open

Pluggable text-renderer #741

katajakasa opened this issue Nov 3, 2024 · 0 comments

Comments

@katajakasa
Copy link
Member

katajakasa commented Nov 3, 2024

Make the text renderer pluggable, with support for multiple platforms. This idea is slightly extended from the N64 port:

# This replaces the text_settings struct.
typedef struct textbox {
    bool dirty;
    void *userdata;
    
    char *data;
    size_t len;
    
    text_valign valign;
    text_halign halign;
    // ... and all the other options
} textbox;

typedef struct text_engine {
    init_cb init;
    render_cb render; // Called to generate the layout and do the render
    close_cb close; // Called when shutting down the renderer (app exit, renderer change)
} text_engine;

// First, initialize any engine we have. One of these:
// These will set the callback pointers to text_engine.
text_engine engine;
void freetype_engine_init(&engine);
void monospace_engine_init(&engine); // Our old thing

// Then, set it to be used. This would set static variable.
void renderer_engine_set(&engine);

// These replace the old text_settings struct
// Calling any of these sets the dirty = true flag,
void textbox_create(textbox *box);
void textbox_create_with(textbox *box, /* other options for single line call */);
void textbox_from_c(textbox *box, const char *src);
void textbox_from_str(textbox *box, const str *src);
void textbox_set_valign(textbox *box, text_valign valign);

// Calls the text_engine.render(). Render would check if dirty is set, and would do the layout thing
// and set the userdata pointer with cached data (whatever it is). Then just call video renderer with
// whatever needs to be done.
void textbox_render(textbox *box);
@katajakasa katajakasa changed the title Pluggable font-renderer Pluggable text-renderer Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant