mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
mobile: Make it buildable for desktops (just for comments)
This commit is contained in:
parent
7d99ce35ba
commit
e30ef050f2
37
mobile/impl_empty.go
Normal file
37
mobile/impl_empty.go
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2016 Hajime Hoshi
|
||||
//
|
||||
// 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.
|
||||
|
||||
// +build darwin,!arm,!arm64 linux windows
|
||||
// +build !android
|
||||
// +build !ios
|
||||
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
|
||||
func setScreenSize(width, height int) {
|
||||
}
|
||||
|
||||
func setScreenScale(scale float64) {
|
||||
}
|
||||
|
||||
func render() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func start(f func(*ebiten.Image) error, width, height int, scale float64, title string) (EventDispatcher, error) {
|
||||
return nil, nil
|
||||
}
|
48
mobile/impl_mobile.go
Normal file
48
mobile/impl_mobile.go
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright 2016 Hajime Hoshi
|
||||
//
|
||||
// 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.
|
||||
|
||||
// +build android ios darwin,arm darwin,arm64
|
||||
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
|
||||
var chError <-chan error
|
||||
|
||||
func setScreenSize(width, height int) {
|
||||
ui.CurrentUI().SetScreenSize(width, height)
|
||||
}
|
||||
|
||||
func setScreenScale(scale float64) {
|
||||
ui.CurrentUI().SetScreenScale(scale)
|
||||
}
|
||||
|
||||
func render() error {
|
||||
if chError == nil {
|
||||
return errors.New("mobile: chError must not be nil: Start is not called yet?")
|
||||
}
|
||||
return ui.Render(chError)
|
||||
}
|
||||
|
||||
func start(f func(*ebiten.Image) error, width, height int, scale float64, title string) (EventDispatcher, error) {
|
||||
chError = ebiten.RunWithoutMainLoop(f, width, height, scale, title)
|
||||
return &eventDispatcher{
|
||||
touches: map[int]position{},
|
||||
}, nil
|
||||
}
|
@ -12,21 +12,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// TODO: Fix build tags to show comment docs on any platforms
|
||||
|
||||
// +build android ios darwin,arm darwin,arm64
|
||||
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
|
||||
var chError <-chan error
|
||||
|
||||
type EventDispatcher interface {
|
||||
SetScreenSize(width, height int)
|
||||
SetScreenScale(scale float64)
|
||||
@ -39,10 +31,7 @@ type EventDispatcher interface {
|
||||
//
|
||||
// Different from ebiten.Run, this invokes only the game loop and not the main (UI) loop.
|
||||
func Start(f func(*ebiten.Image) error, width, height int, scale float64, title string) (EventDispatcher, error) {
|
||||
chError = ebiten.RunWithoutMainLoop(f, width, height, scale, title)
|
||||
return &eventDispatcher{
|
||||
touches: map[int]position{},
|
||||
}, nil
|
||||
return start(f, width, height, scale, title)
|
||||
}
|
||||
|
||||
type position struct {
|
||||
@ -55,18 +44,15 @@ type eventDispatcher struct {
|
||||
}
|
||||
|
||||
func (e *eventDispatcher) SetScreenSize(width, height int) {
|
||||
ui.CurrentUI().SetScreenSize(width, height)
|
||||
setScreenSize(width, height)
|
||||
}
|
||||
|
||||
func (e *eventDispatcher) SetScreenScale(scale float64) {
|
||||
ui.CurrentUI().SetScreenScale(scale)
|
||||
setScreenScale(scale)
|
||||
}
|
||||
|
||||
func (e *eventDispatcher) Render() error {
|
||||
if chError == nil {
|
||||
return errors.New("mobile: chError must not be nil: Start is not called yet?")
|
||||
}
|
||||
return ui.Render(chError)
|
||||
return render()
|
||||
}
|
||||
|
||||
// touch implements ui.Touch.
|
||||
@ -113,11 +99,3 @@ func (e *eventDispatcher) UpdateTouchesOnAndroid(action int, id int, x, y int) {
|
||||
func (e *eventDispatcher) UpdateTouchesOnIOS(phase int, ptr int, x, y int) {
|
||||
e.updateTouchesOnIOSImpl(phase, ptr, x, y)
|
||||
}
|
||||
|
||||
func (e *eventDispatcher) updateTouches() {
|
||||
ts := []ui.Touch{}
|
||||
for id, position := range e.touches {
|
||||
ts = append(ts, touch{id, position})
|
||||
}
|
||||
ui.UpdateTouches(ts)
|
||||
}
|
||||
|
25
mobile/touches_empty.go
Normal file
25
mobile/touches_empty.go
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2016 Hajime Hoshi
|
||||
//
|
||||
// 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.
|
||||
|
||||
// +build darwin,!arm,!arm64 linux windows
|
||||
// +build !android
|
||||
// +build !ios
|
||||
|
||||
package mobile
|
||||
|
||||
func (e *eventDispatcher) updateTouchesOnIOSImpl(phase int, ptr int, x, y int) {
|
||||
}
|
||||
|
||||
func (e *eventDispatcher) updateTouches() {
|
||||
}
|
29
mobile/touches_mobile.go
Normal file
29
mobile/touches_mobile.go
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2016 Hajime Hoshi
|
||||
//
|
||||
// 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.
|
||||
|
||||
// +build android ios darwin,arm darwin,arm64
|
||||
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
|
||||
func (e *eventDispatcher) updateTouches() {
|
||||
ts := []ui.Touch{}
|
||||
for id, position := range e.touches {
|
||||
ts = append(ts, touch{id, position})
|
||||
}
|
||||
ui.UpdateTouches(ts)
|
||||
}
|
Loading…
Reference in New Issue
Block a user