Code: Select all
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <gl/glut.h>
#include <CEGUI.h>
#include <CEGUIDefaultResourceProvider.h>
#include <OpenGLGUIRenderer/openglrenderer.h>
using namespace std;
using namespace CEGUI;
int lastTime = 0;
void display()
{
int t = glutGet(GLUT_ELAPSED_TIME);
float elapsed = (float)(t - lastTime);
System::getSingleton().injectTimePulse(elapsed / 1000.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
System::getSingleton().renderGUI();
glFlush();
glutPostRedisplay();
glutSwapBuffers();
}
void initGL()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
void keyChar(unsigned char key, int x, int y)
{
System &S = System::getSingleton();
switch (key)
{
case 0x08:
S.injectKeyDown(Key::Backspace);
break;
case 0x7f:
S.injectKeyDown(Key::Delete);
break;
case 0x1b:
exit(0);
break;
case 0x0d:
S.injectKeyDown(Key::Return);
break;
default:
S.injectChar(static_cast<utf32>(key));
break;
}
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
OpenGLRenderer *R = (OpenGLRenderer *)(System::getSingleton().getRenderer());
R->setDisplaySize(Size((float)w, (float)h));
}
void mouseButton(int button, int state, int x, int y)
{
System &S = System::getSingleton();
switch (button)
{
case GLUT_LEFT_BUTTON:
(state == GLUT_UP) ? S.injectMouseButtonUp(LeftButton) : S.injectMouseButtonDown(LeftButton);
break;
case GLUT_RIGHT_BUTTON:
(state == GLUT_UP) ? S.injectMouseButtonUp(RightButton) : S.injectMouseButtonDown(RightButton);
break;
case GLUT_MIDDLE_BUTTON:
(state == GLUT_UP) ? S.injectMouseButtonUp(MiddleButton) : S.injectMouseButtonDown(MiddleButton);
break;
}
glutPostRedisplay();
}
void mouseMotion(int x, int y)
{
System::getSingleton().injectMousePosition(x, y);
glutPostRedisplay();
}
int _tmain(int argc, _TCHAR* argv[])
{
glutInit(&argc, (char **)&argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("CE Test");
new System(new OpenGLRenderer(0));
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMotionFunc(mouseMotion);
glutMouseFunc(mouseButton);
glutKeyboardFunc(keyChar);
initGL();
try
{
DefaultResourceProvider *rp = static_cast<DefaultResourceProvider *>(System::getSingleton().getResourceProvider());
rp->setResourceGroupDirectory("schemes", "datafiles/schemes/");
rp->setResourceGroupDirectory("imagesets", "datafiles/imagesets/");
rp->setResourceGroupDirectory("fonts", "datafiles/fonts/");
rp->setResourceGroupDirectory("layouts", "datafiles/layouts/");
rp->setResourceGroupDirectory("looknfeels", "datafiles/looknfeel/");
rp->setResourceGroupDirectory("lua_scripts", "datafiles/lua_scripts/");
Imageset::setDefaultResourceGroup("imagesets");
Font::setDefaultResourceGroup("fonts");
Scheme::setDefaultResourceGroup("schemes");
WidgetLookManager::setDefaultResourceGroup("looknfeels");
WindowManager::setDefaultResourceGroup("layouts");
ScriptModule::setDefaultResourceGroup("lua_scripts");
SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
Window *console = WindowManager::getSingleton().loadWindowLayout("Console.wnd");
System::getSingleton().setGUISheet(console);
}
catch (InvalidRequestException e)
{
cerr << e.getMessage() << endl;
}
lastTime = glutGet(GLUT_ELAPSED_TIME);
glutMainLoop();
return 0;
}
Edit: I added a bit more to the code, mainly keyboard handling as well as the time pulse (thinking it could solve the issue), to no avail. Once I wrestle the cursor to the editbox, i can type text in fine. Just can't get the mouse to follow the pointer at all times.