]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/slider_decibels.c
rebrand nexuiz -> xonotic, will fix possible mess later
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider_decibels.c
diff --git a/qcsrc/menu/xonotic/slider_decibels.c b/qcsrc/menu/xonotic/slider_decibels.c
new file mode 100644 (file)
index 0000000..20beec9
--- /dev/null
@@ -0,0 +1,56 @@
+#ifdef INTERFACE
+CLASS(XonoticDecibelsSlider) EXTENDS(XonoticSlider)
+       METHOD(XonoticDecibelsSlider, loadCvars, void(entity))
+       METHOD(XonoticDecibelsSlider, saveCvars, void(entity))
+       METHOD(XonoticDecibelsSlider, valueToText, string(entity, float))
+ENDCLASS(XonoticDecibelsSlider)
+entity makeXonoticDecibelsSlider(float, float, float, string);
+#endif
+
+#ifdef IMPLEMENTATION
+
+entity makeXonoticDecibelsSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar)
+{
+       entity me;
+       me = spawnXonoticDecibelsSlider();
+       me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar);
+       return me;
+}
+void loadCvarsXonoticDecibelsSlider(entity me)
+{
+       float v;
+
+       if not(me.cvarName)
+               return;
+
+       v = cvar(me.cvarName);
+       if(v >= 0.98)
+               me.value = 0;
+       else if(v < 0.0005)
+               me.value = -1000000;
+       else
+               me.value = 0.1 * floor(0.5 + 10.0 * log10(cvar(me.cvarName)) * 10);
+}
+void saveCvarsXonoticDecibelsSlider(entity me)
+{
+       if not(me.cvarName)
+               return;
+
+       if(me.value >= -0.1)
+               cvar_set(me.cvarName, "1");
+       if(me.value < -33)
+               cvar_set(me.cvarName, "0");
+       else
+               cvar_set(me.cvarName, ftos(pow(10, me.value / 10)));
+}
+
+string valueToTextXonoticDecibelsSlider(entity me, float v)
+{
+       if(v < -33)
+               return "OFF";
+       else if(v >= -0.1)
+               return "MAX";
+       return strcat(valueToTextSlider(me, v), " dB");
+}
+
+#endif