- Reworked Surface class and drawing stuff:
[supertux.git] / src / 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 #include <config.h>
20
21 #include <sys/types.h>
22 #include <ctype.h>
23
24 #include <iostream>
25 #include <sstream>
26 #include <cstdlib>
27 #include <cstdio>
28 #include <string>
29 #include <cassert>
30 #include <stdexcept>
31
32 #include "menu.hpp"
33 #include "video/screen.hpp"
34 #include "video/drawing_context.hpp"
35 #include "gettext.hpp"
36 #include "math/vector.hpp"
37 #include "main.hpp"
38 #include "resources.hpp"
39 #include "control/joystickkeyboardcontroller.hpp"
40
41 static const int MENU_REPEAT_INITIAL = 400;
42 static const int MENU_REPEAT_RATE = 200;
43 static const int FLICK_CURSOR_TIME = 500;
44
45 extern SDL_Surface* screen;
46
47 Surface* checkbox;
48 Surface* checkbox_checked;
49 Surface* back;
50 Surface* arrow_left;
51 Surface* arrow_right;
52
53 std::vector<Menu*> Menu::last_menus;
54 Menu* Menu::current_ = 0;
55 Font* Menu::default_font;
56 Font* Menu::active_font;
57 Font* Menu::deactive_font;
58 Font* Menu::label_font;
59 Font* Menu::field_font;
60
61 /* just displays a Yes/No text that can be used to confirm stuff */
62 bool confirm_dialog(Surface *background, std::string text)
63 {
64   //Surface* cap_screen = Surface::CaptureScreen();
65   Menu* dialog = new Menu;
66   dialog->add_deactive(-1, text);
67   dialog->add_hl();
68   dialog->add_entry(true, _("Yes"));
69   dialog->add_entry(false, _("No"));
70   dialog->add_hl();
71   
72   Menu::set_current(dialog);
73
74   DrawingContext context;
75
76   while(true)
77     {
78       SDL_Event event;
79       while (SDL_PollEvent(&event)) {
80         if(event.type == SDL_QUIT)
81           throw std::runtime_error("received window close event");
82         main_controller->process_event(event);
83         dialog->event(event);
84       }
85
86       if(background == NULL)
87         context.draw_gradient(Color(0.8, 0.95, 0.85), Color(0.8, 0.8, 0.8),
88                               LAYER_BACKGROUND0);
89       else
90         context.draw_surface(background, Vector(0,0), LAYER_BACKGROUND0);
91
92       dialog->draw(context);
93       dialog->update();
94
95       switch (dialog->check())
96         {
97         case true:
98           //delete cap_screen;
99           Menu::set_current(0);
100           delete dialog;
101           return true;
102           break;
103         case false:
104           //delete cap_screen;
105           Menu::set_current(0);
106           delete dialog;
107           return false;
108           break;
109         default:
110           break;
111         }
112
113       mouse_cursor->draw(context);
114       context.do_drawing();
115       SDL_Delay(25);
116     }
117
118   return false;
119 }
120
121 void
122 Menu::push_current(Menu* pmenu)
123 {
124   if (current_)
125     last_menus.push_back(current_);
126
127   current_ = pmenu;
128   current_->effect_ticks = SDL_GetTicks();
129 }
130
131 void
132 Menu::pop_current()
133 {
134   if (last_menus.size() >= 1) {
135     current_ = last_menus.back();
136     current_->effect_ticks = SDL_GetTicks();
137     last_menus.pop_back();
138   } else {
139     current_ = 0;
140   }
141 }
142
143 void
144 Menu::set_current(Menu* menu)
145 {
146   last_menus.clear();
147
148   if (menu)
149     menu->effect_ticks = SDL_GetTicks();
150
151   current_ = menu;
152   // just to be sure...
153   main_controller->reset();
154 }
155
156 MenuItem::MenuItem(MenuItemKind _kind, int _id)
157   : kind(_kind) , id(_id)
158 {
159   toggled = false;
160   selected = false;
161   target_menu = 0;
162 }
163
164 void
165 MenuItem::change_text(const  std::string& text_)
166 {
167   text = text_;
168 }
169
170 void
171 MenuItem::change_input(const  std::string& text_)
172 {
173   input = text_;
174 }
175
176 std::string MenuItem::get_input_with_symbol(bool active_item)
177 {
178   if(!active_item) {
179     input_flickering = true;
180   } else {
181     input_flickering = (SDL_GetTicks() / FLICK_CURSOR_TIME) % 2;
182   }
183
184   char str[1024];
185   if(input_flickering)
186     sprintf(str,"%s ",input.c_str());
187   else
188     sprintf(str,"%s_",input.c_str());
189
190   std::string string = str;
191
192   return string;
193 }
194
195 Menu::~Menu()
196 {
197   for(std::vector<MenuItem*>::iterator i = items.begin();
198       i != items.end(); ++i)
199     delete *i;
200 }
201
202 Menu::Menu()
203 {
204   hit_item = -1;
205   menuaction = MENU_ACTION_NONE;
206   delete_character = 0;
207   mn_input_char = '\0';
208
209   pos_x        = SCREEN_WIDTH/2;
210   pos_y        = SCREEN_HEIGHT/2;
211   arrange_left = 0;
212   active_item  = -1;
213 }
214
215 void Menu::set_pos(int x, int y, float rw, float rh)
216 {
217   pos_x = x + (int)((float)get_width() * rw);
218   pos_y = y + (int)((float)get_height() * rh);
219 }
220
221 /* Add an item to a menu */
222 void
223 Menu::additem(MenuItem* item)
224 {
225   items.push_back(item);
226
227   /* If a new menu is being built, the active item shouldn't be set to
228    * something that isnt selectable. Set the active_item to the first
229    * selectable item added
230    */
231   if (active_item == -1
232       && item->kind != MN_HL 
233       && item->kind != MN_LABEL
234       && item->kind != MN_DEACTIVE) {
235     active_item = items.size() - 1;
236   }
237 }
238
239 void
240 Menu::add_hl()
241 {
242   additem(new MenuItem(MN_HL));
243 }
244
245 void
246 Menu::add_label(const std::string& text)
247 {
248   MenuItem* item = new MenuItem(MN_LABEL);
249   item->text = text;
250   additem(item);
251 }
252
253 void
254 Menu::add_controlfield(int id, const std::string& text,
255                 const std::string& mapping)
256 {
257   MenuItem* item = new MenuItem(MN_CONTROLFIELD, id);
258   item->change_text(text);
259         item->change_input(mapping);
260   additem(item);
261 }
262
263 void
264 Menu::add_entry(int id, const std::string& text)
265 {
266   MenuItem* item = new MenuItem(MN_ACTION, id);
267   item->text = text;
268   additem(item);
269 }
270
271 void
272 Menu::add_deactive(int id, const std::string& text)
273 {
274   MenuItem* item = new MenuItem(MN_DEACTIVE, id);
275   item->text = text;
276   additem(item);
277 }
278
279 void
280 Menu::add_toggle(int id, const std::string& text, bool toogled)
281 {
282   MenuItem* item = new MenuItem(MN_TOGGLE, id);
283   item->text = text;
284   item->toggled = toogled;
285   additem(item);
286 }
287
288 void
289 Menu::add_back(const std::string& text)
290 {
291   MenuItem* item = new MenuItem(MN_BACK);
292   item->text = text;
293   additem(item);
294 }
295
296 void
297 Menu::add_submenu(const std::string& text, Menu* submenu, int id)
298 {
299   MenuItem* item = new MenuItem(MN_GOTO, id);
300   item->text = text;
301   item->target_menu = submenu;
302   additem(item);
303 }
304
305 void
306 Menu::clear()
307 {
308   for(std::vector<MenuItem*>::iterator i = items.begin();
309       i != items.end(); ++i) {
310     delete *i;
311   }
312   items.clear();
313   active_item = -1;
314 }
315
316 /* Process actions done on the menu */
317 void
318 Menu::update()
319 {
320   /** check main input controller... */
321   Uint32 ticks = SDL_GetTicks();
322   if(main_controller->pressed(Controller::UP)) {
323     menuaction = MENU_ACTION_UP;
324     menu_repeat_ticks = ticks + MENU_REPEAT_INITIAL;
325   }
326   if(main_controller->hold(Controller::UP) && 
327       menu_repeat_ticks != 0 && ticks > menu_repeat_ticks) {
328     menuaction = MENU_ACTION_UP;
329     menu_repeat_ticks = ticks + MENU_REPEAT_RATE;
330   } 
331   if(main_controller->pressed(Controller::DOWN)) {
332     menuaction = MENU_ACTION_DOWN;
333     menu_repeat_ticks = ticks + MENU_REPEAT_INITIAL;
334   }
335   if(main_controller->hold(Controller::DOWN) && 
336       menu_repeat_ticks != 0 && ticks > menu_repeat_ticks) {
337     menuaction = MENU_ACTION_DOWN;
338     menu_repeat_ticks = ticks + MENU_REPEAT_RATE;
339   }
340   if(main_controller->pressed(Controller::JUMP)
341      || main_controller->pressed(Controller::ACTION)
342      || main_controller->pressed(Controller::MENU_SELECT)) {
343     menuaction = MENU_ACTION_HIT;
344   }
345   if(main_controller->pressed(Controller::PAUSE_MENU)) {
346     menuaction = MENU_ACTION_BACK;
347   }
348
349   hit_item = -1;
350   if(items.size() == 0)
351     return;
352   
353   int last_active_item = active_item;
354   switch(menuaction) {
355     case MENU_ACTION_UP:
356       do {
357         if (active_item > 0)
358           --active_item;
359         else
360           active_item = int(items.size())-1;
361       } while ((items[active_item]->kind == MN_HL 
362                 || items[active_item]->kind == MN_LABEL
363                 || items[active_item]->kind == MN_DEACTIVE)
364                && (active_item != last_active_item));
365       
366       break;
367       
368     case MENU_ACTION_DOWN:
369       do {
370         if(active_item < int(items.size())-1 )
371           ++active_item;
372         else
373           active_item = 0;
374       } while ((items[active_item]->kind == MN_HL
375                 || items[active_item]->kind == MN_LABEL
376                 || items[active_item]->kind == MN_DEACTIVE)
377                && (active_item != last_active_item));
378       
379       break;
380       
381     case MENU_ACTION_LEFT:
382       if(items[active_item]->kind == MN_STRINGSELECT) {
383         if(items[active_item]->selected > 0)
384           items[active_item]->selected--;
385         else
386           items[active_item]->selected = items[active_item]->list.size()-1;
387       }
388       break;
389       
390     case MENU_ACTION_RIGHT:
391       if(items[active_item]->kind == MN_STRINGSELECT) {
392         if(items[active_item]->selected+1 < items[active_item]->list.size())
393           items[active_item]->selected++;
394         else
395           items[active_item]->selected = 0;
396       }
397       break;
398       
399     case MENU_ACTION_HIT: {
400       hit_item = active_item;
401       switch (items[active_item]->kind) {
402         case MN_GOTO:
403           assert(items[active_item]->target_menu != 0);
404           Menu::push_current(items[active_item]->target_menu);
405           break;
406           
407         case MN_TOGGLE:
408           items[active_item]->toggled = !items[active_item]->toggled;
409           menu_action(items[active_item]);
410           break;
411           
412         case MN_CONTROLFIELD:
413           menu_action(items[active_item]);
414           break;
415           
416         case MN_ACTION:
417           menu_action(items[active_item]);
418           break;
419           
420         case MN_TEXTFIELD:
421         case MN_NUMFIELD:
422           menuaction = MENU_ACTION_DOWN;
423           update();
424           break;
425           
426         case MN_BACK:
427           Menu::pop_current();
428           break;
429         default:
430           break;
431       }
432       break;
433     }
434     
435     case MENU_ACTION_REMOVE:
436       if(items[active_item]->kind == MN_TEXTFIELD
437          || items[active_item]->kind == MN_NUMFIELD)
438       {
439         if(!items[active_item]->input.empty())
440         {
441           int i = items[active_item]->input.size();
442           
443           while(delete_character > 0)   /* remove charactes */
444           {
445             items[active_item]->input.resize(i-1);
446             delete_character--;
447           }
448         }
449       }
450       break;
451       
452     case MENU_ACTION_INPUT:
453       if(items[active_item]->kind == MN_TEXTFIELD
454          || (items[active_item]->kind == MN_NUMFIELD 
455              && mn_input_char >= '0' && mn_input_char <= '9'))
456       {
457         items[active_item]->input.push_back(mn_input_char);
458       }
459       break;
460       
461     case MENU_ACTION_BACK:
462       Menu::pop_current();
463       break;
464
465     case MENU_ACTION_NONE:
466       break;
467   }
468   menuaction = MENU_ACTION_NONE;
469
470   assert(active_item < int(items.size()));
471 }
472
473 int
474 Menu::check()
475 {
476   if (hit_item != -1)
477     return items[hit_item]->id;
478   else
479     return -1;
480 }
481
482 void
483 Menu::menu_action(MenuItem* )
484 {}
485
486 void
487 Menu::draw_item(DrawingContext& context, int index)
488 {
489   int menu_height = get_height();
490   int menu_width = get_width();  
491
492   MenuItem& pitem = *(items[index]);
493
494   int effect_offset = 0;
495   if(effect_ticks != 0) {
496     if(SDL_GetTicks() - effect_ticks > 500) {
497       effect_ticks = 0;
498     } else {
499       Uint32 effect_time = (500 - (SDL_GetTicks() - effect_ticks)) / 4;
500       effect_offset = (index % 2) ? effect_time : -effect_time;
501     }
502   }
503
504   Font* text_font = default_font;
505   int x_pos       = pos_x;
506   int y_pos       = pos_y + 24*index - menu_height/2 + 12 + effect_offset;
507   int shadow_size = 2;
508   int text_width  = int(text_font->get_text_width(pitem.text));
509   int input_width = int(text_font->get_text_width(pitem.input) + 10);
510   int list_width = 0;
511   if(pitem.list.size() > 0) {
512     list_width = (int) text_font->get_text_width(pitem.list[pitem.selected]);
513   }
514   
515   if (arrange_left)
516     x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2;
517
518   if(index == active_item)
519     {
520       shadow_size = 3;
521       text_font = active_font;
522     }
523
524   switch (pitem.kind)
525     {
526     case MN_DEACTIVE:
527       {
528         context.draw_text(deactive_font, pitem.text,
529                           Vector(SCREEN_WIDTH/2, y_pos - int(deactive_font->get_height()/2)),
530                           CENTER_ALLIGN, LAYER_GUI);
531         break;
532       }
533
534     case MN_HL:
535       {
536         // TODO
537         int x = pos_x - menu_width/2;
538         int y = y_pos - 12 - effect_offset;
539         /* Draw a horizontal line with a little 3d effect */
540         context.draw_filled_rect(Vector(x, y + 6),
541                                  Vector(menu_width, 4),
542                                  Color(0.6f, 0.7f, 1.0f, 1.0f), LAYER_GUI);
543         context.draw_filled_rect(Vector(x, y + 6),
544                                  Vector(menu_width, 2),
545                                  Color(1.0f, 1.0f, 1.0f, 1.0f), LAYER_GUI);
546         break;
547       }
548     case MN_LABEL:
549       {
550         context.draw_text(label_font, pitem.text,
551                           Vector(SCREEN_WIDTH/2, y_pos - int(label_font->get_height()/2)),
552                           CENTER_ALLIGN, LAYER_GUI);
553         break;
554       }
555     case MN_TEXTFIELD:
556     case MN_NUMFIELD:
557     case MN_CONTROLFIELD:
558       {
559         int width = text_width + input_width + 5;
560         int text_pos = SCREEN_WIDTH/2 - width/2;
561         int input_pos = text_pos + text_width + 10;
562
563         context.draw_filled_rect(
564           Vector(input_pos - 5, y_pos - 10),
565           Vector(input_width + 10, 20),
566           Color(1.0f, 1.0f, 1.0f, 1.0f), LAYER_GUI-5);
567         context.draw_filled_rect(
568           Vector(input_pos - 4, y_pos - 9),
569           Vector(input_width + 8, 18),
570           Color(0, 0, 0, 0.5f), LAYER_GUI-4);
571
572         if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
573           {
574             if(active_item == index)
575               context.draw_text(field_font,
576                                 pitem.get_input_with_symbol(true),
577                                 Vector(input_pos, y_pos - int(field_font->get_height()/2)),
578                                 LEFT_ALLIGN, LAYER_GUI);
579             else
580               context.draw_text(field_font,
581                                 pitem.get_input_with_symbol(false),
582                                 Vector(input_pos, y_pos - int(field_font->get_height()/2)),
583                                 LEFT_ALLIGN, LAYER_GUI);
584           }
585         else
586           context.draw_text(field_font, pitem.input,
587                             Vector(input_pos, y_pos - int(field_font->get_height()/2)),
588                             LEFT_ALLIGN, LAYER_GUI);
589
590         context.draw_text(text_font, pitem.text,
591                           Vector(text_pos, y_pos - int(text_font->get_height()/2)),
592                           LEFT_ALLIGN, LAYER_GUI);
593         break;
594       }
595     case MN_STRINGSELECT:
596       {
597         int list_pos_2 = list_width + 16;
598         int list_pos   = list_width/2;
599         int text_pos   = (text_width + 16)/2;
600
601         /* Draw arrows */
602         context.draw_surface(arrow_left,
603                              Vector(x_pos - list_pos + text_pos - 17, y_pos - 8),
604                              LAYER_GUI);
605         context.draw_surface(arrow_right,
606                              Vector(x_pos - list_pos + text_pos - 1 + list_pos_2, y_pos - 8),
607                              LAYER_GUI);
608
609         /* Draw input background */
610         context.draw_filled_rect(
611           Vector(x_pos - list_pos + text_pos - 1, y_pos - 10),
612           Vector(list_pos_2 + 2, 20),
613           Color(1.0f, 1.0f, 1.0f, 1.0f), LAYER_GUI - 4);
614         context.draw_filled_rect(
615           Vector(x_pos - list_pos + text_pos, y_pos - 9),
616           Vector(list_pos_2, 18),
617           Color(0, 0, 0, 0.5f), LAYER_GUI - 5);
618
619         context.draw_text(text_font, pitem.list[pitem.selected],
620                                  Vector(SCREEN_WIDTH/2 + text_pos, y_pos - int(text_font->get_height()/2)),
621                                  CENTER_ALLIGN, LAYER_GUI);
622         context.draw_text(text_font, pitem.text,
623                                  Vector(SCREEN_WIDTH/2  + list_pos_2/2, y_pos - int(text_font->get_height()/2)),
624                                  CENTER_ALLIGN, LAYER_GUI);
625         break;
626       }
627     case MN_BACK:
628       {
629         context.draw_text(text_font, pitem.text,
630                           Vector(SCREEN_WIDTH/2, y_pos - int(text_font->get_height()/2)),
631                           CENTER_ALLIGN, LAYER_GUI);
632         context.draw_surface(back,
633                              Vector(x_pos + text_width/2  + 16, y_pos - 8),
634                              LAYER_GUI);
635         break;
636       }
637
638     case MN_TOGGLE:
639       {
640         context.draw_text(text_font, pitem.text,
641                           Vector(SCREEN_WIDTH/2, y_pos - (text_font->get_height()/2)),
642                           CENTER_ALLIGN, LAYER_GUI);
643
644         if(pitem.toggled)
645           context.draw_surface(checkbox_checked,
646                                Vector(x_pos + (text_width+16)/2, y_pos - 8),
647                                LAYER_GUI + 1);
648         else
649           context.draw_surface(checkbox,
650                                Vector(x_pos + (text_width+16)/2, y_pos - 8),
651                                LAYER_GUI + 1);
652         break;
653       }
654     case MN_ACTION:
655       context.draw_text(text_font, pitem.text,
656                         Vector(SCREEN_WIDTH/2, y_pos - int(text_font->get_height()/2)),
657                         CENTER_ALLIGN, LAYER_GUI);
658       break;
659
660     case MN_GOTO:
661       context.draw_text(text_font, pitem.text,
662                         Vector(SCREEN_WIDTH/2, y_pos - int(text_font->get_height()/2)),
663                         CENTER_ALLIGN, LAYER_GUI);
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 < items.size(); ++i)
674       {
675         int w = items[i]->text.size() + items[i]->input.size() + 1;
676         if(w > menu_width)
677           {
678             menu_width = w;
679             if( items[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 items.size() * 24;
690   }
691
692 /* Draw the current menu. */
693 void
694 Menu::draw(DrawingContext& context)
695 {
696   if(MouseCursor::current()) {
697     MouseCursor::current()->draw(context);
698   }
699   
700   int menu_height = get_height();
701   int menu_width = get_width();  
702
703   /* Draw a transparent background */
704   context.draw_filled_rect(
705     Vector(pos_x - menu_width/2, pos_y - 24*items.size()/2 - 10),
706     Vector(menu_width,menu_height + 20),
707     Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI-10);
708
709   for(unsigned int i = 0; i < items.size(); ++i)
710     {
711       draw_item(context, i);
712     }
713 }
714
715 MenuItem&
716 Menu::get_item_by_id(int id)
717 {
718   for(std::vector<MenuItem*>::iterator i = items.begin();
719       i != items.end(); ++i) {
720     MenuItem& item = **i;
721     
722     if(item.id == id)
723       return item;
724   }
725
726   throw std::runtime_error("MenuItem not found");
727 }
728
729 const MenuItem&
730 Menu::get_item_by_id(int id) const
731 {
732   for(std::vector<MenuItem*>::const_iterator i = items.begin();
733       i != items.end(); ++i) {
734     const MenuItem& item = **i;
735     
736     if(item.id == id)
737       return item;
738   }
739
740   throw std::runtime_error("MenuItem not found");
741 }
742
743 int Menu::get_active_item_id()
744 {
745   return items[active_item]->id;
746 }
747
748 bool
749 Menu::is_toggled(int id) const
750 {
751   return get_item_by_id(id).toggled;
752 }
753
754 /* Check for menu event */
755 void
756 Menu::event(const SDL_Event& event)
757 {
758   if(effect_ticks != 0)
759     return;
760
761   switch(event.type) {
762     case SDL_MOUSEBUTTONDOWN:
763       {
764         int x = int(event.motion.x * float(SCREEN_WIDTH)/screen->w);
765         int y = int(event.motion.y * float(SCREEN_HEIGHT)/screen->h);
766
767         if(x > pos_x - get_width()/2 &&
768             x < pos_x + get_width()/2 &&
769             y > pos_y - get_height()/2 &&
770             y < pos_y + get_height()/2)
771           {
772             menuaction = MENU_ACTION_HIT;
773           }
774       }
775       break;
776
777     case SDL_MOUSEMOTION:
778       {
779         int x = int(event.motion.x * float(SCREEN_WIDTH)/screen->w);
780         int y = int(event.motion.y * float(SCREEN_HEIGHT)/screen->h);
781
782         if(x > pos_x - get_width()/2 &&
783             x < pos_x + get_width()/2 &&
784             y > pos_y - get_height()/2 &&
785             y < pos_y + get_height()/2)
786           {
787             int new_active_item = (y - (pos_y - get_height()/2)) / 24;
788           
789             /* only change the mouse focus to a selectable item */
790             if ((items[new_active_item]->kind != MN_HL)
791                 && (items[new_active_item]->kind != MN_LABEL)
792                 && (items[new_active_item]->kind != MN_DEACTIVE))
793               active_item = new_active_item;
794             
795             if(MouseCursor::current())
796               MouseCursor::current()->set_state(MC_LINK);
797           }
798         else
799         {
800           if(MouseCursor::current())
801             MouseCursor::current()->set_state(MC_NORMAL);
802         }
803       }
804       break;
805
806     default:
807       break;
808     }
809 }
810
811 void
812 Menu::set_active_item(int id)
813 {
814   for(size_t i = 0; i < items.size(); ++i) {
815     MenuItem* item = items[i];
816     if(item->id == id) {
817       active_item = i;
818       break;
819     }
820   }
821 }