making underliing glfv window public

This commit is contained in:
Jakub Dóka 2020-12-31 20:12:17 +01:00
parent 857c068d8d
commit a49ca19a42
2 changed files with 34 additions and 34 deletions

View File

@ -45,7 +45,7 @@ func (w *Window) SetMousePosition(v pixel.Vec) {
mainthread.Call(func() {
if (v.X >= 0 && v.X <= w.bounds.W()) &&
(v.Y >= 0 && v.Y <= w.bounds.H()) {
w.window.SetCursorPos(
w.Window.SetCursorPos(
v.X+w.bounds.Min.X,
(w.bounds.H()-v.Y)+w.bounds.Min.Y,
)
@ -359,7 +359,7 @@ var buttonNames = map[Button]string{
func (w *Window) initInput() {
mainthread.Call(func() {
w.window.SetMouseButtonCallback(func(_ *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) {
w.Window.SetMouseButtonCallback(func(_ *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) {
switch action {
case glfw.Press:
w.tempInp.buttons[Button(button)] = true
@ -368,7 +368,7 @@ func (w *Window) initInput() {
}
})
w.window.SetKeyCallback(func(_ *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
w.Window.SetKeyCallback(func(_ *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
if key == glfw.KeyUnknown {
return
}
@ -382,23 +382,23 @@ func (w *Window) initInput() {
}
})
w.window.SetCursorEnterCallback(func(_ *glfw.Window, entered bool) {
w.Window.SetCursorEnterCallback(func(_ *glfw.Window, entered bool) {
w.cursorInsideWindow = entered
})
w.window.SetCursorPosCallback(func(_ *glfw.Window, x, y float64) {
w.Window.SetCursorPosCallback(func(_ *glfw.Window, x, y float64) {
w.tempInp.mouse = pixel.V(
x+w.bounds.Min.X,
(w.bounds.H()-y)+w.bounds.Min.Y,
)
})
w.window.SetScrollCallback(func(_ *glfw.Window, xoff, yoff float64) {
w.Window.SetScrollCallback(func(_ *glfw.Window, xoff, yoff float64) {
w.tempInp.scroll.X += xoff
w.tempInp.scroll.Y += yoff
})
w.window.SetCharCallback(func(_ *glfw.Window, r rune) {
w.Window.SetCharCallback(func(_ *glfw.Window, r rune) {
w.tempInp.typed += string(r)
})
})

View File

@ -79,7 +79,7 @@ type WindowConfig struct {
// Window is a window handler. Use this type to manipulate a window (input, drawing, etc.).
type Window struct {
window *glfw.Window
*glfw.Window
bounds pixel.Rect
canvas *Canvas
@ -138,10 +138,10 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
var share *glfw.Window
if currWin != nil {
share = currWin.window
share = currWin.Window
}
_, _, width, height := intBounds(cfg.Bounds)
w.window, err = glfw.CreateWindow(
w.Window, err = glfw.CreateWindow(
width,
height,
cfg.Title,
@ -153,8 +153,8 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
}
if cfg.Position.X != 0 || cfg.Position.Y != 0 {
w.window.SetPos(int(cfg.Position.X), int(cfg.Position.Y))
w.window.Show()
w.Window.SetPos(int(cfg.Position.X), int(cfg.Position.Y))
w.Window.Show()
}
// enter the OpenGL context
@ -175,7 +175,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
imgs[i] = pic.Image()
}
mainthread.Call(func() {
w.window.SetIcon(imgs)
w.Window.SetIcon(imgs)
})
}
@ -195,7 +195,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
// Destroy destroys the Window. The Window can't be used any further.
func (w *Window) Destroy() {
mainthread.Call(func() {
w.window.Destroy()
w.Window.Destroy()
})
}
@ -210,7 +210,7 @@ func (w *Window) Update() {
func (w *Window) SwapBuffers() {
mainthread.Call(func() {
_, _, oldW, oldH := intBounds(w.bounds)
newW, newH := w.window.GetSize()
newW, newH := w.Window.GetSize()
w.bounds = w.bounds.ResizedMin(w.bounds.Size().Add(pixel.V(
float64(newW-oldW),
float64(newH-oldH),
@ -222,7 +222,7 @@ func (w *Window) SwapBuffers() {
mainthread.Call(func() {
w.begin()
framebufferWidth, framebufferHeight := w.window.GetFramebufferSize()
framebufferWidth, framebufferHeight := w.Window.GetFramebufferSize()
glhf.Bounds(0, 0, framebufferWidth, framebufferHeight)
glhf.Clear(0, 0, 0, 0)
@ -239,7 +239,7 @@ func (w *Window) SwapBuffers() {
} else {
glfw.SwapInterval(0)
}
w.window.SwapBuffers()
w.Window.SwapBuffers()
w.end()
})
}
@ -250,7 +250,7 @@ func (w *Window) SwapBuffers() {
// Window from within the program.
func (w *Window) SetClosed(closed bool) {
mainthread.Call(func() {
w.window.SetShouldClose(closed)
w.Window.SetShouldClose(closed)
})
}
@ -260,7 +260,7 @@ func (w *Window) SetClosed(closed bool) {
func (w *Window) Closed() bool {
var closed bool
mainthread.Call(func() {
closed = w.window.ShouldClose()
closed = w.Window.ShouldClose()
})
return closed
}
@ -268,7 +268,7 @@ func (w *Window) Closed() bool {
// SetTitle changes the title of the Window.
func (w *Window) SetTitle(title string) {
mainthread.Call(func() {
w.window.SetTitle(title)
w.Window.SetTitle(title)
})
}
@ -278,7 +278,7 @@ func (w *Window) SetBounds(bounds pixel.Rect) {
w.bounds = bounds
mainthread.Call(func() {
_, _, width, height := intBounds(bounds)
w.window.SetSize(width, height)
w.Window.SetSize(width, height)
})
}
@ -290,7 +290,7 @@ func (w *Window) SetBounds(bounds pixel.Rect) {
func (w *Window) SetPos(pos pixel.Vec) {
mainthread.Call(func() {
left, top := int(pos.X), int(pos.Y)
w.window.SetPos(left, top)
w.Window.SetPos(left, top)
})
}
@ -299,7 +299,7 @@ func (w *Window) SetPos(pos pixel.Vec) {
func (w *Window) GetPos() pixel.Vec {
var v pixel.Vec
mainthread.Call(func() {
x, y := w.window.GetPos()
x, y := w.Window.GetPos()
v = pixel.V(float64(x), float64(y))
})
return v
@ -312,12 +312,12 @@ func (w *Window) Bounds() pixel.Rect {
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()
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(
w.Window.SetMonitor(
monitor.monitor,
0,
0,
@ -330,7 +330,7 @@ func (w *Window) setFullscreen(monitor *Monitor) {
func (w *Window) setWindowed() {
mainthread.Call(func() {
w.window.SetMonitor(
w.Window.SetMonitor(
nil,
w.restore.xpos,
w.restore.ypos,
@ -361,7 +361,7 @@ func (w *Window) SetMonitor(monitor *Monitor) {
func (w *Window) Monitor() *Monitor {
var monitor *glfw.Monitor
mainthread.Call(func() {
monitor = w.window.GetMonitor()
monitor = w.Window.GetMonitor()
})
if monitor == nil {
return nil
@ -375,7 +375,7 @@ func (w *Window) Monitor() *Monitor {
func (w *Window) Focused() bool {
var focused bool
mainthread.Call(func() {
focused = w.window.GetAttrib(glfw.Focused) == glfw.True
focused = w.Window.GetAttrib(glfw.Focused) == glfw.True
})
return focused
}
@ -395,9 +395,9 @@ func (w *Window) SetCursorVisible(visible bool) {
w.cursorVisible = visible
mainthread.Call(func() {
if visible {
w.window.SetInputMode(glfw.CursorMode, glfw.CursorNormal)
w.Window.SetInputMode(glfw.CursorMode, glfw.CursorNormal)
} else {
w.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden)
w.Window.SetInputMode(glfw.CursorMode, glfw.CursorHidden)
}
})
}
@ -407,7 +407,7 @@ func (w *Window) SetCursorVisible(visible bool) {
func (w *Window) SetCursorDisabled() {
w.cursorVisible = false
mainthread.Call(func() {
w.window.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
w.Window.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
})
}
@ -419,7 +419,7 @@ func (w *Window) CursorVisible() bool {
// Note: must be called inside the main thread.
func (w *Window) begin() {
if currWin != w {
w.window.MakeContextCurrent()
w.Window.MakeContextCurrent()
currWin = w
}
}
@ -491,6 +491,6 @@ func (w *Window) Canvas() *Canvas {
// already visible or is in full screen mode, this function does nothing.
func (w *Window) Show() {
mainthread.Call(func() {
w.window.Show()
w.Window.Show()
})
}