startup.cpp

00001 #include "startup.h"
00002 
00003 using namespace irr;
00004 using namespace core;
00005 using namespace video;
00006 using namespace gui;
00007 
00009 StartUpParameters::StartUpParameters()
00010 {
00011     // ctor
00012     fullScreen = false;
00013     driverType = EDT_OPENGL;
00014     screen.Width = 800;
00015     screen.Height = 600;
00016     colorBitDepth = 16;
00017     error = stringc("NO_ERROR");
00018 }
00019 
00020 StartUpParameters::StartUpParameters(bool fs,
00021                                      E_DRIVER_TYPE dt,
00022                                      dimension2d<s32> dim,
00023                                      u32 cbd)
00024 {
00025     // ctor
00026     fullScreen = fs;
00027     driverType = dt;
00028     screen = dim;
00029     colorBitDepth = cbd;
00030     error = stringc("NO_ERROR");
00031 }
00032 
00033 StartUpParameters::~StartUpParameters()
00034 {
00035     // dtor
00036 }
00037 
00039 StartUp::StartUp()
00040 {
00041     //ctor
00042     param.error = stringc("USER_QUIT");
00043 
00044     device = createDevice(EDT_SOFTWARE, dimension2d<s32>(320, 240));
00045     if (! device)
00046     {
00047         param.error = stringc("cannot create device");
00048         return;
00049     }
00050 
00051     device->setWindowCaption(L"Swarm");
00052     device->setEventReceiver(this);
00053     ITexture* texture = device->getVideoDriver()->getTexture("media/startUp.png");
00054     if (! texture)
00055     {
00056         param.error = stringc("cannot load image");
00057         return;
00058     }
00059     imgMenu = device->getGUIEnvironment()->addImage(texture, position2d<s32>(0, 0));
00060     // enable mouse
00061     device->getCursorControl()->setVisible(true);
00062 
00063     IGUIEnvironment* env = device->getGUIEnvironment();
00064 
00065         env->addButton(rect<s32>(10,130,80,150), 0, 101, L"start");
00066         env->addButton(rect<s32>(10,160,80,180), 0, 103, L"credits");
00067         env->addButton(rect<s32>(10,190,80,210), 0, 104, L"quit");
00068         env->addButton(rect<s32>(160,100,230,120), 0, 102, L"fullscreen");
00069         fullScreenText = env->addStaticText(L"no", rect<s32>(250,105,300,115));
00070         fullScreenText->setOverrideColor(SColor(0,255,255,255));
00071         env->addButton(rect<s32>(160,130,230,150), 0, 105, L"resolution");
00072         resolutionText = env->addStaticText(L"800x600", rect<s32>(250,135,300,145));
00073         resolutionText->setOverrideColor(SColor(0,255,255,255));
00074         env->addButton(rect<s32>(160,160,230,180), 0, 106, L"video driver");
00075         videDriverText = env->addStaticText(L"openGL", rect<s32>(250,165,300,175));
00076         videDriverText->setOverrideColor(SColor(0,255,255,255));
00077     env->addButton(rect<s32>(160,190,230,210), 0, 107, L"color bit depth");
00078         colorBitDepthText = env->addStaticText(L"16", rect<s32>(250,195,300,215));
00079         colorBitDepthText->setOverrideColor(SColor(0,255,255,255));
00080 
00081         loop();
00082 }
00083 
00084 StartUp::~StartUp()
00085 {
00086     //dtor
00087     device->getSceneManager()->clear();
00088     device->getGUIEnvironment()->getRootGUIElement()->remove();
00089     device->drop();
00090 }
00091 
00092 bool StartUp::OnEvent(SEvent event)
00093 {
00094     // user pressed enter: accept settings and start application
00095     if (event.EventType == EET_KEY_INPUT_EVENT)
00096     {
00097         if (event.KeyInput.PressedDown)
00098         {
00099             switch(event.KeyInput.Key)
00100             {
00101                 case KEY_RETURN:
00102                 {
00103                     device->closeDevice();
00104                     param.error = stringc("NO_ERROR");
00105                     return true;
00106                 }
00107             }
00108         }
00109     }
00110 
00111     if (event.EventType == EET_GUI_EVENT)
00112     {
00113         s32 id = event.GUIEvent.Caller->getID();
00114         IGUIEnvironment* env = device->getGUIEnvironment();
00115 
00116         switch(event.GUIEvent.EventType)
00117         {
00118             case EGET_BUTTON_CLICKED:
00119             {
00120                 if (id == 107)
00121                 {
00122                     if (param.colorBitDepth == 16)
00123                     {
00124                         param.colorBitDepth = 32;
00125                         colorBitDepthText->setText(L"32");
00126                     }
00127                     else
00128                     {
00129                         param.colorBitDepth = 16;
00130                         colorBitDepthText->setText(L"16");
00131                     }
00132                     return true;
00133                 }
00134 
00135                 if (id == 106)
00136                 {
00137                     if (param.driverType == EDT_OPENGL)
00138                     {
00139                         param.driverType = EDT_SOFTWARE;
00140                         videDriverText->setText(L"software 1");
00141                     }
00142                     else if (param.driverType == EDT_SOFTWARE)
00143                     {
00144                         param.driverType = EDT_SOFTWARE2;
00145                         videDriverText->setText(L"software 2");
00146                     }
00147                     else if (param.driverType == EDT_SOFTWARE2)
00148                     {
00149                         param.driverType = EDT_OPENGL;
00150                         videDriverText->setText(L"openGL");
00151                     }
00154 
00155                     return true;
00156                 }
00157 
00158                 if (id == 105)
00159                 {
00160                     if (param.screen == dimension2d<s32>(800, 600))
00161                     {
00162                         param.screen = dimension2d<s32>(1280, 1024);
00163                         resolutionText->setText(L"1280x1024");
00164                     }
00165                     else if (param.screen == dimension2d<s32>(1280, 1024))
00166                     {
00167                         param.screen = dimension2d<s32>(640, 400);
00168                         resolutionText->setText(L"640x400");
00169                     }
00170                     else if (param.screen == dimension2d<s32>(640, 400))
00171                     {
00172                         param.screen = dimension2d<s32>(800, 600);
00173                         resolutionText->setText(L"800x600");
00174                     }
00175                     return true;
00176                 }
00177 
00178                 if (id == 104)
00179                 {
00180                     device->closeDevice();
00181                     param.error = stringc("USER_QUIT");
00182                     return true;
00183                 }
00184 
00185                 if (id == 103)
00186                 {
00187                     IGUIWindow* window = env->addWindow(
00188                         rect<s32>(20, 20, 300, 220),
00189                         true, // modal?
00190                         L"Credits");
00191 
00192                     for (s32 i=0; i<EGDC_COUNT ; ++i)
00193                                         {
00194                                                 SColor col = env->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
00195                                                 col.setAlpha(255);
00196                                                 env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
00197                                         }
00198 
00199                     env->addStaticText(L"Swarm (c) 2006  Philipp Rossberger and Sebastian Roll",
00200                         rect<s32>(20,40,260,60),
00201                         true, // border?
00202                         true, // wordwrap?
00203                         window);
00204                     env->addStaticText(L"Visit www.einszunull.net !",
00205                         rect<s32>(20,70,260,90),
00206                         true, // border?
00207                         true, // wordwrap?
00208                         window);
00209                     env->addStaticText(L"SWARM 0.0.4",
00210                         rect<s32>(20,100,260,120),
00211                         true, // border?
00212                         true, // wordwrap?
00213                         window);
00214                     env->addStaticText(L"IRRLICHT 0.14.0",
00215                         rect<s32>(20,130,260,150),
00216                         true, // border?
00217                         true, // wordwrap?
00218                         window);
00219                     env->addStaticText(L"RAKKNET 2.4.3",
00220                         rect<s32>(20,160,260,180),
00221                         true, // border?
00222                         true, // wordwrap?
00223                         window);
00224 
00225                     return true;
00226                 }
00227 
00228                 if (id == 102)
00229                 {
00230                     param.fullScreen = !param.fullScreen;
00231                     if (param.fullScreen)
00232                     {
00233                         fullScreenText->setText(L"yes");
00234                     }
00235                     else
00236                     {
00237                         fullScreenText->setText(L"no");
00238                     }
00239                     return true;
00240                 }
00241                 if (id == 101)
00242                 {
00243                     device->closeDevice();
00244                     param.error = stringc("NO_ERROR");
00245                     return true;
00246                 }
00247 
00248                 break;
00249             }
00250         }
00251     }
00252 
00253     return false;
00254 }
00255 
00256 StartUpParameters StartUp::getStartUpParameters(void)
00257 {
00258     return param;
00259 }
00260 
00261 void StartUp::loop()
00262 {
00263         while(device->run())
00264     {
00265         if (device->isWindowActive())
00266         {
00267             device->getVideoDriver()->beginScene(true, true, SColor(0,0,0,0));
00268             device->getGUIEnvironment()->drawAll();
00269             device->getVideoDriver()->endScene();
00270         }
00271     }
00272 }

Generated on Sun Dec 2 17:09:58 2007 for Swarm by  doxygen 1.4.6-NO