zorldo

Goofing around with Ebiten
git clone git://bsandro.tech/zorldo
Log | Files | Refs | README

callback_notwindows.go (2769B)


      1 // Copyright 2021 The Ebiten Authors
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 //go:build !js && !windows
     16 // +build !js,!windows
     17 
     18 package glfw
     19 
     20 import (
     21 	"github.com/go-gl/glfw/v3.3/glfw"
     22 )
     23 
     24 var (
     25 	charModsCallbacks        = map[CharModsCallback]glfw.CharModsCallback{}
     26 	closeCallbacks           = map[CloseCallback]glfw.CloseCallback{}
     27 	framebufferSizeCallbacks = map[FramebufferSizeCallback]glfw.FramebufferSizeCallback{}
     28 	scrollCallbacks          = map[ScrollCallback]glfw.ScrollCallback{}
     29 	sizeCallbacks            = map[SizeCallback]glfw.SizeCallback{}
     30 )
     31 
     32 func ToCharModsCallback(cb func(window *Window, char rune, mods ModifierKey)) CharModsCallback {
     33 	if cb == nil {
     34 		return 0
     35 	}
     36 	id := CharModsCallback(len(charModsCallbacks) + 1)
     37 	var gcb glfw.CharModsCallback = func(window *glfw.Window, char rune, mods glfw.ModifierKey) {
     38 		cb(theWindows.get(window), char, ModifierKey(mods))
     39 	}
     40 	charModsCallbacks[id] = gcb
     41 	return id
     42 }
     43 
     44 func ToCloseCallback(cb func(window *Window)) CloseCallback {
     45 	if cb == nil {
     46 		return 0
     47 	}
     48 	id := CloseCallback(len(closeCallbacks) + 1)
     49 	var gcb glfw.CloseCallback = func(window *glfw.Window) {
     50 		cb(theWindows.get(window))
     51 	}
     52 	closeCallbacks[id] = gcb
     53 	return id
     54 }
     55 
     56 func ToFramebufferSizeCallback(cb func(window *Window, width int, height int)) FramebufferSizeCallback {
     57 	if cb == nil {
     58 		return 0
     59 	}
     60 	id := FramebufferSizeCallback(len(framebufferSizeCallbacks) + 1)
     61 	var gcb glfw.FramebufferSizeCallback = func(window *glfw.Window, width int, height int) {
     62 		cb(theWindows.get(window), width, height)
     63 	}
     64 	framebufferSizeCallbacks[id] = gcb
     65 	return id
     66 }
     67 
     68 func ToScrollCallback(cb func(window *Window, xoff float64, yoff float64)) ScrollCallback {
     69 	if cb == nil {
     70 		return 0
     71 	}
     72 	id := ScrollCallback(len(scrollCallbacks) + 1)
     73 	var gcb glfw.ScrollCallback = func(window *glfw.Window, xoff float64, yoff float64) {
     74 		cb(theWindows.get(window), xoff, yoff)
     75 	}
     76 	scrollCallbacks[id] = gcb
     77 	return id
     78 }
     79 
     80 func ToSizeCallback(cb func(window *Window, width int, height int)) SizeCallback {
     81 	if cb == nil {
     82 		return 0
     83 	}
     84 	id := SizeCallback(len(sizeCallbacks) + 1)
     85 	var gcb glfw.SizeCallback = func(window *glfw.Window, width, height int) {
     86 		cb(theWindows.get(window), width, height)
     87 	}
     88 	sizeCallbacks[id] = gcb
     89 	return id
     90 }