User:Jusonex: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 2: | Line 2: | ||
===Awesomium API=== | ===Awesomium API=== | ||
====How to test==== | ====How to test==== | ||
Install the | Install the latest installer from ('''run it as admin manually!'''): https://jusonex.net/public/mta/cef/ | ||
If it doesn't work, you'll have to install the x86 VC++ Redist 2013 (http://www.microsoft.com/en-us/download/details.aspx?id=40784). | If it doesn't work, you'll have to install the x86 VC++ Redist 2013 (http://www.microsoft.com/en-us/download/details.aspx?id=40784). | ||
Line 133: | Line 133: | ||
====Examples==== | ====Examples==== | ||
Examples on: https://github.com/Jusonex/mtasa_cef_tools | |||
=====Example 1: A 2D browser with mouse and a simple input handler===== | =====Example 1: A 2D browser with mouse and a simple input handler===== | ||
<syntaxhighlight lang="lua">local webBrowser = createBrowser(1024, 768, false) | <syntaxhighlight lang="lua">local webBrowser = createBrowser(1024, 768, false) | ||
requestBrowserPages({"youtube.com"}) | requestBrowserPages({"youtube.com"}) | ||
focusBrowser(webBrowser) | |||
addCommandHandler("load", | addCommandHandler("load", | ||
Line 167: | Line 170: | ||
injectBrowserMouseUp(webBrowser, button) | injectBrowserMouseUp(webBrowser, button) | ||
end | end | ||
end | end | ||
) | ) | ||
Line 206: | Line 187: | ||
addEventHandler("onClientRender", root, | addEventHandler("onClientRender", root, | ||
function() | function() | ||
-- Draw the line | -- Draw the line | ||
local x, y = 110.7, 1024.15 | local x, y = 110.7, 1024.15 |
Revision as of 23:06, 12 January 2015
Features
Awesomium API
How to test
Install the latest installer from (run it as admin manually!): https://jusonex.net/public/mta/cef/
If it doesn't work, you'll have to install the x86 VC++ Redist 2013 (http://www.microsoft.com/en-us/download/details.aspx?id=40784).
How you can help
The Awesomium branch needs a lot of testing before it can be merged into the trunk. This is the perfect way to help. Especially the URL and javascript filter must work perfectly, so that you are not able to:
- read any file outside the MTA resorce directory
- load a website that is not explicitly allowed (by the whitelist or an accepted request)
- execute your own javascript code in non-local mode
Local versus non-local mode
Local:
- you can execute your own javascript code using executeBrowserJavascript/Browser.executeJavascript
- you cannot load websites from remote servers
- local mode is recommended for HTML UIs
Non-local:
- you cannot load local websites
- remote websites are filtered
- you cannot your own execute javascript code (javascript code execution on remote websites can also be blocked in the settings)
- non-local mode is recommended (and necessary) for extern websites such as YouTube
Functions
browser createBrowser(int width, int height, bool isLocal [, bool transparent = false] )
- isLocal: Specifies whether to use the browser in local or global mode
- transparent: Should the browser support transparency?
bool requestBrowserPages(table pages)
bool loadBrowserURL(browser webBrowser, string url)
bool isBrowserLoading(browser webBrowser)
string getBrowserTitle(browser webBrowser)
string getBrowserURL(browser webBrowser)
bool injectBrowserMouseMove(browser webBrowser, int x, int y)
bool injectBrowserMouseDown(browser webBrowser, string mouseButton) -- mouseButton: left/middle/right
bool injectBrowserMouseUp(browser webBrowser, string mouseButton) -- mouseButton: left/middle/right
bool injectBrowserMouseWheel(browser webBrowser, int scrollVertical, int scrolLHorizontal)
bool setBrowserRenderingPaused(browser webBrowser, bool isPaused)
bool executeBrowserJavascript(brower webBrowser, string jsCode) -- works only in local mode
bool setBrowserVolume(browser webBrowser, float volume) bool setBrowserVolume(float volume)
bool isBrowserURLBlocked(string url)
bool focusBrowser(browser webBrowser)
Events
onClientBrowserRequestChange Parameters: table allowedRequests
onClientBrowserCursorChange Parameters: int cursor Source: The webbrowser element
Cursor IDs:
Todo
onClientBrowserPopup Parameters: string targetURL, string openerURL, bool isPopup Source: The webbrowser element
onClientBrowserNavigate Parameters: string targetURL, bool isMainFrame Source: The webbrowser element
onClientBrowserLoadingFailed Parameters: string url, int errorCode, string errorDescription Source: The webbrowser element
onClientBrowserDocumentReady Parameters: string url Source: The webbrowser element
Javascript API
Syntax:
[javascript] null mta.triggerEvent(string eventName, ...)
Example: Javascript:
[javascript] mta.triggerEvent("chatOutput", "Hello world!")
Lua:
addEvent("chatOutput") addEventHandler("chatOutput", root, function(text) outputChatBox(text) end )
Examples
Examples on: https://github.com/Jusonex/mtasa_cef_tools
Example 1: A 2D browser with mouse and a simple input handler
local webBrowser = createBrowser(1024, 768, false) requestBrowserPages({"youtube.com"}) focusBrowser(webBrowser) addCommandHandler("load", function() -- Load the url loadBrowserURL(webBrowser, "http://youtube.com") -- This line is potentially needless since YouTube is whitelisted end ) addEventHandler("onClientRender", root, function() -- Draw a nice border dxDrawRectangle(195, 95, 1024+10, 768+10, tocolor(255, 255, 0)) -- Draw the browser dxDrawImage(200, 100, 1024, 768, webBrowser) end ) addEventHandler("onClientCursorMove", root, function(relativeX, relativeY, absoluteX, absoluteY) injectBrowserMouseMove(webBrowser, absoluteX - 200, absoluteY - 100) end ) addEventHandler("onClientClick", root, function(button, state) if state == "down" then injectBrowserMouseDown(webBrowser, button) else injectBrowserMouseUp(webBrowser, button) end end ) showCursor(true)
A 3D browser at the car cinema in Fort Carson (Demo: https://www.youtube.com/watch?v=9w2qU6mZDh8)
local width, height = 1600, 900 -- Create the browser local webBrowser = createBrowser(width, height, false) -- Request the pages requestBrowserPages({"www.youtube.com", "nyan.cat"}) addEventHandler("onClientRender", root, function() -- Draw the line local x, y = 110.7, 1024.15 dxDrawMaterialLine3D(x, y, 23.25, x, y, 14.75, webBrowser, 18.2, tocolor(255, 255, 255, 255), x, y+1, 19) end ) addCommandHandler("youtube", function() outputChatBox("YouTube?") loadBrowserURL(webBrowser, "http://www.youtube.com/watch?v=kdemFfbS5H0") end ) addCommandHandler("nyan", function() outputChatBox("Nyan!") loadBrowserURL(webBrowser, "http://nyan.cat") end )
Notes
- Crosshair position (weapons that use the "normal" crosshair texture "siteM16"): X = screenWidth * 0.5299999714f; Y = screenHeight * 0.4f