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
110 $(self->
images, addObject, image);
130 release(self->current);
134 self->next->color.a = 0;
142#pragma mark - Class lifecycle
149 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
152 ((ViewInterface *) clazz->interface)->init =
init;
154 ((SlideShowViewInterface *) clazz->interface)->addImage =
addImage;
167 clazz = _initialize(&(
const ClassDef) {
168 .name =
"SlideShowView",
169 .superclass =
_View(),
172 .interfaceSize =
sizeof(SlideShowViewInterface),
static void setImage(ImageView *self, Image *image)
static void addSubview(View *self, View *subview)
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.
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.
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 render(View *self, Renderer *renderer)
Renders this View using the given renderer.
View * initWithFrame(View *self, const SDL_Rect *frame)
Initializes this View with the specified frame.