src/ascension/text.h

Sun, 21 Jan 2024 13:31:51 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 21 Jan 2024 13:31:51 +0100
changeset 25
601b3f4e17a2
parent 23
ab07757004b4
child 26
139dac8ef9ee
permissions
-rw-r--r--

rename AscTextNode to just AscText

     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  * Copyright 2023 Mike Becker. All rights reserved.
     4  *
     5  * Redistribution and use in source and binary forms, with or without
     6  * modification, are permitted provided that the following conditions are met:
     7  *
     8  *   1. Redistributions of source code must retain the above copyright
     9  *      notice, this list of conditions and the following disclaimer.
    10  *
    11  *   2. Redistributions in binary form must reproduce the above copyright
    12  *      notice, this list of conditions and the following disclaimer in the
    13  *      documentation and/or other materials provided with the distribution.
    14  *
    15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    25  * POSSIBILITY OF SUCH DAMAGE.
    26  */
    28 #ifndef ASCENSION_TEXT_H
    29 #define ASCENSION_TEXT_H
    31 #include "font.h"
    32 #include "datatypes.h"
    33 #include <cx/buffer.h>
    35 typedef struct AscText {
    36     char *text;
    37     AscFont const *font;
    38     asc_vec2i position;
    39     asc_col4i color;
    40     unsigned max_width;
    41     bool hidden;
    42     bool centered;
    43     struct {
    44         asc_vec2i dimension;
    45         unsigned tex_id;
    46     } internal;
    47 } AscText;
    50 /**
    51  * Creates a text node.
    52  *
    53  * The current context ink and font will be used.
    54  *
    55  * To allow more adjustments before initializing the internal structure
    56  * this function does NOT invoke asc_text_update() automatically.
    57  *
    58  * @param x the position where to draw the text
    59  * @param y the position where to draw the text
    60  * @param text the text to draw
    61  * @see asc_ink()
    62  * @see asc_font()
    63  */
    64 AscText *asc_text(int x, int y, char const* text);
    66 /**
    67  * Updates the internal state of the text node.
    68  *
    69  * You must invoke this method after changing the state of the struct,
    70  * but not in every frame.
    71  *
    72  * @param node the text node
    73  */
    74 void asc_text_update(AscText *node);
    76 /**
    77  * Draws the text node in the current frame.
    78  *
    79  * @param node the text node
    80  */
    81 void asc_text_draw(AscText *node);
    83 /**
    84  * Releases all the memory of this node.
    85  *
    86  * @param node the text node
    87  */
    88 void asc_text_free(AscText *node);
    90 #endif //ASCENSION_TEXT_H

mercurial