src/ascension/sprite.h

Thu, 10 Jul 2025 22:19:48 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 10 Jul 2025 22:19:48 +0200
changeset 195
f9e9b7425ed3
parent 150
3045f61bc4eb
child 196
ac2ade047d5b
permissions
-rw-r--r--

improve signature of asc_sprite_set_size()

/*
* 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_SPRITE_H
#define ASCENSION_SPRITE_H

#include "scene_node.h"
#include "mesh.h"
#include "texture.h"
#include "camera.h"

typedef struct asc_sprite_s {
    AscSceneNode data;
    AscMesh mesh;
    unsigned width;
    unsigned height;
    AscTexture *texture;
    enum asc_texture_scale_mode texture_scale_mode;
    asc_vec2f texture_scale;
} AscSprite;

struct asc_sprite_create_args {
    const char *name;
    AscTexture *texture;
    int x;
    int y;
    /**
     * Optional width for re-scaling.
     * If zero, the texture width will be used.
     */
    unsigned width;
    /**
     * Optional height for re-scaling.
     * If zero, the texture height will be used.
     */
    unsigned height;
    enum asc_texture_scale_mode texture_scale_mode;
    float texture_scale_x;
    float texture_scale_y;
    bool opaque;
};

AscSceneNode *asc_sprite_create(struct asc_sprite_create_args args);

#define asc_sprite(...) \
    asc_sprite_create((struct asc_sprite_create_args) { __VA_ARGS__ })

void asc_sprite_set_size(AscSprite *sprite, asc_vec2u size);

// TODO: can be removed once AscText does no longer depend on AscSprite
void asc_sprite_draw(const AscCamera *camera, const AscSceneNode *node);

#endif //ASCENSION_SPRITE_H

mercurial