-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
faeb736
commit 2ff94bc
Showing
14 changed files
with
143 additions
and
106 deletions.
There are no files selected for viewing
15 changes: 0 additions & 15 deletions
15
flutter-ui/src/main/java/com/primogemstudio/advancedfmk/flutter/Events.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
flutter-ui/src/main/java/com/primogemstudio/advancedfmk/flutter/FlutterAppRect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.primogemstudio.advancedfmk.flutter | ||
|
||
class FlutterAppRect { | ||
var left: Int = 0 | ||
var top: Int = 0 | ||
var right: Int = 0 | ||
var bottom: Int = 0 | ||
|
||
constructor(left: Int, top: Int, right: Int, bottom: Int) { | ||
this.left = left | ||
this.top = top | ||
this.right = right | ||
this.bottom = bottom | ||
} | ||
|
||
constructor() | ||
} |
13 changes: 13 additions & 0 deletions
13
flutter-ui/src/main/java/com/primogemstudio/advancedfmk/flutter/FlutterEvents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.primogemstudio.advancedfmk.flutter | ||
|
||
object FlutterEvents { | ||
val instances: HashSet<FlutterInstance> = java.util.HashSet() | ||
|
||
fun register(instance: FlutterInstance) { | ||
instances.add(instance) | ||
} | ||
|
||
fun unregister(instance: FlutterInstance) { | ||
instances.remove(instance) | ||
} | ||
} |
43 changes: 19 additions & 24 deletions
43
flutter-ui/src/main/java/com/primogemstudio/advancedfmk/flutter/FlutterInstance.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,29 @@ | ||
package com.primogemstudio.advancedfmk.flutter; | ||
package com.primogemstudio.advancedfmk.flutter | ||
|
||
public class FlutterInstance implements AutoCloseable { | ||
public final long handle; | ||
public final Rect rect; | ||
public int width, height; | ||
import com.primogemstudio.advancedfmk.flutter.FlutterEvents.register | ||
import com.primogemstudio.advancedfmk.flutter.FlutterEvents.unregister | ||
|
||
public FlutterInstance(String assets, Rect rect, int width, int height) { | ||
handle = FlutterNative.createInstance(assets); | ||
this.rect = rect; | ||
this.width = width; | ||
this.height = height; | ||
FlutterNative.sendMetricsEvent(handle, rect.right - rect.left, rect.bottom - rect.top, 0); | ||
Events.register(this); | ||
} | ||
class FlutterInstance(assets: String?, val rect: FlutterAppRect, var width: Int, var height: Int) : AutoCloseable { | ||
val handle: Long = FlutterNative.createInstance(assets) | ||
|
||
public boolean hitTest(double x, double y) { | ||
return x > rect.left && x < rect.right && y > rect.top && y < rect.bottom; | ||
init { | ||
FlutterNative.sendMetricsEvent(handle, rect.right - rect.left, rect.bottom - rect.top, 0) | ||
register(this) | ||
} | ||
|
||
public void pollEvents() { | ||
FlutterNative.pollEvents(handle); | ||
fun hitTest(x: Double, y: Double): Boolean { | ||
return x > rect.left && x < rect.right && y > rect.top && y < rect.bottom | ||
} | ||
|
||
public int getTexture() { | ||
return FlutterNative.getTexture(handle); | ||
fun pollEvents() { | ||
FlutterNative.pollEvents(handle) | ||
} | ||
|
||
@Override | ||
public void close() { | ||
Events.unregister(this); | ||
FlutterNative.destroyInstance(handle); | ||
val texture: Int | ||
get() = FlutterNative.getTexture(handle) | ||
|
||
override fun close() { | ||
unregister(this) | ||
FlutterNative.destroyInstance(handle) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 23 additions & 7 deletions
30
flutter-ui/src/main/java/com/primogemstudio/advancedfmk/flutter/KeyEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
package com.primogemstudio.advancedfmk.flutter; | ||
package com.primogemstudio.advancedfmk.flutter | ||
|
||
import static com.primogemstudio.advancedfmk.flutter.Events.instances; | ||
import com.primogemstudio.advancedfmk.flutter.FlutterEvents.instances | ||
import java.util.function.Consumer | ||
|
||
public class KeyEvent { | ||
public static void onKey(long window, int key, int scanCode, int action, int modifiers) { | ||
instances.forEach(i -> FlutterNative.sendKeyEvent(i.handle, window, key, scanCode, action, modifiers)); | ||
object KeyEvent { | ||
fun onKey(window: Long, key: Int, scanCode: Int, action: Int, modifiers: Int) { | ||
instances.forEach { i: FlutterInstance -> | ||
FlutterNative.sendKeyEvent( | ||
i.handle, | ||
window, | ||
key, | ||
scanCode, | ||
action, | ||
modifiers | ||
) | ||
} | ||
} | ||
|
||
public static void onChar(long window, int code) { | ||
instances.forEach(i -> FlutterNative.sendCharEvent(i.handle, window, code)); | ||
fun onChar(window: Long, code: Int) { | ||
instances.forEach { i: FlutterInstance -> | ||
FlutterNative.sendCharEvent( | ||
i.handle, | ||
window, | ||
code | ||
) | ||
} | ||
} | ||
} |
43 changes: 30 additions & 13 deletions
43
flutter-ui/src/main/java/com/primogemstudio/advancedfmk/flutter/MouseEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,42 @@ | ||
package com.primogemstudio.advancedfmk.flutter; | ||
package com.primogemstudio.advancedfmk.flutter | ||
|
||
import static com.primogemstudio.advancedfmk.flutter.Events.instances; | ||
import com.primogemstudio.advancedfmk.flutter.FlutterEvents.instances | ||
|
||
public class MouseEvent { | ||
public static boolean onMouseButton(int phase, double x, double y) { | ||
for (var i : instances) { | ||
object MouseEvent { | ||
fun onMouseButton(phase: Int, x: Double, y: Double): Boolean { | ||
for (i in instances) { | ||
if (i.hitTest(x, y)) { | ||
FlutterNative.sendPosEvent(i.handle, phase, x - i.rect.left, y - i.rect.top, 0); | ||
return true; | ||
FlutterNative.sendPosEvent(i.handle, phase, x - i.rect.left, y - i.rect.top, 0) | ||
return true | ||
} | ||
} | ||
return false; | ||
return false | ||
} | ||
|
||
public static boolean onMouseMove(double x, double y) { | ||
for (var i : instances) { | ||
fun onMouseMove(x: Double, y: Double): Boolean { | ||
for (i in instances) { | ||
if (i.hitTest(x, y)) { | ||
FlutterNative.sendPosEvent(i.handle, PointerPhase.kHover, x - i.rect.left, y - i.rect.top, 0); | ||
return true; | ||
FlutterNative.sendPosEvent(i.handle, PointerPhase.kMove, x - i.rect.left, y - i.rect.top, 0) | ||
FlutterNative.sendPosEvent(i.handle, PointerPhase.kHover, x - i.rect.left, y - i.rect.top, 0) | ||
return true | ||
} | ||
} | ||
return false; | ||
return false | ||
} | ||
|
||
fun onMouseScroll(x: Double, y: Double, amount: Double): Boolean { | ||
for (i in instances) { | ||
if (i.hitTest(x, y)) { | ||
FlutterNative.sendPosEvent(i.handle, PointerPhase.kRemove, x - i.rect.left, y - i.rect.top, 0) | ||
FlutterNative.sendPosEvent(i.handle, PointerPhase.kAdd, x - i.rect.left, y - i.rect.top, 0) | ||
FlutterNative.sendPosEvent(i.handle, PointerPhase.kCancel, x - i.rect.left, y - i.rect.top, 0) | ||
FlutterNative.sendPosEvent(i.handle, PointerPhase.kPanZoomStart, x - i.rect.left, y - i.rect.top, 0) | ||
|
||
FlutterNative.sendPosEvent(i.handle, PointerPhase.kPanZoomUpdate, x - i.rect.left, y - i.rect.top, 0) | ||
FlutterNative.sendPosEvent(i.handle, PointerPhase.kPanZoomEnd, x - i.rect.left, y - i.rect.top, 0) | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
} |
26 changes: 13 additions & 13 deletions
26
flutter-ui/src/main/java/com/primogemstudio/advancedfmk/flutter/PointerPhase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package com.primogemstudio.advancedfmk.flutter; | ||
package com.primogemstudio.advancedfmk.flutter | ||
|
||
public final class PointerPhase { | ||
public static final int kCancel = 0; | ||
public static final int kUp = 1; | ||
public static final int kDown = 2; | ||
public static final int kMove = 3; | ||
public static final int kAdd = 4; | ||
public static final int kRemove = 5; | ||
public static final int kHover = 6; | ||
public static final int kPanZoomStart = 7; | ||
public static final int kPanZoomUpdate = 8; | ||
public static final int kPanZoomEnd = 9; | ||
} | ||
object PointerPhase { | ||
const val kCancel: Int = 0 | ||
const val kUp: Int = 1 | ||
const val kDown: Int = 2 | ||
const val kMove: Int = 3 | ||
const val kAdd: Int = 4 | ||
const val kRemove: Int = 5 | ||
const val kHover: Int = 6 | ||
const val kPanZoomStart: Int = 7 | ||
const val kPanZoomUpdate: Int = 8 | ||
const val kPanZoomEnd: Int = 9 | ||
} |
15 changes: 0 additions & 15 deletions
15
flutter-ui/src/main/java/com/primogemstudio/advancedfmk/flutter/Rect.java
This file was deleted.
Oops, something went wrong.
16 changes: 7 additions & 9 deletions
16
flutter-ui/src/main/java/com/primogemstudio/advancedfmk/flutter/ViewEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package com.primogemstudio.advancedfmk.flutter; | ||
package com.primogemstudio.advancedfmk.flutter | ||
|
||
import static com.primogemstudio.advancedfmk.flutter.Events.instances; | ||
|
||
public class ViewEvent { | ||
public static void resize(int width, int height) { | ||
instances.forEach(i -> { | ||
i.rect.top = height - i.height; | ||
i.rect.bottom = height; | ||
}); | ||
object ViewEvent { | ||
fun resize(width: Int, height: Int) { | ||
FlutterEvents.instances.forEach { i: FlutterInstance -> | ||
i.rect.top = height - i.height | ||
i.rect.bottom = height | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters