Compare commits

..

No commits in common. "bb57fe8e15c8df8f453823872156001df7568fe2" and "dfa8f21e52846eb5a718a53984192a38807a6449" have entirely different histories.

4 changed files with 32 additions and 65 deletions

View File

@ -16,13 +16,36 @@
package textinput package textinput
// TODO: Remove Cgo after ebitengine/purego#143 is resolved.
// #cgo CFLAGS: -x objective-c // #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa // #cgo LDFLAGS: -framework Cocoa
//
// #import <Cocoa/Cocoa.h>
//
// @interface TextInputClient : NSView<NSTextInputClient>
// @end
//
// static TextInputClient* getTextInputClient() {
// static TextInputClient* textInputClient;
// if (!textInputClient) {
// textInputClient = [[TextInputClient alloc] init];
// }
// return textInputClient;
// }
//
// static void start(int x, int y) {
// TextInputClient* textInputClient = getTextInputClient();
// NSWindow* window = [[NSApplication sharedApplication] mainWindow];
// [[window contentView] addSubview: textInputClient];
// [window makeFirstResponder: textInputClient];
//
// y = [[window contentView] frame].size.height - y - 4;
// [textInputClient setFrame:NSMakeRect(x, y, 1, 1)];
// }
import "C" import "C"
import ( import (
"github.com/ebitengine/purego/objc"
"github.com/hajimehoshi/ebiten/v2/internal/ui" "github.com/hajimehoshi/ebiten/v2/internal/ui"
) )
@ -37,7 +60,7 @@ func (t *textInput) Start(x, y int) (chan State, func()) {
var session *session var session *session
ui.Get().RunOnMainThread(func() { ui.Get().RunOnMainThread(func() {
t.end() t.end()
start(x, y) C.start(C.int(x), C.int(y))
session = newSession() session = newSession()
t.session = session t.session = session
}) })
@ -76,57 +99,3 @@ func (t *textInput) end() {
t.session = nil t.session = nil
} }
} }
var (
selAddSubview = objc.RegisterName("addSubview:")
selAlloc = objc.RegisterName("alloc")
selContentView = objc.RegisterName("contentView")
selFrame = objc.RegisterName("frame")
selInit = objc.RegisterName("init")
selMainWindow = objc.RegisterName("mainWindow")
selMakeFirstResponder = objc.RegisterName("makeFirstResponder:")
selSetFrame = objc.RegisterName("setFrame:")
selSharedApplication = objc.RegisterName("sharedApplication")
idNSApplication = objc.ID(objc.GetClass("NSApplication"))
)
var theTextInputClient objc.ID
func getTextInputClient() objc.ID {
if theTextInputClient == 0 {
class := objc.ID(objc.GetClass("TextInputClient"))
theTextInputClient = class.Send(selAlloc).Send(selInit)
}
return theTextInputClient
}
type nsPoint struct {
x float64
y float64
}
type nsSize struct {
width float64
height float64
}
type nsRect struct {
origin nsPoint
size nsSize
}
func start(x, y int) {
t := getTextInputClient()
window := idNSApplication.Send(selSharedApplication).Send(selMainWindow)
contentView := window.Send(selContentView)
contentView.Send(selAddSubview, t)
window.Send(selMakeFirstResponder, t)
r := objc.Send[nsRect](contentView, selFrame)
y = int(r.size.height) - y - 4
t.Send(selSetFrame, nsRect{
origin: nsPoint{float64(x), float64(y)},
size: nsSize{1, 1},
})
}

View File

@ -14,8 +14,6 @@
//go:build !ios //go:build !ios
// TODO: Remove Cgo with PureGo (#1162).
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
void ebitengine_textinput_update(const char* text, int start, int end, BOOL committed); void ebitengine_textinput_update(const char* text, int start, int end, BOOL committed);

4
go.mod
View File

@ -5,8 +5,8 @@ go 1.18
require ( require (
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8 github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8
github.com/ebitengine/hideconsole v1.0.0 github.com/ebitengine/hideconsole v1.0.0
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 github.com/ebitengine/oto/v3 v3.3.0-alpha.0.20240401142028-457cd3ebf3f3
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393 github.com/ebitengine/purego v0.8.0-alpha
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703
github.com/hajimehoshi/bitmapfont/v3 v3.0.0 github.com/hajimehoshi/bitmapfont/v3 v3.0.0
github.com/hajimehoshi/go-mp3 v0.3.4 github.com/hajimehoshi/go-mp3 v0.3.4

8
go.sum
View File

@ -2,10 +2,10 @@ github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8 h1:5e8X7WEdOWr
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8/go.mod h1:tWboRRNagZwwwis4QIgEFG1ZNFwBJ3LAhSLAXAAxobQ= github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8/go.mod h1:tWboRRNagZwwwis4QIgEFG1ZNFwBJ3LAhSLAXAAxobQ=
github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj1yReDqE= github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj1yReDqE=
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A= github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk= github.com/ebitengine/oto/v3 v3.3.0-alpha.0.20240401142028-457cd3ebf3f3 h1:4vw8U48AKjRSXjwWZLi7g/xA6wNM7PjGNh7TBNES6sI=
github.com/ebitengine/oto/v3 v3.3.0-alpha.1/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg= github.com/ebitengine/oto/v3 v3.3.0-alpha.0.20240401142028-457cd3ebf3f3/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg=
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393 h1:8mFaXjlt/DLC5MlrnsR71EpK196kVYvPTC2soh06rGU= github.com/ebitengine/purego v0.8.0-alpha h1:xWsUo8xQZLH8f9TzXXSvs/qjc2s6rhNGYxEo5Qd10so=
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393/go.mod h1:y8L+ZRLphbdPW2xs41fur/KaW57yTzrFsqsclHyHrTM= github.com/ebitengine/purego v0.8.0-alpha/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 h1:AqtMl9yw7r319Ah4W2afQm3Ql+PEsQKHds18tGvKhog= github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 h1:AqtMl9yw7r319Ah4W2afQm3Ql+PEsQKHds18tGvKhog=
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I= github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I=
github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY= github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY=