Input_injection not working

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

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Input_injection not working

Postby aaron1a12 » Thu Sep 30, 2010 02:33

Leadwerks + CEGUI + SDL in C++

Can someone please tell me why the following code only shows a MessageBox once?



Code: Select all

/*
//Load the engine
#include "engine.h"
//Load the scene processer
#include "ProcessScene.h"
//Load the UI engine
#include "include/CEGUI.h"
#include "include/RendererModules/OpenGL/CEGUIOpenGLRenderer.h"
//Load the input engine
#include "sdl/include/SDL.h"


void handle_mouse_down(Uint8 button)
    {
    switch ( button )
        {
        // handle real mouse buttons
        case SDL_BUTTON_LEFT:
            CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
            break;
        case SDL_BUTTON_MIDDLE:
            CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
            break;
        case SDL_BUTTON_RIGHT:
            CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
            break;
       
        // handle the mouse wheel
        case SDL_BUTTON_WHEELDOWN:
            CEGUI::System::getSingleton().injectMouseWheelChange( -1 );
            break;
        case SDL_BUTTON_WHEELUP:
            CEGUI::System::getSingleton().injectMouseWheelChange( +1 );
            break;
        }
    }


void handle_mouse_up(Uint8 button)
    {
    switch ( button )
        {
        case SDL_BUTTON_LEFT:
            CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
            break;
        case SDL_BUTTON_MIDDLE:
            CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
            break;
        case SDL_BUTTON_RIGHT:
            CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
            break;
        }
    }


void inject_input()
{

}


void inject_time_pulse(double& last_time_pulse)
{
    // get current "run-time" in seconds
    double t = 0.001*SDL_GetTicks();

    // inject the time that passed since the last call
    CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );

    // store the new time as the last time
    last_time_pulse = t;
}


void render_gui()
{
    // clear the colour buffer
    glClear( GL_COLOR_BUFFER_BIT );

    // render the GUI :)
    CEGUI::System::getSingleton().renderGUI();

    // Update the screen
    SDL_GL_SwapBuffers();
}






int WINAPI WinMain( HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nShowCmd )
{
    Initialize() ;
    RegisterAbstractPath("C:/vita");
    SetAppTitle( "Vita" ) ;
    Graphics( 800, 600 ) ;


/*
*======================================================
*   UI
*======================================================
*/


    CEGUI::OpenGLRenderer &ceguiRenderer = CEGUI::OpenGLRenderer::create();
    CEGUI::System::create(ceguiRenderer);

    ceguiRenderer.enableExtraStateSettings(true);

    CEGUI::DefaultResourceProvider *rp = static_cast<CEGUI::DefaultResourceProvider*>(CEGUI::System::getSingleton().getResourceProvider());

    rp->setResourceGroupDirectory("schemes", "GUI/schemes/");   
    rp->setResourceGroupDirectory("layouts", "GUI/layouts/");
    rp->setResourceGroupDirectory("looknfeel", "GUI/looknfeel/");
    rp->setResourceGroupDirectory("imagesets", "GUI/imagesets/");
    rp->setResourceGroupDirectory("fonts", "GUI/fonts/");

    CEGUI::Scheme::setDefaultResourceGroup("schemes");
    CEGUI::WindowManager::setDefaultResourceGroup("layouts");
    CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeel");
    CEGUI::Imageset::setDefaultResourceGroup("imagesets");
    CEGUI::Font::setDefaultResourceGroup("fonts");

    CEGUI::SchemeManager::getSingleton().create("TaharezLook.scheme");


    CEGUI::FontManager::getSingleton().create( "DejaVuSans-10.font" );

    CEGUI::System::getSingleton().setDefaultFont("DejaVuSans-10");

    CEGUI::WindowManager &wm = CEGUI::WindowManager::getSingleton();

    CEGUI::Window *root = wm.loadWindowLayout("TextDemo.layout");
    CEGUI::System::getSingleton().setGUISheet(root);

    //Set cursor
    CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");

    CEGUI::System::getSingleton().setDefaultTooltip( "TaharezLook/Tooltip" );
    //Button->setTooltipText("This button will cause the self-destruct!");


//===========================
// USER INPUT
//

//Before we can do anything, we need to initialise our libraries. First SDL:
if (SDL_Init(SDL_INIT_VIDEO)<0)
{
  fprintf(stderr, "Unable to initialise SDL: %s", SDL_GetError());
  exit(0);
}


/*
As keypress characters needs to be injected into CEGUI,
we activate unicode translation for SDL key events
*/

SDL_EnableUNICODE(1);

/*
This makes it alot easier as we don't have to worry about modifier keys
and keyboard layouts ourselves. More about this later on...
Key repeat is a nice feature for the text input widgets in CEGUI, so we use SDL to generate them
*/

SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

//===========================



    AFilter() ;
    TFilter() ;

    TWorld    world;
    TBuffer gbuffer;
    TCamera camera;
    TMesh    mesh;
    TLight    light;
    TMesh    ground;
    TMaterial material;

    world = CreateWorld() ;
    if (!world) {
        MessageBoxA(0,"Error","Failed to create world.",0);
        return Terminate();
    }
   
    //Lighting Render buffer
    gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);
   
    camera=CreateCamera();







    TVec3 camrotation=Vec3(0);
    float mx=0;
    float my=0;
    float move=0;
    float strafe=0;

    //Center Mouse
    MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

    /*
    ==================================
    */

    //Load scene
    //TEntity scene=LoadScene("Maps/default.sbx");
    //ProcessScene(scene);


    PositionEntity(camera,Vec3(0,0,-2));


    // Game loop
    while( !KeyHit() && !AppTerminate() )
    {
        if( !AppSuspended() ) // We are not in focus!
        {

//===========================
            //NOCLIP - Updates every frame

            //Capture Mouse movements
            mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
            my=Curve(MouseY()-GraphicsHeight()/2,my,6);

            camrotation.X=camrotation.X+my/10.0;
            camrotation.Y=camrotation.Y-mx/10.0;
            RotateEntity(camera, camrotation);

            //Hide the cursor
            //ShowCursor(false);

            //If the shift key is pressed, move faster
            if(KeyDown(KEY_LSHIFT))
            {
                move=Curve(KeyDown(KEY_W)-KeyDown(KEY_S),move,50);
                strafe=Curve(KeyDown(KEY_D)-KeyDown(KEY_A),strafe,50);
                MoveEntity(camera, Vec3(strafe/5.0,0,move/5.0));
            }

            move=Curve(KeyDown(KEY_W)-KeyDown(KEY_S),move,50);
            strafe=Curve(KeyDown(KEY_D)-KeyDown(KEY_A),strafe,50);
            MoveEntity(camera, Vec3(strafe/20.0,0,move/20.0));

            //Center the mouse on screen (Cannot while menu is open)
            //MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

//===========================
// USER INPUT
//
// we inject the mouse position directly.
/*CEGUI::System::getSingleton().injectMousePosition(
  static_cast<float>(MouseX()),
  static_cast<float>(MouseY())
);*/





  bool must_quit = false;
 
  // get "run-time" in seconds
  double last_time_pulse = 0.001*static_cast<double>(SDL_GetTicks());
 
  SDL_Event e;
 
  // go through all available events
  while (SDL_PollEvent(&e))
  {
      MessageBox(NULL, L"An entry", NULL, NULL);
    // we use a switch to determine the event type
    switch (e.type)
    {
      // mouse motion handler
      case SDL_MOUSEMOTION:
        // we inject the mouse position directly.
        CEGUI::System::getSingleton().injectMousePosition(
          static_cast<float>(e.motion.x),
          static_cast<float>(e.motion.y)
        );
        break;
   
      // mouse down handler
      case SDL_MOUSEBUTTONDOWN:
        // let a special function handle the mouse button down event
        handle_mouse_down(e.button.button);
        break;
   
      // mouse up handler
      case SDL_MOUSEBUTTONUP:
        // let a special function handle the mouse button up event
        handle_mouse_up(e.button.button);
        break;
   
   
      // key down
      case SDL_KEYDOWN:
        // to tell CEGUI that a key was pressed, we inject the scancode.
        CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);
       
        // as for the character it's a litte more complicated. we'll use for translated unicode value.
        // this is described in more detail below.
        if ((e.key.keysym.unicode != 0))
        {
          CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);
        }
        break;
   
      // key up
      case SDL_KEYUP:
        // like before we inject the scancode directly.
        CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);
        break;
   
   
      // WM quit event occured
      case SDL_QUIT:
        //must_quit = true;
        break;
   
    }
 
  }

    inject_time_pulse(last_time_pulse);
    render_gui();



      RECT r;

      GetWindowRect( FindWindow(NULL, TEXT("Vita") ), &r);

      ClipCursor( &r );


//===========================

            // Update timing and world
            UpdateAppTime();
            UpdateWorld(AppSpeed()) ;
       
            // Render
            SetBuffer(gbuffer);
            RenderWorld();
            SetBuffer(BackBuffer());
            RenderLights(gbuffer);

            //Render UI
            glPixelStoref(0x806E, 0);
            glPixelStoref(GL_PACK_ROW_LENGTH, 0);
            glPixelStoref(GL_UNPACK_ROW_LENGTH, 0);
            CEGUI::System::getSingleton().renderGUI();

            // Send to screen
            Flip(0) ;



            //FINISH UI
        }

        ClipCursor (NULL);

    }

    // Done
    return Terminate() ;
}


As you can see, I've extracted the contents of the inject_input() function down to within the main render loop. I made it show the MessageBox for each event that occurs, but apparently only ONE event occurs at startup. So only ONE message box shows. I click & click, drag & drag, type & type, AND no events occur?
I hate BBCode pls enable <b>HTML</b> ;)

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Input_injection not working

Postby Jamarr » Thu Sep 30, 2010 16:36

...I made it show the MessageBox for each event that occurs...

Code: Select all

while (SDL_PollEvent(&e))
{
    MessageBox(NULL, L"An entry", NULL, NULL);
    ...



If your MessageBox is not being shown, you should first look at the requirements for that action to occur. In this case, it clearly looks like SDL_PollEvent is not behaving as you would expect it too. I do not see how this is in any way related to CEGUI. So either this is an SDL issue, or you have left out some other pertinent information.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Input_injection not working

Postby aaron1a12 » Thu Sep 30, 2010 18:10

I guess I should be posting in an SDL forum but it's just that since it's working with CEGUI... well.

CEGUI is still not working! :( Read on

It turns out the problem was that SDL was not attaching itself to the window I created along with CEGUI.
So to attach SDL to the main window I used the following code:

Code: Select all

// Attach SDL to the Leadwerks window
HWND window = FindWindowA(NULL, "Vita"); //My window
char variable[256];
sprintf(variable, "SDL_WINDOWID=%u", (unsigned long)window);
_putenv(variable);


HOWEVER, when I attach SDL, CEGUI stops working!

So I think; "Maybe I should try attaching then CEGUI to the SDL window, right?".

Is the following code correct for CEGUI to attach to my main window?:

Code: Select all

CEGUI::Window::setID((unsigned long)window); 


When I run it I get the error:
error C2352: 'CEGUI::Window::setID' : illegal call of non-static member function

It's because I need to initialise the CEGUI::Window class right? How do I do that? :?:
I hate BBCode pls enable <b>HTML</b> ;)

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Input_injection not working

Postby Kulik » Thu Sep 30, 2010 18:34

You seriously should learn C++ first. CEGUI isn't a good beginner's library.

To answer your question, look at CEGUI::WindowManager. And learn concepts of singletons. Hope this helps :)

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Input_injection not working

Postby aaron1a12 » Thu Sep 30, 2010 18:43

You mean to use the CEGUI getSingleton() function?

I tried
CEGUI::System::getSingleton().setID();
and
CEGUI::Window::getSingleton().setID();
and
CEGUI::WindowManager::getSingleton().setID();

Nothing works :cry:

I'm an advanced PHP/MySQL/HTML developer so I am familiar with C-like languages but C++ seems so complicated :x
I hate BBCode pls enable <b>HTML</b> ;)

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Input_injection not working

Postby Jamarr » Thu Sep 30, 2010 19:35

You are mixing two different concepts: operating-system windows and rendered windows. CEGUI is rendered onto the OS window via the Renderer. In short, setting a CEGUI window's id to the OS window's handle is not going to produce the results you expect. If you have not properly initialized your renderer to paint on the OS window then you will not see any CEGUI windows (I assume SDL handles this?). If this is your issue, it is beyond the scope of the CEGUI forums.

However, since you have not explicitly detailed your issue it is impossible for us to help you diagnose anything. First, I have never used SDL but I seriously doubt your snippet is the correct way of "attaching" SDL to an OS window; that code looks absurd. I highly doubt that a library with SDL's reputation requires an operating-system environment variable to be set for this purpose. Second, how did you verify that you fixed your SDL initialization / input problem? Last, what precisely is "not working" with CEGUI - what are you expecting to happen, and what is actually happening?

CEGUI is still not working!


Please read The Forum Usage Guidelines. We cannot assist you if you make it impossible for us to do so.

It sounds like you transitioning from a web (server/client) paradigm while also trying to jump into a lower-level language. Regardless of how much of an expert you are, you cannot do this over night. You really need to utilize the documentation that is accessible all around you instead of asking others to figure out your problems - especially problems outside their domain! There are tons of online resources for c++, for your operating system, for your compiler, for SDL, CEGUI, and any other library you want to utilize. If you try to rush it you will only find pain and misery - take things one step at a time: setup your window environment first, then setup SDL and ensure all is working, then slowly add in CEGUI - step by step, one piece at a time; do not try to integrate everything at once.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Input_injection not working

Postby aaron1a12 » Thu Sep 30, 2010 20:20

OK, I'll go into details:

My Goal
To setup the Leadwerks Engine (a 3d OpenGL library) with CEGUI rendering UI over the OpenGL using SDL for capturing USER INPUT.

So first I create the main Window with Leadwerks, then I initialise CEGUI and render it in the same loop the OpenGL engine uses. Before rendering I initialise the SDL engine for the events. Apparently SDL wasn't listening for events because it's supposed to listen to events ONLY from a window created by itself. But I couldn't create a window with SDL because I would end up with two windows. I googled and found out that SDL provides a small simple hack to attach the engine to a window created previously. THAT is the "absurd" snippet code that I use. That fixed the connection and to prove it I tried changing the window title with an SDL command and it worked (this didn't happen before the "hack"). BUT, The problem is that when I attached SDL to my Leadwerks window, CEGUI stopped injecting input. So maybe CEGUI doesn't know what window to inject the input? Thats why I wanted to try using CEGUI::Window::setID();

Get it now?

So why isn't CEGUI injecting input?

I've been following this tutorial:
http://www.cegui.org.uk/wiki/index.php/ ... and_OpenGL
I hate BBCode pls enable <b>HTML</b> ;)

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Input_injection not working

Postby aaron1a12 » Thu Sep 30, 2010 20:36

Here's my code for if anyone bothers to look at it :? :

Code: Select all

/*
//Load the engine
#include "engine.h"
//Load the scene processer
#include "ProcessScene.h"
//Load the UI engine
#include "include/CEGUI.h"
#include "include/RendererModules/OpenGL/CEGUIOpenGLRenderer.h"
//Load the input engine
#include "sdl/include/SDL.h"


void handle_mouse_down(Uint8 button)
   {
   switch ( button )
      {
      // handle real mouse buttons
      case SDL_BUTTON_LEFT:
         CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
         break;
      case SDL_BUTTON_MIDDLE:
         CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
         break;
      case SDL_BUTTON_RIGHT:
         CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
         break;
      
      // handle the mouse wheel
      case SDL_BUTTON_WHEELDOWN:
         CEGUI::System::getSingleton().injectMouseWheelChange( -1 );
         break;
      case SDL_BUTTON_WHEELUP:
         CEGUI::System::getSingleton().injectMouseWheelChange( +1 );
         break;
      }
   }


void handle_mouse_up(Uint8 button)
   {
   switch ( button )
      {
      case SDL_BUTTON_LEFT:
         CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
         break;
      case SDL_BUTTON_MIDDLE:
         CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
         break;
      case SDL_BUTTON_RIGHT:
         CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
         break;
      }
   }


void inject_input()
{
  SDL_Event e;
 
  // go through all available events
  while (SDL_PollEvent(&e))
  {
    // we use a switch to determine the event type
    switch (e.type)
    {
      // mouse motion handler
      case SDL_MOUSEMOTION:
        // we inject the mouse position directly.
        CEGUI::System::getSingleton().injectMousePosition(
          static_cast<float>(MouseX()),
          static_cast<float>(MouseY())
        );
        break;
   
      // mouse down handler
      case SDL_MOUSEBUTTONDOWN:
        // let a special function handle the mouse button down event
        handle_mouse_down(e.button.button);
        break;
   
      // mouse up handler
      case SDL_MOUSEBUTTONUP:
        // let a special function handle the mouse button up event
        handle_mouse_up(e.button.button);
        break;
   
   
      // key down
      case SDL_KEYDOWN:
        // to tell CEGUI that a key was pressed, we inject the scancode.
        CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);
       
        // as for the character it's a litte more complicated. we'll use for translated unicode value.
        // this is described in more detail below.
        if ((e.key.keysym.unicode != 0))
        {
          CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);
        }
        break;
   
      // key up
      case SDL_KEYUP:
        // like before we inject the scancode directly.
        CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);
        break;
   
   
      // WM quit event occured
      case SDL_QUIT:
        break;
   
    }
 
  }

}



void inject_time_pulse(double& last_time_pulse)
{
   // get current "run-time" in seconds
   double t = 0.001*SDL_GetTicks();

   // inject the time that passed since the last call
   CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );

   // store the new time as the last time
   last_time_pulse = t;
}


void render_gui()
{
   // clear the colour buffer
   glClear( GL_COLOR_BUFFER_BIT );

   // render the GUI :)
   CEGUI::System::getSingleton().renderGUI();

   // Update the screen
   SDL_GL_SwapBuffers();
}






int WINAPI WinMain( HINSTANCE hInstance,
               HINSTANCE hPrevInstance,
               LPSTR lpCmdLine,
               int nShowCmd )
{
   Initialize() ;
   RegisterAbstractPath("C:/vita");
   SetAppTitle( "Vita" ) ;
   Graphics( 800, 600 ) ;

/* Attach SDL to the Leadwerks window
HWND window = FindWindowA(NULL, "Vita");
char variable[256];
sprintf(variable, "SDL_WINDOWID=%u", (unsigned long)window);
_putenv(variable);
*/





//===========================
// USER INPUT
//

//Before we can do anything, we need to initialise our libraries. First SDL:
// Initializes the video subsystem
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    MessageBox(NULL, L"Unable to init SDL: %s\n", NULL, NULL);
    exit(1);
}

/*
As keypress characters needs to be injected into CEGUI,
we activate unicode translation for SDL key events
*/

SDL_EnableUNICODE(1);

/*
This makes it alot easier as we don't have to worry about modifier keys
and keyboard layouts ourselves. More about this later on...
Key repeat is a nice feature for the text input widgets in CEGUI, so we use SDL to generate them
*/

SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

//===========================



/*
*======================================================
*   UI
*======================================================
*/


   CEGUI::OpenGLRenderer &ceguiRenderer = CEGUI::OpenGLRenderer::create();
   CEGUI::System::create(ceguiRenderer);
   ceguiRenderer.enableExtraStateSettings(true);
   CEGUI::DefaultResourceProvider *rp = static_cast<CEGUI::DefaultResourceProvider*>(CEGUI::System::getSingleton().getResourceProvider());

   rp->setResourceGroupDirectory("schemes", "GUI/schemes/");   
   rp->setResourceGroupDirectory("layouts", "GUI/layouts/");
   rp->setResourceGroupDirectory("looknfeel", "GUI/looknfeel/");
   rp->setResourceGroupDirectory("imagesets", "GUI/imagesets/");
   rp->setResourceGroupDirectory("fonts", "GUI/fonts/");

   CEGUI::Scheme::setDefaultResourceGroup("schemes");
   CEGUI::WindowManager::setDefaultResourceGroup("layouts");
   CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeel");
   CEGUI::Imageset::setDefaultResourceGroup("imagesets");
   CEGUI::Font::setDefaultResourceGroup("fonts");

   CEGUI::SchemeManager::getSingleton().create("TaharezLook.scheme");


   CEGUI::FontManager::getSingleton().create( "DejaVuSans-10.font" );

   CEGUI::System::getSingleton().setDefaultFont("DejaVuSans-10");

   CEGUI::WindowManager &wm = CEGUI::WindowManager::getSingleton();

   CEGUI::Window *root = wm.loadWindowLayout("TextDemo.layout");
   CEGUI::System::getSingleton().setGUISheet(root);

   //Set cursor
   CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");

   CEGUI::System::getSingleton().setDefaultTooltip( "TaharezLook/Tooltip" );
   //Button->setTooltipText("This button will cause the self-destruct!");


   //Attach CEGUI to the SDL window (the Leadwerks window)
   //CEGUI::SY
   //CEGUI::Window::getSingleton().setID((unsigned long)window);
//slist.setID((unsigned long)window);
   //CEGUI::Window::get
   //CEGUI::Window::activate();

   //CEGUI::Window::setID((unsigned long)window);




   AFilter() ;
   TFilter() ;

   TWorld   world;
   TBuffer gbuffer;
   TCamera camera;
   TMesh   mesh;
   TLight   light;
   TMesh   ground;
   TMaterial material;

   world = CreateWorld() ;
   if (!world) {
      MessageBoxA(0,"Error","Failed to create world.",0);
      return Terminate();
   }
   
   //Lighting Render buffer
   gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);
   
   camera=CreateCamera();







   TVec3 camrotation=Vec3(0);
   float mx=0;
   float my=0;
   float move=0;
   float strafe=0;

   //Center Mouse
   MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

   /*
   ==================================
   */

   //Load scene
   //TEntity scene=LoadScene("Maps/default.sbx");
   //ProcessScene(scene);


   PositionEntity(camera,Vec3(0,0,-2));

   
//HWND fWindow; // Window handle of the window you want to get
//fWindow = FindWindow(NULL, L"Vita");

//SetWindowText(fWindow,L"Text to be..");

   SDL_WM_SetCaption("SDL Window", NULL);

   // Game loop
   while( !KeyHit() && !AppTerminate() )
   {
      if( !AppSuspended() ) // We are not in focus!
      {

//===========================
         //NOCLIP - Updates every frame

         //Capture Mouse movements
         mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
         my=Curve(MouseY()-GraphicsHeight()/2,my,6);

         camrotation.X=camrotation.X+my/10.0;
         camrotation.Y=camrotation.Y-mx/10.0;
         RotateEntity(camera, camrotation);

         //Hide the cursor
         ShowCursor(false);

         //If the shift key is pressed, move faster
         if(KeyDown(KEY_LSHIFT))
         {
            move=Curve(KeyDown(KEY_W)-KeyDown(KEY_S),move,50);
            strafe=Curve(KeyDown(KEY_D)-KeyDown(KEY_A),strafe,50);
            MoveEntity(camera, Vec3(strafe/5.0,0,move/5.0));
         }

         move=Curve(KeyDown(KEY_W)-KeyDown(KEY_S),move,50);
         strafe=Curve(KeyDown(KEY_D)-KeyDown(KEY_A),strafe,50);
         MoveEntity(camera, Vec3(strafe/20.0,0,move/20.0));

         //Center the mouse on screen (Cannot while menu is open)
         //MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

//===========================
// USER INPUT
//
// we inject the mouse position directly.
CEGUI::System::getSingleton().injectMousePosition(
  static_cast<float>(MouseX()),
  static_cast<float>(MouseY())
);
 

//MessageBox(NULL, winID, NULL, NULL);

//CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);


SDL_Event event; // Event structure
// Check for events
while(SDL_PollEvent(&event)) {  // Loop until there are no events left on the queue
  switch(event.type) { // Process the appropriate event type
    case SDL_KEYDOWN:  // Handle a KEYDOWN event
      MessageBox(NULL, L"Key pressed!", NULL, NULL);
      break;
    case SDL_MOUSEMOTION:

    default: // Report an unhandled event
      printf("I don't know what this event is!\n");
  }
}



//handle_mouse_down(MouseDown("LEFT"));


  bool must_quit = false;
 
  // get "run-time" in seconds
  double last_time_pulse = 0.001*static_cast<double>(SDL_GetTicks());



   //inject_input();
    inject_time_pulse(last_time_pulse);
    render_gui();



      RECT r;

      GetWindowRect( FindWindow(NULL, TEXT("Vita") ), &r);

      ClipCursor( &r );


//===========================

         // Update timing and world
         UpdateAppTime();
         UpdateWorld(AppSpeed()) ;
      
         // Render
         SetBuffer(gbuffer);
         RenderWorld();
         SetBuffer(BackBuffer());
         RenderLights(gbuffer);

         //Render UI
         glPixelStoref(0x806E, 0);
            glPixelStoref(GL_PACK_ROW_LENGTH, 0);
            glPixelStoref(GL_UNPACK_ROW_LENGTH, 0);
            CEGUI::System::getSingleton().renderGUI();

         // Send to screen
         Flip(0) ;



         //FINISH UI
      }

      ClipCursor (NULL);

   }

   // Done
   return Terminate() ;
}
I hate BBCode pls enable <b>HTML</b> ;)

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Input_injection not working

Postby Jamarr » Thu Sep 30, 2010 21:37

aaron1a12 wrote:The problem is that when I attached SDL to my Leadwerks window, CEGUI stopped injecting input. So maybe CEGUI doesn't know what window to inject the input? Thats why I wanted to try using CEGUI::Window::setID(); Get it now? So why isn't CEGUI injecting input?


Ok this clarified some things. Thanks you. It sounds like you still have a misunderstanding here. CEGUI does not inject input; you inject input into CEGUI and the inject functions return true/false indicating that the injected input was used by CEGUI. So for example, if you inject a MouseDown event and the mouse is over a window (and CEGUI knows it is over a window via inject MousePosition) then the inject will return true since you clicked on a window that CEGUI knows about, and you should probably consume (not propagate) the event. If you inject MouseDown and the mouse is not over a CEGUI window (or that window has mousePassThrough enabled) the inject will return false meaning the event had no effect on the GUI and so you should probably propagate (pass it on) to your application.

note: I have not looked at the code you posted yet...
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Input_injection not working

Postby IR3uL » Thu Sep 30, 2010 22:09

1st, I suggest you take into consideration Kulik's advice, one step at a time will make your life easier.

To simplify a bit your life... a see you are trying to use a lot of different libraries, and SDL is just bloating your code. I don't have experience with Leadwerks engine, but if you take a look in the wiki you'll find articles about everything (I haven't read any and I don't plan to), one of them http://www.leadwerks.com/wiki/index.php?title=Input talks about input processing.

Once you get something working with Leadwerks (I see it makes almost everything except gui stuff) you should drop some GUI stuff.

HTH (Can I borrow this from you CE? :D )

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Input_injection not working

Postby aaron1a12 » Thu Sep 30, 2010 22:23

Jamarr wrote:If you inject MouseDown and the mouse is not over a CEGUI window (or that window has mousePassThrough enabled) the inject will return false meaning the event had no effect on the GUI and so you should probably propagate (pass it on) to your application


And how do I "pass it on" to my application? With what function?
I hate BBCode pls enable <b>HTML</b> ;)

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Input_injection not working

Postby Jamarr » Thu Sep 30, 2010 22:39

aaron1a12 wrote:
Jamarr wrote:And how do I "pass it on" to my application? With what function?


There is no specific function to do this - it something you must handle / write yourself. You need to write your own Input Manager/Processor. By "application" I mean your application's logic, whatever that may be. For example, if your application expects that when you MouseDown over an object in your scene then injecting this into CEGUI (if setup properly) will return false (meaning the mouse is not over a CEGUI window) and thus you should pass the MouseDown event, yourself, to your applications logic perhaps to pickup said object. Now picture the user moved a CEGUI window over the object and clicked at the same screen position - well now the mouse is over a CEGUI window so inject* will return true meaning the user interacted with the GUI and you probably do not want to pass it onto your application logic (which would subsequently pick up the object). This is just a contrived example - the point is it is ultimately your job to manage the input.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Input_injection not working

Postby aaron1a12 » Fri Oct 01, 2010 03:16

Jamarr wrote: (meaning the mouse is not over a CEGUI window)


Right, I'll do my own Manager (already working on one) but how can I know what window is CEGUI listening for events?

Thanks for all your help btw.
I hate BBCode pls enable <b>HTML</b> ;)

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

Re: Input_injection not working

Postby CrazyEddie » Fri Oct 01, 2010 09:27

Ok, there is clearly a lot of confusion here :lol:

The absolute key thing to know here is that CEGUI is not in control of your application; it is not an application framework in the same ilk as wxWidgets, Qt or (horror, of horrors!) MFC. You and your application remain in control of all things at all times (whether your choice of rendering engine takes that control away from you is not something I have any say in!). So, this means that CEGUI is rendered only when you decide to render it, and input is received into CEGUI only when you pass it in (via the injection functions on the CEGUI::System object).

In most apps you will need to know whether a mouse event (like a button press) occurs over a UI element or not. There are multiple ways of handling this, though within CEGUI there exists a mechanism whereby you can have simple logic to decide how to deal with this in a uniform way. That mechanism is to examine the return from the input injection function[*]:

Code: Select all

if (!CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton))
{
    // Click was on the playfield, do game logic.
}

So, we can see that if the return value is true, we do no further processing of the input since we assume that CEGUI or some subscribed CEGUI event handler has marked the input as having been processed. If the return value is false it means that CEGUI did not handle this event and the input should be passed to whatever other logic your app has for handling user interaction with whatever else you are rendering (i.e. non UI elements).

CE.

[*] The prerequisites for this mechanism to work are that you have a CEGUI::DefaultWindow set as the system GUI sheet (obviously with other content attached to it), and that the DefaultWindow have the MousePassThroughEnabled property set to True.

User avatar
aaron1a12
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Wed Sep 29, 2010 21:46
Location: Miami, Florida, USA

Re: Input_injection not working

Postby aaron1a12 » Fri Oct 01, 2010 17:32

Thanks Ed and everyone else. It's all been real helpful. I get it know, and after looking and experimenting with my code I realised that CEGUI was not the problem, so I can drink this pint now :pint:
(I love that smiley). Specifically with the Mouse Input now, I have problem with SDL and my Leadwerks engine NOT CEGUI, therefore, I assume it wouldn't be logical to discuss it here. For some strange reason when I integrate SDL in the window, MouseX and Y(); (functions included with the leadwerks engine) now return zero (0) always and SDL returns mysteriously the number 65535 , the number must mean something since it even has a page in Wikipedia:

65535 is a frequently occurring number in the field of computing because it is the highest number which can be represented by an unsigned 16 bit binary number. Some computer programming environments may have pre-defined constant values representing 65535, with names like "MAX_UNSIGNED_SHORT".


So I guess I'll have to find another way to capture Mouse movements.

Thanks!
I hate BBCode pls enable <b>HTML</b> ;)


Return to “Help”

Who is online

Users browsing this forum: No registered users and 11 guests