]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/cvarlist.c
menu rearrangements by Samual
[divverent/nexuiz.git] / data / qcsrc / menu / nexuiz / cvarlist.c
1 #ifdef INTERFACE
2 CLASS(NexuizCvarList) EXTENDS(NexuizListBox)
3         METHOD(NexuizCvarList, configureNexuizCvarList, void(entity))
4         ATTRIB(NexuizCvarList, rowsPerItem, float, 1)
5         METHOD(NexuizCvarList, drawListBoxItem, void(entity, float, vector, float))
6         METHOD(NexuizCvarList, resizeNotify, void(entity, vector, vector, vector, vector))
7         METHOD(NexuizCvarList, keyDown, float(entity, float, float, float))
8
9         ATTRIB(NexuizCvarList, realFontSize, vector, '0 0 0')
10         ATTRIB(NexuizCvarList, realUpperMargin, float, 0)
11         ATTRIB(NexuizCvarList, columnNameOrigin, float, 0)
12         ATTRIB(NexuizCvarList, columnNameSize, float, 0)
13         ATTRIB(NexuizCvarList, columnValueOrigin, float, 0)
14         ATTRIB(NexuizCvarList, columnValueSize, float, 0)
15
16         METHOD(NexuizCvarList, setSelected, void(entity, float))
17         ATTRIB(NexuizCvarList, controlledTextbox, entity, NULL)
18         ATTRIB(NexuizCvarList, cvarNameBox, entity, NULL)
19         ATTRIB(NexuizCvarList, cvarDescriptionBox, entity, NULL)
20         ATTRIB(NexuizCvarList, cvarTypeBox, entity, NULL)
21         ATTRIB(NexuizCvarList, cvarValueBox, entity, NULL)
22         ATTRIB(NexuizCvarList, cvarDefaultBox, entity, NULL)
23
24         ATTRIB(NexuizCvarList, handle, float, -1)
25         ATTRIB(NexuizCvarList, cvarName, string, string_null)
26         ATTRIB(NexuizCvarList, cvarDescription, string, string_null)
27         ATTRIB(NexuizCvarList, cvarType, string, string_null)
28         ATTRIB(NexuizCvarList, cvarDefault, string, string_null)
29 ENDCLASS(NexuizCvarList)
30 entity makeNexuizCvarList();
31 void CvarList_Filter_Change(entity box, entity me);
32 void CvarList_Value_Change(entity box, entity me);
33 void CvarList_Revert_Click(entity btn, entity me);
34 #endif
35
36 #ifdef IMPLEMENTATION
37 entity makeNexuizCvarList()
38 {
39         entity me;
40         me = spawnNexuizCvarList();
41         me.configureNexuizCvarList(me);
42         return me;
43 }
44 void configureNexuizCvarListNexuizCvarList(entity me)
45 {
46         me.configureNexuizListBox(me);
47
48         me.handle = buf_create();
49         buf_cvarlist(me.handle, "", "_");
50         me.nItems = buf_getsize(me.handle);
51 }
52 void setSelectedNexuizCvarList(entity me, float i)
53 {
54         string s;
55
56         setSelectedListBox(me, i);
57         if(me.nItems == 0)
58                 return;
59         
60         if(me.cvarName)
61                 strunzone(me.cvarName);
62         if(me.cvarDescription)
63                 strunzone(me.cvarDescription);
64         if(me.cvarType)
65                 strunzone(me.cvarType);
66         if(me.cvarDefault)
67                 strunzone(me.cvarDefault);
68         me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem));
69         me.cvarDescription = strzone(cvar_description(me.cvarName));
70         me.cvarDefault = strzone(cvar_defstring(me.cvarName));
71
72         float t;
73         t = cvar_type(me.cvarName);
74         me.cvarType = "";
75         if(t & CVAR_TYPEFLAG_SAVED)
76                 me.cvarType = strcat(me.cvarType, ", will be saved to config.cfg");
77         else
78                 me.cvarType = strcat(me.cvarType, ", will not be saved");
79         if(t & CVAR_TYPEFLAG_PRIVATE)
80                 me.cvarType = strcat(me.cvarType, ", private");
81         if(t & CVAR_TYPEFLAG_ENGINE)
82                 me.cvarType = strcat(me.cvarType, ", engine setting");
83         if(t & CVAR_TYPEFLAG_READONLY)
84                 me.cvarType = strcat(me.cvarType, ", read only");
85         me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
86
87         me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
88         me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
89         me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
90         me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
91
92         // this one can handle tempstrings
93         s = cvar_string(me.cvarName);
94         me.cvarValueBox.setText(me.cvarValueBox, s);
95         me.cvarValueBox.cursorPos = strlen(s);
96 }
97 void CvarList_Filter_Change(entity box, entity me)
98 {
99         buf_cvarlist(me.handle, box.text, "_");
100         me.nItems = buf_getsize(me.handle);
101
102         me.setSelected(me, 0);
103 }
104 void resizeNotifyNexuizCvarList(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
105 {
106         resizeNotifyNexuizListBox(me, relOrigin, relSize, absOrigin, absSize);
107
108         me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
109         me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
110         me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
111
112         me.columnNameOrigin = 0;
113         me.columnValueSize = me.realFontSize_x * 20;
114         me.columnNameSize = 1 - me.columnValueSize - me.realFontSize_x;
115         me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize_x;
116
117         me.setSelected(me, me.selectedItem);
118 }
119 void drawListBoxItemNexuizCvarList(entity me, float i, vector absSize, float isSelected)
120 {
121         string k, v, d;
122         float t;
123
124         vector theColor;
125         float theAlpha;
126
127         string s;
128
129         if(isSelected)
130                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
131         
132         k = bufstr_get(me.handle, i);
133
134         v = cvar_string(k);
135         d = cvar_defstring(k);
136         t = cvar_type(k);
137         if(t & CVAR_TYPEFLAG_SAVED)
138                 theAlpha = SKINALPHA_CVARLIST_SAVED;
139         else
140                 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
141         if(v == d)
142                 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
143         else
144                 theColor = SKINCOLOR_CVARLIST_CHANGED;
145
146         s = draw_TextShortenToWidth(k, me.columnNameSize / me.realFontSize_x, 0);
147         draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
148         s = draw_TextShortenToWidth(v, me.columnValueSize / me.realFontSize_x, 0);
149         draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
150 }
151
152 float keyDownNexuizCvarList(entity me, float scan, float ascii, float shift)
153 {
154         if(keyDownListBox(me, scan, ascii, shift))
155                 return 1;
156         else if(!me.controlledTextbox)
157                 return 0;
158         else
159                 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
160 }
161
162 void CvarList_Value_Change(entity box, entity me)
163 {
164         cvar_set(me.cvarNameBox.text, box.text);
165 }
166
167 void CvarList_Revert_Click(entity btn, entity me)
168 {
169         me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
170         me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
171 }
172 #endif