src/ascension/ui/font.h

Fri, 19 Apr 2024 22:28:29 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 19 Apr 2024 22:28:29 +0200
changeset 66
8297afa1c29c
parent 65
9c44c55d327a
permissions
-rw-r--r--

replaces broken font cache with improved cache - fixes #387

universe@3 1 /*
universe@3 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@3 3 * Copyright 2023 Mike Becker. All rights reserved.
universe@3 4 *
universe@3 5 * Redistribution and use in source and binary forms, with or without
universe@3 6 * modification, are permitted provided that the following conditions are met:
universe@3 7 *
universe@3 8 * 1. Redistributions of source code must retain the above copyright
universe@3 9 * notice, this list of conditions and the following disclaimer.
universe@3 10 *
universe@3 11 * 2. Redistributions in binary form must reproduce the above copyright
universe@3 12 * notice, this list of conditions and the following disclaimer in the
universe@3 13 * documentation and/or other materials provided with the distribution.
universe@3 14 *
universe@3 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@3 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@3 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@3 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@3 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@3 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@3 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@3 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@3 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@3 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@3 25 * POSSIBILITY OF SUCH DAMAGE.
universe@3 26 */
universe@3 27
universe@11 28 #ifndef ASCENSION_FONT_H
universe@11 29 #define ASCENSION_FONT_H
universe@3 30
universe@11 31 #include <SDL2/SDL_ttf.h>
universe@11 32
universe@11 33 enum AscFontStyle {
universe@11 34 ASC_FONT_REGULAR,
universe@11 35 ASC_FONT_BOLD,
universe@11 36 ASC_FONT_ITALIC,
universe@11 37 ASC_FONT_BOLD_ITALIC,
universe@11 38 };
universe@4 39
universe@11 40 typedef struct AscFont {
universe@11 41 /**
universe@11 42 * Style of the font.
universe@11 43 */
universe@11 44 enum AscFontStyle style;
universe@11 45 /**
universe@11 46 * Point size.
universe@11 47 */
universe@11 48 int size;
universe@11 49 } AscFont;
universe@4 50
universe@4 51 /**
universe@65 52 * Activates a font with the given style and size.
universe@4 53 *
universe@65 54 * The font is cached and activated faster the next time you call this
universe@11 55 * function with the same arguments. However, when you reach the maximum
universe@11 56 * number of fonts, the cache is completely cleared and rebuilt.
universe@4 57 *
universe@11 58 * That means in general, that you should not be using too many fonts of
universe@65 59 * different sizes at the same time.
universe@11 60 *
universe@11 61 * @param style the style
universe@11 62 * @param size the point size
universe@4 63 */
universe@65 64 void asc_font(enum AscFontStyle style, int size);
universe@3 65
universe@66 66 /**
universe@66 67 * Loads the specified font.
universe@66 68 *
universe@66 69 * Loaded fonts are kept within a font cache and returned faster
universe@66 70 * on the next invocation.
universe@66 71 *
universe@66 72 * You will almost never need to use this function on your own.
universe@66 73 * Ascension UI elements are loading the required fonts for you.
universe@66 74 *
universe@66 75 * @param font the font description
universe@66 76 * @return a pointer to the SDL TTF font handle, or \c NULL on error
universe@66 77 */
universe@66 78 TTF_Font *asc_font_load(AscFont font);
universe@66 79
universe@11 80 #endif //ASCENSION_FONT_H

mercurial