4 * \author Matt Raykowski
8 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
9 // Copyright (C) 2010 Winch Gate Property Limited
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU Affero General Public License as
13 // published by the Free Software Foundation, either version 3 of the
14 // License, or (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Affero General Public License for more details.
21 // You should have received a copy of the GNU Affero General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
33 HINSTANCE ghInstance
= 0;
40 #include <nel/cegui/inellibrary.h>
41 #include <nel/cegui/nelrenderer.h>
42 //#include <nel/cegui/nellogger.h>
44 #include "NeLDriver.h"
46 #include <nel/misc/hierarchical_timer.h>
47 #include <nel/misc/dynloadlib.h>
63 //CEGUI::NeLLogger *gGuiLogger;
64 CEGUI::System
*gGuiSystem
;
65 CEGUI::Renderer
*gGuiRenderer
;
68 void createDemoWindows();
69 void initDemoEventWiring();
70 bool handleQuit(const CEGUI::EventArgs
& e
);
71 bool handleSlider(const CEGUI::EventArgs
& e
);
72 bool handleRadio(const CEGUI::EventArgs
& e
);
73 bool handleCheck(const CEGUI::EventArgs
& e
);
75 #ifndef CEGUI_DATA_DIR
76 #define CEGUI_DATA_DIR "datafiles"
77 #endif // CEGUI_DATA_DIR
80 int WINAPI
WinMain( HINSTANCE hInstance
,
81 HINSTANCE hPrevInstance
,
84 ghInstance
= hInstance
;
86 int main(int argc
, char **argv
)
89 NLMISC::CApplicationContext myApplicationContext
;
93 NLMISC::CPath::addSearchPath(CEGUI_DATA_DIR
,true,false);
95 // Load the CEGUI renderer and get a handle to the library.
96 NLMISC::CLibrary driverLib
;
97 if(!driverLib
.loadLibrary("nelceguirenderer", true, true , true)) {
98 nlerror("Failed to load NeL CEGUI Renderer library.");
100 NELRENDERER_CREATE_PROC createNelRenderer
= reinterpret_cast<NELRENDERER_CREATE_PROC
>(driverLib
.getSymbolAddress(NELRENDERER_CREATE_PROC_NAME
));
102 // CCeguiRendererNelLibrary *nelCeguiDriverLib = dynamic_cast<CCeguiRendererNelLibrary *>(driverLib.getNelLibraryInterface());
104 NL3D::UDriver
*driver
;
109 icon
= (uint
)LoadIcon(ghInstance
,MAKEINTRESOURCE(IDI_ICON1
));
112 #ifdef NL_INDEX_BUFFER_H //new 3d
113 NL3D::UDriver
*driver
= NL3D::UDriver::createDriver(icon
,useD3D
);
115 driver
= NL3D::UDriver::createDriver(icon
);
119 nlinfo("Start initializing the 3D system");
120 gDriver
=new NeLDriver(driver
);
123 // start up the Gui system.
124 //gGuiLogger = nelCeguiDriverLib->createNelLogger();
125 //gGuiRenderer = new CEGUI::NeLRenderer(driver);
127 gGuiRenderer
= createNelRenderer(driver
, true);
128 gGuiSystem
= new CEGUI::System(gGuiRenderer
);
129 CEGUI::NeLRenderer
*rndr
= (CEGUI::NeLRenderer
*)gGuiRenderer
;
130 rndr
->activateInput();
131 rndr
->captureCursor(true);
133 // load some GUI stuff for demo.
134 nlinfo("Start up and configure the GUI system.");
136 using namespace CEGUI
;
138 Logger::getSingleton().setLoggingLevel(Insane
);
140 // load scheme and set up defaults
141 SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
142 System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
144 // create the font and set it up as the default.
145 FontManager::getSingleton().createFont("Commonwealth-10.font");
147 // load an image to use as a background
148 ImagesetManager::getSingleton().createImagesetFromImageFile("BackgroundImage", "GPN-2000-001437.tga");
150 // here we will use a StaticImage as the root, then we can use it to place a background image
151 Window
* background
= WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "background_wnd");
152 // set position and size
153 background
->setPosition(UVector2(cegui_reldim(0), cegui_reldim( 0)));
154 background
->setSize(UVector2(cegui_reldim(1), cegui_reldim( 1)));
155 // disable frame and standard background
156 background
->setProperty("FrameEnabled", "false");
157 background
->setProperty("BackgroundEnabled", "false");
158 // set the background image
159 background
->setProperty("Image", "set:BackgroundImage image:full_image");
160 // install this as the root GUI sheet
161 System::getSingleton().setGUISheet(background
);
163 // load the windows for Demo7 from the layout file.
164 Window
* sheet
= WindowManager::getSingleton().loadWindowLayout("Demo7Windows.layout");
165 // attach this to the 'real' root
166 background
->addChildWindow(sheet
);
168 initDemoEventWiring();
169 } catch(CEGUI::Exception
) { // catch to prevent exit (errors will be logged).
173 NLMISC::CRGBA
pClearColor(0,0,0,255);
174 const CEGUI::Font
*fnt
= gGuiSystem
->getDefaultFont();
177 //NLMISC::CHTimer::startBench();
178 //NLMISC::CHTimer frameTimer("MAIN_DemoLoop");
179 //NLMISC::CHTimer renderGUITimer("MAIN_RenderGUI");
181 //frameTimer.before();
182 // stop the demo if the driver stops.
183 if(!gDriver
->getDriver().isActive()) {
187 gDriver
->getDriver().clearBuffers(pClearColor
);
193 if(gDriver
->getDriver().AsyncListener
.isKeyPushed(NLMISC::KeyESCAPE
)) {
199 //renderGUITimer.before();
200 gGuiSystem
->renderGUI();
201 //renderGUITimer.after();
206 // 3D Swap ** ALWAYS THE LAST PART
207 gDriver
->getDriver().swapBuffers();
208 if(gDriver
->getDriver().AsyncListener
.isKeyPushed(NLMISC::KeyF2
)) {
210 gDriver
->getDriver().getBuffer(btm
);
211 std::string filename
= NLMISC::CFile::findNewFile("screenshot.jpg");
212 NLMISC::COFile
fs(filename
);
214 nlinfo("Screenshot '%s' saved", filename
.c_str());
216 // 3D Swap ** NOTHING AFTER THIS
217 //frameTimer.after();
218 if(gDriver
->getDriver().AsyncListener
.isKeyPushed(NLMISC::KeyF3
)) {
219 NLMISC::CHTimer::display();
223 } catch(NLMISC::Exception
&e
) {
224 fprintf (stderr
,"main trapped an exception: '%s'", e
.what ());
230 /*************************************************************************
231 Sample sub-class for ListboxTextItem that auto-sets the selection brush
233 *************************************************************************/
234 class MyListItem
: public CEGUI::ListboxTextItem
237 MyListItem(const CEGUI::String
& text
) : ListboxTextItem(text
)
239 setSelectionBrushImage((CEGUI::utf8
*)"TaharezLook", (CEGUI::utf8
*)"MultiListSelectionBrush");
245 /*************************************************************************
246 Perform required event hook-ups for this demo.
247 *************************************************************************/
248 void initDemoEventWiring(void)
250 using namespace CEGUI
;
252 WindowManager::getSingleton().getWindow("Demo7/Window1/Quit")->
253 subscribeEvent(PushButton::EventClicked
, handleQuit
);
255 WindowManager::getSingleton().getWindow("Demo7/Window1/Slider1")->
256 subscribeEvent(Slider::EventValueChanged
, handleSlider
);
258 WindowManager::getSingleton().getWindow("Demo7/Window1/Checkbox")->
259 subscribeEvent(Checkbox::EventCheckStateChanged
, handleCheck
);
261 WindowManager::getSingleton().getWindow("Demo7/Window1/Radio1")->
262 subscribeEvent(RadioButton::EventSelectStateChanged
, handleRadio
);
264 WindowManager::getSingleton().getWindow("Demo7/Window1/Radio2")->
265 subscribeEvent(RadioButton::EventSelectStateChanged
, handleRadio
);
267 WindowManager::getSingleton().getWindow("Demo7/Window1/Radio3")->
268 subscribeEvent(RadioButton::EventSelectStateChanged
, handleRadio
);
272 bool handleQuit(const CEGUI::EventArgs
& e
)
279 bool handleSlider(const CEGUI::EventArgs
& e
)
281 using namespace CEGUI
;
283 float val
= ((Slider
*)((const WindowEventArgs
&)e
).window
)->getCurrentValue();
285 ((ProgressBar
*)WindowManager::getSingleton().getWindow("Demo7/Window2/Progbar1"))->setProgress(val
);
286 ((ProgressBar
*)WindowManager::getSingleton().getWindow("Demo7/Window2/Progbar2"))->setProgress(1.0f
- val
);
288 WindowManager::getSingleton().getWindow("root_wnd")->setAlpha(val
);
293 bool handleRadio(const CEGUI::EventArgs
& e
)
295 using namespace CEGUI
;
297 CEGUI::uint id
= ((RadioButton
*)((const WindowEventArgs
&)e
).window
)->getSelectedButtonInGroup()->getID();
301 WindowManager::getSingleton().getWindow("Demo7/Window2/Image1")->setProperty("Image", "set:WerewolfGuiImagery image:CeguiLogo");
305 WindowManager::getSingleton().getWindow("Demo7/Window2/Image1")->setProperty("Image", "set:WerewolfGuiImagery image:NeLLogo");
309 WindowManager::getSingleton().getWindow("Demo7/Window2/Image1")->setProperty("Image", "set:WerewolfGuiImagery image:WerewolfLogo");
316 bool handleCheck(const CEGUI::EventArgs
& e
)
318 using namespace CEGUI
;
320 if (((Checkbox
*)((const WindowEventArgs
&)e
).window
)->isSelected())
322 WindowManager::getSingleton().getWindow("Demo7/Window3")->show();
326 WindowManager::getSingleton().getWindow("Demo7/Window3")->hide();