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