Skip to content

Commit 9e0a812

Browse files
committed
Implemented keyboard and mouse input for CEGUI webbrowser widget
Reverted changes in "Core 2013.sln" made in the last commit (my VS was too old :( )
1 parent c00e6e4 commit 9e0a812

File tree

7 files changed

+129
-65
lines changed

7 files changed

+129
-65
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ 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 );
5252
IDirect3DTexture9* GetTexture () { return static_cast<IDirect3DTexture9*>(m_pWebBrowserRenderItem->m_pD3DTexture); }
5353
void ClearTexture ();
5454
inline void NotifyPaint () { m_PaintCV.notify_one (); }

MTA10/gui/CGUIWebBrowser_Impl.cpp

Lines changed: 80 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ CGUIWebBrowser_Impl::CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent
3939

4040
AddEvents ();
4141

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+
4250
// If a parent is specified, add it to it's children list, if not, add it as a child to the pManager
4351
if ( pParent )
4452
{
@@ -51,14 +59,28 @@ CGUIWebBrowser_Impl::CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent
5159
}
5260
}
5361

54-
CGUIWebBrowser_Impl::~CGUIWebBrowser_Impl ( void )
62+
CGUIWebBrowser_Impl::~CGUIWebBrowser_Impl ()
5563
{
56-
// Clear the image
57-
Clear ();
64+
Clear();
5865

5966
DestroyElement ();
6067
}
6168

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+
6284
bool CGUIWebBrowser_Impl::LoadFromTexture ( IDirect3DTexture9* pTexture )
6385
{
6486
if ( m_pImageset && m_pImage )
@@ -102,35 +124,6 @@ void CGUIWebBrowser_Impl::LoadFromWebView ( CWebViewInterface* pWebView )
102124
LoadFromTexture ( pWebView->GetTexture () );
103125
}
104126

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-
134127
void CGUIWebBrowser_Impl::SetFrameEnabled ( bool bFrameEnabled )
135128
{
136129
reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> setFrameEnabled ( bFrameEnabled );
@@ -153,10 +146,64 @@ void CGUIWebBrowser_Impl::Render ( void )
153146
return reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> render ();
154147
}
155148

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 * 30, 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+
}
156198

199+
bool CGUIWebBrowser_Impl::Event_Deactivated ( const CEGUI::EventArgs& e )
200+
{
201+
m_pWebView->Focus ( false );
202+
return true;
203+
}
157204

158205

159-
CGUIWebBrowserTexture::CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ) : CEGUI::DirectX9Texture(pOwner)
206+
CGUIWebBrowserTexture::CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ) : CEGUI::DirectX9Texture ( pOwner )
160207
{
161208
m_pTexture = pTexture;
162209

MTA10/gui/CGUIWebBrowser_Impl.h

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,28 @@ class CGUIWebBrowser_Impl : public CGUIWebBrowser, public CGUIElement_Impl
2424
{
2525
public:
2626
CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent = nullptr );
27-
~CGUIWebBrowser_Impl ( void );
27+
~CGUIWebBrowser_Impl ();
28+
void Clear ();
2829

2930
void LoadFromWebView ( CWebViewInterface* pWebView );
3031
bool LoadFromTexture ( IDirect3DTexture9* pD3DTexture );
31-
bool GetNativeSize ( CVector2D& vecSize );
32-
void Clear ( void );
3332

3433
void SetFrameEnabled ( bool bFrameEnabled );
35-
bool IsFrameEnabled ( void );
34+
bool IsFrameEnabled ();
3635

37-
CEGUI::Image* GetDirectImage ( void );
36+
CEGUI::Image* GetDirectImage ();
3837

39-
void Render ( void );
38+
void Render ();
4039

41-
eCGUIType GetType ( void ) { return CGUI_WEBBROWSER; }
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 );
4249

4350
private:
4451
CGUI_Impl* m_pGUI;
@@ -51,20 +58,23 @@ class CGUIWebBrowser_Impl : public CGUIWebBrowser, public CGUIElement_Impl
5158
#include "CGUIElement_Inc.h"
5259
};
5360

61+
62+
// The purpose of this class is to provide an externally managed DirectX texture
5463
class CGUIWebBrowserTexture : public CEGUI::DirectX9Texture
5564
{
5665
public:
57-
CGUIWebBrowserTexture(CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture);
66+
CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture );
5867

59-
virtual ushort getWidth() const override { return m_Width; };
60-
virtual ushort getHeight() const override { return m_Height; };
68+
virtual ushort getWidth () const override { return m_Width; };
69+
virtual ushort getHeight () const override { return m_Height; };
6170

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 {};
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 {};
6474

65-
virtual LPDIRECT3DTEXTURE9 getD3DTexture() const override { return m_pTexture; };
66-
virtual void preD3DReset() {};
67-
virtual void postD3DReset() {};
75+
virtual LPDIRECT3DTEXTURE9 getD3DTexture () const override { return m_pTexture; };
76+
virtual void preD3DReset () {};
77+
virtual void postD3DReset () {};
6878

6979
private:
7080
IDirect3DTexture9* m_pTexture;

MTA10/sdk/core/CWebViewInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CWebViewInterface
2727
virtual void GetURL ( SString& outURL ) = 0;
2828
virtual void GetTitle ( SString& outTitle ) = 0;
2929
virtual void SetRenderingPaused ( bool bPaused ) = 0;
30-
virtual void Focus () = 0;
30+
virtual void Focus ( bool state = true ) = 0;
3131
virtual IDirect3DTexture9* GetTexture () = 0;
3232

3333
virtual void ExecuteJavascript ( const SString& strJavascriptCode ) = 0;

MTA10/sdk/gui/CGUIWebBrowser.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class CGUIWebBrowser : public CGUIElement
2121

2222
virtual void LoadFromWebView ( class CWebViewInterface* pWebView ) = 0;
2323

24-
virtual void Clear () = 0;
25-
virtual bool GetNativeSize ( CVector2D &vecSize ) = 0;
26-
2724
virtual void SetFrameEnabled ( bool bFrameEnabled ) = 0;
2825
virtual bool IsFrameEnabled () = 0;
2926

Shared/Core 2013.sln

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 2013
3-
VisualStudioVersion = 12.0.21005.1
3+
VisualStudioVersion = 12.0.30110.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CEGUI", "CEGUI", "{4C0157CE-9DD9-4729-8CDF-F5B9D2D71D2B}"
66
EndProject
@@ -725,25 +725,31 @@ Global
725725
{C5076389-A166-4FB8-A083-AC5443482C31}.Release|x64.ActiveCfg = Release|Win32
726726
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|Win32.ActiveCfg = Debug|Win32
727727
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|Win32.Build.0 = Debug|Win32
728-
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|x64.ActiveCfg = Debug|Win32
728+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|x64.ActiveCfg = Debug|x64
729+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|x64.Build.0 = Debug|x64
729730
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|Win32.ActiveCfg = Debug|Win32
730731
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|Win32.Build.0 = Debug|Win32
731-
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|x64.ActiveCfg = Debug|Win32
732+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|x64.ActiveCfg = Debug|x64
733+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|x64.Build.0 = Debug|x64
732734
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|Win32.ActiveCfg = Debug|Win32
733735
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|Win32.Build.0 = Debug|Win32
734-
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.ActiveCfg = Debug|Win32
736+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.ActiveCfg = Debug|x64
737+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.Build.0 = Debug|x64
735738
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|Win32.ActiveCfg = Nightly|Win32
736739
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|Win32.Build.0 = Nightly|Win32
737-
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|x64.ActiveCfg = Nightly|Win32
740+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|x64.ActiveCfg = Release|x64
738741
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|Win32.ActiveCfg = Release|Win32
739742
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|Win32.Build.0 = Release|Win32
740-
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|x64.ActiveCfg = Release|Win32
743+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|x64.ActiveCfg = Release|x64
744+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|x64.Build.0 = Release|x64
741745
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|Win32.ActiveCfg = Release|Win32
742746
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|Win32.Build.0 = Release|Win32
743-
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|x64.ActiveCfg = Release|Win32
747+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|x64.ActiveCfg = Release|x64
748+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|x64.Build.0 = Release|x64
744749
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|Win32.ActiveCfg = Release|Win32
745750
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|Win32.Build.0 = Release|Win32
746-
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.ActiveCfg = Release|Win32
751+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.ActiveCfg = Release|x64
752+
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.Build.0 = Release|x64
747753
EndGlobalSection
748754
GlobalSection(SolutionProperties) = preSolution
749755
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)