120 lines
4.1 KiB
C++
120 lines
4.1 KiB
C++
// compositor.h v0.3
|
|
#pragma once
|
|
#ifndef COMPOSITOR_H
|
|
#define COMPOSITOR_H
|
|
|
|
// This subsystem is thread-unsafe.
|
|
// Caller must serialize all calls. Calls do not need to be made from the main thread.
|
|
// Removing an element while ticking/rendering may crash.
|
|
// Modifying an element while ticking/rendering may cause visual glitches.
|
|
|
|
// Easing functions
|
|
enum easing_t {
|
|
EASE_LINEAR = 0,
|
|
EASE_IN_QUAD,
|
|
EASE_OUT_QUAD,
|
|
EASE_IN_OUT_QUAD,
|
|
EASE_IN_CUBIC,
|
|
EASE_OUT_CUBIC,
|
|
EASE_IN_OUT_CUBIC
|
|
};
|
|
|
|
// Anchor points
|
|
enum anchor_point_t {
|
|
ANCHOR_TOP_LEFT,
|
|
ANCHOR_TOP_CENTER,
|
|
ANCHOR_TOP_RIGHT,
|
|
ANCHOR_CENTER_LEFT,
|
|
ANCHOR_CENTER,
|
|
ANCHOR_CENTER_RIGHT,
|
|
ANCHOR_BOTTOM_LEFT,
|
|
ANCHOR_BOTTOM_CENTER,
|
|
ANCHOR_BOTTOM_RIGHT,
|
|
};
|
|
|
|
#ifdef __cplusplus
|
|
#include <cstdint>
|
|
extern "C" {
|
|
#else
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#endif
|
|
|
|
typedef struct compositor_t compositor_t;
|
|
typedef uint32_t element_handle_t;
|
|
|
|
// If the return type is bool, false means failure.
|
|
|
|
// Initialize compositor with given dimensions
|
|
// nullptr means failure
|
|
compositor_t* compositor_init(uint32_t width, uint32_t height);
|
|
|
|
// Destroy compositor and free resources. Everything dies with it.
|
|
void compositor_destroy(compositor_t* comp);
|
|
|
|
// Insert element, returns unique ID
|
|
// FB format is ARGB8888 and it always will be
|
|
// The compositor takes a reference, caller must keep alive until removed
|
|
// 0 means failure, valid IDs start from 1
|
|
element_handle_t compositor_insert(compositor_t* comp,
|
|
const uint32_t* fb,
|
|
uint32_t fb_width,
|
|
uint32_t fb_height,
|
|
int32_t x, int32_t y,
|
|
int32_t z_order, float scale,
|
|
anchor_point_t anchor);
|
|
|
|
// Remove element by ID
|
|
bool compositor_remove(compositor_t* comp, element_handle_t id);
|
|
|
|
// Setters, immediate effect
|
|
bool compositor_set_position(compositor_t* comp, element_handle_t id,
|
|
int32_t x, int32_t y);
|
|
bool compositor_set_zorder(compositor_t* comp, element_handle_t id,
|
|
int32_t z_order);
|
|
bool compositor_set_scale(compositor_t* comp, element_handle_t id,
|
|
float scale);
|
|
bool compositor_set_visible(compositor_t* comp, element_handle_t id,
|
|
bool visible);
|
|
bool compositor_set_alpha(compositor_t* comp, element_handle_t id,
|
|
float alpha);
|
|
|
|
// Advances all animations by a given time delta.
|
|
void compositor_tick(compositor_t* comp, float delta_time_sec);
|
|
|
|
// Sets a target state to advance over time by tick()
|
|
// Queue means the animation will start after the previous animation completed
|
|
// Not queueing will play the animation alongside any current animation
|
|
// You cannot stack the same type of animation without queueing, the second call will cancel the first call.
|
|
bool compositor_animate_move(compositor_t* comp, element_handle_t id,
|
|
int32_t to_x, int32_t to_y,
|
|
float duration_sec, easing_t easing, bool queue, bool parallel);
|
|
bool compositor_animate_fade(compositor_t* comp, element_handle_t id,
|
|
float to_alpha,
|
|
float duration_sec, easing_t easing, bool queue, bool parallel);
|
|
bool compositor_animate_scale(compositor_t* comp, element_handle_t id,
|
|
float to_scale,
|
|
float duration_sec, easing_t easing, bool queue, bool parallel);
|
|
|
|
// Immediately finish all animations on a specific object (optionally only N queued, 0 = all), or every object.
|
|
bool compositor_animation_finish_element(compositor_t* comp, element_handle_t id, int num_queued /*0=all*/);
|
|
void compositor_animation_finish_all(compositor_t* comp);
|
|
|
|
// Returns true if any element is animating or has queued animations.
|
|
bool compositor_is_animating(compositor_t* comp);
|
|
|
|
// Returns true if the specified element is animating or has queued animations.
|
|
bool compositor_is_element_animating(compositor_t* comp, element_handle_t id);
|
|
|
|
// Compose all visible elements and return framebuffer pointer
|
|
const uint32_t* compositor_compose(compositor_t* comp);
|
|
|
|
// Mark an element's content as dirty for redrawing
|
|
bool compositor_mark_content_dirty(compositor_t* comp, element_handle_t id);
|
|
void compositor_mark_all_dirty(compositor_t* comp);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // COMPOSITOR_H
|