]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider_decibels.c
Merge branch 'master' of git://git.xonotic.org/xonotic/xonotic-data.pk3dir
[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 XonoticDecibelsSlider_loadCvars(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                 Slider_setValue( me, 0 );
29         else if(v < 0.0005)
30                 Slider_setValue( me, -1000000 );
31         else
32                 Slider_setValue( me, 0.1 * floor(0.5 + 10.0 * log10(cvar(me.cvarName)) * 10) );
33 }
34 void XonoticDecibelsSlider_saveCvars(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 XonoticDecibelsSlider_valueToText(entity me, float v)
48 {
49         if(v < -33)
50                 return CTX(_("VOL^OFF"));
51         else if(v >= -0.1)
52                 return CTX(_("VOL^MAX"));
53         return sprintf(_("%s dB"), SUPER(XonoticDecibelsSlider).valueToText(me, v));
54 }
55
56 #endif