Commit d2c7071e authored by Roman Sedaikin's avatar Roman Sedaikin

Added Swing integration support. Revert skija, skia_build.

parent ccd10abf
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SkijaInjectSample</name>
<comment>Project SkijaInjectSample created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1605001915303</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
package SkijaInjectSample
import java.awt.Dimension
import java.awt.BorderLayout
import java.awt.event.KeyEvent
import java.awt.event.MouseEvent
import java.awt.event.MouseMotionAdapter
import javax.swing.JFrame
import javax.swing.JButton
import javax.swing.event.MouseInputAdapter
import javax.swing.WindowConstants
import org.jetbrains.skiko.Library
import org.jetbrains.skiko.SkiaLayer
fun Button(text: String): JButton {
val btn = JButton(text)
btn.setPreferredSize(Dimension(100, 100))
return btn
}
fun SwingSkia() {
Library.load("/", "skiko")
val window = JFrame()
window.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
window.title = "SwingSkiaWindow"
val layer = SkiaLayer()
window.contentPane.add(Button("North"), BorderLayout.NORTH)
window.contentPane.add(Button("West"), BorderLayout.WEST)
window.contentPane.add(Button("East"), BorderLayout.EAST)
window.contentPane.add(Button("South"), BorderLayout.SOUTH)
window.contentPane.add(layer, BorderLayout.CENTER)
val state = State()
state.text = window.title
var mouseX = 0
var mouseY = 0
layer.renderer = Renderer { renderer, w, h -> displayScene(renderer, w, h, mouseX, mouseY, state) }
layer.addMouseMotionListener(object : MouseMotionAdapter() {
override fun mouseMoved(event: MouseEvent) {
mouseX = event.x
mouseY = event.y
layer.display()
}
})
window.setSize(800, 600)
window.setVisible(true)
}
......@@ -233,7 +233,7 @@ tasks.withType(CppCompile::class.java).configureEach {
"-DSK_SHAPER_HARFBUZZ_AVAILABLE",
"-DSK_SUPPORT_OPENCL=0",
"-Dskija_EXPORTS",
"-DSK_UNICODE_AVAILABLE",
// "-DSK_UNICODE_AVAILABLE",
"-DNDEBUG"
))
when (target) {
......
kotlin.code.style=official
deploy.version=0.1
dependencies.skija.git.commit=20f2c58f121b7f858092781cf0ecf3657e167ce6
dependencies.skia.windows=m87-4893488/Skia-m87-4893488-windows-Release-x64
dependencies.skia.linux=m87-4893488/Skia-m87-4893488-linux-Release-x64
dependencies.skia.macos=m87-4893488/Skia-m87-4893488-macos-Release-x64
dependencies.skija.git.commit=11dc7805b8148df8f7b2c72651008b73bf06c00d
dependencies.skia.windows=m87-a0c82f0/Skia-m87-a0c82f0-windows-Release-x64b
dependencies.skia.linux=m87-a0c82f0/Skia-m87-a0c82f0-linux-Release-x64
dependencies.skia.macos=m87-a0c82f0/Skia-m87-a0c82f0-macos-Release-x64
......@@ -55,7 +55,7 @@ object Library {
private fun miscSystemInit() {
// we have to set this property to avoid render flickering.
System.setProperty("sun.awt.noerasebackground", "true")
System.setProperty("skija.staticLoad", "false")
// System.setProperty("skija.staticLoad", "false")
// setup menu look and feel
try {
......
......@@ -55,7 +55,7 @@ JavaVM *jvm = NULL;
if (!drawMethod) drawMethod = (*env)->GetMethodID(env, wndClass, "draw", "()V");
if (NULL == drawMethod)
{
NSLog(@"The method Window.draw() not found!");
NSLog(@"The method HardwareLayer.draw() not found!");
return;
}
(*env)->CallVoidMethod(env, self.canvasGlobalRef, drawMethod);
......@@ -101,6 +101,8 @@ JavaVM *jvm = NULL;
{
wndClass = (*env)->GetObjectClass(env, self.glLayer.canvasGlobalRef);
}
// scale factor
static jmethodID contentScaleMethod = NULL;
if (!contentScaleMethod)
{
......@@ -108,13 +110,66 @@ JavaVM *jvm = NULL;
}
if (NULL == contentScaleMethod)
{
NSLog(@"The method Window.getContentScale() not found!");
NSLog(@"The method HardwareLayer.getContentScale() not found!");
return;
}
float scaleFactor = (*env)->CallFloatMethod(env, self.glLayer.canvasGlobalRef, contentScaleMethod);
assert(scaleFactor != 0);
self.container.contentsScale = scaleFactor;
self.glLayer.contentsScale = scaleFactor;
// size & position
static jmethodID getXMethod = NULL;
if (!getXMethod)
{
getXMethod = (*env)->GetMethodID(env, wndClass, "getX", "()I");
}
if (NULL == getXMethod)
{
NSLog(@"The method HardwareLayer.getX() not found!");
return;
}
static jmethodID getYMethod = NULL;
if (!getYMethod)
{
getYMethod = (*env)->GetMethodID(env, wndClass, "getY", "()I");
}
if (NULL == getYMethod)
{
NSLog(@"The method HardwareLayer.getY() not found!");
return;
}
static jmethodID getWidthMethod = NULL;
if (!getWidthMethod)
{
getWidthMethod = (*env)->GetMethodID(env, wndClass, "getWidth", "()I");
}
if (NULL == getWidthMethod)
{
NSLog(@"The method HardwareLayer.getWidth() not found!");
return;
}
static jmethodID getHeightMethod = NULL;
if (!getHeightMethod)
{
getHeightMethod = (*env)->GetMethodID(env, wndClass, "getHeight", "()I");
}
if (NULL == getHeightMethod)
{
NSLog(@"The method HardwareLayer.getHeight() not found!");
return;
}
int x = (*env)->CallIntMethod(env, self.glLayer.canvasGlobalRef, getXMethod);
int y = (*env)->CallIntMethod(env, self.glLayer.canvasGlobalRef, getYMethod);
int w = (*env)->CallIntMethod(env, self.glLayer.canvasGlobalRef, getWidthMethod);
int h = (*env)->CallIntMethod(env, self.glLayer.canvasGlobalRef, getHeightMethod);
y = (int)self.container.frame.size.height - y - h;
CGRect boundsRect = CGRectMake(x, y, w, h);
self.glLayer.frame = boundsRect;
}
}
......@@ -222,8 +277,6 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_updateLayer(JNIEnv
layersSet.glLayer = [AWTGLLayer new];
[layersSet.container addSublayer: layersSet.glLayer];
CGFloat white[] = { 1.0f, 1.0f, 1.0f, 1.0f };
layersSet.glLayer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), white);
jobject canvasGlobalRef = (*env)->NewGlobalRef(env, canvas);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment