ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
AtlasImage.c File Reference
#include <assert.h>
#include "AtlasImage.h"
#include "ImageAtlas.h"

Go to the source code of this file.

Macros

#define _Class   _AtlasImage
 

Functions

Class * _AtlasImage (void)
 
static void initialize (Class *clazz)
 
static AtlasImage * initWithImage (AtlasImage *self, ImageAtlas *atlas, Image *image)
 
static SDL_FRect texcoords (const AtlasImage *self)
 

Macro Definition Documentation

◆ _Class

#define _Class   _AtlasImage

Definition at line 24 of file AtlasImage.c.

Function Documentation

◆ _AtlasImage()

Class * _AtlasImage ( void  )

Definition at line 84 of file AtlasImage.c.

84 {
85 static Class *clazz;
86 static Once once;
87
88 do_once(&once, {
89 clazz = _initialize(&(const ClassDef) {
90 .name = "AtlasImage",
91 .superclass = _Image(),
92 .instanceSize = sizeof(AtlasImage),
93 .interfaceSize = sizeof(AtlasImageInterface),
94 .initialize = initialize,
95 });
96 });
97
98 return clazz;
99}
static void initialize(Class *clazz)
Definition AtlasImage.c:74
Class * _Image(void)
Definition Image.c:452
An Image packed into an ImageAtlas.
Definition AtlasImage.h:41

◆ initialize()

static void initialize ( Class *  clazz)
static
See also
Class::initialize(Class *)

Definition at line 74 of file AtlasImage.c.

74 {
75
76 ((AtlasImageInterface *) clazz->interface)->initWithImage = initWithImage;
77 ((AtlasImageInterface *) clazz->interface)->texcoords = texcoords;
78}
static AtlasImage * initWithImage(AtlasImage *self, ImageAtlas *atlas, Image *image)
Definition AtlasImage.c:32
static SDL_FRect texcoords(const AtlasImage *self)
Definition AtlasImage.c:52
SDL_FRect texcoords(const AtlasImage *self)
Resolves this AtlasImage's normalized texture coordinates within the atlas Texture.
Definition AtlasImage.c:52

◆ initWithImage()

static AtlasImage * initWithImage ( AtlasImage *  self,
ImageAtlas *  atlas,
Image *  image 
)
static

Definition at line 32 of file AtlasImage.c.

32 {
33
34 assert(atlas);
35 assert(image);
36 assert(image->surface);
37
38 self = (AtlasImage *) super(Image, self, initWithSurface, image->surface);
39 if (self) {
40 self->image.scale = image->scale;
41 self->atlas = atlas;
42 self->rect = (SDL_Rect) { 0, 0, 0, 0 };
43 }
44
45 return self;
46}
static Image * initWithSurface(Image *self, SDL_Surface *surface)
Definition Image.c:391
static Image * image(Theme *self, const char *name, float pixelDensity)
Definition Theme.c:82
SDL_Rect rect
This AtlasImage's rectangle within the atlas sheet, in texels.
Definition AtlasImage.h:66
Image image
The superclass.
Definition AtlasImage.h:46
ImageAtlas * atlas
The ImageAtlas this AtlasImage belongs to, or NULL once that atlas has been released,...
Definition AtlasImage.h:59
Image loading.
Definition Image.h:41
float scale
Pixels of surface per point: 1 for raster images, the requested scale for SVG.
Definition Image.h:57
SDL_Surface * surface
The backing surface.
Definition Image.h:62

◆ texcoords()

static SDL_FRect texcoords ( const AtlasImage *  self)
static

Definition at line 52 of file AtlasImage.c.

52 {
53
54 const Image *sheet = self->atlas ? self->atlas->image : NULL;
55 if (sheet == NULL) {
56 return (SDL_FRect) { 0.f, 0.f, 0.f, 0.f };
57 }
58
59 const float w = (float) sheet->surface->w, h = (float) sheet->surface->h;
60
61 return (SDL_FRect) {
62 self->rect.x / w,
63 self->rect.y / h,
64 self->rect.w / w,
65 self->rect.h / h
66 };
67}
Image * image
The compiled sheet, or NULL until ImageAtlas::compile.
Definition ImageAtlas.h:71