Browse Source

Update emscripten shell

Rob Loach 1 year ago
parent
commit
fab887a91c
2 changed files with 45 additions and 79 deletions
  1. 4 2
      examples/CMakeLists.txt
  2. 41 77
      examples/minshell.html

+ 4 - 2
examples/CMakeLists.txt

@@ -92,6 +92,8 @@ if (EMSCRIPTEN)
     # Tell Emscripten to build an example.html file.
     # Tell Emscripten to build an example.html file.
     set_target_properties(raylib-nuklear-demo PROPERTIES SUFFIX ".html")
     set_target_properties(raylib-nuklear-demo PROPERTIES SUFFIX ".html")
     set_target_properties(raylib-nuklear-demo PROPERTIES OUTPUT_NAME "index")
     set_target_properties(raylib-nuklear-demo PROPERTIES OUTPUT_NAME "index")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --shell-file ${CMAKE_CURRENT_SOURCE_DIR}/minshell.html")
-    #add_definitions(-DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-s USE_GLFW=3")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --shell-file ${CMAKE_CURRENT_SOURCE_DIR}/minshell.html")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3")
+    add_definitions(-DPLATFORM=Web)
+    add_definitions(-DCMAKE_BUILD_TYPE=Release)
 endif()
 endif()

+ 41 - 77
examples/minshell.html

@@ -1,85 +1,49 @@
-<!doctype html>
-<html lang="EN-us">
-  <head>
+<!DOCTYPE html>
+<html>
+<head>
     <meta charset="utf-8">
     <meta charset="utf-8">
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-
-    <title>raylib web game</title>
-
-    <meta name="title" content="raylib web game">
-    <meta name="description" content="New raylib web videogame, developed using raylib videogames library">
-    <meta name="keywords" content="raylib, programming, examples, html5, C, C++, library, learn, games, videogames">
-    <meta name="viewport" content="width=device-width">
-
-    <!-- Open Graph metatags for sharing -->
-    <meta property="og:type" content="website" />
-    <meta property="og:title" content="raylib web game">
-    <meta property="og:image:type" content="image/png">
-    <meta property="og:image" content="https://www.raylib.com/common/raylib_logo.png">
-    <meta property="og:image:alt" content="New raylib web videogame, developed using raylib videogames library" />
-    <meta property="og:site_name" content="raylib - example">
-    <meta property="og:url" content="https://www.raylib.com/games.html">
-    <meta property="og:description" content="New raylib web videogame, developed using raylib videogames library">
-
-    <!-- Twitter metatags for sharing -->
-    <meta name="twitter:card" content="summary_large_image">
-    <meta name="twitter:site" content="@raysan5">
-    <meta name="twitter:title" content="raylib web game">
-    <meta name="twitter:image" content="https://www.raylib.com/common/raylib_logo.png">
-    <meta name="twitter:image:alt" content="New raylib web videogame, developed using raylib videogames library">
-    <meta name="twitter:url" content="https://www.raylib.com/games.html">
-    <meta name="twitter:description" content="New raylib web videogame, developed using raylib videogames library">
-
-    <!-- Favicon -->
-    <link rel="shortcut icon" href="https://www.raylib.com/favicon.ico">
-
+    <title>raylib-nuklear: Demo</title>
+    <meta name="description" content="Use Nuklear GUI within raylib: https://github.com/RobLoach/raylib-nuklear">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta name="author" content="Rob Loach">
     <style>
     <style>
-        body { margin: 0px; }
-        canvas.emscripten { border: 0px none; background-color: black; }
+        html, body  {
+            margin: 0;
+            height: 100vh;
+            max-width: 100vw;
+        }
+        body {
+            display: flex;
+            align-items: center;
+            justify-content: center;
+            flex-direction: column;
+            color: white;
+            background: black;
+        }
+        #console {
+            overflow: auto;
+        }
     </style>
     </style>
-    <script type='text/javascript' src="https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js"> </script>
-    <script type='text/javascript'>
-        function saveFileFromMEMFSToDisk(memoryFSname, localFSname)     // This can be called by C/C++ code
-        {
-            var isSafari = false; // Not supported, navigator.userAgent access is being restricted
-            //var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
-            var data = FS.readFile(memoryFSname);
-            var blob;
-
-            if (isSafari) blob = new Blob([data.buffer], { type: "application/octet-stream" });
-            else blob = new Blob([data.buffer], { type: "application/octet-binary" });
+</head>
 
 
-            // NOTE: SaveAsDialog is a browser setting. For example, in Google Chrome,
-            // in Settings/Advanced/Downloads section you have a setting:
-            // 'Ask where to save each file before downloading' - which you can set true/false.
-            // If you enable this setting it would always ask you and bring the SaveAsDialog
-            saveAs(blob, localFSname);
+<body>
+    <canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
+    <!-- <pre id="console"></pre> -->
+    <script type='text/javascript'>
+        window.Module = {
+            canvas: document.getElementById('canvas'),
+            print: (...args) => {
+                const consoleElement = document.getElementById('console')
+                const text = args.join(' ')
+                console.log(text);
+                if (consoleElement) {
+                  consoleElement.innerText += text + "\n"
+                  consoleElement.scrollTop = consoleElement.scrollHeight
+                }
+            }
         }
         }
     </script>
     </script>
-    </head>
-    <body>
-        <canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>
-        <p id="output" />
-        <script>
-            var Module = {
-                print: (function() {
-                    var element = document.getElementById('output');
-                    if (element) element.value = ''; // clear browser cache
-                    return function(text) {
-                        if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
-                        console.log(text);
-                        if (element) {
-                          element.value += text + "\n";
-                          element.scrollTop = element.scrollHeight; // focus on bottom
-                        }
-                    };
-                })(),
-                canvas: (function() {
-                    var canvas = document.getElementById('canvas');
-                    return canvas;
-                })()
-            };
-        </script>
-        {{{ SCRIPT }}}
-    </body>
+   {{{ SCRIPT }}}
+</body>
 </html>
 </html>