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