From 9a54ab34a2f524a4c1798c7065e86928868bd223 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 24 Mar 2021 06:43:26 -0400 Subject: texture: Add accessor and texture creation funcs --- diff --git a/src/tileset.c b/src/tileset.c index 382220d..0871602 100644 --- a/src/tileset.c +++ b/src/tileset.c @@ -28,6 +28,7 @@ struct db_tileset { char *game_id; SDL_Surface *image; + SDL_Texture *texture; int tw; int th; int tc; @@ -410,3 +411,47 @@ db_tileset_new(const char *game_id, const char *file, int firstgid, return tileset; } + +int +db_tileset_tilewidth(struct db_tileset *tileset) +{ + return tileset->tw; +} + +int +db_tileset_tileheight(struct db_tileset *tileset) +{ + return tileset->th; +} + +int +db_tileset_tilecount(struct db_tileset *tileset) +{ + return tileset->tc; +} + +int +db_tileset_columns(struct db_tileset *tileset) +{ + return tileset->cols; +} + +int +db_tileset_firstgid(struct db_tileset *tileset) +{ + return tileset->firstgid; +} + +struct db_tileset * +db_tileset_next(struct db_tileset *tileset) +{ + return tileset->next; +} + +int +db_tileset_create_texture(struct db_tileset *tileset, SDL_Renderer *renderer) +{ + tileset->texture = SDL_CreateTextureFromSurface(renderer, + tileset->image); + return (tileset->texture != NULL ? 0 : -1); +} diff --git a/src/tileset.h b/src/tileset.h index 7a3a06a..8d660b7 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -24,5 +24,14 @@ struct db_tileset; struct db_tileset *db_tileset_new(const char *game_id, const char *file, int firstgid, struct db_tileset *prev); +int db_tileset_tilewidth (struct db_tileset *tileset) __attribute__((__pure__)); +int db_tileset_tileheight(struct db_tileset *tileset) __attribute__((__pure__)); +int db_tileset_tilecount (struct db_tileset *tileset) __attribute__((__pure__)); +int db_tileset_columns (struct db_tileset *tileset) __attribute__((__pure__)); +int db_tileset_firstgid (struct db_tileset *tileset) __attribute__((__pure__)); +struct db_tileset *db_tileset_next(struct db_tileset *tileset) + __attribute__((__pure__)); +int db_tileset_create_texture(struct db_tileset *tileset, + SDL_Renderer *renderer); #endif /* DB_TILESET_H_ */ -- cgit v0.9.1