src/ascension/context.h

changeset 65
9c44c55d327a
parent 63
e3cacdd636e4
child 66
8297afa1c29c
     1.1 --- a/src/ascension/context.h	Thu Apr 18 21:53:53 2024 +0200
     1.2 +++ b/src/ascension/context.h	Thu Apr 18 22:53:55 2024 +0200
     1.3 @@ -52,10 +52,11 @@
     1.4      CxBuffer error_buffer;
     1.5      AscInput input;
     1.6      AscWindow windows[ASC_MAX_WINDOWS];
     1.7 -    AscWindow *active_window;
     1.8 +    // TODO: rework how fonts are cached
     1.9      AscFont fonts[ASC_MAX_FONTS];
    1.10 -    unsigned int fonts_loaded;
    1.11 -    AscFont const *active_font;
    1.12 +    unsigned char fonts_loaded;
    1.13 +    unsigned char active_window;
    1.14 +    unsigned char active_font;
    1.15      asc_col4i ink;
    1.16      uint64_t frame_nanos;
    1.17      uint64_t total_nanos;
    1.18 @@ -64,6 +65,29 @@
    1.19  /** Global ascension context. */
    1.20  extern AscContext asc_context;
    1.21  
    1.22 +/**
    1.23 + * The currently active font.
    1.24 + * @see asc_font()
    1.25 + */
    1.26 +#define asc_active_font \
    1.27 +    (&asc_context.fonts[asc_context.active_font])
    1.28 +
    1.29 +/**
    1.30 + * The currently active window in the context.
    1.31 + * @see asc_window_activate()
    1.32 + */
    1.33 +#define asc_active_window \
    1.34 +    (&asc_context.windows[asc_context.active_window])
    1.35 +
    1.36 +static inline bool asc_assert_active_window() {
    1.37 +    if (asc_context.active_window < ASC_MAX_WINDOWS) {
    1.38 +        return true;
    1.39 +    } else {
    1.40 +        asc_error("A graphics operation was performed without active window");
    1.41 +        return false;
    1.42 +    }
    1.43 +}
    1.44 +
    1.45  void asc_context_initialize(void);
    1.46  void asc_context_destroy(void);
    1.47  
    1.48 @@ -86,10 +110,5 @@
    1.49  #define asc_ink_rgba(r,g,b,a) asc_context.ink = (asc_col4i){(r),(g),(b),(a)}
    1.50  #define asc_ink_rgb(r,g,b) asc_context.ink = (asc_col4i){(r),(g),(b),255u}
    1.51  
    1.52 -/**
    1.53 - * Sets the active drawing font.
    1.54 - */
    1.55 -#define asc_set_font(font) asc_context.active_font = (font)
    1.56 -
    1.57  #endif /* ASCENSION_CONTEXT_H */
    1.58  

mercurial