From c00e6e4d728c5946fd0d772fe923281ec3a7a9d5 Mon Sep 17 00:00:00 2001 From: Jusonex Date: Thu, 9 Apr 2015 14:50:41 +0200 Subject: [PATCH 1/3] Added CEGUI browser element --- MTA10/core/CWebView.h | 1 + MTA10/gui/CGUIWebBrowser_Impl.cpp | 170 ++++++++++++++++++ MTA10/gui/CGUIWebBrowser_Impl.h | 75 ++++++++ MTA10/gui/CGUI_Impl.cpp | 21 +++ MTA10/gui/CGUI_Impl.h | 4 + MTA10/gui/StdInc.h | 1 + MTA10/gui/gui 2008.vcxproj | 3 + MTA10/gui/gui 2008.vcxproj.filters | 9 + .../logic/CStaticFunctionDefinitions.cpp | 24 +++ .../logic/CStaticFunctionDefinitions.h | 3 +- MTA10/mods/shared_logic/CClientGUIElement.cpp | 3 + MTA10/mods/shared_logic/CClientGUIElement.h | 2 +- MTA10/mods/shared_logic/CClientWebBrowser.cpp | 7 + MTA10/mods/shared_logic/CClientWebBrowser.h | 11 ++ .../lua/CLuaFunctionDefs.Browser.cpp | 64 +++++++ .../mods/shared_logic/lua/CLuaFunctionDefs.h | 2 + .../lua/CLuaFunctionParseHelpers.cpp | 1 + .../lua/CLuaFunctionParseHelpers.h | 2 + MTA10/mods/shared_logic/lua/CLuaMain.cpp | 7 + MTA10/mods/shared_logic/lua/CLuaManager.cpp | 2 + .../shared_logic/luadefs/CLuaClassDefs.cpp | 1 + MTA10/sdk/core/CWebViewInterface.h | 3 + MTA10/sdk/gui/CGUI.h | 4 + MTA10/sdk/gui/CGUIElement.h | 3 +- MTA10/sdk/gui/CGUIWebBrowser.h | 33 ++++ Shared/Core 2013.sln | 22 +-- .../directx9GUIRenderer/d3d9texture.h | 4 +- 27 files changed, 463 insertions(+), 19 deletions(-) create mode 100644 MTA10/gui/CGUIWebBrowser_Impl.cpp create mode 100644 MTA10/gui/CGUIWebBrowser_Impl.h create mode 100644 MTA10/sdk/gui/CGUIWebBrowser.h diff --git a/MTA10/core/CWebView.h b/MTA10/core/CWebView.h index c8c1498185e..d8e14af1c98 100644 --- a/MTA10/core/CWebView.h +++ b/MTA10/core/CWebView.h @@ -49,6 +49,7 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH void GetTitle ( SString& outTitle ); void SetRenderingPaused ( bool bPaused ); void Focus (); + IDirect3DTexture9* GetTexture () { return static_cast(m_pWebBrowserRenderItem->m_pD3DTexture); } void ClearTexture (); inline void NotifyPaint () { m_PaintCV.notify_one (); } diff --git a/MTA10/gui/CGUIWebBrowser_Impl.cpp b/MTA10/gui/CGUIWebBrowser_Impl.cpp new file mode 100644 index 00000000000..d5cfbe5ad0a --- /dev/null +++ b/MTA10/gui/CGUIWebBrowser_Impl.cpp @@ -0,0 +1,170 @@ +/***************************************************************************** +* +* PROJECT: Multi Theft Auto v1.0 +* LICENSE: See LICENSE in the top level directory +* FILE: gui/CGUIWebBrowser_Impl.cpp +* PURPOSE: WebBrowser widget class +* +* Multi Theft Auto is available from http://www.multitheftauto.com/ +* +*****************************************************************************/ +#include "StdInc.h" +#include + +// Use StaticImage here as we'd have to add the same definition twice to the Falagard definition file otherwise +#define CGUIWEBBROWSER_NAME "CGUI/StaticImage" + +CGUIWebBrowser_Impl::CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent ) +{ + // Initialize + m_pImagesetManager = pGUI->GetImageSetManager (); + m_pImageset = nullptr; + m_pImage = nullptr; + m_pGUI = pGUI; + m_pManager = pGUI; + m_pWebView = nullptr; + + // Get an unique identifier for CEGUI + char szUnique [CGUI_CHAR_SIZE]; + pGUI->GetUniqueName ( szUnique ); + + // Create the control and set default properties + m_pWindow = pGUI->GetWindowManager ()->createWindow ( CGUIWEBBROWSER_NAME, szUnique ); + m_pWindow->setDestroyedByParent ( false ); + m_pWindow->setRect ( CEGUI::Relative, CEGUI::Rect ( 0.0f, 0.0f, 1.0f, 1.0f ) ); + reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> setBackgroundEnabled ( false ); + + // Store the pointer to this CGUI element in the CEGUI element + m_pWindow->setUserData ( reinterpret_cast < void* > ( this ) ); + + AddEvents (); + + // If a parent is specified, add it to it's children list, if not, add it as a child to the pManager + if ( pParent ) + { + SetParent ( pParent ); + } + else + { + pGUI->AddChild ( this ); + SetParent ( nullptr ); + } +} + +CGUIWebBrowser_Impl::~CGUIWebBrowser_Impl ( void ) +{ + // Clear the image + Clear (); + + DestroyElement (); +} + +bool CGUIWebBrowser_Impl::LoadFromTexture ( IDirect3DTexture9* pTexture ) +{ + if ( m_pImageset && m_pImage ) + { + m_pImageset->undefineAllImages (); + } + + CGUIWebBrowserTexture* pCEGUITexture = new CGUIWebBrowserTexture ( m_pGUI->GetRenderer (), pTexture ); + + // Get an unique identifier for CEGUI for the imageset + char szUnique [CGUI_CHAR_SIZE]; + m_pGUI->GetUniqueName ( szUnique ); + + // Create an imageset + if ( !m_pImageset ) + { + while ( m_pImagesetManager->isImagesetPresent( szUnique ) ) + m_pGUI->GetUniqueName ( szUnique ); + m_pImageset = m_pImagesetManager->createImageset ( szUnique, pCEGUITexture, true ); + } + + // Get an unique identifier for CEGUI for the image + m_pGUI->GetUniqueName ( szUnique ); + + // Define an image and get its pointer + m_pImageset->defineImage ( szUnique, CEGUI::Point ( 0, 0 ), CEGUI::Size ( pCEGUITexture->getWidth (), pCEGUITexture->getHeight () ), CEGUI::Point ( 0, 0 ) ); + m_pImage = &m_pImageset->getImage ( szUnique ); + + // Set the image just loaded as the image to be drawn for the widget + reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( m_pImage ); + + // Success + return true; +} + +void CGUIWebBrowser_Impl::LoadFromWebView ( CWebViewInterface* pWebView ) +{ + m_pWebView = pWebView; + + // Load webview texture + LoadFromTexture ( pWebView->GetTexture () ); +} + +void CGUIWebBrowser_Impl::Clear ( void ) +{ + // Stop the control from using it + reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( nullptr ); + + // Kill the images + if ( m_pImageset ) + { + m_pImageset->undefineAllImages (); + m_pImagesetManager->destroyImageset ( m_pImageset ); + m_pImage = nullptr; + m_pImageset = nullptr; + } +} + +bool CGUIWebBrowser_Impl::GetNativeSize ( CVector2D& vecSize ) +{ + auto pTexture = m_pWebView->GetTexture (); + D3DSURFACE_DESC SurfaceDesc; + if ( pTexture->GetLevelDesc ( 0, &SurfaceDesc ) == ERROR_SUCCESS ) + { + vecSize.fX = (float)SurfaceDesc.Width; + vecSize.fY = (float)SurfaceDesc.Height; + return true; + } + + return false; +} + +void CGUIWebBrowser_Impl::SetFrameEnabled ( bool bFrameEnabled ) +{ + reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> setFrameEnabled ( bFrameEnabled ); +} + + +bool CGUIWebBrowser_Impl::IsFrameEnabled ( void ) +{ + return reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> isFrameEnabled (); +} + + +CEGUI::Image* CGUIWebBrowser_Impl::GetDirectImage ( void ) +{ + return const_cast < CEGUI::Image* > ( reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) ->getImage () ); +} + +void CGUIWebBrowser_Impl::Render ( void ) +{ + return reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> render (); +} + + + + +CGUIWebBrowserTexture::CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ) : CEGUI::DirectX9Texture(pOwner) +{ + m_pTexture = pTexture; + + // Get width and height + D3DSURFACE_DESC SurfaceDesc; + if ( pTexture->GetLevelDesc ( 0, &SurfaceDesc ) == ERROR_SUCCESS ) + { + m_Width = SurfaceDesc.Width; + m_Height = SurfaceDesc.Height; + } +} diff --git a/MTA10/gui/CGUIWebBrowser_Impl.h b/MTA10/gui/CGUIWebBrowser_Impl.h new file mode 100644 index 00000000000..540aff05dcf --- /dev/null +++ b/MTA10/gui/CGUIWebBrowser_Impl.h @@ -0,0 +1,75 @@ +/***************************************************************************** +* +* PROJECT: Multi Theft Auto v1.0 +* LICENSE: See LICENSE in the top level directory +* FILE: gui/CGUIWebBrowser_Impl.h +* PURPOSE: WebBrowser CGUI class +* +* Multi Theft Auto is available from http://www.multitheftauto.com/ +* +*****************************************************************************/ +#ifndef __CGUIWEBBROWSER_IMPL_H +#define __CGUIWEBBROWSER_IMPL_H + +#include +#include "CGUITexture_Impl.h" +#include + +class CGUITexture; +class CGUITexture_Impl; +class CGUI_Impl; +class CWebViewInterface; + +class CGUIWebBrowser_Impl : public CGUIWebBrowser, public CGUIElement_Impl +{ +public: + CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent = nullptr ); + ~CGUIWebBrowser_Impl ( void ); + + void LoadFromWebView ( CWebViewInterface* pWebView ); + bool LoadFromTexture ( IDirect3DTexture9* pD3DTexture ); + bool GetNativeSize ( CVector2D& vecSize ); + void Clear ( void ); + + void SetFrameEnabled ( bool bFrameEnabled ); + bool IsFrameEnabled ( void ); + + CEGUI::Image* GetDirectImage ( void ); + + void Render ( void ); + + eCGUIType GetType ( void ) { return CGUI_WEBBROWSER; } + +private: + CGUI_Impl* m_pGUI; + CEGUI::ImagesetManager* m_pImagesetManager; + CEGUI::Imageset* m_pImageset; + const CEGUI::Image* m_pImage; + + CWebViewInterface* m_pWebView; + + #include "CGUIElement_Inc.h" +}; + +class CGUIWebBrowserTexture : public CEGUI::DirectX9Texture +{ +public: + CGUIWebBrowserTexture(CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture); + + virtual ushort getWidth() const override { return m_Width; }; + virtual ushort getHeight() const override { return m_Height; }; + + virtual void loadFromFile(const CEGUI::String& filename, const CEGUI::String& resourceGroup) override {}; + virtual void loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight) override {}; + + virtual LPDIRECT3DTEXTURE9 getD3DTexture() const override { return m_pTexture; }; + virtual void preD3DReset() {}; + virtual void postD3DReset() {}; + +private: + IDirect3DTexture9* m_pTexture; + ushort m_Width; + ushort m_Height; +}; + +#endif diff --git a/MTA10/gui/CGUI_Impl.cpp b/MTA10/gui/CGUI_Impl.cpp index e56fbf63187..58a5111bf30 100644 --- a/MTA10/gui/CGUI_Impl.cpp +++ b/MTA10/gui/CGUI_Impl.cpp @@ -482,6 +482,12 @@ CGUIComboBox* CGUI_Impl::_CreateComboBox ( CGUIElement_Impl* pParent, const char } +CGUIWebBrowser* CGUI_Impl::_CreateWebBrowser ( CGUIElement_Impl* pParent ) +{ + return new CGUIWebBrowser_Impl ( this, pParent ); +} + + CGUITexture* CGUI_Impl::CreateTexture ( void ) { return new CGUITexture_Impl ( this ); @@ -1651,6 +1657,21 @@ CGUIComboBox* CGUI_Impl::CreateComboBox ( CGUIComboBox* pParent, const char* szC return _CreateComboBox ( wnd, szCaption ); } + +CGUIWebBrowser* CGUI_Impl::CreateWebBrowser ( CGUIElement* pParent ) +{ + CGUIWindow_Impl* wnd = reinterpret_cast < CGUIWindow_Impl* > ( pParent ); + return _CreateWebBrowser ( wnd ); +} + + +CGUIWebBrowser* CGUI_Impl::CreateWebBrowser ( CGUITab* pParent ) +{ + CGUITab_Impl* wnd = reinterpret_cast < CGUITab_Impl* > ( pParent ); + return _CreateWebBrowser ( wnd ); +} + + void CGUI_Impl::CleanDeadPool () { if ( m_pWindowManager ) diff --git a/MTA10/gui/CGUI_Impl.h b/MTA10/gui/CGUI_Impl.h index a63717afd54..6724ddaa4d5 100644 --- a/MTA10/gui/CGUI_Impl.h +++ b/MTA10/gui/CGUI_Impl.h @@ -134,6 +134,9 @@ class CGUI_Impl : public CGUI, public CGUITabList CGUIComboBox* CreateComboBox ( CGUIElement* pParent = NULL, const char* szCaption = "" ); CGUIComboBox* CreateComboBox ( CGUIComboBox* pParent = NULL, const char* szCaption = "" ); + CGUIWebBrowser* CreateWebBrowser ( CGUIElement* pParent = nullptr ); + CGUIWebBrowser* CreateWebBrowser ( CGUITab* pParent = nullptr ); + CGUIWindow* CreateWnd ( CGUIElement* pParent = NULL, const char* szCaption = "" ); // @@ -234,6 +237,7 @@ class CGUI_Impl : public CGUI, public CGUITabList CGUIScrollPane* _CreateScrollPane ( CGUIElement_Impl* pParent = NULL ); CGUIScrollBar* _CreateScrollBar ( bool bHorizontal, CGUIElement_Impl* pParent = NULL ); CGUIComboBox* _CreateComboBox ( CGUIElement_Impl* pParent = NULL, const char* szCaption = "" ); + CGUIWebBrowser* _CreateWebBrowser ( CGUIElement_Impl* pParent = nullptr ); void SubscribeToMouseEvents(); CGUIFont* CreateFntFromWinFont ( const char* szFontName, const char* szFontWinReg, const char* szFontWinFile, unsigned int uSize = 8, unsigned int uFlags = 0, bool bAutoScale = false ); diff --git a/MTA10/gui/StdInc.h b/MTA10/gui/StdInc.h index 7101881d3ef..fa7cc2545e7 100644 --- a/MTA10/gui/StdInc.h +++ b/MTA10/gui/StdInc.h @@ -33,5 +33,6 @@ #include "CGUIScrollPane_Impl.h" #include "CGUITabPanel_Impl.h" #include "CGUITexture_Impl.h" +#include "CGUIWebBrowser_Impl.h" #include "CGUIWindow_Impl.h" #include "CGUIComboBox_Impl.h" diff --git a/MTA10/gui/gui 2008.vcxproj b/MTA10/gui/gui 2008.vcxproj index 21a03ec2f40..d1b36bd770e 100644 --- a/MTA10/gui/gui 2008.vcxproj +++ b/MTA10/gui/gui 2008.vcxproj @@ -184,6 +184,7 @@ + @@ -214,6 +215,8 @@ + + diff --git a/MTA10/gui/gui 2008.vcxproj.filters b/MTA10/gui/gui 2008.vcxproj.filters index d6aa3863d77..80e5de8853f 100644 --- a/MTA10/gui/gui 2008.vcxproj.filters +++ b/MTA10/gui/gui 2008.vcxproj.filters @@ -86,6 +86,9 @@ Source Files + + Source Files + @@ -238,5 +241,11 @@ Header Files\interface + + Header Files + + + Header Files\interface + \ No newline at end of file diff --git a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index b86f3138004..128f2f39068 100644 --- a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -5125,6 +5125,30 @@ bool CStaticFunctionDefinitions::GUIComboBoxSetItemText ( CClientEntity& Entity, return false; } +CClientGUIElement* CStaticFunctionDefinitions::GUICreateBrowser ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strURL, bool bIsLocal, bool bRelative, CClientGUIElement* pParent ) +{ + CGUIWebBrowser* pElement = m_pGUI->CreateWebBrowser ( pParent ? pParent->GetCGUIElement () : nullptr ); + pElement->SetPosition ( CVector2D ( fX, fY ), bRelative ); + pElement->SetSize ( CVector2D ( fWidth, fHeight ), bRelative ); + + // Register to the gui manager + CVector2D absoluteSize; + pElement->GetSize ( absoluteSize, false ); + auto pGUIElement = new CClientGUIWebBrowser ( bIsLocal, (uint)absoluteSize.fX, (uint)absoluteSize.fY, m_pManager, &LuaMain, pElement ); + pGUIElement->SetParent ( pParent ? pParent : LuaMain.GetResource ()->GetResourceGUIEntity () ); + + // Load CEGUI element texture from webview + pElement->LoadFromWebView ( pGUIElement->GetBrowser ()->GetWebView () ); + + if ( pParent && !pParent->IsCallPropagationEnabled () ) + { + pGUIElement->GetCGUIElement ()->SetInheritsAlpha ( false ); + } + + return pGUIElement; +} + + void CStaticFunctionDefinitions::GUISetText ( CClientEntity& Entity, const char* szText ) { // Are we a CGUI element? diff --git a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 94815713973..da16c9a4898 100644 --- a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -396,7 +396,8 @@ class CStaticFunctionDefinitions static CClientGUIElement* GUICreateRadioButton ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent ); static CClientGUIElement* GUICreateStaticImage ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strFile, bool bRelative, CClientGUIElement* pParent ); static CClientGUIElement* GUICreateComboBox ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent ); - + static CClientGUIElement* GUICreateBrowser ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strURL, bool bIsLocal, bool bRelative, CClientGUIElement* pParent ); + static bool GUIStaticImageLoadImage ( CClientEntity& Element, const SString& strDir ); static bool GUIStaticImageGetNativeSize ( CClientEntity& Entity, CVector2D &vecSize ); diff --git a/MTA10/mods/shared_logic/CClientGUIElement.cpp b/MTA10/mods/shared_logic/CClientGUIElement.cpp index 835525db429..02219769821 100644 --- a/MTA10/mods/shared_logic/CClientGUIElement.cpp +++ b/MTA10/mods/shared_logic/CClientGUIElement.cpp @@ -75,6 +75,9 @@ CClientGUIElement::CClientGUIElement ( CClientManager * pManager, CLuaMain* pLua case CGUI_COMBOBOX: m_strCGUITypeName = "combobox"; break; + case CGUI_WEBBROWSER: + m_strCGUITypeName = "browser"; + break; default: m_strCGUITypeName = "unknown"; break; diff --git a/MTA10/mods/shared_logic/CClientGUIElement.h b/MTA10/mods/shared_logic/CClientGUIElement.h index dd51129b779..dca17892e00 100644 --- a/MTA10/mods/shared_logic/CClientGUIElement.h +++ b/MTA10/mods/shared_logic/CClientGUIElement.h @@ -54,7 +54,7 @@ class CClientGUIElement : public CClientEntity public: CClientGUIElement ( CClientManager* pManager, CLuaMain* pLuaMain, CGUIElement* pCGUIElement, ElementID ID = INVALID_ELEMENT_ID ); - ~CClientGUIElement ( void ); + virtual ~CClientGUIElement ( void ); void Unlink ( void ); diff --git a/MTA10/mods/shared_logic/CClientWebBrowser.cpp b/MTA10/mods/shared_logic/CClientWebBrowser.cpp index 2da06258d47..7ec67dde2f2 100644 --- a/MTA10/mods/shared_logic/CClientWebBrowser.cpp +++ b/MTA10/mods/shared_logic/CClientWebBrowser.cpp @@ -228,3 +228,10 @@ bool CClientWebBrowser::Events_OnResourcePathCheck ( SString& strURL ) return false; } + + +CClientGUIWebBrowser::CClientGUIWebBrowser ( bool isLocal, uint width, uint height, CClientManager* pManager, CLuaMain* pLuaMain, CGUIElement* pCGUIElement, ElementID ID ) + : CClientGUIElement ( pManager, pLuaMain, pCGUIElement, ID ) +{ + m_pBrowser = std::unique_ptr < CClientWebBrowser > ( g_pClientGame->GetManager ()->GetRenderElementManager ()->CreateWebBrowser ( width, height, isLocal, false ) ); +} diff --git a/MTA10/mods/shared_logic/CClientWebBrowser.h b/MTA10/mods/shared_logic/CClientWebBrowser.h index 880115e0b70..179a15aaf68 100644 --- a/MTA10/mods/shared_logic/CClientWebBrowser.h +++ b/MTA10/mods/shared_logic/CClientWebBrowser.h @@ -69,4 +69,15 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa CResource* m_pResource; }; +class CClientGUIWebBrowser : public CClientGUIElement +{ +public: + CClientGUIWebBrowser ( bool isLocal, uint width, uint height, CClientManager* pManager, CLuaMain* pLuaMain, CGUIElement* pCGUIElement, ElementID ID = INVALID_ELEMENT_ID ); + + inline CClientWebBrowser* GetBrowser () { return m_pBrowser.get (); } + +private: + std::unique_ptr < CClientWebBrowser > m_pBrowser; +}; + #endif diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp index 2055d83f5a0..9df2e82886a 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp @@ -460,3 +460,67 @@ int CLuaFunctionDefs::GetBrowserProperty ( lua_State* luaVM ) lua_pushnil ( luaVM ); return 1; } + +int CLuaFunctionDefs::GUICreateBrowser ( lua_State* luaVM ) +{ +// element guiCreateBrowser ( float x, float y, float width, float height, string url, bool isLocal, bool relative, [element parent = nil] ) + float x; float y; float width; float height; SString url; bool bIsLocal; bool bIsRelative; CClientGUIElement* parent; + + CScriptArgReader argStream ( luaVM ); + argStream.ReadNumber ( x ); + argStream.ReadNumber ( y ); + argStream.ReadNumber ( width ); + argStream.ReadNumber ( height ); + argStream.ReadString ( url ); + argStream.ReadBool ( bIsLocal ); + argStream.ReadBool ( bIsRelative ); + argStream.ReadUserData ( parent, nullptr ); + + if ( !argStream.HasErrors () ) + { + CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); + + if ( pLuaMain ) + { + CResource* pResource = pLuaMain->GetResource(); + SString strPath; + //if ( CResourceManager::ParseResourcePathInput( url, pResource, strPath ) ) + { + CClientGUIElement* pGUIElement = CStaticFunctionDefinitions::GUICreateBrowser ( *pLuaMain, x, y, width, height, strPath, bIsLocal, bIsRelative, parent ); + lua_pushelement ( luaVM, pGUIElement ); + return 1; + } + /*else + argStream.SetCustomError( strPath, "Bad file path" );*/ + } + } + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); + + lua_pushboolean ( luaVM, false ); + return 1; +} + +int CLuaFunctionDefs::GUIGetBrowser ( lua_State* luaVM ) +{ +// webbrowser guiGetBrowser ( gui-webbrowser browser ) + CClientGUIElement* pGUIElement; + + CScriptArgReader argStream ( luaVM ); + argStream.ReadUserData < CGUIWebBrowser > ( pGUIElement ); + + if ( !argStream.HasErrors () ) + { + if ( IS_GUI(pGUIElement) && pGUIElement->GetCGUIType () == CGUI_WEBBROWSER ) + { + CClientGUIWebBrowser* pGUIBrowser = static_cast < CClientGUIWebBrowser* > ( pGUIElement ); + lua_pushelement ( luaVM, pGUIBrowser->GetBrowser () ); + return 1; + } + } + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); + + lua_pushboolean ( luaVM, false ); + return 1; +} diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h index 77627a4d7f0..532332768cf 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h @@ -1035,6 +1035,8 @@ class CLuaFunctionDefs LUA_DECLARE ( IsBrowserFocused ); LUA_DECLARE ( SetBrowserProperty ); LUA_DECLARE ( GetBrowserProperty ); + LUA_DECLARE ( GUICreateBrowser ); + LUA_DECLARE ( GUIGetBrowser ); private: // Static references to objects diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.cpp index 2cc7f9a885c..27c1ad348cb 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.cpp @@ -144,6 +144,7 @@ IMPLEMENT_ENUM_BEGIN( eCGUIType ) ADD_ENUM ( CGUI_SCROLLPANE, "gui-scrollpane" ) ADD_ENUM ( CGUI_SCROLLBAR, "gui-scrollbar" ) ADD_ENUM ( CGUI_COMBOBOX, "gui-combobox" ) + ADD_ENUM ( CGUI_WEBBROWSER, "gui-browser" ) IMPLEMENT_ENUM_END( "gui-type" ) IMPLEMENT_ENUM_BEGIN( eDxTestMode ) diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.h b/MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.h index 042eabcf060..d0a32b1da58 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.h +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.h @@ -78,6 +78,7 @@ inline eCGUIType GetClassType ( CGUIWindow* ) { return CGUI_WINDOW; } inline eCGUIType GetClassType ( CGUIScrollPane* ) { return CGUI_SCROLLPANE; } inline eCGUIType GetClassType ( CGUIScrollBar* ) { return CGUI_SCROLLBAR; } inline eCGUIType GetClassType ( CGUIComboBox* ) { return CGUI_COMBOBOX; } +inline eCGUIType GetClassType ( CGUIWebBrowser* ) { return CGUI_WEBBROWSER; } // class -> class name @@ -126,6 +127,7 @@ inline SString GetClassTypeName ( CGUIWindow* ) { return "gui-window"; } inline SString GetClassTypeName ( CGUIScrollPane* ) { return "gui-scrollpane"; } inline SString GetClassTypeName ( CGUIScrollBar* ) { return "gui-scrollbar"; } inline SString GetClassTypeName ( CGUIComboBox* ) { return "gui-combobox"; } +inline SString GetClassTypeName ( CGUIWebBrowser* ) { return "gui-browser"; } inline SString GetClassTypeName ( CResource* ) { return "resource-data"; } inline SString GetClassTypeName ( CXMLNode* ) { return "xml-node"; } diff --git a/MTA10/mods/shared_logic/lua/CLuaMain.cpp b/MTA10/mods/shared_logic/lua/CLuaMain.cpp index aadb304f800..d13239eb96d 100644 --- a/MTA10/mods/shared_logic/lua/CLuaMain.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaMain.cpp @@ -1652,6 +1652,13 @@ void CLuaMain::AddBrowserClass ( lua_State* luaVM ) lua_classvariable ( luaVM, "volume", "setBrowserVolume", NULL ); lua_registerclass ( luaVM, "Browser", "DxTexture" ); + + // Add GUI browser class + lua_newclass ( luaVM ); + lua_classfunction ( luaVM, "create", "guiCreateBrowser" ); + lua_classfunction ( luaVM, "getBrowser", "guiGetBrowser" ); + lua_classvariable ( luaVM, "browser", NULL, "guiGetBrowser" ); + lua_registerclass ( luaVM, "GuiBrowser", "GuiElement" ); } diff --git a/MTA10/mods/shared_logic/lua/CLuaManager.cpp b/MTA10/mods/shared_logic/lua/CLuaManager.cpp index bdc2f83f639..2a22ed12a71 100644 --- a/MTA10/mods/shared_logic/lua/CLuaManager.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaManager.cpp @@ -1210,6 +1210,8 @@ void CLuaManager::LoadCFunctions ( void ) CLuaCFunctions::AddFunction ( "isBrowserFocused", CLuaFunctionDefs::IsBrowserFocused ); CLuaCFunctions::AddFunction ( "setBrowserProperty", CLuaFunctionDefs::SetBrowserProperty ); CLuaCFunctions::AddFunction ( "getBrowserProperty", CLuaFunctionDefs::GetBrowserProperty ); + CLuaCFunctions::AddFunction ( "guiCreateBrowser", CLuaFunctionDefs::GUICreateBrowser ); + CLuaCFunctions::AddFunction ( "guiGetBrowser", CLuaFunctionDefs::GUIGetBrowser ); // Luadef definitions CLuaFileDefs::LoadFunctions (); diff --git a/MTA10/mods/shared_logic/luadefs/CLuaClassDefs.cpp b/MTA10/mods/shared_logic/luadefs/CLuaClassDefs.cpp index 04469c96caf..134480730ad 100644 --- a/MTA10/mods/shared_logic/luadefs/CLuaClassDefs.cpp +++ b/MTA10/mods/shared_logic/luadefs/CLuaClassDefs.cpp @@ -320,6 +320,7 @@ const char* CLuaClassDefs::GetEntityClass ( CClientEntity* pEntity ) case CGUI_SCROLLPANE: return "GuiScrollPane"; case CGUI_SCROLLBAR: return "GuiScrollBar"; case CGUI_COMBOBOX: return "GuiComboBox"; + case CGUI_WEBBROWSER: return "GuiBrowser"; } return "GuiElement"; } diff --git a/MTA10/sdk/core/CWebViewInterface.h b/MTA10/sdk/core/CWebViewInterface.h index 04b6dc46289..ee42db9796a 100644 --- a/MTA10/sdk/core/CWebViewInterface.h +++ b/MTA10/sdk/core/CWebViewInterface.h @@ -11,6 +11,8 @@ #ifndef __CWEBVIEWINTERFACE_H #define __CWEBVIEWINTERFACE_H +#include "CWebCoreInterface.h" + class CWebBrowserEventsInterface; class CWebViewInterface @@ -26,6 +28,7 @@ class CWebViewInterface virtual void GetTitle ( SString& outTitle ) = 0; virtual void SetRenderingPaused ( bool bPaused ) = 0; virtual void Focus () = 0; + virtual IDirect3DTexture9* GetTexture () = 0; virtual void ExecuteJavascript ( const SString& strJavascriptCode ) = 0; diff --git a/MTA10/sdk/gui/CGUI.h b/MTA10/sdk/gui/CGUI.h index 92584c215fa..bc020dd537b 100644 --- a/MTA10/sdk/gui/CGUI.h +++ b/MTA10/sdk/gui/CGUI.h @@ -33,6 +33,7 @@ class CGUI; #include "CGUIScrollPane.h" #include "CGUITexture.h" #include "CGUIWindow.h" +#include "CGUIWebBrowser.h" #include "CGUITabPanel.h" #include "CGUIComboBox.h" #include "CGUITypes.h" @@ -144,6 +145,9 @@ class CGUI virtual CGUIComboBox* CreateComboBox ( CGUIElement* pParent = NULL, const char* szCaption = "" ) = 0; virtual CGUIComboBox* CreateComboBox ( CGUIComboBox* pParent = NULL, const char* szCaption = "" ) = 0; + virtual CGUIWebBrowser* CreateWebBrowser ( CGUIElement* pParent = nullptr ) = 0; + virtual CGUIWebBrowser* CreateWebBrowser ( CGUITab* pParent = nullptr ) = 0; + // virtual CGUIWindow* CreateWnd ( CGUIElement* pParent = NULL, const char* szCaption = "" ) = 0; diff --git a/MTA10/sdk/gui/CGUIElement.h b/MTA10/sdk/gui/CGUIElement.h index 6da941ce06a..64753b8649a 100644 --- a/MTA10/sdk/gui/CGUIElement.h +++ b/MTA10/sdk/gui/CGUIElement.h @@ -34,7 +34,8 @@ enum eCGUIType { CGUI_WINDOW, CGUI_SCROLLPANE, CGUI_SCROLLBAR, - CGUI_COMBOBOX + CGUI_COMBOBOX, + CGUI_WEBBROWSER }; class CGUIElement diff --git a/MTA10/sdk/gui/CGUIWebBrowser.h b/MTA10/sdk/gui/CGUIWebBrowser.h new file mode 100644 index 00000000000..ce4a7af1f42 --- /dev/null +++ b/MTA10/sdk/gui/CGUIWebBrowser.h @@ -0,0 +1,33 @@ +/***************************************************************************** +* +* PROJECT: Multi Theft Auto v1.0 +* LICENSE: See LICENSE in the top level directory +* FILE: sdk/gui/CGUIWebBrowser.h +* PURPOSE: Web browser widget interface +* +* Multi Theft Auto is available from http://www.multitheftauto.com/ +* +*****************************************************************************/ +#ifndef __CGUIWEBBROWSER_H +#define __CGUIWEBBROWSER_H + +#include "CGUIElement.h" +#include "CGUITexture.h" + +class CGUIWebBrowser : public CGUIElement +{ +public: + virtual ~CGUIWebBrowser () {}; + + virtual void LoadFromWebView ( class CWebViewInterface* pWebView ) = 0; + + virtual void Clear () = 0; + virtual bool GetNativeSize ( CVector2D &vecSize ) = 0; + + virtual void SetFrameEnabled ( bool bFrameEnabled ) = 0; + virtual bool IsFrameEnabled () = 0; + + virtual void Render () = 0; +}; + +#endif diff --git a/Shared/Core 2013.sln b/Shared/Core 2013.sln index aa3bf76231b..93f5edf20ee 100644 --- a/Shared/Core 2013.sln +++ b/Shared/Core 2013.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30110.0 +VisualStudioVersion = 12.0.21005.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CEGUI", "CEGUI", "{4C0157CE-9DD9-4729-8CDF-F5B9D2D71D2B}" EndProject @@ -725,31 +725,25 @@ Global {C5076389-A166-4FB8-A083-AC5443482C31}.Release|x64.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|Win32.ActiveCfg = Debug|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|Win32.Build.0 = Debug|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|x64.ActiveCfg = Debug|x64 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|x64.Build.0 = Debug|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|x64.ActiveCfg = Debug|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|Win32.ActiveCfg = Debug|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|Win32.Build.0 = Debug|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|x64.ActiveCfg = Debug|x64 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|x64.Build.0 = Debug|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|x64.ActiveCfg = Debug|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|Win32.ActiveCfg = Debug|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|Win32.Build.0 = Debug|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.ActiveCfg = Debug|x64 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.Build.0 = Debug|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.ActiveCfg = Debug|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|Win32.ActiveCfg = Nightly|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|Win32.Build.0 = Nightly|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|x64.ActiveCfg = Release|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|x64.ActiveCfg = Nightly|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|Win32.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|Win32.Build.0 = Release|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|x64.ActiveCfg = Release|x64 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|x64.Build.0 = Release|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|x64.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|Win32.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|Win32.Build.0 = Release|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|x64.ActiveCfg = Release|x64 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|x64.Build.0 = Release|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|x64.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|Win32.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|Win32.Build.0 = Release|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.ActiveCfg = Release|x64 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.Build.0 = Release|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/vendor/cegui-0.4.0-custom/include/renderers/directx9GUIRenderer/d3d9texture.h b/vendor/cegui-0.4.0-custom/include/renderers/directx9GUIRenderer/d3d9texture.h index d04611ba5e2..7382ac3d489 100644 --- a/vendor/cegui-0.4.0-custom/include/renderers/directx9GUIRenderer/d3d9texture.h +++ b/vendor/cegui-0.4.0-custom/include/renderers/directx9GUIRenderer/d3d9texture.h @@ -56,10 +56,10 @@ class DIRECTX9_GUIRENDERER_API DirectX9Texture : public Texture /************************************************************************* Construction & Destruction (by Renderer object only) *************************************************************************/ +public: // changed by MTA; BE CAREFUL! DirectX9Texture(Renderer* owner); virtual ~DirectX9Texture(void); -public: /*! \brief Returns the current pixel width of the texture @@ -122,7 +122,7 @@ class DIRECTX9_GUIRENDERER_API DirectX9Texture : public Texture \return Pointer to the IDirect3DTexture9 interface currently being used by this Texture object */ - LPDIRECT3DTEXTURE9 getD3DTexture(void) const {return d_d3dtexture;} + virtual LPDIRECT3DTEXTURE9 getD3DTexture(void) const {return d_d3dtexture;} // From 9e0a812716cee209e98379defaaff3eec3d3f1ba Mon Sep 17 00:00:00 2001 From: Jusonex Date: Thu, 9 Apr 2015 20:20:26 +0200 Subject: [PATCH 2/3] 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 :( ) --- MTA10/core/CWebView.cpp | 12 ++- MTA10/core/CWebView.h | 2 +- MTA10/gui/CGUIWebBrowser_Impl.cpp | 113 ++++++++++++++++++++--------- MTA10/gui/CGUIWebBrowser_Impl.h | 40 ++++++---- MTA10/sdk/core/CWebViewInterface.h | 2 +- MTA10/sdk/gui/CGUIWebBrowser.h | 3 - Shared/Core 2013.sln | 22 ++++-- 7 files changed, 129 insertions(+), 65 deletions(-) diff --git a/MTA10/core/CWebView.cpp b/MTA10/core/CWebView.cpp index 3fb3c4d40d2..f18009f95fb 100644 --- a/MTA10/core/CWebView.cpp +++ b/MTA10/core/CWebView.cpp @@ -128,14 +128,18 @@ void CWebView::SetRenderingPaused ( bool bPaused ) m_pWebView->GetHost ()->WasHidden ( bPaused ); } -void CWebView::Focus () +void CWebView::Focus ( bool state ) { if ( m_pWebView ) { - m_pWebView->GetHost ()->SetFocus ( true ); - m_pWebView->GetHost ()->SendFocusEvent ( true ); + m_pWebView->GetHost ()->SetFocus ( state ); + m_pWebView->GetHost ()->SendFocusEvent ( state ); } - g_pCore->GetWebCore()->SetFocusedWebView ( this ); + + if ( state ) + g_pCore->GetWebCore ()->SetFocusedWebView ( this ); + else if ( g_pCore->GetWebCore ()->GetFocusedWebView () == this ) + g_pCore->GetWebCore ()->SetFocusedWebView ( nullptr ); } void CWebView::ClearTexture () diff --git a/MTA10/core/CWebView.h b/MTA10/core/CWebView.h index d8e14af1c98..7f9684c3ef1 100644 --- a/MTA10/core/CWebView.h +++ b/MTA10/core/CWebView.h @@ -48,7 +48,7 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH void GetURL ( SString& outURL ); void GetTitle ( SString& outTitle ); void SetRenderingPaused ( bool bPaused ); - void Focus (); + void Focus ( bool state = true ); IDirect3DTexture9* GetTexture () { return static_cast(m_pWebBrowserRenderItem->m_pD3DTexture); } void ClearTexture (); inline void NotifyPaint () { m_PaintCV.notify_one (); } diff --git a/MTA10/gui/CGUIWebBrowser_Impl.cpp b/MTA10/gui/CGUIWebBrowser_Impl.cpp index d5cfbe5ad0a..9cf09ffeb34 100644 --- a/MTA10/gui/CGUIWebBrowser_Impl.cpp +++ b/MTA10/gui/CGUIWebBrowser_Impl.cpp @@ -39,6 +39,14 @@ CGUIWebBrowser_Impl::CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent AddEvents (); + // Apply browser events + m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseButtonDown, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseButtonDown, this ) ); + m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseButtonUp, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseButtonUp, this ) ); + m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseMove, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseMove, this ) ); + m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseWheel, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseWheel, this ) ); + m_pWindow->subscribeEvent ( CEGUI::Window::EventActivated, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_Activated, this ) ); + m_pWindow->subscribeEvent ( CEGUI::Window::EventDeactivated, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_Deactivated, this ) ); + // If a parent is specified, add it to it's children list, if not, add it as a child to the pManager if ( pParent ) { @@ -51,14 +59,28 @@ CGUIWebBrowser_Impl::CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent } } -CGUIWebBrowser_Impl::~CGUIWebBrowser_Impl ( void ) +CGUIWebBrowser_Impl::~CGUIWebBrowser_Impl () { - // Clear the image - Clear (); + Clear(); DestroyElement (); } +void CGUIWebBrowser_Impl::Clear () +{ + // Stop the control from using it + reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( nullptr ); + + // Kill the images + if ( m_pImageset ) + { + m_pImageset->undefineAllImages (); + m_pImagesetManager->destroyImageset ( m_pImageset ); + m_pImage = nullptr; + m_pImageset = nullptr; + } +} + bool CGUIWebBrowser_Impl::LoadFromTexture ( IDirect3DTexture9* pTexture ) { if ( m_pImageset && m_pImage ) @@ -102,35 +124,6 @@ void CGUIWebBrowser_Impl::LoadFromWebView ( CWebViewInterface* pWebView ) LoadFromTexture ( pWebView->GetTexture () ); } -void CGUIWebBrowser_Impl::Clear ( void ) -{ - // Stop the control from using it - reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( nullptr ); - - // Kill the images - if ( m_pImageset ) - { - m_pImageset->undefineAllImages (); - m_pImagesetManager->destroyImageset ( m_pImageset ); - m_pImage = nullptr; - m_pImageset = nullptr; - } -} - -bool CGUIWebBrowser_Impl::GetNativeSize ( CVector2D& vecSize ) -{ - auto pTexture = m_pWebView->GetTexture (); - D3DSURFACE_DESC SurfaceDesc; - if ( pTexture->GetLevelDesc ( 0, &SurfaceDesc ) == ERROR_SUCCESS ) - { - vecSize.fX = (float)SurfaceDesc.Width; - vecSize.fY = (float)SurfaceDesc.Height; - return true; - } - - return false; -} - void CGUIWebBrowser_Impl::SetFrameEnabled ( bool bFrameEnabled ) { reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> setFrameEnabled ( bFrameEnabled ); @@ -153,10 +146,64 @@ void CGUIWebBrowser_Impl::Render ( void ) return reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> render (); } +bool CGUIWebBrowser_Impl::Event_MouseButtonDown ( const CEGUI::EventArgs& e ) +{ + const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e ); + + if ( args.button == CEGUI::MouseButton::LeftButton ) + m_pWebView->InjectMouseDown ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_LEFT ); + else if ( args.button == CEGUI::MouseButton::MiddleButton ) + m_pWebView->InjectMouseDown ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_MIDDLE ); + else if ( args.button == CEGUI::MouseButton::RightButton ) + m_pWebView->InjectMouseDown ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_RIGHT ); + + return true; +} + +bool CGUIWebBrowser_Impl::Event_MouseButtonUp ( const CEGUI::EventArgs& e ) +{ + const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e ); + + if ( args.button == CEGUI::MouseButton::LeftButton ) + m_pWebView->InjectMouseUp ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_LEFT ); + else if ( args.button == CEGUI::MouseButton::MiddleButton ) + m_pWebView->InjectMouseUp ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_MIDDLE ); + else if ( args.button == CEGUI::MouseButton::RightButton ) + m_pWebView->InjectMouseUp ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_RIGHT ); + + return true; +} + +bool CGUIWebBrowser_Impl::Event_MouseMove ( const CEGUI::EventArgs& e ) +{ + const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e ); + + m_pWebView->InjectMouseMove ( (int)args.position.d_x - m_pWindow->windowToScreenX ( 0.0f ), (int)args.position.d_y - m_pWindow->windowToScreenY ( 0.0f ) ); + return true; +} + +bool CGUIWebBrowser_Impl::Event_MouseWheel ( const CEGUI::EventArgs& e ) +{ + const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e ); + + m_pWebView->InjectMouseWheel ( args.wheelChange * 30, 0 ); + return true; +} + +bool CGUIWebBrowser_Impl::Event_Activated ( const CEGUI::EventArgs& e ) +{ + m_pWebView->Focus ( true ); + return true; +} +bool CGUIWebBrowser_Impl::Event_Deactivated ( const CEGUI::EventArgs& e ) +{ + m_pWebView->Focus ( false ); + return true; +} -CGUIWebBrowserTexture::CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ) : CEGUI::DirectX9Texture(pOwner) +CGUIWebBrowserTexture::CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ) : CEGUI::DirectX9Texture ( pOwner ) { m_pTexture = pTexture; diff --git a/MTA10/gui/CGUIWebBrowser_Impl.h b/MTA10/gui/CGUIWebBrowser_Impl.h index 540aff05dcf..b29fbb19863 100644 --- a/MTA10/gui/CGUIWebBrowser_Impl.h +++ b/MTA10/gui/CGUIWebBrowser_Impl.h @@ -24,21 +24,28 @@ class CGUIWebBrowser_Impl : public CGUIWebBrowser, public CGUIElement_Impl { public: CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent = nullptr ); - ~CGUIWebBrowser_Impl ( void ); + ~CGUIWebBrowser_Impl (); + void Clear (); void LoadFromWebView ( CWebViewInterface* pWebView ); bool LoadFromTexture ( IDirect3DTexture9* pD3DTexture ); - bool GetNativeSize ( CVector2D& vecSize ); - void Clear ( void ); void SetFrameEnabled ( bool bFrameEnabled ); - bool IsFrameEnabled ( void ); + bool IsFrameEnabled (); - CEGUI::Image* GetDirectImage ( void ); + CEGUI::Image* GetDirectImage (); - void Render ( void ); + void Render (); - eCGUIType GetType ( void ) { return CGUI_WEBBROWSER; } + eCGUIType GetType () { return CGUI_WEBBROWSER; } + +protected: + bool Event_MouseButtonDown ( const CEGUI::EventArgs& e ); + bool Event_MouseButtonUp ( const CEGUI::EventArgs& e ); + bool Event_MouseWheel ( const CEGUI::EventArgs& e ); + bool Event_MouseMove ( const CEGUI::EventArgs& e ); + bool Event_Activated ( const CEGUI::EventArgs& e ); + bool Event_Deactivated ( const CEGUI::EventArgs& e ); private: CGUI_Impl* m_pGUI; @@ -51,20 +58,23 @@ class CGUIWebBrowser_Impl : public CGUIWebBrowser, public CGUIElement_Impl #include "CGUIElement_Inc.h" }; + +// The purpose of this class is to provide an externally managed DirectX texture class CGUIWebBrowserTexture : public CEGUI::DirectX9Texture { public: - CGUIWebBrowserTexture(CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture); + CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ); - virtual ushort getWidth() const override { return m_Width; }; - virtual ushort getHeight() const override { return m_Height; }; + virtual ushort getWidth () const override { return m_Width; }; + virtual ushort getHeight () const override { return m_Height; }; - virtual void loadFromFile(const CEGUI::String& filename, const CEGUI::String& resourceGroup) override {}; - virtual void loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight) override {}; + // Override with empty function (--> eliminate the functinions from DirectX9Texture) + virtual void loadFromFile ( const CEGUI::String& filename, const CEGUI::String& resourceGroup ) override {}; + virtual void loadFromMemory ( const void* buffPtr, uint buffWidth, uint buffHeight ) override {}; - virtual LPDIRECT3DTEXTURE9 getD3DTexture() const override { return m_pTexture; }; - virtual void preD3DReset() {}; - virtual void postD3DReset() {}; + virtual LPDIRECT3DTEXTURE9 getD3DTexture () const override { return m_pTexture; }; + virtual void preD3DReset () {}; + virtual void postD3DReset () {}; private: IDirect3DTexture9* m_pTexture; diff --git a/MTA10/sdk/core/CWebViewInterface.h b/MTA10/sdk/core/CWebViewInterface.h index ee42db9796a..a9c6e269680 100644 --- a/MTA10/sdk/core/CWebViewInterface.h +++ b/MTA10/sdk/core/CWebViewInterface.h @@ -27,7 +27,7 @@ class CWebViewInterface virtual void GetURL ( SString& outURL ) = 0; virtual void GetTitle ( SString& outTitle ) = 0; virtual void SetRenderingPaused ( bool bPaused ) = 0; - virtual void Focus () = 0; + virtual void Focus ( bool state = true ) = 0; virtual IDirect3DTexture9* GetTexture () = 0; virtual void ExecuteJavascript ( const SString& strJavascriptCode ) = 0; diff --git a/MTA10/sdk/gui/CGUIWebBrowser.h b/MTA10/sdk/gui/CGUIWebBrowser.h index ce4a7af1f42..639a54100b5 100644 --- a/MTA10/sdk/gui/CGUIWebBrowser.h +++ b/MTA10/sdk/gui/CGUIWebBrowser.h @@ -21,9 +21,6 @@ class CGUIWebBrowser : public CGUIElement virtual void LoadFromWebView ( class CWebViewInterface* pWebView ) = 0; - virtual void Clear () = 0; - virtual bool GetNativeSize ( CVector2D &vecSize ) = 0; - virtual void SetFrameEnabled ( bool bFrameEnabled ) = 0; virtual bool IsFrameEnabled () = 0; diff --git a/Shared/Core 2013.sln b/Shared/Core 2013.sln index 93f5edf20ee..aa3bf76231b 100644 --- a/Shared/Core 2013.sln +++ b/Shared/Core 2013.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +VisualStudioVersion = 12.0.30110.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CEGUI", "CEGUI", "{4C0157CE-9DD9-4729-8CDF-F5B9D2D71D2B}" EndProject @@ -725,25 +725,31 @@ Global {C5076389-A166-4FB8-A083-AC5443482C31}.Release|x64.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|Win32.ActiveCfg = Debug|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|Win32.Build.0 = Debug|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|x64.ActiveCfg = Debug|Win32 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|x64.ActiveCfg = Debug|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug client only|x64.Build.0 = Debug|x64 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|Win32.ActiveCfg = Debug|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|Win32.Build.0 = Debug|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|x64.ActiveCfg = Debug|Win32 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|x64.ActiveCfg = Debug|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug server only|x64.Build.0 = Debug|x64 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|Win32.ActiveCfg = Debug|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|Win32.Build.0 = Debug|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.ActiveCfg = Debug|Win32 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.ActiveCfg = Debug|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.Build.0 = Debug|x64 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|Win32.ActiveCfg = Nightly|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|Win32.Build.0 = Nightly|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|x64.ActiveCfg = Nightly|Win32 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Nightly|x64.ActiveCfg = Release|x64 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|Win32.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|Win32.Build.0 = Release|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|x64.ActiveCfg = Release|Win32 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|x64.ActiveCfg = Release|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release client only|x64.Build.0 = Release|x64 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|Win32.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|Win32.Build.0 = Release|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|x64.ActiveCfg = Release|Win32 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|x64.ActiveCfg = Release|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release server only|x64.Build.0 = Release|x64 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|Win32.ActiveCfg = Release|Win32 {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|Win32.Build.0 = Release|Win32 - {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.ActiveCfg = Release|Win32 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.ActiveCfg = Release|x64 + {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From e3cb676602bcdc895515e79beb039200a20d9130 Mon Sep 17 00:00:00 2001 From: Jusonex Date: Thu, 9 Apr 2015 21:00:45 +0200 Subject: [PATCH 3/3] CEF CEGUI widget: Increased scroll speed Removed guiCreateBrowser's URL parameter (use guiBrowser:getBrowser():loadURL instead) --- MTA10/gui/CGUIWebBrowser_Impl.cpp | 2 +- .../logic/CStaticFunctionDefinitions.cpp | 2 +- .../logic/CStaticFunctionDefinitions.h | 2 +- .../lua/CLuaFunctionDefs.Browser.cpp | 19 ++++++------------- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/MTA10/gui/CGUIWebBrowser_Impl.cpp b/MTA10/gui/CGUIWebBrowser_Impl.cpp index 9cf09ffeb34..16ec0f465e5 100644 --- a/MTA10/gui/CGUIWebBrowser_Impl.cpp +++ b/MTA10/gui/CGUIWebBrowser_Impl.cpp @@ -186,7 +186,7 @@ bool CGUIWebBrowser_Impl::Event_MouseWheel ( const CEGUI::EventArgs& e ) { const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e ); - m_pWebView->InjectMouseWheel ( args.wheelChange * 30, 0 ); + m_pWebView->InjectMouseWheel ( args.wheelChange * 40, 0 ); return true; } diff --git a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 128f2f39068..68b10020400 100644 --- a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -5125,7 +5125,7 @@ bool CStaticFunctionDefinitions::GUIComboBoxSetItemText ( CClientEntity& Entity, return false; } -CClientGUIElement* CStaticFunctionDefinitions::GUICreateBrowser ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strURL, bool bIsLocal, bool bRelative, CClientGUIElement* pParent ) +CClientGUIElement* CStaticFunctionDefinitions::GUICreateBrowser ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, bool bIsLocal, bool bRelative, CClientGUIElement* pParent ) { CGUIWebBrowser* pElement = m_pGUI->CreateWebBrowser ( pParent ? pParent->GetCGUIElement () : nullptr ); pElement->SetPosition ( CVector2D ( fX, fY ), bRelative ); diff --git a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h index da16c9a4898..223a0300233 100644 --- a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -396,7 +396,7 @@ class CStaticFunctionDefinitions static CClientGUIElement* GUICreateRadioButton ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent ); static CClientGUIElement* GUICreateStaticImage ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strFile, bool bRelative, CClientGUIElement* pParent ); static CClientGUIElement* GUICreateComboBox ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent ); - static CClientGUIElement* GUICreateBrowser ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strURL, bool bIsLocal, bool bRelative, CClientGUIElement* pParent ); + static CClientGUIElement* GUICreateBrowser ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, bool bIsLocal, bool bRelative, CClientGUIElement* pParent ); static bool GUIStaticImageLoadImage ( CClientEntity& Element, const SString& strDir ); diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp index 9df2e82886a..b71ea5e0b60 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp @@ -463,7 +463,7 @@ int CLuaFunctionDefs::GetBrowserProperty ( lua_State* luaVM ) int CLuaFunctionDefs::GUICreateBrowser ( lua_State* luaVM ) { -// element guiCreateBrowser ( float x, float y, float width, float height, string url, bool isLocal, bool relative, [element parent = nil] ) +// element guiCreateBrowser ( float x, float y, float width, float height, bool isLocal, bool relative, [element parent = nil] ) float x; float y; float width; float height; SString url; bool bIsLocal; bool bIsRelative; CClientGUIElement* parent; CScriptArgReader argStream ( luaVM ); @@ -482,16 +482,9 @@ int CLuaFunctionDefs::GUICreateBrowser ( lua_State* luaVM ) if ( pLuaMain ) { - CResource* pResource = pLuaMain->GetResource(); - SString strPath; - //if ( CResourceManager::ParseResourcePathInput( url, pResource, strPath ) ) - { - CClientGUIElement* pGUIElement = CStaticFunctionDefinitions::GUICreateBrowser ( *pLuaMain, x, y, width, height, strPath, bIsLocal, bIsRelative, parent ); - lua_pushelement ( luaVM, pGUIElement ); - return 1; - } - /*else - argStream.SetCustomError( strPath, "Bad file path" );*/ + CClientGUIElement* pGUIElement = CStaticFunctionDefinitions::GUICreateBrowser ( *pLuaMain, x, y, width, height, bIsLocal, bIsRelative, parent ); + lua_pushelement ( luaVM, pGUIElement ); + return 1; } } else @@ -501,7 +494,7 @@ int CLuaFunctionDefs::GUICreateBrowser ( lua_State* luaVM ) return 1; } -int CLuaFunctionDefs::GUIGetBrowser ( lua_State* luaVM ) +int CLuaFunctionDefs::GUIGetBrowser ( lua_State* luaVM ) // Or rather guiGetBrowserBrowser? { // webbrowser guiGetBrowser ( gui-webbrowser browser ) CClientGUIElement* pGUIElement; @@ -511,7 +504,7 @@ int CLuaFunctionDefs::GUIGetBrowser ( lua_State* luaVM ) if ( !argStream.HasErrors () ) { - if ( IS_GUI(pGUIElement) && pGUIElement->GetCGUIType () == CGUI_WEBBROWSER ) + if ( IS_GUI ( pGUIElement ) && pGUIElement->GetCGUIType () == CGUI_WEBBROWSER ) { CClientGUIWebBrowser* pGUIBrowser = static_cast < CClientGUIWebBrowser* > ( pGUIElement ); lua_pushelement ( luaVM, pGUIBrowser->GetBrowser () );