]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/textslider.c
Merge branch 'master' into divVerent/desktopfullscreen
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / textslider.c
1 // Note:
2 //   to use this, you FIRST call configureSliderVisuals, then multiple times addValue, then configureTextSlider
3 #ifdef INTERFACE
4 CLASS(TextSlider) EXTENDS(Slider)
5         METHOD(TextSlider, valueToText, string(entity, float))
6         METHOD(TextSlider, valueToIdentifier, string(entity, float))
7         METHOD(TextSlider, setValueFromIdentifier, void(entity, string))
8         METHOD(TextSlider, getIdentifier, string(entity))
9         METHOD(TextSlider, clearValues, void(entity))
10         METHOD(TextSlider, addValue, void(entity, string, string))
11         METHOD(TextSlider, configureTextSliderValues, void(entity, string))
12         ATTRIBARRAY(TextSlider, valueStrings, string, 256)
13         ATTRIBARRAY(TextSlider, valueIdentifiers, string, 256)
14         ATTRIB(TextSlider, nValues, float, 0)
15 ENDCLASS(TextSlider)
16 #endif
17
18 #ifdef IMPLEMENTATION
19 string TextSlider_valueToIdentifier(entity me, float val)
20 {
21         if(val >= me.nValues)
22                 return "custom";
23         if(val < 0)
24                 return "custom";
25         return me.(valueIdentifiers[val]);
26 }
27 string TextSlider_valueToText(entity me, float val)
28 {
29         if(val >= me.nValues)
30                 return _("custom");
31         if(val < 0)
32                 return _("custom");
33         return me.(valueStrings[val]);
34 }
35 void TextSlider_setValueFromIdentifier(entity me, string id)
36 {
37         float i;
38         for(i = 0; i < me.nValues; ++i)
39                 if(me.valueToIdentifier(me, i) == id)
40                 {
41                         SUPER(TextSlider).setValue( me, i );
42                         return;
43                 }
44         SUPER(TextSlider).setValue( me, -1 );
45 }
46 string TextSlider_getIdentifier(entity me)
47 {
48         return me.valueToIdentifier(me, me.value);
49 }
50 void TextSlider_clearValues(entity me)
51 {
52         me.nValues = 0;
53 }
54 void TextSlider_addValue(entity me, string theString, string theIdentifier)
55 {
56         me.(valueStrings[me.nValues]) = theString;
57         me.(valueIdentifiers[me.nValues]) = theIdentifier;
58         me.nValues += 1;
59 }
60 void TextSlider_configureTextSliderValues(entity me, string theDefault)
61 {
62         me.configureSliderValues(me, 0, 0, me.nValues - 1, 1, 1, 1);
63         me.setValueFromIdentifier(me, theDefault);
64 }
65 #endif