Mon, 01 Apr 2024 19:01:04 +0200
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 |
--- a/src/Makefile Mon Apr 01 18:54:19 2024 +0200 +++ b/src/Makefile Mon Apr 01 19:01:04 2024 +0200 @@ -49,14 +49,15 @@ ascension/datatypes.h ascension/window.h ascension/glcontext.h \ ascension/primitives.h ascension/mesh.h ascension/shader.h \ ascension/scene.h ascension/transform.h ascension/camera.h \ - ascension/font.h ascension/error.h ascension/utils.h ascension/shader.h + ascension/ui/font.h ascension/error.h ascension/utils.h \ + ascension/shader.h @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< $(BUILD_DIR)/error.o: error.c ascension/context.h ascension/datatypes.h \ ascension/window.h ascension/glcontext.h ascension/primitives.h \ ascension/mesh.h ascension/shader.h ascension/scene.h \ - ascension/transform.h ascension/camera.h ascension/font.h \ + ascension/transform.h ascension/camera.h ascension/ui/font.h \ ascension/error.h ascension/utils.h @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< @@ -65,11 +66,11 @@ @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< -$(BUILD_DIR)/font.o: font.c ascension/font.h ascension/context.h \ +$(BUILD_DIR)/font.o: font.c ascension/ui/font.h ascension/context.h \ ascension/datatypes.h ascension/window.h ascension/glcontext.h \ ascension/primitives.h ascension/mesh.h ascension/shader.h \ ascension/scene.h ascension/transform.h ascension/camera.h \ - ascension/font.h ascension/error.h + ascension/ui/font.h ascension/error.h @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< @@ -83,7 +84,7 @@ ascension/mesh.h ascension/error.h ascension/context.h \ ascension/datatypes.h ascension/window.h ascension/glcontext.h \ ascension/primitives.h ascension/shader.h ascension/scene.h \ - ascension/transform.h ascension/camera.h ascension/font.h + ascension/transform.h ascension/camera.h ascension/ui/font.h @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< @@ -91,7 +92,7 @@ ascension/transform.h ascension/camera.h ascension/error.h \ ascension/context.h ascension/window.h ascension/glcontext.h \ ascension/primitives.h ascension/mesh.h ascension/shader.h \ - ascension/scene.h ascension/font.h ascension/shader.h + ascension/scene.h ascension/ui/font.h ascension/shader.h @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< @@ -100,11 +101,13 @@ @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< -$(BUILD_DIR)/text.o: text.c ascension/text.h ascension/font.h \ - ascension/scene.h ascension/datatypes.h ascension/transform.h \ - ascension/camera.h ascension/context.h ascension/window.h \ - ascension/glcontext.h ascension/primitives.h ascension/mesh.h \ - ascension/shader.h ascension/error.h ascension/shader.h +$(BUILD_DIR)/text.o: text.c ascension/ui/text.h ascension/ui/font.h \ + ascension/ui/../scene.h ascension/ui/../datatypes.h \ + ascension/ui/../transform.h ascension/ui/../camera.h ascension/context.h \ + ascension/datatypes.h ascension/window.h ascension/glcontext.h \ + ascension/primitives.h ascension/mesh.h ascension/shader.h \ + ascension/scene.h ascension/ui/font.h ascension/error.h \ + ascension/shader.h @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< @@ -112,7 +115,7 @@ ascension/glcontext.h ascension/primitives.h ascension/mesh.h \ ascension/shader.h ascension/scene.h ascension/transform.h \ ascension/camera.h ascension/context.h ascension/window.h \ - ascension/font.h ascension/error.h ascension/utils.h + ascension/ui/font.h ascension/error.h ascension/utils.h @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $<
--- a/src/ascension/ascension.h Mon Apr 01 18:54:19 2024 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * 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_H -#define ASCENSION_H - -#include "error.h" -#include "context.h" -#include "shader.h" -#include "text.h" -#include "scene.h" - -#endif /* ASCENSION_H */ -
--- a/src/ascension/context.h Mon Apr 01 18:54:19 2024 +0200 +++ b/src/ascension/context.h Mon Apr 01 19:01:04 2024 +0200 @@ -30,7 +30,7 @@ #include "datatypes.h" #include "window.h" -#include "font.h" +#include "ui/font.h" #include <cx/buffer.h>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ascension/core.h Mon Apr 01 19:01:04 2024 +0200 @@ -0,0 +1,37 @@ +/* + * 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_CORE_H +#define ASCENSION_CORE_H + +#include "error.h" +#include "context.h" +#include "shader.h" +#include "scene.h" + +#endif /* ASCENSION_CORE_H */ +
--- a/src/ascension/font.h Mon Apr 01 18:54:19 2024 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/* - * 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> - -#ifndef ASC_MAX_FONTS -/** The maximum number of style/size combinations that can be loaded in parallel. */ -#define ASC_MAX_FONTS 64u -#endif // ASC_MAX_FONTS - -enum AscFontStyle { - ASC_FONT_REGULAR, - ASC_FONT_BOLD, - ASC_FONT_ITALIC, - ASC_FONT_BOLD_ITALIC, -}; - -typedef struct AscFont { - /** - * Style of the font. - */ - enum AscFontStyle style; - /** - * Point size. - */ - int size; - /** - * Pointer to the SDL TTF font structure. - */ - TTF_Font *ptr; -} AscFont; - -/** - * Loads a font with the given style and size. - * - * The font is cached and returned 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, and you should not keep the pointer - * returned by this function too long, because you would risking cache misses. - * - * @param style the style - * @param size the point size - * @return a pointer to the font structure (do not free) - */ -AscFont const *asc_font(enum AscFontStyle style, int size); - -/** - * Unloads all cached fonts from the context. - */ -void asc_font_cache_clear(void); - -/** - * Checks, if the font is still loaded and reloads it, if required. - * - * There is no need to call this function manually. Every Ascension function - * that you pass a font will do that for you and use the returned pointer in - * case of a cache miss. - * - * @param font the font to validate - * @return \p font, or a pointer to the new location of the loaded font - */ -AscFont const *asc_font_cache_validate(AscFont const *font); - -#endif //ASCENSION_FONT_H
--- a/src/ascension/text.h Mon Apr 01 18:54:19 2024 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * 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_TEXT_H -#define ASCENSION_TEXT_H - -#include "font.h" -#include "scene.h" - -typedef struct AscText { - extend_asc_scene_node; - char *text; - AscFont const *font; - asc_col4i color; - unsigned max_width; - bool hidden; - bool centered; - unsigned tex_id; -} AscText; - - -/** - * Creates a text node. - * - * The current context ink and font will be used. - * - * @param x the position where to draw the text - * @param y the position where to draw the text - * @param text the text to draw - * @return the scene node - * - * @see asc_ink() - * @see asc_font() - */ -AscSceneNode *asc_text(int x, int y, char const* text); - -/** - * Provides access to the text data fields. - * - * @param node scene node created by asc_text() - */ -#define asc_text_data(node) ((AscText*)node) - -/** - * Releases all the memory of this node. - * - * @param node the text node - */ -void asc_text_free(AscText *node); - -#endif //ASCENSION_TEXT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ascension/ui.h Mon Apr 01 19:01:04 2024 +0200 @@ -0,0 +1,34 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * Copyright 2024 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_UI_H +#define ASCENSION_UI_H + +#include "ui/text.h" + +#endif /* ASCENSION_UI_H */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ascension/ui/font.h Mon Apr 01 19:01:04 2024 +0200 @@ -0,0 +1,94 @@ +/* + * 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> + +#ifndef ASC_MAX_FONTS +/** The maximum number of style/size combinations that can be loaded in parallel. */ +#define ASC_MAX_FONTS 64u +#endif // ASC_MAX_FONTS + +enum AscFontStyle { + ASC_FONT_REGULAR, + ASC_FONT_BOLD, + ASC_FONT_ITALIC, + ASC_FONT_BOLD_ITALIC, +}; + +typedef struct AscFont { + /** + * Style of the font. + */ + enum AscFontStyle style; + /** + * Point size. + */ + int size; + /** + * Pointer to the SDL TTF font structure. + */ + TTF_Font *ptr; +} AscFont; + +/** + * Loads a font with the given style and size. + * + * The font is cached and returned 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, and you should not keep the pointer + * returned by this function too long, because you would risking cache misses. + * + * @param style the style + * @param size the point size + * @return a pointer to the font structure (do not free) + */ +AscFont const *asc_font(enum AscFontStyle style, int size); + +/** + * Unloads all cached fonts from the context. + */ +void asc_font_cache_clear(void); + +/** + * Checks, if the font is still loaded and reloads it, if required. + * + * There is no need to call this function manually. Every Ascension function + * that you pass a font will do that for you and use the returned pointer in + * case of a cache miss. + * + * @param font the font to validate + * @return \p font, or a pointer to the new location of the loaded font + */ +AscFont const *asc_font_cache_validate(AscFont const *font); + +#endif //ASCENSION_FONT_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ascension/ui/text.h Mon Apr 01 19:01:04 2024 +0200 @@ -0,0 +1,75 @@ +/* + * 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_UI_TEXT_H +#define ASCENSION_UI_TEXT_H + +#include "font.h" +#include "../scene.h" + +typedef struct AscText { + extend_asc_scene_node; + char *text; + AscFont const *font; + asc_col4i color; + unsigned max_width; + bool hidden; + bool centered; + unsigned tex_id; +} AscText; + + +/** + * Creates a text node. + * + * The current context ink and font will be used. + * + * @param x the position where to draw the text + * @param y the position where to draw the text + * @param text the text to draw + * @return the scene node + * + * @see asc_ink() + * @see asc_font() + */ +AscSceneNode *asc_text(int x, int y, char const* text); + +/** + * Provides access to the text data fields. + * + * @param node scene node created by asc_text() + */ +#define asc_text_data(node) ((AscText*)node) + +/** + * Releases all the memory of this node. + * + * @param node the text node + */ +void asc_text_free(AscText *node); + +#endif //ASCENSION_UI_TEXT_H
--- a/src/font.c Mon Apr 01 18:54:19 2024 +0200 +++ b/src/font.c Mon Apr 01 19:01:04 2024 +0200 @@ -25,7 +25,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "ascension/font.h" +#include "ascension/ui/font.h" #include "ascension/context.h" #include "ascension/error.h"
--- a/src/text.c Mon Apr 01 18:54:19 2024 +0200 +++ b/src/text.c Mon Apr 01 19:01:04 2024 +0200 @@ -25,7 +25,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "ascension/text.h" +#include "ascension/ui/text.h" #include "ascension/context.h" #include "ascension/error.h" #include "ascension/shader.h"
--- a/test/Makefile Mon Apr 01 18:54:19 2024 +0200 +++ b/test/Makefile Mon Apr 01 19:01:04 2024 +0200 @@ -41,14 +41,15 @@ FORCE: -$(BUILD_DIR)/snake.o: snake.c ../src/ascension/ascension.h \ +$(BUILD_DIR)/snake.o: snake.c ../src/ascension/core.h \ ../src/ascension/error.h ../src/ascension/context.h \ ../src/ascension/datatypes.h ../src/ascension/window.h \ ../src/ascension/glcontext.h ../src/ascension/primitives.h \ ../src/ascension/mesh.h ../src/ascension/shader.h \ ../src/ascension/scene.h ../src/ascension/transform.h \ - ../src/ascension/camera.h ../src/ascension/font.h \ - ../src/ascension/text.h + ../src/ascension/camera.h ../src/ascension/ui/font.h \ + ../src/ascension/ui.h ../src/ascension/ui/text.h \ + ../src/ascension/ui/font.h ../src/ascension/ui/../scene.h @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $<
--- a/test/snake.c Mon Apr 01 18:54:19 2024 +0200 +++ b/test/snake.c Mon Apr 01 19:01:04 2024 +0200 @@ -25,7 +25,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <ascension/ascension.h> +#include "ascension/core.h" +#include <ascension/ui.h> + #include <cx/printf.h> static void update_fps_counter(AscSceneNode *node) {