├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── cpplibs ├── include │ ├── JavaScriptCore │ │ ├── JSBase.h │ │ ├── JSContextRef.h │ │ ├── JSObjectRef.h │ │ ├── JSObjectRefPrivate.h │ │ ├── JSRetainPtr.h │ │ ├── JSStringRef.h │ │ ├── JSTypedArray.h │ │ ├── JSValueRef.h │ │ ├── JavaScript.h │ │ └── WebKitAvailability.h │ └── Ultralight │ │ ├── Bitmap.h │ │ ├── Buffer.h │ │ ├── CAPI.h │ │ ├── Defines.h │ │ ├── Geometry.h │ │ ├── KeyCodes.h │ │ ├── KeyEvent.h │ │ ├── Listener.h │ │ ├── Matrix.h │ │ ├── MouseEvent.h │ │ ├── RefPtr.h │ │ ├── RenderTarget.h │ │ ├── Renderer.h │ │ ├── ScrollEvent.h │ │ ├── String.h │ │ ├── String16.h │ │ ├── String32.h │ │ ├── String8.h │ │ ├── Ultralight.h │ │ ├── View.h │ │ └── platform │ │ ├── Config.h │ │ ├── FileSystem.h │ │ ├── FontLoader.h │ │ ├── GPUDriver.h │ │ └── Platform.h ├── linux │ ├── libUltralight.so │ ├── libUltralightCore.so │ └── libWebCore.so ├── mac │ ├── libUltralight.dylib │ ├── libUltralightCore.dylib │ └── libWebCore.dylib └── win │ ├── Ultralight.dll │ ├── Ultralight.lib │ ├── UltralightCore.dll │ ├── UltralightCore.lib │ ├── WebCore.dll │ └── WebCore.lib ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── cpp │ ├── FileSystemBasic.cpp │ ├── FileSystemBasic.h │ ├── cafe_qwq_webcraft_api_View.cpp │ ├── cafe_qwq_webcraft_api_WebRenderer.cpp │ ├── cafe_qwq_webcraft_client_ClientEventListener.cpp │ ├── gl │ │ ├── GPUDriverGL.cpp │ │ └── GPUDriverGL.h │ ├── glad │ │ ├── glad.c │ │ ├── glad.h │ │ └── khrplatform.h │ └── shaders │ │ └── glsl │ │ ├── shader_fill_frag.h │ │ ├── shader_fill_path_frag.h │ │ ├── shader_v2f_c4f_t2f_t2f_d28f_vert.h │ │ └── shader_v2f_c4f_t2f_vert.h ├── java │ └── cafe │ │ └── qwq │ │ └── webcraft │ │ ├── Config.java │ │ ├── WebCraft.java │ │ ├── api │ │ ├── IRenderer.java │ │ ├── View.java │ │ ├── WebRenderer.java │ │ ├── WebScreen.java │ │ └── math │ │ │ ├── Vec2i.java │ │ │ └── Vec4i.java │ │ ├── client │ │ ├── ClientEventListener.java │ │ ├── KeyboardHelper.java │ │ └── UltralightWindow.java │ │ └── util │ │ └── FileUtils.java └── resources │ ├── META-INF │ └── mods.toml │ ├── assets │ └── webcraft │ │ └── web │ │ ├── button │ │ ├── button.png │ │ ├── button_disabled.png │ │ └── button_hover.png │ │ ├── fzxs12.ttf │ │ ├── minecraft.css │ │ └── minecraft.ttf │ ├── pack.mcmeta │ └── webcraft_logo.png └── test ├── java └── cafe │ └── qwq │ └── webcraft │ └── demo │ └── Demo.java └── resources ├── META-INF └── mods.toml ├── assets └── demo │ └── web │ └── test.html └── pack.mcmeta /.gitignore: -------------------------------------------------------------------------------- 1 | # eclipse 2 | /bin 3 | *.launch 4 | .settings 5 | .metadata 6 | .classpath 7 | .project 8 | 9 | # idea 10 | out 11 | *.ipr 12 | *.iws 13 | *.iml 14 | .idea 15 | 16 | # gradle 17 | build 18 | .gradle 19 | 20 | # other 21 | eclipse 22 | run 23 | 24 | # Files from Forge MDK 25 | forge*changelog.txt 26 | 27 | # vscode 28 | .vscode -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebCraft 2 | 3 | ![](https://i.loli.net/2020/04/11/j5YimS2nNXUbQpJ.png) 4 | 5 | WebCraft is a open-source GUI library based on Minecraft Forge for createing GUIs with HTML, CSS and JavaScript. 6 | 7 | (It is still under development and only supports for Minecraft 1.15.2) 8 | 9 | WebCraft accomplishes the GUI-rendering system by [Ultralight](https://ultralig.ht) as Web engine. 10 | 11 | Please obey WebCraft Open-Source License (LGPL) and the licenses of Ultralight. 12 | 13 | The operating system we support: Windows & Linux (We only have tested on Ubuntu, Manjaro and ArchLinux so we don't know whether it can work on other distros or not. If you have tested on others, please let us know) 14 | 15 | About the support for Mac OS: We have tried our best to offer support for Mac. However ,we gave up for the reason that we have no Mac OSX device. If you can provide support for Mac, we would appreciate for your sending a pull request. 16 | 17 | API docs are editing...... 18 | 19 | ## TODO List 20 | 21 | Full version(v1.0): 22 | 23 | * Use with Inventories/Slots/TileEntities. 24 | * API doc with details. 25 | 26 | Plans in the future: 27 | 28 | * Provide some APIs for bukkit plugins. 29 | * Use Fabric instead of Forge 30 | * Develop a version that supports Minecraft 1.12.2. 31 | * Separate our mod from Mod Loaders and make it be an independent mod. 32 | 33 | ## How to install WebCraft? 34 | 35 | You can download it from this [link](https://github.com/Hookan/hookan.github.io/tree/master/cafe/qwq/webcraft). 36 | 37 | Then put it into the `mods` folder.(needs to install Forge) 38 | 39 | And you should install [VC redist](https://aka.ms/vs/16/release/vc_redist.x64.exe) if you are using Windows. 40 | 41 | When the first time you run this mod, it will download natives jar. It may be VERY slow because we only use one thread to download. So, you can download it by yourself and unzip it in the folder `natives-` . 42 | 43 | ## Get Started with WebCraft 44 | 45 | Tips: All the `` needs to be replaced with the version of WebCraft you use. (For example, you may substitute the version 0.4.2 for the `webcraft:` and the version in gradle.build would look like `webcraft:0.4.2` ) 46 | 47 | Firstly, download Forge MDK and set `mappings` to `mappings channel: 'snapshot', version: '20200306-1.15.1'` in `build.gradle` (you can skip this step if you still want to apply your appropriate `mappings`) 48 | 49 | Secondly, add these codes to `build.gradle` (NOT IN `buildscript`!!). 50 | 51 | ```groovy 52 | repositories { 53 | maven { url 'https://maven.qwq.cafe' } // or https://ci.qwq.cafe/maven 54 | } 55 | ``` 56 | 57 | Thirdly, add `implementation 'cafe.qwq:webcraft::dev'` or `implementation fg.deobf('cafe.qwq:webcraft:runtime')`(which can help you change mapping freely) to `dependencies`. 58 | 59 | This is an example for a completly available`build.gradle`. (Modified by mdk's default build.gradle) 60 | 61 | ```groovy 62 | buildscript { 63 | repositories { 64 | maven { url = 'https://files.minecraftforge.net/maven' } 65 | jcenter() 66 | mavenCentral() 67 | } 68 | dependencies { 69 | classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true 70 | } 71 | } 72 | apply plugin: 'net.minecraftforge.gradle' 73 | // Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. 74 | apply plugin: 'eclipse' 75 | apply plugin: 'maven-publish' 76 | 77 | version = '1.0' 78 | group = 'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html 79 | archivesBaseName = 'modid' 80 | 81 | sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. 82 | 83 | minecraft { 84 | mappings channel: 'snapshot', version: '20200306-1.15.1' 85 | runs { 86 | client { 87 | workingDirectory project.file('run') 88 | 89 | // Recommended logging data for a userdev environment 90 | property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' 91 | 92 | // Recommended logging level for the console 93 | property 'forge.logging.console.level', 'debug' 94 | 95 | mods { 96 | examplemod { 97 | source sourceSets.main 98 | } 99 | } 100 | } 101 | 102 | server { 103 | workingDirectory project.file('run') 104 | 105 | // Recommended logging data for a userdev environment 106 | property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' 107 | 108 | // Recommended logging level for the console 109 | property 'forge.logging.console.level', 'debug' 110 | 111 | mods { 112 | examplemod { 113 | source sourceSets.main 114 | } 115 | } 116 | } 117 | 118 | data { 119 | workingDirectory project.file('run') 120 | 121 | // Recommended logging data for a userdev environment 122 | property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' 123 | 124 | // Recommended logging level for the console 125 | property 'forge.logging.console.level', 'debug' 126 | 127 | args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/') 128 | 129 | mods { 130 | examplemod { 131 | source sourceSets.main 132 | } 133 | } 134 | } 135 | } 136 | } 137 | 138 | repositories { 139 | maven { url 'https://maven.qwq.cafe' } 140 | } 141 | 142 | dependencies { 143 | minecraft 'net.minecraftforge:forge:1.15.2-31.1.0' 144 | implementation 'cafe.qwq:webcraft::dev' 145 | //or implementation fg.deobf('cafe.qwq:webcraft::runtime') 146 | } 147 | 148 | jar { 149 | manifest { 150 | attributes([ 151 | "Specification-Title": "examplemod", 152 | "Specification-Vendor": "examplemodsareus", 153 | "Specification-Version": "1", // We are version 1 of ourselves 154 | "Implementation-Title": project.name, 155 | "Implementation-Version": "${version}", 156 | "Implementation-Vendor" :"examplemodsareus", 157 | "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") 158 | ]) 159 | } 160 | } 161 | 162 | def reobfFile = file("$buildDir/reobfJar/output.jar") 163 | def reobfArtifact = artifacts.add('default', reobfFile) { 164 | type 'jar' 165 | builtBy 'reobfJar' 166 | } 167 | publishing { 168 | publications { 169 | mavenJava(MavenPublication) { 170 | artifact reobfArtifact 171 | } 172 | } 173 | repositories { 174 | maven { 175 | url "file:///${project.projectDir}/mcmodsrepo" 176 | } 177 | } 178 | } 179 | 180 | ``` 181 | 182 | Then add these codes to `mods.toml`: 183 | 184 | ```toml 185 | [[dependencies.modid]] # Please change it to your modid. 186 | modId="webcraft" 187 | mandatory=true 188 | versionRange="[]" 189 | ordering="NONE" 190 | side="BOTH" # We will provide some APIs for server in the future. 191 | ``` 192 | 193 | Finally you can use WebCraft API in your mod. 194 | 195 | ```java 196 | WebScreen screen = new WebScreen(new StringTextComponent("MyGui")); 197 | Minecraft.getInstance() 198 | .displayScreen(screen.addView(new View().loadHTML("

Hello,World!

"))); 199 | ``` 200 | 201 | ## How to build development environment for WebCraft 202 | 203 | * Linux 204 | 205 | Firstly, you should install GCC and make sure you can use the command `g++` 206 | 207 | For Debian/Ubuntu: 208 | 209 | ```sh 210 | sudo apt update 211 | sudo apt install gcc 212 | sudo apt install g++ 213 | ``` 214 | 215 | For ArchLinux/Manjaro: 216 | 217 | ```sh 218 | sudo pacman -Syy 219 | sudo pacman -S gcc 220 | ``` 221 | 222 | For CentOS/Fedora: 223 | 224 | ```sh 225 | sudo dnf update 226 | sudo dnf install gcc 227 | sudo dnf install gcc-c++ 228 | ``` 229 | 230 | Then import this project into your IDE. 231 | 232 | * Windows 233 | 234 | Install the BuildTool of VisualStudio at first. (You only need to install VC++) 235 | 236 | Then you need to find the path you install in and configure the environment variables. If you configure it successfully, you should be able to use the command `cl` in the command line. 237 | 238 | At last you should import this project into your IDE. -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven { url = 'https://files.minecraftforge.net/maven' } 4 | jcenter() 5 | mavenCentral() 6 | } 7 | dependencies { 8 | classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true 9 | } 10 | } 11 | apply plugin: 'net.minecraftforge.gradle' 12 | apply plugin: 'eclipse' 13 | apply plugin: 'maven-publish' 14 | apply plugin: 'cpp' 15 | 16 | version = '0.4.2' 17 | group = 'cafe.qwq' 18 | archivesBaseName = 'webcraft' 19 | 20 | [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8' 21 | 22 | 23 | sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' 24 | 25 | minecraft { 26 | mappings channel: 'snapshot', version: '20200306-1.15.1' 27 | 28 | runs { 29 | client { 30 | workingDirectory project.file('run') 31 | property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' 32 | property 'forge.logging.console.level', 'debug' 33 | property 'cafe.qwq.webcraft.nativesPath', "${buildDir}/libs/webcraft_core/shared/" 34 | mods { 35 | webcraft { 36 | source sourceSets.main 37 | } 38 | webcraftdemo { 39 | source sourceSets.test 40 | } 41 | } 42 | } 43 | 44 | server { 45 | workingDirectory project.file('run') 46 | property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' 47 | property 'forge.logging.console.level', 'debug' 48 | mods { 49 | webcraft { 50 | source sourceSets.main 51 | } 52 | webcraftdemo { 53 | source sourceSets.test 54 | } 55 | } 56 | } 57 | } 58 | } 59 | 60 | model { 61 | platforms { 62 | x64 { 63 | architecture 'x64' 64 | } 65 | } 66 | 67 | components { 68 | webcraft_core(NativeLibrarySpec) { 69 | targetPlatform "x64" 70 | binaries.all { 71 | if (targetPlatform.operatingSystem.macOsX) { 72 | cppCompiler.args '-O2' 73 | cppCompiler.args '-std=c++11' 74 | cppCompiler.args '-I', "${project.projectDir}/cpplibs/include" 75 | cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include" 76 | cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/darwin" 77 | linker.args '-Wl,-rpath,@loader_path' 78 | linker.args "-L${project.projectDir}/cpplibs/mac" 79 | linker.args '-lWebCore' 80 | linker.args '-lUltralightCore' 81 | linker.args '-lUltralight' 82 | } else if (targetPlatform.operatingSystem.linux) { 83 | cppCompiler.args '-O2' 84 | cppCompiler.args '-std=c++11' 85 | cppCompiler.args '-I', "${project.projectDir}/cpplibs/include" 86 | cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include" 87 | cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux" 88 | cppCompiler.args '-D_FILE_OFFSET_BITS=64' 89 | linker.args '-Wl,-rpath=$ORIGIN' 90 | linker.args "-L${project.projectDir}/cpplibs/linux" 91 | linker.args '-lWebCore' 92 | linker.args '-lUltralightCore' 93 | linker.args '-lUltralight' 94 | } else if (targetPlatform.operatingSystem.windows) {//Use MSVC to compile 95 | cppCompiler.args '/O2' 96 | cppCompiler.args '/LD', '/MD' 97 | cppCompiler.args '/std:c++14' 98 | cppCompiler.args "/I${project.projectDir}/cpplibs/include" 99 | cppCompiler.args "/I${org.gradle.internal.jvm.Jvm.current().javaHome}/include" 100 | cppCompiler.args "/I${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32" 101 | cppCompiler.args '/EHsc', '/GS-', '/fp:fast' 102 | linker.args '/MANIFEST', '/MACHINE:x64' 103 | linker.args '/DYNAMICBASE' 104 | linker.args "${project.projectDir}/cpplibs/win/Ultralight.lib" 105 | linker.args "${project.projectDir}/cpplibs/win/UltralightCore.lib" 106 | linker.args "${project.projectDir}/cpplibs/win/WebCore.lib" 107 | } 108 | } 109 | 110 | sources { 111 | cpp { 112 | source { 113 | srcDirs "src/main/cpp" 114 | include "**/*.cpp" , "**/*.h" , "**/*.c" 115 | } 116 | } 117 | } 118 | } 119 | } 120 | } 121 | 122 | dependencies { 123 | minecraft 'net.minecraftforge:forge:1.15.2-31.1.0' 124 | } 125 | 126 | task sourcesJar(type: Jar) { 127 | classifier 'sources' 128 | from sourceSets.main.allSource 129 | } 130 | 131 | task nativesJar(type: Jar, dependsOn: 'compileJava') { 132 | if(System.getProperty("os.name").toLowerCase().contains('linux')) { 133 | classifier = 'natives-linux' 134 | from "${buildDir}/libs/webcraft_core/shared" 135 | } else if(System.getProperty("os.name").toLowerCase().contains("win")) { 136 | classifier = 'natives-win' 137 | from("${buildDir}/libs/webcraft_core/shared") { 138 | include '*.dll' 139 | } 140 | } else { 141 | classifier = 'natives-mac' 142 | from "${buildDir}/libs/webcraft_core/shared" 143 | } 144 | } 145 | 146 | def reobfFile = file("${buildDir}/reobfJar/output.jar") 147 | def reobfArtifact = artifacts.add('default', reobfFile) { 148 | type 'jar' 149 | builtBy 'reobfJar' 150 | classifier 'runtime' 151 | } 152 | 153 | task devJar(type: Jar, dependsOn: 'classes') { 154 | from "${buildDir}/classes/java/main/" 155 | from "${buildDir}/resources/main" 156 | classifier 'dev' 157 | manifest { 158 | attributes([ 159 | "Specification-Title": 'webcraft', 160 | "Specification-Vendor": 'bogos', 161 | "Specification-Version": '1', 162 | "Implementation-Title": project.name, 163 | "Implementation-Version": "${version}", 164 | "Implementation-Vendor" :'bogos', 165 | "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") 166 | ]) 167 | } 168 | } 169 | 170 | task javadocJar(type: Jar, dependsOn: 'javadoc') { 171 | from "${buildDir}/docs/javadoc" 172 | classifier 'javadoc' 173 | } 174 | 175 | task demoJar(type: Jar, dependsOn: 'test') { 176 | from "${buildDir}/classes/java/test/" 177 | from "${buildDir}/resources/test" 178 | classifier 'demo' 179 | manifest { 180 | attributes([ 181 | "Specification-Title": 'demo', 182 | "Specification-Vendor": 'bogos', 183 | "Specification-Version": '1', 184 | "Implementation-Title": project.name, 185 | "Implementation-Version": "${version}", 186 | "Implementation-Vendor" :'bogos', 187 | "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") 188 | ]) 189 | } 190 | } 191 | 192 | publishing { 193 | publications { 194 | mavenJava(MavenPublication) { 195 | artifact devJar 196 | artifact sourcesJar 197 | artifact nativesJar 198 | artifact reobfArtifact 199 | artifact javadocJar 200 | artifact demoJar 201 | } 202 | } 203 | repositories { 204 | maven { 205 | url 'file:///' + System.getenv('NATIVE_MAVEN_PATH') 206 | } 207 | } 208 | } 209 | 210 | jar { 211 | manifest { 212 | attributes([ 213 | "Specification-Title": 'webcraft', 214 | "Specification-Vendor": 'bogos', 215 | "Specification-Version": '1', 216 | "Implementation-Title": project.name, 217 | "Implementation-Version": "${version}", 218 | "Implementation-Vendor" :'bogos', 219 | "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") 220 | ]) 221 | } 222 | } 223 | 224 | compileJava.dependsOn('webcraft_coreSharedLibrary') 225 | 226 | compileJava << { 227 | copy { 228 | if(System.getProperty("os.name").toLowerCase().contains('linux')) { 229 | from "${project.projectDir}/cpplibs/linux" 230 | } 231 | else if(System.getProperty("os.name").toLowerCase().contains("win")) { 232 | from("${project.projectDir}/cpplibs/win") { 233 | exclude '*.lib' 234 | } 235 | } 236 | else { 237 | from "${project.projectDir}/cpplibs/mac" 238 | } 239 | into "${buildDir}/libs/webcraft_core/shared" 240 | } 241 | } -------------------------------------------------------------------------------- /cpplibs/include/JavaScriptCore/JSBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSBase_h 27 | #define JSBase_h 28 | 29 | #ifndef __cplusplus 30 | #include 31 | #endif 32 | 33 | #ifdef __OBJC__ 34 | #import 35 | #endif 36 | 37 | /* JavaScript engine interface */ 38 | 39 | /*! @typedef JSContextGroupRef A group that associates JavaScript contexts with one another. Contexts in the same group may share and exchange JavaScript objects. */ 40 | typedef const struct OpaqueJSContextGroup* JSContextGroupRef; 41 | 42 | /*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */ 43 | typedef const struct OpaqueJSContext* JSContextRef; 44 | 45 | /*! @typedef JSGlobalContextRef A global JavaScript execution context. A JSGlobalContext is a JSContext. */ 46 | typedef struct OpaqueJSContext* JSGlobalContextRef; 47 | 48 | /*! @typedef JSStringRef A UTF16 character buffer. The fundamental string representation in JavaScript. */ 49 | typedef struct OpaqueJSString* JSStringRef; 50 | 51 | /*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */ 52 | typedef struct OpaqueJSClass* JSClassRef; 53 | 54 | /*! @typedef JSPropertyNameArrayRef An array of JavaScript property names. */ 55 | typedef struct OpaqueJSPropertyNameArray* JSPropertyNameArrayRef; 56 | 57 | /*! @typedef JSPropertyNameAccumulatorRef An ordered set used to collect the names of a JavaScript object's properties. */ 58 | typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef; 59 | 60 | /*! @typedef JSTypedArrayBytesDeallocator A function used to deallocate bytes passed to a Typed Array constructor. The function should take two arguments. The first is a pointer to the bytes that were originally passed to the Typed Array constructor. The second is a pointer to additional information desired at the time the bytes are to be freed. */ 61 | typedef void (*JSTypedArrayBytesDeallocator)(void* bytes, void* deallocatorContext); 62 | 63 | /* JavaScript data types */ 64 | 65 | /*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */ 66 | typedef const struct OpaqueJSValue* JSValueRef; 67 | 68 | /*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */ 69 | typedef struct OpaqueJSValue* JSObjectRef; 70 | 71 | /* JavaScript symbol exports */ 72 | /* These rules should stay the same as in WebKit2/Shared/API/c/WKBase.h */ 73 | 74 | #undef JS_EXPORT 75 | #if defined(JS_NO_EXPORT) 76 | #define JS_EXPORT 77 | #elif defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC__) 78 | #define JS_EXPORT __attribute__((visibility("default"))) 79 | #elif defined(WIN32) || defined(_WIN32) || defined(_WIN32_WCE) || defined(__CC_ARM) || defined(__ARMCC__) 80 | #if defined(BUILDING_JavaScriptCore) || defined(STATICALLY_LINKED_WITH_JavaScriptCore) 81 | #define JS_EXPORT __declspec(dllexport) 82 | #else 83 | #define JS_EXPORT __declspec(dllimport) 84 | #endif 85 | #else /* !defined(JS_NO_EXPORT) */ 86 | #define JS_EXPORT 87 | #endif /* defined(JS_NO_EXPORT) */ 88 | 89 | #ifdef __cplusplus 90 | extern "C" { 91 | #endif 92 | 93 | /* Script Evaluation */ 94 | 95 | /*! 96 | @function JSEvaluateScript 97 | @abstract Evaluates a string of JavaScript. 98 | @param ctx The execution context to use. 99 | @param script A JSString containing the script to evaluate. 100 | @param thisObject The object to use as "this," or NULL to use the global object as "this." 101 | @param sourceURL A JSString containing a URL for the script's source file. This is used by debuggers and when reporting exceptions. Pass NULL if you do not care to include source file information. 102 | @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1. 103 | @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 104 | @result The JSValue that results from evaluating script, or NULL if an exception is thrown. 105 | */ 106 | JS_EXPORT JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); 107 | 108 | /*! 109 | @function JSCheckScriptSyntax 110 | @abstract Checks for syntax errors in a string of JavaScript. 111 | @param ctx The execution context to use. 112 | @param script A JSString containing the script to check for syntax errors. 113 | @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. 114 | @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1. 115 | @param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception. 116 | @result true if the script is syntactically correct, otherwise false. 117 | */ 118 | JS_EXPORT bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); 119 | 120 | /*! 121 | @function JSGarbageCollect 122 | @abstract Performs a JavaScript garbage collection. 123 | @param ctx The execution context to use. 124 | @discussion JavaScript values that are on the machine stack, in a register, 125 | protected by JSValueProtect, set as the global object of an execution context, 126 | or reachable from any such value will not be collected. 127 | 128 | During JavaScript execution, you are not required to call this function; the 129 | JavaScript engine will garbage collect as needed. JavaScript values created 130 | within a context group are automatically destroyed when the last reference 131 | to the context group is released. 132 | */ 133 | JS_EXPORT void JSGarbageCollect(JSContextRef ctx); 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif 138 | 139 | /* Enable the Objective-C API for platforms with a modern runtime. */ 140 | #if !defined(JSC_OBJC_API_ENABLED) 141 | #define JSC_OBJC_API_ENABLED (defined(__clang__) && defined(__APPLE__) && ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && !defined(__i386__)) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE))) 142 | #endif 143 | 144 | #endif /* JSBase_h */ 145 | -------------------------------------------------------------------------------- /cpplibs/include/JavaScriptCore/JSContextRef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSContextRef_h 27 | #define JSContextRef_h 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifndef __cplusplus 34 | #include 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /*! 42 | @function 43 | @abstract Creates a JavaScript context group. 44 | @discussion A JSContextGroup associates JavaScript contexts with one another. 45 | Contexts in the same group may share and exchange JavaScript objects. Sharing and/or exchanging 46 | JavaScript objects between contexts in different groups will produce undefined behavior. 47 | When objects from the same context group are used in multiple threads, explicit 48 | synchronization is required. 49 | @result The created JSContextGroup. 50 | */ 51 | JS_EXPORT JSContextGroupRef JSContextGroupCreate(void) CF_AVAILABLE(10_6, 7_0); 52 | 53 | /*! 54 | @function 55 | @abstract Retains a JavaScript context group. 56 | @param group The JSContextGroup to retain. 57 | @result A JSContextGroup that is the same as group. 58 | */ 59 | JS_EXPORT JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group) CF_AVAILABLE(10_6, 7_0); 60 | 61 | /*! 62 | @function 63 | @abstract Releases a JavaScript context group. 64 | @param group The JSContextGroup to release. 65 | */ 66 | JS_EXPORT void JSContextGroupRelease(JSContextGroupRef group) CF_AVAILABLE(10_6, 7_0); 67 | 68 | /*! 69 | @function 70 | @abstract Creates a global JavaScript execution context. 71 | @discussion JSGlobalContextCreate allocates a global object and populates it with all the 72 | built-in JavaScript objects, such as Object, Function, String, and Array. 73 | 74 | In WebKit version 4.0 and later, the context is created in a unique context group. 75 | Therefore, scripts may execute in it concurrently with scripts executing in other contexts. 76 | However, you may not use values created in the context in other contexts. 77 | @param globalObjectClass The class to use when creating the global object. Pass 78 | NULL to use the default object class. 79 | @result A JSGlobalContext with a global object of class globalObjectClass. 80 | */ 81 | JS_EXPORT JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) CF_AVAILABLE(10_5, 7_0); 82 | 83 | /*! 84 | @function 85 | @abstract Creates a global JavaScript execution context in the context group provided. 86 | @discussion JSGlobalContextCreateInGroup allocates a global object and populates it with 87 | all the built-in JavaScript objects, such as Object, Function, String, and Array. 88 | @param globalObjectClass The class to use when creating the global object. Pass 89 | NULL to use the default object class. 90 | @param group The context group to use. The created global context retains the group. 91 | Pass NULL to create a unique group for the context. 92 | @result A JSGlobalContext with a global object of class globalObjectClass and a context 93 | group equal to group. 94 | */ 95 | JS_EXPORT JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass) CF_AVAILABLE(10_6, 7_0); 96 | 97 | /*! 98 | @function 99 | @abstract Retains a global JavaScript execution context. 100 | @param ctx The JSGlobalContext to retain. 101 | @result A JSGlobalContext that is the same as ctx. 102 | */ 103 | JS_EXPORT JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx); 104 | 105 | /*! 106 | @function 107 | @abstract Releases a global JavaScript execution context. 108 | @param ctx The JSGlobalContext to release. 109 | */ 110 | JS_EXPORT void JSGlobalContextRelease(JSGlobalContextRef ctx); 111 | 112 | /*! 113 | @function 114 | @abstract Gets the global object of a JavaScript execution context. 115 | @param ctx The JSContext whose global object you want to get. 116 | @result ctx's global object. 117 | */ 118 | JS_EXPORT JSObjectRef JSContextGetGlobalObject(JSContextRef ctx); 119 | 120 | /*! 121 | @function 122 | @abstract Gets the context group to which a JavaScript execution context belongs. 123 | @param ctx The JSContext whose group you want to get. 124 | @result ctx's group. 125 | */ 126 | JS_EXPORT JSContextGroupRef JSContextGetGroup(JSContextRef ctx) CF_AVAILABLE(10_6, 7_0); 127 | 128 | /*! 129 | @function 130 | @abstract Gets the global context of a JavaScript execution context. 131 | @param ctx The JSContext whose global context you want to get. 132 | @result ctx's global context. 133 | */ 134 | JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx) CF_AVAILABLE(10_7, 7_0); 135 | 136 | /*! 137 | @function 138 | @abstract Gets a copy of the name of a context. 139 | @param ctx The JSGlobalContext whose name you want to get. 140 | @result The name for ctx. 141 | @discussion A JSGlobalContext's name is exposed for remote debugging to make it 142 | easier to identify the context you would like to attach to. 143 | */ 144 | JS_EXPORT JSStringRef JSGlobalContextCopyName(JSGlobalContextRef ctx) CF_AVAILABLE(10_10, 8_0); 145 | 146 | /*! 147 | @function 148 | @abstract Sets the remote debugging name for a context. 149 | @param ctx The JSGlobalContext that you want to name. 150 | @param name The remote debugging name to set on ctx. 151 | */ 152 | JS_EXPORT void JSGlobalContextSetName(JSGlobalContextRef ctx, JSStringRef name) CF_AVAILABLE(10_10, 8_0); 153 | 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | 158 | #endif /* JSContextRef_h */ 159 | -------------------------------------------------------------------------------- /cpplibs/include/JavaScriptCore/JSObjectRefPrivate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 | * THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSObjectRefPrivate_h 27 | #define JSObjectRefPrivate_h 28 | 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /*! 36 | @function 37 | @abstract Sets a private property on an object. This private property cannot be accessed from within JavaScript. 38 | @param ctx The execution context to use. 39 | @param object The JSObject whose private property you want to set. 40 | @param propertyName A JSString containing the property's name. 41 | @param value A JSValue to use as the property's value. This may be NULL. 42 | @result true if object can store private data, otherwise false. 43 | @discussion This API allows you to store JS values directly an object in a way that will be ensure that they are kept alive without exposing them to JavaScript code and without introducing the reference cycles that may occur when using JSValueProtect. 44 | 45 | The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private properties. 46 | */ 47 | JS_EXPORT bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value); 48 | 49 | /*! 50 | @function 51 | @abstract Gets a private property from an object. 52 | @param ctx The execution context to use. 53 | @param object The JSObject whose private property you want to get. 54 | @param propertyName A JSString containing the property's name. 55 | @result The property's value if object has the property, otherwise NULL. 56 | */ 57 | JS_EXPORT JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); 58 | 59 | /*! 60 | @function 61 | @abstract Deletes a private property from an object. 62 | @param ctx The execution context to use. 63 | @param object The JSObject whose private property you want to delete. 64 | @param propertyName A JSString containing the property's name. 65 | @result true if object can store private data, otherwise false. 66 | @discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data. 67 | */ 68 | JS_EXPORT bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif // JSObjectRefPrivate_h 75 | -------------------------------------------------------------------------------- /cpplibs/include/JavaScriptCore/JSRetainPtr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of 14 | * its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef JSRetainPtr_h 30 | #define JSRetainPtr_h 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | inline void JSRetain(JSStringRef string) { JSStringRetain(string); } 37 | inline void JSRelease(JSStringRef string) { JSStringRelease(string); } 38 | inline void JSRetain(JSGlobalContextRef context) { JSGlobalContextRetain(context); } 39 | inline void JSRelease(JSGlobalContextRef context) { JSGlobalContextRelease(context); } 40 | 41 | enum AdoptTag { Adopt }; 42 | 43 | template class JSRetainPtr { 44 | public: 45 | JSRetainPtr() : m_ptr(0) { } 46 | JSRetainPtr(T ptr) : m_ptr(ptr) { if (ptr) JSRetain(ptr); } 47 | JSRetainPtr(AdoptTag, T ptr) : m_ptr(ptr) { } 48 | JSRetainPtr(const JSRetainPtr&); 49 | template JSRetainPtr(const JSRetainPtr&); 50 | ~JSRetainPtr(); 51 | 52 | T get() const { return m_ptr; } 53 | 54 | void clear(); 55 | T leakRef(); 56 | 57 | T operator->() const { return m_ptr; } 58 | 59 | bool operator!() const { return !m_ptr; } 60 | explicit operator bool() const { return m_ptr; } 61 | 62 | JSRetainPtr& operator=(const JSRetainPtr&); 63 | template JSRetainPtr& operator=(const JSRetainPtr&); 64 | JSRetainPtr& operator=(T); 65 | template JSRetainPtr& operator=(U*); 66 | 67 | void adopt(T); 68 | 69 | void swap(JSRetainPtr&); 70 | 71 | private: 72 | T m_ptr; 73 | }; 74 | 75 | inline JSRetainPtr adopt(JSStringRef o) 76 | { 77 | return JSRetainPtr(Adopt, o); 78 | } 79 | 80 | inline JSRetainPtr adopt(JSGlobalContextRef o) 81 | { 82 | return JSRetainPtr(Adopt, o); 83 | } 84 | 85 | template inline JSRetainPtr::JSRetainPtr(const JSRetainPtr& o) 86 | : m_ptr(o.m_ptr) 87 | { 88 | if (m_ptr) 89 | JSRetain(m_ptr); 90 | } 91 | 92 | template template inline JSRetainPtr::JSRetainPtr(const JSRetainPtr& o) 93 | : m_ptr(o.get()) 94 | { 95 | if (m_ptr) 96 | JSRetain(m_ptr); 97 | } 98 | 99 | template inline JSRetainPtr::~JSRetainPtr() 100 | { 101 | if (m_ptr) 102 | JSRelease(m_ptr); 103 | } 104 | 105 | template inline void JSRetainPtr::clear() 106 | { 107 | if (T ptr = m_ptr) { 108 | m_ptr = 0; 109 | JSRelease(ptr); 110 | } 111 | } 112 | 113 | template inline T JSRetainPtr::leakRef() 114 | { 115 | T ptr = m_ptr; 116 | m_ptr = 0; 117 | return ptr; 118 | } 119 | 120 | template inline JSRetainPtr& JSRetainPtr::operator=(const JSRetainPtr& o) 121 | { 122 | T optr = o.get(); 123 | if (optr) 124 | JSRetain(optr); 125 | T ptr = m_ptr; 126 | m_ptr = optr; 127 | if (ptr) 128 | JSRelease(ptr); 129 | return *this; 130 | } 131 | 132 | template template inline JSRetainPtr& JSRetainPtr::operator=(const JSRetainPtr& o) 133 | { 134 | T optr = o.get(); 135 | if (optr) 136 | JSRetain(optr); 137 | T ptr = m_ptr; 138 | m_ptr = optr; 139 | if (ptr) 140 | JSRelease(ptr); 141 | return *this; 142 | } 143 | 144 | template inline JSRetainPtr& JSRetainPtr::operator=(T optr) 145 | { 146 | if (optr) 147 | JSRetain(optr); 148 | T ptr = m_ptr; 149 | m_ptr = optr; 150 | if (ptr) 151 | JSRelease(ptr); 152 | return *this; 153 | } 154 | 155 | template inline void JSRetainPtr::adopt(T optr) 156 | { 157 | T ptr = m_ptr; 158 | m_ptr = optr; 159 | if (ptr) 160 | JSRelease(ptr); 161 | } 162 | 163 | template template inline JSRetainPtr& JSRetainPtr::operator=(U* optr) 164 | { 165 | if (optr) 166 | JSRetain(optr); 167 | T ptr = m_ptr; 168 | m_ptr = optr; 169 | if (ptr) 170 | JSRelease(ptr); 171 | return *this; 172 | } 173 | 174 | template inline void JSRetainPtr::swap(JSRetainPtr& o) 175 | { 176 | std::swap(m_ptr, o.m_ptr); 177 | } 178 | 179 | template inline void swap(JSRetainPtr& a, JSRetainPtr& b) 180 | { 181 | a.swap(b); 182 | } 183 | 184 | template inline bool operator==(const JSRetainPtr& a, const JSRetainPtr& b) 185 | { 186 | return a.get() == b.get(); 187 | } 188 | 189 | template inline bool operator==(const JSRetainPtr& a, U* b) 190 | { 191 | return a.get() == b; 192 | } 193 | 194 | template inline bool operator==(T* a, const JSRetainPtr& b) 195 | { 196 | return a == b.get(); 197 | } 198 | 199 | template inline bool operator!=(const JSRetainPtr& a, const JSRetainPtr& b) 200 | { 201 | return a.get() != b.get(); 202 | } 203 | 204 | template inline bool operator!=(const JSRetainPtr& a, U* b) 205 | { 206 | return a.get() != b; 207 | } 208 | 209 | template inline bool operator!=(T* a, const JSRetainPtr& b) 210 | { 211 | return a != b.get(); 212 | } 213 | 214 | 215 | #endif // JSRetainPtr_h 216 | -------------------------------------------------------------------------------- /cpplibs/include/JavaScriptCore/JSStringRef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSStringRef_h 27 | #define JSStringRef_h 28 | 29 | #include 30 | 31 | #ifndef __cplusplus 32 | #include 33 | #endif 34 | #include /* for size_t */ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #if !defined(_NATIVE_WCHAR_T_DEFINED) /* MSVC */ \ 41 | && (!defined(__WCHAR_MAX__) || (__WCHAR_MAX__ > 0xffffU)) /* ISO C/C++ */ \ 42 | && (!defined(WCHAR_MAX) || (WCHAR_MAX > 0xffffU)) /* RVCT */ 43 | /*! 44 | @typedef JSChar 45 | @abstract A UTF-16 code unit. One, or a sequence of two, can encode any Unicode 46 | character. As with all scalar types, endianness depends on the underlying 47 | architecture. 48 | */ 49 | typedef unsigned short JSChar; 50 | #else 51 | typedef wchar_t JSChar; 52 | #endif 53 | 54 | /*! 55 | @function 56 | @abstract Creates a JavaScript string from a buffer of Unicode characters. 57 | @param chars The buffer of Unicode characters to copy into the new JSString. 58 | @param numChars The number of characters to copy from the buffer pointed to by chars. 59 | @result A JSString containing chars. Ownership follows the Create Rule. 60 | */ 61 | JS_EXPORT JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars); 62 | /*! 63 | @function 64 | @abstract Creates a JavaScript string from a null-terminated UTF8 string. 65 | @param string The null-terminated UTF8 string to copy into the new JSString. 66 | @result A JSString containing string. Ownership follows the Create Rule. 67 | */ 68 | JS_EXPORT JSStringRef JSStringCreateWithUTF8CString(const char* string); 69 | 70 | /*! 71 | @function 72 | @abstract Retains a JavaScript string. 73 | @param string The JSString to retain. 74 | @result A JSString that is the same as string. 75 | */ 76 | JS_EXPORT JSStringRef JSStringRetain(JSStringRef string); 77 | /*! 78 | @function 79 | @abstract Releases a JavaScript string. 80 | @param string The JSString to release. 81 | */ 82 | JS_EXPORT void JSStringRelease(JSStringRef string); 83 | 84 | /*! 85 | @function 86 | @abstract Returns the number of Unicode characters in a JavaScript string. 87 | @param string The JSString whose length (in Unicode characters) you want to know. 88 | @result The number of Unicode characters stored in string. 89 | */ 90 | JS_EXPORT size_t JSStringGetLength(JSStringRef string); 91 | /*! 92 | @function 93 | @abstract Returns a pointer to the Unicode character buffer that 94 | serves as the backing store for a JavaScript string. 95 | @param string The JSString whose backing store you want to access. 96 | @result A pointer to the Unicode character buffer that serves as string's 97 | backing store, which will be deallocated when string is deallocated. 98 | */ 99 | JS_EXPORT const JSChar* JSStringGetCharactersPtr(JSStringRef string); 100 | 101 | /*! 102 | @function 103 | @abstract Returns the maximum number of bytes a JavaScript string will 104 | take up if converted into a null-terminated UTF8 string. 105 | @param string The JSString whose maximum converted size (in bytes) you 106 | want to know. 107 | @result The maximum number of bytes that could be required to convert string into a 108 | null-terminated UTF8 string. The number of bytes that the conversion actually ends 109 | up requiring could be less than this, but never more. 110 | */ 111 | JS_EXPORT size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string); 112 | /*! 113 | @function 114 | @abstract Converts a JavaScript string into a null-terminated UTF8 string, 115 | and copies the result into an external byte buffer. 116 | @param string The source JSString. 117 | @param buffer The destination byte buffer into which to copy a null-terminated 118 | UTF8 representation of string. On return, buffer contains a UTF8 string 119 | representation of string. If bufferSize is too small, buffer will contain only 120 | partial results. If buffer is not at least bufferSize bytes in size, 121 | behavior is undefined. 122 | @param bufferSize The size of the external buffer in bytes. 123 | @result The number of bytes written into buffer (including the null-terminator byte). 124 | */ 125 | JS_EXPORT size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize); 126 | 127 | /*! 128 | @function 129 | @abstract Tests whether two JavaScript strings match. 130 | @param a The first JSString to test. 131 | @param b The second JSString to test. 132 | @result true if the two strings match, otherwise false. 133 | */ 134 | JS_EXPORT bool JSStringIsEqual(JSStringRef a, JSStringRef b); 135 | /*! 136 | @function 137 | @abstract Tests whether a JavaScript string matches a null-terminated UTF8 string. 138 | @param a The JSString to test. 139 | @param b The null-terminated UTF8 string to test. 140 | @result true if the two strings match, otherwise false. 141 | */ 142 | JS_EXPORT bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b); 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif /* JSStringRef_h */ 149 | -------------------------------------------------------------------------------- /cpplibs/include/JavaScriptCore/JavaScript.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Apple Inc. All rights reserved. 3 | * Copyright (C) 2008 Alp Toker 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef JavaScript_h 28 | #define JavaScript_h 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #endif /* JavaScript_h */ 38 | -------------------------------------------------------------------------------- /cpplibs/include/JavaScriptCore/WebKitAvailability.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008, 2009, 2010, 2014 Apple Inc. All Rights Reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef __WebKitAvailability__ 27 | #define __WebKitAvailability__ 28 | 29 | #if defined(__APPLE__) && defined(DEFINE_AVAILABILITY_MACROS) 30 | 31 | #include 32 | #include 33 | 34 | #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED < 101100 35 | /* To support availability macros that mention newer OS X versions when building on older OS X versions, 36 | we provide our own definitions of the underlying macros that the availability macros expand to. We're 37 | free to expand the macros as no-ops since frameworks built on older OS X versions only ship bundled with 38 | an application rather than as part of the system. 39 | */ 40 | 41 | #ifndef __NSi_10_10 // Building from trunk rather than SDK. 42 | #define __NSi_10_10 introduced=10.0 // Use 10.0 to indicate that everything is available. 43 | #endif 44 | 45 | #ifndef __NSi_10_11 // Building from trunk rather than SDK. 46 | #define __NSi_10_11 introduced=10.0 // Use 10.0 to indicate that everything is available. 47 | #endif 48 | 49 | #ifndef __NSi_10_12 // Building from trunk rather than SDK. 50 | #define __NSi_10_12 introduced=10.0 // Use 10.0 to indicate that everything is available. 51 | #endif 52 | 53 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_9 54 | #define __AVAILABILITY_INTERNAL__MAC_10_9 55 | #endif 56 | 57 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_10 58 | #define __AVAILABILITY_INTERNAL__MAC_10_10 59 | #endif 60 | 61 | #ifndef AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER 62 | #define AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER 63 | #endif 64 | 65 | #ifndef AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER 66 | #define AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER 67 | #endif 68 | 69 | #endif /* __MAC_OS_X_VERSION_MIN_REQUIRED <= 101100 */ 70 | 71 | #if defined(BUILDING_GTK__) 72 | #undef CF_AVAILABLE 73 | #define CF_AVAILABLE(_mac, _ios) 74 | #undef CF_ENUM_AVAILABLE 75 | #define CF_ENUM_AVAILABLE(_mac, _ios) 76 | #endif 77 | 78 | #else 79 | #ifndef CF_AVAILABLE 80 | #define CF_AVAILABLE(_mac, _ios) 81 | #define CF_ENUM_AVAILABLE(_mac, _ios) 82 | #endif 83 | #endif 84 | 85 | #endif /* __WebKitAvailability__ */ 86 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/Bitmap.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file Bitmap.h 3 | /// 4 | /// @brief The header for the Bitmap class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ultralight { 20 | 21 | #pragma pack(push, 1) 22 | 23 | /// 24 | /// The various Bitmap formats. 25 | /// 26 | enum UExport BitmapFormat { 27 | /** 28 | * Alpha channel only, 8-bits per pixel. 29 | * 30 | * Encoding: 8-bits per channel, unsigned normalized. 31 | * 32 | * Color-space: Linear (no gamma), alpha-coverage only. 33 | */ 34 | kBitmapFormat_A8_UNORM, 35 | 36 | /** 37 | * Blue Green Red Alpha channels, 32-bits per pixel. 38 | * 39 | * Encoding: 8-bits per channel, unsigned normalized. 40 | * 41 | * Color-space: sRGB gamma with premultiplied linear alpha channel. 42 | * 43 | * NOTE: Alpha is premultiplied with BGR channels _before_ sRGB gamma is 44 | * applied so we can use sRGB conversion hardware and perform all 45 | * blending in linear space on GPU. 46 | */ 47 | kBitmapFormat_BGRA8_UNORM_SRGB, 48 | }; 49 | 50 | /// 51 | /// Macro to get the bytes per pixel from a BitmapFormat 52 | /// 53 | #define GetBytesPerPixel(x) (x == kBitmapFormat_A8_UNORM? 1 : 4) 54 | 55 | /// 56 | /// @brief Bitmap container with basic blitting and conversion routines. 57 | /// 58 | class UExport Bitmap : public RefCounted { 59 | public: 60 | /// 61 | /// Create an empty Bitmap. No pixels will be allocated. 62 | /// 63 | static Ref Create(); 64 | 65 | /// 66 | /// Create a Bitmap with a certain configuration. Pixels will be allocated 67 | /// but not initialized. 68 | /// 69 | /// @param width The width in pixels. 70 | /// 71 | /// @param height The height in pixels. 72 | /// 73 | /// @param format The pixel format to use. 74 | /// 75 | /// @return A ref-pointer to a new Bitmap instance. 76 | /// 77 | static Ref Create(uint32_t width, uint32_t height, 78 | BitmapFormat format); 79 | 80 | /// 81 | /// Create a Bitmap with existing pixels and configuration. 82 | /// 83 | /// @param width The width in pixels. 84 | /// 85 | /// @param height The height in pixels. 86 | /// 87 | /// @param format The pixel format to use. 88 | /// 89 | /// @param row_bytes The number of bytes between each row (note that this 90 | /// value should be >= width * bytes_per_pixel). 91 | /// 92 | /// @param pixels Pointer to raw pixel buffer. 93 | /// 94 | /// @param size Size of the raw pixel buffer. 95 | /// 96 | /// @param should_copy Whether or not a copy should be made of the pixels. 97 | /// If this is false, the returned Bitmap will use the 98 | /// raw pixels passed in as its own, but you are still 99 | /// responsible for destroying your buffer afterwards. 100 | /// 101 | /// @param fixup_gamma Whether or not we should reinterpret the source 102 | /// as an sRGB bitmap with premultiplied alpha applied 103 | /// after the gamma function (typical of PNGs). We 104 | /// expect all premultiplication to be applied before 105 | /// the gamma function so we can blend properly in 106 | /// linear space. Only valid for 107 | /// kBitmapFormat_BGRA8_UNORM_SRGB. 108 | /// 109 | /// @return A ref-pointer to a new Bitmap instance. 110 | /// 111 | static Ref Create(uint32_t width, uint32_t height, 112 | BitmapFormat format, uint32_t row_bytes, 113 | const void* pixels, size_t size, 114 | bool should_copy = true, bool fixup_gamma = false); 115 | 116 | /// 117 | /// Create a bitmap from a deep copy of another Bitmap. 118 | /// 119 | static Ref Create(const Bitmap& bitmap); 120 | 121 | /// 122 | /// Get the width in pixels. 123 | /// 124 | virtual uint32_t width() const = 0; 125 | 126 | /// 127 | /// Get the height in pixels. 128 | /// 129 | virtual uint32_t height() const = 0; 130 | 131 | /// 132 | /// Get the bounds as an IntRect 133 | /// 134 | virtual IntRect bounds() const = 0; 135 | 136 | /// 137 | /// Get the pixel format. 138 | /// 139 | virtual BitmapFormat format() const = 0; 140 | 141 | /// 142 | /// Get the number of bytes per pixel. 143 | /// 144 | virtual uint32_t bpp() const = 0; 145 | 146 | /// 147 | /// Get the number of bytes between each row (this is always >= width * bpp) 148 | /// 149 | virtual uint32_t row_bytes() const = 0; 150 | 151 | /// 152 | /// Get the size in bytes of the pixel buffer. 153 | /// 154 | virtual size_t size() const = 0; 155 | 156 | /// 157 | /// Whether or not this Bitmap owns the pixel buffer and will destroy it 158 | /// at the end of its lifetime. 159 | /// 160 | virtual bool owns_pixels() const = 0; 161 | 162 | /// 163 | /// Lock the pixel buffer for reading/writing. 164 | /// 165 | /// @return A pointer to the pixel buffer. 166 | /// 167 | virtual void* LockPixels() = 0; 168 | 169 | /// 170 | /// Unlock the pixel buffer. 171 | /// 172 | virtual void UnlockPixels() = 0; 173 | 174 | /// 175 | /// Lock the pixel buffer for reading/writing. (const) 176 | /// 177 | /// @return A const pointer to the pixel buffer. 178 | /// 179 | virtual const void* LockPixels() const = 0; 180 | 181 | /// 182 | /// Unlock the pixel buffer. (const) 183 | /// 184 | virtual void UnlockPixels() const = 0; 185 | 186 | /// 187 | /// Get the raw pixel buffer. 188 | /// 189 | /// @note You should only call this if pixels are already locked. 190 | /// 191 | virtual void* raw_pixels() = 0; 192 | 193 | /// 194 | /// Whether or not this Bitmap is empty (no pixels allocated). 195 | /// 196 | virtual bool IsEmpty() const = 0; 197 | 198 | /// 199 | /// Erase the Bitmap (set all pixels to 0). 200 | /// 201 | virtual void Erase() = 0; 202 | 203 | /// 204 | /// Assign another bitmap to this one. 205 | /// 206 | /// @param bitmap The bitmap to copy from. 207 | /// 208 | virtual void Set(Ref bitmap) = 0; 209 | 210 | /// 211 | /// Draw another bitmap to this bitmap. 212 | /// 213 | /// @note Formats do not need to match. Bitmap formats will be converted 214 | /// to one another automatically. Note that when converting from 215 | /// BGRA8 to A8, only the Blue channel will be used. 216 | /// 217 | /// @param src_rect The source rectangle, relative to src bitmap. 218 | /// 219 | /// @param dest_rect The destination rectangle, relative to this bitmap. 220 | /// 221 | /// @param src The source bitmap. 222 | /// 223 | /// @param pad_repeat Whether or not we should pad the drawn bitmap by one 224 | /// pixel of repeated edge pixels from the source bitmap. 225 | /// 226 | /// @return Whether or not the operation succeeded (this can fail if the 227 | /// src_rect and/or dest_rect are invalid, or if their total 228 | /// dimensions do not match). 229 | /// 230 | virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect, 231 | Ref src, bool pad_repeat) = 0; 232 | 233 | /// 234 | /// Write this Bitmap out to a PNG image. (mainly used for Debug) 235 | /// 236 | /// @param path The filepath to write to (opened with fopen()) 237 | /// 238 | /// @return Whether or not the operation succeeded. 239 | /// 240 | virtual bool WritePNG(const char* path) = 0; 241 | 242 | 243 | /// 244 | /// Make a resized copy of this bitmap by writing to a pre-allocated 245 | /// destination bitmap. 246 | /// 247 | /// @param destination The bitmap to store the result in, the width and 248 | /// height of the destination will be used. 249 | /// 250 | /// @param high_quality Whether or not a high quality resampling will be 251 | /// used during the resize. (Otherwise, just uses fast 252 | /// nearest-neighbor sampling) 253 | /// 254 | /// @return Whether or not the operation succeeded. This operation is only 255 | /// valid if both formats are kBitmapFormat_BGRA8_UNORM_SRGB and 256 | /// both the source and destination are non-empty. 257 | /// 258 | virtual bool Resample(Ref destination, bool high_quality) = 0; 259 | 260 | protected: 261 | Bitmap(); 262 | virtual ~Bitmap(); 263 | Bitmap(const Bitmap&); 264 | void operator=(const Bitmap&); 265 | }; 266 | 267 | #pragma pack(pop) 268 | 269 | } // namespace ultralight 270 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/Buffer.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file Buffer.h 3 | /// 4 | /// @brief The header for the Buffer class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | 18 | namespace ultralight { 19 | 20 | /// 21 | /// A fixed-size byte container for passing data around. 22 | /// 23 | class UExport Buffer : public RefCounted { 24 | public: 25 | /// 26 | /// Create a Buffer, a copy of data is made. 27 | /// 28 | static Ref Create(const void* data, size_t size); 29 | 30 | /// 31 | /// Get a pointer to raw byte data. 32 | /// 33 | virtual void* data() = 0; 34 | 35 | /// 36 | /// Get the size in bytes. 37 | /// 38 | virtual size_t size() const = 0; 39 | 40 | protected: 41 | Buffer(); 42 | virtual ~Buffer(); 43 | Buffer(const Buffer&); 44 | void operator=(const Buffer&); 45 | }; 46 | 47 | } // namespace ultralight 48 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/Defines.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file Defines.h 3 | /// 4 | /// @brief Common platform definitions 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | 16 | // Needed for limit defines, like INTMAX_MAX, which is used by the std C++ library 17 | #ifndef __STDC_LIMIT_MACROS 18 | #define __STDC_LIMIT_MACROS 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef SWIG 26 | #define UExport 27 | #else 28 | 29 | // Require C++11 Support 30 | #if defined(_MSC_VER) 31 | # if _MSC_VER < 1800 32 | # error This project needs at least Visual Studio 2013 to build 33 | # endif 34 | #elif __cplusplus <= 199711L 35 | # error This project can only be compiled with a compiler that supports C++11 36 | #endif 37 | 38 | 39 | #if defined(__WIN32__) || defined(_WIN32) 40 | # if defined(ULTRALIGHT_IMPLEMENTATION) 41 | # define UExport __declspec(dllexport) 42 | # else 43 | # define UExport __declspec(dllimport) 44 | # endif 45 | #define _thread_local __declspec(thread) 46 | #ifndef _NATIVE_WCHAR_T_DEFINED 47 | #define DISABLE_NATIVE_WCHAR_T 48 | #endif 49 | #else 50 | # define UExport __attribute__((visibility("default"))) 51 | #define _thread_local __thread 52 | #endif 53 | 54 | #endif 55 | 56 | #define ULTRALIGHT_VERSION "1.1.0" 57 | 58 | /// 59 | /// @mainpage Ultralight C++ API Reference 60 | /// 61 | /// @section intro_sec Introduction 62 | /// 63 | /// Hi there, welcome to the C++ API Reference for Ultralight! 64 | /// 65 | /// Ultralight is a fast, lightweight HTML UI engine for desktop apps. 66 | /// 67 | /// If this is your first time exploring the API, we recommend 68 | /// starting with ultralight::Renderer and ultralight::View. 69 | /// 70 | /// 71 | /// @section usefullinks_sec Useful Links 72 | /// - Home: -- Get the latest binaries 73 | /// - Docs: -- API overview, code snippets, tutorials and more! 74 | /// - Slack: -- Stuck? Have questions? Come chat with us! 75 | /// - GitHub: -- Report issues and browse code 76 | /// 77 | /// @section copyright_sec Copyright 78 | /// Documentation is copyright (C) 2019 Ultralight, Inc. All rights reserved. 79 | /// 80 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/KeyEvent.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file KeyEvent.h 3 | /// 4 | /// @brief The header for the KeyEvent class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | #ifdef __OBJC__ 19 | #import 20 | #endif 21 | 22 | namespace ultralight { 23 | 24 | /// 25 | /// @brief A generic keyboard event that can be created from a platform event 26 | /// or synthesized from scratch. 27 | /// 28 | /// @see View::FireKeyEvent 29 | /// 30 | class UExport KeyEvent { 31 | public: 32 | /// 33 | /// The various KeyEvent types. 34 | /// 35 | enum Type { 36 | /// Key-Down type 37 | kType_KeyDown, 38 | 39 | /// Key-Up type 40 | kType_KeyUp, 41 | 42 | /// Raw Key-Down type 43 | kType_RawKeyDown, 44 | 45 | /// Character input type (this event generates text in input fields) 46 | kType_Char, 47 | }; 48 | 49 | /// 50 | /// Creates an empty KeyEvent, you will need to initialize its members 51 | /// yourself. This is useful for synthesizing your own keyboard events. 52 | /// 53 | KeyEvent(); 54 | 55 | #ifdef _WIN32 56 | /// 57 | /// Create a KeyEvent directly from a Windows keyboard event. 58 | /// 59 | KeyEvent(Type type, uintptr_t wparam, intptr_t lparam, bool is_system_key); 60 | #endif 61 | 62 | #ifdef __OBJC__ 63 | /// 64 | /// Create a KeyEvent directly from a macOS NSEvent. 65 | /// 66 | KeyEvent(NSEvent* evt); 67 | #endif 68 | 69 | /// 70 | /// An enumeration of the different keyboard modifiers. 71 | /// 72 | enum Modifiers : uint8_t { 73 | /// Whether or not an ALT key is down 74 | kMod_AltKey = 1 << 0, 75 | 76 | /// Whether or not a Control key is down 77 | kMod_CtrlKey = 1 << 1, 78 | 79 | /// Whether or not a meta key (Command-key on Mac, Windows-key on Win) is down 80 | kMod_MetaKey = 1 << 2, 81 | 82 | /// Whether or not a Shift key is down 83 | kMod_ShiftKey = 1 << 3, 84 | }; 85 | 86 | /// 87 | // The type of this KeyEvent 88 | /// 89 | Type type; 90 | 91 | /// 92 | /// The current state of the keyboard. Modifiers may be OR'd together to 93 | /// represent multiple values. 94 | /// 95 | unsigned modifiers; 96 | 97 | /// 98 | // The virtual key-code associated with this keyboard event. This is either 99 | // directly from the event (ie, WPARAM on Windows) or via a mapping function. 100 | // You can see a full list of the possible virtual key-codes in 101 | // KeyboardCodes.h 102 | /// 103 | int virtual_key_code; 104 | 105 | /// 106 | /// The actual key-code generated by the platform. The DOM spec primarily 107 | /// uses Windows-equivalent codes (hence virtualKeyCode above) but it helps to 108 | /// also specify the platform-specific key-code as well. 109 | /// 110 | int native_key_code; 111 | 112 | /// 113 | /// This is a string identifying the key that was pressed. This can be 114 | /// generated from the virtual_key_code via the GetKeyIdentifierFromVirtualKeyCode() 115 | /// utility function. You can find the full list of key identifiers at: 116 | /// 117 | /// 118 | String key_identifier; 119 | 120 | /// 121 | /// The actual text generated by this keyboard event. This is usually only a 122 | /// single character. 123 | /// 124 | String text; 125 | 126 | /// 127 | /// The text generated by this keyboard event before all modifiers except 128 | /// shift are applied. This is used internally for working out shortcut keys. 129 | /// This is usually only a single character. 130 | /// 131 | String unmodified_text; 132 | 133 | /// 134 | /// Whether or not this is a keypad event. 135 | /// 136 | bool is_keypad; 137 | 138 | /// 139 | /// Whether or not this was generated as the result of an auto-repeat 140 | /// (eg, holding down a key). 141 | /// 142 | bool is_auto_repeat; 143 | 144 | /// 145 | /// Whether or not the pressed key is a "system key". This is a Windows-only 146 | /// concept and should be "false" for all non-Windows platforms. For more 147 | /// information, see the following link: 148 | /// 149 | bool is_system_key; 150 | }; 151 | 152 | /// 153 | /// Utility function for generating a key identifier string from a virtual 154 | /// key-code. 155 | /// 156 | /// @param virtual_key_code The virtual key-code to generate the key 157 | /// identifier from. 158 | /// 159 | /// @param key_identifier_result The string to store the result in. 160 | /// 161 | void UExport GetKeyIdentifierFromVirtualKeyCode(int virtual_key_code, 162 | String& key_identifier_result); 163 | 164 | } // namespace ultralight 165 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/Listener.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file Listener.h 3 | /// 4 | /// @brief The header for View listener interfaces. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | 18 | namespace ultralight { 19 | 20 | class View; 21 | 22 | /// 23 | /// MessageSource types, @see ViewListener::OnAddConsoleMessage 24 | /// 25 | enum MessageSource { 26 | kMessageSource_XML = 0, 27 | kMessageSource_JS, 28 | kMessageSource_Network, 29 | kMessageSource_ConsoleAPI, 30 | kMessageSource_Storage, 31 | kMessageSource_AppCache, 32 | kMessageSource_Rendering, 33 | kMessageSource_CSS, 34 | kMessageSource_Security, 35 | kMessageSource_ContentBlocker, 36 | kMessageSource_Other, 37 | }; 38 | 39 | /// 40 | /// MessageLevel types, @see ViewListener::OnAddConsoleMessage 41 | /// 42 | enum MessageLevel { 43 | kMessageLevel_Log = 1, 44 | kMessageLevel_Warning = 2, 45 | kMessageLevel_Error = 3, 46 | kMessageLevel_Debug = 4, 47 | kMessageLevel_Info = 5, 48 | }; 49 | 50 | /// 51 | /// Cursor types, @see ViewListener::OnChangeCursor 52 | /// 53 | enum Cursor { 54 | kCursor_Pointer = 0, 55 | kCursor_Cross, 56 | kCursor_Hand, 57 | kCursor_IBeam, 58 | kCursor_Wait, 59 | kCursor_Help, 60 | kCursor_EastResize, 61 | kCursor_NorthResize, 62 | kCursor_NorthEastResize, 63 | kCursor_NorthWestResize, 64 | kCursor_SouthResize, 65 | kCursor_SouthEastResize, 66 | kCursor_SouthWestResize, 67 | kCursor_WestResize, 68 | kCursor_NorthSouthResize, 69 | kCursor_EastWestResize, 70 | kCursor_NorthEastSouthWestResize, 71 | kCursor_NorthWestSouthEastResize, 72 | kCursor_ColumnResize, 73 | kCursor_RowResize, 74 | kCursor_MiddlePanning, 75 | kCursor_EastPanning, 76 | kCursor_NorthPanning, 77 | kCursor_NorthEastPanning, 78 | kCursor_NorthWestPanning, 79 | kCursor_SouthPanning, 80 | kCursor_SouthEastPanning, 81 | kCursor_SouthWestPanning, 82 | kCursor_WestPanning, 83 | kCursor_Move, 84 | kCursor_VerticalText, 85 | kCursor_Cell, 86 | kCursor_ContextMenu, 87 | kCursor_Alias, 88 | kCursor_Progress, 89 | kCursor_NoDrop, 90 | kCursor_Copy, 91 | kCursor_None, 92 | kCursor_NotAllowed, 93 | kCursor_ZoomIn, 94 | kCursor_ZoomOut, 95 | kCursor_Grab, 96 | kCursor_Grabbing, 97 | kCursor_Custom 98 | }; 99 | 100 | /// 101 | /// @brief Interface for View-related events 102 | /// 103 | /// @note For more info @see View::set_view_listener 104 | /// 105 | class UExport ViewListener { 106 | public: 107 | virtual ~ViewListener() {} 108 | 109 | /// 110 | /// Called when the page title changes 111 | /// 112 | virtual void OnChangeTitle(ultralight::View* caller, 113 | const String& title) {} 114 | 115 | /// 116 | /// Called when the page URL changes 117 | /// 118 | virtual void OnChangeURL(ultralight::View* caller, 119 | const String& url) {} 120 | 121 | /// 122 | /// Called when the tooltip changes (usually as result of a mouse hover) 123 | /// 124 | virtual void OnChangeTooltip(ultralight::View* caller, 125 | const String& tooltip) {} 126 | 127 | /// 128 | /// Called when the mouse cursor changes 129 | /// 130 | virtual void OnChangeCursor(ultralight::View* caller, 131 | Cursor cursor) {} 132 | 133 | /// 134 | /// Called when a message is added to the console (useful for errors / debug) 135 | /// 136 | virtual void OnAddConsoleMessage(ultralight::View* caller, 137 | MessageSource source, 138 | MessageLevel level, 139 | const String& message, 140 | uint32_t line_number, 141 | uint32_t column_number, 142 | const String& source_id) {} 143 | }; 144 | 145 | /// 146 | /// @brief Interface for Load-related events 147 | /// 148 | /// @note For more info @see View::set_load_listener 149 | /// 150 | class UExport LoadListener { 151 | public: 152 | virtual ~LoadListener() {} 153 | 154 | /// 155 | /// Called when the page begins loading new URL into main frame 156 | /// 157 | virtual void OnBeginLoading(ultralight::View* caller) {} 158 | 159 | /// 160 | /// Called when the page finishes loading URL into main frame 161 | /// 162 | virtual void OnFinishLoading(ultralight::View* caller) {} 163 | 164 | /// 165 | /// Called when the history (back/forward state) is modified 166 | /// 167 | virtual void OnUpdateHistory(ultralight::View* caller) {} 168 | 169 | /// 170 | /// Called when all JavaScript has been parsed and the document is ready. 171 | /// This is the best time to make any initial JavaScript calls to your page. 172 | /// 173 | virtual void OnDOMReady(ultralight::View* caller) {} 174 | }; 175 | 176 | } // namespace ultralight 177 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/Matrix.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file Matrix.h 3 | /// 4 | /// @brief The header for Matrix helpers 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ultralight { 20 | 21 | /// 22 | /// 4x4 Matrix Helper 23 | /// 24 | struct UExport Matrix4x4 { 25 | /// 26 | /// Raw 4x4 matrix as an array 27 | /// 28 | float data[16]; 29 | 30 | /// 31 | /// Set to identity matrix. 32 | /// 33 | void SetIdentity(); 34 | }; 35 | 36 | /// 37 | /// Transformation Matrix helper 38 | /// 39 | struct UExport Matrix { 40 | #if defined(__x86_64__) || defined(_M_X64) 41 | #if defined(_MSC_VER) 42 | __declspec(align(16)) typedef double Aligned4x4[4][4]; 43 | #else 44 | typedef double Aligned4x4[4][4] __attribute__((aligned(16))); 45 | #endif 46 | #else 47 | typedef double Aligned4x4[4][4]; 48 | #endif 49 | 50 | Aligned4x4 data; 51 | 52 | /// 53 | /// Set to identity matrix. 54 | /// 55 | void SetIdentity(); 56 | 57 | /// 58 | /// Set to an orthographic projection matrix suitable for use with our 59 | /// vertex shaders. Optionally flip the y-coordinate space (eg, for OpenGL). 60 | /// 61 | void SetOrthographicProjection(double screen_width, double screen_height, 62 | bool flip_y); 63 | 64 | /// 65 | /// Set to another matrix. 66 | /// 67 | void Set(const Matrix& other); 68 | 69 | /// 70 | /// Set to another matrix. 71 | /// 72 | void Set(const Matrix4x4& other); 73 | 74 | /// 75 | /// Set from raw affine members. 76 | /// 77 | void Set(double a, double b, double c, double d, double e, double f); 78 | 79 | /// 80 | /// Set from raw 4x4 components. 81 | /// 82 | void Set(double m11, double m12, double m13, double m14, 83 | double m21, double m22, double m23, double m24, 84 | double m31, double m32, double m33, double m34, 85 | double m41, double m42, double m43, double m44); 86 | 87 | inline double m11() const { return data[0][0]; } 88 | inline double m12() const { return data[0][1]; } 89 | inline double m13() const { return data[0][2]; } 90 | inline double m14() const { return data[0][3]; } 91 | inline double m21() const { return data[1][0]; } 92 | inline double m22() const { return data[1][1]; } 93 | inline double m23() const { return data[1][2]; } 94 | inline double m24() const { return data[1][3]; } 95 | inline double m31() const { return data[2][0]; } 96 | inline double m32() const { return data[2][1]; } 97 | inline double m33() const { return data[2][2]; } 98 | inline double m34() const { return data[2][3]; } 99 | inline double m41() const { return data[3][0]; } 100 | inline double m42() const { return data[3][1]; } 101 | inline double m43() const { return data[3][2]; } 102 | inline double m44() const { return data[3][3]; } 103 | 104 | inline double a() const { return data[0][0]; } 105 | inline double b() const { return data[0][1]; } 106 | inline double c() const { return data[1][0]; } 107 | inline double d() const { return data[1][1]; } 108 | inline double e() const { return data[3][0]; } 109 | inline double f() const { return data[3][1]; } 110 | 111 | /// 112 | /// Whether or not this is an identity matrix. 113 | /// 114 | bool IsIdentity() const; 115 | 116 | /// 117 | /// Whether or not this is an identity matrix or translation. 118 | /// 119 | bool IsIdentityOrTranslation() const; 120 | 121 | /// 122 | /// Whether or not this matrix uses only affine transformations. 123 | /// 124 | bool IsAffine() const; 125 | 126 | /// 127 | /// Whether or not this is an identity, translation, or non-negative 128 | /// uniform scale. 129 | /// 130 | bool IsSimple() const; 131 | 132 | /// 133 | /// Translate by x and y. 134 | /// 135 | void Translate(double x, double y); 136 | 137 | /// 138 | /// Scale by x and y. 139 | /// 140 | void Scale(double x, double y); 141 | 142 | /// 143 | /// Rotate matrix by theta (in degrees) 144 | /// 145 | void Rotate(double theta); 146 | 147 | /// 148 | /// Rotate matrix by x and y 149 | /// 150 | void Rotate(double x, double y); 151 | 152 | /// 153 | /// Transform (multiply) by another Matrix 154 | /// 155 | void Transform(const Matrix& other); 156 | 157 | /// 158 | /// Get the inverse of this matrix. May return false if not invertible. 159 | /// 160 | bool GetInverse(Matrix& result) const; 161 | 162 | /// 163 | /// Transform point by this matrix and get the result. 164 | /// 165 | Point Apply(const Point& p) const; 166 | 167 | /// 168 | /// Transform rect by this matrix and get the result as an axis-aligned rect. 169 | /// 170 | Rect Apply(const Rect& r) const; 171 | 172 | /// 173 | /// Get an integer hash of this matrix's members. 174 | /// 175 | uint32_t Hash() const; 176 | 177 | /// 178 | /// Get this matrix as unaligned 4x4 float components (for use passing to 179 | /// GPU driver APIs). 180 | /// 181 | Matrix4x4 GetMatrix4x4() const; 182 | }; 183 | 184 | bool UExport operator==(const Matrix& a, const Matrix& b); 185 | bool UExport operator!=(const Matrix& a, const Matrix& b); 186 | 187 | bool UExport operator==(const Matrix4x4& a, const Matrix4x4& b); 188 | bool UExport operator!=(const Matrix4x4& a, const Matrix4x4& b); 189 | 190 | } // namespace ultralight 191 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/MouseEvent.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file MouseEvent.h 3 | /// 4 | /// @brief The header for the MouseEvent class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | 17 | namespace ultralight { 18 | 19 | /// 20 | /// @brief A generic mouse event. 21 | /// 22 | /// @note @see View::FireMouseEvent 23 | /// 24 | class MouseEvent { 25 | public: 26 | /// 27 | /// The various MouseEvent types. 28 | /// 29 | enum Type { 30 | /// 31 | /// Mouse moved type 32 | /// 33 | kType_MouseMoved, 34 | 35 | /// 36 | /// Mouse button pressed type 37 | /// 38 | kType_MouseDown, 39 | 40 | /// 41 | /// Mouse button released type 42 | /// 43 | kType_MouseUp, 44 | }; 45 | 46 | /// 47 | /// The various mouse button types. 48 | /// 49 | enum Button { 50 | kButton_None = 0, 51 | kButton_Left, 52 | kButton_Middle, 53 | kButton_Right, 54 | }; 55 | 56 | /// 57 | /// The type of this MouseEvent 58 | /// 59 | Type type; 60 | 61 | /// 62 | /// The current x-position of the mouse, relative to the View 63 | /// 64 | int x; 65 | 66 | /// 67 | /// The current y-position of the mouse, relative to the View 68 | /// 69 | int y; 70 | 71 | /// 72 | /// The mouse button that was pressed/released, if any. 73 | /// 74 | Button button; 75 | }; 76 | 77 | } // namespace ultralight 78 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/RenderTarget.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file RenderTarget.h 3 | /// 4 | /// @brief The header for the RenderTarget struct. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ultralight { 20 | 21 | #pragma pack(push, 1) 22 | 23 | /// 24 | /// @brief Rendering details for a View, to be used with your own GPUDriver 25 | /// 26 | /// When using your own GPUDriver, each View is rendered to an offscreen 27 | /// texture that you must display on a quad in your engine. This struct 28 | /// provides all the details you need to render the View texture in your 29 | /// engine. 30 | /// 31 | struct UExport RenderTarget { 32 | /// 33 | /// Whether this target is empty (null texture) 34 | /// 35 | bool is_empty; 36 | 37 | /// 38 | /// The viewport width (in device coordinates). 39 | /// 40 | uint32_t width; 41 | 42 | /// 43 | /// The viewport height (in device coordinates). 44 | /// 45 | uint32_t height; 46 | 47 | /// 48 | /// The GPUDriver-specific texture ID (you should bind the texture using 49 | /// your implementation of GPUDriver::BindTexture before drawing a quad). 50 | /// 51 | uint32_t texture_id; 52 | 53 | /// 54 | /// The texture width (in pixels). This may be padded. 55 | /// 56 | uint32_t texture_width; 57 | 58 | /// 59 | /// The texture height (in pixels). This may be padded. 60 | /// 61 | uint32_t texture_height; 62 | 63 | /// 64 | /// The pixel format of the texture. 65 | /// 66 | BitmapFormat texture_format; 67 | 68 | /// 69 | /// UV coordinates of the texture (this is needed because the texture may 70 | /// be padded). 71 | /// 72 | Rect uv_coords; 73 | 74 | /// 75 | /// The GPUDriver-specific render buffer ID. 76 | /// 77 | uint32_t render_buffer_id; 78 | 79 | RenderTarget(); 80 | }; 81 | 82 | #pragma pack(pop) 83 | 84 | } // namespace ultralight 85 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/Renderer.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file Renderer.h 3 | /// 4 | /// @brief The header for the Renderer class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ultralight { 20 | 21 | /// 22 | /// @brief The core of Ultralight. You should initialize it after setting up 23 | /// your Platform config and drivers. 24 | /// 25 | /// This singleton class manages the lifetime of all Views (@see View) and 26 | /// coordinates all painting, rendering, network requests, and event dispatch. 27 | /// 28 | /// @note You don't have to create this instance directly if you use the 29 | /// AppCore API. The App class will automatically create a Renderer and 30 | /// perform all rendering within its run loop. @see App::Create 31 | /// 32 | class UExport Renderer : public RefCounted { 33 | public: 34 | /// 35 | /// Create the Renderer singleton. You should set up all your Platform config, 36 | /// file-system, and drivers before calling this function. @see Platform 37 | /// 38 | /// @note You should only create one Renderer per application lifetime. 39 | /// 40 | /// @return Returns a ref-pointer to a new Renderer instance. You should 41 | /// assign it to either a Ref (non-nullable) or 42 | /// RefPtr (nullable). 43 | /// 44 | static Ref Create(); 45 | 46 | /// 47 | /// Create a new View. 48 | /// 49 | /// @param width The initial width, in device coordinates. 50 | /// 51 | /// @param height The initial height, in device coordinates. 52 | /// 53 | /// @param transparent Whether or not the view background is transparent. 54 | /// 55 | /// @return Returns a ref-pointer to a new View instance. You should assign 56 | /// it to either a Ref (non-nullable) or RefPtr 57 | /// (nullable). 58 | /// 59 | /// @note The device coordinates are scaled to pixels by multiplying them 60 | /// with the current DPI scale (@see Config::device_scale_hint) and 61 | /// rounding to the nearest integer value. 62 | /// 63 | virtual Ref CreateView(uint32_t width, uint32_t height, 64 | bool transparent) = 0; 65 | 66 | /// 67 | /// Update timers and dispatch internal callbacks. You should call this often 68 | /// from your main application loop. 69 | /// 70 | virtual void Update() = 0; 71 | 72 | /// 73 | /// Render all active views to display lists and dispatch calls to GPUDriver. 74 | /// 75 | /// @note If you're using the default, offscreen GL driver, this updates the 76 | /// internal bitmap of each View (@see View::bitmap). 77 | /// 78 | virtual void Render() = 0; 79 | 80 | /// 81 | /// Attempt to release as much memory as possible. Don't call this from any 82 | /// callbacks or driver code. 83 | /// 84 | virtual void PurgeMemory() = 0; 85 | 86 | protected: 87 | virtual ~Renderer(); 88 | }; 89 | 90 | } // namespace ultralight 91 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/ScrollEvent.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file ScrollEvent.h 3 | /// 4 | /// @brief The header for the ScrollEvent class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | 17 | namespace ultralight { 18 | 19 | /// 20 | /// @brief A generic scroll event. 21 | /// 22 | /// @note @see View::FireScrollEvent 23 | /// 24 | class ScrollEvent { 25 | public: 26 | /// 27 | /// The scroll event granularity type 28 | /// 29 | enum Type { 30 | /// The delta value is interpreted as number of pixels 31 | kType_ScrollByPixel, 32 | 33 | /// The delta value is interpreted as number of pages 34 | kType_ScrollByPage, 35 | }; 36 | 37 | /// 38 | /// Scroll granularity type 39 | /// 40 | Type type; 41 | 42 | /// 43 | /// Horizontal scroll amount 44 | /// 45 | int delta_x; 46 | 47 | /// 48 | /// Vertical scroll amount 49 | /// 50 | int delta_y; 51 | }; 52 | 53 | } // namespace ultralight 54 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/String.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file String.h 3 | /// 4 | /// @brief The header for the String class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace ultralight { 21 | 22 | /// 23 | /// @brief UTF-16 String container with conversions for UTF-8 and UTF-32. 24 | /// 25 | /// @note Internally, all strings are represented as UTF-16. 26 | /// 27 | class UExport String { 28 | public: 29 | /// 30 | /// Create empty string 31 | /// 32 | String(); 33 | 34 | /// 35 | /// Create from null-terminated, ASCII C-string 36 | /// 37 | String(const char* str); 38 | 39 | /// 40 | /// Create from raw, UTF-8 string with certain length 41 | /// 42 | String(const char* str, size_t len); 43 | 44 | /// 45 | /// Create from existing String8 (UTF-8). 46 | /// 47 | String(const String8& str); 48 | 49 | /// 50 | /// Create from raw UTF-16 string with certain length 51 | /// 52 | String(const Char16* str, size_t len); 53 | 54 | /// 55 | /// Create from existing String16 (UTF-16) 56 | /// 57 | String(const String16& str); 58 | 59 | /// 60 | /// Create from existing String32 (UTF-32) 61 | /// 62 | String(const String32& str); 63 | 64 | /// 65 | /// Copy constructor 66 | /// 67 | String(const String& other); 68 | 69 | /// 70 | /// Destructor 71 | /// 72 | ~String(); 73 | 74 | /// 75 | /// Assign string from another, copy is made 76 | /// 77 | String& operator=(const String& other); 78 | 79 | /// 80 | /// Append string with another 81 | /// 82 | String& operator+=(const String& other); 83 | 84 | /// 85 | /// Concatenation operator 86 | /// 87 | inline friend String operator+(String lhs, const String& rhs) { lhs += rhs; return lhs; } 88 | 89 | /// 90 | /// Get native UTF-16 string 91 | /// 92 | String16& utf16() { return str_; } 93 | 94 | /// 95 | /// Get native UTF-16 string 96 | /// 97 | const String16& utf16() const { return str_; } 98 | 99 | /// 100 | /// Convert to UTF-8 string 101 | /// 102 | String8 utf8() const; 103 | 104 | /// 105 | /// Convert to UTF-32 string 106 | /// 107 | String32 utf32() const; 108 | 109 | /// 110 | /// Check if string is empty or not 111 | /// 112 | bool empty() const { return utf16().empty(); } 113 | 114 | private: 115 | String16 str_; 116 | }; 117 | 118 | 119 | } // namespace ultralight 120 | 121 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/String16.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file String16.h 3 | /// 4 | /// @brief The header for the String16 class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ultralight { 20 | 21 | namespace detail { 22 | template struct selector; 23 | template<> struct selector<4> { typedef char16_t Char16; }; 24 | template<> struct selector<2> { typedef wchar_t Char16; }; 25 | } 26 | 27 | #ifdef DISABLE_NATIVE_WCHAR_T 28 | // Force Char16 type to use char16_t, used on Windows when native wchar_t support is disabled. 29 | typedef char16_t Char16; 30 | #else 31 | // We use wchar_t if size == 2, otherwise use char16_t 32 | typedef detail::selector::Char16 Char16; 33 | #endif 34 | 35 | /// 36 | /// @brief A UTF-16 string container. 37 | /// 38 | class UExport String16 { 39 | public: 40 | // Make an empty String16 41 | String16(); 42 | 43 | // Make a String16 from null-terminated ASCII C-string 44 | String16(const char* c_str); 45 | 46 | // Make a String16 from ASCII C-string with certain length 47 | String16(const char* c_str, size_t len); 48 | 49 | // Make a String16 from raw UTF-16 buffer with certain length 50 | String16(const Char16* str, size_t len); 51 | 52 | // Make a String16 from raw unsigned short UTF-16 buffer with certain length. Useful on Windows 53 | // when native support for wchar_t is disabled (eg, /Zc:wchar_t-). 54 | String16(const unsigned short* str, size_t len); 55 | 56 | // Make a deep copy of String16 57 | String16(const String16& other); 58 | 59 | ~String16(); 60 | 61 | // Assign a String16 to this one, deep copy is made 62 | String16& operator=(const String16& other); 63 | 64 | // Append a String16 to this one. 65 | String16& operator+=(const String16& other); 66 | 67 | // Concatenation operator 68 | inline friend String16 operator+(String16 lhs, const String16& rhs) { lhs += rhs; return lhs; } 69 | 70 | // Get raw UTF-16 data 71 | Char16* data() { return data_; } 72 | 73 | // Get raw UTF-16 data (const) 74 | const Char16* data() const { return data_; } 75 | 76 | // Get raw UTF-16 data as unsigned short. This is useful on Windows if you compile without native 77 | // support for wchar_t (eg, /Zc:wchar_t-) 78 | unsigned short* udata() { return reinterpret_cast(data_); } 79 | 80 | // Get raw UTF-16 data as unsigned short (const). 81 | const unsigned short* udata() const { return reinterpret_cast(data_); } 82 | 83 | // Get length in characters. 84 | size_t length() const { return length_; } 85 | 86 | // Get size in characters (synonym for length) 87 | size_t size() const { return length_; } 88 | 89 | // Check if string is empty. 90 | bool empty() const { return !data_ || length_ == 0; } 91 | 92 | // Get character at specific position 93 | Char16& operator[](size_t pos) { return data_[pos]; } 94 | 95 | // Get character at specific position (const) 96 | const Char16& operator[](size_t pos) const { return data_[pos]; } 97 | 98 | private: 99 | Char16* data_; 100 | size_t length_; 101 | }; 102 | 103 | /// 104 | /// @brief A UTF-16 string vector. 105 | /// 106 | class UExport String16Vector : public RefCounted { 107 | public: 108 | // Create an empty string vector 109 | static Ref Create(); 110 | 111 | // Create a string vector from an existing array (a deep copy is made) 112 | static Ref Create(const String16* stringArray, size_t len); 113 | 114 | // Add an element to the back of the string vector 115 | virtual void push_back(const String16& val) = 0; 116 | 117 | // Get raw String16 vector array 118 | virtual String16* data() = 0; 119 | 120 | // Get the number of elements in vector 121 | virtual size_t size() const = 0; 122 | 123 | protected: 124 | String16Vector(); 125 | virtual ~String16Vector(); 126 | String16Vector(const String16Vector&); 127 | void operator=(const String16Vector&); 128 | }; 129 | 130 | } // namespace ultralight 131 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/String32.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file String32.h 3 | /// 4 | /// @brief The header for the String32 class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | 18 | namespace ultralight { 19 | 20 | /// 21 | /// @brief A UTF-32 string container. 22 | /// 23 | class UExport String32 { 24 | public: 25 | // Make an empty String32 26 | String32(); 27 | 28 | // Make a String32 from raw UTF-32 string with certain length 29 | String32(const char32_t* c_str, size_t len); 30 | 31 | // Make a deep copy of String32 32 | String32(const String32& other); 33 | 34 | ~String32(); 35 | 36 | // Assign a String32 to this one, deep copy is made 37 | String32& operator=(const String32& other); 38 | 39 | // Append a String32 to this one. 40 | String32& operator+=(const String32& other); 41 | 42 | // Concatenation operator 43 | inline friend String32 operator+(String32 lhs, const String32& rhs) { lhs += rhs; return lhs; } 44 | 45 | // Get raw UTF-32 data 46 | char32_t* data() { return data_; } 47 | 48 | // Get raw UTF-32 data (const) 49 | const char32_t* data() const { return data_; } 50 | 51 | // Get length in characters. 52 | size_t length() const { return length_; } 53 | 54 | // Get size in characters (synonym for length) 55 | size_t size() const { return length_; } 56 | 57 | // Check if string is empty. 58 | bool empty() const { return !data_ || length_ == 0; } 59 | 60 | // Get character at specific position 61 | char32_t& operator[](size_t pos) { return data_[pos]; } 62 | 63 | // Get character at specific position (const) 64 | const char32_t& operator[](size_t pos) const { return data_[pos]; } 65 | 66 | private: 67 | char32_t* data_; 68 | size_t length_; 69 | }; 70 | 71 | } // namespace ultralight 72 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/String8.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file String8.h 3 | /// 4 | /// @brief The header for the String8 class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | 18 | namespace ultralight { 19 | 20 | /// 21 | /// @brief A UTF-8 string container. 22 | // 23 | class UExport String8 { 24 | public: 25 | // Make an empty String8 26 | String8(); 27 | 28 | // Make a String8 from raw, null-terminated UTF-8 string 29 | String8(const char* c_str); 30 | 31 | // Make a String8 from raw UTF-8 string with certain length 32 | String8(const char* c_str, size_t len); 33 | 34 | // Make a deep copy of String8 35 | String8(const String8& other); 36 | 37 | ~String8(); 38 | 39 | // Assign a String8 to this one, deep copy is made 40 | String8& operator=(const String8& other); 41 | 42 | // Append a String8 to this one. 43 | String8& operator+=(const String8& other); 44 | 45 | // Concatenation operator 46 | inline friend String8 operator+(String8 lhs, const String8& rhs) { lhs += rhs; return lhs; } 47 | 48 | // Get raw UTF-8 data 49 | char* data() { return data_; } 50 | 51 | // Get raw UTF-8 data (const) 52 | const char* data() const { return data_; } 53 | 54 | // Get length in characters. 55 | size_t length() const { return length_; } 56 | 57 | // Get size in characters (synonym for length) 58 | size_t size() const { return length_; } 59 | 60 | // Check if string is empty. 61 | bool empty() const { return !data_ || length_ == 0; } 62 | 63 | // Get character at specific position 64 | char& operator[](size_t pos) { return data_[pos]; } 65 | 66 | // Get character at specific position (const) 67 | const char& operator[](size_t pos) const { return data_[pos]; } 68 | 69 | private: 70 | char* data_; 71 | size_t length_; 72 | }; 73 | 74 | } // namespace ultralight 75 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/Ultralight.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Ultralight, Inc. All rights reserved. 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/View.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file View.h 3 | /// 4 | /// @brief The header for the View class. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace ultralight { 26 | 27 | /// 28 | /// @brief A View is similar to a tab in a browser-- you load web content into 29 | /// it and display it however you want. @see Renderer::CreateView 30 | /// 31 | /// @note The API is currently not thread-safe, all calls must be made on the 32 | /// main thread. 33 | /// 34 | class UExport View : public RefCounted { 35 | public: 36 | /// 37 | /// Get the URL of the current page loaded into this View, if any. 38 | /// 39 | virtual String url() = 0; 40 | 41 | /// 42 | /// Get the title of the current page loaded into this View, if any. 43 | /// 44 | virtual String title() = 0; 45 | 46 | /// 47 | /// Get the width of the View, in device coordinates. 48 | /// 49 | virtual uint32_t width() const = 0; 50 | 51 | /// 52 | /// Get the height of the View, in device coordinates. 53 | /// 54 | virtual uint32_t height() const = 0; 55 | 56 | /// 57 | /// Check if the main frame of the page is currently loading. 58 | /// 59 | virtual bool is_loading() = 0; 60 | 61 | /// 62 | /// Get the RenderTarget for the View. 63 | /// 64 | /// @note The RenderTarget is only used when you define a custom GPUDriver. 65 | /// 66 | /// During each call to Renderer::Render, each View will be drawn to 67 | /// an offscreen texture/render-buffer. You should use RenderTarget 68 | /// to obtain the internal texture ID for the View and then display 69 | /// it in some quad (eg, call GPUDriver::BindTexture with the texture 70 | /// ID, then draw a textured quad in your 3D engine, making sure to 71 | /// use the UV coords specified in the RenderTarget). 72 | /// 73 | /// @see Overlay.cpp within the AppCore source for an example. 74 | /// 75 | virtual RenderTarget render_target() = 0; 76 | 77 | /// 78 | /// Check if bitmap is dirty (has changed since last call to View::bitmap) 79 | /// 80 | /// @note Only valid when using the default, offscreen GPUDriver. 81 | /// 82 | virtual bool is_bitmap_dirty() = 0; 83 | 84 | /// 85 | /// Get the bitmap for the View (calling this resets the dirty state). 86 | /// 87 | // @note Only valid when using the default, offscreen GPUDriver. 88 | /// 89 | virtual RefPtr bitmap() = 0; 90 | 91 | /// 92 | /// Load a raw string of HTML, the View will navigate to it as a new page. 93 | /// 94 | virtual void LoadHTML(const String& html) = 0; 95 | 96 | /// 97 | /// Load a URL, the View will navigate to it as a new page. 98 | /// 99 | /// @note You can use File URLs (eg, file:///page.html) but you must define 100 | /// your own FileSystem implementation. @see Platform::set_file_system 101 | /// 102 | virtual void LoadURL(const String& url) = 0; 103 | 104 | /// 105 | /// Resize View to a certain size. 106 | /// 107 | /// @param width The initial width, in device coordinates. 108 | /// 109 | /// @param height The initial height, in device coordinates. 110 | /// 111 | /// @note The device coordinates are scaled to pixels by multiplying them 112 | /// with the current DPI scale (@see Config::device_scale_hint) and 113 | /// rounding to the nearest integer value. 114 | /// 115 | virtual void Resize(uint32_t width, uint32_t height) = 0; 116 | 117 | /// 118 | /// Get the page's JSContext for use with the JavaScriptCore API 119 | /// 120 | /// @note We expose the entire JavaScriptCore API to users for maximum 121 | /// flexibility. Each page has its own JSContext that gets reset 122 | /// after each page navigation. You should make all your initial 123 | /// JavaScript calls to the page within the DOMReady event, 124 | /// @see ViewListener::OnDOMReady 125 | /// 126 | virtual JSContextRef js_context() = 0; 127 | 128 | /// 129 | /// Evaluate a raw string of JavaScript and return results as a native 130 | /// JavaScriptCore JSValueRef (@see ) 131 | /// 132 | /// @note This is just a wrapper for JSEvaluateScript() in JavaScriptCore 133 | /// 134 | virtual JSValueRef EvaluateScript(const String& script) = 0; 135 | 136 | /// 137 | /// Whether or not we can navigate backwards in history 138 | /// 139 | virtual bool CanGoBack() = 0; 140 | 141 | /// 142 | /// Whether or not we can navigate forwards in history 143 | /// 144 | virtual bool CanGoForward() = 0; 145 | 146 | /// 147 | /// Navigate backwards in history 148 | /// 149 | virtual void GoBack() = 0; 150 | 151 | /// 152 | /// Navigate forwards in history 153 | /// 154 | virtual void GoForward() = 0; 155 | 156 | /// 157 | /// Navigate to an arbitrary offset in history 158 | /// 159 | virtual void GoToHistoryOffset(int offset) = 0; 160 | 161 | /// 162 | /// Reload current page 163 | /// 164 | virtual void Reload() = 0; 165 | 166 | /// 167 | /// Stop all page loads 168 | /// 169 | virtual void Stop() = 0; 170 | 171 | /// 172 | /// Fire a keyboard event 173 | /// 174 | /// @note Only 'Char' events actually generate text in input fields. 175 | /// 176 | virtual void FireKeyEvent(const KeyEvent& evt) = 0; 177 | 178 | /// 179 | /// Fire a mouse event 180 | /// 181 | virtual void FireMouseEvent(const MouseEvent& evt) = 0; 182 | 183 | /// 184 | /// Fire a scroll event 185 | /// 186 | virtual void FireScrollEvent(const ScrollEvent& evt) = 0; 187 | 188 | /// 189 | /// Set a ViewListener to receive callbacks for View-related events. 190 | /// 191 | /// @note Ownership remains with the caller. 192 | /// 193 | virtual void set_view_listener(ViewListener* listener) = 0; 194 | 195 | /// 196 | /// Get the active ViewListener, if any 197 | /// 198 | virtual ViewListener* view_listener() const = 0; 199 | 200 | /// 201 | /// Set a LoadListener to receive callbacks for Load-related events. 202 | /// 203 | /// @note Ownership remains with the caller. 204 | /// 205 | virtual void set_load_listener(LoadListener* listener) = 0; 206 | 207 | /// 208 | /// Get the active LoadListener, if any 209 | /// 210 | virtual LoadListener* load_listener() const = 0; 211 | 212 | /// 213 | /// Set whether or not this View should be repainted during the next 214 | /// call to Renderer::Render 215 | /// 216 | /// @note This flag is automatically set whenever the page content changes 217 | /// but you can set it directly in case you need to force a repaint. 218 | /// 219 | virtual void set_needs_paint(bool needs_paint) = 0; 220 | 221 | /// 222 | /// Whether or not this View should be repainted during the next call to 223 | /// Renderer::Render. 224 | /// 225 | virtual bool needs_paint() const = 0; 226 | 227 | /// 228 | /// Get the inspector for this View, this is useful for debugging and 229 | /// inspecting pages locally. This will only succeed if you have the 230 | /// inspector assets in your filesystem-- the inspector will look for 231 | /// file:///inspector/Main.html when it first loads. 232 | /// 233 | /// @note The inspector View is owned by the View and lazily-created on 234 | /// first call. The initial dimensions are 10x10, you should call 235 | /// View::Resize() on the returned View to resize it to your desired 236 | /// dimensions. 237 | /// 238 | virtual RefPtr inspector() = 0; 239 | 240 | protected: 241 | virtual ~View(); 242 | }; 243 | 244 | } // namespace ultralight 245 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/platform/Config.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file Config.h 3 | /// 4 | /// @brief The header for the Config struct. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | 18 | namespace ultralight { 19 | 20 | /// 21 | /// The winding order for front-facing triangles. 22 | /// 23 | /// @note In most 3D engines, there is the concept that triangles have a 24 | /// a "front" and a "back". All the front-facing triangles (eg, those 25 | /// that are facing the camera) are rendered, and all back-facing 26 | /// triangles are culled (ignored). The winding-order of the triangle's 27 | /// vertices is used to determine which side is front and back. You 28 | /// should tell Ultralight which winding-order your 3D engine uses. 29 | /// 30 | enum FaceWinding { 31 | /// 32 | /// Clockwise Winding (Direct3D, etc.) 33 | /// 34 | kFaceWinding_Clockwise, 35 | 36 | /// 37 | /// Counter-Clockwise Winding (OpenGL, etc.) 38 | /// 39 | kFaceWinding_CounterClockwise, 40 | }; 41 | 42 | /// 43 | /// @brief Configurations settings for Ultralight. 44 | /// 45 | /// This is intended to be implemented by users and defined before creating the 46 | /// Renderer. @see Platform::set_config. 47 | /// 48 | struct UExport Config { 49 | /// 50 | /// The winding order for front-facing triangles. @see FaceWinding 51 | /// 52 | FaceWinding face_winding = kFaceWinding_CounterClockwise; 53 | 54 | /// 55 | /// Whether or not images should be enabled. 56 | /// 57 | bool enable_images = true; 58 | 59 | /// 60 | /// Whether or not JavaScript should be enabled. 61 | /// 62 | bool enable_javascript = true; 63 | 64 | /// 65 | /// When using the default, offscreen GPU driver, whether or not we 66 | /// should use BGRA byte order (instead of RGBA). @see View::bitmap 67 | /// 68 | bool use_bgra_for_offscreen_rendering = false; 69 | 70 | /// 71 | /// The amount that the application DPI has been scaled (200% = 2.0). 72 | /// Used for scaling device coordinates to pixels and oversampling raster 73 | /// shapes. 74 | /// 75 | double device_scale_hint = 1.0; 76 | 77 | /// 78 | /// Default font-family to use. 79 | /// 80 | String16 font_family_standard = "Times New Roman"; 81 | 82 | /// 83 | /// Default font-family to use for fixed fonts. (pre/code) 84 | /// 85 | String16 font_family_fixed = "Courier New"; 86 | 87 | /// 88 | /// Default font-family to use for serif fonts. 89 | /// 90 | String16 font_family_serif = "Times New Roman"; 91 | 92 | /// 93 | /// Default font-family to use for sans-serif fonts. 94 | /// 95 | String16 font_family_sans_serif = "Arial"; 96 | 97 | /// 98 | /// Default user-agent string. 99 | /// 100 | String16 user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " 101 | "AppleWebKit/602.1 (KHTML, like Gecko) " 102 | "Ultralight/0.9.2 Safari/602.1"; 103 | 104 | /// 105 | /// Default user stylesheet. You should set this to your own custom CSS 106 | /// string to define default styles for various DOM elements, scrollbars, 107 | /// and platform input widgets. 108 | /// 109 | String16 user_stylesheet; 110 | 111 | /// 112 | /// Whether or not we should continuously repaint any Views or compositor 113 | /// layers, regardless if they are dirty or not. This is mainly used to 114 | /// diagnose painting/shader issues. 115 | /// 116 | bool force_repaint = false; 117 | 118 | /// 119 | /// When a CSS animation is active, the amount of time to wait before 120 | /// triggering another repaint. 121 | /// 122 | double animation_timer_delay = 1.0 / 60.0; 123 | 124 | /// 125 | /// Size of WebCore's memory cache in bytes. 126 | /// 127 | /// @note You should increase this if you anticipate handling pages with 128 | /// large resources, Safari typically uses 128+ MiB for its cache. 129 | /// 130 | uint32_t memory_cache_size = 64 * 1024 * 1024; 131 | 132 | /// 133 | /// Number of pages to keep in the cache. Defaults to 0 (none). 134 | /// 135 | /// @note Safari typically caches about 5 pages and maintains an on-disk 136 | /// cache to support typical web-browsing activities. If you increase 137 | /// this, you should probably increase the memory cache size as well. 138 | /// 139 | uint32_t page_cache_size = 0; 140 | }; 141 | 142 | } // namespace ultralight 143 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/platform/FileSystem.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file FileSystem.h 3 | /// 4 | /// @brief The header for the FileSystem interface. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ultralight { 20 | 21 | /// 22 | /// File Handle type used as unique ID for opened files. 23 | /// 24 | #if defined(__WIN32__) || defined(_WIN32) 25 | typedef size_t FileHandle; 26 | #else 27 | typedef int FileHandle; 28 | #endif 29 | 30 | /// 31 | /// Handle used to denote an invalid file. 32 | /// 33 | const FileHandle invalidFileHandle = (FileHandle)-1; 34 | 35 | /// 36 | /// The position to seek from in a file, @see FileSystem::SeekFile 37 | /// 38 | enum FileSeekOrigin { 39 | kFileSeekOrigin_Beginning = 0, 40 | kFileSeekOrigin_Current, 41 | kFileSeekOrigin_End 42 | }; 43 | 44 | /// 45 | /// The type of path, @see FileSystem::GetMetadata 46 | /// 47 | enum MetadataType { 48 | kMetadataType_Unknown = 0, 49 | kMetadataType_File, 50 | kMetadataType_Directory, 51 | }; 52 | 53 | /// 54 | /// @brief FileSystem interface, used for all file system operations. 55 | /// 56 | /// This is used for things like loading File URLs (eg, and 57 | /// the JavaScript FileSystem API. If you don't implement this interface, you 58 | /// will not be able to load any File URLs. 59 | /// 60 | /// 61 | /// This is intended to be implemented by users and defined before creating the 62 | /// Renderer. @see Platform::set_file_system. 63 | /// 64 | /// @note To support File URL loading, you ONLY need to implement the 65 | /// following functions: 66 | /// - FileSystem::FileExists 67 | /// - FileSystem::GetFileSize 68 | /// - FileSystem::GetFileMimeType 69 | /// - FileSystem::OpenFile 70 | /// - FileSystem::ReadFromFile 71 | /// - FileSystem::CloseFile 72 | /// 73 | class UExport FileSystem { 74 | public: 75 | virtual ~FileSystem(); 76 | 77 | /// 78 | /// Check if file path exists, return true if exists. 79 | /// 80 | virtual bool FileExists(const String16& path) = 0; 81 | 82 | /// 83 | /// Delete file, return true on success. 84 | /// 85 | virtual bool DeleteFile_(const String16& path) = 0; 86 | 87 | /// 88 | /// Delete empty directory, return true on success. 89 | /// 90 | virtual bool DeleteEmptyDirectory(const String16& path) = 0; 91 | 92 | /// 93 | /// Move file, return true on success. 94 | /// 95 | virtual bool MoveFile_(const String16& old_path, const String16& new_path) = 0; 96 | 97 | /// 98 | /// Get file size, store result in 'result'. Return true on success. 99 | /// 100 | virtual bool GetFileSize(const String16& path, int64_t& result) = 0; 101 | 102 | /// 103 | /// Get file size of previously opened file, store result in 'result'. Return true on success. 104 | /// 105 | virtual bool GetFileSize(FileHandle handle, int64_t& result) = 0; 106 | 107 | /// 108 | /// Get file mime type (eg "text/html"), store result in 'result'. Return true on success. 109 | /// 110 | virtual bool GetFileMimeType(const String16& path, String16& result) = 0; 111 | 112 | /// 113 | /// Get file last modification time, store result in 'result'. Return true on success. 114 | /// 115 | virtual bool GetFileModificationTime(const String16& path, time_t& result) = 0; 116 | 117 | /// 118 | /// Get file creation time, store result in 'result'. Return true on success. 119 | /// 120 | virtual bool GetFileCreationTime(const String16& path, time_t& result) = 0; 121 | 122 | /// 123 | /// Get path type (file or directory). 124 | /// 125 | virtual MetadataType GetMetadataType(const String16& path) = 0; 126 | 127 | /// 128 | /// Concatenate path with another path component. Return concatenated result. 129 | /// 130 | virtual String16 GetPathByAppendingComponent(const String16& path, const String16& component) = 0; 131 | 132 | /// 133 | /// Create directory, return true on success. 134 | /// 135 | virtual bool CreateDirectory_(const String16& path) = 0; 136 | 137 | /// 138 | /// Get home directory path. 139 | /// 140 | virtual String16 GetHomeDirectory() = 0; 141 | 142 | /// 143 | /// Get filename component from path. 144 | /// 145 | virtual String16 GetFilenameFromPath(const String16& path) = 0; 146 | 147 | /// 148 | /// Get directory name from path. 149 | /// 150 | virtual String16 GetDirectoryNameFromPath(const String16& path) = 0; 151 | 152 | /// 153 | /// Get volume from path and store free space in 'result'. Return true on success. 154 | /// 155 | virtual bool GetVolumeFreeSpace(const String16& path, uint64_t& result) = 0; 156 | 157 | /// 158 | /// Get volume from path and return its unique volume id. 159 | /// 160 | virtual int32_t GetVolumeId(const String16& path) = 0; 161 | 162 | /// 163 | /// Get file listing for directory path with optional filter, return vector of file paths. 164 | /// 165 | virtual Ref ListDirectory(const String16& path, const String16& filter) = 0; 166 | 167 | /// 168 | /// Open a temporary file with suggested prefix, store handle in 'handle'. Return path of temporary file. 169 | /// 170 | virtual String16 OpenTemporaryFile(const String16& prefix, FileHandle& handle) = 0; 171 | 172 | /// 173 | /// Open file path for reading or writing. Return file handle on success, or invalidFileHandle on failure. 174 | /// 175 | virtual FileHandle OpenFile(const String16& path, bool open_for_writing) = 0; 176 | 177 | /// 178 | /// Close previously-opened file. 179 | /// 180 | virtual void CloseFile(FileHandle& handle) = 0; 181 | 182 | /// 183 | /// Seek currently-opened file, with offset relative to certain origin. Return new file offset. 184 | /// 185 | virtual int64_t SeekFile(FileHandle handle, int64_t offset, FileSeekOrigin origin) = 0; 186 | 187 | /// 188 | /// Truncate currently-opened file with offset, return true on success. 189 | /// 190 | virtual bool TruncateFile(FileHandle handle, int64_t offset) = 0; 191 | 192 | /// 193 | /// Write to currently-opened file, return number of bytes written or -1 on failure. 194 | /// 195 | virtual int64_t WriteToFile(FileHandle handle, const char* data, int64_t length) = 0; 196 | 197 | /// 198 | /// Read from currently-opened file, return number of bytes read or -1 on failure. 199 | /// 200 | virtual int64_t ReadFromFile(FileHandle handle, char* data, int64_t length) = 0; 201 | 202 | /// 203 | /// Copy file from source to destination, return true on success. 204 | /// 205 | virtual bool CopyFile_(const String16& source_path, const String16& destination_path) = 0; 206 | }; 207 | 208 | } // namespace ultralight 209 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/platform/FontLoader.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file FontLoader.h 3 | /// 4 | /// @brief The header for the FontLoader interface. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ultralight { 20 | 21 | /// 22 | /// @brief Font Loader interface, used for all font lookup operations. 23 | /// 24 | /// Every operating system has its own library of installed system fonts. The 25 | /// FontLoader interface is used to lookup these fonts and fetch the actual 26 | /// font data (raw TTF/OTF file data) given a certain font description. 27 | /// 28 | /// You can override this interface to bundle your own fonts or override the 29 | /// default system font loading behavior. 30 | /// 31 | /// This is intended to be implemented by users and defined before creating the 32 | /// Renderer. @see Platform::set_font_loader 33 | /// 34 | class UExport FontLoader { 35 | public: 36 | virtual ~FontLoader(); 37 | 38 | /// 39 | /// Fallback font family name. Will be used if all other fonts fail to load. 40 | /// 41 | /// @note This font should be GUARANTEED to exist (eg, FontLoader::Load 42 | /// won't fail when passed this font family name). 43 | /// 44 | virtual String16 fallback_font() const = 0; 45 | 46 | /// 47 | /// Fallback font family name that can render the specified characters. This 48 | /// is mainly used to support CJK (Chinese, Japanese, Korean) text display. 49 | /// 50 | /// @param characters One or more UTF-16 characters. This is almost ALWAYS 51 | /// a single character. 52 | /// 53 | /// @param weight Font weight. 54 | /// 55 | /// @param italic Whether or not italic is requested. 56 | /// 57 | /// @param size Font size. 58 | /// 59 | /// @return Should return a font family name that can render the text. 60 | /// 61 | virtual String16 fallback_font_for_characters(const String16& characters, 62 | int weight, bool italic, 63 | float size) const = 0; 64 | 65 | /// 66 | /// Get the actual font file data (TTF/OTF) for a given font description. 67 | /// 68 | /// @param family Font family name. 69 | /// 70 | /// @param weight Font weight. 71 | /// 72 | /// @param italic Whether or not italic is requested. 73 | /// 74 | /// @param size Font size. 75 | /// 76 | /// @return A buffer of bytes containing raw font file contents of the 77 | /// font matching the given description. 78 | /// 79 | /// @note As an example of usage, when given the family "Arial", this 80 | /// function should return the raw file contents for "ARIAL.TTF" 81 | /// 82 | virtual Ref Load(const String16& family, int weight, bool italic, 83 | float size) = 0; 84 | }; 85 | 86 | } // namespace ultralight 87 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/platform/GPUDriver.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file GPUDriver.h 3 | /// 4 | /// @brief The header for the GPUDriver interface. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #pragma warning(disable: 4251) 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace ultralight { 22 | 23 | /// 24 | /// @note This pragma pack(push, 1) command is important! Vertex layouts 25 | /// should not be padded with any bytes. 26 | /// 27 | #pragma pack(push, 1) 28 | 29 | /// 30 | /// RenderBuffer description, @see GPUDriver::CreateRenderBuffer. 31 | /// 32 | struct UExport RenderBuffer { 33 | uint32_t texture_id; // The backing texture for this RenderBuffer 34 | uint32_t width; // The width of the RenderBuffer texture 35 | uint32_t height; // The height of the RenderBuffer texture 36 | bool has_stencil_buffer; // Currently unused, always false. 37 | bool has_depth_buffer; // Currently unsued, always false. 38 | }; 39 | 40 | /// 41 | /// Vertex layout for path vertices, useful for synthesizing or modifying 42 | /// vertex data. 43 | /// 44 | struct Vertex_2f_4ub_2f { 45 | float pos[2]; 46 | unsigned char color[4]; 47 | float obj[2]; 48 | }; 49 | 50 | /// 51 | /// Vertex layout for quad vertices, useful for synthesizing or modifying 52 | /// vertex data. 53 | /// 54 | struct Vertex_2f_4ub_2f_2f_28f { 55 | float pos[2]; 56 | unsigned char color[4]; 57 | float tex[2]; 58 | float obj[2]; 59 | float data0[4]; 60 | float data1[4]; 61 | float data2[4]; 62 | float data3[4]; 63 | float data4[4]; 64 | float data5[4]; 65 | float data6[4]; 66 | }; 67 | 68 | /// 69 | /// Vertex formats 70 | /// 71 | enum UExport VertexBufferFormat { 72 | kVertexBufferFormat_2f_4ub_2f, 73 | kVertexBufferFormat_2f_4ub_2f_2f_28f, 74 | }; 75 | 76 | /// 77 | /// Vertex buffer, @see GPUDriver::CreateGeometry 78 | /// 79 | struct UExport VertexBuffer { 80 | VertexBufferFormat format; 81 | uint32_t size; 82 | uint8_t* data; 83 | }; 84 | 85 | /// 86 | /// Vertex index type 87 | /// 88 | typedef uint32_t IndexType; 89 | 90 | /// 91 | /// Vertex index buffer, @see GPUDriver::CreateGeometry 92 | /// 93 | struct UExport IndexBuffer { 94 | uint32_t size; 95 | uint8_t* data; 96 | }; 97 | 98 | /// 99 | /// Shader types, used by GPUState::shader_type 100 | /// 101 | /// Each of these correspond to a vertex/pixel shader pair. You can find 102 | /// stock shader code for these in the `shaders` folder of the AppCore repo. 103 | /// 104 | enum UExport ShaderType { 105 | kShaderType_Fill, // Shader program for quad geometry 106 | kShaderType_FillPath, // Shader program for path geometry 107 | }; 108 | 109 | /// 110 | /// GPU state description. 111 | /// 112 | struct UExport GPUState { 113 | /// Viewport width in logical units (multiply by device scale to get pixels). 114 | float viewport_width; 115 | 116 | /// Viewport height in logical units (multiply by device scale to get pixels). 117 | float viewport_height; 118 | 119 | /// Transform matrix-- you should multiply this with the screen-space 120 | /// orthographic projection matrix then pass to the vertex shader. 121 | Matrix4x4 transform; 122 | 123 | /// Whether or not we should enable texturing for the current draw command. 124 | bool enable_texturing; 125 | 126 | /// Whether or not we should enable blending for the current draw command. 127 | /// If blending is disabled, any drawn pixels should overwrite existing. 128 | /// Mainly used so we can modify alpha values of the RenderBuffer during 129 | /// scissored clears. 130 | bool enable_blend; 131 | 132 | /// The vertex/pixel shader program pair to use for the current draw command. 133 | /// You should cast this to ShaderType to get the corresponding enum. 134 | uint8_t shader_type; 135 | 136 | /// The render buffer to use for the current draw command. 137 | uint32_t render_buffer_id; 138 | 139 | /// The texture id to bind to slot #1. (Will be 0 if none) 140 | uint32_t texture_1_id; 141 | 142 | /// The texture id to bind to slot #2. (Will be 0 if none) 143 | uint32_t texture_2_id; 144 | 145 | /// The texture id to bind to slot #3. (Will be 0 if none) 146 | uint32_t texture_3_id; 147 | 148 | /// The following four members are passed to the pixel shader via uniforms. 149 | float uniform_scalar[8]; 150 | vec4 uniform_vector[8]; 151 | uint8_t clip_size; 152 | Matrix4x4 clip[8]; 153 | 154 | /// Whether or not scissor testing should be used for the current draw command. 155 | bool enable_scissor; 156 | 157 | /// The scissor rect to use for scissor testing (in logical units, you should 158 | /// multiply by device scale to get pixel units). 159 | Rect scissor_rect; 160 | }; 161 | 162 | /// 163 | /// Command types, used by Command::command_type 164 | /// 165 | enum UExport CommandType { 166 | kCommandType_ClearRenderBuffer, // Corresponds to ClearRenderBuffer() 167 | kCommandType_DrawGeometry, // Corresponds to DrawGeometry() 168 | }; 169 | 170 | /// 171 | /// Command description, handling one of these should result in either a call to 172 | /// GPUDriver::ClearRenderBuffer or GPUDriver::DrawGeometry. 173 | /// 174 | struct UExport Command { 175 | uint8_t command_type; // The type of command to dispatch. 176 | GPUState gpu_state; // GPU state parameters for current command. 177 | uint32_t geometry_id; // Used with DrawGeometry, the geometry ID to bind. 178 | uint32_t indices_count; // Used with DrawGeometry, the number of indices. 179 | uint32_t indices_offset; // Used with DrawGeometry, the index to start from. 180 | }; 181 | 182 | /// 183 | /// Command list, @see GPUDriver::UpdateCommandList 184 | /// 185 | struct UExport CommandList { 186 | uint32_t size; 187 | Command* commands; 188 | }; 189 | 190 | #pragma pack(pop) 191 | 192 | /// 193 | /// @brief GPUDriver interface, dispatches GPU calls to the native driver. 194 | /// 195 | /// By default, Ultralight uses an offscreen, OpenGL GPUDriver that draws each 196 | /// View to an offscreen Bitmap (@see View::bitmap). You can override this to 197 | /// provide your own GPUDriver and integrate directly with your own 3D engine. 198 | /// 199 | /// This is intended to be implemented by users and defined before creating the 200 | /// Renderer. @see Platform::set_gpu_driver 201 | /// 202 | class UExport GPUDriver { 203 | public: 204 | virtual ~GPUDriver(); 205 | 206 | /// 207 | /// Called before any commands are dispatched during a frame. 208 | /// 209 | virtual void BeginSynchronize() = 0; 210 | 211 | /// 212 | /// Called after any commands are dispatched during a frame. 213 | /// 214 | virtual void EndSynchronize() = 0; 215 | 216 | /// 217 | /// Get the next available texture ID. 218 | /// 219 | virtual uint32_t NextTextureId() = 0; 220 | 221 | /// 222 | /// Create a texture with a certain ID and optional bitmap. 223 | /// 224 | /// **NOTE**: If the Bitmap is empty (Bitmap::IsEmpty), then a RTT Texture 225 | /// should be created instead. This will be used as a backing 226 | /// texture for a new RenderBuffer. 227 | /// 228 | virtual void CreateTexture(uint32_t texture_id, 229 | Ref bitmap) = 0; 230 | 231 | /// 232 | /// Update an existing non-RTT texture with new bitmap data. 233 | /// 234 | virtual void UpdateTexture(uint32_t texture_id, 235 | Ref bitmap) = 0; 236 | 237 | /// 238 | /// Bind a texture to a certain texture unit. 239 | /// 240 | /// **NOTE**: This is not called directly by Ultralight-- you are expected to 241 | /// call this from your own implementation during drawing. 242 | /// 243 | virtual void BindTexture(uint8_t texture_unit, 244 | uint32_t texture_id) = 0; 245 | 246 | /// 247 | /// Destroy a texture. 248 | /// 249 | virtual void DestroyTexture(uint32_t texture_id) = 0; 250 | 251 | /// 252 | /// Generate the next available render buffer ID. 253 | /// 254 | virtual uint32_t NextRenderBufferId() = 0; 255 | 256 | /// 257 | /// Create a render buffer with certain ID and buffer description. 258 | /// 259 | virtual void CreateRenderBuffer(uint32_t render_buffer_id, 260 | const RenderBuffer& buffer) = 0; 261 | 262 | /// 263 | /// Bind a render buffer. 264 | /// 265 | /// **NOTE**: This is not called directly by Ultralight-- you are expected to 266 | /// call this from your own implementation during drawing. 267 | /// 268 | virtual void BindRenderBuffer(uint32_t render_buffer_id) = 0; 269 | 270 | /// 271 | /// Clear a render buffer (flush pixels to 0). 272 | /// 273 | /// **NOTE**: This is not called directly by Ultralight-- you are expected to 274 | /// call this from your own implementation during drawing. 275 | /// 276 | virtual void ClearRenderBuffer(uint32_t render_buffer_id) = 0; 277 | 278 | /// 279 | /// Destroy a render buffer 280 | /// 281 | virtual void DestroyRenderBuffer(uint32_t render_buffer_id) = 0; 282 | 283 | /// 284 | /// Generate the next available geometry ID. 285 | /// 286 | virtual uint32_t NextGeometryId() = 0; 287 | 288 | /// 289 | /// Create geometry with certain ID and vertex/index data. 290 | /// 291 | virtual void CreateGeometry(uint32_t geometry_id, 292 | const VertexBuffer& vertices, 293 | const IndexBuffer& indices) = 0; 294 | 295 | /// 296 | /// Update existing geometry with new vertex/index data. 297 | /// 298 | virtual void UpdateGeometry(uint32_t geometry_id, 299 | const VertexBuffer& vertices, 300 | const IndexBuffer& indices) = 0; 301 | 302 | /// 303 | /// Draw geometry using the specific index count/offset and GPUState. 304 | /// 305 | virtual void DrawGeometry(uint32_t geometry_id, 306 | uint32_t indices_count, 307 | uint32_t indices_offset, 308 | const GPUState& state) = 0; 309 | 310 | /// 311 | /// Destroy geometry. 312 | /// 313 | virtual void DestroyGeometry(uint32_t geometry_id) = 0; 314 | 315 | /// 316 | /// Update command list (you should copy the commands to your own structure). 317 | /// 318 | virtual void UpdateCommandList(const CommandList& list) = 0; 319 | 320 | /// 321 | /// Check if any commands need drawing. 322 | /// 323 | virtual bool HasCommandsPending() = 0; 324 | 325 | /// 326 | /// Iterate through the current command list and dispatch commands. The list 327 | /// should be cleared at the end of this operation. 328 | /// 329 | /// **NOTE**: This is not called directly by Ultralight-- you are expected to 330 | /// call this from your own implementation during drawing. 331 | /// 332 | virtual void DrawCommandList() = 0; 333 | }; 334 | 335 | } // namespace ultralight 336 | -------------------------------------------------------------------------------- /cpplibs/include/Ultralight/platform/Platform.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// @file Platform.h 3 | /// 4 | /// @brief The header for the Platform singleton. 5 | /// 6 | /// @author 7 | /// 8 | /// This file is a part of Ultralight, a fast, lightweight, HTML UI engine 9 | /// 10 | /// Website: 11 | /// 12 | /// Copyright (C) 2019 Ultralight, Inc. All rights reserved. 13 | /// 14 | #pragma once 15 | #include 16 | 17 | namespace ultralight { 18 | 19 | struct Config; 20 | class GPUDriver; 21 | class FontLoader; 22 | class FileSystem; 23 | 24 | /// 25 | /// @brief Platform singleton to configure Ultralight and provide user-defined 26 | /// implementations for various platform operations. 27 | /// 28 | /// @note All of these settings and user-defined interfaces should be set 29 | /// BEFORE creating the Renderer. 30 | /// 31 | /// A default GPUDriver and FontLoader are provided, you must provide 32 | /// your own FileSystem interface if you want to load local files. 33 | /// 34 | /// For more info about the defaults @see DefaultGPUDriver and 35 | /// @see DefaultFontLoader. 36 | /// 37 | class UExport Platform { 38 | public: 39 | /// 40 | /// Get the Platform singleton 41 | /// 42 | static Platform& instance(); 43 | 44 | virtual ~Platform(); 45 | 46 | /// 47 | /// Set the Config 48 | /// 49 | virtual void set_config(const Config& config) = 0; 50 | 51 | /// 52 | /// Get the Config 53 | /// 54 | virtual const Config& config() const = 0; 55 | 56 | /// 57 | /// Set the GPU Driver (will handle all rendering) 58 | /// 59 | /// @param gpu_driver A user-defined GPUDriver implementation, ownership 60 | /// remains with the caller. 61 | /// 62 | /// @note If you never call this, the default driver will be used instead. 63 | /// @see DefaultGPUDriver 64 | /// 65 | virtual void set_gpu_driver(GPUDriver* gpu_driver) = 0; 66 | 67 | /// 68 | /// Get the GPU Driver 69 | /// 70 | virtual GPUDriver* gpu_driver() const = 0; 71 | 72 | /// 73 | /// Set the Font Loader (will be used to map font families to actual fonts) 74 | /// 75 | /// @param font_loader A user-defined FontLoader implementation, ownership 76 | /// remains with the caller. 77 | /// 78 | /// @note If you never call this, the default font loader will be used 79 | /// instead. @see DefaultFontLoader 80 | /// 81 | virtual void set_font_loader(FontLoader* font_loader) = 0; 82 | 83 | /// 84 | /// Get the Font Loader 85 | /// 86 | virtual FontLoader* font_loader() const = 0; 87 | 88 | /// 89 | /// Set the File System (will be used for all file system operations) 90 | /// 91 | /// @param file_system A user-defined FileSystem implementation, ownership 92 | /// remains with the caller. 93 | /// 94 | virtual void set_file_system(FileSystem* file_system) = 0; 95 | 96 | /// 97 | /// Get the File System 98 | /// 99 | virtual FileSystem* file_system() const = 0; 100 | }; 101 | 102 | /// 103 | /// The default GPU driver is an OpenGL driver that paints each View to an 104 | /// offscreen bitmap (@see View::bitmap). This is lazily-initialized. 105 | /// 106 | UExport GPUDriver* DefaultGPUDriver(); 107 | 108 | /// 109 | /// The default Font Loader uses the native font loader API for the platform. 110 | /// 111 | /// @note Windows and macOS font loading is implemented but Linux is still in 112 | /// progress-- currently just loads an embedded Roboto font. 113 | /// 114 | UExport FontLoader* DefaultFontLoader(); 115 | 116 | } // namespace ultralight 117 | -------------------------------------------------------------------------------- /cpplibs/linux/libUltralight.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/linux/libUltralight.so -------------------------------------------------------------------------------- /cpplibs/linux/libUltralightCore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/linux/libUltralightCore.so -------------------------------------------------------------------------------- /cpplibs/linux/libWebCore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/linux/libWebCore.so -------------------------------------------------------------------------------- /cpplibs/mac/libUltralight.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/mac/libUltralight.dylib -------------------------------------------------------------------------------- /cpplibs/mac/libUltralightCore.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/mac/libUltralightCore.dylib -------------------------------------------------------------------------------- /cpplibs/mac/libWebCore.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/mac/libWebCore.dylib -------------------------------------------------------------------------------- /cpplibs/win/Ultralight.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/win/Ultralight.dll -------------------------------------------------------------------------------- /cpplibs/win/Ultralight.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/win/Ultralight.lib -------------------------------------------------------------------------------- /cpplibs/win/UltralightCore.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/win/UltralightCore.dll -------------------------------------------------------------------------------- /cpplibs/win/UltralightCore.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/win/UltralightCore.lib -------------------------------------------------------------------------------- /cpplibs/win/WebCore.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/win/WebCore.dll -------------------------------------------------------------------------------- /cpplibs/win/WebCore.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/cpplibs/win/WebCore.lib -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Sets default memory used for gradle commands. Can be overridden by user or command line properties. 2 | # This is required to provide enough memory for the Minecraft decompilation process. 3 | org.gradle.jvmargs=-Xmx3G 4 | org.gradle.daemon=false -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Mar 03 15:48:43 CST 2020 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'webcraft' -------------------------------------------------------------------------------- /src/main/cpp/FileSystemBasic.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | GNU LESSER GENERAL PUBLIC LICENSE 4 | Version 2.1, February 1999 5 | 6 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 7 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | 11 | [This is the first released version of the Lesser GPL. It also counts 12 | as the successor of the GNU Library Public License, version 2, hence 13 | the version number 2.1.] 14 | 15 | FULL LICENSE SEE https://github.com/ultralight-ux/AppCore/blob/master/LICENSE 16 | */ 17 | #pragma once 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace ultralight { 25 | 26 | /** 27 | * Basic FileSystem interface, implemented using the C++ STL. 28 | * 29 | * This provides only the minimum needed to load file URLs, eg: 30 | * - FileSystem::FileExists 31 | * - FileSystem::GetFileSize 32 | * - FileSystem::GetFileMimeType 33 | * - FileSystem::OpenFile 34 | * - FileSystem::ReadFromFile 35 | * - FileSystem::CloseFile 36 | */ 37 | class FileSystemBasic : public FileSystem { 38 | public: 39 | FileSystemBasic(const char* baseDir); 40 | virtual ~FileSystemBasic() {} 41 | 42 | virtual bool FileExists(const String16& path); 43 | 44 | virtual bool DeleteFile_(const String16& path) { return false; } 45 | 46 | virtual bool DeleteEmptyDirectory(const String16& path) { return false; } 47 | 48 | virtual bool MoveFile_(const String16& old_path, const String16& new_path) { return false; } 49 | 50 | virtual bool GetFileSize(const String16& path, int64_t& result); 51 | 52 | virtual bool GetFileSize(FileHandle handle, int64_t& result); 53 | 54 | virtual bool GetFileMimeType(const String16& path, String16& result); 55 | 56 | virtual bool GetFileModificationTime(const String16& path, time_t& result) { return false; } 57 | 58 | virtual bool GetFileCreationTime(const String16& path, time_t& result) { return false; } 59 | 60 | virtual MetadataType GetMetadataType(const String16& path) { return kMetadataType_Unknown; } 61 | 62 | virtual String16 GetPathByAppendingComponent(const String16& path, const String16& component) { return String16(); } 63 | 64 | virtual bool CreateDirectory_(const String16& path) { return false; } 65 | 66 | virtual String16 GetHomeDirectory() { return String16(); } 67 | 68 | virtual String16 GetFilenameFromPath(const String16& path) { return String16(); } 69 | 70 | virtual String16 GetDirectoryNameFromPath(const String16& path) { return String16(); } 71 | 72 | virtual bool GetVolumeFreeSpace(const String16& path, uint64_t& result) { return false; } 73 | 74 | virtual int32_t GetVolumeId(const String16& path) { return 0; } 75 | 76 | virtual Ref ListDirectory(const String16& path, const String16& filter) { return String16Vector::Create(); } 77 | 78 | virtual String16 OpenTemporaryFile(const String16& prefix, FileHandle& handle) { return String16(); } 79 | 80 | virtual FileHandle OpenFile(const String16& path, bool open_for_writing); 81 | 82 | virtual void CloseFile(FileHandle& handle); 83 | 84 | virtual int64_t SeekFile(FileHandle handle, int64_t offset, FileSeekOrigin origin) { return 0; } 85 | 86 | virtual bool TruncateFile(FileHandle handle, int64_t offset) { return false; } 87 | 88 | virtual int64_t WriteToFile(FileHandle handle, const char* data, int64_t length) { return 0; } 89 | 90 | virtual int64_t ReadFromFile(FileHandle handle, char* data, int64_t length); 91 | 92 | virtual bool CopyFile_(const String16& source_path, const String16& destination_path) { return false; } 93 | 94 | protected: 95 | std::string baseDir_; 96 | std::string getRelative(const String16& path); 97 | FileHandle next_handle_ = 0; 98 | std::map> open_files_; 99 | }; 100 | 101 | } // namespace ultralight 102 | 103 | -------------------------------------------------------------------------------- /src/main/cpp/cafe_qwq_webcraft_api_WebRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "glad/glad.h" 4 | 5 | using namespace ultralight; 6 | 7 | extern "C" 8 | JNIEXPORT jlong JNICALL 9 | Java_cafe_qwq_webcraft_api_WebRenderer_createRenderer(JNIEnv* env_, jclass clazz) 10 | { 11 | return (jlong)(new RefPtr(Renderer::Create())); 12 | } 13 | 14 | extern "C" 15 | JNIEXPORT void JNICALL 16 | Java_cafe_qwq_webcraft_api_WebRenderer_npurgeMemory(JNIEnv* env_, jobject obj, jlong pointer) 17 | { 18 | ((RefPtr*)pointer)->get()->PurgeMemory(); 19 | } 20 | 21 | extern "C" 22 | JNIEXPORT void JNICALL 23 | Java_cafe_qwq_webcraft_api_WebRenderer_render(JNIEnv* env_, jobject obj, jlong pointer) 24 | { 25 | //glClearColor(0.0,0.0,0.0,0.0); 26 | //glClearDepth(1.0); 27 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 28 | ((RefPtr*)pointer)->get()->Render(); 29 | GPUDriver* gpu_driver=Platform::instance().gpu_driver(); 30 | if (gpu_driver->HasCommandsPending()) 31 | { 32 | gpu_driver->DrawCommandList(); 33 | } 34 | glBindBuffer(GL_ARRAY_BUFFER, 0); 35 | } -------------------------------------------------------------------------------- /src/main/cpp/cafe_qwq_webcraft_client_ClientEventListener.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "gl/GPUDriverGL.h" 4 | #include "FileSystemBasic.h" 5 | #include 6 | 7 | using namespace ultralight; 8 | 9 | String* jstringToUltralightString(JNIEnv* env_, jstring& str) 10 | { 11 | const char* ch = env_->GetStringUTFChars(str, 0); 12 | const int length = env_->GetStringUTFLength(str); 13 | return new String(ch,length); 14 | } 15 | 16 | extern "C" 17 | JNIEXPORT jlong JNICALL 18 | Java_cafe_qwq_webcraft_client_ClientEventListener_setNativeConfig(JNIEnv* env_, jclass clazz, jstring font_family_standard, jstring font_family_fixed, jstring font_family_serif, jstring font_family_sans_serif, jstring user_agent) 19 | { 20 | Config* config = new Config(); 21 | config->font_family_standard = jstringToUltralightString(env_,font_family_standard)->utf16(); 22 | config->font_family_fixed = jstringToUltralightString(env_,font_family_fixed)->utf16(); 23 | config->font_family_serif = jstringToUltralightString(env_,font_family_serif)->utf16(); 24 | config->font_family_sans_serif = jstringToUltralightString(env_,font_family_sans_serif)->utf16(); 25 | config->user_agent = jstringToUltralightString(env_,user_agent)->utf16(); 26 | //config->device_scale_hint = 2; 27 | return (jlong)config; 28 | } 29 | 30 | extern "C" 31 | JNIEXPORT void JNICALL 32 | Java_cafe_qwq_webcraft_client_ClientEventListener_nativeInit(JNIEnv* env_, jclass clazz, jlong pointer, jlong pointer2, jlong config) 33 | { 34 | set_glfwGetTime_address((void*)pointer2); 35 | Platform::instance().set_file_system(new FileSystemBasic("")); 36 | Platform::instance().set_config(*((Config*)config)); 37 | gladLoadGLLoader((GLADloadproc)pointer); 38 | GPUDriver* gpu_driver = new GPUDriverGL(); 39 | Platform::instance().set_gpu_driver(gpu_driver); 40 | } -------------------------------------------------------------------------------- /src/main/cpp/gl/GPUDriverGL.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | GNU LESSER GENERAL PUBLIC LICENSE 4 | Version 2.1, February 1999 5 | 6 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 7 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | 11 | [This is the first released version of the Lesser GPL. It also counts 12 | as the successor of the GNU Library Public License, version 2, hence 13 | the version number 2.1.] 14 | 15 | FULL LICENSE SEE https://github.com/ultralight-ux/AppCore/blob/master/LICENSE 16 | */ 17 | #pragma once 18 | #include 19 | #include "../glad/glad.h" 20 | #include 21 | #include 22 | 23 | extern "C" { 24 | 25 | void set_glfwGetTime_address(void* address); 26 | 27 | } 28 | 29 | namespace ultralight { 30 | 31 | typedef ShaderType ProgramType; 32 | 33 | class GPUDriverGL : public GPUDriver { 34 | public: 35 | GPUDriverGL(); 36 | 37 | virtual ~GPUDriverGL() { } 38 | 39 | #if ENABLE_OFFSCREEN_GL 40 | virtual void SetRenderBufferBitmap(uint32_t render_buffer_id, 41 | RefPtr bitmap); 42 | 43 | virtual bool IsRenderBufferBitmapDirty(uint32_t render_buffer_id); 44 | 45 | virtual void SetRenderBufferBitmapDirty(uint32_t render_buffer_id, 46 | bool dirty); 47 | #endif 48 | 49 | virtual void BeginSynchronize() override { } 50 | 51 | virtual void EndSynchronize() override { } 52 | 53 | virtual uint32_t NextTextureId() override { return next_texture_id_++; } 54 | 55 | virtual void CreateTexture(uint32_t texture_id, 56 | Ref bitmap) override; 57 | 58 | virtual void UpdateTexture(uint32_t texture_id, 59 | Ref bitmap) override; 60 | 61 | virtual void BindTexture(uint8_t texture_unit, 62 | uint32_t texture_id) override; 63 | 64 | virtual void DestroyTexture(uint32_t texture_id) override; 65 | 66 | virtual uint32_t NextRenderBufferId() override { return next_render_buffer_id_++; } 67 | 68 | virtual void CreateRenderBuffer(uint32_t render_buffer_id, 69 | const RenderBuffer& buffer) override; 70 | 71 | virtual void BindRenderBuffer(uint32_t render_buffer_id) override; 72 | 73 | virtual void ClearRenderBuffer(uint32_t render_buffer_id) override; 74 | 75 | virtual void DestroyRenderBuffer(uint32_t render_buffer_id) override; 76 | 77 | virtual uint32_t NextGeometryId() override { return next_geometry_id_++; } 78 | 79 | virtual void CreateGeometry(uint32_t geometry_id, 80 | const VertexBuffer& vertices, 81 | const IndexBuffer& indices) override; 82 | 83 | virtual void UpdateGeometry(uint32_t geometry_id, 84 | const VertexBuffer& vertices, 85 | const IndexBuffer& indices) override; 86 | 87 | virtual void DrawGeometry(uint32_t geometry_id, 88 | uint32_t indices_count, 89 | uint32_t indices_offset, 90 | const GPUState& state) override; 91 | 92 | virtual void DestroyGeometry(uint32_t geometry_id) override; 93 | 94 | virtual void UpdateCommandList(const CommandList& list) override; 95 | 96 | virtual bool HasCommandsPending() override { return !command_list.empty(); } 97 | 98 | virtual void DrawCommandList() override; 99 | 100 | int batch_count() { return batch_count_; } 101 | 102 | void BindUltralightTexture(uint32_t ultralight_texture_id); 103 | 104 | void LoadPrograms(); 105 | void DestroyPrograms(); 106 | 107 | void LoadProgram(ProgramType type); 108 | void SelectProgram(ProgramType type); 109 | void UpdateUniforms(const GPUState& state); 110 | void SetUniform1ui(const char* name, GLuint val); 111 | void SetUniform1f(const char* name, float val); 112 | void SetUniform1fv(const char* name, size_t count, const float* val); 113 | void SetUniform4f(const char* name, const float val[4]); 114 | void SetUniform4fv(const char* name, size_t count, const float* val); 115 | void SetUniformMatrix4fv(const char* name, size_t count, const float* val); 116 | void SetViewport(float width, float height); 117 | 118 | int GetOpenGLTextureByUT(int ); 119 | 120 | protected: 121 | Matrix ApplyProjection(const Matrix4x4& transform, float screen_width, float screen_height, bool flip_y); 122 | 123 | void CreateFBOTexture(uint32_t texture_id, Ref bitmap); 124 | 125 | struct TextureEntry { 126 | GLuint tex_id = 0; // GL Texture ID 127 | GLuint msaa_tex_id = 0; // GL Texture ID (only used if MSAA is enabled) 128 | uint32_t render_buffer_id = 0; // Used to check if we need to perform MSAA resolve 129 | GLuint width, height; // Used when resolving MSAA FBO, only valid if FBO 130 | bool is_sRGB = false; // Whether or not the primary texture is sRGB or not. 131 | }; 132 | 133 | // Maps Ultralight Texture IDs to OpenGL texture handles 134 | std::map texture_map; 135 | 136 | uint32_t next_texture_id_ = 1; 137 | uint32_t next_render_buffer_id_ = 1; // 0 is reserved for default render buffer 138 | uint32_t next_geometry_id_ = 1; 139 | 140 | struct GeometryEntry { 141 | GLuint vao; // VAO id 142 | GLuint vbo_vertices; // VBO id for vertices 143 | GLuint vbo_indices; // VBO id for indices 144 | }; 145 | std::map geometry_map; 146 | 147 | struct RenderBufferEntry { 148 | GLuint fbo_id = 0; // GL FBO ID (if MSAA is enabled, this will be used for resolve) 149 | GLuint msaa_fbo_id = 0; // GL FBO ID for MSAA 150 | bool needs_resolve = false; // Whether or not we need to perform MSAA resolve 151 | uint32_t texture_id = 0; // The Ultralight texture ID backing this RenderBuffer. 152 | #if ENABLE_OFFSCREEN_GL 153 | RefPtr bitmap; 154 | GLuint pbo_id = 0; 155 | bool is_bitmap_dirty = false; 156 | bool is_first_draw = true; 157 | bool needs_update = false; 158 | #endif 159 | }; 160 | 161 | void ResolveIfNeeded(uint32_t render_buffer_id); 162 | 163 | void MakeTextureSRGBIfNeeded(uint32_t texture_id); 164 | 165 | #if ENABLE_OFFSCREEN_GL 166 | void UpdateBitmap(RenderBufferEntry& entry, GLuint pbo_id); 167 | #endif 168 | 169 | std::map render_buffer_map; 170 | 171 | struct ProgramEntry { 172 | GLuint program_id; 173 | GLuint vert_shader_id; 174 | GLuint frag_shader_id; 175 | }; 176 | std::map programs_; 177 | GLuint cur_program_id_; 178 | 179 | std::vector command_list; 180 | int batch_count_; 181 | }; 182 | 183 | } // namespace ultralight 184 | -------------------------------------------------------------------------------- /src/main/cpp/shaders/glsl/shader_fill_path_frag.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | GNU LESSER GENERAL PUBLIC LICENSE 4 | Version 2.1, February 1999 5 | 6 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 7 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | 11 | [This is the first released version of the Lesser GPL. It also counts 12 | as the successor of the GNU Library Public License, version 2, hence 13 | the version number 2.1.] 14 | 15 | FULL LICENSE SEE https://github.com/ultralight-ux/AppCore/blob/master/LICENSE 16 | */ 17 | #include 18 | 19 | static std::string shader_fill_path_frag() { 20 | return R"(#version 150 21 | 22 | // Program Uniforms 23 | uniform vec4 State; 24 | uniform mat4 Transform; 25 | uniform vec4 Scalar4[2]; 26 | uniform vec4 Vector[8]; 27 | uniform uint ClipSize; 28 | uniform mat4 Clip[8]; 29 | 30 | // Uniform Accessor Functions 31 | float Time() { return State[0]; } 32 | float ScreenWidth() { return State[1]; } 33 | float ScreenHeight() { return State[2]; } 34 | float ScreenScale() { return State[3]; } 35 | float Scalar(uint i) { if (i < 4u) return Scalar4[0][i]; else return Scalar4[1][i - 4u]; } 36 | 37 | // Vertex Attributes 38 | in vec4 ex_Color; 39 | in vec2 ex_ObjectCoord; 40 | in vec2 ex_ScreenCoord; 41 | 42 | // Out Params 43 | out vec4 out_Color; 44 | 45 | float sdRect(vec2 p, vec2 size) { 46 | vec2 d = abs(p) - size; 47 | return min(max(d.x,d.y),0.0) + length(max(d,0.0)); 48 | } 49 | 50 | // The below function "sdEllipse" is MIT licensed with following text: 51 | // 52 | // The MIT License 53 | // Copyright 2013 Inigo Quilez 54 | // Permission is hereby granted, free of charge, to any person obtaining a 55 | // copy of this software and associated documentation files (the "Software"), 56 | // to deal in the Software without restriction, including without limitation 57 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 58 | // and/or sell copies of the Software, and to permit persons to whom the Software 59 | // is furnished to do so, subject to the following conditions: The above copyright 60 | // notice and this permission notice shall be included in all copies or substantial 61 | // portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 62 | // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 63 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 64 | // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 65 | // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 66 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 67 | // THE SOFTWARE. 68 | 69 | float sdEllipse( vec2 p, in vec2 ab ) { 70 | if (abs(ab.x - ab.y) < 0.1) 71 | return length(p) - ab.x; 72 | 73 | p = abs(p); if (p.x > p.y) { p=p.yx; ab=ab.yx; } 74 | 75 | float l = ab.y*ab.y - ab.x*ab.x; 76 | 77 | float m = ab.x*p.x/l; 78 | float n = ab.y*p.y/l; 79 | float m2 = m*m; 80 | float n2 = n*n; 81 | 82 | float c = (m2 + n2 - 1.0)/3.0; 83 | float c3 = c*c*c; 84 | 85 | float q = c3 + m2*n2*2.0; 86 | float d = c3 + m2*n2; 87 | float g = m + m*n2; 88 | 89 | float co; 90 | 91 | if (d < 0.0) 92 | { 93 | float p = acos(q/c3)/3.0; 94 | float s = cos(p); 95 | float t = sin(p)*sqrt(3.0); 96 | float rx = sqrt( -c*(s + t + 2.0) + m2 ); 97 | float ry = sqrt( -c*(s - t + 2.0) + m2 ); 98 | co = ( ry + sign(l)*rx + abs(g)/(rx*ry) - m)/2.0; 99 | } else { 100 | float h = 2.0*m*n*sqrt( d ); 101 | float s = sign(q+h)*pow( abs(q+h), 1.0/3.0 ); 102 | float u = sign(q-h)*pow( abs(q-h), 1.0/3.0 ); 103 | float rx = -s - u - c*4.0 + 2.0*m2; 104 | float ry = (s - u)*sqrt(3.0); 105 | float rm = sqrt( rx*rx + ry*ry ); 106 | float p = ry/sqrt(rm-rx); 107 | co = (p + 2.0*g/rm - m)/2.0; 108 | } 109 | 110 | float si = sqrt(1.0 - co*co); 111 | 112 | vec2 r = vec2(ab.x*co, ab.y*si); 113 | 114 | return length(r - p) * sign(p.y-r.y); 115 | } 116 | 117 | float sdRoundRect(vec2 p, vec2 size, vec4 rx, vec4 ry) { 118 | size *= 0.5; 119 | vec2 corner; 120 | 121 | corner = vec2(-size.x+rx.x, -size.y+ry.x); // Top-Left 122 | vec2 local = p - corner; 123 | if (dot(rx.x, ry.x) > 0.0 && p.x < corner.x && p.y <= corner.y) 124 | return sdEllipse(local, vec2(rx.x, ry.x)); 125 | 126 | corner = vec2(size.x-rx.y, -size.y+ry.y); // Top-Right 127 | local = p - corner; 128 | if (dot(rx.y, ry.y) > 0.0 && p.x >= corner.x && p.y <= corner.y) 129 | return sdEllipse(local, vec2(rx.y, ry.y)); 130 | 131 | corner = vec2(size.x-rx.z, size.y-ry.z); // Bottom-Right 132 | local = p - corner; 133 | if (dot(rx.z, ry.z) > 0.0 && p.x >= corner.x && p.y >= corner.y) 134 | return sdEllipse(local, vec2(rx.z, ry.z)); 135 | 136 | corner = vec2(-size.x+rx.w, size.y-ry.w); // Bottom-Left 137 | local = p - corner; 138 | if (dot(rx.w, ry.w) > 0.0 && p.x < corner.x && p.y > corner.y) 139 | return sdEllipse(local, vec2(rx.w, ry.w)); 140 | 141 | return sdRect(p, size); 142 | } 143 | 144 | vec2 transformAffine(vec2 val, vec2 a, vec2 b, vec2 c) { 145 | return val.x * a + val.y * b + c; 146 | } 147 | 148 | void Unpack(vec4 x, out vec4 a, out vec4 b) { 149 | const float s = 65536.0; 150 | a = floor(x / s); 151 | b = floor(x - a * s); 152 | } 153 | 154 | #define AA_WIDTH 0.354 155 | 156 | float antialias(in float d, in float width, in float median) { 157 | return smoothstep(median - width, median + width, d); 158 | } 159 | 160 | void applyClip() { 161 | for (uint i = 0u; i < ClipSize; i++) { 162 | mat4 data = Clip[i]; 163 | vec2 origin = data[0].xy; 164 | vec2 size = data[0].zw; 165 | vec4 radii_x, radii_y; 166 | Unpack(data[1], radii_x, radii_y); 167 | bool inverse = bool(data[3].z); 168 | 169 | vec2 p = ex_ObjectCoord; 170 | p = transformAffine(p, data[2].xy, data[2].zw, data[3].xy); 171 | p -= origin; 172 | 173 | float d_clip = sdRoundRect(p, size, radii_x, radii_y) * (inverse? -1.0 : 1.0); 174 | float alpha = antialias(-d_clip, AA_WIDTH, -AA_WIDTH); 175 | out_Color = vec4(out_Color.rgb * alpha, out_Color.a * alpha); 176 | 177 | //if (abs(d_clip) < 2.0) 178 | // out_Color = vec4(0.9, 1.0, 0.0, 1.0); 179 | } 180 | } 181 | 182 | void main(void) { 183 | out_Color = ex_Color; 184 | applyClip(); 185 | } 186 | 187 | )"; 188 | } 189 | -------------------------------------------------------------------------------- /src/main/cpp/shaders/glsl/shader_v2f_c4f_t2f_t2f_d28f_vert.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | GNU LESSER GENERAL PUBLIC LICENSE 4 | Version 2.1, February 1999 5 | 6 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 7 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | 11 | [This is the first released version of the Lesser GPL. It also counts 12 | as the successor of the GNU Library Public License, version 2, hence 13 | the version number 2.1.] 14 | 15 | FULL LICENSE SEE https://github.com/ultralight-ux/AppCore/blob/master/LICENSE 16 | */ 17 | 18 | #include 19 | 20 | static std::string shader_v2f_c4f_t2f_t2f_d28f_vert() { 21 | return R"(#version 150 22 | 23 | // Program Uniforms 24 | uniform vec4 State; 25 | uniform mat4 Transform; 26 | uniform vec4 Scalar4[2]; 27 | uniform vec4 Vector[8]; 28 | uniform uint ClipSize; 29 | uniform mat4 Clip[8]; 30 | 31 | // Uniform Accessor Functions 32 | float Time() { return State[0]; } 33 | float ScreenWidth() { return State[1]; } 34 | float ScreenHeight() { return State[2]; } 35 | float ScreenScale() { return State[3]; } 36 | float Scalar(uint i) { if (i < 4u) return Scalar4[0][i]; else return Scalar4[1][i - 4u]; } 37 | vec4 sRGBToLinear(vec4 val) { return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w); } 38 | 39 | // Vertex Attributes 40 | in vec2 in_Position; 41 | in vec4 in_Color; 42 | in vec2 in_TexCoord; 43 | in vec2 in_ObjCoord; 44 | in vec4 in_Data0; 45 | in vec4 in_Data1; 46 | in vec4 in_Data2; 47 | in vec4 in_Data3; 48 | in vec4 in_Data4; 49 | in vec4 in_Data5; 50 | in vec4 in_Data6; 51 | 52 | // Out Params 53 | out vec4 ex_Color; 54 | out vec2 ex_TexCoord; 55 | out vec4 ex_Data0; 56 | out vec4 ex_Data1; 57 | out vec4 ex_Data2; 58 | out vec4 ex_Data3; 59 | out vec4 ex_Data4; 60 | out vec4 ex_Data5; 61 | out vec4 ex_Data6; 62 | out vec2 ex_ObjectCoord; 63 | out vec2 ex_ScreenCoord; 64 | 65 | void main(void) 66 | { 67 | ex_ObjectCoord = in_ObjCoord; 68 | gl_Position = Transform * vec4(in_Position, 0.0, 1.0); 69 | ex_Color = in_Color;//sRGBToLinear(in_Color); 70 | ex_TexCoord = in_TexCoord; 71 | ex_Data0 = in_Data0; 72 | ex_Data1 = in_Data1; 73 | ex_Data2 = in_Data2; 74 | ex_Data3 = in_Data3; 75 | ex_Data4 = in_Data4; 76 | ex_Data5 = in_Data5; 77 | ex_Data6 = in_Data6; 78 | } 79 | 80 | )"; 81 | } 82 | -------------------------------------------------------------------------------- /src/main/cpp/shaders/glsl/shader_v2f_c4f_t2f_vert.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | GNU LESSER GENERAL PUBLIC LICENSE 4 | Version 2.1, February 1999 5 | 6 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 7 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | 11 | [This is the first released version of the Lesser GPL. It also counts 12 | as the successor of the GNU Library Public License, version 2, hence 13 | the version number 2.1.] 14 | 15 | FULL LICENSE SEE https://github.com/ultralight-ux/AppCore/blob/master/LICENSE 16 | */ 17 | 18 | #include 19 | 20 | static std::string shader_v2f_c4f_t2f_vert() { 21 | return R"(#version 150 22 | 23 | // Program Uniforms 24 | uniform vec4 State; 25 | uniform mat4 Transform; 26 | uniform vec4 Scalar4[2]; 27 | uniform vec4 Vector[8]; 28 | uniform uint ClipSize; 29 | uniform mat4 Clip[8]; 30 | 31 | // Uniform Accessor Functions 32 | float Time() { return State[0]; } 33 | float ScreenWidth() { return State[1]; } 34 | float ScreenHeight() { return State[2]; } 35 | float ScreenScale() { return State[3]; } 36 | float Scalar(uint i) { if (i < 4u) return Scalar4[0][i]; else return Scalar4[1][i - 4u]; } 37 | vec4 sRGBToLinear(vec4 val) { return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w); } 38 | 39 | // Vertex Attributes 40 | in vec2 in_Position; 41 | in vec4 in_Color; 42 | in vec2 in_TexCoord; 43 | 44 | // Out Params 45 | out vec4 ex_Color; 46 | out vec2 ex_ObjectCoord; 47 | out vec2 ex_ScreenCoord; 48 | 49 | void main(void) 50 | { 51 | ex_ObjectCoord = in_TexCoord; 52 | gl_Position = Transform * vec4(in_Position, 0.0, 1.0); 53 | ex_Color = in_Color;//sRGBToLinear(in_Color); 54 | } 55 | 56 | )"; 57 | } -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/Config.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import com.google.gson.stream.JsonReader; 6 | import com.google.gson.stream.JsonWriter; 7 | import net.minecraftforge.api.distmarker.Dist; 8 | import net.minecraftforge.api.distmarker.OnlyIn; 9 | 10 | import java.io.File; 11 | import java.io.FileReader; 12 | import java.io.FileWriter; 13 | import java.io.IOException; 14 | 15 | public class Config 16 | { 17 | private static Config instance; 18 | private static final String CONFIG_FILE_PATH = "mods/webcraft/config.json"; 19 | 20 | @OnlyIn(Dist.CLIENT) 21 | public boolean downloadNativesSilently = false; 22 | 23 | @OnlyIn(Dist.CLIENT) 24 | public String fontFamilyStandard; 25 | 26 | @OnlyIn(Dist.CLIENT) 27 | public String fontFamilyFixed; 28 | 29 | @OnlyIn(Dist.CLIENT) 30 | public String fontFamilySerif; 31 | 32 | @OnlyIn(Dist.CLIENT) 33 | public String fontFamilySansSerif; 34 | 35 | @OnlyIn(Dist.CLIENT) 36 | public String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/602.1 (KHTML, like Gecko) Ultralight/1.1.0 Safari/602.1"; 37 | 38 | @OnlyIn(Dist.CLIENT) 39 | public Config() 40 | { 41 | if(WebCraft.RUNTIME_OS == WebCraft.OS.WINDOWS) 42 | { 43 | fontFamilyStandard = "Microsoft Yahei"; 44 | fontFamilyFixed = "Microsoft Yahei"; 45 | fontFamilySansSerif = "Microsoft Yahei"; 46 | fontFamilySerif = "Times New Roman"; 47 | } 48 | else 49 | { 50 | fontFamilyStandard = "WenQuanYi Micro Hei"; 51 | fontFamilyFixed = "WenQuanYi Micro Hei"; 52 | fontFamilySansSerif = "WenQuanYi Micro Hei"; 53 | fontFamilySerif = "Noto Serif"; 54 | } 55 | } 56 | 57 | public static void init() 58 | { 59 | File f = new File(CONFIG_FILE_PATH); 60 | if (f.exists() && f.isFile()) 61 | { 62 | try (JsonReader reader = new JsonReader(new FileReader(f))) 63 | { 64 | Gson gson = new GsonBuilder().setPrettyPrinting().create();; 65 | instance = gson.fromJson(reader, Config.class); 66 | } 67 | catch (IOException e) 68 | { 69 | e.printStackTrace(); 70 | } 71 | } 72 | else 73 | { 74 | instance = new Config(); 75 | if (!f.getParentFile().exists()) f.getParentFile().mkdirs(); 76 | try 77 | { 78 | f.createNewFile(); 79 | try (JsonWriter writer = new JsonWriter(new FileWriter(f, false))) 80 | { 81 | Gson gson = new GsonBuilder().setPrettyPrinting().create();; 82 | gson.toJson(instance, Config.class, writer); 83 | } 84 | } 85 | catch (IOException e) 86 | { 87 | e.printStackTrace(); 88 | } 89 | } 90 | } 91 | 92 | public static Config getInstance() 93 | { 94 | return instance; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/WebCraft.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft; 2 | 3 | import cafe.qwq.webcraft.util.FileUtils; 4 | import net.minecraft.util.ResourceLocation; 5 | import net.minecraftforge.fml.MavenVersionStringHelper; 6 | import net.minecraftforge.fml.ModList; 7 | import net.minecraftforge.fml.common.Mod; 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | 11 | import java.io.IOException; 12 | import java.util.Arrays; 13 | 14 | @Mod(WebCraft.MODID) 15 | public class WebCraft 16 | { 17 | public static final String MODID = "webcraft"; 18 | public static String VERSION = "NULL"; 19 | public static final Logger LOGGER = LogManager.getLogger(); 20 | public static OS RUNTIME_OS; 21 | private static final String[] resourceArray = {"minecraft.ttf", 22 | "fzxs12.ttf", "minecraft.css", "button/button.png", "button/button_disabled.png", 23 | "button/button_hover.png"}; 24 | 25 | public WebCraft() 26 | { 27 | Arrays.stream(resourceArray).forEach(resource -> { 28 | try 29 | { 30 | FileUtils.upzipIfNeeded(new ResourceLocation(MODID, resource)); 31 | } 32 | catch (IOException e) 33 | { 34 | e.printStackTrace(); 35 | } 36 | }); 37 | 38 | String osName = System.getProperty("os.name").toLowerCase(); 39 | if (osName.contains("win")) 40 | RUNTIME_OS = OS.WINDOWS; 41 | else if (osName.contains("linux")) 42 | RUNTIME_OS = OS.LINUX; 43 | else 44 | RUNTIME_OS = OS.MAC; 45 | 46 | ModList.get().getMods().stream() 47 | .filter(info -> info.getModId().equals(MODID)) 48 | .forEach(info -> VERSION = MavenVersionStringHelper.artifactVersionToString(info.getVersion())); 49 | 50 | if (VERSION.equals("NULL")) LOGGER.warn("WebCraft got version failed !"); 51 | else LOGGER.info("Welcome to use WebCraft (version:" + VERSION + ") ! "); 52 | 53 | Config.init(); 54 | } 55 | 56 | public enum OS 57 | { 58 | WINDOWS, MAC, LINUX 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/api/IRenderer.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.api; 2 | 3 | public interface IRenderer 4 | { 5 | void render(int mouseX, int mouseY, float pTicks); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/api/View.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.api; 2 | 3 | import cafe.qwq.webcraft.api.math.Vec2i; 4 | import cafe.qwq.webcraft.api.math.Vec4i; 5 | import cafe.qwq.webcraft.util.FileUtils; 6 | import com.google.gson.JsonElement; 7 | import com.google.gson.JsonObject; 8 | import com.google.gson.JsonParser; 9 | import com.mojang.blaze3d.systems.RenderSystem; 10 | import net.minecraft.client.renderer.BufferBuilder; 11 | import net.minecraft.client.renderer.Tessellator; 12 | import net.minecraft.client.renderer.vertex.DefaultVertexFormats; 13 | import net.minecraft.util.ResourceLocation; 14 | 15 | import java.io.IOException; 16 | import java.net.URL; 17 | import java.util.HashMap; 18 | import java.util.LinkedList; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | public class View 23 | { 24 | private Vec4i bounds; 25 | private final long viewPointer; 26 | private final boolean isTransparent; 27 | private IResizeCallback resizeCallback; 28 | private double scale = 1.0f; 29 | private final List domReadyCallbakList = new LinkedList<>(); 30 | private final Map jsCallbackMap = new HashMap<>(); 31 | private static JsonParser jsonParser = new JsonParser(); 32 | 33 | public View() 34 | { 35 | this(0, 0, 100, 100); 36 | } 37 | 38 | public View(int x, int y, int width, int height) 39 | { 40 | this(new Vec4i(x, y, width, height), true); 41 | } 42 | 43 | public void finalize() throws Throwable 44 | { 45 | super.finalize(); 46 | destroyView(viewPointer); 47 | } 48 | 49 | /** 50 | * @param vec 一个表示坐标和长宽的向量 51 | * @param isTransparent 表示view的背景是否透明 52 | */ 53 | public View(Vec4i vec, boolean isTransparent/*, float scale*/) 54 | { 55 | bounds = vec; 56 | //this.scale = Minecraft.getInstance().getMainWindow().getGuiScaleFactor(); 57 | this.isTransparent = isTransparent; 58 | viewPointer = WebRenderer.INSTANCE.createView((int) (vec.w * scale), (int) (vec.h * scale), isTransparent, this); 59 | } 60 | 61 | /** 62 | * @return 这个view的背景是否透明(默认为true且一旦已实例化则不能修改) 63 | */ 64 | public boolean isTransparent() 65 | { 66 | return isTransparent; 67 | } 68 | 69 | /** 70 | * @return view的位置信息 71 | */ 72 | public Vec4i getBounds() 73 | { 74 | return bounds; 75 | } 76 | 77 | /** 78 | * 设置view的坐标以及长宽 79 | */ 80 | public View setBounds(Vec4i bounds) 81 | { 82 | this.bounds = bounds; 83 | //this.scale = Minecraft.getInstance().getMainWindow().getGuiScaleFactor(); 84 | //float scale = this.scale; 85 | //if (scale > Minecraft.getInstance().getMainWindow().getGuiScaleFactor()) 86 | // scale = (float) Minecraft.getInstance().getMainWindow().getGuiScaleFactor(); 87 | resize(viewPointer, (int) (bounds.w * scale), (int) (bounds.h * scale)); 88 | return this; 89 | } 90 | 91 | /** 92 | * 设置WebScreen窗口大小改变时的回调函数 93 | */ 94 | public View setResizeCallback(IResizeCallback callback) 95 | { 96 | resizeCallback = callback; 97 | return this; 98 | } 99 | 100 | void onResize(Vec2i vec) 101 | { 102 | if (resizeCallback != null) setBounds(resizeCallback.onResize(vec)); 103 | } 104 | 105 | public View loadHTML(String html) 106 | { 107 | nloadHTML(viewPointer, html); 108 | return this; 109 | } 110 | 111 | public View loadHTML(ResourceLocation location) throws IOException 112 | { 113 | String path = "/assets/" + location.getNamespace() + "/web/" + location.getPath(); 114 | FileUtils.upzipIfNeeded(path); 115 | String url = "file:///" + "mods/webcraft" + path; 116 | loadURL(url); 117 | return this; 118 | } 119 | 120 | public View loadURL(URL url) 121 | { 122 | loadURL(url.toString()); 123 | return this; 124 | } 125 | 126 | public View loadURL(String url) 127 | { 128 | //System.out.println(url); 129 | nloadURL(viewPointer, url); 130 | return this; 131 | } 132 | 133 | /** 134 | * 绘制view,注意本方法必须在离屏渲染之后执行 135 | */ 136 | public void draw() 137 | { 138 | long rtt = getRTT(viewPointer); 139 | int textureID = getRTTTextureID(rtt); 140 | float t = getRTTTop(rtt), b = getRTTBottom(rtt), l = getRTTLeft(rtt), r = getRTTRight(rtt); 141 | //int pID = WCShaders.getSRGBToLinearProgramID(); 142 | //glUseProgram(pID); 143 | Tessellator tessellator = Tessellator.getInstance(); 144 | BufferBuilder bufferbuilder = tessellator.getBuffer(); 145 | RenderSystem.bindTexture(textureID); 146 | RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f); 147 | RenderSystem.disableLighting(); 148 | RenderSystem.enableAlphaTest(); 149 | RenderSystem.enableBlend(); 150 | bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX); 151 | bufferbuilder.pos(bounds.x, bounds.y, 0.0).tex(l, t).endVertex(); 152 | bufferbuilder.pos(bounds.x + bounds.w, bounds.y, 0.0).tex(r, t).endVertex(); 153 | bufferbuilder.pos(bounds.x + bounds.w, bounds.y + bounds.h, 0.0).tex(r, b).endVertex(); 154 | bufferbuilder.pos(bounds.x, bounds.y + bounds.h, 0.0).tex(l, b).endVertex(); 155 | tessellator.draw(); 156 | RenderSystem.enableLighting(); 157 | RenderSystem.disableAlphaTest(); 158 | RenderSystem.disableBlend(); 159 | destroyRTT(rtt); 160 | } 161 | 162 | public void fireMouseEvent(int type, int buttonType, int x, int y) 163 | { 164 | nfireMouseEvent(viewPointer, type, buttonType, (int) (x * scale), (int) (y * scale)); 165 | } 166 | 167 | public void fireScrollEvent(int amount) 168 | { 169 | nfireScrollEvent(viewPointer, amount); 170 | } 171 | 172 | public void fireKeyEvent(int type, int modifiers, String text, int scanCode, int keyCode) 173 | { 174 | nfireKeyEvent(viewPointer, type, modifiers, text, scanCode, keyCode); 175 | } 176 | 177 | public View addJSFuncWithCallback(String name, IJSFuncCallback callback) 178 | { 179 | jsCallbackMap.put(name, callback); 180 | return this; 181 | } 182 | 183 | public void addDOMReadyListener(Runnable runnable) 184 | { 185 | domReadyCallbakList.add(runnable); 186 | } 187 | 188 | public void onDOMReady() 189 | { 190 | jsCallbackMap.keySet().forEach(name -> addJSFuncWithCallback(viewPointer, name)); 191 | domReadyCallbakList.forEach(Runnable::run); 192 | } 193 | 194 | public void enable() 195 | { 196 | enable(viewPointer); 197 | } 198 | 199 | public void disable() 200 | { 201 | disable(viewPointer); 202 | } 203 | 204 | public String jsFuncCallback(String funcName) 205 | { 206 | IJSFuncCallback callback = jsCallbackMap.get(funcName); 207 | JsonElement obj = callback.callback(null); 208 | return obj == null ? null : obj.toString(); 209 | } 210 | 211 | public String jsFuncCallback(String funcName, String jsonStr) 212 | { 213 | IJSFuncCallback callback = jsCallbackMap.get(funcName); 214 | JsonElement obj = callback.callback(jsonParser.parse(jsonStr)); 215 | return obj == null ? null : obj.toString(); 216 | } 217 | 218 | public JsonElement evaluteJS(String js) 219 | { 220 | String result = evaluateScript(viewPointer, js); 221 | if (result == null) return null; 222 | return jsonParser.parse(result); 223 | } 224 | 225 | public JsonElement evaluteJSFunc(String jsFuncName, JsonObject arg) 226 | { 227 | String js = jsFuncName + "(" + arg.toString() + ")"; 228 | String result = evaluateScript(viewPointer, js); 229 | if (result == null) return null; 230 | return jsonParser.parse(result); 231 | } 232 | 233 | /*public static void test(int x) 234 | { 235 | WebCraft.LOGGER.info(x); 236 | }*/ 237 | 238 | /** 239 | * 当WebScreen的尺寸发生改变时会调用的回调函数 240 | */ 241 | public interface IResizeCallback 242 | { 243 | /** 244 | * @param vec 用一个二维向量表示WebScreen的尺寸,其中x为长,y为宽 245 | * @return 用一个四维向量表示的view的坐标和长宽 246 | */ 247 | Vec4i onResize(Vec2i vec); 248 | } 249 | 250 | public interface IJSFuncCallback 251 | { 252 | JsonElement callback(JsonElement obj); 253 | } 254 | 255 | private native void nloadURL(long pointer, String url); 256 | 257 | private native void nloadHTML(long pointer, String html); 258 | 259 | private native void resize(long pointer, int width, int height); 260 | 261 | private native long getRTT(long pointer); 262 | 263 | private native int getRTTTextureID(long rttPointer); 264 | 265 | private native float getRTTTop(long rttPointer); 266 | 267 | private native float getRTTBottom(long rttPointer); 268 | 269 | private native float getRTTRight(long rttPointer); 270 | 271 | private native float getRTTLeft(long rttPointer); 272 | 273 | private native void nfireScrollEvent(long pointer, int amount); 274 | 275 | private native void nfireMouseEvent(long pointer, int type, int buttonType, int x, int y); 276 | 277 | private native void destroyRTT(long pointer); 278 | 279 | private native void destroyView(long pointer); 280 | 281 | private native void nfireKeyEvent(long pointer, int type, int modifiers, String text, int scanCode, int keyCode); 282 | 283 | private native void addJSFuncWithCallback(long pointer, String funcName); 284 | 285 | private native void enable(long pointer); 286 | 287 | private native void disable(long pointer); 288 | 289 | private native String evaluateScript(long pointer, String script); 290 | } 291 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/api/WebRenderer.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.api; 2 | 3 | import cafe.qwq.webcraft.client.UltralightWindow; 4 | import org.lwjgl.BufferUtils; 5 | import org.lwjgl.opengl.GL20; 6 | import org.lwjgl.opengl.GL32; 7 | 8 | import java.nio.IntBuffer; 9 | 10 | public class WebRenderer 11 | { 12 | public static final WebRenderer INSTANCE = new WebRenderer(); 13 | 14 | private final long rendererPointer; 15 | 16 | private WebRenderer() 17 | { 18 | rendererPointer = createRenderer(); 19 | } 20 | 21 | /** 22 | * 生成一个view,不推荐直接使用本方法(除非你不得不用它来实现某些功能) 23 | * 请使用cafe.qwq.webcraft.api.View#View来创建view 24 | * 25 | * @return 使用Ultralight创建的view的地址 26 | */ 27 | public long createView(int width, int height, boolean transparent, View view) 28 | { 29 | return ncreateView(rendererPointer, width, height, transparent, view); 30 | } 31 | 32 | /** 33 | * @return Renderer的地址 34 | */ 35 | public long getNativeRendererPointer() 36 | { 37 | return rendererPointer; 38 | } 39 | 40 | /** 41 | * 让Renderer释放内存 42 | */ 43 | public void purgeMemory() 44 | { 45 | npurgeMemory(rendererPointer); 46 | } 47 | 48 | /** 49 | * 逻辑更新 50 | */ 51 | public void logicUpdate() 52 | { 53 | update(rendererPointer); 54 | } 55 | 56 | /** 57 | * 离屏渲染 58 | */ 59 | public void offscreenRender() 60 | { 61 | IntBuffer id = BufferUtils.createIntBuffer(1); 62 | GL20.glGetIntegerv(GL20.GL_CURRENT_PROGRAM, id); 63 | UltralightWindow.getInstance().makeCurrent(); 64 | GL32.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 65 | //GL32.glDisable(GL32.GL_LIGHTING); 66 | logicUpdate(); 67 | render(rendererPointer); 68 | GL32.glBindTexture(GL32.GL_TEXTURE_2D, 0); 69 | GL32.glFinish(); 70 | UltralightWindow.getInstance().unmakeCurrent(); 71 | GL20.glUseProgram(id.get()); 72 | } 73 | 74 | private static native long createRenderer(); 75 | 76 | private native long ncreateView(long pointer, int width, int height, boolean transparent, View view); 77 | 78 | private native void npurgeMemory(long pointer); 79 | 80 | private native void update(long pointer); 81 | 82 | private native void render(long pointer); 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/api/WebScreen.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.api; 2 | 3 | import cafe.qwq.webcraft.api.math.Vec2i; 4 | import cafe.qwq.webcraft.api.math.Vec4i; 5 | import cafe.qwq.webcraft.client.KeyboardHelper; 6 | import com.mojang.blaze3d.systems.RenderSystem; 7 | import net.minecraft.client.gui.screen.Screen; 8 | import net.minecraft.util.text.ITextComponent; 9 | import net.minecraftforge.client.event.GuiScreenEvent; 10 | import net.minecraftforge.common.MinecraftForge; 11 | import org.lwjgl.glfw.GLFW; 12 | 13 | import java.util.LinkedList; 14 | import java.util.List; 15 | 16 | public class WebScreen extends Screen 17 | { 18 | private List viewList; 19 | private boolean shouldCloseOnEsc; 20 | private List rendererList1; 21 | private List rendererList2; 22 | protected double scale; 23 | 24 | public WebScreen(ITextComponent component) 25 | { 26 | super(component); 27 | viewList = new LinkedList<>(); 28 | rendererList1 = new LinkedList<>(); 29 | rendererList2 = new LinkedList<>(); 30 | shouldCloseOnEsc = true; 31 | } 32 | 33 | /** 34 | * 添加一个网页View 35 | */ 36 | public WebScreen addView(View view) 37 | { 38 | viewList.add(view); 39 | return this; 40 | } 41 | 42 | /** 43 | * 设置当按下Esc键时是否关闭GUI 44 | */ 45 | public WebScreen setShouldCloseOnEsc(boolean shouldCloseOnEsc) 46 | { 47 | this.shouldCloseOnEsc = shouldCloseOnEsc; 48 | return this; 49 | } 50 | 51 | /** 52 | * 添加一个Renderer可以在网页渲染前渲染自己的东西 53 | */ 54 | public WebScreen addPreRenderer(IRenderer renderer) 55 | { 56 | rendererList1.add(renderer); 57 | return this; 58 | } 59 | 60 | /** 61 | * 添加一个Renderer可以在网页渲染后渲染自己的东西 62 | */ 63 | public WebScreen addPostRenderer(IRenderer renderer) 64 | { 65 | rendererList2.add(renderer); 66 | return this; 67 | } 68 | 69 | protected void init() 70 | { 71 | scale = minecraft.getMainWindow().getGuiScaleFactor(); 72 | viewList.forEach(view -> { 73 | view.enable(); 74 | view.onResize(new Vec2i((int) (width * scale), (int) (height * scale))); 75 | }); 76 | } 77 | 78 | public void onClose() 79 | { 80 | super.onClose(); 81 | viewList.forEach(view -> view.disable()); 82 | WebRenderer.INSTANCE.purgeMemory(); 83 | } 84 | 85 | public boolean shouldCloseOnEsc() 86 | { 87 | return shouldCloseOnEsc; 88 | } 89 | 90 | public boolean mouseClicked(double mouseX, double mouseY, int buttonID) 91 | { 92 | mouseX *= scale; 93 | mouseY *= scale; 94 | for (View view : viewList) 95 | view.fireMouseEvent(1, buttonID, (int) mouseX - view.getBounds().x, (int) mouseY - view.getBounds().y); 96 | return true; 97 | } 98 | 99 | public boolean mouseReleased(double mouseX, double mouseY, int buttonID) 100 | { 101 | mouseX *= scale; 102 | mouseY *= scale; 103 | for (View view : viewList) 104 | view.fireMouseEvent(2, buttonID, (int) mouseX - view.getBounds().x, (int) mouseY - view.getBounds().y); 105 | return true; 106 | } 107 | 108 | public void mouseMoved(double mouseX, double mouseY) 109 | { 110 | mouseX *= scale; 111 | mouseY *= scale; 112 | for (View view : viewList) 113 | view.fireMouseEvent(0, 0, (int) (mouseX - view.getBounds().x), (int) (mouseY - view.getBounds().y)); 114 | } 115 | 116 | public boolean mouseScrolled(double mouseX, double mouseY, double scrollDelta) 117 | { 118 | for (View view : viewList) 119 | { 120 | Vec4i vec = view.getBounds(); 121 | if (vec.x <= mouseX && vec.x + vec.w >= mouseX && vec.y <= mouseY && vec.y + vec.h >= mouseY) 122 | view.fireScrollEvent((int) (scrollDelta * 25)); 123 | } 124 | return true; 125 | } 126 | 127 | public boolean charTyped(char codePoint, int modifiers) 128 | { 129 | viewList.forEach(view -> view.fireKeyEvent(3, 0, Character.toString(codePoint), 0, 0)); 130 | return true; 131 | } 132 | 133 | public boolean keyPressed(int keyCode, int scanCode, int modifiers) 134 | { 135 | int uKeyCode = KeyboardHelper.glfwKeyCodeToUltralightKeyCode(keyCode); 136 | int uModifiers = KeyboardHelper.glfwModsToUltralightMods(modifiers); 137 | viewList.forEach(view -> view.fireKeyEvent(2, uModifiers, null, scanCode, uKeyCode)); 138 | if (keyCode == GLFW.GLFW_KEY_ENTER) 139 | { 140 | charTyped('\r', 0); 141 | } 142 | return super.keyPressed(keyCode, scanCode, modifiers); 143 | } 144 | 145 | public boolean keyReleased(int keyCode, int scanCode, int modifiers) 146 | { 147 | int uKeyCode = KeyboardHelper.glfwKeyCodeToUltralightKeyCode(keyCode); 148 | int uModifiers = KeyboardHelper.glfwModsToUltralightMods(modifiers); 149 | viewList.forEach(view -> view.fireKeyEvent(1, uModifiers, null, scanCode, uKeyCode)); 150 | return super.keyReleased(keyCode, scanCode, modifiers); 151 | } 152 | 153 | public void renderBackground(int p_renderBackground_1_) 154 | { 155 | RenderSystem.pushMatrix(); 156 | RenderSystem.scaled(scale, scale, scale); 157 | if (this.minecraft.world != null) 158 | { 159 | this.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680); 160 | MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.BackgroundDrawnEvent(this)); 161 | } 162 | else 163 | { 164 | this.renderDirtBackground(p_renderBackground_1_); 165 | } 166 | RenderSystem.popMatrix(); 167 | } 168 | 169 | //double lastTime = 0.0; 170 | //int fpsSum = 0; 171 | 172 | public void render(int mX, int mY, float pTicks) 173 | { 174 | int mouseX = (int) (mX * scale); 175 | int mouseY = (int) (mY * scale); 176 | 177 | RenderSystem.pushMatrix(); 178 | RenderSystem.scaled(1.0 / scale, 1.0 / scale, 1.0 / scale); 179 | 180 | WebRenderer.INSTANCE.offscreenRender(); 181 | //renderBackground(); 182 | 183 | rendererList1.forEach(renderer -> renderer.render(mouseX, mouseY, pTicks)); 184 | viewList.forEach(view -> view.draw()); 185 | rendererList2.forEach(renderer -> renderer.render(mouseX, mouseY, pTicks)); 186 | 187 | //fpsSum++; 188 | //double time = GLFW.glfwGetTime(); 189 | /*if (time - lastTime > 1.0) 190 | { 191 | //System.out.printf("FPS = %.1f\n", 1.0 * fpsSum / (time - lastTime)); 192 | int a = (int) (1.0 * fpsSum / (time - lastTime) * 10 + 0.5); 193 | GLFW.glfwSetWindowTitle(minecraft.getMainWindow().getHandle(), 194 | "Minecraft 1.15.2 FPS: " + a / 10 + "." + a % 10); 195 | lastTime = time; 196 | fpsSum = 0; 197 | }*/ 198 | 199 | RenderSystem.popMatrix(); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/api/math/Vec2i.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.api.math; 2 | 3 | public class Vec2i 4 | { 5 | public int x, y; 6 | 7 | public Vec2i(int x, int y) 8 | { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/api/math/Vec4i.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.api.math; 2 | 3 | public class Vec4i 4 | { 5 | public int x, y, w, h; 6 | 7 | public Vec4i(int x, int y, int w, int h) 8 | { 9 | this.x = x; 10 | this.y = y; 11 | this.w = w; 12 | this.h = h; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/client/ClientEventListener.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.client; 2 | 3 | import cafe.qwq.webcraft.Config; 4 | import cafe.qwq.webcraft.WebCraft; 5 | import cafe.qwq.webcraft.util.FileUtils; 6 | import net.minecraft.client.Minecraft; 7 | import net.minecraftforge.api.distmarker.Dist; 8 | import net.minecraftforge.api.distmarker.OnlyIn; 9 | import net.minecraftforge.client.event.GuiOpenEvent; 10 | import net.minecraftforge.common.MinecraftForge; 11 | import net.minecraftforge.eventbus.api.EventPriority; 12 | import net.minecraftforge.eventbus.api.SubscribeEvent; 13 | import net.minecraftforge.fml.common.Mod; 14 | import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; 15 | import org.lwjgl.glfw.GLFW; 16 | 17 | import javax.swing.*; 18 | import java.awt.*; 19 | import java.io.File; 20 | import java.io.FileOutputStream; 21 | import java.io.InputStream; 22 | import java.io.OutputStream; 23 | import java.net.URL; 24 | import java.util.function.Consumer; 25 | import java.util.zip.ZipFile; 26 | 27 | @OnlyIn(Dist.CLIENT) 28 | @Mod.EventBusSubscriber(modid = WebCraft.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) 29 | public class ClientEventListener 30 | { 31 | private static Consumer consumer; 32 | private static String MAVEN_URL = "https://maven.qwq.cafe/"; 33 | private static String libPath; 34 | 35 | static 36 | { 37 | if (WebCraft.RUNTIME_OS == WebCraft.OS.WINDOWS) 38 | MAVEN_URL = "https://ci.qwq.cafe/maven/"; 39 | 40 | if (!WebCraft.VERSION.equals("NONE") && !WebCraft.VERSION.equals("NULL")) 41 | { 42 | libPath = "mods/webcraft/natives-" + WebCraft.VERSION + "/"; 43 | if (!checkNatives()) downloadNatives(); 44 | } 45 | else libPath = System.getProperty("cafe.qwq.webcraft.nativesPath"); 46 | 47 | if (WebCraft.RUNTIME_OS == WebCraft.OS.WINDOWS) 48 | { 49 | loadLibrary("UltralightCore"); 50 | loadLibrary("WebCore"); 51 | loadLibrary("Ultralight"); 52 | } 53 | 54 | loadLibrary("webcraft_core"); 55 | } 56 | 57 | private static String getNativePath(String name) 58 | { 59 | String name1; 60 | switch (WebCraft.RUNTIME_OS) 61 | { 62 | case WINDOWS: 63 | name1 = name + ".dll"; 64 | break; 65 | case LINUX: 66 | name1 = "lib" + name + ".so"; 67 | break; 68 | default: 69 | name1 = "lib" + name + ".dylib"; 70 | break; 71 | } 72 | return libPath + name1; 73 | } 74 | 75 | private static boolean checkNatives() 76 | { 77 | File f = new File(libPath); 78 | if (!f.exists() || !f.isDirectory()) return false; 79 | 80 | File f1 = new File(getNativePath("UltralightCore")); 81 | if (!f1.exists() || !f1.isFile()) return false; 82 | 83 | f1 = new File(getNativePath("WebCore")); 84 | if (!f1.exists() || !f1.isFile()) return false; 85 | 86 | f1 = new File(getNativePath("Ultralight")); 87 | if (!f1.exists() || !f1.isFile()) return false; 88 | 89 | f1 = new File(getNativePath("webcraft_core")); 90 | if (!f1.exists() || !f1.isFile()) return false; 91 | 92 | return true; 93 | } 94 | 95 | private static void downloadNatives() 96 | { 97 | String fileName = "webcraft-" + WebCraft.VERSION + "-natives"; 98 | switch (WebCraft.RUNTIME_OS) 99 | { 100 | case WINDOWS: 101 | fileName += "-win.jar"; 102 | break; 103 | case LINUX: 104 | fileName += "-linux.jar"; 105 | break; 106 | default: 107 | fileName += "-mac.jar";//虽然并没有MAC版本 108 | break; 109 | } 110 | 111 | String urlstr = MAVEN_URL + "cafe/qwq/webcraft/" + WebCraft.VERSION + "/" + fileName; 112 | try 113 | { 114 | URL url = new URL(urlstr); 115 | File outputFile = new File("mods/webcraft/" + fileName); 116 | if (Config.getInstance().downloadNativesSilently) 117 | { 118 | FileUtils.downloadFile(url, outputFile, null); 119 | } 120 | else 121 | { 122 | System.setProperty("java.awt.headless", "false"); 123 | 124 | JFrame frame = new JFrame(); 125 | JPanel panel = new JPanel(); 126 | 127 | panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 128 | frame.setContentPane(panel); 129 | frame.setTitle("WebCraft"); 130 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 131 | int width = 800; 132 | int height = 70; 133 | int x = (screenSize.width - width) / 2; 134 | int y = (screenSize.height - height) / 2; 135 | frame.setBounds(x, y, width, height); 136 | frame.setAlwaysOnTop(true); 137 | frame.setResizable(false); 138 | frame.setUndecorated(true); 139 | frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 140 | 141 | panel.setBackground(Color.WHITE); 142 | JLabel label = new JLabel("Downloading " + fileName + "..."); 143 | label.setFont(new Font("Arial", Font.PLAIN, 16)); 144 | panel.add(label); 145 | JProgressBar bar = new JProgressBar(); 146 | bar.setMaximum(1000); 147 | panel.add(bar); 148 | frame.setVisible(true); 149 | 150 | final String finalFileName = fileName; 151 | FileUtils.downloadFile(url, outputFile, (size, downloadSize, speed) -> { 152 | label.setText(String.format("Downloading %s(%.2fMB/%.2fMB %.2fMB/s)...", finalFileName, downloadSize / 1024f, size / 1024f, speed / 1024f)); 153 | bar.setValue((int) (downloadSize * 1000 / size)); 154 | }); 155 | 156 | frame.dispose(); 157 | } 158 | ZipFile zip = new ZipFile(outputFile); 159 | File libDir = new File(libPath); 160 | if (!libDir.exists()) libDir.mkdirs(); 161 | zip.stream().filter(entry -> !entry.isDirectory() && !entry.getName().contains("MANIFEST.MF")) 162 | .forEach(entry -> { 163 | try 164 | { 165 | InputStream input = zip.getInputStream(entry); 166 | OutputStream output = new FileOutputStream(libPath + entry.getName()); 167 | int length; 168 | byte[] bytes = new byte[1024]; 169 | while ((length = input.read(bytes)) != -1) 170 | { 171 | output.write(bytes, 0, length); 172 | } 173 | input.close(); 174 | output.close(); 175 | } 176 | catch (Exception e) 177 | { 178 | WebCraft.LOGGER.error("Error While Unzipping Natives !"); 179 | e.printStackTrace(); 180 | } 181 | }); 182 | } 183 | catch (Exception e) 184 | { 185 | WebCraft.LOGGER.error("Error While Downloading Natives !"); 186 | e.printStackTrace(); 187 | } 188 | } 189 | 190 | private static void loadLibrary(String name) 191 | { 192 | File f = new File(getNativePath(name)); 193 | System.load(f.getAbsolutePath()); 194 | } 195 | 196 | @SubscribeEvent 197 | public static void onClientSetup(final FMLClientSetupEvent event) 198 | { 199 | consumer = ClientEventListener::onGuiOpen; 200 | MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGHEST, consumer); 201 | } 202 | 203 | public static void onGuiOpen(final GuiOpenEvent event) 204 | { 205 | MinecraftForge.EVENT_BUS.unregister(consumer); 206 | WebCraft.LOGGER.info("Start loading Ultralight..."); 207 | UltralightWindow.init(); 208 | UltralightWindow.getInstance().makeCurrent(); 209 | Config config = Config.getInstance(); 210 | long configPointer = setNativeConfig(config.fontFamilyStandard, config.fontFamilyFixed, config.fontFamilySerif, config.fontFamilySansSerif, config.userAgent); 211 | nativeInit(GLFW.Functions.GetProcAddress, GLFW.Functions.GetTime, configPointer); 212 | UltralightWindow.getInstance().unmakeCurrent(); 213 | } 214 | 215 | private native static long setNativeConfig(String fontFamilyStandard, String fontFamilyFixed, String fontFamilySerif, String fontFamilySansSerif, String userAgent); 216 | 217 | private native static void nativeInit(long pointer1, long pointer2, long pointer3); 218 | } 219 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/client/UltralightWindow.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.client; 2 | 3 | import net.minecraft.client.Minecraft; 4 | 5 | import static org.lwjgl.glfw.GLFW.*; 6 | 7 | public class UltralightWindow 8 | { 9 | private static UltralightWindow instance; 10 | 11 | private long ulWindowHandle; 12 | private long mainWindowHandle; 13 | 14 | private UltralightWindow() 15 | { 16 | mainWindowHandle = Minecraft.getInstance().getMainWindow().getHandle(); 17 | glfwDefaultWindowHints(); 18 | glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); 19 | glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API); 20 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 22 | //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); 23 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); 24 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 25 | ulWindowHandle = glfwCreateWindow(640, 480, "Ultralight", 0, mainWindowHandle); 26 | } 27 | 28 | static void init() 29 | { 30 | instance = new UltralightWindow(); 31 | } 32 | 33 | public static UltralightWindow getInstance() 34 | { 35 | return instance; 36 | } 37 | 38 | public long getHandle() 39 | { 40 | return ulWindowHandle; 41 | } 42 | 43 | public void makeCurrent() 44 | { 45 | glfwMakeContextCurrent(ulWindowHandle); 46 | } 47 | 48 | public void unmakeCurrent() 49 | { 50 | glfwMakeContextCurrent(mainWindowHandle); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/cafe/qwq/webcraft/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.util; 2 | 3 | import cafe.qwq.webcraft.WebCraft; 4 | import net.minecraft.util.ResourceLocation; 5 | 6 | import java.io.*; 7 | import java.net.URL; 8 | import java.net.URLConnection; 9 | import java.util.HashSet; 10 | import java.util.Set; 11 | 12 | public class FileUtils 13 | { 14 | private static Set unzipSet = new HashSet<>(); 15 | 16 | public static void downloadFile(URL url, File outputFile, IDownloadCallback callback) throws IOException 17 | { 18 | URLConnection connection = url.openConnection(); 19 | InputStream input = connection.getInputStream(); 20 | OutputStream output = new FileOutputStream(outputFile); 21 | float size = connection.getContentLength() / 1024f; 22 | int length, sum = 0, sum2 = 0; 23 | byte[] bytes = new byte[1024]; 24 | long lastTime = System.currentTimeMillis(); 25 | String name = outputFile.getName(); 26 | 27 | while ((length = input.read(bytes)) != -1) 28 | { 29 | output.write(bytes, 0, length); 30 | sum += length; 31 | sum2 += length; 32 | long time = System.currentTimeMillis(); 33 | if (time - lastTime >= 1000) 34 | { 35 | WebCraft.LOGGER.info(String.format("Downloading %s(%.2fKB/%.2fKB %.2fKB/s)...", name, sum / 1024f, size, sum2 / (1.024f * (time - lastTime)))); 36 | if (callback != null) callback.callback(size, sum / 1024f, sum2 / (1.024f * (time - lastTime))); 37 | sum2 = 0; 38 | lastTime = time; 39 | } 40 | } 41 | 42 | long time = System.currentTimeMillis(); 43 | WebCraft.LOGGER.info(String.format("Downloading %s(%.2fKB/%.2fKB %.2fKB/s)...", name, sum / 1024f, size, sum2 / (1.024f * (time - lastTime)))); 44 | if (callback != null) callback.callback(size, sum / 1024f, sum2 / (1.024f * (time - lastTime))); 45 | 46 | input.close(); 47 | output.close(); 48 | } 49 | 50 | public static void upzipIfNeeded(ResourceLocation location) throws IOException 51 | { 52 | upzipIfNeeded("/assets/" + location.getNamespace() + "/web/" + location.getPath()); 53 | } 54 | 55 | public static void upzipIfNeeded(String resourcePath) throws IOException 56 | { 57 | if (unzipSet.contains(resourcePath)) return; 58 | 59 | File ouputFile = new File("mods/webcraft" + resourcePath); 60 | if (!ouputFile.getParentFile().exists()) ouputFile.getParentFile().mkdirs(); 61 | 62 | InputStream input = FileUtils.class.getResourceAsStream(resourcePath); 63 | OutputStream output = new FileOutputStream(ouputFile); 64 | 65 | int length; 66 | byte[] bytes = new byte[1024]; 67 | 68 | while ((length = input.read(bytes)) != -1) 69 | { 70 | output.write(bytes, 0, length); 71 | } 72 | } 73 | 74 | public interface IDownloadCallback 75 | { 76 | void callback(float size, float downloadSize, float speed); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/mods.toml: -------------------------------------------------------------------------------- 1 | modLoader="javafml" #mandatory 2 | loaderVersion="[31,)" 3 | [[mods]] 4 | modId="webcraft" 5 | version="${file.jarVersion}" 6 | displayName="WebCraft" 7 | credits="Bogos" 8 | authors="hookan" 9 | logoFile="webcraft_logo.png" 10 | description=''' 11 | A GUI API for modders to use HTML/JS/CSS to write GUIs. 12 | ''' 13 | [[dependencies.webcraft]] 14 | modId="forge" 15 | mandatory=true 16 | versionRange="[31,)" 17 | ordering="NONE" 18 | side="BOTH" 19 | [[dependencies.webcraft]] 20 | modId="minecraft" 21 | mandatory=true 22 | versionRange="[1.15.2]" 23 | ordering="NONE" 24 | side="BOTH" 25 | -------------------------------------------------------------------------------- /src/main/resources/assets/webcraft/web/button/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/src/main/resources/assets/webcraft/web/button/button.png -------------------------------------------------------------------------------- /src/main/resources/assets/webcraft/web/button/button_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/src/main/resources/assets/webcraft/web/button/button_disabled.png -------------------------------------------------------------------------------- /src/main/resources/assets/webcraft/web/button/button_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/src/main/resources/assets/webcraft/web/button/button_hover.png -------------------------------------------------------------------------------- /src/main/resources/assets/webcraft/web/fzxs12.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/src/main/resources/assets/webcraft/web/fzxs12.ttf -------------------------------------------------------------------------------- /src/main/resources/assets/webcraft/web/minecraft.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'mc'; 3 | src: url('file:///mods/webcraft/assets/webcraft/web/minecraft.ttf'); 4 | font-weight: normal; 5 | font-style: normal; 6 | } 7 | 8 | @font-face { 9 | font-family: 'fzxs12'; 10 | src: url('file:///mods/webcraft/assets/webcraft/web/fzxs12.ttf'); 11 | font-weight: normal; 12 | font-style: normal; 13 | } 14 | 15 | body { 16 | font-family: 'mc','fzxs12'; 17 | color: #fff; 18 | font-size: 18px; 19 | } 20 | 21 | button { 22 | font-family: 'mc','fzxs12'; 23 | color: #fff; 24 | font-size: 18px; 25 | background: url('file:///mods/webcraft/assets/webcraft/web/button/button.png'); 26 | background-size: 100% 100%; 27 | border: none; 28 | text-align: center; 29 | text-decoration: none; 30 | float: left; 31 | border-radius: 0px; 32 | padding-top: 2px; 33 | padding-bottom: 33px; 34 | } 35 | 36 | button:hover { 37 | background: url('file:///mods/webcraft/assets/webcraft/web/button/button_hover.png'); 38 | background-size: 100% 100%; 39 | background-blend-mode: color; 40 | border: none; 41 | color: #fff; 42 | } 43 | 44 | button:disabled { 45 | background: url('file:///mods/webcraft/assets/webcraft/web/button/button_disabled.png'); 46 | background-size: 100% 100%; 47 | color: #aaa; 48 | } 49 | 50 | button:active { 51 | background: url('file:///mods/webcraft/assets/webcraft/web/button/button_disabled.png'); 52 | background-size: 100% 100%; 53 | border: none; 54 | color: #aaa; 55 | } -------------------------------------------------------------------------------- /src/main/resources/assets/webcraft/web/minecraft.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/src/main/resources/assets/webcraft/web/minecraft.ttf -------------------------------------------------------------------------------- /src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "webcraft resources", 4 | "pack_format": 5 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/main/resources/webcraft_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hookan/WebCraft/81ac8acccf6773ec43255536150b843a16fb6984/src/main/resources/webcraft_logo.png -------------------------------------------------------------------------------- /src/test/java/cafe/qwq/webcraft/demo/Demo.java: -------------------------------------------------------------------------------- 1 | package cafe.qwq.webcraft.demo; 2 | 3 | import cafe.qwq.webcraft.api.View; 4 | import cafe.qwq.webcraft.api.WebScreen; 5 | import cafe.qwq.webcraft.api.math.Vec4i; 6 | import com.google.gson.JsonParser; 7 | import net.minecraft.client.gui.screen.MainMenuScreen; 8 | import net.minecraft.util.ResourceLocation; 9 | import net.minecraft.util.text.StringTextComponent; 10 | import net.minecraftforge.client.event.GuiOpenEvent; 11 | import net.minecraftforge.common.MinecraftForge; 12 | import net.minecraftforge.fml.common.Mod; 13 | 14 | import java.io.IOException; 15 | 16 | @Mod("demo") 17 | public class Demo 18 | { 19 | public Demo() 20 | { 21 | MinecraftForge.EVENT_BUS.addListener(Demo::onGUiOpen); 22 | } 23 | 24 | public static void onGUiOpen(final GuiOpenEvent event) 25 | { 26 | if (event.getGui() instanceof MainMenuScreen) 27 | { 28 | //event.setGui(new DemoScreen()); 29 | WebScreen screen = new WebScreen(new StringTextComponent("test")); 30 | View view = new View(); 31 | view.setResizeCallback(vec -> new Vec4i(0, 0, vec.x, vec.y)); 32 | try 33 | { 34 | view.loadHTML(new ResourceLocation("demo:test.html")); 35 | view.addJSFuncWithCallback("qwqwq", obj -> { 36 | return new JsonParser().parse("{\"qwq\": \"老子宇宙第一可爱\"}"); 37 | }); 38 | view.addDOMReadyListener(() -> { 39 | /*System.out.println(*/view.evaluteJS("qwq()");//.toString()); 40 | }); 41 | } 42 | catch (IOException e) 43 | { 44 | e.printStackTrace(); 45 | } 46 | //view.loadURL("https://qwq.cafe"); 47 | //view.loadHTML("

我好可爱啊喵

"); 48 | //view.loadHTML("

■■■

" + 49 | // "

草草草

" + 50 | // "

喵喵喵

" + 51 | // "

■■■

"); 52 | screen.addView(view).addPreRenderer((mouseX, mouseY, pTicks) -> screen.renderBackground()); 53 | event.setGui(screen); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/mods.toml: -------------------------------------------------------------------------------- 1 | modLoader="javafml" #mandatory 2 | loaderVersion="[31,)" 3 | [[mods]] 4 | modId="demo" 5 | version="${file.jarVersion}" 6 | displayName="WebCraftDemo" 7 | credits="Bogos" 8 | authors="hookan" 9 | description=''' 10 | ''' 11 | [[dependencies.webcraft]] 12 | modId="forge" 13 | mandatory=true 14 | versionRange="[31,)" 15 | ordering="NONE" 16 | side="BOTH" 17 | [[dependencies.webcraft]] 18 | modId="minecraft" 19 | mandatory=true 20 | versionRange="[1.15.2]" 21 | ordering="NONE" 22 | side="BOTH" 23 | -------------------------------------------------------------------------------- /src/test/resources/assets/demo/web/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 18 | 19 | 20 | 21 | 22 | 23 |

这里是测试HTML喵

24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/test/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "webcraft demo resources", 4 | "pack_format": 5 5 | } 6 | } 7 | --------------------------------------------------------------------------------