home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / Menu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-18  |  16.0 KB  |  734 lines

  1. #include "Menu.h"
  2.  
  3. #include "Gui.h"
  4.  
  5. #include "Input.h"
  6. #include "texfont.h"
  7. #include "SoundInfo.h"
  8. //#include "Sound.h"
  9. #include "Renderer.h"
  10. #include "ConsoleFrontEnd.h"
  11. #include "System.h"
  12. #include "Display.h"
  13.  
  14. #define MENU_FONT_SCALE    ( 0.5f ) 
  15.  
  16.  
  17. Mix_Chunk* Menu::pressButtonSound = NULL;
  18. Mix_Chunk* Menu::toggleSound = NULL;
  19. Mix_Chunk* Menu::errorSound = NULL;
  20.  
  21.  
  22. MenuItem::MenuItem(int x, int y, int width, int height){
  23.     this->x = x;
  24.     this->y = y;
  25.     this->width = width;
  26.     this->height = height;
  27.  
  28.     highlighted=false;
  29.     hasKeyboardFocus = false;
  30.     active=true;
  31. }
  32.  
  33. MenuItem::~MenuItem(){
  34. }
  35.  
  36. void MenuItem::activate(){
  37.     active=true;
  38. }
  39.  
  40. void MenuItem::deactivate(){
  41.     active=false;
  42. }
  43.  
  44. bool MenuItem::isActive(){
  45.     return active;
  46. }
  47.  
  48. void MenuItem::draw(){
  49. }
  50.  
  51. void MenuItem::clicked(){
  52. }
  53.  
  54. void MenuItem::clickedRight(){
  55. }
  56.  
  57. void MenuItem::receiveKey(SDL_keysym* keysym){
  58. }
  59.  
  60.  
  61. TextButton::TextButton(int x, int y, int width, int height, const char* label):MenuItem(x,y,width, height){
  62.     this->label = label;
  63.  
  64.     callback=NULL;
  65. }
  66.  
  67. TextButton::TextButton(int x, int y, const char* label):MenuItem(0,0,0,0){
  68.     this->x = x;
  69.     this->y = y;
  70.     this->label = label;
  71.  
  72.     width = (int)(getStringWidth(Gui::info.var.menu_bigFont, label)*MENU_FONT_SCALE);
  73.     height = (int)(Gui::info.var.menu_bigFont->height*MENU_FONT_SCALE);
  74.  
  75.     callback=NULL;
  76. }
  77.  
  78. TextButton::~TextButton(){
  79. }
  80.  
  81. void TextButton::draw(){
  82.     if(active){
  83.         if(!highlighted)
  84.             glColor4fv(Gui::info.var.menu_normalColor);
  85.         else
  86.             glColor4fv(Gui::info.var.menu_activeColor);
  87.     }else{
  88.         glColor4fv(Gui::info.var.menu_passiveColor);
  89.     }
  90.  
  91.     glBegin(GL_LINE_LOOP);
  92.         glVertex2i(x, y);
  93.         glVertex2i(x+width, y);
  94.         glVertex2i(x+width, y+height);
  95.         glVertex2i(x, y+height);
  96.     glEnd();
  97.  
  98.     //drawScaledAndAlignedString(MENU_POS_SCALE_X(x+width/2), MENU_POS_SCALE_Y(y), labelScaleX, labelScaleY, Gui::info.var.menu_bigFont, TEXT_ALIGN_CENTER, label);
  99.     drawScaledAndAlignedString(x+width/2, y, MENU_FONT_SCALE, MENU_FONT_SCALE, Gui::info.var.menu_bigFont, TEXT_ALIGN_CENTER, label);
  100. }
  101.  
  102. void TextButton::clicked(){
  103.     if(Sound::info.var.enabled && Sound::info.var.playSamples)
  104.         Sound::playSample(SOUND_COMPUTER_CHANNEL, Menu::pressButtonSound);
  105.  
  106.     if(callback!=NULL)
  107.         callback();
  108. }
  109.  
  110. void TextButton::clickedRight(){
  111.     clicked();
  112. }
  113.  
  114. void TextButton::setCallbackFunction(void (*func)(void)){
  115.     callback=func;
  116. }
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. ToggleButton::ToggleButton(int x, int y, const char** items, int numItems, const char* label):MenuItem(x, y, 0, 0){
  125.     this->width = (int)(getStringWidth(Gui::info.var.menu_smallFont, label)*1.0f);
  126.     this->height = (int)(Gui::info.var.menu_smallFont->height*1.0f);
  127.     this->label = label;
  128.  
  129.     this->items = items;
  130.     this->numItems = numItems;
  131.     this->index = 0;
  132.  
  133.     int maxWidth = 0;
  134.     for(int i = 0; i < numItems; i++){
  135.         int w = (int)( getStringWidth(Gui::info.var.menu_smallFont, items[i])*1.0f );
  136.         maxWidth = w > maxWidth ? w : maxWidth;
  137.         //printf("string %i: %s\n", i, items[i]);
  138.     }
  139.     this->width += maxWidth;
  140. }
  141.  
  142.  
  143. ToggleButton::~ToggleButton(){
  144. }
  145.  
  146. void ToggleButton::draw(){
  147.     if(active){
  148.         if(!highlighted)
  149.             glColor4fv(Gui::info.var.menu_normalColor);
  150.         else
  151.             glColor4fv(Gui::info.var.menu_activeColor);
  152.     }else{
  153.         glColor4fv(Gui::info.var.menu_passiveColor);
  154.     }
  155.  
  156.     drawScaledFormatString(x,y,1.0f, 1.0f,Gui::info.var.menu_smallFont, "%s%s", label, items[index]);
  157. }
  158.  
  159. void ToggleButton::clicked(){
  160.     if(Sound::info.var.enabled && Sound::info.var.playSamples)
  161.         Sound::playSample(SOUND_COMPUTER_CHANNEL, Menu::toggleSound);
  162.  
  163.     index = (index+1) % numItems;
  164. }
  165.  
  166. void ToggleButton::clickedRight(){
  167.     if(Sound::info.var.enabled && Sound::info.var.playSamples)
  168.         Sound::playSample(SOUND_COMPUTER_CHANNEL, Menu::toggleSound);
  169.  
  170.     index = (index-1) < 0 ? numItems-1 : (index-1);
  171. }
  172.  
  173. const char* ToggleButton::getSelectedItem(){
  174.     return items[index];
  175. }
  176. int ToggleButton::getIndex(){
  177.     return index;
  178. }
  179. void ToggleButton::setIndex(int newIndex){
  180.     if(newIndex >= 0 && newIndex < numItems){
  181.         this->index = newIndex;
  182.     }
  183. }
  184.  
  185. void ToggleButton::changeItems(const char** newItems, int newNumItems){
  186.     this->items = newItems;
  187.     this->numItems = newNumItems;
  188.     this->index = 0;
  189.  
  190.     int maxWidth = 0;
  191.     for(int i = 0; i < numItems; i++){
  192.         int w = (int)( getStringWidth(Gui::info.var.menu_smallFont, items[i])*1.0f );
  193.         maxWidth = w > maxWidth ? w : maxWidth;
  194.         //printf("string %i: %s\n", i, items[i]);
  195.     }
  196.     this->width = (int)( getStringWidth(Gui::info.var.menu_smallFont, label)*1.0f + maxWidth );
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208. Textfield::Textfield(int x, int y, int minChars, int maxChars, const char* label):MenuItem(x, y, 0, 0){
  209.     this->width = (int)(getStringWidth(Gui::info.var.menu_smallFont, label)*1.0f);
  210.     this->height = (int)(Gui::info.var.menu_smallFont->height*1.0f);
  211.     this->label = label;
  212.  
  213.     this->minChars = minChars;
  214.     this->maxChars = maxChars;
  215.  
  216.     this->inputStrIndex = 0;
  217.     this->inputStr[0] = '\0';
  218. }
  219.  
  220.  
  221. Textfield::~Textfield(){
  222. }
  223.  
  224. void Textfield::draw(){
  225.     if(active){
  226.         if(!highlighted)
  227.             glColor4fv(Gui::info.var.menu_normalColor);
  228.         else
  229.             glColor4fv(Gui::info.var.menu_activeColor);
  230.     }else{
  231.         glColor4fv(Gui::info.var.menu_passiveColor);
  232.     }
  233.  
  234.     if(hasKeyboardFocus){
  235.         drawScaledFormatString(x,y,1.0f, 1.0f,Gui::info.var.menu_smallFont, "%s%s", label, inputStr);
  236.         if((SDL_GetTicks()/500)%2){
  237.             char buff[CON_MAX_STRING_LENGTH];
  238.             strncpy(buff, inputStr, inputStrIndex);
  239.             buff[inputStrIndex] = '\0';
  240.             float xOffs = (getStringWidth(Gui::info.var.menu_smallFont, label)+getStringWidth(Gui::info.var.menu_smallFont, buff))*1.0f;
  241.             drawScaledString(x+(int)xOffs, y, 1.0f, 1.0f, Gui::info.var.menu_smallFont, "_");
  242.         }
  243.     }else{
  244.         drawScaledFormatString(x,y,1.0f, 1.0f,Gui::info.var.menu_smallFont, "%s%s", label, text);
  245.     }
  246.  
  247.     this->width = (int)( getStringWidth(Gui::info.var.menu_smallFont, label) + getStringWidth(Gui::info.var.menu_smallFont, text)*1.0f );
  248. }
  249.  
  250. void Textfield::clicked(){
  251.     if(Sound::info.var.enabled && Sound::info.var.playSamples)
  252.         Sound::playSample(SOUND_COMPUTER_CHANNEL, Menu::toggleSound);
  253.  
  254.     strcpy(inputStr, text);
  255.     inputStrIndex = strlen(inputStr);
  256.     SDL_EnableUNICODE(1);
  257.     SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
  258. //    hasKeyboardFocus = true;
  259. }
  260.  
  261. void Textfield::clickedRight(){
  262. }
  263.  
  264.  
  265. void Textfield::receiveKey(SDL_keysym* keysym){
  266.     int i;
  267.     SDLKey key=keysym->sym;
  268.  
  269.     if(key==SDLK_ESCAPE){
  270.         //deactivate();
  271.         strcpy(inputStr, text);
  272.         hasKeyboardFocus = false;
  273.         SDL_EnableUNICODE(0);
  274.         SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
  275.     }else if(key==SDLK_RIGHT){
  276.         if(inputStr[inputStrIndex]!='\0'){
  277.             inputStrIndex++;
  278.         }
  279.     }else if(key==SDLK_LEFT){
  280.         if(inputStrIndex>0){
  281.             inputStrIndex--;
  282.         }
  283.     }else if(key==SDLK_HOME && !(keysym->mod & KMOD_CTRL) ){
  284.         inputStrIndex=0;
  285.     }else if(key==SDLK_END && !(keysym->mod & KMOD_CTRL) ){
  286.         inputStrIndex=strlen(inputStr);
  287.     }else if(key==SDLK_RETURN){    // enter
  288.         // tja...
  289. //        inputStr[inputStrIndex] = '\0';
  290.         if(strlen(inputStr) >= (unsigned int)minChars && strlen(inputStr) <= (unsigned int)maxChars){
  291.             strcpy(text, inputStr);
  292.         }else{
  293.             strcpy(inputStr, text);
  294.         }
  295.         hasKeyboardFocus = false;
  296.         SDL_EnableUNICODE(0);
  297.         SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
  298.     }else if(key==SDLK_BACKSPACE){    // backspace
  299.         if(inputStrIndex<=0)
  300.             return;
  301.  
  302.         i=inputStrIndex-1;
  303.         while(inputStr[i]!='\0'){
  304.             inputStr[i]=inputStr[i+1];
  305.             i++;
  306.         }
  307.         inputStrIndex-=1;
  308.     }else if(key==SDLK_DELETE){    // del
  309.         if(inputStr[inputStrIndex]=='\0')
  310.             return;
  311.  
  312.         i=inputStrIndex;
  313.         while(inputStr[i]!='\0'){
  314.             inputStr[i]=inputStr[i+1];
  315.             i++;
  316.         }
  317.     }else{        // add char to inputStr
  318.         int l=strlen(inputStr);
  319.         if(l < CON_MAX_STRING_LENGTH && l < maxChars){
  320.             char ch;
  321.             if ( (keysym->unicode & 0xFF80) == 0 && keysym->unicode!=0) {
  322.                 ch = keysym->unicode & 0x7F;
  323.                 for(i=l+1;i>inputStrIndex;i--){
  324.                     inputStr[i]=inputStr[i-1];
  325.                 }
  326.  
  327.                 inputStr[inputStrIndex]=ch;
  328.                 inputStrIndex++;
  329.                 //inputStr[inputStrIndex]='\0';
  330.                 //inputStrIndex = inputStrIndex >= CON_MAX_LINE_LENGTH-1 ? CON_MAX_LINE_LENGTH-1 : inputStrIndex+1;
  331.             }else{
  332. //                warn("(in ConsoleFrontEnd::recieveKey()): unicode of key not known!\n\n");
  333.             }
  334.         }
  335.     }
  336.  
  337. }
  338.  
  339. char* Textfield::getText(){
  340.     return text;
  341. }
  342.  
  343. void Textfield::setText(const char* newText){
  344.     if(strlen(newText) >= (unsigned int)minChars && strlen(newText) <= (unsigned int)maxChars)
  345.         strcpy(this->text, newText);
  346. }
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361. Menu::Menu(const char* name){
  362.     int i;
  363.  
  364.     this->name=name;
  365.  
  366.     for(i=0;i<MENU_MAX_SUBMENUS;i++){
  367.         submenus[i]=NULL;
  368.     }
  369.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  370.         menuItems[i]=NULL;
  371.     }
  372.  
  373.     opened=false;
  374.     allowConsole=false;
  375. }
  376.  
  377. Menu::~Menu(){
  378.     int i;
  379. /*
  380.     for(i=0;i<MENU_MAX_SUBMENUS;i++){
  381.         if(submenus[i]!=NULL)
  382.             delete submenus[i];
  383.     }
  384. */
  385.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  386.         if(menuItems[i]!=NULL)
  387.             delete menuItems[i];
  388.     }
  389.  
  390. }
  391.  
  392. MenuItem* Menu::getMenuItem(int x, int y){
  393.     int i;
  394.  
  395.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  396.         if(menuItems[i]!=NULL 
  397.                 && y>menuItems[i]->y && y<menuItems[i]->y+menuItems[i]->height && x>menuItems[i]->x && x<menuItems[i]->x+menuItems[i]->width){
  398.             return menuItems[i];
  399.         }
  400.     }
  401.  
  402.     return NULL;
  403. }
  404.  
  405. bool Menu::addMenuItem(MenuItem* item){
  406.     int i;
  407.  
  408.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  409.         if(menuItems[i]==NULL){
  410.             menuItems[i]=item;
  411.             return true;
  412.         }
  413.     }
  414.  
  415.     return false;
  416. }
  417.  
  418. bool Menu::removeMenuItem(MenuItem* item){
  419.     int i;
  420.  
  421.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  422.         if(menuItems[i]==item){
  423.             menuItems[i]=NULL;
  424.             return true;
  425.         }
  426.     }
  427.  
  428.     return false;
  429. }
  430.  
  431. bool Menu::deleteMenuItem(MenuItem* item){
  432.     int i;
  433.  
  434.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  435.         if(menuItems[i]==item){
  436.             delete menuItems[i];
  437.             menuItems[i]=NULL;
  438.             return true;
  439.         }
  440.     }
  441.  
  442.     return false;
  443. }
  444.  
  445. bool Menu::addSubmenu(Menu* submenu){
  446.     int i;
  447.  
  448.     for(i=0;i<MENU_MAX_SUBMENUS;i++){
  449.         if(submenus[i]==NULL){
  450.             submenus[i]=submenu;
  451.             return true;
  452.         }
  453.     }
  454.  
  455.     return false;
  456. }
  457.  
  458. bool Menu::removeSubmenu(Menu* submenu){
  459.     int i;
  460.  
  461.     for(i=0;i<MENU_MAX_SUBMENUS;i++){
  462.         if(submenus[i]==submenu){
  463.             submenus[i]=NULL;
  464.             return true;
  465.         }
  466.     }
  467.  
  468.     return false;
  469. }
  470.  
  471. bool Menu::deleteSubmenu(Menu* submenu){
  472.     int i;
  473.  
  474.     for(i=0;i<MENU_MAX_SUBMENUS;i++){
  475.         if(submenus[i]==submenu){
  476.             delete submenus[i];
  477.             submenus[i]=NULL;
  478.             return true;
  479.         }
  480.     }
  481.  
  482.     return false;
  483. }
  484.  
  485. void Menu::closeAllSubmenus(){
  486.     for(int i=0;i<MENU_MAX_SUBMENUS;i++){
  487.         if(submenus[i]!=NULL && submenus[i]->isOpened()){
  488.             submenus[i]->close();
  489.         }
  490.     }
  491. }
  492.  
  493. /*
  494. bool Menu::openAsSubmenu(){
  495.     if(!opened){
  496.         opened=true;
  497.         //mainLoop();
  498.         return true;
  499.     }else{
  500.         return false;
  501.     }
  502. }
  503. */
  504. bool Menu::open(){
  505.     if(!opened){
  506.         opened=true;
  507.         //showMouseCursor();    // THINKABOUTME
  508.         //freeInput();
  509.         //mainLoop();
  510.         return true;
  511.     }else{
  512.         return false;
  513.     }
  514. }
  515.  
  516. bool Menu::close(){
  517.     if(opened){
  518. /*        for(int i=0;i<MENU_MAX_SUBMENUS;i++){
  519.             if(submenus[i]!=NULL && submenus[i]->isOpened())
  520.                 submenus[i]->closeAsSubmenu();
  521.         }
  522. */
  523.         closeAllSubmenus();
  524.         opened=false;
  525.         //hideMouseCursor();
  526.         //grabInput();
  527.         return true;
  528.     }else{
  529.         return false;
  530.     }
  531. }
  532. /*
  533. bool Menu::closeAsSubmenu(){
  534.     if(opened){
  535.         for(int i=0;i<MENU_MAX_SUBMENUS;i++){
  536.             if(submenus[i]!=NULL && submenus[i]->isOpened())
  537.                 submenus[i]->closeAsSubmenu();
  538.         }
  539.         opened=false;
  540.         return true;
  541.     }else{
  542.         return false;
  543.     }
  544. }
  545. */
  546. bool Menu::isOpened(){
  547.     return opened;
  548. }
  549.  
  550. void Menu::mainLoop(){
  551.     SDL_Event event;
  552.  
  553.     while(opened){
  554.         while( SDL_PollEvent(& event) ){
  555.             switch(event.type)
  556.             {
  557.                 case SDL_QUIT:
  558.                     System::normalQuit();
  559.                     break;
  560.  
  561.                 case SDL_KEYDOWN:
  562.                     handleKeyboardEvent(&event.key);
  563.                     break;
  564.  
  565.                 case SDL_KEYUP:
  566.                     handleKeyboardEvent(&event.key);
  567.                     break;
  568.  
  569.                 case SDL_MOUSEMOTION:
  570.                     handleMouseMotionEvent(&event.motion);
  571.                     break;
  572.  
  573.                 case SDL_MOUSEBUTTONDOWN:
  574.                     handleMouseButtonEvent(&event.button);
  575.                     break;
  576.  
  577.                 case SDL_MOUSEBUTTONUP:
  578.                     handleMouseButtonEvent(&event.button);
  579.                     break;
  580.  
  581.                 default:
  582.                     break;
  583.             } // switch
  584.         } // while( SDL_ ...
  585.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  586.         draw();
  587.         if(allowConsole && consoleFrontEnd->isActive){
  588.             consoleFrontEnd->draw();
  589.         }
  590.         SDL_GL_SwapBuffers();    // THINKABOUTME: spΣter backgroundScene
  591.     } // while( ! done)
  592.  
  593. }
  594.  
  595. void Menu::draw(){
  596.     int i;
  597.  
  598.     Renderer::beginDrawing();
  599.  
  600.     drawBackground();
  601.  
  602.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  603.         if(menuItems[i]!=NULL){
  604.             menuItems[i]->draw();
  605.         }
  606.     }
  607.  
  608.     Renderer::endDrawing();
  609.  
  610.  
  611.     for(i=0;i<MENU_MAX_SUBMENUS;i++){
  612.         if(submenus[i]!=NULL && submenus[i]->isOpened()){
  613.             submenus[i]->draw();
  614.         }
  615.     }
  616. }
  617.  
  618. void Menu::drawBackground(){
  619.     int i;
  620.     int x=800;
  621.     int y=600;
  622.     int mx=0;
  623.     int my=0;
  624.  
  625.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  626.         if(menuItems[i]!=NULL){
  627.             x = x<menuItems[i]->x ? x : menuItems[i]->x;
  628.             y = y<menuItems[i]->y ? y : menuItems[i]->y;
  629.  
  630.             mx = mx>menuItems[i]->x+menuItems[i]->width ? mx : menuItems[i]->x+menuItems[i]->width;
  631.             my = my>menuItems[i]->y+menuItems[i]->height ? my : menuItems[i]->y+menuItems[i]->height;
  632.         }
  633.     }
  634.  
  635.     if(x>=800 || y>=600 || mx<=0 || my<=0)
  636.         return;
  637.  
  638.     x -= 10;
  639.     y -= 10;
  640.     mx += 10;
  641.     my += 10;
  642.  
  643.     Renderer::drawQuad(x, y, mx, my, Gui::info.var.menu_normalColor, Gui::info.var.menu_backgroundColor);
  644. }
  645.  
  646.  
  647. void Menu::handleKeyboardEvent(SDL_KeyboardEvent* event){
  648.     int i;
  649.  
  650.     if(allowConsole && event->type==SDL_KEYDOWN){
  651.         if(Input::keyMap[event->keysym.sym].action==TOGGLE_CONSOLE){
  652.             if(consoleFrontEnd->isActive)
  653.                 consoleFrontEnd->deactivate();
  654.             else
  655.                 consoleFrontEnd->activate();
  656.  
  657.             return;
  658.         }
  659.         if(consoleFrontEnd->isActive){
  660.             consoleFrontEnd->receiveKey(&event->keysym);
  661.             return;
  662.         }
  663.     }
  664.  
  665.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  666.         if(menuItems[i]!=NULL && menuItems[i]->hasKeyboardFocus && event->type==SDL_KEYDOWN)
  667.             menuItems[i]->receiveKey(&event->keysym);
  668.     }
  669.     
  670.  
  671.     for(i=0;i<MENU_MAX_SUBMENUS;i++){
  672.         if(submenus[i]!=NULL && submenus[i]->isOpened())
  673.             submenus[i]->handleKeyboardEvent(event);
  674.     }
  675. //    printf("sym: %d, scancode: %d, unicode: %d, mod: %d\n",keysym->sym, keysym->scancode, keysym->unicode, keysym->mod);
  676. }
  677.  
  678. void Menu::handleMouseMotionEvent(SDL_MouseMotionEvent* event){
  679. //    printf("MOUSE MOTION: x: %i, y: %i\n", event->x, event->y);
  680.     int i;
  681.  
  682.     // THINKABOUTME: hightlights??
  683.     for(i=0;i<MENU_MAX_MENU_ITEMS;i++){
  684.         if(menuItems[i]!=NULL)
  685.             menuItems[i]->highlighted=false;
  686.     }
  687.     MenuItem* mi = getMenuItem((int)(event->x/Display::info.var.scaleX), (int)((Display::info.var.height - event->y)/Display::info.var.scaleY));
  688.     if(mi!=NULL)
  689.         mi->highlighted=true;
  690.  
  691.     for(i=0;i<MENU_MAX_SUBMENUS;i++){
  692.         if(submenus[i]!=NULL && submenus[i]->isOpened())
  693.             submenus[i]->handleMouseMotionEvent(event);
  694.     }
  695.  
  696. }
  697.  
  698. void Menu::handleMouseButtonEvent(SDL_MouseButtonEvent* event){
  699. //    printf("MOUSE BUTTON: %i\n", event->button);
  700.     if(allowConsole && consoleFrontEnd->isActive)
  701.         return;
  702.  
  703.     int button=event->button;
  704.     if(button != MOUSE_BUTTON1 && button != MOUSE_BUTTON3)
  705.         return;
  706.  
  707.     if(event->type==SDL_MOUSEBUTTONUP){
  708.         MenuItem* mi = getMenuItem((int)(event->x/Display::info.var.scaleX), (int)((Display::info.var.height - event->y)/Display::info.var.scaleY));
  709.  
  710.         if(mi!=NULL && mi->isActive()){
  711.             for(int i=0;i<MENU_MAX_MENU_ITEMS;i++){
  712.                 if(menuItems[i] != NULL)
  713.                     menuItems[i]->hasKeyboardFocus = false;
  714.             }
  715.             mi->hasKeyboardFocus = true;
  716.             
  717.             if(button == MOUSE_BUTTON1){
  718.                 mi->clicked();
  719.             }else if(button == MOUSE_BUTTON3){
  720.                 mi->clickedRight();
  721.             }
  722.         }
  723.     }else if(event->type==SDL_MOUSEBUTTONDOWN){
  724.         // THINKABOUTME: play a sound??
  725.     }
  726.  
  727.     for(int i=0;i<MENU_MAX_SUBMENUS;i++){
  728.         if(submenus[i]!=NULL && submenus[i]->isOpened())
  729.             submenus[i]->handleMouseButtonEvent(event);
  730.     }
  731. }
  732.  
  733.  
  734.