]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider_decibels.c
let's USE the super keyword! yay!
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider_decibels.c
1 #ifdef INTERFACE
2 CLASS(XonoticDecibelsSlider) EXTENDS(XonoticSlider)
3         METHOD(XonoticDecibelsSlider, loadCvars, void(entity))
4         METHOD(XonoticDecibelsSlider, saveCvars, void(entity))
5         METHOD(XonoticDecibelsSlider, valueToText, string(entity, float))
6 ENDCLASS(XonoticDecibelsSlider)
7 entity makeXonoticDecibelsSlider(float, float, float, string);
8 #endif
9
10 #ifdef IMPLEMENTATION
11
12 entity makeXonoticDecibelsSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar)
13 {
14         entity me;
15         me = spawnXonoticDecibelsSlider();
16         me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar);
17         return me;
18 }
19 void loadCvarsXonoticDecibelsSlider(entity me)
20 {
21         float v;
22
23         if not(me.cvarName)
24                 return;
25
26         v = cvar(me.cvarName);
27         if(v >= 0.98)
28                 setValueSlider( me, 0 );
29         else if(v < 0.0005)
30                 setValueSlider( me, -1000000 );
31         else
32                 setValueSlider( me, 0.1 * floor(0.5 + 10.0 * log10(cvar(me.cvarName)) * 10) );
33 }
34 void saveCvarsXonoticDecibelsSlider(entity me)
35 {
36         if not(me.cvarName)
37                 return;
38
39         if(me.value >= -0.1)
40                 cvar_set(me.cvarName, "1");
41         if(me.value < -33)
42                 cvar_set(me.cvarName, "0");
43         else
44                 cvar_set(me.cvarName, ftos(pow(10, me.value / 10)));
45 }
46
47 string valueToTextXonoticDecibelsSlider(entity me, float v)
48 {
49         if(v < -33)
50                 return "OFF";
51         else if(v >= -0.1)
52                 return "MAX";
53         return strcat(SUPER(XonoticDecibelsSlider).valueToText(me, v), " dB");
54 }
55
56 #endif