1 ///////////////////////////////////////////////
2 // Functions Source File
3 ///////////////////////
4 // This file belongs to dpmod/darkplaces
5 // AK contains all menu controlling stuff (sub-menus)
6 ///////////////////////////////////////////////
11 void(entity ent) raise_x =
24 void(entity ent) raise_reinit =
36 void(entity ent) raise_destroy =
48 void(entity ent, float keynr, float ascii) raise_key =
56 self._key(keynr, ascii);
60 void(entity ent) raise_draw =
72 void(entity ent) raise_mouse_enter =
84 void(entity ent) raise_mouse_leave =
96 void(entity ent) raise_action =
108 void(entity ent) raise_refresh =
120 // safe call control function functions
121 // default control functions
124 void(void) ctcall_x =
131 void(void) ctcall_init =
137 void(void) ctcall_reinit =
143 void(void) ctcall_destroy =
149 float(float keynr, float ascii) ctcall_key =
152 return self.key(keynr, ascii);
157 void(void) ctcall_draw =
163 void(void) ctcall_mouse_enter =
169 void(void) ctcall_mouse_leave =
175 void(void) ctcall_action =
181 void(void) ctcall_refresh =
187 // default control functions
188 /* template (expect defct_key)
196 // defct_init not needed cause its the same like the type function
198 void(void) defct_reinit =
203 void(void) defct_destroy =
208 void(float keynr, float ascii) defct_key =
210 if(!ctcall_key(keynr, ascii))
211 def_keyevent(keynr, ascii);
214 void(void) defct_draw =
219 void(void) defct_mouse_enter =
221 ctcall_mouse_enter();
224 void(void) defct_mouse_leave =
226 ctcall_mouse_leave();
229 void(void) defct_action =
234 void(void) defct_refresh =
236 // do first the own fresh stuff and *then* call refresh
241 // default refresh function
242 void(void) def_refresh =
245 if(self.flag & FLAG_AUTOSETCLICK)
247 self.click_pos = self.pos;
248 self.click_size = self.size;
250 if(self.flag & FLAG_AUTOSETCLIP)
252 self.clip_pos = self.pos;
253 self.clip_size = self.size;
257 // default key function
258 void(float keynr, float ascii) def_keyevent =
260 if(keynr == K_ESCAPE)
262 // move up to the parent
264 } else if(keynr == K_LEFTARROW || keynr == K_UPARROW)
266 // move to the previous element
269 if(menu_selected == self)
273 menu_selected = self._prev;
275 if(menu_selected != self._prev)
280 menu_selected = self;
282 } else if(keynr == K_RIGHTARROW || keynr == K_DOWNARROW)
284 // move to the next element
287 if(menu_selected == self)
291 menu_selected = self._next;
293 if(menu_selected != self._next)
298 menu_selected = self;
300 } else if(keynr == K_ENTER || keynr == K_MOUSE1)
304 // move to the child menu
309 // a rect is described by the top-left point and its size
310 float(vector point, vector r_pos, vector r_size) inrect =
312 if(point_x < r_pos_x)
314 if(point_y < r_pos_y)
316 if(point_x > (r_pos_x + r_size_x))
318 if(point_y > (r_pos_y + r_size_y))
323 vector(vector r_pos, vector r_size, vector c_pos, vector c_size) cliprectpos =
328 v_x = max(c_pos_x, r_pos_x);
329 v_y = max(c_pos_y, r_pos_y);
334 vector(vector r_pos, vector r_size, vector c_pos, vector c_size) cliprectsize =
338 //r_size_x = bound(c_pos_x, r_pos_x + r_size_x, c_pos_x + c_size_x) - bound(c_pos_x, r_pos_x, c_pos_x + c_size_x);
339 //r_size_y = bound(c_pos_y, r_pos_y + r_size_y, c_pos_y + c_size_y) - bound(c_pos_y, r_pos_y, c_pos_y + c_size_y);
340 v_x = min(c_pos_x + c_size_x, r_pos_x + r_size_x) - max(c_pos_x, r_pos_x);
341 v_y = min(c_pos_y + c_size_y, r_pos_y + r_size_y) - max(c_pos_y, r_pos_y);
343 if(v_x <= 0 || v_y <= 0)
349 void(void(void) reinitevent, void(void) destroyevent, void(float key, float ascii) keyevent, void(void) drawevent, void(void) mouse_enterevent, void(void) mouse_leaveevent, void(void) actionevent, void(void) refreshevent)
352 self._reinit = reinitevent;
353 self._destroy = destroyevent;
355 self._key = keyevent;
356 self._draw = drawevent;
357 self._mouse_enter = mouse_enterevent;
358 self._mouse_leave = mouse_leaveevent;
359 self._action = actionevent;
360 self._refresh = refreshevent;
363 float(float tfactor) getflicker =
365 // TODO: use tfactor to vary the result
366 return (sin(tfactor * time) + 1)/2;
369 float(string s) getaltstringcount =
377 for(pos = 0; pos < len; pos = pos + 1)
379 if(substring(s,pos,1) == "'")
383 if(mod(count,2) == 1)
384 return 0; // bad string
389 string(float n, string s) getaltstring =
396 if(n >= getaltstringcount(s) || n < 0)
399 // go to the beginning of the altstring
401 for(start = 0;tmp <= n * 2 ; start = start + 1)
403 if(substring(s, start, 1) == "'")
407 for(length = 0; substring(s, start + length, 1) != "'"; length = length + 1)
411 return substring(s, start, length);
414 void(string key) bind_unbindkey =
416 cmd(strcat("unbind ",key,"\n"));
419 void(string key, string command) bind_bindkey =
421 cmd(strcat("bind ",key," ",command,"\n"));
424 string(float keynum) bind_getstringforkey =
426 return keynumtostring(keynum);
429 string(string command) bind_getkeylist =
431 return findkeysforcommand(command);
434 void(float num, string command) bind_limitbinds =
440 keystr = strzone(bind_getkeylist(command));
442 maxnum = getaltstringcount(keystr);
446 //dprint("num = ", ftos(num),"\n");
447 //dprint("maxnum = ", ftos(maxnum), "\n");
450 while(counter < maxnum)
454 keynum = stof(getaltstring(counter, keystr));
456 //dprint(ftos(keynum),"\n");
462 bind_unbindkey(bind_getstringforkey(keynum));
464 counter = counter + 1;