- Fixed gradient not working when cached (SDL mode);
[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 "../special/timer.h"
38 #include "../app/gettext.h"
39 #include "../math/vector.h"
40
41 using namespace SuperTux;
42
43 #define FLICK_CURSOR_TIME 500
44
45 Surface* SuperTux::checkbox;
46 Surface* SuperTux::checkbox_checked;
47 Surface* SuperTux::back;
48 Surface* SuperTux::arrow_left;
49 Surface* SuperTux::arrow_right;
50
51 std::vector<Menu*> Menu::last_menus;
52 Menu* Menu::current_ = 0;
53 Font* Menu::default_font;
54 Font* Menu::active_font;
55 Font* Menu::deactive_font;
56 Font* Menu::label_font;
57 Font* Menu::field_font;
58
59 /* just displays a Yes/No text that can be used to confirm stuff */
60 bool SuperTux::confirm_dialog(Surface *background, std::string text)
61 {
62   //Surface* cap_screen = Surface::CaptureScreen();
63
64   Menu* dialog = new Menu;
65   dialog->additem(MN_DEACTIVE, text,0,0);
66   dialog->additem(MN_HL,"",0,0);
67   dialog->additem(MN_ACTION,_("Yes"),0,0,true);
68   dialog->additem(MN_ACTION,_("No"),0,0,false);
69   dialog->additem(MN_HL,"",0,0);
70
71   Menu::set_current(dialog);
72
73   DrawingContext context;
74
75   while(true)
76     {
77       SDL_Event event;
78
79       while (SDL_PollEvent(&event))
80         {
81           dialog->event(event);
82         }
83
84       if(background == NULL)
85         context.draw_gradient(Color(200,240,220), Color(200,200,220), LAYER_BACKGROUND0);
86       else
87         context.draw_surface(background, Vector(0,0), LAYER_BACKGROUND0);
88
89       dialog->draw(context);
90       dialog->action();
91
92       switch (dialog->check())
93         {
94         case true:
95           //delete cap_screen;
96           Menu::set_current(0);
97           delete dialog;
98           return true;
99           break;
100         case false:
101           //delete cap_screen;
102           Menu::set_current(0);
103           delete dialog;
104           return false;
105           break;
106         default:
107           break;
108         }
109
110       mouse_cursor->draw(context);
111       context.do_drawing();
112       SDL_Delay(25);
113     }
114
115   return false;
116 }
117
118 void
119 Menu::push_current(Menu* pmenu)
120 {
121   if (current_)
122     last_menus.push_back(current_);
123
124   current_ = pmenu;
125   current_->effect.start(500);
126 }
127
128 void
129 Menu::pop_current()
130 {
131   if (!last_menus.empty())
132     {
133       current_ = last_menus.back();
134       current_->effect.start(500);
135
136       last_menus.pop_back();
137     }
138   else
139     {
140       current_ = 0;
141     }
142 }
143
144 void
145 Menu::set_current(Menu* menu)
146 {
147   last_menus.clear();
148
149   if (menu)
150     menu->effect.start(500);
151
152   current_ = menu;
153 }
154
155 /* Return a pointer to a new menu item */
156 MenuItem*
157 MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* target_menu_, int id, int* int_p_)
158 {
159   MenuItem *pnew_item = new MenuItem;
160
161   pnew_item->kind = kind_;
162   pnew_item->text = (char*) malloc(sizeof(char) * (strlen(text_) + 1));
163   strcpy(pnew_item->text, text_);
164
165   if(kind_ == MN_TOGGLE)
166     pnew_item->toggled = init_toggle_;
167   else
168     pnew_item->toggled = false;
169
170   pnew_item->target_menu = target_menu_;
171   pnew_item->input = (char*) malloc(sizeof(char));
172   pnew_item->input[0] = '\0';
173
174   pnew_item->id = id;
175   pnew_item->int_p = int_p_;
176   
177   pnew_item->list.second = 0;
178
179   pnew_item->input_flickering = false;
180   pnew_item->input_flickering_timer.init(true);
181   pnew_item->input_flickering_timer.start(FLICK_CURSOR_TIME);
182
183   return pnew_item;
184 }
185
186 void
187 MenuItem::change_text(const  char *text_)
188 {
189   if (text_)
190     {
191       free(text);
192       text = (char*) malloc(sizeof(char )*(strlen(text_)+1));
193       strcpy(text, text_);
194     }
195 }
196
197 void
198 MenuItem::change_input(const  char *text_)
199 {
200   if(text)
201     {
202       free(input);
203       input = (char*) malloc(sizeof(char )*(strlen(text_)+1));
204       strcpy(input, text_);
205     }
206 }
207
208 std::string MenuItem::get_input_with_symbol(bool active_item)
209 {
210   if(!active_item)
211     input_flickering = true;
212   else
213     {
214       if(input_flickering_timer.get_left() < 0)
215         {
216           if(input_flickering)
217             input_flickering = false;
218           else
219             input_flickering = true;
220           input_flickering_timer.start(FLICK_CURSOR_TIME);
221         }
222     }
223
224   char str[1024];
225   if(input_flickering)
226     sprintf(str,"%s ",input);
227   else
228     sprintf(str,"%s_",input);
229
230   std::string string = str;
231
232   return string;
233 }
234
235 /* Set ControlField for keyboard key */
236 void Menu::get_controlfield_key_into_input(MenuItem *item)
237 {
238   switch(*item->int_p)
239     {
240     case SDLK_UP:
241       item->change_input(_("Up cursor"));
242       break;
243     case SDLK_DOWN:
244       item->change_input(_("Down cursor"));
245       break;
246     case SDLK_LEFT:
247       item->change_input(_("Left cursor"));
248       break;
249     case SDLK_RIGHT:
250       item->change_input(_("Right cursor"));
251       break;
252     case SDLK_RETURN:
253       item->change_input(_("Return"));
254       break;
255     case SDLK_SPACE:
256       item->change_input(_("Space"));
257       break;
258     case SDLK_RSHIFT:
259       item->change_input(_("Right Shift"));
260       break;
261     case SDLK_LSHIFT:
262       item->change_input(_("Left Shift"));
263       break;
264     case SDLK_RCTRL:
265       item->change_input(_("Right Control"));
266       break;
267     case SDLK_LCTRL:
268       item->change_input(_("Left Control"));
269       break;
270     case SDLK_RALT:
271       item->change_input(_("Right Alt"));
272       break;
273     case SDLK_LALT:
274       item->change_input(_("Left Alt"));
275       break;
276     default:
277       {
278         char tmp[64];
279         snprintf(tmp, 64, "%d", *item->int_p);
280         item->change_input(tmp);
281       }
282       break;
283     }
284 }
285
286 /* Set ControlField for joystick button */
287 void Menu::get_controlfield_js_into_input(MenuItem *item)
288 {
289   std::ostringstream oss;
290   oss << "Button " << *item->int_p;
291   item->change_input(oss.str().c_str());
292 }
293
294 /* Free a menu and all its items */
295 Menu::~Menu()
296 {
297   if(item.size() != 0)
298     {
299       for(unsigned int i = 0; i < item.size(); ++i)
300         {
301           free(item[i].text);
302           free(item[i].input);
303           item[i].list.first.clear();
304         }
305     }
306 }
307
308
309 Menu::Menu()
310 {
311   hit_item = -1;
312   menuaction = MENU_ACTION_NONE;
313   delete_character = 0;
314   mn_input_char = '\0';
315
316   pos_x        = screen->w/2;
317   pos_y        = screen->h/2;
318   arrange_left = 0;
319   active_item  = 0;
320   effect.init(false);
321
322   joystick_timer.init(true);
323 }
324
325 void Menu::set_pos(int x, int y, float rw, float rh)
326 {
327   pos_x = x + (int)((float)get_width() * rw);
328   pos_y = y + (int)((float)get_height() * rh);
329 }
330
331 void
332 Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* menu_, int id, int* int_p)
333 {
334   additem(MenuItem::create(kind_, text_.c_str(), toggle_, menu_, id, int_p));
335 }
336
337 /* Add an item to a menu */
338 void
339 Menu::additem(MenuItem* pmenu_item)
340 {
341   item.push_back(*pmenu_item);
342   delete pmenu_item;
343 }
344
345 void
346 Menu::clear()
347 {
348   item.clear();
349 }
350
351 /* Process actions done on the menu */
352 void
353 Menu::action()
354 {
355   hit_item = -1;
356   if(item.size() != 0)
357     {
358       switch(menuaction)
359         {
360         case MENU_ACTION_UP:
361           if (active_item > 0)
362             --active_item;
363           else
364             active_item = int(item.size())-1;
365           break;
366
367         case MENU_ACTION_DOWN:
368           if(active_item < int(item.size())-1)
369             ++active_item;
370           else
371             active_item = 0;
372           break;
373
374         case MENU_ACTION_LEFT:
375           if(item[active_item].kind == MN_STRINGSELECT
376               && item[active_item].list.first.size() != 0)
377             {
378               if(item[active_item].list.second != item[active_item].list.first.begin())
379                 --item[active_item].list.second;
380               else
381                 item[active_item].list.second = item[active_item].list.first.end();
382             }
383           break;
384
385         case MENU_ACTION_RIGHT:
386           if(item[active_item].kind == MN_STRINGSELECT
387               && item[active_item].list.first.size() != 0)
388             {
389               if(item[active_item].list.second != item[active_item].list.first.end())
390                 ++item[active_item].list.second;
391               else
392                 item[active_item].list.second = item[active_item].list.first.begin();
393             }
394           break;
395
396         case MENU_ACTION_HIT:
397           {
398             hit_item = active_item;
399             switch (item[active_item].kind)
400               {
401               case MN_GOTO:
402                 if (item[active_item].target_menu != NULL)
403                   Menu::push_current(item[active_item].target_menu);
404                 else
405                   puts("NULLL");
406                 break;
407
408               case MN_TOGGLE:
409                 item[active_item].toggled = !item[active_item].toggled;
410                 break;
411
412               case MN_ACTION:
413                 Menu::set_current(0);
414                 item[active_item].toggled = true;
415                 break;
416               case MN_TEXTFIELD:
417               case MN_NUMFIELD:
418                 menuaction = MENU_ACTION_DOWN;
419                 action();
420                 break;
421
422               case MN_BACK:
423                 Menu::pop_current();
424                 break;
425               default:
426                 break;
427               }
428           }
429           break;
430
431         case MENU_ACTION_REMOVE:
432           if(item[active_item].kind == MN_TEXTFIELD
433               || item[active_item].kind == MN_NUMFIELD)
434             {
435               if(item[active_item].input != NULL)
436                 {
437                   int i = strlen(item[active_item].input);
438
439                   while(delete_character > 0)   /* remove charactes */
440                     {
441                       item[active_item].input[i-1] = '\0';
442                       delete_character--;
443                     }
444                 }
445             }
446           break;
447
448         case MENU_ACTION_INPUT:
449           if(item[active_item].kind == MN_TEXTFIELD
450               || (item[active_item].kind == MN_NUMFIELD && mn_input_char >= '0' && mn_input_char <= '9'))
451             {
452               if(item[active_item].input != NULL)
453                 {
454                   int i = strlen(item[active_item].input);
455                   item[active_item].input = (char*) realloc(item[active_item].input,sizeof(char)*(i + 2));
456                   item[active_item].input[i] = mn_input_char;
457                   item[active_item].input[i+1] = '\0';
458                 }
459               else
460                 {
461                   item[active_item].input = (char*) malloc(2*sizeof(char));
462                   item[active_item].input[0] = mn_input_char;
463                   item[active_item].input[1] = '\0';
464                 }
465             }
466
467         case MENU_ACTION_NONE:
468           break;
469         }
470     }
471
472   MenuItem& new_item = item[active_item];
473   if(new_item.kind == MN_DEACTIVE
474       || new_item.kind == MN_LABEL
475       || new_item.kind == MN_HL)
476     {
477       // Skip the horzontal line item
478       if (menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN)
479         menuaction = MENU_ACTION_DOWN;
480
481       if (item.size() > 1)
482         action();
483     }
484
485   menuaction = MENU_ACTION_NONE;
486
487   if (active_item >= int(item.size()))
488     active_item = int(item.size()) - 1;
489 }
490
491 int
492 Menu::check()
493 {
494   if (hit_item != -1)
495     return item[hit_item].id;
496   else
497     return -1;
498 }
499
500 void
501 Menu::draw_item(DrawingContext& context,
502                 int index, // Position of the current item in the menu
503                 int menu_width, int menu_height)
504 {
505   MenuItem& pitem = item[index];
506
507   int effect_offset = 0;
508   {
509     int effect_time = 0;
510
511     if(effect.check())
512       effect_time = effect.get_left() / 4;
513
514     effect_offset = (index % 2) ? effect_time : -effect_time;
515   }
516
517   Font* text_font = default_font;
518   int x_pos       = pos_x;
519   int y_pos       = pos_y + 24*index - menu_height/2 + 12 + effect_offset;
520   int shadow_size = 2;
521   int text_width  = int(text_font->get_text_width(pitem.text));
522   int input_width = int(text_font->get_text_width(pitem.input) + 10);
523   int list_width = 0;
524   if(pitem.list.second != 0)
525   list_width = int(text_font->get_text_width((*pitem.list.second)));
526   
527   if (arrange_left)
528     x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2;
529
530   if(index == active_item)
531     {
532       shadow_size = 3;
533       text_font = active_font;
534     }
535
536   switch (pitem.kind)
537     {
538     case MN_DEACTIVE:
539       {
540         context.draw_text_center(deactive_font, pitem.text,
541                                  Vector(0, y_pos - int(deactive_font->get_height()/2)),
542                                  LAYER_GUI);
543         break;
544       }
545
546     case MN_HL:
547       {
548         // TODO
549         int x = pos_x - menu_width/2;
550         int y = y_pos - 12 - effect_offset;
551         /* Draw a horizontal line with a little 3d effect */
552         context.draw_filled_rect(Vector(x, y + 6),
553                                  Vector(menu_width, 4), Color(150,200,255,225), LAYER_GUI);
554         context.draw_filled_rect(Vector(x, y + 6),
555                                  Vector(menu_width, 2), Color(255,255,255,255), LAYER_GUI);
556         break;
557       }
558     case MN_LABEL:
559       {
560         context.draw_text_center(label_font,
561                                  pitem.text, Vector(0, y_pos - int(label_font->get_height()/2)),
562                                  LAYER_GUI);
563         break;
564       }
565     case MN_TEXTFIELD:
566     case MN_NUMFIELD:
567     case MN_CONTROLFIELD_KB:
568     case MN_CONTROLFIELD_JS:
569       {
570         int width = text_width + input_width + 5;
571         int text_pos = screen->w/2 - width/2;
572         int input_pos = text_pos + text_width + 10;
573
574         context.draw_filled_rect(
575           Vector(input_pos - 5, y_pos - 10),
576           Vector(input_width + 10, 20),
577           Color(255,255,255,255), LAYER_GUI-5);
578         context.draw_filled_rect(
579           Vector(input_pos - 4, y_pos - 9),
580           Vector(input_width + 8, 18),
581           Color(0,0,0,128), LAYER_GUI-4);
582
583         if(pitem.kind == MN_CONTROLFIELD_KB)
584           get_controlfield_key_into_input(&pitem);
585         else if (pitem.kind == MN_CONTROLFIELD_JS)
586           get_controlfield_js_into_input(&pitem);
587
588         if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
589           {
590             if(active_item == index)
591               context.draw_text(field_font,
592                                 pitem.get_input_with_symbol(true),
593                                 Vector(input_pos, y_pos - int(field_font->get_height()/2)),
594                                 LAYER_GUI);
595             else
596               context.draw_text(field_font,
597                                 pitem.get_input_with_symbol(false),
598                                 Vector(input_pos, y_pos - int(field_font->get_height()/2)),
599                                 LAYER_GUI);
600           }
601         else
602           context.draw_text(field_font, pitem.input,
603                             Vector(input_pos, y_pos - int(field_font->get_height()/2)),
604                             LAYER_GUI);
605
606         context.draw_text(text_font, pitem.text,
607                           Vector(text_pos, y_pos - int(text_font->get_height()/2)),
608                           LAYER_GUI);
609         break;
610       }
611     case MN_STRINGSELECT:
612       {
613         int list_pos_2 = list_width + 16;
614         int list_pos   = list_width/2;
615         int text_pos   = (text_width + 16)/2;
616
617         /* Draw arrows */
618         context.draw_surface(arrow_left,
619                              Vector(x_pos - list_pos + text_pos - 17, y_pos - 8),
620                              LAYER_GUI);
621         context.draw_surface(arrow_right,
622                              Vector(x_pos - list_pos + text_pos - 1 + list_pos_2, y_pos - 8),
623                              LAYER_GUI);
624
625         /* Draw input background */
626         context.draw_filled_rect(
627           Vector(x_pos - list_pos + text_pos - 1, y_pos - 10),
628           Vector(list_pos_2 + 2, 20),
629           Color(255,255,255,255), LAYER_GUI - 4);
630         context.draw_filled_rect(
631           Vector(x_pos - list_pos + text_pos, y_pos - 9),
632           Vector(list_pos_2, 18),
633           Color(0,0,0,128), LAYER_GUI - 5);
634
635         context.draw_text_center(text_font, (*pitem.list.second),
636                                  Vector(text_pos, y_pos - int(text_font->get_height()/2)),
637                                  LAYER_GUI);
638         context.draw_text_center(text_font, pitem.text,
639                                  Vector(list_pos_2/2, y_pos - int(text_font->get_height()/2)),
640                                  LAYER_GUI);
641         break;
642       }
643     case MN_BACK:
644       {
645         context.draw_text_center(text_font, pitem.text,
646                                  Vector(0, y_pos - int(text_font->get_height()/2)),
647                                  LAYER_GUI);
648         context.draw_surface(back,
649                              Vector(x_pos + text_width/2  + 16, y_pos - 8),
650                              LAYER_GUI);
651         break;
652       }
653
654     case MN_TOGGLE:
655       {
656         context.draw_text_center(text_font, pitem.text,
657                                  Vector(0, y_pos - (text_font->get_height()/2)),
658                                  LAYER_GUI);
659
660         if(pitem.toggled)
661           context.draw_surface(checkbox_checked,
662                                Vector(x_pos + (text_width+16)/2, y_pos - 8),
663                                LAYER_GUI + 1);
664         else
665           context.draw_surface(checkbox,
666                                Vector(x_pos + (text_width+16)/2, y_pos - 8),
667                                LAYER_GUI + 1);
668         break;
669       }
670     case MN_ACTION:
671       context.draw_text_center(text_font, pitem.text,
672                                Vector(0, y_pos - int(text_font->get_height()/2)),
673                                LAYER_GUI);
674       break;
675
676     case MN_GOTO:
677       context.draw_text_center(text_font, pitem.text,
678                                Vector(0, y_pos - int(text_font->get_height()/2)),
679                                LAYER_GUI);
680       break;
681     }
682 }
683
684 int Menu::get_width() const
685   {
686     /* The width of the menu has to be more than the width of the text
687        with the most characters */
688     int menu_width = 0;
689     for(unsigned int i = 0; i < item.size(); ++i)
690       {
691         int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0); //+ ((item[i].list.second != item[i].list.first.end()) ? (strlen((*(item[i].list.second)).c_str())) : 0);
692         if( w > menu_width )
693           {
694             menu_width = w;
695             if( item[i].kind == MN_TOGGLE)
696               menu_width += 2;
697           }
698       }
699
700     return (menu_width * 16 + 24);
701   }
702
703 int Menu::get_height() const
704   {
705     return item.size() * 24;
706   }
707
708 /* Draw the current menu. */
709 void
710 Menu::draw(DrawingContext& context)
711 {
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             if(MouseCursor::current())
892             MouseCursor::current()->set_state(MC_LINK);
893           }
894         else
895           {
896             if(MouseCursor::current())
897             MouseCursor::current()->set_state(MC_NORMAL);
898           }
899       }
900       break;
901
902     default:
903       break;
904     }
905 }
906
907
908 // EOF //