2017-02-22 13:44:38 -06:00
|
|
|
package pixelgl
|
2016-11-23 16:12:23 -06:00
|
|
|
|
|
|
|
import (
|
2016-11-24 08:13:05 -06:00
|
|
|
"image/color"
|
2016-12-18 13:16:27 -06:00
|
|
|
"runtime"
|
|
|
|
|
2017-02-11 07:09:47 -06:00
|
|
|
"github.com/faiface/glhf"
|
2017-01-20 10:45:19 -06:00
|
|
|
"github.com/faiface/mainthread"
|
2017-02-22 13:44:38 -06:00
|
|
|
"github.com/faiface/pixel"
|
2016-11-23 16:12:23 -06:00
|
|
|
"github.com/go-gl/glfw/v3.2/glfw"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// WindowConfig is a structure for specifying all possible properties of a Window. Properties are
|
2017-01-10 17:36:54 -06:00
|
|
|
// chosen in such a way, that you usually only need to set a few of them - defaults (zeros) should
|
|
|
|
// usually be sensible.
|
2016-11-24 07:27:43 -06:00
|
|
|
//
|
2017-03-15 16:55:43 -05:00
|
|
|
// Note that you always need to set the Bounds of a Window.
|
2016-11-23 16:12:23 -06:00
|
|
|
type WindowConfig struct {
|
2017-03-14 19:09:33 -05:00
|
|
|
// Title at the top of the Window.
|
2016-11-24 09:16:00 -06:00
|
|
|
Title string
|
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
// Bounds specify the bounds of the Window in pixels.
|
|
|
|
Bounds pixel.Rect
|
2016-11-24 09:16:00 -06:00
|
|
|
|
2017-04-07 05:34:16 -05:00
|
|
|
// If set to nil, the Window will be windowed. Otherwise it will be fullscreen on the
|
2017-03-15 16:56:23 -05:00
|
|
|
// specified Monitor.
|
2016-11-24 10:24:38 -06:00
|
|
|
Fullscreen *Monitor
|
|
|
|
|
2017-04-07 05:34:16 -05:00
|
|
|
// Whether the Window is resizable.
|
2016-11-24 09:16:00 -06:00
|
|
|
Resizable bool
|
|
|
|
|
2017-03-15 16:56:23 -05:00
|
|
|
// If set to true, the Window will be initially invisible.
|
2016-11-24 09:16:00 -06:00
|
|
|
Hidden bool
|
|
|
|
|
2017-03-15 16:56:23 -05:00
|
|
|
// Undecorated Window ommits the borders and decorations (close button, etc.).
|
2016-11-23 16:12:23 -06:00
|
|
|
Undecorated bool
|
2016-11-24 09:16:00 -06:00
|
|
|
|
2017-04-07 05:34:16 -05:00
|
|
|
// If set to true, the Window will not get focused upon showing up.
|
2016-11-24 09:16:00 -06:00
|
|
|
Unfocused bool
|
|
|
|
|
2017-04-07 05:34:16 -05:00
|
|
|
// Whether the Window is maximized.
|
2016-11-24 09:16:00 -06:00
|
|
|
Maximized bool
|
|
|
|
|
2017-03-15 16:56:23 -05:00
|
|
|
// VSync (vertical synchronization) synchronizes Window's framerate with the framerate of
|
2017-03-05 17:28:52 -06:00
|
|
|
// the monitor.
|
2016-11-24 09:16:00 -06:00
|
|
|
VSync bool
|
2016-11-23 16:12:23 -06:00
|
|
|
}
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// Window is a window handler. Use this type to manipulate a window (input, drawing, etc.).
|
2016-11-23 16:12:23 -06:00
|
|
|
type Window struct {
|
2017-02-11 07:09:47 -06:00
|
|
|
window *glfw.Window
|
2017-01-10 17:26:33 -06:00
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
bounds pixel.Rect
|
|
|
|
canvas *Canvas
|
|
|
|
vsync bool
|
2016-11-24 15:06:51 -06:00
|
|
|
|
|
|
|
// need to save these to correctly restore a fullscreen window
|
|
|
|
restore struct {
|
|
|
|
xpos, ypos, width, height int
|
|
|
|
}
|
2016-12-21 13:18:38 -06:00
|
|
|
|
|
|
|
prevInp, tempInp, currInp struct {
|
2017-03-08 17:56:57 -06:00
|
|
|
mouse pixel.Vec
|
2016-12-21 13:18:38 -06:00
|
|
|
buttons [KeyLast + 1]bool
|
2017-02-22 13:44:38 -06:00
|
|
|
scroll pixel.Vec
|
2016-12-21 13:18:38 -06:00
|
|
|
}
|
2016-11-23 16:12:23 -06:00
|
|
|
}
|
|
|
|
|
2017-03-15 18:15:39 -05:00
|
|
|
var currWin *Window
|
2017-01-01 15:12:12 -06:00
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// NewWindow creates a new Window with it's properties specified in the provided config.
|
2016-11-24 07:27:43 -06:00
|
|
|
//
|
2017-01-25 11:55:17 -06:00
|
|
|
// If Window creation fails, an error is returned (e.g. due to unavailable graphics device).
|
2017-03-05 17:28:52 -06:00
|
|
|
func NewWindow(cfg WindowConfig) (*Window, error) {
|
2016-11-23 16:12:23 -06:00
|
|
|
bool2int := map[bool]int{
|
|
|
|
true: glfw.True,
|
|
|
|
false: glfw.False,
|
|
|
|
}
|
|
|
|
|
2017-03-15 18:15:39 -05:00
|
|
|
w := &Window{bounds: cfg.Bounds}
|
2016-11-23 16:12:23 -06:00
|
|
|
|
2017-01-20 10:45:19 -06:00
|
|
|
err := mainthread.CallErr(func() error {
|
2017-01-25 20:33:21 -06:00
|
|
|
var err error
|
2016-11-25 16:12:01 -06:00
|
|
|
|
2016-11-23 16:12:23 -06:00
|
|
|
glfw.WindowHint(glfw.ContextVersionMajor, 3)
|
|
|
|
glfw.WindowHint(glfw.ContextVersionMinor, 3)
|
|
|
|
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
|
|
|
|
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
|
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
glfw.WindowHint(glfw.Resizable, bool2int[cfg.Resizable])
|
|
|
|
glfw.WindowHint(glfw.Visible, bool2int[!cfg.Hidden])
|
|
|
|
glfw.WindowHint(glfw.Decorated, bool2int[!cfg.Undecorated])
|
|
|
|
glfw.WindowHint(glfw.Focused, bool2int[!cfg.Unfocused])
|
|
|
|
glfw.WindowHint(glfw.Maximized, bool2int[cfg.Maximized])
|
2016-11-23 16:12:23 -06:00
|
|
|
|
2017-01-01 15:12:12 -06:00
|
|
|
var share *glfw.Window
|
2017-03-15 18:15:39 -05:00
|
|
|
if currWin != nil {
|
|
|
|
share = currWin.window
|
2017-01-01 15:12:12 -06:00
|
|
|
}
|
2017-03-07 10:45:46 -06:00
|
|
|
_, _, width, height := intBounds(cfg.Bounds)
|
2017-01-21 19:43:13 -06:00
|
|
|
w.window, err = glfw.CreateWindow(
|
2017-03-05 17:28:52 -06:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
cfg.Title,
|
2017-01-21 19:43:13 -06:00
|
|
|
nil,
|
|
|
|
share,
|
|
|
|
)
|
2016-11-23 16:12:23 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-11-24 10:24:38 -06:00
|
|
|
|
2017-01-21 19:43:13 -06:00
|
|
|
// enter the OpenGL context
|
2017-01-04 17:19:45 -06:00
|
|
|
w.begin()
|
2017-01-10 18:05:24 -06:00
|
|
|
w.end()
|
2016-11-24 15:06:51 -06:00
|
|
|
|
2017-01-21 19:43:13 -06:00
|
|
|
return nil
|
2016-12-16 13:46:24 -06:00
|
|
|
})
|
2016-12-01 18:20:54 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "creating window failed")
|
|
|
|
}
|
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
w.SetVSync(cfg.VSync)
|
|
|
|
|
2017-01-01 15:12:12 -06:00
|
|
|
w.initInput()
|
2017-03-05 17:28:52 -06:00
|
|
|
w.SetMonitor(cfg.Fullscreen)
|
2017-01-21 20:05:59 -06:00
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
w.canvas = NewCanvas(cfg.Bounds, false)
|
2017-01-21 19:43:13 -06:00
|
|
|
w.Update()
|
2017-01-10 17:26:33 -06:00
|
|
|
|
2016-12-18 13:16:27 -06:00
|
|
|
runtime.SetFinalizer(w, (*Window).Destroy)
|
|
|
|
|
2016-11-23 16:12:23 -06:00
|
|
|
return w, nil
|
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// Destroy destroys the Window. The Window can't be used any further.
|
2016-12-18 13:16:27 -06:00
|
|
|
func (w *Window) Destroy() {
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-16 13:27:40 -06:00
|
|
|
w.window.Destroy()
|
2016-11-24 10:24:38 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// Update swaps buffers and polls events. Call this method at the end of each frame.
|
2016-11-23 16:12:23 -06:00
|
|
|
func (w *Window) Update() {
|
2017-03-05 17:28:52 -06:00
|
|
|
mainthread.Call(func() {
|
2017-03-14 12:31:44 -05:00
|
|
|
_, _, oldW, oldH := intBounds(w.bounds)
|
|
|
|
newW, newH := w.window.GetSize()
|
|
|
|
w.bounds = w.bounds.ResizedMin(w.bounds.Size() + pixel.V(
|
|
|
|
float64(newW-oldW),
|
|
|
|
float64(newH-oldH),
|
|
|
|
))
|
2017-03-05 17:28:52 -06:00
|
|
|
})
|
|
|
|
|
2017-03-14 12:31:44 -05:00
|
|
|
w.canvas.SetBounds(w.bounds)
|
2017-01-21 19:43:13 -06:00
|
|
|
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2017-01-04 17:19:45 -06:00
|
|
|
w.begin()
|
2017-01-21 19:43:13 -06:00
|
|
|
|
2017-04-01 14:54:44 -05:00
|
|
|
glhf.Bounds(0, 0, w.canvas.Texture().Width(), w.canvas.Texture().Height())
|
2017-03-05 17:28:52 -06:00
|
|
|
|
2017-02-11 07:09:47 -06:00
|
|
|
glhf.Clear(0, 0, 0, 0)
|
2017-04-01 14:54:44 -05:00
|
|
|
w.canvas.gf.Frame().Begin()
|
|
|
|
w.canvas.gf.Frame().Blit(
|
2017-03-05 17:28:52 -06:00
|
|
|
nil,
|
2017-04-01 14:54:44 -05:00
|
|
|
0, 0, w.canvas.Texture().Width(), w.canvas.Texture().Height(),
|
|
|
|
0, 0, w.canvas.Texture().Width(), w.canvas.Texture().Height(),
|
2017-03-05 17:28:52 -06:00
|
|
|
)
|
2017-04-01 14:54:44 -05:00
|
|
|
w.canvas.gf.Frame().End()
|
2017-03-05 17:28:52 -06:00
|
|
|
|
|
|
|
if w.vsync {
|
2017-01-01 15:12:12 -06:00
|
|
|
glfw.SwapInterval(1)
|
2017-03-05 17:28:52 -06:00
|
|
|
} else {
|
|
|
|
glfw.SwapInterval(0)
|
2017-01-01 15:12:12 -06:00
|
|
|
}
|
|
|
|
w.window.SwapBuffers()
|
2017-01-15 18:12:03 -06:00
|
|
|
w.end()
|
2017-01-01 15:12:12 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
w.updateInput()
|
2016-11-24 15:06:51 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// SetClosed sets the closed flag of the Window.
|
2016-12-21 13:18:38 -06:00
|
|
|
//
|
2017-03-15 18:45:04 -05:00
|
|
|
// This is useful when overriding the user's attempt to close the Window, or just to close the
|
2017-01-25 11:55:17 -06:00
|
|
|
// Window from within the program.
|
2016-12-21 13:18:38 -06:00
|
|
|
func (w *Window) SetClosed(closed bool) {
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-21 13:18:38 -06:00
|
|
|
w.window.SetShouldClose(closed)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// Closed returns the closed flag of the Window, which reports whether the Window should be closed.
|
2016-12-21 13:18:38 -06:00
|
|
|
//
|
2017-01-25 11:55:17 -06:00
|
|
|
// The closed flag is automatically set when a user attempts to close the Window.
|
2016-12-21 13:18:38 -06:00
|
|
|
func (w *Window) Closed() bool {
|
2017-03-15 17:43:00 -05:00
|
|
|
var closed bool
|
|
|
|
mainthread.Call(func() {
|
|
|
|
closed = w.window.ShouldClose()
|
|
|
|
})
|
|
|
|
return closed
|
2016-12-21 13:18:38 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// SetTitle changes the title of the Window.
|
2016-11-24 15:06:51 -06:00
|
|
|
func (w *Window) SetTitle(title string) {
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-16 13:27:40 -06:00
|
|
|
w.window.SetTitle(title)
|
2016-11-24 15:06:51 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// SetBounds sets the bounds of the Window in pixels. Bounds can be fractional, but the actual size
|
|
|
|
// of the window will be rounded to integers.
|
2017-03-05 17:28:52 -06:00
|
|
|
func (w *Window) SetBounds(bounds pixel.Rect) {
|
|
|
|
w.bounds = bounds
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2017-03-07 10:45:46 -06:00
|
|
|
_, _, width, height := intBounds(bounds)
|
2017-03-05 17:28:52 -06:00
|
|
|
w.window.SetSize(width, height)
|
2016-11-24 15:06:51 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
// Bounds returns the current bounds of the Window.
|
|
|
|
func (w *Window) Bounds() pixel.Rect {
|
|
|
|
return w.bounds
|
2016-11-24 15:06:51 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// Show makes the Window visible if it was hidden.
|
2016-11-24 15:06:51 -06:00
|
|
|
func (w *Window) Show() {
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-16 13:27:40 -06:00
|
|
|
w.window.Show()
|
2016-11-24 15:06:51 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// Hide hides the Window if it was visible.
|
2016-11-24 15:06:51 -06:00
|
|
|
func (w *Window) Hide() {
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-16 13:27:40 -06:00
|
|
|
w.window.Hide()
|
2016-11-24 15:06:51 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-25 11:14:19 -06:00
|
|
|
func (w *Window) setFullscreen(monitor *Monitor) {
|
|
|
|
mainthread.Call(func() {
|
|
|
|
w.restore.xpos, w.restore.ypos = w.window.GetPos()
|
|
|
|
w.restore.width, w.restore.height = w.window.GetSize()
|
|
|
|
|
|
|
|
mode := monitor.monitor.GetVideoMode()
|
|
|
|
|
|
|
|
w.window.SetMonitor(
|
|
|
|
monitor.monitor,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
mode.Width,
|
|
|
|
mode.Height,
|
|
|
|
mode.RefreshRate,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *Window) setWindowed() {
|
|
|
|
mainthread.Call(func() {
|
|
|
|
w.window.SetMonitor(
|
|
|
|
nil,
|
|
|
|
w.restore.xpos,
|
|
|
|
w.restore.ypos,
|
|
|
|
w.restore.width,
|
|
|
|
w.restore.height,
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// SetMonitor sets the Window fullscreen on the given Monitor. If the Monitor is nil, the Window
|
2017-03-15 16:55:43 -05:00
|
|
|
// will be restored to windowed state instead.
|
2016-11-24 15:06:51 -06:00
|
|
|
//
|
2017-03-15 16:55:43 -05:00
|
|
|
// The Window will be automatically set to the Monitor's resolution. If you want a different
|
|
|
|
// resolution, you will need to set it manually with SetBounds method.
|
2017-01-25 11:12:11 -06:00
|
|
|
func (w *Window) SetMonitor(monitor *Monitor) {
|
2016-11-24 15:06:51 -06:00
|
|
|
if w.Monitor() != monitor {
|
2017-01-25 11:14:19 -06:00
|
|
|
if monitor != nil {
|
|
|
|
w.setFullscreen(monitor)
|
2016-11-24 15:06:51 -06:00
|
|
|
} else {
|
2017-01-25 11:14:19 -06:00
|
|
|
w.setWindowed()
|
2016-11-24 15:06:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// IsFullscreen returns true if the Window is in fullscreen mode.
|
2016-11-24 15:06:51 -06:00
|
|
|
func (w *Window) IsFullscreen() bool {
|
|
|
|
return w.Monitor() != nil
|
|
|
|
}
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// Monitor returns a monitor the Window is fullscreen on. If the Window is not fullscreen, this
|
2016-12-30 10:43:26 -06:00
|
|
|
// function returns nil.
|
2016-11-24 15:06:51 -06:00
|
|
|
func (w *Window) Monitor() *Monitor {
|
2017-03-15 17:43:00 -05:00
|
|
|
var monitor *glfw.Monitor
|
|
|
|
mainthread.Call(func() {
|
|
|
|
monitor = w.window.GetMonitor()
|
|
|
|
})
|
2016-11-24 15:06:51 -06:00
|
|
|
if monitor == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &Monitor{
|
|
|
|
monitor: monitor,
|
|
|
|
}
|
2016-11-23 16:12:23 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// Focus brings the Window to the front and sets input focus.
|
2016-11-24 10:24:38 -06:00
|
|
|
func (w *Window) Focus() {
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-16 13:27:40 -06:00
|
|
|
w.window.Focus()
|
2016-11-24 10:24:38 -06:00
|
|
|
})
|
2016-11-24 15:06:51 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// Focused returns true if the Window has input focus.
|
2016-11-24 15:06:51 -06:00
|
|
|
func (w *Window) Focused() bool {
|
2017-03-15 17:43:00 -05:00
|
|
|
var focused bool
|
|
|
|
mainthread.Call(func() {
|
|
|
|
focused = w.window.GetAttrib(glfw.Focused) == glfw.True
|
|
|
|
})
|
|
|
|
return focused
|
2016-11-24 15:06:51 -06:00
|
|
|
}
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// Maximize puts the Window to the maximized state.
|
2016-11-24 15:06:51 -06:00
|
|
|
func (w *Window) Maximize() {
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-16 13:27:40 -06:00
|
|
|
w.window.Maximize()
|
2016-11-24 15:06:51 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// Restore restores the Window from the maximized state.
|
2016-11-24 15:06:51 -06:00
|
|
|
func (w *Window) Restore() {
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-16 13:27:40 -06:00
|
|
|
w.window.Restore()
|
2016-11-24 15:06:51 -06:00
|
|
|
})
|
2016-11-24 10:24:38 -06:00
|
|
|
}
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// SetVSync sets whether the Window's Update should synchronize with the monitor refresh rate.
|
2017-03-05 17:28:52 -06:00
|
|
|
func (w *Window) SetVSync(vsync bool) {
|
|
|
|
w.vsync = vsync
|
|
|
|
}
|
|
|
|
|
|
|
|
// VSync returns whether the Window is set to synchronize with the monitor refresh rate.
|
|
|
|
func (w *Window) VSync() bool {
|
|
|
|
return w.vsync
|
|
|
|
}
|
|
|
|
|
2017-01-10 16:54:35 -06:00
|
|
|
// Note: must be called inside the main thread.
|
2017-01-04 17:19:45 -06:00
|
|
|
func (w *Window) begin() {
|
2017-03-15 18:15:39 -05:00
|
|
|
if currWin != w {
|
2017-01-01 15:12:12 -06:00
|
|
|
w.window.MakeContextCurrent()
|
2017-02-11 07:09:47 -06:00
|
|
|
glhf.Init()
|
2017-03-15 18:15:39 -05:00
|
|
|
currWin = w
|
2017-01-01 15:12:12 -06:00
|
|
|
}
|
2016-11-24 09:16:00 -06:00
|
|
|
}
|
2016-11-23 16:12:23 -06:00
|
|
|
|
2017-01-10 16:54:35 -06:00
|
|
|
// Note: must be called inside the main thread.
|
2017-01-04 17:19:45 -06:00
|
|
|
func (w *Window) end() {
|
2017-01-25 11:55:17 -06:00
|
|
|
// nothing, really
|
2017-01-04 17:19:45 -06:00
|
|
|
}
|
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
// MakeTriangles generates a specialized copy of the supplied Triangles that will draw onto this
|
2017-01-04 17:19:45 -06:00
|
|
|
// Window.
|
|
|
|
//
|
2017-03-15 16:55:43 -05:00
|
|
|
// Window supports TrianglesPosition, TrianglesColor and TrianglesPicture.
|
2017-02-22 13:44:38 -06:00
|
|
|
func (w *Window) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles {
|
2017-01-21 19:43:13 -06:00
|
|
|
return w.canvas.MakeTriangles(t)
|
2017-01-04 17:19:45 -06:00
|
|
|
}
|
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
// MakePicture generates a specialized copy of the supplied Picture that will draw onto this Window.
|
|
|
|
//
|
|
|
|
// Window support PictureColor.
|
|
|
|
func (w *Window) MakePicture(p pixel.Picture) pixel.TargetPicture {
|
|
|
|
return w.canvas.MakePicture(p)
|
2017-01-10 17:26:33 -06:00
|
|
|
}
|
|
|
|
|
2017-03-06 12:58:24 -06:00
|
|
|
// SetMatrix sets a Matrix that every point will be projected by.
|
|
|
|
func (w *Window) SetMatrix(m pixel.Matrix) {
|
|
|
|
w.canvas.SetMatrix(m)
|
2017-01-04 17:19:45 -06:00
|
|
|
}
|
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
// SetColorMask sets a global color mask for the Window.
|
|
|
|
func (w *Window) SetColorMask(c color.Color) {
|
|
|
|
w.canvas.SetColorMask(c)
|
2016-12-02 11:17:40 -06:00
|
|
|
}
|
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
// SetSmooth sets whether the stretched Pictures drawn onto this Window should be drawn smooth or
|
|
|
|
// pixely.
|
|
|
|
func (w *Window) SetSmooth(smooth bool) {
|
|
|
|
w.canvas.SetSmooth(smooth)
|
2016-11-23 16:12:23 -06:00
|
|
|
}
|
2016-12-01 18:20:54 -06:00
|
|
|
|
2017-03-05 17:28:52 -06:00
|
|
|
// Smooth returns whether the stretched Pictures drawn onto this Window are set to be drawn smooth
|
|
|
|
// or pixely.
|
|
|
|
func (w *Window) Smooth() bool {
|
|
|
|
return w.canvas.Smooth()
|
2016-12-01 18:20:54 -06:00
|
|
|
}
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// Clear clears the Window with a single color.
|
2017-03-05 17:28:52 -06:00
|
|
|
func (w *Window) Clear(c color.Color) {
|
|
|
|
w.canvas.Clear(c)
|
2016-12-01 18:20:54 -06:00
|
|
|
}
|
2017-04-02 12:08:48 -05:00
|
|
|
|
|
|
|
// Color returns the color of the pixel over the given position inside the Window.
|
|
|
|
func (w *Window) Color(at pixel.Vec) pixel.NRGBA {
|
|
|
|
return w.canvas.Color(at)
|
|
|
|
}
|