create new UI subdir

Mon, 01 Apr 2024 19:01:04 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 01 Apr 2024 19:01:04 +0200
changeset 48
6e5b5ba2752c
parent 47
44457f6cb0a2
child 49
77493525eac2

create new UI subdir

src/Makefile file | annotate | diff | comparison | revisions
src/ascension/ascension.h file | annotate | diff | comparison | revisions
src/ascension/context.h file | annotate | diff | comparison | revisions
src/ascension/core.h file | annotate | diff | comparison | revisions
src/ascension/font.h file | annotate | diff | comparison | revisions
src/ascension/text.h file | annotate | diff | comparison | revisions
src/ascension/ui.h file | annotate | diff | comparison | revisions
src/ascension/ui/font.h file | annotate | diff | comparison | revisions
src/ascension/ui/text.h file | annotate | diff | comparison | revisions
src/font.c file | annotate | diff | comparison | revisions
src/text.c file | annotate | diff | comparison | revisions
test/Makefile file | annotate | diff | comparison | revisions
test/snake.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/Makefile	Mon Apr 01 18:54:19 2024 +0200
     1.2 +++ b/src/Makefile	Mon Apr 01 19:01:04 2024 +0200
     1.3 @@ -49,14 +49,15 @@
     1.4   ascension/datatypes.h ascension/window.h ascension/glcontext.h \
     1.5   ascension/primitives.h ascension/mesh.h ascension/shader.h \
     1.6   ascension/scene.h ascension/transform.h ascension/camera.h \
     1.7 - ascension/font.h ascension/error.h ascension/utils.h ascension/shader.h
     1.8 + ascension/ui/font.h ascension/error.h ascension/utils.h \
     1.9 + ascension/shader.h
    1.10  	@echo "Compiling $<"
    1.11  	$(CC) -o $@ $(CFLAGS) -c $<
    1.12  
    1.13  $(BUILD_DIR)/error.o: error.c ascension/context.h ascension/datatypes.h \
    1.14   ascension/window.h ascension/glcontext.h ascension/primitives.h \
    1.15   ascension/mesh.h ascension/shader.h ascension/scene.h \
    1.16 - ascension/transform.h ascension/camera.h ascension/font.h \
    1.17 + ascension/transform.h ascension/camera.h ascension/ui/font.h \
    1.18   ascension/error.h ascension/utils.h
    1.19  	@echo "Compiling $<"
    1.20  	$(CC) -o $@ $(CFLAGS) -c $<
    1.21 @@ -65,11 +66,11 @@
    1.22  	@echo "Compiling $<"
    1.23  	$(CC) -o $@ $(CFLAGS) -c $<
    1.24  
    1.25 -$(BUILD_DIR)/font.o: font.c ascension/font.h ascension/context.h \
    1.26 +$(BUILD_DIR)/font.o: font.c ascension/ui/font.h ascension/context.h \
    1.27   ascension/datatypes.h ascension/window.h ascension/glcontext.h \
    1.28   ascension/primitives.h ascension/mesh.h ascension/shader.h \
    1.29   ascension/scene.h ascension/transform.h ascension/camera.h \
    1.30 - ascension/font.h ascension/error.h
    1.31 + ascension/ui/font.h ascension/error.h
    1.32  	@echo "Compiling $<"
    1.33  	$(CC) -o $@ $(CFLAGS) -c $<
    1.34  
    1.35 @@ -83,7 +84,7 @@
    1.36   ascension/mesh.h ascension/error.h ascension/context.h \
    1.37   ascension/datatypes.h ascension/window.h ascension/glcontext.h \
    1.38   ascension/primitives.h ascension/shader.h ascension/scene.h \
    1.39 - ascension/transform.h ascension/camera.h ascension/font.h
    1.40 + ascension/transform.h ascension/camera.h ascension/ui/font.h
    1.41  	@echo "Compiling $<"
    1.42  	$(CC) -o $@ $(CFLAGS) -c $<
    1.43  
    1.44 @@ -91,7 +92,7 @@
    1.45   ascension/transform.h ascension/camera.h ascension/error.h \
    1.46   ascension/context.h ascension/window.h ascension/glcontext.h \
    1.47   ascension/primitives.h ascension/mesh.h ascension/shader.h \
    1.48 - ascension/scene.h ascension/font.h ascension/shader.h
    1.49 + ascension/scene.h ascension/ui/font.h ascension/shader.h
    1.50  	@echo "Compiling $<"
    1.51  	$(CC) -o $@ $(CFLAGS) -c $<
    1.52  
    1.53 @@ -100,11 +101,13 @@
    1.54  	@echo "Compiling $<"
    1.55  	$(CC) -o $@ $(CFLAGS) -c $<
    1.56  
    1.57 -$(BUILD_DIR)/text.o: text.c ascension/text.h ascension/font.h \
    1.58 - ascension/scene.h ascension/datatypes.h ascension/transform.h \
    1.59 - ascension/camera.h ascension/context.h ascension/window.h \
    1.60 - ascension/glcontext.h ascension/primitives.h ascension/mesh.h \
    1.61 - ascension/shader.h ascension/error.h ascension/shader.h
    1.62 +$(BUILD_DIR)/text.o: text.c ascension/ui/text.h ascension/ui/font.h \
    1.63 + ascension/ui/../scene.h ascension/ui/../datatypes.h \
    1.64 + ascension/ui/../transform.h ascension/ui/../camera.h ascension/context.h \
    1.65 + ascension/datatypes.h ascension/window.h ascension/glcontext.h \
    1.66 + ascension/primitives.h ascension/mesh.h ascension/shader.h \
    1.67 + ascension/scene.h ascension/ui/font.h ascension/error.h \
    1.68 + ascension/shader.h
    1.69  	@echo "Compiling $<"
    1.70  	$(CC) -o $@ $(CFLAGS) -c $<
    1.71  
    1.72 @@ -112,7 +115,7 @@
    1.73   ascension/glcontext.h ascension/primitives.h ascension/mesh.h \
    1.74   ascension/shader.h ascension/scene.h ascension/transform.h \
    1.75   ascension/camera.h ascension/context.h ascension/window.h \
    1.76 - ascension/font.h ascension/error.h ascension/utils.h
    1.77 + ascension/ui/font.h ascension/error.h ascension/utils.h
    1.78  	@echo "Compiling $<"
    1.79  	$(CC) -o $@ $(CFLAGS) -c $<
    1.80  
     2.1 --- a/src/ascension/ascension.h	Mon Apr 01 18:54:19 2024 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,38 +0,0 @@
     2.4 -/*
     2.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 - * Copyright 2023 Mike Becker. All rights reserved.
     2.7 - *
     2.8 - * Redistribution and use in source and binary forms, with or without
     2.9 - * modification, are permitted provided that the following conditions are met:
    2.10 - *
    2.11 - *   1. Redistributions of source code must retain the above copyright
    2.12 - *      notice, this list of conditions and the following disclaimer.
    2.13 - *
    2.14 - *   2. Redistributions in binary form must reproduce the above copyright
    2.15 - *      notice, this list of conditions and the following disclaimer in the
    2.16 - *      documentation and/or other materials provided with the distribution.
    2.17 - *
    2.18 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    2.19 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    2.20 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    2.21 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    2.22 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    2.23 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    2.24 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    2.25 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    2.26 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    2.27 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    2.28 - * POSSIBILITY OF SUCH DAMAGE.
    2.29 - */
    2.30 -
    2.31 -#ifndef ASCENSION_H
    2.32 -#define ASCENSION_H
    2.33 -
    2.34 -#include "error.h"
    2.35 -#include "context.h"
    2.36 -#include "shader.h"
    2.37 -#include "text.h"
    2.38 -#include "scene.h"
    2.39 -
    2.40 -#endif /* ASCENSION_H */
    2.41 -
     3.1 --- a/src/ascension/context.h	Mon Apr 01 18:54:19 2024 +0200
     3.2 +++ b/src/ascension/context.h	Mon Apr 01 19:01:04 2024 +0200
     3.3 @@ -30,7 +30,7 @@
     3.4  
     3.5  #include "datatypes.h"
     3.6  #include "window.h"
     3.7 -#include "font.h"
     3.8 +#include "ui/font.h"
     3.9  
    3.10  #include <cx/buffer.h>
    3.11  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/ascension/core.h	Mon Apr 01 19:01:04 2024 +0200
     4.3 @@ -0,0 +1,37 @@
     4.4 +/*
     4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6 + * Copyright 2023 Mike Becker. All rights reserved.
     4.7 + *
     4.8 + * Redistribution and use in source and binary forms, with or without
     4.9 + * modification, are permitted provided that the following conditions are met:
    4.10 + *
    4.11 + *   1. Redistributions of source code must retain the above copyright
    4.12 + *      notice, this list of conditions and the following disclaimer.
    4.13 + *
    4.14 + *   2. Redistributions in binary form must reproduce the above copyright
    4.15 + *      notice, this list of conditions and the following disclaimer in the
    4.16 + *      documentation and/or other materials provided with the distribution.
    4.17 + *
    4.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    4.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    4.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    4.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    4.22 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    4.23 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    4.24 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    4.25 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    4.26 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    4.27 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    4.28 + * POSSIBILITY OF SUCH DAMAGE.
    4.29 + */
    4.30 +
    4.31 +#ifndef ASCENSION_CORE_H
    4.32 +#define ASCENSION_CORE_H
    4.33 +
    4.34 +#include "error.h"
    4.35 +#include "context.h"
    4.36 +#include "shader.h"
    4.37 +#include "scene.h"
    4.38 +
    4.39 +#endif /* ASCENSION_CORE_H */
    4.40 +
     5.1 --- a/src/ascension/font.h	Mon Apr 01 18:54:19 2024 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,94 +0,0 @@
     5.4 -/*
     5.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.6 - * Copyright 2023 Mike Becker. All rights reserved.
     5.7 - *
     5.8 - * Redistribution and use in source and binary forms, with or without
     5.9 - * modification, are permitted provided that the following conditions are met:
    5.10 - *
    5.11 - *   1. Redistributions of source code must retain the above copyright
    5.12 - *      notice, this list of conditions and the following disclaimer.
    5.13 - *
    5.14 - *   2. Redistributions in binary form must reproduce the above copyright
    5.15 - *      notice, this list of conditions and the following disclaimer in the
    5.16 - *      documentation and/or other materials provided with the distribution.
    5.17 - *
    5.18 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    5.19 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    5.20 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    5.21 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    5.22 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    5.23 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    5.24 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    5.25 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    5.26 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    5.27 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    5.28 - * POSSIBILITY OF SUCH DAMAGE.
    5.29 - */
    5.30 -
    5.31 -#ifndef ASCENSION_FONT_H
    5.32 -#define ASCENSION_FONT_H
    5.33 -
    5.34 -#include <SDL2/SDL_ttf.h>
    5.35 -
    5.36 -#ifndef ASC_MAX_FONTS
    5.37 -/** The maximum number of style/size combinations that can be loaded in parallel. */
    5.38 -#define ASC_MAX_FONTS 64u
    5.39 -#endif // ASC_MAX_FONTS
    5.40 -
    5.41 -enum AscFontStyle {
    5.42 -    ASC_FONT_REGULAR,
    5.43 -    ASC_FONT_BOLD,
    5.44 -    ASC_FONT_ITALIC,
    5.45 -    ASC_FONT_BOLD_ITALIC,
    5.46 -};
    5.47 -
    5.48 -typedef struct AscFont {
    5.49 -    /**
    5.50 -     * Style of the font.
    5.51 -     */
    5.52 -    enum AscFontStyle style;
    5.53 -    /**
    5.54 -     * Point size.
    5.55 -     */
    5.56 -    int size;
    5.57 -    /**
    5.58 -     * Pointer to the SDL TTF font structure.
    5.59 -     */
    5.60 -    TTF_Font *ptr;
    5.61 -} AscFont;
    5.62 -
    5.63 -/**
    5.64 - * Loads a font with the given style and size.
    5.65 - *
    5.66 - * The font is cached and returned faster the next time you call this
    5.67 - * function with the same arguments. However, when you reach the maximum
    5.68 - * number of fonts, the cache is completely cleared and rebuilt.
    5.69 - *
    5.70 - * That means in general, that you should not be using too many fonts of
    5.71 - * different sizes at the same time, and you should not keep the pointer
    5.72 - * returned by this function too long, because you would risking cache misses.
    5.73 - *
    5.74 - * @param style the style
    5.75 - * @param size the point size
    5.76 - * @return a pointer to the font structure (do not free)
    5.77 - */
    5.78 -AscFont const *asc_font(enum AscFontStyle style, int size);
    5.79 -
    5.80 -/**
    5.81 - * Unloads all cached fonts from the context.
    5.82 - */
    5.83 -void asc_font_cache_clear(void);
    5.84 -
    5.85 -/**
    5.86 - * Checks, if the font is still loaded and reloads it, if required.
    5.87 - *
    5.88 - * There is no need to call this function manually. Every Ascension function
    5.89 - * that you pass a font will do that for you and use the returned pointer in
    5.90 - * case of a cache miss.
    5.91 - *
    5.92 - * @param font the font to validate
    5.93 - * @return \p font, or a pointer to the new location of the loaded font
    5.94 - */
    5.95 -AscFont const *asc_font_cache_validate(AscFont const *font);
    5.96 -
    5.97 -#endif //ASCENSION_FONT_H
     6.1 --- a/src/ascension/text.h	Mon Apr 01 18:54:19 2024 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,75 +0,0 @@
     6.4 -/*
     6.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     6.6 - * Copyright 2023 Mike Becker. All rights reserved.
     6.7 - *
     6.8 - * Redistribution and use in source and binary forms, with or without
     6.9 - * modification, are permitted provided that the following conditions are met:
    6.10 - *
    6.11 - *   1. Redistributions of source code must retain the above copyright
    6.12 - *      notice, this list of conditions and the following disclaimer.
    6.13 - *
    6.14 - *   2. Redistributions in binary form must reproduce the above copyright
    6.15 - *      notice, this list of conditions and the following disclaimer in the
    6.16 - *      documentation and/or other materials provided with the distribution.
    6.17 - *
    6.18 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    6.19 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    6.20 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    6.21 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    6.22 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    6.23 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    6.24 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    6.25 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    6.26 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    6.27 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    6.28 - * POSSIBILITY OF SUCH DAMAGE.
    6.29 - */
    6.30 -
    6.31 -#ifndef ASCENSION_TEXT_H
    6.32 -#define ASCENSION_TEXT_H
    6.33 -
    6.34 -#include "font.h"
    6.35 -#include "scene.h"
    6.36 -
    6.37 -typedef struct AscText {
    6.38 -    extend_asc_scene_node;
    6.39 -    char *text;
    6.40 -    AscFont const *font;
    6.41 -    asc_col4i color;
    6.42 -    unsigned max_width;
    6.43 -    bool hidden;
    6.44 -    bool centered;
    6.45 -    unsigned tex_id;
    6.46 -} AscText;
    6.47 -
    6.48 -
    6.49 -/**
    6.50 - * Creates a text node.
    6.51 - *
    6.52 - * The current context ink and font will be used.
    6.53 - *
    6.54 - * @param x the position where to draw the text
    6.55 - * @param y the position where to draw the text
    6.56 - * @param text the text to draw
    6.57 - * @return the scene node
    6.58 - *
    6.59 - * @see asc_ink()
    6.60 - * @see asc_font()
    6.61 - */
    6.62 -AscSceneNode *asc_text(int x, int y, char const* text);
    6.63 -
    6.64 -/**
    6.65 - * Provides access to the text data fields.
    6.66 - *
    6.67 - * @param node scene node created by asc_text()
    6.68 - */
    6.69 -#define asc_text_data(node) ((AscText*)node)
    6.70 -
    6.71 -/**
    6.72 - * Releases all the memory of this node.
    6.73 - *
    6.74 - * @param node the text node
    6.75 - */
    6.76 -void asc_text_free(AscText *node);
    6.77 -
    6.78 -#endif //ASCENSION_TEXT_H
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/ascension/ui.h	Mon Apr 01 19:01:04 2024 +0200
     7.3 @@ -0,0 +1,34 @@
     7.4 +/*
     7.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     7.6 + * Copyright 2024 Mike Becker. All rights reserved.
     7.7 + *
     7.8 + * Redistribution and use in source and binary forms, with or without
     7.9 + * modification, are permitted provided that the following conditions are met:
    7.10 + *
    7.11 + *   1. Redistributions of source code must retain the above copyright
    7.12 + *      notice, this list of conditions and the following disclaimer.
    7.13 + *
    7.14 + *   2. Redistributions in binary form must reproduce the above copyright
    7.15 + *      notice, this list of conditions and the following disclaimer in the
    7.16 + *      documentation and/or other materials provided with the distribution.
    7.17 + *
    7.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    7.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    7.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    7.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    7.22 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    7.23 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    7.24 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    7.25 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    7.26 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    7.27 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    7.28 + * POSSIBILITY OF SUCH DAMAGE.
    7.29 + */
    7.30 +
    7.31 +#ifndef ASCENSION_UI_H
    7.32 +#define ASCENSION_UI_H
    7.33 +
    7.34 +#include "ui/text.h"
    7.35 +
    7.36 +#endif /* ASCENSION_UI_H */
    7.37 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/ascension/ui/font.h	Mon Apr 01 19:01:04 2024 +0200
     8.3 @@ -0,0 +1,94 @@
     8.4 +/*
     8.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     8.6 + * Copyright 2023 Mike Becker. All rights reserved.
     8.7 + *
     8.8 + * Redistribution and use in source and binary forms, with or without
     8.9 + * modification, are permitted provided that the following conditions are met:
    8.10 + *
    8.11 + *   1. Redistributions of source code must retain the above copyright
    8.12 + *      notice, this list of conditions and the following disclaimer.
    8.13 + *
    8.14 + *   2. Redistributions in binary form must reproduce the above copyright
    8.15 + *      notice, this list of conditions and the following disclaimer in the
    8.16 + *      documentation and/or other materials provided with the distribution.
    8.17 + *
    8.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    8.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    8.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    8.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    8.22 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    8.23 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    8.24 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    8.25 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    8.26 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    8.27 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    8.28 + * POSSIBILITY OF SUCH DAMAGE.
    8.29 + */
    8.30 +
    8.31 +#ifndef ASCENSION_FONT_H
    8.32 +#define ASCENSION_FONT_H
    8.33 +
    8.34 +#include <SDL2/SDL_ttf.h>
    8.35 +
    8.36 +#ifndef ASC_MAX_FONTS
    8.37 +/** The maximum number of style/size combinations that can be loaded in parallel. */
    8.38 +#define ASC_MAX_FONTS 64u
    8.39 +#endif // ASC_MAX_FONTS
    8.40 +
    8.41 +enum AscFontStyle {
    8.42 +    ASC_FONT_REGULAR,
    8.43 +    ASC_FONT_BOLD,
    8.44 +    ASC_FONT_ITALIC,
    8.45 +    ASC_FONT_BOLD_ITALIC,
    8.46 +};
    8.47 +
    8.48 +typedef struct AscFont {
    8.49 +    /**
    8.50 +     * Style of the font.
    8.51 +     */
    8.52 +    enum AscFontStyle style;
    8.53 +    /**
    8.54 +     * Point size.
    8.55 +     */
    8.56 +    int size;
    8.57 +    /**
    8.58 +     * Pointer to the SDL TTF font structure.
    8.59 +     */
    8.60 +    TTF_Font *ptr;
    8.61 +} AscFont;
    8.62 +
    8.63 +/**
    8.64 + * Loads a font with the given style and size.
    8.65 + *
    8.66 + * The font is cached and returned faster the next time you call this
    8.67 + * function with the same arguments. However, when you reach the maximum
    8.68 + * number of fonts, the cache is completely cleared and rebuilt.
    8.69 + *
    8.70 + * That means in general, that you should not be using too many fonts of
    8.71 + * different sizes at the same time, and you should not keep the pointer
    8.72 + * returned by this function too long, because you would risking cache misses.
    8.73 + *
    8.74 + * @param style the style
    8.75 + * @param size the point size
    8.76 + * @return a pointer to the font structure (do not free)
    8.77 + */
    8.78 +AscFont const *asc_font(enum AscFontStyle style, int size);
    8.79 +
    8.80 +/**
    8.81 + * Unloads all cached fonts from the context.
    8.82 + */
    8.83 +void asc_font_cache_clear(void);
    8.84 +
    8.85 +/**
    8.86 + * Checks, if the font is still loaded and reloads it, if required.
    8.87 + *
    8.88 + * There is no need to call this function manually. Every Ascension function
    8.89 + * that you pass a font will do that for you and use the returned pointer in
    8.90 + * case of a cache miss.
    8.91 + *
    8.92 + * @param font the font to validate
    8.93 + * @return \p font, or a pointer to the new location of the loaded font
    8.94 + */
    8.95 +AscFont const *asc_font_cache_validate(AscFont const *font);
    8.96 +
    8.97 +#endif //ASCENSION_FONT_H
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/ascension/ui/text.h	Mon Apr 01 19:01:04 2024 +0200
     9.3 @@ -0,0 +1,75 @@
     9.4 +/*
     9.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     9.6 + * Copyright 2023 Mike Becker. All rights reserved.
     9.7 + *
     9.8 + * Redistribution and use in source and binary forms, with or without
     9.9 + * modification, are permitted provided that the following conditions are met:
    9.10 + *
    9.11 + *   1. Redistributions of source code must retain the above copyright
    9.12 + *      notice, this list of conditions and the following disclaimer.
    9.13 + *
    9.14 + *   2. Redistributions in binary form must reproduce the above copyright
    9.15 + *      notice, this list of conditions and the following disclaimer in the
    9.16 + *      documentation and/or other materials provided with the distribution.
    9.17 + *
    9.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    9.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    9.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    9.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    9.22 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    9.23 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    9.24 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    9.25 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    9.26 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    9.27 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    9.28 + * POSSIBILITY OF SUCH DAMAGE.
    9.29 + */
    9.30 +
    9.31 +#ifndef ASCENSION_UI_TEXT_H
    9.32 +#define ASCENSION_UI_TEXT_H
    9.33 +
    9.34 +#include "font.h"
    9.35 +#include "../scene.h"
    9.36 +
    9.37 +typedef struct AscText {
    9.38 +    extend_asc_scene_node;
    9.39 +    char *text;
    9.40 +    AscFont const *font;
    9.41 +    asc_col4i color;
    9.42 +    unsigned max_width;
    9.43 +    bool hidden;
    9.44 +    bool centered;
    9.45 +    unsigned tex_id;
    9.46 +} AscText;
    9.47 +
    9.48 +
    9.49 +/**
    9.50 + * Creates a text node.
    9.51 + *
    9.52 + * The current context ink and font will be used.
    9.53 + *
    9.54 + * @param x the position where to draw the text
    9.55 + * @param y the position where to draw the text
    9.56 + * @param text the text to draw
    9.57 + * @return the scene node
    9.58 + *
    9.59 + * @see asc_ink()
    9.60 + * @see asc_font()
    9.61 + */
    9.62 +AscSceneNode *asc_text(int x, int y, char const* text);
    9.63 +
    9.64 +/**
    9.65 + * Provides access to the text data fields.
    9.66 + *
    9.67 + * @param node scene node created by asc_text()
    9.68 + */
    9.69 +#define asc_text_data(node) ((AscText*)node)
    9.70 +
    9.71 +/**
    9.72 + * Releases all the memory of this node.
    9.73 + *
    9.74 + * @param node the text node
    9.75 + */
    9.76 +void asc_text_free(AscText *node);
    9.77 +
    9.78 +#endif //ASCENSION_UI_TEXT_H
    10.1 --- a/src/font.c	Mon Apr 01 18:54:19 2024 +0200
    10.2 +++ b/src/font.c	Mon Apr 01 19:01:04 2024 +0200
    10.3 @@ -25,7 +25,7 @@
    10.4   * POSSIBILITY OF SUCH DAMAGE.
    10.5   */
    10.6  
    10.7 -#include "ascension/font.h"
    10.8 +#include "ascension/ui/font.h"
    10.9  #include "ascension/context.h"
   10.10  #include "ascension/error.h"
   10.11  
    11.1 --- a/src/text.c	Mon Apr 01 18:54:19 2024 +0200
    11.2 +++ b/src/text.c	Mon Apr 01 19:01:04 2024 +0200
    11.3 @@ -25,7 +25,7 @@
    11.4   * POSSIBILITY OF SUCH DAMAGE.
    11.5   */
    11.6  
    11.7 -#include "ascension/text.h"
    11.8 +#include "ascension/ui/text.h"
    11.9  #include "ascension/context.h"
   11.10  #include "ascension/error.h"
   11.11  #include "ascension/shader.h"
    12.1 --- a/test/Makefile	Mon Apr 01 18:54:19 2024 +0200
    12.2 +++ b/test/Makefile	Mon Apr 01 19:01:04 2024 +0200
    12.3 @@ -41,14 +41,15 @@
    12.4  
    12.5  FORCE:
    12.6  
    12.7 -$(BUILD_DIR)/snake.o: snake.c ../src/ascension/ascension.h \
    12.8 +$(BUILD_DIR)/snake.o: snake.c ../src/ascension/core.h \
    12.9   ../src/ascension/error.h ../src/ascension/context.h \
   12.10   ../src/ascension/datatypes.h ../src/ascension/window.h \
   12.11   ../src/ascension/glcontext.h ../src/ascension/primitives.h \
   12.12   ../src/ascension/mesh.h ../src/ascension/shader.h \
   12.13   ../src/ascension/scene.h ../src/ascension/transform.h \
   12.14 - ../src/ascension/camera.h ../src/ascension/font.h \
   12.15 - ../src/ascension/text.h
   12.16 + ../src/ascension/camera.h ../src/ascension/ui/font.h \
   12.17 + ../src/ascension/ui.h ../src/ascension/ui/text.h \
   12.18 + ../src/ascension/ui/font.h ../src/ascension/ui/../scene.h
   12.19  	@echo "Compiling $<"
   12.20  	$(CC) -o $@ $(CFLAGS) -c $<
   12.21  
    13.1 --- a/test/snake.c	Mon Apr 01 18:54:19 2024 +0200
    13.2 +++ b/test/snake.c	Mon Apr 01 19:01:04 2024 +0200
    13.3 @@ -25,7 +25,9 @@
    13.4   * POSSIBILITY OF SUCH DAMAGE.
    13.5   */
    13.6  
    13.7 -#include <ascension/ascension.h>
    13.8 +#include "ascension/core.h"
    13.9 +#include <ascension/ui.h>
   13.10 +
   13.11  #include <cx/printf.h>
   13.12  
   13.13  static void update_fps_counter(AscSceneNode *node) {

mercurial