summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2013-06-17 09:23:14 -0400
committerKristian Høgsberg <krh@bitplanet.net>2013-06-17 09:24:14 -0400
commit091b09652aa3a9d0d3d2f82a6529276d49a2012e (patch)
treec1706951c2e43f4b918c4d3bef4c2f91e3ebb309
parent7eec9b32f74bd571a5817a293f4edfe58a2c4290 (diff)
spring: Make min/max part of spring parameters
Don't hard code the 0.0 - 1.0 spring envelope.
-rw-r--r--src/animation.c30
-rw-r--r--src/compositor.h1
2 files changed, 19 insertions, 12 deletions
diff --git a/src/animation.c b/src/animation.c
index 57d384d2..b8de5748 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -42,6 +42,8 @@ weston_spring_init(struct weston_spring *spring,
spring->previous = current;
spring->target = target;
spring->clip = WESTON_SPRING_OVERSHOOT;
+ spring->min = 0.0;
+ spring->max = 1.0;
}
WL_EXPORT void
@@ -77,22 +79,26 @@ weston_spring_update(struct weston_spring *spring, uint32_t msec)
break;
case WESTON_SPRING_CLAMP:
- if (spring->current >= 1.0) {
- spring->current = 1.0;
- spring->previous = 1.0;
- } else if (spring->current <= 0.0) {
- spring->current = 0.0;
- spring->previous = 0.0;
+ if (spring->current > spring->max) {
+ spring->current = spring->max;
+ spring->previous = spring->max;
+ } else if (spring->current < 0.0) {
+ spring->current = spring->min;
+ spring->previous = spring->min;
}
break;
case WESTON_SPRING_BOUNCE:
- if (spring->current >= 1.0) {
- spring->current = 2.0 - spring->current;
- spring->previous = 2.0 - spring->previous;
- } else if (spring->current <= 0.0) {
- spring->current = -spring->current;
- spring->previous = -spring->previous;
+ if (spring->current > spring->max) {
+ spring->current =
+ 2 * spring->max - spring->current;
+ spring->previous =
+ 2 * spring->max - spring->previous;
+ } else if (spring->current < spring->min) {
+ spring->current =
+ 2 * spring->min - spring->current;
+ spring->previous =
+ 2 * spring->min - spring->previous;
}
break;
}
diff --git a/src/compositor.h b/src/compositor.h
index 12ec8e3a..faa2f200 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -125,6 +125,7 @@ struct weston_spring {
double current;
double target;
double previous;
+ double min, max;
uint32_t timestamp;
uint32_t clip;
};