26#include <SDL3/SDL_timer.h>
30#define _Class _SlideShowView
41 release(this->images);
64 const Array *images = (Array *) this->images;
65 if (images->count == 0) {
69 const Uint64 now = SDL_GetTicks();
71 if (this->current->image == NULL) {
72 Image *first = $(images, firstObject);
74 this->fadeEndedAt = now;
78 if (images->count < 2) {
82 if (this->fadeStartedAt) {
83 const float frac = (float) (now - this->fadeStartedAt) / (float) this->fadeDuration;
84 this->next->color.a = (Uint8) (SDL_min(frac, 1.f) * 255.f);
86 $(this->current,
setImage, this->next->image);
88 this->next->color.a = 0;
89 this->fadeStartedAt = 0;
90 this->fadeEndedAt = now;
92 }
else if (now - this->fadeEndedAt >= this->slideDuration) {
93 this->index = (this->index + 1) % images->count;
94 Image *
image = $(images, objectAtIndex, this->index);
96 this->fadeStartedAt = now;
100#pragma mark - SlideShowView
130 release(self->current);
134 self->next->color.a = 0;
142#pragma mark - Class lifecycle
149 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
151 ((ViewInterface *) clazz->interface)->render =
render;
152 ((ViewInterface *) clazz->interface)->init =
init;
154 ((SlideShowViewInterface *) clazz->interface)->addImage =
addImage;
155 ((SlideShowViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
167 clazz = _initialize(&(
const ClassDef) {
168 .name =
"SlideShowView",
169 .superclass =
_View(),
171 .interfaceSize =
sizeof(SlideShowViewInterface),
static void initialize(Class *clazz)
static View * init(View *self)
static void dealloc(Object *self)
static Box * initWithFrame(Box *self, const SDL_Rect *frame)
static void render(View *self, Renderer *renderer)
static AtlasImage * addImage(ImageAtlas *self, Image *image)
static void setImage(ImageView *self, Image *image)
static SlideShowView * initWithFrame(SlideShowView *self, const SDL_Rect *frame)
static void addImage(SlideShowView *self, Image *image)
static View * init(View *self)
static void render(View *self, Renderer *renderer)
static void dealloc(Object *self)
Class * _SlideShowView(void)
static void initialize(Class *clazz)
SlideShowView cycles through a collection of Images with crossfade transitions.
static Image * image(Theme *self, const char *name, float pixelDensity)
ImageViews render an Image in the context of a View hierarchy.
Renderer extends Object with ObjectivelyMVC's UI rendering layer.
SlideShowView cycles through a collection of Images with crossfade transitions.
SlideShowView * initWithFrame(SlideShowView *self, const SDL_Rect *frame)
Initializes this SlideShowView with the specified frame.
Array * images
The images to display.
ImageView * current
The bottom ImageView, showing the current slide.
Uint32 slideDuration
The duration of each slide in milliseconds, excluding the fade transition.
Uint32 fadeDuration
The duration of the fade transition in milliseconds.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
View * init(View *self)
Initializes this View.
SDL_Rect frame
The frame, relative to the superview.