Hello ths, this code works but i can't see the cursor, i'm in debian etch. Any suggestions ?
this is the same sample but with TaharezLookSkin.scheme:
Code: Select all
#include "CEGUI.h"
#include "renderers/OpenGLGUIRenderer/openglrenderer.h"
#include <time.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
using namespace CEGUI;
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(bool& must_quit)
{
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>(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 & 0xFF80) == 0)
{
CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode & 0x7F);
}
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;
}
}
}
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();
}
main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO)<0)
{
fprintf(stderr, "Unable to initialise SDL: %s", SDL_GetError());
exit(0);
}
if (SDL_SetVideoMode(800,600,0,SDL_OPENGL)==NULL)
{
fprintf(stderr, "Unable to set OpenGL videomode: %s", SDL_GetError());
SDL_Quit();
exit(0);
}
glEnable(GL_CULL_FACE);
glDisable(GL_FOG);
glClearColor(0.0f,0.0f,0.0f,1.0f);
glViewport(0,0, 800,600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 800.0/600.0, 0.1,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
CEGUI::OpenGLRenderer* renderer = new CEGUI::OpenGLRenderer(0,800,600);
new CEGUI::System(renderer);
SDL_ShowCursor(SDL_DISABLE);
SDL_EnableUNICODE(1);
bool must_quit = false;
// get "run-time" in seconds
double last_time_pulse = 0.001*static_cast<double>(SDL_GetTicks());
/*
WindowManager& wmgr = WindowManager::getSingleton();
Window* myRoot = wmgr.createWindow("DefaultWindow", "root");
System::getSingleton().setGUISheet(myRoot);
FrameWindow* fWnd = (FrameWindow*)wmgr.createWindow("TaharezLook/FrameWindow", "testWindow");
myRoot->addChildWindow(fWnd);
fWnd->setPosition( Point( 0.25f, 0.25f ) );
fWnd->setSize( Size( 0.5f, 0.5f ) );
fWnd->setText( "Hello World!" );
*/
WindowManager& wmgr = WindowManager::getSingleton();
SchemeManager::getSingleton().loadScheme("../datafiles/schemes/TaharezLookSkin.scheme");
Window* myRoot = wmgr.createWindow("DefaultWindow", "root");
System::getSingleton().setGUISheet(myRoot);
//FrameWindow* fWnd = (FrameWindow*)wmgr.createWindow("VanillaSkin/FrameWindow", "testWindow");
FrameWindow* fWnd = (FrameWindow*)wmgr.createWindow("TaharezLook/FrameWindow", "testWindow");
FontManager::getSingleton().createFont("../datafiles/fonts/Iconified-12.font");
myRoot->addChildWindow(fWnd);
fWnd->setPosition( Point( 0.25f, 0.25f ) );
fWnd->setSize( Size( 0.5f, 0.5f ) );
fWnd->setText( "Hello World!" );
while (!must_quit)
{
inject_input(must_quit);
inject_time_pulse(last_time_pulse);
render_gui();
}
return 0;
}
Link with:
Code: Select all
-lSDLmain -lSDL -lCEGUIBase -lCEGUIOpenGLRenderer
And put the folder "datafiles" on the top of your binary(or exe) folder:
PD: datafiles comes in the folder Samples with the source of CEGUI:
cegui_mk2-source-0.4.1.tar.bz2
And sorry my english i'am from Perú
SOLVEDDD::
Change
new CEGUI::System(renderer);
with
CEGUI::System *mySystem = new CEGUI::System(renderer);
and you can add:
mySystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
and ther is , now you have a nice cursor
bytes thx again