Code: Select all
VOID CEGUIBase::CreateBase(LPDIRECT3DDEVICE9 pDevice)
{
this->d_lastFrameTime = GetTickCount();
this->d_resourceProvider = 0;
this->d_imageCodec = 0;
try {
new CEGUI::DefaultLogger();
CEGUI::DefaultLogger::getSingleton().setLoggingLevel(CEGUI::Insane);
CEGUI::DefaultLogger::getSingleton().setLogFilename("D:\\CEGUI_LOG\\GEGUI.log");
this->d_renderer = &CEGUI::Direct3D9Renderer::bootstrapSystem(pDevice);
}
catch (CEGUI::Exception e)
{
fods("ERROR BOOTSTRAPING THE SYSTEM\n");
}
this->initialiseResourceGroupDirectories();
this->initialiseDefaultResourceGroups();
MainMenu * mainMenu = new MainMenu();
mainMenu->initialise(&CEGUI::System::getSingleton().getDefaultGUIContext());
}
Here is my EndScene , thats what i'm using to display MainMenu :
Code: Select all
HRESULT WINAPI myEndScene( LPDIRECT3DDEVICE9 pDevice )
{
_asm pushad;
if ( ! InitCEGUI ){
CEGuiBase->CreateBase(pDevice);
CEGuiBase->CEGUIRenderUI(pDevice); // Fix for Full-Screen Hang
InitCEGUI = true;
}
SHORT PRESSED = GetAsyncKeyState(VK_INSERT);
if ((PRESSED&1) && (MenuSet == FALSE) )
MenuSet = true;
else if ((PRESSED&1) && (MenuSet == TRUE) )
MenuSet = false;
if ( MenuSet == true )
{
CEGuiBase->CEGUIRenderUI(pDevice);
}
_asm popad;
return pEndScene( pDevice );
}
First weird thing is that when i have a d3d9 game running at FullScreen and i start my hooks without CEGuiBase->CEGUIRenderUI(pDevice); at InitCEGUI Condition the application HANGS and i must Kill it ,no black screen or any Error.
Anyways using Windowed mode solves the problem too.
Here is my CEGUIRenderUI:
Code: Select all
BOOL CEGUIBase::CEGUIRenderUI(LPDIRECT3DDEVICE9 pDevice)
{
static bool WaitingForReset = false;
static bool MyGUIInitAttempted = false;
HRESULT coop;
if ( !MyGUIInitAttempted )
{
MyGUIInitAttempted = true;
}
CEGUI::System& guiSystem = CEGUI::System::getSingleton();
DWORD thisTime = GetTickCount();
float elapsed = static_cast<float>(thisTime - d_lastFrameTime);
d_lastFrameTime = thisTime;
guiSystem.injectTimePulse( elapsed / 1000.0f );
coop = pDevice->TestCooperativeLevel();
if( coop == D3DERR_DEVICELOST || coop == D3DERR_DEVICENOTRESET )
{
if ( !WaitingForReset )
{
WaitingForReset = true;
static_cast<CEGUI::Direct3D9Renderer*>(d_renderer)->preD3DReset();
}
return true;
}
else if ( coop == D3D_OK )
{
if ( WaitingForReset )
{
WaitingForReset = false;
//d_renderer->postD3DReset();
static_cast<CEGUI::Direct3D9Renderer*>(d_renderer)->postD3DReset();
return true;
}
}
try
{
IDirect3DStateBlock9* pStateBlock = NULL;
pDevice->CreateStateBlock( D3DSBT_ALL, &pStateBlock );
CEGUI::System::getSingleton().renderAllGUIContexts();
if ( pStateBlock )
{
pStateBlock->Apply();
pStateBlock->Release();
return true;
}
}
catch ( CEGUI::Exception e )
{
fods( "MyGUIRender() -> renderGUI() FAILED: Error message: %s", e.what() );
}
return false;
}
My MainMenu is just a copy paste of HelloWorld Demo :
Code: Select all
bool MainMenu::initialise(CEGUI::GUIContext* guiContext)
{
using namespace CEGUI;
SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
guiContext->getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");
WindowManager& winMgr = WindowManager::getSingleton();
d_root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
Font& defaultFont = FontManager::getSingleton().createFromFile("DejaVuSans-12.font");
guiContext->setDefaultFont(&defaultFont);
guiContext->setRootWindow(d_root);
FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "Demo1 Window");
d_root->addChild(wnd);
wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
wnd->setSize(USize(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
wnd->setMaxSize(USize(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
wnd->setMinSize(USize(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
wnd->setText("Hello!! World!");
wnd->subscribeEvent(CEGUI::Window::EventMouseClick, Event::Subscriber(&MainMenu::handleMainMenuClicked, this));
return true;
}
And HandleMainMenuClicked just prints "CLICKED" String.
The way i'm injecting inputs within application right now its using a SystemWideHookEx and parsing messages within a switch case:
Code: Select all
bool CEGUIInjections::InjectToCEGUI( LPMSG msg ,WPARAM wParam, LPARAM lParam)
{
switch( msg->message )
{
case WM_CHAR:
this->injectChar((CEGUI::utf32)wParam);
SendMessage( hWndServer, WM_CHAR, 0, 0);
break;
case WM_MOUSELEAVE:
this->mouseLeaves();
SendMessage( hWndServer, WM_MOUSELEAVE, 0, 0);
break;
case WM_NCMOUSEMOVE:
this->mouseLeaves();
SendMessage( hWndServer, UWM_MOUSEMOVE, 0, 0);
break;
case WM_MOUSEMOVE:
mouseEnters();
this->injectMousePosition((float)(LOWORD(lParam)), (float)(HIWORD(lParam)));
SendMessage( hWndServer, UWM_MOUSEMOVE, 0, 0);
break;
case WM_LBUTTONUP:
fods("UPP\n");
this->injectMouseButtonUp(CEGUI::LeftButton);
SendMessage( hWndServer, UWM_MOUSELBUTTONUP, 0 , 0 );
break;
case WM_RBUTTONDOWN:
injectMouseButtonDown(CEGUI::RightButton);
SendMessage( hWndServer, WM_RBUTTONDOWN, 0 , 0 );
break;
case WM_RBUTTONUP:
this->injectMouseButtonUp(CEGUI::RightButton);
SendMessage( hWndServer, WM_RBUTTONUP, 0 , 0 );
break;
case WM_MBUTTONDOWN:
this->injectMouseButtonDown(CEGUI::MiddleButton);
SendMessage( hWndServer, WM_MBUTTONDOWN, 0 , 0 );
break;
case WM_MBUTTONUP:
this->injectMouseButtonUp(CEGUI::MiddleButton);
SendMessage( hWndServer, WM_MBUTTONUP, 0 , 0 );
break;
case 0x020A: // WM_MOUSEWHEEL:
this->injectMouseWheelChange(static_cast<float>((short)HIWORD(wParam)) / static_cast<float>(120));
SendMessage( hWndServer, 0x020A, 0 , 0 );
break;
And the Code of InjectXXXX its another copy paste of win32Helper Class within CEGUI Examples , so :
Code: Select all
bool CEGUIInjections::injectMouseButtonDown(const CEGUI::MouseButton& ceguiMouseButton)
{
if (CEGUI::System* ceguiSystem = CEGUI::System::getSingletonPtr())
ceguiSystem->getDefaultGUIContext().injectMouseButtonDown(ceguiMouseButton);
return false;
}
And my problems:
I can use Subscribe Event within MainMenu Class but just for CEGUI::DefaultWindow * d_root. So When using d_root->SubscribeEvent I hit the BreakPoints in &MainMenu::handleMainMenuClicked. But When i use FrameWindow* wnd we never reach the BreakPoints.
The FrameWindow i create is static , can't move it within the D3D9 App. I suppose that i'm doing something wrong at renderGUI or the injections never reach the window.
Mouse Have the same problem , even using guiContext->getMouseCursor().setDefaultImage("TaharezLook/MouseArrow") , my mouse look never displays the correct image.
Thx in advance.