2014-12-24 03:04:10 +01:00
|
|
|
// Copyright 2014 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.
|
2014-12-10 15:52:37 +01:00
|
|
|
|
|
|
|
package ebiten
|
|
|
|
|
|
|
|
import (
|
2015-01-01 17:20:20 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
|
|
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
|
|
|
"github.com/hajimehoshi/ebiten/internal/ui"
|
2014-12-10 15:52:37 +01:00
|
|
|
"image"
|
|
|
|
)
|
|
|
|
|
2014-12-14 14:05:44 +01:00
|
|
|
// IsKeyPressed returns a boolean indicating whether key is pressed.
|
2014-12-14 09:28:19 +01:00
|
|
|
func IsKeyPressed(key Key) bool {
|
2015-01-01 19:25:31 +01:00
|
|
|
return ui.IsKeyPressed(ui.Key(key))
|
2014-12-14 09:28:19 +01:00
|
|
|
}
|
|
|
|
|
2014-12-14 14:05:44 +01:00
|
|
|
// CursorPosition returns a position of a mouse cursor.
|
2014-12-14 09:28:19 +01:00
|
|
|
func CursorPosition() (x, y int) {
|
2015-01-01 19:25:31 +01:00
|
|
|
return ui.CursorPosition()
|
2014-12-14 09:28:19 +01:00
|
|
|
}
|
|
|
|
|
2014-12-14 14:05:44 +01:00
|
|
|
// IsMouseButtonPressed returns a boolean indicating whether mouseButton is pressed.
|
2014-12-14 09:28:19 +01:00
|
|
|
func IsMouseButtonPressed(mouseButton MouseButton) bool {
|
2015-01-01 19:25:31 +01:00
|
|
|
return ui.IsMouseButtonPressed(ui.MouseButton(mouseButton))
|
2014-12-14 10:34:47 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 06:55:28 +01:00
|
|
|
// GamepadAxisNum returns the number of axes of the gamepad.
|
|
|
|
//
|
|
|
|
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
|
|
|
|
// To use this API, browsers might require rebooting the browser.
|
2015-01-12 05:33:21 +01:00
|
|
|
func GamepadAxisNum(id int) int {
|
|
|
|
return ui.GamepadAxisNum(id)
|
|
|
|
}
|
|
|
|
|
2015-01-12 06:55:28 +01:00
|
|
|
// GamepadAxis returns the float value [-1.0 - 1.0] of the axis.
|
|
|
|
//
|
|
|
|
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
|
|
|
|
// To use this API, browsers might require rebooting the browser.
|
2015-01-12 05:33:21 +01:00
|
|
|
func GamepadAxis(id int, axis int) float64 {
|
|
|
|
return ui.GamepadAxis(id, axis)
|
|
|
|
}
|
|
|
|
|
2015-01-12 06:55:28 +01:00
|
|
|
// GamepadButtonNum returns the number of the buttons of the gamepad.
|
|
|
|
//
|
|
|
|
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
|
|
|
|
// To use this API, browsers might require rebooting the browser.
|
2015-01-12 05:33:21 +01:00
|
|
|
func GamepadButtonNum(id int) int {
|
|
|
|
return ui.GamepadButtonNum(id)
|
2015-01-11 17:54:18 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 06:55:28 +01:00
|
|
|
// IsGamepadButtonPressed returns the boolean indicating the buttons is pressed or not.
|
|
|
|
//
|
|
|
|
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
|
|
|
|
// To use this API, browsers might require rebooting the browser.
|
2015-01-12 05:33:21 +01:00
|
|
|
func IsGamepadButtonPressed(id int, button GamepadButton) bool {
|
|
|
|
return ui.IsGamepadButtonPressed(id, ui.GamepadButton(button))
|
2015-01-11 17:54:18 +01:00
|
|
|
}
|
|
|
|
|
2014-12-22 02:36:42 +01:00
|
|
|
// NewImage returns an empty image.
|
|
|
|
func NewImage(width, height int, filter Filter) (*Image, error) {
|
2015-01-01 17:20:20 +01:00
|
|
|
var innerImage *innerImage
|
|
|
|
var err error
|
2015-01-01 19:25:31 +01:00
|
|
|
ui.Use(func(c *opengl.Context) {
|
2015-01-01 17:20:20 +01:00
|
|
|
var texture *graphics.Texture
|
|
|
|
texture, err = graphics.NewTexture(c, width, height, glFilter(c, filter))
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
innerImage, err = newInnerImage(c, texture)
|
|
|
|
innerImage.Clear(c)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-01-01 19:25:31 +01:00
|
|
|
return &Image{inner: innerImage}, nil
|
2014-12-14 09:28:19 +01:00
|
|
|
}
|
|
|
|
|
2014-12-22 03:20:14 +01:00
|
|
|
// NewImageFromImage creates a new image with the given image (img).
|
2014-12-22 02:36:42 +01:00
|
|
|
func NewImageFromImage(img image.Image, filter Filter) (*Image, error) {
|
2015-01-01 17:20:20 +01:00
|
|
|
var innerImage *innerImage
|
|
|
|
var err error
|
2015-01-01 19:25:31 +01:00
|
|
|
ui.Use(func(c *opengl.Context) {
|
2015-01-01 17:20:20 +01:00
|
|
|
var texture *graphics.Texture
|
|
|
|
texture, err = graphics.NewTextureFromImage(c, img, glFilter(c, filter))
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
innerImage, err = newInnerImage(c, texture)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-01-01 19:25:31 +01:00
|
|
|
return &Image{inner: innerImage}, nil
|
2014-12-10 15:52:37 +01:00
|
|
|
}
|