How can I get which button I licked ?

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
noname
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Wed Jan 12, 2005 12:06

How can I get which button I licked ?

Postby noname » Mon Feb 28, 2005 03:17

If there several buttons on the same plane ,how can I get which button I licked ?


By the way , I want words "WrapCentred" in StaticText but can not make it ,the code is:

CEGUI::String infor((utf8*)"Hellow , world !") ;
StaticText* Infor = (StaticText*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/StaticText", (utf8*)"ESGUIInforPlane");
msgBox->addChildWindow(Infor);
Infor->setPosition(Point(0.05f, 0.15f));
Infor->setSize(Size(0.9f, 0.65f));
Infor->setFrameEnabled(false);
Infor->setBackgroundEnabled(false);
Infor->setVerticalFormatting(StaticText::VertCentred);
Infor->setHorizontalFormatting(StaticText::WordWrapCentred);
Infor->setText(infor);

what's wrong with me ?

User avatar
spannerman
Home away from home
Home away from home
Posts: 330
Joined: Wed Jan 12, 2005 12:06

Re: How can I get which button I licked ?

Postby spannerman » Mon Feb 28, 2005 08:41

Hi noname,

noname wrote:
If there several buttons on the same plane ,how can I get which button I licked ?


What do you mean by on the same plane? You know which button you have clicked on because a clicked event can trigger one of your own methods to run, like this:

Code: Select all

pushBut->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&myPanelFile::handleButtonPressed, this));


If you want to use the event method to listen to muliple buttons, you can get the button name by doing this:

Code: Select all

CEGUI::PushButton* btnPushTemp = (CEGUI::PushButton*)((const CEGUI::WindowEventArgs&)e).window;
   Ogre::String butName = btnPushTemp->getName().c_str();


Hope that helps.

By the way, please post these questions in the help forums.

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

Re: How can I get which button I licked ?

Postby CrazyEddie » Mon Feb 28, 2005 09:50

noname wrote:
By the way , I want words "WrapCentred" in StaticText but can not make it

At first glance the code looked ok. Can you link to some screenshots which show how the behaviour is incorrect (for the purposes of the test, re-enable the static text frame so we can see exactly where the issue lies).

I have moved this topic to the Help forum.

CE.

User avatar
noname
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Wed Jan 12, 2005 12:06

Re: How can I get which button I licked ?

Postby noname » Tue Mar 01, 2005 01:44

First , I'm sorry for wrong place when posting :oops: .

The StaticText works nicely now . I think that it is Chinese words cause this.After I modify the process of the
Chinese,... ;)

About the buttons I am trying . Thanks .


Another question , I can not move the Mouse Cursor to somewhere , here are some screenshots :
(files)

Here are some related codes:

void ESGUISys::InitESGUISys( void ) //<! Init
{

mRendererSys = new CEGUI::OpenGLRenderer(1024); /// CEGUI OpenGL Rendering System
new CEGUI::System(mRendererSys);
buildESGUI();
registerEventListeners();
}

void ESGUISys::MouseMotionProcesse( int x, int y ) //<! handle WM_MOUSEMOVE
{
deltaMouseX =x - deltaMouseX ;
deltaMouseY =y - deltaMouseY ;
CEGUI::System::getSingleton().injectMouseMove(deltaMouseX, deltaMouseY);

deltaMouseX = x ;
deltaMouseY = y ;
}


////////////////////////////////////////////////////////////////////////////////////
// GLOBALS
////////////////////////////////////////////////////////////////////////////////////
void initOpenGLSys( void )
{
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));

pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 16;

g_hDC = GetDC( g_hWnd );
GLuint iPixelFormat = ChoosePixelFormat( g_hDC, &pfd );

if( iPixelFormat != 0 )
{
PIXELFORMATDESCRIPTOR bestMatch_pfd;
DescribePixelFormat( g_hDC, iPixelFormat, sizeof(pfd), &bestMatch_pfd );

// TO DO: Double-check the closet match pfd for anything unacceptable...

if( bestMatch_pfd.cDepthBits < pfd.cDepthBits )
{
// POTENTIAL PROBLEM: We need at least a 16-bit z-buffer!
return;
}

if( SetPixelFormat( g_hDC, iPixelFormat, &pfd) == FALSE )
{
DWORD dwErrorCode = GetLastError();
// TO DO: Report cause of failure here...
return;
}
}
else
{
DWORD dwErrorCode = GetLastError();
// TO DO: Report cause of failure here...
return;
}

g_hRC = wglCreateContext( g_hDC );
wglMakeCurrent( g_hDC, g_hRC );

glClearColor( 0.35f, 0.53f, 0.7f, 1.0f );
}

// Desc: The window's message handler
LRESULT CALLBACK WindowProc( HWND hWnd , UINT msg , WPARAM wParam , LPARAM lParam )
{
switch( msg )
{
//.......
case WM_MOUSEMOVE:
{
POINT mousePos;
mousePos.x = (int)LOWORD(lParam);
mousePos.y = (int)HIWORD(lParam);
gESGUISysApp.MouseMotionProcesse( mousePos.x , mousePos.y ); /// Calling
break;
}
}
//.......
}

User avatar
noname
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Wed Jan 12, 2005 12:06

Re: How can I get which button I licked ?

Postby noname » Tue Mar 01, 2005 02:51

I mean how can i make a message box like MS Window's MessageBox,here are some codes:

static int clickedButton = -1 ;
static bool handleESMessageBoxOKButton(const CEGUI::EventArgs& e); // OK 按钮的操作
static bool handleESMessageBoxCancelButton(const CEGUI::EventArgs& e); // Cancel 按钮的操作
static bool handleESMessageBoxRetryButton(const CEGUI::EventArgs& e); // Retry 按钮的操作
int ESMessageBox( const CEGUI::String & boxTitle , const CEGUI::String & infor , ESWndStyle style /* = ESWS_OK */)
{
using namespace CEGUI ;
clickedButton = -1 ;
Window* rootWnd = System::getSingleton().getGUISheet();
float height = rootWnd->getHeight();
try{
Window* hWnd = WindowManager::getSingleton().getWindow((utf8*)"ESGUIMSWindow" ) ;
if(hWnd) // if existed then we destroy it
WindowManager::getSingleton().destroyWindow((utf8*)"ESGUIMSWindow" ) ;
}catch (CEGUI::Exception & e )
{
// skip the exception and go on
}
FrameWindow* msgBox = (FrameWindow*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/FrameWindow", (utf8*)"ESGUIMSWindow" ) ;
rootWnd->addChildWindow(msgBox);
msgBox->setPosition(Point(0.2f, 0.3f));
msgBox->setAlwaysOnTop(true);
msgBox->setSize(Size(0.5f, 0.4f));
msgBox->setCloseButtonEnabled(false);
msgBox->setText(boxTitle);//

//----------------------------------------------------
// MessageBox窗口---信息提示
StaticText* Infor = (StaticText*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/StaticText", (utf8*)"ESGUIInforPlane" ) ;
msgBox->addChildWindow(Infor);
Infor->setPosition(Point(0.05f, 0.15f));
Infor->setSize(Size(0.9f, 0.65f));
Infor->setFrameEnabled(false);
Infor->setBackgroundEnabled(false);
Infor->setVerticalFormatting(StaticText::VertCentred);
Infor->setHorizontalFormatting(StaticText::WordWrapCentred);
Infor->setText(infor);


//----------------------------------------------------
switch(style)
{
case ESWS_OK:// button OK
{
PushButton* ok = (PushButton*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/Button", (utf8*)"ESGUIMSOKButton" ) ;
msgBox->addChildWindow(ok);
ok->setText((utf8*)"确定" ) ;
ok->setPosition(Point( 0.35f , height - 0.15f));
ok->setSize(Size(0.2f, 0.1f));
ok->subscribeEvent(PushButton::EventClicked, &handleESMessageBoxOKButton);
//ok->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&handleESMessageBoxOKButton, this));
break;
}
case ESWS_CANCEL:// button CANCEL
{
PushButton* cancel = (PushButton*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/Button", (utf8*)"ESGUIMSCancelButton" ) ;
msgBox->addChildWindow(cancel);
cancel->setText((utf8*)"取消" ) ;
cancel->setPosition(Point( 0.35f , height - 0.15f));
cancel->setSize(Size(0.2f, 0.1f));
cancel->subscribeEvent(PushButton::EventClicked, &handleESMessageBoxCancelButton);
break;
}
case ESWS_OKCANCEL:// button
{
PushButton* ok = (PushButton*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/Button", (utf8*)"ESGUIMSOKButton" ) ;
msgBox->addChildWindow(ok);
ok->setText((utf8*)"确定" ) ;
ok->setPosition(Point( 0.15f , height - 0.15f));
ok->setSize(Size(0.2f, 0.1f));
ok->subscribeEvent(PushButton::EventClicked, &handleESMessageBoxOKButton);

PushButton* cancel = (PushButton*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/Button", (utf8*)"ESGUIMSCancelButton" ) ;
msgBox->addChildWindow(cancel);
cancel->setText((utf8*)"取消" ) ;
cancel->setPosition(Point( 0.65f , height - 0.15f));
cancel->setSize(Size(0.2f, 0.1f));
cancel->subscribeEvent(PushButton::EventClicked, &handleESMessageBoxCancelButton);
break;
}
case ESWS_OKRETRY:// button
{
PushButton* ok = (PushButton*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/Button", (utf8*)"ESGUIMSOKButton" ) ;
msgBox->addChildWindow(ok);
ok->setText((utf8*)"确定" ) ;
ok->setPosition(Point( 0.15f , height - 0.15f));
ok->setSize(Size(0.2f, 0.1f));
ok->subscribeEvent(PushButton::EventClicked, &handleESMessageBoxRetryButton);

PushButton* retry = (PushButton*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/Button", (utf8*)"ESGUIMSRetryButton" ) ;
msgBox->addChildWindow(retry);
retry->setText((utf8*)"重试" ) ;
retry->setPosition(Point( 0.65f , height - 0.15f));
retry->setSize(Size(0.2f, 0.1f));
retry->subscribeEvent(PushButton::EventClicked, &handleESMessageBoxOKButton ) ;
break;
}
case ESWS_OKCANCELRETRY:// button
{
PushButton* ok = (PushButton*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/Button", (utf8*)"ESGUIMSOKButton" ) ;
msgBox->addChildWindow(ok);
ok->setText((utf8*)"确定" ) ;
ok->setPosition(Point( 0.1f , height - 0.15f));
ok->setSize(Size(0.2f, 0.1f));
ok->subscribeEvent(PushButton::EventClicked, &handleESMessageBoxOKButton);

PushButton* cancel = (PushButton*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/Button", (utf8*)"ESGUIMSCancelButton" ) ;
msgBox->addChildWindow(cancel);
cancel->setText((utf8*)"取消" ) ;
cancel->setPosition(Point( 0.4f , height - 0.15f));
cancel->setSize(Size(0.2f, 0.1f));
cancel->subscribeEvent(PushButton::EventClicked, &handleESMessageBoxCancelButton);

PushButton* retry = (PushButton*)WindowManager::getSingleton().createWindow((utf8*)"TaharezLook/Button", (utf8*)"ESGUIMSRetryButton" ) ;
msgBox->addChildWindow(retry);
retry->setText((utf8*)"重试" ) ;
retry->setPosition(Point( 0.7f , height - 0.15f));
retry->setSize(Size(0.2f, 0.1f));
retry->subscribeEvent(PushButton::EventClicked, &handleESMessageBoxRetryButton ) ;
break;
}
}
return clickedButton ;
}

//------------------------------------------------------------------------------------------------------
bool handleESMessageBoxOKButton(const CEGUI::EventArgs& e)
{
using namespace CEGUI;

WindowManager::getSingleton().getWindow((utf8*)"ESGUIMSWindow" )->hide() ;
clickedButton = 0 ;
return true;
}

//------------------------------------------------------------------------------------------------------
static bool handleESMessageBoxCancelButton(const CEGUI::EventArgs& e) // Cancel 按钮的操作
{
using namespace CEGUI;

WindowManager::getSingleton().getWindow((utf8*)"ESGUIMSWindow" )->hide() ;
clickedButton = 1 ;
return true;
}

//------------------------------------------------------------------------------------------------------
static bool handleESMessageBoxRetryButton(const CEGUI::EventArgs& e) // Retry 按钮的操作
{
using namespace CEGUI;

WindowManager::getSingleton().getWindow((utf8*)"ESGUIMSWindow" )->hide() ;
clickedButton = 2 ;
return true;
}

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

Re: How can I get which button I licked ?

Postby CrazyEddie » Tue Mar 01, 2005 14:08

So what am I supposed to be telling you? You're code for the message box seems to be taking the right general approach. I can't be expected to write half you app for you surely?

Man I'm getting tired of all this, :lol:


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 13 guests