Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
fe6bf4af
Unverified
Commit
fe6bf4af
authored
Nov 08, 2021
by
Roman Sedaikin
Committed by
GitHub
Nov 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prototype for common skiko events. (#344)
* Prototype for common skiko events.
parent
fa2f2af4
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
306 additions
and
74 deletions
+306
-74
.gitignore
.gitignore
+1
-0
Clocks.kt
...rc/commonMain/kotlin/org/jetbrains/skiko/sample/Clocks.kt
+47
-8
App.ios.kt
.../src/iosMain/kotlin/org/jetbrains/skiko/sample/App.ios.kt
+1
-1
App.jvm.kt
.../src/jvmMain/kotlin/org/jetbrains/skiko/sample/App.jvm.kt
+1
-1
Events.kt
skiko/src/commonMain/kotlin/org/jetbrains/skiko/Events.kt
+24
-2
SkikoView.kt
skiko/src/commonMain/kotlin/org/jetbrains/skiko/SkikoView.kt
+5
-0
Convertors.kt
skiko/src/iosMain/kotlin/org/jetbrains/skiko/Convertors.kt
+23
-0
SkiaLayer.ios.kt
...o/src/iosMain/kotlin/org/jetbrains/skiko/SkiaLayer.ios.kt
+85
-12
SkikoViewController.kt
...iosMain/kotlin/org/jetbrains/skiko/SkikoViewController.kt
+11
-2
SkiaLayer.js.kt
skiko/src/jsMain/kotlin/org/jetbrains/skiko/SkiaLayer.js.kt
+1
-0
Convertors.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Convertors.kt
+57
-0
SkiaLayer.jvm.kt
...o/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.jvm.kt
+48
-48
SkiaLayer.linux.kt
...c/linuxMain/kotlin/org/jetbrains/skiko/SkiaLayer.linux.kt
+1
-0
SkiaLayer.macos.kt
...c/macosMain/kotlin/org/jetbrains/skiko/SkiaLayer.macos.kt
+1
-0
No files found.
.gitignore
View file @
fe6bf4af
...
@@ -7,4 +7,5 @@ local.properties
...
@@ -7,4 +7,5 @@ local.properties
.vscode
.vscode
deploy.sh
deploy.sh
deploy.bat
deploy.bat
*.xcodeproj
skiko/src/jvmMain/java
skiko/src/jvmMain/java
samples/SkiaMultiplatformSample/src/commonMain/kotlin/org/jetbrains/skiko/sample/Clocks.kt
View file @
fe6bf4af
...
@@ -7,19 +7,30 @@ import org.jetbrains.skia.paragraph.ParagraphStyle
...
@@ -7,19 +7,30 @@ import org.jetbrains.skia.paragraph.ParagraphStyle
import
org.jetbrains.skia.paragraph.TextStyle
import
org.jetbrains.skia.paragraph.TextStyle
import
org.jetbrains.skiko.SkikoView
import
org.jetbrains.skiko.SkikoView
import
org.jetbrains.skiko.SkikoPointerEvent
import
org.jetbrains.skiko.SkikoPointerEvent
import
org.jetbrains.skiko.SkikoGestureEvent
import
org.jetbrains.skiko.SkikoGestureEventKind
import
org.jetbrains.skiko.SkikoGestureEventState
import
org.jetbrains.skiko.isLeftClick
import
org.jetbrains.skiko.isLeftClick
import
kotlin.math.cos
import
kotlin.math.cos
import
kotlin.math.sin
import
kotlin.math.sin
import
kotlin.math.PI
import
kotlin.math.PI
import
kotlin.math.pow
class
Clocks
:
SkikoView
{
class
Clocks
:
SkikoView
{
private
var
frame
=
0
private
var
frame
=
0
private
var
xpos
=
0.0
private
var
xpos
=
0.0
private
var
ypos
=
0.0
private
var
ypos
=
0.0
private
var
xOffset
=
0.0
private
var
yOffset
=
0.0
private
var
scale
=
1.0
private
var
k
=
scale
private
var
rotate
=
0.0
private
val
fontCollection
=
FontCollection
()
private
val
fontCollection
=
FontCollection
()
.
setDefaultFontManager
(
FontMgr
.
default
)
.
setDefaultFontManager
(
FontMgr
.
default
)
override
fun
onRender
(
canvas
:
Canvas
,
width
:
Int
,
height
:
Int
,
nanoTime
:
Long
)
{
override
fun
onRender
(
canvas
:
Canvas
,
width
:
Int
,
height
:
Int
,
nanoTime
:
Long
)
{
canvas
.
translate
(
xOffset
.
toFloat
(),
yOffset
.
toFloat
())
canvas
.
scale
(
scale
.
toFloat
(),
scale
.
toFloat
())
val
watchFill
=
Paint
().
apply
{
color
=
0
xFFFFFFFF
.
toInt
()
}
val
watchFill
=
Paint
().
apply
{
color
=
0
xFFFFFFFF
.
toInt
()
}
val
watchStroke
=
Paint
().
apply
{
val
watchStroke
=
Paint
().
apply
{
color
=
0
xFF000000
.
toInt
()
color
=
0
xFF000000
.
toInt
()
...
@@ -32,9 +43,9 @@ class Clocks: SkikoView {
...
@@ -32,9 +43,9 @@ class Clocks: SkikoView {
strokeWidth
=
1f
strokeWidth
=
1f
}
}
val
watchFillHover
=
Paint
().
apply
{
color
=
0
xFFE4FF01
.
toInt
()
}
val
watchFillHover
=
Paint
().
apply
{
color
=
0
xFFE4FF01
.
toInt
()
}
for
(
x
in
0
..
(
width
-
50
)
step
50
)
{
for
(
x
in
0
..
width
-
50
step
50
)
{
for
(
y
in
20
..
(
height
-
50
)
step
50
)
{
for
(
y
in
20
..
height
-
50
step
50
)
{
val
hover
=
xpos
>
x
+
0
&&
xpos
<
x
+
50
&&
ypos
>
y
+
0
&&
ypos
<
y
+
50
val
hover
=
xpos
/
scale
>
x
&&
xpos
/
scale
<
x
+
50
&&
ypos
/
scale
>
y
&&
ypos
/
scale
<
y
+
50
val
fill
=
if
(
hover
)
watchFillHover
else
watchFill
val
fill
=
if
(
hover
)
watchFillHover
else
watchFill
val
stroke
=
if
(
x
>
width
/
2
)
watchStrokeAA
else
watchStroke
val
stroke
=
if
(
x
>
width
/
2
)
watchStrokeAA
else
watchStroke
canvas
.
drawOval
(
Rect
.
makeXYWH
(
x
+
5f
,
y
+
5f
,
40f
,
40f
),
fill
)
canvas
.
drawOval
(
Rect
.
makeXYWH
(
x
+
5f
,
y
+
5f
,
40f
,
40f
),
fill
)
...
@@ -55,13 +66,17 @@ class Clocks: SkikoView {
...
@@ -55,13 +66,17 @@ class Clocks: SkikoView {
(
y
.
toFloat
()
/
width
*
5000
).
toLong
()
(
y
.
toFloat
()
/
width
*
5000
).
toLong
()
val
angle1
=
(
time
.
toFloat
()
/
5000
*
2f
*
PI
).
toFloat
()
val
angle1
=
(
time
.
toFloat
()
/
5000
*
2f
*
PI
).
toFloat
()
canvas
.
drawLine
(
x
+
25f
,
y
+
25f
,
canvas
.
drawLine
(
x
+
25f
,
y
+
25f
,
x
+
25f
-
15f
*
sin
(
angle1
),
x
+
25f
-
15f
*
sin
(
angle1
),
y
+
25f
+
15
*
cos
(
angle1
),
y
+
25f
+
15
*
cos
(
angle1
),
stroke
)
stroke
)
val
angle2
=
(
time
/
60000
*
2f
*
PI
).
toFloat
()
val
angle2
=
(
time
/
60000
*
2f
*
PI
).
toFloat
()
canvas
.
drawLine
(
x
+
25f
,
y
+
25f
,
canvas
.
drawLine
(
x
+
25f
,
y
+
25f
,
x
+
25f
-
10f
*
sin
(
angle2
),
x
+
25f
-
10f
*
sin
(
angle2
),
y
+
25f
+
10f
*
cos
(
angle2
),
y
+
25f
+
10f
*
cos
(
angle2
),
stroke
)
stroke
)
...
@@ -70,12 +85,12 @@ class Clocks: SkikoView {
...
@@ -70,12 +85,12 @@ class Clocks: SkikoView {
val
style
=
ParagraphStyle
()
val
style
=
ParagraphStyle
()
val
frames
=
ParagraphBuilder
(
style
,
fontCollection
)
val
frames
=
ParagraphBuilder
(
style
,
fontCollection
)
.
pushStyle
(
TextStyle
().
setColor
(
0
x
FFFFAA0A
.
toInt
()).
setFontSize
(
25
f
))
.
pushStyle
(
TextStyle
().
setColor
(
0
x
ff9BC730L
.
toInt
()).
setFontSize
(
20
f
))
.
addText
(
"Frames: ${frame++}"
)
.
addText
(
"Frames: ${frame++}
\nAngle: $rotate
"
)
.
popStyle
()
.
popStyle
()
.
build
()
.
build
()
frames
.
layout
(
Float
.
POSITIVE_INFINITY
)
frames
.
layout
(
Float
.
POSITIVE_INFINITY
)
frames
.
paint
(
canvas
,
xpos
.
toFloat
(),
ypos
.
toFloat
())
frames
.
paint
(
canvas
,
(
xpos
/
scale
).
toFloat
(),
(
ypos
/
scale
)
.
toFloat
())
}
}
override
fun
onPointerEvent
(
event
:
SkikoPointerEvent
)
{
override
fun
onPointerEvent
(
event
:
SkikoPointerEvent
)
{
...
@@ -84,4 +99,28 @@ class Clocks: SkikoView {
...
@@ -84,4 +99,28 @@ class Clocks: SkikoView {
ypos
=
event
.
y
ypos
=
event
.
y
}
}
}
}
override
fun
onGestureEvent
(
event
:
SkikoGestureEvent
)
{
when
(
event
.
kind
)
{
SkikoGestureEventKind
.
PRESS
,
SkikoGestureEventKind
.
TAP
->
{
xpos
=
event
.
x
-
xOffset
ypos
=
event
.
y
-
yOffset
}
SkikoGestureEventKind
.
PINCH
->
{
if
(
event
.
state
==
SkikoGestureEventState
.
STARTED
)
{
k
=
scale
}
scale
=
k
*
event
.
scale
}
SkikoGestureEventKind
.
PAN
->
{
xOffset
=
event
.
x
-
xpos
yOffset
=
event
.
y
-
ypos
}
SkikoGestureEventKind
.
ROTATION
->
{
rotate
=
(
event
.
rotation
*
PI
)
}
else
->
{}
}
}
}
}
\ No newline at end of file
samples/SkiaMultiplatformSample/src/iosMain/kotlin/org/jetbrains/skiko/sample/App.ios.kt
View file @
fe6bf4af
...
@@ -45,4 +45,4 @@ class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol {
...
@@ -45,4 +45,4 @@ class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol {
window
!!
.
makeKeyAndVisible
()
window
!!
.
makeKeyAndVisible
()
return
true
return
true
}
}
}
}
\ No newline at end of file
samples/SkiaMultiplatformSample/src/jvmMain/kotlin/org/jetbrains/skiko/sample/App.jvm.kt
View file @
fe6bf4af
...
@@ -7,7 +7,7 @@ import javax.swing.*
...
@@ -7,7 +7,7 @@ import javax.swing.*
fun
main
()
{
fun
main
()
{
val
skiaLayer
=
SkiaLayer
()
val
skiaLayer
=
SkiaLayer
()
skiaLayer
.
skikoView
=
GenericSkikoView
(
skiaLayer
,
BouncingBalls
(
))
skiaLayer
.
addView
(
GenericSkikoView
(
skiaLayer
,
Clocks
()
))
SwingUtilities
.
invokeLater
{
SwingUtilities
.
invokeLater
{
val
window
=
JFrame
(
"Skiko example"
).
apply
{
val
window
=
JFrame
(
"Skiko example"
).
apply
{
defaultCloseOperation
=
WindowConstants
.
EXIT_ON_CLOSE
defaultCloseOperation
=
WindowConstants
.
EXIT_ON_CLOSE
...
...
skiko/src/commonMain/kotlin/org/jetbrains/skiko/Events.kt
View file @
fe6bf4af
...
@@ -8,6 +8,28 @@ object SkikoMouseButtons {
...
@@ -8,6 +8,28 @@ object SkikoMouseButtons {
const
val
MIDDLE
=
1
shl
2
const
val
MIDDLE
=
1
shl
2
}
}
enum
class
SkikoGestureEventKind
{
PRESS
,
TAP
,
PAN
,
PINCH
,
ROTATION
,
LONGPRESS
,
SWIPE
,
UNKNOWN
}
enum
class
SkikoGestureEventDirection
{
UP
,
DOWN
,
LEFT
,
RIGHT
,
UNKNOWN
}
enum
class
SkikoGestureEventState
{
PRESSED
,
STARTED
,
CHANGED
,
ENDED
,
UNKNOWN
}
expect
class
SkikoGesturePlatformEvent
data class
SkikoGestureEvent
(
val
x
:
Double
,
val
y
:
Double
,
val
velocity
:
Double
=
0.0
,
val
direction
:
SkikoGestureEventDirection
=
SkikoGestureEventDirection
.
UNKNOWN
,
val
interval
:
Long
=
0
,
val
rotation
:
Double
=
0.0
,
val
scale
:
Double
=
1.0
,
val
kind
:
SkikoGestureEventKind
,
val
state
:
SkikoGestureEventState
=
SkikoGestureEventState
.
UNKNOWN
,
val
platform
:
SkikoGesturePlatformEvent
?
=
null
)
expect
class
SkikoPlatformInputEvent
expect
class
SkikoPlatformInputEvent
data class
SkikoInputEvent
(
data class
SkikoInputEvent
(
val
input
:
String
,
val
input
:
String
,
...
@@ -15,7 +37,7 @@ data class SkikoInputEvent(
...
@@ -15,7 +37,7 @@ data class SkikoInputEvent(
)
)
enum
class
SkikoKeyboardEventKind
{
enum
class
SkikoKeyboardEventKind
{
UP
,
DOWN
UP
,
DOWN
,
TYPE
,
UNKNOWN
}
}
expect
class
SkikoPlatformKeyboardEvent
expect
class
SkikoPlatformKeyboardEvent
data class
SkikoKeyboardEvent
(
data class
SkikoKeyboardEvent
(
...
@@ -25,7 +47,7 @@ data class SkikoKeyboardEvent(
...
@@ -25,7 +47,7 @@ data class SkikoKeyboardEvent(
)
)
enum
class
SkikoPointerEventKind
{
enum
class
SkikoPointerEventKind
{
UP
,
DOWN
,
MOVE
UP
,
DOWN
,
MOVE
,
DRAG
,
SCROLL
,
ENTER
,
EXIT
,
UNKNOWN
}
}
expect
class
SkikoPlatformPointerEvent
expect
class
SkikoPlatformPointerEvent
data class
SkikoPointerEvent
(
data class
SkikoPointerEvent
(
...
...
skiko/src/commonMain/kotlin/org/jetbrains/skiko/SkikoView.kt
View file @
fe6bf4af
...
@@ -7,6 +7,7 @@ interface SkikoView {
...
@@ -7,6 +7,7 @@ interface SkikoView {
fun
onKeyboardEvent
(
event
:
SkikoKeyboardEvent
)
=
Unit
fun
onKeyboardEvent
(
event
:
SkikoKeyboardEvent
)
=
Unit
fun
onPointerEvent
(
event
:
SkikoPointerEvent
)
=
Unit
fun
onPointerEvent
(
event
:
SkikoPointerEvent
)
=
Unit
fun
onInputEvent
(
event
:
SkikoInputEvent
)
=
Unit
fun
onInputEvent
(
event
:
SkikoInputEvent
)
=
Unit
fun
onGestureEvent
(
event
:
SkikoGestureEvent
)
=
Unit
// Rendering
// Rendering
fun
onRender
(
canvas
:
Canvas
,
width
:
Int
,
height
:
Int
,
nanoTime
:
Long
)
fun
onRender
(
canvas
:
Canvas
,
width
:
Int
,
height
:
Int
,
nanoTime
:
Long
)
...
@@ -36,4 +37,8 @@ open class GenericSkikoView(
...
@@ -36,4 +37,8 @@ open class GenericSkikoView(
override
fun
onPointerEvent
(
event
:
SkikoPointerEvent
)
{
override
fun
onPointerEvent
(
event
:
SkikoPointerEvent
)
{
app
.
onPointerEvent
(
event
)
app
.
onPointerEvent
(
event
)
}
}
override
fun
onGestureEvent
(
event
:
SkikoGestureEvent
)
{
app
.
onGestureEvent
(
event
)
}
}
}
skiko/src/iosMain/kotlin/org/jetbrains/skiko/Convertors.kt
0 → 100644
View file @
fe6bf4af
package
org.jetbrains.skiko
import
platform.UIKit.*
fun
toSkikoGestureDirection
(
direction
:
UISwipeGestureRecognizerDirection
)
:
SkikoGestureEventDirection
{
return
when
(
direction
)
{
UISwipeGestureRecognizerDirectionUp
->
SkikoGestureEventDirection
.
UP
UISwipeGestureRecognizerDirectionDown
->
SkikoGestureEventDirection
.
DOWN
UISwipeGestureRecognizerDirectionLeft
->
SkikoGestureEventDirection
.
LEFT
UISwipeGestureRecognizerDirectionRight
->
SkikoGestureEventDirection
.
RIGHT
else
->
SkikoGestureEventDirection
.
UNKNOWN
}
}
fun
toSkikoGestureState
(
state
:
UIGestureRecognizerState
)
:
SkikoGestureEventState
{
return
when
(
state
)
{
UIGestureRecognizerStatePossible
->
SkikoGestureEventState
.
PRESSED
UIGestureRecognizerStateBegan
->
SkikoGestureEventState
.
STARTED
UIGestureRecognizerStateChanged
->
SkikoGestureEventState
.
CHANGED
UIGestureRecognizerStateEnded
->
SkikoGestureEventState
.
ENDED
else
->
SkikoGestureEventState
.
UNKNOWN
}
}
skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkiaLayer.ios.kt
View file @
fe6bf4af
...
@@ -62,23 +62,95 @@ actual open class SkiaLayer {
...
@@ -62,23 +62,95 @@ actual open class SkiaLayer {
controller
=
object
:
NSObject
()
{
controller
=
object
:
NSObject
()
{
@ObjCAction
@ObjCAction
fun
onTap
(
sender
:
UITapGestureRecognizer
)
{
fun
onTap
(
sender
:
UITapGestureRecognizer
)
{
val
(
x
,
y
)
=
sender
.
locationInView
(
view
).
useContents
{
val
(
x
,
y
)
=
sender
.
locationInView
(
view
).
useContents
{
x
to
y
}
x
to
y
skikoView
?.
onGestureEvent
(
}
SkikoGestureEvent
(
// TODO: rework events using https://developer.apple.com/documentation/uikit/uiresponder/1621142-touchesbegan?language=objc
x
=
x
,
skikoView
?.
onPointerEvent
(
y
=
y
,
SkikoPointerEvent
(
x
,
y
,
kind
=
SkikoGestureEventKind
.
TAP
,
SkikoMouseButtons
.
LEFT
,
SkikoPointerEventKind
.
DOWN
,
state
=
toSkikoGestureState
(
sender
.
state
)
null
))
)
skikoView
?.
onPointerEvent
(
)
SkikoPointerEvent
(
x
,
y
,
}
SkikoMouseButtons
.
LEFT
,
SkikoPointerEventKind
.
UP
,
null
))
@ObjCAction
fun
onLongPress
(
sender
:
UILongPressGestureRecognizer
)
{
val
(
x
,
y
)
=
sender
.
locationInView
(
view
).
useContents
{
x
to
y
}
skikoView
?.
onGestureEvent
(
SkikoGestureEvent
(
x
=
x
,
y
=
y
,
kind
=
SkikoGestureEventKind
.
LONGPRESS
,
state
=
toSkikoGestureState
(
sender
.
state
)
)
)
}
@ObjCAction
fun
onPinch
(
sender
:
UIPinchGestureRecognizer
)
{
val
(
x
,
y
)
=
sender
.
locationInView
(
view
).
useContents
{
x
to
y
}
skikoView
?.
onGestureEvent
(
SkikoGestureEvent
(
x
=
x
,
y
=
y
,
kind
=
SkikoGestureEventKind
.
PINCH
,
scale
=
sender
.
scale
,
velocity
=
sender
.
velocity
,
state
=
toSkikoGestureState
(
sender
.
state
)
)
)
}
@ObjCAction
fun
onRotation
(
sender
:
UIRotationGestureRecognizer
)
{
val
(
x
,
y
)
=
sender
.
locationInView
(
view
).
useContents
{
x
to
y
}
skikoView
?.
onGestureEvent
(
SkikoGestureEvent
(
x
=
x
,
y
=
y
,
kind
=
SkikoGestureEventKind
.
ROTATION
,
rotation
=
sender
.
rotation
,
velocity
=
sender
.
velocity
,
state
=
toSkikoGestureState
(
sender
.
state
)
)
)
}
@ObjCAction
fun
onSwipe
(
sender
:
UISwipeGestureRecognizer
)
{
val
(
x
,
y
)
=
sender
.
locationInView
(
view
).
useContents
{
x
to
y
}
skikoView
?.
onGestureEvent
(
SkikoGestureEvent
(
x
=
x
,
y
=
y
,
kind
=
SkikoGestureEventKind
.
SWIPE
,
direction
=
toSkikoGestureDirection
(
sender
.
direction
),
state
=
toSkikoGestureState
(
sender
.
state
)
)
)
}
@ObjCAction
fun
onPan
(
sender
:
UIPanGestureRecognizer
)
{
val
(
x
,
y
)
=
sender
.
locationInView
(
view
).
useContents
{
x
to
y
}
skikoView
?.
onGestureEvent
(
SkikoGestureEvent
(
x
=
x
,
y
=
y
,
kind
=
SkikoGestureEventKind
.
PAN
,
state
=
toSkikoGestureState
(
sender
.
state
)
)
)
}
}
}
}
// We have ':' in selector to take care of function argument.
// We have ':' in selector to take care of function argument.
view
.
addGestureRecognizer
(
UITapGestureRecognizer
(
controller
,
NSSelectorFromString
(
"onTap:"
)))
view
.
addGestureRecognizer
(
UITapGestureRecognizer
(
controller
,
NSSelectorFromString
(
"onTap:"
)))
view
.
addGestureRecognizer
(
UILongPressGestureRecognizer
(
controller
,
NSSelectorFromString
(
"onLongPress:"
)))
view
.
addGestureRecognizer
(
UIPinchGestureRecognizer
(
controller
,
NSSelectorFromString
(
"onPinch:"
)))
view
.
addGestureRecognizer
(
UIRotationGestureRecognizer
(
controller
,
NSSelectorFromString
(
"onRotation:"
)))
view
.
addGestureRecognizer
(
UISwipeGestureRecognizer
(
controller
,
NSSelectorFromString
(
"onSwipe:"
)))
view
.
addGestureRecognizer
(
UIPanGestureRecognizer
(
controller
,
NSSelectorFromString
(
"onPan:"
)))
// TODO: maybe add observer for view.viewDidDisappear() to detach us?
// TODO: maybe add observer for view.viewDidDisappear() to detach us?
redrawer
=
MetalRedrawer
(
this
).
apply
{
redrawer
=
MetalRedrawer
(
this
).
apply
{
needRedraw
()
needRedraw
()
...
@@ -129,6 +201,7 @@ actual open class SkiaLayer {
...
@@ -129,6 +201,7 @@ actual open class SkiaLayer {
}
}
// TODO: do properly
// TODO: do properly
actual
typealias
SkikoGesturePlatformEvent
=
UIEvent
actual
typealias
SkikoPlatformInputEvent
=
UIEvent
actual
typealias
SkikoPlatformInputEvent
=
UIEvent
actual
typealias
SkikoPlatformKeyboardEvent
=
UIEvent
actual
typealias
SkikoPlatformKeyboardEvent
=
UIEvent
actual
typealias
SkikoPlatformPointerEvent
=
UIEvent
actual
typealias
SkikoPlatformPointerEvent
=
UIEvent
\ No newline at end of file
skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkikoViewController.kt
View file @
fe6bf4af
...
@@ -5,6 +5,7 @@ import kotlinx.cinterop.useContents
...
@@ -5,6 +5,7 @@ import kotlinx.cinterop.useContents
import
platform.CoreGraphics.CGRectMake
import
platform.CoreGraphics.CGRectMake
import
platform.Foundation.NSCoder
import
platform.Foundation.NSCoder
import
platform.UIKit.UIEvent
import
platform.UIKit.UIEvent
import
platform.UIKit.UITouch
import
platform.UIKit.UIScreen
import
platform.UIKit.UIScreen
import
platform.UIKit.UIViewController
import
platform.UIKit.UIViewController
import
platform.UIKit.setFrame
import
platform.UIKit.setFrame
...
@@ -19,12 +20,20 @@ class SkikoViewController : UIViewController {
...
@@ -19,12 +20,20 @@ class SkikoViewController : UIViewController {
constructor
(
coder
:
NSCoder
)
:
super
(
coder
)
constructor
(
coder
:
NSCoder
)
:
super
(
coder
)
override
fun
touchesBegan
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
override
fun
touchesBegan
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
println
(
"touchesBegan: $withEvent"
)
super
.
touchesBegan
(
touches
,
withEvent
)
super
.
touchesBegan
(
touches
,
withEvent
)
val
sender
=
(
touches
.
elementAt
(
0
)
as
UITouch
)
val
(
x
,
y
)
=
sender
.
locationInView
(
null
).
useContents
{
x
to
y
}
skikoLayer
.
skikoView
?.
onGestureEvent
(
SkikoGestureEvent
(
x
=
x
,
y
=
y
,
kind
=
SkikoGestureEventKind
.
PRESS
,
state
=
SkikoGestureEventState
.
PRESSED
)
)
}
}
override
fun
touchesEnded
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
override
fun
touchesEnded
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
println
(
"touchesEnded $withEvent"
)
super
.
touchesEnded
(
touches
,
withEvent
)
super
.
touchesEnded
(
touches
,
withEvent
)
}
}
...
...
skiko/src/jsMain/kotlin/org/jetbrains/skiko/SkiaLayer.js.kt
View file @
fe6bf4af
...
@@ -100,6 +100,7 @@ actual open class SkiaLayer {
...
@@ -100,6 +100,7 @@ actual open class SkiaLayer {
}
}
}
}
actual
typealias
SkikoGesturePlatformEvent
=
Any
actual
typealias
SkikoPlatformInputEvent
=
InputEvent
actual
typealias
SkikoPlatformInputEvent
=
InputEvent
actual
typealias
SkikoPlatformKeyboardEvent
=
KeyboardEvent
actual
typealias
SkikoPlatformKeyboardEvent
=
KeyboardEvent
// MouseEvent is base class of PointerEvent
// MouseEvent is base class of PointerEvent
...
...
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Convertors.kt
View file @
fe6bf4af
...
@@ -9,6 +9,7 @@ import org.jetbrains.skia.impl.BufferUtil
...
@@ -9,6 +9,7 @@ import org.jetbrains.skia.impl.BufferUtil
import
java.awt.Transparency
import
java.awt.Transparency
import
java.awt.color.ColorSpace
import
java.awt.color.ColorSpace
import
java.awt.image.*
import
java.awt.image.*
import
java.awt.event.*
import
java.nio.ByteBuffer
import
java.nio.ByteBuffer
private
class
DirectDataBuffer
(
val
backing
:
ByteBuffer
):
DataBuffer
(
TYPE_BYTE
,
backing
.
limit
())
{
private
class
DirectDataBuffer
(
val
backing
:
ByteBuffer
):
DataBuffer
(
TYPE_BYTE
,
backing
.
limit
())
{
...
@@ -76,3 +77,59 @@ fun BufferedImage.toBitmap(): Bitmap {
...
@@ -76,3 +77,59 @@ fun BufferedImage.toBitmap(): Bitmap {
fun
BufferedImage
.
toImage
():
Image
{
fun
BufferedImage
.
toImage
():
Image
{
return
Image
.
makeFromBitmap
(
toBitmap
())
return
Image
.
makeFromBitmap
(
toBitmap
())
}
}
fun
toSkikoEvent
(
e
:
MouseEvent
):
SkikoPointerEvent
{
return
SkikoPointerEvent
(
e
.
x
.
toDouble
(),
e
.
y
.
toDouble
(),
when
(
e
.
button
)
{
MouseEvent
.
BUTTON1
->
SkikoMouseButtons
.
LEFT
MouseEvent
.
BUTTON2
->
SkikoMouseButtons
.
RIGHT
MouseEvent
.
BUTTON3
->
SkikoMouseButtons
.
MIDDLE
else
->
SkikoMouseButtons
.
NONE
},
when
(
e
.
id
)
{
MouseEvent
.
MOUSE_PRESSED
->
SkikoPointerEventKind
.
DOWN
MouseEvent
.
MOUSE_RELEASED
->
SkikoPointerEventKind
.
UP
MouseEvent
.
MOUSE_DRAGGED
->
SkikoPointerEventKind
.
DRAG
MouseEvent
.
MOUSE_MOVED
->
SkikoPointerEventKind
.
MOVE
MouseEvent
.
MOUSE_ENTERED
->
SkikoPointerEventKind
.
ENTER
MouseEvent
.
MOUSE_EXITED
->
SkikoPointerEventKind
.
EXIT
else
->
SkikoPointerEventKind
.
UNKNOWN
},
e
)
}
fun
toSkikoEvent
(
e
:
MouseWheelEvent
):
SkikoPointerEvent
{
return
SkikoPointerEvent
(
e
.
x
.
toDouble
(),
e
.
y
.
toDouble
(),
SkikoMouseButtons
.
NONE
,
when
(
e
.
id
)
{
MouseEvent
.
MOUSE_WHEEL
->
SkikoPointerEventKind
.
SCROLL
else
->
SkikoPointerEventKind
.
UNKNOWN
},
e
)
}
fun
toSkikoEvent
(
e
:
KeyEvent
):
SkikoKeyboardEvent
{
return
SkikoKeyboardEvent
(
e
.
keyCode
,
when
(
e
.
id
)
{
KeyEvent
.
KEY_PRESSED
->
SkikoKeyboardEventKind
.
DOWN
KeyEvent
.
KEY_RELEASED
->
SkikoKeyboardEventKind
.
UP
KeyEvent
.
KEY_TYPED
->
SkikoKeyboardEventKind
.
TYPE
else
->
SkikoKeyboardEventKind
.
UNKNOWN
},
e
)
}
fun
toSkikoEvent
(
e
:
InputMethodEvent
):
SkikoInputEvent
{
return
SkikoInputEvent
(
""
,
e
)
}
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.jvm.kt
View file @
fe6bf4af
...
@@ -148,59 +148,58 @@ actual open class SkiaLayer internal constructor(
...
@@ -148,59 +148,58 @@ actual open class SkiaLayer internal constructor(
fun
attachTo
(
jComponent
:
JComponent
)
{
fun
attachTo
(
jComponent
:
JComponent
)
{
jComponent
.
add
(
this
)
jComponent
.
add
(
this
)
backedLayer
.
addMouseListener
(
object
:
MouseAdapter
()
{
}
override
fun
mousePressed
(
e
:
MouseEvent
?)
{
e
!!
fun
addView
(
view
:
SkikoView
)
{
skikoView
?.
onPointerEvent
(
skikoView
=
view
SkikoPointerEvent
(
e
.
x
.
toDouble
(),
e
.
y
.
toDouble
(),
addMouseListener
(
object
:
MouseAdapter
()
{
if
(
e
.
button
==
1
)
SkikoMouseButtons
.
LEFT
else
SkikoMouseButtons
.
RIGHT
,
override
fun
mousePressed
(
e
:
MouseEvent
)
{
SkikoPointerEventKind
.
DOWN
,
skikoView
?.
onPointerEvent
(
toSkikoEvent
(
e
))
e
}
)
override
fun
mouseReleased
(
e
:
MouseEvent
)
{
)
skikoView
?.
onPointerEvent
(
toSkikoEvent
(
e
))
}
override
fun
mouseEntered
(
e
:
MouseEvent
)
{
skikoView
?.
onPointerEvent
(
toSkikoEvent
(
e
))
}
}
override
fun
mouseReleased
(
e
:
MouseEvent
?)
{
override
fun
mouseExited
(
e
:
MouseEvent
)
{
e
!!
skikoView
?.
onPointerEvent
(
toSkikoEvent
(
e
))
skikoView
?.
onPointerEvent
(
SkikoPointerEvent
(
e
.
x
.
toDouble
(),
e
.
y
.
toDouble
(),
if
(
e
.
button
==
1
)
SkikoMouseButtons
.
LEFT
else
SkikoMouseButtons
.
RIGHT
,
SkikoPointerEventKind
.
UP
,
e
)
)
}
}
})
})
backedLayer
.
addMouseMotionListener
(
object
:
MouseMotionAdapter
()
{
override
fun
mouseMoved
(
e
:
MouseEvent
?)
{
addMouseMotionListener
(
object
:
MouseMotionAdapter
()
{
e
!!
override
fun
mouseDragged
(
e
:
MouseEvent
)
{
skikoView
?.
onPointerEvent
(
skikoView
?.
onPointerEvent
(
toSkikoEvent
(
e
))
SkikoPointerEvent
(
e
.
x
.
toDouble
(),
e
.
y
.
toDouble
(),
}
SkikoMouseButtons
.
NONE
,
override
fun
mouseMoved
(
e
:
MouseEvent
)
{
SkikoPointerEventKind
.
MOVE
,
skikoView
?.
onPointerEvent
(
toSkikoEvent
(
e
))
e
)
)
}
}
})
})
backedLayer
.
addKeyListener
(
object
:
KeyAdapter
()
{
override
fun
keyPressed
(
e
:
KeyEvent
?)
{
addMouseWheelListener
(
object
:
MouseWheelListener
{
e
!!
override
fun
mouseWheelMoved
(
e
:
MouseWheelEvent
)
{
skikoView
?.
onKeyboardEvent
(
skikoView
?.
onPointerEvent
(
toSkikoEvent
(
e
))
SkikoKeyboardEvent
(
e
.
keyCode
,
}
SkikoKeyboardEventKind
.
DOWN
,
})
e
)
addKeyListener
(
object
:
KeyAdapter
()
{
)
override
fun
keyPressed
(
e
:
KeyEvent
)
{
skikoView
?.
onKeyboardEvent
(
toSkikoEvent
(
e
))
}
override
fun
keyReleased
(
e
:
KeyEvent
)
{
skikoView
?.
onKeyboardEvent
(
toSkikoEvent
(
e
))
}
override
fun
keyTyped
(
e
:
KeyEvent
)
{
skikoView
?.
onKeyboardEvent
(
toSkikoEvent
(
e
))
}
})
addInputMethodListener
(
object
:
InputMethodListener
{
override
fun
caretPositionChanged
(
e
:
InputMethodEvent
)
{
skikoView
?.
onInputEvent
(
toSkikoEvent
(
e
))
}
}
override
fun
keyReleased
(
e
:
KeyEvent
?)
{
override
fun
inputMethodTextChanged
(
e
:
InputMethodEvent
)
{
e
!!
skikoView
?.
onInputEvent
(
toSkikoEvent
(
e
))
skikoView
?.
onKeyboardEvent
(
SkikoKeyboardEvent
(
e
.
keyCode
,
SkikoKeyboardEventKind
.
UP
,
e
)
)
}
}
})
})
}
}
...
@@ -540,6 +539,7 @@ internal fun defaultFPSCounter(
...
@@ -540,6 +539,7 @@ internal fun defaultFPSCounter(
}
}
// InputEvent is abstract, so we wrap to match modality.
// InputEvent is abstract, so we wrap to match modality.
actual
class
SkikoPlatformInputEvent
(
val
wrapped
:
InputEvent
)
actual
typealias
SkikoGesturePlatformEvent
=
Any
actual
typealias
SkikoPlatformInputEvent
=
InputMethodEvent
actual
typealias
SkikoPlatformKeyboardEvent
=
KeyEvent
actual
typealias
SkikoPlatformKeyboardEvent
=
KeyEvent
actual
typealias
SkikoPlatformPointerEvent
=
MouseEvent
actual
typealias
SkikoPlatformPointerEvent
=
MouseEvent
\ No newline at end of file
skiko/src/linuxMain/kotlin/org/jetbrains/skiko/SkiaLayer.linux.kt
View file @
fe6bf4af
...
@@ -25,6 +25,7 @@ actual open class SkiaLayer {
...
@@ -25,6 +25,7 @@ actual open class SkiaLayer {
}
}
// TODO: do properly
// TODO: do properly
actual
typealias
SkikoGesturePlatformEvent
=
Any
actual
typealias
SkikoPlatformInputEvent
=
Any
actual
typealias
SkikoPlatformInputEvent
=
Any
actual
typealias
SkikoPlatformKeyboardEvent
=
Any
actual
typealias
SkikoPlatformKeyboardEvent
=
Any
actual
typealias
SkikoPlatformPointerEvent
=
Any
actual
typealias
SkikoPlatformPointerEvent
=
Any
\ No newline at end of file
skiko/src/macosMain/kotlin/org/jetbrains/skiko/SkiaLayer.macos.kt
View file @
fe6bf4af
...
@@ -175,6 +175,7 @@ actual open class SkiaLayer {
...
@@ -175,6 +175,7 @@ actual open class SkiaLayer {
}
}
// TODO: do properly
// TODO: do properly
actual
typealias
SkikoGesturePlatformEvent
=
NSEvent
actual
typealias
SkikoPlatformInputEvent
=
NSEvent
actual
typealias
SkikoPlatformInputEvent
=
NSEvent
actual
typealias
SkikoPlatformKeyboardEvent
=
NSEvent
actual
typealias
SkikoPlatformKeyboardEvent
=
NSEvent
actual
typealias
SkikoPlatformPointerEvent
=
NSEvent
actual
typealias
SkikoPlatformPointerEvent
=
NSEvent
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment