mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Compare commits
4 Commits
dfa8f21e52
...
bb57fe8e15
Author | SHA1 | Date | |
---|---|---|---|
|
bb57fe8e15 | ||
|
6f66386f07 | ||
|
13039e214e | ||
|
84a868e77e |
@ -16,36 +16,13 @@
|
||||
|
||||
package textinput
|
||||
|
||||
// TODO: Remove Cgo after ebitengine/purego#143 is resolved.
|
||||
|
||||
// #cgo CFLAGS: -x objective-c
|
||||
// #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 (
|
||||
"github.com/ebitengine/purego/objc"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||
)
|
||||
|
||||
@ -60,7 +37,7 @@ func (t *textInput) Start(x, y int) (chan State, func()) {
|
||||
var session *session
|
||||
ui.Get().RunOnMainThread(func() {
|
||||
t.end()
|
||||
C.start(C.int(x), C.int(y))
|
||||
start(x, y)
|
||||
session = newSession()
|
||||
t.session = session
|
||||
})
|
||||
@ -99,3 +76,57 @@ func (t *textInput) end() {
|
||||
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},
|
||||
})
|
||||
}
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
//go:build !ios
|
||||
|
||||
// TODO: Remove Cgo with PureGo (#1162).
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
void ebitengine_textinput_update(const char* text, int start, int end, BOOL committed);
|
||||
|
4
go.mod
4
go.mod
@ -5,8 +5,8 @@ go 1.18
|
||||
require (
|
||||
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8
|
||||
github.com/ebitengine/hideconsole v1.0.0
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.0.20240401142028-457cd3ebf3f3
|
||||
github.com/ebitengine/purego v0.8.0-alpha
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.1
|
||||
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393
|
||||
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.0.0
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4
|
||||
|
8
go.sum
8
go.sum
@ -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/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj1yReDqE=
|
||||
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.0.20240401142028-457cd3ebf3f3 h1:4vw8U48AKjRSXjwWZLi7g/xA6wNM7PjGNh7TBNES6sI=
|
||||
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 h1:xWsUo8xQZLH8f9TzXXSvs/qjc2s6rhNGYxEo5Qd10so=
|
||||
github.com/ebitengine/purego v0.8.0-alpha/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk=
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.1/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.0.20240404024320-d0aedd0f4393/go.mod h1:y8L+ZRLphbdPW2xs41fur/KaW57yTzrFsqsclHyHrTM=
|
||||
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-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY=
|
||||
|
Loading…
Reference in New Issue
Block a user