Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members

mainmenu.cpp

Go to the documentation of this file.
00001 #ifdef WIN32
00002 #include <windows.h>
00003 #else
00004 #include <unistd.h>
00005 #endif
00006 #include <GL/glut.h>
00007 #include <plib/pu.h>
00008 
00009 #include "common_vars_gui.h"
00010 #include "common_vars_game.h"
00011 #include "common_gui_funcs.h"
00012 
00013 #include "configuration.h"
00014 
00015 #include <signal.h>
00016 
00017 class MainMenu {
00018   public:
00019     MainMenu();
00020     ~MainMenu();
00021     void _display_total();
00022     void _display_graph_config();
00023     puButtonBox* fsORwindow_switch;
00024     puInput* window_width;
00025     puInput* window_height;
00026     puButtonBox* resolution_switch;
00027     puButtonBox* bpp_switch;
00028     puButtonBox* refresh_switch;
00029     puGroup* left;
00030     puGroup* right;
00031     bool test_graph_settings(char* gms);
00032     void apply_graph_settings();
00033     bool wasfs;
00034 };
00035 
00036 bool MainMenu::test_graph_settings(char* gms) {
00037     if (!config->get_fullscreen())
00038       return true;
00039     glutGameModeString(gms);
00040     if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE) != -1) {
00041       return true;
00042     }
00043     return false;
00044 }
00045 
00046 void MainMenu::apply_graph_settings() {
00047   int I;
00048   fsORwindow_switch->getValue(&I);
00049   config->set_fullscreen((bool)I);
00050   if (I) {
00051     char tmpg[50];
00052     int tw, th, tb, tr;
00053     tw=th=tb=tr = 0; 
00054     resolution_switch->getValue(&tw);
00055     switch(tw) {
00056       case 0:
00057         tw = 640;
00058         th = 480;
00059         break;
00060       case 1:
00061         tw = 800;
00062         th = 600;
00063         break;
00064       case 2:
00065         tw = 1024;
00066         th = 768;
00067         break;
00068       case 3:
00069         tw = 1280;
00070         th = 960;
00071         break;
00072       case 4:
00073         tw = 1280;
00074         th = 1024;
00075         break;
00076     }
00077     bpp_switch->getValue(&tb);
00078     tb = (++tb) * 8;
00079     
00080     refresh_switch->getValue(&tr);
00081     switch(tr) {
00082       case 0:
00083         tr = 60;
00084         break;
00085       case 1:
00086         tr = 65;
00087         break;
00088       case 2:
00089         tr = 70;
00090         break;
00091       case 3:
00092         tr = 72;
00093         break;
00094       case 4:
00095         tr = 75;
00096         break;
00097       case 5:
00098         tr = 80;
00099         break;
00100     }
00101     sprintf((char*)&tmpg, "%ix%i:%i@%i",tw, th, tb, tr); 
00102     if (test_graph_settings((char*)&tmpg)) {
00103       config->set_game_mode_string((char*)&tmpg);
00104       glutEnterGameMode();
00105       _register_glutfuncs_menuonly();
00106       display_height = th;
00107       display_width = tw;
00108     }
00109   }
00110   else {
00111     window_width->getValue(&I);
00112     config->set_window_width(I);
00113     window_height->getValue(&I);
00114     config->set_window_height(I);
00115     display_width = config->get_window_width();
00116     display_height = config->get_window_height();
00117     if (wasfs) {
00118       glutLeaveGameMode();
00119       if (win_handle != -1)
00120       glutDestroyWindow(win_handle);
00121       glutInitWindowSize(config->get_window_width(), config->get_window_height());
00122       win_handle = glutCreateWindow(WINDOW_TITLE);
00123       _register_glutfuncs_menuonly();
00124     }
00125     else {
00126       glutReshapeWindow(display_width, display_height);
00127     }
00128   }
00129   _display_graph_config();
00130 }
00131 MainMenu* _mm = NULL;
00132 
00133 void apply_settings_cb(puObject* e) {
00134   _mm->apply_graph_settings();
00135 }
00136 
00137 void _clear_main_menu(puObject* o) {
00138   if (total_menu != NULL)
00139   total_menu->hide();
00140   if (_mm != NULL) {
00141     delete _mm;
00142     _mm = NULL;
00143   }
00144 }
00145 
00146 void quit_callback(puObject* e) {
00147   _clear_main_menu(NULL);
00148   _clear_total_menu();
00149   raise(SIGINT);
00150 }
00151 
00152 
00153 void _make_main_menu(puObject* o) {
00154   _clear_main_menu(NULL);
00155   _mm = new MainMenu();
00156 }
00157 
00158 void _show_graph_config(puObject* e) {
00159   _mm->_display_graph_config();
00160 }
00161 
00162 void _switch_window2fs (puObject* p) {
00163   int i;
00164   p->getValue(&i);
00165   if (!i) {
00166     _mm->right->greyOut();
00167     _mm->right->setChildColourScheme(PUCLASS_BUTTONBOX, 0.5, 0.5, 0.5, 0.8);
00168     _mm->left->setChildColourScheme(PUCLASS_INPUT, 0.3, 0.6, 0.7, 0.8);
00169     _mm->left->activate();
00170   }
00171   else {
00172     _mm->left->greyOut();
00173     _mm->right->activate();
00174     _mm->left->setChildColourScheme(PUCLASS_INPUT, 0.5, 0.5, 0.5, 0.8);
00175     _mm->right->setChildColourScheme(PUCLASS_BUTTONBOX, 0.3, 0.6, 0.7, 0.8);
00176   }
00177 }
00178 
00179 MainMenu::MainMenu() {
00180   wasfs=false;
00181   _display_total();
00182 }
00183 
00184 MainMenu::~MainMenu() {
00185 }
00186 
00187 void MainMenu::_display_total() {
00188   _clear_total_menu();
00189   total_menu = new puGroup(0, 0);
00190   puFrame* top_frame = new puFrame(10, display_height-10,
00191       display_width - 10, display_height - 30);
00192   top_frame->setLegend("main menu");
00193   top_frame->setColour(PUCOL_FOREGROUND, 0.2, 0.5, 0.9, 1.0);
00194   
00195   puButton* new_game_button = new puButton(30, display_height/2 + 40,
00196       "new game");
00197   new_game_button->setCallback(make_char_creator);
00198   puButton* graph_config_button = new puButton(30, display_height/2,
00199       "graphic configuration");
00200   graph_config_button->setCallback(_show_graph_config);
00201 
00202   puButton* quit_button = new puButton(30, display_height/2 - 40,
00203       "quit game");
00204   quit_button->setCallback(quit_callback);
00205   total_menu->close();
00206   total_menu->setChildColourScheme(PUCLASS_BUTTON, 0.3, 0.6, 0.7, 0.8);
00207 }
00208 
00209 void MainMenu::_display_graph_config() {
00210   _clear_total_menu();
00211   total_menu = new puGroup(0,0);
00212   puFrame* top_frame = new puFrame(10, display_height-10,
00213       display_width - 10, display_height - 30);
00214   top_frame->setLegend("graphic configuration");
00215   top_frame->setColour(PUCOL_FOREGROUND, 0.2, 0.5, 0.9, 1.0);
00216 
00217   static char* windowstr[] = { "window", "fullscreen", NULL};
00218    fsORwindow_switch = new puButtonBox(20, display_height - 110,
00219       140, display_height - 50, windowstr, 1);
00220   fsORwindow_switch->setLabel("select main viewmode");
00221   fsORwindow_switch->setCallback(_switch_window2fs);
00222   fsORwindow_switch->setValue((int)config->get_fullscreen());
00223   wasfs = config->get_fullscreen();
00224    left = new puGroup(10, display_height - 250);
00225    window_width = new puInput(10, 0, 60, 25);
00226   window_width->setLabel("width");
00227   window_width->setValue(config->get_window_width());
00228   window_width->setValidData("0123456789");
00229    window_height = new puInput(10, 35, 60, 60);
00230   window_height->setLabel("height");
00231   window_height->setValue(config->get_window_height());
00232   window_height->setValidData("0123456789");
00233   left->close();
00234                                                                                    
00235    right = new puGroup(display_width/2,  display_height - 450);
00236                                                                                    
00237   char* tmpstr;
00238   tmpstr = config->get_game_mode_string();
00239                                                                                    
00240    resolution_switch = new puButtonBox(10, 0, 160, 120,
00241       default_resolutions, 1);
00242   resolution_switch->setLabel("screen resolution");
00243                                                                                    
00244    bpp_switch = new puButtonBox(10, 125, 160, 230,
00245       default_bpp, 1);
00246   bpp_switch->setLabel("colour depth");
00247                                                                                    
00248    refresh_switch = new puButtonBox(10, 235, 160, 350,
00249       default_refresh, 1);
00250   refresh_switch->setLabel("refresh rate");
00251   right->close();
00252                                                                                    
00253   if (!config->get_fullscreen()) {
00254     right->greyOut();
00255     right->setChildColourScheme(PUCLASS_BUTTONBOX, 0.5, 0.5, 0.5, 0.8);
00256     left->setChildColourScheme(PUCLASS_INPUT, 0.3, 0.6, 0.7, 0.8);
00257   }
00258   else {
00259     left->greyOut();
00260     left->setChildColourScheme(PUCLASS_INPUT, 0.5, 0.5, 0.5, 0.8);
00261     right->setChildColourScheme(PUCLASS_BUTTONBOX, 0.3, 0.6, 0.7, 0.8);
00262   }
00263                                                                                    
00264   puButton* test_graph_config = new puButton(30, 70, "test config");
00265   test_graph_config->setCallback(apply_settings_cb);                                                             
00266   puButton* cancel_button = new puButton(10, 10, "main menu");
00267   cancel_button->setCallback(_make_main_menu);
00268   total_menu->close();
00269   total_menu->setChildColourScheme(PUCLASS_BUTTONBOX,0.3, 0.6, 0.7, 0.8);
00270   total_menu->setChildColourScheme(PUCLASS_BUTTON,0.3, 0.6, 0.7, 0.8);
00271 }
00272 

Generated on Sat Jul 12 04:29:21 2003 for glPirates by doxygen 1.3.2