Skip to content

Commit c00e6e4

Browse files
committed
Added CEGUI browser element
1 parent e0d794b commit c00e6e4

27 files changed

+463
-19
lines changed

MTA10/core/CWebView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH
4949
void GetTitle ( SString& outTitle );
5050
void SetRenderingPaused ( bool bPaused );
5151
void Focus ();
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: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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+
// If a parent is specified, add it to it's children list, if not, add it as a child to the pManager
43+
if ( pParent )
44+
{
45+
SetParent ( pParent );
46+
}
47+
else
48+
{
49+
pGUI->AddChild ( this );
50+
SetParent ( nullptr );
51+
}
52+
}
53+
54+
CGUIWebBrowser_Impl::~CGUIWebBrowser_Impl ( void )
55+
{
56+
// Clear the image
57+
Clear ();
58+
59+
DestroyElement ();
60+
}
61+
62+
bool CGUIWebBrowser_Impl::LoadFromTexture ( IDirect3DTexture9* pTexture )
63+
{
64+
if ( m_pImageset && m_pImage )
65+
{
66+
m_pImageset->undefineAllImages ();
67+
}
68+
69+
CGUIWebBrowserTexture* pCEGUITexture = new CGUIWebBrowserTexture ( m_pGUI->GetRenderer (), pTexture );
70+
71+
// Get an unique identifier for CEGUI for the imageset
72+
char szUnique [CGUI_CHAR_SIZE];
73+
m_pGUI->GetUniqueName ( szUnique );
74+
75+
// Create an imageset
76+
if ( !m_pImageset )
77+
{
78+
while ( m_pImagesetManager->isImagesetPresent( szUnique ) )
79+
m_pGUI->GetUniqueName ( szUnique );
80+
m_pImageset = m_pImagesetManager->createImageset ( szUnique, pCEGUITexture, true );
81+
}
82+
83+
// Get an unique identifier for CEGUI for the image
84+
m_pGUI->GetUniqueName ( szUnique );
85+
86+
// Define an image and get its pointer
87+
m_pImageset->defineImage ( szUnique, CEGUI::Point ( 0, 0 ), CEGUI::Size ( pCEGUITexture->getWidth (), pCEGUITexture->getHeight () ), CEGUI::Point ( 0, 0 ) );
88+
m_pImage = &m_pImageset->getImage ( szUnique );
89+
90+
// Set the image just loaded as the image to be drawn for the widget
91+
reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( m_pImage );
92+
93+
// Success
94+
return true;
95+
}
96+
97+
void CGUIWebBrowser_Impl::LoadFromWebView ( CWebViewInterface* pWebView )
98+
{
99+
m_pWebView = pWebView;
100+
101+
// Load webview texture
102+
LoadFromTexture ( pWebView->GetTexture () );
103+
}
104+
105+
void CGUIWebBrowser_Impl::Clear ( void )
106+
{
107+
// Stop the control from using it
108+
reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( nullptr );
109+
110+
// Kill the images
111+
if ( m_pImageset )
112+
{
113+
m_pImageset->undefineAllImages ();
114+
m_pImagesetManager->destroyImageset ( m_pImageset );
115+
m_pImage = nullptr;
116+
m_pImageset = nullptr;
117+
}
118+
}
119+
120+
bool CGUIWebBrowser_Impl::GetNativeSize ( CVector2D& vecSize )
121+
{
122+
auto pTexture = m_pWebView->GetTexture ();
123+
D3DSURFACE_DESC SurfaceDesc;
124+
if ( pTexture->GetLevelDesc ( 0, &SurfaceDesc ) == ERROR_SUCCESS )
125+
{
126+
vecSize.fX = (float)SurfaceDesc.Width;
127+
vecSize.fY = (float)SurfaceDesc.Height;
128+
return true;
129+
}
130+
131+
return false;
132+
}
133+
134+
void CGUIWebBrowser_Impl::SetFrameEnabled ( bool bFrameEnabled )
135+
{
136+
reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> setFrameEnabled ( bFrameEnabled );
137+
}
138+
139+
140+
bool CGUIWebBrowser_Impl::IsFrameEnabled ( void )
141+
{
142+
return reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> isFrameEnabled ();
143+
}
144+
145+
146+
CEGUI::Image* CGUIWebBrowser_Impl::GetDirectImage ( void )
147+
{
148+
return const_cast < CEGUI::Image* > ( reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) ->getImage () );
149+
}
150+
151+
void CGUIWebBrowser_Impl::Render ( void )
152+
{
153+
return reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> render ();
154+
}
155+
156+
157+
158+
159+
CGUIWebBrowserTexture::CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ) : CEGUI::DirectX9Texture(pOwner)
160+
{
161+
m_pTexture = pTexture;
162+
163+
// Get width and height
164+
D3DSURFACE_DESC SurfaceDesc;
165+
if ( pTexture->GetLevelDesc ( 0, &SurfaceDesc ) == ERROR_SUCCESS )
166+
{
167+
m_Width = SurfaceDesc.Width;
168+
m_Height = SurfaceDesc.Height;
169+
}
170+
}

MTA10/gui/CGUIWebBrowser_Impl.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 ( void );
28+
29+
void LoadFromWebView ( CWebViewInterface* pWebView );
30+
bool LoadFromTexture ( IDirect3DTexture9* pD3DTexture );
31+
bool GetNativeSize ( CVector2D& vecSize );
32+
void Clear ( void );
33+
34+
void SetFrameEnabled ( bool bFrameEnabled );
35+
bool IsFrameEnabled ( void );
36+
37+
CEGUI::Image* GetDirectImage ( void );
38+
39+
void Render ( void );
40+
41+
eCGUIType GetType ( void ) { return CGUI_WEBBROWSER; }
42+
43+
private:
44+
CGUI_Impl* m_pGUI;
45+
CEGUI::ImagesetManager* m_pImagesetManager;
46+
CEGUI::Imageset* m_pImageset;
47+
const CEGUI::Image* m_pImage;
48+
49+
CWebViewInterface* m_pWebView;
50+
51+
#include "CGUIElement_Inc.h"
52+
};
53+
54+
class CGUIWebBrowserTexture : public CEGUI::DirectX9Texture
55+
{
56+
public:
57+
CGUIWebBrowserTexture(CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture);
58+
59+
virtual ushort getWidth() const override { return m_Width; };
60+
virtual ushort getHeight() const override { return m_Height; };
61+
62+
virtual void loadFromFile(const CEGUI::String& filename, const CEGUI::String& resourceGroup) override {};
63+
virtual void loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight) override {};
64+
65+
virtual LPDIRECT3DTEXTURE9 getD3DTexture() const override { return m_pTexture; };
66+
virtual void preD3DReset() {};
67+
virtual void postD3DReset() {};
68+
69+
private:
70+
IDirect3DTexture9* m_pTexture;
71+
ushort m_Width;
72+
ushort m_Height;
73+
};
74+
75+
#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"

MTA10/gui/gui 2008.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
</Link>
185185
</ItemDefinitionGroup>
186186
<ItemGroup>
187+
<ClCompile Include="CGUIWebBrowser_Impl.cpp" />
187188
<ClCompile Include="CGUI_Impl.cpp" />
188189
<ClCompile Include="CGUIButton_Impl.cpp" />
189190
<ClCompile Include="CGUICheckBox_Impl.cpp" />
@@ -214,6 +215,8 @@
214215
</ClCompile>
215216
</ItemGroup>
216217
<ItemGroup>
218+
<ClInclude Include="..\sdk\gui\CGUIWebBrowser.h" />
219+
<ClInclude Include="CGUIWebBrowser_Impl.h" />
217220
<ClInclude Include="CGUI_Impl.h" />
218221
<ClInclude Include="CGUIButton_Impl.h" />
219222
<ClInclude Include="CGUICheckBox_Impl.h" />

MTA10/gui/gui 2008.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
<ClCompile Include="StdInc.cpp">
8787
<Filter>Source Files</Filter>
8888
</ClCompile>
89+
<ClCompile Include="CGUIWebBrowser_Impl.cpp">
90+
<Filter>Source Files</Filter>
91+
</ClCompile>
8992
</ItemGroup>
9093
<ItemGroup>
9194
<ClInclude Include="CGUI_Impl.h">
@@ -238,5 +241,11 @@
238241
<ClInclude Include="..\sdk\gui\CGUIWindow.h">
239242
<Filter>Header Files\interface</Filter>
240243
</ClInclude>
244+
<ClInclude Include="CGUIWebBrowser_Impl.h">
245+
<Filter>Header Files</Filter>
246+
</ClInclude>
247+
<ClInclude Include="..\sdk\gui\CGUIWebBrowser.h">
248+
<Filter>Header Files\interface</Filter>
249+
</ClInclude>
241250
</ItemGroup>
242251
</Project>

MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5125,6 +5125,30 @@ bool CStaticFunctionDefinitions::GUIComboBoxSetItemText ( CClientEntity& Entity,
51255125
return false;
51265126
}
51275127

5128+
CClientGUIElement* CStaticFunctionDefinitions::GUICreateBrowser ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strURL, bool bIsLocal, bool bRelative, CClientGUIElement* pParent )
5129+
{
5130+
CGUIWebBrowser* pElement = m_pGUI->CreateWebBrowser ( pParent ? pParent->GetCGUIElement () : nullptr );
5131+
pElement->SetPosition ( CVector2D ( fX, fY ), bRelative );
5132+
pElement->SetSize ( CVector2D ( fWidth, fHeight ), bRelative );
5133+
5134+
// Register to the gui manager
5135+
CVector2D absoluteSize;
5136+
pElement->GetSize ( absoluteSize, false );
5137+
auto pGUIElement = new CClientGUIWebBrowser ( bIsLocal, (uint)absoluteSize.fX, (uint)absoluteSize.fY, m_pManager, &LuaMain, pElement );
5138+
pGUIElement->SetParent ( pParent ? pParent : LuaMain.GetResource ()->GetResourceGUIEntity () );
5139+
5140+
// Load CEGUI element texture from webview
5141+
pElement->LoadFromWebView ( pGUIElement->GetBrowser ()->GetWebView () );
5142+
5143+
if ( pParent && !pParent->IsCallPropagationEnabled () )
5144+
{
5145+
pGUIElement->GetCGUIElement ()->SetInheritsAlpha ( false );
5146+
}
5147+
5148+
return pGUIElement;
5149+
}
5150+
5151+
51285152
void CStaticFunctionDefinitions::GUISetText ( CClientEntity& Entity, const char* szText )
51295153
{
51305154
// Are we a CGUI element?

MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ class CStaticFunctionDefinitions
396396
static CClientGUIElement* GUICreateRadioButton ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent );
397397
static CClientGUIElement* GUICreateStaticImage ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strFile, bool bRelative, CClientGUIElement* pParent );
398398
static CClientGUIElement* GUICreateComboBox ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent );
399-
399+
static CClientGUIElement* GUICreateBrowser ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strURL, bool bIsLocal, bool bRelative, CClientGUIElement* pParent );
400+
400401

401402
static bool GUIStaticImageLoadImage ( CClientEntity& Element, const SString& strDir );
402403
static bool GUIStaticImageGetNativeSize ( CClientEntity& Entity, CVector2D &vecSize );

0 commit comments

Comments
 (0)