31 MakeEnumName(SDL_GPU_BLENDFACTOR_ZERO),
32 MakeEnumName(SDL_GPU_BLENDFACTOR_ONE),
33 MakeEnumName(SDL_GPU_BLENDFACTOR_SRC_COLOR),
34 MakeEnumName(SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_COLOR),
35 MakeEnumName(SDL_GPU_BLENDFACTOR_DST_COLOR),
36 MakeEnumName(SDL_GPU_BLENDFACTOR_ONE_MINUS_DST_COLOR),
37 MakeEnumName(SDL_GPU_BLENDFACTOR_SRC_ALPHA),
38 MakeEnumName(SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA),
39 MakeEnumName(SDL_GPU_BLENDFACTOR_DST_ALPHA),
40 MakeEnumName(SDL_GPU_BLENDFACTOR_ONE_MINUS_DST_ALPHA),
41 MakeEnumName(SDL_GPU_BLENDFACTOR_CONSTANT_COLOR),
42 MakeEnumName(SDL_GPU_BLENDFACTOR_ONE_MINUS_CONSTANT_COLOR),
43 MakeEnumName(SDL_GPU_BLENDFACTOR_SRC_ALPHA_SATURATE)
46#define _Class _ImageView
59 free(this->imageName);
79 const bool width = $(style->
attributes, objectForKeyPath,
"width") != NULL;
80 const bool height = $(style->
attributes, objectForKeyPath,
"height") != NULL;
83 const SDL_Size imageSize = $(this->
image,
size);
86 if (width && !height) {
88 size.h =
size.w * imageSize.h / (float) imageSize.w;
90 }
else if (height && !width) {
92 size.w =
size.h * imageSize.w / (float) imageSize.h;
94 }
else if (
size.w == 0 &&
size.h == 0) {
95 $(self,
resize, &imageSize);
116 $(self, bind, inlets, dictionary);
134 if (this->imageName == NULL) {
138 char *
name = this->imageName;
139 this->imageName = NULL;
151 this->imageName =
name;
171 SDL_Rect region, *src = NULL;
178 if (atlasImage->
atlas) {
180 region = atlasImage->
rect;
185 if (this->texture == NULL) {
186 this->texture = $(renderer->
device, createTextureFromSurface,
187 this->image->surface, SDL_GPU_TEXTUREUSAGE_SAMPLER,
false);
188 assert(this->texture);
203 SDL_RectToFRect(&frame, &frect);
232#pragma mark - ImageView
242 self->
blend.
src = SDL_GPU_BLENDFACTOR_SRC_ALPHA;
243 self->
blend.
dst = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
271 free(self->imageName);
272 self->imageName = NULL;
274 release(self->
image);
310 self->imageName = strdup(
name);
337#pragma mark - Class lifecycle
344 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
346 ((ViewInterface *) clazz->interface)->applyStyle =
applyStyle;
348 ((ViewInterface *) clazz->interface)->didMoveToWindow =
didMoveToWindow;
349 ((ViewInterface *) clazz->interface)->init =
init;
350 ((ViewInterface *) clazz->interface)->render =
render;
353 ((ImageViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
354 ((ImageViewInterface *) clazz->interface)->initWithImage =
initWithImage;
355 ((ImageViewInterface *) clazz->interface)->setImage =
setImage;
370 clazz = _initialize(&(
const ClassDef) {
372 .superclass =
_View(),
374 .interfaceSize =
sizeof(ImageViewInterface),
static AtlasImage * initWithImage(AtlasImage *self, ImageAtlas *atlas, Image *image)
Class * _AtlasImage(void)
static void initialize(Class *clazz)
static View * init(View *self)
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
static void dealloc(Object *self)
static Box * initWithFrame(Box *self, const SDL_Rect *frame)
static void applyStyle(View *self, const Style *style)
static void render(View *self, Renderer *renderer)
static String * name(const Font *self)
static Image * initWithSurface(Image *self, SDL_Surface *surface)
static Image * imageWithResource(const Resource *resource, float pixelDensity)
static Image * imageWithResourceName(const char *name, float pixelDensity)
static SDL_Size size(const Image *self)
static void renderDeviceWillReset(ImageAtlas *self)
static Texture * texture(ImageAtlas *self, RenderDevice *device)
Packs many Images into one sheet, backed by one Texture.
static void setImageWithResource(ImageView *self, const Resource *resource)
static void didMoveToWindow(View *self, SDL_Window *window)
static void setImageWithSurface(ImageView *self, SDL_Surface *surface)
static View * init(View *self)
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
static ImageView * initWithFrame(ImageView *self, const SDL_Rect *frame)
static void setImageWithResourceName(ImageView *self, const char *name)
static void applyStyle(View *self, const Style *style)
static void setImage(ImageView *self, Image *image)
static void render(View *self, Renderer *renderer)
static ImageView * initWithImage(ImageView *self, Image *image)
static void dealloc(Object *self)
const EnumName SDLGPUBlendFactorNames[]
static void initialize(Class *clazz)
static void renderDeviceWillReset(View *self)
ImageViews render an Image in the context of a View hierarchy.
static void drawTextureRegion(const Renderer *self, Texture *texture, const SDL_Rect *src, const SDL_FRect *dest, const SDL_Color *color)
static void drawRoundedTextureRegion(const Renderer *self, Texture *texture, const SDL_Rect *src, const SDL_FRect *dest, int radius, const SDL_Color *color)
static Theme * theme(SDL_Window *window)
static Image * image(Theme *self, const char *name, float pixelDensity)
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
static void resize(View *self, const SDL_Size *size)
static SDL_Rect renderFrame(const View *self)
#define ClampSize(size, min, max)
Clamps size to min and max, where a max of zero is unbounded.
An Image packed into an ImageAtlas.
SDL_Rect rect
This AtlasImage's rectangle within the atlas sheet, in texels.
ImageAtlas * atlas
The ImageAtlas this AtlasImage belongs to, or NULL once that atlas has been released,...
Packs many Images into one sheet, backed by one Texture.
ImageViews render an Image in the context of a View hierarchy.
ImageView * initWithFrame(ImageView *self, const SDL_Rect *frame)
Initializes this ImageView with the specified frame.
struct ImageView::@057055105372320051011063062227120011174355046077 blend
The blend factors (currently unused; reserved for future per-pipeline support).
void setImage(ImageView *self, Image *image)
Sets the Image for this ImageView.
Texture * texture
The GPU texture.
SDL_Color color
The drawing color.
Inlets enable inbound data binding of View attributes through JSON.
Renderer extends Object with ObjectivelyMVC's UI rendering layer.
RenderDevice * device
The backing RenderDevice.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
void invalidateStyle(View *self)
Invalidates the computed Style for this View and its descendants.
SDL_Window * window
The window.
void renderDeviceWillReset(View *self)
Informs this View that the render device will reset.
SDL_Size minSize
The minimum size this View may be resized to during layout.
void didMoveToWindow(View *self, SDL_Window *window)
Informs this View that it has been added to the View hierachy of the given window.
int borderRadius
The corner radius applied to the background, border and bevel.
SDL_Size maxSize
The maximum size this View may be resized to during layout.
SDL_Rect frame
The frame, relative to the superview.