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