1 ///////////////////////////////////////////////
2 // Controls/Item Source File
3 ///////////////////////
4 // This file belongs to dpmod/darkplaces
5 // AK contains all item specific stuff
6 ////////////////////////////////////////////////
12 void(void) ITEM_WINDOW =
14 self.flag = self.flag | FLAG_NOSELECT | FLAG_DRAWONLY;
33 void(void) ITEM_REFERENCE =
35 self.flag = self.flag | FLAG_NOSELECT | FLAG_DRAWONLY;
37 // if there is no link, this is a dynamic reference
40 self._child = menu_getitem(self.link);
41 if(self._child == null_entity)
43 print(self.name, " removed, cause link ", self.link, " not found\n");
44 remove(self); // no need to call terminate
66 void(void) ITEM_CUSTOM =
68 item_init(defct_reinit, defct_destroy, defct_key, defct_draw, defct_mouse_enter, defct_mouse_leave, defct_action, defct_refresh);
76 // ITEM_PICTURE has a special draw function
77 void(void) ITEM_PICTURE_DRAW =
79 menu_drawpic(self.pos, self.picture, self.size, self.color, self.alpha, self.drawflag);
84 void(void) ITEM_PICTURE_DESTROY =
86 gfx_unloadpic(self.picture);
91 void(void) ITEM_PICTURE =
93 if(self.picture == "")
94 // a picture has to have a picture
95 remove(self); // no need to call terminate
97 // load the picture if it isnt loaded already
98 gfx_loadpic(self.picture, MENU_ENFORCELOADING);
100 // if flag wasnt set yet, then set it to FLAG_DRAWONLY
102 self.flag = FLAG_DRAWONLY;
104 if(self.color == '0 0 0')
105 self.color = ITEM_PICTURE_NORMAL_COLOR;
107 self.alpha = ITEM_PICTURE_NORMAL_ALPHA;
111 ITEM_PICTURE_DESTROY,
126 void(void) ITEM_TEXT_REFRESH =
128 // first do own refresh, *then* call the default refresh !
129 if(self.size == '0 0 0')
131 if(self.font_size == '0 0 0')
132 self.font_size = ITEM_TEXT_FONT_SIZE;
134 self.size_x = self.font_size_x * strlen(self.text);
135 self.size_y = self.font_size_y;
136 } else if(self.font_size == '0 0 0')
138 self.font_size_x = self.size_x / strlen(self.text);
139 self.font_size_y = self.size_y;
146 void(void) ITEM_TEXT_DRAW =
150 // align to the rect pos - (pos + size)
152 // now check the alignement
153 if(self.alignment & TEXT_ALIGN_CENTER)
154 alignpos_x = self.pos_x + (self.size_x - strlen(self.text) * self.font_size_x) / 2;
155 else if(self.alignment & TEXT_ALIGN_RIGHT)
156 alignpos_x = self.pos_x + self.size_x - strlen(self.text) * self.font_size_x;
158 alignpos_x = self.pos_x;
159 alignpos_y = self.pos_y;
161 menu_drawstring(alignpos, self.text, self.font_size, self.color, self.alpha, self.drawflag);
166 void(void) ITEM_TEXT =
169 self.flag = FLAG_DRAWONLY;
171 if(self.color == '0 0 0')
172 self.color = ITEM_TEXT_NORMAL_COLOR;
174 self.alpha = ITEM_TEXT_NORMAL_ALPHA;
177 if(self.alignment & TEXT_ALIGN_CENTERPOS)
179 self.pos_x = self.pos_x - self.size_x / 2;
180 } else if(self.alignment & TEXT_ALIGN_LEFTPOS)
182 self.pos_x = self.pos_x - self.size_x;
202 void(void) ITEM_RECTANGLE_DRAW =
204 menu_fillarea(self.pos, self.size, self.color, self.alpha, self.drawflag);
207 void(void) ITEM_RECTANGLE =
210 self.flag = FLAG_DRAWONLY;
229 void(void) ITEM_BUTTON_DRAW =
231 if(self._button_state == BUTTON_NORMAL)
232 menu_drawpic(self.pos, self.picture, self.size, self.color, self.alpha, self.drawflag);
233 else if(self._button_state == BUTTON_SELECTED)
234 menu_drawpic(self.pos, self.picture_selected, self.size, self.color_selected, self.alpha_selected, self.drawflag_selected);
236 menu_drawpic(self.pos, self.picture_pressed, self.size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
241 void(void) ITEM_BUTTON_REFRESH =
243 if( self.hold_pressed + self._press_time < time )
245 if( menu_selected != self && self._button_state != BUTTON_NORMAL )
246 self._button_state = BUTTON_NORMAL;
247 else if( menu_selected == self && self._button_state != BUTTON_SELECTED)
249 self._button_state = BUTTON_SELECTED;
250 if(self.sound_selected != "" && menu_automatedselection == false)
251 snd_play(self.sound_selected);
259 void(float keynr, float ascii) ITEM_BUTTON_KEY =
261 if(ctcall_key(keynr, ascii))
264 if(keynr == K_ENTER || keynr == K_MOUSE1)
268 def_keyevent(keynr, ascii);
271 void(void) ITEM_BUTTON_ACTION =
273 self._press_time = time;
274 self._button_state = BUTTON_PRESSED;
275 if(self.sound_pressed)
276 snd_play(self.sound_pressed);
280 void(void) ITEM_BUTTON_REINIT =
282 self._button_state = BUTTON_NORMAL;
287 void(void) ITEM_BUTTON_DESTROY =
289 gfx_unloadpic(self.picture);
290 gfx_unloadpic(self.picture_selected);
291 gfx_unloadpic(self.picture_pressed);
296 void(void) ITEM_BUTTON =
298 if(self.picture == "" || self.picture_selected == "" || self.picture_pressed == "")
299 // a picture has to have pictures
300 remove(self); // no need to call terminate
302 // load the picture if it isnt loaded already
303 gfx_loadpic(self.picture, MENU_ENFORCELOADING);
304 gfx_loadpic(self.picture_selected, MENU_ENFORCELOADING);
305 gfx_loadpic(self.picture_pressed, MENU_ENFORCELOADING);
307 if(self.sound_selected != "")
308 snd_loadsound(self.sound_selected, SOUND_ENFORCELOADING);
310 self.sound_selected = SOUND_SELECT;
312 if(self.sound_pressed != "")
313 snd_loadsound(self.sound_pressed, SOUND_ENFORCELOADING);
315 self.sound_pressed = SOUND_ACTION;
317 // if flag wasnt set yet, then set it to FLAG_DRAWONLY
319 self.flag = FLAG_AUTOSETCLICK;
321 if(self.color == '0 0 0')
322 self.color = ITEM_PICTURE_NORMAL_COLOR;
324 self.alpha = ITEM_PICTURE_NORMAL_ALPHA;
325 if(self.color_selected == '0 0 0')
326 self.color_selected = ITEM_PICTURE_SELECTED_COLOR;
327 if(self.alpha_selected == 0)
328 self.alpha_selected = ITEM_PICTURE_SELECTED_ALPHA;
329 if(self.color_pressed == '0 0 0')
330 self.color_pressed = ITEM_PICTURE_PRESSED_COLOR;
331 if(self.alpha_pressed == 0)
332 self.alpha_pressed = ITEM_PICTURE_PRESSED_ALPHA;
334 if(self.hold_pressed == 0)
335 self.hold_pressed = ITEM_BUTTON_HOLD_PRESSED;
345 ITEM_BUTTON_REFRESH);
354 void(void) ITEM_TEXTBUTTON_REFRESH =
356 // first do own refresh, *then* call the default refresh !
357 if(self.size == '0 0 0')
359 if(self.font_size == '0 0 0')
360 self.font_size = ITEM_TEXT_FONT_SIZE;
362 self.size_x = self.font_size_x * strlen(self.text);
363 self.size_y = self.font_size_y;
364 } else if(self.font_size == '0 0 0')
366 self.font_size_x = self.size_x / strlen(self.text);
367 self.font_size_y = self.size_y;
370 /*if((self.hold_pressed + self._press_time < time && self._button_state == BUTTON_PRESSED) || (menu_selected != self && self._button_state == BUTTON_SELECTED))
372 self._button_state = BUTTON_NORMAL;
374 if(menu_selected == self && self._button_state == BUTTON_NORMAL)
376 self._button_state = BUTTON_SELECTED;
377 if(self.sound_selected != "" && menu_automatedselection == false)
378 snd_play(self.sound_selected);
380 /*if( self.hold_pressed + self._press_time < time )
382 if( menu_selected != self && self._button_state != BUTTON_NORMAL )
383 self._button_state = BUTTON_NORMAL;
384 else if( menu_selected == self && self._button_state != BUTTON_SELECTED)
386 self._button_state = BUTTON_SELECTED;
387 if(self.sound_selected != "" && menu_automatedselection == false)
388 snd_play(self.sound_selected);
391 if( self._button_state == BUTTON_PRESSED ) {
392 if( self.hold_pressed + self._press_time < time )
393 if( menu_selected == self )
394 self._button_state = BUTTON_SELECTED;
396 self._button_state = BUTTON_NORMAL;
397 } else if( self._button_state == BUTTON_NORMAL && menu_selected == self ) {
398 self._button_state = BUTTON_SELECTED;
399 if( self.sound_selected != "" && menu_automatedselection == false )
400 snd_play( self.sound_selected );
401 } else if( menu_selected != self )
402 self._button_state = BUTTON_NORMAL;
408 void(void) ITEM_TEXTBUTTON_DRAW =
413 // align to the rect pos - (pos + size)
415 // now check the alignement
416 if(self.alignment & TEXT_ALIGN_CENTER)
417 alignpos_x = self.pos_x + (self.size_x - strlen(self.text) * self.font_size_x) / 2;
418 else if(self.alignment & TEXT_ALIGN_RIGHT)
419 alignpos_x = self.pos_x + self.size_x - strlen(self.text) * self.font_size_x;
421 alignpos_x = self.pos_x;
422 alignpos_y = self.pos_y;
424 if(self.style == TEXTBUTTON_STYLE_OUTLINE && self._button_state != BUTTON_NORMAL)
430 s_x = TEXTBUTTON_OUTLINE_WIDTH;
432 if(self._button_state == BUTTON_PRESSED)
434 menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
436 else if(self._button_state == BUTTON_SELECTED)
438 menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
441 p_x = self.pos_x + self.size_x - TEXTBUTTON_OUTLINE_WIDTH;
443 s_x = TEXTBUTTON_OUTLINE_WIDTH;
445 if(self._button_state == BUTTON_PRESSED)
447 menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
449 else if(self._button_state == BUTTON_SELECTED)
451 menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
456 s_y = TEXTBUTTON_OUTLINE_WIDTH;
458 if(self._button_state == BUTTON_PRESSED)
460 menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
462 else if(self._button_state == BUTTON_SELECTED)
464 menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
468 p_y = self.pos_y + self.size_y - TEXTBUTTON_OUTLINE_WIDTH;
469 s_y = TEXTBUTTON_OUTLINE_WIDTH;
471 if(self._button_state == BUTTON_PRESSED)
473 menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
475 else if(self._button_state == BUTTON_SELECTED)
477 menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
479 } else if(self.style == TEXTBUTTON_STYLE_BOX)
481 if(self._button_state == BUTTON_PRESSED)
483 menu_fillarea(alignpos, self.size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
485 else if(self._button_state == BUTTON_SELECTED)
487 menu_fillarea(alignpos, self.size, self.color_selected, self.alpha_selected, self.drawflag_selected);
491 if(self._button_state == BUTTON_NORMAL || self.style == TEXTBUTTON_STYLE_BOX || self.style == TEXTBUTTON_STYLE_OUTLINE)
492 menu_drawstring(alignpos, self.text, self.font_size, self.color, self.alpha, self.drawflag);
494 if(self.style == TEXTBUTTON_STYLE_TEXT)
496 if(self._button_state == BUTTON_PRESSED)
498 menu_drawstring(alignpos, self.text, self.font_size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
500 else if(self._button_state == BUTTON_SELECTED)
502 menu_drawstring(alignpos, self.text, self.font_size, self.color_selected, self.alpha_selected, self.drawflag_selected);
509 void(void) ITEM_TEXTBUTTON_ACTION =
511 self._press_time = time;
512 self._button_state = BUTTON_PRESSED;
513 if(self.sound_pressed)
514 snd_play(self.sound_pressed);
519 void(float keynr, float ascii) ITEM_TEXTBUTTON_KEY =
521 if(ctcall_key(keynr, ascii))
524 if(keynr == K_ENTER || keynr == K_MOUSE1)
528 def_keyevent(keynr, ascii);
531 void(void) ITEM_TEXTBUTTON_REINIT =
533 self._button_state = BUTTON_NORMAL;
538 void(void) ITEM_TEXTBUTTON =
541 self.flag = FLAG_AUTOSETCLICK;
543 if(self.color == '0 0 0')
544 self.color = ITEM_TEXT_NORMAL_COLOR;
546 self.alpha = ITEM_TEXT_NORMAL_ALPHA;
547 if(self.color_selected == '0 0 0')
548 self.color_selected = ITEM_TEXT_SELECTED_COLOR;
549 if(self.alpha_selected == 0)
550 self.alpha_selected = ITEM_TEXT_SELECTED_ALPHA;
551 if(self.color_pressed == '0 0 0')
552 self.color_pressed = ITEM_TEXT_PRESSED_COLOR;
553 if(self.alpha_pressed == 0)
554 self.alpha_pressed = ITEM_TEXT_PRESSED_ALPHA;
556 if(self.hold_pressed == 0)
557 self.hold_pressed = ITEM_BUTTON_HOLD_PRESSED;
559 if(self.sound_selected != "")
560 snd_loadsound(self.sound_selected, SOUND_ENFORCELOADING);
562 self.sound_selected = SOUND_SELECT;
564 if(self.sound_pressed != "")
565 snd_loadsound(self.sound_pressed, SOUND_ENFORCELOADING);
567 self.sound_pressed = SOUND_ACTION;
569 ITEM_TEXTBUTTON_REFRESH();
570 if(self.alignment & TEXT_ALIGN_CENTERPOS)
572 self.pos_x = self.pos_x - self.size_x / 2;
573 } else if(self.alignment & TEXT_ALIGN_LEFTPOS)
575 self.pos_x = self.pos_x - self.size_x;
579 ITEM_TEXTBUTTON_REINIT,
582 ITEM_TEXTBUTTON_DRAW,
585 ITEM_TEXTBUTTON_ACTION,
586 ITEM_TEXTBUTTON_REFRESH);
593 void(void) ITEM_SLIDER_DRAW =
599 if(self.picture_bar != "")
601 menu_drawpic(self.pos, self.picture_bar, self.size, self.color, self.alpha, self.drawflag);
605 menu_fillarea(self.pos, self.size, self.color, self.alpha, self.drawflag);
609 slider_pos = self.pos;
610 slider_pos_x = slider_pos_x + self.left_margin + ((self.size_x - self.slider_size_x - self.left_margin - self.right_margin) / (self.max_value - self.min_value)) * (self.value - self.min_value);
611 if(self.picture != "")
613 menu_drawpic(slider_pos, self.picture, self.slider_size, self.color, self.alpha, self.drawflag);
617 menu_fillarea(slider_pos, self.slider_size, self.color + ITEM_SLIDER_BAR_COLOR_DELTA, self.alpha, self.drawflag);
621 void(void) ITEM_SLIDER_UPDATESLIDER =
623 self.value = bound(self.min_value, self.value, self.max_value);
628 void(float keynr, float ascii) ITEM_SLIDER_KEY =
633 if(ctcall_key(keynr, ascii))
636 if(keynr == K_LEFTARROW)
638 self.value = (rint(self.value / self.step) - 1) * self.step;
640 else if(keynr == K_RIGHTARROW)
642 self.value = (rint(self.value / self.step) + 1)* self.step;
644 else if(keynr == K_MOUSE1)
646 if(inrect(menu_cursor, self.pos, self.size))
648 if(menu_cursor_x - self.pos_x <= self.left_margin)
650 self.value = (rint(self.value / self.step) - 1)* self.step;
652 else if(menu_cursor_x - self.pos_x >= self.size_x - self.right_margin)
654 self.value = (rint(self.value / self.step) + 1)* self.step;
658 self.value = self.min_value + ((menu_cursor_x - self.slider_size_x / 2) - self.pos_x - self.left_margin) * ((self.max_value - self.min_value) / (self.size_x - self.slider_size_x - self.left_margin - self.right_margin));
664 def_keyevent(keynr, ascii);
670 snd_play(self.sound_increase);
672 else if(self.value < old)
674 snd_play(self.sound_decrease);
677 ITEM_SLIDER_UPDATESLIDER();
681 void(void) ITEM_SLIDER_DESTROY =
683 if(self.picture != "" && self.picture != ITEM_SLIDER_DEFAULT_SLIDER)
684 gfx_unloadpic(self.picture);
685 if(self.picture_bar != "" && self.picture_bar != ITEM_SLIDER_DEFAULT_BAR)
686 gfx_unloadpic(self.picture);
687 if(self.sound_increase != SOUND_INCREASE)
688 snd_unloadsound(self.sound_decrease);
689 if(self.sound_increase != SOUND_INCREASE)
690 snd_unloadsound(self.sound_increase);
695 void(void) ITEM_SLIDER =
697 if(self.picture != "")
698 self.picture = gfx_loadpic(self.picture, MENU_ENFORCELOADING);
699 if(self.picture == "")
700 self.picture = gfx_loadpic(ITEM_SLIDER_DEFAULT_SLIDER, MENU_ENFORCELOADING);
701 if(self.picture_bar != "")
702 self.picture_bar = gfx_loadpic(self.picture_bar, MENU_ENFORCELOADING);
703 if(self.picture_bar == "")
704 self.picture_bar = gfx_loadpic(ITEM_SLIDER_DEFAULT_BAR, MENU_ENFORCELOADING);
705 if(self.sound_decrease == "")
706 self.sound_decrease = SOUND_DECREASE;
708 snd_loadsound(self.sound_decrease, MENU_ENFORCELOADING);
709 if(self.sound_increase == "")
710 self.sound_increase = SOUND_INCREASE;
712 snd_loadsound(self.sound_increase, MENU_ENFORCELOADING);
714 if(self.color == '0 0 0')
715 self.color = ITEM_SLIDER_COLOR;
717 self.alpha = ITEM_SLIDER_ALPHA;
719 self.step = ITEM_SLIDER_STEP;
720 if(self.slider_size == '0 0 0')
722 /*if(self.picture != "")
723 self.slider_size = gfx_getimagesize(self.picture);
725 self.slider_size = ITEM_SLIDER_SIZE;
727 if(self.left_margin == 0)
728 self.left_margin = ITEM_SLIDER_LEFT_MARGIN;
729 if(self.right_margin == 0)
730 self.right_margin = ITEM_SLIDER_RIGHT_MARGIN;
747 void(void) ITEM_TEXTSWITCH_DRAW =
751 // get the current text
753 self.text = getaltstring(self.value, self.text);
759 void(void) ITEM_TEXTSWITCH_REFRESH =
764 self.text = getaltstring(self.value, self.text);
771 void(float keynr, float ascii) ITEM_TEXTSWITCH_KEY =
774 if(ctcall_key(keynr, ascii))
777 if(keynr == K_LEFTARROW || keynr == K_MOUSE2)
780 self.value = self.value - 1;
782 self.value = getaltstringcount(self.text) - 1;
784 else if(keynr == K_RIGHTARROW || keynr == K_MOUSE1 || keynr == K_ENTER)
787 self.value = self.value + 1;
788 if(self.value > getaltstringcount(self.text) - 1)
792 def_keyevent(keynr, ascii);
797 snd_play(self.sound_increase);
799 snd_play(self.sound_decrease);
801 if(self.switchchange)
805 void(void) ITEM_TEXTSWITCH_DESTROY =
807 if(self.sound_increase != SOUND_INCREASE)
808 snd_unloadsound(self.sound_decrease);
809 if(self.sound_increase != SOUND_INCREASE)
810 snd_unloadsound(self.sound_increase);
813 void(void) ITEM_TEXTSWITCH =
817 if(self.sound_decrease == "")
818 self.sound_decrease = SOUND_DECREASE;
820 snd_loadsound(self.sound_decrease, MENU_ENFORCELOADING);
821 if(self.sound_increase == "")
822 self.sound_increase = SOUND_INCREASE;
824 snd_loadsound(self.sound_increase, MENU_ENFORCELOADING);
827 self.text = getaltstring(self.value, self.text);
833 ITEM_TEXTSWITCH_DESTROY,
835 ITEM_TEXTSWITCH_DRAW,
839 ITEM_TEXTSWITCH_REFRESH);
846 void(void) ITEM_EDITBOX_REINIT =
849 self._button_state = BUTTON_NORMAL;
852 void(void) ITEM_EDITBOX_DRAW =
859 if(self._button_state == BUTTON_NORMAL || mod(time * 1000, 1000 / EDITBOX_CURSOR_FREQ) > 500 / EDITBOX_CURSOR_FREQ)
863 csize_y = self.font_size_y;
866 cpos_x = cpos_x + self._cursorpos * self.font_size_x;
868 menu_fillarea(cpos, csize, self.color_selected, self.alpha_selected, self.drawflag_selected);
871 void(float ascii) ITEM_EDITBOX_INSERT =
873 string firsthalf, secondhalf;
876 if(self._cursorpos > strlen(self.text))
879 if(self.format == "")
881 // no format stuff, so lets have fun
882 firsthalf = substring(self.text, 0, self._cursorpos);
883 secondhalf = substring(self.text, self._cursorpos, strlen(self.text) - self._cursorpos);
884 strunzone(self.text);
885 self.text = strcat(firsthalf, chr(ascii));
886 self.text = strcat(self.text, secondhalf);
887 if(self.maxlen >= 0 && strlen(self.text) > self.maxlen)
889 // remove the last char(s)
890 self.text = substring(self.text, 0, self.maxlen);
892 // move the cursor forward
893 if(strlen(self.text) >= self._cursorpos)
894 self._cursorpos = self._cursorpos + 1;
896 self.text = strzone(self.text);
898 else // here begins the funny part
900 // TODO: add wildcard support :-/
901 // move the cursor to the next space
902 len = strlen(self.format);
903 while(substring(self.format, self._cursorpos, 1) != " " && len > self._cursorpos)
905 self._cursorpos = self._cursorpos + 1;
907 if(self._cursorpos >= len)
910 firsthalf = substring(self.text, 0, self._cursorpos);
911 secondhalf = substring(self.text, self._cursorpos + 1 , strlen(self.text) - self._cursorpos - 1);
912 strunzone(self.text);
913 self.text = strcat(firsthalf, chr(ascii), secondhalf);
914 self.text = strzone(self.text);
918 void(void) ITEM_EDITBOX_LEFT =
920 if(self._cursorpos > 0)
921 self._cursorpos = self._cursorpos - 1;
924 void(void) ITEM_EDITBOX_RIGHT =
926 if(self._cursorpos < strlen(self.text))
927 self._cursorpos = self._cursorpos + 1;
930 void(float keynr, float ascii) ITEM_EDITBOX_KEY =
932 if(ctcall_key(keynr, ascii))
935 if(ascii >= 30 && ascii <= 126)
937 ITEM_EDITBOX_INSERT(ascii);
938 } else if(keynr == K_BACKSPACE)
940 if(self.format == "")
942 string firsthalf, secondhalf;
944 firsthalf = substring(self.text,0, self._cursorpos - 1);
945 secondhalf = substring(self.text,self._cursorpos, strlen(self.text) - self._cursorpos);
946 strunzone(self.text);
947 self.text = strcat(firsthalf, secondhalf);
948 self.text = strzone(self.text);
952 } else if(keynr == K_ENTER)
955 //snd_play(self.sound_action);
956 } else if(keynr == K_LEFTARROW)
960 else if(keynr == K_RIGHTARROW)
962 ITEM_EDITBOX_RIGHT();
965 def_keyevent(keynr, ascii);
967 snd_play(self.sound_pressed);
970 void(void) ITEM_EDITBOX_REFRESH =
972 if(menu_selected != self && menu_selected != self._parent)
973 self._button_state = BUTTON_NORMAL;
974 else if(self._button_state == BUTTON_NORMAL)
976 self._button_state = BUTTON_SELECTED;
978 if(self.sound_selected != "" && menu_automatedselection == false)
979 snd_play(self.sound_selected);
982 if(self._cursorpos > strlen(self.text))
983 self._cursorpos = strlen(self.text);
985 // hack: we want the text to scroll if possible
986 // self.clip_pos holds the normal value
987 if(self._cursorpos >= self.size_x / self.font_size_x - 1.5 )
988 self.pos_x = self.clip_pos_x -(self._cursorpos - floor( self.size_x / self.font_size_x - 1.5)) * self.font_size_x;
990 self.pos_x = self.clip_pos_x;
995 void(void) ITEM_EDITBOX =
997 if(self.sound_selected != "")
998 snd_loadsound(self.sound_selected, SOUND_ENFORCELOADING);
1000 self.sound_selected = SOUND_SELECT;
1002 if(self.sound_pressed != "")
1003 snd_loadsound(self.sound_pressed, SOUND_ENFORCELOADING);
1005 self.sound_pressed = SOUND_ACTION;
1007 // if flag wasnt set yet, then set it to FLAG_DRAWONLY
1009 self.flag = FLAG_AUTOSETCLICK;
1011 if(self.color == '0 0 0')
1012 self.color = ITEM_PICTURE_NORMAL_COLOR;
1014 self.alpha = ITEM_PICTURE_NORMAL_ALPHA;
1015 if(self.color_selected == '0 0 0')
1016 self.color_selected = ITEM_PICTURE_SELECTED_COLOR;
1017 if(self.alpha_selected == 0)
1018 self.alpha_selected = ITEM_PICTURE_SELECTED_ALPHA;
1020 self.text = strzone(self.text);
1022 ITEM_TEXT_REFRESH();
1023 if(self.alignment & TEXT_ALIGN_CENTERPOS)
1025 self.pos_x = self.pos_x - self.size_x / 2;
1026 } else if(self.alignment & TEXT_ALIGN_LEFTPOS)
1028 self.pos_x = self.pos_x - self.size_x;
1032 self.clip_pos = self.pos;
1042 ITEM_EDITBOX_REFRESH);
1048 /////////////////////////////////////////////////////////////////////////
1049 // The "actual" funtions
1051 void(void) ctinit_picture =
1056 // draws a text (uses the std. way)
1057 void(string text, vector pos, vector size, float alignment, float style, float state) ctdrawtext =
1064 // align to the rect pos - (pos + size)
1066 // now check the alignement
1067 if(alignment & TEXT_ALIGN_CENTER)
1068 alignpos_x = pos_x + (size_x - strlen(text) * self.font_size_x) / 2;
1069 else if(alignment & TEXT_ALIGN_RIGHT)
1070 alignpos_x = pos_x + size_x - strlen(text) * self.font_size_x;
1075 if(style == TEXTBUTTON_STYLE_OUTLINE && state != BUTTON_NORMAL)
1081 s_x = TEXTBUTTON_OUTLINE_WIDTH;
1083 if(state == BUTTON_PRESSED)
1085 menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
1087 else if(state == BUTTON_SELECTED)
1089 menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
1092 p_x = pos_x + size_x - TEXTBUTTON_OUTLINE_WIDTH;
1094 s_x = TEXTBUTTON_OUTLINE_WIDTH;
1096 if(state == BUTTON_PRESSED)
1098 menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
1100 else if(state == BUTTON_SELECTED)
1102 menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
1107 s_y = TEXTBUTTON_OUTLINE_WIDTH;
1109 if(state == BUTTON_PRESSED)
1111 menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
1113 else if(self._button_state == BUTTON_SELECTED)
1115 menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
1119 p_y = pos_y + size_y - TEXTBUTTON_OUTLINE_WIDTH;
1120 s_y = TEXTBUTTON_OUTLINE_WIDTH;
1122 if(state == BUTTON_PRESSED)
1124 menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
1126 else if(state == BUTTON_SELECTED)
1128 menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
1130 } else if(style == TEXTBUTTON_STYLE_BOX)
1132 if(state == BUTTON_PRESSED)
1134 menu_fillarea(alignpos, size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
1136 else if(self._button_state == BUTTON_SELECTED)
1138 menu_fillarea(alignpos, size, self.color_selected, self.alpha_selected, self.drawflag_selected);
1142 if(state == BUTTON_NORMAL || style == TEXTBUTTON_STYLE_BOX || style == TEXTBUTTON_STYLE_OUTLINE)
1143 menu_drawstring(alignpos, text, self.font_size, self.color, self.alpha, self.drawflag);
1145 if(style == TEXTBUTTON_STYLE_TEXT)
1147 if(state == BUTTON_PRESSED)
1149 menu_drawstring(alignpos, text, self.font_size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
1151 else if(state == BUTTON_SELECTED)
1153 menu_drawstring(alignpos, text, self.font_size, self.color_selected, self.alpha_selected, self.drawflag_selected);