Rename InputStateUpdated -> MouseStateUpdated

This commit is contained in:
Hajime Hoshi 2013-12-15 23:41:33 +09:00
parent f61d9280e4
commit 0a3ec197ff
7 changed files with 64 additions and 38 deletions

View File

@ -34,20 +34,20 @@ type drawInfo struct {
}
type Game struct {
inputX int
inputY int
inputPrevX int
inputPrevY int
mouseX int
mouseY int
mousePrevX int
mousePrevY int
counter int
drawInfo
}
func NewGame() *Game {
return &Game{
inputX: -1,
inputY: -1,
inputPrevX: -1,
inputPrevY: -1,
mouseX: -1,
mouseY: -1,
mousePrevX: -1,
mousePrevY: -1,
counter: 0,
drawInfo: drawInfo{
textures: map[string]graphics.TextureId{},
@ -74,8 +74,8 @@ func (game *Game) OnRenderTargetCreated(e graphics.RenderTargetCreatedEvent) {
game.renderTargets[e.Tag.(string)] = e.Id
}
func (game *Game) OnInputStateUpdated(e ui.InputStateUpdatedEvent) {
game.inputX, game.inputY = e.X, e.Y
func (game *Game) OnMouseStateUpdated(e ui.MouseStateUpdatedEvent) {
game.mouseX, game.mouseY = e.X, e.Y
}
func (game *Game) isInitialized() bool {
@ -99,11 +99,11 @@ func (game *Game) Update() {
game.counter++
game.drawInfo.inputStr = fmt.Sprintf(`Input State:
X: %d
Y: %d`, game.inputX, game.inputY)
Y: %d`, game.mouseX, game.mouseY)
if game.inputPrevX != -1 && game.inputPrevY != -1 &&
game.inputX != -1 && game.inputY != -1 {
dx, dy := game.inputX-game.inputPrevX, game.inputY-game.inputPrevY
if game.mousePrevX != -1 && game.mousePrevY != -1 &&
game.mouseX != -1 && game.mouseY != -1 {
dx, dy := game.mouseX-game.mousePrevX, game.mouseY-game.mousePrevY
game.textureX += dx
game.textureY += dy
@ -119,7 +119,7 @@ func (game *Game) Update() {
game.drawInfo.textureGeo = geo
// 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) {

View File

@ -67,7 +67,7 @@ func main() {
go func() {
defer close(quit)
inputStateUpdated := window.InputStateUpdated()
mouseStateUpdated := window.MouseStateUpdated()
screenSizeUpdated := window.ScreenSizeUpdated()
windowClosed := window.WindowClosed()
game := NewGame()
@ -79,8 +79,8 @@ func main() {
game.OnTextureCreated(e)
case e := <-renderTargetCreated:
game.OnRenderTargetCreated(e)
case e := <-inputStateUpdated:
game.OnInputStateUpdated(e)
case e := <-mouseStateUpdated:
game.OnMouseStateUpdated(e)
case _, ok := <-screenSizeUpdated:
if !ok {
screenSizeUpdated = nil

View File

@ -25,6 +25,8 @@ type Context interface {
ResetOffscreen()
SetOffscreen(id RenderTargetId)
// TODO: glTextureSubImage2D
}
type LazyContext struct {

View File

@ -3,21 +3,32 @@
#include "ebiten_content_view.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 {
}
- (BOOL)acceptsFirstResponder {
return YES;
}
- (BOOL)isFlipped {
return YES;
}
- (void)keyDown:(NSEvent*)theEvent {
[self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
}
- (void)insertText:(id)aString {
}
- (void)mouseDown:(NSEvent*)theEvent {
NSPoint location = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
int x = location.x;
int y = location.y;
ebiten_InputUpdated([self window], InputTypeMouseDown, x, y);
ebiten_MouseStateUpdated([self window], InputTypeMouseDown, x, y);
}
- (void)mouseUp:(NSEvent*)theEvent {
@ -26,7 +37,7 @@ void ebiten_InputUpdated(void* nativeWindow, InputType inputType, int x, int y);
fromView:nil];
int x = location.x;
int y = location.y;
ebiten_InputUpdated([self window], InputTypeMouseUp, x, y);
ebiten_MouseStateUpdated([self window], InputTypeMouseUp, x, y);
}
- (void)mouseDragged:(NSEvent*)theEvent {
@ -34,7 +45,20 @@ void ebiten_InputUpdated(void* nativeWindow, InputType inputType, int x, int y);
fromView:nil];
int x = location.x;
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

View File

@ -27,7 +27,7 @@ type Window struct {
screenScale int
closed bool
native unsafe.Pointer
context *opengl.Context
context *opengl.Context
funcs chan func()
funcsDone chan struct{}
windowEvents
@ -102,12 +102,12 @@ func ebiten_ScreenSizeUpdated(nativeWindow unsafe.Pointer, width, height int) {
u.windowEvents.notifyScreenSizeUpdated(e)
}*/
//export ebiten_InputUpdated
func ebiten_InputUpdated(nativeWindow unsafe.Pointer, inputType C.InputType, cx, cy C.int) {
//export ebiten_MouseStateUpdated
func ebiten_MouseStateUpdated(nativeWindow unsafe.Pointer, inputType C.InputType, cx, cy C.int) {
w := windows[nativeWindow]
if inputType == C.InputTypeMouseUp {
e := ui.InputStateUpdatedEvent{-1, -1}
e := ui.MouseStateUpdatedEvent{-1, -1}
w.notifyInputStateUpdated(e)
return
}
@ -125,7 +125,7 @@ func ebiten_InputUpdated(nativeWindow unsafe.Pointer, inputType C.InputType, cx,
} else if w.screenHeight <= y {
y = w.screenHeight - 1
}
e := ui.InputStateUpdatedEvent{x, y}
e := ui.MouseStateUpdatedEvent{x, y}
w.notifyInputStateUpdated(e)
}

View File

@ -6,7 +6,7 @@ import (
type windowEvents struct {
screenSizeUpdated chan ui.ScreenSizeUpdatedEvent // initialized lazily
inputStateUpdated chan ui.InputStateUpdatedEvent // initialized lazily
mouseStateUpdated chan ui.MouseStateUpdatedEvent // 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 {
if w.inputStateUpdated != nil {
return w.inputStateUpdated
func (w *windowEvents) MouseStateUpdated() <-chan ui.MouseStateUpdatedEvent {
if w.mouseStateUpdated != nil {
return w.mouseStateUpdated
}
w.inputStateUpdated = make(chan ui.InputStateUpdatedEvent)
return w.inputStateUpdated
w.mouseStateUpdated = make(chan ui.MouseStateUpdatedEvent)
return w.mouseStateUpdated
}
func (w *windowEvents) notifyInputStateUpdated(e ui.InputStateUpdatedEvent) {
if w.inputStateUpdated == nil {
func (w *windowEvents) notifyInputStateUpdated(e ui.MouseStateUpdatedEvent) {
if w.mouseStateUpdated == nil {
return
}
go func() {
w.inputStateUpdated <- e
w.mouseStateUpdated <- e
}()
}

View File

@ -9,7 +9,7 @@ type ScreenSizeUpdatedEvent struct {
Height int
}
type InputStateUpdatedEvent struct {
type MouseStateUpdatedEvent struct {
X int
Y int
}
@ -24,7 +24,7 @@ type UI interface {
type WindowEvents interface {
ScreenSizeUpdated() <-chan ScreenSizeUpdatedEvent
InputStateUpdated() <-chan InputStateUpdatedEvent
MouseStateUpdated() <-chan MouseStateUpdatedEvent
WindowClosed() <-chan WindowClosedEvent
}