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
|
// -*- C++ -*-
/*
* Simple MultimEdia LiTerator(SMELT)
* by Chris Xiong 2015
* Progresser header & implementation
*
* WARNING: This library is in development and interfaces would be very
* unstable.
*
*/
#include "smmath.hpp"
class smProgresserLinear
{
private:
double a,b,val;
double elapsed,lim;
bool done;
public:
void init(double _a,double _b,double _lim){a=_a;b=_b;lim=_lim;}
void launch(){elapsed=.0;val=a;done=false;}
void update(double delta)
{
if(elapsed+delta>=lim)return(void)(val=b,elapsed=lim,done=true);
elapsed+=delta;val=(b-a)*(elapsed/lim)+a;
}
bool isDone(){return done;}
double getValue(){return val;}
double getPercentage(){return elapsed/lim;}
double getDelta(){return val-a;}
double getElapsed(){return elapsed;}
};
class smProgresserCurve
{
private:
double a,b,val;int cpara;
double elapsed,lim;
bool done;
double transformFunc(double x)
{
if(cpara>=64)return sqrt(1-sqr(x-1));
if(cpara>0)
{
double ctrx=(1+sqrt(2*sqr(64-cpara)-1))/2;double ctry=1-ctrx;
return sqrt(sqr(64-cpara)-sqr(x-ctrx))+ctry;
}
if(cpara==0)return x;
if(cpara<=-64)return -sqrt(1-sqr(x))+1;
if(cpara<0)
{
double ctrx=(1-sqrt(2*sqr(64+cpara)-1))/2;double ctry=1-ctrx;
return -sqrt(sqr(64+cpara)-sqr(x-ctrx))+ctry;
}
return NAN;
}
public:
void init(double _a,double _b,double _lim,int _cp){a=_a;b=_b;lim=_lim;cpara=_cp;}
void launch(){elapsed=.0;val=a;done=false;}
void update(double delta)
{
if(elapsed+delta>=lim)return(void)(val=b,elapsed=lim,done=true);
elapsed+=delta;val=(b-a)*transformFunc(elapsed/lim)+a;
}
bool isDone(){return done;}
double getValue(){return val;}
double getPercentage(){return elapsed/lim;}
double getDelta(){return val-a;}
double getElapsed(){return elapsed;}
};
|