-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfluid_scroll.h
95 lines (66 loc) · 2.77 KB
/
fluid_scroll.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2023 ktiays
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __SCROLL_PHYSICS_H
#define __SCROLL_PHYSICS_H
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
char padding[16];
} FlScroller;
typedef struct {
float offset;
float velocity;
} FlScrollerValue;
void fl_scroller_init(FlScroller *scroller, float deceleration_rate);
void fl_scroller_init_default(FlScroller *scroller);
void fl_scroller_set_deceleration_rate(FlScroller *scroller,
float deceleration_rate);
void fl_scroller_fling(FlScroller *scroller, float velocity);
FlScrollerValue fl_scroller_value(FlScroller *scroller, float time,
bool *out_stop);
void fl_scroller_reset(FlScroller *scroller);
typedef struct {
char padding[16];
} FlSpringBack;
void fl_spring_back_init(FlSpringBack *spring_back);
void fl_spring_back_absorb(FlSpringBack *spring_back, float velocity,
float distance);
void fl_spring_back_absorb_with_response(FlSpringBack *spring_back,
float velocity, float distance,
float response);
float fl_spring_back_value(FlSpringBack *spring_back, float time,
bool *out_stop);
void fl_spring_back_reset(FlSpringBack *spring_back);
float fl_calculate_rubber_band_offset(float offset, float range);
float fl_calculate_rubber_band_offset_inv(float offset, float range);
typedef struct __FlVelocityTracker FlVelocityTracker;
enum FlVelocityTrackerStrategy {
FL_VELOCITY_TRACKER_RECURRENCE_STRATEGY = 0,
FL_VELOCITY_TRACKER_LSQ2_STRATEGY = 1,
};
FlVelocityTracker *fl_velocity_tracker_new(FlVelocityTrackerStrategy strategy);
FlVelocityTracker *fl_velocity_tracker_new_default(void);
void fl_velocity_tracker_free(FlVelocityTracker *velocity_tracker);
void fl_velocity_tracker_add_data_point(FlVelocityTracker *velocity_tracker,
float time, float position);
float fl_velocity_tracker_calculate_velocity(
FlVelocityTracker *velocity_tracker);
void fl_velocity_tracker_reset(FlVelocityTracker *velocity_tracker);
bool fl_velocity_approaching_halt(float vx, float vy);
#ifdef __cplusplus
}
#endif
#endif // __SCROLL_PHYSICS_H