src/ascension/2d.h

Mon, 18 Aug 2025 23:11:50 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 18 Aug 2025 23:11:50 +0200
changeset 266
a73674e99e62
parent 256
60014484121c
permissions
-rw-r--r--

convert behavior list to a behavior map

prepares the by-name lookup functions for behaviors

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * Copyright 2025 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_2D_H
#define ASCENSION_2D_H

#include "scene_node.h"
#include "mesh.h"

typedef struct asc_rectangle_s {
    AscSceneNode node;
    AscMesh mesh;
    asc_color color;
    asc_color border_color;
    asc_vec2f size;
    float radius;
    float thickness;
    bool filled;
} AscRectangle;

struct asc_rectangle_create_args {
    /**
     * X-coordinate of the rectangle's origin.
     * When no alternate point of origin is specified, the (x,y) belongs to the top-left corner.
     */
    int x;
    /**
     * Y-coordinate of the rectangle's origin.
     * When no alternate point of origin is specified, the (x,y) belongs to the top-left corner.
     */
    int y;
    /**
     * X-offset for the point of origin in rectangle coordinates.
     * Zero means the left edge and the rectangle's width means the right edge.
     * The origin may lie outside the rectangle's bounds.
     */
    int origin_x;
    /**
     * Y-offset for the point of origin in rectangle coordinates.
     * Zero means the top edge and the rectangle's height means the bottom edge.
    * The origin may lie outside the rectangle's bounds.
     */
    int origin_y;
    /**
     * The horizontal length of the rectangle.
     */
    unsigned int width;
    /**
     * The vertical length of the rectangle.
     */
    unsigned int height;
    /**
     * Corner radius.
     */
    unsigned int radius;
    /**
     * Border thickness
     */
    unsigned int thickness;
    /**
     * The main color to use.
     * If filled is true, this is the fill color.
     * If filled is false, and no border_color is specified, this is used as border color.
     */
    asc_color color;
    /**
     * Border color to be used when thickness is larger than zero and filled is true.
     */
    asc_color border_color;
    /**
     * If true, the rectangle will be filled with the specified color.
     * If the thickness is larger than zero, an outline border with that thickness is drawn
     * using the border_color.
     */
    bool filled;
};

AscSceneNode *asc_rectangle_create(struct asc_rectangle_create_args args);

#define asc_rectangle(...) asc_rectangle_create((struct asc_rectangle_create_args) { __VA_ARGS__ })

/**
 * Sets new bounds of the rectangle.
 *
 * Triggers a mesh-recalculation only if the new bounds are unequal to the current bounds.
 *
 * @param rect the rectangle
 * @param bounds the new bounds of the rectangle
 */
void asc_rectangle_set_bounds(AscRectangle *rect, asc_rect bounds);


typedef struct asc_ellipsis_s {
    AscSceneNode node;
    AscMesh mesh;
    asc_color color;
    asc_color border_color;
    asc_vec2f radii;
    float thickness;
    bool filled;
} AscEllipsis;

struct asc_ellipsis_create_args {
    /**
     * The bounds of the ellipsis.
     * Preferred over all other settings.
     * When you specify bounds, you cannot specify a center and radii.
     * The origin point will be the center of the rectangle.
     */
    asc_rect bounds;
    /**
     * The center point of the ellipsis.
     * Preferred over x and y.
     */
    asc_vec2i center;
    /**
     * The x coordinate of the center, if center is not specified.
     */
    int x;
    /**
     * The y coordinate of the center, if center is not specified.
     */
    int y;
    /**
     * The radius in both directions (use for circles).
     */
    unsigned int radius;
    /**
     * The radius in x-direction.
     */
    unsigned int radius_x;
    /**
     * The radius in y-direction.
     */
    unsigned int radius_y;
    /**
     * Border thickness
     */
    unsigned int thickness;
    /**
     * The main color to use.
     * If filled is true, this is the fill color.
     * If filled is false, and no border_color is specified, this is used as border color.
     */
    asc_color color;
    /**
     * Border color to be used when thickness is larger than zero and filled is true.
     */
    asc_color border_color;
    /**
     * If true, the ellipsis will be filled with the specified color.
     * If the thickness is larger than zero, an outline border with that thickness is drawn
     * using the border_color.
     */
    bool filled;
};

AscSceneNode *asc_ellipsis_create(struct asc_ellipsis_create_args args);

#define asc_ellipsis(...) asc_ellipsis_create((struct asc_ellipsis_create_args) { __VA_ARGS__ })

#endif /* ASCENSION_2D_H */

mercurial