mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
Compare commits
185 Commits
remove-app-main
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a5fa17a39 | |||
| 5191409708 | |||
| 3eab806940 | |||
| 30dc7ff294 | |||
| 9e18cb93fb | |||
| e4932e163e | |||
| a8fe27488f | |||
| 06307313cd | |||
| 15335a2b37 | |||
| acf5635575 | |||
| caccb608a5 | |||
| d52632b475 | |||
| dec57aea1c | |||
| e2e2c1a046 | |||
| e8c1e1ba11 | |||
| b1cadbdd76 | |||
| 451b7d3a74 | |||
| e49c5b02c7 | |||
| dfe4ff0200 | |||
| 65d86895b8 | |||
| c3a6e85f5c | |||
| 8c2e45b8f8 | |||
| 47ab4c97b2 | |||
| 760369174d | |||
| 92fa23b59b | |||
| f98baf7f76 | |||
| a6da4083de | |||
| bbb54d5f54 | |||
| 8b96643490 | |||
| 4ed9695d57 | |||
| 9b38545fc2 | |||
| 0d08eaa55c | |||
| 9ab8095d1a | |||
| 3d6cafa94d | |||
| 9966e922f9 | |||
| 3af0ebb3a8 | |||
| 99647591f6 | |||
| e38f80adc6 | |||
| 93419a77bd | |||
| c250d7d562 | |||
| 6e5bbfe8d4 | |||
| 42bc707f7c | |||
| 7bcb315ee1 | |||
| 74671a7f9e | |||
| f48cc2c47f | |||
| 818061a18a | |||
| 45963441c1 | |||
| be8d9df848 | |||
| 3f4f8ba7c1 | |||
| 6553915e59 | |||
| 4c0e526c0b | |||
| f45039734f | |||
| 30f8ac10b7 | |||
| 176570527d | |||
| 36a2fa37c7 | |||
| bbb6d05f09 | |||
| a274f6fe0f | |||
| 0c145b3815 | |||
| ba82ae46d0 | |||
| 4e5a344cc2 | |||
| 78b54615cc | |||
| 31564b98c9 | |||
| 3b1effb7f5 | |||
| d76b4272aa | |||
| 3e601e73c4 | |||
| b2b12d6288 | |||
| b2f6707ad1 | |||
| 420f4c32f4 | |||
| ea979b436d | |||
| d50ef687b8 | |||
| 6ce7ffa4ca | |||
| c3ce484b5e | |||
| 8104d527c7 | |||
| 809a6d0dc7 | |||
| 0eac4f2c6a | |||
| 1a17e9ea37 | |||
| 0a209f7d39 | |||
| 0225334124 | |||
| f73287be87 | |||
| 86668e8b45 | |||
| e18db64991 | |||
| efd31ad621 | |||
| 35ec76e516 | |||
| cc6048bc25 | |||
| 016714a668 | |||
| a3117d3823 | |||
| fff2375470 | |||
| 72a72a2bc2 | |||
| 14a9fbcc0d | |||
| 0d23240556 | |||
| 77709d1771 | |||
| 4f720af6f2 | |||
| af446e8b87 | |||
| 95354d80bd | |||
| a5068a1996 | |||
| 593c5fbf4a | |||
| adaace864d | |||
| f200f0e9a3 | |||
| 1ae2b9b8fe | |||
| fe4bf00c70 | |||
| 8107ec2206 | |||
| d2db4f6875 | |||
| 971f86ea7e | |||
| e1fbb189e5 | |||
| a206e5e847 | |||
| e025ed1344 | |||
| b576252963 | |||
| 1d0d5f0383 | |||
| 26cddb00b1 | |||
| 0cbbacc45a | |||
| 1d95c7c6b3 | |||
| 7337c06daf | |||
| 94355e5201 | |||
| ea456f42c7 | |||
| 8daff13af6 | |||
| aa158e0c9c | |||
| 520efdfa75 | |||
| d7a1ec7461 | |||
| d4c5e54375 | |||
| 44ac50506d | |||
| 38e4b1c6a4 | |||
| 5d886b4d7f | |||
| c7277581f8 | |||
| a5f7e7b2c7 | |||
| 0781e62b56 | |||
| 95f63c66b6 | |||
| 6efcb65c4b | |||
| f6e9f6861d | |||
| 6c6cc157c4 | |||
| 8cf449034c | |||
| 6722c7960a | |||
| 97044e53b5 | |||
| af6dda67a5 | |||
| 042ed4ab49 | |||
| 6aa027136e | |||
| b1db32ef72 | |||
| 9dceca6c95 | |||
| 7293fa8a41 | |||
| 82cbb7b8da | |||
| 6c19821a6c | |||
| 86349775b7 | |||
| 4a1b4c2642 | |||
| c900d58fb3 | |||
| 74ccc9c2c7 | |||
| 3f671afea8 | |||
| 42357a29e0 | |||
| 8fb6d3da2b | |||
| 706940ff9b | |||
| 5542aac772 | |||
| 026d3f9daa | |||
| 38fca9ae13 | |||
| e878dbc598 | |||
| 1151eac07d | |||
| 56177c55cf | |||
| e6da07a85a | |||
| 175e134478 | |||
| 46cc311d19 | |||
| b8821875ed | |||
| f6e33914d9 | |||
| a394b330e8 | |||
| 24b0c2a4a1 | |||
| 7a9ce51988 | |||
| 8242234274 | |||
| 691adf4e77 | |||
| ba1e34e570 | |||
| 0deb7b3efc | |||
| e8c73bcb37 | |||
| cf9f2bbffe | |||
| ed28861309 | |||
| 971b01d836 | |||
| 5083a23301 | |||
| 61b603d521 | |||
| 3b5148a64e | |||
| ee6cdec60b | |||
| 42ef3476cc | |||
| 98d3a2eb24 | |||
| 109226b7e9 | |||
| 477bd5c744 | |||
| 1802761c93 | |||
| 0558bb3f1c | |||
| 78ce5e3ad5 | |||
| 1be34eec6f | |||
| 44ede4eceb | |||
| 993ec907be | |||
| 35785e9c96 |
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
# SPDX-License-Identifier: Unlicense OR MIT
|
# SPDX-License-Identifier: Unlicense OR MIT
|
||||||
image: debian/testing
|
image: debian/stable
|
||||||
packages:
|
packages:
|
||||||
- clang
|
- clang
|
||||||
- cmake
|
- cmake
|
||||||
@@ -29,7 +29,7 @@ environment:
|
|||||||
tasks:
|
tasks:
|
||||||
- install_go: |
|
- install_go: |
|
||||||
mkdir -p /home/build/sdk
|
mkdir -p /home/build/sdk
|
||||||
curl -s https://dl.google.com/go/go1.19.11.linux-amd64.tar.gz | tar -C /home/build/sdk -xzf -
|
curl -s https://dl.google.com/go/go1.24.2.linux-amd64.tar.gz | tar -C /home/build/sdk -xzf -
|
||||||
- prepare_toolchain: |
|
- prepare_toolchain: |
|
||||||
mkdir -p $APPLE_TOOLCHAIN_ROOT
|
mkdir -p $APPLE_TOOLCHAIN_ROOT
|
||||||
cd $APPLE_TOOLCHAIN_ROOT
|
cd $APPLE_TOOLCHAIN_ROOT
|
||||||
@@ -71,4 +71,4 @@ tasks:
|
|||||||
CC=$APPLE_TOOLCHAIN_ROOT/tools/clang-macos GOOS=darwin CGO_ENABLED=1 go build ./...
|
CC=$APPLE_TOOLCHAIN_ROOT/tools/clang-macos GOOS=darwin CGO_ENABLED=1 go build ./...
|
||||||
- test_ios: |
|
- test_ios: |
|
||||||
cd gio
|
cd gio
|
||||||
CC=$APPLE_TOOLCHAIN_ROOT/tools/clang-ios GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -tags ios ./...
|
CGO_CFLAGS=-Wno-deprecated-module-dot-map CC=$APPLE_TOOLCHAIN_ROOT/tools/clang-ios GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -tags ios ./...
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
# SPDX-License-Identifier: Unlicense OR MIT
|
# SPDX-License-Identifier: Unlicense OR MIT
|
||||||
image: freebsd/13.x
|
image: freebsd/latest
|
||||||
packages:
|
packages:
|
||||||
- libX11
|
- libX11
|
||||||
- libxkbcommon
|
- libxkbcommon
|
||||||
@@ -16,7 +16,7 @@ environment:
|
|||||||
tasks:
|
tasks:
|
||||||
- install_go: |
|
- install_go: |
|
||||||
mkdir -p /home/build/sdk
|
mkdir -p /home/build/sdk
|
||||||
curl https://dl.google.com/go/go1.19.11.freebsd-amd64.tar.gz | tar -C /home/build/sdk -xzf -
|
curl https://dl.google.com/go/go1.24.2.freebsd-amd64.tar.gz | tar -C /home/build/sdk -xzf -
|
||||||
- test_gio: |
|
- test_gio: |
|
||||||
cd gio
|
cd gio
|
||||||
go test ./...
|
go test ./...
|
||||||
|
|||||||
+11
-3
@@ -1,5 +1,5 @@
|
|||||||
# SPDX-License-Identifier: Unlicense OR MIT
|
# SPDX-License-Identifier: Unlicense OR MIT
|
||||||
image: debian/testing
|
image: debian/stable
|
||||||
packages:
|
packages:
|
||||||
- curl
|
- curl
|
||||||
- pkg-config
|
- pkg-config
|
||||||
@@ -18,6 +18,12 @@ packages:
|
|||||||
- libxinerama-dev
|
- libxinerama-dev
|
||||||
- libxi-dev
|
- libxi-dev
|
||||||
- libxxf86vm-dev
|
- libxxf86vm-dev
|
||||||
|
- libegl-mesa0
|
||||||
|
- libglx-mesa0
|
||||||
|
- libgl1-mesa-dri
|
||||||
|
- mesa-libgallium
|
||||||
|
- libgbm1
|
||||||
|
- libegl1
|
||||||
- mesa-vulkan-drivers
|
- mesa-vulkan-drivers
|
||||||
- wine
|
- wine
|
||||||
- xvfb
|
- xvfb
|
||||||
@@ -40,7 +46,7 @@ secrets:
|
|||||||
tasks:
|
tasks:
|
||||||
- install_go: |
|
- install_go: |
|
||||||
mkdir -p /home/build/sdk
|
mkdir -p /home/build/sdk
|
||||||
curl -s https://dl.google.com/go/go1.19.11.linux-amd64.tar.gz | tar -C /home/build/sdk -xzf -
|
curl -s https://dl.google.com/go/go1.24.2.linux-amd64.tar.gz | tar -C /home/build/sdk -xzf -
|
||||||
- check_gofmt: |
|
- check_gofmt: |
|
||||||
cd gio
|
cd gio
|
||||||
test -z "$(gofmt -s -l .)"
|
test -z "$(gofmt -s -l .)"
|
||||||
@@ -60,7 +66,7 @@ tasks:
|
|||||||
- add_32bit_arch: |
|
- add_32bit_arch: |
|
||||||
sudo dpkg --add-architecture i386
|
sudo dpkg --add-architecture i386
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y "libwayland-dev:i386" "libx11-dev:i386" "libx11-xcb-dev:i386" "libxkbcommon-dev:i386" "libxkbcommon-x11-dev:i386" "libgles2-mesa-dev:i386" "libegl1-mesa-dev:i386" "libffi-dev:i386" "libvulkan-dev:i386" "libxcursor-dev:i386"
|
sudo apt-get install -y "libwayland-dev:i386" "libx11-dev:i386" "libx11-xcb-dev:i386" "libxkbcommon-dev:i386" "libxkbcommon-x11-dev:i386" "libgles2-mesa-dev:i386" "libegl1-mesa-dev:i386" "libffi-dev:i386" "libvulkan-dev:i386" "libxcursor-dev:i386" "libegl-mesa0:i386" "libglx-mesa0:i386" "libgbm1:i386" "mesa-libgallium:i386" "libgl1-mesa-dri:i386"
|
||||||
- test_gio: |
|
- test_gio: |
|
||||||
cd gio
|
cd gio
|
||||||
go test -race ./...
|
go test -race ./...
|
||||||
@@ -80,6 +86,8 @@ tasks:
|
|||||||
unzip -q ndk.zip
|
unzip -q ndk.zip
|
||||||
rm ndk.zip
|
rm ndk.zip
|
||||||
mv android-ndk-* ndk-bundle
|
mv android-ndk-* ndk-bundle
|
||||||
|
# sdkmanager needs lots of file descriptors
|
||||||
|
ulimit -n 10000
|
||||||
yes|sdkmanager --licenses
|
yes|sdkmanager --licenses
|
||||||
sdkmanager "platforms;android-31" "build-tools;32.0.0"
|
sdkmanager "platforms;android-31" "build-tools;32.0.0"
|
||||||
- test_android: |
|
- test_android: |
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ environment:
|
|||||||
tasks:
|
tasks:
|
||||||
- install_go: |
|
- install_go: |
|
||||||
mkdir -p /home/build/sdk
|
mkdir -p /home/build/sdk
|
||||||
curl https://dl.google.com/go/go1.19.11.src.tar.gz | tar -C /home/build/sdk -xzf -
|
curl https://dl.google.com/go/go1.24.2.src.tar.gz | tar -C /home/build/sdk -xzf -
|
||||||
cd /home/build/sdk/go/src
|
cd /home/build/sdk/go/src
|
||||||
./make.bash
|
./make.bash
|
||||||
- test_gio: |
|
- test_gio: |
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package org.gioui;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -29,6 +30,7 @@ public final class GioActivity extends Activity {
|
|||||||
|
|
||||||
layer.addView(view);
|
layer.addView(view);
|
||||||
setContentView(layer);
|
setContentView(layer);
|
||||||
|
onNewIntent(this.getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onDestroy() {
|
@Override public void onDestroy() {
|
||||||
@@ -46,6 +48,16 @@ public final class GioActivity extends Activity {
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
view.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
view.resume();
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onConfigurationChanged(Configuration c) {
|
@Override public void onConfigurationChanged(Configuration c) {
|
||||||
super.onConfigurationChanged(c);
|
super.onConfigurationChanged(c);
|
||||||
view.configurationChanged();
|
view.configurationChanged();
|
||||||
@@ -60,4 +72,9 @@ public final class GioActivity extends Activity {
|
|||||||
if (!view.backPressed())
|
if (!view.backPressed())
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
view.onIntentEvent(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-7
@@ -12,6 +12,7 @@ import android.app.Fragment;
|
|||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
@@ -61,7 +62,6 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
|
|||||||
private static boolean jniLoaded;
|
private static boolean jniLoaded;
|
||||||
|
|
||||||
private final SurfaceHolder.Callback surfCallbacks;
|
private final SurfaceHolder.Callback surfCallbacks;
|
||||||
private final View.OnFocusChangeListener focusCallback;
|
|
||||||
private final InputMethodManager imm;
|
private final InputMethodManager imm;
|
||||||
private final float scrollXScale;
|
private final float scrollXScale;
|
||||||
private final float scrollYScale;
|
private final float scrollYScale;
|
||||||
@@ -113,12 +113,6 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
|
|||||||
nhandle = onCreateView(this);
|
nhandle = onCreateView(this);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
setFocusableInTouchMode(true);
|
setFocusableInTouchMode(true);
|
||||||
focusCallback = new View.OnFocusChangeListener() {
|
|
||||||
@Override public void onFocusChange(View v, boolean focus) {
|
|
||||||
GioView.this.onFocusChange(nhandle, focus);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
setOnFocusChangeListener(focusCallback);
|
|
||||||
surfCallbacks = new SurfaceHolder.Callback() {
|
surfCallbacks = new SurfaceHolder.Callback() {
|
||||||
@Override public void surfaceCreated(SurfaceHolder holder) {
|
@Override public void surfaceCreated(SurfaceHolder holder) {
|
||||||
// Ignore; surfaceChanged is guaranteed to be called immediately after this.
|
// Ignore; surfaceChanged is guaranteed to be called immediately after this.
|
||||||
@@ -259,6 +253,10 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setHighRefreshRate() {
|
private void setHighRefreshRate() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
Display display = context.getDisplay();
|
Display display = context.getDisplay();
|
||||||
Display.Mode[] supportedModes = display.getSupportedModes();
|
Display.Mode[] supportedModes = display.getSupportedModes();
|
||||||
@@ -311,6 +309,15 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
|
|||||||
window.setAttributes(layoutParams);
|
window.setAttributes(layoutParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onIntentEvent(Intent intent) {
|
||||||
|
if (intent == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (intent.getData() != null) {
|
||||||
|
this.onOpenURI(nhandle, intent.getData().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override protected boolean dispatchHoverEvent(MotionEvent event) {
|
@Override protected boolean dispatchHoverEvent(MotionEvent event) {
|
||||||
if (!accessManager.isTouchExplorationEnabled()) {
|
if (!accessManager.isTouchExplorationEnabled()) {
|
||||||
return super.dispatchHoverEvent(event);
|
return super.dispatchHoverEvent(event);
|
||||||
@@ -468,6 +475,18 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pause() {
|
||||||
|
if (nhandle != 0) {
|
||||||
|
onFocusChange(nhandle, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resume() {
|
||||||
|
if (nhandle != 0) {
|
||||||
|
onFocusChange(nhandle, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
if (nhandle != 0) {
|
if (nhandle != 0) {
|
||||||
onDestroyView(nhandle);
|
onDestroyView(nhandle);
|
||||||
@@ -549,6 +568,7 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
|
|||||||
static private native void onExitTouchExploration(long handle);
|
static private native void onExitTouchExploration(long handle);
|
||||||
static private native void onA11yFocus(long handle, int viewId);
|
static private native void onA11yFocus(long handle, int viewId);
|
||||||
static private native void onClearA11yFocus(long handle, int viewId);
|
static private native void onClearA11yFocus(long handle, int viewId);
|
||||||
|
static private native void onOpenURI(long handle, String uri);
|
||||||
static private native void imeSetSnippet(long handle, int start, int end);
|
static private native void imeSetSnippet(long handle, int start, int end);
|
||||||
static private native String imeSnippet(long handle);
|
static private native String imeSnippet(long handle);
|
||||||
static private native int imeSnippetStart(long handle);
|
static private native int imeSnippetStart(long handle);
|
||||||
|
|||||||
+56
-2
@@ -3,7 +3,10 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gioui.org/io/event"
|
||||||
|
"golang.org/x/net/idna"
|
||||||
"image"
|
"image"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -56,11 +59,24 @@ type FrameEvent struct {
|
|||||||
Source input.Source
|
Source input.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// URLEvent is generated for external requests to open a URL. Unlike window specific events,
|
||||||
|
// it is delivered through the [Events] iterator.
|
||||||
|
//
|
||||||
|
// In order to receive URLEvents the program must register one or more URL schemes. A scheme can
|
||||||
|
// be registered using gogio, with the `-schemes` flag.
|
||||||
|
type URLEvent struct {
|
||||||
|
URL *url.URL
|
||||||
|
}
|
||||||
|
|
||||||
// ViewEvent provides handles to the underlying window objects for the
|
// ViewEvent provides handles to the underlying window objects for the
|
||||||
// current display protocol.
|
// current display protocol.
|
||||||
type ViewEvent interface {
|
type ViewEvent interface {
|
||||||
implementsViewEvent()
|
implementsViewEvent()
|
||||||
ImplementsEvent()
|
ImplementsEvent()
|
||||||
|
// Valid will return true when the ViewEvent does contains valid handles.
|
||||||
|
// If a window receives an invalid ViewEvent, it should deinitialize any
|
||||||
|
// state referring to handles from a previous ViewEvent.
|
||||||
|
Valid() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insets is the space taken up by
|
// Insets is the space taken up by
|
||||||
@@ -114,8 +130,7 @@ func NewContext(ops *op.Ops, e FrameEvent) layout.Context {
|
|||||||
// On iOS NSDocumentDirectory is queried.
|
// On iOS NSDocumentDirectory is queried.
|
||||||
// For Android Context.getFilesDir is used.
|
// For Android Context.getFilesDir is used.
|
||||||
//
|
//
|
||||||
// BUG: DataDir blocks on Android until init functions
|
// BUG: On Android, DataDir panics if called before main.
|
||||||
// have completed.
|
|
||||||
func DataDir() (string, error) {
|
func DataDir() (string, error) {
|
||||||
return dataDir()
|
return dataDir()
|
||||||
}
|
}
|
||||||
@@ -132,7 +147,29 @@ func Main() {
|
|||||||
osMain()
|
osMain()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Events is an iterator that yields events that are not specific to any window,
|
||||||
|
// such as [URLEvent]. It never returns.
|
||||||
|
//
|
||||||
|
// Events must be called by the main goroutine, and replaces the
|
||||||
|
// call to [Main].
|
||||||
|
func Events(yield func(event.Event) bool) {
|
||||||
|
yieldGlobalEvent = yield
|
||||||
|
osMain()
|
||||||
|
}
|
||||||
|
|
||||||
|
var yieldGlobalEvent func(evt event.Event) bool
|
||||||
|
|
||||||
|
func processGlobalEvent(evt event.Event) {
|
||||||
|
if yieldGlobalEvent == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !yieldGlobalEvent(evt) {
|
||||||
|
yieldGlobalEvent = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (FrameEvent) ImplementsEvent() {}
|
func (FrameEvent) ImplementsEvent() {}
|
||||||
|
func (URLEvent) ImplementsEvent() {}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if extraArgs != "" {
|
if extraArgs != "" {
|
||||||
@@ -143,3 +180,20 @@ func init() {
|
|||||||
ID = filepath.Base(os.Args[0])
|
ID = filepath.Base(os.Args[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newURLEvent creates a URLEvent from a raw URL string, handling Punycode decoding.
|
||||||
|
func newURLEvent(rawurl string) (URLEvent, error) {
|
||||||
|
u, err := url.Parse(rawurl)
|
||||||
|
if err != nil {
|
||||||
|
return URLEvent{}, err
|
||||||
|
}
|
||||||
|
u.Host, err = idna.Punycode.ToUnicode(u.Hostname())
|
||||||
|
if err != nil {
|
||||||
|
return URLEvent{}, err
|
||||||
|
}
|
||||||
|
u, err = url.Parse(u.String())
|
||||||
|
if err != nil {
|
||||||
|
return URLEvent{}, err
|
||||||
|
}
|
||||||
|
return URLEvent{URL: u}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build !android
|
//go:build !android
|
||||||
// +build !android
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -48,7 +48,7 @@ For example, to display a blank but otherwise functional window:
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go func() {
|
go func() {
|
||||||
w := app.NewWindow()
|
w := new(app.Window)
|
||||||
for {
|
for {
|
||||||
w.Event()
|
w.Event()
|
||||||
}
|
}
|
||||||
@@ -56,6 +56,11 @@ For example, to display a blank but otherwise functional window:
|
|||||||
app.Main()
|
app.Main()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Events
|
||||||
|
|
||||||
|
The [Events] iterator yields app-specific events such as [URLEvent]. [Window.Event]
|
||||||
|
yields events that target a particular window.
|
||||||
|
|
||||||
# Permissions
|
# Permissions
|
||||||
|
|
||||||
The packages under gioui.org/app/permission should be imported
|
The packages under gioui.org/app/permission should be imported
|
||||||
|
|||||||
+4
-6
@@ -17,9 +17,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type androidContext struct {
|
type androidContext struct {
|
||||||
win *window
|
win *window
|
||||||
eglSurf egl.NativeWindowType
|
eglSurf egl.NativeWindowType
|
||||||
width, height int
|
|
||||||
*egl.Context
|
*egl.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,9 +44,8 @@ func (c *androidContext) Refresh() error {
|
|||||||
if err := c.win.setVisual(c.Context.VisualID()); err != nil {
|
if err := c.win.setVisual(c.Context.VisualID()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
win, width, height := c.win.nativeWindow()
|
win, _, _ := c.win.nativeWindow()
|
||||||
c.eglSurf = egl.NativeWindowType(unsafe.Pointer(win))
|
c.eglSurf = egl.NativeWindowType(unsafe.Pointer(win))
|
||||||
c.width, c.height = width, height
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +53,7 @@ func (c *androidContext) Lock() error {
|
|||||||
// The Android emulator creates a broken surface if it is not
|
// The Android emulator creates a broken surface if it is not
|
||||||
// created on the same thread as the context is made current.
|
// created on the same thread as the context is made current.
|
||||||
if c.eglSurf != nil {
|
if c.eglSurf != nil {
|
||||||
if err := c.Context.CreateSurface(c.eglSurf, c.width, c.height); err != nil {
|
if err := c.Context.CreateSurface(c.eglSurf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.eglSurf = nil
|
c.eglSurf = nil
|
||||||
|
|||||||
+19
-22
@@ -38,7 +38,24 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &wlContext{Context: ctx, win: w}, nil
|
|
||||||
|
surf, width, height := w.surface()
|
||||||
|
if surf == nil {
|
||||||
|
return nil, errors.New("wayland: no surface")
|
||||||
|
}
|
||||||
|
eglWin := C.wl_egl_window_create(surf, C.int(width), C.int(height))
|
||||||
|
if eglWin == nil {
|
||||||
|
return nil, errors.New("wayland: wl_egl_window_create failed")
|
||||||
|
}
|
||||||
|
eglSurf := egl.NativeWindowType(uintptr(unsafe.Pointer(eglWin)))
|
||||||
|
if err := ctx.CreateSurface(eglSurf); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// We're in charge of the frame callbacks, don't let eglSwapBuffers
|
||||||
|
// wait for callbacks that may never arrive.
|
||||||
|
ctx.EnableVSync(false)
|
||||||
|
|
||||||
|
return &wlContext{Context: ctx, win: w, eglWin: eglWin}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,31 +71,11 @@ func (c *wlContext) Release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *wlContext) Refresh() error {
|
func (c *wlContext) Refresh() error {
|
||||||
c.Context.ReleaseSurface()
|
|
||||||
if c.eglWin != nil {
|
|
||||||
C.wl_egl_window_destroy(c.eglWin)
|
|
||||||
c.eglWin = nil
|
|
||||||
}
|
|
||||||
surf, width, height := c.win.surface()
|
surf, width, height := c.win.surface()
|
||||||
if surf == nil {
|
if surf == nil {
|
||||||
return errors.New("wayland: no surface")
|
return errors.New("wayland: no surface")
|
||||||
}
|
}
|
||||||
eglWin := C.wl_egl_window_create(surf, C.int(width), C.int(height))
|
C.wl_egl_window_resize(c.eglWin, C.int(width), C.int(height), 0, 0)
|
||||||
if eglWin == nil {
|
|
||||||
return errors.New("wayland: wl_egl_window_create failed")
|
|
||||||
}
|
|
||||||
c.eglWin = eglWin
|
|
||||||
eglSurf := egl.NativeWindowType(uintptr(unsafe.Pointer(eglWin)))
|
|
||||||
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := c.Context.MakeCurrent(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer c.Context.ReleaseCurrent()
|
|
||||||
// We're in charge of the frame callbacks, don't let eglSwapBuffers
|
|
||||||
// wait for callbacks that may never arrive.
|
|
||||||
c.Context.EnableVSync(false)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-17
@@ -5,8 +5,6 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
|
|
||||||
"gioui.org/internal/egl"
|
"gioui.org/internal/egl"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,6 +22,18 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
win, _, _ := w.HWND()
|
||||||
|
eglSurf := egl.NativeWindowType(win)
|
||||||
|
if err := ctx.CreateSurface(eglSurf); err != nil {
|
||||||
|
ctx.Release()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := ctx.MakeCurrent(); err != nil {
|
||||||
|
ctx.Release()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer ctx.ReleaseCurrent()
|
||||||
|
ctx.EnableVSync(true)
|
||||||
return &glContext{win: w, Context: ctx}, nil
|
return &glContext{win: w, Context: ctx}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -37,21 +47,6 @@ func (c *glContext) Release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *glContext) Refresh() error {
|
func (c *glContext) Refresh() error {
|
||||||
c.Context.ReleaseSurface()
|
|
||||||
var (
|
|
||||||
win windows.Handle
|
|
||||||
width, height int
|
|
||||||
)
|
|
||||||
win, width, height = c.win.HWND()
|
|
||||||
eglSurf := egl.NativeWindowType(win)
|
|
||||||
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := c.Context.MakeCurrent(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Context.EnableVSync(true)
|
|
||||||
c.Context.ReleaseCurrent()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-11
@@ -25,6 +25,18 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
win, _, _ := w.window()
|
||||||
|
eglSurf := egl.NativeWindowType(uintptr(win))
|
||||||
|
if err := ctx.CreateSurface(eglSurf); err != nil {
|
||||||
|
ctx.Release()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := ctx.MakeCurrent(); err != nil {
|
||||||
|
ctx.Release()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer ctx.ReleaseCurrent()
|
||||||
|
ctx.EnableVSync(true)
|
||||||
return &x11Context{win: w, Context: ctx}, nil
|
return &x11Context{win: w, Context: ctx}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,17 +49,6 @@ func (c *x11Context) Release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *x11Context) Refresh() error {
|
func (c *x11Context) Refresh() error {
|
||||||
c.Context.ReleaseSurface()
|
|
||||||
win, width, height := c.win.window()
|
|
||||||
eglSurf := egl.NativeWindowType(uintptr(win))
|
|
||||||
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := c.Context.MakeCurrent(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer c.Context.ReleaseCurrent()
|
|
||||||
c.Context.EnableVSync(true)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build darwin && ios && nometal
|
//go:build darwin && ios && nometal
|
||||||
// +build darwin,ios,nometal
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build darwin && !ios && nometal
|
//go:build darwin && !ios && nometal
|
||||||
// +build darwin,!ios,nometal
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"gioui.org/gpu"
|
"gioui.org/gpu"
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
#include <OpenGL/OpenGL.h>
|
#include <OpenGL/OpenGL.h>
|
||||||
#include "_cgo_export.h"
|
#include "_cgo_export.h"
|
||||||
|
|
||||||
CALayer *gio_layerFactory(void) {
|
CALayer *gio_layerFactory(BOOL presentWithTrans) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
return [CALayer layer];
|
return [CALayer layer];
|
||||||
}
|
}
|
||||||
|
|||||||
+27
@@ -1,9 +1,11 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf16"
|
"unicode/utf16"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"gioui.org/io/input"
|
"gioui.org/io/input"
|
||||||
"gioui.org/io/key"
|
"gioui.org/io/key"
|
||||||
@@ -116,3 +118,28 @@ func (e *editorState) RunesIndex(chars int) int {
|
|||||||
// Assume runes after snippets are one UTF-16 character each.
|
// Assume runes after snippets are one UTF-16 character each.
|
||||||
return runes + chars
|
return runes + chars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// areSnippetsConsistent reports whether the content of the old snippet is
|
||||||
|
// consistent with the content of the new.
|
||||||
|
func areSnippetsConsistent(old, new key.Snippet) bool {
|
||||||
|
// Compute the overlapping range.
|
||||||
|
r := old.Range
|
||||||
|
r.Start = max(r.Start, new.Start)
|
||||||
|
r.End = max(r.End, r.Start)
|
||||||
|
r.End = min(r.End, new.End)
|
||||||
|
return snippetSubstring(old, r) == snippetSubstring(new, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func snippetSubstring(s key.Snippet, r key.Range) string {
|
||||||
|
for r.Start > s.Start && r.Start < s.End {
|
||||||
|
_, n := utf8.DecodeRuneInString(s.Text)
|
||||||
|
s.Text = s.Text[n:]
|
||||||
|
s.Start++
|
||||||
|
}
|
||||||
|
for r.End < s.End && r.End > s.Start {
|
||||||
|
_, n := utf8.DecodeLastRuneInString(s.Text)
|
||||||
|
s.Text = s.Text[:len(s.Text)-n]
|
||||||
|
s.End--
|
||||||
|
}
|
||||||
|
return s.Text
|
||||||
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,11 +1,9 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build go1.18
|
|
||||||
// +build go1.18
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gioui.org/f32"
|
||||||
"testing"
|
"testing"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
@@ -40,6 +38,7 @@ func FuzzIME(f *testing.F) {
|
|||||||
r.Frame(gtx.Ops)
|
r.Frame(gtx.Ops)
|
||||||
|
|
||||||
var state editorState
|
var state editorState
|
||||||
|
state.Selection.Transform = f32.AffineId()
|
||||||
const (
|
const (
|
||||||
cmdReplace = iota
|
cmdReplace = iota
|
||||||
cmdSelect
|
cmdSelect
|
||||||
@@ -139,6 +138,7 @@ func FuzzIME(f *testing.F) {
|
|||||||
|
|
||||||
func TestEditorIndices(t *testing.T) {
|
func TestEditorIndices(t *testing.T) {
|
||||||
var s editorState
|
var s editorState
|
||||||
|
s.Selection.Transform = f32.AffineId()
|
||||||
const str = "Hello, 😀"
|
const str = "Hello, 😀"
|
||||||
s.Snippet = key.Snippet{
|
s.Snippet = key.Snippet{
|
||||||
Text: str,
|
Text: str,
|
||||||
|
|||||||
+182
-42
@@ -108,6 +108,80 @@ type MonitorInfo struct {
|
|||||||
Flags uint32
|
Flags uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CopyDataStruct struct {
|
||||||
|
DwData uintptr
|
||||||
|
CbData uint32
|
||||||
|
LpData uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type POINTER_INPUT_TYPE int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
PT_POINTER POINTER_INPUT_TYPE = 1
|
||||||
|
PT_TOUCH POINTER_INPUT_TYPE = 2
|
||||||
|
PT_PEN POINTER_INPUT_TYPE = 3
|
||||||
|
PT_MOUSE POINTER_INPUT_TYPE = 4
|
||||||
|
PT_TOUCHPAD POINTER_INPUT_TYPE = 5
|
||||||
|
)
|
||||||
|
|
||||||
|
type POINTER_INFO_POINTER_FLAGS int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
POINTER_FLAG_NEW POINTER_INFO_POINTER_FLAGS = 0x00000001
|
||||||
|
POINTER_FLAG_INRANGE POINTER_INFO_POINTER_FLAGS = 0x00000002
|
||||||
|
POINTER_FLAG_INCONTACT POINTER_INFO_POINTER_FLAGS = 0x00000004
|
||||||
|
POINTER_FLAG_FIRSTBUTTON POINTER_INFO_POINTER_FLAGS = 0x00000010
|
||||||
|
POINTER_FLAG_SECONDBUTTON POINTER_INFO_POINTER_FLAGS = 0x00000020
|
||||||
|
POINTER_FLAG_THIRDBUTTON POINTER_INFO_POINTER_FLAGS = 0x00000040
|
||||||
|
POINTER_FLAG_FOURTHBUTTON POINTER_INFO_POINTER_FLAGS = 0x00000080
|
||||||
|
POINTER_FLAG_FIFTHBUTTON POINTER_INFO_POINTER_FLAGS = 0x00000100
|
||||||
|
POINTER_FLAG_PRIMARY POINTER_INFO_POINTER_FLAGS = 0x00002000
|
||||||
|
POINTER_FLAG_CONFIDENCE POINTER_INFO_POINTER_FLAGS = 0x00004000
|
||||||
|
POINTER_FLAG_CANCELED POINTER_INFO_POINTER_FLAGS = 0x00008000
|
||||||
|
POINTER_FLAG_DOWN POINTER_INFO_POINTER_FLAGS = 0x00010000
|
||||||
|
POINTER_FLAG_UPDATE POINTER_INFO_POINTER_FLAGS = 0x00020000
|
||||||
|
POINTER_FLAG_UP POINTER_INFO_POINTER_FLAGS = 0x00040000
|
||||||
|
POINTER_FLAG_WHEEL POINTER_INFO_POINTER_FLAGS = 0x00080000
|
||||||
|
POINTER_FLAG_HWHEEL POINTER_INFO_POINTER_FLAGS = 0x00100000
|
||||||
|
POINTER_FLAG_CAPTURECHANGED POINTER_INFO_POINTER_FLAGS = 0x00200000
|
||||||
|
POINTER_FLAG_HASTRANSFORM POINTER_INFO_POINTER_FLAGS = 0x00400000
|
||||||
|
)
|
||||||
|
|
||||||
|
type POINTER_BUTTON_CHANGE_TYPE int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
POINTER_CHANGE_NONE POINTER_BUTTON_CHANGE_TYPE = 0
|
||||||
|
POINTER_CHANGE_FIRSTBUTTON_DOWN POINTER_BUTTON_CHANGE_TYPE = 1
|
||||||
|
POINTER_CHANGE_FIRSTBUTTON_UP POINTER_BUTTON_CHANGE_TYPE = 2
|
||||||
|
POINTER_CHANGE_SECONDBUTTON_DOWN POINTER_BUTTON_CHANGE_TYPE = 3
|
||||||
|
POINTER_CHANGE_SECONDBUTTON_UP POINTER_BUTTON_CHANGE_TYPE = 4
|
||||||
|
POINTER_CHANGE_THIRDBUTTON_DOWN POINTER_BUTTON_CHANGE_TYPE = 5
|
||||||
|
POINTER_CHANGE_THIRDBUTTON_UP POINTER_BUTTON_CHANGE_TYPE = 6
|
||||||
|
POINTER_CHANGE_FOURTHBUTTON_DOWN POINTER_BUTTON_CHANGE_TYPE = 7
|
||||||
|
POINTER_CHANGE_FOURTHBUTTON_UP POINTER_BUTTON_CHANGE_TYPE = 8
|
||||||
|
POINTER_CHANGE_FIFTHBUTTON_DOWN POINTER_BUTTON_CHANGE_TYPE = 9
|
||||||
|
POINTER_CHANGE_FIFTHBUTTON_UP POINTER_BUTTON_CHANGE_TYPE = 10
|
||||||
|
)
|
||||||
|
|
||||||
|
type PointerInfo struct {
|
||||||
|
PointerType POINTER_INPUT_TYPE
|
||||||
|
PointerId uint32
|
||||||
|
FrameId uint32
|
||||||
|
PointerFlags POINTER_INFO_POINTER_FLAGS
|
||||||
|
SourceDevice syscall.Handle
|
||||||
|
HwndTarget syscall.Handle
|
||||||
|
PtPixelLocation Point
|
||||||
|
PtHimetricLocation Point
|
||||||
|
PtPixelLocationRaw Point
|
||||||
|
PtHimetricLocationRaw Point
|
||||||
|
DwTime uint32
|
||||||
|
HistoryCount uint32
|
||||||
|
InputData int32
|
||||||
|
DwKeyStates uint32
|
||||||
|
PerformanceCount uint64
|
||||||
|
ButtonChangeType POINTER_BUTTON_CHANGE_TYPE
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TRUE = 1
|
TRUE = 1
|
||||||
|
|
||||||
@@ -133,7 +207,9 @@ const (
|
|||||||
CFS_POINT = 0x0002
|
CFS_POINT = 0x0002
|
||||||
CFS_CANDIDATEPOS = 0x0040
|
CFS_CANDIDATEPOS = 0x0040
|
||||||
|
|
||||||
HWND_TOPMOST = ^(uint32(1) - 1) // -1
|
HWND_TOP = syscall.Handle(0)
|
||||||
|
HWND_TOPMOST = ^(syscall.Handle(1) - 1) // -1
|
||||||
|
HWND_NOTOPMOST = ^(syscall.Handle(2) - 1) // -2
|
||||||
|
|
||||||
HTCAPTION = 2
|
HTCAPTION = 2
|
||||||
HTCLIENT = 1
|
HTCLIENT = 1
|
||||||
@@ -244,44 +320,52 @@ const (
|
|||||||
|
|
||||||
UNICODE_NOCHAR = 65535
|
UNICODE_NOCHAR = 65535
|
||||||
|
|
||||||
WM_CANCELMODE = 0x001F
|
WM_CANCELMODE = 0x001F
|
||||||
WM_CHAR = 0x0102
|
WM_CHAR = 0x0102
|
||||||
WM_CLOSE = 0x0010
|
WM_CLOSE = 0x0010
|
||||||
WM_CREATE = 0x0001
|
WM_COPYDATA = 0x004A
|
||||||
WM_DPICHANGED = 0x02E0
|
WM_CREATE = 0x0001
|
||||||
WM_DESTROY = 0x0002
|
WM_DPICHANGED = 0x02E0
|
||||||
WM_ERASEBKGND = 0x0014
|
WM_DESTROY = 0x0002
|
||||||
WM_GETMINMAXINFO = 0x0024
|
WM_ERASEBKGND = 0x0014
|
||||||
WM_IME_COMPOSITION = 0x010F
|
WM_GETMINMAXINFO = 0x0024
|
||||||
WM_IME_ENDCOMPOSITION = 0x010E
|
WM_IME_COMPOSITION = 0x010F
|
||||||
WM_IME_STARTCOMPOSITION = 0x010D
|
WM_IME_ENDCOMPOSITION = 0x010E
|
||||||
WM_KEYDOWN = 0x0100
|
WM_IME_STARTCOMPOSITION = 0x010D
|
||||||
WM_KEYUP = 0x0101
|
WM_KEYDOWN = 0x0100
|
||||||
WM_KILLFOCUS = 0x0008
|
WM_KEYUP = 0x0101
|
||||||
WM_LBUTTONDOWN = 0x0201
|
WM_KILLFOCUS = 0x0008
|
||||||
WM_LBUTTONUP = 0x0202
|
WM_LBUTTONDOWN = 0x0201
|
||||||
WM_MBUTTONDOWN = 0x0207
|
WM_LBUTTONUP = 0x0202
|
||||||
WM_MBUTTONUP = 0x0208
|
WM_MBUTTONDOWN = 0x0207
|
||||||
WM_MOUSEMOVE = 0x0200
|
WM_MBUTTONUP = 0x0208
|
||||||
WM_MOUSEWHEEL = 0x020A
|
WM_MOUSEMOVE = 0x0200
|
||||||
WM_MOUSEHWHEEL = 0x020E
|
WM_MOUSEWHEEL = 0x020A
|
||||||
WM_NCACTIVATE = 0x0086
|
WM_MOUSEHWHEEL = 0x020E
|
||||||
WM_NCHITTEST = 0x0084
|
WM_NCACTIVATE = 0x0086
|
||||||
WM_NCCALCSIZE = 0x0083
|
WM_NCHITTEST = 0x0084
|
||||||
WM_PAINT = 0x000F
|
WM_NCCALCSIZE = 0x0083
|
||||||
WM_QUIT = 0x0012
|
WM_PAINT = 0x000F
|
||||||
WM_SETCURSOR = 0x0020
|
WM_POINTERCAPTURECHANGED = 0x024C
|
||||||
WM_SETFOCUS = 0x0007
|
WM_POINTERDOWN = 0x0246
|
||||||
WM_SHOWWINDOW = 0x0018
|
WM_POINTERUP = 0x0247
|
||||||
WM_SIZE = 0x0005
|
WM_POINTERUPDATE = 0x0245
|
||||||
WM_SYSKEYDOWN = 0x0104
|
WM_POINTERWHEEL = 0x024E
|
||||||
WM_SYSKEYUP = 0x0105
|
WM_POINTERHWHEEL = 0x024F
|
||||||
WM_RBUTTONDOWN = 0x0204
|
WM_QUIT = 0x0012
|
||||||
WM_RBUTTONUP = 0x0205
|
WM_RBUTTONDOWN = 0x0204
|
||||||
WM_TIMER = 0x0113
|
WM_RBUTTONUP = 0x0205
|
||||||
WM_UNICHAR = 0x0109
|
WM_SETCURSOR = 0x0020
|
||||||
WM_USER = 0x0400
|
WM_SETFOCUS = 0x0007
|
||||||
WM_WINDOWPOSCHANGED = 0x0047
|
WM_SHOWWINDOW = 0x0018
|
||||||
|
WM_SIZE = 0x0005
|
||||||
|
WM_STYLECHANGED = 0x007D
|
||||||
|
WM_SYSKEYDOWN = 0x0104
|
||||||
|
WM_SYSKEYUP = 0x0105
|
||||||
|
WM_TIMER = 0x0113
|
||||||
|
WM_UNICHAR = 0x0109
|
||||||
|
WM_USER = 0x0400
|
||||||
|
WM_WINDOWPOSCHANGED = 0x0047
|
||||||
|
|
||||||
WS_CLIPCHILDREN = 0x02000000
|
WS_CLIPCHILDREN = 0x02000000
|
||||||
WS_CLIPSIBLINGS = 0x04000000
|
WS_CLIPSIBLINGS = 0x04000000
|
||||||
@@ -344,7 +428,9 @@ var (
|
|||||||
_DefWindowProc = user32.NewProc("DefWindowProcW")
|
_DefWindowProc = user32.NewProc("DefWindowProcW")
|
||||||
_DestroyWindow = user32.NewProc("DestroyWindow")
|
_DestroyWindow = user32.NewProc("DestroyWindow")
|
||||||
_DispatchMessage = user32.NewProc("DispatchMessageW")
|
_DispatchMessage = user32.NewProc("DispatchMessageW")
|
||||||
|
_FindWindow = user32.NewProc("FindWindowW")
|
||||||
_EmptyClipboard = user32.NewProc("EmptyClipboard")
|
_EmptyClipboard = user32.NewProc("EmptyClipboard")
|
||||||
|
_EnableMouseInPointer = user32.NewProc("EnableMouseInPointer")
|
||||||
_GetWindowRect = user32.NewProc("GetWindowRect")
|
_GetWindowRect = user32.NewProc("GetWindowRect")
|
||||||
_GetClientRect = user32.NewProc("GetClientRect")
|
_GetClientRect = user32.NewProc("GetClientRect")
|
||||||
_GetClipboardData = user32.NewProc("GetClipboardData")
|
_GetClipboardData = user32.NewProc("GetClipboardData")
|
||||||
@@ -354,6 +440,7 @@ var (
|
|||||||
_GetMessage = user32.NewProc("GetMessageW")
|
_GetMessage = user32.NewProc("GetMessageW")
|
||||||
_GetMessageTime = user32.NewProc("GetMessageTime")
|
_GetMessageTime = user32.NewProc("GetMessageTime")
|
||||||
_GetMonitorInfo = user32.NewProc("GetMonitorInfoW")
|
_GetMonitorInfo = user32.NewProc("GetMonitorInfoW")
|
||||||
|
_GetPointerInfo = user32.NewProc("GetPointerInfo")
|
||||||
_GetSystemMetrics = user32.NewProc("GetSystemMetrics")
|
_GetSystemMetrics = user32.NewProc("GetSystemMetrics")
|
||||||
_GetWindowLong = user32.NewProc("GetWindowLongPtrW")
|
_GetWindowLong = user32.NewProc("GetWindowLongPtrW")
|
||||||
_GetWindowLong32 = user32.NewProc("GetWindowLongW")
|
_GetWindowLong32 = user32.NewProc("GetWindowLongW")
|
||||||
@@ -371,9 +458,11 @@ var (
|
|||||||
_PostQuitMessage = user32.NewProc("PostQuitMessage")
|
_PostQuitMessage = user32.NewProc("PostQuitMessage")
|
||||||
_ReleaseCapture = user32.NewProc("ReleaseCapture")
|
_ReleaseCapture = user32.NewProc("ReleaseCapture")
|
||||||
_RegisterClassExW = user32.NewProc("RegisterClassExW")
|
_RegisterClassExW = user32.NewProc("RegisterClassExW")
|
||||||
|
_RegisterTouchWindow = user32.NewProc("RegisterTouchWindow")
|
||||||
_ReleaseDC = user32.NewProc("ReleaseDC")
|
_ReleaseDC = user32.NewProc("ReleaseDC")
|
||||||
_ScreenToClient = user32.NewProc("ScreenToClient")
|
_ScreenToClient = user32.NewProc("ScreenToClient")
|
||||||
_ShowWindow = user32.NewProc("ShowWindow")
|
_ShowWindow = user32.NewProc("ShowWindow")
|
||||||
|
_SendMessage = user32.NewProc("SendMessageW")
|
||||||
_SetCapture = user32.NewProc("SetCapture")
|
_SetCapture = user32.NewProc("SetCapture")
|
||||||
_SetCursor = user32.NewProc("SetCursor")
|
_SetCursor = user32.NewProc("SetCursor")
|
||||||
_SetClipboardData = user32.NewProc("SetClipboardData")
|
_SetClipboardData = user32.NewProc("SetClipboardData")
|
||||||
@@ -426,7 +515,10 @@ func CloseClipboard() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateWindowEx(dwExStyle uint32, lpClassName uint16, lpWindowName string, dwStyle uint32, x, y, w, h int32, hWndParent, hMenu, hInstance syscall.Handle, lpParam uintptr) (syscall.Handle, error) {
|
func CreateWindowEx(dwExStyle uint32, lpClassName uint16, lpWindowName string, dwStyle uint32, x, y, w, h int32, hWndParent, hMenu, hInstance syscall.Handle, lpParam uintptr) (syscall.Handle, error) {
|
||||||
wname := syscall.StringToUTF16Ptr(lpWindowName)
|
wname, err := syscall.UTF16PtrFromString(lpWindowName)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("CreateWindowEx failed: %v", err)
|
||||||
|
}
|
||||||
hwnd, _, err := _CreateWindowEx.Call(
|
hwnd, _, err := _CreateWindowEx.Call(
|
||||||
uintptr(dwExStyle),
|
uintptr(dwExStyle),
|
||||||
uintptr(lpClassName),
|
uintptr(lpClassName),
|
||||||
@@ -444,6 +536,31 @@ func CreateWindowEx(dwExStyle uint32, lpClassName uint16, lpWindowName string, d
|
|||||||
return syscall.Handle(hwnd), nil
|
return syscall.Handle(hwnd), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPointerInfo(pointerId uint32) (PointerInfo, error) {
|
||||||
|
var info PointerInfo
|
||||||
|
r1, _, err := _GetPointerInfo.Call(uintptr(pointerId), uintptr(unsafe.Pointer(&info)))
|
||||||
|
if r1 == 0 {
|
||||||
|
return PointerInfo{}, fmt.Errorf("GetPointerInfo failed: %v", err)
|
||||||
|
}
|
||||||
|
return info, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterTouchWindow(hwnd syscall.Handle, flags uint32) error {
|
||||||
|
r1, _, err := _RegisterTouchWindow.Call(uintptr(hwnd), uintptr(flags))
|
||||||
|
if r1 == 0 {
|
||||||
|
return fmt.Errorf("RegisterTouchWindow failed: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnableMouseInPointer(enable uint) error {
|
||||||
|
r1, _, err := _EnableMouseInPointer.Call(uintptr(enable))
|
||||||
|
if r1 == 0 {
|
||||||
|
return fmt.Errorf("EnableMouseInPointer failed: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func DefWindowProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) uintptr {
|
func DefWindowProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) uintptr {
|
||||||
r, _, _ := _DefWindowProc.Call(uintptr(hwnd), uintptr(msg), wparam, lparam)
|
r, _, _ := _DefWindowProc.Call(uintptr(hwnd), uintptr(msg), wparam, lparam)
|
||||||
return r
|
return r
|
||||||
@@ -473,6 +590,18 @@ func EmptyClipboard() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindWindow(lpClassName string) (syscall.Handle, error) {
|
||||||
|
className, err := syscall.UTF16PtrFromString(lpClassName)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("FindWindow failed: %v", err)
|
||||||
|
}
|
||||||
|
hwnd, _, err := _FindWindow.Call(uintptr(unsafe.Pointer(className)), 0)
|
||||||
|
if hwnd == 0 {
|
||||||
|
return 0, fmt.Errorf("FindWindow failed: %v", err)
|
||||||
|
}
|
||||||
|
return syscall.Handle(hwnd), nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetWindowRect(hwnd syscall.Handle) Rect {
|
func GetWindowRect(hwnd syscall.Handle) Rect {
|
||||||
var r Rect
|
var r Rect
|
||||||
_GetWindowRect.Call(uintptr(hwnd), uintptr(unsafe.Pointer(&r)))
|
_GetWindowRect.Call(uintptr(hwnd), uintptr(unsafe.Pointer(&r)))
|
||||||
@@ -655,7 +784,7 @@ func SetWindowPlacement(hwnd syscall.Handle, wp *WindowPlacement) {
|
|||||||
_SetWindowPlacement.Call(uintptr(hwnd), uintptr(unsafe.Pointer(wp)))
|
_SetWindowPlacement.Call(uintptr(hwnd), uintptr(unsafe.Pointer(wp)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetWindowPos(hwnd syscall.Handle, hwndInsertAfter uint32, x, y, dx, dy int32, style uintptr) {
|
func SetWindowPos(hwnd, hwndInsertAfter syscall.Handle, x, y, dx, dy int32, style uintptr) {
|
||||||
_SetWindowPos.Call(uintptr(hwnd), uintptr(hwndInsertAfter),
|
_SetWindowPos.Call(uintptr(hwnd), uintptr(hwndInsertAfter),
|
||||||
uintptr(x), uintptr(y),
|
uintptr(x), uintptr(y),
|
||||||
uintptr(dx), uintptr(dy),
|
uintptr(dx), uintptr(dy),
|
||||||
@@ -664,7 +793,10 @@ func SetWindowPos(hwnd syscall.Handle, hwndInsertAfter uint32, x, y, dx, dy int3
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetWindowText(hwnd syscall.Handle, title string) {
|
func SetWindowText(hwnd syscall.Handle, title string) {
|
||||||
wname := syscall.StringToUTF16Ptr(title)
|
wname, err := syscall.UTF16PtrFromString(title)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
_SetWindowText.Call(uintptr(hwnd), uintptr(unsafe.Pointer(wname)))
|
_SetWindowText.Call(uintptr(hwnd), uintptr(unsafe.Pointer(wname)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -780,6 +912,14 @@ func ReleaseDC(hdc syscall.Handle) {
|
|||||||
_ReleaseDC.Call(uintptr(hdc))
|
_ReleaseDC.Call(uintptr(hdc))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SendMessage(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) error {
|
||||||
|
r, _, err := _SendMessage.Call(uintptr(hwnd), uintptr(msg), wParam, lParam)
|
||||||
|
if r == 0 {
|
||||||
|
return fmt.Errorf("SendMessage failed: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func SetForegroundWindow(hwnd syscall.Handle) {
|
func SetForegroundWindow(hwnd syscall.Handle) {
|
||||||
_SetForegroundWindow.Call(uintptr(hwnd))
|
_SetForegroundWindow.Call(uintptr(hwnd))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build darwin && ios
|
//go:build darwin && ios
|
||||||
// +build darwin,ios
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -4,14 +4,15 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
syscall "golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
type logger struct{}
|
type logger struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
kernel32 = syscall.NewLazyDLL("kernel32")
|
kernel32 = syscall.NewLazySystemDLL("kernel32")
|
||||||
outputDebugStringW = kernel32.NewProc("OutputDebugStringW")
|
outputDebugStringW = kernel32.NewProc("OutputDebugStringW")
|
||||||
debugView *logger
|
debugView *logger
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-2
@@ -60,8 +60,9 @@ static void presentDrawable(CFTypeRef queueRef, CFTypeRef drawableRef) {
|
|||||||
id<MTLDrawable> drawable = (__bridge id<MTLDrawable>)drawableRef;
|
id<MTLDrawable> drawable = (__bridge id<MTLDrawable>)drawableRef;
|
||||||
id<MTLCommandQueue> queue = (__bridge id<MTLCommandQueue>)queueRef;
|
id<MTLCommandQueue> queue = (__bridge id<MTLCommandQueue>)queueRef;
|
||||||
id<MTLCommandBuffer> cmdBuffer = [queue commandBuffer];
|
id<MTLCommandBuffer> cmdBuffer = [queue commandBuffer];
|
||||||
[cmdBuffer presentDrawable:drawable];
|
|
||||||
[cmdBuffer commit];
|
[cmdBuffer commit];
|
||||||
|
[cmdBuffer waitUntilScheduled];
|
||||||
|
[drawable present];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ func newMtlContext(w *window) (*mtlContext, error) {
|
|||||||
return nil, errors.New("metal: CAMetalLayer construction failed")
|
return nil, errors.New("metal: CAMetalLayer construction failed")
|
||||||
}
|
}
|
||||||
queue := C.newCommandQueue(dev)
|
queue := C.newCommandQueue(dev)
|
||||||
if layer == 0 {
|
if queue == 0 {
|
||||||
C.CFRelease(dev)
|
C.CFRelease(dev)
|
||||||
C.CFRelease(layer)
|
C.CFRelease(layer)
|
||||||
return nil, errors.New("metal: [MTLDevice newCommandQueue] failed")
|
return nil, errors.New("metal: [MTLDevice newCommandQueue] failed")
|
||||||
|
|||||||
+4
-2
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build !nometal
|
//go:build !nometal
|
||||||
// +build !nometal
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
@@ -21,7 +20,10 @@ Class gio_layerClass(void) {
|
|||||||
static CFTypeRef getMetalLayer(CFTypeRef viewRef) {
|
static CFTypeRef getMetalLayer(CFTypeRef viewRef) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
UIView *view = (__bridge UIView *)viewRef;
|
UIView *view = (__bridge UIView *)viewRef;
|
||||||
return CFBridgingRetain(view.layer);
|
CAMetalLayer *l = (CAMetalLayer *)view.layer;
|
||||||
|
l.needsDisplayOnBoundsChange = YES;
|
||||||
|
l.presentsWithTransaction = YES;
|
||||||
|
return CFBridgingRetain(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -12,9 +12,13 @@ package app
|
|||||||
#import <QuartzCore/CAMetalLayer.h>
|
#import <QuartzCore/CAMetalLayer.h>
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
|
||||||
CALayer *gio_layerFactory(void) {
|
CALayer *gio_layerFactory(BOOL presentWithTrans) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
return [CAMetalLayer layer];
|
CAMetalLayer *l = [CAMetalLayer layer];
|
||||||
|
l.autoresizingMask = kCALayerHeightSizable|kCALayerWidthSizable;
|
||||||
|
l.needsDisplayOnBoundsChange = YES;
|
||||||
|
l.presentsWithTransaction = presentWithTrans;
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ type Config struct {
|
|||||||
CustomRenderer bool
|
CustomRenderer bool
|
||||||
// Decorated reports whether window decorations are provided automatically.
|
// Decorated reports whether window decorations are provided automatically.
|
||||||
Decorated bool
|
Decorated bool
|
||||||
|
// TopMost windows render above all other non-top-most windows.
|
||||||
|
TopMost bool
|
||||||
|
// Focused reports whether the window is focused.
|
||||||
|
Focused bool
|
||||||
// decoHeight is the height of the fallback decoration for platforms such
|
// decoHeight is the height of the fallback decoration for platforms such
|
||||||
// as Wayland that may need fallback client-side decorations.
|
// as Wayland that may need fallback client-side decorations.
|
||||||
decoHeight unit.Dp
|
decoHeight unit.Dp
|
||||||
@@ -171,19 +175,13 @@ type context interface {
|
|||||||
Unlock()
|
Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// basicDriver is the subset of [driver] that may be called even after
|
|
||||||
// a window is destroyed.
|
|
||||||
type basicDriver interface {
|
|
||||||
// Event blocks until an even is available and returns it.
|
|
||||||
Event() event.Event
|
|
||||||
// Invalidate requests a FrameEvent.
|
|
||||||
Invalidate()
|
|
||||||
}
|
|
||||||
|
|
||||||
// driver is the interface for the platform implementation
|
// driver is the interface for the platform implementation
|
||||||
// of a window.
|
// of a window.
|
||||||
type driver interface {
|
type driver interface {
|
||||||
basicDriver
|
// Event blocks until an event is available and returns it.
|
||||||
|
Event() event.Event
|
||||||
|
// Invalidate requests a FrameEvent.
|
||||||
|
Invalidate()
|
||||||
// SetAnimating sets the animation flag. When the window is animating,
|
// SetAnimating sets the animation flag. When the window is animating,
|
||||||
// FrameEvents are delivered as fast as the display can handle them.
|
// FrameEvents are delivered as fast as the display can handle them.
|
||||||
SetAnimating(anim bool)
|
SetAnimating(anim bool)
|
||||||
@@ -199,8 +197,6 @@ type driver interface {
|
|||||||
Configure([]Option)
|
Configure([]Option)
|
||||||
// SetCursor updates the current cursor to name.
|
// SetCursor updates the current cursor to name.
|
||||||
SetCursor(cursor pointer.Cursor)
|
SetCursor(cursor pointer.Cursor)
|
||||||
// Wakeup wakes up the event loop and sends a WakeupEvent.
|
|
||||||
// Wakeup()
|
|
||||||
// Perform actions on the window.
|
// Perform actions on the window.
|
||||||
Perform(system.Action)
|
Perform(system.Action)
|
||||||
// EditorStateChanged notifies the driver that the editor state changed.
|
// EditorStateChanged notifies the driver that the editor state changed.
|
||||||
|
|||||||
+26
-14
@@ -136,6 +136,8 @@ import (
|
|||||||
"unicode/utf16"
|
"unicode/utf16"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"gioui.org/io/transfer"
|
||||||
|
|
||||||
"gioui.org/internal/f32color"
|
"gioui.org/internal/f32color"
|
||||||
"gioui.org/op"
|
"gioui.org/op"
|
||||||
|
|
||||||
@@ -146,7 +148,6 @@ import (
|
|||||||
"gioui.org/io/pointer"
|
"gioui.org/io/pointer"
|
||||||
"gioui.org/io/semantic"
|
"gioui.org/io/semantic"
|
||||||
"gioui.org/io/system"
|
"gioui.org/io/system"
|
||||||
"gioui.org/io/transfer"
|
|
||||||
"gioui.org/unit"
|
"gioui.org/unit"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -217,8 +218,6 @@ type AndroidViewEvent struct {
|
|||||||
|
|
||||||
type jvalue uint64 // The largest JNI type fits in 64 bits.
|
type jvalue uint64 // The largest JNI type fits in 64 bits.
|
||||||
|
|
||||||
var dataDirChan = make(chan string, 1)
|
|
||||||
|
|
||||||
var android struct {
|
var android struct {
|
||||||
// mu protects all fields of this structure. However, once a
|
// mu protects all fields of this structure. However, once a
|
||||||
// non-nil jvm is returned from javaVM, all the other fields may
|
// non-nil jvm is returned from javaVM, all the other fields may
|
||||||
@@ -294,8 +293,7 @@ var mainWindow = newWindowRendezvous()
|
|||||||
var mainFuncs = make(chan func(env *C.JNIEnv), 1)
|
var mainFuncs = make(chan func(env *C.JNIEnv), 1)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dataDirOnce sync.Once
|
dataPath string
|
||||||
dataPath string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -342,9 +340,9 @@ func (w *window) NewContext() (context, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataDir() (string, error) {
|
func dataDir() (string, error) {
|
||||||
dataDirOnce.Do(func() {
|
if dataPath == "" {
|
||||||
dataPath = <-dataDirChan
|
panic("DataDir isn't valid before main")
|
||||||
})
|
}
|
||||||
return dataPath, nil
|
return dataPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,7 +395,7 @@ func Java_org_gioui_Gio_runGoMain(env *C.JNIEnv, class C.jclass, jdataDir C.jbyt
|
|||||||
os.Setenv("HOME", dataDir)
|
os.Setenv("HOME", dataDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataDirChan <- dataDir
|
dataPath = dataDir
|
||||||
C.jni_ReleaseByteArrayElements(env, jdataDir, dirBytes)
|
C.jni_ReleaseByteArrayElements(env, jdataDir, dirBytes)
|
||||||
|
|
||||||
runMain()
|
runMain()
|
||||||
@@ -575,10 +573,7 @@ func Java_org_gioui_GioView_onFrameCallback(env *C.JNIEnv, class C.jclass, view
|
|||||||
if !exist {
|
if !exist {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.visible && w.animating {
|
w.draw(env, false)
|
||||||
w.draw(env, false)
|
|
||||||
callVoidMethod(env, w.view, gioView.postFrameCallback)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export Java_org_gioui_GioView_onBack
|
//export Java_org_gioui_GioView_onBack
|
||||||
@@ -593,7 +588,8 @@ func Java_org_gioui_GioView_onBack(env *C.JNIEnv, class C.jclass, view C.jlong)
|
|||||||
//export Java_org_gioui_GioView_onFocusChange
|
//export Java_org_gioui_GioView_onFocusChange
|
||||||
func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) {
|
func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) {
|
||||||
w := cgo.Handle(view).Value().(*window)
|
w := cgo.Handle(view).Value().(*window)
|
||||||
w.processEvent(key.FocusEvent{Focus: focus == C.JNI_TRUE})
|
w.config.Focused = focus == C.JNI_TRUE
|
||||||
|
w.processEvent(ConfigEvent{Config: w.config})
|
||||||
}
|
}
|
||||||
|
|
||||||
//export Java_org_gioui_GioView_onWindowInsets
|
//export Java_org_gioui_GioView_onWindowInsets
|
||||||
@@ -666,6 +662,15 @@ func Java_org_gioui_GioView_onClearA11yFocus(env *C.JNIEnv, class C.jclass, view
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export Java_org_gioui_GioView_onOpenURI
|
||||||
|
func Java_org_gioui_GioView_onOpenURI(env *C.JNIEnv, class C.jclass, view C.jlong, uri C.jstring) {
|
||||||
|
evt, err := newURLEvent(goString(env, uri))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
processGlobalEvent(evt)
|
||||||
|
}
|
||||||
|
|
||||||
func (w *window) ProcessEvent(e event.Event) {
|
func (w *window) ProcessEvent(e event.Event) {
|
||||||
w.processEvent(e)
|
w.processEvent(e)
|
||||||
}
|
}
|
||||||
@@ -881,6 +886,9 @@ func (w *window) draw(env *C.JNIEnv, sync bool) {
|
|||||||
},
|
},
|
||||||
Sync: sync,
|
Sync: sync,
|
||||||
})
|
})
|
||||||
|
if w.animating {
|
||||||
|
callVoidMethod(env, w.view, gioView.postFrameCallback)
|
||||||
|
}
|
||||||
a11yActive, err := callBooleanMethod(env, w.view, gioView.isA11yActive)
|
a11yActive, err := callBooleanMethod(env, w.view, gioView.isA11yActive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -1317,6 +1325,7 @@ func findClass(env *C.JNIEnv, name string) C.jclass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func osMain() {
|
func osMain() {
|
||||||
|
select {}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWindow(window *callbacks, options []Option) {
|
func newWindow(window *callbacks, options []Option) {
|
||||||
@@ -1494,3 +1503,6 @@ func Java_org_gioui_Gio_scheduleMainFuncs(env *C.JNIEnv, cls C.jclass) {
|
|||||||
|
|
||||||
func (AndroidViewEvent) implementsViewEvent() {}
|
func (AndroidViewEvent) implementsViewEvent() {}
|
||||||
func (AndroidViewEvent) ImplementsEvent() {}
|
func (AndroidViewEvent) ImplementsEvent() {}
|
||||||
|
func (a AndroidViewEvent) Valid() bool {
|
||||||
|
return a != (AndroidViewEvent{})
|
||||||
|
}
|
||||||
|
|||||||
+14
-17
@@ -5,7 +5,7 @@ package app
|
|||||||
/*
|
/*
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
|
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_wakeupMainThread(void);
|
__attribute__ ((visibility ("hidden"))) void gio_runOnMain(uintptr_t h);
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createDisplayLink(void);
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createDisplayLink(void);
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_releaseDisplayLink(CFTypeRef dl);
|
__attribute__ ((visibility ("hidden"))) void gio_releaseDisplayLink(CFTypeRef dl);
|
||||||
__attribute__ ((visibility ("hidden"))) int gio_startDisplayLink(CFTypeRef dl);
|
__attribute__ ((visibility ("hidden"))) int gio_startDisplayLink(CFTypeRef dl);
|
||||||
@@ -40,8 +40,10 @@ static CFTypeRef newNSString(unichar *chars, NSUInteger length) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"runtime/cgo"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@@ -73,30 +75,25 @@ type displayLink struct {
|
|||||||
// displayLinks maps CFTypeRefs to *displayLinks.
|
// displayLinks maps CFTypeRefs to *displayLinks.
|
||||||
var displayLinks sync.Map
|
var displayLinks sync.Map
|
||||||
|
|
||||||
var mainFuncs = make(chan func(), 1)
|
func isMainThread() bool {
|
||||||
|
return bool(C.isMainThread())
|
||||||
|
}
|
||||||
|
|
||||||
// runOnMain runs the function on the main thread.
|
// runOnMain runs the function on the main thread.
|
||||||
func runOnMain(f func()) {
|
func runOnMain(f func()) {
|
||||||
if C.isMainThread() {
|
if isMainThread() {
|
||||||
f()
|
f()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go func() {
|
C.gio_runOnMain(C.uintptr_t(cgo.NewHandle(f)))
|
||||||
mainFuncs <- f
|
|
||||||
C.gio_wakeupMainThread()
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_dispatchMainFuncs
|
//export gio_runFunc
|
||||||
func gio_dispatchMainFuncs() {
|
func gio_runFunc(h C.uintptr_t) {
|
||||||
for {
|
handle := cgo.Handle(h)
|
||||||
select {
|
defer handle.Delete()
|
||||||
case f := <-mainFuncs:
|
f := handle.Value().(func())
|
||||||
f()
|
f()
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// nsstringToString converts a NSString to a Go string.
|
// nsstringToString converts a NSString to a Go string.
|
||||||
|
|||||||
+2
-2
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
#include "_cgo_export.h"
|
#include "_cgo_export.h"
|
||||||
|
|
||||||
void gio_wakeupMainThread(void) {
|
void gio_runOnMain(uintptr_t h) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
gio_dispatchMainFuncs();
|
gio_runFunc(h);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-3
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build darwin && ios
|
//go:build darwin && ios
|
||||||
// +build darwin,ios
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
@@ -12,6 +11,7 @@ package app
|
|||||||
#include <UIKit/UIKit.h>
|
#include <UIKit/UIKit.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
__attribute__ ((visibility ("hidden"))) int gio_applicationMain(int argc, char *argv[]);
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle);
|
__attribute__ ((visibility ("hidden"))) void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle);
|
||||||
|
|
||||||
struct drawParams {
|
struct drawParams {
|
||||||
@@ -21,6 +21,7 @@ struct drawParams {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void writeClipboard(unichar *chars, NSUInteger length) {
|
static void writeClipboard(unichar *chars, NSUInteger length) {
|
||||||
|
#if !TARGET_OS_TV
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSString *s = [NSString string];
|
NSString *s = [NSString string];
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
@@ -29,13 +30,18 @@ static void writeClipboard(unichar *chars, NSUInteger length) {
|
|||||||
UIPasteboard *p = UIPasteboard.generalPasteboard;
|
UIPasteboard *p = UIPasteboard.generalPasteboard;
|
||||||
p.string = s;
|
p.string = s;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static CFTypeRef readClipboard(void) {
|
static CFTypeRef readClipboard(void) {
|
||||||
|
#if !TARGET_OS_TV
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
UIPasteboard *p = UIPasteboard.generalPasteboard;
|
UIPasteboard *p = UIPasteboard.generalPasteboard;
|
||||||
return (__bridge_retained CFTypeRef)p.string;
|
return (__bridge_retained CFTypeRef)p.string;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
return nil;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void showTextInput(CFTypeRef viewRef) {
|
static void showTextInput(CFTypeRef viewRef) {
|
||||||
@@ -75,6 +81,7 @@ import "C"
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/cgo"
|
"runtime/cgo"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
@@ -211,7 +218,8 @@ func onDestroy(h C.uintptr_t) {
|
|||||||
//export onFocus
|
//export onFocus
|
||||||
func onFocus(h C.uintptr_t, focus int) {
|
func onFocus(h C.uintptr_t, focus int) {
|
||||||
w := viewFor(h)
|
w := viewFor(h)
|
||||||
w.ProcessEvent(key.FocusEvent{Focus: focus != 0})
|
w.config.Focused = focus != 0
|
||||||
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onLowMemory
|
//export onLowMemory
|
||||||
@@ -387,13 +395,62 @@ func newWindow(win *callbacks, options []Option) {
|
|||||||
<-mainWindow.windows
|
<-mainWindow.windows
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mainMode = mainModeUndefined
|
||||||
|
|
||||||
|
const (
|
||||||
|
mainModeUndefined = iota
|
||||||
|
mainModeExe
|
||||||
|
mainModeLibrary
|
||||||
|
)
|
||||||
|
|
||||||
func osMain() {
|
func osMain() {
|
||||||
|
switch mainMode {
|
||||||
|
case mainModeUndefined:
|
||||||
|
if !isMainThread() {
|
||||||
|
panic("app.Main must be run on the main goroutine")
|
||||||
|
}
|
||||||
|
|
||||||
|
mainMode = mainModeExe
|
||||||
|
var argv []*C.char
|
||||||
|
for _, arg := range os.Args {
|
||||||
|
a := C.CString(arg)
|
||||||
|
defer C.free(unsafe.Pointer(a))
|
||||||
|
argv = append(argv, a)
|
||||||
|
}
|
||||||
|
C.gio_applicationMain(C.int(len(argv)), unsafe.SliceData(argv))
|
||||||
|
case mainModeExe:
|
||||||
|
panic("app.Main may be called only once")
|
||||||
|
case mainModeLibrary:
|
||||||
|
// Do nothing, we're embedded as a library.
|
||||||
|
}
|
||||||
|
select {}
|
||||||
|
}
|
||||||
|
|
||||||
|
//export gio_onOpenURI
|
||||||
|
func gio_onOpenURI(uri C.CFTypeRef) {
|
||||||
|
evt, err := newURLEvent(nsstringToString(uri))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
processGlobalEvent(evt)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_runMain
|
//export gio_runMain
|
||||||
func gio_runMain() {
|
func gio_runMain() {
|
||||||
runMain()
|
if !isMainThread() {
|
||||||
|
panic("app.Main must be run on the main goroutine")
|
||||||
|
}
|
||||||
|
switch mainMode {
|
||||||
|
case mainModeUndefined:
|
||||||
|
mainMode = mainModeLibrary
|
||||||
|
runMain()
|
||||||
|
case mainModeExe:
|
||||||
|
// Do nothing, main has already been called.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UIKitViewEvent) implementsViewEvent() {}
|
func (UIKitViewEvent) implementsViewEvent() {}
|
||||||
func (UIKitViewEvent) ImplementsEvent() {}
|
func (UIKitViewEvent) ImplementsEvent() {}
|
||||||
|
func (u UIKitViewEvent) Valid() bool {
|
||||||
|
return u != (UIKitViewEvent{})
|
||||||
|
}
|
||||||
|
|||||||
+76
-12
@@ -26,12 +26,13 @@ CGFloat _keyboardHeight;
|
|||||||
self.view.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0);
|
self.view.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0);
|
||||||
UIView *drawView = [[GioView alloc] initWithFrame:zeroFrame];
|
UIView *drawView = [[GioView alloc] initWithFrame:zeroFrame];
|
||||||
[self.view addSubview: drawView];
|
[self.view addSubview: drawView];
|
||||||
#ifndef TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
drawView.multipleTouchEnabled = YES;
|
drawView.multipleTouchEnabled = YES;
|
||||||
#endif
|
#endif
|
||||||
drawView.preservesSuperviewLayoutMargins = YES;
|
drawView.preservesSuperviewLayoutMargins = YES;
|
||||||
drawView.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0);
|
drawView.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0);
|
||||||
onCreate((__bridge CFTypeRef)drawView, (__bridge CFTypeRef)self);
|
onCreate((__bridge CFTypeRef)drawView, (__bridge CFTypeRef)self);
|
||||||
|
#if !TARGET_OS_TV
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(keyboardWillChange:)
|
selector:@selector(keyboardWillChange:)
|
||||||
name:UIKeyboardWillShowNotification
|
name:UIKeyboardWillShowNotification
|
||||||
@@ -44,6 +45,7 @@ CGFloat _keyboardHeight;
|
|||||||
selector:@selector(keyboardWillHide:)
|
selector:@selector(keyboardWillHide:)
|
||||||
name:UIKeyboardWillHideNotification
|
name:UIKeyboardWillHideNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
|
#endif
|
||||||
[[NSNotificationCenter defaultCenter] addObserver: self
|
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||||
selector: @selector(applicationDidEnterBackground:)
|
selector: @selector(applicationDidEnterBackground:)
|
||||||
name: UIApplicationDidEnterBackgroundNotification
|
name: UIApplicationDidEnterBackgroundNotification
|
||||||
@@ -89,6 +91,7 @@ CGFloat _keyboardHeight;
|
|||||||
[super didReceiveMemoryWarning];
|
[super didReceiveMemoryWarning];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TARGET_OS_TV
|
||||||
- (void)keyboardWillChange:(NSNotification *)note {
|
- (void)keyboardWillChange:(NSNotification *)note {
|
||||||
NSDictionary *userInfo = note.userInfo;
|
NSDictionary *userInfo = note.userInfo;
|
||||||
CGRect f = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
CGRect f = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
||||||
@@ -100,6 +103,7 @@ CGFloat _keyboardHeight;
|
|||||||
_keyboardHeight = 0.0;
|
_keyboardHeight = 0.0;
|
||||||
[self.view setNeedsLayout];
|
[self.view setNeedsLayout];
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static void handleTouches(int last, GioView *view, NSSet<UITouch *> *touches, UIEvent *event) {
|
static void handleTouches(int last, GioView *view, NSSet<UITouch *> *touches, UIEvent *event) {
|
||||||
@@ -130,23 +134,59 @@ NSArray<UIKeyCommand *> *_keyCommands;
|
|||||||
return gio_layerClass();
|
return gio_layerClass();
|
||||||
}
|
}
|
||||||
- (void)willMoveToWindow:(UIWindow *)newWindow {
|
- (void)willMoveToWindow:(UIWindow *)newWindow {
|
||||||
|
self.contentScaleFactor = newWindow.screen.nativeScale;
|
||||||
|
if (@available(iOS 13.0, *)) {
|
||||||
|
[self registerSceneNotifications:newWindow];
|
||||||
|
}else{
|
||||||
|
[self registerWindowNotifications:newWindow];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)registerSceneNotifications:(UIWindow *)newWindow {
|
||||||
|
if (self.window != nil) {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||||
|
name:UISceneDidActivateNotification
|
||||||
|
object:self.window.windowScene];
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||||
|
name:UISceneWillDeactivateNotification
|
||||||
|
object:self.window.windowScene];
|
||||||
|
}
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(onSceneDidActivate:)
|
||||||
|
name:UISceneDidActivateNotification
|
||||||
|
object:newWindow.windowScene];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(onSceneWillDeactivate:)
|
||||||
|
name:UISceneWillDeactivateNotification
|
||||||
|
object:newWindow.windowScene];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)onSceneDidActivate:(NSNotification *)note API_AVAILABLE(ios(13.0)){
|
||||||
|
onFocus(self.handle, YES);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)onSceneWillDeactivate:(NSNotification *)note API_AVAILABLE(ios(13.0)){
|
||||||
|
onFocus(self.handle, NO);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)registerWindowNotifications:(UIWindow *)newWindow {
|
||||||
if (self.window != nil) {
|
if (self.window != nil) {
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||||
name:UIWindowDidBecomeKeyNotification
|
name:UIWindowDidBecomeKeyNotification
|
||||||
object:self.window];
|
object:self.window];
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||||
name:UIWindowDidResignKeyNotification
|
name:UIWindowDidResignKeyNotification
|
||||||
object:self.window];
|
object:self.window];
|
||||||
}
|
}
|
||||||
self.contentScaleFactor = newWindow.screen.nativeScale;
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(onWindowDidBecomeKey:)
|
selector:@selector(onWindowDidBecomeKey:)
|
||||||
name:UIWindowDidBecomeKeyNotification
|
name:UIWindowDidBecomeKeyNotification
|
||||||
object:newWindow];
|
object:newWindow];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(onWindowDidResignKey:)
|
selector:@selector(onWindowDidResignKey:)
|
||||||
name:UIWindowDidResignKeyNotification
|
name:UIWindowDidResignKeyNotification
|
||||||
object:newWindow];
|
object:newWindow];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onWindowDidBecomeKey:(NSNotification *)note {
|
- (void)onWindowDidBecomeKey:(NSNotification *)note {
|
||||||
@@ -276,3 +316,27 @@ void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle) {
|
|||||||
GioView *v = (__bridge GioView *)viewRef;
|
GioView *v = (__bridge GioView *)viewRef;
|
||||||
v.handle = handle;
|
v.handle = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface _gioAppDelegate : UIResponder <UIApplicationDelegate>
|
||||||
|
@property (strong, nonatomic) UIWindow *window;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation _gioAppDelegate
|
||||||
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||||
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||||
|
GioViewController *controller = [[GioViewController alloc] initWithNibName:nil bundle:nil];
|
||||||
|
self.window.rootViewController = controller;
|
||||||
|
[self.window makeKeyAndVisible];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
|
||||||
|
gio_onOpenURI((__bridge CFTypeRef)url.absoluteString);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
int gio_applicationMain(int argc, char *argv[]) {
|
||||||
|
@autoreleasepool {
|
||||||
|
return UIApplicationMain(argc, argv, nil, NSStringFromClass([_gioAppDelegate class]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+359
-20
@@ -53,7 +53,8 @@ type window struct {
|
|||||||
screenOrientation js.Value
|
screenOrientation js.Value
|
||||||
cleanfuncs []func()
|
cleanfuncs []func()
|
||||||
touches []js.Value
|
touches []js.Value
|
||||||
composing bool
|
composing int
|
||||||
|
lastCursor int
|
||||||
requestFocus bool
|
requestFocus bool
|
||||||
|
|
||||||
config Config
|
config Config
|
||||||
@@ -84,6 +85,7 @@ func newWindow(win *callbacks, options []Option) {
|
|||||||
clipboard: js.Global().Get("navigator").Get("clipboard"),
|
clipboard: js.Global().Get("navigator").Get("clipboard"),
|
||||||
wakeups: make(chan struct{}, 1),
|
wakeups: make(chan struct{}, 1),
|
||||||
w: win,
|
w: win,
|
||||||
|
composing: -1,
|
||||||
}
|
}
|
||||||
w.w.SetDriver(w)
|
w.w.SetDriver(w)
|
||||||
w.requestAnimationFrame = w.window.Get("requestAnimationFrame")
|
w.requestAnimationFrame = w.window.Get("requestAnimationFrame")
|
||||||
@@ -130,8 +132,10 @@ func getContainer(doc js.Value) js.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createTextArea(doc js.Value) js.Value {
|
func createTextArea(doc js.Value) js.Value {
|
||||||
tarea := doc.Call("createElement", "input")
|
tarea := doc.Call("createElement", "textarea")
|
||||||
style := tarea.Get("style")
|
style := tarea.Get("style")
|
||||||
|
// Position absolute so left/top coordinates actually place the element
|
||||||
|
style.Set("position", "absolute")
|
||||||
style.Set("width", "1px")
|
style.Set("width", "1px")
|
||||||
style.Set("height", "1px")
|
style.Set("height", "1px")
|
||||||
style.Set("opacity", "0")
|
style.Set("opacity", "0")
|
||||||
@@ -141,6 +145,12 @@ func createTextArea(doc js.Value) js.Value {
|
|||||||
tarea.Set("autocorrect", "off")
|
tarea.Set("autocorrect", "off")
|
||||||
tarea.Set("autocapitalize", "off")
|
tarea.Set("autocapitalize", "off")
|
||||||
tarea.Set("spellcheck", false)
|
tarea.Set("spellcheck", false)
|
||||||
|
// Enable multiline text input for better composition support on some browsers.
|
||||||
|
tarea.Set("rows", 1)
|
||||||
|
style.Set("resize", "none")
|
||||||
|
style.Set("overflow", "hidden")
|
||||||
|
style.Set("white-space", "pre-wrap")
|
||||||
|
style.Set("word-break", "normal")
|
||||||
return tarea
|
return tarea
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,11 +268,21 @@ func (w *window) addEventListeners() {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
w.addEventListener(w.tarea, "focus", func(this js.Value, args []js.Value) interface{} {
|
w.addEventListener(w.tarea, "focus", func(this js.Value, args []js.Value) interface{} {
|
||||||
w.processEvent(key.FocusEvent{Focus: true})
|
w.config.Focused = true
|
||||||
|
w.processEvent(ConfigEvent{Config: w.config})
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
w.addEventListener(w.tarea, "blur", func(this js.Value, args []js.Value) interface{} {
|
w.addEventListener(w.tarea, "blur", func(this js.Value, args []js.Value) interface{} {
|
||||||
w.processEvent(key.FocusEvent{Focus: false})
|
if w.composing != -1 {
|
||||||
|
// If we're composing, try to cancel.
|
||||||
|
// On Javascript is not possible to cancel the composition once started.
|
||||||
|
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
||||||
|
w.composing = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
w.config.Focused = false
|
||||||
|
w.lastCursor = 0 // Reset cursor tracking on blur
|
||||||
|
w.processEvent(ConfigEvent{Config: w.config})
|
||||||
w.blur()
|
w.blur()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -275,19 +295,205 @@ func (w *window) addEventListeners() {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
w.addEventListener(w.tarea, "compositionstart", func(this js.Value, args []js.Value) interface{} {
|
w.addEventListener(w.tarea, "compositionstart", func(this js.Value, args []js.Value) interface{} {
|
||||||
w.composing = true
|
st := w.w.EditorState()
|
||||||
|
sel := st.Selection.Range
|
||||||
|
if sel.Start == -1 {
|
||||||
|
sel.Start = 0
|
||||||
|
sel.End = 0
|
||||||
|
}
|
||||||
|
w.w.SetEditorSnippet(key.Range{Start: sel.Start, End: sel.End})
|
||||||
|
w.composing = sel.Start
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
w.addEventListener(w.tarea, "compositionend", func(this js.Value, args []js.Value) interface{} {
|
w.addEventListener(w.tarea, "compositionend", func(this js.Value, args []js.Value) interface{} {
|
||||||
w.composing = false
|
finalText := w.tarea.Get("value").String()
|
||||||
w.flushInput()
|
|
||||||
|
if w.composing != -1 && finalText != "" {
|
||||||
|
// Replace the entire composition range with the final text.
|
||||||
|
compEnd := w.composing + utf8.RuneCountInString(finalText)
|
||||||
|
replaceRange := key.Range{Start: w.composing, End: compEnd}
|
||||||
|
w.w.EditorReplace(replaceRange, finalText)
|
||||||
|
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
||||||
|
|
||||||
|
// Position cursor after the final composition text.
|
||||||
|
newEnd := w.composing + utf8.RuneCountInString(finalText)
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: newEnd, End: newEnd})
|
||||||
|
}
|
||||||
|
|
||||||
|
w.composing = -1
|
||||||
|
w.tarea.Set("value", "")
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
w.addEventListener(w.tarea, "input", func(this js.Value, args []js.Value) interface{} {
|
w.addEventListener(w.tarea, "input", func(this js.Value, args []js.Value) interface{} {
|
||||||
if w.composing {
|
e := args[0]
|
||||||
return nil
|
inputType := e.Get("inputType").String()
|
||||||
|
|
||||||
|
dataVal := e.Get("data")
|
||||||
|
var data string
|
||||||
|
if dataVal.Truthy() {
|
||||||
|
data = dataVal.String()
|
||||||
}
|
}
|
||||||
w.flushInput()
|
|
||||||
|
// Get the current textarea value.
|
||||||
|
tareaValue := w.tarea.Get("value").String()
|
||||||
|
st := w.w.EditorState()
|
||||||
|
|
||||||
|
sel := st.Selection.Range
|
||||||
|
var absStart, absEnd int
|
||||||
|
|
||||||
|
snippetStart := st.Snippet.Range.Start
|
||||||
|
snippetEnd := st.Snippet.Range.End
|
||||||
|
|
||||||
|
cursorPos := sel.Start
|
||||||
|
selectionEnd := sel.End
|
||||||
|
if cursorPos < 0 {
|
||||||
|
cursorPos = 0
|
||||||
|
selectionEnd = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we need to expand the snippet to include the range.
|
||||||
|
if st.Snippet.Range.Start == 0 && st.Snippet.Range.End == 0 && tareaValue != "" {
|
||||||
|
// Empty snippet - set it to include the selection/cursor.
|
||||||
|
w.w.SetEditorSnippet(key.Range{Start: cursorPos, End: selectionEnd})
|
||||||
|
absStart = cursorPos
|
||||||
|
absEnd = selectionEnd
|
||||||
|
} else if cursorPos < snippetStart || selectionEnd > snippetEnd {
|
||||||
|
// Selection is outside the snippet
|
||||||
|
newStart := snippetStart
|
||||||
|
newEnd := snippetEnd
|
||||||
|
if cursorPos < newStart {
|
||||||
|
newStart = cursorPos
|
||||||
|
}
|
||||||
|
if selectionEnd > newEnd {
|
||||||
|
newEnd = selectionEnd
|
||||||
|
}
|
||||||
|
w.w.SetEditorSnippet(key.Range{Start: newStart, End: newEnd})
|
||||||
|
// Refresh state after snippet update.
|
||||||
|
st = w.w.EditorState()
|
||||||
|
// Use the selection range directly.
|
||||||
|
absStart = cursorPos
|
||||||
|
absEnd = selectionEnd
|
||||||
|
} else {
|
||||||
|
// Selection is within snippet to absolute positions.
|
||||||
|
absStart = cursorPos
|
||||||
|
absEnd = selectionEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
switch inputType {
|
||||||
|
case "insertCompositionText":
|
||||||
|
if w.composing == -1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
compEnd := absEnd
|
||||||
|
if compEnd < w.composing {
|
||||||
|
compEnd = w.composing
|
||||||
|
}
|
||||||
|
replaceRange := key.Range{Start: w.composing, End: compEnd}
|
||||||
|
w.w.EditorReplace(replaceRange, data)
|
||||||
|
|
||||||
|
newEnd := w.composing + utf8.RuneCountInString(data)
|
||||||
|
w.w.SetComposingRegion(key.Range{Start: w.composing, End: newEnd})
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: newEnd, End: newEnd})
|
||||||
|
|
||||||
|
case "deleteContentBackward", "deleteContentForward", "deleteByCut":
|
||||||
|
if w.composing != -1 {
|
||||||
|
compEnd := w.composing + utf8.RuneCountInString(tareaValue)
|
||||||
|
replaceRange := key.Range{Start: w.composing, End: compEnd}
|
||||||
|
w.w.EditorReplace(replaceRange, tareaValue)
|
||||||
|
|
||||||
|
newEnd := w.composing + utf8.RuneCountInString(tareaValue)
|
||||||
|
w.w.SetComposingRegion(key.Range{Start: w.composing, End: newEnd})
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: newEnd, End: newEnd})
|
||||||
|
} else {
|
||||||
|
replaceRange := key.Range{Start: absStart, End: absEnd}
|
||||||
|
w.w.EditorReplace(replaceRange, "")
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: absStart, End: absStart})
|
||||||
|
}
|
||||||
|
|
||||||
|
case "insertReplacementText":
|
||||||
|
if w.composing != -1 {
|
||||||
|
// During composition, replace the entire composition.
|
||||||
|
compEnd := w.composing + utf8.RuneCountInString(data)
|
||||||
|
replaceRange := key.Range{Start: w.composing, End: compEnd}
|
||||||
|
w.w.EditorReplace(replaceRange, data)
|
||||||
|
|
||||||
|
newEnd := w.composing + utf8.RuneCountInString(data)
|
||||||
|
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: newEnd, End: newEnd})
|
||||||
|
w.composing = -1
|
||||||
|
w.lastCursor = newEnd
|
||||||
|
} else {
|
||||||
|
// Safari sends "insertReplacementText" for autocorrect, but the cursor is at the end of the word, so we need to find the word start.
|
||||||
|
insertLen := utf8.RuneCountInString(data)
|
||||||
|
wordStart := absStart
|
||||||
|
|
||||||
|
if absStart > snippetStart {
|
||||||
|
relPos := absStart - snippetStart
|
||||||
|
snippetRunes := []rune(st.Snippet.Text)
|
||||||
|
|
||||||
|
for i := relPos - 1; i >= 0; i-- {
|
||||||
|
if i >= len(snippetRunes) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
r := snippetRunes[i]
|
||||||
|
if r == ' ' || r == '\t' || r == '\n' || r == '\r' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
wordStart = snippetStart + i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
replaceRange := key.Range{Start: wordStart, End: absStart}
|
||||||
|
w.w.EditorReplace(replaceRange, data)
|
||||||
|
|
||||||
|
newCursor := wordStart + insertLen
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: newCursor, End: newCursor})
|
||||||
|
w.lastCursor = newCursor
|
||||||
|
}
|
||||||
|
|
||||||
|
case "insertText":
|
||||||
|
if w.composing != -1 {
|
||||||
|
compEnd := w.composing + utf8.RuneCountInString(data)
|
||||||
|
replaceRange := key.Range{Start: w.composing, End: compEnd}
|
||||||
|
w.w.EditorReplace(replaceRange, data)
|
||||||
|
|
||||||
|
newEnd := w.composing + utf8.RuneCountInString(data)
|
||||||
|
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: newEnd, End: newEnd})
|
||||||
|
w.composing = -1
|
||||||
|
w.lastCursor = newEnd
|
||||||
|
} else {
|
||||||
|
insertLen := utf8.RuneCountInString(data)
|
||||||
|
replaceRange := key.Range{Start: absStart, End: absStart}
|
||||||
|
if absStart != absEnd {
|
||||||
|
replaceRange = key.Range{Start: absStart, End: absEnd}
|
||||||
|
}
|
||||||
|
|
||||||
|
newCursor := replaceRange.Start + insertLen
|
||||||
|
w.w.EditorReplace(replaceRange, data)
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: newCursor, End: newCursor})
|
||||||
|
w.lastCursor = newCursor
|
||||||
|
}
|
||||||
|
|
||||||
|
default: // paste and other input types
|
||||||
|
if w.composing != -1 {
|
||||||
|
compEnd := w.composing + utf8.RuneCountInString(tareaValue)
|
||||||
|
replaceRange := key.Range{Start: w.composing, End: compEnd}
|
||||||
|
w.w.EditorReplace(replaceRange, tareaValue)
|
||||||
|
|
||||||
|
newEnd := w.composing + utf8.RuneCountInString(tareaValue)
|
||||||
|
w.w.SetComposingRegion(key.Range{Start: w.composing, End: newEnd})
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: newEnd, End: newEnd})
|
||||||
|
} else {
|
||||||
|
replaceRange := key.Range{Start: absStart, End: absEnd}
|
||||||
|
w.w.EditorReplace(replaceRange, tareaValue)
|
||||||
|
|
||||||
|
newCursor := absStart + utf8.RuneCountInString(tareaValue)
|
||||||
|
w.w.SetEditorSelection(key.Range{Start: newCursor, End: newCursor})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
w.addEventListener(w.tarea, "paste", func(this js.Value, args []js.Value) interface{} {
|
w.addEventListener(w.tarea, "paste", func(this js.Value, args []js.Value) interface{} {
|
||||||
@@ -304,12 +510,6 @@ func (w *window) addHistory() {
|
|||||||
w.browserHistory.Call("pushState", nil, nil, w.window.Get("location").Get("href"))
|
w.browserHistory.Call("pushState", nil, nil, w.window.Get("location").Get("href"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) flushInput() {
|
|
||||||
val := w.tarea.Get("value").String()
|
|
||||||
w.tarea.Set("value", "")
|
|
||||||
w.w.EditorInsert(string(val))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *window) blur() {
|
func (w *window) blur() {
|
||||||
w.tarea.Call("blur")
|
w.tarea.Call("blur")
|
||||||
w.requestFocus = false
|
w.requestFocus = false
|
||||||
@@ -341,11 +541,49 @@ func (w *window) keyboard(hint key.InputHint) {
|
|||||||
m = "text"
|
m = "text"
|
||||||
}
|
}
|
||||||
w.tarea.Set("inputMode", m)
|
w.tarea.Set("inputMode", m)
|
||||||
|
|
||||||
|
// Update autocomplete / autocorrect attributes.
|
||||||
|
var autocomplete, autocorrect, autocapitalize string
|
||||||
|
var spellcheck bool
|
||||||
|
|
||||||
|
switch hint {
|
||||||
|
case key.HintAny, key.HintText:
|
||||||
|
autocomplete, autocorrect, autocapitalize, spellcheck = "on", "on", "on", true
|
||||||
|
case key.HintEmail:
|
||||||
|
autocomplete, autocorrect, autocapitalize, spellcheck = "email", "off", "off", false
|
||||||
|
case key.HintURL:
|
||||||
|
autocomplete, autocorrect, autocapitalize, spellcheck = "url", "off", "off", false
|
||||||
|
case key.HintTelephone:
|
||||||
|
autocomplete, autocorrect, autocapitalize, spellcheck = "tel", "off", "off", false
|
||||||
|
case key.HintPassword:
|
||||||
|
autocomplete, autocorrect, autocapitalize, spellcheck = "current-password", "off", "off", false
|
||||||
|
default: // key.HintNumeric and others
|
||||||
|
autocomplete, autocorrect, autocapitalize, spellcheck = "off", "off", "off", false
|
||||||
|
}
|
||||||
|
|
||||||
|
w.tarea.Set("autocomplete", autocomplete)
|
||||||
|
w.tarea.Set("autocorrect", autocorrect)
|
||||||
|
w.tarea.Set("autocapitalize", autocapitalize)
|
||||||
|
w.tarea.Set("spellcheck", spellcheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) keyEvent(e js.Value, ks key.State) {
|
func (w *window) keyEvent(e js.Value, ks key.State) {
|
||||||
k := e.Get("key").String()
|
k := e.Get("key").String()
|
||||||
|
|
||||||
if n, ok := translateKey(k); ok {
|
if n, ok := translateKey(k); ok {
|
||||||
|
if ks == key.Press {
|
||||||
|
isMod := n == key.NameAlt || n == key.NameCommand || n == key.NameCtrl || n == key.NameShift || n == key.NameSuper
|
||||||
|
isFunc := n == key.NameUpArrow || n == key.NameDownArrow || n == key.NameLeftArrow || n == key.NameRightArrow ||
|
||||||
|
n == key.NamePageUp || n == key.NamePageDown || n == key.NameHome || n == key.NameEnd ||
|
||||||
|
n == key.NameEscape || n == key.NameReturn || n == key.NameEnter || n == key.NameTab ||
|
||||||
|
n == key.NameDeleteBackward || n == key.NameDeleteForward
|
||||||
|
|
||||||
|
if isMod || isFunc {
|
||||||
|
// Gio will request the browser to change the selection/carret position natively.
|
||||||
|
e.Call("preventDefault")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmd := key.Event{
|
cmd := key.Event{
|
||||||
Name: n,
|
Name: n,
|
||||||
Modifiers: modifiersFor(e),
|
Modifiers: modifiersFor(e),
|
||||||
@@ -412,6 +650,12 @@ func modifiersFor(e js.Value) key.Modifiers {
|
|||||||
if e.Call("getModifierState", "Shift").Bool() {
|
if e.Call("getModifierState", "Shift").Bool() {
|
||||||
mods |= key.ModShift
|
mods |= key.ModShift
|
||||||
}
|
}
|
||||||
|
if e.Call("getModifierState", "Meta").Bool() {
|
||||||
|
mods |= key.ModCommand
|
||||||
|
}
|
||||||
|
if e.Call("getModifierState", "OS").Bool() {
|
||||||
|
mods |= key.ModSuper
|
||||||
|
}
|
||||||
return mods
|
return mods
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,6 +676,9 @@ func (w *window) touchEvent(kind pointer.Kind, e js.Value) {
|
|||||||
if e.Get("ctrlKey").Bool() {
|
if e.Get("ctrlKey").Bool() {
|
||||||
mods |= key.ModCtrl
|
mods |= key.ModCtrl
|
||||||
}
|
}
|
||||||
|
if e.Get("metaKey").Bool() {
|
||||||
|
mods |= key.ModCommand
|
||||||
|
}
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
touch := changedTouches.Index(i)
|
touch := changedTouches.Index(i)
|
||||||
pid := w.touchIDFor(touch)
|
pid := w.touchIDFor(touch)
|
||||||
@@ -519,7 +766,90 @@ func (w *window) funcOf(f func(this js.Value, args []js.Value) interface{}) js.F
|
|||||||
return jsf
|
return jsf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) EditorStateChanged(old, new editorState) {}
|
func (w *window) EditorStateChanged(old, new editorState) {
|
||||||
|
if w.composing != -1 {
|
||||||
|
// Do not interfere with browser state while composing.
|
||||||
|
// On Javascript is not possible to cancel the composition once started!
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update textarea value to match the snippet.
|
||||||
|
if old.Snippet != new.Snippet {
|
||||||
|
w.tarea.Set("value", new.Snippet.Text)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update selection to match Gio's selection.
|
||||||
|
if old.Selection.Range != new.Selection.Range || old.Snippet != new.Snippet {
|
||||||
|
if new.Selection.Range.Start != -1 && new.Selection.Range.End != -1 {
|
||||||
|
// Calculate selection positions relative to snippet start.
|
||||||
|
// The textarea contains only the snippet text.
|
||||||
|
snippetStart := new.Snippet.Range.Start
|
||||||
|
snippetEnd := new.Snippet.Range.End
|
||||||
|
|
||||||
|
selStart := new.Selection.Range.Start
|
||||||
|
selEnd := new.Selection.Range.End
|
||||||
|
if selStart < snippetStart {
|
||||||
|
selStart = snippetStart
|
||||||
|
}
|
||||||
|
if selStart > snippetEnd {
|
||||||
|
selStart = snippetEnd
|
||||||
|
}
|
||||||
|
if selEnd < snippetStart {
|
||||||
|
selEnd = snippetStart
|
||||||
|
}
|
||||||
|
if selEnd > snippetEnd {
|
||||||
|
selEnd = snippetEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert absolute rune positions to UTF-16 positions for the textarea.
|
||||||
|
startUTF16 := new.UTF16Index(selStart)
|
||||||
|
endUTF16 := new.UTF16Index(selEnd)
|
||||||
|
|
||||||
|
// Convert to snippet-relative UTF-16 positions.
|
||||||
|
snippetStartUTF16 := new.UTF16Index(snippetStart)
|
||||||
|
start := startUTF16 - snippetStartUTF16
|
||||||
|
end := endUTF16 - snippetStartUTF16
|
||||||
|
|
||||||
|
if start < 0 {
|
||||||
|
start = 0
|
||||||
|
}
|
||||||
|
if end < 0 {
|
||||||
|
end = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate max UTF-16 length of snippet text.
|
||||||
|
textLen := new.UTF16Index(snippetEnd) - snippetStartUTF16
|
||||||
|
if start > textLen {
|
||||||
|
start = textLen
|
||||||
|
}
|
||||||
|
if end > textLen {
|
||||||
|
end = textLen
|
||||||
|
}
|
||||||
|
|
||||||
|
if start > end {
|
||||||
|
start, end = end, start
|
||||||
|
}
|
||||||
|
|
||||||
|
w.tarea.Set("selectionStart", start)
|
||||||
|
w.tarea.Set("selectionEnd", end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move DOM element to position the caret.
|
||||||
|
if old.Selection.Caret != new.Selection.Caret || old.Selection.Transform != new.Selection.Transform {
|
||||||
|
pos := new.Selection.Transform.Transform(new.Selection.Caret.Pos.Add(f32.Pt(0, new.Selection.Caret.Descent)))
|
||||||
|
bounds := w.cnv.Call("getBoundingClientRect")
|
||||||
|
left := bounds.Get("left").Float() + float64(pos.X)/float64(w.scale)
|
||||||
|
top := bounds.Get("top").Float() + float64(pos.Y-new.Selection.Caret.Ascent)/float64(w.scale)
|
||||||
|
height := float64(new.Selection.Caret.Ascent+new.Selection.Caret.Descent) / float64(w.scale)
|
||||||
|
|
||||||
|
style := w.tarea.Get("style")
|
||||||
|
style.Set("left", fmt.Sprintf("%fpx", left))
|
||||||
|
style.Set("top", fmt.Sprintf("%fpx", top))
|
||||||
|
style.Set("height", fmt.Sprintf("%fpx", height))
|
||||||
|
style.Set("width", "1px")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *window) SetAnimating(anim bool) {
|
func (w *window) SetAnimating(anim bool) {
|
||||||
w.animating = anim
|
w.animating = anim
|
||||||
@@ -533,10 +863,9 @@ func (w *window) ReadClipboard() {
|
|||||||
if w.clipboard.IsUndefined() {
|
if w.clipboard.IsUndefined() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.clipboard.Get("readText").IsUndefined() {
|
if w.clipboard.Get("readText").Truthy() {
|
||||||
return
|
w.clipboard.Call("readText").Call("then", w.clipboardCallback)
|
||||||
}
|
}
|
||||||
w.clipboard.Call("readText", w.clipboard).Call("then", w.clipboardCallback)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) WriteClipboard(mime string, s []byte) {
|
func (w *window) WriteClipboard(mime string, s []byte) {
|
||||||
@@ -619,6 +948,13 @@ func (w *window) ShowTextInput(show bool) {
|
|||||||
if show {
|
if show {
|
||||||
w.focus()
|
w.focus()
|
||||||
} else {
|
} else {
|
||||||
|
// If we're composing, end composition first by clearing the textarea.
|
||||||
|
// That is a attempt to force the browser to end composition.
|
||||||
|
if w.composing != -1 {
|
||||||
|
w.tarea.Set("value", "")
|
||||||
|
w.composing = -1
|
||||||
|
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
||||||
|
}
|
||||||
w.blur()
|
w.blur()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -820,3 +1156,6 @@ func translateKey(k string) (key.Name, bool) {
|
|||||||
|
|
||||||
func (JSViewEvent) implementsViewEvent() {}
|
func (JSViewEvent) implementsViewEvent() {}
|
||||||
func (JSViewEvent) ImplementsEvent() {}
|
func (JSViewEvent) ImplementsEvent() {}
|
||||||
|
func (j JSViewEvent) Valid() bool {
|
||||||
|
return !(j.Element.IsNull() || j.Element.IsUndefined())
|
||||||
|
}
|
||||||
|
|||||||
+280
-143
@@ -40,8 +40,9 @@ import (
|
|||||||
#define MOUSE_SCROLL 4
|
#define MOUSE_SCROLL 4
|
||||||
|
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_main(void);
|
__attribute__ ((visibility ("hidden"))) void gio_main(void);
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createView(void);
|
__attribute__ ((visibility ("hidden"))) void gio_init(void);
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createWindow(CFTypeRef viewRef, CGFloat width, CGFloat height, CGFloat minWidth, CGFloat minHeight, CGFloat maxWidth, CGFloat maxHeight);
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createView(int presentWithTrans);
|
||||||
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createWindow(CFTypeRef viewRef, CGFloat width, CGFloat height);
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle);
|
__attribute__ ((visibility ("hidden"))) void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle);
|
||||||
|
|
||||||
static void writeClipboard(CFTypeRef str) {
|
static void writeClipboard(CFTypeRef str) {
|
||||||
@@ -109,6 +110,14 @@ static void makeKeyAndOrderFront(CFTypeRef windowRef) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void makeFirstResponder(CFTypeRef windowRef, CFTypeRef viewRef) {
|
||||||
|
@autoreleasepool {
|
||||||
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
|
[window makeFirstResponder:view];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void toggleFullScreen(CFTypeRef windowRef) {
|
static void toggleFullScreen(CFTypeRef windowRef) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
@@ -184,6 +193,7 @@ static void setMaxSize(CFTypeRef windowRef, CGFloat width, CGFloat height) {
|
|||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
window.contentMaxSize = NSMakeSize(width, height);
|
window.contentMaxSize = NSMakeSize(width, height);
|
||||||
|
window.maxFullScreenContentSize = NSMakeSize(width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,6 +205,14 @@ static void setScreenFrame(CFTypeRef windowRef, CGFloat x, CGFloat y, CGFloat w,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void resetLayerFrame(CFTypeRef viewRef) {
|
||||||
|
@autoreleasepool {
|
||||||
|
NSView* view = (__bridge NSView *)viewRef;
|
||||||
|
NSRect r = view.frame;
|
||||||
|
view.layer.frame = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void hideWindow(CFTypeRef windowRef) {
|
static void hideWindow(CFTypeRef windowRef) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
@@ -223,6 +241,13 @@ static void setTitle(CFTypeRef windowRef, CFTypeRef titleRef) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setWindowLevel(CFTypeRef windowRef, NSWindowLevel level) {
|
||||||
|
@autoreleasepool {
|
||||||
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
window.level = level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int isWindowZoomed(CFTypeRef windowRef) {
|
static int isWindowZoomed(CFTypeRef windowRef) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
@@ -230,6 +255,13 @@ static int isWindowZoomed(CFTypeRef windowRef) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int isWindowMiniaturized(CFTypeRef windowRef) {
|
||||||
|
@autoreleasepool {
|
||||||
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
return window.miniaturized ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void zoomWindow(CFTypeRef windowRef) {
|
static void zoomWindow(CFTypeRef windowRef) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
@@ -289,12 +321,29 @@ static void invalidateCharacterCoordinates(CFTypeRef viewRef) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void interpretKeyEvents(CFTypeRef viewRef, CFTypeRef eventRef) {
|
||||||
|
@autoreleasepool {
|
||||||
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
|
NSEvent *event = (__bridge NSEvent *)eventRef;
|
||||||
|
[view interpretKeyEvents:[NSArray arrayWithObject:event]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int isMiniaturized(CFTypeRef windowRef) {
|
||||||
|
@autoreleasepool {
|
||||||
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
return window.miniaturized ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Darwin requires that UI operations happen on the main thread only.
|
// Darwin requires that UI operations happen on the main thread only.
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
|
// Register launch finished listener.
|
||||||
|
C.gio_init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppKitViewEvent notifies the client of changes to the window AppKit handles.
|
// AppKitViewEvent notifies the client of changes to the window AppKit handles.
|
||||||
@@ -310,7 +359,6 @@ type window struct {
|
|||||||
view C.CFTypeRef
|
view C.CFTypeRef
|
||||||
w *callbacks
|
w *callbacks
|
||||||
anim bool
|
anim bool
|
||||||
visible bool
|
|
||||||
displayLink *displayLink
|
displayLink *displayLink
|
||||||
// redraw is a single entry channel for making sure only one
|
// redraw is a single entry channel for making sure only one
|
||||||
// display link redraw request is in flight.
|
// display link redraw request is in flight.
|
||||||
@@ -318,9 +366,20 @@ type window struct {
|
|||||||
cursor pointer.Cursor
|
cursor pointer.Cursor
|
||||||
pointerBtns pointer.Buttons
|
pointerBtns pointer.Buttons
|
||||||
loop *eventLoop
|
loop *eventLoop
|
||||||
|
lastMods C.NSUInteger
|
||||||
|
|
||||||
scale float32
|
scale float32
|
||||||
config Config
|
config Config
|
||||||
|
|
||||||
|
keysDown map[key.Name]struct{}
|
||||||
|
// cmdKeys is for storing the current key event while
|
||||||
|
// waiting for a doCommandBySelector.
|
||||||
|
cmdKeys cmdKeys
|
||||||
|
}
|
||||||
|
|
||||||
|
type cmdKeys struct {
|
||||||
|
eventStr string
|
||||||
|
eventMods key.Modifiers
|
||||||
}
|
}
|
||||||
|
|
||||||
// launched is closed when applicationDidFinishLaunching is called.
|
// launched is closed when applicationDidFinishLaunching is called.
|
||||||
@@ -359,11 +418,23 @@ func (w *window) WriteClipboard(mime string, s []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) updateWindowMode() {
|
func (w *window) updateWindowMode() {
|
||||||
|
w.scale = float32(C.getViewBackingScale(w.view))
|
||||||
|
wf, hf := float32(C.viewWidth(w.view)), float32(C.viewHeight(w.view))
|
||||||
|
w.config.Size = image.Point{
|
||||||
|
X: int(wf*w.scale + .5),
|
||||||
|
Y: int(hf*w.scale + .5),
|
||||||
|
}
|
||||||
|
w.config.Mode = Windowed
|
||||||
|
window := C.windowForView(w.view)
|
||||||
|
if window == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
style := int(C.getWindowStyleMask(C.windowForView(w.view)))
|
style := int(C.getWindowStyleMask(C.windowForView(w.view)))
|
||||||
if style&C.NSWindowStyleMaskFullScreen != 0 {
|
switch {
|
||||||
|
case style&C.NSWindowStyleMaskFullScreen != 0:
|
||||||
w.config.Mode = Fullscreen
|
w.config.Mode = Fullscreen
|
||||||
} else {
|
case C.isWindowZoomed(window) != 0:
|
||||||
w.config.Mode = Windowed
|
w.config.Mode = Maximized
|
||||||
}
|
}
|
||||||
w.config.Decorated = style&C.NSWindowStyleMaskFullSizeContentView == 0
|
w.config.Decorated = style&C.NSWindowStyleMaskFullSizeContentView == 0
|
||||||
}
|
}
|
||||||
@@ -371,102 +442,85 @@ func (w *window) updateWindowMode() {
|
|||||||
func (w *window) Configure(options []Option) {
|
func (w *window) Configure(options []Option) {
|
||||||
screenScale := float32(C.getScreenBackingScale())
|
screenScale := float32(C.getScreenBackingScale())
|
||||||
cfg := configFor(screenScale)
|
cfg := configFor(screenScale)
|
||||||
prev := w.config
|
|
||||||
w.updateWindowMode()
|
|
||||||
cnf := w.config
|
cnf := w.config
|
||||||
cnf.apply(cfg, options)
|
cnf.apply(cfg, options)
|
||||||
window := C.windowForView(w.view)
|
window := C.windowForView(w.view)
|
||||||
|
|
||||||
|
mask := C.getWindowStyleMask(window)
|
||||||
|
fullscreen := mask&C.NSWindowStyleMaskFullScreen != 0
|
||||||
switch cnf.Mode {
|
switch cnf.Mode {
|
||||||
case Fullscreen:
|
case Fullscreen:
|
||||||
switch prev.Mode {
|
if C.isWindowMiniaturized(window) != 0 {
|
||||||
case Fullscreen:
|
|
||||||
case Minimized:
|
|
||||||
C.unhideWindow(window)
|
C.unhideWindow(window)
|
||||||
fallthrough
|
}
|
||||||
default:
|
if !fullscreen {
|
||||||
w.config.Mode = Fullscreen
|
|
||||||
C.toggleFullScreen(window)
|
C.toggleFullScreen(window)
|
||||||
}
|
}
|
||||||
case Minimized:
|
case Minimized:
|
||||||
switch prev.Mode {
|
C.hideWindow(window)
|
||||||
case Minimized, Fullscreen:
|
|
||||||
default:
|
|
||||||
w.config.Mode = Minimized
|
|
||||||
C.hideWindow(window)
|
|
||||||
}
|
|
||||||
case Maximized:
|
case Maximized:
|
||||||
switch prev.Mode {
|
if C.isWindowMiniaturized(window) != 0 {
|
||||||
case Fullscreen:
|
|
||||||
case Minimized:
|
|
||||||
C.unhideWindow(window)
|
C.unhideWindow(window)
|
||||||
fallthrough
|
}
|
||||||
default:
|
if fullscreen {
|
||||||
w.config.Mode = Maximized
|
C.toggleFullScreen(window)
|
||||||
w.setTitle(prev, cnf)
|
}
|
||||||
if C.isWindowZoomed(window) == 0 {
|
w.setTitle(cnf.Title)
|
||||||
C.zoomWindow(window)
|
if C.isWindowZoomed(window) == 0 {
|
||||||
}
|
C.zoomWindow(window)
|
||||||
}
|
}
|
||||||
case Windowed:
|
case Windowed:
|
||||||
switch prev.Mode {
|
if C.isWindowMiniaturized(window) != 0 {
|
||||||
case Fullscreen:
|
|
||||||
C.toggleFullScreen(window)
|
|
||||||
case Minimized:
|
|
||||||
C.unhideWindow(window)
|
C.unhideWindow(window)
|
||||||
case Maximized:
|
|
||||||
if C.isWindowZoomed(window) != 0 {
|
|
||||||
C.zoomWindow(window)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
w.config.Mode = Windowed
|
if fullscreen {
|
||||||
w.setTitle(prev, cnf)
|
C.toggleFullScreen(window)
|
||||||
if prev.Size != cnf.Size {
|
|
||||||
w.config.Size = cnf.Size
|
|
||||||
cnf.Size = cnf.Size.Div(int(screenScale))
|
|
||||||
C.setSize(window, C.CGFloat(cnf.Size.X), C.CGFloat(cnf.Size.Y))
|
|
||||||
}
|
}
|
||||||
if prev.MinSize != cnf.MinSize {
|
w.setTitle(cnf.Title)
|
||||||
w.config.MinSize = cnf.MinSize
|
w.config.Size = cnf.Size
|
||||||
cnf.MinSize = cnf.MinSize.Div(int(screenScale))
|
cnf.Size = cnf.Size.Div(int(screenScale))
|
||||||
C.setMinSize(window, C.CGFloat(cnf.MinSize.X), C.CGFloat(cnf.MinSize.Y))
|
C.setSize(window, C.CGFloat(cnf.Size.X), C.CGFloat(cnf.Size.Y))
|
||||||
}
|
w.config.MinSize = cnf.MinSize
|
||||||
if prev.MaxSize != cnf.MaxSize {
|
cnf.MinSize = cnf.MinSize.Div(int(screenScale))
|
||||||
w.config.MaxSize = cnf.MaxSize
|
C.setMinSize(window, C.CGFloat(cnf.MinSize.X), C.CGFloat(cnf.MinSize.Y))
|
||||||
cnf.MaxSize = cnf.MaxSize.Div(int(screenScale))
|
w.config.MaxSize = cnf.MaxSize
|
||||||
|
cnf.MaxSize = cnf.MaxSize.Div(int(screenScale))
|
||||||
|
if cnf.MaxSize != (image.Point{}) {
|
||||||
C.setMaxSize(window, C.CGFloat(cnf.MaxSize.X), C.CGFloat(cnf.MaxSize.Y))
|
C.setMaxSize(window, C.CGFloat(cnf.MaxSize.X), C.CGFloat(cnf.MaxSize.Y))
|
||||||
}
|
}
|
||||||
}
|
if C.isWindowZoomed(window) != 0 {
|
||||||
if cnf.Decorated != prev.Decorated {
|
C.zoomWindow(window)
|
||||||
w.config.Decorated = cnf.Decorated
|
|
||||||
mask := C.getWindowStyleMask(window)
|
|
||||||
style := C.NSWindowStyleMask(C.NSWindowStyleMaskTitled | C.NSWindowStyleMaskResizable | C.NSWindowStyleMaskMiniaturizable | C.NSWindowStyleMaskClosable)
|
|
||||||
style = C.NSWindowStyleMaskFullSizeContentView
|
|
||||||
mask &^= style
|
|
||||||
barTrans := C.int(C.NO)
|
|
||||||
titleVis := C.NSWindowTitleVisibility(C.NSWindowTitleVisible)
|
|
||||||
if !cnf.Decorated {
|
|
||||||
mask |= style
|
|
||||||
barTrans = C.YES
|
|
||||||
titleVis = C.NSWindowTitleHidden
|
|
||||||
}
|
}
|
||||||
C.setWindowTitlebarAppearsTransparent(window, barTrans)
|
|
||||||
C.setWindowTitleVisibility(window, titleVis)
|
|
||||||
C.setWindowStyleMask(window, mask)
|
|
||||||
C.setWindowStandardButtonHidden(window, C.NSWindowCloseButton, barTrans)
|
|
||||||
C.setWindowStandardButtonHidden(window, C.NSWindowMiniaturizeButton, barTrans)
|
|
||||||
C.setWindowStandardButtonHidden(window, C.NSWindowZoomButton, barTrans)
|
|
||||||
}
|
}
|
||||||
w.ProcessEvent(ConfigEvent{Config: w.config})
|
style := C.NSWindowStyleMask(C.NSWindowStyleMaskTitled | C.NSWindowStyleMaskResizable | C.NSWindowStyleMaskMiniaturizable | C.NSWindowStyleMaskClosable)
|
||||||
|
style = C.NSWindowStyleMaskFullSizeContentView
|
||||||
|
mask &^= style
|
||||||
|
barTrans := C.int(C.NO)
|
||||||
|
titleVis := C.NSWindowTitleVisibility(C.NSWindowTitleVisible)
|
||||||
|
if !cnf.Decorated {
|
||||||
|
mask |= style
|
||||||
|
barTrans = C.YES
|
||||||
|
titleVis = C.NSWindowTitleHidden
|
||||||
|
}
|
||||||
|
if cnf.TopMost {
|
||||||
|
C.setWindowLevel(window, C.NSFloatingWindowLevel)
|
||||||
|
}
|
||||||
|
C.setWindowTitlebarAppearsTransparent(window, barTrans)
|
||||||
|
C.setWindowTitleVisibility(window, titleVis)
|
||||||
|
C.setWindowStyleMask(window, mask)
|
||||||
|
C.setWindowStandardButtonHidden(window, C.NSWindowCloseButton, barTrans)
|
||||||
|
C.setWindowStandardButtonHidden(window, C.NSWindowMiniaturizeButton, barTrans)
|
||||||
|
C.setWindowStandardButtonHidden(window, C.NSWindowZoomButton, barTrans)
|
||||||
|
// When toggling the titlebar, the layer doesn't update its frame
|
||||||
|
// until the next resize. Force it.
|
||||||
|
C.resetLayerFrame(w.view)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setTitle(prev, cnf Config) {
|
func (w *window) setTitle(title string) {
|
||||||
if prev.Title != cnf.Title {
|
w.config.Title = title
|
||||||
w.config.Title = cnf.Title
|
titleC := stringToNSString(title)
|
||||||
title := stringToNSString(cnf.Title)
|
defer C.CFRelease(titleC)
|
||||||
defer C.CFRelease(title)
|
C.setTitle(C.windowForView(w.view), titleC)
|
||||||
C.setTitle(C.windowForView(w.view), title)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Perform(acts system.Action) {
|
func (w *window) Perform(acts system.Action) {
|
||||||
@@ -494,7 +548,7 @@ func (w *window) SetCursor(cursor pointer.Cursor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) EditorStateChanged(old, new editorState) {
|
func (w *window) EditorStateChanged(old, new editorState) {
|
||||||
if old.Selection.Range != new.Selection.Range || old.Snippet != new.Snippet {
|
if old.Selection.Range != new.Selection.Range || !areSnippetsConsistent(old.Snippet, new.Snippet) {
|
||||||
C.discardMarkedText(w.view)
|
C.discardMarkedText(w.view)
|
||||||
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
||||||
}
|
}
|
||||||
@@ -509,7 +563,8 @@ func (w *window) SetInputHint(_ key.InputHint) {}
|
|||||||
|
|
||||||
func (w *window) SetAnimating(anim bool) {
|
func (w *window) SetAnimating(anim bool) {
|
||||||
w.anim = anim
|
w.anim = anim
|
||||||
if w.anim && w.visible {
|
window := C.windowForView(w.view)
|
||||||
|
if w.anim && window != 0 && C.isMiniaturized(window) == 0 {
|
||||||
w.displayLink.Start()
|
w.displayLink.Start()
|
||||||
} else {
|
} else {
|
||||||
w.displayLink.Stop()
|
w.displayLink.Stop()
|
||||||
@@ -527,23 +582,92 @@ func (w *window) runOnMain(f func()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onKeys
|
//export gio_onKeys
|
||||||
func gio_onKeys(h C.uintptr_t, cstr C.CFTypeRef, ti C.double, mods C.NSUInteger, keyDown C.bool) {
|
func gio_onKeys(h C.uintptr_t, event C.CFTypeRef, cstr C.CFTypeRef, ti C.double, mods C.NSUInteger, keyDown C.bool) {
|
||||||
|
w := windowFor(h)
|
||||||
|
if w.keysDown == nil {
|
||||||
|
w.keysDown = make(map[key.Name]struct{})
|
||||||
|
}
|
||||||
str := nsstringToString(cstr)
|
str := nsstringToString(cstr)
|
||||||
kmods := convertMods(mods)
|
kmods := convertMods(mods)
|
||||||
ks := key.Release
|
ks := key.Release
|
||||||
if keyDown {
|
if keyDown {
|
||||||
ks = key.Press
|
ks = key.Press
|
||||||
|
w.cmdKeys.eventStr = str
|
||||||
|
w.cmdKeys.eventMods = kmods
|
||||||
|
C.interpretKeyEvents(w.view, event)
|
||||||
}
|
}
|
||||||
w := windowFor(h)
|
|
||||||
for _, k := range str {
|
for _, k := range str {
|
||||||
if n, ok := convertKey(k); ok {
|
if n, ok := convertKey(k); ok {
|
||||||
w.ProcessEvent(key.Event{
|
ke := key.Event{
|
||||||
Name: n,
|
Name: n,
|
||||||
Modifiers: kmods,
|
Modifiers: kmods,
|
||||||
State: ks,
|
State: ks,
|
||||||
|
}
|
||||||
|
if keyDown {
|
||||||
|
w.keysDown[ke.Name] = struct{}{}
|
||||||
|
if _, isCmd := convertCommandKey(k); isCmd || kmods.Contain(key.ModCommand) {
|
||||||
|
// doCommandBySelector already processed the event.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if _, pressed := w.keysDown[n]; !pressed {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
delete(w.keysDown, n)
|
||||||
|
}
|
||||||
|
w.ProcessEvent(ke)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//export gio_onCommandBySelector
|
||||||
|
func gio_onCommandBySelector(h C.uintptr_t) C.bool {
|
||||||
|
w := windowFor(h)
|
||||||
|
ev := w.cmdKeys
|
||||||
|
w.cmdKeys = cmdKeys{}
|
||||||
|
handled := false
|
||||||
|
for _, k := range ev.eventStr {
|
||||||
|
n, ok := convertCommandKey(k)
|
||||||
|
if !ok && ev.eventMods.Contain(key.ModCommand) {
|
||||||
|
n, ok = convertKey(k)
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ke := key.Event{
|
||||||
|
Name: n,
|
||||||
|
Modifiers: ev.eventMods,
|
||||||
|
State: key.Press,
|
||||||
|
}
|
||||||
|
handled = w.processEvent(ke) || handled
|
||||||
|
}
|
||||||
|
return C.bool(handled)
|
||||||
|
}
|
||||||
|
|
||||||
|
//export gio_onFlagsChanged
|
||||||
|
func gio_onFlagsChanged(h C.uintptr_t, curMods C.NSUInteger) {
|
||||||
|
w := windowFor(h)
|
||||||
|
|
||||||
|
mods := []C.NSUInteger{C.NSControlKeyMask, C.NSAlternateKeyMask, C.NSShiftKeyMask, C.NSCommandKeyMask}
|
||||||
|
keys := []key.Name{key.NameCtrl, key.NameAlt, key.NameShift, key.NameCommand}
|
||||||
|
|
||||||
|
for i, mod := range mods {
|
||||||
|
wasPressed := w.lastMods&mod != 0
|
||||||
|
isPressed := curMods&mod != 0
|
||||||
|
|
||||||
|
if wasPressed != isPressed {
|
||||||
|
st := key.Release
|
||||||
|
if isPressed {
|
||||||
|
st = key.Press
|
||||||
|
}
|
||||||
|
w.ProcessEvent(key.Event{
|
||||||
|
Name: keys[i],
|
||||||
|
State: st,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.lastMods = curMods
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onText
|
//export gio_onText
|
||||||
@@ -612,8 +736,9 @@ func gio_onDraw(h C.uintptr_t) {
|
|||||||
//export gio_onFocus
|
//export gio_onFocus
|
||||||
func gio_onFocus(h C.uintptr_t, focus C.int) {
|
func gio_onFocus(h C.uintptr_t, focus C.int) {
|
||||||
w := windowFor(h)
|
w := windowFor(h)
|
||||||
w.ProcessEvent(key.FocusEvent{Focus: focus == 1})
|
|
||||||
w.SetCursor(w.cursor)
|
w.SetCursor(w.cursor)
|
||||||
|
w.config.Focused = focus == 1
|
||||||
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onChangeScreen
|
//export gio_onChangeScreen
|
||||||
@@ -735,6 +860,15 @@ func gio_substringForProposedRange(h C.uintptr_t, crng C.NSRange, actual C.NSRan
|
|||||||
//export gio_insertText
|
//export gio_insertText
|
||||||
func gio_insertText(h C.uintptr_t, cstr C.CFTypeRef, crng C.NSRange) {
|
func gio_insertText(h C.uintptr_t, cstr C.CFTypeRef, crng C.NSRange) {
|
||||||
w := windowFor(h)
|
w := windowFor(h)
|
||||||
|
str := nsstringToString(cstr)
|
||||||
|
// macOS IME in some cases calls insertText for command keys such as backspace
|
||||||
|
// instead of doCommandBySelector.
|
||||||
|
for _, r := range str {
|
||||||
|
if _, ok := convertCommandKey(r); ok {
|
||||||
|
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
state := w.w.EditorState()
|
state := w.w.EditorState()
|
||||||
rng := state.compose
|
rng := state.compose
|
||||||
if rng.Start == -1 {
|
if rng.Start == -1 {
|
||||||
@@ -746,7 +880,6 @@ func gio_insertText(h C.uintptr_t, cstr C.CFTypeRef, crng C.NSRange) {
|
|||||||
End: state.RunesIndex(int(crng.location + crng.length)),
|
End: state.RunesIndex(int(crng.location + crng.length)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
str := nsstringToString(cstr)
|
|
||||||
w.w.EditorReplace(rng, str)
|
w.w.EditorReplace(rng, str)
|
||||||
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
||||||
start := rng.Start
|
start := rng.Start
|
||||||
@@ -773,7 +906,7 @@ func gio_firstRectForCharacterRange(h C.uintptr_t, crng C.NSRange, actual C.NSRa
|
|||||||
// Transform to NSView local coordinates (lower left origin, undo backing scale).
|
// Transform to NSView local coordinates (lower left origin, undo backing scale).
|
||||||
scale := 1. / float32(C.getViewBackingScale(w.view))
|
scale := 1. / float32(C.getViewBackingScale(w.view))
|
||||||
height := float32(C.viewHeight(w.view))
|
height := float32(C.viewHeight(w.view))
|
||||||
local := f32.Affine2D{}.Scale(f32.Pt(0, 0), f32.Pt(scale, -scale)).Offset(f32.Pt(0, height))
|
local := f32.AffineId().Scale(f32.Pt(0, 0), f32.Pt(scale, -scale)).Offset(f32.Pt(0, height))
|
||||||
t := local.Mul(sel.Transform)
|
t := local.Mul(sel.Transform)
|
||||||
bounds := f32.Rectangle{
|
bounds := f32.Rectangle{
|
||||||
Min: t.Transform(sel.Pos.Sub(f32.Pt(0, sel.Ascent))),
|
Min: t.Transform(sel.Pos.Sub(f32.Pt(0, sel.Ascent))),
|
||||||
@@ -787,24 +920,19 @@ func gio_firstRectForCharacterRange(h C.uintptr_t, crng C.NSRange, actual C.NSRa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) draw() {
|
func (w *window) draw() {
|
||||||
|
cnf := w.config
|
||||||
|
w.updateWindowMode()
|
||||||
|
if w.config != cnf {
|
||||||
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case <-w.redraw:
|
case <-w.redraw:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
w.visible = true
|
|
||||||
if w.anim {
|
if w.anim {
|
||||||
w.SetAnimating(w.anim)
|
w.SetAnimating(w.anim)
|
||||||
}
|
}
|
||||||
w.scale = float32(C.getViewBackingScale(w.view))
|
sz := w.config.Size
|
||||||
wf, hf := float32(C.viewWidth(w.view)), float32(C.viewHeight(w.view))
|
|
||||||
sz := image.Point{
|
|
||||||
X: int(wf*w.scale + .5),
|
|
||||||
Y: int(hf*w.scale + .5),
|
|
||||||
}
|
|
||||||
if sz != w.config.Size {
|
|
||||||
w.config.Size = sz
|
|
||||||
w.ProcessEvent(ConfigEvent{Config: w.config})
|
|
||||||
}
|
|
||||||
if sz.X == 0 || sz.Y == 0 {
|
if sz.X == 0 || sz.Y == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -812,7 +940,7 @@ func (w *window) draw() {
|
|||||||
w.ProcessEvent(frameEvent{
|
w.ProcessEvent(frameEvent{
|
||||||
FrameEvent: FrameEvent{
|
FrameEvent: FrameEvent{
|
||||||
Now: time.Now(),
|
Now: time.Now(),
|
||||||
Size: w.config.Size,
|
Size: sz,
|
||||||
Metric: cfg,
|
Metric: cfg,
|
||||||
},
|
},
|
||||||
Sync: true,
|
Sync: true,
|
||||||
@@ -820,8 +948,13 @@ func (w *window) draw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) ProcessEvent(e event.Event) {
|
func (w *window) ProcessEvent(e event.Event) {
|
||||||
w.w.ProcessEvent(e)
|
w.processEvent(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *window) processEvent(e event.Event) bool {
|
||||||
|
handled := w.w.ProcessEvent(e)
|
||||||
w.loop.FlushEvents()
|
w.loop.FlushEvents()
|
||||||
|
return handled
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Event() event.Event {
|
func (w *window) Event() event.Event {
|
||||||
@@ -855,7 +988,6 @@ func gio_onAttached(h C.uintptr_t, attached C.int) {
|
|||||||
w.ProcessEvent(AppKitViewEvent{View: uintptr(w.view), Layer: uintptr(layer)})
|
w.ProcessEvent(AppKitViewEvent{View: uintptr(w.view), Layer: uintptr(layer)})
|
||||||
} else {
|
} else {
|
||||||
w.ProcessEvent(AppKitViewEvent{})
|
w.ProcessEvent(AppKitViewEvent{})
|
||||||
w.visible = false
|
|
||||||
w.SetAnimating(w.anim)
|
w.SetAnimating(w.anim)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -870,38 +1002,21 @@ func gio_onDestroy(h C.uintptr_t) {
|
|||||||
w.view = 0
|
w.view = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onHide
|
|
||||||
func gio_onHide(h C.uintptr_t) {
|
|
||||||
w := windowFor(h)
|
|
||||||
w.visible = false
|
|
||||||
w.SetAnimating(w.anim)
|
|
||||||
}
|
|
||||||
|
|
||||||
//export gio_onShow
|
|
||||||
func gio_onShow(h C.uintptr_t) {
|
|
||||||
w := windowFor(h)
|
|
||||||
w.draw()
|
|
||||||
}
|
|
||||||
|
|
||||||
//export gio_onFullscreen
|
|
||||||
func gio_onFullscreen(h C.uintptr_t) {
|
|
||||||
w := windowFor(h)
|
|
||||||
w.config.Mode = Fullscreen
|
|
||||||
w.ProcessEvent(ConfigEvent{Config: w.config})
|
|
||||||
}
|
|
||||||
|
|
||||||
//export gio_onWindowed
|
|
||||||
func gio_onWindowed(h C.uintptr_t) {
|
|
||||||
w := windowFor(h)
|
|
||||||
w.config.Mode = Windowed
|
|
||||||
w.ProcessEvent(ConfigEvent{Config: w.config})
|
|
||||||
}
|
|
||||||
|
|
||||||
//export gio_onFinishLaunching
|
//export gio_onFinishLaunching
|
||||||
func gio_onFinishLaunching() {
|
func gio_onFinishLaunching() {
|
||||||
close(launched)
|
close(launched)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export gio_onOpenURI
|
||||||
|
func gio_onOpenURI(uri C.CFTypeRef) {
|
||||||
|
evt, err := newURLEvent(nsstringToString(uri))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
processGlobalEvent(evt)
|
||||||
|
}
|
||||||
|
|
||||||
func newWindow(win *callbacks, options []Option) {
|
func newWindow(win *callbacks, options []Option) {
|
||||||
<-launched
|
<-launched
|
||||||
res := make(chan struct{})
|
res := make(chan struct{})
|
||||||
@@ -913,14 +1028,15 @@ func newWindow(win *callbacks, options []Option) {
|
|||||||
w.loop = newEventLoop(w.w, w.wakeup)
|
w.loop = newEventLoop(w.w, w.wakeup)
|
||||||
win.SetDriver(w)
|
win.SetDriver(w)
|
||||||
res <- struct{}{}
|
res <- struct{}{}
|
||||||
if err := w.init(); err != nil {
|
var cnf Config
|
||||||
|
cnf.apply(unit.Metric{}, options)
|
||||||
|
if err := w.init(cnf.CustomRenderer); err != nil {
|
||||||
w.ProcessEvent(DestroyEvent{Err: err})
|
w.ProcessEvent(DestroyEvent{Err: err})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
window := C.gio_createWindow(w.view, 0, 0, 0, 0, 0, 0)
|
window := C.gio_createWindow(w.view, C.CGFloat(cnf.Size.X), C.CGFloat(cnf.Size.Y))
|
||||||
// Release our reference now that the NSWindow has it.
|
// Release our reference now that the NSWindow has it.
|
||||||
C.CFRelease(w.view)
|
C.CFRelease(w.view)
|
||||||
w.updateWindowMode()
|
|
||||||
w.Configure(options)
|
w.Configure(options)
|
||||||
if nextTopLeft.x == 0 && nextTopLeft.y == 0 {
|
if nextTopLeft.x == 0 && nextTopLeft.y == 0 {
|
||||||
// cascadeTopLeftFromPoint treats (0, 0) as a no-op,
|
// cascadeTopLeftFromPoint treats (0, 0) as a no-op,
|
||||||
@@ -928,14 +1044,19 @@ func newWindow(win *callbacks, options []Option) {
|
|||||||
nextTopLeft = C.cascadeTopLeftFromPoint(window, nextTopLeft)
|
nextTopLeft = C.cascadeTopLeftFromPoint(window, nextTopLeft)
|
||||||
}
|
}
|
||||||
nextTopLeft = C.cascadeTopLeftFromPoint(window, nextTopLeft)
|
nextTopLeft = C.cascadeTopLeftFromPoint(window, nextTopLeft)
|
||||||
|
C.makeFirstResponder(window, w.view)
|
||||||
// makeKeyAndOrderFront assumes ownership of our window reference.
|
// makeKeyAndOrderFront assumes ownership of our window reference.
|
||||||
C.makeKeyAndOrderFront(window)
|
C.makeKeyAndOrderFront(window)
|
||||||
})
|
})
|
||||||
<-res
|
<-res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) init() error {
|
func (w *window) init(customRenderer bool) error {
|
||||||
view := C.gio_createView()
|
presentWithTrans := 1
|
||||||
|
if customRenderer {
|
||||||
|
presentWithTrans = 0
|
||||||
|
}
|
||||||
|
view := C.gio_createView(C.int(presentWithTrans))
|
||||||
if view == 0 {
|
if view == 0 {
|
||||||
return errors.New("newOSWindow: failed to create view")
|
return errors.New("newOSWindow: failed to create view")
|
||||||
}
|
}
|
||||||
@@ -948,9 +1069,7 @@ func (w *window) init() error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.runOnMain(func() {
|
w.runOnMain(func() {
|
||||||
if w.visible {
|
C.setNeedsDisplay(w.view)
|
||||||
C.setNeedsDisplay(w.view)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
w.displayLink = dl
|
w.displayLink = dl
|
||||||
@@ -964,13 +1083,16 @@ func (w *window) init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func osMain() {
|
func osMain() {
|
||||||
|
if !isMainThread() {
|
||||||
|
panic("app.Main must run on the main goroutine")
|
||||||
|
}
|
||||||
C.gio_main()
|
C.gio_main()
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertKey(k rune) (key.Name, bool) {
|
func convertCommandKey(k rune) (key.Name, bool) {
|
||||||
var n key.Name
|
var n key.Name
|
||||||
switch k {
|
switch k {
|
||||||
case 0x1b:
|
case '\x1b': // ASCII escape.
|
||||||
n = key.NameEscape
|
n = key.NameEscape
|
||||||
case C.NSLeftArrowFunctionKey:
|
case C.NSLeftArrowFunctionKey:
|
||||||
n = key.NameLeftArrow
|
n = key.NameLeftArrow
|
||||||
@@ -980,22 +1102,36 @@ func convertKey(k rune) (key.Name, bool) {
|
|||||||
n = key.NameUpArrow
|
n = key.NameUpArrow
|
||||||
case C.NSDownArrowFunctionKey:
|
case C.NSDownArrowFunctionKey:
|
||||||
n = key.NameDownArrow
|
n = key.NameDownArrow
|
||||||
case 0xd:
|
case '\r':
|
||||||
n = key.NameReturn
|
n = key.NameReturn
|
||||||
case 0x3:
|
case '\x03':
|
||||||
n = key.NameEnter
|
n = key.NameEnter
|
||||||
case C.NSHomeFunctionKey:
|
case C.NSHomeFunctionKey:
|
||||||
n = key.NameHome
|
n = key.NameHome
|
||||||
case C.NSEndFunctionKey:
|
case C.NSEndFunctionKey:
|
||||||
n = key.NameEnd
|
n = key.NameEnd
|
||||||
case 0x7f:
|
case '\x7f', '\b':
|
||||||
n = key.NameDeleteBackward
|
n = key.NameDeleteBackward
|
||||||
case C.NSDeleteFunctionKey:
|
case C.NSDeleteFunctionKey:
|
||||||
n = key.NameDeleteForward
|
n = key.NameDeleteForward
|
||||||
|
case '\t', 0x19:
|
||||||
|
n = key.NameTab
|
||||||
case C.NSPageUpFunctionKey:
|
case C.NSPageUpFunctionKey:
|
||||||
n = key.NamePageUp
|
n = key.NamePageUp
|
||||||
case C.NSPageDownFunctionKey:
|
case C.NSPageDownFunctionKey:
|
||||||
n = key.NamePageDown
|
n = key.NamePageDown
|
||||||
|
default:
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return n, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertKey(k rune) (key.Name, bool) {
|
||||||
|
if n, ok := convertCommandKey(k); ok {
|
||||||
|
return n, true
|
||||||
|
}
|
||||||
|
var n key.Name
|
||||||
|
switch k {
|
||||||
case C.NSF1FunctionKey:
|
case C.NSF1FunctionKey:
|
||||||
n = key.NameF1
|
n = key.NameF1
|
||||||
case C.NSF2FunctionKey:
|
case C.NSF2FunctionKey:
|
||||||
@@ -1020,8 +1156,6 @@ func convertKey(k rune) (key.Name, bool) {
|
|||||||
n = key.NameF11
|
n = key.NameF11
|
||||||
case C.NSF12FunctionKey:
|
case C.NSF12FunctionKey:
|
||||||
n = key.NameF12
|
n = key.NameF12
|
||||||
case 0x09, 0x19:
|
|
||||||
n = key.NameTab
|
|
||||||
case 0x20:
|
case 0x20:
|
||||||
n = key.NameSpace
|
n = key.NameSpace
|
||||||
default:
|
default:
|
||||||
@@ -1053,3 +1187,6 @@ func convertMods(mods C.NSUInteger) key.Modifiers {
|
|||||||
|
|
||||||
func (AppKitViewEvent) implementsViewEvent() {}
|
func (AppKitViewEvent) implementsViewEvent() {}
|
||||||
func (AppKitViewEvent) ImplementsEvent() {}
|
func (AppKitViewEvent) ImplementsEvent() {}
|
||||||
|
func (a AppKitViewEvent) Valid() bool {
|
||||||
|
return a != (AppKitViewEvent{})
|
||||||
|
}
|
||||||
|
|||||||
+65
-29
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "_cgo_export.h"
|
#include "_cgo_export.h"
|
||||||
|
|
||||||
__attribute__ ((visibility ("hidden"))) CALayer *gio_layerFactory(void);
|
__attribute__ ((visibility ("hidden"))) CALayer *gio_layerFactory(BOOL presentWithTrans);
|
||||||
|
|
||||||
@interface GioAppDelegate : NSObject<NSApplicationDelegate>
|
@interface GioAppDelegate : NSObject<NSApplicationDelegate>
|
||||||
@end
|
@end
|
||||||
@@ -16,28 +16,29 @@ __attribute__ ((visibility ("hidden"))) CALayer *gio_layerFactory(void);
|
|||||||
|
|
||||||
@interface GioView : NSView <CALayerDelegate,NSTextInputClient>
|
@interface GioView : NSView <CALayerDelegate,NSTextInputClient>
|
||||||
@property uintptr_t handle;
|
@property uintptr_t handle;
|
||||||
|
@property BOOL presentWithTrans;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation GioWindowDelegate
|
@implementation GioWindowDelegate
|
||||||
- (void)windowWillMiniaturize:(NSNotification *)notification {
|
- (void)windowWillMiniaturize:(NSNotification *)notification {
|
||||||
NSWindow *window = (NSWindow *)[notification object];
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
GioView *view = (GioView *)window.contentView;
|
GioView *view = (GioView *)window.contentView;
|
||||||
gio_onHide(view.handle);
|
gio_onDraw(view.handle);
|
||||||
}
|
}
|
||||||
- (void)windowDidDeminiaturize:(NSNotification *)notification {
|
- (void)windowDidDeminiaturize:(NSNotification *)notification {
|
||||||
NSWindow *window = (NSWindow *)[notification object];
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
GioView *view = (GioView *)window.contentView;
|
GioView *view = (GioView *)window.contentView;
|
||||||
gio_onShow(view.handle);
|
gio_onDraw(view.handle);
|
||||||
}
|
}
|
||||||
- (void)windowWillEnterFullScreen:(NSNotification *)notification {
|
- (void)windowWillEnterFullScreen:(NSNotification *)notification {
|
||||||
NSWindow *window = (NSWindow *)[notification object];
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
GioView *view = (GioView *)window.contentView;
|
GioView *view = (GioView *)window.contentView;
|
||||||
gio_onFullscreen(view.handle);
|
gio_onDraw(view.handle);
|
||||||
}
|
}
|
||||||
- (void)windowWillExitFullScreen:(NSNotification *)notification {
|
- (void)windowWillExitFullScreen:(NSNotification *)notification {
|
||||||
NSWindow *window = (NSWindow *)[notification object];
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
GioView *view = (GioView *)window.contentView;
|
GioView *view = (GioView *)window.contentView;
|
||||||
gio_onWindowed(view.handle);
|
gio_onDraw(view.handle);
|
||||||
}
|
}
|
||||||
- (void)windowDidChangeScreen:(NSNotification *)notification {
|
- (void)windowDidChangeScreen:(NSNotification *)notification {
|
||||||
NSWindow *window = (NSWindow *)[notification object];
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
@@ -47,13 +48,17 @@ __attribute__ ((visibility ("hidden"))) CALayer *gio_layerFactory(void);
|
|||||||
}
|
}
|
||||||
- (void)windowDidBecomeKey:(NSNotification *)notification {
|
- (void)windowDidBecomeKey:(NSNotification *)notification {
|
||||||
NSWindow *window = (NSWindow *)[notification object];
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
GioView *view = (GioView *)window.contentView;
|
GioView *view = (GioView *)window.contentView;
|
||||||
gio_onFocus(view.handle, 1);
|
if ([window firstResponder] == view) {
|
||||||
|
gio_onFocus(view.handle, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
- (void)windowDidResignKey:(NSNotification *)notification {
|
- (void)windowDidResignKey:(NSNotification *)notification {
|
||||||
NSWindow *window = (NSWindow *)[notification object];
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
GioView *view = (GioView *)window.contentView;
|
GioView *view = (GioView *)window.contentView;
|
||||||
gio_onFocus(view.handle, 0);
|
if ([window firstResponder] == view) {
|
||||||
|
gio_onFocus(view.handle, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -84,7 +89,7 @@ static void handleMouse(GioView *view, NSEvent *event, int typ, CGFloat dx, CGFl
|
|||||||
gio_onDraw(self.handle);
|
gio_onDraw(self.handle);
|
||||||
}
|
}
|
||||||
- (CALayer *)makeBackingLayer {
|
- (CALayer *)makeBackingLayer {
|
||||||
CALayer *layer = gio_layerFactory();
|
CALayer *layer = gio_layerFactory(self.presentWithTrans);
|
||||||
layer.delegate = self;
|
layer.delegate = self;
|
||||||
return layer;
|
return layer;
|
||||||
}
|
}
|
||||||
@@ -127,22 +132,25 @@ static void handleMouse(GioView *view, NSEvent *event, int typ, CGFloat dx, CGFl
|
|||||||
handleMouse(self, event, MOUSE_SCROLL, dx, dy);
|
handleMouse(self, event, MOUSE_SCROLL, dx, dy);
|
||||||
}
|
}
|
||||||
- (void)keyDown:(NSEvent *)event {
|
- (void)keyDown:(NSEvent *)event {
|
||||||
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
|
|
||||||
NSString *keys = [event charactersIgnoringModifiers];
|
NSString *keys = [event charactersIgnoringModifiers];
|
||||||
gio_onKeys(self.handle, (__bridge CFTypeRef)keys, [event timestamp], [event modifierFlags], true);
|
gio_onKeys(self.handle, (__bridge CFTypeRef)event, (__bridge CFTypeRef)keys, [event timestamp], [event modifierFlags], true);
|
||||||
|
}
|
||||||
|
- (void)flagsChanged:(NSEvent *)event {
|
||||||
|
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
|
||||||
|
gio_onFlagsChanged(self.handle, [event modifierFlags]);
|
||||||
}
|
}
|
||||||
- (void)keyUp:(NSEvent *)event {
|
- (void)keyUp:(NSEvent *)event {
|
||||||
NSString *keys = [event charactersIgnoringModifiers];
|
NSString *keys = [event charactersIgnoringModifiers];
|
||||||
gio_onKeys(self.handle, (__bridge CFTypeRef)keys, [event timestamp], [event modifierFlags], false);
|
gio_onKeys(self.handle, (__bridge CFTypeRef)event, (__bridge CFTypeRef)keys, [event timestamp], [event modifierFlags], false);
|
||||||
}
|
}
|
||||||
- (void)insertText:(id)string {
|
- (void)insertText:(id)string {
|
||||||
gio_onText(self.handle, (__bridge CFTypeRef)string);
|
gio_onText(self.handle, (__bridge CFTypeRef)string);
|
||||||
}
|
}
|
||||||
- (void)doCommandBySelector:(SEL)sel {
|
- (void)doCommandBySelector:(SEL)action {
|
||||||
// Don't pass commands up the responder chain.
|
if (!gio_onCommandBySelector(self.handle)) {
|
||||||
// They will end up in a beep.
|
[super doCommandBySelector:action];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)hasMarkedText {
|
- (BOOL)hasMarkedText {
|
||||||
int res = gio_hasMarkedText(self.handle);
|
int res = gio_hasMarkedText(self.handle);
|
||||||
return res ? YES : NO;
|
return res ? YES : NO;
|
||||||
@@ -197,14 +205,22 @@ static void handleMouse(GioView *view, NSEvent *event, int typ, CGFloat dx, CGFl
|
|||||||
return [[self window] convertRectToScreen:r];
|
return [[self window] convertRectToScreen:r];
|
||||||
}
|
}
|
||||||
- (void)applicationWillUnhide:(NSNotification *)notification {
|
- (void)applicationWillUnhide:(NSNotification *)notification {
|
||||||
gio_onShow(self.handle);
|
gio_onDraw(self.handle);
|
||||||
}
|
}
|
||||||
- (void)applicationDidHide:(NSNotification *)notification {
|
- (void)applicationDidHide:(NSNotification *)notification {
|
||||||
gio_onHide(self.handle);
|
gio_onDraw(self.handle);
|
||||||
}
|
}
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
gio_onDestroy(self.handle);
|
gio_onDestroy(self.handle);
|
||||||
}
|
}
|
||||||
|
- (BOOL) becomeFirstResponder {
|
||||||
|
gio_onFocus(self.handle, 1);
|
||||||
|
return [super becomeFirstResponder];
|
||||||
|
}
|
||||||
|
- (BOOL) resignFirstResponder {
|
||||||
|
gio_onFocus(self.handle, 0);
|
||||||
|
return [super resignFirstResponder];
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// Delegates are weakly referenced from their peers. Nothing
|
// Delegates are weakly referenced from their peers. Nothing
|
||||||
@@ -353,7 +369,7 @@ void gio_setCursor(NSUInteger curID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CFTypeRef gio_createWindow(CFTypeRef viewRef, CGFloat width, CGFloat height, CGFloat minWidth, CGFloat minHeight, CGFloat maxWidth, CGFloat maxHeight) {
|
CFTypeRef gio_createWindow(CFTypeRef viewRef, CGFloat width, CGFloat height) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSRect rect = NSMakeRect(0, 0, width, height);
|
NSRect rect = NSMakeRect(0, 0, width, height);
|
||||||
NSUInteger styleMask = NSTitledWindowMask |
|
NSUInteger styleMask = NSTitledWindowMask |
|
||||||
@@ -365,25 +381,19 @@ CFTypeRef gio_createWindow(CFTypeRef viewRef, CGFloat width, CGFloat height, CGF
|
|||||||
styleMask:styleMask
|
styleMask:styleMask
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
defer:NO];
|
defer:NO];
|
||||||
if (minWidth > 0 || minHeight > 0) {
|
|
||||||
window.contentMinSize = NSMakeSize(minWidth, minHeight);
|
|
||||||
}
|
|
||||||
if (maxWidth > 0 || maxHeight > 0) {
|
|
||||||
window.contentMaxSize = NSMakeSize(maxWidth, maxHeight);
|
|
||||||
}
|
|
||||||
[window setAcceptsMouseMovedEvents:YES];
|
[window setAcceptsMouseMovedEvents:YES];
|
||||||
NSView *view = (__bridge NSView *)viewRef;
|
NSView *view = (__bridge NSView *)viewRef;
|
||||||
[window setContentView:view];
|
[window setContentView:view];
|
||||||
[window makeFirstResponder:view];
|
|
||||||
window.delegate = globalWindowDel;
|
window.delegate = globalWindowDel;
|
||||||
return (__bridge_retained CFTypeRef)window;
|
return (__bridge_retained CFTypeRef)window;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CFTypeRef gio_createView(void) {
|
CFTypeRef gio_createView(int presentWithTrans) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSRect frame = NSMakeRect(0, 0, 0, 0);
|
NSRect frame = NSMakeRect(0, 0, 0, 0);
|
||||||
GioView* view = [[GioView alloc] initWithFrame:frame];
|
GioView* view = [[GioView alloc] initWithFrame:frame];
|
||||||
|
view.presentWithTrans = presentWithTrans ? YES : NO;
|
||||||
view.wantsLayer = YES;
|
view.wantsLayer = YES;
|
||||||
view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize;
|
view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize;
|
||||||
|
|
||||||
@@ -410,7 +420,11 @@ void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle) {
|
|||||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
gio_onFinishLaunching();
|
}
|
||||||
|
- (void)application:(NSApplication *)application openURLs:(NSArray<NSURL *> *)urls {
|
||||||
|
for (NSURL *url in urls) {
|
||||||
|
gio_onOpenURI((__bridge CFTypeRef)url.absoluteString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -441,3 +455,25 @@ void gio_main() {
|
|||||||
[NSApp run];
|
[NSApp run];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface AppListener : NSObject
|
||||||
|
@end
|
||||||
|
|
||||||
|
static AppListener *appListener;
|
||||||
|
|
||||||
|
@implementation AppListener
|
||||||
|
- (void)launchFinished:(NSNotification *)notification {
|
||||||
|
appListener = nil;
|
||||||
|
gio_onFinishLaunching();
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
void gio_init() {
|
||||||
|
@autoreleasepool {
|
||||||
|
appListener = [[AppListener alloc] init];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:appListener
|
||||||
|
selector:@selector(launchFinished:)
|
||||||
|
name:NSApplicationDidFinishLaunchingNotification
|
||||||
|
object:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+6
-25
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build (linux && !android) || freebsd || openbsd
|
//go:build (linux && !android) || freebsd || openbsd
|
||||||
// +build linux,!android freebsd openbsd
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
@@ -9,7 +8,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"gioui.org/io/event"
|
|
||||||
"gioui.org/io/pointer"
|
"gioui.org/io/pointer"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,6 +20,9 @@ type X11ViewEvent struct {
|
|||||||
|
|
||||||
func (X11ViewEvent) implementsViewEvent() {}
|
func (X11ViewEvent) implementsViewEvent() {}
|
||||||
func (X11ViewEvent) ImplementsEvent() {}
|
func (X11ViewEvent) ImplementsEvent() {}
|
||||||
|
func (x X11ViewEvent) Valid() bool {
|
||||||
|
return x != (X11ViewEvent{})
|
||||||
|
}
|
||||||
|
|
||||||
type WaylandViewEvent struct {
|
type WaylandViewEvent struct {
|
||||||
// Display is the *wl_display returned by wl_display_connect.
|
// Display is the *wl_display returned by wl_display_connect.
|
||||||
@@ -32,6 +33,9 @@ type WaylandViewEvent struct {
|
|||||||
|
|
||||||
func (WaylandViewEvent) implementsViewEvent() {}
|
func (WaylandViewEvent) implementsViewEvent() {}
|
||||||
func (WaylandViewEvent) ImplementsEvent() {}
|
func (WaylandViewEvent) ImplementsEvent() {}
|
||||||
|
func (w WaylandViewEvent) Valid() bool {
|
||||||
|
return w != (WaylandViewEvent{})
|
||||||
|
}
|
||||||
|
|
||||||
func osMain() {
|
func osMain() {
|
||||||
select {}
|
select {}
|
||||||
@@ -57,35 +61,12 @@ func newWindow(window *callbacks, options []Option) {
|
|||||||
errFirst = err
|
errFirst = err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.SetDriver(&dummyDriver{
|
|
||||||
win: window,
|
|
||||||
wakeups: make(chan event.Event, 1),
|
|
||||||
})
|
|
||||||
if errFirst == nil {
|
if errFirst == nil {
|
||||||
errFirst = errors.New("app: no window driver available")
|
errFirst = errors.New("app: no window driver available")
|
||||||
}
|
}
|
||||||
window.ProcessEvent(DestroyEvent{Err: errFirst})
|
window.ProcessEvent(DestroyEvent{Err: errFirst})
|
||||||
}
|
}
|
||||||
|
|
||||||
type dummyDriver struct {
|
|
||||||
win *callbacks
|
|
||||||
wakeups chan event.Event
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dummyDriver) Event() event.Event {
|
|
||||||
if e, ok := d.win.nextEvent(); ok {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
return <-d.wakeups
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dummyDriver) Invalidate() {
|
|
||||||
select {
|
|
||||||
case d.wakeups <- wakeupEvent{}:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// xCursor contains mapping from pointer.Cursor to XCursor.
|
// xCursor contains mapping from pointer.Cursor to XCursor.
|
||||||
var xCursor = [...]string{
|
var xCursor = [...]string{
|
||||||
pointer.CursorDefault: "left_ptr",
|
pointer.CursorDefault: "left_ptr",
|
||||||
|
|||||||
+50
-40
@@ -116,6 +116,8 @@ type wlSeat struct {
|
|||||||
|
|
||||||
// The most recent input serial.
|
// The most recent input serial.
|
||||||
serial C.uint32_t
|
serial C.uint32_t
|
||||||
|
// The most recent pointer enter serial.
|
||||||
|
pointerSerial C.uint32_t
|
||||||
|
|
||||||
pointerFocus *window
|
pointerFocus *window
|
||||||
keyboardFocus *window
|
keyboardFocus *window
|
||||||
@@ -154,7 +156,6 @@ type repeatState struct {
|
|||||||
type window struct {
|
type window struct {
|
||||||
w *callbacks
|
w *callbacks
|
||||||
disp *wlDisplay
|
disp *wlDisplay
|
||||||
seat *wlSeat
|
|
||||||
surf *C.struct_wl_surface
|
surf *C.struct_wl_surface
|
||||||
wmSurf *C.struct_xdg_surface
|
wmSurf *C.struct_xdg_surface
|
||||||
topLvl *C.struct_xdg_toplevel
|
topLvl *C.struct_xdg_toplevel
|
||||||
@@ -216,9 +217,7 @@ type window struct {
|
|||||||
|
|
||||||
wakeups chan struct{}
|
wakeups chan struct{}
|
||||||
|
|
||||||
// invMu avoids the race between the destruction of disp and
|
closing bool
|
||||||
// Invalidate waking it up.
|
|
||||||
invMu sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type poller struct {
|
type poller struct {
|
||||||
@@ -556,7 +555,7 @@ func gio_onXdgSurfaceConfigure(data unsafe.Pointer, wmSurf *C.struct_xdg_surface
|
|||||||
//export gio_onToplevelClose
|
//export gio_onToplevelClose
|
||||||
func gio_onToplevelClose(data unsafe.Pointer, topLvl *C.struct_xdg_toplevel) {
|
func gio_onToplevelClose(data unsafe.Pointer, topLvl *C.struct_xdg_toplevel) {
|
||||||
w := callbackLoad(data).(*window)
|
w := callbackLoad(data).(*window)
|
||||||
w.close(nil)
|
w.closing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onToplevelConfigure
|
//export gio_onToplevelConfigure
|
||||||
@@ -853,8 +852,8 @@ func gio_onTouchCancel(data unsafe.Pointer, touch *C.struct_wl_touch) {
|
|||||||
func gio_onPointerEnter(data unsafe.Pointer, pointer *C.struct_wl_pointer, serial C.uint32_t, surf *C.struct_wl_surface, x, y C.wl_fixed_t) {
|
func gio_onPointerEnter(data unsafe.Pointer, pointer *C.struct_wl_pointer, serial C.uint32_t, surf *C.struct_wl_surface, x, y C.wl_fixed_t) {
|
||||||
s := callbackLoad(data).(*wlSeat)
|
s := callbackLoad(data).(*wlSeat)
|
||||||
s.serial = serial
|
s.serial = serial
|
||||||
|
s.pointerSerial = serial
|
||||||
w := callbackLoad(unsafe.Pointer(surf)).(*window)
|
w := callbackLoad(unsafe.Pointer(surf)).(*window)
|
||||||
w.seat = s
|
|
||||||
s.pointerFocus = w
|
s.pointerFocus = w
|
||||||
w.setCursor(pointer, serial)
|
w.setCursor(pointer, serial)
|
||||||
w.lastPos = f32.Point{X: fromFixed(x), Y: fromFixed(y)}
|
w.lastPos = f32.Point{X: fromFixed(x), Y: fromFixed(y)}
|
||||||
@@ -863,9 +862,9 @@ func gio_onPointerEnter(data unsafe.Pointer, pointer *C.struct_wl_pointer, seria
|
|||||||
//export gio_onPointerLeave
|
//export gio_onPointerLeave
|
||||||
func gio_onPointerLeave(data unsafe.Pointer, p *C.struct_wl_pointer, serial C.uint32_t, surf *C.struct_wl_surface) {
|
func gio_onPointerLeave(data unsafe.Pointer, p *C.struct_wl_pointer, serial C.uint32_t, surf *C.struct_wl_surface) {
|
||||||
w := callbackLoad(unsafe.Pointer(surf)).(*window)
|
w := callbackLoad(unsafe.Pointer(surf)).(*window)
|
||||||
w.seat = nil
|
|
||||||
s := callbackLoad(data).(*wlSeat)
|
s := callbackLoad(data).(*wlSeat)
|
||||||
s.serial = serial
|
s.serial = serial
|
||||||
|
s.pointerFocus = nil
|
||||||
if w.inCompositor {
|
if w.inCompositor {
|
||||||
w.inCompositor = false
|
w.inCompositor = false
|
||||||
w.ProcessEvent(pointer.Event{Kind: pointer.Cancel})
|
w.ProcessEvent(pointer.Event{Kind: pointer.Cancel})
|
||||||
@@ -885,11 +884,13 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t,
|
|||||||
s := callbackLoad(data).(*wlSeat)
|
s := callbackLoad(data).(*wlSeat)
|
||||||
s.serial = serial
|
s.serial = serial
|
||||||
w := s.pointerFocus
|
w := s.pointerFocus
|
||||||
// From linux-event-codes.h.
|
// From Linux: include/uapi/linux/input-event-codes.h
|
||||||
const (
|
const (
|
||||||
BTN_LEFT = 0x110
|
BTN_LEFT = 0x110
|
||||||
BTN_RIGHT = 0x111
|
BTN_RIGHT = 0x111
|
||||||
BTN_MIDDLE = 0x112
|
BTN_MIDDLE = 0x112
|
||||||
|
BTN_SIDE = 0x113
|
||||||
|
BTN_EXTRA = 0x114
|
||||||
)
|
)
|
||||||
var btn pointer.Buttons
|
var btn pointer.Buttons
|
||||||
switch wbtn {
|
switch wbtn {
|
||||||
@@ -899,6 +900,10 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t,
|
|||||||
btn = pointer.ButtonSecondary
|
btn = pointer.ButtonSecondary
|
||||||
case BTN_MIDDLE:
|
case BTN_MIDDLE:
|
||||||
btn = pointer.ButtonTertiary
|
btn = pointer.ButtonTertiary
|
||||||
|
case BTN_SIDE:
|
||||||
|
btn = pointer.ButtonQuaternary
|
||||||
|
case BTN_EXTRA:
|
||||||
|
btn = pointer.ButtonQuinary
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -965,6 +970,9 @@ func gio_onPointerAxis(data unsafe.Pointer, p *C.struct_wl_pointer, t, axis C.ui
|
|||||||
func gio_onPointerFrame(data unsafe.Pointer, p *C.struct_wl_pointer) {
|
func gio_onPointerFrame(data unsafe.Pointer, p *C.struct_wl_pointer) {
|
||||||
s := callbackLoad(data).(*wlSeat)
|
s := callbackLoad(data).(*wlSeat)
|
||||||
w := s.pointerFocus
|
w := s.pointerFocus
|
||||||
|
if w == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
w.flushScroll()
|
w.flushScroll()
|
||||||
w.flushFling()
|
w.flushFling()
|
||||||
}
|
}
|
||||||
@@ -1139,22 +1147,23 @@ func (w *window) Perform(actions system.Action) {
|
|||||||
walkActions(actions, func(action system.Action) {
|
walkActions(actions, func(action system.Action) {
|
||||||
switch action {
|
switch action {
|
||||||
case system.ActionClose:
|
case system.ActionClose:
|
||||||
w.close(nil)
|
w.closing = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) move(serial C.uint32_t) {
|
func (w *window) move(serial C.uint32_t) {
|
||||||
s := w.seat
|
s := w.disp.seat
|
||||||
if !w.inCompositor && s != nil {
|
if w.inCompositor || s.pointerFocus != w {
|
||||||
w.inCompositor = true
|
return
|
||||||
C.xdg_toplevel_move(w.topLvl, s.seat, serial)
|
|
||||||
}
|
}
|
||||||
|
w.inCompositor = true
|
||||||
|
C.xdg_toplevel_move(w.topLvl, s.seat, serial)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) resize(serial, edge C.uint32_t) {
|
func (w *window) resize(serial, edge C.uint32_t) {
|
||||||
s := w.seat
|
s := w.disp.seat
|
||||||
if w.inCompositor || s == nil {
|
if w.inCompositor || s.pointerFocus != w {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.inCompositor = true
|
w.inCompositor = true
|
||||||
@@ -1167,11 +1176,12 @@ func (w *window) SetCursor(cursor pointer.Cursor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) updateCursor() {
|
func (w *window) updateCursor() {
|
||||||
ptr := w.disp.seat.pointer
|
s := w.disp.seat
|
||||||
if ptr == nil {
|
ptr := s.pointer
|
||||||
|
if ptr == nil || s.pointerFocus != w {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.setCursor(ptr, w.serial)
|
w.setCursor(ptr, s.pointerSerial)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setCursor(pointer *C.struct_wl_pointer, serial C.uint32_t) {
|
func (w *window) setCursor(pointer *C.struct_wl_pointer, serial C.uint32_t) {
|
||||||
@@ -1180,7 +1190,7 @@ func (w *window) setCursor(pointer *C.struct_wl_pointer, serial C.uint32_t) {
|
|||||||
c = w.cursor.cursor
|
c = w.cursor.cursor
|
||||||
}
|
}
|
||||||
if c == nil {
|
if c == nil {
|
||||||
C.wl_pointer_set_cursor(pointer, w.serial, nil, 0, 0)
|
C.wl_pointer_set_cursor(pointer, serial, nil, 0, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Get images[0].
|
// Get images[0].
|
||||||
@@ -1222,7 +1232,8 @@ func gio_onKeyboardEnter(data unsafe.Pointer, keyboard *C.struct_wl_keyboard, se
|
|||||||
w := callbackLoad(unsafe.Pointer(surf)).(*window)
|
w := callbackLoad(unsafe.Pointer(surf)).(*window)
|
||||||
s.keyboardFocus = w
|
s.keyboardFocus = w
|
||||||
s.disp.repeat.Stop(0)
|
s.disp.repeat.Stop(0)
|
||||||
w.ProcessEvent(key.FocusEvent{Focus: true})
|
w.config.Focused = true
|
||||||
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onKeyboardLeave
|
//export gio_onKeyboardLeave
|
||||||
@@ -1231,7 +1242,8 @@ func gio_onKeyboardLeave(data unsafe.Pointer, keyboard *C.struct_wl_keyboard, se
|
|||||||
s.serial = serial
|
s.serial = serial
|
||||||
s.disp.repeat.Stop(0)
|
s.disp.repeat.Stop(0)
|
||||||
w := s.keyboardFocus
|
w := s.keyboardFocus
|
||||||
w.ProcessEvent(key.FocusEvent{Focus: false})
|
w.config.Focused = false
|
||||||
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onKeyboardKey
|
//export gio_onKeyboardKey
|
||||||
@@ -1364,6 +1376,9 @@ func gio_onFrameDone(data unsafe.Pointer, callback *C.struct_wl_callback, t C.ui
|
|||||||
func (w *window) close(err error) {
|
func (w *window) close(err error) {
|
||||||
w.ProcessEvent(WaylandViewEvent{})
|
w.ProcessEvent(WaylandViewEvent{})
|
||||||
w.ProcessEvent(DestroyEvent{Err: err})
|
w.ProcessEvent(DestroyEvent{Err: err})
|
||||||
|
w.destroy()
|
||||||
|
w.disp.destroy()
|
||||||
|
w.disp = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) dispatch() {
|
func (w *window) dispatch() {
|
||||||
@@ -1372,7 +1387,7 @@ func (w *window) dispatch() {
|
|||||||
w.w.Invalidate()
|
w.w.Invalidate()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := w.disp.dispatch(); err != nil {
|
if err := w.disp.dispatch(); err != nil || w.closing {
|
||||||
w.close(err)
|
w.close(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1397,13 +1412,6 @@ func (w *window) Event() event.Event {
|
|||||||
w.dispatch()
|
w.dispatch()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, destroy := evt.(DestroyEvent); destroy {
|
|
||||||
w.destroy()
|
|
||||||
w.invMu.Lock()
|
|
||||||
w.disp.destroy()
|
|
||||||
w.disp = nil
|
|
||||||
w.invMu.Unlock()
|
|
||||||
}
|
|
||||||
return evt
|
return evt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1414,11 +1422,7 @@ func (w *window) Invalidate() {
|
|||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.invMu.Lock()
|
w.disp.wakeup()
|
||||||
defer w.invMu.Unlock()
|
|
||||||
if w.disp != nil {
|
|
||||||
w.disp.wakeup()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Run(f func()) {
|
func (w *window) Run(f func()) {
|
||||||
@@ -1513,6 +1517,10 @@ func (d *wlDisplay) wakeup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) destroy() {
|
func (w *window) destroy() {
|
||||||
|
if w.lastFrameCallback != nil {
|
||||||
|
C.wl_callback_destroy(w.lastFrameCallback)
|
||||||
|
w.lastFrameCallback = nil
|
||||||
|
}
|
||||||
if w.cursor.surf != nil {
|
if w.cursor.surf != nil {
|
||||||
C.wl_surface_destroy(w.cursor.surf)
|
C.wl_surface_destroy(w.cursor.surf)
|
||||||
}
|
}
|
||||||
@@ -1637,6 +1645,14 @@ func (w *window) flushScroll() {
|
|||||||
if total == (f32.Point{}) {
|
if total == (f32.Point{}) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if w.scroll.steps == (image.Point{}) {
|
||||||
|
w.fling.xExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.X)
|
||||||
|
w.fling.yExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.Y)
|
||||||
|
}
|
||||||
|
// Zero scroll distance prior to calling ProcessEvent, otherwise we may recursively
|
||||||
|
// re-process the scroll distance.
|
||||||
|
w.scroll.dist = f32.Point{}
|
||||||
|
w.scroll.steps = image.Point{}
|
||||||
w.ProcessEvent(pointer.Event{
|
w.ProcessEvent(pointer.Event{
|
||||||
Kind: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
@@ -1646,12 +1662,6 @@ func (w *window) flushScroll() {
|
|||||||
Time: w.scroll.time,
|
Time: w.scroll.time,
|
||||||
Modifiers: w.disp.xkb.Modifiers(),
|
Modifiers: w.disp.xkb.Modifiers(),
|
||||||
})
|
})
|
||||||
if w.scroll.steps == (image.Point{}) {
|
|
||||||
w.fling.xExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.X)
|
|
||||||
w.fling.yExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.Y)
|
|
||||||
}
|
|
||||||
w.scroll.dist = f32.Point{}
|
|
||||||
w.scroll.steps = image.Point{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) onPointerMotion(x, y C.wl_fixed_t, t C.uint32_t) {
|
func (w *window) onPointerMotion(x, y C.wl_fixed_t, t C.uint32_t) {
|
||||||
|
|||||||
+465
-158
@@ -5,8 +5,12 @@ package app
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gioui.org/io/transfer"
|
||||||
|
syscall "golang.org/x/sys/windows"
|
||||||
|
"golang.org/x/sys/windows/registry"
|
||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -16,8 +20,6 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
syscall "golang.org/x/sys/windows"
|
|
||||||
|
|
||||||
"gioui.org/app/internal/windows"
|
"gioui.org/app/internal/windows"
|
||||||
"gioui.org/op"
|
"gioui.org/op"
|
||||||
"gioui.org/unit"
|
"gioui.org/unit"
|
||||||
@@ -28,7 +30,6 @@ import (
|
|||||||
"gioui.org/io/key"
|
"gioui.org/io/key"
|
||||||
"gioui.org/io/pointer"
|
"gioui.org/io/pointer"
|
||||||
"gioui.org/io/system"
|
"gioui.org/io/system"
|
||||||
"gioui.org/io/transfer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Win32ViewEvent struct {
|
type Win32ViewEvent struct {
|
||||||
@@ -36,32 +37,28 @@ type Win32ViewEvent struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type window struct {
|
type window struct {
|
||||||
hwnd syscall.Handle
|
hwnd syscall.Handle
|
||||||
hdc syscall.Handle
|
hdc syscall.Handle
|
||||||
w *callbacks
|
w *callbacks
|
||||||
pointerBtns pointer.Buttons
|
|
||||||
|
|
||||||
// cursorIn tracks whether the cursor was inside the window according
|
// cursorIn tracks whether the cursor was inside the window according
|
||||||
// to the most recent WM_SETCURSOR.
|
// to the most recent WM_SETCURSOR.
|
||||||
cursorIn bool
|
cursorIn bool
|
||||||
cursor syscall.Handle
|
cursor syscall.Handle
|
||||||
|
|
||||||
// placement saves the previous window position when in full screen mode.
|
|
||||||
placement *windows.WindowPlacement
|
|
||||||
|
|
||||||
animating bool
|
animating bool
|
||||||
focused bool
|
|
||||||
|
|
||||||
borderSize image.Point
|
borderSize image.Point
|
||||||
config Config
|
config Config
|
||||||
loop *eventLoop
|
// frameDims stores the last seen window frame width and height.
|
||||||
|
frameDims image.Point
|
||||||
// invMu avoids the race between destroying the window and Invalidate.
|
loop *eventLoop
|
||||||
invMu sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const _WM_WAKEUP = windows.WM_USER + iota
|
const _WM_WAKEUP = windows.WM_USER + iota
|
||||||
|
|
||||||
|
const copyDataURLType = 0xffffff00
|
||||||
|
|
||||||
type gpuAPI struct {
|
type gpuAPI struct {
|
||||||
priority int
|
priority int
|
||||||
initializer func(w *window) (context, error)
|
initializer func(w *window) (context, error)
|
||||||
@@ -87,6 +84,7 @@ var resources struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func osMain() {
|
func osMain() {
|
||||||
|
processURLEvent(startupURI())
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +110,8 @@ func newWindow(win *callbacks, options []Option) {
|
|||||||
}
|
}
|
||||||
winMap.Store(w.hwnd, w)
|
winMap.Store(w.hwnd, w)
|
||||||
defer winMap.Delete(w.hwnd)
|
defer winMap.Delete(w.hwnd)
|
||||||
w.ProcessEvent(Win32ViewEvent{HWND: uintptr(w.hwnd)})
|
|
||||||
w.Configure(options)
|
w.Configure(options)
|
||||||
|
w.ProcessEvent(Win32ViewEvent{HWND: uintptr(w.hwnd)})
|
||||||
windows.SetForegroundWindow(w.hwnd)
|
windows.SetForegroundWindow(w.hwnd)
|
||||||
windows.SetFocus(w.hwnd)
|
windows.SetFocus(w.hwnd)
|
||||||
// Since the window class for the cursor is null,
|
// Since the window class for the cursor is null,
|
||||||
@@ -138,13 +136,19 @@ func initResources() error {
|
|||||||
}
|
}
|
||||||
resources.cursor = c
|
resources.cursor = c
|
||||||
icon, _ := windows.LoadImage(hInst, iconID, windows.IMAGE_ICON, 0, 0, windows.LR_DEFAULTSIZE|windows.LR_SHARED)
|
icon, _ := windows.LoadImage(hInst, iconID, windows.IMAGE_ICON, 0, 0, windows.LR_DEFAULTSIZE|windows.LR_SHARED)
|
||||||
|
|
||||||
|
appid, err := syscall.UTF16PtrFromString(ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
wcls := windows.WndClassEx{
|
wcls := windows.WndClassEx{
|
||||||
CbSize: uint32(unsafe.Sizeof(windows.WndClassEx{})),
|
CbSize: uint32(unsafe.Sizeof(windows.WndClassEx{})),
|
||||||
Style: windows.CS_HREDRAW | windows.CS_VREDRAW | windows.CS_OWNDC,
|
Style: windows.CS_HREDRAW | windows.CS_VREDRAW | windows.CS_OWNDC,
|
||||||
LpfnWndProc: syscall.NewCallback(windowProc),
|
LpfnWndProc: syscall.NewCallback(windowProc),
|
||||||
HInstance: hInst,
|
HInstance: hInst,
|
||||||
HIcon: icon,
|
HIcon: icon,
|
||||||
LpszClassName: syscall.StringToUTF16Ptr("GioWindow"),
|
LpszClassName: appid,
|
||||||
}
|
}
|
||||||
cls, err := windows.RegisterClassEx(&wcls)
|
cls, err := windows.RegisterClassEx(&wcls)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -180,6 +184,12 @@ func (w *window) init() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := windows.RegisterTouchWindow(hwnd, 0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := windows.EnableMouseInPointer(1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
w.hdc, err = windows.GetDC(hwnd)
|
w.hdc, err = windows.GetDC(hwnd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
windows.DestroyWindow(hwnd)
|
windows.DestroyWindow(hwnd)
|
||||||
@@ -189,21 +199,39 @@ func (w *window) init() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// update() handles changes done by the user, and updates the configuration.
|
// update handles changes done by the user, and updates the configuration.
|
||||||
// It reads the window style and size/position and updates w.config.
|
// It reads the window style and size/position and updates w.config.
|
||||||
// If anything has changed it emits a ConfigEvent to notify the application.
|
// If anything has changed it emits a ConfigEvent to notify the application.
|
||||||
func (w *window) update() {
|
func (w *window) update() {
|
||||||
cr := windows.GetClientRect(w.hwnd)
|
p := windows.GetWindowPlacement(w.hwnd)
|
||||||
w.config.Size = image.Point{
|
if !p.IsMinimized() {
|
||||||
X: int(cr.Right - cr.Left),
|
r := windows.GetWindowRect(w.hwnd)
|
||||||
Y: int(cr.Bottom - cr.Top),
|
cr := windows.GetClientRect(w.hwnd)
|
||||||
|
w.config.Size = image.Point{
|
||||||
|
X: int(cr.Right - cr.Left),
|
||||||
|
Y: int(cr.Bottom - cr.Top),
|
||||||
|
}
|
||||||
|
w.frameDims = image.Point{
|
||||||
|
X: int(r.Right - r.Left),
|
||||||
|
Y: int(r.Bottom - r.Top),
|
||||||
|
}.Sub(w.config.Size)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.borderSize = image.Pt(
|
w.borderSize = image.Pt(
|
||||||
windows.GetSystemMetrics(windows.SM_CXSIZEFRAME),
|
windows.GetSystemMetrics(windows.SM_CXSIZEFRAME),
|
||||||
windows.GetSystemMetrics(windows.SM_CYSIZEFRAME),
|
windows.GetSystemMetrics(windows.SM_CYSIZEFRAME),
|
||||||
)
|
)
|
||||||
|
style := windows.GetWindowLong(w.hwnd, windows.GWL_STYLE)
|
||||||
|
switch {
|
||||||
|
case p.IsMaximized() && style&windows.WS_OVERLAPPEDWINDOW != 0:
|
||||||
|
w.config.Mode = Maximized
|
||||||
|
case p.IsMaximized():
|
||||||
|
w.config.Mode = Fullscreen
|
||||||
|
default:
|
||||||
|
w.config.Mode = Windowed
|
||||||
|
}
|
||||||
w.ProcessEvent(ConfigEvent{Config: w.config})
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
|
w.draw(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr {
|
func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr {
|
||||||
@@ -252,28 +280,42 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case windows.WM_LBUTTONDOWN:
|
case windows.WM_POINTERDOWN, windows.WM_POINTERUP, windows.WM_POINTERUPDATE, windows.WM_POINTERCAPTURECHANGED:
|
||||||
w.pointerButton(pointer.ButtonPrimary, true, lParam, getModifiers())
|
pid := getPointerIDwParam(wParam)
|
||||||
case windows.WM_LBUTTONUP:
|
pi, err := windows.GetPointerInfo(uint32(pid))
|
||||||
w.pointerButton(pointer.ButtonPrimary, false, lParam, getModifiers())
|
if err != nil {
|
||||||
case windows.WM_RBUTTONDOWN:
|
panic(err)
|
||||||
w.pointerButton(pointer.ButtonSecondary, true, lParam, getModifiers())
|
}
|
||||||
case windows.WM_RBUTTONUP:
|
switch msg {
|
||||||
w.pointerButton(pointer.ButtonSecondary, false, lParam, getModifiers())
|
case windows.WM_POINTERDOWN:
|
||||||
case windows.WM_MBUTTONDOWN:
|
windows.SetCapture(w.hwnd)
|
||||||
w.pointerButton(pointer.ButtonTertiary, true, lParam, getModifiers())
|
case windows.WM_POINTERUP:
|
||||||
case windows.WM_MBUTTONUP:
|
windows.ReleaseCapture()
|
||||||
w.pointerButton(pointer.ButtonTertiary, false, lParam, getModifiers())
|
}
|
||||||
|
|
||||||
|
kind := pointer.Move
|
||||||
|
switch pi.ButtonChangeType {
|
||||||
|
case windows.POINTER_CHANGE_FIRSTBUTTON_DOWN, windows.POINTER_CHANGE_SECONDBUTTON_DOWN, windows.POINTER_CHANGE_THIRDBUTTON_DOWN, windows.POINTER_CHANGE_FOURTHBUTTON_DOWN, windows.POINTER_CHANGE_FIFTHBUTTON_DOWN:
|
||||||
|
kind = pointer.Press
|
||||||
|
case windows.POINTER_CHANGE_FIRSTBUTTON_UP, windows.POINTER_CHANGE_SECONDBUTTON_UP, windows.POINTER_CHANGE_THIRDBUTTON_UP, windows.POINTER_CHANGE_FOURTHBUTTON_UP, windows.POINTER_CHANGE_FIFTHBUTTON_UP:
|
||||||
|
kind = pointer.Release
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pi.PointerFlags&windows.POINTER_FLAG_CANCELED != 0) || (msg == windows.WM_POINTERCAPTURECHANGED) {
|
||||||
|
kind = pointer.Cancel
|
||||||
|
}
|
||||||
|
|
||||||
|
w.pointerUpdate(pi, pid, kind, lParam)
|
||||||
case windows.WM_CANCELMODE:
|
case windows.WM_CANCELMODE:
|
||||||
w.ProcessEvent(pointer.Event{
|
w.ProcessEvent(pointer.Event{
|
||||||
Kind: pointer.Cancel,
|
Kind: pointer.Cancel,
|
||||||
})
|
})
|
||||||
case windows.WM_SETFOCUS:
|
case windows.WM_SETFOCUS:
|
||||||
w.focused = true
|
w.config.Focused = true
|
||||||
w.ProcessEvent(key.FocusEvent{Focus: true})
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
case windows.WM_KILLFOCUS:
|
case windows.WM_KILLFOCUS:
|
||||||
w.focused = false
|
w.config.Focused = false
|
||||||
w.ProcessEvent(key.FocusEvent{Focus: false})
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
case windows.WM_NCHITTEST:
|
case windows.WM_NCHITTEST:
|
||||||
if w.config.Decorated {
|
if w.config.Decorated {
|
||||||
// Let the system handle it.
|
// Let the system handle it.
|
||||||
@@ -283,33 +325,22 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
np := windows.Point{X: int32(x), Y: int32(y)}
|
np := windows.Point{X: int32(x), Y: int32(y)}
|
||||||
windows.ScreenToClient(w.hwnd, &np)
|
windows.ScreenToClient(w.hwnd, &np)
|
||||||
return w.hitTest(int(np.X), int(np.Y))
|
return w.hitTest(int(np.X), int(np.Y))
|
||||||
case windows.WM_MOUSEMOVE:
|
case windows.WM_POINTERWHEEL:
|
||||||
x, y := coordsFromlParam(lParam)
|
|
||||||
p := f32.Point{X: float32(x), Y: float32(y)}
|
|
||||||
w.ProcessEvent(pointer.Event{
|
|
||||||
Kind: pointer.Move,
|
|
||||||
Source: pointer.Mouse,
|
|
||||||
Position: p,
|
|
||||||
Buttons: w.pointerBtns,
|
|
||||||
Time: windows.GetMessageTime(),
|
|
||||||
Modifiers: getModifiers(),
|
|
||||||
})
|
|
||||||
case windows.WM_MOUSEWHEEL:
|
|
||||||
w.scrollEvent(wParam, lParam, false, getModifiers())
|
w.scrollEvent(wParam, lParam, false, getModifiers())
|
||||||
case windows.WM_MOUSEHWHEEL:
|
case windows.WM_POINTERHWHEEL:
|
||||||
w.scrollEvent(wParam, lParam, true, getModifiers())
|
w.scrollEvent(wParam, lParam, true, getModifiers())
|
||||||
case windows.WM_DESTROY:
|
case windows.WM_DESTROY:
|
||||||
w.ProcessEvent(Win32ViewEvent{})
|
w.ProcessEvent(Win32ViewEvent{})
|
||||||
w.ProcessEvent(DestroyEvent{})
|
w.ProcessEvent(DestroyEvent{})
|
||||||
|
w.w = nil
|
||||||
if w.hdc != 0 {
|
if w.hdc != 0 {
|
||||||
windows.ReleaseDC(w.hdc)
|
windows.ReleaseDC(w.hdc)
|
||||||
w.hdc = 0
|
w.hdc = 0
|
||||||
}
|
}
|
||||||
w.invMu.Lock()
|
|
||||||
// The system destroys the HWND for us.
|
// The system destroys the HWND for us.
|
||||||
w.hwnd = 0
|
w.hwnd = 0
|
||||||
w.invMu.Unlock()
|
|
||||||
windows.PostQuitMessage(0)
|
windows.PostQuitMessage(0)
|
||||||
|
return 0
|
||||||
case windows.WM_NCCALCSIZE:
|
case windows.WM_NCCALCSIZE:
|
||||||
if w.config.Decorated {
|
if w.config.Decorated {
|
||||||
// Let Windows handle decorations.
|
// Let Windows handle decorations.
|
||||||
@@ -334,37 +365,30 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
return 0
|
return 0
|
||||||
case windows.WM_PAINT:
|
case windows.WM_PAINT:
|
||||||
w.draw(true)
|
w.draw(true)
|
||||||
case windows.WM_SIZE:
|
case windows.WM_STYLECHANGED:
|
||||||
w.update()
|
w.update()
|
||||||
switch wParam {
|
case windows.WM_WINDOWPOSCHANGED:
|
||||||
case windows.SIZE_MINIMIZED:
|
w.update()
|
||||||
w.config.Mode = Minimized
|
return 0
|
||||||
case windows.SIZE_MAXIMIZED:
|
|
||||||
w.config.Mode = Maximized
|
|
||||||
case windows.SIZE_RESTORED:
|
|
||||||
if w.config.Mode != Fullscreen {
|
|
||||||
w.config.Mode = Windowed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case windows.WM_GETMINMAXINFO:
|
case windows.WM_GETMINMAXINFO:
|
||||||
mm := (*windows.MinMaxInfo)(unsafe.Pointer(lParam))
|
mm := (*windows.MinMaxInfo)(unsafe.Pointer(lParam))
|
||||||
var bw, bh int32
|
|
||||||
|
var frameDims image.Point
|
||||||
if w.config.Decorated {
|
if w.config.Decorated {
|
||||||
r := windows.GetWindowRect(w.hwnd)
|
frameDims = w.frameDims
|
||||||
cr := windows.GetClientRect(w.hwnd)
|
|
||||||
bw = r.Right - r.Left - (cr.Right - cr.Left)
|
|
||||||
bh = r.Bottom - r.Top - (cr.Bottom - cr.Top)
|
|
||||||
}
|
}
|
||||||
if p := w.config.MinSize; p.X > 0 || p.Y > 0 {
|
if p := w.config.MinSize; p.X > 0 || p.Y > 0 {
|
||||||
|
p = p.Add(frameDims)
|
||||||
mm.PtMinTrackSize = windows.Point{
|
mm.PtMinTrackSize = windows.Point{
|
||||||
X: int32(p.X) + bw,
|
X: int32(p.X),
|
||||||
Y: int32(p.Y) + bh,
|
Y: int32(p.Y),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if p := w.config.MaxSize; p.X > 0 || p.Y > 0 {
|
if p := w.config.MaxSize; p.X > 0 || p.Y > 0 {
|
||||||
|
p = p.Add(frameDims)
|
||||||
mm.PtMaxTrackSize = windows.Point{
|
mm.PtMaxTrackSize = windows.Point{
|
||||||
X: int32(p.X) + bw,
|
X: int32(p.X),
|
||||||
Y: int32(p.Y) + bh,
|
Y: int32(p.Y),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
@@ -388,6 +412,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
icaret := image.Pt(int(caret.X+.5), int(caret.Y+.5))
|
icaret := image.Pt(int(caret.X+.5), int(caret.Y+.5))
|
||||||
windows.ImmSetCompositionWindow(imc, icaret.X, icaret.Y)
|
windows.ImmSetCompositionWindow(imc, icaret.X, icaret.Y)
|
||||||
windows.ImmSetCandidateWindow(imc, icaret.X, icaret.Y)
|
windows.ImmSetCandidateWindow(imc, icaret.X, icaret.Y)
|
||||||
|
return windows.TRUE
|
||||||
case windows.WM_IME_COMPOSITION:
|
case windows.WM_IME_COMPOSITION:
|
||||||
imc := windows.ImmGetContext(w.hwnd)
|
imc := windows.ImmGetContext(w.hwnd)
|
||||||
if imc == 0 {
|
if imc == 0 {
|
||||||
@@ -431,6 +456,20 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
case windows.WM_IME_ENDCOMPOSITION:
|
case windows.WM_IME_ENDCOMPOSITION:
|
||||||
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
w.w.SetComposingRegion(key.Range{Start: -1, End: -1})
|
||||||
return windows.TRUE
|
return windows.TRUE
|
||||||
|
case windows.WM_COPYDATA:
|
||||||
|
data := (*windows.CopyDataStruct)(unsafe.Pointer(lParam))
|
||||||
|
switch data.DwData {
|
||||||
|
case copyDataURLType:
|
||||||
|
if schemesURI == "" {
|
||||||
|
return windows.TRUE
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := syscall.UTF16PtrToString((*uint16)(unsafe.Pointer(data.LpData)))
|
||||||
|
if processURLEvent(uri) {
|
||||||
|
w.Perform(system.ActionRaise)
|
||||||
|
}
|
||||||
|
return windows.TRUE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return windows.DefWindowProc(hwnd, msg, wParam, lParam)
|
return windows.DefWindowProc(hwnd, msg, wParam, lParam)
|
||||||
@@ -456,37 +495,32 @@ func getModifiers() key.Modifiers {
|
|||||||
// hitTest returns the non-client area hit by the point, needed to
|
// hitTest returns the non-client area hit by the point, needed to
|
||||||
// process WM_NCHITTEST.
|
// process WM_NCHITTEST.
|
||||||
func (w *window) hitTest(x, y int) uintptr {
|
func (w *window) hitTest(x, y int) uintptr {
|
||||||
if w.config.Mode == Fullscreen {
|
if w.config.Mode == Windowed {
|
||||||
return windows.HTCLIENT
|
// Check for resize handle before system actions; otherwise it can be impossible to
|
||||||
}
|
// resize a custom-decorations window when the system move area is flush with the
|
||||||
if w.config.Mode != Windowed {
|
// edge of the window.
|
||||||
// Only windowed mode should allow resizing.
|
top := y <= w.borderSize.Y
|
||||||
return windows.HTCLIENT
|
bottom := y >= w.config.Size.Y-w.borderSize.Y
|
||||||
}
|
left := x <= w.borderSize.X
|
||||||
// Check for resize handle before system actions; otherwise it can be impossible to
|
right := x >= w.config.Size.X-w.borderSize.X
|
||||||
// resize a custom-decorations window when the system move area is flush with the
|
switch {
|
||||||
// edge of the window.
|
case top && left:
|
||||||
top := y <= w.borderSize.Y
|
return windows.HTTOPLEFT
|
||||||
bottom := y >= w.config.Size.Y-w.borderSize.Y
|
case top && right:
|
||||||
left := x <= w.borderSize.X
|
return windows.HTTOPRIGHT
|
||||||
right := x >= w.config.Size.X-w.borderSize.X
|
case bottom && left:
|
||||||
switch {
|
return windows.HTBOTTOMLEFT
|
||||||
case top && left:
|
case bottom && right:
|
||||||
return windows.HTTOPLEFT
|
return windows.HTBOTTOMRIGHT
|
||||||
case top && right:
|
case top:
|
||||||
return windows.HTTOPRIGHT
|
return windows.HTTOP
|
||||||
case bottom && left:
|
case bottom:
|
||||||
return windows.HTBOTTOMLEFT
|
return windows.HTBOTTOM
|
||||||
case bottom && right:
|
case left:
|
||||||
return windows.HTBOTTOMRIGHT
|
return windows.HTLEFT
|
||||||
case top:
|
case right:
|
||||||
return windows.HTTOP
|
return windows.HTRIGHT
|
||||||
case bottom:
|
}
|
||||||
return windows.HTBOTTOM
|
|
||||||
case left:
|
|
||||||
return windows.HTLEFT
|
|
||||||
case right:
|
|
||||||
return windows.HTRIGHT
|
|
||||||
}
|
}
|
||||||
p := f32.Pt(float32(x), float32(y))
|
p := f32.Pt(float32(x), float32(y))
|
||||||
if a, ok := w.w.ActionAt(p); ok && a == system.ActionMove {
|
if a, ok := w.w.ActionAt(p); ok && a == system.ActionMove {
|
||||||
@@ -495,34 +529,28 @@ func (w *window) hitTest(x, y int) uintptr {
|
|||||||
return windows.HTCLIENT
|
return windows.HTCLIENT
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr, kmods key.Modifiers) {
|
func (w *window) pointerUpdate(pi windows.PointerInfo, pid pointer.ID, kind pointer.Kind, lParam uintptr) {
|
||||||
if !w.focused {
|
if !w.config.Focused {
|
||||||
windows.SetFocus(w.hwnd)
|
windows.SetFocus(w.hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var kind pointer.Kind
|
src := pointer.Touch
|
||||||
if press {
|
if pi.PointerType == windows.PT_MOUSE {
|
||||||
kind = pointer.Press
|
src = pointer.Mouse
|
||||||
if w.pointerBtns == 0 {
|
|
||||||
windows.SetCapture(w.hwnd)
|
|
||||||
}
|
|
||||||
w.pointerBtns |= btn
|
|
||||||
} else {
|
|
||||||
kind = pointer.Release
|
|
||||||
w.pointerBtns &^= btn
|
|
||||||
if w.pointerBtns == 0 {
|
|
||||||
windows.ReleaseCapture()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x, y := coordsFromlParam(lParam)
|
x, y := coordsFromlParam(lParam)
|
||||||
p := f32.Point{X: float32(x), Y: float32(y)}
|
np := windows.Point{X: int32(x), Y: int32(y)}
|
||||||
|
windows.ScreenToClient(w.hwnd, &np)
|
||||||
|
p := f32.Point{X: float32(np.X), Y: float32(np.Y)}
|
||||||
w.ProcessEvent(pointer.Event{
|
w.ProcessEvent(pointer.Event{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
Source: pointer.Mouse,
|
Source: src,
|
||||||
Position: p,
|
Position: p,
|
||||||
Buttons: w.pointerBtns,
|
PointerID: pid,
|
||||||
|
Buttons: getPointerButtons(pi),
|
||||||
Time: windows.GetMessageTime(),
|
Time: windows.GetMessageTime(),
|
||||||
Modifiers: kmods,
|
Modifiers: getModifiers(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,6 +561,12 @@ func coordsFromlParam(lParam uintptr) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool, kmods key.Modifiers) {
|
func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool, kmods key.Modifiers) {
|
||||||
|
pid := getPointerIDwParam(wParam)
|
||||||
|
pi, err := windows.GetPointerInfo(uint32(pid))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
x, y := coordsFromlParam(lParam)
|
x, y := coordsFromlParam(lParam)
|
||||||
// The WM_MOUSEWHEEL coordinates are in screen coordinates, in contrast
|
// The WM_MOUSEWHEEL coordinates are in screen coordinates, in contrast
|
||||||
// to other mouse events.
|
// to other mouse events.
|
||||||
@@ -555,7 +589,7 @@ func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool, kmods key.
|
|||||||
Kind: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Position: p,
|
Position: p,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: getPointerButtons(pi),
|
||||||
Scroll: sp,
|
Scroll: sp,
|
||||||
Modifiers: kmods,
|
Modifiers: kmods,
|
||||||
Time: windows.GetMessageTime(),
|
Time: windows.GetMessageTime(),
|
||||||
@@ -568,7 +602,8 @@ func (w *window) runLoop() {
|
|||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
anim := w.animating
|
anim := w.animating
|
||||||
if anim && !windows.PeekMessage(msg, 0, 0, 0, windows.PM_NOREMOVE) {
|
p := windows.GetWindowPlacement(w.hwnd)
|
||||||
|
if anim && !p.IsMinimized() && !windows.PeekMessage(msg, 0, 0, 0, windows.PM_NOREMOVE) {
|
||||||
w.draw(false)
|
w.draw(false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -621,13 +656,6 @@ func (w *window) Frame(frame *op.Ops) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) wakeup() {
|
func (w *window) wakeup() {
|
||||||
w.invMu.Lock()
|
|
||||||
defer w.invMu.Unlock()
|
|
||||||
if w.hwnd == 0 {
|
|
||||||
w.loop.Wakeup()
|
|
||||||
w.loop.FlushEvents()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := windows.PostMessage(w.hwnd, _WM_WAKEUP, 0, 0); err != nil {
|
if err := windows.PostMessage(w.hwnd, _WM_WAKEUP, 0, 0); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -671,7 +699,13 @@ func (w *window) ReadClipboard() {
|
|||||||
w.readClipboard()
|
w.readClipboard()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) readClipboard() error {
|
func (w *window) readClipboard() (cerr error) {
|
||||||
|
defer func() {
|
||||||
|
if cerr != nil {
|
||||||
|
w.processDataEvent("")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := windows.OpenClipboard(w.hwnd); err != nil {
|
if err := windows.OpenClipboard(w.hwnd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -686,28 +720,46 @@ func (w *window) readClipboard() error {
|
|||||||
}
|
}
|
||||||
defer windows.GlobalUnlock(mem)
|
defer windows.GlobalUnlock(mem)
|
||||||
content := gowindows.UTF16PtrToString((*uint16)(unsafe.Pointer(ptr)))
|
content := gowindows.UTF16PtrToString((*uint16)(unsafe.Pointer(ptr)))
|
||||||
|
w.processDataEvent(content)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *window) processDataEvent(content string) {
|
||||||
w.ProcessEvent(transfer.DataEvent{
|
w.ProcessEvent(transfer.DataEvent{
|
||||||
Type: "application/text",
|
Type: "application/text",
|
||||||
Open: func() io.ReadCloser {
|
Open: func() io.ReadCloser {
|
||||||
return io.NopCloser(strings.NewReader(content))
|
return io.NopCloser(strings.NewReader(content))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Configure(options []Option) {
|
func (w *window) Configure(options []Option) {
|
||||||
dpi := windows.GetSystemDPI()
|
dpi := windows.GetSystemDPI()
|
||||||
metric := configForDPI(dpi)
|
metric := configForDPI(dpi)
|
||||||
w.config.apply(metric, options)
|
cnf := w.config
|
||||||
windows.SetWindowText(w.hwnd, w.config.Title)
|
cnf.apply(metric, options)
|
||||||
|
w.config.Title = cnf.Title
|
||||||
|
w.config.Decorated = cnf.Decorated
|
||||||
|
w.config.MinSize = cnf.MinSize
|
||||||
|
w.config.MaxSize = cnf.MaxSize
|
||||||
|
windows.SetWindowText(w.hwnd, cnf.Title)
|
||||||
|
|
||||||
style := windows.GetWindowLong(w.hwnd, windows.GWL_STYLE)
|
style := windows.GetWindowLong(w.hwnd, windows.GWL_STYLE)
|
||||||
var showMode int32
|
var showMode int32
|
||||||
var x, y, width, height int32
|
var x, y, width, height int32
|
||||||
swpStyle := uintptr(windows.SWP_NOZORDER | windows.SWP_FRAMECHANGED)
|
swpStyle := uintptr(windows.SWP_FRAMECHANGED)
|
||||||
|
if cnf.TopMost == w.config.TopMost {
|
||||||
|
// Don't change the z-order if TopMost didn't change.
|
||||||
|
swpStyle |= windows.SWP_NOZORDER
|
||||||
|
}
|
||||||
|
hwndAfter := windows.HWND_NOTOPMOST
|
||||||
|
if cnf.TopMost {
|
||||||
|
hwndAfter = windows.HWND_TOPMOST
|
||||||
|
}
|
||||||
|
w.config.TopMost = cnf.TopMost
|
||||||
winStyle := uintptr(windows.WS_OVERLAPPEDWINDOW)
|
winStyle := uintptr(windows.WS_OVERLAPPEDWINDOW)
|
||||||
style &^= winStyle
|
style &^= winStyle
|
||||||
switch w.config.Mode {
|
switch cnf.Mode {
|
||||||
case Minimized:
|
case Minimized:
|
||||||
style |= winStyle
|
style |= winStyle
|
||||||
swpStyle |= windows.SWP_NOMOVE | windows.SWP_NOSIZE
|
swpStyle |= windows.SWP_NOMOVE | windows.SWP_NOSIZE
|
||||||
@@ -722,13 +774,13 @@ func (w *window) Configure(options []Option) {
|
|||||||
style |= winStyle
|
style |= winStyle
|
||||||
showMode = windows.SW_SHOWNORMAL
|
showMode = windows.SW_SHOWNORMAL
|
||||||
// Get target for client area size.
|
// Get target for client area size.
|
||||||
width = int32(w.config.Size.X)
|
width = int32(cnf.Size.X)
|
||||||
height = int32(w.config.Size.Y)
|
height = int32(cnf.Size.Y)
|
||||||
// Get the current window size and position.
|
// Get the current window size and position.
|
||||||
wr := windows.GetWindowRect(w.hwnd)
|
wr := windows.GetWindowRect(w.hwnd)
|
||||||
x = wr.Left
|
x = wr.Left
|
||||||
y = wr.Top
|
y = wr.Top
|
||||||
if w.config.Decorated {
|
if cnf.Decorated {
|
||||||
// Compute client size and position. Note that the client size is
|
// Compute client size and position. Note that the client size is
|
||||||
// equal to the window size when we are in control of decorations.
|
// equal to the window size when we are in control of decorations.
|
||||||
r := windows.Rect{
|
r := windows.Rect{
|
||||||
@@ -738,25 +790,27 @@ func (w *window) Configure(options []Option) {
|
|||||||
windows.AdjustWindowRectEx(&r, uint32(style), 0, dwExStyle)
|
windows.AdjustWindowRectEx(&r, uint32(style), 0, dwExStyle)
|
||||||
width = r.Right - r.Left
|
width = r.Right - r.Left
|
||||||
height = r.Bottom - r.Top
|
height = r.Bottom - r.Top
|
||||||
}
|
} else {
|
||||||
if !w.config.Decorated {
|
|
||||||
// Enable drop shadows when we draw decorations.
|
// Enable drop shadows when we draw decorations.
|
||||||
windows.DwmExtendFrameIntoClientArea(w.hwnd, windows.Margins{-1, -1, -1, -1})
|
windows.DwmExtendFrameIntoClientArea(w.hwnd, windows.Margins{-1, -1, -1, -1})
|
||||||
}
|
}
|
||||||
|
|
||||||
case Fullscreen:
|
case Fullscreen:
|
||||||
swpStyle |= windows.SWP_NOMOVE | windows.SWP_NOSIZE
|
swpStyle |= windows.SWP_NOMOVE | windows.SWP_NOSIZE
|
||||||
mi := windows.GetMonitorInfo(w.hwnd)
|
|
||||||
x, y = mi.Monitor.Left, mi.Monitor.Top
|
|
||||||
width = mi.Monitor.Right - mi.Monitor.Left
|
|
||||||
height = mi.Monitor.Bottom - mi.Monitor.Top
|
|
||||||
showMode = windows.SW_SHOWMAXIMIZED
|
showMode = windows.SW_SHOWMAXIMIZED
|
||||||
}
|
}
|
||||||
windows.SetWindowLong(w.hwnd, windows.GWL_STYLE, style)
|
|
||||||
windows.SetWindowPos(w.hwnd, 0, x, y, width, height, swpStyle)
|
|
||||||
windows.ShowWindow(w.hwnd, showMode)
|
|
||||||
|
|
||||||
w.update()
|
// Disable window resizing if MinSize and MaxSize are equal.
|
||||||
|
if cnf.MaxSize != (image.Point{}) && cnf.MinSize == cnf.MaxSize {
|
||||||
|
style &^= windows.WS_MAXIMIZEBOX
|
||||||
|
style &^= windows.WS_THICKFRAME
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: these invocation all trigger the windows callback method which may process a pending system.ActionCenter
|
||||||
|
// action, so SetWindowPos should come first so as to not "overwrite" system.ActionCenter.
|
||||||
|
windows.SetWindowPos(w.hwnd, hwndAfter, x, y, width, height, swpStyle)
|
||||||
|
windows.SetWindowLong(w.hwnd, windows.GWL_STYLE, style)
|
||||||
|
windows.ShowWindow(w.hwnd, showMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) WriteClipboard(mime string, s []byte) {
|
func (w *window) WriteClipboard(mime string, s []byte) {
|
||||||
@@ -875,19 +929,15 @@ func (w *window) Perform(acts system.Action) {
|
|||||||
y := (mi.Bottom - mi.Top - dy) / 2
|
y := (mi.Bottom - mi.Top - dy) / 2
|
||||||
windows.SetWindowPos(w.hwnd, 0, x, y, dx, dy, windows.SWP_NOZORDER|windows.SWP_FRAMECHANGED)
|
windows.SetWindowPos(w.hwnd, 0, x, y, dx, dy, windows.SWP_NOZORDER|windows.SWP_FRAMECHANGED)
|
||||||
case system.ActionRaise:
|
case system.ActionRaise:
|
||||||
w.raise()
|
windows.SetForegroundWindow(w.hwnd)
|
||||||
|
windows.SetWindowPos(w.hwnd, windows.HWND_TOP, 0, 0, 0, 0,
|
||||||
|
windows.SWP_NOMOVE|windows.SWP_NOSIZE|windows.SWP_SHOWWINDOW)
|
||||||
case system.ActionClose:
|
case system.ActionClose:
|
||||||
windows.PostMessage(w.hwnd, windows.WM_CLOSE, 0, 0)
|
windows.PostMessage(w.hwnd, windows.WM_CLOSE, 0, 0)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) raise() {
|
|
||||||
windows.SetForegroundWindow(w.hwnd)
|
|
||||||
windows.SetWindowPos(w.hwnd, windows.HWND_TOPMOST, 0, 0, 0, 0,
|
|
||||||
windows.SWP_NOMOVE|windows.SWP_NOSIZE|windows.SWP_SHOWWINDOW)
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertKeyCode(code uintptr) (key.Name, bool) {
|
func convertKeyCode(code uintptr) (key.Name, bool) {
|
||||||
if '0' <= code && code <= '9' || 'A' <= code && code <= 'Z' {
|
if '0' <= code && code <= '9' || 'A' <= code && code <= 'Z' {
|
||||||
return key.Name(rune(code)), true
|
return key.Name(rune(code)), true
|
||||||
@@ -994,3 +1044,260 @@ func configForDPI(dpi int) unit.Metric {
|
|||||||
|
|
||||||
func (Win32ViewEvent) implementsViewEvent() {}
|
func (Win32ViewEvent) implementsViewEvent() {}
|
||||||
func (Win32ViewEvent) ImplementsEvent() {}
|
func (Win32ViewEvent) ImplementsEvent() {}
|
||||||
|
func (w Win32ViewEvent) Valid() bool {
|
||||||
|
return w != (Win32ViewEvent{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// LOWORD (minwindef.h)
|
||||||
|
func loWord(val uint32) uint16 {
|
||||||
|
return uint16(val & 0xFFFF)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET_POINTERID_WPARAM (winuser.h)
|
||||||
|
func getPointerIDwParam(wParam uintptr) pointer.ID {
|
||||||
|
return pointer.ID(loWord(uint32(wParam)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPointerButtons(pi windows.PointerInfo) pointer.Buttons {
|
||||||
|
var btns pointer.Buttons
|
||||||
|
|
||||||
|
if pi.PointerFlags&windows.POINTER_FLAG_FIRSTBUTTON != 0 {
|
||||||
|
btns |= pointer.ButtonPrimary
|
||||||
|
} else {
|
||||||
|
btns &^= pointer.ButtonPrimary
|
||||||
|
}
|
||||||
|
if pi.PointerFlags&windows.POINTER_FLAG_SECONDBUTTON != 0 {
|
||||||
|
btns |= pointer.ButtonSecondary
|
||||||
|
} else {
|
||||||
|
btns &^= pointer.ButtonSecondary
|
||||||
|
}
|
||||||
|
if pi.PointerFlags&windows.POINTER_FLAG_THIRDBUTTON != 0 {
|
||||||
|
btns |= pointer.ButtonTertiary
|
||||||
|
} else {
|
||||||
|
btns &^= pointer.ButtonTertiary
|
||||||
|
}
|
||||||
|
if pi.PointerFlags&windows.POINTER_FLAG_FOURTHBUTTON != 0 {
|
||||||
|
btns |= pointer.ButtonQuaternary
|
||||||
|
} else {
|
||||||
|
btns &^= pointer.ButtonQuaternary
|
||||||
|
}
|
||||||
|
if pi.PointerFlags&windows.POINTER_FLAG_FIFTHBUTTON != 0 {
|
||||||
|
btns |= pointer.ButtonQuinary
|
||||||
|
} else {
|
||||||
|
btns &^= pointer.ButtonQuinary
|
||||||
|
}
|
||||||
|
|
||||||
|
return btns
|
||||||
|
}
|
||||||
|
|
||||||
|
// schemesURI is a list of schemes, comma separated, that must be
|
||||||
|
// defined using -X compiler ldflag, that used in gogio.
|
||||||
|
var schemesURI string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if schemesURI == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSchemes := strings.Split(schemesURI, ",")
|
||||||
|
oldSchemes := registeredSchemes(ID)
|
||||||
|
|
||||||
|
for _, s := range currentSchemes {
|
||||||
|
for i, o := range oldSchemes {
|
||||||
|
if s == o {
|
||||||
|
oldSchemes = append(oldSchemes[:i], oldSchemes[i+1:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(oldSchemes) > 0 {
|
||||||
|
go unregisterSchemes(ID, oldSchemes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(currentSchemes) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// On Windows, launching the app using a URI will start a new instance of the app,
|
||||||
|
// a new window. That behavior, by default, doesn't align with iOS/Android/macOS, where
|
||||||
|
// the deeplink sends the event to the running app (if any). We are emulating it.
|
||||||
|
if hwnd, _ := windows.FindWindow(ID); hwnd != 0 {
|
||||||
|
if u := startupURI(); u != "" {
|
||||||
|
broadcastURI(hwnd, u)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
go registerSchemes(ID, currentSchemes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func startupURI() string {
|
||||||
|
if len(os.Args) == 3 && os.Args[1] == "-gio_launch_url" {
|
||||||
|
return os.Args[2]
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func processURLEvent(rawurl string) bool {
|
||||||
|
if rawurl == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
evt, err := newURLEvent(rawurl)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, scheme := range strings.Split(schemesURI, ",") {
|
||||||
|
if strings.EqualFold(scheme, evt.URL.Scheme) {
|
||||||
|
processGlobalEvent(evt)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func broadcastURI(hwnd syscall.Handle, uri string) {
|
||||||
|
data, err := syscall.UTF16FromString(uri)
|
||||||
|
if err != nil {
|
||||||
|
return // Only happens if uri contains NULL character.
|
||||||
|
}
|
||||||
|
|
||||||
|
pinner := new(runtime.Pinner)
|
||||||
|
defer pinner.Unpin()
|
||||||
|
pinner.Pin(unsafe.Pointer(&data[0]))
|
||||||
|
|
||||||
|
msg := &windows.CopyDataStruct{
|
||||||
|
DwData: copyDataURLType,
|
||||||
|
CbData: uint32(len(data) * int(unsafe.Sizeof(data[0]))),
|
||||||
|
LpData: uintptr(unsafe.Pointer(unsafe.SliceData(data))),
|
||||||
|
}
|
||||||
|
pinner.Pin(unsafe.Pointer(msg))
|
||||||
|
|
||||||
|
// SendMessage blocks until the message is processed.
|
||||||
|
windows.SendMessage(hwnd, windows.WM_COPYDATA, 0, uintptr(unsafe.Pointer(msg)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func registeredSchemes(appid string) []string {
|
||||||
|
meta, err := registry.OpenKey(registry.CURRENT_USER, `Software\\`+appid, registry.ALL_ACCESS)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer meta.Close()
|
||||||
|
|
||||||
|
schemes, _, _ := meta.GetStringsValue("URISchemes")
|
||||||
|
return schemes
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerSchemes(appid string, schemes []string) error {
|
||||||
|
reg := func(scheme string) error {
|
||||||
|
key, existent, err := registry.CreateKey(registry.CURRENT_USER, `Software\\Classes\\`+scheme, registry.ALL_ACCESS)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer key.Close()
|
||||||
|
|
||||||
|
if existent {
|
||||||
|
// Check if the existent key belongs to the current application
|
||||||
|
id, _, err := key.GetStringValue("appid")
|
||||||
|
if err != nil || id != appid {
|
||||||
|
return fmt.Errorf("scheme %s already registered by another application", scheme)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = key.SetStringValue("", "URL:"+scheme+" Protocol"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = key.SetStringValue("URL Protocol", ""); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = key.SetStringValue("appid", appid); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
icon, _, err := registry.CreateKey(key, `DefaultIcon`, registry.ALL_ACCESS)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer icon.Close()
|
||||||
|
|
||||||
|
if err = icon.SetStringValue("", `"`+path+`",1`); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd, _, err := registry.CreateKey(key, `shell\\open\\command`, registry.ALL_ACCESS)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer cmd.Close()
|
||||||
|
|
||||||
|
if err = cmd.SetStringValue("", `"`+path+`" -gio_launch_url "%1"`); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, scheme := range schemes {
|
||||||
|
if scheme == "" {
|
||||||
|
continue // just in case
|
||||||
|
}
|
||||||
|
if err := reg(scheme); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
meta, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\\`+appid, registry.ALL_ACCESS)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer meta.Close()
|
||||||
|
|
||||||
|
if err = meta.SetStringsValue("URISchemes", schemes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func unregisterSchemes(appid string, schemes []string) {
|
||||||
|
classes, err := registry.OpenKey(registry.CURRENT_USER, `Software\\Classes`, registry.ALL_ACCESS)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer classes.Close()
|
||||||
|
|
||||||
|
for _, scheme := range schemes {
|
||||||
|
if scheme == "" {
|
||||||
|
continue // just in case
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := registry.OpenKey(classes, scheme, registry.ALL_ACCESS)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
id, _, err := key.GetStringValue("appid")
|
||||||
|
if err == nil && id != appid {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, k := range []string{`DefaultIcon`, `shell\\open\\command`, `shell\\open`, `shell`} {
|
||||||
|
registry.DeleteKey(key, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := key.Close(); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
registry.DeleteKey(classes, scheme)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+16
-19
@@ -26,6 +26,7 @@ package app
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -113,9 +114,6 @@ type x11Window struct {
|
|||||||
wakeups chan struct{}
|
wakeups chan struct{}
|
||||||
handler x11EventHandler
|
handler x11EventHandler
|
||||||
buf [100]byte
|
buf [100]byte
|
||||||
|
|
||||||
// invMy avoids the race between destroy and Invalidate.
|
|
||||||
invMu sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -389,6 +387,7 @@ func (w *x11Window) ProcessEvent(e event.Event) {
|
|||||||
func (w *x11Window) shutdown(err error) {
|
func (w *x11Window) shutdown(err error) {
|
||||||
w.ProcessEvent(X11ViewEvent{})
|
w.ProcessEvent(X11ViewEvent{})
|
||||||
w.ProcessEvent(DestroyEvent{Err: err})
|
w.ProcessEvent(DestroyEvent{Err: err})
|
||||||
|
w.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *x11Window) Event() event.Event {
|
func (w *x11Window) Event() event.Event {
|
||||||
@@ -398,9 +397,6 @@ func (w *x11Window) Event() event.Event {
|
|||||||
w.dispatch()
|
w.dispatch()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, destroy := evt.(DestroyEvent); destroy {
|
|
||||||
w.destroy()
|
|
||||||
}
|
|
||||||
return evt
|
return evt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,11 +414,6 @@ func (w *x11Window) Invalidate() {
|
|||||||
case w.wakeups <- struct{}{}:
|
case w.wakeups <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
w.invMu.Lock()
|
|
||||||
defer w.invMu.Unlock()
|
|
||||||
if w.x == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, err := syscall.Write(w.notify.write, x11OneByte); err != nil && err != syscall.EAGAIN {
|
if _, err := syscall.Write(w.notify.write, x11OneByte); err != nil && err != syscall.EAGAIN {
|
||||||
panic(fmt.Errorf("failed to write to pipe: %v", err))
|
panic(fmt.Errorf("failed to write to pipe: %v", err))
|
||||||
}
|
}
|
||||||
@@ -464,7 +455,12 @@ func (w *x11Window) dispatch() {
|
|||||||
// Check for pending draw events before checking animation or blocking.
|
// Check for pending draw events before checking animation or blocking.
|
||||||
// This fixes an issue on Xephyr where on startup XPending() > 0 but
|
// This fixes an issue on Xephyr where on startup XPending() > 0 but
|
||||||
// poll will still block. This also prevents no-op calls to poll.
|
// poll will still block. This also prevents no-op calls to poll.
|
||||||
if syn = w.handler.handleEvents(); !syn {
|
syn = w.handler.handleEvents()
|
||||||
|
if w.x == nil {
|
||||||
|
// handleEvents received a close request and destroyed the window.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !syn {
|
||||||
anim = w.animating
|
anim = w.animating
|
||||||
if !anim {
|
if !anim {
|
||||||
// Clear poll events.
|
// Clear poll events.
|
||||||
@@ -476,6 +472,9 @@ func (w *x11Window) dispatch() {
|
|||||||
switch {
|
switch {
|
||||||
case *xEvents&syscall.POLLIN != 0:
|
case *xEvents&syscall.POLLIN != 0:
|
||||||
syn = w.handler.handleEvents()
|
syn = w.handler.handleEvents()
|
||||||
|
if w.x == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
case *xEvents&(syscall.POLLERR|syscall.POLLHUP) != 0:
|
case *xEvents&(syscall.POLLERR|syscall.POLLHUP) != 0:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -503,8 +502,6 @@ func (w *x11Window) dispatch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *x11Window) destroy() {
|
func (w *x11Window) destroy() {
|
||||||
w.invMu.Lock()
|
|
||||||
defer w.invMu.Unlock()
|
|
||||||
if w.notify.write != 0 {
|
if w.notify.write != 0 {
|
||||||
syscall.Close(w.notify.write)
|
syscall.Close(w.notify.write)
|
||||||
w.notify.write = 0
|
w.notify.write = 0
|
||||||
@@ -657,9 +654,11 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
// redraw only on the last expose event
|
// redraw only on the last expose event
|
||||||
redraw = (*C.XExposeEvent)(unsafe.Pointer(xev)).count == 0
|
redraw = (*C.XExposeEvent)(unsafe.Pointer(xev)).count == 0
|
||||||
case C.FocusIn:
|
case C.FocusIn:
|
||||||
w.ProcessEvent(key.FocusEvent{Focus: true})
|
w.config.Focused = true
|
||||||
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
case C.FocusOut:
|
case C.FocusOut:
|
||||||
w.ProcessEvent(key.FocusEvent{Focus: false})
|
w.config.Focused = false
|
||||||
|
w.ProcessEvent(ConfigEvent{Config: w.config})
|
||||||
case C.ConfigureNotify: // window configuration change
|
case C.ConfigureNotify: // window configuration change
|
||||||
cevt := (*C.XConfigureEvent)(unsafe.Pointer(xev))
|
cevt := (*C.XConfigureEvent)(unsafe.Pointer(xev))
|
||||||
if sz := image.Pt(int(cevt.width), int(cevt.height)); sz != w.config.Size {
|
if sz := image.Pt(int(cevt.width), int(cevt.height)); sz != w.config.Size {
|
||||||
@@ -753,9 +752,7 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
return redraw
|
return redraw
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var x11Threads sync.Once
|
||||||
x11Threads sync.Once
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
x11Driver = newX11Window
|
x11Driver = newX11Window
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package microphone implements permissions to access microphone hardware.
|
||||||
|
|
||||||
|
# Android
|
||||||
|
|
||||||
|
The following entries will be added to AndroidManifest.xml:
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
||||||
|
|
||||||
|
RECORD_AUDIO is a "dangerous" permission. See documentation for package
|
||||||
|
gioui.org/app/permission for more information.
|
||||||
|
*/
|
||||||
|
package microphone
|
||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build android || (darwin && ios)
|
//go:build android || (darwin && ios)
|
||||||
// +build android darwin,ios
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
@@ -25,6 +24,6 @@ func runMain() {
|
|||||||
// Indirect call, since the linker does not know the address of main when
|
// Indirect call, since the linker does not know the address of main when
|
||||||
// laying down this package.
|
// laying down this package.
|
||||||
fn := mainMain
|
fn := mainMain
|
||||||
fn()
|
go fn()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -175,7 +175,7 @@ func (c *vkContext) refresh(surf vk.Surface, width, height int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
minExt, maxExt := caps.MinExtent(), caps.MaxExtent()
|
minExt, maxExt := vk.SurfaceCapabilitiesMinExtent(caps), vk.SurfaceCapabilitiesMaxExtent(caps)
|
||||||
if width < minExt.X || maxExt.X < width || height < minExt.Y || maxExt.Y < height {
|
if width < minExt.X || maxExt.X < width || height < minExt.Y || maxExt.Y < height {
|
||||||
return errOutOfDate
|
return errOutOfDate
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build !novulkan
|
//go:build !novulkan
|
||||||
// +build !novulkan
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
|
|||||||
+151
-78
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"reflect"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -36,14 +35,15 @@ type Option func(unit.Metric, *Config)
|
|||||||
|
|
||||||
// Window represents an operating system window.
|
// Window represents an operating system window.
|
||||||
//
|
//
|
||||||
// The zero-value Window is useful, and calling any method on
|
// The zero-value Window is useful; the GUI window is created and shown the first
|
||||||
// it creates and shows a new GUI window. On iOS or Android,
|
// time the [Event] method is called. On iOS or Android, the first Window represents
|
||||||
// the first Window represents the the window previously
|
// the window previously created by the platform.
|
||||||
// created by the platform.
|
|
||||||
//
|
//
|
||||||
// More than one Window is not supported on iOS, Android,
|
// More than one Window is not supported on iOS, Android, WebAssembly.
|
||||||
// WebAssembly.
|
|
||||||
type Window struct {
|
type Window struct {
|
||||||
|
initialOpts []Option
|
||||||
|
initialActions []system.Action
|
||||||
|
|
||||||
ctx context
|
ctx context
|
||||||
gpu gpu.GPU
|
gpu gpu.GPU
|
||||||
// timer tracks the delayed invalidate goroutine.
|
// timer tracks the delayed invalidate goroutine.
|
||||||
@@ -89,13 +89,18 @@ type Window struct {
|
|||||||
}
|
}
|
||||||
imeState editorState
|
imeState editorState
|
||||||
driver driver
|
driver driver
|
||||||
// basic is the driver interface that is needed even after the window is gone.
|
// gpuErr tracks the GPU error that is to be reported when
|
||||||
basic basicDriver
|
// the window is closed.
|
||||||
once sync.Once
|
gpuErr error
|
||||||
|
|
||||||
|
// invMu protects mayInvalidate.
|
||||||
|
invMu sync.Mutex
|
||||||
|
mayInvalidate bool
|
||||||
|
|
||||||
// coalesced tracks the most recent events waiting to be delivered
|
// coalesced tracks the most recent events waiting to be delivered
|
||||||
// to the client.
|
// to the client.
|
||||||
coalesced eventSummary
|
coalesced eventSummary
|
||||||
// frame tracks the most recently frame event.
|
// frame tracks the most recent frame event.
|
||||||
lastFrame struct {
|
lastFrame struct {
|
||||||
sync bool
|
sync bool
|
||||||
size image.Point
|
size image.Point
|
||||||
@@ -105,11 +110,12 @@ type Window struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type eventSummary struct {
|
type eventSummary struct {
|
||||||
wakeup bool
|
wakeup bool
|
||||||
cfg *ConfigEvent
|
cfg *ConfigEvent
|
||||||
view *ViewEvent
|
view *ViewEvent
|
||||||
frame *frameEvent
|
frame *frameEvent
|
||||||
destroy *DestroyEvent
|
framePending bool
|
||||||
|
destroy *DestroyEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
type callbacks struct {
|
type callbacks struct {
|
||||||
@@ -216,6 +222,7 @@ func (w *Window) frame(frame *op.Ops, viewport image.Point) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) processFrame(frame *op.Ops, ack chan<- struct{}) {
|
func (w *Window) processFrame(frame *op.Ops, ack chan<- struct{}) {
|
||||||
|
w.coalesced.framePending = false
|
||||||
wrapper := &w.decorations.Ops
|
wrapper := &w.decorations.Ops
|
||||||
off := op.Offset(w.lastFrame.off).Push(wrapper)
|
off := op.Offset(w.lastFrame.off).Push(wrapper)
|
||||||
ops.AddCall(&wrapper.Internal, &frame.Internal, ops.PC{}, ops.PCFor(&frame.Internal))
|
ops.AddCall(&wrapper.Internal, &frame.Internal, ops.PC{}, ops.PCFor(&frame.Internal))
|
||||||
@@ -223,7 +230,8 @@ func (w *Window) processFrame(frame *op.Ops, ack chan<- struct{}) {
|
|||||||
w.lastFrame.deco.Add(wrapper)
|
w.lastFrame.deco.Add(wrapper)
|
||||||
if err := w.validateAndProcess(w.lastFrame.size, w.lastFrame.sync, wrapper, ack); err != nil {
|
if err := w.validateAndProcess(w.lastFrame.size, w.lastFrame.sync, wrapper, ack); err != nil {
|
||||||
w.destroyGPU()
|
w.destroyGPU()
|
||||||
w.driver.ProcessEvent(DestroyEvent{Err: err})
|
w.gpuErr = err
|
||||||
|
w.driver.Perform(system.ActionClose)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.updateState()
|
w.updateState()
|
||||||
@@ -273,8 +281,12 @@ func (w *Window) updateState() {
|
|||||||
//
|
//
|
||||||
// Invalidate is safe for concurrent use.
|
// Invalidate is safe for concurrent use.
|
||||||
func (w *Window) Invalidate() {
|
func (w *Window) Invalidate() {
|
||||||
w.init()
|
w.invMu.Lock()
|
||||||
w.basic.Invalidate()
|
defer w.invMu.Unlock()
|
||||||
|
if w.mayInvalidate {
|
||||||
|
w.mayInvalidate = false
|
||||||
|
w.driver.Invalidate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option applies the options to the window. The options are hints; the platform is
|
// Option applies the options to the window. The options are hints; the platform is
|
||||||
@@ -283,7 +295,10 @@ func (w *Window) Option(opts ...Option) {
|
|||||||
if len(opts) == 0 {
|
if len(opts) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.init(opts...)
|
if w.driver == nil {
|
||||||
|
w.initialOpts = append(w.initialOpts, opts...)
|
||||||
|
return
|
||||||
|
}
|
||||||
w.Run(func() {
|
w.Run(func() {
|
||||||
cnf := Config{Decorated: w.decorations.enabled}
|
cnf := Config{Decorated: w.decorations.enabled}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -302,16 +317,14 @@ func (w *Window) Option(opts ...Option) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run f in the same thread as the native window event loop, and wait for f to
|
// Run f in the same thread as the native window event loop, and wait for f to
|
||||||
// return or the window to close. Run is guaranteed not to deadlock if it is
|
// return or the window to close. If the window has not yet been created,
|
||||||
// invoked during the handling of a [ViewEvent], [FrameEvent],
|
// Run calls f directly.
|
||||||
// [StageEvent]; call Run in a separate goroutine to avoid deadlock in all
|
|
||||||
// other cases.
|
|
||||||
//
|
//
|
||||||
// Note that most programs should not call Run; configuring a Window with
|
// Note that most programs should not call Run; configuring a Window with
|
||||||
// [CustomRenderer] is a notable exception.
|
// [CustomRenderer] is a notable exception.
|
||||||
func (w *Window) Run(f func()) {
|
func (w *Window) Run(f func()) {
|
||||||
w.init()
|
|
||||||
if w.driver == nil {
|
if w.driver == nil {
|
||||||
|
f()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
@@ -377,11 +390,13 @@ func (w *Window) setNextFrame(at time.Time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *callbacks) SetDriver(d basicDriver) {
|
func (c *callbacks) SetDriver(d driver) {
|
||||||
c.w.basic = d
|
if d == nil {
|
||||||
if d, ok := d.(driver); ok {
|
panic("nil driver")
|
||||||
c.w.driver = d
|
|
||||||
}
|
}
|
||||||
|
c.w.invMu.Lock()
|
||||||
|
defer c.w.invMu.Unlock()
|
||||||
|
c.w.driver = d
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *callbacks) ProcessFrame(frame *op.Ops, ack chan<- struct{}) {
|
func (c *callbacks) ProcessFrame(frame *op.Ops, ack chan<- struct{}) {
|
||||||
@@ -424,15 +439,13 @@ func (c *callbacks) EditorState() editorState {
|
|||||||
|
|
||||||
func (c *callbacks) SetComposingRegion(r key.Range) {
|
func (c *callbacks) SetComposingRegion(r key.Range) {
|
||||||
c.w.imeState.compose = r
|
c.w.imeState.compose = r
|
||||||
|
c.w.driver.ProcessEvent(key.CompositionEvent(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *callbacks) EditorInsert(text string) {
|
func (c *callbacks) EditorInsert(text string) {
|
||||||
sel := c.w.imeState.Selection.Range
|
sel := c.w.imeState.Selection.Range
|
||||||
c.EditorReplace(sel, text)
|
c.EditorReplace(sel, text)
|
||||||
start := sel.Start
|
start := min(sel.End, sel.Start)
|
||||||
if sel.End < start {
|
|
||||||
start = sel.End
|
|
||||||
}
|
|
||||||
sel.Start = start + utf8.RuneCountInString(text)
|
sel.Start = start + utf8.RuneCountInString(text)
|
||||||
sel.End = sel.Start
|
sel.End = sel.Start
|
||||||
c.SetEditorSelection(sel)
|
c.SetEditorSelection(sel)
|
||||||
@@ -548,10 +561,20 @@ func (c *callbacks) Invalidate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *callbacks) nextEvent() (event.Event, bool) {
|
func (c *callbacks) nextEvent() (event.Event, bool) {
|
||||||
s := &c.w.coalesced
|
return c.w.nextEvent()
|
||||||
// Every event counts as a wakeup.
|
}
|
||||||
defer func() { s.wakeup = false }()
|
|
||||||
|
func (w *Window) nextEvent() (event.Event, bool) {
|
||||||
|
s := &w.coalesced
|
||||||
|
defer func() {
|
||||||
|
// Every event counts as a wakeup.
|
||||||
|
s.wakeup = false
|
||||||
|
}()
|
||||||
switch {
|
switch {
|
||||||
|
case s.framePending:
|
||||||
|
// If the user didn't call FrameEvent.Event, process
|
||||||
|
// an empty frame.
|
||||||
|
w.processFrame(new(op.Ops), nil)
|
||||||
case s.view != nil:
|
case s.view != nil:
|
||||||
e := *s.view
|
e := *s.view
|
||||||
s.view = nil
|
s.view = nil
|
||||||
@@ -568,10 +591,14 @@ func (c *callbacks) nextEvent() (event.Event, bool) {
|
|||||||
case s.frame != nil:
|
case s.frame != nil:
|
||||||
e := *s.frame
|
e := *s.frame
|
||||||
s.frame = nil
|
s.frame = nil
|
||||||
|
s.framePending = true
|
||||||
return e.FrameEvent, true
|
return e.FrameEvent, true
|
||||||
case s.wakeup:
|
case s.wakeup:
|
||||||
return wakeupEvent{}, true
|
return wakeupEvent{}, true
|
||||||
}
|
}
|
||||||
|
w.invMu.Lock()
|
||||||
|
defer w.invMu.Unlock()
|
||||||
|
w.mayInvalidate = w.driver != nil
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,15 +641,21 @@ func (w *Window) processEvent(e event.Event) bool {
|
|||||||
e2.Size = e2.Size.Sub(offset)
|
e2.Size = e2.Size.Sub(offset)
|
||||||
w.coalesced.frame = &e2
|
w.coalesced.frame = &e2
|
||||||
case DestroyEvent:
|
case DestroyEvent:
|
||||||
|
if w.gpuErr != nil {
|
||||||
|
e2.Err = w.gpuErr
|
||||||
|
}
|
||||||
w.destroyGPU()
|
w.destroyGPU()
|
||||||
|
w.invMu.Lock()
|
||||||
|
w.mayInvalidate = false
|
||||||
w.driver = nil
|
w.driver = nil
|
||||||
|
w.invMu.Unlock()
|
||||||
if q := w.timer.quit; q != nil {
|
if q := w.timer.quit; q != nil {
|
||||||
q <- struct{}{}
|
q <- struct{}{}
|
||||||
<-q
|
<-q
|
||||||
}
|
}
|
||||||
w.coalesced.destroy = &e2
|
w.coalesced.destroy = &e2
|
||||||
case ViewEvent:
|
case ViewEvent:
|
||||||
if reflect.ValueOf(e2).IsZero() && w.gpu != nil {
|
if !e2.Valid() && w.gpu != nil {
|
||||||
w.ctx.Lock()
|
w.ctx.Lock()
|
||||||
w.gpu.Release()
|
w.gpu.Release()
|
||||||
w.gpu = nil
|
w.gpu = nil
|
||||||
@@ -630,9 +663,20 @@ func (w *Window) processEvent(e event.Event) bool {
|
|||||||
}
|
}
|
||||||
w.coalesced.view = &e2
|
w.coalesced.view = &e2
|
||||||
case ConfigEvent:
|
case ConfigEvent:
|
||||||
|
w.decorations.Decorations.Maximized = e2.Config.Mode == Maximized
|
||||||
|
wasFocused := w.decorations.Config.Focused
|
||||||
w.decorations.Config = e2.Config
|
w.decorations.Config = e2.Config
|
||||||
e2.Config = w.effectiveConfig()
|
e2.Config = w.effectiveConfig()
|
||||||
w.coalesced.cfg = &e2
|
w.coalesced.cfg = &e2
|
||||||
|
if f := w.decorations.Config.Focused; f != wasFocused {
|
||||||
|
w.queue.Queue(key.FocusEvent{Focus: f})
|
||||||
|
}
|
||||||
|
t, handled := w.queue.WakeupTime()
|
||||||
|
if handled {
|
||||||
|
w.setNextFrame(t)
|
||||||
|
w.updateAnimation()
|
||||||
|
}
|
||||||
|
return handled
|
||||||
case event.Event:
|
case event.Event:
|
||||||
focusDir := key.FocusDirection(-1)
|
focusDir := key.FocusDirection(-1)
|
||||||
if e, ok := e2.(key.Event); ok && e.State == key.Press {
|
if e, ok := e2.(key.Event); ok && e.State == key.Press {
|
||||||
@@ -673,48 +717,61 @@ func (w *Window) processEvent(e event.Event) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Event blocks until an event is received from the window, such as
|
// Event blocks until an event is received from the window, such as
|
||||||
// [FrameEvent], or until [Invalidate] is called.
|
// [FrameEvent], or until [Invalidate] is called. The window is created
|
||||||
|
// and shown the first time Event is called.
|
||||||
func (w *Window) Event() event.Event {
|
func (w *Window) Event() event.Event {
|
||||||
w.init()
|
if w.driver == nil {
|
||||||
return w.basic.Event()
|
w.init()
|
||||||
|
}
|
||||||
|
if w.driver == nil {
|
||||||
|
e, ok := w.nextEvent()
|
||||||
|
if !ok {
|
||||||
|
panic("window initialization failed without a DestroyEvent")
|
||||||
|
}
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return w.driver.Event()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) init(initial ...Option) {
|
func (w *Window) init() {
|
||||||
w.once.Do(func() {
|
debug.Parse()
|
||||||
debug.Parse()
|
// Measure decoration height.
|
||||||
// Measure decoration height.
|
deco := new(widget.Decorations)
|
||||||
deco := new(widget.Decorations)
|
theme := material.NewTheme()
|
||||||
theme := material.NewTheme()
|
theme.Shaper = text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Regular()))
|
||||||
theme.Shaper = text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Regular()))
|
decoStyle := material.Decorations(theme, deco, 0, "")
|
||||||
decoStyle := material.Decorations(theme, deco, 0, "")
|
gtx := layout.Context{
|
||||||
gtx := layout.Context{
|
Ops: new(op.Ops),
|
||||||
Ops: new(op.Ops),
|
// Measure in Dp.
|
||||||
// Measure in Dp.
|
Metric: unit.Metric{},
|
||||||
Metric: unit.Metric{},
|
}
|
||||||
}
|
// Allow plenty of space.
|
||||||
// Allow plenty of space.
|
gtx.Constraints.Max.Y = 200
|
||||||
gtx.Constraints.Max.Y = 200
|
dims := decoStyle.Layout(gtx)
|
||||||
dims := decoStyle.Layout(gtx)
|
decoHeight := unit.Dp(dims.Size.Y)
|
||||||
decoHeight := unit.Dp(dims.Size.Y)
|
defaultOptions := []Option{
|
||||||
defaultOptions := []Option{
|
Size(800, 600),
|
||||||
Size(800, 600),
|
Title("Gio"),
|
||||||
Title("Gio"),
|
Decorated(true),
|
||||||
Decorated(true),
|
decoHeightOpt(decoHeight),
|
||||||
decoHeightOpt(decoHeight),
|
}
|
||||||
}
|
options := append(defaultOptions, w.initialOpts...)
|
||||||
options := append(defaultOptions, initial...)
|
w.initialOpts = nil
|
||||||
var cnf Config
|
var cnf Config
|
||||||
cnf.apply(unit.Metric{}, options)
|
cnf.apply(unit.Metric{}, options)
|
||||||
|
|
||||||
w.nocontext = cnf.CustomRenderer
|
w.nocontext = cnf.CustomRenderer
|
||||||
w.decorations.Theme = theme
|
w.decorations.Theme = theme
|
||||||
w.decorations.Decorations = deco
|
w.decorations.Decorations = deco
|
||||||
w.decorations.enabled = cnf.Decorated
|
w.decorations.enabled = cnf.Decorated
|
||||||
w.decorations.height = decoHeight
|
w.decorations.height = decoHeight
|
||||||
w.imeState.compose = key.Range{Start: -1, End: -1}
|
w.imeState.compose = key.Range{Start: -1, End: -1}
|
||||||
w.semantic.ids = make(map[input.SemanticID]input.SemanticNode)
|
w.semantic.ids = make(map[input.SemanticID]input.SemanticNode)
|
||||||
newWindow(&callbacks{w}, options)
|
newWindow(&callbacks{w}, options)
|
||||||
})
|
for _, acts := range w.initialActions {
|
||||||
|
w.Perform(acts)
|
||||||
|
}
|
||||||
|
w.initialActions = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) updateCursor() {
|
func (w *Window) updateCursor() {
|
||||||
@@ -752,7 +809,6 @@ func (w *Window) decorate(e FrameEvent, o *op.Ops) image.Point {
|
|||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("unknown WindowMode %v", m))
|
panic(fmt.Errorf("unknown WindowMode %v", m))
|
||||||
}
|
}
|
||||||
deco.Perform(actions)
|
|
||||||
gtx := layout.Context{
|
gtx := layout.Context{
|
||||||
Ops: o,
|
Ops: o,
|
||||||
Now: e.Now,
|
Now: e.Now,
|
||||||
@@ -762,8 +818,12 @@ func (w *Window) decorate(e FrameEvent, o *op.Ops) image.Point {
|
|||||||
}
|
}
|
||||||
// Update the window based on the actions on the decorations.
|
// Update the window based on the actions on the decorations.
|
||||||
opts, acts := splitActions(deco.Update(gtx))
|
opts, acts := splitActions(deco.Update(gtx))
|
||||||
w.driver.Configure(opts)
|
if len(opts) > 0 {
|
||||||
w.driver.Perform(acts)
|
w.driver.Configure(opts)
|
||||||
|
}
|
||||||
|
if acts != 0 {
|
||||||
|
w.driver.Perform(acts)
|
||||||
|
}
|
||||||
style.Layout(gtx)
|
style.Layout(gtx)
|
||||||
// Offset to place the frame content below the decorations.
|
// Offset to place the frame content below the decorations.
|
||||||
decoHeight := gtx.Dp(w.decorations.Config.decoHeight)
|
decoHeight := gtx.Dp(w.decorations.Config.decoHeight)
|
||||||
@@ -810,6 +870,10 @@ func (w *Window) Perform(actions system.Action) {
|
|||||||
if acts == 0 {
|
if acts == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if w.driver == nil {
|
||||||
|
w.initialActions = append(w.initialActions, acts)
|
||||||
|
return
|
||||||
|
}
|
||||||
w.Run(func() {
|
w.Run(func() {
|
||||||
w.driver.Perform(actions)
|
w.driver.Perform(actions)
|
||||||
})
|
})
|
||||||
@@ -906,6 +970,15 @@ func Decorated(enabled bool) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TopMost windows will be rendered above all other non-top-most windows.
|
||||||
|
//
|
||||||
|
// TopMost windows are supported on macOS, Windows.
|
||||||
|
func TopMost(enabled bool) Option {
|
||||||
|
return func(_ unit.Metric, cnf *Config) {
|
||||||
|
cnf.TopMost = enabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// flushEvent is sent to detect when the user program
|
// flushEvent is sent to detect when the user program
|
||||||
// has completed processing of all prior events. Its an
|
// has completed processing of all prior events. Its an
|
||||||
// [io/event.Event] but only for internal use.
|
// [io/event.Event] but only for internal use.
|
||||||
|
|||||||
+10
-1
@@ -30,6 +30,15 @@ func NewAffine2D(sx, hx, ox, hy, sy, oy float32) Affine2D {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AffineId returns an identity transformation matrix that represents no transformation
|
||||||
|
// when applied.
|
||||||
|
func AffineId() Affine2D {
|
||||||
|
return NewAffine2D(
|
||||||
|
1, 0, 0,
|
||||||
|
0, 1, 0,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Offset the transformation.
|
// Offset the transformation.
|
||||||
func (a Affine2D) Offset(offset Point) Affine2D {
|
func (a Affine2D) Offset(offset Point) Affine2D {
|
||||||
return Affine2D{
|
return Affine2D{
|
||||||
@@ -114,7 +123,7 @@ func (a Affine2D) Elems() (sx, hx, ox, hy, sy, oy float32) {
|
|||||||
|
|
||||||
// Split a transform into two parts, one which is pure offset and the
|
// Split a transform into two parts, one which is pure offset and the
|
||||||
// other representing the scaling, shearing and rotation part.
|
// other representing the scaling, shearing and rotation part.
|
||||||
func (a *Affine2D) Split() (srs Affine2D, offset Point) {
|
func (a Affine2D) Split() (srs Affine2D, offset Point) {
|
||||||
return Affine2D{
|
return Affine2D{
|
||||||
a: a.a, b: a.b, c: 0,
|
a: a.a, b: a.b, c: 0,
|
||||||
d: a.d, e: a.e, f: 0,
|
d: a.d, e: a.e, f: 0,
|
||||||
|
|||||||
+160
-30
@@ -27,11 +27,11 @@ func TestTransformOffset(t *testing.T) {
|
|||||||
p := Point{X: 1, Y: 2}
|
p := Point{X: 1, Y: 2}
|
||||||
o := Point{X: 2, Y: -3}
|
o := Point{X: 2, Y: -3}
|
||||||
|
|
||||||
r := Affine2D{}.Offset(o).Transform(p)
|
r := AffineId().Offset(o).Transform(p)
|
||||||
if !eq(r, Pt(3, -1)) {
|
if !eq(r, Pt(3, -1)) {
|
||||||
t.Errorf("offset transformation mismatch: have %v, want {3 -1}", r)
|
t.Errorf("offset transformation mismatch: have %v, want {3 -1}", r)
|
||||||
}
|
}
|
||||||
i := Affine2D{}.Offset(o).Invert().Transform(r)
|
i := AffineId().Offset(o).Invert().Transform(r)
|
||||||
if !eq(i, p) {
|
if !eq(i, p) {
|
||||||
t.Errorf("offset transformation inverse mismatch: have %v, want %v", i, p)
|
t.Errorf("offset transformation inverse mismatch: have %v, want %v", i, p)
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,9 @@ func TestString(t *testing.T) {
|
|||||||
}, {
|
}, {
|
||||||
in: NewAffine2D(29.142342, 31.4123412, 37.53152, 43.51324213, 47.123412, 53.14312342),
|
in: NewAffine2D(29.142342, 31.4123412, 37.53152, 43.51324213, 47.123412, 53.14312342),
|
||||||
exp: "[[29.1423 31.4123 37.5315] [43.5132 47.1234 53.1431]]",
|
exp: "[[29.1423 31.4123 37.5315] [43.5132 47.1234 53.1431]]",
|
||||||
|
}, {
|
||||||
|
in: AffineId(),
|
||||||
|
exp: "[[1 0 0] [0 1 0]]",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -64,11 +67,11 @@ func TestTransformScale(t *testing.T) {
|
|||||||
p := Point{X: 1, Y: 2}
|
p := Point{X: 1, Y: 2}
|
||||||
s := Point{X: -1, Y: 2}
|
s := Point{X: -1, Y: 2}
|
||||||
|
|
||||||
r := Affine2D{}.Scale(Point{}, s).Transform(p)
|
r := AffineId().Scale(Point{}, s).Transform(p)
|
||||||
if !eq(r, Pt(-1, 4)) {
|
if !eq(r, Pt(-1, 4)) {
|
||||||
t.Errorf("scale transformation mismatch: have %v, want {-1 4}", r)
|
t.Errorf("scale transformation mismatch: have %v, want {-1 4}", r)
|
||||||
}
|
}
|
||||||
i := Affine2D{}.Scale(Point{}, s).Invert().Transform(r)
|
i := AffineId().Scale(Point{}, s).Invert().Transform(r)
|
||||||
if !eq(i, p) {
|
if !eq(i, p) {
|
||||||
t.Errorf("scale transformation inverse mismatch: have %v, want %v", i, p)
|
t.Errorf("scale transformation inverse mismatch: have %v, want %v", i, p)
|
||||||
}
|
}
|
||||||
@@ -78,11 +81,11 @@ func TestTransformRotate(t *testing.T) {
|
|||||||
p := Point{X: 1, Y: 0}
|
p := Point{X: 1, Y: 0}
|
||||||
a := float32(math.Pi / 2)
|
a := float32(math.Pi / 2)
|
||||||
|
|
||||||
r := Affine2D{}.Rotate(Point{}, a).Transform(p)
|
r := AffineId().Rotate(Point{}, a).Transform(p)
|
||||||
if !eq(r, Pt(0, 1)) {
|
if !eq(r, Pt(0, 1)) {
|
||||||
t.Errorf("rotate transformation mismatch: have %v, want {0 1}", r)
|
t.Errorf("rotate transformation mismatch: have %v, want {0 1}", r)
|
||||||
}
|
}
|
||||||
i := Affine2D{}.Rotate(Point{}, a).Invert().Transform(r)
|
i := AffineId().Rotate(Point{}, a).Invert().Transform(r)
|
||||||
if !eq(i, p) {
|
if !eq(i, p) {
|
||||||
t.Errorf("rotate transformation inverse mismatch: have %v, want %v", i, p)
|
t.Errorf("rotate transformation inverse mismatch: have %v, want %v", i, p)
|
||||||
}
|
}
|
||||||
@@ -91,11 +94,11 @@ func TestTransformRotate(t *testing.T) {
|
|||||||
func TestTransformShear(t *testing.T) {
|
func TestTransformShear(t *testing.T) {
|
||||||
p := Point{X: 1, Y: 1}
|
p := Point{X: 1, Y: 1}
|
||||||
|
|
||||||
r := Affine2D{}.Shear(Point{}, math.Pi/4, 0).Transform(p)
|
r := AffineId().Shear(Point{}, math.Pi/4, 0).Transform(p)
|
||||||
if !eq(r, Pt(2, 1)) {
|
if !eq(r, Pt(2, 1)) {
|
||||||
t.Errorf("shear transformation mismatch: have %v, want {2 1}", r)
|
t.Errorf("shear transformation mismatch: have %v, want {2 1}", r)
|
||||||
}
|
}
|
||||||
i := Affine2D{}.Shear(Point{}, math.Pi/4, 0).Invert().Transform(r)
|
i := AffineId().Shear(Point{}, math.Pi/4, 0).Invert().Transform(r)
|
||||||
if !eq(i, p) {
|
if !eq(i, p) {
|
||||||
t.Errorf("shear transformation inverse mismatch: have %v, want %v", i, p)
|
t.Errorf("shear transformation inverse mismatch: have %v, want %v", i, p)
|
||||||
}
|
}
|
||||||
@@ -107,11 +110,11 @@ func TestTransformMultiply(t *testing.T) {
|
|||||||
s := Point{X: -1, Y: 2}
|
s := Point{X: -1, Y: 2}
|
||||||
a := float32(-math.Pi / 2)
|
a := float32(-math.Pi / 2)
|
||||||
|
|
||||||
r := Affine2D{}.Offset(o).Scale(Point{}, s).Rotate(Point{}, a).Shear(Point{}, math.Pi/4, 0).Transform(p)
|
r := AffineId().Offset(o).Scale(Point{}, s).Rotate(Point{}, a).Shear(Point{}, math.Pi/4, 0).Transform(p)
|
||||||
if !eq(r, Pt(1, 3)) {
|
if !eq(r, Pt(1, 3)) {
|
||||||
t.Errorf("complex transformation mismatch: have %v, want {1 3}", r)
|
t.Errorf("complex transformation mismatch: have %v, want {1 3}", r)
|
||||||
}
|
}
|
||||||
i := Affine2D{}.Offset(o).Scale(Point{}, s).Rotate(Point{}, a).Shear(Point{}, math.Pi/4, 0).Invert().Transform(r)
|
i := AffineId().Offset(o).Scale(Point{}, s).Rotate(Point{}, a).Shear(Point{}, math.Pi/4, 0).Invert().Transform(r)
|
||||||
if !eq(i, p) {
|
if !eq(i, p) {
|
||||||
t.Errorf("complex transformation inverse mismatch: have %v, want %v", i, p)
|
t.Errorf("complex transformation inverse mismatch: have %v, want %v", i, p)
|
||||||
}
|
}
|
||||||
@@ -163,7 +166,7 @@ func TestPrimes(t *testing.T) {
|
|||||||
func TestTransformScaleAround(t *testing.T) {
|
func TestTransformScaleAround(t *testing.T) {
|
||||||
p := Pt(-1, -1)
|
p := Pt(-1, -1)
|
||||||
target := Pt(-6, -13)
|
target := Pt(-6, -13)
|
||||||
pt := Affine2D{}.Scale(Pt(4, 5), Pt(2, 3)).Transform(p)
|
pt := AffineId().Scale(Pt(4, 5), Pt(2, 3)).Transform(p)
|
||||||
if !eq(pt, target) {
|
if !eq(pt, target) {
|
||||||
t.Log(pt, "!=", target)
|
t.Log(pt, "!=", target)
|
||||||
t.Error("Scale not as expected")
|
t.Error("Scale not as expected")
|
||||||
@@ -172,7 +175,7 @@ func TestTransformScaleAround(t *testing.T) {
|
|||||||
|
|
||||||
func TestTransformRotateAround(t *testing.T) {
|
func TestTransformRotateAround(t *testing.T) {
|
||||||
p := Pt(-1, -1)
|
p := Pt(-1, -1)
|
||||||
pt := Affine2D{}.Rotate(Pt(1, 1), -math.Pi/2).Transform(p)
|
pt := AffineId().Rotate(Pt(1, 1), -math.Pi/2).Transform(p)
|
||||||
target := Pt(-1, 3)
|
target := Pt(-1, 3)
|
||||||
if !eq(pt, target) {
|
if !eq(pt, target) {
|
||||||
t.Log(pt, "!=", target)
|
t.Log(pt, "!=", target)
|
||||||
@@ -181,12 +184,12 @@ func TestTransformRotateAround(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMulOrder(t *testing.T) {
|
func TestMulOrder(t *testing.T) {
|
||||||
A := Affine2D{}.Offset(Pt(100, 100))
|
A := AffineId().Offset(Pt(100, 100))
|
||||||
B := Affine2D{}.Scale(Point{}, Pt(2, 2))
|
B := AffineId().Scale(Point{}, Pt(2, 2))
|
||||||
_ = A
|
_ = A
|
||||||
_ = B
|
_ = B
|
||||||
|
|
||||||
T1 := Affine2D{}.Offset(Pt(100, 100)).Scale(Point{}, Pt(2, 2))
|
T1 := AffineId().Offset(Pt(100, 100)).Scale(Point{}, Pt(2, 2))
|
||||||
T2 := B.Mul(A)
|
T2 := B.Mul(A)
|
||||||
|
|
||||||
if T1 != T2 {
|
if T1 != T2 {
|
||||||
@@ -199,9 +202,9 @@ func TestMulOrder(t *testing.T) {
|
|||||||
func BenchmarkTransformOffset(b *testing.B) {
|
func BenchmarkTransformOffset(b *testing.B) {
|
||||||
p := Point{X: 1, Y: 2}
|
p := Point{X: 1, Y: 2}
|
||||||
o := Point{X: 0.5, Y: 0.5}
|
o := Point{X: 0.5, Y: 0.5}
|
||||||
aff := Affine2D{}.Offset(o)
|
aff := AffineId().Offset(o)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
p = aff.Transform(p)
|
p = aff.Transform(p)
|
||||||
}
|
}
|
||||||
_ = p
|
_ = p
|
||||||
@@ -210,8 +213,8 @@ func BenchmarkTransformOffset(b *testing.B) {
|
|||||||
func BenchmarkTransformScale(b *testing.B) {
|
func BenchmarkTransformScale(b *testing.B) {
|
||||||
p := Point{X: 1, Y: 2}
|
p := Point{X: 1, Y: 2}
|
||||||
s := Point{X: 0.5, Y: 0.5}
|
s := Point{X: 0.5, Y: 0.5}
|
||||||
aff := Affine2D{}.Scale(Point{}, s)
|
aff := AffineId().Scale(Point{}, s)
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
p = aff.Transform(p)
|
p = aff.Transform(p)
|
||||||
}
|
}
|
||||||
_ = p
|
_ = p
|
||||||
@@ -220,36 +223,163 @@ func BenchmarkTransformScale(b *testing.B) {
|
|||||||
func BenchmarkTransformRotate(b *testing.B) {
|
func BenchmarkTransformRotate(b *testing.B) {
|
||||||
p := Point{X: 1, Y: 2}
|
p := Point{X: 1, Y: 2}
|
||||||
a := float32(math.Pi / 2)
|
a := float32(math.Pi / 2)
|
||||||
aff := Affine2D{}.Rotate(Point{}, a)
|
aff := AffineId().Rotate(Point{}, a)
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
p = aff.Transform(p)
|
p = aff.Transform(p)
|
||||||
}
|
}
|
||||||
_ = p
|
_ = p
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkTransformTranslateMultiply(b *testing.B) {
|
func BenchmarkTransformTranslateMultiply(b *testing.B) {
|
||||||
a := Affine2D{}.Offset(Point{X: 1, Y: 1}).Rotate(Point{}, math.Pi/3)
|
a := AffineId().Offset(Point{X: 1, Y: 1}).Rotate(Point{}, math.Pi/3)
|
||||||
t := Affine2D{}.Offset(Point{X: 0.5, Y: 0.5})
|
t := AffineId().Offset(Point{X: 0.5, Y: 0.5})
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
a = a.Mul(t)
|
a = a.Mul(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkTransformScaleMultiply(b *testing.B) {
|
func BenchmarkTransformScaleMultiply(b *testing.B) {
|
||||||
a := Affine2D{}.Offset(Point{X: 1, Y: 1}).Rotate(Point{}, math.Pi/3)
|
a := AffineId().Offset(Point{X: 1, Y: 1}).Rotate(Point{}, math.Pi/3)
|
||||||
t := Affine2D{}.Offset(Point{X: 0.5, Y: 0.5}).Scale(Point{}, Point{X: 0.4, Y: -0.5})
|
t := AffineId().Offset(Point{X: 0.5, Y: 0.5}).Scale(Point{}, Point{X: 0.4, Y: -0.5})
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
a = a.Mul(t)
|
a = a.Mul(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkTransformMultiply(b *testing.B) {
|
func BenchmarkTransformMultiply(b *testing.B) {
|
||||||
a := Affine2D{}.Offset(Point{X: 1, Y: 1}).Rotate(Point{}, math.Pi/3)
|
a := AffineId().Offset(Point{X: 1, Y: 1}).Rotate(Point{}, math.Pi/3)
|
||||||
t := Affine2D{}.Offset(Point{X: 0.5, Y: 0.5}).Rotate(Point{}, math.Pi/7)
|
t := AffineId().Offset(Point{X: 0.5, Y: 0.5}).Rotate(Point{}, math.Pi/7)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
a = a.Mul(t)
|
a = a.Mul(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewAffine2D(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
sx, hx, ox, hy, sy, oy float32
|
||||||
|
expected Affine2D
|
||||||
|
}{
|
||||||
|
{1, 0, 0, 0, 1, 0, AffineId()},
|
||||||
|
{2, 0, 5, 0, 3, 7, Affine2D{a: 1, b: 0, c: 5, d: 0, e: 2, f: 7}},
|
||||||
|
{-1, 2, 3, 4, -5, 6, Affine2D{a: -2, b: 2, c: 3, d: 4, e: -6, f: 6}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
|
got := NewAffine2D(test.sx, test.hx, test.ox, test.hy, test.sy, test.oy)
|
||||||
|
if !eqaff(got, test.expected) {
|
||||||
|
t.Errorf(
|
||||||
|
"Test %d: NewAffine2D(%v, %v, %v, %v, %v, %v) = %v, want %v",
|
||||||
|
i, test.sx, test.hx, test.ox, test.hy, test.sy, test.oy, got, test.expected,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAffineId(t *testing.T) {
|
||||||
|
id := AffineId()
|
||||||
|
|
||||||
|
testPoints := []Point{
|
||||||
|
{0, 0},
|
||||||
|
{1, 0},
|
||||||
|
{0, 1},
|
||||||
|
{-1, -1},
|
||||||
|
{10, 20},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range testPoints {
|
||||||
|
transformed := id.Transform(p)
|
||||||
|
if !eq(transformed, p) {
|
||||||
|
t.Errorf("Identity transform changed point: %v -> %v", p, transformed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestElems(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
aff Affine2D
|
||||||
|
sx, hx, ox, hy, sy, oy float32
|
||||||
|
}{
|
||||||
|
{AffineId(), 1, 0, 0, 0, 1, 0},
|
||||||
|
{Affine2D{a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}, 2, 2, 3, 4, 6, 6},
|
||||||
|
{NewAffine2D(7, 8, 9, 10, 11, 12), 7, 8, 9, 10, 11, 12},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
|
sx, hx, ox, hy, sy, oy := test.aff.Elems()
|
||||||
|
if sx != test.sx || hx != test.hx || ox != test.ox ||
|
||||||
|
hy != test.hy || sy != test.sy || oy != test.oy {
|
||||||
|
t.Errorf(
|
||||||
|
"Test %d: %v.Elems() = (%v, %v, %v, %v, %v, %v), want (%v, %v, %v, %v, %v, %v)",
|
||||||
|
i, test.aff, sx, hx, ox, hy, sy, oy, test.sx, test.hx, test.ox, test.hy, test.sy, test.oy,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSplit(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
aff Affine2D
|
||||||
|
expectedSRS Affine2D
|
||||||
|
expectedOffset Point
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
AffineId(),
|
||||||
|
AffineId(),
|
||||||
|
Point{0, 0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Affine2D{a: 1, b: 2, c: 3, d: 4, e: 5, f: 6},
|
||||||
|
Affine2D{a: 1, b: 2, c: 0, d: 4, e: 5, f: 0},
|
||||||
|
Point{3, 6},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NewAffine2D(2, 0, 10, 0, 3, 20),
|
||||||
|
NewAffine2D(2, 0, 0, 0, 3, 0),
|
||||||
|
Point{10, 20},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
|
srs, offset := test.aff.Split()
|
||||||
|
if !eqaff(srs, test.expectedSRS) || !eq(offset, test.expectedOffset) {
|
||||||
|
t.Errorf(
|
||||||
|
"Test %d: %v.Split() = (%v, %v), want (%v, %v)",
|
||||||
|
i, test.aff, srs, offset, test.expectedSRS, test.expectedOffset,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestShear(t *testing.T) {
|
||||||
|
p := Pt(2, 3)
|
||||||
|
origin := Pt(1, 1)
|
||||||
|
|
||||||
|
shearX := AffineId().Shear(origin, math.Pi/4, 0)
|
||||||
|
resultX := shearX.Transform(p)
|
||||||
|
expectedX := Pt(4, 3)
|
||||||
|
|
||||||
|
if !eq(resultX, expectedX) {
|
||||||
|
t.Errorf("Shear around origin in X: got %v, want %v", resultX, expectedX)
|
||||||
|
}
|
||||||
|
|
||||||
|
inverseX := shearX.Invert().Transform(resultX)
|
||||||
|
if !eq(inverseX, p) {
|
||||||
|
t.Errorf("Inverse shear X: got %v, want %v", inverseX, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
shearY := AffineId().Shear(origin, 0, math.Pi/4)
|
||||||
|
resultY := shearY.Transform(p)
|
||||||
|
expectedY := Pt(2, 4)
|
||||||
|
|
||||||
|
if !eq(resultY, expectedY) {
|
||||||
|
t.Errorf("Shear around origin in Y: got %v, want %v", resultY, expectedY)
|
||||||
|
}
|
||||||
|
|
||||||
|
inverseY := shearY.Invert().Transform(resultY)
|
||||||
|
if !eq(inverseY, p) {
|
||||||
|
t.Errorf("Inverse shear Y: got %v, want %v", inverseY, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Generated
+17
-76
@@ -1,87 +1,25 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"android": {
|
|
||||||
"inputs": {
|
|
||||||
"devshell": "devshell",
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1701721028,
|
|
||||||
"narHash": "sha256-2z4YrdHPLoMZNWR1MPOjNZMqPg057i1eZXaYI6RTahQ=",
|
|
||||||
"owner": "tadfisher",
|
|
||||||
"repo": "android-nixpkgs",
|
|
||||||
"rev": "c923f9ec0f4dd0d7dc725dc5b73fbf03658e50dd",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "tadfisher",
|
|
||||||
"repo": "android-nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"devshell": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"android",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"systems": "systems"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1701697687,
|
|
||||||
"narHash": "sha256-dLLE5wQBVv+pIb4bWmKFSw2DvLVyuEk0F7ng6hpZPSU=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "devshell",
|
|
||||||
"rev": "c3bd77911391eb1638af6ce773de86da57ee6df5",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "devshell",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils": {
|
|
||||||
"inputs": {
|
|
||||||
"systems": "systems_2"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1701680307,
|
|
||||||
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1701282334,
|
"lastModified": 1747953325,
|
||||||
"narHash": "sha256-MxCVrXY6v4QmfTwIysjjaX0XUhqBbxTWWB4HXtDYsdk=",
|
"narHash": "sha256-y2ZtlIlNTuVJUZCqzZAhIw5rrKP4DOSklev6c8PyCkQ=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "057f9aecfb71c4437d2b27d3323df7f93c010b7e",
|
"rev": "55d1f923c480dadce40f5231feb472e81b0bab48",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"ref": "23.11",
|
"ref": "nixos-25.05",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"android": "android",
|
"nixpkgs": "nixpkgs",
|
||||||
"nixpkgs": "nixpkgs"
|
"utils": "utils"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
"systems": {
|
||||||
@@ -99,18 +37,21 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems_2": {
|
"utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1681028828,
|
"lastModified": 1731533236,
|
||||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
"owner": "nix-systems",
|
"owner": "numtide",
|
||||||
"repo": "default",
|
"repo": "flake-utils",
|
||||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nix-systems",
|
"owner": "numtide",
|
||||||
"repo": "default",
|
"repo": "flake-utils",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,42 +3,38 @@
|
|||||||
description = "Gio build environment";
|
description = "Gio build environment";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/23.11";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
|
||||||
android.url = "github:tadfisher/android-nixpkgs";
|
utils.url = "github:numtide/flake-utils";
|
||||||
android.inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, android }:
|
outputs = { self, nixpkgs, utils }:
|
||||||
let
|
utils.lib.eachDefaultSystem (system:
|
||||||
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
let
|
||||||
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
|
pkgs = import nixpkgs {
|
||||||
in
|
inherit system;
|
||||||
{
|
|
||||||
devShells = forAllSystems
|
# allow unfree Android packages.
|
||||||
(system:
|
config.allowUnfree = true;
|
||||||
let
|
# accept the Android SDK license.
|
||||||
pkgs = import nixpkgs {
|
config.android_sdk.accept_license = true;
|
||||||
inherit system;
|
};
|
||||||
|
in {
|
||||||
|
devShells = let
|
||||||
|
android-sdk = let
|
||||||
|
androidComposition = pkgs.androidenv.composeAndroidPackages {
|
||||||
|
platformVersions = [ "latest" ];
|
||||||
|
abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
|
||||||
|
# Omit the deprecated tools package.
|
||||||
|
toolsVersion = null;
|
||||||
|
includeNDK = true;
|
||||||
};
|
};
|
||||||
android-sdk = android.sdk.${system} (sdkPkgs: with sdkPkgs;
|
in androidComposition.androidsdk;
|
||||||
[
|
in {
|
||||||
build-tools-31-0-0
|
default = with pkgs;
|
||||||
cmdline-tools-latest
|
mkShell (rec {
|
||||||
platform-tools
|
ANDROID_HOME = "${android-sdk}/libexec/android-sdk";
|
||||||
platforms-android-31
|
packages = [ android-sdk jdk clang ]
|
||||||
ndk-bundle
|
++ (if stdenv.isLinux then [
|
||||||
]);
|
|
||||||
in
|
|
||||||
{
|
|
||||||
default = with pkgs; mkShell
|
|
||||||
({
|
|
||||||
ANDROID_SDK_ROOT = "${android-sdk}/share/android-sdk";
|
|
||||||
JAVA_HOME = jdk17.home;
|
|
||||||
packages = [
|
|
||||||
android-sdk
|
|
||||||
jdk17
|
|
||||||
clang
|
|
||||||
] ++ (if stdenv.isLinux then [
|
|
||||||
vulkan-headers
|
vulkan-headers
|
||||||
libxkbcommon
|
libxkbcommon
|
||||||
wayland
|
wayland
|
||||||
@@ -47,17 +43,12 @@
|
|||||||
xorg.libXfixes
|
xorg.libXfixes
|
||||||
libGL
|
libGL
|
||||||
pkg-config
|
pkg-config
|
||||||
] else if stdenv.isDarwin then [
|
] else
|
||||||
darwin.apple_sdk_11_0.frameworks.Foundation
|
[ ]);
|
||||||
darwin.apple_sdk_11_0.frameworks.Metal
|
} // (if stdenv.isLinux then {
|
||||||
darwin.apple_sdk_11_0.frameworks.QuartzCore
|
LD_LIBRARY_PATH = "${vulkan-loader}/lib";
|
||||||
darwin.apple_sdk_11_0.frameworks.AppKit
|
} else
|
||||||
darwin.apple_sdk_11_0.MacOSX-SDK
|
{ }));
|
||||||
] else [ ]);
|
};
|
||||||
} // (if stdenv.isLinux then {
|
});
|
||||||
LD_LIBRARY_PATH = "${vulkan-loader}/lib";
|
|
||||||
} else { }));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ type Font struct {
|
|||||||
// Face is an opaque handle to a typeface. The concrete implementation depends
|
// Face is an opaque handle to a typeface. The concrete implementation depends
|
||||||
// upon the kind of font and shaper in use.
|
// upon the kind of font and shaper in use.
|
||||||
type Face interface {
|
type Face interface {
|
||||||
Face() font.Face
|
Face() *font.Face
|
||||||
}
|
}
|
||||||
|
|
||||||
// Typeface identifies a list of font families to attempt to use for displaying
|
// Typeface identifies a list of font families to attempt to use for displaying
|
||||||
|
|||||||
+42
-44
@@ -16,23 +16,21 @@ import (
|
|||||||
_ "image/png"
|
_ "image/png"
|
||||||
|
|
||||||
giofont "gioui.org/font"
|
giofont "gioui.org/font"
|
||||||
"github.com/go-text/typesetting/font"
|
fontapi "github.com/go-text/typesetting/font"
|
||||||
fontapi "github.com/go-text/typesetting/opentype/api/font"
|
"github.com/go-text/typesetting/font/opentype"
|
||||||
"github.com/go-text/typesetting/opentype/api/metadata"
|
|
||||||
"github.com/go-text/typesetting/opentype/loader"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Face is a thread-safe representation of a loaded font. For efficiency, applications
|
// Face is a thread-safe representation of a loaded font. For efficiency, applications
|
||||||
// should construct a face for any given font file once, reusing it across different
|
// should construct a face for any given font file once, reusing it across different
|
||||||
// text shapers.
|
// text shapers.
|
||||||
type Face struct {
|
type Face struct {
|
||||||
face font.Font
|
face *fontapi.Font
|
||||||
font giofont.Font
|
font giofont.Font
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse constructs a Face from source bytes.
|
// Parse constructs a Face from source bytes.
|
||||||
func Parse(src []byte) (Face, error) {
|
func Parse(src []byte) (Face, error) {
|
||||||
ld, err := loader.NewLoader(bytes.NewReader(src))
|
ld, err := opentype.NewLoader(bytes.NewReader(src))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Face{}, err
|
return Face{}, err
|
||||||
}
|
}
|
||||||
@@ -49,11 +47,11 @@ func Parse(src []byte) (Face, error) {
|
|||||||
// ParseCollection parse an Opentype font file, with support for collections.
|
// ParseCollection parse an Opentype font file, with support for collections.
|
||||||
// Single font files are supported, returning a slice with length 1.
|
// Single font files are supported, returning a slice with length 1.
|
||||||
// The returned fonts are automatically wrapped in a text.FontFace with
|
// The returned fonts are automatically wrapped in a text.FontFace with
|
||||||
// inferred font metadata.
|
// inferred font font.
|
||||||
// BUG(whereswaldon): the only Variant that can be detected automatically is
|
// BUG(whereswaldon): the only Variant that can be detected automatically is
|
||||||
// "Mono".
|
// "Mono".
|
||||||
func ParseCollection(src []byte) ([]giofont.FontFace, error) {
|
func ParseCollection(src []byte) ([]giofont.FontFace, error) {
|
||||||
lds, err := loader.NewLoaders(bytes.NewReader(src))
|
lds, err := opentype.NewLoaders(bytes.NewReader(src))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -76,7 +74,7 @@ func ParseCollection(src []byte) ([]giofont.FontFace, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DescriptionToFont(md metadata.Description) giofont.Font {
|
func DescriptionToFont(md fontapi.Description) giofont.Font {
|
||||||
return giofont.Font{
|
return giofont.Font{
|
||||||
Typeface: giofont.Typeface(md.Family),
|
Typeface: giofont.Typeface(md.Family),
|
||||||
Style: gioStyle(md.Aspect.Style),
|
Style: gioStyle(md.Aspect.Style),
|
||||||
@@ -84,31 +82,31 @@ func DescriptionToFont(md metadata.Description) giofont.Font {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FontToDescription(font giofont.Font) metadata.Description {
|
func FontToDescription(font giofont.Font) fontapi.Description {
|
||||||
return metadata.Description{
|
return fontapi.Description{
|
||||||
Family: string(font.Typeface),
|
Family: string(font.Typeface),
|
||||||
Aspect: metadata.Aspect{
|
Aspect: fontapi.Aspect{
|
||||||
Style: mdStyle(font.Style),
|
Style: mdStyle(font.Style),
|
||||||
Weight: mdWeight(font.Weight),
|
Weight: mdWeight(font.Weight),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseLoader parses the contents of the loader into a face and its metadata.
|
// parseLoader parses the contents of the loader into a face and its font.
|
||||||
func parseLoader(ld *loader.Loader) (font.Font, giofont.Font, error) {
|
func parseLoader(ld *opentype.Loader) (*fontapi.Font, giofont.Font, error) {
|
||||||
ft, err := fontapi.NewFont(ld)
|
ft, err := fontapi.NewFont(ld)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, giofont.Font{}, err
|
return nil, giofont.Font{}, err
|
||||||
}
|
}
|
||||||
data := DescriptionToFont(metadata.Metadata(ld))
|
data := DescriptionToFont(ft.Describe())
|
||||||
return ft, data, nil
|
return ft, data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Face returns a thread-unsafe wrapper for this Face suitable for use by a single shaper.
|
// Face returns a thread-unsafe wrapper for this Face suitable for use by a single shaper.
|
||||||
// Face many be invoked any number of times and is safe so long as each return value is
|
// Face many be invoked any number of times and is safe so long as each return value is
|
||||||
// only used by one goroutine.
|
// only used by one goroutine.
|
||||||
func (f Face) Face() font.Face {
|
func (f Face) Face() *fontapi.Face {
|
||||||
return &fontapi.Face{Font: f.face}
|
return fontapi.NewFace(f.face)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FontFace returns a text.Font with populated font metadata for the
|
// FontFace returns a text.Font with populated font metadata for the
|
||||||
@@ -119,74 +117,74 @@ func (f Face) Font() giofont.Font {
|
|||||||
return f.font
|
return f.font
|
||||||
}
|
}
|
||||||
|
|
||||||
func gioStyle(s metadata.Style) giofont.Style {
|
func gioStyle(s fontapi.Style) giofont.Style {
|
||||||
switch s {
|
switch s {
|
||||||
case metadata.StyleItalic:
|
case fontapi.StyleItalic:
|
||||||
return giofont.Italic
|
return giofont.Italic
|
||||||
case metadata.StyleNormal:
|
case fontapi.StyleNormal:
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
return giofont.Regular
|
return giofont.Regular
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mdStyle(g giofont.Style) metadata.Style {
|
func mdStyle(g giofont.Style) fontapi.Style {
|
||||||
switch g {
|
switch g {
|
||||||
case giofont.Italic:
|
case giofont.Italic:
|
||||||
return metadata.StyleItalic
|
return fontapi.StyleItalic
|
||||||
case giofont.Regular:
|
case giofont.Regular:
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
return metadata.StyleNormal
|
return fontapi.StyleNormal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func gioWeight(w metadata.Weight) giofont.Weight {
|
func gioWeight(w fontapi.Weight) giofont.Weight {
|
||||||
switch w {
|
switch w {
|
||||||
case metadata.WeightThin:
|
case fontapi.WeightThin:
|
||||||
return giofont.Thin
|
return giofont.Thin
|
||||||
case metadata.WeightExtraLight:
|
case fontapi.WeightExtraLight:
|
||||||
return giofont.ExtraLight
|
return giofont.ExtraLight
|
||||||
case metadata.WeightLight:
|
case fontapi.WeightLight:
|
||||||
return giofont.Light
|
return giofont.Light
|
||||||
case metadata.WeightNormal:
|
case fontapi.WeightNormal:
|
||||||
return giofont.Normal
|
return giofont.Normal
|
||||||
case metadata.WeightMedium:
|
case fontapi.WeightMedium:
|
||||||
return giofont.Medium
|
return giofont.Medium
|
||||||
case metadata.WeightSemibold:
|
case fontapi.WeightSemibold:
|
||||||
return giofont.SemiBold
|
return giofont.SemiBold
|
||||||
case metadata.WeightBold:
|
case fontapi.WeightBold:
|
||||||
return giofont.Bold
|
return giofont.Bold
|
||||||
case metadata.WeightExtraBold:
|
case fontapi.WeightExtraBold:
|
||||||
return giofont.ExtraBold
|
return giofont.ExtraBold
|
||||||
case metadata.WeightBlack:
|
case fontapi.WeightBlack:
|
||||||
return giofont.Black
|
return giofont.Black
|
||||||
default:
|
default:
|
||||||
return giofont.Normal
|
return giofont.Normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mdWeight(g giofont.Weight) metadata.Weight {
|
func mdWeight(g giofont.Weight) fontapi.Weight {
|
||||||
switch g {
|
switch g {
|
||||||
case giofont.Thin:
|
case giofont.Thin:
|
||||||
return metadata.WeightThin
|
return fontapi.WeightThin
|
||||||
case giofont.ExtraLight:
|
case giofont.ExtraLight:
|
||||||
return metadata.WeightExtraLight
|
return fontapi.WeightExtraLight
|
||||||
case giofont.Light:
|
case giofont.Light:
|
||||||
return metadata.WeightLight
|
return fontapi.WeightLight
|
||||||
case giofont.Normal:
|
case giofont.Normal:
|
||||||
return metadata.WeightNormal
|
return fontapi.WeightNormal
|
||||||
case giofont.Medium:
|
case giofont.Medium:
|
||||||
return metadata.WeightMedium
|
return fontapi.WeightMedium
|
||||||
case giofont.SemiBold:
|
case giofont.SemiBold:
|
||||||
return metadata.WeightSemibold
|
return fontapi.WeightSemibold
|
||||||
case giofont.Bold:
|
case giofont.Bold:
|
||||||
return metadata.WeightBold
|
return fontapi.WeightBold
|
||||||
case giofont.ExtraBold:
|
case giofont.ExtraBold:
|
||||||
return metadata.WeightExtraBold
|
return fontapi.WeightExtraBold
|
||||||
case giofont.Black:
|
case giofont.Black:
|
||||||
return metadata.WeightBlack
|
return fontapi.WeightBlack
|
||||||
default:
|
default:
|
||||||
return metadata.WeightNormal
|
return fontapi.WeightNormal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-18
@@ -61,12 +61,8 @@ func (h *Hover) Update(q input.Source) bool {
|
|||||||
h.entered = false
|
h.entered = false
|
||||||
}
|
}
|
||||||
case pointer.Enter:
|
case pointer.Enter:
|
||||||
if !h.entered {
|
h.pid = e.PointerID
|
||||||
h.pid = e.PointerID
|
h.entered = true
|
||||||
}
|
|
||||||
if h.pid == e.PointerID {
|
|
||||||
h.entered = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return h.entered
|
return h.entered
|
||||||
@@ -222,12 +218,7 @@ func (c *Click) Update(q input.Source) (ClickEvent, bool) {
|
|||||||
if e.Source == pointer.Mouse && e.Buttons != pointer.ButtonPrimary {
|
if e.Source == pointer.Mouse && e.Buttons != pointer.ButtonPrimary {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if !c.hovered {
|
c.pid = e.PointerID
|
||||||
c.pid = e.PointerID
|
|
||||||
}
|
|
||||||
if c.pid != e.PointerID {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
c.pressed = true
|
c.pressed = true
|
||||||
if e.Time-c.clickedAt < doubleClickDuration {
|
if e.Time-c.clickedAt < doubleClickDuration {
|
||||||
c.clicks++
|
c.clicks++
|
||||||
@@ -271,12 +262,13 @@ func (s *Scroll) Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update state and report the scroll distance along axis.
|
// Update state and report the scroll distance along axis.
|
||||||
func (s *Scroll) Update(cfg unit.Metric, q input.Source, t time.Time, axis Axis, bounds image.Rectangle) int {
|
func (s *Scroll) Update(cfg unit.Metric, q input.Source, t time.Time, axis Axis, scrollx, scrolly pointer.ScrollRange) int {
|
||||||
total := 0
|
total := 0
|
||||||
f := pointer.Filter{
|
f := pointer.Filter{
|
||||||
Target: s,
|
Target: s,
|
||||||
Kinds: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll | pointer.Cancel,
|
Kinds: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll | pointer.Cancel,
|
||||||
ScrollBounds: bounds,
|
ScrollX: scrollx,
|
||||||
|
ScrollY: scrolly,
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
evt, ok := q.Event(f)
|
evt, ok := q.Event(f)
|
||||||
@@ -321,6 +313,8 @@ func (s *Scroll) Update(cfg unit.Metric, q input.Source, t time.Time, axis Axis,
|
|||||||
s.scroll += e.Scroll.X
|
s.scroll += e.Scroll.X
|
||||||
case Vertical:
|
case Vertical:
|
||||||
s.scroll += e.Scroll.Y
|
s.scroll += e.Scroll.Y
|
||||||
|
case Both:
|
||||||
|
s.scroll += e.Scroll.X + e.Scroll.Y
|
||||||
}
|
}
|
||||||
iscroll := int(s.scroll)
|
iscroll := int(s.scroll)
|
||||||
s.scroll -= float32(iscroll)
|
s.scroll -= float32(iscroll)
|
||||||
@@ -352,10 +346,15 @@ func (s *Scroll) Update(cfg unit.Metric, q input.Source, t time.Time, axis Axis,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scroll) val(axis Axis, p f32.Point) float32 {
|
func (s *Scroll) val(axis Axis, p f32.Point) float32 {
|
||||||
if axis == Horizontal {
|
switch axis {
|
||||||
|
case Horizontal:
|
||||||
return p.X
|
return p.X
|
||||||
} else {
|
case Vertical:
|
||||||
return p.Y
|
return p.Y
|
||||||
|
case Both:
|
||||||
|
return p.X + p.Y
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,78 @@ func TestMouseClicks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClickPointerIDReassignment(t *testing.T) {
|
||||||
|
// A Click must accept a Press from a PointerID that differs from the
|
||||||
|
// one its hovered state was previously associated with. Some backends
|
||||||
|
// reassign a single physical pointer's ID over its lifetime — e.g. the
|
||||||
|
// Windows pointer API across focus changes — and locking the gesture
|
||||||
|
// to the first observed ID would silently drop every subsequent press.
|
||||||
|
//
|
||||||
|
// The sequence below puts the gesture into the buggy state through
|
||||||
|
// public events alone: a press under PointerID 1 starts an active
|
||||||
|
// press cycle, a Move under PointerID 2 arrives mid-press (which the
|
||||||
|
// router routes as an Enter for PID 2 but the gesture's Enter handler
|
||||||
|
// is a no-op for pid while pressed), then PID 1 releases. After this,
|
||||||
|
// the router has the gesture entered for PID 2 (so the next event
|
||||||
|
// under PID 2 won't trigger another Enter) but the gesture itself
|
||||||
|
// still has pid=1.
|
||||||
|
var click Click
|
||||||
|
var ops op.Ops
|
||||||
|
rect := image.Rect(0, 0, 100, 100)
|
||||||
|
stack := clip.Rect(rect).Push(&ops)
|
||||||
|
click.Add(&ops)
|
||||||
|
stack.Pop()
|
||||||
|
|
||||||
|
var r input.Router
|
||||||
|
click.Update(r.Source())
|
||||||
|
r.Frame(&ops)
|
||||||
|
|
||||||
|
drain := func() {
|
||||||
|
for {
|
||||||
|
if _, ok := click.Update(r.Source()); !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Press under PointerID 1.
|
||||||
|
r.Queue(
|
||||||
|
pointer.Event{Kind: pointer.Move, Source: pointer.Mouse, Position: f32.Pt(50, 50), PointerID: 1},
|
||||||
|
pointer.Event{Kind: pointer.Press, Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, Position: f32.Pt(50, 50), PointerID: 1},
|
||||||
|
)
|
||||||
|
drain()
|
||||||
|
|
||||||
|
// Move under PointerID 2 while PointerID 1 is still pressed. The
|
||||||
|
// router records the gesture as entered for PointerID 2 but the
|
||||||
|
// gesture's Enter handler is a no-op for pid because c.pressed.
|
||||||
|
r.Queue(pointer.Event{Kind: pointer.Move, Source: pointer.Mouse, Position: f32.Pt(50, 50), PointerID: 2})
|
||||||
|
drain()
|
||||||
|
|
||||||
|
// Release PointerID 1. PointerID 1's press tracking ends; the
|
||||||
|
// gesture's recorded pid stays at 1.
|
||||||
|
r.Queue(pointer.Event{Kind: pointer.Release, Source: pointer.Mouse, Position: f32.Pt(50, 50), PointerID: 1})
|
||||||
|
drain()
|
||||||
|
|
||||||
|
// Press under PointerID 2. The router won't refire Enter for PID 2
|
||||||
|
// (the gesture is already in PID 2's entered set), so the gesture's
|
||||||
|
// only chance to refresh its pid is the Press handler itself.
|
||||||
|
r.Queue(pointer.Event{Kind: pointer.Press, Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, Position: f32.Pt(50, 50), PointerID: 2})
|
||||||
|
|
||||||
|
var sawPress bool
|
||||||
|
for {
|
||||||
|
ev, ok := click.Update(r.Source())
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if ev.Kind == KindPress {
|
||||||
|
sawPress = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !sawPress {
|
||||||
|
t.Fatal("expected KindPress for press under reassigned PointerID; gesture dropped the press because of stale recorded pid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func mouseClickEvents(times ...time.Duration) []event.Event {
|
func mouseClickEvents(times ...time.Duration) []event.Event {
|
||||||
press := pointer.Event{
|
press := pointer.Event{
|
||||||
Kind: pointer.Press,
|
Kind: pointer.Press,
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
module gioui.org
|
module gioui.org
|
||||||
|
|
||||||
go 1.19
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d
|
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d
|
||||||
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2
|
|
||||||
gioui.org/shader v1.0.8
|
gioui.org/shader v1.0.8
|
||||||
github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372
|
github.com/go-text/typesetting v0.3.4
|
||||||
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95
|
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0
|
||||||
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91
|
golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0
|
||||||
golang.org/x/image v0.5.0
|
golang.org/x/image v0.26.0
|
||||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64
|
golang.org/x/sys v0.39.0
|
||||||
|
golang.org/x/text v0.32.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require golang.org/x/text v0.7.0
|
require golang.org/x/net v0.48.0
|
||||||
|
|||||||
@@ -1,43 +1,21 @@
|
|||||||
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d h1:ARo7NCVvN2NdhLlJE9xAbKweuI9L6UgfTbYb0YwPacY=
|
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d h1:ARo7NCVvN2NdhLlJE9xAbKweuI9L6UgfTbYb0YwPacY=
|
||||||
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d/go.mod h1:OYVuxibdk9OSLX8vAqydtRPP87PyTFcT9uH3MlEGBQA=
|
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d/go.mod h1:OYVuxibdk9OSLX8vAqydtRPP87PyTFcT9uH3MlEGBQA=
|
||||||
gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
|
gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
|
||||||
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 h1:AGDDxsJE1RpcXTAxPG2B4jrwVUJGFDjINIPi1jtO6pc=
|
|
||||||
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
|
|
||||||
gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA=
|
gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA=
|
||||||
gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
|
gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
|
||||||
github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372 h1:FQivqchis6bE2/9uF70M2gmmLpe82esEm2QadL0TEJo=
|
github.com/go-text/typesetting v0.3.4 h1:YYurUOtEb9kGSOz4uE3k4OpBGsp1dDL8+fjCeaFamAU=
|
||||||
github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372/go.mod h1:evDBbvNR/KaVFZ2ZlDSOWWXIUKq0wCOEtzLxRM8SG3k=
|
github.com/go-text/typesetting v0.3.4/go.mod h1:4qZCQphq4KSgGTAeI0uMEkVbROgfah8BuyF5LRYr7XY=
|
||||||
github.com/go-text/typesetting-utils v0.0.0-20230616150549-2a7df14b6a22 h1:LBQTFxP2MfsyEDqSKmUBZaDuDHN1vpqDyOZjcqS7MYI=
|
github.com/go-text/typesetting-utils v0.0.0-20260223113751-2d88ac90dae3 h1:drBZzMgdYPbmyXqOto4YhhJGrFIQCX94FpR4MzTCsos=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/go-text/typesetting-utils v0.0.0-20260223113751-2d88ac90dae3/go.mod h1:3/62I4La/HBRX9TcTpBj4eipLiwzf+vhI+7whTc9V7o=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 h1:R84qjqJb5nVJMxqWYb3np9L5ZsaDtB+a39EqjV0JSUM=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:S9Xr4PYopiDyqSyp5NjCrhFrqg6A5zA2E/iPHPhqnS8=
|
||||||
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 h1:sBdrWpxhGDdTAYNqbgBLAR+ULAPPhfgncLr1X0lyWtg=
|
golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0 h1:tMSqXTK+AQdW3LpCbfatHSRPHeW6+2WuxaVQuHftn80=
|
||||||
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
|
golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:ygj7T6vSGhhm/9yTpOQQNvuAUFziTH7RUiH74EoE2C8=
|
||||||
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 h1:ryT6Nf0R83ZgD8WnFFdfI8wCeyqgdXWN4+CkFVNPAT0=
|
golang.org/x/image v0.26.0 h1:4XjIFEZWQmCZi6Wv8BoxsDhRU3RVnLX04dToTDAEPlY=
|
||||||
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91/go.mod h1:VjAR7z0ngyATZTELrBSkxOOHhhlnVUxDye4mcjx5h/8=
|
golang.org/x/image v0.26.0/go.mod h1:lcxbMFAovzpnJxzXS3nyL83K27tmqtKzIJpctK8YO5c=
|
||||||
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
|
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
||||||
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
|
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM=
|
|
||||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
|
||||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
|
|||||||
+6
-6
@@ -19,10 +19,10 @@ type quadSplitter struct {
|
|||||||
|
|
||||||
func encodeQuadTo(data []byte, meta uint32, from, ctrl, to f32.Point) {
|
func encodeQuadTo(data []byte, meta uint32, from, ctrl, to f32.Point) {
|
||||||
// inlined code:
|
// inlined code:
|
||||||
// encodeVertex(data, meta, -1, 1, from, ctrl, to)
|
// encodeVertex(data, meta, 1, -1, from, ctrl, to)
|
||||||
// encodeVertex(data[vertStride:], meta, 1, 1, from, ctrl, to)
|
// encodeVertex(data[vertStride:], meta, 1, 1, from, ctrl, to)
|
||||||
// encodeVertex(data[vertStride*2:], meta, -1, -1, from, ctrl, to)
|
// encodeVertex(data[vertStride*2:], meta, -1, -1, from, ctrl, to)
|
||||||
// encodeVertex(data[vertStride*3:], meta, 1, -1, from, ctrl, to)
|
// encodeVertex(data[vertStride*3:], meta, -1, 1, from, ctrl, to)
|
||||||
// this code needs to stay in sync with `vertex.encode`.
|
// this code needs to stay in sync with `vertex.encode`.
|
||||||
|
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
@@ -48,10 +48,10 @@ func encodeQuadTo(data []byte, meta uint32, from, ctrl, to f32.Point) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
nwCorner = 1*0.25 + 0*0.5
|
nwCorner = 1*0.5 + 0*0.25
|
||||||
neCorner = 1*0.25 + 1*0.5
|
neCorner = 1*0.5 + 1*0.25
|
||||||
swCorner = 0*0.25 + 0*0.5
|
swCorner = 0*0.5 + 0*0.25
|
||||||
seCorner = 0*0.25 + 1*0.5
|
seCorner = 0*0.5 + 1*0.25
|
||||||
)
|
)
|
||||||
|
|
||||||
func encodeVertex(data []byte, meta uint32, cornerx, cornery int16, from, ctrl, to f32.Point) {
|
func encodeVertex(data []byte, meta uint32, cornerx, cornery int16, from, ctrl, to f32.Point) {
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func BenchmarkEncodeQuadTo(b *testing.B) {
|
func BenchmarkEncodeQuadTo(b *testing.B) {
|
||||||
var data [vertStride * 4]byte
|
var data [vertStride * 4]byte
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; b.Loop(); i++ {
|
||||||
v := float32(i)
|
v := float32(i)
|
||||||
encodeQuadTo(data[:], 123,
|
encodeQuadTo(data[:], 123,
|
||||||
f32.Point{X: v, Y: v},
|
f32.Point{X: v, Y: v},
|
||||||
|
|||||||
-2193
File diff suppressed because it is too large
Load Diff
-129
@@ -1,129 +0,0 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
|
||||||
|
|
||||||
package gpu
|
|
||||||
|
|
||||||
import (
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"gioui.org/cpu"
|
|
||||||
)
|
|
||||||
|
|
||||||
// This file contains code specific to running compute shaders on the CPU.
|
|
||||||
|
|
||||||
// dispatcher dispatches CPU compute programs across multiple goroutines.
|
|
||||||
type dispatcher struct {
|
|
||||||
// done is notified when a worker completes its work slice.
|
|
||||||
done chan struct{}
|
|
||||||
// work receives work slice indices. It is closed when the dispatcher is released.
|
|
||||||
work chan work
|
|
||||||
// dispatch receives compute jobs, which is then split among workers.
|
|
||||||
dispatch chan dispatch
|
|
||||||
// sync receives notification when a Sync completes.
|
|
||||||
sync chan struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type work struct {
|
|
||||||
ctx *cpu.DispatchContext
|
|
||||||
index int
|
|
||||||
}
|
|
||||||
|
|
||||||
type dispatch struct {
|
|
||||||
_type jobType
|
|
||||||
program *cpu.ProgramInfo
|
|
||||||
descSet unsafe.Pointer
|
|
||||||
x, y, z int
|
|
||||||
}
|
|
||||||
|
|
||||||
type jobType uint8
|
|
||||||
|
|
||||||
const (
|
|
||||||
jobDispatch jobType = iota
|
|
||||||
jobBarrier
|
|
||||||
jobSync
|
|
||||||
)
|
|
||||||
|
|
||||||
func newDispatcher(workers int) *dispatcher {
|
|
||||||
d := &dispatcher{
|
|
||||||
work: make(chan work, workers),
|
|
||||||
done: make(chan struct{}, workers),
|
|
||||||
// Leave some room to avoid blocking calls to Dispatch.
|
|
||||||
dispatch: make(chan dispatch, 20),
|
|
||||||
sync: make(chan struct{}),
|
|
||||||
}
|
|
||||||
for i := 0; i < workers; i++ {
|
|
||||||
go d.worker()
|
|
||||||
}
|
|
||||||
go d.dispatcher()
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dispatcher) dispatcher() {
|
|
||||||
defer close(d.work)
|
|
||||||
var free []*cpu.DispatchContext
|
|
||||||
defer func() {
|
|
||||||
for _, ctx := range free {
|
|
||||||
ctx.Free()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
var used []*cpu.DispatchContext
|
|
||||||
for job := range d.dispatch {
|
|
||||||
switch job._type {
|
|
||||||
case jobDispatch:
|
|
||||||
if len(free) == 0 {
|
|
||||||
free = append(free, cpu.NewDispatchContext())
|
|
||||||
}
|
|
||||||
ctx := free[len(free)-1]
|
|
||||||
free = free[:len(free)-1]
|
|
||||||
used = append(used, ctx)
|
|
||||||
ctx.Prepare(cap(d.work), job.program, job.descSet, job.x, job.y, job.z)
|
|
||||||
for i := 0; i < cap(d.work); i++ {
|
|
||||||
d.work <- work{
|
|
||||||
ctx: ctx,
|
|
||||||
index: i,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case jobBarrier:
|
|
||||||
// Wait for all outstanding dispatches to complete.
|
|
||||||
for i := 0; i < len(used)*cap(d.work); i++ {
|
|
||||||
<-d.done
|
|
||||||
}
|
|
||||||
free = append(free, used...)
|
|
||||||
used = used[:0]
|
|
||||||
case jobSync:
|
|
||||||
d.sync <- struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dispatcher) worker() {
|
|
||||||
thread := cpu.NewThreadContext()
|
|
||||||
defer thread.Free()
|
|
||||||
for w := range d.work {
|
|
||||||
w.ctx.Dispatch(w.index, thread)
|
|
||||||
d.done <- struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dispatcher) Barrier() {
|
|
||||||
d.dispatch <- dispatch{_type: jobBarrier}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dispatcher) Sync() {
|
|
||||||
d.dispatch <- dispatch{_type: jobSync}
|
|
||||||
<-d.sync
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dispatcher) Dispatch(program *cpu.ProgramInfo, descSet unsafe.Pointer, x, y, z int) {
|
|
||||||
d.dispatch <- dispatch{
|
|
||||||
_type: jobDispatch,
|
|
||||||
program: program,
|
|
||||||
descSet: descSet,
|
|
||||||
x: x,
|
|
||||||
y: y,
|
|
||||||
z: z,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *dispatcher) Stop() {
|
|
||||||
close(d.dispatch)
|
|
||||||
}
|
|
||||||
+152
-120
@@ -9,12 +9,13 @@ package gpu
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@@ -189,7 +190,7 @@ const (
|
|||||||
// imageOpData is the shadow of paint.ImageOp.
|
// imageOpData is the shadow of paint.ImageOp.
|
||||||
type imageOpData struct {
|
type imageOpData struct {
|
||||||
src *image.RGBA
|
src *image.RGBA
|
||||||
handle interface{}
|
handle any
|
||||||
filter byte
|
filter byte
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +201,7 @@ type linearGradientOpData struct {
|
|||||||
color2 color.NRGBA
|
color2 color.NRGBA
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeImageOp(data []byte, refs []interface{}) imageOpData {
|
func decodeImageOp(data []byte, refs []any) imageOpData {
|
||||||
handle := refs[1]
|
handle := refs[1]
|
||||||
if handle == nil {
|
if handle == nil {
|
||||||
return imageOpData{}
|
return imageOpData{}
|
||||||
@@ -261,7 +262,7 @@ type texture struct {
|
|||||||
type blitter struct {
|
type blitter struct {
|
||||||
ctx driver.Device
|
ctx driver.Device
|
||||||
viewport image.Point
|
viewport image.Point
|
||||||
pipelines [3]*pipeline
|
pipelines [2][3]*pipeline
|
||||||
colUniforms *blitColUniforms
|
colUniforms *blitColUniforms
|
||||||
texUniforms *blitTexUniforms
|
texUniforms *blitTexUniforms
|
||||||
linearGradientUniforms *blitLinearGradientUniforms
|
linearGradientUniforms *blitLinearGradientUniforms
|
||||||
@@ -343,13 +344,12 @@ func New(api API) (GPU, error) {
|
|||||||
func NewWithDevice(d driver.Device) (GPU, error) {
|
func NewWithDevice(d driver.Device) (GPU, error) {
|
||||||
d.BeginFrame(nil, false, image.Point{})
|
d.BeginFrame(nil, false, image.Point{})
|
||||||
defer d.EndFrame()
|
defer d.EndFrame()
|
||||||
forceCompute := os.Getenv("GIORENDERER") == "forcecompute"
|
|
||||||
feats := d.Caps().Features
|
feats := d.Caps().Features
|
||||||
switch {
|
switch {
|
||||||
case !forceCompute && feats.Has(driver.FeatureFloatRenderTargets) && feats.Has(driver.FeatureSRGB):
|
case feats.Has(driver.FeatureFloatRenderTargets) && feats.Has(driver.FeatureSRGB):
|
||||||
return newGPU(d)
|
return newGPU(d)
|
||||||
}
|
}
|
||||||
return newCompute(d)
|
return nil, errors.New("no available GPU driver")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGPU(ctx driver.Device) (*gpu, error) {
|
func newGPU(ctx driver.Device) (*gpu, error) {
|
||||||
@@ -548,7 +548,7 @@ func newBlitter(ctx driver.Device) *blitter {
|
|||||||
b.texUniforms = new(blitTexUniforms)
|
b.texUniforms = new(blitTexUniforms)
|
||||||
b.linearGradientUniforms = new(blitLinearGradientUniforms)
|
b.linearGradientUniforms = new(blitLinearGradientUniforms)
|
||||||
pipelines, err := createColorPrograms(ctx, gio.Shader_blit_vert, gio.Shader_blit_frag,
|
pipelines, err := createColorPrograms(ctx, gio.Shader_blit_vert, gio.Shader_blit_frag,
|
||||||
[3]interface{}{b.colUniforms, b.linearGradientUniforms, b.texUniforms},
|
[3]any{b.colUniforms, b.linearGradientUniforms, b.texUniforms},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -560,12 +560,24 @@ func newBlitter(ctx driver.Device) *blitter {
|
|||||||
func (b *blitter) release() {
|
func (b *blitter) release() {
|
||||||
b.quadVerts.Release()
|
b.quadVerts.Release()
|
||||||
for _, p := range b.pipelines {
|
for _, p := range b.pipelines {
|
||||||
p.Release()
|
for _, p := range p {
|
||||||
|
p.Release()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createColorPrograms(b driver.Device, vsSrc shader.Sources, fsSrc [3]shader.Sources, uniforms [3]interface{}) ([3]*pipeline, error) {
|
func createColorPrograms(b driver.Device, vsSrc shader.Sources, fsSrc [3]shader.Sources, uniforms [3]any) (pipelines [2][3]*pipeline, err error) {
|
||||||
var pipelines [3]*pipeline
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
for _, p := range pipelines {
|
||||||
|
for _, p := range p {
|
||||||
|
if p != nil {
|
||||||
|
p.Release()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
blend := driver.BlendDesc{
|
blend := driver.BlendDesc{
|
||||||
Enable: true,
|
Enable: true,
|
||||||
SrcFactor: driver.BlendFactorOne,
|
SrcFactor: driver.BlendFactorOne,
|
||||||
@@ -583,86 +595,76 @@ func createColorPrograms(b driver.Device, vsSrc shader.Sources, fsSrc [3]shader.
|
|||||||
return pipelines, err
|
return pipelines, err
|
||||||
}
|
}
|
||||||
defer vsh.Release()
|
defer vsh.Release()
|
||||||
{
|
for i, format := range []driver.TextureFormat{driver.TextureFormatOutput, driver.TextureFormatSRGBA} {
|
||||||
fsh, err := b.NewFragmentShader(fsSrc[materialTexture])
|
{
|
||||||
if err != nil {
|
fsh, err := b.NewFragmentShader(fsSrc[materialTexture])
|
||||||
return pipelines, err
|
if err != nil {
|
||||||
|
return pipelines, err
|
||||||
|
}
|
||||||
|
defer fsh.Release()
|
||||||
|
pipe, err := b.NewPipeline(driver.PipelineDesc{
|
||||||
|
VertexShader: vsh,
|
||||||
|
FragmentShader: fsh,
|
||||||
|
BlendDesc: blend,
|
||||||
|
VertexLayout: layout,
|
||||||
|
PixelFormat: format,
|
||||||
|
Topology: driver.TopologyTriangleStrip,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return pipelines, err
|
||||||
|
}
|
||||||
|
var vertBuffer *uniformBuffer
|
||||||
|
if u := uniforms[materialTexture]; u != nil {
|
||||||
|
vertBuffer = newUniformBuffer(b, u)
|
||||||
|
}
|
||||||
|
pipelines[i][materialTexture] = &pipeline{pipe, vertBuffer}
|
||||||
}
|
}
|
||||||
defer fsh.Release()
|
{
|
||||||
pipe, err := b.NewPipeline(driver.PipelineDesc{
|
var vertBuffer *uniformBuffer
|
||||||
VertexShader: vsh,
|
fsh, err := b.NewFragmentShader(fsSrc[materialColor])
|
||||||
FragmentShader: fsh,
|
if err != nil {
|
||||||
BlendDesc: blend,
|
return pipelines, err
|
||||||
VertexLayout: layout,
|
}
|
||||||
PixelFormat: driver.TextureFormatOutput,
|
defer fsh.Release()
|
||||||
Topology: driver.TopologyTriangleStrip,
|
pipe, err := b.NewPipeline(driver.PipelineDesc{
|
||||||
})
|
VertexShader: vsh,
|
||||||
if err != nil {
|
FragmentShader: fsh,
|
||||||
return pipelines, err
|
BlendDesc: blend,
|
||||||
|
VertexLayout: layout,
|
||||||
|
PixelFormat: format,
|
||||||
|
Topology: driver.TopologyTriangleStrip,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return pipelines, err
|
||||||
|
}
|
||||||
|
if u := uniforms[materialColor]; u != nil {
|
||||||
|
vertBuffer = newUniformBuffer(b, u)
|
||||||
|
}
|
||||||
|
pipelines[i][materialColor] = &pipeline{pipe, vertBuffer}
|
||||||
}
|
}
|
||||||
var vertBuffer *uniformBuffer
|
{
|
||||||
if u := uniforms[materialTexture]; u != nil {
|
var vertBuffer *uniformBuffer
|
||||||
vertBuffer = newUniformBuffer(b, u)
|
fsh, err := b.NewFragmentShader(fsSrc[materialLinearGradient])
|
||||||
|
if err != nil {
|
||||||
|
return pipelines, err
|
||||||
|
}
|
||||||
|
defer fsh.Release()
|
||||||
|
pipe, err := b.NewPipeline(driver.PipelineDesc{
|
||||||
|
VertexShader: vsh,
|
||||||
|
FragmentShader: fsh,
|
||||||
|
BlendDesc: blend,
|
||||||
|
VertexLayout: layout,
|
||||||
|
PixelFormat: format,
|
||||||
|
Topology: driver.TopologyTriangleStrip,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return pipelines, err
|
||||||
|
}
|
||||||
|
if u := uniforms[materialLinearGradient]; u != nil {
|
||||||
|
vertBuffer = newUniformBuffer(b, u)
|
||||||
|
}
|
||||||
|
pipelines[i][materialLinearGradient] = &pipeline{pipe, vertBuffer}
|
||||||
}
|
}
|
||||||
pipelines[materialTexture] = &pipeline{pipe, vertBuffer}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var vertBuffer *uniformBuffer
|
|
||||||
fsh, err := b.NewFragmentShader(fsSrc[materialColor])
|
|
||||||
if err != nil {
|
|
||||||
pipelines[materialTexture].Release()
|
|
||||||
return pipelines, err
|
|
||||||
}
|
|
||||||
defer fsh.Release()
|
|
||||||
pipe, err := b.NewPipeline(driver.PipelineDesc{
|
|
||||||
VertexShader: vsh,
|
|
||||||
FragmentShader: fsh,
|
|
||||||
BlendDesc: blend,
|
|
||||||
VertexLayout: layout,
|
|
||||||
PixelFormat: driver.TextureFormatOutput,
|
|
||||||
Topology: driver.TopologyTriangleStrip,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
pipelines[materialTexture].Release()
|
|
||||||
return pipelines, err
|
|
||||||
}
|
|
||||||
if u := uniforms[materialColor]; u != nil {
|
|
||||||
vertBuffer = newUniformBuffer(b, u)
|
|
||||||
}
|
|
||||||
pipelines[materialColor] = &pipeline{pipe, vertBuffer}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var vertBuffer *uniformBuffer
|
|
||||||
fsh, err := b.NewFragmentShader(fsSrc[materialLinearGradient])
|
|
||||||
if err != nil {
|
|
||||||
pipelines[materialTexture].Release()
|
|
||||||
pipelines[materialColor].Release()
|
|
||||||
return pipelines, err
|
|
||||||
}
|
|
||||||
defer fsh.Release()
|
|
||||||
pipe, err := b.NewPipeline(driver.PipelineDesc{
|
|
||||||
VertexShader: vsh,
|
|
||||||
FragmentShader: fsh,
|
|
||||||
BlendDesc: blend,
|
|
||||||
VertexLayout: layout,
|
|
||||||
PixelFormat: driver.TextureFormatOutput,
|
|
||||||
Topology: driver.TopologyTriangleStrip,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
pipelines[materialTexture].Release()
|
|
||||||
pipelines[materialColor].Release()
|
|
||||||
return pipelines, err
|
|
||||||
}
|
|
||||||
if u := uniforms[materialLinearGradient]; u != nil {
|
|
||||||
vertBuffer = newUniformBuffer(b, u)
|
|
||||||
}
|
|
||||||
pipelines[materialLinearGradient] = &pipeline{pipe, vertBuffer}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
for _, p := range pipelines {
|
|
||||||
p.Release()
|
|
||||||
}
|
|
||||||
return pipelines, err
|
|
||||||
}
|
}
|
||||||
return pipelines, nil
|
return pipelines, nil
|
||||||
}
|
}
|
||||||
@@ -821,7 +823,7 @@ func (r *renderer) packLayers(layers []opacityLayer) []opacityLayer {
|
|||||||
layers[l.parent].clip = b.Union(l.clip)
|
layers[l.parent].clip = b.Union(l.clip)
|
||||||
}
|
}
|
||||||
if l.clip.Empty() {
|
if l.clip.Empty() {
|
||||||
layers = append(layers[:i], layers[i+1:]...)
|
layers = slices.Delete(layers, i, i+1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Pack layers.
|
// Pack layers.
|
||||||
@@ -865,12 +867,12 @@ func (r *renderer) drawLayers(layers []opacityLayer, ops []imageOp) {
|
|||||||
Min: l.place.Pos,
|
Min: l.place.Pos,
|
||||||
Max: l.place.Pos.Add(l.clip.Size()),
|
Max: l.place.Pos.Add(l.clip.Size()),
|
||||||
}
|
}
|
||||||
r.ctx.Viewport(v.Min.X, v.Min.Y, v.Max.X, v.Max.Y)
|
r.ctx.Viewport(v.Min.X, v.Min.Y, v.Dx(), v.Dy())
|
||||||
f := r.layerFBOs.fbos[fbo]
|
f := r.layerFBOs.fbos[fbo]
|
||||||
r.drawOps(true, l.clip.Min.Mul(-1), l.clip.Size(), ops[l.opStart:l.opEnd])
|
r.drawOps(true, l.clip.Min.Mul(-1), l.clip.Size(), ops[l.opStart:l.opEnd])
|
||||||
sr := f32.FRect(v)
|
sr := f32.FRect(v)
|
||||||
uvScale, uvOffset := texSpaceTransform(sr, f.size)
|
uvScale, uvOffset := texSpaceTransform(sr, f.size)
|
||||||
uvTrans := f32.Affine2D{}.Scale(f32.Point{}, uvScale).Offset(uvOffset)
|
uvTrans := f32.AffineId().Scale(f32.Point{}, uvScale).Offset(uvOffset)
|
||||||
// Replace layer ops with one textured op.
|
// Replace layer ops with one textured op.
|
||||||
ops[l.opStart] = imageOp{
|
ops[l.opStart] = imageOp{
|
||||||
clip: l.clip,
|
clip: l.clip,
|
||||||
@@ -930,7 +932,7 @@ func (d *drawOps) newPathOp() *pathOp {
|
|||||||
return &d.pathOpCache[len(d.pathOpCache)-1]
|
return &d.pathOpCache[len(d.pathOpCache)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *drawOps) addClipPath(state *drawState, aux []byte, auxKey opKey, bounds f32.Rectangle, off f32.Point, push bool) {
|
func (d *drawOps) addClipPath(state *drawState, aux []byte, auxKey opKey, bounds f32.Rectangle, off f32.Point) {
|
||||||
npath := d.newPathOp()
|
npath := d.newPathOp()
|
||||||
*npath = pathOp{
|
*npath = pathOp{
|
||||||
parent: state.cpath,
|
parent: state.cpath,
|
||||||
@@ -955,7 +957,9 @@ func (d *drawOps) addClipPath(state *drawState, aux []byte, auxKey opKey, bounds
|
|||||||
|
|
||||||
func (d *drawOps) save(id int, state f32.Affine2D) {
|
func (d *drawOps) save(id int, state f32.Affine2D) {
|
||||||
if extra := id - len(d.states) + 1; extra > 0 {
|
if extra := id - len(d.states) + 1; extra > 0 {
|
||||||
d.states = append(d.states, make([]f32.Affine2D, extra)...)
|
for range extra {
|
||||||
|
d.states = append(d.states, f32.AffineId())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
d.states[id] = state
|
d.states[id] = state
|
||||||
}
|
}
|
||||||
@@ -970,12 +974,13 @@ func (k opKey) SetTransform(t f32.Affine2D) opKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *drawOps) collectOps(r *ops.Reader, viewport f32.Rectangle) {
|
func (d *drawOps) collectOps(r *ops.Reader, viewport f32.Rectangle) {
|
||||||
var (
|
var quads quadsOp
|
||||||
quads quadsOp
|
state := drawState{
|
||||||
state drawState
|
t: f32.AffineId(),
|
||||||
)
|
}
|
||||||
reset := func() {
|
reset := func() {
|
||||||
state = drawState{
|
state = drawState{
|
||||||
|
t: f32.AffineId(),
|
||||||
color: color.NRGBA{A: 0xff},
|
color: color.NRGBA{A: 0xff},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1031,7 +1036,7 @@ loop:
|
|||||||
op.Decode(encOp.Data)
|
op.Decode(encOp.Data)
|
||||||
quads.key.outline = op.Outline
|
quads.key.outline = op.Outline
|
||||||
bounds := f32.FRect(op.Bounds)
|
bounds := f32.FRect(op.Bounds)
|
||||||
trans, off := state.t.Split()
|
trans, off := transformOffset(state.t)
|
||||||
if len(quads.aux) > 0 {
|
if len(quads.aux) > 0 {
|
||||||
// There is a clipping path, build the gpu data and update the
|
// There is a clipping path, build the gpu data and update the
|
||||||
// cache key such that it will be equal only if the transform is the
|
// cache key such that it will be equal only if the transform is the
|
||||||
@@ -1054,8 +1059,9 @@ loop:
|
|||||||
} else {
|
} else {
|
||||||
quads.aux, bounds, _ = d.boundsForTransformedRect(bounds, trans)
|
quads.aux, bounds, _ = d.boundsForTransformedRect(bounds, trans)
|
||||||
quads.key = opKey{Key: encOp.Key}
|
quads.key = opKey{Key: encOp.Key}
|
||||||
|
quads.key = quads.key.SetTransform(trans)
|
||||||
}
|
}
|
||||||
d.addClipPath(&state, quads.aux, quads.key, bounds, off, true)
|
d.addClipPath(&state, quads.aux, quads.key, bounds, off)
|
||||||
quads = quadsOp{}
|
quads = quadsOp{}
|
||||||
case ops.TypePopClip:
|
case ops.TypePopClip:
|
||||||
state.cpath = state.cpath.parent
|
state.cpath = state.cpath.parent
|
||||||
@@ -1077,7 +1083,7 @@ loop:
|
|||||||
// Transform (if needed) the painting rectangle and if so generate a clip path,
|
// Transform (if needed) the painting rectangle and if so generate a clip path,
|
||||||
// for those cases also compute a partialTrans that maps texture coordinates between
|
// for those cases also compute a partialTrans that maps texture coordinates between
|
||||||
// the new bounding rectangle and the transformed original paint rectangle.
|
// the new bounding rectangle and the transformed original paint rectangle.
|
||||||
t, off := state.t.Split()
|
t, off := transformOffset(state.t)
|
||||||
// Fill the clip area, unless the material is a (bounded) image.
|
// Fill the clip area, unless the material is a (bounded) image.
|
||||||
// TODO: Find a tighter bound.
|
// TODO: Find a tighter bound.
|
||||||
inf := float32(1e6)
|
inf := float32(1e6)
|
||||||
@@ -1099,8 +1105,8 @@ loop:
|
|||||||
// The paint operation is sheared or rotated, add a clip path representing
|
// The paint operation is sheared or rotated, add a clip path representing
|
||||||
// this transformed rectangle.
|
// this transformed rectangle.
|
||||||
k := opKey{Key: encOp.Key}
|
k := opKey{Key: encOp.Key}
|
||||||
k.SetTransform(t) // TODO: This call has no effect.
|
k = k.SetTransform(t)
|
||||||
d.addClipPath(&state, clipData, k, bnd, off, false)
|
d.addClipPath(&state, clipData, k, bnd, off)
|
||||||
}
|
}
|
||||||
|
|
||||||
bounds := cl.Round()
|
bounds := cl.Round()
|
||||||
@@ -1160,6 +1166,7 @@ func expandPathOp(p *pathOp, clip image.Rectangle) {
|
|||||||
func (d *drawState) materialFor(rect f32.Rectangle, off f32.Point, partTrans f32.Affine2D, clip image.Rectangle) material {
|
func (d *drawState) materialFor(rect f32.Rectangle, off f32.Point, partTrans f32.Affine2D, clip image.Rectangle) material {
|
||||||
m := material{
|
m := material{
|
||||||
opacity: 1.,
|
opacity: 1.,
|
||||||
|
uvTrans: f32.AffineId(),
|
||||||
}
|
}
|
||||||
switch d.matType {
|
switch d.matType {
|
||||||
case materialColor:
|
case materialColor:
|
||||||
@@ -1193,7 +1200,7 @@ func (d *drawState) materialFor(rect f32.Rectangle, off f32.Point, partTrans f32
|
|||||||
sr.Min.Y += float32(clip.Min.Y-dr.Min.Y) * sdy / dy
|
sr.Min.Y += float32(clip.Min.Y-dr.Min.Y) * sdy / dy
|
||||||
sr.Max.Y -= float32(dr.Max.Y-clip.Max.Y) * sdy / dy
|
sr.Max.Y -= float32(dr.Max.Y-clip.Max.Y) * sdy / dy
|
||||||
uvScale, uvOffset := texSpaceTransform(sr, sz)
|
uvScale, uvOffset := texSpaceTransform(sr, sz)
|
||||||
m.uvTrans = partTrans.Mul(f32.Affine2D{}.Scale(f32.Point{}, uvScale).Offset(uvOffset))
|
m.uvTrans = partTrans.Mul(f32.AffineId().Scale(f32.Point{}, uvScale).Offset(uvOffset))
|
||||||
m.data = d.image
|
m.data = d.image
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
@@ -1230,7 +1237,7 @@ func (r *renderer) prepareDrawOps(ops []imageOp) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderer) drawOps(isFBO bool, opOff image.Point, viewport image.Point, ops []imageOp) {
|
func (r *renderer) drawOps(isFBO bool, opOff, viewport image.Point, ops []imageOp) {
|
||||||
var coverTex driver.Texture
|
var coverTex driver.Texture
|
||||||
for i := 0; i < len(ops); i++ {
|
for i := 0; i < len(ops); i++ {
|
||||||
img := ops[i]
|
img := ops[i]
|
||||||
@@ -1244,9 +1251,13 @@ func (r *renderer) drawOps(isFBO bool, opOff image.Point, viewport image.Point,
|
|||||||
|
|
||||||
scale, off := clipSpaceTransform(drc, viewport)
|
scale, off := clipSpaceTransform(drc, viewport)
|
||||||
var fbo FBO
|
var fbo FBO
|
||||||
|
fboIdx := 0
|
||||||
|
if isFBO {
|
||||||
|
fboIdx = 1
|
||||||
|
}
|
||||||
switch img.clipType {
|
switch img.clipType {
|
||||||
case clipTypeNone:
|
case clipTypeNone:
|
||||||
p := r.blitter.pipelines[m.material]
|
p := r.blitter.pipelines[fboIdx][m.material]
|
||||||
r.ctx.BindPipeline(p.pipeline)
|
r.ctx.BindPipeline(p.pipeline)
|
||||||
r.ctx.BindVertexBuffer(r.blitter.quadVerts, 0)
|
r.ctx.BindVertexBuffer(r.blitter.quadVerts, 0)
|
||||||
r.blitter.blit(m.material, isFBO, m.color, m.color1, m.color2, scale, off, m.opacity, m.uvTrans)
|
r.blitter.blit(m.material, isFBO, m.color, m.color1, m.color2, scale, off, m.opacity, m.uvTrans)
|
||||||
@@ -1265,7 +1276,7 @@ func (r *renderer) drawOps(isFBO bool, opOff image.Point, viewport image.Point,
|
|||||||
Max: img.place.Pos.Add(drc.Size()),
|
Max: img.place.Pos.Add(drc.Size()),
|
||||||
}
|
}
|
||||||
coverScale, coverOff := texSpaceTransform(f32.FRect(uv), fbo.size)
|
coverScale, coverOff := texSpaceTransform(f32.FRect(uv), fbo.size)
|
||||||
p := r.pather.coverer.pipelines[m.material]
|
p := r.pather.coverer.pipelines[fboIdx][m.material]
|
||||||
r.ctx.BindPipeline(p.pipeline)
|
r.ctx.BindPipeline(p.pipeline)
|
||||||
r.ctx.BindVertexBuffer(r.blitter.quadVerts, 0)
|
r.ctx.BindVertexBuffer(r.blitter.quadVerts, 0)
|
||||||
r.pather.cover(m.material, isFBO, m.color, m.color1, m.color2, scale, off, m.uvTrans, coverScale, coverOff)
|
r.pather.cover(m.material, isFBO, m.color, m.color1, m.color2, scale, off, m.uvTrans, coverScale, coverOff)
|
||||||
@@ -1273,7 +1284,11 @@ func (r *renderer) drawOps(isFBO bool, opOff image.Point, viewport image.Point,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *blitter) blit(mat materialType, fbo bool, col f32color.RGBA, col1, col2 f32color.RGBA, scale, off f32.Point, opacity float32, uvTrans f32.Affine2D) {
|
func (b *blitter) blit(mat materialType, fbo bool, col f32color.RGBA, col1, col2 f32color.RGBA, scale, off f32.Point, opacity float32, uvTrans f32.Affine2D) {
|
||||||
p := b.pipelines[mat]
|
fboIdx := 0
|
||||||
|
if fbo {
|
||||||
|
fboIdx = 1
|
||||||
|
}
|
||||||
|
p := b.pipelines[fboIdx][mat]
|
||||||
b.ctx.BindPipeline(p.pipeline)
|
b.ctx.BindPipeline(p.pipeline)
|
||||||
var uniforms *blitUniforms
|
var uniforms *blitUniforms
|
||||||
switch mat {
|
switch mat {
|
||||||
@@ -1306,7 +1321,7 @@ func (b *blitter) blit(mat materialType, fbo bool, col f32color.RGBA, col1, col2
|
|||||||
|
|
||||||
// newUniformBuffer creates a new GPU uniform buffer backed by the
|
// newUniformBuffer creates a new GPU uniform buffer backed by the
|
||||||
// structure uniformBlock points to.
|
// structure uniformBlock points to.
|
||||||
func newUniformBuffer(b driver.Device, uniformBlock interface{}) *uniformBuffer {
|
func newUniformBuffer(b driver.Device, uniformBlock any) *uniformBuffer {
|
||||||
ref := reflect.ValueOf(uniformBlock)
|
ref := reflect.ValueOf(uniformBlock)
|
||||||
// Determine the size of the uniforms structure, *uniforms.
|
// Determine the size of the uniforms structure, *uniforms.
|
||||||
size := ref.Elem().Type().Size()
|
size := ref.Elem().Type().Size()
|
||||||
@@ -1360,7 +1375,7 @@ func gradientSpaceTransform(clip image.Rectangle, off f32.Point, stop1, stop2 f3
|
|||||||
|
|
||||||
// TODO: optimize
|
// TODO: optimize
|
||||||
zp := f32.Point{}
|
zp := f32.Point{}
|
||||||
return f32.Affine2D{}.
|
return f32.AffineId().
|
||||||
Scale(zp, layout.FPt(clip.Size())). // scale to pixel space
|
Scale(zp, layout.FPt(clip.Size())). // scale to pixel space
|
||||||
Offset(zp.Sub(off).Add(layout.FPt(clip.Min))). // offset to clip space
|
Offset(zp.Sub(off).Add(layout.FPt(clip.Min))). // offset to clip space
|
||||||
Offset(zp.Sub(stop1)). // offset to first stop point
|
Offset(zp.Sub(stop1)). // offset to first stop point
|
||||||
@@ -1474,7 +1489,7 @@ func (d *drawOps) buildVerts(pathData []byte, tr f32.Affine2D, outline bool, str
|
|||||||
// as needed and feeds them to the supplied splitter.
|
// as needed and feeds them to the supplied splitter.
|
||||||
func decodeToOutlineQuads(qs *quadSplitter, tr f32.Affine2D, pathData []byte) {
|
func decodeToOutlineQuads(qs *quadSplitter, tr f32.Affine2D, pathData []byte) {
|
||||||
for len(pathData) >= scene.CommandSize+4 {
|
for len(pathData) >= scene.CommandSize+4 {
|
||||||
qs.contour = bo.Uint32(pathData)
|
qs.contour = binary.LittleEndian.Uint32(pathData)
|
||||||
cmd := ops.DecodeCommand(pathData[4:])
|
cmd := ops.DecodeCommand(pathData[4:])
|
||||||
switch cmd.Op() {
|
switch cmd.Op() {
|
||||||
case scene.OpLine:
|
case scene.OpLine:
|
||||||
@@ -1510,12 +1525,10 @@ func decodeToOutlineQuads(qs *quadSplitter, tr f32.Affine2D, pathData []byte) {
|
|||||||
|
|
||||||
// create GPU vertices for transformed r, find the bounds and establish texture transform.
|
// create GPU vertices for transformed r, find the bounds and establish texture transform.
|
||||||
func (d *drawOps) boundsForTransformedRect(r f32.Rectangle, tr f32.Affine2D) (aux []byte, bnd f32.Rectangle, ptr f32.Affine2D) {
|
func (d *drawOps) boundsForTransformedRect(r f32.Rectangle, tr f32.Affine2D) (aux []byte, bnd f32.Rectangle, ptr f32.Affine2D) {
|
||||||
if isPureOffset(tr) {
|
ptr = f32.AffineId()
|
||||||
// fast-path to allow blitting of pure rectangles
|
if tr == f32.AffineId() {
|
||||||
_, _, ox, _, _, oy := tr.Elems()
|
// fast-path to allow blitting of pure rectangles.
|
||||||
off := f32.Pt(ox, oy)
|
bnd = r
|
||||||
bnd.Min = r.Min.Add(off)
|
|
||||||
bnd.Max = r.Max.Add(off)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1562,10 +1575,29 @@ func (d *drawOps) boundsForTransformedRect(r f32.Rectangle, tr f32.Affine2D) (au
|
|||||||
sx, sy := P2.X-P3.X, P2.Y-P3.Y
|
sx, sy := P2.X-P3.X, P2.Y-P3.Y
|
||||||
ptr = f32.NewAffine2D(sx, P2.X-P1.X, P1.X-sx, sy, P2.Y-P1.Y, P1.Y-sy).Invert()
|
ptr = f32.NewAffine2D(sx, P2.X-P1.X, P1.X-sx, sy, P2.Y-P1.Y, P1.Y-sy).Invert()
|
||||||
|
|
||||||
return
|
return aux, bnd, ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPureOffset(t f32.Affine2D) bool {
|
// transformOffset a transform into two parts, one which is pure integer offset
|
||||||
a, b, _, d, e, _ := t.Elems()
|
// and the other representing the scaling, shearing and rotation and fractional
|
||||||
return a == 1 && b == 0 && d == 0 && e == 1
|
// offset.
|
||||||
|
func transformOffset(t f32.Affine2D) (f32.Affine2D, f32.Point) {
|
||||||
|
sx, hx, ox, hy, sy, oy := t.Elems()
|
||||||
|
iox, fox := math.Modf(float64(ox))
|
||||||
|
ioy, foy := math.Modf(float64(oy))
|
||||||
|
ft := f32.NewAffine2D(sx, hx, float32(fox), hy, sy, float32(foy))
|
||||||
|
ip := f32.Pt(float32(iox), float32(ioy))
|
||||||
|
return ft, ip
|
||||||
|
}
|
||||||
|
|
||||||
|
func newShaders(ctx driver.Device, vsrc, fsrc shader.Sources) (vert driver.VertexShader, frag driver.FragmentShader, err error) {
|
||||||
|
vert, err = ctx.NewVertexShader(vsrc)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
frag, err = ctx.NewFragmentShader(fsrc)
|
||||||
|
if err != nil {
|
||||||
|
vert.Release()
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ import (
|
|||||||
|
|
||||||
var dumpImages = flag.Bool("saveimages", false, "save test images")
|
var dumpImages = flag.Bool("saveimages", false, "save test images")
|
||||||
|
|
||||||
var clearCol = color.NRGBA{A: 0xff, R: 0xde, G: 0xad, B: 0xbe}
|
var (
|
||||||
var clearColExpect = f32color.NRGBAToRGBA(clearCol)
|
clearCol = color.NRGBA{A: 0xff, R: 0xde, G: 0xad, B: 0xbe}
|
||||||
|
clearColExpect = f32color.NRGBAToRGBA(clearCol)
|
||||||
|
)
|
||||||
|
|
||||||
func TestFramebufferClear(t *testing.T) {
|
func TestFramebufferClear(t *testing.T) {
|
||||||
b := newDriver(t)
|
b := newDriver(t)
|
||||||
@@ -202,5 +204,5 @@ func saveImage(file string, img image.Image) error {
|
|||||||
if err := png.Encode(&buf, img); err != nil {
|
if err := png.Encode(&buf, img); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return os.WriteFile(file, buf.Bytes(), 0666)
|
return os.WriteFile(file, buf.Bytes(), 0o666)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
//go:build linux || freebsd || openbsd
|
//go:build linux || freebsd || openbsd
|
||||||
// +build linux freebsd openbsd
|
|
||||||
|
|
||||||
package headless
|
package headless
|
||||||
|
|
||||||
|
|||||||
@@ -152,9 +152,7 @@ func newDirect3D11Device(api driver.Direct3D11) (driver.Device, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backend) BeginFrame(target driver.RenderTarget, clear bool, viewport image.Point) driver.Texture {
|
func (b *Backend) BeginFrame(target driver.RenderTarget, clear bool, viewport image.Point) driver.Texture {
|
||||||
var (
|
var renderTarget *d3d11.RenderTargetView
|
||||||
renderTarget *d3d11.RenderTargetView
|
|
||||||
)
|
|
||||||
if target != nil {
|
if target != nil {
|
||||||
switch t := target.(type) {
|
switch t := target.(type) {
|
||||||
case driver.Direct3D11RenderTarget:
|
case driver.Direct3D11RenderTarget:
|
||||||
@@ -229,10 +227,7 @@ func (b *Backend) NewTexture(format driver.TextureFormat, width, height int, min
|
|||||||
// Flags required by ID3D11DeviceContext::GenerateMips.
|
// Flags required by ID3D11DeviceContext::GenerateMips.
|
||||||
bindFlags |= d3d11.BIND_SHADER_RESOURCE | d3d11.BIND_RENDER_TARGET
|
bindFlags |= d3d11.BIND_SHADER_RESOURCE | d3d11.BIND_RENDER_TARGET
|
||||||
miscFlags |= d3d11.RESOURCE_MISC_GENERATE_MIPS
|
miscFlags |= d3d11.RESOURCE_MISC_GENERATE_MIPS
|
||||||
dim := width
|
dim := max(height, width)
|
||||||
if height > dim {
|
|
||||||
dim = height
|
|
||||||
}
|
|
||||||
log2 := 32 - bits.LeadingZeros32(uint32(dim)) - 1
|
log2 := 32 - bits.LeadingZeros32(uint32(dim)) - 1
|
||||||
nmipmaps = log2 + 1
|
nmipmaps = log2 + 1
|
||||||
}
|
}
|
||||||
@@ -802,7 +797,7 @@ func (t *Texture) ReadPixels(src image.Rectangle, pixels []byte, stride int) err
|
|||||||
mapSize := dstPitch * h
|
mapSize := dstPitch * h
|
||||||
data := sliceOf(resMap.PData, mapSize)
|
data := sliceOf(resMap.PData, mapSize)
|
||||||
width := w * 4
|
width := w * 4
|
||||||
for r := 0; r < h; r++ {
|
for r := range h {
|
||||||
pixels := pixels[r*srcPitch:]
|
pixels := pixels[r*srcPitch:]
|
||||||
copy(pixels[:width], data[r*dstPitch:])
|
copy(pixels[:width], data[r*dstPitch:])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,8 +96,10 @@ type BlendFactor uint8
|
|||||||
|
|
||||||
type Topology uint8
|
type Topology uint8
|
||||||
|
|
||||||
type TextureFilter uint8
|
type (
|
||||||
type TextureFormat uint8
|
TextureFilter uint8
|
||||||
|
TextureFormat uint8
|
||||||
|
)
|
||||||
|
|
||||||
type BufferBinding uint8
|
type BufferBinding uint8
|
||||||
|
|
||||||
@@ -217,7 +219,7 @@ func flipImageY(stride, height int, pixels []byte) {
|
|||||||
// Flip image in y-direction. OpenGL's origin is in the lower
|
// Flip image in y-direction. OpenGL's origin is in the lower
|
||||||
// left corner.
|
// left corner.
|
||||||
row := make([]uint8, stride)
|
row := make([]uint8, stride)
|
||||||
for y := 0; y < height/2; y++ {
|
for y := range height / 2 {
|
||||||
y1 := height - y - 1
|
y1 := height - y - 1
|
||||||
dest := y1 * stride
|
dest := y1 * stride
|
||||||
src := y * stride
|
src := y * stride
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@@ -717,10 +718,7 @@ func (b *Backend) NewTexture(format driver.TextureFormat, width, height int, min
|
|||||||
if mipmap {
|
if mipmap {
|
||||||
nmipmaps := 1
|
nmipmaps := 1
|
||||||
if mipmap {
|
if mipmap {
|
||||||
dim := width
|
dim := max(height, width)
|
||||||
if height > dim {
|
|
||||||
dim = height
|
|
||||||
}
|
|
||||||
log2 := 32 - bits.LeadingZeros32(uint32(dim)) - 1
|
log2 := 32 - bits.LeadingZeros32(uint32(dim)) - 1
|
||||||
nmipmaps = log2 + 1
|
nmipmaps = log2 + 1
|
||||||
}
|
}
|
||||||
@@ -1132,7 +1130,7 @@ func (b *Backend) setupVertexArrays() {
|
|||||||
enabled[inp.Location] = true
|
enabled[inp.Location] = true
|
||||||
b.glstate.vertexAttribPointer(b.funcs, buf.obj, inp.Location, l.Size, gltyp, false, p.layout.Stride, buf.offset+l.Offset)
|
b.glstate.vertexAttribPointer(b.funcs, buf.obj, inp.Location, l.Size, gltyp, false, p.layout.Stride, buf.offset+l.Offset)
|
||||||
}
|
}
|
||||||
for i := 0; i < max; i++ {
|
for i := range max {
|
||||||
b.glstate.setVertexAttribArray(b.funcs, i, enabled[i])
|
b.glstate.setVertexAttribArray(b.funcs, i, enabled[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1175,7 +1173,7 @@ func (t *texture) ReadPixels(src image.Rectangle, pixels []byte, stride int) err
|
|||||||
} else {
|
} else {
|
||||||
tmp := make([]byte, w*h*4)
|
tmp := make([]byte, w*h*4)
|
||||||
t.backend.funcs.ReadPixels(src.Min.X, src.Min.Y, w, h, gl.RGBA, gl.UNSIGNED_BYTE, tmp)
|
t.backend.funcs.ReadPixels(src.Min.X, src.Min.Y, w, h, gl.RGBA, gl.UNSIGNED_BYTE, tmp)
|
||||||
for y := 0; y < h; y++ {
|
for y := range h {
|
||||||
copy(pixels[y*stride:], tmp[y*w*4:])
|
copy(pixels[y*stride:], tmp[y*w*4:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1357,12 +1355,7 @@ func alphaTripleFor(ver [2]int) textureTriple {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hasExtension(exts []string, ext string) bool {
|
func hasExtension(exts []string, ext string) bool {
|
||||||
for _, e := range exts {
|
return slices.Contains(exts, ext)
|
||||||
if ext == e {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func firstBufferType(typ driver.BufferBinding) gl.Enum {
|
func firstBufferType(typ driver.BufferBinding) gl.Enum {
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ func BenchmarkDrawUICached(b *testing.B) {
|
|||||||
defer w.Release()
|
defer w.Release()
|
||||||
drawCore(gtx, th)
|
drawCore(gtx, th)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
}
|
}
|
||||||
finishBenchmark(b, w)
|
finishBenchmark(b, w)
|
||||||
@@ -83,12 +83,12 @@ func BenchmarkDrawUI(b *testing.B) {
|
|||||||
drawCore(gtx, th)
|
drawCore(gtx, th)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; b.Loop(); i++ {
|
||||||
resetOps(gtx)
|
resetOps(gtx)
|
||||||
|
|
||||||
off := float32(math.Mod(float64(i)/10, 10))
|
off := float32(math.Mod(float64(i)/10, 10))
|
||||||
t := op.Affine(f32.Affine2D{}.Offset(f32.Pt(off, off))).Push(gtx.Ops)
|
t := op.Affine(f32.AffineId().Offset(f32.Pt(off, off))).Push(gtx.Ops)
|
||||||
|
|
||||||
drawCore(gtx, th)
|
drawCore(gtx, th)
|
||||||
|
|
||||||
@@ -105,12 +105,12 @@ func BenchmarkDrawUITransformed(b *testing.B) {
|
|||||||
drawCore(gtx, th)
|
drawCore(gtx, th)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; b.Loop(); i++ {
|
||||||
resetOps(gtx)
|
resetOps(gtx)
|
||||||
|
|
||||||
angle := float32(math.Mod(float64(i)/1000, 0.05))
|
angle := float32(math.Mod(float64(i)/1000, 0.05))
|
||||||
a := f32.Affine2D{}.Shear(f32.Point{}, angle, angle).Rotate(f32.Point{}, angle)
|
a := f32.AffineId().Shear(f32.Point{}, angle, angle).Rotate(f32.Point{}, angle)
|
||||||
t := op.Affine(a).Push(gtx.Ops)
|
t := op.Affine(a).Push(gtx.Ops)
|
||||||
|
|
||||||
drawCore(gtx, th)
|
drawCore(gtx, th)
|
||||||
@@ -130,8 +130,8 @@ func Benchmark1000Circles(b *testing.B) {
|
|||||||
draw1000Circles(gtx)
|
draw1000Circles(gtx)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
resetOps(gtx)
|
resetOps(gtx)
|
||||||
draw1000Circles(gtx)
|
draw1000Circles(gtx)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
@@ -147,8 +147,8 @@ func Benchmark1000CirclesInstanced(b *testing.B) {
|
|||||||
draw1000CirclesInstanced(gtx)
|
draw1000CirclesInstanced(gtx)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
resetOps(gtx)
|
resetOps(gtx)
|
||||||
draw1000CirclesInstanced(gtx)
|
draw1000CirclesInstanced(gtx)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
@@ -158,9 +158,9 @@ func Benchmark1000CirclesInstanced(b *testing.B) {
|
|||||||
|
|
||||||
func draw1000Circles(gtx layout.Context) {
|
func draw1000Circles(gtx layout.Context) {
|
||||||
ops := gtx.Ops
|
ops := gtx.Ops
|
||||||
for x := 0; x < 100; x++ {
|
for x := range 100 {
|
||||||
op.Offset(image.Pt(x*10, 0)).Add(ops)
|
op.Offset(image.Pt(x*10, 0)).Add(ops)
|
||||||
for y := 0; y < 10; y++ {
|
for y := range 10 {
|
||||||
paint.FillShape(ops,
|
paint.FillShape(ops,
|
||||||
color.NRGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120},
|
color.NRGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120},
|
||||||
clip.RRect{Rect: image.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Op(ops),
|
clip.RRect{Rect: image.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Op(ops),
|
||||||
@@ -179,9 +179,9 @@ func draw1000CirclesInstanced(gtx layout.Context) {
|
|||||||
cl.Pop()
|
cl.Pop()
|
||||||
c := r.Stop()
|
c := r.Stop()
|
||||||
|
|
||||||
for x := 0; x < 100; x++ {
|
for x := range 100 {
|
||||||
op.Offset(image.Pt(x*10, 0)).Add(ops)
|
op.Offset(image.Pt(x*10, 0)).Add(ops)
|
||||||
for y := 0; y < 10; y++ {
|
for y := range 10 {
|
||||||
paint.ColorOp{Color: color.NRGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
paint.ColorOp{Color: color.NRGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
||||||
c.Add(ops)
|
c.Add(ops)
|
||||||
op.Offset(image.Pt(0, 100)).Add(ops)
|
op.Offset(image.Pt(0, 100)).Add(ops)
|
||||||
@@ -204,9 +204,9 @@ func drawIndividualShapes(gtx layout.Context, th *material.Theme) chan op.CallOp
|
|||||||
go func() {
|
go func() {
|
||||||
ops := &op1
|
ops := &op1
|
||||||
c := op.Record(ops)
|
c := op.Record(ops)
|
||||||
for x := 0; x < 9; x++ {
|
for x := range 9 {
|
||||||
op.Offset(image.Pt(x*50, 0)).Add(ops)
|
op.Offset(image.Pt(x*50, 0)).Add(ops)
|
||||||
for y := 0; y < 9; y++ {
|
for y := range 9 {
|
||||||
paint.FillShape(ops,
|
paint.FillShape(ops,
|
||||||
color.NRGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120},
|
color.NRGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120},
|
||||||
clip.RRect{Rect: image.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Op(ops),
|
clip.RRect{Rect: image.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Op(ops),
|
||||||
@@ -233,8 +233,8 @@ func drawShapeInstances(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
|||||||
|
|
||||||
squares.Add(ops)
|
squares.Add(ops)
|
||||||
rad := float32(0)
|
rad := float32(0)
|
||||||
for x := 0; x < 20; x++ {
|
for x := range 20 {
|
||||||
for y := 0; y < 20; y++ {
|
for y := range 20 {
|
||||||
t := op.Offset(image.Pt(x*50+25, y*50+25)).Push(ops)
|
t := op.Offset(image.Pt(x*50+25, y*50+25)).Push(ops)
|
||||||
c.Add(ops)
|
c.Add(ops)
|
||||||
t.Pop()
|
t.Pop()
|
||||||
@@ -253,7 +253,7 @@ func drawText(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
|||||||
c := op.Record(ops)
|
c := op.Record(ops)
|
||||||
|
|
||||||
txt := material.H6(th, "")
|
txt := material.H6(th, "")
|
||||||
for x := 0; x < 40; x++ {
|
for x := range 40 {
|
||||||
txt.Text = textRows[x]
|
txt.Text = textRows[x]
|
||||||
t := op.Offset(image.Pt(0, 24*x)).Push(ops)
|
t := op.Offset(image.Pt(0, 24*x)).Push(ops)
|
||||||
gtx.Ops = ops
|
gtx.Ops = ops
|
||||||
|
|||||||
@@ -40,6 +40,25 @@ func TestPaintClippedRect(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPaintClippedRectOffset(t *testing.T) {
|
||||||
|
run(t, func(o *op.Ops) {
|
||||||
|
defer op.Affine(f32.AffineId().Offset(f32.Pt(0.5, 0.5))).Push(o).Pop()
|
||||||
|
defer clip.RRect{Rect: image.Rect(25, 25, 60, 60)}.Push(o).Pop()
|
||||||
|
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 50, 50)).Op())
|
||||||
|
}, func(r result) {
|
||||||
|
r.expect(0, 0, transparent)
|
||||||
|
r.expect(24, 35, transparent)
|
||||||
|
r.expect(24, 24, transparent)
|
||||||
|
r.expect(25, 25, color.RGBA{R: 137, A: 64})
|
||||||
|
r.expect(25, 35, color.RGBA{R: 187, A: 128})
|
||||||
|
r.expect(35, 25, color.RGBA{R: 187, A: 128})
|
||||||
|
r.expect(50, 50, color.RGBA{R: 137, A: 64})
|
||||||
|
r.expect(51, 51, transparent)
|
||||||
|
r.expect(50, 0, transparent)
|
||||||
|
r.expect(10, 50, transparent)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestPaintClippedCircle(t *testing.T) {
|
func TestPaintClippedCircle(t *testing.T) {
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
const r = 10
|
const r = 10
|
||||||
@@ -132,8 +151,7 @@ func TestTexturedStrokeClipped(t *testing.T) {
|
|||||||
defer clip.RRect{Rect: image.Rect(-30, -30, 60, 60)}.Push(o).Pop()
|
defer clip.RRect{Rect: image.Rect(-30, -30, 60, 60)}.Push(o).Pop()
|
||||||
defer op.Offset(image.Pt(-10, -10)).Push(o).Pop()
|
defer op.Offset(image.Pt(-10, -10)).Push(o).Pop()
|
||||||
paint.PaintOp{}.Add(o)
|
paint.PaintOp{}.Add(o)
|
||||||
}, func(r result) {
|
}, nil)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTexturedStroke(t *testing.T) {
|
func TestTexturedStroke(t *testing.T) {
|
||||||
@@ -146,8 +164,7 @@ func TestTexturedStroke(t *testing.T) {
|
|||||||
}.Op().Push(o).Pop()
|
}.Op().Push(o).Pop()
|
||||||
defer op.Offset(image.Pt(-10, -10)).Push(o).Pop()
|
defer op.Offset(image.Pt(-10, -10)).Push(o).Pop()
|
||||||
paint.PaintOp{}.Add(o)
|
paint.PaintOp{}.Add(o)
|
||||||
}, func(r result) {
|
}, nil)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPaintClippedTexture(t *testing.T) {
|
func TestPaintClippedTexture(t *testing.T) {
|
||||||
@@ -178,7 +195,6 @@ func TestStrokedPathZeroWidth(t *testing.T) {
|
|||||||
paint.Fill(o, red)
|
paint.Fill(o, red)
|
||||||
cl.Pop()
|
cl.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
}, func(r result) {
|
}, func(r result) {
|
||||||
r.expect(0, 0, transparent)
|
r.expect(0, 0, transparent)
|
||||||
r.expect(10, 50, colornames.Black)
|
r.expect(10, 50, colornames.Black)
|
||||||
@@ -252,8 +268,7 @@ func TestPathReuse(t *testing.T) {
|
|||||||
stroke := clip.Stroke{Path: spec, Width: 3}.Op().Push(o)
|
stroke := clip.Stroke{Path: spec, Width: 3}.Op().Push(o)
|
||||||
paint.Fill(o, color.NRGBA{B: 0xFF, A: 0xFF})
|
paint.Fill(o, color.NRGBA{B: 0xFF, A: 0xFF})
|
||||||
stroke.Pop()
|
stroke.Pop()
|
||||||
}, func(r result) {
|
}, nil)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPathInterleave(t *testing.T) {
|
func TestPathInterleave(t *testing.T) {
|
||||||
@@ -290,6 +305,22 @@ func TestStrokedRect(t *testing.T) {
|
|||||||
Width: 5,
|
Width: 5,
|
||||||
}.Op(),
|
}.Op(),
|
||||||
)
|
)
|
||||||
}, func(r result) {
|
}, nil)
|
||||||
})
|
}
|
||||||
|
|
||||||
|
func TestInstancedRects(t *testing.T) {
|
||||||
|
run(t, func(o *op.Ops) {
|
||||||
|
macro := op.Record(o)
|
||||||
|
clip := clip.Rect{Max: image.Pt(20, 20)}.Push(o)
|
||||||
|
paint.ColorOp{Color: color.NRGBA{R: 0x80, A: 0xFF}}.Add(o)
|
||||||
|
paint.PaintOp{}.Add(o)
|
||||||
|
clip.Pop()
|
||||||
|
c := macro.Stop()
|
||||||
|
|
||||||
|
for range 2 {
|
||||||
|
op.Affine(f32.AffineId().Rotate(f32.Pt(0, 0), .2)).Add(o)
|
||||||
|
c.Add(o)
|
||||||
|
op.Offset(image.Pt(20, 20)).Add(o)
|
||||||
|
}
|
||||||
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 787 B |
Binary file not shown.
|
Before Width: | Height: | Size: 334 B After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 435 B |
@@ -24,7 +24,6 @@ func TestTransformMacro(t *testing.T) {
|
|||||||
c := constSqPath()
|
c := constSqPath()
|
||||||
|
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
|
|
||||||
// render the first Stacked item
|
// render the first Stacked item
|
||||||
m1 := op.Record(o)
|
m1 := op.Record(o)
|
||||||
dr := image.Rect(0, 0, 128, 50)
|
dr := image.Rect(0, 0, 128, 50)
|
||||||
@@ -88,10 +87,10 @@ func TestNoClipFromPaint(t *testing.T) {
|
|||||||
// ensure that a paint operation does not pollute the state
|
// ensure that a paint operation does not pollute the state
|
||||||
// by leaving any clip paths in place.
|
// by leaving any clip paths in place.
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
a := f32.Affine2D{}.Rotate(f32.Pt(20, 20), math.Pi/4)
|
a := f32.AffineId().Rotate(f32.Pt(20, 20), math.Pi/4)
|
||||||
defer op.Affine(a).Push(o).Pop()
|
defer op.Affine(a).Push(o).Pop()
|
||||||
paint.FillShape(o, red, clip.Rect(image.Rect(10, 10, 30, 30)).Op())
|
paint.FillShape(o, red, clip.Rect(image.Rect(10, 10, 30, 30)).Op())
|
||||||
a = f32.Affine2D{}.Rotate(f32.Pt(20, 20), -math.Pi/4)
|
a = f32.AffineId().Rotate(f32.Pt(20, 20), -math.Pi/4)
|
||||||
defer op.Affine(a).Push(o).Pop()
|
defer op.Affine(a).Push(o).Pop()
|
||||||
|
|
||||||
paint.FillShape(o, black, clip.Rect(image.Rect(0, 0, 50, 50)).Op())
|
paint.FillShape(o, black, clip.Rect(image.Rect(0, 0, 50, 50)).Op())
|
||||||
@@ -110,7 +109,7 @@ func TestDeferredPaint(t *testing.T) {
|
|||||||
paint.PaintOp{}.Add(o)
|
paint.PaintOp{}.Add(o)
|
||||||
cl.Pop()
|
cl.Pop()
|
||||||
|
|
||||||
t := op.Affine(f32.Affine2D{}.Offset(f32.Pt(20, 20))).Push(o)
|
t := op.Affine(f32.AffineId().Offset(f32.Pt(20, 20))).Push(o)
|
||||||
m := op.Record(o)
|
m := op.Record(o)
|
||||||
cl2 := clip.Rect(image.Rect(0, 0, 80, 80)).Op().Push(o)
|
cl2 := clip.Rect(image.Rect(0, 0, 80, 80)).Op().Push(o)
|
||||||
paint.ColorOp{Color: color.NRGBA{A: 0x60, R: 0xff, G: 0xff}}.Add(o)
|
paint.ColorOp{Color: color.NRGBA{A: 0x60, R: 0xff, G: 0xff}}.Add(o)
|
||||||
@@ -120,12 +119,11 @@ func TestDeferredPaint(t *testing.T) {
|
|||||||
op.Defer(o, paintMacro)
|
op.Defer(o, paintMacro)
|
||||||
t.Pop()
|
t.Pop()
|
||||||
|
|
||||||
defer op.Affine(f32.Affine2D{}.Offset(f32.Pt(10, 10))).Push(o).Pop()
|
defer op.Affine(f32.AffineId().Offset(f32.Pt(10, 10))).Push(o).Pop()
|
||||||
defer clip.Rect(image.Rect(0, 0, 80, 80)).Op().Push(o).Pop()
|
defer clip.Rect(image.Rect(0, 0, 80, 80)).Op().Push(o).Pop()
|
||||||
paint.ColorOp{Color: color.NRGBA{A: 0x60, B: 0xff}}.Add(o)
|
paint.ColorOp{Color: color.NRGBA{A: 0x60, B: 0xff}}.Add(o)
|
||||||
paint.PaintOp{}.Add(o)
|
paint.PaintOp{}.Add(o)
|
||||||
}, func(r result) {
|
}, nil)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func constSqPath() clip.Op {
|
func constSqPath() clip.Op {
|
||||||
@@ -143,8 +141,10 @@ func constSqPath() clip.Op {
|
|||||||
|
|
||||||
func constSqCirc() clip.Op {
|
func constSqCirc() clip.Op {
|
||||||
innerOps := new(op.Ops)
|
innerOps := new(op.Ops)
|
||||||
return clip.RRect{Rect: image.Rect(0, 0, 40, 40),
|
return clip.RRect{
|
||||||
NW: 20, NE: 20, SW: 20, SE: 20}.Op(innerOps)
|
Rect: image.Rect(0, 0, 40, 40),
|
||||||
|
NW: 20, NE: 20, SW: 20, SE: 20,
|
||||||
|
}.Op(innerOps)
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawChild(ops *op.Ops, text clip.Op) op.CallOp {
|
func drawChild(ops *op.Ops, text clip.Op) op.CallOp {
|
||||||
@@ -260,7 +260,7 @@ func TestLinearGradient(t *testing.T) {
|
|||||||
Color2: g.To,
|
Color2: g.To,
|
||||||
}.Add(ops)
|
}.Add(ops)
|
||||||
cl := clip.RRect{Rect: gr.Round()}.Push(ops)
|
cl := clip.RRect{Rect: gr.Round()}.Push(ops)
|
||||||
t1 := op.Affine(f32.Affine2D{}.Offset(pixelAligned.Min)).Push(ops)
|
t1 := op.Affine(f32.AffineId().Offset(pixelAligned.Min)).Push(ops)
|
||||||
t2 := scale(pixelAligned.Dx()/128, 1).Push(ops)
|
t2 := scale(pixelAligned.Dx()/128, 1).Push(ops)
|
||||||
paint.PaintOp{}.Add(ops)
|
paint.PaintOp{}.Add(ops)
|
||||||
t2.Pop()
|
t2.Pop()
|
||||||
@@ -323,7 +323,7 @@ func TestLinearGradientAngled(t *testing.T) {
|
|||||||
cl = clip.Rect(image.Rect(0, 64, 64, 128)).Push(ops)
|
cl = clip.Rect(image.Rect(0, 64, 64, 128)).Push(ops)
|
||||||
paint.PaintOp{}.Add(ops)
|
paint.PaintOp{}.Add(ops)
|
||||||
cl.Pop()
|
cl.Pop()
|
||||||
}, func(r result) {})
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestZeroImage(t *testing.T) {
|
func TestZeroImage(t *testing.T) {
|
||||||
@@ -363,7 +363,7 @@ func TestImageRGBA_ScaleLinear(t *testing.T) {
|
|||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
w := newWindow(t, 128, 128)
|
w := newWindow(t, 128, 128)
|
||||||
defer clip.Rect{Max: image.Pt(128, 128)}.Push(o).Pop()
|
defer clip.Rect{Max: image.Pt(128, 128)}.Push(o).Pop()
|
||||||
op.Affine(f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(64, 64))).Add(o)
|
op.Affine(f32.AffineId().Scale(f32.Point{}, f32.Pt(64, 64))).Add(o)
|
||||||
|
|
||||||
im := image.NewRGBA(image.Rect(0, 0, 2, 2))
|
im := image.NewRGBA(image.Rect(0, 0, 2, 2))
|
||||||
im.Set(0, 0, colornames.Red)
|
im.Set(0, 0, colornames.Red)
|
||||||
@@ -397,7 +397,7 @@ func TestImageRGBA_ScaleLinear(t *testing.T) {
|
|||||||
func TestImageRGBA_ScaleNearest(t *testing.T) {
|
func TestImageRGBA_ScaleNearest(t *testing.T) {
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
w := newWindow(t, 128, 128)
|
w := newWindow(t, 128, 128)
|
||||||
op.Affine(f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(64, 64))).Add(o)
|
op.Affine(f32.AffineId().Scale(f32.Point{}, f32.Pt(64, 64))).Add(o)
|
||||||
|
|
||||||
im := image.NewRGBA(image.Rect(0, 0, 2, 2))
|
im := image.NewRGBA(image.Rect(0, 0, 2, 2))
|
||||||
im.Set(0, 0, colornames.Red)
|
im.Set(0, 0, colornames.Red)
|
||||||
@@ -483,17 +483,16 @@ func TestGapsInPath(t *testing.T) {
|
|||||||
func TestOpacity(t *testing.T) {
|
func TestOpacity(t *testing.T) {
|
||||||
run(t, func(ops *op.Ops) {
|
run(t, func(ops *op.Ops) {
|
||||||
opc1 := paint.PushOpacity(ops, .3)
|
opc1 := paint.PushOpacity(ops, .3)
|
||||||
// Fill screen to exercize the glClear optimization.
|
// Fill screen to exercise the glClear optimization.
|
||||||
paint.FillShape(ops, color.NRGBA{R: 255, A: 255}, clip.Rect{Max: image.Pt(1024, 1024)}.Op())
|
paint.FillShape(ops, color.NRGBA{R: 255, A: 255}, clip.Rect{Max: image.Pt(1024, 1024)}.Op())
|
||||||
opc2 := paint.PushOpacity(ops, .6)
|
opc2 := paint.PushOpacity(ops, .6)
|
||||||
paint.FillShape(ops, color.NRGBA{G: 255, A: 255}, clip.Rect{Min: image.Pt(20, 10), Max: image.Pt(64, 128)}.Op())
|
paint.FillShape(ops, color.NRGBA{G: 255, A: 255}, clip.Rect{Min: image.Pt(20, 10), Max: image.Pt(64, 128)}.Op())
|
||||||
opc2.Pop()
|
opc2.Pop()
|
||||||
opc1.Pop()
|
opc1.Pop()
|
||||||
opc3 := paint.PushOpacity(ops, .6)
|
opc3 := paint.PushOpacity(ops, .6)
|
||||||
paint.FillShape(ops, color.NRGBA{G: 255, A: 255}, clip.Rect{Min: image.Pt(50+20, 10), Max: image.Pt(50+64, 128)}.Op())
|
paint.FillShape(ops, color.NRGBA{B: 255, A: 255}, clip.Ellipse(image.Rectangle{Min: image.Pt(20+20, 10), Max: image.Pt(50+64, 128)}).Op(ops))
|
||||||
opc3.Pop()
|
opc3.Pop()
|
||||||
}, func(r result) {
|
}, nil)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// lerp calculates linear interpolation with color b and p.
|
// lerp calculates linear interpolation with color b and p.
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func TestPaintOffset(t *testing.T) {
|
|||||||
|
|
||||||
func TestPaintRotate(t *testing.T) {
|
func TestPaintRotate(t *testing.T) {
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
a := f32.Affine2D{}.Rotate(f32.Pt(40, 40), -math.Pi/8)
|
a := f32.AffineId().Rotate(f32.Pt(40, 40), -math.Pi/8)
|
||||||
defer op.Affine(a).Push(o).Pop()
|
defer op.Affine(a).Push(o).Pop()
|
||||||
paint.FillShape(o, red, clip.Rect(image.Rect(20, 20, 60, 60)).Op())
|
paint.FillShape(o, red, clip.Rect(image.Rect(20, 20, 60, 60)).Op())
|
||||||
}, func(r result) {
|
}, func(r result) {
|
||||||
@@ -42,7 +42,7 @@ func TestPaintRotate(t *testing.T) {
|
|||||||
|
|
||||||
func TestPaintShear(t *testing.T) {
|
func TestPaintShear(t *testing.T) {
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
a := f32.Affine2D{}.Shear(f32.Point{}, math.Pi/4, 0)
|
a := f32.AffineId().Shear(f32.Point{}, math.Pi/4, 0)
|
||||||
defer op.Affine(a).Push(o).Pop()
|
defer op.Affine(a).Push(o).Pop()
|
||||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 40, 40)).Op())
|
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 40, 40)).Op())
|
||||||
}, func(r result) {
|
}, func(r result) {
|
||||||
@@ -79,7 +79,7 @@ func TestClipOffset(t *testing.T) {
|
|||||||
|
|
||||||
func TestClipScale(t *testing.T) {
|
func TestClipScale(t *testing.T) {
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
a := f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(2, 2)).Offset(f32.Pt(10, 10))
|
a := f32.AffineId().Scale(f32.Point{}, f32.Pt(2, 2)).Offset(f32.Pt(10, 10))
|
||||||
defer op.Affine(a).Push(o).Pop()
|
defer op.Affine(a).Push(o).Pop()
|
||||||
defer clip.RRect{Rect: image.Rect(10, 10, 20, 20)}.Push(o).Pop()
|
defer clip.RRect{Rect: image.Rect(10, 10, 20, 20)}.Push(o).Pop()
|
||||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 1000, 1000)).Op())
|
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 1000, 1000)).Op())
|
||||||
@@ -93,7 +93,7 @@ func TestClipScale(t *testing.T) {
|
|||||||
|
|
||||||
func TestClipRotate(t *testing.T) {
|
func TestClipRotate(t *testing.T) {
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
defer op.Affine(f32.Affine2D{}.Rotate(f32.Pt(40, 40), -math.Pi/4)).Push(o).Pop()
|
defer op.Affine(f32.AffineId().Rotate(f32.Pt(40, 40), -math.Pi/4)).Push(o).Pop()
|
||||||
defer clip.RRect{Rect: image.Rect(30, 30, 50, 50)}.Push(o).Pop()
|
defer clip.RRect{Rect: image.Rect(30, 30, 50, 50)}.Push(o).Pop()
|
||||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 40, 100, 100)).Op())
|
paint.FillShape(o, red, clip.Rect(image.Rect(0, 40, 100, 100)).Op())
|
||||||
}, func(r result) {
|
}, func(r result) {
|
||||||
@@ -121,7 +121,7 @@ func TestOffsetScaleTexture(t *testing.T) {
|
|||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
defer op.Offset(image.Pt(15, 15)).Push(o).Pop()
|
defer op.Offset(image.Pt(15, 15)).Push(o).Pop()
|
||||||
squares.Add(o)
|
squares.Add(o)
|
||||||
defer op.Affine(f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(2, 1))).Push(o).Pop()
|
defer op.Affine(f32.AffineId().Scale(f32.Point{}, f32.Pt(2, 1))).Push(o).Pop()
|
||||||
defer scale(50.0/512, 50.0/512).Push(o).Pop()
|
defer scale(50.0/512, 50.0/512).Push(o).Pop()
|
||||||
paint.PaintOp{}.Add(o)
|
paint.PaintOp{}.Add(o)
|
||||||
}, func(r result) {
|
}, func(r result) {
|
||||||
@@ -133,7 +133,7 @@ func TestOffsetScaleTexture(t *testing.T) {
|
|||||||
func TestRotateTexture(t *testing.T) {
|
func TestRotateTexture(t *testing.T) {
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
squares.Add(o)
|
squares.Add(o)
|
||||||
a := f32.Affine2D{}.Offset(f32.Pt(30, 30)).Rotate(f32.Pt(40, 40), math.Pi/4)
|
a := f32.AffineId().Offset(f32.Pt(30, 30)).Rotate(f32.Pt(40, 40), math.Pi/4)
|
||||||
defer op.Affine(a).Push(o).Pop()
|
defer op.Affine(a).Push(o).Pop()
|
||||||
defer scale(20.0/512, 20.0/512).Push(o).Pop()
|
defer scale(20.0/512, 20.0/512).Push(o).Pop()
|
||||||
paint.PaintOp{}.Add(o)
|
paint.PaintOp{}.Add(o)
|
||||||
@@ -146,10 +146,10 @@ func TestRotateTexture(t *testing.T) {
|
|||||||
func TestRotateClipTexture(t *testing.T) {
|
func TestRotateClipTexture(t *testing.T) {
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
squares.Add(o)
|
squares.Add(o)
|
||||||
a := f32.Affine2D{}.Rotate(f32.Pt(40, 40), math.Pi/8)
|
a := f32.AffineId().Rotate(f32.Pt(40, 40), math.Pi/8)
|
||||||
defer op.Affine(a).Push(o).Pop()
|
defer op.Affine(a).Push(o).Pop()
|
||||||
defer clip.RRect{Rect: image.Rect(30, 30, 50, 50)}.Push(o).Pop()
|
defer clip.RRect{Rect: image.Rect(30, 30, 50, 50)}.Push(o).Pop()
|
||||||
defer op.Affine(f32.Affine2D{}.Offset(f32.Pt(10, 10))).Push(o).Pop()
|
defer op.Affine(f32.AffineId().Offset(f32.Pt(10, 10))).Push(o).Pop()
|
||||||
defer scale(60.0/512, 60.0/512).Push(o).Pop()
|
defer scale(60.0/512, 60.0/512).Push(o).Pop()
|
||||||
paint.PaintOp{}.Add(o)
|
paint.PaintOp{}.Add(o)
|
||||||
}, func(r result) {
|
}, func(r result) {
|
||||||
@@ -168,7 +168,7 @@ func TestComplicatedTransform(t *testing.T) {
|
|||||||
|
|
||||||
defer clip.RRect{Rect: image.Rect(0, 0, 100, 100), SE: 50, SW: 50, NW: 50, NE: 50}.Push(o).Pop()
|
defer clip.RRect{Rect: image.Rect(0, 0, 100, 100), SE: 50, SW: 50, NW: 50, NE: 50}.Push(o).Pop()
|
||||||
|
|
||||||
a := f32.Affine2D{}.Shear(f32.Point{}, math.Pi/4, 0)
|
a := f32.AffineId().Shear(f32.Point{}, math.Pi/4, 0)
|
||||||
defer op.Affine(a).Push(o).Pop()
|
defer op.Affine(a).Push(o).Pop()
|
||||||
defer clip.RRect{Rect: image.Rect(0, 0, 50, 40)}.Push(o).Pop()
|
defer clip.RRect{Rect: image.Rect(0, 0, 50, 40)}.Push(o).Pop()
|
||||||
|
|
||||||
@@ -182,13 +182,13 @@ func TestComplicatedTransform(t *testing.T) {
|
|||||||
func TestTransformOrder(t *testing.T) {
|
func TestTransformOrder(t *testing.T) {
|
||||||
// check the ordering of operations bot in affine and in gpu stack.
|
// check the ordering of operations bot in affine and in gpu stack.
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
a := f32.Affine2D{}.Offset(f32.Pt(64, 64))
|
a := f32.AffineId().Offset(f32.Pt(64, 64))
|
||||||
defer op.Affine(a).Push(o).Pop()
|
defer op.Affine(a).Push(o).Pop()
|
||||||
|
|
||||||
b := f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(8, 8))
|
b := f32.AffineId().Scale(f32.Point{}, f32.Pt(8, 8))
|
||||||
defer op.Affine(b).Push(o).Pop()
|
defer op.Affine(b).Push(o).Pop()
|
||||||
|
|
||||||
c := f32.Affine2D{}.Offset(f32.Pt(-10, -10)).Scale(f32.Point{}, f32.Pt(0.5, 0.5))
|
c := f32.AffineId().Offset(f32.Pt(-10, -10)).Scale(f32.Point{}, f32.Pt(0.5, 0.5))
|
||||||
defer op.Affine(c).Push(o).Pop()
|
defer op.Affine(c).Push(o).Pop()
|
||||||
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 20, 20)).Op())
|
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 20, 20)).Op())
|
||||||
}, func(r result) {
|
}, func(r result) {
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ func buildSquares(size int) paint.ImageOp {
|
|||||||
sub := size / 4
|
sub := size / 4
|
||||||
im := image.NewNRGBA(image.Rect(0, 0, size, size))
|
im := image.NewNRGBA(image.Rect(0, 0, size, size))
|
||||||
c1, c2 := image.NewUniform(colornames.Green), image.NewUniform(colornames.Blue)
|
c1, c2 := image.NewUniform(colornames.Green), image.NewUniform(colornames.Blue)
|
||||||
for r := 0; r < 4; r++ {
|
for r := range 4 {
|
||||||
for c := 0; c < 4; c++ {
|
for c := range 4 {
|
||||||
c1, c2 = c2, c1
|
c1, c2 = c2, c1
|
||||||
draw.Draw(im, image.Rect(r*sub, c*sub, r*sub+sub, c*sub+sub), c1, image.Point{}, draw.Over)
|
draw.Draw(im, image.Rect(r*sub, c*sub, r*sub+sub, c*sub+sub), c1, image.Point{}, draw.Over)
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ func run(t *testing.T, f func(o *op.Ops), c func(r result)) {
|
|||||||
var img *image.RGBA
|
var img *image.RGBA
|
||||||
var err error
|
var err error
|
||||||
ops := new(op.Ops)
|
ops := new(op.Ops)
|
||||||
for i := 0; i < 3; i++ {
|
for i := range 3 {
|
||||||
ops.Reset()
|
ops.Reset()
|
||||||
img, err = drawImage(t, 128, ops, f)
|
img, err = drawImage(t, 128, ops, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -90,7 +90,9 @@ func run(t *testing.T, f func(o *op.Ops), c func(r result)) {
|
|||||||
name := fmt.Sprintf("%s-%d-bad.png", t.Name(), i)
|
name := fmt.Sprintf("%s-%d-bad.png", t.Name(), i)
|
||||||
saveImage(t, name, img)
|
saveImage(t, name, img)
|
||||||
}
|
}
|
||||||
c(result{t: t, img: img})
|
if c != nil {
|
||||||
|
c(result{t: t, img: img})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +153,7 @@ func verifyRef(t *testing.T, img *image.RGBA, frame int) (ok bool) {
|
|||||||
}
|
}
|
||||||
path = filepath.Join("refs", path+".png")
|
path = filepath.Join("refs", path+".png")
|
||||||
if *dumpImages {
|
if *dumpImages {
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0766); err != nil {
|
if err := os.MkdirAll(filepath.Dir(path), 0o766); err != nil {
|
||||||
if !os.IsExist(err) {
|
if !os.IsExist(err) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@@ -285,7 +287,7 @@ func saveImage(t testing.TB, file string, img *image.RGBA) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(file, buf.Bytes(), 0666); err != nil {
|
if err := os.WriteFile(file, buf.Bytes(), 0o666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -300,5 +302,5 @@ func newWindow(t testing.TB, width, height int) *headless.Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func scale(sx, sy float32) op.TransformOp {
|
func scale(sx, sy float32) op.TransformOp {
|
||||||
return op.Affine(f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(sx, sy)))
|
return op.Affine(f32.AffineId().Scale(f32.Point{}, f32.Pt(sx, sy)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -862,8 +862,8 @@ func (b *Backend) BindUniforms(buffer driver.Buffer) {
|
|||||||
buf := buffer.(*Buffer)
|
buf := buffer.(*Buffer)
|
||||||
cmdBuf := b.currentCmdBuf()
|
cmdBuf := b.currentCmdBuf()
|
||||||
for _, s := range b.pipe.pushRanges {
|
for _, s := range b.pipe.pushRanges {
|
||||||
off := s.Offset()
|
off := vk.PushConstantRangeOffset(s)
|
||||||
vk.CmdPushConstants(cmdBuf, b.pipe.desc.layout, s.StageFlags(), off, buf.store[off:off+s.Size()])
|
vk.CmdPushConstants(cmdBuf, b.pipe.desc.layout, vk.PushConstantRangeStageFlags(s), off, buf.store[off:off+vk.PushConstantRangeSize(s)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -10,10 +10,10 @@ import (
|
|||||||
func BenchmarkPacker(b *testing.B) {
|
func BenchmarkPacker(b *testing.B) {
|
||||||
var p packer
|
var p packer
|
||||||
p.maxDims = image.Point{X: 4096, Y: 4096}
|
p.maxDims = image.Point{X: 4096, Y: 4096}
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; b.Loop(); i++ {
|
||||||
p.clear()
|
p.clear()
|
||||||
p.newPage()
|
p.newPage()
|
||||||
for k := 0; k < 500; k++ {
|
for k := range 500 {
|
||||||
_, ok := p.tryAdd(xy(k))
|
_, ok := p.tryAdd(xy(k))
|
||||||
if !ok {
|
if !ok {
|
||||||
b.Fatal("add failed", i, k, xy(k))
|
b.Fatal("add failed", i, k, xy(k))
|
||||||
|
|||||||
+11
-5
@@ -30,7 +30,7 @@ type pather struct {
|
|||||||
|
|
||||||
type coverer struct {
|
type coverer struct {
|
||||||
ctx driver.Device
|
ctx driver.Device
|
||||||
pipelines [3]*pipeline
|
pipelines [2][3]*pipeline
|
||||||
texUniforms *coverTexUniforms
|
texUniforms *coverTexUniforms
|
||||||
colUniforms *coverColUniforms
|
colUniforms *coverColUniforms
|
||||||
linearGradientUniforms *coverLinearGradientUniforms
|
linearGradientUniforms *coverLinearGradientUniforms
|
||||||
@@ -150,7 +150,7 @@ func newCoverer(ctx driver.Device) *coverer {
|
|||||||
c.texUniforms = new(coverTexUniforms)
|
c.texUniforms = new(coverTexUniforms)
|
||||||
c.linearGradientUniforms = new(coverLinearGradientUniforms)
|
c.linearGradientUniforms = new(coverLinearGradientUniforms)
|
||||||
pipelines, err := createColorPrograms(ctx, gio.Shader_cover_vert, gio.Shader_cover_frag,
|
pipelines, err := createColorPrograms(ctx, gio.Shader_cover_vert, gio.Shader_cover_frag,
|
||||||
[3]interface{}{c.colUniforms, c.linearGradientUniforms, c.texUniforms},
|
[3]any{c.colUniforms, c.linearGradientUniforms, c.texUniforms},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -162,7 +162,7 @@ func newCoverer(ctx driver.Device) *coverer {
|
|||||||
func newStenciler(ctx driver.Device) *stenciler {
|
func newStenciler(ctx driver.Device) *stenciler {
|
||||||
// Allocate a suitably large index buffer for drawing paths.
|
// Allocate a suitably large index buffer for drawing paths.
|
||||||
indices := make([]uint16, pathBatchSize*6)
|
indices := make([]uint16, pathBatchSize*6)
|
||||||
for i := 0; i < pathBatchSize; i++ {
|
for i := range pathBatchSize {
|
||||||
i := uint16(i)
|
i := uint16(i)
|
||||||
indices[i*6+0] = i*4 + 0
|
indices[i*6+0] = i*4 + 0
|
||||||
indices[i*6+1] = i*4 + 1
|
indices[i*6+1] = i*4 + 1
|
||||||
@@ -309,7 +309,9 @@ func (p *pather) release() {
|
|||||||
|
|
||||||
func (c *coverer) release() {
|
func (c *coverer) release() {
|
||||||
for _, p := range c.pipelines {
|
for _, p := range c.pipelines {
|
||||||
p.Release()
|
for _, p := range p {
|
||||||
|
p.Release()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,7 +407,11 @@ func (c *coverer) cover(mat materialType, isFBO bool, col f32color.RGBA, col1, c
|
|||||||
}
|
}
|
||||||
uniforms.transform = [4]float32{scale.X, scale.Y, off.X, off.Y}
|
uniforms.transform = [4]float32{scale.X, scale.Y, off.X, off.Y}
|
||||||
uniforms.uvCoverTransform = [4]float32{coverScale.X, coverScale.Y, coverOff.X, coverOff.Y}
|
uniforms.uvCoverTransform = [4]float32{coverScale.X, coverScale.Y, coverOff.X, coverOff.Y}
|
||||||
c.pipelines[mat].UploadUniforms(c.ctx)
|
fboIdx := 0
|
||||||
|
if isFBO {
|
||||||
|
fboIdx = 1
|
||||||
|
}
|
||||||
|
c.pipelines[fboIdx][mat].UploadUniforms(c.ctx)
|
||||||
c.ctx.DrawArrays(0, 4)
|
c.ctx.DrawArrays(0, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Struct returns a byte slice view of a struct.
|
// Struct returns a byte slice view of a struct.
|
||||||
func Struct(s interface{}) []byte {
|
func Struct(s any) []byte {
|
||||||
v := reflect.ValueOf(s)
|
v := reflect.ValueOf(s)
|
||||||
sz := int(v.Elem().Type().Size())
|
sz := int(v.Elem().Type().Size())
|
||||||
return unsafe.Slice((*byte)(unsafe.Pointer(v.Pointer())), sz)
|
return unsafe.Slice((*byte)(unsafe.Pointer(v.Pointer())), sz)
|
||||||
@@ -27,7 +27,7 @@ func Uint32(s []uint32) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slice returns a byte slice view of a slice.
|
// Slice returns a byte slice view of a slice.
|
||||||
func Slice(s interface{}) []byte {
|
func Slice(s any) []byte {
|
||||||
v := reflect.ValueOf(s)
|
v := reflect.ValueOf(s)
|
||||||
first := v.Index(0)
|
first := v.Index(0)
|
||||||
sz := int(first.Type().Size())
|
sz := int(first.Type().Size())
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func Parse() {
|
|||||||
}
|
}
|
||||||
print := false
|
print := false
|
||||||
silent := false
|
silent := false
|
||||||
for _, part := range strings.Split(val, ",") {
|
for part := range strings.SplitSeq(val, ",") {
|
||||||
switch part {
|
switch part {
|
||||||
case textSubsystem:
|
case textSubsystem:
|
||||||
Text.Store(true)
|
Text.Store(true)
|
||||||
|
|||||||
+6
-13
@@ -9,16 +9,16 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gioui.org/gpu"
|
"gioui.org/gpu"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
disp _EGLDisplay
|
disp _EGLDisplay
|
||||||
eglCtx *eglContext
|
eglCtx *eglContext
|
||||||
eglSurf _EGLSurface
|
eglSurf _EGLSurface
|
||||||
width, height int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type eglContext struct {
|
type eglContext struct {
|
||||||
@@ -121,11 +121,9 @@ func (c *Context) VisualID() int {
|
|||||||
return c.eglCtx.visualID
|
return c.eglCtx.visualID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) CreateSurface(win NativeWindowType, width, height int) error {
|
func (c *Context) CreateSurface(win NativeWindowType) error {
|
||||||
eglSurf, err := createSurface(c.disp, c.eglCtx, win)
|
eglSurf, err := createSurface(c.disp, c.eglCtx, win)
|
||||||
c.eglSurf = eglSurf
|
c.eglSurf = eglSurf
|
||||||
c.width = width
|
|
||||||
c.height = height
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,12 +155,7 @@ func (c *Context) EnableVSync(enable bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hasExtension(exts []string, ext string) bool {
|
func hasExtension(exts []string, ext string) bool {
|
||||||
for _, e := range exts {
|
return slices.Contains(exts, ext)
|
||||||
if ext == e {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createContext(disp _EGLDisplay) (*eglContext, error) {
|
func createContext(disp _EGLDisplay) (*eglContext, error) {
|
||||||
|
|||||||
+51
-33
@@ -9,8 +9,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
syscall "golang.org/x/sys/windows"
|
syscall "golang.org/x/sys/windows"
|
||||||
|
|
||||||
"gioui.org/internal/gl"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -24,51 +22,71 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
libEGL = syscall.NewLazyDLL("libEGL.dll")
|
libEGL = syscall.DLL{}
|
||||||
_eglChooseConfig = libEGL.NewProc("eglChooseConfig")
|
_eglChooseConfig *syscall.Proc
|
||||||
_eglCreateContext = libEGL.NewProc("eglCreateContext")
|
_eglCreateContext *syscall.Proc
|
||||||
_eglCreateWindowSurface = libEGL.NewProc("eglCreateWindowSurface")
|
_eglCreateWindowSurface *syscall.Proc
|
||||||
_eglDestroyContext = libEGL.NewProc("eglDestroyContext")
|
_eglDestroyContext *syscall.Proc
|
||||||
_eglDestroySurface = libEGL.NewProc("eglDestroySurface")
|
_eglDestroySurface *syscall.Proc
|
||||||
_eglGetConfigAttrib = libEGL.NewProc("eglGetConfigAttrib")
|
_eglGetConfigAttrib *syscall.Proc
|
||||||
_eglGetDisplay = libEGL.NewProc("eglGetDisplay")
|
_eglGetDisplay *syscall.Proc
|
||||||
_eglGetError = libEGL.NewProc("eglGetError")
|
_eglGetError *syscall.Proc
|
||||||
_eglInitialize = libEGL.NewProc("eglInitialize")
|
_eglInitialize *syscall.Proc
|
||||||
_eglMakeCurrent = libEGL.NewProc("eglMakeCurrent")
|
_eglMakeCurrent *syscall.Proc
|
||||||
_eglReleaseThread = libEGL.NewProc("eglReleaseThread")
|
_eglReleaseThread *syscall.Proc
|
||||||
_eglSwapInterval = libEGL.NewProc("eglSwapInterval")
|
_eglSwapInterval *syscall.Proc
|
||||||
_eglSwapBuffers = libEGL.NewProc("eglSwapBuffers")
|
_eglSwapBuffers *syscall.Proc
|
||||||
_eglTerminate = libEGL.NewProc("eglTerminate")
|
_eglTerminate *syscall.Proc
|
||||||
_eglQueryString = libEGL.NewProc("eglQueryString")
|
_eglQueryString *syscall.Proc
|
||||||
_eglWaitClient = libEGL.NewProc("eglWaitClient")
|
_eglWaitClient *syscall.Proc
|
||||||
)
|
)
|
||||||
|
|
||||||
var loadOnce sync.Once
|
var loadOnce = sync.OnceValue(loadDLLs)
|
||||||
|
|
||||||
func loadEGL() error {
|
func loadEGL() error {
|
||||||
var err error
|
return loadOnce()
|
||||||
loadOnce.Do(func() {
|
|
||||||
err = loadDLLs()
|
|
||||||
})
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadDLLs() error {
|
func loadDLLs() error {
|
||||||
if err := loadDLL(libEGL, "libEGL.dll"); err != nil {
|
if err := loadDLL(&libEGL, "libEGL.dll"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := loadDLL(gl.LibGLESv2, "libGLESv2.dll"); err != nil {
|
|
||||||
return err
|
procs := map[string]**syscall.Proc{
|
||||||
|
"eglChooseConfig": &_eglChooseConfig,
|
||||||
|
"eglCreateContext": &_eglCreateContext,
|
||||||
|
"eglCreateWindowSurface": &_eglCreateWindowSurface,
|
||||||
|
"eglDestroyContext": &_eglDestroyContext,
|
||||||
|
"eglDestroySurface": &_eglDestroySurface,
|
||||||
|
"eglGetConfigAttrib": &_eglGetConfigAttrib,
|
||||||
|
"eglGetDisplay": &_eglGetDisplay,
|
||||||
|
"eglGetError": &_eglGetError,
|
||||||
|
"eglInitialize": &_eglInitialize,
|
||||||
|
"eglMakeCurrent": &_eglMakeCurrent,
|
||||||
|
"eglReleaseThread": &_eglReleaseThread,
|
||||||
|
"eglSwapInterval": &_eglSwapInterval,
|
||||||
|
"eglSwapBuffers": &_eglSwapBuffers,
|
||||||
|
"eglTerminate": &_eglTerminate,
|
||||||
|
"eglQueryString": &_eglQueryString,
|
||||||
|
"eglWaitClient": &_eglWaitClient,
|
||||||
}
|
}
|
||||||
// d3dcompiler_47.dll is needed internally for shader compilation to function.
|
for name, proc := range procs {
|
||||||
return loadDLL(syscall.NewLazyDLL("d3dcompiler_47.dll"), "d3dcompiler_47.dll")
|
p, err := libEGL.FindProc(name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to locate %s in %s: %w", name, libEGL.Name, err)
|
||||||
|
}
|
||||||
|
*proc = p
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadDLL(dll *syscall.LazyDLL, name string) error {
|
func loadDLL(dll *syscall.DLL, name string) error {
|
||||||
err := dll.Load()
|
handle, err := syscall.LoadLibraryEx(name, 0, syscall.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("egl: failed to load %s: %v", name, err)
|
return fmt.Errorf("egl: failed to load %s: %v", name, err)
|
||||||
}
|
}
|
||||||
|
dll.Handle = handle
|
||||||
|
dll.Name = name
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,6 +182,6 @@ func eglWaitClient() bool {
|
|||||||
|
|
||||||
// issue34474KeepAlive calls runtime.KeepAlive as a
|
// issue34474KeepAlive calls runtime.KeepAlive as a
|
||||||
// workaround for golang.org/issue/34474.
|
// workaround for golang.org/issue/34474.
|
||||||
func issue34474KeepAlive(v interface{}) {
|
func issue34474KeepAlive(v any) {
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ type Affine2D = f32.Affine2D
|
|||||||
|
|
||||||
var NewAffine2D = f32.NewAffine2D
|
var NewAffine2D = f32.NewAffine2D
|
||||||
|
|
||||||
|
var AffineId = f32.AffineId
|
||||||
|
|
||||||
// A Rectangle contains the points (X, Y) where Min.X <= X < Max.X,
|
// A Rectangle contains the points (X, Y) where Min.X <= X < Max.X,
|
||||||
// Min.Y <= Y < Max.Y.
|
// Min.Y <= Y < Max.Y.
|
||||||
type Rectangle struct {
|
type Rectangle struct {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
printf := func(content string, args ...interface{}) {
|
printf := func(content string, args ...any) {
|
||||||
fmt.Fprintf(&b, content, args...)
|
fmt.Fprintf(&b, content, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.WriteFile(*out, data, 0755)
|
err = os.WriteFile(*out, data, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,17 +41,17 @@ var sink RGBA
|
|||||||
|
|
||||||
func BenchmarkLinearFromSRGB(b *testing.B) {
|
func BenchmarkLinearFromSRGB(b *testing.B) {
|
||||||
b.Run("opaque", func(b *testing.B) {
|
b.Run("opaque", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; b.Loop(); i++ {
|
||||||
sink = LinearFromSRGB(color.NRGBA{R: byte(i), G: byte(i >> 8), B: byte(i >> 16), A: 0xFF})
|
sink = LinearFromSRGB(color.NRGBA{R: byte(i), G: byte(i >> 8), B: byte(i >> 16), A: 0xFF})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
b.Run("translucent", func(b *testing.B) {
|
b.Run("translucent", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; b.Loop(); i++ {
|
||||||
sink = LinearFromSRGB(color.NRGBA{R: byte(i), G: byte(i >> 8), B: byte(i >> 16), A: 0x50})
|
sink = LinearFromSRGB(color.NRGBA{R: byte(i), G: byte(i >> 8), B: byte(i >> 16), A: 0x50})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
b.Run("transparent", func(b *testing.B) {
|
b.Run("transparent", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; b.Loop(); i++ {
|
||||||
sink = LinearFromSRGB(color.NRGBA{R: byte(i), G: byte(i >> 8), B: byte(i >> 16), A: 0x00})
|
sink = LinearFromSRGB(color.NRGBA{R: byte(i), G: byte(i >> 8), B: byte(i >> 16), A: 0x00})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ func (e *Extrapolation) Estimate() Estimate {
|
|||||||
first := e.get(0)
|
first := e.get(0)
|
||||||
t := first.t
|
t := first.t
|
||||||
// Walk backwards collecting samples.
|
// Walk backwards collecting samples.
|
||||||
for i := 0; i < len(e.samples); i++ {
|
for i := range e.samples {
|
||||||
p := e.get(-i)
|
p := e.get(-i)
|
||||||
age := first.t - p.t
|
age := first.t - p.t
|
||||||
if age >= maxAge || t-p.t >= maxSampleGap {
|
if age >= maxAge || t-p.t >= maxSampleGap {
|
||||||
@@ -172,9 +172,9 @@ func decomposeQR(A *matrix) (*matrix, *matrix, bool) {
|
|||||||
// https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process
|
// https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process
|
||||||
Q := newMatrix(A.rows, A.cols) // Column-major.
|
Q := newMatrix(A.rows, A.cols) // Column-major.
|
||||||
Rt := newMatrix(A.rows, A.rows) // R transposed, row-major.
|
Rt := newMatrix(A.rows, A.rows) // R transposed, row-major.
|
||||||
for i := 0; i < Q.rows; i++ {
|
for i := range Q.rows {
|
||||||
// Copy A column.
|
// Copy A column.
|
||||||
for j := 0; j < Q.cols; j++ {
|
for j := range Q.cols {
|
||||||
Q.set(i, j, A.get(i, j))
|
Q.set(i, j, A.get(i, j))
|
||||||
}
|
}
|
||||||
// Subtract projections. Note that int the projection
|
// Subtract projections. Note that int the projection
|
||||||
@@ -184,9 +184,9 @@ func decomposeQR(A *matrix) (*matrix, *matrix, bool) {
|
|||||||
// the normalized column e replaces u, where <e, e> = 1:
|
// the normalized column e replaces u, where <e, e> = 1:
|
||||||
//
|
//
|
||||||
// proje a = <e, a>/<e, e> e = <e, a> e
|
// proje a = <e, a>/<e, e> e = <e, a> e
|
||||||
for j := 0; j < i; j++ {
|
for j := range i {
|
||||||
d := dot(Q.col(j), Q.col(i))
|
d := dot(Q.col(j), Q.col(i))
|
||||||
for k := 0; k < Q.cols; k++ {
|
for k := range Q.cols {
|
||||||
Q.set(i, k, Q.get(i, k)-d*Q.get(j, k))
|
Q.set(i, k, Q.get(i, k)-d*Q.get(j, k))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ func decomposeQR(A *matrix) (*matrix, *matrix, bool) {
|
|||||||
return nil, nil, false
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
invNorm := 1 / n
|
invNorm := 1 / n
|
||||||
for j := 0; j < Q.cols; j++ {
|
for j := range Q.cols {
|
||||||
Q.set(i, j, Q.get(i, j)*invNorm)
|
Q.set(i, j, Q.get(i, j)*invNorm)
|
||||||
}
|
}
|
||||||
// Update Rt.
|
// Update Rt.
|
||||||
@@ -261,8 +261,8 @@ func (m *matrix) approxEqual(m2 *matrix) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const epsilon = 0.00001
|
const epsilon = 0.00001
|
||||||
for row := 0; row < m.rows; row++ {
|
for row := range m.rows {
|
||||||
for col := 0; col < m.cols; col++ {
|
for col := range m.cols {
|
||||||
d := m2.get(row, col) - m.get(row, col)
|
d := m2.get(row, col) - m.get(row, col)
|
||||||
if d < -epsilon || d > epsilon {
|
if d < -epsilon || d > epsilon {
|
||||||
return false
|
return false
|
||||||
@@ -278,8 +278,8 @@ func (m *matrix) transpose() *matrix {
|
|||||||
cols: m.rows,
|
cols: m.rows,
|
||||||
data: make([]float32, len(m.data)),
|
data: make([]float32, len(m.data)),
|
||||||
}
|
}
|
||||||
for i := 0; i < m.rows; i++ {
|
for i := range m.rows {
|
||||||
for j := 0; j < m.cols; j++ {
|
for j := range m.cols {
|
||||||
t.set(j, i, m.get(i, j))
|
t.set(j, i, m.get(i, j))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,10 +295,10 @@ func (m *matrix) mul(m2 *matrix) *matrix {
|
|||||||
cols: m2.cols,
|
cols: m2.cols,
|
||||||
data: make([]float32, m.rows*m2.cols),
|
data: make([]float32, m.rows*m2.cols),
|
||||||
}
|
}
|
||||||
for i := 0; i < mm.rows; i++ {
|
for i := range mm.rows {
|
||||||
for j := 0; j < mm.cols; j++ {
|
for j := range mm.cols {
|
||||||
var v float32
|
var v float32
|
||||||
for k := 0; k < m.rows; k++ {
|
for k := range m.rows {
|
||||||
v += m.get(k, j) * m2.get(i, k)
|
v += m.get(k, j) * m2.get(i, k)
|
||||||
}
|
}
|
||||||
mm.set(i, j, v)
|
mm.set(i, j, v)
|
||||||
@@ -309,8 +309,8 @@ func (m *matrix) mul(m2 *matrix) *matrix {
|
|||||||
|
|
||||||
func (m *matrix) String() string {
|
func (m *matrix) String() string {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
for i := 0; i < m.rows; i++ {
|
for i := range m.rows {
|
||||||
for j := 0; j < m.cols; j++ {
|
for j := range m.cols {
|
||||||
v := m.get(i, j)
|
v := m.get(i, j)
|
||||||
b.WriteString(strconv.FormatFloat(float64(v), 'g', -1, 32))
|
b.WriteString(strconv.FormatFloat(float64(v), 'g', -1, 32))
|
||||||
b.WriteString(", ")
|
b.WriteString(", ")
|
||||||
|
|||||||
@@ -247,9 +247,11 @@ func (f *Functions) getExtension(name string) js.Value {
|
|||||||
func (f *Functions) ActiveTexture(t Enum) {
|
func (f *Functions) ActiveTexture(t Enum) {
|
||||||
f._activeTexture.Invoke(int(t))
|
f._activeTexture.Invoke(int(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) AttachShader(p Program, s Shader) {
|
func (f *Functions) AttachShader(p Program, s Shader) {
|
||||||
f._attachShader.Invoke(js.Value(p), js.Value(s))
|
f._attachShader.Invoke(js.Value(p), js.Value(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BeginQuery(target Enum, query Query) {
|
func (f *Functions) BeginQuery(target Enum, query Query) {
|
||||||
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
|
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
|
||||||
f._beginQuery.Invoke(int(target), js.Value(query))
|
f._beginQuery.Invoke(int(target), js.Value(query))
|
||||||
@@ -257,36 +259,47 @@ func (f *Functions) BeginQuery(target Enum, query Query) {
|
|||||||
f.EXT_disjoint_timer_query.Call("beginQueryEXT", int(target), js.Value(query))
|
f.EXT_disjoint_timer_query.Call("beginQueryEXT", int(target), js.Value(query))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BindAttribLocation(p Program, a Attrib, name string) {
|
func (f *Functions) BindAttribLocation(p Program, a Attrib, name string) {
|
||||||
f._bindAttribLocation.Invoke(js.Value(p), int(a), name)
|
f._bindAttribLocation.Invoke(js.Value(p), int(a), name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BindBuffer(target Enum, b Buffer) {
|
func (f *Functions) BindBuffer(target Enum, b Buffer) {
|
||||||
f._bindBuffer.Invoke(int(target), js.Value(b))
|
f._bindBuffer.Invoke(int(target), js.Value(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BindBufferBase(target Enum, index int, b Buffer) {
|
func (f *Functions) BindBufferBase(target Enum, index int, b Buffer) {
|
||||||
f._bindBufferBase.Invoke(int(target), index, js.Value(b))
|
f._bindBufferBase.Invoke(int(target), index, js.Value(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BindFramebuffer(target Enum, fb Framebuffer) {
|
func (f *Functions) BindFramebuffer(target Enum, fb Framebuffer) {
|
||||||
f._bindFramebuffer.Invoke(int(target), js.Value(fb))
|
f._bindFramebuffer.Invoke(int(target), js.Value(fb))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BindRenderbuffer(target Enum, rb Renderbuffer) {
|
func (f *Functions) BindRenderbuffer(target Enum, rb Renderbuffer) {
|
||||||
f._bindRenderbuffer.Invoke(int(target), js.Value(rb))
|
f._bindRenderbuffer.Invoke(int(target), js.Value(rb))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BindTexture(target Enum, t Texture) {
|
func (f *Functions) BindTexture(target Enum, t Texture) {
|
||||||
f._bindTexture.Invoke(int(target), js.Value(t))
|
f._bindTexture.Invoke(int(target), js.Value(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BindImageTexture(unit int, t Texture, level int, layered bool, layer int, access, format Enum) {
|
func (f *Functions) BindImageTexture(unit int, t Texture, level int, layered bool, layer int, access, format Enum) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BindVertexArray(a VertexArray) {
|
func (f *Functions) BindVertexArray(a VertexArray) {
|
||||||
panic("not supported")
|
panic("not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BlendEquation(mode Enum) {
|
func (f *Functions) BlendEquation(mode Enum) {
|
||||||
f._blendEquation.Invoke(int(mode))
|
f._blendEquation.Invoke(int(mode))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BlendFuncSeparate(srcRGB, dstRGB, srcA, dstA Enum) {
|
func (f *Functions) BlendFuncSeparate(srcRGB, dstRGB, srcA, dstA Enum) {
|
||||||
f._blendFunc.Invoke(int(srcRGB), int(dstRGB), int(srcA), int(dstA))
|
f._blendFunc.Invoke(int(srcRGB), int(dstRGB), int(srcA), int(dstA))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BufferData(target Enum, size int, usage Enum, data []byte) {
|
func (f *Functions) BufferData(target Enum, size int, usage Enum, data []byte) {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
f._bufferData.Invoke(int(target), size, int(usage))
|
f._bufferData.Invoke(int(target), size, int(usage))
|
||||||
@@ -297,9 +310,11 @@ func (f *Functions) BufferData(target Enum, size int, usage Enum, data []byte) {
|
|||||||
f._bufferData.Invoke(int(target), f.byteArrayOf(data), int(usage))
|
f._bufferData.Invoke(int(target), f.byteArrayOf(data), int(usage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BufferSubData(target Enum, offset int, src []byte) {
|
func (f *Functions) BufferSubData(target Enum, offset int, src []byte) {
|
||||||
f._bufferSubData.Invoke(int(target), offset, f.byteArrayOf(src))
|
f._bufferSubData.Invoke(int(target), offset, f.byteArrayOf(src))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CheckFramebufferStatus(target Enum) Enum {
|
func (f *Functions) CheckFramebufferStatus(target Enum) Enum {
|
||||||
status := Enum(f._checkFramebufferStatus.Invoke(int(target)).Int())
|
status := Enum(f._checkFramebufferStatus.Invoke(int(target)).Int())
|
||||||
if status != FRAMEBUFFER_COMPLETE && f.Ctx.Call("isContextLost").Bool() {
|
if status != FRAMEBUFFER_COMPLETE && f.Ctx.Call("isContextLost").Bool() {
|
||||||
@@ -308,54 +323,71 @@ func (f *Functions) CheckFramebufferStatus(target Enum) Enum {
|
|||||||
}
|
}
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Clear(mask Enum) {
|
func (f *Functions) Clear(mask Enum) {
|
||||||
f._clear.Invoke(int(mask))
|
f._clear.Invoke(int(mask))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) ClearColor(red, green, blue, alpha float32) {
|
func (f *Functions) ClearColor(red, green, blue, alpha float32) {
|
||||||
f._clearColor.Invoke(red, green, blue, alpha)
|
f._clearColor.Invoke(red, green, blue, alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) ClearDepthf(d float32) {
|
func (f *Functions) ClearDepthf(d float32) {
|
||||||
f._clearDepth.Invoke(d)
|
f._clearDepth.Invoke(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CompileShader(s Shader) {
|
func (f *Functions) CompileShader(s Shader) {
|
||||||
f._compileShader.Invoke(js.Value(s))
|
f._compileShader.Invoke(js.Value(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height int) {
|
func (f *Functions) CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height int) {
|
||||||
f._copyTexSubImage2D.Invoke(int(target), level, xoffset, yoffset, x, y, width, height)
|
f._copyTexSubImage2D.Invoke(int(target), level, xoffset, yoffset, x, y, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CreateBuffer() Buffer {
|
func (f *Functions) CreateBuffer() Buffer {
|
||||||
return Buffer(f._createBuffer.Invoke())
|
return Buffer(f._createBuffer.Invoke())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CreateFramebuffer() Framebuffer {
|
func (f *Functions) CreateFramebuffer() Framebuffer {
|
||||||
return Framebuffer(f._createFramebuffer.Invoke())
|
return Framebuffer(f._createFramebuffer.Invoke())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CreateProgram() Program {
|
func (f *Functions) CreateProgram() Program {
|
||||||
return Program(f._createProgram.Invoke())
|
return Program(f._createProgram.Invoke())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CreateQuery() Query {
|
func (f *Functions) CreateQuery() Query {
|
||||||
return Query(f._createQuery.Invoke())
|
return Query(f._createQuery.Invoke())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CreateRenderbuffer() Renderbuffer {
|
func (f *Functions) CreateRenderbuffer() Renderbuffer {
|
||||||
return Renderbuffer(f._createRenderbuffer.Invoke())
|
return Renderbuffer(f._createRenderbuffer.Invoke())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CreateShader(ty Enum) Shader {
|
func (f *Functions) CreateShader(ty Enum) Shader {
|
||||||
return Shader(f._createShader.Invoke(int(ty)))
|
return Shader(f._createShader.Invoke(int(ty)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CreateTexture() Texture {
|
func (f *Functions) CreateTexture() Texture {
|
||||||
return Texture(f._createTexture.Invoke())
|
return Texture(f._createTexture.Invoke())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CreateVertexArray() VertexArray {
|
func (f *Functions) CreateVertexArray() VertexArray {
|
||||||
panic("not supported")
|
panic("not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteBuffer(v Buffer) {
|
func (f *Functions) DeleteBuffer(v Buffer) {
|
||||||
f._deleteBuffer.Invoke(js.Value(v))
|
f._deleteBuffer.Invoke(js.Value(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteFramebuffer(v Framebuffer) {
|
func (f *Functions) DeleteFramebuffer(v Framebuffer) {
|
||||||
f._deleteFramebuffer.Invoke(js.Value(v))
|
f._deleteFramebuffer.Invoke(js.Value(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteProgram(p Program) {
|
func (f *Functions) DeleteProgram(p Program) {
|
||||||
f._deleteProgram.Invoke(js.Value(p))
|
f._deleteProgram.Invoke(js.Value(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteQuery(query Query) {
|
func (f *Functions) DeleteQuery(query Query) {
|
||||||
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
|
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
|
||||||
f._deleteQuery.Invoke(js.Value(query))
|
f._deleteQuery.Invoke(js.Value(query))
|
||||||
@@ -363,45 +395,59 @@ func (f *Functions) DeleteQuery(query Query) {
|
|||||||
f.EXT_disjoint_timer_query.Call("deleteQueryEXT", js.Value(query))
|
f.EXT_disjoint_timer_query.Call("deleteQueryEXT", js.Value(query))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteShader(s Shader) {
|
func (f *Functions) DeleteShader(s Shader) {
|
||||||
f._deleteShader.Invoke(js.Value(s))
|
f._deleteShader.Invoke(js.Value(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteRenderbuffer(v Renderbuffer) {
|
func (f *Functions) DeleteRenderbuffer(v Renderbuffer) {
|
||||||
f._deleteRenderbuffer.Invoke(js.Value(v))
|
f._deleteRenderbuffer.Invoke(js.Value(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteTexture(v Texture) {
|
func (f *Functions) DeleteTexture(v Texture) {
|
||||||
f._deleteTexture.Invoke(js.Value(v))
|
f._deleteTexture.Invoke(js.Value(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteVertexArray(a VertexArray) {
|
func (f *Functions) DeleteVertexArray(a VertexArray) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DepthFunc(fn Enum) {
|
func (f *Functions) DepthFunc(fn Enum) {
|
||||||
f._depthFunc.Invoke(int(fn))
|
f._depthFunc.Invoke(int(fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DepthMask(mask bool) {
|
func (f *Functions) DepthMask(mask bool) {
|
||||||
f._depthMask.Invoke(mask)
|
f._depthMask.Invoke(mask)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DisableVertexAttribArray(a Attrib) {
|
func (f *Functions) DisableVertexAttribArray(a Attrib) {
|
||||||
f._disableVertexAttribArray.Invoke(int(a))
|
f._disableVertexAttribArray.Invoke(int(a))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Disable(cap Enum) {
|
func (f *Functions) Disable(cap Enum) {
|
||||||
f._disable.Invoke(int(cap))
|
f._disable.Invoke(int(cap))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DrawArrays(mode Enum, first, count int) {
|
func (f *Functions) DrawArrays(mode Enum, first, count int) {
|
||||||
f._drawArrays.Invoke(int(mode), first, count)
|
f._drawArrays.Invoke(int(mode), first, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DrawElements(mode Enum, count int, ty Enum, offset int) {
|
func (f *Functions) DrawElements(mode Enum, count int, ty Enum, offset int) {
|
||||||
f._drawElements.Invoke(int(mode), count, int(ty), offset)
|
f._drawElements.Invoke(int(mode), count, int(ty), offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DispatchCompute(x, y, z int) {
|
func (f *Functions) DispatchCompute(x, y, z int) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Enable(cap Enum) {
|
func (f *Functions) Enable(cap Enum) {
|
||||||
f._enable.Invoke(int(cap))
|
f._enable.Invoke(int(cap))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) EnableVertexAttribArray(a Attrib) {
|
func (f *Functions) EnableVertexAttribArray(a Attrib) {
|
||||||
f._enableVertexAttribArray.Invoke(int(a))
|
f._enableVertexAttribArray.Invoke(int(a))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) EndQuery(target Enum) {
|
func (f *Functions) EndQuery(target Enum) {
|
||||||
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
|
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
|
||||||
f._endQuery.Invoke(int(target))
|
f._endQuery.Invoke(int(target))
|
||||||
@@ -409,28 +455,36 @@ func (f *Functions) EndQuery(target Enum) {
|
|||||||
f.EXT_disjoint_timer_query.Call("endQueryEXT", int(target))
|
f.EXT_disjoint_timer_query.Call("endQueryEXT", int(target))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Finish() {
|
func (f *Functions) Finish() {
|
||||||
f._finish.Invoke()
|
f._finish.Invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Flush() {
|
func (f *Functions) Flush() {
|
||||||
f._flush.Invoke()
|
f._flush.Invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) FramebufferRenderbuffer(target, attachment, renderbuffertarget Enum, renderbuffer Renderbuffer) {
|
func (f *Functions) FramebufferRenderbuffer(target, attachment, renderbuffertarget Enum, renderbuffer Renderbuffer) {
|
||||||
f._framebufferRenderbuffer.Invoke(int(target), int(attachment), int(renderbuffertarget), js.Value(renderbuffer))
|
f._framebufferRenderbuffer.Invoke(int(target), int(attachment), int(renderbuffertarget), js.Value(renderbuffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) FramebufferTexture2D(target, attachment, texTarget Enum, t Texture, level int) {
|
func (f *Functions) FramebufferTexture2D(target, attachment, texTarget Enum, t Texture, level int) {
|
||||||
f._framebufferTexture2D.Invoke(int(target), int(attachment), int(texTarget), js.Value(t), level)
|
f._framebufferTexture2D.Invoke(int(target), int(attachment), int(texTarget), js.Value(t), level)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GenerateMipmap(target Enum) {
|
func (f *Functions) GenerateMipmap(target Enum) {
|
||||||
f._generateMipmap.Invoke(int(target))
|
f._generateMipmap.Invoke(int(target))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetError() Enum {
|
func (f *Functions) GetError() Enum {
|
||||||
// Avoid slow getError calls. See gio#179.
|
// Avoid slow getError calls. See gio#179.
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetRenderbufferParameteri(target, pname Enum) int {
|
func (f *Functions) GetRenderbufferParameteri(target, pname Enum) int {
|
||||||
return paramVal(f._getRenderbufferParameteri.Invoke(int(pname)))
|
return paramVal(f._getRenderbufferParameteri.Invoke(int(pname)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetFramebufferAttachmentParameteri(target, attachment, pname Enum) int {
|
func (f *Functions) GetFramebufferAttachmentParameteri(target, attachment, pname Enum) int {
|
||||||
if !f.isWebGL2 && pname == FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING {
|
if !f.isWebGL2 && pname == FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING {
|
||||||
// FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is only available on WebGL 2
|
// FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is only available on WebGL 2
|
||||||
@@ -438,6 +492,7 @@ func (f *Functions) GetFramebufferAttachmentParameteri(target, attachment, pname
|
|||||||
}
|
}
|
||||||
return paramVal(f._getFramebufferAttachmentParameter.Invoke(int(target), int(attachment), int(pname)))
|
return paramVal(f._getFramebufferAttachmentParameter.Invoke(int(target), int(attachment), int(pname)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetBinding(pname Enum) Object {
|
func (f *Functions) GetBinding(pname Enum) Object {
|
||||||
obj := f._getParameter.Invoke(int(pname))
|
obj := f._getParameter.Invoke(int(pname))
|
||||||
if !obj.Truthy() {
|
if !obj.Truthy() {
|
||||||
@@ -445,6 +500,7 @@ func (f *Functions) GetBinding(pname Enum) Object {
|
|||||||
}
|
}
|
||||||
return Object(obj)
|
return Object(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetBindingi(pname Enum, idx int) Object {
|
func (f *Functions) GetBindingi(pname Enum, idx int) Object {
|
||||||
obj := f._getIndexedParameter.Invoke(int(pname), idx)
|
obj := f._getIndexedParameter.Invoke(int(pname), idx)
|
||||||
if !obj.Truthy() {
|
if !obj.Truthy() {
|
||||||
@@ -452,6 +508,7 @@ func (f *Functions) GetBindingi(pname Enum, idx int) Object {
|
|||||||
}
|
}
|
||||||
return Object(obj)
|
return Object(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetInteger(pname Enum) int {
|
func (f *Functions) GetInteger(pname Enum) int {
|
||||||
if !f.isWebGL2 {
|
if !f.isWebGL2 {
|
||||||
switch pname {
|
switch pname {
|
||||||
@@ -461,9 +518,11 @@ func (f *Functions) GetInteger(pname Enum) int {
|
|||||||
}
|
}
|
||||||
return paramVal(f._getParameter.Invoke(int(pname)))
|
return paramVal(f._getParameter.Invoke(int(pname)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetFloat(pname Enum) float32 {
|
func (f *Functions) GetFloat(pname Enum) float32 {
|
||||||
return float32(f._getParameter.Invoke(int(pname)).Float())
|
return float32(f._getParameter.Invoke(int(pname)).Float())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetInteger4(pname Enum) [4]int {
|
func (f *Functions) GetInteger4(pname Enum) [4]int {
|
||||||
arr := f._getParameter.Invoke(int(pname))
|
arr := f._getParameter.Invoke(int(pname))
|
||||||
var res [4]int
|
var res [4]int
|
||||||
@@ -472,6 +531,7 @@ func (f *Functions) GetInteger4(pname Enum) [4]int {
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetFloat4(pname Enum) [4]float32 {
|
func (f *Functions) GetFloat4(pname Enum) [4]float32 {
|
||||||
arr := f._getParameter.Invoke(int(pname))
|
arr := f._getParameter.Invoke(int(pname))
|
||||||
var res [4]float32
|
var res [4]float32
|
||||||
@@ -480,12 +540,15 @@ func (f *Functions) GetFloat4(pname Enum) [4]float32 {
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetProgrami(p Program, pname Enum) int {
|
func (f *Functions) GetProgrami(p Program, pname Enum) int {
|
||||||
return paramVal(f._getProgramParameter.Invoke(js.Value(p), int(pname)))
|
return paramVal(f._getProgramParameter.Invoke(js.Value(p), int(pname)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetProgramInfoLog(p Program) string {
|
func (f *Functions) GetProgramInfoLog(p Program) string {
|
||||||
return f._getProgramInfoLog.Invoke(js.Value(p)).String()
|
return f._getProgramInfoLog.Invoke(js.Value(p)).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetQueryObjectuiv(query Query, pname Enum) uint {
|
func (f *Functions) GetQueryObjectuiv(query Query, pname Enum) uint {
|
||||||
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
|
if !f.EXT_disjoint_timer_query_webgl2.IsNull() {
|
||||||
return uint(paramVal(f._getQueryParameter.Invoke(js.Value(query), int(pname))))
|
return uint(paramVal(f._getQueryParameter.Invoke(js.Value(query), int(pname))))
|
||||||
@@ -493,12 +556,15 @@ func (f *Functions) GetQueryObjectuiv(query Query, pname Enum) uint {
|
|||||||
return uint(paramVal(f.EXT_disjoint_timer_query.Call("getQueryObjectEXT", js.Value(query), int(pname))))
|
return uint(paramVal(f.EXT_disjoint_timer_query.Call("getQueryObjectEXT", js.Value(query), int(pname))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetShaderi(s Shader, pname Enum) int {
|
func (f *Functions) GetShaderi(s Shader, pname Enum) int {
|
||||||
return paramVal(f._getShaderParameter.Invoke(js.Value(s), int(pname)))
|
return paramVal(f._getShaderParameter.Invoke(js.Value(s), int(pname)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetShaderInfoLog(s Shader) string {
|
func (f *Functions) GetShaderInfoLog(s Shader) string {
|
||||||
return f._getShaderInfoLog.Invoke(js.Value(s)).String()
|
return f._getShaderInfoLog.Invoke(js.Value(s)).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetString(pname Enum) string {
|
func (f *Functions) GetString(pname Enum) string {
|
||||||
switch pname {
|
switch pname {
|
||||||
case EXTENSIONS:
|
case EXTENSIONS:
|
||||||
@@ -512,15 +578,19 @@ func (f *Functions) GetString(pname Enum) string {
|
|||||||
return f._getParameter.Invoke(int(pname)).String()
|
return f._getParameter.Invoke(int(pname)).String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetUniformBlockIndex(p Program, name string) uint {
|
func (f *Functions) GetUniformBlockIndex(p Program, name string) uint {
|
||||||
return uint(paramVal(f._getUniformBlockIndex.Invoke(js.Value(p), name)))
|
return uint(paramVal(f._getUniformBlockIndex.Invoke(js.Value(p), name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetUniformLocation(p Program, name string) Uniform {
|
func (f *Functions) GetUniformLocation(p Program, name string) Uniform {
|
||||||
return Uniform(f._getUniformLocation.Invoke(js.Value(p), name))
|
return Uniform(f._getUniformLocation.Invoke(js.Value(p), name))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetVertexAttrib(index int, pname Enum) int {
|
func (f *Functions) GetVertexAttrib(index int, pname Enum) int {
|
||||||
return paramVal(f._getVertexAttrib.Invoke(index, int(pname)))
|
return paramVal(f._getVertexAttrib.Invoke(index, int(pname)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetVertexAttribBinding(index int, pname Enum) Object {
|
func (f *Functions) GetVertexAttribBinding(index int, pname Enum) Object {
|
||||||
obj := f._getVertexAttrib.Invoke(index, int(pname))
|
obj := f._getVertexAttrib.Invoke(index, int(pname))
|
||||||
if !obj.Truthy() {
|
if !obj.Truthy() {
|
||||||
@@ -528,9 +598,11 @@ func (f *Functions) GetVertexAttribBinding(index int, pname Enum) Object {
|
|||||||
}
|
}
|
||||||
return Object(obj)
|
return Object(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetVertexAttribPointer(index int, pname Enum) uintptr {
|
func (f *Functions) GetVertexAttribPointer(index int, pname Enum) uintptr {
|
||||||
return uintptr(f._getVertexAttribOffset.Invoke(index, int(pname)).Int())
|
return uintptr(f._getVertexAttribOffset.Invoke(index, int(pname)).Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) InvalidateFramebuffer(target, attachment Enum) {
|
func (f *Functions) InvalidateFramebuffer(target, attachment Enum) {
|
||||||
fn := f.Ctx.Get("invalidateFramebuffer")
|
fn := f.Ctx.Get("invalidateFramebuffer")
|
||||||
if !fn.IsUndefined() {
|
if !fn.IsUndefined() {
|
||||||
@@ -541,74 +613,97 @@ func (f *Functions) InvalidateFramebuffer(target, attachment Enum) {
|
|||||||
f._invalidateFramebuffer.Invoke(int(target), f.int32Buf)
|
f._invalidateFramebuffer.Invoke(int(target), f.int32Buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) IsEnabled(cap Enum) bool {
|
func (f *Functions) IsEnabled(cap Enum) bool {
|
||||||
return f._isEnabled.Invoke(int(cap)).Truthy()
|
return f._isEnabled.Invoke(int(cap)).Truthy()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) LinkProgram(p Program) {
|
func (f *Functions) LinkProgram(p Program) {
|
||||||
f._linkProgram.Invoke(js.Value(p))
|
f._linkProgram.Invoke(js.Value(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) PixelStorei(pname Enum, param int) {
|
func (f *Functions) PixelStorei(pname Enum, param int) {
|
||||||
f._pixelStorei.Invoke(int(pname), param)
|
f._pixelStorei.Invoke(int(pname), param)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) MemoryBarrier(barriers Enum) {
|
func (f *Functions) MemoryBarrier(barriers Enum) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) MapBufferRange(target Enum, offset, length int, access Enum) []byte {
|
func (f *Functions) MapBufferRange(target Enum, offset, length int, access Enum) []byte {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) RenderbufferStorage(target, internalformat Enum, width, height int) {
|
func (f *Functions) RenderbufferStorage(target, internalformat Enum, width, height int) {
|
||||||
f._renderbufferStorage.Invoke(int(target), int(internalformat), width, height)
|
f._renderbufferStorage.Invoke(int(target), int(internalformat), width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) ReadPixels(x, y, width, height int, format, ty Enum, data []byte) {
|
func (f *Functions) ReadPixels(x, y, width, height int, format, ty Enum, data []byte) {
|
||||||
ba := f.byteArrayOf(data)
|
ba := f.byteArrayOf(data)
|
||||||
f._readPixels.Invoke(x, y, width, height, int(format), int(ty), ba)
|
f._readPixels.Invoke(x, y, width, height, int(format), int(ty), ba)
|
||||||
js.CopyBytesToGo(data, ba)
|
js.CopyBytesToGo(data, ba)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Scissor(x, y, width, height int32) {
|
func (f *Functions) Scissor(x, y, width, height int32) {
|
||||||
f._scissor.Invoke(x, y, width, height)
|
f._scissor.Invoke(x, y, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) ShaderSource(s Shader, src string) {
|
func (f *Functions) ShaderSource(s Shader, src string) {
|
||||||
f._shaderSource.Invoke(js.Value(s), src)
|
f._shaderSource.Invoke(js.Value(s), src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) TexImage2D(target Enum, level int, internalFormat Enum, width, height int, format, ty Enum) {
|
func (f *Functions) TexImage2D(target Enum, level int, internalFormat Enum, width, height int, format, ty Enum) {
|
||||||
f._texImage2D.Invoke(int(target), int(level), int(internalFormat), int(width), int(height), 0, int(format), int(ty), nil)
|
f._texImage2D.Invoke(int(target), int(level), int(internalFormat), int(width), int(height), 0, int(format), int(ty), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) TexStorage2D(target Enum, levels int, internalFormat Enum, width, height int) {
|
func (f *Functions) TexStorage2D(target Enum, levels int, internalFormat Enum, width, height int) {
|
||||||
f._texStorage2D.Invoke(int(target), levels, int(internalFormat), width, height)
|
f._texStorage2D.Invoke(int(target), levels, int(internalFormat), width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty Enum, data []byte) {
|
func (f *Functions) TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty Enum, data []byte) {
|
||||||
f._texSubImage2D.Invoke(int(target), level, x, y, width, height, int(format), int(ty), f.byteArrayOf(data))
|
f._texSubImage2D.Invoke(int(target), level, x, y, width, height, int(format), int(ty), f.byteArrayOf(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) TexParameteri(target, pname Enum, param int) {
|
func (f *Functions) TexParameteri(target, pname Enum, param int) {
|
||||||
f._texParameteri.Invoke(int(target), int(pname), int(param))
|
f._texParameteri.Invoke(int(target), int(pname), int(param))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) UniformBlockBinding(p Program, uniformBlockIndex uint, uniformBlockBinding uint) {
|
func (f *Functions) UniformBlockBinding(p Program, uniformBlockIndex uint, uniformBlockBinding uint) {
|
||||||
f._uniformBlockBinding.Invoke(js.Value(p), int(uniformBlockIndex), int(uniformBlockBinding))
|
f._uniformBlockBinding.Invoke(js.Value(p), int(uniformBlockIndex), int(uniformBlockBinding))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Uniform1f(dst Uniform, v float32) {
|
func (f *Functions) Uniform1f(dst Uniform, v float32) {
|
||||||
f._uniform1f.Invoke(js.Value(dst), v)
|
f._uniform1f.Invoke(js.Value(dst), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Uniform1i(dst Uniform, v int) {
|
func (f *Functions) Uniform1i(dst Uniform, v int) {
|
||||||
f._uniform1i.Invoke(js.Value(dst), v)
|
f._uniform1i.Invoke(js.Value(dst), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Uniform2f(dst Uniform, v0, v1 float32) {
|
func (f *Functions) Uniform2f(dst Uniform, v0, v1 float32) {
|
||||||
f._uniform2f.Invoke(js.Value(dst), v0, v1)
|
f._uniform2f.Invoke(js.Value(dst), v0, v1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Uniform3f(dst Uniform, v0, v1, v2 float32) {
|
func (f *Functions) Uniform3f(dst Uniform, v0, v1, v2 float32) {
|
||||||
f._uniform3f.Invoke(js.Value(dst), v0, v1, v2)
|
f._uniform3f.Invoke(js.Value(dst), v0, v1, v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Uniform4f(dst Uniform, v0, v1, v2, v3 float32) {
|
func (f *Functions) Uniform4f(dst Uniform, v0, v1, v2, v3 float32) {
|
||||||
f._uniform4f.Invoke(js.Value(dst), v0, v1, v2, v3)
|
f._uniform4f.Invoke(js.Value(dst), v0, v1, v2, v3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) UseProgram(p Program) {
|
func (f *Functions) UseProgram(p Program) {
|
||||||
f._useProgram.Invoke(js.Value(p))
|
f._useProgram.Invoke(js.Value(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) UnmapBuffer(target Enum) bool {
|
func (f *Functions) UnmapBuffer(target Enum) bool {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride, offset int) {
|
func (f *Functions) VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride, offset int) {
|
||||||
f._vertexAttribPointer.Invoke(int(dst), size, int(ty), normalized, stride, offset)
|
f._vertexAttribPointer.Invoke(int(dst), size, int(ty), normalized, stride, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Viewport(x, y, width, height int) {
|
func (f *Functions) Viewport(x, y, width, height int) {
|
||||||
f._viewport.Invoke(x, y, width, height)
|
f._viewport.Invoke(x, y, width, height)
|
||||||
}
|
}
|
||||||
|
|||||||
+306
-91
@@ -3,103 +3,217 @@
|
|||||||
package gl
|
package gl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func loadGLESv2Procs() error {
|
||||||
|
dllName := "libGLESv2.dll"
|
||||||
|
handle, err := windows.LoadLibraryEx(dllName, 0, windows.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("gl: failed to load %s: %v", dllName, err)
|
||||||
|
}
|
||||||
|
gles := windows.DLL{Handle: handle, Name: dllName}
|
||||||
|
// d3dcompiler_47.dll is needed internally for shader compilation to function.
|
||||||
|
dllName = "d3dcompiler_47.dll"
|
||||||
|
_, err = windows.LoadLibraryEx(dllName, 0, windows.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("gl: failed to load %s: %v", dllName, err)
|
||||||
|
}
|
||||||
|
procs := map[string]**windows.Proc{
|
||||||
|
"glActiveTexture": &_glActiveTexture,
|
||||||
|
"glAttachShader": &_glAttachShader,
|
||||||
|
"glBeginQuery": &_glBeginQuery,
|
||||||
|
"glBindAttribLocation": &_glBindAttribLocation,
|
||||||
|
"glBindBuffer": &_glBindBuffer,
|
||||||
|
"glBindBufferBase": &_glBindBufferBase,
|
||||||
|
"glBindFramebuffer": &_glBindFramebuffer,
|
||||||
|
"glBindRenderbuffer": &_glBindRenderbuffer,
|
||||||
|
"glBindTexture": &_glBindTexture,
|
||||||
|
"glBindVertexArray": &_glBindVertexArray,
|
||||||
|
"glBlendEquation": &_glBlendEquation,
|
||||||
|
"glBlendFuncSeparate": &_glBlendFuncSeparate,
|
||||||
|
"glBufferData": &_glBufferData,
|
||||||
|
"glBufferSubData": &_glBufferSubData,
|
||||||
|
"glCheckFramebufferStatus": &_glCheckFramebufferStatus,
|
||||||
|
"glClear": &_glClear,
|
||||||
|
"glClearColor": &_glClearColor,
|
||||||
|
"glClearDepthf": &_glClearDepthf,
|
||||||
|
"glDeleteQueries": &_glDeleteQueries,
|
||||||
|
"glDeleteVertexArrays": &_glDeleteVertexArrays,
|
||||||
|
"glCompileShader": &_glCompileShader,
|
||||||
|
"glCopyTexSubImage2D": &_glCopyTexSubImage2D,
|
||||||
|
"glGenerateMipmap": &_glGenerateMipmap,
|
||||||
|
"glGenBuffers": &_glGenBuffers,
|
||||||
|
"glGenFramebuffers": &_glGenFramebuffers,
|
||||||
|
"glGenVertexArrays": &_glGenVertexArrays,
|
||||||
|
"glGetUniformBlockIndex": &_glGetUniformBlockIndex,
|
||||||
|
"glCreateProgram": &_glCreateProgram,
|
||||||
|
"glGenRenderbuffers": &_glGenRenderbuffers,
|
||||||
|
"glCreateShader": &_glCreateShader,
|
||||||
|
"glGenTextures": &_glGenTextures,
|
||||||
|
"glDeleteBuffers": &_glDeleteBuffers,
|
||||||
|
"glDeleteFramebuffers": &_glDeleteFramebuffers,
|
||||||
|
"glDeleteProgram": &_glDeleteProgram,
|
||||||
|
"glDeleteShader": &_glDeleteShader,
|
||||||
|
"glDeleteRenderbuffers": &_glDeleteRenderbuffers,
|
||||||
|
"glDeleteTextures": &_glDeleteTextures,
|
||||||
|
"glDepthFunc": &_glDepthFunc,
|
||||||
|
"glDepthMask": &_glDepthMask,
|
||||||
|
"glDisableVertexAttribArray": &_glDisableVertexAttribArray,
|
||||||
|
"glDisable": &_glDisable,
|
||||||
|
"glDrawArrays": &_glDrawArrays,
|
||||||
|
"glDrawElements": &_glDrawElements,
|
||||||
|
"glEnable": &_glEnable,
|
||||||
|
"glEnableVertexAttribArray": &_glEnableVertexAttribArray,
|
||||||
|
"glEndQuery": &_glEndQuery,
|
||||||
|
"glFinish": &_glFinish,
|
||||||
|
"glFlush": &_glFlush,
|
||||||
|
"glFramebufferRenderbuffer": &_glFramebufferRenderbuffer,
|
||||||
|
"glFramebufferTexture2D": &_glFramebufferTexture2D,
|
||||||
|
"glGenQueries": &_glGenQueries,
|
||||||
|
"glGetError": &_glGetError,
|
||||||
|
"glGetRenderbufferParameteriv": &_glGetRenderbufferParameteriv,
|
||||||
|
"glGetFloatv": &_glGetFloatv,
|
||||||
|
"glGetFramebufferAttachmentParameteriv": &_glGetFramebufferAttachmentParameteriv,
|
||||||
|
"glGetIntegerv": &_glGetIntegerv,
|
||||||
|
"glGetIntegeri_v": &_glGetIntegeri_v,
|
||||||
|
"glGetProgramiv": &_glGetProgramiv,
|
||||||
|
"glGetProgramInfoLog": &_glGetProgramInfoLog,
|
||||||
|
"glGetQueryObjectuiv": &_glGetQueryObjectuiv,
|
||||||
|
"glGetShaderiv": &_glGetShaderiv,
|
||||||
|
"glGetShaderInfoLog": &_glGetShaderInfoLog,
|
||||||
|
"glGetString": &_glGetString,
|
||||||
|
"glGetUniformLocation": &_glGetUniformLocation,
|
||||||
|
"glGetVertexAttribiv": &_glGetVertexAttribiv,
|
||||||
|
"glGetVertexAttribPointerv": &_glGetVertexAttribPointerv,
|
||||||
|
"glInvalidateFramebuffer": &_glInvalidateFramebuffer,
|
||||||
|
"glIsEnabled": &_glIsEnabled,
|
||||||
|
"glLinkProgram": &_glLinkProgram,
|
||||||
|
"glPixelStorei": &_glPixelStorei,
|
||||||
|
"glReadPixels": &_glReadPixels,
|
||||||
|
"glRenderbufferStorage": &_glRenderbufferStorage,
|
||||||
|
"glScissor": &_glScissor,
|
||||||
|
"glShaderSource": &_glShaderSource,
|
||||||
|
"glTexImage2D": &_glTexImage2D,
|
||||||
|
"glTexStorage2D": &_glTexStorage2D,
|
||||||
|
"glTexSubImage2D": &_glTexSubImage2D,
|
||||||
|
"glTexParameteri": &_glTexParameteri,
|
||||||
|
"glUniformBlockBinding": &_glUniformBlockBinding,
|
||||||
|
"glUniform1f": &_glUniform1f,
|
||||||
|
"glUniform1i": &_glUniform1i,
|
||||||
|
"glUniform2f": &_glUniform2f,
|
||||||
|
"glUniform3f": &_glUniform3f,
|
||||||
|
"glUniform4f": &_glUniform4f,
|
||||||
|
"glUseProgram": &_glUseProgram,
|
||||||
|
"glVertexAttribPointer": &_glVertexAttribPointer,
|
||||||
|
"glViewport": &_glViewport,
|
||||||
|
}
|
||||||
|
for name, proc := range procs {
|
||||||
|
p, err := gles.FindProc(name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to locate %s in %s: %w", name, gles.Name, err)
|
||||||
|
}
|
||||||
|
*proc = p
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
LibGLESv2 = windows.NewLazyDLL("libGLESv2.dll")
|
glInitOnce sync.Once
|
||||||
_glActiveTexture = LibGLESv2.NewProc("glActiveTexture")
|
_glActiveTexture *windows.Proc
|
||||||
_glAttachShader = LibGLESv2.NewProc("glAttachShader")
|
_glAttachShader *windows.Proc
|
||||||
_glBeginQuery = LibGLESv2.NewProc("glBeginQuery")
|
_glBeginQuery *windows.Proc
|
||||||
_glBindAttribLocation = LibGLESv2.NewProc("glBindAttribLocation")
|
_glBindAttribLocation *windows.Proc
|
||||||
_glBindBuffer = LibGLESv2.NewProc("glBindBuffer")
|
_glBindBuffer *windows.Proc
|
||||||
_glBindBufferBase = LibGLESv2.NewProc("glBindBufferBase")
|
_glBindBufferBase *windows.Proc
|
||||||
_glBindFramebuffer = LibGLESv2.NewProc("glBindFramebuffer")
|
_glBindFramebuffer *windows.Proc
|
||||||
_glBindRenderbuffer = LibGLESv2.NewProc("glBindRenderbuffer")
|
_glBindRenderbuffer *windows.Proc
|
||||||
_glBindTexture = LibGLESv2.NewProc("glBindTexture")
|
_glBindTexture *windows.Proc
|
||||||
_glBindVertexArray = LibGLESv2.NewProc("glBindVertexArray")
|
_glBindVertexArray *windows.Proc
|
||||||
_glBlendEquation = LibGLESv2.NewProc("glBlendEquation")
|
_glBlendEquation *windows.Proc
|
||||||
_glBlendFuncSeparate = LibGLESv2.NewProc("glBlendFuncSeparate")
|
_glBlendFuncSeparate *windows.Proc
|
||||||
_glBufferData = LibGLESv2.NewProc("glBufferData")
|
_glBufferData *windows.Proc
|
||||||
_glBufferSubData = LibGLESv2.NewProc("glBufferSubData")
|
_glBufferSubData *windows.Proc
|
||||||
_glCheckFramebufferStatus = LibGLESv2.NewProc("glCheckFramebufferStatus")
|
_glCheckFramebufferStatus *windows.Proc
|
||||||
_glClear = LibGLESv2.NewProc("glClear")
|
_glClear *windows.Proc
|
||||||
_glClearColor = LibGLESv2.NewProc("glClearColor")
|
_glClearColor *windows.Proc
|
||||||
_glClearDepthf = LibGLESv2.NewProc("glClearDepthf")
|
_glClearDepthf *windows.Proc
|
||||||
_glDeleteQueries = LibGLESv2.NewProc("glDeleteQueries")
|
_glDeleteQueries *windows.Proc
|
||||||
_glDeleteVertexArrays = LibGLESv2.NewProc("glDeleteVertexArrays")
|
_glDeleteVertexArrays *windows.Proc
|
||||||
_glCompileShader = LibGLESv2.NewProc("glCompileShader")
|
_glCompileShader *windows.Proc
|
||||||
_glCopyTexSubImage2D = LibGLESv2.NewProc("glCopyTexSubImage2D")
|
_glCopyTexSubImage2D *windows.Proc
|
||||||
_glGenerateMipmap = LibGLESv2.NewProc("glGenerateMipmap")
|
_glGenerateMipmap *windows.Proc
|
||||||
_glGenBuffers = LibGLESv2.NewProc("glGenBuffers")
|
_glGenBuffers *windows.Proc
|
||||||
_glGenFramebuffers = LibGLESv2.NewProc("glGenFramebuffers")
|
_glGenFramebuffers *windows.Proc
|
||||||
_glGenVertexArrays = LibGLESv2.NewProc("glGenVertexArrays")
|
_glGenVertexArrays *windows.Proc
|
||||||
_glGetUniformBlockIndex = LibGLESv2.NewProc("glGetUniformBlockIndex")
|
_glGetUniformBlockIndex *windows.Proc
|
||||||
_glCreateProgram = LibGLESv2.NewProc("glCreateProgram")
|
_glCreateProgram *windows.Proc
|
||||||
_glGenRenderbuffers = LibGLESv2.NewProc("glGenRenderbuffers")
|
_glGenRenderbuffers *windows.Proc
|
||||||
_glCreateShader = LibGLESv2.NewProc("glCreateShader")
|
_glCreateShader *windows.Proc
|
||||||
_glGenTextures = LibGLESv2.NewProc("glGenTextures")
|
_glGenTextures *windows.Proc
|
||||||
_glDeleteBuffers = LibGLESv2.NewProc("glDeleteBuffers")
|
_glDeleteBuffers *windows.Proc
|
||||||
_glDeleteFramebuffers = LibGLESv2.NewProc("glDeleteFramebuffers")
|
_glDeleteFramebuffers *windows.Proc
|
||||||
_glDeleteProgram = LibGLESv2.NewProc("glDeleteProgram")
|
_glDeleteProgram *windows.Proc
|
||||||
_glDeleteShader = LibGLESv2.NewProc("glDeleteShader")
|
_glDeleteShader *windows.Proc
|
||||||
_glDeleteRenderbuffers = LibGLESv2.NewProc("glDeleteRenderbuffers")
|
_glDeleteRenderbuffers *windows.Proc
|
||||||
_glDeleteTextures = LibGLESv2.NewProc("glDeleteTextures")
|
_glDeleteTextures *windows.Proc
|
||||||
_glDepthFunc = LibGLESv2.NewProc("glDepthFunc")
|
_glDepthFunc *windows.Proc
|
||||||
_glDepthMask = LibGLESv2.NewProc("glDepthMask")
|
_glDepthMask *windows.Proc
|
||||||
_glDisableVertexAttribArray = LibGLESv2.NewProc("glDisableVertexAttribArray")
|
_glDisableVertexAttribArray *windows.Proc
|
||||||
_glDisable = LibGLESv2.NewProc("glDisable")
|
_glDisable *windows.Proc
|
||||||
_glDrawArrays = LibGLESv2.NewProc("glDrawArrays")
|
_glDrawArrays *windows.Proc
|
||||||
_glDrawElements = LibGLESv2.NewProc("glDrawElements")
|
_glDrawElements *windows.Proc
|
||||||
_glEnable = LibGLESv2.NewProc("glEnable")
|
_glEnable *windows.Proc
|
||||||
_glEnableVertexAttribArray = LibGLESv2.NewProc("glEnableVertexAttribArray")
|
_glEnableVertexAttribArray *windows.Proc
|
||||||
_glEndQuery = LibGLESv2.NewProc("glEndQuery")
|
_glEndQuery *windows.Proc
|
||||||
_glFinish = LibGLESv2.NewProc("glFinish")
|
_glFinish *windows.Proc
|
||||||
_glFlush = LibGLESv2.NewProc("glFlush")
|
_glFlush *windows.Proc
|
||||||
_glFramebufferRenderbuffer = LibGLESv2.NewProc("glFramebufferRenderbuffer")
|
_glFramebufferRenderbuffer *windows.Proc
|
||||||
_glFramebufferTexture2D = LibGLESv2.NewProc("glFramebufferTexture2D")
|
_glFramebufferTexture2D *windows.Proc
|
||||||
_glGenQueries = LibGLESv2.NewProc("glGenQueries")
|
_glGenQueries *windows.Proc
|
||||||
_glGetError = LibGLESv2.NewProc("glGetError")
|
_glGetError *windows.Proc
|
||||||
_glGetRenderbufferParameteriv = LibGLESv2.NewProc("glGetRenderbufferParameteriv")
|
_glGetRenderbufferParameteriv *windows.Proc
|
||||||
_glGetFloatv = LibGLESv2.NewProc("glGetFloatv")
|
_glGetFloatv *windows.Proc
|
||||||
_glGetFramebufferAttachmentParameteriv = LibGLESv2.NewProc("glGetFramebufferAttachmentParameteriv")
|
_glGetFramebufferAttachmentParameteriv *windows.Proc
|
||||||
_glGetIntegerv = LibGLESv2.NewProc("glGetIntegerv")
|
_glGetIntegerv *windows.Proc
|
||||||
_glGetIntegeri_v = LibGLESv2.NewProc("glGetIntegeri_v")
|
_glGetIntegeri_v *windows.Proc
|
||||||
_glGetProgramiv = LibGLESv2.NewProc("glGetProgramiv")
|
_glGetProgramiv *windows.Proc
|
||||||
_glGetProgramInfoLog = LibGLESv2.NewProc("glGetProgramInfoLog")
|
_glGetProgramInfoLog *windows.Proc
|
||||||
_glGetQueryObjectuiv = LibGLESv2.NewProc("glGetQueryObjectuiv")
|
_glGetQueryObjectuiv *windows.Proc
|
||||||
_glGetShaderiv = LibGLESv2.NewProc("glGetShaderiv")
|
_glGetShaderiv *windows.Proc
|
||||||
_glGetShaderInfoLog = LibGLESv2.NewProc("glGetShaderInfoLog")
|
_glGetShaderInfoLog *windows.Proc
|
||||||
_glGetString = LibGLESv2.NewProc("glGetString")
|
_glGetString *windows.Proc
|
||||||
_glGetUniformLocation = LibGLESv2.NewProc("glGetUniformLocation")
|
_glGetUniformLocation *windows.Proc
|
||||||
_glGetVertexAttribiv = LibGLESv2.NewProc("glGetVertexAttribiv")
|
_glGetVertexAttribiv *windows.Proc
|
||||||
_glGetVertexAttribPointerv = LibGLESv2.NewProc("glGetVertexAttribPointerv")
|
_glGetVertexAttribPointerv *windows.Proc
|
||||||
_glInvalidateFramebuffer = LibGLESv2.NewProc("glInvalidateFramebuffer")
|
_glInvalidateFramebuffer *windows.Proc
|
||||||
_glIsEnabled = LibGLESv2.NewProc("glIsEnabled")
|
_glIsEnabled *windows.Proc
|
||||||
_glLinkProgram = LibGLESv2.NewProc("glLinkProgram")
|
_glLinkProgram *windows.Proc
|
||||||
_glPixelStorei = LibGLESv2.NewProc("glPixelStorei")
|
_glPixelStorei *windows.Proc
|
||||||
_glReadPixels = LibGLESv2.NewProc("glReadPixels")
|
_glReadPixels *windows.Proc
|
||||||
_glRenderbufferStorage = LibGLESv2.NewProc("glRenderbufferStorage")
|
_glRenderbufferStorage *windows.Proc
|
||||||
_glScissor = LibGLESv2.NewProc("glScissor")
|
_glScissor *windows.Proc
|
||||||
_glShaderSource = LibGLESv2.NewProc("glShaderSource")
|
_glShaderSource *windows.Proc
|
||||||
_glTexImage2D = LibGLESv2.NewProc("glTexImage2D")
|
_glTexImage2D *windows.Proc
|
||||||
_glTexStorage2D = LibGLESv2.NewProc("glTexStorage2D")
|
_glTexStorage2D *windows.Proc
|
||||||
_glTexSubImage2D = LibGLESv2.NewProc("glTexSubImage2D")
|
_glTexSubImage2D *windows.Proc
|
||||||
_glTexParameteri = LibGLESv2.NewProc("glTexParameteri")
|
_glTexParameteri *windows.Proc
|
||||||
_glUniformBlockBinding = LibGLESv2.NewProc("glUniformBlockBinding")
|
_glUniformBlockBinding *windows.Proc
|
||||||
_glUniform1f = LibGLESv2.NewProc("glUniform1f")
|
_glUniform1f *windows.Proc
|
||||||
_glUniform1i = LibGLESv2.NewProc("glUniform1i")
|
_glUniform1i *windows.Proc
|
||||||
_glUniform2f = LibGLESv2.NewProc("glUniform2f")
|
_glUniform2f *windows.Proc
|
||||||
_glUniform3f = LibGLESv2.NewProc("glUniform3f")
|
_glUniform3f *windows.Proc
|
||||||
_glUniform4f = LibGLESv2.NewProc("glUniform4f")
|
_glUniform4f *windows.Proc
|
||||||
_glUseProgram = LibGLESv2.NewProc("glUseProgram")
|
_glUseProgram *windows.Proc
|
||||||
_glVertexAttribPointer = LibGLESv2.NewProc("glVertexAttribPointer")
|
_glVertexAttribPointer *windows.Proc
|
||||||
_glViewport = LibGLESv2.NewProc("glViewport")
|
_glViewport *windows.Proc
|
||||||
)
|
)
|
||||||
|
|
||||||
type Functions struct {
|
type Functions struct {
|
||||||
@@ -109,57 +223,74 @@ type Functions struct {
|
|||||||
uintptrs [100]uintptr
|
uintptrs [100]uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
type Context interface{}
|
type Context any
|
||||||
|
|
||||||
func NewFunctions(ctx Context, forceES bool) (*Functions, error) {
|
func NewFunctions(ctx Context, forceES bool) (*Functions, error) {
|
||||||
if ctx != nil {
|
if ctx != nil {
|
||||||
panic("non-nil context")
|
panic("non-nil context")
|
||||||
}
|
}
|
||||||
return new(Functions), nil
|
var err error
|
||||||
|
glInitOnce.Do(func() {
|
||||||
|
err = loadGLESv2Procs()
|
||||||
|
})
|
||||||
|
return new(Functions), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) ActiveTexture(t Enum) {
|
func (c *Functions) ActiveTexture(t Enum) {
|
||||||
syscall.Syscall(_glActiveTexture.Addr(), 1, uintptr(t), 0, 0)
|
syscall.Syscall(_glActiveTexture.Addr(), 1, uintptr(t), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) AttachShader(p Program, s Shader) {
|
func (c *Functions) AttachShader(p Program, s Shader) {
|
||||||
syscall.Syscall(_glAttachShader.Addr(), 2, uintptr(p.V), uintptr(s.V), 0)
|
syscall.Syscall(_glAttachShader.Addr(), 2, uintptr(p.V), uintptr(s.V), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BeginQuery(target Enum, query Query) {
|
func (f *Functions) BeginQuery(target Enum, query Query) {
|
||||||
syscall.Syscall(_glBeginQuery.Addr(), 2, uintptr(target), uintptr(query.V), 0)
|
syscall.Syscall(_glBeginQuery.Addr(), 2, uintptr(target), uintptr(query.V), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BindAttribLocation(p Program, a Attrib, name string) {
|
func (c *Functions) BindAttribLocation(p Program, a Attrib, name string) {
|
||||||
cname := cString(name)
|
cname := cString(name)
|
||||||
c0 := &cname[0]
|
c0 := &cname[0]
|
||||||
syscall.Syscall(_glBindAttribLocation.Addr(), 3, uintptr(p.V), uintptr(a), uintptr(unsafe.Pointer(c0)))
|
syscall.Syscall(_glBindAttribLocation.Addr(), 3, uintptr(p.V), uintptr(a), uintptr(unsafe.Pointer(c0)))
|
||||||
issue34474KeepAlive(c)
|
issue34474KeepAlive(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BindBuffer(target Enum, b Buffer) {
|
func (c *Functions) BindBuffer(target Enum, b Buffer) {
|
||||||
syscall.Syscall(_glBindBuffer.Addr(), 2, uintptr(target), uintptr(b.V), 0)
|
syscall.Syscall(_glBindBuffer.Addr(), 2, uintptr(target), uintptr(b.V), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BindBufferBase(target Enum, index int, b Buffer) {
|
func (c *Functions) BindBufferBase(target Enum, index int, b Buffer) {
|
||||||
syscall.Syscall(_glBindBufferBase.Addr(), 3, uintptr(target), uintptr(index), uintptr(b.V))
|
syscall.Syscall(_glBindBufferBase.Addr(), 3, uintptr(target), uintptr(index), uintptr(b.V))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BindFramebuffer(target Enum, fb Framebuffer) {
|
func (c *Functions) BindFramebuffer(target Enum, fb Framebuffer) {
|
||||||
syscall.Syscall(_glBindFramebuffer.Addr(), 2, uintptr(target), uintptr(fb.V), 0)
|
syscall.Syscall(_glBindFramebuffer.Addr(), 2, uintptr(target), uintptr(fb.V), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BindRenderbuffer(target Enum, rb Renderbuffer) {
|
func (c *Functions) BindRenderbuffer(target Enum, rb Renderbuffer) {
|
||||||
syscall.Syscall(_glBindRenderbuffer.Addr(), 2, uintptr(target), uintptr(rb.V), 0)
|
syscall.Syscall(_glBindRenderbuffer.Addr(), 2, uintptr(target), uintptr(rb.V), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BindImageTexture(unit int, t Texture, level int, layered bool, layer int, access, format Enum) {
|
func (f *Functions) BindImageTexture(unit int, t Texture, level int, layered bool, layer int, access, format Enum) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BindTexture(target Enum, t Texture) {
|
func (c *Functions) BindTexture(target Enum, t Texture) {
|
||||||
syscall.Syscall(_glBindTexture.Addr(), 2, uintptr(target), uintptr(t.V), 0)
|
syscall.Syscall(_glBindTexture.Addr(), 2, uintptr(target), uintptr(t.V), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BindVertexArray(a VertexArray) {
|
func (c *Functions) BindVertexArray(a VertexArray) {
|
||||||
syscall.Syscall(_glBindVertexArray.Addr(), 1, uintptr(a.V), 0, 0)
|
syscall.Syscall(_glBindVertexArray.Addr(), 1, uintptr(a.V), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BlendEquation(mode Enum) {
|
func (c *Functions) BlendEquation(mode Enum) {
|
||||||
syscall.Syscall(_glBlendEquation.Addr(), 1, uintptr(mode), 0, 0)
|
syscall.Syscall(_glBlendEquation.Addr(), 1, uintptr(mode), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BlendFuncSeparate(srcRGB, dstRGB, srcA, dstA Enum) {
|
func (c *Functions) BlendFuncSeparate(srcRGB, dstRGB, srcA, dstA Enum) {
|
||||||
syscall.Syscall6(_glBlendFuncSeparate.Addr(), 4, uintptr(srcRGB), uintptr(dstRGB), uintptr(srcA), uintptr(dstA), 0, 0)
|
syscall.Syscall6(_glBlendFuncSeparate.Addr(), 4, uintptr(srcRGB), uintptr(dstRGB), uintptr(srcA), uintptr(dstA), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) BufferData(target Enum, size int, usage Enum, data []byte) {
|
func (c *Functions) BufferData(target Enum, size int, usage Enum, data []byte) {
|
||||||
var p unsafe.Pointer
|
var p unsafe.Pointer
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
@@ -167,6 +298,7 @@ func (c *Functions) BufferData(target Enum, size int, usage Enum, data []byte) {
|
|||||||
}
|
}
|
||||||
syscall.Syscall6(_glBufferData.Addr(), 4, uintptr(target), uintptr(size), uintptr(p), uintptr(usage), 0, 0)
|
syscall.Syscall6(_glBufferData.Addr(), 4, uintptr(target), uintptr(size), uintptr(p), uintptr(usage), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) BufferSubData(target Enum, offset int, src []byte) {
|
func (f *Functions) BufferSubData(target Enum, offset int, src []byte) {
|
||||||
if n := len(src); n > 0 {
|
if n := len(src); n > 0 {
|
||||||
s0 := &src[0]
|
s0 := &src[0]
|
||||||
@@ -174,93 +306,118 @@ func (f *Functions) BufferSubData(target Enum, offset int, src []byte) {
|
|||||||
issue34474KeepAlive(s0)
|
issue34474KeepAlive(s0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) CheckFramebufferStatus(target Enum) Enum {
|
func (c *Functions) CheckFramebufferStatus(target Enum) Enum {
|
||||||
s, _, _ := syscall.Syscall(_glCheckFramebufferStatus.Addr(), 1, uintptr(target), 0, 0)
|
s, _, _ := syscall.Syscall(_glCheckFramebufferStatus.Addr(), 1, uintptr(target), 0, 0)
|
||||||
return Enum(s)
|
return Enum(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Clear(mask Enum) {
|
func (c *Functions) Clear(mask Enum) {
|
||||||
syscall.Syscall(_glClear.Addr(), 1, uintptr(mask), 0, 0)
|
syscall.Syscall(_glClear.Addr(), 1, uintptr(mask), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) ClearColor(red, green, blue, alpha float32) {
|
func (c *Functions) ClearColor(red, green, blue, alpha float32) {
|
||||||
syscall.Syscall6(_glClearColor.Addr(), 4, uintptr(math.Float32bits(red)), uintptr(math.Float32bits(green)), uintptr(math.Float32bits(blue)), uintptr(math.Float32bits(alpha)), 0, 0)
|
syscall.Syscall6(_glClearColor.Addr(), 4, uintptr(math.Float32bits(red)), uintptr(math.Float32bits(green)), uintptr(math.Float32bits(blue)), uintptr(math.Float32bits(alpha)), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) ClearDepthf(d float32) {
|
func (c *Functions) ClearDepthf(d float32) {
|
||||||
syscall.Syscall(_glClearDepthf.Addr(), 1, uintptr(math.Float32bits(d)), 0, 0)
|
syscall.Syscall(_glClearDepthf.Addr(), 1, uintptr(math.Float32bits(d)), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) CompileShader(s Shader) {
|
func (c *Functions) CompileShader(s Shader) {
|
||||||
syscall.Syscall(_glCompileShader.Addr(), 1, uintptr(s.V), 0, 0)
|
syscall.Syscall(_glCompileShader.Addr(), 1, uintptr(s.V), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height int) {
|
func (f *Functions) CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height int) {
|
||||||
syscall.Syscall9(_glCopyTexSubImage2D.Addr(), 8, uintptr(target), uintptr(level), uintptr(xoffset), uintptr(yoffset), uintptr(x), uintptr(y), uintptr(width), uintptr(height), 0)
|
syscall.Syscall9(_glCopyTexSubImage2D.Addr(), 8, uintptr(target), uintptr(level), uintptr(xoffset), uintptr(yoffset), uintptr(x), uintptr(y), uintptr(width), uintptr(height), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GenerateMipmap(target Enum) {
|
func (f *Functions) GenerateMipmap(target Enum) {
|
||||||
syscall.Syscall(_glGenerateMipmap.Addr(), 1, uintptr(target), 0, 0)
|
syscall.Syscall(_glGenerateMipmap.Addr(), 1, uintptr(target), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) CreateBuffer() Buffer {
|
func (c *Functions) CreateBuffer() Buffer {
|
||||||
var buf uintptr
|
var buf uintptr
|
||||||
syscall.Syscall(_glGenBuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&buf)), 0)
|
syscall.Syscall(_glGenBuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&buf)), 0)
|
||||||
return Buffer{uint(buf)}
|
return Buffer{uint(buf)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) CreateFramebuffer() Framebuffer {
|
func (c *Functions) CreateFramebuffer() Framebuffer {
|
||||||
var fb uintptr
|
var fb uintptr
|
||||||
syscall.Syscall(_glGenFramebuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&fb)), 0)
|
syscall.Syscall(_glGenFramebuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&fb)), 0)
|
||||||
return Framebuffer{uint(fb)}
|
return Framebuffer{uint(fb)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) CreateProgram() Program {
|
func (c *Functions) CreateProgram() Program {
|
||||||
p, _, _ := syscall.Syscall(_glCreateProgram.Addr(), 0, 0, 0, 0)
|
p, _, _ := syscall.Syscall(_glCreateProgram.Addr(), 0, 0, 0, 0)
|
||||||
return Program{uint(p)}
|
return Program{uint(p)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) CreateQuery() Query {
|
func (f *Functions) CreateQuery() Query {
|
||||||
var q uintptr
|
var q uintptr
|
||||||
syscall.Syscall(_glGenQueries.Addr(), 2, 1, uintptr(unsafe.Pointer(&q)), 0)
|
syscall.Syscall(_glGenQueries.Addr(), 2, 1, uintptr(unsafe.Pointer(&q)), 0)
|
||||||
return Query{uint(q)}
|
return Query{uint(q)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) CreateRenderbuffer() Renderbuffer {
|
func (c *Functions) CreateRenderbuffer() Renderbuffer {
|
||||||
var rb uintptr
|
var rb uintptr
|
||||||
syscall.Syscall(_glGenRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&rb)), 0)
|
syscall.Syscall(_glGenRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&rb)), 0)
|
||||||
return Renderbuffer{uint(rb)}
|
return Renderbuffer{uint(rb)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) CreateShader(ty Enum) Shader {
|
func (c *Functions) CreateShader(ty Enum) Shader {
|
||||||
s, _, _ := syscall.Syscall(_glCreateShader.Addr(), 1, uintptr(ty), 0, 0)
|
s, _, _ := syscall.Syscall(_glCreateShader.Addr(), 1, uintptr(ty), 0, 0)
|
||||||
return Shader{uint(s)}
|
return Shader{uint(s)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) CreateTexture() Texture {
|
func (c *Functions) CreateTexture() Texture {
|
||||||
var t uintptr
|
var t uintptr
|
||||||
syscall.Syscall(_glGenTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&t)), 0)
|
syscall.Syscall(_glGenTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&t)), 0)
|
||||||
return Texture{uint(t)}
|
return Texture{uint(t)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) CreateVertexArray() VertexArray {
|
func (c *Functions) CreateVertexArray() VertexArray {
|
||||||
var t uintptr
|
var t uintptr
|
||||||
syscall.Syscall(_glGenVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&t)), 0)
|
syscall.Syscall(_glGenVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&t)), 0)
|
||||||
return VertexArray{uint(t)}
|
return VertexArray{uint(t)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DeleteBuffer(v Buffer) {
|
func (c *Functions) DeleteBuffer(v Buffer) {
|
||||||
syscall.Syscall(_glDeleteBuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&v)), 0)
|
syscall.Syscall(_glDeleteBuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&v)), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DeleteFramebuffer(v Framebuffer) {
|
func (c *Functions) DeleteFramebuffer(v Framebuffer) {
|
||||||
syscall.Syscall(_glDeleteFramebuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&v.V)), 0)
|
syscall.Syscall(_glDeleteFramebuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&v.V)), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DeleteProgram(p Program) {
|
func (c *Functions) DeleteProgram(p Program) {
|
||||||
syscall.Syscall(_glDeleteProgram.Addr(), 1, uintptr(p.V), 0, 0)
|
syscall.Syscall(_glDeleteProgram.Addr(), 1, uintptr(p.V), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteQuery(query Query) {
|
func (f *Functions) DeleteQuery(query Query) {
|
||||||
syscall.Syscall(_glDeleteQueries.Addr(), 2, 1, uintptr(unsafe.Pointer(&query.V)), 0)
|
syscall.Syscall(_glDeleteQueries.Addr(), 2, 1, uintptr(unsafe.Pointer(&query.V)), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DeleteShader(s Shader) {
|
func (c *Functions) DeleteShader(s Shader) {
|
||||||
syscall.Syscall(_glDeleteShader.Addr(), 1, uintptr(s.V), 0, 0)
|
syscall.Syscall(_glDeleteShader.Addr(), 1, uintptr(s.V), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DeleteRenderbuffer(v Renderbuffer) {
|
func (c *Functions) DeleteRenderbuffer(v Renderbuffer) {
|
||||||
syscall.Syscall(_glDeleteRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&v.V)), 0)
|
syscall.Syscall(_glDeleteRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&v.V)), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DeleteTexture(v Texture) {
|
func (c *Functions) DeleteTexture(v Texture) {
|
||||||
syscall.Syscall(_glDeleteTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&v.V)), 0)
|
syscall.Syscall(_glDeleteTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&v.V)), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DeleteVertexArray(array VertexArray) {
|
func (f *Functions) DeleteVertexArray(array VertexArray) {
|
||||||
syscall.Syscall(_glDeleteVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&array.V)), 0)
|
syscall.Syscall(_glDeleteVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&array.V)), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DepthFunc(f Enum) {
|
func (c *Functions) DepthFunc(f Enum) {
|
||||||
syscall.Syscall(_glDepthFunc.Addr(), 1, uintptr(f), 0, 0)
|
syscall.Syscall(_glDepthFunc.Addr(), 1, uintptr(f), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DepthMask(mask bool) {
|
func (c *Functions) DepthMask(mask bool) {
|
||||||
var m uintptr
|
var m uintptr
|
||||||
if mask {
|
if mask {
|
||||||
@@ -268,42 +425,55 @@ func (c *Functions) DepthMask(mask bool) {
|
|||||||
}
|
}
|
||||||
syscall.Syscall(_glDepthMask.Addr(), 1, m, 0, 0)
|
syscall.Syscall(_glDepthMask.Addr(), 1, m, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DisableVertexAttribArray(a Attrib) {
|
func (c *Functions) DisableVertexAttribArray(a Attrib) {
|
||||||
syscall.Syscall(_glDisableVertexAttribArray.Addr(), 1, uintptr(a), 0, 0)
|
syscall.Syscall(_glDisableVertexAttribArray.Addr(), 1, uintptr(a), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Disable(cap Enum) {
|
func (c *Functions) Disable(cap Enum) {
|
||||||
syscall.Syscall(_glDisable.Addr(), 1, uintptr(cap), 0, 0)
|
syscall.Syscall(_glDisable.Addr(), 1, uintptr(cap), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DrawArrays(mode Enum, first, count int) {
|
func (c *Functions) DrawArrays(mode Enum, first, count int) {
|
||||||
syscall.Syscall(_glDrawArrays.Addr(), 3, uintptr(mode), uintptr(first), uintptr(count))
|
syscall.Syscall(_glDrawArrays.Addr(), 3, uintptr(mode), uintptr(first), uintptr(count))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) DrawElements(mode Enum, count int, ty Enum, offset int) {
|
func (c *Functions) DrawElements(mode Enum, count int, ty Enum, offset int) {
|
||||||
syscall.Syscall6(_glDrawElements.Addr(), 4, uintptr(mode), uintptr(count), uintptr(ty), uintptr(offset), 0, 0)
|
syscall.Syscall6(_glDrawElements.Addr(), 4, uintptr(mode), uintptr(count), uintptr(ty), uintptr(offset), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) DispatchCompute(x, y, z int) {
|
func (f *Functions) DispatchCompute(x, y, z int) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Enable(cap Enum) {
|
func (c *Functions) Enable(cap Enum) {
|
||||||
syscall.Syscall(_glEnable.Addr(), 1, uintptr(cap), 0, 0)
|
syscall.Syscall(_glEnable.Addr(), 1, uintptr(cap), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) EnableVertexAttribArray(a Attrib) {
|
func (c *Functions) EnableVertexAttribArray(a Attrib) {
|
||||||
syscall.Syscall(_glEnableVertexAttribArray.Addr(), 1, uintptr(a), 0, 0)
|
syscall.Syscall(_glEnableVertexAttribArray.Addr(), 1, uintptr(a), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) EndQuery(target Enum) {
|
func (f *Functions) EndQuery(target Enum) {
|
||||||
syscall.Syscall(_glEndQuery.Addr(), 1, uintptr(target), 0, 0)
|
syscall.Syscall(_glEndQuery.Addr(), 1, uintptr(target), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Finish() {
|
func (c *Functions) Finish() {
|
||||||
syscall.Syscall(_glFinish.Addr(), 0, 0, 0, 0)
|
syscall.Syscall(_glFinish.Addr(), 0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Flush() {
|
func (c *Functions) Flush() {
|
||||||
syscall.Syscall(_glFlush.Addr(), 0, 0, 0, 0)
|
syscall.Syscall(_glFlush.Addr(), 0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) FramebufferRenderbuffer(target, attachment, renderbuffertarget Enum, renderbuffer Renderbuffer) {
|
func (c *Functions) FramebufferRenderbuffer(target, attachment, renderbuffertarget Enum, renderbuffer Renderbuffer) {
|
||||||
syscall.Syscall6(_glFramebufferRenderbuffer.Addr(), 4, uintptr(target), uintptr(attachment), uintptr(renderbuffertarget), uintptr(renderbuffer.V), 0, 0)
|
syscall.Syscall6(_glFramebufferRenderbuffer.Addr(), 4, uintptr(target), uintptr(attachment), uintptr(renderbuffertarget), uintptr(renderbuffer.V), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) FramebufferTexture2D(target, attachment, texTarget Enum, t Texture, level int) {
|
func (c *Functions) FramebufferTexture2D(target, attachment, texTarget Enum, t Texture, level int) {
|
||||||
syscall.Syscall6(_glFramebufferTexture2D.Addr(), 5, uintptr(target), uintptr(attachment), uintptr(texTarget), uintptr(t.V), uintptr(level), 0)
|
syscall.Syscall6(_glFramebufferTexture2D.Addr(), 5, uintptr(target), uintptr(attachment), uintptr(texTarget), uintptr(t.V), uintptr(level), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) GetUniformBlockIndex(p Program, name string) uint {
|
func (f *Functions) GetUniformBlockIndex(p Program, name string) uint {
|
||||||
cname := cString(name)
|
cname := cString(name)
|
||||||
c0 := &cname[0]
|
c0 := &cname[0]
|
||||||
@@ -311,24 +481,30 @@ func (f *Functions) GetUniformBlockIndex(p Program, name string) uint {
|
|||||||
issue34474KeepAlive(c0)
|
issue34474KeepAlive(c0)
|
||||||
return uint(u)
|
return uint(u)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetBinding(pname Enum) Object {
|
func (c *Functions) GetBinding(pname Enum) Object {
|
||||||
return Object{uint(c.GetInteger(pname))}
|
return Object{uint(c.GetInteger(pname))}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetBindingi(pname Enum, idx int) Object {
|
func (c *Functions) GetBindingi(pname Enum, idx int) Object {
|
||||||
return Object{uint(c.GetIntegeri(pname, idx))}
|
return Object{uint(c.GetIntegeri(pname, idx))}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetError() Enum {
|
func (c *Functions) GetError() Enum {
|
||||||
e, _, _ := syscall.Syscall(_glGetError.Addr(), 0, 0, 0, 0)
|
e, _, _ := syscall.Syscall(_glGetError.Addr(), 0, 0, 0, 0)
|
||||||
return Enum(e)
|
return Enum(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetRenderbufferParameteri(target, pname Enum) int {
|
func (c *Functions) GetRenderbufferParameteri(target, pname Enum) int {
|
||||||
syscall.Syscall(_glGetRenderbufferParameteriv.Addr(), 3, uintptr(target), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
syscall.Syscall(_glGetRenderbufferParameteriv.Addr(), 3, uintptr(target), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
||||||
return int(c.int32s[0])
|
return int(c.int32s[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetFramebufferAttachmentParameteri(target, attachment, pname Enum) int {
|
func (c *Functions) GetFramebufferAttachmentParameteri(target, attachment, pname Enum) int {
|
||||||
syscall.Syscall6(_glGetFramebufferAttachmentParameteriv.Addr(), 4, uintptr(target), uintptr(attachment), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0, 0)
|
syscall.Syscall6(_glGetFramebufferAttachmentParameteriv.Addr(), 4, uintptr(target), uintptr(attachment), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0, 0)
|
||||||
return int(c.int32s[0])
|
return int(c.int32s[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetInteger4(pname Enum) [4]int {
|
func (c *Functions) GetInteger4(pname Enum) [4]int {
|
||||||
syscall.Syscall(_glGetIntegerv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0)
|
syscall.Syscall(_glGetIntegerv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0)
|
||||||
var r [4]int
|
var r [4]int
|
||||||
@@ -337,52 +513,66 @@ func (c *Functions) GetInteger4(pname Enum) [4]int {
|
|||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetInteger(pname Enum) int {
|
func (c *Functions) GetInteger(pname Enum) int {
|
||||||
syscall.Syscall(_glGetIntegerv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0)
|
syscall.Syscall(_glGetIntegerv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])), 0)
|
||||||
return int(c.int32s[0])
|
return int(c.int32s[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetIntegeri(pname Enum, idx int) int {
|
func (c *Functions) GetIntegeri(pname Enum, idx int) int {
|
||||||
syscall.Syscall(_glGetIntegeri_v.Addr(), 3, uintptr(pname), uintptr(idx), uintptr(unsafe.Pointer(&c.int32s[0])))
|
syscall.Syscall(_glGetIntegeri_v.Addr(), 3, uintptr(pname), uintptr(idx), uintptr(unsafe.Pointer(&c.int32s[0])))
|
||||||
return int(c.int32s[0])
|
return int(c.int32s[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetFloat(pname Enum) float32 {
|
func (c *Functions) GetFloat(pname Enum) float32 {
|
||||||
syscall.Syscall(_glGetFloatv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.float32s[0])), 0)
|
syscall.Syscall(_glGetFloatv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.float32s[0])), 0)
|
||||||
return c.float32s[0]
|
return c.float32s[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetFloat4(pname Enum) [4]float32 {
|
func (c *Functions) GetFloat4(pname Enum) [4]float32 {
|
||||||
syscall.Syscall(_glGetFloatv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.float32s[0])), 0)
|
syscall.Syscall(_glGetFloatv.Addr(), 2, uintptr(pname), uintptr(unsafe.Pointer(&c.float32s[0])), 0)
|
||||||
var r [4]float32
|
var r [4]float32
|
||||||
copy(r[:], c.float32s[:])
|
copy(r[:], c.float32s[:])
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetProgrami(p Program, pname Enum) int {
|
func (c *Functions) GetProgrami(p Program, pname Enum) int {
|
||||||
syscall.Syscall(_glGetProgramiv.Addr(), 3, uintptr(p.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
syscall.Syscall(_glGetProgramiv.Addr(), 3, uintptr(p.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
||||||
return int(c.int32s[0])
|
return int(c.int32s[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetProgramInfoLog(p Program) string {
|
func (c *Functions) GetProgramInfoLog(p Program) string {
|
||||||
n := c.GetProgrami(p, INFO_LOG_LENGTH)
|
n := c.GetProgrami(p, INFO_LOG_LENGTH)
|
||||||
|
if n == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
buf := make([]byte, n)
|
buf := make([]byte, n)
|
||||||
syscall.Syscall6(_glGetProgramInfoLog.Addr(), 4, uintptr(p.V), uintptr(len(buf)), 0, uintptr(unsafe.Pointer(&buf[0])), 0, 0)
|
syscall.Syscall6(_glGetProgramInfoLog.Addr(), 4, uintptr(p.V), uintptr(len(buf)), 0, uintptr(unsafe.Pointer(&buf[0])), 0, 0)
|
||||||
return string(buf)
|
return string(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetQueryObjectuiv(query Query, pname Enum) uint {
|
func (c *Functions) GetQueryObjectuiv(query Query, pname Enum) uint {
|
||||||
syscall.Syscall(_glGetQueryObjectuiv.Addr(), 3, uintptr(query.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
syscall.Syscall(_glGetQueryObjectuiv.Addr(), 3, uintptr(query.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
||||||
return uint(c.int32s[0])
|
return uint(c.int32s[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetShaderi(s Shader, pname Enum) int {
|
func (c *Functions) GetShaderi(s Shader, pname Enum) int {
|
||||||
syscall.Syscall(_glGetShaderiv.Addr(), 3, uintptr(s.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
syscall.Syscall(_glGetShaderiv.Addr(), 3, uintptr(s.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
||||||
return int(c.int32s[0])
|
return int(c.int32s[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetShaderInfoLog(s Shader) string {
|
func (c *Functions) GetShaderInfoLog(s Shader) string {
|
||||||
n := c.GetShaderi(s, INFO_LOG_LENGTH)
|
n := c.GetShaderi(s, INFO_LOG_LENGTH)
|
||||||
buf := make([]byte, n)
|
buf := make([]byte, n)
|
||||||
syscall.Syscall6(_glGetShaderInfoLog.Addr(), 4, uintptr(s.V), uintptr(len(buf)), 0, uintptr(unsafe.Pointer(&buf[0])), 0, 0)
|
syscall.Syscall6(_glGetShaderInfoLog.Addr(), 4, uintptr(s.V), uintptr(len(buf)), 0, uintptr(unsafe.Pointer(&buf[0])), 0, 0)
|
||||||
return string(buf)
|
return string(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetString(pname Enum) string {
|
func (c *Functions) GetString(pname Enum) string {
|
||||||
s, _, _ := syscall.Syscall(_glGetString.Addr(), 1, uintptr(pname), 0, 0)
|
s, _, _ := syscall.Syscall(_glGetString.Addr(), 1, uintptr(pname), 0, 0)
|
||||||
return windows.BytePtrToString((*byte)(unsafe.Pointer(s)))
|
return windows.BytePtrToString((*byte)(unsafe.Pointer(s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetUniformLocation(p Program, name string) Uniform {
|
func (c *Functions) GetUniformLocation(p Program, name string) Uniform {
|
||||||
cname := cString(name)
|
cname := cString(name)
|
||||||
c0 := &cname[0]
|
c0 := &cname[0]
|
||||||
@@ -390,6 +580,7 @@ func (c *Functions) GetUniformLocation(p Program, name string) Uniform {
|
|||||||
issue34474KeepAlive(c0)
|
issue34474KeepAlive(c0)
|
||||||
return Uniform{int(u)}
|
return Uniform{int(u)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) GetVertexAttrib(index int, pname Enum) int {
|
func (c *Functions) GetVertexAttrib(index int, pname Enum) int {
|
||||||
syscall.Syscall(_glGetVertexAttribiv.Addr(), 3, uintptr(index), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
syscall.Syscall(_glGetVertexAttribiv.Addr(), 3, uintptr(index), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0])))
|
||||||
return int(c.int32s[0])
|
return int(c.int32s[0])
|
||||||
@@ -403,6 +594,7 @@ func (c *Functions) GetVertexAttribPointer(index int, pname Enum) uintptr {
|
|||||||
syscall.Syscall(_glGetVertexAttribPointerv.Addr(), 3, uintptr(index), uintptr(pname), uintptr(unsafe.Pointer(&c.uintptrs[0])))
|
syscall.Syscall(_glGetVertexAttribPointerv.Addr(), 3, uintptr(index), uintptr(pname), uintptr(unsafe.Pointer(&c.uintptrs[0])))
|
||||||
return c.uintptrs[0]
|
return c.uintptrs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) InvalidateFramebuffer(target, attachment Enum) {
|
func (c *Functions) InvalidateFramebuffer(target, attachment Enum) {
|
||||||
addr := _glInvalidateFramebuffer.Addr()
|
addr := _glInvalidateFramebuffer.Addr()
|
||||||
if addr == 0 {
|
if addr == 0 {
|
||||||
@@ -411,77 +603,99 @@ func (c *Functions) InvalidateFramebuffer(target, attachment Enum) {
|
|||||||
}
|
}
|
||||||
syscall.Syscall(addr, 3, uintptr(target), 1, uintptr(unsafe.Pointer(&attachment)))
|
syscall.Syscall(addr, 3, uintptr(target), 1, uintptr(unsafe.Pointer(&attachment)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) IsEnabled(cap Enum) bool {
|
func (f *Functions) IsEnabled(cap Enum) bool {
|
||||||
u, _, _ := syscall.Syscall(_glIsEnabled.Addr(), 1, uintptr(cap), 0, 0)
|
u, _, _ := syscall.Syscall(_glIsEnabled.Addr(), 1, uintptr(cap), 0, 0)
|
||||||
return u == TRUE
|
return u == TRUE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) LinkProgram(p Program) {
|
func (c *Functions) LinkProgram(p Program) {
|
||||||
syscall.Syscall(_glLinkProgram.Addr(), 1, uintptr(p.V), 0, 0)
|
syscall.Syscall(_glLinkProgram.Addr(), 1, uintptr(p.V), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) PixelStorei(pname Enum, param int) {
|
func (c *Functions) PixelStorei(pname Enum, param int) {
|
||||||
syscall.Syscall(_glPixelStorei.Addr(), 2, uintptr(pname), uintptr(param), 0)
|
syscall.Syscall(_glPixelStorei.Addr(), 2, uintptr(pname), uintptr(param), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) MemoryBarrier(barriers Enum) {
|
func (f *Functions) MemoryBarrier(barriers Enum) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) MapBufferRange(target Enum, offset, length int, access Enum) []byte {
|
func (f *Functions) MapBufferRange(target Enum, offset, length int, access Enum) []byte {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) ReadPixels(x, y, width, height int, format, ty Enum, data []byte) {
|
func (f *Functions) ReadPixels(x, y, width, height int, format, ty Enum, data []byte) {
|
||||||
d0 := &data[0]
|
d0 := &data[0]
|
||||||
syscall.Syscall9(_glReadPixels.Addr(), 7, uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(format), uintptr(ty), uintptr(unsafe.Pointer(d0)), 0, 0)
|
syscall.Syscall9(_glReadPixels.Addr(), 7, uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(format), uintptr(ty), uintptr(unsafe.Pointer(d0)), 0, 0)
|
||||||
issue34474KeepAlive(d0)
|
issue34474KeepAlive(d0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) RenderbufferStorage(target, internalformat Enum, width, height int) {
|
func (c *Functions) RenderbufferStorage(target, internalformat Enum, width, height int) {
|
||||||
syscall.Syscall6(_glRenderbufferStorage.Addr(), 4, uintptr(target), uintptr(internalformat), uintptr(width), uintptr(height), 0, 0)
|
syscall.Syscall6(_glRenderbufferStorage.Addr(), 4, uintptr(target), uintptr(internalformat), uintptr(width), uintptr(height), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Scissor(x, y, width, height int32) {
|
func (c *Functions) Scissor(x, y, width, height int32) {
|
||||||
syscall.Syscall6(_glScissor.Addr(), 4, uintptr(x), uintptr(y), uintptr(width), uintptr(height), 0, 0)
|
syscall.Syscall6(_glScissor.Addr(), 4, uintptr(x), uintptr(y), uintptr(width), uintptr(height), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) ShaderSource(s Shader, src string) {
|
func (c *Functions) ShaderSource(s Shader, src string) {
|
||||||
var n uintptr = uintptr(len(src))
|
var n uintptr = uintptr(len(src))
|
||||||
psrc := &src
|
psrc := &src
|
||||||
syscall.Syscall6(_glShaderSource.Addr(), 4, uintptr(s.V), 1, uintptr(unsafe.Pointer(psrc)), uintptr(unsafe.Pointer(&n)), 0, 0)
|
syscall.Syscall6(_glShaderSource.Addr(), 4, uintptr(s.V), 1, uintptr(unsafe.Pointer(psrc)), uintptr(unsafe.Pointer(&n)), 0, 0)
|
||||||
issue34474KeepAlive(psrc)
|
issue34474KeepAlive(psrc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) TexImage2D(target Enum, level int, internalFormat Enum, width int, height int, format Enum, ty Enum) {
|
func (f *Functions) TexImage2D(target Enum, level int, internalFormat Enum, width int, height int, format Enum, ty Enum) {
|
||||||
syscall.Syscall9(_glTexImage2D.Addr(), 9, uintptr(target), uintptr(level), uintptr(internalFormat), uintptr(width), uintptr(height), 0, uintptr(format), uintptr(ty), 0)
|
syscall.Syscall9(_glTexImage2D.Addr(), 9, uintptr(target), uintptr(level), uintptr(internalFormat), uintptr(width), uintptr(height), 0, uintptr(format), uintptr(ty), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) TexStorage2D(target Enum, levels int, internalFormat Enum, width, height int) {
|
func (f *Functions) TexStorage2D(target Enum, levels int, internalFormat Enum, width, height int) {
|
||||||
syscall.Syscall6(_glTexStorage2D.Addr(), 5, uintptr(target), uintptr(levels), uintptr(internalFormat), uintptr(width), uintptr(height), 0)
|
syscall.Syscall6(_glTexStorage2D.Addr(), 5, uintptr(target), uintptr(levels), uintptr(internalFormat), uintptr(width), uintptr(height), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty Enum, data []byte) {
|
func (c *Functions) TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty Enum, data []byte) {
|
||||||
d0 := &data[0]
|
d0 := &data[0]
|
||||||
syscall.Syscall9(_glTexSubImage2D.Addr(), 9, uintptr(target), uintptr(level), uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(format), uintptr(ty), uintptr(unsafe.Pointer(d0)))
|
syscall.Syscall9(_glTexSubImage2D.Addr(), 9, uintptr(target), uintptr(level), uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(format), uintptr(ty), uintptr(unsafe.Pointer(d0)))
|
||||||
issue34474KeepAlive(d0)
|
issue34474KeepAlive(d0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) TexParameteri(target, pname Enum, param int) {
|
func (c *Functions) TexParameteri(target, pname Enum, param int) {
|
||||||
syscall.Syscall(_glTexParameteri.Addr(), 3, uintptr(target), uintptr(pname), uintptr(param))
|
syscall.Syscall(_glTexParameteri.Addr(), 3, uintptr(target), uintptr(pname), uintptr(param))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) UniformBlockBinding(p Program, uniformBlockIndex uint, uniformBlockBinding uint) {
|
func (f *Functions) UniformBlockBinding(p Program, uniformBlockIndex uint, uniformBlockBinding uint) {
|
||||||
syscall.Syscall(_glUniformBlockBinding.Addr(), 3, uintptr(p.V), uintptr(uniformBlockIndex), uintptr(uniformBlockBinding))
|
syscall.Syscall(_glUniformBlockBinding.Addr(), 3, uintptr(p.V), uintptr(uniformBlockIndex), uintptr(uniformBlockBinding))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Uniform1f(dst Uniform, v float32) {
|
func (c *Functions) Uniform1f(dst Uniform, v float32) {
|
||||||
syscall.Syscall(_glUniform1f.Addr(), 2, uintptr(dst.V), uintptr(math.Float32bits(v)), 0)
|
syscall.Syscall(_glUniform1f.Addr(), 2, uintptr(dst.V), uintptr(math.Float32bits(v)), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Uniform1i(dst Uniform, v int) {
|
func (c *Functions) Uniform1i(dst Uniform, v int) {
|
||||||
syscall.Syscall(_glUniform1i.Addr(), 2, uintptr(dst.V), uintptr(v), 0)
|
syscall.Syscall(_glUniform1i.Addr(), 2, uintptr(dst.V), uintptr(v), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Uniform2f(dst Uniform, v0, v1 float32) {
|
func (c *Functions) Uniform2f(dst Uniform, v0, v1 float32) {
|
||||||
syscall.Syscall(_glUniform2f.Addr(), 3, uintptr(dst.V), uintptr(math.Float32bits(v0)), uintptr(math.Float32bits(v1)))
|
syscall.Syscall(_glUniform2f.Addr(), 3, uintptr(dst.V), uintptr(math.Float32bits(v0)), uintptr(math.Float32bits(v1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Uniform3f(dst Uniform, v0, v1, v2 float32) {
|
func (c *Functions) Uniform3f(dst Uniform, v0, v1, v2 float32) {
|
||||||
syscall.Syscall6(_glUniform3f.Addr(), 4, uintptr(dst.V), uintptr(math.Float32bits(v0)), uintptr(math.Float32bits(v1)), uintptr(math.Float32bits(v2)), 0, 0)
|
syscall.Syscall6(_glUniform3f.Addr(), 4, uintptr(dst.V), uintptr(math.Float32bits(v0)), uintptr(math.Float32bits(v1)), uintptr(math.Float32bits(v2)), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Uniform4f(dst Uniform, v0, v1, v2, v3 float32) {
|
func (c *Functions) Uniform4f(dst Uniform, v0, v1, v2, v3 float32) {
|
||||||
syscall.Syscall6(_glUniform4f.Addr(), 5, uintptr(dst.V), uintptr(math.Float32bits(v0)), uintptr(math.Float32bits(v1)), uintptr(math.Float32bits(v2)), uintptr(math.Float32bits(v3)), 0)
|
syscall.Syscall6(_glUniform4f.Addr(), 5, uintptr(dst.V), uintptr(math.Float32bits(v0)), uintptr(math.Float32bits(v1)), uintptr(math.Float32bits(v2)), uintptr(math.Float32bits(v3)), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) UseProgram(p Program) {
|
func (c *Functions) UseProgram(p Program) {
|
||||||
syscall.Syscall(_glUseProgram.Addr(), 1, uintptr(p.V), 0, 0)
|
syscall.Syscall(_glUseProgram.Addr(), 1, uintptr(p.V), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) UnmapBuffer(target Enum) bool {
|
func (f *Functions) UnmapBuffer(target Enum) bool {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride, offset int) {
|
func (c *Functions) VertexAttribPointer(dst Attrib, size int, ty Enum, normalized bool, stride, offset int) {
|
||||||
var norm uintptr
|
var norm uintptr
|
||||||
if normalized {
|
if normalized {
|
||||||
@@ -489,6 +703,7 @@ func (c *Functions) VertexAttribPointer(dst Attrib, size int, ty Enum, normalize
|
|||||||
}
|
}
|
||||||
syscall.Syscall6(_glVertexAttribPointer.Addr(), 6, uintptr(dst), uintptr(size), uintptr(ty), norm, uintptr(stride), uintptr(offset))
|
syscall.Syscall6(_glVertexAttribPointer.Addr(), 6, uintptr(dst), uintptr(size), uintptr(ty), norm, uintptr(stride), uintptr(offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Functions) Viewport(x, y, width, height int) {
|
func (c *Functions) Viewport(x, y, width, height int) {
|
||||||
syscall.Syscall6(_glViewport.Addr(), 4, uintptr(x), uintptr(y), uintptr(width), uintptr(height), 0, 0)
|
syscall.Syscall6(_glViewport.Addr(), 4, uintptr(x), uintptr(y), uintptr(width), uintptr(height), 0, 0)
|
||||||
}
|
}
|
||||||
@@ -501,6 +716,6 @@ func cString(s string) []byte {
|
|||||||
|
|
||||||
// issue34474KeepAlive calls runtime.KeepAlive as a
|
// issue34474KeepAlive calls runtime.KeepAlive as a
|
||||||
// workaround for golang.org/issue/34474.
|
// workaround for golang.org/issue/34474.
|
||||||
func issue34474KeepAlive(v interface{}) {
|
func issue34474KeepAlive(v any) {
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !js
|
//go:build !js
|
||||||
// +build !js
|
|
||||||
|
|
||||||
package gl
|
package gl
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -18,7 +18,7 @@ type Ops struct {
|
|||||||
// data contains the serialized operations.
|
// data contains the serialized operations.
|
||||||
data []byte
|
data []byte
|
||||||
// refs hold external references for operations.
|
// refs hold external references for operations.
|
||||||
refs []interface{}
|
refs []any
|
||||||
// stringRefs provides space for string references, pointers to which will
|
// stringRefs provides space for string references, pointers to which will
|
||||||
// be stored in refs. Storing a string directly in refs would cause a heap
|
// be stored in refs. Storing a string directly in refs would cause a heap
|
||||||
// allocation, to store the string header in an interface value. The backing
|
// allocation, to store the string header in an interface value. The backing
|
||||||
@@ -256,7 +256,7 @@ func PopOp(o *Ops, kind StackKind, sid StackID, macroID uint32) {
|
|||||||
o.stacks[kind].pop(sid)
|
o.stacks[kind].pop(sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Write1(o *Ops, n int, ref1 interface{}) []byte {
|
func Write1(o *Ops, n int, ref1 any) []byte {
|
||||||
o.data = append(o.data, make([]byte, n)...)
|
o.data = append(o.data, make([]byte, n)...)
|
||||||
o.refs = append(o.refs, ref1)
|
o.refs = append(o.refs, ref1)
|
||||||
return o.data[len(o.data)-n:]
|
return o.data[len(o.data)-n:]
|
||||||
@@ -269,20 +269,20 @@ func Write1String(o *Ops, n int, ref1 string) []byte {
|
|||||||
return o.data[len(o.data)-n:]
|
return o.data[len(o.data)-n:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func Write2(o *Ops, n int, ref1, ref2 interface{}) []byte {
|
func Write2(o *Ops, n int, ref1, ref2 any) []byte {
|
||||||
o.data = append(o.data, make([]byte, n)...)
|
o.data = append(o.data, make([]byte, n)...)
|
||||||
o.refs = append(o.refs, ref1, ref2)
|
o.refs = append(o.refs, ref1, ref2)
|
||||||
return o.data[len(o.data)-n:]
|
return o.data[len(o.data)-n:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func Write2String(o *Ops, n int, ref1 interface{}, ref2 string) []byte {
|
func Write2String(o *Ops, n int, ref1 any, ref2 string) []byte {
|
||||||
o.data = append(o.data, make([]byte, n)...)
|
o.data = append(o.data, make([]byte, n)...)
|
||||||
o.stringRefs = append(o.stringRefs, ref2)
|
o.stringRefs = append(o.stringRefs, ref2)
|
||||||
o.refs = append(o.refs, ref1, &o.stringRefs[len(o.stringRefs)-1])
|
o.refs = append(o.refs, ref1, &o.stringRefs[len(o.stringRefs)-1])
|
||||||
return o.data[len(o.data)-n:]
|
return o.data[len(o.data)-n:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func Write3(o *Ops, n int, ref1, ref2, ref3 interface{}) []byte {
|
func Write3(o *Ops, n int, ref1, ref2, ref3 any) []byte {
|
||||||
o.data = append(o.data, make([]byte, n)...)
|
o.data = append(o.data, make([]byte, n)...)
|
||||||
o.refs = append(o.refs, ref1, ref2, ref3)
|
o.refs = append(o.refs, ref1, ref2, ref3)
|
||||||
return o.data[len(o.data)-n:]
|
return o.data[len(o.data)-n:]
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type Reader struct {
|
|||||||
type EncodedOp struct {
|
type EncodedOp struct {
|
||||||
Key Key
|
Key Key
|
||||||
Data []byte
|
Data []byte
|
||||||
Refs []interface{}
|
Refs []any
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key is a unique key for a given op.
|
// Key is a unique key for a given op.
|
||||||
@@ -175,7 +175,7 @@ func (op *opMacroDef) decode(data []byte) {
|
|||||||
op.endpc.refs = bo.Uint32(data[5:])
|
op.endpc.refs = bo.Uint32(data[5:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *macroOp) decode(data []byte, refs []interface{}) {
|
func (m *macroOp) decode(data []byte, refs []any) {
|
||||||
if len(data) < TypeCallLen || len(refs) < 1 || OpType(data[0]) != TypeCall {
|
if len(data) < TypeCallLen || len(refs) < 1 || OpType(data[0]) != TypeCall {
|
||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-10
@@ -87,7 +87,7 @@ func (qs *StrokeQuads) lineTo(pt f32.Point) {
|
|||||||
func (qs *StrokeQuads) arc(f1, f2 f32.Point, angle float32) {
|
func (qs *StrokeQuads) arc(f1, f2 f32.Point, angle float32) {
|
||||||
pen := qs.pen()
|
pen := qs.pen()
|
||||||
m, segments := ArcTransform(pen, f1.Add(pen), f2.Add(pen), angle)
|
m, segments := ArcTransform(pen, f1.Add(pen), f2.Add(pen), angle)
|
||||||
for i := 0; i < segments; i++ {
|
for range segments {
|
||||||
p0 := qs.pen()
|
p0 := qs.pen()
|
||||||
p1 := m.Transform(p0)
|
p1 := m.Transform(p0)
|
||||||
p2 := m.Transform(p1)
|
p2 := m.Transform(p1)
|
||||||
@@ -327,10 +327,26 @@ func strokePathNorm(p0, p1, p2 f32.Point, t, d float32) f32.Point {
|
|||||||
func rot90CW(p f32.Point) f32.Point { return f32.Pt(+p.Y, -p.X) }
|
func rot90CW(p f32.Point) f32.Point { return f32.Pt(+p.Y, -p.X) }
|
||||||
|
|
||||||
func normPt(p f32.Point, l float32) f32.Point {
|
func normPt(p f32.Point, l float32) f32.Point {
|
||||||
|
if (p.X == 0 && p.Y == 0) || l == 0 {
|
||||||
|
return f32.Point{}
|
||||||
|
}
|
||||||
|
isVerticalUnit := p.X == 0 && (p.Y == l || p.Y == -l)
|
||||||
|
isHorizontalUnit := p.Y == 0 && (p.X == l || p.X == -l)
|
||||||
|
if isVerticalUnit || isHorizontalUnit {
|
||||||
|
if math.Signbit(float64(l)) {
|
||||||
|
return f32.Point{X: -p.X, Y: -p.Y}
|
||||||
|
} else {
|
||||||
|
return f32.Point{X: p.X, Y: p.Y}
|
||||||
|
}
|
||||||
|
}
|
||||||
d := math.Hypot(float64(p.X), float64(p.Y))
|
d := math.Hypot(float64(p.X), float64(p.Y))
|
||||||
l64 := float64(l)
|
l64 := float64(l)
|
||||||
if math.Abs(d-l64) < 1e-10 {
|
if math.Abs(d-l64) < 1e-10 {
|
||||||
return f32.Point{}
|
if math.Signbit(float64(l)) {
|
||||||
|
return f32.Point{X: -p.X, Y: -p.Y}
|
||||||
|
} else {
|
||||||
|
return f32.Point{X: p.X, Y: p.Y}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
n := float32(l64 / d)
|
n := float32(l64 / d)
|
||||||
return f32.Point{X: p.X * n, Y: p.Y * n}
|
return f32.Point{X: p.X * n, Y: p.Y * n}
|
||||||
@@ -437,7 +453,6 @@ func flattenQuadBezier(qs StrokeQuads, p0, p1, p2 f32.Point, d, flatness float32
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (qs *StrokeQuads) addLine(p0, ctrl, p1 f32.Point, t, d float32) {
|
func (qs *StrokeQuads) addLine(p0, ctrl, p1 f32.Point, t, d float32) {
|
||||||
|
|
||||||
switch i := len(*qs); i {
|
switch i := len(*qs); i {
|
||||||
case 0:
|
case 0:
|
||||||
p0 = p0.Add(strokePathNorm(p0, ctrl, p1, 0, d))
|
p0 = p0.Add(strokePathNorm(p0, ctrl, p1, 0, d))
|
||||||
@@ -470,7 +485,6 @@ func quadInterp(p, q f32.Point, t float32) f32.Point {
|
|||||||
// quadBezierSplit returns the pair of triplets (from,ctrl,to) Bézier curve,
|
// quadBezierSplit returns the pair of triplets (from,ctrl,to) Bézier curve,
|
||||||
// split before (resp. after) the provided parametric t value.
|
// split before (resp. after) the provided parametric t value.
|
||||||
func quadBezierSplit(p0, p1, p2 f32.Point, t float32) (f32.Point, f32.Point, f32.Point, f32.Point, f32.Point, f32.Point) {
|
func quadBezierSplit(p0, p1, p2 f32.Point, t float32) (f32.Point, f32.Point, f32.Point, f32.Point, f32.Point, f32.Point) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
b0 = p0
|
b0 = p0
|
||||||
b1 = quadInterp(p0, p1, t)
|
b1 = quadInterp(p0, p1, t)
|
||||||
@@ -574,12 +588,10 @@ func ArcTransform(p, f1, f2 f32.Point, angle float32) (transform f32.Affine2D, s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
θ := angle / float32(segments)
|
||||||
θ = angle / float32(segments)
|
ref := f32.AffineId() // transform from absolute frame to ellipse-based one
|
||||||
ref f32.Affine2D // transform from absolute frame to ellipse-based one
|
rot := f32.AffineId() // rotation matrix for each segment
|
||||||
rot f32.Affine2D // rotation matrix for each segment
|
inv := f32.AffineId() // transform from ellipse-based frame to absolute one
|
||||||
inv f32.Affine2D // transform from ellipse-based frame to absolute one
|
|
||||||
)
|
|
||||||
center := f32.Point{
|
center := f32.Point{
|
||||||
X: 0.5 * (f1.X + f2.X),
|
X: 0.5 * (f1.X + f2.X),
|
||||||
Y: 0.5 * (f1.Y + f2.Y),
|
Y: 0.5 * (f1.Y + f2.Y),
|
||||||
|
|||||||
@@ -9,6 +9,111 @@ import (
|
|||||||
"gioui.org/internal/f32"
|
"gioui.org/internal/f32"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestNormPt(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
l float32
|
||||||
|
ptIn, ptOut f32.Point
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
// l!=0 && X=Y=0
|
||||||
|
{l: 10, ptIn: f32.Point{X: 0, Y: 0}, ptOut: f32.Point{X: 0, Y: 0}},
|
||||||
|
{l: -10, ptIn: f32.Point{X: 0, Y: 0}, ptOut: f32.Point{X: 0, Y: 0}},
|
||||||
|
|
||||||
|
// l>0 & X
|
||||||
|
{l: +20, ptIn: f32.Point{X: +30, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: +20, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: +10, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -10, Y: 0}, ptOut: f32.Point{X: -20, Y: 0}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -20, Y: 0}, ptOut: f32.Point{X: -20, Y: 0}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -30, Y: 0}, ptOut: f32.Point{X: -20, Y: 0}},
|
||||||
|
|
||||||
|
// l<0 & X
|
||||||
|
{l: -20, ptIn: f32.Point{X: +30, Y: 0}, ptOut: f32.Point{X: -20, Y: 0}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: +20, Y: 0}, ptOut: f32.Point{X: -20, Y: 0}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: +10, Y: 0}, ptOut: f32.Point{X: -20, Y: 0}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -10, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -20, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -30, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
||||||
|
|
||||||
|
// l>0 & Y
|
||||||
|
{l: +20, ptIn: f32.Point{X: 0, Y: +30}, ptOut: f32.Point{X: 0, Y: +20}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: 0, Y: +20}, ptOut: f32.Point{X: 0, Y: +20}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: 0, Y: +10}, ptOut: f32.Point{X: 0, Y: +20}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: 0, Y: -10}, ptOut: f32.Point{X: 0, Y: -20}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: 0, Y: -20}, ptOut: f32.Point{X: 0, Y: -20}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: 0, Y: -30}, ptOut: f32.Point{X: 0, Y: -20}},
|
||||||
|
|
||||||
|
// l<0 & Y
|
||||||
|
{l: -20, ptIn: f32.Point{X: 0, Y: +30}, ptOut: f32.Point{X: 0, Y: -20}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: 0, Y: +20}, ptOut: f32.Point{X: 0, Y: -20}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: 0, Y: +10}, ptOut: f32.Point{X: 0, Y: -20}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: 0, Y: -10}, ptOut: f32.Point{X: 0, Y: +20}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: 0, Y: -20}, ptOut: f32.Point{X: 0, Y: +20}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: 0, Y: -30}, ptOut: f32.Point{X: 0, Y: +20}},
|
||||||
|
|
||||||
|
// l>0 && X=Y
|
||||||
|
{l: +20, ptIn: f32.Point{X: +90, Y: +90}, ptOut: f32.Point{X: +14.142137, Y: +14.142137}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: +30, Y: +30}, ptOut: f32.Point{X: +14.142136, Y: +14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: +20, Y: +20}, ptOut: f32.Point{X: +14.142136, Y: +14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: +10, Y: +10}, ptOut: f32.Point{X: +14.142136, Y: +14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -10, Y: -10}, ptOut: f32.Point{X: -14.142136, Y: -14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -20, Y: -20}, ptOut: f32.Point{X: -14.142136, Y: -14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -30, Y: -30}, ptOut: f32.Point{X: -14.142136, Y: -14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -90, Y: -90}, ptOut: f32.Point{X: -14.142137, Y: -14.142137}},
|
||||||
|
|
||||||
|
// l>0 && X=-Y
|
||||||
|
{l: +20, ptIn: f32.Point{X: +90, Y: -90}, ptOut: f32.Point{X: +14.142137, Y: -14.142137}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: +30, Y: -30}, ptOut: f32.Point{X: +14.142136, Y: -14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: +20, Y: -20}, ptOut: f32.Point{X: +14.142136, Y: -14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: +10, Y: -10}, ptOut: f32.Point{X: +14.142136, Y: -14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -10, Y: +10}, ptOut: f32.Point{X: -14.142136, Y: +14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -20, Y: +20}, ptOut: f32.Point{X: -14.142136, Y: +14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -30, Y: +30}, ptOut: f32.Point{X: -14.142136, Y: +14.142136}},
|
||||||
|
{l: +20, ptIn: f32.Point{X: -90, Y: +90}, ptOut: f32.Point{X: -14.142137, Y: +14.142137}},
|
||||||
|
|
||||||
|
// l<0 && X=Y
|
||||||
|
{l: -20, ptIn: f32.Point{X: +90, Y: +90}, ptOut: f32.Point{X: -14.142137, Y: -14.142137}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: +30, Y: +30}, ptOut: f32.Point{X: -14.142136, Y: -14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: +20, Y: +20}, ptOut: f32.Point{X: -14.142136, Y: -14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: +10, Y: +10}, ptOut: f32.Point{X: -14.142136, Y: -14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -10, Y: -10}, ptOut: f32.Point{X: +14.142136, Y: +14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -20, Y: -20}, ptOut: f32.Point{X: +14.142136, Y: +14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -30, Y: -30}, ptOut: f32.Point{X: +14.142136, Y: +14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -90, Y: -90}, ptOut: f32.Point{X: +14.142137, Y: +14.142137}},
|
||||||
|
|
||||||
|
// l<0 && X=-Y
|
||||||
|
{l: -20, ptIn: f32.Point{X: +90, Y: -90}, ptOut: f32.Point{X: -14.142137, Y: +14.142137}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: +30, Y: -30}, ptOut: f32.Point{X: -14.142136, Y: +14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: +20, Y: -20}, ptOut: f32.Point{X: -14.142136, Y: +14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: +10, Y: -10}, ptOut: f32.Point{X: -14.142136, Y: +14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -10, Y: +10}, ptOut: f32.Point{X: +14.142136, Y: -14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -20, Y: +20}, ptOut: f32.Point{X: +14.142136, Y: -14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -30, Y: +30}, ptOut: f32.Point{X: +14.142136, Y: -14.142136}},
|
||||||
|
{l: -20, ptIn: f32.Point{X: -90, Y: +90}, ptOut: f32.Point{X: +14.142137, Y: -14.142137}},
|
||||||
|
|
||||||
|
// l!=0 && Hypot=l
|
||||||
|
{l: 5, ptIn: f32.Point{X: 3, Y: 4}, ptOut: f32.Point{X: 3, Y: 4}},
|
||||||
|
{l: 5, ptIn: f32.Point{X: 3, Y: -4}, ptOut: f32.Point{X: 3, Y: -4}},
|
||||||
|
{l: 5, ptIn: f32.Point{X: -3, Y: -4}, ptOut: f32.Point{X: -3, Y: -4}},
|
||||||
|
{l: 5, ptIn: f32.Point{X: -3, Y: 4}, ptOut: f32.Point{X: -3, Y: 4}},
|
||||||
|
{l: -5, ptIn: f32.Point{X: 3, Y: 4}, ptOut: f32.Point{X: -3, Y: -4}},
|
||||||
|
{l: -5, ptIn: f32.Point{X: 3, Y: -4}, ptOut: f32.Point{X: -3, Y: 4}},
|
||||||
|
{l: -5, ptIn: f32.Point{X: -3, Y: -4}, ptOut: f32.Point{X: 3, Y: 4}},
|
||||||
|
{l: -5, ptIn: f32.Point{X: -3, Y: 4}, ptOut: f32.Point{X: 3, Y: -4}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, s := range scenarios {
|
||||||
|
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||||
|
actual := normPt(s.ptIn, s.l)
|
||||||
|
if actual != s.ptOut {
|
||||||
|
t.Errorf("in: %v*%v, expected: %v, actual: %v", s.l, s.ptIn, s.ptOut, actual)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkSplitCubic(b *testing.B) {
|
func BenchmarkSplitCubic(b *testing.B) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
segments int
|
segments int
|
||||||
@@ -47,12 +152,11 @@ func BenchmarkSplitCubic(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
s := s
|
|
||||||
b.Run(strconv.Itoa(s.segments), func(b *testing.B) {
|
b.Run(strconv.Itoa(s.segments), func(b *testing.B) {
|
||||||
from, ctrl0, ctrl1, to := s.from, s.ctrl0, s.ctrl1, s.to
|
from, ctrl0, ctrl1, to := s.from, s.ctrl0, s.ctrl1, s.to
|
||||||
quads := make([]QuadSegment, s.segments)
|
quads := make([]QuadSegment, s.segments)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
quads = SplitCubic(from, ctrl0, ctrl1, to, quads[:0])
|
quads = SplitCubic(from, ctrl0, ctrl1, to, quads[:0])
|
||||||
}
|
}
|
||||||
if len(quads) != s.segments {
|
if len(quads) != s.segments {
|
||||||
|
|||||||
@@ -385,6 +385,7 @@ static VkResult vkQueuePresentKHR(PFN_vkQueuePresentKHR f, VkQueue queue, const
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1167,7 +1168,6 @@ func CreateFramebuffer(d Device, rp RenderPass, view ImageView, width, height in
|
|||||||
return nilFramebuffer, fmt.Errorf("vulkan: vkCreateFramebuffer: %w", err)
|
return nilFramebuffer, fmt.Errorf("vulkan: vkCreateFramebuffer: %w", err)
|
||||||
}
|
}
|
||||||
return fbo, nil
|
return fbo, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DestroyFramebuffer(d Device, f Framebuffer) {
|
func DestroyFramebuffer(d Device, f Framebuffer) {
|
||||||
@@ -1893,27 +1893,27 @@ func BuildWriteDescriptorSetBuffer(set DescriptorSet, binding int, typ Descripto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r PushConstantRange) StageFlags() ShaderStageFlags {
|
func PushConstantRangeStageFlags(r PushConstantRange) ShaderStageFlags {
|
||||||
return r.stageFlags
|
return r.stageFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r PushConstantRange) Offset() int {
|
func PushConstantRangeOffset(r PushConstantRange) int {
|
||||||
return int(r.offset)
|
return int(r.offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r PushConstantRange) Size() int {
|
func PushConstantRangeSize(r PushConstantRange) int {
|
||||||
return int(r.size)
|
return int(r.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p QueueFamilyProperties) Flags() QueueFlags {
|
func QueueFamilyPropertiesFlags(p QueueFamilyProperties) QueueFlags {
|
||||||
return p.queueFlags
|
return p.queueFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c SurfaceCapabilities) MinExtent() image.Point {
|
func SurfaceCapabilitiesMinExtent(c SurfaceCapabilities) image.Point {
|
||||||
return image.Pt(int(c.minImageExtent.width), int(c.minImageExtent.height))
|
return image.Pt(int(c.minImageExtent.width), int(c.minImageExtent.height))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c SurfaceCapabilities) MaxExtent() image.Point {
|
func SurfaceCapabilitiesMaxExtent(c SurfaceCapabilities) image.Point {
|
||||||
return image.Pt(int(c.maxImageExtent.width), int(c.maxImageExtent.height))
|
return image.Pt(int(c.maxImageExtent.width), int(c.maxImageExtent.height))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ static VkResult vkCreateAndroidSurfaceKHR(PFN_vkCreateAndroidSurfaceKHR f, VkIns
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ static VkResult vkCreateWaylandSurfaceKHR(PFN_vkCreateWaylandSurfaceKHR f, VkIns
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ static VkResult vkCreateXlibSurfaceKHR(PFN_vkCreateXlibSurfaceKHR f, VkInstance
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
// Tag is the stable identifier for an event handler.
|
// Tag is the stable identifier for an event handler.
|
||||||
// For a handler h, the tag is typically &h.
|
// For a handler h, the tag is typically &h.
|
||||||
type Tag interface{}
|
type Tag any
|
||||||
|
|
||||||
// Event is the marker interface for events.
|
// Event is the marker interface for events.
|
||||||
type Event interface {
|
type Event interface {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package input
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"gioui.org/io/clipboard"
|
"gioui.org/io/clipboard"
|
||||||
"gioui.org/io/event"
|
"gioui.org/io/event"
|
||||||
@@ -60,10 +61,8 @@ func (q *clipboardQueue) ProcessWriteClipboard(req clipboard.WriteCmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *clipboardQueue) ProcessReadClipboard(state clipboardState, tag event.Tag) clipboardState {
|
func (q *clipboardQueue) ProcessReadClipboard(state clipboardState, tag event.Tag) clipboardState {
|
||||||
for _, k := range state.receivers {
|
if slices.Contains(state.receivers, tag) {
|
||||||
if k == tag {
|
return state
|
||||||
return state
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
n := len(state.receivers)
|
n := len(state.receivers)
|
||||||
state.receivers = append(state.receivers[:n:n], tag)
|
state.receivers = append(state.receivers[:n:n], tag)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func TestQueueProcessReadClipboard(t *testing.T) {
|
|||||||
assertClipboardReadCmd(t, r, 1)
|
assertClipboardReadCmd(t, r, 1)
|
||||||
ops.Reset()
|
ops.Reset()
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for range 3 {
|
||||||
// No ReadCmd
|
// No ReadCmd
|
||||||
// One receiver must still wait for response
|
// One receiver must still wait for response
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -4,6 +4,7 @@ package input
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"gioui.org/f32"
|
"gioui.org/f32"
|
||||||
@@ -280,6 +281,7 @@ func (q *keyQueue) Focus(handlers map[event.Tag]*handler, state keyState, focus
|
|||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
state.content = EditorState{}
|
state.content = EditorState{}
|
||||||
|
state.content.Selection.Transform = f32.AffineId()
|
||||||
var evts []taggedEvent
|
var evts []taggedEvent
|
||||||
if state.focus != nil {
|
if state.focus != nil {
|
||||||
evts = append(evts, taggedEvent{tag: state.focus, event: key.FocusEvent{Focus: false}})
|
evts = append(evts, taggedEvent{tag: state.focus, event: key.FocusEvent{Focus: false}})
|
||||||
@@ -304,10 +306,8 @@ func (s keyState) softKeyboard(show bool) keyState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (k *keyFilter) Add(f key.Filter) {
|
func (k *keyFilter) Add(f key.Filter) {
|
||||||
for _, f2 := range *k {
|
if slices.Contains(*k, f) {
|
||||||
if f == f2 {
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*k = append(*k, f)
|
*k = append(*k, f)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,9 +251,10 @@ func TestFocusScroll(t *testing.T) {
|
|||||||
filters := []event.Filter{
|
filters := []event.Filter{
|
||||||
key.FocusFilter{Target: h},
|
key.FocusFilter{Target: h},
|
||||||
pointer.Filter{
|
pointer.Filter{
|
||||||
Target: h,
|
Target: h,
|
||||||
Kinds: pointer.Scroll,
|
Kinds: pointer.Scroll,
|
||||||
ScrollBounds: image.Rect(-100, -100, 100, 100),
|
ScrollX: pointer.ScrollRange{Min: -100, Max: +100},
|
||||||
|
ScrollY: pointer.ScrollRange{Min: -100, Max: +100},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
events(r, -1, filters...)
|
events(r, -1, filters...)
|
||||||
|
|||||||
+52
-45
@@ -5,6 +5,7 @@ package input
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"gioui.org/f32"
|
"gioui.org/f32"
|
||||||
f32internal "gioui.org/internal/f32"
|
f32internal "gioui.org/internal/f32"
|
||||||
@@ -72,7 +73,7 @@ type pointerHandler struct {
|
|||||||
type pointerFilter struct {
|
type pointerFilter struct {
|
||||||
kinds pointer.Kind
|
kinds pointer.Kind
|
||||||
// min and max horizontal/vertical scroll
|
// min and max horizontal/vertical scroll
|
||||||
scrollRange image.Rectangle
|
scrollX, scrollY pointer.ScrollRange
|
||||||
|
|
||||||
sourceMimes []string
|
sourceMimes []string
|
||||||
targetMimes []string
|
targetMimes []string
|
||||||
@@ -143,7 +144,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *pointerCollector) resetState() {
|
func (c *pointerCollector) resetState() {
|
||||||
c.state = collectState{}
|
c.state = collectState{
|
||||||
|
t: f32.AffineId(),
|
||||||
|
}
|
||||||
c.nodeStack = c.nodeStack[:0]
|
c.nodeStack = c.nodeStack[:0]
|
||||||
// Pop every node except the root.
|
// Pop every node except the root.
|
||||||
if len(c.q.hitTree) > 0 {
|
if len(c.q.hitTree) > 0 {
|
||||||
@@ -257,6 +260,11 @@ func (q *pointerQueue) grab(state pointerState, req pointer.GrabCmd) (pointerSta
|
|||||||
if !p.pressed || p.id != req.ID {
|
if !p.pressed || p.id != req.ID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// Verify that the grabber is among the handlers.
|
||||||
|
found := slices.Contains(p.handlers, req.Tag)
|
||||||
|
if !found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Drop other handlers that lost their grab.
|
// Drop other handlers that lost their grab.
|
||||||
for i := len(p.handlers) - 1; i >= 0; i-- {
|
for i := len(p.handlers) - 1; i >= 0; i-- {
|
||||||
if tag := p.handlers[i]; tag != req.Tag {
|
if tag := p.handlers[i]; tag != req.Tag {
|
||||||
@@ -282,22 +290,19 @@ func (c *pointerCollector) inputOp(tag event.Tag, state *pointerHandler) {
|
|||||||
func (p *pointerFilter) Add(f event.Filter) {
|
func (p *pointerFilter) Add(f event.Filter) {
|
||||||
switch f := f.(type) {
|
switch f := f.(type) {
|
||||||
case transfer.SourceFilter:
|
case transfer.SourceFilter:
|
||||||
for _, m := range p.sourceMimes {
|
if slices.Contains(p.sourceMimes, f.Type) {
|
||||||
if m == f.Type {
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
p.sourceMimes = append(p.sourceMimes, f.Type)
|
p.sourceMimes = append(p.sourceMimes, f.Type)
|
||||||
case transfer.TargetFilter:
|
case transfer.TargetFilter:
|
||||||
for _, m := range p.targetMimes {
|
if slices.Contains(p.targetMimes, f.Type) {
|
||||||
if m == f.Type {
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
p.targetMimes = append(p.targetMimes, f.Type)
|
p.targetMimes = append(p.targetMimes, f.Type)
|
||||||
case pointer.Filter:
|
case pointer.Filter:
|
||||||
p.kinds = p.kinds | f.Kinds
|
p.kinds = p.kinds | f.Kinds
|
||||||
p.scrollRange = p.scrollRange.Union(f.ScrollBounds)
|
p.scrollX = p.scrollX.Union(f.ScrollX)
|
||||||
|
p.scrollY = p.scrollY.Union(f.ScrollY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,16 +313,12 @@ func (p *pointerFilter) Matches(e event.Event) bool {
|
|||||||
case transfer.CancelEvent, transfer.InitiateEvent:
|
case transfer.CancelEvent, transfer.InitiateEvent:
|
||||||
return len(p.sourceMimes) > 0 || len(p.targetMimes) > 0
|
return len(p.sourceMimes) > 0 || len(p.targetMimes) > 0
|
||||||
case transfer.RequestEvent:
|
case transfer.RequestEvent:
|
||||||
for _, t := range p.sourceMimes {
|
if slices.Contains(p.sourceMimes, e.Type) {
|
||||||
if t == e.Type {
|
return true
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case transfer.DataEvent:
|
case transfer.DataEvent:
|
||||||
for _, t := range p.targetMimes {
|
if slices.Contains(p.targetMimes, e.Type) {
|
||||||
if t == e.Type {
|
return true
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -325,7 +326,8 @@ func (p *pointerFilter) Matches(e event.Event) bool {
|
|||||||
|
|
||||||
func (p *pointerFilter) Merge(p2 pointerFilter) {
|
func (p *pointerFilter) Merge(p2 pointerFilter) {
|
||||||
p.kinds = p.kinds | p2.kinds
|
p.kinds = p.kinds | p2.kinds
|
||||||
p.scrollRange = p.scrollRange.Union(p2.scrollRange)
|
p.scrollX = p.scrollX.Union(p2.scrollX)
|
||||||
|
p.scrollY = p.scrollY.Union(p2.scrollY)
|
||||||
p.sourceMimes = append(p.sourceMimes, p2.sourceMimes...)
|
p.sourceMimes = append(p.sourceMimes, p2.sourceMimes...)
|
||||||
p.targetMimes = append(p.targetMimes, p2.targetMimes...)
|
p.targetMimes = append(p.targetMimes, p2.targetMimes...)
|
||||||
}
|
}
|
||||||
@@ -333,8 +335,8 @@ func (p *pointerFilter) Merge(p2 pointerFilter) {
|
|||||||
// clampScroll splits a scroll distance in the remaining scroll and the
|
// clampScroll splits a scroll distance in the remaining scroll and the
|
||||||
// scroll accepted by the filter.
|
// scroll accepted by the filter.
|
||||||
func (p *pointerFilter) clampScroll(scroll f32.Point) (left, scrolled f32.Point) {
|
func (p *pointerFilter) clampScroll(scroll f32.Point) (left, scrolled f32.Point) {
|
||||||
left.X, scrolled.X = clampSplit(scroll.X, p.scrollRange.Min.X, p.scrollRange.Max.X)
|
left.X, scrolled.X = clampSplit(scroll.X, p.scrollX.Min, p.scrollX.Max)
|
||||||
left.Y, scrolled.Y = clampSplit(scroll.Y, p.scrollRange.Min.Y, p.scrollRange.Max.Y)
|
left.Y, scrolled.Y = clampSplit(scroll.Y, p.scrollY.Min, p.scrollY.Max)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,7 +413,7 @@ func (q *pointerQueue) offerData(handlers map[event.Tag]*handler, state pointerS
|
|||||||
},
|
},
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
state.pointers = append([]pointerInfo{}, state.pointers...)
|
state.pointers = slices.Clone(state.pointers)
|
||||||
state.pointers[i], evts = q.deliverTransferCancelEvent(handlers, p, evts)
|
state.pointers[i], evts = q.deliverTransferCancelEvent(handlers, p, evts)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -603,7 +605,7 @@ func (q *pointerQueue) reset() {
|
|||||||
for k, ids := range q.semantic.contentIDs {
|
for k, ids := range q.semantic.contentIDs {
|
||||||
for i := len(ids) - 1; i >= 0; i-- {
|
for i := len(ids) - 1; i >= 0; i-- {
|
||||||
if !ids[i].used {
|
if !ids[i].used {
|
||||||
ids = append(ids[:i], ids[i+1:]...)
|
ids = slices.Delete(ids, i, i+1)
|
||||||
} else {
|
} else {
|
||||||
ids[i].used = false
|
ids[i].used = false
|
||||||
}
|
}
|
||||||
@@ -634,7 +636,7 @@ func (q *pointerQueue) Frame(handlers map[event.Tag]*handler, state pointerState
|
|||||||
changed := false
|
changed := false
|
||||||
p, evts, state.cursor, changed = q.deliverEnterLeaveEvents(handlers, state.cursor, p, evts, p.last)
|
p, evts, state.cursor, changed = q.deliverEnterLeaveEvents(handlers, state.cursor, p, evts, p.last)
|
||||||
if changed {
|
if changed {
|
||||||
state.pointers = append([]pointerInfo{}, state.pointers...)
|
state.pointers = slices.Clone(state.pointers)
|
||||||
state.pointers[i] = p
|
state.pointers[i] = p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -737,6 +739,10 @@ func (q *pointerQueue) Push(handlers map[event.Tag]*handler, state pointerState,
|
|||||||
state.pointers = nil
|
state.pointers = nil
|
||||||
return state, evts
|
return state, evts
|
||||||
}
|
}
|
||||||
|
if e.Kind == pointer.Scroll {
|
||||||
|
// Scroll events are not bound to a pointer; see pointer.Event.PointerID.
|
||||||
|
return state, q.deliverScrollEvent(handlers, evts, e)
|
||||||
|
}
|
||||||
state, pidx := state.pointerOf(e)
|
state, pidx := state.pointerOf(e)
|
||||||
p := state.pointers[pidx]
|
p := state.pointers[pidx]
|
||||||
|
|
||||||
@@ -754,14 +760,13 @@ func (q *pointerQueue) Push(handlers map[event.Tag]*handler, state pointerState,
|
|||||||
if p.pressed {
|
if p.pressed {
|
||||||
p, evts = q.deliverDragEvent(handlers, p, evts)
|
p, evts = q.deliverDragEvent(handlers, p, evts)
|
||||||
}
|
}
|
||||||
|
case pointer.Leave:
|
||||||
|
p, evts, state.cursor, _ = q.deliverEnterLeaveEvents(handlers, state.cursor, p, evts, e)
|
||||||
case pointer.Release:
|
case pointer.Release:
|
||||||
evts = q.deliverEvent(handlers, p, evts, e)
|
evts = q.deliverEvent(handlers, p, evts, e)
|
||||||
p.pressed = false
|
p.pressed = false
|
||||||
p, evts, state.cursor, _ = q.deliverEnterLeaveEvents(handlers, state.cursor, p, evts, e)
|
p, evts, state.cursor, _ = q.deliverEnterLeaveEvents(handlers, state.cursor, p, evts, e)
|
||||||
p, evts = q.deliverDropEvent(handlers, p, evts)
|
p, evts = q.deliverDropEvent(handlers, p, evts)
|
||||||
case pointer.Scroll:
|
|
||||||
p, evts, state.cursor, _ = q.deliverEnterLeaveEvents(handlers, state.cursor, p, evts, e)
|
|
||||||
evts = q.deliverEvent(handlers, p, evts, e)
|
|
||||||
default:
|
default:
|
||||||
panic("unsupported pointer event type")
|
panic("unsupported pointer event type")
|
||||||
}
|
}
|
||||||
@@ -770,19 +775,29 @@ func (q *pointerQueue) Push(handlers map[event.Tag]*handler, state pointerState,
|
|||||||
|
|
||||||
if !p.pressed && len(p.entered) == 0 {
|
if !p.pressed && len(p.entered) == 0 {
|
||||||
// No longer need to track pointer.
|
// No longer need to track pointer.
|
||||||
state.pointers = append(state.pointers[:pidx:pidx], state.pointers[pidx+1:]...)
|
state.pointers = slices.Concat(state.pointers[:pidx:pidx], state.pointers[pidx+1:])
|
||||||
} else {
|
} else {
|
||||||
state.pointers = append([]pointerInfo{}, state.pointers...)
|
state.pointers = slices.Clone(state.pointers)
|
||||||
state.pointers[pidx] = p
|
state.pointers[pidx] = p
|
||||||
}
|
}
|
||||||
return state, evts
|
return state, evts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deliverScrollEvent delivers scroll events to the handlers hit by the event coordinate.
|
||||||
|
func (q *pointerQueue) deliverScrollEvent(handlers map[event.Tag]*handler, evts []taggedEvent, e pointer.Event) []taggedEvent {
|
||||||
|
var hits []event.Tag
|
||||||
|
q.hitTest(e.Position, func(n *hitNode) bool {
|
||||||
|
if _, ok := handlers[n.tag]; ok {
|
||||||
|
hits = addHandler(hits, n.tag)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return q.deliverEvent(handlers, pointerInfo{handlers: hits}, evts, e)
|
||||||
|
}
|
||||||
|
|
||||||
func (q *pointerQueue) deliverEvent(handlers map[event.Tag]*handler, p pointerInfo, evts []taggedEvent, e pointer.Event) []taggedEvent {
|
func (q *pointerQueue) deliverEvent(handlers map[event.Tag]*handler, p pointerInfo, evts []taggedEvent, e pointer.Event) []taggedEvent {
|
||||||
foremost := true
|
|
||||||
if p.pressed && len(p.handlers) == 1 {
|
if p.pressed && len(p.handlers) == 1 {
|
||||||
e.Priority = pointer.Grabbed
|
e.Priority = pointer.Grabbed
|
||||||
foremost = false
|
|
||||||
}
|
}
|
||||||
scroll := e.Scroll
|
scroll := e.Scroll
|
||||||
for _, k := range p.handlers {
|
for _, k := range p.handlers {
|
||||||
@@ -801,10 +816,6 @@ func (q *pointerQueue) deliverEvent(handlers map[event.Tag]*handler, p pointerIn
|
|||||||
scroll, e.Scroll = f.clampScroll(scroll)
|
scroll, e.Scroll = f.clampScroll(scroll)
|
||||||
}
|
}
|
||||||
e := e
|
e := e
|
||||||
if foremost {
|
|
||||||
foremost = false
|
|
||||||
e.Priority = pointer.Foremost
|
|
||||||
}
|
|
||||||
e.Position = q.invTransform(h.pointer.areaPlusOne-1, e.Position)
|
e.Position = q.invTransform(h.pointer.areaPlusOne-1, e.Position)
|
||||||
evts = append(evts, taggedEvent{event: e, tag: k})
|
evts = append(evts, taggedEvent{event: e, tag: k})
|
||||||
}
|
}
|
||||||
@@ -814,7 +825,7 @@ func (q *pointerQueue) deliverEvent(handlers map[event.Tag]*handler, p pointerIn
|
|||||||
func (q *pointerQueue) deliverEnterLeaveEvents(handlers map[event.Tag]*handler, cursor pointer.Cursor, p pointerInfo, evts []taggedEvent, e pointer.Event) (pointerInfo, []taggedEvent, pointer.Cursor, bool) {
|
func (q *pointerQueue) deliverEnterLeaveEvents(handlers map[event.Tag]*handler, cursor pointer.Cursor, p pointerInfo, evts []taggedEvent, e pointer.Event) (pointerInfo, []taggedEvent, pointer.Cursor, bool) {
|
||||||
changed := false
|
changed := false
|
||||||
var hits []event.Tag
|
var hits []event.Tag
|
||||||
if e.Source != pointer.Mouse && !p.pressed && e.Kind != pointer.Press {
|
if e.Kind == pointer.Leave || e.Source != pointer.Mouse && !p.pressed && e.Kind != pointer.Press {
|
||||||
// Consider non-mouse pointers leaving when they're released.
|
// Consider non-mouse pointers leaving when they're released.
|
||||||
} else {
|
} else {
|
||||||
var transSrc *pointerFilter
|
var transSrc *pointerFilter
|
||||||
@@ -968,10 +979,8 @@ func searchTag(tags []event.Tag, tag event.Tag) (int, bool) {
|
|||||||
|
|
||||||
// addHandler adds tag to the slice if not present.
|
// addHandler adds tag to the slice if not present.
|
||||||
func addHandler(tags []event.Tag, tag event.Tag) []event.Tag {
|
func addHandler(tags []event.Tag, tag event.Tag) []event.Tag {
|
||||||
for _, t := range tags {
|
if slices.Contains(tags, tag) {
|
||||||
if t == tag {
|
return tags
|
||||||
return tags
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return append(tags, tag)
|
return append(tags, tag)
|
||||||
}
|
}
|
||||||
@@ -979,10 +988,8 @@ func addHandler(tags []event.Tag, tag event.Tag) []event.Tag {
|
|||||||
// firstMimeMatch returns the first type match between src and tgt.
|
// firstMimeMatch returns the first type match between src and tgt.
|
||||||
func firstMimeMatch(src, tgt *pointerFilter) (first string, matched bool) {
|
func firstMimeMatch(src, tgt *pointerFilter) (first string, matched bool) {
|
||||||
for _, m1 := range tgt.targetMimes {
|
for _, m1 := range tgt.targetMimes {
|
||||||
for _, m2 := range src.sourceMimes {
|
if slices.Contains(src.sourceMimes, m1) {
|
||||||
if m1 == m2 {
|
return m1, true
|
||||||
return m1, true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
|
|||||||
+167
-22
@@ -97,6 +97,39 @@ func TestPointerDragNegative(t *testing.T) {
|
|||||||
assertEventPointerTypeSequence(t, events(&r, -1, f), pointer.Enter, pointer.Press, pointer.Leave, pointer.Drag)
|
assertEventPointerTypeSequence(t, events(&r, -1, f), pointer.Enter, pointer.Press, pointer.Leave, pointer.Drag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIgnoredGrab(t *testing.T) {
|
||||||
|
handler1 := new(int)
|
||||||
|
handler2 := new(int)
|
||||||
|
var ops op.Ops
|
||||||
|
|
||||||
|
filter := func(t event.Tag) event.Filter {
|
||||||
|
return pointer.Filter{Target: t, Kinds: pointer.Press | pointer.Release | pointer.Cancel}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.Op(&ops, handler1)
|
||||||
|
event.Op(&ops, handler2)
|
||||||
|
var r Router
|
||||||
|
assertEventPointerTypeSequence(t, events(&r, -1, filter(handler1)), pointer.Cancel)
|
||||||
|
assertEventPointerTypeSequence(t, events(&r, -1, filter(handler2)), pointer.Cancel)
|
||||||
|
r.Frame(&ops)
|
||||||
|
r.Queue(
|
||||||
|
pointer.Event{
|
||||||
|
Kind: pointer.Press,
|
||||||
|
Position: f32.Pt(50, 50),
|
||||||
|
},
|
||||||
|
pointer.Event{
|
||||||
|
Kind: pointer.Release,
|
||||||
|
Position: f32.Pt(50, 50),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assertEventPointerTypeSequence(t, events(&r, 1, filter(handler1)), pointer.Press)
|
||||||
|
assertEventPointerTypeSequence(t, events(&r, 1, filter(handler2)), pointer.Press)
|
||||||
|
r.Source().Execute(pointer.GrabCmd{Tag: handler1})
|
||||||
|
r.Source().Execute(pointer.GrabCmd{Tag: handler2})
|
||||||
|
assertEventPointerTypeSequence(t, events(&r, 1, filter(handler1)), pointer.Release)
|
||||||
|
assertEventPointerTypeSequence(t, events(&r, 1, filter(handler2)), pointer.Cancel)
|
||||||
|
}
|
||||||
|
|
||||||
func TestPointerGrab(t *testing.T) {
|
func TestPointerGrab(t *testing.T) {
|
||||||
handler1 := new(int)
|
handler1 := new(int)
|
||||||
handler2 := new(int)
|
handler2 := new(int)
|
||||||
@@ -222,6 +255,45 @@ func TestPointerMove(t *testing.T) {
|
|||||||
assertEventPointerTypeSequence(t, events(&r, -1, filter(handler2)), pointer.Enter, pointer.Move, pointer.Leave, pointer.Cancel)
|
assertEventPointerTypeSequence(t, events(&r, -1, filter(handler2)), pointer.Enter, pointer.Move, pointer.Leave, pointer.Cancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPointerLeave(t *testing.T) {
|
||||||
|
handler := new(int)
|
||||||
|
var ops op.Ops
|
||||||
|
|
||||||
|
filter := pointer.Filter{
|
||||||
|
Target: handler,
|
||||||
|
Kinds: pointer.Move | pointer.Enter | pointer.Leave | pointer.Cancel,
|
||||||
|
}
|
||||||
|
defer clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops).Pop()
|
||||||
|
event.Op(&ops, handler)
|
||||||
|
|
||||||
|
var r Router
|
||||||
|
events(&r, -1, filter)
|
||||||
|
r.Frame(&ops)
|
||||||
|
r.Queue(
|
||||||
|
pointer.Event{
|
||||||
|
Kind: pointer.Move,
|
||||||
|
Source: pointer.Mouse,
|
||||||
|
PointerID: 1,
|
||||||
|
Position: f32.Pt(50, 50),
|
||||||
|
},
|
||||||
|
pointer.Event{
|
||||||
|
Kind: pointer.Leave,
|
||||||
|
Source: pointer.Mouse,
|
||||||
|
PointerID: 1,
|
||||||
|
Position: f32.Pt(50, 50),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assertEventPointerTypeSequence(t, events(&r, -1, filter), pointer.Enter, pointer.Move, pointer.Leave)
|
||||||
|
|
||||||
|
r.Queue(pointer.Event{
|
||||||
|
Kind: pointer.Move,
|
||||||
|
Source: pointer.Mouse,
|
||||||
|
PointerID: 1,
|
||||||
|
Position: f32.Pt(50, 50),
|
||||||
|
})
|
||||||
|
assertEventPointerTypeSequence(t, events(&r, -1, filter), pointer.Enter, pointer.Move)
|
||||||
|
}
|
||||||
|
|
||||||
func TestPointerTypes(t *testing.T) {
|
func TestPointerTypes(t *testing.T) {
|
||||||
handler := new(int)
|
handler := new(int)
|
||||||
var ops op.Ops
|
var ops op.Ops
|
||||||
@@ -300,9 +372,9 @@ func TestPointerPriority(t *testing.T) {
|
|||||||
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
||||||
f1 := func(t event.Tag) event.Filter {
|
f1 := func(t event.Tag) event.Filter {
|
||||||
return pointer.Filter{
|
return pointer.Filter{
|
||||||
Target: t,
|
Target: t,
|
||||||
Kinds: pointer.Scroll,
|
Kinds: pointer.Scroll,
|
||||||
ScrollBounds: image.Rectangle{Max: image.Point{X: 100}},
|
ScrollX: pointer.ScrollRange{Max: 100},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
events(&r, -1, f1(handler1))
|
events(&r, -1, f1(handler1))
|
||||||
@@ -311,9 +383,9 @@ func TestPointerPriority(t *testing.T) {
|
|||||||
r2 := clip.Rect(image.Rect(0, 0, 100, 50)).Push(&ops)
|
r2 := clip.Rect(image.Rect(0, 0, 100, 50)).Push(&ops)
|
||||||
f2 := func(t event.Tag) event.Filter {
|
f2 := func(t event.Tag) event.Filter {
|
||||||
return pointer.Filter{
|
return pointer.Filter{
|
||||||
Target: t,
|
Target: t,
|
||||||
Kinds: pointer.Scroll,
|
Kinds: pointer.Scroll,
|
||||||
ScrollBounds: image.Rectangle{Max: image.Point{X: 20}},
|
ScrollX: pointer.ScrollRange{Max: 20},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
events(&r, -1, f2(handler2))
|
events(&r, -1, f2(handler2))
|
||||||
@@ -324,9 +396,10 @@ func TestPointerPriority(t *testing.T) {
|
|||||||
r3 := clip.Rect(image.Rect(0, 100, 100, 200)).Push(&ops)
|
r3 := clip.Rect(image.Rect(0, 100, 100, 200)).Push(&ops)
|
||||||
f3 := func(t event.Tag) event.Filter {
|
f3 := func(t event.Tag) event.Filter {
|
||||||
return pointer.Filter{
|
return pointer.Filter{
|
||||||
Target: t,
|
Target: t,
|
||||||
Kinds: pointer.Scroll,
|
Kinds: pointer.Scroll,
|
||||||
ScrollBounds: image.Rectangle{Min: image.Point{X: -20, Y: -40}},
|
ScrollX: pointer.ScrollRange{Min: -20},
|
||||||
|
ScrollY: pointer.ScrollRange{Min: -40},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
events(&r, -1, f3(handler3))
|
events(&r, -1, f3(handler3))
|
||||||
@@ -366,9 +439,9 @@ func TestPointerPriority(t *testing.T) {
|
|||||||
assertEventPointerTypeSequence(t, hev1, pointer.Scroll, pointer.Scroll)
|
assertEventPointerTypeSequence(t, hev1, pointer.Scroll, pointer.Scroll)
|
||||||
assertEventPointerTypeSequence(t, hev2, pointer.Scroll)
|
assertEventPointerTypeSequence(t, hev2, pointer.Scroll)
|
||||||
assertEventPointerTypeSequence(t, hev3, pointer.Scroll)
|
assertEventPointerTypeSequence(t, hev3, pointer.Scroll)
|
||||||
assertEventPriorities(t, hev1, pointer.Shared, pointer.Foremost)
|
assertEventPriorities(t, hev1, pointer.Shared, pointer.Shared)
|
||||||
assertEventPriorities(t, hev2, pointer.Foremost)
|
assertEventPriorities(t, hev2, pointer.Shared)
|
||||||
assertEventPriorities(t, hev3, pointer.Foremost)
|
assertEventPriorities(t, hev3, pointer.Shared)
|
||||||
assertScrollEvent(t, hev1[0], f32.Pt(30, 0))
|
assertScrollEvent(t, hev1[0], f32.Pt(30, 0))
|
||||||
assertScrollEvent(t, hev2[0], f32.Pt(20, 0))
|
assertScrollEvent(t, hev2[0], f32.Pt(20, 0))
|
||||||
assertScrollEvent(t, hev1[1], f32.Pt(50, 0))
|
assertScrollEvent(t, hev1[1], f32.Pt(50, 0))
|
||||||
@@ -677,26 +750,31 @@ func TestCursor(t *testing.T) {
|
|||||||
cursors []pointer.Cursor
|
cursors []pointer.Cursor
|
||||||
want pointer.Cursor
|
want pointer.Cursor
|
||||||
}{
|
}{
|
||||||
{label: "no movement",
|
{
|
||||||
|
label: "no movement",
|
||||||
cursors: []pointer.Cursor{pointer.CursorPointer},
|
cursors: []pointer.Cursor{pointer.CursorPointer},
|
||||||
want: pointer.CursorDefault,
|
want: pointer.CursorDefault,
|
||||||
},
|
},
|
||||||
{label: "move inside",
|
{
|
||||||
|
label: "move inside",
|
||||||
cursors: []pointer.Cursor{pointer.CursorPointer},
|
cursors: []pointer.Cursor{pointer.CursorPointer},
|
||||||
events: _at(50, 50),
|
events: _at(50, 50),
|
||||||
want: pointer.CursorPointer,
|
want: pointer.CursorPointer,
|
||||||
},
|
},
|
||||||
{label: "move outside",
|
{
|
||||||
|
label: "move outside",
|
||||||
cursors: []pointer.Cursor{pointer.CursorPointer},
|
cursors: []pointer.Cursor{pointer.CursorPointer},
|
||||||
events: _at(200, 200),
|
events: _at(200, 200),
|
||||||
want: pointer.CursorDefault,
|
want: pointer.CursorDefault,
|
||||||
},
|
},
|
||||||
{label: "move back inside",
|
{
|
||||||
|
label: "move back inside",
|
||||||
cursors: []pointer.Cursor{pointer.CursorPointer},
|
cursors: []pointer.Cursor{pointer.CursorPointer},
|
||||||
events: _at(50, 50),
|
events: _at(50, 50),
|
||||||
want: pointer.CursorPointer,
|
want: pointer.CursorPointer,
|
||||||
},
|
},
|
||||||
{label: "send key events while inside",
|
{
|
||||||
|
label: "send key events while inside",
|
||||||
cursors: []pointer.Cursor{pointer.CursorPointer},
|
cursors: []pointer.Cursor{pointer.CursorPointer},
|
||||||
events: []event.Event{
|
events: []event.Event{
|
||||||
key.Event{Name: "A", State: key.Press},
|
key.Event{Name: "A", State: key.Press},
|
||||||
@@ -704,7 +782,8 @@ func TestCursor(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: pointer.CursorPointer,
|
want: pointer.CursorPointer,
|
||||||
},
|
},
|
||||||
{label: "send key events while outside",
|
{
|
||||||
|
label: "send key events while outside",
|
||||||
cursors: []pointer.Cursor{pointer.CursorPointer},
|
cursors: []pointer.Cursor{pointer.CursorPointer},
|
||||||
events: append(
|
events: append(
|
||||||
_at(200, 200),
|
_at(200, 200),
|
||||||
@@ -713,7 +792,8 @@ func TestCursor(t *testing.T) {
|
|||||||
),
|
),
|
||||||
want: pointer.CursorDefault,
|
want: pointer.CursorDefault,
|
||||||
},
|
},
|
||||||
{label: "add new input on top while inside",
|
{
|
||||||
|
label: "add new input on top while inside",
|
||||||
cursors: []pointer.Cursor{pointer.CursorPointer, pointer.CursorCrosshair},
|
cursors: []pointer.Cursor{pointer.CursorPointer, pointer.CursorCrosshair},
|
||||||
events: append(
|
events: append(
|
||||||
_at(50, 50),
|
_at(50, 50),
|
||||||
@@ -724,7 +804,8 @@ func TestCursor(t *testing.T) {
|
|||||||
),
|
),
|
||||||
want: pointer.CursorCrosshair,
|
want: pointer.CursorCrosshair,
|
||||||
},
|
},
|
||||||
{label: "remove input on top while inside",
|
{
|
||||||
|
label: "remove input on top while inside",
|
||||||
cursors: []pointer.Cursor{pointer.CursorPointer},
|
cursors: []pointer.Cursor{pointer.CursorPointer},
|
||||||
events: append(
|
events: append(
|
||||||
_at(50, 50),
|
_at(50, 50),
|
||||||
@@ -1085,6 +1166,33 @@ func TestPassCursor(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPartialEvent(t *testing.T) {
|
||||||
|
var ops op.Ops
|
||||||
|
var r Router
|
||||||
|
|
||||||
|
rect := clip.Rect(image.Rect(0, 0, 100, 100))
|
||||||
|
background := rect.Push(&ops)
|
||||||
|
event.Op(&ops, 1)
|
||||||
|
background.Pop()
|
||||||
|
|
||||||
|
overlayPass := pointer.PassOp{}.Push(&ops)
|
||||||
|
overlay := rect.Push(&ops)
|
||||||
|
event.Op(&ops, 2)
|
||||||
|
overlay.Pop()
|
||||||
|
overlayPass.Pop()
|
||||||
|
assertEventSequence(t, events(&r, -1, pointer.Filter{Target: 1, Kinds: pointer.Press}))
|
||||||
|
assertEventSequence(t, events(&r, -1, pointer.Filter{Target: 2, Kinds: pointer.Press}))
|
||||||
|
r.Frame(&ops)
|
||||||
|
r.Queue(pointer.Event{
|
||||||
|
Kind: pointer.Press,
|
||||||
|
})
|
||||||
|
assertEventSequence(t, events(&r, -1, pointer.Filter{Target: 1, Kinds: pointer.Press}, key.FocusFilter{Target: 1}),
|
||||||
|
key.FocusEvent{}, pointer.Event{Kind: pointer.Press, Source: pointer.Mouse, Priority: pointer.Shared})
|
||||||
|
r.Source().Execute(key.FocusCmd{Tag: 1})
|
||||||
|
assertEventSequence(t, events(&r, -1, pointer.Filter{Target: 2, Kinds: pointer.Press}),
|
||||||
|
pointer.Event{Kind: pointer.Press, Source: pointer.Mouse, Priority: pointer.Shared})
|
||||||
|
}
|
||||||
|
|
||||||
// offer satisfies io.ReadCloser for use in data transfers.
|
// offer satisfies io.ReadCloser for use in data transfers.
|
||||||
type offer struct {
|
type offer struct {
|
||||||
data string
|
data string
|
||||||
@@ -1228,7 +1336,7 @@ func BenchmarkRouterAdd(b *testing.B) {
|
|||||||
handlerCount := i
|
handlerCount := i
|
||||||
b.Run(fmt.Sprintf("%d-handlers", i), func(b *testing.B) {
|
b.Run(fmt.Sprintf("%d-handlers", i), func(b *testing.B) {
|
||||||
handlers := make([]event.Tag, handlerCount)
|
handlers := make([]event.Tag, handlerCount)
|
||||||
for i := 0; i < handlerCount; i++ {
|
for i := range handlerCount {
|
||||||
h := new(int)
|
h := new(int)
|
||||||
*h = i
|
*h = i
|
||||||
handlers[i] = h
|
handlers[i] = h
|
||||||
@@ -1250,7 +1358,7 @@ func BenchmarkRouterAdd(b *testing.B) {
|
|||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Kind: pointer.Move,
|
Kind: pointer.Move,
|
||||||
@@ -1276,3 +1384,40 @@ func events(r *Router, n int, filters ...event.Filter) []event.Event {
|
|||||||
}
|
}
|
||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestPointerScrollDoesNotTrackPointer queues two events over two cursor
|
||||||
|
// regions. The Move puts the live pointer over the button (CursorPointer);
|
||||||
|
// the Scroll happens over the cell (CursorText) and must not update the
|
||||||
|
// cursor.
|
||||||
|
func TestPointerScrollDoesNotTrackPointer(t *testing.T) {
|
||||||
|
var ops op.Ops
|
||||||
|
|
||||||
|
button := clip.Rect(image.Rect(0, 0, 50, 50)).Push(&ops)
|
||||||
|
pointer.CursorPointer.Add(&ops)
|
||||||
|
button.Pop()
|
||||||
|
|
||||||
|
cell := clip.Rect(image.Rect(100, 0, 200, 50)).Push(&ops)
|
||||||
|
pointer.CursorText.Add(&ops)
|
||||||
|
cell.Pop()
|
||||||
|
|
||||||
|
var r Router
|
||||||
|
r.Frame(&ops)
|
||||||
|
r.Queue(
|
||||||
|
pointer.Event{
|
||||||
|
Kind: pointer.Move,
|
||||||
|
Source: pointer.Mouse,
|
||||||
|
Position: f32.Pt(25, 25),
|
||||||
|
},
|
||||||
|
pointer.Event{
|
||||||
|
Kind: pointer.Scroll,
|
||||||
|
Source: pointer.Mouse,
|
||||||
|
Position: f32.Pt(150, 25),
|
||||||
|
Scroll: f32.Pt(0, 1),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if got, want := r.Cursor(), pointer.CursorPointer; got != want {
|
||||||
|
t.Errorf("got %q, want %q (scroll position must not update the cursor; "+
|
||||||
|
"the live pointer's last position is what determines it)", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+61
-43
@@ -5,6 +5,7 @@ package input
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -35,10 +36,9 @@ type Router struct {
|
|||||||
queue keyQueue
|
queue keyQueue
|
||||||
// The following fields have the same purpose as the fields in
|
// The following fields have the same purpose as the fields in
|
||||||
// type handler, but for key.Events.
|
// type handler, but for key.Events.
|
||||||
filter keyFilter
|
filter keyFilter
|
||||||
nextFilter keyFilter
|
nextFilter keyFilter
|
||||||
processedFilter keyFilter
|
scratchFilter keyFilter
|
||||||
scratchFilter keyFilter
|
|
||||||
}
|
}
|
||||||
cqueue clipboardQueue
|
cqueue clipboardQueue
|
||||||
// states is the list of pending state changes resulting from
|
// states is the list of pending state changes resulting from
|
||||||
@@ -61,9 +61,10 @@ type Router struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Source implements the interface between a Router and user interface widgets.
|
// Source implements the interface between a Router and user interface widgets.
|
||||||
// The value Source is disabled.
|
// The zero-value Source is disabled.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
r *Router
|
r *Router
|
||||||
|
disabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command represents a request such as moving the focus, or initiating a clipboard read.
|
// Command represents a request such as moving the focus, or initiating a clipboard read.
|
||||||
@@ -178,10 +179,17 @@ func (s Source) Execute(c Command) {
|
|||||||
s.r.execute(c)
|
s.r.execute(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disabled returns a copy of this source that don't deliver any events.
|
||||||
|
func (s Source) Disabled() Source {
|
||||||
|
s2 := s
|
||||||
|
s2.disabled = true
|
||||||
|
return s2
|
||||||
|
}
|
||||||
|
|
||||||
// Enabled reports whether the source is enabled. Only enabled
|
// Enabled reports whether the source is enabled. Only enabled
|
||||||
// Sources deliver events and respond to commands.
|
// Sources deliver events.
|
||||||
func (s Source) Enabled() bool {
|
func (s Source) Enabled() bool {
|
||||||
return s.r != nil
|
return s.r != nil && !s.disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
// Focused reports whether tag is focused, according to the most recent
|
// Focused reports whether tag is focused, according to the most recent
|
||||||
@@ -194,6 +202,7 @@ func (s Source) Focused(tag event.Tag) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Event returns the next event that matches at least one of filters.
|
// Event returns the next event that matches at least one of filters.
|
||||||
|
// If the source is disabled, no events will be reported.
|
||||||
func (s Source) Event(filters ...event.Filter) (event.Event, bool) {
|
func (s Source) Event(filters ...event.Filter) (event.Event, bool) {
|
||||||
if !s.Enabled() {
|
if !s.Enabled() {
|
||||||
return nil, false
|
return nil, false
|
||||||
@@ -275,28 +284,29 @@ func (q *Router) Event(filters ...event.Filter) (event.Event, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !q.deferring {
|
for i := range q.changes {
|
||||||
for i := range q.changes {
|
if q.deferring && i > 0 {
|
||||||
change := &q.changes[i]
|
break
|
||||||
for j, evt := range change.events {
|
}
|
||||||
match := false
|
change := &q.changes[i]
|
||||||
switch e := evt.event.(type) {
|
for j, evt := range change.events {
|
||||||
case key.Event:
|
match := false
|
||||||
match = q.key.scratchFilter.Matches(change.state.keyState.focus, e, false)
|
switch e := evt.event.(type) {
|
||||||
default:
|
case key.Event:
|
||||||
for _, tf := range q.scratchFilters {
|
match = q.key.scratchFilter.Matches(change.state.keyState.focus, e, false)
|
||||||
if evt.tag == tf.tag && tf.filter.Matches(evt.event) {
|
default:
|
||||||
match = true
|
for _, tf := range q.scratchFilters {
|
||||||
break
|
if evt.tag == tf.tag && tf.filter.Matches(evt.event) {
|
||||||
}
|
match = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if match {
|
}
|
||||||
change.events = append(change.events[:j], change.events[j+1:]...)
|
if match {
|
||||||
// Fast forward state to last matched.
|
change.events = slices.Delete(change.events, j, j+1)
|
||||||
q.collapseState(i)
|
// Fast forward state to last matched.
|
||||||
return evt.event, true
|
q.collapseState(i)
|
||||||
}
|
return evt.event, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,7 +314,6 @@ func (q *Router) Event(filters ...event.Filter) (event.Event, bool) {
|
|||||||
h := q.stateFor(tf.tag)
|
h := q.stateFor(tf.tag)
|
||||||
h.processedFilter.Merge(tf.filter)
|
h.processedFilter.Merge(tf.filter)
|
||||||
}
|
}
|
||||||
q.key.processedFilter = append(q.key.processedFilter, q.key.scratchFilter...)
|
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,15 +324,15 @@ func (q *Router) collapseState(idx int) {
|
|||||||
}
|
}
|
||||||
first := &q.changes[0]
|
first := &q.changes[0]
|
||||||
first.state = q.changes[idx].state
|
first.state = q.changes[idx].state
|
||||||
for i := 1; i <= idx; i++ {
|
for _, ch := range q.changes[1 : idx+1] {
|
||||||
first.events = append(first.events, q.changes[i].events...)
|
first.events = append(first.events, ch.events...)
|
||||||
}
|
}
|
||||||
q.changes = append(q.changes[:1], q.changes[idx+1:]...)
|
q.changes = append(q.changes[:1], q.changes[idx+1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frame replaces the declared handlers from the supplied
|
// Frame completes the current frame and starts a new with the
|
||||||
// operation list. The text input state, wakeup time and whether
|
// handlers from the frame argument. Remaining events are discarded,
|
||||||
// there are active profile handlers is also saved.
|
// unless they were deferred by a command.
|
||||||
func (q *Router) Frame(frame *op.Ops) {
|
func (q *Router) Frame(frame *op.Ops) {
|
||||||
var remaining []event.Event
|
var remaining []event.Event
|
||||||
if n := len(q.changes); n > 0 {
|
if n := len(q.changes); n > 0 {
|
||||||
@@ -410,7 +419,7 @@ func (f *filter) Merge(f2 filter) {
|
|||||||
|
|
||||||
func (f *filter) Matches(e event.Event) bool {
|
func (f *filter) Matches(e event.Event) bool {
|
||||||
switch e.(type) {
|
switch e.(type) {
|
||||||
case key.FocusEvent, key.SnippetEvent, key.EditEvent, key.SelectionEvent:
|
case key.FocusEvent, key.SnippetEvent, key.EditEvent, key.SelectionEvent, key.CompositionEvent:
|
||||||
return f.focusable
|
return f.focusable
|
||||||
default:
|
default:
|
||||||
return f.pointer.Matches(e)
|
return f.pointer.Matches(e)
|
||||||
@@ -454,6 +463,13 @@ func (q *Router) processEvent(e event.Event, system bool) {
|
|||||||
evts = append(evts, taggedEvent{tag: f, event: e})
|
evts = append(evts, taggedEvent{tag: f, event: e})
|
||||||
}
|
}
|
||||||
q.changeState(e, state, evts)
|
q.changeState(e, state, evts)
|
||||||
|
case key.CompositionEvent:
|
||||||
|
e = key.CompositionEvent(rangeNorm(key.Range(e)))
|
||||||
|
var evts []taggedEvent
|
||||||
|
if f := state.focus; f != nil {
|
||||||
|
evts = append(evts, taggedEvent{tag: f, event: e})
|
||||||
|
}
|
||||||
|
q.changeState(e, state, evts)
|
||||||
case key.EditEvent, key.FocusEvent, key.SelectionEvent:
|
case key.EditEvent, key.FocusEvent, key.SelectionEvent:
|
||||||
var evts []taggedEvent
|
var evts []taggedEvent
|
||||||
if f := state.focus; f != nil {
|
if f := state.focus; f != nil {
|
||||||
@@ -619,11 +635,11 @@ func (q *Router) RevealFocus(viewport image.Rectangle) {
|
|||||||
viewport = q.pointer.queue.ClipFor(area, viewport)
|
viewport = q.pointer.queue.ClipFor(area, viewport)
|
||||||
|
|
||||||
topleft := bounds.Min.Sub(viewport.Min)
|
topleft := bounds.Min.Sub(viewport.Min)
|
||||||
topleft = max(topleft, bounds.Max.Sub(viewport.Max))
|
topleft = maxPoint(topleft, bounds.Max.Sub(viewport.Max))
|
||||||
topleft = min(image.Pt(0, 0), topleft)
|
topleft = minPoint(image.Pt(0, 0), topleft)
|
||||||
bottomright := bounds.Max.Sub(viewport.Max)
|
bottomright := bounds.Max.Sub(viewport.Max)
|
||||||
bottomright = min(bottomright, bounds.Min.Sub(viewport.Min))
|
bottomright = minPoint(bottomright, bounds.Min.Sub(viewport.Min))
|
||||||
bottomright = max(image.Pt(0, 0), bottomright)
|
bottomright = maxPoint(image.Pt(0, 0), bottomright)
|
||||||
s := topleft
|
s := topleft
|
||||||
if s.X == 0 {
|
if s.X == 0 {
|
||||||
s.X = bottomright.X
|
s.X = bottomright.X
|
||||||
@@ -650,7 +666,7 @@ func (q *Router) ScrollFocus(dist image.Point) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func max(p1, p2 image.Point) image.Point {
|
func maxPoint(p1, p2 image.Point) image.Point {
|
||||||
m := p1
|
m := p1
|
||||||
if p2.X > m.X {
|
if p2.X > m.X {
|
||||||
m.X = p2.X
|
m.X = p2.X
|
||||||
@@ -661,7 +677,7 @@ func max(p1, p2 image.Point) image.Point {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func min(p1, p2 image.Point) image.Point {
|
func minPoint(p1, p2 image.Point) image.Point {
|
||||||
m := p1
|
m := p1
|
||||||
if p2.X < m.X {
|
if p2.X < m.X {
|
||||||
m.X = p2.X
|
m.X = p2.X
|
||||||
@@ -770,13 +786,15 @@ func (q *Router) collect() {
|
|||||||
pc.Reset()
|
pc.Reset()
|
||||||
kq := &q.key.queue
|
kq := &q.key.queue
|
||||||
q.key.queue.Reset()
|
q.key.queue.Reset()
|
||||||
var t f32.Affine2D
|
t := f32.AffineId()
|
||||||
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
||||||
switch ops.OpType(encOp.Data[0]) {
|
switch ops.OpType(encOp.Data[0]) {
|
||||||
case ops.TypeSave:
|
case ops.TypeSave:
|
||||||
id := ops.DecodeSave(encOp.Data)
|
id := ops.DecodeSave(encOp.Data)
|
||||||
if extra := id - len(q.savedTrans) + 1; extra > 0 {
|
if extra := id - len(q.savedTrans) + 1; extra > 0 {
|
||||||
q.savedTrans = append(q.savedTrans, make([]f32.Affine2D, extra)...)
|
for range extra {
|
||||||
|
q.savedTrans = append(q.savedTrans, f32.AffineId())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
q.savedTrans[id] = t
|
q.savedTrans[id] = t
|
||||||
case ops.TypeLoad:
|
case ops.TypeLoad:
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user