2021-12-17 07:03:23 +01:00
|
|
|
// Copyright 2021 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-08-12 05:40:23 +02:00
|
|
|
//go:build nintendosdk
|
2021-12-17 07:03:23 +01:00
|
|
|
|
2022-08-12 10:19:28 +02:00
|
|
|
package nintendosdk
|
2021-12-17 07:03:23 +01:00
|
|
|
|
|
|
|
// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all
|
|
|
|
// #cgo darwin LDFLAGS: -Wl,-undefined,dynamic_lookup
|
|
|
|
//
|
|
|
|
// #include <stdint.h>
|
|
|
|
//
|
|
|
|
// struct Touch {
|
|
|
|
// int id;
|
|
|
|
// int x;
|
|
|
|
// int y;
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// // UI
|
|
|
|
// void EbitenInitializeGame();
|
|
|
|
// void EbitenGetScreenSize(int* width, int* height);
|
|
|
|
// void EbitenBeginFrame();
|
|
|
|
// void EbitenEndFrame();
|
|
|
|
//
|
|
|
|
// // Input
|
|
|
|
// int EbitenGetTouchNum();
|
|
|
|
// void EbitenGetTouches(struct Touch* touches);
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type Touch struct {
|
2022-02-06 11:07:17 +01:00
|
|
|
ID int
|
2021-12-17 07:03:23 +01:00
|
|
|
X int
|
|
|
|
Y int
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitializeGame() {
|
|
|
|
C.EbitenInitializeGame()
|
|
|
|
}
|
|
|
|
|
|
|
|
func ScreenSize() (int, int) {
|
|
|
|
var width, height C.int
|
|
|
|
C.EbitenGetScreenSize(&width, &height)
|
|
|
|
return int(width), int(height)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BeginFrame() {
|
|
|
|
C.EbitenBeginFrame()
|
|
|
|
}
|
|
|
|
|
|
|
|
func EndFrame() {
|
|
|
|
C.EbitenEndFrame()
|
|
|
|
}
|
|
|
|
|
|
|
|
var cTouches []C.struct_Touch
|
|
|
|
|
|
|
|
func AppendTouches(touches []Touch) []Touch {
|
|
|
|
n := int(C.EbitenGetTouchNum())
|
|
|
|
cTouches = cTouches[:0]
|
|
|
|
if cap(cTouches) < n {
|
|
|
|
cTouches = append(cTouches, make([]C.struct_Touch, n)...)
|
|
|
|
} else {
|
|
|
|
cTouches = cTouches[:n]
|
|
|
|
}
|
|
|
|
if n > 0 {
|
|
|
|
C.EbitenGetTouches(&cTouches[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, t := range cTouches {
|
|
|
|
touches = append(touches, Touch{
|
2022-02-06 11:07:17 +01:00
|
|
|
ID: int(t.id),
|
2021-12-17 07:03:23 +01:00
|
|
|
X: int(t.x),
|
|
|
|
Y: int(t.y),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return touches
|
|
|
|
}
|