main
Dominik Madarász 2023-10-28 22:36:59 +02:00
parent d4fcf42d7a
commit 6bc3c82ff0
10 changed files with 568 additions and 587 deletions

View File

@ -1610,59 +1610,6 @@ typedef float mat44[16];
float simplex2( vec2 xy ); float simplex2( vec2 xy );
float simplex3( vec3 xyz ); float simplex3( vec3 xyz );
float simplex4( vec4 xyzw ); float simplex4( vec4 xyzw );
float ease_linear(float t);
float ease_nearest(float t);
float ease_out_sine(float t);
float ease_out_quad(float t);
float ease_out_cubic(float t);
float ease_out_quart(float t);
float ease_out_quint(float t);
float ease_out_expo(float t);
float ease_out_circ(float t);
float ease_out_back(float t);
float ease_out_elastic(float t);
float ease_out_bounce(float t);
float ease_in_sine(float t);
float ease_in_quad(float t);
float ease_in_cubic(float t);
float ease_in_quart(float t);
float ease_in_quint(float t);
float ease_in_expo(float t);
float ease_in_circ(float t);
float ease_in_back(float t);
float ease_in_elastic(float t);
float ease_in_bounce(float t);
float ease_inout_sine(float t);
float ease_inout_quad(float t);
float ease_inout_cubic(float t);
float ease_inout_quart(float t);
float ease_inout_quint(float t);
float ease_inout_expo(float t);
float ease_inout_circ(float t);
float ease_inout_back(float t);
float ease_inout_elastic(float t);
float ease_inout_bounce(float t);
float ease_inout_perlin(float t);
enum EASE_FLAGS {
EASE_LINEAR,
EASE_SINE,
EASE_QUAD,
EASE_CUBIC,
EASE_QUART,
EASE_QUINT,
EASE_EXPO,
EASE_CIRC,
EASE_BACK,
EASE_ELASTIC,
EASE_BOUNCE,
EASE_IN,
EASE_INOUT = EASE_IN * 2,
EASE_OUT = 0,
};
float ease(float t01, unsigned fn);
float ease_pong(float t01, unsigned fn);
float ease_ping_pong(float t, unsigned fn1, unsigned fn2);
float ease_pong_ping(float t, unsigned fn1, unsigned fn2);
float deg (float radians); float deg (float radians);
float rad (float degrees); float rad (float degrees);
int mini (int a, int b); int mini (int a, int b);
@ -1842,6 +1789,58 @@ EASE_OUT = 0,
void print33( float *m ); void print33( float *m );
void print34( float *m ); void print34( float *m );
void print44( float *m ); void print44( float *m );
float ease_linear(float t);
float ease_out_sine(float t);
float ease_out_quad(float t);
float ease_out_cubic(float t);
float ease_out_quart(float t);
float ease_out_quint(float t);
float ease_out_expo(float t);
float ease_out_circ(float t);
float ease_out_back(float t);
float ease_out_elastic(float t);
float ease_out_bounce(float t);
float ease_in_sine(float t);
float ease_in_quad(float t);
float ease_in_cubic(float t);
float ease_in_quart(float t);
float ease_in_quint(float t);
float ease_in_expo(float t);
float ease_in_circ(float t);
float ease_in_back(float t);
float ease_in_elastic(float t);
float ease_in_bounce(float t);
float ease_inout_sine(float t);
float ease_inout_quad(float t);
float ease_inout_cubic(float t);
float ease_inout_quart(float t);
float ease_inout_quint(float t);
float ease_inout_expo(float t);
float ease_inout_circ(float t);
float ease_inout_back(float t);
float ease_inout_elastic(float t);
float ease_inout_bounce(float t);
float ease_inout_perlin(float t);
enum EASE_FLAGS {
EASE_LINEAR,
EASE_SINE,
EASE_QUAD,
EASE_CUBIC,
EASE_QUART,
EASE_QUINT,
EASE_EXPO,
EASE_CIRC,
EASE_BACK,
EASE_ELASTIC,
EASE_BOUNCE,
EASE_IN,
EASE_INOUT = EASE_IN * 2,
EASE_OUT = 0,
};
float ease(float t01, unsigned fn);
float ease_pong(float t01, unsigned fn);
float ease_ping_pong(float t, unsigned fn1, unsigned fn2);
float ease_pong_ping(float t, unsigned fn1, unsigned fn2);
typedef struct tween_keyframe_t { typedef struct tween_keyframe_t {
int easing_mode; int easing_mode;
float t; float t;

View File

@ -14933,69 +14933,6 @@ API float simplex4( vec4 xyzw );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
API float ease_linear(float t);
API float ease_nearest(float t);
API float ease_out_sine(float t);
API float ease_out_quad(float t);
API float ease_out_cubic(float t);
API float ease_out_quart(float t);
API float ease_out_quint(float t);
API float ease_out_expo(float t);
API float ease_out_circ(float t);
API float ease_out_back(float t);
API float ease_out_elastic(float t);
API float ease_out_bounce(float t);
API float ease_in_sine(float t);
API float ease_in_quad(float t);
API float ease_in_cubic(float t);
API float ease_in_quart(float t);
API float ease_in_quint(float t);
API float ease_in_expo(float t);
API float ease_in_circ(float t);
API float ease_in_back(float t);
API float ease_in_elastic(float t);
API float ease_in_bounce(float t);
API float ease_inout_sine(float t);
API float ease_inout_quad(float t);
API float ease_inout_cubic(float t);
API float ease_inout_quart(float t);
API float ease_inout_quint(float t);
API float ease_inout_expo(float t);
API float ease_inout_circ(float t);
API float ease_inout_back(float t);
API float ease_inout_elastic(float t);
API float ease_inout_bounce(float t);
API float ease_inout_perlin(float t);
enum EASE_FLAGS {
EASE_LINEAR,
EASE_SINE,
EASE_QUAD,
EASE_CUBIC,
EASE_QUART,
EASE_QUINT,
EASE_EXPO,
EASE_CIRC,
EASE_BACK,
EASE_ELASTIC,
EASE_BOUNCE,
EASE_IN,
EASE_INOUT = EASE_IN * 2,
EASE_OUT = 0,
};
API float ease(float t01, unsigned fn); // / 0-to-1
API float ease_pong(float t01, unsigned fn); // \ 1-to-0
API float ease_ping_pong(float t, unsigned fn1, unsigned fn2); // /\ 0-to-1-to-0
API float ease_pong_ping(float t, unsigned fn1, unsigned fn2); // \/ 1-to-0-to-1
// ----------------------------------------------------------------------------
API float deg (float radians); API float deg (float radians);
API float rad (float degrees); API float rad (float degrees);
@ -15226,6 +15163,72 @@ API void print44( float *m );
#line 0 #line 0
#line 1 "engine/split/v4k_tween.h" #line 1 "engine/split/v4k_tween.h"
// ----------------------------------------------------------------------------
// ease
API float ease_linear(float t);
API float ease_out_sine(float t);
API float ease_out_quad(float t);
API float ease_out_cubic(float t);
API float ease_out_quart(float t);
API float ease_out_quint(float t);
API float ease_out_expo(float t);
API float ease_out_circ(float t);
API float ease_out_back(float t);
API float ease_out_elastic(float t);
API float ease_out_bounce(float t);
API float ease_in_sine(float t);
API float ease_in_quad(float t);
API float ease_in_cubic(float t);
API float ease_in_quart(float t);
API float ease_in_quint(float t);
API float ease_in_expo(float t);
API float ease_in_circ(float t);
API float ease_in_back(float t);
API float ease_in_elastic(float t);
API float ease_in_bounce(float t);
API float ease_inout_sine(float t);
API float ease_inout_quad(float t);
API float ease_inout_cubic(float t);
API float ease_inout_quart(float t);
API float ease_inout_quint(float t);
API float ease_inout_expo(float t);
API float ease_inout_circ(float t);
API float ease_inout_back(float t);
API float ease_inout_elastic(float t);
API float ease_inout_bounce(float t);
API float ease_inout_perlin(float t);
enum EASE_FLAGS {
EASE_LINEAR,
EASE_SINE,
EASE_QUAD,
EASE_CUBIC,
EASE_QUART,
EASE_QUINT,
EASE_EXPO,
EASE_CIRC,
EASE_BACK,
EASE_ELASTIC,
EASE_BOUNCE,
EASE_IN,
EASE_INOUT = EASE_IN * 2,
EASE_OUT = 0,
};
API float ease(float t01, unsigned fn); // / 0-to-1
API float ease_pong(float t01, unsigned fn); // \ 1-to-0
API float ease_ping_pong(float t, unsigned fn1, unsigned fn2); // /\ 0-to-1-to-0
API float ease_pong_ping(float t, unsigned fn1, unsigned fn2); // \/ 1-to-0-to-1
// ----------------------------------------------------------------------------
// tween
typedef struct tween_keyframe_t { typedef struct tween_keyframe_t {
int easing_mode; int easing_mode;
float t; float t;
@ -340988,7 +340991,7 @@ vec2 input2( int vk ) {
// --- events // --- events
const float MS2FRAME = 60.0f; // 60 hz/1000 ms const float MS2FRAME = 0.06f; // 60 hz/1000 ms
int event( int vk ) { int event( int vk ) {
float v = input_frame(vk,0); float v = input_frame(vk,0);
@ -341015,29 +341018,18 @@ int input_up( int vk ) {
int input_idle( int vk ) { int input_idle( int vk ) {
return input_diff(vk) == 0 && input_frame(vk,0) <= 0; // input_frame(vk,-1) <= 0 && input_frame(vk,0) <= 0; return input_diff(vk) == 0 && input_frame(vk,0) <= 0; // input_frame(vk,-1) <= 0 && input_frame(vk,0) <= 0;
} }
int input_repeat(int vk, int ms) { int input_repeat( int vk, int ms ) { // @fixme: broken
assert(ms >= 0 && ms <= 1000); assert((unsigned)ms <= 1000);
float hz = window_fps() ? window_fps() : MS2FRAME; return input_frame(vk,-ms * MS2FRAME ) > 0 && input_frame(vk,-ms * MS2FRAME /2) > 0 && input_frame(vk,0) > 0;
return input_frame(vk, -ms * hz) > 0 &&
input_frame(vk, -ms * hz / 2.0) > 0 &&
input_frame(vk, 0) > 0;
} }
int input_click(int vk, int ms) { int input_click( int vk, int ms ) { // @fixme: broken
assert(ms >= 0 && ms <= 1000); assert((unsigned)ms <= 1000);
float hz = window_fps() ? window_fps() : MS2FRAME; return input_frame(vk,-ms * MS2FRAME ) <= 0 && input_frame(vk,-ms * MS2FRAME /2) > 0 && input_frame(vk,0) <= 0;
return input_frame(vk, -ms * hz) <= 0 &&
input_frame(vk, -ms * hz / 2.0) > 0 &&
input_frame(vk, 0) <= 0;
} }
int input_click2( int vk, int ms ) { // @fixme: broken
int input_click2(int vk, int ms) { assert((unsigned)ms <= 1000);
assert(ms >= 0 && ms <= 1000); return input_frame(vk,-ms * MS2FRAME ) <= 0 && input_frame(vk,-ms * MS2FRAME *3/4) > 0
float hz = window_fps() ? window_fps() : MS2FRAME; && input_frame(vk,-ms * MS2FRAME *2/4) <= 0 && input_frame(vk,-ms * MS2FRAME *1/4) > 0 && input_frame(vk,0) <= 0;
return input_frame(vk, -ms * hz) <= 0 &&
input_frame(vk, -ms * hz * 3 / 4.0) > 0 &&
input_frame(vk, -ms * hz * 2 / 4.0) <= 0 &&
input_frame(vk, -ms * hz * 1 / 4.0) > 0 &&
input_frame(vk, 0) <= 0;
} }
#undef MS2FRAME #undef MS2FRAME
@ -341442,94 +341434,6 @@ float simplex4( vec4 v ) { return snoise4(v.x,v.y,v.z,v.w); }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
float ease_linear(float t) { return t; }
float ease_nearest(float t) { return t >= 0.5f ? 1.0f : 0.0f; }
float ease_out_sine(float t) { return sinf(t*(C_PI*0.5f)); }
float ease_out_quad(float t) { return -(t*(t-2)); }
float ease_out_cubic(float t) { float f=t-1; return f*f*f+1; }
float ease_out_quart(float t) { float f=t-1; return f*f*f*(1-t)+1; }
float ease_out_quint(float t) { float f=(t-1); return f*f*f*f*f+1; }
float ease_out_expo(float t) { return (t >= 1) ? t : 1-powf(2,-10*t); }
float ease_out_circ(float t) { return sqrtf((2-t)*t); }
float ease_out_back(float t) { float f=1-t; return 1-(f*f*f-f*sinf(f*C_PI)); }
float ease_out_elastic(float t) { return sinf(-13*(C_PI*0.5f)*(t+1))*powf(2,-10*t)+1; }
float ease_out_bounce(float t) { return (t < 4.f/11) ? (121.f*t*t)/16 : (t < 8.f/11) ? (363.f/40*t*t)-(99.f/10*t)+17.f/5 : (t < 9.f/10) ? (4356.f/361*t*t)-(35442.f/1805*t)+16061.f/1805 : (54.f/5*t*t)-(513.f/25*t)+268.f/25; }
float ease_in_sine(float t) { return 1+sinf((t-1)*(C_PI*0.5f)); }
float ease_in_quad(float t) { return t*t; }
float ease_in_cubic(float t) { return t*t*t; }
float ease_in_quart(float t) { return t*t*t*t; }
float ease_in_quint(float t) { return t*t*t*t*t; }
float ease_in_expo(float t) { return (t <= 0) ? t : powf(2,10*(t-1)); }
float ease_in_circ(float t) { return 1-sqrtf(1-(t*t)); }
float ease_in_back(float t) { return t*t*t-t*sinf(t*C_PI); }
float ease_in_elastic(float t) { return sinf(13*(C_PI*0.5f)*t)*powf(2,10*(t-1)); }
float ease_in_bounce(float t) { return 1-ease_out_bounce(1-t); }
float ease_inout_sine(float t) { return 0.5f*(1-cosf(t*C_PI)); }
float ease_inout_quad(float t) { return (t < 0.5f) ? 2*t*t : (-2*t*t)+(4*t)-1; }
float ease_inout_cubic(float t) { float f; return (t < 0.5f) ? 4*t*t*t : (f=(2*t)-2,0.5f*f*f*f+1); }
float ease_inout_quart(float t) { float f; return (t < 0.5f) ? 8*t*t*t*t : (f=(t-1),-8*f*f*f*f+1); }
float ease_inout_quint(float t) { float f; return (t < 0.5f) ? 16*t*t*t*t*t : (f=((2*t)-2),0.5f*f*f*f*f*f+1); }
float ease_inout_expo(float t) { return (t <= 0 || t >= 1) ? t : t < 0.5f ? 0.5f*powf(2,(20*t)-10) : -0.5f*powf(2,(-20*t)+10)+1; }
float ease_inout_circ(float t) { return t < 0.5f ? 0.5f*(1-sqrtf(1-4*(t*t))) : 0.5f*(sqrtf(-((2*t)-3)*((2*t)-1))+1); }
float ease_inout_back(float t) { float f; return t < 0.5f ? (f=2*t,0.5f*(f*f*f-f*sinf(f*C_PI))) : (f=(1-(2*t-1)),0.5f*(1-(f*f*f-f*sinf(f*C_PI)))+0.5f); }
float ease_inout_elastic(float t) { return t < 0.5f ? 0.5f*sinf(13*(C_PI*0.5f)*(2*t))*powf(2,10*((2*t)-1)) : 0.5f*(sinf(-13*(C_PI*0.5f)*((2*t-1)+1))*powf(2,-10*(2*t-1))+2); }
float ease_inout_bounce(float t) { return t < 0.5f ? 0.5f*ease_in_bounce(t*2) : 0.5f*ease_out_bounce(t*2-1)+0.5f; }
float ease_inout_perlin(float t) { float t3=t*t*t,t4=t3*t,t5=t4*t; return 6*t5-15*t4+10*t3; }
float ease(float t01, unsigned mode) {
typedef float (*easing)(float);
easing modes[] = {
ease_linear,
ease_out_sine,
ease_out_quad,
ease_out_cubic,
ease_out_quart,
ease_out_quint,
ease_out_expo,
ease_out_circ,
ease_out_back,
ease_out_elastic,
ease_out_bounce,
ease_linear,
ease_in_sine,
ease_in_quad,
ease_in_cubic,
ease_in_quart,
ease_in_quint,
ease_in_expo,
ease_in_circ,
ease_in_back,
ease_in_elastic,
ease_in_bounce,
ease_linear,
ease_inout_sine,
ease_inout_quad,
ease_inout_cubic,
ease_inout_quart,
ease_inout_quint,
ease_inout_expo,
ease_inout_circ,
ease_inout_back,
ease_inout_elastic,
ease_inout_bounce,
ease_inout_perlin,
};
return modes[clampi(mode, 0, countof(modes))](clampf(t01,0,1));
}
float ease_pong(float t, unsigned fn) { return 1 - ease(t, fn); }
float ease_ping_pong(float t, unsigned fn1, unsigned fn2) { return t < 0.5 ? ease(t*2,fn1) : ease(1-(t-0.5)*2,fn2); }
float ease_pong_ping(float t, unsigned fn1, unsigned fn2) { return 1 - ease_ping_pong(t,fn1,fn2); }
// ----------------------------------------------------------------------------
float deg (float radians) { return radians / C_PI * 180.0f; } float deg (float radians) { return radians / C_PI * 180.0f; }
float rad (float degrees) { return degrees * C_PI / 180.0f; } float rad (float degrees) { return degrees * C_PI / 180.0f; }
@ -342333,6 +342237,97 @@ AUTORUN {
#line 0 #line 0
#line 1 "engine/split/v4k_tween.c" #line 1 "engine/split/v4k_tween.c"
// ----------------------------------------------------------------------------
// ease
float ease_linear(float t) { return t; }
float ease_out_sine(float t) { return sinf(t*(C_PI*0.5f)); }
float ease_out_quad(float t) { return -(t*(t-2)); }
float ease_out_cubic(float t) { float f=t-1; return f*f*f+1; }
float ease_out_quart(float t) { float f=t-1; return f*f*f*(1-t)+1; }
float ease_out_quint(float t) { float f=(t-1); return f*f*f*f*f+1; }
float ease_out_expo(float t) { return (t >= 1) ? t : 1-powf(2,-10*t); }
float ease_out_circ(float t) { return sqrtf((2-t)*t); }
float ease_out_back(float t) { float f=1-t; return 1-(f*f*f-f*sinf(f*C_PI)); }
float ease_out_elastic(float t) { return sinf(-13*(C_PI*0.5f)*(t+1))*powf(2,-10*t)+1; }
float ease_out_bounce(float t) { return (t < 4.f/11) ? (121.f*t*t)/16 : (t < 8.f/11) ? (363.f/40*t*t)-(99.f/10*t)+17.f/5 : (t < 9.f/10) ? (4356.f/361*t*t)-(35442.f/1805*t)+16061.f/1805 : (54.f/5*t*t)-(513.f/25*t)+268.f/25; }
float ease_in_sine(float t) { return 1+sinf((t-1)*(C_PI*0.5f)); }
float ease_in_quad(float t) { return t*t; }
float ease_in_cubic(float t) { return t*t*t; }
float ease_in_quart(float t) { return t*t*t*t; }
float ease_in_quint(float t) { return t*t*t*t*t; }
float ease_in_expo(float t) { return (t <= 0) ? t : powf(2,10*(t-1)); }
float ease_in_circ(float t) { return 1-sqrtf(1-(t*t)); }
float ease_in_back(float t) { return t*t*t-t*sinf(t*C_PI); }
float ease_in_elastic(float t) { return sinf(13*(C_PI*0.5f)*t)*powf(2,10*(t-1)); }
float ease_in_bounce(float t) { return 1-ease_out_bounce(1-t); }
float ease_inout_sine(float t) { return 0.5f*(1-cosf(t*C_PI)); }
float ease_inout_quad(float t) { return (t < 0.5f) ? 2*t*t : (-2*t*t)+(4*t)-1; }
float ease_inout_cubic(float t) { float f; return (t < 0.5f) ? 4*t*t*t : (f=(2*t)-2,0.5f*f*f*f+1); }
float ease_inout_quart(float t) { float f; return (t < 0.5f) ? 8*t*t*t*t : (f=(t-1),-8*f*f*f*f+1); }
float ease_inout_quint(float t) { float f; return (t < 0.5f) ? 16*t*t*t*t*t : (f=((2*t)-2),0.5f*f*f*f*f*f+1); }
float ease_inout_expo(float t) { return (t <= 0 || t >= 1) ? t : t < 0.5f ? 0.5f*powf(2,(20*t)-10) : -0.5f*powf(2,(-20*t)+10)+1; }
float ease_inout_circ(float t) { return t < 0.5f ? 0.5f*(1-sqrtf(1-4*(t*t))) : 0.5f*(sqrtf(-((2*t)-3)*((2*t)-1))+1); }
float ease_inout_back(float t) { float f; return t < 0.5f ? (f=2*t,0.5f*(f*f*f-f*sinf(f*C_PI))) : (f=(1-(2*t-1)),0.5f*(1-(f*f*f-f*sinf(f*C_PI)))+0.5f); }
float ease_inout_elastic(float t) { return t < 0.5f ? 0.5f*sinf(13*(C_PI*0.5f)*(2*t))*powf(2,10*((2*t)-1)) : 0.5f*(sinf(-13*(C_PI*0.5f)*((2*t-1)+1))*powf(2,-10*(2*t-1))+2); }
float ease_inout_bounce(float t) { return t < 0.5f ? 0.5f*ease_in_bounce(t*2) : 0.5f*ease_out_bounce(t*2-1)+0.5f; }
float ease_inout_perlin(float t) { float t3=t*t*t,t4=t3*t,t5=t4*t; return 6*t5-15*t4+10*t3; }
float ease(float t01, unsigned mode) {
typedef float (*easing)(float);
easing modes[] = {
ease_linear,
ease_out_sine,
ease_out_quad,
ease_out_cubic,
ease_out_quart,
ease_out_quint,
ease_out_expo,
ease_out_circ,
ease_out_back,
ease_out_elastic,
ease_out_bounce,
ease_linear,
ease_in_sine,
ease_in_quad,
ease_in_cubic,
ease_in_quart,
ease_in_quint,
ease_in_expo,
ease_in_circ,
ease_in_back,
ease_in_elastic,
ease_in_bounce,
ease_linear,
ease_inout_sine,
ease_inout_quad,
ease_inout_cubic,
ease_inout_quart,
ease_inout_quint,
ease_inout_expo,
ease_inout_circ,
ease_inout_back,
ease_inout_elastic,
ease_inout_bounce,
ease_inout_perlin,
};
return modes[clampi(mode, 0, countof(modes))](clampf(t01,0,1));
}
float ease_pong(float t, unsigned fn) { return 1 - ease(t, fn); }
float ease_ping_pong(float t, unsigned fn1, unsigned fn2) { return t < 0.5 ? ease(t*2,fn1) : ease(1-(t-0.5)*2,fn2); }
float ease_pong_ping(float t, unsigned fn1, unsigned fn2) { return 1 - ease_ping_pong(t,fn1,fn2); }
// ----------------------------------------------------------------------------
// tween
tween_t tween() { tween_t tween() {
tween_t tw = {0}; tween_t tw = {0};
return tw; return tw;
@ -342367,7 +342362,7 @@ void tween_destroy(tween_t *tw) {
*tw = tw_; *tw = tw_;
} }
static inline static INLINE
int tween_comp_keyframes(const void *a, const void *b) { int tween_comp_keyframes(const void *a, const void *b) {
float t1 = ((const tween_keyframe_t*)a)->t; float t1 = ((const tween_keyframe_t*)a)->t;
float t2 = ((const tween_keyframe_t*)b)->t; float t2 = ((const tween_keyframe_t*)b)->t;
@ -342381,7 +342376,7 @@ void tween_keyframe_set(tween_t *tw, float t, int mode, vec3 v) {
tw->duration = array_back(tw->keyframes)->t; tw->duration = array_back(tw->keyframes)->t;
} }
void tween_keyframe_unset(tween_t *tw, float t) { /*@todo: untested*/ void tween_keyframe_unset(tween_t *tw, float t) { // @todo: untested
int id = -1; int id = -1;
for (int i = 0; i < array_count(tw->keyframes); i++) { for (int i = 0; i < array_count(tw->keyframes); i++) {
if (tw->keyframes[i].t == t) { if (tw->keyframes[i].t == t) {
@ -353232,7 +353227,6 @@ nk_hovered_text(struct nk_context *ctx, const char *str, int len,
int embedded = !!ui_ctx->current; \ int embedded = !!ui_ctx->current; \
struct nk_rect total_space = {0,0,window_width(),window_height()}; \ struct nk_rect total_space = {0,0,window_width(),window_height()}; \
if( embedded ) total_space = nk_window_get_bounds(ui_ctx), total_space.w -= 10; \ if( embedded ) total_space = nk_window_get_bounds(ui_ctx), total_space.w -= 10; \
vec2 popup_space = { total_space.w * 0.33, total_space.h * 0.85 }; \
int created = !embedded && nk_begin(ui_ctx, "MENU_" STRINGIZE(__COUNTER__), nk_rect(0, 0, window_width(), UI_MENUROW_HEIGHT), NK_WINDOW_NO_SCROLLBAR); \ int created = !embedded && nk_begin(ui_ctx, "MENU_" STRINGIZE(__COUNTER__), nk_rect(0, 0, window_width(), UI_MENUROW_HEIGHT), NK_WINDOW_NO_SCROLLBAR); \
if ( embedded || created ) { \ if ( embedded || created ) { \
int align = NK_TEXT_LEFT, Nth = (N), ITEM_WIDTH = 30, span = 0; \ int align = NK_TEXT_LEFT, Nth = (N), ITEM_WIDTH = 30, span = 0; \
@ -353242,10 +353236,10 @@ nk_hovered_text(struct nk_context *ctx, const char *str, int len,
nk_menubar_end(ui_ctx); \ nk_menubar_end(ui_ctx); \
if( created ) nk_end(ui_ctx); \ if( created ) nk_end(ui_ctx); \
} } while(0) } } while(0)
#define UI_MENU_POPUP(title, ...) { \ #define UI_MENU_POPUP(title, px, ...) { \
int hspace = maxi(ITEM_WIDTH, nk_text_width(ui_ctx,(title),0)); \ int hspace = maxi(ITEM_WIDTH, nk_text_width(ui_ctx,(title),0)); \
nk_layout_row_push(ui_ctx, hspace); span += hspace; \ nk_layout_row_push(ui_ctx, hspace); span += hspace; \
if (nk_menu_begin_label(ui_ctx, (title), align, nk_vec2(popup_space.w,popup_space.h))) { \ if (nk_menu_begin_label(ui_ctx, (title), align, nk_vec2(px.x>1?px.x:px.x*total_space.w,px.y>1?px.y:px.y*total_space.h))) { \
__VA_ARGS__; \ __VA_ARGS__; \
nk_menu_end(ui_ctx); \ nk_menu_end(ui_ctx); \
}} }}

View File

@ -398,7 +398,7 @@ vec2 input2( int vk ) {
// --- events // --- events
const float MS2FRAME = 60.0f; // 60 hz/1000 ms const float MS2FRAME = 0.06f; // 60 hz/1000 ms
int event( int vk ) { int event( int vk ) {
float v = input_frame(vk,0); float v = input_frame(vk,0);
@ -425,29 +425,18 @@ int input_up( int vk ) {
int input_idle( int vk ) { int input_idle( int vk ) {
return input_diff(vk) == 0 && input_frame(vk,0) <= 0; // input_frame(vk,-1) <= 0 && input_frame(vk,0) <= 0; return input_diff(vk) == 0 && input_frame(vk,0) <= 0; // input_frame(vk,-1) <= 0 && input_frame(vk,0) <= 0;
} }
int input_repeat(int vk, int ms) { int input_repeat( int vk, int ms ) { // @fixme: broken
assert(ms >= 0 && ms <= 1000); assert((unsigned)ms <= 1000);
float hz = window_fps() ? window_fps() : MS2FRAME; return input_frame(vk,-ms * MS2FRAME ) > 0 && input_frame(vk,-ms * MS2FRAME /2) > 0 && input_frame(vk,0) > 0;
return input_frame(vk, -ms * hz) > 0 &&
input_frame(vk, -ms * hz / 2.0) > 0 &&
input_frame(vk, 0) > 0;
} }
int input_click(int vk, int ms) { int input_click( int vk, int ms ) { // @fixme: broken
assert(ms >= 0 && ms <= 1000); assert((unsigned)ms <= 1000);
float hz = window_fps() ? window_fps() : MS2FRAME; return input_frame(vk,-ms * MS2FRAME ) <= 0 && input_frame(vk,-ms * MS2FRAME /2) > 0 && input_frame(vk,0) <= 0;
return input_frame(vk, -ms * hz) <= 0 &&
input_frame(vk, -ms * hz / 2.0) > 0 &&
input_frame(vk, 0) <= 0;
} }
int input_click2( int vk, int ms ) { // @fixme: broken
int input_click2(int vk, int ms) { assert((unsigned)ms <= 1000);
assert(ms >= 0 && ms <= 1000); return input_frame(vk,-ms * MS2FRAME ) <= 0 && input_frame(vk,-ms * MS2FRAME *3/4) > 0
float hz = window_fps() ? window_fps() : MS2FRAME; && input_frame(vk,-ms * MS2FRAME *2/4) <= 0 && input_frame(vk,-ms * MS2FRAME *1/4) > 0 && input_frame(vk,0) <= 0;
return input_frame(vk, -ms * hz) <= 0 &&
input_frame(vk, -ms * hz * 3 / 4.0) > 0 &&
input_frame(vk, -ms * hz * 2 / 4.0) <= 0 &&
input_frame(vk, -ms * hz * 1 / 4.0) > 0 &&
input_frame(vk, 0) <= 0;
} }
#undef MS2FRAME #undef MS2FRAME

View File

@ -75,94 +75,6 @@ float simplex4( vec4 v ) { return snoise4(v.x,v.y,v.z,v.w); }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
float ease_linear(float t) { return t; }
float ease_nearest(float t) { return t >= 0.5f ? 1.0f : 0.0f; }
float ease_out_sine(float t) { return sinf(t*(C_PI*0.5f)); }
float ease_out_quad(float t) { return -(t*(t-2)); }
float ease_out_cubic(float t) { float f=t-1; return f*f*f+1; }
float ease_out_quart(float t) { float f=t-1; return f*f*f*(1-t)+1; }
float ease_out_quint(float t) { float f=(t-1); return f*f*f*f*f+1; }
float ease_out_expo(float t) { return (t >= 1) ? t : 1-powf(2,-10*t); }
float ease_out_circ(float t) { return sqrtf((2-t)*t); }
float ease_out_back(float t) { float f=1-t; return 1-(f*f*f-f*sinf(f*C_PI)); }
float ease_out_elastic(float t) { return sinf(-13*(C_PI*0.5f)*(t+1))*powf(2,-10*t)+1; }
float ease_out_bounce(float t) { return (t < 4.f/11) ? (121.f*t*t)/16 : (t < 8.f/11) ? (363.f/40*t*t)-(99.f/10*t)+17.f/5 : (t < 9.f/10) ? (4356.f/361*t*t)-(35442.f/1805*t)+16061.f/1805 : (54.f/5*t*t)-(513.f/25*t)+268.f/25; }
float ease_in_sine(float t) { return 1+sinf((t-1)*(C_PI*0.5f)); }
float ease_in_quad(float t) { return t*t; }
float ease_in_cubic(float t) { return t*t*t; }
float ease_in_quart(float t) { return t*t*t*t; }
float ease_in_quint(float t) { return t*t*t*t*t; }
float ease_in_expo(float t) { return (t <= 0) ? t : powf(2,10*(t-1)); }
float ease_in_circ(float t) { return 1-sqrtf(1-(t*t)); }
float ease_in_back(float t) { return t*t*t-t*sinf(t*C_PI); }
float ease_in_elastic(float t) { return sinf(13*(C_PI*0.5f)*t)*powf(2,10*(t-1)); }
float ease_in_bounce(float t) { return 1-ease_out_bounce(1-t); }
float ease_inout_sine(float t) { return 0.5f*(1-cosf(t*C_PI)); }
float ease_inout_quad(float t) { return (t < 0.5f) ? 2*t*t : (-2*t*t)+(4*t)-1; }
float ease_inout_cubic(float t) { float f; return (t < 0.5f) ? 4*t*t*t : (f=(2*t)-2,0.5f*f*f*f+1); }
float ease_inout_quart(float t) { float f; return (t < 0.5f) ? 8*t*t*t*t : (f=(t-1),-8*f*f*f*f+1); }
float ease_inout_quint(float t) { float f; return (t < 0.5f) ? 16*t*t*t*t*t : (f=((2*t)-2),0.5f*f*f*f*f*f+1); }
float ease_inout_expo(float t) { return (t <= 0 || t >= 1) ? t : t < 0.5f ? 0.5f*powf(2,(20*t)-10) : -0.5f*powf(2,(-20*t)+10)+1; }
float ease_inout_circ(float t) { return t < 0.5f ? 0.5f*(1-sqrtf(1-4*(t*t))) : 0.5f*(sqrtf(-((2*t)-3)*((2*t)-1))+1); }
float ease_inout_back(float t) { float f; return t < 0.5f ? (f=2*t,0.5f*(f*f*f-f*sinf(f*C_PI))) : (f=(1-(2*t-1)),0.5f*(1-(f*f*f-f*sinf(f*C_PI)))+0.5f); }
float ease_inout_elastic(float t) { return t < 0.5f ? 0.5f*sinf(13*(C_PI*0.5f)*(2*t))*powf(2,10*((2*t)-1)) : 0.5f*(sinf(-13*(C_PI*0.5f)*((2*t-1)+1))*powf(2,-10*(2*t-1))+2); }
float ease_inout_bounce(float t) { return t < 0.5f ? 0.5f*ease_in_bounce(t*2) : 0.5f*ease_out_bounce(t*2-1)+0.5f; }
float ease_inout_perlin(float t) { float t3=t*t*t,t4=t3*t,t5=t4*t; return 6*t5-15*t4+10*t3; }
float ease(float t01, unsigned mode) {
typedef float (*easing)(float);
easing modes[] = {
ease_linear,
ease_out_sine,
ease_out_quad,
ease_out_cubic,
ease_out_quart,
ease_out_quint,
ease_out_expo,
ease_out_circ,
ease_out_back,
ease_out_elastic,
ease_out_bounce,
ease_linear,
ease_in_sine,
ease_in_quad,
ease_in_cubic,
ease_in_quart,
ease_in_quint,
ease_in_expo,
ease_in_circ,
ease_in_back,
ease_in_elastic,
ease_in_bounce,
ease_linear,
ease_inout_sine,
ease_inout_quad,
ease_inout_cubic,
ease_inout_quart,
ease_inout_quint,
ease_inout_expo,
ease_inout_circ,
ease_inout_back,
ease_inout_elastic,
ease_inout_bounce,
ease_inout_perlin,
};
return modes[clampi(mode, 0, countof(modes))](clampf(t01,0,1));
}
float ease_pong(float t, unsigned fn) { return 1 - ease(t, fn); }
float ease_ping_pong(float t, unsigned fn1, unsigned fn2) { return t < 0.5 ? ease(t*2,fn1) : ease(1-(t-0.5)*2,fn2); }
float ease_pong_ping(float t, unsigned fn1, unsigned fn2) { return 1 - ease_ping_pong(t,fn1,fn2); }
// ----------------------------------------------------------------------------
float deg (float radians) { return radians / C_PI * 180.0f; } float deg (float radians) { return radians / C_PI * 180.0f; }
float rad (float degrees) { return degrees * C_PI / 180.0f; } float rad (float degrees) { return degrees * C_PI / 180.0f; }

View File

@ -49,69 +49,6 @@ API float simplex4( vec4 xyzw );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
API float ease_linear(float t);
API float ease_nearest(float t);
API float ease_out_sine(float t);
API float ease_out_quad(float t);
API float ease_out_cubic(float t);
API float ease_out_quart(float t);
API float ease_out_quint(float t);
API float ease_out_expo(float t);
API float ease_out_circ(float t);
API float ease_out_back(float t);
API float ease_out_elastic(float t);
API float ease_out_bounce(float t);
API float ease_in_sine(float t);
API float ease_in_quad(float t);
API float ease_in_cubic(float t);
API float ease_in_quart(float t);
API float ease_in_quint(float t);
API float ease_in_expo(float t);
API float ease_in_circ(float t);
API float ease_in_back(float t);
API float ease_in_elastic(float t);
API float ease_in_bounce(float t);
API float ease_inout_sine(float t);
API float ease_inout_quad(float t);
API float ease_inout_cubic(float t);
API float ease_inout_quart(float t);
API float ease_inout_quint(float t);
API float ease_inout_expo(float t);
API float ease_inout_circ(float t);
API float ease_inout_back(float t);
API float ease_inout_elastic(float t);
API float ease_inout_bounce(float t);
API float ease_inout_perlin(float t);
enum EASE_FLAGS {
EASE_LINEAR,
EASE_SINE,
EASE_QUAD,
EASE_CUBIC,
EASE_QUART,
EASE_QUINT,
EASE_EXPO,
EASE_CIRC,
EASE_BACK,
EASE_ELASTIC,
EASE_BOUNCE,
EASE_IN,
EASE_INOUT = EASE_IN * 2,
EASE_OUT = 0,
};
API float ease(float t01, unsigned fn); // / 0-to-1
API float ease_pong(float t01, unsigned fn); // \ 1-to-0
API float ease_ping_pong(float t, unsigned fn1, unsigned fn2); // /\ 0-to-1-to-0
API float ease_pong_ping(float t, unsigned fn1, unsigned fn2); // \/ 1-to-0-to-1
// ----------------------------------------------------------------------------
API float deg (float radians); API float deg (float radians);
API float rad (float degrees); API float rad (float degrees);

View File

@ -1,3 +1,94 @@
// ----------------------------------------------------------------------------
// ease
float ease_linear(float t) { return t; }
float ease_out_sine(float t) { return sinf(t*(C_PI*0.5f)); }
float ease_out_quad(float t) { return -(t*(t-2)); }
float ease_out_cubic(float t) { float f=t-1; return f*f*f+1; }
float ease_out_quart(float t) { float f=t-1; return f*f*f*(1-t)+1; }
float ease_out_quint(float t) { float f=(t-1); return f*f*f*f*f+1; }
float ease_out_expo(float t) { return (t >= 1) ? t : 1-powf(2,-10*t); }
float ease_out_circ(float t) { return sqrtf((2-t)*t); }
float ease_out_back(float t) { float f=1-t; return 1-(f*f*f-f*sinf(f*C_PI)); }
float ease_out_elastic(float t) { return sinf(-13*(C_PI*0.5f)*(t+1))*powf(2,-10*t)+1; }
float ease_out_bounce(float t) { return (t < 4.f/11) ? (121.f*t*t)/16 : (t < 8.f/11) ? (363.f/40*t*t)-(99.f/10*t)+17.f/5 : (t < 9.f/10) ? (4356.f/361*t*t)-(35442.f/1805*t)+16061.f/1805 : (54.f/5*t*t)-(513.f/25*t)+268.f/25; }
float ease_in_sine(float t) { return 1+sinf((t-1)*(C_PI*0.5f)); }
float ease_in_quad(float t) { return t*t; }
float ease_in_cubic(float t) { return t*t*t; }
float ease_in_quart(float t) { return t*t*t*t; }
float ease_in_quint(float t) { return t*t*t*t*t; }
float ease_in_expo(float t) { return (t <= 0) ? t : powf(2,10*(t-1)); }
float ease_in_circ(float t) { return 1-sqrtf(1-(t*t)); }
float ease_in_back(float t) { return t*t*t-t*sinf(t*C_PI); }
float ease_in_elastic(float t) { return sinf(13*(C_PI*0.5f)*t)*powf(2,10*(t-1)); }
float ease_in_bounce(float t) { return 1-ease_out_bounce(1-t); }
float ease_inout_sine(float t) { return 0.5f*(1-cosf(t*C_PI)); }
float ease_inout_quad(float t) { return (t < 0.5f) ? 2*t*t : (-2*t*t)+(4*t)-1; }
float ease_inout_cubic(float t) { float f; return (t < 0.5f) ? 4*t*t*t : (f=(2*t)-2,0.5f*f*f*f+1); }
float ease_inout_quart(float t) { float f; return (t < 0.5f) ? 8*t*t*t*t : (f=(t-1),-8*f*f*f*f+1); }
float ease_inout_quint(float t) { float f; return (t < 0.5f) ? 16*t*t*t*t*t : (f=((2*t)-2),0.5f*f*f*f*f*f+1); }
float ease_inout_expo(float t) { return (t <= 0 || t >= 1) ? t : t < 0.5f ? 0.5f*powf(2,(20*t)-10) : -0.5f*powf(2,(-20*t)+10)+1; }
float ease_inout_circ(float t) { return t < 0.5f ? 0.5f*(1-sqrtf(1-4*(t*t))) : 0.5f*(sqrtf(-((2*t)-3)*((2*t)-1))+1); }
float ease_inout_back(float t) { float f; return t < 0.5f ? (f=2*t,0.5f*(f*f*f-f*sinf(f*C_PI))) : (f=(1-(2*t-1)),0.5f*(1-(f*f*f-f*sinf(f*C_PI)))+0.5f); }
float ease_inout_elastic(float t) { return t < 0.5f ? 0.5f*sinf(13*(C_PI*0.5f)*(2*t))*powf(2,10*((2*t)-1)) : 0.5f*(sinf(-13*(C_PI*0.5f)*((2*t-1)+1))*powf(2,-10*(2*t-1))+2); }
float ease_inout_bounce(float t) { return t < 0.5f ? 0.5f*ease_in_bounce(t*2) : 0.5f*ease_out_bounce(t*2-1)+0.5f; }
float ease_inout_perlin(float t) { float t3=t*t*t,t4=t3*t,t5=t4*t; return 6*t5-15*t4+10*t3; }
float ease(float t01, unsigned mode) {
typedef float (*easing)(float);
easing modes[] = {
ease_linear,
ease_out_sine,
ease_out_quad,
ease_out_cubic,
ease_out_quart,
ease_out_quint,
ease_out_expo,
ease_out_circ,
ease_out_back,
ease_out_elastic,
ease_out_bounce,
ease_linear,
ease_in_sine,
ease_in_quad,
ease_in_cubic,
ease_in_quart,
ease_in_quint,
ease_in_expo,
ease_in_circ,
ease_in_back,
ease_in_elastic,
ease_in_bounce,
ease_linear,
ease_inout_sine,
ease_inout_quad,
ease_inout_cubic,
ease_inout_quart,
ease_inout_quint,
ease_inout_expo,
ease_inout_circ,
ease_inout_back,
ease_inout_elastic,
ease_inout_bounce,
ease_inout_perlin,
};
return modes[clampi(mode, 0, countof(modes))](clampf(t01,0,1));
}
float ease_pong(float t, unsigned fn) { return 1 - ease(t, fn); }
float ease_ping_pong(float t, unsigned fn1, unsigned fn2) { return t < 0.5 ? ease(t*2,fn1) : ease(1-(t-0.5)*2,fn2); }
float ease_pong_ping(float t, unsigned fn1, unsigned fn2) { return 1 - ease_ping_pong(t,fn1,fn2); }
// ----------------------------------------------------------------------------
// tween
tween_t tween() { tween_t tween() {
tween_t tw = {0}; tween_t tw = {0};
return tw; return tw;
@ -32,7 +123,7 @@ void tween_destroy(tween_t *tw) {
*tw = tw_; *tw = tw_;
} }
static inline static INLINE
int tween_comp_keyframes(const void *a, const void *b) { int tween_comp_keyframes(const void *a, const void *b) {
float t1 = ((const tween_keyframe_t*)a)->t; float t1 = ((const tween_keyframe_t*)a)->t;
float t2 = ((const tween_keyframe_t*)b)->t; float t2 = ((const tween_keyframe_t*)b)->t;
@ -46,7 +137,7 @@ void tween_keyframe_set(tween_t *tw, float t, int mode, vec3 v) {
tw->duration = array_back(tw->keyframes)->t; tw->duration = array_back(tw->keyframes)->t;
} }
void tween_keyframe_unset(tween_t *tw, float t) { /*@todo: untested*/ void tween_keyframe_unset(tween_t *tw, float t) { // @todo: untested
int id = -1; int id = -1;
for (int i = 0; i < array_count(tw->keyframes); i++) { for (int i = 0; i < array_count(tw->keyframes); i++) {
if (tw->keyframes[i].t == t) { if (tw->keyframes[i].t == t) {

View File

@ -1,3 +1,69 @@
// ----------------------------------------------------------------------------
// ease
API float ease_linear(float t);
API float ease_out_sine(float t);
API float ease_out_quad(float t);
API float ease_out_cubic(float t);
API float ease_out_quart(float t);
API float ease_out_quint(float t);
API float ease_out_expo(float t);
API float ease_out_circ(float t);
API float ease_out_back(float t);
API float ease_out_elastic(float t);
API float ease_out_bounce(float t);
API float ease_in_sine(float t);
API float ease_in_quad(float t);
API float ease_in_cubic(float t);
API float ease_in_quart(float t);
API float ease_in_quint(float t);
API float ease_in_expo(float t);
API float ease_in_circ(float t);
API float ease_in_back(float t);
API float ease_in_elastic(float t);
API float ease_in_bounce(float t);
API float ease_inout_sine(float t);
API float ease_inout_quad(float t);
API float ease_inout_cubic(float t);
API float ease_inout_quart(float t);
API float ease_inout_quint(float t);
API float ease_inout_expo(float t);
API float ease_inout_circ(float t);
API float ease_inout_back(float t);
API float ease_inout_elastic(float t);
API float ease_inout_bounce(float t);
API float ease_inout_perlin(float t);
enum EASE_FLAGS {
EASE_LINEAR,
EASE_SINE,
EASE_QUAD,
EASE_CUBIC,
EASE_QUART,
EASE_QUINT,
EASE_EXPO,
EASE_CIRC,
EASE_BACK,
EASE_ELASTIC,
EASE_BOUNCE,
EASE_IN,
EASE_INOUT = EASE_IN * 2,
EASE_OUT = 0,
};
API float ease(float t01, unsigned fn); // / 0-to-1
API float ease_pong(float t01, unsigned fn); // \ 1-to-0
API float ease_ping_pong(float t, unsigned fn1, unsigned fn2); // /\ 0-to-1-to-0
API float ease_pong_ping(float t, unsigned fn1, unsigned fn2); // \/ 1-to-0-to-1
// ----------------------------------------------------------------------------
// tween
typedef struct tween_keyframe_t { typedef struct tween_keyframe_t {
int easing_mode; int easing_mode;
float t; float t;

View File

@ -81,7 +81,6 @@ nk_hovered_text(struct nk_context *ctx, const char *str, int len,
int embedded = !!ui_ctx->current; \ int embedded = !!ui_ctx->current; \
struct nk_rect total_space = {0,0,window_width(),window_height()}; \ struct nk_rect total_space = {0,0,window_width(),window_height()}; \
if( embedded ) total_space = nk_window_get_bounds(ui_ctx), total_space.w -= 10; \ if( embedded ) total_space = nk_window_get_bounds(ui_ctx), total_space.w -= 10; \
vec2 popup_space = { total_space.w * 0.33, total_space.h * 0.85 }; \
int created = !embedded && nk_begin(ui_ctx, "MENU_" STRINGIZE(__COUNTER__), nk_rect(0, 0, window_width(), UI_MENUROW_HEIGHT), NK_WINDOW_NO_SCROLLBAR); \ int created = !embedded && nk_begin(ui_ctx, "MENU_" STRINGIZE(__COUNTER__), nk_rect(0, 0, window_width(), UI_MENUROW_HEIGHT), NK_WINDOW_NO_SCROLLBAR); \
if ( embedded || created ) { \ if ( embedded || created ) { \
int align = NK_TEXT_LEFT, Nth = (N), ITEM_WIDTH = 30, span = 0; \ int align = NK_TEXT_LEFT, Nth = (N), ITEM_WIDTH = 30, span = 0; \
@ -91,10 +90,10 @@ nk_hovered_text(struct nk_context *ctx, const char *str, int len,
nk_menubar_end(ui_ctx); \ nk_menubar_end(ui_ctx); \
if( created ) nk_end(ui_ctx); \ if( created ) nk_end(ui_ctx); \
} } while(0) } } while(0)
#define UI_MENU_POPUP(title, ...) { \ #define UI_MENU_POPUP(title, px, ...) { \
int hspace = maxi(ITEM_WIDTH, nk_text_width(ui_ctx,(title),0)); \ int hspace = maxi(ITEM_WIDTH, nk_text_width(ui_ctx,(title),0)); \
nk_layout_row_push(ui_ctx, hspace); span += hspace; \ nk_layout_row_push(ui_ctx, hspace); span += hspace; \
if (nk_menu_begin_label(ui_ctx, (title), align, nk_vec2(popup_space.w,popup_space.h))) { \ if (nk_menu_begin_label(ui_ctx, (title), align, nk_vec2(px.x>1?px.x:px.x*total_space.w,px.y>1?px.y:px.y*total_space.h))) { \
__VA_ARGS__; \ __VA_ARGS__; \
nk_menu_end(ui_ctx); \ nk_menu_end(ui_ctx); \
}} }}

View File

@ -8887,7 +8887,7 @@ vec2 input2( int vk ) {
// --- events // --- events
const float MS2FRAME = 60.0f; // 60 hz/1000 ms const float MS2FRAME = 0.06f; // 60 hz/1000 ms
int event( int vk ) { int event( int vk ) {
float v = input_frame(vk,0); float v = input_frame(vk,0);
@ -8914,29 +8914,18 @@ int input_up( int vk ) {
int input_idle( int vk ) { int input_idle( int vk ) {
return input_diff(vk) == 0 && input_frame(vk,0) <= 0; // input_frame(vk,-1) <= 0 && input_frame(vk,0) <= 0; return input_diff(vk) == 0 && input_frame(vk,0) <= 0; // input_frame(vk,-1) <= 0 && input_frame(vk,0) <= 0;
} }
int input_repeat(int vk, int ms) { int input_repeat( int vk, int ms ) { // @fixme: broken
assert(ms >= 0 && ms <= 1000); assert((unsigned)ms <= 1000);
float hz = window_fps() ? window_fps() : MS2FRAME; return input_frame(vk,-ms * MS2FRAME ) > 0 && input_frame(vk,-ms * MS2FRAME /2) > 0 && input_frame(vk,0) > 0;
return input_frame(vk, -ms * hz) > 0 &&
input_frame(vk, -ms * hz / 2.0) > 0 &&
input_frame(vk, 0) > 0;
} }
int input_click(int vk, int ms) { int input_click( int vk, int ms ) { // @fixme: broken
assert(ms >= 0 && ms <= 1000); assert((unsigned)ms <= 1000);
float hz = window_fps() ? window_fps() : MS2FRAME; return input_frame(vk,-ms * MS2FRAME ) <= 0 && input_frame(vk,-ms * MS2FRAME /2) > 0 && input_frame(vk,0) <= 0;
return input_frame(vk, -ms * hz) <= 0 &&
input_frame(vk, -ms * hz / 2.0) > 0 &&
input_frame(vk, 0) <= 0;
} }
int input_click2( int vk, int ms ) { // @fixme: broken
int input_click2(int vk, int ms) { assert((unsigned)ms <= 1000);
assert(ms >= 0 && ms <= 1000); return input_frame(vk,-ms * MS2FRAME ) <= 0 && input_frame(vk,-ms * MS2FRAME *3/4) > 0
float hz = window_fps() ? window_fps() : MS2FRAME; && input_frame(vk,-ms * MS2FRAME *2/4) <= 0 && input_frame(vk,-ms * MS2FRAME *1/4) > 0 && input_frame(vk,0) <= 0;
return input_frame(vk, -ms * hz) <= 0 &&
input_frame(vk, -ms * hz * 3 / 4.0) > 0 &&
input_frame(vk, -ms * hz * 2 / 4.0) <= 0 &&
input_frame(vk, -ms * hz * 1 / 4.0) > 0 &&
input_frame(vk, 0) <= 0;
} }
#undef MS2FRAME #undef MS2FRAME
@ -9341,94 +9330,6 @@ float simplex4( vec4 v ) { return snoise4(v.x,v.y,v.z,v.w); }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
float ease_linear(float t) { return t; }
float ease_nearest(float t) { return t >= 0.5f ? 1.0f : 0.0f; }
float ease_out_sine(float t) { return sinf(t*(C_PI*0.5f)); }
float ease_out_quad(float t) { return -(t*(t-2)); }
float ease_out_cubic(float t) { float f=t-1; return f*f*f+1; }
float ease_out_quart(float t) { float f=t-1; return f*f*f*(1-t)+1; }
float ease_out_quint(float t) { float f=(t-1); return f*f*f*f*f+1; }
float ease_out_expo(float t) { return (t >= 1) ? t : 1-powf(2,-10*t); }
float ease_out_circ(float t) { return sqrtf((2-t)*t); }
float ease_out_back(float t) { float f=1-t; return 1-(f*f*f-f*sinf(f*C_PI)); }
float ease_out_elastic(float t) { return sinf(-13*(C_PI*0.5f)*(t+1))*powf(2,-10*t)+1; }
float ease_out_bounce(float t) { return (t < 4.f/11) ? (121.f*t*t)/16 : (t < 8.f/11) ? (363.f/40*t*t)-(99.f/10*t)+17.f/5 : (t < 9.f/10) ? (4356.f/361*t*t)-(35442.f/1805*t)+16061.f/1805 : (54.f/5*t*t)-(513.f/25*t)+268.f/25; }
float ease_in_sine(float t) { return 1+sinf((t-1)*(C_PI*0.5f)); }
float ease_in_quad(float t) { return t*t; }
float ease_in_cubic(float t) { return t*t*t; }
float ease_in_quart(float t) { return t*t*t*t; }
float ease_in_quint(float t) { return t*t*t*t*t; }
float ease_in_expo(float t) { return (t <= 0) ? t : powf(2,10*(t-1)); }
float ease_in_circ(float t) { return 1-sqrtf(1-(t*t)); }
float ease_in_back(float t) { return t*t*t-t*sinf(t*C_PI); }
float ease_in_elastic(float t) { return sinf(13*(C_PI*0.5f)*t)*powf(2,10*(t-1)); }
float ease_in_bounce(float t) { return 1-ease_out_bounce(1-t); }
float ease_inout_sine(float t) { return 0.5f*(1-cosf(t*C_PI)); }
float ease_inout_quad(float t) { return (t < 0.5f) ? 2*t*t : (-2*t*t)+(4*t)-1; }
float ease_inout_cubic(float t) { float f; return (t < 0.5f) ? 4*t*t*t : (f=(2*t)-2,0.5f*f*f*f+1); }
float ease_inout_quart(float t) { float f; return (t < 0.5f) ? 8*t*t*t*t : (f=(t-1),-8*f*f*f*f+1); }
float ease_inout_quint(float t) { float f; return (t < 0.5f) ? 16*t*t*t*t*t : (f=((2*t)-2),0.5f*f*f*f*f*f+1); }
float ease_inout_expo(float t) { return (t <= 0 || t >= 1) ? t : t < 0.5f ? 0.5f*powf(2,(20*t)-10) : -0.5f*powf(2,(-20*t)+10)+1; }
float ease_inout_circ(float t) { return t < 0.5f ? 0.5f*(1-sqrtf(1-4*(t*t))) : 0.5f*(sqrtf(-((2*t)-3)*((2*t)-1))+1); }
float ease_inout_back(float t) { float f; return t < 0.5f ? (f=2*t,0.5f*(f*f*f-f*sinf(f*C_PI))) : (f=(1-(2*t-1)),0.5f*(1-(f*f*f-f*sinf(f*C_PI)))+0.5f); }
float ease_inout_elastic(float t) { return t < 0.5f ? 0.5f*sinf(13*(C_PI*0.5f)*(2*t))*powf(2,10*((2*t)-1)) : 0.5f*(sinf(-13*(C_PI*0.5f)*((2*t-1)+1))*powf(2,-10*(2*t-1))+2); }
float ease_inout_bounce(float t) { return t < 0.5f ? 0.5f*ease_in_bounce(t*2) : 0.5f*ease_out_bounce(t*2-1)+0.5f; }
float ease_inout_perlin(float t) { float t3=t*t*t,t4=t3*t,t5=t4*t; return 6*t5-15*t4+10*t3; }
float ease(float t01, unsigned mode) {
typedef float (*easing)(float);
easing modes[] = {
ease_linear,
ease_out_sine,
ease_out_quad,
ease_out_cubic,
ease_out_quart,
ease_out_quint,
ease_out_expo,
ease_out_circ,
ease_out_back,
ease_out_elastic,
ease_out_bounce,
ease_linear,
ease_in_sine,
ease_in_quad,
ease_in_cubic,
ease_in_quart,
ease_in_quint,
ease_in_expo,
ease_in_circ,
ease_in_back,
ease_in_elastic,
ease_in_bounce,
ease_linear,
ease_inout_sine,
ease_inout_quad,
ease_inout_cubic,
ease_inout_quart,
ease_inout_quint,
ease_inout_expo,
ease_inout_circ,
ease_inout_back,
ease_inout_elastic,
ease_inout_bounce,
ease_inout_perlin,
};
return modes[clampi(mode, 0, countof(modes))](clampf(t01,0,1));
}
float ease_pong(float t, unsigned fn) { return 1 - ease(t, fn); }
float ease_ping_pong(float t, unsigned fn1, unsigned fn2) { return t < 0.5 ? ease(t*2,fn1) : ease(1-(t-0.5)*2,fn2); }
float ease_pong_ping(float t, unsigned fn1, unsigned fn2) { return 1 - ease_ping_pong(t,fn1,fn2); }
// ----------------------------------------------------------------------------
float deg (float radians) { return radians / C_PI * 180.0f; } float deg (float radians) { return radians / C_PI * 180.0f; }
float rad (float degrees) { return degrees * C_PI / 180.0f; } float rad (float degrees) { return degrees * C_PI / 180.0f; }
@ -10232,6 +10133,97 @@ AUTORUN {
#line 0 #line 0
#line 1 "engine/split/v4k_tween.c" #line 1 "engine/split/v4k_tween.c"
// ----------------------------------------------------------------------------
// ease
float ease_linear(float t) { return t; }
float ease_out_sine(float t) { return sinf(t*(C_PI*0.5f)); }
float ease_out_quad(float t) { return -(t*(t-2)); }
float ease_out_cubic(float t) { float f=t-1; return f*f*f+1; }
float ease_out_quart(float t) { float f=t-1; return f*f*f*(1-t)+1; }
float ease_out_quint(float t) { float f=(t-1); return f*f*f*f*f+1; }
float ease_out_expo(float t) { return (t >= 1) ? t : 1-powf(2,-10*t); }
float ease_out_circ(float t) { return sqrtf((2-t)*t); }
float ease_out_back(float t) { float f=1-t; return 1-(f*f*f-f*sinf(f*C_PI)); }
float ease_out_elastic(float t) { return sinf(-13*(C_PI*0.5f)*(t+1))*powf(2,-10*t)+1; }
float ease_out_bounce(float t) { return (t < 4.f/11) ? (121.f*t*t)/16 : (t < 8.f/11) ? (363.f/40*t*t)-(99.f/10*t)+17.f/5 : (t < 9.f/10) ? (4356.f/361*t*t)-(35442.f/1805*t)+16061.f/1805 : (54.f/5*t*t)-(513.f/25*t)+268.f/25; }
float ease_in_sine(float t) { return 1+sinf((t-1)*(C_PI*0.5f)); }
float ease_in_quad(float t) { return t*t; }
float ease_in_cubic(float t) { return t*t*t; }
float ease_in_quart(float t) { return t*t*t*t; }
float ease_in_quint(float t) { return t*t*t*t*t; }
float ease_in_expo(float t) { return (t <= 0) ? t : powf(2,10*(t-1)); }
float ease_in_circ(float t) { return 1-sqrtf(1-(t*t)); }
float ease_in_back(float t) { return t*t*t-t*sinf(t*C_PI); }
float ease_in_elastic(float t) { return sinf(13*(C_PI*0.5f)*t)*powf(2,10*(t-1)); }
float ease_in_bounce(float t) { return 1-ease_out_bounce(1-t); }
float ease_inout_sine(float t) { return 0.5f*(1-cosf(t*C_PI)); }
float ease_inout_quad(float t) { return (t < 0.5f) ? 2*t*t : (-2*t*t)+(4*t)-1; }
float ease_inout_cubic(float t) { float f; return (t < 0.5f) ? 4*t*t*t : (f=(2*t)-2,0.5f*f*f*f+1); }
float ease_inout_quart(float t) { float f; return (t < 0.5f) ? 8*t*t*t*t : (f=(t-1),-8*f*f*f*f+1); }
float ease_inout_quint(float t) { float f; return (t < 0.5f) ? 16*t*t*t*t*t : (f=((2*t)-2),0.5f*f*f*f*f*f+1); }
float ease_inout_expo(float t) { return (t <= 0 || t >= 1) ? t : t < 0.5f ? 0.5f*powf(2,(20*t)-10) : -0.5f*powf(2,(-20*t)+10)+1; }
float ease_inout_circ(float t) { return t < 0.5f ? 0.5f*(1-sqrtf(1-4*(t*t))) : 0.5f*(sqrtf(-((2*t)-3)*((2*t)-1))+1); }
float ease_inout_back(float t) { float f; return t < 0.5f ? (f=2*t,0.5f*(f*f*f-f*sinf(f*C_PI))) : (f=(1-(2*t-1)),0.5f*(1-(f*f*f-f*sinf(f*C_PI)))+0.5f); }
float ease_inout_elastic(float t) { return t < 0.5f ? 0.5f*sinf(13*(C_PI*0.5f)*(2*t))*powf(2,10*((2*t)-1)) : 0.5f*(sinf(-13*(C_PI*0.5f)*((2*t-1)+1))*powf(2,-10*(2*t-1))+2); }
float ease_inout_bounce(float t) { return t < 0.5f ? 0.5f*ease_in_bounce(t*2) : 0.5f*ease_out_bounce(t*2-1)+0.5f; }
float ease_inout_perlin(float t) { float t3=t*t*t,t4=t3*t,t5=t4*t; return 6*t5-15*t4+10*t3; }
float ease(float t01, unsigned mode) {
typedef float (*easing)(float);
easing modes[] = {
ease_linear,
ease_out_sine,
ease_out_quad,
ease_out_cubic,
ease_out_quart,
ease_out_quint,
ease_out_expo,
ease_out_circ,
ease_out_back,
ease_out_elastic,
ease_out_bounce,
ease_linear,
ease_in_sine,
ease_in_quad,
ease_in_cubic,
ease_in_quart,
ease_in_quint,
ease_in_expo,
ease_in_circ,
ease_in_back,
ease_in_elastic,
ease_in_bounce,
ease_linear,
ease_inout_sine,
ease_inout_quad,
ease_inout_cubic,
ease_inout_quart,
ease_inout_quint,
ease_inout_expo,
ease_inout_circ,
ease_inout_back,
ease_inout_elastic,
ease_inout_bounce,
ease_inout_perlin,
};
return modes[clampi(mode, 0, countof(modes))](clampf(t01,0,1));
}
float ease_pong(float t, unsigned fn) { return 1 - ease(t, fn); }
float ease_ping_pong(float t, unsigned fn1, unsigned fn2) { return t < 0.5 ? ease(t*2,fn1) : ease(1-(t-0.5)*2,fn2); }
float ease_pong_ping(float t, unsigned fn1, unsigned fn2) { return 1 - ease_ping_pong(t,fn1,fn2); }
// ----------------------------------------------------------------------------
// tween
tween_t tween() { tween_t tween() {
tween_t tw = {0}; tween_t tw = {0};
return tw; return tw;
@ -10266,7 +10258,7 @@ void tween_destroy(tween_t *tw) {
*tw = tw_; *tw = tw_;
} }
static inline static INLINE
int tween_comp_keyframes(const void *a, const void *b) { int tween_comp_keyframes(const void *a, const void *b) {
float t1 = ((const tween_keyframe_t*)a)->t; float t1 = ((const tween_keyframe_t*)a)->t;
float t2 = ((const tween_keyframe_t*)b)->t; float t2 = ((const tween_keyframe_t*)b)->t;
@ -10280,7 +10272,7 @@ void tween_keyframe_set(tween_t *tw, float t, int mode, vec3 v) {
tw->duration = array_back(tw->keyframes)->t; tw->duration = array_back(tw->keyframes)->t;
} }
void tween_keyframe_unset(tween_t *tw, float t) { /*@todo: untested*/ void tween_keyframe_unset(tween_t *tw, float t) { // @todo: untested
int id = -1; int id = -1;
for (int i = 0; i < array_count(tw->keyframes); i++) { for (int i = 0; i < array_count(tw->keyframes); i++) {
if (tw->keyframes[i].t == t) { if (tw->keyframes[i].t == t) {
@ -21131,7 +21123,6 @@ nk_hovered_text(struct nk_context *ctx, const char *str, int len,
int embedded = !!ui_ctx->current; \ int embedded = !!ui_ctx->current; \
struct nk_rect total_space = {0,0,window_width(),window_height()}; \ struct nk_rect total_space = {0,0,window_width(),window_height()}; \
if( embedded ) total_space = nk_window_get_bounds(ui_ctx), total_space.w -= 10; \ if( embedded ) total_space = nk_window_get_bounds(ui_ctx), total_space.w -= 10; \
vec2 popup_space = { total_space.w * 0.33, total_space.h * 0.85 }; \
int created = !embedded && nk_begin(ui_ctx, "MENU_" STRINGIZE(__COUNTER__), nk_rect(0, 0, window_width(), UI_MENUROW_HEIGHT), NK_WINDOW_NO_SCROLLBAR); \ int created = !embedded && nk_begin(ui_ctx, "MENU_" STRINGIZE(__COUNTER__), nk_rect(0, 0, window_width(), UI_MENUROW_HEIGHT), NK_WINDOW_NO_SCROLLBAR); \
if ( embedded || created ) { \ if ( embedded || created ) { \
int align = NK_TEXT_LEFT, Nth = (N), ITEM_WIDTH = 30, span = 0; \ int align = NK_TEXT_LEFT, Nth = (N), ITEM_WIDTH = 30, span = 0; \
@ -21141,10 +21132,10 @@ nk_hovered_text(struct nk_context *ctx, const char *str, int len,
nk_menubar_end(ui_ctx); \ nk_menubar_end(ui_ctx); \
if( created ) nk_end(ui_ctx); \ if( created ) nk_end(ui_ctx); \
} } while(0) } } while(0)
#define UI_MENU_POPUP(title, ...) { \ #define UI_MENU_POPUP(title, px, ...) { \
int hspace = maxi(ITEM_WIDTH, nk_text_width(ui_ctx,(title),0)); \ int hspace = maxi(ITEM_WIDTH, nk_text_width(ui_ctx,(title),0)); \
nk_layout_row_push(ui_ctx, hspace); span += hspace; \ nk_layout_row_push(ui_ctx, hspace); span += hspace; \
if (nk_menu_begin_label(ui_ctx, (title), align, nk_vec2(popup_space.w,popup_space.h))) { \ if (nk_menu_begin_label(ui_ctx, (title), align, nk_vec2(px.x>1?px.x:px.x*total_space.w,px.y>1?px.y:px.y*total_space.h))) { \
__VA_ARGS__; \ __VA_ARGS__; \
nk_menu_end(ui_ctx); \ nk_menu_end(ui_ctx); \
}} }}

View File

@ -1000,69 +1000,6 @@ API float simplex4( vec4 xyzw );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
API float ease_linear(float t);
API float ease_nearest(float t);
API float ease_out_sine(float t);
API float ease_out_quad(float t);
API float ease_out_cubic(float t);
API float ease_out_quart(float t);
API float ease_out_quint(float t);
API float ease_out_expo(float t);
API float ease_out_circ(float t);
API float ease_out_back(float t);
API float ease_out_elastic(float t);
API float ease_out_bounce(float t);
API float ease_in_sine(float t);
API float ease_in_quad(float t);
API float ease_in_cubic(float t);
API float ease_in_quart(float t);
API float ease_in_quint(float t);
API float ease_in_expo(float t);
API float ease_in_circ(float t);
API float ease_in_back(float t);
API float ease_in_elastic(float t);
API float ease_in_bounce(float t);
API float ease_inout_sine(float t);
API float ease_inout_quad(float t);
API float ease_inout_cubic(float t);
API float ease_inout_quart(float t);
API float ease_inout_quint(float t);
API float ease_inout_expo(float t);
API float ease_inout_circ(float t);
API float ease_inout_back(float t);
API float ease_inout_elastic(float t);
API float ease_inout_bounce(float t);
API float ease_inout_perlin(float t);
enum EASE_FLAGS {
EASE_LINEAR,
EASE_SINE,
EASE_QUAD,
EASE_CUBIC,
EASE_QUART,
EASE_QUINT,
EASE_EXPO,
EASE_CIRC,
EASE_BACK,
EASE_ELASTIC,
EASE_BOUNCE,
EASE_IN,
EASE_INOUT = EASE_IN * 2,
EASE_OUT = 0,
};
API float ease(float t01, unsigned fn); // / 0-to-1
API float ease_pong(float t01, unsigned fn); // \ 1-to-0
API float ease_ping_pong(float t, unsigned fn1, unsigned fn2); // /\ 0-to-1-to-0
API float ease_pong_ping(float t, unsigned fn1, unsigned fn2); // \/ 1-to-0-to-1
// ----------------------------------------------------------------------------
API float deg (float radians); API float deg (float radians);
API float rad (float degrees); API float rad (float degrees);
@ -1293,6 +1230,72 @@ API void print44( float *m );
#line 0 #line 0
#line 1 "engine/split/v4k_tween.h" #line 1 "engine/split/v4k_tween.h"
// ----------------------------------------------------------------------------
// ease
API float ease_linear(float t);
API float ease_out_sine(float t);
API float ease_out_quad(float t);
API float ease_out_cubic(float t);
API float ease_out_quart(float t);
API float ease_out_quint(float t);
API float ease_out_expo(float t);
API float ease_out_circ(float t);
API float ease_out_back(float t);
API float ease_out_elastic(float t);
API float ease_out_bounce(float t);
API float ease_in_sine(float t);
API float ease_in_quad(float t);
API float ease_in_cubic(float t);
API float ease_in_quart(float t);
API float ease_in_quint(float t);
API float ease_in_expo(float t);
API float ease_in_circ(float t);
API float ease_in_back(float t);
API float ease_in_elastic(float t);
API float ease_in_bounce(float t);
API float ease_inout_sine(float t);
API float ease_inout_quad(float t);
API float ease_inout_cubic(float t);
API float ease_inout_quart(float t);
API float ease_inout_quint(float t);
API float ease_inout_expo(float t);
API float ease_inout_circ(float t);
API float ease_inout_back(float t);
API float ease_inout_elastic(float t);
API float ease_inout_bounce(float t);
API float ease_inout_perlin(float t);
enum EASE_FLAGS {
EASE_LINEAR,
EASE_SINE,
EASE_QUAD,
EASE_CUBIC,
EASE_QUART,
EASE_QUINT,
EASE_EXPO,
EASE_CIRC,
EASE_BACK,
EASE_ELASTIC,
EASE_BOUNCE,
EASE_IN,
EASE_INOUT = EASE_IN * 2,
EASE_OUT = 0,
};
API float ease(float t01, unsigned fn); // / 0-to-1
API float ease_pong(float t01, unsigned fn); // \ 1-to-0
API float ease_ping_pong(float t, unsigned fn1, unsigned fn2); // /\ 0-to-1-to-0
API float ease_pong_ping(float t, unsigned fn1, unsigned fn2); // \/ 1-to-0-to-1
// ----------------------------------------------------------------------------
// tween
typedef struct tween_keyframe_t { typedef struct tween_keyframe_t {
int easing_mode; int easing_mode;
float t; float t;