src/ascension/ui/font.h

Sun, 22 Jun 2025 11:15:53 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 22 Jun 2025 11:15:53 +0200
changeset 162
d3598c834f9b
parent 145
a3231310d66d
permissions
-rw-r--r--

improve NULL-safety - fixes #690

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * Copyright 2023 Mike Becker. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef ASCENSION_FONT_H
#define ASCENSION_FONT_H

#include <SDL2/SDL_ttf.h>

enum AscFontStyle {
    ASC_FONT_REGULAR,
    ASC_FONT_BOLD,
    ASC_FONT_ITALIC,
    ASC_FONT_BOLD_ITALIC,
};

typedef struct asc_font_s {
    /**
     * Style of the font.
     */
    enum AscFontStyle style;
    /**
     * Point size.
     */
    int size;
} AscFont;

/**
 * Activates a font with the given style and size.
 *
 * The font is cached and activated faster the next time you call this
 * function with the same arguments. However, when you reach the maximum
 * number of fonts, the cache is completely cleared and rebuilt.
 *
 * That means in general, that you should not be using too many fonts of
 * different sizes at the same time.
 *
 * @param style the style
 * @param size the point size
 */
void asc_font(enum AscFontStyle style, int size);

/**
 * Loads the specified font.
 *
 * Loaded fonts are kept within a font cache and returned faster
 * on the next invocation.
 *
 * You will almost never need to use this function on your own.
 * Ascension UI elements are loading the required fonts for you.
 *
 * @param font the font description
 * @return a pointer to the SDL TTF font handle, or @c NULL on error
 */
TTF_Font *asc_font_load(AscFont font);

#endif //ASCENSION_FONT_H

mercurial