ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
AtlasImage Struct Reference

An Image packed into an ImageAtlas. More...

#include <AtlasImage.h>

Inheritance diagram for AtlasImage:
Image

Public Member Functions

Class * _AtlasImage (void)
 
AtlasImage * initWithImage (AtlasImage *self, ImageAtlas *atlas, Image *image)
 Initializes this AtlasImage with the given Image's surface.
 
SDL_FRect texcoords (const AtlasImage *self)
 Resolves this AtlasImage's normalized texture coordinates within the atlas Texture.
 
- Public Member Functions inherited from Image
Class * _Image (void)
 The Image archetype.
 
Image * imageWithBytes (const uint8_t *bytes, size_t length)
 Instantiates an Image with the specified bytes.
 
Image * imageWithData (const Data *data)
 Instantiates an Image with the specified Data.
 
Image * imageWithResource (const Resource *resource)
 Instantiates an Image with the specified Resource.
 
Image * imageWithResourceName (const char *name)
 Instantiates an Image with the specified Resource name.
 
Image * imageWithSurface (SDL_Surface *surface)
 Instantiates an Image with the specified surface.
 
Image * imageWithSVG (const uint8_t *bytes, size_t length, float scale)
 Instantiates an Image by rasterizing the specified SVG.
 
Image * initWithBytes (Image *self, const uint8_t *bytes, size_t length)
 Initializes this Image with the specified bytes.
 
Image * initWithData (Image *self, const Data *data)
 Initializes this Image with the specified Data.
 
Image * initWithResource (Image *self, const Resource *resource)
 Initializes this Image with the specified Resource.
 
Image * initWithResourceName (Image *self, const char *name)
 Initializes this Image, loading the Resource by the given name.
 
Image * initWithSurface (Image *self, SDL_Surface *surface)
 Initializes this Image with the given surface.
 
Image * initWithSVG (Image *self, const uint8_t *bytes, size_t length, float scale)
 Initializes this Image by rasterizing the specified SVG at its intrinsic size times scale.
 
Image * initWithSVGSize (Image *self, const uint8_t *bytes, size_t length, SDL_Size points)
 Initializes this Image by rasterizing the specified SVG at points times the pixel density, so that Image::size reports points.
 
SDL_Size size (const Image *self)
 

Data Fields

ImageAtlas * atlas
 The ImageAtlas this AtlasImage belongs to, or NULL once that atlas has been released, after which this AtlasImage draws nothing.
 
Image image
 The superclass.
 
SDL_Rect rect
 This AtlasImage's rectangle within the atlas sheet, in texels.
 
- Data Fields inherited from Image
Object object
 The superclass.
 
float scale
 Pixels of surface per point: 1 for raster images, the requested scale for SVG.
 
SDL_Surface * surface
 The backing surface.
 
const char * type
 The image type, inferred if instantiated with a Resource.
 

Protected Attributes

AtlasImageInterface * interface [0]
 The interface type.
 
- Protected Attributes inherited from Image
ImageInterface * interface [0]
 The interface type.
 

Detailed Description

An Image packed into an ImageAtlas.

An AtlasImage keeps its source surface, so Image::size and anything else that reads surface behave as for a standalone Image. What it adds is where those pixels landed in the atlas sheet, so that a View drawing it samples the atlas Texture rather than a Texture of its own, and consecutive draws from the same atlas merge into one call.

Definition at line 41 of file AtlasImage.h.

Member 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
An Image packed into an ImageAtlas.
Definition AtlasImage.h:41
Class * _Image(void)
The Image archetype.
Definition Image.c:452

◆ initWithImage()

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

Initializes this AtlasImage with the given Image's surface.

Parameters
selfThe AtlasImage.
atlasThe ImageAtlas.
imageThe Image.
Returns
The initialized AtlasImage, or NULL on error.
Remarks
Use ImageAtlas::addImage; the atlas creates and owns its AtlasImages.

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}
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
Image * initWithSurface(Image *self, SDL_Surface *surface)
Initializes this Image with the given surface.
Definition Image.c:391
SDL_Surface * surface
The backing surface.
Definition Image.h:62

◆ texcoords()

SDL_FRect texcoords ( const AtlasImage *  self)

Resolves this AtlasImage's normalized texture coordinates within the atlas Texture.

Parameters
selfThe AtlasImage.
Returns
The texture coordinates, or an empty rectangle if the atlas has not been compiled or has been released.

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

Field Documentation

◆ atlas

ImageAtlas* AtlasImage::atlas

The ImageAtlas this AtlasImage belongs to, or NULL once that atlas has been released, after which this AtlasImage draws nothing.

Remarks
Weak: the atlas owns its AtlasImages, and clears this on dealloc.

Definition at line 59 of file AtlasImage.h.

◆ image

Image AtlasImage::image

The superclass.

Definition at line 46 of file AtlasImage.h.

◆ interface

AtlasImageInterface* AtlasImage::interface[0]
protected

The interface type.

Definition at line 52 of file AtlasImage.h.

◆ rect

SDL_Rect AtlasImage::rect

This AtlasImage's rectangle within the atlas sheet, in texels.

Remarks
Assigned by ImageAtlas::compile, and reassigned by every subsequent compile, so it MUST be read at draw time rather than cached.

Definition at line 66 of file AtlasImage.h.


The documentation for this struct was generated from the following files: