- #include <GL/glut.h>
- #include <CEGUI.h>
- #include <CEGUIDefaultResourceProvider.h>
- #include <RendererModules/OpenGLGUIRenderer/openglrenderer.h>
- using namespace CEGUI;
- //#include "UIAnimationManager.h"
- // GLUT callback prototypes
- void drawFrame(void);
- void mouseMotion(int x, int y);
- void mouseButton(int button, int state, int x, int y);
- void keyChar(unsigned char key, int x, int y);
- // super global vars!
- bool G_quitFlag = false;
- CEGUI::OpenGLRenderer* G_renderer = 0;
- //uiae::UIAnimationManager* G_animMgr = 0;
- int G_lastFrameTime = 0;
- // app entry point
- int main(int argc, char* argv[])
- {
- // Do GLUT init
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA);
- glutInitWindowSize(800, 600);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("CEGUI / UIAE Test");
- glutSetCursor(GLUT_CURSOR_NONE);
- // register callbacks
- glutDisplayFunc(drawFrame);
- glutMotionFunc(mouseMotion);
- glutPassiveMotionFunc(mouseMotion);
- glutMouseFunc(mouseButton);
- glutKeyboardFunc(keyChar);
- // initialise basic CEGUI system
- G_renderer = new OpenGLRenderer(1024);
- new System(G_renderer);
- // initialise the required dirs for the DefaultResourceProvider
- DefaultResourceProvider* rp = static_cast<DefaultResourceProvider*>
- (System::getSingleton().getResourceProvider());
- //注意:这里要修改为下载的CEGUI界面文件对应的目录
- rp->setResourceGroupDirectory("schemes", "../GUI/schemes/");
- rp->setResourceGroupDirectory("imagesets", "../GUI/imagesets/");
- rp->setResourceGroupDirectory("fonts", "../GUI/fonts/");
- rp->setResourceGroupDirectory("layouts", "../GUI/layouts/");
- rp->setResourceGroupDirectory("looknfeels", "../GUI/looknfeel/");
- rp->setResourceGroupDirectory("lua_scripts", "../GUI/lua_scripts/");
- // set the default resource groups to be used
- Imageset::setDefaultResourceGroup("imagesets");
- Font::setDefaultResourceGroup("fonts");
- Scheme::setDefaultResourceGroup("schemes");
- WidgetLookManager::setDefaultResourceGroup("looknfeels");
- WindowManager::setDefaultResourceGroup("layouts");
- ScriptModule::setDefaultResourceGroup("lua_scripts");
- // we will make use of the WindowManager.
- WindowManager& winMgr = WindowManager::getSingleton();
- // load scheme and set up defaults
- SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
- System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
- if(!FontManager::getSingleton().isFontPresent("Commonwealth-10"))
- FontManager::getSingleton().createFont("Commonwealth-10.font");
- // create root window
- DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
- // set root as the active GUI sheet
- System::getSingleton().setGUISheet(root);
- // create a FrameWindow for the test
- FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "TestWindow");
- // add the frame window to the root
- root->addChildWindow(wnd);
- // set window initial position and size
- wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
- wnd->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
- // set window text
- wnd->setText("UIAE Demo Window");
- initialise the uiae system
- *** Step 1 from the artice ***
- //G_animMgr = uiae::UIAnimationManager::instance();
- load the sample animations that came with uiae
- *** Step 2 from the artice ***
- //if (G_animMgr->loadAnimationsFromFile("./sample.xml"))
- //{
- // // add the FrameWindow to be managed by uiae, using anims from the "misc" list
- // // *** Step 3 from the artice ***
- // if (G_animMgr->addWindow(wnd, "1", "misc"))
- // {
- // // set window ID "1" to use the "bounce" animation (from the "misc" list).
- // // *** Step 4 from the artice ***
- // G_animMgr->setAnimationState("1", "bounce");
- // }
- //}
- // start loop
- glutMainLoop();
- return 0;
- }
- void drawFrame(void)
- {
- // do time based updates
- int thisTime = glutGet(GLUT_ELAPSED_TIME);
- float elapsed = static_cast<float>(thisTime - G_lastFrameTime);
- G_lastFrameTime = thisTime;
- // inject the time pulse (CEGUI and UIAE)
- CEGUI::System::getSingleton().injectTimePulse(elapsed / 1000.0f);
- // *** Step 5 from the artice ***
- //G_animMgr->update(elapsed / 1000.f);
- // do rendering for this frame.
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.0, 0.0, 12, 0.0, 0.0, -100, 0.0, 1.0, 0.0);
- CEGUI::System::getSingleton().renderGUI();
- glFlush();
- glutPostRedisplay();
- glutSwapBuffers();
- // handle quit conditiion
- if (G_quitFlag)
- {
- //G_animMgr->cleanup();
- // cleanup cegui system
- delete CEGUI::System::getSingletonPtr();
- delete G_renderer;
- // exit
- exit(0);
- }
- }
- void mouseMotion(int x, int y)
- {
- CEGUI::System::getSingleton().injectMousePosition(x, y);
- }
- void mouseButton(int button, int state, int x, int y)
- {
- switch(button)
- {
- case GLUT_LEFT_BUTTON:
- if (state == GLUT_UP)
- {
- CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
- }
- else
- {
- CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
- }
- break;
- case GLUT_RIGHT_BUTTON:
- if (state == GLUT_UP)
- {
- CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
- }
- else
- {
- CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
- }
- break;
- case GLUT_MIDDLE_BUTTON:
- if (state == GLUT_UP)
- {
- CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
- }
- else
- {
- CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
- }
- break;
- }
- }
- void keyChar(unsigned char key, int x, int y)
- {
- // extract some keys may be handled via key code and generate those too
- switch (key)
- {
- case 0x08: // backspace
- CEGUI::System::getSingleton().injectKeyDown(CEGUI::Key::Backspace);
- break;
- case 0x7F: // delete
- CEGUI::System::getSingleton().injectKeyDown(CEGUI::Key::Delete);
- break;
- case 0x1B: // Escape
- G_quitFlag = true;
- break;
- case 0x0D: // CR (Return)
- CEGUI::System::getSingleton().injectKeyDown(CEGUI::Key::Return);
- break;
- default:
- // inject Character code
- CEGUI::System::getSingleton().injectChar(static_cast<CEGUI::utf32>(key));
- break;
- }
- }