[Solved] Cursor only updating when mouse is clicked

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

reacher
Just popping in
Just popping in
Posts: 8
Joined: Thu Apr 02, 2009 14:29

[Solved] Cursor only updating when mouse is clicked

Postby reacher » Wed Apr 08, 2009 17:55

I have a simple demo, based on the FirstWindow sample included with CEGUI. I'm using VC++2008 express with glut. The frame window and cursor both display properly. But the CEGUI cursor only moves while I holding down the mouse button. If I let off the button, it fails to update anymore. I must be doing something wrong, but it's not immediately apparent to me. Code is included below. Thanks!

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.
Last edited by reacher on Thu Apr 09, 2009 00:33, edited 1 time in total.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Wed Apr 08, 2009 22:13

Hi, and welcome :)

I think you need to set the callback for 'glutPassiveMotionFunc' - you can use the same function as for glutMotionFunc (which is only called when a mouse button is down).

HTH

CE.

reacher
Just popping in
Just popping in
Posts: 8
Joined: Thu Apr 02, 2009 14:29

Postby reacher » Thu Apr 09, 2009 00:12

haha i just figured it out while cooking. I was tossing some garlic, onions and squash, thinking "man i wish i had some device to do this for me. all it would need is some passive motion that would--" and it hit me: glutPassiveMotionFunc()!!

thanks!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 11 guests