Had to change the #includes of dependend headers from "dir/header.h" to "../dir...
[supertux.git] / lib / gui / menu.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #ifndef WIN32
21 #include <sys/types.h>
22 #include <ctype.h>
23 #endif
24
25 #include <iostream>
26 #include <sstream>
27 #include <cstdlib>
28 #include <cstdio>
29 #include <string>
30 #include <cassert>
31
32 #include "../app/globals.h"
33 #include "../gui/menu.h"
34 #include "../video/screen.h"
35 #include "../video/drawing_context.h"
36 #include "../app/setup.h"
37 #include "../audio/sound.h"
38 #include "../special/timer.h"
39 #include "../app/gettext.h"
40 #include "../math/vector.h"
41
42 using namespace SuperTux;
43
44 #define FLICK_CURSOR_TIME 500
45
46 Surface* SuperTux::checkbox;
47 Surface* SuperTux::checkbox_checked;
48 Surface* SuperTux::back;
49 Surface* SuperTux::arrow_left;
50 Surface* SuperTux::arrow_right;
51
52 std::vector<Menu*> Menu::last_menus;
53 Menu* Menu::current_ = 0;
54
55 /* just displays a Yes/No text that can be used to confirm stuff */
56 bool SuperTux::confirm_dialog(Surface *background, std::string text)
57 {
58   //Surface* cap_screen = Surface::CaptureScreen();
59   
60   Menu* dialog = new Menu;
61   dialog->additem(MN_DEACTIVE, text,0,0);
62   dialog->additem(MN_HL,"",0,0);
63   dialog->additem(MN_ACTION,_("Yes"),0,0,true);
64   dialog->additem(MN_ACTION,_("No"),0,0,false);
65   dialog->additem(MN_HL,"",0,0);
66
67   Menu::set_current(dialog);
68
69   DrawingContext context;
70
71   while(true)
72   {
73     SDL_Event event;
74
75     while (SDL_PollEvent(&event))
76     {
77       dialog->event(event);
78     }
79
80     if(background == NULL)
81       context.draw_gradient(Color(200,240,220), Color(200,200,220), LAYER_BACKGROUND0);
82     else
83       context.draw_surface(background, Vector(0,0), LAYER_BACKGROUND0);
84
85     dialog->draw(context);
86     dialog->action();
87
88     switch (dialog->check())
89     {
90     case true:
91       //delete cap_screen;
92       Menu::set_current(0);
93       delete dialog;
94       return true;
95       break;
96     case false:
97       //delete cap_screen;
98       Menu::set_current(0);
99       delete dialog;
100       return false;
101       break;
102     default:
103       break;
104     }
105
106     mouse_cursor->draw(context);
107     context.do_drawing();
108     SDL_Delay(25);
109   }
110
111   return false;
112 }
113
114 void
115 Menu::push_current(Menu* pmenu)
116 {
117   if (current_)
118     last_menus.push_back(current_);
119
120   current_ = pmenu;
121   current_->effect.start(500);
122 }
123
124 void
125 Menu::pop_current()
126 {
127   if (!last_menus.empty())
128   {
129     current_ = last_menus.back();
130     current_->effect.start(500);
131
132     last_menus.pop_back();
133   }
134   else
135   {
136     current_ = 0;
137   }
138 }
139
140 void
141 Menu::set_current(Menu* menu)
142 {
143   last_menus.clear();
144
145   if (menu)
146     menu->effect.start(500);
147
148   current_ = menu;
149 }
150
151 /* Return a pointer to a new menu item */
152 MenuItem*
153 MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* target_menu_, int id, int* int_p_)
154 {
155   MenuItem *pnew_item = new MenuItem;
156
157   pnew_item->kind = kind_;
158   pnew_item->text = (char*) malloc(sizeof(char) * (strlen(text_) + 1));
159   strcpy(pnew_item->text, text_);
160
161   if(kind_ == MN_TOGGLE)
162     pnew_item->toggled = init_toggle_;
163   else
164     pnew_item->toggled = false;
165
166   pnew_item->target_menu = target_menu_;
167   pnew_item->input = (char*) malloc(sizeof(char));
168   pnew_item->input[0] = '\0';
169
170   if(kind_ == MN_STRINGSELECT)
171   {
172     pnew_item->list = (string_list_type*) malloc(sizeof(string_list_type));
173     string_list_init(pnew_item->list);
174   }
175   else
176     pnew_item->list = NULL;
177
178   pnew_item->id = id;
179   pnew_item->int_p = int_p_;
180
181   pnew_item->input_flickering = false;
182   pnew_item->input_flickering_timer.init(true);
183   pnew_item->input_flickering_timer.start(FLICK_CURSOR_TIME);
184
185   return pnew_item;
186 }
187
188 void
189 MenuItem::change_text(const  char *text_)
190 {
191   if (text_)
192   {
193     free(text);
194     text = (char*) malloc(sizeof(char )*(strlen(text_)+1));
195     strcpy(text, text_);
196   }
197 }
198
199 void
200 MenuItem::change_input(const  char *text_)
201 {
202   if(text)
203   {
204     free(input);
205     input = (char*) malloc(sizeof(char )*(strlen(text_)+1));
206     strcpy(input, text_);
207   }
208 }
209
210 std::string MenuItem::get_input_with_symbol(bool active_item)
211 {
212   if(!active_item)
213     input_flickering = true;
214   else
215   {
216     if(input_flickering_timer.get_left() < 0)
217     {
218       if(input_flickering)
219         input_flickering = false;
220       else
221         input_flickering = true;
222       input_flickering_timer.start(FLICK_CURSOR_TIME);
223     }
224   }
225
226   char str[1024];
227   if(input_flickering)
228     sprintf(str,"%s ",input);
229   else
230     sprintf(str,"%s_",input);
231
232   std::string string = str;
233
234   return string;
235 }
236
237 /* Set ControlField for keyboard key */
238 void Menu::get_controlfield_key_into_input(MenuItem *item)
239 {
240   switch(*item->int_p)
241   {
242   case SDLK_UP:
243     item->change_input(_("Up cursor"));
244     break;
245   case SDLK_DOWN:
246     item->change_input(_("Down cursor"));
247     break;
248   case SDLK_LEFT:
249     item->change_input(_("Left cursor"));
250     break;
251   case SDLK_RIGHT:
252     item->change_input(_("Right cursor"));
253     break;
254   case SDLK_RETURN:
255     item->change_input(_("Return"));
256     break;
257   case SDLK_SPACE:
258     item->change_input(_("Space"));
259     break;
260   case SDLK_RSHIFT:
261     item->change_input(_("Right Shift"));
262     break;
263   case SDLK_LSHIFT:
264     item->change_input(_("Left Shift"));
265     break;
266   case SDLK_RCTRL:
267     item->change_input(_("Right Control"));
268     break;
269   case SDLK_LCTRL:
270     item->change_input(_("Left Control"));
271     break;
272   case SDLK_RALT:
273     item->change_input(_("Right Alt"));
274     break;
275   case SDLK_LALT:
276     item->change_input(_("Left Alt"));
277     break;
278   default:
279     {
280       char tmp[64];
281       snprintf(tmp, 64, "%d", *item->int_p);
282       item->change_input(tmp);
283     }
284     break;
285   }
286 }
287
288 /* Set ControlField for joystick button */
289 void Menu::get_controlfield_js_into_input(MenuItem *item)
290 {
291   std::ostringstream oss;
292   oss << "Button " << *item->int_p;
293   item->change_input(oss.str().c_str());
294 }
295
296 /* Free a menu and all its items */
297 Menu::~Menu()
298 {
299   if(item.size() != 0)
300   {
301     for(unsigned int i = 0; i < item.size(); ++i)
302     {
303       free(item[i].text);
304       free(item[i].input);
305       string_list_free(item[i].list);
306     }
307   }
308 }
309
310
311 Menu::Menu()
312 {
313   hit_item = -1;
314   menuaction = MENU_ACTION_NONE;
315   delete_character = 0;
316   mn_input_char = '\0';
317
318   pos_x        = screen->w/2;
319   pos_y        = screen->h/2;
320   arrange_left = 0;
321   active_item  = 0;
322   effect.init(false);
323
324   joystick_timer.init(true);
325 }
326
327 void Menu::set_pos(int x, int y, float rw, float rh)
328 {
329   pos_x = x + (int)((float)get_width() * rw);
330   pos_y = y + (int)((float)get_height() * rh);
331 }
332
333 void
334 Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* menu_, int id, int* int_p)
335 {
336   additem(MenuItem::create(kind_, text_.c_str(), toggle_, menu_, id, int_p));
337 }
338
339 /* Add an item to a menu */
340 void
341 Menu::additem(MenuItem* pmenu_item)
342 {
343   item.push_back(*pmenu_item);
344   delete pmenu_item;
345 }
346
347 void
348 Menu::clear()
349 {
350   item.clear();
351 }
352
353 /* Process actions done on the menu */
354 void
355 Menu::action()
356 {
357   hit_item = -1;
358   if(item.size() != 0)
359   {
360     switch(menuaction)
361     {
362     case MENU_ACTION_UP:
363       if (active_item > 0)
364         --active_item;
365       else
366         active_item = int(item.size())-1;
367       break;
368
369     case MENU_ACTION_DOWN:
370       if(active_item < int(item.size())-1)
371         ++active_item;
372       else
373         active_item = 0;
374       break;
375
376     case MENU_ACTION_LEFT:
377       if(item[active_item].kind == MN_STRINGSELECT
378           && item[active_item].list->num_items != 0)
379       {
380         if(item[active_item].list->active_item > 0)
381           --item[active_item].list->active_item;
382         else
383           item[active_item].list->active_item = item[active_item].list->num_items-1;
384       }
385       break;
386
387     case MENU_ACTION_RIGHT:
388       if(item[active_item].kind == MN_STRINGSELECT
389           && item[active_item].list->num_items != 0)
390       {
391         if(item[active_item].list->active_item < item[active_item].list->num_items-1)
392           ++item[active_item].list->active_item;
393         else
394           item[active_item].list->active_item = 0;
395       }
396       break;
397
398     case MENU_ACTION_HIT:
399       {
400         hit_item = active_item;
401         switch (item[active_item].kind)
402         {
403         case MN_GOTO:
404           if (item[active_item].target_menu != NULL)
405             Menu::push_current(item[active_item].target_menu);
406           else
407             puts("NULLL");
408           break;
409
410         case MN_TOGGLE:
411           item[active_item].toggled = !item[active_item].toggled;
412           break;
413
414         case MN_ACTION:
415           Menu::set_current(0);
416           item[active_item].toggled = true;
417           break;
418         case MN_TEXTFIELD:
419         case MN_NUMFIELD:
420           menuaction = MENU_ACTION_DOWN;
421           action();
422           break;
423
424         case MN_BACK:
425           Menu::pop_current();
426           break;
427         default:
428           break;
429         }
430       }
431       break;
432
433     case MENU_ACTION_REMOVE:
434       if(item[active_item].kind == MN_TEXTFIELD
435           || item[active_item].kind == MN_NUMFIELD)
436       {
437         if(item[active_item].input != NULL)
438         {
439           int i = strlen(item[active_item].input);
440
441           while(delete_character > 0)   /* remove charactes */
442           {
443             item[active_item].input[i-1] = '\0';
444             delete_character--;
445           }
446         }
447       }
448       break;
449
450     case MENU_ACTION_INPUT:
451       if(item[active_item].kind == MN_TEXTFIELD
452           || (item[active_item].kind == MN_NUMFIELD && mn_input_char >= '0' && mn_input_char <= '9'))
453       {
454         if(item[active_item].input != NULL)
455         {
456           int i = strlen(item[active_item].input);
457           item[active_item].input = (char*) realloc(item[active_item].input,sizeof(char)*(i + 2));
458           item[active_item].input[i] = mn_input_char;
459           item[active_item].input[i+1] = '\0';
460         }
461         else
462         {
463           item[active_item].input = (char*) malloc(2*sizeof(char));
464           item[active_item].input[0] = mn_input_char;
465           item[active_item].input[1] = '\0';
466         }
467       }
468
469     case MENU_ACTION_NONE:
470       break;
471     }
472   }
473
474   MenuItem& new_item = item[active_item];
475   if(new_item.kind == MN_DEACTIVE
476       || new_item.kind == MN_LABEL
477       || new_item.kind == MN_HL)
478   {
479     // Skip the horzontal line item
480     if (menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN)
481       menuaction = MENU_ACTION_DOWN;
482
483     if (item.size() > 1)
484       action();
485   }
486
487   menuaction = MENU_ACTION_NONE;
488
489   if (active_item >= int(item.size()))
490     active_item = int(item.size()) - 1;
491 }
492
493 int
494 Menu::check()
495 {
496   if (hit_item != -1)
497     return item[hit_item].id;
498   else
499     return -1;
500 }
501
502 void
503 Menu::draw_item(DrawingContext& context,
504     int index, // Position of the current item in the menu
505     int menu_width, int menu_height)
506 {
507   MenuItem& pitem = item[index];
508
509   int effect_offset = 0;
510   {
511     int effect_time = 0;
512
513     if(effect.check())
514       effect_time = effect.get_left() / 4;
515
516     effect_offset = (index % 2) ? effect_time : -effect_time;
517   }
518
519   Font* text_font = white_text;
520   int x_pos       = pos_x;
521   int y_pos       = pos_y + 24*index - menu_height/2 + 12 + effect_offset;
522   int shadow_size = 2;
523   int text_width  = int(text_font->get_text_width(pitem.text));
524   int input_width = int(text_font->get_text_width(pitem.input) + 10);
525   int list_width  =
526     int(text_font->get_text_width(string_list_active(pitem.list)));
527
528   if (arrange_left)
529     x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2;
530
531   if(index == active_item)
532   {
533     shadow_size = 3;
534     text_font = blue_text;
535   }
536
537   switch (pitem.kind)
538   {
539   case MN_DEACTIVE:
540     {
541       context.draw_text_center(gray_text, pitem.text,
542           Vector(0, y_pos - int(blue_text->get_height()/2)),
543           LAYER_GUI);
544       break;
545     }
546
547   case MN_HL:
548     {
549       // TODO
550       int x = pos_x - menu_width/2;
551       int y = y_pos - 12 - effect_offset;
552       /* Draw a horizontal line with a little 3d effect */
553       context.draw_filled_rect(Vector(x, y + 6),
554           Vector(menu_width, 4), Color(150,200,255,225), LAYER_GUI);
555       context.draw_filled_rect(Vector(x, y + 6),
556           Vector(menu_width, 2), Color(255,255,255,255), LAYER_GUI);
557       break;
558     }
559   case MN_LABEL:
560     {
561       context.draw_text_center(white_big_text,
562           pitem.text, Vector(0, y_pos - int(white_big_text->get_height()/2)),
563           LAYER_GUI);
564       break;
565     }
566   case MN_TEXTFIELD:
567   case MN_NUMFIELD:
568   case MN_CONTROLFIELD_KB:
569   case MN_CONTROLFIELD_JS:
570     {
571       int width = text_width + input_width + 5;
572       int text_pos = screen->w/2 - width/2;
573       int input_pos = text_pos + text_width + 10;
574
575       context.draw_filled_rect(
576           Vector(input_pos - 5, y_pos - 10),
577           Vector(input_width + 10, 20),
578           Color(255,255,255,255), LAYER_GUI-5);
579       context.draw_filled_rect(
580           Vector(input_pos - 4, y_pos - 9),
581           Vector(input_width + 8, 18),
582           Color(0,0,0,128), LAYER_GUI-4);
583
584       if(pitem.kind == MN_CONTROLFIELD_KB)
585         get_controlfield_key_into_input(&pitem);
586       else if (pitem.kind == MN_CONTROLFIELD_JS)
587         get_controlfield_js_into_input(&pitem);
588
589       if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
590       {
591         if(active_item == index)
592           context.draw_text(gold_text,
593               pitem.get_input_with_symbol(true),
594               Vector(input_pos, y_pos - int(gold_text->get_height()/2)),
595               LAYER_GUI);
596         else
597           context.draw_text(gold_text,
598               pitem.get_input_with_symbol(false),
599               Vector(input_pos, y_pos - int(gold_text->get_height()/2)),
600               LAYER_GUI);
601       }
602       else
603         context.draw_text(gold_text, pitem.input,
604             Vector(input_pos, y_pos - int(gold_text->get_height()/2)),
605             LAYER_GUI);
606
607       context.draw_text(text_font, pitem.text,
608           Vector(text_pos, y_pos - int(text_font->get_height()/2)),
609           LAYER_GUI);
610       break;
611     }
612   case MN_STRINGSELECT:
613     {
614       int list_pos_2 = list_width + 16;
615       int list_pos   = list_width/2;
616       int text_pos   = (text_width + 16)/2;
617
618       /* Draw arrows */
619       context.draw_surface(arrow_left,
620           Vector(x_pos - list_pos + text_pos - 17, y_pos - 8),
621           LAYER_GUI);
622       context.draw_surface(arrow_right,
623           Vector(x_pos - list_pos + text_pos - 1 + list_pos_2, y_pos - 8),
624           LAYER_GUI);
625
626       /* Draw input background */
627       context.draw_filled_rect(
628           Vector(x_pos - list_pos + text_pos - 1, y_pos - 10),
629           Vector(list_pos_2 + 2, 20),
630           Color(255,255,255,255), LAYER_GUI - 4);
631       context.draw_filled_rect(
632           Vector(x_pos - list_pos + text_pos, y_pos - 9),
633           Vector(list_pos_2, 18),
634           Color(0,0,0,128), LAYER_GUI - 5);
635
636       context.draw_text_center(text_font, string_list_active(pitem.list),
637           Vector(text_pos, y_pos - int(text_font->get_height()/2)),
638           LAYER_GUI);
639       context.draw_text_center(text_font, pitem.text,
640           Vector(list_pos_2/2, y_pos - int(text_font->get_height()/2)),
641           LAYER_GUI);
642       break;
643     }
644   case MN_BACK:
645     {
646       context.draw_text_center(text_font, pitem.text,
647           Vector(0, y_pos - int(text_font->get_height()/2)),
648           LAYER_GUI);
649       context.draw_surface(back,
650           Vector(x_pos + text_width/2  + 16, y_pos - 8),
651           LAYER_GUI);
652       break;
653     }
654
655   case MN_TOGGLE:
656     {
657       context.draw_text_center(text_font, pitem.text,
658           Vector(0, y_pos - (text_font->get_height()/2)),
659           LAYER_GUI);
660
661       if(pitem.toggled)
662         context.draw_surface(checkbox_checked,
663             Vector(x_pos + (text_width+16)/2, y_pos - 8),
664             LAYER_GUI + 1);
665       else
666         context.draw_surface(checkbox,
667             Vector(x_pos + (text_width+16)/2, y_pos - 8),
668             LAYER_GUI + 1);                                      
669       break;
670     }
671   case MN_ACTION:
672     context.draw_text_center(text_font, pitem.text,
673         Vector(0, y_pos - int(text_font->get_height()/2)),
674         LAYER_GUI);
675     break;
676
677   case MN_GOTO:
678     context.draw_text_center(text_font, pitem.text,
679         Vector(0, y_pos - int(text_font->get_height()/2)),
680         LAYER_GUI);
681     break;
682   }
683 }
684
685 int Menu::get_width() const
686 {
687   /* The width of the menu has to be more than the width of the text
688      with the most characters */
689   int menu_width = 0;
690   for(unsigned int i = 0; i < item.size(); ++i)
691   {
692     int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0) + strlen(string_list_active(item[i].list));
693     if( w > menu_width )
694     {
695       menu_width = w;
696       if( item[i].kind == MN_TOGGLE)
697         menu_width += 2;
698     }
699   }
700
701   return (menu_width * 16 + 24);
702 }
703
704 int Menu::get_height() const
705 {
706   return item.size() * 24;
707 }
708
709 /* Draw the current menu. */
710 void
711 Menu::draw(DrawingContext& context)
712 {
713   int menu_height = get_height();
714   int menu_width  = get_width();
715
716   /* Draw a transparent background */
717   context.draw_filled_rect(
718       Vector(pos_x - menu_width/2, pos_y - 24*item.size()/2 - 10),
719       Vector(menu_width,menu_height + 20),
720       Color(150,180,200,125), LAYER_GUI-10);
721
722   for(unsigned int i = 0; i < item.size(); ++i)
723   {
724     draw_item(context, i, menu_width, menu_height);
725   }
726 }
727
728 MenuItem&
729 Menu::get_item_by_id(int id)
730 {
731   for(std::vector<MenuItem>::iterator i = item.begin(); i != item.end(); ++i)
732   {
733     if(i->id == id)
734       return *i;
735   }
736
737   assert(false);
738   static MenuItem dummyitem;
739   return dummyitem;
740 }
741
742 int Menu::get_active_item_id()
743 {
744   return item[active_item].id;
745 }
746
747 bool
748 Menu::isToggled(int id)
749 {
750   return get_item_by_id(id).toggled;
751 }
752
753 /* Check for menu event */
754 void
755 Menu::event(SDL_Event& event)
756 {
757   switch(event.type)
758     {
759     case SDL_KEYDOWN:
760       {
761         SDLKey key = key = event.key.keysym.sym;
762         SDLMod keymod;
763         char ch[2];
764         keymod = SDL_GetModState();
765
766         /* If the current unicode character is an ASCII character,
767            assign it to ch. */
768         if ( (event.key.keysym.unicode & 0xFF80) == 0 )
769           {
770             ch[0] = event.key.keysym.unicode & 0x7F;
771             ch[1] = '\0';
772           }
773         else
774           {
775             /* An International Character. */
776           }
777
778         if(item[active_item].kind == MN_CONTROLFIELD_KB)
779           {
780             if(key == SDLK_ESCAPE)
781               {
782                 Menu::pop_current();
783                 return;
784               }
785             *item[active_item].int_p = key;
786             menuaction = MENU_ACTION_DOWN;
787             return;
788           }
789
790
791         switch(key)
792           {
793           case SDLK_UP:         /* Menu Up */
794             menuaction = MENU_ACTION_UP;
795             break;
796           case SDLK_DOWN:               /* Menu Down */
797             menuaction = MENU_ACTION_DOWN;
798             break;
799           case SDLK_LEFT:               /* Menu Up */
800             menuaction = MENU_ACTION_LEFT;
801             break;
802           case SDLK_RIGHT:              /* Menu Down */
803             menuaction = MENU_ACTION_RIGHT;
804             break;
805           case SDLK_SPACE:
806             if(item[active_item].kind == MN_TEXTFIELD)
807               {
808                 menuaction = MENU_ACTION_INPUT;
809                 mn_input_char = ' ';
810                 break;
811               }
812           case SDLK_RETURN: /* Menu Hit */
813             menuaction = MENU_ACTION_HIT;
814             break;
815           case SDLK_DELETE:
816           case SDLK_BACKSPACE:
817             menuaction = MENU_ACTION_REMOVE;
818             delete_character++;
819             break;
820           case SDLK_ESCAPE:
821             Menu::pop_current();
822             break;
823           default:
824             if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH))
825               {
826                 menuaction = MENU_ACTION_INPUT;
827                 mn_input_char = *ch;
828               }
829             else
830               {
831                 mn_input_char = '\0';
832               }
833             break;
834           }
835       }
836       break;
837       
838     case  SDL_JOYAXISMOTION:
839       if(event.jaxis.axis == joystick_keymap.y_axis)
840         {
841           if (event.jaxis.value > joystick_keymap.dead_zone && !joystick_timer.started())
842             {
843               menuaction = MENU_ACTION_DOWN;
844               joystick_timer.start(JOYSTICK_MENU_DELAY);
845             }
846           else if (event.jaxis.value < -joystick_keymap.dead_zone && !joystick_timer.started())
847             {
848               menuaction = MENU_ACTION_UP;
849               joystick_timer.start(JOYSTICK_MENU_DELAY);
850             }
851           else
852             joystick_timer.stop();
853         }
854       break;
855     case  SDL_JOYBUTTONDOWN:
856       if (item[active_item].kind == MN_CONTROLFIELD_JS)
857         {
858           // FIXME: This next line does nothing useable, right? 
859           // *item[active_item].int_p = key;
860           menuaction = MENU_ACTION_DOWN;
861         }
862       menuaction = MENU_ACTION_HIT;
863       break;
864
865     case SDL_MOUSEBUTTONDOWN:
866       {
867         int x = event.motion.x;
868         int y = event.motion.y;
869
870         if(x > pos_x - get_width()/2 &&
871            x < pos_x + get_width()/2 &&
872            y > pos_y - get_height()/2 &&
873            y < pos_y + get_height()/2)
874           {
875             menuaction = MENU_ACTION_HIT;
876           }
877       }
878       break;
879
880     case SDL_MOUSEMOTION:
881       {
882         int x = event.motion.x;
883         int y = event.motion.y;
884
885         if(x > pos_x - get_width()/2 &&
886            x < pos_x + get_width()/2 &&
887            y > pos_y - get_height()/2 &&
888            y < pos_y + get_height()/2)
889           {
890             active_item = (y - (pos_y - get_height()/2)) / 24;
891             mouse_cursor->set_state(MC_LINK);
892           }
893         else
894           {
895             mouse_cursor->set_state(MC_NORMAL);
896           }
897       }
898       break;
899
900     default:
901       break;
902     }
903 }
904
905
906 // EOF //