Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_atlas.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
27
28#ifndef __N_ATLAS_HEADER
29#define __N_ATLAS_HEADER
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#include "n_common.h"
36#include "n_log.h"
37#include "allegro5/allegro.h"
38
43
45typedef struct N_ATLAS_PAGE {
47 ALLEGRO_BITMAP* bmp;
49 uint16_t cols;
51 uint16_t rows;
53
55typedef struct N_ATLAS {
59 size_t npages;
60} N_ATLAS;
61
62N_ATLAS* new_n_atlas(size_t npages);
63void n_atlas_destroy(N_ATLAS** atlas);
64int n_atlas_set_page(N_ATLAS* atlas, size_t page, const void* bytes, size_t len, const char* ext, uint16_t cols, uint16_t rows);
65int n_atlas_page_ready(const N_ATLAS* atlas, size_t page);
66int n_atlas_draw_cell(N_ATLAS* atlas, size_t page, size_t index, float x, float y, float size);
67int n_atlas_cell_rect(const N_ATLAS* atlas, size_t page, size_t index, float* sx, float* sy, float* sw, float* sh);
69
73
74#ifdef __cplusplus
75}
76#endif
77
78#endif // __N_ATLAS_HEADER
uint16_t cols
grid width in cells
Definition n_atlas.h:49
N_ATLAS_PAGE * pages
page array, npages entries
Definition n_atlas.h:57
ALLEGRO_BITMAP * bmp
the decoded page bitmap, NULL until set
Definition n_atlas.h:47
uint16_t rows
grid height in cells
Definition n_atlas.h:51
size_t npages
number of pages
Definition n_atlas.h:59
int n_atlas_max_bitmap_size(void)
get the largest bitmap dimension this display can hold
Definition n_atlas.c:43
int n_atlas_set_page(N_ATLAS *atlas, size_t page, const void *bytes, size_t len, const char *ext, uint16_t cols, uint16_t rows)
decode bytes into one atlas page
Definition n_atlas.c:112
int n_atlas_draw_cell(N_ATLAS *atlas, size_t page, size_t index, float x, float y, float size)
draw one cell as a size x size square
Definition n_atlas.c:226
void n_atlas_destroy(N_ATLAS **atlas)
destroy an atlas and every bitmap it owns
Definition n_atlas.c:75
int n_atlas_page_ready(const N_ATLAS *atlas, size_t page)
test whether a page holds a usable bitmap
Definition n_atlas.c:160
int n_atlas_cell_rect(const N_ATLAS *atlas, size_t page, size_t index, float *sx, float *sy, float *sw, float *sh)
compute the source rectangle of one cell
Definition n_atlas.c:183
N_ATLAS * new_n_atlas(size_t npages)
allocate an atlas holding npages empty pages
Definition n_atlas.c:54
a set of atlas pages addressed as (page, cell index)
Definition n_atlas.h:55
one atlas page: a bitmap holding cols*rows equally sized cells
Definition n_atlas.h:45
Common headers and low-level functions & define.
Generic log system.