Hi...
I want a menu with 4 buttons and when i press one of them, every buton on the screen disappear and should appear 2 new butons.
I read all topics about it and:
1. I created 4 butons.
2. I subscribed 4 handle events for each buton.
But what should i do for disappear all buttons and appear the news butons?
First i Created 6 buttons. On the first 4 call setVisible(true) and on the other two call setVisible(false). This will show the first four and hide the last two, then on the button press do the opposite.
But a Windows error is generated:
AppName: dragon.exe AppVer: 0.0.0.0 ModName: ceguibase_d.dll
ModVer: 0.0.0.0 Offset: 0020255b
Logs doesn't have errors.
Error is generated when i to put setVisible(Bool) in the code and i press a button.
I quit it and Ogre runs OK. But my buttons don't disappear.
Do miss i something?
Thanks for all your help...
What should i do for disappear all buttons?
Moderators: CEGUI MVP, CEGUI Team
-
- Just popping in
- Posts: 8
- Joined: Tue Jul 25, 2006 23:57
- Location: Colombia
- Contact:
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
You need to debug into that and find out where exactly the crach is happening; the information presented at the moment is not enough to be able to offer any suggestions.
So, please post some diagnostic information, such as a call-stack / backtrace, and also some source for the offending block of code in your app.
CE.
So, please post some diagnostic information, such as a call-stack / backtrace, and also some source for the offending block of code in your app.
CE.
-
- Just popping in
- Posts: 8
- Joined: Tue Jul 25, 2006 23:57
- Location: Colombia
- Contact:
What should i do for disappear all buttons?
Thanks for your answer CrazyEddie...
The application code:
The handle method of SALIR button (quit) works very well, but the others doesn't work.
Thanks CrazzyEddie (again)
PD: Sorry for my Englilsh
The application code:
Code: Select all
/*
-----------------------------------------------------------------------------
Filename: borrar.h
Description: Es el codigo fuente de la aplicacion
-----------------------------------------------------------------------------
*/
#include <CEGUI/CEGUIImageset.h>
#include <CEGUI/CEGUISystem.h>
#include <CEGUI/CEGUILogger.h>
#include <CEGUI/CEGUISchemeManager.h>
#include <CEGUI/CEGUIWindowManager.h>
#include <CEGUI/CEGUIWindow.h>
#include <CEGUI/elements/CEGUICombobox.h>
#include <CEGUI/elements/CEGUIListbox.h>
#include <CEGUI/elements/CEGUIListboxTextItem.h>
#include <CEGUI/elements/CEGUIPushButton.h>
#include <CEGUI/elements/CEGUIScrollbar.h>
#include <CEGUI/elements/CEGUIStaticImage.h>
#include "OgreCEGUIRenderer.h"
#include "OgreCEGUIResourceProvider.h"
#include "inicializacionOgre.h"
#include "inicializacionCEGUI.h"
//metodo para convertir eventos sobre los botones a eventos de CEGUI
CEGUI::MouseButton convertirOgreButtonACegui(int buttonID)
{ switch (buttonID)
{ case MouseEvent::BUTTON0_MASK:
return CEGUI::LeftButton;
case MouseEvent::BUTTON1_MASK:
return CEGUI::RightButton;
case MouseEvent::BUTTON2_MASK:
return CEGUI::MiddleButton;
case MouseEvent::BUTTON3_MASK:
return CEGUI::X1Button;
default:
return CEGUI::LeftButton;
}
}
//Listener de Ogre, subclase de la clase configuracionOgre
class MyListener : public configuracionOgre, public MouseMotionListener, public MouseListener
{
public:
//constructor
MyListener(RenderWindow* win, Camera* cam, CEGUI::Renderer* renderer)
: configuracionOgre(win, cam, true, true),
mGUIRenderer(renderer),
mGUISystem(0),
mShutdownRequested(false)
{ mEventProcessor->addMouseMotionListener(this);
mEventProcessor->addMouseListener(this);
mEventProcessor->addKeyListener(this);
//para que el cursor sea visible
CEGUI::System::getSingleton().injectMouseMove(mInputDevice->getMouseRelativeX(), mInputDevice->getMouseRelativeY());
}
//metodos para manejo de eventos de mouse de CEGUI, son llamados automaticamente por
//Ogre mediante configuracionOgre.h
//metodo para mover el mouse
void mouseMoved(MouseEvent *e)
{ CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
e->consume();
}
//metodo para arrastrar el mouse
void mouseDragged(MouseEvent *e)
{ //hace lo mismo que cuando se mueve el mouse
mouseMoved(e);
}
//metodo para cuando se presiona el mouse
void mousePressed(MouseEvent *e)
{ //evento de mouse down
CEGUI::System::getSingleton().injectMouseButtonDown(convertirOgreButtonACegui(e->getButtonID()));
e->consume();
}
//metodo para despues de presionar el mouse
void mouseReleased(MouseEvent *e)
{ //evento de mouse up
CEGUI::System::getSingleton().injectMouseButtonUp(convertirOgreButtonACegui(e->getButtonID()));
e->consume();
}
//metodo para cuando se presiona el mouse
void mouseClicked(MouseEvent* e)
{
}
//metodo para cuando el mouse entre a un area
void mouseEntered(MouseEvent* e)
{
}
//metodo para cuando el mouse salga de un area
void mouseExited(MouseEvent* e)
{
}
//metodo para cuando se presiona una tecla
void keyPressed(KeyEvent* e)
{ //tecla ESC para salir
if(e->getKey() == KC_ESCAPE)
{ mShutdownRequested = true;
e->consume();
return;
}
//tecla de visualizacion de estadisticas
if (e->getKey() == KC_F)
{ mStatsOn = !mStatsOn;
showDebugOverlay(mStatsOn);
}
//tecla para toma de screenshoot
if (e->getKey() == KC_SYSRQ)
{ char tmp[20];
sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
mWindow->writeContentsToFile(tmp);
mWindow->setDebugText(String("Wrote ") + tmp);
}
//tecla de forma de renderizado
if (e->getKey() == KC_R)
{ mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
switch(mSceneDetailIndex)
{ //modo solido (por defecto)
case 0 : mCamera->setPolygonMode(PM_SOLID);
break ;
//modo wireframe
case 1 : mCamera->setPolygonMode(PM_WIREFRAME);
break ;
//modo de puntos
case 2 : mCamera->setPolygonMode(PM_POINTS);
break ;
}
}
//evento de key down
CEGUI::System::getSingleton().injectKeyDown(e->getKey());
//evento de inject character
CEGUI::System::getSingleton().injectChar(e->getKeyChar());
e->consume();
}
//metodo para cuando se libera una tecla
void keyReleased(KeyEvent* e)
{ //evento de key up
CEGUI::System::getSingleton().injectKeyUp(e->getKey());
e->consume();
}
//metodo para cuando se presiona una tecla
void keyClicked(KeyEvent* e)
{ //no hace nada
e->consume();
}
//Dice al listener cuando parar
void requestShutdown(void)
{ mShutdownRequested = true;
}
//declaracion de todo lo que se hace al inicio del frame
bool frameStarted(const FrameEvent& evt)
{ //si hay requerimiento de salida sale del ciclo
if(mShutdownRequested)
return false;
else
//de lo contrario continua
return configuracionOgre::frameStarted(evt);
}
//declaracion de todo lo que se hace al final de frame
bool frameEnded(const FrameEvent& evt)
{ //si hay requerimiento de salida sale del ciclo
if (mShutdownRequested)
return false;
else
//de lo contrario continua
return configuracionOgre::frameEnded(evt);
}
private:
//atributos de la clase (members)
CEGUI::Renderer* mGUIRenderer;
CEGUI::System* mGUISystem;
bool mShutdownRequested;
};
//La aplicacion. Subclase de inicializacionOgre
class SampleApp : public inicializacionOgre
{
public:
//constructor
SampleApp()
: mGUIRenderer(0),
mGUISystem(0),
mEditorGuiSheet(0)
{
}
//destructor
~SampleApp()
{ //destruye todo
if(mEditorGuiSheet)
{ CEGUI::WindowManager::getSingleton().destroyWindow(mEditorGuiSheet);
}
if(mGUISystem)
{ delete mGUISystem;
mGUISystem = 0;
}
if(mGUIRenderer)
{ delete mGUIRenderer;
mGUIRenderer = 0;
}
}
//metodo para controlar los eventos sobre la GUI
void setupEventos(void)
{ //ventana inicial
//manager de ventana
CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
//evento de push button para el boton salir
wmgr.getWindow((CEGUI::utf8*)"SALIR")->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&SampleApp::eventoSalir, this));
//evento de push button para el boton opciones
wmgr.getWindow((CEGUI::utf8*)"OPCIONES")->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&SampleApp::eventoOpciones, this));
//evento de push button para el boton cargar
wmgr.getWindow((CEGUI::utf8*)"CARGAR JUEGO")->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&SampleApp::eventoCargar, this));
//evento de push button para el boton jugar
wmgr.getWindow((CEGUI::utf8*)"INICIAR JUEGO")->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&SampleApp::eventoJugar, this));
//evento de push button para el boton aceptar
wmgr.getWindow((CEGUI::utf8*)"ACEPTAR")->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&SampleApp::eventoAceptar, this));
}
//metodo para salir
bool eventoSalir(const CEGUI::EventArgs& e)
{ //requerimiento de salida
static_cast<MyListener*>(mFrameListener)->requestShutdown();
return true;
}
//metodo para opciones
bool eventoOpciones(const CEGUI::EventArgs& e)
{ /*jugar->setVisible(false);
cargar->setVisible(false);
opciones->setVisible(false);
salir->setVisible(false);
aceptar->setVisible(true);*/
return true;
}
//metodo para cargar
bool eventoCargar(const CEGUI::EventArgs& e)
{ return true;
}
//metodo para jugar
bool eventoJugar(const CEGUI::EventArgs& e)
{ return true;
}
//metodo para aceptar
bool eventoAceptar(const CEGUI::EventArgs& e)
{ /*cargar->setVisible(true);
opciones->setVisible(true);
salir->setVisible(true);
aceptar->setVisible(false);*/
return true;
}
private:
//atributos de la clase (members)
CEGUI::OgreCEGUIRenderer* mGUIRenderer;
CEGUI::System* mGUISystem;
bool mNuevoGUI;
//ventana de GUI
CEGUI::Window* mEditorGuiSheet;
//elementos de CEGUI
//botones
CEGUI::PushButton* jugar;
CEGUI::PushButton* cargar;
CEGUI::PushButton* opciones;
CEGUI::PushButton* salir;
CEGUI::PushButton* aceptar;
typedef std::map<CEGUI::String, CEGUI::String> DescriptionMap;
DescriptionMap mDescriptionMap;
protected:
//metodo de cracion de camara (override)
virtual void createCamera(void)
{ // create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");
// set its position, direction
mCamera->setPosition(Vector3(450, 20, 40));
mCamera->setDirection(0.0, 0.0, 1.0);
//mCamera->lookAt(Vector3(0, 0, 0));
mCamera->setNearClipDistance(5);
}
//metodo de creacion de viewport (override)
virtual void createViewports(void)
{ // Create one viewport, entire window
Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(ColourValue(0, 0, 0));
// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
}
//metodo de eleccion de scene manager (override)
void chooseSceneManager(void)
{ //scena manager para terreno
mSceneMgr = mRoot->createSceneManager(ST_EXTERIOR_CLOSE);
//inicializa todos los recursos para sky
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
//metodo de creacion de la escena (override)
void createScene(void)
{ //iniciar CEGUI
iniciarCEGUI();
//la escena
mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
//skydome
mSceneMgr->setSkyDome(true, "Examples/MenuSky", 10, 8, 1500);
//**********elementos GUI de la escena************
//configuracion de eventos sobre GUI
//gui inicial
//boton de salida. Nombre: SALIR
crearBoton(salir, CEGUI::Point(0.65, 0.75), CEGUI::Size(0.2, 0.05), "SALIR");
//boton de opciones de juego. Nombre: OPCIONES
crearBoton(opciones, CEGUI::Point(0.65, 0.65), CEGUI::Size(0.2, 0.05), "OPCIONES");
//boton de cargar juego. Nombre: CARGAR JUEGO
crearBoton(cargar, CEGUI::Point(0.65, 0.55), CEGUI::Size(0.2, 0.05), "CARGAR JUEGO");
//boton de iniciar juego. Nombre: INICIAR JUEGO
crearBoton(jugar, CEGUI::Point(0.65, 0.45), CEGUI::Size(0.2, 0.05), "INICIAR JUEGO");
//boton de iniciar aceptar configuracion. Nombre: ACEPTAR
crearBoton(aceptar, CEGUI::Point(0.40, 0.70), CEGUI::Size(0.2, 0.05), "ACEPTAR");
aceptar->setVisible(false);
//control de eventos sobre la GUI
setupEventos();
}
//metodo para crear un boton
void crearBoton(CEGUI::PushButton* id, CEGUI::Point P, CEGUI::Size S, CEGUI::String texto)
{ //creacion de objeto boton
id = (CEGUI::PushButton*)CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button", texto);
//se agrega el boton a la ventana padre de CEGUI
mEditorGuiSheet->addChildWindow(id);
//posicion de boton
id->setPosition(P);
//tamaño de boton
id->setSize(S);
//texto en boton
id->setText(texto);
}
//metodo de inicializacion de CEGUI (override)
virtual void iniciarCEGUI()
{ //iniciliza la venta de CEGUI
mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
//inicializa el renderer
mGUISystem = new CEGUI::System(mGUIRenderer);
//inicializa el log de CEGUI (puede ser tambien Standard, Errors, o Insane)
CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
//cargar el esquema, setup de mouse y fuente
CEGUI::SchemeManager::getSingleton().loadScheme( (CEGUI::utf8*)"TaharezLookSkin.scheme");
mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseMoveCursor");
mGUISystem->setDefaultFont((CEGUI::utf8*)"BlueHighway-12");
//crea un objeto ventana de CEGUI
mEditorGuiSheet= CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"DefaultWindow", (CEGUI::utf8*)"Sheet");
//adiciona la ventana al renderer de CEGUI
mGUISystem->setGUISheet(mEditorGuiSheet);
}
//Crea un nuevo frame listener
void createFrameListener(void)
{ mFrameListener = new MyListener(mWindow, mCamera, mGUIRenderer);
//agrega el listener al Root de Ogre
mRoot->addFrameListener(mFrameListener);
}
};
#ifdef __cplusplus
extern "C" {
#endif
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
//aplicacion solo de Win32
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
{ //Instancia la subclase
SampleApp myApp;
try
{ //Inicia a renderizar.
myApp.go();
}
catch (Ogre::Exception& e)
{ MessageBox(NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
return 1;
}
return 0;
}
#ifdef __cplusplus
}
#endif
The handle method of SALIR button (quit) works very well, but the others doesn't work.
Thanks CrazzyEddie (again)
PD: Sorry for my Englilsh
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Hi,
I believe the code to initialise the button pointers is bad; you are passing a pointer, which is effectively lost upon exit from the crearBoton member. To do what you are trying to do, you should be passing a pointer to a pointer...
So, the signature for crearBoton should be:
You'll also need a couple of other minor adjustments to the code that call that member (change the way it passes the argument), and also within crearBoton where the member gets assigned.
Hope this helps.
CE.
I believe the code to initialise the button pointers is bad; you are passing a pointer, which is effectively lost upon exit from the crearBoton member. To do what you are trying to do, you should be passing a pointer to a pointer...
So, the signature for crearBoton should be:
Code: Select all
void crearBoton(CEGUI::PushButton** id, CEGUI::Point P, CEGUI::Size S, CEGUI::String texto)
You'll also need a couple of other minor adjustments to the code that call that member (change the way it passes the argument), and also within crearBoton where the member gets assigned.
Hope this helps.
CE.
-
- Just popping in
- Posts: 8
- Joined: Tue Jul 25, 2006 23:57
- Location: Colombia
- Contact:
What should i do for disappear all buttons?
Thank you so much CrazyEddie
I changed the member like:
Thanks, thanks, thanks...
Greetings
I changed the member like:
Code: Select all
//metodo para crear un boton
void crearBoton(CEGUI::PushButton** id, CEGUI::Point P, CEGUI::Size S, CEGUI::String texto)
{ //creacion de objeto boton
*id = (CEGUI::PushButton*)CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button", texto);
//se agrega el boton a la ventana padre de CEGUI
mEditorGuiSheet->addChildWindow(*id);
//posicion de boton
(*id)->setPosition(P);
//tamaño de boton
(*id)->setSize(S);
//texto en boton
(*id)->setText(texto);
}
Thanks, thanks, thanks...
Greetings
Who is online
Users browsing this forum: No registered users and 12 guests