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);
12 float toDecibelOfSquare(float f, float mi)
14 float A = log(10) / 20; // note: about 0.115; inverse: about 8.686
19 float y = exp(1 + A * mi);
21 return mi + (t - mi) * (f / y);
26 float fromDecibelOfSquare(float f, float mi)
28 float A = log(10) / 20; // note: about 0.115; inverse: about 8.686
33 float y = exp(1 + A * mi);
35 return y * ((f - mi) / (t - mi));
40 entity makeXonoticDecibelsSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar)
43 me = spawnXonoticDecibelsSlider();
44 me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar);
47 void XonoticDecibelsSlider_loadCvars(entity me)
54 v = cvar(me.cvarName);
57 if(v > fromDecibelOfSquare(me.valueMax - 0.5 * me.valueStep, me.valueMin))
58 Slider_setValue(me, me.valueMax);
60 Slider_setValue(me, me.valueStep * floor(0.5 + toDecibelOfSquare(v, me.valueMin) / me.valueStep) );
62 void XonoticDecibelsSlider_saveCvars(entity me)
67 if(me.value > me.valueMax - 0.5 * me.valueStep)
68 cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.valueMax, me.valueMin)));
70 cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.value, me.valueMin)));
73 float autocvar_menu_snd_sliderscale;
74 string XonoticDecibelsSlider_valueToText(entity me, float v)
76 if(v > me.valueMax - 0.5 * me.valueStep)
77 return CTX(_("VOL^MAX"));
78 else if(v <= me.valueMin)
79 return CTX(_("VOL^OFF"));
80 else if(autocvar_menu_snd_sliderscale == 2) // 0..10 scale
81 return sprintf(_("%.1f"), (v - me.valueMin) / (me.valueMax - me.valueMin) * 10);
82 else if(autocvar_menu_snd_sliderscale == 1) // percent scale
83 return sprintf(_("%.2f %%"), fromDecibelOfSquare(v, me.valueMin));
85 return sprintf(_("%s dB"), ftos_decimals(toDecibelOfSquare(fromDecibelOfSquare(v, me.valueMin), 0), me.valueDigits));