Skip to content

Commit b1874e1

Browse files
committed
Browser functions
1 parent 397f618 commit b1874e1

File tree

90 files changed

+1796
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1796
-90
lines changed

elements/Browser/browser.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: browser
2+
description: |
3+
A **browser** is an element representing a CEF browser instance, created with [createBrowser](/reference/createBrowser/) or [guiCreateBrowser](/reference/guiCreateBrowser/). This element also simultaneously represents the browser’s [texture](/reference/texture/), so it can be used as a texture, e.g. for rendering with [dxDrawImage](/reference/dxDrawImage/).
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/canBrowserNavigateBack
21
client:
32
name: canBrowserNavigateBack
4-
description: TODO
5-
incomplete: true
3+
description: This function checks if the [[browser]] can return to the previous page.
4+
oop:
5+
element: browser
6+
method: canNavigateBack
7+
parameters:
8+
- name: webBrowser
9+
type: browser
10+
description: The [[browser]] you want to check for a previous page.
11+
returns:
12+
values:
13+
- type: bool
14+
name: result
15+
description: Returns true if the browser can navigate back, false otherwise.
16+
examples:
17+
- path: examples/canBrowserNavigateBack-1.lua
18+
description: This example creates a browser that can return to the last and previous pages and can also be refreshed.
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/canBrowserNavigateForward
21
client:
32
name: canBrowserNavigateForward
4-
description: TODO
5-
incomplete: true
3+
description: This function checks if the [[browser]] can go to the next page.
4+
oop:
5+
element: browser
6+
method: canNavigateForward
7+
parameters:
8+
- name: webBrowser
9+
type: browser
10+
description: The [[browser]] you want check for a next page.
11+
returns:
12+
values:
13+
- type: bool
14+
name: result
15+
description: Returns true if the browser can go to the next page, false otherwise.
16+
examples:
17+
- path: examples/canBrowserNavigateForward-1.lua
18+
description: This example creates a browser that can return to the last and previous pages and can also be refreshed.

functions/Browser/createBrowser.yaml

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/createBrowser
21
client:
32
name: createBrowser
4-
description: TODO
5-
incomplete: true
3+
description: This function creates a new web [[browser]] element.
4+
notes:
5+
- type: tip
6+
content: You can also enable CEF development tools using [[toggleBrowserDevTools]].
7+
- type: info
8+
content: For local files as url please read [Local Scheme Handler](/reference/Local_Scheme_Handler/).
9+
oop:
10+
element: browser
11+
constructorclass: browser
12+
parameters:
13+
- name: width
14+
type: int
15+
description: The browser's native width. This should be greater than or equal to 1.
16+
- name: height
17+
type: int
18+
description: The browser's native height. This should be greater than or equal to 1.
19+
- name: isLocal
20+
type: bool
21+
description: Sets whether the browser can only show local content or content from the internet (see examples for more information).
22+
- name: transparent
23+
type: bool
24+
description: true if you want the browser transparent, false for opaque.
25+
default: 'false'
26+
returns:
27+
values:
28+
- type: element|false
29+
name: new browser
30+
description: Returns a [[texture]] of the [[browser]] if it was created successfully, false otherwise. Returns also false, if the user disabled remote pages and isLocal was set to false.
31+
examples:
32+
- path: examples/createBrowser-1.lua
33+
description: This example shows you how to create a fullscreen web browser (showing a local html file) without input-handling.
34+
- path: examples/createBrowser_OOP-1.lua
35+
description: This example shows you how to create a fullscreen web browser (showing a local html file) without input-handling.
36+
oop: true
37+
- path: examples/createBrowser-2.lua
38+
description: |
39+
This example shows you how to create a fullscreen web browser (showing youtube.com) without input-handling.
40+
Remember, that youtube.com is on the global whitelist. If you want to load a domain/page that is not on the global whitelist, you have to request it with [[requestBrowserDomains]].
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
local window = guiCreateWindow(126, 122, 848, 674, "Firechrome", false)
2+
guiWindowSetSizable(window, false)
3+
4+
local navigateBackBtn = guiCreateButton(10, 19, 39, 36, "<", false, window)
5+
local navigateForwardBtn = guiCreateButton(98, 19, 39, 36, ">", false, window)
6+
local addressBar = guiCreateEdit(137, 19, 701, 36, "", false, window)
7+
guiSetEnabled( addressBar, false )
8+
local reloadBtn = guiCreateButton(49, 19, 49, 36, "reload", false, window)
9+
local browser = guiCreateBrowser(10, 55, 828, 609, false, false, false, window)
10+
11+
-- Load our page on browser creation.
12+
local theBrowser = guiGetBrowser(browser)
13+
addEventHandler("onClientBrowserCreated", theBrowser,
14+
function()
15+
loadBrowserURL(source, "https://forum.mtasa.com/")
16+
end
17+
)
18+
19+
-- This checks to see if the browser can navigate in any direction and enables the back or forward buttons
20+
addEventHandler( "onClientBrowserDocumentReady", theBrowser, function( )
21+
guiSetEnabled(navigateForwardBtn, canBrowserNavigateForward(theBrowser))
22+
guiSetEnabled(navigateBackBtn, canBrowserNavigateBack(theBrowser))
23+
guiSetText( addressBar, getBrowserURL( theBrowser ) )
24+
end )
25+
26+
-- This part handles the GUI navigation buttons for the browser.
27+
addEventHandler( "onClientGUIClick", resourceRoot, function ( )
28+
if source == navigateBackBtn then
29+
navigateBrowserBack(theBrowser)
30+
elseif source == navigateForwardBtn then
31+
navigateBrowserForward(theBrowser)
32+
elseif source == reloadBtn then
33+
reloadBrowserPage(theBrowser)
34+
end
35+
end )
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local window = guiCreateWindow(126, 122, 848, 674, "browser", false)
2+
guiWindowSetSizable(window, false)
3+
local navigateBackBtn = guiCreateButton(10, 19, 39, 36, "<", false, window)
4+
local navigateForwardBtn = guiCreateButton(98, 19, 39, 36, ">", false, window)
5+
local reloadBtn = guiCreateButton(49, 19, 49, 36, "reload", false, window)
6+
local addressBar = guiCreateEdit(137, 19, 701, 36, "", false, window)
7+
guiSetEnabled(addressBar,false)
8+
local webBrowser = guiCreateBrowser(10, 55, 828, 609, false, false, false, window)
9+
local theBrowser = guiGetBrowser(webBrowser)
10+
11+
-- Load our page on browser creation.
12+
addEventHandler("onClientBrowserCreated", theBrowser,
13+
function()
14+
showCursor(true)
15+
loadBrowserURL(source, "https://forum.mtasa.com/")
16+
end
17+
)
18+
19+
addEventHandler( "onClientBrowserDocumentReady", theBrowser, function( url )
20+
guiSetText( addressBar, getBrowserURL( theBrowser ) )
21+
end )
22+
23+
-- This part handles the GUI navigation buttons for the browser.
24+
addEventHandler( "onClientGUIClick", resourceRoot, function ( )
25+
if source == navigateBackBtn then
26+
if (not canBrowserNavigateBack(theBrowser)) then return end -- This checks to see if the browser can navigate to the back
27+
navigateBrowserBack(theBrowser)
28+
elseif source == navigateForwardBtn then -- This checks to see if the browser can navigate to the forward
29+
if (not canBrowserNavigateForward(theBrowser)) then return end
30+
navigateBrowserForward(theBrowser)
31+
elseif source == reloadBtn then
32+
reloadBrowserPage(theBrowser)
33+
end
34+
end )
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--In order to render the browser on the full screen, we need to know the dimensions.
2+
local screenWidth, screenHeight = guiGetScreenSize()
3+
4+
--Let's create a new browser in local mode. We will not be able to load an external URL.
5+
local webBrowser = createBrowser(screenWidth, screenHeight, true, false)
6+
7+
--This is the function to render the browser.
8+
function webBrowserRender()
9+
--Render the browser on the full size of the screen.
10+
dxDrawImage(0, 0, screenWidth, screenHeight, webBrowser, 0, 0, 0, tocolor(255,255,255,255), true)
11+
end
12+
13+
--The event onClientBrowserCreated will be triggered, after the browser has been initialized.
14+
--After this event has been triggered, we will be able to load our URL and start drawing.
15+
addEventHandler("onClientBrowserCreated", webBrowser,
16+
function()
17+
--After the browser has been initialized, we can load our file.
18+
loadBrowserURL(webBrowser, "http://mta/local/html/site.html")
19+
--Now we can start to render the browser.
20+
addEventHandler("onClientRender", root, webBrowserRender)
21+
end
22+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--In order to render the browser on the full screen, we need to know the dimensions.
2+
local screenWidth, screenHeight = guiGetScreenSize()
3+
4+
--Let's create a new browser in remote mode.
5+
local webBrowser = createBrowser(screenWidth, screenHeight, false, false)
6+
7+
--Function to render the browser.
8+
function webBrowserRender()
9+
--Render the browser on the full size of the screen.
10+
dxDrawImage(0, 0, screenWidth, screenHeight, webBrowser, 0, 0, 0, tocolor(255,255,255,255), true)
11+
end
12+
13+
--The event onClientBrowserCreated will be triggered, after the browser has been initialized.
14+
--After this event has been triggered, we will be able to load our URL and start drawing.
15+
addEventHandler("onClientBrowserCreated", webBrowser,
16+
function()
17+
--After the browser has been initialized, we can load www.youtube.com
18+
loadBrowserURL(webBrowser, "http://www.youtube.com")
19+
--Now we can start to render the browser.
20+
addEventHandler("onClientRender", root, webBrowserRender)
21+
end
22+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--In order to render the browser on the full screen, we need to know the dimensions.
2+
local screenWidth, screenHeight = GuiElement.getScreenSize()
3+
4+
--Let's create a new browser in local mode. We will not be able to load an external URL.
5+
local webBrowser = Browser(screenWidth, screenHeight, true, false)
6+
7+
--This is the function to render the browser.
8+
function webBrowserRender()
9+
--Render the browser on the full size of the screen.
10+
dxDrawImage(0, 0, screenWidth, screenHeight, webBrowser, 0, 0, 0, tocolor(255,255,255,255), true)
11+
end
12+
13+
--The event onClientBrowserCreated will be triggered, after the browser has been initialized.
14+
--After this event has been triggered, we will be able to load our URL and start drawing.
15+
addEventHandler("onClientBrowserCreated", webBrowser,
16+
function()
17+
--After the browser has been initialized, we can load our file.
18+
webBrowser.url = "http://mta/local/html/site.html"
19+
--Now we can start to render the browser.
20+
addEventHandler("onClientRender", root, webBrowserRender)
21+
end
22+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
local browser = guiGetBrowser(guiCreateBrowser(200, 200, 400, 200, true, false, false))
2+
3+
addEventHandler("onClientBrowserCreated", browser,
4+
function ()
5+
loadBrowserURL(source, "http://mta/local/example.html") --Containing <span id="nick"></span> somewhere in the file
6+
end)
7+
8+
--The page has to load first
9+
addEventHandler("onClientBrowserDocumentReady", browser,
10+
function ()
11+
executeBrowserJavascript(source, string.format("document.getElementById('nick').innerText = %q;", getPlayerName(localPlayer)))
12+
end)

0 commit comments

Comments
 (0)