]> icculus.org git repositories - divverent/nexuiz.git/blob - menusrc/mcontrols.qc
The color control menu should be finished now - the pattern should perhaps be adjuste...
[divverent/nexuiz.git] / menusrc / mcontrols.qc
1 ///////////////////////////////////////////////
2 // Controls/Item Source File
3 ///////////////////////
4 // This file belongs to dpmod/darkplaces
5 // AK contains all item specific stuff
6 ////////////////////////////////////////////////
7
8 ////////////////
9 // ITEM_WINDOW
10 //
11
12 void(void) ITEM_WINDOW =
13 {
14         self.flag = self.flag | FLAG_NOSELECT | FLAG_DRAWONLY;
15
16         item_init(
17                 defct_reinit,
18                 defct_destroy,
19                 defct_key,
20                 defct_draw,
21                 defct_mouse_enter,
22                 defct_mouse_leave,
23                 defct_action,
24                 defct_refresh);
25
26         ctcall_init();
27 };
28
29 //////////////////
30 // ITEM_REFERENCE
31 ///
32
33 void(void) ITEM_REFERENCE =
34 {
35         self.flag = self.flag | FLAG_NOSELECT | FLAG_DRAWONLY;
36
37         // if there is no link, this is a dynamic reference
38         if(self.link != "")
39         {
40                 self._child = menu_getitem(self.link);
41                 if(self._child == null_entity)
42                 {
43                         print(self.name, " removed, cause link ", self.link, " not found\n");
44                         remove(self);   // no need to call terminate
45                         return;
46                 }
47         }
48
49         item_init(
50                 defct_reinit,
51                 defct_destroy,
52                 defct_key,
53                 defct_draw,
54                 defct_mouse_enter,
55                 defct_mouse_leave,
56                 defct_action,
57                 defct_refresh);
58
59         ctcall_init();
60 };
61
62 ////////////////
63 // ITEM_CUSTOM
64 ////
65
66 void(void) ITEM_CUSTOM =
67 {
68         item_init(defct_reinit, defct_destroy, defct_key, defct_draw, defct_mouse_enter, defct_mouse_leave, defct_action, defct_refresh);
69         ctcall_init();
70 };
71
72 /////////////////
73 // ITEM_PICTURE
74 ///
75
76 // ITEM_PICTURE has a special draw function
77 void(void) ITEM_PICTURE_DRAW =
78 {
79         menu_drawpic(self.pos, self.picture, self.size, self.color, self.alpha, self.drawflag);
80
81         ctcall_draw();
82 };
83
84 void(void) ITEM_PICTURE_DESTROY =
85 {
86         gfx_unloadpic(self.picture);
87
88         ctcall_destroy();
89 };
90
91 void(void) ITEM_PICTURE =
92 {
93         if(self.picture == "")
94                 // a picture has to have a picture
95                 remove(self);           // no need to call terminate
96
97         // load the picture if it isnt loaded already
98         gfx_loadpic(self.picture, MENU_ENFORCELOADING);
99
100         // if flag wasnt set yet, then set it to FLAG_DRAWONLY
101         if(self.flag == 0)
102                 self.flag = FLAG_DRAWONLY;
103
104         if(self.color == '0 0 0')
105                 self.color = ITEM_PICTURE_NORMAL_COLOR;
106         if(self.alpha == 0)
107                 self.alpha = ITEM_PICTURE_NORMAL_ALPHA;
108
109         item_init(
110                 defct_reinit,
111                 ITEM_PICTURE_DESTROY,
112                 defct_key,
113                 ITEM_PICTURE_DRAW,
114                 defct_mouse_enter,
115                 defct_mouse_leave,
116                 defct_action,
117                 defct_refresh);
118
119         ctcall_init();
120 };
121
122 /////////////
123 // ITEM_TEXT
124 ///
125
126 void(void) ITEM_TEXT_REFRESH =
127 {
128         // first do own refresh, *then* call the default refresh !
129         if(self.size == '0 0 0')
130         {
131                 if(self.font_size == '0 0 0')
132                         self.font_size = ITEM_TEXT_FONT_SIZE;
133
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')
137         {
138                         self.font_size_x = self.size_x / strlen(self.text);
139                         self.font_size_y = self.size_y;
140         }
141
142         def_refresh();
143         ctcall_refresh();
144 };
145
146 void(void) ITEM_TEXT_DRAW =
147 {
148         if(self.text)
149         {
150                 // align to the rect pos - (pos + size)
151                 vector alignpos;
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;
157                 else
158                         alignpos_x = self.pos_x;
159                 alignpos_y = self.pos_y;
160
161                 menu_drawstring(alignpos, self.text, self.font_size, self.color, self.alpha, self.drawflag);
162         }
163         ctcall_draw();
164 };
165
166 void(void) ITEM_TEXT =
167 {
168         if(self.flag == 0)
169                 self.flag = FLAG_DRAWONLY;
170
171         if(self.color == '0 0 0')
172                 self.color = ITEM_TEXT_NORMAL_COLOR;
173         if(self.alpha == 0)
174                 self.alpha = ITEM_TEXT_NORMAL_ALPHA;
175
176         ITEM_TEXT_REFRESH();
177         if(self.alignment & TEXT_ALIGN_CENTERPOS)
178         {
179                 self.pos_x = self.pos_x - self.size_x / 2;
180         } else  if(self.alignment & TEXT_ALIGN_LEFTPOS)
181         {
182                 self.pos_x = self.pos_x - self.size_x;
183         }
184
185         item_init(
186                 defct_reinit,
187                 defct_destroy,
188                 defct_key,
189                 ITEM_TEXT_DRAW,
190                 defct_mouse_enter,
191                 defct_mouse_leave,
192                 defct_action,
193                 ITEM_TEXT_REFRESH);
194
195         ctcall_init();
196 };
197
198 /////////////////
199 // ITEM_RECTANLE
200 ///
201
202 void(void) ITEM_RECTANGLE_DRAW =
203 {
204         menu_fillarea(self.pos, self.size, self.color, self.alpha, self.drawflag);
205 };
206
207 void(void) ITEM_RECTANGLE =
208 {
209         if(self.flag == 0)
210                 self.flag = FLAG_DRAWONLY;
211
212         item_init(
213                 defct_reinit,
214                 defct_destroy,
215                 defct_key,
216                 ITEM_RECTANGLE_DRAW,
217                 defct_mouse_enter,
218                 defct_mouse_leave,
219                 defct_action,
220                 defct_refresh);
221
222         ctcall_init();
223 };
224
225 ////////////////
226 // ITEM_BUTTON
227 ///
228
229 void(void) ITEM_BUTTON_DRAW =
230 {
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);
235         else
236                 menu_drawpic(self.pos, self.picture_pressed, self.size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
237
238         ctcall_draw();
239 };
240
241 void(void) ITEM_BUTTON_REFRESH =
242 {
243
244         if((self.hold_pressed + self._press_time < time && self._button_state == BUTTON_PRESSED) || (menu_selected != self && self._button_state == BUTTON_SELECTED))
245         {
246                 self._button_state = BUTTON_NORMAL;
247         }
248         if(menu_selected == self && self._button_state == BUTTON_NORMAL)
249         {
250                 self._button_state = BUTTON_SELECTED;
251                 if(self.sound_selected)
252                         snd_play(self.sound_selected);
253         }
254         def_refresh();
255         ctcall_refresh();
256 };
257
258 void(float keynr, float ascii) ITEM_BUTTON_KEY =
259 {
260         if(ctcall_key(keynr, ascii))
261                 return;
262
263         if(keynr == K_ENTER || keynr == K_MOUSE1)
264         {
265                 self._action();
266         } else
267                 def_keyevent(keynr, ascii);
268 };
269
270 void(void) ITEM_BUTTON_ACTION =
271 {
272         self._press_time = time;
273         self._button_state = BUTTON_PRESSED;
274         if(self.sound_pressed)
275                 snd_play(self.sound_pressed);
276
277         ctcall_action();
278 };
279 void(void) ITEM_BUTTON_REINIT =
280 {
281         self._button_state = BUTTON_NORMAL;
282
283         ctcall_reinit();
284 };
285
286 void(void) ITEM_BUTTON_DESTROY =
287 {
288         gfx_unloadpic(self.picture);
289         gfx_unloadpic(self.picture_selected);
290         gfx_unloadpic(self.picture_pressed);
291
292         ctcall_destroy();
293 };
294
295 void(void) ITEM_BUTTON =
296 {
297         if(self.picture == "" || self.picture_selected == "" || self.picture_pressed == "")
298                 // a picture has to have pictures
299                 remove(self);   // no need to call terminate
300
301         // load the picture if it isnt loaded already
302         gfx_loadpic(self.picture, MENU_ENFORCELOADING);
303         gfx_loadpic(self.picture_selected, MENU_ENFORCELOADING);
304         gfx_loadpic(self.picture_pressed, MENU_ENFORCELOADING);
305
306         if(self.sound_selected != "")
307                 snd_loadsound(self.sound_selected, SOUND_ENFORCELOADING);
308         else
309                 self.sound_selected = SOUND_SELECT;
310
311         if(self.sound_pressed != "")
312                 snd_loadsound(self.sound_pressed, SOUND_ENFORCELOADING);
313         else
314                 self.sound_pressed = SOUND_ACTION;
315
316         // if flag wasnt set yet, then set it to FLAG_DRAWONLY
317         if(self.flag == 0)
318                 self.flag = FLAG_AUTOSETCLICK;
319
320         if(self.color == '0 0 0')
321                 self.color = ITEM_PICTURE_NORMAL_COLOR;
322         if(self.alpha == 0)
323                 self.alpha = ITEM_PICTURE_NORMAL_ALPHA;
324         if(self.color_selected == '0 0 0')
325                 self.color_selected = ITEM_PICTURE_SELECTED_COLOR;
326         if(self.alpha_selected == 0)
327                 self.alpha_selected = ITEM_PICTURE_SELECTED_ALPHA;
328         if(self.color_pressed == '0 0 0')
329                 self.color_pressed = ITEM_PICTURE_PRESSED_COLOR;
330         if(self.alpha_pressed == 0)
331                 self.alpha_pressed = ITEM_PICTURE_PRESSED_ALPHA;
332
333         if(self.hold_pressed == 0)
334                 self.hold_pressed = ITEM_BUTTON_HOLD_PRESSED;
335
336         item_init(
337                 ITEM_BUTTON_REINIT,
338                 ITEM_BUTTON_DESTROY,
339                 ITEM_BUTTON_KEY,
340                 ITEM_BUTTON_DRAW,
341                 defct_mouse_enter,
342                 defct_mouse_leave,
343                 defct_action,
344                 ITEM_BUTTON_REFRESH);
345
346         ctcall_init();
347 };
348
349 ////////////////////
350 // ITEM_TEXTBUTTON
351 ///
352
353 void(void) ITEM_TEXTBUTTON_REFRESH =
354 {
355         // first do own refresh, *then* call the default refresh !
356         if(self.size == '0 0 0')
357         {
358                 if(self.font_size == '0 0 0')
359                         self.font_size = ITEM_TEXT_FONT_SIZE;
360
361                 self.size_x = self.font_size_x * strlen(self.text);
362                 self.size_y = self.font_size_y;
363         } else if(self.font_size == '0 0 0')
364         {
365                         self.font_size_x = self.size_x / strlen(self.text);
366                         self.font_size_y = self.size_y;
367         }
368
369         if((self.hold_pressed + self._press_time < time && self._button_state == BUTTON_PRESSED) || (menu_selected != self && self._button_state == BUTTON_SELECTED))
370         {
371                 self._button_state = BUTTON_NORMAL;
372         }
373         if(menu_selected == self && self._button_state == BUTTON_NORMAL)
374         {
375                 self._button_state = BUTTON_SELECTED;
376                 if(self.sound_selected)
377                         snd_play(self.sound_selected);
378         }
379
380         def_refresh();
381         ctcall_refresh();
382 };
383
384 void(void) ITEM_TEXTBUTTON_DRAW =
385 {
386         if(self.text == "")
387                 return;
388
389         // align to the rect pos - (pos + size)
390         vector alignpos;
391         // now check the alignement
392         if(self.alignment & TEXT_ALIGN_CENTER)
393                 alignpos_x = self.pos_x + (self.size_x - strlen(self.text) * self.font_size_x) / 2;
394         else if(self.alignment & TEXT_ALIGN_RIGHT)
395                 alignpos_x = self.pos_x + self.size_x - strlen(self.text) * self.font_size_x;
396         else
397                 alignpos_x = self.pos_x;
398                 alignpos_y = self.pos_y;
399
400         if(self.style == TEXTBUTTON_STYLE_OUTLINE && self._button_state != BUTTON_NORMAL)
401         {
402                 vector p,s;
403                 // left
404                 p_x = self.pos_x;
405                 p_y = self.pos_y;
406                 s_x = TEXTBUTTON_OUTLINE_WIDTH;
407                 s_y = self.size_y;
408                 if(self._button_state == BUTTON_PRESSED)
409                 {
410                         menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
411                 }
412                 else if(self._button_state == BUTTON_SELECTED)
413                 {
414                         menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
415                 }
416                 // right
417                 p_x = self.pos_x + self.size_x - TEXTBUTTON_OUTLINE_WIDTH;
418                 p_y = self.pos_y;
419                 s_x = TEXTBUTTON_OUTLINE_WIDTH;
420                 s_y = self.size_y;
421                 if(self._button_state == BUTTON_PRESSED)
422                 {
423                         menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
424                 }
425                 else if(self._button_state == BUTTON_SELECTED)
426                 {
427                         menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
428                 }
429                 // top
430                 p_x = self.pos_x;
431                 p_y = self.pos_y;
432                 s_y = TEXTBUTTON_OUTLINE_WIDTH;
433                 s_x = self.size_x;
434                 if(self._button_state == BUTTON_PRESSED)
435                 {
436                         menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
437                 }
438                 else if(self._button_state == BUTTON_SELECTED)
439                 {
440                         menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
441                 }
442                 // bottom
443                 p_x = self.pos_x;
444                 p_y = self.pos_y + self.size_y - TEXTBUTTON_OUTLINE_WIDTH;
445                 s_y = TEXTBUTTON_OUTLINE_WIDTH;
446                 s_x = self.size_x;
447                 if(self._button_state == BUTTON_PRESSED)
448                 {
449                         menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
450                 }
451                 else if(self._button_state == BUTTON_SELECTED)
452                 {
453                         menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
454                 }
455         } else  if(self.style == TEXTBUTTON_STYLE_BOX)
456         {
457                 if(self._button_state == BUTTON_PRESSED)
458                 {
459                         menu_fillarea(alignpos, self.size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
460                 }
461                 else if(self._button_state == BUTTON_SELECTED)
462                 {
463                         menu_fillarea(alignpos, self.size, self.color_selected, self.alpha_selected, self.drawflag_selected);
464                 }
465         }
466
467         if(self._button_state == BUTTON_NORMAL || self.style == TEXTBUTTON_STYLE_BOX || self.style == TEXTBUTTON_STYLE_OUTLINE)
468                 menu_drawstring(alignpos, self.text, self.font_size, self.color, self.alpha, self.drawflag);
469
470         if(self.style == TEXTBUTTON_STYLE_TEXT)
471         {
472                 if(self._button_state == BUTTON_PRESSED)
473                 {
474                         menu_drawstring(alignpos, self.text, self.font_size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
475                 }
476                 else if(self._button_state == BUTTON_SELECTED)
477                 {
478                         menu_drawstring(alignpos, self.text, self.font_size, self.color_selected, self.alpha_selected, self.drawflag_selected);
479                 }
480         }
481
482         ctcall_draw();
483 };
484
485 void(void) ITEM_TEXTBUTTON_ACTION =
486 {
487         self._press_time = time;
488         self._button_state = BUTTON_PRESSED;
489         if(self.sound_pressed)
490                 snd_play(self.sound_pressed);
491
492         ctcall_action();
493 };
494
495 void(float keynr, float ascii) ITEM_TEXTBUTTON_KEY =
496 {
497         if(ctcall_key(keynr, ascii))
498                 return;
499
500         if(keynr == K_ENTER || keynr == K_MOUSE1)
501         {
502                 self._action();
503         } else
504                 def_keyevent(keynr, ascii);
505 };
506
507 void(void) ITEM_TEXTBUTTON_REINIT =
508 {
509         self._button_state = BUTTON_NORMAL;
510
511         ctcall_reinit();
512 };
513
514 void(void) ITEM_TEXTBUTTON =
515 {
516         if(self.flag == 0)
517                 self.flag = FLAG_AUTOSETCLICK;
518
519         if(self.color == '0 0 0')
520                 self.color = ITEM_TEXT_NORMAL_COLOR;
521         if(self.alpha == 0)
522                 self.alpha = ITEM_TEXT_NORMAL_ALPHA;
523         if(self.color_selected == '0 0 0')
524                 self.color_selected = ITEM_TEXT_SELECTED_COLOR;
525         if(self.alpha_selected == 0)
526                 self.alpha_selected = ITEM_TEXT_SELECTED_ALPHA;
527         if(self.color_pressed == '0 0 0')
528                 self.color_pressed = ITEM_TEXT_PRESSED_COLOR;
529         if(self.alpha_pressed == 0)
530                 self.alpha_pressed = ITEM_TEXT_PRESSED_ALPHA;
531
532         if(self.hold_pressed == 0)
533                 self.hold_pressed = ITEM_BUTTON_HOLD_PRESSED;
534
535         if(self.sound_selected != "")
536                 snd_loadsound(self.sound_selected, SOUND_ENFORCELOADING);
537         else
538                 self.sound_selected = SOUND_SELECT;
539
540         if(self.sound_pressed != "")
541                 snd_loadsound(self.sound_pressed, SOUND_ENFORCELOADING);
542         else
543                 self.sound_pressed = SOUND_ACTION;
544
545         ITEM_TEXTBUTTON_REFRESH();
546         if(self.alignment & TEXT_ALIGN_CENTERPOS)
547         {
548                 self.pos_x = self.pos_x - self.size_x / 2;
549         } else  if(self.alignment & TEXT_ALIGN_LEFTPOS)
550         {
551                 self.pos_x = self.pos_x - self.size_x;
552         }
553
554         item_init(
555                 ITEM_TEXTBUTTON_REINIT,
556                 defct_destroy,
557                 ITEM_TEXTBUTTON_KEY,
558                 ITEM_TEXTBUTTON_DRAW,
559                 defct_mouse_enter,
560                 defct_mouse_leave,
561                 ITEM_TEXTBUTTON_ACTION,
562                 ITEM_TEXTBUTTON_REFRESH);
563
564         ctcall_init();
565 };
566
567 // ITEM_SLIDER
568
569 void(void) ITEM_SLIDER_DRAW =
570 {
571         vector slider_pos;
572         string t;
573
574         // draw the bar
575         if(self.picture_bar != "")
576         {
577                 menu_drawpic(self.pos, self.picture_bar, self.size, self.color, self.alpha, self.drawflag);
578         }
579         else
580         {
581                 menu_fillarea(self.pos, self.size, self.color, self.alpha, self.drawflag);
582         }
583
584         // draw the slider
585         slider_pos = self.pos;
586         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);
587         if(self.picture != "")
588         {
589                 menu_drawpic(slider_pos, self.picture, self.slider_size, self.color, self.alpha, self.drawflag);
590         }
591         else
592         {
593                 menu_fillarea(slider_pos, self.slider_size, self.color + ITEM_SLIDER_BAR_COLOR_DELTA, self.alpha, self.drawflag);
594         }
595 };
596
597 void(void) ITEM_SLIDER_UPDATESLIDER =
598 {
599         self.value = bound(self.min_value, self.value, self.max_value);
600         if(self.slidermove)
601                 self.slidermove();
602 };
603
604 void(float keynr, float ascii) ITEM_SLIDER_KEY =
605 {
606         float old;
607         old = self.value;
608
609         if(ctcall_key(keynr, ascii))
610                 return;
611
612         if(keynr == K_LEFTARROW)
613         {
614                 self.value = (rint(self.value / self.step) - 1) * self.step;
615         }
616         else if(keynr == K_RIGHTARROW)
617         {
618                 self.value = (rint(self.value / self.step) + 1)* self.step;
619         }
620         else if(keynr == K_MOUSE1)
621         {
622                 if(inrect(menu_cursor, self.pos, self.size))
623                 {
624                         if(menu_cursor_x - self.pos_x <= self.left_margin)
625                         {
626                                 self.value = (rint(self.value / self.step) - 1)* self.step;
627                         }
628                         else if(menu_cursor_x - self.pos_x >= self.size_x - self.right_margin)
629                         {
630                                 self.value = (rint(self.value / self.step) + 1)* self.step;
631                         }
632                         else
633                         {
634                                 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));
635                         }
636                 }
637         }
638         else
639         {
640                 def_keyevent(keynr, ascii);
641                 return;
642         }
643         // play sound
644         if(old < self.value)
645         {
646                 snd_play(self.sound_increase);
647         }
648         else if(self.value < old)
649         {
650                 snd_play(self.sound_decrease);
651         }
652
653         ITEM_SLIDER_UPDATESLIDER();
654         ctcall_action();
655 };
656
657 void(void) ITEM_SLIDER_DESTROY =
658 {
659         if(self.picture != "" && self.picture != ITEM_SLIDER_DEFAULT_SLIDER)
660                 gfx_unloadpic(self.picture);
661         if(self.picture_bar != "" && self.picture_bar != ITEM_SLIDER_DEFAULT_BAR)
662                 gfx_unloadpic(self.picture);
663         if(self.sound_increase != SOUND_INCREASE)
664                 snd_unloadsound(self.sound_decrease);
665         if(self.sound_increase != SOUND_INCREASE)
666                 snd_unloadsound(self.sound_increase);
667
668         ctcall_destroy();
669 };
670
671 void(void) ITEM_SLIDER =
672 {
673         if(self.picture != "")
674                 self.picture = gfx_loadpic(self.picture, MENU_ENFORCELOADING);
675         if(self.picture == "")
676                 self.picture = gfx_loadpic(ITEM_SLIDER_DEFAULT_SLIDER, MENU_ENFORCELOADING);
677         if(self.picture_bar != "")
678                 self.picture_bar = gfx_loadpic(self.picture_bar, MENU_ENFORCELOADING);
679         if(self.picture_bar == "")
680                 self.picture_bar = gfx_loadpic(ITEM_SLIDER_DEFAULT_BAR, MENU_ENFORCELOADING);
681         if(self.sound_decrease == "")
682                 self.sound_decrease = SOUND_DECREASE;
683         else
684                 snd_loadsound(self.sound_decrease, MENU_ENFORCELOADING);
685         if(self.sound_increase == "")
686                 self.sound_increase = SOUND_INCREASE;
687         else
688                 snd_loadsound(self.sound_increase, MENU_ENFORCELOADING);
689
690         if(self.color == '0 0 0')
691                 self.color = ITEM_SLIDER_COLOR;
692         if(self.alpha == 0)
693                 self.alpha = ITEM_SLIDER_ALPHA;
694         if(self.step == 0)
695                 self.step = ITEM_SLIDER_STEP;
696         if(self.slider_size == '0 0 0')
697         {
698                 /*if(self.picture != "")
699                         self.slider_size = gfx_getimagesize(self.picture);
700                 else*/
701                         self.slider_size = ITEM_SLIDER_SIZE;
702         }
703         if(self.left_margin == 0)
704                 self.left_margin = ITEM_SLIDER_LEFT_MARGIN;
705         if(self.right_margin == 0)
706                 self.right_margin = ITEM_SLIDER_RIGHT_MARGIN;
707
708         item_init(
709                 defct_reinit,
710                 defct_destroy,
711                 ITEM_SLIDER_KEY,
712                 ITEM_SLIDER_DRAW,
713                 defct_mouse_enter,
714                 defct_mouse_leave,
715                 defct_action,
716                 defct_refresh);
717
718         ctcall_init();
719 };
720
721 // ITEM_TEXTSWITCH
722
723 void(void) ITEM_TEXTSWITCH_DRAW =
724 {
725         string temp;
726
727         // get the current text
728         temp = self.text;
729         self.text = getaltstring(self.value, self.text);
730         // call ITEM_TEXT
731         ITEM_TEXT_DRAW();
732         self.text = temp;
733 };
734
735 void(void) ITEM_TEXTSWITCH_REFRESH =
736 {
737         string temp;
738
739         temp = self.text;
740         self.text = getaltstring(self.value, self.text);
741
742         ITEM_TEXT_REFRESH();
743
744         self.text = temp;
745 };
746
747 void(float keynr, float ascii)  ITEM_TEXTSWITCH_KEY =
748 {
749         float old;
750         old = self.value;
751
752         if(ctcall_key(keynr, ascii))
753                 return;
754
755         if(keynr == K_LEFTARROW || keynr == K_MOUSE2)
756         {
757                 self.value = self.value - 1;
758                 if(self.value < 0)
759                         self.value = getaltstringcount(self.text) - 1;
760         }
761         else if(keynr == K_RIGHTARROW || keynr == K_MOUSE1 || keynr == K_ENTER)
762         {
763                 self.value = self.value + 1;
764                 if(self.value > getaltstringcount(self.text) - 1)
765                         self.value = 0;
766         } else
767         {
768                 def_keyevent(keynr, ascii);
769                 return;
770         }
771         // play sound
772         if(old < self.value)
773                 snd_play(self.sound_increase);
774         else if(self.value < old)
775                 snd_play(self.sound_decrease);
776
777         if(self.switchchange)
778                 self.switchchange();
779 };
780
781 void(void) ITEM_TEXTSWITCH_DESTROY =
782 {
783         if(self.sound_increase != SOUND_INCREASE)
784                 snd_unloadsound(self.sound_decrease);
785         if(self.sound_increase != SOUND_INCREASE)
786                 snd_unloadsound(self.sound_increase);
787 }
788
789 void(void) ITEM_TEXTSWITCH =
790 {
791         string temp;
792
793         if(self.sound_decrease == "")
794                 self.sound_decrease = SOUND_DECREASE;
795         else
796                 snd_loadsound(self.sound_decrease, MENU_ENFORCELOADING);
797         if(self.sound_increase == "")
798                 self.sound_increase = SOUND_INCREASE;
799         else
800                 snd_loadsound(self.sound_increase, MENU_ENFORCELOADING);
801
802         temp = self.text;
803         self.text = getaltstring(self.value, self.text);
804         ITEM_TEXT();
805         self.text = temp;
806
807         item_init(
808                 defct_reinit,
809                 ITEM_TEXTSWITCH_DESTROY,
810                 ITEM_TEXTSWITCH_KEY,
811                 ITEM_TEXTSWITCH_DRAW,
812                 defct_mouse_enter,
813                 defct_mouse_leave,
814                 defct_action,
815                 ITEM_TEXTSWITCH_REFRESH);
816
817         ctcall_init();
818 };
819
820 /*
821 /////////////////////////////////////////////////////////////////////////
822 // The "actual" funtions
823
824 void(void) ctinit_picture =
825 {
826
827 };
828
829 // draws a text (uses the std. way)
830 void(string text, vector pos, vector size, float alignment, float style, float state) ctdrawtext =
831 {
832         vector alignpos;
833
834         if(text == "")
835                 return;
836
837         // align to the rect pos - (pos + size)
838
839         // now check the alignement
840         if(alignment & TEXT_ALIGN_CENTER)
841                 alignpos_x = pos_x + (size_x - strlen(text) * self.font_size_x) / 2;
842         else if(alignment & TEXT_ALIGN_RIGHT)
843                 alignpos_x = pos_x + size_x - strlen(text) * self.font_size_x;
844         else
845                 alignpos_x = pos_x;
846                 alignpos_y = pos_y;
847
848         if(style == TEXTBUTTON_STYLE_OUTLINE && state != BUTTON_NORMAL)
849         {
850                 vector p,s;
851                 // left
852                 p_x = pos_x;
853                 p_y = pos_y;
854                 s_x = TEXTBUTTON_OUTLINE_WIDTH;
855                 s_y = size_y;
856                 if(state == BUTTON_PRESSED)
857                 {
858                         menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
859                 }
860                 else if(state == BUTTON_SELECTED)
861                 {
862                         menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
863                 }
864                 // right
865                 p_x = pos_x + size_x - TEXTBUTTON_OUTLINE_WIDTH;
866                 p_y = pos_y;
867                 s_x = TEXTBUTTON_OUTLINE_WIDTH;
868                 s_y = size_y;
869                 if(state == BUTTON_PRESSED)
870                 {
871                         menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
872                 }
873                 else if(state == BUTTON_SELECTED)
874                 {
875                         menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
876                 }
877                 // top
878                 p_x = pos_x;
879                 p_y = pos_y;
880                 s_y = TEXTBUTTON_OUTLINE_WIDTH;
881                 s_x = size_x;
882                 if(state == BUTTON_PRESSED)
883                 {
884                         menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
885                 }
886                 else if(self._button_state == BUTTON_SELECTED)
887                 {
888                         menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
889                 }
890                 // bottom
891                 p_x = pos_x;
892                 p_y = pos_y + size_y - TEXTBUTTON_OUTLINE_WIDTH;
893                 s_y = TEXTBUTTON_OUTLINE_WIDTH;
894                 s_x = size_x;
895                 if(state == BUTTON_PRESSED)
896                 {
897                         menu_fillarea(p, s, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
898                 }
899                 else if(state == BUTTON_SELECTED)
900                 {
901                         menu_fillarea(p, s, self.color_selected, self.alpha_selected, self.drawflag_selected);
902                 }
903         } else  if(style == TEXTBUTTON_STYLE_BOX)
904         {
905                 if(state == BUTTON_PRESSED)
906                 {
907                         menu_fillarea(alignpos, size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
908                 }
909                 else if(self._button_state == BUTTON_SELECTED)
910                 {
911                         menu_fillarea(alignpos, size, self.color_selected, self.alpha_selected, self.drawflag_selected);
912                 }
913         }
914
915         if(state == BUTTON_NORMAL || style == TEXTBUTTON_STYLE_BOX || style == TEXTBUTTON_STYLE_OUTLINE)
916                 menu_drawstring(alignpos, text, self.font_size, self.color, self.alpha, self.drawflag);
917
918         if(style == TEXTBUTTON_STYLE_TEXT)
919         {
920                 if(state == BUTTON_PRESSED)
921                 {
922                         menu_drawstring(alignpos, text, self.font_size, self.color_pressed, self.alpha_pressed, self.drawflag_pressed);
923                 }
924                 else if(state == BUTTON_SELECTED)
925                 {
926                         menu_drawstring(alignpos, text, self.font_size, self.color_selected, self.alpha_selected, self.drawflag_selected);
927                 }
928         }
929 };*/