mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
Rename InputStateUpdated -> MouseStateUpdated
This commit is contained in:
parent
f61d9280e4
commit
0a3ec197ff
@ -34,20 +34,20 @@ type drawInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
inputX int
|
mouseX int
|
||||||
inputY int
|
mouseY int
|
||||||
inputPrevX int
|
mousePrevX int
|
||||||
inputPrevY int
|
mousePrevY int
|
||||||
counter int
|
counter int
|
||||||
drawInfo
|
drawInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGame() *Game {
|
func NewGame() *Game {
|
||||||
return &Game{
|
return &Game{
|
||||||
inputX: -1,
|
mouseX: -1,
|
||||||
inputY: -1,
|
mouseY: -1,
|
||||||
inputPrevX: -1,
|
mousePrevX: -1,
|
||||||
inputPrevY: -1,
|
mousePrevY: -1,
|
||||||
counter: 0,
|
counter: 0,
|
||||||
drawInfo: drawInfo{
|
drawInfo: drawInfo{
|
||||||
textures: map[string]graphics.TextureId{},
|
textures: map[string]graphics.TextureId{},
|
||||||
@ -74,8 +74,8 @@ func (game *Game) OnRenderTargetCreated(e graphics.RenderTargetCreatedEvent) {
|
|||||||
game.renderTargets[e.Tag.(string)] = e.Id
|
game.renderTargets[e.Tag.(string)] = e.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) OnInputStateUpdated(e ui.InputStateUpdatedEvent) {
|
func (game *Game) OnMouseStateUpdated(e ui.MouseStateUpdatedEvent) {
|
||||||
game.inputX, game.inputY = e.X, e.Y
|
game.mouseX, game.mouseY = e.X, e.Y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) isInitialized() bool {
|
func (game *Game) isInitialized() bool {
|
||||||
@ -99,11 +99,11 @@ func (game *Game) Update() {
|
|||||||
game.counter++
|
game.counter++
|
||||||
game.drawInfo.inputStr = fmt.Sprintf(`Input State:
|
game.drawInfo.inputStr = fmt.Sprintf(`Input State:
|
||||||
X: %d
|
X: %d
|
||||||
Y: %d`, game.inputX, game.inputY)
|
Y: %d`, game.mouseX, game.mouseY)
|
||||||
|
|
||||||
if game.inputPrevX != -1 && game.inputPrevY != -1 &&
|
if game.mousePrevX != -1 && game.mousePrevY != -1 &&
|
||||||
game.inputX != -1 && game.inputY != -1 {
|
game.mouseX != -1 && game.mouseY != -1 {
|
||||||
dx, dy := game.inputX-game.inputPrevX, game.inputY-game.inputPrevY
|
dx, dy := game.mouseX-game.mousePrevX, game.mouseY-game.mousePrevY
|
||||||
game.textureX += dx
|
game.textureX += dx
|
||||||
game.textureY += dy
|
game.textureY += dy
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ func (game *Game) Update() {
|
|||||||
game.drawInfo.textureGeo = geo
|
game.drawInfo.textureGeo = geo
|
||||||
|
|
||||||
// Update for the next frame.
|
// Update for the next frame.
|
||||||
game.inputPrevX, game.inputPrevY = game.inputX, game.inputY
|
game.mousePrevX, game.mousePrevY = game.mouseX, game.mouseY
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) Draw(g graphics.Context) {
|
func (game *Game) Draw(g graphics.Context) {
|
||||||
|
@ -67,7 +67,7 @@ func main() {
|
|||||||
go func() {
|
go func() {
|
||||||
defer close(quit)
|
defer close(quit)
|
||||||
|
|
||||||
inputStateUpdated := window.InputStateUpdated()
|
mouseStateUpdated := window.MouseStateUpdated()
|
||||||
screenSizeUpdated := window.ScreenSizeUpdated()
|
screenSizeUpdated := window.ScreenSizeUpdated()
|
||||||
windowClosed := window.WindowClosed()
|
windowClosed := window.WindowClosed()
|
||||||
game := NewGame()
|
game := NewGame()
|
||||||
@ -79,8 +79,8 @@ func main() {
|
|||||||
game.OnTextureCreated(e)
|
game.OnTextureCreated(e)
|
||||||
case e := <-renderTargetCreated:
|
case e := <-renderTargetCreated:
|
||||||
game.OnRenderTargetCreated(e)
|
game.OnRenderTargetCreated(e)
|
||||||
case e := <-inputStateUpdated:
|
case e := <-mouseStateUpdated:
|
||||||
game.OnInputStateUpdated(e)
|
game.OnMouseStateUpdated(e)
|
||||||
case _, ok := <-screenSizeUpdated:
|
case _, ok := <-screenSizeUpdated:
|
||||||
if !ok {
|
if !ok {
|
||||||
screenSizeUpdated = nil
|
screenSizeUpdated = nil
|
||||||
|
@ -25,6 +25,8 @@ type Context interface {
|
|||||||
|
|
||||||
ResetOffscreen()
|
ResetOffscreen()
|
||||||
SetOffscreen(id RenderTargetId)
|
SetOffscreen(id RenderTargetId)
|
||||||
|
|
||||||
|
// TODO: glTextureSubImage2D
|
||||||
}
|
}
|
||||||
|
|
||||||
type LazyContext struct {
|
type LazyContext struct {
|
||||||
|
@ -3,21 +3,32 @@
|
|||||||
#include "ebiten_content_view.h"
|
#include "ebiten_content_view.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
void ebiten_InputUpdated(void* nativeWindow, InputType inputType, int x, int y);
|
void ebiten_MouseStateUpdated(void* nativeWindow, InputType inputType, int x, int y);
|
||||||
|
|
||||||
@implementation EbitenContentView {
|
@implementation EbitenContentView {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)acceptsFirstResponder {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)isFlipped {
|
- (BOOL)isFlipped {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)keyDown:(NSEvent*)theEvent {
|
||||||
|
[self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)insertText:(id)aString {
|
||||||
|
}
|
||||||
|
|
||||||
- (void)mouseDown:(NSEvent*)theEvent {
|
- (void)mouseDown:(NSEvent*)theEvent {
|
||||||
NSPoint location = [self convertPoint:[theEvent locationInWindow]
|
NSPoint location = [self convertPoint:[theEvent locationInWindow]
|
||||||
fromView:nil];
|
fromView:nil];
|
||||||
int x = location.x;
|
int x = location.x;
|
||||||
int y = location.y;
|
int y = location.y;
|
||||||
ebiten_InputUpdated([self window], InputTypeMouseDown, x, y);
|
ebiten_MouseStateUpdated([self window], InputTypeMouseDown, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseUp:(NSEvent*)theEvent {
|
- (void)mouseUp:(NSEvent*)theEvent {
|
||||||
@ -26,7 +37,7 @@ void ebiten_InputUpdated(void* nativeWindow, InputType inputType, int x, int y);
|
|||||||
fromView:nil];
|
fromView:nil];
|
||||||
int x = location.x;
|
int x = location.x;
|
||||||
int y = location.y;
|
int y = location.y;
|
||||||
ebiten_InputUpdated([self window], InputTypeMouseUp, x, y);
|
ebiten_MouseStateUpdated([self window], InputTypeMouseUp, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDragged:(NSEvent*)theEvent {
|
- (void)mouseDragged:(NSEvent*)theEvent {
|
||||||
@ -34,7 +45,20 @@ void ebiten_InputUpdated(void* nativeWindow, InputType inputType, int x, int y);
|
|||||||
fromView:nil];
|
fromView:nil];
|
||||||
int x = location.x;
|
int x = location.x;
|
||||||
int y = location.y;
|
int y = location.y;
|
||||||
ebiten_InputUpdated([self window], InputTypeMouseDragged, x, y);
|
ebiten_MouseStateUpdated([self window], InputTypeMouseDragged, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)moveDown:(id)sender {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)moveLeft:(id)sender {
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)moveRight:(id)sender {
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)moveUp:(id)sender {
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -27,7 +27,7 @@ type Window struct {
|
|||||||
screenScale int
|
screenScale int
|
||||||
closed bool
|
closed bool
|
||||||
native unsafe.Pointer
|
native unsafe.Pointer
|
||||||
context *opengl.Context
|
context *opengl.Context
|
||||||
funcs chan func()
|
funcs chan func()
|
||||||
funcsDone chan struct{}
|
funcsDone chan struct{}
|
||||||
windowEvents
|
windowEvents
|
||||||
@ -102,12 +102,12 @@ func ebiten_ScreenSizeUpdated(nativeWindow unsafe.Pointer, width, height int) {
|
|||||||
u.windowEvents.notifyScreenSizeUpdated(e)
|
u.windowEvents.notifyScreenSizeUpdated(e)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//export ebiten_InputUpdated
|
//export ebiten_MouseStateUpdated
|
||||||
func ebiten_InputUpdated(nativeWindow unsafe.Pointer, inputType C.InputType, cx, cy C.int) {
|
func ebiten_MouseStateUpdated(nativeWindow unsafe.Pointer, inputType C.InputType, cx, cy C.int) {
|
||||||
w := windows[nativeWindow]
|
w := windows[nativeWindow]
|
||||||
|
|
||||||
if inputType == C.InputTypeMouseUp {
|
if inputType == C.InputTypeMouseUp {
|
||||||
e := ui.InputStateUpdatedEvent{-1, -1}
|
e := ui.MouseStateUpdatedEvent{-1, -1}
|
||||||
w.notifyInputStateUpdated(e)
|
w.notifyInputStateUpdated(e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ func ebiten_InputUpdated(nativeWindow unsafe.Pointer, inputType C.InputType, cx,
|
|||||||
} else if w.screenHeight <= y {
|
} else if w.screenHeight <= y {
|
||||||
y = w.screenHeight - 1
|
y = w.screenHeight - 1
|
||||||
}
|
}
|
||||||
e := ui.InputStateUpdatedEvent{x, y}
|
e := ui.MouseStateUpdatedEvent{x, y}
|
||||||
w.notifyInputStateUpdated(e)
|
w.notifyInputStateUpdated(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
type windowEvents struct {
|
type windowEvents struct {
|
||||||
screenSizeUpdated chan ui.ScreenSizeUpdatedEvent // initialized lazily
|
screenSizeUpdated chan ui.ScreenSizeUpdatedEvent // initialized lazily
|
||||||
inputStateUpdated chan ui.InputStateUpdatedEvent // initialized lazily
|
mouseStateUpdated chan ui.MouseStateUpdatedEvent // initialized lazily
|
||||||
windowClosed chan ui.WindowClosedEvent // initialized lazily
|
windowClosed chan ui.WindowClosedEvent // initialized lazily
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,20 +27,20 @@ func (w *windowEvents) notifyScreenSizeUpdated(e ui.ScreenSizeUpdatedEvent) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *windowEvents) InputStateUpdated() <-chan ui.InputStateUpdatedEvent {
|
func (w *windowEvents) MouseStateUpdated() <-chan ui.MouseStateUpdatedEvent {
|
||||||
if w.inputStateUpdated != nil {
|
if w.mouseStateUpdated != nil {
|
||||||
return w.inputStateUpdated
|
return w.mouseStateUpdated
|
||||||
}
|
}
|
||||||
w.inputStateUpdated = make(chan ui.InputStateUpdatedEvent)
|
w.mouseStateUpdated = make(chan ui.MouseStateUpdatedEvent)
|
||||||
return w.inputStateUpdated
|
return w.mouseStateUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *windowEvents) notifyInputStateUpdated(e ui.InputStateUpdatedEvent) {
|
func (w *windowEvents) notifyInputStateUpdated(e ui.MouseStateUpdatedEvent) {
|
||||||
if w.inputStateUpdated == nil {
|
if w.mouseStateUpdated == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
w.inputStateUpdated <- e
|
w.mouseStateUpdated <- e
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
ui/ui.go
4
ui/ui.go
@ -9,7 +9,7 @@ type ScreenSizeUpdatedEvent struct {
|
|||||||
Height int
|
Height int
|
||||||
}
|
}
|
||||||
|
|
||||||
type InputStateUpdatedEvent struct {
|
type MouseStateUpdatedEvent struct {
|
||||||
X int
|
X int
|
||||||
Y int
|
Y int
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ type UI interface {
|
|||||||
|
|
||||||
type WindowEvents interface {
|
type WindowEvents interface {
|
||||||
ScreenSizeUpdated() <-chan ScreenSizeUpdatedEvent
|
ScreenSizeUpdated() <-chan ScreenSizeUpdatedEvent
|
||||||
InputStateUpdated() <-chan InputStateUpdatedEvent
|
MouseStateUpdated() <-chan MouseStateUpdatedEvent
|
||||||
WindowClosed() <-chan WindowClosedEvent
|
WindowClosed() <-chan WindowClosedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user