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);
155 void(void) ctcall_draw =
161 void(void) ctcall_mouse_enter =
167 void(void) ctcall_mouse_leave =
173 void(void) ctcall_action =
179 void(void) ctcall_refresh =
185 // default control functions
186 /* template (expect defct_key)
194 // defct_init not needed cause its the same like the type function
196 void(void) defct_reinit =
201 void(void) defct_destroy =
206 void(float keynr, float ascii) defct_key =
208 if(!ctcall_key(keynr, ascii))
209 def_keyevent(keynr, ascii);
212 void(void) defct_draw =
217 void(void) defct_mouse_enter =
219 ctcall_mouse_enter();
222 void(void) defct_mouse_leave =
224 ctcall_mouse_leave();
227 void(void) defct_action =
232 void(void) defct_refresh =
234 // do first the own fresh stuff and *then* call refresh
239 // default refresh function
240 void(void) def_refresh =
243 if(self.flag & FLAG_AUTOSETCLICK)
245 self.click_pos = self.pos;
246 self.click_size = self.size;
248 if(self.flag & FLAG_AUTOSETCLIP)
250 self.clip_pos = self.pos;
251 self.clip_size = self.size;
255 // default key function
256 void(float keynr, float ascii) def_keyevent =
258 if(keynr == K_ESCAPE)
260 // move up to the parent
262 } else if(keynr == K_LEFTARROW || keynr == K_UPARROW)
264 // move to the previous element
267 if(menu_selected == self)
271 menu_selected = self._prev;
273 if(menu_selected != self._prev)
278 menu_selected = self;
280 } else if(keynr == K_RIGHTARROW || keynr == K_DOWNARROW)
282 // move to the next element
285 if(menu_selected == self)
289 menu_selected = self._next;
291 if(menu_selected != self._next)
296 menu_selected = self;
298 } else if(keynr == K_ENTER || keynr == K_MOUSE1)
302 // move to the child menu
307 // a rect is described by the top-left point and its size
308 float(vector point, vector r_pos, vector r_size) inrect =
310 if(point_x < r_pos_x)
312 if(point_y < r_pos_y)
314 if(point_x > (r_pos_x + r_size_x))
316 if(point_y > (r_pos_y + r_size_y))
321 vector(vector r_pos, vector r_size, vector c_pos, vector c_size) cliprectpos =
326 v_x = max(c_pos_x, r_pos_x);
327 v_y = max(c_pos_y, r_pos_y);
332 vector(vector r_pos, vector r_size, vector c_pos, vector c_size) cliprectsize =
336 //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);
337 //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);
338 v_x = min(c_pos_x + c_size_x, r_pos_x + r_size_x) - max(c_pos_x, r_pos_x);
339 v_y = min(c_pos_y + c_size_y, r_pos_y + r_size_y) - max(c_pos_y, r_pos_y);
341 if(v_x <= 0 || v_y <= 0)
347 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)
350 self._reinit = reinitevent;
351 self._destroy = destroyevent;
353 self._key = keyevent;
354 self._draw = drawevent;
355 self._mouse_enter = mouse_enterevent;
356 self._mouse_leave = mouse_leaveevent;
357 self._action = actionevent;
358 self._refresh = refreshevent;
361 float(float tfactor) getflicker =
363 // TODO: use tfactor to vary the result
364 return (sin(tfactor * time) + 1)/2;
367 float(string s) getaltstringcount =
375 for(pos = 0; pos < len; pos = pos + 1)
377 if(substring(s,pos,1) == "'")
381 if(mod(count,2) == 1)
382 return 0; // bad string
387 string(float n, string s) getaltstring =
394 if(n >= getaltstringcount(s) || n < 0)
397 // go to the beginning of the altstring
399 for(start = 0;tmp <= n * 2 ; start = start + 1)
401 if(substring(s, start, 1) == "'")
405 for(length = 0; substring(s, start + length, 1) != "'"; length = length + 1)
409 return substring(s, start, length);
412 void(string key) bind_unbindkey =
414 cmd(strcat("unbind ",key,"\n"));
417 void(string key, string command) bind_bindkey =
419 cmd(strcat("bind ",key," ",command,"\n"));
422 string(float keynum) bind_getstringforkey =
424 return keynumtostring(keynum);
427 string(string command) bind_getkeylist =
429 return findkeysforcommand(command);
432 void(float num, string command) bind_limitbinds =
438 keystr = strzone(bind_getkeylist(command));
440 maxnum = getaltstringcount(keystr);
444 //dprint("num = ", ftos(num),"\n");
445 //dprint("maxnum = ", ftos(maxnum), "\n");
448 while(counter < maxnum)
452 keynum = stof(getaltstring(counter, keystr));
454 //dprint(ftos(keynum),"\n");
460 bind_unbindkey(bind_getstringforkey(keynum));
462 counter = counter + 1;