Skip to content

Commit f4d2e4c

Browse files
JusonexJusonex
Jusonex
authored and
Jusonex
committed
Merge pull request #3 from Jusonex/master
CEF CEGUI widget
2 parents e0d794b + e3cb676 commit f4d2e4c

27 files changed

+512
-11
lines changed

MTA10/core/CWebView.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,18 @@ void CWebView::SetRenderingPaused ( bool bPaused )
128128
m_pWebView->GetHost ()->WasHidden ( bPaused );
129129
}
130130

131-
void CWebView::Focus ()
131+
void CWebView::Focus ( bool state )
132132
{
133133
if ( m_pWebView )
134134
{
135-
m_pWebView->GetHost ()->SetFocus ( true );
136-
m_pWebView->GetHost ()->SendFocusEvent ( true );
135+
m_pWebView->GetHost ()->SetFocus ( state );
136+
m_pWebView->GetHost ()->SendFocusEvent ( state );
137137
}
138-
g_pCore->GetWebCore()->SetFocusedWebView ( this );
138+
139+
if ( state )
140+
g_pCore->GetWebCore ()->SetFocusedWebView ( this );
141+
else if ( g_pCore->GetWebCore ()->GetFocusedWebView () == this )
142+
g_pCore->GetWebCore ()->SetFocusedWebView ( nullptr );
139143
}
140144

141145
void CWebView::ClearTexture ()

MTA10/core/CWebView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH
4848
void GetURL ( SString& outURL );
4949
void GetTitle ( SString& outTitle );
5050
void SetRenderingPaused ( bool bPaused );
51-
void Focus ();
51+
void Focus ( bool state = true );
52+
IDirect3DTexture9* GetTexture () { return static_cast<IDirect3DTexture9*>(m_pWebBrowserRenderItem->m_pD3DTexture); }
5253
void ClearTexture ();
5354
inline void NotifyPaint () { m_PaintCV.notify_one (); }
5455

MTA10/gui/CGUIWebBrowser_Impl.cpp

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: gui/CGUIWebBrowser_Impl.cpp
6+
* PURPOSE: WebBrowser widget class
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
#include "StdInc.h"
12+
#include <core/CWebViewInterface.h>
13+
14+
// Use StaticImage here as we'd have to add the same definition twice to the Falagard definition file otherwise
15+
#define CGUIWEBBROWSER_NAME "CGUI/StaticImage"
16+
17+
CGUIWebBrowser_Impl::CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent )
18+
{
19+
// Initialize
20+
m_pImagesetManager = pGUI->GetImageSetManager ();
21+
m_pImageset = nullptr;
22+
m_pImage = nullptr;
23+
m_pGUI = pGUI;
24+
m_pManager = pGUI;
25+
m_pWebView = nullptr;
26+
27+
// Get an unique identifier for CEGUI
28+
char szUnique [CGUI_CHAR_SIZE];
29+
pGUI->GetUniqueName ( szUnique );
30+
31+
// Create the control and set default properties
32+
m_pWindow = pGUI->GetWindowManager ()->createWindow ( CGUIWEBBROWSER_NAME, szUnique );
33+
m_pWindow->setDestroyedByParent ( false );
34+
m_pWindow->setRect ( CEGUI::Relative, CEGUI::Rect ( 0.0f, 0.0f, 1.0f, 1.0f ) );
35+
reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> setBackgroundEnabled ( false );
36+
37+
// Store the pointer to this CGUI element in the CEGUI element
38+
m_pWindow->setUserData ( reinterpret_cast < void* > ( this ) );
39+
40+
AddEvents ();
41+
42+
// Apply browser events
43+
m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseButtonDown, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseButtonDown, this ) );
44+
m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseButtonUp, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseButtonUp, this ) );
45+
m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseMove, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseMove, this ) );
46+
m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseWheel, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseWheel, this ) );
47+
m_pWindow->subscribeEvent ( CEGUI::Window::EventActivated, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_Activated, this ) );
48+
m_pWindow->subscribeEvent ( CEGUI::Window::EventDeactivated, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_Deactivated, this ) );
49+
50+
// If a parent is specified, add it to it's children list, if not, add it as a child to the pManager
51+
if ( pParent )
52+
{
53+
SetParent ( pParent );
54+
}
55+
else
56+
{
57+
pGUI->AddChild ( this );
58+
SetParent ( nullptr );
59+
}
60+
}
61+
62+
CGUIWebBrowser_Impl::~CGUIWebBrowser_Impl ()
63+
{
64+
Clear();
65+
66+
DestroyElement ();
67+
}
68+
69+
void CGUIWebBrowser_Impl::Clear ()
70+
{
71+
// Stop the control from using it
72+
reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( nullptr );
73+
74+
// Kill the images
75+
if ( m_pImageset )
76+
{
77+
m_pImageset->undefineAllImages ();
78+
m_pImagesetManager->destroyImageset ( m_pImageset );
79+
m_pImage = nullptr;
80+
m_pImageset = nullptr;
81+
}
82+
}
83+
84+
bool CGUIWebBrowser_Impl::LoadFromTexture ( IDirect3DTexture9* pTexture )
85+
{
86+
if ( m_pImageset && m_pImage )
87+
{
88+
m_pImageset->undefineAllImages ();
89+
}
90+
91+
CGUIWebBrowserTexture* pCEGUITexture = new CGUIWebBrowserTexture ( m_pGUI->GetRenderer (), pTexture );
92+
93+
// Get an unique identifier for CEGUI for the imageset
94+
char szUnique [CGUI_CHAR_SIZE];
95+
m_pGUI->GetUniqueName ( szUnique );
96+
97+
// Create an imageset
98+
if ( !m_pImageset )
99+
{
100+
while ( m_pImagesetManager->isImagesetPresent( szUnique ) )
101+
m_pGUI->GetUniqueName ( szUnique );
102+
m_pImageset = m_pImagesetManager->createImageset ( szUnique, pCEGUITexture, true );
103+
}
104+
105+
// Get an unique identifier for CEGUI for the image
106+
m_pGUI->GetUniqueName ( szUnique );
107+
108+
// Define an image and get its pointer
109+
m_pImageset->defineImage ( szUnique, CEGUI::Point ( 0, 0 ), CEGUI::Size ( pCEGUITexture->getWidth (), pCEGUITexture->getHeight () ), CEGUI::Point ( 0, 0 ) );
110+
m_pImage = &m_pImageset->getImage ( szUnique );
111+
112+
// Set the image just loaded as the image to be drawn for the widget
113+
reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( m_pImage );
114+
115+
// Success
116+
return true;
117+
}
118+
119+
void CGUIWebBrowser_Impl::LoadFromWebView ( CWebViewInterface* pWebView )
120+
{
121+
m_pWebView = pWebView;
122+
123+
// Load webview texture
124+
LoadFromTexture ( pWebView->GetTexture () );
125+
}
126+
127+
void CGUIWebBrowser_Impl::SetFrameEnabled ( bool bFrameEnabled )
128+
{
129+
reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> setFrameEnabled ( bFrameEnabled );
130+
}
131+
132+
133+
bool CGUIWebBrowser_Impl::IsFrameEnabled ( void )
134+
{
135+
return reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> isFrameEnabled ();
136+
}
137+
138+
139+
CEGUI::Image* CGUIWebBrowser_Impl::GetDirectImage ( void )
140+
{
141+
return const_cast < CEGUI::Image* > ( reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) ->getImage () );
142+
}
143+
144+
void CGUIWebBrowser_Impl::Render ( void )
145+
{
146+
return reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> render ();
147+
}
148+
149+
bool CGUIWebBrowser_Impl::Event_MouseButtonDown ( const CEGUI::EventArgs& e )
150+
{
151+
const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e );
152+
153+
if ( args.button == CEGUI::MouseButton::LeftButton )
154+
m_pWebView->InjectMouseDown ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_LEFT );
155+
else if ( args.button == CEGUI::MouseButton::MiddleButton )
156+
m_pWebView->InjectMouseDown ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_MIDDLE );
157+
else if ( args.button == CEGUI::MouseButton::RightButton )
158+
m_pWebView->InjectMouseDown ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_RIGHT );
159+
160+
return true;
161+
}
162+
163+
bool CGUIWebBrowser_Impl::Event_MouseButtonUp ( const CEGUI::EventArgs& e )
164+
{
165+
const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e );
166+
167+
if ( args.button == CEGUI::MouseButton::LeftButton )
168+
m_pWebView->InjectMouseUp ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_LEFT );
169+
else if ( args.button == CEGUI::MouseButton::MiddleButton )
170+
m_pWebView->InjectMouseUp ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_MIDDLE );
171+
else if ( args.button == CEGUI::MouseButton::RightButton )
172+
m_pWebView->InjectMouseUp ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_RIGHT );
173+
174+
return true;
175+
}
176+
177+
bool CGUIWebBrowser_Impl::Event_MouseMove ( const CEGUI::EventArgs& e )
178+
{
179+
const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e );
180+
181+
m_pWebView->InjectMouseMove ( (int)args.position.d_x - m_pWindow->windowToScreenX ( 0.0f ), (int)args.position.d_y - m_pWindow->windowToScreenY ( 0.0f ) );
182+
return true;
183+
}
184+
185+
bool CGUIWebBrowser_Impl::Event_MouseWheel ( const CEGUI::EventArgs& e )
186+
{
187+
const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e );
188+
189+
m_pWebView->InjectMouseWheel ( args.wheelChange * 40, 0 );
190+
return true;
191+
}
192+
193+
bool CGUIWebBrowser_Impl::Event_Activated ( const CEGUI::EventArgs& e )
194+
{
195+
m_pWebView->Focus ( true );
196+
return true;
197+
}
198+
199+
bool CGUIWebBrowser_Impl::Event_Deactivated ( const CEGUI::EventArgs& e )
200+
{
201+
m_pWebView->Focus ( false );
202+
return true;
203+
}
204+
205+
206+
CGUIWebBrowserTexture::CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ) : CEGUI::DirectX9Texture ( pOwner )
207+
{
208+
m_pTexture = pTexture;
209+
210+
// Get width and height
211+
D3DSURFACE_DESC SurfaceDesc;
212+
if ( pTexture->GetLevelDesc ( 0, &SurfaceDesc ) == ERROR_SUCCESS )
213+
{
214+
m_Width = SurfaceDesc.Width;
215+
m_Height = SurfaceDesc.Height;
216+
}
217+
}

MTA10/gui/CGUIWebBrowser_Impl.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: gui/CGUIWebBrowser_Impl.h
6+
* PURPOSE: WebBrowser CGUI class
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
#ifndef __CGUIWEBBROWSER_IMPL_H
12+
#define __CGUIWEBBROWSER_IMPL_H
13+
14+
#include <gui/CGUIWebBrowser.h>
15+
#include "CGUITexture_Impl.h"
16+
#include <renderers/directx9GUIRenderer/d3d9texture.h>
17+
18+
class CGUITexture;
19+
class CGUITexture_Impl;
20+
class CGUI_Impl;
21+
class CWebViewInterface;
22+
23+
class CGUIWebBrowser_Impl : public CGUIWebBrowser, public CGUIElement_Impl
24+
{
25+
public:
26+
CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent = nullptr );
27+
~CGUIWebBrowser_Impl ();
28+
void Clear ();
29+
30+
void LoadFromWebView ( CWebViewInterface* pWebView );
31+
bool LoadFromTexture ( IDirect3DTexture9* pD3DTexture );
32+
33+
void SetFrameEnabled ( bool bFrameEnabled );
34+
bool IsFrameEnabled ();
35+
36+
CEGUI::Image* GetDirectImage ();
37+
38+
void Render ();
39+
40+
eCGUIType GetType () { return CGUI_WEBBROWSER; }
41+
42+
protected:
43+
bool Event_MouseButtonDown ( const CEGUI::EventArgs& e );
44+
bool Event_MouseButtonUp ( const CEGUI::EventArgs& e );
45+
bool Event_MouseWheel ( const CEGUI::EventArgs& e );
46+
bool Event_MouseMove ( const CEGUI::EventArgs& e );
47+
bool Event_Activated ( const CEGUI::EventArgs& e );
48+
bool Event_Deactivated ( const CEGUI::EventArgs& e );
49+
50+
private:
51+
CGUI_Impl* m_pGUI;
52+
CEGUI::ImagesetManager* m_pImagesetManager;
53+
CEGUI::Imageset* m_pImageset;
54+
const CEGUI::Image* m_pImage;
55+
56+
CWebViewInterface* m_pWebView;
57+
58+
#include "CGUIElement_Inc.h"
59+
};
60+
61+
62+
// The purpose of this class is to provide an externally managed DirectX texture
63+
class CGUIWebBrowserTexture : public CEGUI::DirectX9Texture
64+
{
65+
public:
66+
CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture );
67+
68+
virtual ushort getWidth () const override { return m_Width; };
69+
virtual ushort getHeight () const override { return m_Height; };
70+
71+
// Override with empty function (--> eliminate the functinions from DirectX9Texture)
72+
virtual void loadFromFile ( const CEGUI::String& filename, const CEGUI::String& resourceGroup ) override {};
73+
virtual void loadFromMemory ( const void* buffPtr, uint buffWidth, uint buffHeight ) override {};
74+
75+
virtual LPDIRECT3DTEXTURE9 getD3DTexture () const override { return m_pTexture; };
76+
virtual void preD3DReset () {};
77+
virtual void postD3DReset () {};
78+
79+
private:
80+
IDirect3DTexture9* m_pTexture;
81+
ushort m_Width;
82+
ushort m_Height;
83+
};
84+
85+
#endif

MTA10/gui/CGUI_Impl.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ CGUIComboBox* CGUI_Impl::_CreateComboBox ( CGUIElement_Impl* pParent, const char
482482
}
483483

484484

485+
CGUIWebBrowser* CGUI_Impl::_CreateWebBrowser ( CGUIElement_Impl* pParent )
486+
{
487+
return new CGUIWebBrowser_Impl ( this, pParent );
488+
}
489+
490+
485491
CGUITexture* CGUI_Impl::CreateTexture ( void )
486492
{
487493
return new CGUITexture_Impl ( this );
@@ -1651,6 +1657,21 @@ CGUIComboBox* CGUI_Impl::CreateComboBox ( CGUIComboBox* pParent, const char* szC
16511657
return _CreateComboBox ( wnd, szCaption );
16521658
}
16531659

1660+
1661+
CGUIWebBrowser* CGUI_Impl::CreateWebBrowser ( CGUIElement* pParent )
1662+
{
1663+
CGUIWindow_Impl* wnd = reinterpret_cast < CGUIWindow_Impl* > ( pParent );
1664+
return _CreateWebBrowser ( wnd );
1665+
}
1666+
1667+
1668+
CGUIWebBrowser* CGUI_Impl::CreateWebBrowser ( CGUITab* pParent )
1669+
{
1670+
CGUITab_Impl* wnd = reinterpret_cast < CGUITab_Impl* > ( pParent );
1671+
return _CreateWebBrowser ( wnd );
1672+
}
1673+
1674+
16541675
void CGUI_Impl::CleanDeadPool ()
16551676
{
16561677
if ( m_pWindowManager )

MTA10/gui/CGUI_Impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class CGUI_Impl : public CGUI, public CGUITabList
134134
CGUIComboBox* CreateComboBox ( CGUIElement* pParent = NULL, const char* szCaption = "" );
135135
CGUIComboBox* CreateComboBox ( CGUIComboBox* pParent = NULL, const char* szCaption = "" );
136136

137+
CGUIWebBrowser* CreateWebBrowser ( CGUIElement* pParent = nullptr );
138+
CGUIWebBrowser* CreateWebBrowser ( CGUITab* pParent = nullptr );
139+
137140
CGUIWindow* CreateWnd ( CGUIElement* pParent = NULL, const char* szCaption = "" );
138141
//
139142

@@ -234,6 +237,7 @@ class CGUI_Impl : public CGUI, public CGUITabList
234237
CGUIScrollPane* _CreateScrollPane ( CGUIElement_Impl* pParent = NULL );
235238
CGUIScrollBar* _CreateScrollBar ( bool bHorizontal, CGUIElement_Impl* pParent = NULL );
236239
CGUIComboBox* _CreateComboBox ( CGUIElement_Impl* pParent = NULL, const char* szCaption = "" );
240+
CGUIWebBrowser* _CreateWebBrowser ( CGUIElement_Impl* pParent = nullptr );
237241

238242
void SubscribeToMouseEvents();
239243
CGUIFont* CreateFntFromWinFont ( const char* szFontName, const char* szFontWinReg, const char* szFontWinFile, unsigned int uSize = 8, unsigned int uFlags = 0, bool bAutoScale = false );

MTA10/gui/StdInc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333
#include "CGUIScrollPane_Impl.h"
3434
#include "CGUITabPanel_Impl.h"
3535
#include "CGUITexture_Impl.h"
36+
#include "CGUIWebBrowser_Impl.h"
3637
#include "CGUIWindow_Impl.h"
3738
#include "CGUIComboBox_Impl.h"

0 commit comments

Comments
 (0)